@formatjs/intl-numberformat 8.15.6 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/polyfill.js CHANGED
@@ -1,14 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var core_1 = require("./src/core");
4
- var to_locale_string_1 = require("./src/to_locale_string");
5
- var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
6
- var should_polyfill_1 = require("./should-polyfill");
7
- if ((0, should_polyfill_1.shouldPolyfill)()) {
8
- (0, ecma402_abstract_1.defineProperty)(Intl, 'NumberFormat', { value: core_1.NumberFormat });
9
- (0, ecma402_abstract_1.defineProperty)(Number.prototype, 'toLocaleString', {
1
+ import { NumberFormat } from './src/core.js';
2
+ import { toLocaleString as _toLocaleString } from './src/to_locale_string.js';
3
+ import { defineProperty } from '@formatjs/ecma402-abstract';
4
+ import { shouldPolyfill } from './should-polyfill.js';
5
+ if (shouldPolyfill()) {
6
+ defineProperty(Intl, 'NumberFormat', { value: NumberFormat });
7
+ defineProperty(Number.prototype, 'toLocaleString', {
10
8
  value: function toLocaleString(locales, options) {
11
- return (0, to_locale_string_1.toLocaleString)(this, locales, options);
9
+ return _toLocaleString(this, locales, options);
12
10
  },
13
11
  });
14
12
  }
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shouldPolyfill = shouldPolyfill;
4
- var intl_localematcher_1 = require("@formatjs/intl-localematcher");
5
- var supported_locales_generated_1 = require("./supported-locales.generated");
1
+ import { match } from '@formatjs/intl-localematcher';
2
+ import { supportedLocales } from './supported-locales.generated.js';
6
3
  /**
7
4
  * Check if this is old Node that only supports en
8
5
  * @returns
@@ -32,7 +29,7 @@ function supportsES2020() {
32
29
  return false;
33
30
  }
34
31
  }
35
- catch (e) {
32
+ catch (_a) {
36
33
  return false;
37
34
  }
38
35
  return true;
@@ -57,7 +54,7 @@ function supportsES2023() {
57
54
  }).format(1e8);
58
55
  return s === '100.00M';
59
56
  }
60
- catch (e) {
57
+ catch (_a) {
61
58
  return false;
62
59
  }
63
60
  }
@@ -68,7 +65,7 @@ function supportedLocalesOf(locale) {
68
65
  var locales = Array.isArray(locale) ? locale : [locale];
69
66
  return Intl.NumberFormat.supportedLocalesOf(locales).length === locales.length;
70
67
  }
71
- function shouldPolyfill(locale) {
68
+ export function shouldPolyfill(locale) {
72
69
  if (locale === void 0) { locale = 'en'; }
73
70
  if (typeof Intl === 'undefined' ||
74
71
  !('NumberFormat' in Intl) ||
@@ -76,6 +73,6 @@ function shouldPolyfill(locale) {
76
73
  !supportsES2023() ||
77
74
  onlySupportsEn() ||
78
75
  !supportedLocalesOf(locale)) {
79
- return locale ? (0, intl_localematcher_1.match)([locale], supported_locales_generated_1.supportedLocales, 'en') : undefined;
76
+ return locale ? match([locale], supportedLocales, 'en') : undefined;
80
77
  }
81
78
  }
package/src/core.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NumberFormatConstructor, NumberFormat as NumberFormatType } from './types';
1
+ import { NumberFormatConstructor, NumberFormat as NumberFormatType } from './types.js';
2
2
  export type NumberFormat = NumberFormatType;
3
3
  /**
4
4
  * https://tc39.es/ecma402/#sec-intl-numberformat-constructor
package/src/core.js CHANGED
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NumberFormat = void 0;
4
- var tslib_1 = require("tslib");
5
- var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
6
- var currency_digits_generated_1 = require("./currency-digits.generated");
7
- var numbering_systems_generated_1 = require("./numbering-systems.generated");
8
- var get_internal_slots_1 = tslib_1.__importDefault(require("./get_internal_slots"));
1
+ import { CanonicalizeLocaleList, FormatNumeric, FormatNumericRange, FormatNumericRangeToParts, FormatNumericToParts, InitializeNumberFormat, OrdinaryHasInstance, SupportedLocales, ToIntlMathematicalValue, createMemoizedPluralRules, defineProperty, invariant, } from '@formatjs/ecma402-abstract';
2
+ import { currencyDigitsData } from './currency-digits.generated.js';
3
+ import { numberingSystemNames } from './numbering-systems.generated.js';
4
+ import getInternalSlots from './get_internal_slots.js';
9
5
  var RESOLVED_OPTIONS_KEYS = [
10
6
  'locale',
11
7
  'numberingSystem',
@@ -28,24 +24,24 @@ var RESOLVED_OPTIONS_KEYS = [
28
24
  /**
29
25
  * https://tc39.es/ecma402/#sec-intl-numberformat-constructor
30
26
  */
31
- exports.NumberFormat = function (locales, options) {
27
+ export var NumberFormat = function (locales, options) {
32
28
  // Cannot use `new.target` bc of IE11 & TS transpiles it to something else
33
- if (!this || !(0, ecma402_abstract_1.OrdinaryHasInstance)(exports.NumberFormat, this)) {
34
- return new exports.NumberFormat(locales, options);
29
+ if (!this || !OrdinaryHasInstance(NumberFormat, this)) {
30
+ return new NumberFormat(locales, options);
35
31
  }
36
- (0, ecma402_abstract_1.InitializeNumberFormat)(this, locales, options, {
37
- getInternalSlots: get_internal_slots_1.default,
38
- localeData: exports.NumberFormat.localeData,
39
- availableLocales: exports.NumberFormat.availableLocales,
40
- getDefaultLocale: exports.NumberFormat.getDefaultLocale,
41
- currencyDigitsData: currency_digits_generated_1.currencyDigitsData,
42
- numberingSystemNames: numbering_systems_generated_1.numberingSystemNames,
32
+ InitializeNumberFormat(this, locales, options, {
33
+ getInternalSlots: getInternalSlots,
34
+ localeData: NumberFormat.localeData,
35
+ availableLocales: NumberFormat.availableLocales,
36
+ getDefaultLocale: NumberFormat.getDefaultLocale,
37
+ currencyDigitsData: currencyDigitsData,
38
+ numberingSystemNames: numberingSystemNames,
43
39
  });
44
- var internalSlots = (0, get_internal_slots_1.default)(this);
40
+ var internalSlots = getInternalSlots(this);
45
41
  var dataLocale = internalSlots.dataLocale;
46
- var dataLocaleData = exports.NumberFormat.localeData[dataLocale];
47
- (0, ecma402_abstract_1.invariant)(dataLocaleData !== undefined, "Cannot load locale-dependent data for ".concat(dataLocale, "."));
48
- internalSlots.pl = (0, ecma402_abstract_1.createMemoizedPluralRules)(dataLocale, {
42
+ var dataLocaleData = NumberFormat.localeData[dataLocale];
43
+ invariant(dataLocaleData !== undefined, "Cannot load locale-dependent data for ".concat(dataLocale, "."));
44
+ internalSlots.pl = createMemoizedPluralRules(dataLocale, {
49
45
  minimumFractionDigits: internalSlots.minimumFractionDigits,
50
46
  maximumFractionDigits: internalSlots.maximumFractionDigits,
51
47
  minimumIntegerDigits: internalSlots.minimumIntegerDigits,
@@ -55,18 +51,18 @@ exports.NumberFormat = function (locales, options) {
55
51
  return this;
56
52
  };
57
53
  function formatToParts(x) {
58
- return (0, ecma402_abstract_1.FormatNumericToParts)(this, (0, ecma402_abstract_1.ToIntlMathematicalValue)(x), {
59
- getInternalSlots: get_internal_slots_1.default,
54
+ return FormatNumericToParts(this, ToIntlMathematicalValue(x), {
55
+ getInternalSlots: getInternalSlots,
60
56
  });
61
57
  }
62
58
  function formatRange(start, end) {
63
- return (0, ecma402_abstract_1.FormatNumericRange)(this, (0, ecma402_abstract_1.ToIntlMathematicalValue)(start), (0, ecma402_abstract_1.ToIntlMathematicalValue)(end), {
64
- getInternalSlots: get_internal_slots_1.default,
59
+ return FormatNumericRange(this, ToIntlMathematicalValue(start), ToIntlMathematicalValue(end), {
60
+ getInternalSlots: getInternalSlots,
65
61
  });
66
62
  }
67
63
  function formatRangeToParts(start, end) {
68
- return (0, ecma402_abstract_1.FormatNumericRangeToParts)(this, (0, ecma402_abstract_1.ToIntlMathematicalValue)(start), (0, ecma402_abstract_1.ToIntlMathematicalValue)(end), {
69
- getInternalSlots: get_internal_slots_1.default,
64
+ return FormatNumericRangeToParts(this, ToIntlMathematicalValue(start), ToIntlMathematicalValue(end), {
65
+ getInternalSlots: getInternalSlots,
70
66
  });
71
67
  }
72
68
  try {
@@ -77,25 +73,25 @@ try {
77
73
  configurable: true,
78
74
  });
79
75
  }
80
- catch (e) {
76
+ catch (_a) {
81
77
  // In older browser (e.g Chrome 36 like polyfill-fastly.io)
82
78
  // TypeError: Cannot redefine property: name
83
79
  }
84
- (0, ecma402_abstract_1.defineProperty)(exports.NumberFormat.prototype, 'formatToParts', {
80
+ defineProperty(NumberFormat.prototype, 'formatToParts', {
85
81
  value: formatToParts,
86
82
  });
87
- (0, ecma402_abstract_1.defineProperty)(exports.NumberFormat.prototype, 'formatRange', {
83
+ defineProperty(NumberFormat.prototype, 'formatRange', {
88
84
  value: formatRange,
89
85
  });
90
- (0, ecma402_abstract_1.defineProperty)(exports.NumberFormat.prototype, 'formatRangeToParts', {
86
+ defineProperty(NumberFormat.prototype, 'formatRangeToParts', {
91
87
  value: formatRangeToParts,
92
88
  });
93
- (0, ecma402_abstract_1.defineProperty)(exports.NumberFormat.prototype, 'resolvedOptions', {
89
+ defineProperty(NumberFormat.prototype, 'resolvedOptions', {
94
90
  value: function resolvedOptions() {
95
- if (typeof this !== 'object' || !(0, ecma402_abstract_1.OrdinaryHasInstance)(exports.NumberFormat, this)) {
91
+ if (typeof this !== 'object' || !OrdinaryHasInstance(NumberFormat, this)) {
96
92
  throw TypeError('Method Intl.NumberFormat.prototype.resolvedOptions called on incompatible receiver');
97
93
  }
98
- var internalSlots = (0, get_internal_slots_1.default)(this);
94
+ var internalSlots = getInternalSlots(this);
99
95
  var ro = {};
100
96
  for (var _i = 0, RESOLVED_OPTIONS_KEYS_1 = RESOLVED_OPTIONS_KEYS; _i < RESOLVED_OPTIONS_KEYS_1.length; _i++) {
101
97
  var key = RESOLVED_OPTIONS_KEYS_1[_i];
@@ -120,16 +116,14 @@ var formatDescriptor = {
120
116
  enumerable: false,
121
117
  configurable: true,
122
118
  get: function () {
123
- if (typeof this !== 'object' || !(0, ecma402_abstract_1.OrdinaryHasInstance)(exports.NumberFormat, this)) {
119
+ if (typeof this !== 'object' || !OrdinaryHasInstance(NumberFormat, this)) {
124
120
  throw TypeError('Intl.NumberFormat format property accessor called on incompatible receiver');
125
121
  }
126
- var internalSlots = (0, get_internal_slots_1.default)(this);
122
+ var internalSlots = getInternalSlots(this);
127
123
  var boundFormat = internalSlots.boundFormat;
128
124
  if (boundFormat === undefined) {
129
125
  // https://tc39.es/proposal-unified-intl-numberformat/section11/numberformat_diff_out.html#sec-number-format-functions
130
- boundFormat = function (value) {
131
- return (0, ecma402_abstract_1.FormatNumeric)(internalSlots, (0, ecma402_abstract_1.ToIntlMathematicalValue)(value));
132
- };
126
+ boundFormat = function (value) { return FormatNumeric(internalSlots, ToIntlMathematicalValue(value)); };
133
127
  try {
134
128
  // https://github.com/tc39/test262/blob/master/test/intl402/NumberFormat/prototype/format/format-function-name.js
135
129
  Object.defineProperty(boundFormat, 'name', {
@@ -139,7 +133,7 @@ var formatDescriptor = {
139
133
  value: '',
140
134
  });
141
135
  }
142
- catch (e) {
136
+ catch (_a) {
143
137
  // In older browser (e.g Chrome 36 like polyfill-fastly.io)
144
138
  // TypeError: Cannot redefine property: name
145
139
  }
@@ -157,18 +151,18 @@ try {
157
151
  value: 'get format',
158
152
  });
159
153
  }
160
- catch (e) {
154
+ catch (_b) {
161
155
  // In older browser (e.g Chrome 36 like polyfill-fastly.io)
162
156
  // TypeError: Cannot redefine property: name
163
157
  }
164
- Object.defineProperty(exports.NumberFormat.prototype, 'format', formatDescriptor);
158
+ Object.defineProperty(NumberFormat.prototype, 'format', formatDescriptor);
165
159
  // Static properties
166
- (0, ecma402_abstract_1.defineProperty)(exports.NumberFormat, 'supportedLocalesOf', {
160
+ defineProperty(NumberFormat, 'supportedLocalesOf', {
167
161
  value: function supportedLocalesOf(locales, options) {
168
- return (0, ecma402_abstract_1.SupportedLocales)(exports.NumberFormat.availableLocales, (0, ecma402_abstract_1.CanonicalizeLocaleList)(locales), options);
162
+ return SupportedLocales(NumberFormat.availableLocales, CanonicalizeLocaleList(locales), options);
169
163
  },
170
164
  });
171
- exports.NumberFormat.__addLocaleData = function __addLocaleData() {
165
+ NumberFormat.__addLocaleData = function __addLocaleData() {
172
166
  var data = [];
173
167
  for (var _i = 0; _i < arguments.length; _i++) {
174
168
  data[_i] = arguments[_i];
@@ -178,17 +172,17 @@ exports.NumberFormat.__addLocaleData = function __addLocaleData() {
178
172
  var minimizedLocale = new Intl.Locale(locale)
179
173
  .minimize()
180
174
  .toString();
181
- exports.NumberFormat.localeData[locale] = exports.NumberFormat.localeData[minimizedLocale] =
175
+ NumberFormat.localeData[locale] = NumberFormat.localeData[minimizedLocale] =
182
176
  d;
183
- exports.NumberFormat.availableLocales.add(minimizedLocale);
184
- exports.NumberFormat.availableLocales.add(locale);
185
- if (!exports.NumberFormat.__defaultLocale) {
186
- exports.NumberFormat.__defaultLocale = minimizedLocale;
177
+ NumberFormat.availableLocales.add(minimizedLocale);
178
+ NumberFormat.availableLocales.add(locale);
179
+ if (!NumberFormat.__defaultLocale) {
180
+ NumberFormat.__defaultLocale = minimizedLocale;
187
181
  }
188
182
  }
189
183
  };
190
- exports.NumberFormat.__addUnitData = function __addUnitData(locale, unitsData) {
191
- var _a = exports.NumberFormat.localeData, _b = locale, existingData = _a[_b];
184
+ NumberFormat.__addUnitData = function __addUnitData(locale, unitsData) {
185
+ var _a = NumberFormat.localeData, _b = locale, existingData = _a[_b];
192
186
  if (!existingData) {
193
187
  throw new Error("Locale data for \"".concat(locale, "\" has not been loaded in NumberFormat. \nPlease __addLocaleData before adding additional unit data"));
194
188
  }
@@ -199,17 +193,17 @@ exports.NumberFormat.__addUnitData = function __addUnitData(locale, unitsData) {
199
193
  existingData.units.compound[unit] = unitsData.compound[unit];
200
194
  }
201
195
  };
202
- exports.NumberFormat.__defaultLocale = '';
203
- exports.NumberFormat.localeData = {};
204
- exports.NumberFormat.availableLocales = new Set();
205
- exports.NumberFormat.getDefaultLocale = function () {
206
- return exports.NumberFormat.__defaultLocale;
196
+ NumberFormat.__defaultLocale = '';
197
+ NumberFormat.localeData = {};
198
+ NumberFormat.availableLocales = new Set();
199
+ NumberFormat.getDefaultLocale = function () {
200
+ return NumberFormat.__defaultLocale;
207
201
  };
208
- exports.NumberFormat.polyfilled = true;
202
+ NumberFormat.polyfilled = true;
209
203
  try {
210
204
  // IE11 does not have Symbol
211
205
  if (typeof Symbol !== 'undefined') {
212
- Object.defineProperty(exports.NumberFormat.prototype, Symbol.toStringTag, {
206
+ Object.defineProperty(NumberFormat.prototype, Symbol.toStringTag, {
213
207
  configurable: true,
214
208
  enumerable: false,
215
209
  writable: false,
@@ -217,26 +211,26 @@ try {
217
211
  });
218
212
  }
219
213
  // https://github.com/tc39/test262/blob/master/test/intl402/NumberFormat/length.js
220
- Object.defineProperty(exports.NumberFormat.prototype.constructor, 'length', {
214
+ Object.defineProperty(NumberFormat.prototype.constructor, 'length', {
221
215
  configurable: true,
222
216
  enumerable: false,
223
217
  writable: false,
224
218
  value: 0,
225
219
  });
226
220
  // https://github.com/tc39/test262/blob/master/test/intl402/NumberFormat/supportedLocalesOf/length.js
227
- Object.defineProperty(exports.NumberFormat.supportedLocalesOf, 'length', {
221
+ Object.defineProperty(NumberFormat.supportedLocalesOf, 'length', {
228
222
  configurable: true,
229
223
  enumerable: false,
230
224
  writable: false,
231
225
  value: 1,
232
226
  });
233
- Object.defineProperty(exports.NumberFormat, 'prototype', {
227
+ Object.defineProperty(NumberFormat, 'prototype', {
234
228
  configurable: false,
235
229
  enumerable: false,
236
230
  writable: false,
237
- value: exports.NumberFormat.prototype,
231
+ value: NumberFormat.prototype,
238
232
  });
239
233
  }
240
- catch (e) {
234
+ catch (_c) {
241
235
  // Meta fix so we're test262-compliant, not important
242
236
  }
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.currencyDigitsData = void 0;
4
- exports.currencyDigitsData = {
1
+ export var currencyDigitsData = {
5
2
  "ADP": 0,
6
3
  "AFN": 0,
7
4
  "ALL": 0,
@@ -1,9 +1,6 @@
1
- "use strict";
2
1
  // Type-only circular import
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.default = getInternalSlots;
5
2
  var internalSlotMap = new WeakMap();
6
- function getInternalSlots(x) {
3
+ export default function getInternalSlots(x) {
7
4
  var internalSlots = internalSlotMap.get(x);
8
5
  if (!internalSlots) {
9
6
  internalSlots = Object.create(null);
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.numberingSystemNames = void 0;
4
- exports.numberingSystemNames = ["adlm", "ahom", "arab", "arabext", "armn", "armnlow", "bali", "beng", "bhks", "brah", "cakm", "cham", "cyrl", "deva", "diak", "ethi", "fullwide", "gara", "geor", "gong", "gonm", "grek", "greklow", "gujr", "gukh", "guru", "hanidays", "hanidec", "hans", "hansfin", "hant", "hantfin", "hebr", "hmng", "hmnp", "java", "jpan", "jpanfin", "jpanyear", "kali", "kawi", "khmr", "knda", "krai", "lana", "lanatham", "laoo", "latn", "lepc", "limb", "mathbold", "mathdbl", "mathmono", "mathsanb", "mathsans", "mlym", "modi", "mong", "mroo", "mtei", "mymr", "mymrepka", "mymrpao", "mymrshan", "mymrtlng", "nagm", "newa", "nkoo", "olck", "onao", "orya", "osma", "outlined", "rohg", "roman", "romanlow", "saur", "segment", "shrd", "sind", "sinh", "sora", "sund", "sunu", "takr", "talu", "taml", "tamldec", "telu", "thai", "tibt", "tirh", "tnsa", "vaii", "wara", "wcho"];
1
+ export var numberingSystemNames = ["adlm", "ahom", "arab", "arabext", "armn", "armnlow", "bali", "beng", "bhks", "brah", "cakm", "cham", "cyrl", "deva", "diak", "ethi", "fullwide", "gara", "geor", "gong", "gonm", "grek", "greklow", "gujr", "gukh", "guru", "hanidays", "hanidec", "hans", "hansfin", "hant", "hantfin", "hebr", "hmng", "hmnp", "java", "jpan", "jpanfin", "jpanyear", "kali", "kawi", "khmr", "knda", "krai", "lana", "lanatham", "laoo", "latn", "lepc", "limb", "mathbold", "mathdbl", "mathmono", "mathsanb", "mathsans", "mlym", "modi", "mong", "mroo", "mtei", "mymr", "mymrepka", "mymrpao", "mymrshan", "mymrtlng", "nagm", "newa", "nkoo", "olck", "onao", "orya", "osma", "outlined", "rohg", "roman", "romanlow", "saur", "segment", "shrd", "sind", "sinh", "sora", "sund", "sunu", "takr", "talu", "taml", "tamldec", "telu", "thai", "tibt", "tirh", "tnsa", "vaii", "wara", "wcho"];
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toLocaleString = toLocaleString;
4
1
  // eslint-disable-next-line import/no-cycle
5
- var core_1 = require("./core");
2
+ import { NumberFormat } from './core.js';
6
3
  /**
7
4
  * Number.prototype.toLocaleString ponyfill
8
5
  * https://tc39.es/ecma402/#sup-number.prototype.tolocalestring
9
6
  */
10
- function toLocaleString(x, locales, options) {
11
- var numberFormat = new core_1.NumberFormat(locales, options);
7
+ export function toLocaleString(x, locales, options) {
8
+ var numberFormat = new NumberFormat(locales, options);
12
9
  return numberFormat.format(x);
13
10
  }
package/src/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.supportedLocales = void 0;
4
- exports.supportedLocales = ["af", "af-NA", "agq", "ak", "am", "ar", "ar-AE", "ar-BH", "ar-DJ", "ar-DZ", "ar-EG", "ar-EH", "ar-ER", "ar-IL", "ar-IQ", "ar-JO", "ar-KM", "ar-KW", "ar-LB", "ar-LY", "ar-MA", "ar-MR", "ar-OM", "ar-PS", "ar-QA", "ar-SA", "ar-SD", "ar-SO", "ar-SS", "ar-SY", "ar-TD", "ar-TN", "ar-YE", "as", "asa", "ast", "az", "az-Cyrl", "az-Latn", "bas", "be", "be-tarask", "bem", "bez", "bg", "bm", "bn", "bn-IN", "bo", "bo-IN", "br", "brx", "bs", "bs-Cyrl", "bs-Latn", "ca", "ca-AD", "ca-ES-valencia", "ca-FR", "ca-IT", "ccp", "ccp-IN", "ce", "ceb", "cgg", "chr", "ckb", "ckb-IR", "cs", "cy", "da", "da-GL", "dav", "de", "de-AT", "de-BE", "de-CH", "de-IT", "de-LI", "de-LU", "dje", "doi", "dsb", "dua", "dyo", "dz", "ebu", "ee", "ee-TG", "el", "el-CY", "en", "en-001", "en-150", "en-AE", "en-AG", "en-AI", "en-AS", "en-AT", "en-AU", "en-BB", "en-BE", "en-BI", "en-BM", "en-BS", "en-BW", "en-BZ", "en-CA", "en-CC", "en-CH", "en-CK", "en-CM", "en-CX", "en-CY", "en-DE", "en-DG", "en-DK", "en-DM", "en-ER", "en-FI", "en-FJ", "en-FK", "en-FM", "en-GB", "en-GD", "en-GG", "en-GH", "en-GI", "en-GM", "en-GU", "en-GY", "en-HK", "en-IE", "en-IL", "en-IM", "en-IN", "en-IO", "en-JE", "en-JM", "en-KE", "en-KI", "en-KN", "en-KY", "en-LC", "en-LR", "en-LS", "en-MG", "en-MH", "en-MO", "en-MP", "en-MS", "en-MT", "en-MU", "en-MW", "en-MY", "en-NA", "en-NF", "en-NG", "en-NL", "en-NR", "en-NU", "en-NZ", "en-PG", "en-PH", "en-PK", "en-PN", "en-PR", "en-PW", "en-RW", "en-SB", "en-SC", "en-SD", "en-SE", "en-SG", "en-SH", "en-SI", "en-SL", "en-SS", "en-SX", "en-SZ", "en-TC", "en-TK", "en-TO", "en-TT", "en-TV", "en-TZ", "en-UG", "en-UM", "en-VC", "en-VG", "en-VI", "en-VU", "en-WS", "en-ZA", "en-ZM", "en-ZW", "eo", "es", "es-419", "es-AR", "es-BO", "es-BR", "es-BZ", "es-CL", "es-CO", "es-CR", "es-CU", "es-DO", "es-EA", "es-EC", "es-GQ", "es-GT", "es-HN", "es-IC", "es-MX", "es-NI", "es-PA", "es-PE", "es-PH", "es-PR", "es-PY", "es-SV", "es-US", "es-UY", "es-VE", "et", "eu", "ewo", "fa", "fa-AF", "ff", "ff-Adlm", "ff-Adlm-BF", "ff-Adlm-CM", "ff-Adlm-GH", "ff-Adlm-GM", "ff-Adlm-GW", "ff-Adlm-LR", "ff-Adlm-MR", "ff-Adlm-NE", "ff-Adlm-NG", "ff-Adlm-SL", "ff-Adlm-SN", "ff-Latn", "ff-Latn-BF", "ff-Latn-CM", "ff-Latn-GH", "ff-Latn-GM", "ff-Latn-GN", "ff-Latn-GW", "ff-Latn-LR", "ff-Latn-MR", "ff-Latn-NE", "ff-Latn-NG", "ff-Latn-SL", "fi", "fil", "fo", "fo-DK", "fr", "fr-BE", "fr-BF", "fr-BI", "fr-BJ", "fr-BL", "fr-CA", "fr-CD", "fr-CF", "fr-CG", "fr-CH", "fr-CI", "fr-CM", "fr-DJ", "fr-DZ", "fr-GA", "fr-GF", "fr-GN", "fr-GP", "fr-GQ", "fr-HT", "fr-KM", "fr-LU", "fr-MA", "fr-MC", "fr-MF", "fr-MG", "fr-ML", "fr-MQ", "fr-MR", "fr-MU", "fr-NC", "fr-NE", "fr-PF", "fr-PM", "fr-RE", "fr-RW", "fr-SC", "fr-SN", "fr-SY", "fr-TD", "fr-TG", "fr-TN", "fr-VU", "fr-WF", "fr-YT", "fur", "fy", "ga", "ga-GB", "gd", "gl", "gsw", "gsw-FR", "gsw-LI", "gu", "guz", "gv", "ha", "ha-GH", "ha-NE", "haw", "he", "hi", "hr", "hr-BA", "hsb", "hu", "hy", "ia", "id", "ig", "ii", "is", "it", "it-CH", "it-SM", "it-VA", "ja", "jgo", "jmc", "jv", "ka", "kab", "kam", "kde", "kea", "kgp", "khq", "ki", "kk", "kkj", "kl", "kln", "km", "kn", "ko", "ko-KP", "kok", "ks", "ks-Arab", "ksb", "ksf", "ksh", "ku", "kw", "ky", "lag", "lb", "lg", "lkt", "ln", "ln-AO", "ln-CF", "ln-CG", "lo", "lrc", "lrc-IQ", "lt", "lu", "luo", "luy", "lv", "mai", "mas", "mas-TZ", "mer", "mfe", "mg", "mgh", "mgo", "mi", "mk", "ml", "mn", "mni", "mni-Beng", "mr", "ms", "ms-BN", "ms-ID", "ms-SG", "mt", "mua", "my", "mzn", "naq", "nb", "nb-SJ", "nd", "nds", "nds-NL", "ne", "ne-IN", "nl", "nl-AW", "nl-BE", "nl-BQ", "nl-CW", "nl-SR", "nl-SX", "nmg", "nn", "nnh", "no", "nus", "nyn", "om", "om-KE", "or", "os", "os-RU", "pa", "pa-Arab", "pa-Guru", "pcm", "pl", "ps", "ps-PK", "pt", "pt-AO", "pt-CH", "pt-CV", "pt-GQ", "pt-GW", "pt-LU", "pt-MO", "pt-MZ", "pt-PT", "pt-ST", "pt-TL", "qu", "qu-BO", "qu-EC", "rm", "rn", "ro", "ro-MD", "rof", "ru", "ru-BY", "ru-KG", "ru-KZ", "ru-MD", "ru-UA", "rw", "rwk", "sa", "sah", "saq", "sat", "sat-Olck", "sbp", "sc", "sd", "sd-Arab", "sd-Deva", "se", "se-FI", "se-SE", "seh", "ses", "sg", "shi", "shi-Latn", "shi-Tfng", "si", "sk", "sl", "smn", "sn", "so", "so-DJ", "so-ET", "so-KE", "sq", "sq-MK", "sq-XK", "sr", "sr-Cyrl", "sr-Cyrl-BA", "sr-Cyrl-ME", "sr-Cyrl-XK", "sr-Latn", "sr-Latn-BA", "sr-Latn-ME", "sr-Latn-XK", "su", "su-Latn", "sv", "sv-AX", "sv-FI", "sw", "sw-CD", "sw-KE", "sw-UG", "ta", "ta-LK", "ta-MY", "ta-SG", "te", "teo", "teo-KE", "tg", "th", "ti", "ti-ER", "tk", "to", "tr", "tr-CY", "tt", "twq", "tzm", "ug", "uk", "und", "ur", "ur-IN", "uz", "uz-Arab", "uz-Cyrl", "uz-Latn", "vai", "vai-Latn", "vai-Vaii", "vi", "vun", "wae", "wo", "xh", "xog", "yav", "yi", "yo", "yo-BJ", "yrl", "yrl-CO", "yrl-VE", "yue", "yue-Hans", "yue-Hant", "zgh", "zh", "zh-Hans", "zh-Hans-HK", "zh-Hans-MO", "zh-Hans-SG", "zh-Hant", "zh-Hant-HK", "zh-Hant-MO", "zu"];
1
+ export var supportedLocales = ["af", "af-NA", "agq", "ak", "am", "ar", "ar-AE", "ar-BH", "ar-DJ", "ar-DZ", "ar-EG", "ar-EH", "ar-ER", "ar-IL", "ar-IQ", "ar-JO", "ar-KM", "ar-KW", "ar-LB", "ar-LY", "ar-MA", "ar-MR", "ar-OM", "ar-PS", "ar-QA", "ar-SA", "ar-SD", "ar-SO", "ar-SS", "ar-SY", "ar-TD", "ar-TN", "ar-YE", "as", "asa", "ast", "az", "az-Cyrl", "az-Latn", "bas", "be", "be-tarask", "bem", "bez", "bg", "bm", "bn", "bn-IN", "bo", "bo-IN", "br", "brx", "bs", "bs-Cyrl", "bs-Latn", "ca", "ca-AD", "ca-ES-valencia", "ca-FR", "ca-IT", "ccp", "ccp-IN", "ce", "ceb", "cgg", "chr", "ckb", "ckb-IR", "cs", "cy", "da", "da-GL", "dav", "de", "de-AT", "de-BE", "de-CH", "de-IT", "de-LI", "de-LU", "dje", "doi", "dsb", "dua", "dyo", "dz", "ebu", "ee", "ee-TG", "el", "el-CY", "en", "en-001", "en-150", "en-AE", "en-AG", "en-AI", "en-AS", "en-AT", "en-AU", "en-BB", "en-BE", "en-BI", "en-BM", "en-BS", "en-BW", "en-BZ", "en-CA", "en-CC", "en-CH", "en-CK", "en-CM", "en-CX", "en-CY", "en-DE", "en-DG", "en-DK", "en-DM", "en-ER", "en-FI", "en-FJ", "en-FK", "en-FM", "en-GB", "en-GD", "en-GG", "en-GH", "en-GI", "en-GM", "en-GU", "en-GY", "en-HK", "en-IE", "en-IL", "en-IM", "en-IN", "en-IO", "en-JE", "en-JM", "en-KE", "en-KI", "en-KN", "en-KY", "en-LC", "en-LR", "en-LS", "en-MG", "en-MH", "en-MO", "en-MP", "en-MS", "en-MT", "en-MU", "en-MW", "en-MY", "en-NA", "en-NF", "en-NG", "en-NL", "en-NR", "en-NU", "en-NZ", "en-PG", "en-PH", "en-PK", "en-PN", "en-PR", "en-PW", "en-RW", "en-SB", "en-SC", "en-SD", "en-SE", "en-SG", "en-SH", "en-SI", "en-SL", "en-SS", "en-SX", "en-SZ", "en-TC", "en-TK", "en-TO", "en-TT", "en-TV", "en-TZ", "en-UG", "en-UM", "en-VC", "en-VG", "en-VI", "en-VU", "en-WS", "en-ZA", "en-ZM", "en-ZW", "eo", "es", "es-419", "es-AR", "es-BO", "es-BR", "es-BZ", "es-CL", "es-CO", "es-CR", "es-CU", "es-DO", "es-EA", "es-EC", "es-GQ", "es-GT", "es-HN", "es-IC", "es-MX", "es-NI", "es-PA", "es-PE", "es-PH", "es-PR", "es-PY", "es-SV", "es-US", "es-UY", "es-VE", "et", "eu", "ewo", "fa", "fa-AF", "ff", "ff-Adlm", "ff-Adlm-BF", "ff-Adlm-CM", "ff-Adlm-GH", "ff-Adlm-GM", "ff-Adlm-GW", "ff-Adlm-LR", "ff-Adlm-MR", "ff-Adlm-NE", "ff-Adlm-NG", "ff-Adlm-SL", "ff-Adlm-SN", "ff-Latn", "ff-Latn-BF", "ff-Latn-CM", "ff-Latn-GH", "ff-Latn-GM", "ff-Latn-GN", "ff-Latn-GW", "ff-Latn-LR", "ff-Latn-MR", "ff-Latn-NE", "ff-Latn-NG", "ff-Latn-SL", "fi", "fil", "fo", "fo-DK", "fr", "fr-BE", "fr-BF", "fr-BI", "fr-BJ", "fr-BL", "fr-CA", "fr-CD", "fr-CF", "fr-CG", "fr-CH", "fr-CI", "fr-CM", "fr-DJ", "fr-DZ", "fr-GA", "fr-GF", "fr-GN", "fr-GP", "fr-GQ", "fr-HT", "fr-KM", "fr-LU", "fr-MA", "fr-MC", "fr-MF", "fr-MG", "fr-ML", "fr-MQ", "fr-MR", "fr-MU", "fr-NC", "fr-NE", "fr-PF", "fr-PM", "fr-RE", "fr-RW", "fr-SC", "fr-SN", "fr-SY", "fr-TD", "fr-TG", "fr-TN", "fr-VU", "fr-WF", "fr-YT", "fur", "fy", "ga", "ga-GB", "gd", "gl", "gsw", "gsw-FR", "gsw-LI", "gu", "guz", "gv", "ha", "ha-GH", "ha-NE", "haw", "he", "hi", "hr", "hr-BA", "hsb", "hu", "hy", "ia", "id", "ig", "ii", "is", "it", "it-CH", "it-SM", "it-VA", "ja", "jgo", "jmc", "jv", "ka", "kab", "kam", "kde", "kea", "kgp", "khq", "ki", "kk", "kkj", "kl", "kln", "km", "kn", "ko", "ko-KP", "kok", "ks", "ks-Arab", "ksb", "ksf", "ksh", "ku", "kw", "ky", "lag", "lb", "lg", "lkt", "ln", "ln-AO", "ln-CF", "ln-CG", "lo", "lrc", "lrc-IQ", "lt", "lu", "luo", "luy", "lv", "mai", "mas", "mas-TZ", "mer", "mfe", "mg", "mgh", "mgo", "mi", "mk", "ml", "mn", "mni", "mni-Beng", "mr", "ms", "ms-BN", "ms-ID", "ms-SG", "mt", "mua", "my", "mzn", "naq", "nb", "nb-SJ", "nd", "nds", "nds-NL", "ne", "ne-IN", "nl", "nl-AW", "nl-BE", "nl-BQ", "nl-CW", "nl-SR", "nl-SX", "nmg", "nn", "nnh", "no", "nus", "nyn", "om", "om-KE", "or", "os", "os-RU", "pa", "pa-Arab", "pa-Guru", "pcm", "pl", "ps", "ps-PK", "pt", "pt-AO", "pt-CH", "pt-CV", "pt-GQ", "pt-GW", "pt-LU", "pt-MO", "pt-MZ", "pt-PT", "pt-ST", "pt-TL", "qu", "qu-BO", "qu-EC", "rm", "rn", "ro", "ro-MD", "rof", "ru", "ru-BY", "ru-KG", "ru-KZ", "ru-MD", "ru-UA", "rw", "rwk", "sa", "sah", "saq", "sat", "sat-Olck", "sbp", "sc", "sd", "sd-Arab", "sd-Deva", "se", "se-FI", "se-SE", "seh", "ses", "sg", "shi", "shi-Latn", "shi-Tfng", "si", "sk", "sl", "smn", "sn", "so", "so-DJ", "so-ET", "so-KE", "sq", "sq-MK", "sq-XK", "sr", "sr-Cyrl", "sr-Cyrl-BA", "sr-Cyrl-ME", "sr-Cyrl-XK", "sr-Latn", "sr-Latn-BA", "sr-Latn-ME", "sr-Latn-XK", "su", "su-Latn", "sv", "sv-AX", "sv-FI", "sw", "sw-CD", "sw-KE", "sw-UG", "ta", "ta-LK", "ta-MY", "ta-SG", "te", "teo", "teo-KE", "tg", "th", "ti", "ti-ER", "tk", "to", "tr", "tr-CY", "tt", "twq", "tzm", "ug", "uk", "und", "ur", "ur-IN", "uz", "uz-Arab", "uz-Cyrl", "uz-Latn", "vai", "vai-Latn", "vai-Vaii", "vi", "vun", "wae", "wo", "xh", "xog", "yav", "yi", "yo", "yo-BJ", "yrl", "yrl-CO", "yrl-VE", "yue", "yue-Hans", "yue-Hant", "zgh", "zh", "zh-Hans", "zh-Hans-HK", "zh-Hans-MO", "zh-Hans-SG", "zh-Hant", "zh-Hant-HK", "zh-Hant-MO", "zu"];
package/lib/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './src/core';
package/lib/index.js DELETED
@@ -1 +0,0 @@
1
- export * from './src/core';
@@ -1 +0,0 @@
1
- export {};
@@ -1,9 +0,0 @@
1
- import { NumberFormat } from './src/core';
2
- import { toLocaleString as _toLocaleString } from './src/to_locale_string';
3
- import { defineProperty } from '@formatjs/ecma402-abstract';
4
- defineProperty(Intl, 'NumberFormat', { value: NumberFormat });
5
- defineProperty(Number.prototype, 'toLocaleString', {
6
- value: function toLocaleString(locales, options) {
7
- return _toLocaleString(this, locales, options);
8
- },
9
- });
package/lib/polyfill.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/lib/polyfill.js DELETED
@@ -1,12 +0,0 @@
1
- import { NumberFormat } from './src/core';
2
- import { toLocaleString as _toLocaleString } from './src/to_locale_string';
3
- import { defineProperty } from '@formatjs/ecma402-abstract';
4
- import { shouldPolyfill } from './should-polyfill';
5
- if (shouldPolyfill()) {
6
- defineProperty(Intl, 'NumberFormat', { value: NumberFormat });
7
- defineProperty(Number.prototype, 'toLocaleString', {
8
- value: function toLocaleString(locales, options) {
9
- return _toLocaleString(this, locales, options);
10
- },
11
- });
12
- }
@@ -1 +0,0 @@
1
- export declare function shouldPolyfill(locale?: string): string | undefined;
@@ -1,78 +0,0 @@
1
- import { match } from '@formatjs/intl-localematcher';
2
- import { supportedLocales } from './supported-locales.generated';
3
- /**
4
- * Check if this is old Node that only supports en
5
- * @returns
6
- */
7
- function onlySupportsEn() {
8
- return (!Intl.NumberFormat.polyfilled &&
9
- !Intl.NumberFormat.supportedLocalesOf(['es']).length);
10
- }
11
- /**
12
- * Check if Intl.NumberFormat is ES2020 compatible.
13
- * Caveat: we are not checking `toLocaleString`.
14
- *
15
- * @public
16
- * @param unit unit to check
17
- */
18
- function supportsES2020() {
19
- try {
20
- var s = new Intl.NumberFormat('en', {
21
- style: 'unit',
22
- unit: 'bit',
23
- unitDisplay: 'long',
24
- notation: 'scientific',
25
- }).format(10000);
26
- // Check for a plurality bug in environment that uses the older versions of ICU:
27
- // https://unicode-org.atlassian.net/browse/ICU-13836
28
- if (s !== '1E4 bits') {
29
- return false;
30
- }
31
- }
32
- catch (e) {
33
- return false;
34
- }
35
- return true;
36
- }
37
- /**
38
- * Check if Intl.NumberFormat is ES2020 compatible.
39
- * Caveat: we are not checking `toLocaleString`.
40
- *
41
- * @public
42
- * @param unit unit to check
43
- */
44
- function supportsES2023() {
45
- try {
46
- var s = new Intl.NumberFormat('en', {
47
- notation: 'compact',
48
- minimumSignificantDigits: 3,
49
- maximumSignificantDigits: 3,
50
- minimumFractionDigits: 2,
51
- maximumFractionDigits: 2,
52
- // @ts-ignore TS types are old
53
- roundingPriority: 'morePrecision',
54
- }).format(1e8);
55
- return s === '100.00M';
56
- }
57
- catch (e) {
58
- return false;
59
- }
60
- }
61
- function supportedLocalesOf(locale) {
62
- if (!locale) {
63
- return true;
64
- }
65
- var locales = Array.isArray(locale) ? locale : [locale];
66
- return Intl.NumberFormat.supportedLocalesOf(locales).length === locales.length;
67
- }
68
- export function shouldPolyfill(locale) {
69
- if (locale === void 0) { locale = 'en'; }
70
- if (typeof Intl === 'undefined' ||
71
- !('NumberFormat' in Intl) ||
72
- !supportsES2020() ||
73
- !supportsES2023() ||
74
- onlySupportsEn() ||
75
- !supportedLocalesOf(locale)) {
76
- return locale ? match([locale], supportedLocales, 'en') : undefined;
77
- }
78
- }
package/lib/src/core.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { NumberFormatConstructor, NumberFormat as NumberFormatType } from './types';
2
- export type NumberFormat = NumberFormatType;
3
- /**
4
- * https://tc39.es/ecma402/#sec-intl-numberformat-constructor
5
- */
6
- export declare const NumberFormat: NumberFormatConstructor;