@formatjs/intl-pluralrules 6.1.1 → 6.1.2

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.
@@ -1,32 +1,32 @@
1
- import Decimal from 'decimal.js';
1
+ import type Decimal from "decimal.js";
2
2
  export interface OperandsRecord {
3
- /**
4
- * Absolute value of the source number (integer and decimals)
5
- */
6
- Number: Decimal;
7
- /**
8
- * Number of digits of `number`
9
- */
10
- IntegerDigits: number;
11
- /**
12
- * Number of visible fraction digits in [[Number]], with trailing zeroes.
13
- */
14
- NumberOfFractionDigits: number;
15
- /**
16
- * Number of visible fraction digits in [[Number]], without trailing zeroes.
17
- */
18
- NumberOfFractionDigitsWithoutTrailing: number;
19
- /**
20
- * Number of visible fractional digits in [[Number]], with trailing zeroes.
21
- */
22
- FractionDigits: number;
23
- /**
24
- * Number of visible fractional digits in [[Number]], without trailing zeroes.
25
- */
26
- FractionDigitsWithoutTrailing: number;
3
+ /**
4
+ * Absolute value of the source number (integer and decimals)
5
+ */
6
+ Number: Decimal;
7
+ /**
8
+ * Number of digits of `number`
9
+ */
10
+ IntegerDigits: number;
11
+ /**
12
+ * Number of visible fraction digits in [[Number]], with trailing zeroes.
13
+ */
14
+ NumberOfFractionDigits: number;
15
+ /**
16
+ * Number of visible fraction digits in [[Number]], without trailing zeroes.
17
+ */
18
+ NumberOfFractionDigitsWithoutTrailing: number;
19
+ /**
20
+ * Number of visible fractional digits in [[Number]], with trailing zeroes.
21
+ */
22
+ FractionDigits: number;
23
+ /**
24
+ * Number of visible fractional digits in [[Number]], without trailing zeroes.
25
+ */
26
+ FractionDigitsWithoutTrailing: number;
27
27
  }
28
28
  /**
29
- * http://ecma-international.org/ecma-402/7.0/index.html#sec-getoperands
30
- * @param s
31
- */
29
+ * http://ecma-international.org/ecma-402/7.0/index.html#sec-getoperands
30
+ * @param s
31
+ */
32
32
  export declare function GetOperands(s: string): OperandsRecord;
@@ -1,46 +1,44 @@
1
- import { invariant, ToNumber, ZERO } from '@formatjs/ecma402-abstract';
1
+ import { invariant, ToNumber, ZERO } from "@formatjs/ecma402-abstract";
2
2
  /**
3
- * http://ecma-international.org/ecma-402/7.0/index.html#sec-getoperands
4
- * @param s
5
- */
3
+ * http://ecma-international.org/ecma-402/7.0/index.html#sec-getoperands
4
+ * @param s
5
+ */
6
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(n.isFinite(), 'n should be finite');
10
- var dp = s.indexOf('.');
11
- var iv;
12
- var f;
13
- var v;
14
- var fv = '';
15
- if (dp === -1) {
16
- iv = n;
17
- f = ZERO;
18
- v = 0;
19
- }
20
- else {
21
- iv = s.slice(0, dp);
22
- fv = s.slice(dp, s.length);
23
- f = ToNumber(fv);
24
- v = fv.length;
25
- }
26
- var i = ToNumber(iv).abs();
27
- var w;
28
- var t;
29
- if (!f.isZero()) {
30
- var ft = fv.replace(/0+$/, '');
31
- w = ft.length;
32
- t = ToNumber(ft);
33
- }
34
- else {
35
- w = 0;
36
- t = ZERO;
37
- }
38
- return {
39
- Number: n,
40
- IntegerDigits: i.toNumber(),
41
- NumberOfFractionDigits: v,
42
- NumberOfFractionDigitsWithoutTrailing: w,
43
- FractionDigits: f.toNumber(),
44
- FractionDigitsWithoutTrailing: t.toNumber(),
45
- };
7
+ invariant(typeof s === "string", `GetOperands should have been called with a string`);
8
+ const n = ToNumber(s);
9
+ invariant(n.isFinite(), "n should be finite");
10
+ let dp = s.indexOf(".");
11
+ let iv;
12
+ let f;
13
+ let v;
14
+ let fv = "";
15
+ if (dp === -1) {
16
+ iv = n;
17
+ f = ZERO;
18
+ v = 0;
19
+ } else {
20
+ iv = s.slice(0, dp);
21
+ fv = s.slice(dp, s.length);
22
+ f = ToNumber(fv);
23
+ v = fv.length;
24
+ }
25
+ const i = ToNumber(iv).abs();
26
+ let w;
27
+ let t;
28
+ if (!f.isZero()) {
29
+ const ft = fv.replace(/0+$/, "");
30
+ w = ft.length;
31
+ t = ToNumber(ft);
32
+ } else {
33
+ w = 0;
34
+ t = ZERO;
35
+ }
36
+ return {
37
+ Number: n,
38
+ IntegerDigits: i.toNumber(),
39
+ NumberOfFractionDigits: v,
40
+ NumberOfFractionDigitsWithoutTrailing: w,
41
+ FractionDigits: f.toNumber(),
42
+ FractionDigitsWithoutTrailing: t.toNumber()
43
+ };
46
44
  }
@@ -1,8 +1,8 @@
1
- import { PluralRulesData, PluralRulesInternal } from '@formatjs/ecma402-abstract';
2
- export declare function InitializePluralRules(pl: Intl.PluralRules, locales: string | string[] | undefined, options: Intl.PluralRulesOptions | undefined, { availableLocales, relevantExtensionKeys, localeData, getDefaultLocale, getInternalSlots, }: {
3
- availableLocales: Set<string>;
4
- relevantExtensionKeys: string[];
5
- localeData: Record<string, PluralRulesData | undefined>;
6
- getDefaultLocale(): string;
7
- getInternalSlots(pl: Intl.PluralRules): PluralRulesInternal;
1
+ import { type PluralRulesData, type PluralRulesInternal } from "@formatjs/ecma402-abstract";
2
+ export declare function InitializePluralRules(pl: Intl.PluralRules, locales: string | string[] | undefined, options: Intl.PluralRulesOptions | undefined, { availableLocales, relevantExtensionKeys, localeData, getDefaultLocale, getInternalSlots }: {
3
+ availableLocales: Set<string>;
4
+ relevantExtensionKeys: string[];
5
+ localeData: Record<string, PluralRulesData | undefined>;
6
+ getDefaultLocale(): string;
7
+ getInternalSlots(pl: Intl.PluralRules): PluralRulesInternal;
8
8
  }): Intl.PluralRules;
@@ -1,17 +1,16 @@
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) {
4
- var availableLocales = _a.availableLocales, relevantExtensionKeys = _a.relevantExtensionKeys, localeData = _a.localeData, getDefaultLocale = _a.getDefaultLocale, getInternalSlots = _a.getInternalSlots;
5
- var requestedLocales = CanonicalizeLocaleList(locales);
6
- var opt = Object.create(null);
7
- var opts = CoerceOptionsToObject(options);
8
- var internalSlots = getInternalSlots(pl);
9
- internalSlots.initializedPluralRules = true;
10
- var matcher = GetOption(opts, 'localeMatcher', 'string', ['best fit', 'lookup'], 'best fit');
11
- opt.localeMatcher = matcher;
12
- var r = ResolveLocale(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
13
- internalSlots.locale = r.locale;
14
- internalSlots.type = GetOption(opts, 'type', 'string', ['cardinal', 'ordinal'], 'cardinal');
15
- SetNumberFormatDigitOptions(internalSlots, opts, 0, 3, 'standard');
16
- return pl;
1
+ import { CanonicalizeLocaleList, CoerceOptionsToObject, GetOption, SetNumberFormatDigitOptions } from "@formatjs/ecma402-abstract";
2
+ import { ResolveLocale } from "@formatjs/intl-localematcher";
3
+ export function InitializePluralRules(pl, locales, options, { availableLocales, relevantExtensionKeys, localeData, getDefaultLocale, getInternalSlots }) {
4
+ const requestedLocales = CanonicalizeLocaleList(locales);
5
+ const opt = Object.create(null);
6
+ const opts = CoerceOptionsToObject(options);
7
+ const internalSlots = getInternalSlots(pl);
8
+ internalSlots.initializedPluralRules = true;
9
+ const matcher = GetOption(opts, "localeMatcher", "string", ["best fit", "lookup"], "best fit");
10
+ opt.localeMatcher = matcher;
11
+ const r = ResolveLocale(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
12
+ internalSlots.locale = r.locale;
13
+ internalSlots.type = GetOption(opts, "type", "string", ["cardinal", "ordinal"], "cardinal");
14
+ SetNumberFormatDigitOptions(internalSlots, opts, 0, 3, "standard");
15
+ return pl;
17
16
  }
@@ -1,13 +1,13 @@
1
- import { LDMLPluralRule, PluralRulesInternal } from '@formatjs/ecma402-abstract';
2
- import Decimal from 'decimal.js';
3
- import { OperandsRecord } from './GetOperands.js';
1
+ import { type LDMLPluralRule, type PluralRulesInternal } from "@formatjs/ecma402-abstract";
2
+ import type Decimal from "decimal.js";
3
+ import { type OperandsRecord } from "./GetOperands.js";
4
4
  /**
5
- * http://ecma-international.org/ecma-402/7.0/index.html#sec-resolveplural
6
- * @param pl
7
- * @param n
8
- * @param PluralRuleSelect Has to pass in bc it's implementation-specific
9
- */
10
- export declare function ResolvePlural(pl: Intl.PluralRules, n: Decimal, { getInternalSlots, PluralRuleSelect, }: {
11
- getInternalSlots(pl: Intl.PluralRules): PluralRulesInternal;
12
- PluralRuleSelect: (locale: string, type: 'cardinal' | 'ordinal', n: Decimal, operands: OperandsRecord) => LDMLPluralRule;
5
+ * http://ecma-international.org/ecma-402/7.0/index.html#sec-resolveplural
6
+ * @param pl
7
+ * @param n
8
+ * @param PluralRuleSelect Has to pass in bc it's implementation-specific
9
+ */
10
+ export declare function ResolvePlural(pl: Intl.PluralRules, n: Decimal, { getInternalSlots, PluralRuleSelect }: {
11
+ getInternalSlots(pl: Intl.PluralRules): PluralRulesInternal;
12
+ PluralRuleSelect: (locale: string, type: "cardinal" | "ordinal", n: Decimal, operands: OperandsRecord) => LDMLPluralRule;
13
13
  }): LDMLPluralRule;
@@ -1,22 +1,21 @@
1
- import { FormatNumericToString, invariant, Type, } from '@formatjs/ecma402-abstract';
2
- import { GetOperands } from './GetOperands.js';
1
+ import { FormatNumericToString, invariant, Type } from "@formatjs/ecma402-abstract";
2
+ import { GetOperands } from "./GetOperands.js";
3
3
  /**
4
- * http://ecma-international.org/ecma-402/7.0/index.html#sec-resolveplural
5
- * @param pl
6
- * @param n
7
- * @param PluralRuleSelect Has to pass in bc it's implementation-specific
8
- */
9
- export function ResolvePlural(pl, n, _a) {
10
- var getInternalSlots = _a.getInternalSlots, PluralRuleSelect = _a.PluralRuleSelect;
11
- 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
- if (!n.isFinite()) {
15
- return 'other';
16
- }
17
- var locale = internalSlots.locale, type = internalSlots.type;
18
- var res = FormatNumericToString(internalSlots, n);
19
- var s = res.formattedString;
20
- var operands = GetOperands(s);
21
- return PluralRuleSelect(locale, type, n, operands);
4
+ * http://ecma-international.org/ecma-402/7.0/index.html#sec-resolveplural
5
+ * @param pl
6
+ * @param n
7
+ * @param PluralRuleSelect Has to pass in bc it's implementation-specific
8
+ */
9
+ export function ResolvePlural(pl, n, { getInternalSlots, PluralRuleSelect }) {
10
+ const internalSlots = getInternalSlots(pl);
11
+ invariant(Type(internalSlots) === "Object", "pl has to be an object");
12
+ invariant("initializedPluralRules" in internalSlots, "pluralrules must be initialized");
13
+ if (!n.isFinite()) {
14
+ return "other";
15
+ }
16
+ const { locale, type } = internalSlots;
17
+ const res = FormatNumericToString(internalSlots, n);
18
+ const s = res.formattedString;
19
+ const operands = GetOperands(s);
20
+ return PluralRuleSelect(locale, type, n, operands);
22
21
  }
@@ -1,2 +1,5 @@
1
- import { PluralRules, PluralRulesInternal } from '.';
1
+ // Type-only circular import
2
+ // eslint-disable-next-line import/no-cycle
3
+ import type { PluralRules } from "./index.js";
4
+ import { type PluralRulesInternal } from "./index.js";
2
5
  export default function getInternalSlots(x: PluralRules): PluralRulesInternal;
@@ -1,9 +1,10 @@
1
- var internalSlotMap = new WeakMap();
1
+ import "./index.js";
2
+ const internalSlotMap = new WeakMap();
2
3
  export default function getInternalSlots(x) {
3
- var internalSlots = internalSlotMap.get(x);
4
- if (!internalSlots) {
5
- internalSlots = Object.create(null);
6
- internalSlotMap.set(x, internalSlots);
7
- }
8
- return internalSlots;
4
+ let internalSlots = internalSlotMap.get(x);
5
+ if (!internalSlots) {
6
+ internalSlots = Object.create(null);
7
+ internalSlotMap.set(x, internalSlots);
8
+ }
9
+ return internalSlots;
9
10
  }
package/index.d.ts CHANGED
@@ -1,20 +1,20 @@
1
- import { LDMLPluralRule, NumberFormatDigitInternalSlots, PluralRulesData, PluralRulesLocaleData } from '@formatjs/ecma402-abstract';
1
+ import { type LDMLPluralRule, type NumberFormatDigitInternalSlots, type PluralRulesData, type PluralRulesLocaleData } from "@formatjs/ecma402-abstract";
2
2
  export interface PluralRulesInternal extends NumberFormatDigitInternalSlots {
3
- initializedPluralRules: boolean;
4
- locale: string;
5
- type: 'cardinal' | 'ordinal';
3
+ initializedPluralRules: boolean;
4
+ locale: string;
5
+ type: "cardinal" | "ordinal";
6
6
  }
7
7
  export declare class PluralRules implements Intl.PluralRules {
8
- constructor(locales?: string | string[], options?: Intl.PluralRulesOptions);
9
- resolvedOptions(): Intl.ResolvedPluralRulesOptions;
10
- select(val: number): LDMLPluralRule;
11
- toString(): string;
12
- static supportedLocalesOf(locales?: string | string[], options?: Pick<Intl.PluralRulesOptions, 'localeMatcher'>): string[];
13
- static __addLocaleData(...data: PluralRulesLocaleData[]): void;
14
- static localeData: Record<string, PluralRulesData>;
15
- static availableLocales: Set<string>;
16
- static __defaultLocale: string;
17
- static getDefaultLocale(): string;
18
- static relevantExtensionKeys: never[];
19
- static polyfilled: boolean;
8
+ constructor(locales?: string | string[], options?: Intl.PluralRulesOptions);
9
+ resolvedOptions(): Intl.ResolvedPluralRulesOptions;
10
+ select(val: number): LDMLPluralRule;
11
+ toString(): string;
12
+ static supportedLocalesOf(locales?: string | string[], options?: Pick<Intl.PluralRulesOptions, "localeMatcher">): string[];
13
+ static __addLocaleData(...data: PluralRulesLocaleData[]): void;
14
+ static localeData: Record<string, PluralRulesData>;
15
+ static availableLocales: Set<string>;
16
+ static __defaultLocale: string;
17
+ static getDefaultLocale(): string;
18
+ static relevantExtensionKeys: never[];
19
+ static polyfilled: boolean;
20
20
  }
package/index.js CHANGED
@@ -1,143 +1,129 @@
1
- import { __spreadArray } from "tslib";
2
- import { CanonicalizeLocaleList, SupportedLocales, ToNumber, } from '@formatjs/ecma402-abstract';
3
- import { InitializePluralRules } from './abstract/InitializePluralRules.js';
4
- import { ResolvePlural } from './abstract/ResolvePlural.js';
5
- import getInternalSlots from './get_internal_slots.js';
1
+ import { CanonicalizeLocaleList, SupportedLocales, ToNumber } from "@formatjs/ecma402-abstract";
2
+ import "./abstract/GetOperands.js";
3
+ import { InitializePluralRules } from "./abstract/InitializePluralRules.js";
4
+ import { ResolvePlural } from "./abstract/ResolvePlural.js";
5
+ import getInternalSlots from "./get_internal_slots.js";
6
6
  function validateInstance(instance, method) {
7
- if (!(instance instanceof PluralRules)) {
8
- throw new TypeError("Method Intl.PluralRules.prototype.".concat(method, " called on incompatible receiver ").concat(String(instance)));
9
- }
7
+ if (!(instance instanceof PluralRules)) {
8
+ throw new TypeError(`Method Intl.PluralRules.prototype.${method} called on incompatible receiver ${String(instance)}`);
9
+ }
10
10
  }
11
11
  /**
12
- * http://ecma-international.org/ecma-402/7.0/index.html#sec-pluralruleselect
13
- * @param locale
14
- * @param type
15
- * @param _n
16
- * @param param3
17
- */
18
- function PluralRuleSelect(locale, type, _n, _a) {
19
- var IntegerDigits = _a.IntegerDigits, NumberOfFractionDigits = _a.NumberOfFractionDigits, FractionDigits = _a.FractionDigits;
20
- return PluralRules.localeData[locale].fn(NumberOfFractionDigits
21
- ? "".concat(IntegerDigits, ".").concat(FractionDigits)
22
- : IntegerDigits, type === 'ordinal');
12
+ * http://ecma-international.org/ecma-402/7.0/index.html#sec-pluralruleselect
13
+ * @param locale
14
+ * @param type
15
+ * @param _n
16
+ * @param param3
17
+ */
18
+ function PluralRuleSelect(locale, type, _n, { IntegerDigits, NumberOfFractionDigits, FractionDigits }) {
19
+ return PluralRules.localeData[locale].fn(NumberOfFractionDigits ? `${IntegerDigits}.${FractionDigits}` : IntegerDigits, type === "ordinal");
23
20
  }
24
- var PluralRules = /** @class */ (function () {
25
- function PluralRules(locales, options) {
26
- // test262/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js
27
- // Cannot use `new.target` bc of IE11 & TS transpiles it to something else
28
- var newTarget = this && this instanceof PluralRules ? this.constructor : void 0;
29
- if (!newTarget) {
30
- throw new TypeError("Intl.PluralRules must be called with 'new'");
31
- }
32
- return InitializePluralRules(this, locales, options, {
33
- availableLocales: PluralRules.availableLocales,
34
- relevantExtensionKeys: PluralRules.relevantExtensionKeys,
35
- localeData: PluralRules.localeData,
36
- getDefaultLocale: PluralRules.getDefaultLocale,
37
- getInternalSlots: getInternalSlots,
38
- });
39
- }
40
- PluralRules.prototype.resolvedOptions = function () {
41
- validateInstance(this, 'resolvedOptions');
42
- var opts = Object.create(null);
43
- var internalSlots = getInternalSlots(this);
44
- opts.locale = internalSlots.locale;
45
- opts.type = internalSlots.type;
46
- [
47
- 'minimumIntegerDigits',
48
- 'minimumFractionDigits',
49
- 'maximumFractionDigits',
50
- 'minimumSignificantDigits',
51
- 'maximumSignificantDigits',
52
- ].forEach(function (field) {
53
- var val = internalSlots[field];
54
- if (val !== undefined) {
55
- opts[field] = val;
56
- }
57
- });
58
- opts.pluralCategories = __spreadArray([], PluralRules.localeData[opts.locale].categories[opts.type], true);
59
- return opts;
60
- };
61
- PluralRules.prototype.select = function (val) {
62
- validateInstance(this, 'select');
63
- var n = ToNumber(val);
64
- return ResolvePlural(this, n, { getInternalSlots: getInternalSlots, PluralRuleSelect: PluralRuleSelect });
65
- };
66
- PluralRules.prototype.toString = function () {
67
- return '[object Intl.PluralRules]';
68
- };
69
- PluralRules.supportedLocalesOf = function (locales, options) {
70
- return SupportedLocales(PluralRules.availableLocales, CanonicalizeLocaleList(locales), options);
71
- };
72
- PluralRules.__addLocaleData = function () {
73
- var data = [];
74
- for (var _i = 0; _i < arguments.length; _i++) {
75
- data[_i] = arguments[_i];
76
- }
77
- for (var _a = 0, data_1 = data; _a < data_1.length; _a++) {
78
- var _b = data_1[_a], d = _b.data, locale = _b.locale;
79
- PluralRules.localeData[locale] = d;
80
- PluralRules.availableLocales.add(locale);
81
- if (!PluralRules.__defaultLocale) {
82
- PluralRules.__defaultLocale = locale;
83
- }
84
- }
85
- };
86
- PluralRules.getDefaultLocale = function () {
87
- return PluralRules.__defaultLocale;
88
- };
89
- PluralRules.localeData = {};
90
- PluralRules.availableLocales = new Set();
91
- PluralRules.__defaultLocale = '';
92
- PluralRules.relevantExtensionKeys = [];
93
- PluralRules.polyfilled = true;
94
- return PluralRules;
95
- }());
96
- export { PluralRules };
97
- try {
98
- // IE11 does not have Symbol
99
- if (typeof Symbol !== 'undefined') {
100
- Object.defineProperty(PluralRules.prototype, Symbol.toStringTag, {
101
- value: 'Intl.PluralRules',
102
- writable: false,
103
- enumerable: false,
104
- configurable: true,
105
- });
106
- }
107
- try {
108
- // https://github.com/tc39/test262/blob/master/test/intl402/PluralRules/length.js
109
- Object.defineProperty(PluralRules, 'length', {
110
- value: 0,
111
- writable: false,
112
- enumerable: false,
113
- configurable: true,
114
- });
115
- }
116
- catch (_a) {
117
- // IE 11 sets Function.prototype.length to be non-configurable which will cause the
118
- // above Object.defineProperty to throw an error.
119
- }
120
- // https://github.com/tc39/test262/blob/master/test/intl402/RelativeTimeFormat/constructor/length.js
121
- Object.defineProperty(PluralRules.prototype.constructor, 'length', {
122
- value: 0,
123
- writable: false,
124
- enumerable: false,
125
- configurable: true,
126
- });
127
- // https://github.com/tc39/test262/blob/master/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/length.js
128
- Object.defineProperty(PluralRules.supportedLocalesOf, 'length', {
129
- value: 1,
130
- writable: false,
131
- enumerable: false,
132
- configurable: true,
133
- });
134
- Object.defineProperty(PluralRules, 'name', {
135
- value: 'PluralRules',
136
- writable: false,
137
- enumerable: false,
138
- configurable: true,
139
- });
140
- }
141
- catch (_b) {
142
- // Meta fixes for test262
21
+ export class PluralRules {
22
+ constructor(locales, options) {
23
+ // test262/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js
24
+ // Cannot use `new.target` bc of IE11 & TS transpiles it to something else
25
+ const newTarget = this && this instanceof PluralRules ? this.constructor : void 0;
26
+ if (!newTarget) {
27
+ throw new TypeError("Intl.PluralRules must be called with 'new'");
28
+ }
29
+ return InitializePluralRules(this, locales, options, {
30
+ availableLocales: PluralRules.availableLocales,
31
+ relevantExtensionKeys: PluralRules.relevantExtensionKeys,
32
+ localeData: PluralRules.localeData,
33
+ getDefaultLocale: PluralRules.getDefaultLocale,
34
+ getInternalSlots
35
+ });
36
+ }
37
+ resolvedOptions() {
38
+ validateInstance(this, "resolvedOptions");
39
+ const opts = Object.create(null);
40
+ const internalSlots = getInternalSlots(this);
41
+ opts.locale = internalSlots.locale;
42
+ opts.type = internalSlots.type;
43
+ [
44
+ "minimumIntegerDigits",
45
+ "minimumFractionDigits",
46
+ "maximumFractionDigits",
47
+ "minimumSignificantDigits",
48
+ "maximumSignificantDigits"
49
+ ].forEach((field) => {
50
+ const val = internalSlots[field];
51
+ if (val !== undefined) {
52
+ opts[field] = val;
53
+ }
54
+ });
55
+ opts.pluralCategories = [...PluralRules.localeData[opts.locale].categories[opts.type]];
56
+ return opts;
57
+ }
58
+ select(val) {
59
+ validateInstance(this, "select");
60
+ const n = ToNumber(val);
61
+ return ResolvePlural(this, n, {
62
+ getInternalSlots,
63
+ PluralRuleSelect
64
+ });
65
+ }
66
+ toString() {
67
+ return "[object Intl.PluralRules]";
68
+ }
69
+ static supportedLocalesOf(locales, options) {
70
+ return SupportedLocales(PluralRules.availableLocales, CanonicalizeLocaleList(locales), options);
71
+ }
72
+ static __addLocaleData(...data) {
73
+ for (const { data: d, locale } of data) {
74
+ PluralRules.localeData[locale] = d;
75
+ PluralRules.availableLocales.add(locale);
76
+ if (!PluralRules.__defaultLocale) {
77
+ PluralRules.__defaultLocale = locale;
78
+ }
79
+ }
80
+ }
81
+ static localeData = {};
82
+ static availableLocales = new Set();
83
+ static __defaultLocale = "";
84
+ static getDefaultLocale() {
85
+ return PluralRules.__defaultLocale;
86
+ }
87
+ static relevantExtensionKeys = [];
88
+ static polyfilled = true;
143
89
  }
90
+ try {
91
+ // IE11 does not have Symbol
92
+ if (typeof Symbol !== "undefined") {
93
+ Object.defineProperty(PluralRules.prototype, Symbol.toStringTag, {
94
+ value: "Intl.PluralRules",
95
+ writable: false,
96
+ enumerable: false,
97
+ configurable: true
98
+ });
99
+ }
100
+ try {
101
+ // https://github.com/tc39/test262/blob/master/test/intl402/PluralRules/length.js
102
+ Object.defineProperty(PluralRules, "length", {
103
+ value: 0,
104
+ writable: false,
105
+ enumerable: false,
106
+ configurable: true
107
+ });
108
+ } catch {}
109
+ // https://github.com/tc39/test262/blob/master/test/intl402/RelativeTimeFormat/constructor/length.js
110
+ Object.defineProperty(PluralRules.prototype.constructor, "length", {
111
+ value: 0,
112
+ writable: false,
113
+ enumerable: false,
114
+ configurable: true
115
+ });
116
+ // https://github.com/tc39/test262/blob/master/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/length.js
117
+ Object.defineProperty(PluralRules.supportedLocalesOf, "length", {
118
+ value: 1,
119
+ writable: false,
120
+ enumerable: false,
121
+ configurable: true
122
+ });
123
+ Object.defineProperty(PluralRules, "name", {
124
+ value: "PluralRules",
125
+ writable: false,
126
+ enumerable: false,
127
+ configurable: true
128
+ });
129
+ } catch {}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formatjs/intl-pluralrules",
3
3
  "description": "Polyfill for Intl.PluralRules",
4
- "version": "6.1.1",
4
+ "version": "6.1.2",
5
5
  "license": "MIT",
6
6
  "author": "Long Ho <holevietlong@gmail.com>",
7
7
  "type": "module",
@@ -16,12 +16,12 @@
16
16
  "dependencies": {
17
17
  "decimal.js": "^10.4.3",
18
18
  "tslib": "^2.8.0",
19
- "@formatjs/intl-localematcher": "0.7.4",
20
- "@formatjs/ecma402-abstract": "3.0.7"
19
+ "@formatjs/ecma402-abstract": "3.0.8",
20
+ "@formatjs/intl-localematcher": "0.7.5"
21
21
  },
22
22
  "devDependencies": {
23
- "@formatjs/intl-getcanonicallocales": "3.1.1",
24
- "@formatjs/intl-locale": "5.1.1"
23
+ "@formatjs/intl-getcanonicallocales": "3.1.2",
24
+ "@formatjs/intl-locale": "5.1.2"
25
25
  },
26
26
  "bugs": "https://github.com/formatjs/formatjs/issues",
27
27
  "gitHead": "a7842673d8ad205171ad7c8cb8bb2f318b427c0c",