@formatjs/intl-numberformat 8.9.2 → 8.10.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/lib/should-polyfill.js +25 -0
- package/lib/src/core.js +3 -3
- package/package.json +3 -3
- package/polyfill.iife.js +17 -1
- package/should-polyfill.js +25 -0
- package/src/core.js +3 -3
package/lib/should-polyfill.js
CHANGED
|
@@ -34,6 +34,30 @@ function supportsES2020() {
|
|
|
34
34
|
}
|
|
35
35
|
return true;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Check if Intl.NumberFormat is ES2020 compatible.
|
|
39
|
+
* Caveat: we are not checking `toLocaleString`.
|
|
40
|
+
*
|
|
41
|
+
* @public
|
|
42
|
+
* @param unit unit to check
|
|
43
|
+
*/
|
|
44
|
+
function supportsES2023() {
|
|
45
|
+
try {
|
|
46
|
+
var s = new Intl.NumberFormat('en', {
|
|
47
|
+
notation: 'compact',
|
|
48
|
+
minimumSignificantDigits: 3,
|
|
49
|
+
maximumSignificantDigits: 3,
|
|
50
|
+
minimumFractionDigits: 2,
|
|
51
|
+
maximumFractionDigits: 2,
|
|
52
|
+
// @ts-ignore TS types are old
|
|
53
|
+
roundingPriority: 'morePrecision',
|
|
54
|
+
}).format(1e8);
|
|
55
|
+
return s === '100.00M';
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
37
61
|
function supportedLocalesOf(locale) {
|
|
38
62
|
if (!locale) {
|
|
39
63
|
return true;
|
|
@@ -46,6 +70,7 @@ export function shouldPolyfill(locale) {
|
|
|
46
70
|
if (typeof Intl === 'undefined' ||
|
|
47
71
|
!('NumberFormat' in Intl) ||
|
|
48
72
|
!supportsES2020() ||
|
|
73
|
+
!supportsES2023() ||
|
|
49
74
|
onlySupportsEn() ||
|
|
50
75
|
!supportedLocalesOf(locale)) {
|
|
51
76
|
return locale ? match([locale], supportedLocales, 'en') : undefined;
|
package/lib/src/core.js
CHANGED
|
@@ -71,7 +71,7 @@ try {
|
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
catch (e) {
|
|
74
|
-
// In older browser (e.g Chrome 36 like polyfill.io)
|
|
74
|
+
// In older browser (e.g Chrome 36 like polyfill-fastly.io)
|
|
75
75
|
// TypeError: Cannot redefine property: name
|
|
76
76
|
}
|
|
77
77
|
defineProperty(NumberFormat.prototype, 'formatToParts', {
|
|
@@ -140,7 +140,7 @@ var formatDescriptor = {
|
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
142
|
catch (e) {
|
|
143
|
-
// In older browser (e.g Chrome 36 like polyfill.io)
|
|
143
|
+
// In older browser (e.g Chrome 36 like polyfill-fastly.io)
|
|
144
144
|
// TypeError: Cannot redefine property: name
|
|
145
145
|
}
|
|
146
146
|
internalSlots.boundFormat = boundFormat;
|
|
@@ -158,7 +158,7 @@ try {
|
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
160
|
catch (e) {
|
|
161
|
-
// In older browser (e.g Chrome 36 like polyfill.io)
|
|
161
|
+
// In older browser (e.g Chrome 36 like polyfill-fastly.io)
|
|
162
162
|
// TypeError: Cannot redefine property: name
|
|
163
163
|
}
|
|
164
164
|
Object.defineProperty(NumberFormat.prototype, 'format', formatDescriptor);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/intl-numberformat",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.10.1",
|
|
4
4
|
"description": "Ponyfill for ES2020 Intl.NumberFormat",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"polyfill",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"@formatjs/intl-localematcher": "0.5.4"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@formatjs/intl-
|
|
30
|
+
"@formatjs/intl-locale": "3.4.5",
|
|
31
31
|
"@formatjs/intl-pluralrules": "5.2.12",
|
|
32
|
-
"@formatjs/intl-
|
|
32
|
+
"@formatjs/intl-getcanonicallocales": "2.3.0"
|
|
33
33
|
},
|
|
34
34
|
"bugs": {
|
|
35
35
|
"url": "https://github.com/formatjs/formatjs/issues"
|
package/polyfill.iife.js
CHANGED
|
@@ -6634,6 +6634,22 @@
|
|
|
6634
6634
|
}
|
|
6635
6635
|
return true;
|
|
6636
6636
|
}
|
|
6637
|
+
function supportsES2023() {
|
|
6638
|
+
try {
|
|
6639
|
+
var s = new Intl.NumberFormat("en", {
|
|
6640
|
+
notation: "compact",
|
|
6641
|
+
minimumSignificantDigits: 3,
|
|
6642
|
+
maximumSignificantDigits: 3,
|
|
6643
|
+
minimumFractionDigits: 2,
|
|
6644
|
+
maximumFractionDigits: 2,
|
|
6645
|
+
// @ts-ignore TS types are old
|
|
6646
|
+
roundingPriority: "morePrecision"
|
|
6647
|
+
}).format(1e8);
|
|
6648
|
+
return s === "100.00M";
|
|
6649
|
+
} catch (e) {
|
|
6650
|
+
return false;
|
|
6651
|
+
}
|
|
6652
|
+
}
|
|
6637
6653
|
function supportedLocalesOf2(locale) {
|
|
6638
6654
|
if (!locale) {
|
|
6639
6655
|
return true;
|
|
@@ -6645,7 +6661,7 @@
|
|
|
6645
6661
|
if (locale === void 0) {
|
|
6646
6662
|
locale = "en";
|
|
6647
6663
|
}
|
|
6648
|
-
if (typeof Intl === "undefined" || !("NumberFormat" in Intl) || !supportsES2020() || onlySupportsEn() || !supportedLocalesOf2(locale)) {
|
|
6664
|
+
if (typeof Intl === "undefined" || !("NumberFormat" in Intl) || !supportsES2020() || !supportsES2023() || onlySupportsEn() || !supportedLocalesOf2(locale)) {
|
|
6649
6665
|
return locale ? match([locale], supportedLocales, "en") : void 0;
|
|
6650
6666
|
}
|
|
6651
6667
|
}
|
package/should-polyfill.js
CHANGED
|
@@ -37,6 +37,30 @@ function supportsES2020() {
|
|
|
37
37
|
}
|
|
38
38
|
return true;
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Check if Intl.NumberFormat is ES2020 compatible.
|
|
42
|
+
* Caveat: we are not checking `toLocaleString`.
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
* @param unit unit to check
|
|
46
|
+
*/
|
|
47
|
+
function supportsES2023() {
|
|
48
|
+
try {
|
|
49
|
+
var s = new Intl.NumberFormat('en', {
|
|
50
|
+
notation: 'compact',
|
|
51
|
+
minimumSignificantDigits: 3,
|
|
52
|
+
maximumSignificantDigits: 3,
|
|
53
|
+
minimumFractionDigits: 2,
|
|
54
|
+
maximumFractionDigits: 2,
|
|
55
|
+
// @ts-ignore TS types are old
|
|
56
|
+
roundingPriority: 'morePrecision',
|
|
57
|
+
}).format(1e8);
|
|
58
|
+
return s === '100.00M';
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
40
64
|
function supportedLocalesOf(locale) {
|
|
41
65
|
if (!locale) {
|
|
42
66
|
return true;
|
|
@@ -49,6 +73,7 @@ function shouldPolyfill(locale) {
|
|
|
49
73
|
if (typeof Intl === 'undefined' ||
|
|
50
74
|
!('NumberFormat' in Intl) ||
|
|
51
75
|
!supportsES2020() ||
|
|
76
|
+
!supportsES2023() ||
|
|
52
77
|
onlySupportsEn() ||
|
|
53
78
|
!supportedLocalesOf(locale)) {
|
|
54
79
|
return locale ? (0, intl_localematcher_1.match)([locale], supported_locales_generated_1.supportedLocales, 'en') : undefined;
|
package/src/core.js
CHANGED
|
@@ -75,7 +75,7 @@ try {
|
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
catch (e) {
|
|
78
|
-
// In older browser (e.g Chrome 36 like polyfill.io)
|
|
78
|
+
// In older browser (e.g Chrome 36 like polyfill-fastly.io)
|
|
79
79
|
// TypeError: Cannot redefine property: name
|
|
80
80
|
}
|
|
81
81
|
(0, ecma402_abstract_1.defineProperty)(exports.NumberFormat.prototype, 'formatToParts', {
|
|
@@ -144,7 +144,7 @@ var formatDescriptor = {
|
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
catch (e) {
|
|
147
|
-
// In older browser (e.g Chrome 36 like polyfill.io)
|
|
147
|
+
// In older browser (e.g Chrome 36 like polyfill-fastly.io)
|
|
148
148
|
// TypeError: Cannot redefine property: name
|
|
149
149
|
}
|
|
150
150
|
internalSlots.boundFormat = boundFormat;
|
|
@@ -162,7 +162,7 @@ try {
|
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
catch (e) {
|
|
165
|
-
// In older browser (e.g Chrome 36 like polyfill.io)
|
|
165
|
+
// In older browser (e.g Chrome 36 like polyfill-fastly.io)
|
|
166
166
|
// TypeError: Cannot redefine property: name
|
|
167
167
|
}
|
|
168
168
|
Object.defineProperty(exports.NumberFormat.prototype, 'format', formatDescriptor);
|