@formatjs/intl-pluralrules 5.2.7 → 5.2.8

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/index.js CHANGED
@@ -24,7 +24,7 @@ function PluralRuleSelect(locale, type, _n, _a) {
24
24
  ? "".concat(IntegerDigits, ".").concat(FractionDigits)
25
25
  : IntegerDigits, type === 'ordinal');
26
26
  }
27
- var PluralRules = exports.PluralRules = /** @class */ (function () {
27
+ var PluralRules = /** @class */ (function () {
28
28
  function PluralRules(locales, options) {
29
29
  // test262/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js
30
30
  // Cannot use `new.target` bc of IE11 & TS transpiles it to something else
@@ -97,6 +97,7 @@ var PluralRules = exports.PluralRules = /** @class */ (function () {
97
97
  PluralRules.polyfilled = true;
98
98
  return PluralRules;
99
99
  }());
100
+ exports.PluralRules = PluralRules;
100
101
  try {
101
102
  // IE11 does not have Symbol
102
103
  if (typeof Symbol !== 'undefined') {
@@ -1,12 +1,15 @@
1
- import { invariant, ToNumber } from '@formatjs/ecma402-abstract';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetOperands = void 0;
4
+ var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
2
5
  /**
3
6
  * http://ecma-international.org/ecma-402/7.0/index.html#sec-getoperands
4
7
  * @param s
5
8
  */
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');
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');
10
13
  var dp = s.indexOf('.');
11
14
  var iv;
12
15
  var f;
@@ -20,16 +23,16 @@ export function GetOperands(s) {
20
23
  else {
21
24
  iv = s.slice(0, dp);
22
25
  fv = s.slice(dp, s.length);
23
- f = ToNumber(fv);
26
+ f = (0, ecma402_abstract_1.ToNumber)(fv);
24
27
  v = fv.length;
25
28
  }
26
- var i = Math.abs(ToNumber(iv));
29
+ var i = Math.abs((0, ecma402_abstract_1.ToNumber)(iv));
27
30
  var w;
28
31
  var t;
29
32
  if (f !== 0) {
30
33
  var ft = fv.replace(/0+$/, '');
31
34
  w = ft.length;
32
- t = ToNumber(ft);
35
+ t = (0, ecma402_abstract_1.ToNumber)(ft);
33
36
  }
34
37
  else {
35
38
  w = 0;
@@ -44,3 +47,4 @@ export function GetOperands(s) {
44
47
  FractionDigitsWithoutTrailing: t,
45
48
  };
46
49
  }
50
+ exports.GetOperands = GetOperands;
@@ -1,17 +1,21 @@
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) {
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) {
4
7
  var availableLocales = _a.availableLocales, relevantExtensionKeys = _a.relevantExtensionKeys, localeData = _a.localeData, getDefaultLocale = _a.getDefaultLocale, getInternalSlots = _a.getInternalSlots;
5
- var requestedLocales = CanonicalizeLocaleList(locales);
8
+ var requestedLocales = (0, ecma402_abstract_1.CanonicalizeLocaleList)(locales);
6
9
  var opt = Object.create(null);
7
- var opts = CoerceOptionsToObject(options);
10
+ var opts = (0, ecma402_abstract_1.CoerceOptionsToObject)(options);
8
11
  var internalSlots = getInternalSlots(pl);
9
12
  internalSlots.initializedPluralRules = true;
10
- var matcher = GetOption(opts, 'localeMatcher', 'string', ['best fit', 'lookup'], 'best fit');
13
+ var matcher = (0, ecma402_abstract_1.GetOption)(opts, 'localeMatcher', 'string', ['best fit', 'lookup'], 'best fit');
11
14
  opt.localeMatcher = matcher;
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);
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);
15
18
  internalSlots.locale = r.locale;
16
19
  return pl;
17
20
  }
21
+ exports.InitializePluralRules = InitializePluralRules;
@@ -1,23 +1,27 @@
1
- import { Type, invariant, FormatNumericToString, } from '@formatjs/ecma402-abstract';
2
- import { GetOperands } from './GetOperands';
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");
3
6
  /**
4
7
  * http://ecma-international.org/ecma-402/7.0/index.html#sec-resolveplural
5
8
  * @param pl
6
9
  * @param n
7
10
  * @param PluralRuleSelect Has to pass in bc it's implementation-specific
8
11
  */
9
- export function ResolvePlural(pl, n, _a) {
12
+ function ResolvePlural(pl, n, _a) {
10
13
  var getInternalSlots = _a.getInternalSlots, PluralRuleSelect = _a.PluralRuleSelect;
11
14
  var internalSlots = getInternalSlots(pl);
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');
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');
15
18
  if (!isFinite(n)) {
16
19
  return 'other';
17
20
  }
18
21
  var locale = internalSlots.locale, type = internalSlots.type;
19
- var res = FormatNumericToString(internalSlots, n);
22
+ var res = (0, ecma402_abstract_1.FormatNumericToString)(internalSlots, n);
20
23
  var s = res.formattedString;
21
- var operands = GetOperands(s);
24
+ var operands = (0, GetOperands_1.GetOperands)(s);
22
25
  return PluralRuleSelect(locale, type, n, operands);
23
26
  }
27
+ exports.ResolvePlural = ResolvePlural;
@@ -1,5 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  var internalSlotMap = new WeakMap();
2
- export default function getInternalSlots(x) {
4
+ function getInternalSlots(x) {
3
5
  var internalSlots = internalSlotMap.get(x);
4
6
  if (!internalSlots) {
5
7
  internalSlots = Object.create(null);
@@ -7,3 +9,4 @@ export default function getInternalSlots(x) {
7
9
  }
8
10
  return internalSlots;
9
11
  }
12
+ exports.default = getInternalSlots;
package/lib/index.js CHANGED
@@ -1,8 +1,11 @@
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';
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"));
6
9
  function validateInstance(instance, method) {
7
10
  if (!(instance instanceof PluralRules)) {
8
11
  throw new TypeError("Method Intl.PluralRules.prototype.".concat(method, " called on incompatible receiver ").concat(String(instance)));
@@ -21,7 +24,7 @@ function PluralRuleSelect(locale, type, _n, _a) {
21
24
  ? "".concat(IntegerDigits, ".").concat(FractionDigits)
22
25
  : IntegerDigits, type === 'ordinal');
23
26
  }
24
- export var PluralRules = /** @class */ (function () {
27
+ var PluralRules = /** @class */ (function () {
25
28
  function PluralRules(locales, options) {
26
29
  // test262/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js
27
30
  // Cannot use `new.target` bc of IE11 & TS transpiles it to something else
@@ -29,18 +32,18 @@ export var PluralRules = /** @class */ (function () {
29
32
  if (!newTarget) {
30
33
  throw new TypeError("Intl.PluralRules must be called with 'new'");
31
34
  }
32
- return InitializePluralRules(this, locales, options, {
35
+ return (0, InitializePluralRules_1.InitializePluralRules)(this, locales, options, {
33
36
  availableLocales: PluralRules.availableLocales,
34
37
  relevantExtensionKeys: PluralRules.relevantExtensionKeys,
35
38
  localeData: PluralRules.localeData,
36
39
  getDefaultLocale: PluralRules.getDefaultLocale,
37
- getInternalSlots: getInternalSlots,
40
+ getInternalSlots: get_internal_slots_1.default,
38
41
  });
39
42
  }
40
43
  PluralRules.prototype.resolvedOptions = function () {
41
44
  validateInstance(this, 'resolvedOptions');
42
45
  var opts = Object.create(null);
43
- var internalSlots = getInternalSlots(this);
46
+ var internalSlots = (0, get_internal_slots_1.default)(this);
44
47
  opts.locale = internalSlots.locale;
45
48
  opts.type = internalSlots.type;
46
49
  [
@@ -55,20 +58,20 @@ export var PluralRules = /** @class */ (function () {
55
58
  opts[field] = val;
56
59
  }
57
60
  });
58
- opts.pluralCategories = __spreadArray([], PluralRules.localeData[opts.locale].categories[opts.type], true);
61
+ opts.pluralCategories = tslib_1.__spreadArray([], PluralRules.localeData[opts.locale].categories[opts.type], true);
59
62
  return opts;
60
63
  };
61
64
  PluralRules.prototype.select = function (val) {
62
65
  var pr = this;
63
66
  validateInstance(pr, 'select');
64
- var n = ToNumber(val);
65
- return ResolvePlural(pr, n, { getInternalSlots: getInternalSlots, PluralRuleSelect: PluralRuleSelect });
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 });
66
69
  };
67
70
  PluralRules.prototype.toString = function () {
68
71
  return '[object Intl.PluralRules]';
69
72
  };
70
73
  PluralRules.supportedLocalesOf = function (locales, options) {
71
- return SupportedLocales(PluralRules.availableLocales, CanonicalizeLocaleList(locales), options);
74
+ return (0, ecma402_abstract_1.SupportedLocales)(PluralRules.availableLocales, (0, ecma402_abstract_1.CanonicalizeLocaleList)(locales), options);
72
75
  };
73
76
  PluralRules.__addLocaleData = function () {
74
77
  var data = [];
@@ -94,6 +97,7 @@ export var PluralRules = /** @class */ (function () {
94
97
  PluralRules.polyfilled = true;
95
98
  return PluralRules;
96
99
  }());
100
+ exports.PluralRules = PluralRules;
97
101
  try {
98
102
  // IE11 does not have Symbol
99
103
  if (typeof Symbol !== 'undefined') {
@@ -1,6 +1,8 @@
1
- import { PluralRules } from './';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var _1 = require("./");
2
4
  Object.defineProperty(Intl, 'PluralRules', {
3
- value: PluralRules,
5
+ value: _1.PluralRules,
4
6
  writable: true,
5
7
  enumerable: false,
6
8
  configurable: true,
package/lib/polyfill.js CHANGED
@@ -1,8 +1,10 @@
1
- import { PluralRules } from './';
2
- import { shouldPolyfill } from './should-polyfill';
3
- if (shouldPolyfill()) {
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)()) {
4
6
  Object.defineProperty(Intl, 'PluralRules', {
5
- value: PluralRules,
7
+ value: _1.PluralRules,
6
8
  writable: true,
7
9
  enumerable: false,
8
10
  configurable: true,
@@ -1,5 +1,8 @@
1
- import { match } from '@formatjs/intl-localematcher';
2
- import { supportedLocales } from './supported-locales.generated';
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");
3
6
  function supportedLocalesOf(locale) {
4
7
  if (!locale) {
5
8
  return true;
@@ -7,12 +10,13 @@ function supportedLocalesOf(locale) {
7
10
  var locales = Array.isArray(locale) ? locale : [locale];
8
11
  return Intl.PluralRules.supportedLocalesOf(locales).length === locales.length;
9
12
  }
10
- export function shouldPolyfill(locale) {
13
+ function shouldPolyfill(locale) {
11
14
  if (locale === void 0) { locale = 'en'; }
12
15
  if (!('PluralRules' in Intl) ||
13
16
  new Intl.PluralRules('en', { minimumFractionDigits: 2 }).select(1) ===
14
17
  'one' ||
15
18
  !supportedLocalesOf(locale)) {
16
- return locale ? match([locale], supportedLocales, 'en') : undefined;
19
+ return locale ? (0, intl_localematcher_1.match)([locale], supported_locales_generated_1.supportedLocales, 'en') : undefined;
17
20
  }
18
21
  }
22
+ exports.shouldPolyfill = shouldPolyfill;
@@ -1 +1,4 @@
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"];
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"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl-pluralrules",
3
- "version": "5.2.7",
3
+ "version": "5.2.8",
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.2",
25
- "@formatjs/intl-localematcher": "0.4.2"
24
+ "@formatjs/ecma402-abstract": "1.17.3",
25
+ "@formatjs/intl-localematcher": "0.5.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@formatjs/intl-getcanonicallocales": "2.3.0",
29
- "@formatjs/intl-locale": "3.4.0"
29
+ "@formatjs/intl-locale": "3.4.1"
30
30
  },
31
31
  "bugs": {
32
32
  "url": "https://github.com/formatjs/formatjs/issues"