@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.
- package/abstract/GetOperands.d.ts +28 -28
- package/abstract/GetOperands.js +41 -43
- package/abstract/InitializePluralRules.d.ts +7 -7
- package/abstract/InitializePluralRules.js +15 -16
- package/abstract/ResolvePlural.d.ts +11 -11
- package/abstract/ResolvePlural.js +19 -20
- package/get_internal_slots.d.ts +4 -1
- package/get_internal_slots.js +8 -7
- package/index.d.ts +16 -16
- package/index.js +124 -138
- package/package.json +5 -5
- package/polyfill-force.js +6 -6
- package/polyfill.iife.js +2415 -3159
- package/polyfill.js +8 -8
- package/should-polyfill.js +11 -15
- package/supported-locales.generated.js +216 -216
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import Decimal from
|
|
1
|
+
import type Decimal from "decimal.js";
|
|
2
2
|
export interface OperandsRecord {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
30
|
-
|
|
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;
|
package/abstract/GetOperands.js
CHANGED
|
@@ -1,46 +1,44 @@
|
|
|
1
|
-
import { invariant, ToNumber, ZERO } from
|
|
1
|
+
import { invariant, ToNumber, ZERO } from "@formatjs/ecma402-abstract";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
|
2
|
-
export declare function InitializePluralRules(pl: Intl.PluralRules, locales: string | string[] | undefined, options: Intl.PluralRulesOptions | undefined, { availableLocales, relevantExtensionKeys, localeData, getDefaultLocale, getInternalSlots
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
2
|
-
import { ResolveLocale } from
|
|
3
|
-
export function InitializePluralRules(pl, locales, options,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
2
|
-
import Decimal from
|
|
3
|
-
import { OperandsRecord } from
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export declare function ResolvePlural(pl: Intl.PluralRules, n: Decimal, { getInternalSlots, PluralRuleSelect
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
2
|
-
import { GetOperands } from
|
|
1
|
+
import { FormatNumericToString, invariant, Type } from "@formatjs/ecma402-abstract";
|
|
2
|
+
import { GetOperands } from "./GetOperands.js";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export function ResolvePlural(pl, n,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
}
|
package/get_internal_slots.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
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;
|
package/get_internal_slots.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import "./index.js";
|
|
2
|
+
const internalSlotMap = new WeakMap();
|
|
2
3
|
export default function getInternalSlots(x) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
1
|
+
import { type LDMLPluralRule, type NumberFormatDigitInternalSlots, type PluralRulesData, type PluralRulesLocaleData } from "@formatjs/ecma402-abstract";
|
|
2
2
|
export interface PluralRulesInternal extends NumberFormatDigitInternalSlots {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
initializedPluralRules: boolean;
|
|
4
|
+
locale: string;
|
|
5
|
+
type: "cardinal" | "ordinal";
|
|
6
6
|
}
|
|
7
7
|
export declare class PluralRules implements Intl.PluralRules {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 {
|
|
2
|
-
import
|
|
3
|
-
import { InitializePluralRules } from
|
|
4
|
-
import { ResolvePlural } from
|
|
5
|
-
import getInternalSlots from
|
|
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
|
-
|
|
8
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function PluralRuleSelect(locale, type, _n,
|
|
19
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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.
|
|
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/
|
|
20
|
-
"@formatjs/
|
|
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.
|
|
24
|
-
"@formatjs/intl-locale": "5.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",
|