Lightweight Temporal polyfill.
npm install temporal-polyfill-lite
For users who need only Gregorian calendar (iso8601 and gregory), you can use a smaller "basic" bundle:
// as a ponyfill (without patching global variables)
import { Intl, Temporal } from "temporal-polyfill-lite";
// load the polyfill to global
import "temporal-polyfill-lite/global";
// load types to global if you need (optional)
import "temporal-polyfill-lite/types/global";
// or you can manually install the polyfill
import { install } from "temporal-polyfill-lite/shim";
// overwrite native Temporal implementation
install(true);
// don't overwrite native Temporal implementation
install(false);
If you need other calendars (such as hebrew, chinese, or indian), you have to load a "full" bundle from temporal-polyfill-lite/calendars-full module instead of temporal-polyfill-lite.
import { Intl, Temporal } from "temporal-polyfill-lite/calendars-full";
import "temporal-polyfill-lite/calendars-full/global";
import { install } from "temporal-polyfill-lite/calendars-full/shim";
Temporal.Now.timeZoneId is very slow in the polyfill because there is no efficient way to get the system time zone (except native Temporal.Now.timeZoneId). temporal-polyfill-lite has an opt-in cache mechanism for this.
import { setSystemTimeZoneIdCacheTtl } from "temporal-polyfill-lite/shim";
// or use "temporal-polyfill-lite/calendars-full/shim" entrypoint if you use the "full" bundle
setSystemTimeZoneIdCacheTtl(1000);
// The result of `Temporal.Now.timeZoneId()` will be cached for a second
The polyfill works in browsers after September 2020 by default (e.g. Safari 14). See docs/legacy.md if you want broader support.
This polyfill provides type definitions out of the box (You don't need @types/*).
This package is ESM-only, so you have to set module and moduleResolution correctly. It also uses the exports field in package.json, so you should not set the resolvePackageJsonExports option to false in your tsconfig.json. Otherwise the type resolution will fail.
It supports the latest spec with few intentional deviations (see tests/expectedFailures directory for details).
docs/legacy.md: information about support for legacy browsersdocs/restrictions.md: caveats and restrictions of this polyfillLightweight Temporal polyfill.
npm install temporal-polyfill-lite
For users who need only Gregorian calendar (iso8601 and gregory), you can use a smaller "basic" bundle:
// as a ponyfill (without patching global variables)
import { Intl, Temporal } from "temporal-polyfill-lite";
// load the polyfill to global
import "temporal-polyfill-lite/global";
// load types to global if you need (optional)
import "temporal-polyfill-lite/types/global";
// or you can manually install the polyfill
import { install } from "temporal-polyfill-lite/shim";
// overwrite native Temporal implementation
install(true);
// don't overwrite native Temporal implementation
install(false);
If you need other calendars (such as hebrew, chinese, or indian), you have to load a "full" bundle from temporal-polyfill-lite/calendars-full module instead of temporal-polyfill-lite.
import { Intl, Temporal } from "temporal-polyfill-lite/calendars-full";
import "temporal-polyfill-lite/calendars-full/global";
import { install } from "temporal-polyfill-lite/calendars-full/shim";
Temporal.Now.timeZoneId is very slow in the polyfill because there is no efficient way to get the system time zone (except native Temporal.Now.timeZoneId). temporal-polyfill-lite has an opt-in cache mechanism for this.
import { setSystemTimeZoneIdCacheTtl } from "temporal-polyfill-lite/shim";
// or use "temporal-polyfill-lite/calendars-full/shim" entrypoint if you use the "full" bundle
setSystemTimeZoneIdCacheTtl(1000);
// The result of `Temporal.Now.timeZoneId()` will be cached for a second
The polyfill works in browsers after September 2020 by default (e.g. Safari 14). See docs/legacy.md if you want broader support.
This polyfill provides type definitions out of the box (You don't need @types/*).
This package is ESM-only, so you have to set module and moduleResolution correctly. It also uses the exports field in package.json, so you should not set the resolvePackageJsonExports option to false in your tsconfig.json. Otherwise the type resolution will fail.
It supports the latest spec with few intentional deviations (see tests/expectedFailures directory for details).
docs/legacy.md: information about support for legacy browsersdocs/restrictions.md: caveats and restrictions of this polyfillTypeScript
100.0%