messageformat.js 194 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.MessageFormat = factory());
  5. })(this, (function () { 'use strict';
  6. /******************************************************************************
  7. Copyright (c) Microsoft Corporation.
  8. Permission to use, copy, modify, and/or distribute this software for any
  9. purpose with or without fee is hereby granted.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  11. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  12. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  13. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  14. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  15. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. PERFORMANCE OF THIS SOFTWARE.
  17. ***************************************************************************** */
  18. /* global Reflect, Promise */
  19. var __assign = function () {
  20. __assign = Object.assign || function __assign(t) {
  21. for (var s, i = 1, n = arguments.length; i < n; i++) {
  22. s = arguments[i];
  23. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  24. }
  25. return t;
  26. };
  27. return __assign.apply(this, arguments);
  28. };
  29. function __values(o) {
  30. var s = typeof Symbol === "function" && Symbol.iterator,
  31. m = s && o[s],
  32. i = 0;
  33. if (m) return m.call(o);
  34. if (o && typeof o.length === "number") return {
  35. next: function () {
  36. if (o && i >= o.length) o = void 0;
  37. return {
  38. value: o && o[i++],
  39. done: !o
  40. };
  41. }
  42. };
  43. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  44. }
  45. function __read(o, n) {
  46. var m = typeof Symbol === "function" && o[Symbol.iterator];
  47. if (!m) return o;
  48. var i = m.call(o),
  49. r,
  50. ar = [],
  51. e;
  52. try {
  53. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  54. } catch (error) {
  55. e = {
  56. error: error
  57. };
  58. } finally {
  59. try {
  60. if (r && !r.done && (m = i["return"])) m.call(i);
  61. } finally {
  62. if (e) throw e.error;
  63. }
  64. }
  65. return ar;
  66. }
  67. function __spreadArray(to, from, pack) {
  68. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  69. if (ar || !(i in from)) {
  70. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  71. ar[i] = from[i];
  72. }
  73. }
  74. return to.concat(ar || Array.prototype.slice.call(from));
  75. }
  76. /**
  77. * Parent class for errors.
  78. *
  79. * @remarks
  80. * Errors with `type: "warning"` do not necessarily indicate that the parser
  81. * encountered an error. In addition to a human-friendly `message`, may also
  82. * includes the `token` at which the error was encountered.
  83. *
  84. * @public
  85. */
  86. class DateFormatError extends Error {
  87. /** @internal */
  88. constructor(msg, token, type) {
  89. super(msg);
  90. this.token = token;
  91. this.type = type || 'error';
  92. }
  93. }
  94. const alpha = width => width < 4 ? 'short' : width === 4 ? 'long' : 'narrow';
  95. const numeric = width => width % 2 === 0 ? '2-digit' : 'numeric';
  96. function yearOptions(token, onError) {
  97. switch (token.char) {
  98. case 'y':
  99. return {
  100. year: numeric(token.width)
  101. };
  102. case 'r':
  103. return {
  104. calendar: 'gregory',
  105. year: 'numeric'
  106. };
  107. case 'u':
  108. case 'U':
  109. case 'Y':
  110. default:
  111. onError(`${token.desc} is not supported; falling back to year:numeric`, DateFormatError.WARNING);
  112. return {
  113. year: 'numeric'
  114. };
  115. }
  116. }
  117. function monthStyle(token, onError) {
  118. switch (token.width) {
  119. case 1:
  120. return 'numeric';
  121. case 2:
  122. return '2-digit';
  123. case 3:
  124. return 'short';
  125. case 4:
  126. return 'long';
  127. case 5:
  128. return 'narrow';
  129. default:
  130. onError(`${token.desc} is not supported with width ${token.width}`);
  131. return undefined;
  132. }
  133. }
  134. function dayStyle(token, onError) {
  135. const {
  136. char,
  137. desc,
  138. width
  139. } = token;
  140. if (char === 'd') return numeric(width);else {
  141. onError(`${desc} is not supported`);
  142. return undefined;
  143. }
  144. }
  145. function weekdayStyle(token, onError) {
  146. const {
  147. char,
  148. desc,
  149. width
  150. } = token;
  151. if ((char === 'c' || char === 'e') && width < 3) {
  152. // ignoring stand-alone-ness
  153. const msg = `Numeric value is not supported for ${desc}; falling back to weekday:short`;
  154. onError(msg, DateFormatError.WARNING);
  155. }
  156. // merging narrow styles
  157. return alpha(width);
  158. }
  159. function hourOptions(token) {
  160. const hour = numeric(token.width);
  161. let hourCycle;
  162. switch (token.char) {
  163. case 'h':
  164. hourCycle = 'h12';
  165. break;
  166. case 'H':
  167. hourCycle = 'h23';
  168. break;
  169. case 'k':
  170. hourCycle = 'h24';
  171. break;
  172. case 'K':
  173. hourCycle = 'h11';
  174. break;
  175. }
  176. return hourCycle ? {
  177. hour,
  178. hourCycle
  179. } : {
  180. hour
  181. };
  182. }
  183. function timeZoneNameStyle(token, onError) {
  184. // so much fallback behaviour here
  185. const {
  186. char,
  187. desc,
  188. width
  189. } = token;
  190. switch (char) {
  191. case 'v':
  192. case 'z':
  193. return width === 4 ? 'long' : 'short';
  194. case 'V':
  195. if (width === 4) return 'long';
  196. onError(`${desc} is not supported with width ${width}`);
  197. return undefined;
  198. case 'X':
  199. onError(`${desc} is not supported`);
  200. return undefined;
  201. }
  202. return 'short';
  203. }
  204. function compileOptions(token, onError) {
  205. switch (token.field) {
  206. case 'era':
  207. return {
  208. era: alpha(token.width)
  209. };
  210. case 'year':
  211. return yearOptions(token, onError);
  212. case 'month':
  213. return {
  214. month: monthStyle(token, onError)
  215. };
  216. case 'day':
  217. return {
  218. day: dayStyle(token, onError)
  219. };
  220. case 'weekday':
  221. return {
  222. weekday: weekdayStyle(token, onError)
  223. };
  224. case 'period':
  225. return undefined;
  226. case 'hour':
  227. return hourOptions(token);
  228. case 'min':
  229. return {
  230. minute: numeric(token.width)
  231. };
  232. case 'sec':
  233. return {
  234. second: numeric(token.width)
  235. };
  236. case 'tz':
  237. return {
  238. timeZoneName: timeZoneNameStyle(token, onError)
  239. };
  240. case 'quarter':
  241. case 'week':
  242. case 'sec-frac':
  243. case 'ms':
  244. onError(`${token.desc} is not supported`);
  245. }
  246. return undefined;
  247. }
  248. function getDateFormatOptions(tokens) {
  249. let onError = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : error => {
  250. throw error;
  251. };
  252. const options = {};
  253. const fields = [];
  254. for (const token of tokens) {
  255. const {
  256. error,
  257. field,
  258. str
  259. } = token;
  260. if (error) {
  261. const dte = new DateFormatError(error.message, token);
  262. dte.stack = error.stack;
  263. onError(dte);
  264. }
  265. if (str) {
  266. const msg = `Ignoring string part: ${str}`;
  267. onError(new DateFormatError(msg, token, DateFormatError.WARNING));
  268. }
  269. if (field) {
  270. if (fields.indexOf(field) === -1) fields.push(field);else onError(new DateFormatError(`Duplicate ${field} token`, token));
  271. }
  272. const opt = compileOptions(token, (msg, isWarning) => onError(new DateFormatError(msg, token, isWarning)));
  273. if (opt) Object.assign(options, opt);
  274. }
  275. return options;
  276. }
  277. const fields = {
  278. G: {
  279. field: 'era',
  280. desc: 'Era'
  281. },
  282. y: {
  283. field: 'year',
  284. desc: 'Year'
  285. },
  286. Y: {
  287. field: 'year',
  288. desc: 'Year of "Week of Year"'
  289. },
  290. u: {
  291. field: 'year',
  292. desc: 'Extended year'
  293. },
  294. U: {
  295. field: 'year',
  296. desc: 'Cyclic year name'
  297. },
  298. r: {
  299. field: 'year',
  300. desc: 'Related Gregorian year'
  301. },
  302. Q: {
  303. field: 'quarter',
  304. desc: 'Quarter'
  305. },
  306. q: {
  307. field: 'quarter',
  308. desc: 'Stand-alone quarter'
  309. },
  310. M: {
  311. field: 'month',
  312. desc: 'Month in year'
  313. },
  314. L: {
  315. field: 'month',
  316. desc: 'Stand-alone month in year'
  317. },
  318. w: {
  319. field: 'week',
  320. desc: 'Week of year'
  321. },
  322. W: {
  323. field: 'week',
  324. desc: 'Week of month'
  325. },
  326. d: {
  327. field: 'day',
  328. desc: 'Day in month'
  329. },
  330. D: {
  331. field: 'day',
  332. desc: 'Day of year'
  333. },
  334. F: {
  335. field: 'day',
  336. desc: 'Day of week in month'
  337. },
  338. g: {
  339. field: 'day',
  340. desc: 'Modified julian day'
  341. },
  342. E: {
  343. field: 'weekday',
  344. desc: 'Day of week'
  345. },
  346. e: {
  347. field: 'weekday',
  348. desc: 'Local day of week'
  349. },
  350. c: {
  351. field: 'weekday',
  352. desc: 'Stand-alone local day of week'
  353. },
  354. a: {
  355. field: 'period',
  356. desc: 'AM/PM marker'
  357. },
  358. b: {
  359. field: 'period',
  360. desc: 'AM/PM/noon/midnight marker'
  361. },
  362. B: {
  363. field: 'period',
  364. desc: 'Flexible day period'
  365. },
  366. h: {
  367. field: 'hour',
  368. desc: 'Hour in AM/PM (1~12)'
  369. },
  370. H: {
  371. field: 'hour',
  372. desc: 'Hour in day (0~23)'
  373. },
  374. k: {
  375. field: 'hour',
  376. desc: 'Hour in day (1~24)'
  377. },
  378. K: {
  379. field: 'hour',
  380. desc: 'Hour in AM/PM (0~11)'
  381. },
  382. j: {
  383. field: 'hour',
  384. desc: 'Hour in preferred cycle'
  385. },
  386. J: {
  387. field: 'hour',
  388. desc: 'Hour in preferred cycle without marker'
  389. },
  390. C: {
  391. field: 'hour',
  392. desc: 'Hour in preferred cycle with flexible marker'
  393. },
  394. m: {
  395. field: 'min',
  396. desc: 'Minute in hour'
  397. },
  398. s: {
  399. field: 'sec',
  400. desc: 'Second in minute'
  401. },
  402. S: {
  403. field: 'sec-frac',
  404. desc: 'Fractional second'
  405. },
  406. A: {
  407. field: 'ms',
  408. desc: 'Milliseconds in day'
  409. },
  410. z: {
  411. field: 'tz',
  412. desc: 'Time Zone: specific non-location'
  413. },
  414. Z: {
  415. field: 'tz',
  416. desc: 'Time Zone'
  417. },
  418. O: {
  419. field: 'tz',
  420. desc: 'Time Zone: localized'
  421. },
  422. v: {
  423. field: 'tz',
  424. desc: 'Time Zone: generic non-location'
  425. },
  426. V: {
  427. field: 'tz',
  428. desc: 'Time Zone: ID'
  429. },
  430. X: {
  431. field: 'tz',
  432. desc: 'Time Zone: ISO8601 with Z'
  433. },
  434. x: {
  435. field: 'tz',
  436. desc: 'Time Zone: ISO8601'
  437. }
  438. };
  439. const isLetter = char => char >= 'A' && char <= 'Z' || char >= 'a' && char <= 'z';
  440. function readFieldToken(src, pos) {
  441. const char = src[pos];
  442. let width = 1;
  443. while (src[++pos] === char) ++width;
  444. const field = fields[char];
  445. if (!field) {
  446. const msg = `The letter ${char} is not a valid field identifier`;
  447. return {
  448. char,
  449. error: new Error(msg),
  450. width
  451. };
  452. }
  453. return {
  454. char,
  455. field: field.field,
  456. desc: field.desc,
  457. width
  458. };
  459. }
  460. function readQuotedToken(src, pos) {
  461. let str = src[++pos];
  462. let width = 2;
  463. if (str === "'") return {
  464. char: "'",
  465. str,
  466. width
  467. };
  468. while (true) {
  469. const next = src[++pos];
  470. ++width;
  471. if (next === undefined) {
  472. const msg = `Unterminated quoted literal in pattern: ${str || src}`;
  473. return {
  474. char: "'",
  475. error: new Error(msg),
  476. str,
  477. width
  478. };
  479. } else if (next === "'") {
  480. if (src[++pos] !== "'") return {
  481. char: "'",
  482. str,
  483. width
  484. };else ++width;
  485. }
  486. str += next;
  487. }
  488. }
  489. function readToken(src, pos) {
  490. const char = src[pos];
  491. if (!char) return null;
  492. if (isLetter(char)) return readFieldToken(src, pos);
  493. if (char === "'") return readQuotedToken(src, pos);
  494. let str = char;
  495. let width = 1;
  496. while (true) {
  497. const next = src[++pos];
  498. if (!next || isLetter(next) || next === "'") return {
  499. char,
  500. str,
  501. width
  502. };
  503. str += next;
  504. width += 1;
  505. }
  506. }
  507. /**
  508. * Parse an {@link http://userguide.icu-project.org/formatparse/datetime | ICU
  509. * DateFormat skeleton} string into a {@link DateToken} array.
  510. *
  511. * @remarks
  512. * Errors will not be thrown, but if encountered are included as the relevant
  513. * token's `error` value.
  514. *
  515. * @public
  516. * @param src - The skeleton string
  517. *
  518. * @example
  519. * ```js
  520. * import { parseDateTokens } from '@messageformat/date-skeleton'
  521. *
  522. * parseDateTokens('GrMMMdd', console.error)
  523. * // [
  524. * // { char: 'G', field: 'era', desc: 'Era', width: 1 },
  525. * // { char: 'r', field: 'year', desc: 'Related Gregorian year', width: 1 },
  526. * // { char: 'M', field: 'month', desc: 'Month in year', width: 3 },
  527. * // { char: 'd', field: 'day', desc: 'Day in month', width: 2 }
  528. * // ]
  529. * ```
  530. */
  531. function parseDateTokens(src) {
  532. const tokens = [];
  533. let pos = 0;
  534. while (true) {
  535. const token = readToken(src, pos);
  536. if (!token) return tokens;
  537. tokens.push(token);
  538. pos += token.width;
  539. }
  540. }
  541. /**
  542. * Returns a date formatter function for the given locales and date skeleton
  543. *
  544. * @remarks
  545. * Uses `Intl.DateTimeFormat` internally.
  546. *
  547. * @public
  548. * @param locales - One or more valid BCP 47 language tags, e.g. `fr` or `en-CA`
  549. * @param tokens - An ICU DateFormat skeleton string, or an array or parsed
  550. * `DateToken` tokens
  551. * @param onError - If defined, will be called separately for each encountered
  552. * parsing error and unsupported feature.
  553. * @example
  554. * ```js
  555. * import { getDateFormatter } from '@messageformat/date-skeleton'
  556. *
  557. * // 2006 Jan 2, 15:04:05.789 in local time
  558. * const date = new Date(2006, 0, 2, 15, 4, 5, 789)
  559. *
  560. * let fmt = getDateFormatter('en-CA', 'GrMMMdd', console.error)
  561. * fmt(date) // 'Jan. 02, 2006 AD'
  562. *
  563. * fmt = getDateFormatter('en-CA', 'hamszzzz', console.error)
  564. * fmt(date) // '3:04:05 p.m. Newfoundland Daylight Time'
  565. * ```
  566. */
  567. function getDateFormatter(locales, tokens, onError) {
  568. if (typeof tokens === 'string') tokens = parseDateTokens(tokens);
  569. const opt = getDateFormatOptions(tokens, onError);
  570. const dtf = new Intl.DateTimeFormat(locales, opt);
  571. return date => dtf.format(date);
  572. }
  573. /**
  574. * Returns a string of JavaScript source that evaluates to a date formatter
  575. * function with the same `(date: Date | number) => string` signature as the
  576. * function returned by {@link getDateFormatter}.
  577. *
  578. * @remarks
  579. * The returned function will memoize an `Intl.DateTimeFormat` instance.
  580. *
  581. * @public
  582. * @param locales - One or more valid BCP 47 language tags, e.g. `fr` or `en-CA`
  583. * @param tokens - An ICU DateFormat skeleton string, or an array or parsed
  584. * `DateToken` tokens
  585. * @param onError - If defined, will be called separately for each encountered
  586. * parsing error and unsupported feature.
  587. * @example
  588. * ```js
  589. * import { getDateFormatterSource } from '@messageformat/date-skeleton'
  590. *
  591. * getDateFormatterSource('en-CA', 'GrMMMdd', console.error)
  592. * // '(function() {\n' +
  593. * // ' var opt = {"era":"short","calendar":"gregory","year":"numeric",' +
  594. * // '"month":"short","day":"2-digit"};\n' +
  595. * // ' var dtf = new Intl.DateTimeFormat("en-CA", opt);\n' +
  596. * // ' return function(value) { return dtf.format(value); }\n' +
  597. * // '})()'
  598. *
  599. * const src = getDateFormatterSource('en-CA', 'hamszzzz', console.error)
  600. * // '(function() {\n' +
  601. * // ' var opt = {"hour":"numeric","hourCycle":"h12","minute":"numeric",' +
  602. * // '"second":"numeric","timeZoneName":"long"};\n' +
  603. * // ' var dtf = new Intl.DateTimeFormat("en-CA", opt);\n' +
  604. * // ' return function(value) { return dtf.format(value); }\n' +
  605. * // '})()'
  606. *
  607. * const fmt = new Function(`return ${src}`)()
  608. * const date = new Date(2006, 0, 2, 15, 4, 5, 789)
  609. * fmt(date) // '3:04:05 p.m. Newfoundland Daylight Time'
  610. * ```
  611. */
  612. function getDateFormatterSource(locales, tokens, onError) {
  613. if (typeof tokens === 'string') tokens = parseDateTokens(tokens);
  614. const opt = getDateFormatOptions(tokens, onError);
  615. const lines = [`(function() {`, `var opt = ${JSON.stringify(opt)};`, `var dtf = new Intl.DateTimeFormat(${JSON.stringify(locales)}, opt);`, `return function(value) { return dtf.format(value); }`];
  616. return lines.join('\n ') + '\n})()';
  617. }
  618. /**
  619. * Base class for errors. In addition to a `code` and a human-friendly
  620. * `message`, may also includes the token `stem` as well as other fields.
  621. *
  622. * @public
  623. */
  624. class NumberFormatError extends Error {
  625. /** @internal */
  626. constructor(code, msg) {
  627. super(msg);
  628. this.code = code;
  629. }
  630. }
  631. /** @internal */
  632. class BadOptionError extends NumberFormatError {
  633. constructor(stem, opt) {
  634. super('BAD_OPTION', `Unknown ${stem} option: ${opt}`);
  635. this.stem = stem;
  636. this.option = opt;
  637. }
  638. }
  639. /** @internal */
  640. class BadStemError extends NumberFormatError {
  641. constructor(stem) {
  642. super('BAD_STEM', `Unknown stem: ${stem}`);
  643. this.stem = stem;
  644. }
  645. }
  646. /** @internal */
  647. class MaskedValueError extends NumberFormatError {
  648. constructor(type, prev) {
  649. super('MASKED_VALUE', `Value for ${type} is set multiple times`);
  650. this.type = type;
  651. this.prev = prev;
  652. }
  653. }
  654. /** @internal */
  655. class MissingOptionError extends NumberFormatError {
  656. constructor(stem) {
  657. super('MISSING_OPTION', `Required option missing for ${stem}`);
  658. this.stem = stem;
  659. }
  660. }
  661. /** @internal */
  662. class PatternError extends NumberFormatError {
  663. constructor(char, msg) {
  664. super('BAD_PATTERN', msg);
  665. this.char = char;
  666. }
  667. }
  668. /** @internal */
  669. class TooManyOptionsError extends NumberFormatError {
  670. constructor(stem, options, maxOpt) {
  671. const maxOptStr = maxOpt > 1 ? `${maxOpt} options` : 'one option';
  672. super('TOO_MANY_OPTIONS', `Token ${stem} only supports ${maxOptStr} (got ${options.length})`);
  673. this.stem = stem;
  674. this.options = options;
  675. }
  676. }
  677. /** @internal */
  678. class UnsupportedError extends NumberFormatError {
  679. constructor(stem, source) {
  680. super('UNSUPPORTED', `The stem ${stem} is not supported`);
  681. this.stem = stem;
  682. if (source) {
  683. this.message += ` with value ${source}`;
  684. this.source = source;
  685. }
  686. }
  687. }
  688. /**
  689. * Add
  690. * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation | numbering-system tags}
  691. * to locale identifiers
  692. *
  693. * @internal
  694. */
  695. function getNumberFormatLocales(locales, _ref) {
  696. let {
  697. numberingSystem
  698. } = _ref;
  699. if (!Array.isArray(locales)) locales = [locales];
  700. return numberingSystem ? locales.map(lc => {
  701. const ext = lc.indexOf('-u-') === -1 ? 'u-nu' : 'nu';
  702. return `${lc}-${ext}-${numberingSystem}`;
  703. }).concat(locales) : locales;
  704. }
  705. // from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
  706. function round(x, precision) {
  707. const y = +x + precision / 2;
  708. return y - y % +precision;
  709. }
  710. function getNumberFormatMultiplier(_ref) {
  711. let {
  712. scale,
  713. unit
  714. } = _ref;
  715. let mult = typeof scale === 'number' && scale >= 0 ? scale : 1;
  716. if (unit && unit.style === 'percent') mult *= 0.01;
  717. return mult;
  718. }
  719. /**
  720. * Determine a modifier for the input value to account for any `scale`,
  721. * `percent`, and `precision-increment` tokens in the skeleton.
  722. *
  723. * @internal
  724. * @remarks
  725. * With ICU NumberFormatter, the `percent` skeleton would style `25` as "25%".
  726. * To achieve the same with `Intl.NumberFormat`, the input value must be `0.25`.
  727. */
  728. function getNumberFormatModifier(skeleton) {
  729. const mult = getNumberFormatMultiplier(skeleton);
  730. const {
  731. precision
  732. } = skeleton;
  733. if (precision && precision.style === 'precision-increment') {
  734. return n => round(n, precision.increment) * mult;
  735. } else {
  736. return n => n * mult;
  737. }
  738. }
  739. /**
  740. * Returns a string of JavaScript source that evaluates to a modifier for the
  741. * input value to account for any `scale`, `percent`, and `precision-increment`
  742. * tokens in the skeleton.
  743. *
  744. * @internal
  745. * @remarks
  746. * With ICU NumberFormatter, the `percent` skeleton would style `25` as "25%".
  747. * To achieve the same with `Intl.NumberFormat`, the input value must be `0.25`.
  748. */
  749. function getNumberFormatModifierSource(skeleton) {
  750. const mult = getNumberFormatMultiplier(skeleton);
  751. const {
  752. precision
  753. } = skeleton;
  754. if (precision && precision.style === 'precision-increment') {
  755. // see round() above for source
  756. const setX = `+n + ${precision.increment / 2}`;
  757. let res = `x - (x % +${precision.increment})`;
  758. if (mult !== 1) res = `(${res}) * ${mult}`;
  759. return `function(n) { var x = ${setX}; return ${res}; }`;
  760. }
  761. return mult !== 1 ? `function(n) { return n * ${mult}; }` : null;
  762. }
  763. /**
  764. * Given an input ICU NumberFormatter skeleton, does its best to construct a
  765. * corresponding `Intl.NumberFormat` options structure.
  766. *
  767. * @remarks
  768. * Some features depend on `Intl.NumberFormat` features defined in ES2020.
  769. *
  770. * @internal
  771. * @param onUnsupported - If defined, called when encountering unsupported (but
  772. * valid) tokens, such as `decimal-always` or `permille`. The error `source`
  773. * may specify the source of an unsupported option.
  774. *
  775. * @example
  776. * ```js
  777. * import {
  778. * getNumberFormatOptions,
  779. * parseNumberSkeleton
  780. * } from '@messageformat/number-skeleton'
  781. *
  782. * const src = 'currency/CAD unit-width-narrow'
  783. * const skeleton = parseNumberSkeleton(src, console.error)
  784. * // {
  785. * // unit: { style: 'currency', currency: 'CAD' },
  786. * // unitWidth: 'unit-width-narrow'
  787. * // }
  788. *
  789. * getNumberFormatOptions(skeleton, console.error)
  790. * // {
  791. * // style: 'currency',
  792. * // currency: 'CAD',
  793. * // currencyDisplay: 'narrowSymbol',
  794. * // unitDisplay: 'narrow'
  795. * // }
  796. *
  797. * const sk2 = parseNumberSkeleton('group-min2')
  798. * // { group: 'group-min2' }
  799. *
  800. * getNumberFormatOptions(sk2, console.error)
  801. * // Error: The stem group-min2 is not supported
  802. * // at UnsupportedError.NumberFormatError ... {
  803. * // code: 'UNSUPPORTED',
  804. * // stem: 'group-min2'
  805. * // }
  806. * // {}
  807. * ```
  808. */
  809. function getNumberFormatOptions(skeleton, onUnsupported) {
  810. const {
  811. decimal,
  812. group,
  813. integerWidth,
  814. notation,
  815. precision,
  816. roundingMode,
  817. sign,
  818. unit,
  819. unitPer,
  820. unitWidth
  821. } = skeleton;
  822. const fail = (stem, source) => {
  823. if (onUnsupported) onUnsupported(new UnsupportedError(stem, source));
  824. };
  825. const opt = {};
  826. if (unit) {
  827. switch (unit.style) {
  828. case 'base-unit':
  829. opt.style = 'decimal';
  830. break;
  831. case 'currency':
  832. opt.style = 'currency';
  833. opt.currency = unit.currency;
  834. break;
  835. case 'measure-unit':
  836. opt.style = 'unit';
  837. opt.unit = unit.unit.replace(/.*-/, '');
  838. if (unitPer) opt.unit += '-per-' + unitPer.replace(/.*-/, '');
  839. break;
  840. case 'percent':
  841. opt.style = 'percent';
  842. break;
  843. case 'permille':
  844. fail('permille');
  845. break;
  846. }
  847. }
  848. switch (unitWidth) {
  849. case 'unit-width-full-name':
  850. opt.currencyDisplay = 'name';
  851. opt.unitDisplay = 'long';
  852. break;
  853. case 'unit-width-hidden':
  854. fail(unitWidth);
  855. break;
  856. case 'unit-width-iso-code':
  857. opt.currencyDisplay = 'code';
  858. break;
  859. case 'unit-width-narrow':
  860. opt.currencyDisplay = 'narrowSymbol';
  861. opt.unitDisplay = 'narrow';
  862. break;
  863. case 'unit-width-short':
  864. opt.currencyDisplay = 'symbol';
  865. opt.unitDisplay = 'short';
  866. break;
  867. }
  868. switch (group) {
  869. case 'group-off':
  870. opt.useGrouping = false;
  871. break;
  872. case 'group-auto':
  873. opt.useGrouping = true;
  874. break;
  875. case 'group-min2':
  876. case 'group-on-aligned':
  877. case 'group-thousands':
  878. fail(group);
  879. opt.useGrouping = true;
  880. break;
  881. }
  882. if (precision) {
  883. switch (precision.style) {
  884. case 'precision-fraction':
  885. {
  886. const {
  887. minFraction: minF,
  888. maxFraction: maxF,
  889. minSignificant: minS,
  890. maxSignificant: maxS,
  891. source
  892. } = precision;
  893. if (typeof minF === 'number') {
  894. opt.minimumFractionDigits = minF;
  895. if (typeof minS === 'number') fail('precision-fraction', source);
  896. }
  897. if (typeof maxF === 'number') opt.maximumFractionDigits = maxF;
  898. if (typeof minS === 'number') opt.minimumSignificantDigits = minS;
  899. if (typeof maxS === 'number') opt.maximumSignificantDigits = maxS;
  900. break;
  901. }
  902. case 'precision-integer':
  903. opt.maximumFractionDigits = 0;
  904. break;
  905. case 'precision-unlimited':
  906. opt.maximumFractionDigits = 20;
  907. break;
  908. case 'precision-increment':
  909. break;
  910. case 'precision-currency-standard':
  911. opt.trailingZeroDisplay = precision.trailingZero;
  912. break;
  913. case 'precision-currency-cash':
  914. fail(precision.style);
  915. break;
  916. }
  917. }
  918. if (notation) {
  919. switch (notation.style) {
  920. case 'compact-short':
  921. opt.notation = 'compact';
  922. opt.compactDisplay = 'short';
  923. break;
  924. case 'compact-long':
  925. opt.notation = 'compact';
  926. opt.compactDisplay = 'long';
  927. break;
  928. case 'notation-simple':
  929. opt.notation = 'standard';
  930. break;
  931. case 'scientific':
  932. case 'engineering':
  933. {
  934. const {
  935. expDigits,
  936. expSign,
  937. source,
  938. style
  939. } = notation;
  940. opt.notation = style;
  941. if (expDigits && expDigits > 1 || expSign && expSign !== 'sign-auto') fail(style, source);
  942. break;
  943. }
  944. }
  945. }
  946. if (integerWidth) {
  947. const {
  948. min,
  949. max,
  950. source
  951. } = integerWidth;
  952. if (min > 0) opt.minimumIntegerDigits = min;
  953. if (Number(max) > 0) {
  954. const hasExp = opt.notation === 'engineering' || opt.notation === 'scientific';
  955. if (max === 3 && hasExp) opt.notation = 'engineering';else fail('integer-width', source);
  956. }
  957. }
  958. switch (sign) {
  959. case 'sign-auto':
  960. opt.signDisplay = 'auto';
  961. break;
  962. case 'sign-always':
  963. opt.signDisplay = 'always';
  964. break;
  965. case 'sign-except-zero':
  966. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  967. // @ts-ignore https://github.com/microsoft/TypeScript/issues/46712
  968. opt.signDisplay = 'exceptZero';
  969. break;
  970. case 'sign-never':
  971. opt.signDisplay = 'never';
  972. break;
  973. case 'sign-accounting':
  974. opt.currencySign = 'accounting';
  975. break;
  976. case 'sign-accounting-always':
  977. opt.currencySign = 'accounting';
  978. opt.signDisplay = 'always';
  979. break;
  980. case 'sign-accounting-except-zero':
  981. opt.currencySign = 'accounting';
  982. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  983. // @ts-ignore https://github.com/microsoft/TypeScript/issues/46712
  984. opt.signDisplay = 'exceptZero';
  985. break;
  986. }
  987. if (decimal === 'decimal-always') fail(decimal);
  988. if (roundingMode) fail(roundingMode);
  989. return opt;
  990. }
  991. function parseAffixToken(src, pos, onError) {
  992. const char = src[pos];
  993. switch (char) {
  994. case '%':
  995. return {
  996. char: '%',
  997. style: 'percent',
  998. width: 1
  999. };
  1000. case '‰':
  1001. return {
  1002. char: '%',
  1003. style: 'permille',
  1004. width: 1
  1005. };
  1006. case '¤':
  1007. {
  1008. let width = 1;
  1009. while (src[++pos] === '¤') ++width;
  1010. switch (width) {
  1011. case 1:
  1012. return {
  1013. char,
  1014. currency: 'default',
  1015. width
  1016. };
  1017. case 2:
  1018. return {
  1019. char,
  1020. currency: 'iso-code',
  1021. width
  1022. };
  1023. case 3:
  1024. return {
  1025. char,
  1026. currency: 'full-name',
  1027. width
  1028. };
  1029. case 5:
  1030. return {
  1031. char,
  1032. currency: 'narrow',
  1033. width
  1034. };
  1035. default:
  1036. {
  1037. const msg = `Invalid number (${width}) of ¤ chars in pattern`;
  1038. onError(new PatternError('¤', msg));
  1039. return null;
  1040. }
  1041. }
  1042. }
  1043. case '*':
  1044. {
  1045. const pad = src[pos + 1];
  1046. if (pad) return {
  1047. char,
  1048. pad,
  1049. width: 2
  1050. };
  1051. break;
  1052. }
  1053. case '+':
  1054. case '-':
  1055. return {
  1056. char,
  1057. width: 1
  1058. };
  1059. case "'":
  1060. {
  1061. let str = src[++pos];
  1062. let width = 2;
  1063. if (str === "'") return {
  1064. char,
  1065. str,
  1066. width
  1067. };
  1068. while (true) {
  1069. const next = src[++pos];
  1070. ++width;
  1071. if (next === undefined) {
  1072. const msg = `Unterminated quoted literal in pattern: ${str}`;
  1073. onError(new PatternError("'", msg));
  1074. return {
  1075. char,
  1076. str,
  1077. width
  1078. };
  1079. } else if (next === "'") {
  1080. if (src[++pos] !== "'") return {
  1081. char,
  1082. str,
  1083. width
  1084. };else ++width;
  1085. }
  1086. str += next;
  1087. }
  1088. }
  1089. }
  1090. return null;
  1091. }
  1092. const isDigit = char => char >= '0' && char <= '9';
  1093. function parseNumberToken(src, pos) {
  1094. const char = src[pos];
  1095. if (isDigit(char)) {
  1096. let digits = char;
  1097. while (true) {
  1098. const next = src[++pos];
  1099. if (isDigit(next)) digits += next;else return {
  1100. char: '0',
  1101. digits,
  1102. width: digits.length
  1103. };
  1104. }
  1105. }
  1106. switch (char) {
  1107. case '#':
  1108. {
  1109. let width = 1;
  1110. while (src[++pos] === '#') ++width;
  1111. return {
  1112. char,
  1113. width
  1114. };
  1115. }
  1116. case '@':
  1117. {
  1118. let min = 1;
  1119. while (src[++pos] === '@') ++min;
  1120. let width = min;
  1121. pos -= 1;
  1122. while (src[++pos] === '#') ++width;
  1123. return {
  1124. char,
  1125. min,
  1126. width
  1127. };
  1128. }
  1129. case 'E':
  1130. {
  1131. const plus = src[pos + 1] === '+';
  1132. if (plus) ++pos;
  1133. let expDigits = 0;
  1134. while (src[++pos] === '0') ++expDigits;
  1135. const width = (plus ? 2 : 1) + expDigits;
  1136. if (expDigits) return {
  1137. char,
  1138. expDigits,
  1139. plus,
  1140. width
  1141. };else break;
  1142. }
  1143. case '.':
  1144. case ',':
  1145. return {
  1146. char,
  1147. width: 1
  1148. };
  1149. }
  1150. return null;
  1151. }
  1152. function parseSubpattern(src, pos, onError) {
  1153. let State;
  1154. (function (State) {
  1155. State[State["Prefix"] = 0] = "Prefix";
  1156. State[State["Number"] = 1] = "Number";
  1157. State[State["Suffix"] = 2] = "Suffix";
  1158. })(State || (State = {}));
  1159. const prefix = [];
  1160. const number = [];
  1161. const suffix = [];
  1162. let state = State.Prefix;
  1163. let str = '';
  1164. while (pos < src.length) {
  1165. const char = src[pos];
  1166. if (char === ';') {
  1167. pos += 1;
  1168. break;
  1169. }
  1170. switch (state) {
  1171. case State.Prefix:
  1172. {
  1173. const token = parseAffixToken(src, pos, onError);
  1174. if (token) {
  1175. if (str) {
  1176. prefix.push({
  1177. char: "'",
  1178. str,
  1179. width: str.length
  1180. });
  1181. str = '';
  1182. }
  1183. prefix.push(token);
  1184. pos += token.width;
  1185. } else {
  1186. const token = parseNumberToken(src, pos);
  1187. if (token) {
  1188. if (str) {
  1189. prefix.push({
  1190. char: "'",
  1191. str,
  1192. width: str.length
  1193. });
  1194. str = '';
  1195. }
  1196. state = State.Number;
  1197. number.push(token);
  1198. pos += token.width;
  1199. } else {
  1200. str += char;
  1201. pos += 1;
  1202. }
  1203. }
  1204. break;
  1205. }
  1206. case State.Number:
  1207. {
  1208. const token = parseNumberToken(src, pos);
  1209. if (token) {
  1210. number.push(token);
  1211. pos += token.width;
  1212. } else {
  1213. state = State.Suffix;
  1214. }
  1215. break;
  1216. }
  1217. case State.Suffix:
  1218. {
  1219. const token = parseAffixToken(src, pos, onError);
  1220. if (token) {
  1221. if (str) {
  1222. suffix.push({
  1223. char: "'",
  1224. str,
  1225. width: str.length
  1226. });
  1227. str = '';
  1228. }
  1229. suffix.push(token);
  1230. pos += token.width;
  1231. } else {
  1232. str += char;
  1233. pos += 1;
  1234. }
  1235. break;
  1236. }
  1237. }
  1238. }
  1239. if (str) suffix.push({
  1240. char: "'",
  1241. str,
  1242. width: str.length
  1243. });
  1244. return {
  1245. pattern: {
  1246. prefix,
  1247. number,
  1248. suffix
  1249. },
  1250. pos
  1251. };
  1252. }
  1253. function parseTokens(src, onError) {
  1254. const {
  1255. pattern,
  1256. pos
  1257. } = parseSubpattern(src, 0, onError);
  1258. if (pos < src.length) {
  1259. const {
  1260. pattern: negative
  1261. } = parseSubpattern(src, pos, onError);
  1262. return {
  1263. tokens: pattern,
  1264. negative
  1265. };
  1266. }
  1267. return {
  1268. tokens: pattern
  1269. };
  1270. }
  1271. function parseNumberAsSkeleton(tokens, onError) {
  1272. const res = {};
  1273. let hasGroups = false;
  1274. let hasExponent = false;
  1275. let intOptional = 0;
  1276. let intDigits = '';
  1277. let decimalPos = -1;
  1278. let fracDigits = '';
  1279. let fracOptional = 0;
  1280. for (let pos = 0; pos < tokens.length; ++pos) {
  1281. const token = tokens[pos];
  1282. switch (token.char) {
  1283. case '#':
  1284. {
  1285. if (decimalPos === -1) {
  1286. if (intDigits) {
  1287. const msg = 'Pattern has # after integer digits';
  1288. onError(new PatternError('#', msg));
  1289. }
  1290. intOptional += token.width;
  1291. } else {
  1292. fracOptional += token.width;
  1293. }
  1294. break;
  1295. }
  1296. case '0':
  1297. {
  1298. if (decimalPos === -1) {
  1299. intDigits += token.digits;
  1300. } else {
  1301. if (fracOptional) {
  1302. const msg = 'Pattern has digits after # in fraction';
  1303. onError(new PatternError('0', msg));
  1304. }
  1305. fracDigits += token.digits;
  1306. }
  1307. break;
  1308. }
  1309. case '@':
  1310. {
  1311. if (res.precision) onError(new MaskedValueError('precision', res.precision));
  1312. res.precision = {
  1313. style: 'precision-fraction',
  1314. minSignificant: token.min,
  1315. maxSignificant: token.width
  1316. };
  1317. break;
  1318. }
  1319. case ',':
  1320. hasGroups = true;
  1321. break;
  1322. case '.':
  1323. if (decimalPos === 1) {
  1324. const msg = 'Pattern has more than one decimal separator';
  1325. onError(new PatternError('.', msg));
  1326. }
  1327. decimalPos = pos;
  1328. break;
  1329. case 'E':
  1330. {
  1331. if (hasExponent) onError(new MaskedValueError('exponent', res.notation));
  1332. if (hasGroups) {
  1333. const msg = 'Exponential patterns may not contain grouping separators';
  1334. onError(new PatternError('E', msg));
  1335. }
  1336. res.notation = {
  1337. style: 'scientific'
  1338. };
  1339. if (token.expDigits > 1) res.notation.expDigits = token.expDigits;
  1340. if (token.plus) res.notation.expSign = 'sign-always';
  1341. hasExponent = true;
  1342. }
  1343. }
  1344. }
  1345. // imprecise mapping due to paradigm differences
  1346. if (hasGroups) res.group = 'group-auto';else if (intOptional + intDigits.length > 3) res.group = 'group-off';
  1347. const increment = Number(`${intDigits || '0'}.${fracDigits}`);
  1348. if (increment) res.precision = {
  1349. style: 'precision-increment',
  1350. increment
  1351. };
  1352. if (!hasExponent) {
  1353. if (intDigits.length > 1) res.integerWidth = {
  1354. min: intDigits.length
  1355. };
  1356. if (!res.precision && (fracDigits.length || fracOptional)) {
  1357. res.precision = {
  1358. style: 'precision-fraction',
  1359. minFraction: fracDigits.length,
  1360. maxFraction: fracDigits.length + fracOptional
  1361. };
  1362. }
  1363. } else {
  1364. if (!res.precision || increment) {
  1365. res.integerWidth = intOptional ? {
  1366. min: 1,
  1367. max: intOptional + intDigits.length
  1368. } : {
  1369. min: Math.max(1, intDigits.length)
  1370. };
  1371. }
  1372. if (res.precision) {
  1373. if (!increment) res.integerWidth = {
  1374. min: 1,
  1375. max: 1
  1376. };
  1377. } else {
  1378. const dc = intDigits.length + fracDigits.length;
  1379. if (decimalPos === -1) {
  1380. if (dc > 0) res.precision = {
  1381. style: 'precision-fraction',
  1382. maxSignificant: dc
  1383. };
  1384. } else {
  1385. res.precision = {
  1386. style: 'precision-fraction',
  1387. maxSignificant: Math.max(1, dc) + fracOptional
  1388. };
  1389. if (dc > 1) res.precision.minSignificant = dc;
  1390. }
  1391. }
  1392. }
  1393. return res;
  1394. }
  1395. function handleAffix(affixTokens, res, currency, onError, isPrefix) {
  1396. let inFmt = false;
  1397. let str = '';
  1398. for (const token of affixTokens) {
  1399. switch (token.char) {
  1400. case '%':
  1401. res.unit = {
  1402. style: token.style
  1403. };
  1404. if (isPrefix) inFmt = true;else str = '';
  1405. break;
  1406. case '¤':
  1407. if (!currency) {
  1408. const msg = `The ¤ pattern requires a currency`;
  1409. onError(new PatternError('¤', msg));
  1410. break;
  1411. }
  1412. res.unit = {
  1413. style: 'currency',
  1414. currency
  1415. };
  1416. switch (token.currency) {
  1417. case 'iso-code':
  1418. res.unitWidth = 'unit-width-iso-code';
  1419. break;
  1420. case 'full-name':
  1421. res.unitWidth = 'unit-width-full-name';
  1422. break;
  1423. case 'narrow':
  1424. res.unitWidth = 'unit-width-narrow';
  1425. break;
  1426. }
  1427. if (isPrefix) inFmt = true;else str = '';
  1428. break;
  1429. case '*':
  1430. // TODO
  1431. break;
  1432. case '+':
  1433. if (!inFmt) str += '+';
  1434. break;
  1435. case "'":
  1436. if (!inFmt) str += token.str;
  1437. break;
  1438. }
  1439. }
  1440. return str;
  1441. }
  1442. function getNegativeAffix(affixTokens, isPrefix) {
  1443. let inFmt = false;
  1444. let str = '';
  1445. for (const token of affixTokens) {
  1446. switch (token.char) {
  1447. case '%':
  1448. case '¤':
  1449. if (isPrefix) inFmt = true;else str = '';
  1450. break;
  1451. case '-':
  1452. if (!inFmt) str += '-';
  1453. break;
  1454. case "'":
  1455. if (!inFmt) str += token.str;
  1456. break;
  1457. }
  1458. }
  1459. return str;
  1460. }
  1461. /**
  1462. * Parse an {@link
  1463. * http://unicode.org/reports/tr35/tr35-numbers.html#Number_Format_Patterns |
  1464. * ICU NumberFormatter pattern} string into a {@link Skeleton} structure.
  1465. *
  1466. * @public
  1467. * @param src - The pattern string
  1468. * @param currency - If the pattern includes ¤ tokens, their skeleton
  1469. * representation requires a three-letter currency code.
  1470. * @param onError - Called when the parser encounters a syntax error. The
  1471. * function will still return a {@link Skeleton}, but it will be incomplete
  1472. * and/or inaccurate. If not defined, the error will be thrown instead.
  1473. *
  1474. * @remarks
  1475. * Unlike the skeleton parser, the pattern parser is not able to return partial
  1476. * results on error, and will instead throw. Output padding is not supported.
  1477. *
  1478. * @example
  1479. * ```js
  1480. * import { parseNumberPattern } from '@messageformat/number-skeleton'
  1481. *
  1482. * parseNumberPattern('#,##0.00 ¤', 'EUR', console.error)
  1483. * // {
  1484. * // group: 'group-auto',
  1485. * // precision: {
  1486. * // style: 'precision-fraction',
  1487. * // minFraction: 2,
  1488. * // maxFraction: 2
  1489. * // },
  1490. * // unit: { style: 'currency', currency: 'EUR' }
  1491. * // }
  1492. * ```
  1493. */
  1494. function parseNumberPattern(src, currency) {
  1495. let onError = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : error => {
  1496. throw error;
  1497. };
  1498. const {
  1499. tokens,
  1500. negative
  1501. } = parseTokens(src, onError);
  1502. const res = parseNumberAsSkeleton(tokens.number, onError);
  1503. const prefix = handleAffix(tokens.prefix, res, currency, onError, true);
  1504. const suffix = handleAffix(tokens.suffix, res, currency, onError, false);
  1505. if (negative) {
  1506. const negPrefix = getNegativeAffix(negative.prefix, true);
  1507. const negSuffix = getNegativeAffix(negative.suffix, false);
  1508. res.affix = {
  1509. pos: [prefix, suffix],
  1510. neg: [negPrefix, negSuffix]
  1511. };
  1512. res.sign = 'sign-never';
  1513. } else if (prefix || suffix) {
  1514. res.affix = {
  1515. pos: [prefix, suffix]
  1516. };
  1517. }
  1518. return res;
  1519. }
  1520. /** @internal */
  1521. function isNumberingSystem(ns) {
  1522. const systems = ['arab', 'arabext', 'bali', 'beng', 'deva', 'fullwide', 'gujr', 'guru', 'hanidec', 'khmr', 'knda', 'laoo', 'latn', 'limb', 'mlym', 'mong', 'mymr', 'orya', 'tamldec', 'telu', 'thai', 'tibt'];
  1523. return systems.indexOf(ns) !== -1;
  1524. }
  1525. // FIXME: subtype is not checked
  1526. /** @internal */
  1527. function isUnit(unit) {
  1528. const types = ['acceleration', 'angle', 'area', 'concentr', 'consumption', 'digital', 'duration', 'electric', 'energy', 'force', 'frequency', 'graphics', 'length', 'light', 'mass', 'power', 'pressure', 'speed', 'temperature', 'torque', 'volume'];
  1529. const [type] = unit.split('-', 1);
  1530. return types.indexOf(type) !== -1;
  1531. }
  1532. const maxOptions = {
  1533. 'compact-short': 0,
  1534. 'compact-long': 0,
  1535. 'notation-simple': 0,
  1536. scientific: 2,
  1537. engineering: 2,
  1538. percent: 0,
  1539. permille: 0,
  1540. 'base-unit': 0,
  1541. currency: 1,
  1542. 'measure-unit': 1,
  1543. 'per-measure-unit': 1,
  1544. 'unit-width-narrow': 0,
  1545. 'unit-width-short': 0,
  1546. 'unit-width-full-name': 0,
  1547. 'unit-width-iso-code': 0,
  1548. 'unit-width-hidden': 0,
  1549. 'precision-integer': 0,
  1550. 'precision-unlimited': 0,
  1551. 'precision-currency-standard': 1,
  1552. 'precision-currency-cash': 0,
  1553. 'precision-increment': 1,
  1554. 'rounding-mode-ceiling': 0,
  1555. 'rounding-mode-floor': 0,
  1556. 'rounding-mode-down': 0,
  1557. 'rounding-mode-up': 0,
  1558. 'rounding-mode-half-even': 0,
  1559. 'rounding-mode-half-down': 0,
  1560. 'rounding-mode-half-up': 0,
  1561. 'rounding-mode-unnecessary': 0,
  1562. 'integer-width': 1,
  1563. scale: 1,
  1564. 'group-off': 0,
  1565. 'group-min2': 0,
  1566. 'group-auto': 0,
  1567. 'group-on-aligned': 0,
  1568. 'group-thousands': 0,
  1569. latin: 0,
  1570. 'numbering-system': 1,
  1571. 'sign-auto': 0,
  1572. 'sign-always': 0,
  1573. 'sign-never': 0,
  1574. 'sign-accounting': 0,
  1575. 'sign-accounting-always': 0,
  1576. 'sign-except-zero': 0,
  1577. 'sign-accounting-except-zero': 0,
  1578. 'decimal-auto': 0,
  1579. 'decimal-always': 0
  1580. };
  1581. const minOptions = {
  1582. currency: 1,
  1583. 'integer-width': 1,
  1584. 'measure-unit': 1,
  1585. 'numbering-system': 1,
  1586. 'per-measure-unit': 1,
  1587. 'precision-increment': 1,
  1588. scale: 1
  1589. };
  1590. function hasMaxOption(stem) {
  1591. return stem in maxOptions;
  1592. }
  1593. function hasMinOption(stem) {
  1594. return stem in minOptions;
  1595. }
  1596. /** @internal */
  1597. function validOptions(stem, options, onError) {
  1598. if (hasMaxOption(stem)) {
  1599. const maxOpt = maxOptions[stem];
  1600. if (options.length > maxOpt) {
  1601. if (maxOpt === 0) {
  1602. for (const opt of options) onError(new BadOptionError(stem, opt));
  1603. } else {
  1604. onError(new TooManyOptionsError(stem, options, maxOpt));
  1605. }
  1606. return false;
  1607. } else if (hasMinOption(stem) && options.length < minOptions[stem]) {
  1608. onError(new MissingOptionError(stem));
  1609. return false;
  1610. }
  1611. }
  1612. return true;
  1613. }
  1614. function parseBlueprintDigits(src, style) {
  1615. const re = style === 'fraction' ? /^\.(0*)(\+|#*)$/ : /^(@+)(\+|#*)$/;
  1616. const match = src && src.match(re);
  1617. if (match) {
  1618. const min = match[1].length;
  1619. switch (match[2].charAt(0)) {
  1620. case '':
  1621. return {
  1622. min,
  1623. max: min
  1624. };
  1625. case '+':
  1626. return {
  1627. min,
  1628. max: null
  1629. };
  1630. case '#':
  1631. {
  1632. return {
  1633. min,
  1634. max: min + match[2].length
  1635. };
  1636. }
  1637. }
  1638. }
  1639. return null;
  1640. }
  1641. function parsePrecisionBlueprint(stem, options, onError) {
  1642. const fd = parseBlueprintDigits(stem, 'fraction');
  1643. if (fd) {
  1644. if (options.length > 1) onError(new TooManyOptionsError(stem, options, 1));
  1645. const res = {
  1646. style: 'precision-fraction',
  1647. source: stem,
  1648. minFraction: fd.min
  1649. };
  1650. if (fd.max != null) res.maxFraction = fd.max;
  1651. const option = options[0];
  1652. const sd = parseBlueprintDigits(option, 'significant');
  1653. if (sd) {
  1654. res.source = `${stem}/${option}`;
  1655. res.minSignificant = sd.min;
  1656. if (sd.max != null) res.maxSignificant = sd.max;
  1657. } else if (option) onError(new BadOptionError(stem, option));
  1658. return res;
  1659. }
  1660. const sd = parseBlueprintDigits(stem, 'significant');
  1661. if (sd) {
  1662. for (const opt of options) onError(new BadOptionError(stem, opt));
  1663. const res = {
  1664. style: 'precision-fraction',
  1665. source: stem,
  1666. minSignificant: sd.min
  1667. };
  1668. if (sd.max != null) res.maxSignificant = sd.max;
  1669. return res;
  1670. }
  1671. return null;
  1672. }
  1673. /** @internal */
  1674. class TokenParser {
  1675. constructor(onError) {
  1676. this.skeleton = {};
  1677. this.onError = onError;
  1678. }
  1679. badOption(stem, opt) {
  1680. this.onError(new BadOptionError(stem, opt));
  1681. }
  1682. assertEmpty(key) {
  1683. const prev = this.skeleton[key];
  1684. if (prev) this.onError(new MaskedValueError(key, prev));
  1685. }
  1686. parseToken(stem, options) {
  1687. if (!validOptions(stem, options, this.onError)) return;
  1688. const option = options[0];
  1689. const res = this.skeleton;
  1690. switch (stem) {
  1691. // notation
  1692. case 'compact-short':
  1693. case 'compact-long':
  1694. case 'notation-simple':
  1695. this.assertEmpty('notation');
  1696. res.notation = {
  1697. style: stem
  1698. };
  1699. break;
  1700. case 'scientific':
  1701. case 'engineering':
  1702. {
  1703. let expDigits = null;
  1704. let expSign = undefined;
  1705. for (const opt of options) {
  1706. switch (opt) {
  1707. case 'sign-auto':
  1708. case 'sign-always':
  1709. case 'sign-never':
  1710. case 'sign-accounting':
  1711. case 'sign-accounting-always':
  1712. case 'sign-except-zero':
  1713. case 'sign-accounting-except-zero':
  1714. expSign = opt;
  1715. break;
  1716. default:
  1717. if (/^\+e+$/.test(opt)) expDigits = opt.length - 1;else {
  1718. this.badOption(stem, opt);
  1719. }
  1720. }
  1721. }
  1722. this.assertEmpty('notation');
  1723. const source = options.join('/');
  1724. res.notation = expDigits && expSign ? {
  1725. style: stem,
  1726. source,
  1727. expDigits,
  1728. expSign
  1729. } : expDigits ? {
  1730. style: stem,
  1731. source,
  1732. expDigits
  1733. } : expSign ? {
  1734. style: stem,
  1735. source,
  1736. expSign
  1737. } : {
  1738. style: stem,
  1739. source
  1740. };
  1741. break;
  1742. }
  1743. // unit
  1744. case 'percent':
  1745. case 'permille':
  1746. case 'base-unit':
  1747. this.assertEmpty('unit');
  1748. res.unit = {
  1749. style: stem
  1750. };
  1751. break;
  1752. case 'currency':
  1753. if (/^[A-Z]{3}$/.test(option)) {
  1754. this.assertEmpty('unit');
  1755. res.unit = {
  1756. style: stem,
  1757. currency: option
  1758. };
  1759. } else this.badOption(stem, option);
  1760. break;
  1761. case 'measure-unit':
  1762. {
  1763. if (isUnit(option)) {
  1764. this.assertEmpty('unit');
  1765. res.unit = {
  1766. style: stem,
  1767. unit: option
  1768. };
  1769. } else this.badOption(stem, option);
  1770. break;
  1771. }
  1772. // unitPer
  1773. case 'per-measure-unit':
  1774. {
  1775. if (isUnit(option)) {
  1776. this.assertEmpty('unitPer');
  1777. res.unitPer = option;
  1778. } else this.badOption(stem, option);
  1779. break;
  1780. }
  1781. // unitWidth
  1782. case 'unit-width-narrow':
  1783. case 'unit-width-short':
  1784. case 'unit-width-full-name':
  1785. case 'unit-width-iso-code':
  1786. case 'unit-width-hidden':
  1787. this.assertEmpty('unitWidth');
  1788. res.unitWidth = stem;
  1789. break;
  1790. // precision
  1791. case 'precision-integer':
  1792. case 'precision-unlimited':
  1793. case 'precision-currency-cash':
  1794. this.assertEmpty('precision');
  1795. res.precision = {
  1796. style: stem
  1797. };
  1798. break;
  1799. case 'precision-currency-standard':
  1800. this.assertEmpty('precision');
  1801. if (option === 'w') {
  1802. res.precision = {
  1803. style: stem,
  1804. trailingZero: 'stripIfInteger'
  1805. };
  1806. } else {
  1807. res.precision = {
  1808. style: stem
  1809. };
  1810. }
  1811. break;
  1812. case 'precision-increment':
  1813. {
  1814. const increment = Number(option);
  1815. if (increment > 0) {
  1816. this.assertEmpty('precision');
  1817. res.precision = {
  1818. style: stem,
  1819. increment
  1820. };
  1821. } else this.badOption(stem, option);
  1822. break;
  1823. }
  1824. // roundingMode
  1825. case 'rounding-mode-ceiling':
  1826. case 'rounding-mode-floor':
  1827. case 'rounding-mode-down':
  1828. case 'rounding-mode-up':
  1829. case 'rounding-mode-half-even':
  1830. case 'rounding-mode-half-odd':
  1831. case 'rounding-mode-half-ceiling':
  1832. case 'rounding-mode-half-floor':
  1833. case 'rounding-mode-half-down':
  1834. case 'rounding-mode-half-up':
  1835. case 'rounding-mode-unnecessary':
  1836. this.assertEmpty('roundingMode');
  1837. res.roundingMode = stem;
  1838. break;
  1839. // integerWidth
  1840. case 'integer-width':
  1841. {
  1842. if (/^\+0*$/.test(option)) {
  1843. this.assertEmpty('integerWidth');
  1844. res.integerWidth = {
  1845. source: option,
  1846. min: option.length - 1
  1847. };
  1848. } else {
  1849. const m = option.match(/^#*(0*)$/);
  1850. if (m) {
  1851. this.assertEmpty('integerWidth');
  1852. res.integerWidth = {
  1853. source: option,
  1854. min: m[1].length,
  1855. max: m[0].length
  1856. };
  1857. } else this.badOption(stem, option);
  1858. }
  1859. break;
  1860. }
  1861. // scale
  1862. case 'scale':
  1863. {
  1864. const scale = Number(option);
  1865. if (scale > 0) {
  1866. this.assertEmpty('scale');
  1867. res.scale = scale;
  1868. } else this.badOption(stem, option);
  1869. break;
  1870. }
  1871. // group
  1872. case 'group-off':
  1873. case 'group-min2':
  1874. case 'group-auto':
  1875. case 'group-on-aligned':
  1876. case 'group-thousands':
  1877. this.assertEmpty('group');
  1878. res.group = stem;
  1879. break;
  1880. // numberingSystem
  1881. case 'latin':
  1882. this.assertEmpty('numberingSystem');
  1883. res.numberingSystem = 'latn';
  1884. break;
  1885. case 'numbering-system':
  1886. {
  1887. if (isNumberingSystem(option)) {
  1888. this.assertEmpty('numberingSystem');
  1889. res.numberingSystem = option;
  1890. } else this.badOption(stem, option);
  1891. break;
  1892. }
  1893. // sign
  1894. case 'sign-auto':
  1895. case 'sign-always':
  1896. case 'sign-never':
  1897. case 'sign-accounting':
  1898. case 'sign-accounting-always':
  1899. case 'sign-except-zero':
  1900. case 'sign-accounting-except-zero':
  1901. this.assertEmpty('sign');
  1902. res.sign = stem;
  1903. break;
  1904. // decimal
  1905. case 'decimal-auto':
  1906. case 'decimal-always':
  1907. this.assertEmpty('decimal');
  1908. res.decimal = stem;
  1909. break;
  1910. // precision blueprint
  1911. default:
  1912. {
  1913. const precision = parsePrecisionBlueprint(stem, options, this.onError);
  1914. if (precision) {
  1915. this.assertEmpty('precision');
  1916. res.precision = precision;
  1917. } else {
  1918. this.onError(new BadStemError(stem));
  1919. }
  1920. }
  1921. }
  1922. }
  1923. }
  1924. /**
  1925. * Parse an {@link
  1926. * https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md
  1927. * | ICU NumberFormatter skeleton} string into a {@link Skeleton} structure.
  1928. *
  1929. * @public
  1930. * @param src - The skeleton string
  1931. * @param onError - Called when the parser encounters a syntax error. The
  1932. * function will still return a {@link Skeleton}, but it may not contain
  1933. * information for all tokens. If not defined, the error will be thrown
  1934. * instead.
  1935. *
  1936. * @example
  1937. * ```js
  1938. * import { parseNumberSkeleton } from '@messageformat/number-skeleton'
  1939. *
  1940. * parseNumberSkeleton('compact-short currency/GBP', console.error)
  1941. * // {
  1942. * // notation: { style: 'compact-short' },
  1943. * // unit: { style: 'currency', currency: 'GBP' }
  1944. * // }
  1945. * ```
  1946. */
  1947. function parseNumberSkeleton(src) {
  1948. let onError = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : error => {
  1949. throw error;
  1950. };
  1951. const tokens = [];
  1952. for (const part of src.split(' ')) {
  1953. if (part) {
  1954. const options = part.split('/');
  1955. const stem = options.shift() || '';
  1956. tokens.push({
  1957. stem,
  1958. options
  1959. });
  1960. }
  1961. }
  1962. const parser = new TokenParser(onError);
  1963. for (const {
  1964. stem,
  1965. options
  1966. } of tokens) {
  1967. parser.parseToken(stem, options);
  1968. }
  1969. return parser.skeleton;
  1970. }
  1971. /**
  1972. * Returns a number formatter function for the given locales and number skeleton
  1973. *
  1974. * @remarks
  1975. * Uses `Intl.NumberFormat` (ES2020) internally.
  1976. *
  1977. * @public
  1978. * @param locales - One or more valid BCP 47 language tags, e.g. `fr` or `en-CA`
  1979. * @param skeleton - An ICU NumberFormatter pattern or `::`-prefixed skeleton
  1980. * string, or a parsed `Skeleton` structure
  1981. * @param currency - If `skeleton` is a pattern string that includes ¤ tokens,
  1982. * their skeleton representation requires a three-letter currency code.
  1983. * @param onError - If defined, will be called separately for each encountered
  1984. * parsing error and unsupported feature.
  1985. * @example
  1986. * ```js
  1987. * import { getNumberFormatter } from '@messageformat/number-skeleton'
  1988. *
  1989. * let src = ':: currency/CAD unit-width-narrow'
  1990. * let fmt = getNumberFormatter('en-CA', src, console.error)
  1991. * fmt(42) // '$42.00'
  1992. *
  1993. * src = '::percent scale/100'
  1994. * fmt = getNumberFormatter('en', src, console.error)
  1995. * fmt(0.3) // '30%'
  1996. * ```
  1997. */
  1998. function getNumberFormatter(locales, skeleton, currency, onError) {
  1999. if (typeof skeleton === 'string') {
  2000. skeleton = skeleton.indexOf('::') === 0 ? parseNumberSkeleton(skeleton.slice(2), onError) : parseNumberPattern(skeleton, currency, onError);
  2001. }
  2002. const lc = getNumberFormatLocales(locales, skeleton);
  2003. const opt = getNumberFormatOptions(skeleton, onError);
  2004. const mod = getNumberFormatModifier(skeleton);
  2005. const nf = new Intl.NumberFormat(lc, opt);
  2006. if (skeleton.affix) {
  2007. const [p0, p1] = skeleton.affix.pos;
  2008. const [n0, n1] = skeleton.affix.neg || ['', ''];
  2009. return value => {
  2010. const n = nf.format(mod(value));
  2011. return value < 0 ? `${n0}${n}${n1}` : `${p0}${n}${p1}`;
  2012. };
  2013. }
  2014. return value => nf.format(mod(value));
  2015. }
  2016. /**
  2017. * Returns a string of JavaScript source that evaluates to a number formatter
  2018. * function with the same `(value: number) => string` signature as the function
  2019. * returned by {@link getNumberFormatter}.
  2020. *
  2021. * @remarks
  2022. * The returned function will memoize an `Intl.NumberFormat` instance.
  2023. *
  2024. * @public
  2025. * @param locales - One or more valid BCP 47 language tags, e.g. `fr` or `en-CA`
  2026. * @param skeleton - An ICU NumberFormatter pattern or `::`-prefixed skeleton
  2027. * string, or a parsed `Skeleton` structure
  2028. * @param currency - If `skeleton` is a pattern string that includes ¤ tokens,
  2029. * their skeleton representation requires a three-letter currency code.
  2030. * @param onError - If defined, will be called separately for each encountered
  2031. * parsing error and unsupported feature.
  2032. * @example
  2033. * ```js
  2034. * import { getNumberFormatterSource } from '@messageformat/number-skeleton'
  2035. *
  2036. * getNumberFormatterSource('en', '::percent', console.error)
  2037. * // '(function() {\n' +
  2038. * // ' var opt = {"style":"percent"};\n' +
  2039. * // ' var nf = new Intl.NumberFormat(["en"], opt);\n' +
  2040. * // ' var mod = function(n) { return n * 0.01; };\n' +
  2041. * // ' return function(value) { return nf.format(mod(value)); }\n' +
  2042. * // '})()'
  2043. *
  2044. * const src = getNumberFormatterSource('en-CA', ':: currency/CAD unit-width-narrow', console.error)
  2045. * // '(function() {\n' +
  2046. * // ' var opt = {"style":"currency","currency":"CAD","currencyDisplay":"narrowSymbol","unitDisplay":"narrow"};\n' +
  2047. * // ' var nf = new Intl.NumberFormat(["en-CA"], opt);\n'
  2048. * // ' return function(value) { return nf.format(value); }\n' +
  2049. * // '})()'
  2050. * const fmt = new Function(`return ${src}`)()
  2051. * fmt(42) // '$42.00'
  2052. * ```
  2053. */
  2054. function getNumberFormatterSource(locales, skeleton, currency, onError) {
  2055. if (typeof skeleton === 'string') {
  2056. skeleton = skeleton.indexOf('::') === 0 ? parseNumberSkeleton(skeleton.slice(2), onError) : parseNumberPattern(skeleton, currency, onError);
  2057. }
  2058. const lc = getNumberFormatLocales(locales, skeleton);
  2059. const opt = getNumberFormatOptions(skeleton, onError);
  2060. const modSrc = getNumberFormatModifierSource(skeleton);
  2061. const lines = [`(function() {`, `var opt = ${JSON.stringify(opt)};`, `var nf = new Intl.NumberFormat(${JSON.stringify(lc)}, opt);`];
  2062. let res = 'nf.format(value)';
  2063. if (modSrc) {
  2064. lines.push(`var mod = ${modSrc};`);
  2065. res = 'nf.format(mod(value))';
  2066. }
  2067. if (skeleton.affix) {
  2068. const [p0, p1] = skeleton.affix.pos.map(s => JSON.stringify(s));
  2069. if (skeleton.affix.neg) {
  2070. const [n0, n1] = skeleton.affix.neg.map(s => JSON.stringify(s));
  2071. res = `value < 0 ? ${n0} + ${res} + ${n1} : ${p0} + ${res} + ${p1}`;
  2072. } else {
  2073. res = `${p0} + ${res} + ${p1}`;
  2074. }
  2075. }
  2076. lines.push(`return function(value) { return ${res}; }`);
  2077. return lines.join('\n ') + '\n})()';
  2078. }
  2079. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  2080. var parser = {};
  2081. var lexer = {};
  2082. var mooExports = {};
  2083. var moo = {
  2084. get exports(){ return mooExports; },
  2085. set exports(v){ mooExports = v; },
  2086. };
  2087. (function (module) {
  2088. (function (root, factory) {
  2089. if (module.exports) {
  2090. module.exports = factory();
  2091. } else {
  2092. root.moo = factory();
  2093. }
  2094. })(commonjsGlobal, function () {
  2095. var hasOwnProperty = Object.prototype.hasOwnProperty;
  2096. var toString = Object.prototype.toString;
  2097. var hasSticky = typeof new RegExp().sticky === 'boolean';
  2098. /***************************************************************************/
  2099. function isRegExp(o) {
  2100. return o && toString.call(o) === '[object RegExp]';
  2101. }
  2102. function isObject(o) {
  2103. return o && typeof o === 'object' && !isRegExp(o) && !Array.isArray(o);
  2104. }
  2105. function reEscape(s) {
  2106. return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  2107. }
  2108. function reGroups(s) {
  2109. var re = new RegExp('|' + s);
  2110. return re.exec('').length - 1;
  2111. }
  2112. function reCapture(s) {
  2113. return '(' + s + ')';
  2114. }
  2115. function reUnion(regexps) {
  2116. if (!regexps.length) return '(?!)';
  2117. var source = regexps.map(function (s) {
  2118. return "(?:" + s + ")";
  2119. }).join('|');
  2120. return "(?:" + source + ")";
  2121. }
  2122. function regexpOrLiteral(obj) {
  2123. if (typeof obj === 'string') {
  2124. return '(?:' + reEscape(obj) + ')';
  2125. } else if (isRegExp(obj)) {
  2126. // TODO: consider /u support
  2127. if (obj.ignoreCase) throw new Error('RegExp /i flag not allowed');
  2128. if (obj.global) throw new Error('RegExp /g flag is implied');
  2129. if (obj.sticky) throw new Error('RegExp /y flag is implied');
  2130. if (obj.multiline) throw new Error('RegExp /m flag is implied');
  2131. return obj.source;
  2132. } else {
  2133. throw new Error('Not a pattern: ' + obj);
  2134. }
  2135. }
  2136. function pad(s, length) {
  2137. if (s.length > length) {
  2138. return s;
  2139. }
  2140. return Array(length - s.length + 1).join(" ") + s;
  2141. }
  2142. function lastNLines(string, numLines) {
  2143. var position = string.length;
  2144. var lineBreaks = 0;
  2145. while (true) {
  2146. var idx = string.lastIndexOf("\n", position - 1);
  2147. if (idx === -1) {
  2148. break;
  2149. } else {
  2150. lineBreaks++;
  2151. }
  2152. position = idx;
  2153. if (lineBreaks === numLines) {
  2154. break;
  2155. }
  2156. if (position === 0) {
  2157. break;
  2158. }
  2159. }
  2160. var startPosition = lineBreaks < numLines ? 0 : position + 1;
  2161. return string.substring(startPosition).split("\n");
  2162. }
  2163. function objectToRules(object) {
  2164. var keys = Object.getOwnPropertyNames(object);
  2165. var result = [];
  2166. for (var i = 0; i < keys.length; i++) {
  2167. var key = keys[i];
  2168. var thing = object[key];
  2169. var rules = [].concat(thing);
  2170. if (key === 'include') {
  2171. for (var j = 0; j < rules.length; j++) {
  2172. result.push({
  2173. include: rules[j]
  2174. });
  2175. }
  2176. continue;
  2177. }
  2178. var match = [];
  2179. rules.forEach(function (rule) {
  2180. if (isObject(rule)) {
  2181. if (match.length) result.push(ruleOptions(key, match));
  2182. result.push(ruleOptions(key, rule));
  2183. match = [];
  2184. } else {
  2185. match.push(rule);
  2186. }
  2187. });
  2188. if (match.length) result.push(ruleOptions(key, match));
  2189. }
  2190. return result;
  2191. }
  2192. function arrayToRules(array) {
  2193. var result = [];
  2194. for (var i = 0; i < array.length; i++) {
  2195. var obj = array[i];
  2196. if (obj.include) {
  2197. var include = [].concat(obj.include);
  2198. for (var j = 0; j < include.length; j++) {
  2199. result.push({
  2200. include: include[j]
  2201. });
  2202. }
  2203. continue;
  2204. }
  2205. if (!obj.type) {
  2206. throw new Error('Rule has no type: ' + JSON.stringify(obj));
  2207. }
  2208. result.push(ruleOptions(obj.type, obj));
  2209. }
  2210. return result;
  2211. }
  2212. function ruleOptions(type, obj) {
  2213. if (!isObject(obj)) {
  2214. obj = {
  2215. match: obj
  2216. };
  2217. }
  2218. if (obj.include) {
  2219. throw new Error('Matching rules cannot also include states');
  2220. }
  2221. // nb. error and fallback imply lineBreaks
  2222. var options = {
  2223. defaultType: type,
  2224. lineBreaks: !!obj.error || !!obj.fallback,
  2225. pop: false,
  2226. next: null,
  2227. push: null,
  2228. error: false,
  2229. fallback: false,
  2230. value: null,
  2231. type: null,
  2232. shouldThrow: false
  2233. };
  2234. // Avoid Object.assign(), so we support IE9+
  2235. for (var key in obj) {
  2236. if (hasOwnProperty.call(obj, key)) {
  2237. options[key] = obj[key];
  2238. }
  2239. }
  2240. // type transform cannot be a string
  2241. if (typeof options.type === 'string' && type !== options.type) {
  2242. throw new Error("Type transform cannot be a string (type '" + options.type + "' for token '" + type + "')");
  2243. }
  2244. // convert to array
  2245. var match = options.match;
  2246. options.match = Array.isArray(match) ? match : match ? [match] : [];
  2247. options.match.sort(function (a, b) {
  2248. return isRegExp(a) && isRegExp(b) ? 0 : isRegExp(b) ? -1 : isRegExp(a) ? +1 : b.length - a.length;
  2249. });
  2250. return options;
  2251. }
  2252. function toRules(spec) {
  2253. return Array.isArray(spec) ? arrayToRules(spec) : objectToRules(spec);
  2254. }
  2255. var defaultErrorRule = ruleOptions('error', {
  2256. lineBreaks: true,
  2257. shouldThrow: true
  2258. });
  2259. function compileRules(rules, hasStates) {
  2260. var errorRule = null;
  2261. var fast = Object.create(null);
  2262. var fastAllowed = true;
  2263. var unicodeFlag = null;
  2264. var groups = [];
  2265. var parts = [];
  2266. // If there is a fallback rule, then disable fast matching
  2267. for (var i = 0; i < rules.length; i++) {
  2268. if (rules[i].fallback) {
  2269. fastAllowed = false;
  2270. }
  2271. }
  2272. for (var i = 0; i < rules.length; i++) {
  2273. var options = rules[i];
  2274. if (options.include) {
  2275. // all valid inclusions are removed by states() preprocessor
  2276. throw new Error('Inheritance is not allowed in stateless lexers');
  2277. }
  2278. if (options.error || options.fallback) {
  2279. // errorRule can only be set once
  2280. if (errorRule) {
  2281. if (!options.fallback === !errorRule.fallback) {
  2282. throw new Error("Multiple " + (options.fallback ? "fallback" : "error") + " rules not allowed (for token '" + options.defaultType + "')");
  2283. } else {
  2284. throw new Error("fallback and error are mutually exclusive (for token '" + options.defaultType + "')");
  2285. }
  2286. }
  2287. errorRule = options;
  2288. }
  2289. var match = options.match.slice();
  2290. if (fastAllowed) {
  2291. while (match.length && typeof match[0] === 'string' && match[0].length === 1) {
  2292. var word = match.shift();
  2293. fast[word.charCodeAt(0)] = options;
  2294. }
  2295. }
  2296. // Warn about inappropriate state-switching options
  2297. if (options.pop || options.push || options.next) {
  2298. if (!hasStates) {
  2299. throw new Error("State-switching options are not allowed in stateless lexers (for token '" + options.defaultType + "')");
  2300. }
  2301. if (options.fallback) {
  2302. throw new Error("State-switching options are not allowed on fallback tokens (for token '" + options.defaultType + "')");
  2303. }
  2304. }
  2305. // Only rules with a .match are included in the RegExp
  2306. if (match.length === 0) {
  2307. continue;
  2308. }
  2309. fastAllowed = false;
  2310. groups.push(options);
  2311. // Check unicode flag is used everywhere or nowhere
  2312. for (var j = 0; j < match.length; j++) {
  2313. var obj = match[j];
  2314. if (!isRegExp(obj)) {
  2315. continue;
  2316. }
  2317. if (unicodeFlag === null) {
  2318. unicodeFlag = obj.unicode;
  2319. } else if (unicodeFlag !== obj.unicode && options.fallback === false) {
  2320. throw new Error('If one rule is /u then all must be');
  2321. }
  2322. }
  2323. // convert to RegExp
  2324. var pat = reUnion(match.map(regexpOrLiteral));
  2325. // validate
  2326. var regexp = new RegExp(pat);
  2327. if (regexp.test("")) {
  2328. throw new Error("RegExp matches empty string: " + regexp);
  2329. }
  2330. var groupCount = reGroups(pat);
  2331. if (groupCount > 0) {
  2332. throw new Error("RegExp has capture groups: " + regexp + "\nUse (?: … ) instead");
  2333. }
  2334. // try and detect rules matching newlines
  2335. if (!options.lineBreaks && regexp.test('\n')) {
  2336. throw new Error('Rule should declare lineBreaks: ' + regexp);
  2337. }
  2338. // store regex
  2339. parts.push(reCapture(pat));
  2340. }
  2341. // If there's no fallback rule, use the sticky flag so we only look for
  2342. // matches at the current index.
  2343. //
  2344. // If we don't support the sticky flag, then fake it using an irrefutable
  2345. // match (i.e. an empty pattern).
  2346. var fallbackRule = errorRule && errorRule.fallback;
  2347. var flags = hasSticky && !fallbackRule ? 'ym' : 'gm';
  2348. var suffix = hasSticky || fallbackRule ? '' : '|';
  2349. if (unicodeFlag === true) flags += "u";
  2350. var combined = new RegExp(reUnion(parts) + suffix, flags);
  2351. return {
  2352. regexp: combined,
  2353. groups: groups,
  2354. fast: fast,
  2355. error: errorRule || defaultErrorRule
  2356. };
  2357. }
  2358. function compile(rules) {
  2359. var result = compileRules(toRules(rules));
  2360. return new Lexer({
  2361. start: result
  2362. }, 'start');
  2363. }
  2364. function checkStateGroup(g, name, map) {
  2365. var state = g && (g.push || g.next);
  2366. if (state && !map[state]) {
  2367. throw new Error("Missing state '" + state + "' (in token '" + g.defaultType + "' of state '" + name + "')");
  2368. }
  2369. if (g && g.pop && +g.pop !== 1) {
  2370. throw new Error("pop must be 1 (in token '" + g.defaultType + "' of state '" + name + "')");
  2371. }
  2372. }
  2373. function compileStates(states, start) {
  2374. var all = states.$all ? toRules(states.$all) : [];
  2375. delete states.$all;
  2376. var keys = Object.getOwnPropertyNames(states);
  2377. if (!start) start = keys[0];
  2378. var ruleMap = Object.create(null);
  2379. for (var i = 0; i < keys.length; i++) {
  2380. var key = keys[i];
  2381. ruleMap[key] = toRules(states[key]).concat(all);
  2382. }
  2383. for (var i = 0; i < keys.length; i++) {
  2384. var key = keys[i];
  2385. var rules = ruleMap[key];
  2386. var included = Object.create(null);
  2387. for (var j = 0; j < rules.length; j++) {
  2388. var rule = rules[j];
  2389. if (!rule.include) continue;
  2390. var splice = [j, 1];
  2391. if (rule.include !== key && !included[rule.include]) {
  2392. included[rule.include] = true;
  2393. var newRules = ruleMap[rule.include];
  2394. if (!newRules) {
  2395. throw new Error("Cannot include nonexistent state '" + rule.include + "' (in state '" + key + "')");
  2396. }
  2397. for (var k = 0; k < newRules.length; k++) {
  2398. var newRule = newRules[k];
  2399. if (rules.indexOf(newRule) !== -1) continue;
  2400. splice.push(newRule);
  2401. }
  2402. }
  2403. rules.splice.apply(rules, splice);
  2404. j--;
  2405. }
  2406. }
  2407. var map = Object.create(null);
  2408. for (var i = 0; i < keys.length; i++) {
  2409. var key = keys[i];
  2410. map[key] = compileRules(ruleMap[key], true);
  2411. }
  2412. for (var i = 0; i < keys.length; i++) {
  2413. var name = keys[i];
  2414. var state = map[name];
  2415. var groups = state.groups;
  2416. for (var j = 0; j < groups.length; j++) {
  2417. checkStateGroup(groups[j], name, map);
  2418. }
  2419. var fastKeys = Object.getOwnPropertyNames(state.fast);
  2420. for (var j = 0; j < fastKeys.length; j++) {
  2421. checkStateGroup(state.fast[fastKeys[j]], name, map);
  2422. }
  2423. }
  2424. return new Lexer(map, start);
  2425. }
  2426. function keywordTransform(map) {
  2427. // Use a JavaScript Map to map keywords to their corresponding token type
  2428. // unless Map is unsupported, then fall back to using an Object:
  2429. var isMap = typeof Map !== 'undefined';
  2430. var reverseMap = isMap ? new Map() : Object.create(null);
  2431. var types = Object.getOwnPropertyNames(map);
  2432. for (var i = 0; i < types.length; i++) {
  2433. var tokenType = types[i];
  2434. var item = map[tokenType];
  2435. var keywordList = Array.isArray(item) ? item : [item];
  2436. keywordList.forEach(function (keyword) {
  2437. if (typeof keyword !== 'string') {
  2438. throw new Error("keyword must be string (in keyword '" + tokenType + "')");
  2439. }
  2440. if (isMap) {
  2441. reverseMap.set(keyword, tokenType);
  2442. } else {
  2443. reverseMap[keyword] = tokenType;
  2444. }
  2445. });
  2446. }
  2447. return function (k) {
  2448. return isMap ? reverseMap.get(k) : reverseMap[k];
  2449. };
  2450. }
  2451. /***************************************************************************/
  2452. var Lexer = function (states, state) {
  2453. this.startState = state;
  2454. this.states = states;
  2455. this.buffer = '';
  2456. this.stack = [];
  2457. this.reset();
  2458. };
  2459. Lexer.prototype.reset = function (data, info) {
  2460. this.buffer = data || '';
  2461. this.index = 0;
  2462. this.line = info ? info.line : 1;
  2463. this.col = info ? info.col : 1;
  2464. this.queuedToken = info ? info.queuedToken : null;
  2465. this.queuedText = info ? info.queuedText : "";
  2466. this.queuedThrow = info ? info.queuedThrow : null;
  2467. this.setState(info ? info.state : this.startState);
  2468. this.stack = info && info.stack ? info.stack.slice() : [];
  2469. return this;
  2470. };
  2471. Lexer.prototype.save = function () {
  2472. return {
  2473. line: this.line,
  2474. col: this.col,
  2475. state: this.state,
  2476. stack: this.stack.slice(),
  2477. queuedToken: this.queuedToken,
  2478. queuedText: this.queuedText,
  2479. queuedThrow: this.queuedThrow
  2480. };
  2481. };
  2482. Lexer.prototype.setState = function (state) {
  2483. if (!state || this.state === state) return;
  2484. this.state = state;
  2485. var info = this.states[state];
  2486. this.groups = info.groups;
  2487. this.error = info.error;
  2488. this.re = info.regexp;
  2489. this.fast = info.fast;
  2490. };
  2491. Lexer.prototype.popState = function () {
  2492. this.setState(this.stack.pop());
  2493. };
  2494. Lexer.prototype.pushState = function (state) {
  2495. this.stack.push(this.state);
  2496. this.setState(state);
  2497. };
  2498. var eat = hasSticky ? function (re, buffer) {
  2499. // assume re is /y
  2500. return re.exec(buffer);
  2501. } : function (re, buffer) {
  2502. // assume re is /g
  2503. var match = re.exec(buffer);
  2504. // will always match, since we used the |(?:) trick
  2505. if (match[0].length === 0) {
  2506. return null;
  2507. }
  2508. return match;
  2509. };
  2510. Lexer.prototype._getGroup = function (match) {
  2511. var groupCount = this.groups.length;
  2512. for (var i = 0; i < groupCount; i++) {
  2513. if (match[i + 1] !== undefined) {
  2514. return this.groups[i];
  2515. }
  2516. }
  2517. throw new Error('Cannot find token type for matched text');
  2518. };
  2519. function tokenToString() {
  2520. return this.value;
  2521. }
  2522. Lexer.prototype.next = function () {
  2523. var index = this.index;
  2524. // If a fallback token matched, we don't need to re-run the RegExp
  2525. if (this.queuedGroup) {
  2526. var token = this._token(this.queuedGroup, this.queuedText, index);
  2527. this.queuedGroup = null;
  2528. this.queuedText = "";
  2529. return token;
  2530. }
  2531. var buffer = this.buffer;
  2532. if (index === buffer.length) {
  2533. return; // EOF
  2534. }
  2535. // Fast matching for single characters
  2536. var group = this.fast[buffer.charCodeAt(index)];
  2537. if (group) {
  2538. return this._token(group, buffer.charAt(index), index);
  2539. }
  2540. // Execute RegExp
  2541. var re = this.re;
  2542. re.lastIndex = index;
  2543. var match = eat(re, buffer);
  2544. // Error tokens match the remaining buffer
  2545. var error = this.error;
  2546. if (match == null) {
  2547. return this._token(error, buffer.slice(index, buffer.length), index);
  2548. }
  2549. var group = this._getGroup(match);
  2550. var text = match[0];
  2551. if (error.fallback && match.index !== index) {
  2552. this.queuedGroup = group;
  2553. this.queuedText = text;
  2554. // Fallback tokens contain the unmatched portion of the buffer
  2555. return this._token(error, buffer.slice(index, match.index), index);
  2556. }
  2557. return this._token(group, text, index);
  2558. };
  2559. Lexer.prototype._token = function (group, text, offset) {
  2560. // count line breaks
  2561. var lineBreaks = 0;
  2562. if (group.lineBreaks) {
  2563. var matchNL = /\n/g;
  2564. var nl = 1;
  2565. if (text === '\n') {
  2566. lineBreaks = 1;
  2567. } else {
  2568. while (matchNL.exec(text)) {
  2569. lineBreaks++;
  2570. nl = matchNL.lastIndex;
  2571. }
  2572. }
  2573. }
  2574. var token = {
  2575. type: typeof group.type === 'function' && group.type(text) || group.defaultType,
  2576. value: typeof group.value === 'function' ? group.value(text) : text,
  2577. text: text,
  2578. toString: tokenToString,
  2579. offset: offset,
  2580. lineBreaks: lineBreaks,
  2581. line: this.line,
  2582. col: this.col
  2583. };
  2584. // nb. adding more props to token object will make V8 sad!
  2585. var size = text.length;
  2586. this.index += size;
  2587. this.line += lineBreaks;
  2588. if (lineBreaks !== 0) {
  2589. this.col = size - nl + 1;
  2590. } else {
  2591. this.col += size;
  2592. }
  2593. // throw, if no rule with {error: true}
  2594. if (group.shouldThrow) {
  2595. var err = new Error(this.formatError(token, "invalid syntax"));
  2596. throw err;
  2597. }
  2598. if (group.pop) this.popState();else if (group.push) this.pushState(group.push);else if (group.next) this.setState(group.next);
  2599. return token;
  2600. };
  2601. if (typeof Symbol !== 'undefined' && Symbol.iterator) {
  2602. var LexerIterator = function (lexer) {
  2603. this.lexer = lexer;
  2604. };
  2605. LexerIterator.prototype.next = function () {
  2606. var token = this.lexer.next();
  2607. return {
  2608. value: token,
  2609. done: !token
  2610. };
  2611. };
  2612. LexerIterator.prototype[Symbol.iterator] = function () {
  2613. return this;
  2614. };
  2615. Lexer.prototype[Symbol.iterator] = function () {
  2616. return new LexerIterator(this);
  2617. };
  2618. }
  2619. Lexer.prototype.formatError = function (token, message) {
  2620. if (token == null) {
  2621. // An undefined token indicates EOF
  2622. var text = this.buffer.slice(this.index);
  2623. var token = {
  2624. text: text,
  2625. offset: this.index,
  2626. lineBreaks: text.indexOf('\n') === -1 ? 0 : 1,
  2627. line: this.line,
  2628. col: this.col
  2629. };
  2630. }
  2631. var numLinesAround = 2;
  2632. var firstDisplayedLine = Math.max(token.line - numLinesAround, 1);
  2633. var lastDisplayedLine = token.line + numLinesAround;
  2634. var lastLineDigits = String(lastDisplayedLine).length;
  2635. var displayedLines = lastNLines(this.buffer, this.line - token.line + numLinesAround + 1).slice(0, 5);
  2636. var errorLines = [];
  2637. errorLines.push(message + " at line " + token.line + " col " + token.col + ":");
  2638. errorLines.push("");
  2639. for (var i = 0; i < displayedLines.length; i++) {
  2640. var line = displayedLines[i];
  2641. var lineNo = firstDisplayedLine + i;
  2642. errorLines.push(pad(String(lineNo), lastLineDigits) + " " + line);
  2643. if (lineNo === token.line) {
  2644. errorLines.push(pad("", lastLineDigits + token.col + 1) + "^");
  2645. }
  2646. }
  2647. return errorLines.join("\n");
  2648. };
  2649. Lexer.prototype.clone = function () {
  2650. return new Lexer(this.states, this.state);
  2651. };
  2652. Lexer.prototype.has = function (tokenType) {
  2653. return true;
  2654. };
  2655. return {
  2656. compile: compile,
  2657. states: compileStates,
  2658. error: Object.freeze({
  2659. error: true
  2660. }),
  2661. fallback: Object.freeze({
  2662. fallback: true
  2663. }),
  2664. keywords: keywordTransform
  2665. };
  2666. });
  2667. })(moo);
  2668. (function (exports) {
  2669. var __importDefault = commonjsGlobal && commonjsGlobal.__importDefault || function (mod) {
  2670. return mod && mod.__esModule ? mod : {
  2671. "default": mod
  2672. };
  2673. };
  2674. Object.defineProperty(exports, "__esModule", {
  2675. value: true
  2676. });
  2677. exports.lexer = exports.states = void 0;
  2678. const moo_1 = __importDefault(mooExports);
  2679. exports.states = {
  2680. body: {
  2681. doubleapos: {
  2682. match: "''",
  2683. value: () => "'"
  2684. },
  2685. quoted: {
  2686. lineBreaks: true,
  2687. match: /'[{}#](?:[^]*?[^'])?'(?!')/u,
  2688. value: src => src.slice(1, -1).replace(/''/g, "'")
  2689. },
  2690. argument: {
  2691. lineBreaks: true,
  2692. match: /\{\s*[^\p{Pat_Syn}\p{Pat_WS}]+\s*/u,
  2693. push: 'arg',
  2694. value: src => src.substring(1).trim()
  2695. },
  2696. octothorpe: '#',
  2697. end: {
  2698. match: '}',
  2699. pop: 1
  2700. },
  2701. content: {
  2702. lineBreaks: true,
  2703. match: /[^][^{}#']*/u
  2704. }
  2705. },
  2706. arg: {
  2707. select: {
  2708. lineBreaks: true,
  2709. match: /,\s*(?:plural|select|selectordinal)\s*,\s*/u,
  2710. next: 'select',
  2711. value: src => src.split(',')[1].trim()
  2712. },
  2713. 'func-args': {
  2714. lineBreaks: true,
  2715. match: /,\s*[^\p{Pat_Syn}\p{Pat_WS}]+\s*,/u,
  2716. next: 'body',
  2717. value: src => src.split(',')[1].trim()
  2718. },
  2719. 'func-simple': {
  2720. lineBreaks: true,
  2721. match: /,\s*[^\p{Pat_Syn}\p{Pat_WS}]+\s*/u,
  2722. value: src => src.substring(1).trim()
  2723. },
  2724. end: {
  2725. match: '}',
  2726. pop: 1
  2727. }
  2728. },
  2729. select: {
  2730. offset: {
  2731. lineBreaks: true,
  2732. match: /\s*offset\s*:\s*\d+\s*/u,
  2733. value: src => src.split(':')[1].trim()
  2734. },
  2735. case: {
  2736. lineBreaks: true,
  2737. match: /\s*(?:=\d+|[^\p{Pat_Syn}\p{Pat_WS}]+)\s*\{/u,
  2738. push: 'body',
  2739. value: src => src.substring(0, src.indexOf('{')).trim()
  2740. },
  2741. end: {
  2742. match: /\s*\}/u,
  2743. pop: 1
  2744. }
  2745. }
  2746. };
  2747. exports.lexer = moo_1.default.states(exports.states);
  2748. })(lexer);
  2749. /**
  2750. * An AST parser for ICU MessageFormat strings
  2751. *
  2752. * @packageDocumentation
  2753. * @example
  2754. * ```
  2755. * import { parse } from '@messageformat/parser
  2756. *
  2757. * parse('So {wow}.')
  2758. * [ { type: 'content', value: 'So ' },
  2759. * { type: 'argument', arg: 'wow' },
  2760. * { type: 'content', value: '.' } ]
  2761. *
  2762. *
  2763. * parse('Such { thing }. { count, selectordinal, one {First} two {Second}' +
  2764. * ' few {Third} other {#th} } word.')
  2765. * [ { type: 'content', value: 'Such ' },
  2766. * { type: 'argument', arg: 'thing' },
  2767. * { type: 'content', value: '. ' },
  2768. * { type: 'selectordinal',
  2769. * arg: 'count',
  2770. * cases: [
  2771. * { key: 'one', tokens: [ { type: 'content', value: 'First' } ] },
  2772. * { key: 'two', tokens: [ { type: 'content', value: 'Second' } ] },
  2773. * { key: 'few', tokens: [ { type: 'content', value: 'Third' } ] },
  2774. * { key: 'other',
  2775. * tokens: [ { type: 'octothorpe' }, { type: 'content', value: 'th' } ] }
  2776. * ] },
  2777. * { type: 'content', value: ' word.' } ]
  2778. *
  2779. *
  2780. * parse('Many{type,select,plural{ numbers}selectordinal{ counting}' +
  2781. * 'select{ choices}other{ some {type}}}.')
  2782. * [ { type: 'content', value: 'Many' },
  2783. * { type: 'select',
  2784. * arg: 'type',
  2785. * cases: [
  2786. * { key: 'plural', tokens: [ { type: 'content', value: 'numbers' } ] },
  2787. * { key: 'selectordinal', tokens: [ { type: 'content', value: 'counting' } ] },
  2788. * { key: 'select', tokens: [ { type: 'content', value: 'choices' } ] },
  2789. * { key: 'other',
  2790. * tokens: [ { type: 'content', value: 'some ' }, { type: 'argument', arg: 'type' } ] }
  2791. * ] },
  2792. * { type: 'content', value: '.' } ]
  2793. *
  2794. *
  2795. * parse('{Such compliance')
  2796. * // ParseError: invalid syntax at line 1 col 7:
  2797. * //
  2798. * // {Such compliance
  2799. * // ^
  2800. *
  2801. *
  2802. * const msg = '{words, plural, zero{No words} one{One word} other{# words}}'
  2803. * parse(msg)
  2804. * [ { type: 'plural',
  2805. * arg: 'words',
  2806. * cases: [
  2807. * { key: 'zero', tokens: [ { type: 'content', value: 'No words' } ] },
  2808. * { key: 'one', tokens: [ { type: 'content', value: 'One word' } ] },
  2809. * { key: 'other',
  2810. * tokens: [ { type: 'octothorpe' }, { type: 'content', value: ' words' } ] }
  2811. * ] } ]
  2812. *
  2813. *
  2814. * parse(msg, { cardinal: [ 'one', 'other' ], ordinal: [ 'one', 'two', 'few', 'other' ] })
  2815. * // ParseError: The plural case zero is not valid in this locale at line 1 col 17:
  2816. * //
  2817. * // {words, plural, zero{
  2818. * // ^
  2819. * ```
  2820. */
  2821. Object.defineProperty(parser, "__esModule", {
  2822. value: true
  2823. });
  2824. var parse_1 = parser.parse = parser.ParseError = void 0;
  2825. const lexer_js_1 = lexer;
  2826. const getContext = lt => ({
  2827. offset: lt.offset,
  2828. line: lt.line,
  2829. col: lt.col,
  2830. text: lt.text,
  2831. lineBreaks: lt.lineBreaks
  2832. });
  2833. const isSelectType = type => type === 'plural' || type === 'select' || type === 'selectordinal';
  2834. function strictArgStyleParam(lt, param) {
  2835. let value = '';
  2836. let text = '';
  2837. for (const p of param) {
  2838. const pText = p.ctx.text;
  2839. text += pText;
  2840. switch (p.type) {
  2841. case 'content':
  2842. value += p.value;
  2843. break;
  2844. case 'argument':
  2845. case 'function':
  2846. case 'octothorpe':
  2847. value += pText;
  2848. break;
  2849. default:
  2850. throw new ParseError(lt, `Unsupported part in strict mode function arg style: ${pText}`);
  2851. }
  2852. }
  2853. const c = {
  2854. type: 'content',
  2855. value: value.trim(),
  2856. ctx: Object.assign({}, param[0].ctx, {
  2857. text
  2858. })
  2859. };
  2860. return [c];
  2861. }
  2862. const strictArgTypes = ['number', 'date', 'time', 'spellout', 'ordinal', 'duration'];
  2863. const defaultPluralKeys = ['zero', 'one', 'two', 'few', 'many', 'other'];
  2864. /**
  2865. * Thrown by {@link parse} on error
  2866. *
  2867. * @public
  2868. */
  2869. class ParseError extends Error {
  2870. /** @internal */
  2871. constructor(lt, msg) {
  2872. super(lexer_js_1.lexer.formatError(lt, msg));
  2873. }
  2874. }
  2875. parser.ParseError = ParseError;
  2876. class Parser {
  2877. constructor(src, opt) {
  2878. var _a, _b, _c, _d;
  2879. this.lexer = lexer_js_1.lexer.reset(src);
  2880. this.cardinalKeys = (_a = opt === null || opt === void 0 ? void 0 : opt.cardinal) !== null && _a !== void 0 ? _a : defaultPluralKeys;
  2881. this.ordinalKeys = (_b = opt === null || opt === void 0 ? void 0 : opt.ordinal) !== null && _b !== void 0 ? _b : defaultPluralKeys;
  2882. this.strict = (_c = opt === null || opt === void 0 ? void 0 : opt.strict) !== null && _c !== void 0 ? _c : false;
  2883. this.strictPluralKeys = (_d = opt === null || opt === void 0 ? void 0 : opt.strictPluralKeys) !== null && _d !== void 0 ? _d : true;
  2884. }
  2885. parse() {
  2886. return this.parseBody(false, true);
  2887. }
  2888. checkSelectKey(lt, type, key) {
  2889. if (key[0] === '=') {
  2890. if (type === 'select') throw new ParseError(lt, `The case ${key} is not valid with select`);
  2891. } else if (type !== 'select') {
  2892. const keys = type === 'plural' ? this.cardinalKeys : this.ordinalKeys;
  2893. if (this.strictPluralKeys && keys.length > 0 && !keys.includes(key)) {
  2894. const msg = `The ${type} case ${key} is not valid in this locale`;
  2895. throw new ParseError(lt, msg);
  2896. }
  2897. }
  2898. }
  2899. parseSelect(_ref, inPlural, ctx, type) {
  2900. let {
  2901. value: arg
  2902. } = _ref;
  2903. const sel = {
  2904. type,
  2905. arg,
  2906. cases: [],
  2907. ctx
  2908. };
  2909. if (type === 'plural' || type === 'selectordinal') inPlural = true;else if (this.strict) inPlural = false;
  2910. for (const lt of this.lexer) {
  2911. switch (lt.type) {
  2912. case 'offset':
  2913. if (type === 'select') throw new ParseError(lt, 'Unexpected plural offset for select');
  2914. if (sel.cases.length > 0) throw new ParseError(lt, 'Plural offset must be set before cases');
  2915. sel.pluralOffset = Number(lt.value);
  2916. ctx.text += lt.text;
  2917. ctx.lineBreaks += lt.lineBreaks;
  2918. break;
  2919. case 'case':
  2920. {
  2921. this.checkSelectKey(lt, type, lt.value);
  2922. sel.cases.push({
  2923. key: lt.value,
  2924. tokens: this.parseBody(inPlural),
  2925. ctx: getContext(lt)
  2926. });
  2927. break;
  2928. }
  2929. case 'end':
  2930. return sel;
  2931. /* istanbul ignore next: never happens */
  2932. default:
  2933. throw new ParseError(lt, `Unexpected lexer token: ${lt.type}`);
  2934. }
  2935. }
  2936. throw new ParseError(null, 'Unexpected message end');
  2937. }
  2938. parseArgToken(lt, inPlural) {
  2939. const ctx = getContext(lt);
  2940. const argType = this.lexer.next();
  2941. if (!argType) throw new ParseError(null, 'Unexpected message end');
  2942. ctx.text += argType.text;
  2943. ctx.lineBreaks += argType.lineBreaks;
  2944. if (this.strict && (argType.type === 'func-simple' || argType.type === 'func-args') && !strictArgTypes.includes(argType.value)) {
  2945. const msg = `Invalid strict mode function arg type: ${argType.value}`;
  2946. throw new ParseError(lt, msg);
  2947. }
  2948. switch (argType.type) {
  2949. case 'end':
  2950. return {
  2951. type: 'argument',
  2952. arg: lt.value,
  2953. ctx
  2954. };
  2955. case 'func-simple':
  2956. {
  2957. const end = this.lexer.next();
  2958. if (!end) throw new ParseError(null, 'Unexpected message end');
  2959. /* istanbul ignore if: never happens */
  2960. if (end.type !== 'end') throw new ParseError(end, `Unexpected lexer token: ${end.type}`);
  2961. ctx.text += end.text;
  2962. if (isSelectType(argType.value.toLowerCase())) throw new ParseError(argType, `Invalid type identifier: ${argType.value}`);
  2963. return {
  2964. type: 'function',
  2965. arg: lt.value,
  2966. key: argType.value,
  2967. ctx
  2968. };
  2969. }
  2970. case 'func-args':
  2971. {
  2972. if (isSelectType(argType.value.toLowerCase())) {
  2973. const msg = `Invalid type identifier: ${argType.value}`;
  2974. throw new ParseError(argType, msg);
  2975. }
  2976. let param = this.parseBody(this.strict ? false : inPlural);
  2977. if (this.strict && param.length > 0) param = strictArgStyleParam(lt, param);
  2978. return {
  2979. type: 'function',
  2980. arg: lt.value,
  2981. key: argType.value,
  2982. param,
  2983. ctx
  2984. };
  2985. }
  2986. case 'select':
  2987. /* istanbul ignore else: never happens */
  2988. if (isSelectType(argType.value)) return this.parseSelect(lt, inPlural, ctx, argType.value);else throw new ParseError(argType, `Unexpected select type ${argType.value}`);
  2989. /* istanbul ignore next: never happens */
  2990. default:
  2991. throw new ParseError(argType, `Unexpected lexer token: ${argType.type}`);
  2992. }
  2993. }
  2994. parseBody(inPlural, atRoot) {
  2995. const tokens = [];
  2996. let content = null;
  2997. for (const lt of this.lexer) {
  2998. if (lt.type === 'argument') {
  2999. if (content) content = null;
  3000. tokens.push(this.parseArgToken(lt, inPlural));
  3001. } else if (lt.type === 'octothorpe' && inPlural) {
  3002. if (content) content = null;
  3003. tokens.push({
  3004. type: 'octothorpe',
  3005. ctx: getContext(lt)
  3006. });
  3007. } else if (lt.type === 'end' && !atRoot) {
  3008. return tokens;
  3009. } else {
  3010. let value = lt.value;
  3011. if (!inPlural && lt.type === 'quoted' && value[0] === '#') {
  3012. if (value.includes('{')) {
  3013. const errMsg = `Unsupported escape pattern: ${value}`;
  3014. throw new ParseError(lt, errMsg);
  3015. }
  3016. value = lt.text;
  3017. }
  3018. if (content) {
  3019. content.value += value;
  3020. content.ctx.text += lt.text;
  3021. content.ctx.lineBreaks += lt.lineBreaks;
  3022. } else {
  3023. content = {
  3024. type: 'content',
  3025. value,
  3026. ctx: getContext(lt)
  3027. };
  3028. tokens.push(content);
  3029. }
  3030. }
  3031. }
  3032. if (atRoot) return tokens;
  3033. throw new ParseError(null, 'Unexpected message end');
  3034. }
  3035. }
  3036. /**
  3037. * Parse an input string into an array of tokens
  3038. *
  3039. * @public
  3040. * @remarks
  3041. * The parser only supports the default `DOUBLE_OPTIONAL`
  3042. * {@link http://www.icu-project.org/apiref/icu4c/messagepattern_8h.html#af6e0757e0eb81c980b01ee5d68a9978b | apostrophe mode}.
  3043. */
  3044. function parse(src) {
  3045. let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  3046. const parser = new Parser(src, options);
  3047. return parser.parse();
  3048. }
  3049. parse_1 = parser.parse = parse;
  3050. /**
  3051. * A set of utility functions that are called by the compiled Javascript
  3052. * functions, these are included locally in the output of {@link MessageFormat.compile compile()}.
  3053. */
  3054. /** @private */
  3055. function _nf$1(lc) {
  3056. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  3057. // @ts-ignore
  3058. return _nf$1[lc] || (_nf$1[lc] = new Intl.NumberFormat(lc));
  3059. }
  3060. /**
  3061. * Utility function for `#` in plural rules
  3062. *
  3063. * @param lc The current locale
  3064. * @param value The value to operate on
  3065. * @param offset An offset, set by the surrounding context
  3066. * @returns The result of applying the offset to the input value
  3067. */
  3068. function number(lc, value, offset) {
  3069. return _nf$1(lc).format(value - offset);
  3070. }
  3071. /**
  3072. * Strict utility function for `#` in plural rules
  3073. *
  3074. * Will throw an Error if `value` or `offset` are non-numeric.
  3075. *
  3076. * @param lc The current locale
  3077. * @param value The value to operate on
  3078. * @param offset An offset, set by the surrounding context
  3079. * @param name The name of the argument, used for error reporting
  3080. * @returns The result of applying the offset to the input value
  3081. */
  3082. function strictNumber(lc, value, offset, name) {
  3083. var n = value - offset;
  3084. if (isNaN(n)) throw new Error('`' + name + '` or its offset is not a number');
  3085. return _nf$1(lc).format(n);
  3086. }
  3087. /**
  3088. * Utility function for `{N, plural|selectordinal, ...}`
  3089. *
  3090. * @param value The key to use to find a pluralization rule
  3091. * @param offset An offset to apply to `value`
  3092. * @param lcfunc A locale function from `pluralFuncs`
  3093. * @param data The object from which results are looked up
  3094. * @param isOrdinal If true, use ordinal rather than cardinal rules
  3095. * @returns The result of the pluralization
  3096. */
  3097. function plural(value, offset, lcfunc, data, isOrdinal) {
  3098. if ({}.hasOwnProperty.call(data, value)) return data[value];
  3099. if (offset) value -= offset;
  3100. var key = lcfunc(value, isOrdinal);
  3101. return key in data ? data[key] : data.other;
  3102. }
  3103. /**
  3104. * Utility function for `{N, select, ...}`
  3105. *
  3106. * @param value The key to use to find a selection
  3107. * @param data The object from which results are looked up
  3108. * @returns The result of the select statement
  3109. */
  3110. function select(value, data) {
  3111. return {}.hasOwnProperty.call(data, value) ? data[value] : data.other;
  3112. }
  3113. /**
  3114. * Checks that all required arguments are set to defined values
  3115. *
  3116. * Throws on failure; otherwise returns undefined
  3117. *
  3118. * @param keys The required keys
  3119. * @param data The data object being checked
  3120. */
  3121. function reqArgs(keys, data) {
  3122. for (var i = 0; i < keys.length; ++i) if (!data || data[keys[i]] === undefined) throw new Error("Message requires argument '".concat(keys[i], "'"));
  3123. }
  3124. var Runtime = /*#__PURE__*/Object.freeze({
  3125. __proto__: null,
  3126. _nf: _nf$1,
  3127. number: number,
  3128. plural: plural,
  3129. reqArgs: reqArgs,
  3130. select: select,
  3131. strictNumber: strictNumber
  3132. });
  3133. /**
  3134. * Represent a date as a short/default/long/full string
  3135. *
  3136. * @param value Either a Unix epoch time in milliseconds, or a string value
  3137. * representing a date. Parsed with `new Date(value)`
  3138. *
  3139. * @example
  3140. * ```js
  3141. * var mf = new MessageFormat(['en', 'fi']);
  3142. *
  3143. * mf.compile('Today is {T, date}')({ T: Date.now() })
  3144. * // 'Today is Feb 21, 2016'
  3145. *
  3146. * mf.compile('Tänään on {T, date}', 'fi')({ T: Date.now() })
  3147. * // 'Tänään on 21. helmikuuta 2016'
  3148. *
  3149. * mf.compile('Unix time started on {T, date, full}')({ T: 0 })
  3150. * // 'Unix time started on Thursday, January 1, 1970'
  3151. *
  3152. * var cf = mf.compile('{sys} became operational on {d0, date, short}');
  3153. * cf({ sys: 'HAL 9000', d0: '12 January 1999' })
  3154. * // 'HAL 9000 became operational on 1/12/1999'
  3155. * ```
  3156. */
  3157. function date(value, lc, size) {
  3158. var o = {
  3159. day: 'numeric',
  3160. month: 'short',
  3161. year: 'numeric'
  3162. };
  3163. /* eslint-disable no-fallthrough */
  3164. switch (size) {
  3165. case 'full':
  3166. o.weekday = 'long';
  3167. case 'long':
  3168. o.month = 'long';
  3169. break;
  3170. case 'short':
  3171. o.month = 'numeric';
  3172. }
  3173. return new Date(value).toLocaleDateString(lc, o);
  3174. }
  3175. /**
  3176. * Represent a duration in seconds as a string
  3177. *
  3178. * @param value A finite number, or its string representation
  3179. * @return Includes one or two `:` separators, and matches the pattern
  3180. * `hhhh:mm:ss`, possibly with a leading `-` for negative values and a
  3181. * trailing `.sss` part for non-integer input
  3182. *
  3183. * @example
  3184. * ```js
  3185. * var mf = new MessageFormat();
  3186. *
  3187. * mf.compile('It has been {D, duration}')({ D: 123 })
  3188. * // 'It has been 2:03'
  3189. *
  3190. * mf.compile('Countdown: {D, duration}')({ D: -151200.42 })
  3191. * // 'Countdown: -42:00:00.420'
  3192. * ```
  3193. */
  3194. function duration(value) {
  3195. if (typeof value !== 'number') value = Number(value);
  3196. if (!isFinite(value)) return String(value);
  3197. var sign = '';
  3198. if (value < 0) {
  3199. sign = '-';
  3200. value = Math.abs(value);
  3201. } else {
  3202. value = Number(value);
  3203. }
  3204. var sec = value % 60;
  3205. var parts = [Math.round(sec) === sec ? sec : sec.toFixed(3)];
  3206. if (value < 60) {
  3207. parts.unshift(0); // at least one : is required
  3208. } else {
  3209. value = Math.round((value - Number(parts[0])) / 60);
  3210. parts.unshift(value % 60); // minutes
  3211. if (value >= 60) {
  3212. value = Math.round((value - Number(parts[0])) / 60);
  3213. parts.unshift(value); // hours
  3214. }
  3215. }
  3216. var first = parts.shift();
  3217. return sign + first + ':' + parts.map(function (n) {
  3218. return Number(n) < 10 ? '0' + String(n) : String(n);
  3219. }).join(':');
  3220. }
  3221. /**
  3222. * Represent a number as an integer, percent or currency value
  3223. *
  3224. * Available in MessageFormat strings as `{VAR, number, integer|percent|currency}`.
  3225. * Internally, calls Intl.NumberFormat with appropriate parameters. `currency` will
  3226. * default to USD; to change, set `MessageFormat#currency` to the appropriate
  3227. * three-letter currency code, or use the `currency:EUR` form of the argument.
  3228. *
  3229. * @example
  3230. * ```js
  3231. * var mf = new MessageFormat('en', { currency: 'EUR'});
  3232. *
  3233. * mf.compile('{N} is almost {N, number, integer}')({ N: 3.14 })
  3234. * // '3.14 is almost 3'
  3235. *
  3236. * mf.compile('{P, number, percent} complete')({ P: 0.99 })
  3237. * // '99% complete'
  3238. *
  3239. * mf.compile('The total is {V, number, currency}.')({ V: 5.5 })
  3240. * // 'The total is €5.50.'
  3241. *
  3242. * mf.compile('The total is {V, number, currency:GBP}.')({ V: 5.5 })
  3243. * // 'The total is £5.50.'
  3244. * ```
  3245. */
  3246. var _nf = {};
  3247. function nf(lc, opt) {
  3248. var key = String(lc) + JSON.stringify(opt);
  3249. if (!_nf[key]) _nf[key] = new Intl.NumberFormat(lc, opt);
  3250. return _nf[key];
  3251. }
  3252. function numberFmt(value, lc, arg, defaultCurrency) {
  3253. var _a = arg && arg.split(':') || [],
  3254. type = _a[0],
  3255. currency = _a[1];
  3256. var opt = {
  3257. integer: {
  3258. maximumFractionDigits: 0
  3259. },
  3260. percent: {
  3261. style: 'percent'
  3262. },
  3263. currency: {
  3264. style: 'currency',
  3265. currency: currency && currency.trim() || defaultCurrency,
  3266. minimumFractionDigits: 2,
  3267. maximumFractionDigits: 2
  3268. }
  3269. };
  3270. return nf(lc, opt[type] || {}).format(value);
  3271. }
  3272. var numberCurrency = function (value, lc, arg) {
  3273. return nf(lc, {
  3274. style: 'currency',
  3275. currency: arg,
  3276. minimumFractionDigits: 2,
  3277. maximumFractionDigits: 2
  3278. }).format(value);
  3279. };
  3280. var numberInteger = function (value, lc) {
  3281. return nf(lc, {
  3282. maximumFractionDigits: 0
  3283. }).format(value);
  3284. };
  3285. var numberPercent = function (value, lc) {
  3286. return nf(lc, {
  3287. style: 'percent'
  3288. }).format(value);
  3289. };
  3290. /**
  3291. * Represent a time as a short/default/long string
  3292. *
  3293. * @param value Either a Unix epoch time in milliseconds, or a string value
  3294. * representing a date. Parsed with `new Date(value)`
  3295. *
  3296. * @example
  3297. * ```js
  3298. * var mf = new MessageFormat(['en', 'fi']);
  3299. *
  3300. * mf.compile('The time is now {T, time}')({ T: Date.now() })
  3301. * // 'The time is now 11:26:35 PM'
  3302. *
  3303. * mf.compile('Kello on nyt {T, time}', 'fi')({ T: Date.now() })
  3304. * // 'Kello on nyt 23.26.35'
  3305. *
  3306. * var cf = mf.compile('The Eagle landed at {T, time, full} on {T, date, full}');
  3307. * cf({ T: '1969-07-20 20:17:40 UTC' })
  3308. * // 'The Eagle landed at 10:17:40 PM GMT+2 on Sunday, July 20, 1969'
  3309. * ```
  3310. */
  3311. function time(value, lc, size) {
  3312. var o = {
  3313. second: 'numeric',
  3314. minute: 'numeric',
  3315. hour: 'numeric'
  3316. };
  3317. /* eslint-disable no-fallthrough */
  3318. switch (size) {
  3319. case 'full':
  3320. case 'long':
  3321. o.timeZoneName = 'short';
  3322. break;
  3323. case 'short':
  3324. delete o.second;
  3325. }
  3326. return new Date(value).toLocaleTimeString(lc, o);
  3327. }
  3328. var Formatters = /*#__PURE__*/Object.freeze({
  3329. __proto__: null,
  3330. date: date,
  3331. duration: duration,
  3332. numberCurrency: numberCurrency,
  3333. numberFmt: numberFmt,
  3334. numberInteger: numberInteger,
  3335. numberPercent: numberPercent,
  3336. time: time
  3337. });
  3338. const ES3 = {
  3339. break: true,
  3340. continue: true,
  3341. delete: true,
  3342. else: true,
  3343. for: true,
  3344. function: true,
  3345. if: true,
  3346. in: true,
  3347. new: true,
  3348. return: true,
  3349. this: true,
  3350. typeof: true,
  3351. var: true,
  3352. void: true,
  3353. while: true,
  3354. with: true,
  3355. case: true,
  3356. catch: true,
  3357. default: true,
  3358. do: true,
  3359. finally: true,
  3360. instanceof: true,
  3361. switch: true,
  3362. throw: true,
  3363. try: true
  3364. };
  3365. const ESnext = {
  3366. // in addition to reservedES3
  3367. await: true,
  3368. debugger: true,
  3369. class: true,
  3370. enum: true,
  3371. extends: true,
  3372. super: true,
  3373. const: true,
  3374. export: true,
  3375. import: true,
  3376. null: true,
  3377. true: true,
  3378. false: true,
  3379. implements: true,
  3380. let: true,
  3381. private: true,
  3382. public: true,
  3383. yield: true,
  3384. interface: true,
  3385. package: true,
  3386. protected: true,
  3387. static: true
  3388. };
  3389. var reserved = {
  3390. ES3,
  3391. ESnext
  3392. };
  3393. var reserved$1 = reserved;
  3394. // from https://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/
  3395. function hashCode(str) {
  3396. let hash = 0;
  3397. for (let i = 0; i < str.length; ++i) {
  3398. const char = str.charCodeAt(i);
  3399. hash = (hash << 5) - hash + char;
  3400. hash |= 0; // Convert to 32bit integer
  3401. }
  3402. return hash;
  3403. }
  3404. function identifier(key, unique) {
  3405. if (unique) key += ' ' + hashCode(key).toString(36);
  3406. const id = key.trim().replace(/\W+/g, '_');
  3407. return reserved$1.ES3[id] || reserved$1.ESnext[id] || /^\d/.test(id) ? '_' + id : id;
  3408. }
  3409. function property(obj, key) {
  3410. if (/^[A-Z_$][0-9A-Z_$]*$/i.test(key) && !reserved$1.ES3[key]) {
  3411. return obj ? obj + '.' + key : key;
  3412. } else {
  3413. const jkey = JSON.stringify(key);
  3414. return obj ? obj + '[' + jkey + ']' : jkey;
  3415. }
  3416. }
  3417. var rtlLanguages = [
  3418. 'ar',
  3419. 'ckb',
  3420. 'fa',
  3421. 'he',
  3422. 'ks($|[^bfh])',
  3423. 'lrc',
  3424. 'mzn',
  3425. 'pa-Arab',
  3426. 'ps',
  3427. 'ug',
  3428. 'ur',
  3429. 'uz-Arab',
  3430. 'yi'
  3431. ];
  3432. var rtlRegExp = new RegExp('^' + rtlLanguages.join('|^'));
  3433. function biDiMarkText(text, locale) {
  3434. var isLocaleRTL = rtlRegExp.test(locale);
  3435. var mark = JSON.stringify(isLocaleRTL ? '\u200F' : '\u200E');
  3436. return "".concat(mark, " + ").concat(text, " + ").concat(mark);
  3437. }
  3438. var RUNTIME_MODULE = '@messageformat/runtime';
  3439. var CARDINAL_MODULE = '@messageformat/runtime/lib/cardinals';
  3440. var PLURAL_MODULE = '@messageformat/runtime/lib/plurals';
  3441. var FORMATTER_MODULE = '@messageformat/runtime/lib/formatters';
  3442. var Compiler = (function () {
  3443. function Compiler(options) {
  3444. this.arguments = [];
  3445. this.runtime = {};
  3446. this.options = options;
  3447. }
  3448. Compiler.prototype.compile = function (src, plural, plurals) {
  3449. var e_1, _a;
  3450. var _this = this;
  3451. var _b = this.options, localeCodeFromKey = _b.localeCodeFromKey, requireAllArguments = _b.requireAllArguments, strict = _b.strict, strictPluralKeys = _b.strictPluralKeys;
  3452. if (typeof src === 'object') {
  3453. var result = {};
  3454. try {
  3455. for (var _c = __values(Object.keys(src)), _d = _c.next(); !_d.done; _d = _c.next()) {
  3456. var key = _d.value;
  3457. var lc = localeCodeFromKey ? localeCodeFromKey(key) : key;
  3458. var pl = (plurals && lc && plurals[lc]) || plural;
  3459. result[key] = this.compile(src[key], pl, plurals);
  3460. }
  3461. }
  3462. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  3463. finally {
  3464. try {
  3465. if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
  3466. }
  3467. finally { if (e_1) throw e_1.error; }
  3468. }
  3469. return result;
  3470. }
  3471. this.plural = plural;
  3472. var parserOptions = {
  3473. cardinal: plural.cardinals,
  3474. ordinal: plural.ordinals,
  3475. strict: strict,
  3476. strictPluralKeys: strictPluralKeys
  3477. };
  3478. this.arguments = [];
  3479. var r = parse_1(src, parserOptions).map(function (token) { return _this.token(token, null); });
  3480. var hasArgs = this.arguments.length > 0;
  3481. var res = this.concatenate(r, true);
  3482. if (requireAllArguments && hasArgs) {
  3483. this.setRuntimeFn('reqArgs');
  3484. var reqArgs = JSON.stringify(this.arguments);
  3485. return "(d) => { reqArgs(".concat(reqArgs, ", d); return ").concat(res, "; }");
  3486. }
  3487. return "(".concat(hasArgs ? 'd' : '', ") => ").concat(res);
  3488. };
  3489. Compiler.prototype.cases = function (token, pluralToken) {
  3490. var _this = this;
  3491. var needOther = true;
  3492. var r = token.cases.map(function (_a) {
  3493. var key = _a.key, tokens = _a.tokens;
  3494. if (key === 'other')
  3495. needOther = false;
  3496. var s = tokens.map(function (tok) { return _this.token(tok, pluralToken); });
  3497. return "".concat(property(null, key.replace(/^=/, '')), ": ").concat(_this.concatenate(s, false));
  3498. });
  3499. if (needOther) {
  3500. var type = token.type;
  3501. var _a = this.plural, cardinals = _a.cardinals, ordinals = _a.ordinals;
  3502. if (type === 'select' ||
  3503. (type === 'plural' && cardinals.includes('other')) ||
  3504. (type === 'selectordinal' && ordinals.includes('other')))
  3505. throw new Error("No 'other' form found in ".concat(JSON.stringify(token)));
  3506. }
  3507. return "{ ".concat(r.join(', '), " }");
  3508. };
  3509. Compiler.prototype.concatenate = function (tokens, root) {
  3510. var asValues = this.options.returnType === 'values';
  3511. return asValues && (root || tokens.length > 1)
  3512. ? '[' + tokens.join(', ') + ']'
  3513. : tokens.join(' + ') || '""';
  3514. };
  3515. Compiler.prototype.token = function (token, pluralToken) {
  3516. if (token.type === 'content')
  3517. return JSON.stringify(token.value);
  3518. var _a = this.plural, id = _a.id, lc = _a.lc;
  3519. var args, fn;
  3520. if ('arg' in token) {
  3521. this.arguments.push(token.arg);
  3522. args = [property('d', token.arg)];
  3523. }
  3524. else
  3525. args = [];
  3526. switch (token.type) {
  3527. case 'argument':
  3528. return this.options.biDiSupport
  3529. ? biDiMarkText(String(args[0]), lc)
  3530. : String(args[0]);
  3531. case 'select':
  3532. fn = 'select';
  3533. if (pluralToken && this.options.strict)
  3534. pluralToken = null;
  3535. args.push(this.cases(token, pluralToken));
  3536. this.setRuntimeFn('select');
  3537. break;
  3538. case 'selectordinal':
  3539. fn = 'plural';
  3540. args.push(token.pluralOffset || 0, id, this.cases(token, token), 1);
  3541. this.setLocale(id, true);
  3542. this.setRuntimeFn('plural');
  3543. break;
  3544. case 'plural':
  3545. fn = 'plural';
  3546. args.push(token.pluralOffset || 0, id, this.cases(token, token));
  3547. this.setLocale(id, false);
  3548. this.setRuntimeFn('plural');
  3549. break;
  3550. case 'function':
  3551. if (!this.options.customFormatters[token.key]) {
  3552. if (token.key === 'date') {
  3553. fn = this.setDateFormatter(token, args, pluralToken);
  3554. break;
  3555. }
  3556. else if (token.key === 'number') {
  3557. fn = this.setNumberFormatter(token, args, pluralToken);
  3558. break;
  3559. }
  3560. }
  3561. args.push(JSON.stringify(this.plural.locale));
  3562. if (token.param) {
  3563. if (pluralToken && this.options.strict)
  3564. pluralToken = null;
  3565. var arg = this.getFormatterArg(token, pluralToken);
  3566. if (arg)
  3567. args.push(arg);
  3568. }
  3569. fn = token.key;
  3570. this.setFormatter(fn);
  3571. break;
  3572. case 'octothorpe':
  3573. if (!pluralToken)
  3574. return '"#"';
  3575. args = [
  3576. JSON.stringify(this.plural.locale),
  3577. property('d', pluralToken.arg),
  3578. pluralToken.pluralOffset || 0
  3579. ];
  3580. if (this.options.strict) {
  3581. fn = 'strictNumber';
  3582. args.push(JSON.stringify(pluralToken.arg));
  3583. this.setRuntimeFn('strictNumber');
  3584. }
  3585. else {
  3586. fn = 'number';
  3587. this.setRuntimeFn('number');
  3588. }
  3589. break;
  3590. }
  3591. if (!fn)
  3592. throw new Error('Parser error for token ' + JSON.stringify(token));
  3593. return "".concat(fn, "(").concat(args.join(', '), ")");
  3594. };
  3595. Compiler.prototype.runtimeIncludes = function (key, type) {
  3596. if (identifier(key) !== key)
  3597. throw new SyntaxError("Reserved word used as ".concat(type, " identifier: ").concat(key));
  3598. var prev = this.runtime[key];
  3599. if (!prev || prev.type === type)
  3600. return prev;
  3601. throw new TypeError("Cannot override ".concat(prev.type, " runtime function as ").concat(type, ": ").concat(key));
  3602. };
  3603. Compiler.prototype.setLocale = function (key, ord) {
  3604. var prev = this.runtimeIncludes(key, 'locale');
  3605. var _a = this.plural, getCardinal = _a.getCardinal, getPlural = _a.getPlural, isDefault = _a.isDefault;
  3606. var pf, module, toString;
  3607. if (!ord && isDefault && getCardinal) {
  3608. if (prev)
  3609. return;
  3610. pf = function (n) { return getCardinal(n); };
  3611. module = CARDINAL_MODULE;
  3612. toString = function () { return String(getCardinal); };
  3613. }
  3614. else {
  3615. if (prev && (!isDefault || prev.module === PLURAL_MODULE))
  3616. return;
  3617. pf = function (n, ord) { return getPlural(n, ord); };
  3618. module = isDefault ? PLURAL_MODULE : getPlural.module || null;
  3619. toString = function () { return String(getPlural); };
  3620. }
  3621. this.runtime[key] = Object.assign(pf, {
  3622. id: key,
  3623. module: module,
  3624. toString: toString,
  3625. type: 'locale'
  3626. });
  3627. };
  3628. Compiler.prototype.setRuntimeFn = function (key) {
  3629. if (this.runtimeIncludes(key, 'runtime'))
  3630. return;
  3631. this.runtime[key] = Object.assign(Runtime[key], {
  3632. id: key,
  3633. module: RUNTIME_MODULE,
  3634. type: 'runtime'
  3635. });
  3636. };
  3637. Compiler.prototype.getFormatterArg = function (_a, pluralToken) {
  3638. var e_2, _b, e_3, _c;
  3639. var _this = this;
  3640. var key = _a.key, param = _a.param;
  3641. var fmt = this.options.customFormatters[key] ||
  3642. (isFormatterKey(key) && Formatters[key]);
  3643. if (!fmt || !param)
  3644. return null;
  3645. var argShape = ('arg' in fmt && fmt.arg) || 'string';
  3646. if (argShape === 'options') {
  3647. var value = '';
  3648. try {
  3649. for (var param_1 = __values(param), param_1_1 = param_1.next(); !param_1_1.done; param_1_1 = param_1.next()) {
  3650. var tok = param_1_1.value;
  3651. if (tok.type === 'content')
  3652. value += tok.value;
  3653. else
  3654. throw new SyntaxError("Expected literal options for ".concat(key, " formatter"));
  3655. }
  3656. }
  3657. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  3658. finally {
  3659. try {
  3660. if (param_1_1 && !param_1_1.done && (_b = param_1.return)) _b.call(param_1);
  3661. }
  3662. finally { if (e_2) throw e_2.error; }
  3663. }
  3664. var options = {};
  3665. try {
  3666. for (var _d = __values(value.split(',')), _e = _d.next(); !_e.done; _e = _d.next()) {
  3667. var pair = _e.value;
  3668. var keyEnd = pair.indexOf(':');
  3669. if (keyEnd === -1)
  3670. options[pair.trim()] = null;
  3671. else {
  3672. var k = pair.substring(0, keyEnd).trim();
  3673. var v = pair.substring(keyEnd + 1).trim();
  3674. if (v === 'true')
  3675. options[k] = true;
  3676. else if (v === 'false')
  3677. options[k] = false;
  3678. else if (v === 'null')
  3679. options[k] = null;
  3680. else {
  3681. var n = Number(v);
  3682. options[k] = Number.isFinite(n) ? n : v;
  3683. }
  3684. }
  3685. }
  3686. }
  3687. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  3688. finally {
  3689. try {
  3690. if (_e && !_e.done && (_c = _d.return)) _c.call(_d);
  3691. }
  3692. finally { if (e_3) throw e_3.error; }
  3693. }
  3694. return JSON.stringify(options);
  3695. }
  3696. else {
  3697. var parts = param.map(function (tok) { return _this.token(tok, pluralToken); });
  3698. if (argShape === 'raw')
  3699. return "[".concat(parts.join(', '), "]");
  3700. var s = parts.join(' + ');
  3701. return s ? "(".concat(s, ").trim()") : '""';
  3702. }
  3703. };
  3704. Compiler.prototype.setFormatter = function (key) {
  3705. if (this.runtimeIncludes(key, 'formatter'))
  3706. return;
  3707. var cf = this.options.customFormatters[key];
  3708. if (cf) {
  3709. if (typeof cf === 'function')
  3710. cf = { formatter: cf };
  3711. this.runtime[key] = Object.assign(cf.formatter, { type: 'formatter' }, 'module' in cf && cf.module && cf.id
  3712. ? { id: identifier(cf.id), module: cf.module }
  3713. : { id: null, module: null });
  3714. }
  3715. else if (isFormatterKey(key)) {
  3716. this.runtime[key] = Object.assign(Formatters[key], { type: 'formatter' }, { id: key, module: FORMATTER_MODULE });
  3717. }
  3718. else {
  3719. throw new Error("Formatting function not found: ".concat(key));
  3720. }
  3721. };
  3722. Compiler.prototype.setDateFormatter = function (_a, args, plural) {
  3723. var _this = this;
  3724. var param = _a.param;
  3725. var locale = this.plural.locale;
  3726. var argStyle = param && param.length === 1 && param[0];
  3727. if (argStyle &&
  3728. argStyle.type === 'content' &&
  3729. /^\s*::/.test(argStyle.value)) {
  3730. var argSkeletonText_1 = argStyle.value.trim().substr(2);
  3731. var key = identifier("date_".concat(locale, "_").concat(argSkeletonText_1), true);
  3732. if (!this.runtimeIncludes(key, 'formatter')) {
  3733. var fmt = getDateFormatter(locale, argSkeletonText_1);
  3734. this.runtime[key] = Object.assign(fmt, {
  3735. id: key,
  3736. module: null,
  3737. toString: function () { return getDateFormatterSource(locale, argSkeletonText_1); },
  3738. type: 'formatter'
  3739. });
  3740. }
  3741. return key;
  3742. }
  3743. args.push(JSON.stringify(locale));
  3744. if (param && param.length > 0) {
  3745. if (plural && this.options.strict)
  3746. plural = null;
  3747. var s = param.map(function (tok) { return _this.token(tok, plural); });
  3748. args.push('(' + (s.join(' + ') || '""') + ').trim()');
  3749. }
  3750. this.setFormatter('date');
  3751. return 'date';
  3752. };
  3753. Compiler.prototype.setNumberFormatter = function (_a, args, plural) {
  3754. var _this = this;
  3755. var param = _a.param;
  3756. var locale = this.plural.locale;
  3757. if (!param || param.length === 0) {
  3758. args.unshift(JSON.stringify(locale));
  3759. args.push('0');
  3760. this.setRuntimeFn('number');
  3761. return 'number';
  3762. }
  3763. args.push(JSON.stringify(locale));
  3764. if (param.length === 1 && param[0].type === 'content') {
  3765. var fmtArg_1 = param[0].value.trim();
  3766. switch (fmtArg_1) {
  3767. case 'currency':
  3768. args.push(JSON.stringify(this.options.currency));
  3769. this.setFormatter('numberCurrency');
  3770. return 'numberCurrency';
  3771. case 'integer':
  3772. this.setFormatter('numberInteger');
  3773. return 'numberInteger';
  3774. case 'percent':
  3775. this.setFormatter('numberPercent');
  3776. return 'numberPercent';
  3777. }
  3778. var cm = fmtArg_1.match(/^currency:([A-Z]+)$/);
  3779. if (cm) {
  3780. args.push(JSON.stringify(cm[1]));
  3781. this.setFormatter('numberCurrency');
  3782. return 'numberCurrency';
  3783. }
  3784. var key = identifier("number_".concat(locale, "_").concat(fmtArg_1), true);
  3785. if (!this.runtimeIncludes(key, 'formatter')) {
  3786. var currency_1 = this.options.currency;
  3787. var fmt = getNumberFormatter(locale, fmtArg_1, currency_1);
  3788. this.runtime[key] = Object.assign(fmt, {
  3789. id: null,
  3790. module: null,
  3791. toString: function () { return getNumberFormatterSource(locale, fmtArg_1, currency_1); },
  3792. type: 'formatter'
  3793. });
  3794. }
  3795. return key;
  3796. }
  3797. if (plural && this.options.strict)
  3798. plural = null;
  3799. var s = param.map(function (tok) { return _this.token(tok, plural); });
  3800. args.push('(' + (s.join(' + ') || '""') + ').trim()');
  3801. args.push(JSON.stringify(this.options.currency));
  3802. this.setFormatter('numberFmt');
  3803. return 'numberFmt';
  3804. };
  3805. return Compiler;
  3806. }());
  3807. function isFormatterKey(key) {
  3808. return key in Formatters;
  3809. }
  3810. const a$2 = n => n == 1 ? 'one' : 'other';
  3811. const b$2 = n => n == 0 || n == 1 ? 'one' : 'other';
  3812. const c$2 = n => n >= 0 && n <= 1 ? 'one' : 'other';
  3813. const d$2 = n => {
  3814. const s = String(n).split('.'),
  3815. v0 = !s[1];
  3816. return n == 1 && v0 ? 'one' : 'other';
  3817. };
  3818. const e$1 = n => 'other';
  3819. const f$2 = n => n == 1 ? 'one' : n == 2 ? 'two' : 'other';
  3820. const af$2 = a$2;
  3821. const ak$2 = b$2;
  3822. const am$2 = c$2;
  3823. const an$2 = a$2;
  3824. const ar$2 = n => {
  3825. const s = String(n).split('.'),
  3826. t0 = Number(s[0]) == n,
  3827. n100 = t0 && s[0].slice(-2);
  3828. return n == 0 ? 'zero' : n == 1 ? 'one' : n == 2 ? 'two' : n100 >= 3 && n100 <= 10 ? 'few' : n100 >= 11 && n100 <= 99 ? 'many' : 'other';
  3829. };
  3830. const ars$2 = n => {
  3831. const s = String(n).split('.'),
  3832. t0 = Number(s[0]) == n,
  3833. n100 = t0 && s[0].slice(-2);
  3834. return n == 0 ? 'zero' : n == 1 ? 'one' : n == 2 ? 'two' : n100 >= 3 && n100 <= 10 ? 'few' : n100 >= 11 && n100 <= 99 ? 'many' : 'other';
  3835. };
  3836. const as$2 = c$2;
  3837. const asa$2 = a$2;
  3838. const ast$2 = d$2;
  3839. const az$2 = a$2;
  3840. const bal$2 = a$2;
  3841. const be$2 = n => {
  3842. const s = String(n).split('.'),
  3843. t0 = Number(s[0]) == n,
  3844. n10 = t0 && s[0].slice(-1),
  3845. n100 = t0 && s[0].slice(-2);
  3846. return n10 == 1 && n100 != 11 ? 'one' : n10 >= 2 && n10 <= 4 && (n100 < 12 || n100 > 14) ? 'few' : t0 && n10 == 0 || n10 >= 5 && n10 <= 9 || n100 >= 11 && n100 <= 14 ? 'many' : 'other';
  3847. };
  3848. const bem$2 = a$2;
  3849. const bez$2 = a$2;
  3850. const bg$2 = a$2;
  3851. const bho$2 = b$2;
  3852. const bm$2 = e$1;
  3853. const bn$2 = c$2;
  3854. const bo$2 = e$1;
  3855. const br$2 = n => {
  3856. const s = String(n).split('.'),
  3857. t0 = Number(s[0]) == n,
  3858. n10 = t0 && s[0].slice(-1),
  3859. n100 = t0 && s[0].slice(-2),
  3860. n1000000 = t0 && s[0].slice(-6);
  3861. return n10 == 1 && n100 != 11 && n100 != 71 && n100 != 91 ? 'one' : n10 == 2 && n100 != 12 && n100 != 72 && n100 != 92 ? 'two' : (n10 == 3 || n10 == 4 || n10 == 9) && (n100 < 10 || n100 > 19) && (n100 < 70 || n100 > 79) && (n100 < 90 || n100 > 99) ? 'few' : n != 0 && t0 && n1000000 == 0 ? 'many' : 'other';
  3862. };
  3863. const brx$2 = a$2;
  3864. const bs$2 = n => {
  3865. const s = String(n).split('.'),
  3866. i = s[0],
  3867. f = s[1] || '',
  3868. v0 = !s[1],
  3869. i10 = i.slice(-1),
  3870. i100 = i.slice(-2),
  3871. f10 = f.slice(-1),
  3872. f100 = f.slice(-2);
  3873. return v0 && i10 == 1 && i100 != 11 || f10 == 1 && f100 != 11 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) || f10 >= 2 && f10 <= 4 && (f100 < 12 || f100 > 14) ? 'few' : 'other';
  3874. };
  3875. const ca$2 = n => {
  3876. const s = String(n).split('.'),
  3877. i = s[0],
  3878. v0 = !s[1],
  3879. i1000000 = i.slice(-6);
  3880. return n == 1 && v0 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
  3881. };
  3882. const ce$2 = a$2;
  3883. const ceb$2 = n => {
  3884. const s = String(n).split('.'),
  3885. i = s[0],
  3886. f = s[1] || '',
  3887. v0 = !s[1],
  3888. i10 = i.slice(-1),
  3889. f10 = f.slice(-1);
  3890. return v0 && (i == 1 || i == 2 || i == 3) || v0 && i10 != 4 && i10 != 6 && i10 != 9 || !v0 && f10 != 4 && f10 != 6 && f10 != 9 ? 'one' : 'other';
  3891. };
  3892. const cgg$2 = a$2;
  3893. const chr$2 = a$2;
  3894. const ckb$2 = a$2;
  3895. const cs$2 = n => {
  3896. const s = String(n).split('.'),
  3897. i = s[0],
  3898. v0 = !s[1];
  3899. return n == 1 && v0 ? 'one' : i >= 2 && i <= 4 && v0 ? 'few' : !v0 ? 'many' : 'other';
  3900. };
  3901. const cy$2 = n => n == 0 ? 'zero' : n == 1 ? 'one' : n == 2 ? 'two' : n == 3 ? 'few' : n == 6 ? 'many' : 'other';
  3902. const da$2 = n => {
  3903. const s = String(n).split('.'),
  3904. i = s[0],
  3905. t0 = Number(s[0]) == n;
  3906. return n == 1 || !t0 && (i == 0 || i == 1) ? 'one' : 'other';
  3907. };
  3908. const de$2 = d$2;
  3909. const doi$2 = c$2;
  3910. const dsb$2 = n => {
  3911. const s = String(n).split('.'),
  3912. i = s[0],
  3913. f = s[1] || '',
  3914. v0 = !s[1],
  3915. i100 = i.slice(-2),
  3916. f100 = f.slice(-2);
  3917. return v0 && i100 == 1 || f100 == 1 ? 'one' : v0 && i100 == 2 || f100 == 2 ? 'two' : v0 && (i100 == 3 || i100 == 4) || f100 == 3 || f100 == 4 ? 'few' : 'other';
  3918. };
  3919. const dv$2 = a$2;
  3920. const dz$2 = e$1;
  3921. const ee$2 = a$2;
  3922. const el$2 = a$2;
  3923. const en$2 = d$2;
  3924. const eo$2 = a$2;
  3925. const es$2 = n => {
  3926. const s = String(n).split('.'),
  3927. i = s[0],
  3928. v0 = !s[1],
  3929. i1000000 = i.slice(-6);
  3930. return n == 1 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
  3931. };
  3932. const et$2 = d$2;
  3933. const eu$2 = a$2;
  3934. const fa$2 = c$2;
  3935. const ff$2 = n => n >= 0 && n < 2 ? 'one' : 'other';
  3936. const fi$2 = d$2;
  3937. const fil$2 = n => {
  3938. const s = String(n).split('.'),
  3939. i = s[0],
  3940. f = s[1] || '',
  3941. v0 = !s[1],
  3942. i10 = i.slice(-1),
  3943. f10 = f.slice(-1);
  3944. return v0 && (i == 1 || i == 2 || i == 3) || v0 && i10 != 4 && i10 != 6 && i10 != 9 || !v0 && f10 != 4 && f10 != 6 && f10 != 9 ? 'one' : 'other';
  3945. };
  3946. const fo$2 = a$2;
  3947. const fr$2 = n => {
  3948. const s = String(n).split('.'),
  3949. i = s[0],
  3950. v0 = !s[1],
  3951. i1000000 = i.slice(-6);
  3952. return n >= 0 && n < 2 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
  3953. };
  3954. const fur$2 = a$2;
  3955. const fy$2 = d$2;
  3956. const ga$2 = n => {
  3957. const s = String(n).split('.'),
  3958. t0 = Number(s[0]) == n;
  3959. return n == 1 ? 'one' : n == 2 ? 'two' : t0 && n >= 3 && n <= 6 ? 'few' : t0 && n >= 7 && n <= 10 ? 'many' : 'other';
  3960. };
  3961. const gd$2 = n => {
  3962. const s = String(n).split('.'),
  3963. t0 = Number(s[0]) == n;
  3964. return n == 1 || n == 11 ? 'one' : n == 2 || n == 12 ? 'two' : t0 && n >= 3 && n <= 10 || t0 && n >= 13 && n <= 19 ? 'few' : 'other';
  3965. };
  3966. const gl$2 = d$2;
  3967. const gsw$2 = a$2;
  3968. const gu$2 = c$2;
  3969. const guw$2 = b$2;
  3970. const gv$2 = n => {
  3971. const s = String(n).split('.'),
  3972. i = s[0],
  3973. v0 = !s[1],
  3974. i10 = i.slice(-1),
  3975. i100 = i.slice(-2);
  3976. return v0 && i10 == 1 ? 'one' : v0 && i10 == 2 ? 'two' : v0 && (i100 == 0 || i100 == 20 || i100 == 40 || i100 == 60 || i100 == 80) ? 'few' : !v0 ? 'many' : 'other';
  3977. };
  3978. const ha$2 = a$2;
  3979. const haw$2 = a$2;
  3980. const he$2 = n => {
  3981. const s = String(n).split('.'),
  3982. i = s[0],
  3983. v0 = !s[1];
  3984. return i == 1 && v0 || i == 0 && !v0 ? 'one' : i == 2 && v0 ? 'two' : 'other';
  3985. };
  3986. const hi$2 = c$2;
  3987. const hnj$2 = e$1;
  3988. const hr$2 = n => {
  3989. const s = String(n).split('.'),
  3990. i = s[0],
  3991. f = s[1] || '',
  3992. v0 = !s[1],
  3993. i10 = i.slice(-1),
  3994. i100 = i.slice(-2),
  3995. f10 = f.slice(-1),
  3996. f100 = f.slice(-2);
  3997. return v0 && i10 == 1 && i100 != 11 || f10 == 1 && f100 != 11 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) || f10 >= 2 && f10 <= 4 && (f100 < 12 || f100 > 14) ? 'few' : 'other';
  3998. };
  3999. const hsb$2 = n => {
  4000. const s = String(n).split('.'),
  4001. i = s[0],
  4002. f = s[1] || '',
  4003. v0 = !s[1],
  4004. i100 = i.slice(-2),
  4005. f100 = f.slice(-2);
  4006. return v0 && i100 == 1 || f100 == 1 ? 'one' : v0 && i100 == 2 || f100 == 2 ? 'two' : v0 && (i100 == 3 || i100 == 4) || f100 == 3 || f100 == 4 ? 'few' : 'other';
  4007. };
  4008. const hu$2 = a$2;
  4009. const hy$2 = n => n >= 0 && n < 2 ? 'one' : 'other';
  4010. const ia$2 = d$2;
  4011. const id$2 = e$1;
  4012. const ig$2 = e$1;
  4013. const ii$2 = e$1;
  4014. const io$2 = d$2;
  4015. const is$2 = n => {
  4016. const s = String(n).split('.'),
  4017. i = s[0],
  4018. t = (s[1] || '').replace(/0+$/, ''),
  4019. t0 = Number(s[0]) == n,
  4020. i10 = i.slice(-1),
  4021. i100 = i.slice(-2);
  4022. return t0 && i10 == 1 && i100 != 11 || t % 10 == 1 && t % 100 != 11 ? 'one' : 'other';
  4023. };
  4024. const it$2 = n => {
  4025. const s = String(n).split('.'),
  4026. i = s[0],
  4027. v0 = !s[1],
  4028. i1000000 = i.slice(-6);
  4029. return n == 1 && v0 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
  4030. };
  4031. const iu$2 = f$2;
  4032. const ja$2 = e$1;
  4033. const jbo$2 = e$1;
  4034. const jgo$2 = a$2;
  4035. const jmc$2 = a$2;
  4036. const jv$2 = e$1;
  4037. const jw$2 = e$1;
  4038. const ka$2 = a$2;
  4039. const kab$2 = n => n >= 0 && n < 2 ? 'one' : 'other';
  4040. const kaj$2 = a$2;
  4041. const kcg$2 = a$2;
  4042. const kde$2 = e$1;
  4043. const kea$2 = e$1;
  4044. const kk$2 = a$2;
  4045. const kkj$2 = a$2;
  4046. const kl$2 = a$2;
  4047. const km$2 = e$1;
  4048. const kn$2 = c$2;
  4049. const ko$2 = e$1;
  4050. const ks$2 = a$2;
  4051. const ksb$2 = a$2;
  4052. const ksh$2 = n => n == 0 ? 'zero' : n == 1 ? 'one' : 'other';
  4053. const ku$2 = a$2;
  4054. const kw$2 = n => {
  4055. const s = String(n).split('.'),
  4056. t0 = Number(s[0]) == n,
  4057. n100 = t0 && s[0].slice(-2),
  4058. n1000 = t0 && s[0].slice(-3),
  4059. n100000 = t0 && s[0].slice(-5),
  4060. n1000000 = t0 && s[0].slice(-6);
  4061. return n == 0 ? 'zero' : n == 1 ? 'one' : n100 == 2 || n100 == 22 || n100 == 42 || n100 == 62 || n100 == 82 || t0 && n1000 == 0 && (n100000 >= 1000 && n100000 <= 20000 || n100000 == 40000 || n100000 == 60000 || n100000 == 80000) || n != 0 && n1000000 == 100000 ? 'two' : n100 == 3 || n100 == 23 || n100 == 43 || n100 == 63 || n100 == 83 ? 'few' : n != 1 && (n100 == 1 || n100 == 21 || n100 == 41 || n100 == 61 || n100 == 81) ? 'many' : 'other';
  4062. };
  4063. const ky$2 = a$2;
  4064. const lag$2 = n => {
  4065. const s = String(n).split('.'),
  4066. i = s[0];
  4067. return n == 0 ? 'zero' : (i == 0 || i == 1) && n != 0 ? 'one' : 'other';
  4068. };
  4069. const lb$2 = a$2;
  4070. const lg$2 = a$2;
  4071. const lij$2 = d$2;
  4072. const lkt$2 = e$1;
  4073. const ln$2 = b$2;
  4074. const lo$2 = e$1;
  4075. const lt$2 = n => {
  4076. const s = String(n).split('.'),
  4077. f = s[1] || '',
  4078. t0 = Number(s[0]) == n,
  4079. n10 = t0 && s[0].slice(-1),
  4080. n100 = t0 && s[0].slice(-2);
  4081. return n10 == 1 && (n100 < 11 || n100 > 19) ? 'one' : n10 >= 2 && n10 <= 9 && (n100 < 11 || n100 > 19) ? 'few' : f != 0 ? 'many' : 'other';
  4082. };
  4083. const lv$2 = n => {
  4084. const s = String(n).split('.'),
  4085. f = s[1] || '',
  4086. v = f.length,
  4087. t0 = Number(s[0]) == n,
  4088. n10 = t0 && s[0].slice(-1),
  4089. n100 = t0 && s[0].slice(-2),
  4090. f100 = f.slice(-2),
  4091. f10 = f.slice(-1);
  4092. return t0 && n10 == 0 || n100 >= 11 && n100 <= 19 || v == 2 && f100 >= 11 && f100 <= 19 ? 'zero' : n10 == 1 && n100 != 11 || v == 2 && f10 == 1 && f100 != 11 || v != 2 && f10 == 1 ? 'one' : 'other';
  4093. };
  4094. const mas$2 = a$2;
  4095. const mg$2 = b$2;
  4096. const mgo$2 = a$2;
  4097. const mk$2 = n => {
  4098. const s = String(n).split('.'),
  4099. i = s[0],
  4100. f = s[1] || '',
  4101. v0 = !s[1],
  4102. i10 = i.slice(-1),
  4103. i100 = i.slice(-2),
  4104. f10 = f.slice(-1),
  4105. f100 = f.slice(-2);
  4106. return v0 && i10 == 1 && i100 != 11 || f10 == 1 && f100 != 11 ? 'one' : 'other';
  4107. };
  4108. const ml$2 = a$2;
  4109. const mn$2 = a$2;
  4110. const mo$2 = n => {
  4111. const s = String(n).split('.'),
  4112. v0 = !s[1],
  4113. t0 = Number(s[0]) == n,
  4114. n100 = t0 && s[0].slice(-2);
  4115. return n == 1 && v0 ? 'one' : !v0 || n == 0 || n != 1 && n100 >= 1 && n100 <= 19 ? 'few' : 'other';
  4116. };
  4117. const mr$2 = a$2;
  4118. const ms$2 = e$1;
  4119. const mt$2 = n => {
  4120. const s = String(n).split('.'),
  4121. t0 = Number(s[0]) == n,
  4122. n100 = t0 && s[0].slice(-2);
  4123. return n == 1 ? 'one' : n == 2 ? 'two' : n == 0 || n100 >= 3 && n100 <= 10 ? 'few' : n100 >= 11 && n100 <= 19 ? 'many' : 'other';
  4124. };
  4125. const my$2 = e$1;
  4126. const nah$2 = a$2;
  4127. const naq$2 = f$2;
  4128. const nb$2 = a$2;
  4129. const nd$2 = a$2;
  4130. const ne$2 = a$2;
  4131. const nl$2 = d$2;
  4132. const nn$2 = a$2;
  4133. const nnh$2 = a$2;
  4134. const no$2 = a$2;
  4135. const nqo$2 = e$1;
  4136. const nr$2 = a$2;
  4137. const nso$2 = b$2;
  4138. const ny$2 = a$2;
  4139. const nyn$2 = a$2;
  4140. const om$2 = a$2;
  4141. const or$2 = a$2;
  4142. const os$2 = a$2;
  4143. const osa$2 = e$1;
  4144. const pa$2 = b$2;
  4145. const pap$2 = a$2;
  4146. const pcm$2 = c$2;
  4147. const pl$2 = n => {
  4148. const s = String(n).split('.'),
  4149. i = s[0],
  4150. v0 = !s[1],
  4151. i10 = i.slice(-1),
  4152. i100 = i.slice(-2);
  4153. return n == 1 && v0 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) ? 'few' : v0 && i != 1 && (i10 == 0 || i10 == 1) || v0 && i10 >= 5 && i10 <= 9 || v0 && i100 >= 12 && i100 <= 14 ? 'many' : 'other';
  4154. };
  4155. const prg$2 = n => {
  4156. const s = String(n).split('.'),
  4157. f = s[1] || '',
  4158. v = f.length,
  4159. t0 = Number(s[0]) == n,
  4160. n10 = t0 && s[0].slice(-1),
  4161. n100 = t0 && s[0].slice(-2),
  4162. f100 = f.slice(-2),
  4163. f10 = f.slice(-1);
  4164. return t0 && n10 == 0 || n100 >= 11 && n100 <= 19 || v == 2 && f100 >= 11 && f100 <= 19 ? 'zero' : n10 == 1 && n100 != 11 || v == 2 && f10 == 1 && f100 != 11 || v != 2 && f10 == 1 ? 'one' : 'other';
  4165. };
  4166. const ps$2 = a$2;
  4167. const pt$2 = n => {
  4168. const s = String(n).split('.'),
  4169. i = s[0],
  4170. v0 = !s[1],
  4171. i1000000 = i.slice(-6);
  4172. return i == 0 || i == 1 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
  4173. };
  4174. const pt_PT$2 = n => {
  4175. const s = String(n).split('.'),
  4176. i = s[0],
  4177. v0 = !s[1],
  4178. i1000000 = i.slice(-6);
  4179. return n == 1 && v0 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
  4180. };
  4181. const rm$2 = a$2;
  4182. const ro$2 = n => {
  4183. const s = String(n).split('.'),
  4184. v0 = !s[1],
  4185. t0 = Number(s[0]) == n,
  4186. n100 = t0 && s[0].slice(-2);
  4187. return n == 1 && v0 ? 'one' : !v0 || n == 0 || n != 1 && n100 >= 1 && n100 <= 19 ? 'few' : 'other';
  4188. };
  4189. const rof$2 = a$2;
  4190. const ru$2 = n => {
  4191. const s = String(n).split('.'),
  4192. i = s[0],
  4193. v0 = !s[1],
  4194. i10 = i.slice(-1),
  4195. i100 = i.slice(-2);
  4196. return v0 && i10 == 1 && i100 != 11 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) ? 'few' : v0 && i10 == 0 || v0 && i10 >= 5 && i10 <= 9 || v0 && i100 >= 11 && i100 <= 14 ? 'many' : 'other';
  4197. };
  4198. const rwk$2 = a$2;
  4199. const sah$2 = e$1;
  4200. const saq$2 = a$2;
  4201. const sat$2 = f$2;
  4202. const sc$2 = d$2;
  4203. const scn$2 = d$2;
  4204. const sd$2 = a$2;
  4205. const sdh$2 = a$2;
  4206. const se$2 = f$2;
  4207. const seh$2 = a$2;
  4208. const ses$2 = e$1;
  4209. const sg$2 = e$1;
  4210. const sh$2 = n => {
  4211. const s = String(n).split('.'),
  4212. i = s[0],
  4213. f = s[1] || '',
  4214. v0 = !s[1],
  4215. i10 = i.slice(-1),
  4216. i100 = i.slice(-2),
  4217. f10 = f.slice(-1),
  4218. f100 = f.slice(-2);
  4219. return v0 && i10 == 1 && i100 != 11 || f10 == 1 && f100 != 11 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) || f10 >= 2 && f10 <= 4 && (f100 < 12 || f100 > 14) ? 'few' : 'other';
  4220. };
  4221. const shi$2 = n => {
  4222. const s = String(n).split('.'),
  4223. t0 = Number(s[0]) == n;
  4224. return n >= 0 && n <= 1 ? 'one' : t0 && n >= 2 && n <= 10 ? 'few' : 'other';
  4225. };
  4226. const si$2 = n => {
  4227. const s = String(n).split('.'),
  4228. i = s[0],
  4229. f = s[1] || '';
  4230. return n == 0 || n == 1 || i == 0 && f == 1 ? 'one' : 'other';
  4231. };
  4232. const sk$2 = n => {
  4233. const s = String(n).split('.'),
  4234. i = s[0],
  4235. v0 = !s[1];
  4236. return n == 1 && v0 ? 'one' : i >= 2 && i <= 4 && v0 ? 'few' : !v0 ? 'many' : 'other';
  4237. };
  4238. const sl$2 = n => {
  4239. const s = String(n).split('.'),
  4240. i = s[0],
  4241. v0 = !s[1],
  4242. i100 = i.slice(-2);
  4243. return v0 && i100 == 1 ? 'one' : v0 && i100 == 2 ? 'two' : v0 && (i100 == 3 || i100 == 4) || !v0 ? 'few' : 'other';
  4244. };
  4245. const sma$2 = f$2;
  4246. const smi$2 = f$2;
  4247. const smj$2 = f$2;
  4248. const smn$2 = f$2;
  4249. const sms$2 = f$2;
  4250. const sn$2 = a$2;
  4251. const so$2 = a$2;
  4252. const sq$2 = a$2;
  4253. const sr$2 = n => {
  4254. const s = String(n).split('.'),
  4255. i = s[0],
  4256. f = s[1] || '',
  4257. v0 = !s[1],
  4258. i10 = i.slice(-1),
  4259. i100 = i.slice(-2),
  4260. f10 = f.slice(-1),
  4261. f100 = f.slice(-2);
  4262. return v0 && i10 == 1 && i100 != 11 || f10 == 1 && f100 != 11 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) || f10 >= 2 && f10 <= 4 && (f100 < 12 || f100 > 14) ? 'few' : 'other';
  4263. };
  4264. const ss$2 = a$2;
  4265. const ssy$2 = a$2;
  4266. const st$2 = a$2;
  4267. const su$2 = e$1;
  4268. const sv$2 = d$2;
  4269. const sw$2 = d$2;
  4270. const syr$2 = a$2;
  4271. const ta$2 = a$2;
  4272. const te$2 = a$2;
  4273. const teo$2 = a$2;
  4274. const th$2 = e$1;
  4275. const ti$2 = b$2;
  4276. const tig$2 = a$2;
  4277. const tk$2 = a$2;
  4278. const tl$2 = n => {
  4279. const s = String(n).split('.'),
  4280. i = s[0],
  4281. f = s[1] || '',
  4282. v0 = !s[1],
  4283. i10 = i.slice(-1),
  4284. f10 = f.slice(-1);
  4285. return v0 && (i == 1 || i == 2 || i == 3) || v0 && i10 != 4 && i10 != 6 && i10 != 9 || !v0 && f10 != 4 && f10 != 6 && f10 != 9 ? 'one' : 'other';
  4286. };
  4287. const tn$2 = a$2;
  4288. const to$2 = e$1;
  4289. const tpi$2 = e$1;
  4290. const tr$2 = a$2;
  4291. const ts$2 = a$2;
  4292. const tzm$2 = n => {
  4293. const s = String(n).split('.'),
  4294. t0 = Number(s[0]) == n;
  4295. return n == 0 || n == 1 || t0 && n >= 11 && n <= 99 ? 'one' : 'other';
  4296. };
  4297. const ug$2 = a$2;
  4298. const uk$2 = n => {
  4299. const s = String(n).split('.'),
  4300. i = s[0],
  4301. v0 = !s[1],
  4302. i10 = i.slice(-1),
  4303. i100 = i.slice(-2);
  4304. return v0 && i10 == 1 && i100 != 11 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) ? 'few' : v0 && i10 == 0 || v0 && i10 >= 5 && i10 <= 9 || v0 && i100 >= 11 && i100 <= 14 ? 'many' : 'other';
  4305. };
  4306. const und$2 = e$1;
  4307. const ur$2 = d$2;
  4308. const uz$2 = a$2;
  4309. const ve$2 = a$2;
  4310. const vec$2 = n => {
  4311. const s = String(n).split('.'),
  4312. i = s[0],
  4313. v0 = !s[1],
  4314. i1000000 = i.slice(-6);
  4315. return n == 1 && v0 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
  4316. };
  4317. const vi$2 = e$1;
  4318. const vo$2 = a$2;
  4319. const vun$2 = a$2;
  4320. const wa$2 = b$2;
  4321. const wae$2 = a$2;
  4322. const wo$2 = e$1;
  4323. const xh$2 = a$2;
  4324. const xog$2 = a$2;
  4325. const yi$2 = d$2;
  4326. const yo$2 = e$1;
  4327. const yue$2 = e$1;
  4328. const zh$2 = e$1;
  4329. const zu$2 = c$2;
  4330. var Cardinals = /*#__PURE__*/Object.freeze({
  4331. __proto__: null,
  4332. af: af$2,
  4333. ak: ak$2,
  4334. am: am$2,
  4335. an: an$2,
  4336. ar: ar$2,
  4337. ars: ars$2,
  4338. as: as$2,
  4339. asa: asa$2,
  4340. ast: ast$2,
  4341. az: az$2,
  4342. bal: bal$2,
  4343. be: be$2,
  4344. bem: bem$2,
  4345. bez: bez$2,
  4346. bg: bg$2,
  4347. bho: bho$2,
  4348. bm: bm$2,
  4349. bn: bn$2,
  4350. bo: bo$2,
  4351. br: br$2,
  4352. brx: brx$2,
  4353. bs: bs$2,
  4354. ca: ca$2,
  4355. ce: ce$2,
  4356. ceb: ceb$2,
  4357. cgg: cgg$2,
  4358. chr: chr$2,
  4359. ckb: ckb$2,
  4360. cs: cs$2,
  4361. cy: cy$2,
  4362. da: da$2,
  4363. de: de$2,
  4364. doi: doi$2,
  4365. dsb: dsb$2,
  4366. dv: dv$2,
  4367. dz: dz$2,
  4368. ee: ee$2,
  4369. el: el$2,
  4370. en: en$2,
  4371. eo: eo$2,
  4372. es: es$2,
  4373. et: et$2,
  4374. eu: eu$2,
  4375. fa: fa$2,
  4376. ff: ff$2,
  4377. fi: fi$2,
  4378. fil: fil$2,
  4379. fo: fo$2,
  4380. fr: fr$2,
  4381. fur: fur$2,
  4382. fy: fy$2,
  4383. ga: ga$2,
  4384. gd: gd$2,
  4385. gl: gl$2,
  4386. gsw: gsw$2,
  4387. gu: gu$2,
  4388. guw: guw$2,
  4389. gv: gv$2,
  4390. ha: ha$2,
  4391. haw: haw$2,
  4392. he: he$2,
  4393. hi: hi$2,
  4394. hnj: hnj$2,
  4395. hr: hr$2,
  4396. hsb: hsb$2,
  4397. hu: hu$2,
  4398. hy: hy$2,
  4399. ia: ia$2,
  4400. id: id$2,
  4401. ig: ig$2,
  4402. ii: ii$2,
  4403. io: io$2,
  4404. is: is$2,
  4405. it: it$2,
  4406. iu: iu$2,
  4407. ja: ja$2,
  4408. jbo: jbo$2,
  4409. jgo: jgo$2,
  4410. jmc: jmc$2,
  4411. jv: jv$2,
  4412. jw: jw$2,
  4413. ka: ka$2,
  4414. kab: kab$2,
  4415. kaj: kaj$2,
  4416. kcg: kcg$2,
  4417. kde: kde$2,
  4418. kea: kea$2,
  4419. kk: kk$2,
  4420. kkj: kkj$2,
  4421. kl: kl$2,
  4422. km: km$2,
  4423. kn: kn$2,
  4424. ko: ko$2,
  4425. ks: ks$2,
  4426. ksb: ksb$2,
  4427. ksh: ksh$2,
  4428. ku: ku$2,
  4429. kw: kw$2,
  4430. ky: ky$2,
  4431. lag: lag$2,
  4432. lb: lb$2,
  4433. lg: lg$2,
  4434. lij: lij$2,
  4435. lkt: lkt$2,
  4436. ln: ln$2,
  4437. lo: lo$2,
  4438. lt: lt$2,
  4439. lv: lv$2,
  4440. mas: mas$2,
  4441. mg: mg$2,
  4442. mgo: mgo$2,
  4443. mk: mk$2,
  4444. ml: ml$2,
  4445. mn: mn$2,
  4446. mo: mo$2,
  4447. mr: mr$2,
  4448. ms: ms$2,
  4449. mt: mt$2,
  4450. my: my$2,
  4451. nah: nah$2,
  4452. naq: naq$2,
  4453. nb: nb$2,
  4454. nd: nd$2,
  4455. ne: ne$2,
  4456. nl: nl$2,
  4457. nn: nn$2,
  4458. nnh: nnh$2,
  4459. no: no$2,
  4460. nqo: nqo$2,
  4461. nr: nr$2,
  4462. nso: nso$2,
  4463. ny: ny$2,
  4464. nyn: nyn$2,
  4465. om: om$2,
  4466. or: or$2,
  4467. os: os$2,
  4468. osa: osa$2,
  4469. pa: pa$2,
  4470. pap: pap$2,
  4471. pcm: pcm$2,
  4472. pl: pl$2,
  4473. prg: prg$2,
  4474. ps: ps$2,
  4475. pt: pt$2,
  4476. pt_PT: pt_PT$2,
  4477. rm: rm$2,
  4478. ro: ro$2,
  4479. rof: rof$2,
  4480. ru: ru$2,
  4481. rwk: rwk$2,
  4482. sah: sah$2,
  4483. saq: saq$2,
  4484. sat: sat$2,
  4485. sc: sc$2,
  4486. scn: scn$2,
  4487. sd: sd$2,
  4488. sdh: sdh$2,
  4489. se: se$2,
  4490. seh: seh$2,
  4491. ses: ses$2,
  4492. sg: sg$2,
  4493. sh: sh$2,
  4494. shi: shi$2,
  4495. si: si$2,
  4496. sk: sk$2,
  4497. sl: sl$2,
  4498. sma: sma$2,
  4499. smi: smi$2,
  4500. smj: smj$2,
  4501. smn: smn$2,
  4502. sms: sms$2,
  4503. sn: sn$2,
  4504. so: so$2,
  4505. sq: sq$2,
  4506. sr: sr$2,
  4507. ss: ss$2,
  4508. ssy: ssy$2,
  4509. st: st$2,
  4510. su: su$2,
  4511. sv: sv$2,
  4512. sw: sw$2,
  4513. syr: syr$2,
  4514. ta: ta$2,
  4515. te: te$2,
  4516. teo: teo$2,
  4517. th: th$2,
  4518. ti: ti$2,
  4519. tig: tig$2,
  4520. tk: tk$2,
  4521. tl: tl$2,
  4522. tn: tn$2,
  4523. to: to$2,
  4524. tpi: tpi$2,
  4525. tr: tr$2,
  4526. ts: ts$2,
  4527. tzm: tzm$2,
  4528. ug: ug$2,
  4529. uk: uk$2,
  4530. und: und$2,
  4531. ur: ur$2,
  4532. uz: uz$2,
  4533. ve: ve$2,
  4534. vec: vec$2,
  4535. vi: vi$2,
  4536. vo: vo$2,
  4537. vun: vun$2,
  4538. wa: wa$2,
  4539. wae: wae$2,
  4540. wo: wo$2,
  4541. xh: xh$2,
  4542. xog: xog$2,
  4543. yi: yi$2,
  4544. yo: yo$2,
  4545. yue: yue$2,
  4546. zh: zh$2,
  4547. zu: zu$2
  4548. });
  4549. const z = "zero",
  4550. o = "one",
  4551. t = "two",
  4552. f$1 = "few",
  4553. m = "many",
  4554. x = "other";
  4555. const a$1 = {
  4556. cardinal: [o, x],
  4557. ordinal: [x]
  4558. };
  4559. const b$1 = {
  4560. cardinal: [o, x],
  4561. ordinal: [o, x]
  4562. };
  4563. const c$1 = {
  4564. cardinal: [x],
  4565. ordinal: [x]
  4566. };
  4567. const d$1 = {
  4568. cardinal: [o, t, x],
  4569. ordinal: [x]
  4570. };
  4571. const af$1 = a$1;
  4572. const ak$1 = a$1;
  4573. const am$1 = a$1;
  4574. const an$1 = a$1;
  4575. const ar$1 = {
  4576. cardinal: [z, o, t, f$1, m, x],
  4577. ordinal: [x]
  4578. };
  4579. const ars$1 = {
  4580. cardinal: [z, o, t, f$1, m, x],
  4581. ordinal: [x]
  4582. };
  4583. const as$1 = {
  4584. cardinal: [o, x],
  4585. ordinal: [o, t, f$1, m, x]
  4586. };
  4587. const asa$1 = a$1;
  4588. const ast$1 = a$1;
  4589. const az$1 = {
  4590. cardinal: [o, x],
  4591. ordinal: [o, f$1, m, x]
  4592. };
  4593. const bal$1 = b$1;
  4594. const be$1 = {
  4595. cardinal: [o, f$1, m, x],
  4596. ordinal: [f$1, x]
  4597. };
  4598. const bem$1 = a$1;
  4599. const bez$1 = a$1;
  4600. const bg$1 = a$1;
  4601. const bho$1 = a$1;
  4602. const bm$1 = c$1;
  4603. const bn$1 = {
  4604. cardinal: [o, x],
  4605. ordinal: [o, t, f$1, m, x]
  4606. };
  4607. const bo$1 = c$1;
  4608. const br$1 = {
  4609. cardinal: [o, t, f$1, m, x],
  4610. ordinal: [x]
  4611. };
  4612. const brx$1 = a$1;
  4613. const bs$1 = {
  4614. cardinal: [o, f$1, x],
  4615. ordinal: [x]
  4616. };
  4617. const ca$1 = {
  4618. cardinal: [o, m, x],
  4619. ordinal: [o, t, f$1, x]
  4620. };
  4621. const ce$1 = a$1;
  4622. const ceb$1 = a$1;
  4623. const cgg$1 = a$1;
  4624. const chr$1 = a$1;
  4625. const ckb$1 = a$1;
  4626. const cs$1 = {
  4627. cardinal: [o, f$1, m, x],
  4628. ordinal: [x]
  4629. };
  4630. const cy$1 = {
  4631. cardinal: [z, o, t, f$1, m, x],
  4632. ordinal: [z, o, t, f$1, m, x]
  4633. };
  4634. const da$1 = a$1;
  4635. const de$1 = a$1;
  4636. const doi$1 = a$1;
  4637. const dsb$1 = {
  4638. cardinal: [o, t, f$1, x],
  4639. ordinal: [x]
  4640. };
  4641. const dv$1 = a$1;
  4642. const dz$1 = c$1;
  4643. const ee$1 = a$1;
  4644. const el$1 = a$1;
  4645. const en$1 = {
  4646. cardinal: [o, x],
  4647. ordinal: [o, t, f$1, x]
  4648. };
  4649. const eo$1 = a$1;
  4650. const es$1 = {
  4651. cardinal: [o, m, x],
  4652. ordinal: [x]
  4653. };
  4654. const et$1 = a$1;
  4655. const eu$1 = a$1;
  4656. const fa$1 = a$1;
  4657. const ff$1 = a$1;
  4658. const fi$1 = a$1;
  4659. const fil$1 = b$1;
  4660. const fo$1 = a$1;
  4661. const fr$1 = {
  4662. cardinal: [o, m, x],
  4663. ordinal: [o, x]
  4664. };
  4665. const fur$1 = a$1;
  4666. const fy$1 = a$1;
  4667. const ga$1 = {
  4668. cardinal: [o, t, f$1, m, x],
  4669. ordinal: [o, x]
  4670. };
  4671. const gd$1 = {
  4672. cardinal: [o, t, f$1, x],
  4673. ordinal: [o, t, f$1, x]
  4674. };
  4675. const gl$1 = a$1;
  4676. const gsw$1 = a$1;
  4677. const gu$1 = {
  4678. cardinal: [o, x],
  4679. ordinal: [o, t, f$1, m, x]
  4680. };
  4681. const guw$1 = a$1;
  4682. const gv$1 = {
  4683. cardinal: [o, t, f$1, m, x],
  4684. ordinal: [x]
  4685. };
  4686. const ha$1 = a$1;
  4687. const haw$1 = a$1;
  4688. const he$1 = d$1;
  4689. const hi$1 = {
  4690. cardinal: [o, x],
  4691. ordinal: [o, t, f$1, m, x]
  4692. };
  4693. const hnj$1 = c$1;
  4694. const hr$1 = {
  4695. cardinal: [o, f$1, x],
  4696. ordinal: [x]
  4697. };
  4698. const hsb$1 = {
  4699. cardinal: [o, t, f$1, x],
  4700. ordinal: [x]
  4701. };
  4702. const hu$1 = b$1;
  4703. const hy$1 = b$1;
  4704. const ia$1 = a$1;
  4705. const id$1 = c$1;
  4706. const ig$1 = c$1;
  4707. const ii$1 = c$1;
  4708. const io$1 = a$1;
  4709. const is$1 = a$1;
  4710. const it$1 = {
  4711. cardinal: [o, m, x],
  4712. ordinal: [m, x]
  4713. };
  4714. const iu$1 = d$1;
  4715. const ja$1 = c$1;
  4716. const jbo$1 = c$1;
  4717. const jgo$1 = a$1;
  4718. const jmc$1 = a$1;
  4719. const jv$1 = c$1;
  4720. const jw$1 = c$1;
  4721. const ka$1 = {
  4722. cardinal: [o, x],
  4723. ordinal: [o, m, x]
  4724. };
  4725. const kab$1 = a$1;
  4726. const kaj$1 = a$1;
  4727. const kcg$1 = a$1;
  4728. const kde$1 = c$1;
  4729. const kea$1 = c$1;
  4730. const kk$1 = {
  4731. cardinal: [o, x],
  4732. ordinal: [m, x]
  4733. };
  4734. const kkj$1 = a$1;
  4735. const kl$1 = a$1;
  4736. const km$1 = c$1;
  4737. const kn$1 = a$1;
  4738. const ko$1 = c$1;
  4739. const ks$1 = a$1;
  4740. const ksb$1 = a$1;
  4741. const ksh$1 = {
  4742. cardinal: [z, o, x],
  4743. ordinal: [x]
  4744. };
  4745. const ku$1 = a$1;
  4746. const kw$1 = {
  4747. cardinal: [z, o, t, f$1, m, x],
  4748. ordinal: [o, m, x]
  4749. };
  4750. const ky$1 = a$1;
  4751. const lag$1 = {
  4752. cardinal: [z, o, x],
  4753. ordinal: [x]
  4754. };
  4755. const lb$1 = a$1;
  4756. const lg$1 = a$1;
  4757. const lij$1 = {
  4758. cardinal: [o, x],
  4759. ordinal: [m, x]
  4760. };
  4761. const lkt$1 = c$1;
  4762. const ln$1 = a$1;
  4763. const lo$1 = {
  4764. cardinal: [x],
  4765. ordinal: [o, x]
  4766. };
  4767. const lt$1 = {
  4768. cardinal: [o, f$1, m, x],
  4769. ordinal: [x]
  4770. };
  4771. const lv$1 = {
  4772. cardinal: [z, o, x],
  4773. ordinal: [x]
  4774. };
  4775. const mas$1 = a$1;
  4776. const mg$1 = a$1;
  4777. const mgo$1 = a$1;
  4778. const mk$1 = {
  4779. cardinal: [o, x],
  4780. ordinal: [o, t, m, x]
  4781. };
  4782. const ml$1 = a$1;
  4783. const mn$1 = a$1;
  4784. const mo$1 = {
  4785. cardinal: [o, f$1, x],
  4786. ordinal: [o, x]
  4787. };
  4788. const mr$1 = {
  4789. cardinal: [o, x],
  4790. ordinal: [o, t, f$1, x]
  4791. };
  4792. const ms$1 = {
  4793. cardinal: [x],
  4794. ordinal: [o, x]
  4795. };
  4796. const mt$1 = {
  4797. cardinal: [o, t, f$1, m, x],
  4798. ordinal: [x]
  4799. };
  4800. const my$1 = c$1;
  4801. const nah$1 = a$1;
  4802. const naq$1 = d$1;
  4803. const nb$1 = a$1;
  4804. const nd$1 = a$1;
  4805. const ne$1 = b$1;
  4806. const nl$1 = a$1;
  4807. const nn$1 = a$1;
  4808. const nnh$1 = a$1;
  4809. const no$1 = a$1;
  4810. const nqo$1 = c$1;
  4811. const nr$1 = a$1;
  4812. const nso$1 = a$1;
  4813. const ny$1 = a$1;
  4814. const nyn$1 = a$1;
  4815. const om$1 = a$1;
  4816. const or$1 = {
  4817. cardinal: [o, x],
  4818. ordinal: [o, t, f$1, m, x]
  4819. };
  4820. const os$1 = a$1;
  4821. const osa$1 = c$1;
  4822. const pa$1 = a$1;
  4823. const pap$1 = a$1;
  4824. const pcm$1 = a$1;
  4825. const pl$1 = {
  4826. cardinal: [o, f$1, m, x],
  4827. ordinal: [x]
  4828. };
  4829. const prg$1 = {
  4830. cardinal: [z, o, x],
  4831. ordinal: [x]
  4832. };
  4833. const ps$1 = a$1;
  4834. const pt$1 = {
  4835. cardinal: [o, m, x],
  4836. ordinal: [x]
  4837. };
  4838. const pt_PT$1 = {
  4839. cardinal: [o, m, x],
  4840. ordinal: [x]
  4841. };
  4842. const rm$1 = a$1;
  4843. const ro$1 = {
  4844. cardinal: [o, f$1, x],
  4845. ordinal: [o, x]
  4846. };
  4847. const rof$1 = a$1;
  4848. const ru$1 = {
  4849. cardinal: [o, f$1, m, x],
  4850. ordinal: [x]
  4851. };
  4852. const rwk$1 = a$1;
  4853. const sah$1 = c$1;
  4854. const saq$1 = a$1;
  4855. const sat$1 = d$1;
  4856. const sc$1 = {
  4857. cardinal: [o, x],
  4858. ordinal: [m, x]
  4859. };
  4860. const scn$1 = {
  4861. cardinal: [o, x],
  4862. ordinal: [m, x]
  4863. };
  4864. const sd$1 = a$1;
  4865. const sdh$1 = a$1;
  4866. const se$1 = d$1;
  4867. const seh$1 = a$1;
  4868. const ses$1 = c$1;
  4869. const sg$1 = c$1;
  4870. const sh$1 = {
  4871. cardinal: [o, f$1, x],
  4872. ordinal: [x]
  4873. };
  4874. const shi$1 = {
  4875. cardinal: [o, f$1, x],
  4876. ordinal: [x]
  4877. };
  4878. const si$1 = a$1;
  4879. const sk$1 = {
  4880. cardinal: [o, f$1, m, x],
  4881. ordinal: [x]
  4882. };
  4883. const sl$1 = {
  4884. cardinal: [o, t, f$1, x],
  4885. ordinal: [x]
  4886. };
  4887. const sma$1 = d$1;
  4888. const smi$1 = d$1;
  4889. const smj$1 = d$1;
  4890. const smn$1 = d$1;
  4891. const sms$1 = d$1;
  4892. const sn$1 = a$1;
  4893. const so$1 = a$1;
  4894. const sq$1 = {
  4895. cardinal: [o, x],
  4896. ordinal: [o, m, x]
  4897. };
  4898. const sr$1 = {
  4899. cardinal: [o, f$1, x],
  4900. ordinal: [x]
  4901. };
  4902. const ss$1 = a$1;
  4903. const ssy$1 = a$1;
  4904. const st$1 = a$1;
  4905. const su$1 = c$1;
  4906. const sv$1 = b$1;
  4907. const sw$1 = a$1;
  4908. const syr$1 = a$1;
  4909. const ta$1 = a$1;
  4910. const te$1 = a$1;
  4911. const teo$1 = a$1;
  4912. const th$1 = c$1;
  4913. const ti$1 = a$1;
  4914. const tig$1 = a$1;
  4915. const tk$1 = {
  4916. cardinal: [o, x],
  4917. ordinal: [f$1, x]
  4918. };
  4919. const tl$1 = b$1;
  4920. const tn$1 = a$1;
  4921. const to$1 = c$1;
  4922. const tpi$1 = c$1;
  4923. const tr$1 = a$1;
  4924. const ts$1 = a$1;
  4925. const tzm$1 = a$1;
  4926. const ug$1 = a$1;
  4927. const uk$1 = {
  4928. cardinal: [o, f$1, m, x],
  4929. ordinal: [f$1, x]
  4930. };
  4931. const und$1 = c$1;
  4932. const ur$1 = a$1;
  4933. const uz$1 = a$1;
  4934. const ve$1 = a$1;
  4935. const vec$1 = {
  4936. cardinal: [o, m, x],
  4937. ordinal: [m, x]
  4938. };
  4939. const vi$1 = {
  4940. cardinal: [x],
  4941. ordinal: [o, x]
  4942. };
  4943. const vo$1 = a$1;
  4944. const vun$1 = a$1;
  4945. const wa$1 = a$1;
  4946. const wae$1 = a$1;
  4947. const wo$1 = c$1;
  4948. const xh$1 = a$1;
  4949. const xog$1 = a$1;
  4950. const yi$1 = a$1;
  4951. const yo$1 = c$1;
  4952. const yue$1 = c$1;
  4953. const zh$1 = c$1;
  4954. const zu$1 = a$1;
  4955. var PluralCategories = /*#__PURE__*/Object.freeze({
  4956. __proto__: null,
  4957. af: af$1,
  4958. ak: ak$1,
  4959. am: am$1,
  4960. an: an$1,
  4961. ar: ar$1,
  4962. ars: ars$1,
  4963. as: as$1,
  4964. asa: asa$1,
  4965. ast: ast$1,
  4966. az: az$1,
  4967. bal: bal$1,
  4968. be: be$1,
  4969. bem: bem$1,
  4970. bez: bez$1,
  4971. bg: bg$1,
  4972. bho: bho$1,
  4973. bm: bm$1,
  4974. bn: bn$1,
  4975. bo: bo$1,
  4976. br: br$1,
  4977. brx: brx$1,
  4978. bs: bs$1,
  4979. ca: ca$1,
  4980. ce: ce$1,
  4981. ceb: ceb$1,
  4982. cgg: cgg$1,
  4983. chr: chr$1,
  4984. ckb: ckb$1,
  4985. cs: cs$1,
  4986. cy: cy$1,
  4987. da: da$1,
  4988. de: de$1,
  4989. doi: doi$1,
  4990. dsb: dsb$1,
  4991. dv: dv$1,
  4992. dz: dz$1,
  4993. ee: ee$1,
  4994. el: el$1,
  4995. en: en$1,
  4996. eo: eo$1,
  4997. es: es$1,
  4998. et: et$1,
  4999. eu: eu$1,
  5000. fa: fa$1,
  5001. ff: ff$1,
  5002. fi: fi$1,
  5003. fil: fil$1,
  5004. fo: fo$1,
  5005. fr: fr$1,
  5006. fur: fur$1,
  5007. fy: fy$1,
  5008. ga: ga$1,
  5009. gd: gd$1,
  5010. gl: gl$1,
  5011. gsw: gsw$1,
  5012. gu: gu$1,
  5013. guw: guw$1,
  5014. gv: gv$1,
  5015. ha: ha$1,
  5016. haw: haw$1,
  5017. he: he$1,
  5018. hi: hi$1,
  5019. hnj: hnj$1,
  5020. hr: hr$1,
  5021. hsb: hsb$1,
  5022. hu: hu$1,
  5023. hy: hy$1,
  5024. ia: ia$1,
  5025. id: id$1,
  5026. ig: ig$1,
  5027. ii: ii$1,
  5028. io: io$1,
  5029. is: is$1,
  5030. it: it$1,
  5031. iu: iu$1,
  5032. ja: ja$1,
  5033. jbo: jbo$1,
  5034. jgo: jgo$1,
  5035. jmc: jmc$1,
  5036. jv: jv$1,
  5037. jw: jw$1,
  5038. ka: ka$1,
  5039. kab: kab$1,
  5040. kaj: kaj$1,
  5041. kcg: kcg$1,
  5042. kde: kde$1,
  5043. kea: kea$1,
  5044. kk: kk$1,
  5045. kkj: kkj$1,
  5046. kl: kl$1,
  5047. km: km$1,
  5048. kn: kn$1,
  5049. ko: ko$1,
  5050. ks: ks$1,
  5051. ksb: ksb$1,
  5052. ksh: ksh$1,
  5053. ku: ku$1,
  5054. kw: kw$1,
  5055. ky: ky$1,
  5056. lag: lag$1,
  5057. lb: lb$1,
  5058. lg: lg$1,
  5059. lij: lij$1,
  5060. lkt: lkt$1,
  5061. ln: ln$1,
  5062. lo: lo$1,
  5063. lt: lt$1,
  5064. lv: lv$1,
  5065. mas: mas$1,
  5066. mg: mg$1,
  5067. mgo: mgo$1,
  5068. mk: mk$1,
  5069. ml: ml$1,
  5070. mn: mn$1,
  5071. mo: mo$1,
  5072. mr: mr$1,
  5073. ms: ms$1,
  5074. mt: mt$1,
  5075. my: my$1,
  5076. nah: nah$1,
  5077. naq: naq$1,
  5078. nb: nb$1,
  5079. nd: nd$1,
  5080. ne: ne$1,
  5081. nl: nl$1,
  5082. nn: nn$1,
  5083. nnh: nnh$1,
  5084. no: no$1,
  5085. nqo: nqo$1,
  5086. nr: nr$1,
  5087. nso: nso$1,
  5088. ny: ny$1,
  5089. nyn: nyn$1,
  5090. om: om$1,
  5091. or: or$1,
  5092. os: os$1,
  5093. osa: osa$1,
  5094. pa: pa$1,
  5095. pap: pap$1,
  5096. pcm: pcm$1,
  5097. pl: pl$1,
  5098. prg: prg$1,
  5099. ps: ps$1,
  5100. pt: pt$1,
  5101. pt_PT: pt_PT$1,
  5102. rm: rm$1,
  5103. ro: ro$1,
  5104. rof: rof$1,
  5105. ru: ru$1,
  5106. rwk: rwk$1,
  5107. sah: sah$1,
  5108. saq: saq$1,
  5109. sat: sat$1,
  5110. sc: sc$1,
  5111. scn: scn$1,
  5112. sd: sd$1,
  5113. sdh: sdh$1,
  5114. se: se$1,
  5115. seh: seh$1,
  5116. ses: ses$1,
  5117. sg: sg$1,
  5118. sh: sh$1,
  5119. shi: shi$1,
  5120. si: si$1,
  5121. sk: sk$1,
  5122. sl: sl$1,
  5123. sma: sma$1,
  5124. smi: smi$1,
  5125. smj: smj$1,
  5126. smn: smn$1,
  5127. sms: sms$1,
  5128. sn: sn$1,
  5129. so: so$1,
  5130. sq: sq$1,
  5131. sr: sr$1,
  5132. ss: ss$1,
  5133. ssy: ssy$1,
  5134. st: st$1,
  5135. su: su$1,
  5136. sv: sv$1,
  5137. sw: sw$1,
  5138. syr: syr$1,
  5139. ta: ta$1,
  5140. te: te$1,
  5141. teo: teo$1,
  5142. th: th$1,
  5143. ti: ti$1,
  5144. tig: tig$1,
  5145. tk: tk$1,
  5146. tl: tl$1,
  5147. tn: tn$1,
  5148. to: to$1,
  5149. tpi: tpi$1,
  5150. tr: tr$1,
  5151. ts: ts$1,
  5152. tzm: tzm$1,
  5153. ug: ug$1,
  5154. uk: uk$1,
  5155. und: und$1,
  5156. ur: ur$1,
  5157. uz: uz$1,
  5158. ve: ve$1,
  5159. vec: vec$1,
  5160. vi: vi$1,
  5161. vo: vo$1,
  5162. vun: vun$1,
  5163. wa: wa$1,
  5164. wae: wae$1,
  5165. wo: wo$1,
  5166. xh: xh$1,
  5167. xog: xog$1,
  5168. yi: yi$1,
  5169. yo: yo$1,
  5170. yue: yue$1,
  5171. zh: zh$1,
  5172. zu: zu$1
  5173. });
  5174. const a = (n, ord) => {
  5175. if (ord) return 'other';
  5176. return n == 1 ? 'one' : 'other';
  5177. };
  5178. const b = (n, ord) => {
  5179. if (ord) return 'other';
  5180. return n == 0 || n == 1 ? 'one' : 'other';
  5181. };
  5182. const c = (n, ord) => {
  5183. if (ord) return 'other';
  5184. return n >= 0 && n <= 1 ? 'one' : 'other';
  5185. };
  5186. const d = (n, ord) => {
  5187. const s = String(n).split('.'),
  5188. v0 = !s[1];
  5189. if (ord) return 'other';
  5190. return n == 1 && v0 ? 'one' : 'other';
  5191. };
  5192. const e = (n, ord) => 'other';
  5193. const f = (n, ord) => {
  5194. if (ord) return 'other';
  5195. return n == 1 ? 'one' : n == 2 ? 'two' : 'other';
  5196. };
  5197. const af = a;
  5198. const ak = b;
  5199. const am = c;
  5200. const an = a;
  5201. const ar = (n, ord) => {
  5202. const s = String(n).split('.'),
  5203. t0 = Number(s[0]) == n,
  5204. n100 = t0 && s[0].slice(-2);
  5205. if (ord) return 'other';
  5206. return n == 0 ? 'zero' : n == 1 ? 'one' : n == 2 ? 'two' : n100 >= 3 && n100 <= 10 ? 'few' : n100 >= 11 && n100 <= 99 ? 'many' : 'other';
  5207. };
  5208. const ars = (n, ord) => {
  5209. const s = String(n).split('.'),
  5210. t0 = Number(s[0]) == n,
  5211. n100 = t0 && s[0].slice(-2);
  5212. if (ord) return 'other';
  5213. return n == 0 ? 'zero' : n == 1 ? 'one' : n == 2 ? 'two' : n100 >= 3 && n100 <= 10 ? 'few' : n100 >= 11 && n100 <= 99 ? 'many' : 'other';
  5214. };
  5215. const as = (n, ord) => {
  5216. if (ord) return n == 1 || n == 5 || n == 7 || n == 8 || n == 9 || n == 10 ? 'one' : n == 2 || n == 3 ? 'two' : n == 4 ? 'few' : n == 6 ? 'many' : 'other';
  5217. return n >= 0 && n <= 1 ? 'one' : 'other';
  5218. };
  5219. const asa = a;
  5220. const ast = d;
  5221. const az = (n, ord) => {
  5222. const s = String(n).split('.'),
  5223. i = s[0],
  5224. i10 = i.slice(-1),
  5225. i100 = i.slice(-2),
  5226. i1000 = i.slice(-3);
  5227. if (ord) return i10 == 1 || i10 == 2 || i10 == 5 || i10 == 7 || i10 == 8 || i100 == 20 || i100 == 50 || i100 == 70 || i100 == 80 ? 'one' : i10 == 3 || i10 == 4 || i1000 == 100 || i1000 == 200 || i1000 == 300 || i1000 == 400 || i1000 == 500 || i1000 == 600 || i1000 == 700 || i1000 == 800 || i1000 == 900 ? 'few' : i == 0 || i10 == 6 || i100 == 40 || i100 == 60 || i100 == 90 ? 'many' : 'other';
  5228. return n == 1 ? 'one' : 'other';
  5229. };
  5230. const bal = (n, ord) => n == 1 ? 'one' : 'other';
  5231. const be = (n, ord) => {
  5232. const s = String(n).split('.'),
  5233. t0 = Number(s[0]) == n,
  5234. n10 = t0 && s[0].slice(-1),
  5235. n100 = t0 && s[0].slice(-2);
  5236. if (ord) return (n10 == 2 || n10 == 3) && n100 != 12 && n100 != 13 ? 'few' : 'other';
  5237. return n10 == 1 && n100 != 11 ? 'one' : n10 >= 2 && n10 <= 4 && (n100 < 12 || n100 > 14) ? 'few' : t0 && n10 == 0 || n10 >= 5 && n10 <= 9 || n100 >= 11 && n100 <= 14 ? 'many' : 'other';
  5238. };
  5239. const bem = a;
  5240. const bez = a;
  5241. const bg = a;
  5242. const bho = b;
  5243. const bm = e;
  5244. const bn = (n, ord) => {
  5245. if (ord) return n == 1 || n == 5 || n == 7 || n == 8 || n == 9 || n == 10 ? 'one' : n == 2 || n == 3 ? 'two' : n == 4 ? 'few' : n == 6 ? 'many' : 'other';
  5246. return n >= 0 && n <= 1 ? 'one' : 'other';
  5247. };
  5248. const bo = e;
  5249. const br = (n, ord) => {
  5250. const s = String(n).split('.'),
  5251. t0 = Number(s[0]) == n,
  5252. n10 = t0 && s[0].slice(-1),
  5253. n100 = t0 && s[0].slice(-2),
  5254. n1000000 = t0 && s[0].slice(-6);
  5255. if (ord) return 'other';
  5256. return n10 == 1 && n100 != 11 && n100 != 71 && n100 != 91 ? 'one' : n10 == 2 && n100 != 12 && n100 != 72 && n100 != 92 ? 'two' : (n10 == 3 || n10 == 4 || n10 == 9) && (n100 < 10 || n100 > 19) && (n100 < 70 || n100 > 79) && (n100 < 90 || n100 > 99) ? 'few' : n != 0 && t0 && n1000000 == 0 ? 'many' : 'other';
  5257. };
  5258. const brx = a;
  5259. const bs = (n, ord) => {
  5260. const s = String(n).split('.'),
  5261. i = s[0],
  5262. f = s[1] || '',
  5263. v0 = !s[1],
  5264. i10 = i.slice(-1),
  5265. i100 = i.slice(-2),
  5266. f10 = f.slice(-1),
  5267. f100 = f.slice(-2);
  5268. if (ord) return 'other';
  5269. return v0 && i10 == 1 && i100 != 11 || f10 == 1 && f100 != 11 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) || f10 >= 2 && f10 <= 4 && (f100 < 12 || f100 > 14) ? 'few' : 'other';
  5270. };
  5271. const ca = (n, ord) => {
  5272. const s = String(n).split('.'),
  5273. i = s[0],
  5274. v0 = !s[1],
  5275. i1000000 = i.slice(-6);
  5276. if (ord) return n == 1 || n == 3 ? 'one' : n == 2 ? 'two' : n == 4 ? 'few' : 'other';
  5277. return n == 1 && v0 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
  5278. };
  5279. const ce = a;
  5280. const ceb = (n, ord) => {
  5281. const s = String(n).split('.'),
  5282. i = s[0],
  5283. f = s[1] || '',
  5284. v0 = !s[1],
  5285. i10 = i.slice(-1),
  5286. f10 = f.slice(-1);
  5287. if (ord) return 'other';
  5288. return v0 && (i == 1 || i == 2 || i == 3) || v0 && i10 != 4 && i10 != 6 && i10 != 9 || !v0 && f10 != 4 && f10 != 6 && f10 != 9 ? 'one' : 'other';
  5289. };
  5290. const cgg = a;
  5291. const chr = a;
  5292. const ckb = a;
  5293. const cs = (n, ord) => {
  5294. const s = String(n).split('.'),
  5295. i = s[0],
  5296. v0 = !s[1];
  5297. if (ord) return 'other';
  5298. return n == 1 && v0 ? 'one' : i >= 2 && i <= 4 && v0 ? 'few' : !v0 ? 'many' : 'other';
  5299. };
  5300. const cy = (n, ord) => {
  5301. if (ord) return n == 0 || n == 7 || n == 8 || n == 9 ? 'zero' : n == 1 ? 'one' : n == 2 ? 'two' : n == 3 || n == 4 ? 'few' : n == 5 || n == 6 ? 'many' : 'other';
  5302. return n == 0 ? 'zero' : n == 1 ? 'one' : n == 2 ? 'two' : n == 3 ? 'few' : n == 6 ? 'many' : 'other';
  5303. };
  5304. const da = (n, ord) => {
  5305. const s = String(n).split('.'),
  5306. i = s[0],
  5307. t0 = Number(s[0]) == n;
  5308. if (ord) return 'other';
  5309. return n == 1 || !t0 && (i == 0 || i == 1) ? 'one' : 'other';
  5310. };
  5311. const de = d;
  5312. const doi = c;
  5313. const dsb = (n, ord) => {
  5314. const s = String(n).split('.'),
  5315. i = s[0],
  5316. f = s[1] || '',
  5317. v0 = !s[1],
  5318. i100 = i.slice(-2),
  5319. f100 = f.slice(-2);
  5320. if (ord) return 'other';
  5321. return v0 && i100 == 1 || f100 == 1 ? 'one' : v0 && i100 == 2 || f100 == 2 ? 'two' : v0 && (i100 == 3 || i100 == 4) || f100 == 3 || f100 == 4 ? 'few' : 'other';
  5322. };
  5323. const dv = a;
  5324. const dz = e;
  5325. const ee = a;
  5326. const el = a;
  5327. const en = (n, ord) => {
  5328. const s = String(n).split('.'),
  5329. v0 = !s[1],
  5330. t0 = Number(s[0]) == n,
  5331. n10 = t0 && s[0].slice(-1),
  5332. n100 = t0 && s[0].slice(-2);
  5333. if (ord) return n10 == 1 && n100 != 11 ? 'one' : n10 == 2 && n100 != 12 ? 'two' : n10 == 3 && n100 != 13 ? 'few' : 'other';
  5334. return n == 1 && v0 ? 'one' : 'other';
  5335. };
  5336. const eo = a;
  5337. const es = (n, ord) => {
  5338. const s = String(n).split('.'),
  5339. i = s[0],
  5340. v0 = !s[1],
  5341. i1000000 = i.slice(-6);
  5342. if (ord) return 'other';
  5343. return n == 1 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
  5344. };
  5345. const et = d;
  5346. const eu = a;
  5347. const fa = c;
  5348. const ff = (n, ord) => {
  5349. if (ord) return 'other';
  5350. return n >= 0 && n < 2 ? 'one' : 'other';
  5351. };
  5352. const fi = d;
  5353. const fil = (n, ord) => {
  5354. const s = String(n).split('.'),
  5355. i = s[0],
  5356. f = s[1] || '',
  5357. v0 = !s[1],
  5358. i10 = i.slice(-1),
  5359. f10 = f.slice(-1);
  5360. if (ord) return n == 1 ? 'one' : 'other';
  5361. return v0 && (i == 1 || i == 2 || i == 3) || v0 && i10 != 4 && i10 != 6 && i10 != 9 || !v0 && f10 != 4 && f10 != 6 && f10 != 9 ? 'one' : 'other';
  5362. };
  5363. const fo = a;
  5364. const fr = (n, ord) => {
  5365. const s = String(n).split('.'),
  5366. i = s[0],
  5367. v0 = !s[1],
  5368. i1000000 = i.slice(-6);
  5369. if (ord) return n == 1 ? 'one' : 'other';
  5370. return n >= 0 && n < 2 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
  5371. };
  5372. const fur = a;
  5373. const fy = d;
  5374. const ga = (n, ord) => {
  5375. const s = String(n).split('.'),
  5376. t0 = Number(s[0]) == n;
  5377. if (ord) return n == 1 ? 'one' : 'other';
  5378. return n == 1 ? 'one' : n == 2 ? 'two' : t0 && n >= 3 && n <= 6 ? 'few' : t0 && n >= 7 && n <= 10 ? 'many' : 'other';
  5379. };
  5380. const gd = (n, ord) => {
  5381. const s = String(n).split('.'),
  5382. t0 = Number(s[0]) == n;
  5383. if (ord) return n == 1 || n == 11 ? 'one' : n == 2 || n == 12 ? 'two' : n == 3 || n == 13 ? 'few' : 'other';
  5384. return n == 1 || n == 11 ? 'one' : n == 2 || n == 12 ? 'two' : t0 && n >= 3 && n <= 10 || t0 && n >= 13 && n <= 19 ? 'few' : 'other';
  5385. };
  5386. const gl = d;
  5387. const gsw = a;
  5388. const gu = (n, ord) => {
  5389. if (ord) return n == 1 ? 'one' : n == 2 || n == 3 ? 'two' : n == 4 ? 'few' : n == 6 ? 'many' : 'other';
  5390. return n >= 0 && n <= 1 ? 'one' : 'other';
  5391. };
  5392. const guw = b;
  5393. const gv = (n, ord) => {
  5394. const s = String(n).split('.'),
  5395. i = s[0],
  5396. v0 = !s[1],
  5397. i10 = i.slice(-1),
  5398. i100 = i.slice(-2);
  5399. if (ord) return 'other';
  5400. return v0 && i10 == 1 ? 'one' : v0 && i10 == 2 ? 'two' : v0 && (i100 == 0 || i100 == 20 || i100 == 40 || i100 == 60 || i100 == 80) ? 'few' : !v0 ? 'many' : 'other';
  5401. };
  5402. const ha = a;
  5403. const haw = a;
  5404. const he = (n, ord) => {
  5405. const s = String(n).split('.'),
  5406. i = s[0],
  5407. v0 = !s[1];
  5408. if (ord) return 'other';
  5409. return i == 1 && v0 || i == 0 && !v0 ? 'one' : i == 2 && v0 ? 'two' : 'other';
  5410. };
  5411. const hi = (n, ord) => {
  5412. if (ord) return n == 1 ? 'one' : n == 2 || n == 3 ? 'two' : n == 4 ? 'few' : n == 6 ? 'many' : 'other';
  5413. return n >= 0 && n <= 1 ? 'one' : 'other';
  5414. };
  5415. const hnj = e;
  5416. const hr = (n, ord) => {
  5417. const s = String(n).split('.'),
  5418. i = s[0],
  5419. f = s[1] || '',
  5420. v0 = !s[1],
  5421. i10 = i.slice(-1),
  5422. i100 = i.slice(-2),
  5423. f10 = f.slice(-1),
  5424. f100 = f.slice(-2);
  5425. if (ord) return 'other';
  5426. return v0 && i10 == 1 && i100 != 11 || f10 == 1 && f100 != 11 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) || f10 >= 2 && f10 <= 4 && (f100 < 12 || f100 > 14) ? 'few' : 'other';
  5427. };
  5428. const hsb = (n, ord) => {
  5429. const s = String(n).split('.'),
  5430. i = s[0],
  5431. f = s[1] || '',
  5432. v0 = !s[1],
  5433. i100 = i.slice(-2),
  5434. f100 = f.slice(-2);
  5435. if (ord) return 'other';
  5436. return v0 && i100 == 1 || f100 == 1 ? 'one' : v0 && i100 == 2 || f100 == 2 ? 'two' : v0 && (i100 == 3 || i100 == 4) || f100 == 3 || f100 == 4 ? 'few' : 'other';
  5437. };
  5438. const hu = (n, ord) => {
  5439. if (ord) return n == 1 || n == 5 ? 'one' : 'other';
  5440. return n == 1 ? 'one' : 'other';
  5441. };
  5442. const hy = (n, ord) => {
  5443. if (ord) return n == 1 ? 'one' : 'other';
  5444. return n >= 0 && n < 2 ? 'one' : 'other';
  5445. };
  5446. const ia = d;
  5447. const id = e;
  5448. const ig = e;
  5449. const ii = e;
  5450. const io = d;
  5451. const is = (n, ord) => {
  5452. const s = String(n).split('.'),
  5453. i = s[0],
  5454. t = (s[1] || '').replace(/0+$/, ''),
  5455. t0 = Number(s[0]) == n,
  5456. i10 = i.slice(-1),
  5457. i100 = i.slice(-2);
  5458. if (ord) return 'other';
  5459. return t0 && i10 == 1 && i100 != 11 || t % 10 == 1 && t % 100 != 11 ? 'one' : 'other';
  5460. };
  5461. const it = (n, ord) => {
  5462. const s = String(n).split('.'),
  5463. i = s[0],
  5464. v0 = !s[1],
  5465. i1000000 = i.slice(-6);
  5466. if (ord) return n == 11 || n == 8 || n == 80 || n == 800 ? 'many' : 'other';
  5467. return n == 1 && v0 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
  5468. };
  5469. const iu = f;
  5470. const ja = e;
  5471. const jbo = e;
  5472. const jgo = a;
  5473. const jmc = a;
  5474. const jv = e;
  5475. const jw = e;
  5476. const ka = (n, ord) => {
  5477. const s = String(n).split('.'),
  5478. i = s[0],
  5479. i100 = i.slice(-2);
  5480. if (ord) return i == 1 ? 'one' : i == 0 || i100 >= 2 && i100 <= 20 || i100 == 40 || i100 == 60 || i100 == 80 ? 'many' : 'other';
  5481. return n == 1 ? 'one' : 'other';
  5482. };
  5483. const kab = (n, ord) => {
  5484. if (ord) return 'other';
  5485. return n >= 0 && n < 2 ? 'one' : 'other';
  5486. };
  5487. const kaj = a;
  5488. const kcg = a;
  5489. const kde = e;
  5490. const kea = e;
  5491. const kk = (n, ord) => {
  5492. const s = String(n).split('.'),
  5493. t0 = Number(s[0]) == n,
  5494. n10 = t0 && s[0].slice(-1);
  5495. if (ord) return n10 == 6 || n10 == 9 || t0 && n10 == 0 && n != 0 ? 'many' : 'other';
  5496. return n == 1 ? 'one' : 'other';
  5497. };
  5498. const kkj = a;
  5499. const kl = a;
  5500. const km = e;
  5501. const kn = c;
  5502. const ko = e;
  5503. const ks = a;
  5504. const ksb = a;
  5505. const ksh = (n, ord) => {
  5506. if (ord) return 'other';
  5507. return n == 0 ? 'zero' : n == 1 ? 'one' : 'other';
  5508. };
  5509. const ku = a;
  5510. const kw = (n, ord) => {
  5511. const s = String(n).split('.'),
  5512. t0 = Number(s[0]) == n,
  5513. n100 = t0 && s[0].slice(-2),
  5514. n1000 = t0 && s[0].slice(-3),
  5515. n100000 = t0 && s[0].slice(-5),
  5516. n1000000 = t0 && s[0].slice(-6);
  5517. if (ord) return t0 && n >= 1 && n <= 4 || n100 >= 1 && n100 <= 4 || n100 >= 21 && n100 <= 24 || n100 >= 41 && n100 <= 44 || n100 >= 61 && n100 <= 64 || n100 >= 81 && n100 <= 84 ? 'one' : n == 5 || n100 == 5 ? 'many' : 'other';
  5518. return n == 0 ? 'zero' : n == 1 ? 'one' : n100 == 2 || n100 == 22 || n100 == 42 || n100 == 62 || n100 == 82 || t0 && n1000 == 0 && (n100000 >= 1000 && n100000 <= 20000 || n100000 == 40000 || n100000 == 60000 || n100000 == 80000) || n != 0 && n1000000 == 100000 ? 'two' : n100 == 3 || n100 == 23 || n100 == 43 || n100 == 63 || n100 == 83 ? 'few' : n != 1 && (n100 == 1 || n100 == 21 || n100 == 41 || n100 == 61 || n100 == 81) ? 'many' : 'other';
  5519. };
  5520. const ky = a;
  5521. const lag = (n, ord) => {
  5522. const s = String(n).split('.'),
  5523. i = s[0];
  5524. if (ord) return 'other';
  5525. return n == 0 ? 'zero' : (i == 0 || i == 1) && n != 0 ? 'one' : 'other';
  5526. };
  5527. const lb = a;
  5528. const lg = a;
  5529. const lij = (n, ord) => {
  5530. const s = String(n).split('.'),
  5531. v0 = !s[1],
  5532. t0 = Number(s[0]) == n;
  5533. if (ord) return n == 11 || n == 8 || t0 && n >= 80 && n <= 89 || t0 && n >= 800 && n <= 899 ? 'many' : 'other';
  5534. return n == 1 && v0 ? 'one' : 'other';
  5535. };
  5536. const lkt = e;
  5537. const ln = b;
  5538. const lo = (n, ord) => {
  5539. if (ord) return n == 1 ? 'one' : 'other';
  5540. return 'other';
  5541. };
  5542. const lt = (n, ord) => {
  5543. const s = String(n).split('.'),
  5544. f = s[1] || '',
  5545. t0 = Number(s[0]) == n,
  5546. n10 = t0 && s[0].slice(-1),
  5547. n100 = t0 && s[0].slice(-2);
  5548. if (ord) return 'other';
  5549. return n10 == 1 && (n100 < 11 || n100 > 19) ? 'one' : n10 >= 2 && n10 <= 9 && (n100 < 11 || n100 > 19) ? 'few' : f != 0 ? 'many' : 'other';
  5550. };
  5551. const lv = (n, ord) => {
  5552. const s = String(n).split('.'),
  5553. f = s[1] || '',
  5554. v = f.length,
  5555. t0 = Number(s[0]) == n,
  5556. n10 = t0 && s[0].slice(-1),
  5557. n100 = t0 && s[0].slice(-2),
  5558. f100 = f.slice(-2),
  5559. f10 = f.slice(-1);
  5560. if (ord) return 'other';
  5561. return t0 && n10 == 0 || n100 >= 11 && n100 <= 19 || v == 2 && f100 >= 11 && f100 <= 19 ? 'zero' : n10 == 1 && n100 != 11 || v == 2 && f10 == 1 && f100 != 11 || v != 2 && f10 == 1 ? 'one' : 'other';
  5562. };
  5563. const mas = a;
  5564. const mg = b;
  5565. const mgo = a;
  5566. const mk = (n, ord) => {
  5567. const s = String(n).split('.'),
  5568. i = s[0],
  5569. f = s[1] || '',
  5570. v0 = !s[1],
  5571. i10 = i.slice(-1),
  5572. i100 = i.slice(-2),
  5573. f10 = f.slice(-1),
  5574. f100 = f.slice(-2);
  5575. if (ord) return i10 == 1 && i100 != 11 ? 'one' : i10 == 2 && i100 != 12 ? 'two' : (i10 == 7 || i10 == 8) && i100 != 17 && i100 != 18 ? 'many' : 'other';
  5576. return v0 && i10 == 1 && i100 != 11 || f10 == 1 && f100 != 11 ? 'one' : 'other';
  5577. };
  5578. const ml = a;
  5579. const mn = a;
  5580. const mo = (n, ord) => {
  5581. const s = String(n).split('.'),
  5582. v0 = !s[1],
  5583. t0 = Number(s[0]) == n,
  5584. n100 = t0 && s[0].slice(-2);
  5585. if (ord) return n == 1 ? 'one' : 'other';
  5586. return n == 1 && v0 ? 'one' : !v0 || n == 0 || n != 1 && n100 >= 1 && n100 <= 19 ? 'few' : 'other';
  5587. };
  5588. const mr = (n, ord) => {
  5589. if (ord) return n == 1 ? 'one' : n == 2 || n == 3 ? 'two' : n == 4 ? 'few' : 'other';
  5590. return n == 1 ? 'one' : 'other';
  5591. };
  5592. const ms = (n, ord) => {
  5593. if (ord) return n == 1 ? 'one' : 'other';
  5594. return 'other';
  5595. };
  5596. const mt = (n, ord) => {
  5597. const s = String(n).split('.'),
  5598. t0 = Number(s[0]) == n,
  5599. n100 = t0 && s[0].slice(-2);
  5600. if (ord) return 'other';
  5601. return n == 1 ? 'one' : n == 2 ? 'two' : n == 0 || n100 >= 3 && n100 <= 10 ? 'few' : n100 >= 11 && n100 <= 19 ? 'many' : 'other';
  5602. };
  5603. const my = e;
  5604. const nah = a;
  5605. const naq = f;
  5606. const nb = a;
  5607. const nd = a;
  5608. const ne = (n, ord) => {
  5609. const s = String(n).split('.'),
  5610. t0 = Number(s[0]) == n;
  5611. if (ord) return t0 && n >= 1 && n <= 4 ? 'one' : 'other';
  5612. return n == 1 ? 'one' : 'other';
  5613. };
  5614. const nl = d;
  5615. const nn = a;
  5616. const nnh = a;
  5617. const no = a;
  5618. const nqo = e;
  5619. const nr = a;
  5620. const nso = b;
  5621. const ny = a;
  5622. const nyn = a;
  5623. const om = a;
  5624. const or = (n, ord) => {
  5625. const s = String(n).split('.'),
  5626. t0 = Number(s[0]) == n;
  5627. if (ord) return n == 1 || n == 5 || t0 && n >= 7 && n <= 9 ? 'one' : n == 2 || n == 3 ? 'two' : n == 4 ? 'few' : n == 6 ? 'many' : 'other';
  5628. return n == 1 ? 'one' : 'other';
  5629. };
  5630. const os = a;
  5631. const osa = e;
  5632. const pa = b;
  5633. const pap = a;
  5634. const pcm = c;
  5635. const pl = (n, ord) => {
  5636. const s = String(n).split('.'),
  5637. i = s[0],
  5638. v0 = !s[1],
  5639. i10 = i.slice(-1),
  5640. i100 = i.slice(-2);
  5641. if (ord) return 'other';
  5642. return n == 1 && v0 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) ? 'few' : v0 && i != 1 && (i10 == 0 || i10 == 1) || v0 && i10 >= 5 && i10 <= 9 || v0 && i100 >= 12 && i100 <= 14 ? 'many' : 'other';
  5643. };
  5644. const prg = (n, ord) => {
  5645. const s = String(n).split('.'),
  5646. f = s[1] || '',
  5647. v = f.length,
  5648. t0 = Number(s[0]) == n,
  5649. n10 = t0 && s[0].slice(-1),
  5650. n100 = t0 && s[0].slice(-2),
  5651. f100 = f.slice(-2),
  5652. f10 = f.slice(-1);
  5653. if (ord) return 'other';
  5654. return t0 && n10 == 0 || n100 >= 11 && n100 <= 19 || v == 2 && f100 >= 11 && f100 <= 19 ? 'zero' : n10 == 1 && n100 != 11 || v == 2 && f10 == 1 && f100 != 11 || v != 2 && f10 == 1 ? 'one' : 'other';
  5655. };
  5656. const ps = a;
  5657. const pt = (n, ord) => {
  5658. const s = String(n).split('.'),
  5659. i = s[0],
  5660. v0 = !s[1],
  5661. i1000000 = i.slice(-6);
  5662. if (ord) return 'other';
  5663. return i == 0 || i == 1 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
  5664. };
  5665. const pt_PT = (n, ord) => {
  5666. const s = String(n).split('.'),
  5667. i = s[0],
  5668. v0 = !s[1],
  5669. i1000000 = i.slice(-6);
  5670. if (ord) return 'other';
  5671. return n == 1 && v0 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
  5672. };
  5673. const rm = a;
  5674. const ro = (n, ord) => {
  5675. const s = String(n).split('.'),
  5676. v0 = !s[1],
  5677. t0 = Number(s[0]) == n,
  5678. n100 = t0 && s[0].slice(-2);
  5679. if (ord) return n == 1 ? 'one' : 'other';
  5680. return n == 1 && v0 ? 'one' : !v0 || n == 0 || n != 1 && n100 >= 1 && n100 <= 19 ? 'few' : 'other';
  5681. };
  5682. const rof = a;
  5683. const ru = (n, ord) => {
  5684. const s = String(n).split('.'),
  5685. i = s[0],
  5686. v0 = !s[1],
  5687. i10 = i.slice(-1),
  5688. i100 = i.slice(-2);
  5689. if (ord) return 'other';
  5690. return v0 && i10 == 1 && i100 != 11 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) ? 'few' : v0 && i10 == 0 || v0 && i10 >= 5 && i10 <= 9 || v0 && i100 >= 11 && i100 <= 14 ? 'many' : 'other';
  5691. };
  5692. const rwk = a;
  5693. const sah = e;
  5694. const saq = a;
  5695. const sat = f;
  5696. const sc = (n, ord) => {
  5697. const s = String(n).split('.'),
  5698. v0 = !s[1];
  5699. if (ord) return n == 11 || n == 8 || n == 80 || n == 800 ? 'many' : 'other';
  5700. return n == 1 && v0 ? 'one' : 'other';
  5701. };
  5702. const scn = (n, ord) => {
  5703. const s = String(n).split('.'),
  5704. v0 = !s[1];
  5705. if (ord) return n == 11 || n == 8 || n == 80 || n == 800 ? 'many' : 'other';
  5706. return n == 1 && v0 ? 'one' : 'other';
  5707. };
  5708. const sd = a;
  5709. const sdh = a;
  5710. const se = f;
  5711. const seh = a;
  5712. const ses = e;
  5713. const sg = e;
  5714. const sh = (n, ord) => {
  5715. const s = String(n).split('.'),
  5716. i = s[0],
  5717. f = s[1] || '',
  5718. v0 = !s[1],
  5719. i10 = i.slice(-1),
  5720. i100 = i.slice(-2),
  5721. f10 = f.slice(-1),
  5722. f100 = f.slice(-2);
  5723. if (ord) return 'other';
  5724. return v0 && i10 == 1 && i100 != 11 || f10 == 1 && f100 != 11 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) || f10 >= 2 && f10 <= 4 && (f100 < 12 || f100 > 14) ? 'few' : 'other';
  5725. };
  5726. const shi = (n, ord) => {
  5727. const s = String(n).split('.'),
  5728. t0 = Number(s[0]) == n;
  5729. if (ord) return 'other';
  5730. return n >= 0 && n <= 1 ? 'one' : t0 && n >= 2 && n <= 10 ? 'few' : 'other';
  5731. };
  5732. const si = (n, ord) => {
  5733. const s = String(n).split('.'),
  5734. i = s[0],
  5735. f = s[1] || '';
  5736. if (ord) return 'other';
  5737. return n == 0 || n == 1 || i == 0 && f == 1 ? 'one' : 'other';
  5738. };
  5739. const sk = (n, ord) => {
  5740. const s = String(n).split('.'),
  5741. i = s[0],
  5742. v0 = !s[1];
  5743. if (ord) return 'other';
  5744. return n == 1 && v0 ? 'one' : i >= 2 && i <= 4 && v0 ? 'few' : !v0 ? 'many' : 'other';
  5745. };
  5746. const sl = (n, ord) => {
  5747. const s = String(n).split('.'),
  5748. i = s[0],
  5749. v0 = !s[1],
  5750. i100 = i.slice(-2);
  5751. if (ord) return 'other';
  5752. return v0 && i100 == 1 ? 'one' : v0 && i100 == 2 ? 'two' : v0 && (i100 == 3 || i100 == 4) || !v0 ? 'few' : 'other';
  5753. };
  5754. const sma = f;
  5755. const smi = f;
  5756. const smj = f;
  5757. const smn = f;
  5758. const sms = f;
  5759. const sn = a;
  5760. const so = a;
  5761. const sq = (n, ord) => {
  5762. const s = String(n).split('.'),
  5763. t0 = Number(s[0]) == n,
  5764. n10 = t0 && s[0].slice(-1),
  5765. n100 = t0 && s[0].slice(-2);
  5766. if (ord) return n == 1 ? 'one' : n10 == 4 && n100 != 14 ? 'many' : 'other';
  5767. return n == 1 ? 'one' : 'other';
  5768. };
  5769. const sr = (n, ord) => {
  5770. const s = String(n).split('.'),
  5771. i = s[0],
  5772. f = s[1] || '',
  5773. v0 = !s[1],
  5774. i10 = i.slice(-1),
  5775. i100 = i.slice(-2),
  5776. f10 = f.slice(-1),
  5777. f100 = f.slice(-2);
  5778. if (ord) return 'other';
  5779. return v0 && i10 == 1 && i100 != 11 || f10 == 1 && f100 != 11 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) || f10 >= 2 && f10 <= 4 && (f100 < 12 || f100 > 14) ? 'few' : 'other';
  5780. };
  5781. const ss = a;
  5782. const ssy = a;
  5783. const st = a;
  5784. const su = e;
  5785. const sv = (n, ord) => {
  5786. const s = String(n).split('.'),
  5787. v0 = !s[1],
  5788. t0 = Number(s[0]) == n,
  5789. n10 = t0 && s[0].slice(-1),
  5790. n100 = t0 && s[0].slice(-2);
  5791. if (ord) return (n10 == 1 || n10 == 2) && n100 != 11 && n100 != 12 ? 'one' : 'other';
  5792. return n == 1 && v0 ? 'one' : 'other';
  5793. };
  5794. const sw = d;
  5795. const syr = a;
  5796. const ta = a;
  5797. const te = a;
  5798. const teo = a;
  5799. const th = e;
  5800. const ti = b;
  5801. const tig = a;
  5802. const tk = (n, ord) => {
  5803. const s = String(n).split('.'),
  5804. t0 = Number(s[0]) == n,
  5805. n10 = t0 && s[0].slice(-1);
  5806. if (ord) return n10 == 6 || n10 == 9 || n == 10 ? 'few' : 'other';
  5807. return n == 1 ? 'one' : 'other';
  5808. };
  5809. const tl = (n, ord) => {
  5810. const s = String(n).split('.'),
  5811. i = s[0],
  5812. f = s[1] || '',
  5813. v0 = !s[1],
  5814. i10 = i.slice(-1),
  5815. f10 = f.slice(-1);
  5816. if (ord) return n == 1 ? 'one' : 'other';
  5817. return v0 && (i == 1 || i == 2 || i == 3) || v0 && i10 != 4 && i10 != 6 && i10 != 9 || !v0 && f10 != 4 && f10 != 6 && f10 != 9 ? 'one' : 'other';
  5818. };
  5819. const tn = a;
  5820. const to = e;
  5821. const tpi = e;
  5822. const tr = a;
  5823. const ts = a;
  5824. const tzm = (n, ord) => {
  5825. const s = String(n).split('.'),
  5826. t0 = Number(s[0]) == n;
  5827. if (ord) return 'other';
  5828. return n == 0 || n == 1 || t0 && n >= 11 && n <= 99 ? 'one' : 'other';
  5829. };
  5830. const ug = a;
  5831. const uk = (n, ord) => {
  5832. const s = String(n).split('.'),
  5833. i = s[0],
  5834. v0 = !s[1],
  5835. t0 = Number(s[0]) == n,
  5836. n10 = t0 && s[0].slice(-1),
  5837. n100 = t0 && s[0].slice(-2),
  5838. i10 = i.slice(-1),
  5839. i100 = i.slice(-2);
  5840. if (ord) return n10 == 3 && n100 != 13 ? 'few' : 'other';
  5841. return v0 && i10 == 1 && i100 != 11 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) ? 'few' : v0 && i10 == 0 || v0 && i10 >= 5 && i10 <= 9 || v0 && i100 >= 11 && i100 <= 14 ? 'many' : 'other';
  5842. };
  5843. const und = e;
  5844. const ur = d;
  5845. const uz = a;
  5846. const ve = a;
  5847. const vec = (n, ord) => {
  5848. const s = String(n).split('.'),
  5849. i = s[0],
  5850. v0 = !s[1],
  5851. i1000000 = i.slice(-6);
  5852. if (ord) return n == 11 || n == 8 || n == 80 || n == 800 ? 'many' : 'other';
  5853. return n == 1 && v0 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
  5854. };
  5855. const vi = (n, ord) => {
  5856. if (ord) return n == 1 ? 'one' : 'other';
  5857. return 'other';
  5858. };
  5859. const vo = a;
  5860. const vun = a;
  5861. const wa = b;
  5862. const wae = a;
  5863. const wo = e;
  5864. const xh = a;
  5865. const xog = a;
  5866. const yi = d;
  5867. const yo = e;
  5868. const yue = e;
  5869. const zh = e;
  5870. const zu = c;
  5871. var Plurals = /*#__PURE__*/Object.freeze({
  5872. __proto__: null,
  5873. af: af,
  5874. ak: ak,
  5875. am: am,
  5876. an: an,
  5877. ar: ar,
  5878. ars: ars,
  5879. as: as,
  5880. asa: asa,
  5881. ast: ast,
  5882. az: az,
  5883. bal: bal,
  5884. be: be,
  5885. bem: bem,
  5886. bez: bez,
  5887. bg: bg,
  5888. bho: bho,
  5889. bm: bm,
  5890. bn: bn,
  5891. bo: bo,
  5892. br: br,
  5893. brx: brx,
  5894. bs: bs,
  5895. ca: ca,
  5896. ce: ce,
  5897. ceb: ceb,
  5898. cgg: cgg,
  5899. chr: chr,
  5900. ckb: ckb,
  5901. cs: cs,
  5902. cy: cy,
  5903. da: da,
  5904. de: de,
  5905. doi: doi,
  5906. dsb: dsb,
  5907. dv: dv,
  5908. dz: dz,
  5909. ee: ee,
  5910. el: el,
  5911. en: en,
  5912. eo: eo,
  5913. es: es,
  5914. et: et,
  5915. eu: eu,
  5916. fa: fa,
  5917. ff: ff,
  5918. fi: fi,
  5919. fil: fil,
  5920. fo: fo,
  5921. fr: fr,
  5922. fur: fur,
  5923. fy: fy,
  5924. ga: ga,
  5925. gd: gd,
  5926. gl: gl,
  5927. gsw: gsw,
  5928. gu: gu,
  5929. guw: guw,
  5930. gv: gv,
  5931. ha: ha,
  5932. haw: haw,
  5933. he: he,
  5934. hi: hi,
  5935. hnj: hnj,
  5936. hr: hr,
  5937. hsb: hsb,
  5938. hu: hu,
  5939. hy: hy,
  5940. ia: ia,
  5941. id: id,
  5942. ig: ig,
  5943. ii: ii,
  5944. io: io,
  5945. is: is,
  5946. it: it,
  5947. iu: iu,
  5948. ja: ja,
  5949. jbo: jbo,
  5950. jgo: jgo,
  5951. jmc: jmc,
  5952. jv: jv,
  5953. jw: jw,
  5954. ka: ka,
  5955. kab: kab,
  5956. kaj: kaj,
  5957. kcg: kcg,
  5958. kde: kde,
  5959. kea: kea,
  5960. kk: kk,
  5961. kkj: kkj,
  5962. kl: kl,
  5963. km: km,
  5964. kn: kn,
  5965. ko: ko,
  5966. ks: ks,
  5967. ksb: ksb,
  5968. ksh: ksh,
  5969. ku: ku,
  5970. kw: kw,
  5971. ky: ky,
  5972. lag: lag,
  5973. lb: lb,
  5974. lg: lg,
  5975. lij: lij,
  5976. lkt: lkt,
  5977. ln: ln,
  5978. lo: lo,
  5979. lt: lt,
  5980. lv: lv,
  5981. mas: mas,
  5982. mg: mg,
  5983. mgo: mgo,
  5984. mk: mk,
  5985. ml: ml,
  5986. mn: mn,
  5987. mo: mo,
  5988. mr: mr,
  5989. ms: ms,
  5990. mt: mt,
  5991. my: my,
  5992. nah: nah,
  5993. naq: naq,
  5994. nb: nb,
  5995. nd: nd,
  5996. ne: ne,
  5997. nl: nl,
  5998. nn: nn,
  5999. nnh: nnh,
  6000. no: no,
  6001. nqo: nqo,
  6002. nr: nr,
  6003. nso: nso,
  6004. ny: ny,
  6005. nyn: nyn,
  6006. om: om,
  6007. or: or,
  6008. os: os,
  6009. osa: osa,
  6010. pa: pa,
  6011. pap: pap,
  6012. pcm: pcm,
  6013. pl: pl,
  6014. prg: prg,
  6015. ps: ps,
  6016. pt: pt,
  6017. pt_PT: pt_PT,
  6018. rm: rm,
  6019. ro: ro,
  6020. rof: rof,
  6021. ru: ru,
  6022. rwk: rwk,
  6023. sah: sah,
  6024. saq: saq,
  6025. sat: sat,
  6026. sc: sc,
  6027. scn: scn,
  6028. sd: sd,
  6029. sdh: sdh,
  6030. se: se,
  6031. seh: seh,
  6032. ses: ses,
  6033. sg: sg,
  6034. sh: sh,
  6035. shi: shi,
  6036. si: si,
  6037. sk: sk,
  6038. sl: sl,
  6039. sma: sma,
  6040. smi: smi,
  6041. smj: smj,
  6042. smn: smn,
  6043. sms: sms,
  6044. sn: sn,
  6045. so: so,
  6046. sq: sq,
  6047. sr: sr,
  6048. ss: ss,
  6049. ssy: ssy,
  6050. st: st,
  6051. su: su,
  6052. sv: sv,
  6053. sw: sw,
  6054. syr: syr,
  6055. ta: ta,
  6056. te: te,
  6057. teo: teo,
  6058. th: th,
  6059. ti: ti,
  6060. tig: tig,
  6061. tk: tk,
  6062. tl: tl,
  6063. tn: tn,
  6064. to: to,
  6065. tpi: tpi,
  6066. tr: tr,
  6067. ts: ts,
  6068. tzm: tzm,
  6069. ug: ug,
  6070. uk: uk,
  6071. und: und,
  6072. ur: ur,
  6073. uz: uz,
  6074. ve: ve,
  6075. vec: vec,
  6076. vi: vi,
  6077. vo: vo,
  6078. vun: vun,
  6079. wa: wa,
  6080. wae: wae,
  6081. wo: wo,
  6082. xh: xh,
  6083. xog: xog,
  6084. yi: yi,
  6085. yo: yo,
  6086. yue: yue,
  6087. zh: zh,
  6088. zu: zu
  6089. });
  6090. function normalize(locale) {
  6091. if (typeof locale !== 'string' || locale.length < 2)
  6092. throw new RangeError("Invalid language tag: ".concat(locale));
  6093. if (locale.startsWith('pt-PT'))
  6094. return 'pt-PT';
  6095. var m = locale.match(/.+?(?=[-_])/);
  6096. return m ? m[0] : locale;
  6097. }
  6098. function getPlural(locale) {
  6099. if (typeof locale === 'function') {
  6100. var lc_1 = normalize(locale.name);
  6101. return {
  6102. isDefault: false,
  6103. id: identifier(lc_1),
  6104. lc: lc_1,
  6105. locale: locale.name,
  6106. getPlural: locale,
  6107. cardinals: locale.cardinals || [],
  6108. ordinals: locale.ordinals || []
  6109. };
  6110. }
  6111. var lc = normalize(locale);
  6112. var id = identifier(lc);
  6113. if (isPluralId(id)) {
  6114. return {
  6115. isDefault: true,
  6116. id: id,
  6117. lc: lc,
  6118. locale: locale,
  6119. getCardinal: Cardinals[id],
  6120. getPlural: Plurals[id],
  6121. cardinals: PluralCategories[id].cardinal,
  6122. ordinals: PluralCategories[id].ordinal
  6123. };
  6124. }
  6125. return null;
  6126. }
  6127. function getAllPlurals(firstLocale) {
  6128. var keys = Object.keys(Plurals).filter(function (key) { return key !== firstLocale; });
  6129. keys.unshift(firstLocale);
  6130. return keys.map(getPlural);
  6131. }
  6132. function hasPlural(locale) {
  6133. var lc = normalize(locale);
  6134. return identifier(lc) in Plurals;
  6135. }
  6136. function isPluralId(id) {
  6137. return id in Plurals;
  6138. }
  6139. var MessageFormat = (function () {
  6140. function MessageFormat(locale, options) {
  6141. this.plurals = [];
  6142. this.options = Object.assign({
  6143. biDiSupport: false,
  6144. currency: 'USD',
  6145. customFormatters: {},
  6146. localeCodeFromKey: null,
  6147. requireAllArguments: false,
  6148. returnType: 'string',
  6149. strict: (options && options.strictNumberSign) || false,
  6150. strictPluralKeys: true
  6151. }, options);
  6152. if (locale === '*') {
  6153. this.plurals = getAllPlurals(MessageFormat.defaultLocale);
  6154. }
  6155. else if (Array.isArray(locale)) {
  6156. this.plurals = locale.map(getPlural).filter(Boolean);
  6157. }
  6158. else if (locale) {
  6159. var pl = getPlural(locale);
  6160. if (pl)
  6161. this.plurals = [pl];
  6162. }
  6163. if (this.plurals.length === 0) {
  6164. var pl = getPlural(MessageFormat.defaultLocale);
  6165. this.plurals = [pl];
  6166. }
  6167. }
  6168. MessageFormat.escape = function (str, octothorpe) {
  6169. var esc = octothorpe ? /[#{}]/g : /[{}]/g;
  6170. return String(str).replace(esc, "'$&'");
  6171. };
  6172. MessageFormat.supportedLocalesOf = function (locales) {
  6173. var la = Array.isArray(locales) ? locales : [locales];
  6174. return la.filter(hasPlural);
  6175. };
  6176. MessageFormat.prototype.resolvedOptions = function () {
  6177. return __assign(__assign({}, this.options), { locale: this.plurals[0].locale, plurals: this.plurals });
  6178. };
  6179. MessageFormat.prototype.compile = function (message) {
  6180. var e_1, _a;
  6181. var compiler = new Compiler(this.options);
  6182. var fnBody = 'return ' + compiler.compile(message, this.plurals[0]);
  6183. var nfArgs = [];
  6184. var fnArgs = [];
  6185. try {
  6186. for (var _b = __values(Object.entries(compiler.runtime)), _c = _b.next(); !_c.done; _c = _b.next()) {
  6187. var _d = __read(_c.value, 2), key = _d[0], fmt = _d[1];
  6188. nfArgs.push(key);
  6189. fnArgs.push(fmt);
  6190. }
  6191. }
  6192. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  6193. finally {
  6194. try {
  6195. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  6196. }
  6197. finally { if (e_1) throw e_1.error; }
  6198. }
  6199. var fn = new (Function.bind.apply(Function, __spreadArray(__spreadArray([void 0], __read(nfArgs), false), [fnBody], false)))();
  6200. return fn.apply(void 0, __spreadArray([], __read(fnArgs), false));
  6201. };
  6202. MessageFormat.defaultLocale = 'en';
  6203. return MessageFormat;
  6204. }());
  6205. return MessageFormat;
  6206. }));