Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

lesspass.js 406 KiB

há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
há 8 anos
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.LessPass = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. var v1 = require('./src/v1');
  3. var v2 = require('./src/v2');
  4. module.exports = {
  5. encryptLogin: v1.encryptLogin,
  6. renderPassword: v1.renderPassword,
  7. createFingerprint: v1.createFingerprint,
  8. _deriveEncryptedLogin: v1._deriveEncryptedLogin,
  9. _getPasswordTemplate: v1._getPasswordTemplate,
  10. _prettyPrint: v1._prettyPrint,
  11. _string2charCodes: v1._string2charCodes,
  12. _getCharType: v1._getCharType,
  13. _getPasswordChar: v1._getPasswordChar,
  14. _createHmac: v1._createHmac,
  15. generatePassword: v2.generatePassword,
  16. _calcEntropy: v2._calcEntropy,
  17. _getSetOfCharacters: v2._getSetOfCharacters,
  18. _renderPassword: v2._renderPassword,
  19. };
  20. },{"./src/v1":46,"./src/v2":47}],2:[function(require,module,exports){
  21. 'use strict'
  22. exports.byteLength = byteLength
  23. exports.toByteArray = toByteArray
  24. exports.fromByteArray = fromByteArray
  25. var lookup = []
  26. var revLookup = []
  27. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  28. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  29. for (var i = 0, len = code.length; i < len; ++i) {
  30. lookup[i] = code[i]
  31. revLookup[code.charCodeAt(i)] = i
  32. }
  33. revLookup['-'.charCodeAt(0)] = 62
  34. revLookup['_'.charCodeAt(0)] = 63
  35. function placeHoldersCount (b64) {
  36. var len = b64.length
  37. if (len % 4 > 0) {
  38. throw new Error('Invalid string. Length must be a multiple of 4')
  39. }
  40. // the number of equal signs (place holders)
  41. // if there are two placeholders, than the two characters before it
  42. // represent one byte
  43. // if there is only one, then the three characters before it represent 2 bytes
  44. // this is just a cheap hack to not do indexOf twice
  45. return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
  46. }
  47. function byteLength (b64) {
  48. // base64 is 4/3 + up to two characters of the original data
  49. return b64.length * 3 / 4 - placeHoldersCount(b64)
  50. }
  51. function toByteArray (b64) {
  52. var i, j, l, tmp, placeHolders, arr
  53. var len = b64.length
  54. placeHolders = placeHoldersCount(b64)
  55. arr = new Arr(len * 3 / 4 - placeHolders)
  56. // if there are placeholders, only get up to the last complete 4 chars
  57. l = placeHolders > 0 ? len - 4 : len
  58. var L = 0
  59. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  60. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
  61. arr[L++] = (tmp >> 16) & 0xFF
  62. arr[L++] = (tmp >> 8) & 0xFF
  63. arr[L++] = tmp & 0xFF
  64. }
  65. if (placeHolders === 2) {
  66. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
  67. arr[L++] = tmp & 0xFF
  68. } else if (placeHolders === 1) {
  69. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
  70. arr[L++] = (tmp >> 8) & 0xFF
  71. arr[L++] = tmp & 0xFF
  72. }
  73. return arr
  74. }
  75. function tripletToBase64 (num) {
  76. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  77. }
  78. function encodeChunk (uint8, start, end) {
  79. var tmp
  80. var output = []
  81. for (var i = start; i < end; i += 3) {
  82. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  83. output.push(tripletToBase64(tmp))
  84. }
  85. return output.join('')
  86. }
  87. function fromByteArray (uint8) {
  88. var tmp
  89. var len = uint8.length
  90. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  91. var output = ''
  92. var parts = []
  93. var maxChunkLength = 16383 // must be multiple of 3
  94. // go through the array every three bytes, we'll deal with trailing stuff later
  95. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  96. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  97. }
  98. // pad the end with zeros, but make sure to not forget the extra bytes
  99. if (extraBytes === 1) {
  100. tmp = uint8[len - 1]
  101. output += lookup[tmp >> 2]
  102. output += lookup[(tmp << 4) & 0x3F]
  103. output += '=='
  104. } else if (extraBytes === 2) {
  105. tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
  106. output += lookup[tmp >> 10]
  107. output += lookup[(tmp >> 4) & 0x3F]
  108. output += lookup[(tmp << 2) & 0x3F]
  109. output += '='
  110. }
  111. parts.push(output)
  112. return parts.join('')
  113. }
  114. },{}],3:[function(require,module,exports){
  115. var bigInt = (function (undefined) {
  116. "use strict";
  117. var BASE = 1e7,
  118. LOG_BASE = 7,
  119. MAX_INT = 9007199254740992,
  120. MAX_INT_ARR = smallToArray(MAX_INT),
  121. LOG_MAX_INT = Math.log(MAX_INT);
  122. function Integer(v, radix) {
  123. if (typeof v === "undefined") return Integer[0];
  124. if (typeof radix !== "undefined") return +radix === 10 ? parseValue(v) : parseBase(v, radix);
  125. return parseValue(v);
  126. }
  127. function BigInteger(value, sign) {
  128. this.value = value;
  129. this.sign = sign;
  130. this.isSmall = false;
  131. }
  132. BigInteger.prototype = Object.create(Integer.prototype);
  133. function SmallInteger(value) {
  134. this.value = value;
  135. this.sign = value < 0;
  136. this.isSmall = true;
  137. }
  138. SmallInteger.prototype = Object.create(Integer.prototype);
  139. function isPrecise(n) {
  140. return -MAX_INT < n && n < MAX_INT;
  141. }
  142. function smallToArray(n) { // For performance reasons doesn't reference BASE, need to change this function if BASE changes
  143. if (n < 1e7)
  144. return [n];
  145. if (n < 1e14)
  146. return [n % 1e7, Math.floor(n / 1e7)];
  147. return [n % 1e7, Math.floor(n / 1e7) % 1e7, Math.floor(n / 1e14)];
  148. }
  149. function arrayToSmall(arr) { // If BASE changes this function may need to change
  150. trim(arr);
  151. var length = arr.length;
  152. if (length < 4 && compareAbs(arr, MAX_INT_ARR) < 0) {
  153. switch (length) {
  154. case 0: return 0;
  155. case 1: return arr[0];
  156. case 2: return arr[0] + arr[1] * BASE;
  157. default: return arr[0] + (arr[1] + arr[2] * BASE) * BASE;
  158. }
  159. }
  160. return arr;
  161. }
  162. function trim(v) {
  163. var i = v.length;
  164. while (v[--i] === 0);
  165. v.length = i + 1;
  166. }
  167. function createArray(length) { // function shamelessly stolen from Yaffle's library https://github.com/Yaffle/BigInteger
  168. var x = new Array(length);
  169. var i = -1;
  170. while (++i < length) {
  171. x[i] = 0;
  172. }
  173. return x;
  174. }
  175. function truncate(n) {
  176. if (n > 0) return Math.floor(n);
  177. return Math.ceil(n);
  178. }
  179. function add(a, b) { // assumes a and b are arrays with a.length >= b.length
  180. var l_a = a.length,
  181. l_b = b.length,
  182. r = new Array(l_a),
  183. carry = 0,
  184. base = BASE,
  185. sum, i;
  186. for (i = 0; i < l_b; i++) {
  187. sum = a[i] + b[i] + carry;
  188. carry = sum >= base ? 1 : 0;
  189. r[i] = sum - carry * base;
  190. }
  191. while (i < l_a) {
  192. sum = a[i] + carry;
  193. carry = sum === base ? 1 : 0;
  194. r[i++] = sum - carry * base;
  195. }
  196. if (carry > 0) r.push(carry);
  197. return r;
  198. }
  199. function addAny(a, b) {
  200. if (a.length >= b.length) return add(a, b);
  201. return add(b, a);
  202. }
  203. function addSmall(a, carry) { // assumes a is array, carry is number with 0 <= carry < MAX_INT
  204. var l = a.length,
  205. r = new Array(l),
  206. base = BASE,
  207. sum, i;
  208. for (i = 0; i < l; i++) {
  209. sum = a[i] - base + carry;
  210. carry = Math.floor(sum / base);
  211. r[i] = sum - carry * base;
  212. carry += 1;
  213. }
  214. while (carry > 0) {
  215. r[i++] = carry % base;
  216. carry = Math.floor(carry / base);
  217. }
  218. return r;
  219. }
  220. BigInteger.prototype.add = function (v) {
  221. var value, n = parseValue(v);
  222. if (this.sign !== n.sign) {
  223. return this.subtract(n.negate());
  224. }
  225. var a = this.value, b = n.value;
  226. if (n.isSmall) {
  227. return new BigInteger(addSmall(a, Math.abs(b)), this.sign);
  228. }
  229. return new BigInteger(addAny(a, b), this.sign);
  230. };
  231. BigInteger.prototype.plus = BigInteger.prototype.add;
  232. SmallInteger.prototype.add = function (v) {
  233. var n = parseValue(v);
  234. var a = this.value;
  235. if (a < 0 !== n.sign) {
  236. return this.subtract(n.negate());
  237. }
  238. var b = n.value;
  239. if (n.isSmall) {
  240. if (isPrecise(a + b)) return new SmallInteger(a + b);
  241. b = smallToArray(Math.abs(b));
  242. }
  243. return new BigInteger(addSmall(b, Math.abs(a)), a < 0);
  244. };
  245. SmallInteger.prototype.plus = SmallInteger.prototype.add;
  246. function subtract(a, b) { // assumes a and b are arrays with a >= b
  247. var a_l = a.length,
  248. b_l = b.length,
  249. r = new Array(a_l),
  250. borrow = 0,
  251. base = BASE,
  252. i, difference;
  253. for (i = 0; i < b_l; i++) {
  254. difference = a[i] - borrow - b[i];
  255. if (difference < 0) {
  256. difference += base;
  257. borrow = 1;
  258. } else borrow = 0;
  259. r[i] = difference;
  260. }
  261. for (i = b_l; i < a_l; i++) {
  262. difference = a[i] - borrow;
  263. if (difference < 0) difference += base;
  264. else {
  265. r[i++] = difference;
  266. break;
  267. }
  268. r[i] = difference;
  269. }
  270. for (; i < a_l; i++) {
  271. r[i] = a[i];
  272. }
  273. trim(r);
  274. return r;
  275. }
  276. function subtractAny(a, b, sign) {
  277. var value, isSmall;
  278. if (compareAbs(a, b) >= 0) {
  279. value = subtract(a,b);
  280. } else {
  281. value = subtract(b, a);
  282. sign = !sign;
  283. }
  284. value = arrayToSmall(value);
  285. if (typeof value === "number") {
  286. if (sign) value = -value;
  287. return new SmallInteger(value);
  288. }
  289. return new BigInteger(value, sign);
  290. }
  291. function subtractSmall(a, b, sign) { // assumes a is array, b is number with 0 <= b < MAX_INT
  292. var l = a.length,
  293. r = new Array(l),
  294. carry = -b,
  295. base = BASE,
  296. i, difference;
  297. for (i = 0; i < l; i++) {
  298. difference = a[i] + carry;
  299. carry = Math.floor(difference / base);
  300. difference %= base;
  301. r[i] = difference < 0 ? difference + base : difference;
  302. }
  303. r = arrayToSmall(r);
  304. if (typeof r === "number") {
  305. if (sign) r = -r;
  306. return new SmallInteger(r);
  307. } return new BigInteger(r, sign);
  308. }
  309. BigInteger.prototype.subtract = function (v) {
  310. var n = parseValue(v);
  311. if (this.sign !== n.sign) {
  312. return this.add(n.negate());
  313. }
  314. var a = this.value, b = n.value;
  315. if (n.isSmall)
  316. return subtractSmall(a, Math.abs(b), this.sign);
  317. return subtractAny(a, b, this.sign);
  318. };
  319. BigInteger.prototype.minus = BigInteger.prototype.subtract;
  320. SmallInteger.prototype.subtract = function (v) {
  321. var n = parseValue(v);
  322. var a = this.value;
  323. if (a < 0 !== n.sign) {
  324. return this.add(n.negate());
  325. }
  326. var b = n.value;
  327. if (n.isSmall) {
  328. return new SmallInteger(a - b);
  329. }
  330. return subtractSmall(b, Math.abs(a), a >= 0);
  331. };
  332. SmallInteger.prototype.minus = SmallInteger.prototype.subtract;
  333. BigInteger.prototype.negate = function () {
  334. return new BigInteger(this.value, !this.sign);
  335. };
  336. SmallInteger.prototype.negate = function () {
  337. var sign = this.sign;
  338. var small = new SmallInteger(-this.value);
  339. small.sign = !sign;
  340. return small;
  341. };
  342. BigInteger.prototype.abs = function () {
  343. return new BigInteger(this.value, false);
  344. };
  345. SmallInteger.prototype.abs = function () {
  346. return new SmallInteger(Math.abs(this.value));
  347. };
  348. function multiplyLong(a, b) {
  349. var a_l = a.length,
  350. b_l = b.length,
  351. l = a_l + b_l,
  352. r = createArray(l),
  353. base = BASE,
  354. product, carry, i, a_i, b_j;
  355. for (i = 0; i < a_l; ++i) {
  356. a_i = a[i];
  357. for (var j = 0; j < b_l; ++j) {
  358. b_j = b[j];
  359. product = a_i * b_j + r[i + j];
  360. carry = Math.floor(product / base);
  361. r[i + j] = product - carry * base;
  362. r[i + j + 1] += carry;
  363. }
  364. }
  365. trim(r);
  366. return r;
  367. }
  368. function multiplySmall(a, b) { // assumes a is array, b is number with |b| < BASE
  369. var l = a.length,
  370. r = new Array(l),
  371. base = BASE,
  372. carry = 0,
  373. product, i;
  374. for (i = 0; i < l; i++) {
  375. product = a[i] * b + carry;
  376. carry = Math.floor(product / base);
  377. r[i] = product - carry * base;
  378. }
  379. while (carry > 0) {
  380. r[i++] = carry % base;
  381. carry = Math.floor(carry / base);
  382. }
  383. return r;
  384. }
  385. function shiftLeft(x, n) {
  386. var r = [];
  387. while (n-- > 0) r.push(0);
  388. return r.concat(x);
  389. }
  390. function multiplyKaratsuba(x, y) {
  391. var n = Math.max(x.length, y.length);
  392. if (n <= 30) return multiplyLong(x, y);
  393. n = Math.ceil(n / 2);
  394. var b = x.slice(n),
  395. a = x.slice(0, n),
  396. d = y.slice(n),
  397. c = y.slice(0, n);
  398. var ac = multiplyKaratsuba(a, c),
  399. bd = multiplyKaratsuba(b, d),
  400. abcd = multiplyKaratsuba(addAny(a, b), addAny(c, d));
  401. var product = addAny(addAny(ac, shiftLeft(subtract(subtract(abcd, ac), bd), n)), shiftLeft(bd, 2 * n));
  402. trim(product);
  403. return product;
  404. }
  405. // The following function is derived from a surface fit of a graph plotting the performance difference
  406. // between long multiplication and karatsuba multiplication versus the lengths of the two arrays.
  407. function useKaratsuba(l1, l2) {
  408. return -0.012 * l1 - 0.012 * l2 + 0.000015 * l1 * l2 > 0;
  409. }
  410. BigInteger.prototype.multiply = function (v) {
  411. var value, n = parseValue(v),
  412. a = this.value, b = n.value,
  413. sign = this.sign !== n.sign,
  414. abs;
  415. if (n.isSmall) {
  416. if (b === 0) return Integer[0];
  417. if (b === 1) return this;
  418. if (b === -1) return this.negate();
  419. abs = Math.abs(b);
  420. if (abs < BASE) {
  421. return new BigInteger(multiplySmall(a, abs), sign);
  422. }
  423. b = smallToArray(abs);
  424. }
  425. if (useKaratsuba(a.length, b.length)) // Karatsuba is only faster for certain array sizes
  426. return new BigInteger(multiplyKaratsuba(a, b), sign);
  427. return new BigInteger(multiplyLong(a, b), sign);
  428. };
  429. BigInteger.prototype.times = BigInteger.prototype.multiply;
  430. function multiplySmallAndArray(a, b, sign) { // a >= 0
  431. if (a < BASE) {
  432. return new BigInteger(multiplySmall(b, a), sign);
  433. }
  434. return new BigInteger(multiplyLong(b, smallToArray(a)), sign);
  435. }
  436. SmallInteger.prototype._multiplyBySmall = function (a) {
  437. if (isPrecise(a.value * this.value)) {
  438. return new SmallInteger(a.value * this.value);
  439. }
  440. return multiplySmallAndArray(Math.abs(a.value), smallToArray(Math.abs(this.value)), this.sign !== a.sign);
  441. };
  442. BigInteger.prototype._multiplyBySmall = function (a) {
  443. if (a.value === 0) return Integer[0];
  444. if (a.value === 1) return this;
  445. if (a.value === -1) return this.negate();
  446. return multiplySmallAndArray(Math.abs(a.value), this.value, this.sign !== a.sign);
  447. };
  448. SmallInteger.prototype.multiply = function (v) {
  449. return parseValue(v)._multiplyBySmall(this);
  450. };
  451. SmallInteger.prototype.times = SmallInteger.prototype.multiply;
  452. function square(a) {
  453. var l = a.length,
  454. r = createArray(l + l),
  455. base = BASE,
  456. product, carry, i, a_i, a_j;
  457. for (i = 0; i < l; i++) {
  458. a_i = a[i];
  459. for (var j = 0; j < l; j++) {
  460. a_j = a[j];
  461. product = a_i * a_j + r[i + j];
  462. carry = Math.floor(product / base);
  463. r[i + j] = product - carry * base;
  464. r[i + j + 1] += carry;
  465. }
  466. }
  467. trim(r);
  468. return r;
  469. }
  470. BigInteger.prototype.square = function () {
  471. return new BigInteger(square(this.value), false);
  472. };
  473. SmallInteger.prototype.square = function () {
  474. var value = this.value * this.value;
  475. if (isPrecise(value)) return new SmallInteger(value);
  476. return new BigInteger(square(smallToArray(Math.abs(this.value))), false);
  477. };
  478. function divMod1(a, b) { // Left over from previous version. Performs faster than divMod2 on smaller input sizes.
  479. var a_l = a.length,
  480. b_l = b.length,
  481. base = BASE,
  482. result = createArray(b.length),
  483. divisorMostSignificantDigit = b[b_l - 1],
  484. // normalization
  485. lambda = Math.ceil(base / (2 * divisorMostSignificantDigit)),
  486. remainder = multiplySmall(a, lambda),
  487. divisor = multiplySmall(b, lambda),
  488. quotientDigit, shift, carry, borrow, i, l, q;
  489. if (remainder.length <= a_l) remainder.push(0);
  490. divisor.push(0);
  491. divisorMostSignificantDigit = divisor[b_l - 1];
  492. for (shift = a_l - b_l; shift >= 0; shift--) {
  493. quotientDigit = base - 1;
  494. if (remainder[shift + b_l] !== divisorMostSignificantDigit) {
  495. quotientDigit = Math.floor((remainder[shift + b_l] * base + remainder[shift + b_l - 1]) / divisorMostSignificantDigit);
  496. }
  497. // quotientDigit <= base - 1
  498. carry = 0;
  499. borrow = 0;
  500. l = divisor.length;
  501. for (i = 0; i < l; i++) {
  502. carry += quotientDigit * divisor[i];
  503. q = Math.floor(carry / base);
  504. borrow += remainder[shift + i] - (carry - q * base);
  505. carry = q;
  506. if (borrow < 0) {
  507. remainder[shift + i] = borrow + base;
  508. borrow = -1;
  509. } else {
  510. remainder[shift + i] = borrow;
  511. borrow = 0;
  512. }
  513. }
  514. while (borrow !== 0) {
  515. quotientDigit -= 1;
  516. carry = 0;
  517. for (i = 0; i < l; i++) {
  518. carry += remainder[shift + i] - base + divisor[i];
  519. if (carry < 0) {
  520. remainder[shift + i] = carry + base;
  521. carry = 0;
  522. } else {
  523. remainder[shift + i] = carry;
  524. carry = 1;
  525. }
  526. }
  527. borrow += carry;
  528. }
  529. result[shift] = quotientDigit;
  530. }
  531. // denormalization
  532. remainder = divModSmall(remainder, lambda)[0];
  533. return [arrayToSmall(result), arrayToSmall(remainder)];
  534. }
  535. function divMod2(a, b) { // Implementation idea shamelessly stolen from Silent Matt's library http://silentmatt.com/biginteger/
  536. // Performs faster than divMod1 on larger input sizes.
  537. var a_l = a.length,
  538. b_l = b.length,
  539. result = [],
  540. part = [],
  541. base = BASE,
  542. guess, xlen, highx, highy, check;
  543. while (a_l) {
  544. part.unshift(a[--a_l]);
  545. if (compareAbs(part, b) < 0) {
  546. result.push(0);
  547. continue;
  548. }
  549. xlen = part.length;
  550. highx = part[xlen - 1] * base + part[xlen - 2];
  551. highy = b[b_l - 1] * base + b[b_l - 2];
  552. if (xlen > b_l) {
  553. highx = (highx + 1) * base;
  554. }
  555. guess = Math.ceil(highx / highy);
  556. do {
  557. check = multiplySmall(b, guess);
  558. if (compareAbs(check, part) <= 0) break;
  559. guess--;
  560. } while (guess);
  561. result.push(guess);
  562. part = subtract(part, check);
  563. }
  564. result.reverse();
  565. return [arrayToSmall(result), arrayToSmall(part)];
  566. }
  567. function divModSmall(value, lambda) {
  568. var length = value.length,
  569. quotient = createArray(length),
  570. base = BASE,
  571. i, q, remainder, divisor;
  572. remainder = 0;
  573. for (i = length - 1; i >= 0; --i) {
  574. divisor = remainder * base + value[i];
  575. q = truncate(divisor / lambda);
  576. remainder = divisor - q * lambda;
  577. quotient[i] = q | 0;
  578. }
  579. return [quotient, remainder | 0];
  580. }
  581. function divModAny(self, v) {
  582. var value, n = parseValue(v);
  583. var a = self.value, b = n.value;
  584. var quotient;
  585. if (b === 0) throw new Error("Cannot divide by zero");
  586. if (self.isSmall) {
  587. if (n.isSmall) {
  588. return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)];
  589. }
  590. return [Integer[0], self];
  591. }
  592. if (n.isSmall) {
  593. if (b === 1) return [self, Integer[0]];
  594. if (b == -1) return [self.negate(), Integer[0]];
  595. var abs = Math.abs(b);
  596. if (abs < BASE) {
  597. value = divModSmall(a, abs);
  598. quotient = arrayToSmall(value[0]);
  599. var remainder = value[1];
  600. if (self.sign) remainder = -remainder;
  601. if (typeof quotient === "number") {
  602. if (self.sign !== n.sign) quotient = -quotient;
  603. return [new SmallInteger(quotient), new SmallInteger(remainder)];
  604. }
  605. return [new BigInteger(quotient, self.sign !== n.sign), new SmallInteger(remainder)];
  606. }
  607. b = smallToArray(abs);
  608. }
  609. var comparison = compareAbs(a, b);
  610. if (comparison === -1) return [Integer[0], self];
  611. if (comparison === 0) return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]];
  612. // divMod1 is faster on smaller input sizes
  613. if (a.length + b.length <= 200)
  614. value = divMod1(a, b);
  615. else value = divMod2(a, b);
  616. quotient = value[0];
  617. var qSign = self.sign !== n.sign,
  618. mod = value[1],
  619. mSign = self.sign;
  620. if (typeof quotient === "number") {
  621. if (qSign) quotient = -quotient;
  622. quotient = new SmallInteger(quotient);
  623. } else quotient = new BigInteger(quotient, qSign);
  624. if (typeof mod === "number") {
  625. if (mSign) mod = -mod;
  626. mod = new SmallInteger(mod);
  627. } else mod = new BigInteger(mod, mSign);
  628. return [quotient, mod];
  629. }
  630. BigInteger.prototype.divmod = function (v) {
  631. var result = divModAny(this, v);
  632. return {
  633. quotient: result[0],
  634. remainder: result[1]
  635. };
  636. };
  637. SmallInteger.prototype.divmod = BigInteger.prototype.divmod;
  638. BigInteger.prototype.divide = function (v) {
  639. return divModAny(this, v)[0];
  640. };
  641. SmallInteger.prototype.over = SmallInteger.prototype.divide = BigInteger.prototype.over = BigInteger.prototype.divide;
  642. BigInteger.prototype.mod = function (v) {
  643. return divModAny(this, v)[1];
  644. };
  645. SmallInteger.prototype.remainder = SmallInteger.prototype.mod = BigInteger.prototype.remainder = BigInteger.prototype.mod;
  646. BigInteger.prototype.pow = function (v) {
  647. var n = parseValue(v),
  648. a = this.value,
  649. b = n.value,
  650. value, x, y;
  651. if (b === 0) return Integer[1];
  652. if (a === 0) return Integer[0];
  653. if (a === 1) return Integer[1];
  654. if (a === -1) return n.isEven() ? Integer[1] : Integer[-1];
  655. if (n.sign) {
  656. return Integer[0];
  657. }
  658. if (!n.isSmall) throw new Error("The exponent " + n.toString() + " is too large.");
  659. if (this.isSmall) {
  660. if (isPrecise(value = Math.pow(a, b)))
  661. return new SmallInteger(truncate(value));
  662. }
  663. x = this;
  664. y = Integer[1];
  665. while (true) {
  666. if (b & 1 === 1) {
  667. y = y.times(x);
  668. --b;
  669. }
  670. if (b === 0) break;
  671. b /= 2;
  672. x = x.square();
  673. }
  674. return y;
  675. };
  676. SmallInteger.prototype.pow = BigInteger.prototype.pow;
  677. BigInteger.prototype.modPow = function (exp, mod) {
  678. exp = parseValue(exp);
  679. mod = parseValue(mod);
  680. if (mod.isZero()) throw new Error("Cannot take modPow with modulus 0");
  681. var r = Integer[1],
  682. base = this.mod(mod);
  683. while (exp.isPositive()) {
  684. if (base.isZero()) return Integer[0];
  685. if (exp.isOdd()) r = r.multiply(base).mod(mod);
  686. exp = exp.divide(2);
  687. base = base.square().mod(mod);
  688. }
  689. return r;
  690. };
  691. SmallInteger.prototype.modPow = BigInteger.prototype.modPow;
  692. function compareAbs(a, b) {
  693. if (a.length !== b.length) {
  694. return a.length > b.length ? 1 : -1;
  695. }
  696. for (var i = a.length - 1; i >= 0; i--) {
  697. if (a[i] !== b[i]) return a[i] > b[i] ? 1 : -1;
  698. }
  699. return 0;
  700. }
  701. BigInteger.prototype.compareAbs = function (v) {
  702. var n = parseValue(v),
  703. a = this.value,
  704. b = n.value;
  705. if (n.isSmall) return 1;
  706. return compareAbs(a, b);
  707. };
  708. SmallInteger.prototype.compareAbs = function (v) {
  709. var n = parseValue(v),
  710. a = Math.abs(this.value),
  711. b = n.value;
  712. if (n.isSmall) {
  713. b = Math.abs(b);
  714. return a === b ? 0 : a > b ? 1 : -1;
  715. }
  716. return -1;
  717. };
  718. BigInteger.prototype.compare = function (v) {
  719. // See discussion about comparison with Infinity:
  720. // https://github.com/peterolson/BigInteger.js/issues/61
  721. if (v === Infinity) {
  722. return -1;
  723. }
  724. if (v === -Infinity) {
  725. return 1;
  726. }
  727. var n = parseValue(v),
  728. a = this.value,
  729. b = n.value;
  730. if (this.sign !== n.sign) {
  731. return n.sign ? 1 : -1;
  732. }
  733. if (n.isSmall) {
  734. return this.sign ? -1 : 1;
  735. }
  736. return compareAbs(a, b) * (this.sign ? -1 : 1);
  737. };
  738. BigInteger.prototype.compareTo = BigInteger.prototype.compare;
  739. SmallInteger.prototype.compare = function (v) {
  740. if (v === Infinity) {
  741. return -1;
  742. }
  743. if (v === -Infinity) {
  744. return 1;
  745. }
  746. var n = parseValue(v),
  747. a = this.value,
  748. b = n.value;
  749. if (n.isSmall) {
  750. return a == b ? 0 : a > b ? 1 : -1;
  751. }
  752. if (a < 0 !== n.sign) {
  753. return a < 0 ? -1 : 1;
  754. }
  755. return a < 0 ? 1 : -1;
  756. };
  757. SmallInteger.prototype.compareTo = SmallInteger.prototype.compare;
  758. BigInteger.prototype.equals = function (v) {
  759. return this.compare(v) === 0;
  760. };
  761. SmallInteger.prototype.eq = SmallInteger.prototype.equals = BigInteger.prototype.eq = BigInteger.prototype.equals;
  762. BigInteger.prototype.notEquals = function (v) {
  763. return this.compare(v) !== 0;
  764. };
  765. SmallInteger.prototype.neq = SmallInteger.prototype.notEquals = BigInteger.prototype.neq = BigInteger.prototype.notEquals;
  766. BigInteger.prototype.greater = function (v) {
  767. return this.compare(v) > 0;
  768. };
  769. SmallInteger.prototype.gt = SmallInteger.prototype.greater = BigInteger.prototype.gt = BigInteger.prototype.greater;
  770. BigInteger.prototype.lesser = function (v) {
  771. return this.compare(v) < 0;
  772. };
  773. SmallInteger.prototype.lt = SmallInteger.prototype.lesser = BigInteger.prototype.lt = BigInteger.prototype.lesser;
  774. BigInteger.prototype.greaterOrEquals = function (v) {
  775. return this.compare(v) >= 0;
  776. };
  777. SmallInteger.prototype.geq = SmallInteger.prototype.greaterOrEquals = BigInteger.prototype.geq = BigInteger.prototype.greaterOrEquals;
  778. BigInteger.prototype.lesserOrEquals = function (v) {
  779. return this.compare(v) <= 0;
  780. };
  781. SmallInteger.prototype.leq = SmallInteger.prototype.lesserOrEquals = BigInteger.prototype.leq = BigInteger.prototype.lesserOrEquals;
  782. BigInteger.prototype.isEven = function () {
  783. return (this.value[0] & 1) === 0;
  784. };
  785. SmallInteger.prototype.isEven = function () {
  786. return (this.value & 1) === 0;
  787. };
  788. BigInteger.prototype.isOdd = function () {
  789. return (this.value[0] & 1) === 1;
  790. };
  791. SmallInteger.prototype.isOdd = function () {
  792. return (this.value & 1) === 1;
  793. };
  794. BigInteger.prototype.isPositive = function () {
  795. return !this.sign;
  796. };
  797. SmallInteger.prototype.isPositive = function () {
  798. return this.value > 0;
  799. };
  800. BigInteger.prototype.isNegative = function () {
  801. return this.sign;
  802. };
  803. SmallInteger.prototype.isNegative = function () {
  804. return this.value < 0;
  805. };
  806. BigInteger.prototype.isUnit = function () {
  807. return false;
  808. };
  809. SmallInteger.prototype.isUnit = function () {
  810. return Math.abs(this.value) === 1;
  811. };
  812. BigInteger.prototype.isZero = function () {
  813. return false;
  814. };
  815. SmallInteger.prototype.isZero = function () {
  816. return this.value === 0;
  817. };
  818. BigInteger.prototype.isDivisibleBy = function (v) {
  819. var n = parseValue(v);
  820. var value = n.value;
  821. if (value === 0) return false;
  822. if (value === 1) return true;
  823. if (value === 2) return this.isEven();
  824. return this.mod(n).equals(Integer[0]);
  825. };
  826. SmallInteger.prototype.isDivisibleBy = BigInteger.prototype.isDivisibleBy;
  827. function isBasicPrime(v) {
  828. var n = v.abs();
  829. if (n.isUnit()) return false;
  830. if (n.equals(2) || n.equals(3) || n.equals(5)) return true;
  831. if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false;
  832. if (n.lesser(25)) return true;
  833. // we don't know if it's prime: let the other functions figure it out
  834. }
  835. BigInteger.prototype.isPrime = function () {
  836. var isPrime = isBasicPrime(this);
  837. if (isPrime !== undefined) return isPrime;
  838. var n = this.abs(),
  839. nPrev = n.prev();
  840. var a = [2, 3, 5, 7, 11, 13, 17, 19],
  841. b = nPrev,
  842. d, t, i, x;
  843. while (b.isEven()) b = b.divide(2);
  844. for (i = 0; i < a.length; i++) {
  845. x = bigInt(a[i]).modPow(b, n);
  846. if (x.equals(Integer[1]) || x.equals(nPrev)) continue;
  847. for (t = true, d = b; t && d.lesser(nPrev) ; d = d.multiply(2)) {
  848. x = x.square().mod(n);
  849. if (x.equals(nPrev)) t = false;
  850. }
  851. if (t) return false;
  852. }
  853. return true;
  854. };
  855. SmallInteger.prototype.isPrime = BigInteger.prototype.isPrime;
  856. BigInteger.prototype.isProbablePrime = function (iterations) {
  857. var isPrime = isBasicPrime(this);
  858. if (isPrime !== undefined) return isPrime;
  859. var n = this.abs();
  860. var t = iterations === undefined ? 5 : iterations;
  861. // use the Fermat primality test
  862. for (var i = 0; i < t; i++) {
  863. var a = bigInt.randBetween(2, n.minus(2));
  864. if (!a.modPow(n.prev(), n).isUnit()) return false; // definitely composite
  865. }
  866. return true; // large chance of being prime
  867. };
  868. SmallInteger.prototype.isProbablePrime = BigInteger.prototype.isProbablePrime;
  869. BigInteger.prototype.modInv = function (n) {
  870. var t = bigInt.zero, newT = bigInt.one, r = parseValue(n), newR = this.abs(), q, lastT, lastR;
  871. while (!newR.equals(bigInt.zero)) {
  872. q = r.divide(newR);
  873. lastT = t;
  874. lastR = r;
  875. t = newT;
  876. r = newR;
  877. newT = lastT.subtract(q.multiply(newT));
  878. newR = lastR.subtract(q.multiply(newR));
  879. }
  880. if (!r.equals(1)) throw new Error(this.toString() + " and " + n.toString() + " are not co-prime");
  881. if (t.compare(0) === -1) {
  882. t = t.add(n);
  883. }
  884. return t;
  885. }
  886. SmallInteger.prototype.modInv = BigInteger.prototype.modInv;
  887. BigInteger.prototype.next = function () {
  888. var value = this.value;
  889. if (this.sign) {
  890. return subtractSmall(value, 1, this.sign);
  891. }
  892. return new BigInteger(addSmall(value, 1), this.sign);
  893. };
  894. SmallInteger.prototype.next = function () {
  895. var value = this.value;
  896. if (value + 1 < MAX_INT) return new SmallInteger(value + 1);
  897. return new BigInteger(MAX_INT_ARR, false);
  898. };
  899. BigInteger.prototype.prev = function () {
  900. var value = this.value;
  901. if (this.sign) {
  902. return new BigInteger(addSmall(value, 1), true);
  903. }
  904. return subtractSmall(value, 1, this.sign);
  905. };
  906. SmallInteger.prototype.prev = function () {
  907. var value = this.value;
  908. if (value - 1 > -MAX_INT) return new SmallInteger(value - 1);
  909. return new BigInteger(MAX_INT_ARR, true);
  910. };
  911. var powersOfTwo = [1];
  912. while (powersOfTwo[powersOfTwo.length - 1] <= BASE) powersOfTwo.push(2 * powersOfTwo[powersOfTwo.length - 1]);
  913. var powers2Length = powersOfTwo.length, highestPower2 = powersOfTwo[powers2Length - 1];
  914. function shift_isSmall(n) {
  915. return ((typeof n === "number" || typeof n === "string") && +Math.abs(n) <= BASE) ||
  916. (n instanceof BigInteger && n.value.length <= 1);
  917. }
  918. BigInteger.prototype.shiftLeft = function (n) {
  919. if (!shift_isSmall(n)) {
  920. throw new Error(String(n) + " is too large for shifting.");
  921. }
  922. n = +n;
  923. if (n < 0) return this.shiftRight(-n);
  924. var result = this;
  925. while (n >= powers2Length) {
  926. result = result.multiply(highestPower2);
  927. n -= powers2Length - 1;
  928. }
  929. return result.multiply(powersOfTwo[n]);
  930. };
  931. SmallInteger.prototype.shiftLeft = BigInteger.prototype.shiftLeft;
  932. BigInteger.prototype.shiftRight = function (n) {
  933. var remQuo;
  934. if (!shift_isSmall(n)) {
  935. throw new Error(String(n) + " is too large for shifting.");
  936. }
  937. n = +n;
  938. if (n < 0) return this.shiftLeft(-n);
  939. var result = this;
  940. while (n >= powers2Length) {
  941. if (result.isZero()) return result;
  942. remQuo = divModAny(result, highestPower2);
  943. result = remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];
  944. n -= powers2Length - 1;
  945. }
  946. remQuo = divModAny(result, powersOfTwo[n]);
  947. return remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];
  948. };
  949. SmallInteger.prototype.shiftRight = BigInteger.prototype.shiftRight;
  950. function bitwise(x, y, fn) {
  951. y = parseValue(y);
  952. var xSign = x.isNegative(), ySign = y.isNegative();
  953. var xRem = xSign ? x.not() : x,
  954. yRem = ySign ? y.not() : y;
  955. var xBits = [], yBits = [];
  956. var xStop = false, yStop = false;
  957. while (!xStop || !yStop) {
  958. if (xRem.isZero()) { // virtual sign extension for simulating two's complement
  959. xStop = true;
  960. xBits.push(xSign ? 1 : 0);
  961. }
  962. else if (xSign) xBits.push(xRem.isEven() ? 1 : 0); // two's complement for negative numbers
  963. else xBits.push(xRem.isEven() ? 0 : 1);
  964. if (yRem.isZero()) {
  965. yStop = true;
  966. yBits.push(ySign ? 1 : 0);
  967. }
  968. else if (ySign) yBits.push(yRem.isEven() ? 1 : 0);
  969. else yBits.push(yRem.isEven() ? 0 : 1);
  970. xRem = xRem.over(2);
  971. yRem = yRem.over(2);
  972. }
  973. var result = [];
  974. for (var i = 0; i < xBits.length; i++) result.push(fn(xBits[i], yBits[i]));
  975. var sum = bigInt(result.pop()).negate().times(bigInt(2).pow(result.length));
  976. while (result.length) {
  977. sum = sum.add(bigInt(result.pop()).times(bigInt(2).pow(result.length)));
  978. }
  979. return sum;
  980. }
  981. BigInteger.prototype.not = function () {
  982. return this.negate().prev();
  983. };
  984. SmallInteger.prototype.not = BigInteger.prototype.not;
  985. BigInteger.prototype.and = function (n) {
  986. return bitwise(this, n, function (a, b) { return a & b; });
  987. };
  988. SmallInteger.prototype.and = BigInteger.prototype.and;
  989. BigInteger.prototype.or = function (n) {
  990. return bitwise(this, n, function (a, b) { return a | b; });
  991. };
  992. SmallInteger.prototype.or = BigInteger.prototype.or;
  993. BigInteger.prototype.xor = function (n) {
  994. return bitwise(this, n, function (a, b) { return a ^ b; });
  995. };
  996. SmallInteger.prototype.xor = BigInteger.prototype.xor;
  997. var LOBMASK_I = 1 << 30, LOBMASK_BI = (BASE & -BASE) * (BASE & -BASE) | LOBMASK_I;
  998. function roughLOB(n) { // get lowestOneBit (rough)
  999. // SmallInteger: return Min(lowestOneBit(n), 1 << 30)
  1000. // BigInteger: return Min(lowestOneBit(n), 1 << 14) [BASE=1e7]
  1001. var v = n.value, x = typeof v === "number" ? v | LOBMASK_I : v[0] + v[1] * BASE | LOBMASK_BI;
  1002. return x & -x;
  1003. }
  1004. function max(a, b) {
  1005. a = parseValue(a);
  1006. b = parseValue(b);
  1007. return a.greater(b) ? a : b;
  1008. }
  1009. function min(a,b) {
  1010. a = parseValue(a);
  1011. b = parseValue(b);
  1012. return a.lesser(b) ? a : b;
  1013. }
  1014. function gcd(a, b) {
  1015. a = parseValue(a).abs();
  1016. b = parseValue(b).abs();
  1017. if (a.equals(b)) return a;
  1018. if (a.isZero()) return b;
  1019. if (b.isZero()) return a;
  1020. var c = Integer[1], d, t;
  1021. while (a.isEven() && b.isEven()) {
  1022. d = Math.min(roughLOB(a), roughLOB(b));
  1023. a = a.divide(d);
  1024. b = b.divide(d);
  1025. c = c.multiply(d);
  1026. }
  1027. while (a.isEven()) {
  1028. a = a.divide(roughLOB(a));
  1029. }
  1030. do {
  1031. while (b.isEven()) {
  1032. b = b.divide(roughLOB(b));
  1033. }
  1034. if (a.greater(b)) {
  1035. t = b; b = a; a = t;
  1036. }
  1037. b = b.subtract(a);
  1038. } while (!b.isZero());
  1039. return c.isUnit() ? a : a.multiply(c);
  1040. }
  1041. function lcm(a, b) {
  1042. a = parseValue(a).abs();
  1043. b = parseValue(b).abs();
  1044. return a.divide(gcd(a, b)).multiply(b);
  1045. }
  1046. function randBetween(a, b) {
  1047. a = parseValue(a);
  1048. b = parseValue(b);
  1049. var low = min(a, b), high = max(a, b);
  1050. var range = high.subtract(low);
  1051. if (range.isSmall) return low.add(Math.round(Math.random() * range));
  1052. var length = range.value.length - 1;
  1053. var result = [], restricted = true;
  1054. for (var i = length; i >= 0; i--) {
  1055. var top = restricted ? range.value[i] : BASE;
  1056. var digit = truncate(Math.random() * top);
  1057. result.unshift(digit);
  1058. if (digit < top) restricted = false;
  1059. }
  1060. result = arrayToSmall(result);
  1061. return low.add(typeof result === "number" ? new SmallInteger(result) : new BigInteger(result, false));
  1062. }
  1063. var parseBase = function (text, base) {
  1064. var val = Integer[0], pow = Integer[1],
  1065. length = text.length;
  1066. if (2 <= base && base <= 36) {
  1067. if (length <= LOG_MAX_INT / Math.log(base)) {
  1068. return new SmallInteger(parseInt(text, base));
  1069. }
  1070. }
  1071. base = parseValue(base);
  1072. var digits = [];
  1073. var i;
  1074. var isNegative = text[0] === "-";
  1075. for (i = isNegative ? 1 : 0; i < text.length; i++) {
  1076. var c = text[i].toLowerCase(),
  1077. charCode = c.charCodeAt(0);
  1078. if (48 <= charCode && charCode <= 57) digits.push(parseValue(c));
  1079. else if (97 <= charCode && charCode <= 122) digits.push(parseValue(c.charCodeAt(0) - 87));
  1080. else if (c === "<") {
  1081. var start = i;
  1082. do { i++; } while (text[i] !== ">");
  1083. digits.push(parseValue(text.slice(start + 1, i)));
  1084. }
  1085. else throw new Error(c + " is not a valid character");
  1086. }
  1087. digits.reverse();
  1088. for (i = 0; i < digits.length; i++) {
  1089. val = val.add(digits[i].times(pow));
  1090. pow = pow.times(base);
  1091. }
  1092. return isNegative ? val.negate() : val;
  1093. };
  1094. function stringify(digit) {
  1095. var v = digit.value;
  1096. if (typeof v === "number") v = [v];
  1097. if (v.length === 1 && v[0] <= 35) {
  1098. return "0123456789abcdefghijklmnopqrstuvwxyz".charAt(v[0]);
  1099. }
  1100. return "<" + v + ">";
  1101. }
  1102. function toBase(n, base) {
  1103. base = bigInt(base);
  1104. if (base.isZero()) {
  1105. if (n.isZero()) return "0";
  1106. throw new Error("Cannot convert nonzero numbers to base 0.");
  1107. }
  1108. if (base.equals(-1)) {
  1109. if (n.isZero()) return "0";
  1110. if (n.isNegative()) return new Array(1 - n).join("10");
  1111. return "1" + new Array(+n).join("01");
  1112. }
  1113. var minusSign = "";
  1114. if (n.isNegative() && base.isPositive()) {
  1115. minusSign = "-";
  1116. n = n.abs();
  1117. }
  1118. if (base.equals(1)) {
  1119. if (n.isZero()) return "0";
  1120. return minusSign + new Array(+n + 1).join(1);
  1121. }
  1122. var out = [];
  1123. var left = n, divmod;
  1124. while (left.isNegative() || left.compareAbs(base) >= 0) {
  1125. divmod = left.divmod(base);
  1126. left = divmod.quotient;
  1127. var digit = divmod.remainder;
  1128. if (digit.isNegative()) {
  1129. digit = base.minus(digit).abs();
  1130. left = left.next();
  1131. }
  1132. out.push(stringify(digit));
  1133. }
  1134. out.push(stringify(left));
  1135. return minusSign + out.reverse().join("");
  1136. }
  1137. BigInteger.prototype.toString = function (radix) {
  1138. if (radix === undefined) radix = 10;
  1139. if (radix !== 10) return toBase(this, radix);
  1140. var v = this.value, l = v.length, str = String(v[--l]), zeros = "0000000", digit;
  1141. while (--l >= 0) {
  1142. digit = String(v[l]);
  1143. str += zeros.slice(digit.length) + digit;
  1144. }
  1145. var sign = this.sign ? "-" : "";
  1146. return sign + str;
  1147. };
  1148. SmallInteger.prototype.toString = function (radix) {
  1149. if (radix === undefined) radix = 10;
  1150. if (radix != 10) return toBase(this, radix);
  1151. return String(this.value);
  1152. };
  1153. BigInteger.prototype.valueOf = function () {
  1154. return +this.toString();
  1155. };
  1156. BigInteger.prototype.toJSNumber = BigInteger.prototype.valueOf;
  1157. SmallInteger.prototype.valueOf = function () {
  1158. return this.value;
  1159. };
  1160. SmallInteger.prototype.toJSNumber = SmallInteger.prototype.valueOf;
  1161. function parseStringValue(v) {
  1162. if (isPrecise(+v)) {
  1163. var x = +v;
  1164. if (x === truncate(x))
  1165. return new SmallInteger(x);
  1166. throw "Invalid integer: " + v;
  1167. }
  1168. var sign = v[0] === "-";
  1169. if (sign) v = v.slice(1);
  1170. var split = v.split(/e/i);
  1171. if (split.length > 2) throw new Error("Invalid integer: " + split.join("e"));
  1172. if (split.length === 2) {
  1173. var exp = split[1];
  1174. if (exp[0] === "+") exp = exp.slice(1);
  1175. exp = +exp;
  1176. if (exp !== truncate(exp) || !isPrecise(exp)) throw new Error("Invalid integer: " + exp + " is not a valid exponent.");
  1177. var text = split[0];
  1178. var decimalPlace = text.indexOf(".");
  1179. if (decimalPlace >= 0) {
  1180. exp -= text.length - decimalPlace - 1;
  1181. text = text.slice(0, decimalPlace) + text.slice(decimalPlace + 1);
  1182. }
  1183. if (exp < 0) throw new Error("Cannot include negative exponent part for integers");
  1184. text += (new Array(exp + 1)).join("0");
  1185. v = text;
  1186. }
  1187. var isValid = /^([0-9][0-9]*)$/.test(v);
  1188. if (!isValid) throw new Error("Invalid integer: " + v);
  1189. var r = [], max = v.length, l = LOG_BASE, min = max - l;
  1190. while (max > 0) {
  1191. r.push(+v.slice(min, max));
  1192. min -= l;
  1193. if (min < 0) min = 0;
  1194. max -= l;
  1195. }
  1196. trim(r);
  1197. return new BigInteger(r, sign);
  1198. }
  1199. function parseNumberValue(v) {
  1200. if (isPrecise(v)) {
  1201. if (v !== truncate(v)) throw new Error(v + " is not an integer.");
  1202. return new SmallInteger(v);
  1203. }
  1204. return parseStringValue(v.toString());
  1205. }
  1206. function parseValue(v) {
  1207. if (typeof v === "number") {
  1208. return parseNumberValue(v);
  1209. }
  1210. if (typeof v === "string") {
  1211. return parseStringValue(v);
  1212. }
  1213. return v;
  1214. }
  1215. // Pre-define numbers in range [-999,999]
  1216. for (var i = 0; i < 1000; i++) {
  1217. Integer[i] = new SmallInteger(i);
  1218. if (i > 0) Integer[-i] = new SmallInteger(-i);
  1219. }
  1220. // Backwards compatibility
  1221. Integer.one = Integer[1];
  1222. Integer.zero = Integer[0];
  1223. Integer.minusOne = Integer[-1];
  1224. Integer.max = max;
  1225. Integer.min = min;
  1226. Integer.gcd = gcd;
  1227. Integer.lcm = lcm;
  1228. Integer.isInstance = function (x) { return x instanceof BigInteger || x instanceof SmallInteger; };
  1229. Integer.randBetween = randBetween;
  1230. return Integer;
  1231. })();
  1232. // Node.js check
  1233. if (typeof module !== "undefined" && module.hasOwnProperty("exports")) {
  1234. module.exports = bigInt;
  1235. }
  1236. },{}],4:[function(require,module,exports){
  1237. (function (process,global){
  1238. /* @preserve
  1239. * The MIT License (MIT)
  1240. *
  1241. * Copyright (c) 2013-2015 Petka Antonov
  1242. *
  1243. * Permission is hereby granted, free of charge, to any person obtaining a copy
  1244. * of this software and associated documentation files (the "Software"), to deal
  1245. * in the Software without restriction, including without limitation the rights
  1246. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  1247. * copies of the Software, and to permit persons to whom the Software is
  1248. * furnished to do so, subject to the following conditions:
  1249. *
  1250. * The above copyright notice and this permission notice shall be included in
  1251. * all copies or substantial portions of the Software.
  1252. *
  1253. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1254. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1255. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  1256. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1257. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1258. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  1259. * THE SOFTWARE.
  1260. *
  1261. */
  1262. /**
  1263. * bluebird build version 3.4.6
  1264. * Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, using, timers, filter, any, each
  1265. */
  1266. !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Promise=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof _dereq_=="function"&&_dereq_;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof _dereq_=="function"&&_dereq_;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
  1267. "use strict";
  1268. module.exports = function(Promise) {
  1269. var SomePromiseArray = Promise._SomePromiseArray;
  1270. function any(promises) {
  1271. var ret = new SomePromiseArray(promises);
  1272. var promise = ret.promise();
  1273. ret.setHowMany(1);
  1274. ret.setUnwrap();
  1275. ret.init();
  1276. return promise;
  1277. }
  1278. Promise.any = function (promises) {
  1279. return any(promises);
  1280. };
  1281. Promise.prototype.any = function () {
  1282. return any(this);
  1283. };
  1284. };
  1285. },{}],2:[function(_dereq_,module,exports){
  1286. "use strict";
  1287. var firstLineError;
  1288. try {throw new Error(); } catch (e) {firstLineError = e;}
  1289. var schedule = _dereq_("./schedule");
  1290. var Queue = _dereq_("./queue");
  1291. var util = _dereq_("./util");
  1292. function Async() {
  1293. this._customScheduler = false;
  1294. this._isTickUsed = false;
  1295. this._lateQueue = new Queue(16);
  1296. this._normalQueue = new Queue(16);
  1297. this._haveDrainedQueues = false;
  1298. this._trampolineEnabled = true;
  1299. var self = this;
  1300. this.drainQueues = function () {
  1301. self._drainQueues();
  1302. };
  1303. this._schedule = schedule;
  1304. }
  1305. Async.prototype.setScheduler = function(fn) {
  1306. var prev = this._schedule;
  1307. this._schedule = fn;
  1308. this._customScheduler = true;
  1309. return prev;
  1310. };
  1311. Async.prototype.hasCustomScheduler = function() {
  1312. return this._customScheduler;
  1313. };
  1314. Async.prototype.enableTrampoline = function() {
  1315. this._trampolineEnabled = true;
  1316. };
  1317. Async.prototype.disableTrampolineIfNecessary = function() {
  1318. if (util.hasDevTools) {
  1319. this._trampolineEnabled = false;
  1320. }
  1321. };
  1322. Async.prototype.haveItemsQueued = function () {
  1323. return this._isTickUsed || this._haveDrainedQueues;
  1324. };
  1325. Async.prototype.fatalError = function(e, isNode) {
  1326. if (isNode) {
  1327. process.stderr.write("Fatal " + (e instanceof Error ? e.stack : e) +
  1328. "\n");
  1329. process.exit(2);
  1330. } else {
  1331. this.throwLater(e);
  1332. }
  1333. };
  1334. Async.prototype.throwLater = function(fn, arg) {
  1335. if (arguments.length === 1) {
  1336. arg = fn;
  1337. fn = function () { throw arg; };
  1338. }
  1339. if (typeof setTimeout !== "undefined") {
  1340. setTimeout(function() {
  1341. fn(arg);
  1342. }, 0);
  1343. } else try {
  1344. this._schedule(function() {
  1345. fn(arg);
  1346. });
  1347. } catch (e) {
  1348. throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  1349. }
  1350. };
  1351. function AsyncInvokeLater(fn, receiver, arg) {
  1352. this._lateQueue.push(fn, receiver, arg);
  1353. this._queueTick();
  1354. }
  1355. function AsyncInvoke(fn, receiver, arg) {
  1356. this._normalQueue.push(fn, receiver, arg);
  1357. this._queueTick();
  1358. }
  1359. function AsyncSettlePromises(promise) {
  1360. this._normalQueue._pushOne(promise);
  1361. this._queueTick();
  1362. }
  1363. if (!util.hasDevTools) {
  1364. Async.prototype.invokeLater = AsyncInvokeLater;
  1365. Async.prototype.invoke = AsyncInvoke;
  1366. Async.prototype.settlePromises = AsyncSettlePromises;
  1367. } else {
  1368. Async.prototype.invokeLater = function (fn, receiver, arg) {
  1369. if (this._trampolineEnabled) {
  1370. AsyncInvokeLater.call(this, fn, receiver, arg);
  1371. } else {
  1372. this._schedule(function() {
  1373. setTimeout(function() {
  1374. fn.call(receiver, arg);
  1375. }, 100);
  1376. });
  1377. }
  1378. };
  1379. Async.prototype.invoke = function (fn, receiver, arg) {
  1380. if (this._trampolineEnabled) {
  1381. AsyncInvoke.call(this, fn, receiver, arg);
  1382. } else {
  1383. this._schedule(function() {
  1384. fn.call(receiver, arg);
  1385. });
  1386. }
  1387. };
  1388. Async.prototype.settlePromises = function(promise) {
  1389. if (this._trampolineEnabled) {
  1390. AsyncSettlePromises.call(this, promise);
  1391. } else {
  1392. this._schedule(function() {
  1393. promise._settlePromises();
  1394. });
  1395. }
  1396. };
  1397. }
  1398. Async.prototype.invokeFirst = function (fn, receiver, arg) {
  1399. this._normalQueue.unshift(fn, receiver, arg);
  1400. this._queueTick();
  1401. };
  1402. Async.prototype._drainQueue = function(queue) {
  1403. while (queue.length() > 0) {
  1404. var fn = queue.shift();
  1405. if (typeof fn !== "function") {
  1406. fn._settlePromises();
  1407. continue;
  1408. }
  1409. var receiver = queue.shift();
  1410. var arg = queue.shift();
  1411. fn.call(receiver, arg);
  1412. }
  1413. };
  1414. Async.prototype._drainQueues = function () {
  1415. this._drainQueue(this._normalQueue);
  1416. this._reset();
  1417. this._haveDrainedQueues = true;
  1418. this._drainQueue(this._lateQueue);
  1419. };
  1420. Async.prototype._queueTick = function () {
  1421. if (!this._isTickUsed) {
  1422. this._isTickUsed = true;
  1423. this._schedule(this.drainQueues);
  1424. }
  1425. };
  1426. Async.prototype._reset = function () {
  1427. this._isTickUsed = false;
  1428. };
  1429. module.exports = Async;
  1430. module.exports.firstLineError = firstLineError;
  1431. },{"./queue":26,"./schedule":29,"./util":36}],3:[function(_dereq_,module,exports){
  1432. "use strict";
  1433. module.exports = function(Promise, INTERNAL, tryConvertToPromise, debug) {
  1434. var calledBind = false;
  1435. var rejectThis = function(_, e) {
  1436. this._reject(e);
  1437. };
  1438. var targetRejected = function(e, context) {
  1439. context.promiseRejectionQueued = true;
  1440. context.bindingPromise._then(rejectThis, rejectThis, null, this, e);
  1441. };
  1442. var bindingResolved = function(thisArg, context) {
  1443. if (((this._bitField & 50397184) === 0)) {
  1444. this._resolveCallback(context.target);
  1445. }
  1446. };
  1447. var bindingRejected = function(e, context) {
  1448. if (!context.promiseRejectionQueued) this._reject(e);
  1449. };
  1450. Promise.prototype.bind = function (thisArg) {
  1451. if (!calledBind) {
  1452. calledBind = true;
  1453. Promise.prototype._propagateFrom = debug.propagateFromFunction();
  1454. Promise.prototype._boundValue = debug.boundValueFunction();
  1455. }
  1456. var maybePromise = tryConvertToPromise(thisArg);
  1457. var ret = new Promise(INTERNAL);
  1458. ret._propagateFrom(this, 1);
  1459. var target = this._target();
  1460. ret._setBoundTo(maybePromise);
  1461. if (maybePromise instanceof Promise) {
  1462. var context = {
  1463. promiseRejectionQueued: false,
  1464. promise: ret,
  1465. target: target,
  1466. bindingPromise: maybePromise
  1467. };
  1468. target._then(INTERNAL, targetRejected, undefined, ret, context);
  1469. maybePromise._then(
  1470. bindingResolved, bindingRejected, undefined, ret, context);
  1471. ret._setOnCancel(maybePromise);
  1472. } else {
  1473. ret._resolveCallback(target);
  1474. }
  1475. return ret;
  1476. };
  1477. Promise.prototype._setBoundTo = function (obj) {
  1478. if (obj !== undefined) {
  1479. this._bitField = this._bitField | 2097152;
  1480. this._boundTo = obj;
  1481. } else {
  1482. this._bitField = this._bitField & (~2097152);
  1483. }
  1484. };
  1485. Promise.prototype._isBound = function () {
  1486. return (this._bitField & 2097152) === 2097152;
  1487. };
  1488. Promise.bind = function (thisArg, value) {
  1489. return Promise.resolve(value).bind(thisArg);
  1490. };
  1491. };
  1492. },{}],4:[function(_dereq_,module,exports){
  1493. "use strict";
  1494. var old;
  1495. if (typeof Promise !== "undefined") old = Promise;
  1496. function noConflict() {
  1497. try { if (Promise === bluebird) Promise = old; }
  1498. catch (e) {}
  1499. return bluebird;
  1500. }
  1501. var bluebird = _dereq_("./promise")();
  1502. bluebird.noConflict = noConflict;
  1503. module.exports = bluebird;
  1504. },{"./promise":22}],5:[function(_dereq_,module,exports){
  1505. "use strict";
  1506. var cr = Object.create;
  1507. if (cr) {
  1508. var callerCache = cr(null);
  1509. var getterCache = cr(null);
  1510. callerCache[" size"] = getterCache[" size"] = 0;
  1511. }
  1512. module.exports = function(Promise) {
  1513. var util = _dereq_("./util");
  1514. var canEvaluate = util.canEvaluate;
  1515. var isIdentifier = util.isIdentifier;
  1516. var getMethodCaller;
  1517. var getGetter;
  1518. if (!true) {
  1519. var makeMethodCaller = function (methodName) {
  1520. return new Function("ensureMethod", " \n\
  1521. return function(obj) { \n\
  1522. 'use strict' \n\
  1523. var len = this.length; \n\
  1524. ensureMethod(obj, 'methodName'); \n\
  1525. switch(len) { \n\
  1526. case 1: return obj.methodName(this[0]); \n\
  1527. case 2: return obj.methodName(this[0], this[1]); \n\
  1528. case 3: return obj.methodName(this[0], this[1], this[2]); \n\
  1529. case 0: return obj.methodName(); \n\
  1530. default: \n\
  1531. return obj.methodName.apply(obj, this); \n\
  1532. } \n\
  1533. }; \n\
  1534. ".replace(/methodName/g, methodName))(ensureMethod);
  1535. };
  1536. var makeGetter = function (propertyName) {
  1537. return new Function("obj", " \n\
  1538. 'use strict'; \n\
  1539. return obj.propertyName; \n\
  1540. ".replace("propertyName", propertyName));
  1541. };
  1542. var getCompiled = function(name, compiler, cache) {
  1543. var ret = cache[name];
  1544. if (typeof ret !== "function") {
  1545. if (!isIdentifier(name)) {
  1546. return null;
  1547. }
  1548. ret = compiler(name);
  1549. cache[name] = ret;
  1550. cache[" size"]++;
  1551. if (cache[" size"] > 512) {
  1552. var keys = Object.keys(cache);
  1553. for (var i = 0; i < 256; ++i) delete cache[keys[i]];
  1554. cache[" size"] = keys.length - 256;
  1555. }
  1556. }
  1557. return ret;
  1558. };
  1559. getMethodCaller = function(name) {
  1560. return getCompiled(name, makeMethodCaller, callerCache);
  1561. };
  1562. getGetter = function(name) {
  1563. return getCompiled(name, makeGetter, getterCache);
  1564. };
  1565. }
  1566. function ensureMethod(obj, methodName) {
  1567. var fn;
  1568. if (obj != null) fn = obj[methodName];
  1569. if (typeof fn !== "function") {
  1570. var message = "Object " + util.classString(obj) + " has no method '" +
  1571. util.toString(methodName) + "'";
  1572. throw new Promise.TypeError(message);
  1573. }
  1574. return fn;
  1575. }
  1576. function caller(obj) {
  1577. var methodName = this.pop();
  1578. var fn = ensureMethod(obj, methodName);
  1579. return fn.apply(obj, this);
  1580. }
  1581. Promise.prototype.call = function (methodName) {
  1582. var args = [].slice.call(arguments, 1);;
  1583. if (!true) {
  1584. if (canEvaluate) {
  1585. var maybeCaller = getMethodCaller(methodName);
  1586. if (maybeCaller !== null) {
  1587. return this._then(
  1588. maybeCaller, undefined, undefined, args, undefined);
  1589. }
  1590. }
  1591. }
  1592. args.push(methodName);
  1593. return this._then(caller, undefined, undefined, args, undefined);
  1594. };
  1595. function namedGetter(obj) {
  1596. return obj[this];
  1597. }
  1598. function indexedGetter(obj) {
  1599. var index = +this;
  1600. if (index < 0) index = Math.max(0, index + obj.length);
  1601. return obj[index];
  1602. }
  1603. Promise.prototype.get = function (propertyName) {
  1604. var isIndex = (typeof propertyName === "number");
  1605. var getter;
  1606. if (!isIndex) {
  1607. if (canEvaluate) {
  1608. var maybeGetter = getGetter(propertyName);
  1609. getter = maybeGetter !== null ? maybeGetter : namedGetter;
  1610. } else {
  1611. getter = namedGetter;
  1612. }
  1613. } else {
  1614. getter = indexedGetter;
  1615. }
  1616. return this._then(getter, undefined, undefined, propertyName, undefined);
  1617. };
  1618. };
  1619. },{"./util":36}],6:[function(_dereq_,module,exports){
  1620. "use strict";
  1621. module.exports = function(Promise, PromiseArray, apiRejection, debug) {
  1622. var util = _dereq_("./util");
  1623. var tryCatch = util.tryCatch;
  1624. var errorObj = util.errorObj;
  1625. var async = Promise._async;
  1626. Promise.prototype["break"] = Promise.prototype.cancel = function() {
  1627. if (!debug.cancellation()) return this._warn("cancellation is disabled");
  1628. var promise = this;
  1629. var child = promise;
  1630. while (promise._isCancellable()) {
  1631. if (!promise._cancelBy(child)) {
  1632. if (child._isFollowing()) {
  1633. child._followee().cancel();
  1634. } else {
  1635. child._cancelBranched();
  1636. }
  1637. break;
  1638. }
  1639. var parent = promise._cancellationParent;
  1640. if (parent == null || !parent._isCancellable()) {
  1641. if (promise._isFollowing()) {
  1642. promise._followee().cancel();
  1643. } else {
  1644. promise._cancelBranched();
  1645. }
  1646. break;
  1647. } else {
  1648. if (promise._isFollowing()) promise._followee().cancel();
  1649. promise._setWillBeCancelled();
  1650. child = promise;
  1651. promise = parent;
  1652. }
  1653. }
  1654. };
  1655. Promise.prototype._branchHasCancelled = function() {
  1656. this._branchesRemainingToCancel--;
  1657. };
  1658. Promise.prototype._enoughBranchesHaveCancelled = function() {
  1659. return this._branchesRemainingToCancel === undefined ||
  1660. this._branchesRemainingToCancel <= 0;
  1661. };
  1662. Promise.prototype._cancelBy = function(canceller) {
  1663. if (canceller === this) {
  1664. this._branchesRemainingToCancel = 0;
  1665. this._invokeOnCancel();
  1666. return true;
  1667. } else {
  1668. this._branchHasCancelled();
  1669. if (this._enoughBranchesHaveCancelled()) {
  1670. this._invokeOnCancel();
  1671. return true;
  1672. }
  1673. }
  1674. return false;
  1675. };
  1676. Promise.prototype._cancelBranched = function() {
  1677. if (this._enoughBranchesHaveCancelled()) {
  1678. this._cancel();
  1679. }
  1680. };
  1681. Promise.prototype._cancel = function() {
  1682. if (!this._isCancellable()) return;
  1683. this._setCancelled();
  1684. async.invoke(this._cancelPromises, this, undefined);
  1685. };
  1686. Promise.prototype._cancelPromises = function() {
  1687. if (this._length() > 0) this._settlePromises();
  1688. };
  1689. Promise.prototype._unsetOnCancel = function() {
  1690. this._onCancelField = undefined;
  1691. };
  1692. Promise.prototype._isCancellable = function() {
  1693. return this.isPending() && !this._isCancelled();
  1694. };
  1695. Promise.prototype.isCancellable = function() {
  1696. return this.isPending() && !this.isCancelled();
  1697. };
  1698. Promise.prototype._doInvokeOnCancel = function(onCancelCallback, internalOnly) {
  1699. if (util.isArray(onCancelCallback)) {
  1700. for (var i = 0; i < onCancelCallback.length; ++i) {
  1701. this._doInvokeOnCancel(onCancelCallback[i], internalOnly);
  1702. }
  1703. } else if (onCancelCallback !== undefined) {
  1704. if (typeof onCancelCallback === "function") {
  1705. if (!internalOnly) {
  1706. var e = tryCatch(onCancelCallback).call(this._boundValue());
  1707. if (e === errorObj) {
  1708. this._attachExtraTrace(e.e);
  1709. async.throwLater(e.e);
  1710. }
  1711. }
  1712. } else {
  1713. onCancelCallback._resultCancelled(this);
  1714. }
  1715. }
  1716. };
  1717. Promise.prototype._invokeOnCancel = function() {
  1718. var onCancelCallback = this._onCancel();
  1719. this._unsetOnCancel();
  1720. async.invoke(this._doInvokeOnCancel, this, onCancelCallback);
  1721. };
  1722. Promise.prototype._invokeInternalOnCancel = function() {
  1723. if (this._isCancellable()) {
  1724. this._doInvokeOnCancel(this._onCancel(), true);
  1725. this._unsetOnCancel();
  1726. }
  1727. };
  1728. Promise.prototype._resultCancelled = function() {
  1729. this.cancel();
  1730. };
  1731. };
  1732. },{"./util":36}],7:[function(_dereq_,module,exports){
  1733. "use strict";
  1734. module.exports = function(NEXT_FILTER) {
  1735. var util = _dereq_("./util");
  1736. var getKeys = _dereq_("./es5").keys;
  1737. var tryCatch = util.tryCatch;
  1738. var errorObj = util.errorObj;
  1739. function catchFilter(instances, cb, promise) {
  1740. return function(e) {
  1741. var boundTo = promise._boundValue();
  1742. predicateLoop: for (var i = 0; i < instances.length; ++i) {
  1743. var item = instances[i];
  1744. if (item === Error ||
  1745. (item != null && item.prototype instanceof Error)) {
  1746. if (e instanceof item) {
  1747. return tryCatch(cb).call(boundTo, e);
  1748. }
  1749. } else if (typeof item === "function") {
  1750. var matchesPredicate = tryCatch(item).call(boundTo, e);
  1751. if (matchesPredicate === errorObj) {
  1752. return matchesPredicate;
  1753. } else if (matchesPredicate) {
  1754. return tryCatch(cb).call(boundTo, e);
  1755. }
  1756. } else if (util.isObject(e)) {
  1757. var keys = getKeys(item);
  1758. for (var j = 0; j < keys.length; ++j) {
  1759. var key = keys[j];
  1760. if (item[key] != e[key]) {
  1761. continue predicateLoop;
  1762. }
  1763. }
  1764. return tryCatch(cb).call(boundTo, e);
  1765. }
  1766. }
  1767. return NEXT_FILTER;
  1768. };
  1769. }
  1770. return catchFilter;
  1771. };
  1772. },{"./es5":13,"./util":36}],8:[function(_dereq_,module,exports){
  1773. "use strict";
  1774. module.exports = function(Promise) {
  1775. var longStackTraces = false;
  1776. var contextStack = [];
  1777. Promise.prototype._promiseCreated = function() {};
  1778. Promise.prototype._pushContext = function() {};
  1779. Promise.prototype._popContext = function() {return null;};
  1780. Promise._peekContext = Promise.prototype._peekContext = function() {};
  1781. function Context() {
  1782. this._trace = new Context.CapturedTrace(peekContext());
  1783. }
  1784. Context.prototype._pushContext = function () {
  1785. if (this._trace !== undefined) {
  1786. this._trace._promiseCreated = null;
  1787. contextStack.push(this._trace);
  1788. }
  1789. };
  1790. Context.prototype._popContext = function () {
  1791. if (this._trace !== undefined) {
  1792. var trace = contextStack.pop();
  1793. var ret = trace._promiseCreated;
  1794. trace._promiseCreated = null;
  1795. return ret;
  1796. }
  1797. return null;
  1798. };
  1799. function createContext() {
  1800. if (longStackTraces) return new Context();
  1801. }
  1802. function peekContext() {
  1803. var lastIndex = contextStack.length - 1;
  1804. if (lastIndex >= 0) {
  1805. return contextStack[lastIndex];
  1806. }
  1807. return undefined;
  1808. }
  1809. Context.CapturedTrace = null;
  1810. Context.create = createContext;
  1811. Context.deactivateLongStackTraces = function() {};
  1812. Context.activateLongStackTraces = function() {
  1813. var Promise_pushContext = Promise.prototype._pushContext;
  1814. var Promise_popContext = Promise.prototype._popContext;
  1815. var Promise_PeekContext = Promise._peekContext;
  1816. var Promise_peekContext = Promise.prototype._peekContext;
  1817. var Promise_promiseCreated = Promise.prototype._promiseCreated;
  1818. Context.deactivateLongStackTraces = function() {
  1819. Promise.prototype._pushContext = Promise_pushContext;
  1820. Promise.prototype._popContext = Promise_popContext;
  1821. Promise._peekContext = Promise_PeekContext;
  1822. Promise.prototype._peekContext = Promise_peekContext;
  1823. Promise.prototype._promiseCreated = Promise_promiseCreated;
  1824. longStackTraces = false;
  1825. };
  1826. longStackTraces = true;
  1827. Promise.prototype._pushContext = Context.prototype._pushContext;
  1828. Promise.prototype._popContext = Context.prototype._popContext;
  1829. Promise._peekContext = Promise.prototype._peekContext = peekContext;
  1830. Promise.prototype._promiseCreated = function() {
  1831. var ctx = this._peekContext();
  1832. if (ctx && ctx._promiseCreated == null) ctx._promiseCreated = this;
  1833. };
  1834. };
  1835. return Context;
  1836. };
  1837. },{}],9:[function(_dereq_,module,exports){
  1838. "use strict";
  1839. module.exports = function(Promise, Context) {
  1840. var getDomain = Promise._getDomain;
  1841. var async = Promise._async;
  1842. var Warning = _dereq_("./errors").Warning;
  1843. var util = _dereq_("./util");
  1844. var canAttachTrace = util.canAttachTrace;
  1845. var unhandledRejectionHandled;
  1846. var possiblyUnhandledRejection;
  1847. var bluebirdFramePattern =
  1848. /[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/;
  1849. var nodeFramePattern = /\((?:timers\.js):\d+:\d+\)/;
  1850. var parseLinePattern = /[\/<\(](.+?):(\d+):(\d+)\)?\s*$/;
  1851. var stackFramePattern = null;
  1852. var formatStack = null;
  1853. var indentStackFrames = false;
  1854. var printWarning;
  1855. var debugging = !!(util.env("BLUEBIRD_DEBUG") != 0 &&
  1856. (true ||
  1857. util.env("BLUEBIRD_DEBUG") ||
  1858. util.env("NODE_ENV") === "development"));
  1859. var warnings = !!(util.env("BLUEBIRD_WARNINGS") != 0 &&
  1860. (debugging || util.env("BLUEBIRD_WARNINGS")));
  1861. var longStackTraces = !!(util.env("BLUEBIRD_LONG_STACK_TRACES") != 0 &&
  1862. (debugging || util.env("BLUEBIRD_LONG_STACK_TRACES")));
  1863. var wForgottenReturn = util.env("BLUEBIRD_W_FORGOTTEN_RETURN") != 0 &&
  1864. (warnings || !!util.env("BLUEBIRD_W_FORGOTTEN_RETURN"));
  1865. Promise.prototype.suppressUnhandledRejections = function() {
  1866. var target = this._target();
  1867. target._bitField = ((target._bitField & (~1048576)) |
  1868. 524288);
  1869. };
  1870. Promise.prototype._ensurePossibleRejectionHandled = function () {
  1871. if ((this._bitField & 524288) !== 0) return;
  1872. this._setRejectionIsUnhandled();
  1873. async.invokeLater(this._notifyUnhandledRejection, this, undefined);
  1874. };
  1875. Promise.prototype._notifyUnhandledRejectionIsHandled = function () {
  1876. fireRejectionEvent("rejectionHandled",
  1877. unhandledRejectionHandled, undefined, this);
  1878. };
  1879. Promise.prototype._setReturnedNonUndefined = function() {
  1880. this._bitField = this._bitField | 268435456;
  1881. };
  1882. Promise.prototype._returnedNonUndefined = function() {
  1883. return (this._bitField & 268435456) !== 0;
  1884. };
  1885. Promise.prototype._notifyUnhandledRejection = function () {
  1886. if (this._isRejectionUnhandled()) {
  1887. var reason = this._settledValue();
  1888. this._setUnhandledRejectionIsNotified();
  1889. fireRejectionEvent("unhandledRejection",
  1890. possiblyUnhandledRejection, reason, this);
  1891. }
  1892. };
  1893. Promise.prototype._setUnhandledRejectionIsNotified = function () {
  1894. this._bitField = this._bitField | 262144;
  1895. };
  1896. Promise.prototype._unsetUnhandledRejectionIsNotified = function () {
  1897. this._bitField = this._bitField & (~262144);
  1898. };
  1899. Promise.prototype._isUnhandledRejectionNotified = function () {
  1900. return (this._bitField & 262144) > 0;
  1901. };
  1902. Promise.prototype._setRejectionIsUnhandled = function () {
  1903. this._bitField = this._bitField | 1048576;
  1904. };
  1905. Promise.prototype._unsetRejectionIsUnhandled = function () {
  1906. this._bitField = this._bitField & (~1048576);
  1907. if (this._isUnhandledRejectionNotified()) {
  1908. this._unsetUnhandledRejectionIsNotified();
  1909. this._notifyUnhandledRejectionIsHandled();
  1910. }
  1911. };
  1912. Promise.prototype._isRejectionUnhandled = function () {
  1913. return (this._bitField & 1048576) > 0;
  1914. };
  1915. Promise.prototype._warn = function(message, shouldUseOwnTrace, promise) {
  1916. return warn(message, shouldUseOwnTrace, promise || this);
  1917. };
  1918. Promise.onPossiblyUnhandledRejection = function (fn) {
  1919. var domain = getDomain();
  1920. possiblyUnhandledRejection =
  1921. typeof fn === "function" ? (domain === null ?
  1922. fn : util.domainBind(domain, fn))
  1923. : undefined;
  1924. };
  1925. Promise.onUnhandledRejectionHandled = function (fn) {
  1926. var domain = getDomain();
  1927. unhandledRejectionHandled =
  1928. typeof fn === "function" ? (domain === null ?
  1929. fn : util.domainBind(domain, fn))
  1930. : undefined;
  1931. };
  1932. var disableLongStackTraces = function() {};
  1933. Promise.longStackTraces = function () {
  1934. if (async.haveItemsQueued() && !config.longStackTraces) {
  1935. throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  1936. }
  1937. if (!config.longStackTraces && longStackTracesIsSupported()) {
  1938. var Promise_captureStackTrace = Promise.prototype._captureStackTrace;
  1939. var Promise_attachExtraTrace = Promise.prototype._attachExtraTrace;
  1940. config.longStackTraces = true;
  1941. disableLongStackTraces = function() {
  1942. if (async.haveItemsQueued() && !config.longStackTraces) {
  1943. throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  1944. }
  1945. Promise.prototype._captureStackTrace = Promise_captureStackTrace;
  1946. Promise.prototype._attachExtraTrace = Promise_attachExtraTrace;
  1947. Context.deactivateLongStackTraces();
  1948. async.enableTrampoline();
  1949. config.longStackTraces = false;
  1950. };
  1951. Promise.prototype._captureStackTrace = longStackTracesCaptureStackTrace;
  1952. Promise.prototype._attachExtraTrace = longStackTracesAttachExtraTrace;
  1953. Context.activateLongStackTraces();
  1954. async.disableTrampolineIfNecessary();
  1955. }
  1956. };
  1957. Promise.hasLongStackTraces = function () {
  1958. return config.longStackTraces && longStackTracesIsSupported();
  1959. };
  1960. var fireDomEvent = (function() {
  1961. try {
  1962. if (typeof CustomEvent === "function") {
  1963. var event = new CustomEvent("CustomEvent");
  1964. util.global.dispatchEvent(event);
  1965. return function(name, event) {
  1966. var domEvent = new CustomEvent(name.toLowerCase(), {
  1967. detail: event,
  1968. cancelable: true
  1969. });
  1970. return !util.global.dispatchEvent(domEvent);
  1971. };
  1972. } else if (typeof Event === "function") {
  1973. var event = new Event("CustomEvent");
  1974. util.global.dispatchEvent(event);
  1975. return function(name, event) {
  1976. var domEvent = new Event(name.toLowerCase(), {
  1977. cancelable: true
  1978. });
  1979. domEvent.detail = event;
  1980. return !util.global.dispatchEvent(domEvent);
  1981. };
  1982. } else {
  1983. var event = document.createEvent("CustomEvent");
  1984. event.initCustomEvent("testingtheevent", false, true, {});
  1985. util.global.dispatchEvent(event);
  1986. return function(name, event) {
  1987. var domEvent = document.createEvent("CustomEvent");
  1988. domEvent.initCustomEvent(name.toLowerCase(), false, true,
  1989. event);
  1990. return !util.global.dispatchEvent(domEvent);
  1991. };
  1992. }
  1993. } catch (e) {}
  1994. return function() {
  1995. return false;
  1996. };
  1997. })();
  1998. var fireGlobalEvent = (function() {
  1999. if (util.isNode) {
  2000. return function() {
  2001. return process.emit.apply(process, arguments);
  2002. };
  2003. } else {
  2004. if (!util.global) {
  2005. return function() {
  2006. return false;
  2007. };
  2008. }
  2009. return function(name) {
  2010. var methodName = "on" + name.toLowerCase();
  2011. var method = util.global[methodName];
  2012. if (!method) return false;
  2013. method.apply(util.global, [].slice.call(arguments, 1));
  2014. return true;
  2015. };
  2016. }
  2017. })();
  2018. function generatePromiseLifecycleEventObject(name, promise) {
  2019. return {promise: promise};
  2020. }
  2021. var eventToObjectGenerator = {
  2022. promiseCreated: generatePromiseLifecycleEventObject,
  2023. promiseFulfilled: generatePromiseLifecycleEventObject,
  2024. promiseRejected: generatePromiseLifecycleEventObject,
  2025. promiseResolved: generatePromiseLifecycleEventObject,
  2026. promiseCancelled: generatePromiseLifecycleEventObject,
  2027. promiseChained: function(name, promise, child) {
  2028. return {promise: promise, child: child};
  2029. },
  2030. warning: function(name, warning) {
  2031. return {warning: warning};
  2032. },
  2033. unhandledRejection: function (name, reason, promise) {
  2034. return {reason: reason, promise: promise};
  2035. },
  2036. rejectionHandled: generatePromiseLifecycleEventObject
  2037. };
  2038. var activeFireEvent = function (name) {
  2039. var globalEventFired = false;
  2040. try {
  2041. globalEventFired = fireGlobalEvent.apply(null, arguments);
  2042. } catch (e) {
  2043. async.throwLater(e);
  2044. globalEventFired = true;
  2045. }
  2046. var domEventFired = false;
  2047. try {
  2048. domEventFired = fireDomEvent(name,
  2049. eventToObjectGenerator[name].apply(null, arguments));
  2050. } catch (e) {
  2051. async.throwLater(e);
  2052. domEventFired = true;
  2053. }
  2054. return domEventFired || globalEventFired;
  2055. };
  2056. Promise.config = function(opts) {
  2057. opts = Object(opts);
  2058. if ("longStackTraces" in opts) {
  2059. if (opts.longStackTraces) {
  2060. Promise.longStackTraces();
  2061. } else if (!opts.longStackTraces && Promise.hasLongStackTraces()) {
  2062. disableLongStackTraces();
  2063. }
  2064. }
  2065. if ("warnings" in opts) {
  2066. var warningsOption = opts.warnings;
  2067. config.warnings = !!warningsOption;
  2068. wForgottenReturn = config.warnings;
  2069. if (util.isObject(warningsOption)) {
  2070. if ("wForgottenReturn" in warningsOption) {
  2071. wForgottenReturn = !!warningsOption.wForgottenReturn;
  2072. }
  2073. }
  2074. }
  2075. if ("cancellation" in opts && opts.cancellation && !config.cancellation) {
  2076. if (async.haveItemsQueued()) {
  2077. throw new Error(
  2078. "cannot enable cancellation after promises are in use");
  2079. }
  2080. Promise.prototype._clearCancellationData =
  2081. cancellationClearCancellationData;
  2082. Promise.prototype._propagateFrom = cancellationPropagateFrom;
  2083. Promise.prototype._onCancel = cancellationOnCancel;
  2084. Promise.prototype._setOnCancel = cancellationSetOnCancel;
  2085. Promise.prototype._attachCancellationCallback =
  2086. cancellationAttachCancellationCallback;
  2087. Promise.prototype._execute = cancellationExecute;
  2088. propagateFromFunction = cancellationPropagateFrom;
  2089. config.cancellation = true;
  2090. }
  2091. if ("monitoring" in opts) {
  2092. if (opts.monitoring && !config.monitoring) {
  2093. config.monitoring = true;
  2094. Promise.prototype._fireEvent = activeFireEvent;
  2095. } else if (!opts.monitoring && config.monitoring) {
  2096. config.monitoring = false;
  2097. Promise.prototype._fireEvent = defaultFireEvent;
  2098. }
  2099. }
  2100. };
  2101. function defaultFireEvent() { return false; }
  2102. Promise.prototype._fireEvent = defaultFireEvent;
  2103. Promise.prototype._execute = function(executor, resolve, reject) {
  2104. try {
  2105. executor(resolve, reject);
  2106. } catch (e) {
  2107. return e;
  2108. }
  2109. };
  2110. Promise.prototype._onCancel = function () {};
  2111. Promise.prototype._setOnCancel = function (handler) { ; };
  2112. Promise.prototype._attachCancellationCallback = function(onCancel) {
  2113. ;
  2114. };
  2115. Promise.prototype._captureStackTrace = function () {};
  2116. Promise.prototype._attachExtraTrace = function () {};
  2117. Promise.prototype._clearCancellationData = function() {};
  2118. Promise.prototype._propagateFrom = function (parent, flags) {
  2119. ;
  2120. ;
  2121. };
  2122. function cancellationExecute(executor, resolve, reject) {
  2123. var promise = this;
  2124. try {
  2125. executor(resolve, reject, function(onCancel) {
  2126. if (typeof onCancel !== "function") {
  2127. throw new TypeError("onCancel must be a function, got: " +
  2128. util.toString(onCancel));
  2129. }
  2130. promise._attachCancellationCallback(onCancel);
  2131. });
  2132. } catch (e) {
  2133. return e;
  2134. }
  2135. }
  2136. function cancellationAttachCancellationCallback(onCancel) {
  2137. if (!this._isCancellable()) return this;
  2138. var previousOnCancel = this._onCancel();
  2139. if (previousOnCancel !== undefined) {
  2140. if (util.isArray(previousOnCancel)) {
  2141. previousOnCancel.push(onCancel);
  2142. } else {
  2143. this._setOnCancel([previousOnCancel, onCancel]);
  2144. }
  2145. } else {
  2146. this._setOnCancel(onCancel);
  2147. }
  2148. }
  2149. function cancellationOnCancel() {
  2150. return this._onCancelField;
  2151. }
  2152. function cancellationSetOnCancel(onCancel) {
  2153. this._onCancelField = onCancel;
  2154. }
  2155. function cancellationClearCancellationData() {
  2156. this._cancellationParent = undefined;
  2157. this._onCancelField = undefined;
  2158. }
  2159. function cancellationPropagateFrom(parent, flags) {
  2160. if ((flags & 1) !== 0) {
  2161. this._cancellationParent = parent;
  2162. var branchesRemainingToCancel = parent._branchesRemainingToCancel;
  2163. if (branchesRemainingToCancel === undefined) {
  2164. branchesRemainingToCancel = 0;
  2165. }
  2166. parent._branchesRemainingToCancel = branchesRemainingToCancel + 1;
  2167. }
  2168. if ((flags & 2) !== 0 && parent._isBound()) {
  2169. this._setBoundTo(parent._boundTo);
  2170. }
  2171. }
  2172. function bindingPropagateFrom(parent, flags) {
  2173. if ((flags & 2) !== 0 && parent._isBound()) {
  2174. this._setBoundTo(parent._boundTo);
  2175. }
  2176. }
  2177. var propagateFromFunction = bindingPropagateFrom;
  2178. function boundValueFunction() {
  2179. var ret = this._boundTo;
  2180. if (ret !== undefined) {
  2181. if (ret instanceof Promise) {
  2182. if (ret.isFulfilled()) {
  2183. return ret.value();
  2184. } else {
  2185. return undefined;
  2186. }
  2187. }
  2188. }
  2189. return ret;
  2190. }
  2191. function longStackTracesCaptureStackTrace() {
  2192. this._trace = new CapturedTrace(this._peekContext());
  2193. }
  2194. function longStackTracesAttachExtraTrace(error, ignoreSelf) {
  2195. if (canAttachTrace(error)) {
  2196. var trace = this._trace;
  2197. if (trace !== undefined) {
  2198. if (ignoreSelf) trace = trace._parent;
  2199. }
  2200. if (trace !== undefined) {
  2201. trace.attachExtraTrace(error);
  2202. } else if (!error.__stackCleaned__) {
  2203. var parsed = parseStackAndMessage(error);
  2204. util.notEnumerableProp(error, "stack",
  2205. parsed.message + "\n" + parsed.stack.join("\n"));
  2206. util.notEnumerableProp(error, "__stackCleaned__", true);
  2207. }
  2208. }
  2209. }
  2210. function checkForgottenReturns(returnValue, promiseCreated, name, promise,
  2211. parent) {
  2212. if (returnValue === undefined && promiseCreated !== null &&
  2213. wForgottenReturn) {
  2214. if (parent !== undefined && parent._returnedNonUndefined()) return;
  2215. if ((promise._bitField & 65535) === 0) return;
  2216. if (name) name = name + " ";
  2217. var handlerLine = "";
  2218. var creatorLine = "";
  2219. if (promiseCreated._trace) {
  2220. var traceLines = promiseCreated._trace.stack.split("\n");
  2221. var stack = cleanStack(traceLines);
  2222. for (var i = stack.length - 1; i >= 0; --i) {
  2223. var line = stack[i];
  2224. if (!nodeFramePattern.test(line)) {
  2225. var lineMatches = line.match(parseLinePattern);
  2226. if (lineMatches) {
  2227. handlerLine = "at " + lineMatches[1] +
  2228. ":" + lineMatches[2] + ":" + lineMatches[3] + " ";
  2229. }
  2230. break;
  2231. }
  2232. }
  2233. if (stack.length > 0) {
  2234. var firstUserLine = stack[0];
  2235. for (var i = 0; i < traceLines.length; ++i) {
  2236. if (traceLines[i] === firstUserLine) {
  2237. if (i > 0) {
  2238. creatorLine = "\n" + traceLines[i - 1];
  2239. }
  2240. break;
  2241. }
  2242. }
  2243. }
  2244. }
  2245. var msg = "a promise was created in a " + name +
  2246. "handler " + handlerLine + "but was not returned from it, " +
  2247. "see http://goo.gl/rRqMUw" +
  2248. creatorLine;
  2249. promise._warn(msg, true, promiseCreated);
  2250. }
  2251. }
  2252. function deprecated(name, replacement) {
  2253. var message = name +
  2254. " is deprecated and will be removed in a future version.";
  2255. if (replacement) message += " Use " + replacement + " instead.";
  2256. return warn(message);
  2257. }
  2258. function warn(message, shouldUseOwnTrace, promise) {
  2259. if (!config.warnings) return;
  2260. var warning = new Warning(message);
  2261. var ctx;
  2262. if (shouldUseOwnTrace) {
  2263. promise._attachExtraTrace(warning);
  2264. } else if (config.longStackTraces && (ctx = Promise._peekContext())) {
  2265. ctx.attachExtraTrace(warning);
  2266. } else {
  2267. var parsed = parseStackAndMessage(warning);
  2268. warning.stack = parsed.message + "\n" + parsed.stack.join("\n");
  2269. }
  2270. if (!activeFireEvent("warning", warning)) {
  2271. formatAndLogError(warning, "", true);
  2272. }
  2273. }
  2274. function reconstructStack(message, stacks) {
  2275. for (var i = 0; i < stacks.length - 1; ++i) {
  2276. stacks[i].push("From previous event:");
  2277. stacks[i] = stacks[i].join("\n");
  2278. }
  2279. if (i < stacks.length) {
  2280. stacks[i] = stacks[i].join("\n");
  2281. }
  2282. return message + "\n" + stacks.join("\n");
  2283. }
  2284. function removeDuplicateOrEmptyJumps(stacks) {
  2285. for (var i = 0; i < stacks.length; ++i) {
  2286. if (stacks[i].length === 0 ||
  2287. ((i + 1 < stacks.length) && stacks[i][0] === stacks[i+1][0])) {
  2288. stacks.splice(i, 1);
  2289. i--;
  2290. }
  2291. }
  2292. }
  2293. function removeCommonRoots(stacks) {
  2294. var current = stacks[0];
  2295. for (var i = 1; i < stacks.length; ++i) {
  2296. var prev = stacks[i];
  2297. var currentLastIndex = current.length - 1;
  2298. var currentLastLine = current[currentLastIndex];
  2299. var commonRootMeetPoint = -1;
  2300. for (var j = prev.length - 1; j >= 0; --j) {
  2301. if (prev[j] === currentLastLine) {
  2302. commonRootMeetPoint = j;
  2303. break;
  2304. }
  2305. }
  2306. for (var j = commonRootMeetPoint; j >= 0; --j) {
  2307. var line = prev[j];
  2308. if (current[currentLastIndex] === line) {
  2309. current.pop();
  2310. currentLastIndex--;
  2311. } else {
  2312. break;
  2313. }
  2314. }
  2315. current = prev;
  2316. }
  2317. }
  2318. function cleanStack(stack) {
  2319. var ret = [];
  2320. for (var i = 0; i < stack.length; ++i) {
  2321. var line = stack[i];
  2322. var isTraceLine = " (No stack trace)" === line ||
  2323. stackFramePattern.test(line);
  2324. var isInternalFrame = isTraceLine && shouldIgnore(line);
  2325. if (isTraceLine && !isInternalFrame) {
  2326. if (indentStackFrames && line.charAt(0) !== " ") {
  2327. line = " " + line;
  2328. }
  2329. ret.push(line);
  2330. }
  2331. }
  2332. return ret;
  2333. }
  2334. function stackFramesAsArray(error) {
  2335. var stack = error.stack.replace(/\s+$/g, "").split("\n");
  2336. for (var i = 0; i < stack.length; ++i) {
  2337. var line = stack[i];
  2338. if (" (No stack trace)" === line || stackFramePattern.test(line)) {
  2339. break;
  2340. }
  2341. }
  2342. if (i > 0) {
  2343. stack = stack.slice(i);
  2344. }
  2345. return stack;
  2346. }
  2347. function parseStackAndMessage(error) {
  2348. var stack = error.stack;
  2349. var message = error.toString();
  2350. stack = typeof stack === "string" && stack.length > 0
  2351. ? stackFramesAsArray(error) : [" (No stack trace)"];
  2352. return {
  2353. message: message,
  2354. stack: cleanStack(stack)
  2355. };
  2356. }
  2357. function formatAndLogError(error, title, isSoft) {
  2358. if (typeof console !== "undefined") {
  2359. var message;
  2360. if (util.isObject(error)) {
  2361. var stack = error.stack;
  2362. message = title + formatStack(stack, error);
  2363. } else {
  2364. message = title + String(error);
  2365. }
  2366. if (typeof printWarning === "function") {
  2367. printWarning(message, isSoft);
  2368. } else if (typeof console.log === "function" ||
  2369. typeof console.log === "object") {
  2370. console.log(message);
  2371. }
  2372. }
  2373. }
  2374. function fireRejectionEvent(name, localHandler, reason, promise) {
  2375. var localEventFired = false;
  2376. try {
  2377. if (typeof localHandler === "function") {
  2378. localEventFired = true;
  2379. if (name === "rejectionHandled") {
  2380. localHandler(promise);
  2381. } else {
  2382. localHandler(reason, promise);
  2383. }
  2384. }
  2385. } catch (e) {
  2386. async.throwLater(e);
  2387. }
  2388. if (name === "unhandledRejection") {
  2389. if (!activeFireEvent(name, reason, promise) && !localEventFired) {
  2390. formatAndLogError(reason, "Unhandled rejection ");
  2391. }
  2392. } else {
  2393. activeFireEvent(name, promise);
  2394. }
  2395. }
  2396. function formatNonError(obj) {
  2397. var str;
  2398. if (typeof obj === "function") {
  2399. str = "[function " +
  2400. (obj.name || "anonymous") +
  2401. "]";
  2402. } else {
  2403. str = obj && typeof obj.toString === "function"
  2404. ? obj.toString() : util.toString(obj);
  2405. var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/;
  2406. if (ruselessToString.test(str)) {
  2407. try {
  2408. var newStr = JSON.stringify(obj);
  2409. str = newStr;
  2410. }
  2411. catch(e) {
  2412. }
  2413. }
  2414. if (str.length === 0) {
  2415. str = "(empty array)";
  2416. }
  2417. }
  2418. return ("(<" + snip(str) + ">, no stack trace)");
  2419. }
  2420. function snip(str) {
  2421. var maxChars = 41;
  2422. if (str.length < maxChars) {
  2423. return str;
  2424. }
  2425. return str.substr(0, maxChars - 3) + "...";
  2426. }
  2427. function longStackTracesIsSupported() {
  2428. return typeof captureStackTrace === "function";
  2429. }
  2430. var shouldIgnore = function() { return false; };
  2431. var parseLineInfoRegex = /[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;
  2432. function parseLineInfo(line) {
  2433. var matches = line.match(parseLineInfoRegex);
  2434. if (matches) {
  2435. return {
  2436. fileName: matches[1],
  2437. line: parseInt(matches[2], 10)
  2438. };
  2439. }
  2440. }
  2441. function setBounds(firstLineError, lastLineError) {
  2442. if (!longStackTracesIsSupported()) return;
  2443. var firstStackLines = firstLineError.stack.split("\n");
  2444. var lastStackLines = lastLineError.stack.split("\n");
  2445. var firstIndex = -1;
  2446. var lastIndex = -1;
  2447. var firstFileName;
  2448. var lastFileName;
  2449. for (var i = 0; i < firstStackLines.length; ++i) {
  2450. var result = parseLineInfo(firstStackLines[i]);
  2451. if (result) {
  2452. firstFileName = result.fileName;
  2453. firstIndex = result.line;
  2454. break;
  2455. }
  2456. }
  2457. for (var i = 0; i < lastStackLines.length; ++i) {
  2458. var result = parseLineInfo(lastStackLines[i]);
  2459. if (result) {
  2460. lastFileName = result.fileName;
  2461. lastIndex = result.line;
  2462. break;
  2463. }
  2464. }
  2465. if (firstIndex < 0 || lastIndex < 0 || !firstFileName || !lastFileName ||
  2466. firstFileName !== lastFileName || firstIndex >= lastIndex) {
  2467. return;
  2468. }
  2469. shouldIgnore = function(line) {
  2470. if (bluebirdFramePattern.test(line)) return true;
  2471. var info = parseLineInfo(line);
  2472. if (info) {
  2473. if (info.fileName === firstFileName &&
  2474. (firstIndex <= info.line && info.line <= lastIndex)) {
  2475. return true;
  2476. }
  2477. }
  2478. return false;
  2479. };
  2480. }
  2481. function CapturedTrace(parent) {
  2482. this._parent = parent;
  2483. this._promisesCreated = 0;
  2484. var length = this._length = 1 + (parent === undefined ? 0 : parent._length);
  2485. captureStackTrace(this, CapturedTrace);
  2486. if (length > 32) this.uncycle();
  2487. }
  2488. util.inherits(CapturedTrace, Error);
  2489. Context.CapturedTrace = CapturedTrace;
  2490. CapturedTrace.prototype.uncycle = function() {
  2491. var length = this._length;
  2492. if (length < 2) return;
  2493. var nodes = [];
  2494. var stackToIndex = {};
  2495. for (var i = 0, node = this; node !== undefined; ++i) {
  2496. nodes.push(node);
  2497. node = node._parent;
  2498. }
  2499. length = this._length = i;
  2500. for (var i = length - 1; i >= 0; --i) {
  2501. var stack = nodes[i].stack;
  2502. if (stackToIndex[stack] === undefined) {
  2503. stackToIndex[stack] = i;
  2504. }
  2505. }
  2506. for (var i = 0; i < length; ++i) {
  2507. var currentStack = nodes[i].stack;
  2508. var index = stackToIndex[currentStack];
  2509. if (index !== undefined && index !== i) {
  2510. if (index > 0) {
  2511. nodes[index - 1]._parent = undefined;
  2512. nodes[index - 1]._length = 1;
  2513. }
  2514. nodes[i]._parent = undefined;
  2515. nodes[i]._length = 1;
  2516. var cycleEdgeNode = i > 0 ? nodes[i - 1] : this;
  2517. if (index < length - 1) {
  2518. cycleEdgeNode._parent = nodes[index + 1];
  2519. cycleEdgeNode._parent.uncycle();
  2520. cycleEdgeNode._length =
  2521. cycleEdgeNode._parent._length + 1;
  2522. } else {
  2523. cycleEdgeNode._parent = undefined;
  2524. cycleEdgeNode._length = 1;
  2525. }
  2526. var currentChildLength = cycleEdgeNode._length + 1;
  2527. for (var j = i - 2; j >= 0; --j) {
  2528. nodes[j]._length = currentChildLength;
  2529. currentChildLength++;
  2530. }
  2531. return;
  2532. }
  2533. }
  2534. };
  2535. CapturedTrace.prototype.attachExtraTrace = function(error) {
  2536. if (error.__stackCleaned__) return;
  2537. this.uncycle();
  2538. var parsed = parseStackAndMessage(error);
  2539. var message = parsed.message;
  2540. var stacks = [parsed.stack];
  2541. var trace = this;
  2542. while (trace !== undefined) {
  2543. stacks.push(cleanStack(trace.stack.split("\n")));
  2544. trace = trace._parent;
  2545. }
  2546. removeCommonRoots(stacks);
  2547. removeDuplicateOrEmptyJumps(stacks);
  2548. util.notEnumerableProp(error, "stack", reconstructStack(message, stacks));
  2549. util.notEnumerableProp(error, "__stackCleaned__", true);
  2550. };
  2551. var captureStackTrace = (function stackDetection() {
  2552. var v8stackFramePattern = /^\s*at\s*/;
  2553. var v8stackFormatter = function(stack, error) {
  2554. if (typeof stack === "string") return stack;
  2555. if (error.name !== undefined &&
  2556. error.message !== undefined) {
  2557. return error.toString();
  2558. }
  2559. return formatNonError(error);
  2560. };
  2561. if (typeof Error.stackTraceLimit === "number" &&
  2562. typeof Error.captureStackTrace === "function") {
  2563. Error.stackTraceLimit += 6;
  2564. stackFramePattern = v8stackFramePattern;
  2565. formatStack = v8stackFormatter;
  2566. var captureStackTrace = Error.captureStackTrace;
  2567. shouldIgnore = function(line) {
  2568. return bluebirdFramePattern.test(line);
  2569. };
  2570. return function(receiver, ignoreUntil) {
  2571. Error.stackTraceLimit += 6;
  2572. captureStackTrace(receiver, ignoreUntil);
  2573. Error.stackTraceLimit -= 6;
  2574. };
  2575. }
  2576. var err = new Error();
  2577. if (typeof err.stack === "string" &&
  2578. err.stack.split("\n")[0].indexOf("stackDetection@") >= 0) {
  2579. stackFramePattern = /@/;
  2580. formatStack = v8stackFormatter;
  2581. indentStackFrames = true;
  2582. return function captureStackTrace(o) {
  2583. o.stack = new Error().stack;
  2584. };
  2585. }
  2586. var hasStackAfterThrow;
  2587. try { throw new Error(); }
  2588. catch(e) {
  2589. hasStackAfterThrow = ("stack" in e);
  2590. }
  2591. if (!("stack" in err) && hasStackAfterThrow &&
  2592. typeof Error.stackTraceLimit === "number") {
  2593. stackFramePattern = v8stackFramePattern;
  2594. formatStack = v8stackFormatter;
  2595. return function captureStackTrace(o) {
  2596. Error.stackTraceLimit += 6;
  2597. try { throw new Error(); }
  2598. catch(e) { o.stack = e.stack; }
  2599. Error.stackTraceLimit -= 6;
  2600. };
  2601. }
  2602. formatStack = function(stack, error) {
  2603. if (typeof stack === "string") return stack;
  2604. if ((typeof error === "object" ||
  2605. typeof error === "function") &&
  2606. error.name !== undefined &&
  2607. error.message !== undefined) {
  2608. return error.toString();
  2609. }
  2610. return formatNonError(error);
  2611. };
  2612. return null;
  2613. })([]);
  2614. if (typeof console !== "undefined" && typeof console.warn !== "undefined") {
  2615. printWarning = function (message) {
  2616. console.warn(message);
  2617. };
  2618. if (util.isNode && process.stderr.isTTY) {
  2619. printWarning = function(message, isSoft) {
  2620. var color = isSoft ? "\u001b[33m" : "\u001b[31m";
  2621. console.warn(color + message + "\u001b[0m\n");
  2622. };
  2623. } else if (!util.isNode && typeof (new Error().stack) === "string") {
  2624. printWarning = function(message, isSoft) {
  2625. console.warn("%c" + message,
  2626. isSoft ? "color: darkorange" : "color: red");
  2627. };
  2628. }
  2629. }
  2630. var config = {
  2631. warnings: warnings,
  2632. longStackTraces: false,
  2633. cancellation: false,
  2634. monitoring: false
  2635. };
  2636. if (longStackTraces) Promise.longStackTraces();
  2637. return {
  2638. longStackTraces: function() {
  2639. return config.longStackTraces;
  2640. },
  2641. warnings: function() {
  2642. return config.warnings;
  2643. },
  2644. cancellation: function() {
  2645. return config.cancellation;
  2646. },
  2647. monitoring: function() {
  2648. return config.monitoring;
  2649. },
  2650. propagateFromFunction: function() {
  2651. return propagateFromFunction;
  2652. },
  2653. boundValueFunction: function() {
  2654. return boundValueFunction;
  2655. },
  2656. checkForgottenReturns: checkForgottenReturns,
  2657. setBounds: setBounds,
  2658. warn: warn,
  2659. deprecated: deprecated,
  2660. CapturedTrace: CapturedTrace,
  2661. fireDomEvent: fireDomEvent,
  2662. fireGlobalEvent: fireGlobalEvent
  2663. };
  2664. };
  2665. },{"./errors":12,"./util":36}],10:[function(_dereq_,module,exports){
  2666. "use strict";
  2667. module.exports = function(Promise) {
  2668. function returner() {
  2669. return this.value;
  2670. }
  2671. function thrower() {
  2672. throw this.reason;
  2673. }
  2674. Promise.prototype["return"] =
  2675. Promise.prototype.thenReturn = function (value) {
  2676. if (value instanceof Promise) value.suppressUnhandledRejections();
  2677. return this._then(
  2678. returner, undefined, undefined, {value: value}, undefined);
  2679. };
  2680. Promise.prototype["throw"] =
  2681. Promise.prototype.thenThrow = function (reason) {
  2682. return this._then(
  2683. thrower, undefined, undefined, {reason: reason}, undefined);
  2684. };
  2685. Promise.prototype.catchThrow = function (reason) {
  2686. if (arguments.length <= 1) {
  2687. return this._then(
  2688. undefined, thrower, undefined, {reason: reason}, undefined);
  2689. } else {
  2690. var _reason = arguments[1];
  2691. var handler = function() {throw _reason;};
  2692. return this.caught(reason, handler);
  2693. }
  2694. };
  2695. Promise.prototype.catchReturn = function (value) {
  2696. if (arguments.length <= 1) {
  2697. if (value instanceof Promise) value.suppressUnhandledRejections();
  2698. return this._then(
  2699. undefined, returner, undefined, {value: value}, undefined);
  2700. } else {
  2701. var _value = arguments[1];
  2702. if (_value instanceof Promise) _value.suppressUnhandledRejections();
  2703. var handler = function() {return _value;};
  2704. return this.caught(value, handler);
  2705. }
  2706. };
  2707. };
  2708. },{}],11:[function(_dereq_,module,exports){
  2709. "use strict";
  2710. module.exports = function(Promise, INTERNAL) {
  2711. var PromiseReduce = Promise.reduce;
  2712. var PromiseAll = Promise.all;
  2713. function promiseAllThis() {
  2714. return PromiseAll(this);
  2715. }
  2716. function PromiseMapSeries(promises, fn) {
  2717. return PromiseReduce(promises, fn, INTERNAL, INTERNAL);
  2718. }
  2719. Promise.prototype.each = function (fn) {
  2720. return PromiseReduce(this, fn, INTERNAL, 0)
  2721. ._then(promiseAllThis, undefined, undefined, this, undefined);
  2722. };
  2723. Promise.prototype.mapSeries = function (fn) {
  2724. return PromiseReduce(this, fn, INTERNAL, INTERNAL);
  2725. };
  2726. Promise.each = function (promises, fn) {
  2727. return PromiseReduce(promises, fn, INTERNAL, 0)
  2728. ._then(promiseAllThis, undefined, undefined, promises, undefined);
  2729. };
  2730. Promise.mapSeries = PromiseMapSeries;
  2731. };
  2732. },{}],12:[function(_dereq_,module,exports){
  2733. "use strict";
  2734. var es5 = _dereq_("./es5");
  2735. var Objectfreeze = es5.freeze;
  2736. var util = _dereq_("./util");
  2737. var inherits = util.inherits;
  2738. var notEnumerableProp = util.notEnumerableProp;
  2739. function subError(nameProperty, defaultMessage) {
  2740. function SubError(message) {
  2741. if (!(this instanceof SubError)) return new SubError(message);
  2742. notEnumerableProp(this, "message",
  2743. typeof message === "string" ? message : defaultMessage);
  2744. notEnumerableProp(this, "name", nameProperty);
  2745. if (Error.captureStackTrace) {
  2746. Error.captureStackTrace(this, this.constructor);
  2747. } else {
  2748. Error.call(this);
  2749. }
  2750. }
  2751. inherits(SubError, Error);
  2752. return SubError;
  2753. }
  2754. var _TypeError, _RangeError;
  2755. var Warning = subError("Warning", "warning");
  2756. var CancellationError = subError("CancellationError", "cancellation error");
  2757. var TimeoutError = subError("TimeoutError", "timeout error");
  2758. var AggregateError = subError("AggregateError", "aggregate error");
  2759. try {
  2760. _TypeError = TypeError;
  2761. _RangeError = RangeError;
  2762. } catch(e) {
  2763. _TypeError = subError("TypeError", "type error");
  2764. _RangeError = subError("RangeError", "range error");
  2765. }
  2766. var methods = ("join pop push shift unshift slice filter forEach some " +
  2767. "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" ");
  2768. for (var i = 0; i < methods.length; ++i) {
  2769. if (typeof Array.prototype[methods[i]] === "function") {
  2770. AggregateError.prototype[methods[i]] = Array.prototype[methods[i]];
  2771. }
  2772. }
  2773. es5.defineProperty(AggregateError.prototype, "length", {
  2774. value: 0,
  2775. configurable: false,
  2776. writable: true,
  2777. enumerable: true
  2778. });
  2779. AggregateError.prototype["isOperational"] = true;
  2780. var level = 0;
  2781. AggregateError.prototype.toString = function() {
  2782. var indent = Array(level * 4 + 1).join(" ");
  2783. var ret = "\n" + indent + "AggregateError of:" + "\n";
  2784. level++;
  2785. indent = Array(level * 4 + 1).join(" ");
  2786. for (var i = 0; i < this.length; ++i) {
  2787. var str = this[i] === this ? "[Circular AggregateError]" : this[i] + "";
  2788. var lines = str.split("\n");
  2789. for (var j = 0; j < lines.length; ++j) {
  2790. lines[j] = indent + lines[j];
  2791. }
  2792. str = lines.join("\n");
  2793. ret += str + "\n";
  2794. }
  2795. level--;
  2796. return ret;
  2797. };
  2798. function OperationalError(message) {
  2799. if (!(this instanceof OperationalError))
  2800. return new OperationalError(message);
  2801. notEnumerableProp(this, "name", "OperationalError");
  2802. notEnumerableProp(this, "message", message);
  2803. this.cause = message;
  2804. this["isOperational"] = true;
  2805. if (message instanceof Error) {
  2806. notEnumerableProp(this, "message", message.message);
  2807. notEnumerableProp(this, "stack", message.stack);
  2808. } else if (Error.captureStackTrace) {
  2809. Error.captureStackTrace(this, this.constructor);
  2810. }
  2811. }
  2812. inherits(OperationalError, Error);
  2813. var errorTypes = Error["__BluebirdErrorTypes__"];
  2814. if (!errorTypes) {
  2815. errorTypes = Objectfreeze({
  2816. CancellationError: CancellationError,
  2817. TimeoutError: TimeoutError,
  2818. OperationalError: OperationalError,
  2819. RejectionError: OperationalError,
  2820. AggregateError: AggregateError
  2821. });
  2822. es5.defineProperty(Error, "__BluebirdErrorTypes__", {
  2823. value: errorTypes,
  2824. writable: false,
  2825. enumerable: false,
  2826. configurable: false
  2827. });
  2828. }
  2829. module.exports = {
  2830. Error: Error,
  2831. TypeError: _TypeError,
  2832. RangeError: _RangeError,
  2833. CancellationError: errorTypes.CancellationError,
  2834. OperationalError: errorTypes.OperationalError,
  2835. TimeoutError: errorTypes.TimeoutError,
  2836. AggregateError: errorTypes.AggregateError,
  2837. Warning: Warning
  2838. };
  2839. },{"./es5":13,"./util":36}],13:[function(_dereq_,module,exports){
  2840. var isES5 = (function(){
  2841. "use strict";
  2842. return this === undefined;
  2843. })();
  2844. if (isES5) {
  2845. module.exports = {
  2846. freeze: Object.freeze,
  2847. defineProperty: Object.defineProperty,
  2848. getDescriptor: Object.getOwnPropertyDescriptor,
  2849. keys: Object.keys,
  2850. names: Object.getOwnPropertyNames,
  2851. getPrototypeOf: Object.getPrototypeOf,
  2852. isArray: Array.isArray,
  2853. isES5: isES5,
  2854. propertyIsWritable: function(obj, prop) {
  2855. var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
  2856. return !!(!descriptor || descriptor.writable || descriptor.set);
  2857. }
  2858. };
  2859. } else {
  2860. var has = {}.hasOwnProperty;
  2861. var str = {}.toString;
  2862. var proto = {}.constructor.prototype;
  2863. var ObjectKeys = function (o) {
  2864. var ret = [];
  2865. for (var key in o) {
  2866. if (has.call(o, key)) {
  2867. ret.push(key);
  2868. }
  2869. }
  2870. return ret;
  2871. };
  2872. var ObjectGetDescriptor = function(o, key) {
  2873. return {value: o[key]};
  2874. };
  2875. var ObjectDefineProperty = function (o, key, desc) {
  2876. o[key] = desc.value;
  2877. return o;
  2878. };
  2879. var ObjectFreeze = function (obj) {
  2880. return obj;
  2881. };
  2882. var ObjectGetPrototypeOf = function (obj) {
  2883. try {
  2884. return Object(obj).constructor.prototype;
  2885. }
  2886. catch (e) {
  2887. return proto;
  2888. }
  2889. };
  2890. var ArrayIsArray = function (obj) {
  2891. try {
  2892. return str.call(obj) === "[object Array]";
  2893. }
  2894. catch(e) {
  2895. return false;
  2896. }
  2897. };
  2898. module.exports = {
  2899. isArray: ArrayIsArray,
  2900. keys: ObjectKeys,
  2901. names: ObjectKeys,
  2902. defineProperty: ObjectDefineProperty,
  2903. getDescriptor: ObjectGetDescriptor,
  2904. freeze: ObjectFreeze,
  2905. getPrototypeOf: ObjectGetPrototypeOf,
  2906. isES5: isES5,
  2907. propertyIsWritable: function() {
  2908. return true;
  2909. }
  2910. };
  2911. }
  2912. },{}],14:[function(_dereq_,module,exports){
  2913. "use strict";
  2914. module.exports = function(Promise, INTERNAL) {
  2915. var PromiseMap = Promise.map;
  2916. Promise.prototype.filter = function (fn, options) {
  2917. return PromiseMap(this, fn, options, INTERNAL);
  2918. };
  2919. Promise.filter = function (promises, fn, options) {
  2920. return PromiseMap(promises, fn, options, INTERNAL);
  2921. };
  2922. };
  2923. },{}],15:[function(_dereq_,module,exports){
  2924. "use strict";
  2925. module.exports = function(Promise, tryConvertToPromise) {
  2926. var util = _dereq_("./util");
  2927. var CancellationError = Promise.CancellationError;
  2928. var errorObj = util.errorObj;
  2929. function PassThroughHandlerContext(promise, type, handler) {
  2930. this.promise = promise;
  2931. this.type = type;
  2932. this.handler = handler;
  2933. this.called = false;
  2934. this.cancelPromise = null;
  2935. }
  2936. PassThroughHandlerContext.prototype.isFinallyHandler = function() {
  2937. return this.type === 0;
  2938. };
  2939. function FinallyHandlerCancelReaction(finallyHandler) {
  2940. this.finallyHandler = finallyHandler;
  2941. }
  2942. FinallyHandlerCancelReaction.prototype._resultCancelled = function() {
  2943. checkCancel(this.finallyHandler);
  2944. };
  2945. function checkCancel(ctx, reason) {
  2946. if (ctx.cancelPromise != null) {
  2947. if (arguments.length > 1) {
  2948. ctx.cancelPromise._reject(reason);
  2949. } else {
  2950. ctx.cancelPromise._cancel();
  2951. }
  2952. ctx.cancelPromise = null;
  2953. return true;
  2954. }
  2955. return false;
  2956. }
  2957. function succeed() {
  2958. return finallyHandler.call(this, this.promise._target()._settledValue());
  2959. }
  2960. function fail(reason) {
  2961. if (checkCancel(this, reason)) return;
  2962. errorObj.e = reason;
  2963. return errorObj;
  2964. }
  2965. function finallyHandler(reasonOrValue) {
  2966. var promise = this.promise;
  2967. var handler = this.handler;
  2968. if (!this.called) {
  2969. this.called = true;
  2970. var ret = this.isFinallyHandler()
  2971. ? handler.call(promise._boundValue())
  2972. : handler.call(promise._boundValue(), reasonOrValue);
  2973. if (ret !== undefined) {
  2974. promise._setReturnedNonUndefined();
  2975. var maybePromise = tryConvertToPromise(ret, promise);
  2976. if (maybePromise instanceof Promise) {
  2977. if (this.cancelPromise != null) {
  2978. if (maybePromise._isCancelled()) {
  2979. var reason =
  2980. new CancellationError("late cancellation observer");
  2981. promise._attachExtraTrace(reason);
  2982. errorObj.e = reason;
  2983. return errorObj;
  2984. } else if (maybePromise.isPending()) {
  2985. maybePromise._attachCancellationCallback(
  2986. new FinallyHandlerCancelReaction(this));
  2987. }
  2988. }
  2989. return maybePromise._then(
  2990. succeed, fail, undefined, this, undefined);
  2991. }
  2992. }
  2993. }
  2994. if (promise.isRejected()) {
  2995. checkCancel(this);
  2996. errorObj.e = reasonOrValue;
  2997. return errorObj;
  2998. } else {
  2999. checkCancel(this);
  3000. return reasonOrValue;
  3001. }
  3002. }
  3003. Promise.prototype._passThrough = function(handler, type, success, fail) {
  3004. if (typeof handler !== "function") return this.then();
  3005. return this._then(success,
  3006. fail,
  3007. undefined,
  3008. new PassThroughHandlerContext(this, type, handler),
  3009. undefined);
  3010. };
  3011. Promise.prototype.lastly =
  3012. Promise.prototype["finally"] = function (handler) {
  3013. return this._passThrough(handler,
  3014. 0,
  3015. finallyHandler,
  3016. finallyHandler);
  3017. };
  3018. Promise.prototype.tap = function (handler) {
  3019. return this._passThrough(handler, 1, finallyHandler);
  3020. };
  3021. return PassThroughHandlerContext;
  3022. };
  3023. },{"./util":36}],16:[function(_dereq_,module,exports){
  3024. "use strict";
  3025. module.exports = function(Promise,
  3026. apiRejection,
  3027. INTERNAL,
  3028. tryConvertToPromise,
  3029. Proxyable,
  3030. debug) {
  3031. var errors = _dereq_("./errors");
  3032. var TypeError = errors.TypeError;
  3033. var util = _dereq_("./util");
  3034. var errorObj = util.errorObj;
  3035. var tryCatch = util.tryCatch;
  3036. var yieldHandlers = [];
  3037. function promiseFromYieldHandler(value, yieldHandlers, traceParent) {
  3038. for (var i = 0; i < yieldHandlers.length; ++i) {
  3039. traceParent._pushContext();
  3040. var result = tryCatch(yieldHandlers[i])(value);
  3041. traceParent._popContext();
  3042. if (result === errorObj) {
  3043. traceParent._pushContext();
  3044. var ret = Promise.reject(errorObj.e);
  3045. traceParent._popContext();
  3046. return ret;
  3047. }
  3048. var maybePromise = tryConvertToPromise(result, traceParent);
  3049. if (maybePromise instanceof Promise) return maybePromise;
  3050. }
  3051. return null;
  3052. }
  3053. function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) {
  3054. if (debug.cancellation()) {
  3055. var internal = new Promise(INTERNAL);
  3056. var _finallyPromise = this._finallyPromise = new Promise(INTERNAL);
  3057. this._promise = internal.lastly(function() {
  3058. return _finallyPromise;
  3059. });
  3060. internal._captureStackTrace();
  3061. internal._setOnCancel(this);
  3062. } else {
  3063. var promise = this._promise = new Promise(INTERNAL);
  3064. promise._captureStackTrace();
  3065. }
  3066. this._stack = stack;
  3067. this._generatorFunction = generatorFunction;
  3068. this._receiver = receiver;
  3069. this._generator = undefined;
  3070. this._yieldHandlers = typeof yieldHandler === "function"
  3071. ? [yieldHandler].concat(yieldHandlers)
  3072. : yieldHandlers;
  3073. this._yieldedPromise = null;
  3074. this._cancellationPhase = false;
  3075. }
  3076. util.inherits(PromiseSpawn, Proxyable);
  3077. PromiseSpawn.prototype._isResolved = function() {
  3078. return this._promise === null;
  3079. };
  3080. PromiseSpawn.prototype._cleanup = function() {
  3081. this._promise = this._generator = null;
  3082. if (debug.cancellation() && this._finallyPromise !== null) {
  3083. this._finallyPromise._fulfill();
  3084. this._finallyPromise = null;
  3085. }
  3086. };
  3087. PromiseSpawn.prototype._promiseCancelled = function() {
  3088. if (this._isResolved()) return;
  3089. var implementsReturn = typeof this._generator["return"] !== "undefined";
  3090. var result;
  3091. if (!implementsReturn) {
  3092. var reason = new Promise.CancellationError(
  3093. "generator .return() sentinel");
  3094. Promise.coroutine.returnSentinel = reason;
  3095. this._promise._attachExtraTrace(reason);
  3096. this._promise._pushContext();
  3097. result = tryCatch(this._generator["throw"]).call(this._generator,
  3098. reason);
  3099. this._promise._popContext();
  3100. } else {
  3101. this._promise._pushContext();
  3102. result = tryCatch(this._generator["return"]).call(this._generator,
  3103. undefined);
  3104. this._promise._popContext();
  3105. }
  3106. this._cancellationPhase = true;
  3107. this._yieldedPromise = null;
  3108. this._continue(result);
  3109. };
  3110. PromiseSpawn.prototype._promiseFulfilled = function(value) {
  3111. this._yieldedPromise = null;
  3112. this._promise._pushContext();
  3113. var result = tryCatch(this._generator.next).call(this._generator, value);
  3114. this._promise._popContext();
  3115. this._continue(result);
  3116. };
  3117. PromiseSpawn.prototype._promiseRejected = function(reason) {
  3118. this._yieldedPromise = null;
  3119. this._promise._attachExtraTrace(reason);
  3120. this._promise._pushContext();
  3121. var result = tryCatch(this._generator["throw"])
  3122. .call(this._generator, reason);
  3123. this._promise._popContext();
  3124. this._continue(result);
  3125. };
  3126. PromiseSpawn.prototype._resultCancelled = function() {
  3127. if (this._yieldedPromise instanceof Promise) {
  3128. var promise = this._yieldedPromise;
  3129. this._yieldedPromise = null;
  3130. promise.cancel();
  3131. }
  3132. };
  3133. PromiseSpawn.prototype.promise = function () {
  3134. return this._promise;
  3135. };
  3136. PromiseSpawn.prototype._run = function () {
  3137. this._generator = this._generatorFunction.call(this._receiver);
  3138. this._receiver =
  3139. this._generatorFunction = undefined;
  3140. this._promiseFulfilled(undefined);
  3141. };
  3142. PromiseSpawn.prototype._continue = function (result) {
  3143. var promise = this._promise;
  3144. if (result === errorObj) {
  3145. this._cleanup();
  3146. if (this._cancellationPhase) {
  3147. return promise.cancel();
  3148. } else {
  3149. return promise._rejectCallback(result.e, false);
  3150. }
  3151. }
  3152. var value = result.value;
  3153. if (result.done === true) {
  3154. this._cleanup();
  3155. if (this._cancellationPhase) {
  3156. return promise.cancel();
  3157. } else {
  3158. return promise._resolveCallback(value);
  3159. }
  3160. } else {
  3161. var maybePromise = tryConvertToPromise(value, this._promise);
  3162. if (!(maybePromise instanceof Promise)) {
  3163. maybePromise =
  3164. promiseFromYieldHandler(maybePromise,
  3165. this._yieldHandlers,
  3166. this._promise);
  3167. if (maybePromise === null) {
  3168. this._promiseRejected(
  3169. new TypeError(
  3170. "A value %s was yielded that could not be treated as a promise\u000a\u000a See http://goo.gl/MqrFmX\u000a\u000a".replace("%s", value) +
  3171. "From coroutine:\u000a" +
  3172. this._stack.split("\n").slice(1, -7).join("\n")
  3173. )
  3174. );
  3175. return;
  3176. }
  3177. }
  3178. maybePromise = maybePromise._target();
  3179. var bitField = maybePromise._bitField;
  3180. ;
  3181. if (((bitField & 50397184) === 0)) {
  3182. this._yieldedPromise = maybePromise;
  3183. maybePromise._proxy(this, null);
  3184. } else if (((bitField & 33554432) !== 0)) {
  3185. Promise._async.invoke(
  3186. this._promiseFulfilled, this, maybePromise._value()
  3187. );
  3188. } else if (((bitField & 16777216) !== 0)) {
  3189. Promise._async.invoke(
  3190. this._promiseRejected, this, maybePromise._reason()
  3191. );
  3192. } else {
  3193. this._promiseCancelled();
  3194. }
  3195. }
  3196. };
  3197. Promise.coroutine = function (generatorFunction, options) {
  3198. if (typeof generatorFunction !== "function") {
  3199. throw new TypeError("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  3200. }
  3201. var yieldHandler = Object(options).yieldHandler;
  3202. var PromiseSpawn$ = PromiseSpawn;
  3203. var stack = new Error().stack;
  3204. return function () {
  3205. var generator = generatorFunction.apply(this, arguments);
  3206. var spawn = new PromiseSpawn$(undefined, undefined, yieldHandler,
  3207. stack);
  3208. var ret = spawn.promise();
  3209. spawn._generator = generator;
  3210. spawn._promiseFulfilled(undefined);
  3211. return ret;
  3212. };
  3213. };
  3214. Promise.coroutine.addYieldHandler = function(fn) {
  3215. if (typeof fn !== "function") {
  3216. throw new TypeError("expecting a function but got " + util.classString(fn));
  3217. }
  3218. yieldHandlers.push(fn);
  3219. };
  3220. Promise.spawn = function (generatorFunction) {
  3221. debug.deprecated("Promise.spawn()", "Promise.coroutine()");
  3222. if (typeof generatorFunction !== "function") {
  3223. return apiRejection("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  3224. }
  3225. var spawn = new PromiseSpawn(generatorFunction, this);
  3226. var ret = spawn.promise();
  3227. spawn._run(Promise.spawn);
  3228. return ret;
  3229. };
  3230. };
  3231. },{"./errors":12,"./util":36}],17:[function(_dereq_,module,exports){
  3232. "use strict";
  3233. module.exports =
  3234. function(Promise, PromiseArray, tryConvertToPromise, INTERNAL, async,
  3235. getDomain) {
  3236. var util = _dereq_("./util");
  3237. var canEvaluate = util.canEvaluate;
  3238. var tryCatch = util.tryCatch;
  3239. var errorObj = util.errorObj;
  3240. var reject;
  3241. if (!true) {
  3242. if (canEvaluate) {
  3243. var thenCallback = function(i) {
  3244. return new Function("value", "holder", " \n\
  3245. 'use strict'; \n\
  3246. holder.pIndex = value; \n\
  3247. holder.checkFulfillment(this); \n\
  3248. ".replace(/Index/g, i));
  3249. };
  3250. var promiseSetter = function(i) {
  3251. return new Function("promise", "holder", " \n\
  3252. 'use strict'; \n\
  3253. holder.pIndex = promise; \n\
  3254. ".replace(/Index/g, i));
  3255. };
  3256. var generateHolderClass = function(total) {
  3257. var props = new Array(total);
  3258. for (var i = 0; i < props.length; ++i) {
  3259. props[i] = "this.p" + (i+1);
  3260. }
  3261. var assignment = props.join(" = ") + " = null;";
  3262. var cancellationCode= "var promise;\n" + props.map(function(prop) {
  3263. return " \n\
  3264. promise = " + prop + "; \n\
  3265. if (promise instanceof Promise) { \n\
  3266. promise.cancel(); \n\
  3267. } \n\
  3268. ";
  3269. }).join("\n");
  3270. var passedArguments = props.join(", ");
  3271. var name = "Holder$" + total;
  3272. var code = "return function(tryCatch, errorObj, Promise, async) { \n\
  3273. 'use strict'; \n\
  3274. function [TheName](fn) { \n\
  3275. [TheProperties] \n\
  3276. this.fn = fn; \n\
  3277. this.asyncNeeded = true; \n\
  3278. this.now = 0; \n\
  3279. } \n\
  3280. \n\
  3281. [TheName].prototype._callFunction = function(promise) { \n\
  3282. promise._pushContext(); \n\
  3283. var ret = tryCatch(this.fn)([ThePassedArguments]); \n\
  3284. promise._popContext(); \n\
  3285. if (ret === errorObj) { \n\
  3286. promise._rejectCallback(ret.e, false); \n\
  3287. } else { \n\
  3288. promise._resolveCallback(ret); \n\
  3289. } \n\
  3290. }; \n\
  3291. \n\
  3292. [TheName].prototype.checkFulfillment = function(promise) { \n\
  3293. var now = ++this.now; \n\
  3294. if (now === [TheTotal]) { \n\
  3295. if (this.asyncNeeded) { \n\
  3296. async.invoke(this._callFunction, this, promise); \n\
  3297. } else { \n\
  3298. this._callFunction(promise); \n\
  3299. } \n\
  3300. \n\
  3301. } \n\
  3302. }; \n\
  3303. \n\
  3304. [TheName].prototype._resultCancelled = function() { \n\
  3305. [CancellationCode] \n\
  3306. }; \n\
  3307. \n\
  3308. return [TheName]; \n\
  3309. }(tryCatch, errorObj, Promise, async); \n\
  3310. ";
  3311. code = code.replace(/\[TheName\]/g, name)
  3312. .replace(/\[TheTotal\]/g, total)
  3313. .replace(/\[ThePassedArguments\]/g, passedArguments)
  3314. .replace(/\[TheProperties\]/g, assignment)
  3315. .replace(/\[CancellationCode\]/g, cancellationCode);
  3316. return new Function("tryCatch", "errorObj", "Promise", "async", code)
  3317. (tryCatch, errorObj, Promise, async);
  3318. };
  3319. var holderClasses = [];
  3320. var thenCallbacks = [];
  3321. var promiseSetters = [];
  3322. for (var i = 0; i < 8; ++i) {
  3323. holderClasses.push(generateHolderClass(i + 1));
  3324. thenCallbacks.push(thenCallback(i + 1));
  3325. promiseSetters.push(promiseSetter(i + 1));
  3326. }
  3327. reject = function (reason) {
  3328. this._reject(reason);
  3329. };
  3330. }}
  3331. Promise.join = function () {
  3332. var last = arguments.length - 1;
  3333. var fn;
  3334. if (last > 0 && typeof arguments[last] === "function") {
  3335. fn = arguments[last];
  3336. if (!true) {
  3337. if (last <= 8 && canEvaluate) {
  3338. var ret = new Promise(INTERNAL);
  3339. ret._captureStackTrace();
  3340. var HolderClass = holderClasses[last - 1];
  3341. var holder = new HolderClass(fn);
  3342. var callbacks = thenCallbacks;
  3343. for (var i = 0; i < last; ++i) {
  3344. var maybePromise = tryConvertToPromise(arguments[i], ret);
  3345. if (maybePromise instanceof Promise) {
  3346. maybePromise = maybePromise._target();
  3347. var bitField = maybePromise._bitField;
  3348. ;
  3349. if (((bitField & 50397184) === 0)) {
  3350. maybePromise._then(callbacks[i], reject,
  3351. undefined, ret, holder);
  3352. promiseSetters[i](maybePromise, holder);
  3353. holder.asyncNeeded = false;
  3354. } else if (((bitField & 33554432) !== 0)) {
  3355. callbacks[i].call(ret,
  3356. maybePromise._value(), holder);
  3357. } else if (((bitField & 16777216) !== 0)) {
  3358. ret._reject(maybePromise._reason());
  3359. } else {
  3360. ret._cancel();
  3361. }
  3362. } else {
  3363. callbacks[i].call(ret, maybePromise, holder);
  3364. }
  3365. }
  3366. if (!ret._isFateSealed()) {
  3367. if (holder.asyncNeeded) {
  3368. var domain = getDomain();
  3369. if (domain !== null) {
  3370. holder.fn = util.domainBind(domain, holder.fn);
  3371. }
  3372. }
  3373. ret._setAsyncGuaranteed();
  3374. ret._setOnCancel(holder);
  3375. }
  3376. return ret;
  3377. }
  3378. }
  3379. }
  3380. var args = [].slice.call(arguments);;
  3381. if (fn) args.pop();
  3382. var ret = new PromiseArray(args).promise();
  3383. return fn !== undefined ? ret.spread(fn) : ret;
  3384. };
  3385. };
  3386. },{"./util":36}],18:[function(_dereq_,module,exports){
  3387. "use strict";
  3388. module.exports = function(Promise,
  3389. PromiseArray,
  3390. apiRejection,
  3391. tryConvertToPromise,
  3392. INTERNAL,
  3393. debug) {
  3394. var getDomain = Promise._getDomain;
  3395. var util = _dereq_("./util");
  3396. var tryCatch = util.tryCatch;
  3397. var errorObj = util.errorObj;
  3398. var async = Promise._async;
  3399. function MappingPromiseArray(promises, fn, limit, _filter) {
  3400. this.constructor$(promises);
  3401. this._promise._captureStackTrace();
  3402. var domain = getDomain();
  3403. this._callback = domain === null ? fn : util.domainBind(domain, fn);
  3404. this._preservedValues = _filter === INTERNAL
  3405. ? new Array(this.length())
  3406. : null;
  3407. this._limit = limit;
  3408. this._inFlight = 0;
  3409. this._queue = [];
  3410. async.invoke(this._asyncInit, this, undefined);
  3411. }
  3412. util.inherits(MappingPromiseArray, PromiseArray);
  3413. MappingPromiseArray.prototype._asyncInit = function() {
  3414. this._init$(undefined, -2);
  3415. };
  3416. MappingPromiseArray.prototype._init = function () {};
  3417. MappingPromiseArray.prototype._promiseFulfilled = function (value, index) {
  3418. var values = this._values;
  3419. var length = this.length();
  3420. var preservedValues = this._preservedValues;
  3421. var limit = this._limit;
  3422. if (index < 0) {
  3423. index = (index * -1) - 1;
  3424. values[index] = value;
  3425. if (limit >= 1) {
  3426. this._inFlight--;
  3427. this._drainQueue();
  3428. if (this._isResolved()) return true;
  3429. }
  3430. } else {
  3431. if (limit >= 1 && this._inFlight >= limit) {
  3432. values[index] = value;
  3433. this._queue.push(index);
  3434. return false;
  3435. }
  3436. if (preservedValues !== null) preservedValues[index] = value;
  3437. var promise = this._promise;
  3438. var callback = this._callback;
  3439. var receiver = promise._boundValue();
  3440. promise._pushContext();
  3441. var ret = tryCatch(callback).call(receiver, value, index, length);
  3442. var promiseCreated = promise._popContext();
  3443. debug.checkForgottenReturns(
  3444. ret,
  3445. promiseCreated,
  3446. preservedValues !== null ? "Promise.filter" : "Promise.map",
  3447. promise
  3448. );
  3449. if (ret === errorObj) {
  3450. this._reject(ret.e);
  3451. return true;
  3452. }
  3453. var maybePromise = tryConvertToPromise(ret, this._promise);
  3454. if (maybePromise instanceof Promise) {
  3455. maybePromise = maybePromise._target();
  3456. var bitField = maybePromise._bitField;
  3457. ;
  3458. if (((bitField & 50397184) === 0)) {
  3459. if (limit >= 1) this._inFlight++;
  3460. values[index] = maybePromise;
  3461. maybePromise._proxy(this, (index + 1) * -1);
  3462. return false;
  3463. } else if (((bitField & 33554432) !== 0)) {
  3464. ret = maybePromise._value();
  3465. } else if (((bitField & 16777216) !== 0)) {
  3466. this._reject(maybePromise._reason());
  3467. return true;
  3468. } else {
  3469. this._cancel();
  3470. return true;
  3471. }
  3472. }
  3473. values[index] = ret;
  3474. }
  3475. var totalResolved = ++this._totalResolved;
  3476. if (totalResolved >= length) {
  3477. if (preservedValues !== null) {
  3478. this._filter(values, preservedValues);
  3479. } else {
  3480. this._resolve(values);
  3481. }
  3482. return true;
  3483. }
  3484. return false;
  3485. };
  3486. MappingPromiseArray.prototype._drainQueue = function () {
  3487. var queue = this._queue;
  3488. var limit = this._limit;
  3489. var values = this._values;
  3490. while (queue.length > 0 && this._inFlight < limit) {
  3491. if (this._isResolved()) return;
  3492. var index = queue.pop();
  3493. this._promiseFulfilled(values[index], index);
  3494. }
  3495. };
  3496. MappingPromiseArray.prototype._filter = function (booleans, values) {
  3497. var len = values.length;
  3498. var ret = new Array(len);
  3499. var j = 0;
  3500. for (var i = 0; i < len; ++i) {
  3501. if (booleans[i]) ret[j++] = values[i];
  3502. }
  3503. ret.length = j;
  3504. this._resolve(ret);
  3505. };
  3506. MappingPromiseArray.prototype.preservedValues = function () {
  3507. return this._preservedValues;
  3508. };
  3509. function map(promises, fn, options, _filter) {
  3510. if (typeof fn !== "function") {
  3511. return apiRejection("expecting a function but got " + util.classString(fn));
  3512. }
  3513. var limit = 0;
  3514. if (options !== undefined) {
  3515. if (typeof options === "object" && options !== null) {
  3516. if (typeof options.concurrency !== "number") {
  3517. return Promise.reject(
  3518. new TypeError("'concurrency' must be a number but it is " +
  3519. util.classString(options.concurrency)));
  3520. }
  3521. limit = options.concurrency;
  3522. } else {
  3523. return Promise.reject(new TypeError(
  3524. "options argument must be an object but it is " +
  3525. util.classString(options)));
  3526. }
  3527. }
  3528. limit = typeof limit === "number" &&
  3529. isFinite(limit) && limit >= 1 ? limit : 0;
  3530. return new MappingPromiseArray(promises, fn, limit, _filter).promise();
  3531. }
  3532. Promise.prototype.map = function (fn, options) {
  3533. return map(this, fn, options, null);
  3534. };
  3535. Promise.map = function (promises, fn, options, _filter) {
  3536. return map(promises, fn, options, _filter);
  3537. };
  3538. };
  3539. },{"./util":36}],19:[function(_dereq_,module,exports){
  3540. "use strict";
  3541. module.exports =
  3542. function(Promise, INTERNAL, tryConvertToPromise, apiRejection, debug) {
  3543. var util = _dereq_("./util");
  3544. var tryCatch = util.tryCatch;
  3545. Promise.method = function (fn) {
  3546. if (typeof fn !== "function") {
  3547. throw new Promise.TypeError("expecting a function but got " + util.classString(fn));
  3548. }
  3549. return function () {
  3550. var ret = new Promise(INTERNAL);
  3551. ret._captureStackTrace();
  3552. ret._pushContext();
  3553. var value = tryCatch(fn).apply(this, arguments);
  3554. var promiseCreated = ret._popContext();
  3555. debug.checkForgottenReturns(
  3556. value, promiseCreated, "Promise.method", ret);
  3557. ret._resolveFromSyncValue(value);
  3558. return ret;
  3559. };
  3560. };
  3561. Promise.attempt = Promise["try"] = function (fn) {
  3562. if (typeof fn !== "function") {
  3563. return apiRejection("expecting a function but got " + util.classString(fn));
  3564. }
  3565. var ret = new Promise(INTERNAL);
  3566. ret._captureStackTrace();
  3567. ret._pushContext();
  3568. var value;
  3569. if (arguments.length > 1) {
  3570. debug.deprecated("calling Promise.try with more than 1 argument");
  3571. var arg = arguments[1];
  3572. var ctx = arguments[2];
  3573. value = util.isArray(arg) ? tryCatch(fn).apply(ctx, arg)
  3574. : tryCatch(fn).call(ctx, arg);
  3575. } else {
  3576. value = tryCatch(fn)();
  3577. }
  3578. var promiseCreated = ret._popContext();
  3579. debug.checkForgottenReturns(
  3580. value, promiseCreated, "Promise.try", ret);
  3581. ret._resolveFromSyncValue(value);
  3582. return ret;
  3583. };
  3584. Promise.prototype._resolveFromSyncValue = function (value) {
  3585. if (value === util.errorObj) {
  3586. this._rejectCallback(value.e, false);
  3587. } else {
  3588. this._resolveCallback(value, true);
  3589. }
  3590. };
  3591. };
  3592. },{"./util":36}],20:[function(_dereq_,module,exports){
  3593. "use strict";
  3594. var util = _dereq_("./util");
  3595. var maybeWrapAsError = util.maybeWrapAsError;
  3596. var errors = _dereq_("./errors");
  3597. var OperationalError = errors.OperationalError;
  3598. var es5 = _dereq_("./es5");
  3599. function isUntypedError(obj) {
  3600. return obj instanceof Error &&
  3601. es5.getPrototypeOf(obj) === Error.prototype;
  3602. }
  3603. var rErrorKey = /^(?:name|message|stack|cause)$/;
  3604. function wrapAsOperationalError(obj) {
  3605. var ret;
  3606. if (isUntypedError(obj)) {
  3607. ret = new OperationalError(obj);
  3608. ret.name = obj.name;
  3609. ret.message = obj.message;
  3610. ret.stack = obj.stack;
  3611. var keys = es5.keys(obj);
  3612. for (var i = 0; i < keys.length; ++i) {
  3613. var key = keys[i];
  3614. if (!rErrorKey.test(key)) {
  3615. ret[key] = obj[key];
  3616. }
  3617. }
  3618. return ret;
  3619. }
  3620. util.markAsOriginatingFromRejection(obj);
  3621. return obj;
  3622. }
  3623. function nodebackForPromise(promise, multiArgs) {
  3624. return function(err, value) {
  3625. if (promise === null) return;
  3626. if (err) {
  3627. var wrapped = wrapAsOperationalError(maybeWrapAsError(err));
  3628. promise._attachExtraTrace(wrapped);
  3629. promise._reject(wrapped);
  3630. } else if (!multiArgs) {
  3631. promise._fulfill(value);
  3632. } else {
  3633. var args = [].slice.call(arguments, 1);;
  3634. promise._fulfill(args);
  3635. }
  3636. promise = null;
  3637. };
  3638. }
  3639. module.exports = nodebackForPromise;
  3640. },{"./errors":12,"./es5":13,"./util":36}],21:[function(_dereq_,module,exports){
  3641. "use strict";
  3642. module.exports = function(Promise) {
  3643. var util = _dereq_("./util");
  3644. var async = Promise._async;
  3645. var tryCatch = util.tryCatch;
  3646. var errorObj = util.errorObj;
  3647. function spreadAdapter(val, nodeback) {
  3648. var promise = this;
  3649. if (!util.isArray(val)) return successAdapter.call(promise, val, nodeback);
  3650. var ret =
  3651. tryCatch(nodeback).apply(promise._boundValue(), [null].concat(val));
  3652. if (ret === errorObj) {
  3653. async.throwLater(ret.e);
  3654. }
  3655. }
  3656. function successAdapter(val, nodeback) {
  3657. var promise = this;
  3658. var receiver = promise._boundValue();
  3659. var ret = val === undefined
  3660. ? tryCatch(nodeback).call(receiver, null)
  3661. : tryCatch(nodeback).call(receiver, null, val);
  3662. if (ret === errorObj) {
  3663. async.throwLater(ret.e);
  3664. }
  3665. }
  3666. function errorAdapter(reason, nodeback) {
  3667. var promise = this;
  3668. if (!reason) {
  3669. var newReason = new Error(reason + "");
  3670. newReason.cause = reason;
  3671. reason = newReason;
  3672. }
  3673. var ret = tryCatch(nodeback).call(promise._boundValue(), reason);
  3674. if (ret === errorObj) {
  3675. async.throwLater(ret.e);
  3676. }
  3677. }
  3678. Promise.prototype.asCallback = Promise.prototype.nodeify = function (nodeback,
  3679. options) {
  3680. if (typeof nodeback == "function") {
  3681. var adapter = successAdapter;
  3682. if (options !== undefined && Object(options).spread) {
  3683. adapter = spreadAdapter;
  3684. }
  3685. this._then(
  3686. adapter,
  3687. errorAdapter,
  3688. undefined,
  3689. this,
  3690. nodeback
  3691. );
  3692. }
  3693. return this;
  3694. };
  3695. };
  3696. },{"./util":36}],22:[function(_dereq_,module,exports){
  3697. "use strict";
  3698. module.exports = function() {
  3699. var makeSelfResolutionError = function () {
  3700. return new TypeError("circular promise resolution chain\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  3701. };
  3702. var reflectHandler = function() {
  3703. return new Promise.PromiseInspection(this._target());
  3704. };
  3705. var apiRejection = function(msg) {
  3706. return Promise.reject(new TypeError(msg));
  3707. };
  3708. function Proxyable() {}
  3709. var UNDEFINED_BINDING = {};
  3710. var util = _dereq_("./util");
  3711. var getDomain;
  3712. if (util.isNode) {
  3713. getDomain = function() {
  3714. var ret = process.domain;
  3715. if (ret === undefined) ret = null;
  3716. return ret;
  3717. };
  3718. } else {
  3719. getDomain = function() {
  3720. return null;
  3721. };
  3722. }
  3723. util.notEnumerableProp(Promise, "_getDomain", getDomain);
  3724. var es5 = _dereq_("./es5");
  3725. var Async = _dereq_("./async");
  3726. var async = new Async();
  3727. es5.defineProperty(Promise, "_async", {value: async});
  3728. var errors = _dereq_("./errors");
  3729. var TypeError = Promise.TypeError = errors.TypeError;
  3730. Promise.RangeError = errors.RangeError;
  3731. var CancellationError = Promise.CancellationError = errors.CancellationError;
  3732. Promise.TimeoutError = errors.TimeoutError;
  3733. Promise.OperationalError = errors.OperationalError;
  3734. Promise.RejectionError = errors.OperationalError;
  3735. Promise.AggregateError = errors.AggregateError;
  3736. var INTERNAL = function(){};
  3737. var APPLY = {};
  3738. var NEXT_FILTER = {};
  3739. var tryConvertToPromise = _dereq_("./thenables")(Promise, INTERNAL);
  3740. var PromiseArray =
  3741. _dereq_("./promise_array")(Promise, INTERNAL,
  3742. tryConvertToPromise, apiRejection, Proxyable);
  3743. var Context = _dereq_("./context")(Promise);
  3744. /*jshint unused:false*/
  3745. var createContext = Context.create;
  3746. var debug = _dereq_("./debuggability")(Promise, Context);
  3747. var CapturedTrace = debug.CapturedTrace;
  3748. var PassThroughHandlerContext =
  3749. _dereq_("./finally")(Promise, tryConvertToPromise);
  3750. var catchFilter = _dereq_("./catch_filter")(NEXT_FILTER);
  3751. var nodebackForPromise = _dereq_("./nodeback");
  3752. var errorObj = util.errorObj;
  3753. var tryCatch = util.tryCatch;
  3754. function check(self, executor) {
  3755. if (typeof executor !== "function") {
  3756. throw new TypeError("expecting a function but got " + util.classString(executor));
  3757. }
  3758. if (self.constructor !== Promise) {
  3759. throw new TypeError("the promise constructor cannot be invoked directly\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  3760. }
  3761. }
  3762. function Promise(executor) {
  3763. this._bitField = 0;
  3764. this._fulfillmentHandler0 = undefined;
  3765. this._rejectionHandler0 = undefined;
  3766. this._promise0 = undefined;
  3767. this._receiver0 = undefined;
  3768. if (executor !== INTERNAL) {
  3769. check(this, executor);
  3770. this._resolveFromExecutor(executor);
  3771. }
  3772. this._promiseCreated();
  3773. this._fireEvent("promiseCreated", this);
  3774. }
  3775. Promise.prototype.toString = function () {
  3776. return "[object Promise]";
  3777. };
  3778. Promise.prototype.caught = Promise.prototype["catch"] = function (fn) {
  3779. var len = arguments.length;
  3780. if (len > 1) {
  3781. var catchInstances = new Array(len - 1),
  3782. j = 0, i;
  3783. for (i = 0; i < len - 1; ++i) {
  3784. var item = arguments[i];
  3785. if (util.isObject(item)) {
  3786. catchInstances[j++] = item;
  3787. } else {
  3788. return apiRejection("expecting an object but got " +
  3789. "A catch statement predicate " + util.classString(item));
  3790. }
  3791. }
  3792. catchInstances.length = j;
  3793. fn = arguments[i];
  3794. return this.then(undefined, catchFilter(catchInstances, fn, this));
  3795. }
  3796. return this.then(undefined, fn);
  3797. };
  3798. Promise.prototype.reflect = function () {
  3799. return this._then(reflectHandler,
  3800. reflectHandler, undefined, this, undefined);
  3801. };
  3802. Promise.prototype.then = function (didFulfill, didReject) {
  3803. if (debug.warnings() && arguments.length > 0 &&
  3804. typeof didFulfill !== "function" &&
  3805. typeof didReject !== "function") {
  3806. var msg = ".then() only accepts functions but was passed: " +
  3807. util.classString(didFulfill);
  3808. if (arguments.length > 1) {
  3809. msg += ", " + util.classString(didReject);
  3810. }
  3811. this._warn(msg);
  3812. }
  3813. return this._then(didFulfill, didReject, undefined, undefined, undefined);
  3814. };
  3815. Promise.prototype.done = function (didFulfill, didReject) {
  3816. var promise =
  3817. this._then(didFulfill, didReject, undefined, undefined, undefined);
  3818. promise._setIsFinal();
  3819. };
  3820. Promise.prototype.spread = function (fn) {
  3821. if (typeof fn !== "function") {
  3822. return apiRejection("expecting a function but got " + util.classString(fn));
  3823. }
  3824. return this.all()._then(fn, undefined, undefined, APPLY, undefined);
  3825. };
  3826. Promise.prototype.toJSON = function () {
  3827. var ret = {
  3828. isFulfilled: false,
  3829. isRejected: false,
  3830. fulfillmentValue: undefined,
  3831. rejectionReason: undefined
  3832. };
  3833. if (this.isFulfilled()) {
  3834. ret.fulfillmentValue = this.value();
  3835. ret.isFulfilled = true;
  3836. } else if (this.isRejected()) {
  3837. ret.rejectionReason = this.reason();
  3838. ret.isRejected = true;
  3839. }
  3840. return ret;
  3841. };
  3842. Promise.prototype.all = function () {
  3843. if (arguments.length > 0) {
  3844. this._warn(".all() was passed arguments but it does not take any");
  3845. }
  3846. return new PromiseArray(this).promise();
  3847. };
  3848. Promise.prototype.error = function (fn) {
  3849. return this.caught(util.originatesFromRejection, fn);
  3850. };
  3851. Promise.getNewLibraryCopy = module.exports;
  3852. Promise.is = function (val) {
  3853. return val instanceof Promise;
  3854. };
  3855. Promise.fromNode = Promise.fromCallback = function(fn) {
  3856. var ret = new Promise(INTERNAL);
  3857. ret._captureStackTrace();
  3858. var multiArgs = arguments.length > 1 ? !!Object(arguments[1]).multiArgs
  3859. : false;
  3860. var result = tryCatch(fn)(nodebackForPromise(ret, multiArgs));
  3861. if (result === errorObj) {
  3862. ret._rejectCallback(result.e, true);
  3863. }
  3864. if (!ret._isFateSealed()) ret._setAsyncGuaranteed();
  3865. return ret;
  3866. };
  3867. Promise.all = function (promises) {
  3868. return new PromiseArray(promises).promise();
  3869. };
  3870. Promise.cast = function (obj) {
  3871. var ret = tryConvertToPromise(obj);
  3872. if (!(ret instanceof Promise)) {
  3873. ret = new Promise(INTERNAL);
  3874. ret._captureStackTrace();
  3875. ret._setFulfilled();
  3876. ret._rejectionHandler0 = obj;
  3877. }
  3878. return ret;
  3879. };
  3880. Promise.resolve = Promise.fulfilled = Promise.cast;
  3881. Promise.reject = Promise.rejected = function (reason) {
  3882. var ret = new Promise(INTERNAL);
  3883. ret._captureStackTrace();
  3884. ret._rejectCallback(reason, true);
  3885. return ret;
  3886. };
  3887. Promise.setScheduler = function(fn) {
  3888. if (typeof fn !== "function") {
  3889. throw new TypeError("expecting a function but got " + util.classString(fn));
  3890. }
  3891. return async.setScheduler(fn);
  3892. };
  3893. Promise.prototype._then = function (
  3894. didFulfill,
  3895. didReject,
  3896. _, receiver,
  3897. internalData
  3898. ) {
  3899. var haveInternalData = internalData !== undefined;
  3900. var promise = haveInternalData ? internalData : new Promise(INTERNAL);
  3901. var target = this._target();
  3902. var bitField = target._bitField;
  3903. if (!haveInternalData) {
  3904. promise._propagateFrom(this, 3);
  3905. promise._captureStackTrace();
  3906. if (receiver === undefined &&
  3907. ((this._bitField & 2097152) !== 0)) {
  3908. if (!((bitField & 50397184) === 0)) {
  3909. receiver = this._boundValue();
  3910. } else {
  3911. receiver = target === this ? undefined : this._boundTo;
  3912. }
  3913. }
  3914. this._fireEvent("promiseChained", this, promise);
  3915. }
  3916. var domain = getDomain();
  3917. if (!((bitField & 50397184) === 0)) {
  3918. var handler, value, settler = target._settlePromiseCtx;
  3919. if (((bitField & 33554432) !== 0)) {
  3920. value = target._rejectionHandler0;
  3921. handler = didFulfill;
  3922. } else if (((bitField & 16777216) !== 0)) {
  3923. value = target._fulfillmentHandler0;
  3924. handler = didReject;
  3925. target._unsetRejectionIsUnhandled();
  3926. } else {
  3927. settler = target._settlePromiseLateCancellationObserver;
  3928. value = new CancellationError("late cancellation observer");
  3929. target._attachExtraTrace(value);
  3930. handler = didReject;
  3931. }
  3932. async.invoke(settler, target, {
  3933. handler: domain === null ? handler
  3934. : (typeof handler === "function" &&
  3935. util.domainBind(domain, handler)),
  3936. promise: promise,
  3937. receiver: receiver,
  3938. value: value
  3939. });
  3940. } else {
  3941. target._addCallbacks(didFulfill, didReject, promise, receiver, domain);
  3942. }
  3943. return promise;
  3944. };
  3945. Promise.prototype._length = function () {
  3946. return this._bitField & 65535;
  3947. };
  3948. Promise.prototype._isFateSealed = function () {
  3949. return (this._bitField & 117506048) !== 0;
  3950. };
  3951. Promise.prototype._isFollowing = function () {
  3952. return (this._bitField & 67108864) === 67108864;
  3953. };
  3954. Promise.prototype._setLength = function (len) {
  3955. this._bitField = (this._bitField & -65536) |
  3956. (len & 65535);
  3957. };
  3958. Promise.prototype._setFulfilled = function () {
  3959. this._bitField = this._bitField | 33554432;
  3960. this._fireEvent("promiseFulfilled", this);
  3961. };
  3962. Promise.prototype._setRejected = function () {
  3963. this._bitField = this._bitField | 16777216;
  3964. this._fireEvent("promiseRejected", this);
  3965. };
  3966. Promise.prototype._setFollowing = function () {
  3967. this._bitField = this._bitField | 67108864;
  3968. this._fireEvent("promiseResolved", this);
  3969. };
  3970. Promise.prototype._setIsFinal = function () {
  3971. this._bitField = this._bitField | 4194304;
  3972. };
  3973. Promise.prototype._isFinal = function () {
  3974. return (this._bitField & 4194304) > 0;
  3975. };
  3976. Promise.prototype._unsetCancelled = function() {
  3977. this._bitField = this._bitField & (~65536);
  3978. };
  3979. Promise.prototype._setCancelled = function() {
  3980. this._bitField = this._bitField | 65536;
  3981. this._fireEvent("promiseCancelled", this);
  3982. };
  3983. Promise.prototype._setWillBeCancelled = function() {
  3984. this._bitField = this._bitField | 8388608;
  3985. };
  3986. Promise.prototype._setAsyncGuaranteed = function() {
  3987. if (async.hasCustomScheduler()) return;
  3988. this._bitField = this._bitField | 134217728;
  3989. };
  3990. Promise.prototype._receiverAt = function (index) {
  3991. var ret = index === 0 ? this._receiver0 : this[
  3992. index * 4 - 4 + 3];
  3993. if (ret === UNDEFINED_BINDING) {
  3994. return undefined;
  3995. } else if (ret === undefined && this._isBound()) {
  3996. return this._boundValue();
  3997. }
  3998. return ret;
  3999. };
  4000. Promise.prototype._promiseAt = function (index) {
  4001. return this[
  4002. index * 4 - 4 + 2];
  4003. };
  4004. Promise.prototype._fulfillmentHandlerAt = function (index) {
  4005. return this[
  4006. index * 4 - 4 + 0];
  4007. };
  4008. Promise.prototype._rejectionHandlerAt = function (index) {
  4009. return this[
  4010. index * 4 - 4 + 1];
  4011. };
  4012. Promise.prototype._boundValue = function() {};
  4013. Promise.prototype._migrateCallback0 = function (follower) {
  4014. var bitField = follower._bitField;
  4015. var fulfill = follower._fulfillmentHandler0;
  4016. var reject = follower._rejectionHandler0;
  4017. var promise = follower._promise0;
  4018. var receiver = follower._receiverAt(0);
  4019. if (receiver === undefined) receiver = UNDEFINED_BINDING;
  4020. this._addCallbacks(fulfill, reject, promise, receiver, null);
  4021. };
  4022. Promise.prototype._migrateCallbackAt = function (follower, index) {
  4023. var fulfill = follower._fulfillmentHandlerAt(index);
  4024. var reject = follower._rejectionHandlerAt(index);
  4025. var promise = follower._promiseAt(index);
  4026. var receiver = follower._receiverAt(index);
  4027. if (receiver === undefined) receiver = UNDEFINED_BINDING;
  4028. this._addCallbacks(fulfill, reject, promise, receiver, null);
  4029. };
  4030. Promise.prototype._addCallbacks = function (
  4031. fulfill,
  4032. reject,
  4033. promise,
  4034. receiver,
  4035. domain
  4036. ) {
  4037. var index = this._length();
  4038. if (index >= 65535 - 4) {
  4039. index = 0;
  4040. this._setLength(0);
  4041. }
  4042. if (index === 0) {
  4043. this._promise0 = promise;
  4044. this._receiver0 = receiver;
  4045. if (typeof fulfill === "function") {
  4046. this._fulfillmentHandler0 =
  4047. domain === null ? fulfill : util.domainBind(domain, fulfill);
  4048. }
  4049. if (typeof reject === "function") {
  4050. this._rejectionHandler0 =
  4051. domain === null ? reject : util.domainBind(domain, reject);
  4052. }
  4053. } else {
  4054. var base = index * 4 - 4;
  4055. this[base + 2] = promise;
  4056. this[base + 3] = receiver;
  4057. if (typeof fulfill === "function") {
  4058. this[base + 0] =
  4059. domain === null ? fulfill : util.domainBind(domain, fulfill);
  4060. }
  4061. if (typeof reject === "function") {
  4062. this[base + 1] =
  4063. domain === null ? reject : util.domainBind(domain, reject);
  4064. }
  4065. }
  4066. this._setLength(index + 1);
  4067. return index;
  4068. };
  4069. Promise.prototype._proxy = function (proxyable, arg) {
  4070. this._addCallbacks(undefined, undefined, arg, proxyable, null);
  4071. };
  4072. Promise.prototype._resolveCallback = function(value, shouldBind) {
  4073. if (((this._bitField & 117506048) !== 0)) return;
  4074. if (value === this)
  4075. return this._rejectCallback(makeSelfResolutionError(), false);
  4076. var maybePromise = tryConvertToPromise(value, this);
  4077. if (!(maybePromise instanceof Promise)) return this._fulfill(value);
  4078. if (shouldBind) this._propagateFrom(maybePromise, 2);
  4079. var promise = maybePromise._target();
  4080. if (promise === this) {
  4081. this._reject(makeSelfResolutionError());
  4082. return;
  4083. }
  4084. var bitField = promise._bitField;
  4085. if (((bitField & 50397184) === 0)) {
  4086. var len = this._length();
  4087. if (len > 0) promise._migrateCallback0(this);
  4088. for (var i = 1; i < len; ++i) {
  4089. promise._migrateCallbackAt(this, i);
  4090. }
  4091. this._setFollowing();
  4092. this._setLength(0);
  4093. this._setFollowee(promise);
  4094. } else if (((bitField & 33554432) !== 0)) {
  4095. this._fulfill(promise._value());
  4096. } else if (((bitField & 16777216) !== 0)) {
  4097. this._reject(promise._reason());
  4098. } else {
  4099. var reason = new CancellationError("late cancellation observer");
  4100. promise._attachExtraTrace(reason);
  4101. this._reject(reason);
  4102. }
  4103. };
  4104. Promise.prototype._rejectCallback =
  4105. function(reason, synchronous, ignoreNonErrorWarnings) {
  4106. var trace = util.ensureErrorObject(reason);
  4107. var hasStack = trace === reason;
  4108. if (!hasStack && !ignoreNonErrorWarnings && debug.warnings()) {
  4109. var message = "a promise was rejected with a non-error: " +
  4110. util.classString(reason);
  4111. this._warn(message, true);
  4112. }
  4113. this._attachExtraTrace(trace, synchronous ? hasStack : false);
  4114. this._reject(reason);
  4115. };
  4116. Promise.prototype._resolveFromExecutor = function (executor) {
  4117. var promise = this;
  4118. this._captureStackTrace();
  4119. this._pushContext();
  4120. var synchronous = true;
  4121. var r = this._execute(executor, function(value) {
  4122. promise._resolveCallback(value);
  4123. }, function (reason) {
  4124. promise._rejectCallback(reason, synchronous);
  4125. });
  4126. synchronous = false;
  4127. this._popContext();
  4128. if (r !== undefined) {
  4129. promise._rejectCallback(r, true);
  4130. }
  4131. };
  4132. Promise.prototype._settlePromiseFromHandler = function (
  4133. handler, receiver, value, promise
  4134. ) {
  4135. var bitField = promise._bitField;
  4136. if (((bitField & 65536) !== 0)) return;
  4137. promise._pushContext();
  4138. var x;
  4139. if (receiver === APPLY) {
  4140. if (!value || typeof value.length !== "number") {
  4141. x = errorObj;
  4142. x.e = new TypeError("cannot .spread() a non-array: " +
  4143. util.classString(value));
  4144. } else {
  4145. x = tryCatch(handler).apply(this._boundValue(), value);
  4146. }
  4147. } else {
  4148. x = tryCatch(handler).call(receiver, value);
  4149. }
  4150. var promiseCreated = promise._popContext();
  4151. bitField = promise._bitField;
  4152. if (((bitField & 65536) !== 0)) return;
  4153. if (x === NEXT_FILTER) {
  4154. promise._reject(value);
  4155. } else if (x === errorObj) {
  4156. promise._rejectCallback(x.e, false);
  4157. } else {
  4158. debug.checkForgottenReturns(x, promiseCreated, "", promise, this);
  4159. promise._resolveCallback(x);
  4160. }
  4161. };
  4162. Promise.prototype._target = function() {
  4163. var ret = this;
  4164. while (ret._isFollowing()) ret = ret._followee();
  4165. return ret;
  4166. };
  4167. Promise.prototype._followee = function() {
  4168. return this._rejectionHandler0;
  4169. };
  4170. Promise.prototype._setFollowee = function(promise) {
  4171. this._rejectionHandler0 = promise;
  4172. };
  4173. Promise.prototype._settlePromise = function(promise, handler, receiver, value) {
  4174. var isPromise = promise instanceof Promise;
  4175. var bitField = this._bitField;
  4176. var asyncGuaranteed = ((bitField & 134217728) !== 0);
  4177. if (((bitField & 65536) !== 0)) {
  4178. if (isPromise) promise._invokeInternalOnCancel();
  4179. if (receiver instanceof PassThroughHandlerContext &&
  4180. receiver.isFinallyHandler()) {
  4181. receiver.cancelPromise = promise;
  4182. if (tryCatch(handler).call(receiver, value) === errorObj) {
  4183. promise._reject(errorObj.e);
  4184. }
  4185. } else if (handler === reflectHandler) {
  4186. promise._fulfill(reflectHandler.call(receiver));
  4187. } else if (receiver instanceof Proxyable) {
  4188. receiver._promiseCancelled(promise);
  4189. } else if (isPromise || promise instanceof PromiseArray) {
  4190. promise._cancel();
  4191. } else {
  4192. receiver.cancel();
  4193. }
  4194. } else if (typeof handler === "function") {
  4195. if (!isPromise) {
  4196. handler.call(receiver, value, promise);
  4197. } else {
  4198. if (asyncGuaranteed) promise._setAsyncGuaranteed();
  4199. this._settlePromiseFromHandler(handler, receiver, value, promise);
  4200. }
  4201. } else if (receiver instanceof Proxyable) {
  4202. if (!receiver._isResolved()) {
  4203. if (((bitField & 33554432) !== 0)) {
  4204. receiver._promiseFulfilled(value, promise);
  4205. } else {
  4206. receiver._promiseRejected(value, promise);
  4207. }
  4208. }
  4209. } else if (isPromise) {
  4210. if (asyncGuaranteed) promise._setAsyncGuaranteed();
  4211. if (((bitField & 33554432) !== 0)) {
  4212. promise._fulfill(value);
  4213. } else {
  4214. promise._reject(value);
  4215. }
  4216. }
  4217. };
  4218. Promise.prototype._settlePromiseLateCancellationObserver = function(ctx) {
  4219. var handler = ctx.handler;
  4220. var promise = ctx.promise;
  4221. var receiver = ctx.receiver;
  4222. var value = ctx.value;
  4223. if (typeof handler === "function") {
  4224. if (!(promise instanceof Promise)) {
  4225. handler.call(receiver, value, promise);
  4226. } else {
  4227. this._settlePromiseFromHandler(handler, receiver, value, promise);
  4228. }
  4229. } else if (promise instanceof Promise) {
  4230. promise._reject(value);
  4231. }
  4232. };
  4233. Promise.prototype._settlePromiseCtx = function(ctx) {
  4234. this._settlePromise(ctx.promise, ctx.handler, ctx.receiver, ctx.value);
  4235. };
  4236. Promise.prototype._settlePromise0 = function(handler, value, bitField) {
  4237. var promise = this._promise0;
  4238. var receiver = this._receiverAt(0);
  4239. this._promise0 = undefined;
  4240. this._receiver0 = undefined;
  4241. this._settlePromise(promise, handler, receiver, value);
  4242. };
  4243. Promise.prototype._clearCallbackDataAtIndex = function(index) {
  4244. var base = index * 4 - 4;
  4245. this[base + 2] =
  4246. this[base + 3] =
  4247. this[base + 0] =
  4248. this[base + 1] = undefined;
  4249. };
  4250. Promise.prototype._fulfill = function (value) {
  4251. var bitField = this._bitField;
  4252. if (((bitField & 117506048) >>> 16)) return;
  4253. if (value === this) {
  4254. var err = makeSelfResolutionError();
  4255. this._attachExtraTrace(err);
  4256. return this._reject(err);
  4257. }
  4258. this._setFulfilled();
  4259. this._rejectionHandler0 = value;
  4260. if ((bitField & 65535) > 0) {
  4261. if (((bitField & 134217728) !== 0)) {
  4262. this._settlePromises();
  4263. } else {
  4264. async.settlePromises(this);
  4265. }
  4266. }
  4267. };
  4268. Promise.prototype._reject = function (reason) {
  4269. var bitField = this._bitField;
  4270. if (((bitField & 117506048) >>> 16)) return;
  4271. this._setRejected();
  4272. this._fulfillmentHandler0 = reason;
  4273. if (this._isFinal()) {
  4274. return async.fatalError(reason, util.isNode);
  4275. }
  4276. if ((bitField & 65535) > 0) {
  4277. async.settlePromises(this);
  4278. } else {
  4279. this._ensurePossibleRejectionHandled();
  4280. }
  4281. };
  4282. Promise.prototype._fulfillPromises = function (len, value) {
  4283. for (var i = 1; i < len; i++) {
  4284. var handler = this._fulfillmentHandlerAt(i);
  4285. var promise = this._promiseAt(i);
  4286. var receiver = this._receiverAt(i);
  4287. this._clearCallbackDataAtIndex(i);
  4288. this._settlePromise(promise, handler, receiver, value);
  4289. }
  4290. };
  4291. Promise.prototype._rejectPromises = function (len, reason) {
  4292. for (var i = 1; i < len; i++) {
  4293. var handler = this._rejectionHandlerAt(i);
  4294. var promise = this._promiseAt(i);
  4295. var receiver = this._receiverAt(i);
  4296. this._clearCallbackDataAtIndex(i);
  4297. this._settlePromise(promise, handler, receiver, reason);
  4298. }
  4299. };
  4300. Promise.prototype._settlePromises = function () {
  4301. var bitField = this._bitField;
  4302. var len = (bitField & 65535);
  4303. if (len > 0) {
  4304. if (((bitField & 16842752) !== 0)) {
  4305. var reason = this._fulfillmentHandler0;
  4306. this._settlePromise0(this._rejectionHandler0, reason, bitField);
  4307. this._rejectPromises(len, reason);
  4308. } else {
  4309. var value = this._rejectionHandler0;
  4310. this._settlePromise0(this._fulfillmentHandler0, value, bitField);
  4311. this._fulfillPromises(len, value);
  4312. }
  4313. this._setLength(0);
  4314. }
  4315. this._clearCancellationData();
  4316. };
  4317. Promise.prototype._settledValue = function() {
  4318. var bitField = this._bitField;
  4319. if (((bitField & 33554432) !== 0)) {
  4320. return this._rejectionHandler0;
  4321. } else if (((bitField & 16777216) !== 0)) {
  4322. return this._fulfillmentHandler0;
  4323. }
  4324. };
  4325. function deferResolve(v) {this.promise._resolveCallback(v);}
  4326. function deferReject(v) {this.promise._rejectCallback(v, false);}
  4327. Promise.defer = Promise.pending = function() {
  4328. debug.deprecated("Promise.defer", "new Promise");
  4329. var promise = new Promise(INTERNAL);
  4330. return {
  4331. promise: promise,
  4332. resolve: deferResolve,
  4333. reject: deferReject
  4334. };
  4335. };
  4336. util.notEnumerableProp(Promise,
  4337. "_makeSelfResolutionError",
  4338. makeSelfResolutionError);
  4339. _dereq_("./method")(Promise, INTERNAL, tryConvertToPromise, apiRejection,
  4340. debug);
  4341. _dereq_("./bind")(Promise, INTERNAL, tryConvertToPromise, debug);
  4342. _dereq_("./cancel")(Promise, PromiseArray, apiRejection, debug);
  4343. _dereq_("./direct_resolve")(Promise);
  4344. _dereq_("./synchronous_inspection")(Promise);
  4345. _dereq_("./join")(
  4346. Promise, PromiseArray, tryConvertToPromise, INTERNAL, async, getDomain);
  4347. Promise.Promise = Promise;
  4348. Promise.version = "3.4.6";
  4349. _dereq_('./map.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug);
  4350. _dereq_('./call_get.js')(Promise);
  4351. _dereq_('./using.js')(Promise, apiRejection, tryConvertToPromise, createContext, INTERNAL, debug);
  4352. _dereq_('./timers.js')(Promise, INTERNAL, debug);
  4353. _dereq_('./generators.js')(Promise, apiRejection, INTERNAL, tryConvertToPromise, Proxyable, debug);
  4354. _dereq_('./nodeify.js')(Promise);
  4355. _dereq_('./promisify.js')(Promise, INTERNAL);
  4356. _dereq_('./props.js')(Promise, PromiseArray, tryConvertToPromise, apiRejection);
  4357. _dereq_('./race.js')(Promise, INTERNAL, tryConvertToPromise, apiRejection);
  4358. _dereq_('./reduce.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug);
  4359. _dereq_('./settle.js')(Promise, PromiseArray, debug);
  4360. _dereq_('./some.js')(Promise, PromiseArray, apiRejection);
  4361. _dereq_('./filter.js')(Promise, INTERNAL);
  4362. _dereq_('./each.js')(Promise, INTERNAL);
  4363. _dereq_('./any.js')(Promise);
  4364. util.toFastProperties(Promise);
  4365. util.toFastProperties(Promise.prototype);
  4366. function fillTypes(value) {
  4367. var p = new Promise(INTERNAL);
  4368. p._fulfillmentHandler0 = value;
  4369. p._rejectionHandler0 = value;
  4370. p._promise0 = value;
  4371. p._receiver0 = value;
  4372. }
  4373. // Complete slack tracking, opt out of field-type tracking and
  4374. // stabilize map
  4375. fillTypes({a: 1});
  4376. fillTypes({b: 2});
  4377. fillTypes({c: 3});
  4378. fillTypes(1);
  4379. fillTypes(function(){});
  4380. fillTypes(undefined);
  4381. fillTypes(false);
  4382. fillTypes(new Promise(INTERNAL));
  4383. debug.setBounds(Async.firstLineError, util.lastLineError);
  4384. return Promise;
  4385. };
  4386. },{"./any.js":1,"./async":2,"./bind":3,"./call_get.js":5,"./cancel":6,"./catch_filter":7,"./context":8,"./debuggability":9,"./direct_resolve":10,"./each.js":11,"./errors":12,"./es5":13,"./filter.js":14,"./finally":15,"./generators.js":16,"./join":17,"./map.js":18,"./method":19,"./nodeback":20,"./nodeify.js":21,"./promise_array":23,"./promisify.js":24,"./props.js":25,"./race.js":27,"./reduce.js":28,"./settle.js":30,"./some.js":31,"./synchronous_inspection":32,"./thenables":33,"./timers.js":34,"./using.js":35,"./util":36}],23:[function(_dereq_,module,exports){
  4387. "use strict";
  4388. module.exports = function(Promise, INTERNAL, tryConvertToPromise,
  4389. apiRejection, Proxyable) {
  4390. var util = _dereq_("./util");
  4391. var isArray = util.isArray;
  4392. function toResolutionValue(val) {
  4393. switch(val) {
  4394. case -2: return [];
  4395. case -3: return {};
  4396. }
  4397. }
  4398. function PromiseArray(values) {
  4399. var promise = this._promise = new Promise(INTERNAL);
  4400. if (values instanceof Promise) {
  4401. promise._propagateFrom(values, 3);
  4402. }
  4403. promise._setOnCancel(this);
  4404. this._values = values;
  4405. this._length = 0;
  4406. this._totalResolved = 0;
  4407. this._init(undefined, -2);
  4408. }
  4409. util.inherits(PromiseArray, Proxyable);
  4410. PromiseArray.prototype.length = function () {
  4411. return this._length;
  4412. };
  4413. PromiseArray.prototype.promise = function () {
  4414. return this._promise;
  4415. };
  4416. PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) {
  4417. var values = tryConvertToPromise(this._values, this._promise);
  4418. if (values instanceof Promise) {
  4419. values = values._target();
  4420. var bitField = values._bitField;
  4421. ;
  4422. this._values = values;
  4423. if (((bitField & 50397184) === 0)) {
  4424. this._promise._setAsyncGuaranteed();
  4425. return values._then(
  4426. init,
  4427. this._reject,
  4428. undefined,
  4429. this,
  4430. resolveValueIfEmpty
  4431. );
  4432. } else if (((bitField & 33554432) !== 0)) {
  4433. values = values._value();
  4434. } else if (((bitField & 16777216) !== 0)) {
  4435. return this._reject(values._reason());
  4436. } else {
  4437. return this._cancel();
  4438. }
  4439. }
  4440. values = util.asArray(values);
  4441. if (values === null) {
  4442. var err = apiRejection(
  4443. "expecting an array or an iterable object but got " + util.classString(values)).reason();
  4444. this._promise._rejectCallback(err, false);
  4445. return;
  4446. }
  4447. if (values.length === 0) {
  4448. if (resolveValueIfEmpty === -5) {
  4449. this._resolveEmptyArray();
  4450. }
  4451. else {
  4452. this._resolve(toResolutionValue(resolveValueIfEmpty));
  4453. }
  4454. return;
  4455. }
  4456. this._iterate(values);
  4457. };
  4458. PromiseArray.prototype._iterate = function(values) {
  4459. var len = this.getActualLength(values.length);
  4460. this._length = len;
  4461. this._values = this.shouldCopyValues() ? new Array(len) : this._values;
  4462. var result = this._promise;
  4463. var isResolved = false;
  4464. var bitField = null;
  4465. for (var i = 0; i < len; ++i) {
  4466. var maybePromise = tryConvertToPromise(values[i], result);
  4467. if (maybePromise instanceof Promise) {
  4468. maybePromise = maybePromise._target();
  4469. bitField = maybePromise._bitField;
  4470. } else {
  4471. bitField = null;
  4472. }
  4473. if (isResolved) {
  4474. if (bitField !== null) {
  4475. maybePromise.suppressUnhandledRejections();
  4476. }
  4477. } else if (bitField !== null) {
  4478. if (((bitField & 50397184) === 0)) {
  4479. maybePromise._proxy(this, i);
  4480. this._values[i] = maybePromise;
  4481. } else if (((bitField & 33554432) !== 0)) {
  4482. isResolved = this._promiseFulfilled(maybePromise._value(), i);
  4483. } else if (((bitField & 16777216) !== 0)) {
  4484. isResolved = this._promiseRejected(maybePromise._reason(), i);
  4485. } else {
  4486. isResolved = this._promiseCancelled(i);
  4487. }
  4488. } else {
  4489. isResolved = this._promiseFulfilled(maybePromise, i);
  4490. }
  4491. }
  4492. if (!isResolved) result._setAsyncGuaranteed();
  4493. };
  4494. PromiseArray.prototype._isResolved = function () {
  4495. return this._values === null;
  4496. };
  4497. PromiseArray.prototype._resolve = function (value) {
  4498. this._values = null;
  4499. this._promise._fulfill(value);
  4500. };
  4501. PromiseArray.prototype._cancel = function() {
  4502. if (this._isResolved() || !this._promise._isCancellable()) return;
  4503. this._values = null;
  4504. this._promise._cancel();
  4505. };
  4506. PromiseArray.prototype._reject = function (reason) {
  4507. this._values = null;
  4508. this._promise._rejectCallback(reason, false);
  4509. };
  4510. PromiseArray.prototype._promiseFulfilled = function (value, index) {
  4511. this._values[index] = value;
  4512. var totalResolved = ++this._totalResolved;
  4513. if (totalResolved >= this._length) {
  4514. this._resolve(this._values);
  4515. return true;
  4516. }
  4517. return false;
  4518. };
  4519. PromiseArray.prototype._promiseCancelled = function() {
  4520. this._cancel();
  4521. return true;
  4522. };
  4523. PromiseArray.prototype._promiseRejected = function (reason) {
  4524. this._totalResolved++;
  4525. this._reject(reason);
  4526. return true;
  4527. };
  4528. PromiseArray.prototype._resultCancelled = function() {
  4529. if (this._isResolved()) return;
  4530. var values = this._values;
  4531. this._cancel();
  4532. if (values instanceof Promise) {
  4533. values.cancel();
  4534. } else {
  4535. for (var i = 0; i < values.length; ++i) {
  4536. if (values[i] instanceof Promise) {
  4537. values[i].cancel();
  4538. }
  4539. }
  4540. }
  4541. };
  4542. PromiseArray.prototype.shouldCopyValues = function () {
  4543. return true;
  4544. };
  4545. PromiseArray.prototype.getActualLength = function (len) {
  4546. return len;
  4547. };
  4548. return PromiseArray;
  4549. };
  4550. },{"./util":36}],24:[function(_dereq_,module,exports){
  4551. "use strict";
  4552. module.exports = function(Promise, INTERNAL) {
  4553. var THIS = {};
  4554. var util = _dereq_("./util");
  4555. var nodebackForPromise = _dereq_("./nodeback");
  4556. var withAppended = util.withAppended;
  4557. var maybeWrapAsError = util.maybeWrapAsError;
  4558. var canEvaluate = util.canEvaluate;
  4559. var TypeError = _dereq_("./errors").TypeError;
  4560. var defaultSuffix = "Async";
  4561. var defaultPromisified = {__isPromisified__: true};
  4562. var noCopyProps = [
  4563. "arity", "length",
  4564. "name",
  4565. "arguments",
  4566. "caller",
  4567. "callee",
  4568. "prototype",
  4569. "__isPromisified__"
  4570. ];
  4571. var noCopyPropsPattern = new RegExp("^(?:" + noCopyProps.join("|") + ")$");
  4572. var defaultFilter = function(name) {
  4573. return util.isIdentifier(name) &&
  4574. name.charAt(0) !== "_" &&
  4575. name !== "constructor";
  4576. };
  4577. function propsFilter(key) {
  4578. return !noCopyPropsPattern.test(key);
  4579. }
  4580. function isPromisified(fn) {
  4581. try {
  4582. return fn.__isPromisified__ === true;
  4583. }
  4584. catch (e) {
  4585. return false;
  4586. }
  4587. }
  4588. function hasPromisified(obj, key, suffix) {
  4589. var val = util.getDataPropertyOrDefault(obj, key + suffix,
  4590. defaultPromisified);
  4591. return val ? isPromisified(val) : false;
  4592. }
  4593. function checkValid(ret, suffix, suffixRegexp) {
  4594. for (var i = 0; i < ret.length; i += 2) {
  4595. var key = ret[i];
  4596. if (suffixRegexp.test(key)) {
  4597. var keyWithoutAsyncSuffix = key.replace(suffixRegexp, "");
  4598. for (var j = 0; j < ret.length; j += 2) {
  4599. if (ret[j] === keyWithoutAsyncSuffix) {
  4600. throw new TypeError("Cannot promisify an API that has normal methods with '%s'-suffix\u000a\u000a See http://goo.gl/MqrFmX\u000a"
  4601. .replace("%s", suffix));
  4602. }
  4603. }
  4604. }
  4605. }
  4606. }
  4607. function promisifiableMethods(obj, suffix, suffixRegexp, filter) {
  4608. var keys = util.inheritedDataKeys(obj);
  4609. var ret = [];
  4610. for (var i = 0; i < keys.length; ++i) {
  4611. var key = keys[i];
  4612. var value = obj[key];
  4613. var passesDefaultFilter = filter === defaultFilter
  4614. ? true : defaultFilter(key, value, obj);
  4615. if (typeof value === "function" &&
  4616. !isPromisified(value) &&
  4617. !hasPromisified(obj, key, suffix) &&
  4618. filter(key, value, obj, passesDefaultFilter)) {
  4619. ret.push(key, value);
  4620. }
  4621. }
  4622. checkValid(ret, suffix, suffixRegexp);
  4623. return ret;
  4624. }
  4625. var escapeIdentRegex = function(str) {
  4626. return str.replace(/([$])/, "\\$");
  4627. };
  4628. var makeNodePromisifiedEval;
  4629. if (!true) {
  4630. var switchCaseArgumentOrder = function(likelyArgumentCount) {
  4631. var ret = [likelyArgumentCount];
  4632. var min = Math.max(0, likelyArgumentCount - 1 - 3);
  4633. for(var i = likelyArgumentCount - 1; i >= min; --i) {
  4634. ret.push(i);
  4635. }
  4636. for(var i = likelyArgumentCount + 1; i <= 3; ++i) {
  4637. ret.push(i);
  4638. }
  4639. return ret;
  4640. };
  4641. var argumentSequence = function(argumentCount) {
  4642. return util.filledRange(argumentCount, "_arg", "");
  4643. };
  4644. var parameterDeclaration = function(parameterCount) {
  4645. return util.filledRange(
  4646. Math.max(parameterCount, 3), "_arg", "");
  4647. };
  4648. var parameterCount = function(fn) {
  4649. if (typeof fn.length === "number") {
  4650. return Math.max(Math.min(fn.length, 1023 + 1), 0);
  4651. }
  4652. return 0;
  4653. };
  4654. makeNodePromisifiedEval =
  4655. function(callback, receiver, originalName, fn, _, multiArgs) {
  4656. var newParameterCount = Math.max(0, parameterCount(fn) - 1);
  4657. var argumentOrder = switchCaseArgumentOrder(newParameterCount);
  4658. var shouldProxyThis = typeof callback === "string" || receiver === THIS;
  4659. function generateCallForArgumentCount(count) {
  4660. var args = argumentSequence(count).join(", ");
  4661. var comma = count > 0 ? ", " : "";
  4662. var ret;
  4663. if (shouldProxyThis) {
  4664. ret = "ret = callback.call(this, {{args}}, nodeback); break;\n";
  4665. } else {
  4666. ret = receiver === undefined
  4667. ? "ret = callback({{args}}, nodeback); break;\n"
  4668. : "ret = callback.call(receiver, {{args}}, nodeback); break;\n";
  4669. }
  4670. return ret.replace("{{args}}", args).replace(", ", comma);
  4671. }
  4672. function generateArgumentSwitchCase() {
  4673. var ret = "";
  4674. for (var i = 0; i < argumentOrder.length; ++i) {
  4675. ret += "case " + argumentOrder[i] +":" +
  4676. generateCallForArgumentCount(argumentOrder[i]);
  4677. }
  4678. ret += " \n\
  4679. default: \n\
  4680. var args = new Array(len + 1); \n\
  4681. var i = 0; \n\
  4682. for (var i = 0; i < len; ++i) { \n\
  4683. args[i] = arguments[i]; \n\
  4684. } \n\
  4685. args[i] = nodeback; \n\
  4686. [CodeForCall] \n\
  4687. break; \n\
  4688. ".replace("[CodeForCall]", (shouldProxyThis
  4689. ? "ret = callback.apply(this, args);\n"
  4690. : "ret = callback.apply(receiver, args);\n"));
  4691. return ret;
  4692. }
  4693. var getFunctionCode = typeof callback === "string"
  4694. ? ("this != null ? this['"+callback+"'] : fn")
  4695. : "fn";
  4696. var body = "'use strict'; \n\
  4697. var ret = function (Parameters) { \n\
  4698. 'use strict'; \n\
  4699. var len = arguments.length; \n\
  4700. var promise = new Promise(INTERNAL); \n\
  4701. promise._captureStackTrace(); \n\
  4702. var nodeback = nodebackForPromise(promise, " + multiArgs + "); \n\
  4703. var ret; \n\
  4704. var callback = tryCatch([GetFunctionCode]); \n\
  4705. switch(len) { \n\
  4706. [CodeForSwitchCase] \n\
  4707. } \n\
  4708. if (ret === errorObj) { \n\
  4709. promise._rejectCallback(maybeWrapAsError(ret.e), true, true);\n\
  4710. } \n\
  4711. if (!promise._isFateSealed()) promise._setAsyncGuaranteed(); \n\
  4712. return promise; \n\
  4713. }; \n\
  4714. notEnumerableProp(ret, '__isPromisified__', true); \n\
  4715. return ret; \n\
  4716. ".replace("[CodeForSwitchCase]", generateArgumentSwitchCase())
  4717. .replace("[GetFunctionCode]", getFunctionCode);
  4718. body = body.replace("Parameters", parameterDeclaration(newParameterCount));
  4719. return new Function("Promise",
  4720. "fn",
  4721. "receiver",
  4722. "withAppended",
  4723. "maybeWrapAsError",
  4724. "nodebackForPromise",
  4725. "tryCatch",
  4726. "errorObj",
  4727. "notEnumerableProp",
  4728. "INTERNAL",
  4729. body)(
  4730. Promise,
  4731. fn,
  4732. receiver,
  4733. withAppended,
  4734. maybeWrapAsError,
  4735. nodebackForPromise,
  4736. util.tryCatch,
  4737. util.errorObj,
  4738. util.notEnumerableProp,
  4739. INTERNAL);
  4740. };
  4741. }
  4742. function makeNodePromisifiedClosure(callback, receiver, _, fn, __, multiArgs) {
  4743. var defaultThis = (function() {return this;})();
  4744. var method = callback;
  4745. if (typeof method === "string") {
  4746. callback = fn;
  4747. }
  4748. function promisified() {
  4749. var _receiver = receiver;
  4750. if (receiver === THIS) _receiver = this;
  4751. var promise = new Promise(INTERNAL);
  4752. promise._captureStackTrace();
  4753. var cb = typeof method === "string" && this !== defaultThis
  4754. ? this[method] : callback;
  4755. var fn = nodebackForPromise(promise, multiArgs);
  4756. try {
  4757. cb.apply(_receiver, withAppended(arguments, fn));
  4758. } catch(e) {
  4759. promise._rejectCallback(maybeWrapAsError(e), true, true);
  4760. }
  4761. if (!promise._isFateSealed()) promise._setAsyncGuaranteed();
  4762. return promise;
  4763. }
  4764. util.notEnumerableProp(promisified, "__isPromisified__", true);
  4765. return promisified;
  4766. }
  4767. var makeNodePromisified = canEvaluate
  4768. ? makeNodePromisifiedEval
  4769. : makeNodePromisifiedClosure;
  4770. function promisifyAll(obj, suffix, filter, promisifier, multiArgs) {
  4771. var suffixRegexp = new RegExp(escapeIdentRegex(suffix) + "$");
  4772. var methods =
  4773. promisifiableMethods(obj, suffix, suffixRegexp, filter);
  4774. for (var i = 0, len = methods.length; i < len; i+= 2) {
  4775. var key = methods[i];
  4776. var fn = methods[i+1];
  4777. var promisifiedKey = key + suffix;
  4778. if (promisifier === makeNodePromisified) {
  4779. obj[promisifiedKey] =
  4780. makeNodePromisified(key, THIS, key, fn, suffix, multiArgs);
  4781. } else {
  4782. var promisified = promisifier(fn, function() {
  4783. return makeNodePromisified(key, THIS, key,
  4784. fn, suffix, multiArgs);
  4785. });
  4786. util.notEnumerableProp(promisified, "__isPromisified__", true);
  4787. obj[promisifiedKey] = promisified;
  4788. }
  4789. }
  4790. util.toFastProperties(obj);
  4791. return obj;
  4792. }
  4793. function promisify(callback, receiver, multiArgs) {
  4794. return makeNodePromisified(callback, receiver, undefined,
  4795. callback, null, multiArgs);
  4796. }
  4797. Promise.promisify = function (fn, options) {
  4798. if (typeof fn !== "function") {
  4799. throw new TypeError("expecting a function but got " + util.classString(fn));
  4800. }
  4801. if (isPromisified(fn)) {
  4802. return fn;
  4803. }
  4804. options = Object(options);
  4805. var receiver = options.context === undefined ? THIS : options.context;
  4806. var multiArgs = !!options.multiArgs;
  4807. var ret = promisify(fn, receiver, multiArgs);
  4808. util.copyDescriptors(fn, ret, propsFilter);
  4809. return ret;
  4810. };
  4811. Promise.promisifyAll = function (target, options) {
  4812. if (typeof target !== "function" && typeof target !== "object") {
  4813. throw new TypeError("the target of promisifyAll must be an object or a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  4814. }
  4815. options = Object(options);
  4816. var multiArgs = !!options.multiArgs;
  4817. var suffix = options.suffix;
  4818. if (typeof suffix !== "string") suffix = defaultSuffix;
  4819. var filter = options.filter;
  4820. if (typeof filter !== "function") filter = defaultFilter;
  4821. var promisifier = options.promisifier;
  4822. if (typeof promisifier !== "function") promisifier = makeNodePromisified;
  4823. if (!util.isIdentifier(suffix)) {
  4824. throw new RangeError("suffix must be a valid identifier\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  4825. }
  4826. var keys = util.inheritedDataKeys(target);
  4827. for (var i = 0; i < keys.length; ++i) {
  4828. var value = target[keys[i]];
  4829. if (keys[i] !== "constructor" &&
  4830. util.isClass(value)) {
  4831. promisifyAll(value.prototype, suffix, filter, promisifier,
  4832. multiArgs);
  4833. promisifyAll(value, suffix, filter, promisifier, multiArgs);
  4834. }
  4835. }
  4836. return promisifyAll(target, suffix, filter, promisifier, multiArgs);
  4837. };
  4838. };
  4839. },{"./errors":12,"./nodeback":20,"./util":36}],25:[function(_dereq_,module,exports){
  4840. "use strict";
  4841. module.exports = function(
  4842. Promise, PromiseArray, tryConvertToPromise, apiRejection) {
  4843. var util = _dereq_("./util");
  4844. var isObject = util.isObject;
  4845. var es5 = _dereq_("./es5");
  4846. var Es6Map;
  4847. if (typeof Map === "function") Es6Map = Map;
  4848. var mapToEntries = (function() {
  4849. var index = 0;
  4850. var size = 0;
  4851. function extractEntry(value, key) {
  4852. this[index] = value;
  4853. this[index + size] = key;
  4854. index++;
  4855. }
  4856. return function mapToEntries(map) {
  4857. size = map.size;
  4858. index = 0;
  4859. var ret = new Array(map.size * 2);
  4860. map.forEach(extractEntry, ret);
  4861. return ret;
  4862. };
  4863. })();
  4864. var entriesToMap = function(entries) {
  4865. var ret = new Es6Map();
  4866. var length = entries.length / 2 | 0;
  4867. for (var i = 0; i < length; ++i) {
  4868. var key = entries[length + i];
  4869. var value = entries[i];
  4870. ret.set(key, value);
  4871. }
  4872. return ret;
  4873. };
  4874. function PropertiesPromiseArray(obj) {
  4875. var isMap = false;
  4876. var entries;
  4877. if (Es6Map !== undefined && obj instanceof Es6Map) {
  4878. entries = mapToEntries(obj);
  4879. isMap = true;
  4880. } else {
  4881. var keys = es5.keys(obj);
  4882. var len = keys.length;
  4883. entries = new Array(len * 2);
  4884. for (var i = 0; i < len; ++i) {
  4885. var key = keys[i];
  4886. entries[i] = obj[key];
  4887. entries[i + len] = key;
  4888. }
  4889. }
  4890. this.constructor$(entries);
  4891. this._isMap = isMap;
  4892. this._init$(undefined, -3);
  4893. }
  4894. util.inherits(PropertiesPromiseArray, PromiseArray);
  4895. PropertiesPromiseArray.prototype._init = function () {};
  4896. PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) {
  4897. this._values[index] = value;
  4898. var totalResolved = ++this._totalResolved;
  4899. if (totalResolved >= this._length) {
  4900. var val;
  4901. if (this._isMap) {
  4902. val = entriesToMap(this._values);
  4903. } else {
  4904. val = {};
  4905. var keyOffset = this.length();
  4906. for (var i = 0, len = this.length(); i < len; ++i) {
  4907. val[this._values[i + keyOffset]] = this._values[i];
  4908. }
  4909. }
  4910. this._resolve(val);
  4911. return true;
  4912. }
  4913. return false;
  4914. };
  4915. PropertiesPromiseArray.prototype.shouldCopyValues = function () {
  4916. return false;
  4917. };
  4918. PropertiesPromiseArray.prototype.getActualLength = function (len) {
  4919. return len >> 1;
  4920. };
  4921. function props(promises) {
  4922. var ret;
  4923. var castValue = tryConvertToPromise(promises);
  4924. if (!isObject(castValue)) {
  4925. return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  4926. } else if (castValue instanceof Promise) {
  4927. ret = castValue._then(
  4928. Promise.props, undefined, undefined, undefined, undefined);
  4929. } else {
  4930. ret = new PropertiesPromiseArray(castValue).promise();
  4931. }
  4932. if (castValue instanceof Promise) {
  4933. ret._propagateFrom(castValue, 2);
  4934. }
  4935. return ret;
  4936. }
  4937. Promise.prototype.props = function () {
  4938. return props(this);
  4939. };
  4940. Promise.props = function (promises) {
  4941. return props(promises);
  4942. };
  4943. };
  4944. },{"./es5":13,"./util":36}],26:[function(_dereq_,module,exports){
  4945. "use strict";
  4946. function arrayMove(src, srcIndex, dst, dstIndex, len) {
  4947. for (var j = 0; j < len; ++j) {
  4948. dst[j + dstIndex] = src[j + srcIndex];
  4949. src[j + srcIndex] = void 0;
  4950. }
  4951. }
  4952. function Queue(capacity) {
  4953. this._capacity = capacity;
  4954. this._length = 0;
  4955. this._front = 0;
  4956. }
  4957. Queue.prototype._willBeOverCapacity = function (size) {
  4958. return this._capacity < size;
  4959. };
  4960. Queue.prototype._pushOne = function (arg) {
  4961. var length = this.length();
  4962. this._checkCapacity(length + 1);
  4963. var i = (this._front + length) & (this._capacity - 1);
  4964. this[i] = arg;
  4965. this._length = length + 1;
  4966. };
  4967. Queue.prototype._unshiftOne = function(value) {
  4968. var capacity = this._capacity;
  4969. this._checkCapacity(this.length() + 1);
  4970. var front = this._front;
  4971. var i = (((( front - 1 ) &
  4972. ( capacity - 1) ) ^ capacity ) - capacity );
  4973. this[i] = value;
  4974. this._front = i;
  4975. this._length = this.length() + 1;
  4976. };
  4977. Queue.prototype.unshift = function(fn, receiver, arg) {
  4978. this._unshiftOne(arg);
  4979. this._unshiftOne(receiver);
  4980. this._unshiftOne(fn);
  4981. };
  4982. Queue.prototype.push = function (fn, receiver, arg) {
  4983. var length = this.length() + 3;
  4984. if (this._willBeOverCapacity(length)) {
  4985. this._pushOne(fn);
  4986. this._pushOne(receiver);
  4987. this._pushOne(arg);
  4988. return;
  4989. }
  4990. var j = this._front + length - 3;
  4991. this._checkCapacity(length);
  4992. var wrapMask = this._capacity - 1;
  4993. this[(j + 0) & wrapMask] = fn;
  4994. this[(j + 1) & wrapMask] = receiver;
  4995. this[(j + 2) & wrapMask] = arg;
  4996. this._length = length;
  4997. };
  4998. Queue.prototype.shift = function () {
  4999. var front = this._front,
  5000. ret = this[front];
  5001. this[front] = undefined;
  5002. this._front = (front + 1) & (this._capacity - 1);
  5003. this._length--;
  5004. return ret;
  5005. };
  5006. Queue.prototype.length = function () {
  5007. return this._length;
  5008. };
  5009. Queue.prototype._checkCapacity = function (size) {
  5010. if (this._capacity < size) {
  5011. this._resizeTo(this._capacity << 1);
  5012. }
  5013. };
  5014. Queue.prototype._resizeTo = function (capacity) {
  5015. var oldCapacity = this._capacity;
  5016. this._capacity = capacity;
  5017. var front = this._front;
  5018. var length = this._length;
  5019. var moveItemsCount = (front + length) & (oldCapacity - 1);
  5020. arrayMove(this, 0, this, oldCapacity, moveItemsCount);
  5021. };
  5022. module.exports = Queue;
  5023. },{}],27:[function(_dereq_,module,exports){
  5024. "use strict";
  5025. module.exports = function(
  5026. Promise, INTERNAL, tryConvertToPromise, apiRejection) {
  5027. var util = _dereq_("./util");
  5028. var raceLater = function (promise) {
  5029. return promise.then(function(array) {
  5030. return race(array, promise);
  5031. });
  5032. };
  5033. function race(promises, parent) {
  5034. var maybePromise = tryConvertToPromise(promises);
  5035. if (maybePromise instanceof Promise) {
  5036. return raceLater(maybePromise);
  5037. } else {
  5038. promises = util.asArray(promises);
  5039. if (promises === null)
  5040. return apiRejection("expecting an array or an iterable object but got " + util.classString(promises));
  5041. }
  5042. var ret = new Promise(INTERNAL);
  5043. if (parent !== undefined) {
  5044. ret._propagateFrom(parent, 3);
  5045. }
  5046. var fulfill = ret._fulfill;
  5047. var reject = ret._reject;
  5048. for (var i = 0, len = promises.length; i < len; ++i) {
  5049. var val = promises[i];
  5050. if (val === undefined && !(i in promises)) {
  5051. continue;
  5052. }
  5053. Promise.cast(val)._then(fulfill, reject, undefined, ret, null);
  5054. }
  5055. return ret;
  5056. }
  5057. Promise.race = function (promises) {
  5058. return race(promises, undefined);
  5059. };
  5060. Promise.prototype.race = function () {
  5061. return race(this, undefined);
  5062. };
  5063. };
  5064. },{"./util":36}],28:[function(_dereq_,module,exports){
  5065. "use strict";
  5066. module.exports = function(Promise,
  5067. PromiseArray,
  5068. apiRejection,
  5069. tryConvertToPromise,
  5070. INTERNAL,
  5071. debug) {
  5072. var getDomain = Promise._getDomain;
  5073. var util = _dereq_("./util");
  5074. var tryCatch = util.tryCatch;
  5075. function ReductionPromiseArray(promises, fn, initialValue, _each) {
  5076. this.constructor$(promises);
  5077. var domain = getDomain();
  5078. this._fn = domain === null ? fn : util.domainBind(domain, fn);
  5079. if (initialValue !== undefined) {
  5080. initialValue = Promise.resolve(initialValue);
  5081. initialValue._attachCancellationCallback(this);
  5082. }
  5083. this._initialValue = initialValue;
  5084. this._currentCancellable = null;
  5085. if(_each === INTERNAL) {
  5086. this._eachValues = Array(this._length);
  5087. } else if (_each === 0) {
  5088. this._eachValues = null;
  5089. } else {
  5090. this._eachValues = undefined;
  5091. }
  5092. this._promise._captureStackTrace();
  5093. this._init$(undefined, -5);
  5094. }
  5095. util.inherits(ReductionPromiseArray, PromiseArray);
  5096. ReductionPromiseArray.prototype._gotAccum = function(accum) {
  5097. if (this._eachValues !== undefined &&
  5098. this._eachValues !== null &&
  5099. accum !== INTERNAL) {
  5100. this._eachValues.push(accum);
  5101. }
  5102. };
  5103. ReductionPromiseArray.prototype._eachComplete = function(value) {
  5104. if (this._eachValues !== null) {
  5105. this._eachValues.push(value);
  5106. }
  5107. return this._eachValues;
  5108. };
  5109. ReductionPromiseArray.prototype._init = function() {};
  5110. ReductionPromiseArray.prototype._resolveEmptyArray = function() {
  5111. this._resolve(this._eachValues !== undefined ? this._eachValues
  5112. : this._initialValue);
  5113. };
  5114. ReductionPromiseArray.prototype.shouldCopyValues = function () {
  5115. return false;
  5116. };
  5117. ReductionPromiseArray.prototype._resolve = function(value) {
  5118. this._promise._resolveCallback(value);
  5119. this._values = null;
  5120. };
  5121. ReductionPromiseArray.prototype._resultCancelled = function(sender) {
  5122. if (sender === this._initialValue) return this._cancel();
  5123. if (this._isResolved()) return;
  5124. this._resultCancelled$();
  5125. if (this._currentCancellable instanceof Promise) {
  5126. this._currentCancellable.cancel();
  5127. }
  5128. if (this._initialValue instanceof Promise) {
  5129. this._initialValue.cancel();
  5130. }
  5131. };
  5132. ReductionPromiseArray.prototype._iterate = function (values) {
  5133. this._values = values;
  5134. var value;
  5135. var i;
  5136. var length = values.length;
  5137. if (this._initialValue !== undefined) {
  5138. value = this._initialValue;
  5139. i = 0;
  5140. } else {
  5141. value = Promise.resolve(values[0]);
  5142. i = 1;
  5143. }
  5144. this._currentCancellable = value;
  5145. if (!value.isRejected()) {
  5146. for (; i < length; ++i) {
  5147. var ctx = {
  5148. accum: null,
  5149. value: values[i],
  5150. index: i,
  5151. length: length,
  5152. array: this
  5153. };
  5154. value = value._then(gotAccum, undefined, undefined, ctx, undefined);
  5155. }
  5156. }
  5157. if (this._eachValues !== undefined) {
  5158. value = value
  5159. ._then(this._eachComplete, undefined, undefined, this, undefined);
  5160. }
  5161. value._then(completed, completed, undefined, value, this);
  5162. };
  5163. Promise.prototype.reduce = function (fn, initialValue) {
  5164. return reduce(this, fn, initialValue, null);
  5165. };
  5166. Promise.reduce = function (promises, fn, initialValue, _each) {
  5167. return reduce(promises, fn, initialValue, _each);
  5168. };
  5169. function completed(valueOrReason, array) {
  5170. if (this.isFulfilled()) {
  5171. array._resolve(valueOrReason);
  5172. } else {
  5173. array._reject(valueOrReason);
  5174. }
  5175. }
  5176. function reduce(promises, fn, initialValue, _each) {
  5177. if (typeof fn !== "function") {
  5178. return apiRejection("expecting a function but got " + util.classString(fn));
  5179. }
  5180. var array = new ReductionPromiseArray(promises, fn, initialValue, _each);
  5181. return array.promise();
  5182. }
  5183. function gotAccum(accum) {
  5184. this.accum = accum;
  5185. this.array._gotAccum(accum);
  5186. var value = tryConvertToPromise(this.value, this.array._promise);
  5187. if (value instanceof Promise) {
  5188. this.array._currentCancellable = value;
  5189. return value._then(gotValue, undefined, undefined, this, undefined);
  5190. } else {
  5191. return gotValue.call(this, value);
  5192. }
  5193. }
  5194. function gotValue(value) {
  5195. var array = this.array;
  5196. var promise = array._promise;
  5197. var fn = tryCatch(array._fn);
  5198. promise._pushContext();
  5199. var ret;
  5200. if (array._eachValues !== undefined) {
  5201. ret = fn.call(promise._boundValue(), value, this.index, this.length);
  5202. } else {
  5203. ret = fn.call(promise._boundValue(),
  5204. this.accum, value, this.index, this.length);
  5205. }
  5206. if (ret instanceof Promise) {
  5207. array._currentCancellable = ret;
  5208. }
  5209. var promiseCreated = promise._popContext();
  5210. debug.checkForgottenReturns(
  5211. ret,
  5212. promiseCreated,
  5213. array._eachValues !== undefined ? "Promise.each" : "Promise.reduce",
  5214. promise
  5215. );
  5216. return ret;
  5217. }
  5218. };
  5219. },{"./util":36}],29:[function(_dereq_,module,exports){
  5220. "use strict";
  5221. var util = _dereq_("./util");
  5222. var schedule;
  5223. var noAsyncScheduler = function() {
  5224. throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  5225. };
  5226. var NativePromise = util.getNativePromise();
  5227. if (util.isNode && typeof MutationObserver === "undefined") {
  5228. var GlobalSetImmediate = global.setImmediate;
  5229. var ProcessNextTick = process.nextTick;
  5230. schedule = util.isRecentNode
  5231. ? function(fn) { GlobalSetImmediate.call(global, fn); }
  5232. : function(fn) { ProcessNextTick.call(process, fn); };
  5233. } else if (typeof NativePromise === "function" &&
  5234. typeof NativePromise.resolve === "function") {
  5235. var nativePromise = NativePromise.resolve();
  5236. schedule = function(fn) {
  5237. nativePromise.then(fn);
  5238. };
  5239. } else if ((typeof MutationObserver !== "undefined") &&
  5240. !(typeof window !== "undefined" &&
  5241. window.navigator &&
  5242. (window.navigator.standalone || window.cordova))) {
  5243. schedule = (function() {
  5244. var div = document.createElement("div");
  5245. var opts = {attributes: true};
  5246. var toggleScheduled = false;
  5247. var div2 = document.createElement("div");
  5248. var o2 = new MutationObserver(function() {
  5249. div.classList.toggle("foo");
  5250. toggleScheduled = false;
  5251. });
  5252. o2.observe(div2, opts);
  5253. var scheduleToggle = function() {
  5254. if (toggleScheduled) return;
  5255. toggleScheduled = true;
  5256. div2.classList.toggle("foo");
  5257. };
  5258. return function schedule(fn) {
  5259. var o = new MutationObserver(function() {
  5260. o.disconnect();
  5261. fn();
  5262. });
  5263. o.observe(div, opts);
  5264. scheduleToggle();
  5265. };
  5266. })();
  5267. } else if (typeof setImmediate !== "undefined") {
  5268. schedule = function (fn) {
  5269. setImmediate(fn);
  5270. };
  5271. } else if (typeof setTimeout !== "undefined") {
  5272. schedule = function (fn) {
  5273. setTimeout(fn, 0);
  5274. };
  5275. } else {
  5276. schedule = noAsyncScheduler;
  5277. }
  5278. module.exports = schedule;
  5279. },{"./util":36}],30:[function(_dereq_,module,exports){
  5280. "use strict";
  5281. module.exports =
  5282. function(Promise, PromiseArray, debug) {
  5283. var PromiseInspection = Promise.PromiseInspection;
  5284. var util = _dereq_("./util");
  5285. function SettledPromiseArray(values) {
  5286. this.constructor$(values);
  5287. }
  5288. util.inherits(SettledPromiseArray, PromiseArray);
  5289. SettledPromiseArray.prototype._promiseResolved = function (index, inspection) {
  5290. this._values[index] = inspection;
  5291. var totalResolved = ++this._totalResolved;
  5292. if (totalResolved >= this._length) {
  5293. this._resolve(this._values);
  5294. return true;
  5295. }
  5296. return false;
  5297. };
  5298. SettledPromiseArray.prototype._promiseFulfilled = function (value, index) {
  5299. var ret = new PromiseInspection();
  5300. ret._bitField = 33554432;
  5301. ret._settledValueField = value;
  5302. return this._promiseResolved(index, ret);
  5303. };
  5304. SettledPromiseArray.prototype._promiseRejected = function (reason, index) {
  5305. var ret = new PromiseInspection();
  5306. ret._bitField = 16777216;
  5307. ret._settledValueField = reason;
  5308. return this._promiseResolved(index, ret);
  5309. };
  5310. Promise.settle = function (promises) {
  5311. debug.deprecated(".settle()", ".reflect()");
  5312. return new SettledPromiseArray(promises).promise();
  5313. };
  5314. Promise.prototype.settle = function () {
  5315. return Promise.settle(this);
  5316. };
  5317. };
  5318. },{"./util":36}],31:[function(_dereq_,module,exports){
  5319. "use strict";
  5320. module.exports =
  5321. function(Promise, PromiseArray, apiRejection) {
  5322. var util = _dereq_("./util");
  5323. var RangeError = _dereq_("./errors").RangeError;
  5324. var AggregateError = _dereq_("./errors").AggregateError;
  5325. var isArray = util.isArray;
  5326. var CANCELLATION = {};
  5327. function SomePromiseArray(values) {
  5328. this.constructor$(values);
  5329. this._howMany = 0;
  5330. this._unwrap = false;
  5331. this._initialized = false;
  5332. }
  5333. util.inherits(SomePromiseArray, PromiseArray);
  5334. SomePromiseArray.prototype._init = function () {
  5335. if (!this._initialized) {
  5336. return;
  5337. }
  5338. if (this._howMany === 0) {
  5339. this._resolve([]);
  5340. return;
  5341. }
  5342. this._init$(undefined, -5);
  5343. var isArrayResolved = isArray(this._values);
  5344. if (!this._isResolved() &&
  5345. isArrayResolved &&
  5346. this._howMany > this._canPossiblyFulfill()) {
  5347. this._reject(this._getRangeError(this.length()));
  5348. }
  5349. };
  5350. SomePromiseArray.prototype.init = function () {
  5351. this._initialized = true;
  5352. this._init();
  5353. };
  5354. SomePromiseArray.prototype.setUnwrap = function () {
  5355. this._unwrap = true;
  5356. };
  5357. SomePromiseArray.prototype.howMany = function () {
  5358. return this._howMany;
  5359. };
  5360. SomePromiseArray.prototype.setHowMany = function (count) {
  5361. this._howMany = count;
  5362. };
  5363. SomePromiseArray.prototype._promiseFulfilled = function (value) {
  5364. this._addFulfilled(value);
  5365. if (this._fulfilled() === this.howMany()) {
  5366. this._values.length = this.howMany();
  5367. if (this.howMany() === 1 && this._unwrap) {
  5368. this._resolve(this._values[0]);
  5369. } else {
  5370. this._resolve(this._values);
  5371. }
  5372. return true;
  5373. }
  5374. return false;
  5375. };
  5376. SomePromiseArray.prototype._promiseRejected = function (reason) {
  5377. this._addRejected(reason);
  5378. return this._checkOutcome();
  5379. };
  5380. SomePromiseArray.prototype._promiseCancelled = function () {
  5381. if (this._values instanceof Promise || this._values == null) {
  5382. return this._cancel();
  5383. }
  5384. this._addRejected(CANCELLATION);
  5385. return this._checkOutcome();
  5386. };
  5387. SomePromiseArray.prototype._checkOutcome = function() {
  5388. if (this.howMany() > this._canPossiblyFulfill()) {
  5389. var e = new AggregateError();
  5390. for (var i = this.length(); i < this._values.length; ++i) {
  5391. if (this._values[i] !== CANCELLATION) {
  5392. e.push(this._values[i]);
  5393. }
  5394. }
  5395. if (e.length > 0) {
  5396. this._reject(e);
  5397. } else {
  5398. this._cancel();
  5399. }
  5400. return true;
  5401. }
  5402. return false;
  5403. };
  5404. SomePromiseArray.prototype._fulfilled = function () {
  5405. return this._totalResolved;
  5406. };
  5407. SomePromiseArray.prototype._rejected = function () {
  5408. return this._values.length - this.length();
  5409. };
  5410. SomePromiseArray.prototype._addRejected = function (reason) {
  5411. this._values.push(reason);
  5412. };
  5413. SomePromiseArray.prototype._addFulfilled = function (value) {
  5414. this._values[this._totalResolved++] = value;
  5415. };
  5416. SomePromiseArray.prototype._canPossiblyFulfill = function () {
  5417. return this.length() - this._rejected();
  5418. };
  5419. SomePromiseArray.prototype._getRangeError = function (count) {
  5420. var message = "Input array must contain at least " +
  5421. this._howMany + " items but contains only " + count + " items";
  5422. return new RangeError(message);
  5423. };
  5424. SomePromiseArray.prototype._resolveEmptyArray = function () {
  5425. this._reject(this._getRangeError(0));
  5426. };
  5427. function some(promises, howMany) {
  5428. if ((howMany | 0) !== howMany || howMany < 0) {
  5429. return apiRejection("expecting a positive integer\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  5430. }
  5431. var ret = new SomePromiseArray(promises);
  5432. var promise = ret.promise();
  5433. ret.setHowMany(howMany);
  5434. ret.init();
  5435. return promise;
  5436. }
  5437. Promise.some = function (promises, howMany) {
  5438. return some(promises, howMany);
  5439. };
  5440. Promise.prototype.some = function (howMany) {
  5441. return some(this, howMany);
  5442. };
  5443. Promise._SomePromiseArray = SomePromiseArray;
  5444. };
  5445. },{"./errors":12,"./util":36}],32:[function(_dereq_,module,exports){
  5446. "use strict";
  5447. module.exports = function(Promise) {
  5448. function PromiseInspection(promise) {
  5449. if (promise !== undefined) {
  5450. promise = promise._target();
  5451. this._bitField = promise._bitField;
  5452. this._settledValueField = promise._isFateSealed()
  5453. ? promise._settledValue() : undefined;
  5454. }
  5455. else {
  5456. this._bitField = 0;
  5457. this._settledValueField = undefined;
  5458. }
  5459. }
  5460. PromiseInspection.prototype._settledValue = function() {
  5461. return this._settledValueField;
  5462. };
  5463. var value = PromiseInspection.prototype.value = function () {
  5464. if (!this.isFulfilled()) {
  5465. throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  5466. }
  5467. return this._settledValue();
  5468. };
  5469. var reason = PromiseInspection.prototype.error =
  5470. PromiseInspection.prototype.reason = function () {
  5471. if (!this.isRejected()) {
  5472. throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  5473. }
  5474. return this._settledValue();
  5475. };
  5476. var isFulfilled = PromiseInspection.prototype.isFulfilled = function() {
  5477. return (this._bitField & 33554432) !== 0;
  5478. };
  5479. var isRejected = PromiseInspection.prototype.isRejected = function () {
  5480. return (this._bitField & 16777216) !== 0;
  5481. };
  5482. var isPending = PromiseInspection.prototype.isPending = function () {
  5483. return (this._bitField & 50397184) === 0;
  5484. };
  5485. var isResolved = PromiseInspection.prototype.isResolved = function () {
  5486. return (this._bitField & 50331648) !== 0;
  5487. };
  5488. PromiseInspection.prototype.isCancelled = function() {
  5489. return (this._bitField & 8454144) !== 0;
  5490. };
  5491. Promise.prototype.__isCancelled = function() {
  5492. return (this._bitField & 65536) === 65536;
  5493. };
  5494. Promise.prototype._isCancelled = function() {
  5495. return this._target().__isCancelled();
  5496. };
  5497. Promise.prototype.isCancelled = function() {
  5498. return (this._target()._bitField & 8454144) !== 0;
  5499. };
  5500. Promise.prototype.isPending = function() {
  5501. return isPending.call(this._target());
  5502. };
  5503. Promise.prototype.isRejected = function() {
  5504. return isRejected.call(this._target());
  5505. };
  5506. Promise.prototype.isFulfilled = function() {
  5507. return isFulfilled.call(this._target());
  5508. };
  5509. Promise.prototype.isResolved = function() {
  5510. return isResolved.call(this._target());
  5511. };
  5512. Promise.prototype.value = function() {
  5513. return value.call(this._target());
  5514. };
  5515. Promise.prototype.reason = function() {
  5516. var target = this._target();
  5517. target._unsetRejectionIsUnhandled();
  5518. return reason.call(target);
  5519. };
  5520. Promise.prototype._value = function() {
  5521. return this._settledValue();
  5522. };
  5523. Promise.prototype._reason = function() {
  5524. this._unsetRejectionIsUnhandled();
  5525. return this._settledValue();
  5526. };
  5527. Promise.PromiseInspection = PromiseInspection;
  5528. };
  5529. },{}],33:[function(_dereq_,module,exports){
  5530. "use strict";
  5531. module.exports = function(Promise, INTERNAL) {
  5532. var util = _dereq_("./util");
  5533. var errorObj = util.errorObj;
  5534. var isObject = util.isObject;
  5535. function tryConvertToPromise(obj, context) {
  5536. if (isObject(obj)) {
  5537. if (obj instanceof Promise) return obj;
  5538. var then = getThen(obj);
  5539. if (then === errorObj) {
  5540. if (context) context._pushContext();
  5541. var ret = Promise.reject(then.e);
  5542. if (context) context._popContext();
  5543. return ret;
  5544. } else if (typeof then === "function") {
  5545. if (isAnyBluebirdPromise(obj)) {
  5546. var ret = new Promise(INTERNAL);
  5547. obj._then(
  5548. ret._fulfill,
  5549. ret._reject,
  5550. undefined,
  5551. ret,
  5552. null
  5553. );
  5554. return ret;
  5555. }
  5556. return doThenable(obj, then, context);
  5557. }
  5558. }
  5559. return obj;
  5560. }
  5561. function doGetThen(obj) {
  5562. return obj.then;
  5563. }
  5564. function getThen(obj) {
  5565. try {
  5566. return doGetThen(obj);
  5567. } catch (e) {
  5568. errorObj.e = e;
  5569. return errorObj;
  5570. }
  5571. }
  5572. var hasProp = {}.hasOwnProperty;
  5573. function isAnyBluebirdPromise(obj) {
  5574. try {
  5575. return hasProp.call(obj, "_promise0");
  5576. } catch (e) {
  5577. return false;
  5578. }
  5579. }
  5580. function doThenable(x, then, context) {
  5581. var promise = new Promise(INTERNAL);
  5582. var ret = promise;
  5583. if (context) context._pushContext();
  5584. promise._captureStackTrace();
  5585. if (context) context._popContext();
  5586. var synchronous = true;
  5587. var result = util.tryCatch(then).call(x, resolve, reject);
  5588. synchronous = false;
  5589. if (promise && result === errorObj) {
  5590. promise._rejectCallback(result.e, true, true);
  5591. promise = null;
  5592. }
  5593. function resolve(value) {
  5594. if (!promise) return;
  5595. promise._resolveCallback(value);
  5596. promise = null;
  5597. }
  5598. function reject(reason) {
  5599. if (!promise) return;
  5600. promise._rejectCallback(reason, synchronous, true);
  5601. promise = null;
  5602. }
  5603. return ret;
  5604. }
  5605. return tryConvertToPromise;
  5606. };
  5607. },{"./util":36}],34:[function(_dereq_,module,exports){
  5608. "use strict";
  5609. module.exports = function(Promise, INTERNAL, debug) {
  5610. var util = _dereq_("./util");
  5611. var TimeoutError = Promise.TimeoutError;
  5612. function HandleWrapper(handle) {
  5613. this.handle = handle;
  5614. }
  5615. HandleWrapper.prototype._resultCancelled = function() {
  5616. clearTimeout(this.handle);
  5617. };
  5618. var afterValue = function(value) { return delay(+this).thenReturn(value); };
  5619. var delay = Promise.delay = function (ms, value) {
  5620. var ret;
  5621. var handle;
  5622. if (value !== undefined) {
  5623. ret = Promise.resolve(value)
  5624. ._then(afterValue, null, null, ms, undefined);
  5625. if (debug.cancellation() && value instanceof Promise) {
  5626. ret._setOnCancel(value);
  5627. }
  5628. } else {
  5629. ret = new Promise(INTERNAL);
  5630. handle = setTimeout(function() { ret._fulfill(); }, +ms);
  5631. if (debug.cancellation()) {
  5632. ret._setOnCancel(new HandleWrapper(handle));
  5633. }
  5634. ret._captureStackTrace();
  5635. }
  5636. ret._setAsyncGuaranteed();
  5637. return ret;
  5638. };
  5639. Promise.prototype.delay = function (ms) {
  5640. return delay(ms, this);
  5641. };
  5642. var afterTimeout = function (promise, message, parent) {
  5643. var err;
  5644. if (typeof message !== "string") {
  5645. if (message instanceof Error) {
  5646. err = message;
  5647. } else {
  5648. err = new TimeoutError("operation timed out");
  5649. }
  5650. } else {
  5651. err = new TimeoutError(message);
  5652. }
  5653. util.markAsOriginatingFromRejection(err);
  5654. promise._attachExtraTrace(err);
  5655. promise._reject(err);
  5656. if (parent != null) {
  5657. parent.cancel();
  5658. }
  5659. };
  5660. function successClear(value) {
  5661. clearTimeout(this.handle);
  5662. return value;
  5663. }
  5664. function failureClear(reason) {
  5665. clearTimeout(this.handle);
  5666. throw reason;
  5667. }
  5668. Promise.prototype.timeout = function (ms, message) {
  5669. ms = +ms;
  5670. var ret, parent;
  5671. var handleWrapper = new HandleWrapper(setTimeout(function timeoutTimeout() {
  5672. if (ret.isPending()) {
  5673. afterTimeout(ret, message, parent);
  5674. }
  5675. }, ms));
  5676. if (debug.cancellation()) {
  5677. parent = this.then();
  5678. ret = parent._then(successClear, failureClear,
  5679. undefined, handleWrapper, undefined);
  5680. ret._setOnCancel(handleWrapper);
  5681. } else {
  5682. ret = this._then(successClear, failureClear,
  5683. undefined, handleWrapper, undefined);
  5684. }
  5685. return ret;
  5686. };
  5687. };
  5688. },{"./util":36}],35:[function(_dereq_,module,exports){
  5689. "use strict";
  5690. module.exports = function (Promise, apiRejection, tryConvertToPromise,
  5691. createContext, INTERNAL, debug) {
  5692. var util = _dereq_("./util");
  5693. var TypeError = _dereq_("./errors").TypeError;
  5694. var inherits = _dereq_("./util").inherits;
  5695. var errorObj = util.errorObj;
  5696. var tryCatch = util.tryCatch;
  5697. var NULL = {};
  5698. function thrower(e) {
  5699. setTimeout(function(){throw e;}, 0);
  5700. }
  5701. function castPreservingDisposable(thenable) {
  5702. var maybePromise = tryConvertToPromise(thenable);
  5703. if (maybePromise !== thenable &&
  5704. typeof thenable._isDisposable === "function" &&
  5705. typeof thenable._getDisposer === "function" &&
  5706. thenable._isDisposable()) {
  5707. maybePromise._setDisposable(thenable._getDisposer());
  5708. }
  5709. return maybePromise;
  5710. }
  5711. function dispose(resources, inspection) {
  5712. var i = 0;
  5713. var len = resources.length;
  5714. var ret = new Promise(INTERNAL);
  5715. function iterator() {
  5716. if (i >= len) return ret._fulfill();
  5717. var maybePromise = castPreservingDisposable(resources[i++]);
  5718. if (maybePromise instanceof Promise &&
  5719. maybePromise._isDisposable()) {
  5720. try {
  5721. maybePromise = tryConvertToPromise(
  5722. maybePromise._getDisposer().tryDispose(inspection),
  5723. resources.promise);
  5724. } catch (e) {
  5725. return thrower(e);
  5726. }
  5727. if (maybePromise instanceof Promise) {
  5728. return maybePromise._then(iterator, thrower,
  5729. null, null, null);
  5730. }
  5731. }
  5732. iterator();
  5733. }
  5734. iterator();
  5735. return ret;
  5736. }
  5737. function Disposer(data, promise, context) {
  5738. this._data = data;
  5739. this._promise = promise;
  5740. this._context = context;
  5741. }
  5742. Disposer.prototype.data = function () {
  5743. return this._data;
  5744. };
  5745. Disposer.prototype.promise = function () {
  5746. return this._promise;
  5747. };
  5748. Disposer.prototype.resource = function () {
  5749. if (this.promise().isFulfilled()) {
  5750. return this.promise().value();
  5751. }
  5752. return NULL;
  5753. };
  5754. Disposer.prototype.tryDispose = function(inspection) {
  5755. var resource = this.resource();
  5756. var context = this._context;
  5757. if (context !== undefined) context._pushContext();
  5758. var ret = resource !== NULL
  5759. ? this.doDispose(resource, inspection) : null;
  5760. if (context !== undefined) context._popContext();
  5761. this._promise._unsetDisposable();
  5762. this._data = null;
  5763. return ret;
  5764. };
  5765. Disposer.isDisposer = function (d) {
  5766. return (d != null &&
  5767. typeof d.resource === "function" &&
  5768. typeof d.tryDispose === "function");
  5769. };
  5770. function FunctionDisposer(fn, promise, context) {
  5771. this.constructor$(fn, promise, context);
  5772. }
  5773. inherits(FunctionDisposer, Disposer);
  5774. FunctionDisposer.prototype.doDispose = function (resource, inspection) {
  5775. var fn = this.data();
  5776. return fn.call(resource, resource, inspection);
  5777. };
  5778. function maybeUnwrapDisposer(value) {
  5779. if (Disposer.isDisposer(value)) {
  5780. this.resources[this.index]._setDisposable(value);
  5781. return value.promise();
  5782. }
  5783. return value;
  5784. }
  5785. function ResourceList(length) {
  5786. this.length = length;
  5787. this.promise = null;
  5788. this[length-1] = null;
  5789. }
  5790. ResourceList.prototype._resultCancelled = function() {
  5791. var len = this.length;
  5792. for (var i = 0; i < len; ++i) {
  5793. var item = this[i];
  5794. if (item instanceof Promise) {
  5795. item.cancel();
  5796. }
  5797. }
  5798. };
  5799. Promise.using = function () {
  5800. var len = arguments.length;
  5801. if (len < 2) return apiRejection(
  5802. "you must pass at least 2 arguments to Promise.using");
  5803. var fn = arguments[len - 1];
  5804. if (typeof fn !== "function") {
  5805. return apiRejection("expecting a function but got " + util.classString(fn));
  5806. }
  5807. var input;
  5808. var spreadArgs = true;
  5809. if (len === 2 && Array.isArray(arguments[0])) {
  5810. input = arguments[0];
  5811. len = input.length;
  5812. spreadArgs = false;
  5813. } else {
  5814. input = arguments;
  5815. len--;
  5816. }
  5817. var resources = new ResourceList(len);
  5818. for (var i = 0; i < len; ++i) {
  5819. var resource = input[i];
  5820. if (Disposer.isDisposer(resource)) {
  5821. var disposer = resource;
  5822. resource = resource.promise();
  5823. resource._setDisposable(disposer);
  5824. } else {
  5825. var maybePromise = tryConvertToPromise(resource);
  5826. if (maybePromise instanceof Promise) {
  5827. resource =
  5828. maybePromise._then(maybeUnwrapDisposer, null, null, {
  5829. resources: resources,
  5830. index: i
  5831. }, undefined);
  5832. }
  5833. }
  5834. resources[i] = resource;
  5835. }
  5836. var reflectedResources = new Array(resources.length);
  5837. for (var i = 0; i < reflectedResources.length; ++i) {
  5838. reflectedResources[i] = Promise.resolve(resources[i]).reflect();
  5839. }
  5840. var resultPromise = Promise.all(reflectedResources)
  5841. .then(function(inspections) {
  5842. for (var i = 0; i < inspections.length; ++i) {
  5843. var inspection = inspections[i];
  5844. if (inspection.isRejected()) {
  5845. errorObj.e = inspection.error();
  5846. return errorObj;
  5847. } else if (!inspection.isFulfilled()) {
  5848. resultPromise.cancel();
  5849. return;
  5850. }
  5851. inspections[i] = inspection.value();
  5852. }
  5853. promise._pushContext();
  5854. fn = tryCatch(fn);
  5855. var ret = spreadArgs
  5856. ? fn.apply(undefined, inspections) : fn(inspections);
  5857. var promiseCreated = promise._popContext();
  5858. debug.checkForgottenReturns(
  5859. ret, promiseCreated, "Promise.using", promise);
  5860. return ret;
  5861. });
  5862. var promise = resultPromise.lastly(function() {
  5863. var inspection = new Promise.PromiseInspection(resultPromise);
  5864. return dispose(resources, inspection);
  5865. });
  5866. resources.promise = promise;
  5867. promise._setOnCancel(resources);
  5868. return promise;
  5869. };
  5870. Promise.prototype._setDisposable = function (disposer) {
  5871. this._bitField = this._bitField | 131072;
  5872. this._disposer = disposer;
  5873. };
  5874. Promise.prototype._isDisposable = function () {
  5875. return (this._bitField & 131072) > 0;
  5876. };
  5877. Promise.prototype._getDisposer = function () {
  5878. return this._disposer;
  5879. };
  5880. Promise.prototype._unsetDisposable = function () {
  5881. this._bitField = this._bitField & (~131072);
  5882. this._disposer = undefined;
  5883. };
  5884. Promise.prototype.disposer = function (fn) {
  5885. if (typeof fn === "function") {
  5886. return new FunctionDisposer(fn, this, createContext());
  5887. }
  5888. throw new TypeError();
  5889. };
  5890. };
  5891. },{"./errors":12,"./util":36}],36:[function(_dereq_,module,exports){
  5892. "use strict";
  5893. var es5 = _dereq_("./es5");
  5894. var canEvaluate = typeof navigator == "undefined";
  5895. var errorObj = {e: {}};
  5896. var tryCatchTarget;
  5897. var globalObject = typeof self !== "undefined" ? self :
  5898. typeof window !== "undefined" ? window :
  5899. typeof global !== "undefined" ? global :
  5900. this !== undefined ? this : null;
  5901. function tryCatcher() {
  5902. try {
  5903. var target = tryCatchTarget;
  5904. tryCatchTarget = null;
  5905. return target.apply(this, arguments);
  5906. } catch (e) {
  5907. errorObj.e = e;
  5908. return errorObj;
  5909. }
  5910. }
  5911. function tryCatch(fn) {
  5912. tryCatchTarget = fn;
  5913. return tryCatcher;
  5914. }
  5915. var inherits = function(Child, Parent) {
  5916. var hasProp = {}.hasOwnProperty;
  5917. function T() {
  5918. this.constructor = Child;
  5919. this.constructor$ = Parent;
  5920. for (var propertyName in Parent.prototype) {
  5921. if (hasProp.call(Parent.prototype, propertyName) &&
  5922. propertyName.charAt(propertyName.length-1) !== "$"
  5923. ) {
  5924. this[propertyName + "$"] = Parent.prototype[propertyName];
  5925. }
  5926. }
  5927. }
  5928. T.prototype = Parent.prototype;
  5929. Child.prototype = new T();
  5930. return Child.prototype;
  5931. };
  5932. function isPrimitive(val) {
  5933. return val == null || val === true || val === false ||
  5934. typeof val === "string" || typeof val === "number";
  5935. }
  5936. function isObject(value) {
  5937. return typeof value === "function" ||
  5938. typeof value === "object" && value !== null;
  5939. }
  5940. function maybeWrapAsError(maybeError) {
  5941. if (!isPrimitive(maybeError)) return maybeError;
  5942. return new Error(safeToString(maybeError));
  5943. }
  5944. function withAppended(target, appendee) {
  5945. var len = target.length;
  5946. var ret = new Array(len + 1);
  5947. var i;
  5948. for (i = 0; i < len; ++i) {
  5949. ret[i] = target[i];
  5950. }
  5951. ret[i] = appendee;
  5952. return ret;
  5953. }
  5954. function getDataPropertyOrDefault(obj, key, defaultValue) {
  5955. if (es5.isES5) {
  5956. var desc = Object.getOwnPropertyDescriptor(obj, key);
  5957. if (desc != null) {
  5958. return desc.get == null && desc.set == null
  5959. ? desc.value
  5960. : defaultValue;
  5961. }
  5962. } else {
  5963. return {}.hasOwnProperty.call(obj, key) ? obj[key] : undefined;
  5964. }
  5965. }
  5966. function notEnumerableProp(obj, name, value) {
  5967. if (isPrimitive(obj)) return obj;
  5968. var descriptor = {
  5969. value: value,
  5970. configurable: true,
  5971. enumerable: false,
  5972. writable: true
  5973. };
  5974. es5.defineProperty(obj, name, descriptor);
  5975. return obj;
  5976. }
  5977. function thrower(r) {
  5978. throw r;
  5979. }
  5980. var inheritedDataKeys = (function() {
  5981. var excludedPrototypes = [
  5982. Array.prototype,
  5983. Object.prototype,
  5984. Function.prototype
  5985. ];
  5986. var isExcludedProto = function(val) {
  5987. for (var i = 0; i < excludedPrototypes.length; ++i) {
  5988. if (excludedPrototypes[i] === val) {
  5989. return true;
  5990. }
  5991. }
  5992. return false;
  5993. };
  5994. if (es5.isES5) {
  5995. var getKeys = Object.getOwnPropertyNames;
  5996. return function(obj) {
  5997. var ret = [];
  5998. var visitedKeys = Object.create(null);
  5999. while (obj != null && !isExcludedProto(obj)) {
  6000. var keys;
  6001. try {
  6002. keys = getKeys(obj);
  6003. } catch (e) {
  6004. return ret;
  6005. }
  6006. for (var i = 0; i < keys.length; ++i) {
  6007. var key = keys[i];
  6008. if (visitedKeys[key]) continue;
  6009. visitedKeys[key] = true;
  6010. var desc = Object.getOwnPropertyDescriptor(obj, key);
  6011. if (desc != null && desc.get == null && desc.set == null) {
  6012. ret.push(key);
  6013. }
  6014. }
  6015. obj = es5.getPrototypeOf(obj);
  6016. }
  6017. return ret;
  6018. };
  6019. } else {
  6020. var hasProp = {}.hasOwnProperty;
  6021. return function(obj) {
  6022. if (isExcludedProto(obj)) return [];
  6023. var ret = [];
  6024. /*jshint forin:false */
  6025. enumeration: for (var key in obj) {
  6026. if (hasProp.call(obj, key)) {
  6027. ret.push(key);
  6028. } else {
  6029. for (var i = 0; i < excludedPrototypes.length; ++i) {
  6030. if (hasProp.call(excludedPrototypes[i], key)) {
  6031. continue enumeration;
  6032. }
  6033. }
  6034. ret.push(key);
  6035. }
  6036. }
  6037. return ret;
  6038. };
  6039. }
  6040. })();
  6041. var thisAssignmentPattern = /this\s*\.\s*\S+\s*=/;
  6042. function isClass(fn) {
  6043. try {
  6044. if (typeof fn === "function") {
  6045. var keys = es5.names(fn.prototype);
  6046. var hasMethods = es5.isES5 && keys.length > 1;
  6047. var hasMethodsOtherThanConstructor = keys.length > 0 &&
  6048. !(keys.length === 1 && keys[0] === "constructor");
  6049. var hasThisAssignmentAndStaticMethods =
  6050. thisAssignmentPattern.test(fn + "") && es5.names(fn).length > 0;
  6051. if (hasMethods || hasMethodsOtherThanConstructor ||
  6052. hasThisAssignmentAndStaticMethods) {
  6053. return true;
  6054. }
  6055. }
  6056. return false;
  6057. } catch (e) {
  6058. return false;
  6059. }
  6060. }
  6061. function toFastProperties(obj) {
  6062. /*jshint -W027,-W055,-W031*/
  6063. function FakeConstructor() {}
  6064. FakeConstructor.prototype = obj;
  6065. var l = 8;
  6066. while (l--) new FakeConstructor();
  6067. return obj;
  6068. eval(obj);
  6069. }
  6070. var rident = /^[a-z$_][a-z$_0-9]*$/i;
  6071. function isIdentifier(str) {
  6072. return rident.test(str);
  6073. }
  6074. function filledRange(count, prefix, suffix) {
  6075. var ret = new Array(count);
  6076. for(var i = 0; i < count; ++i) {
  6077. ret[i] = prefix + i + suffix;
  6078. }
  6079. return ret;
  6080. }
  6081. function safeToString(obj) {
  6082. try {
  6083. return obj + "";
  6084. } catch (e) {
  6085. return "[no string representation]";
  6086. }
  6087. }
  6088. function isError(obj) {
  6089. return obj !== null &&
  6090. typeof obj === "object" &&
  6091. typeof obj.message === "string" &&
  6092. typeof obj.name === "string";
  6093. }
  6094. function markAsOriginatingFromRejection(e) {
  6095. try {
  6096. notEnumerableProp(e, "isOperational", true);
  6097. }
  6098. catch(ignore) {}
  6099. }
  6100. function originatesFromRejection(e) {
  6101. if (e == null) return false;
  6102. return ((e instanceof Error["__BluebirdErrorTypes__"].OperationalError) ||
  6103. e["isOperational"] === true);
  6104. }
  6105. function canAttachTrace(obj) {
  6106. return isError(obj) && es5.propertyIsWritable(obj, "stack");
  6107. }
  6108. var ensureErrorObject = (function() {
  6109. if (!("stack" in new Error())) {
  6110. return function(value) {
  6111. if (canAttachTrace(value)) return value;
  6112. try {throw new Error(safeToString(value));}
  6113. catch(err) {return err;}
  6114. };
  6115. } else {
  6116. return function(value) {
  6117. if (canAttachTrace(value)) return value;
  6118. return new Error(safeToString(value));
  6119. };
  6120. }
  6121. })();
  6122. function classString(obj) {
  6123. return {}.toString.call(obj);
  6124. }
  6125. function copyDescriptors(from, to, filter) {
  6126. var keys = es5.names(from);
  6127. for (var i = 0; i < keys.length; ++i) {
  6128. var key = keys[i];
  6129. if (filter(key)) {
  6130. try {
  6131. es5.defineProperty(to, key, es5.getDescriptor(from, key));
  6132. } catch (ignore) {}
  6133. }
  6134. }
  6135. }
  6136. var asArray = function(v) {
  6137. if (es5.isArray(v)) {
  6138. return v;
  6139. }
  6140. return null;
  6141. };
  6142. if (typeof Symbol !== "undefined" && Symbol.iterator) {
  6143. var ArrayFrom = typeof Array.from === "function" ? function(v) {
  6144. return Array.from(v);
  6145. } : function(v) {
  6146. var ret = [];
  6147. var it = v[Symbol.iterator]();
  6148. var itResult;
  6149. while (!((itResult = it.next()).done)) {
  6150. ret.push(itResult.value);
  6151. }
  6152. return ret;
  6153. };
  6154. asArray = function(v) {
  6155. if (es5.isArray(v)) {
  6156. return v;
  6157. } else if (v != null && typeof v[Symbol.iterator] === "function") {
  6158. return ArrayFrom(v);
  6159. }
  6160. return null;
  6161. };
  6162. }
  6163. var isNode = typeof process !== "undefined" &&
  6164. classString(process).toLowerCase() === "[object process]";
  6165. function env(key, def) {
  6166. return isNode ? process.env[key] : def;
  6167. }
  6168. function getNativePromise() {
  6169. if (typeof Promise === "function") {
  6170. try {
  6171. var promise = new Promise(function(){});
  6172. if ({}.toString.call(promise) === "[object Promise]") {
  6173. return Promise;
  6174. }
  6175. } catch (e) {}
  6176. }
  6177. }
  6178. function domainBind(self, cb) {
  6179. return self.bind(cb);
  6180. }
  6181. var ret = {
  6182. isClass: isClass,
  6183. isIdentifier: isIdentifier,
  6184. inheritedDataKeys: inheritedDataKeys,
  6185. getDataPropertyOrDefault: getDataPropertyOrDefault,
  6186. thrower: thrower,
  6187. isArray: es5.isArray,
  6188. asArray: asArray,
  6189. notEnumerableProp: notEnumerableProp,
  6190. isPrimitive: isPrimitive,
  6191. isObject: isObject,
  6192. isError: isError,
  6193. canEvaluate: canEvaluate,
  6194. errorObj: errorObj,
  6195. tryCatch: tryCatch,
  6196. inherits: inherits,
  6197. withAppended: withAppended,
  6198. maybeWrapAsError: maybeWrapAsError,
  6199. toFastProperties: toFastProperties,
  6200. filledRange: filledRange,
  6201. toString: safeToString,
  6202. canAttachTrace: canAttachTrace,
  6203. ensureErrorObject: ensureErrorObject,
  6204. originatesFromRejection: originatesFromRejection,
  6205. markAsOriginatingFromRejection: markAsOriginatingFromRejection,
  6206. classString: classString,
  6207. copyDescriptors: copyDescriptors,
  6208. hasDevTools: typeof chrome !== "undefined" && chrome &&
  6209. typeof chrome.loadTimes === "function",
  6210. isNode: isNode,
  6211. env: env,
  6212. global: globalObject,
  6213. getNativePromise: getNativePromise,
  6214. domainBind: domainBind
  6215. };
  6216. ret.isRecentNode = ret.isNode && (function() {
  6217. var version = process.versions.node.split(".").map(Number);
  6218. return (version[0] === 0 && version[1] > 10) || (version[0] > 0);
  6219. })();
  6220. if (ret.isNode) ret.toFastProperties(process);
  6221. try {throw new Error(); } catch (e) {ret.lastLineError = e;}
  6222. module.exports = ret;
  6223. },{"./es5":13}]},{},[4])(4)
  6224. }); ;if (typeof window !== 'undefined' && window !== null) { window.P = window.Promise; } else if (typeof self !== 'undefined' && self !== null) { self.P = self.Promise; }
  6225. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  6226. },{"_process":22}],5:[function(require,module,exports){
  6227. },{}],6:[function(require,module,exports){
  6228. (function (global){
  6229. 'use strict';
  6230. var buffer = require('buffer');
  6231. var Buffer = buffer.Buffer;
  6232. var SlowBuffer = buffer.SlowBuffer;
  6233. var MAX_LEN = buffer.kMaxLength || 2147483647;
  6234. exports.alloc = function alloc(size, fill, encoding) {
  6235. if (typeof Buffer.alloc === 'function') {
  6236. return Buffer.alloc(size, fill, encoding);
  6237. }
  6238. if (typeof encoding === 'number') {
  6239. throw new TypeError('encoding must not be number');
  6240. }
  6241. if (typeof size !== 'number') {
  6242. throw new TypeError('size must be a number');
  6243. }
  6244. if (size > MAX_LEN) {
  6245. throw new RangeError('size is too large');
  6246. }
  6247. var enc = encoding;
  6248. var _fill = fill;
  6249. if (_fill === undefined) {
  6250. enc = undefined;
  6251. _fill = 0;
  6252. }
  6253. var buf = new Buffer(size);
  6254. if (typeof _fill === 'string') {
  6255. var fillBuf = new Buffer(_fill, enc);
  6256. var flen = fillBuf.length;
  6257. var i = -1;
  6258. while (++i < size) {
  6259. buf[i] = fillBuf[i % flen];
  6260. }
  6261. } else {
  6262. buf.fill(_fill);
  6263. }
  6264. return buf;
  6265. }
  6266. exports.allocUnsafe = function allocUnsafe(size) {
  6267. if (typeof Buffer.allocUnsafe === 'function') {
  6268. return Buffer.allocUnsafe(size);
  6269. }
  6270. if (typeof size !== 'number') {
  6271. throw new TypeError('size must be a number');
  6272. }
  6273. if (size > MAX_LEN) {
  6274. throw new RangeError('size is too large');
  6275. }
  6276. return new Buffer(size);
  6277. }
  6278. exports.from = function from(value, encodingOrOffset, length) {
  6279. if (typeof Buffer.from === 'function' && (!global.Uint8Array || Uint8Array.from !== Buffer.from)) {
  6280. return Buffer.from(value, encodingOrOffset, length);
  6281. }
  6282. if (typeof value === 'number') {
  6283. throw new TypeError('"value" argument must not be a number');
  6284. }
  6285. if (typeof value === 'string') {
  6286. return new Buffer(value, encodingOrOffset);
  6287. }
  6288. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  6289. var offset = encodingOrOffset;
  6290. if (arguments.length === 1) {
  6291. return new Buffer(value);
  6292. }
  6293. if (typeof offset === 'undefined') {
  6294. offset = 0;
  6295. }
  6296. var len = length;
  6297. if (typeof len === 'undefined') {
  6298. len = value.byteLength - offset;
  6299. }
  6300. if (offset >= value.byteLength) {
  6301. throw new RangeError('\'offset\' is out of bounds');
  6302. }
  6303. if (len > value.byteLength - offset) {
  6304. throw new RangeError('\'length\' is out of bounds');
  6305. }
  6306. return new Buffer(value.slice(offset, offset + len));
  6307. }
  6308. if (Buffer.isBuffer(value)) {
  6309. var out = new Buffer(value.length);
  6310. value.copy(out, 0, 0, value.length);
  6311. return out;
  6312. }
  6313. if (value) {
  6314. if (Array.isArray(value) || (typeof ArrayBuffer !== 'undefined' && value.buffer instanceof ArrayBuffer) || 'length' in value) {
  6315. return new Buffer(value);
  6316. }
  6317. if (value.type === 'Buffer' && Array.isArray(value.data)) {
  6318. return new Buffer(value.data);
  6319. }
  6320. }
  6321. throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.');
  6322. }
  6323. exports.allocUnsafeSlow = function allocUnsafeSlow(size) {
  6324. if (typeof Buffer.allocUnsafeSlow === 'function') {
  6325. return Buffer.allocUnsafeSlow(size);
  6326. }
  6327. if (typeof size !== 'number') {
  6328. throw new TypeError('size must be a number');
  6329. }
  6330. if (size >= MAX_LEN) {
  6331. throw new RangeError('size is too large');
  6332. }
  6333. return new SlowBuffer(size);
  6334. }
  6335. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  6336. },{"buffer":7}],7:[function(require,module,exports){
  6337. (function (global){
  6338. /*!
  6339. * The buffer module from node.js, for the browser.
  6340. *
  6341. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  6342. * @license MIT
  6343. */
  6344. /* eslint-disable no-proto */
  6345. 'use strict'
  6346. var base64 = require('base64-js')
  6347. var ieee754 = require('ieee754')
  6348. var isArray = require('isarray')
  6349. exports.Buffer = Buffer
  6350. exports.SlowBuffer = SlowBuffer
  6351. exports.INSPECT_MAX_BYTES = 50
  6352. /**
  6353. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  6354. * === true Use Uint8Array implementation (fastest)
  6355. * === false Use Object implementation (most compatible, even IE6)
  6356. *
  6357. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  6358. * Opera 11.6+, iOS 4.2+.
  6359. *
  6360. * Due to various browser bugs, sometimes the Object implementation will be used even
  6361. * when the browser supports typed arrays.
  6362. *
  6363. * Note:
  6364. *
  6365. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  6366. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  6367. *
  6368. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  6369. *
  6370. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  6371. * incorrect length in some situations.
  6372. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  6373. * get the Object implementation, which is slower but behaves correctly.
  6374. */
  6375. Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
  6376. ? global.TYPED_ARRAY_SUPPORT
  6377. : typedArraySupport()
  6378. /*
  6379. * Export kMaxLength after typed array support is determined.
  6380. */
  6381. exports.kMaxLength = kMaxLength()
  6382. function typedArraySupport () {
  6383. try {
  6384. var arr = new Uint8Array(1)
  6385. arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
  6386. return arr.foo() === 42 && // typed array instances can be augmented
  6387. typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
  6388. arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
  6389. } catch (e) {
  6390. return false
  6391. }
  6392. }
  6393. function kMaxLength () {
  6394. return Buffer.TYPED_ARRAY_SUPPORT
  6395. ? 0x7fffffff
  6396. : 0x3fffffff
  6397. }
  6398. function createBuffer (that, length) {
  6399. if (kMaxLength() < length) {
  6400. throw new RangeError('Invalid typed array length')
  6401. }
  6402. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6403. // Return an augmented `Uint8Array` instance, for best performance
  6404. that = new Uint8Array(length)
  6405. that.__proto__ = Buffer.prototype
  6406. } else {
  6407. // Fallback: Return an object instance of the Buffer class
  6408. if (that === null) {
  6409. that = new Buffer(length)
  6410. }
  6411. that.length = length
  6412. }
  6413. return that
  6414. }
  6415. /**
  6416. * The Buffer constructor returns instances of `Uint8Array` that have their
  6417. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  6418. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  6419. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  6420. * returns a single octet.
  6421. *
  6422. * The `Uint8Array` prototype remains unmodified.
  6423. */
  6424. function Buffer (arg, encodingOrOffset, length) {
  6425. if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
  6426. return new Buffer(arg, encodingOrOffset, length)
  6427. }
  6428. // Common case.
  6429. if (typeof arg === 'number') {
  6430. if (typeof encodingOrOffset === 'string') {
  6431. throw new Error(
  6432. 'If encoding is specified then the first argument must be a string'
  6433. )
  6434. }
  6435. return allocUnsafe(this, arg)
  6436. }
  6437. return from(this, arg, encodingOrOffset, length)
  6438. }
  6439. Buffer.poolSize = 8192 // not used by this implementation
  6440. // TODO: Legacy, not needed anymore. Remove in next major version.
  6441. Buffer._augment = function (arr) {
  6442. arr.__proto__ = Buffer.prototype
  6443. return arr
  6444. }
  6445. function from (that, value, encodingOrOffset, length) {
  6446. if (typeof value === 'number') {
  6447. throw new TypeError('"value" argument must not be a number')
  6448. }
  6449. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  6450. return fromArrayBuffer(that, value, encodingOrOffset, length)
  6451. }
  6452. if (typeof value === 'string') {
  6453. return fromString(that, value, encodingOrOffset)
  6454. }
  6455. return fromObject(that, value)
  6456. }
  6457. /**
  6458. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  6459. * if value is a number.
  6460. * Buffer.from(str[, encoding])
  6461. * Buffer.from(array)
  6462. * Buffer.from(buffer)
  6463. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  6464. **/
  6465. Buffer.from = function (value, encodingOrOffset, length) {
  6466. return from(null, value, encodingOrOffset, length)
  6467. }
  6468. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6469. Buffer.prototype.__proto__ = Uint8Array.prototype
  6470. Buffer.__proto__ = Uint8Array
  6471. if (typeof Symbol !== 'undefined' && Symbol.species &&
  6472. Buffer[Symbol.species] === Buffer) {
  6473. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  6474. Object.defineProperty(Buffer, Symbol.species, {
  6475. value: null,
  6476. configurable: true
  6477. })
  6478. }
  6479. }
  6480. function assertSize (size) {
  6481. if (typeof size !== 'number') {
  6482. throw new TypeError('"size" argument must be a number')
  6483. } else if (size < 0) {
  6484. throw new RangeError('"size" argument must not be negative')
  6485. }
  6486. }
  6487. function alloc (that, size, fill, encoding) {
  6488. assertSize(size)
  6489. if (size <= 0) {
  6490. return createBuffer(that, size)
  6491. }
  6492. if (fill !== undefined) {
  6493. // Only pay attention to encoding if it's a string. This
  6494. // prevents accidentally sending in a number that would
  6495. // be interpretted as a start offset.
  6496. return typeof encoding === 'string'
  6497. ? createBuffer(that, size).fill(fill, encoding)
  6498. : createBuffer(that, size).fill(fill)
  6499. }
  6500. return createBuffer(that, size)
  6501. }
  6502. /**
  6503. * Creates a new filled Buffer instance.
  6504. * alloc(size[, fill[, encoding]])
  6505. **/
  6506. Buffer.alloc = function (size, fill, encoding) {
  6507. return alloc(null, size, fill, encoding)
  6508. }
  6509. function allocUnsafe (that, size) {
  6510. assertSize(size)
  6511. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
  6512. if (!Buffer.TYPED_ARRAY_SUPPORT) {
  6513. for (var i = 0; i < size; ++i) {
  6514. that[i] = 0
  6515. }
  6516. }
  6517. return that
  6518. }
  6519. /**
  6520. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  6521. * */
  6522. Buffer.allocUnsafe = function (size) {
  6523. return allocUnsafe(null, size)
  6524. }
  6525. /**
  6526. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  6527. */
  6528. Buffer.allocUnsafeSlow = function (size) {
  6529. return allocUnsafe(null, size)
  6530. }
  6531. function fromString (that, string, encoding) {
  6532. if (typeof encoding !== 'string' || encoding === '') {
  6533. encoding = 'utf8'
  6534. }
  6535. if (!Buffer.isEncoding(encoding)) {
  6536. throw new TypeError('"encoding" must be a valid string encoding')
  6537. }
  6538. var length = byteLength(string, encoding) | 0
  6539. that = createBuffer(that, length)
  6540. var actual = that.write(string, encoding)
  6541. if (actual !== length) {
  6542. // Writing a hex string, for example, that contains invalid characters will
  6543. // cause everything after the first invalid character to be ignored. (e.g.
  6544. // 'abxxcd' will be treated as 'ab')
  6545. that = that.slice(0, actual)
  6546. }
  6547. return that
  6548. }
  6549. function fromArrayLike (that, array) {
  6550. var length = array.length < 0 ? 0 : checked(array.length) | 0
  6551. that = createBuffer(that, length)
  6552. for (var i = 0; i < length; i += 1) {
  6553. that[i] = array[i] & 255
  6554. }
  6555. return that
  6556. }
  6557. function fromArrayBuffer (that, array, byteOffset, length) {
  6558. array.byteLength // this throws if `array` is not a valid ArrayBuffer
  6559. if (byteOffset < 0 || array.byteLength < byteOffset) {
  6560. throw new RangeError('\'offset\' is out of bounds')
  6561. }
  6562. if (array.byteLength < byteOffset + (length || 0)) {
  6563. throw new RangeError('\'length\' is out of bounds')
  6564. }
  6565. if (byteOffset === undefined && length === undefined) {
  6566. array = new Uint8Array(array)
  6567. } else if (length === undefined) {
  6568. array = new Uint8Array(array, byteOffset)
  6569. } else {
  6570. array = new Uint8Array(array, byteOffset, length)
  6571. }
  6572. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6573. // Return an augmented `Uint8Array` instance, for best performance
  6574. that = array
  6575. that.__proto__ = Buffer.prototype
  6576. } else {
  6577. // Fallback: Return an object instance of the Buffer class
  6578. that = fromArrayLike(that, array)
  6579. }
  6580. return that
  6581. }
  6582. function fromObject (that, obj) {
  6583. if (Buffer.isBuffer(obj)) {
  6584. var len = checked(obj.length) | 0
  6585. that = createBuffer(that, len)
  6586. if (that.length === 0) {
  6587. return that
  6588. }
  6589. obj.copy(that, 0, 0, len)
  6590. return that
  6591. }
  6592. if (obj) {
  6593. if ((typeof ArrayBuffer !== 'undefined' &&
  6594. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  6595. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  6596. return createBuffer(that, 0)
  6597. }
  6598. return fromArrayLike(that, obj)
  6599. }
  6600. if (obj.type === 'Buffer' && isArray(obj.data)) {
  6601. return fromArrayLike(that, obj.data)
  6602. }
  6603. }
  6604. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  6605. }
  6606. function checked (length) {
  6607. // Note: cannot use `length < kMaxLength()` here because that fails when
  6608. // length is NaN (which is otherwise coerced to zero.)
  6609. if (length >= kMaxLength()) {
  6610. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  6611. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  6612. }
  6613. return length | 0
  6614. }
  6615. function SlowBuffer (length) {
  6616. if (+length != length) { // eslint-disable-line eqeqeq
  6617. length = 0
  6618. }
  6619. return Buffer.alloc(+length)
  6620. }
  6621. Buffer.isBuffer = function isBuffer (b) {
  6622. return !!(b != null && b._isBuffer)
  6623. }
  6624. Buffer.compare = function compare (a, b) {
  6625. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  6626. throw new TypeError('Arguments must be Buffers')
  6627. }
  6628. if (a === b) return 0
  6629. var x = a.length
  6630. var y = b.length
  6631. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  6632. if (a[i] !== b[i]) {
  6633. x = a[i]
  6634. y = b[i]
  6635. break
  6636. }
  6637. }
  6638. if (x < y) return -1
  6639. if (y < x) return 1
  6640. return 0
  6641. }
  6642. Buffer.isEncoding = function isEncoding (encoding) {
  6643. switch (String(encoding).toLowerCase()) {
  6644. case 'hex':
  6645. case 'utf8':
  6646. case 'utf-8':
  6647. case 'ascii':
  6648. case 'latin1':
  6649. case 'binary':
  6650. case 'base64':
  6651. case 'ucs2':
  6652. case 'ucs-2':
  6653. case 'utf16le':
  6654. case 'utf-16le':
  6655. return true
  6656. default:
  6657. return false
  6658. }
  6659. }
  6660. Buffer.concat = function concat (list, length) {
  6661. if (!isArray(list)) {
  6662. throw new TypeError('"list" argument must be an Array of Buffers')
  6663. }
  6664. if (list.length === 0) {
  6665. return Buffer.alloc(0)
  6666. }
  6667. var i
  6668. if (length === undefined) {
  6669. length = 0
  6670. for (i = 0; i < list.length; ++i) {
  6671. length += list[i].length
  6672. }
  6673. }
  6674. var buffer = Buffer.allocUnsafe(length)
  6675. var pos = 0
  6676. for (i = 0; i < list.length; ++i) {
  6677. var buf = list[i]
  6678. if (!Buffer.isBuffer(buf)) {
  6679. throw new TypeError('"list" argument must be an Array of Buffers')
  6680. }
  6681. buf.copy(buffer, pos)
  6682. pos += buf.length
  6683. }
  6684. return buffer
  6685. }
  6686. function byteLength (string, encoding) {
  6687. if (Buffer.isBuffer(string)) {
  6688. return string.length
  6689. }
  6690. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  6691. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  6692. return string.byteLength
  6693. }
  6694. if (typeof string !== 'string') {
  6695. string = '' + string
  6696. }
  6697. var len = string.length
  6698. if (len === 0) return 0
  6699. // Use a for loop to avoid recursion
  6700. var loweredCase = false
  6701. for (;;) {
  6702. switch (encoding) {
  6703. case 'ascii':
  6704. case 'latin1':
  6705. case 'binary':
  6706. return len
  6707. case 'utf8':
  6708. case 'utf-8':
  6709. case undefined:
  6710. return utf8ToBytes(string).length
  6711. case 'ucs2':
  6712. case 'ucs-2':
  6713. case 'utf16le':
  6714. case 'utf-16le':
  6715. return len * 2
  6716. case 'hex':
  6717. return len >>> 1
  6718. case 'base64':
  6719. return base64ToBytes(string).length
  6720. default:
  6721. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  6722. encoding = ('' + encoding).toLowerCase()
  6723. loweredCase = true
  6724. }
  6725. }
  6726. }
  6727. Buffer.byteLength = byteLength
  6728. function slowToString (encoding, start, end) {
  6729. var loweredCase = false
  6730. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  6731. // property of a typed array.
  6732. // This behaves neither like String nor Uint8Array in that we set start/end
  6733. // to their upper/lower bounds if the value passed is out of range.
  6734. // undefined is handled specially as per ECMA-262 6th Edition,
  6735. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  6736. if (start === undefined || start < 0) {
  6737. start = 0
  6738. }
  6739. // Return early if start > this.length. Done here to prevent potential uint32
  6740. // coercion fail below.
  6741. if (start > this.length) {
  6742. return ''
  6743. }
  6744. if (end === undefined || end > this.length) {
  6745. end = this.length
  6746. }
  6747. if (end <= 0) {
  6748. return ''
  6749. }
  6750. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  6751. end >>>= 0
  6752. start >>>= 0
  6753. if (end <= start) {
  6754. return ''
  6755. }
  6756. if (!encoding) encoding = 'utf8'
  6757. while (true) {
  6758. switch (encoding) {
  6759. case 'hex':
  6760. return hexSlice(this, start, end)
  6761. case 'utf8':
  6762. case 'utf-8':
  6763. return utf8Slice(this, start, end)
  6764. case 'ascii':
  6765. return asciiSlice(this, start, end)
  6766. case 'latin1':
  6767. case 'binary':
  6768. return latin1Slice(this, start, end)
  6769. case 'base64':
  6770. return base64Slice(this, start, end)
  6771. case 'ucs2':
  6772. case 'ucs-2':
  6773. case 'utf16le':
  6774. case 'utf-16le':
  6775. return utf16leSlice(this, start, end)
  6776. default:
  6777. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  6778. encoding = (encoding + '').toLowerCase()
  6779. loweredCase = true
  6780. }
  6781. }
  6782. }
  6783. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  6784. // Buffer instances.
  6785. Buffer.prototype._isBuffer = true
  6786. function swap (b, n, m) {
  6787. var i = b[n]
  6788. b[n] = b[m]
  6789. b[m] = i
  6790. }
  6791. Buffer.prototype.swap16 = function swap16 () {
  6792. var len = this.length
  6793. if (len % 2 !== 0) {
  6794. throw new RangeError('Buffer size must be a multiple of 16-bits')
  6795. }
  6796. for (var i = 0; i < len; i += 2) {
  6797. swap(this, i, i + 1)
  6798. }
  6799. return this
  6800. }
  6801. Buffer.prototype.swap32 = function swap32 () {
  6802. var len = this.length
  6803. if (len % 4 !== 0) {
  6804. throw new RangeError('Buffer size must be a multiple of 32-bits')
  6805. }
  6806. for (var i = 0; i < len; i += 4) {
  6807. swap(this, i, i + 3)
  6808. swap(this, i + 1, i + 2)
  6809. }
  6810. return this
  6811. }
  6812. Buffer.prototype.swap64 = function swap64 () {
  6813. var len = this.length
  6814. if (len % 8 !== 0) {
  6815. throw new RangeError('Buffer size must be a multiple of 64-bits')
  6816. }
  6817. for (var i = 0; i < len; i += 8) {
  6818. swap(this, i, i + 7)
  6819. swap(this, i + 1, i + 6)
  6820. swap(this, i + 2, i + 5)
  6821. swap(this, i + 3, i + 4)
  6822. }
  6823. return this
  6824. }
  6825. Buffer.prototype.toString = function toString () {
  6826. var length = this.length | 0
  6827. if (length === 0) return ''
  6828. if (arguments.length === 0) return utf8Slice(this, 0, length)
  6829. return slowToString.apply(this, arguments)
  6830. }
  6831. Buffer.prototype.equals = function equals (b) {
  6832. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  6833. if (this === b) return true
  6834. return Buffer.compare(this, b) === 0
  6835. }
  6836. Buffer.prototype.inspect = function inspect () {
  6837. var str = ''
  6838. var max = exports.INSPECT_MAX_BYTES
  6839. if (this.length > 0) {
  6840. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  6841. if (this.length > max) str += ' ... '
  6842. }
  6843. return '<Buffer ' + str + '>'
  6844. }
  6845. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  6846. if (!Buffer.isBuffer(target)) {
  6847. throw new TypeError('Argument must be a Buffer')
  6848. }
  6849. if (start === undefined) {
  6850. start = 0
  6851. }
  6852. if (end === undefined) {
  6853. end = target ? target.length : 0
  6854. }
  6855. if (thisStart === undefined) {
  6856. thisStart = 0
  6857. }
  6858. if (thisEnd === undefined) {
  6859. thisEnd = this.length
  6860. }
  6861. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  6862. throw new RangeError('out of range index')
  6863. }
  6864. if (thisStart >= thisEnd && start >= end) {
  6865. return 0
  6866. }
  6867. if (thisStart >= thisEnd) {
  6868. return -1
  6869. }
  6870. if (start >= end) {
  6871. return 1
  6872. }
  6873. start >>>= 0
  6874. end >>>= 0
  6875. thisStart >>>= 0
  6876. thisEnd >>>= 0
  6877. if (this === target) return 0
  6878. var x = thisEnd - thisStart
  6879. var y = end - start
  6880. var len = Math.min(x, y)
  6881. var thisCopy = this.slice(thisStart, thisEnd)
  6882. var targetCopy = target.slice(start, end)
  6883. for (var i = 0; i < len; ++i) {
  6884. if (thisCopy[i] !== targetCopy[i]) {
  6885. x = thisCopy[i]
  6886. y = targetCopy[i]
  6887. break
  6888. }
  6889. }
  6890. if (x < y) return -1
  6891. if (y < x) return 1
  6892. return 0
  6893. }
  6894. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  6895. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  6896. //
  6897. // Arguments:
  6898. // - buffer - a Buffer to search
  6899. // - val - a string, Buffer, or number
  6900. // - byteOffset - an index into `buffer`; will be clamped to an int32
  6901. // - encoding - an optional encoding, relevant is val is a string
  6902. // - dir - true for indexOf, false for lastIndexOf
  6903. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  6904. // Empty buffer means no match
  6905. if (buffer.length === 0) return -1
  6906. // Normalize byteOffset
  6907. if (typeof byteOffset === 'string') {
  6908. encoding = byteOffset
  6909. byteOffset = 0
  6910. } else if (byteOffset > 0x7fffffff) {
  6911. byteOffset = 0x7fffffff
  6912. } else if (byteOffset < -0x80000000) {
  6913. byteOffset = -0x80000000
  6914. }
  6915. byteOffset = +byteOffset // Coerce to Number.
  6916. if (isNaN(byteOffset)) {
  6917. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  6918. byteOffset = dir ? 0 : (buffer.length - 1)
  6919. }
  6920. // Normalize byteOffset: negative offsets start from the end of the buffer
  6921. if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  6922. if (byteOffset >= buffer.length) {
  6923. if (dir) return -1
  6924. else byteOffset = buffer.length - 1
  6925. } else if (byteOffset < 0) {
  6926. if (dir) byteOffset = 0
  6927. else return -1
  6928. }
  6929. // Normalize val
  6930. if (typeof val === 'string') {
  6931. val = Buffer.from(val, encoding)
  6932. }
  6933. // Finally, search either indexOf (if dir is true) or lastIndexOf
  6934. if (Buffer.isBuffer(val)) {
  6935. // Special case: looking for empty string/buffer always fails
  6936. if (val.length === 0) {
  6937. return -1
  6938. }
  6939. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  6940. } else if (typeof val === 'number') {
  6941. val = val & 0xFF // Search for a byte value [0-255]
  6942. if (Buffer.TYPED_ARRAY_SUPPORT &&
  6943. typeof Uint8Array.prototype.indexOf === 'function') {
  6944. if (dir) {
  6945. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  6946. } else {
  6947. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  6948. }
  6949. }
  6950. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  6951. }
  6952. throw new TypeError('val must be string, number or Buffer')
  6953. }
  6954. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  6955. var indexSize = 1
  6956. var arrLength = arr.length
  6957. var valLength = val.length
  6958. if (encoding !== undefined) {
  6959. encoding = String(encoding).toLowerCase()
  6960. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  6961. encoding === 'utf16le' || encoding === 'utf-16le') {
  6962. if (arr.length < 2 || val.length < 2) {
  6963. return -1
  6964. }
  6965. indexSize = 2
  6966. arrLength /= 2
  6967. valLength /= 2
  6968. byteOffset /= 2
  6969. }
  6970. }
  6971. function read (buf, i) {
  6972. if (indexSize === 1) {
  6973. return buf[i]
  6974. } else {
  6975. return buf.readUInt16BE(i * indexSize)
  6976. }
  6977. }
  6978. var i
  6979. if (dir) {
  6980. var foundIndex = -1
  6981. for (i = byteOffset; i < arrLength; i++) {
  6982. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  6983. if (foundIndex === -1) foundIndex = i
  6984. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  6985. } else {
  6986. if (foundIndex !== -1) i -= i - foundIndex
  6987. foundIndex = -1
  6988. }
  6989. }
  6990. } else {
  6991. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  6992. for (i = byteOffset; i >= 0; i--) {
  6993. var found = true
  6994. for (var j = 0; j < valLength; j++) {
  6995. if (read(arr, i + j) !== read(val, j)) {
  6996. found = false
  6997. break
  6998. }
  6999. }
  7000. if (found) return i
  7001. }
  7002. }
  7003. return -1
  7004. }
  7005. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  7006. return this.indexOf(val, byteOffset, encoding) !== -1
  7007. }
  7008. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  7009. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  7010. }
  7011. Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  7012. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  7013. }
  7014. function hexWrite (buf, string, offset, length) {
  7015. offset = Number(offset) || 0
  7016. var remaining = buf.length - offset
  7017. if (!length) {
  7018. length = remaining
  7019. } else {
  7020. length = Number(length)
  7021. if (length > remaining) {
  7022. length = remaining
  7023. }
  7024. }
  7025. // must be an even number of digits
  7026. var strLen = string.length
  7027. if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
  7028. if (length > strLen / 2) {
  7029. length = strLen / 2
  7030. }
  7031. for (var i = 0; i < length; ++i) {
  7032. var parsed = parseInt(string.substr(i * 2, 2), 16)
  7033. if (isNaN(parsed)) return i
  7034. buf[offset + i] = parsed
  7035. }
  7036. return i
  7037. }
  7038. function utf8Write (buf, string, offset, length) {
  7039. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  7040. }
  7041. function asciiWrite (buf, string, offset, length) {
  7042. return blitBuffer(asciiToBytes(string), buf, offset, length)
  7043. }
  7044. function latin1Write (buf, string, offset, length) {
  7045. return asciiWrite(buf, string, offset, length)
  7046. }
  7047. function base64Write (buf, string, offset, length) {
  7048. return blitBuffer(base64ToBytes(string), buf, offset, length)
  7049. }
  7050. function ucs2Write (buf, string, offset, length) {
  7051. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  7052. }
  7053. Buffer.prototype.write = function write (string, offset, length, encoding) {
  7054. // Buffer#write(string)
  7055. if (offset === undefined) {
  7056. encoding = 'utf8'
  7057. length = this.length
  7058. offset = 0
  7059. // Buffer#write(string, encoding)
  7060. } else if (length === undefined && typeof offset === 'string') {
  7061. encoding = offset
  7062. length = this.length
  7063. offset = 0
  7064. // Buffer#write(string, offset[, length][, encoding])
  7065. } else if (isFinite(offset)) {
  7066. offset = offset | 0
  7067. if (isFinite(length)) {
  7068. length = length | 0
  7069. if (encoding === undefined) encoding = 'utf8'
  7070. } else {
  7071. encoding = length
  7072. length = undefined
  7073. }
  7074. // legacy write(string, encoding, offset, length) - remove in v0.13
  7075. } else {
  7076. throw new Error(
  7077. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  7078. )
  7079. }
  7080. var remaining = this.length - offset
  7081. if (length === undefined || length > remaining) length = remaining
  7082. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  7083. throw new RangeError('Attempt to write outside buffer bounds')
  7084. }
  7085. if (!encoding) encoding = 'utf8'
  7086. var loweredCase = false
  7087. for (;;) {
  7088. switch (encoding) {
  7089. case 'hex':
  7090. return hexWrite(this, string, offset, length)
  7091. case 'utf8':
  7092. case 'utf-8':
  7093. return utf8Write(this, string, offset, length)
  7094. case 'ascii':
  7095. return asciiWrite(this, string, offset, length)
  7096. case 'latin1':
  7097. case 'binary':
  7098. return latin1Write(this, string, offset, length)
  7099. case 'base64':
  7100. // Warning: maxLength not taken into account in base64Write
  7101. return base64Write(this, string, offset, length)
  7102. case 'ucs2':
  7103. case 'ucs-2':
  7104. case 'utf16le':
  7105. case 'utf-16le':
  7106. return ucs2Write(this, string, offset, length)
  7107. default:
  7108. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  7109. encoding = ('' + encoding).toLowerCase()
  7110. loweredCase = true
  7111. }
  7112. }
  7113. }
  7114. Buffer.prototype.toJSON = function toJSON () {
  7115. return {
  7116. type: 'Buffer',
  7117. data: Array.prototype.slice.call(this._arr || this, 0)
  7118. }
  7119. }
  7120. function base64Slice (buf, start, end) {
  7121. if (start === 0 && end === buf.length) {
  7122. return base64.fromByteArray(buf)
  7123. } else {
  7124. return base64.fromByteArray(buf.slice(start, end))
  7125. }
  7126. }
  7127. function utf8Slice (buf, start, end) {
  7128. end = Math.min(buf.length, end)
  7129. var res = []
  7130. var i = start
  7131. while (i < end) {
  7132. var firstByte = buf[i]
  7133. var codePoint = null
  7134. var bytesPerSequence = (firstByte > 0xEF) ? 4
  7135. : (firstByte > 0xDF) ? 3
  7136. : (firstByte > 0xBF) ? 2
  7137. : 1
  7138. if (i + bytesPerSequence <= end) {
  7139. var secondByte, thirdByte, fourthByte, tempCodePoint
  7140. switch (bytesPerSequence) {
  7141. case 1:
  7142. if (firstByte < 0x80) {
  7143. codePoint = firstByte
  7144. }
  7145. break
  7146. case 2:
  7147. secondByte = buf[i + 1]
  7148. if ((secondByte & 0xC0) === 0x80) {
  7149. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  7150. if (tempCodePoint > 0x7F) {
  7151. codePoint = tempCodePoint
  7152. }
  7153. }
  7154. break
  7155. case 3:
  7156. secondByte = buf[i + 1]
  7157. thirdByte = buf[i + 2]
  7158. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  7159. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  7160. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  7161. codePoint = tempCodePoint
  7162. }
  7163. }
  7164. break
  7165. case 4:
  7166. secondByte = buf[i + 1]
  7167. thirdByte = buf[i + 2]
  7168. fourthByte = buf[i + 3]
  7169. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  7170. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  7171. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  7172. codePoint = tempCodePoint
  7173. }
  7174. }
  7175. }
  7176. }
  7177. if (codePoint === null) {
  7178. // we did not generate a valid codePoint so insert a
  7179. // replacement char (U+FFFD) and advance only 1 byte
  7180. codePoint = 0xFFFD
  7181. bytesPerSequence = 1
  7182. } else if (codePoint > 0xFFFF) {
  7183. // encode to utf16 (surrogate pair dance)
  7184. codePoint -= 0x10000
  7185. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  7186. codePoint = 0xDC00 | codePoint & 0x3FF
  7187. }
  7188. res.push(codePoint)
  7189. i += bytesPerSequence
  7190. }
  7191. return decodeCodePointsArray(res)
  7192. }
  7193. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  7194. // the lowest limit is Chrome, with 0x10000 args.
  7195. // We go 1 magnitude less, for safety
  7196. var MAX_ARGUMENTS_LENGTH = 0x1000
  7197. function decodeCodePointsArray (codePoints) {
  7198. var len = codePoints.length
  7199. if (len <= MAX_ARGUMENTS_LENGTH) {
  7200. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  7201. }
  7202. // Decode in chunks to avoid "call stack size exceeded".
  7203. var res = ''
  7204. var i = 0
  7205. while (i < len) {
  7206. res += String.fromCharCode.apply(
  7207. String,
  7208. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  7209. )
  7210. }
  7211. return res
  7212. }
  7213. function asciiSlice (buf, start, end) {
  7214. var ret = ''
  7215. end = Math.min(buf.length, end)
  7216. for (var i = start; i < end; ++i) {
  7217. ret += String.fromCharCode(buf[i] & 0x7F)
  7218. }
  7219. return ret
  7220. }
  7221. function latin1Slice (buf, start, end) {
  7222. var ret = ''
  7223. end = Math.min(buf.length, end)
  7224. for (var i = start; i < end; ++i) {
  7225. ret += String.fromCharCode(buf[i])
  7226. }
  7227. return ret
  7228. }
  7229. function hexSlice (buf, start, end) {
  7230. var len = buf.length
  7231. if (!start || start < 0) start = 0
  7232. if (!end || end < 0 || end > len) end = len
  7233. var out = ''
  7234. for (var i = start; i < end; ++i) {
  7235. out += toHex(buf[i])
  7236. }
  7237. return out
  7238. }
  7239. function utf16leSlice (buf, start, end) {
  7240. var bytes = buf.slice(start, end)
  7241. var res = ''
  7242. for (var i = 0; i < bytes.length; i += 2) {
  7243. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
  7244. }
  7245. return res
  7246. }
  7247. Buffer.prototype.slice = function slice (start, end) {
  7248. var len = this.length
  7249. start = ~~start
  7250. end = end === undefined ? len : ~~end
  7251. if (start < 0) {
  7252. start += len
  7253. if (start < 0) start = 0
  7254. } else if (start > len) {
  7255. start = len
  7256. }
  7257. if (end < 0) {
  7258. end += len
  7259. if (end < 0) end = 0
  7260. } else if (end > len) {
  7261. end = len
  7262. }
  7263. if (end < start) end = start
  7264. var newBuf
  7265. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7266. newBuf = this.subarray(start, end)
  7267. newBuf.__proto__ = Buffer.prototype
  7268. } else {
  7269. var sliceLen = end - start
  7270. newBuf = new Buffer(sliceLen, undefined)
  7271. for (var i = 0; i < sliceLen; ++i) {
  7272. newBuf[i] = this[i + start]
  7273. }
  7274. }
  7275. return newBuf
  7276. }
  7277. /*
  7278. * Need to make sure that buffer isn't trying to write out of bounds.
  7279. */
  7280. function checkOffset (offset, ext, length) {
  7281. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  7282. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  7283. }
  7284. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  7285. offset = offset | 0
  7286. byteLength = byteLength | 0
  7287. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7288. var val = this[offset]
  7289. var mul = 1
  7290. var i = 0
  7291. while (++i < byteLength && (mul *= 0x100)) {
  7292. val += this[offset + i] * mul
  7293. }
  7294. return val
  7295. }
  7296. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  7297. offset = offset | 0
  7298. byteLength = byteLength | 0
  7299. if (!noAssert) {
  7300. checkOffset(offset, byteLength, this.length)
  7301. }
  7302. var val = this[offset + --byteLength]
  7303. var mul = 1
  7304. while (byteLength > 0 && (mul *= 0x100)) {
  7305. val += this[offset + --byteLength] * mul
  7306. }
  7307. return val
  7308. }
  7309. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  7310. if (!noAssert) checkOffset(offset, 1, this.length)
  7311. return this[offset]
  7312. }
  7313. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  7314. if (!noAssert) checkOffset(offset, 2, this.length)
  7315. return this[offset] | (this[offset + 1] << 8)
  7316. }
  7317. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  7318. if (!noAssert) checkOffset(offset, 2, this.length)
  7319. return (this[offset] << 8) | this[offset + 1]
  7320. }
  7321. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  7322. if (!noAssert) checkOffset(offset, 4, this.length)
  7323. return ((this[offset]) |
  7324. (this[offset + 1] << 8) |
  7325. (this[offset + 2] << 16)) +
  7326. (this[offset + 3] * 0x1000000)
  7327. }
  7328. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  7329. if (!noAssert) checkOffset(offset, 4, this.length)
  7330. return (this[offset] * 0x1000000) +
  7331. ((this[offset + 1] << 16) |
  7332. (this[offset + 2] << 8) |
  7333. this[offset + 3])
  7334. }
  7335. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  7336. offset = offset | 0
  7337. byteLength = byteLength | 0
  7338. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7339. var val = this[offset]
  7340. var mul = 1
  7341. var i = 0
  7342. while (++i < byteLength && (mul *= 0x100)) {
  7343. val += this[offset + i] * mul
  7344. }
  7345. mul *= 0x80
  7346. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  7347. return val
  7348. }
  7349. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  7350. offset = offset | 0
  7351. byteLength = byteLength | 0
  7352. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7353. var i = byteLength
  7354. var mul = 1
  7355. var val = this[offset + --i]
  7356. while (i > 0 && (mul *= 0x100)) {
  7357. val += this[offset + --i] * mul
  7358. }
  7359. mul *= 0x80
  7360. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  7361. return val
  7362. }
  7363. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  7364. if (!noAssert) checkOffset(offset, 1, this.length)
  7365. if (!(this[offset] & 0x80)) return (this[offset])
  7366. return ((0xff - this[offset] + 1) * -1)
  7367. }
  7368. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  7369. if (!noAssert) checkOffset(offset, 2, this.length)
  7370. var val = this[offset] | (this[offset + 1] << 8)
  7371. return (val & 0x8000) ? val | 0xFFFF0000 : val
  7372. }
  7373. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  7374. if (!noAssert) checkOffset(offset, 2, this.length)
  7375. var val = this[offset + 1] | (this[offset] << 8)
  7376. return (val & 0x8000) ? val | 0xFFFF0000 : val
  7377. }
  7378. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  7379. if (!noAssert) checkOffset(offset, 4, this.length)
  7380. return (this[offset]) |
  7381. (this[offset + 1] << 8) |
  7382. (this[offset + 2] << 16) |
  7383. (this[offset + 3] << 24)
  7384. }
  7385. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  7386. if (!noAssert) checkOffset(offset, 4, this.length)
  7387. return (this[offset] << 24) |
  7388. (this[offset + 1] << 16) |
  7389. (this[offset + 2] << 8) |
  7390. (this[offset + 3])
  7391. }
  7392. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  7393. if (!noAssert) checkOffset(offset, 4, this.length)
  7394. return ieee754.read(this, offset, true, 23, 4)
  7395. }
  7396. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  7397. if (!noAssert) checkOffset(offset, 4, this.length)
  7398. return ieee754.read(this, offset, false, 23, 4)
  7399. }
  7400. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  7401. if (!noAssert) checkOffset(offset, 8, this.length)
  7402. return ieee754.read(this, offset, true, 52, 8)
  7403. }
  7404. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  7405. if (!noAssert) checkOffset(offset, 8, this.length)
  7406. return ieee754.read(this, offset, false, 52, 8)
  7407. }
  7408. function checkInt (buf, value, offset, ext, max, min) {
  7409. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  7410. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  7411. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  7412. }
  7413. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  7414. value = +value
  7415. offset = offset | 0
  7416. byteLength = byteLength | 0
  7417. if (!noAssert) {
  7418. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  7419. checkInt(this, value, offset, byteLength, maxBytes, 0)
  7420. }
  7421. var mul = 1
  7422. var i = 0
  7423. this[offset] = value & 0xFF
  7424. while (++i < byteLength && (mul *= 0x100)) {
  7425. this[offset + i] = (value / mul) & 0xFF
  7426. }
  7427. return offset + byteLength
  7428. }
  7429. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  7430. value = +value
  7431. offset = offset | 0
  7432. byteLength = byteLength | 0
  7433. if (!noAssert) {
  7434. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  7435. checkInt(this, value, offset, byteLength, maxBytes, 0)
  7436. }
  7437. var i = byteLength - 1
  7438. var mul = 1
  7439. this[offset + i] = value & 0xFF
  7440. while (--i >= 0 && (mul *= 0x100)) {
  7441. this[offset + i] = (value / mul) & 0xFF
  7442. }
  7443. return offset + byteLength
  7444. }
  7445. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  7446. value = +value
  7447. offset = offset | 0
  7448. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  7449. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  7450. this[offset] = (value & 0xff)
  7451. return offset + 1
  7452. }
  7453. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  7454. if (value < 0) value = 0xffff + value + 1
  7455. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  7456. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  7457. (littleEndian ? i : 1 - i) * 8
  7458. }
  7459. }
  7460. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  7461. value = +value
  7462. offset = offset | 0
  7463. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  7464. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7465. this[offset] = (value & 0xff)
  7466. this[offset + 1] = (value >>> 8)
  7467. } else {
  7468. objectWriteUInt16(this, value, offset, true)
  7469. }
  7470. return offset + 2
  7471. }
  7472. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  7473. value = +value
  7474. offset = offset | 0
  7475. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  7476. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7477. this[offset] = (value >>> 8)
  7478. this[offset + 1] = (value & 0xff)
  7479. } else {
  7480. objectWriteUInt16(this, value, offset, false)
  7481. }
  7482. return offset + 2
  7483. }
  7484. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  7485. if (value < 0) value = 0xffffffff + value + 1
  7486. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  7487. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  7488. }
  7489. }
  7490. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  7491. value = +value
  7492. offset = offset | 0
  7493. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  7494. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7495. this[offset + 3] = (value >>> 24)
  7496. this[offset + 2] = (value >>> 16)
  7497. this[offset + 1] = (value >>> 8)
  7498. this[offset] = (value & 0xff)
  7499. } else {
  7500. objectWriteUInt32(this, value, offset, true)
  7501. }
  7502. return offset + 4
  7503. }
  7504. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  7505. value = +value
  7506. offset = offset | 0
  7507. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  7508. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7509. this[offset] = (value >>> 24)
  7510. this[offset + 1] = (value >>> 16)
  7511. this[offset + 2] = (value >>> 8)
  7512. this[offset + 3] = (value & 0xff)
  7513. } else {
  7514. objectWriteUInt32(this, value, offset, false)
  7515. }
  7516. return offset + 4
  7517. }
  7518. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  7519. value = +value
  7520. offset = offset | 0
  7521. if (!noAssert) {
  7522. var limit = Math.pow(2, 8 * byteLength - 1)
  7523. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  7524. }
  7525. var i = 0
  7526. var mul = 1
  7527. var sub = 0
  7528. this[offset] = value & 0xFF
  7529. while (++i < byteLength && (mul *= 0x100)) {
  7530. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  7531. sub = 1
  7532. }
  7533. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  7534. }
  7535. return offset + byteLength
  7536. }
  7537. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  7538. value = +value
  7539. offset = offset | 0
  7540. if (!noAssert) {
  7541. var limit = Math.pow(2, 8 * byteLength - 1)
  7542. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  7543. }
  7544. var i = byteLength - 1
  7545. var mul = 1
  7546. var sub = 0
  7547. this[offset + i] = value & 0xFF
  7548. while (--i >= 0 && (mul *= 0x100)) {
  7549. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  7550. sub = 1
  7551. }
  7552. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  7553. }
  7554. return offset + byteLength
  7555. }
  7556. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  7557. value = +value
  7558. offset = offset | 0
  7559. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  7560. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  7561. if (value < 0) value = 0xff + value + 1
  7562. this[offset] = (value & 0xff)
  7563. return offset + 1
  7564. }
  7565. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  7566. value = +value
  7567. offset = offset | 0
  7568. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  7569. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7570. this[offset] = (value & 0xff)
  7571. this[offset + 1] = (value >>> 8)
  7572. } else {
  7573. objectWriteUInt16(this, value, offset, true)
  7574. }
  7575. return offset + 2
  7576. }
  7577. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  7578. value = +value
  7579. offset = offset | 0
  7580. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  7581. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7582. this[offset] = (value >>> 8)
  7583. this[offset + 1] = (value & 0xff)
  7584. } else {
  7585. objectWriteUInt16(this, value, offset, false)
  7586. }
  7587. return offset + 2
  7588. }
  7589. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  7590. value = +value
  7591. offset = offset | 0
  7592. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  7593. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7594. this[offset] = (value & 0xff)
  7595. this[offset + 1] = (value >>> 8)
  7596. this[offset + 2] = (value >>> 16)
  7597. this[offset + 3] = (value >>> 24)
  7598. } else {
  7599. objectWriteUInt32(this, value, offset, true)
  7600. }
  7601. return offset + 4
  7602. }
  7603. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  7604. value = +value
  7605. offset = offset | 0
  7606. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  7607. if (value < 0) value = 0xffffffff + value + 1
  7608. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7609. this[offset] = (value >>> 24)
  7610. this[offset + 1] = (value >>> 16)
  7611. this[offset + 2] = (value >>> 8)
  7612. this[offset + 3] = (value & 0xff)
  7613. } else {
  7614. objectWriteUInt32(this, value, offset, false)
  7615. }
  7616. return offset + 4
  7617. }
  7618. function checkIEEE754 (buf, value, offset, ext, max, min) {
  7619. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  7620. if (offset < 0) throw new RangeError('Index out of range')
  7621. }
  7622. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  7623. if (!noAssert) {
  7624. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  7625. }
  7626. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  7627. return offset + 4
  7628. }
  7629. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  7630. return writeFloat(this, value, offset, true, noAssert)
  7631. }
  7632. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  7633. return writeFloat(this, value, offset, false, noAssert)
  7634. }
  7635. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  7636. if (!noAssert) {
  7637. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  7638. }
  7639. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  7640. return offset + 8
  7641. }
  7642. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  7643. return writeDouble(this, value, offset, true, noAssert)
  7644. }
  7645. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  7646. return writeDouble(this, value, offset, false, noAssert)
  7647. }
  7648. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  7649. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  7650. if (!start) start = 0
  7651. if (!end && end !== 0) end = this.length
  7652. if (targetStart >= target.length) targetStart = target.length
  7653. if (!targetStart) targetStart = 0
  7654. if (end > 0 && end < start) end = start
  7655. // Copy 0 bytes; we're done
  7656. if (end === start) return 0
  7657. if (target.length === 0 || this.length === 0) return 0
  7658. // Fatal error conditions
  7659. if (targetStart < 0) {
  7660. throw new RangeError('targetStart out of bounds')
  7661. }
  7662. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  7663. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  7664. // Are we oob?
  7665. if (end > this.length) end = this.length
  7666. if (target.length - targetStart < end - start) {
  7667. end = target.length - targetStart + start
  7668. }
  7669. var len = end - start
  7670. var i
  7671. if (this === target && start < targetStart && targetStart < end) {
  7672. // descending copy from end
  7673. for (i = len - 1; i >= 0; --i) {
  7674. target[i + targetStart] = this[i + start]
  7675. }
  7676. } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  7677. // ascending copy from start
  7678. for (i = 0; i < len; ++i) {
  7679. target[i + targetStart] = this[i + start]
  7680. }
  7681. } else {
  7682. Uint8Array.prototype.set.call(
  7683. target,
  7684. this.subarray(start, start + len),
  7685. targetStart
  7686. )
  7687. }
  7688. return len
  7689. }
  7690. // Usage:
  7691. // buffer.fill(number[, offset[, end]])
  7692. // buffer.fill(buffer[, offset[, end]])
  7693. // buffer.fill(string[, offset[, end]][, encoding])
  7694. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  7695. // Handle string cases:
  7696. if (typeof val === 'string') {
  7697. if (typeof start === 'string') {
  7698. encoding = start
  7699. start = 0
  7700. end = this.length
  7701. } else if (typeof end === 'string') {
  7702. encoding = end
  7703. end = this.length
  7704. }
  7705. if (val.length === 1) {
  7706. var code = val.charCodeAt(0)
  7707. if (code < 256) {
  7708. val = code
  7709. }
  7710. }
  7711. if (encoding !== undefined && typeof encoding !== 'string') {
  7712. throw new TypeError('encoding must be a string')
  7713. }
  7714. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  7715. throw new TypeError('Unknown encoding: ' + encoding)
  7716. }
  7717. } else if (typeof val === 'number') {
  7718. val = val & 255
  7719. }
  7720. // Invalid ranges are not set to a default, so can range check early.
  7721. if (start < 0 || this.length < start || this.length < end) {
  7722. throw new RangeError('Out of range index')
  7723. }
  7724. if (end <= start) {
  7725. return this
  7726. }
  7727. start = start >>> 0
  7728. end = end === undefined ? this.length : end >>> 0
  7729. if (!val) val = 0
  7730. var i
  7731. if (typeof val === 'number') {
  7732. for (i = start; i < end; ++i) {
  7733. this[i] = val
  7734. }
  7735. } else {
  7736. var bytes = Buffer.isBuffer(val)
  7737. ? val
  7738. : utf8ToBytes(new Buffer(val, encoding).toString())
  7739. var len = bytes.length
  7740. for (i = 0; i < end - start; ++i) {
  7741. this[i + start] = bytes[i % len]
  7742. }
  7743. }
  7744. return this
  7745. }
  7746. // HELPER FUNCTIONS
  7747. // ================
  7748. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
  7749. function base64clean (str) {
  7750. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  7751. str = stringtrim(str).replace(INVALID_BASE64_RE, '')
  7752. // Node converts strings with length < 2 to ''
  7753. if (str.length < 2) return ''
  7754. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  7755. while (str.length % 4 !== 0) {
  7756. str = str + '='
  7757. }
  7758. return str
  7759. }
  7760. function stringtrim (str) {
  7761. if (str.trim) return str.trim()
  7762. return str.replace(/^\s+|\s+$/g, '')
  7763. }
  7764. function toHex (n) {
  7765. if (n < 16) return '0' + n.toString(16)
  7766. return n.toString(16)
  7767. }
  7768. function utf8ToBytes (string, units) {
  7769. units = units || Infinity
  7770. var codePoint
  7771. var length = string.length
  7772. var leadSurrogate = null
  7773. var bytes = []
  7774. for (var i = 0; i < length; ++i) {
  7775. codePoint = string.charCodeAt(i)
  7776. // is surrogate component
  7777. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  7778. // last char was a lead
  7779. if (!leadSurrogate) {
  7780. // no lead yet
  7781. if (codePoint > 0xDBFF) {
  7782. // unexpected trail
  7783. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7784. continue
  7785. } else if (i + 1 === length) {
  7786. // unpaired lead
  7787. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7788. continue
  7789. }
  7790. // valid lead
  7791. leadSurrogate = codePoint
  7792. continue
  7793. }
  7794. // 2 leads in a row
  7795. if (codePoint < 0xDC00) {
  7796. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7797. leadSurrogate = codePoint
  7798. continue
  7799. }
  7800. // valid surrogate pair
  7801. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  7802. } else if (leadSurrogate) {
  7803. // valid bmp char, but last char was a lead
  7804. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7805. }
  7806. leadSurrogate = null
  7807. // encode utf8
  7808. if (codePoint < 0x80) {
  7809. if ((units -= 1) < 0) break
  7810. bytes.push(codePoint)
  7811. } else if (codePoint < 0x800) {
  7812. if ((units -= 2) < 0) break
  7813. bytes.push(
  7814. codePoint >> 0x6 | 0xC0,
  7815. codePoint & 0x3F | 0x80
  7816. )
  7817. } else if (codePoint < 0x10000) {
  7818. if ((units -= 3) < 0) break
  7819. bytes.push(
  7820. codePoint >> 0xC | 0xE0,
  7821. codePoint >> 0x6 & 0x3F | 0x80,
  7822. codePoint & 0x3F | 0x80
  7823. )
  7824. } else if (codePoint < 0x110000) {
  7825. if ((units -= 4) < 0) break
  7826. bytes.push(
  7827. codePoint >> 0x12 | 0xF0,
  7828. codePoint >> 0xC & 0x3F | 0x80,
  7829. codePoint >> 0x6 & 0x3F | 0x80,
  7830. codePoint & 0x3F | 0x80
  7831. )
  7832. } else {
  7833. throw new Error('Invalid code point')
  7834. }
  7835. }
  7836. return bytes
  7837. }
  7838. function asciiToBytes (str) {
  7839. var byteArray = []
  7840. for (var i = 0; i < str.length; ++i) {
  7841. // Node's code seems to be doing this and not & 0x7F..
  7842. byteArray.push(str.charCodeAt(i) & 0xFF)
  7843. }
  7844. return byteArray
  7845. }
  7846. function utf16leToBytes (str, units) {
  7847. var c, hi, lo
  7848. var byteArray = []
  7849. for (var i = 0; i < str.length; ++i) {
  7850. if ((units -= 2) < 0) break
  7851. c = str.charCodeAt(i)
  7852. hi = c >> 8
  7853. lo = c % 256
  7854. byteArray.push(lo)
  7855. byteArray.push(hi)
  7856. }
  7857. return byteArray
  7858. }
  7859. function base64ToBytes (str) {
  7860. return base64.toByteArray(base64clean(str))
  7861. }
  7862. function blitBuffer (src, dst, offset, length) {
  7863. for (var i = 0; i < length; ++i) {
  7864. if ((i + offset >= dst.length) || (i >= src.length)) break
  7865. dst[i + offset] = src[i]
  7866. }
  7867. return i
  7868. }
  7869. function isnan (val) {
  7870. return val !== val // eslint-disable-line no-self-compare
  7871. }
  7872. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7873. },{"base64-js":2,"ieee754":15,"isarray":18}],8:[function(require,module,exports){
  7874. (function (Buffer){
  7875. var Transform = require('stream').Transform
  7876. var inherits = require('inherits')
  7877. var StringDecoder = require('string_decoder').StringDecoder
  7878. module.exports = CipherBase
  7879. inherits(CipherBase, Transform)
  7880. function CipherBase (hashMode) {
  7881. Transform.call(this)
  7882. this.hashMode = typeof hashMode === 'string'
  7883. if (this.hashMode) {
  7884. this[hashMode] = this._finalOrDigest
  7885. } else {
  7886. this.final = this._finalOrDigest
  7887. }
  7888. this._decoder = null
  7889. this._encoding = null
  7890. }
  7891. CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
  7892. if (typeof data === 'string') {
  7893. data = new Buffer(data, inputEnc)
  7894. }
  7895. var outData = this._update(data)
  7896. if (this.hashMode) {
  7897. return this
  7898. }
  7899. if (outputEnc) {
  7900. outData = this._toString(outData, outputEnc)
  7901. }
  7902. return outData
  7903. }
  7904. CipherBase.prototype.setAutoPadding = function () {}
  7905. CipherBase.prototype.getAuthTag = function () {
  7906. throw new Error('trying to get auth tag in unsupported state')
  7907. }
  7908. CipherBase.prototype.setAuthTag = function () {
  7909. throw new Error('trying to set auth tag in unsupported state')
  7910. }
  7911. CipherBase.prototype.setAAD = function () {
  7912. throw new Error('trying to set aad in unsupported state')
  7913. }
  7914. CipherBase.prototype._transform = function (data, _, next) {
  7915. var err
  7916. try {
  7917. if (this.hashMode) {
  7918. this._update(data)
  7919. } else {
  7920. this.push(this._update(data))
  7921. }
  7922. } catch (e) {
  7923. err = e
  7924. } finally {
  7925. next(err)
  7926. }
  7927. }
  7928. CipherBase.prototype._flush = function (done) {
  7929. var err
  7930. try {
  7931. this.push(this._final())
  7932. } catch (e) {
  7933. err = e
  7934. } finally {
  7935. done(err)
  7936. }
  7937. }
  7938. CipherBase.prototype._finalOrDigest = function (outputEnc) {
  7939. var outData = this._final() || new Buffer('')
  7940. if (outputEnc) {
  7941. outData = this._toString(outData, outputEnc, true)
  7942. }
  7943. return outData
  7944. }
  7945. CipherBase.prototype._toString = function (value, enc, fin) {
  7946. if (!this._decoder) {
  7947. this._decoder = new StringDecoder(enc)
  7948. this._encoding = enc
  7949. }
  7950. if (this._encoding !== enc) {
  7951. throw new Error('can\'t switch encodings')
  7952. }
  7953. var out = this._decoder.write(value)
  7954. if (fin) {
  7955. out += this._decoder.end()
  7956. }
  7957. return out
  7958. }
  7959. }).call(this,require("buffer").Buffer)
  7960. },{"buffer":7,"inherits":16,"stream":43,"string_decoder":44}],9:[function(require,module,exports){
  7961. (function (Buffer){
  7962. // Copyright Joyent, Inc. and other Node contributors.
  7963. //
  7964. // Permission is hereby granted, free of charge, to any person obtaining a
  7965. // copy of this software and associated documentation files (the
  7966. // "Software"), to deal in the Software without restriction, including
  7967. // without limitation the rights to use, copy, modify, merge, publish,
  7968. // distribute, sublicense, and/or sell copies of the Software, and to permit
  7969. // persons to whom the Software is furnished to do so, subject to the
  7970. // following conditions:
  7971. //
  7972. // The above copyright notice and this permission notice shall be included
  7973. // in all copies or substantial portions of the Software.
  7974. //
  7975. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  7976. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  7977. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  7978. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  7979. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  7980. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  7981. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  7982. // NOTE: These type checking functions intentionally don't use `instanceof`
  7983. // because it is fragile and can be easily faked with `Object.create()`.
  7984. function isArray(arg) {
  7985. if (Array.isArray) {
  7986. return Array.isArray(arg);
  7987. }
  7988. return objectToString(arg) === '[object Array]';
  7989. }
  7990. exports.isArray = isArray;
  7991. function isBoolean(arg) {
  7992. return typeof arg === 'boolean';
  7993. }
  7994. exports.isBoolean = isBoolean;
  7995. function isNull(arg) {
  7996. return arg === null;
  7997. }
  7998. exports.isNull = isNull;
  7999. function isNullOrUndefined(arg) {
  8000. return arg == null;
  8001. }
  8002. exports.isNullOrUndefined = isNullOrUndefined;
  8003. function isNumber(arg) {
  8004. return typeof arg === 'number';
  8005. }
  8006. exports.isNumber = isNumber;
  8007. function isString(arg) {
  8008. return typeof arg === 'string';
  8009. }
  8010. exports.isString = isString;
  8011. function isSymbol(arg) {
  8012. return typeof arg === 'symbol';
  8013. }
  8014. exports.isSymbol = isSymbol;
  8015. function isUndefined(arg) {
  8016. return arg === void 0;
  8017. }
  8018. exports.isUndefined = isUndefined;
  8019. function isRegExp(re) {
  8020. return objectToString(re) === '[object RegExp]';
  8021. }
  8022. exports.isRegExp = isRegExp;
  8023. function isObject(arg) {
  8024. return typeof arg === 'object' && arg !== null;
  8025. }
  8026. exports.isObject = isObject;
  8027. function isDate(d) {
  8028. return objectToString(d) === '[object Date]';
  8029. }
  8030. exports.isDate = isDate;
  8031. function isError(e) {
  8032. return (objectToString(e) === '[object Error]' || e instanceof Error);
  8033. }
  8034. exports.isError = isError;
  8035. function isFunction(arg) {
  8036. return typeof arg === 'function';
  8037. }
  8038. exports.isFunction = isFunction;
  8039. function isPrimitive(arg) {
  8040. return arg === null ||
  8041. typeof arg === 'boolean' ||
  8042. typeof arg === 'number' ||
  8043. typeof arg === 'string' ||
  8044. typeof arg === 'symbol' || // ES6 symbol
  8045. typeof arg === 'undefined';
  8046. }
  8047. exports.isPrimitive = isPrimitive;
  8048. exports.isBuffer = Buffer.isBuffer;
  8049. function objectToString(o) {
  8050. return Object.prototype.toString.call(o);
  8051. }
  8052. }).call(this,{"isBuffer":require("../../is-buffer/index.js")})
  8053. },{"../../is-buffer/index.js":17}],10:[function(require,module,exports){
  8054. (function (Buffer){
  8055. 'use strict';
  8056. var inherits = require('inherits')
  8057. var md5 = require('./md5')
  8058. var rmd160 = require('ripemd160')
  8059. var sha = require('sha.js')
  8060. var Base = require('cipher-base')
  8061. function HashNoConstructor(hash) {
  8062. Base.call(this, 'digest')
  8063. this._hash = hash
  8064. this.buffers = []
  8065. }
  8066. inherits(HashNoConstructor, Base)
  8067. HashNoConstructor.prototype._update = function (data) {
  8068. this.buffers.push(data)
  8069. }
  8070. HashNoConstructor.prototype._final = function () {
  8071. var buf = Buffer.concat(this.buffers)
  8072. var r = this._hash(buf)
  8073. this.buffers = null
  8074. return r
  8075. }
  8076. function Hash(hash) {
  8077. Base.call(this, 'digest')
  8078. this._hash = hash
  8079. }
  8080. inherits(Hash, Base)
  8081. Hash.prototype._update = function (data) {
  8082. this._hash.update(data)
  8083. }
  8084. Hash.prototype._final = function () {
  8085. return this._hash.digest()
  8086. }
  8087. module.exports = function createHash (alg) {
  8088. alg = alg.toLowerCase()
  8089. if ('md5' === alg) return new HashNoConstructor(md5)
  8090. if ('rmd160' === alg || 'ripemd160' === alg) return new HashNoConstructor(rmd160)
  8091. return new Hash(sha(alg))
  8092. }
  8093. }).call(this,require("buffer").Buffer)
  8094. },{"./md5":12,"buffer":7,"cipher-base":8,"inherits":16,"ripemd160":34,"sha.js":36}],11:[function(require,module,exports){
  8095. (function (Buffer){
  8096. 'use strict';
  8097. var intSize = 4;
  8098. var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0);
  8099. var chrsz = 8;
  8100. function toArray(buf, bigEndian) {
  8101. if ((buf.length % intSize) !== 0) {
  8102. var len = buf.length + (intSize - (buf.length % intSize));
  8103. buf = Buffer.concat([buf, zeroBuffer], len);
  8104. }
  8105. var arr = [];
  8106. var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE;
  8107. for (var i = 0; i < buf.length; i += intSize) {
  8108. arr.push(fn.call(buf, i));
  8109. }
  8110. return arr;
  8111. }
  8112. function toBuffer(arr, size, bigEndian) {
  8113. var buf = new Buffer(size);
  8114. var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE;
  8115. for (var i = 0; i < arr.length; i++) {
  8116. fn.call(buf, arr[i], i * 4, true);
  8117. }
  8118. return buf;
  8119. }
  8120. function hash(buf, fn, hashSize, bigEndian) {
  8121. if (!Buffer.isBuffer(buf)) buf = new Buffer(buf);
  8122. var arr = fn(toArray(buf, bigEndian), buf.length * chrsz);
  8123. return toBuffer(arr, hashSize, bigEndian);
  8124. }
  8125. exports.hash = hash;
  8126. }).call(this,require("buffer").Buffer)
  8127. },{"buffer":7}],12:[function(require,module,exports){
  8128. 'use strict';
  8129. /*
  8130. * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
  8131. * Digest Algorithm, as defined in RFC 1321.
  8132. * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
  8133. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  8134. * Distributed under the BSD License
  8135. * See http://pajhome.org.uk/crypt/md5 for more info.
  8136. */
  8137. var helpers = require('./helpers');
  8138. /*
  8139. * Calculate the MD5 of an array of little-endian words, and a bit length
  8140. */
  8141. function core_md5(x, len)
  8142. {
  8143. /* append padding */
  8144. x[len >> 5] |= 0x80 << ((len) % 32);
  8145. x[(((len + 64) >>> 9) << 4) + 14] = len;
  8146. var a = 1732584193;
  8147. var b = -271733879;
  8148. var c = -1732584194;
  8149. var d = 271733878;
  8150. for(var i = 0; i < x.length; i += 16)
  8151. {
  8152. var olda = a;
  8153. var oldb = b;
  8154. var oldc = c;
  8155. var oldd = d;
  8156. a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
  8157. d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
  8158. c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
  8159. b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
  8160. a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
  8161. d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
  8162. c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
  8163. b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
  8164. a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
  8165. d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
  8166. c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
  8167. b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
  8168. a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
  8169. d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
  8170. c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
  8171. b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
  8172. a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
  8173. d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
  8174. c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
  8175. b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
  8176. a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
  8177. d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
  8178. c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
  8179. b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
  8180. a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
  8181. d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
  8182. c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
  8183. b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
  8184. a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
  8185. d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
  8186. c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
  8187. b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
  8188. a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
  8189. d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
  8190. c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
  8191. b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
  8192. a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
  8193. d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
  8194. c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
  8195. b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
  8196. a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
  8197. d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
  8198. c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
  8199. b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
  8200. a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
  8201. d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
  8202. c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
  8203. b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
  8204. a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
  8205. d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
  8206. c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
  8207. b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
  8208. a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
  8209. d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
  8210. c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
  8211. b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
  8212. a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
  8213. d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
  8214. c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
  8215. b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
  8216. a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
  8217. d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
  8218. c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
  8219. b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
  8220. a = safe_add(a, olda);
  8221. b = safe_add(b, oldb);
  8222. c = safe_add(c, oldc);
  8223. d = safe_add(d, oldd);
  8224. }
  8225. return Array(a, b, c, d);
  8226. }
  8227. /*
  8228. * These functions implement the four basic operations the algorithm uses.
  8229. */
  8230. function md5_cmn(q, a, b, x, s, t)
  8231. {
  8232. return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
  8233. }
  8234. function md5_ff(a, b, c, d, x, s, t)
  8235. {
  8236. return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
  8237. }
  8238. function md5_gg(a, b, c, d, x, s, t)
  8239. {
  8240. return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
  8241. }
  8242. function md5_hh(a, b, c, d, x, s, t)
  8243. {
  8244. return md5_cmn(b ^ c ^ d, a, b, x, s, t);
  8245. }
  8246. function md5_ii(a, b, c, d, x, s, t)
  8247. {
  8248. return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
  8249. }
  8250. /*
  8251. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  8252. * to work around bugs in some JS interpreters.
  8253. */
  8254. function safe_add(x, y)
  8255. {
  8256. var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  8257. var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  8258. return (msw << 16) | (lsw & 0xFFFF);
  8259. }
  8260. /*
  8261. * Bitwise rotate a 32-bit number to the left.
  8262. */
  8263. function bit_rol(num, cnt)
  8264. {
  8265. return (num << cnt) | (num >>> (32 - cnt));
  8266. }
  8267. module.exports = function md5(buf) {
  8268. return helpers.hash(buf, core_md5, 16);
  8269. };
  8270. },{"./helpers":11}],13:[function(require,module,exports){
  8271. (function (Buffer){
  8272. 'use strict';
  8273. var createHash = require('create-hash/browser');
  8274. var inherits = require('inherits')
  8275. var Transform = require('stream').Transform
  8276. var ZEROS = new Buffer(128)
  8277. ZEROS.fill(0)
  8278. function Hmac(alg, key) {
  8279. Transform.call(this)
  8280. alg = alg.toLowerCase()
  8281. if (typeof key === 'string') {
  8282. key = new Buffer(key)
  8283. }
  8284. var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64
  8285. this._alg = alg
  8286. this._key = key
  8287. if (key.length > blocksize) {
  8288. key = createHash(alg).update(key).digest()
  8289. } else if (key.length < blocksize) {
  8290. key = Buffer.concat([key, ZEROS], blocksize)
  8291. }
  8292. var ipad = this._ipad = new Buffer(blocksize)
  8293. var opad = this._opad = new Buffer(blocksize)
  8294. for (var i = 0; i < blocksize; i++) {
  8295. ipad[i] = key[i] ^ 0x36
  8296. opad[i] = key[i] ^ 0x5C
  8297. }
  8298. this._hash = createHash(alg).update(ipad)
  8299. }
  8300. inherits(Hmac, Transform)
  8301. Hmac.prototype.update = function (data, enc) {
  8302. this._hash.update(data, enc)
  8303. return this
  8304. }
  8305. Hmac.prototype._transform = function (data, _, next) {
  8306. this._hash.update(data)
  8307. next()
  8308. }
  8309. Hmac.prototype._flush = function (next) {
  8310. this.push(this.digest())
  8311. next()
  8312. }
  8313. Hmac.prototype.digest = function (enc) {
  8314. var h = this._hash.digest()
  8315. return createHash(this._alg).update(this._opad).update(h).digest(enc)
  8316. }
  8317. module.exports = function createHmac(alg, key) {
  8318. return new Hmac(alg, key)
  8319. }
  8320. }).call(this,require("buffer").Buffer)
  8321. },{"buffer":7,"create-hash/browser":10,"inherits":16,"stream":43}],14:[function(require,module,exports){
  8322. // Copyright Joyent, Inc. and other Node contributors.
  8323. //
  8324. // Permission is hereby granted, free of charge, to any person obtaining a
  8325. // copy of this software and associated documentation files (the
  8326. // "Software"), to deal in the Software without restriction, including
  8327. // without limitation the rights to use, copy, modify, merge, publish,
  8328. // distribute, sublicense, and/or sell copies of the Software, and to permit
  8329. // persons to whom the Software is furnished to do so, subject to the
  8330. // following conditions:
  8331. //
  8332. // The above copyright notice and this permission notice shall be included
  8333. // in all copies or substantial portions of the Software.
  8334. //
  8335. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  8336. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  8337. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  8338. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  8339. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  8340. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  8341. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  8342. function EventEmitter() {
  8343. this._events = this._events || {};
  8344. this._maxListeners = this._maxListeners || undefined;
  8345. }
  8346. module.exports = EventEmitter;
  8347. // Backwards-compat with node 0.10.x
  8348. EventEmitter.EventEmitter = EventEmitter;
  8349. EventEmitter.prototype._events = undefined;
  8350. EventEmitter.prototype._maxListeners = undefined;
  8351. // By default EventEmitters will print a warning if more than 10 listeners are
  8352. // added to it. This is a useful default which helps finding memory leaks.
  8353. EventEmitter.defaultMaxListeners = 10;
  8354. // Obviously not all Emitters should be limited to 10. This function allows
  8355. // that to be increased. Set to zero for unlimited.
  8356. EventEmitter.prototype.setMaxListeners = function(n) {
  8357. if (!isNumber(n) || n < 0 || isNaN(n))
  8358. throw TypeError('n must be a positive number');
  8359. this._maxListeners = n;
  8360. return this;
  8361. };
  8362. EventEmitter.prototype.emit = function(type) {
  8363. var er, handler, len, args, i, listeners;
  8364. if (!this._events)
  8365. this._events = {};
  8366. // If there is no 'error' event listener then throw.
  8367. if (type === 'error') {
  8368. if (!this._events.error ||
  8369. (isObject(this._events.error) && !this._events.error.length)) {
  8370. er = arguments[1];
  8371. if (er instanceof Error) {
  8372. throw er; // Unhandled 'error' event
  8373. } else {
  8374. // At least give some kind of context to the user
  8375. var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
  8376. err.context = er;
  8377. throw err;
  8378. }
  8379. }
  8380. }
  8381. handler = this._events[type];
  8382. if (isUndefined(handler))
  8383. return false;
  8384. if (isFunction(handler)) {
  8385. switch (arguments.length) {
  8386. // fast cases
  8387. case 1:
  8388. handler.call(this);
  8389. break;
  8390. case 2:
  8391. handler.call(this, arguments[1]);
  8392. break;
  8393. case 3:
  8394. handler.call(this, arguments[1], arguments[2]);
  8395. break;
  8396. // slower
  8397. default:
  8398. args = Array.prototype.slice.call(arguments, 1);
  8399. handler.apply(this, args);
  8400. }
  8401. } else if (isObject(handler)) {
  8402. args = Array.prototype.slice.call(arguments, 1);
  8403. listeners = handler.slice();
  8404. len = listeners.length;
  8405. for (i = 0; i < len; i++)
  8406. listeners[i].apply(this, args);
  8407. }
  8408. return true;
  8409. };
  8410. EventEmitter.prototype.addListener = function(type, listener) {
  8411. var m;
  8412. if (!isFunction(listener))
  8413. throw TypeError('listener must be a function');
  8414. if (!this._events)
  8415. this._events = {};
  8416. // To avoid recursion in the case that type === "newListener"! Before
  8417. // adding it to the listeners, first emit "newListener".
  8418. if (this._events.newListener)
  8419. this.emit('newListener', type,
  8420. isFunction(listener.listener) ?
  8421. listener.listener : listener);
  8422. if (!this._events[type])
  8423. // Optimize the case of one listener. Don't need the extra array object.
  8424. this._events[type] = listener;
  8425. else if (isObject(this._events[type]))
  8426. // If we've already got an array, just append.
  8427. this._events[type].push(listener);
  8428. else
  8429. // Adding the second element, need to change to array.
  8430. this._events[type] = [this._events[type], listener];
  8431. // Check for listener leak
  8432. if (isObject(this._events[type]) && !this._events[type].warned) {
  8433. if (!isUndefined(this._maxListeners)) {
  8434. m = this._maxListeners;
  8435. } else {
  8436. m = EventEmitter.defaultMaxListeners;
  8437. }
  8438. if (m && m > 0 && this._events[type].length > m) {
  8439. this._events[type].warned = true;
  8440. console.error('(node) warning: possible EventEmitter memory ' +
  8441. 'leak detected. %d listeners added. ' +
  8442. 'Use emitter.setMaxListeners() to increase limit.',
  8443. this._events[type].length);
  8444. if (typeof console.trace === 'function') {
  8445. // not supported in IE 10
  8446. console.trace();
  8447. }
  8448. }
  8449. }
  8450. return this;
  8451. };
  8452. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  8453. EventEmitter.prototype.once = function(type, listener) {
  8454. if (!isFunction(listener))
  8455. throw TypeError('listener must be a function');
  8456. var fired = false;
  8457. function g() {
  8458. this.removeListener(type, g);
  8459. if (!fired) {
  8460. fired = true;
  8461. listener.apply(this, arguments);
  8462. }
  8463. }
  8464. g.listener = listener;
  8465. this.on(type, g);
  8466. return this;
  8467. };
  8468. // emits a 'removeListener' event iff the listener was removed
  8469. EventEmitter.prototype.removeListener = function(type, listener) {
  8470. var list, position, length, i;
  8471. if (!isFunction(listener))
  8472. throw TypeError('listener must be a function');
  8473. if (!this._events || !this._events[type])
  8474. return this;
  8475. list = this._events[type];
  8476. length = list.length;
  8477. position = -1;
  8478. if (list === listener ||
  8479. (isFunction(list.listener) && list.listener === listener)) {
  8480. delete this._events[type];
  8481. if (this._events.removeListener)
  8482. this.emit('removeListener', type, listener);
  8483. } else if (isObject(list)) {
  8484. for (i = length; i-- > 0;) {
  8485. if (list[i] === listener ||
  8486. (list[i].listener && list[i].listener === listener)) {
  8487. position = i;
  8488. break;
  8489. }
  8490. }
  8491. if (position < 0)
  8492. return this;
  8493. if (list.length === 1) {
  8494. list.length = 0;
  8495. delete this._events[type];
  8496. } else {
  8497. list.splice(position, 1);
  8498. }
  8499. if (this._events.removeListener)
  8500. this.emit('removeListener', type, listener);
  8501. }
  8502. return this;
  8503. };
  8504. EventEmitter.prototype.removeAllListeners = function(type) {
  8505. var key, listeners;
  8506. if (!this._events)
  8507. return this;
  8508. // not listening for removeListener, no need to emit
  8509. if (!this._events.removeListener) {
  8510. if (arguments.length === 0)
  8511. this._events = {};
  8512. else if (this._events[type])
  8513. delete this._events[type];
  8514. return this;
  8515. }
  8516. // emit removeListener for all listeners on all events
  8517. if (arguments.length === 0) {
  8518. for (key in this._events) {
  8519. if (key === 'removeListener') continue;
  8520. this.removeAllListeners(key);
  8521. }
  8522. this.removeAllListeners('removeListener');
  8523. this._events = {};
  8524. return this;
  8525. }
  8526. listeners = this._events[type];
  8527. if (isFunction(listeners)) {
  8528. this.removeListener(type, listeners);
  8529. } else if (listeners) {
  8530. // LIFO order
  8531. while (listeners.length)
  8532. this.removeListener(type, listeners[listeners.length - 1]);
  8533. }
  8534. delete this._events[type];
  8535. return this;
  8536. };
  8537. EventEmitter.prototype.listeners = function(type) {
  8538. var ret;
  8539. if (!this._events || !this._events[type])
  8540. ret = [];
  8541. else if (isFunction(this._events[type]))
  8542. ret = [this._events[type]];
  8543. else
  8544. ret = this._events[type].slice();
  8545. return ret;
  8546. };
  8547. EventEmitter.prototype.listenerCount = function(type) {
  8548. if (this._events) {
  8549. var evlistener = this._events[type];
  8550. if (isFunction(evlistener))
  8551. return 1;
  8552. else if (evlistener)
  8553. return evlistener.length;
  8554. }
  8555. return 0;
  8556. };
  8557. EventEmitter.listenerCount = function(emitter, type) {
  8558. return emitter.listenerCount(type);
  8559. };
  8560. function isFunction(arg) {
  8561. return typeof arg === 'function';
  8562. }
  8563. function isNumber(arg) {
  8564. return typeof arg === 'number';
  8565. }
  8566. function isObject(arg) {
  8567. return typeof arg === 'object' && arg !== null;
  8568. }
  8569. function isUndefined(arg) {
  8570. return arg === void 0;
  8571. }
  8572. },{}],15:[function(require,module,exports){
  8573. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  8574. var e, m
  8575. var eLen = nBytes * 8 - mLen - 1
  8576. var eMax = (1 << eLen) - 1
  8577. var eBias = eMax >> 1
  8578. var nBits = -7
  8579. var i = isLE ? (nBytes - 1) : 0
  8580. var d = isLE ? -1 : 1
  8581. var s = buffer[offset + i]
  8582. i += d
  8583. e = s & ((1 << (-nBits)) - 1)
  8584. s >>= (-nBits)
  8585. nBits += eLen
  8586. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  8587. m = e & ((1 << (-nBits)) - 1)
  8588. e >>= (-nBits)
  8589. nBits += mLen
  8590. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  8591. if (e === 0) {
  8592. e = 1 - eBias
  8593. } else if (e === eMax) {
  8594. return m ? NaN : ((s ? -1 : 1) * Infinity)
  8595. } else {
  8596. m = m + Math.pow(2, mLen)
  8597. e = e - eBias
  8598. }
  8599. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  8600. }
  8601. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  8602. var e, m, c
  8603. var eLen = nBytes * 8 - mLen - 1
  8604. var eMax = (1 << eLen) - 1
  8605. var eBias = eMax >> 1
  8606. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  8607. var i = isLE ? 0 : (nBytes - 1)
  8608. var d = isLE ? 1 : -1
  8609. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  8610. value = Math.abs(value)
  8611. if (isNaN(value) || value === Infinity) {
  8612. m = isNaN(value) ? 1 : 0
  8613. e = eMax
  8614. } else {
  8615. e = Math.floor(Math.log(value) / Math.LN2)
  8616. if (value * (c = Math.pow(2, -e)) < 1) {
  8617. e--
  8618. c *= 2
  8619. }
  8620. if (e + eBias >= 1) {
  8621. value += rt / c
  8622. } else {
  8623. value += rt * Math.pow(2, 1 - eBias)
  8624. }
  8625. if (value * c >= 2) {
  8626. e++
  8627. c /= 2
  8628. }
  8629. if (e + eBias >= eMax) {
  8630. m = 0
  8631. e = eMax
  8632. } else if (e + eBias >= 1) {
  8633. m = (value * c - 1) * Math.pow(2, mLen)
  8634. e = e + eBias
  8635. } else {
  8636. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  8637. e = 0
  8638. }
  8639. }
  8640. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  8641. e = (e << mLen) | m
  8642. eLen += mLen
  8643. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  8644. buffer[offset + i - d] |= s * 128
  8645. }
  8646. },{}],16:[function(require,module,exports){
  8647. if (typeof Object.create === 'function') {
  8648. // implementation from standard node.js 'util' module
  8649. module.exports = function inherits(ctor, superCtor) {
  8650. ctor.super_ = superCtor
  8651. ctor.prototype = Object.create(superCtor.prototype, {
  8652. constructor: {
  8653. value: ctor,
  8654. enumerable: false,
  8655. writable: true,
  8656. configurable: true
  8657. }
  8658. });
  8659. };
  8660. } else {
  8661. // old school shim for old browsers
  8662. module.exports = function inherits(ctor, superCtor) {
  8663. ctor.super_ = superCtor
  8664. var TempCtor = function () {}
  8665. TempCtor.prototype = superCtor.prototype
  8666. ctor.prototype = new TempCtor()
  8667. ctor.prototype.constructor = ctor
  8668. }
  8669. }
  8670. },{}],17:[function(require,module,exports){
  8671. /*!
  8672. * Determine if an object is a Buffer
  8673. *
  8674. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  8675. * @license MIT
  8676. */
  8677. // The _isBuffer check is for Safari 5-7 support, because it's missing
  8678. // Object.prototype.constructor. Remove this eventually
  8679. module.exports = function (obj) {
  8680. return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
  8681. }
  8682. function isBuffer (obj) {
  8683. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  8684. }
  8685. // For Node v0.10 support. Remove this eventually.
  8686. function isSlowBuffer (obj) {
  8687. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
  8688. }
  8689. },{}],18:[function(require,module,exports){
  8690. var toString = {}.toString;
  8691. module.exports = Array.isArray || function (arr) {
  8692. return toString.call(arr) == '[object Array]';
  8693. };
  8694. },{}],19:[function(require,module,exports){
  8695. (function (process,Buffer){
  8696. var createHmac = require('create-hmac')
  8697. var checkParameters = require('./precondition')
  8698. exports.pbkdf2 = function (password, salt, iterations, keylen, digest, callback) {
  8699. if (typeof digest === 'function') {
  8700. callback = digest
  8701. digest = undefined
  8702. }
  8703. checkParameters(iterations, keylen)
  8704. if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2')
  8705. setTimeout(function () {
  8706. callback(null, exports.pbkdf2Sync(password, salt, iterations, keylen, digest))
  8707. })
  8708. }
  8709. var defaultEncoding
  8710. if (process.browser) {
  8711. defaultEncoding = 'utf-8'
  8712. } else {
  8713. var pVersionMajor = parseInt(process.version.split('.')[0].slice(1), 10)
  8714. defaultEncoding = pVersionMajor >= 6 ? 'utf-8' : 'binary'
  8715. }
  8716. exports.pbkdf2Sync = function (password, salt, iterations, keylen, digest) {
  8717. if (!Buffer.isBuffer(password)) password = new Buffer(password, defaultEncoding)
  8718. if (!Buffer.isBuffer(salt)) salt = new Buffer(salt, defaultEncoding)
  8719. checkParameters(iterations, keylen)
  8720. digest = digest || 'sha1'
  8721. var hLen
  8722. var l = 1
  8723. var DK = new Buffer(keylen)
  8724. var block1 = new Buffer(salt.length + 4)
  8725. salt.copy(block1, 0, 0, salt.length)
  8726. var r
  8727. var T
  8728. for (var i = 1; i <= l; i++) {
  8729. block1.writeUInt32BE(i, salt.length)
  8730. var U = createHmac(digest, password).update(block1).digest()
  8731. if (!hLen) {
  8732. hLen = U.length
  8733. T = new Buffer(hLen)
  8734. l = Math.ceil(keylen / hLen)
  8735. r = keylen - (l - 1) * hLen
  8736. }
  8737. U.copy(T, 0, 0, hLen)
  8738. for (var j = 1; j < iterations; j++) {
  8739. U = createHmac(digest, password).update(U).digest()
  8740. for (var k = 0; k < hLen; k++) T[k] ^= U[k]
  8741. }
  8742. var destPos = (i - 1) * hLen
  8743. var len = (i === l ? r : hLen)
  8744. T.copy(DK, destPos, 0, len)
  8745. }
  8746. return DK
  8747. }
  8748. }).call(this,require('_process'),require("buffer").Buffer)
  8749. },{"./precondition":20,"_process":22,"buffer":7,"create-hmac":13}],20:[function(require,module,exports){
  8750. var MAX_ALLOC = Math.pow(2, 30) - 1 // default in iojs
  8751. module.exports = function (iterations, keylen) {
  8752. if (typeof iterations !== 'number') {
  8753. throw new TypeError('Iterations not a number')
  8754. }
  8755. if (iterations < 0) {
  8756. throw new TypeError('Bad iterations')
  8757. }
  8758. if (typeof keylen !== 'number') {
  8759. throw new TypeError('Key length not a number')
  8760. }
  8761. if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) { /* eslint no-self-compare: 0 */
  8762. throw new TypeError('Bad key length')
  8763. }
  8764. }
  8765. },{}],21:[function(require,module,exports){
  8766. (function (process){
  8767. 'use strict';
  8768. if (!process.version ||
  8769. process.version.indexOf('v0.') === 0 ||
  8770. process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
  8771. module.exports = nextTick;
  8772. } else {
  8773. module.exports = process.nextTick;
  8774. }
  8775. function nextTick(fn, arg1, arg2, arg3) {
  8776. if (typeof fn !== 'function') {
  8777. throw new TypeError('"callback" argument must be a function');
  8778. }
  8779. var len = arguments.length;
  8780. var args, i;
  8781. switch (len) {
  8782. case 0:
  8783. case 1:
  8784. return process.nextTick(fn);
  8785. case 2:
  8786. return process.nextTick(function afterTickOne() {
  8787. fn.call(null, arg1);
  8788. });
  8789. case 3:
  8790. return process.nextTick(function afterTickTwo() {
  8791. fn.call(null, arg1, arg2);
  8792. });
  8793. case 4:
  8794. return process.nextTick(function afterTickThree() {
  8795. fn.call(null, arg1, arg2, arg3);
  8796. });
  8797. default:
  8798. args = new Array(len - 1);
  8799. i = 0;
  8800. while (i < args.length) {
  8801. args[i++] = arguments[i];
  8802. }
  8803. return process.nextTick(function afterTick() {
  8804. fn.apply(null, args);
  8805. });
  8806. }
  8807. }
  8808. }).call(this,require('_process'))
  8809. },{"_process":22}],22:[function(require,module,exports){
  8810. // shim for using process in browser
  8811. var process = module.exports = {};
  8812. // cached from whatever global is present so that test runners that stub it
  8813. // don't break things. But we need to wrap it in a try catch in case it is
  8814. // wrapped in strict mode code which doesn't define any globals. It's inside a
  8815. // function because try/catches deoptimize in certain engines.
  8816. var cachedSetTimeout;
  8817. var cachedClearTimeout;
  8818. function defaultSetTimout() {
  8819. throw new Error('setTimeout has not been defined');
  8820. }
  8821. function defaultClearTimeout () {
  8822. throw new Error('clearTimeout has not been defined');
  8823. }
  8824. (function () {
  8825. try {
  8826. if (typeof setTimeout === 'function') {
  8827. cachedSetTimeout = setTimeout;
  8828. } else {
  8829. cachedSetTimeout = defaultSetTimout;
  8830. }
  8831. } catch (e) {
  8832. cachedSetTimeout = defaultSetTimout;
  8833. }
  8834. try {
  8835. if (typeof clearTimeout === 'function') {
  8836. cachedClearTimeout = clearTimeout;
  8837. } else {
  8838. cachedClearTimeout = defaultClearTimeout;
  8839. }
  8840. } catch (e) {
  8841. cachedClearTimeout = defaultClearTimeout;
  8842. }
  8843. } ())
  8844. function runTimeout(fun) {
  8845. if (cachedSetTimeout === setTimeout) {
  8846. //normal enviroments in sane situations
  8847. return setTimeout(fun, 0);
  8848. }
  8849. // if setTimeout wasn't available but was latter defined
  8850. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  8851. cachedSetTimeout = setTimeout;
  8852. return setTimeout(fun, 0);
  8853. }
  8854. try {
  8855. // when when somebody has screwed with setTimeout but no I.E. maddness
  8856. return cachedSetTimeout(fun, 0);
  8857. } catch(e){
  8858. try {
  8859. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  8860. return cachedSetTimeout.call(null, fun, 0);
  8861. } catch(e){
  8862. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  8863. return cachedSetTimeout.call(this, fun, 0);
  8864. }
  8865. }
  8866. }
  8867. function runClearTimeout(marker) {
  8868. if (cachedClearTimeout === clearTimeout) {
  8869. //normal enviroments in sane situations
  8870. return clearTimeout(marker);
  8871. }
  8872. // if clearTimeout wasn't available but was latter defined
  8873. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  8874. cachedClearTimeout = clearTimeout;
  8875. return clearTimeout(marker);
  8876. }
  8877. try {
  8878. // when when somebody has screwed with setTimeout but no I.E. maddness
  8879. return cachedClearTimeout(marker);
  8880. } catch (e){
  8881. try {
  8882. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  8883. return cachedClearTimeout.call(null, marker);
  8884. } catch (e){
  8885. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  8886. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  8887. return cachedClearTimeout.call(this, marker);
  8888. }
  8889. }
  8890. }
  8891. var queue = [];
  8892. var draining = false;
  8893. var currentQueue;
  8894. var queueIndex = -1;
  8895. function cleanUpNextTick() {
  8896. if (!draining || !currentQueue) {
  8897. return;
  8898. }
  8899. draining = false;
  8900. if (currentQueue.length) {
  8901. queue = currentQueue.concat(queue);
  8902. } else {
  8903. queueIndex = -1;
  8904. }
  8905. if (queue.length) {
  8906. drainQueue();
  8907. }
  8908. }
  8909. function drainQueue() {
  8910. if (draining) {
  8911. return;
  8912. }
  8913. var timeout = runTimeout(cleanUpNextTick);
  8914. draining = true;
  8915. var len = queue.length;
  8916. while(len) {
  8917. currentQueue = queue;
  8918. queue = [];
  8919. while (++queueIndex < len) {
  8920. if (currentQueue) {
  8921. currentQueue[queueIndex].run();
  8922. }
  8923. }
  8924. queueIndex = -1;
  8925. len = queue.length;
  8926. }
  8927. currentQueue = null;
  8928. draining = false;
  8929. runClearTimeout(timeout);
  8930. }
  8931. process.nextTick = function (fun) {
  8932. var args = new Array(arguments.length - 1);
  8933. if (arguments.length > 1) {
  8934. for (var i = 1; i < arguments.length; i++) {
  8935. args[i - 1] = arguments[i];
  8936. }
  8937. }
  8938. queue.push(new Item(fun, args));
  8939. if (queue.length === 1 && !draining) {
  8940. runTimeout(drainQueue);
  8941. }
  8942. };
  8943. // v8 likes predictible objects
  8944. function Item(fun, array) {
  8945. this.fun = fun;
  8946. this.array = array;
  8947. }
  8948. Item.prototype.run = function () {
  8949. this.fun.apply(null, this.array);
  8950. };
  8951. process.title = 'browser';
  8952. process.browser = true;
  8953. process.env = {};
  8954. process.argv = [];
  8955. process.version = ''; // empty string to avoid regexp issues
  8956. process.versions = {};
  8957. function noop() {}
  8958. process.on = noop;
  8959. process.addListener = noop;
  8960. process.once = noop;
  8961. process.off = noop;
  8962. process.removeListener = noop;
  8963. process.removeAllListeners = noop;
  8964. process.emit = noop;
  8965. process.binding = function (name) {
  8966. throw new Error('process.binding is not supported');
  8967. };
  8968. process.cwd = function () { return '/' };
  8969. process.chdir = function (dir) {
  8970. throw new Error('process.chdir is not supported');
  8971. };
  8972. process.umask = function() { return 0; };
  8973. },{}],23:[function(require,module,exports){
  8974. module.exports = require("./lib/_stream_duplex.js")
  8975. },{"./lib/_stream_duplex.js":24}],24:[function(require,module,exports){
  8976. // a duplex stream is just a stream that is both readable and writable.
  8977. // Since JS doesn't have multiple prototypal inheritance, this class
  8978. // prototypally inherits from Readable, and then parasitically from
  8979. // Writable.
  8980. 'use strict';
  8981. /*<replacement>*/
  8982. var objectKeys = Object.keys || function (obj) {
  8983. var keys = [];
  8984. for (var key in obj) {
  8985. keys.push(key);
  8986. }return keys;
  8987. };
  8988. /*</replacement>*/
  8989. module.exports = Duplex;
  8990. /*<replacement>*/
  8991. var processNextTick = require('process-nextick-args');
  8992. /*</replacement>*/
  8993. /*<replacement>*/
  8994. var util = require('core-util-is');
  8995. util.inherits = require('inherits');
  8996. /*</replacement>*/
  8997. var Readable = require('./_stream_readable');
  8998. var Writable = require('./_stream_writable');
  8999. util.inherits(Duplex, Readable);
  9000. var keys = objectKeys(Writable.prototype);
  9001. for (var v = 0; v < keys.length; v++) {
  9002. var method = keys[v];
  9003. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  9004. }
  9005. function Duplex(options) {
  9006. if (!(this instanceof Duplex)) return new Duplex(options);
  9007. Readable.call(this, options);
  9008. Writable.call(this, options);
  9009. if (options && options.readable === false) this.readable = false;
  9010. if (options && options.writable === false) this.writable = false;
  9011. this.allowHalfOpen = true;
  9012. if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
  9013. this.once('end', onend);
  9014. }
  9015. // the no-half-open enforcer
  9016. function onend() {
  9017. // if we allow half-open state, or if the writable side ended,
  9018. // then we're ok.
  9019. if (this.allowHalfOpen || this._writableState.ended) return;
  9020. // no more data can be written.
  9021. // But allow more writes to happen in this tick.
  9022. processNextTick(onEndNT, this);
  9023. }
  9024. function onEndNT(self) {
  9025. self.end();
  9026. }
  9027. function forEach(xs, f) {
  9028. for (var i = 0, l = xs.length; i < l; i++) {
  9029. f(xs[i], i);
  9030. }
  9031. }
  9032. },{"./_stream_readable":26,"./_stream_writable":28,"core-util-is":9,"inherits":16,"process-nextick-args":21}],25:[function(require,module,exports){
  9033. // a passthrough stream.
  9034. // basically just the most minimal sort of Transform stream.
  9035. // Every written chunk gets output as-is.
  9036. 'use strict';
  9037. module.exports = PassThrough;
  9038. var Transform = require('./_stream_transform');
  9039. /*<replacement>*/
  9040. var util = require('core-util-is');
  9041. util.inherits = require('inherits');
  9042. /*</replacement>*/
  9043. util.inherits(PassThrough, Transform);
  9044. function PassThrough(options) {
  9045. if (!(this instanceof PassThrough)) return new PassThrough(options);
  9046. Transform.call(this, options);
  9047. }
  9048. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  9049. cb(null, chunk);
  9050. };
  9051. },{"./_stream_transform":27,"core-util-is":9,"inherits":16}],26:[function(require,module,exports){
  9052. (function (process){
  9053. 'use strict';
  9054. module.exports = Readable;
  9055. /*<replacement>*/
  9056. var processNextTick = require('process-nextick-args');
  9057. /*</replacement>*/
  9058. /*<replacement>*/
  9059. var isArray = require('isarray');
  9060. /*</replacement>*/
  9061. Readable.ReadableState = ReadableState;
  9062. /*<replacement>*/
  9063. var EE = require('events').EventEmitter;
  9064. var EElistenerCount = function (emitter, type) {
  9065. return emitter.listeners(type).length;
  9066. };
  9067. /*</replacement>*/
  9068. /*<replacement>*/
  9069. var Stream;
  9070. (function () {
  9071. try {
  9072. Stream = require('st' + 'ream');
  9073. } catch (_) {} finally {
  9074. if (!Stream) Stream = require('events').EventEmitter;
  9075. }
  9076. })();
  9077. /*</replacement>*/
  9078. var Buffer = require('buffer').Buffer;
  9079. /*<replacement>*/
  9080. var bufferShim = require('buffer-shims');
  9081. /*</replacement>*/
  9082. /*<replacement>*/
  9083. var util = require('core-util-is');
  9084. util.inherits = require('inherits');
  9085. /*</replacement>*/
  9086. /*<replacement>*/
  9087. var debugUtil = require('util');
  9088. var debug = void 0;
  9089. if (debugUtil && debugUtil.debuglog) {
  9090. debug = debugUtil.debuglog('stream');
  9091. } else {
  9092. debug = function () {};
  9093. }
  9094. /*</replacement>*/
  9095. var BufferList = require('./internal/streams/BufferList');
  9096. var StringDecoder;
  9097. util.inherits(Readable, Stream);
  9098. function prependListener(emitter, event, fn) {
  9099. if (typeof emitter.prependListener === 'function') {
  9100. return emitter.prependListener(event, fn);
  9101. } else {
  9102. // This is a hack to make sure that our error handler is attached before any
  9103. // userland ones. NEVER DO THIS. This is here only because this code needs
  9104. // to continue to work with older versions of Node.js that do not include
  9105. // the prependListener() method. The goal is to eventually remove this hack.
  9106. if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
  9107. }
  9108. }
  9109. var Duplex;
  9110. function ReadableState(options, stream) {
  9111. Duplex = Duplex || require('./_stream_duplex');
  9112. options = options || {};
  9113. // object stream flag. Used to make read(n) ignore n and to
  9114. // make all the buffer merging and length checks go away
  9115. this.objectMode = !!options.objectMode;
  9116. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
  9117. // the point at which it stops calling _read() to fill the buffer
  9118. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  9119. var hwm = options.highWaterMark;
  9120. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  9121. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  9122. // cast to ints.
  9123. this.highWaterMark = ~ ~this.highWaterMark;
  9124. // A linked list is used to store data chunks instead of an array because the
  9125. // linked list can remove elements from the beginning faster than
  9126. // array.shift()
  9127. this.buffer = new BufferList();
  9128. this.length = 0;
  9129. this.pipes = null;
  9130. this.pipesCount = 0;
  9131. this.flowing = null;
  9132. this.ended = false;
  9133. this.endEmitted = false;
  9134. this.reading = false;
  9135. // a flag to be able to tell if the onwrite cb is called immediately,
  9136. // or on a later tick. We set this to true at first, because any
  9137. // actions that shouldn't happen until "later" should generally also
  9138. // not happen before the first write call.
  9139. this.sync = true;
  9140. // whenever we return null, then we set a flag to say
  9141. // that we're awaiting a 'readable' event emission.
  9142. this.needReadable = false;
  9143. this.emittedReadable = false;
  9144. this.readableListening = false;
  9145. this.resumeScheduled = false;
  9146. // Crypto is kind of old and crusty. Historically, its default string
  9147. // encoding is 'binary' so we have to make this configurable.
  9148. // Everything else in the universe uses 'utf8', though.
  9149. this.defaultEncoding = options.defaultEncoding || 'utf8';
  9150. // when piping, we only care about 'readable' events that happen
  9151. // after read()ing all the bytes and not getting any pushback.
  9152. this.ranOut = false;
  9153. // the number of writers that are awaiting a drain event in .pipe()s
  9154. this.awaitDrain = 0;
  9155. // if true, a maybeReadMore has been scheduled
  9156. this.readingMore = false;
  9157. this.decoder = null;
  9158. this.encoding = null;
  9159. if (options.encoding) {
  9160. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  9161. this.decoder = new StringDecoder(options.encoding);
  9162. this.encoding = options.encoding;
  9163. }
  9164. }
  9165. var Duplex;
  9166. function Readable(options) {
  9167. Duplex = Duplex || require('./_stream_duplex');
  9168. if (!(this instanceof Readable)) return new Readable(options);
  9169. this._readableState = new ReadableState(options, this);
  9170. // legacy
  9171. this.readable = true;
  9172. if (options && typeof options.read === 'function') this._read = options.read;
  9173. Stream.call(this);
  9174. }
  9175. // Manually shove something into the read() buffer.
  9176. // This returns true if the highWaterMark has not been hit yet,
  9177. // similar to how Writable.write() returns true if you should
  9178. // write() some more.
  9179. Readable.prototype.push = function (chunk, encoding) {
  9180. var state = this._readableState;
  9181. if (!state.objectMode && typeof chunk === 'string') {
  9182. encoding = encoding || state.defaultEncoding;
  9183. if (encoding !== state.encoding) {
  9184. chunk = bufferShim.from(chunk, encoding);
  9185. encoding = '';
  9186. }
  9187. }
  9188. return readableAddChunk(this, state, chunk, encoding, false);
  9189. };
  9190. // Unshift should *always* be something directly out of read()
  9191. Readable.prototype.unshift = function (chunk) {
  9192. var state = this._readableState;
  9193. return readableAddChunk(this, state, chunk, '', true);
  9194. };
  9195. Readable.prototype.isPaused = function () {
  9196. return this._readableState.flowing === false;
  9197. };
  9198. function readableAddChunk(stream, state, chunk, encoding, addToFront) {
  9199. var er = chunkInvalid(state, chunk);
  9200. if (er) {
  9201. stream.emit('error', er);
  9202. } else if (chunk === null) {
  9203. state.reading = false;
  9204. onEofChunk(stream, state);
  9205. } else if (state.objectMode || chunk && chunk.length > 0) {
  9206. if (state.ended && !addToFront) {
  9207. var e = new Error('stream.push() after EOF');
  9208. stream.emit('error', e);
  9209. } else if (state.endEmitted && addToFront) {
  9210. var _e = new Error('stream.unshift() after end event');
  9211. stream.emit('error', _e);
  9212. } else {
  9213. var skipAdd;
  9214. if (state.decoder && !addToFront && !encoding) {
  9215. chunk = state.decoder.write(chunk);
  9216. skipAdd = !state.objectMode && chunk.length === 0;
  9217. }
  9218. if (!addToFront) state.reading = false;
  9219. // Don't add to the buffer if we've decoded to an empty string chunk and
  9220. // we're not in object mode
  9221. if (!skipAdd) {
  9222. // if we want the data now, just emit it.
  9223. if (state.flowing && state.length === 0 && !state.sync) {
  9224. stream.emit('data', chunk);
  9225. stream.read(0);
  9226. } else {
  9227. // update the buffer info.
  9228. state.length += state.objectMode ? 1 : chunk.length;
  9229. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  9230. if (state.needReadable) emitReadable(stream);
  9231. }
  9232. }
  9233. maybeReadMore(stream, state);
  9234. }
  9235. } else if (!addToFront) {
  9236. state.reading = false;
  9237. }
  9238. return needMoreData(state);
  9239. }
  9240. // if it's past the high water mark, we can push in some more.
  9241. // Also, if we have no data yet, we can stand some
  9242. // more bytes. This is to work around cases where hwm=0,
  9243. // such as the repl. Also, if the push() triggered a
  9244. // readable event, and the user called read(largeNumber) such that
  9245. // needReadable was set, then we ought to push more, so that another
  9246. // 'readable' event will be triggered.
  9247. function needMoreData(state) {
  9248. return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
  9249. }
  9250. // backwards compatibility.
  9251. Readable.prototype.setEncoding = function (enc) {
  9252. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  9253. this._readableState.decoder = new StringDecoder(enc);
  9254. this._readableState.encoding = enc;
  9255. return this;
  9256. };
  9257. // Don't raise the hwm > 8MB
  9258. var MAX_HWM = 0x800000;
  9259. function computeNewHighWaterMark(n) {
  9260. if (n >= MAX_HWM) {
  9261. n = MAX_HWM;
  9262. } else {
  9263. // Get the next highest power of 2 to prevent increasing hwm excessively in
  9264. // tiny amounts
  9265. n--;
  9266. n |= n >>> 1;
  9267. n |= n >>> 2;
  9268. n |= n >>> 4;
  9269. n |= n >>> 8;
  9270. n |= n >>> 16;
  9271. n++;
  9272. }
  9273. return n;
  9274. }
  9275. // This function is designed to be inlinable, so please take care when making
  9276. // changes to the function body.
  9277. function howMuchToRead(n, state) {
  9278. if (n <= 0 || state.length === 0 && state.ended) return 0;
  9279. if (state.objectMode) return 1;
  9280. if (n !== n) {
  9281. // Only flow one buffer at a time
  9282. if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
  9283. }
  9284. // If we're asking for more than the current hwm, then raise the hwm.
  9285. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  9286. if (n <= state.length) return n;
  9287. // Don't have enough
  9288. if (!state.ended) {
  9289. state.needReadable = true;
  9290. return 0;
  9291. }
  9292. return state.length;
  9293. }
  9294. // you can override either this method, or the async _read(n) below.
  9295. Readable.prototype.read = function (n) {
  9296. debug('read', n);
  9297. n = parseInt(n, 10);
  9298. var state = this._readableState;
  9299. var nOrig = n;
  9300. if (n !== 0) state.emittedReadable = false;
  9301. // if we're doing read(0) to trigger a readable event, but we
  9302. // already have a bunch of data in the buffer, then just trigger
  9303. // the 'readable' event and move on.
  9304. if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
  9305. debug('read: emitReadable', state.length, state.ended);
  9306. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  9307. return null;
  9308. }
  9309. n = howMuchToRead(n, state);
  9310. // if we've ended, and we're now clear, then finish it up.
  9311. if (n === 0 && state.ended) {
  9312. if (state.length === 0) endReadable(this);
  9313. return null;
  9314. }
  9315. // All the actual chunk generation logic needs to be
  9316. // *below* the call to _read. The reason is that in certain
  9317. // synthetic stream cases, such as passthrough streams, _read
  9318. // may be a completely synchronous operation which may change
  9319. // the state of the read buffer, providing enough data when
  9320. // before there was *not* enough.
  9321. //
  9322. // So, the steps are:
  9323. // 1. Figure out what the state of things will be after we do
  9324. // a read from the buffer.
  9325. //
  9326. // 2. If that resulting state will trigger a _read, then call _read.
  9327. // Note that this may be asynchronous, or synchronous. Yes, it is
  9328. // deeply ugly to write APIs this way, but that still doesn't mean
  9329. // that the Readable class should behave improperly, as streams are
  9330. // designed to be sync/async agnostic.
  9331. // Take note if the _read call is sync or async (ie, if the read call
  9332. // has returned yet), so that we know whether or not it's safe to emit
  9333. // 'readable' etc.
  9334. //
  9335. // 3. Actually pull the requested chunks out of the buffer and return.
  9336. // if we need a readable event, then we need to do some reading.
  9337. var doRead = state.needReadable;
  9338. debug('need readable', doRead);
  9339. // if we currently have less than the highWaterMark, then also read some
  9340. if (state.length === 0 || state.length - n < state.highWaterMark) {
  9341. doRead = true;
  9342. debug('length less than watermark', doRead);
  9343. }
  9344. // however, if we've ended, then there's no point, and if we're already
  9345. // reading, then it's unnecessary.
  9346. if (state.ended || state.reading) {
  9347. doRead = false;
  9348. debug('reading or ended', doRead);
  9349. } else if (doRead) {
  9350. debug('do read');
  9351. state.reading = true;
  9352. state.sync = true;
  9353. // if the length is currently zero, then we *need* a readable event.
  9354. if (state.length === 0) state.needReadable = true;
  9355. // call internal read method
  9356. this._read(state.highWaterMark);
  9357. state.sync = false;
  9358. // If _read pushed data synchronously, then `reading` will be false,
  9359. // and we need to re-evaluate how much data we can return to the user.
  9360. if (!state.reading) n = howMuchToRead(nOrig, state);
  9361. }
  9362. var ret;
  9363. if (n > 0) ret = fromList(n, state);else ret = null;
  9364. if (ret === null) {
  9365. state.needReadable = true;
  9366. n = 0;
  9367. } else {
  9368. state.length -= n;
  9369. }
  9370. if (state.length === 0) {
  9371. // If we have nothing in the buffer, then we want to know
  9372. // as soon as we *do* get something into the buffer.
  9373. if (!state.ended) state.needReadable = true;
  9374. // If we tried to read() past the EOF, then emit end on the next tick.
  9375. if (nOrig !== n && state.ended) endReadable(this);
  9376. }
  9377. if (ret !== null) this.emit('data', ret);
  9378. return ret;
  9379. };
  9380. function chunkInvalid(state, chunk) {
  9381. var er = null;
  9382. if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
  9383. er = new TypeError('Invalid non-string/buffer chunk');
  9384. }
  9385. return er;
  9386. }
  9387. function onEofChunk(stream, state) {
  9388. if (state.ended) return;
  9389. if (state.decoder) {
  9390. var chunk = state.decoder.end();
  9391. if (chunk && chunk.length) {
  9392. state.buffer.push(chunk);
  9393. state.length += state.objectMode ? 1 : chunk.length;
  9394. }
  9395. }
  9396. state.ended = true;
  9397. // emit 'readable' now to make sure it gets picked up.
  9398. emitReadable(stream);
  9399. }
  9400. // Don't emit readable right away in sync mode, because this can trigger
  9401. // another read() call => stack overflow. This way, it might trigger
  9402. // a nextTick recursion warning, but that's not so bad.
  9403. function emitReadable(stream) {
  9404. var state = stream._readableState;
  9405. state.needReadable = false;
  9406. if (!state.emittedReadable) {
  9407. debug('emitReadable', state.flowing);
  9408. state.emittedReadable = true;
  9409. if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream);
  9410. }
  9411. }
  9412. function emitReadable_(stream) {
  9413. debug('emit readable');
  9414. stream.emit('readable');
  9415. flow(stream);
  9416. }
  9417. // at this point, the user has presumably seen the 'readable' event,
  9418. // and called read() to consume some data. that may have triggered
  9419. // in turn another _read(n) call, in which case reading = true if
  9420. // it's in progress.
  9421. // However, if we're not ended, or reading, and the length < hwm,
  9422. // then go ahead and try to read some more preemptively.
  9423. function maybeReadMore(stream, state) {
  9424. if (!state.readingMore) {
  9425. state.readingMore = true;
  9426. processNextTick(maybeReadMore_, stream, state);
  9427. }
  9428. }
  9429. function maybeReadMore_(stream, state) {
  9430. var len = state.length;
  9431. while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
  9432. debug('maybeReadMore read 0');
  9433. stream.read(0);
  9434. if (len === state.length)
  9435. // didn't get any data, stop spinning.
  9436. break;else len = state.length;
  9437. }
  9438. state.readingMore = false;
  9439. }
  9440. // abstract method. to be overridden in specific implementation classes.
  9441. // call cb(er, data) where data is <= n in length.
  9442. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  9443. // arbitrary, and perhaps not very meaningful.
  9444. Readable.prototype._read = function (n) {
  9445. this.emit('error', new Error('not implemented'));
  9446. };
  9447. Readable.prototype.pipe = function (dest, pipeOpts) {
  9448. var src = this;
  9449. var state = this._readableState;
  9450. switch (state.pipesCount) {
  9451. case 0:
  9452. state.pipes = dest;
  9453. break;
  9454. case 1:
  9455. state.pipes = [state.pipes, dest];
  9456. break;
  9457. default:
  9458. state.pipes.push(dest);
  9459. break;
  9460. }
  9461. state.pipesCount += 1;
  9462. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  9463. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  9464. var endFn = doEnd ? onend : cleanup;
  9465. if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn);
  9466. dest.on('unpipe', onunpipe);
  9467. function onunpipe(readable) {
  9468. debug('onunpipe');
  9469. if (readable === src) {
  9470. cleanup();
  9471. }
  9472. }
  9473. function onend() {
  9474. debug('onend');
  9475. dest.end();
  9476. }
  9477. // when the dest drains, it reduces the awaitDrain counter
  9478. // on the source. This would be more elegant with a .once()
  9479. // handler in flow(), but adding and removing repeatedly is
  9480. // too slow.
  9481. var ondrain = pipeOnDrain(src);
  9482. dest.on('drain', ondrain);
  9483. var cleanedUp = false;
  9484. function cleanup() {
  9485. debug('cleanup');
  9486. // cleanup event handlers once the pipe is broken
  9487. dest.removeListener('close', onclose);
  9488. dest.removeListener('finish', onfinish);
  9489. dest.removeListener('drain', ondrain);
  9490. dest.removeListener('error', onerror);
  9491. dest.removeListener('unpipe', onunpipe);
  9492. src.removeListener('end', onend);
  9493. src.removeListener('end', cleanup);
  9494. src.removeListener('data', ondata);
  9495. cleanedUp = true;
  9496. // if the reader is waiting for a drain event from this
  9497. // specific writer, then it would cause it to never start
  9498. // flowing again.
  9499. // So, if this is awaiting a drain, then we just call it now.
  9500. // If we don't know, then assume that we are waiting for one.
  9501. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  9502. }
  9503. // If the user pushes more data while we're writing to dest then we'll end up
  9504. // in ondata again. However, we only want to increase awaitDrain once because
  9505. // dest will only emit one 'drain' event for the multiple writes.
  9506. // => Introduce a guard on increasing awaitDrain.
  9507. var increasedAwaitDrain = false;
  9508. src.on('data', ondata);
  9509. function ondata(chunk) {
  9510. debug('ondata');
  9511. increasedAwaitDrain = false;
  9512. var ret = dest.write(chunk);
  9513. if (false === ret && !increasedAwaitDrain) {
  9514. // If the user unpiped during `dest.write()`, it is possible
  9515. // to get stuck in a permanently paused state if that write
  9516. // also returned false.
  9517. // => Check whether `dest` is still a piping destination.
  9518. if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  9519. debug('false write response, pause', src._readableState.awaitDrain);
  9520. src._readableState.awaitDrain++;
  9521. increasedAwaitDrain = true;
  9522. }
  9523. src.pause();
  9524. }
  9525. }
  9526. // if the dest has an error, then stop piping into it.
  9527. // however, don't suppress the throwing behavior for this.
  9528. function onerror(er) {
  9529. debug('onerror', er);
  9530. unpipe();
  9531. dest.removeListener('error', onerror);
  9532. if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
  9533. }
  9534. // Make sure our error handler is attached before userland ones.
  9535. prependListener(dest, 'error', onerror);
  9536. // Both close and finish should trigger unpipe, but only once.
  9537. function onclose() {
  9538. dest.removeListener('finish', onfinish);
  9539. unpipe();
  9540. }
  9541. dest.once('close', onclose);
  9542. function onfinish() {
  9543. debug('onfinish');
  9544. dest.removeListener('close', onclose);
  9545. unpipe();
  9546. }
  9547. dest.once('finish', onfinish);
  9548. function unpipe() {
  9549. debug('unpipe');
  9550. src.unpipe(dest);
  9551. }
  9552. // tell the dest that it's being piped to
  9553. dest.emit('pipe', src);
  9554. // start the flow if it hasn't been started already.
  9555. if (!state.flowing) {
  9556. debug('pipe resume');
  9557. src.resume();
  9558. }
  9559. return dest;
  9560. };
  9561. function pipeOnDrain(src) {
  9562. return function () {
  9563. var state = src._readableState;
  9564. debug('pipeOnDrain', state.awaitDrain);
  9565. if (state.awaitDrain) state.awaitDrain--;
  9566. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  9567. state.flowing = true;
  9568. flow(src);
  9569. }
  9570. };
  9571. }
  9572. Readable.prototype.unpipe = function (dest) {
  9573. var state = this._readableState;
  9574. // if we're not piping anywhere, then do nothing.
  9575. if (state.pipesCount === 0) return this;
  9576. // just one destination. most common case.
  9577. if (state.pipesCount === 1) {
  9578. // passed in one, but it's not the right one.
  9579. if (dest && dest !== state.pipes) return this;
  9580. if (!dest) dest = state.pipes;
  9581. // got a match.
  9582. state.pipes = null;
  9583. state.pipesCount = 0;
  9584. state.flowing = false;
  9585. if (dest) dest.emit('unpipe', this);
  9586. return this;
  9587. }
  9588. // slow case. multiple pipe destinations.
  9589. if (!dest) {
  9590. // remove all.
  9591. var dests = state.pipes;
  9592. var len = state.pipesCount;
  9593. state.pipes = null;
  9594. state.pipesCount = 0;
  9595. state.flowing = false;
  9596. for (var _i = 0; _i < len; _i++) {
  9597. dests[_i].emit('unpipe', this);
  9598. }return this;
  9599. }
  9600. // try to find the right one.
  9601. var i = indexOf(state.pipes, dest);
  9602. if (i === -1) return this;
  9603. state.pipes.splice(i, 1);
  9604. state.pipesCount -= 1;
  9605. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  9606. dest.emit('unpipe', this);
  9607. return this;
  9608. };
  9609. // set up data events if they are asked for
  9610. // Ensure readable listeners eventually get something
  9611. Readable.prototype.on = function (ev, fn) {
  9612. var res = Stream.prototype.on.call(this, ev, fn);
  9613. if (ev === 'data') {
  9614. // Start flowing on next tick if stream isn't explicitly paused
  9615. if (this._readableState.flowing !== false) this.resume();
  9616. } else if (ev === 'readable') {
  9617. var state = this._readableState;
  9618. if (!state.endEmitted && !state.readableListening) {
  9619. state.readableListening = state.needReadable = true;
  9620. state.emittedReadable = false;
  9621. if (!state.reading) {
  9622. processNextTick(nReadingNextTick, this);
  9623. } else if (state.length) {
  9624. emitReadable(this, state);
  9625. }
  9626. }
  9627. }
  9628. return res;
  9629. };
  9630. Readable.prototype.addListener = Readable.prototype.on;
  9631. function nReadingNextTick(self) {
  9632. debug('readable nexttick read 0');
  9633. self.read(0);
  9634. }
  9635. // pause() and resume() are remnants of the legacy readable stream API
  9636. // If the user uses them, then switch into old mode.
  9637. Readable.prototype.resume = function () {
  9638. var state = this._readableState;
  9639. if (!state.flowing) {
  9640. debug('resume');
  9641. state.flowing = true;
  9642. resume(this, state);
  9643. }
  9644. return this;
  9645. };
  9646. function resume(stream, state) {
  9647. if (!state.resumeScheduled) {
  9648. state.resumeScheduled = true;
  9649. processNextTick(resume_, stream, state);
  9650. }
  9651. }
  9652. function resume_(stream, state) {
  9653. if (!state.reading) {
  9654. debug('resume read 0');
  9655. stream.read(0);
  9656. }
  9657. state.resumeScheduled = false;
  9658. state.awaitDrain = 0;
  9659. stream.emit('resume');
  9660. flow(stream);
  9661. if (state.flowing && !state.reading) stream.read(0);
  9662. }
  9663. Readable.prototype.pause = function () {
  9664. debug('call pause flowing=%j', this._readableState.flowing);
  9665. if (false !== this._readableState.flowing) {
  9666. debug('pause');
  9667. this._readableState.flowing = false;
  9668. this.emit('pause');
  9669. }
  9670. return this;
  9671. };
  9672. function flow(stream) {
  9673. var state = stream._readableState;
  9674. debug('flow', state.flowing);
  9675. while (state.flowing && stream.read() !== null) {}
  9676. }
  9677. // wrap an old-style stream as the async data source.
  9678. // This is *not* part of the readable stream interface.
  9679. // It is an ugly unfortunate mess of history.
  9680. Readable.prototype.wrap = function (stream) {
  9681. var state = this._readableState;
  9682. var paused = false;
  9683. var self = this;
  9684. stream.on('end', function () {
  9685. debug('wrapped end');
  9686. if (state.decoder && !state.ended) {
  9687. var chunk = state.decoder.end();
  9688. if (chunk && chunk.length) self.push(chunk);
  9689. }
  9690. self.push(null);
  9691. });
  9692. stream.on('data', function (chunk) {
  9693. debug('wrapped data');
  9694. if (state.decoder) chunk = state.decoder.write(chunk);
  9695. // don't skip over falsy values in objectMode
  9696. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  9697. var ret = self.push(chunk);
  9698. if (!ret) {
  9699. paused = true;
  9700. stream.pause();
  9701. }
  9702. });
  9703. // proxy all the other methods.
  9704. // important when wrapping filters and duplexes.
  9705. for (var i in stream) {
  9706. if (this[i] === undefined && typeof stream[i] === 'function') {
  9707. this[i] = function (method) {
  9708. return function () {
  9709. return stream[method].apply(stream, arguments);
  9710. };
  9711. }(i);
  9712. }
  9713. }
  9714. // proxy certain important events.
  9715. var events = ['error', 'close', 'destroy', 'pause', 'resume'];
  9716. forEach(events, function (ev) {
  9717. stream.on(ev, self.emit.bind(self, ev));
  9718. });
  9719. // when we try to consume some more bytes, simply unpause the
  9720. // underlying stream.
  9721. self._read = function (n) {
  9722. debug('wrapped _read', n);
  9723. if (paused) {
  9724. paused = false;
  9725. stream.resume();
  9726. }
  9727. };
  9728. return self;
  9729. };
  9730. // exposed for testing purposes only.
  9731. Readable._fromList = fromList;
  9732. // Pluck off n bytes from an array of buffers.
  9733. // Length is the combined lengths of all the buffers in the list.
  9734. // This function is designed to be inlinable, so please take care when making
  9735. // changes to the function body.
  9736. function fromList(n, state) {
  9737. // nothing buffered
  9738. if (state.length === 0) return null;
  9739. var ret;
  9740. if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
  9741. // read it all, truncate the list
  9742. if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length);
  9743. state.buffer.clear();
  9744. } else {
  9745. // read part of list
  9746. ret = fromListPartial(n, state.buffer, state.decoder);
  9747. }
  9748. return ret;
  9749. }
  9750. // Extracts only enough buffered data to satisfy the amount requested.
  9751. // This function is designed to be inlinable, so please take care when making
  9752. // changes to the function body.
  9753. function fromListPartial(n, list, hasStrings) {
  9754. var ret;
  9755. if (n < list.head.data.length) {
  9756. // slice is the same for buffers and strings
  9757. ret = list.head.data.slice(0, n);
  9758. list.head.data = list.head.data.slice(n);
  9759. } else if (n === list.head.data.length) {
  9760. // first chunk is a perfect match
  9761. ret = list.shift();
  9762. } else {
  9763. // result spans more than one buffer
  9764. ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
  9765. }
  9766. return ret;
  9767. }
  9768. // Copies a specified amount of characters from the list of buffered data
  9769. // chunks.
  9770. // This function is designed to be inlinable, so please take care when making
  9771. // changes to the function body.
  9772. function copyFromBufferString(n, list) {
  9773. var p = list.head;
  9774. var c = 1;
  9775. var ret = p.data;
  9776. n -= ret.length;
  9777. while (p = p.next) {
  9778. var str = p.data;
  9779. var nb = n > str.length ? str.length : n;
  9780. if (nb === str.length) ret += str;else ret += str.slice(0, n);
  9781. n -= nb;
  9782. if (n === 0) {
  9783. if (nb === str.length) {
  9784. ++c;
  9785. if (p.next) list.head = p.next;else list.head = list.tail = null;
  9786. } else {
  9787. list.head = p;
  9788. p.data = str.slice(nb);
  9789. }
  9790. break;
  9791. }
  9792. ++c;
  9793. }
  9794. list.length -= c;
  9795. return ret;
  9796. }
  9797. // Copies a specified amount of bytes from the list of buffered data chunks.
  9798. // This function is designed to be inlinable, so please take care when making
  9799. // changes to the function body.
  9800. function copyFromBuffer(n, list) {
  9801. var ret = bufferShim.allocUnsafe(n);
  9802. var p = list.head;
  9803. var c = 1;
  9804. p.data.copy(ret);
  9805. n -= p.data.length;
  9806. while (p = p.next) {
  9807. var buf = p.data;
  9808. var nb = n > buf.length ? buf.length : n;
  9809. buf.copy(ret, ret.length - n, 0, nb);
  9810. n -= nb;
  9811. if (n === 0) {
  9812. if (nb === buf.length) {
  9813. ++c;
  9814. if (p.next) list.head = p.next;else list.head = list.tail = null;
  9815. } else {
  9816. list.head = p;
  9817. p.data = buf.slice(nb);
  9818. }
  9819. break;
  9820. }
  9821. ++c;
  9822. }
  9823. list.length -= c;
  9824. return ret;
  9825. }
  9826. function endReadable(stream) {
  9827. var state = stream._readableState;
  9828. // If we get here before consuming all the bytes, then that is a
  9829. // bug in node. Should never happen.
  9830. if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
  9831. if (!state.endEmitted) {
  9832. state.ended = true;
  9833. processNextTick(endReadableNT, state, stream);
  9834. }
  9835. }
  9836. function endReadableNT(state, stream) {
  9837. // Check that we didn't get one last unshift.
  9838. if (!state.endEmitted && state.length === 0) {
  9839. state.endEmitted = true;
  9840. stream.readable = false;
  9841. stream.emit('end');
  9842. }
  9843. }
  9844. function forEach(xs, f) {
  9845. for (var i = 0, l = xs.length; i < l; i++) {
  9846. f(xs[i], i);
  9847. }
  9848. }
  9849. function indexOf(xs, x) {
  9850. for (var i = 0, l = xs.length; i < l; i++) {
  9851. if (xs[i] === x) return i;
  9852. }
  9853. return -1;
  9854. }
  9855. }).call(this,require('_process'))
  9856. },{"./_stream_duplex":24,"./internal/streams/BufferList":29,"_process":22,"buffer":7,"buffer-shims":6,"core-util-is":9,"events":14,"inherits":16,"isarray":18,"process-nextick-args":21,"string_decoder/":44,"util":5}],27:[function(require,module,exports){
  9857. // a transform stream is a readable/writable stream where you do
  9858. // something with the data. Sometimes it's called a "filter",
  9859. // but that's not a great name for it, since that implies a thing where
  9860. // some bits pass through, and others are simply ignored. (That would
  9861. // be a valid example of a transform, of course.)
  9862. //
  9863. // While the output is causally related to the input, it's not a
  9864. // necessarily symmetric or synchronous transformation. For example,
  9865. // a zlib stream might take multiple plain-text writes(), and then
  9866. // emit a single compressed chunk some time in the future.
  9867. //
  9868. // Here's how this works:
  9869. //
  9870. // The Transform stream has all the aspects of the readable and writable
  9871. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  9872. // internally, and returns false if there's a lot of pending writes
  9873. // buffered up. When you call read(), that calls _read(n) until
  9874. // there's enough pending readable data buffered up.
  9875. //
  9876. // In a transform stream, the written data is placed in a buffer. When
  9877. // _read(n) is called, it transforms the queued up data, calling the
  9878. // buffered _write cb's as it consumes chunks. If consuming a single
  9879. // written chunk would result in multiple output chunks, then the first
  9880. // outputted bit calls the readcb, and subsequent chunks just go into
  9881. // the read buffer, and will cause it to emit 'readable' if necessary.
  9882. //
  9883. // This way, back-pressure is actually determined by the reading side,
  9884. // since _read has to be called to start processing a new chunk. However,
  9885. // a pathological inflate type of transform can cause excessive buffering
  9886. // here. For example, imagine a stream where every byte of input is
  9887. // interpreted as an integer from 0-255, and then results in that many
  9888. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  9889. // 1kb of data being output. In this case, you could write a very small
  9890. // amount of input, and end up with a very large amount of output. In
  9891. // such a pathological inflating mechanism, there'd be no way to tell
  9892. // the system to stop doing the transform. A single 4MB write could
  9893. // cause the system to run out of memory.
  9894. //
  9895. // However, even in such a pathological case, only a single written chunk
  9896. // would be consumed, and then the rest would wait (un-transformed) until
  9897. // the results of the previous transformed chunk were consumed.
  9898. 'use strict';
  9899. module.exports = Transform;
  9900. var Duplex = require('./_stream_duplex');
  9901. /*<replacement>*/
  9902. var util = require('core-util-is');
  9903. util.inherits = require('inherits');
  9904. /*</replacement>*/
  9905. util.inherits(Transform, Duplex);
  9906. function TransformState(stream) {
  9907. this.afterTransform = function (er, data) {
  9908. return afterTransform(stream, er, data);
  9909. };
  9910. this.needTransform = false;
  9911. this.transforming = false;
  9912. this.writecb = null;
  9913. this.writechunk = null;
  9914. this.writeencoding = null;
  9915. }
  9916. function afterTransform(stream, er, data) {
  9917. var ts = stream._transformState;
  9918. ts.transforming = false;
  9919. var cb = ts.writecb;
  9920. if (!cb) return stream.emit('error', new Error('no writecb in Transform class'));
  9921. ts.writechunk = null;
  9922. ts.writecb = null;
  9923. if (data !== null && data !== undefined) stream.push(data);
  9924. cb(er);
  9925. var rs = stream._readableState;
  9926. rs.reading = false;
  9927. if (rs.needReadable || rs.length < rs.highWaterMark) {
  9928. stream._read(rs.highWaterMark);
  9929. }
  9930. }
  9931. function Transform(options) {
  9932. if (!(this instanceof Transform)) return new Transform(options);
  9933. Duplex.call(this, options);
  9934. this._transformState = new TransformState(this);
  9935. // when the writable side finishes, then flush out anything remaining.
  9936. var stream = this;
  9937. // start out asking for a readable event once data is transformed.
  9938. this._readableState.needReadable = true;
  9939. // we have implemented the _read method, and done the other things
  9940. // that Readable wants before the first _read call, so unset the
  9941. // sync guard flag.
  9942. this._readableState.sync = false;
  9943. if (options) {
  9944. if (typeof options.transform === 'function') this._transform = options.transform;
  9945. if (typeof options.flush === 'function') this._flush = options.flush;
  9946. }
  9947. this.once('prefinish', function () {
  9948. if (typeof this._flush === 'function') this._flush(function (er) {
  9949. done(stream, er);
  9950. });else done(stream);
  9951. });
  9952. }
  9953. Transform.prototype.push = function (chunk, encoding) {
  9954. this._transformState.needTransform = false;
  9955. return Duplex.prototype.push.call(this, chunk, encoding);
  9956. };
  9957. // This is the part where you do stuff!
  9958. // override this function in implementation classes.
  9959. // 'chunk' is an input chunk.
  9960. //
  9961. // Call `push(newChunk)` to pass along transformed output
  9962. // to the readable side. You may call 'push' zero or more times.
  9963. //
  9964. // Call `cb(err)` when you are done with this chunk. If you pass
  9965. // an error, then that'll put the hurt on the whole operation. If you
  9966. // never call cb(), then you'll never get another chunk.
  9967. Transform.prototype._transform = function (chunk, encoding, cb) {
  9968. throw new Error('Not implemented');
  9969. };
  9970. Transform.prototype._write = function (chunk, encoding, cb) {
  9971. var ts = this._transformState;
  9972. ts.writecb = cb;
  9973. ts.writechunk = chunk;
  9974. ts.writeencoding = encoding;
  9975. if (!ts.transforming) {
  9976. var rs = this._readableState;
  9977. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  9978. }
  9979. };
  9980. // Doesn't matter what the args are here.
  9981. // _transform does all the work.
  9982. // That we got here means that the readable side wants more data.
  9983. Transform.prototype._read = function (n) {
  9984. var ts = this._transformState;
  9985. if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
  9986. ts.transforming = true;
  9987. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  9988. } else {
  9989. // mark that we need a transform, so that any data that comes in
  9990. // will get processed, now that we've asked for it.
  9991. ts.needTransform = true;
  9992. }
  9993. };
  9994. function done(stream, er) {
  9995. if (er) return stream.emit('error', er);
  9996. // if there's nothing in the write buffer, then that means
  9997. // that nothing more will ever be provided
  9998. var ws = stream._writableState;
  9999. var ts = stream._transformState;
  10000. if (ws.length) throw new Error('Calling transform done when ws.length != 0');
  10001. if (ts.transforming) throw new Error('Calling transform done when still transforming');
  10002. return stream.push(null);
  10003. }
  10004. },{"./_stream_duplex":24,"core-util-is":9,"inherits":16}],28:[function(require,module,exports){
  10005. (function (process){
  10006. // A bit simpler than readable streams.
  10007. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  10008. // the drain event emission and buffering.
  10009. 'use strict';
  10010. module.exports = Writable;
  10011. /*<replacement>*/
  10012. var processNextTick = require('process-nextick-args');
  10013. /*</replacement>*/
  10014. /*<replacement>*/
  10015. var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick;
  10016. /*</replacement>*/
  10017. Writable.WritableState = WritableState;
  10018. /*<replacement>*/
  10019. var util = require('core-util-is');
  10020. util.inherits = require('inherits');
  10021. /*</replacement>*/
  10022. /*<replacement>*/
  10023. var internalUtil = {
  10024. deprecate: require('util-deprecate')
  10025. };
  10026. /*</replacement>*/
  10027. /*<replacement>*/
  10028. var Stream;
  10029. (function () {
  10030. try {
  10031. Stream = require('st' + 'ream');
  10032. } catch (_) {} finally {
  10033. if (!Stream) Stream = require('events').EventEmitter;
  10034. }
  10035. })();
  10036. /*</replacement>*/
  10037. var Buffer = require('buffer').Buffer;
  10038. /*<replacement>*/
  10039. var bufferShim = require('buffer-shims');
  10040. /*</replacement>*/
  10041. util.inherits(Writable, Stream);
  10042. function nop() {}
  10043. function WriteReq(chunk, encoding, cb) {
  10044. this.chunk = chunk;
  10045. this.encoding = encoding;
  10046. this.callback = cb;
  10047. this.next = null;
  10048. }
  10049. var Duplex;
  10050. function WritableState(options, stream) {
  10051. Duplex = Duplex || require('./_stream_duplex');
  10052. options = options || {};
  10053. // object stream flag to indicate whether or not this stream
  10054. // contains buffers or objects.
  10055. this.objectMode = !!options.objectMode;
  10056. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
  10057. // the point at which write() starts returning false
  10058. // Note: 0 is a valid value, means that we always return false if
  10059. // the entire buffer is not flushed immediately on write()
  10060. var hwm = options.highWaterMark;
  10061. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  10062. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  10063. // cast to ints.
  10064. this.highWaterMark = ~ ~this.highWaterMark;
  10065. this.needDrain = false;
  10066. // at the start of calling end()
  10067. this.ending = false;
  10068. // when end() has been called, and returned
  10069. this.ended = false;
  10070. // when 'finish' is emitted
  10071. this.finished = false;
  10072. // should we decode strings into buffers before passing to _write?
  10073. // this is here so that some node-core streams can optimize string
  10074. // handling at a lower level.
  10075. var noDecode = options.decodeStrings === false;
  10076. this.decodeStrings = !noDecode;
  10077. // Crypto is kind of old and crusty. Historically, its default string
  10078. // encoding is 'binary' so we have to make this configurable.
  10079. // Everything else in the universe uses 'utf8', though.
  10080. this.defaultEncoding = options.defaultEncoding || 'utf8';
  10081. // not an actual buffer we keep track of, but a measurement
  10082. // of how much we're waiting to get pushed to some underlying
  10083. // socket or file.
  10084. this.length = 0;
  10085. // a flag to see when we're in the middle of a write.
  10086. this.writing = false;
  10087. // when true all writes will be buffered until .uncork() call
  10088. this.corked = 0;
  10089. // a flag to be able to tell if the onwrite cb is called immediately,
  10090. // or on a later tick. We set this to true at first, because any
  10091. // actions that shouldn't happen until "later" should generally also
  10092. // not happen before the first write call.
  10093. this.sync = true;
  10094. // a flag to know if we're processing previously buffered items, which
  10095. // may call the _write() callback in the same tick, so that we don't
  10096. // end up in an overlapped onwrite situation.
  10097. this.bufferProcessing = false;
  10098. // the callback that's passed to _write(chunk,cb)
  10099. this.onwrite = function (er) {
  10100. onwrite(stream, er);
  10101. };
  10102. // the callback that the user supplies to write(chunk,encoding,cb)
  10103. this.writecb = null;
  10104. // the amount that is being written when _write is called.
  10105. this.writelen = 0;
  10106. this.bufferedRequest = null;
  10107. this.lastBufferedRequest = null;
  10108. // number of pending user-supplied write callbacks
  10109. // this must be 0 before 'finish' can be emitted
  10110. this.pendingcb = 0;
  10111. // emit prefinish if the only thing we're waiting for is _write cbs
  10112. // This is relevant for synchronous Transform streams
  10113. this.prefinished = false;
  10114. // True if the error was already emitted and should not be thrown again
  10115. this.errorEmitted = false;
  10116. // count buffered requests
  10117. this.bufferedRequestCount = 0;
  10118. // allocate the first CorkedRequest, there is always
  10119. // one allocated and free to use, and we maintain at most two
  10120. this.corkedRequestsFree = new CorkedRequest(this);
  10121. }
  10122. WritableState.prototype.getBuffer = function writableStateGetBuffer() {
  10123. var current = this.bufferedRequest;
  10124. var out = [];
  10125. while (current) {
  10126. out.push(current);
  10127. current = current.next;
  10128. }
  10129. return out;
  10130. };
  10131. (function () {
  10132. try {
  10133. Object.defineProperty(WritableState.prototype, 'buffer', {
  10134. get: internalUtil.deprecate(function () {
  10135. return this.getBuffer();
  10136. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
  10137. });
  10138. } catch (_) {}
  10139. })();
  10140. var Duplex;
  10141. function Writable(options) {
  10142. Duplex = Duplex || require('./_stream_duplex');
  10143. // Writable ctor is applied to Duplexes, though they're not
  10144. // instanceof Writable, they're instanceof Readable.
  10145. if (!(this instanceof Writable) && !(this instanceof Duplex)) return new Writable(options);
  10146. this._writableState = new WritableState(options, this);
  10147. // legacy.
  10148. this.writable = true;
  10149. if (options) {
  10150. if (typeof options.write === 'function') this._write = options.write;
  10151. if (typeof options.writev === 'function') this._writev = options.writev;
  10152. }
  10153. Stream.call(this);
  10154. }
  10155. // Otherwise people can pipe Writable streams, which is just wrong.
  10156. Writable.prototype.pipe = function () {
  10157. this.emit('error', new Error('Cannot pipe, not readable'));
  10158. };
  10159. function writeAfterEnd(stream, cb) {
  10160. var er = new Error('write after end');
  10161. // TODO: defer error events consistently everywhere, not just the cb
  10162. stream.emit('error', er);
  10163. processNextTick(cb, er);
  10164. }
  10165. // If we get something that is not a buffer, string, null, or undefined,
  10166. // and we're not in objectMode, then that's an error.
  10167. // Otherwise stream chunks are all considered to be of length=1, and the
  10168. // watermarks determine how many objects to keep in the buffer, rather than
  10169. // how many bytes or characters.
  10170. function validChunk(stream, state, chunk, cb) {
  10171. var valid = true;
  10172. var er = false;
  10173. // Always throw error if a null is written
  10174. // if we are not in object mode then throw
  10175. // if it is not a buffer, string, or undefined.
  10176. if (chunk === null) {
  10177. er = new TypeError('May not write null values to stream');
  10178. } else if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  10179. er = new TypeError('Invalid non-string/buffer chunk');
  10180. }
  10181. if (er) {
  10182. stream.emit('error', er);
  10183. processNextTick(cb, er);
  10184. valid = false;
  10185. }
  10186. return valid;
  10187. }
  10188. Writable.prototype.write = function (chunk, encoding, cb) {
  10189. var state = this._writableState;
  10190. var ret = false;
  10191. if (typeof encoding === 'function') {
  10192. cb = encoding;
  10193. encoding = null;
  10194. }
  10195. if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  10196. if (typeof cb !== 'function') cb = nop;
  10197. if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) {
  10198. state.pendingcb++;
  10199. ret = writeOrBuffer(this, state, chunk, encoding, cb);
  10200. }
  10201. return ret;
  10202. };
  10203. Writable.prototype.cork = function () {
  10204. var state = this._writableState;
  10205. state.corked++;
  10206. };
  10207. Writable.prototype.uncork = function () {
  10208. var state = this._writableState;
  10209. if (state.corked) {
  10210. state.corked--;
  10211. if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  10212. }
  10213. };
  10214. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  10215. // node::ParseEncoding() requires lower case.
  10216. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  10217. if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
  10218. this._writableState.defaultEncoding = encoding;
  10219. return this;
  10220. };
  10221. function decodeChunk(state, chunk, encoding) {
  10222. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  10223. chunk = bufferShim.from(chunk, encoding);
  10224. }
  10225. return chunk;
  10226. }
  10227. // if we're already writing something, then just put this
  10228. // in the queue, and wait our turn. Otherwise, call _write
  10229. // If we return false, then we need a drain event, so set that flag.
  10230. function writeOrBuffer(stream, state, chunk, encoding, cb) {
  10231. chunk = decodeChunk(state, chunk, encoding);
  10232. if (Buffer.isBuffer(chunk)) encoding = 'buffer';
  10233. var len = state.objectMode ? 1 : chunk.length;
  10234. state.length += len;
  10235. var ret = state.length < state.highWaterMark;
  10236. // we must ensure that previous needDrain will not be reset to false.
  10237. if (!ret) state.needDrain = true;
  10238. if (state.writing || state.corked) {
  10239. var last = state.lastBufferedRequest;
  10240. state.lastBufferedRequest = new WriteReq(chunk, encoding, cb);
  10241. if (last) {
  10242. last.next = state.lastBufferedRequest;
  10243. } else {
  10244. state.bufferedRequest = state.lastBufferedRequest;
  10245. }
  10246. state.bufferedRequestCount += 1;
  10247. } else {
  10248. doWrite(stream, state, false, len, chunk, encoding, cb);
  10249. }
  10250. return ret;
  10251. }
  10252. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  10253. state.writelen = len;
  10254. state.writecb = cb;
  10255. state.writing = true;
  10256. state.sync = true;
  10257. if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  10258. state.sync = false;
  10259. }
  10260. function onwriteError(stream, state, sync, er, cb) {
  10261. --state.pendingcb;
  10262. if (sync) processNextTick(cb, er);else cb(er);
  10263. stream._writableState.errorEmitted = true;
  10264. stream.emit('error', er);
  10265. }
  10266. function onwriteStateUpdate(state) {
  10267. state.writing = false;
  10268. state.writecb = null;
  10269. state.length -= state.writelen;
  10270. state.writelen = 0;
  10271. }
  10272. function onwrite(stream, er) {
  10273. var state = stream._writableState;
  10274. var sync = state.sync;
  10275. var cb = state.writecb;
  10276. onwriteStateUpdate(state);
  10277. if (er) onwriteError(stream, state, sync, er, cb);else {
  10278. // Check if we're actually ready to finish, but don't emit yet
  10279. var finished = needFinish(state);
  10280. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  10281. clearBuffer(stream, state);
  10282. }
  10283. if (sync) {
  10284. /*<replacement>*/
  10285. asyncWrite(afterWrite, stream, state, finished, cb);
  10286. /*</replacement>*/
  10287. } else {
  10288. afterWrite(stream, state, finished, cb);
  10289. }
  10290. }
  10291. }
  10292. function afterWrite(stream, state, finished, cb) {
  10293. if (!finished) onwriteDrain(stream, state);
  10294. state.pendingcb--;
  10295. cb();
  10296. finishMaybe(stream, state);
  10297. }
  10298. // Must force callback to be called on nextTick, so that we don't
  10299. // emit 'drain' before the write() consumer gets the 'false' return
  10300. // value, and has a chance to attach a 'drain' listener.
  10301. function onwriteDrain(stream, state) {
  10302. if (state.length === 0 && state.needDrain) {
  10303. state.needDrain = false;
  10304. stream.emit('drain');
  10305. }
  10306. }
  10307. // if there's something in the buffer waiting, then process it
  10308. function clearBuffer(stream, state) {
  10309. state.bufferProcessing = true;
  10310. var entry = state.bufferedRequest;
  10311. if (stream._writev && entry && entry.next) {
  10312. // Fast case, write everything using _writev()
  10313. var l = state.bufferedRequestCount;
  10314. var buffer = new Array(l);
  10315. var holder = state.corkedRequestsFree;
  10316. holder.entry = entry;
  10317. var count = 0;
  10318. while (entry) {
  10319. buffer[count] = entry;
  10320. entry = entry.next;
  10321. count += 1;
  10322. }
  10323. doWrite(stream, state, true, state.length, buffer, '', holder.finish);
  10324. // doWrite is almost always async, defer these to save a bit of time
  10325. // as the hot path ends with doWrite
  10326. state.pendingcb++;
  10327. state.lastBufferedRequest = null;
  10328. if (holder.next) {
  10329. state.corkedRequestsFree = holder.next;
  10330. holder.next = null;
  10331. } else {
  10332. state.corkedRequestsFree = new CorkedRequest(state);
  10333. }
  10334. } else {
  10335. // Slow case, write chunks one-by-one
  10336. while (entry) {
  10337. var chunk = entry.chunk;
  10338. var encoding = entry.encoding;
  10339. var cb = entry.callback;
  10340. var len = state.objectMode ? 1 : chunk.length;
  10341. doWrite(stream, state, false, len, chunk, encoding, cb);
  10342. entry = entry.next;
  10343. // if we didn't call the onwrite immediately, then
  10344. // it means that we need to wait until it does.
  10345. // also, that means that the chunk and cb are currently
  10346. // being processed, so move the buffer counter past them.
  10347. if (state.writing) {
  10348. break;
  10349. }
  10350. }
  10351. if (entry === null) state.lastBufferedRequest = null;
  10352. }
  10353. state.bufferedRequestCount = 0;
  10354. state.bufferedRequest = entry;
  10355. state.bufferProcessing = false;
  10356. }
  10357. Writable.prototype._write = function (chunk, encoding, cb) {
  10358. cb(new Error('not implemented'));
  10359. };
  10360. Writable.prototype._writev = null;
  10361. Writable.prototype.end = function (chunk, encoding, cb) {
  10362. var state = this._writableState;
  10363. if (typeof chunk === 'function') {
  10364. cb = chunk;
  10365. chunk = null;
  10366. encoding = null;
  10367. } else if (typeof encoding === 'function') {
  10368. cb = encoding;
  10369. encoding = null;
  10370. }
  10371. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
  10372. // .end() fully uncorks
  10373. if (state.corked) {
  10374. state.corked = 1;
  10375. this.uncork();
  10376. }
  10377. // ignore unnecessary end() calls.
  10378. if (!state.ending && !state.finished) endWritable(this, state, cb);
  10379. };
  10380. function needFinish(state) {
  10381. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  10382. }
  10383. function prefinish(stream, state) {
  10384. if (!state.prefinished) {
  10385. state.prefinished = true;
  10386. stream.emit('prefinish');
  10387. }
  10388. }
  10389. function finishMaybe(stream, state) {
  10390. var need = needFinish(state);
  10391. if (need) {
  10392. if (state.pendingcb === 0) {
  10393. prefinish(stream, state);
  10394. state.finished = true;
  10395. stream.emit('finish');
  10396. } else {
  10397. prefinish(stream, state);
  10398. }
  10399. }
  10400. return need;
  10401. }
  10402. function endWritable(stream, state, cb) {
  10403. state.ending = true;
  10404. finishMaybe(stream, state);
  10405. if (cb) {
  10406. if (state.finished) processNextTick(cb);else stream.once('finish', cb);
  10407. }
  10408. state.ended = true;
  10409. stream.writable = false;
  10410. }
  10411. // It seems a linked list but it is not
  10412. // there will be only 2 of these for each stream
  10413. function CorkedRequest(state) {
  10414. var _this = this;
  10415. this.next = null;
  10416. this.entry = null;
  10417. this.finish = function (err) {
  10418. var entry = _this.entry;
  10419. _this.entry = null;
  10420. while (entry) {
  10421. var cb = entry.callback;
  10422. state.pendingcb--;
  10423. cb(err);
  10424. entry = entry.next;
  10425. }
  10426. if (state.corkedRequestsFree) {
  10427. state.corkedRequestsFree.next = _this;
  10428. } else {
  10429. state.corkedRequestsFree = _this;
  10430. }
  10431. };
  10432. }
  10433. }).call(this,require('_process'))
  10434. },{"./_stream_duplex":24,"_process":22,"buffer":7,"buffer-shims":6,"core-util-is":9,"events":14,"inherits":16,"process-nextick-args":21,"util-deprecate":45}],29:[function(require,module,exports){
  10435. 'use strict';
  10436. var Buffer = require('buffer').Buffer;
  10437. /*<replacement>*/
  10438. var bufferShim = require('buffer-shims');
  10439. /*</replacement>*/
  10440. module.exports = BufferList;
  10441. function BufferList() {
  10442. this.head = null;
  10443. this.tail = null;
  10444. this.length = 0;
  10445. }
  10446. BufferList.prototype.push = function (v) {
  10447. var entry = { data: v, next: null };
  10448. if (this.length > 0) this.tail.next = entry;else this.head = entry;
  10449. this.tail = entry;
  10450. ++this.length;
  10451. };
  10452. BufferList.prototype.unshift = function (v) {
  10453. var entry = { data: v, next: this.head };
  10454. if (this.length === 0) this.tail = entry;
  10455. this.head = entry;
  10456. ++this.length;
  10457. };
  10458. BufferList.prototype.shift = function () {
  10459. if (this.length === 0) return;
  10460. var ret = this.head.data;
  10461. if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
  10462. --this.length;
  10463. return ret;
  10464. };
  10465. BufferList.prototype.clear = function () {
  10466. this.head = this.tail = null;
  10467. this.length = 0;
  10468. };
  10469. BufferList.prototype.join = function (s) {
  10470. if (this.length === 0) return '';
  10471. var p = this.head;
  10472. var ret = '' + p.data;
  10473. while (p = p.next) {
  10474. ret += s + p.data;
  10475. }return ret;
  10476. };
  10477. BufferList.prototype.concat = function (n) {
  10478. if (this.length === 0) return bufferShim.alloc(0);
  10479. if (this.length === 1) return this.head.data;
  10480. var ret = bufferShim.allocUnsafe(n >>> 0);
  10481. var p = this.head;
  10482. var i = 0;
  10483. while (p) {
  10484. p.data.copy(ret, i);
  10485. i += p.data.length;
  10486. p = p.next;
  10487. }
  10488. return ret;
  10489. };
  10490. },{"buffer":7,"buffer-shims":6}],30:[function(require,module,exports){
  10491. module.exports = require("./lib/_stream_passthrough.js")
  10492. },{"./lib/_stream_passthrough.js":25}],31:[function(require,module,exports){
  10493. (function (process){
  10494. var Stream = (function (){
  10495. try {
  10496. return require('st' + 'ream'); // hack to fix a circular dependency issue when used with browserify
  10497. } catch(_){}
  10498. }());
  10499. exports = module.exports = require('./lib/_stream_readable.js');
  10500. exports.Stream = Stream || exports;
  10501. exports.Readable = exports;
  10502. exports.Writable = require('./lib/_stream_writable.js');
  10503. exports.Duplex = require('./lib/_stream_duplex.js');
  10504. exports.Transform = require('./lib/_stream_transform.js');
  10505. exports.PassThrough = require('./lib/_stream_passthrough.js');
  10506. if (!process.browser && process.env.READABLE_STREAM === 'disable' && Stream) {
  10507. module.exports = Stream;
  10508. }
  10509. }).call(this,require('_process'))
  10510. },{"./lib/_stream_duplex.js":24,"./lib/_stream_passthrough.js":25,"./lib/_stream_readable.js":26,"./lib/_stream_transform.js":27,"./lib/_stream_writable.js":28,"_process":22}],32:[function(require,module,exports){
  10511. module.exports = require("./lib/_stream_transform.js")
  10512. },{"./lib/_stream_transform.js":27}],33:[function(require,module,exports){
  10513. module.exports = require("./lib/_stream_writable.js")
  10514. },{"./lib/_stream_writable.js":28}],34:[function(require,module,exports){
  10515. (function (Buffer){
  10516. /*
  10517. CryptoJS v3.1.2
  10518. code.google.com/p/crypto-js
  10519. (c) 2009-2013 by Jeff Mott. All rights reserved.
  10520. code.google.com/p/crypto-js/wiki/License
  10521. */
  10522. /** @preserve
  10523. (c) 2012 by Cédric Mesnil. All rights reserved.
  10524. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  10525. - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  10526. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  10527. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  10528. */
  10529. // constants table
  10530. var zl = [
  10531. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  10532. 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
  10533. 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
  10534. 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
  10535. 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
  10536. ]
  10537. var zr = [
  10538. 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
  10539. 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
  10540. 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
  10541. 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
  10542. 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
  10543. ]
  10544. var sl = [
  10545. 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
  10546. 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
  10547. 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
  10548. 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
  10549. 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
  10550. ]
  10551. var sr = [
  10552. 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
  10553. 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
  10554. 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
  10555. 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
  10556. 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
  10557. ]
  10558. var hl = [0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]
  10559. var hr = [0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]
  10560. function bytesToWords (bytes) {
  10561. var words = []
  10562. for (var i = 0, b = 0; i < bytes.length; i++, b += 8) {
  10563. words[b >>> 5] |= bytes[i] << (24 - b % 32)
  10564. }
  10565. return words
  10566. }
  10567. function wordsToBytes (words) {
  10568. var bytes = []
  10569. for (var b = 0; b < words.length * 32; b += 8) {
  10570. bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF)
  10571. }
  10572. return bytes
  10573. }
  10574. function processBlock (H, M, offset) {
  10575. // swap endian
  10576. for (var i = 0; i < 16; i++) {
  10577. var offset_i = offset + i
  10578. var M_offset_i = M[offset_i]
  10579. // Swap
  10580. M[offset_i] = (
  10581. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  10582. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  10583. )
  10584. }
  10585. // Working variables
  10586. var al, bl, cl, dl, el
  10587. var ar, br, cr, dr, er
  10588. ar = al = H[0]
  10589. br = bl = H[1]
  10590. cr = cl = H[2]
  10591. dr = dl = H[3]
  10592. er = el = H[4]
  10593. // computation
  10594. var t
  10595. for (i = 0; i < 80; i += 1) {
  10596. t = (al + M[offset + zl[i]]) | 0
  10597. if (i < 16) {
  10598. t += f1(bl, cl, dl) + hl[0]
  10599. } else if (i < 32) {
  10600. t += f2(bl, cl, dl) + hl[1]
  10601. } else if (i < 48) {
  10602. t += f3(bl, cl, dl) + hl[2]
  10603. } else if (i < 64) {
  10604. t += f4(bl, cl, dl) + hl[3]
  10605. } else {// if (i<80) {
  10606. t += f5(bl, cl, dl) + hl[4]
  10607. }
  10608. t = t | 0
  10609. t = rotl(t, sl[i])
  10610. t = (t + el) | 0
  10611. al = el
  10612. el = dl
  10613. dl = rotl(cl, 10)
  10614. cl = bl
  10615. bl = t
  10616. t = (ar + M[offset + zr[i]]) | 0
  10617. if (i < 16) {
  10618. t += f5(br, cr, dr) + hr[0]
  10619. } else if (i < 32) {
  10620. t += f4(br, cr, dr) + hr[1]
  10621. } else if (i < 48) {
  10622. t += f3(br, cr, dr) + hr[2]
  10623. } else if (i < 64) {
  10624. t += f2(br, cr, dr) + hr[3]
  10625. } else {// if (i<80) {
  10626. t += f1(br, cr, dr) + hr[4]
  10627. }
  10628. t = t | 0
  10629. t = rotl(t, sr[i])
  10630. t = (t + er) | 0
  10631. ar = er
  10632. er = dr
  10633. dr = rotl(cr, 10)
  10634. cr = br
  10635. br = t
  10636. }
  10637. // intermediate hash value
  10638. t = (H[1] + cl + dr) | 0
  10639. H[1] = (H[2] + dl + er) | 0
  10640. H[2] = (H[3] + el + ar) | 0
  10641. H[3] = (H[4] + al + br) | 0
  10642. H[4] = (H[0] + bl + cr) | 0
  10643. H[0] = t
  10644. }
  10645. function f1 (x, y, z) {
  10646. return ((x) ^ (y) ^ (z))
  10647. }
  10648. function f2 (x, y, z) {
  10649. return (((x) & (y)) | ((~x) & (z)))
  10650. }
  10651. function f3 (x, y, z) {
  10652. return (((x) | (~(y))) ^ (z))
  10653. }
  10654. function f4 (x, y, z) {
  10655. return (((x) & (z)) | ((y) & (~(z))))
  10656. }
  10657. function f5 (x, y, z) {
  10658. return ((x) ^ ((y) | (~(z))))
  10659. }
  10660. function rotl (x, n) {
  10661. return (x << n) | (x >>> (32 - n))
  10662. }
  10663. function ripemd160 (message) {
  10664. var H = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]
  10665. if (typeof message === 'string') {
  10666. message = new Buffer(message, 'utf8')
  10667. }
  10668. var m = bytesToWords(message)
  10669. var nBitsLeft = message.length * 8
  10670. var nBitsTotal = message.length * 8
  10671. // Add padding
  10672. m[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32)
  10673. m[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  10674. (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
  10675. (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00)
  10676. )
  10677. for (var i = 0; i < m.length; i += 16) {
  10678. processBlock(H, m, i)
  10679. }
  10680. // swap endian
  10681. for (i = 0; i < 5; i++) {
  10682. // shortcut
  10683. var H_i = H[i]
  10684. // Swap
  10685. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  10686. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00)
  10687. }
  10688. var digestbytes = wordsToBytes(H)
  10689. return new Buffer(digestbytes)
  10690. }
  10691. module.exports = ripemd160
  10692. }).call(this,require("buffer").Buffer)
  10693. },{"buffer":7}],35:[function(require,module,exports){
  10694. (function (Buffer){
  10695. // prototype class for hash functions
  10696. function Hash (blockSize, finalSize) {
  10697. this._block = new Buffer(blockSize)
  10698. this._finalSize = finalSize
  10699. this._blockSize = blockSize
  10700. this._len = 0
  10701. this._s = 0
  10702. }
  10703. Hash.prototype.update = function (data, enc) {
  10704. if (typeof data === 'string') {
  10705. enc = enc || 'utf8'
  10706. data = new Buffer(data, enc)
  10707. }
  10708. var l = this._len += data.length
  10709. var s = this._s || 0
  10710. var f = 0
  10711. var buffer = this._block
  10712. while (s < l) {
  10713. var t = Math.min(data.length, f + this._blockSize - (s % this._blockSize))
  10714. var ch = (t - f)
  10715. for (var i = 0; i < ch; i++) {
  10716. buffer[(s % this._blockSize) + i] = data[i + f]
  10717. }
  10718. s += ch
  10719. f += ch
  10720. if ((s % this._blockSize) === 0) {
  10721. this._update(buffer)
  10722. }
  10723. }
  10724. this._s = s
  10725. return this
  10726. }
  10727. Hash.prototype.digest = function (enc) {
  10728. // Suppose the length of the message M, in bits, is l
  10729. var l = this._len * 8
  10730. // Append the bit 1 to the end of the message
  10731. this._block[this._len % this._blockSize] = 0x80
  10732. // and then k zero bits, where k is the smallest non-negative solution to the equation (l + 1 + k) === finalSize mod blockSize
  10733. this._block.fill(0, this._len % this._blockSize + 1)
  10734. if (l % (this._blockSize * 8) >= this._finalSize * 8) {
  10735. this._update(this._block)
  10736. this._block.fill(0)
  10737. }
  10738. // to this append the block which is equal to the number l written in binary
  10739. // TODO: handle case where l is > Math.pow(2, 29)
  10740. this._block.writeInt32BE(l, this._blockSize - 4)
  10741. var hash = this._update(this._block) || this._hash()
  10742. return enc ? hash.toString(enc) : hash
  10743. }
  10744. Hash.prototype._update = function () {
  10745. throw new Error('_update must be implemented by subclass')
  10746. }
  10747. module.exports = Hash
  10748. }).call(this,require("buffer").Buffer)
  10749. },{"buffer":7}],36:[function(require,module,exports){
  10750. var exports = module.exports = function SHA (algorithm) {
  10751. algorithm = algorithm.toLowerCase()
  10752. var Algorithm = exports[algorithm]
  10753. if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)')
  10754. return new Algorithm()
  10755. }
  10756. exports.sha = require('./sha')
  10757. exports.sha1 = require('./sha1')
  10758. exports.sha224 = require('./sha224')
  10759. exports.sha256 = require('./sha256')
  10760. exports.sha384 = require('./sha384')
  10761. exports.sha512 = require('./sha512')
  10762. },{"./sha":37,"./sha1":38,"./sha224":39,"./sha256":40,"./sha384":41,"./sha512":42}],37:[function(require,module,exports){
  10763. (function (Buffer){
  10764. /*
  10765. * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
  10766. * in FIPS PUB 180-1
  10767. * This source code is derived from sha1.js of the same repository.
  10768. * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
  10769. * operation was added.
  10770. */
  10771. var inherits = require('inherits')
  10772. var Hash = require('./hash')
  10773. var K = [
  10774. 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
  10775. ]
  10776. var W = new Array(80)
  10777. function Sha () {
  10778. this.init()
  10779. this._w = W
  10780. Hash.call(this, 64, 56)
  10781. }
  10782. inherits(Sha, Hash)
  10783. Sha.prototype.init = function () {
  10784. this._a = 0x67452301
  10785. this._b = 0xefcdab89
  10786. this._c = 0x98badcfe
  10787. this._d = 0x10325476
  10788. this._e = 0xc3d2e1f0
  10789. return this
  10790. }
  10791. function rotl5 (num) {
  10792. return (num << 5) | (num >>> 27)
  10793. }
  10794. function rotl30 (num) {
  10795. return (num << 30) | (num >>> 2)
  10796. }
  10797. function ft (s, b, c, d) {
  10798. if (s === 0) return (b & c) | ((~b) & d)
  10799. if (s === 2) return (b & c) | (b & d) | (c & d)
  10800. return b ^ c ^ d
  10801. }
  10802. Sha.prototype._update = function (M) {
  10803. var W = this._w
  10804. var a = this._a | 0
  10805. var b = this._b | 0
  10806. var c = this._c | 0
  10807. var d = this._d | 0
  10808. var e = this._e | 0
  10809. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  10810. for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]
  10811. for (var j = 0; j < 80; ++j) {
  10812. var s = ~~(j / 20)
  10813. var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
  10814. e = d
  10815. d = c
  10816. c = rotl30(b)
  10817. b = a
  10818. a = t
  10819. }
  10820. this._a = (a + this._a) | 0
  10821. this._b = (b + this._b) | 0
  10822. this._c = (c + this._c) | 0
  10823. this._d = (d + this._d) | 0
  10824. this._e = (e + this._e) | 0
  10825. }
  10826. Sha.prototype._hash = function () {
  10827. var H = new Buffer(20)
  10828. H.writeInt32BE(this._a | 0, 0)
  10829. H.writeInt32BE(this._b | 0, 4)
  10830. H.writeInt32BE(this._c | 0, 8)
  10831. H.writeInt32BE(this._d | 0, 12)
  10832. H.writeInt32BE(this._e | 0, 16)
  10833. return H
  10834. }
  10835. module.exports = Sha
  10836. }).call(this,require("buffer").Buffer)
  10837. },{"./hash":35,"buffer":7,"inherits":16}],38:[function(require,module,exports){
  10838. (function (Buffer){
  10839. /*
  10840. * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
  10841. * in FIPS PUB 180-1
  10842. * Version 2.1a Copyright Paul Johnston 2000 - 2002.
  10843. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  10844. * Distributed under the BSD License
  10845. * See http://pajhome.org.uk/crypt/md5 for details.
  10846. */
  10847. var inherits = require('inherits')
  10848. var Hash = require('./hash')
  10849. var K = [
  10850. 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
  10851. ]
  10852. var W = new Array(80)
  10853. function Sha1 () {
  10854. this.init()
  10855. this._w = W
  10856. Hash.call(this, 64, 56)
  10857. }
  10858. inherits(Sha1, Hash)
  10859. Sha1.prototype.init = function () {
  10860. this._a = 0x67452301
  10861. this._b = 0xefcdab89
  10862. this._c = 0x98badcfe
  10863. this._d = 0x10325476
  10864. this._e = 0xc3d2e1f0
  10865. return this
  10866. }
  10867. function rotl1 (num) {
  10868. return (num << 1) | (num >>> 31)
  10869. }
  10870. function rotl5 (num) {
  10871. return (num << 5) | (num >>> 27)
  10872. }
  10873. function rotl30 (num) {
  10874. return (num << 30) | (num >>> 2)
  10875. }
  10876. function ft (s, b, c, d) {
  10877. if (s === 0) return (b & c) | ((~b) & d)
  10878. if (s === 2) return (b & c) | (b & d) | (c & d)
  10879. return b ^ c ^ d
  10880. }
  10881. Sha1.prototype._update = function (M) {
  10882. var W = this._w
  10883. var a = this._a | 0
  10884. var b = this._b | 0
  10885. var c = this._c | 0
  10886. var d = this._d | 0
  10887. var e = this._e | 0
  10888. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  10889. for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16])
  10890. for (var j = 0; j < 80; ++j) {
  10891. var s = ~~(j / 20)
  10892. var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
  10893. e = d
  10894. d = c
  10895. c = rotl30(b)
  10896. b = a
  10897. a = t
  10898. }
  10899. this._a = (a + this._a) | 0
  10900. this._b = (b + this._b) | 0
  10901. this._c = (c + this._c) | 0
  10902. this._d = (d + this._d) | 0
  10903. this._e = (e + this._e) | 0
  10904. }
  10905. Sha1.prototype._hash = function () {
  10906. var H = new Buffer(20)
  10907. H.writeInt32BE(this._a | 0, 0)
  10908. H.writeInt32BE(this._b | 0, 4)
  10909. H.writeInt32BE(this._c | 0, 8)
  10910. H.writeInt32BE(this._d | 0, 12)
  10911. H.writeInt32BE(this._e | 0, 16)
  10912. return H
  10913. }
  10914. module.exports = Sha1
  10915. }).call(this,require("buffer").Buffer)
  10916. },{"./hash":35,"buffer":7,"inherits":16}],39:[function(require,module,exports){
  10917. (function (Buffer){
  10918. /**
  10919. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  10920. * in FIPS 180-2
  10921. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  10922. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  10923. *
  10924. */
  10925. var inherits = require('inherits')
  10926. var Sha256 = require('./sha256')
  10927. var Hash = require('./hash')
  10928. var W = new Array(64)
  10929. function Sha224 () {
  10930. this.init()
  10931. this._w = W // new Array(64)
  10932. Hash.call(this, 64, 56)
  10933. }
  10934. inherits(Sha224, Sha256)
  10935. Sha224.prototype.init = function () {
  10936. this._a = 0xc1059ed8
  10937. this._b = 0x367cd507
  10938. this._c = 0x3070dd17
  10939. this._d = 0xf70e5939
  10940. this._e = 0xffc00b31
  10941. this._f = 0x68581511
  10942. this._g = 0x64f98fa7
  10943. this._h = 0xbefa4fa4
  10944. return this
  10945. }
  10946. Sha224.prototype._hash = function () {
  10947. var H = new Buffer(28)
  10948. H.writeInt32BE(this._a, 0)
  10949. H.writeInt32BE(this._b, 4)
  10950. H.writeInt32BE(this._c, 8)
  10951. H.writeInt32BE(this._d, 12)
  10952. H.writeInt32BE(this._e, 16)
  10953. H.writeInt32BE(this._f, 20)
  10954. H.writeInt32BE(this._g, 24)
  10955. return H
  10956. }
  10957. module.exports = Sha224
  10958. }).call(this,require("buffer").Buffer)
  10959. },{"./hash":35,"./sha256":40,"buffer":7,"inherits":16}],40:[function(require,module,exports){
  10960. (function (Buffer){
  10961. /**
  10962. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  10963. * in FIPS 180-2
  10964. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  10965. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  10966. *
  10967. */
  10968. var inherits = require('inherits')
  10969. var Hash = require('./hash')
  10970. var K = [
  10971. 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
  10972. 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
  10973. 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
  10974. 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
  10975. 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
  10976. 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
  10977. 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
  10978. 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
  10979. 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
  10980. 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
  10981. 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
  10982. 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
  10983. 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
  10984. 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
  10985. 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
  10986. 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
  10987. ]
  10988. var W = new Array(64)
  10989. function Sha256 () {
  10990. this.init()
  10991. this._w = W // new Array(64)
  10992. Hash.call(this, 64, 56)
  10993. }
  10994. inherits(Sha256, Hash)
  10995. Sha256.prototype.init = function () {
  10996. this._a = 0x6a09e667
  10997. this._b = 0xbb67ae85
  10998. this._c = 0x3c6ef372
  10999. this._d = 0xa54ff53a
  11000. this._e = 0x510e527f
  11001. this._f = 0x9b05688c
  11002. this._g = 0x1f83d9ab
  11003. this._h = 0x5be0cd19
  11004. return this
  11005. }
  11006. function ch (x, y, z) {
  11007. return z ^ (x & (y ^ z))
  11008. }
  11009. function maj (x, y, z) {
  11010. return (x & y) | (z & (x | y))
  11011. }
  11012. function sigma0 (x) {
  11013. return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10)
  11014. }
  11015. function sigma1 (x) {
  11016. return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7)
  11017. }
  11018. function gamma0 (x) {
  11019. return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3)
  11020. }
  11021. function gamma1 (x) {
  11022. return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10)
  11023. }
  11024. Sha256.prototype._update = function (M) {
  11025. var W = this._w
  11026. var a = this._a | 0
  11027. var b = this._b | 0
  11028. var c = this._c | 0
  11029. var d = this._d | 0
  11030. var e = this._e | 0
  11031. var f = this._f | 0
  11032. var g = this._g | 0
  11033. var h = this._h | 0
  11034. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  11035. for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0
  11036. for (var j = 0; j < 64; ++j) {
  11037. var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0
  11038. var T2 = (sigma0(a) + maj(a, b, c)) | 0
  11039. h = g
  11040. g = f
  11041. f = e
  11042. e = (d + T1) | 0
  11043. d = c
  11044. c = b
  11045. b = a
  11046. a = (T1 + T2) | 0
  11047. }
  11048. this._a = (a + this._a) | 0
  11049. this._b = (b + this._b) | 0
  11050. this._c = (c + this._c) | 0
  11051. this._d = (d + this._d) | 0
  11052. this._e = (e + this._e) | 0
  11053. this._f = (f + this._f) | 0
  11054. this._g = (g + this._g) | 0
  11055. this._h = (h + this._h) | 0
  11056. }
  11057. Sha256.prototype._hash = function () {
  11058. var H = new Buffer(32)
  11059. H.writeInt32BE(this._a, 0)
  11060. H.writeInt32BE(this._b, 4)
  11061. H.writeInt32BE(this._c, 8)
  11062. H.writeInt32BE(this._d, 12)
  11063. H.writeInt32BE(this._e, 16)
  11064. H.writeInt32BE(this._f, 20)
  11065. H.writeInt32BE(this._g, 24)
  11066. H.writeInt32BE(this._h, 28)
  11067. return H
  11068. }
  11069. module.exports = Sha256
  11070. }).call(this,require("buffer").Buffer)
  11071. },{"./hash":35,"buffer":7,"inherits":16}],41:[function(require,module,exports){
  11072. (function (Buffer){
  11073. var inherits = require('inherits')
  11074. var SHA512 = require('./sha512')
  11075. var Hash = require('./hash')
  11076. var W = new Array(160)
  11077. function Sha384 () {
  11078. this.init()
  11079. this._w = W
  11080. Hash.call(this, 128, 112)
  11081. }
  11082. inherits(Sha384, SHA512)
  11083. Sha384.prototype.init = function () {
  11084. this._ah = 0xcbbb9d5d
  11085. this._bh = 0x629a292a
  11086. this._ch = 0x9159015a
  11087. this._dh = 0x152fecd8
  11088. this._eh = 0x67332667
  11089. this._fh = 0x8eb44a87
  11090. this._gh = 0xdb0c2e0d
  11091. this._hh = 0x47b5481d
  11092. this._al = 0xc1059ed8
  11093. this._bl = 0x367cd507
  11094. this._cl = 0x3070dd17
  11095. this._dl = 0xf70e5939
  11096. this._el = 0xffc00b31
  11097. this._fl = 0x68581511
  11098. this._gl = 0x64f98fa7
  11099. this._hl = 0xbefa4fa4
  11100. return this
  11101. }
  11102. Sha384.prototype._hash = function () {
  11103. var H = new Buffer(48)
  11104. function writeInt64BE (h, l, offset) {
  11105. H.writeInt32BE(h, offset)
  11106. H.writeInt32BE(l, offset + 4)
  11107. }
  11108. writeInt64BE(this._ah, this._al, 0)
  11109. writeInt64BE(this._bh, this._bl, 8)
  11110. writeInt64BE(this._ch, this._cl, 16)
  11111. writeInt64BE(this._dh, this._dl, 24)
  11112. writeInt64BE(this._eh, this._el, 32)
  11113. writeInt64BE(this._fh, this._fl, 40)
  11114. return H
  11115. }
  11116. module.exports = Sha384
  11117. }).call(this,require("buffer").Buffer)
  11118. },{"./hash":35,"./sha512":42,"buffer":7,"inherits":16}],42:[function(require,module,exports){
  11119. (function (Buffer){
  11120. var inherits = require('inherits')
  11121. var Hash = require('./hash')
  11122. var K = [
  11123. 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
  11124. 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
  11125. 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
  11126. 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
  11127. 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
  11128. 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
  11129. 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
  11130. 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
  11131. 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
  11132. 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
  11133. 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
  11134. 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
  11135. 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
  11136. 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
  11137. 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
  11138. 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
  11139. 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
  11140. 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
  11141. 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
  11142. 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
  11143. 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
  11144. 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
  11145. 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
  11146. 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
  11147. 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
  11148. 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
  11149. 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
  11150. 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
  11151. 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
  11152. 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
  11153. 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
  11154. 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
  11155. 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
  11156. 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
  11157. 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
  11158. 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
  11159. 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
  11160. 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
  11161. 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
  11162. 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
  11163. ]
  11164. var W = new Array(160)
  11165. function Sha512 () {
  11166. this.init()
  11167. this._w = W
  11168. Hash.call(this, 128, 112)
  11169. }
  11170. inherits(Sha512, Hash)
  11171. Sha512.prototype.init = function () {
  11172. this._ah = 0x6a09e667
  11173. this._bh = 0xbb67ae85
  11174. this._ch = 0x3c6ef372
  11175. this._dh = 0xa54ff53a
  11176. this._eh = 0x510e527f
  11177. this._fh = 0x9b05688c
  11178. this._gh = 0x1f83d9ab
  11179. this._hh = 0x5be0cd19
  11180. this._al = 0xf3bcc908
  11181. this._bl = 0x84caa73b
  11182. this._cl = 0xfe94f82b
  11183. this._dl = 0x5f1d36f1
  11184. this._el = 0xade682d1
  11185. this._fl = 0x2b3e6c1f
  11186. this._gl = 0xfb41bd6b
  11187. this._hl = 0x137e2179
  11188. return this
  11189. }
  11190. function Ch (x, y, z) {
  11191. return z ^ (x & (y ^ z))
  11192. }
  11193. function maj (x, y, z) {
  11194. return (x & y) | (z & (x | y))
  11195. }
  11196. function sigma0 (x, xl) {
  11197. return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25)
  11198. }
  11199. function sigma1 (x, xl) {
  11200. return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23)
  11201. }
  11202. function Gamma0 (x, xl) {
  11203. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7)
  11204. }
  11205. function Gamma0l (x, xl) {
  11206. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25)
  11207. }
  11208. function Gamma1 (x, xl) {
  11209. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6)
  11210. }
  11211. function Gamma1l (x, xl) {
  11212. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26)
  11213. }
  11214. function getCarry (a, b) {
  11215. return (a >>> 0) < (b >>> 0) ? 1 : 0
  11216. }
  11217. Sha512.prototype._update = function (M) {
  11218. var W = this._w
  11219. var ah = this._ah | 0
  11220. var bh = this._bh | 0
  11221. var ch = this._ch | 0
  11222. var dh = this._dh | 0
  11223. var eh = this._eh | 0
  11224. var fh = this._fh | 0
  11225. var gh = this._gh | 0
  11226. var hh = this._hh | 0
  11227. var al = this._al | 0
  11228. var bl = this._bl | 0
  11229. var cl = this._cl | 0
  11230. var dl = this._dl | 0
  11231. var el = this._el | 0
  11232. var fl = this._fl | 0
  11233. var gl = this._gl | 0
  11234. var hl = this._hl | 0
  11235. for (var i = 0; i < 32; i += 2) {
  11236. W[i] = M.readInt32BE(i * 4)
  11237. W[i + 1] = M.readInt32BE(i * 4 + 4)
  11238. }
  11239. for (; i < 160; i += 2) {
  11240. var xh = W[i - 15 * 2]
  11241. var xl = W[i - 15 * 2 + 1]
  11242. var gamma0 = Gamma0(xh, xl)
  11243. var gamma0l = Gamma0l(xl, xh)
  11244. xh = W[i - 2 * 2]
  11245. xl = W[i - 2 * 2 + 1]
  11246. var gamma1 = Gamma1(xh, xl)
  11247. var gamma1l = Gamma1l(xl, xh)
  11248. // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  11249. var Wi7h = W[i - 7 * 2]
  11250. var Wi7l = W[i - 7 * 2 + 1]
  11251. var Wi16h = W[i - 16 * 2]
  11252. var Wi16l = W[i - 16 * 2 + 1]
  11253. var Wil = (gamma0l + Wi7l) | 0
  11254. var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0
  11255. Wil = (Wil + gamma1l) | 0
  11256. Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0
  11257. Wil = (Wil + Wi16l) | 0
  11258. Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0
  11259. W[i] = Wih
  11260. W[i + 1] = Wil
  11261. }
  11262. for (var j = 0; j < 160; j += 2) {
  11263. Wih = W[j]
  11264. Wil = W[j + 1]
  11265. var majh = maj(ah, bh, ch)
  11266. var majl = maj(al, bl, cl)
  11267. var sigma0h = sigma0(ah, al)
  11268. var sigma0l = sigma0(al, ah)
  11269. var sigma1h = sigma1(eh, el)
  11270. var sigma1l = sigma1(el, eh)
  11271. // t1 = h + sigma1 + ch + K[j] + W[j]
  11272. var Kih = K[j]
  11273. var Kil = K[j + 1]
  11274. var chh = Ch(eh, fh, gh)
  11275. var chl = Ch(el, fl, gl)
  11276. var t1l = (hl + sigma1l) | 0
  11277. var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0
  11278. t1l = (t1l + chl) | 0
  11279. t1h = (t1h + chh + getCarry(t1l, chl)) | 0
  11280. t1l = (t1l + Kil) | 0
  11281. t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0
  11282. t1l = (t1l + Wil) | 0
  11283. t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0
  11284. // t2 = sigma0 + maj
  11285. var t2l = (sigma0l + majl) | 0
  11286. var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0
  11287. hh = gh
  11288. hl = gl
  11289. gh = fh
  11290. gl = fl
  11291. fh = eh
  11292. fl = el
  11293. el = (dl + t1l) | 0
  11294. eh = (dh + t1h + getCarry(el, dl)) | 0
  11295. dh = ch
  11296. dl = cl
  11297. ch = bh
  11298. cl = bl
  11299. bh = ah
  11300. bl = al
  11301. al = (t1l + t2l) | 0
  11302. ah = (t1h + t2h + getCarry(al, t1l)) | 0
  11303. }
  11304. this._al = (this._al + al) | 0
  11305. this._bl = (this._bl + bl) | 0
  11306. this._cl = (this._cl + cl) | 0
  11307. this._dl = (this._dl + dl) | 0
  11308. this._el = (this._el + el) | 0
  11309. this._fl = (this._fl + fl) | 0
  11310. this._gl = (this._gl + gl) | 0
  11311. this._hl = (this._hl + hl) | 0
  11312. this._ah = (this._ah + ah + getCarry(this._al, al)) | 0
  11313. this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0
  11314. this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0
  11315. this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0
  11316. this._eh = (this._eh + eh + getCarry(this._el, el)) | 0
  11317. this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0
  11318. this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0
  11319. this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0
  11320. }
  11321. Sha512.prototype._hash = function () {
  11322. var H = new Buffer(64)
  11323. function writeInt64BE (h, l, offset) {
  11324. H.writeInt32BE(h, offset)
  11325. H.writeInt32BE(l, offset + 4)
  11326. }
  11327. writeInt64BE(this._ah, this._al, 0)
  11328. writeInt64BE(this._bh, this._bl, 8)
  11329. writeInt64BE(this._ch, this._cl, 16)
  11330. writeInt64BE(this._dh, this._dl, 24)
  11331. writeInt64BE(this._eh, this._el, 32)
  11332. writeInt64BE(this._fh, this._fl, 40)
  11333. writeInt64BE(this._gh, this._gl, 48)
  11334. writeInt64BE(this._hh, this._hl, 56)
  11335. return H
  11336. }
  11337. module.exports = Sha512
  11338. }).call(this,require("buffer").Buffer)
  11339. },{"./hash":35,"buffer":7,"inherits":16}],43:[function(require,module,exports){
  11340. // Copyright Joyent, Inc. and other Node contributors.
  11341. //
  11342. // Permission is hereby granted, free of charge, to any person obtaining a
  11343. // copy of this software and associated documentation files (the
  11344. // "Software"), to deal in the Software without restriction, including
  11345. // without limitation the rights to use, copy, modify, merge, publish,
  11346. // distribute, sublicense, and/or sell copies of the Software, and to permit
  11347. // persons to whom the Software is furnished to do so, subject to the
  11348. // following conditions:
  11349. //
  11350. // The above copyright notice and this permission notice shall be included
  11351. // in all copies or substantial portions of the Software.
  11352. //
  11353. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11354. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11355. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  11356. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  11357. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  11358. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  11359. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  11360. module.exports = Stream;
  11361. var EE = require('events').EventEmitter;
  11362. var inherits = require('inherits');
  11363. inherits(Stream, EE);
  11364. Stream.Readable = require('readable-stream/readable.js');
  11365. Stream.Writable = require('readable-stream/writable.js');
  11366. Stream.Duplex = require('readable-stream/duplex.js');
  11367. Stream.Transform = require('readable-stream/transform.js');
  11368. Stream.PassThrough = require('readable-stream/passthrough.js');
  11369. // Backwards-compat with node 0.4.x
  11370. Stream.Stream = Stream;
  11371. // old-style streams. Note that the pipe method (the only relevant
  11372. // part of this class) is overridden in the Readable class.
  11373. function Stream() {
  11374. EE.call(this);
  11375. }
  11376. Stream.prototype.pipe = function(dest, options) {
  11377. var source = this;
  11378. function ondata(chunk) {
  11379. if (dest.writable) {
  11380. if (false === dest.write(chunk) && source.pause) {
  11381. source.pause();
  11382. }
  11383. }
  11384. }
  11385. source.on('data', ondata);
  11386. function ondrain() {
  11387. if (source.readable && source.resume) {
  11388. source.resume();
  11389. }
  11390. }
  11391. dest.on('drain', ondrain);
  11392. // If the 'end' option is not supplied, dest.end() will be called when
  11393. // source gets the 'end' or 'close' events. Only dest.end() once.
  11394. if (!dest._isStdio && (!options || options.end !== false)) {
  11395. source.on('end', onend);
  11396. source.on('close', onclose);
  11397. }
  11398. var didOnEnd = false;
  11399. function onend() {
  11400. if (didOnEnd) return;
  11401. didOnEnd = true;
  11402. dest.end();
  11403. }
  11404. function onclose() {
  11405. if (didOnEnd) return;
  11406. didOnEnd = true;
  11407. if (typeof dest.destroy === 'function') dest.destroy();
  11408. }
  11409. // don't leave dangling pipes when there are errors.
  11410. function onerror(er) {
  11411. cleanup();
  11412. if (EE.listenerCount(this, 'error') === 0) {
  11413. throw er; // Unhandled stream error in pipe.
  11414. }
  11415. }
  11416. source.on('error', onerror);
  11417. dest.on('error', onerror);
  11418. // remove all the event listeners that were added.
  11419. function cleanup() {
  11420. source.removeListener('data', ondata);
  11421. dest.removeListener('drain', ondrain);
  11422. source.removeListener('end', onend);
  11423. source.removeListener('close', onclose);
  11424. source.removeListener('error', onerror);
  11425. dest.removeListener('error', onerror);
  11426. source.removeListener('end', cleanup);
  11427. source.removeListener('close', cleanup);
  11428. dest.removeListener('close', cleanup);
  11429. }
  11430. source.on('end', cleanup);
  11431. source.on('close', cleanup);
  11432. dest.on('close', cleanup);
  11433. dest.emit('pipe', source);
  11434. // Allow for unix-like usage: A.pipe(B).pipe(C)
  11435. return dest;
  11436. };
  11437. },{"events":14,"inherits":16,"readable-stream/duplex.js":23,"readable-stream/passthrough.js":30,"readable-stream/readable.js":31,"readable-stream/transform.js":32,"readable-stream/writable.js":33}],44:[function(require,module,exports){
  11438. // Copyright Joyent, Inc. and other Node contributors.
  11439. //
  11440. // Permission is hereby granted, free of charge, to any person obtaining a
  11441. // copy of this software and associated documentation files (the
  11442. // "Software"), to deal in the Software without restriction, including
  11443. // without limitation the rights to use, copy, modify, merge, publish,
  11444. // distribute, sublicense, and/or sell copies of the Software, and to permit
  11445. // persons to whom the Software is furnished to do so, subject to the
  11446. // following conditions:
  11447. //
  11448. // The above copyright notice and this permission notice shall be included
  11449. // in all copies or substantial portions of the Software.
  11450. //
  11451. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11452. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11453. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  11454. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  11455. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  11456. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  11457. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  11458. var Buffer = require('buffer').Buffer;
  11459. var isBufferEncoding = Buffer.isEncoding
  11460. || function(encoding) {
  11461. switch (encoding && encoding.toLowerCase()) {
  11462. case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true;
  11463. default: return false;
  11464. }
  11465. }
  11466. function assertEncoding(encoding) {
  11467. if (encoding && !isBufferEncoding(encoding)) {
  11468. throw new Error('Unknown encoding: ' + encoding);
  11469. }
  11470. }
  11471. // StringDecoder provides an interface for efficiently splitting a series of
  11472. // buffers into a series of JS strings without breaking apart multi-byte
  11473. // characters. CESU-8 is handled as part of the UTF-8 encoding.
  11474. //
  11475. // @TODO Handling all encodings inside a single object makes it very difficult
  11476. // to reason about this code, so it should be split up in the future.
  11477. // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
  11478. // points as used by CESU-8.
  11479. var StringDecoder = exports.StringDecoder = function(encoding) {
  11480. this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
  11481. assertEncoding(encoding);
  11482. switch (this.encoding) {
  11483. case 'utf8':
  11484. // CESU-8 represents each of Surrogate Pair by 3-bytes
  11485. this.surrogateSize = 3;
  11486. break;
  11487. case 'ucs2':
  11488. case 'utf16le':
  11489. // UTF-16 represents each of Surrogate Pair by 2-bytes
  11490. this.surrogateSize = 2;
  11491. this.detectIncompleteChar = utf16DetectIncompleteChar;
  11492. break;
  11493. case 'base64':
  11494. // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
  11495. this.surrogateSize = 3;
  11496. this.detectIncompleteChar = base64DetectIncompleteChar;
  11497. break;
  11498. default:
  11499. this.write = passThroughWrite;
  11500. return;
  11501. }
  11502. // Enough space to store all bytes of a single character. UTF-8 needs 4
  11503. // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
  11504. this.charBuffer = new Buffer(6);
  11505. // Number of bytes received for the current incomplete multi-byte character.
  11506. this.charReceived = 0;
  11507. // Number of bytes expected for the current incomplete multi-byte character.
  11508. this.charLength = 0;
  11509. };
  11510. // write decodes the given buffer and returns it as JS string that is
  11511. // guaranteed to not contain any partial multi-byte characters. Any partial
  11512. // character found at the end of the buffer is buffered up, and will be
  11513. // returned when calling write again with the remaining bytes.
  11514. //
  11515. // Note: Converting a Buffer containing an orphan surrogate to a String
  11516. // currently works, but converting a String to a Buffer (via `new Buffer`, or
  11517. // Buffer#write) will replace incomplete surrogates with the unicode
  11518. // replacement character. See https://codereview.chromium.org/121173009/ .
  11519. StringDecoder.prototype.write = function(buffer) {
  11520. var charStr = '';
  11521. // if our last write ended with an incomplete multibyte character
  11522. while (this.charLength) {
  11523. // determine how many remaining bytes this buffer has to offer for this char
  11524. var available = (buffer.length >= this.charLength - this.charReceived) ?
  11525. this.charLength - this.charReceived :
  11526. buffer.length;
  11527. // add the new bytes to the char buffer
  11528. buffer.copy(this.charBuffer, this.charReceived, 0, available);
  11529. this.charReceived += available;
  11530. if (this.charReceived < this.charLength) {
  11531. // still not enough chars in this buffer? wait for more ...
  11532. return '';
  11533. }
  11534. // remove bytes belonging to the current character from the buffer
  11535. buffer = buffer.slice(available, buffer.length);
  11536. // get the character that was split
  11537. charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
  11538. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  11539. var charCode = charStr.charCodeAt(charStr.length - 1);
  11540. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  11541. this.charLength += this.surrogateSize;
  11542. charStr = '';
  11543. continue;
  11544. }
  11545. this.charReceived = this.charLength = 0;
  11546. // if there are no more bytes in this buffer, just emit our char
  11547. if (buffer.length === 0) {
  11548. return charStr;
  11549. }
  11550. break;
  11551. }
  11552. // determine and set charLength / charReceived
  11553. this.detectIncompleteChar(buffer);
  11554. var end = buffer.length;
  11555. if (this.charLength) {
  11556. // buffer the incomplete character bytes we got
  11557. buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
  11558. end -= this.charReceived;
  11559. }
  11560. charStr += buffer.toString(this.encoding, 0, end);
  11561. var end = charStr.length - 1;
  11562. var charCode = charStr.charCodeAt(end);
  11563. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  11564. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  11565. var size = this.surrogateSize;
  11566. this.charLength += size;
  11567. this.charReceived += size;
  11568. this.charBuffer.copy(this.charBuffer, size, 0, size);
  11569. buffer.copy(this.charBuffer, 0, 0, size);
  11570. return charStr.substring(0, end);
  11571. }
  11572. // or just emit the charStr
  11573. return charStr;
  11574. };
  11575. // detectIncompleteChar determines if there is an incomplete UTF-8 character at
  11576. // the end of the given buffer. If so, it sets this.charLength to the byte
  11577. // length that character, and sets this.charReceived to the number of bytes
  11578. // that are available for this character.
  11579. StringDecoder.prototype.detectIncompleteChar = function(buffer) {
  11580. // determine how many bytes we have to check at the end of this buffer
  11581. var i = (buffer.length >= 3) ? 3 : buffer.length;
  11582. // Figure out if one of the last i bytes of our buffer announces an
  11583. // incomplete char.
  11584. for (; i > 0; i--) {
  11585. var c = buffer[buffer.length - i];
  11586. // See http://en.wikipedia.org/wiki/UTF-8#Description
  11587. // 110XXXXX
  11588. if (i == 1 && c >> 5 == 0x06) {
  11589. this.charLength = 2;
  11590. break;
  11591. }
  11592. // 1110XXXX
  11593. if (i <= 2 && c >> 4 == 0x0E) {
  11594. this.charLength = 3;
  11595. break;
  11596. }
  11597. // 11110XXX
  11598. if (i <= 3 && c >> 3 == 0x1E) {
  11599. this.charLength = 4;
  11600. break;
  11601. }
  11602. }
  11603. this.charReceived = i;
  11604. };
  11605. StringDecoder.prototype.end = function(buffer) {
  11606. var res = '';
  11607. if (buffer && buffer.length)
  11608. res = this.write(buffer);
  11609. if (this.charReceived) {
  11610. var cr = this.charReceived;
  11611. var buf = this.charBuffer;
  11612. var enc = this.encoding;
  11613. res += buf.slice(0, cr).toString(enc);
  11614. }
  11615. return res;
  11616. };
  11617. function passThroughWrite(buffer) {
  11618. return buffer.toString(this.encoding);
  11619. }
  11620. function utf16DetectIncompleteChar(buffer) {
  11621. this.charReceived = buffer.length % 2;
  11622. this.charLength = this.charReceived ? 2 : 0;
  11623. }
  11624. function base64DetectIncompleteChar(buffer) {
  11625. this.charReceived = buffer.length % 3;
  11626. this.charLength = this.charReceived ? 3 : 0;
  11627. }
  11628. },{"buffer":7}],45:[function(require,module,exports){
  11629. (function (global){
  11630. /**
  11631. * Module exports.
  11632. */
  11633. module.exports = deprecate;
  11634. /**
  11635. * Mark that a method should not be used.
  11636. * Returns a modified function which warns once by default.
  11637. *
  11638. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  11639. *
  11640. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  11641. * will throw an Error when invoked.
  11642. *
  11643. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  11644. * will invoke `console.trace()` instead of `console.error()`.
  11645. *
  11646. * @param {Function} fn - the function to deprecate
  11647. * @param {String} msg - the string to print to the console when `fn` is invoked
  11648. * @returns {Function} a new "deprecated" version of `fn`
  11649. * @api public
  11650. */
  11651. function deprecate (fn, msg) {
  11652. if (config('noDeprecation')) {
  11653. return fn;
  11654. }
  11655. var warned = false;
  11656. function deprecated() {
  11657. if (!warned) {
  11658. if (config('throwDeprecation')) {
  11659. throw new Error(msg);
  11660. } else if (config('traceDeprecation')) {
  11661. console.trace(msg);
  11662. } else {
  11663. console.warn(msg);
  11664. }
  11665. warned = true;
  11666. }
  11667. return fn.apply(this, arguments);
  11668. }
  11669. return deprecated;
  11670. }
  11671. /**
  11672. * Checks `localStorage` for boolean values for the given `name`.
  11673. *
  11674. * @param {String} name
  11675. * @returns {Boolean}
  11676. * @api private
  11677. */
  11678. function config (name) {
  11679. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  11680. try {
  11681. if (!global.localStorage) return false;
  11682. } catch (_) {
  11683. return false;
  11684. }
  11685. var val = global.localStorage[name];
  11686. if (null == val) return false;
  11687. return String(val).toLowerCase() === 'true';
  11688. }
  11689. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  11690. },{}],46:[function(require,module,exports){
  11691. (function (Buffer){
  11692. var pbkdf2 = require('pbkdf2');
  11693. var createHMAC = require('create-hmac');
  11694. var Promise = require("bluebird");
  11695. module.exports = {
  11696. encryptLogin: encryptLogin,
  11697. renderPassword: renderPassword,
  11698. createFingerprint: createFingerprint,
  11699. _deriveEncryptedLogin: deriveEncryptedLogin,
  11700. _getPasswordTemplate: getPasswordTemplate,
  11701. _prettyPrint: prettyPrint,
  11702. _string2charCodes: string2charCodes,
  11703. _getCharType: getCharType,
  11704. _getPasswordChar: getPasswordChar,
  11705. _createHmac: createHmac,
  11706. };
  11707. function encryptLogin(login, masterPassword, options) {
  11708. var _options = options !== undefined ? options : {};
  11709. var iterations = _options.iterations || 8192;
  11710. var keylen = _options.keylen || 32;
  11711. return new Promise(function (resolve, reject) {
  11712. if (!login || !masterPassword) {
  11713. reject('login and master password parameters could not be empty');
  11714. }
  11715. pbkdf2.pbkdf2(masterPassword, login, iterations, keylen, 'sha256', function (error, key) {
  11716. if (error) {
  11717. reject('error in pbkdf2');
  11718. } else {
  11719. resolve(key.toString('hex'));
  11720. }
  11721. });
  11722. })
  11723. }
  11724. function renderPassword(encryptedLogin, site, passwordOptions) {
  11725. return deriveEncryptedLogin(encryptedLogin, site, passwordOptions).then(function (derivedEncryptedLogin) {
  11726. var template = passwordOptions.template || getPasswordTemplate(passwordOptions);
  11727. return prettyPrint(derivedEncryptedLogin, template);
  11728. });
  11729. }
  11730. function createHmac(encryptedLogin, salt) {
  11731. return new Promise(function (resolve) {
  11732. resolve(createHMAC('sha256', new Buffer(encryptedLogin)).update(salt).digest('hex'));
  11733. });
  11734. }
  11735. function deriveEncryptedLogin(encryptedLogin, site, options) {
  11736. var _options = options !== undefined ? options : {};
  11737. var length = _options.length || 12;
  11738. var counter = _options.counter || 1;
  11739. var salt = site + counter.toString();
  11740. return createHmac(encryptedLogin, salt).then(function (derivedHash) {
  11741. return derivedHash.substring(0, length);
  11742. });
  11743. }
  11744. function getPasswordTemplate(passwordTypes) {
  11745. var templates = {
  11746. lowercase: 'vc',
  11747. uppercase: 'VC',
  11748. numbers: 'n',
  11749. symbols: 's',
  11750. };
  11751. var returnedTemplate = '';
  11752. Object.keys(templates).forEach(function (template) {
  11753. if (passwordTypes.hasOwnProperty(template) && passwordTypes[template]) {
  11754. returnedTemplate += templates[template]
  11755. }
  11756. });
  11757. return returnedTemplate;
  11758. }
  11759. function prettyPrint(hash, template) {
  11760. var password = '';
  11761. string2charCodes(hash).forEach(function (charCode, index) {
  11762. var charType = getCharType(template, index);
  11763. password += getPasswordChar(charType, charCode);
  11764. });
  11765. return password;
  11766. }
  11767. function string2charCodes(text) {
  11768. var charCodes = [];
  11769. for (var i = 0; i < text.length; i++) {
  11770. charCodes.push(text.charCodeAt(i));
  11771. }
  11772. return charCodes;
  11773. }
  11774. function getCharType(template, index) {
  11775. return template[index % template.length];
  11776. }
  11777. function getPasswordChar(charType, index) {
  11778. var passwordsChars = {
  11779. V: 'AEIOUY',
  11780. C: 'BCDFGHJKLMNPQRSTVWXZ',
  11781. v: 'aeiouy',
  11782. c: 'bcdfghjklmnpqrstvwxz',
  11783. A: 'AEIOUYBCDFGHJKLMNPQRSTVWXZ',
  11784. a: 'AEIOUYaeiouyBCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz',
  11785. n: '0123456789',
  11786. s: '@&%?,=[]_:-+*$#!\'^~;()/.',
  11787. x: 'AEIOUYaeiouyBCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz0123456789@&%?,=[]_:-+*$#!\'^~;()/.'
  11788. };
  11789. var passwordChar = passwordsChars[charType];
  11790. return passwordChar[index % passwordChar.length];
  11791. }
  11792. function createFingerprint(str) {
  11793. return new Promise(function (resolve) {
  11794. resolve(createHMAC('sha256', new Buffer(str)).digest('hex'))
  11795. });
  11796. }
  11797. }).call(this,require("buffer").Buffer)
  11798. },{"bluebird":4,"buffer":7,"create-hmac":13,"pbkdf2":19}],47:[function(require,module,exports){
  11799. var Promise = require("bluebird");
  11800. var pbkdf2 = require('pbkdf2');
  11801. var bigInt = require("big-integer");
  11802. module.exports = {
  11803. generatePassword: generatePassword,
  11804. _calcEntropy: calcEntropy,
  11805. _getSetOfCharacters: getSetOfCharacters,
  11806. _renderPassword: renderPassword
  11807. };
  11808. function generatePassword(site, login, masterPassword, passwordProfile) {
  11809. return calcEntropy(site, login, masterPassword, passwordProfile).then(function (entropy) {
  11810. var setOfCharacters = getSetOfCharacters(passwordProfile);
  11811. return renderPassword(entropy, setOfCharacters, passwordProfile)
  11812. });
  11813. }
  11814. function calcEntropy(site, login, masterPassword, passwordProfile) {
  11815. return new Promise(function (resolve, reject) {
  11816. var salt = site + login + passwordProfile.counter.toString(16);
  11817. var iterations = passwordProfile.iterations || 100000;
  11818. var keylen = passwordProfile.keylen || 32;
  11819. var digest = passwordProfile.digest || 'sha256';
  11820. pbkdf2.pbkdf2(masterPassword, salt, iterations, keylen, digest, function (error, key) {
  11821. if (error) {
  11822. reject('error in pbkdf2');
  11823. } else {
  11824. resolve(key.toString('hex'));
  11825. }
  11826. });
  11827. });
  11828. }
  11829. function getSetOfCharacters(passwordProfile) {
  11830. var subsetOfCharacters = {
  11831. lowercase: 'abcdefghijklmnopqrstuvwxyz',
  11832. uppercase: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
  11833. digits: '0123456789',
  11834. symbols: '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
  11835. };
  11836. if (typeof passwordProfile === 'undefined') {
  11837. return subsetOfCharacters.lowercase + subsetOfCharacters.uppercase + subsetOfCharacters.digits;
  11838. }
  11839. var setOfCharacters = '';
  11840. ['lowercase', 'uppercase', 'digits', 'symbols'].forEach(function (subset) {
  11841. if (passwordProfile.hasOwnProperty(subset) && passwordProfile[subset]) {
  11842. setOfCharacters += subsetOfCharacters[subset]
  11843. }
  11844. });
  11845. return setOfCharacters;
  11846. }
  11847. function consumeEntropy(generatedPassword, quotient, setOfCharacters, maxLength) {
  11848. if (generatedPassword.length >= maxLength) {
  11849. return generatedPassword
  11850. }
  11851. var longDivision = quotient.divmod(setOfCharacters.length);
  11852. generatedPassword += setOfCharacters[longDivision.remainder];
  11853. return consumeEntropy(generatedPassword, longDivision.quotient, setOfCharacters, maxLength)
  11854. }
  11855. function renderPassword(entropy, setOfCharacters, passwordProfile) {
  11856. var _passwordProfile = passwordProfile !== undefined ? passwordProfile : {};
  11857. var length = _passwordProfile.length || 14;
  11858. return consumeEntropy('', bigInt(entropy, 16), setOfCharacters, length);
  11859. }
  11860. },{"big-integer":3,"bluebird":4,"pbkdf2":19}]},{},[1])(1)
  11861. });