intl
Version:
Polyfill the ECMA-402 Intl API (except collation)
1,519 lines (1,305 loc) • 173 kB
JavaScript
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
};
var jsx = function () {
var REACT_ELEMENT_TYPE = typeof Symbol === "function" && Symbol.for && Symbol.for("react.element") || 0xeac7;
return function createRawReactElement(type, props, key, children) {
var defaultProps = type && type.defaultProps;
var childrenLength = arguments.length - 3;
if (!props && childrenLength !== 0) {
props = {};
}
if (props && defaultProps) {
for (var propName in defaultProps) {
if (props[propName] === void 0) {
props[propName] = defaultProps[propName];
}
}
} else if (!props) {
props = defaultProps || {};
}
if (childrenLength === 1) {
props.children = children;
} else if (childrenLength > 1) {
var childArray = Array(childrenLength);
for (var i = 0; i < childrenLength; i++) {
childArray[i] = arguments[i + 3];
}
props.children = childArray;
}
return {
$$typeof: REACT_ELEMENT_TYPE,
type: type,
key: key === undefined ? null : '' + key,
ref: null,
props: props,
_owner: null
};
};
}();
var asyncToGenerator = function (fn) {
return function () {
var gen = fn.apply(this, arguments);
return new Promise(function (resolve, reject) {
function step(key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
return Promise.resolve(value).then(function (value) {
return step("next", value);
}, function (err) {
return step("throw", err);
});
}
}
return step("next");
});
};
};
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var defineEnumerableProperties = function (obj, descs) {
for (var key in descs) {
var desc = descs[key];
desc.configurable = desc.enumerable = true;
if ("value" in desc) desc.writable = true;
Object.defineProperty(obj, key, desc);
}
return obj;
};
var defaults = function (obj, defaults) {
var keys = Object.getOwnPropertyNames(defaults);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var value = Object.getOwnPropertyDescriptor(defaults, key);
if (value && value.configurable && obj[key] === undefined) {
Object.defineProperty(obj, key, value);
}
}
return obj;
};
var defineProperty$1 = function (obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
};
var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
var get = function get(object, property, receiver) {
if (object === null) object = Function.prototype;
var desc = Object.getOwnPropertyDescriptor(object, property);
if (desc === undefined) {
var parent = Object.getPrototypeOf(object);
if (parent === null) {
return undefined;
} else {
return get(parent, property, receiver);
}
} else if ("value" in desc) {
return desc.value;
} else {
var getter = desc.get;
if (getter === undefined) {
return undefined;
}
return getter.call(receiver);
}
};
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
var _instanceof = function (left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
};
var interopRequireDefault = function (obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
};
var interopRequireWildcard = function (obj) {
if (obj && obj.__esModule) {
return obj;
} else {
var newObj = {};
if (obj != null) {
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];
}
}
newObj.default = obj;
return newObj;
}
};
var newArrowCheck = function (innerThis, boundThis) {
if (innerThis !== boundThis) {
throw new TypeError("Cannot instantiate an arrow function");
}
};
var objectDestructuringEmpty = function (obj) {
if (obj == null) throw new TypeError("Cannot destructure undefined");
};
var objectWithoutProperties = function (obj, keys) {
var target = {};
for (var i in obj) {
if (keys.indexOf(i) >= 0) continue;
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
target[i] = obj[i];
}
return target;
};
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
var selfGlobal = typeof global === "undefined" ? self : global;
var set = function set(object, property, value, receiver) {
var desc = Object.getOwnPropertyDescriptor(object, property);
if (desc === undefined) {
var parent = Object.getPrototypeOf(object);
if (parent !== null) {
set(parent, property, value, receiver);
}
} else if ("value" in desc && desc.writable) {
desc.value = value;
} else {
var setter = desc.set;
if (setter !== undefined) {
setter.call(receiver, value);
}
}
return value;
};
var slicedToArray = function () {
function sliceIterator(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"]) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
return function (arr, i) {
if (Array.isArray(arr)) {
return arr;
} else if (Symbol.iterator in Object(arr)) {
return sliceIterator(arr, i);
} else {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
};
}();
var slicedToArrayLoose = function (arr, i) {
if (Array.isArray(arr)) {
return arr;
} else if (Symbol.iterator in Object(arr)) {
var _arr = [];
for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
_arr.push(_step.value);
if (i && _arr.length === i) break;
}
return _arr;
} else {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
};
var taggedTemplateLiteral = function (strings, raw) {
return Object.freeze(Object.defineProperties(strings, {
raw: {
value: Object.freeze(raw)
}
}));
};
var taggedTemplateLiteralLoose = function (strings, raw) {
strings.raw = raw;
return strings;
};
var temporalRef = function (val, name, undef) {
if (val === undef) {
throw new ReferenceError(name + " is not defined - temporal dead zone");
} else {
return val;
}
};
var temporalUndefined = {};
var toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
var toConsumableArray = function (arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
} else {
return Array.from(arr);
}
};
var babelHelpers$1 = Object.freeze({
jsx: jsx,
asyncToGenerator: asyncToGenerator,
classCallCheck: classCallCheck,
createClass: createClass,
defineEnumerableProperties: defineEnumerableProperties,
defaults: defaults,
defineProperty: defineProperty$1,
get: get,
inherits: inherits,
interopRequireDefault: interopRequireDefault,
interopRequireWildcard: interopRequireWildcard,
newArrowCheck: newArrowCheck,
objectDestructuringEmpty: objectDestructuringEmpty,
objectWithoutProperties: objectWithoutProperties,
possibleConstructorReturn: possibleConstructorReturn,
selfGlobal: selfGlobal,
set: set,
slicedToArray: slicedToArray,
slicedToArrayLoose: slicedToArrayLoose,
taggedTemplateLiteral: taggedTemplateLiteral,
taggedTemplateLiteralLoose: taggedTemplateLiteralLoose,
temporalRef: temporalRef,
temporalUndefined: temporalUndefined,
toArray: toArray,
toConsumableArray: toConsumableArray,
typeof: _typeof,
extends: _extends,
instanceof: _instanceof
});
var realDefineProp = function () {
var sentinel = function sentinel() {};
try {
Object.defineProperty(sentinel, 'a', {
get: function get() {
return 1;
}
});
Object.defineProperty(sentinel, 'prototype', { writable: false });
return sentinel.a === 1 && sentinel.prototype instanceof Object;
} catch (e) {
return false;
}
}();
// Need a workaround for getters in ES3
var es3 = !realDefineProp && !Object.prototype.__defineGetter__;
// We use this a lot (and need it for proto-less objects)
var hop = Object.prototype.hasOwnProperty;
// Naive defineProperty for compatibility
var defineProperty = realDefineProp ? Object.defineProperty : function (obj, name, desc) {
if ('get' in desc && obj.__defineGetter__) obj.__defineGetter__(name, desc.get);else if (!hop.call(obj, name) || 'value' in desc) obj[name] = desc.value;
};
// Array.prototype.indexOf, as good as we need it to be
var arrIndexOf = Array.prototype.indexOf || function (search) {
/*jshint validthis:true */
var t = this;
if (!t.length) return -1;
for (var i = arguments[1] || 0, max = t.length; i < max; i++) {
if (t[i] === search) return i;
}
return -1;
};
// Create an object with the specified prototype (2nd arg required for Record)
var objCreate = Object.create || function (proto, props) {
var obj = void 0;
function F() {}
F.prototype = proto;
obj = new F();
for (var k in props) {
if (hop.call(props, k)) defineProperty(obj, k, props[k]);
}
return obj;
};
// Snapshot some (hopefully still) native built-ins
var arrSlice = Array.prototype.slice;
var arrConcat = Array.prototype.concat;
var arrPush = Array.prototype.push;
var arrJoin = Array.prototype.join;
var arrShift = Array.prototype.shift;
// Naive Function.prototype.bind for compatibility
var fnBind = Function.prototype.bind || function (thisObj) {
var fn = this,
args = arrSlice.call(arguments, 1);
// All our (presently) bound functions have either 1 or 0 arguments. By returning
// different function signatures, we can pass some tests in ES3 environments
if (fn.length === 1) {
return function () {
return fn.apply(thisObj, arrConcat.call(args, arrSlice.call(arguments)));
};
}
return function () {
return fn.apply(thisObj, arrConcat.call(args, arrSlice.call(arguments)));
};
};
// Object housing internal properties for constructors
var internals = objCreate(null);
// Keep internal properties internal
var secret = Math.random();
// Helper functions
// ================
/**
* A function to deal with the inaccuracy of calculating log10 in pre-ES6
* JavaScript environments. Math.log(num) / Math.LN10 was responsible for
* causing issue #62.
*/
function log10Floor(n) {
// ES6 provides the more accurate Math.log10
if (typeof Math.log10 === 'function') return Math.floor(Math.log10(n));
var x = Math.round(Math.log(n) * Math.LOG10E);
return x - (Number('1e' + x) > n);
}
/**
* A map that doesn't contain Object in its prototype chain
*/
function Record(obj) {
// Copy only own properties over unless this object is already a Record instance
for (var k in obj) {
if (obj instanceof Record || hop.call(obj, k)) defineProperty(this, k, { value: obj[k], enumerable: true, writable: true, configurable: true });
}
}
Record.prototype = objCreate(null);
/**
* An ordered list
*/
function List() {
defineProperty(this, 'length', { writable: true, value: 0 });
if (arguments.length) arrPush.apply(this, arrSlice.call(arguments));
}
List.prototype = objCreate(null);
/**
* Constructs a regular expression to restore tainted RegExp properties
*/
function createRegExpRestore() {
if (internals.disableRegExpRestore) {
return function () {/* no-op */};
}
var regExpCache = {
lastMatch: RegExp.lastMatch || '',
leftContext: RegExp.leftContext,
multiline: RegExp.multiline,
input: RegExp.input
},
has = false;
// Create a snapshot of all the 'captured' properties
for (var i = 1; i <= 9; i++) {
has = (regExpCache['$' + i] = RegExp['$' + i]) || has;
}return function () {
// Now we've snapshotted some properties, escape the lastMatch string
var esc = /[.?*+^$[\]\\(){}|-]/g,
lm = regExpCache.lastMatch.replace(esc, '\\$&'),
reg = new List();
// If any of the captured strings were non-empty, iterate over them all
if (has) {
for (var _i = 1; _i <= 9; _i++) {
var m = regExpCache['$' + _i];
// If it's empty, add an empty capturing group
if (!m) lm = '()' + lm;
// Else find the string in lm and escape & wrap it to capture it
else {
m = m.replace(esc, '\\$&');
lm = lm.replace(m, '(' + m + ')');
}
// Push it to the reg and chop lm to make sure further groups come after
arrPush.call(reg, lm.slice(0, lm.indexOf('(') + 1));
lm = lm.slice(lm.indexOf('(') + 1);
}
}
var exprStr = arrJoin.call(reg, '') + lm;
// Shorten the regex by replacing each part of the expression with a match
// for a string of that exact length. This is safe for the type of
// expressions generated above, because the expression matches the whole
// match string, so we know each group and each segment between capturing
// groups can be matched by its length alone.
exprStr = exprStr.replace(/(\\\(|\\\)|[^()])+/g, function (match) {
return '[\\s\\S]{' + match.replace('\\', '').length + '}';
});
// Create the regular expression that will reconstruct the RegExp properties
var expr = new RegExp(exprStr, regExpCache.multiline ? 'gm' : 'g');
// Set the lastIndex of the generated expression to ensure that the match
// is found in the correct index.
expr.lastIndex = regExpCache.leftContext.length;
expr.exec(regExpCache.input);
};
}
/**
* Mimics ES5's abstract ToObject() function
*/
function toObject(arg) {
if (arg === null) throw new TypeError('Cannot convert null or undefined to object');
if ((typeof arg === 'undefined' ? 'undefined' : babelHelpers$1['typeof'](arg)) === 'object') return arg;
return Object(arg);
}
function toNumber(arg) {
if (typeof arg === 'number') return arg;
return Number(arg);
}
function toInteger(arg) {
var number = toNumber(arg);
if (isNaN(number)) return 0;
if (number === +0 || number === -0 || number === +Infinity || number === -Infinity) return number;
if (number < 0) return Math.floor(Math.abs(number)) * -1;
return Math.floor(Math.abs(number));
}
function toLength(arg) {
var len = toInteger(arg);
if (len <= 0) return 0;
if (len === Infinity) return Math.pow(2, 53) - 1;
return Math.min(len, Math.pow(2, 53) - 1);
}
/**
* Returns "internal" properties for an object
*/
function getInternalProperties(obj) {
if (hop.call(obj, '__getInternalProperties')) return obj.__getInternalProperties(secret);
return objCreate(null);
}
/**
* Defines regular expressions for various operations related to the BCP 47 syntax,
* as defined at http://tools.ietf.org/html/bcp47#section-2.1
*/
// extlang = 3ALPHA ; selected ISO 639 codes
// *2("-" 3ALPHA) ; permanently reserved
var extlang = '[a-z]{3}(?:-[a-z]{3}){0,2}';
// language = 2*3ALPHA ; shortest ISO 639 code
// ["-" extlang] ; sometimes followed by
// ; extended language subtags
// / 4ALPHA ; or reserved for future use
// / 5*8ALPHA ; or registered language subtag
var language = '(?:[a-z]{2,3}(?:-' + extlang + ')?|[a-z]{4}|[a-z]{5,8})';
// script = 4ALPHA ; ISO 15924 code
var script = '[a-z]{4}';
// region = 2ALPHA ; ISO 3166-1 code
// / 3DIGIT ; UN M.49 code
var region = '(?:[a-z]{2}|\\d{3})';
// variant = 5*8alphanum ; registered variants
// / (DIGIT 3alphanum)
var variant = '(?:[a-z0-9]{5,8}|\\d[a-z0-9]{3})';
// ; Single alphanumerics
// ; "x" reserved for private use
// singleton = DIGIT ; 0 - 9
// / %x41-57 ; A - W
// / %x59-5A ; Y - Z
// / %x61-77 ; a - w
// / %x79-7A ; y - z
var singleton = '[0-9a-wy-z]';
// extension = singleton 1*("-" (2*8alphanum))
var extension = singleton + '(?:-[a-z0-9]{2,8})+';
// privateuse = "x" 1*("-" (1*8alphanum))
var privateuse = 'x(?:-[a-z0-9]{1,8})+';
// irregular = "en-GB-oed" ; irregular tags do not match
// / "i-ami" ; the 'langtag' production and
// / "i-bnn" ; would not otherwise be
// / "i-default" ; considered 'well-formed'
// / "i-enochian" ; These tags are all valid,
// / "i-hak" ; but most are deprecated
// / "i-klingon" ; in favor of more modern
// / "i-lux" ; subtags or subtag
// / "i-mingo" ; combination
// / "i-navajo"
// / "i-pwn"
// / "i-tao"
// / "i-tay"
// / "i-tsu"
// / "sgn-BE-FR"
// / "sgn-BE-NL"
// / "sgn-CH-DE"
var irregular = '(?:en-GB-oed' + '|i-(?:ami|bnn|default|enochian|hak|klingon|lux|mingo|navajo|pwn|tao|tay|tsu)' + '|sgn-(?:BE-FR|BE-NL|CH-DE))';
// regular = "art-lojban" ; these tags match the 'langtag'
// / "cel-gaulish" ; production, but their subtags
// / "no-bok" ; are not extended language
// / "no-nyn" ; or variant subtags: their meaning
// / "zh-guoyu" ; is defined by their registration
// / "zh-hakka" ; and all of these are deprecated
// / "zh-min" ; in favor of a more modern
// / "zh-min-nan" ; subtag or sequence of subtags
// / "zh-xiang"
var regular = '(?:art-lojban|cel-gaulish|no-bok|no-nyn' + '|zh-(?:guoyu|hakka|min|min-nan|xiang))';
// grandfathered = irregular ; non-redundant tags registered
// / regular ; during the RFC 3066 era
var grandfathered = '(?:' + irregular + '|' + regular + ')';
// langtag = language
// ["-" script]
// ["-" region]
// *("-" variant)
// *("-" extension)
// ["-" privateuse]
var langtag = language + '(?:-' + script + ')?(?:-' + region + ')?(?:-' + variant + ')*(?:-' + extension + ')*(?:-' + privateuse + ')?';
// Language-Tag = langtag ; normal language tags
// / privateuse ; private use tag
// / grandfathered ; grandfathered tags
var expBCP47Syntax = RegExp('^(?:' + langtag + '|' + privateuse + '|' + grandfathered + ')$', 'i');
// Match duplicate variants in a language tag
var expVariantDupes = RegExp('^(?!x).*?-(' + variant + ')-(?:\\w{4,8}-(?!x-))*\\1\\b', 'i');
// Match duplicate singletons in a language tag (except in private use)
var expSingletonDupes = RegExp('^(?!x).*?-(' + singleton + ')-(?:\\w+-(?!x-))*\\1\\b', 'i');
// Match all extension sequences
var expExtSequences = RegExp('-' + extension, 'ig');
// Default locale is the first-added locale data for us
var defaultLocale = void 0;
function setDefaultLocale(locale) {
defaultLocale = locale;
}
// IANA Subtag Registry redundant tag and subtag maps
var redundantTags = {
tags: {
"art-lojban": "jbo",
"i-ami": "ami",
"i-bnn": "bnn",
"i-hak": "hak",
"i-klingon": "tlh",
"i-lux": "lb",
"i-navajo": "nv",
"i-pwn": "pwn",
"i-tao": "tao",
"i-tay": "tay",
"i-tsu": "tsu",
"no-bok": "nb",
"no-nyn": "nn",
"sgn-BE-FR": "sfb",
"sgn-BE-NL": "vgt",
"sgn-CH-DE": "sgg",
"zh-guoyu": "cmn",
"zh-hakka": "hak",
"zh-min-nan": "nan",
"zh-xiang": "hsn",
"sgn-BR": "bzs",
"sgn-CO": "csn",
"sgn-DE": "gsg",
"sgn-DK": "dsl",
"sgn-ES": "ssp",
"sgn-FR": "fsl",
"sgn-GB": "bfi",
"sgn-GR": "gss",
"sgn-IE": "isg",
"sgn-IT": "ise",
"sgn-JP": "jsl",
"sgn-MX": "mfs",
"sgn-NI": "ncs",
"sgn-NL": "dse",
"sgn-NO": "nsl",
"sgn-PT": "psr",
"sgn-SE": "swl",
"sgn-US": "ase",
"sgn-ZA": "sfs",
"zh-cmn": "cmn",
"zh-cmn-Hans": "cmn-Hans",
"zh-cmn-Hant": "cmn-Hant",
"zh-gan": "gan",
"zh-wuu": "wuu",
"zh-yue": "yue"
},
subtags: {
BU: "MM",
DD: "DE",
FX: "FR",
TP: "TL",
YD: "YE",
ZR: "CD",
heploc: "alalc97",
'in': "id",
iw: "he",
ji: "yi",
jw: "jv",
mo: "ro",
ayx: "nun",
bjd: "drl",
ccq: "rki",
cjr: "mom",
cka: "cmr",
cmk: "xch",
drh: "khk",
drw: "prs",
gav: "dev",
hrr: "jal",
ibi: "opa",
kgh: "kml",
lcq: "ppr",
mst: "mry",
myt: "mry",
sca: "hle",
tie: "ras",
tkk: "twm",
tlw: "weo",
tnf: "prs",
ybd: "rki",
yma: "lrr"
},
extLang: {
aao: ["aao", "ar"],
abh: ["abh", "ar"],
abv: ["abv", "ar"],
acm: ["acm", "ar"],
acq: ["acq", "ar"],
acw: ["acw", "ar"],
acx: ["acx", "ar"],
acy: ["acy", "ar"],
adf: ["adf", "ar"],
ads: ["ads", "sgn"],
aeb: ["aeb", "ar"],
aec: ["aec", "ar"],
aed: ["aed", "sgn"],
aen: ["aen", "sgn"],
afb: ["afb", "ar"],
afg: ["afg", "sgn"],
ajp: ["ajp", "ar"],
apc: ["apc", "ar"],
apd: ["apd", "ar"],
arb: ["arb", "ar"],
arq: ["arq", "ar"],
ars: ["ars", "ar"],
ary: ["ary", "ar"],
arz: ["arz", "ar"],
ase: ["ase", "sgn"],
asf: ["asf", "sgn"],
asp: ["asp", "sgn"],
asq: ["asq", "sgn"],
asw: ["asw", "sgn"],
auz: ["auz", "ar"],
avl: ["avl", "ar"],
ayh: ["ayh", "ar"],
ayl: ["ayl", "ar"],
ayn: ["ayn", "ar"],
ayp: ["ayp", "ar"],
bbz: ["bbz", "ar"],
bfi: ["bfi", "sgn"],
bfk: ["bfk", "sgn"],
bjn: ["bjn", "ms"],
bog: ["bog", "sgn"],
bqn: ["bqn", "sgn"],
bqy: ["bqy", "sgn"],
btj: ["btj", "ms"],
bve: ["bve", "ms"],
bvl: ["bvl", "sgn"],
bvu: ["bvu", "ms"],
bzs: ["bzs", "sgn"],
cdo: ["cdo", "zh"],
cds: ["cds", "sgn"],
cjy: ["cjy", "zh"],
cmn: ["cmn", "zh"],
coa: ["coa", "ms"],
cpx: ["cpx", "zh"],
csc: ["csc", "sgn"],
csd: ["csd", "sgn"],
cse: ["cse", "sgn"],
csf: ["csf", "sgn"],
csg: ["csg", "sgn"],
csl: ["csl", "sgn"],
csn: ["csn", "sgn"],
csq: ["csq", "sgn"],
csr: ["csr", "sgn"],
czh: ["czh", "zh"],
czo: ["czo", "zh"],
doq: ["doq", "sgn"],
dse: ["dse", "sgn"],
dsl: ["dsl", "sgn"],
dup: ["dup", "ms"],
ecs: ["ecs", "sgn"],
esl: ["esl", "sgn"],
esn: ["esn", "sgn"],
eso: ["eso", "sgn"],
eth: ["eth", "sgn"],
fcs: ["fcs", "sgn"],
fse: ["fse", "sgn"],
fsl: ["fsl", "sgn"],
fss: ["fss", "sgn"],
gan: ["gan", "zh"],
gds: ["gds", "sgn"],
gom: ["gom", "kok"],
gse: ["gse", "sgn"],
gsg: ["gsg", "sgn"],
gsm: ["gsm", "sgn"],
gss: ["gss", "sgn"],
gus: ["gus", "sgn"],
hab: ["hab", "sgn"],
haf: ["haf", "sgn"],
hak: ["hak", "zh"],
hds: ["hds", "sgn"],
hji: ["hji", "ms"],
hks: ["hks", "sgn"],
hos: ["hos", "sgn"],
hps: ["hps", "sgn"],
hsh: ["hsh", "sgn"],
hsl: ["hsl", "sgn"],
hsn: ["hsn", "zh"],
icl: ["icl", "sgn"],
ils: ["ils", "sgn"],
inl: ["inl", "sgn"],
ins: ["ins", "sgn"],
ise: ["ise", "sgn"],
isg: ["isg", "sgn"],
isr: ["isr", "sgn"],
jak: ["jak", "ms"],
jax: ["jax", "ms"],
jcs: ["jcs", "sgn"],
jhs: ["jhs", "sgn"],
jls: ["jls", "sgn"],
jos: ["jos", "sgn"],
jsl: ["jsl", "sgn"],
jus: ["jus", "sgn"],
kgi: ["kgi", "sgn"],
knn: ["knn", "kok"],
kvb: ["kvb", "ms"],
kvk: ["kvk", "sgn"],
kvr: ["kvr", "ms"],
kxd: ["kxd", "ms"],
lbs: ["lbs", "sgn"],
lce: ["lce", "ms"],
lcf: ["lcf", "ms"],
liw: ["liw", "ms"],
lls: ["lls", "sgn"],
lsg: ["lsg", "sgn"],
lsl: ["lsl", "sgn"],
lso: ["lso", "sgn"],
lsp: ["lsp", "sgn"],
lst: ["lst", "sgn"],
lsy: ["lsy", "sgn"],
ltg: ["ltg", "lv"],
lvs: ["lvs", "lv"],
lzh: ["lzh", "zh"],
max: ["max", "ms"],
mdl: ["mdl", "sgn"],
meo: ["meo", "ms"],
mfa: ["mfa", "ms"],
mfb: ["mfb", "ms"],
mfs: ["mfs", "sgn"],
min: ["min", "ms"],
mnp: ["mnp", "zh"],
mqg: ["mqg", "ms"],
mre: ["mre", "sgn"],
msd: ["msd", "sgn"],
msi: ["msi", "ms"],
msr: ["msr", "sgn"],
mui: ["mui", "ms"],
mzc: ["mzc", "sgn"],
mzg: ["mzg", "sgn"],
mzy: ["mzy", "sgn"],
nan: ["nan", "zh"],
nbs: ["nbs", "sgn"],
ncs: ["ncs", "sgn"],
nsi: ["nsi", "sgn"],
nsl: ["nsl", "sgn"],
nsp: ["nsp", "sgn"],
nsr: ["nsr", "sgn"],
nzs: ["nzs", "sgn"],
okl: ["okl", "sgn"],
orn: ["orn", "ms"],
ors: ["ors", "ms"],
pel: ["pel", "ms"],
pga: ["pga", "ar"],
pks: ["pks", "sgn"],
prl: ["prl", "sgn"],
prz: ["prz", "sgn"],
psc: ["psc", "sgn"],
psd: ["psd", "sgn"],
pse: ["pse", "ms"],
psg: ["psg", "sgn"],
psl: ["psl", "sgn"],
pso: ["pso", "sgn"],
psp: ["psp", "sgn"],
psr: ["psr", "sgn"],
pys: ["pys", "sgn"],
rms: ["rms", "sgn"],
rsi: ["rsi", "sgn"],
rsl: ["rsl", "sgn"],
sdl: ["sdl", "sgn"],
sfb: ["sfb", "sgn"],
sfs: ["sfs", "sgn"],
sgg: ["sgg", "sgn"],
sgx: ["sgx", "sgn"],
shu: ["shu", "ar"],
slf: ["slf", "sgn"],
sls: ["sls", "sgn"],
sqk: ["sqk", "sgn"],
sqs: ["sqs", "sgn"],
ssh: ["ssh", "ar"],
ssp: ["ssp", "sgn"],
ssr: ["ssr", "sgn"],
svk: ["svk", "sgn"],
swc: ["swc", "sw"],
swh: ["swh", "sw"],
swl: ["swl", "sgn"],
syy: ["syy", "sgn"],
tmw: ["tmw", "ms"],
tse: ["tse", "sgn"],
tsm: ["tsm", "sgn"],
tsq: ["tsq", "sgn"],
tss: ["tss", "sgn"],
tsy: ["tsy", "sgn"],
tza: ["tza", "sgn"],
ugn: ["ugn", "sgn"],
ugy: ["ugy", "sgn"],
ukl: ["ukl", "sgn"],
uks: ["uks", "sgn"],
urk: ["urk", "ms"],
uzn: ["uzn", "uz"],
uzs: ["uzs", "uz"],
vgt: ["vgt", "sgn"],
vkk: ["vkk", "ms"],
vkt: ["vkt", "ms"],
vsi: ["vsi", "sgn"],
vsl: ["vsl", "sgn"],
vsv: ["vsv", "sgn"],
wuu: ["wuu", "zh"],
xki: ["xki", "sgn"],
xml: ["xml", "sgn"],
xmm: ["xmm", "ms"],
xms: ["xms", "sgn"],
yds: ["yds", "sgn"],
ysl: ["ysl", "sgn"],
yue: ["yue", "zh"],
zib: ["zib", "sgn"],
zlm: ["zlm", "ms"],
zmi: ["zmi", "ms"],
zsl: ["zsl", "sgn"],
zsm: ["zsm", "ms"]
}
};
/**
* Convert only a-z to uppercase as per section 6.1 of the spec
*/
function toLatinUpperCase(str) {
var i = str.length;
while (i--) {
var ch = str.charAt(i);
if (ch >= "a" && ch <= "z") str = str.slice(0, i) + ch.toUpperCase() + str.slice(i + 1);
}
return str;
}
/**
* The IsStructurallyValidLanguageTag abstract operation verifies that the locale
* argument (which must be a String value)
*
* - represents a well-formed BCP 47 language tag as specified in RFC 5646 section
* 2.1, or successor,
* - does not include duplicate variant subtags, and
* - does not include duplicate singleton subtags.
*
* The abstract operation returns true if locale can be generated from the ABNF
* grammar in section 2.1 of the RFC, starting with Language-Tag, and does not
* contain duplicate variant or singleton subtags (other than as a private use
* subtag). It returns false otherwise. Terminal value characters in the grammar are
* interpreted as the Unicode equivalents of the ASCII octet values given.
*/
function /* 6.2.2 */IsStructurallyValidLanguageTag(locale) {
// represents a well-formed BCP 47 language tag as specified in RFC 5646
if (!expBCP47Syntax.test(locale)) return false;
// does not include duplicate variant subtags, and
if (expVariantDupes.test(locale)) return false;
// does not include duplicate singleton subtags.
if (expSingletonDupes.test(locale)) return false;
return true;
}
/**
* The CanonicalizeLanguageTag abstract operation returns the canonical and case-
* regularized form of the locale argument (which must be a String value that is
* a structurally valid BCP 47 language tag as verified by the
* IsStructurallyValidLanguageTag abstract operation). It takes the steps
* specified in RFC 5646 section 4.5, or successor, to bring the language tag
* into canonical form, and to regularize the case of the subtags, but does not
* take the steps to bring a language tag into “extlang form” and to reorder
* variant subtags.
* The specifications for extensions to BCP 47 language tags, such as RFC 6067,
* may include canonicalization rules for the extension subtag sequences they
* define that go beyond the canonicalization rules of RFC 5646 section 4.5.
* Implementations are allowed, but not required, to apply these additional rules.
*/
function /* 6.2.3 */CanonicalizeLanguageTag(locale) {
var match = void 0,
parts = void 0;
// A language tag is in 'canonical form' when the tag is well-formed
// according to the rules in Sections 2.1 and 2.2
// Section 2.1 says all subtags use lowercase...
locale = locale.toLowerCase();
// ...with 2 exceptions: 'two-letter and four-letter subtags that neither
// appear at the start of the tag nor occur after singletons. Such two-letter
// subtags are all uppercase (as in the tags "en-CA-x-ca" or "sgn-BE-FR") and
// four-letter subtags are titlecase (as in the tag "az-Latn-x-latn").
parts = locale.split('-');
for (var i = 1, max = parts.length; i < max; i++) {
// Two-letter subtags are all uppercase
if (parts[i].length === 2) parts[i] = parts[i].toUpperCase();
// Four-letter subtags are titlecase
else if (parts[i].length === 4) parts[i] = parts[i].charAt(0).toUpperCase() + parts[i].slice(1);
// Is it a singleton?
else if (parts[i].length === 1 && parts[i] !== 'x') break;
}
locale = arrJoin.call(parts, '-');
// The steps laid out in RFC 5646 section 4.5 are as follows:
// 1. Extension sequences are ordered into case-insensitive ASCII order
// by singleton subtag.
if ((match = locale.match(expExtSequences)) && match.length > 1) {
// The built-in sort() sorts by ASCII order, so use that
match.sort();
// Replace all extensions with the joined, sorted array
locale = locale.replace(RegExp('(?:' + expExtSequences.source + ')+', 'i'), arrJoin.call(match, ''));
}
// 2. Redundant or grandfathered tags are replaced by their 'Preferred-
// Value', if there is one.
if (hop.call(redundantTags.tags, locale)) locale = redundantTags.tags[locale];
// 3. Subtags are replaced by their 'Preferred-Value', if there is one.
// For extlangs, the original primary language subtag is also
// replaced if there is a primary language subtag in the 'Preferred-
// Value'.
parts = locale.split('-');
for (var _i = 1, _max = parts.length; _i < _max; _i++) {
if (hop.call(redundantTags.subtags, parts[_i])) parts[_i] = redundantTags.subtags[parts[_i]];else if (hop.call(redundantTags.extLang, parts[_i])) {
parts[_i] = redundantTags.extLang[parts[_i]][0];
// For extlang tags, the prefix needs to be removed if it is redundant
if (_i === 1 && redundantTags.extLang[parts[1]][1] === parts[0]) {
parts = arrSlice.call(parts, _i++);
_max -= 1;
}
}
}
return arrJoin.call(parts, '-');
}
/**
* The DefaultLocale abstract operation returns a String value representing the
* structurally valid (6.2.2) and canonicalized (6.2.3) BCP 47 language tag for the
* host environment’s current locale.
*/
function /* 6.2.4 */DefaultLocale() {
return defaultLocale;
}
// Sect 6.3 Currency Codes
// =======================
var expCurrencyCode = /^[A-Z]{3}$/;
/**
* The IsWellFormedCurrencyCode abstract operation verifies that the currency argument
* (after conversion to a String value) represents a well-formed 3-letter ISO currency
* code. The following steps are taken:
*/
function /* 6.3.1 */IsWellFormedCurrencyCode(currency) {
// 1. Let `c` be ToString(currency)
var c = String(currency);
// 2. Let `normalized` be the result of mapping c to upper case as described
// in 6.1.
var normalized = toLatinUpperCase(c);
// 3. If the string length of normalized is not 3, return false.
// 4. If normalized contains any character that is not in the range "A" to "Z"
// (U+0041 to U+005A), return false.
if (expCurrencyCode.test(normalized) === false) return false;
// 5. Return true
return true;
}
var expUnicodeExSeq = /-u(?:-[0-9a-z]{2,8})+/gi; // See `extension` below
function /* 9.2.1 */CanonicalizeLocaleList(locales) {
// The abstract operation CanonicalizeLocaleList takes the following steps:
// 1. If locales is undefined, then a. Return a new empty List
if (locales === undefined) return new List();
// 2. Let seen be a new empty List.
var seen = new List();
// 3. If locales is a String value, then
// a. Let locales be a new array created as if by the expression new
// Array(locales) where Array is the standard built-in constructor with
// that name and locales is the value of locales.
locales = typeof locales === 'string' ? [locales] : locales;
// 4. Let O be ToObject(locales).
var O = toObject(locales);
// 5. Let lenValue be the result of calling the [[Get]] internal method of
// O with the argument "length".
// 6. Let len be ToUint32(lenValue).
var len = toLength(O.length);
// 7. Let k be 0.
var k = 0;
// 8. Repeat, while k < len
while (k < len) {
// a. Let Pk be ToString(k).
var Pk = String(k);
// b. Let kPresent be the result of calling the [[HasProperty]] internal
// method of O with argument Pk.
var kPresent = Pk in O;
// c. If kPresent is true, then
if (kPresent) {
// i. Let kValue be the result of calling the [[Get]] internal
// method of O with argument Pk.
var kValue = O[Pk];
// ii. If the type of kValue is not String or Object, then throw a
// TypeError exception.
if (kValue === null || typeof kValue !== 'string' && (typeof kValue === "undefined" ? "undefined" : babelHelpers$1["typeof"](kValue)) !== 'object') throw new TypeError('String or Object type expected');
// iii. Let tag be ToString(kValue).
var tag = String(kValue);
// iv. If the result of calling the abstract operation
// IsStructurallyValidLanguageTag (defined in 6.2.2), passing tag as
// the argument, is false, then throw a RangeError exception.
if (!IsStructurallyValidLanguageTag(tag)) throw new RangeError("'" + tag + "' is not a structurally valid language tag");
// v. Let tag be the result of calling the abstract operation
// CanonicalizeLanguageTag (defined in 6.2.3), passing tag as the
// argument.
tag = CanonicalizeLanguageTag(tag);
// vi. If tag is not an element of seen, then append tag as the last
// element of seen.
if (arrIndexOf.call(seen, tag) === -1) arrPush.call(seen, tag);
}
// d. Increase k by 1.
k++;
}
// 9. Return seen.
return seen;
}
/**
* The BestAvailableLocale abstract operation compares the provided argument
* locale, which must be a String value with a structurally valid and
* canonicalized BCP 47 language tag, against the locales in availableLocales and
* returns either the longest non-empty prefix of locale that is an element of
* availableLocales, or undefined if there is no such element. It uses the
* fallback mechanism of RFC 4647, section 3.4. The following steps are taken:
*/
function /* 9.2.2 */BestAvailableLocale(availableLocales, locale) {
// 1. Let candidate be locale
var candidate = locale;
// 2. Repeat
while (candidate) {
// a. If availableLocales contains an element equal to candidate, then return
// candidate.
if (arrIndexOf.call(availableLocales, candidate) > -1) return candidate;
// b. Let pos be the character index of the last occurrence of "-"
// (U+002D) within candidate. If that character does not occur, return
// undefined.
var pos = candidate.lastIndexOf('-');
if (pos < 0) return;
// c. If pos ≥ 2 and the character "-" occurs at index pos-2 of candidate,
// then decrease pos by 2.
if (pos >= 2 && candidate.charAt(pos - 2) === '-') pos -= 2;
// d. Let candidate be the substring of candidate from position 0, inclusive,
// to position pos, exclusive.
candidate = candidate.substring(0, pos);
}
}
/**
* The LookupMatcher abstract operation compares requestedLocales, which must be
* a List as returned by CanonicalizeLocaleList, against the locales in
* availableLocales and determines the best available language to meet the
* request. The following steps are taken:
*/
function /* 9.2.3 */LookupMatcher(availableLocales, requestedLocales) {
// 1. Let i be 0.
var i = 0;
// 2. Let len be the number of elements in requestedLocales.
var len = requestedLocales.length;
// 3. Let availableLocale be undefined.
var availableLocale = void 0;
var locale = void 0,
noExtensionsLocale = void 0;
// 4. Repeat while i < len and availableLocale is undefined:
while (i < len && !availableLocale) {
// a. Let locale be the element of requestedLocales at 0-origined list
// position i.
locale = requestedLocales[i];
// b. Let noExtensionsLocale be the String value that is locale with all
// Unicode locale extension sequences removed.
noExtensionsLocale = String(locale).replace(expUnicodeExSeq, '');
// c. Let availableLocale be the result of calling the
// BestAvailableLocale abstract operation (defined in 9.2.2) with
// arguments availableLocales and noExtensionsLocale.
availableLocale = BestAvailableLocale(availableLocales, noExtensionsLocale);
// d. Increase i by 1.
i++;
}
// 5. Let result be a new Record.
var result = new Record();
// 6. If availableLocale is not undefined, then
if (availableLocale !== undefined) {
// a. Set result.[[locale]] to availableLocale.
result['[[locale]]'] = availableLocale;
// b. If locale and noExtensionsLocale are not the same String value, then
if (String(locale) !== String(noExtensionsLocale)) {
// i. Let extension be the String value consisting of the first
// substring of locale that is a Unicode locale extension sequence.
var extension = locale.match(expUnicodeExSeq)[0];
// ii. Let extensionIndex be the character position of the initial
// "-" of the first Unicode locale extension sequence within locale.
var extensionIndex = locale.indexOf('-u-');
// iii. Set result.[[extension]] to extension.
result['[[extension]]'] = extension;
// iv. Set result.[[extensionIndex]] to extensionIndex.
result['[[extensionIndex]]'] = extensionIndex;
}
}
// 7. Else
else
// a. Set result.[[locale]] to the value returned by the DefaultLocale abstract
// operation (defined in 6.2.4).
result['[[locale]]'] = DefaultLocale();
// 8. Return result
return result;
}
/**
* The BestFitMatcher abstract operation compares requestedLocales, which must be
* a List as returned by CanonicalizeLocaleList, against the locales in
* availableLocales and determines the best available language to meet the
* request. The algorithm is implementation dependent, but should produce results
* that a typical user of the requested locales would perceive as at least as
* good as those produced by the LookupMatcher abstract operation. Options
* specified through Unicode locale extension sequences must be ignored by the
* algorithm. Information about such subsequences is returned separately.
* The abstract operation returns a record with a [[locale]] field, whose value
* is the language tag of the selected locale, which must be an element of
* availableLocales. If the language tag of the request locale that led to the
* selected locale contained a Unicode locale extension sequence, then the
* returned record also contains an [[extension]] field whose value is the first
* Unicode locale extension sequence, and an [[extensionIndex]] field whose value
* is the index of the first Unicode locale extension sequence within the request
* locale language tag.
*/
function /* 9.2.4 */BestFitMatcher(availableLocales, requestedLocales) {
return LookupMatcher(availableLocales, requestedLocales);
}
/**
* The ResolveLocale abstract operation compares a BCP 47 language priority list
* requestedLocales against the locales in availableLocales and determines the
* best available language to meet the request. availableLocales and
* requestedLocales must be provided as List values, options as a Record.
*/
function /* 9.2.5 */ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData) {
if (availableLocales.length === 0) {
throw new ReferenceError('No locale data has been provided for this object yet.');
}
// The following steps are taken:
// 1. Let matcher be the value of options.[[localeMatcher]].
var matcher = options['[[localeMatcher]]'];
var r = void 0;
// 2. If matcher is "lookup", then
if (matcher === 'lookup')
// a. Let r be the result of calling the LookupMatcher abstract operation
// (defined in 9.2.3) with arguments availableLocales and
// requestedLocales.
r = LookupMatcher(availableLocales, requestedLocales);
// 3. Else
else
// a. Let r be the result of calling the BestFitMatcher abstract
// operation (defined in 9.2.4) with arguments availableLocales and
// requestedLocales.
r = BestFitMatcher(availableLocales, requestedLocales);
// 4. Let foundLocale be the value of r.[[locale]].
var foundLocale = r['[[locale]]'];
var extensionSubtags = void 0,
extensionSubtagsLength = void 0;
// 5. If r has an [[extension]] field, then
if (hop.call(r, '[[extension]]')) {
// a. Let extension be the value of r.[[extension]].
var extension = r['[[extension]]'];
// b. Let split be the standard built-in function object defined in ES5,
// 15.5.4.14.
var split = String.prototype.split;
// c. Let extensionSubtags be the result of calling the [[Call]] internal
// method of split with extension as the this value and an argument
// list containing the single item "-".
extensionSubtags = split.call(extension, '-');
// d. Let extensionSubtagsLength be the result of calling the [[Get]]
// internal method of extensionSubtags with argument "length".
extensionSubtagsLength = extensionSubtags.length;
}
// 6. Let result be a new Record.
var result = new Record();
// 7. Set result.[[dataLocale]] to foundLocale.
result['[[dataLocale]]'] = foundLocale;
// 8. Let supportedExtension be "-u".
var supportedExtension = '-u';
// 9. Let i be 0.
var i = 0;
// 10. Let len be the result of calling the [[Get]] internal method of
// relevantExtensionKeys with argument "length".
var len = relevantExtensionKeys.length;
// 11 Repeat while i < len:
while (i < len) {
// a. Let key be the result of calling the [[Get]] internal method of
// relevantExtensionKeys with argument ToString(i).
var key = relevantExtensionKeys[i];
// b. Let foundLocaleData be the result of calling the [[Get]] internal
// method of localeData with the argument foundLocale.
var foundLocaleData = localeData[foundLocale];
// c. Let keyLocaleData be the result of calling the [[Get]] internal
// method of foundLocaleData with the argument key.
var keyLocaleData = foundLocaleData[key];
// d. Let value be the result of calling the [[Get]] internal method of
// keyLocaleData with argument "0".
var value = keyLocaleData['0'];
// e. Let supportedExtensionAddition be "".
var supportedExtensionAddition = '';
// f. Let indexOf be the standard built-in function object defined in
// ES5, 15.4.4.14.
var indexOf = arrIndexOf;
// g. If extensionSubtags is not undefined, then
if (extensionSubtags !== undefined) {
// i. Let keyPos be the result of calling the [[Call]] internal
// method of indexOf with extensionSubtags as the this value and
// an argument list containing the single item key.
var keyPos = indexOf.call(extensionSubtags, key);
// ii. If keyPos ≠ -1, then
if (keyPos !== -1) {
// 1. If keyPos + 1 < extensionSubtagsLength and the length of the
// result of calling the [[Get]] internal method of
// extensionSubtags with argument ToString(keyPos +1) is greater