Intl.js 177 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (global.IntlPolyfill = factory());
  5. }(this, function () { 'use strict';
  6. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  7. return typeof obj;
  8. } : function (obj) {
  9. return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
  10. };
  11. var jsx = function () {
  12. var REACT_ELEMENT_TYPE = typeof Symbol === "function" && Symbol.for && Symbol.for("react.element") || 0xeac7;
  13. return function createRawReactElement(type, props, key, children) {
  14. var defaultProps = type && type.defaultProps;
  15. var childrenLength = arguments.length - 3;
  16. if (!props && childrenLength !== 0) {
  17. props = {};
  18. }
  19. if (props && defaultProps) {
  20. for (var propName in defaultProps) {
  21. if (props[propName] === void 0) {
  22. props[propName] = defaultProps[propName];
  23. }
  24. }
  25. } else if (!props) {
  26. props = defaultProps || {};
  27. }
  28. if (childrenLength === 1) {
  29. props.children = children;
  30. } else if (childrenLength > 1) {
  31. var childArray = Array(childrenLength);
  32. for (var i = 0; i < childrenLength; i++) {
  33. childArray[i] = arguments[i + 3];
  34. }
  35. props.children = childArray;
  36. }
  37. return {
  38. $$typeof: REACT_ELEMENT_TYPE,
  39. type: type,
  40. key: key === undefined ? null : '' + key,
  41. ref: null,
  42. props: props,
  43. _owner: null
  44. };
  45. };
  46. }();
  47. var asyncToGenerator = function (fn) {
  48. return function () {
  49. var gen = fn.apply(this, arguments);
  50. return new Promise(function (resolve, reject) {
  51. function step(key, arg) {
  52. try {
  53. var info = gen[key](arg);
  54. var value = info.value;
  55. } catch (error) {
  56. reject(error);
  57. return;
  58. }
  59. if (info.done) {
  60. resolve(value);
  61. } else {
  62. return Promise.resolve(value).then(function (value) {
  63. return step("next", value);
  64. }, function (err) {
  65. return step("throw", err);
  66. });
  67. }
  68. }
  69. return step("next");
  70. });
  71. };
  72. };
  73. var classCallCheck = function (instance, Constructor) {
  74. if (!(instance instanceof Constructor)) {
  75. throw new TypeError("Cannot call a class as a function");
  76. }
  77. };
  78. var createClass = function () {
  79. function defineProperties(target, props) {
  80. for (var i = 0; i < props.length; i++) {
  81. var descriptor = props[i];
  82. descriptor.enumerable = descriptor.enumerable || false;
  83. descriptor.configurable = true;
  84. if ("value" in descriptor) descriptor.writable = true;
  85. Object.defineProperty(target, descriptor.key, descriptor);
  86. }
  87. }
  88. return function (Constructor, protoProps, staticProps) {
  89. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  90. if (staticProps) defineProperties(Constructor, staticProps);
  91. return Constructor;
  92. };
  93. }();
  94. var defineEnumerableProperties = function (obj, descs) {
  95. for (var key in descs) {
  96. var desc = descs[key];
  97. desc.configurable = desc.enumerable = true;
  98. if ("value" in desc) desc.writable = true;
  99. Object.defineProperty(obj, key, desc);
  100. }
  101. return obj;
  102. };
  103. var defaults = function (obj, defaults) {
  104. var keys = Object.getOwnPropertyNames(defaults);
  105. for (var i = 0; i < keys.length; i++) {
  106. var key = keys[i];
  107. var value = Object.getOwnPropertyDescriptor(defaults, key);
  108. if (value && value.configurable && obj[key] === undefined) {
  109. Object.defineProperty(obj, key, value);
  110. }
  111. }
  112. return obj;
  113. };
  114. var defineProperty$1 = function (obj, key, value) {
  115. if (key in obj) {
  116. Object.defineProperty(obj, key, {
  117. value: value,
  118. enumerable: true,
  119. configurable: true,
  120. writable: true
  121. });
  122. } else {
  123. obj[key] = value;
  124. }
  125. return obj;
  126. };
  127. var _extends = Object.assign || function (target) {
  128. for (var i = 1; i < arguments.length; i++) {
  129. var source = arguments[i];
  130. for (var key in source) {
  131. if (Object.prototype.hasOwnProperty.call(source, key)) {
  132. target[key] = source[key];
  133. }
  134. }
  135. }
  136. return target;
  137. };
  138. var get = function get(object, property, receiver) {
  139. if (object === null) object = Function.prototype;
  140. var desc = Object.getOwnPropertyDescriptor(object, property);
  141. if (desc === undefined) {
  142. var parent = Object.getPrototypeOf(object);
  143. if (parent === null) {
  144. return undefined;
  145. } else {
  146. return get(parent, property, receiver);
  147. }
  148. } else if ("value" in desc) {
  149. return desc.value;
  150. } else {
  151. var getter = desc.get;
  152. if (getter === undefined) {
  153. return undefined;
  154. }
  155. return getter.call(receiver);
  156. }
  157. };
  158. var inherits = function (subClass, superClass) {
  159. if (typeof superClass !== "function" && superClass !== null) {
  160. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  161. }
  162. subClass.prototype = Object.create(superClass && superClass.prototype, {
  163. constructor: {
  164. value: subClass,
  165. enumerable: false,
  166. writable: true,
  167. configurable: true
  168. }
  169. });
  170. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  171. };
  172. var _instanceof = function (left, right) {
  173. if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
  174. return right[Symbol.hasInstance](left);
  175. } else {
  176. return left instanceof right;
  177. }
  178. };
  179. var interopRequireDefault = function (obj) {
  180. return obj && obj.__esModule ? obj : {
  181. default: obj
  182. };
  183. };
  184. var interopRequireWildcard = function (obj) {
  185. if (obj && obj.__esModule) {
  186. return obj;
  187. } else {
  188. var newObj = {};
  189. if (obj != null) {
  190. for (var key in obj) {
  191. if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];
  192. }
  193. }
  194. newObj.default = obj;
  195. return newObj;
  196. }
  197. };
  198. var newArrowCheck = function (innerThis, boundThis) {
  199. if (innerThis !== boundThis) {
  200. throw new TypeError("Cannot instantiate an arrow function");
  201. }
  202. };
  203. var objectDestructuringEmpty = function (obj) {
  204. if (obj == null) throw new TypeError("Cannot destructure undefined");
  205. };
  206. var objectWithoutProperties = function (obj, keys) {
  207. var target = {};
  208. for (var i in obj) {
  209. if (keys.indexOf(i) >= 0) continue;
  210. if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
  211. target[i] = obj[i];
  212. }
  213. return target;
  214. };
  215. var possibleConstructorReturn = function (self, call) {
  216. if (!self) {
  217. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  218. }
  219. return call && (typeof call === "object" || typeof call === "function") ? call : self;
  220. };
  221. var selfGlobal = typeof global === "undefined" ? self : global;
  222. var set = function set(object, property, value, receiver) {
  223. var desc = Object.getOwnPropertyDescriptor(object, property);
  224. if (desc === undefined) {
  225. var parent = Object.getPrototypeOf(object);
  226. if (parent !== null) {
  227. set(parent, property, value, receiver);
  228. }
  229. } else if ("value" in desc && desc.writable) {
  230. desc.value = value;
  231. } else {
  232. var setter = desc.set;
  233. if (setter !== undefined) {
  234. setter.call(receiver, value);
  235. }
  236. }
  237. return value;
  238. };
  239. var slicedToArray = function () {
  240. function sliceIterator(arr, i) {
  241. var _arr = [];
  242. var _n = true;
  243. var _d = false;
  244. var _e = undefined;
  245. try {
  246. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  247. _arr.push(_s.value);
  248. if (i && _arr.length === i) break;
  249. }
  250. } catch (err) {
  251. _d = true;
  252. _e = err;
  253. } finally {
  254. try {
  255. if (!_n && _i["return"]) _i["return"]();
  256. } finally {
  257. if (_d) throw _e;
  258. }
  259. }
  260. return _arr;
  261. }
  262. return function (arr, i) {
  263. if (Array.isArray(arr)) {
  264. return arr;
  265. } else if (Symbol.iterator in Object(arr)) {
  266. return sliceIterator(arr, i);
  267. } else {
  268. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  269. }
  270. };
  271. }();
  272. var slicedToArrayLoose = function (arr, i) {
  273. if (Array.isArray(arr)) {
  274. return arr;
  275. } else if (Symbol.iterator in Object(arr)) {
  276. var _arr = [];
  277. for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
  278. _arr.push(_step.value);
  279. if (i && _arr.length === i) break;
  280. }
  281. return _arr;
  282. } else {
  283. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  284. }
  285. };
  286. var taggedTemplateLiteral = function (strings, raw) {
  287. return Object.freeze(Object.defineProperties(strings, {
  288. raw: {
  289. value: Object.freeze(raw)
  290. }
  291. }));
  292. };
  293. var taggedTemplateLiteralLoose = function (strings, raw) {
  294. strings.raw = raw;
  295. return strings;
  296. };
  297. var temporalRef = function (val, name, undef) {
  298. if (val === undef) {
  299. throw new ReferenceError(name + " is not defined - temporal dead zone");
  300. } else {
  301. return val;
  302. }
  303. };
  304. var temporalUndefined = {};
  305. var toArray = function (arr) {
  306. return Array.isArray(arr) ? arr : Array.from(arr);
  307. };
  308. var toConsumableArray = function (arr) {
  309. if (Array.isArray(arr)) {
  310. for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
  311. return arr2;
  312. } else {
  313. return Array.from(arr);
  314. }
  315. };
  316. var babelHelpers$1 = Object.freeze({
  317. jsx: jsx,
  318. asyncToGenerator: asyncToGenerator,
  319. classCallCheck: classCallCheck,
  320. createClass: createClass,
  321. defineEnumerableProperties: defineEnumerableProperties,
  322. defaults: defaults,
  323. defineProperty: defineProperty$1,
  324. get: get,
  325. inherits: inherits,
  326. interopRequireDefault: interopRequireDefault,
  327. interopRequireWildcard: interopRequireWildcard,
  328. newArrowCheck: newArrowCheck,
  329. objectDestructuringEmpty: objectDestructuringEmpty,
  330. objectWithoutProperties: objectWithoutProperties,
  331. possibleConstructorReturn: possibleConstructorReturn,
  332. selfGlobal: selfGlobal,
  333. set: set,
  334. slicedToArray: slicedToArray,
  335. slicedToArrayLoose: slicedToArrayLoose,
  336. taggedTemplateLiteral: taggedTemplateLiteral,
  337. taggedTemplateLiteralLoose: taggedTemplateLiteralLoose,
  338. temporalRef: temporalRef,
  339. temporalUndefined: temporalUndefined,
  340. toArray: toArray,
  341. toConsumableArray: toConsumableArray,
  342. typeof: _typeof,
  343. extends: _extends,
  344. instanceof: _instanceof
  345. });
  346. var realDefineProp = function () {
  347. var sentinel = function sentinel() {};
  348. try {
  349. Object.defineProperty(sentinel, 'a', {
  350. get: function get() {
  351. return 1;
  352. }
  353. });
  354. Object.defineProperty(sentinel, 'prototype', { writable: false });
  355. return sentinel.a === 1 && sentinel.prototype instanceof Object;
  356. } catch (e) {
  357. return false;
  358. }
  359. }();
  360. // Need a workaround for getters in ES3
  361. var es3 = !realDefineProp && !Object.prototype.__defineGetter__;
  362. // We use this a lot (and need it for proto-less objects)
  363. var hop = Object.prototype.hasOwnProperty;
  364. // Naive defineProperty for compatibility
  365. var defineProperty = realDefineProp ? Object.defineProperty : function (obj, name, desc) {
  366. if ('get' in desc && obj.__defineGetter__) obj.__defineGetter__(name, desc.get);else if (!hop.call(obj, name) || 'value' in desc) obj[name] = desc.value;
  367. };
  368. // Array.prototype.indexOf, as good as we need it to be
  369. var arrIndexOf = Array.prototype.indexOf || function (search) {
  370. /*jshint validthis:true */
  371. var t = this;
  372. if (!t.length) return -1;
  373. for (var i = arguments[1] || 0, max = t.length; i < max; i++) {
  374. if (t[i] === search) return i;
  375. }
  376. return -1;
  377. };
  378. // Create an object with the specified prototype (2nd arg required for Record)
  379. var objCreate = Object.create || function (proto, props) {
  380. var obj = void 0;
  381. function F() {}
  382. F.prototype = proto;
  383. obj = new F();
  384. for (var k in props) {
  385. if (hop.call(props, k)) defineProperty(obj, k, props[k]);
  386. }
  387. return obj;
  388. };
  389. // Snapshot some (hopefully still) native built-ins
  390. var arrSlice = Array.prototype.slice;
  391. var arrConcat = Array.prototype.concat;
  392. var arrPush = Array.prototype.push;
  393. var arrJoin = Array.prototype.join;
  394. var arrShift = Array.prototype.shift;
  395. // Naive Function.prototype.bind for compatibility
  396. var fnBind = Function.prototype.bind || function (thisObj) {
  397. var fn = this,
  398. args = arrSlice.call(arguments, 1);
  399. // All our (presently) bound functions have either 1 or 0 arguments. By returning
  400. // different function signatures, we can pass some tests in ES3 environments
  401. if (fn.length === 1) {
  402. return function () {
  403. return fn.apply(thisObj, arrConcat.call(args, arrSlice.call(arguments)));
  404. };
  405. }
  406. return function () {
  407. return fn.apply(thisObj, arrConcat.call(args, arrSlice.call(arguments)));
  408. };
  409. };
  410. // Object housing internal properties for constructors
  411. var internals = objCreate(null);
  412. // Keep internal properties internal
  413. var secret = Math.random();
  414. // Helper functions
  415. // ================
  416. /**
  417. * A function to deal with the inaccuracy of calculating log10 in pre-ES6
  418. * JavaScript environments. Math.log(num) / Math.LN10 was responsible for
  419. * causing issue #62.
  420. */
  421. function log10Floor(n) {
  422. // ES6 provides the more accurate Math.log10
  423. if (typeof Math.log10 === 'function') return Math.floor(Math.log10(n));
  424. var x = Math.round(Math.log(n) * Math.LOG10E);
  425. return x - (Number('1e' + x) > n);
  426. }
  427. /**
  428. * A map that doesn't contain Object in its prototype chain
  429. */
  430. function Record(obj) {
  431. // Copy only own properties over unless this object is already a Record instance
  432. for (var k in obj) {
  433. if (obj instanceof Record || hop.call(obj, k)) defineProperty(this, k, { value: obj[k], enumerable: true, writable: true, configurable: true });
  434. }
  435. }
  436. Record.prototype = objCreate(null);
  437. /**
  438. * An ordered list
  439. */
  440. function List() {
  441. defineProperty(this, 'length', { writable: true, value: 0 });
  442. if (arguments.length) arrPush.apply(this, arrSlice.call(arguments));
  443. }
  444. List.prototype = objCreate(null);
  445. /**
  446. * Constructs a regular expression to restore tainted RegExp properties
  447. */
  448. function createRegExpRestore() {
  449. if (internals.disableRegExpRestore) {
  450. return function () {/* no-op */};
  451. }
  452. var regExpCache = {
  453. lastMatch: RegExp.lastMatch || '',
  454. leftContext: RegExp.leftContext,
  455. multiline: RegExp.multiline,
  456. input: RegExp.input
  457. },
  458. has = false;
  459. // Create a snapshot of all the 'captured' properties
  460. for (var i = 1; i <= 9; i++) {
  461. has = (regExpCache['$' + i] = RegExp['$' + i]) || has;
  462. }return function () {
  463. // Now we've snapshotted some properties, escape the lastMatch string
  464. var esc = /[.?*+^$[\]\\(){}|-]/g,
  465. lm = regExpCache.lastMatch.replace(esc, '\\$&'),
  466. reg = new List();
  467. // If any of the captured strings were non-empty, iterate over them all
  468. if (has) {
  469. for (var _i = 1; _i <= 9; _i++) {
  470. var m = regExpCache['$' + _i];
  471. // If it's empty, add an empty capturing group
  472. if (!m) lm = '()' + lm;
  473. // Else find the string in lm and escape & wrap it to capture it
  474. else {
  475. m = m.replace(esc, '\\$&');
  476. lm = lm.replace(m, '(' + m + ')');
  477. }
  478. // Push it to the reg and chop lm to make sure further groups come after
  479. arrPush.call(reg, lm.slice(0, lm.indexOf('(') + 1));
  480. lm = lm.slice(lm.indexOf('(') + 1);
  481. }
  482. }
  483. var exprStr = arrJoin.call(reg, '') + lm;
  484. // Shorten the regex by replacing each part of the expression with a match
  485. // for a string of that exact length. This is safe for the type of
  486. // expressions generated above, because the expression matches the whole
  487. // match string, so we know each group and each segment between capturing
  488. // groups can be matched by its length alone.
  489. exprStr = exprStr.replace(/(\\\(|\\\)|[^()])+/g, function (match) {
  490. return '[\\s\\S]{' + match.replace('\\', '').length + '}';
  491. });
  492. // Create the regular expression that will reconstruct the RegExp properties
  493. var expr = new RegExp(exprStr, regExpCache.multiline ? 'gm' : 'g');
  494. // Set the lastIndex of the generated expression to ensure that the match
  495. // is found in the correct index.
  496. expr.lastIndex = regExpCache.leftContext.length;
  497. expr.exec(regExpCache.input);
  498. };
  499. }
  500. /**
  501. * Mimics ES5's abstract ToObject() function
  502. */
  503. function toObject(arg) {
  504. if (arg === null) throw new TypeError('Cannot convert null or undefined to object');
  505. if ((typeof arg === 'undefined' ? 'undefined' : babelHelpers$1['typeof'](arg)) === 'object') return arg;
  506. return Object(arg);
  507. }
  508. function toNumber(arg) {
  509. if (typeof arg === 'number') return arg;
  510. return Number(arg);
  511. }
  512. function toInteger(arg) {
  513. var number = toNumber(arg);
  514. if (isNaN(number)) return 0;
  515. if (number === +0 || number === -0 || number === +Infinity || number === -Infinity) return number;
  516. if (number < 0) return Math.floor(Math.abs(number)) * -1;
  517. return Math.floor(Math.abs(number));
  518. }
  519. function toLength(arg) {
  520. var len = toInteger(arg);
  521. if (len <= 0) return 0;
  522. if (len === Infinity) return Math.pow(2, 53) - 1;
  523. return Math.min(len, Math.pow(2, 53) - 1);
  524. }
  525. /**
  526. * Returns "internal" properties for an object
  527. */
  528. function getInternalProperties(obj) {
  529. if (hop.call(obj, '__getInternalProperties')) return obj.__getInternalProperties(secret);
  530. return objCreate(null);
  531. }
  532. /**
  533. * Defines regular expressions for various operations related to the BCP 47 syntax,
  534. * as defined at http://tools.ietf.org/html/bcp47#section-2.1
  535. */
  536. // extlang = 3ALPHA ; selected ISO 639 codes
  537. // *2("-" 3ALPHA) ; permanently reserved
  538. var extlang = '[a-z]{3}(?:-[a-z]{3}){0,2}';
  539. // language = 2*3ALPHA ; shortest ISO 639 code
  540. // ["-" extlang] ; sometimes followed by
  541. // ; extended language subtags
  542. // / 4ALPHA ; or reserved for future use
  543. // / 5*8ALPHA ; or registered language subtag
  544. var language = '(?:[a-z]{2,3}(?:-' + extlang + ')?|[a-z]{4}|[a-z]{5,8})';
  545. // script = 4ALPHA ; ISO 15924 code
  546. var script = '[a-z]{4}';
  547. // region = 2ALPHA ; ISO 3166-1 code
  548. // / 3DIGIT ; UN M.49 code
  549. var region = '(?:[a-z]{2}|\\d{3})';
  550. // variant = 5*8alphanum ; registered variants
  551. // / (DIGIT 3alphanum)
  552. var variant = '(?:[a-z0-9]{5,8}|\\d[a-z0-9]{3})';
  553. // ; Single alphanumerics
  554. // ; "x" reserved for private use
  555. // singleton = DIGIT ; 0 - 9
  556. // / %x41-57 ; A - W
  557. // / %x59-5A ; Y - Z
  558. // / %x61-77 ; a - w
  559. // / %x79-7A ; y - z
  560. var singleton = '[0-9a-wy-z]';
  561. // extension = singleton 1*("-" (2*8alphanum))
  562. var extension = singleton + '(?:-[a-z0-9]{2,8})+';
  563. // privateuse = "x" 1*("-" (1*8alphanum))
  564. var privateuse = 'x(?:-[a-z0-9]{1,8})+';
  565. // irregular = "en-GB-oed" ; irregular tags do not match
  566. // / "i-ami" ; the 'langtag' production and
  567. // / "i-bnn" ; would not otherwise be
  568. // / "i-default" ; considered 'well-formed'
  569. // / "i-enochian" ; These tags are all valid,
  570. // / "i-hak" ; but most are deprecated
  571. // / "i-klingon" ; in favor of more modern
  572. // / "i-lux" ; subtags or subtag
  573. // / "i-mingo" ; combination
  574. // / "i-navajo"
  575. // / "i-pwn"
  576. // / "i-tao"
  577. // / "i-tay"
  578. // / "i-tsu"
  579. // / "sgn-BE-FR"
  580. // / "sgn-BE-NL"
  581. // / "sgn-CH-DE"
  582. 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))';
  583. // regular = "art-lojban" ; these tags match the 'langtag'
  584. // / "cel-gaulish" ; production, but their subtags
  585. // / "no-bok" ; are not extended language
  586. // / "no-nyn" ; or variant subtags: their meaning
  587. // / "zh-guoyu" ; is defined by their registration
  588. // / "zh-hakka" ; and all of these are deprecated
  589. // / "zh-min" ; in favor of a more modern
  590. // / "zh-min-nan" ; subtag or sequence of subtags
  591. // / "zh-xiang"
  592. var regular = '(?:art-lojban|cel-gaulish|no-bok|no-nyn' + '|zh-(?:guoyu|hakka|min|min-nan|xiang))';
  593. // grandfathered = irregular ; non-redundant tags registered
  594. // / regular ; during the RFC 3066 era
  595. var grandfathered = '(?:' + irregular + '|' + regular + ')';
  596. // langtag = language
  597. // ["-" script]
  598. // ["-" region]
  599. // *("-" variant)
  600. // *("-" extension)
  601. // ["-" privateuse]
  602. var langtag = language + '(?:-' + script + ')?(?:-' + region + ')?(?:-' + variant + ')*(?:-' + extension + ')*(?:-' + privateuse + ')?';
  603. // Language-Tag = langtag ; normal language tags
  604. // / privateuse ; private use tag
  605. // / grandfathered ; grandfathered tags
  606. var expBCP47Syntax = RegExp('^(?:' + langtag + '|' + privateuse + '|' + grandfathered + ')$', 'i');
  607. // Match duplicate variants in a language tag
  608. var expVariantDupes = RegExp('^(?!x).*?-(' + variant + ')-(?:\\w{4,8}-(?!x-))*\\1\\b', 'i');
  609. // Match duplicate singletons in a language tag (except in private use)
  610. var expSingletonDupes = RegExp('^(?!x).*?-(' + singleton + ')-(?:\\w+-(?!x-))*\\1\\b', 'i');
  611. // Match all extension sequences
  612. var expExtSequences = RegExp('-' + extension, 'ig');
  613. // Default locale is the first-added locale data for us
  614. var defaultLocale = void 0;
  615. function setDefaultLocale(locale) {
  616. defaultLocale = locale;
  617. }
  618. // IANA Subtag Registry redundant tag and subtag maps
  619. var redundantTags = {
  620. tags: {
  621. "art-lojban": "jbo",
  622. "i-ami": "ami",
  623. "i-bnn": "bnn",
  624. "i-hak": "hak",
  625. "i-klingon": "tlh",
  626. "i-lux": "lb",
  627. "i-navajo": "nv",
  628. "i-pwn": "pwn",
  629. "i-tao": "tao",
  630. "i-tay": "tay",
  631. "i-tsu": "tsu",
  632. "no-bok": "nb",
  633. "no-nyn": "nn",
  634. "sgn-BE-FR": "sfb",
  635. "sgn-BE-NL": "vgt",
  636. "sgn-CH-DE": "sgg",
  637. "zh-guoyu": "cmn",
  638. "zh-hakka": "hak",
  639. "zh-min-nan": "nan",
  640. "zh-xiang": "hsn",
  641. "sgn-BR": "bzs",
  642. "sgn-CO": "csn",
  643. "sgn-DE": "gsg",
  644. "sgn-DK": "dsl",
  645. "sgn-ES": "ssp",
  646. "sgn-FR": "fsl",
  647. "sgn-GB": "bfi",
  648. "sgn-GR": "gss",
  649. "sgn-IE": "isg",
  650. "sgn-IT": "ise",
  651. "sgn-JP": "jsl",
  652. "sgn-MX": "mfs",
  653. "sgn-NI": "ncs",
  654. "sgn-NL": "dse",
  655. "sgn-NO": "nsl",
  656. "sgn-PT": "psr",
  657. "sgn-SE": "swl",
  658. "sgn-US": "ase",
  659. "sgn-ZA": "sfs",
  660. "zh-cmn": "cmn",
  661. "zh-cmn-Hans": "cmn-Hans",
  662. "zh-cmn-Hant": "cmn-Hant",
  663. "zh-gan": "gan",
  664. "zh-wuu": "wuu",
  665. "zh-yue": "yue"
  666. },
  667. subtags: {
  668. BU: "MM",
  669. DD: "DE",
  670. FX: "FR",
  671. TP: "TL",
  672. YD: "YE",
  673. ZR: "CD",
  674. heploc: "alalc97",
  675. 'in': "id",
  676. iw: "he",
  677. ji: "yi",
  678. jw: "jv",
  679. mo: "ro",
  680. ayx: "nun",
  681. bjd: "drl",
  682. ccq: "rki",
  683. cjr: "mom",
  684. cka: "cmr",
  685. cmk: "xch",
  686. drh: "khk",
  687. drw: "prs",
  688. gav: "dev",
  689. hrr: "jal",
  690. ibi: "opa",
  691. kgh: "kml",
  692. lcq: "ppr",
  693. mst: "mry",
  694. myt: "mry",
  695. sca: "hle",
  696. tie: "ras",
  697. tkk: "twm",
  698. tlw: "weo",
  699. tnf: "prs",
  700. ybd: "rki",
  701. yma: "lrr"
  702. },
  703. extLang: {
  704. aao: ["aao", "ar"],
  705. abh: ["abh", "ar"],
  706. abv: ["abv", "ar"],
  707. acm: ["acm", "ar"],
  708. acq: ["acq", "ar"],
  709. acw: ["acw", "ar"],
  710. acx: ["acx", "ar"],
  711. acy: ["acy", "ar"],
  712. adf: ["adf", "ar"],
  713. ads: ["ads", "sgn"],
  714. aeb: ["aeb", "ar"],
  715. aec: ["aec", "ar"],
  716. aed: ["aed", "sgn"],
  717. aen: ["aen", "sgn"],
  718. afb: ["afb", "ar"],
  719. afg: ["afg", "sgn"],
  720. ajp: ["ajp", "ar"],
  721. apc: ["apc", "ar"],
  722. apd: ["apd", "ar"],
  723. arb: ["arb", "ar"],
  724. arq: ["arq", "ar"],
  725. ars: ["ars", "ar"],
  726. ary: ["ary", "ar"],
  727. arz: ["arz", "ar"],
  728. ase: ["ase", "sgn"],
  729. asf: ["asf", "sgn"],
  730. asp: ["asp", "sgn"],
  731. asq: ["asq", "sgn"],
  732. asw: ["asw", "sgn"],
  733. auz: ["auz", "ar"],
  734. avl: ["avl", "ar"],
  735. ayh: ["ayh", "ar"],
  736. ayl: ["ayl", "ar"],
  737. ayn: ["ayn", "ar"],
  738. ayp: ["ayp", "ar"],
  739. bbz: ["bbz", "ar"],
  740. bfi: ["bfi", "sgn"],
  741. bfk: ["bfk", "sgn"],
  742. bjn: ["bjn", "ms"],
  743. bog: ["bog", "sgn"],
  744. bqn: ["bqn", "sgn"],
  745. bqy: ["bqy", "sgn"],
  746. btj: ["btj", "ms"],
  747. bve: ["bve", "ms"],
  748. bvl: ["bvl", "sgn"],
  749. bvu: ["bvu", "ms"],
  750. bzs: ["bzs", "sgn"],
  751. cdo: ["cdo", "zh"],
  752. cds: ["cds", "sgn"],
  753. cjy: ["cjy", "zh"],
  754. cmn: ["cmn", "zh"],
  755. coa: ["coa", "ms"],
  756. cpx: ["cpx", "zh"],
  757. csc: ["csc", "sgn"],
  758. csd: ["csd", "sgn"],
  759. cse: ["cse", "sgn"],
  760. csf: ["csf", "sgn"],
  761. csg: ["csg", "sgn"],
  762. csl: ["csl", "sgn"],
  763. csn: ["csn", "sgn"],
  764. csq: ["csq", "sgn"],
  765. csr: ["csr", "sgn"],
  766. czh: ["czh", "zh"],
  767. czo: ["czo", "zh"],
  768. doq: ["doq", "sgn"],
  769. dse: ["dse", "sgn"],
  770. dsl: ["dsl", "sgn"],
  771. dup: ["dup", "ms"],
  772. ecs: ["ecs", "sgn"],
  773. esl: ["esl", "sgn"],
  774. esn: ["esn", "sgn"],
  775. eso: ["eso", "sgn"],
  776. eth: ["eth", "sgn"],
  777. fcs: ["fcs", "sgn"],
  778. fse: ["fse", "sgn"],
  779. fsl: ["fsl", "sgn"],
  780. fss: ["fss", "sgn"],
  781. gan: ["gan", "zh"],
  782. gds: ["gds", "sgn"],
  783. gom: ["gom", "kok"],
  784. gse: ["gse", "sgn"],
  785. gsg: ["gsg", "sgn"],
  786. gsm: ["gsm", "sgn"],
  787. gss: ["gss", "sgn"],
  788. gus: ["gus", "sgn"],
  789. hab: ["hab", "sgn"],
  790. haf: ["haf", "sgn"],
  791. hak: ["hak", "zh"],
  792. hds: ["hds", "sgn"],
  793. hji: ["hji", "ms"],
  794. hks: ["hks", "sgn"],
  795. hos: ["hos", "sgn"],
  796. hps: ["hps", "sgn"],
  797. hsh: ["hsh", "sgn"],
  798. hsl: ["hsl", "sgn"],
  799. hsn: ["hsn", "zh"],
  800. icl: ["icl", "sgn"],
  801. ils: ["ils", "sgn"],
  802. inl: ["inl", "sgn"],
  803. ins: ["ins", "sgn"],
  804. ise: ["ise", "sgn"],
  805. isg: ["isg", "sgn"],
  806. isr: ["isr", "sgn"],
  807. jak: ["jak", "ms"],
  808. jax: ["jax", "ms"],
  809. jcs: ["jcs", "sgn"],
  810. jhs: ["jhs", "sgn"],
  811. jls: ["jls", "sgn"],
  812. jos: ["jos", "sgn"],
  813. jsl: ["jsl", "sgn"],
  814. jus: ["jus", "sgn"],
  815. kgi: ["kgi", "sgn"],
  816. knn: ["knn", "kok"],
  817. kvb: ["kvb", "ms"],
  818. kvk: ["kvk", "sgn"],
  819. kvr: ["kvr", "ms"],
  820. kxd: ["kxd", "ms"],
  821. lbs: ["lbs", "sgn"],
  822. lce: ["lce", "ms"],
  823. lcf: ["lcf", "ms"],
  824. liw: ["liw", "ms"],
  825. lls: ["lls", "sgn"],
  826. lsg: ["lsg", "sgn"],
  827. lsl: ["lsl", "sgn"],
  828. lso: ["lso", "sgn"],
  829. lsp: ["lsp", "sgn"],
  830. lst: ["lst", "sgn"],
  831. lsy: ["lsy", "sgn"],
  832. ltg: ["ltg", "lv"],
  833. lvs: ["lvs", "lv"],
  834. lzh: ["lzh", "zh"],
  835. max: ["max", "ms"],
  836. mdl: ["mdl", "sgn"],
  837. meo: ["meo", "ms"],
  838. mfa: ["mfa", "ms"],
  839. mfb: ["mfb", "ms"],
  840. mfs: ["mfs", "sgn"],
  841. min: ["min", "ms"],
  842. mnp: ["mnp", "zh"],
  843. mqg: ["mqg", "ms"],
  844. mre: ["mre", "sgn"],
  845. msd: ["msd", "sgn"],
  846. msi: ["msi", "ms"],
  847. msr: ["msr", "sgn"],
  848. mui: ["mui", "ms"],
  849. mzc: ["mzc", "sgn"],
  850. mzg: ["mzg", "sgn"],
  851. mzy: ["mzy", "sgn"],
  852. nan: ["nan", "zh"],
  853. nbs: ["nbs", "sgn"],
  854. ncs: ["ncs", "sgn"],
  855. nsi: ["nsi", "sgn"],
  856. nsl: ["nsl", "sgn"],
  857. nsp: ["nsp", "sgn"],
  858. nsr: ["nsr", "sgn"],
  859. nzs: ["nzs", "sgn"],
  860. okl: ["okl", "sgn"],
  861. orn: ["orn", "ms"],
  862. ors: ["ors", "ms"],
  863. pel: ["pel", "ms"],
  864. pga: ["pga", "ar"],
  865. pks: ["pks", "sgn"],
  866. prl: ["prl", "sgn"],
  867. prz: ["prz", "sgn"],
  868. psc: ["psc", "sgn"],
  869. psd: ["psd", "sgn"],
  870. pse: ["pse", "ms"],
  871. psg: ["psg", "sgn"],
  872. psl: ["psl", "sgn"],
  873. pso: ["pso", "sgn"],
  874. psp: ["psp", "sgn"],
  875. psr: ["psr", "sgn"],
  876. pys: ["pys", "sgn"],
  877. rms: ["rms", "sgn"],
  878. rsi: ["rsi", "sgn"],
  879. rsl: ["rsl", "sgn"],
  880. sdl: ["sdl", "sgn"],
  881. sfb: ["sfb", "sgn"],
  882. sfs: ["sfs", "sgn"],
  883. sgg: ["sgg", "sgn"],
  884. sgx: ["sgx", "sgn"],
  885. shu: ["shu", "ar"],
  886. slf: ["slf", "sgn"],
  887. sls: ["sls", "sgn"],
  888. sqk: ["sqk", "sgn"],
  889. sqs: ["sqs", "sgn"],
  890. ssh: ["ssh", "ar"],
  891. ssp: ["ssp", "sgn"],
  892. ssr: ["ssr", "sgn"],
  893. svk: ["svk", "sgn"],
  894. swc: ["swc", "sw"],
  895. swh: ["swh", "sw"],
  896. swl: ["swl", "sgn"],
  897. syy: ["syy", "sgn"],
  898. tmw: ["tmw", "ms"],
  899. tse: ["tse", "sgn"],
  900. tsm: ["tsm", "sgn"],
  901. tsq: ["tsq", "sgn"],
  902. tss: ["tss", "sgn"],
  903. tsy: ["tsy", "sgn"],
  904. tza: ["tza", "sgn"],
  905. ugn: ["ugn", "sgn"],
  906. ugy: ["ugy", "sgn"],
  907. ukl: ["ukl", "sgn"],
  908. uks: ["uks", "sgn"],
  909. urk: ["urk", "ms"],
  910. uzn: ["uzn", "uz"],
  911. uzs: ["uzs", "uz"],
  912. vgt: ["vgt", "sgn"],
  913. vkk: ["vkk", "ms"],
  914. vkt: ["vkt", "ms"],
  915. vsi: ["vsi", "sgn"],
  916. vsl: ["vsl", "sgn"],
  917. vsv: ["vsv", "sgn"],
  918. wuu: ["wuu", "zh"],
  919. xki: ["xki", "sgn"],
  920. xml: ["xml", "sgn"],
  921. xmm: ["xmm", "ms"],
  922. xms: ["xms", "sgn"],
  923. yds: ["yds", "sgn"],
  924. ysl: ["ysl", "sgn"],
  925. yue: ["yue", "zh"],
  926. zib: ["zib", "sgn"],
  927. zlm: ["zlm", "ms"],
  928. zmi: ["zmi", "ms"],
  929. zsl: ["zsl", "sgn"],
  930. zsm: ["zsm", "ms"]
  931. }
  932. };
  933. /**
  934. * Convert only a-z to uppercase as per section 6.1 of the spec
  935. */
  936. function toLatinUpperCase(str) {
  937. var i = str.length;
  938. while (i--) {
  939. var ch = str.charAt(i);
  940. if (ch >= "a" && ch <= "z") str = str.slice(0, i) + ch.toUpperCase() + str.slice(i + 1);
  941. }
  942. return str;
  943. }
  944. /**
  945. * The IsStructurallyValidLanguageTag abstract operation verifies that the locale
  946. * argument (which must be a String value)
  947. *
  948. * - represents a well-formed BCP 47 language tag as specified in RFC 5646 section
  949. * 2.1, or successor,
  950. * - does not include duplicate variant subtags, and
  951. * - does not include duplicate singleton subtags.
  952. *
  953. * The abstract operation returns true if locale can be generated from the ABNF
  954. * grammar in section 2.1 of the RFC, starting with Language-Tag, and does not
  955. * contain duplicate variant or singleton subtags (other than as a private use
  956. * subtag). It returns false otherwise. Terminal value characters in the grammar are
  957. * interpreted as the Unicode equivalents of the ASCII octet values given.
  958. */
  959. function /* 6.2.2 */IsStructurallyValidLanguageTag(locale) {
  960. // represents a well-formed BCP 47 language tag as specified in RFC 5646
  961. if (!expBCP47Syntax.test(locale)) return false;
  962. // does not include duplicate variant subtags, and
  963. if (expVariantDupes.test(locale)) return false;
  964. // does not include duplicate singleton subtags.
  965. if (expSingletonDupes.test(locale)) return false;
  966. return true;
  967. }
  968. /**
  969. * The CanonicalizeLanguageTag abstract operation returns the canonical and case-
  970. * regularized form of the locale argument (which must be a String value that is
  971. * a structurally valid BCP 47 language tag as verified by the
  972. * IsStructurallyValidLanguageTag abstract operation). It takes the steps
  973. * specified in RFC 5646 section 4.5, or successor, to bring the language tag
  974. * into canonical form, and to regularize the case of the subtags, but does not
  975. * take the steps to bring a language tag into “extlang form” and to reorder
  976. * variant subtags.
  977. * The specifications for extensions to BCP 47 language tags, such as RFC 6067,
  978. * may include canonicalization rules for the extension subtag sequences they
  979. * define that go beyond the canonicalization rules of RFC 5646 section 4.5.
  980. * Implementations are allowed, but not required, to apply these additional rules.
  981. */
  982. function /* 6.2.3 */CanonicalizeLanguageTag(locale) {
  983. var match = void 0,
  984. parts = void 0;
  985. // A language tag is in 'canonical form' when the tag is well-formed
  986. // according to the rules in Sections 2.1 and 2.2
  987. // Section 2.1 says all subtags use lowercase...
  988. locale = locale.toLowerCase();
  989. // ...with 2 exceptions: 'two-letter and four-letter subtags that neither
  990. // appear at the start of the tag nor occur after singletons. Such two-letter
  991. // subtags are all uppercase (as in the tags "en-CA-x-ca" or "sgn-BE-FR") and
  992. // four-letter subtags are titlecase (as in the tag "az-Latn-x-latn").
  993. parts = locale.split('-');
  994. for (var i = 1, max = parts.length; i < max; i++) {
  995. // Two-letter subtags are all uppercase
  996. if (parts[i].length === 2) parts[i] = parts[i].toUpperCase();
  997. // Four-letter subtags are titlecase
  998. else if (parts[i].length === 4) parts[i] = parts[i].charAt(0).toUpperCase() + parts[i].slice(1);
  999. // Is it a singleton?
  1000. else if (parts[i].length === 1 && parts[i] !== 'x') break;
  1001. }
  1002. locale = arrJoin.call(parts, '-');
  1003. // The steps laid out in RFC 5646 section 4.5 are as follows:
  1004. // 1. Extension sequences are ordered into case-insensitive ASCII order
  1005. // by singleton subtag.
  1006. if ((match = locale.match(expExtSequences)) && match.length > 1) {
  1007. // The built-in sort() sorts by ASCII order, so use that
  1008. match.sort();
  1009. // Replace all extensions with the joined, sorted array
  1010. locale = locale.replace(RegExp('(?:' + expExtSequences.source + ')+', 'i'), arrJoin.call(match, ''));
  1011. }
  1012. // 2. Redundant or grandfathered tags are replaced by their 'Preferred-
  1013. // Value', if there is one.
  1014. if (hop.call(redundantTags.tags, locale)) locale = redundantTags.tags[locale];
  1015. // 3. Subtags are replaced by their 'Preferred-Value', if there is one.
  1016. // For extlangs, the original primary language subtag is also
  1017. // replaced if there is a primary language subtag in the 'Preferred-
  1018. // Value'.
  1019. parts = locale.split('-');
  1020. for (var _i = 1, _max = parts.length; _i < _max; _i++) {
  1021. if (hop.call(redundantTags.subtags, parts[_i])) parts[_i] = redundantTags.subtags[parts[_i]];else if (hop.call(redundantTags.extLang, parts[_i])) {
  1022. parts[_i] = redundantTags.extLang[parts[_i]][0];
  1023. // For extlang tags, the prefix needs to be removed if it is redundant
  1024. if (_i === 1 && redundantTags.extLang[parts[1]][1] === parts[0]) {
  1025. parts = arrSlice.call(parts, _i++);
  1026. _max -= 1;
  1027. }
  1028. }
  1029. }
  1030. return arrJoin.call(parts, '-');
  1031. }
  1032. /**
  1033. * The DefaultLocale abstract operation returns a String value representing the
  1034. * structurally valid (6.2.2) and canonicalized (6.2.3) BCP 47 language tag for the
  1035. * host environment’s current locale.
  1036. */
  1037. function /* 6.2.4 */DefaultLocale() {
  1038. return defaultLocale;
  1039. }
  1040. // Sect 6.3 Currency Codes
  1041. // =======================
  1042. var expCurrencyCode = /^[A-Z]{3}$/;
  1043. /**
  1044. * The IsWellFormedCurrencyCode abstract operation verifies that the currency argument
  1045. * (after conversion to a String value) represents a well-formed 3-letter ISO currency
  1046. * code. The following steps are taken:
  1047. */
  1048. function /* 6.3.1 */IsWellFormedCurrencyCode(currency) {
  1049. // 1. Let `c` be ToString(currency)
  1050. var c = String(currency);
  1051. // 2. Let `normalized` be the result of mapping c to upper case as described
  1052. // in 6.1.
  1053. var normalized = toLatinUpperCase(c);
  1054. // 3. If the string length of normalized is not 3, return false.
  1055. // 4. If normalized contains any character that is not in the range "A" to "Z"
  1056. // (U+0041 to U+005A), return false.
  1057. if (expCurrencyCode.test(normalized) === false) return false;
  1058. // 5. Return true
  1059. return true;
  1060. }
  1061. var expUnicodeExSeq = /-u(?:-[0-9a-z]{2,8})+/gi; // See `extension` below
  1062. function /* 9.2.1 */CanonicalizeLocaleList(locales) {
  1063. // The abstract operation CanonicalizeLocaleList takes the following steps:
  1064. // 1. If locales is undefined, then a. Return a new empty List
  1065. if (locales === undefined) return new List();
  1066. // 2. Let seen be a new empty List.
  1067. var seen = new List();
  1068. // 3. If locales is a String value, then
  1069. // a. Let locales be a new array created as if by the expression new
  1070. // Array(locales) where Array is the standard built-in constructor with
  1071. // that name and locales is the value of locales.
  1072. locales = typeof locales === 'string' ? [locales] : locales;
  1073. // 4. Let O be ToObject(locales).
  1074. var O = toObject(locales);
  1075. // 5. Let lenValue be the result of calling the [[Get]] internal method of
  1076. // O with the argument "length".
  1077. // 6. Let len be ToUint32(lenValue).
  1078. var len = toLength(O.length);
  1079. // 7. Let k be 0.
  1080. var k = 0;
  1081. // 8. Repeat, while k < len
  1082. while (k < len) {
  1083. // a. Let Pk be ToString(k).
  1084. var Pk = String(k);
  1085. // b. Let kPresent be the result of calling the [[HasProperty]] internal
  1086. // method of O with argument Pk.
  1087. var kPresent = Pk in O;
  1088. // c. If kPresent is true, then
  1089. if (kPresent) {
  1090. // i. Let kValue be the result of calling the [[Get]] internal
  1091. // method of O with argument Pk.
  1092. var kValue = O[Pk];
  1093. // ii. If the type of kValue is not String or Object, then throw a
  1094. // TypeError exception.
  1095. if (kValue === null || typeof kValue !== 'string' && (typeof kValue === "undefined" ? "undefined" : babelHelpers$1["typeof"](kValue)) !== 'object') throw new TypeError('String or Object type expected');
  1096. // iii. Let tag be ToString(kValue).
  1097. var tag = String(kValue);
  1098. // iv. If the result of calling the abstract operation
  1099. // IsStructurallyValidLanguageTag (defined in 6.2.2), passing tag as
  1100. // the argument, is false, then throw a RangeError exception.
  1101. if (!IsStructurallyValidLanguageTag(tag)) throw new RangeError("'" + tag + "' is not a structurally valid language tag");
  1102. // v. Let tag be the result of calling the abstract operation
  1103. // CanonicalizeLanguageTag (defined in 6.2.3), passing tag as the
  1104. // argument.
  1105. tag = CanonicalizeLanguageTag(tag);
  1106. // vi. If tag is not an element of seen, then append tag as the last
  1107. // element of seen.
  1108. if (arrIndexOf.call(seen, tag) === -1) arrPush.call(seen, tag);
  1109. }
  1110. // d. Increase k by 1.
  1111. k++;
  1112. }
  1113. // 9. Return seen.
  1114. return seen;
  1115. }
  1116. /**
  1117. * The BestAvailableLocale abstract operation compares the provided argument
  1118. * locale, which must be a String value with a structurally valid and
  1119. * canonicalized BCP 47 language tag, against the locales in availableLocales and
  1120. * returns either the longest non-empty prefix of locale that is an element of
  1121. * availableLocales, or undefined if there is no such element. It uses the
  1122. * fallback mechanism of RFC 4647, section 3.4. The following steps are taken:
  1123. */
  1124. function /* 9.2.2 */BestAvailableLocale(availableLocales, locale) {
  1125. // 1. Let candidate be locale
  1126. var candidate = locale;
  1127. // 2. Repeat
  1128. while (candidate) {
  1129. // a. If availableLocales contains an element equal to candidate, then return
  1130. // candidate.
  1131. if (arrIndexOf.call(availableLocales, candidate) > -1) return candidate;
  1132. // b. Let pos be the character index of the last occurrence of "-"
  1133. // (U+002D) within candidate. If that character does not occur, return
  1134. // undefined.
  1135. var pos = candidate.lastIndexOf('-');
  1136. if (pos < 0) return;
  1137. // c. If pos ≥ 2 and the character "-" occurs at index pos-2 of candidate,
  1138. // then decrease pos by 2.
  1139. if (pos >= 2 && candidate.charAt(pos - 2) === '-') pos -= 2;
  1140. // d. Let candidate be the substring of candidate from position 0, inclusive,
  1141. // to position pos, exclusive.
  1142. candidate = candidate.substring(0, pos);
  1143. }
  1144. }
  1145. /**
  1146. * The LookupMatcher abstract operation compares requestedLocales, which must be
  1147. * a List as returned by CanonicalizeLocaleList, against the locales in
  1148. * availableLocales and determines the best available language to meet the
  1149. * request. The following steps are taken:
  1150. */
  1151. function /* 9.2.3 */LookupMatcher(availableLocales, requestedLocales) {
  1152. // 1. Let i be 0.
  1153. var i = 0;
  1154. // 2. Let len be the number of elements in requestedLocales.
  1155. var len = requestedLocales.length;
  1156. // 3. Let availableLocale be undefined.
  1157. var availableLocale = void 0;
  1158. var locale = void 0,
  1159. noExtensionsLocale = void 0;
  1160. // 4. Repeat while i < len and availableLocale is undefined:
  1161. while (i < len && !availableLocale) {
  1162. // a. Let locale be the element of requestedLocales at 0-origined list
  1163. // position i.
  1164. locale = requestedLocales[i];
  1165. // b. Let noExtensionsLocale be the String value that is locale with all
  1166. // Unicode locale extension sequences removed.
  1167. noExtensionsLocale = String(locale).replace(expUnicodeExSeq, '');
  1168. // c. Let availableLocale be the result of calling the
  1169. // BestAvailableLocale abstract operation (defined in 9.2.2) with
  1170. // arguments availableLocales and noExtensionsLocale.
  1171. availableLocale = BestAvailableLocale(availableLocales, noExtensionsLocale);
  1172. // d. Increase i by 1.
  1173. i++;
  1174. }
  1175. // 5. Let result be a new Record.
  1176. var result = new Record();
  1177. // 6. If availableLocale is not undefined, then
  1178. if (availableLocale !== undefined) {
  1179. // a. Set result.[[locale]] to availableLocale.
  1180. result['[[locale]]'] = availableLocale;
  1181. // b. If locale and noExtensionsLocale are not the same String value, then
  1182. if (String(locale) !== String(noExtensionsLocale)) {
  1183. // i. Let extension be the String value consisting of the first
  1184. // substring of locale that is a Unicode locale extension sequence.
  1185. var extension = locale.match(expUnicodeExSeq)[0];
  1186. // ii. Let extensionIndex be the character position of the initial
  1187. // "-" of the first Unicode locale extension sequence within locale.
  1188. var extensionIndex = locale.indexOf('-u-');
  1189. // iii. Set result.[[extension]] to extension.
  1190. result['[[extension]]'] = extension;
  1191. // iv. Set result.[[extensionIndex]] to extensionIndex.
  1192. result['[[extensionIndex]]'] = extensionIndex;
  1193. }
  1194. }
  1195. // 7. Else
  1196. else
  1197. // a. Set result.[[locale]] to the value returned by the DefaultLocale abstract
  1198. // operation (defined in 6.2.4).
  1199. result['[[locale]]'] = DefaultLocale();
  1200. // 8. Return result
  1201. return result;
  1202. }
  1203. /**
  1204. * The BestFitMatcher abstract operation compares requestedLocales, which must be
  1205. * a List as returned by CanonicalizeLocaleList, against the locales in
  1206. * availableLocales and determines the best available language to meet the
  1207. * request. The algorithm is implementation dependent, but should produce results
  1208. * that a typical user of the requested locales would perceive as at least as
  1209. * good as those produced by the LookupMatcher abstract operation. Options
  1210. * specified through Unicode locale extension sequences must be ignored by the
  1211. * algorithm. Information about such subsequences is returned separately.
  1212. * The abstract operation returns a record with a [[locale]] field, whose value
  1213. * is the language tag of the selected locale, which must be an element of
  1214. * availableLocales. If the language tag of the request locale that led to the
  1215. * selected locale contained a Unicode locale extension sequence, then the
  1216. * returned record also contains an [[extension]] field whose value is the first
  1217. * Unicode locale extension sequence, and an [[extensionIndex]] field whose value
  1218. * is the index of the first Unicode locale extension sequence within the request
  1219. * locale language tag.
  1220. */
  1221. function /* 9.2.4 */BestFitMatcher(availableLocales, requestedLocales) {
  1222. return LookupMatcher(availableLocales, requestedLocales);
  1223. }
  1224. /**
  1225. * The ResolveLocale abstract operation compares a BCP 47 language priority list
  1226. * requestedLocales against the locales in availableLocales and determines the
  1227. * best available language to meet the request. availableLocales and
  1228. * requestedLocales must be provided as List values, options as a Record.
  1229. */
  1230. function /* 9.2.5 */ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData) {
  1231. if (availableLocales.length === 0) {
  1232. throw new ReferenceError('No locale data has been provided for this object yet.');
  1233. }
  1234. // The following steps are taken:
  1235. // 1. Let matcher be the value of options.[[localeMatcher]].
  1236. var matcher = options['[[localeMatcher]]'];
  1237. var r = void 0;
  1238. // 2. If matcher is "lookup", then
  1239. if (matcher === 'lookup')
  1240. // a. Let r be the result of calling the LookupMatcher abstract operation
  1241. // (defined in 9.2.3) with arguments availableLocales and
  1242. // requestedLocales.
  1243. r = LookupMatcher(availableLocales, requestedLocales);
  1244. // 3. Else
  1245. else
  1246. // a. Let r be the result of calling the BestFitMatcher abstract
  1247. // operation (defined in 9.2.4) with arguments availableLocales and
  1248. // requestedLocales.
  1249. r = BestFitMatcher(availableLocales, requestedLocales);
  1250. // 4. Let foundLocale be the value of r.[[locale]].
  1251. var foundLocale = r['[[locale]]'];
  1252. var extensionSubtags = void 0,
  1253. extensionSubtagsLength = void 0;
  1254. // 5. If r has an [[extension]] field, then
  1255. if (hop.call(r, '[[extension]]')) {
  1256. // a. Let extension be the value of r.[[extension]].
  1257. var extension = r['[[extension]]'];
  1258. // b. Let split be the standard built-in function object defined in ES5,
  1259. // 15.5.4.14.
  1260. var split = String.prototype.split;
  1261. // c. Let extensionSubtags be the result of calling the [[Call]] internal
  1262. // method of split with extension as the this value and an argument
  1263. // list containing the single item "-".
  1264. extensionSubtags = split.call(extension, '-');
  1265. // d. Let extensionSubtagsLength be the result of calling the [[Get]]
  1266. // internal method of extensionSubtags with argument "length".
  1267. extensionSubtagsLength = extensionSubtags.length;
  1268. }
  1269. // 6. Let result be a new Record.
  1270. var result = new Record();
  1271. // 7. Set result.[[dataLocale]] to foundLocale.
  1272. result['[[dataLocale]]'] = foundLocale;
  1273. // 8. Let supportedExtension be "-u".
  1274. var supportedExtension = '-u';
  1275. // 9. Let i be 0.
  1276. var i = 0;
  1277. // 10. Let len be the result of calling the [[Get]] internal method of
  1278. // relevantExtensionKeys with argument "length".
  1279. var len = relevantExtensionKeys.length;
  1280. // 11 Repeat while i < len:
  1281. while (i < len) {
  1282. // a. Let key be the result of calling the [[Get]] internal method of
  1283. // relevantExtensionKeys with argument ToString(i).
  1284. var key = relevantExtensionKeys[i];
  1285. // b. Let foundLocaleData be the result of calling the [[Get]] internal
  1286. // method of localeData with the argument foundLocale.
  1287. var foundLocaleData = localeData[foundLocale];
  1288. // c. Let keyLocaleData be the result of calling the [[Get]] internal
  1289. // method of foundLocaleData with the argument key.
  1290. var keyLocaleData = foundLocaleData[key];
  1291. // d. Let value be the result of calling the [[Get]] internal method of
  1292. // keyLocaleData with argument "0".
  1293. var value = keyLocaleData['0'];
  1294. // e. Let supportedExtensionAddition be "".
  1295. var supportedExtensionAddition = '';
  1296. // f. Let indexOf be the standard built-in function object defined in
  1297. // ES5, 15.4.4.14.
  1298. var indexOf = arrIndexOf;
  1299. // g. If extensionSubtags is not undefined, then
  1300. if (extensionSubtags !== undefined) {
  1301. // i. Let keyPos be the result of calling the [[Call]] internal
  1302. // method of indexOf with extensionSubtags as the this value and
  1303. // an argument list containing the single item key.
  1304. var keyPos = indexOf.call(extensionSubtags, key);
  1305. // ii. If keyPos ≠ -1, then
  1306. if (keyPos !== -1) {
  1307. // 1. If keyPos + 1 < extensionSubtagsLength and the length of the
  1308. // result of calling the [[Get]] internal method of
  1309. // extensionSubtags with argument ToString(keyPos +1) is greater
  1310. // than 2, then
  1311. if (keyPos + 1 < extensionSubtagsLength && extensionSubtags[keyPos + 1].length > 2) {
  1312. // a. Let requestedValue be the result of calling the [[Get]]
  1313. // internal method of extensionSubtags with argument
  1314. // ToString(keyPos + 1).
  1315. var requestedValue = extensionSubtags[keyPos + 1];
  1316. // b. Let valuePos be the result of calling the [[Call]]
  1317. // internal method of indexOf with keyLocaleData as the
  1318. // this value and an argument list containing the single
  1319. // item requestedValue.
  1320. var valuePos = indexOf.call(keyLocaleData, requestedValue);
  1321. // c. If valuePos ≠ -1, then
  1322. if (valuePos !== -1) {
  1323. // i. Let value be requestedValue.
  1324. value = requestedValue,
  1325. // ii. Let supportedExtensionAddition be the
  1326. // concatenation of "-", key, "-", and value.
  1327. supportedExtensionAddition = '-' + key + '-' + value;
  1328. }
  1329. }
  1330. // 2. Else
  1331. else {
  1332. // a. Let valuePos be the result of calling the [[Call]]
  1333. // internal method of indexOf with keyLocaleData as the this
  1334. // value and an argument list containing the single item
  1335. // "true".
  1336. var _valuePos = indexOf(keyLocaleData, 'true');
  1337. // b. If valuePos ≠ -1, then
  1338. if (_valuePos !== -1)
  1339. // i. Let value be "true".
  1340. value = 'true';
  1341. }
  1342. }
  1343. }
  1344. // h. If options has a field [[<key>]], then
  1345. if (hop.call(options, '[[' + key + ']]')) {
  1346. // i. Let optionsValue be the value of options.[[<key>]].
  1347. var optionsValue = options['[[' + key + ']]'];
  1348. // ii. If the result of calling the [[Call]] internal method of indexOf
  1349. // with keyLocaleData as the this value and an argument list
  1350. // containing the single item optionsValue is not -1, then
  1351. if (indexOf.call(keyLocaleData, optionsValue) !== -1) {
  1352. // 1. If optionsValue is not equal to value, then
  1353. if (optionsValue !== value) {
  1354. // a. Let value be optionsValue.
  1355. value = optionsValue;
  1356. // b. Let supportedExtensionAddition be "".
  1357. supportedExtensionAddition = '';
  1358. }
  1359. }
  1360. }
  1361. // i. Set result.[[<key>]] to value.
  1362. result['[[' + key + ']]'] = value;
  1363. // j. Append supportedExtensionAddition to supportedExtension.
  1364. supportedExtension += supportedExtensionAddition;
  1365. // k. Increase i by 1.
  1366. i++;
  1367. }
  1368. // 12. If the length of supportedExtension is greater than 2, then
  1369. if (supportedExtension.length > 2) {
  1370. // a.
  1371. var privateIndex = foundLocale.indexOf("-x-");
  1372. // b.
  1373. if (privateIndex === -1) {
  1374. // i.
  1375. foundLocale = foundLocale + supportedExtension;
  1376. }
  1377. // c.
  1378. else {
  1379. // i.
  1380. var preExtension = foundLocale.substring(0, privateIndex);
  1381. // ii.
  1382. var postExtension = foundLocale.substring(privateIndex);
  1383. // iii.
  1384. foundLocale = preExtension + supportedExtension + postExtension;
  1385. }
  1386. // d. asserting - skipping
  1387. // e.
  1388. foundLocale = CanonicalizeLanguageTag(foundLocale);
  1389. }
  1390. // 13. Set result.[[locale]] to foundLocale.
  1391. result['[[locale]]'] = foundLocale;
  1392. // 14. Return result.
  1393. return result;
  1394. }
  1395. /**
  1396. * The LookupSupportedLocales abstract operation returns the subset of the
  1397. * provided BCP 47 language priority list requestedLocales for which
  1398. * availableLocales has a matching locale when using the BCP 47 Lookup algorithm.
  1399. * Locales appear in the same order in the returned list as in requestedLocales.
  1400. * The following steps are taken:
  1401. */
  1402. function /* 9.2.6 */LookupSupportedLocales(availableLocales, requestedLocales) {
  1403. // 1. Let len be the number of elements in requestedLocales.
  1404. var len = requestedLocales.length;
  1405. // 2. Let subset be a new empty List.
  1406. var subset = new List();
  1407. // 3. Let k be 0.
  1408. var k = 0;
  1409. // 4. Repeat while k < len
  1410. while (k < len) {
  1411. // a. Let locale be the element of requestedLocales at 0-origined list
  1412. // position k.
  1413. var locale = requestedLocales[k];
  1414. // b. Let noExtensionsLocale be the String value that is locale with all
  1415. // Unicode locale extension sequences removed.
  1416. var noExtensionsLocale = String(locale).replace(expUnicodeExSeq, '');
  1417. // c. Let availableLocale be the result of calling the
  1418. // BestAvailableLocale abstract operation (defined in 9.2.2) with
  1419. // arguments availableLocales and noExtensionsLocale.
  1420. var availableLocale = BestAvailableLocale(availableLocales, noExtensionsLocale);
  1421. // d. If availableLocale is not undefined, then append locale to the end of
  1422. // subset.
  1423. if (availableLocale !== undefined) arrPush.call(subset, locale);
  1424. // e. Increment k by 1.
  1425. k++;
  1426. }
  1427. // 5. Let subsetArray be a new Array object whose elements are the same
  1428. // values in the same order as the elements of subset.
  1429. var subsetArray = arrSlice.call(subset);
  1430. // 6. Return subsetArray.
  1431. return subsetArray;
  1432. }
  1433. /**
  1434. * The BestFitSupportedLocales abstract operation returns the subset of the
  1435. * provided BCP 47 language priority list requestedLocales for which
  1436. * availableLocales has a matching locale when using the Best Fit Matcher
  1437. * algorithm. Locales appear in the same order in the returned list as in
  1438. * requestedLocales. The steps taken are implementation dependent.
  1439. */
  1440. function /*9.2.7 */BestFitSupportedLocales(availableLocales, requestedLocales) {
  1441. // ###TODO: implement this function as described by the specification###
  1442. return LookupSupportedLocales(availableLocales, requestedLocales);
  1443. }
  1444. /**
  1445. * The SupportedLocales abstract operation returns the subset of the provided BCP
  1446. * 47 language priority list requestedLocales for which availableLocales has a
  1447. * matching locale. Two algorithms are available to match the locales: the Lookup
  1448. * algorithm described in RFC 4647 section 3.4, and an implementation dependent
  1449. * best-fit algorithm. Locales appear in the same order in the returned list as
  1450. * in requestedLocales. The following steps are taken:
  1451. */
  1452. function /*9.2.8 */SupportedLocales(availableLocales, requestedLocales, options) {
  1453. var matcher = void 0,
  1454. subset = void 0;
  1455. // 1. If options is not undefined, then
  1456. if (options !== undefined) {
  1457. // a. Let options be ToObject(options).
  1458. options = new Record(toObject(options));
  1459. // b. Let matcher be the result of calling the [[Get]] internal method of
  1460. // options with argument "localeMatcher".
  1461. matcher = options.localeMatcher;
  1462. // c. If matcher is not undefined, then
  1463. if (matcher !== undefined) {
  1464. // i. Let matcher be ToString(matcher).
  1465. matcher = String(matcher);
  1466. // ii. If matcher is not "lookup" or "best fit", then throw a RangeError
  1467. // exception.
  1468. if (matcher !== 'lookup' && matcher !== 'best fit') throw new RangeError('matcher should be "lookup" or "best fit"');
  1469. }
  1470. }
  1471. // 2. If matcher is undefined or "best fit", then
  1472. if (matcher === undefined || matcher === 'best fit')
  1473. // a. Let subset be the result of calling the BestFitSupportedLocales
  1474. // abstract operation (defined in 9.2.7) with arguments
  1475. // availableLocales and requestedLocales.
  1476. subset = BestFitSupportedLocales(availableLocales, requestedLocales);
  1477. // 3. Else
  1478. else
  1479. // a. Let subset be the result of calling the LookupSupportedLocales
  1480. // abstract operation (defined in 9.2.6) with arguments
  1481. // availableLocales and requestedLocales.
  1482. subset = LookupSupportedLocales(availableLocales, requestedLocales);
  1483. // 4. For each named own property name P of subset,
  1484. for (var P in subset) {
  1485. if (!hop.call(subset, P)) continue;
  1486. // a. Let desc be the result of calling the [[GetOwnProperty]] internal
  1487. // method of subset with P.
  1488. // b. Set desc.[[Writable]] to false.
  1489. // c. Set desc.[[Configurable]] to false.
  1490. // d. Call the [[DefineOwnProperty]] internal method of subset with P, desc,
  1491. // and true as arguments.
  1492. defineProperty(subset, P, {
  1493. writable: false, configurable: false, value: subset[P]
  1494. });
  1495. }
  1496. // "Freeze" the array so no new elements can be added
  1497. defineProperty(subset, 'length', { writable: false });
  1498. // 5. Return subset
  1499. return subset;
  1500. }
  1501. /**
  1502. * The GetOption abstract operation extracts the value of the property named
  1503. * property from the provided options object, converts it to the required type,
  1504. * checks whether it is one of a List of allowed values, and fills in a fallback
  1505. * value if necessary.
  1506. */
  1507. function /*9.2.9 */GetOption(options, property, type, values, fallback) {
  1508. // 1. Let value be the result of calling the [[Get]] internal method of
  1509. // options with argument property.
  1510. var value = options[property];
  1511. // 2. If value is not undefined, then
  1512. if (value !== undefined) {
  1513. // a. Assert: type is "boolean" or "string".
  1514. // b. If type is "boolean", then let value be ToBoolean(value).
  1515. // c. If type is "string", then let value be ToString(value).
  1516. value = type === 'boolean' ? Boolean(value) : type === 'string' ? String(value) : value;
  1517. // d. If values is not undefined, then
  1518. if (values !== undefined) {
  1519. // i. If values does not contain an element equal to value, then throw a
  1520. // RangeError exception.
  1521. if (arrIndexOf.call(values, value) === -1) throw new RangeError("'" + value + "' is not an allowed value for `" + property + '`');
  1522. }
  1523. // e. Return value.
  1524. return value;
  1525. }
  1526. // Else return fallback.
  1527. return fallback;
  1528. }
  1529. /**
  1530. * The GetNumberOption abstract operation extracts a property value from the
  1531. * provided options object, converts it to a Number value, checks whether it is
  1532. * in the allowed range, and fills in a fallback value if necessary.
  1533. */
  1534. function /* 9.2.10 */GetNumberOption(options, property, minimum, maximum, fallback) {
  1535. // 1. Let value be the result of calling the [[Get]] internal method of
  1536. // options with argument property.
  1537. var value = options[property];
  1538. // 2. If value is not undefined, then
  1539. if (value !== undefined) {
  1540. // a. Let value be ToNumber(value).
  1541. value = Number(value);
  1542. // b. If value is NaN or less than minimum or greater than maximum, throw a
  1543. // RangeError exception.
  1544. if (isNaN(value) || value < minimum || value > maximum) throw new RangeError('Value is not a number or outside accepted range');
  1545. // c. Return floor(value).
  1546. return Math.floor(value);
  1547. }
  1548. // 3. Else return fallback.
  1549. return fallback;
  1550. }
  1551. // 8 The Intl Object
  1552. var Intl$1 = {};
  1553. // 8.2 Function Properties of the Intl Object
  1554. // 8.2.1
  1555. // @spec[tc39/ecma402/master/spec/intl.html]
  1556. // @clause[sec-intl.getcanonicallocales]
  1557. function getCanonicalLocales(locales) {
  1558. // 1. Let ll be ? CanonicalizeLocaleList(locales).
  1559. var ll = CanonicalizeLocaleList(locales);
  1560. // 2. Return CreateArrayFromList(ll).
  1561. {
  1562. var result = [];
  1563. var len = ll.length;
  1564. var k = 0;
  1565. while (k < len) {
  1566. result[k] = ll[k];
  1567. k++;
  1568. }
  1569. return result;
  1570. }
  1571. }
  1572. Object.defineProperty(Intl$1, 'getCanonicalLocales', {
  1573. enumerable: false,
  1574. configurable: true,
  1575. writable: true,
  1576. value: getCanonicalLocales
  1577. });
  1578. // Currency minor units output from get-4217 grunt task, formatted
  1579. var currencyMinorUnits = {
  1580. BHD: 3, BYR: 0, XOF: 0, BIF: 0, XAF: 0, CLF: 4, CLP: 0, KMF: 0, DJF: 0,
  1581. XPF: 0, GNF: 0, ISK: 0, IQD: 3, JPY: 0, JOD: 3, KRW: 0, KWD: 3, LYD: 3,
  1582. OMR: 3, PYG: 0, RWF: 0, TND: 3, UGX: 0, UYI: 0, VUV: 0, VND: 0
  1583. };
  1584. // Define the NumberFormat constructor internally so it cannot be tainted
  1585. function NumberFormatConstructor() {
  1586. var locales = arguments[0];
  1587. var options = arguments[1];
  1588. if (!this || this === Intl$1) {
  1589. return new Intl$1.NumberFormat(locales, options);
  1590. }
  1591. return InitializeNumberFormat(toObject(this), locales, options);
  1592. }
  1593. defineProperty(Intl$1, 'NumberFormat', {
  1594. configurable: true,
  1595. writable: true,
  1596. value: NumberFormatConstructor
  1597. });
  1598. // Must explicitly set prototypes as unwritable
  1599. defineProperty(Intl$1.NumberFormat, 'prototype', {
  1600. writable: false
  1601. });
  1602. /**
  1603. * The abstract operation InitializeNumberFormat accepts the arguments
  1604. * numberFormat (which must be an object), locales, and options. It initializes
  1605. * numberFormat as a NumberFormat object.
  1606. */
  1607. function /*11.1.1.1 */InitializeNumberFormat(numberFormat, locales, options) {
  1608. // This will be a internal properties object if we're not already initialized
  1609. var internal = getInternalProperties(numberFormat);
  1610. // Create an object whose props can be used to restore the values of RegExp props
  1611. var regexpRestore = createRegExpRestore();
  1612. // 1. If numberFormat has an [[initializedIntlObject]] internal property with
  1613. // value true, throw a TypeError exception.
  1614. if (internal['[[initializedIntlObject]]'] === true) throw new TypeError('`this` object has already been initialized as an Intl object');
  1615. // Need this to access the `internal` object
  1616. defineProperty(numberFormat, '__getInternalProperties', {
  1617. value: function value() {
  1618. // NOTE: Non-standard, for internal use only
  1619. if (arguments[0] === secret) return internal;
  1620. }
  1621. });
  1622. // 2. Set the [[initializedIntlObject]] internal property of numberFormat to true.
  1623. internal['[[initializedIntlObject]]'] = true;
  1624. // 3. Let requestedLocales be the result of calling the CanonicalizeLocaleList
  1625. // abstract operation (defined in 9.2.1) with argument locales.
  1626. var requestedLocales = CanonicalizeLocaleList(locales);
  1627. // 4. If options is undefined, then
  1628. if (options === undefined)
  1629. // a. Let options be the result of creating a new object as if by the
  1630. // expression new Object() where Object is the standard built-in constructor
  1631. // with that name.
  1632. options = {};
  1633. // 5. Else
  1634. else
  1635. // a. Let options be ToObject(options).
  1636. options = toObject(options);
  1637. // 6. Let opt be a new Record.
  1638. var opt = new Record(),
  1639. // 7. Let matcher be the result of calling the GetOption abstract operation
  1640. // (defined in 9.2.9) with the arguments options, "localeMatcher", "string",
  1641. // a List containing the two String values "lookup" and "best fit", and
  1642. // "best fit".
  1643. matcher = GetOption(options, 'localeMatcher', 'string', new List('lookup', 'best fit'), 'best fit');
  1644. // 8. Set opt.[[localeMatcher]] to matcher.
  1645. opt['[[localeMatcher]]'] = matcher;
  1646. // 9. Let NumberFormat be the standard built-in object that is the initial value
  1647. // of Intl.NumberFormat.
  1648. // 10. Let localeData be the value of the [[localeData]] internal property of
  1649. // NumberFormat.
  1650. var localeData = internals.NumberFormat['[[localeData]]'];
  1651. // 11. Let r be the result of calling the ResolveLocale abstract operation
  1652. // (defined in 9.2.5) with the [[availableLocales]] internal property of
  1653. // NumberFormat, requestedLocales, opt, the [[relevantExtensionKeys]]
  1654. // internal property of NumberFormat, and localeData.
  1655. var r = ResolveLocale(internals.NumberFormat['[[availableLocales]]'], requestedLocales, opt, internals.NumberFormat['[[relevantExtensionKeys]]'], localeData);
  1656. // 12. Set the [[locale]] internal property of numberFormat to the value of
  1657. // r.[[locale]].
  1658. internal['[[locale]]'] = r['[[locale]]'];
  1659. // 13. Set the [[numberingSystem]] internal property of numberFormat to the value
  1660. // of r.[[nu]].
  1661. internal['[[numberingSystem]]'] = r['[[nu]]'];
  1662. // The specification doesn't tell us to do this, but it's helpful later on
  1663. internal['[[dataLocale]]'] = r['[[dataLocale]]'];
  1664. // 14. Let dataLocale be the value of r.[[dataLocale]].
  1665. var dataLocale = r['[[dataLocale]]'];
  1666. // 15. Let s be the result of calling the GetOption abstract operation with the
  1667. // arguments options, "style", "string", a List containing the three String
  1668. // values "decimal", "percent", and "currency", and "decimal".
  1669. var s = GetOption(options, 'style', 'string', new List('decimal', 'percent', 'currency'), 'decimal');
  1670. // 16. Set the [[style]] internal property of numberFormat to s.
  1671. internal['[[style]]'] = s;
  1672. // 17. Let c be the result of calling the GetOption abstract operation with the
  1673. // arguments options, "currency", "string", undefined, and undefined.
  1674. var c = GetOption(options, 'currency', 'string');
  1675. // 18. If c is not undefined and the result of calling the
  1676. // IsWellFormedCurrencyCode abstract operation (defined in 6.3.1) with
  1677. // argument c is false, then throw a RangeError exception.
  1678. if (c !== undefined && !IsWellFormedCurrencyCode(c)) throw new RangeError("'" + c + "' is not a valid currency code");
  1679. // 19. If s is "currency" and c is undefined, throw a TypeError exception.
  1680. if (s === 'currency' && c === undefined) throw new TypeError('Currency code is required when style is currency');
  1681. var cDigits = void 0;
  1682. // 20. If s is "currency", then
  1683. if (s === 'currency') {
  1684. // a. Let c be the result of converting c to upper case as specified in 6.1.
  1685. c = c.toUpperCase();
  1686. // b. Set the [[currency]] internal property of numberFormat to c.
  1687. internal['[[currency]]'] = c;
  1688. // c. Let cDigits be the result of calling the CurrencyDigits abstract
  1689. // operation (defined below) with argument c.
  1690. cDigits = CurrencyDigits(c);
  1691. }
  1692. // 21. Let cd be the result of calling the GetOption abstract operation with the
  1693. // arguments options, "currencyDisplay", "string", a List containing the
  1694. // three String values "code", "symbol", and "name", and "symbol".
  1695. var cd = GetOption(options, 'currencyDisplay', 'string', new List('code', 'symbol', 'name'), 'symbol');
  1696. // 22. If s is "currency", then set the [[currencyDisplay]] internal property of
  1697. // numberFormat to cd.
  1698. if (s === 'currency') internal['[[currencyDisplay]]'] = cd;
  1699. // 23. Let mnid be the result of calling the GetNumberOption abstract operation
  1700. // (defined in 9.2.10) with arguments options, "minimumIntegerDigits", 1, 21,
  1701. // and 1.
  1702. var mnid = GetNumberOption(options, 'minimumIntegerDigits', 1, 21, 1);
  1703. // 24. Set the [[minimumIntegerDigits]] internal property of numberFormat to mnid.
  1704. internal['[[minimumIntegerDigits]]'] = mnid;
  1705. // 25. If s is "currency", then let mnfdDefault be cDigits; else let mnfdDefault
  1706. // be 0.
  1707. var mnfdDefault = s === 'currency' ? cDigits : 0;
  1708. // 26. Let mnfd be the result of calling the GetNumberOption abstract operation
  1709. // with arguments options, "minimumFractionDigits", 0, 20, and mnfdDefault.
  1710. var mnfd = GetNumberOption(options, 'minimumFractionDigits', 0, 20, mnfdDefault);
  1711. // 27. Set the [[minimumFractionDigits]] internal property of numberFormat to mnfd.
  1712. internal['[[minimumFractionDigits]]'] = mnfd;
  1713. // 28. If s is "currency", then let mxfdDefault be max(mnfd, cDigits); else if s
  1714. // is "percent", then let mxfdDefault be max(mnfd, 0); else let mxfdDefault
  1715. // be max(mnfd, 3).
  1716. var mxfdDefault = s === 'currency' ? Math.max(mnfd, cDigits) : s === 'percent' ? Math.max(mnfd, 0) : Math.max(mnfd, 3);
  1717. // 29. Let mxfd be the result of calling the GetNumberOption abstract operation
  1718. // with arguments options, "maximumFractionDigits", mnfd, 20, and mxfdDefault.
  1719. var mxfd = GetNumberOption(options, 'maximumFractionDigits', mnfd, 20, mxfdDefault);
  1720. // 30. Set the [[maximumFractionDigits]] internal property of numberFormat to mxfd.
  1721. internal['[[maximumFractionDigits]]'] = mxfd;
  1722. // 31. Let mnsd be the result of calling the [[Get]] internal method of options
  1723. // with argument "minimumSignificantDigits".
  1724. var mnsd = options.minimumSignificantDigits;
  1725. // 32. Let mxsd be the result of calling the [[Get]] internal method of options
  1726. // with argument "maximumSignificantDigits".
  1727. var mxsd = options.maximumSignificantDigits;
  1728. // 33. If mnsd is not undefined or mxsd is not undefined, then:
  1729. if (mnsd !== undefined || mxsd !== undefined) {
  1730. // a. Let mnsd be the result of calling the GetNumberOption abstract
  1731. // operation with arguments options, "minimumSignificantDigits", 1, 21,
  1732. // and 1.
  1733. mnsd = GetNumberOption(options, 'minimumSignificantDigits', 1, 21, 1);
  1734. // b. Let mxsd be the result of calling the GetNumberOption abstract
  1735. // operation with arguments options, "maximumSignificantDigits", mnsd,
  1736. // 21, and 21.
  1737. mxsd = GetNumberOption(options, 'maximumSignificantDigits', mnsd, 21, 21);
  1738. // c. Set the [[minimumSignificantDigits]] internal property of numberFormat
  1739. // to mnsd, and the [[maximumSignificantDigits]] internal property of
  1740. // numberFormat to mxsd.
  1741. internal['[[minimumSignificantDigits]]'] = mnsd;
  1742. internal['[[maximumSignificantDigits]]'] = mxsd;
  1743. }
  1744. // 34. Let g be the result of calling the GetOption abstract operation with the
  1745. // arguments options, "useGrouping", "boolean", undefined, and true.
  1746. var g = GetOption(options, 'useGrouping', 'boolean', undefined, true);
  1747. // 35. Set the [[useGrouping]] internal property of numberFormat to g.
  1748. internal['[[useGrouping]]'] = g;
  1749. // 36. Let dataLocaleData be the result of calling the [[Get]] internal method of
  1750. // localeData with argument dataLocale.
  1751. var dataLocaleData = localeData[dataLocale];
  1752. // 37. Let patterns be the result of calling the [[Get]] internal method of
  1753. // dataLocaleData with argument "patterns".
  1754. var patterns = dataLocaleData.patterns;
  1755. // 38. Assert: patterns is an object (see 11.2.3)
  1756. // 39. Let stylePatterns be the result of calling the [[Get]] internal method of
  1757. // patterns with argument s.
  1758. var stylePatterns = patterns[s];
  1759. // 40. Set the [[positivePattern]] internal property of numberFormat to the
  1760. // result of calling the [[Get]] internal method of stylePatterns with the
  1761. // argument "positivePattern".
  1762. internal['[[positivePattern]]'] = stylePatterns.positivePattern;
  1763. // 41. Set the [[negativePattern]] internal property of numberFormat to the
  1764. // result of calling the [[Get]] internal method of stylePatterns with the
  1765. // argument "negativePattern".
  1766. internal['[[negativePattern]]'] = stylePatterns.negativePattern;
  1767. // 42. Set the [[boundFormat]] internal property of numberFormat to undefined.
  1768. internal['[[boundFormat]]'] = undefined;
  1769. // 43. Set the [[initializedNumberFormat]] internal property of numberFormat to
  1770. // true.
  1771. internal['[[initializedNumberFormat]]'] = true;
  1772. // In ES3, we need to pre-bind the format() function
  1773. if (es3) numberFormat.format = GetFormatNumber.call(numberFormat);
  1774. // Restore the RegExp properties
  1775. regexpRestore();
  1776. // Return the newly initialised object
  1777. return numberFormat;
  1778. }
  1779. function CurrencyDigits(currency) {
  1780. // When the CurrencyDigits abstract operation is called with an argument currency
  1781. // (which must be an upper case String value), the following steps are taken:
  1782. // 1. If the ISO 4217 currency and funds code list contains currency as an
  1783. // alphabetic code, then return the minor unit value corresponding to the
  1784. // currency from the list; else return 2.
  1785. return currencyMinorUnits[currency] !== undefined ? currencyMinorUnits[currency] : 2;
  1786. }
  1787. /* 11.2.3 */internals.NumberFormat = {
  1788. '[[availableLocales]]': [],
  1789. '[[relevantExtensionKeys]]': ['nu'],
  1790. '[[localeData]]': {}
  1791. };
  1792. /**
  1793. * When the supportedLocalesOf method of Intl.NumberFormat is called, the
  1794. * following steps are taken:
  1795. */
  1796. /* 11.2.2 */
  1797. defineProperty(Intl$1.NumberFormat, 'supportedLocalesOf', {
  1798. configurable: true,
  1799. writable: true,
  1800. value: fnBind.call(function (locales) {
  1801. // Bound functions only have the `this` value altered if being used as a constructor,
  1802. // this lets us imitate a native function that has no constructor
  1803. if (!hop.call(this, '[[availableLocales]]')) throw new TypeError('supportedLocalesOf() is not a constructor');
  1804. // Create an object whose props can be used to restore the values of RegExp props
  1805. var regexpRestore = createRegExpRestore(),
  1806. // 1. If options is not provided, then let options be undefined.
  1807. options = arguments[1],
  1808. // 2. Let availableLocales be the value of the [[availableLocales]] internal
  1809. // property of the standard built-in object that is the initial value of
  1810. // Intl.NumberFormat.
  1811. availableLocales = this['[[availableLocales]]'],
  1812. // 3. Let requestedLocales be the result of calling the CanonicalizeLocaleList
  1813. // abstract operation (defined in 9.2.1) with argument locales.
  1814. requestedLocales = CanonicalizeLocaleList(locales);
  1815. // Restore the RegExp properties
  1816. regexpRestore();
  1817. // 4. Return the result of calling the SupportedLocales abstract operation
  1818. // (defined in 9.2.8) with arguments availableLocales, requestedLocales,
  1819. // and options.
  1820. return SupportedLocales(availableLocales, requestedLocales, options);
  1821. }, internals.NumberFormat)
  1822. });
  1823. /**
  1824. * This named accessor property returns a function that formats a number
  1825. * according to the effective locale and the formatting options of this
  1826. * NumberFormat object.
  1827. */
  1828. /* 11.3.2 */defineProperty(Intl$1.NumberFormat.prototype, 'format', {
  1829. configurable: true,
  1830. get: GetFormatNumber
  1831. });
  1832. function GetFormatNumber() {
  1833. var internal = this !== null && babelHelpers$1["typeof"](this) === 'object' && getInternalProperties(this);
  1834. // Satisfy test 11.3_b
  1835. if (!internal || !internal['[[initializedNumberFormat]]']) throw new TypeError('`this` value for format() is not an initialized Intl.NumberFormat object.');
  1836. // The value of the [[Get]] attribute is a function that takes the following
  1837. // steps:
  1838. // 1. If the [[boundFormat]] internal property of this NumberFormat object
  1839. // is undefined, then:
  1840. if (internal['[[boundFormat]]'] === undefined) {
  1841. // a. Let F be a Function object, with internal properties set as
  1842. // specified for built-in functions in ES5, 15, or successor, and the
  1843. // length property set to 1, that takes the argument value and
  1844. // performs the following steps:
  1845. var F = function F(value) {
  1846. // i. If value is not provided, then let value be undefined.
  1847. // ii. Let x be ToNumber(value).
  1848. // iii. Return the result of calling the FormatNumber abstract
  1849. // operation (defined below) with arguments this and x.
  1850. return FormatNumber(this, /* x = */Number(value));
  1851. };
  1852. // b. Let bind be the standard built-in function object defined in ES5,
  1853. // 15.3.4.5.
  1854. // c. Let bf be the result of calling the [[Call]] internal method of
  1855. // bind with F as the this value and an argument list containing
  1856. // the single item this.
  1857. var bf = fnBind.call(F, this);
  1858. // d. Set the [[boundFormat]] internal property of this NumberFormat
  1859. // object to bf.
  1860. internal['[[boundFormat]]'] = bf;
  1861. }
  1862. // Return the value of the [[boundFormat]] internal property of this
  1863. // NumberFormat object.
  1864. return internal['[[boundFormat]]'];
  1865. }
  1866. function formatToParts() {
  1867. var value = arguments.length <= 0 || arguments[0] === undefined ? undefined : arguments[0];
  1868. var internal = this !== null && babelHelpers$1["typeof"](this) === 'object' && getInternalProperties(this);
  1869. if (!internal || !internal['[[initializedNumberFormat]]']) throw new TypeError('`this` value for formatToParts() is not an initialized Intl.NumberFormat object.');
  1870. var x = Number(value);
  1871. return FormatNumberToParts(this, x);
  1872. }
  1873. Object.defineProperty(Intl$1.NumberFormat.prototype, 'formatToParts', {
  1874. configurable: true,
  1875. enumerable: false,
  1876. writable: true,
  1877. value: formatToParts
  1878. });
  1879. /*
  1880. * @spec[stasm/ecma402/number-format-to-parts/spec/numberformat.html]
  1881. * @clause[sec-formatnumbertoparts]
  1882. */
  1883. function FormatNumberToParts(numberFormat, x) {
  1884. // 1. Let parts be ? PartitionNumberPattern(numberFormat, x).
  1885. var parts = PartitionNumberPattern(numberFormat, x);
  1886. // 2. Let result be ArrayCreate(0).
  1887. var result = [];
  1888. // 3. Let n be 0.
  1889. var n = 0;
  1890. // 4. For each part in parts, do:
  1891. for (var i = 0; parts.length > i; i++) {
  1892. var part = parts[i];
  1893. // a. Let O be ObjectCreate(%ObjectPrototype%).
  1894. var O = {};
  1895. // a. Perform ? CreateDataPropertyOrThrow(O, "type", part.[[type]]).
  1896. O.type = part['[[type]]'];
  1897. // a. Perform ? CreateDataPropertyOrThrow(O, "value", part.[[value]]).
  1898. O.value = part['[[value]]'];
  1899. // a. Perform ? CreateDataPropertyOrThrow(result, ? ToString(n), O).
  1900. result[n] = O;
  1901. // a. Increment n by 1.
  1902. n += 1;
  1903. }
  1904. // 5. Return result.
  1905. return result;
  1906. }
  1907. /*
  1908. * @spec[stasm/ecma402/number-format-to-parts/spec/numberformat.html]
  1909. * @clause[sec-partitionnumberpattern]
  1910. */
  1911. function PartitionNumberPattern(numberFormat, x) {
  1912. var internal = getInternalProperties(numberFormat),
  1913. locale = internal['[[dataLocale]]'],
  1914. nums = internal['[[numberingSystem]]'],
  1915. data = internals.NumberFormat['[[localeData]]'][locale],
  1916. ild = data.symbols[nums] || data.symbols.latn,
  1917. pattern = void 0;
  1918. // 1. If x is not NaN and x < 0, then:
  1919. if (!isNaN(x) && x < 0) {
  1920. // a. Let x be -x.
  1921. x = -x;
  1922. // a. Let pattern be the value of numberFormat.[[negativePattern]].
  1923. pattern = internal['[[negativePattern]]'];
  1924. }
  1925. // 2. Else,
  1926. else {
  1927. // a. Let pattern be the value of numberFormat.[[positivePattern]].
  1928. pattern = internal['[[positivePattern]]'];
  1929. }
  1930. // 3. Let result be a new empty List.
  1931. var result = new List();
  1932. // 4. Let beginIndex be Call(%StringProto_indexOf%, pattern, "{", 0).
  1933. var beginIndex = pattern.indexOf('{', 0);
  1934. // 5. Let endIndex be 0.
  1935. var endIndex = 0;
  1936. // 6. Let nextIndex be 0.
  1937. var nextIndex = 0;
  1938. // 7. Let length be the number of code units in pattern.
  1939. var length = pattern.length;
  1940. // 8. Repeat while beginIndex is an integer index into pattern:
  1941. while (beginIndex > -1 && beginIndex < length) {
  1942. // a. Set endIndex to Call(%StringProto_indexOf%, pattern, "}", beginIndex)
  1943. endIndex = pattern.indexOf('}', beginIndex);
  1944. // a. If endIndex = -1, throw new Error exception.
  1945. if (endIndex === -1) throw new Error();
  1946. // a. If beginIndex is greater than nextIndex, then:
  1947. if (beginIndex > nextIndex) {
  1948. // i. Let literal be a substring of pattern from position nextIndex, inclusive, to position beginIndex, exclusive.
  1949. var literal = pattern.substring(nextIndex, beginIndex);
  1950. // ii. Add new part record { [[type]]: "literal", [[value]]: literal } as a new element of the list result.
  1951. arrPush.call(result, { '[[type]]': 'literal', '[[value]]': literal });
  1952. }
  1953. // a. Let p be the substring of pattern from position beginIndex, exclusive, to position endIndex, exclusive.
  1954. var p = pattern.substring(beginIndex + 1, endIndex);
  1955. // a. If p is equal "number", then:
  1956. if (p === "number") {
  1957. // i. If x is NaN,
  1958. if (isNaN(x)) {
  1959. // 1. Let n be an ILD String value indicating the NaN value.
  1960. var n = ild.nan;
  1961. // 2. Add new part record { [[type]]: "nan", [[value]]: n } as a new element of the list result.
  1962. arrPush.call(result, { '[[type]]': 'nan', '[[value]]': n });
  1963. }
  1964. // ii. Else if isFinite(x) is false,
  1965. else if (!isFinite(x)) {
  1966. // 1. Let n be an ILD String value indicating infinity.
  1967. var _n = ild.infinity;
  1968. // 2. Add new part record { [[type]]: "infinity", [[value]]: n } as a new element of the list result.
  1969. arrPush.call(result, { '[[type]]': 'infinity', '[[value]]': _n });
  1970. }
  1971. // iii. Else,
  1972. else {
  1973. // 1. If the value of numberFormat.[[style]] is "percent" and isFinite(x), let x be 100 × x.
  1974. if (internal['[[style]]'] === 'percent' && isFinite(x)) x *= 100;
  1975. var _n2 = void 0;
  1976. // 2. If the numberFormat.[[minimumSignificantDigits]] and numberFormat.[[maximumSignificantDigits]] are present, then
  1977. if (hop.call(internal, '[[minimumSignificantDigits]]') && hop.call(internal, '[[maximumSignificantDigits]]')) {
  1978. // a. Let n be ToRawPrecision(x, numberFormat.[[minimumSignificantDigits]], numberFormat.[[maximumSignificantDigits]]).
  1979. _n2 = ToRawPrecision(x, internal['[[minimumSignificantDigits]]'], internal['[[maximumSignificantDigits]]']);
  1980. }
  1981. // 3. Else,
  1982. else {
  1983. // a. Let n be ToRawFixed(x, numberFormat.[[minimumIntegerDigits]], numberFormat.[[minimumFractionDigits]], numberFormat.[[maximumFractionDigits]]).
  1984. _n2 = ToRawFixed(x, internal['[[minimumIntegerDigits]]'], internal['[[minimumFractionDigits]]'], internal['[[maximumFractionDigits]]']);
  1985. }
  1986. // 4. If the value of the numberFormat.[[numberingSystem]] matches one of the values in the "Numbering System" column of Table 2 below, then
  1987. if (numSys[nums]) {
  1988. (function () {
  1989. // a. Let digits be an array whose 10 String valued elements are the UTF-16 string representations of the 10 digits specified in the "Digits" column of the matching row in Table 2.
  1990. var digits = numSys[nums];
  1991. // a. Replace each digit in n with the value of digits[digit].
  1992. _n2 = String(_n2).replace(/\d/g, function (digit) {
  1993. return digits[digit];
  1994. });
  1995. })();
  1996. }
  1997. // 5. Else use an implementation dependent algorithm to map n to the appropriate representation of n in the given numbering system.
  1998. else _n2 = String(_n2); // ###TODO###
  1999. var integer = void 0;
  2000. var fraction = void 0;
  2001. // 6. Let decimalSepIndex be Call(%StringProto_indexOf%, n, ".", 0).
  2002. var decimalSepIndex = _n2.indexOf('.', 0);
  2003. // 7. If decimalSepIndex > 0, then:
  2004. if (decimalSepIndex > 0) {
  2005. // a. Let integer be the substring of n from position 0, inclusive, to position decimalSepIndex, exclusive.
  2006. integer = _n2.substring(0, decimalSepIndex);
  2007. // a. Let fraction be the substring of n from position decimalSepIndex, exclusive, to the end of n.
  2008. fraction = _n2.substring(decimalSepIndex + 1, decimalSepIndex.length);
  2009. }
  2010. // 8. Else:
  2011. else {
  2012. // a. Let integer be n.
  2013. integer = _n2;
  2014. // a. Let fraction be undefined.
  2015. fraction = undefined;
  2016. }
  2017. // 9. If the value of the numberFormat.[[useGrouping]] is true,
  2018. if (internal['[[useGrouping]]'] === true) {
  2019. // a. Let groupSepSymbol be the ILND String representing the grouping separator.
  2020. var groupSepSymbol = ild.group;
  2021. // a. Let groups be a List whose elements are, in left to right order, the substrings defined by ILND set of locations within the integer.
  2022. var groups = [];
  2023. // ----> implementation:
  2024. // Primary group represents the group closest to the decimal
  2025. var pgSize = data.patterns.primaryGroupSize || 3;
  2026. // Secondary group is every other group
  2027. var sgSize = data.patterns.secondaryGroupSize || pgSize;
  2028. // Group only if necessary
  2029. if (integer.length > pgSize) {
  2030. // Index of the primary grouping separator
  2031. var end = integer.length - pgSize;
  2032. // Starting index for our loop
  2033. var idx = end % sgSize;
  2034. var start = integer.slice(0, idx);
  2035. if (start.length) arrPush.call(groups, start);
  2036. // Loop to separate into secondary grouping digits
  2037. while (idx < end) {
  2038. arrPush.call(groups, integer.slice(idx, idx + sgSize));
  2039. idx += sgSize;
  2040. }
  2041. // Add the primary grouping digits
  2042. arrPush.call(groups, integer.slice(end));
  2043. } else {
  2044. arrPush.call(groups, integer);
  2045. }
  2046. // a. Assert: The number of elements in groups List is greater than 0.
  2047. if (groups.length === 0) throw new Error();
  2048. // a. Repeat, while groups List is not empty:
  2049. while (groups.length) {
  2050. // i. Remove the first element from groups and let integerGroup be the value of that element.
  2051. var integerGroup = arrShift.call(groups);
  2052. // ii. Add new part record { [[type]]: "integer", [[value]]: integerGroup } as a new element of the list result.
  2053. arrPush.call(result, { '[[type]]': 'integer', '[[value]]': integerGroup });
  2054. // iii. If groups List is not empty, then:
  2055. if (groups.length) {
  2056. // 1. Add new part record { [[type]]: "group", [[value]]: groupSepSymbol } as a new element of the list result.
  2057. arrPush.call(result, { '[[type]]': 'group', '[[value]]': groupSepSymbol });
  2058. }
  2059. }
  2060. }
  2061. // 10. Else,
  2062. else {
  2063. // a. Add new part record { [[type]]: "integer", [[value]]: integer } as a new element of the list result.
  2064. arrPush.call(result, { '[[type]]': 'integer', '[[value]]': integer });
  2065. }
  2066. // 11. If fraction is not undefined, then:
  2067. if (fraction !== undefined) {
  2068. // a. Let decimalSepSymbol be the ILND String representing the decimal separator.
  2069. var decimalSepSymbol = ild.decimal;
  2070. // a. Add new part record { [[type]]: "decimal", [[value]]: decimalSepSymbol } as a new element of the list result.
  2071. arrPush.call(result, { '[[type]]': 'decimal', '[[value]]': decimalSepSymbol });
  2072. // a. Add new part record { [[type]]: "fraction", [[value]]: fraction } as a new element of the list result.
  2073. arrPush.call(result, { '[[type]]': 'fraction', '[[value]]': fraction });
  2074. }
  2075. }
  2076. }
  2077. // a. Else if p is equal "plusSign", then:
  2078. else if (p === "plusSign") {
  2079. // i. Let plusSignSymbol be the ILND String representing the plus sign.
  2080. var plusSignSymbol = ild.plusSign;
  2081. // ii. Add new part record { [[type]]: "plusSign", [[value]]: plusSignSymbol } as a new element of the list result.
  2082. arrPush.call(result, { '[[type]]': 'plusSign', '[[value]]': plusSignSymbol });
  2083. }
  2084. // a. Else if p is equal "minusSign", then:
  2085. else if (p === "minusSign") {
  2086. // i. Let minusSignSymbol be the ILND String representing the minus sign.
  2087. var minusSignSymbol = ild.minusSign;
  2088. // ii. Add new part record { [[type]]: "minusSign", [[value]]: minusSignSymbol } as a new element of the list result.
  2089. arrPush.call(result, { '[[type]]': 'minusSign', '[[value]]': minusSignSymbol });
  2090. }
  2091. // a. Else if p is equal "percentSign" and numberFormat.[[style]] is "percent", then:
  2092. else if (p === "percentSign" && internal['[[style]]'] === "percent") {
  2093. // i. Let percentSignSymbol be the ILND String representing the percent sign.
  2094. var percentSignSymbol = ild.percentSign;
  2095. // ii. Add new part record { [[type]]: "percentSign", [[value]]: percentSignSymbol } as a new element of the list result.
  2096. arrPush.call(result, { '[[type]]': 'literal', '[[value]]': percentSignSymbol });
  2097. }
  2098. // a. Else if p is equal "currency" and numberFormat.[[style]] is "currency", then:
  2099. else if (p === "currency" && internal['[[style]]'] === "currency") {
  2100. // i. Let currency be the value of numberFormat.[[currency]].
  2101. var currency = internal['[[currency]]'];
  2102. var cd = void 0;
  2103. // ii. If numberFormat.[[currencyDisplay]] is "code", then
  2104. if (internal['[[currencyDisplay]]'] === "code") {
  2105. // 1. Let cd be currency.
  2106. cd = currency;
  2107. }
  2108. // iii. Else if numberFormat.[[currencyDisplay]] is "symbol", then
  2109. else if (internal['[[currencyDisplay]]'] === "symbol") {
  2110. // 1. Let cd be an ILD string representing currency in short form. If the implementation does not have such a representation of currency, use currency itself.
  2111. cd = data.currencies[currency] || currency;
  2112. }
  2113. // iv. Else if numberFormat.[[currencyDisplay]] is "name", then
  2114. else if (internal['[[currencyDisplay]]'] === "name") {
  2115. // 1. Let cd be an ILD string representing currency in long form. If the implementation does not have such a representation of currency, then use currency itself.
  2116. cd = currency;
  2117. }
  2118. // v. Add new part record { [[type]]: "currency", [[value]]: cd } as a new element of the list result.
  2119. arrPush.call(result, { '[[type]]': 'currency', '[[value]]': cd });
  2120. }
  2121. // a. Else,
  2122. else {
  2123. // i. Let literal be the substring of pattern from position beginIndex, inclusive, to position endIndex, inclusive.
  2124. var _literal = pattern.substring(beginIndex, endIndex);
  2125. // ii. Add new part record { [[type]]: "literal", [[value]]: literal } as a new element of the list result.
  2126. arrPush.call(result, { '[[type]]': 'literal', '[[value]]': _literal });
  2127. }
  2128. // a. Set nextIndex to endIndex + 1.
  2129. nextIndex = endIndex + 1;
  2130. // a. Set beginIndex to Call(%StringProto_indexOf%, pattern, "{", nextIndex)
  2131. beginIndex = pattern.indexOf('{', nextIndex);
  2132. }
  2133. // 9. If nextIndex is less than length, then:
  2134. if (nextIndex < length) {
  2135. // a. Let literal be the substring of pattern from position nextIndex, inclusive, to position length, exclusive.
  2136. var _literal2 = pattern.substring(nextIndex, length);
  2137. // a. Add new part record { [[type]]: "literal", [[value]]: literal } as a new element of the list result.
  2138. arrPush.call(result, { '[[type]]': 'literal', '[[value]]': _literal2 });
  2139. }
  2140. // 10. Return result.
  2141. return result;
  2142. }
  2143. /*
  2144. * @spec[stasm/ecma402/number-format-to-parts/spec/numberformat.html]
  2145. * @clause[sec-formatnumber]
  2146. */
  2147. function FormatNumber(numberFormat, x) {
  2148. // 1. Let parts be ? PartitionNumberPattern(numberFormat, x).
  2149. var parts = PartitionNumberPattern(numberFormat, x);
  2150. // 2. Let result be an empty String.
  2151. var result = '';
  2152. // 3. For each part in parts, do:
  2153. for (var i = 0; parts.length > i; i++) {
  2154. var part = parts[i];
  2155. // a. Set result to a String value produced by concatenating result and part.[[value]].
  2156. result += part['[[value]]'];
  2157. }
  2158. // 4. Return result.
  2159. return result;
  2160. }
  2161. /**
  2162. * When the ToRawPrecision abstract operation is called with arguments x (which
  2163. * must be a finite non-negative number), minPrecision, and maxPrecision (both
  2164. * must be integers between 1 and 21) the following steps are taken:
  2165. */
  2166. function ToRawPrecision(x, minPrecision, maxPrecision) {
  2167. // 1. Let p be maxPrecision.
  2168. var p = maxPrecision;
  2169. var m = void 0,
  2170. e = void 0;
  2171. // 2. If x = 0, then
  2172. if (x === 0) {
  2173. // a. Let m be the String consisting of p occurrences of the character "0".
  2174. m = arrJoin.call(Array(p + 1), '0');
  2175. // b. Let e be 0.
  2176. e = 0;
  2177. }
  2178. // 3. Else
  2179. else {
  2180. // a. Let e and n be integers such that 10ᵖ⁻¹ ≤ n < 10ᵖ and for which the
  2181. // exact mathematical value of n × 10ᵉ⁻ᵖ⁺¹ – x is as close to zero as
  2182. // possible. If there are two such sets of e and n, pick the e and n for
  2183. // which n × 10ᵉ⁻ᵖ⁺¹ is larger.
  2184. e = log10Floor(Math.abs(x));
  2185. // Easier to get to m from here
  2186. var f = Math.round(Math.exp(Math.abs(e - p + 1) * Math.LN10));
  2187. // b. Let m be the String consisting of the digits of the decimal
  2188. // representation of n (in order, with no leading zeroes)
  2189. m = String(Math.round(e - p + 1 < 0 ? x * f : x / f));
  2190. }
  2191. // 4. If e ≥ p, then
  2192. if (e >= p)
  2193. // a. Return the concatenation of m and e-p+1 occurrences of the character "0".
  2194. return m + arrJoin.call(Array(e - p + 1 + 1), '0');
  2195. // 5. If e = p-1, then
  2196. else if (e === p - 1)
  2197. // a. Return m.
  2198. return m;
  2199. // 6. If e ≥ 0, then
  2200. else if (e >= 0)
  2201. // a. Let m be the concatenation of the first e+1 characters of m, the character
  2202. // ".", and the remaining p–(e+1) characters of m.
  2203. m = m.slice(0, e + 1) + '.' + m.slice(e + 1);
  2204. // 7. If e < 0, then
  2205. else if (e < 0)
  2206. // a. Let m be the concatenation of the String "0.", –(e+1) occurrences of the
  2207. // character "0", and the string m.
  2208. m = '0.' + arrJoin.call(Array(-(e + 1) + 1), '0') + m;
  2209. // 8. If m contains the character ".", and maxPrecision > minPrecision, then
  2210. if (m.indexOf(".") >= 0 && maxPrecision > minPrecision) {
  2211. // a. Let cut be maxPrecision – minPrecision.
  2212. var cut = maxPrecision - minPrecision;
  2213. // b. Repeat while cut > 0 and the last character of m is "0":
  2214. while (cut > 0 && m.charAt(m.length - 1) === '0') {
  2215. // i. Remove the last character from m.
  2216. m = m.slice(0, -1);
  2217. // ii. Decrease cut by 1.
  2218. cut--;
  2219. }
  2220. // c. If the last character of m is ".", then
  2221. if (m.charAt(m.length - 1) === '.')
  2222. // i. Remove the last character from m.
  2223. m = m.slice(0, -1);
  2224. }
  2225. // 9. Return m.
  2226. return m;
  2227. }
  2228. /**
  2229. * @spec[tc39/ecma402/master/spec/numberformat.html]
  2230. * @clause[sec-torawfixed]
  2231. * When the ToRawFixed abstract operation is called with arguments x (which must
  2232. * be a finite non-negative number), minInteger (which must be an integer between
  2233. * 1 and 21), minFraction, and maxFraction (which must be integers between 0 and
  2234. * 20) the following steps are taken:
  2235. */
  2236. function ToRawFixed(x, minInteger, minFraction, maxFraction) {
  2237. // 1. Let f be maxFraction.
  2238. var f = maxFraction;
  2239. // 2. Let n be an integer for which the exact mathematical value of n ÷ 10f – x is as close to zero as possible. If there are two such n, pick the larger n.
  2240. var n = Math.pow(10, f) * x; // diverging...
  2241. // 3. If n = 0, let m be the String "0". Otherwise, let m be the String consisting of the digits of the decimal representation of n (in order, with no leading zeroes).
  2242. var m = n === 0 ? "0" : n.toFixed(0); // divering...
  2243. {
  2244. // this diversion is needed to take into consideration big numbers, e.g.:
  2245. // 1.2344501e+37 -> 12344501000000000000000000000000000000
  2246. var idx = void 0;
  2247. var exp = (idx = m.indexOf('e')) > -1 ? m.slice(idx + 1) : 0;
  2248. if (exp) {
  2249. m = m.slice(0, idx).replace('.', '');
  2250. m += arrJoin.call(Array(exp - (m.length - 1) + 1), '0');
  2251. }
  2252. }
  2253. var int = void 0;
  2254. // 4. If f ≠ 0, then
  2255. if (f !== 0) {
  2256. // a. Let k be the number of characters in m.
  2257. var k = m.length;
  2258. // a. If k ≤ f, then
  2259. if (k <= f) {
  2260. // i. Let z be the String consisting of f+1–k occurrences of the character "0".
  2261. var z = arrJoin.call(Array(f + 1 - k + 1), '0');
  2262. // ii. Let m be the concatenation of Strings z and m.
  2263. m = z + m;
  2264. // iii. Let k be f+1.
  2265. k = f + 1;
  2266. }
  2267. // a. Let a be the first k–f characters of m, and let b be the remaining f characters of m.
  2268. var a = m.substring(0, k - f),
  2269. b = m.substring(k - f, m.length);
  2270. // a. Let m be the concatenation of the three Strings a, ".", and b.
  2271. m = a + "." + b;
  2272. // a. Let int be the number of characters in a.
  2273. int = a.length;
  2274. }
  2275. // 5. Else, let int be the number of characters in m.
  2276. else int = m.length;
  2277. // 6. Let cut be maxFraction – minFraction.
  2278. var cut = maxFraction - minFraction;
  2279. // 7. Repeat while cut > 0 and the last character of m is "0":
  2280. while (cut > 0 && m.slice(-1) === "0") {
  2281. // a. Remove the last character from m.
  2282. m = m.slice(0, -1);
  2283. // a. Decrease cut by 1.
  2284. cut--;
  2285. }
  2286. // 8. If the last character of m is ".", then
  2287. if (m.slice(-1) === ".") {
  2288. // a. Remove the last character from m.
  2289. m = m.slice(0, -1);
  2290. }
  2291. // 9. If int < minInteger, then
  2292. if (int < minInteger) {
  2293. // a. Let z be the String consisting of minInteger–int occurrences of the character "0".
  2294. var _z = arrJoin.call(Array(minInteger - int + 1), '0');
  2295. // a. Let m be the concatenation of Strings z and m.
  2296. m = _z + m;
  2297. }
  2298. // 10. Return m.
  2299. return m;
  2300. }
  2301. // Sect 11.3.2 Table 2, Numbering systems
  2302. // ======================================
  2303. var numSys = {
  2304. arab: ["٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"],
  2305. arabext: ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"],
  2306. bali: ["᭐", "᭑", "᭒", "᭓", "᭔", "᭕", "᭖", "᭗", "᭘", "᭙"],
  2307. beng: ["০", "১", "২", "৩", "৪", "৫", "৬", "৭", "৮", "৯"],
  2308. deva: ["०", "१", "२", "३", "४", "५", "६", "७", "८", "९"],
  2309. fullwide: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
  2310. gujr: ["૦", "૧", "૨", "૩", "૪", "૫", "૬", "૭", "૮", "૯"],
  2311. guru: ["੦", "੧", "੨", "੩", "੪", "੫", "੬", "੭", "੮", "੯"],
  2312. hanidec: ["〇", "一", "二", "三", "四", "五", "六", "七", "八", "九"],
  2313. khmr: ["០", "១", "២", "៣", "៤", "៥", "៦", "៧", "៨", "៩"],
  2314. knda: ["೦", "೧", "೨", "೩", "೪", "೫", "೬", "೭", "೮", "೯"],
  2315. laoo: ["໐", "໑", "໒", "໓", "໔", "໕", "໖", "໗", "໘", "໙"],
  2316. latn: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
  2317. limb: ["᥆", "᥇", "᥈", "᥉", "᥊", "᥋", "᥌", "᥍", "᥎", "᥏"],
  2318. mlym: ["൦", "൧", "൨", "൩", "൪", "൫", "൬", "൭", "൮", "൯"],
  2319. mong: ["᠐", "᠑", "᠒", "᠓", "᠔", "᠕", "᠖", "᠗", "᠘", "᠙"],
  2320. mymr: ["၀", "၁", "၂", "၃", "၄", "၅", "၆", "၇", "၈", "၉"],
  2321. orya: ["୦", "୧", "୨", "୩", "୪", "୫", "୬", "୭", "୮", "୯"],
  2322. tamldec: ["௦", "௧", "௨", "௩", "௪", "௫", "௬", "௭", "௮", "௯"],
  2323. telu: ["౦", "౧", "౨", "౩", "౪", "౫", "౬", "౭", "౮", "౯"],
  2324. thai: ["๐", "๑", "๒", "๓", "๔", "๕", "๖", "๗", "๘", "๙"],
  2325. tibt: ["༠", "༡", "༢", "༣", "༤", "༥", "༦", "༧", "༨", "༩"]
  2326. };
  2327. /**
  2328. * This function provides access to the locale and formatting options computed
  2329. * during initialization of the object.
  2330. *
  2331. * The function returns a new object whose properties and attributes are set as
  2332. * if constructed by an object literal assigning to each of the following
  2333. * properties the value of the corresponding internal property of this
  2334. * NumberFormat object (see 11.4): locale, numberingSystem, style, currency,
  2335. * currencyDisplay, minimumIntegerDigits, minimumFractionDigits,
  2336. * maximumFractionDigits, minimumSignificantDigits, maximumSignificantDigits, and
  2337. * useGrouping. Properties whose corresponding internal properties are not present
  2338. * are not assigned.
  2339. */
  2340. /* 11.3.3 */defineProperty(Intl$1.NumberFormat.prototype, 'resolvedOptions', {
  2341. configurable: true,
  2342. writable: true,
  2343. value: function value() {
  2344. var prop = void 0,
  2345. descs = new Record(),
  2346. props = ['locale', 'numberingSystem', 'style', 'currency', 'currencyDisplay', 'minimumIntegerDigits', 'minimumFractionDigits', 'maximumFractionDigits', 'minimumSignificantDigits', 'maximumSignificantDigits', 'useGrouping'],
  2347. internal = this !== null && babelHelpers$1["typeof"](this) === 'object' && getInternalProperties(this);
  2348. // Satisfy test 11.3_b
  2349. if (!internal || !internal['[[initializedNumberFormat]]']) throw new TypeError('`this` value for resolvedOptions() is not an initialized Intl.NumberFormat object.');
  2350. for (var i = 0, max = props.length; i < max; i++) {
  2351. if (hop.call(internal, prop = '[[' + props[i] + ']]')) descs[props[i]] = { value: internal[prop], writable: true, configurable: true, enumerable: true };
  2352. }
  2353. return objCreate({}, descs);
  2354. }
  2355. });
  2356. /* jslint esnext: true */
  2357. // Match these datetime components in a CLDR pattern, except those in single quotes
  2358. var expDTComponents = /(?:[Eec]{1,6}|G{1,5}|[Qq]{1,5}|(?:[yYur]+|U{1,5})|[ML]{1,5}|d{1,2}|D{1,3}|F{1}|[abB]{1,5}|[hkHK]{1,2}|w{1,2}|W{1}|m{1,2}|s{1,2}|[zZOvVxX]{1,4})(?=([^']*'[^']*')*[^']*$)/g;
  2359. // trim patterns after transformations
  2360. var expPatternTrimmer = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
  2361. // Skip over patterns with these datetime components because we don't have data
  2362. // to back them up:
  2363. // timezone, weekday, amoung others
  2364. var unwantedDTCs = /[rqQASjJgwWIQq]/; // xXVO were removed from this list in favor of computing matches with timeZoneName values but printing as empty string
  2365. var dtKeys = ["era", "year", "month", "day", "weekday", "quarter"];
  2366. var tmKeys = ["hour", "minute", "second", "hour12", "timeZoneName"];
  2367. function isDateFormatOnly(obj) {
  2368. for (var i = 0; i < tmKeys.length; i += 1) {
  2369. if (obj.hasOwnProperty(tmKeys[i])) {
  2370. return false;
  2371. }
  2372. }
  2373. return true;
  2374. }
  2375. function isTimeFormatOnly(obj) {
  2376. for (var i = 0; i < dtKeys.length; i += 1) {
  2377. if (obj.hasOwnProperty(dtKeys[i])) {
  2378. return false;
  2379. }
  2380. }
  2381. return true;
  2382. }
  2383. function joinDateAndTimeFormats(dateFormatObj, timeFormatObj) {
  2384. var o = { _: {} };
  2385. for (var i = 0; i < dtKeys.length; i += 1) {
  2386. if (dateFormatObj[dtKeys[i]]) {
  2387. o[dtKeys[i]] = dateFormatObj[dtKeys[i]];
  2388. }
  2389. if (dateFormatObj._[dtKeys[i]]) {
  2390. o._[dtKeys[i]] = dateFormatObj._[dtKeys[i]];
  2391. }
  2392. }
  2393. for (var j = 0; j < tmKeys.length; j += 1) {
  2394. if (timeFormatObj[tmKeys[j]]) {
  2395. o[tmKeys[j]] = timeFormatObj[tmKeys[j]];
  2396. }
  2397. if (timeFormatObj._[tmKeys[j]]) {
  2398. o._[tmKeys[j]] = timeFormatObj._[tmKeys[j]];
  2399. }
  2400. }
  2401. return o;
  2402. }
  2403. function computeFinalPatterns(formatObj) {
  2404. // From http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns:
  2405. // 'In patterns, two single quotes represents a literal single quote, either
  2406. // inside or outside single quotes. Text within single quotes is not
  2407. // interpreted in any way (except for two adjacent single quotes).'
  2408. formatObj.pattern12 = formatObj.extendedPattern.replace(/'([^']*)'/g, function ($0, literal) {
  2409. return literal ? literal : "'";
  2410. });
  2411. // pattern 12 is always the default. we can produce the 24 by removing {ampm}
  2412. formatObj.pattern = formatObj.pattern12.replace('{ampm}', '').replace(expPatternTrimmer, '');
  2413. return formatObj;
  2414. }
  2415. function expDTComponentsMeta($0, formatObj) {
  2416. switch ($0.charAt(0)) {
  2417. // --- Era
  2418. case 'G':
  2419. formatObj.era = ['short', 'short', 'short', 'long', 'narrow'][$0.length - 1];
  2420. return '{era}';
  2421. // --- Year
  2422. case 'y':
  2423. case 'Y':
  2424. case 'u':
  2425. case 'U':
  2426. case 'r':
  2427. formatObj.year = $0.length === 2 ? '2-digit' : 'numeric';
  2428. return '{year}';
  2429. // --- Quarter (not supported in this polyfill)
  2430. case 'Q':
  2431. case 'q':
  2432. formatObj.quarter = ['numeric', '2-digit', 'short', 'long', 'narrow'][$0.length - 1];
  2433. return '{quarter}';
  2434. // --- Month
  2435. case 'M':
  2436. case 'L':
  2437. formatObj.month = ['numeric', '2-digit', 'short', 'long', 'narrow'][$0.length - 1];
  2438. return '{month}';
  2439. // --- Week (not supported in this polyfill)
  2440. case 'w':
  2441. // week of the year
  2442. formatObj.week = $0.length === 2 ? '2-digit' : 'numeric';
  2443. return '{weekday}';
  2444. case 'W':
  2445. // week of the month
  2446. formatObj.week = 'numeric';
  2447. return '{weekday}';
  2448. // --- Day
  2449. case 'd':
  2450. // day of the month
  2451. formatObj.day = $0.length === 2 ? '2-digit' : 'numeric';
  2452. return '{day}';
  2453. case 'D': // day of the year
  2454. case 'F': // day of the week
  2455. case 'g':
  2456. // 1..n: Modified Julian day
  2457. formatObj.day = 'numeric';
  2458. return '{day}';
  2459. // --- Week Day
  2460. case 'E':
  2461. // day of the week
  2462. formatObj.weekday = ['short', 'short', 'short', 'long', 'narrow', 'short'][$0.length - 1];
  2463. return '{weekday}';
  2464. case 'e':
  2465. // local day of the week
  2466. formatObj.weekday = ['numeric', '2-digit', 'short', 'long', 'narrow', 'short'][$0.length - 1];
  2467. return '{weekday}';
  2468. case 'c':
  2469. // stand alone local day of the week
  2470. formatObj.weekday = ['numeric', undefined, 'short', 'long', 'narrow', 'short'][$0.length - 1];
  2471. return '{weekday}';
  2472. // --- Period
  2473. case 'a': // AM, PM
  2474. case 'b': // am, pm, noon, midnight
  2475. case 'B':
  2476. // flexible day periods
  2477. formatObj.hour12 = true;
  2478. return '{ampm}';
  2479. // --- Hour
  2480. case 'h':
  2481. case 'H':
  2482. formatObj.hour = $0.length === 2 ? '2-digit' : 'numeric';
  2483. return '{hour}';
  2484. case 'k':
  2485. case 'K':
  2486. formatObj.hour12 = true; // 12-hour-cycle time formats (using h or K)
  2487. formatObj.hour = $0.length === 2 ? '2-digit' : 'numeric';
  2488. return '{hour}';
  2489. // --- Minute
  2490. case 'm':
  2491. formatObj.minute = $0.length === 2 ? '2-digit' : 'numeric';
  2492. return '{minute}';
  2493. // --- Second
  2494. case 's':
  2495. formatObj.second = $0.length === 2 ? '2-digit' : 'numeric';
  2496. return '{second}';
  2497. case 'S':
  2498. case 'A':
  2499. formatObj.second = 'numeric';
  2500. return '{second}';
  2501. // --- Timezone
  2502. case 'z': // 1..3, 4: specific non-location format
  2503. case 'Z': // 1..3, 4, 5: The ISO8601 varios formats
  2504. case 'O': // 1, 4: miliseconds in day short, long
  2505. case 'v': // 1, 4: generic non-location format
  2506. case 'V': // 1, 2, 3, 4: time zone ID or city
  2507. case 'X': // 1, 2, 3, 4: The ISO8601 varios formats
  2508. case 'x':
  2509. // 1, 2, 3, 4: The ISO8601 varios formats
  2510. // this polyfill only supports much, for now, we are just doing something dummy
  2511. formatObj.timeZoneName = $0.length < 4 ? 'short' : 'long';
  2512. return '{timeZoneName}';
  2513. }
  2514. }
  2515. /**
  2516. * Converts the CLDR availableFormats into the objects and patterns required by
  2517. * the ECMAScript Internationalization API specification.
  2518. */
  2519. function createDateTimeFormat(skeleton, pattern) {
  2520. // we ignore certain patterns that are unsupported to avoid this expensive op.
  2521. if (unwantedDTCs.test(pattern)) return undefined;
  2522. var formatObj = {
  2523. originalPattern: pattern,
  2524. _: {}
  2525. };
  2526. // Replace the pattern string with the one required by the specification, whilst
  2527. // at the same time evaluating it for the subsets and formats
  2528. formatObj.extendedPattern = pattern.replace(expDTComponents, function ($0) {
  2529. // See which symbol we're dealing with
  2530. return expDTComponentsMeta($0, formatObj._);
  2531. });
  2532. // Match the skeleton string with the one required by the specification
  2533. // this implementation is based on the Date Field Symbol Table:
  2534. // http://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
  2535. // Note: we are adding extra data to the formatObject even though this polyfill
  2536. // might not support it.
  2537. skeleton.replace(expDTComponents, function ($0) {
  2538. // See which symbol we're dealing with
  2539. return expDTComponentsMeta($0, formatObj);
  2540. });
  2541. return computeFinalPatterns(formatObj);
  2542. }
  2543. /**
  2544. * Processes DateTime formats from CLDR to an easier-to-parse format.
  2545. * the result of this operation should be cached the first time a particular
  2546. * calendar is analyzed.
  2547. *
  2548. * The specification requires we support at least the following subsets of
  2549. * date/time components:
  2550. *
  2551. * - 'weekday', 'year', 'month', 'day', 'hour', 'minute', 'second'
  2552. * - 'weekday', 'year', 'month', 'day'
  2553. * - 'year', 'month', 'day'
  2554. * - 'year', 'month'
  2555. * - 'month', 'day'
  2556. * - 'hour', 'minute', 'second'
  2557. * - 'hour', 'minute'
  2558. *
  2559. * We need to cherry pick at least these subsets from the CLDR data and convert
  2560. * them into the pattern objects used in the ECMA-402 API.
  2561. */
  2562. function createDateTimeFormats(formats) {
  2563. var availableFormats = formats.availableFormats;
  2564. var timeFormats = formats.timeFormats;
  2565. var dateFormats = formats.dateFormats;
  2566. var result = [];
  2567. var skeleton = void 0,
  2568. pattern = void 0,
  2569. computed = void 0,
  2570. i = void 0,
  2571. j = void 0;
  2572. var timeRelatedFormats = [];
  2573. var dateRelatedFormats = [];
  2574. // Map available (custom) formats into a pattern for createDateTimeFormats
  2575. for (skeleton in availableFormats) {
  2576. if (availableFormats.hasOwnProperty(skeleton)) {
  2577. pattern = availableFormats[skeleton];
  2578. computed = createDateTimeFormat(skeleton, pattern);
  2579. if (computed) {
  2580. result.push(computed);
  2581. // in some cases, the format is only displaying date specific props
  2582. // or time specific props, in which case we need to also produce the
  2583. // combined formats.
  2584. if (isDateFormatOnly(computed)) {
  2585. dateRelatedFormats.push(computed);
  2586. } else if (isTimeFormatOnly(computed)) {
  2587. timeRelatedFormats.push(computed);
  2588. }
  2589. }
  2590. }
  2591. }
  2592. // Map time formats into a pattern for createDateTimeFormats
  2593. for (skeleton in timeFormats) {
  2594. if (timeFormats.hasOwnProperty(skeleton)) {
  2595. pattern = timeFormats[skeleton];
  2596. computed = createDateTimeFormat(skeleton, pattern);
  2597. if (computed) {
  2598. result.push(computed);
  2599. timeRelatedFormats.push(computed);
  2600. }
  2601. }
  2602. }
  2603. // Map date formats into a pattern for createDateTimeFormats
  2604. for (skeleton in dateFormats) {
  2605. if (dateFormats.hasOwnProperty(skeleton)) {
  2606. pattern = dateFormats[skeleton];
  2607. computed = createDateTimeFormat(skeleton, pattern);
  2608. if (computed) {
  2609. result.push(computed);
  2610. dateRelatedFormats.push(computed);
  2611. }
  2612. }
  2613. }
  2614. // combine custom time and custom date formats when they are orthogonals to complete the
  2615. // formats supported by CLDR.
  2616. // This Algo is based on section "Missing Skeleton Fields" from:
  2617. // http://unicode.org/reports/tr35/tr35-dates.html#availableFormats_appendItems
  2618. for (i = 0; i < timeRelatedFormats.length; i += 1) {
  2619. for (j = 0; j < dateRelatedFormats.length; j += 1) {
  2620. if (dateRelatedFormats[j].month === 'long') {
  2621. pattern = dateRelatedFormats[j].weekday ? formats.full : formats.long;
  2622. } else if (dateRelatedFormats[j].month === 'short') {
  2623. pattern = formats.medium;
  2624. } else {
  2625. pattern = formats.short;
  2626. }
  2627. computed = joinDateAndTimeFormats(dateRelatedFormats[j], timeRelatedFormats[i]);
  2628. computed.originalPattern = pattern;
  2629. computed.extendedPattern = pattern.replace('{0}', timeRelatedFormats[i].extendedPattern).replace('{1}', dateRelatedFormats[j].extendedPattern).replace(/^[,\s]+|[,\s]+$/gi, '');
  2630. result.push(computeFinalPatterns(computed));
  2631. }
  2632. }
  2633. return result;
  2634. }
  2635. // this represents the exceptions of the rule that are not covered by CLDR availableFormats
  2636. // for single property configurations, they play no role when using multiple properties, and
  2637. // those that are not in this table, are not exceptions or are not covered by the data we
  2638. // provide.
  2639. var validSyntheticProps = {
  2640. second: {
  2641. numeric: 's',
  2642. '2-digit': 'ss'
  2643. },
  2644. minute: {
  2645. numeric: 'm',
  2646. '2-digit': 'mm'
  2647. },
  2648. year: {
  2649. numeric: 'y',
  2650. '2-digit': 'yy'
  2651. },
  2652. day: {
  2653. numeric: 'd',
  2654. '2-digit': 'dd'
  2655. },
  2656. month: {
  2657. numeric: 'L',
  2658. '2-digit': 'LL',
  2659. narrow: 'LLLLL',
  2660. short: 'LLL',
  2661. long: 'LLLL'
  2662. },
  2663. weekday: {
  2664. narrow: 'ccccc',
  2665. short: 'ccc',
  2666. long: 'cccc'
  2667. }
  2668. };
  2669. function generateSyntheticFormat(propName, propValue) {
  2670. if (validSyntheticProps[propName] && validSyntheticProps[propName][propValue]) {
  2671. var _ref2;
  2672. return _ref2 = {
  2673. originalPattern: validSyntheticProps[propName][propValue],
  2674. _: defineProperty$1({}, propName, propValue),
  2675. extendedPattern: "{" + propName + "}"
  2676. }, defineProperty$1(_ref2, propName, propValue), defineProperty$1(_ref2, "pattern12", "{" + propName + "}"), defineProperty$1(_ref2, "pattern", "{" + propName + "}"), _ref2;
  2677. }
  2678. }
  2679. // An object map of date component keys, saves using a regex later
  2680. var dateWidths = objCreate(null, { narrow: {}, short: {}, long: {} });
  2681. /**
  2682. * Returns a string for a date component, resolved using multiple inheritance as specified
  2683. * as specified in the Unicode Technical Standard 35.
  2684. */
  2685. function resolveDateString(data, ca, component, width, key) {
  2686. // From http://www.unicode.org/reports/tr35/tr35.html#Multiple_Inheritance:
  2687. // 'In clearly specified instances, resources may inherit from within the same locale.
  2688. // For example, ... the Buddhist calendar inherits from the Gregorian calendar.'
  2689. var obj = data[ca] && data[ca][component] ? data[ca][component] : data.gregory[component],
  2690. // "sideways" inheritance resolves strings when a key doesn't exist
  2691. alts = {
  2692. narrow: ['short', 'long'],
  2693. short: ['long', 'narrow'],
  2694. long: ['short', 'narrow']
  2695. },
  2696. //
  2697. resolved = hop.call(obj, width) ? obj[width] : hop.call(obj, alts[width][0]) ? obj[alts[width][0]] : obj[alts[width][1]];
  2698. // `key` wouldn't be specified for components 'dayPeriods'
  2699. return key !== null ? resolved[key] : resolved;
  2700. }
  2701. // Define the DateTimeFormat constructor internally so it cannot be tainted
  2702. function DateTimeFormatConstructor() {
  2703. var locales = arguments[0];
  2704. var options = arguments[1];
  2705. if (!this || this === Intl$1) {
  2706. return new Intl$1.DateTimeFormat(locales, options);
  2707. }
  2708. return InitializeDateTimeFormat(toObject(this), locales, options);
  2709. }
  2710. defineProperty(Intl$1, 'DateTimeFormat', {
  2711. configurable: true,
  2712. writable: true,
  2713. value: DateTimeFormatConstructor
  2714. });
  2715. // Must explicitly set prototypes as unwritable
  2716. defineProperty(DateTimeFormatConstructor, 'prototype', {
  2717. writable: false
  2718. });
  2719. /**
  2720. * The abstract operation InitializeDateTimeFormat accepts the arguments dateTimeFormat
  2721. * (which must be an object), locales, and options. It initializes dateTimeFormat as a
  2722. * DateTimeFormat object.
  2723. */
  2724. function /* 12.1.1.1 */InitializeDateTimeFormat(dateTimeFormat, locales, options) {
  2725. // This will be a internal properties object if we're not already initialized
  2726. var internal = getInternalProperties(dateTimeFormat);
  2727. // Create an object whose props can be used to restore the values of RegExp props
  2728. var regexpRestore = createRegExpRestore();
  2729. // 1. If dateTimeFormat has an [[initializedIntlObject]] internal property with
  2730. // value true, throw a TypeError exception.
  2731. if (internal['[[initializedIntlObject]]'] === true) throw new TypeError('`this` object has already been initialized as an Intl object');
  2732. // Need this to access the `internal` object
  2733. defineProperty(dateTimeFormat, '__getInternalProperties', {
  2734. value: function value() {
  2735. // NOTE: Non-standard, for internal use only
  2736. if (arguments[0] === secret) return internal;
  2737. }
  2738. });
  2739. // 2. Set the [[initializedIntlObject]] internal property of numberFormat to true.
  2740. internal['[[initializedIntlObject]]'] = true;
  2741. // 3. Let requestedLocales be the result of calling the CanonicalizeLocaleList
  2742. // abstract operation (defined in 9.2.1) with argument locales.
  2743. var requestedLocales = CanonicalizeLocaleList(locales);
  2744. // 4. Let options be the result of calling the ToDateTimeOptions abstract
  2745. // operation (defined below) with arguments options, "any", and "date".
  2746. options = ToDateTimeOptions(options, 'any', 'date');
  2747. // 5. Let opt be a new Record.
  2748. var opt = new Record();
  2749. // 6. Let matcher be the result of calling the GetOption abstract operation
  2750. // (defined in 9.2.9) with arguments options, "localeMatcher", "string", a List
  2751. // containing the two String values "lookup" and "best fit", and "best fit".
  2752. var matcher = GetOption(options, 'localeMatcher', 'string', new List('lookup', 'best fit'), 'best fit');
  2753. // 7. Set opt.[[localeMatcher]] to matcher.
  2754. opt['[[localeMatcher]]'] = matcher;
  2755. // 8. Let DateTimeFormat be the standard built-in object that is the initial
  2756. // value of Intl.DateTimeFormat.
  2757. var DateTimeFormat = internals.DateTimeFormat; // This is what we *really* need
  2758. // 9. Let localeData be the value of the [[localeData]] internal property of
  2759. // DateTimeFormat.
  2760. var localeData = DateTimeFormat['[[localeData]]'];
  2761. // 10. Let r be the result of calling the ResolveLocale abstract operation
  2762. // (defined in 9.2.5) with the [[availableLocales]] internal property of
  2763. // DateTimeFormat, requestedLocales, opt, the [[relevantExtensionKeys]]
  2764. // internal property of DateTimeFormat, and localeData.
  2765. var r = ResolveLocale(DateTimeFormat['[[availableLocales]]'], requestedLocales, opt, DateTimeFormat['[[relevantExtensionKeys]]'], localeData);
  2766. // 11. Set the [[locale]] internal property of dateTimeFormat to the value of
  2767. // r.[[locale]].
  2768. internal['[[locale]]'] = r['[[locale]]'];
  2769. // 12. Set the [[calendar]] internal property of dateTimeFormat to the value of
  2770. // r.[[ca]].
  2771. internal['[[calendar]]'] = r['[[ca]]'];
  2772. // 13. Set the [[numberingSystem]] internal property of dateTimeFormat to the value of
  2773. // r.[[nu]].
  2774. internal['[[numberingSystem]]'] = r['[[nu]]'];
  2775. // The specification doesn't tell us to do this, but it's helpful later on
  2776. internal['[[dataLocale]]'] = r['[[dataLocale]]'];
  2777. // 14. Let dataLocale be the value of r.[[dataLocale]].
  2778. var dataLocale = r['[[dataLocale]]'];
  2779. // 15. Let tz be the result of calling the [[Get]] internal method of options with
  2780. // argument "timeZone".
  2781. var tz = options.timeZone;
  2782. // 16. If tz is not undefined, then
  2783. if (tz !== undefined) {
  2784. // a. Let tz be ToString(tz).
  2785. // b. Convert tz to upper case as described in 6.1.
  2786. // NOTE: If an implementation accepts additional time zone values, as permitted
  2787. // under certain conditions by the Conformance clause, different casing
  2788. // rules apply.
  2789. tz = toLatinUpperCase(tz);
  2790. // c. If tz is not "UTC", then throw a RangeError exception.
  2791. // ###TODO: accept more time zones###
  2792. if (tz !== 'UTC') throw new RangeError('timeZone is not supported.');
  2793. }
  2794. // 17. Set the [[timeZone]] internal property of dateTimeFormat to tz.
  2795. internal['[[timeZone]]'] = tz;
  2796. // 18. Let opt be a new Record.
  2797. opt = new Record();
  2798. // 19. For each row of Table 3, except the header row, do:
  2799. for (var prop in dateTimeComponents) {
  2800. if (!hop.call(dateTimeComponents, prop)) continue;
  2801. // 20. Let prop be the name given in the Property column of the row.
  2802. // 21. Let value be the result of calling the GetOption abstract operation,
  2803. // passing as argument options, the name given in the Property column of the
  2804. // row, "string", a List containing the strings given in the Values column of
  2805. // the row, and undefined.
  2806. var value = GetOption(options, prop, 'string', dateTimeComponents[prop]);
  2807. // 22. Set opt.[[<prop>]] to value.
  2808. opt['[[' + prop + ']]'] = value;
  2809. }
  2810. // Assigned a value below
  2811. var bestFormat = void 0;
  2812. // 23. Let dataLocaleData be the result of calling the [[Get]] internal method of
  2813. // localeData with argument dataLocale.
  2814. var dataLocaleData = localeData[dataLocale];
  2815. // 24. Let formats be the result of calling the [[Get]] internal method of
  2816. // dataLocaleData with argument "formats".
  2817. // Note: we process the CLDR formats into the spec'd structure
  2818. var formats = ToDateTimeFormats(dataLocaleData.formats);
  2819. // 25. Let matcher be the result of calling the GetOption abstract operation with
  2820. // arguments options, "formatMatcher", "string", a List containing the two String
  2821. // values "basic" and "best fit", and "best fit".
  2822. matcher = GetOption(options, 'formatMatcher', 'string', new List('basic', 'best fit'), 'best fit');
  2823. // Optimization: caching the processed formats as a one time operation by
  2824. // replacing the initial structure from localeData
  2825. dataLocaleData.formats = formats;
  2826. // 26. If matcher is "basic", then
  2827. if (matcher === 'basic') {
  2828. // 27. Let bestFormat be the result of calling the BasicFormatMatcher abstract
  2829. // operation (defined below) with opt and formats.
  2830. bestFormat = BasicFormatMatcher(opt, formats);
  2831. // 28. Else
  2832. } else {
  2833. {
  2834. // diverging
  2835. var _hr = GetOption(options, 'hour12', 'boolean' /*, undefined, undefined*/);
  2836. opt.hour12 = _hr === undefined ? dataLocaleData.hour12 : _hr;
  2837. }
  2838. // 29. Let bestFormat be the result of calling the BestFitFormatMatcher
  2839. // abstract operation (defined below) with opt and formats.
  2840. bestFormat = BestFitFormatMatcher(opt, formats);
  2841. }
  2842. // 30. For each row in Table 3, except the header row, do
  2843. for (var _prop in dateTimeComponents) {
  2844. if (!hop.call(dateTimeComponents, _prop)) continue;
  2845. // a. Let prop be the name given in the Property column of the row.
  2846. // b. Let pDesc be the result of calling the [[GetOwnProperty]] internal method of
  2847. // bestFormat with argument prop.
  2848. // c. If pDesc is not undefined, then
  2849. if (hop.call(bestFormat, _prop)) {
  2850. // i. Let p be the result of calling the [[Get]] internal method of bestFormat
  2851. // with argument prop.
  2852. var p = bestFormat[_prop];
  2853. {
  2854. // diverging
  2855. p = bestFormat._ && hop.call(bestFormat._, _prop) ? bestFormat._[_prop] : p;
  2856. }
  2857. // ii. Set the [[<prop>]] internal property of dateTimeFormat to p.
  2858. internal['[[' + _prop + ']]'] = p;
  2859. }
  2860. }
  2861. var pattern = void 0; // Assigned a value below
  2862. // 31. Let hr12 be the result of calling the GetOption abstract operation with
  2863. // arguments options, "hour12", "boolean", undefined, and undefined.
  2864. var hr12 = GetOption(options, 'hour12', 'boolean' /*, undefined, undefined*/);
  2865. // 32. If dateTimeFormat has an internal property [[hour]], then
  2866. if (internal['[[hour]]']) {
  2867. // a. If hr12 is undefined, then let hr12 be the result of calling the [[Get]]
  2868. // internal method of dataLocaleData with argument "hour12".
  2869. hr12 = hr12 === undefined ? dataLocaleData.hour12 : hr12;
  2870. // b. Set the [[hour12]] internal property of dateTimeFormat to hr12.
  2871. internal['[[hour12]]'] = hr12;
  2872. // c. If hr12 is true, then
  2873. if (hr12 === true) {
  2874. // i. Let hourNo0 be the result of calling the [[Get]] internal method of
  2875. // dataLocaleData with argument "hourNo0".
  2876. var hourNo0 = dataLocaleData.hourNo0;
  2877. // ii. Set the [[hourNo0]] internal property of dateTimeFormat to hourNo0.
  2878. internal['[[hourNo0]]'] = hourNo0;
  2879. // iii. Let pattern be the result of calling the [[Get]] internal method of
  2880. // bestFormat with argument "pattern12".
  2881. pattern = bestFormat.pattern12;
  2882. }
  2883. // d. Else
  2884. else
  2885. // i. Let pattern be the result of calling the [[Get]] internal method of
  2886. // bestFormat with argument "pattern".
  2887. pattern = bestFormat.pattern;
  2888. }
  2889. // 33. Else
  2890. else
  2891. // a. Let pattern be the result of calling the [[Get]] internal method of
  2892. // bestFormat with argument "pattern".
  2893. pattern = bestFormat.pattern;
  2894. // 34. Set the [[pattern]] internal property of dateTimeFormat to pattern.
  2895. internal['[[pattern]]'] = pattern;
  2896. // 35. Set the [[boundFormat]] internal property of dateTimeFormat to undefined.
  2897. internal['[[boundFormat]]'] = undefined;
  2898. // 36. Set the [[initializedDateTimeFormat]] internal property of dateTimeFormat to
  2899. // true.
  2900. internal['[[initializedDateTimeFormat]]'] = true;
  2901. // In ES3, we need to pre-bind the format() function
  2902. if (es3) dateTimeFormat.format = GetFormatDateTime.call(dateTimeFormat);
  2903. // Restore the RegExp properties
  2904. regexpRestore();
  2905. // Return the newly initialised object
  2906. return dateTimeFormat;
  2907. }
  2908. /**
  2909. * Several DateTimeFormat algorithms use values from the following table, which provides
  2910. * property names and allowable values for the components of date and time formats:
  2911. */
  2912. var dateTimeComponents = {
  2913. weekday: ["narrow", "short", "long"],
  2914. era: ["narrow", "short", "long"],
  2915. year: ["2-digit", "numeric"],
  2916. month: ["2-digit", "numeric", "narrow", "short", "long"],
  2917. day: ["2-digit", "numeric"],
  2918. hour: ["2-digit", "numeric"],
  2919. minute: ["2-digit", "numeric"],
  2920. second: ["2-digit", "numeric"],
  2921. timeZoneName: ["short", "long"]
  2922. };
  2923. /**
  2924. * When the ToDateTimeOptions abstract operation is called with arguments options,
  2925. * required, and defaults, the following steps are taken:
  2926. */
  2927. function ToDateTimeFormats(formats) {
  2928. if (Object.prototype.toString.call(formats) === '[object Array]') {
  2929. return formats;
  2930. }
  2931. return createDateTimeFormats(formats);
  2932. }
  2933. /**
  2934. * When the ToDateTimeOptions abstract operation is called with arguments options,
  2935. * required, and defaults, the following steps are taken:
  2936. */
  2937. function ToDateTimeOptions(options, required, defaults) {
  2938. // 1. If options is undefined, then let options be null, else let options be
  2939. // ToObject(options).
  2940. if (options === undefined) options = null;else {
  2941. // (#12) options needs to be a Record, but it also needs to inherit properties
  2942. var opt2 = toObject(options);
  2943. options = new Record();
  2944. for (var k in opt2) {
  2945. options[k] = opt2[k];
  2946. }
  2947. }
  2948. // 2. Let create be the standard built-in function object defined in ES5, 15.2.3.5.
  2949. var create = objCreate;
  2950. // 3. Let options be the result of calling the [[Call]] internal method of create with
  2951. // undefined as the this value and an argument list containing the single item
  2952. // options.
  2953. options = create(options);
  2954. // 4. Let needDefaults be true.
  2955. var needDefaults = true;
  2956. // 5. If required is "date" or "any", then
  2957. if (required === 'date' || required === 'any') {
  2958. // a. For each of the property names "weekday", "year", "month", "day":
  2959. // i. If the result of calling the [[Get]] internal method of options with the
  2960. // property name is not undefined, then let needDefaults be false.
  2961. if (options.weekday !== undefined || options.year !== undefined || options.month !== undefined || options.day !== undefined) needDefaults = false;
  2962. }
  2963. // 6. If required is "time" or "any", then
  2964. if (required === 'time' || required === 'any') {
  2965. // a. For each of the property names "hour", "minute", "second":
  2966. // i. If the result of calling the [[Get]] internal method of options with the
  2967. // property name is not undefined, then let needDefaults be false.
  2968. if (options.hour !== undefined || options.minute !== undefined || options.second !== undefined) needDefaults = false;
  2969. }
  2970. // 7. If needDefaults is true and defaults is either "date" or "all", then
  2971. if (needDefaults && (defaults === 'date' || defaults === 'all'))
  2972. // a. For each of the property names "year", "month", "day":
  2973. // i. Call the [[DefineOwnProperty]] internal method of options with the
  2974. // property name, Property Descriptor {[[Value]]: "numeric", [[Writable]]:
  2975. // true, [[Enumerable]]: true, [[Configurable]]: true}, and false.
  2976. options.year = options.month = options.day = 'numeric';
  2977. // 8. If needDefaults is true and defaults is either "time" or "all", then
  2978. if (needDefaults && (defaults === 'time' || defaults === 'all'))
  2979. // a. For each of the property names "hour", "minute", "second":
  2980. // i. Call the [[DefineOwnProperty]] internal method of options with the
  2981. // property name, Property Descriptor {[[Value]]: "numeric", [[Writable]]:
  2982. // true, [[Enumerable]]: true, [[Configurable]]: true}, and false.
  2983. options.hour = options.minute = options.second = 'numeric';
  2984. // 9. Return options.
  2985. return options;
  2986. }
  2987. /**
  2988. * When the BasicFormatMatcher abstract operation is called with two arguments options and
  2989. * formats, the following steps are taken:
  2990. */
  2991. function BasicFormatMatcher(options, formats) {
  2992. // 1. Let removalPenalty be 120.
  2993. var removalPenalty = 120;
  2994. // 2. Let additionPenalty be 20.
  2995. var additionPenalty = 20;
  2996. // 3. Let longLessPenalty be 8.
  2997. var longLessPenalty = 8;
  2998. // 4. Let longMorePenalty be 6.
  2999. var longMorePenalty = 6;
  3000. // 5. Let shortLessPenalty be 6.
  3001. var shortLessPenalty = 6;
  3002. // 6. Let shortMorePenalty be 3.
  3003. var shortMorePenalty = 3;
  3004. // 7. Let bestScore be -Infinity.
  3005. var bestScore = -Infinity;
  3006. // 8. Let bestFormat be undefined.
  3007. var bestFormat = void 0;
  3008. // 9. Let i be 0.
  3009. var i = 0;
  3010. // 10. Assert: formats is an Array object.
  3011. // 11. Let len be the result of calling the [[Get]] internal method of formats with argument "length".
  3012. var len = formats.length;
  3013. // 12. Repeat while i < len:
  3014. while (i < len) {
  3015. // a. Let format be the result of calling the [[Get]] internal method of formats with argument ToString(i).
  3016. var format = formats[i];
  3017. // b. Let score be 0.
  3018. var score = 0;
  3019. // c. For each property shown in Table 3:
  3020. for (var property in dateTimeComponents) {
  3021. if (!hop.call(dateTimeComponents, property)) continue;
  3022. // i. Let optionsProp be options.[[<property>]].
  3023. var optionsProp = options['[[' + property + ']]'];
  3024. // ii. Let formatPropDesc be the result of calling the [[GetOwnProperty]] internal method of format
  3025. // with argument property.
  3026. // iii. If formatPropDesc is not undefined, then
  3027. // 1. Let formatProp be the result of calling the [[Get]] internal method of format with argument property.
  3028. var formatProp = hop.call(format, property) ? format[property] : undefined;
  3029. // iv. If optionsProp is undefined and formatProp is not undefined, then decrease score by
  3030. // additionPenalty.
  3031. if (optionsProp === undefined && formatProp !== undefined) score -= additionPenalty;
  3032. // v. Else if optionsProp is not undefined and formatProp is undefined, then decrease score by
  3033. // removalPenalty.
  3034. else if (optionsProp !== undefined && formatProp === undefined) score -= removalPenalty;
  3035. // vi. Else
  3036. else {
  3037. // 1. Let values be the array ["2-digit", "numeric", "narrow", "short",
  3038. // "long"].
  3039. var values = ['2-digit', 'numeric', 'narrow', 'short', 'long'];
  3040. // 2. Let optionsPropIndex be the index of optionsProp within values.
  3041. var optionsPropIndex = arrIndexOf.call(values, optionsProp);
  3042. // 3. Let formatPropIndex be the index of formatProp within values.
  3043. var formatPropIndex = arrIndexOf.call(values, formatProp);
  3044. // 4. Let delta be max(min(formatPropIndex - optionsPropIndex, 2), -2).
  3045. var delta = Math.max(Math.min(formatPropIndex - optionsPropIndex, 2), -2);
  3046. // 5. If delta = 2, decrease score by longMorePenalty.
  3047. if (delta === 2) score -= longMorePenalty;
  3048. // 6. Else if delta = 1, decrease score by shortMorePenalty.
  3049. else if (delta === 1) score -= shortMorePenalty;
  3050. // 7. Else if delta = -1, decrease score by shortLessPenalty.
  3051. else if (delta === -1) score -= shortLessPenalty;
  3052. // 8. Else if delta = -2, decrease score by longLessPenalty.
  3053. else if (delta === -2) score -= longLessPenalty;
  3054. }
  3055. }
  3056. // d. If score > bestScore, then
  3057. if (score > bestScore) {
  3058. // i. Let bestScore be score.
  3059. bestScore = score;
  3060. // ii. Let bestFormat be format.
  3061. bestFormat = format;
  3062. }
  3063. // e. Increase i by 1.
  3064. i++;
  3065. }
  3066. // 13. Return bestFormat.
  3067. return bestFormat;
  3068. }
  3069. /**
  3070. * When the BestFitFormatMatcher abstract operation is called with two arguments options
  3071. * and formats, it performs implementation dependent steps, which should return a set of
  3072. * component representations that a typical user of the selected locale would perceive as
  3073. * at least as good as the one returned by BasicFormatMatcher.
  3074. *
  3075. * This polyfill defines the algorithm to be the same as BasicFormatMatcher,
  3076. * with the addition of bonus points awarded where the requested format is of
  3077. * the same data type as the potentially matching format.
  3078. *
  3079. * This algo relies on the concept of closest distance matching described here:
  3080. * http://unicode.org/reports/tr35/tr35-dates.html#Matching_Skeletons
  3081. * Typically a “best match” is found using a closest distance match, such as:
  3082. *
  3083. * Symbols requesting a best choice for the locale are replaced.
  3084. * j → one of {H, k, h, K}; C → one of {a, b, B}
  3085. * -> Covered by cldr.js matching process
  3086. *
  3087. * For fields with symbols representing the same type (year, month, day, etc):
  3088. * Most symbols have a small distance from each other.
  3089. * M ≅ L; E ≅ c; a ≅ b ≅ B; H ≅ k ≅ h ≅ K; ...
  3090. * -> Covered by cldr.js matching process
  3091. *
  3092. * Width differences among fields, other than those marking text vs numeric, are given small distance from each other.
  3093. * MMM ≅ MMMM
  3094. * MM ≅ M
  3095. * Numeric and text fields are given a larger distance from each other.
  3096. * MMM ≈ MM
  3097. * Symbols representing substantial differences (week of year vs week of month) are given much larger a distances from each other.
  3098. * d ≋ D; ...
  3099. * Missing or extra fields cause a match to fail. (But see Missing Skeleton Fields).
  3100. *
  3101. *
  3102. * For example,
  3103. *
  3104. * { month: 'numeric', day: 'numeric' }
  3105. *
  3106. * should match
  3107. *
  3108. * { month: '2-digit', day: '2-digit' }
  3109. *
  3110. * rather than
  3111. *
  3112. * { month: 'short', day: 'numeric' }
  3113. *
  3114. * This makes sense because a user requesting a formatted date with numeric parts would
  3115. * not expect to see the returned format containing narrow, short or long part names
  3116. */
  3117. function BestFitFormatMatcher(options, formats) {
  3118. /** Diverging: this block implements the hack for single property configuration, eg.:
  3119. *
  3120. * `new Intl.DateTimeFormat('en', {day: 'numeric'})`
  3121. *
  3122. * should produce a single digit with the day of the month. This is needed because
  3123. * CLDR `availableFormats` data structure doesn't cover these cases.
  3124. */
  3125. {
  3126. var optionsPropNames = [];
  3127. for (var property in dateTimeComponents) {
  3128. if (!hop.call(dateTimeComponents, property)) continue;
  3129. if (options['[[' + property + ']]'] !== undefined) {
  3130. optionsPropNames.push(property);
  3131. }
  3132. }
  3133. if (optionsPropNames.length === 1) {
  3134. var _bestFormat = generateSyntheticFormat(optionsPropNames[0], options['[[' + optionsPropNames[0] + ']]']);
  3135. if (_bestFormat) {
  3136. return _bestFormat;
  3137. }
  3138. }
  3139. }
  3140. // 1. Let removalPenalty be 120.
  3141. var removalPenalty = 120;
  3142. // 2. Let additionPenalty be 20.
  3143. var additionPenalty = 20;
  3144. // 3. Let longLessPenalty be 8.
  3145. var longLessPenalty = 8;
  3146. // 4. Let longMorePenalty be 6.
  3147. var longMorePenalty = 6;
  3148. // 5. Let shortLessPenalty be 6.
  3149. var shortLessPenalty = 6;
  3150. // 6. Let shortMorePenalty be 3.
  3151. var shortMorePenalty = 3;
  3152. var patternPenalty = 2;
  3153. var hour12Penalty = 1;
  3154. // 7. Let bestScore be -Infinity.
  3155. var bestScore = -Infinity;
  3156. // 8. Let bestFormat be undefined.
  3157. var bestFormat = void 0;
  3158. // 9. Let i be 0.
  3159. var i = 0;
  3160. // 10. Assert: formats is an Array object.
  3161. // 11. Let len be the result of calling the [[Get]] internal method of formats with argument "length".
  3162. var len = formats.length;
  3163. // 12. Repeat while i < len:
  3164. while (i < len) {
  3165. // a. Let format be the result of calling the [[Get]] internal method of formats with argument ToString(i).
  3166. var format = formats[i];
  3167. // b. Let score be 0.
  3168. var score = 0;
  3169. // c. For each property shown in Table 3:
  3170. for (var _property in dateTimeComponents) {
  3171. if (!hop.call(dateTimeComponents, _property)) continue;
  3172. // i. Let optionsProp be options.[[<property>]].
  3173. var optionsProp = options['[[' + _property + ']]'];
  3174. // ii. Let formatPropDesc be the result of calling the [[GetOwnProperty]] internal method of format
  3175. // with argument property.
  3176. // iii. If formatPropDesc is not undefined, then
  3177. // 1. Let formatProp be the result of calling the [[Get]] internal method of format with argument property.
  3178. var formatProp = hop.call(format, _property) ? format[_property] : undefined;
  3179. // Diverging: using the default properties produced by the pattern/skeleton
  3180. // to match it with user options, and apply a penalty
  3181. var patternProp = hop.call(format._, _property) ? format._[_property] : undefined;
  3182. if (optionsProp !== patternProp) {
  3183. score -= patternPenalty;
  3184. }
  3185. // iv. If optionsProp is undefined and formatProp is not undefined, then decrease score by
  3186. // additionPenalty.
  3187. if (optionsProp === undefined && formatProp !== undefined) score -= additionPenalty;
  3188. // v. Else if optionsProp is not undefined and formatProp is undefined, then decrease score by
  3189. // removalPenalty.
  3190. else if (optionsProp !== undefined && formatProp === undefined) score -= removalPenalty;
  3191. // vi. Else
  3192. else {
  3193. // 1. Let values be the array ["2-digit", "numeric", "narrow", "short",
  3194. // "long"].
  3195. var values = ['2-digit', 'numeric', 'narrow', 'short', 'long'];
  3196. // 2. Let optionsPropIndex be the index of optionsProp within values.
  3197. var optionsPropIndex = arrIndexOf.call(values, optionsProp);
  3198. // 3. Let formatPropIndex be the index of formatProp within values.
  3199. var formatPropIndex = arrIndexOf.call(values, formatProp);
  3200. // 4. Let delta be max(min(formatPropIndex - optionsPropIndex, 2), -2).
  3201. var delta = Math.max(Math.min(formatPropIndex - optionsPropIndex, 2), -2);
  3202. {
  3203. // diverging from spec
  3204. // When the bestFit argument is true, subtract additional penalty where data types are not the same
  3205. if (formatPropIndex <= 1 && optionsPropIndex >= 2 || formatPropIndex >= 2 && optionsPropIndex <= 1) {
  3206. // 5. If delta = 2, decrease score by longMorePenalty.
  3207. if (delta > 0) score -= longMorePenalty;else if (delta < 0) score -= longLessPenalty;
  3208. } else {
  3209. // 5. If delta = 2, decrease score by longMorePenalty.
  3210. if (delta > 1) score -= shortMorePenalty;else if (delta < -1) score -= shortLessPenalty;
  3211. }
  3212. }
  3213. }
  3214. }
  3215. {
  3216. // diverging to also take into consideration differences between 12 or 24 hours
  3217. // which is special for the best fit only.
  3218. if (format._.hour12 !== options.hour12) {
  3219. score -= hour12Penalty;
  3220. }
  3221. }
  3222. // d. If score > bestScore, then
  3223. if (score > bestScore) {
  3224. // i. Let bestScore be score.
  3225. bestScore = score;
  3226. // ii. Let bestFormat be format.
  3227. bestFormat = format;
  3228. }
  3229. // e. Increase i by 1.
  3230. i++;
  3231. }
  3232. // 13. Return bestFormat.
  3233. return bestFormat;
  3234. }
  3235. /* 12.2.3 */internals.DateTimeFormat = {
  3236. '[[availableLocales]]': [],
  3237. '[[relevantExtensionKeys]]': ['ca', 'nu'],
  3238. '[[localeData]]': {}
  3239. };
  3240. /**
  3241. * When the supportedLocalesOf method of Intl.DateTimeFormat is called, the
  3242. * following steps are taken:
  3243. */
  3244. /* 12.2.2 */
  3245. defineProperty(Intl$1.DateTimeFormat, 'supportedLocalesOf', {
  3246. configurable: true,
  3247. writable: true,
  3248. value: fnBind.call(function (locales) {
  3249. // Bound functions only have the `this` value altered if being used as a constructor,
  3250. // this lets us imitate a native function that has no constructor
  3251. if (!hop.call(this, '[[availableLocales]]')) throw new TypeError('supportedLocalesOf() is not a constructor');
  3252. // Create an object whose props can be used to restore the values of RegExp props
  3253. var regexpRestore = createRegExpRestore(),
  3254. // 1. If options is not provided, then let options be undefined.
  3255. options = arguments[1],
  3256. // 2. Let availableLocales be the value of the [[availableLocales]] internal
  3257. // property of the standard built-in object that is the initial value of
  3258. // Intl.NumberFormat.
  3259. availableLocales = this['[[availableLocales]]'],
  3260. // 3. Let requestedLocales be the result of calling the CanonicalizeLocaleList
  3261. // abstract operation (defined in 9.2.1) with argument locales.
  3262. requestedLocales = CanonicalizeLocaleList(locales);
  3263. // Restore the RegExp properties
  3264. regexpRestore();
  3265. // 4. Return the result of calling the SupportedLocales abstract operation
  3266. // (defined in 9.2.8) with arguments availableLocales, requestedLocales,
  3267. // and options.
  3268. return SupportedLocales(availableLocales, requestedLocales, options);
  3269. }, internals.NumberFormat)
  3270. });
  3271. /**
  3272. * This named accessor property returns a function that formats a number
  3273. * according to the effective locale and the formatting options of this
  3274. * DateTimeFormat object.
  3275. */
  3276. /* 12.3.2 */defineProperty(Intl$1.DateTimeFormat.prototype, 'format', {
  3277. configurable: true,
  3278. get: GetFormatDateTime
  3279. });
  3280. function GetFormatDateTime() {
  3281. var internal = this !== null && babelHelpers$1["typeof"](this) === 'object' && getInternalProperties(this);
  3282. // Satisfy test 12.3_b
  3283. if (!internal || !internal['[[initializedDateTimeFormat]]']) throw new TypeError('`this` value for format() is not an initialized Intl.DateTimeFormat object.');
  3284. // The value of the [[Get]] attribute is a function that takes the following
  3285. // steps:
  3286. // 1. If the [[boundFormat]] internal property of this DateTimeFormat object
  3287. // is undefined, then:
  3288. if (internal['[[boundFormat]]'] === undefined) {
  3289. // a. Let F be a Function object, with internal properties set as
  3290. // specified for built-in functions in ES5, 15, or successor, and the
  3291. // length property set to 0, that takes the argument date and
  3292. // performs the following steps:
  3293. var F = function F() {
  3294. var date = arguments.length <= 0 || arguments[0] === undefined ? undefined : arguments[0];
  3295. // i. If date is not provided or is undefined, then let x be the
  3296. // result as if by the expression Date.now() where Date.now is
  3297. // the standard built-in function defined in ES5, 15.9.4.4.
  3298. // ii. Else let x be ToNumber(date).
  3299. // iii. Return the result of calling the FormatDateTime abstract
  3300. // operation (defined below) with arguments this and x.
  3301. var x = date === undefined ? Date.now() : toNumber(date);
  3302. return FormatDateTime(this, x);
  3303. };
  3304. // b. Let bind be the standard built-in function object defined in ES5,
  3305. // 15.3.4.5.
  3306. // c. Let bf be the result of calling the [[Call]] internal method of
  3307. // bind with F as the this value and an argument list containing
  3308. // the single item this.
  3309. var bf = fnBind.call(F, this);
  3310. // d. Set the [[boundFormat]] internal property of this NumberFormat
  3311. // object to bf.
  3312. internal['[[boundFormat]]'] = bf;
  3313. }
  3314. // Return the value of the [[boundFormat]] internal property of this
  3315. // NumberFormat object.
  3316. return internal['[[boundFormat]]'];
  3317. }
  3318. function formatToParts$1() {
  3319. var date = arguments.length <= 0 || arguments[0] === undefined ? undefined : arguments[0];
  3320. var internal = this !== null && babelHelpers$1["typeof"](this) === 'object' && getInternalProperties(this);
  3321. if (!internal || !internal['[[initializedDateTimeFormat]]']) throw new TypeError('`this` value for formatToParts() is not an initialized Intl.DateTimeFormat object.');
  3322. var x = date === undefined ? Date.now() : toNumber(date);
  3323. return FormatToPartsDateTime(this, x);
  3324. }
  3325. Object.defineProperty(Intl$1.DateTimeFormat.prototype, 'formatToParts', {
  3326. enumerable: false,
  3327. writable: true,
  3328. configurable: true,
  3329. value: formatToParts$1
  3330. });
  3331. function CreateDateTimeParts(dateTimeFormat, x) {
  3332. // 1. If x is not a finite Number, then throw a RangeError exception.
  3333. if (!isFinite(x)) throw new RangeError('Invalid valid date passed to format');
  3334. var internal = dateTimeFormat.__getInternalProperties(secret);
  3335. // Creating restore point for properties on the RegExp object... please wait
  3336. /* let regexpRestore = */createRegExpRestore(); // ###TODO: review this
  3337. // 2. Let locale be the value of the [[locale]] internal property of dateTimeFormat.
  3338. var locale = internal['[[locale]]'];
  3339. // 3. Let nf be the result of creating a new NumberFormat object as if by the
  3340. // expression new Intl.NumberFormat([locale], {useGrouping: false}) where
  3341. // Intl.NumberFormat is the standard built-in constructor defined in 11.1.3.
  3342. var nf = new Intl$1.NumberFormat([locale], { useGrouping: false });
  3343. // 4. Let nf2 be the result of creating a new NumberFormat object as if by the
  3344. // expression new Intl.NumberFormat([locale], {minimumIntegerDigits: 2, useGrouping:
  3345. // false}) where Intl.NumberFormat is the standard built-in constructor defined in
  3346. // 11.1.3.
  3347. var nf2 = new Intl$1.NumberFormat([locale], { minimumIntegerDigits: 2, useGrouping: false });
  3348. // 5. Let tm be the result of calling the ToLocalTime abstract operation (defined
  3349. // below) with x, the value of the [[calendar]] internal property of dateTimeFormat,
  3350. // and the value of the [[timeZone]] internal property of dateTimeFormat.
  3351. var tm = ToLocalTime(x, internal['[[calendar]]'], internal['[[timeZone]]']);
  3352. // 6. Let result be the value of the [[pattern]] internal property of dateTimeFormat.
  3353. var pattern = internal['[[pattern]]'];
  3354. // 7.
  3355. var result = new List();
  3356. // 8.
  3357. var index = 0;
  3358. // 9.
  3359. var beginIndex = pattern.indexOf('{');
  3360. // 10.
  3361. var endIndex = 0;
  3362. // Need the locale minus any extensions
  3363. var dataLocale = internal['[[dataLocale]]'];
  3364. // Need the calendar data from CLDR
  3365. var localeData = internals.DateTimeFormat['[[localeData]]'][dataLocale].calendars;
  3366. var ca = internal['[[calendar]]'];
  3367. // 11.
  3368. while (beginIndex !== -1) {
  3369. var fv = void 0;
  3370. // a.
  3371. endIndex = pattern.indexOf('}', beginIndex);
  3372. // b.
  3373. if (endIndex === -1) {
  3374. throw new Error('Unclosed pattern');
  3375. }
  3376. // c.
  3377. if (beginIndex > index) {
  3378. arrPush.call(result, {
  3379. type: 'literal',
  3380. value: pattern.substring(index, beginIndex)
  3381. });
  3382. }
  3383. // d.
  3384. var p = pattern.substring(beginIndex + 1, endIndex);
  3385. // e.
  3386. if (dateTimeComponents.hasOwnProperty(p)) {
  3387. // i. Let f be the value of the [[<p>]] internal property of dateTimeFormat.
  3388. var f = internal['[[' + p + ']]'];
  3389. // ii. Let v be the value of tm.[[<p>]].
  3390. var v = tm['[[' + p + ']]'];
  3391. // iii. If p is "year" and v ≤ 0, then let v be 1 - v.
  3392. if (p === 'year' && v <= 0) {
  3393. v = 1 - v;
  3394. }
  3395. // iv. If p is "month", then increase v by 1.
  3396. else if (p === 'month') {
  3397. v++;
  3398. }
  3399. // v. If p is "hour" and the value of the [[hour12]] internal property of
  3400. // dateTimeFormat is true, then
  3401. else if (p === 'hour' && internal['[[hour12]]'] === true) {
  3402. // 1. Let v be v modulo 12.
  3403. v = v % 12;
  3404. // 2. If v is 0 and the value of the [[hourNo0]] internal property of
  3405. // dateTimeFormat is true, then let v be 12.
  3406. if (v === 0 && internal['[[hourNo0]]'] === true) {
  3407. v = 12;
  3408. }
  3409. }
  3410. // vi. If f is "numeric", then
  3411. if (f === 'numeric') {
  3412. // 1. Let fv be the result of calling the FormatNumber abstract operation
  3413. // (defined in 11.3.2) with arguments nf and v.
  3414. fv = FormatNumber(nf, v);
  3415. }
  3416. // vii. Else if f is "2-digit", then
  3417. else if (f === '2-digit') {
  3418. // 1. Let fv be the result of calling the FormatNumber abstract operation
  3419. // with arguments nf2 and v.
  3420. fv = FormatNumber(nf2, v);
  3421. // 2. If the length of fv is greater than 2, let fv be the substring of fv
  3422. // containing the last two characters.
  3423. if (fv.length > 2) {
  3424. fv = fv.slice(-2);
  3425. }
  3426. }
  3427. // viii. Else if f is "narrow", "short", or "long", then let fv be a String
  3428. // value representing f in the desired form; the String value depends upon
  3429. // the implementation and the effective locale and calendar of
  3430. // dateTimeFormat. If p is "month", then the String value may also depend
  3431. // on whether dateTimeFormat has a [[day]] internal property. If p is
  3432. // "timeZoneName", then the String value may also depend on the value of
  3433. // the [[inDST]] field of tm.
  3434. else if (f in dateWidths) {
  3435. switch (p) {
  3436. case 'month':
  3437. fv = resolveDateString(localeData, ca, 'months', f, tm['[[' + p + ']]']);
  3438. break;
  3439. case 'weekday':
  3440. try {
  3441. fv = resolveDateString(localeData, ca, 'days', f, tm['[[' + p + ']]']);
  3442. // fv = resolveDateString(ca.days, f)[tm['[['+ p +']]']];
  3443. } catch (e) {
  3444. throw new Error('Could not find weekday data for locale ' + locale);
  3445. }
  3446. break;
  3447. case 'timeZoneName':
  3448. fv = ''; // ###TODO
  3449. break;
  3450. case 'era':
  3451. try {
  3452. fv = resolveDateString(localeData, ca, 'eras', f, tm['[[' + p + ']]']);
  3453. } catch (e) {
  3454. throw new Error('Could not find era data for locale ' + locale);
  3455. }
  3456. break;
  3457. default:
  3458. fv = tm['[[' + p + ']]'];
  3459. }
  3460. }
  3461. // ix
  3462. arrPush.call(result, {
  3463. type: p,
  3464. value: fv
  3465. });
  3466. // f.
  3467. } else if (p === 'ampm') {
  3468. // i.
  3469. var _v = tm['[[hour]]'];
  3470. // ii./iii.
  3471. fv = resolveDateString(localeData, ca, 'dayPeriods', _v > 11 ? 'pm' : 'am', null);
  3472. // iv.
  3473. arrPush.call(result, {
  3474. type: 'dayPeriod',
  3475. value: fv
  3476. });
  3477. // g.
  3478. } else {
  3479. arrPush.call(result, {
  3480. type: 'literal',
  3481. value: pattern.substring(beginIndex, endIndex + 1)
  3482. });
  3483. }
  3484. // h.
  3485. index = endIndex + 1;
  3486. // i.
  3487. beginIndex = pattern.indexOf('{', index);
  3488. }
  3489. // 12.
  3490. if (endIndex < pattern.length - 1) {
  3491. arrPush.call(result, {
  3492. type: 'literal',
  3493. value: pattern.substr(endIndex + 1)
  3494. });
  3495. }
  3496. // 13.
  3497. return result;
  3498. }
  3499. /**
  3500. * When the FormatDateTime abstract operation is called with arguments dateTimeFormat
  3501. * (which must be an object initialized as a DateTimeFormat) and x (which must be a Number
  3502. * value), it returns a String value representing x (interpreted as a time value as
  3503. * specified in ES5, 15.9.1.1) according to the effective locale and the formatting
  3504. * options of dateTimeFormat.
  3505. */
  3506. function FormatDateTime(dateTimeFormat, x) {
  3507. var parts = CreateDateTimeParts(dateTimeFormat, x);
  3508. var result = '';
  3509. for (var i = 0; parts.length > i; i++) {
  3510. var part = parts[i];
  3511. result += part.value;
  3512. }
  3513. return result;
  3514. }
  3515. function FormatToPartsDateTime(dateTimeFormat, x) {
  3516. var parts = CreateDateTimeParts(dateTimeFormat, x);
  3517. var result = [];
  3518. for (var i = 0; parts.length > i; i++) {
  3519. var part = parts[i];
  3520. result.push({
  3521. type: part.type,
  3522. value: part.value
  3523. });
  3524. }
  3525. return result;
  3526. }
  3527. /**
  3528. * When the ToLocalTime abstract operation is called with arguments date, calendar, and
  3529. * timeZone, the following steps are taken:
  3530. */
  3531. function ToLocalTime(date, calendar, timeZone) {
  3532. // 1. Apply calendrical calculations on date for the given calendar and time zone to
  3533. // produce weekday, era, year, month, day, hour, minute, second, and inDST values.
  3534. // The calculations should use best available information about the specified
  3535. // calendar and time zone. If the calendar is "gregory", then the calculations must
  3536. // match the algorithms specified in ES5, 15.9.1, except that calculations are not
  3537. // bound by the restrictions on the use of best available information on time zones
  3538. // for local time zone adjustment and daylight saving time adjustment imposed by
  3539. // ES5, 15.9.1.7 and 15.9.1.8.
  3540. // ###TODO###
  3541. var d = new Date(date),
  3542. m = 'get' + (timeZone || '');
  3543. // 2. Return a Record with fields [[weekday]], [[era]], [[year]], [[month]], [[day]],
  3544. // [[hour]], [[minute]], [[second]], and [[inDST]], each with the corresponding
  3545. // calculated value.
  3546. return new Record({
  3547. '[[weekday]]': d[m + 'Day'](),
  3548. '[[era]]': +(d[m + 'FullYear']() >= 0),
  3549. '[[year]]': d[m + 'FullYear'](),
  3550. '[[month]]': d[m + 'Month'](),
  3551. '[[day]]': d[m + 'Date'](),
  3552. '[[hour]]': d[m + 'Hours'](),
  3553. '[[minute]]': d[m + 'Minutes'](),
  3554. '[[second]]': d[m + 'Seconds'](),
  3555. '[[inDST]]': false // ###TODO###
  3556. });
  3557. }
  3558. /**
  3559. * The function returns a new object whose properties and attributes are set as if
  3560. * constructed by an object literal assigning to each of the following properties the
  3561. * value of the corresponding internal property of this DateTimeFormat object (see 12.4):
  3562. * locale, calendar, numberingSystem, timeZone, hour12, weekday, era, year, month, day,
  3563. * hour, minute, second, and timeZoneName. Properties whose corresponding internal
  3564. * properties are not present are not assigned.
  3565. */
  3566. /* 12.3.3 */defineProperty(Intl$1.DateTimeFormat.prototype, 'resolvedOptions', {
  3567. writable: true,
  3568. configurable: true,
  3569. value: function value() {
  3570. var prop = void 0,
  3571. descs = new Record(),
  3572. props = ['locale', 'calendar', 'numberingSystem', 'timeZone', 'hour12', 'weekday', 'era', 'year', 'month', 'day', 'hour', 'minute', 'second', 'timeZoneName'],
  3573. internal = this !== null && babelHelpers$1["typeof"](this) === 'object' && getInternalProperties(this);
  3574. // Satisfy test 12.3_b
  3575. if (!internal || !internal['[[initializedDateTimeFormat]]']) throw new TypeError('`this` value for resolvedOptions() is not an initialized Intl.DateTimeFormat object.');
  3576. for (var i = 0, max = props.length; i < max; i++) {
  3577. if (hop.call(internal, prop = '[[' + props[i] + ']]')) descs[props[i]] = { value: internal[prop], writable: true, configurable: true, enumerable: true };
  3578. }
  3579. return objCreate({}, descs);
  3580. }
  3581. });
  3582. var ls = Intl$1.__localeSensitiveProtos = {
  3583. Number: {},
  3584. Date: {}
  3585. };
  3586. /**
  3587. * When the toLocaleString method is called with optional arguments locales and options,
  3588. * the following steps are taken:
  3589. */
  3590. /* 13.2.1 */ls.Number.toLocaleString = function () {
  3591. // Satisfy test 13.2.1_1
  3592. if (Object.prototype.toString.call(this) !== '[object Number]') throw new TypeError('`this` value must be a number for Number.prototype.toLocaleString()');
  3593. // 1. Let x be this Number value (as defined in ES5, 15.7.4).
  3594. // 2. If locales is not provided, then let locales be undefined.
  3595. // 3. If options is not provided, then let options be undefined.
  3596. // 4. Let numberFormat be the result of creating a new object as if by the
  3597. // expression new Intl.NumberFormat(locales, options) where
  3598. // Intl.NumberFormat is the standard built-in constructor defined in 11.1.3.
  3599. // 5. Return the result of calling the FormatNumber abstract operation
  3600. // (defined in 11.3.2) with arguments numberFormat and x.
  3601. return FormatNumber(new NumberFormatConstructor(arguments[0], arguments[1]), this);
  3602. };
  3603. /**
  3604. * When the toLocaleString method is called with optional arguments locales and options,
  3605. * the following steps are taken:
  3606. */
  3607. /* 13.3.1 */ls.Date.toLocaleString = function () {
  3608. // Satisfy test 13.3.0_1
  3609. if (Object.prototype.toString.call(this) !== '[object Date]') throw new TypeError('`this` value must be a Date instance for Date.prototype.toLocaleString()');
  3610. // 1. Let x be this time value (as defined in ES5, 15.9.5).
  3611. var x = +this;
  3612. // 2. If x is NaN, then return "Invalid Date".
  3613. if (isNaN(x)) return 'Invalid Date';
  3614. // 3. If locales is not provided, then let locales be undefined.
  3615. var locales = arguments[0];
  3616. // 4. If options is not provided, then let options be undefined.
  3617. var options = arguments[1];
  3618. // 5. Let options be the result of calling the ToDateTimeOptions abstract
  3619. // operation (defined in 12.1.1) with arguments options, "any", and "all".
  3620. options = ToDateTimeOptions(options, 'any', 'all');
  3621. // 6. Let dateTimeFormat be the result of creating a new object as if by the
  3622. // expression new Intl.DateTimeFormat(locales, options) where
  3623. // Intl.DateTimeFormat is the standard built-in constructor defined in 12.1.3.
  3624. var dateTimeFormat = new DateTimeFormatConstructor(locales, options);
  3625. // 7. Return the result of calling the FormatDateTime abstract operation (defined
  3626. // in 12.3.2) with arguments dateTimeFormat and x.
  3627. return FormatDateTime(dateTimeFormat, x);
  3628. };
  3629. /**
  3630. * When the toLocaleDateString method is called with optional arguments locales and
  3631. * options, the following steps are taken:
  3632. */
  3633. /* 13.3.2 */ls.Date.toLocaleDateString = function () {
  3634. // Satisfy test 13.3.0_1
  3635. if (Object.prototype.toString.call(this) !== '[object Date]') throw new TypeError('`this` value must be a Date instance for Date.prototype.toLocaleDateString()');
  3636. // 1. Let x be this time value (as defined in ES5, 15.9.5).
  3637. var x = +this;
  3638. // 2. If x is NaN, then return "Invalid Date".
  3639. if (isNaN(x)) return 'Invalid Date';
  3640. // 3. If locales is not provided, then let locales be undefined.
  3641. var locales = arguments[0],
  3642. // 4. If options is not provided, then let options be undefined.
  3643. options = arguments[1];
  3644. // 5. Let options be the result of calling the ToDateTimeOptions abstract
  3645. // operation (defined in 12.1.1) with arguments options, "date", and "date".
  3646. options = ToDateTimeOptions(options, 'date', 'date');
  3647. // 6. Let dateTimeFormat be the result of creating a new object as if by the
  3648. // expression new Intl.DateTimeFormat(locales, options) where
  3649. // Intl.DateTimeFormat is the standard built-in constructor defined in 12.1.3.
  3650. var dateTimeFormat = new DateTimeFormatConstructor(locales, options);
  3651. // 7. Return the result of calling the FormatDateTime abstract operation (defined
  3652. // in 12.3.2) with arguments dateTimeFormat and x.
  3653. return FormatDateTime(dateTimeFormat, x);
  3654. };
  3655. /**
  3656. * When the toLocaleTimeString method is called with optional arguments locales and
  3657. * options, the following steps are taken:
  3658. */
  3659. /* 13.3.3 */ls.Date.toLocaleTimeString = function () {
  3660. // Satisfy test 13.3.0_1
  3661. if (Object.prototype.toString.call(this) !== '[object Date]') throw new TypeError('`this` value must be a Date instance for Date.prototype.toLocaleTimeString()');
  3662. // 1. Let x be this time value (as defined in ES5, 15.9.5).
  3663. var x = +this;
  3664. // 2. If x is NaN, then return "Invalid Date".
  3665. if (isNaN(x)) return 'Invalid Date';
  3666. // 3. If locales is not provided, then let locales be undefined.
  3667. var locales = arguments[0];
  3668. // 4. If options is not provided, then let options be undefined.
  3669. var options = arguments[1];
  3670. // 5. Let options be the result of calling the ToDateTimeOptions abstract
  3671. // operation (defined in 12.1.1) with arguments options, "time", and "time".
  3672. options = ToDateTimeOptions(options, 'time', 'time');
  3673. // 6. Let dateTimeFormat be the result of creating a new object as if by the
  3674. // expression new Intl.DateTimeFormat(locales, options) where
  3675. // Intl.DateTimeFormat is the standard built-in constructor defined in 12.1.3.
  3676. var dateTimeFormat = new DateTimeFormatConstructor(locales, options);
  3677. // 7. Return the result of calling the FormatDateTime abstract operation (defined
  3678. // in 12.3.2) with arguments dateTimeFormat and x.
  3679. return FormatDateTime(dateTimeFormat, x);
  3680. };
  3681. defineProperty(Intl$1, '__applyLocaleSensitivePrototypes', {
  3682. writable: true,
  3683. configurable: true,
  3684. value: function value() {
  3685. defineProperty(Number.prototype, 'toLocaleString', { writable: true, configurable: true, value: ls.Number.toLocaleString });
  3686. // Need this here for IE 8, to avoid the _DontEnum_ bug
  3687. defineProperty(Date.prototype, 'toLocaleString', { writable: true, configurable: true, value: ls.Date.toLocaleString });
  3688. for (var k in ls.Date) {
  3689. if (hop.call(ls.Date, k)) defineProperty(Date.prototype, k, { writable: true, configurable: true, value: ls.Date[k] });
  3690. }
  3691. }
  3692. });
  3693. /**
  3694. * Can't really ship a single script with data for hundreds of locales, so we provide
  3695. * this __addLocaleData method as a means for the developer to add the data on an
  3696. * as-needed basis
  3697. */
  3698. defineProperty(Intl$1, '__addLocaleData', {
  3699. value: function value(data) {
  3700. if (!IsStructurallyValidLanguageTag(data.locale)) throw new Error("Object passed doesn't identify itself with a valid language tag");
  3701. addLocaleData(data, data.locale);
  3702. }
  3703. });
  3704. function addLocaleData(data, tag) {
  3705. // Both NumberFormat and DateTimeFormat require number data, so throw if it isn't present
  3706. if (!data.number) throw new Error("Object passed doesn't contain locale data for Intl.NumberFormat");
  3707. var locale = void 0,
  3708. locales = [tag],
  3709. parts = tag.split('-');
  3710. // Create fallbacks for locale data with scripts, e.g. Latn, Hans, Vaii, etc
  3711. if (parts.length > 2 && parts[1].length === 4) arrPush.call(locales, parts[0] + '-' + parts[2]);
  3712. while (locale = arrShift.call(locales)) {
  3713. // Add to NumberFormat internal properties as per 11.2.3
  3714. arrPush.call(internals.NumberFormat['[[availableLocales]]'], locale);
  3715. internals.NumberFormat['[[localeData]]'][locale] = data.number;
  3716. // ...and DateTimeFormat internal properties as per 12.2.3
  3717. if (data.date) {
  3718. data.date.nu = data.number.nu;
  3719. arrPush.call(internals.DateTimeFormat['[[availableLocales]]'], locale);
  3720. internals.DateTimeFormat['[[localeData]]'][locale] = data.date;
  3721. }
  3722. }
  3723. // If this is the first set of locale data added, make it the default
  3724. if (defaultLocale === undefined) setDefaultLocale(tag);
  3725. }
  3726. defineProperty(Intl$1, '__disableRegExpRestore', {
  3727. value: function value() {
  3728. internals.disableRegExpRestore = true;
  3729. }
  3730. });
  3731. // hack to export the polyfill as global Intl if needed
  3732. if (typeof Intl === 'undefined') {
  3733. try {
  3734. window.Intl = Intl$1;
  3735. Intl$1.__applyLocaleSensitivePrototypes();
  3736. } catch (e) {
  3737. // can be read only property
  3738. }
  3739. }
  3740. return Intl$1;
  3741. }));
  3742. //# sourceMappingURL=Intl.js.map