@formatjs/intl-displaynames
Advanced tools
Comparing version 3.3.5 to 3.3.6
{ | ||
"name": "@formatjs/intl-displaynames", | ||
"version": "3.3.5", | ||
"version": "3.3.6", | ||
"description": "Polyfill for: https://tc39.es/proposal-intl-displaynames", | ||
@@ -24,3 +24,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@formatjs/ecma402-abstract": "^1.1.0" | ||
"@formatjs/ecma402-abstract": "^1.2.0" | ||
}, | ||
@@ -27,0 +27,0 @@ "bugs": { |
1196
polyfill.umd.js
(function (factory) { | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
factory(); | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
factory(); | ||
}((function () { 'use strict'; | ||
/** | ||
* http://ecma-international.org/ecma-402/7.0/index.html#sec-canonicalizelocalelist | ||
* @param locales | ||
*/ | ||
function CanonicalizeLocaleList(locales) { | ||
// TODO | ||
return Intl.getCanonicalLocales(locales); | ||
} | ||
/** | ||
* Cannot do Math.log(x) / Math.log(10) bc if IEEE floating point issue | ||
* @param x number | ||
*/ | ||
function setInternalSlot(map, pl, field, value) { | ||
if (!map.get(pl)) { | ||
map.set(pl, Object.create(null)); | ||
} | ||
var slots = map.get(pl); | ||
slots[field] = value; | ||
} | ||
function getInternalSlot(map, pl, field) { | ||
return getMultiInternalSlots(map, pl, field)[field]; | ||
} | ||
function getMultiInternalSlots(map, pl) { | ||
var fields = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
fields[_i - 2] = arguments[_i]; | ||
} | ||
var slots = map.get(pl); | ||
if (!slots) { | ||
throw new TypeError(pl + " InternalSlot has not been initialized"); | ||
} | ||
return fields.reduce(function (all, f) { | ||
all[f] = slots[f]; | ||
return all; | ||
}, Object.create(null)); | ||
} | ||
var UNICODE_EXTENSION_SEQUENCE_REGEX = /-u(?:-[0-9a-z]{2,8})+/gi; | ||
function invariant(condition, message, Err) { | ||
if (Err === void 0) { Err = Error; } | ||
if (!condition) { | ||
throw new Err(message); | ||
} | ||
} | ||
/** | ||
* Cannot do Math.log(x) / Math.log(10) bc if IEEE floating point issue | ||
* @param x number | ||
*/ | ||
function setInternalSlot(map, pl, field, value) { | ||
if (!map.get(pl)) { | ||
map.set(pl, Object.create(null)); | ||
} | ||
var slots = map.get(pl); | ||
slots[field] = value; | ||
} | ||
function getInternalSlot(map, pl, field) { | ||
return getMultiInternalSlots(map, pl, field)[field]; | ||
} | ||
function getMultiInternalSlots(map, pl) { | ||
var fields = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
fields[_i - 2] = arguments[_i]; | ||
} | ||
var slots = map.get(pl); | ||
if (!slots) { | ||
throw new TypeError(pl + " InternalSlot has not been initialized"); | ||
} | ||
return fields.reduce(function (all, f) { | ||
all[f] = slots[f]; | ||
return all; | ||
}, Object.create(null)); | ||
} | ||
var UNICODE_EXTENSION_SEQUENCE_REGEX = /-u(?:-[0-9a-z]{2,8})+/gi; | ||
function invariant(condition, message, Err) { | ||
if (Err === void 0) { Err = Error; } | ||
if (!condition) { | ||
throw new Err(message); | ||
} | ||
} | ||
/** | ||
* http://ecma-international.org/ecma-402/7.0/index.html#sec-canonicalizelocalelist | ||
* @param locales | ||
*/ | ||
function CanonicalizeLocaleList(locales) { | ||
// TODO | ||
return Intl.getCanonicalLocales(locales); | ||
} | ||
/** | ||
* https://tc39.es/ecma262/#sec-tostring | ||
*/ | ||
function ToString(o) { | ||
// Only symbol is irregular... | ||
if (typeof o === 'symbol') { | ||
throw TypeError('Cannot convert a Symbol value to a string'); | ||
} | ||
return String(o); | ||
} | ||
/** | ||
* https://tc39.es/ecma262/#sec-toobject | ||
* @param arg | ||
*/ | ||
function ToObject(arg) { | ||
if (arg == null) { | ||
throw new TypeError('undefined/null cannot be converted to object'); | ||
} | ||
return Object(arg); | ||
} | ||
/** | ||
* https://tc39.es/ecma262/#sec-tostring | ||
*/ | ||
function ToString(o) { | ||
// Only symbol is irregular... | ||
if (typeof o === 'symbol') { | ||
throw TypeError('Cannot convert a Symbol value to a string'); | ||
} | ||
return String(o); | ||
} | ||
/** | ||
* https://tc39.es/ecma262/#sec-toobject | ||
* @param arg | ||
*/ | ||
function ToObject(arg) { | ||
if (arg == null) { | ||
throw new TypeError('undefined/null cannot be converted to object'); | ||
} | ||
return Object(arg); | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-getoption | ||
* @param opts | ||
* @param prop | ||
* @param type | ||
* @param values | ||
* @param fallback | ||
*/ | ||
function GetOption(opts, prop, type, values, fallback) { | ||
// const descriptor = Object.getOwnPropertyDescriptor(opts, prop); | ||
var value = opts[prop]; | ||
if (value !== undefined) { | ||
if (type !== 'boolean' && type !== 'string') { | ||
throw new TypeError('invalid type'); | ||
} | ||
if (type === 'boolean') { | ||
value = Boolean(value); | ||
} | ||
if (type === 'string') { | ||
value = ToString(value); | ||
} | ||
if (values !== undefined && !values.filter(function (val) { return val == value; }).length) { | ||
throw new RangeError(value + " is not within " + values.join(', ')); | ||
} | ||
return value; | ||
} | ||
return fallback; | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-getoption | ||
* @param opts | ||
* @param prop | ||
* @param type | ||
* @param values | ||
* @param fallback | ||
*/ | ||
function GetOption(opts, prop, type, values, fallback) { | ||
// const descriptor = Object.getOwnPropertyDescriptor(opts, prop); | ||
var value = opts[prop]; | ||
if (value !== undefined) { | ||
if (type !== 'boolean' && type !== 'string') { | ||
throw new TypeError('invalid type'); | ||
} | ||
if (type === 'boolean') { | ||
value = Boolean(value); | ||
} | ||
if (type === 'string') { | ||
value = ToString(value); | ||
} | ||
if (values !== undefined && !values.filter(function (val) { return val == value; }).length) { | ||
throw new RangeError(value + " is not within " + values.join(', ')); | ||
} | ||
return value; | ||
} | ||
return fallback; | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-bestavailablelocale | ||
* @param availableLocales | ||
* @param locale | ||
*/ | ||
function BestAvailableLocale(availableLocales, locale) { | ||
var candidate = locale; | ||
while (true) { | ||
if (~availableLocales.indexOf(candidate)) { | ||
return candidate; | ||
} | ||
var pos = candidate.lastIndexOf('-'); | ||
if (!~pos) { | ||
return undefined; | ||
} | ||
if (pos >= 2 && candidate[pos - 2] === '-') { | ||
pos -= 2; | ||
} | ||
candidate = candidate.slice(0, pos); | ||
} | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-bestavailablelocale | ||
* @param availableLocales | ||
* @param locale | ||
*/ | ||
function BestAvailableLocale(availableLocales, locale) { | ||
var candidate = locale; | ||
while (true) { | ||
if (~availableLocales.indexOf(candidate)) { | ||
return candidate; | ||
} | ||
var pos = candidate.lastIndexOf('-'); | ||
if (!~pos) { | ||
return undefined; | ||
} | ||
if (pos >= 2 && candidate[pos - 2] === '-') { | ||
pos -= 2; | ||
} | ||
candidate = candidate.slice(0, pos); | ||
} | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-lookupmatcher | ||
* @param availableLocales | ||
* @param requestedLocales | ||
* @param getDefaultLocale | ||
*/ | ||
function LookupMatcher(availableLocales, requestedLocales, getDefaultLocale) { | ||
var result = { locale: '' }; | ||
for (var _i = 0, requestedLocales_1 = requestedLocales; _i < requestedLocales_1.length; _i++) { | ||
var locale = requestedLocales_1[_i]; | ||
var noExtensionLocale = locale.replace(UNICODE_EXTENSION_SEQUENCE_REGEX, ''); | ||
var availableLocale = BestAvailableLocale(availableLocales, noExtensionLocale); | ||
if (availableLocale) { | ||
result.locale = availableLocale; | ||
if (locale !== noExtensionLocale) { | ||
result.extension = locale.slice(noExtensionLocale.length + 1, locale.length); | ||
} | ||
return result; | ||
} | ||
} | ||
result.locale = getDefaultLocale(); | ||
return result; | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-lookupmatcher | ||
* @param availableLocales | ||
* @param requestedLocales | ||
* @param getDefaultLocale | ||
*/ | ||
function LookupMatcher(availableLocales, requestedLocales, getDefaultLocale) { | ||
var result = { locale: '' }; | ||
for (var _i = 0, requestedLocales_1 = requestedLocales; _i < requestedLocales_1.length; _i++) { | ||
var locale = requestedLocales_1[_i]; | ||
var noExtensionLocale = locale.replace(UNICODE_EXTENSION_SEQUENCE_REGEX, ''); | ||
var availableLocale = BestAvailableLocale(availableLocales, noExtensionLocale); | ||
if (availableLocale) { | ||
result.locale = availableLocale; | ||
if (locale !== noExtensionLocale) { | ||
result.extension = locale.slice(noExtensionLocale.length + 1, locale.length); | ||
} | ||
return result; | ||
} | ||
} | ||
result.locale = getDefaultLocale(); | ||
return result; | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-bestfitmatcher | ||
* @param availableLocales | ||
* @param requestedLocales | ||
* @param getDefaultLocale | ||
*/ | ||
function BestFitMatcher(availableLocales, requestedLocales, getDefaultLocale) { | ||
var result = { locale: '' }; | ||
for (var _i = 0, requestedLocales_1 = requestedLocales; _i < requestedLocales_1.length; _i++) { | ||
var locale = requestedLocales_1[_i]; | ||
var noExtensionLocale = locale.replace(UNICODE_EXTENSION_SEQUENCE_REGEX, ''); | ||
var availableLocale = BestAvailableLocale(availableLocales, noExtensionLocale); | ||
if (availableLocale) { | ||
result.locale = availableLocale; | ||
if (locale !== noExtensionLocale) { | ||
result.extension = locale.slice(noExtensionLocale.length + 1, locale.length); | ||
} | ||
return result; | ||
} | ||
} | ||
result.locale = getDefaultLocale(); | ||
return result; | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-bestfitmatcher | ||
* @param availableLocales | ||
* @param requestedLocales | ||
* @param getDefaultLocale | ||
*/ | ||
function BestFitMatcher(availableLocales, requestedLocales, getDefaultLocale) { | ||
var result = { locale: '' }; | ||
for (var _i = 0, requestedLocales_1 = requestedLocales; _i < requestedLocales_1.length; _i++) { | ||
var locale = requestedLocales_1[_i]; | ||
var noExtensionLocale = locale.replace(UNICODE_EXTENSION_SEQUENCE_REGEX, ''); | ||
var availableLocale = BestAvailableLocale(availableLocales, noExtensionLocale); | ||
if (availableLocale) { | ||
result.locale = availableLocale; | ||
if (locale !== noExtensionLocale) { | ||
result.extension = locale.slice(noExtensionLocale.length + 1, locale.length); | ||
} | ||
return result; | ||
} | ||
} | ||
result.locale = getDefaultLocale(); | ||
return result; | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-unicodeextensionvalue | ||
* @param extension | ||
* @param key | ||
*/ | ||
function UnicodeExtensionValue(extension, key) { | ||
invariant(key.length === 2, 'key must have 2 elements'); | ||
var size = extension.length; | ||
var searchValue = "-" + key + "-"; | ||
var pos = extension.indexOf(searchValue); | ||
if (pos !== -1) { | ||
var start = pos + 4; | ||
var end = start; | ||
var k = start; | ||
var done = false; | ||
while (!done) { | ||
var e = extension.indexOf('-', k); | ||
var len = void 0; | ||
if (e === -1) { | ||
len = size - k; | ||
} | ||
else { | ||
len = e - k; | ||
} | ||
if (len === 2) { | ||
done = true; | ||
} | ||
else if (e === -1) { | ||
end = size; | ||
done = true; | ||
} | ||
else { | ||
end = e; | ||
k = e + 1; | ||
} | ||
} | ||
return extension.slice(start, end); | ||
} | ||
searchValue = "-" + key; | ||
pos = extension.indexOf(searchValue); | ||
if (pos !== -1 && pos + 3 === size) { | ||
return ''; | ||
} | ||
return undefined; | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-unicodeextensionvalue | ||
* @param extension | ||
* @param key | ||
*/ | ||
function UnicodeExtensionValue(extension, key) { | ||
invariant(key.length === 2, 'key must have 2 elements'); | ||
var size = extension.length; | ||
var searchValue = "-" + key + "-"; | ||
var pos = extension.indexOf(searchValue); | ||
if (pos !== -1) { | ||
var start = pos + 4; | ||
var end = start; | ||
var k = start; | ||
var done = false; | ||
while (!done) { | ||
var e = extension.indexOf('-', k); | ||
var len = void 0; | ||
if (e === -1) { | ||
len = size - k; | ||
} | ||
else { | ||
len = e - k; | ||
} | ||
if (len === 2) { | ||
done = true; | ||
} | ||
else if (e === -1) { | ||
end = size; | ||
done = true; | ||
} | ||
else { | ||
end = e; | ||
k = e + 1; | ||
} | ||
} | ||
return extension.slice(start, end); | ||
} | ||
searchValue = "-" + key; | ||
pos = extension.indexOf(searchValue); | ||
if (pos !== -1 && pos + 3 === size) { | ||
return ''; | ||
} | ||
return undefined; | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-resolvelocale | ||
*/ | ||
function ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData, getDefaultLocale) { | ||
var matcher = options.localeMatcher; | ||
var r; | ||
if (matcher === 'lookup') { | ||
r = LookupMatcher(availableLocales, requestedLocales, getDefaultLocale); | ||
} | ||
else { | ||
r = BestFitMatcher(availableLocales, requestedLocales, getDefaultLocale); | ||
} | ||
var foundLocale = r.locale; | ||
var result = { locale: '', dataLocale: foundLocale }; | ||
var supportedExtension = '-u'; | ||
for (var _i = 0, relevantExtensionKeys_1 = relevantExtensionKeys; _i < relevantExtensionKeys_1.length; _i++) { | ||
var key = relevantExtensionKeys_1[_i]; | ||
var foundLocaleData = localeData[foundLocale]; | ||
invariant(typeof foundLocaleData === 'object' && foundLocaleData !== null, "locale data " + key + " must be an object"); | ||
var keyLocaleData = foundLocaleData[key]; | ||
invariant(Array.isArray(keyLocaleData), "keyLocaleData for " + key + " must be an array"); | ||
var value = keyLocaleData[0]; | ||
invariant(typeof value === 'string' || value === null, "value must be string or null but got " + typeof value + " in key " + key); | ||
var supportedExtensionAddition = ''; | ||
if (r.extension) { | ||
var requestedValue = UnicodeExtensionValue(r.extension, key); | ||
if (requestedValue !== undefined) { | ||
if (requestedValue !== '') { | ||
if (~keyLocaleData.indexOf(requestedValue)) { | ||
value = requestedValue; | ||
supportedExtensionAddition = "-" + key + "-" + value; | ||
} | ||
} | ||
else if (~requestedValue.indexOf('true')) { | ||
value = 'true'; | ||
supportedExtensionAddition = "-" + key; | ||
} | ||
} | ||
} | ||
if (key in options) { | ||
var optionsValue = options[key]; | ||
invariant(typeof optionsValue === 'string' || | ||
typeof optionsValue === 'undefined' || | ||
optionsValue === null, 'optionsValue must be String, Undefined or Null'); | ||
if (~keyLocaleData.indexOf(optionsValue)) { | ||
if (optionsValue !== value) { | ||
value = optionsValue; | ||
supportedExtensionAddition = ''; | ||
} | ||
} | ||
} | ||
result[key] = value; | ||
supportedExtension += supportedExtensionAddition; | ||
} | ||
if (supportedExtension.length > 2) { | ||
var privateIndex = foundLocale.indexOf('-x-'); | ||
if (privateIndex === -1) { | ||
foundLocale = foundLocale + supportedExtension; | ||
} | ||
else { | ||
var preExtension = foundLocale.slice(0, privateIndex); | ||
var postExtension = foundLocale.slice(privateIndex, foundLocale.length); | ||
foundLocale = preExtension + supportedExtension + postExtension; | ||
} | ||
foundLocale = Intl.getCanonicalLocales(foundLocale)[0]; | ||
} | ||
result.locale = foundLocale; | ||
return result; | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-resolvelocale | ||
*/ | ||
function ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData, getDefaultLocale) { | ||
var matcher = options.localeMatcher; | ||
var r; | ||
if (matcher === 'lookup') { | ||
r = LookupMatcher(availableLocales, requestedLocales, getDefaultLocale); | ||
} | ||
else { | ||
r = BestFitMatcher(availableLocales, requestedLocales, getDefaultLocale); | ||
} | ||
var foundLocale = r.locale; | ||
var result = { locale: '', dataLocale: foundLocale }; | ||
var supportedExtension = '-u'; | ||
for (var _i = 0, relevantExtensionKeys_1 = relevantExtensionKeys; _i < relevantExtensionKeys_1.length; _i++) { | ||
var key = relevantExtensionKeys_1[_i]; | ||
var foundLocaleData = localeData[foundLocale]; | ||
invariant(typeof foundLocaleData === 'object' && foundLocaleData !== null, "locale data " + key + " must be an object"); | ||
var keyLocaleData = foundLocaleData[key]; | ||
invariant(Array.isArray(keyLocaleData), "keyLocaleData for " + key + " must be an array"); | ||
var value = keyLocaleData[0]; | ||
invariant(typeof value === 'string' || value === null, "value must be string or null but got " + typeof value + " in key " + key); | ||
var supportedExtensionAddition = ''; | ||
if (r.extension) { | ||
var requestedValue = UnicodeExtensionValue(r.extension, key); | ||
if (requestedValue !== undefined) { | ||
if (requestedValue !== '') { | ||
if (~keyLocaleData.indexOf(requestedValue)) { | ||
value = requestedValue; | ||
supportedExtensionAddition = "-" + key + "-" + value; | ||
} | ||
} | ||
else if (~requestedValue.indexOf('true')) { | ||
value = 'true'; | ||
supportedExtensionAddition = "-" + key; | ||
} | ||
} | ||
} | ||
if (key in options) { | ||
var optionsValue = options[key]; | ||
invariant(typeof optionsValue === 'string' || | ||
typeof optionsValue === 'undefined' || | ||
optionsValue === null, 'optionsValue must be String, Undefined or Null'); | ||
if (~keyLocaleData.indexOf(optionsValue)) { | ||
if (optionsValue !== value) { | ||
value = optionsValue; | ||
supportedExtensionAddition = ''; | ||
} | ||
} | ||
} | ||
result[key] = value; | ||
supportedExtension += supportedExtensionAddition; | ||
} | ||
if (supportedExtension.length > 2) { | ||
var privateIndex = foundLocale.indexOf('-x-'); | ||
if (privateIndex === -1) { | ||
foundLocale = foundLocale + supportedExtension; | ||
} | ||
else { | ||
var preExtension = foundLocale.slice(0, privateIndex); | ||
var postExtension = foundLocale.slice(privateIndex, foundLocale.length); | ||
foundLocale = preExtension + supportedExtension + postExtension; | ||
} | ||
foundLocale = Intl.getCanonicalLocales(foundLocale)[0]; | ||
} | ||
result.locale = foundLocale; | ||
return result; | ||
} | ||
/** | ||
* This follows https://tc39.es/ecma402/#sec-case-sensitivity-and-case-mapping | ||
* @param str string to convert | ||
*/ | ||
function toUpperCase(str) { | ||
return str.replace(/([a-z])/g, function (_, c) { return c.toUpperCase(); }); | ||
} | ||
var NOT_A_Z_REGEX = /[^A-Z]/; | ||
/** | ||
* https://tc39.es/ecma402/#sec-iswellformedcurrencycode | ||
*/ | ||
function IsWellFormedCurrencyCode(currency) { | ||
currency = toUpperCase(currency); | ||
if (currency.length !== 3) { | ||
return false; | ||
} | ||
if (NOT_A_Z_REGEX.test(currency)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
/** | ||
* This follows https://tc39.es/ecma402/#sec-case-sensitivity-and-case-mapping | ||
* @param str string to convert | ||
*/ | ||
function toUpperCase(str) { | ||
return str.replace(/([a-z])/g, function (_, c) { return c.toUpperCase(); }); | ||
} | ||
var NOT_A_Z_REGEX = /[^A-Z]/; | ||
/** | ||
* https://tc39.es/ecma402/#sec-iswellformedcurrencycode | ||
*/ | ||
function IsWellFormedCurrencyCode(currency) { | ||
currency = toUpperCase(currency); | ||
if (currency.length !== 3) { | ||
return false; | ||
} | ||
if (NOT_A_Z_REGEX.test(currency)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-lookupsupportedlocales | ||
* @param availableLocales | ||
* @param requestedLocales | ||
*/ | ||
function LookupSupportedLocales(availableLocales, requestedLocales) { | ||
var subset = []; | ||
for (var _i = 0, requestedLocales_1 = requestedLocales; _i < requestedLocales_1.length; _i++) { | ||
var locale = requestedLocales_1[_i]; | ||
var noExtensionLocale = locale.replace(UNICODE_EXTENSION_SEQUENCE_REGEX, ''); | ||
var availableLocale = BestAvailableLocale(availableLocales, noExtensionLocale); | ||
if (availableLocale) { | ||
subset.push(availableLocale); | ||
} | ||
} | ||
return subset; | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-lookupsupportedlocales | ||
* @param availableLocales | ||
* @param requestedLocales | ||
*/ | ||
function LookupSupportedLocales(availableLocales, requestedLocales) { | ||
var subset = []; | ||
for (var _i = 0, requestedLocales_1 = requestedLocales; _i < requestedLocales_1.length; _i++) { | ||
var locale = requestedLocales_1[_i]; | ||
var noExtensionLocale = locale.replace(UNICODE_EXTENSION_SEQUENCE_REGEX, ''); | ||
var availableLocale = BestAvailableLocale(availableLocales, noExtensionLocale); | ||
if (availableLocale) { | ||
subset.push(availableLocale); | ||
} | ||
} | ||
return subset; | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-supportedlocales | ||
* @param availableLocales | ||
* @param requestedLocales | ||
* @param options | ||
*/ | ||
function SupportedLocales(availableLocales, requestedLocales, options) { | ||
var matcher = 'best fit'; | ||
if (options !== undefined) { | ||
options = ToObject(options); | ||
matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit'); | ||
} | ||
if (matcher === 'best fit') { | ||
return LookupSupportedLocales(availableLocales, requestedLocales); | ||
} | ||
return LookupSupportedLocales(availableLocales, requestedLocales); | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-supportedlocales | ||
* @param availableLocales | ||
* @param requestedLocales | ||
* @param options | ||
*/ | ||
function SupportedLocales(availableLocales, requestedLocales, options) { | ||
var matcher = 'best fit'; | ||
if (options !== undefined) { | ||
options = ToObject(options); | ||
matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit'); | ||
} | ||
if (matcher === 'best fit') { | ||
return LookupSupportedLocales(availableLocales, requestedLocales); | ||
} | ||
return LookupSupportedLocales(availableLocales, requestedLocales); | ||
} | ||
var __extends = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (undefined && undefined.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function getLocaleHierarchy(locale) { | ||
var results = [locale]; | ||
var localeParts = locale.split('-'); | ||
for (var i = localeParts.length; i > 1; i--) { | ||
results.push(localeParts.slice(0, i - 1).join('-')); | ||
} | ||
return results; | ||
} | ||
var MissingLocaleDataError = /** @class */ (function (_super) { | ||
__extends(MissingLocaleDataError, _super); | ||
function MissingLocaleDataError() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.type = 'MISSING_LOCALE_DATA'; | ||
return _this; | ||
} | ||
return MissingLocaleDataError; | ||
}(Error)); | ||
function unpackData(locale, localeData, | ||
/** By default shallow merge the dictionaries. */ | ||
reducer) { | ||
if (reducer === void 0) { reducer = function (all, d) { return (__assign(__assign({}, all), d)); }; } | ||
var localeHierarchy = getLocaleHierarchy(locale); | ||
var dataToMerge = localeHierarchy | ||
.map(function (l) { return localeData.data[l]; }) | ||
.filter(Boolean); | ||
if (!dataToMerge.length) { | ||
throw new MissingLocaleDataError("Missing locale data for \"" + locale + "\", lookup hierarchy: " + localeHierarchy.join(', ')); | ||
} | ||
dataToMerge.reverse(); | ||
return dataToMerge.reduce(reducer, {}); | ||
} | ||
var __extends = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (undefined && undefined.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function getLocaleHierarchy(locale) { | ||
var results = [locale]; | ||
var localeParts = locale.split('-'); | ||
for (var i = localeParts.length; i > 1; i--) { | ||
results.push(localeParts.slice(0, i - 1).join('-')); | ||
} | ||
return results; | ||
} | ||
var MissingLocaleDataError = /** @class */ (function (_super) { | ||
__extends(MissingLocaleDataError, _super); | ||
function MissingLocaleDataError() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.type = 'MISSING_LOCALE_DATA'; | ||
return _this; | ||
} | ||
return MissingLocaleDataError; | ||
}(Error)); | ||
function unpackData(locale, localeData, | ||
/** By default shallow merge the dictionaries. */ | ||
reducer) { | ||
if (reducer === void 0) { reducer = function (all, d) { return (__assign(__assign({}, all), d)); }; } | ||
var localeHierarchy = getLocaleHierarchy(locale); | ||
var dataToMerge = localeHierarchy | ||
.map(function (l) { return localeData.data[l]; }) | ||
.filter(Boolean); | ||
if (!dataToMerge.length) { | ||
throw new MissingLocaleDataError("Missing locale data for \"" + locale + "\", lookup hierarchy: " + localeHierarchy.join(', ')); | ||
} | ||
dataToMerge.reverse(); | ||
return dataToMerge.reduce(reducer, {}); | ||
} | ||
var __assign$1 = (undefined && undefined.__assign) || function () { | ||
__assign$1 = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign$1.apply(this, arguments); | ||
}; | ||
var DisplayNames = /** @class */ (function () { | ||
function DisplayNames(locales, options) { | ||
var _newTarget = this.constructor; | ||
if (options === void 0) { options = Object.create(null); } | ||
if (_newTarget === undefined) { | ||
throw TypeError("Constructor Intl.DisplayNames requires 'new'"); | ||
} | ||
var requestedLocales = CanonicalizeLocaleList(locales); | ||
var matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit'); | ||
var r = ResolveLocale(DisplayNames.availableLocales, requestedLocales, { localeMatcher: matcher }, [], // there is no relevantExtensionKeys | ||
DisplayNames.localeData, DisplayNames.getDefaultLocale); | ||
var style = GetOption(options, 'style', 'string', ['narrow', 'short', 'long'], 'long'); | ||
setSlot(this, 'style', style); | ||
var type = GetOption(options, 'type', 'string', ['language', 'currency', 'region', 'script'], 'language'); | ||
setSlot(this, 'type', type); | ||
var fallback = GetOption(options, 'fallback', 'string', ['code', 'none'], 'code'); | ||
setSlot(this, 'fallback', fallback); | ||
setSlot(this, 'locale', r.locale); | ||
var dataLocale = r.dataLocale; | ||
var dataLocaleData = DisplayNames.localeData[dataLocale]; | ||
invariant(dataLocaleData !== undefined, "locale data for " + r.locale + " does not exist."); | ||
setSlot(this, 'localeData', dataLocaleData); | ||
} | ||
DisplayNames.supportedLocalesOf = function (locales, options) { | ||
return SupportedLocales(DisplayNames.availableLocales, CanonicalizeLocaleList(locales), options); | ||
}; | ||
DisplayNames.__addLocaleData = function () { | ||
var data = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
data[_i] = arguments[_i]; | ||
} | ||
for (var _a = 0, data_1 = data; _a < data_1.length; _a++) { | ||
var datum = data_1[_a]; | ||
var availableLocales = datum.availableLocales; | ||
for (var _b = 0, availableLocales_1 = availableLocales; _b < availableLocales_1.length; _b++) { | ||
var locale = availableLocales_1[_b]; | ||
try { | ||
DisplayNames.localeData[locale] = unpackData(locale, datum); | ||
} | ||
catch (e) { | ||
// If we can't unpack this data, ignore the locale | ||
} | ||
} | ||
} | ||
DisplayNames.availableLocales = Object.keys(DisplayNames.localeData); | ||
if (!DisplayNames.__defaultLocale) { | ||
DisplayNames.__defaultLocale = DisplayNames.availableLocales[0]; | ||
} | ||
}; | ||
DisplayNames.prototype.of = function (code) { | ||
checkReceiver(this, 'of'); | ||
var type = getSlot(this, 'type'); | ||
var codeAsString = ToString(code); | ||
if (!isValidCodeForDisplayNames(type, codeAsString)) { | ||
throw RangeError('invalid code for Intl.DisplayNames.prototype.of'); | ||
} | ||
var _a = getMultiInternalSlots(__INTERNAL_SLOT_MAP__, this, 'localeData', 'style', 'fallback'), localeData = _a.localeData, style = _a.style, fallback = _a.fallback; | ||
// Canonicalize the case. | ||
var canonicalCode; | ||
// This is only used to store extracted language region. | ||
var regionSubTag; | ||
switch (type) { | ||
// Normalize the locale id and remove the region. | ||
case 'language': { | ||
canonicalCode = CanonicalizeLocaleList(codeAsString)[0]; | ||
var regionMatch = /-([a-z]{2}|\d{3})\b/i.exec(canonicalCode); | ||
if (regionMatch) { | ||
// Remove region subtag | ||
canonicalCode = | ||
canonicalCode.substring(0, regionMatch.index) + | ||
canonicalCode.substring(regionMatch.index + regionMatch[0].length); | ||
regionSubTag = regionMatch[1]; | ||
} | ||
break; | ||
} | ||
// currency code should be all upper-case. | ||
case 'currency': | ||
canonicalCode = codeAsString.toUpperCase(); | ||
break; | ||
// script code should be title case | ||
case 'script': | ||
canonicalCode = | ||
codeAsString[0] + codeAsString.substring(1).toLowerCase(); | ||
break; | ||
// region shold be all upper-case | ||
case 'region': | ||
canonicalCode = codeAsString.toUpperCase(); | ||
break; | ||
} | ||
var typesData = localeData.types[type]; | ||
// If the style of choice does not exist, fallback to "long". | ||
var name = typesData[style][canonicalCode] || typesData.long[canonicalCode]; | ||
if (name !== undefined) { | ||
// If there is a region subtag in the language id, use locale pattern to interpolate the region | ||
if (regionSubTag) { | ||
// Retrieve region display names | ||
var regionsData = localeData.types.region; | ||
var regionDisplayName = regionsData[style][regionSubTag] || regionsData.long[regionSubTag]; | ||
if (regionDisplayName || fallback === 'code') { | ||
// Interpolate into locale-specific pattern. | ||
var pattern = localeData.patterns.locale; | ||
return pattern | ||
.replace('{0}', name) | ||
.replace('{1}', regionDisplayName || regionSubTag); | ||
} | ||
} | ||
else { | ||
return name; | ||
} | ||
} | ||
if (fallback === 'code') { | ||
return codeAsString; | ||
} | ||
}; | ||
DisplayNames.prototype.resolvedOptions = function () { | ||
checkReceiver(this, 'resolvedOptions'); | ||
return __assign$1({}, getMultiInternalSlots(__INTERNAL_SLOT_MAP__, this, 'locale', 'style', 'type', 'fallback')); | ||
}; | ||
DisplayNames.getDefaultLocale = function () { | ||
return DisplayNames.__defaultLocale; | ||
}; | ||
DisplayNames.localeData = {}; | ||
DisplayNames.availableLocales = []; | ||
DisplayNames.__defaultLocale = 'en'; | ||
DisplayNames.polyfilled = true; | ||
return DisplayNames; | ||
}()); | ||
// https://tc39.es/proposal-intl-displaynames/#sec-isvalidcodefordisplaynames | ||
function isValidCodeForDisplayNames(type, code) { | ||
switch (type) { | ||
case 'language': | ||
// subset of unicode_language_id | ||
// languageCode ["-" scriptCode] ["-" regionCode] *("-" variant) | ||
// where: | ||
// - languageCode is either a two letters ISO 639-1 language code or a three letters ISO 639-2 language code. | ||
// - scriptCode is should be an ISO-15924 four letters script code | ||
// - regionCode is either an ISO-3166 two letters region code, or a three digits UN M49 Geographic Regions. | ||
return /^[a-z]{2,3}(-[a-z]{4})?(-([a-z]{2}|\d{3}))?(-([a-z\d]{5,8}|\d[a-z\d]{3}))*$/i.test(code); | ||
case 'region': | ||
// unicode_region_subtag | ||
return /^([a-z]{2}|\d{3})$/i.test(code); | ||
case 'script': | ||
// unicode_script_subtag | ||
return /^[a-z]{4}$/i.test(code); | ||
case 'currency': | ||
return IsWellFormedCurrencyCode(code); | ||
} | ||
} | ||
try { | ||
// IE11 does not have Symbol | ||
if (typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
Object.defineProperty(DisplayNames.prototype, Symbol.toStringTag, { | ||
value: 'Intl.DisplayNames', | ||
configurable: true, | ||
enumerable: false, | ||
writable: false, | ||
}); | ||
} | ||
Object.defineProperty(DisplayNames, 'length', { | ||
value: 2, | ||
writable: false, | ||
enumerable: false, | ||
configurable: true, | ||
}); | ||
} | ||
catch (e) { | ||
// Make test 262 compliant | ||
} | ||
var __INTERNAL_SLOT_MAP__ = new WeakMap(); | ||
function getSlot(instance, key) { | ||
return getInternalSlot(__INTERNAL_SLOT_MAP__, instance, key); | ||
} | ||
function setSlot(instance, key, value) { | ||
setInternalSlot(__INTERNAL_SLOT_MAP__, instance, key, value); | ||
} | ||
function checkReceiver(receiver, methodName) { | ||
if (!(receiver instanceof DisplayNames)) { | ||
throw TypeError("Method Intl.DisplayNames.prototype." + methodName + " called on incompatible receiver"); | ||
} | ||
} | ||
var __assign$1 = (undefined && undefined.__assign) || function () { | ||
__assign$1 = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign$1.apply(this, arguments); | ||
}; | ||
var DisplayNames = /** @class */ (function () { | ||
function DisplayNames(locales, options) { | ||
var _newTarget = this.constructor; | ||
if (options === void 0) { options = Object.create(null); } | ||
if (_newTarget === undefined) { | ||
throw TypeError("Constructor Intl.DisplayNames requires 'new'"); | ||
} | ||
var requestedLocales = CanonicalizeLocaleList(locales); | ||
var matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit'); | ||
var r = ResolveLocale(DisplayNames.availableLocales, requestedLocales, { localeMatcher: matcher }, [], // there is no relevantExtensionKeys | ||
DisplayNames.localeData, DisplayNames.getDefaultLocale); | ||
var style = GetOption(options, 'style', 'string', ['narrow', 'short', 'long'], 'long'); | ||
setSlot(this, 'style', style); | ||
var type = GetOption(options, 'type', 'string', ['language', 'currency', 'region', 'script'], 'language'); | ||
setSlot(this, 'type', type); | ||
var fallback = GetOption(options, 'fallback', 'string', ['code', 'none'], 'code'); | ||
setSlot(this, 'fallback', fallback); | ||
setSlot(this, 'locale', r.locale); | ||
var dataLocale = r.dataLocale; | ||
var dataLocaleData = DisplayNames.localeData[dataLocale]; | ||
invariant(dataLocaleData !== undefined, "locale data for " + r.locale + " does not exist."); | ||
setSlot(this, 'localeData', dataLocaleData); | ||
} | ||
DisplayNames.supportedLocalesOf = function (locales, options) { | ||
return SupportedLocales(DisplayNames.availableLocales, CanonicalizeLocaleList(locales), options); | ||
}; | ||
DisplayNames.__addLocaleData = function () { | ||
var data = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
data[_i] = arguments[_i]; | ||
} | ||
for (var _a = 0, data_1 = data; _a < data_1.length; _a++) { | ||
var datum = data_1[_a]; | ||
var availableLocales = datum.availableLocales; | ||
for (var _b = 0, availableLocales_1 = availableLocales; _b < availableLocales_1.length; _b++) { | ||
var locale = availableLocales_1[_b]; | ||
try { | ||
DisplayNames.localeData[locale] = unpackData(locale, datum); | ||
} | ||
catch (e) { | ||
// If we can't unpack this data, ignore the locale | ||
} | ||
} | ||
} | ||
DisplayNames.availableLocales = Object.keys(DisplayNames.localeData); | ||
if (!DisplayNames.__defaultLocale) { | ||
DisplayNames.__defaultLocale = DisplayNames.availableLocales[0]; | ||
} | ||
}; | ||
DisplayNames.prototype.of = function (code) { | ||
checkReceiver(this, 'of'); | ||
var type = getSlot(this, 'type'); | ||
var codeAsString = ToString(code); | ||
if (!isValidCodeForDisplayNames(type, codeAsString)) { | ||
throw RangeError('invalid code for Intl.DisplayNames.prototype.of'); | ||
} | ||
var _a = getMultiInternalSlots(__INTERNAL_SLOT_MAP__, this, 'localeData', 'style', 'fallback'), localeData = _a.localeData, style = _a.style, fallback = _a.fallback; | ||
// Canonicalize the case. | ||
var canonicalCode; | ||
// This is only used to store extracted language region. | ||
var regionSubTag; | ||
switch (type) { | ||
// Normalize the locale id and remove the region. | ||
case 'language': { | ||
canonicalCode = CanonicalizeLocaleList(codeAsString)[0]; | ||
var regionMatch = /-([a-z]{2}|\d{3})\b/i.exec(canonicalCode); | ||
if (regionMatch) { | ||
// Remove region subtag | ||
canonicalCode = | ||
canonicalCode.substring(0, regionMatch.index) + | ||
canonicalCode.substring(regionMatch.index + regionMatch[0].length); | ||
regionSubTag = regionMatch[1]; | ||
} | ||
break; | ||
} | ||
// currency code should be all upper-case. | ||
case 'currency': | ||
canonicalCode = codeAsString.toUpperCase(); | ||
break; | ||
// script code should be title case | ||
case 'script': | ||
canonicalCode = | ||
codeAsString[0] + codeAsString.substring(1).toLowerCase(); | ||
break; | ||
// region shold be all upper-case | ||
case 'region': | ||
canonicalCode = codeAsString.toUpperCase(); | ||
break; | ||
} | ||
var typesData = localeData.types[type]; | ||
// If the style of choice does not exist, fallback to "long". | ||
var name = typesData[style][canonicalCode] || typesData.long[canonicalCode]; | ||
if (name !== undefined) { | ||
// If there is a region subtag in the language id, use locale pattern to interpolate the region | ||
if (regionSubTag) { | ||
// Retrieve region display names | ||
var regionsData = localeData.types.region; | ||
var regionDisplayName = regionsData[style][regionSubTag] || regionsData.long[regionSubTag]; | ||
if (regionDisplayName || fallback === 'code') { | ||
// Interpolate into locale-specific pattern. | ||
var pattern = localeData.patterns.locale; | ||
return pattern | ||
.replace('{0}', name) | ||
.replace('{1}', regionDisplayName || regionSubTag); | ||
} | ||
} | ||
else { | ||
return name; | ||
} | ||
} | ||
if (fallback === 'code') { | ||
return codeAsString; | ||
} | ||
}; | ||
DisplayNames.prototype.resolvedOptions = function () { | ||
checkReceiver(this, 'resolvedOptions'); | ||
return __assign$1({}, getMultiInternalSlots(__INTERNAL_SLOT_MAP__, this, 'locale', 'style', 'type', 'fallback')); | ||
}; | ||
DisplayNames.getDefaultLocale = function () { | ||
return DisplayNames.__defaultLocale; | ||
}; | ||
DisplayNames.localeData = {}; | ||
DisplayNames.availableLocales = []; | ||
DisplayNames.__defaultLocale = 'en'; | ||
DisplayNames.polyfilled = true; | ||
return DisplayNames; | ||
}()); | ||
// https://tc39.es/proposal-intl-displaynames/#sec-isvalidcodefordisplaynames | ||
function isValidCodeForDisplayNames(type, code) { | ||
switch (type) { | ||
case 'language': | ||
// subset of unicode_language_id | ||
// languageCode ["-" scriptCode] ["-" regionCode] *("-" variant) | ||
// where: | ||
// - languageCode is either a two letters ISO 639-1 language code or a three letters ISO 639-2 language code. | ||
// - scriptCode is should be an ISO-15924 four letters script code | ||
// - regionCode is either an ISO-3166 two letters region code, or a three digits UN M49 Geographic Regions. | ||
return /^[a-z]{2,3}(-[a-z]{4})?(-([a-z]{2}|\d{3}))?(-([a-z\d]{5,8}|\d[a-z\d]{3}))*$/i.test(code); | ||
case 'region': | ||
// unicode_region_subtag | ||
return /^([a-z]{2}|\d{3})$/i.test(code); | ||
case 'script': | ||
// unicode_script_subtag | ||
return /^[a-z]{4}$/i.test(code); | ||
case 'currency': | ||
return IsWellFormedCurrencyCode(code); | ||
} | ||
} | ||
try { | ||
// IE11 does not have Symbol | ||
if (typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
Object.defineProperty(DisplayNames.prototype, Symbol.toStringTag, { | ||
value: 'Intl.DisplayNames', | ||
configurable: true, | ||
enumerable: false, | ||
writable: false, | ||
}); | ||
} | ||
Object.defineProperty(DisplayNames, 'length', { | ||
value: 2, | ||
writable: false, | ||
enumerable: false, | ||
configurable: true, | ||
}); | ||
} | ||
catch (e) { | ||
// Make test 262 compliant | ||
} | ||
var __INTERNAL_SLOT_MAP__ = new WeakMap(); | ||
function getSlot(instance, key) { | ||
return getInternalSlot(__INTERNAL_SLOT_MAP__, instance, key); | ||
} | ||
function setSlot(instance, key, value) { | ||
setInternalSlot(__INTERNAL_SLOT_MAP__, instance, key, value); | ||
} | ||
function checkReceiver(receiver, methodName) { | ||
if (!(receiver instanceof DisplayNames)) { | ||
throw TypeError("Method Intl.DisplayNames.prototype." + methodName + " called on incompatible receiver"); | ||
} | ||
} | ||
/** | ||
* https://bugs.chromium.org/p/chromium/issues/detail?id=1097432 | ||
*/ | ||
function hasMissingICUBug() { | ||
if (Intl.DisplayNames) { | ||
var regionNames = new Intl.DisplayNames(['en'], { | ||
type: 'region', | ||
}); | ||
return regionNames.of('CA') === 'CA'; | ||
} | ||
return false; | ||
} | ||
function shouldPolyfill() { | ||
return !Intl.DisplayNames || hasMissingICUBug(); | ||
} | ||
/** | ||
* https://bugs.chromium.org/p/chromium/issues/detail?id=1097432 | ||
*/ | ||
function hasMissingICUBug() { | ||
if (Intl.DisplayNames) { | ||
var regionNames = new Intl.DisplayNames(['en'], { | ||
type: 'region', | ||
}); | ||
return regionNames.of('CA') === 'CA'; | ||
} | ||
return false; | ||
} | ||
function shouldPolyfill() { | ||
return !Intl.DisplayNames || hasMissingICUBug(); | ||
} | ||
if (shouldPolyfill()) { | ||
Object.defineProperty(Intl, 'DisplayNames', { | ||
value: DisplayNames, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true, | ||
}); | ||
} | ||
if (shouldPolyfill()) { | ||
Object.defineProperty(Intl, 'DisplayNames', { | ||
value: DisplayNames, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true, | ||
}); | ||
} | ||
}))); | ||
//# sourceMappingURL=polyfill.umd.js.map |
@@ -1,1 +0,1 @@ | ||
!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e){return Intl.getCanonicalLocales(e)}function t(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var a=e.get(t);if(!a)throw new TypeError(t+" InternalSlot has not been initialized");return n.reduce((function(e,t){return e[t]=a[t],e}),Object.create(null))}var n=/-u(?:-[0-9a-z]{2,8})+/gi;function r(e,t,n){if(void 0===n&&(n=Error),!e)throw new n(t)}function a(e){if("symbol"==typeof e)throw TypeError("Cannot convert a Symbol value to a string");return String(e)}function o(e,t,n,r,o){var l=e[t];if(void 0!==l){if("boolean"!==n&&"string"!==n)throw new TypeError("invalid type");if("boolean"===n&&(l=Boolean(l)),"string"===n&&(l=a(l)),void 0!==r&&!r.filter((function(e){return e==l})).length)throw new RangeError(l+" is not within "+r.join(", "));return l}return o}function l(e,t){for(var n=t;;){if(~e.indexOf(n))return n;var r=n.lastIndexOf("-");if(!~r)return;r>=2&&"-"===n[r-2]&&(r-=2),n=n.slice(0,r)}}function i(e,t){r(2===t.length,"key must have 2 elements");var n=e.length,a="-"+t+"-",o=e.indexOf(a);if(-1!==o){for(var l=o+4,i=l,c=l,u=!1;!u;){var f=e.indexOf("-",c);2==(-1===f?n-c:f-c)?u=!0:-1===f?(i=n,u=!0):(i=f,c=f+1)}return e.slice(l,i)}if(-1!==(o=e.indexOf(a="-"+t))&&o+3===n)return""}var c=/[^A-Z]/;var u,f=(u=function(e,t){return(u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}u(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),s=function(){return(s=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)},p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.type="MISSING_LOCALE_DATA",t}return f(t,e),t}(Error);function g(e,t,n){void 0===n&&(n=function(e,t){return s(s({},e),t)});var r=function a(e){for(var t=[e],n=e.split("-"),r=n.length;r>1;r--)t.push(n.slice(0,r-1).join("-"));return t}(e),o=r.map((function(e){return t.data[e]})).filter(Boolean);if(!o.length)throw new p('Missing locale data for "'+e+'", lookup hierarchy: '+r.join(", "));return o.reverse(),o.reduce(n,{})}var v=function(){return(v=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)},y=function(){function u(t,a){var c=this.constructor;if(void 0===a&&(a=Object.create(null)),void 0===c)throw TypeError("Constructor Intl.DisplayNames requires 'new'");var f=e(t),s=o(a,"localeMatcher","string",["lookup","best fit"],"best fit"),p=function g(e,t,a,o,c,u){for(var f,s=(f="lookup"===a.localeMatcher?function p(e,t,r){for(var a={locale:""},o=0,i=t;o<i.length;o++){var c=i[o],u=c.replace(n,""),f=l(e,u);if(f)return a.locale=f,c!==u&&(a.extension=c.slice(u.length+1,c.length)),a}return a.locale=r(),a}(e,t,u):function g(e,t,r){for(var a={locale:""},o=0,i=t;o<i.length;o++){var c=i[o],u=c.replace(n,""),f=l(e,u);if(f)return a.locale=f,c!==u&&(a.extension=c.slice(u.length+1,c.length)),a}return a.locale=r(),a}(e,t,u)).locale,v={locale:"",dataLocale:s},y="-u",d=0,h=o;d<h.length;d++){var b=h[d],w=c[s];r("object"==typeof w&&null!==w,"locale data "+b+" must be an object");var O=w[b];r(Array.isArray(O),"keyLocaleData for "+b+" must be an array");var m=O[0];r("string"==typeof m||null===m,"value must be string or null but got "+typeof m+" in key "+b);var L="";if(f.extension){var D=i(f.extension,b);void 0!==D&&(""!==D?~O.indexOf(D)&&(L="-"+b+"-"+(m=D)):~D.indexOf("true")&&(m="true",L="-"+b))}if(b in a){var j=a[b];r("string"==typeof j||null==j,"optionsValue must be String, Undefined or Null"),~O.indexOf(j)&&j!==m&&(m=j,L="")}v[b]=m,y+=L}if(y.length>2){var _=s.indexOf("-x-");if(-1===_)s+=y;else{var x=s.slice(0,_),k=s.slice(_,s.length);s=x+y+k}s=Intl.getCanonicalLocales(s)[0]}return v.locale=s,v}(u.availableLocales,f,{localeMatcher:s},[],u.localeData,u.getDefaultLocale);h(this,"style",o(a,"style","string",["narrow","short","long"],"long")),h(this,"type",o(a,"type","string",["language","currency","region","script"],"language")),h(this,"fallback",o(a,"fallback","string",["code","none"],"code")),h(this,"locale",p.locale);var v=u.localeData[p.dataLocale];r(void 0!==v,"locale data for "+p.locale+" does not exist."),h(this,"localeData",v)}return u.supportedLocalesOf=function(t,r){return function a(e,t,r){return void 0!==r&&o(r=function a(e){if(null==e)throw new TypeError("undefined/null cannot be converted to object");return Object(e)}(r),"localeMatcher","string",["lookup","best fit"],"best fit"),function i(e,t){for(var r=[],a=0,o=t;a<o.length;a++){var i=l(e,o[a].replace(n,""));i&&r.push(i)}return r}(e,t)}(u.availableLocales,e(t),r)},u.__addLocaleData=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var n=0,r=e;n<r.length;n++)for(var a=r[n],o=a.availableLocales,l=0,i=o;l<i.length;l++){var c=i[l];try{u.localeData[c]=g(c,a)}catch(e){}}u.availableLocales=Object.keys(u.localeData),u.__defaultLocale||(u.__defaultLocale=u.availableLocales[0])},u.prototype.of=function(n){b(this,"of");var r=function o(e,n){return function r(e,n,a){return t(e,n,a)[a]}(d,e,n)}(this,"type"),l=a(n);if(!function i(e,t){switch(e){case"language":return/^[a-z]{2,3}(-[a-z]{4})?(-([a-z]{2}|\d{3}))?(-([a-z\d]{5,8}|\d[a-z\d]{3}))*$/i.test(t);case"region":return/^([a-z]{2}|\d{3})$/i.test(t);case"script":return/^[a-z]{4}$/i.test(t);case"currency":return function n(e){return 3===(e=function t(e){return e.replace(/([a-z])/g,(function(e,t){return t.toUpperCase()}))}(e)).length&&!c.test(e)}(t)}}(r,l))throw RangeError("invalid code for Intl.DisplayNames.prototype.of");var u,f,s=t(d,this,"localeData","style","fallback"),p=s.localeData,g=s.style,v=s.fallback;switch(r){case"language":u=e(l)[0];var y=/-([a-z]{2}|\d{3})\b/i.exec(u);y&&(u=u.substring(0,y.index)+u.substring(y.index+y[0].length),f=y[1]);break;case"currency":u=l.toUpperCase();break;case"script":u=l[0]+l.substring(1).toLowerCase();break;case"region":u=l.toUpperCase()}var h=p.types[r],w=h[g][u]||h.long[u];if(void 0!==w){if(!f)return w;var O=p.types.region,m=O[g][f]||O.long[f];if(m||"code"===v)return p.patterns.locale.replace("{0}",w).replace("{1}",m||f)}if("code"===v)return l},u.prototype.resolvedOptions=function(){return b(this,"resolvedOptions"),v({},t(d,this,"locale","style","type","fallback"))},u.getDefaultLocale=function(){return u.__defaultLocale},u.localeData={},u.availableLocales=[],u.__defaultLocale="en",u.polyfilled=!0,u}();try{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(y.prototype,Symbol.toStringTag,{value:"Intl.DisplayNames",configurable:!0,enumerable:!1,writable:!1}),Object.defineProperty(y,"length",{value:2,writable:!1,enumerable:!1,configurable:!0})}catch(e){}var d=new WeakMap;function h(e,t,n){!function r(e,t,n,a){e.get(t)||e.set(t,Object.create(null)),e.get(t)[n]=a}(d,e,t,n)}function b(e,t){if(!(e instanceof y))throw TypeError("Method Intl.DisplayNames.prototype."+t+" called on incompatible receiver")}(function w(){return!Intl.DisplayNames||function e(){return!!Intl.DisplayNames&&"CA"===new Intl.DisplayNames(["en"],{type:"region"}).of("CA")}()})()&&Object.defineProperty(Intl,"DisplayNames",{value:y,enumerable:!1,writable:!0,configurable:!0})})); | ||
!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var a=e.get(t);if(!a)throw new TypeError(t+" InternalSlot has not been initialized");return n.reduce((function(e,t){return e[t]=a[t],e}),Object.create(null))}var t=/-u(?:-[0-9a-z]{2,8})+/gi;function n(e,t,n){if(void 0===n&&(n=Error),!e)throw new n(t)}function r(e){return Intl.getCanonicalLocales(e)}function a(e){if("symbol"==typeof e)throw TypeError("Cannot convert a Symbol value to a string");return String(e)}function o(e,t,n,r,o){var l=e[t];if(void 0!==l){if("boolean"!==n&&"string"!==n)throw new TypeError("invalid type");if("boolean"===n&&(l=Boolean(l)),"string"===n&&(l=a(l)),void 0!==r&&!r.filter((function(e){return e==l})).length)throw new RangeError(l+" is not within "+r.join(", "));return l}return o}function l(e,t){for(var n=t;;){if(~e.indexOf(n))return n;var r=n.lastIndexOf("-");if(!~r)return;r>=2&&"-"===n[r-2]&&(r-=2),n=n.slice(0,r)}}function i(e,t){n(2===t.length,"key must have 2 elements");var r=e.length,a="-"+t+"-",o=e.indexOf(a);if(-1!==o){for(var l=o+4,i=l,c=l,u=!1;!u;){var f=e.indexOf("-",c);2==(-1===f?r-c:f-c)?u=!0:-1===f?(i=r,u=!0):(i=f,c=f+1)}return e.slice(l,i)}if(-1!==(o=e.indexOf(a="-"+t))&&o+3===r)return""}var c=/[^A-Z]/;var u,f=(u=function(e,t){return(u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}u(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),s=function(){return(s=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)},p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.type="MISSING_LOCALE_DATA",t}return f(t,e),t}(Error);function g(e,t,n){void 0===n&&(n=function(e,t){return s(s({},e),t)});var r=function a(e){for(var t=[e],n=e.split("-"),r=n.length;r>1;r--)t.push(n.slice(0,r-1).join("-"));return t}(e),o=r.map((function(e){return t.data[e]})).filter(Boolean);if(!o.length)throw new p('Missing locale data for "'+e+'", lookup hierarchy: '+r.join(", "));return o.reverse(),o.reduce(n,{})}var v=function(){return(v=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)},y=function(){function u(e,a){var c=this.constructor;if(void 0===a&&(a=Object.create(null)),void 0===c)throw TypeError("Constructor Intl.DisplayNames requires 'new'");var f=r(e),s=o(a,"localeMatcher","string",["lookup","best fit"],"best fit"),p=function g(e,r,a,o,c,u){for(var f,s=(f="lookup"===a.localeMatcher?function p(e,n,r){for(var a={locale:""},o=0,i=n;o<i.length;o++){var c=i[o],u=c.replace(t,""),f=l(e,u);if(f)return a.locale=f,c!==u&&(a.extension=c.slice(u.length+1,c.length)),a}return a.locale=r(),a}(e,r,u):function g(e,n,r){for(var a={locale:""},o=0,i=n;o<i.length;o++){var c=i[o],u=c.replace(t,""),f=l(e,u);if(f)return a.locale=f,c!==u&&(a.extension=c.slice(u.length+1,c.length)),a}return a.locale=r(),a}(e,r,u)).locale,v={locale:"",dataLocale:s},y="-u",d=0,h=o;d<h.length;d++){var b=h[d],w=c[s];n("object"==typeof w&&null!==w,"locale data "+b+" must be an object");var O=w[b];n(Array.isArray(O),"keyLocaleData for "+b+" must be an array");var m=O[0];n("string"==typeof m||null===m,"value must be string or null but got "+typeof m+" in key "+b);var L="";if(f.extension){var D=i(f.extension,b);void 0!==D&&(""!==D?~O.indexOf(D)&&(L="-"+b+"-"+(m=D)):~D.indexOf("true")&&(m="true",L="-"+b))}if(b in a){var j=a[b];n("string"==typeof j||null==j,"optionsValue must be String, Undefined or Null"),~O.indexOf(j)&&j!==m&&(m=j,L="")}v[b]=m,y+=L}if(y.length>2){var _=s.indexOf("-x-");if(-1===_)s+=y;else{var x=s.slice(0,_),k=s.slice(_,s.length);s=x+y+k}s=Intl.getCanonicalLocales(s)[0]}return v.locale=s,v}(u.availableLocales,f,{localeMatcher:s},[],u.localeData,u.getDefaultLocale);h(this,"style",o(a,"style","string",["narrow","short","long"],"long")),h(this,"type",o(a,"type","string",["language","currency","region","script"],"language")),h(this,"fallback",o(a,"fallback","string",["code","none"],"code")),h(this,"locale",p.locale);var v=u.localeData[p.dataLocale];n(void 0!==v,"locale data for "+p.locale+" does not exist."),h(this,"localeData",v)}return u.supportedLocalesOf=function(e,n){return function a(e,n,r){return void 0!==r&&o(r=function a(e){if(null==e)throw new TypeError("undefined/null cannot be converted to object");return Object(e)}(r),"localeMatcher","string",["lookup","best fit"],"best fit"),function i(e,n){for(var r=[],a=0,o=n;a<o.length;a++){var i=l(e,o[a].replace(t,""));i&&r.push(i)}return r}(e,n)}(u.availableLocales,r(e),n)},u.__addLocaleData=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var n=0,r=e;n<r.length;n++)for(var a=r[n],o=a.availableLocales,l=0,i=o;l<i.length;l++){var c=i[l];try{u.localeData[c]=g(c,a)}catch(e){}}u.availableLocales=Object.keys(u.localeData),u.__defaultLocale||(u.__defaultLocale=u.availableLocales[0])},u.prototype.of=function(t){b(this,"of");var n=function o(t,n){return function r(t,n,a){return e(t,n,a)[a]}(d,t,n)}(this,"type"),l=a(t);if(!function i(e,t){switch(e){case"language":return/^[a-z]{2,3}(-[a-z]{4})?(-([a-z]{2}|\d{3}))?(-([a-z\d]{5,8}|\d[a-z\d]{3}))*$/i.test(t);case"region":return/^([a-z]{2}|\d{3})$/i.test(t);case"script":return/^[a-z]{4}$/i.test(t);case"currency":return function n(e){return 3===(e=function t(e){return e.replace(/([a-z])/g,(function(e,t){return t.toUpperCase()}))}(e)).length&&!c.test(e)}(t)}}(n,l))throw RangeError("invalid code for Intl.DisplayNames.prototype.of");var u,f,s=e(d,this,"localeData","style","fallback"),p=s.localeData,g=s.style,v=s.fallback;switch(n){case"language":u=r(l)[0];var y=/-([a-z]{2}|\d{3})\b/i.exec(u);y&&(u=u.substring(0,y.index)+u.substring(y.index+y[0].length),f=y[1]);break;case"currency":u=l.toUpperCase();break;case"script":u=l[0]+l.substring(1).toLowerCase();break;case"region":u=l.toUpperCase()}var h=p.types[n],w=h[g][u]||h.long[u];if(void 0!==w){if(!f)return w;var O=p.types.region,m=O[g][f]||O.long[f];if(m||"code"===v)return p.patterns.locale.replace("{0}",w).replace("{1}",m||f)}if("code"===v)return l},u.prototype.resolvedOptions=function(){return b(this,"resolvedOptions"),v({},e(d,this,"locale","style","type","fallback"))},u.getDefaultLocale=function(){return u.__defaultLocale},u.localeData={},u.availableLocales=[],u.__defaultLocale="en",u.polyfilled=!0,u}();try{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(y.prototype,Symbol.toStringTag,{value:"Intl.DisplayNames",configurable:!0,enumerable:!1,writable:!1}),Object.defineProperty(y,"length",{value:2,writable:!1,enumerable:!1,configurable:!0})}catch(e){}var d=new WeakMap;function h(e,t,n){!function r(e,t,n,a){e.get(t)||e.set(t,Object.create(null)),e.get(t)[n]=a}(d,e,t,n)}function b(e,t){if(!(e instanceof y))throw TypeError("Method Intl.DisplayNames.prototype."+t+" called on incompatible receiver")}(function w(){return!Intl.DisplayNames||function e(){return!!Intl.DisplayNames&&"CA"===new Intl.DisplayNames(["en"],{type:"region"}).of("CA")}()})()&&Object.defineProperty(Intl,"DisplayNames",{value:y,enumerable:!1,writable:!0,configurable:!0})})); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28833848