@formatjs/intl-getcanonicallocales 3.4.0 → 3.4.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/index.d.ts +3 -1
- package/index.js +438 -279
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/polyfill-force.js +555 -286
- package/polyfill-force.js.map +1 -1
- package/polyfill.iife.js +556 -287
- package/polyfill.js +556 -287
- package/polyfill.js.map +1 -1
- package/should-polyfill.js +1 -1
- package/should-polyfill.js.map +1 -1
package/index.js
CHANGED
|
@@ -1,19 +1,128 @@
|
|
|
1
|
-
// packages/
|
|
2
|
-
function
|
|
3
|
-
|
|
1
|
+
// packages/ecma262-abstract/IsObject.js
|
|
2
|
+
function IsObject(value) {
|
|
3
|
+
return value !== null && (typeof value === "object" || typeof value === "function" || typeof value === "undefined" && value !== void 0);
|
|
4
|
+
}
|
|
5
|
+
// packages/ecma262-abstract/intrinsics.js
|
|
6
|
+
const objectFrom = Object;
|
|
7
|
+
const mathMin = Math.min;
|
|
8
|
+
const mathMax = Math.max;
|
|
9
|
+
const mathTrunc = Math.trunc;
|
|
10
|
+
Number.isInteger;
|
|
11
|
+
Number.isFinite;
|
|
12
|
+
Number.isSafeInteger;
|
|
13
|
+
const TypeErrorConstructor$1 = TypeError;
|
|
14
|
+
const RangeErrorConstructor = RangeError;
|
|
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$1 = Array.prototype.indexOf;
|
|
23
|
+
function arrayIncludes(values, search) {
|
|
24
|
+
return arrayApply(includes, values, [search]);
|
|
25
|
+
}
|
|
26
|
+
function arrayIndexOf(values, search) {
|
|
27
|
+
return arrayApply(indexOf$1, values, [search]);
|
|
28
|
+
}
|
|
29
|
+
const defineProperty$1 = Object.defineProperty;
|
|
30
|
+
function setDataProperty(target, key, value) {
|
|
31
|
+
defineProperty$1(target, key, {
|
|
32
|
+
__proto__: null,
|
|
4
33
|
value,
|
|
5
34
|
writable: true,
|
|
6
35
|
enumerable: true,
|
|
7
36
|
configurable: true
|
|
8
37
|
});
|
|
9
38
|
}
|
|
39
|
+
// packages/intl-getcanonicallocales/locale-brand.ts
|
|
40
|
+
const apply = Reflect.apply;
|
|
41
|
+
const defineProperty = Object.defineProperty;
|
|
42
|
+
const localeBrandRegistry = {
|
|
43
|
+
readers: void 0,
|
|
44
|
+
parent: void 0
|
|
45
|
+
};
|
|
46
|
+
function rootRegistry(registry) {
|
|
47
|
+
while (registry.parent) registry = registry.parent;
|
|
48
|
+
return registry;
|
|
49
|
+
}
|
|
50
|
+
function addLocaleBrandReader(read) {
|
|
51
|
+
if (typeof read !== "function") throw new TypeErrorConstructor$1("Locale brand reader must be callable");
|
|
52
|
+
const registry = rootRegistry(localeBrandRegistry);
|
|
53
|
+
for (let node = registry.readers; node; node = node.next) if (node.read === read) return;
|
|
54
|
+
registry.readers = {
|
|
55
|
+
read,
|
|
56
|
+
next: registry.readers
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function connectLocaleBrandReaders(other) {
|
|
60
|
+
const ownRoot = rootRegistry(localeBrandRegistry);
|
|
61
|
+
const otherRoot = rootRegistry(other);
|
|
62
|
+
if (ownRoot === otherRoot) return;
|
|
63
|
+
const readers = ownRoot.readers;
|
|
64
|
+
ownRoot.parent = otherRoot;
|
|
65
|
+
ownRoot.readers = void 0;
|
|
66
|
+
for (let node = readers; node; node = node.next) addLocaleBrandReader(node.read);
|
|
67
|
+
}
|
|
68
|
+
function getLocaleBrandReaders() {
|
|
69
|
+
const result = [];
|
|
70
|
+
for (let node = rootRegistry(localeBrandRegistry).readers; node; node = node.next) defineProperty(result, result.length, {
|
|
71
|
+
value: node.read,
|
|
72
|
+
writable: true,
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true
|
|
75
|
+
});
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
function localeString(value) {
|
|
79
|
+
if (!IsObject(value)) return void 0;
|
|
80
|
+
for (let node = rootRegistry(localeBrandRegistry).readers; node; node = node.next) {
|
|
81
|
+
const tag = node.read(value);
|
|
82
|
+
if (typeof tag === "string") return tag;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const intl = typeof Intl === "undefined" ? void 0 : Intl;
|
|
86
|
+
const currentCanonicalizer = intl?.getCanonicalLocales;
|
|
87
|
+
const currentLocale = intl?.Locale;
|
|
88
|
+
if (currentCanonicalizer?.__localeBrandRegistry) connectLocaleBrandReaders(currentCanonicalizer.__localeBrandRegistry);
|
|
89
|
+
const snapshot = currentLocale?.__getLocaleBrandReaders;
|
|
90
|
+
if (currentLocale?.__localeBrandRegistry) connectLocaleBrandReaders(currentLocale.__localeBrandRegistry);
|
|
91
|
+
else if (typeof snapshot === "function") {
|
|
92
|
+
const known = apply(snapshot, currentLocale, []);
|
|
93
|
+
for (let index = 0; index < known.length; index++) addLocaleBrandReader(known[index]);
|
|
94
|
+
} else {
|
|
95
|
+
const nativeToString = currentLocale?.prototype.toString;
|
|
96
|
+
if (typeof nativeToString === "function") addLocaleBrandReader((value) => {
|
|
97
|
+
try {
|
|
98
|
+
const tag = apply(nativeToString, value, []);
|
|
99
|
+
return typeof tag === "string" ? tag : void 0;
|
|
100
|
+
} catch {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
// packages/ecma262-abstract/ToObject.js
|
|
106
|
+
/**
|
|
107
|
+
* https://tc39.es/ecma262/#sec-toobject
|
|
108
|
+
*/
|
|
109
|
+
function ToObject(arg) {
|
|
110
|
+
if (arg === void 0 || arg === null) throw new TypeErrorConstructor$1("undefined/null cannot be converted to object");
|
|
111
|
+
return objectFrom(arg);
|
|
112
|
+
}
|
|
113
|
+
// packages/intl-getcanonicallocales/appendToList.ts
|
|
114
|
+
function appendToList(list, ...values) {
|
|
115
|
+
for (let index = 0; index < values.length; index++) setDataProperty(list, list.length, values[index]);
|
|
116
|
+
}
|
|
10
117
|
// packages/ecma262-abstract/ToString.js
|
|
118
|
+
const StringConstructor = String;
|
|
119
|
+
const TypeErrorConstructor = TypeError;
|
|
11
120
|
/**
|
|
12
121
|
* https://tc39.es/ecma262/#sec-tostring
|
|
13
122
|
*/
|
|
14
123
|
function ToString(o) {
|
|
15
|
-
if (typeof o === "symbol") throw
|
|
16
|
-
return
|
|
124
|
+
if (typeof o === "symbol") throw TypeErrorConstructor("Cannot convert a Symbol value to a string");
|
|
125
|
+
return StringConstructor(o);
|
|
17
126
|
}
|
|
18
127
|
// node_modules/.aspect_rules_js/@formatjs_generated+cldr.core@0.0.0/node_modules/@formatjs_generated/cldr.core/aliases.js
|
|
19
128
|
const subdivisionAlias = {
|
|
@@ -1391,31 +1500,243 @@ const variantAlias = {
|
|
|
1391
1500
|
"heploc": "alalc97",
|
|
1392
1501
|
"polytoni": "polyton"
|
|
1393
1502
|
};
|
|
1503
|
+
// packages/intl-getcanonicallocales/parser.ts
|
|
1504
|
+
const lowerCase = Function.prototype.call.bind(String.prototype.toLowerCase);
|
|
1505
|
+
const create$1 = Object.create;
|
|
1506
|
+
const charCodeAt = Function.prototype.call.bind(String.prototype.charCodeAt);
|
|
1507
|
+
const indexOf = Function.prototype.call.bind(String.prototype.indexOf);
|
|
1508
|
+
const slice$1 = Function.prototype.call.bind(String.prototype.slice);
|
|
1509
|
+
const shift = Function.prototype.call.bind(Array.prototype.shift);
|
|
1510
|
+
const join = Function.prototype.call.bind(Array.prototype.join);
|
|
1511
|
+
function splitSubtags(value, separator = "-") {
|
|
1512
|
+
const parts = [];
|
|
1513
|
+
let start = 0;
|
|
1514
|
+
let end = indexOf(value, separator, start);
|
|
1515
|
+
while (end !== -1) {
|
|
1516
|
+
appendToList(parts, slice$1(value, start, end));
|
|
1517
|
+
start = end + separator.length;
|
|
1518
|
+
end = indexOf(value, separator, start);
|
|
1519
|
+
}
|
|
1520
|
+
appendToList(parts, slice$1(value, start));
|
|
1521
|
+
return parts;
|
|
1522
|
+
}
|
|
1523
|
+
function isLetter(code) {
|
|
1524
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
1525
|
+
}
|
|
1526
|
+
function isDigit(code) {
|
|
1527
|
+
return code >= 48 && code <= 57;
|
|
1528
|
+
}
|
|
1529
|
+
function isSubtag(value, min, max, digits = false) {
|
|
1530
|
+
if (value.length < min || value.length > max) return false;
|
|
1531
|
+
for (let i = 0; i < value.length; i++) {
|
|
1532
|
+
const code = charCodeAt(value, i);
|
|
1533
|
+
if (!isLetter(code) && !(digits && isDigit(code))) return false;
|
|
1534
|
+
}
|
|
1535
|
+
return true;
|
|
1536
|
+
}
|
|
1537
|
+
function isUnicodeKey(value) {
|
|
1538
|
+
return value.length === 2 && isSubtag(value, 2, 2, true) && isLetter(charCodeAt(value, 1));
|
|
1539
|
+
}
|
|
1540
|
+
function isTransformedKey(value) {
|
|
1541
|
+
return value.length === 2 && isLetter(charCodeAt(value, 0)) && isDigit(charCodeAt(value, 1));
|
|
1542
|
+
}
|
|
1543
|
+
function isUnicodeLanguageSubtag(lang) {
|
|
1544
|
+
return lang.length !== 4 && isSubtag(lang, 2, 8);
|
|
1545
|
+
}
|
|
1546
|
+
function isStructurallyValidLanguageTag(tag) {
|
|
1547
|
+
try {
|
|
1548
|
+
parseUnicodeLocaleId(tag);
|
|
1549
|
+
} catch {
|
|
1550
|
+
return false;
|
|
1551
|
+
}
|
|
1552
|
+
return true;
|
|
1553
|
+
}
|
|
1554
|
+
function isUnicodeRegionSubtag(region) {
|
|
1555
|
+
return isSubtag(region, 2, 2) || region.length === 3 && isDigit(charCodeAt(region, 0)) && isDigit(charCodeAt(region, 1)) && isDigit(charCodeAt(region, 2));
|
|
1556
|
+
}
|
|
1557
|
+
function isUnicodeScriptSubtag(script) {
|
|
1558
|
+
return isSubtag(script, 4, 4);
|
|
1559
|
+
}
|
|
1560
|
+
function isUnicodeVariantSubtag(variant) {
|
|
1561
|
+
return isSubtag(variant, 5, 8, true) || isSubtag(variant, 4, 4, true) && isDigit(charCodeAt(variant, 0));
|
|
1562
|
+
}
|
|
1563
|
+
function parseUnicodeLanguageId(chunks) {
|
|
1564
|
+
if (typeof chunks === "string") chunks = splitSubtags(chunks);
|
|
1565
|
+
const lang = shift(chunks);
|
|
1566
|
+
if (!lang) throw new RangeErrorConstructor("Missing unicode_language_subtag");
|
|
1567
|
+
if (lang === "root") return {
|
|
1568
|
+
lang: "root",
|
|
1569
|
+
variants: []
|
|
1570
|
+
};
|
|
1571
|
+
if (!isUnicodeLanguageSubtag(lang)) throw new RangeErrorConstructor("Malformed unicode_language_subtag");
|
|
1572
|
+
let script;
|
|
1573
|
+
if (chunks.length && isUnicodeScriptSubtag(chunks[0])) script = shift(chunks);
|
|
1574
|
+
let region;
|
|
1575
|
+
if (chunks.length && isUnicodeRegionSubtag(chunks[0])) region = shift(chunks);
|
|
1576
|
+
const variants = [];
|
|
1577
|
+
const seenVariants = create$1(null);
|
|
1578
|
+
while (chunks.length && isUnicodeVariantSubtag(chunks[0])) {
|
|
1579
|
+
const variant = shift(chunks);
|
|
1580
|
+
const key = lowerCase(variant);
|
|
1581
|
+
if (seenVariants[key]) throw new RangeErrorConstructor(`Duplicate variant "${variant}"`);
|
|
1582
|
+
seenVariants[key] = true;
|
|
1583
|
+
appendToList(variants, variant);
|
|
1584
|
+
}
|
|
1585
|
+
return {
|
|
1586
|
+
lang,
|
|
1587
|
+
script,
|
|
1588
|
+
region,
|
|
1589
|
+
variants
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
function parseUnicodeExtension(chunks) {
|
|
1593
|
+
const keywords = [];
|
|
1594
|
+
let keyword;
|
|
1595
|
+
while (chunks.length && (keyword = parseKeyword(chunks))) appendToList(keywords, keyword);
|
|
1596
|
+
if (keywords.length) return {
|
|
1597
|
+
type: "u",
|
|
1598
|
+
keywords,
|
|
1599
|
+
attributes: []
|
|
1600
|
+
};
|
|
1601
|
+
const attributes = [];
|
|
1602
|
+
while (chunks.length && isSubtag(chunks[0], 3, 8, true)) appendToList(attributes, shift(chunks));
|
|
1603
|
+
while (chunks.length && (keyword = parseKeyword(chunks))) appendToList(keywords, keyword);
|
|
1604
|
+
if (keywords.length || attributes.length) return {
|
|
1605
|
+
type: "u",
|
|
1606
|
+
attributes,
|
|
1607
|
+
keywords
|
|
1608
|
+
};
|
|
1609
|
+
throw new RangeErrorConstructor("Malformed unicode_extension");
|
|
1610
|
+
}
|
|
1611
|
+
function parseKeyword(chunks) {
|
|
1612
|
+
let key;
|
|
1613
|
+
if (!isUnicodeKey(chunks[0])) return;
|
|
1614
|
+
key = shift(chunks);
|
|
1615
|
+
const type = [];
|
|
1616
|
+
while (chunks.length && isSubtag(chunks[0], 3, 8, true)) appendToList(type, shift(chunks));
|
|
1617
|
+
let value = "";
|
|
1618
|
+
if (type.length) value = join(type, "-");
|
|
1619
|
+
return [key, value];
|
|
1620
|
+
}
|
|
1621
|
+
function parseTransformedExtension(chunks) {
|
|
1622
|
+
let lang;
|
|
1623
|
+
if (chunks.length && isUnicodeLanguageSubtag(chunks[0])) lang = parseUnicodeLanguageId(chunks);
|
|
1624
|
+
const fields = [];
|
|
1625
|
+
while (chunks.length && isTransformedKey(chunks[0])) {
|
|
1626
|
+
const key = shift(chunks);
|
|
1627
|
+
const value = [];
|
|
1628
|
+
while (chunks.length && isSubtag(chunks[0], 3, 8, true)) appendToList(value, shift(chunks));
|
|
1629
|
+
if (!value.length) throw new RangeErrorConstructor(`Missing tvalue for tkey "${key}"`);
|
|
1630
|
+
appendToList(fields, [key, join(value, "-")]);
|
|
1631
|
+
}
|
|
1632
|
+
if (lang || fields.length) return {
|
|
1633
|
+
type: "t",
|
|
1634
|
+
fields,
|
|
1635
|
+
lang
|
|
1636
|
+
};
|
|
1637
|
+
throw new RangeErrorConstructor("Malformed transformed_extension");
|
|
1638
|
+
}
|
|
1639
|
+
function parsePuExtension(chunks) {
|
|
1640
|
+
const exts = [];
|
|
1641
|
+
while (chunks.length && isSubtag(chunks[0], 1, 8, true)) appendToList(exts, shift(chunks));
|
|
1642
|
+
if (exts.length) return {
|
|
1643
|
+
type: "x",
|
|
1644
|
+
value: join(exts, "-")
|
|
1645
|
+
};
|
|
1646
|
+
throw new RangeErrorConstructor("Malformed private_use_extension");
|
|
1647
|
+
}
|
|
1648
|
+
function parseOtherExtensionValue(chunks) {
|
|
1649
|
+
const exts = [];
|
|
1650
|
+
while (chunks.length && isSubtag(chunks[0], 2, 8, true)) appendToList(exts, shift(chunks));
|
|
1651
|
+
if (exts.length) return join(exts, "-");
|
|
1652
|
+
throw new RangeErrorConstructor("Missing extension value");
|
|
1653
|
+
}
|
|
1654
|
+
function parseExtensions(chunks) {
|
|
1655
|
+
if (!chunks.length) return { extensions: [] };
|
|
1656
|
+
const extensions = [];
|
|
1657
|
+
let unicodeExtension;
|
|
1658
|
+
let transformedExtension;
|
|
1659
|
+
let puExtension;
|
|
1660
|
+
const otherExtensionMap = create$1(null);
|
|
1661
|
+
do {
|
|
1662
|
+
const singleton = shift(chunks);
|
|
1663
|
+
if (!isSubtag(singleton, 1, 1, true)) throw new RangeErrorConstructor("Malformed extension type");
|
|
1664
|
+
const type = lowerCase(singleton);
|
|
1665
|
+
switch (type) {
|
|
1666
|
+
case "u":
|
|
1667
|
+
if (unicodeExtension) throw new RangeErrorConstructor("There can only be 1 -u- extension");
|
|
1668
|
+
unicodeExtension = parseUnicodeExtension(chunks);
|
|
1669
|
+
appendToList(extensions, unicodeExtension);
|
|
1670
|
+
break;
|
|
1671
|
+
case "t":
|
|
1672
|
+
if (transformedExtension) throw new RangeErrorConstructor("There can only be 1 -t- extension");
|
|
1673
|
+
transformedExtension = parseTransformedExtension(chunks);
|
|
1674
|
+
appendToList(extensions, transformedExtension);
|
|
1675
|
+
break;
|
|
1676
|
+
case "x":
|
|
1677
|
+
if (puExtension) throw new RangeErrorConstructor("There can only be 1 -x- extension");
|
|
1678
|
+
puExtension = parsePuExtension(chunks);
|
|
1679
|
+
appendToList(extensions, puExtension);
|
|
1680
|
+
break;
|
|
1681
|
+
default:
|
|
1682
|
+
if (type in otherExtensionMap) throw new RangeErrorConstructor(`There can only be 1 -${type}- extension`);
|
|
1683
|
+
const extension = {
|
|
1684
|
+
type,
|
|
1685
|
+
value: parseOtherExtensionValue(chunks)
|
|
1686
|
+
};
|
|
1687
|
+
otherExtensionMap[extension.type] = extension;
|
|
1688
|
+
appendToList(extensions, extension);
|
|
1689
|
+
}
|
|
1690
|
+
} while (chunks.length);
|
|
1691
|
+
return { extensions };
|
|
1692
|
+
}
|
|
1693
|
+
function parseUnicodeLocaleId(locale) {
|
|
1694
|
+
const chunks = splitSubtags(locale);
|
|
1695
|
+
const lang = parseUnicodeLanguageId(chunks);
|
|
1696
|
+
if (lang.lang === "root") throw new RangeErrorConstructor("Invalid language tag: root");
|
|
1697
|
+
return {
|
|
1698
|
+
lang,
|
|
1699
|
+
...parseExtensions(chunks)
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1394
1702
|
// packages/intl-getcanonicallocales/emitter.ts
|
|
1703
|
+
function appendSubtag(tag, subtag) {
|
|
1704
|
+
if (!subtag) return tag;
|
|
1705
|
+
return tag ? tag + "-" + subtag : subtag;
|
|
1706
|
+
}
|
|
1395
1707
|
function emitUnicodeLanguageId(lang) {
|
|
1396
1708
|
if (!lang) return "";
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1709
|
+
let tag = appendSubtag(appendSubtag(lang.lang, lang.script), lang.region);
|
|
1710
|
+
const variants = lang.variants;
|
|
1711
|
+
for (let i = 0; variants && i < variants.length; i++) tag = appendSubtag(tag, variants[i]);
|
|
1712
|
+
return tag;
|
|
1713
|
+
}
|
|
1714
|
+
function appendFields(tag, fields) {
|
|
1715
|
+
for (let i = 0; i < fields.length; i++) {
|
|
1716
|
+
const field = fields[i];
|
|
1717
|
+
tag = appendSubtag(tag, field[0]);
|
|
1718
|
+
if (field.length > 1) tag = appendSubtag(tag, field[1]);
|
|
1719
|
+
}
|
|
1720
|
+
return tag;
|
|
1403
1721
|
}
|
|
1404
1722
|
function emitUnicodeLocaleId({ lang, extensions }) {
|
|
1405
|
-
|
|
1406
|
-
for (
|
|
1407
|
-
|
|
1723
|
+
let tag = emitUnicodeLanguageId(lang);
|
|
1724
|
+
for (let i = 0; i < extensions.length; i++) {
|
|
1725
|
+
const ext = extensions[i];
|
|
1726
|
+
tag = appendSubtag(tag, ext.type);
|
|
1408
1727
|
switch (ext.type) {
|
|
1409
1728
|
case "u":
|
|
1410
|
-
|
|
1729
|
+
for (let j = 0; j < ext.attributes.length; j++) tag = appendSubtag(tag, ext.attributes[j]);
|
|
1730
|
+
tag = appendFields(tag, ext.keywords);
|
|
1411
1731
|
break;
|
|
1412
1732
|
case "t":
|
|
1413
|
-
|
|
1733
|
+
tag = appendSubtag(tag, lowerCase(emitUnicodeLanguageId(ext.lang)));
|
|
1734
|
+
tag = appendFields(tag, ext.fields);
|
|
1414
1735
|
break;
|
|
1415
|
-
default:
|
|
1736
|
+
default: tag = appendSubtag(tag, ext.value);
|
|
1416
1737
|
}
|
|
1417
1738
|
}
|
|
1418
|
-
return
|
|
1739
|
+
return tag;
|
|
1419
1740
|
}
|
|
1420
1741
|
// node_modules/.aspect_rules_js/@formatjs_generated+cldr.core@0.0.0/node_modules/@formatjs_generated/cldr.core/likelySubtags.js
|
|
1421
1742
|
const likelySubtags = {
|
|
@@ -9288,207 +9609,37 @@ const likelySubtags = {
|
|
|
9288
9609
|
"zza": "zza-Latn-TR",
|
|
9289
9610
|
"zzj": "zzj-Hani-CN"
|
|
9290
9611
|
};
|
|
9291
|
-
// packages/intl-getcanonicallocales/parser.ts
|
|
9292
|
-
function isLetter(code) {
|
|
9293
|
-
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
9294
|
-
}
|
|
9295
|
-
function isDigit(code) {
|
|
9296
|
-
return code >= 48 && code <= 57;
|
|
9297
|
-
}
|
|
9298
|
-
function isSubtag(value, min, max, digits = false) {
|
|
9299
|
-
if (value.length < min || value.length > max) return false;
|
|
9300
|
-
for (let i = 0; i < value.length; i++) {
|
|
9301
|
-
const code = value.charCodeAt(i);
|
|
9302
|
-
if (!isLetter(code) && !(digits && isDigit(code))) return false;
|
|
9303
|
-
}
|
|
9304
|
-
return true;
|
|
9305
|
-
}
|
|
9306
|
-
function isUnicodeKey(value) {
|
|
9307
|
-
return value.length === 2 && isSubtag(value, 2, 2, true) && isLetter(value.charCodeAt(1));
|
|
9308
|
-
}
|
|
9309
|
-
function isTransformedKey(value) {
|
|
9310
|
-
return value.length === 2 && isLetter(value.charCodeAt(0)) && isDigit(value.charCodeAt(1));
|
|
9311
|
-
}
|
|
9312
|
-
function isOtherExtensionType(value) {
|
|
9313
|
-
const type = value.toLowerCase();
|
|
9314
|
-
return isSubtag(type, 1, 1, true) && type !== "t" && type !== "u" && type !== "x";
|
|
9315
|
-
}
|
|
9316
|
-
function isUnicodeLanguageSubtag(lang) {
|
|
9317
|
-
return lang.length !== 4 && isSubtag(lang, 2, 8);
|
|
9318
|
-
}
|
|
9319
|
-
function isStructurallyValidLanguageTag(tag) {
|
|
9320
|
-
try {
|
|
9321
|
-
parseUnicodeLanguageId(tag.split("-"));
|
|
9322
|
-
} catch {
|
|
9323
|
-
return false;
|
|
9324
|
-
}
|
|
9325
|
-
return true;
|
|
9326
|
-
}
|
|
9327
|
-
function isUnicodeRegionSubtag(region) {
|
|
9328
|
-
return isSubtag(region, 2, 2) || region.length === 3 && isDigit(region.charCodeAt(0)) && isDigit(region.charCodeAt(1)) && isDigit(region.charCodeAt(2));
|
|
9329
|
-
}
|
|
9330
|
-
function isUnicodeScriptSubtag(script) {
|
|
9331
|
-
return isSubtag(script, 4, 4);
|
|
9332
|
-
}
|
|
9333
|
-
function isUnicodeVariantSubtag(variant) {
|
|
9334
|
-
return isSubtag(variant, 5, 8, true) || isSubtag(variant, 4, 4, true) && isDigit(variant.charCodeAt(0));
|
|
9335
|
-
}
|
|
9336
|
-
function parseUnicodeLanguageId(chunks) {
|
|
9337
|
-
if (typeof chunks === "string") chunks = chunks.split("-");
|
|
9338
|
-
const lang = chunks.shift();
|
|
9339
|
-
if (!lang) throw new RangeError("Missing unicode_language_subtag");
|
|
9340
|
-
if (lang === "root") return {
|
|
9341
|
-
lang: "root",
|
|
9342
|
-
variants: []
|
|
9343
|
-
};
|
|
9344
|
-
if (!isUnicodeLanguageSubtag(lang)) throw new RangeError("Malformed unicode_language_subtag");
|
|
9345
|
-
let script;
|
|
9346
|
-
if (chunks.length && isUnicodeScriptSubtag(chunks[0])) script = chunks.shift();
|
|
9347
|
-
let region;
|
|
9348
|
-
if (chunks.length && isUnicodeRegionSubtag(chunks[0])) region = chunks.shift();
|
|
9349
|
-
const variants = {};
|
|
9350
|
-
while (chunks.length && isUnicodeVariantSubtag(chunks[0])) {
|
|
9351
|
-
const variant = chunks.shift();
|
|
9352
|
-
if (variant in variants) throw new RangeError(`Duplicate variant "${variant}"`);
|
|
9353
|
-
variants[variant] = 1;
|
|
9354
|
-
}
|
|
9355
|
-
return {
|
|
9356
|
-
lang,
|
|
9357
|
-
script,
|
|
9358
|
-
region,
|
|
9359
|
-
variants: Object.keys(variants)
|
|
9360
|
-
};
|
|
9361
|
-
}
|
|
9362
|
-
function parseUnicodeExtension(chunks) {
|
|
9363
|
-
const keywords = [];
|
|
9364
|
-
let keyword;
|
|
9365
|
-
while (chunks.length && (keyword = parseKeyword(chunks))) appendToList(keywords, keyword);
|
|
9366
|
-
if (keywords.length) return {
|
|
9367
|
-
type: "u",
|
|
9368
|
-
keywords,
|
|
9369
|
-
attributes: []
|
|
9370
|
-
};
|
|
9371
|
-
const attributes = [];
|
|
9372
|
-
while (chunks.length && isSubtag(chunks[0], 3, 8, true)) appendToList(attributes, chunks.shift());
|
|
9373
|
-
while (chunks.length && (keyword = parseKeyword(chunks))) appendToList(keywords, keyword);
|
|
9374
|
-
if (keywords.length || attributes.length) return {
|
|
9375
|
-
type: "u",
|
|
9376
|
-
attributes,
|
|
9377
|
-
keywords
|
|
9378
|
-
};
|
|
9379
|
-
throw new RangeError("Malformed unicode_extension");
|
|
9380
|
-
}
|
|
9381
|
-
function parseKeyword(chunks) {
|
|
9382
|
-
let key;
|
|
9383
|
-
if (!isUnicodeKey(chunks[0])) return;
|
|
9384
|
-
key = chunks.shift();
|
|
9385
|
-
const type = [];
|
|
9386
|
-
while (chunks.length && isSubtag(chunks[0], 3, 8, true)) appendToList(type, chunks.shift());
|
|
9387
|
-
let value = "";
|
|
9388
|
-
if (type.length) value = type.join("-");
|
|
9389
|
-
return [key, value];
|
|
9390
|
-
}
|
|
9391
|
-
function parseTransformedExtension(chunks) {
|
|
9392
|
-
let lang;
|
|
9393
|
-
if (chunks.length && isUnicodeLanguageSubtag(chunks[0])) lang = parseUnicodeLanguageId(chunks);
|
|
9394
|
-
const fields = [];
|
|
9395
|
-
while (chunks.length && isTransformedKey(chunks[0])) {
|
|
9396
|
-
const key = chunks.shift();
|
|
9397
|
-
const value = [];
|
|
9398
|
-
while (chunks.length && isSubtag(chunks[0], 3, 8, true)) appendToList(value, chunks.shift());
|
|
9399
|
-
if (!value.length) throw new RangeError(`Missing tvalue for tkey "${key}"`);
|
|
9400
|
-
appendToList(fields, [key, value.join("-")]);
|
|
9401
|
-
}
|
|
9402
|
-
if (lang || fields.length) return {
|
|
9403
|
-
type: "t",
|
|
9404
|
-
fields,
|
|
9405
|
-
lang
|
|
9406
|
-
};
|
|
9407
|
-
throw new RangeError("Malformed transformed_extension");
|
|
9408
|
-
}
|
|
9409
|
-
function parsePuExtension(chunks) {
|
|
9410
|
-
const exts = [];
|
|
9411
|
-
while (chunks.length && isSubtag(chunks[0], 1, 8, true)) appendToList(exts, chunks.shift());
|
|
9412
|
-
if (exts.length) return {
|
|
9413
|
-
type: "x",
|
|
9414
|
-
value: exts.join("-")
|
|
9415
|
-
};
|
|
9416
|
-
throw new RangeError("Malformed private_use_extension");
|
|
9417
|
-
}
|
|
9418
|
-
function parseOtherExtensionValue(chunks) {
|
|
9419
|
-
const exts = [];
|
|
9420
|
-
while (chunks.length && isSubtag(chunks[0], 2, 8, true)) appendToList(exts, chunks.shift());
|
|
9421
|
-
if (exts.length) return exts.join("-");
|
|
9422
|
-
throw new RangeError("Missing extension value");
|
|
9423
|
-
}
|
|
9424
|
-
function parseExtensions(chunks) {
|
|
9425
|
-
if (!chunks.length) return { extensions: [] };
|
|
9426
|
-
const extensions = [];
|
|
9427
|
-
let unicodeExtension;
|
|
9428
|
-
let transformedExtension;
|
|
9429
|
-
let puExtension;
|
|
9430
|
-
const otherExtensionMap = {};
|
|
9431
|
-
do {
|
|
9432
|
-
const type = chunks.shift().toLowerCase();
|
|
9433
|
-
switch (type) {
|
|
9434
|
-
case "u":
|
|
9435
|
-
case "U":
|
|
9436
|
-
if (unicodeExtension) throw new RangeError("There can only be 1 -u- extension");
|
|
9437
|
-
unicodeExtension = parseUnicodeExtension(chunks);
|
|
9438
|
-
appendToList(extensions, unicodeExtension);
|
|
9439
|
-
break;
|
|
9440
|
-
case "t":
|
|
9441
|
-
case "T":
|
|
9442
|
-
if (transformedExtension) throw new RangeError("There can only be 1 -t- extension");
|
|
9443
|
-
transformedExtension = parseTransformedExtension(chunks);
|
|
9444
|
-
appendToList(extensions, transformedExtension);
|
|
9445
|
-
break;
|
|
9446
|
-
case "x":
|
|
9447
|
-
case "X":
|
|
9448
|
-
if (puExtension) throw new RangeError("There can only be 1 -x- extension");
|
|
9449
|
-
puExtension = parsePuExtension(chunks);
|
|
9450
|
-
appendToList(extensions, puExtension);
|
|
9451
|
-
break;
|
|
9452
|
-
default:
|
|
9453
|
-
if (!isOtherExtensionType(type)) throw new RangeError("Malformed extension type");
|
|
9454
|
-
if (type in otherExtensionMap) throw new RangeError(`There can only be 1 -${type}- extension`);
|
|
9455
|
-
const extension = {
|
|
9456
|
-
type,
|
|
9457
|
-
value: parseOtherExtensionValue(chunks)
|
|
9458
|
-
};
|
|
9459
|
-
otherExtensionMap[extension.type] = extension;
|
|
9460
|
-
appendToList(extensions, extension);
|
|
9461
|
-
}
|
|
9462
|
-
} while (chunks.length);
|
|
9463
|
-
return { extensions };
|
|
9464
|
-
}
|
|
9465
|
-
function parseUnicodeLocaleId(locale) {
|
|
9466
|
-
const chunks = locale.split("-");
|
|
9467
|
-
return {
|
|
9468
|
-
lang: parseUnicodeLanguageId(chunks),
|
|
9469
|
-
...parseExtensions(chunks)
|
|
9470
|
-
};
|
|
9471
|
-
}
|
|
9472
9612
|
// packages/intl-getcanonicallocales/canonicalizer.ts
|
|
9613
|
+
const create = Object.create;
|
|
9614
|
+
const keys = Object.keys;
|
|
9615
|
+
const hasOwn = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
|
|
9616
|
+
const upperCase = Function.prototype.call.bind(String.prototype.toUpperCase);
|
|
9617
|
+
const slice = Function.prototype.call.bind(String.prototype.slice);
|
|
9618
|
+
const sort = Function.prototype.call.bind(Array.prototype.sort);
|
|
9619
|
+
const find = Function.prototype.call.bind(Array.prototype.find);
|
|
9620
|
+
function fromTable(table, key) {
|
|
9621
|
+
return table && hasOwn(table, key) ? table[key] : void 0;
|
|
9622
|
+
}
|
|
9473
9623
|
function canonicalizeAttrs(strs) {
|
|
9474
|
-
|
|
9475
|
-
|
|
9476
|
-
|
|
9477
|
-
}, {})).sort();
|
|
9624
|
+
const seen = create(null);
|
|
9625
|
+
for (let i = 0; i < strs.length; i++) seen[lowerCase(strs[i])] = true;
|
|
9626
|
+
return sort(keys(seen));
|
|
9478
9627
|
}
|
|
9479
9628
|
function canonicalizeKVs(arr, extension) {
|
|
9480
|
-
const seen =
|
|
9629
|
+
const seen = create(null);
|
|
9630
|
+
const aliases = fromTable(extensionAlias, extension);
|
|
9481
9631
|
const result = [];
|
|
9482
|
-
for (
|
|
9483
|
-
const
|
|
9484
|
-
|
|
9485
|
-
seen
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9632
|
+
for (let i = 0; i < arr.length; i++) {
|
|
9633
|
+
const field = arr[i];
|
|
9634
|
+
const key = lowerCase(field[0]);
|
|
9635
|
+
if (seen[key]) continue;
|
|
9636
|
+
seen[key] = true;
|
|
9637
|
+
const value = field.length === 2 ? lowerCase(field[1]) : "";
|
|
9638
|
+
let canonical = fromTable(fromTable(aliases, key), value) || value;
|
|
9639
|
+
if (extension === "u" && (key === "rg" || key === "sd")) canonical = fromTable(subdivisionAlias, canonical) || canonical;
|
|
9489
9640
|
appendToList(result, !canonical || extension === "u" && canonical === "true" ? [key] : [key, canonical]);
|
|
9490
9641
|
}
|
|
9491
|
-
return
|
|
9642
|
+
return sort(result, compareKV);
|
|
9492
9643
|
}
|
|
9493
9644
|
function compareKV(t1, t2) {
|
|
9494
9645
|
return t1[0] < t2[0] ? -1 : t1[0] > t2[0] ? 1 : 0;
|
|
@@ -9498,20 +9649,28 @@ function compareExtension(e1, e2) {
|
|
|
9498
9649
|
if (e2.type === "x") return -1;
|
|
9499
9650
|
return e1.type < e2.type ? -1 : e1.type > e2.type ? 1 : 0;
|
|
9500
9651
|
}
|
|
9501
|
-
function
|
|
9502
|
-
const result = [
|
|
9503
|
-
for (
|
|
9652
|
+
function replaceVariants(source, removed, replacement) {
|
|
9653
|
+
const result = [];
|
|
9654
|
+
for (let i = 0; i < source.length; i++) {
|
|
9655
|
+
const variant = source[i];
|
|
9656
|
+
if (!arrayIncludes(removed, variant)) appendToList(result, variant);
|
|
9657
|
+
}
|
|
9658
|
+
for (let i = 0; i < replacement.length; i++) {
|
|
9659
|
+
const variant = replacement[i];
|
|
9660
|
+
if (!arrayIncludes(result, variant)) appendToList(result, variant);
|
|
9661
|
+
}
|
|
9504
9662
|
return result;
|
|
9505
9663
|
}
|
|
9506
9664
|
function compareLanguageAliasRules(a, b) {
|
|
9507
9665
|
const fields = (id) => [
|
|
9508
|
-
|
|
9509
|
-
|
|
9510
|
-
|
|
9666
|
+
+(id.lang !== "und"),
|
|
9667
|
+
+!!id.script,
|
|
9668
|
+
+!!id.region,
|
|
9511
9669
|
id.variants.length
|
|
9512
9670
|
];
|
|
9513
9671
|
const left = fields(a.type), right = fields(b.type);
|
|
9514
|
-
|
|
9672
|
+
let difference = 0;
|
|
9673
|
+
for (let i = 0; i < left.length; i++) difference += right[i] - left[i];
|
|
9515
9674
|
if (difference) return difference;
|
|
9516
9675
|
for (let i = 0; i < left.length; i++) if (!!left[i] !== !!right[i]) return right[i] ? 1 : -1;
|
|
9517
9676
|
const leftTag = emitUnicodeLanguageId(a.type), rightTag = emitUnicodeLanguageId(b.type);
|
|
@@ -9520,14 +9679,14 @@ function compareLanguageAliasRules(a, b) {
|
|
|
9520
9679
|
const languageAliasRules = Object.keys(languageAlias).reduce((rules, from) => {
|
|
9521
9680
|
const to = languageAlias[from];
|
|
9522
9681
|
let type;
|
|
9523
|
-
const source = from
|
|
9682
|
+
const source = splitSubtags(from);
|
|
9524
9683
|
try {
|
|
9525
9684
|
type = parseUnicodeLanguageId(source);
|
|
9526
9685
|
} catch {
|
|
9527
9686
|
return rules;
|
|
9528
9687
|
}
|
|
9529
9688
|
if (source.length) return rules;
|
|
9530
|
-
const target = to
|
|
9689
|
+
const target = splitSubtags(to);
|
|
9531
9690
|
const replacement = parseUnicodeLanguageId(target);
|
|
9532
9691
|
if (target.length) throw new Error(`Invalid language alias replacement: ${to}`);
|
|
9533
9692
|
appendToList(rules, {
|
|
@@ -9540,15 +9699,18 @@ const languageAliasRules = Object.keys(languageAlias).reduce((rules, from) => {
|
|
|
9540
9699
|
return groups;
|
|
9541
9700
|
}, Object.create(null));
|
|
9542
9701
|
function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
|
|
9543
|
-
unicodeLanguageId.lang = unicodeLanguageId.lang
|
|
9544
|
-
if (unicodeLanguageId.script) unicodeLanguageId.script = unicodeLanguageId.script[0]
|
|
9545
|
-
if (unicodeLanguageId.region) unicodeLanguageId.region = unicodeLanguageId.region
|
|
9546
|
-
|
|
9702
|
+
unicodeLanguageId.lang = lowerCase(unicodeLanguageId.lang);
|
|
9703
|
+
if (unicodeLanguageId.script) unicodeLanguageId.script = upperCase(unicodeLanguageId.script[0]) + lowerCase(slice(unicodeLanguageId.script, 1));
|
|
9704
|
+
if (unicodeLanguageId.region) unicodeLanguageId.region = upperCase(unicodeLanguageId.region);
|
|
9705
|
+
const lowerVariants = [];
|
|
9706
|
+
for (let i = 0; i < unicodeLanguageId.variants.length; i++) appendToList(lowerVariants, lowerCase(unicodeLanguageId.variants[i]));
|
|
9707
|
+
unicodeLanguageId.variants = lowerVariants;
|
|
9547
9708
|
const original = emitUnicodeLanguageId(unicodeLanguageId);
|
|
9548
9709
|
let finalLangAst = unicodeLanguageId;
|
|
9549
|
-
const matches = ({ type }) => (!type.script || type.script === finalLangAst.script) && (!type.region || type.region === finalLangAst.region) && type.variants
|
|
9550
|
-
const
|
|
9551
|
-
const
|
|
9710
|
+
const matches = ({ type }) => (!type.script || type.script === finalLangAst.script) && (!type.region || type.region === finalLangAst.region) && arrayEvery(type.variants, (variant) => arrayIncludes(finalLangAst.variants, variant));
|
|
9711
|
+
const rules = languageAliasRules[finalLangAst.lang];
|
|
9712
|
+
const languageRule = rules && find(rules, matches);
|
|
9713
|
+
const undRule = finalLangAst.lang !== "und" && languageAliasRules.und ? find(languageAliasRules.und, matches) : void 0;
|
|
9552
9714
|
const matched = !languageRule ? undRule : !undRule ? languageRule : compareLanguageAliasRules(languageRule, undRule) <= 0 ? languageRule : undRule;
|
|
9553
9715
|
if (matched) {
|
|
9554
9716
|
const { type, replacement } = matched;
|
|
@@ -9556,44 +9718,50 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
|
|
|
9556
9718
|
lang: type.lang !== "und" || finalLangAst.lang === "und" ? replacement.lang : finalLangAst.lang,
|
|
9557
9719
|
script: type.script ? replacement.script : finalLangAst.script || replacement.script,
|
|
9558
9720
|
region: type.region ? replacement.region : finalLangAst.region || replacement.region,
|
|
9559
|
-
variants:
|
|
9721
|
+
variants: replaceVariants(finalLangAst.variants, type.variants, replacement.variants)
|
|
9560
9722
|
};
|
|
9561
9723
|
return canonicalizeUnicodeLanguageId(finalLangAst);
|
|
9562
9724
|
}
|
|
9563
9725
|
if (finalLangAst.region) {
|
|
9564
|
-
const region = finalLangAst.region
|
|
9565
|
-
const regionAlias = territoryAlias
|
|
9726
|
+
const region = upperCase(finalLangAst.region);
|
|
9727
|
+
const regionAlias = fromTable(territoryAlias, region);
|
|
9566
9728
|
let replacedRegion;
|
|
9567
9729
|
if (regionAlias) {
|
|
9568
|
-
const regions = regionAlias
|
|
9730
|
+
const regions = splitSubtags(regionAlias, " ");
|
|
9569
9731
|
replacedRegion = regions[0];
|
|
9570
|
-
const likelySubtag = likelySubtags
|
|
9732
|
+
const likelySubtag = fromTable(likelySubtags, emitUnicodeLanguageId({
|
|
9571
9733
|
lang: finalLangAst.lang,
|
|
9572
9734
|
script: finalLangAst.script,
|
|
9573
9735
|
variants: []
|
|
9574
|
-
})
|
|
9736
|
+
})) || fromTable(likelySubtags, finalLangAst.lang);
|
|
9575
9737
|
if (likelySubtag) {
|
|
9576
|
-
const { region: likelyRegion } = parseUnicodeLanguageId(likelySubtag
|
|
9577
|
-
if (likelyRegion && regions
|
|
9738
|
+
const { region: likelyRegion } = parseUnicodeLanguageId(likelySubtag);
|
|
9739
|
+
if (likelyRegion && arrayIndexOf(regions, likelyRegion) > -1) replacedRegion = likelyRegion;
|
|
9578
9740
|
}
|
|
9579
9741
|
}
|
|
9580
9742
|
if (replacedRegion) finalLangAst.region = replacedRegion;
|
|
9581
|
-
finalLangAst.region = finalLangAst.region
|
|
9743
|
+
finalLangAst.region = upperCase(finalLangAst.region);
|
|
9582
9744
|
}
|
|
9583
9745
|
if (finalLangAst.script) {
|
|
9584
|
-
finalLangAst.script = finalLangAst.script[0]
|
|
9585
|
-
|
|
9746
|
+
finalLangAst.script = upperCase(finalLangAst.script[0]) + lowerCase(slice(finalLangAst.script, 1));
|
|
9747
|
+
const alias = fromTable(scriptAlias, finalLangAst.script);
|
|
9748
|
+
if (alias) finalLangAst.script = alias;
|
|
9586
9749
|
}
|
|
9587
9750
|
if (finalLangAst.variants.length) {
|
|
9588
9751
|
for (let i = 0; i < finalLangAst.variants.length; i++) {
|
|
9589
|
-
|
|
9590
|
-
if (
|
|
9591
|
-
const alias = variantAlias[variant];
|
|
9752
|
+
const alias = fromTable(variantAlias, lowerCase(finalLangAst.variants[i]));
|
|
9753
|
+
if (alias) {
|
|
9592
9754
|
if (isUnicodeVariantSubtag(alias)) finalLangAst.variants[i] = alias;
|
|
9593
9755
|
else if (isUnicodeLanguageSubtag(alias)) finalLangAst.lang = alias;
|
|
9594
9756
|
}
|
|
9595
9757
|
}
|
|
9596
|
-
finalLangAst.variants
|
|
9758
|
+
const variants = sort(finalLangAst.variants);
|
|
9759
|
+
let count = 1;
|
|
9760
|
+
for (let i = 1; i < variants.length; i++) {
|
|
9761
|
+
const variant = variants[i];
|
|
9762
|
+
if (variant !== variants[count - 1]) variants[count++] = variant;
|
|
9763
|
+
}
|
|
9764
|
+
variants.length = count;
|
|
9597
9765
|
}
|
|
9598
9766
|
return emitUnicodeLanguageId(finalLangAst) === original ? finalLangAst : canonicalizeUnicodeLanguageId(finalLangAst);
|
|
9599
9767
|
}
|
|
@@ -9607,60 +9775,51 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
|
|
|
9607
9775
|
function CanonicalizeUnicodeLocaleId(locale) {
|
|
9608
9776
|
locale.lang = canonicalizeUnicodeLanguageId(locale.lang);
|
|
9609
9777
|
if (locale.extensions) {
|
|
9610
|
-
for (
|
|
9611
|
-
|
|
9612
|
-
|
|
9613
|
-
|
|
9614
|
-
|
|
9615
|
-
|
|
9616
|
-
|
|
9617
|
-
|
|
9618
|
-
|
|
9619
|
-
|
|
9778
|
+
for (let i = 0; i < locale.extensions.length; i++) {
|
|
9779
|
+
const extension = locale.extensions[i];
|
|
9780
|
+
switch (extension.type) {
|
|
9781
|
+
case "u":
|
|
9782
|
+
extension.keywords = canonicalizeKVs(extension.keywords, "u");
|
|
9783
|
+
if (extension.attributes) extension.attributes = canonicalizeAttrs(extension.attributes);
|
|
9784
|
+
break;
|
|
9785
|
+
case "t":
|
|
9786
|
+
if (extension.lang) extension.lang = canonicalizeUnicodeLanguageId(extension.lang);
|
|
9787
|
+
extension.fields = canonicalizeKVs(extension.fields, "t");
|
|
9788
|
+
break;
|
|
9789
|
+
default: extension.value = lowerCase(extension.value);
|
|
9790
|
+
}
|
|
9620
9791
|
}
|
|
9621
|
-
locale.extensions
|
|
9792
|
+
sort(locale.extensions, compareExtension);
|
|
9622
9793
|
}
|
|
9623
9794
|
return locale;
|
|
9624
9795
|
}
|
|
9625
9796
|
// 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
|
-
/**
|
|
9636
|
-
* ECMA-402 §9.2.1 CanonicalizeLocaleList, steps 3–7.
|
|
9637
|
-
* https://tc39.es/ecma402/#sec-canonicalizelocalelist
|
|
9638
|
-
* https://github.com/tc39/ecma402/blob/b1c961988b9a07894b1dc3dc2b5626ea48387d61/spec/negotiation.html#L51-L70
|
|
9639
|
-
*/
|
|
9640
9797
|
function CanonicalizeLocaleList(locales) {
|
|
9641
9798
|
if (locales === void 0) return [];
|
|
9642
|
-
if (locales === null) throw new TypeError("Cannot convert null to an object");
|
|
9643
9799
|
const singleLocale = localeString(locales);
|
|
9644
|
-
const list = typeof locales === "string" ? [locales] : singleLocale !== void 0 ? [singleLocale] :
|
|
9800
|
+
const list = typeof locales === "string" ? [locales] : singleLocale !== void 0 ? [singleLocale] : ToObject(locales);
|
|
9645
9801
|
const length = +list.length;
|
|
9646
|
-
const len =
|
|
9802
|
+
const len = length !== length ? 0 : mathMin(mathMax(mathTrunc(length), 0), 9007199254740991);
|
|
9647
9803
|
const seen = [];
|
|
9648
9804
|
for (let k = 0; k < len; k++) {
|
|
9649
9805
|
if (!(k in list)) continue;
|
|
9650
9806
|
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");
|
|
9807
|
+
if (typeof value !== "string" && !IsObject(value)) throw new TypeErrorConstructor$1("Locale list entries must be strings or objects");
|
|
9656
9808
|
const canonicalizedTag = emitUnicodeLocaleId(CanonicalizeUnicodeLocaleId(parseUnicodeLocaleId(localeString(value) ?? ToString(value))));
|
|
9657
|
-
if (seen
|
|
9809
|
+
if (arrayIndexOf(seen, canonicalizedTag) < 0) appendToList(seen, canonicalizedTag);
|
|
9658
9810
|
}
|
|
9659
9811
|
return seen;
|
|
9660
9812
|
}
|
|
9661
|
-
|
|
9813
|
+
const getCanonicalLocales = { getCanonicalLocales(locales) {
|
|
9662
9814
|
return CanonicalizeLocaleList(locales);
|
|
9663
|
-
}
|
|
9815
|
+
} }.getCanonicalLocales;
|
|
9816
|
+
Object.defineProperties(getCanonicalLocales, {
|
|
9817
|
+
__addLocaleBrandReader: { value: addLocaleBrandReader },
|
|
9818
|
+
__connectLocaleBrandReaders: { value: connectLocaleBrandReaders },
|
|
9819
|
+
__getLocaleBrandReaders: { value: getLocaleBrandReaders },
|
|
9820
|
+
__localeBrandRegistry: { value: localeBrandRegistry },
|
|
9821
|
+
__readLocaleTag: { value: localeString }
|
|
9822
|
+
});
|
|
9664
9823
|
export { emitUnicodeLanguageId, emitUnicodeLocaleId, getCanonicalLocales, isStructurallyValidLanguageTag, isUnicodeLanguageSubtag, isUnicodeRegionSubtag, isUnicodeScriptSubtag, isUnicodeVariantSubtag, likelySubtags, parseUnicodeLanguageId, parseUnicodeLocaleId };
|
|
9665
9824
|
|
|
9666
9825
|
//# sourceMappingURL=index.js.map
|