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

@f-fjs/intl-unified-numberformat

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-unified-numberformat

Ponyfill for intl unified numberformat proposal

latest
Source
npmnpm
Version
3.2.1
Version published
Maintainers
1
Created
Source

intl-unified-numberformat

A ponyfill/polyfill for intl-unified-numberformat. This wraps Intl.NumberFormat and has the exact same APIs.

Installation

npm install @f-fjs/intl-unified-numberformat

Requirements

This package requires the following capabilities:

  • Intl.PluralRules

Features

Everything in the https://github.com/tc39/proposal-unified-intl-numberformat proposal with the caveats below.

Caveats

Usage

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

import {UnifiedNumberFormat} from '@f-fjs/intl-unified-numberformat';
UnifiedNumberFormat.__addLocaleData(
  require('@f-fjs/intl-unified-numberformat/dist/locale-data/zh.json') // locale-data for zh
);
UnifiedNumberFormat.__addLocaleData(
  require('@f-fjs/intl-unified-numberformat/dist/locale-data/en.json') // locale-data for en
);

new UnifiedNumberFormat('zh', {
  style: 'unit',
  unit: 'bit',
  unitDisplay: 'long',
}).format(1000); // 1,000比特

To use this as a polyfill, override Intl.NumberFormat as below:

import '@f-fjs/intl-unified-numberformat/polyfill';
if (typeof Intl.NumberFormat.__addLocaleData === 'function') {
  Intl.NumberFormat.__addLocaleData(
    require('@f-fjs/intl-unified-numberformat/dist/locale-data/zh.json') // locale-data for zh
  );
  Intl.NumberFormat.__addLocaleData(
    require('@f-fjs/intl-unified-numberformat/dist/locale-data/en.json') // locale-data for en
  );
}

new Intl.NumberFormat('zh', {
  style: 'unit',
  unit: 'bit',
  unitDisplay: 'long',
}).format(1000); // 1,000比特

new Intl.NumberFormat('en-US', {
  notation: 'engineering',
}).format(987654321); // 987.7E6

new Intl.NumberFormat('zh', {
  style: 'currency',
  currency: 'EUR',
  currencySign: 'accounting',
}).format(-100); // (€100.00)

Supported Units

Currently intl-unified-numberformat has a list of sanctioned units as below

type Unit =
  | 'acre'
  | 'bit'
  | 'byte'
  | 'celsius'
  | 'centimeter'
  | 'day'
  | 'degree'
  | 'fahrenheit'
  | 'fluid-ounce'
  | 'foot'
  | 'gallon'
  | 'gigabit'
  | 'gigabyte'
  | 'gram'
  | 'hectare'
  | 'hour'
  | 'inch'
  | 'kilobit'
  | 'kilobyte'
  | 'kilogram'
  | 'kilometer'
  | 'liter'
  | 'megabit'
  | 'megabyte'
  | 'meter'
  | 'mile'
  | 'mile-scandinavian'
  | 'millimeter'
  | 'milliliter'
  | 'millisecond'
  | 'minute'
  | 'month'
  | 'ounce'
  | 'percent'
  | 'petabyte'
  | 'pound'
  | 'second'
  | 'stone'
  | 'terabit'
  | 'terabyte'
  | 'week'
  | 'yard'
  | 'year';

Keywords

polyfill

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