@formatjs/intl-pluralrules 5.2.8 → 5.2.10

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/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 FormatJS
3
+ Copyright (c) 2023 FormatJS
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetOperands = void 0;
4
- var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
1
+ import { invariant, ToNumber } from '@formatjs/ecma402-abstract';
5
2
  /**
6
3
  * http://ecma-international.org/ecma-402/7.0/index.html#sec-getoperands
7
4
  * @param s
8
5
  */
9
- function GetOperands(s) {
10
- (0, ecma402_abstract_1.invariant)(typeof s === 'string', "GetOperands should have been called with a string");
11
- var n = (0, ecma402_abstract_1.ToNumber)(s);
12
- (0, ecma402_abstract_1.invariant)(isFinite(n), 'n should be finite');
6
+ export function GetOperands(s) {
7
+ invariant(typeof s === 'string', "GetOperands should have been called with a string");
8
+ var n = ToNumber(s);
9
+ invariant(isFinite(n), 'n should be finite');
13
10
  var dp = s.indexOf('.');
14
11
  var iv;
15
12
  var f;
@@ -23,16 +20,16 @@ function GetOperands(s) {
23
20
  else {
24
21
  iv = s.slice(0, dp);
25
22
  fv = s.slice(dp, s.length);
26
- f = (0, ecma402_abstract_1.ToNumber)(fv);
23
+ f = ToNumber(fv);
27
24
  v = fv.length;
28
25
  }
29
- var i = Math.abs((0, ecma402_abstract_1.ToNumber)(iv));
26
+ var i = Math.abs(ToNumber(iv));
30
27
  var w;
31
28
  var t;
32
29
  if (f !== 0) {
33
30
  var ft = fv.replace(/0+$/, '');
34
31
  w = ft.length;
35
- t = (0, ecma402_abstract_1.ToNumber)(ft);
32
+ t = ToNumber(ft);
36
33
  }
37
34
  else {
38
35
  w = 0;
@@ -47,4 +44,3 @@ function GetOperands(s) {
47
44
  FractionDigitsWithoutTrailing: t,
48
45
  };
49
46
  }
50
- exports.GetOperands = GetOperands;
@@ -1,21 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InitializePluralRules = void 0;
4
- var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
5
- var intl_localematcher_1 = require("@formatjs/intl-localematcher");
6
- function InitializePluralRules(pl, locales, options, _a) {
1
+ import { CanonicalizeLocaleList, CoerceOptionsToObject, GetOption, SetNumberFormatDigitOptions, } from '@formatjs/ecma402-abstract';
2
+ import { ResolveLocale } from '@formatjs/intl-localematcher';
3
+ export function InitializePluralRules(pl, locales, options, _a) {
7
4
  var availableLocales = _a.availableLocales, relevantExtensionKeys = _a.relevantExtensionKeys, localeData = _a.localeData, getDefaultLocale = _a.getDefaultLocale, getInternalSlots = _a.getInternalSlots;
8
- var requestedLocales = (0, ecma402_abstract_1.CanonicalizeLocaleList)(locales);
5
+ var requestedLocales = CanonicalizeLocaleList(locales);
9
6
  var opt = Object.create(null);
10
- var opts = (0, ecma402_abstract_1.CoerceOptionsToObject)(options);
7
+ var opts = CoerceOptionsToObject(options);
11
8
  var internalSlots = getInternalSlots(pl);
12
9
  internalSlots.initializedPluralRules = true;
13
- var matcher = (0, ecma402_abstract_1.GetOption)(opts, 'localeMatcher', 'string', ['best fit', 'lookup'], 'best fit');
10
+ var matcher = GetOption(opts, 'localeMatcher', 'string', ['best fit', 'lookup'], 'best fit');
14
11
  opt.localeMatcher = matcher;
15
- internalSlots.type = (0, ecma402_abstract_1.GetOption)(opts, 'type', 'string', ['cardinal', 'ordinal'], 'cardinal');
16
- (0, ecma402_abstract_1.SetNumberFormatDigitOptions)(internalSlots, opts, 0, 3, 'standard');
17
- var r = (0, intl_localematcher_1.ResolveLocale)(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
12
+ internalSlots.type = GetOption(opts, 'type', 'string', ['cardinal', 'ordinal'], 'cardinal');
13
+ SetNumberFormatDigitOptions(internalSlots, opts, 0, 3, 'standard');
14
+ var r = ResolveLocale(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
18
15
  internalSlots.locale = r.locale;
19
16
  return pl;
20
17
  }
21
- exports.InitializePluralRules = InitializePluralRules;
@@ -1,27 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ResolvePlural = void 0;
4
- var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
5
- var GetOperands_1 = require("./GetOperands");
1
+ import { Type, invariant, FormatNumericToString, } from '@formatjs/ecma402-abstract';
2
+ import { GetOperands } from './GetOperands';
6
3
  /**
7
4
  * http://ecma-international.org/ecma-402/7.0/index.html#sec-resolveplural
8
5
  * @param pl
9
6
  * @param n
10
7
  * @param PluralRuleSelect Has to pass in bc it's implementation-specific
11
8
  */
12
- function ResolvePlural(pl, n, _a) {
9
+ export function ResolvePlural(pl, n, _a) {
13
10
  var getInternalSlots = _a.getInternalSlots, PluralRuleSelect = _a.PluralRuleSelect;
14
11
  var internalSlots = getInternalSlots(pl);
15
- (0, ecma402_abstract_1.invariant)((0, ecma402_abstract_1.Type)(internalSlots) === 'Object', 'pl has to be an object');
16
- (0, ecma402_abstract_1.invariant)('initializedPluralRules' in internalSlots, 'pluralrules must be initialized');
17
- (0, ecma402_abstract_1.invariant)((0, ecma402_abstract_1.Type)(n) === 'Number', 'n must be a number');
12
+ invariant(Type(internalSlots) === 'Object', 'pl has to be an object');
13
+ invariant('initializedPluralRules' in internalSlots, 'pluralrules must be initialized');
14
+ invariant(Type(n) === 'Number', 'n must be a number');
18
15
  if (!isFinite(n)) {
19
16
  return 'other';
20
17
  }
21
18
  var locale = internalSlots.locale, type = internalSlots.type;
22
- var res = (0, ecma402_abstract_1.FormatNumericToString)(internalSlots, n);
19
+ var res = FormatNumericToString(internalSlots, n);
23
20
  var s = res.formattedString;
24
- var operands = (0, GetOperands_1.GetOperands)(s);
21
+ var operands = GetOperands(s);
25
22
  return PluralRuleSelect(locale, type, n, operands);
26
23
  }
27
- exports.ResolvePlural = ResolvePlural;
@@ -1,7 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  var internalSlotMap = new WeakMap();
4
- function getInternalSlots(x) {
2
+ export default function getInternalSlots(x) {
5
3
  var internalSlots = internalSlotMap.get(x);
6
4
  if (!internalSlots) {
7
5
  internalSlots = Object.create(null);
@@ -9,4 +7,3 @@ function getInternalSlots(x) {
9
7
  }
10
8
  return internalSlots;
11
9
  }
12
- exports.default = getInternalSlots;
package/lib/index.js CHANGED
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PluralRules = void 0;
4
- var tslib_1 = require("tslib");
5
- var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
6
- var InitializePluralRules_1 = require("./abstract/InitializePluralRules");
7
- var ResolvePlural_1 = require("./abstract/ResolvePlural");
8
- var get_internal_slots_1 = tslib_1.__importDefault(require("./get_internal_slots"));
1
+ import { __spreadArray } from "tslib";
2
+ import { SupportedLocales, ToNumber, CanonicalizeLocaleList, } from '@formatjs/ecma402-abstract';
3
+ import { InitializePluralRules } from './abstract/InitializePluralRules';
4
+ import { ResolvePlural } from './abstract/ResolvePlural';
5
+ import getInternalSlots from './get_internal_slots';
9
6
  function validateInstance(instance, method) {
10
7
  if (!(instance instanceof PluralRules)) {
11
8
  throw new TypeError("Method Intl.PluralRules.prototype.".concat(method, " called on incompatible receiver ").concat(String(instance)));
@@ -32,18 +29,18 @@ var PluralRules = /** @class */ (function () {
32
29
  if (!newTarget) {
33
30
  throw new TypeError("Intl.PluralRules must be called with 'new'");
34
31
  }
35
- return (0, InitializePluralRules_1.InitializePluralRules)(this, locales, options, {
32
+ return InitializePluralRules(this, locales, options, {
36
33
  availableLocales: PluralRules.availableLocales,
37
34
  relevantExtensionKeys: PluralRules.relevantExtensionKeys,
38
35
  localeData: PluralRules.localeData,
39
36
  getDefaultLocale: PluralRules.getDefaultLocale,
40
- getInternalSlots: get_internal_slots_1.default,
37
+ getInternalSlots: getInternalSlots,
41
38
  });
42
39
  }
43
40
  PluralRules.prototype.resolvedOptions = function () {
44
41
  validateInstance(this, 'resolvedOptions');
45
42
  var opts = Object.create(null);
46
- var internalSlots = (0, get_internal_slots_1.default)(this);
43
+ var internalSlots = getInternalSlots(this);
47
44
  opts.locale = internalSlots.locale;
48
45
  opts.type = internalSlots.type;
49
46
  [
@@ -58,20 +55,20 @@ var PluralRules = /** @class */ (function () {
58
55
  opts[field] = val;
59
56
  }
60
57
  });
61
- opts.pluralCategories = tslib_1.__spreadArray([], PluralRules.localeData[opts.locale].categories[opts.type], true);
58
+ opts.pluralCategories = __spreadArray([], PluralRules.localeData[opts.locale].categories[opts.type], true);
62
59
  return opts;
63
60
  };
64
61
  PluralRules.prototype.select = function (val) {
65
62
  var pr = this;
66
63
  validateInstance(pr, 'select');
67
- var n = (0, ecma402_abstract_1.ToNumber)(val);
68
- return (0, ResolvePlural_1.ResolvePlural)(pr, n, { getInternalSlots: get_internal_slots_1.default, PluralRuleSelect: PluralRuleSelect });
64
+ var n = ToNumber(val);
65
+ return ResolvePlural(pr, n, { getInternalSlots: getInternalSlots, PluralRuleSelect: PluralRuleSelect });
69
66
  };
70
67
  PluralRules.prototype.toString = function () {
71
68
  return '[object Intl.PluralRules]';
72
69
  };
73
70
  PluralRules.supportedLocalesOf = function (locales, options) {
74
- return (0, ecma402_abstract_1.SupportedLocales)(PluralRules.availableLocales, (0, ecma402_abstract_1.CanonicalizeLocaleList)(locales), options);
71
+ return SupportedLocales(PluralRules.availableLocales, CanonicalizeLocaleList(locales), options);
75
72
  };
76
73
  PluralRules.__addLocaleData = function () {
77
74
  var data = [];
@@ -97,7 +94,7 @@ var PluralRules = /** @class */ (function () {
97
94
  PluralRules.polyfilled = true;
98
95
  return PluralRules;
99
96
  }());
100
- exports.PluralRules = PluralRules;
97
+ export { PluralRules };
101
98
  try {
102
99
  // IE11 does not have Symbol
103
100
  if (typeof Symbol !== 'undefined') {
@@ -1,8 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var _1 = require("./");
1
+ import { PluralRules } from './';
4
2
  Object.defineProperty(Intl, 'PluralRules', {
5
- value: _1.PluralRules,
3
+ value: PluralRules,
6
4
  writable: true,
7
5
  enumerable: false,
8
6
  configurable: true,
package/lib/polyfill.js CHANGED
@@ -1,10 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var _1 = require("./");
4
- var should_polyfill_1 = require("./should-polyfill");
5
- if ((0, should_polyfill_1.shouldPolyfill)()) {
1
+ import { PluralRules } from './';
2
+ import { shouldPolyfill } from './should-polyfill';
3
+ if (shouldPolyfill()) {
6
4
  Object.defineProperty(Intl, 'PluralRules', {
7
- value: _1.PluralRules,
5
+ value: PluralRules,
8
6
  writable: true,
9
7
  enumerable: false,
10
8
  configurable: true,
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shouldPolyfill = void 0;
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';
6
3
  function supportedLocalesOf(locale) {
7
4
  if (!locale) {
8
5
  return true;
@@ -10,13 +7,12 @@ function supportedLocalesOf(locale) {
10
7
  var locales = Array.isArray(locale) ? locale : [locale];
11
8
  return Intl.PluralRules.supportedLocalesOf(locales).length === locales.length;
12
9
  }
13
- function shouldPolyfill(locale) {
10
+ export function shouldPolyfill(locale) {
14
11
  if (locale === void 0) { locale = 'en'; }
15
12
  if (!('PluralRules' in Intl) ||
16
13
  new Intl.PluralRules('en', { minimumFractionDigits: 2 }).select(1) ===
17
14
  'one' ||
18
15
  !supportedLocalesOf(locale)) {
19
- return locale ? (0, intl_localematcher_1.match)([locale], supported_locales_generated_1.supportedLocales, 'en') : undefined;
16
+ return locale ? match([locale], supportedLocales, 'en') : undefined;
20
17
  }
21
18
  }
22
- exports.shouldPolyfill = shouldPolyfill;
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.supportedLocales = void 0;
4
- exports.supportedLocales = ["af", "ak", "am", "an", "ar", "ars", "as", "asa", "ast", "az", "bal", "be", "bem", "bez", "bg", "bho", "bm", "bn", "bo", "br", "brx", "bs", "ca", "ce", "ceb", "cgg", "chr", "ckb", "cs", "cy", "da", "de", "doi", "dsb", "dv", "dz", "ee", "el", "en", "eo", "es", "et", "eu", "fa", "ff", "fi", "fil", "fo", "fr", "fur", "fy", "ga", "gd", "gl", "gsw", "gu", "guw", "gv", "ha", "haw", "he", "hi", "hnj", "hr", "hsb", "hu", "hy", "ia", "id", "ig", "ii", "io", "is", "it", "iu", "ja", "jbo", "jgo", "jmc", "jv", "jw", "ka", "kab", "kaj", "kcg", "kde", "kea", "kk", "kkj", "kl", "km", "kn", "ko", "ks", "ksb", "ksh", "ku", "kw", "ky", "lag", "lb", "lg", "lij", "lkt", "ln", "lo", "lt", "lv", "mas", "mg", "mgo", "mk", "ml", "mn", "mo", "mr", "ms", "mt", "my", "nah", "naq", "nb", "nd", "ne", "nl", "nn", "nnh", "no", "nqo", "nr", "nso", "ny", "nyn", "om", "or", "os", "osa", "pa", "pap", "pcm", "pl", "prg", "ps", "pt", "pt-PT", "rm", "ro", "rof", "ru", "rwk", "sah", "saq", "sat", "sc", "scn", "sd", "sdh", "se", "seh", "ses", "sg", "sh", "shi", "si", "sk", "sl", "sma", "smi", "smj", "smn", "sms", "sn", "so", "sq", "sr", "ss", "ssy", "st", "su", "sv", "sw", "syr", "ta", "te", "teo", "th", "ti", "tig", "tk", "tl", "tn", "to", "tpi", "tr", "ts", "tzm", "ug", "uk", "und", "ur", "uz", "ve", "vi", "vo", "vun", "wa", "wae", "wo", "xh", "xog", "yi", "yo", "yue", "zh", "zu"];
1
+ export var supportedLocales = ["af", "ak", "am", "an", "ar", "ars", "as", "asa", "ast", "az", "bal", "be", "bem", "bez", "bg", "bho", "bm", "bn", "bo", "br", "brx", "bs", "ca", "ce", "ceb", "cgg", "chr", "ckb", "cs", "cy", "da", "de", "doi", "dsb", "dv", "dz", "ee", "el", "en", "eo", "es", "et", "eu", "fa", "ff", "fi", "fil", "fo", "fr", "fur", "fy", "ga", "gd", "gl", "gsw", "gu", "guw", "gv", "ha", "haw", "he", "hi", "hnj", "hr", "hsb", "hu", "hy", "ia", "id", "ig", "ii", "io", "is", "it", "iu", "ja", "jbo", "jgo", "jmc", "jv", "jw", "ka", "kab", "kaj", "kcg", "kde", "kea", "kk", "kkj", "kl", "km", "kn", "ko", "ks", "ksb", "ksh", "ku", "kw", "ky", "lag", "lb", "lg", "lij", "lkt", "ln", "lo", "lt", "lv", "mas", "mg", "mgo", "mk", "ml", "mn", "mo", "mr", "ms", "mt", "my", "nah", "naq", "nb", "nd", "ne", "nl", "nn", "nnh", "no", "nqo", "nr", "nso", "ny", "nyn", "om", "or", "os", "osa", "pa", "pap", "pcm", "pl", "prg", "ps", "pt", "pt-PT", "rm", "ro", "rof", "ru", "rwk", "sah", "saq", "sat", "sc", "scn", "sd", "sdh", "se", "seh", "ses", "sg", "sh", "shi", "si", "sk", "sl", "sma", "smi", "smj", "smn", "sms", "sn", "so", "sq", "sr", "ss", "ssy", "st", "su", "sv", "sw", "syr", "ta", "te", "teo", "th", "ti", "tig", "tk", "tl", "tn", "to", "tpi", "tr", "ts", "tzm", "ug", "uk", "und", "ur", "uz", "ve", "vi", "vo", "vun", "wa", "wae", "wo", "xh", "xog", "yi", "yo", "yue", "zh", "zu"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl-pluralrules",
3
- "version": "5.2.8",
3
+ "version": "5.2.10",
4
4
  "description": "Polyfill for Intl.PluralRules",
5
5
  "keywords": [
6
6
  "polyfill",
@@ -21,12 +21,12 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "tslib": "^2.4.0",
24
- "@formatjs/ecma402-abstract": "1.17.3",
25
- "@formatjs/intl-localematcher": "0.5.0"
24
+ "@formatjs/ecma402-abstract": "1.18.0",
25
+ "@formatjs/intl-localematcher": "0.5.2"
26
26
  },
27
27
  "devDependencies": {
28
- "@formatjs/intl-getcanonicallocales": "2.3.0",
29
- "@formatjs/intl-locale": "3.4.1"
28
+ "@formatjs/intl-locale": "3.4.3",
29
+ "@formatjs/intl-getcanonicallocales": "2.3.0"
30
30
  },
31
31
  "bugs": {
32
32
  "url": "https://github.com/formatjs/formatjs/issues"