@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/polyfill.js CHANGED
@@ -1,10 +1,10 @@
1
- import { DisplayNames } from './index.js';
2
- import { shouldPolyfill } from './should-polyfill.js';
1
+ import { DisplayNames } from "./index.js";
2
+ import { shouldPolyfill } from "./should-polyfill.js";
3
3
  if (shouldPolyfill()) {
4
- Object.defineProperty(Intl, 'DisplayNames', {
5
- value: DisplayNames,
6
- enumerable: false,
7
- writable: true,
8
- configurable: true,
9
- });
4
+ Object.defineProperty(Intl, "DisplayNames", {
5
+ value: DisplayNames,
6
+ enumerable: false,
7
+ writable: true,
8
+ configurable: true
9
+ });
10
10
  }
@@ -1,48 +1,51 @@
1
- import { match } from '@formatjs/intl-localematcher';
2
- import { supportedLocales } from './supported-locales.generated.js';
1
+ import { match } from "@formatjs/intl-localematcher";
2
+ import { supportedLocales } from "./supported-locales.generated.js";
3
3
  /**
4
- * https://bugs.chromium.org/p/chromium/issues/detail?id=1097432
5
- */
4
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1097432
5
+ */
6
6
  function hasMissingICUBug() {
7
- var DisplayNames = Intl.DisplayNames;
8
- if (DisplayNames && !DisplayNames.polyfilled) {
9
- return (new DisplayNames(['en'], {
10
- type: 'region',
11
- }).of('CA') === 'CA');
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
- * https://bugs.chromium.org/p/chromium/issues/detail?id=1176979
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
- var DisplayNames = Intl.DisplayNames;
20
- if (DisplayNames && !DisplayNames.polyfilled) {
21
- return (new DisplayNames(['en'], {
22
- type: 'script',
23
- }).of('arab') !== 'Arabic');
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
- if (!locale) {
29
- return true;
30
- }
31
- var locales = Array.isArray(locale) ? locale : [locale];
32
- return (Intl.DisplayNames.supportedLocalesOf(locales).length ===
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
- return !Intl.DisplayNames || hasMissingICUBug() || hasScriptBug();
41
+ return !Intl.DisplayNames || hasMissingICUBug() || hasScriptBug();
37
42
  }
38
- export function shouldPolyfill(locale) {
39
- if (locale === void 0) { locale = 'en'; }
40
- try {
41
- if (_shouldPolyfillWithoutLocale() || !supportedLocalesOf(locale)) {
42
- return match([locale], supportedLocales, 'en');
43
- }
44
- }
45
- catch (_a) {
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
  }