@formatjs/intl-localematcher 0.7.3 → 0.7.5
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/abstract/BestAvailableLocale.d.ts +4 -4
- package/abstract/BestAvailableLocale.js +25 -25
- package/abstract/BestFitMatcher.d.ts +6 -6
- package/abstract/BestFitMatcher.js +27 -28
- package/abstract/CanonicalizeLocaleList.d.ts +3 -3
- package/abstract/CanonicalizeLocaleList.js +4 -4
- package/abstract/CanonicalizeUValue.js +6 -6
- package/abstract/CanonicalizeUnicodeLocaleId.js +1 -1
- package/abstract/InsertUnicodeExtensionAndCanonicalize.d.ts +1 -1
- package/abstract/InsertUnicodeExtensionAndCanonicalize.js +27 -30
- package/abstract/LookupMatcher.d.ts +6 -6
- package/abstract/LookupMatcher.js +21 -22
- package/abstract/LookupSupportedLocales.d.ts +4 -4
- package/abstract/LookupSupportedLocales.js +15 -16
- package/abstract/ResolveLocale.d.ts +11 -10
- package/abstract/ResolveLocale.js +92 -97
- package/abstract/UnicodeExtensionComponents.d.ts +3 -3
- package/abstract/UnicodeExtensionComponents.js +42 -40
- package/abstract/UnicodeExtensionValue.d.ts +4 -4
- package/abstract/UnicodeExtensionValue.js +40 -43
- package/abstract/languageMatching.d.ts +2238 -2238
- package/abstract/languageMatching.js +1846 -2620
- package/abstract/regions.generated.d.ts +1 -0
- package/abstract/regions.generated.js +1332 -1332
- package/abstract/types.d.ts +5 -5
- package/abstract/utils.d.ts +37 -37
- package/abstract/utils.js +329 -359
- package/index.d.ts +3 -3
- package/index.js +5 -7
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
* https://tc39.es/ecma402/#sec-bestavailablelocale
|
|
3
|
+
* @param availableLocales
|
|
4
|
+
* @param locale
|
|
5
|
+
*/
|
|
6
6
|
export declare function BestAvailableLocale(availableLocales: readonly string[], locale: string): string | undefined;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
// Cache for Set conversions to avoid repeated array->Set conversions
|
|
2
|
-
|
|
2
|
+
const availableLocalesSetCache = new WeakMap();
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
* https://tc39.es/ecma402/#sec-bestavailablelocale
|
|
5
|
+
* @param availableLocales
|
|
6
|
+
* @param locale
|
|
7
|
+
*/
|
|
8
8
|
export function BestAvailableLocale(availableLocales, locale) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
9
|
+
// Fast path: use Set for O(1) lookups instead of O(n) indexOf
|
|
10
|
+
let availableSet = availableLocalesSetCache.get(availableLocales);
|
|
11
|
+
if (!availableSet) {
|
|
12
|
+
availableSet = new Set(availableLocales);
|
|
13
|
+
availableLocalesSetCache.set(availableLocales, availableSet);
|
|
14
|
+
}
|
|
15
|
+
let candidate = locale;
|
|
16
|
+
while (true) {
|
|
17
|
+
if (availableSet.has(candidate)) {
|
|
18
|
+
return candidate;
|
|
19
|
+
}
|
|
20
|
+
let pos = candidate.lastIndexOf("-");
|
|
21
|
+
if (!~pos) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
if (pos >= 2 && candidate[pos - 2] === "-") {
|
|
25
|
+
pos -= 2;
|
|
26
|
+
}
|
|
27
|
+
candidate = candidate.slice(0, pos);
|
|
28
|
+
}
|
|
29
29
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { LookupMatcherResult } from
|
|
1
|
+
import type { LookupMatcherResult } from "./types.js";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
* https://tc39.es/ecma402/#sec-bestfitmatcher
|
|
4
|
+
* @param availableLocales
|
|
5
|
+
* @param requestedLocales
|
|
6
|
+
* @param getDefaultLocale
|
|
7
|
+
*/
|
|
8
8
|
export declare function BestFitMatcher(availableLocales: readonly string[], requestedLocales: readonly string[], getDefaultLocale: () => string): LookupMatcherResult;
|
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
import { UNICODE_EXTENSION_SEQUENCE_REGEX, findBestMatch } from
|
|
1
|
+
import { UNICODE_EXTENSION_SEQUENCE_REGEX, findBestMatch } from "./utils.js";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
* https://tc39.es/ecma402/#sec-bestfitmatcher
|
|
4
|
+
* @param availableLocales
|
|
5
|
+
* @param requestedLocales
|
|
6
|
+
* @param getDefaultLocale
|
|
7
|
+
*/
|
|
8
8
|
export function BestFitMatcher(availableLocales, requestedLocales, getDefaultLocale) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
9
|
+
let foundLocale;
|
|
10
|
+
let extension;
|
|
11
|
+
const noExtensionLocales = [];
|
|
12
|
+
const noExtensionLocaleMap = requestedLocales.reduce((all, l) => {
|
|
13
|
+
const noExtensionLocale = l.replace(UNICODE_EXTENSION_SEQUENCE_REGEX, "");
|
|
14
|
+
noExtensionLocales.push(noExtensionLocale);
|
|
15
|
+
all[noExtensionLocale] = l;
|
|
16
|
+
return all;
|
|
17
|
+
}, {});
|
|
18
|
+
const result = findBestMatch(noExtensionLocales, availableLocales);
|
|
19
|
+
if (result.matchedSupportedLocale && result.matchedDesiredLocale) {
|
|
20
|
+
foundLocale = result.matchedSupportedLocale;
|
|
21
|
+
extension = noExtensionLocaleMap[result.matchedDesiredLocale].slice(result.matchedDesiredLocale.length) || undefined;
|
|
22
|
+
}
|
|
23
|
+
if (!foundLocale) {
|
|
24
|
+
return { locale: getDefaultLocale() };
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
locale: foundLocale,
|
|
28
|
+
extension
|
|
29
|
+
};
|
|
31
30
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
* http://ecma-international.org/ecma-402/7.0/index.html#sec-canonicalizelocalelist
|
|
3
|
+
* @param locales
|
|
4
|
+
*/
|
|
5
5
|
export declare function CanonicalizeLocaleList(locales?: string | readonly string[]): string[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
* http://ecma-international.org/ecma-402/7.0/index.html#sec-canonicalizelocalelist
|
|
3
|
+
* @param locales
|
|
4
|
+
*/
|
|
5
5
|
export function CanonicalizeLocaleList(locales) {
|
|
6
|
-
|
|
6
|
+
return Intl.getCanonicalLocales(locales);
|
|
7
7
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { invariant } from
|
|
1
|
+
import { invariant } from "./utils.js";
|
|
2
2
|
export function CanonicalizeUValue(ukey, uvalue) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
// TODO: Implement algorithm for CanonicalizeUValue per https://tc39.es/ecma402/#sec-canonicalizeuvalue
|
|
4
|
+
let lowerValue = uvalue.toLowerCase();
|
|
5
|
+
invariant(ukey !== undefined, `ukey must be defined`);
|
|
6
|
+
let canonicalized = lowerValue;
|
|
7
|
+
return canonicalized;
|
|
8
8
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Keyword } from
|
|
1
|
+
import type { Keyword } from "./types.js";
|
|
2
2
|
export declare function InsertUnicodeExtensionAndCanonicalize(locale: string, attributes: string[], keywords: Array<Keyword>): string;
|
|
@@ -1,32 +1,29 @@
|
|
|
1
|
-
import { CanonicalizeUnicodeLocaleId } from
|
|
2
|
-
import { invariant } from
|
|
1
|
+
import { CanonicalizeUnicodeLocaleId } from "./CanonicalizeUnicodeLocaleId.js";
|
|
2
|
+
import { invariant } from "./utils.js";
|
|
3
3
|
export function InsertUnicodeExtensionAndCanonicalize(locale, attributes, keywords) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
newLocale = preExtension + extension + postExtension;
|
|
30
|
-
}
|
|
31
|
-
return CanonicalizeUnicodeLocaleId(newLocale);
|
|
4
|
+
invariant(locale.indexOf("-u-") === -1, "Expected locale to not have a Unicode locale extension");
|
|
5
|
+
let extension = "-u";
|
|
6
|
+
for (const attr of attributes) {
|
|
7
|
+
extension += `-${attr}`;
|
|
8
|
+
}
|
|
9
|
+
for (const kw of keywords) {
|
|
10
|
+
const { key, value } = kw;
|
|
11
|
+
extension += `-${key}`;
|
|
12
|
+
if (value !== "") {
|
|
13
|
+
extension += `-${value}`;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (extension === "-u") {
|
|
17
|
+
return CanonicalizeUnicodeLocaleId(locale);
|
|
18
|
+
}
|
|
19
|
+
let privateIndex = locale.indexOf("-x-");
|
|
20
|
+
let newLocale;
|
|
21
|
+
if (privateIndex === -1) {
|
|
22
|
+
newLocale = locale + extension;
|
|
23
|
+
} else {
|
|
24
|
+
let preExtension = locale.slice(0, privateIndex);
|
|
25
|
+
let postExtension = locale.slice(privateIndex);
|
|
26
|
+
newLocale = preExtension + extension + postExtension;
|
|
27
|
+
}
|
|
28
|
+
return CanonicalizeUnicodeLocaleId(newLocale);
|
|
32
29
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { LookupMatcherResult } from
|
|
1
|
+
import type { LookupMatcherResult } from "./types.js";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
* https://tc39.es/ecma402/#sec-lookupmatcher
|
|
4
|
+
* @param availableLocales
|
|
5
|
+
* @param requestedLocales
|
|
6
|
+
* @param getDefaultLocale
|
|
7
|
+
*/
|
|
8
8
|
export declare function LookupMatcher(availableLocales: readonly string[], requestedLocales: readonly string[], getDefaultLocale: () => string): LookupMatcherResult;
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
import { BestAvailableLocale } from
|
|
2
|
-
import { UNICODE_EXTENSION_SEQUENCE_REGEX } from
|
|
1
|
+
import { BestAvailableLocale } from "./BestAvailableLocale.js";
|
|
2
|
+
import { UNICODE_EXTENSION_SEQUENCE_REGEX } from "./utils.js";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
* https://tc39.es/ecma402/#sec-lookupmatcher
|
|
5
|
+
* @param availableLocales
|
|
6
|
+
* @param requestedLocales
|
|
7
|
+
* @param getDefaultLocale
|
|
8
|
+
*/
|
|
9
9
|
export function LookupMatcher(availableLocales, requestedLocales, getDefaultLocale) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return result;
|
|
10
|
+
const result = { locale: "" };
|
|
11
|
+
for (const locale of requestedLocales) {
|
|
12
|
+
const noExtensionLocale = locale.replace(UNICODE_EXTENSION_SEQUENCE_REGEX, "");
|
|
13
|
+
const availableLocale = BestAvailableLocale(availableLocales, noExtensionLocale);
|
|
14
|
+
if (availableLocale) {
|
|
15
|
+
result.locale = availableLocale;
|
|
16
|
+
if (locale !== noExtensionLocale) {
|
|
17
|
+
result.extension = locale.slice(noExtensionLocale.length, locale.length);
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
result.locale = getDefaultLocale();
|
|
23
|
+
return result;
|
|
25
24
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
* https://tc39.es/ecma402/#sec-lookupsupportedlocales
|
|
3
|
+
* @param availableLocales
|
|
4
|
+
* @param requestedLocales
|
|
5
|
+
*/
|
|
6
6
|
export declare function LookupSupportedLocales(availableLocales: string[], requestedLocales: string[]): string[];
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import { BestAvailableLocale } from
|
|
2
|
-
import { UNICODE_EXTENSION_SEQUENCE_REGEX } from
|
|
1
|
+
import { BestAvailableLocale } from "./BestAvailableLocale.js";
|
|
2
|
+
import { UNICODE_EXTENSION_SEQUENCE_REGEX } from "./utils.js";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
* https://tc39.es/ecma402/#sec-lookupsupportedlocales
|
|
5
|
+
* @param availableLocales
|
|
6
|
+
* @param requestedLocales
|
|
7
|
+
*/
|
|
8
8
|
export function LookupSupportedLocales(availableLocales, requestedLocales) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return subset;
|
|
9
|
+
const subset = [];
|
|
10
|
+
for (const locale of requestedLocales) {
|
|
11
|
+
const noExtensionLocale = locale.replace(UNICODE_EXTENSION_SEQUENCE_REGEX, "");
|
|
12
|
+
const availableLocale = BestAvailableLocale(availableLocales, noExtensionLocale);
|
|
13
|
+
if (availableLocale) {
|
|
14
|
+
subset.push(availableLocale);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return subset;
|
|
19
18
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export interface ResolveLocaleResult {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
locale: string;
|
|
3
|
+
dataLocale: string;
|
|
4
|
+
[k: string]: any;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export declare function ResolveLocale<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
* https://tc39.es/ecma402/#sec-resolvelocale
|
|
8
|
+
*/
|
|
9
|
+
export declare function ResolveLocale<
|
|
10
|
+
K extends string,
|
|
11
|
+
D extends { [k in K] : any }
|
|
12
|
+
>(availableLocales: Set<string> | readonly string[], requestedLocales: readonly string[], options: {
|
|
13
|
+
localeMatcher: string;
|
|
14
|
+
[k: string]: string;
|
|
14
15
|
}, relevantExtensionKeys: K[], localeData: Record<string, D | undefined>, getDefaultLocale: () => string): ResolveLocaleResult;
|
|
@@ -1,100 +1,95 @@
|
|
|
1
|
-
import { BestFitMatcher } from
|
|
2
|
-
import { CanonicalizeUValue } from
|
|
3
|
-
import { InsertUnicodeExtensionAndCanonicalize } from
|
|
4
|
-
import { LookupMatcher } from
|
|
5
|
-
import { UnicodeExtensionComponents } from
|
|
6
|
-
import { invariant } from
|
|
1
|
+
import { BestFitMatcher } from "./BestFitMatcher.js";
|
|
2
|
+
import { CanonicalizeUValue } from "./CanonicalizeUValue.js";
|
|
3
|
+
import { InsertUnicodeExtensionAndCanonicalize } from "./InsertUnicodeExtensionAndCanonicalize.js";
|
|
4
|
+
import { LookupMatcher } from "./LookupMatcher.js";
|
|
5
|
+
import { UnicodeExtensionComponents } from "./UnicodeExtensionComponents.js";
|
|
6
|
+
import { invariant } from "./utils.js";
|
|
7
7
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
* https://tc39.es/ecma402/#sec-resolvelocale
|
|
9
|
+
*/
|
|
10
10
|
export function ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData, getDefaultLocale) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
supportedAttributes = [];
|
|
96
|
-
foundLocale = InsertUnicodeExtensionAndCanonicalize(foundLocale, supportedAttributes, supportedKeywords);
|
|
97
|
-
}
|
|
98
|
-
result.locale = foundLocale;
|
|
99
|
-
return result;
|
|
11
|
+
const matcher = options.localeMatcher;
|
|
12
|
+
let r;
|
|
13
|
+
if (matcher === "lookup") {
|
|
14
|
+
r = LookupMatcher(Array.from(availableLocales), requestedLocales, getDefaultLocale);
|
|
15
|
+
} else {
|
|
16
|
+
r = BestFitMatcher(Array.from(availableLocales), requestedLocales, getDefaultLocale);
|
|
17
|
+
}
|
|
18
|
+
if (r == null) {
|
|
19
|
+
r = {
|
|
20
|
+
locale: getDefaultLocale(),
|
|
21
|
+
extension: ""
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
let foundLocale = r.locale;
|
|
25
|
+
let foundLocaleData = localeData[foundLocale];
|
|
26
|
+
// TODO: We can't really guarantee that the locale data is available
|
|
27
|
+
// invariant(
|
|
28
|
+
// foundLocaleData !== undefined,
|
|
29
|
+
// `Missing locale data for ${foundLocale}`
|
|
30
|
+
// )
|
|
31
|
+
const result = {
|
|
32
|
+
locale: "en",
|
|
33
|
+
dataLocale: foundLocale
|
|
34
|
+
};
|
|
35
|
+
let components;
|
|
36
|
+
let keywords;
|
|
37
|
+
if (r.extension) {
|
|
38
|
+
components = UnicodeExtensionComponents(r.extension);
|
|
39
|
+
keywords = components.keywords;
|
|
40
|
+
} else {
|
|
41
|
+
keywords = [];
|
|
42
|
+
}
|
|
43
|
+
let supportedKeywords = [];
|
|
44
|
+
for (const key of relevantExtensionKeys) {
|
|
45
|
+
// TODO: Shouldn't default to empty array, see TODO above
|
|
46
|
+
let keyLocaleData = foundLocaleData?.[key] ?? [];
|
|
47
|
+
invariant(Array.isArray(keyLocaleData), `keyLocaleData for ${key} must be an array`);
|
|
48
|
+
let value = keyLocaleData[0];
|
|
49
|
+
invariant(value === undefined || typeof value === "string", `value must be a string or undefined`);
|
|
50
|
+
let supportedKeyword;
|
|
51
|
+
let entry = keywords.find((k) => k.key === key);
|
|
52
|
+
if (entry) {
|
|
53
|
+
let requestedValue = entry.value;
|
|
54
|
+
if (requestedValue !== "") {
|
|
55
|
+
if (keyLocaleData.indexOf(requestedValue) > -1) {
|
|
56
|
+
value = requestedValue;
|
|
57
|
+
supportedKeyword = {
|
|
58
|
+
key,
|
|
59
|
+
value
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
} else if (keyLocaleData.indexOf("true") > -1) {
|
|
63
|
+
value = "true";
|
|
64
|
+
supportedKeyword = {
|
|
65
|
+
key,
|
|
66
|
+
value
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
let optionsValue = options[key];
|
|
71
|
+
invariant(optionsValue == null || typeof optionsValue === "string", `optionsValue must be a string or undefined`);
|
|
72
|
+
if (typeof optionsValue === "string") {
|
|
73
|
+
let ukey = key.toLowerCase();
|
|
74
|
+
optionsValue = CanonicalizeUValue(ukey, optionsValue);
|
|
75
|
+
if (optionsValue === "") {
|
|
76
|
+
optionsValue = "true";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (optionsValue !== value && keyLocaleData.indexOf(optionsValue) > -1) {
|
|
80
|
+
value = optionsValue;
|
|
81
|
+
supportedKeyword = undefined;
|
|
82
|
+
}
|
|
83
|
+
if (supportedKeyword) {
|
|
84
|
+
supportedKeywords.push(supportedKeyword);
|
|
85
|
+
}
|
|
86
|
+
result[key] = value;
|
|
87
|
+
}
|
|
88
|
+
let supportedAttributes = [];
|
|
89
|
+
if (supportedKeywords.length > 0) {
|
|
90
|
+
supportedAttributes = [];
|
|
91
|
+
foundLocale = InsertUnicodeExtensionAndCanonicalize(foundLocale, supportedAttributes, supportedKeywords);
|
|
92
|
+
}
|
|
93
|
+
result.locale = foundLocale;
|
|
94
|
+
return result;
|
|
100
95
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Keyword } from
|
|
1
|
+
import type { Keyword } from "./types.js";
|
|
2
2
|
export declare function UnicodeExtensionComponents(extension: string): {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
attributes: string[];
|
|
4
|
+
keywords: Array<Keyword>;
|
|
5
5
|
};
|