@formatjs/intl-getcanonicallocales 3.4.0 → 3.4.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/index.js +98 -24
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/polyfill-force.js +169 -30
- package/polyfill-force.js.map +1 -1
- package/polyfill.iife.js +169 -30
- package/polyfill.js +169 -30
- package/polyfill.js.map +1 -1
package/index.js
CHANGED
|
@@ -1,3 +1,84 @@
|
|
|
1
|
+
// packages/ecma262-abstract/IsObject.js
|
|
2
|
+
/** Includes browser host objects such as document.all. */
|
|
3
|
+
function IsObject(value) {
|
|
4
|
+
return value !== null && (typeof value === "object" || typeof value === "function" || typeof value === "undefined" && value !== void 0);
|
|
5
|
+
}
|
|
6
|
+
// packages/ecma262-abstract/intrinsics.js
|
|
7
|
+
const objectFrom = Object;
|
|
8
|
+
const mathMin = Math.min;
|
|
9
|
+
const mathMax = Math.max;
|
|
10
|
+
const mathTrunc = Math.trunc;
|
|
11
|
+
Number.isInteger;
|
|
12
|
+
Number.isFinite;
|
|
13
|
+
Number.isSafeInteger;
|
|
14
|
+
const TypeErrorConstructor$1 = TypeError;
|
|
15
|
+
const arrayApply = Reflect.apply;
|
|
16
|
+
const every = Array.prototype.every;
|
|
17
|
+
Array.prototype.some;
|
|
18
|
+
function arrayEvery(values, predicate) {
|
|
19
|
+
return arrayApply(every, values, [predicate]);
|
|
20
|
+
}
|
|
21
|
+
const includes = Array.prototype.includes;
|
|
22
|
+
const indexOf = Array.prototype.indexOf;
|
|
23
|
+
function arrayIncludes(values, search) {
|
|
24
|
+
return arrayApply(includes, values, [search]);
|
|
25
|
+
}
|
|
26
|
+
function arrayIndexOf(values, search) {
|
|
27
|
+
return arrayApply(indexOf, values, [search]);
|
|
28
|
+
}
|
|
29
|
+
// packages/intl-getcanonicallocales/locale-brand.ts
|
|
30
|
+
const apply = Reflect.apply;
|
|
31
|
+
const defineProperty = Object.defineProperty;
|
|
32
|
+
let readers;
|
|
33
|
+
function addLocaleBrandReader(read) {
|
|
34
|
+
if (typeof read !== "function") throw new TypeErrorConstructor$1("Locale brand reader must be callable");
|
|
35
|
+
for (let node = readers; node; node = node.next) if (node.read === read) return;
|
|
36
|
+
readers = {
|
|
37
|
+
read,
|
|
38
|
+
next: readers
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function getLocaleBrandReaders() {
|
|
42
|
+
const result = [];
|
|
43
|
+
for (let node = readers; node; node = node.next) defineProperty(result, result.length, {
|
|
44
|
+
value: node.read,
|
|
45
|
+
writable: true,
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true
|
|
48
|
+
});
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
function localeString(value) {
|
|
52
|
+
if (!IsObject(value)) return void 0;
|
|
53
|
+
for (let node = readers; node; node = node.next) {
|
|
54
|
+
const tag = node.read(value);
|
|
55
|
+
if (typeof tag === "string") return tag;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const LocaleConstructor = typeof Intl === "undefined" ? void 0 : Intl.Locale;
|
|
59
|
+
const snapshot = LocaleConstructor?.__getLocaleBrandReaders;
|
|
60
|
+
if (typeof snapshot === "function") {
|
|
61
|
+
const known = apply(snapshot, LocaleConstructor, []);
|
|
62
|
+
for (let index = 0; index < known.length; index++) addLocaleBrandReader(known[index]);
|
|
63
|
+
} else {
|
|
64
|
+
const nativeToString = LocaleConstructor?.prototype.toString;
|
|
65
|
+
if (typeof nativeToString === "function") addLocaleBrandReader((value) => {
|
|
66
|
+
try {
|
|
67
|
+
const tag = apply(nativeToString, value, []);
|
|
68
|
+
return typeof tag === "string" ? tag : void 0;
|
|
69
|
+
} catch {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// packages/ecma262-abstract/ToObject.js
|
|
75
|
+
/**
|
|
76
|
+
* https://tc39.es/ecma262/#sec-toobject
|
|
77
|
+
*/
|
|
78
|
+
function ToObject(arg) {
|
|
79
|
+
if (arg === void 0 || arg === null) throw new TypeErrorConstructor$1("undefined/null cannot be converted to object");
|
|
80
|
+
return objectFrom(arg);
|
|
81
|
+
}
|
|
1
82
|
// packages/intl-getcanonicallocales/appendToList.ts
|
|
2
83
|
function appendToList(list, ...values) {
|
|
3
84
|
for (const value of values) Object.defineProperty(list, list.length, {
|
|
@@ -8,12 +89,14 @@ function appendToList(list, ...values) {
|
|
|
8
89
|
});
|
|
9
90
|
}
|
|
10
91
|
// packages/ecma262-abstract/ToString.js
|
|
92
|
+
const StringConstructor = String;
|
|
93
|
+
const TypeErrorConstructor = TypeError;
|
|
11
94
|
/**
|
|
12
95
|
* https://tc39.es/ecma262/#sec-tostring
|
|
13
96
|
*/
|
|
14
97
|
function ToString(o) {
|
|
15
|
-
if (typeof o === "symbol") throw
|
|
16
|
-
return
|
|
98
|
+
if (typeof o === "symbol") throw TypeErrorConstructor("Cannot convert a Symbol value to a string");
|
|
99
|
+
return StringConstructor(o);
|
|
17
100
|
}
|
|
18
101
|
// node_modules/.aspect_rules_js/@formatjs_generated+cldr.core@0.0.0/node_modules/@formatjs_generated/cldr.core/aliases.js
|
|
19
102
|
const subdivisionAlias = {
|
|
@@ -9500,7 +9583,7 @@ function compareExtension(e1, e2) {
|
|
|
9500
9583
|
}
|
|
9501
9584
|
function mergeVariants(v1, v2) {
|
|
9502
9585
|
const result = [...v1];
|
|
9503
|
-
for (const v of v2) if (v1
|
|
9586
|
+
for (const v of v2) if (arrayIndexOf(v1, v) < 0) appendToList(result, v);
|
|
9504
9587
|
return result;
|
|
9505
9588
|
}
|
|
9506
9589
|
function compareLanguageAliasRules(a, b) {
|
|
@@ -9546,7 +9629,7 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
|
|
|
9546
9629
|
unicodeLanguageId.variants = unicodeLanguageId.variants.map((v) => v.toLowerCase());
|
|
9547
9630
|
const original = emitUnicodeLanguageId(unicodeLanguageId);
|
|
9548
9631
|
let finalLangAst = unicodeLanguageId;
|
|
9549
|
-
const matches = ({ type }) => (!type.script || type.script === finalLangAst.script) && (!type.region || type.region === finalLangAst.region) && type.variants
|
|
9632
|
+
const matches = ({ type }) => (!type.script || type.script === finalLangAst.script) && (!type.region || type.region === finalLangAst.region) && arrayEvery(type.variants, (variant) => arrayIncludes(finalLangAst.variants, variant));
|
|
9550
9633
|
const languageRule = languageAliasRules[finalLangAst.lang]?.find(matches);
|
|
9551
9634
|
const undRule = finalLangAst.lang === "und" ? void 0 : languageAliasRules.und?.find(matches);
|
|
9552
9635
|
const matched = !languageRule ? undRule : !undRule ? languageRule : compareLanguageAliasRules(languageRule, undRule) <= 0 ? languageRule : undRule;
|
|
@@ -9556,7 +9639,7 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
|
|
|
9556
9639
|
lang: type.lang !== "und" || finalLangAst.lang === "und" ? replacement.lang : finalLangAst.lang,
|
|
9557
9640
|
script: type.script ? replacement.script : finalLangAst.script || replacement.script,
|
|
9558
9641
|
region: type.region ? replacement.region : finalLangAst.region || replacement.region,
|
|
9559
|
-
variants: mergeVariants(finalLangAst.variants.filter((v) => !type.variants
|
|
9642
|
+
variants: mergeVariants(finalLangAst.variants.filter((v) => !arrayIncludes(type.variants, v)), replacement.variants)
|
|
9560
9643
|
};
|
|
9561
9644
|
return canonicalizeUnicodeLanguageId(finalLangAst);
|
|
9562
9645
|
}
|
|
@@ -9574,7 +9657,7 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
|
|
|
9574
9657
|
})] || likelySubtags[finalLangAst.lang];
|
|
9575
9658
|
if (likelySubtag) {
|
|
9576
9659
|
const { region: likelyRegion } = parseUnicodeLanguageId(likelySubtag.split("-"));
|
|
9577
|
-
if (likelyRegion && regions
|
|
9660
|
+
if (likelyRegion && arrayIndexOf(regions, likelyRegion) > -1) replacedRegion = likelyRegion;
|
|
9578
9661
|
}
|
|
9579
9662
|
}
|
|
9580
9663
|
if (replacedRegion) finalLangAst.region = replacedRegion;
|
|
@@ -9623,15 +9706,6 @@ function CanonicalizeUnicodeLocaleId(locale) {
|
|
|
9623
9706
|
return locale;
|
|
9624
9707
|
}
|
|
9625
9708
|
// packages/intl-getcanonicallocales/index.ts
|
|
9626
|
-
const originalLocaleToString = typeof Intl !== "undefined" ? Intl.Locale?.prototype.toString : void 0;
|
|
9627
|
-
function localeString(value) {
|
|
9628
|
-
if (value === null || typeof value !== "object" && typeof value !== "function") return void 0;
|
|
9629
|
-
const currentLocaleToString = typeof Intl !== "undefined" ? Intl.Locale?.prototype.toString : void 0;
|
|
9630
|
-
for (const method of [originalLocaleToString, currentLocaleToString]) if (method) try {
|
|
9631
|
-
const tag = method.call(value);
|
|
9632
|
-
if (typeof tag === "string") return tag;
|
|
9633
|
-
} catch {}
|
|
9634
|
-
}
|
|
9635
9709
|
/**
|
|
9636
9710
|
* ECMA-402 §9.2.1 CanonicalizeLocaleList, steps 3–7.
|
|
9637
9711
|
* https://tc39.es/ecma402/#sec-canonicalizelocalelist
|
|
@@ -9639,28 +9713,28 @@ function localeString(value) {
|
|
|
9639
9713
|
*/
|
|
9640
9714
|
function CanonicalizeLocaleList(locales) {
|
|
9641
9715
|
if (locales === void 0) return [];
|
|
9642
|
-
if (locales === null) throw new
|
|
9716
|
+
if (locales === null) throw new TypeErrorConstructor$1("Cannot convert null to an object");
|
|
9643
9717
|
const singleLocale = localeString(locales);
|
|
9644
|
-
const list = typeof locales === "string" ? [locales] : singleLocale !== void 0 ? [singleLocale] :
|
|
9718
|
+
const list = typeof locales === "string" ? [locales] : singleLocale !== void 0 ? [singleLocale] : ToObject(locales);
|
|
9645
9719
|
const length = +list.length;
|
|
9646
|
-
const len =
|
|
9720
|
+
const len = length !== length ? 0 : mathMin(mathMax(mathTrunc(length), 0), 9007199254740991);
|
|
9647
9721
|
const seen = [];
|
|
9648
9722
|
for (let k = 0; k < len; k++) {
|
|
9649
9723
|
if (!(k in list)) continue;
|
|
9650
9724
|
const value = list[k];
|
|
9651
|
-
if (value
|
|
9652
|
-
"string",
|
|
9653
|
-
"object",
|
|
9654
|
-
"function"
|
|
9655
|
-
].includes(typeof value)) throw new TypeError("Locale list entries must be strings or objects");
|
|
9725
|
+
if (typeof value !== "string" && !IsObject(value)) throw new TypeErrorConstructor$1("Locale list entries must be strings or objects");
|
|
9656
9726
|
const canonicalizedTag = emitUnicodeLocaleId(CanonicalizeUnicodeLocaleId(parseUnicodeLocaleId(localeString(value) ?? ToString(value))));
|
|
9657
|
-
if (seen
|
|
9727
|
+
if (arrayIndexOf(seen, canonicalizedTag) < 0) appendToList(seen, canonicalizedTag);
|
|
9658
9728
|
}
|
|
9659
9729
|
return seen;
|
|
9660
9730
|
}
|
|
9661
9731
|
function getCanonicalLocales(locales) {
|
|
9662
9732
|
return CanonicalizeLocaleList(locales);
|
|
9663
9733
|
}
|
|
9734
|
+
Object.defineProperties(getCanonicalLocales, {
|
|
9735
|
+
__addLocaleBrandReader: { value: addLocaleBrandReader },
|
|
9736
|
+
__getLocaleBrandReaders: { value: getLocaleBrandReaders }
|
|
9737
|
+
});
|
|
9664
9738
|
export { emitUnicodeLanguageId, emitUnicodeLocaleId, getCanonicalLocales, isStructurallyValidLanguageTag, isUnicodeLanguageSubtag, isUnicodeRegionSubtag, isUnicodeScriptSubtag, isUnicodeVariantSubtag, likelySubtags, parseUnicodeLanguageId, parseUnicodeLocaleId };
|
|
9665
9739
|
|
|
9666
9740
|
//# sourceMappingURL=index.js.map
|