@formatjs/intl-localematcher 0.7.4 → 0.8.0
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.js +1332 -1191
- 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 +3 -3
|
@@ -1,42 +1,44 @@
|
|
|
1
|
-
import { invariant } from
|
|
1
|
+
import { invariant } from "./utils.js";
|
|
2
2
|
export function UnicodeExtensionComponents(extension) {
|
|
3
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
3
|
+
invariant(extension === extension.toLowerCase(), "Expected extension to be lowercase");
|
|
4
|
+
invariant(extension.slice(0, 3) === "-u-", "Expected extension to be a Unicode locale extension");
|
|
5
|
+
const attributes = [];
|
|
6
|
+
const keywords = [];
|
|
7
|
+
let keyword;
|
|
8
|
+
let size = extension.length;
|
|
9
|
+
let k = 3;
|
|
10
|
+
while (k < size) {
|
|
11
|
+
let e = extension.indexOf("-", k);
|
|
12
|
+
let len;
|
|
13
|
+
if (e === -1) {
|
|
14
|
+
len = size - k;
|
|
15
|
+
} else {
|
|
16
|
+
len = e - k;
|
|
17
|
+
}
|
|
18
|
+
let subtag = extension.slice(k, k + len);
|
|
19
|
+
invariant(len >= 2, "Expected a subtag to have at least 2 characters");
|
|
20
|
+
if (keyword === undefined && len != 2) {
|
|
21
|
+
if (attributes.indexOf(subtag) === -1) {
|
|
22
|
+
attributes.push(subtag);
|
|
23
|
+
}
|
|
24
|
+
} else if (len === 2) {
|
|
25
|
+
keyword = {
|
|
26
|
+
key: subtag,
|
|
27
|
+
value: ""
|
|
28
|
+
};
|
|
29
|
+
if (keywords.find((k) => k.key === keyword?.key) === undefined) {
|
|
30
|
+
keywords.push(keyword);
|
|
31
|
+
}
|
|
32
|
+
} else if (keyword?.value === "") {
|
|
33
|
+
keyword.value = subtag;
|
|
34
|
+
} else {
|
|
35
|
+
invariant(keyword !== undefined, "Expected keyword to be defined");
|
|
36
|
+
keyword.value += "-" + subtag;
|
|
37
|
+
}
|
|
38
|
+
k += len + 1;
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
attributes,
|
|
42
|
+
keywords
|
|
43
|
+
};
|
|
42
44
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
* https://tc39.es/ecma402/#sec-unicodeextensionvalue
|
|
3
|
+
* @param extension
|
|
4
|
+
* @param key
|
|
5
|
+
*/
|
|
6
6
|
export declare function UnicodeExtensionValue(extension: string, key: string): string | undefined;
|
|
@@ -1,46 +1,43 @@
|
|
|
1
|
-
import { invariant } from
|
|
1
|
+
import { invariant } from "./utils.js";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
* https://tc39.es/ecma402/#sec-unicodeextensionvalue
|
|
4
|
+
* @param extension
|
|
5
|
+
* @param key
|
|
6
|
+
*/
|
|
7
7
|
export function UnicodeExtensionValue(extension, key) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
return '';
|
|
44
|
-
}
|
|
45
|
-
return undefined;
|
|
8
|
+
invariant(key.length === 2, "key must have 2 elements");
|
|
9
|
+
const size = extension.length;
|
|
10
|
+
let searchValue = `-${key}-`;
|
|
11
|
+
let pos = extension.indexOf(searchValue);
|
|
12
|
+
if (pos !== -1) {
|
|
13
|
+
const start = pos + 4;
|
|
14
|
+
let end = start;
|
|
15
|
+
let k = start;
|
|
16
|
+
let done = false;
|
|
17
|
+
while (!done) {
|
|
18
|
+
const e = extension.indexOf("-", k);
|
|
19
|
+
let len;
|
|
20
|
+
if (e === -1) {
|
|
21
|
+
len = size - k;
|
|
22
|
+
} else {
|
|
23
|
+
len = e - k;
|
|
24
|
+
}
|
|
25
|
+
if (len === 2) {
|
|
26
|
+
done = true;
|
|
27
|
+
} else if (e === -1) {
|
|
28
|
+
end = size;
|
|
29
|
+
done = true;
|
|
30
|
+
} else {
|
|
31
|
+
end = e;
|
|
32
|
+
k = e + 1;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return extension.slice(start, end);
|
|
36
|
+
}
|
|
37
|
+
searchValue = `-${key}`;
|
|
38
|
+
pos = extension.indexOf(searchValue);
|
|
39
|
+
if (pos !== -1 && pos + 3 === size) {
|
|
40
|
+
return "";
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
46
43
|
}
|