@formatjs/intl-pluralrules 6.3.1 → 6.3.3
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.d.ts +113 -65
- package/index.js +965 -64
- package/index.js.map +1 -0
- package/package.json +5 -6
- package/polyfill-force.d.ts +1 -1
- package/polyfill-force.js +1125 -2
- package/polyfill-force.js.map +1 -0
- package/polyfill.d.ts +1 -1
- package/polyfill.iife.js +5305 -5845
- package/polyfill.js +1354 -3
- package/polyfill.js.map +1 -0
- package/should-polyfill.d.ts +5 -1
- package/should-polyfill.js +227 -8
- package/should-polyfill.js.map +1 -0
- package/abstract/GetOperands.d.ts +0 -59
- package/abstract/GetOperands.js +0 -50
- package/abstract/InitializePluralRules.d.ts +0 -8
- package/abstract/InitializePluralRules.js +0 -31
- package/abstract/ResolvePlural.d.ts +0 -43
- package/abstract/ResolvePlural.js +0 -75
- package/abstract/ResolvePluralRange.d.ts +0 -23
- package/abstract/ResolvePluralRange.js +0 -59
- package/get_internal_slots.d.ts +0 -3
- package/get_internal_slots.js +0 -10
- package/supported-locales.generated.d.ts +0 -1
- package/supported-locales.generated.js +0 -217
package/index.d.ts
CHANGED
|
@@ -1,4 +1,49 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Decimal as Decimal$1 } from "@formatjs/bigdecimal";
|
|
2
|
+
|
|
3
|
+
//#region packages/ecma402-abstract/types/core.d.ts
|
|
4
|
+
type Locale = string;
|
|
5
|
+
interface LocaleData<T> {
|
|
6
|
+
data: T;
|
|
7
|
+
locale: Locale;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region packages/ecma402-abstract/types/plural-rules.d.ts
|
|
11
|
+
type LDMLPluralRule = "zero" | "one" | "two" | "few" | "many" | "other";
|
|
12
|
+
interface PluralRangesData {
|
|
13
|
+
cardinal?: Record<string, LDMLPluralRule>;
|
|
14
|
+
ordinal?: Record<string, LDMLPluralRule>;
|
|
15
|
+
}
|
|
16
|
+
interface PluralRulesData {
|
|
17
|
+
categories: {
|
|
18
|
+
cardinal: string[];
|
|
19
|
+
ordinal: string[];
|
|
20
|
+
};
|
|
21
|
+
fn: (val: number | string, ord?: boolean, exponent?: number) => LDMLPluralRule;
|
|
22
|
+
pluralRanges?: PluralRangesData;
|
|
23
|
+
}
|
|
24
|
+
type PluralRulesLocaleData = LocaleData<PluralRulesData>;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region packages/ecma402-abstract/types/number.d.ts
|
|
27
|
+
type NumberFormatNotation = "standard" | "scientific" | "engineering" | "compact";
|
|
28
|
+
type RoundingPriorityType = "auto" | "morePrecision" | "lessPrecision";
|
|
29
|
+
type NumberFormatRoundingType = "morePrecision" | "lessPrecision" | "significantDigits" | "fractionDigits";
|
|
30
|
+
type RoundingModeType = "ceil" | "floor" | "expand" | "trunc" | "halfCeil" | "halfFloor" | "halfExpand" | "halfTrunc" | "halfEven";
|
|
31
|
+
interface NumberFormatDigitInternalSlots {
|
|
32
|
+
minimumIntegerDigits: number;
|
|
33
|
+
minimumSignificantDigits: number;
|
|
34
|
+
maximumSignificantDigits: number;
|
|
35
|
+
roundingType: NumberFormatRoundingType;
|
|
36
|
+
minimumFractionDigits: number;
|
|
37
|
+
maximumFractionDigits: number;
|
|
38
|
+
notation: NumberFormatNotation;
|
|
39
|
+
roundingIncrement: number;
|
|
40
|
+
roundingMode: RoundingModeType;
|
|
41
|
+
trailingZeroDisplay: TrailingZeroDisplay;
|
|
42
|
+
roundingPriority: RoundingPriorityType;
|
|
43
|
+
}
|
|
44
|
+
type TrailingZeroDisplay = "auto" | "stripIfInteger";
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region packages/intl-pluralrules/index.d.ts
|
|
2
47
|
/**
|
|
3
48
|
* Type augmentation for Intl.PluralRules
|
|
4
49
|
*
|
|
@@ -9,70 +54,73 @@ import { type LDMLPluralRule, type NumberFormatDigitInternalSlots, type PluralRu
|
|
|
9
54
|
* Mirrors Intl.NumberFormat notation option for proper plural selection with compact numbers
|
|
10
55
|
*/
|
|
11
56
|
declare global {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
57
|
+
namespace Intl {
|
|
58
|
+
interface PluralRules {
|
|
59
|
+
selectRange(start: number | bigint, end: number | bigint): LDMLPluralRule;
|
|
60
|
+
}
|
|
61
|
+
interface PluralRulesOptions {
|
|
62
|
+
notation?: "standard" | "compact";
|
|
63
|
+
compactDisplay?: "short" | "long";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
21
66
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
67
|
+
interface PluralRulesInternal extends NumberFormatDigitInternalSlots {
|
|
68
|
+
initializedPluralRules: boolean;
|
|
69
|
+
locale: string;
|
|
70
|
+
type: "cardinal" | "ordinal";
|
|
71
|
+
notation: "standard" | "compact";
|
|
72
|
+
compactDisplay?: "short" | "long";
|
|
73
|
+
dataLocaleData?: any;
|
|
29
74
|
}
|
|
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
|
-
|
|
75
|
+
declare class PluralRules {
|
|
76
|
+
constructor(locales?: string | string[], options?: Intl.PluralRulesOptions);
|
|
77
|
+
resolvedOptions(): Intl.ResolvedPluralRulesOptions;
|
|
78
|
+
select(val: number | bigint): LDMLPluralRule;
|
|
79
|
+
/**
|
|
80
|
+
* Intl.PluralRules.prototype.selectRange ( start, end )
|
|
81
|
+
*
|
|
82
|
+
* Returns a string indicating which plural rule applies to a range of numbers.
|
|
83
|
+
* This is useful for formatting ranges like "1-2 items" vs "2-3 items" where
|
|
84
|
+
* different languages have different plural rules for ranges.
|
|
85
|
+
*
|
|
86
|
+
* Specification: https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.selectrange
|
|
87
|
+
*
|
|
88
|
+
* @param start - The start value of the range (number or bigint)
|
|
89
|
+
* @param end - The end value of the range (number or bigint)
|
|
90
|
+
* @returns The plural category for the range (zero, one, two, few, many, or other)
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* const pr = new Intl.PluralRules('en');
|
|
94
|
+
* pr.selectRange(1, 2); // "other" (English: "1-2 items")
|
|
95
|
+
* pr.selectRange(1, 1); // "one" (same value: "1 item")
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* const prFr = new Intl.PluralRules('fr');
|
|
99
|
+
* prFr.selectRange(0, 1); // "one" (French: "0-1 vue")
|
|
100
|
+
* prFr.selectRange(1, 2); // "other" (French: "1-2 vues")
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* // BigInt support (spec-compliant, but Chrome has a bug as of early 2025)
|
|
104
|
+
* pr.selectRange(BigInt(1), BigInt(2)); // "other"
|
|
105
|
+
*
|
|
106
|
+
* @throws {TypeError} If start or end is undefined
|
|
107
|
+
* @throws {RangeError} If start or end is not a finite number (Infinity, NaN)
|
|
108
|
+
*
|
|
109
|
+
* @note Chrome's native implementation (as of early 2025) has a bug where it throws
|
|
110
|
+
* "Cannot convert a BigInt value to a number" when using BigInt arguments. This is
|
|
111
|
+
* a browser bug - the spec requires BigInt support. This polyfill handles BigInt correctly.
|
|
112
|
+
*/
|
|
113
|
+
selectRange(start: number | bigint, end: number | bigint): LDMLPluralRule;
|
|
114
|
+
toString(): string;
|
|
115
|
+
static supportedLocalesOf(locales?: string | string[], options?: Pick<Intl.PluralRulesOptions, "localeMatcher">): string[];
|
|
116
|
+
static __addLocaleData(...data: PluralRulesLocaleData[]): void;
|
|
117
|
+
static localeData: Record<string, PluralRulesData>;
|
|
118
|
+
static availableLocales: Set<string>;
|
|
119
|
+
static __defaultLocale: string;
|
|
120
|
+
static getDefaultLocale(): string;
|
|
121
|
+
static relevantExtensionKeys: never[];
|
|
122
|
+
static polyfilled: boolean;
|
|
78
123
|
}
|
|
124
|
+
//#endregion
|
|
125
|
+
export { PluralRules, PluralRulesInternal };
|
|
126
|
+
//# sourceMappingURL=index.d.ts.map
|