@formatjs/intl-locale 4.2.13 → 5.0.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/calendars.generated.js +1 -4
- package/character-orders.generated.js +1 -4
- package/get_internal_slots.js +1 -4
- package/hour-cycles.generated.js +1 -4
- package/index.js +105 -108
- package/numbering-systems.generated.js +1 -4
- package/package.json +16 -10
- package/polyfill-force.js +2 -4
- package/polyfill.iife.js +8281 -20618
- package/polyfill.js +4 -6
- package/preference-data.d.ts +1 -1
- package/preference-data.js +18 -24
- package/should-polyfill.js +2 -5
- package/timezones.generated.js +1 -4
- package/week-data.generated.js +1 -4
- package/lib/calendars.generated.d.ts +0 -55
- package/lib/calendars.generated.js +0 -292
- package/lib/character-orders.generated.d.ts +0 -729
- package/lib/character-orders.generated.js +0 -729
- package/lib/get_internal_slots.d.ts +0 -2
- package/lib/get_internal_slots.js +0 -19
- package/lib/hour-cycles.generated.d.ts +0 -277
- package/lib/hour-cycles.generated.js +0 -1041
- package/lib/index.d.ts +0 -103
- package/lib/index.js +0 -582
- package/lib/numbering-systems.generated.d.ts +0 -728
- package/lib/numbering-systems.generated.js +0 -2299
- package/lib/polyfill-force.d.ts +0 -1
- package/lib/polyfill-force.js +0 -7
- package/lib/polyfill.d.ts +0 -1
- package/lib/polyfill.js +0 -10
- package/lib/preference-data.d.ts +0 -6
- package/lib/preference-data.js +0 -46
- package/lib/should-polyfill.d.ts +0 -1
- package/lib/should-polyfill.js +0 -14
- package/lib/timezones.generated.d.ts +0 -250
- package/lib/timezones.generated.js +0 -966
- package/lib/week-data.generated.d.ts +0 -1299
- package/lib/week-data.generated.js +0 -2073
package/lib/index.d.ts
DELETED
|
@@ -1,103 +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
|
-
firstDayOfWeek?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface IntlLocaleInternal extends IntlLocaleOptions {
|
|
14
|
-
locale: string;
|
|
15
|
-
initializedLocale: boolean;
|
|
16
|
-
}
|
|
17
|
-
export declare class Locale {
|
|
18
|
-
constructor(tag: string | Locale, opts?: IntlLocaleOptions);
|
|
19
|
-
/**
|
|
20
|
-
* https://www.unicode.org/reports/tr35/#Likely_Subtags
|
|
21
|
-
*/
|
|
22
|
-
maximize(): Locale;
|
|
23
|
-
/**
|
|
24
|
-
* https://www.unicode.org/reports/tr35/#Likely_Subtags
|
|
25
|
-
*/
|
|
26
|
-
minimize(): Locale;
|
|
27
|
-
toString(): string;
|
|
28
|
-
get baseName(): string;
|
|
29
|
-
get calendar(): string | undefined;
|
|
30
|
-
get collation(): string | 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
|
-
get firstDayOfWeek(): string | undefined;
|
|
47
|
-
get hourCycle(): 'h11' | 'h12' | 'h23' | 'h24' | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars
|
|
50
|
-
* https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getCalendars
|
|
51
|
-
*/
|
|
52
|
-
getCalendars(): string[];
|
|
53
|
-
/**
|
|
54
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations
|
|
55
|
-
* https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getCollations
|
|
56
|
-
*/
|
|
57
|
-
getCollations(): string[];
|
|
58
|
-
/**
|
|
59
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles
|
|
60
|
-
* https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getHourCycles
|
|
61
|
-
*/
|
|
62
|
-
getHourCycles(): string[];
|
|
63
|
-
/**
|
|
64
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems
|
|
65
|
-
* https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getNumberingSystems
|
|
66
|
-
*/
|
|
67
|
-
getNumberingSystems(): string[];
|
|
68
|
-
/**
|
|
69
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones
|
|
70
|
-
* https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getTimeZones
|
|
71
|
-
*/
|
|
72
|
-
getTimeZones(): string[] | undefined;
|
|
73
|
-
/**
|
|
74
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo
|
|
75
|
-
* https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getTextInfo
|
|
76
|
-
*/
|
|
77
|
-
getTextInfo(): {
|
|
78
|
-
direction: string;
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo
|
|
82
|
-
* https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getWeekInfo
|
|
83
|
-
*/
|
|
84
|
-
getWeekInfo(): {
|
|
85
|
-
firstDay: string;
|
|
86
|
-
weekend: {
|
|
87
|
-
start: string;
|
|
88
|
-
end: string;
|
|
89
|
-
};
|
|
90
|
-
minimalDays: number;
|
|
91
|
-
};
|
|
92
|
-
static relevantExtensionKeys: readonly [
|
|
93
|
-
'ca',
|
|
94
|
-
'co',
|
|
95
|
-
'hc',
|
|
96
|
-
'kf',
|
|
97
|
-
'kn',
|
|
98
|
-
'nu',
|
|
99
|
-
'fw'
|
|
100
|
-
];
|
|
101
|
-
static readonly polyfilled = true;
|
|
102
|
-
}
|
|
103
|
-
export default Locale;
|
package/lib/index.js
DELETED
|
@@ -1,582 +0,0 @@
|
|
|
1
|
-
import { __assign, __spreadArray } from "tslib";
|
|
2
|
-
import { CoerceOptionsToObject, GetOption, HasOwnProperty, SameValue, createDataProperty, invariant, } from '@formatjs/ecma402-abstract';
|
|
3
|
-
import { supportedValuesOf } from '@formatjs/intl-enumerator';
|
|
4
|
-
import { emitUnicodeLanguageId, emitUnicodeLocaleId, isStructurallyValidLanguageTag, isUnicodeLanguageSubtag, isUnicodeRegionSubtag, isUnicodeScriptSubtag, likelySubtags, parseUnicodeLanguageId, parseUnicodeLocaleId, } from '@formatjs/intl-getcanonicallocales';
|
|
5
|
-
import { characterOrders } from './character-orders.generated';
|
|
6
|
-
import getInternalSlots from './get_internal_slots';
|
|
7
|
-
import { numberingSystems } from './numbering-systems.generated';
|
|
8
|
-
import { getCalendarPreferenceDataForRegion, getHourCyclesPreferenceDataForLocaleOrRegion, getTimeZonePreferenceForRegion, getWeekDataForRegion, } from './preference-data';
|
|
9
|
-
var ALPHANUM_3_8 = /^[a-z0-9]{3,8}$/i;
|
|
10
|
-
var RELEVANT_EXTENSION_KEYS = [
|
|
11
|
-
'ca',
|
|
12
|
-
'co',
|
|
13
|
-
'hc',
|
|
14
|
-
'kf',
|
|
15
|
-
'kn',
|
|
16
|
-
'nu',
|
|
17
|
-
'fw',
|
|
18
|
-
];
|
|
19
|
-
var UNICODE_TYPE_REGEX = /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*$/i;
|
|
20
|
-
function applyOptionsToTag(tag, options) {
|
|
21
|
-
invariant(typeof tag === 'string', 'language tag must be a string');
|
|
22
|
-
invariant(isStructurallyValidLanguageTag(tag), 'malformed language tag', RangeError);
|
|
23
|
-
var language = GetOption(options, 'language', 'string', undefined, undefined);
|
|
24
|
-
if (language !== undefined) {
|
|
25
|
-
invariant(isUnicodeLanguageSubtag(language), 'Malformed unicode_language_subtag', RangeError);
|
|
26
|
-
}
|
|
27
|
-
var script = GetOption(options, 'script', 'string', undefined, undefined);
|
|
28
|
-
if (script !== undefined) {
|
|
29
|
-
invariant(isUnicodeScriptSubtag(script), 'Malformed unicode_script_subtag', RangeError);
|
|
30
|
-
}
|
|
31
|
-
var region = GetOption(options, 'region', 'string', undefined, undefined);
|
|
32
|
-
if (region !== undefined) {
|
|
33
|
-
invariant(isUnicodeRegionSubtag(region), 'Malformed unicode_region_subtag', RangeError);
|
|
34
|
-
}
|
|
35
|
-
var languageId = parseUnicodeLanguageId(tag);
|
|
36
|
-
if (language !== undefined) {
|
|
37
|
-
languageId.lang = language;
|
|
38
|
-
}
|
|
39
|
-
if (script !== undefined) {
|
|
40
|
-
languageId.script = script;
|
|
41
|
-
}
|
|
42
|
-
if (region !== undefined) {
|
|
43
|
-
languageId.region = region;
|
|
44
|
-
}
|
|
45
|
-
return Intl.getCanonicalLocales(emitUnicodeLocaleId(__assign(__assign({}, parseUnicodeLocaleId(tag)), { lang: languageId })))[0];
|
|
46
|
-
}
|
|
47
|
-
function applyUnicodeExtensionToTag(tag, options, relevantExtensionKeys) {
|
|
48
|
-
var unicodeExtension;
|
|
49
|
-
var keywords = [];
|
|
50
|
-
var ast = parseUnicodeLocaleId(tag);
|
|
51
|
-
for (var _i = 0, _a = ast.extensions; _i < _a.length; _i++) {
|
|
52
|
-
var ext = _a[_i];
|
|
53
|
-
if (ext.type === 'u') {
|
|
54
|
-
unicodeExtension = ext;
|
|
55
|
-
if (Array.isArray(ext.keywords))
|
|
56
|
-
keywords = ext.keywords;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
var result = Object.create(null);
|
|
60
|
-
for (var _b = 0, relevantExtensionKeys_1 = relevantExtensionKeys; _b < relevantExtensionKeys_1.length; _b++) {
|
|
61
|
-
var key = relevantExtensionKeys_1[_b];
|
|
62
|
-
var value = void 0, entry = void 0;
|
|
63
|
-
for (var _c = 0, keywords_1 = keywords; _c < keywords_1.length; _c++) {
|
|
64
|
-
var keyword = keywords_1[_c];
|
|
65
|
-
if (keyword[0] === key) {
|
|
66
|
-
entry = keyword;
|
|
67
|
-
value = entry[1];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
invariant(key in options, "".concat(key, " must be in options"));
|
|
71
|
-
var optionsValue = options[key];
|
|
72
|
-
if (optionsValue !== undefined) {
|
|
73
|
-
invariant(typeof optionsValue === 'string', "Value for ".concat(key, " must be a string"));
|
|
74
|
-
value = optionsValue;
|
|
75
|
-
if (entry) {
|
|
76
|
-
entry[1] = value;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
keywords.push([key, value]);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
result[key] = value;
|
|
83
|
-
}
|
|
84
|
-
if (!unicodeExtension) {
|
|
85
|
-
if (keywords.length) {
|
|
86
|
-
ast.extensions.push({
|
|
87
|
-
type: 'u',
|
|
88
|
-
keywords: keywords,
|
|
89
|
-
attributes: [],
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
unicodeExtension.keywords = keywords;
|
|
95
|
-
}
|
|
96
|
-
result.locale = Intl.getCanonicalLocales(emitUnicodeLocaleId(ast))[0];
|
|
97
|
-
return result;
|
|
98
|
-
}
|
|
99
|
-
function mergeUnicodeLanguageId(lang, script, region, variants, replacement) {
|
|
100
|
-
if (variants === void 0) { variants = []; }
|
|
101
|
-
if (!replacement) {
|
|
102
|
-
return {
|
|
103
|
-
lang: lang || 'und',
|
|
104
|
-
script: script,
|
|
105
|
-
region: region,
|
|
106
|
-
variants: variants,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
lang: !lang || lang === 'und' ? replacement.lang : lang,
|
|
111
|
-
script: script || replacement.script,
|
|
112
|
-
region: region || replacement.region,
|
|
113
|
-
variants: __spreadArray(__spreadArray([], variants, true), replacement.variants, true),
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
function addLikelySubtags(tag) {
|
|
117
|
-
var ast = parseUnicodeLocaleId(tag);
|
|
118
|
-
var unicodeLangId = ast.lang;
|
|
119
|
-
var lang = unicodeLangId.lang, script = unicodeLangId.script, region = unicodeLangId.region, variants = unicodeLangId.variants;
|
|
120
|
-
if (script && region) {
|
|
121
|
-
var match_1 = likelySubtags[emitUnicodeLanguageId({ lang: lang, script: script, region: region, variants: [] })];
|
|
122
|
-
if (match_1) {
|
|
123
|
-
var parts_1 = parseUnicodeLanguageId(match_1);
|
|
124
|
-
ast.lang = mergeUnicodeLanguageId(undefined, undefined, undefined, variants, parts_1);
|
|
125
|
-
return emitUnicodeLocaleId(ast);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (script) {
|
|
129
|
-
var match_2 = likelySubtags[emitUnicodeLanguageId({ lang: lang, script: script, variants: [] })];
|
|
130
|
-
if (match_2) {
|
|
131
|
-
var parts_2 = parseUnicodeLanguageId(match_2);
|
|
132
|
-
ast.lang = mergeUnicodeLanguageId(undefined, undefined, region, variants, parts_2);
|
|
133
|
-
return emitUnicodeLocaleId(ast);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if (region) {
|
|
137
|
-
var match_3 = likelySubtags[emitUnicodeLanguageId({ lang: lang, region: region, variants: [] })];
|
|
138
|
-
if (match_3) {
|
|
139
|
-
var parts_3 = parseUnicodeLanguageId(match_3);
|
|
140
|
-
ast.lang = mergeUnicodeLanguageId(undefined, script, undefined, variants, parts_3);
|
|
141
|
-
return emitUnicodeLocaleId(ast);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
var match = likelySubtags[lang] ||
|
|
145
|
-
likelySubtags[emitUnicodeLanguageId({ lang: 'und', script: script, variants: [] })];
|
|
146
|
-
if (!match) {
|
|
147
|
-
throw new Error("No match for addLikelySubtags");
|
|
148
|
-
}
|
|
149
|
-
var parts = parseUnicodeLanguageId(match);
|
|
150
|
-
ast.lang = mergeUnicodeLanguageId(undefined, script, region, variants, parts);
|
|
151
|
-
return emitUnicodeLocaleId(ast);
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* From: https://github.com/unicode-org/icu/blob/4231ca5be053a22a1be24eb891817458c97db709/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java#L2395
|
|
155
|
-
* @param tag
|
|
156
|
-
*/
|
|
157
|
-
function removeLikelySubtags(tag) {
|
|
158
|
-
var maxLocale = addLikelySubtags(tag);
|
|
159
|
-
if (!maxLocale) {
|
|
160
|
-
return tag;
|
|
161
|
-
}
|
|
162
|
-
maxLocale = emitUnicodeLanguageId(__assign(__assign({}, parseUnicodeLanguageId(maxLocale)), { variants: [] }));
|
|
163
|
-
var ast = parseUnicodeLocaleId(tag);
|
|
164
|
-
var _a = ast.lang, lang = _a.lang, script = _a.script, region = _a.region, variants = _a.variants;
|
|
165
|
-
var trial = addLikelySubtags(emitUnicodeLanguageId({ lang: lang, variants: [] }));
|
|
166
|
-
if (trial === maxLocale) {
|
|
167
|
-
return emitUnicodeLocaleId(__assign(__assign({}, ast), { lang: mergeUnicodeLanguageId(lang, undefined, undefined, variants) }));
|
|
168
|
-
}
|
|
169
|
-
if (region) {
|
|
170
|
-
var trial_1 = addLikelySubtags(emitUnicodeLanguageId({ lang: lang, region: region, variants: [] }));
|
|
171
|
-
if (trial_1 === maxLocale) {
|
|
172
|
-
return emitUnicodeLocaleId(__assign(__assign({}, ast), { lang: mergeUnicodeLanguageId(lang, undefined, region, variants) }));
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (script) {
|
|
176
|
-
var trial_2 = addLikelySubtags(emitUnicodeLanguageId({ lang: lang, script: script, variants: [] }));
|
|
177
|
-
if (trial_2 === maxLocale) {
|
|
178
|
-
return emitUnicodeLocaleId(__assign(__assign({}, ast), { lang: mergeUnicodeLanguageId(lang, script, undefined, variants) }));
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return tag;
|
|
182
|
-
}
|
|
183
|
-
function createArrayFromListOrRestricted(list, restricted) {
|
|
184
|
-
var result = list;
|
|
185
|
-
if (restricted !== undefined) {
|
|
186
|
-
result = [restricted];
|
|
187
|
-
}
|
|
188
|
-
return Array.from(result);
|
|
189
|
-
}
|
|
190
|
-
function calendarsOfLocale(loc) {
|
|
191
|
-
var locInternalSlots = getInternalSlots(loc);
|
|
192
|
-
var restricted = locInternalSlots.calendar;
|
|
193
|
-
var locale = locInternalSlots.locale;
|
|
194
|
-
var region;
|
|
195
|
-
if (locale !== 'root') {
|
|
196
|
-
region = loc.maximize().region;
|
|
197
|
-
}
|
|
198
|
-
var preferredCalendars = getCalendarPreferenceDataForRegion(region);
|
|
199
|
-
return createArrayFromListOrRestricted(preferredCalendars, restricted);
|
|
200
|
-
}
|
|
201
|
-
function collationsOfLocale(loc) {
|
|
202
|
-
var locInternalSlots = getInternalSlots(loc);
|
|
203
|
-
var restricted = locInternalSlots.collation;
|
|
204
|
-
var locale = locInternalSlots.locale;
|
|
205
|
-
var supportedCollations = supportedValuesOf('collation', locale).filter(function (co) { return co !== 'standard' && co !== 'search'; });
|
|
206
|
-
supportedCollations.sort();
|
|
207
|
-
return createArrayFromListOrRestricted(supportedCollations, restricted);
|
|
208
|
-
}
|
|
209
|
-
function hourCyclesOfLocale(loc) {
|
|
210
|
-
var locInternalSlots = getInternalSlots(loc);
|
|
211
|
-
var restricted = locInternalSlots.hourCycle;
|
|
212
|
-
var locale = locInternalSlots.locale;
|
|
213
|
-
var region;
|
|
214
|
-
if (locale !== 'root') {
|
|
215
|
-
region = loc.maximize().region;
|
|
216
|
-
}
|
|
217
|
-
var preferredHourCycles = getHourCyclesPreferenceDataForLocaleOrRegion(locale, region);
|
|
218
|
-
return createArrayFromListOrRestricted(preferredHourCycles, restricted);
|
|
219
|
-
}
|
|
220
|
-
function numberingSystemsOfLocale(loc) {
|
|
221
|
-
var _a;
|
|
222
|
-
var locInternalSlots = getInternalSlots(loc);
|
|
223
|
-
var restricted = locInternalSlots.numberingSystem;
|
|
224
|
-
var locale = locInternalSlots.locale;
|
|
225
|
-
var language = loc.language;
|
|
226
|
-
var localeNumberingSystems = (_a = numberingSystems[locale]) !== null && _a !== void 0 ? _a : numberingSystems[language];
|
|
227
|
-
if (localeNumberingSystems) {
|
|
228
|
-
return createArrayFromListOrRestricted(__spreadArray([], localeNumberingSystems, true), restricted);
|
|
229
|
-
}
|
|
230
|
-
return createArrayFromListOrRestricted([], restricted);
|
|
231
|
-
}
|
|
232
|
-
function timeZonesOfLocale(loc) {
|
|
233
|
-
var locInternalSlots = getInternalSlots(loc);
|
|
234
|
-
var locale = locInternalSlots.locale;
|
|
235
|
-
var region = parseUnicodeLanguageId(locale).region;
|
|
236
|
-
if (!region) {
|
|
237
|
-
return undefined;
|
|
238
|
-
}
|
|
239
|
-
var preferredTimeZones = getTimeZonePreferenceForRegion(region);
|
|
240
|
-
preferredTimeZones.sort();
|
|
241
|
-
return Array.from(preferredTimeZones);
|
|
242
|
-
}
|
|
243
|
-
function translateCharacterOrder(order) {
|
|
244
|
-
if (order === 'right-to-left') {
|
|
245
|
-
return 'rtl';
|
|
246
|
-
}
|
|
247
|
-
return 'ltr';
|
|
248
|
-
}
|
|
249
|
-
function characterDirectionOfLocale(loc) {
|
|
250
|
-
var locale = loc.minimize().toString();
|
|
251
|
-
return translateCharacterOrder(characterOrders[locale]);
|
|
252
|
-
}
|
|
253
|
-
function weekInfoOfLocale(loc) {
|
|
254
|
-
var locInternalSlots = getInternalSlots(loc);
|
|
255
|
-
var locale = locInternalSlots.locale;
|
|
256
|
-
var region;
|
|
257
|
-
if (locale !== 'root') {
|
|
258
|
-
region = loc.maximize().region;
|
|
259
|
-
}
|
|
260
|
-
return getWeekDataForRegion(region);
|
|
261
|
-
}
|
|
262
|
-
var TABLE_1 = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
|
|
263
|
-
function weekdayToString(fw) {
|
|
264
|
-
return TABLE_1[+fw];
|
|
265
|
-
}
|
|
266
|
-
var Locale = /** @class */ (function () {
|
|
267
|
-
function Locale(tag, opts) {
|
|
268
|
-
// test262/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js
|
|
269
|
-
// Cannot use `new.target` bc of IE11 & TS transpiles it to something else
|
|
270
|
-
var newTarget = this && this instanceof Locale ? this.constructor : void 0;
|
|
271
|
-
if (!newTarget) {
|
|
272
|
-
throw new TypeError("Intl.Locale must be called with 'new'");
|
|
273
|
-
}
|
|
274
|
-
var relevantExtensionKeys = Locale.relevantExtensionKeys;
|
|
275
|
-
var internalSlotsList = [
|
|
276
|
-
'initializedLocale',
|
|
277
|
-
'locale',
|
|
278
|
-
'calendar',
|
|
279
|
-
'collation',
|
|
280
|
-
'hourCycle',
|
|
281
|
-
'numberingSystem',
|
|
282
|
-
];
|
|
283
|
-
if (relevantExtensionKeys.indexOf('kf') > -1) {
|
|
284
|
-
internalSlotsList.push('caseFirst');
|
|
285
|
-
}
|
|
286
|
-
if (relevantExtensionKeys.indexOf('kn') > -1) {
|
|
287
|
-
internalSlotsList.push('numeric');
|
|
288
|
-
}
|
|
289
|
-
if (tag === undefined) {
|
|
290
|
-
throw new TypeError("First argument to Intl.Locale constructor can't be empty or missing");
|
|
291
|
-
}
|
|
292
|
-
if (typeof tag !== 'string' && typeof tag !== 'object') {
|
|
293
|
-
throw new TypeError('tag must be a string or object');
|
|
294
|
-
}
|
|
295
|
-
var tagInternalSlots;
|
|
296
|
-
if (typeof tag === 'object' &&
|
|
297
|
-
(tagInternalSlots = getInternalSlots(tag)) &&
|
|
298
|
-
HasOwnProperty(tagInternalSlots, 'initializedLocale')) {
|
|
299
|
-
tag = tagInternalSlots.locale;
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
tag = tag.toString();
|
|
303
|
-
}
|
|
304
|
-
var internalSlots = getInternalSlots(this, internalSlotsList);
|
|
305
|
-
var options = CoerceOptionsToObject(opts);
|
|
306
|
-
tag = applyOptionsToTag(tag, options);
|
|
307
|
-
var opt = Object.create(null);
|
|
308
|
-
var calendar = GetOption(options, 'calendar', 'string', undefined, undefined);
|
|
309
|
-
if (calendar !== undefined) {
|
|
310
|
-
if (!UNICODE_TYPE_REGEX.test(calendar)) {
|
|
311
|
-
throw new RangeError('invalid calendar');
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
opt.ca = calendar;
|
|
315
|
-
var collation = GetOption(options, 'collation', 'string', undefined, undefined);
|
|
316
|
-
if (collation !== undefined) {
|
|
317
|
-
if (!UNICODE_TYPE_REGEX.test(collation)) {
|
|
318
|
-
throw new RangeError('invalid collation');
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
opt.co = collation;
|
|
322
|
-
var fw = GetOption(options, 'firstDayOfWeek', 'string', undefined, undefined);
|
|
323
|
-
if (fw !== undefined) {
|
|
324
|
-
fw = weekdayToString(fw);
|
|
325
|
-
if (!ALPHANUM_3_8.test(fw)) {
|
|
326
|
-
throw new RangeError('Invalid firstDayOfWeek');
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
opt.fw = fw;
|
|
330
|
-
var hc = GetOption(options, 'hourCycle', 'string', ['h11', 'h12', 'h23', 'h24'], undefined);
|
|
331
|
-
opt.hc = hc;
|
|
332
|
-
var kf = GetOption(options, 'caseFirst', 'string', ['upper', 'lower', 'false'], undefined);
|
|
333
|
-
opt.kf = kf;
|
|
334
|
-
var _kn = GetOption(options, 'numeric', 'boolean', undefined, undefined);
|
|
335
|
-
var kn;
|
|
336
|
-
if (_kn !== undefined) {
|
|
337
|
-
kn = String(_kn);
|
|
338
|
-
}
|
|
339
|
-
opt.kn = kn;
|
|
340
|
-
var numberingSystem = GetOption(options, 'numberingSystem', 'string', undefined, undefined);
|
|
341
|
-
if (numberingSystem !== undefined) {
|
|
342
|
-
if (!UNICODE_TYPE_REGEX.test(numberingSystem)) {
|
|
343
|
-
throw new RangeError('Invalid numberingSystem');
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
opt.nu = numberingSystem;
|
|
347
|
-
var r = applyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys);
|
|
348
|
-
internalSlots.locale = r.locale;
|
|
349
|
-
internalSlots.calendar = r.ca;
|
|
350
|
-
internalSlots.collation = r.co;
|
|
351
|
-
internalSlots.firstDayOfWeek = r.fw;
|
|
352
|
-
internalSlots.hourCycle = r.hc;
|
|
353
|
-
if (relevantExtensionKeys.indexOf('kf') > -1) {
|
|
354
|
-
internalSlots.caseFirst = r.kf;
|
|
355
|
-
}
|
|
356
|
-
if (relevantExtensionKeys.indexOf('kn') > -1) {
|
|
357
|
-
internalSlots.numeric = SameValue(r.kn, 'true');
|
|
358
|
-
}
|
|
359
|
-
internalSlots.numberingSystem = r.nu;
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* https://www.unicode.org/reports/tr35/#Likely_Subtags
|
|
363
|
-
*/
|
|
364
|
-
Locale.prototype.maximize = function () {
|
|
365
|
-
var locale = getInternalSlots(this).locale;
|
|
366
|
-
try {
|
|
367
|
-
var maximizedLocale = addLikelySubtags(locale);
|
|
368
|
-
return new Locale(maximizedLocale);
|
|
369
|
-
}
|
|
370
|
-
catch (e) {
|
|
371
|
-
return new Locale(locale);
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
/**
|
|
375
|
-
* https://www.unicode.org/reports/tr35/#Likely_Subtags
|
|
376
|
-
*/
|
|
377
|
-
Locale.prototype.minimize = function () {
|
|
378
|
-
var locale = getInternalSlots(this).locale;
|
|
379
|
-
try {
|
|
380
|
-
var minimizedLocale = removeLikelySubtags(locale);
|
|
381
|
-
return new Locale(minimizedLocale);
|
|
382
|
-
}
|
|
383
|
-
catch (e) {
|
|
384
|
-
return new Locale(locale);
|
|
385
|
-
}
|
|
386
|
-
};
|
|
387
|
-
Locale.prototype.toString = function () {
|
|
388
|
-
return getInternalSlots(this).locale;
|
|
389
|
-
};
|
|
390
|
-
Object.defineProperty(Locale.prototype, "baseName", {
|
|
391
|
-
get: function () {
|
|
392
|
-
var locale = getInternalSlots(this).locale;
|
|
393
|
-
return emitUnicodeLanguageId(parseUnicodeLanguageId(locale));
|
|
394
|
-
},
|
|
395
|
-
enumerable: false,
|
|
396
|
-
configurable: true
|
|
397
|
-
});
|
|
398
|
-
Object.defineProperty(Locale.prototype, "calendar", {
|
|
399
|
-
get: function () {
|
|
400
|
-
return getInternalSlots(this).calendar;
|
|
401
|
-
},
|
|
402
|
-
enumerable: false,
|
|
403
|
-
configurable: true
|
|
404
|
-
});
|
|
405
|
-
Object.defineProperty(Locale.prototype, "collation", {
|
|
406
|
-
get: function () {
|
|
407
|
-
return getInternalSlots(this).collation;
|
|
408
|
-
},
|
|
409
|
-
enumerable: false,
|
|
410
|
-
configurable: true
|
|
411
|
-
});
|
|
412
|
-
Object.defineProperty(Locale.prototype, "caseFirst", {
|
|
413
|
-
get: function () {
|
|
414
|
-
return getInternalSlots(this).caseFirst;
|
|
415
|
-
},
|
|
416
|
-
enumerable: false,
|
|
417
|
-
configurable: true
|
|
418
|
-
});
|
|
419
|
-
Object.defineProperty(Locale.prototype, "numeric", {
|
|
420
|
-
get: function () {
|
|
421
|
-
return getInternalSlots(this).numeric;
|
|
422
|
-
},
|
|
423
|
-
enumerable: false,
|
|
424
|
-
configurable: true
|
|
425
|
-
});
|
|
426
|
-
Object.defineProperty(Locale.prototype, "numberingSystem", {
|
|
427
|
-
get: function () {
|
|
428
|
-
return getInternalSlots(this).numberingSystem;
|
|
429
|
-
},
|
|
430
|
-
enumerable: false,
|
|
431
|
-
configurable: true
|
|
432
|
-
});
|
|
433
|
-
Object.defineProperty(Locale.prototype, "language", {
|
|
434
|
-
/**
|
|
435
|
-
* https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.language
|
|
436
|
-
*/
|
|
437
|
-
get: function () {
|
|
438
|
-
var locale = getInternalSlots(this).locale;
|
|
439
|
-
return parseUnicodeLanguageId(locale).lang;
|
|
440
|
-
},
|
|
441
|
-
enumerable: false,
|
|
442
|
-
configurable: true
|
|
443
|
-
});
|
|
444
|
-
Object.defineProperty(Locale.prototype, "script", {
|
|
445
|
-
/**
|
|
446
|
-
* https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.script
|
|
447
|
-
*/
|
|
448
|
-
get: function () {
|
|
449
|
-
var locale = getInternalSlots(this).locale;
|
|
450
|
-
return parseUnicodeLanguageId(locale).script;
|
|
451
|
-
},
|
|
452
|
-
enumerable: false,
|
|
453
|
-
configurable: true
|
|
454
|
-
});
|
|
455
|
-
Object.defineProperty(Locale.prototype, "region", {
|
|
456
|
-
/**
|
|
457
|
-
* https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.region
|
|
458
|
-
*/
|
|
459
|
-
get: function () {
|
|
460
|
-
var locale = getInternalSlots(this).locale;
|
|
461
|
-
return parseUnicodeLanguageId(locale).region;
|
|
462
|
-
},
|
|
463
|
-
enumerable: false,
|
|
464
|
-
configurable: true
|
|
465
|
-
});
|
|
466
|
-
Object.defineProperty(Locale.prototype, "firstDayOfWeek", {
|
|
467
|
-
get: function () {
|
|
468
|
-
var internalSlots = getInternalSlots(this);
|
|
469
|
-
if (!HasOwnProperty(internalSlots, 'initializedLocale')) {
|
|
470
|
-
throw new TypeError('Error uninitialized locale');
|
|
471
|
-
}
|
|
472
|
-
return internalSlots.firstDayOfWeek;
|
|
473
|
-
},
|
|
474
|
-
enumerable: false,
|
|
475
|
-
configurable: true
|
|
476
|
-
});
|
|
477
|
-
Object.defineProperty(Locale.prototype, "hourCycle", {
|
|
478
|
-
get: function () {
|
|
479
|
-
var internalSlots = getInternalSlots(this);
|
|
480
|
-
if (!HasOwnProperty(internalSlots, 'initializedLocale')) {
|
|
481
|
-
throw new TypeError('Error uninitialized locale');
|
|
482
|
-
}
|
|
483
|
-
return internalSlots.hourCycle;
|
|
484
|
-
},
|
|
485
|
-
enumerable: false,
|
|
486
|
-
configurable: true
|
|
487
|
-
});
|
|
488
|
-
/**
|
|
489
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars
|
|
490
|
-
* https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getCalendars
|
|
491
|
-
*/
|
|
492
|
-
Locale.prototype.getCalendars = function () {
|
|
493
|
-
return calendarsOfLocale(this);
|
|
494
|
-
};
|
|
495
|
-
/**
|
|
496
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations
|
|
497
|
-
* https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getCollations
|
|
498
|
-
*/
|
|
499
|
-
Locale.prototype.getCollations = function () {
|
|
500
|
-
return collationsOfLocale(this);
|
|
501
|
-
};
|
|
502
|
-
/**
|
|
503
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles
|
|
504
|
-
* https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getHourCycles
|
|
505
|
-
*/
|
|
506
|
-
Locale.prototype.getHourCycles = function () {
|
|
507
|
-
var internalSlots = getInternalSlots(this);
|
|
508
|
-
if (!HasOwnProperty(internalSlots, 'initializedLocale')) {
|
|
509
|
-
throw new TypeError('Error uninitialized locale');
|
|
510
|
-
}
|
|
511
|
-
return hourCyclesOfLocale(this);
|
|
512
|
-
};
|
|
513
|
-
/**
|
|
514
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems
|
|
515
|
-
* https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getNumberingSystems
|
|
516
|
-
*/
|
|
517
|
-
Locale.prototype.getNumberingSystems = function () {
|
|
518
|
-
return numberingSystemsOfLocale(this);
|
|
519
|
-
};
|
|
520
|
-
/**
|
|
521
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones
|
|
522
|
-
* https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getTimeZones
|
|
523
|
-
*/
|
|
524
|
-
Locale.prototype.getTimeZones = function () {
|
|
525
|
-
return timeZonesOfLocale(this);
|
|
526
|
-
};
|
|
527
|
-
/**
|
|
528
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo
|
|
529
|
-
* https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getTextInfo
|
|
530
|
-
*/
|
|
531
|
-
Locale.prototype.getTextInfo = function () {
|
|
532
|
-
var info = Object.create(Object.prototype);
|
|
533
|
-
var dir = characterDirectionOfLocale(this);
|
|
534
|
-
createDataProperty(info, 'direction', dir);
|
|
535
|
-
return info;
|
|
536
|
-
};
|
|
537
|
-
/**
|
|
538
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo
|
|
539
|
-
* https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getWeekInfo
|
|
540
|
-
*/
|
|
541
|
-
Locale.prototype.getWeekInfo = function () {
|
|
542
|
-
var info = Object.create(Object.prototype);
|
|
543
|
-
var internalSlots = getInternalSlots(this);
|
|
544
|
-
if (!HasOwnProperty(internalSlots, 'initializedLocale')) {
|
|
545
|
-
throw new TypeError('Error uninitialized locale');
|
|
546
|
-
}
|
|
547
|
-
var wi = weekInfoOfLocale(this);
|
|
548
|
-
var we = wi.weekend;
|
|
549
|
-
createDataProperty(info, 'firstDay', wi.firstDay);
|
|
550
|
-
createDataProperty(info, 'weekend', we);
|
|
551
|
-
createDataProperty(info, 'minimalDays', wi.minimalDays);
|
|
552
|
-
var fw = internalSlots.firstDayOfWeek;
|
|
553
|
-
if (fw !== undefined) {
|
|
554
|
-
info.firstDay = fw;
|
|
555
|
-
}
|
|
556
|
-
return info;
|
|
557
|
-
};
|
|
558
|
-
Locale.relevantExtensionKeys = RELEVANT_EXTENSION_KEYS;
|
|
559
|
-
Locale.polyfilled = true;
|
|
560
|
-
return Locale;
|
|
561
|
-
}());
|
|
562
|
-
export { Locale };
|
|
563
|
-
try {
|
|
564
|
-
if (typeof Symbol !== 'undefined') {
|
|
565
|
-
Object.defineProperty(Locale.prototype, Symbol.toStringTag, {
|
|
566
|
-
value: 'Intl.Locale',
|
|
567
|
-
writable: false,
|
|
568
|
-
enumerable: false,
|
|
569
|
-
configurable: true,
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
Object.defineProperty(Locale.prototype.constructor, 'length', {
|
|
573
|
-
value: 1,
|
|
574
|
-
writable: false,
|
|
575
|
-
enumerable: false,
|
|
576
|
-
configurable: true,
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
catch (e) {
|
|
580
|
-
// Meta fix so we're test262-compliant, not important
|
|
581
|
-
}
|
|
582
|
-
export default Locale;
|