@formatjs/intl-locale 5.1.1 → 5.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 { Locale } from './index.js';
2
- import { shouldPolyfill } from './should-polyfill.js';
1
+ import { Locale } from "./index.js";
2
+ import { shouldPolyfill } from "./should-polyfill.js";
3
3
  if (shouldPolyfill()) {
4
- Object.defineProperty(Intl, 'Locale', {
5
- value: Locale,
6
- writable: true,
7
- enumerable: false,
8
- configurable: true,
9
- });
4
+ Object.defineProperty(Intl, "Locale", {
5
+ value: Locale,
6
+ writable: true,
7
+ enumerable: false,
8
+ configurable: true
9
+ });
10
10
  }
@@ -1,5 +1,5 @@
1
- import type { WeekInfoInternal } from './week-data.generated.js';
2
- export { WeekInfoInternal };
1
+ import type { WeekInfoInternal } from "./week-data.generated.js";
2
+ export { type WeekInfoInternal };
3
3
  export declare function getCalendarPreferenceDataForRegion(region?: string): string[];
4
4
  export declare function getHourCyclesPreferenceDataForLocaleOrRegion(locale: string, region?: string): string[];
5
5
  export declare function getTimeZonePreferenceForRegion(region: string): string[];
@@ -1,46 +1,42 @@
1
- import { __spreadArray } from "tslib";
2
- import { timezones } from './timezones.generated.js';
3
- import { hourCycles } from './hour-cycles.generated.js';
4
- import { calendars } from './calendars.generated.js';
5
- import { weekData } from './week-data.generated.js';
1
+ import { timezones } from "./timezones.generated.js";
2
+ import { hourCycles } from "./hour-cycles.generated.js";
3
+ import { calendars } from "./calendars.generated.js";
4
+ import { weekData } from "./week-data.generated.js";
6
5
  export function getCalendarPreferenceDataForRegion(region) {
7
- var _region = region ? region.toUpperCase() : null;
8
- return (calendars[(_region || '')] || calendars['001']).map(function (c) {
9
- // Resolve aliases
10
- // cldr-json/cldr-code v42.0.0-ALPHA3-2
11
- // https://github.com/unicode-org/cldr-json/blob/42.0.0-ALPHA3-2/cldr-json/cldr-bcp47/bcp47/calendar.json
12
- if (c === 'gregorian') {
13
- return 'gregory';
14
- }
15
- if (c === 'islamic-civil') {
16
- return 'islamicc';
17
- }
18
- // At the time this has been written this calendar was not listed in
19
- // the supplemental calendarPreferenceData file
20
- // https://github.com/unicode-org/cldr-json/blob/42.0.0-ALPHA3-2/cldr-json/cldr-core/supplemental/calendarPreferenceData.json
21
- // if (c === 'ethiopic-amete-alem') {
22
- // return 'ethioaa'
23
- // }
24
- return c;
25
- });
6
+ const _region = region ? region.toUpperCase() : null;
7
+ return (calendars[_region || ""] || calendars["001"]).map((c) => {
8
+ // Resolve aliases
9
+ // cldr-json/cldr-code v42.0.0-ALPHA3-2
10
+ // https://github.com/unicode-org/cldr-json/blob/42.0.0-ALPHA3-2/cldr-json/cldr-bcp47/bcp47/calendar.json
11
+ if (c === "gregorian") {
12
+ return "gregory";
13
+ }
14
+ if (c === "islamic-civil") {
15
+ return "islamicc";
16
+ }
17
+ // At the time this has been written this calendar was not listed in
18
+ // the supplemental calendarPreferenceData file
19
+ // https://github.com/unicode-org/cldr-json/blob/42.0.0-ALPHA3-2/cldr-json/cldr-core/supplemental/calendarPreferenceData.json
20
+ // if (c === 'ethiopic-amete-alem') {
21
+ // return 'ethioaa'
22
+ // }
23
+ return c;
24
+ });
26
25
  }
27
26
  export function getHourCyclesPreferenceDataForLocaleOrRegion(locale, region) {
28
- var _locale = locale.toLowerCase();
29
- var _region = (region ? region.toUpperCase() : '');
30
- var hourCyclesPreference = hourCycles[_locale] ||
31
- hourCycles[_region] ||
32
- hourCycles["".concat(_locale, "-001")] ||
33
- hourCycles['001'];
34
- return __spreadArray([], hourCyclesPreference, true);
27
+ const _locale = locale.toLowerCase();
28
+ const _region = region ? region.toUpperCase() : "";
29
+ const hourCyclesPreference = hourCycles[_locale] || hourCycles[_region] || hourCycles[`${_locale}-001`] || hourCycles["001"];
30
+ return [...hourCyclesPreference];
35
31
  }
36
32
  export function getTimeZonePreferenceForRegion(region) {
37
- var territory = region.toLowerCase();
38
- if (timezones[territory]) {
39
- return __spreadArray([], timezones[territory], true);
40
- }
41
- return [];
33
+ const territory = region.toLowerCase();
34
+ if (timezones[territory]) {
35
+ return [...timezones[territory]];
36
+ }
37
+ return [];
42
38
  }
43
39
  export function getWeekDataForRegion(region) {
44
- var _region = (region ? region.toUpperCase() : '');
45
- return weekData[_region || '001'] || weekData['001'];
40
+ const _region = region ? region.toUpperCase() : "";
41
+ return weekData[_region || "001"] || weekData["001"];
46
42
  }
@@ -1,46 +1,53 @@
1
1
  /**
2
- * https://bugs.chromium.org/p/v8/issues/detail?id=10682
3
- */
2
+ * https://bugs.chromium.org/p/v8/issues/detail?id=10682
3
+ */
4
4
  function hasIntlGetCanonicalLocalesBug() {
5
- try {
6
- return new Intl.Locale('und-x-private').toString() === 'x-private';
7
- }
8
- catch (_a) {
9
- return true;
10
- }
5
+ try {
6
+ return new Intl.Locale("und-x-private").toString() === "x-private";
7
+ } catch {
8
+ return true;
9
+ }
11
10
  }
12
11
  /**
13
- * Check if Intl.Locale is missing critical methods from the Intl Locale Info proposal.
14
- * Firefox has an incomplete implementation that lacks getWeekInfo() and other methods.
15
- * https://github.com/formatjs/formatjs/issues/5112
16
- * https://bugzilla.mozilla.org/show_bug.cgi?id=1693576
17
- */
12
+ * Check if Intl.Locale is missing the variants property.
13
+ * This property was added to ECMA-402 via PR #960.
14
+ * https://github.com/tc39/ecma402/pull/960
15
+ * https://github.com/tc39/ecma402/issues/900
16
+ */
17
+ function hasVariantsProperty() {
18
+ try {
19
+ const locale = new Intl.Locale("en-US-posix");
20
+ // Check if variants property exists
21
+ const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(locale), "variants");
22
+ return descriptor !== undefined && typeof descriptor.get === "function";
23
+ } catch {
24
+ return false;
25
+ }
26
+ }
27
+ /**
28
+ * Check if Intl.Locale is missing critical methods from the Intl Locale Info proposal.
29
+ * Firefox has an incomplete implementation that lacks getWeekInfo() and other methods.
30
+ * https://github.com/formatjs/formatjs/issues/5112
31
+ * https://bugzilla.mozilla.org/show_bug.cgi?id=1693576
32
+ */
18
33
  function hasIncompleteLocaleInfo() {
19
- try {
20
- var locale = new Intl.Locale('en-US');
21
- // Check for getWeekInfo - critical for week calculations (e.g., Luxon's localWeekNumber)
22
- // This is the most important check as it affects date/time libraries
23
- if (typeof locale.getWeekInfo !== 'function') {
24
- return true;
25
- }
26
- // Also check for other Intl Locale Info methods
27
- // These are part of the same proposal and often missing together
28
- if (typeof locale.getCalendars !== 'function' ||
29
- typeof locale.getCollations !== 'function' ||
30
- typeof locale.getHourCycles !== 'function' ||
31
- typeof locale.getNumberingSystems !== 'function' ||
32
- typeof locale.getTimeZones !== 'function' ||
33
- typeof locale.getTextInfo !== 'function') {
34
- return true;
35
- }
36
- return false;
37
- }
38
- catch (_a) {
39
- return true;
40
- }
34
+ try {
35
+ const locale = new Intl.Locale("en-US");
36
+ // Check for getWeekInfo - critical for week calculations (e.g., Luxon's localWeekNumber)
37
+ // This is the most important check as it affects date/time libraries
38
+ if (typeof locale.getWeekInfo !== "function") {
39
+ return true;
40
+ }
41
+ // Also check for other Intl Locale Info methods
42
+ // These are part of the same proposal and often missing together
43
+ if (typeof locale.getCalendars !== "function" || typeof locale.getCollations !== "function" || typeof locale.getHourCycles !== "function" || typeof locale.getNumberingSystems !== "function" || typeof locale.getTimeZones !== "function" || typeof locale.getTextInfo !== "function") {
44
+ return true;
45
+ }
46
+ return false;
47
+ } catch {
48
+ return true;
49
+ }
41
50
  }
42
51
  export function shouldPolyfill() {
43
- return (!('Locale' in Intl) ||
44
- hasIntlGetCanonicalLocalesBug() ||
45
- hasIncompleteLocaleInfo());
52
+ return !("Locale" in Intl) || hasIntlGetCanonicalLocalesBug() || hasIncompleteLocaleInfo() || !hasVariantsProperty();
46
53
  }