@formatjs/intl-pluralrules 6.3.12 → 6.3.14
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 +48 -48
- package/index.js +519 -154
- package/index.js.map +1 -1
- package/locale-data/ca.js +2 -2
- package/locale-data/es.js +2 -2
- package/locale-data/fr.js +2 -2
- package/locale-data/it.js +2 -2
- package/locale-data/lld.js +2 -2
- package/locale-data/pt-PT.js +2 -2
- package/locale-data/pt.js +2 -2
- package/locale-data/scn.js +2 -2
- package/locale-data/vec.js +2 -2
- package/package.json +2 -2
- package/polyfill-force.d.ts +1 -1
- package/polyfill-force.js +519 -156
- package/polyfill-force.js.map +1 -1
- package/polyfill.d.ts +1 -1
- package/polyfill.iife.js +783 -178
- package/polyfill.js +519 -154
- package/polyfill.js.map +1 -1
- package/should-polyfill.d.ts +1 -2
package/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Decimal } from "@formatjs/bigdecimal";
|
|
2
|
-
|
|
3
2
|
//#region packages/ecma402-abstract/types/core.d.ts
|
|
4
3
|
type Locale = string;
|
|
5
4
|
interface LocaleData<T> {
|
|
@@ -13,7 +12,9 @@ interface PluralRangesData {
|
|
|
13
12
|
cardinal?: Record<string, LDMLPluralRule>;
|
|
14
13
|
ordinal?: Record<string, LDMLPluralRule>;
|
|
15
14
|
}
|
|
15
|
+
type CompactExponentData = Record<"short" | "long", Record<number, number>>;
|
|
16
16
|
interface PluralRulesData {
|
|
17
|
+
compactExponents?: CompactExponentData;
|
|
17
18
|
categories: {
|
|
18
19
|
cardinal: string[];
|
|
19
20
|
ordinal: string[];
|
|
@@ -45,71 +46,71 @@ type TrailingZeroDisplay = "auto" | "stripIfInteger";
|
|
|
45
46
|
//#endregion
|
|
46
47
|
//#region packages/intl-pluralrules/index.d.ts
|
|
47
48
|
/**
|
|
48
|
-
* Type augmentation for Intl.PluralRules
|
|
49
|
-
*
|
|
50
|
-
* ECMA-402 Spec: selectRange method (Intl.PluralRules.prototype.selectRange)
|
|
51
|
-
* https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.selectrange
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* Mirrors Intl.NumberFormat notation option for proper plural selection with compact numbers
|
|
55
|
-
*/
|
|
49
|
+
* Type augmentation for Intl.PluralRules
|
|
50
|
+
*
|
|
51
|
+
* ECMA-402 Spec: selectRange method (Intl.PluralRules.prototype.selectRange)
|
|
52
|
+
* https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.selectrange
|
|
53
|
+
*
|
|
54
|
+
* ECMA-402 notation and compactDisplay options
|
|
55
|
+
* Mirrors Intl.NumberFormat notation option for proper plural selection with compact numbers
|
|
56
|
+
*/
|
|
56
57
|
declare global {
|
|
57
58
|
namespace Intl {
|
|
58
59
|
interface PluralRules {
|
|
59
60
|
selectRange(start: number | bigint, end: number | bigint): LDMLPluralRule;
|
|
60
61
|
}
|
|
61
62
|
interface PluralRulesOptions {
|
|
62
|
-
notation?: "standard" | "compact";
|
|
63
|
+
notation?: "standard" | "scientific" | "engineering" | "compact";
|
|
63
64
|
compactDisplay?: "short" | "long";
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
|
-
interface PluralRulesInternal extends NumberFormatDigitInternalSlots {
|
|
68
|
+
export interface PluralRulesInternal extends NumberFormatDigitInternalSlots {
|
|
68
69
|
initializedPluralRules: boolean;
|
|
69
70
|
locale: string;
|
|
70
71
|
type: "cardinal" | "ordinal";
|
|
71
|
-
notation: "standard" | "compact";
|
|
72
|
+
notation: "standard" | "scientific" | "engineering" | "compact";
|
|
72
73
|
compactDisplay?: "short" | "long";
|
|
73
|
-
|
|
74
|
+
compactExponents?: CompactExponentData;
|
|
74
75
|
}
|
|
75
|
-
declare class PluralRules {
|
|
76
|
+
export declare class PluralRules {
|
|
76
77
|
constructor(locales?: string | string[], options?: Intl.PluralRulesOptions);
|
|
77
78
|
resolvedOptions(): Intl.ResolvedPluralRulesOptions;
|
|
78
79
|
select(val: number | bigint): LDMLPluralRule;
|
|
79
80
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
81
|
+
* Intl.PluralRules.prototype.selectRange ( start, end )
|
|
82
|
+
*
|
|
83
|
+
* Returns a string indicating which plural rule applies to a range of numbers.
|
|
84
|
+
* This is useful for formatting ranges like "1-2 items" vs "2-3 items" where
|
|
85
|
+
* different languages have different plural rules for ranges.
|
|
86
|
+
*
|
|
87
|
+
* Specification: https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.selectrange
|
|
88
|
+
*
|
|
89
|
+
* @param start - The start value of the range (number or bigint)
|
|
90
|
+
* @param end - The end value of the range (number or bigint)
|
|
91
|
+
* @returns The plural category for the range (zero, one, two, few, many, or other)
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* const pr = new Intl.PluralRules('en');
|
|
95
|
+
* pr.selectRange(1, 2); // "other" (English: "1-2 items")
|
|
96
|
+
* pr.selectRange(1, 1); // "one" (same value: "1 item")
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* const prFr = new Intl.PluralRules('fr');
|
|
100
|
+
* prFr.selectRange(0, 1); // "one" (French: "0-1 vue")
|
|
101
|
+
* prFr.selectRange(1, 2); // "other" (French: "1-2 vues")
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* // BigInt support (spec-compliant, but Chrome has a bug as of early 2025)
|
|
105
|
+
* pr.selectRange(BigInt(1), BigInt(2)); // "other"
|
|
106
|
+
*
|
|
107
|
+
* @throws {TypeError} If start or end is undefined
|
|
108
|
+
* @throws {RangeError} If start or end converts to NaN
|
|
109
|
+
*
|
|
110
|
+
* @note Chrome's native implementation (as of early 2025) has a bug where it throws
|
|
111
|
+
* "Cannot convert a BigInt value to a number" when using BigInt arguments. This is
|
|
112
|
+
* a browser bug - the spec requires BigInt support. This polyfill handles BigInt correctly.
|
|
113
|
+
*/
|
|
113
114
|
selectRange(start: number | bigint, end: number | bigint): LDMLPluralRule;
|
|
114
115
|
toString(): string;
|
|
115
116
|
static supportedLocalesOf(locales?: string | string[], options?: Pick<Intl.PluralRulesOptions, "localeMatcher">): string[];
|
|
@@ -122,5 +123,4 @@ declare class PluralRules {
|
|
|
122
123
|
static polyfilled: boolean;
|
|
123
124
|
}
|
|
124
125
|
//#endregion
|
|
125
|
-
export { PluralRules, PluralRulesInternal };
|
|
126
126
|
//# sourceMappingURL=index.d.ts.map
|