Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@f-fjs/intl-relativetimeformat

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@f-fjs/intl-relativetimeformat

Formats JavaScript dates to relative time strings.

latest
Source
npmnpm
Version
4.5.10
Version published
Maintainers
1
Created
Source

Intl RelativeTimeFormat

A spec-compliant polyfill/ponyfill for Intl.RelativeTimeFormat fully tested by the official ECMAScript Conformance test suite

npm Version size

Installation

npm install @f-fjs/intl-relativetimeformat

Requirements

This package requires the following capabilities:

  • Intl.PluralRules

NOTE: formatToParts only works on Node 10+ due to lack of Intl.NumberFormat.prototype.formatToParts natively

Usage

Ponyfill

To use the ponyfill, import it along with its data:

import IntlRelativeTimeFormat from '@f-fjs/intl-relativetimeformat';
// locale-data for zh
IntlRelativeTimeFormat.__addLocaleData(
  require('@f-fjs/intl-relativetimeformat/dist/locale-data/zh.json')
);

// locale-data for zh
IntlRelativeTimeFormat.__addLocaleData(
  require('@f-fjs/intl-relativetimeformat/dist/locale-data/en.json')
);

new IntlRelativeTimeFormat('zh-CN').format(-1, 'second'); // '1秒钟前'

Polyfill

To use the polyfill, just import it to make sure that a fully functional Intl.RelativeTimeFormat is available in your environment:

import '@f-fjs/intl-relativetimeformat/polyfill';
import '@f-fjs/intl-relativetimeformat/dist/locale-data/de'; // Add locale data for de

If you want to polyfill all locales (e.g for Node):

import '@f-fjs/intl-relativetimeformat/polyfill-locales';

Tests

This library is fully test262-compliant.

Keywords

intl

FAQs

Package last updated on 13 Mar 2020

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