Socket
Socket
Sign inDemoInstall

@formatjs/intl-unified-numberformat

Package Overview
Dependencies
Maintainers
2
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@formatjs/intl-unified-numberformat - npm Package Compare versions

Comparing version 0.2.0 to 0.4.0

lib/core.d.ts

17

CHANGELOG.md

@@ -6,2 +6,19 @@ # Change Log

# [0.4.0](https://github.com/formatjs/formatjs/compare/@formatjs/intl-unified-numberformat@0.2.0...@formatjs/intl-unified-numberformat@0.4.0) (2019-08-19)
### Bug Fixes
* **@formatjs/intl-utils:** change default quarter to false in selectUnit ([dadab10](https://github.com/formatjs/formatjs/commit/dadab10))
### Features
* **@formatjs/intl-unified-numberformat:** add polyfill option ([4c1d692](https://github.com/formatjs/formatjs/commit/4c1d692))
* **formatjs-extract-cldr-data:** fix unit extraction ([7e54a0b](https://github.com/formatjs/formatjs/commit/7e54a0b))
# 0.2.0 (2019-08-16)

@@ -8,0 +25,0 @@

4

dist/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var units_1 = require("./units");
exports.UnifiedNumberFormat = units_1.default;
var core_1 = require("./core");
exports.UnifiedNumberFormat = core_1.default;

@@ -1,2 +0,2 @@

export { default as UnifiedNumberFormat } from './units';
export { default as UnifiedNumberFormat } from './core';
export { Unit } from './units-constants';

@@ -1,1 +0,1 @@

export { default as UnifiedNumberFormat } from './units';
export { default as UnifiedNumberFormat } from './core';

@@ -1,161 +0,1 @@

export declare const enum Unit {
'per' = "per",
'g-force' = "g-force",
'meter-per-second-squared' = "meter-per-second-squared",
'revolution' = "revolution",
'radian' = "radian",
'degree' = "degree",
'arc-minute' = "arc-minute",
'arc-second' = "arc-second",
'square-kilometer' = "square-kilometer",
'hectare' = "hectare",
'square-meter' = "square-meter",
'square-centimeter' = "square-centimeter",
'square-mile' = "square-mile",
'acre' = "acre",
'square-yard' = "square-yard",
'square-foot' = "square-foot",
'square-inch' = "square-inch",
'dunam' = "dunam",
'karat' = "karat",
'milligram-per-deciliter' = "milligram-per-deciliter",
'millimole-per-liter' = "millimole-per-liter",
'part-per-million' = "part-per-million",
'percent' = "percent",
'permille' = "permille",
'permyriad' = "permyriad",
'mole' = "mole",
'liter-per-kilometer' = "liter-per-kilometer",
'liter-per-100kilometers' = "liter-per-100kilometers",
'mile-per-gallon' = "mile-per-gallon",
'mile-per-gallon-imperial' = "mile-per-gallon-imperial",
'petabyte' = "petabyte",
'terabyte' = "terabyte",
'terabit' = "terabit",
'gigabyte' = "gigabyte",
'gigabit' = "gigabit",
'megabyte' = "megabyte",
'megabit' = "megabit",
'kilobyte' = "kilobyte",
'kilobit' = "kilobit",
'byte' = "byte",
'bit' = "bit",
'century' = "century",
'year' = "year",
'month' = "month",
'week' = "week",
'day' = "day",
'hour' = "hour",
'minute' = "minute",
'second' = "second",
'millisecond' = "millisecond",
'microsecond' = "microsecond",
'nanosecond' = "nanosecond",
'ampere' = "ampere",
'milliampere' = "milliampere",
'ohm' = "ohm",
'volt' = "volt",
'kilocalorie' = "kilocalorie",
'calorie' = "calorie",
'foodcalorie' = "foodcalorie",
'kilojoule' = "kilojoule",
'joule' = "joule",
'kilowatt-hour' = "kilowatt-hour",
'electronvolt' = "electronvolt",
'british-thermal-unit' = "british-thermal-unit",
'pound-force' = "pound-force",
'newton' = "newton",
'gigahertz' = "gigahertz",
'megahertz' = "megahertz",
'kilohertz' = "kilohertz",
'hertz' = "hertz",
'kilometer' = "kilometer",
'meter' = "meter",
'decimeter' = "decimeter",
'centimeter' = "centimeter",
'millimeter' = "millimeter",
'micrometer' = "micrometer",
'nanometer' = "nanometer",
'picometer' = "picometer",
'mile' = "mile",
'yard' = "yard",
'foot' = "foot",
'inch' = "inch",
'parsec' = "parsec",
'light-year' = "light-year",
'astronomical-unit' = "astronomical-unit",
'furlong' = "furlong",
'fathom' = "fathom",
'nautical-mile' = "nautical-mile",
'mile-scandinavian' = "mile-scandinavian",
'point' = "point",
'solar-radius' = "solar-radius",
'lux' = "lux",
'solar-luminosity' = "solar-luminosity",
'metric-ton' = "metric-ton",
'kilogram' = "kilogram",
'gram' = "gram",
'milligram' = "milligram",
'microgram' = "microgram",
'ton' = "ton",
'stone' = "stone",
'pound' = "pound",
'ounce' = "ounce",
'ounce-troy' = "ounce-troy",
'carat' = "carat",
'dalton' = "dalton",
'earth-mass' = "earth-mass",
'solar-mass' = "solar-mass",
'gigawatt' = "gigawatt",
'megawatt' = "megawatt",
'kilowatt' = "kilowatt",
'watt' = "watt",
'milliwatt' = "milliwatt",
'horsepower' = "horsepower",
'hectopascal' = "hectopascal",
'millimeter-of-mercury' = "millimeter-of-mercury",
'pound-per-square-inch' = "pound-per-square-inch",
'inch-hg' = "inch-hg",
'millibar' = "millibar",
'atmosphere' = "atmosphere",
'kilopascal' = "kilopascal",
'megapascal' = "megapascal",
'kilometer-per-hour' = "kilometer-per-hour",
'meter-per-second' = "meter-per-second",
'mile-per-hour' = "mile-per-hour",
'knot' = "knot",
'generic' = "generic",
'celsius' = "celsius",
'fahrenheit' = "fahrenheit",
'kelvin' = "kelvin",
'pound-foot' = "pound-foot",
'newton-meter' = "newton-meter",
'cubic-kilometer' = "cubic-kilometer",
'cubic-meter' = "cubic-meter",
'cubic-centimeter' = "cubic-centimeter",
'cubic-mile' = "cubic-mile",
'cubic-yard' = "cubic-yard",
'cubic-foot' = "cubic-foot",
'cubic-inch' = "cubic-inch",
'megaliter' = "megaliter",
'hectoliter' = "hectoliter",
'liter' = "liter",
'deciliter' = "deciliter",
'centiliter' = "centiliter",
'milliliter' = "milliliter",
'pint-metric' = "pint-metric",
'cup-metric' = "cup-metric",
'acre-foot' = "acre-foot",
'bushel' = "bushel",
'gallon' = "gallon",
'gallon-imperial' = "gallon-imperial",
'quart' = "quart",
'pint' = "pint",
'cup' = "cup",
'fluid-ounce' = "fluid-ounce",
'fluid-ounce-imperial' = "fluid-ounce-imperial",
'tablespoon' = "tablespoon",
'teaspoon' = "teaspoon",
'barrel' = "barrel",
'coordinateUnit' = "coordinateUnit"
}
export declare 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';
{
"name": "@formatjs/intl-unified-numberformat",
"version": "0.2.0",
"version": "0.4.0",
"description": "Ponyfill for intl unified numberformat proposal",

@@ -27,7 +27,7 @@ "keywords": [

"devDependencies": {
"formatjs-extract-cldr-data": "^9.5.0"
"formatjs-extract-cldr-data": "^9.6.0"
},
"scripts": {
"build": "npm run cldr && npm run compile",
"cldr": "node scripts/cldr",
"cldr": "ts-node --project tsconfig.cjs.json scripts/cldr",
"clean": "rimraf dist lib",

@@ -41,3 +41,3 @@ "compile": "tsc && tsc -p tsconfig.cjs.json",

},
"gitHead": "1193b34868be8414b02ba4d103c79c1061dcb470"
"gitHead": "8731e3472e76505e0383cfbd9e31326ae877140d"
}
# `intl-unified-numberformat`
A ponyfill for [`intl-unified-numberformat`](https://github.com/tc39/proposal-unified-intl-numberformat). This wraps `Intl.NumberFormat` and has the exact same APIs.
A ponyfill/polyfill for [`intl-unified-numberformat`](https://github.com/tc39/proposal-unified-intl-numberformat). This wraps `Intl.NumberFormat` and has the exact same APIs.

@@ -17,2 +17,10 @@ ## Installation

# Features
1. `unit`, `unitDisplay`, `style: unit` and sanctioned units are supported
## Caveats
1. `formatToParts` does not include the `unit` part yet.
# Usage

@@ -23,17 +31,86 @@

```tsx
import {UnifiedNumberFormat} from '@formatjs/intl-unified-numberformat'
import {UnifiedNumberFormat} from '@formatjs/intl-unified-numberformat';
UnifiedNumberFormat.__addUnitLocaleData(
'bit',
...require('../dist/locale-data/bit/zh') // locale-data for zh for unit `bit`
require('@formatjs/intl-unified-numberformat/dist/locale-data/zh.json') // locale-data for zh
);
UnifiedNumberFormat.__addUnitLocaleData(
'bit',
...require('../dist/locale-data/bit/en') // locale-data for zh for unit `bit`
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比特
style: 'unit',
unit: 'bit',
unitDisplay: 'long',
}).format(1000); // 1,000比特
```
To use this as a polyfill, override `Intl.NumberFormat` as below:
```tsx
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](https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_diff_out.html#sec-issanctionedsimpleunitidentifier) has a list of sanctioned units as below
```tsx
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';
```
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