@formatjs/intl-locale 3.0.1 → 3.0.4
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/BUILD +132 -0
- package/CHANGELOG.md +436 -0
- package/LICENSE.md +0 -0
- package/README.md +0 -0
- package/get_internal_slots.ts +15 -0
- package/index.ts +529 -0
- package/package.json +4 -4
- package/polyfill-force.ts +8 -0
- package/polyfill.ts +10 -0
- package/should-polyfill.ts +14 -0
- package/tests/index.test.ts +18 -0
- package/tests/likely-subtags.test.ts +108 -0
- package/tests/minimize.test.ts +35 -0
- package/tsconfig.json +5 -0
- package/get_internal_slots.d.ts +0 -3
- package/get_internal_slots.d.ts.map +0 -1
- package/get_internal_slots.js +0 -14
- package/index.d.ts +0 -49
- package/index.d.ts.map +0 -1
- package/index.js +0 -394
- package/lib/get_internal_slots.d.ts +0 -3
- package/lib/get_internal_slots.d.ts.map +0 -1
- package/lib/get_internal_slots.js +0 -11
- package/lib/index.d.ts +0 -49
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -391
- package/lib/polyfill-force.d.ts +0 -2
- package/lib/polyfill-force.d.ts.map +0 -1
- package/lib/polyfill-force.js +0 -7
- package/lib/polyfill.d.ts +0 -2
- package/lib/polyfill.d.ts.map +0 -1
- package/lib/polyfill.js +0 -10
- package/lib/should-polyfill.d.ts +0 -2
- package/lib/should-polyfill.d.ts.map +0 -1
- package/lib/should-polyfill.js +0 -14
- package/polyfill-force.d.ts +0 -2
- package/polyfill-force.d.ts.map +0 -1
- package/polyfill-force.js +0 -9
- package/polyfill.d.ts +0 -2
- package/polyfill.d.ts.map +0 -1
- package/polyfill.iife.js +0 -6468
- package/polyfill.js +0 -12
- package/should-polyfill.d.ts +0 -2
- package/should-polyfill.d.ts.map +0 -1
- package/should-polyfill.js +0 -18
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import '@formatjs/intl-getcanonicallocales/polyfill'
|
|
2
|
+
import {Locale} from '../'
|
|
3
|
+
const testDataMinimal: Record<string, string> = {
|
|
4
|
+
// Undefined primary language.
|
|
5
|
+
// und: 'en',
|
|
6
|
+
// 'und-Thai': 'th',
|
|
7
|
+
// 'und-419': 'es-419',
|
|
8
|
+
// 'und-150': 'ru-150',
|
|
9
|
+
// 'und-AT': 'de-AT',
|
|
10
|
+
|
|
11
|
+
// https://unicode-org.atlassian.net/browse/ICU-13786
|
|
12
|
+
'aae-Latn-IT': 'aae-Latn-IT',
|
|
13
|
+
'aae-Thai-CO': 'aae-Thai-CO',
|
|
14
|
+
|
|
15
|
+
// https://unicode-org.atlassian.net/browse/ICU-10220
|
|
16
|
+
// https://unicode-org.atlassian.net/browse/ICU-12345
|
|
17
|
+
// 'und-CW': 'pap-CW',
|
|
18
|
+
// 'und-US': 'en',
|
|
19
|
+
// 'zh-Hant': 'zh-TW',
|
|
20
|
+
'zh-Hani': 'zh-Hani',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('minimize', function () {
|
|
24
|
+
for (const tag in testDataMinimal) {
|
|
25
|
+
const minimal = testDataMinimal[tag]
|
|
26
|
+
it(`${minimal} is indeed minimal`, function () {
|
|
27
|
+
// Assert the |minimal| tag is indeed minimal.
|
|
28
|
+
expect(new Locale(minimal).minimize().toString()).toBe(minimal)
|
|
29
|
+
})
|
|
30
|
+
it(`${tag} -> ${minimal}`, function () {
|
|
31
|
+
// Assert RemoveLikelySubtags(tag) returns |minimal|.
|
|
32
|
+
expect(new Locale(tag).minimize().toString()).toBe(minimal)
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
})
|
package/tsconfig.json
ADDED
package/get_internal_slots.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get_internal_slots.d.ts","sourceRoot":"","sources":["../../../../../packages/intl-locale/get_internal_slots.ts"],"names":[],"mappings":"AAGA,OAAO,MAAM,EAAE,EAAC,kBAAkB,EAAC,MAAM,GAAG,CAAA;AAI5C,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAOtE"}
|
package/get_internal_slots.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Type-only circular import
|
|
3
|
-
// eslint-disable-next-line import/no-cycle
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
var internalSlotMap = new WeakMap();
|
|
6
|
-
function getInternalSlots(x) {
|
|
7
|
-
var internalSlots = internalSlotMap.get(x);
|
|
8
|
-
if (!internalSlots) {
|
|
9
|
-
internalSlots = Object.create(null);
|
|
10
|
-
internalSlotMap.set(x, internalSlots);
|
|
11
|
-
}
|
|
12
|
-
return internalSlots;
|
|
13
|
-
}
|
|
14
|
-
exports.default = getInternalSlots;
|
package/index.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export interface IntlLocaleOptions {
|
|
2
|
-
language?: string;
|
|
3
|
-
script?: string;
|
|
4
|
-
region?: string;
|
|
5
|
-
calendar?: string;
|
|
6
|
-
collation?: string;
|
|
7
|
-
hourCycle?: 'h11' | 'h12' | 'h23' | 'h24';
|
|
8
|
-
caseFirst?: 'upper' | 'lower' | 'false';
|
|
9
|
-
numberingSystem?: string;
|
|
10
|
-
numeric?: boolean;
|
|
11
|
-
}
|
|
12
|
-
export interface IntlLocaleInternal extends IntlLocaleOptions {
|
|
13
|
-
locale: string;
|
|
14
|
-
initializedLocale: boolean;
|
|
15
|
-
}
|
|
16
|
-
export declare class Locale {
|
|
17
|
-
constructor(tag: string | Locale, opts?: IntlLocaleOptions);
|
|
18
|
-
/**
|
|
19
|
-
* https://www.unicode.org/reports/tr35/#Likely_Subtags
|
|
20
|
-
*/
|
|
21
|
-
maximize(): Locale;
|
|
22
|
-
/**
|
|
23
|
-
* https://www.unicode.org/reports/tr35/#Likely_Subtags
|
|
24
|
-
*/
|
|
25
|
-
minimize(): Locale;
|
|
26
|
-
toString(): string;
|
|
27
|
-
get baseName(): string;
|
|
28
|
-
get calendar(): string | undefined;
|
|
29
|
-
get collation(): string | undefined;
|
|
30
|
-
get hourCycle(): "h11" | "h12" | "h23" | "h24" | undefined;
|
|
31
|
-
get caseFirst(): "upper" | "lower" | "false" | undefined;
|
|
32
|
-
get numeric(): boolean | undefined;
|
|
33
|
-
get numberingSystem(): string | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.language
|
|
36
|
-
*/
|
|
37
|
-
get language(): string;
|
|
38
|
-
/**
|
|
39
|
-
* https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.script
|
|
40
|
-
*/
|
|
41
|
-
get script(): string | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.region
|
|
44
|
-
*/
|
|
45
|
-
get region(): string | undefined;
|
|
46
|
-
static relevantExtensionKeys: readonly ["ca", "co", "hc", "kf", "kn", "nu"];
|
|
47
|
-
}
|
|
48
|
-
export default Locale;
|
|
49
|
-
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/intl-locale/index.ts"],"names":[],"mappings":"AAsBA,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAA;IACzC,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAA;IACvC,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAMD,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB,EAAE,OAAO,CAAA;CAC3B;AA6PD,qBAAa,MAAM;gBACL,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB;IAmI1D;;OAEG;IACI,QAAQ,IAAI,MAAM;IAUzB;;OAEG;IACI,QAAQ,IAAI,MAAM;IAUlB,QAAQ;IAIf,IAAW,QAAQ,WAGlB;IAED,IAAW,QAAQ,uBAElB;IAED,IAAW,SAAS,uBAEnB;IAED,IAAW,SAAS,8CAEnB;IAED,IAAW,SAAS,4CAEnB;IAED,IAAW,OAAO,wBAEjB;IACD,IAAW,eAAe,uBAEzB;IACD;;OAEG;IACH,IAAW,QAAQ,WAGlB;IACD;;OAEG;IACH,IAAW,MAAM,uBAGhB;IACD;;OAEG;IACH,IAAW,MAAM,uBAGhB;IAED,MAAM,CAAC,qBAAqB,gDAA0B;CACvD;AAsBD,eAAe,MAAM,CAAA"}
|
package/index.js
DELETED
|
@@ -1,394 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Locale = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
6
|
-
var intl_getcanonicallocales_1 = require("@formatjs/intl-getcanonicallocales");
|
|
7
|
-
var get_internal_slots_1 = (0, tslib_1.__importDefault)(require("./get_internal_slots"));
|
|
8
|
-
var RELEVANT_EXTENSION_KEYS = ['ca', 'co', 'hc', 'kf', 'kn', 'nu'];
|
|
9
|
-
var UNICODE_TYPE_REGEX = /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*$/i;
|
|
10
|
-
function applyOptionsToTag(tag, options) {
|
|
11
|
-
(0, ecma402_abstract_1.invariant)(typeof tag === 'string', 'language tag must be a string');
|
|
12
|
-
(0, ecma402_abstract_1.invariant)((0, intl_getcanonicallocales_1.isStructurallyValidLanguageTag)(tag), 'malformed language tag', RangeError);
|
|
13
|
-
var language = (0, ecma402_abstract_1.GetOption)(options, 'language', 'string', undefined, undefined);
|
|
14
|
-
if (language !== undefined) {
|
|
15
|
-
(0, ecma402_abstract_1.invariant)((0, intl_getcanonicallocales_1.isUnicodeLanguageSubtag)(language), 'Malformed unicode_language_subtag', RangeError);
|
|
16
|
-
}
|
|
17
|
-
var script = (0, ecma402_abstract_1.GetOption)(options, 'script', 'string', undefined, undefined);
|
|
18
|
-
if (script !== undefined) {
|
|
19
|
-
(0, ecma402_abstract_1.invariant)((0, intl_getcanonicallocales_1.isUnicodeScriptSubtag)(script), 'Malformed unicode_script_subtag', RangeError);
|
|
20
|
-
}
|
|
21
|
-
var region = (0, ecma402_abstract_1.GetOption)(options, 'region', 'string', undefined, undefined);
|
|
22
|
-
if (region !== undefined) {
|
|
23
|
-
(0, ecma402_abstract_1.invariant)((0, intl_getcanonicallocales_1.isUnicodeRegionSubtag)(region), 'Malformed unicode_region_subtag', RangeError);
|
|
24
|
-
}
|
|
25
|
-
var languageId = (0, intl_getcanonicallocales_1.parseUnicodeLanguageId)(tag);
|
|
26
|
-
if (language !== undefined) {
|
|
27
|
-
languageId.lang = language;
|
|
28
|
-
}
|
|
29
|
-
if (script !== undefined) {
|
|
30
|
-
languageId.script = script;
|
|
31
|
-
}
|
|
32
|
-
if (region !== undefined) {
|
|
33
|
-
languageId.region = region;
|
|
34
|
-
}
|
|
35
|
-
return Intl.getCanonicalLocales((0, intl_getcanonicallocales_1.emitUnicodeLocaleId)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, (0, intl_getcanonicallocales_1.parseUnicodeLocaleId)(tag)), { lang: languageId })))[0];
|
|
36
|
-
}
|
|
37
|
-
function applyUnicodeExtensionToTag(tag, options, relevantExtensionKeys) {
|
|
38
|
-
var unicodeExtension;
|
|
39
|
-
var keywords = [];
|
|
40
|
-
var ast = (0, intl_getcanonicallocales_1.parseUnicodeLocaleId)(tag);
|
|
41
|
-
for (var _i = 0, _a = ast.extensions; _i < _a.length; _i++) {
|
|
42
|
-
var ext = _a[_i];
|
|
43
|
-
if (ext.type === 'u') {
|
|
44
|
-
unicodeExtension = ext;
|
|
45
|
-
if (Array.isArray(ext.keywords))
|
|
46
|
-
keywords = ext.keywords;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
var result = Object.create(null);
|
|
50
|
-
for (var _b = 0, relevantExtensionKeys_1 = relevantExtensionKeys; _b < relevantExtensionKeys_1.length; _b++) {
|
|
51
|
-
var key = relevantExtensionKeys_1[_b];
|
|
52
|
-
var value = void 0, entry = void 0;
|
|
53
|
-
for (var _c = 0, keywords_1 = keywords; _c < keywords_1.length; _c++) {
|
|
54
|
-
var keyword = keywords_1[_c];
|
|
55
|
-
if (keyword[0] === key) {
|
|
56
|
-
entry = keyword;
|
|
57
|
-
value = entry[1];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
(0, ecma402_abstract_1.invariant)(key in options, "".concat(key, " must be in options"));
|
|
61
|
-
var optionsValue = options[key];
|
|
62
|
-
if (optionsValue !== undefined) {
|
|
63
|
-
(0, ecma402_abstract_1.invariant)(typeof optionsValue === 'string', "Value for ".concat(key, " must be a string"));
|
|
64
|
-
value = optionsValue;
|
|
65
|
-
if (entry) {
|
|
66
|
-
entry[1] = value;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
keywords.push([key, value]);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
result[key] = value;
|
|
73
|
-
}
|
|
74
|
-
if (!unicodeExtension) {
|
|
75
|
-
if (keywords.length) {
|
|
76
|
-
ast.extensions.push({
|
|
77
|
-
type: 'u',
|
|
78
|
-
keywords: keywords,
|
|
79
|
-
attributes: [],
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
unicodeExtension.keywords = keywords;
|
|
85
|
-
}
|
|
86
|
-
result.locale = Intl.getCanonicalLocales((0, intl_getcanonicallocales_1.emitUnicodeLocaleId)(ast))[0];
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
function mergeUnicodeLanguageId(lang, script, region, variants, replacement) {
|
|
90
|
-
if (variants === void 0) { variants = []; }
|
|
91
|
-
if (!replacement) {
|
|
92
|
-
return {
|
|
93
|
-
lang: lang || 'und',
|
|
94
|
-
script: script,
|
|
95
|
-
region: region,
|
|
96
|
-
variants: variants,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
lang: !lang || lang === 'und' ? replacement.lang : lang,
|
|
101
|
-
script: script || replacement.script,
|
|
102
|
-
region: region || replacement.region,
|
|
103
|
-
variants: (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], variants, true), replacement.variants, true),
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
function addLikelySubtags(tag) {
|
|
107
|
-
var ast = (0, intl_getcanonicallocales_1.parseUnicodeLocaleId)(tag);
|
|
108
|
-
var unicodeLangId = ast.lang;
|
|
109
|
-
var lang = unicodeLangId.lang, script = unicodeLangId.script, region = unicodeLangId.region, variants = unicodeLangId.variants;
|
|
110
|
-
if (script && region) {
|
|
111
|
-
var match_1 = intl_getcanonicallocales_1.likelySubtags[(0, intl_getcanonicallocales_1.emitUnicodeLanguageId)({ lang: lang, script: script, region: region, variants: [] })];
|
|
112
|
-
if (match_1) {
|
|
113
|
-
var parts_1 = (0, intl_getcanonicallocales_1.parseUnicodeLanguageId)(match_1);
|
|
114
|
-
ast.lang = mergeUnicodeLanguageId(undefined, undefined, undefined, variants, parts_1);
|
|
115
|
-
return (0, intl_getcanonicallocales_1.emitUnicodeLocaleId)(ast);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (script) {
|
|
119
|
-
var match_2 = intl_getcanonicallocales_1.likelySubtags[(0, intl_getcanonicallocales_1.emitUnicodeLanguageId)({ lang: lang, script: script, variants: [] })];
|
|
120
|
-
if (match_2) {
|
|
121
|
-
var parts_2 = (0, intl_getcanonicallocales_1.parseUnicodeLanguageId)(match_2);
|
|
122
|
-
ast.lang = mergeUnicodeLanguageId(undefined, undefined, region, variants, parts_2);
|
|
123
|
-
return (0, intl_getcanonicallocales_1.emitUnicodeLocaleId)(ast);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (region) {
|
|
127
|
-
var match_3 = intl_getcanonicallocales_1.likelySubtags[(0, intl_getcanonicallocales_1.emitUnicodeLanguageId)({ lang: lang, region: region, variants: [] })];
|
|
128
|
-
if (match_3) {
|
|
129
|
-
var parts_3 = (0, intl_getcanonicallocales_1.parseUnicodeLanguageId)(match_3);
|
|
130
|
-
ast.lang = mergeUnicodeLanguageId(undefined, script, undefined, variants, parts_3);
|
|
131
|
-
return (0, intl_getcanonicallocales_1.emitUnicodeLocaleId)(ast);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
var match = intl_getcanonicallocales_1.likelySubtags[lang] ||
|
|
135
|
-
intl_getcanonicallocales_1.likelySubtags[(0, intl_getcanonicallocales_1.emitUnicodeLanguageId)({ lang: 'und', script: script, variants: [] })];
|
|
136
|
-
if (!match) {
|
|
137
|
-
throw new Error("No match for addLikelySubtags");
|
|
138
|
-
}
|
|
139
|
-
var parts = (0, intl_getcanonicallocales_1.parseUnicodeLanguageId)(match);
|
|
140
|
-
ast.lang = mergeUnicodeLanguageId(undefined, script, region, variants, parts);
|
|
141
|
-
return (0, intl_getcanonicallocales_1.emitUnicodeLocaleId)(ast);
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* From: https://github.com/unicode-org/icu/blob/4231ca5be053a22a1be24eb891817458c97db709/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java#L2395
|
|
145
|
-
* @param tag
|
|
146
|
-
*/
|
|
147
|
-
function removeLikelySubtags(tag) {
|
|
148
|
-
var maxLocale = addLikelySubtags(tag);
|
|
149
|
-
if (!maxLocale) {
|
|
150
|
-
return tag;
|
|
151
|
-
}
|
|
152
|
-
maxLocale = (0, intl_getcanonicallocales_1.emitUnicodeLanguageId)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, (0, intl_getcanonicallocales_1.parseUnicodeLanguageId)(maxLocale)), { variants: [] }));
|
|
153
|
-
var ast = (0, intl_getcanonicallocales_1.parseUnicodeLocaleId)(tag);
|
|
154
|
-
var _a = ast.lang, lang = _a.lang, script = _a.script, region = _a.region, variants = _a.variants;
|
|
155
|
-
var trial = addLikelySubtags((0, intl_getcanonicallocales_1.emitUnicodeLanguageId)({ lang: lang, variants: [] }));
|
|
156
|
-
if (trial === maxLocale) {
|
|
157
|
-
return (0, intl_getcanonicallocales_1.emitUnicodeLocaleId)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, ast), { lang: mergeUnicodeLanguageId(lang, undefined, undefined, variants) }));
|
|
158
|
-
}
|
|
159
|
-
if (region) {
|
|
160
|
-
var trial_1 = addLikelySubtags((0, intl_getcanonicallocales_1.emitUnicodeLanguageId)({ lang: lang, region: region, variants: [] }));
|
|
161
|
-
if (trial_1 === maxLocale) {
|
|
162
|
-
return (0, intl_getcanonicallocales_1.emitUnicodeLocaleId)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, ast), { lang: mergeUnicodeLanguageId(lang, undefined, region, variants) }));
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (script) {
|
|
166
|
-
var trial_2 = addLikelySubtags((0, intl_getcanonicallocales_1.emitUnicodeLanguageId)({ lang: lang, script: script, variants: [] }));
|
|
167
|
-
if (trial_2 === maxLocale) {
|
|
168
|
-
return (0, intl_getcanonicallocales_1.emitUnicodeLocaleId)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, ast), { lang: mergeUnicodeLanguageId(lang, script, undefined, variants) }));
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return tag;
|
|
172
|
-
}
|
|
173
|
-
var Locale = /** @class */ (function () {
|
|
174
|
-
function Locale(tag, opts) {
|
|
175
|
-
// test262/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js
|
|
176
|
-
// Cannot use `new.target` bc of IE11 & TS transpiles it to something else
|
|
177
|
-
var newTarget = this && this instanceof Locale ? this.constructor : void 0;
|
|
178
|
-
if (!newTarget) {
|
|
179
|
-
throw new TypeError("Intl.Locale must be called with 'new'");
|
|
180
|
-
}
|
|
181
|
-
var relevantExtensionKeys = Locale.relevantExtensionKeys;
|
|
182
|
-
var internalSlotsList = [
|
|
183
|
-
'initializedLocale',
|
|
184
|
-
'locale',
|
|
185
|
-
'calendar',
|
|
186
|
-
'collation',
|
|
187
|
-
'hourCycle',
|
|
188
|
-
'numberingSystem',
|
|
189
|
-
];
|
|
190
|
-
if (relevantExtensionKeys.indexOf('kf') > -1) {
|
|
191
|
-
internalSlotsList.push('caseFirst');
|
|
192
|
-
}
|
|
193
|
-
if (relevantExtensionKeys.indexOf('kn') > -1) {
|
|
194
|
-
internalSlotsList.push('numeric');
|
|
195
|
-
}
|
|
196
|
-
if (tag === undefined) {
|
|
197
|
-
throw new TypeError("First argument to Intl.Locale constructor can't be empty or missing");
|
|
198
|
-
}
|
|
199
|
-
if (typeof tag !== 'string' && typeof tag !== 'object') {
|
|
200
|
-
throw new TypeError('tag must be a string or object');
|
|
201
|
-
}
|
|
202
|
-
var internalSlots;
|
|
203
|
-
if (typeof tag === 'object' &&
|
|
204
|
-
(internalSlots = (0, get_internal_slots_1.default)(tag)) &&
|
|
205
|
-
internalSlots.initializedLocale) {
|
|
206
|
-
tag = internalSlots.locale;
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
tag = tag.toString();
|
|
210
|
-
}
|
|
211
|
-
internalSlots = (0, get_internal_slots_1.default)(this);
|
|
212
|
-
var options = (0, ecma402_abstract_1.CoerceOptionsToObject)(opts);
|
|
213
|
-
tag = applyOptionsToTag(tag, options);
|
|
214
|
-
var opt = Object.create(null);
|
|
215
|
-
var calendar = (0, ecma402_abstract_1.GetOption)(options, 'calendar', 'string', undefined, undefined);
|
|
216
|
-
if (calendar !== undefined) {
|
|
217
|
-
if (!UNICODE_TYPE_REGEX.test(calendar)) {
|
|
218
|
-
throw new RangeError('invalid calendar');
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
opt.ca = calendar;
|
|
222
|
-
var collation = (0, ecma402_abstract_1.GetOption)(options, 'collation', 'string', undefined, undefined);
|
|
223
|
-
if (collation !== undefined) {
|
|
224
|
-
if (!UNICODE_TYPE_REGEX.test(collation)) {
|
|
225
|
-
throw new RangeError('invalid collation');
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
opt.co = collation;
|
|
229
|
-
var hc = (0, ecma402_abstract_1.GetOption)(options, 'hourCycle', 'string', ['h11', 'h12', 'h23', 'h24'], undefined);
|
|
230
|
-
opt.hc = hc;
|
|
231
|
-
var kf = (0, ecma402_abstract_1.GetOption)(options, 'caseFirst', 'string', ['upper', 'lower', 'false'], undefined);
|
|
232
|
-
opt.kf = kf;
|
|
233
|
-
var _kn = (0, ecma402_abstract_1.GetOption)(options, 'numeric', 'boolean', undefined, undefined);
|
|
234
|
-
var kn;
|
|
235
|
-
if (_kn !== undefined) {
|
|
236
|
-
kn = String(_kn);
|
|
237
|
-
}
|
|
238
|
-
opt.kn = kn;
|
|
239
|
-
var numberingSystem = (0, ecma402_abstract_1.GetOption)(options, 'numberingSystem', 'string', undefined, undefined);
|
|
240
|
-
if (numberingSystem !== undefined) {
|
|
241
|
-
if (!UNICODE_TYPE_REGEX.test(numberingSystem)) {
|
|
242
|
-
throw new RangeError('Invalid numberingSystem');
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
opt.nu = numberingSystem;
|
|
246
|
-
var r = applyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys);
|
|
247
|
-
internalSlots.locale = r.locale;
|
|
248
|
-
internalSlots.calendar = r.ca;
|
|
249
|
-
internalSlots.collation = r.co;
|
|
250
|
-
internalSlots.hourCycle = r.hc;
|
|
251
|
-
if (relevantExtensionKeys.indexOf('kf') > -1) {
|
|
252
|
-
internalSlots.caseFirst = r.kf;
|
|
253
|
-
}
|
|
254
|
-
if (relevantExtensionKeys.indexOf('kn') > -1) {
|
|
255
|
-
internalSlots.numeric = (0, ecma402_abstract_1.SameValue)(r.kn, 'true');
|
|
256
|
-
}
|
|
257
|
-
internalSlots.numberingSystem = r.nu;
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* https://www.unicode.org/reports/tr35/#Likely_Subtags
|
|
261
|
-
*/
|
|
262
|
-
Locale.prototype.maximize = function () {
|
|
263
|
-
var locale = (0, get_internal_slots_1.default)(this).locale;
|
|
264
|
-
try {
|
|
265
|
-
var maximizedLocale = addLikelySubtags(locale);
|
|
266
|
-
return new Locale(maximizedLocale);
|
|
267
|
-
}
|
|
268
|
-
catch (e) {
|
|
269
|
-
return new Locale(locale);
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
/**
|
|
273
|
-
* https://www.unicode.org/reports/tr35/#Likely_Subtags
|
|
274
|
-
*/
|
|
275
|
-
Locale.prototype.minimize = function () {
|
|
276
|
-
var locale = (0, get_internal_slots_1.default)(this).locale;
|
|
277
|
-
try {
|
|
278
|
-
var minimizedLocale = removeLikelySubtags(locale);
|
|
279
|
-
return new Locale(minimizedLocale);
|
|
280
|
-
}
|
|
281
|
-
catch (e) {
|
|
282
|
-
return new Locale(locale);
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
Locale.prototype.toString = function () {
|
|
286
|
-
return (0, get_internal_slots_1.default)(this).locale;
|
|
287
|
-
};
|
|
288
|
-
Object.defineProperty(Locale.prototype, "baseName", {
|
|
289
|
-
get: function () {
|
|
290
|
-
var locale = (0, get_internal_slots_1.default)(this).locale;
|
|
291
|
-
return (0, intl_getcanonicallocales_1.emitUnicodeLanguageId)((0, intl_getcanonicallocales_1.parseUnicodeLanguageId)(locale));
|
|
292
|
-
},
|
|
293
|
-
enumerable: false,
|
|
294
|
-
configurable: true
|
|
295
|
-
});
|
|
296
|
-
Object.defineProperty(Locale.prototype, "calendar", {
|
|
297
|
-
get: function () {
|
|
298
|
-
return (0, get_internal_slots_1.default)(this).calendar;
|
|
299
|
-
},
|
|
300
|
-
enumerable: false,
|
|
301
|
-
configurable: true
|
|
302
|
-
});
|
|
303
|
-
Object.defineProperty(Locale.prototype, "collation", {
|
|
304
|
-
get: function () {
|
|
305
|
-
return (0, get_internal_slots_1.default)(this).collation;
|
|
306
|
-
},
|
|
307
|
-
enumerable: false,
|
|
308
|
-
configurable: true
|
|
309
|
-
});
|
|
310
|
-
Object.defineProperty(Locale.prototype, "hourCycle", {
|
|
311
|
-
get: function () {
|
|
312
|
-
return (0, get_internal_slots_1.default)(this).hourCycle;
|
|
313
|
-
},
|
|
314
|
-
enumerable: false,
|
|
315
|
-
configurable: true
|
|
316
|
-
});
|
|
317
|
-
Object.defineProperty(Locale.prototype, "caseFirst", {
|
|
318
|
-
get: function () {
|
|
319
|
-
return (0, get_internal_slots_1.default)(this).caseFirst;
|
|
320
|
-
},
|
|
321
|
-
enumerable: false,
|
|
322
|
-
configurable: true
|
|
323
|
-
});
|
|
324
|
-
Object.defineProperty(Locale.prototype, "numeric", {
|
|
325
|
-
get: function () {
|
|
326
|
-
return (0, get_internal_slots_1.default)(this).numeric;
|
|
327
|
-
},
|
|
328
|
-
enumerable: false,
|
|
329
|
-
configurable: true
|
|
330
|
-
});
|
|
331
|
-
Object.defineProperty(Locale.prototype, "numberingSystem", {
|
|
332
|
-
get: function () {
|
|
333
|
-
return (0, get_internal_slots_1.default)(this).numberingSystem;
|
|
334
|
-
},
|
|
335
|
-
enumerable: false,
|
|
336
|
-
configurable: true
|
|
337
|
-
});
|
|
338
|
-
Object.defineProperty(Locale.prototype, "language", {
|
|
339
|
-
/**
|
|
340
|
-
* https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.language
|
|
341
|
-
*/
|
|
342
|
-
get: function () {
|
|
343
|
-
var locale = (0, get_internal_slots_1.default)(this).locale;
|
|
344
|
-
return (0, intl_getcanonicallocales_1.parseUnicodeLanguageId)(locale).lang;
|
|
345
|
-
},
|
|
346
|
-
enumerable: false,
|
|
347
|
-
configurable: true
|
|
348
|
-
});
|
|
349
|
-
Object.defineProperty(Locale.prototype, "script", {
|
|
350
|
-
/**
|
|
351
|
-
* https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.script
|
|
352
|
-
*/
|
|
353
|
-
get: function () {
|
|
354
|
-
var locale = (0, get_internal_slots_1.default)(this).locale;
|
|
355
|
-
return (0, intl_getcanonicallocales_1.parseUnicodeLanguageId)(locale).script;
|
|
356
|
-
},
|
|
357
|
-
enumerable: false,
|
|
358
|
-
configurable: true
|
|
359
|
-
});
|
|
360
|
-
Object.defineProperty(Locale.prototype, "region", {
|
|
361
|
-
/**
|
|
362
|
-
* https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.region
|
|
363
|
-
*/
|
|
364
|
-
get: function () {
|
|
365
|
-
var locale = (0, get_internal_slots_1.default)(this).locale;
|
|
366
|
-
return (0, intl_getcanonicallocales_1.parseUnicodeLanguageId)(locale).region;
|
|
367
|
-
},
|
|
368
|
-
enumerable: false,
|
|
369
|
-
configurable: true
|
|
370
|
-
});
|
|
371
|
-
Locale.relevantExtensionKeys = RELEVANT_EXTENSION_KEYS;
|
|
372
|
-
return Locale;
|
|
373
|
-
}());
|
|
374
|
-
exports.Locale = Locale;
|
|
375
|
-
try {
|
|
376
|
-
if (typeof Symbol !== 'undefined') {
|
|
377
|
-
Object.defineProperty(Locale.prototype, Symbol.toStringTag, {
|
|
378
|
-
value: 'Intl.Locale',
|
|
379
|
-
writable: false,
|
|
380
|
-
enumerable: false,
|
|
381
|
-
configurable: true,
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
Object.defineProperty(Locale.prototype.constructor, 'length', {
|
|
385
|
-
value: 1,
|
|
386
|
-
writable: false,
|
|
387
|
-
enumerable: false,
|
|
388
|
-
configurable: true,
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
catch (e) {
|
|
392
|
-
// Meta fix so we're test262-compliant, not important
|
|
393
|
-
}
|
|
394
|
-
exports.default = Locale;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get_internal_slots.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl-locale/get_internal_slots.ts"],"names":[],"mappings":"AAGA,OAAO,MAAM,EAAE,EAAC,kBAAkB,EAAC,MAAM,GAAG,CAAA;AAI5C,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAOtE"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Type-only circular import
|
|
2
|
-
// eslint-disable-next-line import/no-cycle
|
|
3
|
-
var internalSlotMap = new WeakMap();
|
|
4
|
-
export default function getInternalSlots(x) {
|
|
5
|
-
var internalSlots = internalSlotMap.get(x);
|
|
6
|
-
if (!internalSlots) {
|
|
7
|
-
internalSlots = Object.create(null);
|
|
8
|
-
internalSlotMap.set(x, internalSlots);
|
|
9
|
-
}
|
|
10
|
-
return internalSlots;
|
|
11
|
-
}
|
package/lib/index.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export interface IntlLocaleOptions {
|
|
2
|
-
language?: string;
|
|
3
|
-
script?: string;
|
|
4
|
-
region?: string;
|
|
5
|
-
calendar?: string;
|
|
6
|
-
collation?: string;
|
|
7
|
-
hourCycle?: 'h11' | 'h12' | 'h23' | 'h24';
|
|
8
|
-
caseFirst?: 'upper' | 'lower' | 'false';
|
|
9
|
-
numberingSystem?: string;
|
|
10
|
-
numeric?: boolean;
|
|
11
|
-
}
|
|
12
|
-
export interface IntlLocaleInternal extends IntlLocaleOptions {
|
|
13
|
-
locale: string;
|
|
14
|
-
initializedLocale: boolean;
|
|
15
|
-
}
|
|
16
|
-
export declare class Locale {
|
|
17
|
-
constructor(tag: string | Locale, opts?: IntlLocaleOptions);
|
|
18
|
-
/**
|
|
19
|
-
* https://www.unicode.org/reports/tr35/#Likely_Subtags
|
|
20
|
-
*/
|
|
21
|
-
maximize(): Locale;
|
|
22
|
-
/**
|
|
23
|
-
* https://www.unicode.org/reports/tr35/#Likely_Subtags
|
|
24
|
-
*/
|
|
25
|
-
minimize(): Locale;
|
|
26
|
-
toString(): string;
|
|
27
|
-
get baseName(): string;
|
|
28
|
-
get calendar(): string | undefined;
|
|
29
|
-
get collation(): string | undefined;
|
|
30
|
-
get hourCycle(): "h11" | "h12" | "h23" | "h24" | undefined;
|
|
31
|
-
get caseFirst(): "upper" | "lower" | "false" | undefined;
|
|
32
|
-
get numeric(): boolean | undefined;
|
|
33
|
-
get numberingSystem(): string | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.language
|
|
36
|
-
*/
|
|
37
|
-
get language(): string;
|
|
38
|
-
/**
|
|
39
|
-
* https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.script
|
|
40
|
-
*/
|
|
41
|
-
get script(): string | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.region
|
|
44
|
-
*/
|
|
45
|
-
get region(): string | undefined;
|
|
46
|
-
static relevantExtensionKeys: readonly ["ca", "co", "hc", "kf", "kn", "nu"];
|
|
47
|
-
}
|
|
48
|
-
export default Locale;
|
|
49
|
-
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl-locale/index.ts"],"names":[],"mappings":"AAsBA,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAA;IACzC,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAA;IACvC,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAMD,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB,EAAE,OAAO,CAAA;CAC3B;AA6PD,qBAAa,MAAM;gBACL,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB;IAmI1D;;OAEG;IACI,QAAQ,IAAI,MAAM;IAUzB;;OAEG;IACI,QAAQ,IAAI,MAAM;IAUlB,QAAQ;IAIf,IAAW,QAAQ,WAGlB;IAED,IAAW,QAAQ,uBAElB;IAED,IAAW,SAAS,uBAEnB;IAED,IAAW,SAAS,8CAEnB;IAED,IAAW,SAAS,4CAEnB;IAED,IAAW,OAAO,wBAEjB;IACD,IAAW,eAAe,uBAEzB;IACD;;OAEG;IACH,IAAW,QAAQ,WAGlB;IACD;;OAEG;IACH,IAAW,MAAM,uBAGhB;IACD;;OAEG;IACH,IAAW,MAAM,uBAGhB;IAED,MAAM,CAAC,qBAAqB,gDAA0B;CACvD;AAsBD,eAAe,MAAM,CAAA"}
|