@formatjs/intl-pluralrules 5.3.6 → 5.4.1
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 +2 -1
- package/abstract/GetOperands.js +8 -8
- package/abstract/InitializePluralRules.d.ts +1 -1
- package/abstract/InitializePluralRules.js +2 -2
- package/abstract/ResolvePlural.d.ts +4 -3
- package/abstract/ResolvePlural.js +1 -2
- package/index.d.ts +1 -1
- package/lib/abstract/GetOperands.d.ts +2 -1
- package/lib/abstract/GetOperands.js +9 -9
- package/lib/abstract/InitializePluralRules.d.ts +1 -1
- package/lib/abstract/InitializePluralRules.js +2 -2
- package/lib/abstract/ResolvePlural.d.ts +4 -3
- package/lib/abstract/ResolvePlural.js +2 -3
- package/lib/index.d.ts +1 -1
- package/package.json +6 -5
- package/polyfill.iife.js +2708 -137
package/abstract/GetOperands.js
CHANGED
|
@@ -9,7 +9,7 @@ var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
|
9
9
|
function GetOperands(s) {
|
|
10
10
|
(0, ecma402_abstract_1.invariant)(typeof s === 'string', "GetOperands should have been called with a string");
|
|
11
11
|
var n = (0, ecma402_abstract_1.ToNumber)(s);
|
|
12
|
-
(0, ecma402_abstract_1.invariant)(isFinite(
|
|
12
|
+
(0, ecma402_abstract_1.invariant)(n.isFinite(), 'n should be finite');
|
|
13
13
|
var dp = s.indexOf('.');
|
|
14
14
|
var iv;
|
|
15
15
|
var f;
|
|
@@ -17,7 +17,7 @@ function GetOperands(s) {
|
|
|
17
17
|
var fv = '';
|
|
18
18
|
if (dp === -1) {
|
|
19
19
|
iv = n;
|
|
20
|
-
f =
|
|
20
|
+
f = ecma402_abstract_1.ZERO;
|
|
21
21
|
v = 0;
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
@@ -26,24 +26,24 @@ function GetOperands(s) {
|
|
|
26
26
|
f = (0, ecma402_abstract_1.ToNumber)(fv);
|
|
27
27
|
v = fv.length;
|
|
28
28
|
}
|
|
29
|
-
var i =
|
|
29
|
+
var i = (0, ecma402_abstract_1.ToNumber)(iv).abs();
|
|
30
30
|
var w;
|
|
31
31
|
var t;
|
|
32
|
-
if (f
|
|
32
|
+
if (!f.isZero()) {
|
|
33
33
|
var ft = fv.replace(/0+$/, '');
|
|
34
34
|
w = ft.length;
|
|
35
35
|
t = (0, ecma402_abstract_1.ToNumber)(ft);
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
38
|
w = 0;
|
|
39
|
-
t =
|
|
39
|
+
t = ecma402_abstract_1.ZERO;
|
|
40
40
|
}
|
|
41
41
|
return {
|
|
42
42
|
Number: n,
|
|
43
|
-
IntegerDigits: i,
|
|
43
|
+
IntegerDigits: i.toNumber(),
|
|
44
44
|
NumberOfFractionDigits: v,
|
|
45
45
|
NumberOfFractionDigitsWithoutTrailing: w,
|
|
46
|
-
FractionDigits: f,
|
|
47
|
-
FractionDigitsWithoutTrailing: t,
|
|
46
|
+
FractionDigits: f.toNumber(),
|
|
47
|
+
FractionDigitsWithoutTrailing: t.toNumber(),
|
|
48
48
|
};
|
|
49
49
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluralRulesData, PluralRulesInternal } from '@formatjs/ecma402-abstract';
|
|
2
2
|
export declare function InitializePluralRules(pl: Intl.PluralRules, locales: string | string[] | undefined, options: Intl.PluralRulesOptions | undefined, { availableLocales, relevantExtensionKeys, localeData, getDefaultLocale, getInternalSlots, }: {
|
|
3
3
|
availableLocales: Set<string>;
|
|
4
4
|
relevantExtensionKeys: string[];
|
|
@@ -12,9 +12,9 @@ function InitializePluralRules(pl, locales, options, _a) {
|
|
|
12
12
|
internalSlots.initializedPluralRules = true;
|
|
13
13
|
var matcher = (0, ecma402_abstract_1.GetOption)(opts, 'localeMatcher', 'string', ['best fit', 'lookup'], 'best fit');
|
|
14
14
|
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
15
|
var r = (0, intl_localematcher_1.ResolveLocale)(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
|
|
18
16
|
internalSlots.locale = r.locale;
|
|
17
|
+
internalSlots.type = (0, ecma402_abstract_1.GetOption)(opts, 'type', 'string', ['cardinal', 'ordinal'], 'cardinal');
|
|
18
|
+
(0, ecma402_abstract_1.SetNumberFormatDigitOptions)(internalSlots, opts, 0, 3, 'standard');
|
|
19
19
|
return pl;
|
|
20
20
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LDMLPluralRule, PluralRulesInternal } from '@formatjs/ecma402-abstract';
|
|
2
|
+
import Decimal from 'decimal.js';
|
|
2
3
|
import { OperandsRecord } from './GetOperands';
|
|
3
4
|
/**
|
|
4
5
|
* http://ecma-international.org/ecma-402/7.0/index.html#sec-resolveplural
|
|
@@ -6,7 +7,7 @@ import { OperandsRecord } from './GetOperands';
|
|
|
6
7
|
* @param n
|
|
7
8
|
* @param PluralRuleSelect Has to pass in bc it's implementation-specific
|
|
8
9
|
*/
|
|
9
|
-
export declare function ResolvePlural(pl: Intl.PluralRules, n:
|
|
10
|
+
export declare function ResolvePlural(pl: Intl.PluralRules, n: Decimal, { getInternalSlots, PluralRuleSelect, }: {
|
|
10
11
|
getInternalSlots(pl: Intl.PluralRules): PluralRulesInternal;
|
|
11
|
-
PluralRuleSelect: (locale: string, type: 'cardinal' | 'ordinal', n:
|
|
12
|
+
PluralRuleSelect: (locale: string, type: 'cardinal' | 'ordinal', n: Decimal, operands: OperandsRecord) => LDMLPluralRule;
|
|
12
13
|
}): LDMLPluralRule;
|
|
@@ -14,8 +14,7 @@ function ResolvePlural(pl, n, _a) {
|
|
|
14
14
|
var internalSlots = getInternalSlots(pl);
|
|
15
15
|
(0, ecma402_abstract_1.invariant)((0, ecma402_abstract_1.Type)(internalSlots) === 'Object', 'pl has to be an object');
|
|
16
16
|
(0, ecma402_abstract_1.invariant)('initializedPluralRules' in internalSlots, 'pluralrules must be initialized');
|
|
17
|
-
|
|
18
|
-
if (!isFinite(n)) {
|
|
17
|
+
if (!n.isFinite()) {
|
|
19
18
|
return 'other';
|
|
20
19
|
}
|
|
21
20
|
var locale = internalSlots.locale, type = internalSlots.type;
|
package/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface PluralRulesInternal extends NumberFormatDigitInternalSlots {
|
|
|
6
6
|
}
|
|
7
7
|
export declare class PluralRules implements Intl.PluralRules {
|
|
8
8
|
constructor(locales?: string | string[], options?: Intl.PluralRulesOptions);
|
|
9
|
-
resolvedOptions():
|
|
9
|
+
resolvedOptions(): Intl.ResolvedPluralRulesOptions;
|
|
10
10
|
select(val: number): LDMLPluralRule;
|
|
11
11
|
toString(): string;
|
|
12
12
|
static supportedLocalesOf(locales?: string | string[], options?: Pick<Intl.PluralRulesOptions, 'localeMatcher'>): string[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { invariant, ToNumber } from '@formatjs/ecma402-abstract';
|
|
1
|
+
import { invariant, ToNumber, ZERO } from '@formatjs/ecma402-abstract';
|
|
2
2
|
/**
|
|
3
3
|
* http://ecma-international.org/ecma-402/7.0/index.html#sec-getoperands
|
|
4
4
|
* @param s
|
|
@@ -6,7 +6,7 @@ import { invariant, ToNumber } from '@formatjs/ecma402-abstract';
|
|
|
6
6
|
export function GetOperands(s) {
|
|
7
7
|
invariant(typeof s === 'string', "GetOperands should have been called with a string");
|
|
8
8
|
var n = ToNumber(s);
|
|
9
|
-
invariant(isFinite(
|
|
9
|
+
invariant(n.isFinite(), 'n should be finite');
|
|
10
10
|
var dp = s.indexOf('.');
|
|
11
11
|
var iv;
|
|
12
12
|
var f;
|
|
@@ -14,7 +14,7 @@ export function GetOperands(s) {
|
|
|
14
14
|
var fv = '';
|
|
15
15
|
if (dp === -1) {
|
|
16
16
|
iv = n;
|
|
17
|
-
f =
|
|
17
|
+
f = ZERO;
|
|
18
18
|
v = 0;
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
@@ -23,24 +23,24 @@ export function GetOperands(s) {
|
|
|
23
23
|
f = ToNumber(fv);
|
|
24
24
|
v = fv.length;
|
|
25
25
|
}
|
|
26
|
-
var i =
|
|
26
|
+
var i = ToNumber(iv).abs();
|
|
27
27
|
var w;
|
|
28
28
|
var t;
|
|
29
|
-
if (f
|
|
29
|
+
if (!f.isZero()) {
|
|
30
30
|
var ft = fv.replace(/0+$/, '');
|
|
31
31
|
w = ft.length;
|
|
32
32
|
t = ToNumber(ft);
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
35
|
w = 0;
|
|
36
|
-
t =
|
|
36
|
+
t = ZERO;
|
|
37
37
|
}
|
|
38
38
|
return {
|
|
39
39
|
Number: n,
|
|
40
|
-
IntegerDigits: i,
|
|
40
|
+
IntegerDigits: i.toNumber(),
|
|
41
41
|
NumberOfFractionDigits: v,
|
|
42
42
|
NumberOfFractionDigitsWithoutTrailing: w,
|
|
43
|
-
FractionDigits: f,
|
|
44
|
-
FractionDigitsWithoutTrailing: t,
|
|
43
|
+
FractionDigits: f.toNumber(),
|
|
44
|
+
FractionDigitsWithoutTrailing: t.toNumber(),
|
|
45
45
|
};
|
|
46
46
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluralRulesData, PluralRulesInternal } from '@formatjs/ecma402-abstract';
|
|
2
2
|
export declare function InitializePluralRules(pl: Intl.PluralRules, locales: string | string[] | undefined, options: Intl.PluralRulesOptions | undefined, { availableLocales, relevantExtensionKeys, localeData, getDefaultLocale, getInternalSlots, }: {
|
|
3
3
|
availableLocales: Set<string>;
|
|
4
4
|
relevantExtensionKeys: string[];
|
|
@@ -9,9 +9,9 @@ export function InitializePluralRules(pl, locales, options, _a) {
|
|
|
9
9
|
internalSlots.initializedPluralRules = true;
|
|
10
10
|
var matcher = GetOption(opts, 'localeMatcher', 'string', ['best fit', 'lookup'], 'best fit');
|
|
11
11
|
opt.localeMatcher = matcher;
|
|
12
|
-
internalSlots.type = GetOption(opts, 'type', 'string', ['cardinal', 'ordinal'], 'cardinal');
|
|
13
|
-
SetNumberFormatDigitOptions(internalSlots, opts, 0, 3, 'standard');
|
|
14
12
|
var r = ResolveLocale(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
|
|
15
13
|
internalSlots.locale = r.locale;
|
|
14
|
+
internalSlots.type = GetOption(opts, 'type', 'string', ['cardinal', 'ordinal'], 'cardinal');
|
|
15
|
+
SetNumberFormatDigitOptions(internalSlots, opts, 0, 3, 'standard');
|
|
16
16
|
return pl;
|
|
17
17
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LDMLPluralRule, PluralRulesInternal } from '@formatjs/ecma402-abstract';
|
|
2
|
+
import Decimal from 'decimal.js';
|
|
2
3
|
import { OperandsRecord } from './GetOperands';
|
|
3
4
|
/**
|
|
4
5
|
* http://ecma-international.org/ecma-402/7.0/index.html#sec-resolveplural
|
|
@@ -6,7 +7,7 @@ import { OperandsRecord } from './GetOperands';
|
|
|
6
7
|
* @param n
|
|
7
8
|
* @param PluralRuleSelect Has to pass in bc it's implementation-specific
|
|
8
9
|
*/
|
|
9
|
-
export declare function ResolvePlural(pl: Intl.PluralRules, n:
|
|
10
|
+
export declare function ResolvePlural(pl: Intl.PluralRules, n: Decimal, { getInternalSlots, PluralRuleSelect, }: {
|
|
10
11
|
getInternalSlots(pl: Intl.PluralRules): PluralRulesInternal;
|
|
11
|
-
PluralRuleSelect: (locale: string, type: 'cardinal' | 'ordinal', n:
|
|
12
|
+
PluralRuleSelect: (locale: string, type: 'cardinal' | 'ordinal', n: Decimal, operands: OperandsRecord) => LDMLPluralRule;
|
|
12
13
|
}): LDMLPluralRule;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FormatNumericToString, invariant, Type, } from '@formatjs/ecma402-abstract';
|
|
2
2
|
import { GetOperands } from './GetOperands';
|
|
3
3
|
/**
|
|
4
4
|
* http://ecma-international.org/ecma-402/7.0/index.html#sec-resolveplural
|
|
@@ -11,8 +11,7 @@ export function ResolvePlural(pl, n, _a) {
|
|
|
11
11
|
var internalSlots = getInternalSlots(pl);
|
|
12
12
|
invariant(Type(internalSlots) === 'Object', 'pl has to be an object');
|
|
13
13
|
invariant('initializedPluralRules' in internalSlots, 'pluralrules must be initialized');
|
|
14
|
-
|
|
15
|
-
if (!isFinite(n)) {
|
|
14
|
+
if (!n.isFinite()) {
|
|
16
15
|
return 'other';
|
|
17
16
|
}
|
|
18
17
|
var locale = internalSlots.locale, type = internalSlots.type;
|
package/lib/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface PluralRulesInternal extends NumberFormatDigitInternalSlots {
|
|
|
6
6
|
}
|
|
7
7
|
export declare class PluralRules implements Intl.PluralRules {
|
|
8
8
|
constructor(locales?: string | string[], options?: Intl.PluralRulesOptions);
|
|
9
|
-
resolvedOptions():
|
|
9
|
+
resolvedOptions(): Intl.ResolvedPluralRulesOptions;
|
|
10
10
|
select(val: number): LDMLPluralRule;
|
|
11
11
|
toString(): string;
|
|
12
12
|
static supportedLocalesOf(locales?: string | string[], options?: Pick<Intl.PluralRulesOptions, 'localeMatcher'>): string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/intl-pluralrules",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.1",
|
|
4
4
|
"description": "Polyfill for Intl.PluralRules",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"polyfill",
|
|
@@ -20,13 +20,14 @@
|
|
|
20
20
|
"url": "git+https://github.com/formatjs/formatjs.git"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"decimal.js": "10",
|
|
23
24
|
"tslib": "2",
|
|
24
|
-
"@formatjs/
|
|
25
|
-
"@formatjs/
|
|
25
|
+
"@formatjs/intl-localematcher": "0.5.9",
|
|
26
|
+
"@formatjs/ecma402-abstract": "2.3.1"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"@formatjs/intl-getcanonicallocales": "2.5.
|
|
29
|
-
"@formatjs/intl-locale": "4.2.
|
|
29
|
+
"@formatjs/intl-getcanonicallocales": "2.5.4",
|
|
30
|
+
"@formatjs/intl-locale": "4.2.8"
|
|
30
31
|
},
|
|
31
32
|
"bugs": {
|
|
32
33
|
"url": "https://github.com/formatjs/formatjs/issues"
|