@formatjs/intl-unified-numberformat
Ponyfill for intl unified numberformat proposal
Last updated 7 years ago by longlho .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @formatjs/intl-unified-numberformat 
SYNC missed versions from official npm registry.

intl-unified-numberformat

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

Installation

npm install @formatjs/intl-unified-numberformat

Requirements

This package requires the following capabilities:

Features

  1. unit, unitDisplay, style: unit and sanctioned units are supported

Caveats

  1. formatToParts does not include the unit part yet.

Usage

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

import {UnifiedNumberFormat} from '@formatjs/intl-unified-numberformat';
UnifiedNumberFormat.__addLocaleData(
  require('@formatjs/intl-unified-numberformat/dist/locale-data/zh.json') // locale-data for zh
);
UnifiedNumberFormat.__addLocaleData(
  require('@formatjs/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 '@formatjs/intl-unified-numberformat/polyfill';
if (typeof Intl.NumberFormat.__addUnitLocaleData === 'function') {
  Intl.NumberFormat.__addUnitLocaleData(
    require('@formatjs/intl-unified-numberformat/dist/locale-data/zh.json') // locale-data for zh
  );
  Intl.NumberFormat.__addUnitLocaleData(
    require('@formatjs/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比特

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';

Current Tags

  • 3.3.7                                ...           latest (7 years ago)
  • 2.1.4-alpha.7                                ...           next (7 years ago)

43 Versions

  • 3.3.7 [deprecated]           ...           7 years ago
  • 3.3.6 [deprecated]           ...           7 years ago
  • 3.3.5 [deprecated]           ...           7 years ago
  • 3.3.4 [deprecated]           ...           7 years ago
  • 3.3.3 [deprecated]           ...           7 years ago
  • 3.3.2 [deprecated]           ...           7 years ago
  • 3.3.1 [deprecated]           ...           7 years ago
  • 3.3.0 [deprecated]           ...           7 years ago
  • 3.2.0 [deprecated]           ...           7 years ago
  • 3.1.0 [deprecated]           ...           7 years ago
  • 3.0.4 [deprecated]           ...           7 years ago
  • 3.0.3 [deprecated]           ...           7 years ago
  • 3.0.2 [deprecated]           ...           7 years ago
  • 3.0.1 [deprecated]           ...           7 years ago
  • 3.0.0 [deprecated]           ...           7 years ago
  • 2.2.0 [deprecated]           ...           7 years ago
  • 2.1.8 [deprecated]           ...           7 years ago
  • 2.1.7 [deprecated]           ...           7 years ago
  • 2.1.6 [deprecated]           ...           7 years ago
  • 2.1.5 [deprecated]           ...           7 years ago
  • 2.1.4 [deprecated]           ...           7 years ago
  • 2.1.4-alpha.7                                ...           7 years ago
  • 2.1.4-alpha.6                                ...           7 years ago
  • 2.1.3 [deprecated]           ...           7 years ago
  • 2.1.2 [deprecated]           ...           7 years ago
  • 2.1.1 [deprecated]           ...           7 years ago
  • 2.1.0 [deprecated]           ...           7 years ago
  • 2.0.1 [deprecated]           ...           7 years ago
  • 2.0.0 [deprecated]           ...           7 years ago
  • 1.0.1 [deprecated]           ...           7 years ago
  • 1.0.0 [deprecated]           ...           7 years ago
  • 0.5.2 [deprecated]           ...           7 years ago
  • 0.5.1 [deprecated]           ...           7 years ago
  • 0.5.0 [deprecated]           ...           7 years ago
  • 0.4.9 [deprecated]           ...           7 years ago
  • 0.4.8 [deprecated]           ...           7 years ago
  • 0.4.6 [deprecated]           ...           7 years ago
  • 0.4.5 [deprecated]           ...           7 years ago
  • 0.4.3 [deprecated]           ...           7 years ago
  • 0.4.2 [deprecated]           ...           7 years ago
  • 0.4.1 [deprecated]           ...           7 years ago
  • 0.4.0 [deprecated]           ...           7 years ago
  • 0.2.0 [deprecated]           ...           7 years ago
Maintainers (2)
Downloads
Total 109
Today 0
This Week 0
This Month 29
Last Day 0
Last Week 1
Last Month 71
Dependencies (1)
Dev Dependencies (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE