@formatjs/intl-displaynames 7.1.1 → 7.2.0
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/CanonicalCodeForDisplayNames.d.ts +1 -1
- package/abstract/CanonicalCodeForDisplayNames.js +40 -40
- package/abstract/IsValidDateTimeFieldCode.js +14 -14
- package/index.d.ts +21 -21
- package/index.js +184 -198
- package/package.json +6 -6
- package/polyfill-force.js +6 -6
- package/polyfill.iife.js +2303 -3069
- package/polyfill.js +8 -8
- package/should-polyfill.js +40 -37
- package/supported-locales.generated.js +572 -572
package/polyfill.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { DisplayNames } from
|
|
2
|
-
import { shouldPolyfill } from
|
|
1
|
+
import { DisplayNames } from "./index.js";
|
|
2
|
+
import { shouldPolyfill } from "./should-polyfill.js";
|
|
3
3
|
if (shouldPolyfill()) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
Object.defineProperty(Intl, "DisplayNames", {
|
|
5
|
+
value: DisplayNames,
|
|
6
|
+
enumerable: false,
|
|
7
|
+
writable: true,
|
|
8
|
+
configurable: true
|
|
9
|
+
});
|
|
10
10
|
}
|
package/should-polyfill.js
CHANGED
|
@@ -1,48 +1,51 @@
|
|
|
1
|
-
import { match } from
|
|
2
|
-
import { supportedLocales } from
|
|
1
|
+
import { match } from "@formatjs/intl-localematcher";
|
|
2
|
+
import { supportedLocales } from "./supported-locales.generated.js";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
* https://bugs.chromium.org/p/chromium/issues/detail?id=1097432
|
|
5
|
+
*/
|
|
6
6
|
function hasMissingICUBug() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
return false;
|
|
7
|
+
const DisplayNames = Intl.DisplayNames;
|
|
8
|
+
if (DisplayNames && !DisplayNames.polyfilled) {
|
|
9
|
+
return new DisplayNames(["en"], { type: "region" }).of("CA") === "CA";
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
14
12
|
}
|
|
15
13
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
* https://bugs.chromium.org/p/chromium/issues/detail?id=1176979
|
|
15
|
+
* https://github.com/formatjs/formatjs/issues/5889
|
|
16
|
+
*
|
|
17
|
+
* Tests if the implementation properly canonicalizes script codes per ECMA-402 spec.
|
|
18
|
+
* The spec requires CanonicalCodeForDisplayNames to convert lowercase 'arab' to title-case 'Arab'
|
|
19
|
+
* before lookup. This test uses lowercase input to verify canonicalization happens.
|
|
20
|
+
*
|
|
21
|
+
* - Correct implementations: canonicalize 'arab' → 'Arab', look up → return 'Arabic'
|
|
22
|
+
* - Buggy implementations (old Node.js): don't canonicalize, look up 'arab' literally → return 'arab'
|
|
23
|
+
*
|
|
24
|
+
* See ECMA-402 section 12.5.1: CanonicalCodeForDisplayNames
|
|
25
|
+
*/
|
|
18
26
|
function hasScriptBug() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
27
|
+
const DisplayNames = Intl.DisplayNames;
|
|
28
|
+
if (DisplayNames && !DisplayNames.polyfilled) {
|
|
29
|
+
return new DisplayNames(["en"], { type: "script" }).of("arab") !== "Arabic";
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
26
32
|
}
|
|
27
33
|
function supportedLocalesOf(locale) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
locales.length);
|
|
34
|
+
if (!locale) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
const locales = Array.isArray(locale) ? locale : [locale];
|
|
38
|
+
return Intl.DisplayNames.supportedLocalesOf(locales).length === locales.length;
|
|
34
39
|
}
|
|
35
40
|
export function _shouldPolyfillWithoutLocale() {
|
|
36
|
-
|
|
41
|
+
return !Intl.DisplayNames || hasMissingICUBug() || hasScriptBug();
|
|
37
42
|
}
|
|
38
|
-
export function shouldPolyfill(locale) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
43
|
+
export function shouldPolyfill(locale = "en") {
|
|
44
|
+
try {
|
|
45
|
+
if (_shouldPolyfillWithoutLocale() || !supportedLocalesOf(locale)) {
|
|
46
|
+
return match([locale], supportedLocales, "en");
|
|
47
|
+
}
|
|
48
|
+
} catch {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
48
51
|
}
|