@formatjs/intl-pluralrules 6.3.11 → 6.3.13
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 +41 -42
- package/package.json +3 -3
- package/polyfill.iife.js +2 -1
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> {
|
|
@@ -45,14 +44,14 @@ type TrailingZeroDisplay = "auto" | "stripIfInteger";
|
|
|
45
44
|
//#endregion
|
|
46
45
|
//#region packages/intl-pluralrules/index.d.ts
|
|
47
46
|
/**
|
|
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
|
-
* Extension: notation and compactDisplay options (not in ECMA-402 spec)
|
|
54
|
-
* Mirrors Intl.NumberFormat notation option for proper plural selection with compact numbers
|
|
55
|
-
*/
|
|
47
|
+
* Type augmentation for Intl.PluralRules
|
|
48
|
+
*
|
|
49
|
+
* ECMA-402 Spec: selectRange method (Intl.PluralRules.prototype.selectRange)
|
|
50
|
+
* https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.selectrange
|
|
51
|
+
*
|
|
52
|
+
* Extension: notation and compactDisplay options (not in ECMA-402 spec)
|
|
53
|
+
* Mirrors Intl.NumberFormat notation option for proper plural selection with compact numbers
|
|
54
|
+
*/
|
|
56
55
|
declare global {
|
|
57
56
|
namespace Intl {
|
|
58
57
|
interface PluralRules {
|
|
@@ -77,39 +76,39 @@ declare class PluralRules {
|
|
|
77
76
|
resolvedOptions(): Intl.ResolvedPluralRulesOptions;
|
|
78
77
|
select(val: number | bigint): LDMLPluralRule;
|
|
79
78
|
/**
|
|
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
|
-
|
|
79
|
+
* Intl.PluralRules.prototype.selectRange ( start, end )
|
|
80
|
+
*
|
|
81
|
+
* Returns a string indicating which plural rule applies to a range of numbers.
|
|
82
|
+
* This is useful for formatting ranges like "1-2 items" vs "2-3 items" where
|
|
83
|
+
* different languages have different plural rules for ranges.
|
|
84
|
+
*
|
|
85
|
+
* Specification: https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.selectrange
|
|
86
|
+
*
|
|
87
|
+
* @param start - The start value of the range (number or bigint)
|
|
88
|
+
* @param end - The end value of the range (number or bigint)
|
|
89
|
+
* @returns The plural category for the range (zero, one, two, few, many, or other)
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* const pr = new Intl.PluralRules('en');
|
|
93
|
+
* pr.selectRange(1, 2); // "other" (English: "1-2 items")
|
|
94
|
+
* pr.selectRange(1, 1); // "one" (same value: "1 item")
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* const prFr = new Intl.PluralRules('fr');
|
|
98
|
+
* prFr.selectRange(0, 1); // "one" (French: "0-1 vue")
|
|
99
|
+
* prFr.selectRange(1, 2); // "other" (French: "1-2 vues")
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* // BigInt support (spec-compliant, but Chrome has a bug as of early 2025)
|
|
103
|
+
* pr.selectRange(BigInt(1), BigInt(2)); // "other"
|
|
104
|
+
*
|
|
105
|
+
* @throws {TypeError} If start or end is undefined
|
|
106
|
+
* @throws {RangeError} If start or end is not a finite number (Infinity, NaN)
|
|
107
|
+
*
|
|
108
|
+
* @note Chrome's native implementation (as of early 2025) has a bug where it throws
|
|
109
|
+
* "Cannot convert a BigInt value to a number" when using BigInt arguments. This is
|
|
110
|
+
* a browser bug - the spec requires BigInt support. This polyfill handles BigInt correctly.
|
|
111
|
+
*/
|
|
113
112
|
selectRange(start: number | bigint, end: number | bigint): LDMLPluralRule;
|
|
114
113
|
toString(): string;
|
|
115
114
|
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": "6.3.
|
|
3
|
+
"version": "6.3.13",
|
|
4
4
|
"description": "Polyfill for Intl.PluralRules",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"PluralRules",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"./should-polyfill.js": "./should-polyfill.js"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@formatjs/bigdecimal": "0.2.
|
|
33
|
-
"@formatjs/intl-localematcher": "0.8.
|
|
32
|
+
"@formatjs/bigdecimal": "0.2.7",
|
|
33
|
+
"@formatjs/intl-localematcher": "0.8.13"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/polyfill.iife.js
CHANGED
|
@@ -4128,7 +4128,8 @@ var BigDecimal = class BigDecimal {
|
|
|
4128
4128
|
const leading = absMantissa / bigintPow10(shift);
|
|
4129
4129
|
log10Mantissa = Math.log10(Number(leading)) + shift;
|
|
4130
4130
|
}
|
|
4131
|
-
|
|
4131
|
+
const totalLog10 = log10Mantissa + this._exponent;
|
|
4132
|
+
return new BigDecimal(totalLog10);
|
|
4132
4133
|
}
|
|
4133
4134
|
eq(y) {
|
|
4134
4135
|
const other = BigDecimal._coerce(y);
|