a zip code crypto-currency system good for red ONLY

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045
  1. /**
  2. * @license Angular v5.2.11
  3. * (c) 2010-2018 Google, Inc. https://angular.io/
  4. * License: MIT
  5. */
  6. import { Attribute, ChangeDetectorRef, ComponentFactoryResolver, Directive, ElementRef, EventEmitter, Host, Inject, Injectable, InjectionToken, Input, IterableDiffers, KeyValueDiffers, LOCALE_ID, NgModule, NgModuleRef, Optional, Pipe, Renderer2, TemplateRef, Version, ViewContainerRef, WrappedValue, isDevMode, ɵisListLikeIterable, ɵisObservable, ɵisPromise, ɵstringify } from '@angular/core';
  7. /**
  8. * @fileoverview added by tsickle
  9. * @suppress {checkTypes} checked by tsc
  10. */
  11. /**
  12. * @license
  13. * Copyright Google Inc. All Rights Reserved.
  14. *
  15. * Use of this source code is governed by an MIT-style license that can be
  16. * found in the LICENSE file at https://angular.io/license
  17. */
  18. /**
  19. * This class should not be used directly by an application developer. Instead, use
  20. * {\@link Location}.
  21. *
  22. * `PlatformLocation` encapsulates all calls to DOM apis, which allows the Router to be platform
  23. * agnostic.
  24. * This means that we can have different implementation of `PlatformLocation` for the different
  25. * platforms that angular supports. For example, `\@angular/platform-browser` provides an
  26. * implementation specific to the browser environment, while `\@angular/platform-webworker` provides
  27. * one suitable for use with web workers.
  28. *
  29. * The `PlatformLocation` class is used directly by all implementations of {\@link LocationStrategy}
  30. * when they need to interact with the DOM apis like pushState, popState, etc...
  31. *
  32. * {\@link LocationStrategy} in turn is used by the {\@link Location} service which is used directly
  33. * by the {\@link Router} in order to navigate between routes. Since all interactions between {\@link
  34. * Router} /
  35. * {\@link Location} / {\@link LocationStrategy} and DOM apis flow through the `PlatformLocation`
  36. * class they are all platform independent.
  37. *
  38. * \@stable
  39. * @abstract
  40. */
  41. class PlatformLocation {
  42. }
  43. /**
  44. * \@whatItDoes indicates when a location is initialized
  45. * \@experimental
  46. */
  47. const LOCATION_INITIALIZED = new InjectionToken('Location Initialized');
  48. /**
  49. * A serializable version of the event from onPopState or onHashChange
  50. *
  51. * \@experimental
  52. * @record
  53. */
  54. /**
  55. * \@experimental
  56. * @record
  57. */
  58. /**
  59. * @fileoverview added by tsickle
  60. * @suppress {checkTypes} checked by tsc
  61. */
  62. /**
  63. * @license
  64. * Copyright Google Inc. All Rights Reserved.
  65. *
  66. * Use of this source code is governed by an MIT-style license that can be
  67. * found in the LICENSE file at https://angular.io/license
  68. */
  69. /**
  70. * `LocationStrategy` is responsible for representing and reading route state
  71. * from the browser's URL. Angular provides two strategies:
  72. * {\@link HashLocationStrategy} and {\@link PathLocationStrategy}.
  73. *
  74. * This is used under the hood of the {\@link Location} service.
  75. *
  76. * Applications should use the {\@link Router} or {\@link Location} services to
  77. * interact with application route state.
  78. *
  79. * For instance, {\@link HashLocationStrategy} produces URLs like
  80. * `http://example.com#/foo`, and {\@link PathLocationStrategy} produces
  81. * `http://example.com/foo` as an equivalent URL.
  82. *
  83. * See these two classes for more.
  84. *
  85. * \@stable
  86. * @abstract
  87. */
  88. class LocationStrategy {
  89. }
  90. /**
  91. * The `APP_BASE_HREF` token represents the base href to be used with the
  92. * {\@link PathLocationStrategy}.
  93. *
  94. * If you're using {\@link PathLocationStrategy}, you must provide a provider to a string
  95. * representing the URL prefix that should be preserved when generating and recognizing
  96. * URLs.
  97. *
  98. * ### Example
  99. *
  100. * ```typescript
  101. * import {Component, NgModule} from '\@angular/core';
  102. * import {APP_BASE_HREF} from '\@angular/common';
  103. *
  104. * \@NgModule({
  105. * providers: [{provide: APP_BASE_HREF, useValue: '/my/app'}]
  106. * })
  107. * class AppModule {}
  108. * ```
  109. *
  110. * \@stable
  111. */
  112. const APP_BASE_HREF = new InjectionToken('appBaseHref');
  113. /**
  114. * @fileoverview added by tsickle
  115. * @suppress {checkTypes} checked by tsc
  116. */
  117. /**
  118. * @license
  119. * Copyright Google Inc. All Rights Reserved.
  120. *
  121. * Use of this source code is governed by an MIT-style license that can be
  122. * found in the LICENSE file at https://angular.io/license
  123. */
  124. /**
  125. * \@experimental
  126. * @record
  127. */
  128. /**
  129. * \@whatItDoes `Location` is a service that applications can use to interact with a browser's URL.
  130. * \@description
  131. * Depending on which {\@link LocationStrategy} is used, `Location` will either persist
  132. * to the URL's path or the URL's hash segment.
  133. *
  134. * Note: it's better to use {\@link Router#navigate} service to trigger route changes. Use
  135. * `Location` only if you need to interact with or create normalized URLs outside of
  136. * routing.
  137. *
  138. * `Location` is responsible for normalizing the URL against the application's base href.
  139. * A normalized URL is absolute from the URL host, includes the application's base href, and has no
  140. * trailing slash:
  141. * - `/my/app/user/123` is normalized
  142. * - `my/app/user/123` **is not** normalized
  143. * - `/my/app/user/123/` **is not** normalized
  144. *
  145. * ### Example
  146. * {\@example common/location/ts/path_location_component.ts region='LocationComponent'}
  147. * \@stable
  148. */
  149. class Location {
  150. /**
  151. * @param {?} platformStrategy
  152. */
  153. constructor(platformStrategy) {
  154. /**
  155. * \@internal
  156. */
  157. this._subject = new EventEmitter();
  158. this._platformStrategy = platformStrategy;
  159. const /** @type {?} */ browserBaseHref = this._platformStrategy.getBaseHref();
  160. this._baseHref = Location.stripTrailingSlash(_stripIndexHtml(browserBaseHref));
  161. this._platformStrategy.onPopState((ev) => {
  162. this._subject.emit({
  163. 'url': this.path(true),
  164. 'pop': true,
  165. 'type': ev.type,
  166. });
  167. });
  168. }
  169. /**
  170. * Returns the normalized URL path.
  171. * @param {?=} includeHash
  172. * @return {?}
  173. */
  174. path(includeHash = false) {
  175. return this.normalize(this._platformStrategy.path(includeHash));
  176. }
  177. /**
  178. * Normalizes the given path and compares to the current normalized path.
  179. * @param {?} path
  180. * @param {?=} query
  181. * @return {?}
  182. */
  183. isCurrentPathEqualTo(path, query = '') {
  184. return this.path() == this.normalize(path + Location.normalizeQueryParams(query));
  185. }
  186. /**
  187. * Given a string representing a URL, returns the normalized URL path without leading or
  188. * trailing slashes.
  189. * @param {?} url
  190. * @return {?}
  191. */
  192. normalize(url) {
  193. return Location.stripTrailingSlash(_stripBaseHref(this._baseHref, _stripIndexHtml(url)));
  194. }
  195. /**
  196. * Given a string representing a URL, returns the platform-specific external URL path.
  197. * If the given URL doesn't begin with a leading slash (`'/'`), this method adds one
  198. * before normalizing. This method will also add a hash if `HashLocationStrategy` is
  199. * used, or the `APP_BASE_HREF` if the `PathLocationStrategy` is in use.
  200. * @param {?} url
  201. * @return {?}
  202. */
  203. prepareExternalUrl(url) {
  204. if (url && url[0] !== '/') {
  205. url = '/' + url;
  206. }
  207. return this._platformStrategy.prepareExternalUrl(url);
  208. }
  209. /**
  210. * Changes the browsers URL to the normalized version of the given URL, and pushes a
  211. * new item onto the platform's history.
  212. * @param {?} path
  213. * @param {?=} query
  214. * @return {?}
  215. */
  216. go(path, query = '') {
  217. this._platformStrategy.pushState(null, '', path, query);
  218. }
  219. /**
  220. * Changes the browsers URL to the normalized version of the given URL, and replaces
  221. * the top item on the platform's history stack.
  222. * @param {?} path
  223. * @param {?=} query
  224. * @return {?}
  225. */
  226. replaceState(path, query = '') {
  227. this._platformStrategy.replaceState(null, '', path, query);
  228. }
  229. /**
  230. * Navigates forward in the platform's history.
  231. * @return {?}
  232. */
  233. forward() { this._platformStrategy.forward(); }
  234. /**
  235. * Navigates back in the platform's history.
  236. * @return {?}
  237. */
  238. back() { this._platformStrategy.back(); }
  239. /**
  240. * Subscribe to the platform's `popState` events.
  241. * @param {?} onNext
  242. * @param {?=} onThrow
  243. * @param {?=} onReturn
  244. * @return {?}
  245. */
  246. subscribe(onNext, onThrow, onReturn) {
  247. return this._subject.subscribe({ next: onNext, error: onThrow, complete: onReturn });
  248. }
  249. /**
  250. * Given a string of url parameters, prepend with '?' if needed, otherwise return parameters as
  251. * is.
  252. * @param {?} params
  253. * @return {?}
  254. */
  255. static normalizeQueryParams(params) {
  256. return params && params[0] !== '?' ? '?' + params : params;
  257. }
  258. /**
  259. * Given 2 parts of a url, join them with a slash if needed.
  260. * @param {?} start
  261. * @param {?} end
  262. * @return {?}
  263. */
  264. static joinWithSlash(start, end) {
  265. if (start.length == 0) {
  266. return end;
  267. }
  268. if (end.length == 0) {
  269. return start;
  270. }
  271. let /** @type {?} */ slashes = 0;
  272. if (start.endsWith('/')) {
  273. slashes++;
  274. }
  275. if (end.startsWith('/')) {
  276. slashes++;
  277. }
  278. if (slashes == 2) {
  279. return start + end.substring(1);
  280. }
  281. if (slashes == 1) {
  282. return start + end;
  283. }
  284. return start + '/' + end;
  285. }
  286. /**
  287. * If url has a trailing slash, remove it, otherwise return url as is. This
  288. * method looks for the first occurence of either #, ?, or the end of the
  289. * line as `/` characters after any of these should not be replaced.
  290. * @param {?} url
  291. * @return {?}
  292. */
  293. static stripTrailingSlash(url) {
  294. const /** @type {?} */ match = url.match(/#|\?|$/);
  295. const /** @type {?} */ pathEndIdx = match && match.index || url.length;
  296. const /** @type {?} */ droppedSlashIdx = pathEndIdx - (url[pathEndIdx - 1] === '/' ? 1 : 0);
  297. return url.slice(0, droppedSlashIdx) + url.slice(pathEndIdx);
  298. }
  299. }
  300. Location.decorators = [
  301. { type: Injectable },
  302. ];
  303. /** @nocollapse */
  304. Location.ctorParameters = () => [
  305. { type: LocationStrategy, },
  306. ];
  307. /**
  308. * @param {?} baseHref
  309. * @param {?} url
  310. * @return {?}
  311. */
  312. function _stripBaseHref(baseHref, url) {
  313. return baseHref && url.startsWith(baseHref) ? url.substring(baseHref.length) : url;
  314. }
  315. /**
  316. * @param {?} url
  317. * @return {?}
  318. */
  319. function _stripIndexHtml(url) {
  320. return url.replace(/\/index.html$/, '');
  321. }
  322. /**
  323. * @fileoverview added by tsickle
  324. * @suppress {checkTypes} checked by tsc
  325. */
  326. /**
  327. * @license
  328. * Copyright Google Inc. All Rights Reserved.
  329. *
  330. * Use of this source code is governed by an MIT-style license that can be
  331. * found in the LICENSE file at https://angular.io/license
  332. */
  333. /**
  334. * \@whatItDoes Use URL hash for storing application location data.
  335. * \@description
  336. * `HashLocationStrategy` is a {\@link LocationStrategy} used to configure the
  337. * {\@link Location} service to represent its state in the
  338. * [hash fragment](https://en.wikipedia.org/wiki/Uniform_Resource_Locator#Syntax)
  339. * of the browser's URL.
  340. *
  341. * For instance, if you call `location.go('/foo')`, the browser's URL will become
  342. * `example.com#/foo`.
  343. *
  344. * ### Example
  345. *
  346. * {\@example common/location/ts/hash_location_component.ts region='LocationComponent'}
  347. *
  348. * \@stable
  349. */
  350. class HashLocationStrategy extends LocationStrategy {
  351. /**
  352. * @param {?} _platformLocation
  353. * @param {?=} _baseHref
  354. */
  355. constructor(_platformLocation, _baseHref) {
  356. super();
  357. this._platformLocation = _platformLocation;
  358. this._baseHref = '';
  359. if (_baseHref != null) {
  360. this._baseHref = _baseHref;
  361. }
  362. }
  363. /**
  364. * @param {?} fn
  365. * @return {?}
  366. */
  367. onPopState(fn) {
  368. this._platformLocation.onPopState(fn);
  369. this._platformLocation.onHashChange(fn);
  370. }
  371. /**
  372. * @return {?}
  373. */
  374. getBaseHref() { return this._baseHref; }
  375. /**
  376. * @param {?=} includeHash
  377. * @return {?}
  378. */
  379. path(includeHash = false) {
  380. // the hash value is always prefixed with a `#`
  381. // and if it is empty then it will stay empty
  382. let /** @type {?} */ path = this._platformLocation.hash;
  383. if (path == null)
  384. path = '#';
  385. return path.length > 0 ? path.substring(1) : path;
  386. }
  387. /**
  388. * @param {?} internal
  389. * @return {?}
  390. */
  391. prepareExternalUrl(internal) {
  392. const /** @type {?} */ url = Location.joinWithSlash(this._baseHref, internal);
  393. return url.length > 0 ? ('#' + url) : url;
  394. }
  395. /**
  396. * @param {?} state
  397. * @param {?} title
  398. * @param {?} path
  399. * @param {?} queryParams
  400. * @return {?}
  401. */
  402. pushState(state, title, path, queryParams) {
  403. let /** @type {?} */ url = this.prepareExternalUrl(path + Location.normalizeQueryParams(queryParams));
  404. if (url.length == 0) {
  405. url = this._platformLocation.pathname;
  406. }
  407. this._platformLocation.pushState(state, title, url);
  408. }
  409. /**
  410. * @param {?} state
  411. * @param {?} title
  412. * @param {?} path
  413. * @param {?} queryParams
  414. * @return {?}
  415. */
  416. replaceState(state, title, path, queryParams) {
  417. let /** @type {?} */ url = this.prepareExternalUrl(path + Location.normalizeQueryParams(queryParams));
  418. if (url.length == 0) {
  419. url = this._platformLocation.pathname;
  420. }
  421. this._platformLocation.replaceState(state, title, url);
  422. }
  423. /**
  424. * @return {?}
  425. */
  426. forward() { this._platformLocation.forward(); }
  427. /**
  428. * @return {?}
  429. */
  430. back() { this._platformLocation.back(); }
  431. }
  432. HashLocationStrategy.decorators = [
  433. { type: Injectable },
  434. ];
  435. /** @nocollapse */
  436. HashLocationStrategy.ctorParameters = () => [
  437. { type: PlatformLocation, },
  438. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [APP_BASE_HREF,] },] },
  439. ];
  440. /**
  441. * @fileoverview added by tsickle
  442. * @suppress {checkTypes} checked by tsc
  443. */
  444. /**
  445. * @license
  446. * Copyright Google Inc. All Rights Reserved.
  447. *
  448. * Use of this source code is governed by an MIT-style license that can be
  449. * found in the LICENSE file at https://angular.io/license
  450. */
  451. /**
  452. * \@whatItDoes Use URL for storing application location data.
  453. * \@description
  454. * `PathLocationStrategy` is a {\@link LocationStrategy} used to configure the
  455. * {\@link Location} service to represent its state in the
  456. * [path](https://en.wikipedia.org/wiki/Uniform_Resource_Locator#Syntax) of the
  457. * browser's URL.
  458. *
  459. * If you're using `PathLocationStrategy`, you must provide a {\@link APP_BASE_HREF}
  460. * or add a base element to the document. This URL prefix that will be preserved
  461. * when generating and recognizing URLs.
  462. *
  463. * For instance, if you provide an `APP_BASE_HREF` of `'/my/app'` and call
  464. * `location.go('/foo')`, the browser's URL will become
  465. * `example.com/my/app/foo`.
  466. *
  467. * Similarly, if you add `<base href='/my/app'/>` to the document and call
  468. * `location.go('/foo')`, the browser's URL will become
  469. * `example.com/my/app/foo`.
  470. *
  471. * ### Example
  472. *
  473. * {\@example common/location/ts/path_location_component.ts region='LocationComponent'}
  474. *
  475. * \@stable
  476. */
  477. class PathLocationStrategy extends LocationStrategy {
  478. /**
  479. * @param {?} _platformLocation
  480. * @param {?=} href
  481. */
  482. constructor(_platformLocation, href) {
  483. super();
  484. this._platformLocation = _platformLocation;
  485. if (href == null) {
  486. href = this._platformLocation.getBaseHrefFromDOM();
  487. }
  488. if (href == null) {
  489. throw new Error(`No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document.`);
  490. }
  491. this._baseHref = href;
  492. }
  493. /**
  494. * @param {?} fn
  495. * @return {?}
  496. */
  497. onPopState(fn) {
  498. this._platformLocation.onPopState(fn);
  499. this._platformLocation.onHashChange(fn);
  500. }
  501. /**
  502. * @return {?}
  503. */
  504. getBaseHref() { return this._baseHref; }
  505. /**
  506. * @param {?} internal
  507. * @return {?}
  508. */
  509. prepareExternalUrl(internal) {
  510. return Location.joinWithSlash(this._baseHref, internal);
  511. }
  512. /**
  513. * @param {?=} includeHash
  514. * @return {?}
  515. */
  516. path(includeHash = false) {
  517. const /** @type {?} */ pathname = this._platformLocation.pathname +
  518. Location.normalizeQueryParams(this._platformLocation.search);
  519. const /** @type {?} */ hash = this._platformLocation.hash;
  520. return hash && includeHash ? `${pathname}${hash}` : pathname;
  521. }
  522. /**
  523. * @param {?} state
  524. * @param {?} title
  525. * @param {?} url
  526. * @param {?} queryParams
  527. * @return {?}
  528. */
  529. pushState(state, title, url, queryParams) {
  530. const /** @type {?} */ externalUrl = this.prepareExternalUrl(url + Location.normalizeQueryParams(queryParams));
  531. this._platformLocation.pushState(state, title, externalUrl);
  532. }
  533. /**
  534. * @param {?} state
  535. * @param {?} title
  536. * @param {?} url
  537. * @param {?} queryParams
  538. * @return {?}
  539. */
  540. replaceState(state, title, url, queryParams) {
  541. const /** @type {?} */ externalUrl = this.prepareExternalUrl(url + Location.normalizeQueryParams(queryParams));
  542. this._platformLocation.replaceState(state, title, externalUrl);
  543. }
  544. /**
  545. * @return {?}
  546. */
  547. forward() { this._platformLocation.forward(); }
  548. /**
  549. * @return {?}
  550. */
  551. back() { this._platformLocation.back(); }
  552. }
  553. PathLocationStrategy.decorators = [
  554. { type: Injectable },
  555. ];
  556. /** @nocollapse */
  557. PathLocationStrategy.ctorParameters = () => [
  558. { type: PlatformLocation, },
  559. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [APP_BASE_HREF,] },] },
  560. ];
  561. /**
  562. * @fileoverview added by tsickle
  563. * @suppress {checkTypes} checked by tsc
  564. */
  565. /**
  566. * @license
  567. * Copyright Google Inc. All Rights Reserved.
  568. *
  569. * Use of this source code is governed by an MIT-style license that can be
  570. * found in the LICENSE file at https://angular.io/license
  571. */
  572. /**
  573. * @fileoverview added by tsickle
  574. * @suppress {checkTypes} checked by tsc
  575. */
  576. /**
  577. * @license
  578. * Copyright Google Inc. All Rights Reserved.
  579. *
  580. * Use of this source code is governed by an MIT-style license that can be
  581. * found in the LICENSE file at https://angular.io/license
  582. */
  583. // THIS CODE IS GENERATED - DO NOT MODIFY
  584. // See angular/tools/gulp-tasks/cldr/extract.js
  585. /**
  586. * \@internal
  587. */
  588. const CURRENCIES = {
  589. 'AOA': [, 'Kz'],
  590. 'ARS': [, '$'],
  591. 'AUD': ['A$', '$'],
  592. 'BAM': [, 'KM'],
  593. 'BBD': [, '$'],
  594. 'BDT': [, '৳'],
  595. 'BMD': [, '$'],
  596. 'BND': [, '$'],
  597. 'BOB': [, 'Bs'],
  598. 'BRL': ['R$'],
  599. 'BSD': [, '$'],
  600. 'BWP': [, 'P'],
  601. 'BYN': [, 'р.'],
  602. 'BZD': [, '$'],
  603. 'CAD': ['CA$', '$'],
  604. 'CLP': [, '$'],
  605. 'CNY': ['CN¥', '¥'],
  606. 'COP': [, '$'],
  607. 'CRC': [, '₡'],
  608. 'CUC': [, '$'],
  609. 'CUP': [, '$'],
  610. 'CZK': [, 'Kč'],
  611. 'DKK': [, 'kr'],
  612. 'DOP': [, '$'],
  613. 'EGP': [, 'E£'],
  614. 'ESP': [, '₧'],
  615. 'EUR': ['€'],
  616. 'FJD': [, '$'],
  617. 'FKP': [, '£'],
  618. 'GBP': ['£'],
  619. 'GEL': [, '₾'],
  620. 'GIP': [, '£'],
  621. 'GNF': [, 'FG'],
  622. 'GTQ': [, 'Q'],
  623. 'GYD': [, '$'],
  624. 'HKD': ['HK$', '$'],
  625. 'HNL': [, 'L'],
  626. 'HRK': [, 'kn'],
  627. 'HUF': [, 'Ft'],
  628. 'IDR': [, 'Rp'],
  629. 'ILS': ['₪'],
  630. 'INR': ['₹'],
  631. 'ISK': [, 'kr'],
  632. 'JMD': [, '$'],
  633. 'JPY': ['¥'],
  634. 'KHR': [, '៛'],
  635. 'KMF': [, 'CF'],
  636. 'KPW': [, '₩'],
  637. 'KRW': ['₩'],
  638. 'KYD': [, '$'],
  639. 'KZT': [, '₸'],
  640. 'LAK': [, '₭'],
  641. 'LBP': [, 'L£'],
  642. 'LKR': [, 'Rs'],
  643. 'LRD': [, '$'],
  644. 'LTL': [, 'Lt'],
  645. 'LVL': [, 'Ls'],
  646. 'MGA': [, 'Ar'],
  647. 'MMK': [, 'K'],
  648. 'MNT': [, '₮'],
  649. 'MUR': [, 'Rs'],
  650. 'MXN': ['MX$', '$'],
  651. 'MYR': [, 'RM'],
  652. 'NAD': [, '$'],
  653. 'NGN': [, '₦'],
  654. 'NIO': [, 'C$'],
  655. 'NOK': [, 'kr'],
  656. 'NPR': [, 'Rs'],
  657. 'NZD': ['NZ$', '$'],
  658. 'PHP': [, '₱'],
  659. 'PKR': [, 'Rs'],
  660. 'PLN': [, 'zł'],
  661. 'PYG': [, '₲'],
  662. 'RON': [, 'lei'],
  663. 'RUB': [, '₽'],
  664. 'RUR': [, 'р.'],
  665. 'RWF': [, 'RF'],
  666. 'SBD': [, '$'],
  667. 'SEK': [, 'kr'],
  668. 'SGD': [, '$'],
  669. 'SHP': [, '£'],
  670. 'SRD': [, '$'],
  671. 'SSP': [, '£'],
  672. 'STD': [, 'Db'],
  673. 'SYP': [, '£'],
  674. 'THB': [, '฿'],
  675. 'TOP': [, 'T$'],
  676. 'TRY': [, '₺'],
  677. 'TTD': [, '$'],
  678. 'TWD': ['NT$', '$'],
  679. 'UAH': [, '₴'],
  680. 'USD': ['$'],
  681. 'UYU': [, '$'],
  682. 'VEF': [, 'Bs'],
  683. 'VND': ['₫'],
  684. 'XAF': ['FCFA'],
  685. 'XCD': ['EC$', '$'],
  686. 'XOF': ['CFA'],
  687. 'XPF': ['CFPF'],
  688. 'ZAR': [, 'R'],
  689. 'ZMW': [, 'ZK'],
  690. };
  691. /**
  692. * @fileoverview added by tsickle
  693. * @suppress {checkTypes} checked by tsc
  694. */
  695. /**
  696. * @license
  697. * Copyright Google Inc. All Rights Reserved.
  698. *
  699. * Use of this source code is governed by an MIT-style license that can be
  700. * found in the LICENSE file at https://angular.io/license
  701. */
  702. // THIS CODE IS GENERATED - DO NOT MODIFY
  703. // See angular/tools/gulp-tasks/cldr/extract.js
  704. /**
  705. * @param {?} n
  706. * @return {?}
  707. */
  708. function plural(n) {
  709. let /** @type {?} */ i = Math.floor(Math.abs(n)), /** @type {?} */ v = n.toString().replace(/^[^.]*\.?/, '').length;
  710. if (i === 1 && v === 0)
  711. return 1;
  712. return 5;
  713. }
  714. var localeEn = [
  715. 'en',
  716. [
  717. ['a', 'p'],
  718. ['AM', 'PM'],
  719. ],
  720. [
  721. ['AM', 'PM'],
  722. ,
  723. ],
  724. [
  725. ['S', 'M', 'T', 'W', 'T', 'F', 'S'], ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  726. ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  727. ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']
  728. ],
  729. ,
  730. [
  731. ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'],
  732. ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  733. [
  734. 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September',
  735. 'October', 'November', 'December'
  736. ]
  737. ],
  738. ,
  739. [['B', 'A'], ['BC', 'AD'], ['Before Christ', 'Anno Domini']], 0, [6, 0],
  740. ['M/d/yy', 'MMM d, y', 'MMMM d, y', 'EEEE, MMMM d, y'],
  741. ['h:mm a', 'h:mm:ss a', 'h:mm:ss a z', 'h:mm:ss a zzzz'],
  742. [
  743. '{1}, {0}',
  744. ,
  745. '{1} \'at\' {0}',
  746. ],
  747. ['.', ',', ';', '%', '+', '-', 'E', '×', '‰', '∞', 'NaN', ':'],
  748. ['#,##0.###', '#,##0%', '¤#,##0.00', '#E0'], '$', 'US Dollar', plural
  749. ];
  750. /**
  751. * @fileoverview added by tsickle
  752. * @suppress {checkTypes} checked by tsc
  753. */
  754. /**
  755. * @license
  756. * Copyright Google Inc. All Rights Reserved.
  757. *
  758. * Use of this source code is governed by an MIT-style license that can be
  759. * found in the LICENSE file at https://angular.io/license
  760. */
  761. /**
  762. * \@experimental i18n support is experimental.
  763. */
  764. const LOCALE_DATA = {};
  765. /**
  766. * Register global data to be used internally by Angular. See the
  767. * {\@linkDocs guide/i18n#i18n-pipes "I18n guide"} to know how to import additional locale data.
  768. *
  769. * \@experimental i18n support is experimental.
  770. * @param {?} data
  771. * @param {?=} localeId
  772. * @param {?=} extraData
  773. * @return {?}
  774. */
  775. function registerLocaleData(data, localeId, extraData) {
  776. if (typeof localeId !== 'string') {
  777. extraData = localeId;
  778. localeId = data[0 /* LocaleId */];
  779. }
  780. localeId = localeId.toLowerCase().replace(/_/g, '-');
  781. LOCALE_DATA[localeId] = data;
  782. if (extraData) {
  783. LOCALE_DATA[localeId][18 /* ExtraData */] = extraData;
  784. }
  785. }
  786. /**
  787. * @fileoverview added by tsickle
  788. * @suppress {checkTypes} checked by tsc
  789. */
  790. /**
  791. * @license
  792. * Copyright Google Inc. All Rights Reserved.
  793. *
  794. * Use of this source code is governed by an MIT-style license that can be
  795. * found in the LICENSE file at https://angular.io/license
  796. */
  797. /** @enum {number} */
  798. const NumberFormatStyle = {
  799. Decimal: 0,
  800. Percent: 1,
  801. Currency: 2,
  802. Scientific: 3,
  803. };
  804. NumberFormatStyle[NumberFormatStyle.Decimal] = "Decimal";
  805. NumberFormatStyle[NumberFormatStyle.Percent] = "Percent";
  806. NumberFormatStyle[NumberFormatStyle.Currency] = "Currency";
  807. NumberFormatStyle[NumberFormatStyle.Scientific] = "Scientific";
  808. /** @enum {number} */
  809. const Plural = {
  810. Zero: 0,
  811. One: 1,
  812. Two: 2,
  813. Few: 3,
  814. Many: 4,
  815. Other: 5,
  816. };
  817. Plural[Plural.Zero] = "Zero";
  818. Plural[Plural.One] = "One";
  819. Plural[Plural.Two] = "Two";
  820. Plural[Plural.Few] = "Few";
  821. Plural[Plural.Many] = "Many";
  822. Plural[Plural.Other] = "Other";
  823. /** @enum {number} */
  824. const FormStyle = {
  825. Format: 0,
  826. Standalone: 1,
  827. };
  828. FormStyle[FormStyle.Format] = "Format";
  829. FormStyle[FormStyle.Standalone] = "Standalone";
  830. /** @enum {number} */
  831. const TranslationWidth = {
  832. Narrow: 0,
  833. Abbreviated: 1,
  834. Wide: 2,
  835. Short: 3,
  836. };
  837. TranslationWidth[TranslationWidth.Narrow] = "Narrow";
  838. TranslationWidth[TranslationWidth.Abbreviated] = "Abbreviated";
  839. TranslationWidth[TranslationWidth.Wide] = "Wide";
  840. TranslationWidth[TranslationWidth.Short] = "Short";
  841. /** @enum {number} */
  842. const FormatWidth = {
  843. Short: 0,
  844. Medium: 1,
  845. Long: 2,
  846. Full: 3,
  847. };
  848. FormatWidth[FormatWidth.Short] = "Short";
  849. FormatWidth[FormatWidth.Medium] = "Medium";
  850. FormatWidth[FormatWidth.Long] = "Long";
  851. FormatWidth[FormatWidth.Full] = "Full";
  852. /** @enum {number} */
  853. const NumberSymbol = {
  854. Decimal: 0,
  855. Group: 1,
  856. List: 2,
  857. PercentSign: 3,
  858. PlusSign: 4,
  859. MinusSign: 5,
  860. Exponential: 6,
  861. SuperscriptingExponent: 7,
  862. PerMille: 8,
  863. Infinity: 9,
  864. NaN: 10,
  865. TimeSeparator: 11,
  866. CurrencyDecimal: 12,
  867. CurrencyGroup: 13,
  868. };
  869. NumberSymbol[NumberSymbol.Decimal] = "Decimal";
  870. NumberSymbol[NumberSymbol.Group] = "Group";
  871. NumberSymbol[NumberSymbol.List] = "List";
  872. NumberSymbol[NumberSymbol.PercentSign] = "PercentSign";
  873. NumberSymbol[NumberSymbol.PlusSign] = "PlusSign";
  874. NumberSymbol[NumberSymbol.MinusSign] = "MinusSign";
  875. NumberSymbol[NumberSymbol.Exponential] = "Exponential";
  876. NumberSymbol[NumberSymbol.SuperscriptingExponent] = "SuperscriptingExponent";
  877. NumberSymbol[NumberSymbol.PerMille] = "PerMille";
  878. NumberSymbol[NumberSymbol.Infinity] = "Infinity";
  879. NumberSymbol[NumberSymbol.NaN] = "NaN";
  880. NumberSymbol[NumberSymbol.TimeSeparator] = "TimeSeparator";
  881. NumberSymbol[NumberSymbol.CurrencyDecimal] = "CurrencyDecimal";
  882. NumberSymbol[NumberSymbol.CurrencyGroup] = "CurrencyGroup";
  883. /** @enum {number} */
  884. const WeekDay = {
  885. Sunday: 0,
  886. Monday: 1,
  887. Tuesday: 2,
  888. Wednesday: 3,
  889. Thursday: 4,
  890. Friday: 5,
  891. Saturday: 6,
  892. };
  893. WeekDay[WeekDay.Sunday] = "Sunday";
  894. WeekDay[WeekDay.Monday] = "Monday";
  895. WeekDay[WeekDay.Tuesday] = "Tuesday";
  896. WeekDay[WeekDay.Wednesday] = "Wednesday";
  897. WeekDay[WeekDay.Thursday] = "Thursday";
  898. WeekDay[WeekDay.Friday] = "Friday";
  899. WeekDay[WeekDay.Saturday] = "Saturday";
  900. /**
  901. * The locale id for the chosen locale (e.g `en-GB`).
  902. *
  903. * \@experimental i18n support is experimental.
  904. * @param {?} locale
  905. * @return {?}
  906. */
  907. function getLocaleId(locale) {
  908. return findLocaleData(locale)[0 /* LocaleId */];
  909. }
  910. /**
  911. * Periods of the day (e.g. `[AM, PM]` for en-US).
  912. *
  913. * \@experimental i18n support is experimental.
  914. * @param {?} locale
  915. * @param {?} formStyle
  916. * @param {?} width
  917. * @return {?}
  918. */
  919. function getLocaleDayPeriods(locale, formStyle, width) {
  920. const /** @type {?} */ data = findLocaleData(locale);
  921. const /** @type {?} */ amPmData = /** @type {?} */ ([data[1 /* DayPeriodsFormat */], data[2 /* DayPeriodsStandalone */]]);
  922. const /** @type {?} */ amPm = getLastDefinedValue(amPmData, formStyle);
  923. return getLastDefinedValue(amPm, width);
  924. }
  925. /**
  926. * Days of the week for the Gregorian calendar (e.g. `[Sunday, Monday, ... Saturday]` for en-US).
  927. *
  928. * \@experimental i18n support is experimental.
  929. * @param {?} locale
  930. * @param {?} formStyle
  931. * @param {?} width
  932. * @return {?}
  933. */
  934. function getLocaleDayNames(locale, formStyle, width) {
  935. const /** @type {?} */ data = findLocaleData(locale);
  936. const /** @type {?} */ daysData = /** @type {?} */ ([data[3 /* DaysFormat */], data[4 /* DaysStandalone */]]);
  937. const /** @type {?} */ days = getLastDefinedValue(daysData, formStyle);
  938. return getLastDefinedValue(days, width);
  939. }
  940. /**
  941. * Months of the year for the Gregorian calendar (e.g. `[January, February, ...]` for en-US).
  942. *
  943. * \@experimental i18n support is experimental.
  944. * @param {?} locale
  945. * @param {?} formStyle
  946. * @param {?} width
  947. * @return {?}
  948. */
  949. function getLocaleMonthNames(locale, formStyle, width) {
  950. const /** @type {?} */ data = findLocaleData(locale);
  951. const /** @type {?} */ monthsData = /** @type {?} */ ([data[5 /* MonthsFormat */], data[6 /* MonthsStandalone */]]);
  952. const /** @type {?} */ months = getLastDefinedValue(monthsData, formStyle);
  953. return getLastDefinedValue(months, width);
  954. }
  955. /**
  956. * Eras for the Gregorian calendar (e.g. AD/BC).
  957. *
  958. * \@experimental i18n support is experimental.
  959. * @param {?} locale
  960. * @param {?} width
  961. * @return {?}
  962. */
  963. function getLocaleEraNames(locale, width) {
  964. const /** @type {?} */ data = findLocaleData(locale);
  965. const /** @type {?} */ erasData = /** @type {?} */ (data[7 /* Eras */]);
  966. return getLastDefinedValue(erasData, width);
  967. }
  968. /**
  969. * First day of the week for this locale, based on english days (Sunday = 0, Monday = 1, ...).
  970. * For example in french the value would be 1 because the first day of the week is Monday.
  971. *
  972. * \@experimental i18n support is experimental.
  973. * @param {?} locale
  974. * @return {?}
  975. */
  976. function getLocaleFirstDayOfWeek(locale) {
  977. const /** @type {?} */ data = findLocaleData(locale);
  978. return data[8 /* FirstDayOfWeek */];
  979. }
  980. /**
  981. * Range of days in the week that represent the week-end for this locale, based on english days
  982. * (Sunday = 0, Monday = 1, ...).
  983. * For example in english the value would be [6,0] for Saturday to Sunday.
  984. *
  985. * \@experimental i18n support is experimental.
  986. * @param {?} locale
  987. * @return {?}
  988. */
  989. function getLocaleWeekEndRange(locale) {
  990. const /** @type {?} */ data = findLocaleData(locale);
  991. return data[9 /* WeekendRange */];
  992. }
  993. /**
  994. * Date format that depends on the locale.
  995. *
  996. * There are four basic date formats:
  997. * - `full` should contain long-weekday (EEEE), year (y), long-month (MMMM), day (d).
  998. *
  999. * For example, English uses `EEEE, MMMM d, y`, corresponding to a date like
  1000. * "Tuesday, September 14, 1999".
  1001. *
  1002. * - `long` should contain year, long-month, day.
  1003. *
  1004. * For example, `MMMM d, y`, corresponding to a date like "September 14, 1999".
  1005. *
  1006. * - `medium` should contain year, abbreviated-month (MMM), day.
  1007. *
  1008. * For example, `MMM d, y`, corresponding to a date like "Sep 14, 1999".
  1009. * For languages that do not use abbreviated months, use the numeric month (MM/M). For example,
  1010. * `y/MM/dd`, corresponding to a date like "1999/09/14".
  1011. *
  1012. * - `short` should contain year, numeric-month (MM/M), and day.
  1013. *
  1014. * For example, `M/d/yy`, corresponding to a date like "9/14/99".
  1015. *
  1016. * \@experimental i18n support is experimental.
  1017. * @param {?} locale
  1018. * @param {?} width
  1019. * @return {?}
  1020. */
  1021. function getLocaleDateFormat(locale, width) {
  1022. const /** @type {?} */ data = findLocaleData(locale);
  1023. return getLastDefinedValue(data[10 /* DateFormat */], width);
  1024. }
  1025. /**
  1026. * Time format that depends on the locale.
  1027. *
  1028. * The standard formats include four basic time formats:
  1029. * - `full` should contain hour (h/H), minute (mm), second (ss), and zone (zzzz).
  1030. * - `long` should contain hour, minute, second, and zone (z)
  1031. * - `medium` should contain hour, minute, second.
  1032. * - `short` should contain hour, minute.
  1033. *
  1034. * Note: The patterns depend on whether the main country using your language uses 12-hour time or
  1035. * not:
  1036. * - For 12-hour time, use a pattern like `hh:mm a` using h to mean a 12-hour clock cycle running
  1037. * 1 through 12 (midnight plus 1 minute is 12:01), or using K to mean a 12-hour clock cycle
  1038. * running 0 through 11 (midnight plus 1 minute is 0:01).
  1039. * - For 24-hour time, use a pattern like `HH:mm` using H to mean a 24-hour clock cycle running 0
  1040. * through 23 (midnight plus 1 minute is 0:01), or using k to mean a 24-hour clock cycle running
  1041. * 1 through 24 (midnight plus 1 minute is 24:01).
  1042. *
  1043. * \@experimental i18n support is experimental.
  1044. * @param {?} locale
  1045. * @param {?} width
  1046. * @return {?}
  1047. */
  1048. function getLocaleTimeFormat(locale, width) {
  1049. const /** @type {?} */ data = findLocaleData(locale);
  1050. return getLastDefinedValue(data[11 /* TimeFormat */], width);
  1051. }
  1052. /**
  1053. * Date-time format that depends on the locale.
  1054. *
  1055. * The date-time pattern shows how to combine separate patterns for date (represented by {1})
  1056. * and time (represented by {0}) into a single pattern. It usually doesn't need to be changed.
  1057. * What you want to pay attention to are:
  1058. * - possibly removing a space for languages that don't use it, such as many East Asian languages
  1059. * - possibly adding a comma, other punctuation, or a combining word
  1060. *
  1061. * For example:
  1062. * - English uses `{1} 'at' {0}` or `{1}, {0}` (depending on date style), while Japanese uses
  1063. * `{1}{0}`.
  1064. * - An English formatted date-time using the combining pattern `{1}, {0}` could be
  1065. * `Dec 10, 2010, 3:59:49 PM`. Notice the comma and space between the date portion and the time
  1066. * portion.
  1067. *
  1068. * There are four formats (`full`, `long`, `medium`, `short`); the determination of which to use
  1069. * is normally based on the date style. For example, if the date has a full month and weekday
  1070. * name, the full combining pattern will be used to combine that with a time. If the date has
  1071. * numeric month, the short version of the combining pattern will be used to combine that with a
  1072. * time. English uses `{1} 'at' {0}` for full and long styles, and `{1}, {0}` for medium and short
  1073. * styles.
  1074. *
  1075. * \@experimental i18n support is experimental.
  1076. * @param {?} locale
  1077. * @param {?} width
  1078. * @return {?}
  1079. */
  1080. function getLocaleDateTimeFormat(locale, width) {
  1081. const /** @type {?} */ data = findLocaleData(locale);
  1082. const /** @type {?} */ dateTimeFormatData = /** @type {?} */ (data[12 /* DateTimeFormat */]);
  1083. return getLastDefinedValue(dateTimeFormatData, width);
  1084. }
  1085. /**
  1086. * Number symbol that can be used to replace placeholders in number formats.
  1087. * See {\@link NumberSymbol} for more information.
  1088. *
  1089. * \@experimental i18n support is experimental.
  1090. * @param {?} locale
  1091. * @param {?} symbol
  1092. * @return {?}
  1093. */
  1094. function getLocaleNumberSymbol(locale, symbol) {
  1095. const /** @type {?} */ data = findLocaleData(locale);
  1096. const /** @type {?} */ res = data[13 /* NumberSymbols */][symbol];
  1097. if (typeof res === 'undefined') {
  1098. if (symbol === NumberSymbol.CurrencyDecimal) {
  1099. return data[13 /* NumberSymbols */][NumberSymbol.Decimal];
  1100. }
  1101. else if (symbol === NumberSymbol.CurrencyGroup) {
  1102. return data[13 /* NumberSymbols */][NumberSymbol.Group];
  1103. }
  1104. }
  1105. return res;
  1106. }
  1107. /**
  1108. * Number format that depends on the locale.
  1109. *
  1110. * Numbers are formatted using patterns, like `#,###.00`. For example, the pattern `#,###.00`
  1111. * when used to format the number 12345.678 could result in "12'345,67". That would happen if the
  1112. * grouping separator for your language is an apostrophe, and the decimal separator is a comma.
  1113. *
  1114. * <b>Important:</b> The characters `.` `,` `0` `#` (and others below) are special placeholders;
  1115. * they stand for the decimal separator, and so on, and are NOT real characters.
  1116. * You must NOT "translate" the placeholders; for example, don't change `.` to `,` even though in
  1117. * your language the decimal point is written with a comma. The symbols should be replaced by the
  1118. * local equivalents, using the Number Symbols for your language.
  1119. *
  1120. * Here are the special characters used in number patterns:
  1121. *
  1122. * | Symbol | Meaning |
  1123. * |--------|---------|
  1124. * | . | Replaced automatically by the character used for the decimal point. |
  1125. * | , | Replaced by the "grouping" (thousands) separator. |
  1126. * | 0 | Replaced by a digit (or zero if there aren't enough digits). |
  1127. * | # | Replaced by a digit (or nothing if there aren't enough). |
  1128. * | ¤ | This will be replaced by a currency symbol, such as $ or USD. |
  1129. * | % | This marks a percent format. The % symbol may change position, but must be retained. |
  1130. * | E | This marks a scientific format. The E symbol may change position, but must be retained. |
  1131. * | ' | Special characters used as literal characters are quoted with ASCII single quotes. |
  1132. *
  1133. * You can find more information
  1134. * [on the CLDR website](http://cldr.unicode.org/translation/number-patterns)
  1135. *
  1136. * \@experimental i18n support is experimental.
  1137. * @param {?} locale
  1138. * @param {?} type
  1139. * @return {?}
  1140. */
  1141. function getLocaleNumberFormat(locale, type) {
  1142. const /** @type {?} */ data = findLocaleData(locale);
  1143. return data[14 /* NumberFormats */][type];
  1144. }
  1145. /**
  1146. * The symbol used to represent the currency for the main country using this locale (e.g. $ for
  1147. * the locale en-US).
  1148. * The symbol will be `null` if the main country cannot be determined.
  1149. *
  1150. * \@experimental i18n support is experimental.
  1151. * @param {?} locale
  1152. * @return {?}
  1153. */
  1154. function getLocaleCurrencySymbol(locale) {
  1155. const /** @type {?} */ data = findLocaleData(locale);
  1156. return data[15 /* CurrencySymbol */] || null;
  1157. }
  1158. /**
  1159. * The name of the currency for the main country using this locale (e.g. USD for the locale
  1160. * en-US).
  1161. * The name will be `null` if the main country cannot be determined.
  1162. *
  1163. * \@experimental i18n support is experimental.
  1164. * @param {?} locale
  1165. * @return {?}
  1166. */
  1167. function getLocaleCurrencyName(locale) {
  1168. const /** @type {?} */ data = findLocaleData(locale);
  1169. return data[16 /* CurrencyName */] || null;
  1170. }
  1171. /**
  1172. * The locale plural function used by ICU expressions to determine the plural case to use.
  1173. * See {\@link NgPlural} for more information.
  1174. *
  1175. * \@experimental i18n support is experimental.
  1176. * @param {?} locale
  1177. * @return {?}
  1178. */
  1179. function getLocalePluralCase(locale) {
  1180. const /** @type {?} */ data = findLocaleData(locale);
  1181. return data[17 /* PluralCase */];
  1182. }
  1183. /**
  1184. * @param {?} data
  1185. * @return {?}
  1186. */
  1187. function checkFullData(data) {
  1188. if (!data[18 /* ExtraData */]) {
  1189. throw new Error(`Missing extra locale data for the locale "${data[0 /* LocaleId */]}". Use "registerLocaleData" to load new data. See the "I18n guide" on angular.io to know more.`);
  1190. }
  1191. }
  1192. /**
  1193. * Rules used to determine which day period to use (See `dayPeriods` below).
  1194. * The rules can either be an array or a single value. If it's an array, consider it as "from"
  1195. * and "to". If it's a single value then it means that the period is only valid at this exact
  1196. * value.
  1197. * There is always the same number of rules as the number of day periods, which means that the
  1198. * first rule is applied to the first day period and so on.
  1199. * You should fallback to AM/PM when there are no rules available.
  1200. *
  1201. * Note: this is only available if you load the full locale data.
  1202. * See the {\@linkDocs guide/i18n#i18n-pipes "I18n guide"} to know how to import additional locale
  1203. * data.
  1204. *
  1205. * \@experimental i18n support is experimental.
  1206. * @param {?} locale
  1207. * @return {?}
  1208. */
  1209. function getLocaleExtraDayPeriodRules(locale) {
  1210. const /** @type {?} */ data = findLocaleData(locale);
  1211. checkFullData(data);
  1212. const /** @type {?} */ rules = data[18 /* ExtraData */][2 /* ExtraDayPeriodsRules */] || [];
  1213. return rules.map((rule) => {
  1214. if (typeof rule === 'string') {
  1215. return extractTime(rule);
  1216. }
  1217. return [extractTime(rule[0]), extractTime(rule[1])];
  1218. });
  1219. }
  1220. /**
  1221. * Day Periods indicate roughly how the day is broken up in different languages (e.g. morning,
  1222. * noon, afternoon, midnight, ...).
  1223. * You should use the function {\@link getLocaleExtraDayPeriodRules} to determine which period to
  1224. * use.
  1225. * You should fallback to AM/PM when there are no day periods available.
  1226. *
  1227. * Note: this is only available if you load the full locale data.
  1228. * See the {\@linkDocs guide/i18n#i18n-pipes "I18n guide"} to know how to import additional locale
  1229. * data.
  1230. *
  1231. * \@experimental i18n support is experimental.
  1232. * @param {?} locale
  1233. * @param {?} formStyle
  1234. * @param {?} width
  1235. * @return {?}
  1236. */
  1237. function getLocaleExtraDayPeriods(locale, formStyle, width) {
  1238. const /** @type {?} */ data = findLocaleData(locale);
  1239. checkFullData(data);
  1240. const /** @type {?} */ dayPeriodsData = /** @type {?} */ ([
  1241. data[18 /* ExtraData */][0 /* ExtraDayPeriodFormats */],
  1242. data[18 /* ExtraData */][1 /* ExtraDayPeriodStandalone */]
  1243. ]);
  1244. const /** @type {?} */ dayPeriods = getLastDefinedValue(dayPeriodsData, formStyle) || [];
  1245. return getLastDefinedValue(dayPeriods, width) || [];
  1246. }
  1247. /**
  1248. * Returns the first value that is defined in an array, going backwards.
  1249. *
  1250. * To avoid repeating the same data (e.g. when "format" and "standalone" are the same) we only
  1251. * add the first one to the locale data arrays, the other ones are only defined when different.
  1252. * We use this function to retrieve the first defined value.
  1253. *
  1254. * \@experimental i18n support is experimental.
  1255. * @template T
  1256. * @param {?} data
  1257. * @param {?} index
  1258. * @return {?}
  1259. */
  1260. function getLastDefinedValue(data, index) {
  1261. for (let /** @type {?} */ i = index; i > -1; i--) {
  1262. if (typeof data[i] !== 'undefined') {
  1263. return data[i];
  1264. }
  1265. }
  1266. throw new Error('Locale data API: locale data undefined');
  1267. }
  1268. /**
  1269. * Extract the hours and minutes from a string like "15:45"
  1270. * @param {?} time
  1271. * @return {?}
  1272. */
  1273. function extractTime(time) {
  1274. const [h, m] = time.split(':');
  1275. return { hours: +h, minutes: +m };
  1276. }
  1277. /**
  1278. * Finds the locale data for a locale id
  1279. *
  1280. * \@experimental i18n support is experimental.
  1281. * @param {?} locale
  1282. * @return {?}
  1283. */
  1284. function findLocaleData(locale) {
  1285. const /** @type {?} */ normalizedLocale = locale.toLowerCase().replace(/_/g, '-');
  1286. let /** @type {?} */ match = LOCALE_DATA[normalizedLocale];
  1287. if (match) {
  1288. return match;
  1289. }
  1290. // let's try to find a parent locale
  1291. const /** @type {?} */ parentLocale = normalizedLocale.split('-')[0];
  1292. match = LOCALE_DATA[parentLocale];
  1293. if (match) {
  1294. return match;
  1295. }
  1296. if (parentLocale === 'en') {
  1297. return localeEn;
  1298. }
  1299. throw new Error(`Missing locale data for the locale "${locale}".`);
  1300. }
  1301. /**
  1302. * Return the currency symbol for a given currency code, or the code if no symbol available
  1303. * (e.g.: format narrow = $, format wide = US$, code = USD)
  1304. *
  1305. * \@experimental i18n support is experimental.
  1306. * @param {?} code
  1307. * @param {?} format
  1308. * @return {?}
  1309. */
  1310. function getCurrencySymbol(code, format) {
  1311. const /** @type {?} */ currency = CURRENCIES[code] || [];
  1312. const /** @type {?} */ symbolNarrow = currency[1];
  1313. if (format === 'narrow' && typeof symbolNarrow === 'string') {
  1314. return symbolNarrow;
  1315. }
  1316. return currency[0] || code;
  1317. }
  1318. /**
  1319. * @fileoverview added by tsickle
  1320. * @suppress {checkTypes} checked by tsc
  1321. */
  1322. /**
  1323. * @license
  1324. * Copyright Google Inc. All Rights Reserved.
  1325. *
  1326. * Use of this source code is governed by an MIT-style license that can be
  1327. * found in the LICENSE file at https://angular.io/license
  1328. */
  1329. /**
  1330. * @deprecated from v5
  1331. */
  1332. const DEPRECATED_PLURAL_FN = new InjectionToken('UseV4Plurals');
  1333. /**
  1334. * \@experimental
  1335. * @abstract
  1336. */
  1337. class NgLocalization {
  1338. }
  1339. /**
  1340. * Returns the plural category for a given value.
  1341. * - "=value" when the case exists,
  1342. * - the plural category otherwise
  1343. * @param {?} value
  1344. * @param {?} cases
  1345. * @param {?} ngLocalization
  1346. * @param {?=} locale
  1347. * @return {?}
  1348. */
  1349. function getPluralCategory(value, cases, ngLocalization, locale) {
  1350. let /** @type {?} */ key = `=${value}`;
  1351. if (cases.indexOf(key) > -1) {
  1352. return key;
  1353. }
  1354. key = ngLocalization.getPluralCategory(value, locale);
  1355. if (cases.indexOf(key) > -1) {
  1356. return key;
  1357. }
  1358. if (cases.indexOf('other') > -1) {
  1359. return 'other';
  1360. }
  1361. throw new Error(`No plural message found for value "${value}"`);
  1362. }
  1363. /**
  1364. * Returns the plural case based on the locale
  1365. *
  1366. * \@experimental
  1367. */
  1368. class NgLocaleLocalization extends NgLocalization {
  1369. /**
  1370. * @param {?} locale
  1371. * @param {?=} deprecatedPluralFn
  1372. */
  1373. constructor(locale, /** @deprecated from v5 */
  1374. deprecatedPluralFn) {
  1375. super();
  1376. this.locale = locale;
  1377. this.deprecatedPluralFn = deprecatedPluralFn;
  1378. }
  1379. /**
  1380. * @param {?} value
  1381. * @param {?=} locale
  1382. * @return {?}
  1383. */
  1384. getPluralCategory(value, locale) {
  1385. const /** @type {?} */ plural = this.deprecatedPluralFn ? this.deprecatedPluralFn(locale || this.locale, value) :
  1386. getLocalePluralCase(locale || this.locale)(value);
  1387. switch (plural) {
  1388. case Plural.Zero:
  1389. return 'zero';
  1390. case Plural.One:
  1391. return 'one';
  1392. case Plural.Two:
  1393. return 'two';
  1394. case Plural.Few:
  1395. return 'few';
  1396. case Plural.Many:
  1397. return 'many';
  1398. default:
  1399. return 'other';
  1400. }
  1401. }
  1402. }
  1403. NgLocaleLocalization.decorators = [
  1404. { type: Injectable },
  1405. ];
  1406. /** @nocollapse */
  1407. NgLocaleLocalization.ctorParameters = () => [
  1408. { type: undefined, decorators: [{ type: Inject, args: [LOCALE_ID,] },] },
  1409. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DEPRECATED_PLURAL_FN,] },] },
  1410. ];
  1411. /**
  1412. * Returns the plural case based on the locale
  1413. *
  1414. * @deprecated from v5 the plural case function is in locale data files common/locales/*.ts
  1415. * \@experimental
  1416. * @param {?} locale
  1417. * @param {?} nLike
  1418. * @return {?}
  1419. */
  1420. function getPluralCase(locale, nLike) {
  1421. // TODO(vicb): lazy compute
  1422. if (typeof nLike === 'string') {
  1423. nLike = parseInt(/** @type {?} */ (nLike), 10);
  1424. }
  1425. const /** @type {?} */ n = /** @type {?} */ (nLike);
  1426. const /** @type {?} */ nDecimal = n.toString().replace(/^[^.]*\.?/, '');
  1427. const /** @type {?} */ i = Math.floor(Math.abs(n));
  1428. const /** @type {?} */ v = nDecimal.length;
  1429. const /** @type {?} */ f = parseInt(nDecimal, 10);
  1430. const /** @type {?} */ t = parseInt(n.toString().replace(/^[^.]*\.?|0+$/g, ''), 10) || 0;
  1431. const /** @type {?} */ lang = locale.split('-')[0].toLowerCase();
  1432. switch (lang) {
  1433. case 'af':
  1434. case 'asa':
  1435. case 'az':
  1436. case 'bem':
  1437. case 'bez':
  1438. case 'bg':
  1439. case 'brx':
  1440. case 'ce':
  1441. case 'cgg':
  1442. case 'chr':
  1443. case 'ckb':
  1444. case 'ee':
  1445. case 'el':
  1446. case 'eo':
  1447. case 'es':
  1448. case 'eu':
  1449. case 'fo':
  1450. case 'fur':
  1451. case 'gsw':
  1452. case 'ha':
  1453. case 'haw':
  1454. case 'hu':
  1455. case 'jgo':
  1456. case 'jmc':
  1457. case 'ka':
  1458. case 'kk':
  1459. case 'kkj':
  1460. case 'kl':
  1461. case 'ks':
  1462. case 'ksb':
  1463. case 'ky':
  1464. case 'lb':
  1465. case 'lg':
  1466. case 'mas':
  1467. case 'mgo':
  1468. case 'ml':
  1469. case 'mn':
  1470. case 'nb':
  1471. case 'nd':
  1472. case 'ne':
  1473. case 'nn':
  1474. case 'nnh':
  1475. case 'nyn':
  1476. case 'om':
  1477. case 'or':
  1478. case 'os':
  1479. case 'ps':
  1480. case 'rm':
  1481. case 'rof':
  1482. case 'rwk':
  1483. case 'saq':
  1484. case 'seh':
  1485. case 'sn':
  1486. case 'so':
  1487. case 'sq':
  1488. case 'ta':
  1489. case 'te':
  1490. case 'teo':
  1491. case 'tk':
  1492. case 'tr':
  1493. case 'ug':
  1494. case 'uz':
  1495. case 'vo':
  1496. case 'vun':
  1497. case 'wae':
  1498. case 'xog':
  1499. if (n === 1)
  1500. return Plural.One;
  1501. return Plural.Other;
  1502. case 'ak':
  1503. case 'ln':
  1504. case 'mg':
  1505. case 'pa':
  1506. case 'ti':
  1507. if (n === Math.floor(n) && n >= 0 && n <= 1)
  1508. return Plural.One;
  1509. return Plural.Other;
  1510. case 'am':
  1511. case 'as':
  1512. case 'bn':
  1513. case 'fa':
  1514. case 'gu':
  1515. case 'hi':
  1516. case 'kn':
  1517. case 'mr':
  1518. case 'zu':
  1519. if (i === 0 || n === 1)
  1520. return Plural.One;
  1521. return Plural.Other;
  1522. case 'ar':
  1523. if (n === 0)
  1524. return Plural.Zero;
  1525. if (n === 1)
  1526. return Plural.One;
  1527. if (n === 2)
  1528. return Plural.Two;
  1529. if (n % 100 === Math.floor(n % 100) && n % 100 >= 3 && n % 100 <= 10)
  1530. return Plural.Few;
  1531. if (n % 100 === Math.floor(n % 100) && n % 100 >= 11 && n % 100 <= 99)
  1532. return Plural.Many;
  1533. return Plural.Other;
  1534. case 'ast':
  1535. case 'ca':
  1536. case 'de':
  1537. case 'en':
  1538. case 'et':
  1539. case 'fi':
  1540. case 'fy':
  1541. case 'gl':
  1542. case 'it':
  1543. case 'nl':
  1544. case 'sv':
  1545. case 'sw':
  1546. case 'ur':
  1547. case 'yi':
  1548. if (i === 1 && v === 0)
  1549. return Plural.One;
  1550. return Plural.Other;
  1551. case 'be':
  1552. if (n % 10 === 1 && !(n % 100 === 11))
  1553. return Plural.One;
  1554. if (n % 10 === Math.floor(n % 10) && n % 10 >= 2 && n % 10 <= 4 &&
  1555. !(n % 100 >= 12 && n % 100 <= 14))
  1556. return Plural.Few;
  1557. if (n % 10 === 0 || n % 10 === Math.floor(n % 10) && n % 10 >= 5 && n % 10 <= 9 ||
  1558. n % 100 === Math.floor(n % 100) && n % 100 >= 11 && n % 100 <= 14)
  1559. return Plural.Many;
  1560. return Plural.Other;
  1561. case 'br':
  1562. if (n % 10 === 1 && !(n % 100 === 11 || n % 100 === 71 || n % 100 === 91))
  1563. return Plural.One;
  1564. if (n % 10 === 2 && !(n % 100 === 12 || n % 100 === 72 || n % 100 === 92))
  1565. return Plural.Two;
  1566. if (n % 10 === Math.floor(n % 10) && (n % 10 >= 3 && n % 10 <= 4 || n % 10 === 9) &&
  1567. !(n % 100 >= 10 && n % 100 <= 19 || n % 100 >= 70 && n % 100 <= 79 ||
  1568. n % 100 >= 90 && n % 100 <= 99))
  1569. return Plural.Few;
  1570. if (!(n === 0) && n % 1e6 === 0)
  1571. return Plural.Many;
  1572. return Plural.Other;
  1573. case 'bs':
  1574. case 'hr':
  1575. case 'sr':
  1576. if (v === 0 && i % 10 === 1 && !(i % 100 === 11) || f % 10 === 1 && !(f % 100 === 11))
  1577. return Plural.One;
  1578. if (v === 0 && i % 10 === Math.floor(i % 10) && i % 10 >= 2 && i % 10 <= 4 &&
  1579. !(i % 100 >= 12 && i % 100 <= 14) ||
  1580. f % 10 === Math.floor(f % 10) && f % 10 >= 2 && f % 10 <= 4 &&
  1581. !(f % 100 >= 12 && f % 100 <= 14))
  1582. return Plural.Few;
  1583. return Plural.Other;
  1584. case 'cs':
  1585. case 'sk':
  1586. if (i === 1 && v === 0)
  1587. return Plural.One;
  1588. if (i === Math.floor(i) && i >= 2 && i <= 4 && v === 0)
  1589. return Plural.Few;
  1590. if (!(v === 0))
  1591. return Plural.Many;
  1592. return Plural.Other;
  1593. case 'cy':
  1594. if (n === 0)
  1595. return Plural.Zero;
  1596. if (n === 1)
  1597. return Plural.One;
  1598. if (n === 2)
  1599. return Plural.Two;
  1600. if (n === 3)
  1601. return Plural.Few;
  1602. if (n === 6)
  1603. return Plural.Many;
  1604. return Plural.Other;
  1605. case 'da':
  1606. if (n === 1 || !(t === 0) && (i === 0 || i === 1))
  1607. return Plural.One;
  1608. return Plural.Other;
  1609. case 'dsb':
  1610. case 'hsb':
  1611. if (v === 0 && i % 100 === 1 || f % 100 === 1)
  1612. return Plural.One;
  1613. if (v === 0 && i % 100 === 2 || f % 100 === 2)
  1614. return Plural.Two;
  1615. if (v === 0 && i % 100 === Math.floor(i % 100) && i % 100 >= 3 && i % 100 <= 4 ||
  1616. f % 100 === Math.floor(f % 100) && f % 100 >= 3 && f % 100 <= 4)
  1617. return Plural.Few;
  1618. return Plural.Other;
  1619. case 'ff':
  1620. case 'fr':
  1621. case 'hy':
  1622. case 'kab':
  1623. if (i === 0 || i === 1)
  1624. return Plural.One;
  1625. return Plural.Other;
  1626. case 'fil':
  1627. if (v === 0 && (i === 1 || i === 2 || i === 3) ||
  1628. v === 0 && !(i % 10 === 4 || i % 10 === 6 || i % 10 === 9) ||
  1629. !(v === 0) && !(f % 10 === 4 || f % 10 === 6 || f % 10 === 9))
  1630. return Plural.One;
  1631. return Plural.Other;
  1632. case 'ga':
  1633. if (n === 1)
  1634. return Plural.One;
  1635. if (n === 2)
  1636. return Plural.Two;
  1637. if (n === Math.floor(n) && n >= 3 && n <= 6)
  1638. return Plural.Few;
  1639. if (n === Math.floor(n) && n >= 7 && n <= 10)
  1640. return Plural.Many;
  1641. return Plural.Other;
  1642. case 'gd':
  1643. if (n === 1 || n === 11)
  1644. return Plural.One;
  1645. if (n === 2 || n === 12)
  1646. return Plural.Two;
  1647. if (n === Math.floor(n) && (n >= 3 && n <= 10 || n >= 13 && n <= 19))
  1648. return Plural.Few;
  1649. return Plural.Other;
  1650. case 'gv':
  1651. if (v === 0 && i % 10 === 1)
  1652. return Plural.One;
  1653. if (v === 0 && i % 10 === 2)
  1654. return Plural.Two;
  1655. if (v === 0 &&
  1656. (i % 100 === 0 || i % 100 === 20 || i % 100 === 40 || i % 100 === 60 || i % 100 === 80))
  1657. return Plural.Few;
  1658. if (!(v === 0))
  1659. return Plural.Many;
  1660. return Plural.Other;
  1661. case 'he':
  1662. if (i === 1 && v === 0)
  1663. return Plural.One;
  1664. if (i === 2 && v === 0)
  1665. return Plural.Two;
  1666. if (v === 0 && !(n >= 0 && n <= 10) && n % 10 === 0)
  1667. return Plural.Many;
  1668. return Plural.Other;
  1669. case 'is':
  1670. if (t === 0 && i % 10 === 1 && !(i % 100 === 11) || !(t === 0))
  1671. return Plural.One;
  1672. return Plural.Other;
  1673. case 'ksh':
  1674. if (n === 0)
  1675. return Plural.Zero;
  1676. if (n === 1)
  1677. return Plural.One;
  1678. return Plural.Other;
  1679. case 'kw':
  1680. case 'naq':
  1681. case 'se':
  1682. case 'smn':
  1683. if (n === 1)
  1684. return Plural.One;
  1685. if (n === 2)
  1686. return Plural.Two;
  1687. return Plural.Other;
  1688. case 'lag':
  1689. if (n === 0)
  1690. return Plural.Zero;
  1691. if ((i === 0 || i === 1) && !(n === 0))
  1692. return Plural.One;
  1693. return Plural.Other;
  1694. case 'lt':
  1695. if (n % 10 === 1 && !(n % 100 >= 11 && n % 100 <= 19))
  1696. return Plural.One;
  1697. if (n % 10 === Math.floor(n % 10) && n % 10 >= 2 && n % 10 <= 9 &&
  1698. !(n % 100 >= 11 && n % 100 <= 19))
  1699. return Plural.Few;
  1700. if (!(f === 0))
  1701. return Plural.Many;
  1702. return Plural.Other;
  1703. case 'lv':
  1704. case 'prg':
  1705. if (n % 10 === 0 || n % 100 === Math.floor(n % 100) && n % 100 >= 11 && n % 100 <= 19 ||
  1706. v === 2 && f % 100 === Math.floor(f % 100) && f % 100 >= 11 && f % 100 <= 19)
  1707. return Plural.Zero;
  1708. if (n % 10 === 1 && !(n % 100 === 11) || v === 2 && f % 10 === 1 && !(f % 100 === 11) ||
  1709. !(v === 2) && f % 10 === 1)
  1710. return Plural.One;
  1711. return Plural.Other;
  1712. case 'mk':
  1713. if (v === 0 && i % 10 === 1 || f % 10 === 1)
  1714. return Plural.One;
  1715. return Plural.Other;
  1716. case 'mt':
  1717. if (n === 1)
  1718. return Plural.One;
  1719. if (n === 0 || n % 100 === Math.floor(n % 100) && n % 100 >= 2 && n % 100 <= 10)
  1720. return Plural.Few;
  1721. if (n % 100 === Math.floor(n % 100) && n % 100 >= 11 && n % 100 <= 19)
  1722. return Plural.Many;
  1723. return Plural.Other;
  1724. case 'pl':
  1725. if (i === 1 && v === 0)
  1726. return Plural.One;
  1727. if (v === 0 && i % 10 === Math.floor(i % 10) && i % 10 >= 2 && i % 10 <= 4 &&
  1728. !(i % 100 >= 12 && i % 100 <= 14))
  1729. return Plural.Few;
  1730. if (v === 0 && !(i === 1) && i % 10 === Math.floor(i % 10) && i % 10 >= 0 && i % 10 <= 1 ||
  1731. v === 0 && i % 10 === Math.floor(i % 10) && i % 10 >= 5 && i % 10 <= 9 ||
  1732. v === 0 && i % 100 === Math.floor(i % 100) && i % 100 >= 12 && i % 100 <= 14)
  1733. return Plural.Many;
  1734. return Plural.Other;
  1735. case 'pt':
  1736. if (n === Math.floor(n) && n >= 0 && n <= 2 && !(n === 2))
  1737. return Plural.One;
  1738. return Plural.Other;
  1739. case 'ro':
  1740. if (i === 1 && v === 0)
  1741. return Plural.One;
  1742. if (!(v === 0) || n === 0 ||
  1743. !(n === 1) && n % 100 === Math.floor(n % 100) && n % 100 >= 1 && n % 100 <= 19)
  1744. return Plural.Few;
  1745. return Plural.Other;
  1746. case 'ru':
  1747. case 'uk':
  1748. if (v === 0 && i % 10 === 1 && !(i % 100 === 11))
  1749. return Plural.One;
  1750. if (v === 0 && i % 10 === Math.floor(i % 10) && i % 10 >= 2 && i % 10 <= 4 &&
  1751. !(i % 100 >= 12 && i % 100 <= 14))
  1752. return Plural.Few;
  1753. if (v === 0 && i % 10 === 0 ||
  1754. v === 0 && i % 10 === Math.floor(i % 10) && i % 10 >= 5 && i % 10 <= 9 ||
  1755. v === 0 && i % 100 === Math.floor(i % 100) && i % 100 >= 11 && i % 100 <= 14)
  1756. return Plural.Many;
  1757. return Plural.Other;
  1758. case 'shi':
  1759. if (i === 0 || n === 1)
  1760. return Plural.One;
  1761. if (n === Math.floor(n) && n >= 2 && n <= 10)
  1762. return Plural.Few;
  1763. return Plural.Other;
  1764. case 'si':
  1765. if (n === 0 || n === 1 || i === 0 && f === 1)
  1766. return Plural.One;
  1767. return Plural.Other;
  1768. case 'sl':
  1769. if (v === 0 && i % 100 === 1)
  1770. return Plural.One;
  1771. if (v === 0 && i % 100 === 2)
  1772. return Plural.Two;
  1773. if (v === 0 && i % 100 === Math.floor(i % 100) && i % 100 >= 3 && i % 100 <= 4 || !(v === 0))
  1774. return Plural.Few;
  1775. return Plural.Other;
  1776. case 'tzm':
  1777. if (n === Math.floor(n) && n >= 0 && n <= 1 || n === Math.floor(n) && n >= 11 && n <= 99)
  1778. return Plural.One;
  1779. return Plural.Other;
  1780. // When there is no specification, the default is always "other"
  1781. // Spec: http://cldr.unicode.org/index/cldr-spec/plural-rules
  1782. // > other (required—general plural form — also used if the language only has a single form)
  1783. default:
  1784. return Plural.Other;
  1785. }
  1786. }
  1787. /**
  1788. * @fileoverview added by tsickle
  1789. * @suppress {checkTypes} checked by tsc
  1790. */
  1791. /**
  1792. * @license
  1793. * Copyright Google Inc. All Rights Reserved.
  1794. *
  1795. * Use of this source code is governed by an MIT-style license that can be
  1796. * found in the LICENSE file at https://angular.io/license
  1797. */
  1798. /**
  1799. * @param {?} cookieStr
  1800. * @param {?} name
  1801. * @return {?}
  1802. */
  1803. function parseCookieValue(cookieStr, name) {
  1804. name = encodeURIComponent(name);
  1805. for (const /** @type {?} */ cookie of cookieStr.split(';')) {
  1806. const /** @type {?} */ eqIndex = cookie.indexOf('=');
  1807. const [cookieName, cookieValue] = eqIndex == -1 ? [cookie, ''] : [cookie.slice(0, eqIndex), cookie.slice(eqIndex + 1)];
  1808. if (cookieName.trim() === name) {
  1809. return decodeURIComponent(cookieValue);
  1810. }
  1811. }
  1812. return null;
  1813. }
  1814. /**
  1815. * @fileoverview added by tsickle
  1816. * @suppress {checkTypes} checked by tsc
  1817. */
  1818. /**
  1819. * @license
  1820. * Copyright Google Inc. All Rights Reserved.
  1821. *
  1822. * Use of this source code is governed by an MIT-style license that can be
  1823. * found in the LICENSE file at https://angular.io/license
  1824. */
  1825. /**
  1826. * \@ngModule CommonModule
  1827. *
  1828. * \@whatItDoes Adds and removes CSS classes on an HTML element.
  1829. *
  1830. * \@howToUse
  1831. * ```
  1832. * <some-element [ngClass]="'first second'">...</some-element>
  1833. *
  1834. * <some-element [ngClass]="['first', 'second']">...</some-element>
  1835. *
  1836. * <some-element [ngClass]="{'first': true, 'second': true, 'third': false}">...</some-element>
  1837. *
  1838. * <some-element [ngClass]="stringExp|arrayExp|objExp">...</some-element>
  1839. *
  1840. * <some-element [ngClass]="{'class1 class2 class3' : true}">...</some-element>
  1841. * ```
  1842. *
  1843. * \@description
  1844. *
  1845. * The CSS classes are updated as follows, depending on the type of the expression evaluation:
  1846. * - `string` - the CSS classes listed in the string (space delimited) are added,
  1847. * - `Array` - the CSS classes declared as Array elements are added,
  1848. * - `Object` - keys are CSS classes that get added when the expression given in the value
  1849. * evaluates to a truthy value, otherwise they are removed.
  1850. *
  1851. * \@stable
  1852. */
  1853. class NgClass {
  1854. /**
  1855. * @param {?} _iterableDiffers
  1856. * @param {?} _keyValueDiffers
  1857. * @param {?} _ngEl
  1858. * @param {?} _renderer
  1859. */
  1860. constructor(_iterableDiffers, _keyValueDiffers, _ngEl, _renderer) {
  1861. this._iterableDiffers = _iterableDiffers;
  1862. this._keyValueDiffers = _keyValueDiffers;
  1863. this._ngEl = _ngEl;
  1864. this._renderer = _renderer;
  1865. this._initialClasses = [];
  1866. }
  1867. /**
  1868. * @param {?} v
  1869. * @return {?}
  1870. */
  1871. set klass(v) {
  1872. this._removeClasses(this._initialClasses);
  1873. this._initialClasses = typeof v === 'string' ? v.split(/\s+/) : [];
  1874. this._applyClasses(this._initialClasses);
  1875. this._applyClasses(this._rawClass);
  1876. }
  1877. /**
  1878. * @param {?} v
  1879. * @return {?}
  1880. */
  1881. set ngClass(v) {
  1882. this._removeClasses(this._rawClass);
  1883. this._applyClasses(this._initialClasses);
  1884. this._iterableDiffer = null;
  1885. this._keyValueDiffer = null;
  1886. this._rawClass = typeof v === 'string' ? v.split(/\s+/) : v;
  1887. if (this._rawClass) {
  1888. if (ɵisListLikeIterable(this._rawClass)) {
  1889. this._iterableDiffer = this._iterableDiffers.find(this._rawClass).create();
  1890. }
  1891. else {
  1892. this._keyValueDiffer = this._keyValueDiffers.find(this._rawClass).create();
  1893. }
  1894. }
  1895. }
  1896. /**
  1897. * @return {?}
  1898. */
  1899. ngDoCheck() {
  1900. if (this._iterableDiffer) {
  1901. const /** @type {?} */ iterableChanges = this._iterableDiffer.diff(/** @type {?} */ (this._rawClass));
  1902. if (iterableChanges) {
  1903. this._applyIterableChanges(iterableChanges);
  1904. }
  1905. }
  1906. else if (this._keyValueDiffer) {
  1907. const /** @type {?} */ keyValueChanges = this._keyValueDiffer.diff(/** @type {?} */ (this._rawClass));
  1908. if (keyValueChanges) {
  1909. this._applyKeyValueChanges(keyValueChanges);
  1910. }
  1911. }
  1912. }
  1913. /**
  1914. * @param {?} changes
  1915. * @return {?}
  1916. */
  1917. _applyKeyValueChanges(changes) {
  1918. changes.forEachAddedItem((record) => this._toggleClass(record.key, record.currentValue));
  1919. changes.forEachChangedItem((record) => this._toggleClass(record.key, record.currentValue));
  1920. changes.forEachRemovedItem((record) => {
  1921. if (record.previousValue) {
  1922. this._toggleClass(record.key, false);
  1923. }
  1924. });
  1925. }
  1926. /**
  1927. * @param {?} changes
  1928. * @return {?}
  1929. */
  1930. _applyIterableChanges(changes) {
  1931. changes.forEachAddedItem((record) => {
  1932. if (typeof record.item === 'string') {
  1933. this._toggleClass(record.item, true);
  1934. }
  1935. else {
  1936. throw new Error(`NgClass can only toggle CSS classes expressed as strings, got ${ɵstringify(record.item)}`);
  1937. }
  1938. });
  1939. changes.forEachRemovedItem((record) => this._toggleClass(record.item, false));
  1940. }
  1941. /**
  1942. * Applies a collection of CSS classes to the DOM element.
  1943. *
  1944. * For argument of type Set and Array CSS class names contained in those collections are always
  1945. * added.
  1946. * For argument of type Map CSS class name in the map's key is toggled based on the value (added
  1947. * for truthy and removed for falsy).
  1948. * @param {?} rawClassVal
  1949. * @return {?}
  1950. */
  1951. _applyClasses(rawClassVal) {
  1952. if (rawClassVal) {
  1953. if (Array.isArray(rawClassVal) || rawClassVal instanceof Set) {
  1954. (/** @type {?} */ (rawClassVal)).forEach((klass) => this._toggleClass(klass, true));
  1955. }
  1956. else {
  1957. Object.keys(rawClassVal).forEach(klass => this._toggleClass(klass, !!rawClassVal[klass]));
  1958. }
  1959. }
  1960. }
  1961. /**
  1962. * Removes a collection of CSS classes from the DOM element. This is mostly useful for cleanup
  1963. * purposes.
  1964. * @param {?} rawClassVal
  1965. * @return {?}
  1966. */
  1967. _removeClasses(rawClassVal) {
  1968. if (rawClassVal) {
  1969. if (Array.isArray(rawClassVal) || rawClassVal instanceof Set) {
  1970. (/** @type {?} */ (rawClassVal)).forEach((klass) => this._toggleClass(klass, false));
  1971. }
  1972. else {
  1973. Object.keys(rawClassVal).forEach(klass => this._toggleClass(klass, false));
  1974. }
  1975. }
  1976. }
  1977. /**
  1978. * @param {?} klass
  1979. * @param {?} enabled
  1980. * @return {?}
  1981. */
  1982. _toggleClass(klass, enabled) {
  1983. klass = klass.trim();
  1984. if (klass) {
  1985. klass.split(/\s+/g).forEach(klass => {
  1986. if (enabled) {
  1987. this._renderer.addClass(this._ngEl.nativeElement, klass);
  1988. }
  1989. else {
  1990. this._renderer.removeClass(this._ngEl.nativeElement, klass);
  1991. }
  1992. });
  1993. }
  1994. }
  1995. }
  1996. NgClass.decorators = [
  1997. { type: Directive, args: [{ selector: '[ngClass]' },] },
  1998. ];
  1999. /** @nocollapse */
  2000. NgClass.ctorParameters = () => [
  2001. { type: IterableDiffers, },
  2002. { type: KeyValueDiffers, },
  2003. { type: ElementRef, },
  2004. { type: Renderer2, },
  2005. ];
  2006. NgClass.propDecorators = {
  2007. "klass": [{ type: Input, args: ['class',] },],
  2008. "ngClass": [{ type: Input },],
  2009. };
  2010. /**
  2011. * @fileoverview added by tsickle
  2012. * @suppress {checkTypes} checked by tsc
  2013. */
  2014. /**
  2015. * @license
  2016. * Copyright Google Inc. All Rights Reserved.
  2017. *
  2018. * Use of this source code is governed by an MIT-style license that can be
  2019. * found in the LICENSE file at https://angular.io/license
  2020. */
  2021. /**
  2022. * Instantiates a single {\@link Component} type and inserts its Host View into current View.
  2023. * `NgComponentOutlet` provides a declarative approach for dynamic component creation.
  2024. *
  2025. * `NgComponentOutlet` requires a component type, if a falsy value is set the view will clear and
  2026. * any existing component will get destroyed.
  2027. *
  2028. * ### Fine tune control
  2029. *
  2030. * You can control the component creation process by using the following optional attributes:
  2031. *
  2032. * * `ngComponentOutletInjector`: Optional custom {\@link Injector} that will be used as parent for
  2033. * the Component. Defaults to the injector of the current view container.
  2034. *
  2035. * * `ngComponentOutletContent`: Optional list of projectable nodes to insert into the content
  2036. * section of the component, if exists.
  2037. *
  2038. * * `ngComponentOutletNgModuleFactory`: Optional module factory to allow dynamically loading other
  2039. * module, then load a component from that module.
  2040. *
  2041. * ### Syntax
  2042. *
  2043. * Simple
  2044. * ```
  2045. * <ng-container *ngComponentOutlet="componentTypeExpression"></ng-container>
  2046. * ```
  2047. *
  2048. * Customized injector/content
  2049. * ```
  2050. * <ng-container *ngComponentOutlet="componentTypeExpression;
  2051. * injector: injectorExpression;
  2052. * content: contentNodesExpression;">
  2053. * </ng-container>
  2054. * ```
  2055. *
  2056. * Customized ngModuleFactory
  2057. * ```
  2058. * <ng-container *ngComponentOutlet="componentTypeExpression;
  2059. * ngModuleFactory: moduleFactory;">
  2060. * </ng-container>
  2061. * ```
  2062. * ## Example
  2063. *
  2064. * {\@example common/ngComponentOutlet/ts/module.ts region='SimpleExample'}
  2065. *
  2066. * A more complete example with additional options:
  2067. *
  2068. * {\@example common/ngComponentOutlet/ts/module.ts region='CompleteExample'}
  2069. * A more complete example with ngModuleFactory:
  2070. *
  2071. * {\@example common/ngComponentOutlet/ts/module.ts region='NgModuleFactoryExample'}
  2072. *
  2073. * \@experimental
  2074. */
  2075. class NgComponentOutlet {
  2076. /**
  2077. * @param {?} _viewContainerRef
  2078. */
  2079. constructor(_viewContainerRef) {
  2080. this._viewContainerRef = _viewContainerRef;
  2081. this._componentRef = null;
  2082. this._moduleRef = null;
  2083. }
  2084. /**
  2085. * @param {?} changes
  2086. * @return {?}
  2087. */
  2088. ngOnChanges(changes) {
  2089. this._viewContainerRef.clear();
  2090. this._componentRef = null;
  2091. if (this.ngComponentOutlet) {
  2092. const /** @type {?} */ elInjector = this.ngComponentOutletInjector || this._viewContainerRef.parentInjector;
  2093. if (changes['ngComponentOutletNgModuleFactory']) {
  2094. if (this._moduleRef)
  2095. this._moduleRef.destroy();
  2096. if (this.ngComponentOutletNgModuleFactory) {
  2097. const /** @type {?} */ parentModule = elInjector.get(NgModuleRef);
  2098. this._moduleRef = this.ngComponentOutletNgModuleFactory.create(parentModule.injector);
  2099. }
  2100. else {
  2101. this._moduleRef = null;
  2102. }
  2103. }
  2104. const /** @type {?} */ componentFactoryResolver = this._moduleRef ? this._moduleRef.componentFactoryResolver :
  2105. elInjector.get(ComponentFactoryResolver);
  2106. const /** @type {?} */ componentFactory = componentFactoryResolver.resolveComponentFactory(this.ngComponentOutlet);
  2107. this._componentRef = this._viewContainerRef.createComponent(componentFactory, this._viewContainerRef.length, elInjector, this.ngComponentOutletContent);
  2108. }
  2109. }
  2110. /**
  2111. * @return {?}
  2112. */
  2113. ngOnDestroy() {
  2114. if (this._moduleRef)
  2115. this._moduleRef.destroy();
  2116. }
  2117. }
  2118. NgComponentOutlet.decorators = [
  2119. { type: Directive, args: [{ selector: '[ngComponentOutlet]' },] },
  2120. ];
  2121. /** @nocollapse */
  2122. NgComponentOutlet.ctorParameters = () => [
  2123. { type: ViewContainerRef, },
  2124. ];
  2125. NgComponentOutlet.propDecorators = {
  2126. "ngComponentOutlet": [{ type: Input },],
  2127. "ngComponentOutletInjector": [{ type: Input },],
  2128. "ngComponentOutletContent": [{ type: Input },],
  2129. "ngComponentOutletNgModuleFactory": [{ type: Input },],
  2130. };
  2131. /**
  2132. * @fileoverview added by tsickle
  2133. * @suppress {checkTypes} checked by tsc
  2134. */
  2135. /**
  2136. * @license
  2137. * Copyright Google Inc. All Rights Reserved.
  2138. *
  2139. * Use of this source code is governed by an MIT-style license that can be
  2140. * found in the LICENSE file at https://angular.io/license
  2141. */
  2142. /**
  2143. * \@stable
  2144. * @template T
  2145. */
  2146. class NgForOfContext {
  2147. /**
  2148. * @param {?} $implicit
  2149. * @param {?} ngForOf
  2150. * @param {?} index
  2151. * @param {?} count
  2152. */
  2153. constructor($implicit, ngForOf, index, count) {
  2154. this.$implicit = $implicit;
  2155. this.ngForOf = ngForOf;
  2156. this.index = index;
  2157. this.count = count;
  2158. }
  2159. /**
  2160. * @return {?}
  2161. */
  2162. get first() { return this.index === 0; }
  2163. /**
  2164. * @return {?}
  2165. */
  2166. get last() { return this.index === this.count - 1; }
  2167. /**
  2168. * @return {?}
  2169. */
  2170. get even() { return this.index % 2 === 0; }
  2171. /**
  2172. * @return {?}
  2173. */
  2174. get odd() { return !this.even; }
  2175. }
  2176. /**
  2177. * The `NgForOf` directive instantiates a template once per item from an iterable. The context
  2178. * for each instantiated template inherits from the outer context with the given loop variable
  2179. * set to the current item from the iterable.
  2180. *
  2181. * ### Local Variables
  2182. *
  2183. * `NgForOf` provides several exported values that can be aliased to local variables:
  2184. *
  2185. * - `$implicit: T`: The value of the individual items in the iterable (`ngForOf`).
  2186. * - `ngForOf: NgIterable<T>`: The value of the iterable expression. Useful when the expression is
  2187. * more complex then a property access, for example when using the async pipe (`userStreams |
  2188. * async`).
  2189. * - `index: number`: The index of the current item in the iterable.
  2190. * - `first: boolean`: True when the item is the first item in the iterable.
  2191. * - `last: boolean`: True when the item is the last item in the iterable.
  2192. * - `even: boolean`: True when the item has an even index in the iterable.
  2193. * - `odd: boolean`: True when the item has an odd index in the iterable.
  2194. *
  2195. * ```
  2196. * <li *ngFor="let user of userObservable | async as users; index as i; first as isFirst">
  2197. * {{i}}/{{users.length}}. {{user}} <span *ngIf="isFirst">default</span>
  2198. * </li>
  2199. * ```
  2200. *
  2201. * ### Change Propagation
  2202. *
  2203. * When the contents of the iterator changes, `NgForOf` makes the corresponding changes to the DOM:
  2204. *
  2205. * * When an item is added, a new instance of the template is added to the DOM.
  2206. * * When an item is removed, its template instance is removed from the DOM.
  2207. * * When items are reordered, their respective templates are reordered in the DOM.
  2208. * * Otherwise, the DOM element for that item will remain the same.
  2209. *
  2210. * Angular uses object identity to track insertions and deletions within the iterator and reproduce
  2211. * those changes in the DOM. This has important implications for animations and any stateful
  2212. * controls (such as `<input>` elements which accept user input) that are present. Inserted rows can
  2213. * be animated in, deleted rows can be animated out, and unchanged rows retain any unsaved state
  2214. * such as user input.
  2215. *
  2216. * It is possible for the identities of elements in the iterator to change while the data does not.
  2217. * This can happen, for example, if the iterator produced from an RPC to the server, and that
  2218. * RPC is re-run. Even if the data hasn't changed, the second response will produce objects with
  2219. * different identities, and Angular will tear down the entire DOM and rebuild it (as if all old
  2220. * elements were deleted and all new elements inserted). This is an expensive operation and should
  2221. * be avoided if possible.
  2222. *
  2223. * To customize the default tracking algorithm, `NgForOf` supports `trackBy` option.
  2224. * `trackBy` takes a function which has two arguments: `index` and `item`.
  2225. * If `trackBy` is given, Angular tracks changes by the return value of the function.
  2226. *
  2227. * ### Syntax
  2228. *
  2229. * - `<li *ngFor="let item of items; index as i; trackBy: trackByFn">...</li>`
  2230. *
  2231. * With `<ng-template>` element:
  2232. *
  2233. * ```
  2234. * <ng-template ngFor let-item [ngForOf]="items" let-i="index" [ngForTrackBy]="trackByFn">
  2235. * <li>...</li>
  2236. * </ng-template>
  2237. * ```
  2238. *
  2239. * ### Example
  2240. *
  2241. * See a [live demo](http://plnkr.co/edit/KVuXxDp0qinGDyo307QW?p=preview) for a more detailed
  2242. * example.
  2243. *
  2244. * \@stable
  2245. * @template T
  2246. */
  2247. class NgForOf {
  2248. /**
  2249. * @param {?} _viewContainer
  2250. * @param {?} _template
  2251. * @param {?} _differs
  2252. */
  2253. constructor(_viewContainer, _template, _differs) {
  2254. this._viewContainer = _viewContainer;
  2255. this._template = _template;
  2256. this._differs = _differs;
  2257. this._differ = null;
  2258. }
  2259. /**
  2260. * @param {?} fn
  2261. * @return {?}
  2262. */
  2263. set ngForTrackBy(fn) {
  2264. if (isDevMode() && fn != null && typeof fn !== 'function') {
  2265. // TODO(vicb): use a log service once there is a public one available
  2266. if (/** @type {?} */ (console) && /** @type {?} */ (console.warn)) {
  2267. console.warn(`trackBy must be a function, but received ${JSON.stringify(fn)}. ` +
  2268. `See https://angular.io/docs/ts/latest/api/common/index/NgFor-directive.html#!#change-propagation for more information.`);
  2269. }
  2270. }
  2271. this._trackByFn = fn;
  2272. }
  2273. /**
  2274. * @return {?}
  2275. */
  2276. get ngForTrackBy() { return this._trackByFn; }
  2277. /**
  2278. * @param {?} value
  2279. * @return {?}
  2280. */
  2281. set ngForTemplate(value) {
  2282. // TODO(TS2.1): make TemplateRef<Partial<NgForRowOf<T>>> once we move to TS v2.1
  2283. // The current type is too restrictive; a template that just uses index, for example,
  2284. // should be acceptable.
  2285. if (value) {
  2286. this._template = value;
  2287. }
  2288. }
  2289. /**
  2290. * @param {?} changes
  2291. * @return {?}
  2292. */
  2293. ngOnChanges(changes) {
  2294. if ('ngForOf' in changes) {
  2295. // React on ngForOf changes only once all inputs have been initialized
  2296. const /** @type {?} */ value = changes['ngForOf'].currentValue;
  2297. if (!this._differ && value) {
  2298. try {
  2299. this._differ = this._differs.find(value).create(this.ngForTrackBy);
  2300. }
  2301. catch (/** @type {?} */ e) {
  2302. throw new Error(`Cannot find a differ supporting object '${value}' of type '${getTypeNameForDebugging(value)}'. NgFor only supports binding to Iterables such as Arrays.`);
  2303. }
  2304. }
  2305. }
  2306. }
  2307. /**
  2308. * @return {?}
  2309. */
  2310. ngDoCheck() {
  2311. if (this._differ) {
  2312. const /** @type {?} */ changes = this._differ.diff(this.ngForOf);
  2313. if (changes)
  2314. this._applyChanges(changes);
  2315. }
  2316. }
  2317. /**
  2318. * @param {?} changes
  2319. * @return {?}
  2320. */
  2321. _applyChanges(changes) {
  2322. const /** @type {?} */ insertTuples = [];
  2323. changes.forEachOperation((item, adjustedPreviousIndex, currentIndex) => {
  2324. if (item.previousIndex == null) {
  2325. const /** @type {?} */ view = this._viewContainer.createEmbeddedView(this._template, new NgForOfContext(/** @type {?} */ ((null)), this.ngForOf, -1, -1), currentIndex);
  2326. const /** @type {?} */ tuple = new RecordViewTuple(item, view);
  2327. insertTuples.push(tuple);
  2328. }
  2329. else if (currentIndex == null) {
  2330. this._viewContainer.remove(adjustedPreviousIndex);
  2331. }
  2332. else {
  2333. const /** @type {?} */ view = /** @type {?} */ ((this._viewContainer.get(adjustedPreviousIndex)));
  2334. this._viewContainer.move(view, currentIndex);
  2335. const /** @type {?} */ tuple = new RecordViewTuple(item, /** @type {?} */ (view));
  2336. insertTuples.push(tuple);
  2337. }
  2338. });
  2339. for (let /** @type {?} */ i = 0; i < insertTuples.length; i++) {
  2340. this._perViewChange(insertTuples[i].view, insertTuples[i].record);
  2341. }
  2342. for (let /** @type {?} */ i = 0, /** @type {?} */ ilen = this._viewContainer.length; i < ilen; i++) {
  2343. const /** @type {?} */ viewRef = /** @type {?} */ (this._viewContainer.get(i));
  2344. viewRef.context.index = i;
  2345. viewRef.context.count = ilen;
  2346. }
  2347. changes.forEachIdentityChange((record) => {
  2348. const /** @type {?} */ viewRef = /** @type {?} */ (this._viewContainer.get(record.currentIndex));
  2349. viewRef.context.$implicit = record.item;
  2350. });
  2351. }
  2352. /**
  2353. * @param {?} view
  2354. * @param {?} record
  2355. * @return {?}
  2356. */
  2357. _perViewChange(view, record) {
  2358. view.context.$implicit = record.item;
  2359. }
  2360. }
  2361. NgForOf.decorators = [
  2362. { type: Directive, args: [{ selector: '[ngFor][ngForOf]' },] },
  2363. ];
  2364. /** @nocollapse */
  2365. NgForOf.ctorParameters = () => [
  2366. { type: ViewContainerRef, },
  2367. { type: TemplateRef, },
  2368. { type: IterableDiffers, },
  2369. ];
  2370. NgForOf.propDecorators = {
  2371. "ngForOf": [{ type: Input },],
  2372. "ngForTrackBy": [{ type: Input },],
  2373. "ngForTemplate": [{ type: Input },],
  2374. };
  2375. /**
  2376. * @template T
  2377. */
  2378. class RecordViewTuple {
  2379. /**
  2380. * @param {?} record
  2381. * @param {?} view
  2382. */
  2383. constructor(record, view) {
  2384. this.record = record;
  2385. this.view = view;
  2386. }
  2387. }
  2388. /**
  2389. * @param {?} type
  2390. * @return {?}
  2391. */
  2392. function getTypeNameForDebugging(type) {
  2393. return type['name'] || typeof type;
  2394. }
  2395. /**
  2396. * @fileoverview added by tsickle
  2397. * @suppress {checkTypes} checked by tsc
  2398. */
  2399. /**
  2400. * @license
  2401. * Copyright Google Inc. All Rights Reserved.
  2402. *
  2403. * Use of this source code is governed by an MIT-style license that can be
  2404. * found in the LICENSE file at https://angular.io/license
  2405. */
  2406. /**
  2407. * Conditionally includes a template based on the value of an `expression`.
  2408. *
  2409. * `ngIf` evaluates the `expression` and then renders the `then` or `else` template in its place
  2410. * when expression is truthy or falsy respectively. Typically the:
  2411. * - `then` template is the inline template of `ngIf` unless bound to a different value.
  2412. * - `else` template is blank unless it is bound.
  2413. *
  2414. * ## Most common usage
  2415. *
  2416. * The most common usage of the `ngIf` directive is to conditionally show the inline template as
  2417. * seen in this example:
  2418. * {\@example common/ngIf/ts/module.ts region='NgIfSimple'}
  2419. *
  2420. * ## Showing an alternative template using `else`
  2421. *
  2422. * If it is necessary to display a template when the `expression` is falsy use the `else` template
  2423. * binding as shown. Note that the `else` binding points to a `<ng-template>` labeled `#elseBlock`.
  2424. * The template can be defined anywhere in the component view but is typically placed right after
  2425. * `ngIf` for readability.
  2426. *
  2427. * {\@example common/ngIf/ts/module.ts region='NgIfElse'}
  2428. *
  2429. * ## Using non-inlined `then` template
  2430. *
  2431. * Usually the `then` template is the inlined template of the `ngIf`, but it can be changed using
  2432. * a binding (just like `else`). Because `then` and `else` are bindings, the template references can
  2433. * change at runtime as shown in this example.
  2434. *
  2435. * {\@example common/ngIf/ts/module.ts region='NgIfThenElse'}
  2436. *
  2437. * ## Storing conditional result in a variable
  2438. *
  2439. * A common pattern is that we need to show a set of properties from the same object. If the
  2440. * object is undefined, then we have to use the safe-traversal-operator `?.` to guard against
  2441. * dereferencing a `null` value. This is especially the case when waiting on async data such as
  2442. * when using the `async` pipe as shown in following example:
  2443. *
  2444. * ```
  2445. * Hello {{ (userStream|async)?.last }}, {{ (userStream|async)?.first }}!
  2446. * ```
  2447. *
  2448. * There are several inefficiencies in the above example:
  2449. * - We create multiple subscriptions on `userStream`. One for each `async` pipe, or two in the
  2450. * example above.
  2451. * - We cannot display an alternative screen while waiting for the data to arrive asynchronously.
  2452. * - We have to use the safe-traversal-operator `?.` to access properties, which is cumbersome.
  2453. * - We have to place the `async` pipe in parenthesis.
  2454. *
  2455. * A better way to do this is to use `ngIf` and store the result of the condition in a local
  2456. * variable as shown in the the example below:
  2457. *
  2458. * {\@example common/ngIf/ts/module.ts region='NgIfAs'}
  2459. *
  2460. * Notice that:
  2461. * - We use only one `async` pipe and hence only one subscription gets created.
  2462. * - `ngIf` stores the result of the `userStream|async` in the local variable `user`.
  2463. * - The local `user` can then be bound repeatedly in a more efficient way.
  2464. * - No need to use the safe-traversal-operator `?.` to access properties as `ngIf` will only
  2465. * display the data if `userStream` returns a value.
  2466. * - We can display an alternative template while waiting for the data.
  2467. *
  2468. * ### Syntax
  2469. *
  2470. * Simple form:
  2471. * - `<div *ngIf="condition">...</div>`
  2472. * - `<ng-template [ngIf]="condition"><div>...</div></ng-template>`
  2473. *
  2474. * Form with an else block:
  2475. * ```
  2476. * <div *ngIf="condition; else elseBlock">...</div>
  2477. * <ng-template #elseBlock>...</ng-template>
  2478. * ```
  2479. *
  2480. * Form with a `then` and `else` block:
  2481. * ```
  2482. * <div *ngIf="condition; then thenBlock else elseBlock"></div>
  2483. * <ng-template #thenBlock>...</ng-template>
  2484. * <ng-template #elseBlock>...</ng-template>
  2485. * ```
  2486. *
  2487. * Form with storing the value locally:
  2488. * ```
  2489. * <div *ngIf="condition as value; else elseBlock">{{value}}</div>
  2490. * <ng-template #elseBlock>...</ng-template>
  2491. * ```
  2492. *
  2493. * \@stable
  2494. */
  2495. class NgIf {
  2496. /**
  2497. * @param {?} _viewContainer
  2498. * @param {?} templateRef
  2499. */
  2500. constructor(_viewContainer, templateRef) {
  2501. this._viewContainer = _viewContainer;
  2502. this._context = new NgIfContext();
  2503. this._thenTemplateRef = null;
  2504. this._elseTemplateRef = null;
  2505. this._thenViewRef = null;
  2506. this._elseViewRef = null;
  2507. this._thenTemplateRef = templateRef;
  2508. }
  2509. /**
  2510. * @param {?} condition
  2511. * @return {?}
  2512. */
  2513. set ngIf(condition) {
  2514. this._context.$implicit = this._context.ngIf = condition;
  2515. this._updateView();
  2516. }
  2517. /**
  2518. * @param {?} templateRef
  2519. * @return {?}
  2520. */
  2521. set ngIfThen(templateRef) {
  2522. this._thenTemplateRef = templateRef;
  2523. this._thenViewRef = null; // clear previous view if any.
  2524. this._updateView();
  2525. }
  2526. /**
  2527. * @param {?} templateRef
  2528. * @return {?}
  2529. */
  2530. set ngIfElse(templateRef) {
  2531. this._elseTemplateRef = templateRef;
  2532. this._elseViewRef = null; // clear previous view if any.
  2533. this._updateView();
  2534. }
  2535. /**
  2536. * @return {?}
  2537. */
  2538. _updateView() {
  2539. if (this._context.$implicit) {
  2540. if (!this._thenViewRef) {
  2541. this._viewContainer.clear();
  2542. this._elseViewRef = null;
  2543. if (this._thenTemplateRef) {
  2544. this._thenViewRef =
  2545. this._viewContainer.createEmbeddedView(this._thenTemplateRef, this._context);
  2546. }
  2547. }
  2548. }
  2549. else {
  2550. if (!this._elseViewRef) {
  2551. this._viewContainer.clear();
  2552. this._thenViewRef = null;
  2553. if (this._elseTemplateRef) {
  2554. this._elseViewRef =
  2555. this._viewContainer.createEmbeddedView(this._elseTemplateRef, this._context);
  2556. }
  2557. }
  2558. }
  2559. }
  2560. }
  2561. NgIf.decorators = [
  2562. { type: Directive, args: [{ selector: '[ngIf]' },] },
  2563. ];
  2564. /** @nocollapse */
  2565. NgIf.ctorParameters = () => [
  2566. { type: ViewContainerRef, },
  2567. { type: TemplateRef, },
  2568. ];
  2569. NgIf.propDecorators = {
  2570. "ngIf": [{ type: Input },],
  2571. "ngIfThen": [{ type: Input },],
  2572. "ngIfElse": [{ type: Input },],
  2573. };
  2574. /**
  2575. * \@stable
  2576. */
  2577. class NgIfContext {
  2578. constructor() {
  2579. this.$implicit = null;
  2580. this.ngIf = null;
  2581. }
  2582. }
  2583. /**
  2584. * @fileoverview added by tsickle
  2585. * @suppress {checkTypes} checked by tsc
  2586. */
  2587. /**
  2588. * @license
  2589. * Copyright Google Inc. All Rights Reserved.
  2590. *
  2591. * Use of this source code is governed by an MIT-style license that can be
  2592. * found in the LICENSE file at https://angular.io/license
  2593. */
  2594. class SwitchView {
  2595. /**
  2596. * @param {?} _viewContainerRef
  2597. * @param {?} _templateRef
  2598. */
  2599. constructor(_viewContainerRef, _templateRef) {
  2600. this._viewContainerRef = _viewContainerRef;
  2601. this._templateRef = _templateRef;
  2602. this._created = false;
  2603. }
  2604. /**
  2605. * @return {?}
  2606. */
  2607. create() {
  2608. this._created = true;
  2609. this._viewContainerRef.createEmbeddedView(this._templateRef);
  2610. }
  2611. /**
  2612. * @return {?}
  2613. */
  2614. destroy() {
  2615. this._created = false;
  2616. this._viewContainerRef.clear();
  2617. }
  2618. /**
  2619. * @param {?} created
  2620. * @return {?}
  2621. */
  2622. enforceState(created) {
  2623. if (created && !this._created) {
  2624. this.create();
  2625. }
  2626. else if (!created && this._created) {
  2627. this.destroy();
  2628. }
  2629. }
  2630. }
  2631. /**
  2632. * \@ngModule CommonModule
  2633. *
  2634. * \@whatItDoes Adds / removes DOM sub-trees when the nest match expressions matches the switch
  2635. * expression.
  2636. *
  2637. * \@howToUse
  2638. * ```
  2639. * <container-element [ngSwitch]="switch_expression">
  2640. * <some-element *ngSwitchCase="match_expression_1">...</some-element>
  2641. * <some-element *ngSwitchCase="match_expression_2">...</some-element>
  2642. * <some-other-element *ngSwitchCase="match_expression_3">...</some-other-element>
  2643. * <ng-container *ngSwitchCase="match_expression_3">
  2644. * <!-- use a ng-container to group multiple root nodes -->
  2645. * <inner-element></inner-element>
  2646. * <inner-other-element></inner-other-element>
  2647. * </ng-container>
  2648. * <some-element *ngSwitchDefault>...</some-element>
  2649. * </container-element>
  2650. * ```
  2651. * \@description
  2652. *
  2653. * `NgSwitch` stamps out nested views when their match expression value matches the value of the
  2654. * switch expression.
  2655. *
  2656. * In other words:
  2657. * - you define a container element (where you place the directive with a switch expression on the
  2658. * `[ngSwitch]="..."` attribute)
  2659. * - you define inner views inside the `NgSwitch` and place a `*ngSwitchCase` attribute on the view
  2660. * root elements.
  2661. *
  2662. * Elements within `NgSwitch` but outside of a `NgSwitchCase` or `NgSwitchDefault` directives will
  2663. * be preserved at the location.
  2664. *
  2665. * The `ngSwitchCase` directive informs the parent `NgSwitch` of which view to display when the
  2666. * expression is evaluated.
  2667. * When no matching expression is found on a `ngSwitchCase` view, the `ngSwitchDefault` view is
  2668. * stamped out.
  2669. *
  2670. * \@stable
  2671. */
  2672. class NgSwitch {
  2673. constructor() {
  2674. this._defaultUsed = false;
  2675. this._caseCount = 0;
  2676. this._lastCaseCheckIndex = 0;
  2677. this._lastCasesMatched = false;
  2678. }
  2679. /**
  2680. * @param {?} newValue
  2681. * @return {?}
  2682. */
  2683. set ngSwitch(newValue) {
  2684. this._ngSwitch = newValue;
  2685. if (this._caseCount === 0) {
  2686. this._updateDefaultCases(true);
  2687. }
  2688. }
  2689. /**
  2690. * \@internal
  2691. * @return {?}
  2692. */
  2693. _addCase() { return this._caseCount++; }
  2694. /**
  2695. * \@internal
  2696. * @param {?} view
  2697. * @return {?}
  2698. */
  2699. _addDefault(view) {
  2700. if (!this._defaultViews) {
  2701. this._defaultViews = [];
  2702. }
  2703. this._defaultViews.push(view);
  2704. }
  2705. /**
  2706. * \@internal
  2707. * @param {?} value
  2708. * @return {?}
  2709. */
  2710. _matchCase(value) {
  2711. const /** @type {?} */ matched = value == this._ngSwitch;
  2712. this._lastCasesMatched = this._lastCasesMatched || matched;
  2713. this._lastCaseCheckIndex++;
  2714. if (this._lastCaseCheckIndex === this._caseCount) {
  2715. this._updateDefaultCases(!this._lastCasesMatched);
  2716. this._lastCaseCheckIndex = 0;
  2717. this._lastCasesMatched = false;
  2718. }
  2719. return matched;
  2720. }
  2721. /**
  2722. * @param {?} useDefault
  2723. * @return {?}
  2724. */
  2725. _updateDefaultCases(useDefault) {
  2726. if (this._defaultViews && useDefault !== this._defaultUsed) {
  2727. this._defaultUsed = useDefault;
  2728. for (let /** @type {?} */ i = 0; i < this._defaultViews.length; i++) {
  2729. const /** @type {?} */ defaultView = this._defaultViews[i];
  2730. defaultView.enforceState(useDefault);
  2731. }
  2732. }
  2733. }
  2734. }
  2735. NgSwitch.decorators = [
  2736. { type: Directive, args: [{ selector: '[ngSwitch]' },] },
  2737. ];
  2738. /** @nocollapse */
  2739. NgSwitch.ctorParameters = () => [];
  2740. NgSwitch.propDecorators = {
  2741. "ngSwitch": [{ type: Input },],
  2742. };
  2743. /**
  2744. * \@ngModule CommonModule
  2745. *
  2746. * \@whatItDoes Creates a view that will be added/removed from the parent {\@link NgSwitch} when the
  2747. * given expression evaluate to respectively the same/different value as the switch
  2748. * expression.
  2749. *
  2750. * \@howToUse
  2751. * ```
  2752. * <container-element [ngSwitch]="switch_expression">
  2753. * <some-element *ngSwitchCase="match_expression_1">...</some-element>
  2754. * </container-element>
  2755. * ```
  2756. * \@description
  2757. *
  2758. * Insert the sub-tree when the expression evaluates to the same value as the enclosing switch
  2759. * expression.
  2760. *
  2761. * If multiple match expressions match the switch expression value, all of them are displayed.
  2762. *
  2763. * See {\@link NgSwitch} for more details and example.
  2764. *
  2765. * \@stable
  2766. */
  2767. class NgSwitchCase {
  2768. /**
  2769. * @param {?} viewContainer
  2770. * @param {?} templateRef
  2771. * @param {?} ngSwitch
  2772. */
  2773. constructor(viewContainer, templateRef, ngSwitch) {
  2774. this.ngSwitch = ngSwitch;
  2775. ngSwitch._addCase();
  2776. this._view = new SwitchView(viewContainer, templateRef);
  2777. }
  2778. /**
  2779. * @return {?}
  2780. */
  2781. ngDoCheck() { this._view.enforceState(this.ngSwitch._matchCase(this.ngSwitchCase)); }
  2782. }
  2783. NgSwitchCase.decorators = [
  2784. { type: Directive, args: [{ selector: '[ngSwitchCase]' },] },
  2785. ];
  2786. /** @nocollapse */
  2787. NgSwitchCase.ctorParameters = () => [
  2788. { type: ViewContainerRef, },
  2789. { type: TemplateRef, },
  2790. { type: NgSwitch, decorators: [{ type: Host },] },
  2791. ];
  2792. NgSwitchCase.propDecorators = {
  2793. "ngSwitchCase": [{ type: Input },],
  2794. };
  2795. /**
  2796. * \@ngModule CommonModule
  2797. * \@whatItDoes Creates a view that is added to the parent {\@link NgSwitch} when no case expressions
  2798. * match the
  2799. * switch expression.
  2800. *
  2801. * \@howToUse
  2802. * ```
  2803. * <container-element [ngSwitch]="switch_expression">
  2804. * <some-element *ngSwitchCase="match_expression_1">...</some-element>
  2805. * <some-other-element *ngSwitchDefault>...</some-other-element>
  2806. * </container-element>
  2807. * ```
  2808. *
  2809. * \@description
  2810. *
  2811. * Insert the sub-tree when no case expressions evaluate to the same value as the enclosing switch
  2812. * expression.
  2813. *
  2814. * See {\@link NgSwitch} for more details and example.
  2815. *
  2816. * \@stable
  2817. */
  2818. class NgSwitchDefault {
  2819. /**
  2820. * @param {?} viewContainer
  2821. * @param {?} templateRef
  2822. * @param {?} ngSwitch
  2823. */
  2824. constructor(viewContainer, templateRef, ngSwitch) {
  2825. ngSwitch._addDefault(new SwitchView(viewContainer, templateRef));
  2826. }
  2827. }
  2828. NgSwitchDefault.decorators = [
  2829. { type: Directive, args: [{ selector: '[ngSwitchDefault]' },] },
  2830. ];
  2831. /** @nocollapse */
  2832. NgSwitchDefault.ctorParameters = () => [
  2833. { type: ViewContainerRef, },
  2834. { type: TemplateRef, },
  2835. { type: NgSwitch, decorators: [{ type: Host },] },
  2836. ];
  2837. /**
  2838. * @fileoverview added by tsickle
  2839. * @suppress {checkTypes} checked by tsc
  2840. */
  2841. /**
  2842. * @license
  2843. * Copyright Google Inc. All Rights Reserved.
  2844. *
  2845. * Use of this source code is governed by an MIT-style license that can be
  2846. * found in the LICENSE file at https://angular.io/license
  2847. */
  2848. /**
  2849. * \@ngModule CommonModule
  2850. *
  2851. * \@whatItDoes Adds / removes DOM sub-trees based on a numeric value. Tailored for pluralization.
  2852. *
  2853. * \@howToUse
  2854. * ```
  2855. * <some-element [ngPlural]="value">
  2856. * <ng-template ngPluralCase="=0">there is nothing</ng-template>
  2857. * <ng-template ngPluralCase="=1">there is one</ng-template>
  2858. * <ng-template ngPluralCase="few">there are a few</ng-template>
  2859. * </some-element>
  2860. * ```
  2861. *
  2862. * \@description
  2863. *
  2864. * Displays DOM sub-trees that match the switch expression value, or failing that, DOM sub-trees
  2865. * that match the switch expression's pluralization category.
  2866. *
  2867. * To use this directive you must provide a container element that sets the `[ngPlural]` attribute
  2868. * to a switch expression. Inner elements with a `[ngPluralCase]` will display based on their
  2869. * expression:
  2870. * - if `[ngPluralCase]` is set to a value starting with `=`, it will only display if the value
  2871. * matches the switch expression exactly,
  2872. * - otherwise, the view will be treated as a "category match", and will only display if exact
  2873. * value matches aren't found and the value maps to its category for the defined locale.
  2874. *
  2875. * See http://cldr.unicode.org/index/cldr-spec/plural-rules
  2876. *
  2877. * \@experimental
  2878. */
  2879. class NgPlural {
  2880. /**
  2881. * @param {?} _localization
  2882. */
  2883. constructor(_localization) {
  2884. this._localization = _localization;
  2885. this._caseViews = {};
  2886. }
  2887. /**
  2888. * @param {?} value
  2889. * @return {?}
  2890. */
  2891. set ngPlural(value) {
  2892. this._switchValue = value;
  2893. this._updateView();
  2894. }
  2895. /**
  2896. * @param {?} value
  2897. * @param {?} switchView
  2898. * @return {?}
  2899. */
  2900. addCase(value, switchView) { this._caseViews[value] = switchView; }
  2901. /**
  2902. * @return {?}
  2903. */
  2904. _updateView() {
  2905. this._clearViews();
  2906. const /** @type {?} */ cases = Object.keys(this._caseViews);
  2907. const /** @type {?} */ key = getPluralCategory(this._switchValue, cases, this._localization);
  2908. this._activateView(this._caseViews[key]);
  2909. }
  2910. /**
  2911. * @return {?}
  2912. */
  2913. _clearViews() {
  2914. if (this._activeView)
  2915. this._activeView.destroy();
  2916. }
  2917. /**
  2918. * @param {?} view
  2919. * @return {?}
  2920. */
  2921. _activateView(view) {
  2922. if (view) {
  2923. this._activeView = view;
  2924. this._activeView.create();
  2925. }
  2926. }
  2927. }
  2928. NgPlural.decorators = [
  2929. { type: Directive, args: [{ selector: '[ngPlural]' },] },
  2930. ];
  2931. /** @nocollapse */
  2932. NgPlural.ctorParameters = () => [
  2933. { type: NgLocalization, },
  2934. ];
  2935. NgPlural.propDecorators = {
  2936. "ngPlural": [{ type: Input },],
  2937. };
  2938. /**
  2939. * \@ngModule CommonModule
  2940. *
  2941. * \@whatItDoes Creates a view that will be added/removed from the parent {\@link NgPlural} when the
  2942. * given expression matches the plural expression according to CLDR rules.
  2943. *
  2944. * \@howToUse
  2945. * ```
  2946. * <some-element [ngPlural]="value">
  2947. * <ng-template ngPluralCase="=0">...</ng-template>
  2948. * <ng-template ngPluralCase="other">...</ng-template>
  2949. * </some-element>
  2950. * ```
  2951. *
  2952. * See {\@link NgPlural} for more details and example.
  2953. *
  2954. * \@experimental
  2955. */
  2956. class NgPluralCase {
  2957. /**
  2958. * @param {?} value
  2959. * @param {?} template
  2960. * @param {?} viewContainer
  2961. * @param {?} ngPlural
  2962. */
  2963. constructor(value, template, viewContainer, ngPlural) {
  2964. this.value = value;
  2965. const /** @type {?} */ isANumber = !isNaN(Number(value));
  2966. ngPlural.addCase(isANumber ? `=${value}` : value, new SwitchView(viewContainer, template));
  2967. }
  2968. }
  2969. NgPluralCase.decorators = [
  2970. { type: Directive, args: [{ selector: '[ngPluralCase]' },] },
  2971. ];
  2972. /** @nocollapse */
  2973. NgPluralCase.ctorParameters = () => [
  2974. { type: undefined, decorators: [{ type: Attribute, args: ['ngPluralCase',] },] },
  2975. { type: TemplateRef, },
  2976. { type: ViewContainerRef, },
  2977. { type: NgPlural, decorators: [{ type: Host },] },
  2978. ];
  2979. /**
  2980. * @fileoverview added by tsickle
  2981. * @suppress {checkTypes} checked by tsc
  2982. */
  2983. /**
  2984. * @license
  2985. * Copyright Google Inc. All Rights Reserved.
  2986. *
  2987. * Use of this source code is governed by an MIT-style license that can be
  2988. * found in the LICENSE file at https://angular.io/license
  2989. */
  2990. /**
  2991. * \@ngModule CommonModule
  2992. *
  2993. * \@whatItDoes Update an HTML element styles.
  2994. *
  2995. * \@howToUse
  2996. * ```
  2997. * <some-element [ngStyle]="{'font-style': styleExp}">...</some-element>
  2998. *
  2999. * <some-element [ngStyle]="{'max-width.px': widthExp}">...</some-element>
  3000. *
  3001. * <some-element [ngStyle]="objExp">...</some-element>
  3002. * ```
  3003. *
  3004. * \@description
  3005. *
  3006. * The styles are updated according to the value of the expression evaluation:
  3007. * - keys are style names with an optional `.<unit>` suffix (ie 'top.px', 'font-style.em'),
  3008. * - values are the values assigned to those properties (expressed in the given unit).
  3009. *
  3010. * \@stable
  3011. */
  3012. class NgStyle {
  3013. /**
  3014. * @param {?} _differs
  3015. * @param {?} _ngEl
  3016. * @param {?} _renderer
  3017. */
  3018. constructor(_differs, _ngEl, _renderer) {
  3019. this._differs = _differs;
  3020. this._ngEl = _ngEl;
  3021. this._renderer = _renderer;
  3022. }
  3023. /**
  3024. * @param {?} v
  3025. * @return {?}
  3026. */
  3027. set ngStyle(v) {
  3028. this._ngStyle = v;
  3029. if (!this._differ && v) {
  3030. this._differ = this._differs.find(v).create();
  3031. }
  3032. }
  3033. /**
  3034. * @return {?}
  3035. */
  3036. ngDoCheck() {
  3037. if (this._differ) {
  3038. const /** @type {?} */ changes = this._differ.diff(this._ngStyle);
  3039. if (changes) {
  3040. this._applyChanges(changes);
  3041. }
  3042. }
  3043. }
  3044. /**
  3045. * @param {?} changes
  3046. * @return {?}
  3047. */
  3048. _applyChanges(changes) {
  3049. changes.forEachRemovedItem((record) => this._setStyle(record.key, null));
  3050. changes.forEachAddedItem((record) => this._setStyle(record.key, record.currentValue));
  3051. changes.forEachChangedItem((record) => this._setStyle(record.key, record.currentValue));
  3052. }
  3053. /**
  3054. * @param {?} nameAndUnit
  3055. * @param {?} value
  3056. * @return {?}
  3057. */
  3058. _setStyle(nameAndUnit, value) {
  3059. const [name, unit] = nameAndUnit.split('.');
  3060. value = value != null && unit ? `${value}${unit}` : value;
  3061. if (value != null) {
  3062. this._renderer.setStyle(this._ngEl.nativeElement, name, /** @type {?} */ (value));
  3063. }
  3064. else {
  3065. this._renderer.removeStyle(this._ngEl.nativeElement, name);
  3066. }
  3067. }
  3068. }
  3069. NgStyle.decorators = [
  3070. { type: Directive, args: [{ selector: '[ngStyle]' },] },
  3071. ];
  3072. /** @nocollapse */
  3073. NgStyle.ctorParameters = () => [
  3074. { type: KeyValueDiffers, },
  3075. { type: ElementRef, },
  3076. { type: Renderer2, },
  3077. ];
  3078. NgStyle.propDecorators = {
  3079. "ngStyle": [{ type: Input },],
  3080. };
  3081. /**
  3082. * @fileoverview added by tsickle
  3083. * @suppress {checkTypes} checked by tsc
  3084. */
  3085. /**
  3086. * @license
  3087. * Copyright Google Inc. All Rights Reserved.
  3088. *
  3089. * Use of this source code is governed by an MIT-style license that can be
  3090. * found in the LICENSE file at https://angular.io/license
  3091. */
  3092. /**
  3093. * \@ngModule CommonModule
  3094. *
  3095. * \@whatItDoes Inserts an embedded view from a prepared `TemplateRef`
  3096. *
  3097. * \@howToUse
  3098. * ```
  3099. * <ng-container *ngTemplateOutlet="templateRefExp; context: contextExp"></ng-container>
  3100. * ```
  3101. *
  3102. * \@description
  3103. *
  3104. * You can attach a context object to the `EmbeddedViewRef` by setting `[ngTemplateOutletContext]`.
  3105. * `[ngTemplateOutletContext]` should be an object, the object's keys will be available for binding
  3106. * by the local template `let` declarations.
  3107. *
  3108. * Note: using the key `$implicit` in the context object will set its value as default.
  3109. *
  3110. * ## Example
  3111. *
  3112. * {\@example common/ngTemplateOutlet/ts/module.ts region='NgTemplateOutlet'}
  3113. *
  3114. * \@stable
  3115. */
  3116. class NgTemplateOutlet {
  3117. /**
  3118. * @param {?} _viewContainerRef
  3119. */
  3120. constructor(_viewContainerRef) {
  3121. this._viewContainerRef = _viewContainerRef;
  3122. }
  3123. /**
  3124. * @param {?} changes
  3125. * @return {?}
  3126. */
  3127. ngOnChanges(changes) {
  3128. const /** @type {?} */ recreateView = this._shouldRecreateView(changes);
  3129. if (recreateView) {
  3130. if (this._viewRef) {
  3131. this._viewContainerRef.remove(this._viewContainerRef.indexOf(this._viewRef));
  3132. }
  3133. if (this.ngTemplateOutlet) {
  3134. this._viewRef = this._viewContainerRef.createEmbeddedView(this.ngTemplateOutlet, this.ngTemplateOutletContext);
  3135. }
  3136. }
  3137. else {
  3138. if (this._viewRef && this.ngTemplateOutletContext) {
  3139. this._updateExistingContext(this.ngTemplateOutletContext);
  3140. }
  3141. }
  3142. }
  3143. /**
  3144. * We need to re-create existing embedded view if:
  3145. * - templateRef has changed
  3146. * - context has changes
  3147. *
  3148. * We mark context object as changed when the corresponding object
  3149. * shape changes (new properties are added or existing properties are removed).
  3150. * In other words we consider context with the same properties as "the same" even
  3151. * if object reference changes (see https://github.com/angular/angular/issues/13407).
  3152. * @param {?} changes
  3153. * @return {?}
  3154. */
  3155. _shouldRecreateView(changes) {
  3156. const /** @type {?} */ ctxChange = changes['ngTemplateOutletContext'];
  3157. return !!changes['ngTemplateOutlet'] || (ctxChange && this._hasContextShapeChanged(ctxChange));
  3158. }
  3159. /**
  3160. * @param {?} ctxChange
  3161. * @return {?}
  3162. */
  3163. _hasContextShapeChanged(ctxChange) {
  3164. const /** @type {?} */ prevCtxKeys = Object.keys(ctxChange.previousValue || {});
  3165. const /** @type {?} */ currCtxKeys = Object.keys(ctxChange.currentValue || {});
  3166. if (prevCtxKeys.length === currCtxKeys.length) {
  3167. for (let /** @type {?} */ propName of currCtxKeys) {
  3168. if (prevCtxKeys.indexOf(propName) === -1) {
  3169. return true;
  3170. }
  3171. }
  3172. return false;
  3173. }
  3174. else {
  3175. return true;
  3176. }
  3177. }
  3178. /**
  3179. * @param {?} ctx
  3180. * @return {?}
  3181. */
  3182. _updateExistingContext(ctx) {
  3183. for (let /** @type {?} */ propName of Object.keys(ctx)) {
  3184. (/** @type {?} */ (this._viewRef.context))[propName] = (/** @type {?} */ (this.ngTemplateOutletContext))[propName];
  3185. }
  3186. }
  3187. }
  3188. NgTemplateOutlet.decorators = [
  3189. { type: Directive, args: [{ selector: '[ngTemplateOutlet]' },] },
  3190. ];
  3191. /** @nocollapse */
  3192. NgTemplateOutlet.ctorParameters = () => [
  3193. { type: ViewContainerRef, },
  3194. ];
  3195. NgTemplateOutlet.propDecorators = {
  3196. "ngTemplateOutletContext": [{ type: Input },],
  3197. "ngTemplateOutlet": [{ type: Input },],
  3198. };
  3199. /**
  3200. * @fileoverview added by tsickle
  3201. * @suppress {checkTypes} checked by tsc
  3202. */
  3203. /**
  3204. * @license
  3205. * Copyright Google Inc. All Rights Reserved.
  3206. *
  3207. * Use of this source code is governed by an MIT-style license that can be
  3208. * found in the LICENSE file at https://angular.io/license
  3209. */
  3210. /**
  3211. * A collection of Angular directives that are likely to be used in each and every Angular
  3212. * application.
  3213. */
  3214. const COMMON_DIRECTIVES = [
  3215. NgClass,
  3216. NgComponentOutlet,
  3217. NgForOf,
  3218. NgIf,
  3219. NgTemplateOutlet,
  3220. NgStyle,
  3221. NgSwitch,
  3222. NgSwitchCase,
  3223. NgSwitchDefault,
  3224. NgPlural,
  3225. NgPluralCase,
  3226. ];
  3227. /**
  3228. * @fileoverview added by tsickle
  3229. * @suppress {checkTypes} checked by tsc
  3230. */
  3231. /**
  3232. * @license
  3233. * Copyright Google Inc. All Rights Reserved.
  3234. *
  3235. * Use of this source code is governed by an MIT-style license that can be
  3236. * found in the LICENSE file at https://angular.io/license
  3237. */
  3238. const NAMED_FORMATS = {};
  3239. const DATE_FORMATS_SPLIT = /((?:[^GyMLwWdEabBhHmsSzZO']+)|(?:'(?:[^']|'')*')|(?:G{1,5}|y{1,4}|M{1,5}|L{1,5}|w{1,2}|W{1}|d{1,2}|E{1,6}|a{1,5}|b{1,5}|B{1,5}|h{1,2}|H{1,2}|m{1,2}|s{1,2}|S{1,3}|z{1,4}|Z{1,5}|O{1,4}))([\s\S]*)/;
  3240. /** @enum {number} */
  3241. const ZoneWidth = {
  3242. Short: 0,
  3243. ShortGMT: 1,
  3244. Long: 2,
  3245. Extended: 3,
  3246. };
  3247. ZoneWidth[ZoneWidth.Short] = "Short";
  3248. ZoneWidth[ZoneWidth.ShortGMT] = "ShortGMT";
  3249. ZoneWidth[ZoneWidth.Long] = "Long";
  3250. ZoneWidth[ZoneWidth.Extended] = "Extended";
  3251. /** @enum {number} */
  3252. const DateType = {
  3253. FullYear: 0,
  3254. Month: 1,
  3255. Date: 2,
  3256. Hours: 3,
  3257. Minutes: 4,
  3258. Seconds: 5,
  3259. Milliseconds: 6,
  3260. Day: 7,
  3261. };
  3262. DateType[DateType.FullYear] = "FullYear";
  3263. DateType[DateType.Month] = "Month";
  3264. DateType[DateType.Date] = "Date";
  3265. DateType[DateType.Hours] = "Hours";
  3266. DateType[DateType.Minutes] = "Minutes";
  3267. DateType[DateType.Seconds] = "Seconds";
  3268. DateType[DateType.Milliseconds] = "Milliseconds";
  3269. DateType[DateType.Day] = "Day";
  3270. /** @enum {number} */
  3271. const TranslationType = {
  3272. DayPeriods: 0,
  3273. Days: 1,
  3274. Months: 2,
  3275. Eras: 3,
  3276. };
  3277. TranslationType[TranslationType.DayPeriods] = "DayPeriods";
  3278. TranslationType[TranslationType.Days] = "Days";
  3279. TranslationType[TranslationType.Months] = "Months";
  3280. TranslationType[TranslationType.Eras] = "Eras";
  3281. /**
  3282. * Transforms a date to a locale string based on a pattern and a timezone
  3283. *
  3284. * \@internal
  3285. * @param {?} date
  3286. * @param {?} format
  3287. * @param {?} locale
  3288. * @param {?=} timezone
  3289. * @return {?}
  3290. */
  3291. function formatDate(date, format, locale, timezone) {
  3292. const /** @type {?} */ namedFormat = getNamedFormat(locale, format);
  3293. format = namedFormat || format;
  3294. let /** @type {?} */ parts = [];
  3295. let /** @type {?} */ match;
  3296. while (format) {
  3297. match = DATE_FORMATS_SPLIT.exec(format);
  3298. if (match) {
  3299. parts = parts.concat(match.slice(1));
  3300. const /** @type {?} */ part = parts.pop();
  3301. if (!part) {
  3302. break;
  3303. }
  3304. format = part;
  3305. }
  3306. else {
  3307. parts.push(format);
  3308. break;
  3309. }
  3310. }
  3311. let /** @type {?} */ dateTimezoneOffset = date.getTimezoneOffset();
  3312. if (timezone) {
  3313. dateTimezoneOffset = timezoneToOffset(timezone, dateTimezoneOffset);
  3314. date = convertTimezoneToLocal(date, timezone, true);
  3315. }
  3316. let /** @type {?} */ text = '';
  3317. parts.forEach(value => {
  3318. const /** @type {?} */ dateFormatter = getDateFormatter(value);
  3319. text += dateFormatter ?
  3320. dateFormatter(date, locale, dateTimezoneOffset) :
  3321. value === '\'\'' ? '\'' : value.replace(/(^'|'$)/g, '').replace(/''/g, '\'');
  3322. });
  3323. return text;
  3324. }
  3325. /**
  3326. * @param {?} locale
  3327. * @param {?} format
  3328. * @return {?}
  3329. */
  3330. function getNamedFormat(locale, format) {
  3331. const /** @type {?} */ localeId = getLocaleId(locale);
  3332. NAMED_FORMATS[localeId] = NAMED_FORMATS[localeId] || {};
  3333. if (NAMED_FORMATS[localeId][format]) {
  3334. return NAMED_FORMATS[localeId][format];
  3335. }
  3336. let /** @type {?} */ formatValue = '';
  3337. switch (format) {
  3338. case 'shortDate':
  3339. formatValue = getLocaleDateFormat(locale, FormatWidth.Short);
  3340. break;
  3341. case 'mediumDate':
  3342. formatValue = getLocaleDateFormat(locale, FormatWidth.Medium);
  3343. break;
  3344. case 'longDate':
  3345. formatValue = getLocaleDateFormat(locale, FormatWidth.Long);
  3346. break;
  3347. case 'fullDate':
  3348. formatValue = getLocaleDateFormat(locale, FormatWidth.Full);
  3349. break;
  3350. case 'shortTime':
  3351. formatValue = getLocaleTimeFormat(locale, FormatWidth.Short);
  3352. break;
  3353. case 'mediumTime':
  3354. formatValue = getLocaleTimeFormat(locale, FormatWidth.Medium);
  3355. break;
  3356. case 'longTime':
  3357. formatValue = getLocaleTimeFormat(locale, FormatWidth.Long);
  3358. break;
  3359. case 'fullTime':
  3360. formatValue = getLocaleTimeFormat(locale, FormatWidth.Full);
  3361. break;
  3362. case 'short':
  3363. const /** @type {?} */ shortTime = getNamedFormat(locale, 'shortTime');
  3364. const /** @type {?} */ shortDate = getNamedFormat(locale, 'shortDate');
  3365. formatValue = formatDateTime(getLocaleDateTimeFormat(locale, FormatWidth.Short), [shortTime, shortDate]);
  3366. break;
  3367. case 'medium':
  3368. const /** @type {?} */ mediumTime = getNamedFormat(locale, 'mediumTime');
  3369. const /** @type {?} */ mediumDate = getNamedFormat(locale, 'mediumDate');
  3370. formatValue = formatDateTime(getLocaleDateTimeFormat(locale, FormatWidth.Medium), [mediumTime, mediumDate]);
  3371. break;
  3372. case 'long':
  3373. const /** @type {?} */ longTime = getNamedFormat(locale, 'longTime');
  3374. const /** @type {?} */ longDate = getNamedFormat(locale, 'longDate');
  3375. formatValue =
  3376. formatDateTime(getLocaleDateTimeFormat(locale, FormatWidth.Long), [longTime, longDate]);
  3377. break;
  3378. case 'full':
  3379. const /** @type {?} */ fullTime = getNamedFormat(locale, 'fullTime');
  3380. const /** @type {?} */ fullDate = getNamedFormat(locale, 'fullDate');
  3381. formatValue =
  3382. formatDateTime(getLocaleDateTimeFormat(locale, FormatWidth.Full), [fullTime, fullDate]);
  3383. break;
  3384. }
  3385. if (formatValue) {
  3386. NAMED_FORMATS[localeId][format] = formatValue;
  3387. }
  3388. return formatValue;
  3389. }
  3390. /**
  3391. * @param {?} str
  3392. * @param {?} opt_values
  3393. * @return {?}
  3394. */
  3395. function formatDateTime(str, opt_values) {
  3396. if (opt_values) {
  3397. str = str.replace(/\{([^}]+)}/g, function (match, key) {
  3398. return (opt_values != null && key in opt_values) ? opt_values[key] : match;
  3399. });
  3400. }
  3401. return str;
  3402. }
  3403. /**
  3404. * @param {?} num
  3405. * @param {?} digits
  3406. * @param {?=} minusSign
  3407. * @param {?=} trim
  3408. * @param {?=} negWrap
  3409. * @return {?}
  3410. */
  3411. function padNumber(num, digits, minusSign = '-', trim, negWrap) {
  3412. let /** @type {?} */ neg = '';
  3413. if (num < 0 || (negWrap && num <= 0)) {
  3414. if (negWrap) {
  3415. num = -num + 1;
  3416. }
  3417. else {
  3418. num = -num;
  3419. neg = minusSign;
  3420. }
  3421. }
  3422. let /** @type {?} */ strNum = '' + num;
  3423. while (strNum.length < digits)
  3424. strNum = '0' + strNum;
  3425. if (trim) {
  3426. strNum = strNum.substr(strNum.length - digits);
  3427. }
  3428. return neg + strNum;
  3429. }
  3430. /**
  3431. * Returns a date formatter that transforms a date into its locale digit representation
  3432. * @param {?} name
  3433. * @param {?} size
  3434. * @param {?=} offset
  3435. * @param {?=} trim
  3436. * @param {?=} negWrap
  3437. * @return {?}
  3438. */
  3439. function dateGetter(name, size, offset = 0, trim = false, negWrap = false) {
  3440. return function (date, locale) {
  3441. let /** @type {?} */ part = getDatePart(name, date, size);
  3442. if (offset > 0 || part > -offset) {
  3443. part += offset;
  3444. }
  3445. if (name === DateType.Hours && part === 0 && offset === -12) {
  3446. part = 12;
  3447. }
  3448. return padNumber(part, size, getLocaleNumberSymbol(locale, NumberSymbol.MinusSign), trim, negWrap);
  3449. };
  3450. }
  3451. /**
  3452. * @param {?} name
  3453. * @param {?} date
  3454. * @param {?} size
  3455. * @return {?}
  3456. */
  3457. function getDatePart(name, date, size) {
  3458. switch (name) {
  3459. case DateType.FullYear:
  3460. return date.getFullYear();
  3461. case DateType.Month:
  3462. return date.getMonth();
  3463. case DateType.Date:
  3464. return date.getDate();
  3465. case DateType.Hours:
  3466. return date.getHours();
  3467. case DateType.Minutes:
  3468. return date.getMinutes();
  3469. case DateType.Seconds:
  3470. return date.getSeconds();
  3471. case DateType.Milliseconds:
  3472. const /** @type {?} */ div = size === 1 ? 100 : (size === 2 ? 10 : 1);
  3473. return Math.round(date.getMilliseconds() / div);
  3474. case DateType.Day:
  3475. return date.getDay();
  3476. default:
  3477. throw new Error(`Unknown DateType value "${name}".`);
  3478. }
  3479. }
  3480. /**
  3481. * Returns a date formatter that transforms a date into its locale string representation
  3482. * @param {?} name
  3483. * @param {?} width
  3484. * @param {?=} form
  3485. * @param {?=} extended
  3486. * @return {?}
  3487. */
  3488. function dateStrGetter(name, width, form = FormStyle.Format, extended = false) {
  3489. return function (date, locale) {
  3490. return getDateTranslation(date, locale, name, width, form, extended);
  3491. };
  3492. }
  3493. /**
  3494. * Returns the locale translation of a date for a given form, type and width
  3495. * @param {?} date
  3496. * @param {?} locale
  3497. * @param {?} name
  3498. * @param {?} width
  3499. * @param {?} form
  3500. * @param {?} extended
  3501. * @return {?}
  3502. */
  3503. function getDateTranslation(date, locale, name, width, form, extended) {
  3504. switch (name) {
  3505. case TranslationType.Months:
  3506. return getLocaleMonthNames(locale, form, width)[date.getMonth()];
  3507. case TranslationType.Days:
  3508. return getLocaleDayNames(locale, form, width)[date.getDay()];
  3509. case TranslationType.DayPeriods:
  3510. const /** @type {?} */ currentHours = date.getHours();
  3511. const /** @type {?} */ currentMinutes = date.getMinutes();
  3512. if (extended) {
  3513. const /** @type {?} */ rules = getLocaleExtraDayPeriodRules(locale);
  3514. const /** @type {?} */ dayPeriods = getLocaleExtraDayPeriods(locale, form, width);
  3515. let /** @type {?} */ result;
  3516. rules.forEach((rule, index) => {
  3517. if (Array.isArray(rule)) {
  3518. // morning, afternoon, evening, night
  3519. const { hours: hoursFrom, minutes: minutesFrom } = rule[0];
  3520. const { hours: hoursTo, minutes: minutesTo } = rule[1];
  3521. if (currentHours >= hoursFrom && currentMinutes >= minutesFrom &&
  3522. (currentHours < hoursTo ||
  3523. (currentHours === hoursTo && currentMinutes < minutesTo))) {
  3524. result = dayPeriods[index];
  3525. }
  3526. }
  3527. else {
  3528. // noon or midnight
  3529. const { hours, minutes } = rule;
  3530. if (hours === currentHours && minutes === currentMinutes) {
  3531. result = dayPeriods[index];
  3532. }
  3533. }
  3534. });
  3535. if (result) {
  3536. return result;
  3537. }
  3538. }
  3539. // if no rules for the day periods, we use am/pm by default
  3540. return getLocaleDayPeriods(locale, form, /** @type {?} */ (width))[currentHours < 12 ? 0 : 1];
  3541. case TranslationType.Eras:
  3542. return getLocaleEraNames(locale, /** @type {?} */ (width))[date.getFullYear() <= 0 ? 0 : 1];
  3543. default:
  3544. // This default case is not needed by TypeScript compiler, as the switch is exhaustive.
  3545. // However Closure Compiler does not understand that and reports an error in typed mode.
  3546. // The `throw new Error` below works around the problem, and the unexpected: never variable
  3547. // makes sure tsc still checks this code is unreachable.
  3548. const /** @type {?} */ unexpected = name;
  3549. throw new Error(`unexpected translation type ${unexpected}`);
  3550. }
  3551. }
  3552. /**
  3553. * Returns a date formatter that transforms a date and an offset into a timezone with ISO8601 or
  3554. * GMT format depending on the width (eg: short = +0430, short:GMT = GMT+4, long = GMT+04:30,
  3555. * extended = +04:30)
  3556. * @param {?} width
  3557. * @return {?}
  3558. */
  3559. function timeZoneGetter(width) {
  3560. return function (date, locale, offset) {
  3561. const /** @type {?} */ zone = -1 * offset;
  3562. const /** @type {?} */ minusSign = getLocaleNumberSymbol(locale, NumberSymbol.MinusSign);
  3563. const /** @type {?} */ hours = zone > 0 ? Math.floor(zone / 60) : Math.ceil(zone / 60);
  3564. switch (width) {
  3565. case ZoneWidth.Short:
  3566. return ((zone >= 0) ? '+' : '') + padNumber(hours, 2, minusSign) +
  3567. padNumber(Math.abs(zone % 60), 2, minusSign);
  3568. case ZoneWidth.ShortGMT:
  3569. return 'GMT' + ((zone >= 0) ? '+' : '') + padNumber(hours, 1, minusSign);
  3570. case ZoneWidth.Long:
  3571. return 'GMT' + ((zone >= 0) ? '+' : '') + padNumber(hours, 2, minusSign) + ':' +
  3572. padNumber(Math.abs(zone % 60), 2, minusSign);
  3573. case ZoneWidth.Extended:
  3574. if (offset === 0) {
  3575. return 'Z';
  3576. }
  3577. else {
  3578. return ((zone >= 0) ? '+' : '') + padNumber(hours, 2, minusSign) + ':' +
  3579. padNumber(Math.abs(zone % 60), 2, minusSign);
  3580. }
  3581. default:
  3582. throw new Error(`Unknown zone width "${width}"`);
  3583. }
  3584. };
  3585. }
  3586. const JANUARY = 0;
  3587. const THURSDAY = 4;
  3588. /**
  3589. * @param {?} year
  3590. * @return {?}
  3591. */
  3592. function getFirstThursdayOfYear(year) {
  3593. const /** @type {?} */ firstDayOfYear = (new Date(year, JANUARY, 1)).getDay();
  3594. return new Date(year, 0, 1 + ((firstDayOfYear <= THURSDAY) ? THURSDAY : THURSDAY + 7) - firstDayOfYear);
  3595. }
  3596. /**
  3597. * @param {?} datetime
  3598. * @return {?}
  3599. */
  3600. function getThursdayThisWeek(datetime) {
  3601. return new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate() + (THURSDAY - datetime.getDay()));
  3602. }
  3603. /**
  3604. * @param {?} size
  3605. * @param {?=} monthBased
  3606. * @return {?}
  3607. */
  3608. function weekGetter(size, monthBased = false) {
  3609. return function (date, locale) {
  3610. let /** @type {?} */ result;
  3611. if (monthBased) {
  3612. const /** @type {?} */ nbDaysBefore1stDayOfMonth = new Date(date.getFullYear(), date.getMonth(), 1).getDay() - 1;
  3613. const /** @type {?} */ today = date.getDate();
  3614. result = 1 + Math.floor((today + nbDaysBefore1stDayOfMonth) / 7);
  3615. }
  3616. else {
  3617. const /** @type {?} */ firstThurs = getFirstThursdayOfYear(date.getFullYear());
  3618. const /** @type {?} */ thisThurs = getThursdayThisWeek(date);
  3619. const /** @type {?} */ diff = thisThurs.getTime() - firstThurs.getTime();
  3620. result = 1 + Math.round(diff / 6.048e8); // 6.048e8 ms per week
  3621. }
  3622. return padNumber(result, size, getLocaleNumberSymbol(locale, NumberSymbol.MinusSign));
  3623. };
  3624. }
  3625. const DATE_FORMATS = {};
  3626. /**
  3627. * @param {?} format
  3628. * @return {?}
  3629. */
  3630. function getDateFormatter(format) {
  3631. if (DATE_FORMATS[format]) {
  3632. return DATE_FORMATS[format];
  3633. }
  3634. let /** @type {?} */ formatter;
  3635. switch (format) {
  3636. // Era name (AD/BC)
  3637. case 'G':
  3638. case 'GG':
  3639. case 'GGG':
  3640. formatter = dateStrGetter(TranslationType.Eras, TranslationWidth.Abbreviated);
  3641. break;
  3642. case 'GGGG':
  3643. formatter = dateStrGetter(TranslationType.Eras, TranslationWidth.Wide);
  3644. break;
  3645. case 'GGGGG':
  3646. formatter = dateStrGetter(TranslationType.Eras, TranslationWidth.Narrow);
  3647. break;
  3648. // 1 digit representation of the year, e.g. (AD 1 => 1, AD 199 => 199)
  3649. case 'y':
  3650. formatter = dateGetter(DateType.FullYear, 1, 0, false, true);
  3651. break;
  3652. // 2 digit representation of the year, padded (00-99). (e.g. AD 2001 => 01, AD 2010 => 10)
  3653. case 'yy':
  3654. formatter = dateGetter(DateType.FullYear, 2, 0, true, true);
  3655. break;
  3656. // 3 digit representation of the year, padded (000-999). (e.g. AD 2001 => 01, AD 2010 => 10)
  3657. case 'yyy':
  3658. formatter = dateGetter(DateType.FullYear, 3, 0, false, true);
  3659. break;
  3660. // 4 digit representation of the year (e.g. AD 1 => 0001, AD 2010 => 2010)
  3661. case 'yyyy':
  3662. formatter = dateGetter(DateType.FullYear, 4, 0, false, true);
  3663. break;
  3664. // Month of the year (1-12), numeric
  3665. case 'M':
  3666. case 'L':
  3667. formatter = dateGetter(DateType.Month, 1, 1);
  3668. break;
  3669. case 'MM':
  3670. case 'LL':
  3671. formatter = dateGetter(DateType.Month, 2, 1);
  3672. break;
  3673. // Month of the year (January, ...), string, format
  3674. case 'MMM':
  3675. formatter = dateStrGetter(TranslationType.Months, TranslationWidth.Abbreviated);
  3676. break;
  3677. case 'MMMM':
  3678. formatter = dateStrGetter(TranslationType.Months, TranslationWidth.Wide);
  3679. break;
  3680. case 'MMMMM':
  3681. formatter = dateStrGetter(TranslationType.Months, TranslationWidth.Narrow);
  3682. break;
  3683. // Month of the year (January, ...), string, standalone
  3684. case 'LLL':
  3685. formatter =
  3686. dateStrGetter(TranslationType.Months, TranslationWidth.Abbreviated, FormStyle.Standalone);
  3687. break;
  3688. case 'LLLL':
  3689. formatter =
  3690. dateStrGetter(TranslationType.Months, TranslationWidth.Wide, FormStyle.Standalone);
  3691. break;
  3692. case 'LLLLL':
  3693. formatter =
  3694. dateStrGetter(TranslationType.Months, TranslationWidth.Narrow, FormStyle.Standalone);
  3695. break;
  3696. // Week of the year (1, ... 52)
  3697. case 'w':
  3698. formatter = weekGetter(1);
  3699. break;
  3700. case 'ww':
  3701. formatter = weekGetter(2);
  3702. break;
  3703. // Week of the month (1, ...)
  3704. case 'W':
  3705. formatter = weekGetter(1, true);
  3706. break;
  3707. // Day of the month (1-31)
  3708. case 'd':
  3709. formatter = dateGetter(DateType.Date, 1);
  3710. break;
  3711. case 'dd':
  3712. formatter = dateGetter(DateType.Date, 2);
  3713. break;
  3714. // Day of the Week
  3715. case 'E':
  3716. case 'EE':
  3717. case 'EEE':
  3718. formatter = dateStrGetter(TranslationType.Days, TranslationWidth.Abbreviated);
  3719. break;
  3720. case 'EEEE':
  3721. formatter = dateStrGetter(TranslationType.Days, TranslationWidth.Wide);
  3722. break;
  3723. case 'EEEEE':
  3724. formatter = dateStrGetter(TranslationType.Days, TranslationWidth.Narrow);
  3725. break;
  3726. case 'EEEEEE':
  3727. formatter = dateStrGetter(TranslationType.Days, TranslationWidth.Short);
  3728. break;
  3729. // Generic period of the day (am-pm)
  3730. case 'a':
  3731. case 'aa':
  3732. case 'aaa':
  3733. formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Abbreviated);
  3734. break;
  3735. case 'aaaa':
  3736. formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Wide);
  3737. break;
  3738. case 'aaaaa':
  3739. formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Narrow);
  3740. break;
  3741. // Extended period of the day (midnight, at night, ...), standalone
  3742. case 'b':
  3743. case 'bb':
  3744. case 'bbb':
  3745. formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Abbreviated, FormStyle.Standalone, true);
  3746. break;
  3747. case 'bbbb':
  3748. formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Wide, FormStyle.Standalone, true);
  3749. break;
  3750. case 'bbbbb':
  3751. formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Narrow, FormStyle.Standalone, true);
  3752. break;
  3753. // Extended period of the day (midnight, night, ...), standalone
  3754. case 'B':
  3755. case 'BB':
  3756. case 'BBB':
  3757. formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Abbreviated, FormStyle.Format, true);
  3758. break;
  3759. case 'BBBB':
  3760. formatter =
  3761. dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Wide, FormStyle.Format, true);
  3762. break;
  3763. case 'BBBBB':
  3764. formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Narrow, FormStyle.Format, true);
  3765. break;
  3766. // Hour in AM/PM, (1-12)
  3767. case 'h':
  3768. formatter = dateGetter(DateType.Hours, 1, -12);
  3769. break;
  3770. case 'hh':
  3771. formatter = dateGetter(DateType.Hours, 2, -12);
  3772. break;
  3773. // Hour of the day (0-23)
  3774. case 'H':
  3775. formatter = dateGetter(DateType.Hours, 1);
  3776. break;
  3777. // Hour in day, padded (00-23)
  3778. case 'HH':
  3779. formatter = dateGetter(DateType.Hours, 2);
  3780. break;
  3781. // Minute of the hour (0-59)
  3782. case 'm':
  3783. formatter = dateGetter(DateType.Minutes, 1);
  3784. break;
  3785. case 'mm':
  3786. formatter = dateGetter(DateType.Minutes, 2);
  3787. break;
  3788. // Second of the minute (0-59)
  3789. case 's':
  3790. formatter = dateGetter(DateType.Seconds, 1);
  3791. break;
  3792. case 'ss':
  3793. formatter = dateGetter(DateType.Seconds, 2);
  3794. break;
  3795. // Fractional second padded (0-9)
  3796. case 'S':
  3797. formatter = dateGetter(DateType.Milliseconds, 1);
  3798. break;
  3799. case 'SS':
  3800. formatter = dateGetter(DateType.Milliseconds, 2);
  3801. break;
  3802. // = millisecond
  3803. case 'SSS':
  3804. formatter = dateGetter(DateType.Milliseconds, 3);
  3805. break;
  3806. // Timezone ISO8601 short format (-0430)
  3807. case 'Z':
  3808. case 'ZZ':
  3809. case 'ZZZ':
  3810. formatter = timeZoneGetter(ZoneWidth.Short);
  3811. break;
  3812. // Timezone ISO8601 extended format (-04:30)
  3813. case 'ZZZZZ':
  3814. formatter = timeZoneGetter(ZoneWidth.Extended);
  3815. break;
  3816. // Timezone GMT short format (GMT+4)
  3817. case 'O':
  3818. case 'OO':
  3819. case 'OOO':
  3820. // Should be location, but fallback to format O instead because we don't have the data yet
  3821. case 'z':
  3822. case 'zz':
  3823. case 'zzz':
  3824. formatter = timeZoneGetter(ZoneWidth.ShortGMT);
  3825. break;
  3826. // Timezone GMT long format (GMT+0430)
  3827. case 'OOOO':
  3828. case 'ZZZZ':
  3829. // Should be location, but fallback to format O instead because we don't have the data yet
  3830. case 'zzzz':
  3831. formatter = timeZoneGetter(ZoneWidth.Long);
  3832. break;
  3833. default:
  3834. return null;
  3835. }
  3836. DATE_FORMATS[format] = formatter;
  3837. return formatter;
  3838. }
  3839. /**
  3840. * @param {?} timezone
  3841. * @param {?} fallback
  3842. * @return {?}
  3843. */
  3844. function timezoneToOffset(timezone, fallback) {
  3845. // Support: IE 9-11 only, Edge 13-15+
  3846. // IE/Edge do not "understand" colon (`:`) in timezone
  3847. timezone = timezone.replace(/:/g, '');
  3848. const /** @type {?} */ requestedTimezoneOffset = Date.parse('Jan 01, 1970 00:00:00 ' + timezone) / 60000;
  3849. return isNaN(requestedTimezoneOffset) ? fallback : requestedTimezoneOffset;
  3850. }
  3851. /**
  3852. * @param {?} date
  3853. * @param {?} minutes
  3854. * @return {?}
  3855. */
  3856. function addDateMinutes(date, minutes) {
  3857. date = new Date(date.getTime());
  3858. date.setMinutes(date.getMinutes() + minutes);
  3859. return date;
  3860. }
  3861. /**
  3862. * @param {?} date
  3863. * @param {?} timezone
  3864. * @param {?} reverse
  3865. * @return {?}
  3866. */
  3867. function convertTimezoneToLocal(date, timezone, reverse) {
  3868. const /** @type {?} */ reverseValue = reverse ? -1 : 1;
  3869. const /** @type {?} */ dateTimezoneOffset = date.getTimezoneOffset();
  3870. const /** @type {?} */ timezoneOffset = timezoneToOffset(timezone, dateTimezoneOffset);
  3871. return addDateMinutes(date, reverseValue * (timezoneOffset - dateTimezoneOffset));
  3872. }
  3873. /**
  3874. * @fileoverview added by tsickle
  3875. * @suppress {checkTypes} checked by tsc
  3876. */
  3877. /**
  3878. * @license
  3879. * Copyright Google Inc. All Rights Reserved.
  3880. *
  3881. * Use of this source code is governed by an MIT-style license that can be
  3882. * found in the LICENSE file at https://angular.io/license
  3883. */
  3884. /**
  3885. * @param {?} type
  3886. * @param {?} value
  3887. * @return {?}
  3888. */
  3889. function invalidPipeArgumentError(type, value) {
  3890. return Error(`InvalidPipeArgument: '${value}' for pipe '${ɵstringify(type)}'`);
  3891. }
  3892. /**
  3893. * @fileoverview added by tsickle
  3894. * @suppress {checkTypes} checked by tsc
  3895. */
  3896. /**
  3897. * @license
  3898. * Copyright Google Inc. All Rights Reserved.
  3899. *
  3900. * Use of this source code is governed by an MIT-style license that can be
  3901. * found in the LICENSE file at https://angular.io/license
  3902. */
  3903. const ISO8601_DATE_REGEX = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
  3904. /**
  3905. * \@ngModule CommonModule
  3906. * \@whatItDoes Formats a date according to locale rules.
  3907. * \@howToUse `date_expression | date[:format[:timezone[:locale]]]`
  3908. * \@description
  3909. *
  3910. * Where:
  3911. * - `expression` is a date object or a number (milliseconds since UTC epoch) or an ISO string
  3912. * (https://www.w3.org/TR/NOTE-datetime).
  3913. * - `format` indicates which date/time components to include. The format can be predefined as
  3914. * shown below (all examples are given for `en-US`) or custom as shown in the table.
  3915. * - `'short'`: equivalent to `'M/d/yy, h:mm a'` (e.g. `6/15/15, 9:03 AM`)
  3916. * - `'medium'`: equivalent to `'MMM d, y, h:mm:ss a'` (e.g. `Jun 15, 2015, 9:03:01 AM`)
  3917. * - `'long'`: equivalent to `'MMMM d, y, h:mm:ss a z'` (e.g. `June 15, 2015 at 9:03:01 AM GMT+1`)
  3918. * - `'full'`: equivalent to `'EEEE, MMMM d, y, h:mm:ss a zzzz'` (e.g. `Monday, June 15, 2015 at
  3919. * 9:03:01 AM GMT+01:00`)
  3920. * - `'shortDate'`: equivalent to `'M/d/yy'` (e.g. `6/15/15`)
  3921. * - `'mediumDate'`: equivalent to `'MMM d, y'` (e.g. `Jun 15, 2015`)
  3922. * - `'longDate'`: equivalent to `'MMMM d, y'` (e.g. `June 15, 2015`)
  3923. * - `'fullDate'`: equivalent to `'EEEE, MMMM d, y'` (e.g. `Monday, June 15, 2015`)
  3924. * - `'shortTime'`: equivalent to `'h:mm a'` (e.g. `9:03 AM`)
  3925. * - `'mediumTime'`: equivalent to `'h:mm:ss a'` (e.g. `9:03:01 AM`)
  3926. * - `'longTime'`: equivalent to `'h:mm:ss a z'` (e.g. `9:03:01 AM GMT+1`)
  3927. * - `'fullTime'`: equivalent to `'h:mm:ss a zzzz'` (e.g. `9:03:01 AM GMT+01:00`)
  3928. * - `timezone` to be used for formatting. It understands UTC/GMT and the continental US time zone
  3929. * abbreviations, but for general use, use a time zone offset, for example,
  3930. * `'+0430'` (4 hours, 30 minutes east of the Greenwich meridian)
  3931. * If not specified, the local system timezone of the end-user's browser will be used.
  3932. * - `locale` is a `string` defining the locale to use (uses the current {\@link LOCALE_ID} by
  3933. * default)
  3934. *
  3935. *
  3936. * | Field Type | Format | Description | Example Value |
  3937. * |--------------------|-------------|---------------------------------------------------------------|------------------------------------------------------------|
  3938. * | Era | G, GG & GGG | Abbreviated | AD |
  3939. * | | GGGG | Wide | Anno Domini |
  3940. * | | GGGGG | Narrow | A |
  3941. * | Year | y | Numeric: minimum digits | 2, 20, 201, 2017, 20173 |
  3942. * | | yy | Numeric: 2 digits + zero padded | 02, 20, 01, 17, 73 |
  3943. * | | yyy | Numeric: 3 digits + zero padded | 002, 020, 201, 2017, 20173 |
  3944. * | | yyyy | Numeric: 4 digits or more + zero padded | 0002, 0020, 0201, 2017, 20173 |
  3945. * | Month | M | Numeric: 1 digit | 9, 12 |
  3946. * | | MM | Numeric: 2 digits + zero padded | 09, 12 |
  3947. * | | MMM | Abbreviated | Sep |
  3948. * | | MMMM | Wide | September |
  3949. * | | MMMMM | Narrow | S |
  3950. * | Month standalone | L | Numeric: 1 digit | 9, 12 |
  3951. * | | LL | Numeric: 2 digits + zero padded | 09, 12 |
  3952. * | | LLL | Abbreviated | Sep |
  3953. * | | LLLL | Wide | September |
  3954. * | | LLLLL | Narrow | S |
  3955. * | Week of year | w | Numeric: minimum digits | 1... 53 |
  3956. * | | ww | Numeric: 2 digits + zero padded | 01... 53 |
  3957. * | Week of month | W | Numeric: 1 digit | 1... 5 |
  3958. * | Day of month | d | Numeric: minimum digits | 1 |
  3959. * | | dd | Numeric: 2 digits + zero padded | 01 |
  3960. * | Week day | E, EE & EEE | Abbreviated | Tue |
  3961. * | | EEEE | Wide | Tuesday |
  3962. * | | EEEEE | Narrow | T |
  3963. * | | EEEEEE | Short | Tu |
  3964. * | Period | a, aa & aaa | Abbreviated | am/pm or AM/PM |
  3965. * | | aaaa | Wide (fallback to `a` when missing) | ante meridiem/post meridiem |
  3966. * | | aaaaa | Narrow | a/p |
  3967. * | Period* | B, BB & BBB | Abbreviated | mid. |
  3968. * | | BBBB | Wide | am, pm, midnight, noon, morning, afternoon, evening, night |
  3969. * | | BBBBB | Narrow | md |
  3970. * | Period standalone* | b, bb & bbb | Abbreviated | mid. |
  3971. * | | bbbb | Wide | am, pm, midnight, noon, morning, afternoon, evening, night |
  3972. * | | bbbbb | Narrow | md |
  3973. * | Hour 1-12 | h | Numeric: minimum digits | 1, 12 |
  3974. * | | hh | Numeric: 2 digits + zero padded | 01, 12 |
  3975. * | Hour 0-23 | H | Numeric: minimum digits | 0, 23 |
  3976. * | | HH | Numeric: 2 digits + zero padded | 00, 23 |
  3977. * | Minute | m | Numeric: minimum digits | 8, 59 |
  3978. * | | mm | Numeric: 2 digits + zero padded | 08, 59 |
  3979. * | Second | s | Numeric: minimum digits | 0... 59 |
  3980. * | | ss | Numeric: 2 digits + zero padded | 00... 59 |
  3981. * | Fractional seconds | S | Numeric: 1 digit | 0... 9 |
  3982. * | | SS | Numeric: 2 digits + zero padded | 00... 99 |
  3983. * | | SSS | Numeric: 3 digits + zero padded (= milliseconds) | 000... 999 |
  3984. * | Zone | z, zz & zzz | Short specific non location format (fallback to O) | GMT-8 |
  3985. * | | zzzz | Long specific non location format (fallback to OOOO) | GMT-08:00 |
  3986. * | | Z, ZZ & ZZZ | ISO8601 basic format | -0800 |
  3987. * | | ZZZZ | Long localized GMT format | GMT-8:00 |
  3988. * | | ZZZZZ | ISO8601 extended format + Z indicator for offset 0 (= XXXXX) | -08:00 |
  3989. * | | O, OO & OOO | Short localized GMT format | GMT-8 |
  3990. * | | OOOO | Long localized GMT format | GMT-08:00 |
  3991. *
  3992. *
  3993. * When the expression is a ISO string without time (e.g. 2016-09-19) the time zone offset is not
  3994. * applied and the formatted text will have the same day, month and year of the expression.
  3995. *
  3996. * WARNINGS:
  3997. * - this pipe has only access to en-US locale data by default. If you want to localize the dates
  3998. * in another language, you will have to import data for other locales.
  3999. * See the {\@linkDocs guide/i18n#i18n-pipes "I18n guide"} to know how to import additional locale
  4000. * data.
  4001. * - Fields suffixed with * are only available in the extra dataset.
  4002. * See the {\@linkDocs guide/i18n#i18n-pipes "I18n guide"} to know how to import extra locale
  4003. * data.
  4004. * - this pipe is marked as pure hence it will not be re-evaluated when the input is mutated.
  4005. * Instead users should treat the date as an immutable object and change the reference when the
  4006. * pipe needs to re-run (this is to avoid reformatting the date on every change detection run
  4007. * which would be an expensive operation).
  4008. *
  4009. * ### Examples
  4010. *
  4011. * Assuming `dateObj` is (year: 2015, month: 6, day: 15, hour: 21, minute: 43, second: 11)
  4012. * in the _local_ time and locale is 'en-US':
  4013. *
  4014. * {\@example common/pipes/ts/date_pipe.ts region='DatePipe'}
  4015. *
  4016. * \@stable
  4017. */
  4018. class DatePipe {
  4019. /**
  4020. * @param {?} locale
  4021. */
  4022. constructor(locale) {
  4023. this.locale = locale;
  4024. }
  4025. /**
  4026. * @param {?} value
  4027. * @param {?=} format
  4028. * @param {?=} timezone
  4029. * @param {?=} locale
  4030. * @return {?}
  4031. */
  4032. transform(value, format = 'mediumDate', timezone, locale) {
  4033. if (value == null || value === '' || value !== value)
  4034. return null;
  4035. if (typeof value === 'string') {
  4036. value = value.trim();
  4037. }
  4038. let /** @type {?} */ date;
  4039. let /** @type {?} */ match;
  4040. if (isDate$1(value)) {
  4041. date = value;
  4042. }
  4043. else if (!isNaN(value - parseFloat(value))) {
  4044. date = new Date(parseFloat(value));
  4045. }
  4046. else if (typeof value === 'string' && /^(\d{4}-\d{1,2}-\d{1,2})$/.test(value)) {
  4047. /**
  4048. * For ISO Strings without time the day, month and year must be extracted from the ISO String
  4049. * before Date creation to avoid time offset and errors in the new Date.
  4050. * If we only replace '-' with ',' in the ISO String ("2015,01,01"), and try to create a new
  4051. * date, some browsers (e.g. IE 9) will throw an invalid Date error
  4052. * If we leave the '-' ("2015-01-01") and try to create a new Date("2015-01-01") the timeoffset
  4053. * is applied
  4054. * Note: ISO months are 0 for January, 1 for February, ...
  4055. */
  4056. const [y, m, d] = value.split('-').map((val) => +val);
  4057. date = new Date(y, m - 1, d);
  4058. }
  4059. else if ((typeof value === 'string') && (match = value.match(ISO8601_DATE_REGEX))) {
  4060. date = isoStringToDate(match);
  4061. }
  4062. else {
  4063. date = new Date(value);
  4064. }
  4065. if (!isDate$1(date)) {
  4066. throw invalidPipeArgumentError(DatePipe, value);
  4067. }
  4068. return formatDate(date, format, locale || this.locale, timezone);
  4069. }
  4070. }
  4071. DatePipe.decorators = [
  4072. { type: Pipe, args: [{ name: 'date', pure: true },] },
  4073. ];
  4074. /** @nocollapse */
  4075. DatePipe.ctorParameters = () => [
  4076. { type: undefined, decorators: [{ type: Inject, args: [LOCALE_ID,] },] },
  4077. ];
  4078. /**
  4079. * \@internal
  4080. * @param {?} match
  4081. * @return {?}
  4082. */
  4083. function isoStringToDate(match) {
  4084. const /** @type {?} */ date = new Date(0);
  4085. let /** @type {?} */ tzHour = 0;
  4086. let /** @type {?} */ tzMin = 0;
  4087. // match[8] means that the string contains "Z" (UTC) or a timezone like "+01:00" or "+0100"
  4088. const /** @type {?} */ dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear;
  4089. const /** @type {?} */ timeSetter = match[8] ? date.setUTCHours : date.setHours;
  4090. // if there is a timezone defined like "+01:00" or "+0100"
  4091. if (match[9]) {
  4092. tzHour = +(match[9] + match[10]);
  4093. tzMin = +(match[9] + match[11]);
  4094. }
  4095. dateSetter.call(date, +(match[1]), +(match[2]) - 1, +(match[3]));
  4096. const /** @type {?} */ h = +(match[4] || '0') - tzHour;
  4097. const /** @type {?} */ m = +(match[5] || '0') - tzMin;
  4098. const /** @type {?} */ s = +(match[6] || '0');
  4099. const /** @type {?} */ ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000);
  4100. timeSetter.call(date, h, m, s, ms);
  4101. return date;
  4102. }
  4103. /**
  4104. * @param {?} value
  4105. * @return {?}
  4106. */
  4107. function isDate$1(value) {
  4108. return value instanceof Date && !isNaN(value.valueOf());
  4109. }
  4110. /**
  4111. * @fileoverview added by tsickle
  4112. * @suppress {checkTypes} checked by tsc
  4113. */
  4114. class NumberFormatter {
  4115. /**
  4116. * @param {?} num
  4117. * @param {?} locale
  4118. * @param {?} style
  4119. * @param {?=} opts
  4120. * @return {?}
  4121. */
  4122. static format(num, locale, style, opts = {}) {
  4123. const { minimumIntegerDigits, minimumFractionDigits, maximumFractionDigits, currency, currencyAsSymbol = false } = opts;
  4124. const /** @type {?} */ options = {
  4125. minimumIntegerDigits,
  4126. minimumFractionDigits,
  4127. maximumFractionDigits,
  4128. style: NumberFormatStyle[style].toLowerCase()
  4129. };
  4130. if (style == NumberFormatStyle.Currency) {
  4131. options.currency = typeof currency == 'string' ? currency : undefined;
  4132. options.currencyDisplay = currencyAsSymbol ? 'symbol' : 'code';
  4133. }
  4134. return new Intl.NumberFormat(locale, options).format(num);
  4135. }
  4136. }
  4137. const DATE_FORMATS_SPLIT$1 = /((?:[^yMLdHhmsazZEwGjJ']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|L+|d+|H+|h+|J+|j+|m+|s+|a|z|Z|G+|w+))(.*)/;
  4138. const PATTERN_ALIASES = {
  4139. // Keys are quoted so they do not get renamed during closure compilation.
  4140. 'yMMMdjms': datePartGetterFactory(combine([
  4141. digitCondition('year', 1),
  4142. nameCondition('month', 3),
  4143. digitCondition('day', 1),
  4144. digitCondition('hour', 1),
  4145. digitCondition('minute', 1),
  4146. digitCondition('second', 1),
  4147. ])),
  4148. 'yMdjm': datePartGetterFactory(combine([
  4149. digitCondition('year', 1), digitCondition('month', 1), digitCondition('day', 1),
  4150. digitCondition('hour', 1), digitCondition('minute', 1)
  4151. ])),
  4152. 'yMMMMEEEEd': datePartGetterFactory(combine([
  4153. digitCondition('year', 1), nameCondition('month', 4), nameCondition('weekday', 4),
  4154. digitCondition('day', 1)
  4155. ])),
  4156. 'yMMMMd': datePartGetterFactory(combine([digitCondition('year', 1), nameCondition('month', 4), digitCondition('day', 1)])),
  4157. 'yMMMd': datePartGetterFactory(combine([digitCondition('year', 1), nameCondition('month', 3), digitCondition('day', 1)])),
  4158. 'yMd': datePartGetterFactory(combine([digitCondition('year', 1), digitCondition('month', 1), digitCondition('day', 1)])),
  4159. 'jms': datePartGetterFactory(combine([digitCondition('hour', 1), digitCondition('second', 1), digitCondition('minute', 1)])),
  4160. 'jm': datePartGetterFactory(combine([digitCondition('hour', 1), digitCondition('minute', 1)]))
  4161. };
  4162. const DATE_FORMATS$1 = {
  4163. // Keys are quoted so they do not get renamed.
  4164. 'yyyy': datePartGetterFactory(digitCondition('year', 4)),
  4165. 'yy': datePartGetterFactory(digitCondition('year', 2)),
  4166. 'y': datePartGetterFactory(digitCondition('year', 1)),
  4167. 'MMMM': datePartGetterFactory(nameCondition('month', 4)),
  4168. 'MMM': datePartGetterFactory(nameCondition('month', 3)),
  4169. 'MM': datePartGetterFactory(digitCondition('month', 2)),
  4170. 'M': datePartGetterFactory(digitCondition('month', 1)),
  4171. 'LLLL': datePartGetterFactory(nameCondition('month', 4)),
  4172. 'L': datePartGetterFactory(nameCondition('month', 1)),
  4173. 'dd': datePartGetterFactory(digitCondition('day', 2)),
  4174. 'd': datePartGetterFactory(digitCondition('day', 1)),
  4175. 'HH': digitModifier(hourExtractor(datePartGetterFactory(hour12Modify(digitCondition('hour', 2), false)))),
  4176. 'H': hourExtractor(datePartGetterFactory(hour12Modify(digitCondition('hour', 1), false))),
  4177. 'hh': digitModifier(hourExtractor(datePartGetterFactory(hour12Modify(digitCondition('hour', 2), true)))),
  4178. 'h': hourExtractor(datePartGetterFactory(hour12Modify(digitCondition('hour', 1), true))),
  4179. 'jj': datePartGetterFactory(digitCondition('hour', 2)),
  4180. 'j': datePartGetterFactory(digitCondition('hour', 1)),
  4181. 'mm': digitModifier(datePartGetterFactory(digitCondition('minute', 2))),
  4182. 'm': datePartGetterFactory(digitCondition('minute', 1)),
  4183. 'ss': digitModifier(datePartGetterFactory(digitCondition('second', 2))),
  4184. 's': datePartGetterFactory(digitCondition('second', 1)),
  4185. // while ISO 8601 requires fractions to be prefixed with `.` or `,`
  4186. // we can be just safely rely on using `sss` since we currently don't support single or two digit
  4187. // fractions
  4188. 'sss': datePartGetterFactory(digitCondition('second', 3)),
  4189. 'EEEE': datePartGetterFactory(nameCondition('weekday', 4)),
  4190. 'EEE': datePartGetterFactory(nameCondition('weekday', 3)),
  4191. 'EE': datePartGetterFactory(nameCondition('weekday', 2)),
  4192. 'E': datePartGetterFactory(nameCondition('weekday', 1)),
  4193. 'a': hourClockExtractor(datePartGetterFactory(hour12Modify(digitCondition('hour', 1), true))),
  4194. 'Z': timeZoneGetter$1('short'),
  4195. 'z': timeZoneGetter$1('long'),
  4196. 'ww': datePartGetterFactory({}),
  4197. // Week of year, padded (00-53). Week 01 is the week with the
  4198. // first Thursday of the year. not support ?
  4199. 'w': datePartGetterFactory({}),
  4200. // Week of year (0-53). Week 1 is the week with the first Thursday
  4201. // of the year not support ?
  4202. 'G': datePartGetterFactory(nameCondition('era', 1)),
  4203. 'GG': datePartGetterFactory(nameCondition('era', 2)),
  4204. 'GGG': datePartGetterFactory(nameCondition('era', 3)),
  4205. 'GGGG': datePartGetterFactory(nameCondition('era', 4))
  4206. };
  4207. /**
  4208. * @param {?} inner
  4209. * @return {?}
  4210. */
  4211. function digitModifier(inner) {
  4212. return function (date, locale) {
  4213. const /** @type {?} */ result = inner(date, locale);
  4214. return result.length == 1 ? '0' + result : result;
  4215. };
  4216. }
  4217. /**
  4218. * @param {?} inner
  4219. * @return {?}
  4220. */
  4221. function hourClockExtractor(inner) {
  4222. return function (date, locale) { return inner(date, locale).split(' ')[1]; };
  4223. }
  4224. /**
  4225. * @param {?} inner
  4226. * @return {?}
  4227. */
  4228. function hourExtractor(inner) {
  4229. return function (date, locale) { return inner(date, locale).split(' ')[0]; };
  4230. }
  4231. /**
  4232. * @param {?} date
  4233. * @param {?} locale
  4234. * @param {?} options
  4235. * @return {?}
  4236. */
  4237. function intlDateFormat(date, locale, options) {
  4238. return new Intl.DateTimeFormat(locale, options).format(date).replace(/[\u200e\u200f]/g, '');
  4239. }
  4240. /**
  4241. * @param {?} timezone
  4242. * @return {?}
  4243. */
  4244. function timeZoneGetter$1(timezone) {
  4245. // To workaround `Intl` API restriction for single timezone let format with 24 hours
  4246. const /** @type {?} */ options = { hour: '2-digit', hour12: false, timeZoneName: timezone };
  4247. return function (date, locale) {
  4248. const /** @type {?} */ result = intlDateFormat(date, locale, options);
  4249. // Then extract first 3 letters that related to hours
  4250. return result ? result.substring(3) : '';
  4251. };
  4252. }
  4253. /**
  4254. * @param {?} options
  4255. * @param {?} value
  4256. * @return {?}
  4257. */
  4258. function hour12Modify(options, value) {
  4259. options.hour12 = value;
  4260. return options;
  4261. }
  4262. /**
  4263. * @param {?} prop
  4264. * @param {?} len
  4265. * @return {?}
  4266. */
  4267. function digitCondition(prop, len) {
  4268. const /** @type {?} */ result = {};
  4269. result[prop] = len === 2 ? '2-digit' : 'numeric';
  4270. return result;
  4271. }
  4272. /**
  4273. * @param {?} prop
  4274. * @param {?} len
  4275. * @return {?}
  4276. */
  4277. function nameCondition(prop, len) {
  4278. const /** @type {?} */ result = {};
  4279. if (len < 4) {
  4280. result[prop] = len > 1 ? 'short' : 'narrow';
  4281. }
  4282. else {
  4283. result[prop] = 'long';
  4284. }
  4285. return result;
  4286. }
  4287. /**
  4288. * @param {?} options
  4289. * @return {?}
  4290. */
  4291. function combine(options) {
  4292. return options.reduce((merged, opt) => (Object.assign({}, merged, opt)), {});
  4293. }
  4294. /**
  4295. * @param {?} ret
  4296. * @return {?}
  4297. */
  4298. function datePartGetterFactory(ret) {
  4299. return (date, locale) => intlDateFormat(date, locale, ret);
  4300. }
  4301. const DATE_FORMATTER_CACHE = new Map();
  4302. /**
  4303. * @param {?} format
  4304. * @param {?} date
  4305. * @param {?} locale
  4306. * @return {?}
  4307. */
  4308. function dateFormatter(format, date, locale) {
  4309. const /** @type {?} */ fn = PATTERN_ALIASES[format];
  4310. if (fn)
  4311. return fn(date, locale);
  4312. const /** @type {?} */ cacheKey = format;
  4313. let /** @type {?} */ parts = DATE_FORMATTER_CACHE.get(cacheKey);
  4314. if (!parts) {
  4315. parts = [];
  4316. let /** @type {?} */ match;
  4317. DATE_FORMATS_SPLIT$1.exec(format);
  4318. let /** @type {?} */ _format = format;
  4319. while (_format) {
  4320. match = DATE_FORMATS_SPLIT$1.exec(_format);
  4321. if (match) {
  4322. parts = parts.concat(match.slice(1));
  4323. _format = /** @type {?} */ ((parts.pop()));
  4324. }
  4325. else {
  4326. parts.push(_format);
  4327. _format = null;
  4328. }
  4329. }
  4330. DATE_FORMATTER_CACHE.set(cacheKey, parts);
  4331. }
  4332. return parts.reduce((text, part) => {
  4333. const /** @type {?} */ fn = DATE_FORMATS$1[part];
  4334. return text + (fn ? fn(date, locale) : partToTime(part));
  4335. }, '');
  4336. }
  4337. /**
  4338. * @param {?} part
  4339. * @return {?}
  4340. */
  4341. function partToTime(part) {
  4342. return part === '\'\'' ? '\'' : part.replace(/(^'|'$)/g, '').replace(/''/g, '\'');
  4343. }
  4344. class DateFormatter {
  4345. /**
  4346. * @param {?} date
  4347. * @param {?} locale
  4348. * @param {?} pattern
  4349. * @return {?}
  4350. */
  4351. static format(date, locale, pattern) {
  4352. return dateFormatter(pattern, date, locale);
  4353. }
  4354. }
  4355. /**
  4356. * @fileoverview added by tsickle
  4357. * @suppress {checkTypes} checked by tsc
  4358. */
  4359. /**
  4360. * @license
  4361. * Copyright Google Inc. All Rights Reserved.
  4362. *
  4363. * Use of this source code is governed by an MIT-style license that can be
  4364. * found in the LICENSE file at https://angular.io/license
  4365. */
  4366. /**
  4367. * \@ngModule CommonModule
  4368. * \@whatItDoes Formats a date according to locale rules.
  4369. * \@howToUse `date_expression | date[:format]`
  4370. * \@description
  4371. *
  4372. * Where:
  4373. * - `expression` is a date object or a number (milliseconds since UTC epoch) or an ISO string
  4374. * (https://www.w3.org/TR/NOTE-datetime).
  4375. * - `format` indicates which date/time components to include. The format can be predefined as
  4376. * shown below or custom as shown in the table.
  4377. * - `'medium'`: equivalent to `'yMMMdjms'` (e.g. `Sep 3, 2010, 12:05:08 PM` for `en-US`)
  4378. * - `'short'`: equivalent to `'yMdjm'` (e.g. `9/3/2010, 12:05 PM` for `en-US`)
  4379. * - `'fullDate'`: equivalent to `'yMMMMEEEEd'` (e.g. `Friday, September 3, 2010` for `en-US`)
  4380. * - `'longDate'`: equivalent to `'yMMMMd'` (e.g. `September 3, 2010` for `en-US`)
  4381. * - `'mediumDate'`: equivalent to `'yMMMd'` (e.g. `Sep 3, 2010` for `en-US`)
  4382. * - `'shortDate'`: equivalent to `'yMd'` (e.g. `9/3/2010` for `en-US`)
  4383. * - `'mediumTime'`: equivalent to `'jms'` (e.g. `12:05:08 PM` for `en-US`)
  4384. * - `'shortTime'`: equivalent to `'jm'` (e.g. `12:05 PM` for `en-US`)
  4385. *
  4386. *
  4387. * | Component | Symbol | Narrow | Short Form | Long Form | Numeric | 2-digit |
  4388. * |-----------|:------:|--------|--------------|-------------------|-----------|-----------|
  4389. * | era | G | G (A) | GGG (AD) | GGGG (Anno Domini)| - | - |
  4390. * | year | y | - | - | - | y (2015) | yy (15) |
  4391. * | month | M | L (S) | MMM (Sep) | MMMM (September) | M (9) | MM (09) |
  4392. * | day | d | - | - | - | d (3) | dd (03) |
  4393. * | weekday | E | E (S) | EEE (Sun) | EEEE (Sunday) | - | - |
  4394. * | hour | j | - | - | - | j (13) | jj (13) |
  4395. * | hour12 | h | - | - | - | h (1 PM) | hh (01 PM)|
  4396. * | hour24 | H | - | - | - | H (13) | HH (13) |
  4397. * | minute | m | - | - | - | m (5) | mm (05) |
  4398. * | second | s | - | - | - | s (9) | ss (09) |
  4399. * | timezone | z | - | - | z (Pacific Standard Time)| - | - |
  4400. * | timezone | Z | - | Z (GMT-8:00) | - | - | - |
  4401. * | timezone | a | - | a (PM) | - | - | - |
  4402. *
  4403. * In javascript, only the components specified will be respected (not the ordering,
  4404. * punctuations, ...) and details of the formatting will be dependent on the locale.
  4405. *
  4406. * Timezone of the formatted text will be the local system timezone of the end-user's machine.
  4407. *
  4408. * When the expression is a ISO string without time (e.g. 2016-09-19) the time zone offset is not
  4409. * applied and the formatted text will have the same day, month and year of the expression.
  4410. *
  4411. * WARNINGS:
  4412. * - this pipe is marked as pure hence it will not be re-evaluated when the input is mutated.
  4413. * Instead users should treat the date as an immutable object and change the reference when the
  4414. * pipe needs to re-run (this is to avoid reformatting the date on every change detection run
  4415. * which would be an expensive operation).
  4416. * - this pipe uses the Internationalization API. Therefore it is only reliable in Chrome and Opera
  4417. * browsers.
  4418. *
  4419. * ### Examples
  4420. *
  4421. * Assuming `dateObj` is (year: 2010, month: 9, day: 3, hour: 12 PM, minute: 05, second: 08)
  4422. * in the _local_ time and locale is 'en-US':
  4423. *
  4424. * {\@example common/pipes/ts/date_pipe.ts region='DeprecatedDatePipe'}
  4425. *
  4426. * \@stable
  4427. */
  4428. class DeprecatedDatePipe {
  4429. /**
  4430. * @param {?} _locale
  4431. */
  4432. constructor(_locale) {
  4433. this._locale = _locale;
  4434. }
  4435. /**
  4436. * @param {?} value
  4437. * @param {?=} pattern
  4438. * @return {?}
  4439. */
  4440. transform(value, pattern = 'mediumDate') {
  4441. if (value == null || value === '' || value !== value)
  4442. return null;
  4443. let /** @type {?} */ date;
  4444. if (typeof value === 'string') {
  4445. value = value.trim();
  4446. }
  4447. if (isDate(value)) {
  4448. date = value;
  4449. }
  4450. else if (!isNaN(value - parseFloat(value))) {
  4451. date = new Date(parseFloat(value));
  4452. }
  4453. else if (typeof value === 'string' && /^(\d{4}-\d{1,2}-\d{1,2})$/.test(value)) {
  4454. /**
  4455. * For ISO Strings without time the day, month and year must be extracted from the ISO String
  4456. * before Date creation to avoid time offset and errors in the new Date.
  4457. * If we only replace '-' with ',' in the ISO String ("2015,01,01"), and try to create a new
  4458. * date, some browsers (e.g. IE 9) will throw an invalid Date error
  4459. * If we leave the '-' ("2015-01-01") and try to create a new Date("2015-01-01") the
  4460. * timeoffset
  4461. * is applied
  4462. * Note: ISO months are 0 for January, 1 for February, ...
  4463. */
  4464. const [y, m, d] = value.split('-').map((val) => parseInt(val, 10));
  4465. date = new Date(y, m - 1, d);
  4466. }
  4467. else {
  4468. date = new Date(value);
  4469. }
  4470. if (!isDate(date)) {
  4471. let /** @type {?} */ match;
  4472. if ((typeof value === 'string') && (match = value.match(ISO8601_DATE_REGEX))) {
  4473. date = isoStringToDate(match);
  4474. }
  4475. else {
  4476. throw invalidPipeArgumentError(DeprecatedDatePipe, value);
  4477. }
  4478. }
  4479. return DateFormatter.format(date, this._locale, DeprecatedDatePipe._ALIASES[pattern] || pattern);
  4480. }
  4481. }
  4482. /**
  4483. * \@internal
  4484. */
  4485. DeprecatedDatePipe._ALIASES = {
  4486. 'medium': 'yMMMdjms',
  4487. 'short': 'yMdjm',
  4488. 'fullDate': 'yMMMMEEEEd',
  4489. 'longDate': 'yMMMMd',
  4490. 'mediumDate': 'yMMMd',
  4491. 'shortDate': 'yMd',
  4492. 'mediumTime': 'jms',
  4493. 'shortTime': 'jm'
  4494. };
  4495. DeprecatedDatePipe.decorators = [
  4496. { type: Pipe, args: [{ name: 'date', pure: true },] },
  4497. ];
  4498. /** @nocollapse */
  4499. DeprecatedDatePipe.ctorParameters = () => [
  4500. { type: undefined, decorators: [{ type: Inject, args: [LOCALE_ID,] },] },
  4501. ];
  4502. /**
  4503. * @param {?} value
  4504. * @return {?}
  4505. */
  4506. function isDate(value) {
  4507. return value instanceof Date && !isNaN(value.valueOf());
  4508. }
  4509. /**
  4510. * @fileoverview added by tsickle
  4511. * @suppress {checkTypes} checked by tsc
  4512. */
  4513. /**
  4514. * @license
  4515. * Copyright Google Inc. All Rights Reserved.
  4516. *
  4517. * Use of this source code is governed by an MIT-style license that can be
  4518. * found in the LICENSE file at https://angular.io/license
  4519. */
  4520. const NUMBER_FORMAT_REGEXP = /^(\d+)?\.((\d+)(-(\d+))?)?$/;
  4521. const MAX_DIGITS = 22;
  4522. const DECIMAL_SEP = '.';
  4523. const ZERO_CHAR = '0';
  4524. const PATTERN_SEP = ';';
  4525. const GROUP_SEP = ',';
  4526. const DIGIT_CHAR = '#';
  4527. const CURRENCY_CHAR = '¤';
  4528. const PERCENT_CHAR = '%';
  4529. /**
  4530. * Transform a number to a locale string based on a style and a format
  4531. *
  4532. * \@internal
  4533. * @param {?} value
  4534. * @param {?} locale
  4535. * @param {?} style
  4536. * @param {?=} digitsInfo
  4537. * @param {?=} currency
  4538. * @return {?}
  4539. */
  4540. function formatNumber$1(value, locale, style, digitsInfo, currency = null) {
  4541. const /** @type {?} */ res = { str: null };
  4542. const /** @type {?} */ format = getLocaleNumberFormat(locale, style);
  4543. let /** @type {?} */ num;
  4544. // Convert strings to numbers
  4545. if (typeof value === 'string' && !isNaN(+value - parseFloat(value))) {
  4546. num = +value;
  4547. }
  4548. else if (typeof value !== 'number') {
  4549. res.error = `${value} is not a number`;
  4550. return res;
  4551. }
  4552. else {
  4553. num = value;
  4554. }
  4555. const /** @type {?} */ pattern = parseNumberFormat(format, getLocaleNumberSymbol(locale, NumberSymbol.MinusSign));
  4556. let /** @type {?} */ formattedText = '';
  4557. let /** @type {?} */ isZero = false;
  4558. if (!isFinite(num)) {
  4559. formattedText = getLocaleNumberSymbol(locale, NumberSymbol.Infinity);
  4560. }
  4561. else {
  4562. let /** @type {?} */ parsedNumber = parseNumber(num);
  4563. if (style === NumberFormatStyle.Percent) {
  4564. parsedNumber = toPercent(parsedNumber);
  4565. }
  4566. let /** @type {?} */ minInt = pattern.minInt;
  4567. let /** @type {?} */ minFraction = pattern.minFrac;
  4568. let /** @type {?} */ maxFraction = pattern.maxFrac;
  4569. if (digitsInfo) {
  4570. const /** @type {?} */ parts = digitsInfo.match(NUMBER_FORMAT_REGEXP);
  4571. if (parts === null) {
  4572. res.error = `${digitsInfo} is not a valid digit info`;
  4573. return res;
  4574. }
  4575. const /** @type {?} */ minIntPart = parts[1];
  4576. const /** @type {?} */ minFractionPart = parts[3];
  4577. const /** @type {?} */ maxFractionPart = parts[5];
  4578. if (minIntPart != null) {
  4579. minInt = parseIntAutoRadix(minIntPart);
  4580. }
  4581. if (minFractionPart != null) {
  4582. minFraction = parseIntAutoRadix(minFractionPart);
  4583. }
  4584. if (maxFractionPart != null) {
  4585. maxFraction = parseIntAutoRadix(maxFractionPart);
  4586. }
  4587. else if (minFractionPart != null && minFraction > maxFraction) {
  4588. maxFraction = minFraction;
  4589. }
  4590. }
  4591. roundNumber(parsedNumber, minFraction, maxFraction);
  4592. let /** @type {?} */ digits = parsedNumber.digits;
  4593. let /** @type {?} */ integerLen = parsedNumber.integerLen;
  4594. const /** @type {?} */ exponent = parsedNumber.exponent;
  4595. let /** @type {?} */ decimals = [];
  4596. isZero = digits.every(d => !d);
  4597. // pad zeros for small numbers
  4598. for (; integerLen < minInt; integerLen++) {
  4599. digits.unshift(0);
  4600. }
  4601. // pad zeros for small numbers
  4602. for (; integerLen < 0; integerLen++) {
  4603. digits.unshift(0);
  4604. }
  4605. // extract decimals digits
  4606. if (integerLen > 0) {
  4607. decimals = digits.splice(integerLen, digits.length);
  4608. }
  4609. else {
  4610. decimals = digits;
  4611. digits = [0];
  4612. }
  4613. // format the integer digits with grouping separators
  4614. const /** @type {?} */ groups = [];
  4615. if (digits.length >= pattern.lgSize) {
  4616. groups.unshift(digits.splice(-pattern.lgSize, digits.length).join(''));
  4617. }
  4618. while (digits.length > pattern.gSize) {
  4619. groups.unshift(digits.splice(-pattern.gSize, digits.length).join(''));
  4620. }
  4621. if (digits.length) {
  4622. groups.unshift(digits.join(''));
  4623. }
  4624. const /** @type {?} */ groupSymbol = currency ? NumberSymbol.CurrencyGroup : NumberSymbol.Group;
  4625. formattedText = groups.join(getLocaleNumberSymbol(locale, groupSymbol));
  4626. // append the decimal digits
  4627. if (decimals.length) {
  4628. const /** @type {?} */ decimalSymbol = currency ? NumberSymbol.CurrencyDecimal : NumberSymbol.Decimal;
  4629. formattedText += getLocaleNumberSymbol(locale, decimalSymbol) + decimals.join('');
  4630. }
  4631. if (exponent) {
  4632. formattedText += getLocaleNumberSymbol(locale, NumberSymbol.Exponential) + '+' + exponent;
  4633. }
  4634. }
  4635. if (num < 0 && !isZero) {
  4636. formattedText = pattern.negPre + formattedText + pattern.negSuf;
  4637. }
  4638. else {
  4639. formattedText = pattern.posPre + formattedText + pattern.posSuf;
  4640. }
  4641. if (style === NumberFormatStyle.Currency && currency !== null) {
  4642. res.str = formattedText
  4643. .replace(CURRENCY_CHAR, currency)
  4644. .replace(CURRENCY_CHAR, '');
  4645. return res;
  4646. }
  4647. if (style === NumberFormatStyle.Percent) {
  4648. res.str = formattedText.replace(new RegExp(PERCENT_CHAR, 'g'), getLocaleNumberSymbol(locale, NumberSymbol.PercentSign));
  4649. return res;
  4650. }
  4651. res.str = formattedText;
  4652. return res;
  4653. }
  4654. /**
  4655. * @param {?} format
  4656. * @param {?=} minusSign
  4657. * @return {?}
  4658. */
  4659. function parseNumberFormat(format, minusSign = '-') {
  4660. const /** @type {?} */ p = {
  4661. minInt: 1,
  4662. minFrac: 0,
  4663. maxFrac: 0,
  4664. posPre: '',
  4665. posSuf: '',
  4666. negPre: '',
  4667. negSuf: '',
  4668. gSize: 0,
  4669. lgSize: 0
  4670. };
  4671. const /** @type {?} */ patternParts = format.split(PATTERN_SEP);
  4672. const /** @type {?} */ positive = patternParts[0];
  4673. const /** @type {?} */ negative = patternParts[1];
  4674. const /** @type {?} */ positiveParts = positive.indexOf(DECIMAL_SEP) !== -1 ?
  4675. positive.split(DECIMAL_SEP) :
  4676. [
  4677. positive.substring(0, positive.lastIndexOf(ZERO_CHAR) + 1),
  4678. positive.substring(positive.lastIndexOf(ZERO_CHAR) + 1)
  4679. ], /** @type {?} */
  4680. integer = positiveParts[0], /** @type {?} */ fraction = positiveParts[1] || '';
  4681. p.posPre = integer.substr(0, integer.indexOf(DIGIT_CHAR));
  4682. for (let /** @type {?} */ i = 0; i < fraction.length; i++) {
  4683. const /** @type {?} */ ch = fraction.charAt(i);
  4684. if (ch === ZERO_CHAR) {
  4685. p.minFrac = p.maxFrac = i + 1;
  4686. }
  4687. else if (ch === DIGIT_CHAR) {
  4688. p.maxFrac = i + 1;
  4689. }
  4690. else {
  4691. p.posSuf += ch;
  4692. }
  4693. }
  4694. const /** @type {?} */ groups = integer.split(GROUP_SEP);
  4695. p.gSize = groups[1] ? groups[1].length : 0;
  4696. p.lgSize = (groups[2] || groups[1]) ? (groups[2] || groups[1]).length : 0;
  4697. if (negative) {
  4698. const /** @type {?} */ trunkLen = positive.length - p.posPre.length - p.posSuf.length, /** @type {?} */
  4699. pos = negative.indexOf(DIGIT_CHAR);
  4700. p.negPre = negative.substr(0, pos).replace(/'/g, '');
  4701. p.negSuf = negative.substr(pos + trunkLen).replace(/'/g, '');
  4702. }
  4703. else {
  4704. p.negPre = minusSign + p.posPre;
  4705. p.negSuf = p.posSuf;
  4706. }
  4707. return p;
  4708. }
  4709. /**
  4710. * @param {?} parsedNumber
  4711. * @return {?}
  4712. */
  4713. function toPercent(parsedNumber) {
  4714. // if the number is 0, don't do anything
  4715. if (parsedNumber.digits[0] === 0) {
  4716. return parsedNumber;
  4717. }
  4718. // Getting the current number of decimals
  4719. const /** @type {?} */ fractionLen = parsedNumber.digits.length - parsedNumber.integerLen;
  4720. if (parsedNumber.exponent) {
  4721. parsedNumber.exponent += 2;
  4722. }
  4723. else {
  4724. if (fractionLen === 0) {
  4725. parsedNumber.digits.push(0, 0);
  4726. }
  4727. else if (fractionLen === 1) {
  4728. parsedNumber.digits.push(0);
  4729. }
  4730. parsedNumber.integerLen += 2;
  4731. }
  4732. return parsedNumber;
  4733. }
  4734. /**
  4735. * Parses a number.
  4736. * Significant bits of this parse algorithm came from https://github.com/MikeMcl/big.js/
  4737. * @param {?} num
  4738. * @return {?}
  4739. */
  4740. function parseNumber(num) {
  4741. let /** @type {?} */ numStr = Math.abs(num) + '';
  4742. let /** @type {?} */ exponent = 0, /** @type {?} */ digits, /** @type {?} */ integerLen;
  4743. let /** @type {?} */ i, /** @type {?} */ j, /** @type {?} */ zeros;
  4744. // Decimal point?
  4745. if ((integerLen = numStr.indexOf(DECIMAL_SEP)) > -1) {
  4746. numStr = numStr.replace(DECIMAL_SEP, '');
  4747. }
  4748. // Exponential form?
  4749. if ((i = numStr.search(/e/i)) > 0) {
  4750. // Work out the exponent.
  4751. if (integerLen < 0)
  4752. integerLen = i;
  4753. integerLen += +numStr.slice(i + 1);
  4754. numStr = numStr.substring(0, i);
  4755. }
  4756. else if (integerLen < 0) {
  4757. // There was no decimal point or exponent so it is an integer.
  4758. integerLen = numStr.length;
  4759. }
  4760. // Count the number of leading zeros.
  4761. for (i = 0; numStr.charAt(i) === ZERO_CHAR; i++) {
  4762. /* empty */
  4763. }
  4764. if (i === (zeros = numStr.length)) {
  4765. // The digits are all zero.
  4766. digits = [0];
  4767. integerLen = 1;
  4768. }
  4769. else {
  4770. // Count the number of trailing zeros
  4771. zeros--;
  4772. while (numStr.charAt(zeros) === ZERO_CHAR)
  4773. zeros--;
  4774. // Trailing zeros are insignificant so ignore them
  4775. integerLen -= i;
  4776. digits = [];
  4777. // Convert string to array of digits without leading/trailing zeros.
  4778. for (j = 0; i <= zeros; i++, j++) {
  4779. digits[j] = +numStr.charAt(i);
  4780. }
  4781. }
  4782. // If the number overflows the maximum allowed digits then use an exponent.
  4783. if (integerLen > MAX_DIGITS) {
  4784. digits = digits.splice(0, MAX_DIGITS - 1);
  4785. exponent = integerLen - 1;
  4786. integerLen = 1;
  4787. }
  4788. return { digits, exponent, integerLen };
  4789. }
  4790. /**
  4791. * Round the parsed number to the specified number of decimal places
  4792. * This function changes the parsedNumber in-place
  4793. * @param {?} parsedNumber
  4794. * @param {?} minFrac
  4795. * @param {?} maxFrac
  4796. * @return {?}
  4797. */
  4798. function roundNumber(parsedNumber, minFrac, maxFrac) {
  4799. if (minFrac > maxFrac) {
  4800. throw new Error(`The minimum number of digits after fraction (${minFrac}) is higher than the maximum (${maxFrac}).`);
  4801. }
  4802. let /** @type {?} */ digits = parsedNumber.digits;
  4803. let /** @type {?} */ fractionLen = digits.length - parsedNumber.integerLen;
  4804. const /** @type {?} */ fractionSize = Math.min(Math.max(minFrac, fractionLen), maxFrac);
  4805. // The index of the digit to where rounding is to occur
  4806. let /** @type {?} */ roundAt = fractionSize + parsedNumber.integerLen;
  4807. let /** @type {?} */ digit = digits[roundAt];
  4808. if (roundAt > 0) {
  4809. // Drop fractional digits beyond `roundAt`
  4810. digits.splice(Math.max(parsedNumber.integerLen, roundAt));
  4811. // Set non-fractional digits beyond `roundAt` to 0
  4812. for (let /** @type {?} */ j = roundAt; j < digits.length; j++) {
  4813. digits[j] = 0;
  4814. }
  4815. }
  4816. else {
  4817. // We rounded to zero so reset the parsedNumber
  4818. fractionLen = Math.max(0, fractionLen);
  4819. parsedNumber.integerLen = 1;
  4820. digits.length = Math.max(1, roundAt = fractionSize + 1);
  4821. digits[0] = 0;
  4822. for (let /** @type {?} */ i = 1; i < roundAt; i++)
  4823. digits[i] = 0;
  4824. }
  4825. if (digit >= 5) {
  4826. if (roundAt - 1 < 0) {
  4827. for (let /** @type {?} */ k = 0; k > roundAt; k--) {
  4828. digits.unshift(0);
  4829. parsedNumber.integerLen++;
  4830. }
  4831. digits.unshift(1);
  4832. parsedNumber.integerLen++;
  4833. }
  4834. else {
  4835. digits[roundAt - 1]++;
  4836. }
  4837. }
  4838. // Pad out with zeros to get the required fraction length
  4839. for (; fractionLen < Math.max(0, fractionSize); fractionLen++)
  4840. digits.push(0);
  4841. let /** @type {?} */ dropTrailingZeros = fractionSize !== 0;
  4842. // Minimal length = nb of decimals required + current nb of integers
  4843. // Any number besides that is optional and can be removed if it's a trailing 0
  4844. const /** @type {?} */ minLen = minFrac + parsedNumber.integerLen;
  4845. // Do any carrying, e.g. a digit was rounded up to 10
  4846. const /** @type {?} */ carry = digits.reduceRight(function (carry, d, i, digits) {
  4847. d = d + carry;
  4848. digits[i] = d < 10 ? d : d - 10; // d % 10
  4849. if (dropTrailingZeros) {
  4850. // Do not keep meaningless fractional trailing zeros (e.g. 15.52000 --> 15.52)
  4851. if (digits[i] === 0 && i >= minLen) {
  4852. digits.pop();
  4853. }
  4854. else {
  4855. dropTrailingZeros = false;
  4856. }
  4857. }
  4858. return d >= 10 ? 1 : 0; // Math.floor(d / 10);
  4859. }, 0);
  4860. if (carry) {
  4861. digits.unshift(carry);
  4862. parsedNumber.integerLen++;
  4863. }
  4864. }
  4865. /**
  4866. * \@internal
  4867. * @param {?} text
  4868. * @return {?}
  4869. */
  4870. function parseIntAutoRadix(text) {
  4871. const /** @type {?} */ result = parseInt(text);
  4872. if (isNaN(result)) {
  4873. throw new Error('Invalid integer literal when parsing ' + text);
  4874. }
  4875. return result;
  4876. }
  4877. /**
  4878. * @fileoverview added by tsickle
  4879. * @suppress {checkTypes} checked by tsc
  4880. */
  4881. /**
  4882. * @license
  4883. * Copyright Google Inc. All Rights Reserved.
  4884. *
  4885. * Use of this source code is governed by an MIT-style license that can be
  4886. * found in the LICENSE file at https://angular.io/license
  4887. */
  4888. /**
  4889. * @param {?} pipe
  4890. * @param {?} locale
  4891. * @param {?} value
  4892. * @param {?} style
  4893. * @param {?=} digits
  4894. * @param {?=} currency
  4895. * @param {?=} currencyAsSymbol
  4896. * @return {?}
  4897. */
  4898. function formatNumber(pipe, locale, value, style, digits, currency = null, currencyAsSymbol = false) {
  4899. if (value == null)
  4900. return null;
  4901. // Convert strings to numbers
  4902. value = typeof value === 'string' && !isNaN(+value - parseFloat(value)) ? +value : value;
  4903. if (typeof value !== 'number') {
  4904. throw invalidPipeArgumentError(pipe, value);
  4905. }
  4906. let /** @type {?} */ minInt;
  4907. let /** @type {?} */ minFraction;
  4908. let /** @type {?} */ maxFraction;
  4909. if (style !== NumberFormatStyle.Currency) {
  4910. // rely on Intl default for currency
  4911. minInt = 1;
  4912. minFraction = 0;
  4913. maxFraction = 3;
  4914. }
  4915. if (digits) {
  4916. const /** @type {?} */ parts = digits.match(NUMBER_FORMAT_REGEXP);
  4917. if (parts === null) {
  4918. throw new Error(`${digits} is not a valid digit info for number pipes`);
  4919. }
  4920. if (parts[1] != null) {
  4921. // min integer digits
  4922. minInt = parseIntAutoRadix(parts[1]);
  4923. }
  4924. if (parts[3] != null) {
  4925. // min fraction digits
  4926. minFraction = parseIntAutoRadix(parts[3]);
  4927. }
  4928. if (parts[5] != null) {
  4929. // max fraction digits
  4930. maxFraction = parseIntAutoRadix(parts[5]);
  4931. }
  4932. }
  4933. return NumberFormatter.format(/** @type {?} */ (value), locale, style, {
  4934. minimumIntegerDigits: minInt,
  4935. minimumFractionDigits: minFraction,
  4936. maximumFractionDigits: maxFraction,
  4937. currency: currency,
  4938. currencyAsSymbol: currencyAsSymbol,
  4939. });
  4940. }
  4941. /**
  4942. * \@ngModule CommonModule
  4943. * \@whatItDoes Formats a number according to locale rules.
  4944. * \@howToUse `number_expression | number[:digitInfo]`
  4945. *
  4946. * Formats a number as text. Group sizing and separator and other locale-specific
  4947. * configurations are based on the active locale.
  4948. *
  4949. * where `expression` is a number:
  4950. * - `digitInfo` is a `string` which has a following format: <br>
  4951. * <code>{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}</code>
  4952. * - `minIntegerDigits` is the minimum number of integer digits to use. Defaults to `1`.
  4953. * - `minFractionDigits` is the minimum number of digits after fraction. Defaults to `0`.
  4954. * - `maxFractionDigits` is the maximum number of digits after fraction. Defaults to `3`.
  4955. *
  4956. * For more information on the acceptable range for each of these numbers and other
  4957. * details see your native internationalization library.
  4958. *
  4959. * WARNING: this pipe uses the Internationalization API which is not yet available in all browsers
  4960. * and may require a polyfill. See [Browser Support](guide/browser-support) for details.
  4961. *
  4962. * ### Example
  4963. *
  4964. * {\@example common/pipes/ts/number_pipe.ts region='DeprecatedNumberPipe'}
  4965. *
  4966. * \@stable
  4967. */
  4968. class DeprecatedDecimalPipe {
  4969. /**
  4970. * @param {?} _locale
  4971. */
  4972. constructor(_locale) {
  4973. this._locale = _locale;
  4974. }
  4975. /**
  4976. * @param {?} value
  4977. * @param {?=} digits
  4978. * @return {?}
  4979. */
  4980. transform(value, digits) {
  4981. return formatNumber(DeprecatedDecimalPipe, this._locale, value, NumberFormatStyle.Decimal, digits);
  4982. }
  4983. }
  4984. DeprecatedDecimalPipe.decorators = [
  4985. { type: Pipe, args: [{ name: 'number' },] },
  4986. ];
  4987. /** @nocollapse */
  4988. DeprecatedDecimalPipe.ctorParameters = () => [
  4989. { type: undefined, decorators: [{ type: Inject, args: [LOCALE_ID,] },] },
  4990. ];
  4991. /**
  4992. * \@ngModule CommonModule
  4993. * \@whatItDoes Formats a number as a percentage according to locale rules.
  4994. * \@howToUse `number_expression | percent[:digitInfo]`
  4995. *
  4996. * \@description
  4997. *
  4998. * Formats a number as percentage.
  4999. *
  5000. * - `digitInfo` See {\@link DecimalPipe} for detailed description.
  5001. *
  5002. * WARNING: this pipe uses the Internationalization API which is not yet available in all browsers
  5003. * and may require a polyfill. See [Browser Support](guide/browser-support) for details.
  5004. *
  5005. * ### Example
  5006. *
  5007. * {\@example common/pipes/ts/percent_pipe.ts region='DeprecatedPercentPipe'}
  5008. *
  5009. * \@stable
  5010. */
  5011. class DeprecatedPercentPipe {
  5012. /**
  5013. * @param {?} _locale
  5014. */
  5015. constructor(_locale) {
  5016. this._locale = _locale;
  5017. }
  5018. /**
  5019. * @param {?} value
  5020. * @param {?=} digits
  5021. * @return {?}
  5022. */
  5023. transform(value, digits) {
  5024. return formatNumber(DeprecatedPercentPipe, this._locale, value, NumberFormatStyle.Percent, digits);
  5025. }
  5026. }
  5027. DeprecatedPercentPipe.decorators = [
  5028. { type: Pipe, args: [{ name: 'percent' },] },
  5029. ];
  5030. /** @nocollapse */
  5031. DeprecatedPercentPipe.ctorParameters = () => [
  5032. { type: undefined, decorators: [{ type: Inject, args: [LOCALE_ID,] },] },
  5033. ];
  5034. /**
  5035. * \@ngModule CommonModule
  5036. * \@whatItDoes Formats a number as currency using locale rules.
  5037. * \@howToUse `number_expression | currency[:currencyCode[:symbolDisplay[:digitInfo]]]`
  5038. * \@description
  5039. *
  5040. * Use `currency` to format a number as currency.
  5041. *
  5042. * - `currencyCode` is the [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code, such
  5043. * as `USD` for the US dollar and `EUR` for the euro.
  5044. * - `symbolDisplay` is a boolean indicating whether to use the currency symbol or code.
  5045. * - `true`: use symbol (e.g. `$`).
  5046. * - `false`(default): use code (e.g. `USD`).
  5047. * - `digitInfo` See {\@link DecimalPipe} for detailed description.
  5048. *
  5049. * WARNING: this pipe uses the Internationalization API which is not yet available in all browsers
  5050. * and may require a polyfill. See [Browser Support](guide/browser-support) for details.
  5051. *
  5052. * ### Example
  5053. *
  5054. * {\@example common/pipes/ts/currency_pipe.ts region='DeprecatedCurrencyPipe'}
  5055. *
  5056. * \@stable
  5057. */
  5058. class DeprecatedCurrencyPipe {
  5059. /**
  5060. * @param {?} _locale
  5061. */
  5062. constructor(_locale) {
  5063. this._locale = _locale;
  5064. }
  5065. /**
  5066. * @param {?} value
  5067. * @param {?=} currencyCode
  5068. * @param {?=} symbolDisplay
  5069. * @param {?=} digits
  5070. * @return {?}
  5071. */
  5072. transform(value, currencyCode = 'USD', symbolDisplay = false, digits) {
  5073. return formatNumber(DeprecatedCurrencyPipe, this._locale, value, NumberFormatStyle.Currency, digits, currencyCode, symbolDisplay);
  5074. }
  5075. }
  5076. DeprecatedCurrencyPipe.decorators = [
  5077. { type: Pipe, args: [{ name: 'currency' },] },
  5078. ];
  5079. /** @nocollapse */
  5080. DeprecatedCurrencyPipe.ctorParameters = () => [
  5081. { type: undefined, decorators: [{ type: Inject, args: [LOCALE_ID,] },] },
  5082. ];
  5083. /**
  5084. * @fileoverview added by tsickle
  5085. * @suppress {checkTypes} checked by tsc
  5086. */
  5087. /**
  5088. * @license
  5089. * Copyright Google Inc. All Rights Reserved.
  5090. *
  5091. * Use of this source code is governed by an MIT-style license that can be
  5092. * found in the LICENSE file at https://angular.io/license
  5093. */
  5094. /**
  5095. * A collection of deprecated i18n pipes that require intl api
  5096. *
  5097. * @deprecated from v5
  5098. */
  5099. const COMMON_DEPRECATED_I18N_PIPES = [DeprecatedDecimalPipe, DeprecatedPercentPipe, DeprecatedCurrencyPipe, DeprecatedDatePipe];
  5100. /**
  5101. * @fileoverview added by tsickle
  5102. * @suppress {checkTypes} checked by tsc
  5103. */
  5104. /**
  5105. * @license
  5106. * Copyright Google Inc. All Rights Reserved.
  5107. *
  5108. * Use of this source code is governed by an MIT-style license that can be
  5109. * found in the LICENSE file at https://angular.io/license
  5110. */
  5111. class ObservableStrategy {
  5112. /**
  5113. * @param {?} async
  5114. * @param {?} updateLatestValue
  5115. * @return {?}
  5116. */
  5117. createSubscription(async, updateLatestValue) {
  5118. return async.subscribe({ next: updateLatestValue, error: (e) => { throw e; } });
  5119. }
  5120. /**
  5121. * @param {?} subscription
  5122. * @return {?}
  5123. */
  5124. dispose(subscription) { subscription.unsubscribe(); }
  5125. /**
  5126. * @param {?} subscription
  5127. * @return {?}
  5128. */
  5129. onDestroy(subscription) { subscription.unsubscribe(); }
  5130. }
  5131. class PromiseStrategy {
  5132. /**
  5133. * @param {?} async
  5134. * @param {?} updateLatestValue
  5135. * @return {?}
  5136. */
  5137. createSubscription(async, updateLatestValue) {
  5138. return async.then(updateLatestValue, e => { throw e; });
  5139. }
  5140. /**
  5141. * @param {?} subscription
  5142. * @return {?}
  5143. */
  5144. dispose(subscription) { }
  5145. /**
  5146. * @param {?} subscription
  5147. * @return {?}
  5148. */
  5149. onDestroy(subscription) { }
  5150. }
  5151. const _promiseStrategy = new PromiseStrategy();
  5152. const _observableStrategy = new ObservableStrategy();
  5153. /**
  5154. * \@ngModule CommonModule
  5155. * \@whatItDoes Unwraps a value from an asynchronous primitive.
  5156. * \@howToUse `observable_or_promise_expression | async`
  5157. * \@description
  5158. * The `async` pipe subscribes to an `Observable` or `Promise` and returns the latest value it has
  5159. * emitted. When a new value is emitted, the `async` pipe marks the component to be checked for
  5160. * changes. When the component gets destroyed, the `async` pipe unsubscribes automatically to avoid
  5161. * potential memory leaks.
  5162. *
  5163. *
  5164. * ## Examples
  5165. *
  5166. * This example binds a `Promise` to the view. Clicking the `Resolve` button resolves the
  5167. * promise.
  5168. *
  5169. * {\@example common/pipes/ts/async_pipe.ts region='AsyncPipePromise'}
  5170. *
  5171. * It's also possible to use `async` with Observables. The example below binds the `time` Observable
  5172. * to the view. The Observable continuously updates the view with the current time.
  5173. *
  5174. * {\@example common/pipes/ts/async_pipe.ts region='AsyncPipeObservable'}
  5175. *
  5176. * \@stable
  5177. */
  5178. class AsyncPipe {
  5179. /**
  5180. * @param {?} _ref
  5181. */
  5182. constructor(_ref) {
  5183. this._ref = _ref;
  5184. this._latestValue = null;
  5185. this._latestReturnedValue = null;
  5186. this._subscription = null;
  5187. this._obj = null;
  5188. this._strategy = /** @type {?} */ ((null));
  5189. }
  5190. /**
  5191. * @return {?}
  5192. */
  5193. ngOnDestroy() {
  5194. if (this._subscription) {
  5195. this._dispose();
  5196. }
  5197. }
  5198. /**
  5199. * @param {?} obj
  5200. * @return {?}
  5201. */
  5202. transform(obj) {
  5203. if (!this._obj) {
  5204. if (obj) {
  5205. this._subscribe(obj);
  5206. }
  5207. this._latestReturnedValue = this._latestValue;
  5208. return this._latestValue;
  5209. }
  5210. if (obj !== this._obj) {
  5211. this._dispose();
  5212. return this.transform(/** @type {?} */ (obj));
  5213. }
  5214. if (this._latestValue === this._latestReturnedValue) {
  5215. return this._latestReturnedValue;
  5216. }
  5217. this._latestReturnedValue = this._latestValue;
  5218. return WrappedValue.wrap(this._latestValue);
  5219. }
  5220. /**
  5221. * @param {?} obj
  5222. * @return {?}
  5223. */
  5224. _subscribe(obj) {
  5225. this._obj = obj;
  5226. this._strategy = this._selectStrategy(obj);
  5227. this._subscription = this._strategy.createSubscription(obj, (value) => this._updateLatestValue(obj, value));
  5228. }
  5229. /**
  5230. * @param {?} obj
  5231. * @return {?}
  5232. */
  5233. _selectStrategy(obj) {
  5234. if (ɵisPromise(obj)) {
  5235. return _promiseStrategy;
  5236. }
  5237. if (ɵisObservable(obj)) {
  5238. return _observableStrategy;
  5239. }
  5240. throw invalidPipeArgumentError(AsyncPipe, obj);
  5241. }
  5242. /**
  5243. * @return {?}
  5244. */
  5245. _dispose() {
  5246. this._strategy.dispose(/** @type {?} */ ((this._subscription)));
  5247. this._latestValue = null;
  5248. this._latestReturnedValue = null;
  5249. this._subscription = null;
  5250. this._obj = null;
  5251. }
  5252. /**
  5253. * @param {?} async
  5254. * @param {?} value
  5255. * @return {?}
  5256. */
  5257. _updateLatestValue(async, value) {
  5258. if (async === this._obj) {
  5259. this._latestValue = value;
  5260. this._ref.markForCheck();
  5261. }
  5262. }
  5263. }
  5264. AsyncPipe.decorators = [
  5265. { type: Pipe, args: [{ name: 'async', pure: false },] },
  5266. ];
  5267. /** @nocollapse */
  5268. AsyncPipe.ctorParameters = () => [
  5269. { type: ChangeDetectorRef, },
  5270. ];
  5271. /**
  5272. * @fileoverview added by tsickle
  5273. * @suppress {checkTypes} checked by tsc
  5274. */
  5275. /**
  5276. * @license
  5277. * Copyright Google Inc. All Rights Reserved.
  5278. *
  5279. * Use of this source code is governed by an MIT-style license that can be
  5280. * found in the LICENSE file at https://angular.io/license
  5281. */
  5282. /**
  5283. * Transforms text to lowercase.
  5284. *
  5285. * {\@example common/pipes/ts/lowerupper_pipe.ts region='LowerUpperPipe' }
  5286. *
  5287. * \@stable
  5288. */
  5289. class LowerCasePipe {
  5290. /**
  5291. * @param {?} value
  5292. * @return {?}
  5293. */
  5294. transform(value) {
  5295. if (!value)
  5296. return value;
  5297. if (typeof value !== 'string') {
  5298. throw invalidPipeArgumentError(LowerCasePipe, value);
  5299. }
  5300. return value.toLowerCase();
  5301. }
  5302. }
  5303. LowerCasePipe.decorators = [
  5304. { type: Pipe, args: [{ name: 'lowercase' },] },
  5305. ];
  5306. /** @nocollapse */
  5307. LowerCasePipe.ctorParameters = () => [];
  5308. /**
  5309. * Helper method to transform a single word to titlecase.
  5310. *
  5311. * \@stable
  5312. * @param {?} word
  5313. * @return {?}
  5314. */
  5315. function titleCaseWord(word) {
  5316. if (!word)
  5317. return word;
  5318. return word[0].toUpperCase() + word.substr(1).toLowerCase();
  5319. }
  5320. /**
  5321. * Transforms text to titlecase.
  5322. *
  5323. * \@stable
  5324. */
  5325. class TitleCasePipe {
  5326. /**
  5327. * @param {?} value
  5328. * @return {?}
  5329. */
  5330. transform(value) {
  5331. if (!value)
  5332. return value;
  5333. if (typeof value !== 'string') {
  5334. throw invalidPipeArgumentError(TitleCasePipe, value);
  5335. }
  5336. return value.split(/\b/g).map(word => titleCaseWord(word)).join('');
  5337. }
  5338. }
  5339. TitleCasePipe.decorators = [
  5340. { type: Pipe, args: [{ name: 'titlecase' },] },
  5341. ];
  5342. /** @nocollapse */
  5343. TitleCasePipe.ctorParameters = () => [];
  5344. /**
  5345. * Transforms text to uppercase.
  5346. *
  5347. * \@stable
  5348. */
  5349. class UpperCasePipe {
  5350. /**
  5351. * @param {?} value
  5352. * @return {?}
  5353. */
  5354. transform(value) {
  5355. if (!value)
  5356. return value;
  5357. if (typeof value !== 'string') {
  5358. throw invalidPipeArgumentError(UpperCasePipe, value);
  5359. }
  5360. return value.toUpperCase();
  5361. }
  5362. }
  5363. UpperCasePipe.decorators = [
  5364. { type: Pipe, args: [{ name: 'uppercase' },] },
  5365. ];
  5366. /** @nocollapse */
  5367. UpperCasePipe.ctorParameters = () => [];
  5368. /**
  5369. * @fileoverview added by tsickle
  5370. * @suppress {checkTypes} checked by tsc
  5371. */
  5372. /**
  5373. * @license
  5374. * Copyright Google Inc. All Rights Reserved.
  5375. *
  5376. * Use of this source code is governed by an MIT-style license that can be
  5377. * found in the LICENSE file at https://angular.io/license
  5378. */
  5379. const _INTERPOLATION_REGEXP = /#/g;
  5380. /**
  5381. * \@ngModule CommonModule
  5382. * \@whatItDoes Maps a value to a string that pluralizes the value according to locale rules.
  5383. * \@howToUse `expression | i18nPlural:mapping[:locale]`
  5384. * \@description
  5385. *
  5386. * Where:
  5387. * - `expression` is a number.
  5388. * - `mapping` is an object that mimics the ICU format, see
  5389. * http://userguide.icu-project.org/formatparse/messages
  5390. * - `locale` is a `string` defining the locale to use (uses the current {\@link LOCALE_ID} by
  5391. * default)
  5392. *
  5393. * ## Example
  5394. *
  5395. * {\@example common/pipes/ts/i18n_pipe.ts region='I18nPluralPipeComponent'}
  5396. *
  5397. * \@experimental
  5398. */
  5399. class I18nPluralPipe {
  5400. /**
  5401. * @param {?} _localization
  5402. */
  5403. constructor(_localization) {
  5404. this._localization = _localization;
  5405. }
  5406. /**
  5407. * @param {?} value
  5408. * @param {?} pluralMap
  5409. * @param {?=} locale
  5410. * @return {?}
  5411. */
  5412. transform(value, pluralMap, locale) {
  5413. if (value == null)
  5414. return '';
  5415. if (typeof pluralMap !== 'object' || pluralMap === null) {
  5416. throw invalidPipeArgumentError(I18nPluralPipe, pluralMap);
  5417. }
  5418. const /** @type {?} */ key = getPluralCategory(value, Object.keys(pluralMap), this._localization, locale);
  5419. return pluralMap[key].replace(_INTERPOLATION_REGEXP, value.toString());
  5420. }
  5421. }
  5422. I18nPluralPipe.decorators = [
  5423. { type: Pipe, args: [{ name: 'i18nPlural', pure: true },] },
  5424. ];
  5425. /** @nocollapse */
  5426. I18nPluralPipe.ctorParameters = () => [
  5427. { type: NgLocalization, },
  5428. ];
  5429. /**
  5430. * @fileoverview added by tsickle
  5431. * @suppress {checkTypes} checked by tsc
  5432. */
  5433. /**
  5434. * @license
  5435. * Copyright Google Inc. All Rights Reserved.
  5436. *
  5437. * Use of this source code is governed by an MIT-style license that can be
  5438. * found in the LICENSE file at https://angular.io/license
  5439. */
  5440. /**
  5441. * \@ngModule CommonModule
  5442. * \@whatItDoes Generic selector that displays the string that matches the current value.
  5443. * \@howToUse `expression | i18nSelect:mapping`
  5444. * \@description
  5445. *
  5446. * Where `mapping` is an object that indicates the text that should be displayed
  5447. * for different values of the provided `expression`.
  5448. * If none of the keys of the mapping match the value of the `expression`, then the content
  5449. * of the `other` key is returned when present, otherwise an empty string is returned.
  5450. *
  5451. * ## Example
  5452. *
  5453. * {\@example common/pipes/ts/i18n_pipe.ts region='I18nSelectPipeComponent'}
  5454. *
  5455. * \@experimental
  5456. */
  5457. class I18nSelectPipe {
  5458. /**
  5459. * @param {?} value
  5460. * @param {?} mapping
  5461. * @return {?}
  5462. */
  5463. transform(value, mapping) {
  5464. if (value == null)
  5465. return '';
  5466. if (typeof mapping !== 'object' || typeof value !== 'string') {
  5467. throw invalidPipeArgumentError(I18nSelectPipe, mapping);
  5468. }
  5469. if (mapping.hasOwnProperty(value)) {
  5470. return mapping[value];
  5471. }
  5472. if (mapping.hasOwnProperty('other')) {
  5473. return mapping['other'];
  5474. }
  5475. return '';
  5476. }
  5477. }
  5478. I18nSelectPipe.decorators = [
  5479. { type: Pipe, args: [{ name: 'i18nSelect', pure: true },] },
  5480. ];
  5481. /** @nocollapse */
  5482. I18nSelectPipe.ctorParameters = () => [];
  5483. /**
  5484. * @fileoverview added by tsickle
  5485. * @suppress {checkTypes} checked by tsc
  5486. */
  5487. /**
  5488. * @license
  5489. * Copyright Google Inc. All Rights Reserved.
  5490. *
  5491. * Use of this source code is governed by an MIT-style license that can be
  5492. * found in the LICENSE file at https://angular.io/license
  5493. */
  5494. /**
  5495. * \@ngModule CommonModule
  5496. * \@whatItDoes Converts value into JSON string.
  5497. * \@howToUse `expression | json`
  5498. * \@description
  5499. *
  5500. * Converts value into string using `JSON.stringify`. Useful for debugging.
  5501. *
  5502. * ### Example
  5503. * {\@example common/pipes/ts/json_pipe.ts region='JsonPipe'}
  5504. *
  5505. * \@stable
  5506. */
  5507. class JsonPipe {
  5508. /**
  5509. * @param {?} value
  5510. * @return {?}
  5511. */
  5512. transform(value) { return JSON.stringify(value, null, 2); }
  5513. }
  5514. JsonPipe.decorators = [
  5515. { type: Pipe, args: [{ name: 'json', pure: false },] },
  5516. ];
  5517. /** @nocollapse */
  5518. JsonPipe.ctorParameters = () => [];
  5519. /**
  5520. * @fileoverview added by tsickle
  5521. * @suppress {checkTypes} checked by tsc
  5522. */
  5523. /**
  5524. * @license
  5525. * Copyright Google Inc. All Rights Reserved.
  5526. *
  5527. * Use of this source code is governed by an MIT-style license that can be
  5528. * found in the LICENSE file at https://angular.io/license
  5529. */
  5530. /**
  5531. * \@ngModule CommonModule
  5532. * \@whatItDoes Formats a number according to locale rules.
  5533. * \@howToUse `number_expression | number[:digitInfo[:locale]]`
  5534. *
  5535. * Formats a number as text. Group sizing and separator and other locale-specific
  5536. * configurations are based on the active locale.
  5537. *
  5538. * where `expression` is a number:
  5539. * - `digitInfo` is a `string` which has a following format: <br>
  5540. * <code>{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}</code>
  5541. * - `minIntegerDigits` is the minimum number of integer digits to use. Defaults to `1`.
  5542. * - `minFractionDigits` is the minimum number of digits after fraction. Defaults to `0`.
  5543. * - `maxFractionDigits` is the maximum number of digits after fraction. Defaults to `3`.
  5544. * - `locale` is a `string` defining the locale to use (uses the current {\@link LOCALE_ID} by
  5545. * default)
  5546. *
  5547. * For more information on the acceptable range for each of these numbers and other
  5548. * details see your native internationalization library.
  5549. *
  5550. * ### Example
  5551. *
  5552. * {\@example common/pipes/ts/number_pipe.ts region='NumberPipe'}
  5553. *
  5554. * \@stable
  5555. */
  5556. class DecimalPipe {
  5557. /**
  5558. * @param {?} _locale
  5559. */
  5560. constructor(_locale) {
  5561. this._locale = _locale;
  5562. }
  5563. /**
  5564. * @param {?} value
  5565. * @param {?=} digits
  5566. * @param {?=} locale
  5567. * @return {?}
  5568. */
  5569. transform(value, digits, locale) {
  5570. if (isEmpty(value))
  5571. return null;
  5572. locale = locale || this._locale;
  5573. const { str, error } = formatNumber$1(value, locale, NumberFormatStyle.Decimal, digits);
  5574. if (error) {
  5575. throw invalidPipeArgumentError(DecimalPipe, error);
  5576. }
  5577. return str;
  5578. }
  5579. }
  5580. DecimalPipe.decorators = [
  5581. { type: Pipe, args: [{ name: 'number' },] },
  5582. ];
  5583. /** @nocollapse */
  5584. DecimalPipe.ctorParameters = () => [
  5585. { type: undefined, decorators: [{ type: Inject, args: [LOCALE_ID,] },] },
  5586. ];
  5587. /**
  5588. * \@ngModule CommonModule
  5589. * \@whatItDoes Formats a number as a percentage according to locale rules.
  5590. * \@howToUse `number_expression | percent[:digitInfo[:locale]]`
  5591. *
  5592. * \@description
  5593. *
  5594. * Formats a number as percentage.
  5595. *
  5596. * - `digitInfo` See {\@link DecimalPipe} for detailed description.
  5597. * - `locale` is a `string` defining the locale to use (uses the current {\@link LOCALE_ID} by
  5598. * default)
  5599. *
  5600. * ### Example
  5601. *
  5602. * {\@example common/pipes/ts/percent_pipe.ts region='PercentPipe'}
  5603. *
  5604. * \@stable
  5605. */
  5606. class PercentPipe {
  5607. /**
  5608. * @param {?} _locale
  5609. */
  5610. constructor(_locale) {
  5611. this._locale = _locale;
  5612. }
  5613. /**
  5614. * @param {?} value
  5615. * @param {?=} digits
  5616. * @param {?=} locale
  5617. * @return {?}
  5618. */
  5619. transform(value, digits, locale) {
  5620. if (isEmpty(value))
  5621. return null;
  5622. locale = locale || this._locale;
  5623. const { str, error } = formatNumber$1(value, locale, NumberFormatStyle.Percent, digits);
  5624. if (error) {
  5625. throw invalidPipeArgumentError(PercentPipe, error);
  5626. }
  5627. return str;
  5628. }
  5629. }
  5630. PercentPipe.decorators = [
  5631. { type: Pipe, args: [{ name: 'percent' },] },
  5632. ];
  5633. /** @nocollapse */
  5634. PercentPipe.ctorParameters = () => [
  5635. { type: undefined, decorators: [{ type: Inject, args: [LOCALE_ID,] },] },
  5636. ];
  5637. /**
  5638. * \@ngModule CommonModule
  5639. * \@whatItDoes Formats a number as currency using locale rules.
  5640. * \@howToUse `number_expression | currency[:currencyCode[:display[:digitInfo[:locale]]]]`
  5641. * \@description
  5642. *
  5643. * Use `currency` to format a number as currency.
  5644. *
  5645. * - `currencyCode` is the [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code, such
  5646. * as `USD` for the US dollar and `EUR` for the euro.
  5647. * - `display` indicates whether to show the currency symbol or the code.
  5648. * - `code`: use code (e.g. `USD`).
  5649. * - `symbol`(default): use symbol (e.g. `$`).
  5650. * - `symbol-narrow`: some countries have two symbols for their currency, one regular and one
  5651. * narrow (e.g. the canadian dollar CAD has the symbol `CA$` and the symbol-narrow `$`).
  5652. * - boolean (deprecated from v5): `true` for symbol and false for `code`
  5653. * If there is no narrow symbol for the chosen currency, the regular symbol will be used.
  5654. * - `digitInfo` See {\@link DecimalPipe} for detailed description.
  5655. * - `locale` is a `string` defining the locale to use (uses the current {\@link LOCALE_ID} by
  5656. * default)
  5657. *
  5658. * ### Example
  5659. *
  5660. * {\@example common/pipes/ts/currency_pipe.ts region='CurrencyPipe'}
  5661. *
  5662. * \@stable
  5663. */
  5664. class CurrencyPipe {
  5665. /**
  5666. * @param {?} _locale
  5667. */
  5668. constructor(_locale) {
  5669. this._locale = _locale;
  5670. }
  5671. /**
  5672. * @param {?} value
  5673. * @param {?=} currencyCode
  5674. * @param {?=} display
  5675. * @param {?=} digits
  5676. * @param {?=} locale
  5677. * @return {?}
  5678. */
  5679. transform(value, currencyCode, display = 'symbol', digits, locale) {
  5680. if (isEmpty(value))
  5681. return null;
  5682. locale = locale || this._locale;
  5683. if (typeof display === 'boolean') {
  5684. if (/** @type {?} */ (console) && /** @type {?} */ (console.warn)) {
  5685. console.warn(`Warning: the currency pipe has been changed in Angular v5. The symbolDisplay option (third parameter) is now a string instead of a boolean. The accepted values are "code", "symbol" or "symbol-narrow".`);
  5686. }
  5687. display = display ? 'symbol' : 'code';
  5688. }
  5689. let /** @type {?} */ currency = currencyCode || 'USD';
  5690. if (display !== 'code') {
  5691. currency = getCurrencySymbol(currency, display === 'symbol' ? 'wide' : 'narrow');
  5692. }
  5693. const { str, error } = formatNumber$1(value, locale, NumberFormatStyle.Currency, digits, currency);
  5694. if (error) {
  5695. throw invalidPipeArgumentError(CurrencyPipe, error);
  5696. }
  5697. return str;
  5698. }
  5699. }
  5700. CurrencyPipe.decorators = [
  5701. { type: Pipe, args: [{ name: 'currency' },] },
  5702. ];
  5703. /** @nocollapse */
  5704. CurrencyPipe.ctorParameters = () => [
  5705. { type: undefined, decorators: [{ type: Inject, args: [LOCALE_ID,] },] },
  5706. ];
  5707. /**
  5708. * @param {?} value
  5709. * @return {?}
  5710. */
  5711. function isEmpty(value) {
  5712. return value == null || value === '' || value !== value;
  5713. }
  5714. /**
  5715. * @fileoverview added by tsickle
  5716. * @suppress {checkTypes} checked by tsc
  5717. */
  5718. /**
  5719. * @license
  5720. * Copyright Google Inc. All Rights Reserved.
  5721. *
  5722. * Use of this source code is governed by an MIT-style license that can be
  5723. * found in the LICENSE file at https://angular.io/license
  5724. */
  5725. /**
  5726. * \@ngModule CommonModule
  5727. * \@whatItDoes Creates a new List or String containing a subset (slice) of the elements.
  5728. * \@howToUse `array_or_string_expression | slice:start[:end]`
  5729. * \@description
  5730. *
  5731. * Where the input expression is a `List` or `String`, and:
  5732. * - `start`: The starting index of the subset to return.
  5733. * - **a positive integer**: return the item at `start` index and all items after
  5734. * in the list or string expression.
  5735. * - **a negative integer**: return the item at `start` index from the end and all items after
  5736. * in the list or string expression.
  5737. * - **if positive and greater than the size of the expression**: return an empty list or string.
  5738. * - **if negative and greater than the size of the expression**: return entire list or string.
  5739. * - `end`: The ending index of the subset to return.
  5740. * - **omitted**: return all items until the end.
  5741. * - **if positive**: return all items before `end` index of the list or string.
  5742. * - **if negative**: return all items before `end` index from the end of the list or string.
  5743. *
  5744. * All behavior is based on the expected behavior of the JavaScript API `Array.prototype.slice()`
  5745. * and `String.prototype.slice()`.
  5746. *
  5747. * When operating on a [List], the returned list is always a copy even when all
  5748. * the elements are being returned.
  5749. *
  5750. * When operating on a blank value, the pipe returns the blank value.
  5751. *
  5752. * ## List Example
  5753. *
  5754. * This `ngFor` example:
  5755. *
  5756. * {\@example common/pipes/ts/slice_pipe.ts region='SlicePipe_list'}
  5757. *
  5758. * produces the following:
  5759. *
  5760. * <li>b</li>
  5761. * <li>c</li>
  5762. *
  5763. * ## String Examples
  5764. *
  5765. * {\@example common/pipes/ts/slice_pipe.ts region='SlicePipe_string'}
  5766. *
  5767. * \@stable
  5768. */
  5769. class SlicePipe {
  5770. /**
  5771. * @param {?} value
  5772. * @param {?} start
  5773. * @param {?=} end
  5774. * @return {?}
  5775. */
  5776. transform(value, start, end) {
  5777. if (value == null)
  5778. return value;
  5779. if (!this.supports(value)) {
  5780. throw invalidPipeArgumentError(SlicePipe, value);
  5781. }
  5782. return value.slice(start, end);
  5783. }
  5784. /**
  5785. * @param {?} obj
  5786. * @return {?}
  5787. */
  5788. supports(obj) { return typeof obj === 'string' || Array.isArray(obj); }
  5789. }
  5790. SlicePipe.decorators = [
  5791. { type: Pipe, args: [{ name: 'slice', pure: false },] },
  5792. ];
  5793. /** @nocollapse */
  5794. SlicePipe.ctorParameters = () => [];
  5795. /**
  5796. * @fileoverview added by tsickle
  5797. * @suppress {checkTypes} checked by tsc
  5798. */
  5799. /**
  5800. * @license
  5801. * Copyright Google Inc. All Rights Reserved.
  5802. *
  5803. * Use of this source code is governed by an MIT-style license that can be
  5804. * found in the LICENSE file at https://angular.io/license
  5805. */
  5806. /**
  5807. * A collection of Angular pipes that are likely to be used in each and every application.
  5808. */
  5809. const COMMON_PIPES = [
  5810. AsyncPipe,
  5811. UpperCasePipe,
  5812. LowerCasePipe,
  5813. JsonPipe,
  5814. SlicePipe,
  5815. DecimalPipe,
  5816. PercentPipe,
  5817. TitleCasePipe,
  5818. CurrencyPipe,
  5819. DatePipe,
  5820. I18nPluralPipe,
  5821. I18nSelectPipe,
  5822. ];
  5823. /**
  5824. * @fileoverview added by tsickle
  5825. * @suppress {checkTypes} checked by tsc
  5826. */
  5827. /**
  5828. * @license
  5829. * Copyright Google Inc. All Rights Reserved.
  5830. *
  5831. * Use of this source code is governed by an MIT-style license that can be
  5832. * found in the LICENSE file at https://angular.io/license
  5833. */
  5834. /**
  5835. * The module that includes all the basic Angular directives like {\@link NgIf}, {\@link NgForOf}, ...
  5836. *
  5837. * \@stable
  5838. */
  5839. class CommonModule {
  5840. }
  5841. CommonModule.decorators = [
  5842. { type: NgModule, args: [{
  5843. declarations: [COMMON_DIRECTIVES, COMMON_PIPES],
  5844. exports: [COMMON_DIRECTIVES, COMMON_PIPES],
  5845. providers: [
  5846. { provide: NgLocalization, useClass: NgLocaleLocalization },
  5847. ],
  5848. },] },
  5849. ];
  5850. /** @nocollapse */
  5851. CommonModule.ctorParameters = () => [];
  5852. const ɵ0 = getPluralCase;
  5853. /**
  5854. * A module that contains the deprecated i18n pipes.
  5855. *
  5856. * @deprecated from v5
  5857. */
  5858. class DeprecatedI18NPipesModule {
  5859. }
  5860. DeprecatedI18NPipesModule.decorators = [
  5861. { type: NgModule, args: [{
  5862. declarations: [COMMON_DEPRECATED_I18N_PIPES],
  5863. exports: [COMMON_DEPRECATED_I18N_PIPES],
  5864. providers: [{ provide: DEPRECATED_PLURAL_FN, useValue: ɵ0 }],
  5865. },] },
  5866. ];
  5867. /** @nocollapse */
  5868. DeprecatedI18NPipesModule.ctorParameters = () => [];
  5869. /**
  5870. * @fileoverview added by tsickle
  5871. * @suppress {checkTypes} checked by tsc
  5872. */
  5873. /**
  5874. * @license
  5875. * Copyright Google Inc. All Rights Reserved.
  5876. *
  5877. * Use of this source code is governed by an MIT-style license that can be
  5878. * found in the LICENSE file at https://angular.io/license
  5879. */
  5880. /**
  5881. * A DI Token representing the main rendering context. In a browser this is the DOM Document.
  5882. *
  5883. * Note: Document might not be available in the Application Context when Application and Rendering
  5884. * Contexts are not the same (e.g. when running the application into a Web Worker).
  5885. *
  5886. * \@stable
  5887. */
  5888. const DOCUMENT = new InjectionToken('DocumentToken');
  5889. /**
  5890. * @fileoverview added by tsickle
  5891. * @suppress {checkTypes} checked by tsc
  5892. */
  5893. /**
  5894. * @license
  5895. * Copyright Google Inc. All Rights Reserved.
  5896. *
  5897. * Use of this source code is governed by an MIT-style license that can be
  5898. * found in the LICENSE file at https://angular.io/license
  5899. */
  5900. const PLATFORM_BROWSER_ID = 'browser';
  5901. const PLATFORM_SERVER_ID = 'server';
  5902. const PLATFORM_WORKER_APP_ID = 'browserWorkerApp';
  5903. const PLATFORM_WORKER_UI_ID = 'browserWorkerUi';
  5904. /**
  5905. * Returns whether a platform id represents a browser platform.
  5906. * \@experimental
  5907. * @param {?} platformId
  5908. * @return {?}
  5909. */
  5910. function isPlatformBrowser(platformId) {
  5911. return platformId === PLATFORM_BROWSER_ID;
  5912. }
  5913. /**
  5914. * Returns whether a platform id represents a server platform.
  5915. * \@experimental
  5916. * @param {?} platformId
  5917. * @return {?}
  5918. */
  5919. function isPlatformServer(platformId) {
  5920. return platformId === PLATFORM_SERVER_ID;
  5921. }
  5922. /**
  5923. * Returns whether a platform id represents a web worker app platform.
  5924. * \@experimental
  5925. * @param {?} platformId
  5926. * @return {?}
  5927. */
  5928. function isPlatformWorkerApp(platformId) {
  5929. return platformId === PLATFORM_WORKER_APP_ID;
  5930. }
  5931. /**
  5932. * Returns whether a platform id represents a web worker UI platform.
  5933. * \@experimental
  5934. * @param {?} platformId
  5935. * @return {?}
  5936. */
  5937. function isPlatformWorkerUi(platformId) {
  5938. return platformId === PLATFORM_WORKER_UI_ID;
  5939. }
  5940. /**
  5941. * @fileoverview added by tsickle
  5942. * @suppress {checkTypes} checked by tsc
  5943. */
  5944. /**
  5945. * @license
  5946. * Copyright Google Inc. All Rights Reserved.
  5947. *
  5948. * Use of this source code is governed by an MIT-style license that can be
  5949. * found in the LICENSE file at https://angular.io/license
  5950. */
  5951. /**
  5952. * \@stable
  5953. */
  5954. const VERSION = new Version('5.2.11');
  5955. /**
  5956. * @fileoverview added by tsickle
  5957. * @suppress {checkTypes} checked by tsc
  5958. */
  5959. /**
  5960. * @license
  5961. * Copyright Google Inc. All Rights Reserved.
  5962. *
  5963. * Use of this source code is governed by an MIT-style license that can be
  5964. * found in the LICENSE file at https://angular.io/license
  5965. */
  5966. /**
  5967. * @module
  5968. * @description
  5969. * Entry point for all public APIs of the common package.
  5970. */
  5971. /**
  5972. * @fileoverview added by tsickle
  5973. * @suppress {checkTypes} checked by tsc
  5974. */
  5975. /**
  5976. * @license
  5977. * Copyright Google Inc. All Rights Reserved.
  5978. *
  5979. * Use of this source code is governed by an MIT-style license that can be
  5980. * found in the LICENSE file at https://angular.io/license
  5981. */
  5982. /**
  5983. * @module
  5984. * @description
  5985. * Entry point for all public APIs of this package.
  5986. */
  5987. // This file only reexports content of the `src` folder. Keep it that way.
  5988. /**
  5989. * @fileoverview added by tsickle
  5990. * @suppress {checkTypes} checked by tsc
  5991. */
  5992. /**
  5993. * Generated bundle index. Do not edit.
  5994. */
  5995. export { registerLocaleData as ɵregisterLocaleData, NgLocaleLocalization, NgLocalization, registerLocaleData, Plural, NumberFormatStyle, FormStyle, TranslationWidth, FormatWidth, NumberSymbol, WeekDay, getCurrencySymbol, getLocaleDayPeriods, getLocaleDayNames, getLocaleMonthNames, getLocaleId, getLocaleEraNames, getLocaleWeekEndRange, getLocaleFirstDayOfWeek, getLocaleDateFormat, getLocaleDateTimeFormat, getLocaleExtraDayPeriodRules, getLocaleExtraDayPeriods, getLocalePluralCase, getLocaleTimeFormat, getLocaleNumberSymbol, getLocaleNumberFormat, getLocaleCurrencyName, getLocaleCurrencySymbol, parseCookieValue as ɵparseCookieValue, CommonModule, DeprecatedI18NPipesModule, NgClass, NgForOf, NgForOfContext, NgIf, NgIfContext, NgPlural, NgPluralCase, NgStyle, NgSwitch, NgSwitchCase, NgSwitchDefault, NgTemplateOutlet, NgComponentOutlet, DOCUMENT, AsyncPipe, DatePipe, I18nPluralPipe, I18nSelectPipe, JsonPipe, LowerCasePipe, CurrencyPipe, DecimalPipe, PercentPipe, SlicePipe, UpperCasePipe, TitleCasePipe, DeprecatedDatePipe, DeprecatedCurrencyPipe, DeprecatedDecimalPipe, DeprecatedPercentPipe, PLATFORM_BROWSER_ID as ɵPLATFORM_BROWSER_ID, PLATFORM_SERVER_ID as ɵPLATFORM_SERVER_ID, PLATFORM_WORKER_APP_ID as ɵPLATFORM_WORKER_APP_ID, PLATFORM_WORKER_UI_ID as ɵPLATFORM_WORKER_UI_ID, isPlatformBrowser, isPlatformServer, isPlatformWorkerApp, isPlatformWorkerUi, VERSION, PlatformLocation, LOCATION_INITIALIZED, LocationStrategy, APP_BASE_HREF, HashLocationStrategy, PathLocationStrategy, Location, COMMON_DIRECTIVES as ɵe, findLocaleData as ɵd, DEPRECATED_PLURAL_FN as ɵa, getPluralCase as ɵb, COMMON_DEPRECATED_I18N_PIPES as ɵg, COMMON_PIPES as ɵf };
  5996. //# sourceMappingURL=common.js.map