Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

temporal-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

temporal-polyfill

A spec-compliant Temporal JavaScript polyfill in 16kb

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
72K
increased by7.11%
Maintainers
1
Weekly downloads
 
Created
Source

temporal-polyfill

A spec-compliant Temporal JavaScript polyfill in 16kb.

Codepen

CDN link

Browser Support

Minimum required version if...ChromeEdgeSafariSafari iOSFirefoxNode
...transpiling to target environment36 (Jul 2014)14 (Aug 2016)10 (Sep 2016)10 (Sep 2016)52 (Mar 2017)12 (Apr 2019)
...leaving untranspiled60 (Jul 2017)79 (Jan 2020)11.1 (Mar 2018)11.3 (Mar 2018)55 (Aug 2017)12 (Apr 2019)
...using BigInt features67 (May 2018)79 (Jan 2020)14 (Sep 2020)14 (Sep 2020)68 (July 2019)12 (Apr 2019)

BigInt Considerations

This polyfill works fine in environments without BigInt. However, without BigInt, the following will throw errors:

❌ Avoid microseconds/nanoseconds✅ Use milliseconds instead
instant.epochMicrosecondsinstant.epochMilliseconds
instant.epochNanosecondsinstant.epochMilliseconds
Temporal.Instant.fromEpochMicroseconds(micro)Temporal.Instant.fromEpochMilliseconds(milli)
Temporal.Instant.fromEpochNanoseconds(nano)Temporal.Instant.fromEpochMilliseconds(milli)
new Temporal.Instant(nano)Temporal.Instant.fromEpochMilliseconds(milli)
zonedDateTime.epochMicrosecondszonedDateTime.epochMilliseconds
zonedDateTime.epochNanosecondszonedDateTime.epochMilliseconds
new Temporal.ZonedDateTime(nano, tz, cal)Temporal.Instant.fromEpochMilliseconds(milli).toZonedDateTimeISO()
Temporal.Instant.fromEpochMilliseconds(milli).toZonedDateTime(cal)

FYI, it is not possible to properly polyfill BigInt. More Information

Installation

npm install temporal-polyfill

A) Import globally:

import 'temporal-polyfill/global'

console.log(Temporal.Now.zonedDateTimeISO().toString())

B) Import as an ES module without side effects:

import { Temporal } from 'temporal-polyfill'

console.log(Temporal.Now.zonedDateTimeISO().toString())

C) The above techniques try using the built-in Temporal object and fall back to the polyfill. To guarantee using the polyfill, do this:

import { Temporal } from 'temporal-polyfill/impl'

console.log(Temporal.Now.zonedDateTimeISO().toString())

FAQs

Package last updated on 16 Feb 2023

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc