@formatjs/intl-locale 5.1.0 → 5.1.2

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,14 +1,37 @@
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
+ }
10
+ }
11
+ /**
12
+ * Check if Intl.Locale is missing critical methods from the Intl Locale Info proposal.
13
+ * Firefox has an incomplete implementation that lacks getWeekInfo() and other methods.
14
+ * https://github.com/formatjs/formatjs/issues/5112
15
+ * https://bugzilla.mozilla.org/show_bug.cgi?id=1693576
16
+ */
17
+ function hasIncompleteLocaleInfo() {
18
+ try {
19
+ const locale = new Intl.Locale("en-US");
20
+ // Check for getWeekInfo - critical for week calculations (e.g., Luxon's localWeekNumber)
21
+ // This is the most important check as it affects date/time libraries
22
+ if (typeof locale.getWeekInfo !== "function") {
23
+ return true;
24
+ }
25
+ // Also check for other Intl Locale Info methods
26
+ // These are part of the same proposal and often missing together
27
+ 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") {
28
+ return true;
29
+ }
30
+ return false;
31
+ } catch {
32
+ return true;
33
+ }
11
34
  }
12
35
  export function shouldPolyfill() {
13
- return !('Locale' in Intl) || hasIntlGetCanonicalLocalesBug();
36
+ return !("Locale" in Intl) || hasIntlGetCanonicalLocalesBug() || hasIncompleteLocaleInfo();
14
37
  }