Socket
Socket
Sign inDemoInstall

@js-temporal/polyfill

Package Overview
Dependencies
2
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @js-temporal/polyfill

Polyfill for Tc39 Stage 3 proposal Temporal (https://github.com/tc39/proposal-temporal)


Version published
Maintainers
3
Install size
4.71 MB
Created

Changelog

Source

0.3.0

This version roughly corresponds with all the changes made to the Temporal polyfill as of the October 2021 TC39 Plenary meeting.

Breaking changes:

  • Timezones now require a getOffsetNanosecondsFor method, and no longer fall back to the intrinsic definition (previously provided by Temporal.Timezone#getOffsetNanosecondsFor) if not provided. ([08346dc5], see also proposal-temporal polyfill PR)
  • Disallow Z designators when parsing strings for Plain Temporal types ([f3f8a994], see also Spec PR)
  • Allow ISO strings with "Z" + a bracketed IANA name ([70bd9898], see also Spec PR)
  • Emit ES2020 builds for newer browsers, and emit ES5 for older browsers. ([2331468d], [9e95c62b])
  • Temporal.Duration constructor will now throw if given a non-integer ([9df5d068], see also Spec PR)
  • Remove support for sub-minute offsets in ISO strings ([766e5037], see also Spec PR, Spec PR)
  • Throw TypeError on missing options from Duration.total ([4ec075f0], see also Spec PR)
  • Reject non-integer Duration fields in Duration.with() ([e6b2488d], see also Spec PR)
  • Ensure an Object is returned from calendar.mergeFields() ([4e63f25f], see also Spec PR)

Bug fixes:

  • Fix GetFormatterParts for Firefox Nightly ([47f9132f])
  • Fix TS types of RoundTo and TotalOf ([3008a670])
  • Fix crash setting day outside current JPN era ([6d3588c3], see also proposal-temporal polyfill PR)
  • Copy options object for PlainYearMonth.{add,subtract} and InterpretTemporalDateTimeFields to prevent user-modified objects from interfering with later operations. ([bafa1bdf], see also Spec PR)
  • Validate input to Calendar.prototype.fields ([7ebc700e], see also Spec PR)
  • Stop observably calling into getPossibleInstantsFor in InterpretISODateTimeOffset ([5448e59f], see also Spec PR)
  • Call CalendarEquals correctly ([07ea694e], see also proposal-temporal polyfill PR)
  • Fix arithmetic issues when using non-ISO months ([079a3325], see also proposal-temporal polyfill PR)
  • Regex: tighten matching of month and day values in datesplit ([b5736546], see also proposal-temporal polyfill PR)
  • Fix TS types for required CalendarProtocol methods ([0ee4581f], see also proposal-temporal polyfill PR)

Non-breaking changes:

  • Various #round and #total methods now accept string parameters or options bags. Strings are interpreted as the smallestUnit option (or unit for Temporal.Duration#total). ([068e801f], see also Spec PR)
  • Add @@toStringTag to TS types ([41ab6bc0])
  • Accept string Calendar names in PlainMonthDay and PlainYearMonth constructors ([27b4c7e8])
  • Make options optional in Calendar method TS types ([3a09d00d])
  • Align implementation of RoundDuration with adjusted spec text ([4a0d0264], see also Spec PR)

Other:

  • Bump various dependencies ([47701107], [f5427de9], [310d9d8b])
  • Allow launching and debugging tests (both Demitasse and Test262 suites) from the VSCode debug panel ([960d9b76], [7f7c19a1], [4ec6568e], [edcc668b])
  • Run the Test262 test suite against this polyfill, for various configurations of the resulting build artifact ([2331468d], [666c69da], [429273ec], [ff937782], [f885253f])
  • Remove various pieces of unused code, and add CI testing to detect unused code in PR review ([67f9f6bb], [63bdfcd1])
  • Drop the dependency on es-abstract ([d24575f2], [ad7e2e3a], [5b1bc5e2])
  • The polyfill's source was ported to TypeScript ([12e4d529], [ac78fd9d], [53f32e0f], [06b806c9], [66fdc765], [50b1c34b], [4724b017], [947a8a5e], [fdbf7e01], [fa60af6a], [da753f2f], [f4db8b0b], [4a38420d])
  • Document the release process for this polyfill ([c55818b6])

Readme

Source

Temporal Polyfill

Polyfill for TC39 Proposal: Temporal

This polyfill was kicked off by some of the champions of the Temporal proposal. The goal is to be ready for production use when the Temporal proposal reaches Stage 4, although like with all OSS work progress is dependent on contributors. We're eagerly welcoming to contributors who want to help build and maintain this polyfill. PRs are always welcome!

Note that this polyfill is not affiliated with TC39. Links to other polyfills can be found here.

This polyfill is compatible with Node.js 14 or later.

Roadmap

  • Fork non-production polyfill from tc39/proposal-temporal repo
  • Release initial pre-alpha to NPM at @js-temporal/polyfill
  • Sync the code in this repo with the handful of polyfill changes that have recently been made in the tc39/proposal-temporal repo
  • Release alpha version to NPM
  • Deprecate all other earlier Temporal polyfills
  • Optimize slow operations by reducing calls to Intl.DateTimeFormat constructor (see #7, #8, #10, #12)
  • Convert to TypeScript for better maintainability
  • Improve typing of sources for better maintainability
  • Migrate to JSBI for improved compile-time safety around BigInt operations.
  • Optimize performance of other slow operations
  • Release production version to NPM

Bug Reports and Feedback

If you think you've found a bug in the Temporal API itself (not the implementation in this polyfill), please file an issue in the tc39/proposal-temporal issue tracker issue tracker.

If you've found a bug in this polyfill—meaning that the implementation here doesn't match the Temporal spec—please file an issue in this repo's issue tracker.

Documentation

Reference documentation and examples for the Temporal API can be found here.

A cookbook to help you get started and learn the ins and outs of Temporal is available here

If you find a bug in the documentation, please file a bug over in the tc39/proposal-temporal issue tracker issue tracker.

Note that the Temporal documentation is in the process of being migrated to MDN. You can track the progress of the MDN migration here.

Usage

To install:

$ npm install @js-temporal/polyfill

CJS Usage:

const { Temporal, Intl, toTemporalInstant } = require('@js-temporal/polyfill');
Date.prototype.toTemporalInstant = toTemporalInstant;

Import the polyfill as an ES6 module:

import { Temporal, Intl, toTemporalInstant } from '@js-temporal/polyfill';
Date.prototype.toTemporalInstant = toTemporalInstant;

Note that this polyfill currently does not install a global Temporal object like a real implementation will. This behavior avoids hiding the global Temporal object in environments where a real Temporal implementation is present. See this issue for more background on this decision. Once JS engines start shipping with Temporal, we may decide to change this behavior to match built-in behavior more closely. See #2 to provide feedback or track this issue.

This polyfill ships ES2020 code for both CJS and ESM bundles - if your environment does not support ES2020, then please make sure to transpile the content of this package along with the rest of your code.

Contributing / Help Wanted

We're eagerly welcoming to contributors who want to help build and maintain this polyfill. PRs are always welcome!

Keywords

FAQs

Last updated on 10 Dec 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc