@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/polyfill.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$3 = Object.defineProperty;
|
|
30
|
+
function setDataProperty(target, key, value) {
|
|
31
|
+
defineProperty$3(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$1 = Reflect.apply;
|
|
41
|
+
const defineProperty$2 = 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$2(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$1 = typeof Intl === "undefined" ? void 0 : Intl;
|
|
86
|
+
const currentCanonicalizer = intl$1?.getCanonicalLocales;
|
|
87
|
+
const currentLocale = intl$1?.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$1(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$1(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,235 @@ 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$2 = 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$2 = 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$2(value, start, end));
|
|
1517
|
+
start = end + separator.length;
|
|
1518
|
+
end = indexOf(value, separator, start);
|
|
1519
|
+
}
|
|
1520
|
+
appendToList(parts, slice$2(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 isUnicodeRegionSubtag(region) {
|
|
1547
|
+
return isSubtag(region, 2, 2) || region.length === 3 && isDigit(charCodeAt(region, 0)) && isDigit(charCodeAt(region, 1)) && isDigit(charCodeAt(region, 2));
|
|
1548
|
+
}
|
|
1549
|
+
function isUnicodeScriptSubtag(script) {
|
|
1550
|
+
return isSubtag(script, 4, 4);
|
|
1551
|
+
}
|
|
1552
|
+
function isUnicodeVariantSubtag(variant) {
|
|
1553
|
+
return isSubtag(variant, 5, 8, true) || isSubtag(variant, 4, 4, true) && isDigit(charCodeAt(variant, 0));
|
|
1554
|
+
}
|
|
1555
|
+
function parseUnicodeLanguageId(chunks) {
|
|
1556
|
+
if (typeof chunks === "string") chunks = splitSubtags(chunks);
|
|
1557
|
+
const lang = shift(chunks);
|
|
1558
|
+
if (!lang) throw new RangeErrorConstructor("Missing unicode_language_subtag");
|
|
1559
|
+
if (lang === "root") return {
|
|
1560
|
+
lang: "root",
|
|
1561
|
+
variants: []
|
|
1562
|
+
};
|
|
1563
|
+
if (!isUnicodeLanguageSubtag(lang)) throw new RangeErrorConstructor("Malformed unicode_language_subtag");
|
|
1564
|
+
let script;
|
|
1565
|
+
if (chunks.length && isUnicodeScriptSubtag(chunks[0])) script = shift(chunks);
|
|
1566
|
+
let region;
|
|
1567
|
+
if (chunks.length && isUnicodeRegionSubtag(chunks[0])) region = shift(chunks);
|
|
1568
|
+
const variants = [];
|
|
1569
|
+
const seenVariants = create$2(null);
|
|
1570
|
+
while (chunks.length && isUnicodeVariantSubtag(chunks[0])) {
|
|
1571
|
+
const variant = shift(chunks);
|
|
1572
|
+
const key = lowerCase(variant);
|
|
1573
|
+
if (seenVariants[key]) throw new RangeErrorConstructor(`Duplicate variant "${variant}"`);
|
|
1574
|
+
seenVariants[key] = true;
|
|
1575
|
+
appendToList(variants, variant);
|
|
1576
|
+
}
|
|
1577
|
+
return {
|
|
1578
|
+
lang,
|
|
1579
|
+
script,
|
|
1580
|
+
region,
|
|
1581
|
+
variants
|
|
1582
|
+
};
|
|
1583
|
+
}
|
|
1584
|
+
function parseUnicodeExtension(chunks) {
|
|
1585
|
+
const keywords = [];
|
|
1586
|
+
let keyword;
|
|
1587
|
+
while (chunks.length && (keyword = parseKeyword(chunks))) appendToList(keywords, keyword);
|
|
1588
|
+
if (keywords.length) return {
|
|
1589
|
+
type: "u",
|
|
1590
|
+
keywords,
|
|
1591
|
+
attributes: []
|
|
1592
|
+
};
|
|
1593
|
+
const attributes = [];
|
|
1594
|
+
while (chunks.length && isSubtag(chunks[0], 3, 8, true)) appendToList(attributes, shift(chunks));
|
|
1595
|
+
while (chunks.length && (keyword = parseKeyword(chunks))) appendToList(keywords, keyword);
|
|
1596
|
+
if (keywords.length || attributes.length) return {
|
|
1597
|
+
type: "u",
|
|
1598
|
+
attributes,
|
|
1599
|
+
keywords
|
|
1600
|
+
};
|
|
1601
|
+
throw new RangeErrorConstructor("Malformed unicode_extension");
|
|
1602
|
+
}
|
|
1603
|
+
function parseKeyword(chunks) {
|
|
1604
|
+
let key;
|
|
1605
|
+
if (!isUnicodeKey(chunks[0])) return;
|
|
1606
|
+
key = shift(chunks);
|
|
1607
|
+
const type = [];
|
|
1608
|
+
while (chunks.length && isSubtag(chunks[0], 3, 8, true)) appendToList(type, shift(chunks));
|
|
1609
|
+
let value = "";
|
|
1610
|
+
if (type.length) value = join(type, "-");
|
|
1611
|
+
return [key, value];
|
|
1612
|
+
}
|
|
1613
|
+
function parseTransformedExtension(chunks) {
|
|
1614
|
+
let lang;
|
|
1615
|
+
if (chunks.length && isUnicodeLanguageSubtag(chunks[0])) lang = parseUnicodeLanguageId(chunks);
|
|
1616
|
+
const fields = [];
|
|
1617
|
+
while (chunks.length && isTransformedKey(chunks[0])) {
|
|
1618
|
+
const key = shift(chunks);
|
|
1619
|
+
const value = [];
|
|
1620
|
+
while (chunks.length && isSubtag(chunks[0], 3, 8, true)) appendToList(value, shift(chunks));
|
|
1621
|
+
if (!value.length) throw new RangeErrorConstructor(`Missing tvalue for tkey "${key}"`);
|
|
1622
|
+
appendToList(fields, [key, join(value, "-")]);
|
|
1623
|
+
}
|
|
1624
|
+
if (lang || fields.length) return {
|
|
1625
|
+
type: "t",
|
|
1626
|
+
fields,
|
|
1627
|
+
lang
|
|
1628
|
+
};
|
|
1629
|
+
throw new RangeErrorConstructor("Malformed transformed_extension");
|
|
1630
|
+
}
|
|
1631
|
+
function parsePuExtension(chunks) {
|
|
1632
|
+
const exts = [];
|
|
1633
|
+
while (chunks.length && isSubtag(chunks[0], 1, 8, true)) appendToList(exts, shift(chunks));
|
|
1634
|
+
if (exts.length) return {
|
|
1635
|
+
type: "x",
|
|
1636
|
+
value: join(exts, "-")
|
|
1637
|
+
};
|
|
1638
|
+
throw new RangeErrorConstructor("Malformed private_use_extension");
|
|
1639
|
+
}
|
|
1640
|
+
function parseOtherExtensionValue(chunks) {
|
|
1641
|
+
const exts = [];
|
|
1642
|
+
while (chunks.length && isSubtag(chunks[0], 2, 8, true)) appendToList(exts, shift(chunks));
|
|
1643
|
+
if (exts.length) return join(exts, "-");
|
|
1644
|
+
throw new RangeErrorConstructor("Missing extension value");
|
|
1645
|
+
}
|
|
1646
|
+
function parseExtensions(chunks) {
|
|
1647
|
+
if (!chunks.length) return { extensions: [] };
|
|
1648
|
+
const extensions = [];
|
|
1649
|
+
let unicodeExtension;
|
|
1650
|
+
let transformedExtension;
|
|
1651
|
+
let puExtension;
|
|
1652
|
+
const otherExtensionMap = create$2(null);
|
|
1653
|
+
do {
|
|
1654
|
+
const singleton = shift(chunks);
|
|
1655
|
+
if (!isSubtag(singleton, 1, 1, true)) throw new RangeErrorConstructor("Malformed extension type");
|
|
1656
|
+
const type = lowerCase(singleton);
|
|
1657
|
+
switch (type) {
|
|
1658
|
+
case "u":
|
|
1659
|
+
if (unicodeExtension) throw new RangeErrorConstructor("There can only be 1 -u- extension");
|
|
1660
|
+
unicodeExtension = parseUnicodeExtension(chunks);
|
|
1661
|
+
appendToList(extensions, unicodeExtension);
|
|
1662
|
+
break;
|
|
1663
|
+
case "t":
|
|
1664
|
+
if (transformedExtension) throw new RangeErrorConstructor("There can only be 1 -t- extension");
|
|
1665
|
+
transformedExtension = parseTransformedExtension(chunks);
|
|
1666
|
+
appendToList(extensions, transformedExtension);
|
|
1667
|
+
break;
|
|
1668
|
+
case "x":
|
|
1669
|
+
if (puExtension) throw new RangeErrorConstructor("There can only be 1 -x- extension");
|
|
1670
|
+
puExtension = parsePuExtension(chunks);
|
|
1671
|
+
appendToList(extensions, puExtension);
|
|
1672
|
+
break;
|
|
1673
|
+
default:
|
|
1674
|
+
if (type in otherExtensionMap) throw new RangeErrorConstructor(`There can only be 1 -${type}- extension`);
|
|
1675
|
+
const extension = {
|
|
1676
|
+
type,
|
|
1677
|
+
value: parseOtherExtensionValue(chunks)
|
|
1678
|
+
};
|
|
1679
|
+
otherExtensionMap[extension.type] = extension;
|
|
1680
|
+
appendToList(extensions, extension);
|
|
1681
|
+
}
|
|
1682
|
+
} while (chunks.length);
|
|
1683
|
+
return { extensions };
|
|
1684
|
+
}
|
|
1685
|
+
function parseUnicodeLocaleId(locale) {
|
|
1686
|
+
const chunks = splitSubtags(locale);
|
|
1687
|
+
const lang = parseUnicodeLanguageId(chunks);
|
|
1688
|
+
if (lang.lang === "root") throw new RangeErrorConstructor("Invalid language tag: root");
|
|
1689
|
+
return {
|
|
1690
|
+
lang,
|
|
1691
|
+
...parseExtensions(chunks)
|
|
1692
|
+
};
|
|
1693
|
+
}
|
|
1394
1694
|
// packages/intl-getcanonicallocales/emitter.ts
|
|
1695
|
+
function appendSubtag(tag, subtag) {
|
|
1696
|
+
if (!subtag) return tag;
|
|
1697
|
+
return tag ? tag + "-" + subtag : subtag;
|
|
1698
|
+
}
|
|
1395
1699
|
function emitUnicodeLanguageId(lang) {
|
|
1396
1700
|
if (!lang) return "";
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1701
|
+
let tag = appendSubtag(appendSubtag(lang.lang, lang.script), lang.region);
|
|
1702
|
+
const variants = lang.variants;
|
|
1703
|
+
for (let i = 0; variants && i < variants.length; i++) tag = appendSubtag(tag, variants[i]);
|
|
1704
|
+
return tag;
|
|
1705
|
+
}
|
|
1706
|
+
function appendFields(tag, fields) {
|
|
1707
|
+
for (let i = 0; i < fields.length; i++) {
|
|
1708
|
+
const field = fields[i];
|
|
1709
|
+
tag = appendSubtag(tag, field[0]);
|
|
1710
|
+
if (field.length > 1) tag = appendSubtag(tag, field[1]);
|
|
1711
|
+
}
|
|
1712
|
+
return tag;
|
|
1403
1713
|
}
|
|
1404
1714
|
function emitUnicodeLocaleId({ lang, extensions }) {
|
|
1405
|
-
|
|
1406
|
-
for (
|
|
1407
|
-
|
|
1715
|
+
let tag = emitUnicodeLanguageId(lang);
|
|
1716
|
+
for (let i = 0; i < extensions.length; i++) {
|
|
1717
|
+
const ext = extensions[i];
|
|
1718
|
+
tag = appendSubtag(tag, ext.type);
|
|
1408
1719
|
switch (ext.type) {
|
|
1409
1720
|
case "u":
|
|
1410
|
-
|
|
1721
|
+
for (let j = 0; j < ext.attributes.length; j++) tag = appendSubtag(tag, ext.attributes[j]);
|
|
1722
|
+
tag = appendFields(tag, ext.keywords);
|
|
1411
1723
|
break;
|
|
1412
1724
|
case "t":
|
|
1413
|
-
|
|
1725
|
+
tag = appendSubtag(tag, lowerCase(emitUnicodeLanguageId(ext.lang)));
|
|
1726
|
+
tag = appendFields(tag, ext.fields);
|
|
1414
1727
|
break;
|
|
1415
|
-
default:
|
|
1728
|
+
default: tag = appendSubtag(tag, ext.value);
|
|
1416
1729
|
}
|
|
1417
1730
|
}
|
|
1418
|
-
return
|
|
1731
|
+
return tag;
|
|
1419
1732
|
}
|
|
1420
1733
|
// node_modules/.aspect_rules_js/@formatjs_generated+cldr.core@0.0.0/node_modules/@formatjs_generated/cldr.core/likelySubtags.js
|
|
1421
1734
|
const likelySubtags = {
|
|
@@ -9288,199 +9601,37 @@ const likelySubtags = {
|
|
|
9288
9601
|
"zza": "zza-Latn-TR",
|
|
9289
9602
|
"zzj": "zzj-Hani-CN"
|
|
9290
9603
|
};
|
|
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 isUnicodeRegionSubtag(region) {
|
|
9320
|
-
return isSubtag(region, 2, 2) || region.length === 3 && isDigit(region.charCodeAt(0)) && isDigit(region.charCodeAt(1)) && isDigit(region.charCodeAt(2));
|
|
9321
|
-
}
|
|
9322
|
-
function isUnicodeScriptSubtag(script) {
|
|
9323
|
-
return isSubtag(script, 4, 4);
|
|
9324
|
-
}
|
|
9325
|
-
function isUnicodeVariantSubtag(variant) {
|
|
9326
|
-
return isSubtag(variant, 5, 8, true) || isSubtag(variant, 4, 4, true) && isDigit(variant.charCodeAt(0));
|
|
9327
|
-
}
|
|
9328
|
-
function parseUnicodeLanguageId(chunks) {
|
|
9329
|
-
if (typeof chunks === "string") chunks = chunks.split("-");
|
|
9330
|
-
const lang = chunks.shift();
|
|
9331
|
-
if (!lang) throw new RangeError("Missing unicode_language_subtag");
|
|
9332
|
-
if (lang === "root") return {
|
|
9333
|
-
lang: "root",
|
|
9334
|
-
variants: []
|
|
9335
|
-
};
|
|
9336
|
-
if (!isUnicodeLanguageSubtag(lang)) throw new RangeError("Malformed unicode_language_subtag");
|
|
9337
|
-
let script;
|
|
9338
|
-
if (chunks.length && isUnicodeScriptSubtag(chunks[0])) script = chunks.shift();
|
|
9339
|
-
let region;
|
|
9340
|
-
if (chunks.length && isUnicodeRegionSubtag(chunks[0])) region = chunks.shift();
|
|
9341
|
-
const variants = {};
|
|
9342
|
-
while (chunks.length && isUnicodeVariantSubtag(chunks[0])) {
|
|
9343
|
-
const variant = chunks.shift();
|
|
9344
|
-
if (variant in variants) throw new RangeError(`Duplicate variant "${variant}"`);
|
|
9345
|
-
variants[variant] = 1;
|
|
9346
|
-
}
|
|
9347
|
-
return {
|
|
9348
|
-
lang,
|
|
9349
|
-
script,
|
|
9350
|
-
region,
|
|
9351
|
-
variants: Object.keys(variants)
|
|
9352
|
-
};
|
|
9353
|
-
}
|
|
9354
|
-
function parseUnicodeExtension(chunks) {
|
|
9355
|
-
const keywords = [];
|
|
9356
|
-
let keyword;
|
|
9357
|
-
while (chunks.length && (keyword = parseKeyword(chunks))) appendToList(keywords, keyword);
|
|
9358
|
-
if (keywords.length) return {
|
|
9359
|
-
type: "u",
|
|
9360
|
-
keywords,
|
|
9361
|
-
attributes: []
|
|
9362
|
-
};
|
|
9363
|
-
const attributes = [];
|
|
9364
|
-
while (chunks.length && isSubtag(chunks[0], 3, 8, true)) appendToList(attributes, chunks.shift());
|
|
9365
|
-
while (chunks.length && (keyword = parseKeyword(chunks))) appendToList(keywords, keyword);
|
|
9366
|
-
if (keywords.length || attributes.length) return {
|
|
9367
|
-
type: "u",
|
|
9368
|
-
attributes,
|
|
9369
|
-
keywords
|
|
9370
|
-
};
|
|
9371
|
-
throw new RangeError("Malformed unicode_extension");
|
|
9372
|
-
}
|
|
9373
|
-
function parseKeyword(chunks) {
|
|
9374
|
-
let key;
|
|
9375
|
-
if (!isUnicodeKey(chunks[0])) return;
|
|
9376
|
-
key = chunks.shift();
|
|
9377
|
-
const type = [];
|
|
9378
|
-
while (chunks.length && isSubtag(chunks[0], 3, 8, true)) appendToList(type, chunks.shift());
|
|
9379
|
-
let value = "";
|
|
9380
|
-
if (type.length) value = type.join("-");
|
|
9381
|
-
return [key, value];
|
|
9382
|
-
}
|
|
9383
|
-
function parseTransformedExtension(chunks) {
|
|
9384
|
-
let lang;
|
|
9385
|
-
if (chunks.length && isUnicodeLanguageSubtag(chunks[0])) lang = parseUnicodeLanguageId(chunks);
|
|
9386
|
-
const fields = [];
|
|
9387
|
-
while (chunks.length && isTransformedKey(chunks[0])) {
|
|
9388
|
-
const key = chunks.shift();
|
|
9389
|
-
const value = [];
|
|
9390
|
-
while (chunks.length && isSubtag(chunks[0], 3, 8, true)) appendToList(value, chunks.shift());
|
|
9391
|
-
if (!value.length) throw new RangeError(`Missing tvalue for tkey "${key}"`);
|
|
9392
|
-
appendToList(fields, [key, value.join("-")]);
|
|
9393
|
-
}
|
|
9394
|
-
if (lang || fields.length) return {
|
|
9395
|
-
type: "t",
|
|
9396
|
-
fields,
|
|
9397
|
-
lang
|
|
9398
|
-
};
|
|
9399
|
-
throw new RangeError("Malformed transformed_extension");
|
|
9400
|
-
}
|
|
9401
|
-
function parsePuExtension(chunks) {
|
|
9402
|
-
const exts = [];
|
|
9403
|
-
while (chunks.length && isSubtag(chunks[0], 1, 8, true)) appendToList(exts, chunks.shift());
|
|
9404
|
-
if (exts.length) return {
|
|
9405
|
-
type: "x",
|
|
9406
|
-
value: exts.join("-")
|
|
9407
|
-
};
|
|
9408
|
-
throw new RangeError("Malformed private_use_extension");
|
|
9409
|
-
}
|
|
9410
|
-
function parseOtherExtensionValue(chunks) {
|
|
9411
|
-
const exts = [];
|
|
9412
|
-
while (chunks.length && isSubtag(chunks[0], 2, 8, true)) appendToList(exts, chunks.shift());
|
|
9413
|
-
if (exts.length) return exts.join("-");
|
|
9414
|
-
throw new RangeError("Missing extension value");
|
|
9415
|
-
}
|
|
9416
|
-
function parseExtensions(chunks) {
|
|
9417
|
-
if (!chunks.length) return { extensions: [] };
|
|
9418
|
-
const extensions = [];
|
|
9419
|
-
let unicodeExtension;
|
|
9420
|
-
let transformedExtension;
|
|
9421
|
-
let puExtension;
|
|
9422
|
-
const otherExtensionMap = {};
|
|
9423
|
-
do {
|
|
9424
|
-
const type = chunks.shift().toLowerCase();
|
|
9425
|
-
switch (type) {
|
|
9426
|
-
case "u":
|
|
9427
|
-
case "U":
|
|
9428
|
-
if (unicodeExtension) throw new RangeError("There can only be 1 -u- extension");
|
|
9429
|
-
unicodeExtension = parseUnicodeExtension(chunks);
|
|
9430
|
-
appendToList(extensions, unicodeExtension);
|
|
9431
|
-
break;
|
|
9432
|
-
case "t":
|
|
9433
|
-
case "T":
|
|
9434
|
-
if (transformedExtension) throw new RangeError("There can only be 1 -t- extension");
|
|
9435
|
-
transformedExtension = parseTransformedExtension(chunks);
|
|
9436
|
-
appendToList(extensions, transformedExtension);
|
|
9437
|
-
break;
|
|
9438
|
-
case "x":
|
|
9439
|
-
case "X":
|
|
9440
|
-
if (puExtension) throw new RangeError("There can only be 1 -x- extension");
|
|
9441
|
-
puExtension = parsePuExtension(chunks);
|
|
9442
|
-
appendToList(extensions, puExtension);
|
|
9443
|
-
break;
|
|
9444
|
-
default:
|
|
9445
|
-
if (!isOtherExtensionType(type)) throw new RangeError("Malformed extension type");
|
|
9446
|
-
if (type in otherExtensionMap) throw new RangeError(`There can only be 1 -${type}- extension`);
|
|
9447
|
-
const extension = {
|
|
9448
|
-
type,
|
|
9449
|
-
value: parseOtherExtensionValue(chunks)
|
|
9450
|
-
};
|
|
9451
|
-
otherExtensionMap[extension.type] = extension;
|
|
9452
|
-
appendToList(extensions, extension);
|
|
9453
|
-
}
|
|
9454
|
-
} while (chunks.length);
|
|
9455
|
-
return { extensions };
|
|
9456
|
-
}
|
|
9457
|
-
function parseUnicodeLocaleId(locale) {
|
|
9458
|
-
const chunks = locale.split("-");
|
|
9459
|
-
return {
|
|
9460
|
-
lang: parseUnicodeLanguageId(chunks),
|
|
9461
|
-
...parseExtensions(chunks)
|
|
9462
|
-
};
|
|
9463
|
-
}
|
|
9464
9604
|
// packages/intl-getcanonicallocales/canonicalizer.ts
|
|
9605
|
+
const create$1 = Object.create;
|
|
9606
|
+
const keys = Object.keys;
|
|
9607
|
+
const hasOwn = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
|
|
9608
|
+
const upperCase = Function.prototype.call.bind(String.prototype.toUpperCase);
|
|
9609
|
+
const slice$1 = Function.prototype.call.bind(String.prototype.slice);
|
|
9610
|
+
const sort = Function.prototype.call.bind(Array.prototype.sort);
|
|
9611
|
+
const find = Function.prototype.call.bind(Array.prototype.find);
|
|
9612
|
+
function fromTable(table, key) {
|
|
9613
|
+
return table && hasOwn(table, key) ? table[key] : void 0;
|
|
9614
|
+
}
|
|
9465
9615
|
function canonicalizeAttrs(strs) {
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
}, {})).sort();
|
|
9616
|
+
const seen = create$1(null);
|
|
9617
|
+
for (let i = 0; i < strs.length; i++) seen[lowerCase(strs[i])] = true;
|
|
9618
|
+
return sort(keys(seen));
|
|
9470
9619
|
}
|
|
9471
9620
|
function canonicalizeKVs(arr, extension) {
|
|
9472
|
-
const seen =
|
|
9621
|
+
const seen = create$1(null);
|
|
9622
|
+
const aliases = fromTable(extensionAlias, extension);
|
|
9473
9623
|
const result = [];
|
|
9474
|
-
for (
|
|
9475
|
-
const
|
|
9476
|
-
|
|
9477
|
-
seen
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9624
|
+
for (let i = 0; i < arr.length; i++) {
|
|
9625
|
+
const field = arr[i];
|
|
9626
|
+
const key = lowerCase(field[0]);
|
|
9627
|
+
if (seen[key]) continue;
|
|
9628
|
+
seen[key] = true;
|
|
9629
|
+
const value = field.length === 2 ? lowerCase(field[1]) : "";
|
|
9630
|
+
let canonical = fromTable(fromTable(aliases, key), value) || value;
|
|
9631
|
+
if (extension === "u" && (key === "rg" || key === "sd")) canonical = fromTable(subdivisionAlias, canonical) || canonical;
|
|
9481
9632
|
appendToList(result, !canonical || extension === "u" && canonical === "true" ? [key] : [key, canonical]);
|
|
9482
9633
|
}
|
|
9483
|
-
return
|
|
9634
|
+
return sort(result, compareKV);
|
|
9484
9635
|
}
|
|
9485
9636
|
function compareKV(t1, t2) {
|
|
9486
9637
|
return t1[0] < t2[0] ? -1 : t1[0] > t2[0] ? 1 : 0;
|
|
@@ -9490,20 +9641,28 @@ function compareExtension(e1, e2) {
|
|
|
9490
9641
|
if (e2.type === "x") return -1;
|
|
9491
9642
|
return e1.type < e2.type ? -1 : e1.type > e2.type ? 1 : 0;
|
|
9492
9643
|
}
|
|
9493
|
-
function
|
|
9494
|
-
const result = [
|
|
9495
|
-
for (
|
|
9644
|
+
function replaceVariants(source, removed, replacement) {
|
|
9645
|
+
const result = [];
|
|
9646
|
+
for (let i = 0; i < source.length; i++) {
|
|
9647
|
+
const variant = source[i];
|
|
9648
|
+
if (!arrayIncludes(removed, variant)) appendToList(result, variant);
|
|
9649
|
+
}
|
|
9650
|
+
for (let i = 0; i < replacement.length; i++) {
|
|
9651
|
+
const variant = replacement[i];
|
|
9652
|
+
if (!arrayIncludes(result, variant)) appendToList(result, variant);
|
|
9653
|
+
}
|
|
9496
9654
|
return result;
|
|
9497
9655
|
}
|
|
9498
9656
|
function compareLanguageAliasRules(a, b) {
|
|
9499
9657
|
const fields = (id) => [
|
|
9500
|
-
|
|
9501
|
-
|
|
9502
|
-
|
|
9658
|
+
+(id.lang !== "und"),
|
|
9659
|
+
+!!id.script,
|
|
9660
|
+
+!!id.region,
|
|
9503
9661
|
id.variants.length
|
|
9504
9662
|
];
|
|
9505
9663
|
const left = fields(a.type), right = fields(b.type);
|
|
9506
|
-
|
|
9664
|
+
let difference = 0;
|
|
9665
|
+
for (let i = 0; i < left.length; i++) difference += right[i] - left[i];
|
|
9507
9666
|
if (difference) return difference;
|
|
9508
9667
|
for (let i = 0; i < left.length; i++) if (!!left[i] !== !!right[i]) return right[i] ? 1 : -1;
|
|
9509
9668
|
const leftTag = emitUnicodeLanguageId(a.type), rightTag = emitUnicodeLanguageId(b.type);
|
|
@@ -9512,14 +9671,14 @@ function compareLanguageAliasRules(a, b) {
|
|
|
9512
9671
|
const languageAliasRules = Object.keys(languageAlias).reduce((rules, from) => {
|
|
9513
9672
|
const to = languageAlias[from];
|
|
9514
9673
|
let type;
|
|
9515
|
-
const source = from
|
|
9674
|
+
const source = splitSubtags(from);
|
|
9516
9675
|
try {
|
|
9517
9676
|
type = parseUnicodeLanguageId(source);
|
|
9518
9677
|
} catch {
|
|
9519
9678
|
return rules;
|
|
9520
9679
|
}
|
|
9521
9680
|
if (source.length) return rules;
|
|
9522
|
-
const target = to
|
|
9681
|
+
const target = splitSubtags(to);
|
|
9523
9682
|
const replacement = parseUnicodeLanguageId(target);
|
|
9524
9683
|
if (target.length) throw new Error(`Invalid language alias replacement: ${to}`);
|
|
9525
9684
|
appendToList(rules, {
|
|
@@ -9532,15 +9691,18 @@ const languageAliasRules = Object.keys(languageAlias).reduce((rules, from) => {
|
|
|
9532
9691
|
return groups;
|
|
9533
9692
|
}, Object.create(null));
|
|
9534
9693
|
function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
|
|
9535
|
-
unicodeLanguageId.lang = unicodeLanguageId.lang
|
|
9536
|
-
if (unicodeLanguageId.script) unicodeLanguageId.script = unicodeLanguageId.script[0]
|
|
9537
|
-
if (unicodeLanguageId.region) unicodeLanguageId.region = unicodeLanguageId.region
|
|
9538
|
-
|
|
9694
|
+
unicodeLanguageId.lang = lowerCase(unicodeLanguageId.lang);
|
|
9695
|
+
if (unicodeLanguageId.script) unicodeLanguageId.script = upperCase(unicodeLanguageId.script[0]) + lowerCase(slice$1(unicodeLanguageId.script, 1));
|
|
9696
|
+
if (unicodeLanguageId.region) unicodeLanguageId.region = upperCase(unicodeLanguageId.region);
|
|
9697
|
+
const lowerVariants = [];
|
|
9698
|
+
for (let i = 0; i < unicodeLanguageId.variants.length; i++) appendToList(lowerVariants, lowerCase(unicodeLanguageId.variants[i]));
|
|
9699
|
+
unicodeLanguageId.variants = lowerVariants;
|
|
9539
9700
|
const original = emitUnicodeLanguageId(unicodeLanguageId);
|
|
9540
9701
|
let finalLangAst = unicodeLanguageId;
|
|
9541
|
-
const matches = ({ type }) => (!type.script || type.script === finalLangAst.script) && (!type.region || type.region === finalLangAst.region) && type.variants
|
|
9542
|
-
const
|
|
9543
|
-
const
|
|
9702
|
+
const matches = ({ type }) => (!type.script || type.script === finalLangAst.script) && (!type.region || type.region === finalLangAst.region) && arrayEvery(type.variants, (variant) => arrayIncludes(finalLangAst.variants, variant));
|
|
9703
|
+
const rules = languageAliasRules[finalLangAst.lang];
|
|
9704
|
+
const languageRule = rules && find(rules, matches);
|
|
9705
|
+
const undRule = finalLangAst.lang !== "und" && languageAliasRules.und ? find(languageAliasRules.und, matches) : void 0;
|
|
9544
9706
|
const matched = !languageRule ? undRule : !undRule ? languageRule : compareLanguageAliasRules(languageRule, undRule) <= 0 ? languageRule : undRule;
|
|
9545
9707
|
if (matched) {
|
|
9546
9708
|
const { type, replacement } = matched;
|
|
@@ -9548,44 +9710,50 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
|
|
|
9548
9710
|
lang: type.lang !== "und" || finalLangAst.lang === "und" ? replacement.lang : finalLangAst.lang,
|
|
9549
9711
|
script: type.script ? replacement.script : finalLangAst.script || replacement.script,
|
|
9550
9712
|
region: type.region ? replacement.region : finalLangAst.region || replacement.region,
|
|
9551
|
-
variants:
|
|
9713
|
+
variants: replaceVariants(finalLangAst.variants, type.variants, replacement.variants)
|
|
9552
9714
|
};
|
|
9553
9715
|
return canonicalizeUnicodeLanguageId(finalLangAst);
|
|
9554
9716
|
}
|
|
9555
9717
|
if (finalLangAst.region) {
|
|
9556
|
-
const region = finalLangAst.region
|
|
9557
|
-
const regionAlias = territoryAlias
|
|
9718
|
+
const region = upperCase(finalLangAst.region);
|
|
9719
|
+
const regionAlias = fromTable(territoryAlias, region);
|
|
9558
9720
|
let replacedRegion;
|
|
9559
9721
|
if (regionAlias) {
|
|
9560
|
-
const regions = regionAlias
|
|
9722
|
+
const regions = splitSubtags(regionAlias, " ");
|
|
9561
9723
|
replacedRegion = regions[0];
|
|
9562
|
-
const likelySubtag = likelySubtags
|
|
9724
|
+
const likelySubtag = fromTable(likelySubtags, emitUnicodeLanguageId({
|
|
9563
9725
|
lang: finalLangAst.lang,
|
|
9564
9726
|
script: finalLangAst.script,
|
|
9565
9727
|
variants: []
|
|
9566
|
-
})
|
|
9728
|
+
})) || fromTable(likelySubtags, finalLangAst.lang);
|
|
9567
9729
|
if (likelySubtag) {
|
|
9568
|
-
const { region: likelyRegion } = parseUnicodeLanguageId(likelySubtag
|
|
9569
|
-
if (likelyRegion && regions
|
|
9730
|
+
const { region: likelyRegion } = parseUnicodeLanguageId(likelySubtag);
|
|
9731
|
+
if (likelyRegion && arrayIndexOf(regions, likelyRegion) > -1) replacedRegion = likelyRegion;
|
|
9570
9732
|
}
|
|
9571
9733
|
}
|
|
9572
9734
|
if (replacedRegion) finalLangAst.region = replacedRegion;
|
|
9573
|
-
finalLangAst.region = finalLangAst.region
|
|
9735
|
+
finalLangAst.region = upperCase(finalLangAst.region);
|
|
9574
9736
|
}
|
|
9575
9737
|
if (finalLangAst.script) {
|
|
9576
|
-
finalLangAst.script = finalLangAst.script[0]
|
|
9577
|
-
|
|
9738
|
+
finalLangAst.script = upperCase(finalLangAst.script[0]) + lowerCase(slice$1(finalLangAst.script, 1));
|
|
9739
|
+
const alias = fromTable(scriptAlias, finalLangAst.script);
|
|
9740
|
+
if (alias) finalLangAst.script = alias;
|
|
9578
9741
|
}
|
|
9579
9742
|
if (finalLangAst.variants.length) {
|
|
9580
9743
|
for (let i = 0; i < finalLangAst.variants.length; i++) {
|
|
9581
|
-
|
|
9582
|
-
if (
|
|
9583
|
-
const alias = variantAlias[variant];
|
|
9744
|
+
const alias = fromTable(variantAlias, lowerCase(finalLangAst.variants[i]));
|
|
9745
|
+
if (alias) {
|
|
9584
9746
|
if (isUnicodeVariantSubtag(alias)) finalLangAst.variants[i] = alias;
|
|
9585
9747
|
else if (isUnicodeLanguageSubtag(alias)) finalLangAst.lang = alias;
|
|
9586
9748
|
}
|
|
9587
9749
|
}
|
|
9588
|
-
finalLangAst.variants
|
|
9750
|
+
const variants = sort(finalLangAst.variants);
|
|
9751
|
+
let count = 1;
|
|
9752
|
+
for (let i = 1; i < variants.length; i++) {
|
|
9753
|
+
const variant = variants[i];
|
|
9754
|
+
if (variant !== variants[count - 1]) variants[count++] = variant;
|
|
9755
|
+
}
|
|
9756
|
+
variants.length = count;
|
|
9589
9757
|
}
|
|
9590
9758
|
return emitUnicodeLanguageId(finalLangAst) === original ? finalLangAst : canonicalizeUnicodeLanguageId(finalLangAst);
|
|
9591
9759
|
}
|
|
@@ -9599,71 +9767,69 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
|
|
|
9599
9767
|
function CanonicalizeUnicodeLocaleId(locale) {
|
|
9600
9768
|
locale.lang = canonicalizeUnicodeLanguageId(locale.lang);
|
|
9601
9769
|
if (locale.extensions) {
|
|
9602
|
-
for (
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
|
|
9770
|
+
for (let i = 0; i < locale.extensions.length; i++) {
|
|
9771
|
+
const extension = locale.extensions[i];
|
|
9772
|
+
switch (extension.type) {
|
|
9773
|
+
case "u":
|
|
9774
|
+
extension.keywords = canonicalizeKVs(extension.keywords, "u");
|
|
9775
|
+
if (extension.attributes) extension.attributes = canonicalizeAttrs(extension.attributes);
|
|
9776
|
+
break;
|
|
9777
|
+
case "t":
|
|
9778
|
+
if (extension.lang) extension.lang = canonicalizeUnicodeLanguageId(extension.lang);
|
|
9779
|
+
extension.fields = canonicalizeKVs(extension.fields, "t");
|
|
9780
|
+
break;
|
|
9781
|
+
default: extension.value = lowerCase(extension.value);
|
|
9782
|
+
}
|
|
9612
9783
|
}
|
|
9613
|
-
locale.extensions
|
|
9784
|
+
sort(locale.extensions, compareExtension);
|
|
9614
9785
|
}
|
|
9615
9786
|
return locale;
|
|
9616
9787
|
}
|
|
9617
9788
|
// packages/intl-getcanonicallocales/index.ts
|
|
9618
|
-
const originalLocaleToString = typeof Intl !== "undefined" ? Intl.Locale?.prototype.toString : void 0;
|
|
9619
|
-
function localeString(value) {
|
|
9620
|
-
if (value === null || typeof value !== "object" && typeof value !== "function") return void 0;
|
|
9621
|
-
const currentLocaleToString = typeof Intl !== "undefined" ? Intl.Locale?.prototype.toString : void 0;
|
|
9622
|
-
for (const method of [originalLocaleToString, currentLocaleToString]) if (method) try {
|
|
9623
|
-
const tag = method.call(value);
|
|
9624
|
-
if (typeof tag === "string") return tag;
|
|
9625
|
-
} catch {}
|
|
9626
|
-
}
|
|
9627
|
-
/**
|
|
9628
|
-
* ECMA-402 §9.2.1 CanonicalizeLocaleList, steps 3–7.
|
|
9629
|
-
* https://tc39.es/ecma402/#sec-canonicalizelocalelist
|
|
9630
|
-
* https://github.com/tc39/ecma402/blob/b1c961988b9a07894b1dc3dc2b5626ea48387d61/spec/negotiation.html#L51-L70
|
|
9631
|
-
*/
|
|
9632
9789
|
function CanonicalizeLocaleList(locales) {
|
|
9633
9790
|
if (locales === void 0) return [];
|
|
9634
|
-
if (locales === null) throw new TypeError("Cannot convert null to an object");
|
|
9635
9791
|
const singleLocale = localeString(locales);
|
|
9636
|
-
const list = typeof locales === "string" ? [locales] : singleLocale !== void 0 ? [singleLocale] :
|
|
9792
|
+
const list = typeof locales === "string" ? [locales] : singleLocale !== void 0 ? [singleLocale] : ToObject(locales);
|
|
9637
9793
|
const length = +list.length;
|
|
9638
|
-
const len =
|
|
9794
|
+
const len = length !== length ? 0 : mathMin(mathMax(mathTrunc(length), 0), 9007199254740991);
|
|
9639
9795
|
const seen = [];
|
|
9640
9796
|
for (let k = 0; k < len; k++) {
|
|
9641
9797
|
if (!(k in list)) continue;
|
|
9642
9798
|
const value = list[k];
|
|
9643
|
-
if (value
|
|
9644
|
-
"string",
|
|
9645
|
-
"object",
|
|
9646
|
-
"function"
|
|
9647
|
-
].includes(typeof value)) throw new TypeError("Locale list entries must be strings or objects");
|
|
9799
|
+
if (typeof value !== "string" && !IsObject(value)) throw new TypeErrorConstructor$1("Locale list entries must be strings or objects");
|
|
9648
9800
|
const canonicalizedTag = emitUnicodeLocaleId(CanonicalizeUnicodeLocaleId(parseUnicodeLocaleId(localeString(value) ?? ToString(value))));
|
|
9649
|
-
if (seen
|
|
9801
|
+
if (arrayIndexOf(seen, canonicalizedTag) < 0) appendToList(seen, canonicalizedTag);
|
|
9650
9802
|
}
|
|
9651
9803
|
return seen;
|
|
9652
9804
|
}
|
|
9653
|
-
|
|
9805
|
+
const getCanonicalLocales = { getCanonicalLocales(locales) {
|
|
9654
9806
|
return CanonicalizeLocaleList(locales);
|
|
9655
|
-
}
|
|
9807
|
+
} }.getCanonicalLocales;
|
|
9808
|
+
Object.defineProperties(getCanonicalLocales, {
|
|
9809
|
+
__addLocaleBrandReader: { value: addLocaleBrandReader },
|
|
9810
|
+
__connectLocaleBrandReaders: { value: connectLocaleBrandReaders },
|
|
9811
|
+
__getLocaleBrandReaders: { value: getLocaleBrandReaders },
|
|
9812
|
+
__localeBrandRegistry: { value: localeBrandRegistry },
|
|
9813
|
+
__readLocaleTag: { value: localeString }
|
|
9814
|
+
});
|
|
9656
9815
|
// packages/intl-getcanonicallocales/should-polyfill.ts
|
|
9657
9816
|
function shouldPolyfill() {
|
|
9658
9817
|
if (typeof Intl === "undefined" || typeof Intl.getCanonicalLocales !== "function") return true;
|
|
9659
9818
|
try {
|
|
9660
9819
|
const canonicalize = Intl.getCanonicalLocales;
|
|
9661
|
-
return canonicalize("und-x-private")[0] !== "und-x-private" || canonicalize("en-u-aa-yes")[0] !== "en-u-aa-yes" || canonicalize("en-u-kn-yes")[0] !== "en-u-kn";
|
|
9820
|
+
return canonicalize("und-x-private")[0] !== "und-x-private" || canonicalize("en-u-aa-yes")[0] !== "en-u-aa-yes" || canonicalize("en-u-kn-yes")[0] !== "en-u-kn" || canonicalize("en-atom1")[0] !== "en-atom1";
|
|
9662
9821
|
} catch {
|
|
9663
9822
|
return true;
|
|
9664
9823
|
}
|
|
9665
9824
|
}
|
|
9666
9825
|
// node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/index.js
|
|
9826
|
+
const apply = Reflect.apply;
|
|
9827
|
+
const bind = Function.prototype.bind;
|
|
9828
|
+
const slice = Array.prototype.slice;
|
|
9829
|
+
const stringify = JSON.stringify;
|
|
9830
|
+
const create = Object.create;
|
|
9831
|
+
const defineProperty$1 = Object.defineProperty;
|
|
9832
|
+
const setPrototypeOf = Object.setPrototypeOf;
|
|
9667
9833
|
function memoize(fn, options) {
|
|
9668
9834
|
const cache = options && options.cache ? options.cache : cacheDefault;
|
|
9669
9835
|
const serializer = options && options.serializer ? options.serializer : serializerDefault;
|
|
@@ -9679,23 +9845,29 @@ function monadic(fn, cache, serializer, arg) {
|
|
|
9679
9845
|
const cacheKey = isPrimitive(arg) ? arg : serializer(arg);
|
|
9680
9846
|
let computedValue = cache.get(cacheKey);
|
|
9681
9847
|
if (typeof computedValue === "undefined") {
|
|
9682
|
-
computedValue = fn
|
|
9848
|
+
computedValue = apply(fn, this, [arg]);
|
|
9683
9849
|
cache.set(cacheKey, computedValue);
|
|
9684
9850
|
}
|
|
9685
9851
|
return computedValue;
|
|
9686
9852
|
}
|
|
9687
9853
|
function variadic(fn, cache, serializer) {
|
|
9688
|
-
const args =
|
|
9854
|
+
const args = apply(slice, arguments, [3]);
|
|
9855
|
+
if (serializer === serializerDefault) setPrototypeOf(args, null);
|
|
9689
9856
|
const cacheKey = serializer(args);
|
|
9690
9857
|
let computedValue = cache.get(cacheKey);
|
|
9691
9858
|
if (typeof computedValue === "undefined") {
|
|
9692
|
-
computedValue =
|
|
9859
|
+
computedValue = apply(fn, this, args);
|
|
9693
9860
|
cache.set(cacheKey, computedValue);
|
|
9694
9861
|
}
|
|
9695
9862
|
return computedValue;
|
|
9696
9863
|
}
|
|
9697
9864
|
function assemble(fn, context, strategy, cache, serialize) {
|
|
9698
|
-
return
|
|
9865
|
+
return apply(bind, strategy, [
|
|
9866
|
+
context,
|
|
9867
|
+
fn,
|
|
9868
|
+
cache,
|
|
9869
|
+
serialize
|
|
9870
|
+
]);
|
|
9699
9871
|
}
|
|
9700
9872
|
function strategyDefault(fn, options) {
|
|
9701
9873
|
const strategy = fn.length === 1 ? monadic : variadic;
|
|
@@ -9708,11 +9880,18 @@ function strategyMonadic(fn, options) {
|
|
|
9708
9880
|
return assemble(fn, this, monadic, options.cache.create(), options.serializer);
|
|
9709
9881
|
}
|
|
9710
9882
|
const serializerDefault = function() {
|
|
9711
|
-
|
|
9883
|
+
setPrototypeOf(arguments, null);
|
|
9884
|
+
return stringify(arguments);
|
|
9712
9885
|
};
|
|
9713
9886
|
var ObjectWithoutPrototypeCache = class {
|
|
9714
9887
|
constructor() {
|
|
9715
|
-
this
|
|
9888
|
+
defineProperty$1(this, "cache", {
|
|
9889
|
+
__proto__: null,
|
|
9890
|
+
value: create(null),
|
|
9891
|
+
writable: true,
|
|
9892
|
+
enumerable: true,
|
|
9893
|
+
configurable: true
|
|
9894
|
+
});
|
|
9716
9895
|
}
|
|
9717
9896
|
get(key) {
|
|
9718
9897
|
return this.cache[key];
|
|
@@ -9728,7 +9907,9 @@ const strategies = {
|
|
|
9728
9907
|
variadic: strategyVariadic,
|
|
9729
9908
|
monadic: strategyMonadic
|
|
9730
9909
|
};
|
|
9731
|
-
|
|
9910
|
+
String.prototype.repeat;
|
|
9911
|
+
Array.from;
|
|
9912
|
+
Array.prototype.join;
|
|
9732
9913
|
function defineProperty(target, name, { value }) {
|
|
9733
9914
|
Object.defineProperty(target, name, {
|
|
9734
9915
|
configurable: true,
|
|
@@ -9738,19 +9919,107 @@ function defineProperty(target, name, { value }) {
|
|
|
9738
9919
|
});
|
|
9739
9920
|
}
|
|
9740
9921
|
function ensureIntl() {
|
|
9741
|
-
if (typeof Intl === "undefined")
|
|
9742
|
-
|
|
9743
|
-
|
|
9744
|
-
|
|
9745
|
-
|
|
9746
|
-
|
|
9922
|
+
if (typeof Intl === "undefined") {
|
|
9923
|
+
const intl = {};
|
|
9924
|
+
if (typeof Symbol !== "undefined") Object.defineProperty(intl, Symbol.toStringTag, {
|
|
9925
|
+
value: "Intl",
|
|
9926
|
+
writable: false,
|
|
9927
|
+
enumerable: false,
|
|
9928
|
+
configurable: true
|
|
9929
|
+
});
|
|
9930
|
+
Object.defineProperty(globalThis, "Intl", {
|
|
9931
|
+
configurable: true,
|
|
9932
|
+
enumerable: false,
|
|
9933
|
+
writable: true,
|
|
9934
|
+
value: intl
|
|
9935
|
+
});
|
|
9936
|
+
}
|
|
9937
|
+
if (providerIntl === void 0) providerIntl = Intl;
|
|
9747
9938
|
return Intl;
|
|
9748
9939
|
}
|
|
9749
9940
|
memoize((...args) => new Intl.NumberFormat(...args), { strategy: strategies.variadic });
|
|
9750
|
-
memoize((...args) => new Intl.PluralRules(...args), { strategy: strategies.variadic });
|
|
9751
9941
|
memoize((...args) => new Intl.ListFormat(...args), { strategy: strategies.variadic });
|
|
9942
|
+
const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
9943
|
+
strategies.variadic;
|
|
9944
|
+
let providerIntl = globalThis.Intl;
|
|
9945
|
+
function ownIntlProvider(name) {
|
|
9946
|
+
const descriptor = providerIntl && getOwnPropertyDescriptor(providerIntl, name);
|
|
9947
|
+
return (descriptor && getOwnPropertyDescriptor(descriptor, "value"))?.value;
|
|
9948
|
+
}
|
|
9949
|
+
let numberFormatIntrinsic = ownIntlProvider("NumberFormat");
|
|
9950
|
+
let listFormatIntrinsic = ownIntlProvider("ListFormat");
|
|
9951
|
+
let pluralRulesProvider = ownIntlProvider("PluralRules");
|
|
9952
|
+
const getFormatterPrototype = Object.getPrototypeOf;
|
|
9953
|
+
function formatterMethodLookup(name) {
|
|
9954
|
+
const methods = /* @__PURE__ */ new WeakMap();
|
|
9955
|
+
const owners = /* @__PURE__ */ new WeakMap();
|
|
9956
|
+
const getMethod = methods.get.bind(methods);
|
|
9957
|
+
const setMethod = methods.set.bind(methods);
|
|
9958
|
+
const getOwner = owners.get.bind(owners);
|
|
9959
|
+
const setOwner = owners.set.bind(owners);
|
|
9960
|
+
return (Constructor) => {
|
|
9961
|
+
const cached = getMethod(Constructor);
|
|
9962
|
+
if (cached) return cached;
|
|
9963
|
+
let prototype = getOwnPropertyDescriptor(Constructor, "prototype")?.value;
|
|
9964
|
+
while (prototype != null) {
|
|
9965
|
+
const inherited = getOwner(prototype);
|
|
9966
|
+
if (inherited) {
|
|
9967
|
+
setMethod(Constructor, inherited);
|
|
9968
|
+
return inherited;
|
|
9969
|
+
}
|
|
9970
|
+
const descriptor = getOwnPropertyDescriptor(prototype, name);
|
|
9971
|
+
const value = descriptor && getOwnPropertyDescriptor(descriptor, "value");
|
|
9972
|
+
if (value && typeof value.value === "function") {
|
|
9973
|
+
const method = value.value;
|
|
9974
|
+
setMethod(Constructor, method);
|
|
9975
|
+
setOwner(prototype, method);
|
|
9976
|
+
return method;
|
|
9977
|
+
}
|
|
9978
|
+
prototype = getFormatterPrototype(prototype);
|
|
9979
|
+
}
|
|
9980
|
+
};
|
|
9981
|
+
}
|
|
9982
|
+
const findFormatterPartsMethod = formatterMethodLookup("formatToParts");
|
|
9983
|
+
const findPluralRulesSelectMethod = formatterMethodLookup("select");
|
|
9984
|
+
if (typeof numberFormatIntrinsic === "function") findFormatterPartsMethod(numberFormatIntrinsic);
|
|
9985
|
+
if (typeof listFormatIntrinsic === "function") findFormatterPartsMethod(listFormatIntrinsic);
|
|
9986
|
+
if (typeof pluralRulesProvider === "function") findPluralRulesSelectMethod(pluralRulesProvider);
|
|
9987
|
+
const numberFormatMemoizers = /* @__PURE__ */ new WeakMap();
|
|
9988
|
+
numberFormatMemoizers.get.bind(numberFormatMemoizers);
|
|
9989
|
+
numberFormatMemoizers.set.bind(numberFormatMemoizers);
|
|
9990
|
+
const listFormatMemoizers = /* @__PURE__ */ new WeakMap();
|
|
9991
|
+
listFormatMemoizers.get.bind(listFormatMemoizers);
|
|
9992
|
+
listFormatMemoizers.set.bind(listFormatMemoizers);
|
|
9993
|
+
const pluralRulesMemoizers = /* @__PURE__ */ new WeakMap();
|
|
9994
|
+
pluralRulesMemoizers.get.bind(pluralRulesMemoizers);
|
|
9995
|
+
pluralRulesMemoizers.set.bind(pluralRulesMemoizers);
|
|
9996
|
+
// packages/ecma402-abstract/CanonicalizeLocaleList.js
|
|
9997
|
+
let canonicalIntl = globalThis.Intl;
|
|
9998
|
+
const canonicalDescriptor = Object.getOwnPropertyDescriptor;
|
|
9999
|
+
const canonicalDefine = Object.defineProperty;
|
|
10000
|
+
const canonicalIsExtensible = Object.isExtensible;
|
|
10001
|
+
const providerKey = Symbol.for("@formatjs/intlCanonicalizeLocaleList");
|
|
10002
|
+
function ownCanonicalProvider() {
|
|
10003
|
+
const descriptor = canonicalIntl && canonicalDescriptor(canonicalIntl, "getCanonicalLocales");
|
|
10004
|
+
return (descriptor && canonicalDescriptor(descriptor, "value"))?.value;
|
|
10005
|
+
}
|
|
10006
|
+
ownCanonicalProvider();
|
|
10007
|
+
function registerCanonicalizeLocaleList(intl, provider) {
|
|
10008
|
+
if (canonicalIntl === void 0) canonicalIntl = intl;
|
|
10009
|
+
if (canonicalIntl === intl);
|
|
10010
|
+
try {
|
|
10011
|
+
if (canonicalDescriptor(intl, providerKey) || canonicalIsExtensible(intl)) canonicalDefine(intl, providerKey, {
|
|
10012
|
+
__proto__: null,
|
|
10013
|
+
configurable: true,
|
|
10014
|
+
value: provider
|
|
10015
|
+
});
|
|
10016
|
+
} catch {}
|
|
10017
|
+
}
|
|
9752
10018
|
// packages/intl-getcanonicallocales/polyfill.ts
|
|
9753
10019
|
const intl = ensureIntl();
|
|
9754
|
-
if (shouldPolyfill())
|
|
10020
|
+
if (shouldPolyfill()) {
|
|
10021
|
+
defineProperty(intl, "getCanonicalLocales", { value: getCanonicalLocales });
|
|
10022
|
+
registerCanonicalizeLocaleList(intl, getCanonicalLocales);
|
|
10023
|
+
}
|
|
9755
10024
|
|
|
9756
10025
|
//# sourceMappingURL=polyfill.js.map
|