You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693
  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. _consumeEntropy: v2._consumeEntropy,
  18. _getSetOfCharacters: v2._getSetOfCharacters,
  19. _numberSubsetsOfChars: v2._numberSubsetsOfChars,
  20. _includeOneCharPerSetOfCharacters: v2._includeOneCharPerSetOfCharacters,
  21. _generateOneCharPerSetOfCharacters: v2._generateOneCharPerSetOfCharacters,
  22. _renderPassword: v2._renderPassword,
  23. };
  24. },{"./src/v1":46,"./src/v2":47}],2:[function(require,module,exports){
  25. 'use strict'
  26. exports.byteLength = byteLength
  27. exports.toByteArray = toByteArray
  28. exports.fromByteArray = fromByteArray
  29. var lookup = []
  30. var revLookup = []
  31. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  32. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  33. for (var i = 0, len = code.length; i < len; ++i) {
  34. lookup[i] = code[i]
  35. revLookup[code.charCodeAt(i)] = i
  36. }
  37. revLookup['-'.charCodeAt(0)] = 62
  38. revLookup['_'.charCodeAt(0)] = 63
  39. function placeHoldersCount (b64) {
  40. var len = b64.length
  41. if (len % 4 > 0) {
  42. throw new Error('Invalid string. Length must be a multiple of 4')
  43. }
  44. // the number of equal signs (place holders)
  45. // if there are two placeholders, than the two characters before it
  46. // represent one byte
  47. // if there is only one, then the three characters before it represent 2 bytes
  48. // this is just a cheap hack to not do indexOf twice
  49. return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
  50. }
  51. function byteLength (b64) {
  52. // base64 is 4/3 + up to two characters of the original data
  53. return b64.length * 3 / 4 - placeHoldersCount(b64)
  54. }
  55. function toByteArray (b64) {
  56. var i, j, l, tmp, placeHolders, arr
  57. var len = b64.length
  58. placeHolders = placeHoldersCount(b64)
  59. arr = new Arr(len * 3 / 4 - placeHolders)
  60. // if there are placeholders, only get up to the last complete 4 chars
  61. l = placeHolders > 0 ? len - 4 : len
  62. var L = 0
  63. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  64. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
  65. arr[L++] = (tmp >> 16) & 0xFF
  66. arr[L++] = (tmp >> 8) & 0xFF
  67. arr[L++] = tmp & 0xFF
  68. }
  69. if (placeHolders === 2) {
  70. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
  71. arr[L++] = tmp & 0xFF
  72. } else if (placeHolders === 1) {
  73. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
  74. arr[L++] = (tmp >> 8) & 0xFF
  75. arr[L++] = tmp & 0xFF
  76. }
  77. return arr
  78. }
  79. function tripletToBase64 (num) {
  80. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  81. }
  82. function encodeChunk (uint8, start, end) {
  83. var tmp
  84. var output = []
  85. for (var i = start; i < end; i += 3) {
  86. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  87. output.push(tripletToBase64(tmp))
  88. }
  89. return output.join('')
  90. }
  91. function fromByteArray (uint8) {
  92. var tmp
  93. var len = uint8.length
  94. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  95. var output = ''
  96. var parts = []
  97. var maxChunkLength = 16383 // must be multiple of 3
  98. // go through the array every three bytes, we'll deal with trailing stuff later
  99. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  100. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  101. }
  102. // pad the end with zeros, but make sure to not forget the extra bytes
  103. if (extraBytes === 1) {
  104. tmp = uint8[len - 1]
  105. output += lookup[tmp >> 2]
  106. output += lookup[(tmp << 4) & 0x3F]
  107. output += '=='
  108. } else if (extraBytes === 2) {
  109. tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
  110. output += lookup[tmp >> 10]
  111. output += lookup[(tmp >> 4) & 0x3F]
  112. output += lookup[(tmp << 2) & 0x3F]
  113. output += '='
  114. }
  115. parts.push(output)
  116. return parts.join('')
  117. }
  118. },{}],3:[function(require,module,exports){
  119. var bigInt = (function (undefined) {
  120. "use strict";
  121. var BASE = 1e7,
  122. LOG_BASE = 7,
  123. MAX_INT = 9007199254740992,
  124. MAX_INT_ARR = smallToArray(MAX_INT),
  125. LOG_MAX_INT = Math.log(MAX_INT);
  126. function Integer(v, radix) {
  127. if (typeof v === "undefined") return Integer[0];
  128. if (typeof radix !== "undefined") return +radix === 10 ? parseValue(v) : parseBase(v, radix);
  129. return parseValue(v);
  130. }
  131. function BigInteger(value, sign) {
  132. this.value = value;
  133. this.sign = sign;
  134. this.isSmall = false;
  135. }
  136. BigInteger.prototype = Object.create(Integer.prototype);
  137. function SmallInteger(value) {
  138. this.value = value;
  139. this.sign = value < 0;
  140. this.isSmall = true;
  141. }
  142. SmallInteger.prototype = Object.create(Integer.prototype);
  143. function isPrecise(n) {
  144. return -MAX_INT < n && n < MAX_INT;
  145. }
  146. function smallToArray(n) { // For performance reasons doesn't reference BASE, need to change this function if BASE changes
  147. if (n < 1e7)
  148. return [n];
  149. if (n < 1e14)
  150. return [n % 1e7, Math.floor(n / 1e7)];
  151. return [n % 1e7, Math.floor(n / 1e7) % 1e7, Math.floor(n / 1e14)];
  152. }
  153. function arrayToSmall(arr) { // If BASE changes this function may need to change
  154. trim(arr);
  155. var length = arr.length;
  156. if (length < 4 && compareAbs(arr, MAX_INT_ARR) < 0) {
  157. switch (length) {
  158. case 0: return 0;
  159. case 1: return arr[0];
  160. case 2: return arr[0] + arr[1] * BASE;
  161. default: return arr[0] + (arr[1] + arr[2] * BASE) * BASE;
  162. }
  163. }
  164. return arr;
  165. }
  166. function trim(v) {
  167. var i = v.length;
  168. while (v[--i] === 0);
  169. v.length = i + 1;
  170. }
  171. function createArray(length) { // function shamelessly stolen from Yaffle's library https://github.com/Yaffle/BigInteger
  172. var x = new Array(length);
  173. var i = -1;
  174. while (++i < length) {
  175. x[i] = 0;
  176. }
  177. return x;
  178. }
  179. function truncate(n) {
  180. if (n > 0) return Math.floor(n);
  181. return Math.ceil(n);
  182. }
  183. function add(a, b) { // assumes a and b are arrays with a.length >= b.length
  184. var l_a = a.length,
  185. l_b = b.length,
  186. r = new Array(l_a),
  187. carry = 0,
  188. base = BASE,
  189. sum, i;
  190. for (i = 0; i < l_b; i++) {
  191. sum = a[i] + b[i] + carry;
  192. carry = sum >= base ? 1 : 0;
  193. r[i] = sum - carry * base;
  194. }
  195. while (i < l_a) {
  196. sum = a[i] + carry;
  197. carry = sum === base ? 1 : 0;
  198. r[i++] = sum - carry * base;
  199. }
  200. if (carry > 0) r.push(carry);
  201. return r;
  202. }
  203. function addAny(a, b) {
  204. if (a.length >= b.length) return add(a, b);
  205. return add(b, a);
  206. }
  207. function addSmall(a, carry) { // assumes a is array, carry is number with 0 <= carry < MAX_INT
  208. var l = a.length,
  209. r = new Array(l),
  210. base = BASE,
  211. sum, i;
  212. for (i = 0; i < l; i++) {
  213. sum = a[i] - base + carry;
  214. carry = Math.floor(sum / base);
  215. r[i] = sum - carry * base;
  216. carry += 1;
  217. }
  218. while (carry > 0) {
  219. r[i++] = carry % base;
  220. carry = Math.floor(carry / base);
  221. }
  222. return r;
  223. }
  224. BigInteger.prototype.add = function (v) {
  225. var value, n = parseValue(v);
  226. if (this.sign !== n.sign) {
  227. return this.subtract(n.negate());
  228. }
  229. var a = this.value, b = n.value;
  230. if (n.isSmall) {
  231. return new BigInteger(addSmall(a, Math.abs(b)), this.sign);
  232. }
  233. return new BigInteger(addAny(a, b), this.sign);
  234. };
  235. BigInteger.prototype.plus = BigInteger.prototype.add;
  236. SmallInteger.prototype.add = function (v) {
  237. var n = parseValue(v);
  238. var a = this.value;
  239. if (a < 0 !== n.sign) {
  240. return this.subtract(n.negate());
  241. }
  242. var b = n.value;
  243. if (n.isSmall) {
  244. if (isPrecise(a + b)) return new SmallInteger(a + b);
  245. b = smallToArray(Math.abs(b));
  246. }
  247. return new BigInteger(addSmall(b, Math.abs(a)), a < 0);
  248. };
  249. SmallInteger.prototype.plus = SmallInteger.prototype.add;
  250. function subtract(a, b) { // assumes a and b are arrays with a >= b
  251. var a_l = a.length,
  252. b_l = b.length,
  253. r = new Array(a_l),
  254. borrow = 0,
  255. base = BASE,
  256. i, difference;
  257. for (i = 0; i < b_l; i++) {
  258. difference = a[i] - borrow - b[i];
  259. if (difference < 0) {
  260. difference += base;
  261. borrow = 1;
  262. } else borrow = 0;
  263. r[i] = difference;
  264. }
  265. for (i = b_l; i < a_l; i++) {
  266. difference = a[i] - borrow;
  267. if (difference < 0) difference += base;
  268. else {
  269. r[i++] = difference;
  270. break;
  271. }
  272. r[i] = difference;
  273. }
  274. for (; i < a_l; i++) {
  275. r[i] = a[i];
  276. }
  277. trim(r);
  278. return r;
  279. }
  280. function subtractAny(a, b, sign) {
  281. var value, isSmall;
  282. if (compareAbs(a, b) >= 0) {
  283. value = subtract(a,b);
  284. } else {
  285. value = subtract(b, a);
  286. sign = !sign;
  287. }
  288. value = arrayToSmall(value);
  289. if (typeof value === "number") {
  290. if (sign) value = -value;
  291. return new SmallInteger(value);
  292. }
  293. return new BigInteger(value, sign);
  294. }
  295. function subtractSmall(a, b, sign) { // assumes a is array, b is number with 0 <= b < MAX_INT
  296. var l = a.length,
  297. r = new Array(l),
  298. carry = -b,
  299. base = BASE,
  300. i, difference;
  301. for (i = 0; i < l; i++) {
  302. difference = a[i] + carry;
  303. carry = Math.floor(difference / base);
  304. difference %= base;
  305. r[i] = difference < 0 ? difference + base : difference;
  306. }
  307. r = arrayToSmall(r);
  308. if (typeof r === "number") {
  309. if (sign) r = -r;
  310. return new SmallInteger(r);
  311. } return new BigInteger(r, sign);
  312. }
  313. BigInteger.prototype.subtract = function (v) {
  314. var n = parseValue(v);
  315. if (this.sign !== n.sign) {
  316. return this.add(n.negate());
  317. }
  318. var a = this.value, b = n.value;
  319. if (n.isSmall)
  320. return subtractSmall(a, Math.abs(b), this.sign);
  321. return subtractAny(a, b, this.sign);
  322. };
  323. BigInteger.prototype.minus = BigInteger.prototype.subtract;
  324. SmallInteger.prototype.subtract = function (v) {
  325. var n = parseValue(v);
  326. var a = this.value;
  327. if (a < 0 !== n.sign) {
  328. return this.add(n.negate());
  329. }
  330. var b = n.value;
  331. if (n.isSmall) {
  332. return new SmallInteger(a - b);
  333. }
  334. return subtractSmall(b, Math.abs(a), a >= 0);
  335. };
  336. SmallInteger.prototype.minus = SmallInteger.prototype.subtract;
  337. BigInteger.prototype.negate = function () {
  338. return new BigInteger(this.value, !this.sign);
  339. };
  340. SmallInteger.prototype.negate = function () {
  341. var sign = this.sign;
  342. var small = new SmallInteger(-this.value);
  343. small.sign = !sign;
  344. return small;
  345. };
  346. BigInteger.prototype.abs = function () {
  347. return new BigInteger(this.value, false);
  348. };
  349. SmallInteger.prototype.abs = function () {
  350. return new SmallInteger(Math.abs(this.value));
  351. };
  352. function multiplyLong(a, b) {
  353. var a_l = a.length,
  354. b_l = b.length,
  355. l = a_l + b_l,
  356. r = createArray(l),
  357. base = BASE,
  358. product, carry, i, a_i, b_j;
  359. for (i = 0; i < a_l; ++i) {
  360. a_i = a[i];
  361. for (var j = 0; j < b_l; ++j) {
  362. b_j = b[j];
  363. product = a_i * b_j + r[i + j];
  364. carry = Math.floor(product / base);
  365. r[i + j] = product - carry * base;
  366. r[i + j + 1] += carry;
  367. }
  368. }
  369. trim(r);
  370. return r;
  371. }
  372. function multiplySmall(a, b) { // assumes a is array, b is number with |b| < BASE
  373. var l = a.length,
  374. r = new Array(l),
  375. base = BASE,
  376. carry = 0,
  377. product, i;
  378. for (i = 0; i < l; i++) {
  379. product = a[i] * b + carry;
  380. carry = Math.floor(product / base);
  381. r[i] = product - carry * base;
  382. }
  383. while (carry > 0) {
  384. r[i++] = carry % base;
  385. carry = Math.floor(carry / base);
  386. }
  387. return r;
  388. }
  389. function shiftLeft(x, n) {
  390. var r = [];
  391. while (n-- > 0) r.push(0);
  392. return r.concat(x);
  393. }
  394. function multiplyKaratsuba(x, y) {
  395. var n = Math.max(x.length, y.length);
  396. if (n <= 30) return multiplyLong(x, y);
  397. n = Math.ceil(n / 2);
  398. var b = x.slice(n),
  399. a = x.slice(0, n),
  400. d = y.slice(n),
  401. c = y.slice(0, n);
  402. var ac = multiplyKaratsuba(a, c),
  403. bd = multiplyKaratsuba(b, d),
  404. abcd = multiplyKaratsuba(addAny(a, b), addAny(c, d));
  405. var product = addAny(addAny(ac, shiftLeft(subtract(subtract(abcd, ac), bd), n)), shiftLeft(bd, 2 * n));
  406. trim(product);
  407. return product;
  408. }
  409. // The following function is derived from a surface fit of a graph plotting the performance difference
  410. // between long multiplication and karatsuba multiplication versus the lengths of the two arrays.
  411. function useKaratsuba(l1, l2) {
  412. return -0.012 * l1 - 0.012 * l2 + 0.000015 * l1 * l2 > 0;
  413. }
  414. BigInteger.prototype.multiply = function (v) {
  415. var value, n = parseValue(v),
  416. a = this.value, b = n.value,
  417. sign = this.sign !== n.sign,
  418. abs;
  419. if (n.isSmall) {
  420. if (b === 0) return Integer[0];
  421. if (b === 1) return this;
  422. if (b === -1) return this.negate();
  423. abs = Math.abs(b);
  424. if (abs < BASE) {
  425. return new BigInteger(multiplySmall(a, abs), sign);
  426. }
  427. b = smallToArray(abs);
  428. }
  429. if (useKaratsuba(a.length, b.length)) // Karatsuba is only faster for certain array sizes
  430. return new BigInteger(multiplyKaratsuba(a, b), sign);
  431. return new BigInteger(multiplyLong(a, b), sign);
  432. };
  433. BigInteger.prototype.times = BigInteger.prototype.multiply;
  434. function multiplySmallAndArray(a, b, sign) { // a >= 0
  435. if (a < BASE) {
  436. return new BigInteger(multiplySmall(b, a), sign);
  437. }
  438. return new BigInteger(multiplyLong(b, smallToArray(a)), sign);
  439. }
  440. SmallInteger.prototype._multiplyBySmall = function (a) {
  441. if (isPrecise(a.value * this.value)) {
  442. return new SmallInteger(a.value * this.value);
  443. }
  444. return multiplySmallAndArray(Math.abs(a.value), smallToArray(Math.abs(this.value)), this.sign !== a.sign);
  445. };
  446. BigInteger.prototype._multiplyBySmall = function (a) {
  447. if (a.value === 0) return Integer[0];
  448. if (a.value === 1) return this;
  449. if (a.value === -1) return this.negate();
  450. return multiplySmallAndArray(Math.abs(a.value), this.value, this.sign !== a.sign);
  451. };
  452. SmallInteger.prototype.multiply = function (v) {
  453. return parseValue(v)._multiplyBySmall(this);
  454. };
  455. SmallInteger.prototype.times = SmallInteger.prototype.multiply;
  456. function square(a) {
  457. var l = a.length,
  458. r = createArray(l + l),
  459. base = BASE,
  460. product, carry, i, a_i, a_j;
  461. for (i = 0; i < l; i++) {
  462. a_i = a[i];
  463. for (var j = 0; j < l; j++) {
  464. a_j = a[j];
  465. product = a_i * a_j + r[i + j];
  466. carry = Math.floor(product / base);
  467. r[i + j] = product - carry * base;
  468. r[i + j + 1] += carry;
  469. }
  470. }
  471. trim(r);
  472. return r;
  473. }
  474. BigInteger.prototype.square = function () {
  475. return new BigInteger(square(this.value), false);
  476. };
  477. SmallInteger.prototype.square = function () {
  478. var value = this.value * this.value;
  479. if (isPrecise(value)) return new SmallInteger(value);
  480. return new BigInteger(square(smallToArray(Math.abs(this.value))), false);
  481. };
  482. function divMod1(a, b) { // Left over from previous version. Performs faster than divMod2 on smaller input sizes.
  483. var a_l = a.length,
  484. b_l = b.length,
  485. base = BASE,
  486. result = createArray(b.length),
  487. divisorMostSignificantDigit = b[b_l - 1],
  488. // normalization
  489. lambda = Math.ceil(base / (2 * divisorMostSignificantDigit)),
  490. remainder = multiplySmall(a, lambda),
  491. divisor = multiplySmall(b, lambda),
  492. quotientDigit, shift, carry, borrow, i, l, q;
  493. if (remainder.length <= a_l) remainder.push(0);
  494. divisor.push(0);
  495. divisorMostSignificantDigit = divisor[b_l - 1];
  496. for (shift = a_l - b_l; shift >= 0; shift--) {
  497. quotientDigit = base - 1;
  498. if (remainder[shift + b_l] !== divisorMostSignificantDigit) {
  499. quotientDigit = Math.floor((remainder[shift + b_l] * base + remainder[shift + b_l - 1]) / divisorMostSignificantDigit);
  500. }
  501. // quotientDigit <= base - 1
  502. carry = 0;
  503. borrow = 0;
  504. l = divisor.length;
  505. for (i = 0; i < l; i++) {
  506. carry += quotientDigit * divisor[i];
  507. q = Math.floor(carry / base);
  508. borrow += remainder[shift + i] - (carry - q * base);
  509. carry = q;
  510. if (borrow < 0) {
  511. remainder[shift + i] = borrow + base;
  512. borrow = -1;
  513. } else {
  514. remainder[shift + i] = borrow;
  515. borrow = 0;
  516. }
  517. }
  518. while (borrow !== 0) {
  519. quotientDigit -= 1;
  520. carry = 0;
  521. for (i = 0; i < l; i++) {
  522. carry += remainder[shift + i] - base + divisor[i];
  523. if (carry < 0) {
  524. remainder[shift + i] = carry + base;
  525. carry = 0;
  526. } else {
  527. remainder[shift + i] = carry;
  528. carry = 1;
  529. }
  530. }
  531. borrow += carry;
  532. }
  533. result[shift] = quotientDigit;
  534. }
  535. // denormalization
  536. remainder = divModSmall(remainder, lambda)[0];
  537. return [arrayToSmall(result), arrayToSmall(remainder)];
  538. }
  539. function divMod2(a, b) { // Implementation idea shamelessly stolen from Silent Matt's library http://silentmatt.com/biginteger/
  540. // Performs faster than divMod1 on larger input sizes.
  541. var a_l = a.length,
  542. b_l = b.length,
  543. result = [],
  544. part = [],
  545. base = BASE,
  546. guess, xlen, highx, highy, check;
  547. while (a_l) {
  548. part.unshift(a[--a_l]);
  549. if (compareAbs(part, b) < 0) {
  550. result.push(0);
  551. continue;
  552. }
  553. xlen = part.length;
  554. highx = part[xlen - 1] * base + part[xlen - 2];
  555. highy = b[b_l - 1] * base + b[b_l - 2];
  556. if (xlen > b_l) {
  557. highx = (highx + 1) * base;
  558. }
  559. guess = Math.ceil(highx / highy);
  560. do {
  561. check = multiplySmall(b, guess);
  562. if (compareAbs(check, part) <= 0) break;
  563. guess--;
  564. } while (guess);
  565. result.push(guess);
  566. part = subtract(part, check);
  567. }
  568. result.reverse();
  569. return [arrayToSmall(result), arrayToSmall(part)];
  570. }
  571. function divModSmall(value, lambda) {
  572. var length = value.length,
  573. quotient = createArray(length),
  574. base = BASE,
  575. i, q, remainder, divisor;
  576. remainder = 0;
  577. for (i = length - 1; i >= 0; --i) {
  578. divisor = remainder * base + value[i];
  579. q = truncate(divisor / lambda);
  580. remainder = divisor - q * lambda;
  581. quotient[i] = q | 0;
  582. }
  583. return [quotient, remainder | 0];
  584. }
  585. function divModAny(self, v) {
  586. var value, n = parseValue(v);
  587. var a = self.value, b = n.value;
  588. var quotient;
  589. if (b === 0) throw new Error("Cannot divide by zero");
  590. if (self.isSmall) {
  591. if (n.isSmall) {
  592. return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)];
  593. }
  594. return [Integer[0], self];
  595. }
  596. if (n.isSmall) {
  597. if (b === 1) return [self, Integer[0]];
  598. if (b == -1) return [self.negate(), Integer[0]];
  599. var abs = Math.abs(b);
  600. if (abs < BASE) {
  601. value = divModSmall(a, abs);
  602. quotient = arrayToSmall(value[0]);
  603. var remainder = value[1];
  604. if (self.sign) remainder = -remainder;
  605. if (typeof quotient === "number") {
  606. if (self.sign !== n.sign) quotient = -quotient;
  607. return [new SmallInteger(quotient), new SmallInteger(remainder)];
  608. }
  609. return [new BigInteger(quotient, self.sign !== n.sign), new SmallInteger(remainder)];
  610. }
  611. b = smallToArray(abs);
  612. }
  613. var comparison = compareAbs(a, b);
  614. if (comparison === -1) return [Integer[0], self];
  615. if (comparison === 0) return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]];
  616. // divMod1 is faster on smaller input sizes
  617. if (a.length + b.length <= 200)
  618. value = divMod1(a, b);
  619. else value = divMod2(a, b);
  620. quotient = value[0];
  621. var qSign = self.sign !== n.sign,
  622. mod = value[1],
  623. mSign = self.sign;
  624. if (typeof quotient === "number") {
  625. if (qSign) quotient = -quotient;
  626. quotient = new SmallInteger(quotient);
  627. } else quotient = new BigInteger(quotient, qSign);
  628. if (typeof mod === "number") {
  629. if (mSign) mod = -mod;
  630. mod = new SmallInteger(mod);
  631. } else mod = new BigInteger(mod, mSign);
  632. return [quotient, mod];
  633. }
  634. BigInteger.prototype.divmod = function (v) {
  635. var result = divModAny(this, v);
  636. return {
  637. quotient: result[0],
  638. remainder: result[1]
  639. };
  640. };
  641. SmallInteger.prototype.divmod = BigInteger.prototype.divmod;
  642. BigInteger.prototype.divide = function (v) {
  643. return divModAny(this, v)[0];
  644. };
  645. SmallInteger.prototype.over = SmallInteger.prototype.divide = BigInteger.prototype.over = BigInteger.prototype.divide;
  646. BigInteger.prototype.mod = function (v) {
  647. return divModAny(this, v)[1];
  648. };
  649. SmallInteger.prototype.remainder = SmallInteger.prototype.mod = BigInteger.prototype.remainder = BigInteger.prototype.mod;
  650. BigInteger.prototype.pow = function (v) {
  651. var n = parseValue(v),
  652. a = this.value,
  653. b = n.value,
  654. value, x, y;
  655. if (b === 0) return Integer[1];
  656. if (a === 0) return Integer[0];
  657. if (a === 1) return Integer[1];
  658. if (a === -1) return n.isEven() ? Integer[1] : Integer[-1];
  659. if (n.sign) {
  660. return Integer[0];
  661. }
  662. if (!n.isSmall) throw new Error("The exponent " + n.toString() + " is too large.");
  663. if (this.isSmall) {
  664. if (isPrecise(value = Math.pow(a, b)))
  665. return new SmallInteger(truncate(value));
  666. }
  667. x = this;
  668. y = Integer[1];
  669. while (true) {
  670. if (b & 1 === 1) {
  671. y = y.times(x);
  672. --b;
  673. }
  674. if (b === 0) break;
  675. b /= 2;
  676. x = x.square();
  677. }
  678. return y;
  679. };
  680. SmallInteger.prototype.pow = BigInteger.prototype.pow;
  681. BigInteger.prototype.modPow = function (exp, mod) {
  682. exp = parseValue(exp);
  683. mod = parseValue(mod);
  684. if (mod.isZero()) throw new Error("Cannot take modPow with modulus 0");
  685. var r = Integer[1],
  686. base = this.mod(mod);
  687. while (exp.isPositive()) {
  688. if (base.isZero()) return Integer[0];
  689. if (exp.isOdd()) r = r.multiply(base).mod(mod);
  690. exp = exp.divide(2);
  691. base = base.square().mod(mod);
  692. }
  693. return r;
  694. };
  695. SmallInteger.prototype.modPow = BigInteger.prototype.modPow;
  696. function compareAbs(a, b) {
  697. if (a.length !== b.length) {
  698. return a.length > b.length ? 1 : -1;
  699. }
  700. for (var i = a.length - 1; i >= 0; i--) {
  701. if (a[i] !== b[i]) return a[i] > b[i] ? 1 : -1;
  702. }
  703. return 0;
  704. }
  705. BigInteger.prototype.compareAbs = function (v) {
  706. var n = parseValue(v),
  707. a = this.value,
  708. b = n.value;
  709. if (n.isSmall) return 1;
  710. return compareAbs(a, b);
  711. };
  712. SmallInteger.prototype.compareAbs = function (v) {
  713. var n = parseValue(v),
  714. a = Math.abs(this.value),
  715. b = n.value;
  716. if (n.isSmall) {
  717. b = Math.abs(b);
  718. return a === b ? 0 : a > b ? 1 : -1;
  719. }
  720. return -1;
  721. };
  722. BigInteger.prototype.compare = function (v) {
  723. // See discussion about comparison with Infinity:
  724. // https://github.com/peterolson/BigInteger.js/issues/61
  725. if (v === Infinity) {
  726. return -1;
  727. }
  728. if (v === -Infinity) {
  729. return 1;
  730. }
  731. var n = parseValue(v),
  732. a = this.value,
  733. b = n.value;
  734. if (this.sign !== n.sign) {
  735. return n.sign ? 1 : -1;
  736. }
  737. if (n.isSmall) {
  738. return this.sign ? -1 : 1;
  739. }
  740. return compareAbs(a, b) * (this.sign ? -1 : 1);
  741. };
  742. BigInteger.prototype.compareTo = BigInteger.prototype.compare;
  743. SmallInteger.prototype.compare = function (v) {
  744. if (v === Infinity) {
  745. return -1;
  746. }
  747. if (v === -Infinity) {
  748. return 1;
  749. }
  750. var n = parseValue(v),
  751. a = this.value,
  752. b = n.value;
  753. if (n.isSmall) {
  754. return a == b ? 0 : a > b ? 1 : -1;
  755. }
  756. if (a < 0 !== n.sign) {
  757. return a < 0 ? -1 : 1;
  758. }
  759. return a < 0 ? 1 : -1;
  760. };
  761. SmallInteger.prototype.compareTo = SmallInteger.prototype.compare;
  762. BigInteger.prototype.equals = function (v) {
  763. return this.compare(v) === 0;
  764. };
  765. SmallInteger.prototype.eq = SmallInteger.prototype.equals = BigInteger.prototype.eq = BigInteger.prototype.equals;
  766. BigInteger.prototype.notEquals = function (v) {
  767. return this.compare(v) !== 0;
  768. };
  769. SmallInteger.prototype.neq = SmallInteger.prototype.notEquals = BigInteger.prototype.neq = BigInteger.prototype.notEquals;
  770. BigInteger.prototype.greater = function (v) {
  771. return this.compare(v) > 0;
  772. };
  773. SmallInteger.prototype.gt = SmallInteger.prototype.greater = BigInteger.prototype.gt = BigInteger.prototype.greater;
  774. BigInteger.prototype.lesser = function (v) {
  775. return this.compare(v) < 0;
  776. };
  777. SmallInteger.prototype.lt = SmallInteger.prototype.lesser = BigInteger.prototype.lt = BigInteger.prototype.lesser;
  778. BigInteger.prototype.greaterOrEquals = function (v) {
  779. return this.compare(v) >= 0;
  780. };
  781. SmallInteger.prototype.geq = SmallInteger.prototype.greaterOrEquals = BigInteger.prototype.geq = BigInteger.prototype.greaterOrEquals;
  782. BigInteger.prototype.lesserOrEquals = function (v) {
  783. return this.compare(v) <= 0;
  784. };
  785. SmallInteger.prototype.leq = SmallInteger.prototype.lesserOrEquals = BigInteger.prototype.leq = BigInteger.prototype.lesserOrEquals;
  786. BigInteger.prototype.isEven = function () {
  787. return (this.value[0] & 1) === 0;
  788. };
  789. SmallInteger.prototype.isEven = function () {
  790. return (this.value & 1) === 0;
  791. };
  792. BigInteger.prototype.isOdd = function () {
  793. return (this.value[0] & 1) === 1;
  794. };
  795. SmallInteger.prototype.isOdd = function () {
  796. return (this.value & 1) === 1;
  797. };
  798. BigInteger.prototype.isPositive = function () {
  799. return !this.sign;
  800. };
  801. SmallInteger.prototype.isPositive = function () {
  802. return this.value > 0;
  803. };
  804. BigInteger.prototype.isNegative = function () {
  805. return this.sign;
  806. };
  807. SmallInteger.prototype.isNegative = function () {
  808. return this.value < 0;
  809. };
  810. BigInteger.prototype.isUnit = function () {
  811. return false;
  812. };
  813. SmallInteger.prototype.isUnit = function () {
  814. return Math.abs(this.value) === 1;
  815. };
  816. BigInteger.prototype.isZero = function () {
  817. return false;
  818. };
  819. SmallInteger.prototype.isZero = function () {
  820. return this.value === 0;
  821. };
  822. BigInteger.prototype.isDivisibleBy = function (v) {
  823. var n = parseValue(v);
  824. var value = n.value;
  825. if (value === 0) return false;
  826. if (value === 1) return true;
  827. if (value === 2) return this.isEven();
  828. return this.mod(n).equals(Integer[0]);
  829. };
  830. SmallInteger.prototype.isDivisibleBy = BigInteger.prototype.isDivisibleBy;
  831. function isBasicPrime(v) {
  832. var n = v.abs();
  833. if (n.isUnit()) return false;
  834. if (n.equals(2) || n.equals(3) || n.equals(5)) return true;
  835. if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false;
  836. if (n.lesser(25)) return true;
  837. // we don't know if it's prime: let the other functions figure it out
  838. }
  839. BigInteger.prototype.isPrime = function () {
  840. var isPrime = isBasicPrime(this);
  841. if (isPrime !== undefined) return isPrime;
  842. var n = this.abs(),
  843. nPrev = n.prev();
  844. var a = [2, 3, 5, 7, 11, 13, 17, 19],
  845. b = nPrev,
  846. d, t, i, x;
  847. while (b.isEven()) b = b.divide(2);
  848. for (i = 0; i < a.length; i++) {
  849. x = bigInt(a[i]).modPow(b, n);
  850. if (x.equals(Integer[1]) || x.equals(nPrev)) continue;
  851. for (t = true, d = b; t && d.lesser(nPrev) ; d = d.multiply(2)) {
  852. x = x.square().mod(n);
  853. if (x.equals(nPrev)) t = false;
  854. }
  855. if (t) return false;
  856. }
  857. return true;
  858. };
  859. SmallInteger.prototype.isPrime = BigInteger.prototype.isPrime;
  860. BigInteger.prototype.isProbablePrime = function (iterations) {
  861. var isPrime = isBasicPrime(this);
  862. if (isPrime !== undefined) return isPrime;
  863. var n = this.abs();
  864. var t = iterations === undefined ? 5 : iterations;
  865. // use the Fermat primality test
  866. for (var i = 0; i < t; i++) {
  867. var a = bigInt.randBetween(2, n.minus(2));
  868. if (!a.modPow(n.prev(), n).isUnit()) return false; // definitely composite
  869. }
  870. return true; // large chance of being prime
  871. };
  872. SmallInteger.prototype.isProbablePrime = BigInteger.prototype.isProbablePrime;
  873. BigInteger.prototype.modInv = function (n) {
  874. var t = bigInt.zero, newT = bigInt.one, r = parseValue(n), newR = this.abs(), q, lastT, lastR;
  875. while (!newR.equals(bigInt.zero)) {
  876. q = r.divide(newR);
  877. lastT = t;
  878. lastR = r;
  879. t = newT;
  880. r = newR;
  881. newT = lastT.subtract(q.multiply(newT));
  882. newR = lastR.subtract(q.multiply(newR));
  883. }
  884. if (!r.equals(1)) throw new Error(this.toString() + " and " + n.toString() + " are not co-prime");
  885. if (t.compare(0) === -1) {
  886. t = t.add(n);
  887. }
  888. return t;
  889. }
  890. SmallInteger.prototype.modInv = BigInteger.prototype.modInv;
  891. BigInteger.prototype.next = function () {
  892. var value = this.value;
  893. if (this.sign) {
  894. return subtractSmall(value, 1, this.sign);
  895. }
  896. return new BigInteger(addSmall(value, 1), this.sign);
  897. };
  898. SmallInteger.prototype.next = function () {
  899. var value = this.value;
  900. if (value + 1 < MAX_INT) return new SmallInteger(value + 1);
  901. return new BigInteger(MAX_INT_ARR, false);
  902. };
  903. BigInteger.prototype.prev = function () {
  904. var value = this.value;
  905. if (this.sign) {
  906. return new BigInteger(addSmall(value, 1), true);
  907. }
  908. return subtractSmall(value, 1, this.sign);
  909. };
  910. SmallInteger.prototype.prev = function () {
  911. var value = this.value;
  912. if (value - 1 > -MAX_INT) return new SmallInteger(value - 1);
  913. return new BigInteger(MAX_INT_ARR, true);
  914. };
  915. var powersOfTwo = [1];
  916. while (powersOfTwo[powersOfTwo.length - 1] <= BASE) powersOfTwo.push(2 * powersOfTwo[powersOfTwo.length - 1]);
  917. var powers2Length = powersOfTwo.length, highestPower2 = powersOfTwo[powers2Length - 1];
  918. function shift_isSmall(n) {
  919. return ((typeof n === "number" || typeof n === "string") && +Math.abs(n) <= BASE) ||
  920. (n instanceof BigInteger && n.value.length <= 1);
  921. }
  922. BigInteger.prototype.shiftLeft = function (n) {
  923. if (!shift_isSmall(n)) {
  924. throw new Error(String(n) + " is too large for shifting.");
  925. }
  926. n = +n;
  927. if (n < 0) return this.shiftRight(-n);
  928. var result = this;
  929. while (n >= powers2Length) {
  930. result = result.multiply(highestPower2);
  931. n -= powers2Length - 1;
  932. }
  933. return result.multiply(powersOfTwo[n]);
  934. };
  935. SmallInteger.prototype.shiftLeft = BigInteger.prototype.shiftLeft;
  936. BigInteger.prototype.shiftRight = function (n) {
  937. var remQuo;
  938. if (!shift_isSmall(n)) {
  939. throw new Error(String(n) + " is too large for shifting.");
  940. }
  941. n = +n;
  942. if (n < 0) return this.shiftLeft(-n);
  943. var result = this;
  944. while (n >= powers2Length) {
  945. if (result.isZero()) return result;
  946. remQuo = divModAny(result, highestPower2);
  947. result = remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];
  948. n -= powers2Length - 1;
  949. }
  950. remQuo = divModAny(result, powersOfTwo[n]);
  951. return remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];
  952. };
  953. SmallInteger.prototype.shiftRight = BigInteger.prototype.shiftRight;
  954. function bitwise(x, y, fn) {
  955. y = parseValue(y);
  956. var xSign = x.isNegative(), ySign = y.isNegative();
  957. var xRem = xSign ? x.not() : x,
  958. yRem = ySign ? y.not() : y;
  959. var xBits = [], yBits = [];
  960. var xStop = false, yStop = false;
  961. while (!xStop || !yStop) {
  962. if (xRem.isZero()) { // virtual sign extension for simulating two's complement
  963. xStop = true;
  964. xBits.push(xSign ? 1 : 0);
  965. }
  966. else if (xSign) xBits.push(xRem.isEven() ? 1 : 0); // two's complement for negative numbers
  967. else xBits.push(xRem.isEven() ? 0 : 1);
  968. if (yRem.isZero()) {
  969. yStop = true;
  970. yBits.push(ySign ? 1 : 0);
  971. }
  972. else if (ySign) yBits.push(yRem.isEven() ? 1 : 0);
  973. else yBits.push(yRem.isEven() ? 0 : 1);
  974. xRem = xRem.over(2);
  975. yRem = yRem.over(2);
  976. }
  977. var result = [];
  978. for (var i = 0; i < xBits.length; i++) result.push(fn(xBits[i], yBits[i]));
  979. var sum = bigInt(result.pop()).negate().times(bigInt(2).pow(result.length));
  980. while (result.length) {
  981. sum = sum.add(bigInt(result.pop()).times(bigInt(2).pow(result.length)));
  982. }
  983. return sum;
  984. }
  985. BigInteger.prototype.not = function () {
  986. return this.negate().prev();
  987. };
  988. SmallInteger.prototype.not = BigInteger.prototype.not;
  989. BigInteger.prototype.and = function (n) {
  990. return bitwise(this, n, function (a, b) { return a & b; });
  991. };
  992. SmallInteger.prototype.and = BigInteger.prototype.and;
  993. BigInteger.prototype.or = function (n) {
  994. return bitwise(this, n, function (a, b) { return a | b; });
  995. };
  996. SmallInteger.prototype.or = BigInteger.prototype.or;
  997. BigInteger.prototype.xor = function (n) {
  998. return bitwise(this, n, function (a, b) { return a ^ b; });
  999. };
  1000. SmallInteger.prototype.xor = BigInteger.prototype.xor;
  1001. var LOBMASK_I = 1 << 30, LOBMASK_BI = (BASE & -BASE) * (BASE & -BASE) | LOBMASK_I;
  1002. function roughLOB(n) { // get lowestOneBit (rough)
  1003. // SmallInteger: return Min(lowestOneBit(n), 1 << 30)
  1004. // BigInteger: return Min(lowestOneBit(n), 1 << 14) [BASE=1e7]
  1005. var v = n.value, x = typeof v === "number" ? v | LOBMASK_I : v[0] + v[1] * BASE | LOBMASK_BI;
  1006. return x & -x;
  1007. }
  1008. function max(a, b) {
  1009. a = parseValue(a);
  1010. b = parseValue(b);
  1011. return a.greater(b) ? a : b;
  1012. }
  1013. function min(a,b) {
  1014. a = parseValue(a);
  1015. b = parseValue(b);
  1016. return a.lesser(b) ? a : b;
  1017. }
  1018. function gcd(a, b) {
  1019. a = parseValue(a).abs();
  1020. b = parseValue(b).abs();
  1021. if (a.equals(b)) return a;
  1022. if (a.isZero()) return b;
  1023. if (b.isZero()) return a;
  1024. var c = Integer[1], d, t;
  1025. while (a.isEven() && b.isEven()) {
  1026. d = Math.min(roughLOB(a), roughLOB(b));
  1027. a = a.divide(d);
  1028. b = b.divide(d);
  1029. c = c.multiply(d);
  1030. }
  1031. while (a.isEven()) {
  1032. a = a.divide(roughLOB(a));
  1033. }
  1034. do {
  1035. while (b.isEven()) {
  1036. b = b.divide(roughLOB(b));
  1037. }
  1038. if (a.greater(b)) {
  1039. t = b; b = a; a = t;
  1040. }
  1041. b = b.subtract(a);
  1042. } while (!b.isZero());
  1043. return c.isUnit() ? a : a.multiply(c);
  1044. }
  1045. function lcm(a, b) {
  1046. a = parseValue(a).abs();
  1047. b = parseValue(b).abs();
  1048. return a.divide(gcd(a, b)).multiply(b);
  1049. }
  1050. function randBetween(a, b) {
  1051. a = parseValue(a);
  1052. b = parseValue(b);
  1053. var low = min(a, b), high = max(a, b);
  1054. var range = high.subtract(low);
  1055. if (range.isSmall) return low.add(Math.round(Math.random() * range));
  1056. var length = range.value.length - 1;
  1057. var result = [], restricted = true;
  1058. for (var i = length; i >= 0; i--) {
  1059. var top = restricted ? range.value[i] : BASE;
  1060. var digit = truncate(Math.random() * top);
  1061. result.unshift(digit);
  1062. if (digit < top) restricted = false;
  1063. }
  1064. result = arrayToSmall(result);
  1065. return low.add(typeof result === "number" ? new SmallInteger(result) : new BigInteger(result, false));
  1066. }
  1067. var parseBase = function (text, base) {
  1068. var val = Integer[0], pow = Integer[1],
  1069. length = text.length;
  1070. if (2 <= base && base <= 36) {
  1071. if (length <= LOG_MAX_INT / Math.log(base)) {
  1072. return new SmallInteger(parseInt(text, base));
  1073. }
  1074. }
  1075. base = parseValue(base);
  1076. var digits = [];
  1077. var i;
  1078. var isNegative = text[0] === "-";
  1079. for (i = isNegative ? 1 : 0; i < text.length; i++) {
  1080. var c = text[i].toLowerCase(),
  1081. charCode = c.charCodeAt(0);
  1082. if (48 <= charCode && charCode <= 57) digits.push(parseValue(c));
  1083. else if (97 <= charCode && charCode <= 122) digits.push(parseValue(c.charCodeAt(0) - 87));
  1084. else if (c === "<") {
  1085. var start = i;
  1086. do { i++; } while (text[i] !== ">");
  1087. digits.push(parseValue(text.slice(start + 1, i)));
  1088. }
  1089. else throw new Error(c + " is not a valid character");
  1090. }
  1091. digits.reverse();
  1092. for (i = 0; i < digits.length; i++) {
  1093. val = val.add(digits[i].times(pow));
  1094. pow = pow.times(base);
  1095. }
  1096. return isNegative ? val.negate() : val;
  1097. };
  1098. function stringify(digit) {
  1099. var v = digit.value;
  1100. if (typeof v === "number") v = [v];
  1101. if (v.length === 1 && v[0] <= 35) {
  1102. return "0123456789abcdefghijklmnopqrstuvwxyz".charAt(v[0]);
  1103. }
  1104. return "<" + v + ">";
  1105. }
  1106. function toBase(n, base) {
  1107. base = bigInt(base);
  1108. if (base.isZero()) {
  1109. if (n.isZero()) return "0";
  1110. throw new Error("Cannot convert nonzero numbers to base 0.");
  1111. }
  1112. if (base.equals(-1)) {
  1113. if (n.isZero()) return "0";
  1114. if (n.isNegative()) return new Array(1 - n).join("10");
  1115. return "1" + new Array(+n).join("01");
  1116. }
  1117. var minusSign = "";
  1118. if (n.isNegative() && base.isPositive()) {
  1119. minusSign = "-";
  1120. n = n.abs();
  1121. }
  1122. if (base.equals(1)) {
  1123. if (n.isZero()) return "0";
  1124. return minusSign + new Array(+n + 1).join(1);
  1125. }
  1126. var out = [];
  1127. var left = n, divmod;
  1128. while (left.isNegative() || left.compareAbs(base) >= 0) {
  1129. divmod = left.divmod(base);
  1130. left = divmod.quotient;
  1131. var digit = divmod.remainder;
  1132. if (digit.isNegative()) {
  1133. digit = base.minus(digit).abs();
  1134. left = left.next();
  1135. }
  1136. out.push(stringify(digit));
  1137. }
  1138. out.push(stringify(left));
  1139. return minusSign + out.reverse().join("");
  1140. }
  1141. BigInteger.prototype.toString = function (radix) {
  1142. if (radix === undefined) radix = 10;
  1143. if (radix !== 10) return toBase(this, radix);
  1144. var v = this.value, l = v.length, str = String(v[--l]), zeros = "0000000", digit;
  1145. while (--l >= 0) {
  1146. digit = String(v[l]);
  1147. str += zeros.slice(digit.length) + digit;
  1148. }
  1149. var sign = this.sign ? "-" : "";
  1150. return sign + str;
  1151. };
  1152. SmallInteger.prototype.toString = function (radix) {
  1153. if (radix === undefined) radix = 10;
  1154. if (radix != 10) return toBase(this, radix);
  1155. return String(this.value);
  1156. };
  1157. BigInteger.prototype.valueOf = function () {
  1158. return +this.toString();
  1159. };
  1160. BigInteger.prototype.toJSNumber = BigInteger.prototype.valueOf;
  1161. SmallInteger.prototype.valueOf = function () {
  1162. return this.value;
  1163. };
  1164. SmallInteger.prototype.toJSNumber = SmallInteger.prototype.valueOf;
  1165. function parseStringValue(v) {
  1166. if (isPrecise(+v)) {
  1167. var x = +v;
  1168. if (x === truncate(x))
  1169. return new SmallInteger(x);
  1170. throw "Invalid integer: " + v;
  1171. }
  1172. var sign = v[0] === "-";
  1173. if (sign) v = v.slice(1);
  1174. var split = v.split(/e/i);
  1175. if (split.length > 2) throw new Error("Invalid integer: " + split.join("e"));
  1176. if (split.length === 2) {
  1177. var exp = split[1];
  1178. if (exp[0] === "+") exp = exp.slice(1);
  1179. exp = +exp;
  1180. if (exp !== truncate(exp) || !isPrecise(exp)) throw new Error("Invalid integer: " + exp + " is not a valid exponent.");
  1181. var text = split[0];
  1182. var decimalPlace = text.indexOf(".");
  1183. if (decimalPlace >= 0) {
  1184. exp -= text.length - decimalPlace - 1;
  1185. text = text.slice(0, decimalPlace) + text.slice(decimalPlace + 1);
  1186. }
  1187. if (exp < 0) throw new Error("Cannot include negative exponent part for integers");
  1188. text += (new Array(exp + 1)).join("0");
  1189. v = text;
  1190. }
  1191. var isValid = /^([0-9][0-9]*)$/.test(v);
  1192. if (!isValid) throw new Error("Invalid integer: " + v);
  1193. var r = [], max = v.length, l = LOG_BASE, min = max - l;
  1194. while (max > 0) {
  1195. r.push(+v.slice(min, max));
  1196. min -= l;
  1197. if (min < 0) min = 0;
  1198. max -= l;
  1199. }
  1200. trim(r);
  1201. return new BigInteger(r, sign);
  1202. }
  1203. function parseNumberValue(v) {
  1204. if (isPrecise(v)) {
  1205. if (v !== truncate(v)) throw new Error(v + " is not an integer.");
  1206. return new SmallInteger(v);
  1207. }
  1208. return parseStringValue(v.toString());
  1209. }
  1210. function parseValue(v) {
  1211. if (typeof v === "number") {
  1212. return parseNumberValue(v);
  1213. }
  1214. if (typeof v === "string") {
  1215. return parseStringValue(v);
  1216. }
  1217. return v;
  1218. }
  1219. // Pre-define numbers in range [-999,999]
  1220. for (var i = 0; i < 1000; i++) {
  1221. Integer[i] = new SmallInteger(i);
  1222. if (i > 0) Integer[-i] = new SmallInteger(-i);
  1223. }
  1224. // Backwards compatibility
  1225. Integer.one = Integer[1];
  1226. Integer.zero = Integer[0];
  1227. Integer.minusOne = Integer[-1];
  1228. Integer.max = max;
  1229. Integer.min = min;
  1230. Integer.gcd = gcd;
  1231. Integer.lcm = lcm;
  1232. Integer.isInstance = function (x) { return x instanceof BigInteger || x instanceof SmallInteger; };
  1233. Integer.randBetween = randBetween;
  1234. return Integer;
  1235. })();
  1236. // Node.js check
  1237. if (typeof module !== "undefined" && module.hasOwnProperty("exports")) {
  1238. module.exports = bigInt;
  1239. }
  1240. },{}],4:[function(require,module,exports){
  1241. (function (process,global){
  1242. /* @preserve
  1243. * The MIT License (MIT)
  1244. *
  1245. * Copyright (c) 2013-2015 Petka Antonov
  1246. *
  1247. * Permission is hereby granted, free of charge, to any person obtaining a copy
  1248. * of this software and associated documentation files (the "Software"), to deal
  1249. * in the Software without restriction, including without limitation the rights
  1250. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  1251. * copies of the Software, and to permit persons to whom the Software is
  1252. * furnished to do so, subject to the following conditions:
  1253. *
  1254. * The above copyright notice and this permission notice shall be included in
  1255. * all copies or substantial portions of the Software.
  1256. *
  1257. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1258. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1259. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  1260. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1261. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1262. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  1263. * THE SOFTWARE.
  1264. *
  1265. */
  1266. /**
  1267. * bluebird build version 3.4.6
  1268. * Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, using, timers, filter, any, each
  1269. */
  1270. !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){
  1271. "use strict";
  1272. module.exports = function(Promise) {
  1273. var SomePromiseArray = Promise._SomePromiseArray;
  1274. function any(promises) {
  1275. var ret = new SomePromiseArray(promises);
  1276. var promise = ret.promise();
  1277. ret.setHowMany(1);
  1278. ret.setUnwrap();
  1279. ret.init();
  1280. return promise;
  1281. }
  1282. Promise.any = function (promises) {
  1283. return any(promises);
  1284. };
  1285. Promise.prototype.any = function () {
  1286. return any(this);
  1287. };
  1288. };
  1289. },{}],2:[function(_dereq_,module,exports){
  1290. "use strict";
  1291. var firstLineError;
  1292. try {throw new Error(); } catch (e) {firstLineError = e;}
  1293. var schedule = _dereq_("./schedule");
  1294. var Queue = _dereq_("./queue");
  1295. var util = _dereq_("./util");
  1296. function Async() {
  1297. this._customScheduler = false;
  1298. this._isTickUsed = false;
  1299. this._lateQueue = new Queue(16);
  1300. this._normalQueue = new Queue(16);
  1301. this._haveDrainedQueues = false;
  1302. this._trampolineEnabled = true;
  1303. var self = this;
  1304. this.drainQueues = function () {
  1305. self._drainQueues();
  1306. };
  1307. this._schedule = schedule;
  1308. }
  1309. Async.prototype.setScheduler = function(fn) {
  1310. var prev = this._schedule;
  1311. this._schedule = fn;
  1312. this._customScheduler = true;
  1313. return prev;
  1314. };
  1315. Async.prototype.hasCustomScheduler = function() {
  1316. return this._customScheduler;
  1317. };
  1318. Async.prototype.enableTrampoline = function() {
  1319. this._trampolineEnabled = true;
  1320. };
  1321. Async.prototype.disableTrampolineIfNecessary = function() {
  1322. if (util.hasDevTools) {
  1323. this._trampolineEnabled = false;
  1324. }
  1325. };
  1326. Async.prototype.haveItemsQueued = function () {
  1327. return this._isTickUsed || this._haveDrainedQueues;
  1328. };
  1329. Async.prototype.fatalError = function(e, isNode) {
  1330. if (isNode) {
  1331. process.stderr.write("Fatal " + (e instanceof Error ? e.stack : e) +
  1332. "\n");
  1333. process.exit(2);
  1334. } else {
  1335. this.throwLater(e);
  1336. }
  1337. };
  1338. Async.prototype.throwLater = function(fn, arg) {
  1339. if (arguments.length === 1) {
  1340. arg = fn;
  1341. fn = function () { throw arg; };
  1342. }
  1343. if (typeof setTimeout !== "undefined") {
  1344. setTimeout(function() {
  1345. fn(arg);
  1346. }, 0);
  1347. } else try {
  1348. this._schedule(function() {
  1349. fn(arg);
  1350. });
  1351. } catch (e) {
  1352. throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  1353. }
  1354. };
  1355. function AsyncInvokeLater(fn, receiver, arg) {
  1356. this._lateQueue.push(fn, receiver, arg);
  1357. this._queueTick();
  1358. }
  1359. function AsyncInvoke(fn, receiver, arg) {
  1360. this._normalQueue.push(fn, receiver, arg);
  1361. this._queueTick();
  1362. }
  1363. function AsyncSettlePromises(promise) {
  1364. this._normalQueue._pushOne(promise);
  1365. this._queueTick();
  1366. }
  1367. if (!util.hasDevTools) {
  1368. Async.prototype.invokeLater = AsyncInvokeLater;
  1369. Async.prototype.invoke = AsyncInvoke;
  1370. Async.prototype.settlePromises = AsyncSettlePromises;
  1371. } else {
  1372. Async.prototype.invokeLater = function (fn, receiver, arg) {
  1373. if (this._trampolineEnabled) {
  1374. AsyncInvokeLater.call(this, fn, receiver, arg);
  1375. } else {
  1376. this._schedule(function() {
  1377. setTimeout(function() {
  1378. fn.call(receiver, arg);
  1379. }, 100);
  1380. });
  1381. }
  1382. };
  1383. Async.prototype.invoke = function (fn, receiver, arg) {
  1384. if (this._trampolineEnabled) {
  1385. AsyncInvoke.call(this, fn, receiver, arg);
  1386. } else {
  1387. this._schedule(function() {
  1388. fn.call(receiver, arg);
  1389. });
  1390. }
  1391. };
  1392. Async.prototype.settlePromises = function(promise) {
  1393. if (this._trampolineEnabled) {
  1394. AsyncSettlePromises.call(this, promise);
  1395. } else {
  1396. this._schedule(function() {
  1397. promise._settlePromises();
  1398. });
  1399. }
  1400. };
  1401. }
  1402. Async.prototype.invokeFirst = function (fn, receiver, arg) {
  1403. this._normalQueue.unshift(fn, receiver, arg);
  1404. this._queueTick();
  1405. };
  1406. Async.prototype._drainQueue = function(queue) {
  1407. while (queue.length() > 0) {
  1408. var fn = queue.shift();
  1409. if (typeof fn !== "function") {
  1410. fn._settlePromises();
  1411. continue;
  1412. }
  1413. var receiver = queue.shift();
  1414. var arg = queue.shift();
  1415. fn.call(receiver, arg);
  1416. }
  1417. };
  1418. Async.prototype._drainQueues = function () {
  1419. this._drainQueue(this._normalQueue);
  1420. this._reset();
  1421. this._haveDrainedQueues = true;
  1422. this._drainQueue(this._lateQueue);
  1423. };
  1424. Async.prototype._queueTick = function () {
  1425. if (!this._isTickUsed) {
  1426. this._isTickUsed = true;
  1427. this._schedule(this.drainQueues);
  1428. }
  1429. };
  1430. Async.prototype._reset = function () {
  1431. this._isTickUsed = false;
  1432. };
  1433. module.exports = Async;
  1434. module.exports.firstLineError = firstLineError;
  1435. },{"./queue":26,"./schedule":29,"./util":36}],3:[function(_dereq_,module,exports){
  1436. "use strict";
  1437. module.exports = function(Promise, INTERNAL, tryConvertToPromise, debug) {
  1438. var calledBind = false;
  1439. var rejectThis = function(_, e) {
  1440. this._reject(e);
  1441. };
  1442. var targetRejected = function(e, context) {
  1443. context.promiseRejectionQueued = true;
  1444. context.bindingPromise._then(rejectThis, rejectThis, null, this, e);
  1445. };
  1446. var bindingResolved = function(thisArg, context) {
  1447. if (((this._bitField & 50397184) === 0)) {
  1448. this._resolveCallback(context.target);
  1449. }
  1450. };
  1451. var bindingRejected = function(e, context) {
  1452. if (!context.promiseRejectionQueued) this._reject(e);
  1453. };
  1454. Promise.prototype.bind = function (thisArg) {
  1455. if (!calledBind) {
  1456. calledBind = true;
  1457. Promise.prototype._propagateFrom = debug.propagateFromFunction();
  1458. Promise.prototype._boundValue = debug.boundValueFunction();
  1459. }
  1460. var maybePromise = tryConvertToPromise(thisArg);
  1461. var ret = new Promise(INTERNAL);
  1462. ret._propagateFrom(this, 1);
  1463. var target = this._target();
  1464. ret._setBoundTo(maybePromise);
  1465. if (maybePromise instanceof Promise) {
  1466. var context = {
  1467. promiseRejectionQueued: false,
  1468. promise: ret,
  1469. target: target,
  1470. bindingPromise: maybePromise
  1471. };
  1472. target._then(INTERNAL, targetRejected, undefined, ret, context);
  1473. maybePromise._then(
  1474. bindingResolved, bindingRejected, undefined, ret, context);
  1475. ret._setOnCancel(maybePromise);
  1476. } else {
  1477. ret._resolveCallback(target);
  1478. }
  1479. return ret;
  1480. };
  1481. Promise.prototype._setBoundTo = function (obj) {
  1482. if (obj !== undefined) {
  1483. this._bitField = this._bitField | 2097152;
  1484. this._boundTo = obj;
  1485. } else {
  1486. this._bitField = this._bitField & (~2097152);
  1487. }
  1488. };
  1489. Promise.prototype._isBound = function () {
  1490. return (this._bitField & 2097152) === 2097152;
  1491. };
  1492. Promise.bind = function (thisArg, value) {
  1493. return Promise.resolve(value).bind(thisArg);
  1494. };
  1495. };
  1496. },{}],4:[function(_dereq_,module,exports){
  1497. "use strict";
  1498. var old;
  1499. if (typeof Promise !== "undefined") old = Promise;
  1500. function noConflict() {
  1501. try { if (Promise === bluebird) Promise = old; }
  1502. catch (e) {}
  1503. return bluebird;
  1504. }
  1505. var bluebird = _dereq_("./promise")();
  1506. bluebird.noConflict = noConflict;
  1507. module.exports = bluebird;
  1508. },{"./promise":22}],5:[function(_dereq_,module,exports){
  1509. "use strict";
  1510. var cr = Object.create;
  1511. if (cr) {
  1512. var callerCache = cr(null);
  1513. var getterCache = cr(null);
  1514. callerCache[" size"] = getterCache[" size"] = 0;
  1515. }
  1516. module.exports = function(Promise) {
  1517. var util = _dereq_("./util");
  1518. var canEvaluate = util.canEvaluate;
  1519. var isIdentifier = util.isIdentifier;
  1520. var getMethodCaller;
  1521. var getGetter;
  1522. if (!true) {
  1523. var makeMethodCaller = function (methodName) {
  1524. return new Function("ensureMethod", " \n\
  1525. return function(obj) { \n\
  1526. 'use strict' \n\
  1527. var len = this.length; \n\
  1528. ensureMethod(obj, 'methodName'); \n\
  1529. switch(len) { \n\
  1530. case 1: return obj.methodName(this[0]); \n\
  1531. case 2: return obj.methodName(this[0], this[1]); \n\
  1532. case 3: return obj.methodName(this[0], this[1], this[2]); \n\
  1533. case 0: return obj.methodName(); \n\
  1534. default: \n\
  1535. return obj.methodName.apply(obj, this); \n\
  1536. } \n\
  1537. }; \n\
  1538. ".replace(/methodName/g, methodName))(ensureMethod);
  1539. };
  1540. var makeGetter = function (propertyName) {
  1541. return new Function("obj", " \n\
  1542. 'use strict'; \n\
  1543. return obj.propertyName; \n\
  1544. ".replace("propertyName", propertyName));
  1545. };
  1546. var getCompiled = function(name, compiler, cache) {
  1547. var ret = cache[name];
  1548. if (typeof ret !== "function") {
  1549. if (!isIdentifier(name)) {
  1550. return null;
  1551. }
  1552. ret = compiler(name);
  1553. cache[name] = ret;
  1554. cache[" size"]++;
  1555. if (cache[" size"] > 512) {
  1556. var keys = Object.keys(cache);
  1557. for (var i = 0; i < 256; ++i) delete cache[keys[i]];
  1558. cache[" size"] = keys.length - 256;
  1559. }
  1560. }
  1561. return ret;
  1562. };
  1563. getMethodCaller = function(name) {
  1564. return getCompiled(name, makeMethodCaller, callerCache);
  1565. };
  1566. getGetter = function(name) {
  1567. return getCompiled(name, makeGetter, getterCache);
  1568. };
  1569. }
  1570. function ensureMethod(obj, methodName) {
  1571. var fn;
  1572. if (obj != null) fn = obj[methodName];
  1573. if (typeof fn !== "function") {
  1574. var message = "Object " + util.classString(obj) + " has no method '" +
  1575. util.toString(methodName) + "'";
  1576. throw new Promise.TypeError(message);
  1577. }
  1578. return fn;
  1579. }
  1580. function caller(obj) {
  1581. var methodName = this.pop();
  1582. var fn = ensureMethod(obj, methodName);
  1583. return fn.apply(obj, this);
  1584. }
  1585. Promise.prototype.call = function (methodName) {
  1586. var args = [].slice.call(arguments, 1);;
  1587. if (!true) {
  1588. if (canEvaluate) {
  1589. var maybeCaller = getMethodCaller(methodName);
  1590. if (maybeCaller !== null) {
  1591. return this._then(
  1592. maybeCaller, undefined, undefined, args, undefined);
  1593. }
  1594. }
  1595. }
  1596. args.push(methodName);
  1597. return this._then(caller, undefined, undefined, args, undefined);
  1598. };
  1599. function namedGetter(obj) {
  1600. return obj[this];
  1601. }
  1602. function indexedGetter(obj) {
  1603. var index = +this;
  1604. if (index < 0) index = Math.max(0, index + obj.length);
  1605. return obj[index];
  1606. }
  1607. Promise.prototype.get = function (propertyName) {
  1608. var isIndex = (typeof propertyName === "number");
  1609. var getter;
  1610. if (!isIndex) {
  1611. if (canEvaluate) {
  1612. var maybeGetter = getGetter(propertyName);
  1613. getter = maybeGetter !== null ? maybeGetter : namedGetter;
  1614. } else {
  1615. getter = namedGetter;
  1616. }
  1617. } else {
  1618. getter = indexedGetter;
  1619. }
  1620. return this._then(getter, undefined, undefined, propertyName, undefined);
  1621. };
  1622. };
  1623. },{"./util":36}],6:[function(_dereq_,module,exports){
  1624. "use strict";
  1625. module.exports = function(Promise, PromiseArray, apiRejection, debug) {
  1626. var util = _dereq_("./util");
  1627. var tryCatch = util.tryCatch;
  1628. var errorObj = util.errorObj;
  1629. var async = Promise._async;
  1630. Promise.prototype["break"] = Promise.prototype.cancel = function() {
  1631. if (!debug.cancellation()) return this._warn("cancellation is disabled");
  1632. var promise = this;
  1633. var child = promise;
  1634. while (promise._isCancellable()) {
  1635. if (!promise._cancelBy(child)) {
  1636. if (child._isFollowing()) {
  1637. child._followee().cancel();
  1638. } else {
  1639. child._cancelBranched();
  1640. }
  1641. break;
  1642. }
  1643. var parent = promise._cancellationParent;
  1644. if (parent == null || !parent._isCancellable()) {
  1645. if (promise._isFollowing()) {
  1646. promise._followee().cancel();
  1647. } else {
  1648. promise._cancelBranched();
  1649. }
  1650. break;
  1651. } else {
  1652. if (promise._isFollowing()) promise._followee().cancel();
  1653. promise._setWillBeCancelled();
  1654. child = promise;
  1655. promise = parent;
  1656. }
  1657. }
  1658. };
  1659. Promise.prototype._branchHasCancelled = function() {
  1660. this._branchesRemainingToCancel--;
  1661. };
  1662. Promise.prototype._enoughBranchesHaveCancelled = function() {
  1663. return this._branchesRemainingToCancel === undefined ||
  1664. this._branchesRemainingToCancel <= 0;
  1665. };
  1666. Promise.prototype._cancelBy = function(canceller) {
  1667. if (canceller === this) {
  1668. this._branchesRemainingToCancel = 0;
  1669. this._invokeOnCancel();
  1670. return true;
  1671. } else {
  1672. this._branchHasCancelled();
  1673. if (this._enoughBranchesHaveCancelled()) {
  1674. this._invokeOnCancel();
  1675. return true;
  1676. }
  1677. }
  1678. return false;
  1679. };
  1680. Promise.prototype._cancelBranched = function() {
  1681. if (this._enoughBranchesHaveCancelled()) {
  1682. this._cancel();
  1683. }
  1684. };
  1685. Promise.prototype._cancel = function() {
  1686. if (!this._isCancellable()) return;
  1687. this._setCancelled();
  1688. async.invoke(this._cancelPromises, this, undefined);
  1689. };
  1690. Promise.prototype._cancelPromises = function() {
  1691. if (this._length() > 0) this._settlePromises();
  1692. };
  1693. Promise.prototype._unsetOnCancel = function() {
  1694. this._onCancelField = undefined;
  1695. };
  1696. Promise.prototype._isCancellable = function() {
  1697. return this.isPending() && !this._isCancelled();
  1698. };
  1699. Promise.prototype.isCancellable = function() {
  1700. return this.isPending() && !this.isCancelled();
  1701. };
  1702. Promise.prototype._doInvokeOnCancel = function(onCancelCallback, internalOnly) {
  1703. if (util.isArray(onCancelCallback)) {
  1704. for (var i = 0; i < onCancelCallback.length; ++i) {
  1705. this._doInvokeOnCancel(onCancelCallback[i], internalOnly);
  1706. }
  1707. } else if (onCancelCallback !== undefined) {
  1708. if (typeof onCancelCallback === "function") {
  1709. if (!internalOnly) {
  1710. var e = tryCatch(onCancelCallback).call(this._boundValue());
  1711. if (e === errorObj) {
  1712. this._attachExtraTrace(e.e);
  1713. async.throwLater(e.e);
  1714. }
  1715. }
  1716. } else {
  1717. onCancelCallback._resultCancelled(this);
  1718. }
  1719. }
  1720. };
  1721. Promise.prototype._invokeOnCancel = function() {
  1722. var onCancelCallback = this._onCancel();
  1723. this._unsetOnCancel();
  1724. async.invoke(this._doInvokeOnCancel, this, onCancelCallback);
  1725. };
  1726. Promise.prototype._invokeInternalOnCancel = function() {
  1727. if (this._isCancellable()) {
  1728. this._doInvokeOnCancel(this._onCancel(), true);
  1729. this._unsetOnCancel();
  1730. }
  1731. };
  1732. Promise.prototype._resultCancelled = function() {
  1733. this.cancel();
  1734. };
  1735. };
  1736. },{"./util":36}],7:[function(_dereq_,module,exports){
  1737. "use strict";
  1738. module.exports = function(NEXT_FILTER) {
  1739. var util = _dereq_("./util");
  1740. var getKeys = _dereq_("./es5").keys;
  1741. var tryCatch = util.tryCatch;
  1742. var errorObj = util.errorObj;
  1743. function catchFilter(instances, cb, promise) {
  1744. return function(e) {
  1745. var boundTo = promise._boundValue();
  1746. predicateLoop: for (var i = 0; i < instances.length; ++i) {
  1747. var item = instances[i];
  1748. if (item === Error ||
  1749. (item != null && item.prototype instanceof Error)) {
  1750. if (e instanceof item) {
  1751. return tryCatch(cb).call(boundTo, e);
  1752. }
  1753. } else if (typeof item === "function") {
  1754. var matchesPredicate = tryCatch(item).call(boundTo, e);
  1755. if (matchesPredicate === errorObj) {
  1756. return matchesPredicate;
  1757. } else if (matchesPredicate) {
  1758. return tryCatch(cb).call(boundTo, e);
  1759. }
  1760. } else if (util.isObject(e)) {
  1761. var keys = getKeys(item);
  1762. for (var j = 0; j < keys.length; ++j) {
  1763. var key = keys[j];
  1764. if (item[key] != e[key]) {
  1765. continue predicateLoop;
  1766. }
  1767. }
  1768. return tryCatch(cb).call(boundTo, e);
  1769. }
  1770. }
  1771. return NEXT_FILTER;
  1772. };
  1773. }
  1774. return catchFilter;
  1775. };
  1776. },{"./es5":13,"./util":36}],8:[function(_dereq_,module,exports){
  1777. "use strict";
  1778. module.exports = function(Promise) {
  1779. var longStackTraces = false;
  1780. var contextStack = [];
  1781. Promise.prototype._promiseCreated = function() {};
  1782. Promise.prototype._pushContext = function() {};
  1783. Promise.prototype._popContext = function() {return null;};
  1784. Promise._peekContext = Promise.prototype._peekContext = function() {};
  1785. function Context() {
  1786. this._trace = new Context.CapturedTrace(peekContext());
  1787. }
  1788. Context.prototype._pushContext = function () {
  1789. if (this._trace !== undefined) {
  1790. this._trace._promiseCreated = null;
  1791. contextStack.push(this._trace);
  1792. }
  1793. };
  1794. Context.prototype._popContext = function () {
  1795. if (this._trace !== undefined) {
  1796. var trace = contextStack.pop();
  1797. var ret = trace._promiseCreated;
  1798. trace._promiseCreated = null;
  1799. return ret;
  1800. }
  1801. return null;
  1802. };
  1803. function createContext() {
  1804. if (longStackTraces) return new Context();
  1805. }
  1806. function peekContext() {
  1807. var lastIndex = contextStack.length - 1;
  1808. if (lastIndex >= 0) {
  1809. return contextStack[lastIndex];
  1810. }
  1811. return undefined;
  1812. }
  1813. Context.CapturedTrace = null;
  1814. Context.create = createContext;
  1815. Context.deactivateLongStackTraces = function() {};
  1816. Context.activateLongStackTraces = function() {
  1817. var Promise_pushContext = Promise.prototype._pushContext;
  1818. var Promise_popContext = Promise.prototype._popContext;
  1819. var Promise_PeekContext = Promise._peekContext;
  1820. var Promise_peekContext = Promise.prototype._peekContext;
  1821. var Promise_promiseCreated = Promise.prototype._promiseCreated;
  1822. Context.deactivateLongStackTraces = function() {
  1823. Promise.prototype._pushContext = Promise_pushContext;
  1824. Promise.prototype._popContext = Promise_popContext;
  1825. Promise._peekContext = Promise_PeekContext;
  1826. Promise.prototype._peekContext = Promise_peekContext;
  1827. Promise.prototype._promiseCreated = Promise_promiseCreated;
  1828. longStackTraces = false;
  1829. };
  1830. longStackTraces = true;
  1831. Promise.prototype._pushContext = Context.prototype._pushContext;
  1832. Promise.prototype._popContext = Context.prototype._popContext;
  1833. Promise._peekContext = Promise.prototype._peekContext = peekContext;
  1834. Promise.prototype._promiseCreated = function() {
  1835. var ctx = this._peekContext();
  1836. if (ctx && ctx._promiseCreated == null) ctx._promiseCreated = this;
  1837. };
  1838. };
  1839. return Context;
  1840. };
  1841. },{}],9:[function(_dereq_,module,exports){
  1842. "use strict";
  1843. module.exports = function(Promise, Context) {
  1844. var getDomain = Promise._getDomain;
  1845. var async = Promise._async;
  1846. var Warning = _dereq_("./errors").Warning;
  1847. var util = _dereq_("./util");
  1848. var canAttachTrace = util.canAttachTrace;
  1849. var unhandledRejectionHandled;
  1850. var possiblyUnhandledRejection;
  1851. var bluebirdFramePattern =
  1852. /[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/;
  1853. var nodeFramePattern = /\((?:timers\.js):\d+:\d+\)/;
  1854. var parseLinePattern = /[\/<\(](.+?):(\d+):(\d+)\)?\s*$/;
  1855. var stackFramePattern = null;
  1856. var formatStack = null;
  1857. var indentStackFrames = false;
  1858. var printWarning;
  1859. var debugging = !!(util.env("BLUEBIRD_DEBUG") != 0 &&
  1860. (true ||
  1861. util.env("BLUEBIRD_DEBUG") ||
  1862. util.env("NODE_ENV") === "development"));
  1863. var warnings = !!(util.env("BLUEBIRD_WARNINGS") != 0 &&
  1864. (debugging || util.env("BLUEBIRD_WARNINGS")));
  1865. var longStackTraces = !!(util.env("BLUEBIRD_LONG_STACK_TRACES") != 0 &&
  1866. (debugging || util.env("BLUEBIRD_LONG_STACK_TRACES")));
  1867. var wForgottenReturn = util.env("BLUEBIRD_W_FORGOTTEN_RETURN") != 0 &&
  1868. (warnings || !!util.env("BLUEBIRD_W_FORGOTTEN_RETURN"));
  1869. Promise.prototype.suppressUnhandledRejections = function() {
  1870. var target = this._target();
  1871. target._bitField = ((target._bitField & (~1048576)) |
  1872. 524288);
  1873. };
  1874. Promise.prototype._ensurePossibleRejectionHandled = function () {
  1875. if ((this._bitField & 524288) !== 0) return;
  1876. this._setRejectionIsUnhandled();
  1877. async.invokeLater(this._notifyUnhandledRejection, this, undefined);
  1878. };
  1879. Promise.prototype._notifyUnhandledRejectionIsHandled = function () {
  1880. fireRejectionEvent("rejectionHandled",
  1881. unhandledRejectionHandled, undefined, this);
  1882. };
  1883. Promise.prototype._setReturnedNonUndefined = function() {
  1884. this._bitField = this._bitField | 268435456;
  1885. };
  1886. Promise.prototype._returnedNonUndefined = function() {
  1887. return (this._bitField & 268435456) !== 0;
  1888. };
  1889. Promise.prototype._notifyUnhandledRejection = function () {
  1890. if (this._isRejectionUnhandled()) {
  1891. var reason = this._settledValue();
  1892. this._setUnhandledRejectionIsNotified();
  1893. fireRejectionEvent("unhandledRejection",
  1894. possiblyUnhandledRejection, reason, this);
  1895. }
  1896. };
  1897. Promise.prototype._setUnhandledRejectionIsNotified = function () {
  1898. this._bitField = this._bitField | 262144;
  1899. };
  1900. Promise.prototype._unsetUnhandledRejectionIsNotified = function () {
  1901. this._bitField = this._bitField & (~262144);
  1902. };
  1903. Promise.prototype._isUnhandledRejectionNotified = function () {
  1904. return (this._bitField & 262144) > 0;
  1905. };
  1906. Promise.prototype._setRejectionIsUnhandled = function () {
  1907. this._bitField = this._bitField | 1048576;
  1908. };
  1909. Promise.prototype._unsetRejectionIsUnhandled = function () {
  1910. this._bitField = this._bitField & (~1048576);
  1911. if (this._isUnhandledRejectionNotified()) {
  1912. this._unsetUnhandledRejectionIsNotified();
  1913. this._notifyUnhandledRejectionIsHandled();
  1914. }
  1915. };
  1916. Promise.prototype._isRejectionUnhandled = function () {
  1917. return (this._bitField & 1048576) > 0;
  1918. };
  1919. Promise.prototype._warn = function(message, shouldUseOwnTrace, promise) {
  1920. return warn(message, shouldUseOwnTrace, promise || this);
  1921. };
  1922. Promise.onPossiblyUnhandledRejection = function (fn) {
  1923. var domain = getDomain();
  1924. possiblyUnhandledRejection =
  1925. typeof fn === "function" ? (domain === null ?
  1926. fn : util.domainBind(domain, fn))
  1927. : undefined;
  1928. };
  1929. Promise.onUnhandledRejectionHandled = function (fn) {
  1930. var domain = getDomain();
  1931. unhandledRejectionHandled =
  1932. typeof fn === "function" ? (domain === null ?
  1933. fn : util.domainBind(domain, fn))
  1934. : undefined;
  1935. };
  1936. var disableLongStackTraces = function() {};
  1937. Promise.longStackTraces = function () {
  1938. if (async.haveItemsQueued() && !config.longStackTraces) {
  1939. throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  1940. }
  1941. if (!config.longStackTraces && longStackTracesIsSupported()) {
  1942. var Promise_captureStackTrace = Promise.prototype._captureStackTrace;
  1943. var Promise_attachExtraTrace = Promise.prototype._attachExtraTrace;
  1944. config.longStackTraces = true;
  1945. disableLongStackTraces = function() {
  1946. if (async.haveItemsQueued() && !config.longStackTraces) {
  1947. throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  1948. }
  1949. Promise.prototype._captureStackTrace = Promise_captureStackTrace;
  1950. Promise.prototype._attachExtraTrace = Promise_attachExtraTrace;
  1951. Context.deactivateLongStackTraces();
  1952. async.enableTrampoline();
  1953. config.longStackTraces = false;
  1954. };
  1955. Promise.prototype._captureStackTrace = longStackTracesCaptureStackTrace;
  1956. Promise.prototype._attachExtraTrace = longStackTracesAttachExtraTrace;
  1957. Context.activateLongStackTraces();
  1958. async.disableTrampolineIfNecessary();
  1959. }
  1960. };
  1961. Promise.hasLongStackTraces = function () {
  1962. return config.longStackTraces && longStackTracesIsSupported();
  1963. };
  1964. var fireDomEvent = (function() {
  1965. try {
  1966. if (typeof CustomEvent === "function") {
  1967. var event = new CustomEvent("CustomEvent");
  1968. util.global.dispatchEvent(event);
  1969. return function(name, event) {
  1970. var domEvent = new CustomEvent(name.toLowerCase(), {
  1971. detail: event,
  1972. cancelable: true
  1973. });
  1974. return !util.global.dispatchEvent(domEvent);
  1975. };
  1976. } else if (typeof Event === "function") {
  1977. var event = new Event("CustomEvent");
  1978. util.global.dispatchEvent(event);
  1979. return function(name, event) {
  1980. var domEvent = new Event(name.toLowerCase(), {
  1981. cancelable: true
  1982. });
  1983. domEvent.detail = event;
  1984. return !util.global.dispatchEvent(domEvent);
  1985. };
  1986. } else {
  1987. var event = document.createEvent("CustomEvent");
  1988. event.initCustomEvent("testingtheevent", false, true, {});
  1989. util.global.dispatchEvent(event);
  1990. return function(name, event) {
  1991. var domEvent = document.createEvent("CustomEvent");
  1992. domEvent.initCustomEvent(name.toLowerCase(), false, true,
  1993. event);
  1994. return !util.global.dispatchEvent(domEvent);
  1995. };
  1996. }
  1997. } catch (e) {}
  1998. return function() {
  1999. return false;
  2000. };
  2001. })();
  2002. var fireGlobalEvent = (function() {
  2003. if (util.isNode) {
  2004. return function() {
  2005. return process.emit.apply(process, arguments);
  2006. };
  2007. } else {
  2008. if (!util.global) {
  2009. return function() {
  2010. return false;
  2011. };
  2012. }
  2013. return function(name) {
  2014. var methodName = "on" + name.toLowerCase();
  2015. var method = util.global[methodName];
  2016. if (!method) return false;
  2017. method.apply(util.global, [].slice.call(arguments, 1));
  2018. return true;
  2019. };
  2020. }
  2021. })();
  2022. function generatePromiseLifecycleEventObject(name, promise) {
  2023. return {promise: promise};
  2024. }
  2025. var eventToObjectGenerator = {
  2026. promiseCreated: generatePromiseLifecycleEventObject,
  2027. promiseFulfilled: generatePromiseLifecycleEventObject,
  2028. promiseRejected: generatePromiseLifecycleEventObject,
  2029. promiseResolved: generatePromiseLifecycleEventObject,
  2030. promiseCancelled: generatePromiseLifecycleEventObject,
  2031. promiseChained: function(name, promise, child) {
  2032. return {promise: promise, child: child};
  2033. },
  2034. warning: function(name, warning) {
  2035. return {warning: warning};
  2036. },
  2037. unhandledRejection: function (name, reason, promise) {
  2038. return {reason: reason, promise: promise};
  2039. },
  2040. rejectionHandled: generatePromiseLifecycleEventObject
  2041. };
  2042. var activeFireEvent = function (name) {
  2043. var globalEventFired = false;
  2044. try {
  2045. globalEventFired = fireGlobalEvent.apply(null, arguments);
  2046. } catch (e) {
  2047. async.throwLater(e);
  2048. globalEventFired = true;
  2049. }
  2050. var domEventFired = false;
  2051. try {
  2052. domEventFired = fireDomEvent(name,
  2053. eventToObjectGenerator[name].apply(null, arguments));
  2054. } catch (e) {
  2055. async.throwLater(e);
  2056. domEventFired = true;
  2057. }
  2058. return domEventFired || globalEventFired;
  2059. };
  2060. Promise.config = function(opts) {
  2061. opts = Object(opts);
  2062. if ("longStackTraces" in opts) {
  2063. if (opts.longStackTraces) {
  2064. Promise.longStackTraces();
  2065. } else if (!opts.longStackTraces && Promise.hasLongStackTraces()) {
  2066. disableLongStackTraces();
  2067. }
  2068. }
  2069. if ("warnings" in opts) {
  2070. var warningsOption = opts.warnings;
  2071. config.warnings = !!warningsOption;
  2072. wForgottenReturn = config.warnings;
  2073. if (util.isObject(warningsOption)) {
  2074. if ("wForgottenReturn" in warningsOption) {
  2075. wForgottenReturn = !!warningsOption.wForgottenReturn;
  2076. }
  2077. }
  2078. }
  2079. if ("cancellation" in opts && opts.cancellation && !config.cancellation) {
  2080. if (async.haveItemsQueued()) {
  2081. throw new Error(
  2082. "cannot enable cancellation after promises are in use");
  2083. }
  2084. Promise.prototype._clearCancellationData =
  2085. cancellationClearCancellationData;
  2086. Promise.prototype._propagateFrom = cancellationPropagateFrom;
  2087. Promise.prototype._onCancel = cancellationOnCancel;
  2088. Promise.prototype._setOnCancel = cancellationSetOnCancel;
  2089. Promise.prototype._attachCancellationCallback =
  2090. cancellationAttachCancellationCallback;
  2091. Promise.prototype._execute = cancellationExecute;
  2092. propagateFromFunction = cancellationPropagateFrom;
  2093. config.cancellation = true;
  2094. }
  2095. if ("monitoring" in opts) {
  2096. if (opts.monitoring && !config.monitoring) {
  2097. config.monitoring = true;
  2098. Promise.prototype._fireEvent = activeFireEvent;
  2099. } else if (!opts.monitoring && config.monitoring) {
  2100. config.monitoring = false;
  2101. Promise.prototype._fireEvent = defaultFireEvent;
  2102. }
  2103. }
  2104. };
  2105. function defaultFireEvent() { return false; }
  2106. Promise.prototype._fireEvent = defaultFireEvent;
  2107. Promise.prototype._execute = function(executor, resolve, reject) {
  2108. try {
  2109. executor(resolve, reject);
  2110. } catch (e) {
  2111. return e;
  2112. }
  2113. };
  2114. Promise.prototype._onCancel = function () {};
  2115. Promise.prototype._setOnCancel = function (handler) { ; };
  2116. Promise.prototype._attachCancellationCallback = function(onCancel) {
  2117. ;
  2118. };
  2119. Promise.prototype._captureStackTrace = function () {};
  2120. Promise.prototype._attachExtraTrace = function () {};
  2121. Promise.prototype._clearCancellationData = function() {};
  2122. Promise.prototype._propagateFrom = function (parent, flags) {
  2123. ;
  2124. ;
  2125. };
  2126. function cancellationExecute(executor, resolve, reject) {
  2127. var promise = this;
  2128. try {
  2129. executor(resolve, reject, function(onCancel) {
  2130. if (typeof onCancel !== "function") {
  2131. throw new TypeError("onCancel must be a function, got: " +
  2132. util.toString(onCancel));
  2133. }
  2134. promise._attachCancellationCallback(onCancel);
  2135. });
  2136. } catch (e) {
  2137. return e;
  2138. }
  2139. }
  2140. function cancellationAttachCancellationCallback(onCancel) {
  2141. if (!this._isCancellable()) return this;
  2142. var previousOnCancel = this._onCancel();
  2143. if (previousOnCancel !== undefined) {
  2144. if (util.isArray(previousOnCancel)) {
  2145. previousOnCancel.push(onCancel);
  2146. } else {
  2147. this._setOnCancel([previousOnCancel, onCancel]);
  2148. }
  2149. } else {
  2150. this._setOnCancel(onCancel);
  2151. }
  2152. }
  2153. function cancellationOnCancel() {
  2154. return this._onCancelField;
  2155. }
  2156. function cancellationSetOnCancel(onCancel) {
  2157. this._onCancelField = onCancel;
  2158. }
  2159. function cancellationClearCancellationData() {
  2160. this._cancellationParent = undefined;
  2161. this._onCancelField = undefined;
  2162. }
  2163. function cancellationPropagateFrom(parent, flags) {
  2164. if ((flags & 1) !== 0) {
  2165. this._cancellationParent = parent;
  2166. var branchesRemainingToCancel = parent._branchesRemainingToCancel;
  2167. if (branchesRemainingToCancel === undefined) {
  2168. branchesRemainingToCancel = 0;
  2169. }
  2170. parent._branchesRemainingToCancel = branchesRemainingToCancel + 1;
  2171. }
  2172. if ((flags & 2) !== 0 && parent._isBound()) {
  2173. this._setBoundTo(parent._boundTo);
  2174. }
  2175. }
  2176. function bindingPropagateFrom(parent, flags) {
  2177. if ((flags & 2) !== 0 && parent._isBound()) {
  2178. this._setBoundTo(parent._boundTo);
  2179. }
  2180. }
  2181. var propagateFromFunction = bindingPropagateFrom;
  2182. function boundValueFunction() {
  2183. var ret = this._boundTo;
  2184. if (ret !== undefined) {
  2185. if (ret instanceof Promise) {
  2186. if (ret.isFulfilled()) {
  2187. return ret.value();
  2188. } else {
  2189. return undefined;
  2190. }
  2191. }
  2192. }
  2193. return ret;
  2194. }
  2195. function longStackTracesCaptureStackTrace() {
  2196. this._trace = new CapturedTrace(this._peekContext());
  2197. }
  2198. function longStackTracesAttachExtraTrace(error, ignoreSelf) {
  2199. if (canAttachTrace(error)) {
  2200. var trace = this._trace;
  2201. if (trace !== undefined) {
  2202. if (ignoreSelf) trace = trace._parent;
  2203. }
  2204. if (trace !== undefined) {
  2205. trace.attachExtraTrace(error);
  2206. } else if (!error.__stackCleaned__) {
  2207. var parsed = parseStackAndMessage(error);
  2208. util.notEnumerableProp(error, "stack",
  2209. parsed.message + "\n" + parsed.stack.join("\n"));
  2210. util.notEnumerableProp(error, "__stackCleaned__", true);
  2211. }
  2212. }
  2213. }
  2214. function checkForgottenReturns(returnValue, promiseCreated, name, promise,
  2215. parent) {
  2216. if (returnValue === undefined && promiseCreated !== null &&
  2217. wForgottenReturn) {
  2218. if (parent !== undefined && parent._returnedNonUndefined()) return;
  2219. if ((promise._bitField & 65535) === 0) return;
  2220. if (name) name = name + " ";
  2221. var handlerLine = "";
  2222. var creatorLine = "";
  2223. if (promiseCreated._trace) {
  2224. var traceLines = promiseCreated._trace.stack.split("\n");
  2225. var stack = cleanStack(traceLines);
  2226. for (var i = stack.length - 1; i >= 0; --i) {
  2227. var line = stack[i];
  2228. if (!nodeFramePattern.test(line)) {
  2229. var lineMatches = line.match(parseLinePattern);
  2230. if (lineMatches) {
  2231. handlerLine = "at " + lineMatches[1] +
  2232. ":" + lineMatches[2] + ":" + lineMatches[3] + " ";
  2233. }
  2234. break;
  2235. }
  2236. }
  2237. if (stack.length > 0) {
  2238. var firstUserLine = stack[0];
  2239. for (var i = 0; i < traceLines.length; ++i) {
  2240. if (traceLines[i] === firstUserLine) {
  2241. if (i > 0) {
  2242. creatorLine = "\n" + traceLines[i - 1];
  2243. }
  2244. break;
  2245. }
  2246. }
  2247. }
  2248. }
  2249. var msg = "a promise was created in a " + name +
  2250. "handler " + handlerLine + "but was not returned from it, " +
  2251. "see http://goo.gl/rRqMUw" +
  2252. creatorLine;
  2253. promise._warn(msg, true, promiseCreated);
  2254. }
  2255. }
  2256. function deprecated(name, replacement) {
  2257. var message = name +
  2258. " is deprecated and will be removed in a future version.";
  2259. if (replacement) message += " Use " + replacement + " instead.";
  2260. return warn(message);
  2261. }
  2262. function warn(message, shouldUseOwnTrace, promise) {
  2263. if (!config.warnings) return;
  2264. var warning = new Warning(message);
  2265. var ctx;
  2266. if (shouldUseOwnTrace) {
  2267. promise._attachExtraTrace(warning);
  2268. } else if (config.longStackTraces && (ctx = Promise._peekContext())) {
  2269. ctx.attachExtraTrace(warning);
  2270. } else {
  2271. var parsed = parseStackAndMessage(warning);
  2272. warning.stack = parsed.message + "\n" + parsed.stack.join("\n");
  2273. }
  2274. if (!activeFireEvent("warning", warning)) {
  2275. formatAndLogError(warning, "", true);
  2276. }
  2277. }
  2278. function reconstructStack(message, stacks) {
  2279. for (var i = 0; i < stacks.length - 1; ++i) {
  2280. stacks[i].push("From previous event:");
  2281. stacks[i] = stacks[i].join("\n");
  2282. }
  2283. if (i < stacks.length) {
  2284. stacks[i] = stacks[i].join("\n");
  2285. }
  2286. return message + "\n" + stacks.join("\n");
  2287. }
  2288. function removeDuplicateOrEmptyJumps(stacks) {
  2289. for (var i = 0; i < stacks.length; ++i) {
  2290. if (stacks[i].length === 0 ||
  2291. ((i + 1 < stacks.length) && stacks[i][0] === stacks[i+1][0])) {
  2292. stacks.splice(i, 1);
  2293. i--;
  2294. }
  2295. }
  2296. }
  2297. function removeCommonRoots(stacks) {
  2298. var current = stacks[0];
  2299. for (var i = 1; i < stacks.length; ++i) {
  2300. var prev = stacks[i];
  2301. var currentLastIndex = current.length - 1;
  2302. var currentLastLine = current[currentLastIndex];
  2303. var commonRootMeetPoint = -1;
  2304. for (var j = prev.length - 1; j >= 0; --j) {
  2305. if (prev[j] === currentLastLine) {
  2306. commonRootMeetPoint = j;
  2307. break;
  2308. }
  2309. }
  2310. for (var j = commonRootMeetPoint; j >= 0; --j) {
  2311. var line = prev[j];
  2312. if (current[currentLastIndex] === line) {
  2313. current.pop();
  2314. currentLastIndex--;
  2315. } else {
  2316. break;
  2317. }
  2318. }
  2319. current = prev;
  2320. }
  2321. }
  2322. function cleanStack(stack) {
  2323. var ret = [];
  2324. for (var i = 0; i < stack.length; ++i) {
  2325. var line = stack[i];
  2326. var isTraceLine = " (No stack trace)" === line ||
  2327. stackFramePattern.test(line);
  2328. var isInternalFrame = isTraceLine && shouldIgnore(line);
  2329. if (isTraceLine && !isInternalFrame) {
  2330. if (indentStackFrames && line.charAt(0) !== " ") {
  2331. line = " " + line;
  2332. }
  2333. ret.push(line);
  2334. }
  2335. }
  2336. return ret;
  2337. }
  2338. function stackFramesAsArray(error) {
  2339. var stack = error.stack.replace(/\s+$/g, "").split("\n");
  2340. for (var i = 0; i < stack.length; ++i) {
  2341. var line = stack[i];
  2342. if (" (No stack trace)" === line || stackFramePattern.test(line)) {
  2343. break;
  2344. }
  2345. }
  2346. if (i > 0) {
  2347. stack = stack.slice(i);
  2348. }
  2349. return stack;
  2350. }
  2351. function parseStackAndMessage(error) {
  2352. var stack = error.stack;
  2353. var message = error.toString();
  2354. stack = typeof stack === "string" && stack.length > 0
  2355. ? stackFramesAsArray(error) : [" (No stack trace)"];
  2356. return {
  2357. message: message,
  2358. stack: cleanStack(stack)
  2359. };
  2360. }
  2361. function formatAndLogError(error, title, isSoft) {
  2362. if (typeof console !== "undefined") {
  2363. var message;
  2364. if (util.isObject(error)) {
  2365. var stack = error.stack;
  2366. message = title + formatStack(stack, error);
  2367. } else {
  2368. message = title + String(error);
  2369. }
  2370. if (typeof printWarning === "function") {
  2371. printWarning(message, isSoft);
  2372. } else if (typeof console.log === "function" ||
  2373. typeof console.log === "object") {
  2374. console.log(message);
  2375. }
  2376. }
  2377. }
  2378. function fireRejectionEvent(name, localHandler, reason, promise) {
  2379. var localEventFired = false;
  2380. try {
  2381. if (typeof localHandler === "function") {
  2382. localEventFired = true;
  2383. if (name === "rejectionHandled") {
  2384. localHandler(promise);
  2385. } else {
  2386. localHandler(reason, promise);
  2387. }
  2388. }
  2389. } catch (e) {
  2390. async.throwLater(e);
  2391. }
  2392. if (name === "unhandledRejection") {
  2393. if (!activeFireEvent(name, reason, promise) && !localEventFired) {
  2394. formatAndLogError(reason, "Unhandled rejection ");
  2395. }
  2396. } else {
  2397. activeFireEvent(name, promise);
  2398. }
  2399. }
  2400. function formatNonError(obj) {
  2401. var str;
  2402. if (typeof obj === "function") {
  2403. str = "[function " +
  2404. (obj.name || "anonymous") +
  2405. "]";
  2406. } else {
  2407. str = obj && typeof obj.toString === "function"
  2408. ? obj.toString() : util.toString(obj);
  2409. var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/;
  2410. if (ruselessToString.test(str)) {
  2411. try {
  2412. var newStr = JSON.stringify(obj);
  2413. str = newStr;
  2414. }
  2415. catch(e) {
  2416. }
  2417. }
  2418. if (str.length === 0) {
  2419. str = "(empty array)";
  2420. }
  2421. }
  2422. return ("(<" + snip(str) + ">, no stack trace)");
  2423. }
  2424. function snip(str) {
  2425. var maxChars = 41;
  2426. if (str.length < maxChars) {
  2427. return str;
  2428. }
  2429. return str.substr(0, maxChars - 3) + "...";
  2430. }
  2431. function longStackTracesIsSupported() {
  2432. return typeof captureStackTrace === "function";
  2433. }
  2434. var shouldIgnore = function() { return false; };
  2435. var parseLineInfoRegex = /[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;
  2436. function parseLineInfo(line) {
  2437. var matches = line.match(parseLineInfoRegex);
  2438. if (matches) {
  2439. return {
  2440. fileName: matches[1],
  2441. line: parseInt(matches[2], 10)
  2442. };
  2443. }
  2444. }
  2445. function setBounds(firstLineError, lastLineError) {
  2446. if (!longStackTracesIsSupported()) return;
  2447. var firstStackLines = firstLineError.stack.split("\n");
  2448. var lastStackLines = lastLineError.stack.split("\n");
  2449. var firstIndex = -1;
  2450. var lastIndex = -1;
  2451. var firstFileName;
  2452. var lastFileName;
  2453. for (var i = 0; i < firstStackLines.length; ++i) {
  2454. var result = parseLineInfo(firstStackLines[i]);
  2455. if (result) {
  2456. firstFileName = result.fileName;
  2457. firstIndex = result.line;
  2458. break;
  2459. }
  2460. }
  2461. for (var i = 0; i < lastStackLines.length; ++i) {
  2462. var result = parseLineInfo(lastStackLines[i]);
  2463. if (result) {
  2464. lastFileName = result.fileName;
  2465. lastIndex = result.line;
  2466. break;
  2467. }
  2468. }
  2469. if (firstIndex < 0 || lastIndex < 0 || !firstFileName || !lastFileName ||
  2470. firstFileName !== lastFileName || firstIndex >= lastIndex) {
  2471. return;
  2472. }
  2473. shouldIgnore = function(line) {
  2474. if (bluebirdFramePattern.test(line)) return true;
  2475. var info = parseLineInfo(line);
  2476. if (info) {
  2477. if (info.fileName === firstFileName &&
  2478. (firstIndex <= info.line && info.line <= lastIndex)) {
  2479. return true;
  2480. }
  2481. }
  2482. return false;
  2483. };
  2484. }
  2485. function CapturedTrace(parent) {
  2486. this._parent = parent;
  2487. this._promisesCreated = 0;
  2488. var length = this._length = 1 + (parent === undefined ? 0 : parent._length);
  2489. captureStackTrace(this, CapturedTrace);
  2490. if (length > 32) this.uncycle();
  2491. }
  2492. util.inherits(CapturedTrace, Error);
  2493. Context.CapturedTrace = CapturedTrace;
  2494. CapturedTrace.prototype.uncycle = function() {
  2495. var length = this._length;
  2496. if (length < 2) return;
  2497. var nodes = [];
  2498. var stackToIndex = {};
  2499. for (var i = 0, node = this; node !== undefined; ++i) {
  2500. nodes.push(node);
  2501. node = node._parent;
  2502. }
  2503. length = this._length = i;
  2504. for (var i = length - 1; i >= 0; --i) {
  2505. var stack = nodes[i].stack;
  2506. if (stackToIndex[stack] === undefined) {
  2507. stackToIndex[stack] = i;
  2508. }
  2509. }
  2510. for (var i = 0; i < length; ++i) {
  2511. var currentStack = nodes[i].stack;
  2512. var index = stackToIndex[currentStack];
  2513. if (index !== undefined && index !== i) {
  2514. if (index > 0) {
  2515. nodes[index - 1]._parent = undefined;
  2516. nodes[index - 1]._length = 1;
  2517. }
  2518. nodes[i]._parent = undefined;
  2519. nodes[i]._length = 1;
  2520. var cycleEdgeNode = i > 0 ? nodes[i - 1] : this;
  2521. if (index < length - 1) {
  2522. cycleEdgeNode._parent = nodes[index + 1];
  2523. cycleEdgeNode._parent.uncycle();
  2524. cycleEdgeNode._length =
  2525. cycleEdgeNode._parent._length + 1;
  2526. } else {
  2527. cycleEdgeNode._parent = undefined;
  2528. cycleEdgeNode._length = 1;
  2529. }
  2530. var currentChildLength = cycleEdgeNode._length + 1;
  2531. for (var j = i - 2; j >= 0; --j) {
  2532. nodes[j]._length = currentChildLength;
  2533. currentChildLength++;
  2534. }
  2535. return;
  2536. }
  2537. }
  2538. };
  2539. CapturedTrace.prototype.attachExtraTrace = function(error) {
  2540. if (error.__stackCleaned__) return;
  2541. this.uncycle();
  2542. var parsed = parseStackAndMessage(error);
  2543. var message = parsed.message;
  2544. var stacks = [parsed.stack];
  2545. var trace = this;
  2546. while (trace !== undefined) {
  2547. stacks.push(cleanStack(trace.stack.split("\n")));
  2548. trace = trace._parent;
  2549. }
  2550. removeCommonRoots(stacks);
  2551. removeDuplicateOrEmptyJumps(stacks);
  2552. util.notEnumerableProp(error, "stack", reconstructStack(message, stacks));
  2553. util.notEnumerableProp(error, "__stackCleaned__", true);
  2554. };
  2555. var captureStackTrace = (function stackDetection() {
  2556. var v8stackFramePattern = /^\s*at\s*/;
  2557. var v8stackFormatter = function(stack, error) {
  2558. if (typeof stack === "string") return stack;
  2559. if (error.name !== undefined &&
  2560. error.message !== undefined) {
  2561. return error.toString();
  2562. }
  2563. return formatNonError(error);
  2564. };
  2565. if (typeof Error.stackTraceLimit === "number" &&
  2566. typeof Error.captureStackTrace === "function") {
  2567. Error.stackTraceLimit += 6;
  2568. stackFramePattern = v8stackFramePattern;
  2569. formatStack = v8stackFormatter;
  2570. var captureStackTrace = Error.captureStackTrace;
  2571. shouldIgnore = function(line) {
  2572. return bluebirdFramePattern.test(line);
  2573. };
  2574. return function(receiver, ignoreUntil) {
  2575. Error.stackTraceLimit += 6;
  2576. captureStackTrace(receiver, ignoreUntil);
  2577. Error.stackTraceLimit -= 6;
  2578. };
  2579. }
  2580. var err = new Error();
  2581. if (typeof err.stack === "string" &&
  2582. err.stack.split("\n")[0].indexOf("stackDetection@") >= 0) {
  2583. stackFramePattern = /@/;
  2584. formatStack = v8stackFormatter;
  2585. indentStackFrames = true;
  2586. return function captureStackTrace(o) {
  2587. o.stack = new Error().stack;
  2588. };
  2589. }
  2590. var hasStackAfterThrow;
  2591. try { throw new Error(); }
  2592. catch(e) {
  2593. hasStackAfterThrow = ("stack" in e);
  2594. }
  2595. if (!("stack" in err) && hasStackAfterThrow &&
  2596. typeof Error.stackTraceLimit === "number") {
  2597. stackFramePattern = v8stackFramePattern;
  2598. formatStack = v8stackFormatter;
  2599. return function captureStackTrace(o) {
  2600. Error.stackTraceLimit += 6;
  2601. try { throw new Error(); }
  2602. catch(e) { o.stack = e.stack; }
  2603. Error.stackTraceLimit -= 6;
  2604. };
  2605. }
  2606. formatStack = function(stack, error) {
  2607. if (typeof stack === "string") return stack;
  2608. if ((typeof error === "object" ||
  2609. typeof error === "function") &&
  2610. error.name !== undefined &&
  2611. error.message !== undefined) {
  2612. return error.toString();
  2613. }
  2614. return formatNonError(error);
  2615. };
  2616. return null;
  2617. })([]);
  2618. if (typeof console !== "undefined" && typeof console.warn !== "undefined") {
  2619. printWarning = function (message) {
  2620. console.warn(message);
  2621. };
  2622. if (util.isNode && process.stderr.isTTY) {
  2623. printWarning = function(message, isSoft) {
  2624. var color = isSoft ? "\u001b[33m" : "\u001b[31m";
  2625. console.warn(color + message + "\u001b[0m\n");
  2626. };
  2627. } else if (!util.isNode && typeof (new Error().stack) === "string") {
  2628. printWarning = function(message, isSoft) {
  2629. console.warn("%c" + message,
  2630. isSoft ? "color: darkorange" : "color: red");
  2631. };
  2632. }
  2633. }
  2634. var config = {
  2635. warnings: warnings,
  2636. longStackTraces: false,
  2637. cancellation: false,
  2638. monitoring: false
  2639. };
  2640. if (longStackTraces) Promise.longStackTraces();
  2641. return {
  2642. longStackTraces: function() {
  2643. return config.longStackTraces;
  2644. },
  2645. warnings: function() {
  2646. return config.warnings;
  2647. },
  2648. cancellation: function() {
  2649. return config.cancellation;
  2650. },
  2651. monitoring: function() {
  2652. return config.monitoring;
  2653. },
  2654. propagateFromFunction: function() {
  2655. return propagateFromFunction;
  2656. },
  2657. boundValueFunction: function() {
  2658. return boundValueFunction;
  2659. },
  2660. checkForgottenReturns: checkForgottenReturns,
  2661. setBounds: setBounds,
  2662. warn: warn,
  2663. deprecated: deprecated,
  2664. CapturedTrace: CapturedTrace,
  2665. fireDomEvent: fireDomEvent,
  2666. fireGlobalEvent: fireGlobalEvent
  2667. };
  2668. };
  2669. },{"./errors":12,"./util":36}],10:[function(_dereq_,module,exports){
  2670. "use strict";
  2671. module.exports = function(Promise) {
  2672. function returner() {
  2673. return this.value;
  2674. }
  2675. function thrower() {
  2676. throw this.reason;
  2677. }
  2678. Promise.prototype["return"] =
  2679. Promise.prototype.thenReturn = function (value) {
  2680. if (value instanceof Promise) value.suppressUnhandledRejections();
  2681. return this._then(
  2682. returner, undefined, undefined, {value: value}, undefined);
  2683. };
  2684. Promise.prototype["throw"] =
  2685. Promise.prototype.thenThrow = function (reason) {
  2686. return this._then(
  2687. thrower, undefined, undefined, {reason: reason}, undefined);
  2688. };
  2689. Promise.prototype.catchThrow = function (reason) {
  2690. if (arguments.length <= 1) {
  2691. return this._then(
  2692. undefined, thrower, undefined, {reason: reason}, undefined);
  2693. } else {
  2694. var _reason = arguments[1];
  2695. var handler = function() {throw _reason;};
  2696. return this.caught(reason, handler);
  2697. }
  2698. };
  2699. Promise.prototype.catchReturn = function (value) {
  2700. if (arguments.length <= 1) {
  2701. if (value instanceof Promise) value.suppressUnhandledRejections();
  2702. return this._then(
  2703. undefined, returner, undefined, {value: value}, undefined);
  2704. } else {
  2705. var _value = arguments[1];
  2706. if (_value instanceof Promise) _value.suppressUnhandledRejections();
  2707. var handler = function() {return _value;};
  2708. return this.caught(value, handler);
  2709. }
  2710. };
  2711. };
  2712. },{}],11:[function(_dereq_,module,exports){
  2713. "use strict";
  2714. module.exports = function(Promise, INTERNAL) {
  2715. var PromiseReduce = Promise.reduce;
  2716. var PromiseAll = Promise.all;
  2717. function promiseAllThis() {
  2718. return PromiseAll(this);
  2719. }
  2720. function PromiseMapSeries(promises, fn) {
  2721. return PromiseReduce(promises, fn, INTERNAL, INTERNAL);
  2722. }
  2723. Promise.prototype.each = function (fn) {
  2724. return PromiseReduce(this, fn, INTERNAL, 0)
  2725. ._then(promiseAllThis, undefined, undefined, this, undefined);
  2726. };
  2727. Promise.prototype.mapSeries = function (fn) {
  2728. return PromiseReduce(this, fn, INTERNAL, INTERNAL);
  2729. };
  2730. Promise.each = function (promises, fn) {
  2731. return PromiseReduce(promises, fn, INTERNAL, 0)
  2732. ._then(promiseAllThis, undefined, undefined, promises, undefined);
  2733. };
  2734. Promise.mapSeries = PromiseMapSeries;
  2735. };
  2736. },{}],12:[function(_dereq_,module,exports){
  2737. "use strict";
  2738. var es5 = _dereq_("./es5");
  2739. var Objectfreeze = es5.freeze;
  2740. var util = _dereq_("./util");
  2741. var inherits = util.inherits;
  2742. var notEnumerableProp = util.notEnumerableProp;
  2743. function subError(nameProperty, defaultMessage) {
  2744. function SubError(message) {
  2745. if (!(this instanceof SubError)) return new SubError(message);
  2746. notEnumerableProp(this, "message",
  2747. typeof message === "string" ? message : defaultMessage);
  2748. notEnumerableProp(this, "name", nameProperty);
  2749. if (Error.captureStackTrace) {
  2750. Error.captureStackTrace(this, this.constructor);
  2751. } else {
  2752. Error.call(this);
  2753. }
  2754. }
  2755. inherits(SubError, Error);
  2756. return SubError;
  2757. }
  2758. var _TypeError, _RangeError;
  2759. var Warning = subError("Warning", "warning");
  2760. var CancellationError = subError("CancellationError", "cancellation error");
  2761. var TimeoutError = subError("TimeoutError", "timeout error");
  2762. var AggregateError = subError("AggregateError", "aggregate error");
  2763. try {
  2764. _TypeError = TypeError;
  2765. _RangeError = RangeError;
  2766. } catch(e) {
  2767. _TypeError = subError("TypeError", "type error");
  2768. _RangeError = subError("RangeError", "range error");
  2769. }
  2770. var methods = ("join pop push shift unshift slice filter forEach some " +
  2771. "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" ");
  2772. for (var i = 0; i < methods.length; ++i) {
  2773. if (typeof Array.prototype[methods[i]] === "function") {
  2774. AggregateError.prototype[methods[i]] = Array.prototype[methods[i]];
  2775. }
  2776. }
  2777. es5.defineProperty(AggregateError.prototype, "length", {
  2778. value: 0,
  2779. configurable: false,
  2780. writable: true,
  2781. enumerable: true
  2782. });
  2783. AggregateError.prototype["isOperational"] = true;
  2784. var level = 0;
  2785. AggregateError.prototype.toString = function() {
  2786. var indent = Array(level * 4 + 1).join(" ");
  2787. var ret = "\n" + indent + "AggregateError of:" + "\n";
  2788. level++;
  2789. indent = Array(level * 4 + 1).join(" ");
  2790. for (var i = 0; i < this.length; ++i) {
  2791. var str = this[i] === this ? "[Circular AggregateError]" : this[i] + "";
  2792. var lines = str.split("\n");
  2793. for (var j = 0; j < lines.length; ++j) {
  2794. lines[j] = indent + lines[j];
  2795. }
  2796. str = lines.join("\n");
  2797. ret += str + "\n";
  2798. }
  2799. level--;
  2800. return ret;
  2801. };
  2802. function OperationalError(message) {
  2803. if (!(this instanceof OperationalError))
  2804. return new OperationalError(message);
  2805. notEnumerableProp(this, "name", "OperationalError");
  2806. notEnumerableProp(this, "message", message);
  2807. this.cause = message;
  2808. this["isOperational"] = true;
  2809. if (message instanceof Error) {
  2810. notEnumerableProp(this, "message", message.message);
  2811. notEnumerableProp(this, "stack", message.stack);
  2812. } else if (Error.captureStackTrace) {
  2813. Error.captureStackTrace(this, this.constructor);
  2814. }
  2815. }
  2816. inherits(OperationalError, Error);
  2817. var errorTypes = Error["__BluebirdErrorTypes__"];
  2818. if (!errorTypes) {
  2819. errorTypes = Objectfreeze({
  2820. CancellationError: CancellationError,
  2821. TimeoutError: TimeoutError,
  2822. OperationalError: OperationalError,
  2823. RejectionError: OperationalError,
  2824. AggregateError: AggregateError
  2825. });
  2826. es5.defineProperty(Error, "__BluebirdErrorTypes__", {
  2827. value: errorTypes,
  2828. writable: false,
  2829. enumerable: false,
  2830. configurable: false
  2831. });
  2832. }
  2833. module.exports = {
  2834. Error: Error,
  2835. TypeError: _TypeError,
  2836. RangeError: _RangeError,
  2837. CancellationError: errorTypes.CancellationError,
  2838. OperationalError: errorTypes.OperationalError,
  2839. TimeoutError: errorTypes.TimeoutError,
  2840. AggregateError: errorTypes.AggregateError,
  2841. Warning: Warning
  2842. };
  2843. },{"./es5":13,"./util":36}],13:[function(_dereq_,module,exports){
  2844. var isES5 = (function(){
  2845. "use strict";
  2846. return this === undefined;
  2847. })();
  2848. if (isES5) {
  2849. module.exports = {
  2850. freeze: Object.freeze,
  2851. defineProperty: Object.defineProperty,
  2852. getDescriptor: Object.getOwnPropertyDescriptor,
  2853. keys: Object.keys,
  2854. names: Object.getOwnPropertyNames,
  2855. getPrototypeOf: Object.getPrototypeOf,
  2856. isArray: Array.isArray,
  2857. isES5: isES5,
  2858. propertyIsWritable: function(obj, prop) {
  2859. var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
  2860. return !!(!descriptor || descriptor.writable || descriptor.set);
  2861. }
  2862. };
  2863. } else {
  2864. var has = {}.hasOwnProperty;
  2865. var str = {}.toString;
  2866. var proto = {}.constructor.prototype;
  2867. var ObjectKeys = function (o) {
  2868. var ret = [];
  2869. for (var key in o) {
  2870. if (has.call(o, key)) {
  2871. ret.push(key);
  2872. }
  2873. }
  2874. return ret;
  2875. };
  2876. var ObjectGetDescriptor = function(o, key) {
  2877. return {value: o[key]};
  2878. };
  2879. var ObjectDefineProperty = function (o, key, desc) {
  2880. o[key] = desc.value;
  2881. return o;
  2882. };
  2883. var ObjectFreeze = function (obj) {
  2884. return obj;
  2885. };
  2886. var ObjectGetPrototypeOf = function (obj) {
  2887. try {
  2888. return Object(obj).constructor.prototype;
  2889. }
  2890. catch (e) {
  2891. return proto;
  2892. }
  2893. };
  2894. var ArrayIsArray = function (obj) {
  2895. try {
  2896. return str.call(obj) === "[object Array]";
  2897. }
  2898. catch(e) {
  2899. return false;
  2900. }
  2901. };
  2902. module.exports = {
  2903. isArray: ArrayIsArray,
  2904. keys: ObjectKeys,
  2905. names: ObjectKeys,
  2906. defineProperty: ObjectDefineProperty,
  2907. getDescriptor: ObjectGetDescriptor,
  2908. freeze: ObjectFreeze,
  2909. getPrototypeOf: ObjectGetPrototypeOf,
  2910. isES5: isES5,
  2911. propertyIsWritable: function() {
  2912. return true;
  2913. }
  2914. };
  2915. }
  2916. },{}],14:[function(_dereq_,module,exports){
  2917. "use strict";
  2918. module.exports = function(Promise, INTERNAL) {
  2919. var PromiseMap = Promise.map;
  2920. Promise.prototype.filter = function (fn, options) {
  2921. return PromiseMap(this, fn, options, INTERNAL);
  2922. };
  2923. Promise.filter = function (promises, fn, options) {
  2924. return PromiseMap(promises, fn, options, INTERNAL);
  2925. };
  2926. };
  2927. },{}],15:[function(_dereq_,module,exports){
  2928. "use strict";
  2929. module.exports = function(Promise, tryConvertToPromise) {
  2930. var util = _dereq_("./util");
  2931. var CancellationError = Promise.CancellationError;
  2932. var errorObj = util.errorObj;
  2933. function PassThroughHandlerContext(promise, type, handler) {
  2934. this.promise = promise;
  2935. this.type = type;
  2936. this.handler = handler;
  2937. this.called = false;
  2938. this.cancelPromise = null;
  2939. }
  2940. PassThroughHandlerContext.prototype.isFinallyHandler = function() {
  2941. return this.type === 0;
  2942. };
  2943. function FinallyHandlerCancelReaction(finallyHandler) {
  2944. this.finallyHandler = finallyHandler;
  2945. }
  2946. FinallyHandlerCancelReaction.prototype._resultCancelled = function() {
  2947. checkCancel(this.finallyHandler);
  2948. };
  2949. function checkCancel(ctx, reason) {
  2950. if (ctx.cancelPromise != null) {
  2951. if (arguments.length > 1) {
  2952. ctx.cancelPromise._reject(reason);
  2953. } else {
  2954. ctx.cancelPromise._cancel();
  2955. }
  2956. ctx.cancelPromise = null;
  2957. return true;
  2958. }
  2959. return false;
  2960. }
  2961. function succeed() {
  2962. return finallyHandler.call(this, this.promise._target()._settledValue());
  2963. }
  2964. function fail(reason) {
  2965. if (checkCancel(this, reason)) return;
  2966. errorObj.e = reason;
  2967. return errorObj;
  2968. }
  2969. function finallyHandler(reasonOrValue) {
  2970. var promise = this.promise;
  2971. var handler = this.handler;
  2972. if (!this.called) {
  2973. this.called = true;
  2974. var ret = this.isFinallyHandler()
  2975. ? handler.call(promise._boundValue())
  2976. : handler.call(promise._boundValue(), reasonOrValue);
  2977. if (ret !== undefined) {
  2978. promise._setReturnedNonUndefined();
  2979. var maybePromise = tryConvertToPromise(ret, promise);
  2980. if (maybePromise instanceof Promise) {
  2981. if (this.cancelPromise != null) {
  2982. if (maybePromise._isCancelled()) {
  2983. var reason =
  2984. new CancellationError("late cancellation observer");
  2985. promise._attachExtraTrace(reason);
  2986. errorObj.e = reason;
  2987. return errorObj;
  2988. } else if (maybePromise.isPending()) {
  2989. maybePromise._attachCancellationCallback(
  2990. new FinallyHandlerCancelReaction(this));
  2991. }
  2992. }
  2993. return maybePromise._then(
  2994. succeed, fail, undefined, this, undefined);
  2995. }
  2996. }
  2997. }
  2998. if (promise.isRejected()) {
  2999. checkCancel(this);
  3000. errorObj.e = reasonOrValue;
  3001. return errorObj;
  3002. } else {
  3003. checkCancel(this);
  3004. return reasonOrValue;
  3005. }
  3006. }
  3007. Promise.prototype._passThrough = function(handler, type, success, fail) {
  3008. if (typeof handler !== "function") return this.then();
  3009. return this._then(success,
  3010. fail,
  3011. undefined,
  3012. new PassThroughHandlerContext(this, type, handler),
  3013. undefined);
  3014. };
  3015. Promise.prototype.lastly =
  3016. Promise.prototype["finally"] = function (handler) {
  3017. return this._passThrough(handler,
  3018. 0,
  3019. finallyHandler,
  3020. finallyHandler);
  3021. };
  3022. Promise.prototype.tap = function (handler) {
  3023. return this._passThrough(handler, 1, finallyHandler);
  3024. };
  3025. return PassThroughHandlerContext;
  3026. };
  3027. },{"./util":36}],16:[function(_dereq_,module,exports){
  3028. "use strict";
  3029. module.exports = function(Promise,
  3030. apiRejection,
  3031. INTERNAL,
  3032. tryConvertToPromise,
  3033. Proxyable,
  3034. debug) {
  3035. var errors = _dereq_("./errors");
  3036. var TypeError = errors.TypeError;
  3037. var util = _dereq_("./util");
  3038. var errorObj = util.errorObj;
  3039. var tryCatch = util.tryCatch;
  3040. var yieldHandlers = [];
  3041. function promiseFromYieldHandler(value, yieldHandlers, traceParent) {
  3042. for (var i = 0; i < yieldHandlers.length; ++i) {
  3043. traceParent._pushContext();
  3044. var result = tryCatch(yieldHandlers[i])(value);
  3045. traceParent._popContext();
  3046. if (result === errorObj) {
  3047. traceParent._pushContext();
  3048. var ret = Promise.reject(errorObj.e);
  3049. traceParent._popContext();
  3050. return ret;
  3051. }
  3052. var maybePromise = tryConvertToPromise(result, traceParent);
  3053. if (maybePromise instanceof Promise) return maybePromise;
  3054. }
  3055. return null;
  3056. }
  3057. function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) {
  3058. if (debug.cancellation()) {
  3059. var internal = new Promise(INTERNAL);
  3060. var _finallyPromise = this._finallyPromise = new Promise(INTERNAL);
  3061. this._promise = internal.lastly(function() {
  3062. return _finallyPromise;
  3063. });
  3064. internal._captureStackTrace();
  3065. internal._setOnCancel(this);
  3066. } else {
  3067. var promise = this._promise = new Promise(INTERNAL);
  3068. promise._captureStackTrace();
  3069. }
  3070. this._stack = stack;
  3071. this._generatorFunction = generatorFunction;
  3072. this._receiver = receiver;
  3073. this._generator = undefined;
  3074. this._yieldHandlers = typeof yieldHandler === "function"
  3075. ? [yieldHandler].concat(yieldHandlers)
  3076. : yieldHandlers;
  3077. this._yieldedPromise = null;
  3078. this._cancellationPhase = false;
  3079. }
  3080. util.inherits(PromiseSpawn, Proxyable);
  3081. PromiseSpawn.prototype._isResolved = function() {
  3082. return this._promise === null;
  3083. };
  3084. PromiseSpawn.prototype._cleanup = function() {
  3085. this._promise = this._generator = null;
  3086. if (debug.cancellation() && this._finallyPromise !== null) {
  3087. this._finallyPromise._fulfill();
  3088. this._finallyPromise = null;
  3089. }
  3090. };
  3091. PromiseSpawn.prototype._promiseCancelled = function() {
  3092. if (this._isResolved()) return;
  3093. var implementsReturn = typeof this._generator["return"] !== "undefined";
  3094. var result;
  3095. if (!implementsReturn) {
  3096. var reason = new Promise.CancellationError(
  3097. "generator .return() sentinel");
  3098. Promise.coroutine.returnSentinel = reason;
  3099. this._promise._attachExtraTrace(reason);
  3100. this._promise._pushContext();
  3101. result = tryCatch(this._generator["throw"]).call(this._generator,
  3102. reason);
  3103. this._promise._popContext();
  3104. } else {
  3105. this._promise._pushContext();
  3106. result = tryCatch(this._generator["return"]).call(this._generator,
  3107. undefined);
  3108. this._promise._popContext();
  3109. }
  3110. this._cancellationPhase = true;
  3111. this._yieldedPromise = null;
  3112. this._continue(result);
  3113. };
  3114. PromiseSpawn.prototype._promiseFulfilled = function(value) {
  3115. this._yieldedPromise = null;
  3116. this._promise._pushContext();
  3117. var result = tryCatch(this._generator.next).call(this._generator, value);
  3118. this._promise._popContext();
  3119. this._continue(result);
  3120. };
  3121. PromiseSpawn.prototype._promiseRejected = function(reason) {
  3122. this._yieldedPromise = null;
  3123. this._promise._attachExtraTrace(reason);
  3124. this._promise._pushContext();
  3125. var result = tryCatch(this._generator["throw"])
  3126. .call(this._generator, reason);
  3127. this._promise._popContext();
  3128. this._continue(result);
  3129. };
  3130. PromiseSpawn.prototype._resultCancelled = function() {
  3131. if (this._yieldedPromise instanceof Promise) {
  3132. var promise = this._yieldedPromise;
  3133. this._yieldedPromise = null;
  3134. promise.cancel();
  3135. }
  3136. };
  3137. PromiseSpawn.prototype.promise = function () {
  3138. return this._promise;
  3139. };
  3140. PromiseSpawn.prototype._run = function () {
  3141. this._generator = this._generatorFunction.call(this._receiver);
  3142. this._receiver =
  3143. this._generatorFunction = undefined;
  3144. this._promiseFulfilled(undefined);
  3145. };
  3146. PromiseSpawn.prototype._continue = function (result) {
  3147. var promise = this._promise;
  3148. if (result === errorObj) {
  3149. this._cleanup();
  3150. if (this._cancellationPhase) {
  3151. return promise.cancel();
  3152. } else {
  3153. return promise._rejectCallback(result.e, false);
  3154. }
  3155. }
  3156. var value = result.value;
  3157. if (result.done === true) {
  3158. this._cleanup();
  3159. if (this._cancellationPhase) {
  3160. return promise.cancel();
  3161. } else {
  3162. return promise._resolveCallback(value);
  3163. }
  3164. } else {
  3165. var maybePromise = tryConvertToPromise(value, this._promise);
  3166. if (!(maybePromise instanceof Promise)) {
  3167. maybePromise =
  3168. promiseFromYieldHandler(maybePromise,
  3169. this._yieldHandlers,
  3170. this._promise);
  3171. if (maybePromise === null) {
  3172. this._promiseRejected(
  3173. new TypeError(
  3174. "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) +
  3175. "From coroutine:\u000a" +
  3176. this._stack.split("\n").slice(1, -7).join("\n")
  3177. )
  3178. );
  3179. return;
  3180. }
  3181. }
  3182. maybePromise = maybePromise._target();
  3183. var bitField = maybePromise._bitField;
  3184. ;
  3185. if (((bitField & 50397184) === 0)) {
  3186. this._yieldedPromise = maybePromise;
  3187. maybePromise._proxy(this, null);
  3188. } else if (((bitField & 33554432) !== 0)) {
  3189. Promise._async.invoke(
  3190. this._promiseFulfilled, this, maybePromise._value()
  3191. );
  3192. } else if (((bitField & 16777216) !== 0)) {
  3193. Promise._async.invoke(
  3194. this._promiseRejected, this, maybePromise._reason()
  3195. );
  3196. } else {
  3197. this._promiseCancelled();
  3198. }
  3199. }
  3200. };
  3201. Promise.coroutine = function (generatorFunction, options) {
  3202. if (typeof generatorFunction !== "function") {
  3203. throw new TypeError("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  3204. }
  3205. var yieldHandler = Object(options).yieldHandler;
  3206. var PromiseSpawn$ = PromiseSpawn;
  3207. var stack = new Error().stack;
  3208. return function () {
  3209. var generator = generatorFunction.apply(this, arguments);
  3210. var spawn = new PromiseSpawn$(undefined, undefined, yieldHandler,
  3211. stack);
  3212. var ret = spawn.promise();
  3213. spawn._generator = generator;
  3214. spawn._promiseFulfilled(undefined);
  3215. return ret;
  3216. };
  3217. };
  3218. Promise.coroutine.addYieldHandler = function(fn) {
  3219. if (typeof fn !== "function") {
  3220. throw new TypeError("expecting a function but got " + util.classString(fn));
  3221. }
  3222. yieldHandlers.push(fn);
  3223. };
  3224. Promise.spawn = function (generatorFunction) {
  3225. debug.deprecated("Promise.spawn()", "Promise.coroutine()");
  3226. if (typeof generatorFunction !== "function") {
  3227. return apiRejection("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  3228. }
  3229. var spawn = new PromiseSpawn(generatorFunction, this);
  3230. var ret = spawn.promise();
  3231. spawn._run(Promise.spawn);
  3232. return ret;
  3233. };
  3234. };
  3235. },{"./errors":12,"./util":36}],17:[function(_dereq_,module,exports){
  3236. "use strict";
  3237. module.exports =
  3238. function(Promise, PromiseArray, tryConvertToPromise, INTERNAL, async,
  3239. getDomain) {
  3240. var util = _dereq_("./util");
  3241. var canEvaluate = util.canEvaluate;
  3242. var tryCatch = util.tryCatch;
  3243. var errorObj = util.errorObj;
  3244. var reject;
  3245. if (!true) {
  3246. if (canEvaluate) {
  3247. var thenCallback = function(i) {
  3248. return new Function("value", "holder", " \n\
  3249. 'use strict'; \n\
  3250. holder.pIndex = value; \n\
  3251. holder.checkFulfillment(this); \n\
  3252. ".replace(/Index/g, i));
  3253. };
  3254. var promiseSetter = function(i) {
  3255. return new Function("promise", "holder", " \n\
  3256. 'use strict'; \n\
  3257. holder.pIndex = promise; \n\
  3258. ".replace(/Index/g, i));
  3259. };
  3260. var generateHolderClass = function(total) {
  3261. var props = new Array(total);
  3262. for (var i = 0; i < props.length; ++i) {
  3263. props[i] = "this.p" + (i+1);
  3264. }
  3265. var assignment = props.join(" = ") + " = null;";
  3266. var cancellationCode= "var promise;\n" + props.map(function(prop) {
  3267. return " \n\
  3268. promise = " + prop + "; \n\
  3269. if (promise instanceof Promise) { \n\
  3270. promise.cancel(); \n\
  3271. } \n\
  3272. ";
  3273. }).join("\n");
  3274. var passedArguments = props.join(", ");
  3275. var name = "Holder$" + total;
  3276. var code = "return function(tryCatch, errorObj, Promise, async) { \n\
  3277. 'use strict'; \n\
  3278. function [TheName](fn) { \n\
  3279. [TheProperties] \n\
  3280. this.fn = fn; \n\
  3281. this.asyncNeeded = true; \n\
  3282. this.now = 0; \n\
  3283. } \n\
  3284. \n\
  3285. [TheName].prototype._callFunction = function(promise) { \n\
  3286. promise._pushContext(); \n\
  3287. var ret = tryCatch(this.fn)([ThePassedArguments]); \n\
  3288. promise._popContext(); \n\
  3289. if (ret === errorObj) { \n\
  3290. promise._rejectCallback(ret.e, false); \n\
  3291. } else { \n\
  3292. promise._resolveCallback(ret); \n\
  3293. } \n\
  3294. }; \n\
  3295. \n\
  3296. [TheName].prototype.checkFulfillment = function(promise) { \n\
  3297. var now = ++this.now; \n\
  3298. if (now === [TheTotal]) { \n\
  3299. if (this.asyncNeeded) { \n\
  3300. async.invoke(this._callFunction, this, promise); \n\
  3301. } else { \n\
  3302. this._callFunction(promise); \n\
  3303. } \n\
  3304. \n\
  3305. } \n\
  3306. }; \n\
  3307. \n\
  3308. [TheName].prototype._resultCancelled = function() { \n\
  3309. [CancellationCode] \n\
  3310. }; \n\
  3311. \n\
  3312. return [TheName]; \n\
  3313. }(tryCatch, errorObj, Promise, async); \n\
  3314. ";
  3315. code = code.replace(/\[TheName\]/g, name)
  3316. .replace(/\[TheTotal\]/g, total)
  3317. .replace(/\[ThePassedArguments\]/g, passedArguments)
  3318. .replace(/\[TheProperties\]/g, assignment)
  3319. .replace(/\[CancellationCode\]/g, cancellationCode);
  3320. return new Function("tryCatch", "errorObj", "Promise", "async", code)
  3321. (tryCatch, errorObj, Promise, async);
  3322. };
  3323. var holderClasses = [];
  3324. var thenCallbacks = [];
  3325. var promiseSetters = [];
  3326. for (var i = 0; i < 8; ++i) {
  3327. holderClasses.push(generateHolderClass(i + 1));
  3328. thenCallbacks.push(thenCallback(i + 1));
  3329. promiseSetters.push(promiseSetter(i + 1));
  3330. }
  3331. reject = function (reason) {
  3332. this._reject(reason);
  3333. };
  3334. }}
  3335. Promise.join = function () {
  3336. var last = arguments.length - 1;
  3337. var fn;
  3338. if (last > 0 && typeof arguments[last] === "function") {
  3339. fn = arguments[last];
  3340. if (!true) {
  3341. if (last <= 8 && canEvaluate) {
  3342. var ret = new Promise(INTERNAL);
  3343. ret._captureStackTrace();
  3344. var HolderClass = holderClasses[last - 1];
  3345. var holder = new HolderClass(fn);
  3346. var callbacks = thenCallbacks;
  3347. for (var i = 0; i < last; ++i) {
  3348. var maybePromise = tryConvertToPromise(arguments[i], ret);
  3349. if (maybePromise instanceof Promise) {
  3350. maybePromise = maybePromise._target();
  3351. var bitField = maybePromise._bitField;
  3352. ;
  3353. if (((bitField & 50397184) === 0)) {
  3354. maybePromise._then(callbacks[i], reject,
  3355. undefined, ret, holder);
  3356. promiseSetters[i](maybePromise, holder);
  3357. holder.asyncNeeded = false;
  3358. } else if (((bitField & 33554432) !== 0)) {
  3359. callbacks[i].call(ret,
  3360. maybePromise._value(), holder);
  3361. } else if (((bitField & 16777216) !== 0)) {
  3362. ret._reject(maybePromise._reason());
  3363. } else {
  3364. ret._cancel();
  3365. }
  3366. } else {
  3367. callbacks[i].call(ret, maybePromise, holder);
  3368. }
  3369. }
  3370. if (!ret._isFateSealed()) {
  3371. if (holder.asyncNeeded) {
  3372. var domain = getDomain();
  3373. if (domain !== null) {
  3374. holder.fn = util.domainBind(domain, holder.fn);
  3375. }
  3376. }
  3377. ret._setAsyncGuaranteed();
  3378. ret._setOnCancel(holder);
  3379. }
  3380. return ret;
  3381. }
  3382. }
  3383. }
  3384. var args = [].slice.call(arguments);;
  3385. if (fn) args.pop();
  3386. var ret = new PromiseArray(args).promise();
  3387. return fn !== undefined ? ret.spread(fn) : ret;
  3388. };
  3389. };
  3390. },{"./util":36}],18:[function(_dereq_,module,exports){
  3391. "use strict";
  3392. module.exports = function(Promise,
  3393. PromiseArray,
  3394. apiRejection,
  3395. tryConvertToPromise,
  3396. INTERNAL,
  3397. debug) {
  3398. var getDomain = Promise._getDomain;
  3399. var util = _dereq_("./util");
  3400. var tryCatch = util.tryCatch;
  3401. var errorObj = util.errorObj;
  3402. var async = Promise._async;
  3403. function MappingPromiseArray(promises, fn, limit, _filter) {
  3404. this.constructor$(promises);
  3405. this._promise._captureStackTrace();
  3406. var domain = getDomain();
  3407. this._callback = domain === null ? fn : util.domainBind(domain, fn);
  3408. this._preservedValues = _filter === INTERNAL
  3409. ? new Array(this.length())
  3410. : null;
  3411. this._limit = limit;
  3412. this._inFlight = 0;
  3413. this._queue = [];
  3414. async.invoke(this._asyncInit, this, undefined);
  3415. }
  3416. util.inherits(MappingPromiseArray, PromiseArray);
  3417. MappingPromiseArray.prototype._asyncInit = function() {
  3418. this._init$(undefined, -2);
  3419. };
  3420. MappingPromiseArray.prototype._init = function () {};
  3421. MappingPromiseArray.prototype._promiseFulfilled = function (value, index) {
  3422. var values = this._values;
  3423. var length = this.length();
  3424. var preservedValues = this._preservedValues;
  3425. var limit = this._limit;
  3426. if (index < 0) {
  3427. index = (index * -1) - 1;
  3428. values[index] = value;
  3429. if (limit >= 1) {
  3430. this._inFlight--;
  3431. this._drainQueue();
  3432. if (this._isResolved()) return true;
  3433. }
  3434. } else {
  3435. if (limit >= 1 && this._inFlight >= limit) {
  3436. values[index] = value;
  3437. this._queue.push(index);
  3438. return false;
  3439. }
  3440. if (preservedValues !== null) preservedValues[index] = value;
  3441. var promise = this._promise;
  3442. var callback = this._callback;
  3443. var receiver = promise._boundValue();
  3444. promise._pushContext();
  3445. var ret = tryCatch(callback).call(receiver, value, index, length);
  3446. var promiseCreated = promise._popContext();
  3447. debug.checkForgottenReturns(
  3448. ret,
  3449. promiseCreated,
  3450. preservedValues !== null ? "Promise.filter" : "Promise.map",
  3451. promise
  3452. );
  3453. if (ret === errorObj) {
  3454. this._reject(ret.e);
  3455. return true;
  3456. }
  3457. var maybePromise = tryConvertToPromise(ret, this._promise);
  3458. if (maybePromise instanceof Promise) {
  3459. maybePromise = maybePromise._target();
  3460. var bitField = maybePromise._bitField;
  3461. ;
  3462. if (((bitField & 50397184) === 0)) {
  3463. if (limit >= 1) this._inFlight++;
  3464. values[index] = maybePromise;
  3465. maybePromise._proxy(this, (index + 1) * -1);
  3466. return false;
  3467. } else if (((bitField & 33554432) !== 0)) {
  3468. ret = maybePromise._value();
  3469. } else if (((bitField & 16777216) !== 0)) {
  3470. this._reject(maybePromise._reason());
  3471. return true;
  3472. } else {
  3473. this._cancel();
  3474. return true;
  3475. }
  3476. }
  3477. values[index] = ret;
  3478. }
  3479. var totalResolved = ++this._totalResolved;
  3480. if (totalResolved >= length) {
  3481. if (preservedValues !== null) {
  3482. this._filter(values, preservedValues);
  3483. } else {
  3484. this._resolve(values);
  3485. }
  3486. return true;
  3487. }
  3488. return false;
  3489. };
  3490. MappingPromiseArray.prototype._drainQueue = function () {
  3491. var queue = this._queue;
  3492. var limit = this._limit;
  3493. var values = this._values;
  3494. while (queue.length > 0 && this._inFlight < limit) {
  3495. if (this._isResolved()) return;
  3496. var index = queue.pop();
  3497. this._promiseFulfilled(values[index], index);
  3498. }
  3499. };
  3500. MappingPromiseArray.prototype._filter = function (booleans, values) {
  3501. var len = values.length;
  3502. var ret = new Array(len);
  3503. var j = 0;
  3504. for (var i = 0; i < len; ++i) {
  3505. if (booleans[i]) ret[j++] = values[i];
  3506. }
  3507. ret.length = j;
  3508. this._resolve(ret);
  3509. };
  3510. MappingPromiseArray.prototype.preservedValues = function () {
  3511. return this._preservedValues;
  3512. };
  3513. function map(promises, fn, options, _filter) {
  3514. if (typeof fn !== "function") {
  3515. return apiRejection("expecting a function but got " + util.classString(fn));
  3516. }
  3517. var limit = 0;
  3518. if (options !== undefined) {
  3519. if (typeof options === "object" && options !== null) {
  3520. if (typeof options.concurrency !== "number") {
  3521. return Promise.reject(
  3522. new TypeError("'concurrency' must be a number but it is " +
  3523. util.classString(options.concurrency)));
  3524. }
  3525. limit = options.concurrency;
  3526. } else {
  3527. return Promise.reject(new TypeError(
  3528. "options argument must be an object but it is " +
  3529. util.classString(options)));
  3530. }
  3531. }
  3532. limit = typeof limit === "number" &&
  3533. isFinite(limit) && limit >= 1 ? limit : 0;
  3534. return new MappingPromiseArray(promises, fn, limit, _filter).promise();
  3535. }
  3536. Promise.prototype.map = function (fn, options) {
  3537. return map(this, fn, options, null);
  3538. };
  3539. Promise.map = function (promises, fn, options, _filter) {
  3540. return map(promises, fn, options, _filter);
  3541. };
  3542. };
  3543. },{"./util":36}],19:[function(_dereq_,module,exports){
  3544. "use strict";
  3545. module.exports =
  3546. function(Promise, INTERNAL, tryConvertToPromise, apiRejection, debug) {
  3547. var util = _dereq_("./util");
  3548. var tryCatch = util.tryCatch;
  3549. Promise.method = function (fn) {
  3550. if (typeof fn !== "function") {
  3551. throw new Promise.TypeError("expecting a function but got " + util.classString(fn));
  3552. }
  3553. return function () {
  3554. var ret = new Promise(INTERNAL);
  3555. ret._captureStackTrace();
  3556. ret._pushContext();
  3557. var value = tryCatch(fn).apply(this, arguments);
  3558. var promiseCreated = ret._popContext();
  3559. debug.checkForgottenReturns(
  3560. value, promiseCreated, "Promise.method", ret);
  3561. ret._resolveFromSyncValue(value);
  3562. return ret;
  3563. };
  3564. };
  3565. Promise.attempt = Promise["try"] = function (fn) {
  3566. if (typeof fn !== "function") {
  3567. return apiRejection("expecting a function but got " + util.classString(fn));
  3568. }
  3569. var ret = new Promise(INTERNAL);
  3570. ret._captureStackTrace();
  3571. ret._pushContext();
  3572. var value;
  3573. if (arguments.length > 1) {
  3574. debug.deprecated("calling Promise.try with more than 1 argument");
  3575. var arg = arguments[1];
  3576. var ctx = arguments[2];
  3577. value = util.isArray(arg) ? tryCatch(fn).apply(ctx, arg)
  3578. : tryCatch(fn).call(ctx, arg);
  3579. } else {
  3580. value = tryCatch(fn)();
  3581. }
  3582. var promiseCreated = ret._popContext();
  3583. debug.checkForgottenReturns(
  3584. value, promiseCreated, "Promise.try", ret);
  3585. ret._resolveFromSyncValue(value);
  3586. return ret;
  3587. };
  3588. Promise.prototype._resolveFromSyncValue = function (value) {
  3589. if (value === util.errorObj) {
  3590. this._rejectCallback(value.e, false);
  3591. } else {
  3592. this._resolveCallback(value, true);
  3593. }
  3594. };
  3595. };
  3596. },{"./util":36}],20:[function(_dereq_,module,exports){
  3597. "use strict";
  3598. var util = _dereq_("./util");
  3599. var maybeWrapAsError = util.maybeWrapAsError;
  3600. var errors = _dereq_("./errors");
  3601. var OperationalError = errors.OperationalError;
  3602. var es5 = _dereq_("./es5");
  3603. function isUntypedError(obj) {
  3604. return obj instanceof Error &&
  3605. es5.getPrototypeOf(obj) === Error.prototype;
  3606. }
  3607. var rErrorKey = /^(?:name|message|stack|cause)$/;
  3608. function wrapAsOperationalError(obj) {
  3609. var ret;
  3610. if (isUntypedError(obj)) {
  3611. ret = new OperationalError(obj);
  3612. ret.name = obj.name;
  3613. ret.message = obj.message;
  3614. ret.stack = obj.stack;
  3615. var keys = es5.keys(obj);
  3616. for (var i = 0; i < keys.length; ++i) {
  3617. var key = keys[i];
  3618. if (!rErrorKey.test(key)) {
  3619. ret[key] = obj[key];
  3620. }
  3621. }
  3622. return ret;
  3623. }
  3624. util.markAsOriginatingFromRejection(obj);
  3625. return obj;
  3626. }
  3627. function nodebackForPromise(promise, multiArgs) {
  3628. return function(err, value) {
  3629. if (promise === null) return;
  3630. if (err) {
  3631. var wrapped = wrapAsOperationalError(maybeWrapAsError(err));
  3632. promise._attachExtraTrace(wrapped);
  3633. promise._reject(wrapped);
  3634. } else if (!multiArgs) {
  3635. promise._fulfill(value);
  3636. } else {
  3637. var args = [].slice.call(arguments, 1);;
  3638. promise._fulfill(args);
  3639. }
  3640. promise = null;
  3641. };
  3642. }
  3643. module.exports = nodebackForPromise;
  3644. },{"./errors":12,"./es5":13,"./util":36}],21:[function(_dereq_,module,exports){
  3645. "use strict";
  3646. module.exports = function(Promise) {
  3647. var util = _dereq_("./util");
  3648. var async = Promise._async;
  3649. var tryCatch = util.tryCatch;
  3650. var errorObj = util.errorObj;
  3651. function spreadAdapter(val, nodeback) {
  3652. var promise = this;
  3653. if (!util.isArray(val)) return successAdapter.call(promise, val, nodeback);
  3654. var ret =
  3655. tryCatch(nodeback).apply(promise._boundValue(), [null].concat(val));
  3656. if (ret === errorObj) {
  3657. async.throwLater(ret.e);
  3658. }
  3659. }
  3660. function successAdapter(val, nodeback) {
  3661. var promise = this;
  3662. var receiver = promise._boundValue();
  3663. var ret = val === undefined
  3664. ? tryCatch(nodeback).call(receiver, null)
  3665. : tryCatch(nodeback).call(receiver, null, val);
  3666. if (ret === errorObj) {
  3667. async.throwLater(ret.e);
  3668. }
  3669. }
  3670. function errorAdapter(reason, nodeback) {
  3671. var promise = this;
  3672. if (!reason) {
  3673. var newReason = new Error(reason + "");
  3674. newReason.cause = reason;
  3675. reason = newReason;
  3676. }
  3677. var ret = tryCatch(nodeback).call(promise._boundValue(), reason);
  3678. if (ret === errorObj) {
  3679. async.throwLater(ret.e);
  3680. }
  3681. }
  3682. Promise.prototype.asCallback = Promise.prototype.nodeify = function (nodeback,
  3683. options) {
  3684. if (typeof nodeback == "function") {
  3685. var adapter = successAdapter;
  3686. if (options !== undefined && Object(options).spread) {
  3687. adapter = spreadAdapter;
  3688. }
  3689. this._then(
  3690. adapter,
  3691. errorAdapter,
  3692. undefined,
  3693. this,
  3694. nodeback
  3695. );
  3696. }
  3697. return this;
  3698. };
  3699. };
  3700. },{"./util":36}],22:[function(_dereq_,module,exports){
  3701. "use strict";
  3702. module.exports = function() {
  3703. var makeSelfResolutionError = function () {
  3704. return new TypeError("circular promise resolution chain\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  3705. };
  3706. var reflectHandler = function() {
  3707. return new Promise.PromiseInspection(this._target());
  3708. };
  3709. var apiRejection = function(msg) {
  3710. return Promise.reject(new TypeError(msg));
  3711. };
  3712. function Proxyable() {}
  3713. var UNDEFINED_BINDING = {};
  3714. var util = _dereq_("./util");
  3715. var getDomain;
  3716. if (util.isNode) {
  3717. getDomain = function() {
  3718. var ret = process.domain;
  3719. if (ret === undefined) ret = null;
  3720. return ret;
  3721. };
  3722. } else {
  3723. getDomain = function() {
  3724. return null;
  3725. };
  3726. }
  3727. util.notEnumerableProp(Promise, "_getDomain", getDomain);
  3728. var es5 = _dereq_("./es5");
  3729. var Async = _dereq_("./async");
  3730. var async = new Async();
  3731. es5.defineProperty(Promise, "_async", {value: async});
  3732. var errors = _dereq_("./errors");
  3733. var TypeError = Promise.TypeError = errors.TypeError;
  3734. Promise.RangeError = errors.RangeError;
  3735. var CancellationError = Promise.CancellationError = errors.CancellationError;
  3736. Promise.TimeoutError = errors.TimeoutError;
  3737. Promise.OperationalError = errors.OperationalError;
  3738. Promise.RejectionError = errors.OperationalError;
  3739. Promise.AggregateError = errors.AggregateError;
  3740. var INTERNAL = function(){};
  3741. var APPLY = {};
  3742. var NEXT_FILTER = {};
  3743. var tryConvertToPromise = _dereq_("./thenables")(Promise, INTERNAL);
  3744. var PromiseArray =
  3745. _dereq_("./promise_array")(Promise, INTERNAL,
  3746. tryConvertToPromise, apiRejection, Proxyable);
  3747. var Context = _dereq_("./context")(Promise);
  3748. /*jshint unused:false*/
  3749. var createContext = Context.create;
  3750. var debug = _dereq_("./debuggability")(Promise, Context);
  3751. var CapturedTrace = debug.CapturedTrace;
  3752. var PassThroughHandlerContext =
  3753. _dereq_("./finally")(Promise, tryConvertToPromise);
  3754. var catchFilter = _dereq_("./catch_filter")(NEXT_FILTER);
  3755. var nodebackForPromise = _dereq_("./nodeback");
  3756. var errorObj = util.errorObj;
  3757. var tryCatch = util.tryCatch;
  3758. function check(self, executor) {
  3759. if (typeof executor !== "function") {
  3760. throw new TypeError("expecting a function but got " + util.classString(executor));
  3761. }
  3762. if (self.constructor !== Promise) {
  3763. throw new TypeError("the promise constructor cannot be invoked directly\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  3764. }
  3765. }
  3766. function Promise(executor) {
  3767. this._bitField = 0;
  3768. this._fulfillmentHandler0 = undefined;
  3769. this._rejectionHandler0 = undefined;
  3770. this._promise0 = undefined;
  3771. this._receiver0 = undefined;
  3772. if (executor !== INTERNAL) {
  3773. check(this, executor);
  3774. this._resolveFromExecutor(executor);
  3775. }
  3776. this._promiseCreated();
  3777. this._fireEvent("promiseCreated", this);
  3778. }
  3779. Promise.prototype.toString = function () {
  3780. return "[object Promise]";
  3781. };
  3782. Promise.prototype.caught = Promise.prototype["catch"] = function (fn) {
  3783. var len = arguments.length;
  3784. if (len > 1) {
  3785. var catchInstances = new Array(len - 1),
  3786. j = 0, i;
  3787. for (i = 0; i < len - 1; ++i) {
  3788. var item = arguments[i];
  3789. if (util.isObject(item)) {
  3790. catchInstances[j++] = item;
  3791. } else {
  3792. return apiRejection("expecting an object but got " +
  3793. "A catch statement predicate " + util.classString(item));
  3794. }
  3795. }
  3796. catchInstances.length = j;
  3797. fn = arguments[i];
  3798. return this.then(undefined, catchFilter(catchInstances, fn, this));
  3799. }
  3800. return this.then(undefined, fn);
  3801. };
  3802. Promise.prototype.reflect = function () {
  3803. return this._then(reflectHandler,
  3804. reflectHandler, undefined, this, undefined);
  3805. };
  3806. Promise.prototype.then = function (didFulfill, didReject) {
  3807. if (debug.warnings() && arguments.length > 0 &&
  3808. typeof didFulfill !== "function" &&
  3809. typeof didReject !== "function") {
  3810. var msg = ".then() only accepts functions but was passed: " +
  3811. util.classString(didFulfill);
  3812. if (arguments.length > 1) {
  3813. msg += ", " + util.classString(didReject);
  3814. }
  3815. this._warn(msg);
  3816. }
  3817. return this._then(didFulfill, didReject, undefined, undefined, undefined);
  3818. };
  3819. Promise.prototype.done = function (didFulfill, didReject) {
  3820. var promise =
  3821. this._then(didFulfill, didReject, undefined, undefined, undefined);
  3822. promise._setIsFinal();
  3823. };
  3824. Promise.prototype.spread = function (fn) {
  3825. if (typeof fn !== "function") {
  3826. return apiRejection("expecting a function but got " + util.classString(fn));
  3827. }
  3828. return this.all()._then(fn, undefined, undefined, APPLY, undefined);
  3829. };
  3830. Promise.prototype.toJSON = function () {
  3831. var ret = {
  3832. isFulfilled: false,
  3833. isRejected: false,
  3834. fulfillmentValue: undefined,
  3835. rejectionReason: undefined
  3836. };
  3837. if (this.isFulfilled()) {
  3838. ret.fulfillmentValue = this.value();
  3839. ret.isFulfilled = true;
  3840. } else if (this.isRejected()) {
  3841. ret.rejectionReason = this.reason();
  3842. ret.isRejected = true;
  3843. }
  3844. return ret;
  3845. };
  3846. Promise.prototype.all = function () {
  3847. if (arguments.length > 0) {
  3848. this._warn(".all() was passed arguments but it does not take any");
  3849. }
  3850. return new PromiseArray(this).promise();
  3851. };
  3852. Promise.prototype.error = function (fn) {
  3853. return this.caught(util.originatesFromRejection, fn);
  3854. };
  3855. Promise.getNewLibraryCopy = module.exports;
  3856. Promise.is = function (val) {
  3857. return val instanceof Promise;
  3858. };
  3859. Promise.fromNode = Promise.fromCallback = function(fn) {
  3860. var ret = new Promise(INTERNAL);
  3861. ret._captureStackTrace();
  3862. var multiArgs = arguments.length > 1 ? !!Object(arguments[1]).multiArgs
  3863. : false;
  3864. var result = tryCatch(fn)(nodebackForPromise(ret, multiArgs));
  3865. if (result === errorObj) {
  3866. ret._rejectCallback(result.e, true);
  3867. }
  3868. if (!ret._isFateSealed()) ret._setAsyncGuaranteed();
  3869. return ret;
  3870. };
  3871. Promise.all = function (promises) {
  3872. return new PromiseArray(promises).promise();
  3873. };
  3874. Promise.cast = function (obj) {
  3875. var ret = tryConvertToPromise(obj);
  3876. if (!(ret instanceof Promise)) {
  3877. ret = new Promise(INTERNAL);
  3878. ret._captureStackTrace();
  3879. ret._setFulfilled();
  3880. ret._rejectionHandler0 = obj;
  3881. }
  3882. return ret;
  3883. };
  3884. Promise.resolve = Promise.fulfilled = Promise.cast;
  3885. Promise.reject = Promise.rejected = function (reason) {
  3886. var ret = new Promise(INTERNAL);
  3887. ret._captureStackTrace();
  3888. ret._rejectCallback(reason, true);
  3889. return ret;
  3890. };
  3891. Promise.setScheduler = function(fn) {
  3892. if (typeof fn !== "function") {
  3893. throw new TypeError("expecting a function but got " + util.classString(fn));
  3894. }
  3895. return async.setScheduler(fn);
  3896. };
  3897. Promise.prototype._then = function (
  3898. didFulfill,
  3899. didReject,
  3900. _, receiver,
  3901. internalData
  3902. ) {
  3903. var haveInternalData = internalData !== undefined;
  3904. var promise = haveInternalData ? internalData : new Promise(INTERNAL);
  3905. var target = this._target();
  3906. var bitField = target._bitField;
  3907. if (!haveInternalData) {
  3908. promise._propagateFrom(this, 3);
  3909. promise._captureStackTrace();
  3910. if (receiver === undefined &&
  3911. ((this._bitField & 2097152) !== 0)) {
  3912. if (!((bitField & 50397184) === 0)) {
  3913. receiver = this._boundValue();
  3914. } else {
  3915. receiver = target === this ? undefined : this._boundTo;
  3916. }
  3917. }
  3918. this._fireEvent("promiseChained", this, promise);
  3919. }
  3920. var domain = getDomain();
  3921. if (!((bitField & 50397184) === 0)) {
  3922. var handler, value, settler = target._settlePromiseCtx;
  3923. if (((bitField & 33554432) !== 0)) {
  3924. value = target._rejectionHandler0;
  3925. handler = didFulfill;
  3926. } else if (((bitField & 16777216) !== 0)) {
  3927. value = target._fulfillmentHandler0;
  3928. handler = didReject;
  3929. target._unsetRejectionIsUnhandled();
  3930. } else {
  3931. settler = target._settlePromiseLateCancellationObserver;
  3932. value = new CancellationError("late cancellation observer");
  3933. target._attachExtraTrace(value);
  3934. handler = didReject;
  3935. }
  3936. async.invoke(settler, target, {
  3937. handler: domain === null ? handler
  3938. : (typeof handler === "function" &&
  3939. util.domainBind(domain, handler)),
  3940. promise: promise,
  3941. receiver: receiver,
  3942. value: value
  3943. });
  3944. } else {
  3945. target._addCallbacks(didFulfill, didReject, promise, receiver, domain);
  3946. }
  3947. return promise;
  3948. };
  3949. Promise.prototype._length = function () {
  3950. return this._bitField & 65535;
  3951. };
  3952. Promise.prototype._isFateSealed = function () {
  3953. return (this._bitField & 117506048) !== 0;
  3954. };
  3955. Promise.prototype._isFollowing = function () {
  3956. return (this._bitField & 67108864) === 67108864;
  3957. };
  3958. Promise.prototype._setLength = function (len) {
  3959. this._bitField = (this._bitField & -65536) |
  3960. (len & 65535);
  3961. };
  3962. Promise.prototype._setFulfilled = function () {
  3963. this._bitField = this._bitField | 33554432;
  3964. this._fireEvent("promiseFulfilled", this);
  3965. };
  3966. Promise.prototype._setRejected = function () {
  3967. this._bitField = this._bitField | 16777216;
  3968. this._fireEvent("promiseRejected", this);
  3969. };
  3970. Promise.prototype._setFollowing = function () {
  3971. this._bitField = this._bitField | 67108864;
  3972. this._fireEvent("promiseResolved", this);
  3973. };
  3974. Promise.prototype._setIsFinal = function () {
  3975. this._bitField = this._bitField | 4194304;
  3976. };
  3977. Promise.prototype._isFinal = function () {
  3978. return (this._bitField & 4194304) > 0;
  3979. };
  3980. Promise.prototype._unsetCancelled = function() {
  3981. this._bitField = this._bitField & (~65536);
  3982. };
  3983. Promise.prototype._setCancelled = function() {
  3984. this._bitField = this._bitField | 65536;
  3985. this._fireEvent("promiseCancelled", this);
  3986. };
  3987. Promise.prototype._setWillBeCancelled = function() {
  3988. this._bitField = this._bitField | 8388608;
  3989. };
  3990. Promise.prototype._setAsyncGuaranteed = function() {
  3991. if (async.hasCustomScheduler()) return;
  3992. this._bitField = this._bitField | 134217728;
  3993. };
  3994. Promise.prototype._receiverAt = function (index) {
  3995. var ret = index === 0 ? this._receiver0 : this[
  3996. index * 4 - 4 + 3];
  3997. if (ret === UNDEFINED_BINDING) {
  3998. return undefined;
  3999. } else if (ret === undefined && this._isBound()) {
  4000. return this._boundValue();
  4001. }
  4002. return ret;
  4003. };
  4004. Promise.prototype._promiseAt = function (index) {
  4005. return this[
  4006. index * 4 - 4 + 2];
  4007. };
  4008. Promise.prototype._fulfillmentHandlerAt = function (index) {
  4009. return this[
  4010. index * 4 - 4 + 0];
  4011. };
  4012. Promise.prototype._rejectionHandlerAt = function (index) {
  4013. return this[
  4014. index * 4 - 4 + 1];
  4015. };
  4016. Promise.prototype._boundValue = function() {};
  4017. Promise.prototype._migrateCallback0 = function (follower) {
  4018. var bitField = follower._bitField;
  4019. var fulfill = follower._fulfillmentHandler0;
  4020. var reject = follower._rejectionHandler0;
  4021. var promise = follower._promise0;
  4022. var receiver = follower._receiverAt(0);
  4023. if (receiver === undefined) receiver = UNDEFINED_BINDING;
  4024. this._addCallbacks(fulfill, reject, promise, receiver, null);
  4025. };
  4026. Promise.prototype._migrateCallbackAt = function (follower, index) {
  4027. var fulfill = follower._fulfillmentHandlerAt(index);
  4028. var reject = follower._rejectionHandlerAt(index);
  4029. var promise = follower._promiseAt(index);
  4030. var receiver = follower._receiverAt(index);
  4031. if (receiver === undefined) receiver = UNDEFINED_BINDING;
  4032. this._addCallbacks(fulfill, reject, promise, receiver, null);
  4033. };
  4034. Promise.prototype._addCallbacks = function (
  4035. fulfill,
  4036. reject,
  4037. promise,
  4038. receiver,
  4039. domain
  4040. ) {
  4041. var index = this._length();
  4042. if (index >= 65535 - 4) {
  4043. index = 0;
  4044. this._setLength(0);
  4045. }
  4046. if (index === 0) {
  4047. this._promise0 = promise;
  4048. this._receiver0 = receiver;
  4049. if (typeof fulfill === "function") {
  4050. this._fulfillmentHandler0 =
  4051. domain === null ? fulfill : util.domainBind(domain, fulfill);
  4052. }
  4053. if (typeof reject === "function") {
  4054. this._rejectionHandler0 =
  4055. domain === null ? reject : util.domainBind(domain, reject);
  4056. }
  4057. } else {
  4058. var base = index * 4 - 4;
  4059. this[base + 2] = promise;
  4060. this[base + 3] = receiver;
  4061. if (typeof fulfill === "function") {
  4062. this[base + 0] =
  4063. domain === null ? fulfill : util.domainBind(domain, fulfill);
  4064. }
  4065. if (typeof reject === "function") {
  4066. this[base + 1] =
  4067. domain === null ? reject : util.domainBind(domain, reject);
  4068. }
  4069. }
  4070. this._setLength(index + 1);
  4071. return index;
  4072. };
  4073. Promise.prototype._proxy = function (proxyable, arg) {
  4074. this._addCallbacks(undefined, undefined, arg, proxyable, null);
  4075. };
  4076. Promise.prototype._resolveCallback = function(value, shouldBind) {
  4077. if (((this._bitField & 117506048) !== 0)) return;
  4078. if (value === this)
  4079. return this._rejectCallback(makeSelfResolutionError(), false);
  4080. var maybePromise = tryConvertToPromise(value, this);
  4081. if (!(maybePromise instanceof Promise)) return this._fulfill(value);
  4082. if (shouldBind) this._propagateFrom(maybePromise, 2);
  4083. var promise = maybePromise._target();
  4084. if (promise === this) {
  4085. this._reject(makeSelfResolutionError());
  4086. return;
  4087. }
  4088. var bitField = promise._bitField;
  4089. if (((bitField & 50397184) === 0)) {
  4090. var len = this._length();
  4091. if (len > 0) promise._migrateCallback0(this);
  4092. for (var i = 1; i < len; ++i) {
  4093. promise._migrateCallbackAt(this, i);
  4094. }
  4095. this._setFollowing();
  4096. this._setLength(0);
  4097. this._setFollowee(promise);
  4098. } else if (((bitField & 33554432) !== 0)) {
  4099. this._fulfill(promise._value());
  4100. } else if (((bitField & 16777216) !== 0)) {
  4101. this._reject(promise._reason());
  4102. } else {
  4103. var reason = new CancellationError("late cancellation observer");
  4104. promise._attachExtraTrace(reason);
  4105. this._reject(reason);
  4106. }
  4107. };
  4108. Promise.prototype._rejectCallback =
  4109. function(reason, synchronous, ignoreNonErrorWarnings) {
  4110. var trace = util.ensureErrorObject(reason);
  4111. var hasStack = trace === reason;
  4112. if (!hasStack && !ignoreNonErrorWarnings && debug.warnings()) {
  4113. var message = "a promise was rejected with a non-error: " +
  4114. util.classString(reason);
  4115. this._warn(message, true);
  4116. }
  4117. this._attachExtraTrace(trace, synchronous ? hasStack : false);
  4118. this._reject(reason);
  4119. };
  4120. Promise.prototype._resolveFromExecutor = function (executor) {
  4121. var promise = this;
  4122. this._captureStackTrace();
  4123. this._pushContext();
  4124. var synchronous = true;
  4125. var r = this._execute(executor, function(value) {
  4126. promise._resolveCallback(value);
  4127. }, function (reason) {
  4128. promise._rejectCallback(reason, synchronous);
  4129. });
  4130. synchronous = false;
  4131. this._popContext();
  4132. if (r !== undefined) {
  4133. promise._rejectCallback(r, true);
  4134. }
  4135. };
  4136. Promise.prototype._settlePromiseFromHandler = function (
  4137. handler, receiver, value, promise
  4138. ) {
  4139. var bitField = promise._bitField;
  4140. if (((bitField & 65536) !== 0)) return;
  4141. promise._pushContext();
  4142. var x;
  4143. if (receiver === APPLY) {
  4144. if (!value || typeof value.length !== "number") {
  4145. x = errorObj;
  4146. x.e = new TypeError("cannot .spread() a non-array: " +
  4147. util.classString(value));
  4148. } else {
  4149. x = tryCatch(handler).apply(this._boundValue(), value);
  4150. }
  4151. } else {
  4152. x = tryCatch(handler).call(receiver, value);
  4153. }
  4154. var promiseCreated = promise._popContext();
  4155. bitField = promise._bitField;
  4156. if (((bitField & 65536) !== 0)) return;
  4157. if (x === NEXT_FILTER) {
  4158. promise._reject(value);
  4159. } else if (x === errorObj) {
  4160. promise._rejectCallback(x.e, false);
  4161. } else {
  4162. debug.checkForgottenReturns(x, promiseCreated, "", promise, this);
  4163. promise._resolveCallback(x);
  4164. }
  4165. };
  4166. Promise.prototype._target = function() {
  4167. var ret = this;
  4168. while (ret._isFollowing()) ret = ret._followee();
  4169. return ret;
  4170. };
  4171. Promise.prototype._followee = function() {
  4172. return this._rejectionHandler0;
  4173. };
  4174. Promise.prototype._setFollowee = function(promise) {
  4175. this._rejectionHandler0 = promise;
  4176. };
  4177. Promise.prototype._settlePromise = function(promise, handler, receiver, value) {
  4178. var isPromise = promise instanceof Promise;
  4179. var bitField = this._bitField;
  4180. var asyncGuaranteed = ((bitField & 134217728) !== 0);
  4181. if (((bitField & 65536) !== 0)) {
  4182. if (isPromise) promise._invokeInternalOnCancel();
  4183. if (receiver instanceof PassThroughHandlerContext &&
  4184. receiver.isFinallyHandler()) {
  4185. receiver.cancelPromise = promise;
  4186. if (tryCatch(handler).call(receiver, value) === errorObj) {
  4187. promise._reject(errorObj.e);
  4188. }
  4189. } else if (handler === reflectHandler) {
  4190. promise._fulfill(reflectHandler.call(receiver));
  4191. } else if (receiver instanceof Proxyable) {
  4192. receiver._promiseCancelled(promise);
  4193. } else if (isPromise || promise instanceof PromiseArray) {
  4194. promise._cancel();
  4195. } else {
  4196. receiver.cancel();
  4197. }
  4198. } else if (typeof handler === "function") {
  4199. if (!isPromise) {
  4200. handler.call(receiver, value, promise);
  4201. } else {
  4202. if (asyncGuaranteed) promise._setAsyncGuaranteed();
  4203. this._settlePromiseFromHandler(handler, receiver, value, promise);
  4204. }
  4205. } else if (receiver instanceof Proxyable) {
  4206. if (!receiver._isResolved()) {
  4207. if (((bitField & 33554432) !== 0)) {
  4208. receiver._promiseFulfilled(value, promise);
  4209. } else {
  4210. receiver._promiseRejected(value, promise);
  4211. }
  4212. }
  4213. } else if (isPromise) {
  4214. if (asyncGuaranteed) promise._setAsyncGuaranteed();
  4215. if (((bitField & 33554432) !== 0)) {
  4216. promise._fulfill(value);
  4217. } else {
  4218. promise._reject(value);
  4219. }
  4220. }
  4221. };
  4222. Promise.prototype._settlePromiseLateCancellationObserver = function(ctx) {
  4223. var handler = ctx.handler;
  4224. var promise = ctx.promise;
  4225. var receiver = ctx.receiver;
  4226. var value = ctx.value;
  4227. if (typeof handler === "function") {
  4228. if (!(promise instanceof Promise)) {
  4229. handler.call(receiver, value, promise);
  4230. } else {
  4231. this._settlePromiseFromHandler(handler, receiver, value, promise);
  4232. }
  4233. } else if (promise instanceof Promise) {
  4234. promise._reject(value);
  4235. }
  4236. };
  4237. Promise.prototype._settlePromiseCtx = function(ctx) {
  4238. this._settlePromise(ctx.promise, ctx.handler, ctx.receiver, ctx.value);
  4239. };
  4240. Promise.prototype._settlePromise0 = function(handler, value, bitField) {
  4241. var promise = this._promise0;
  4242. var receiver = this._receiverAt(0);
  4243. this._promise0 = undefined;
  4244. this._receiver0 = undefined;
  4245. this._settlePromise(promise, handler, receiver, value);
  4246. };
  4247. Promise.prototype._clearCallbackDataAtIndex = function(index) {
  4248. var base = index * 4 - 4;
  4249. this[base + 2] =
  4250. this[base + 3] =
  4251. this[base + 0] =
  4252. this[base + 1] = undefined;
  4253. };
  4254. Promise.prototype._fulfill = function (value) {
  4255. var bitField = this._bitField;
  4256. if (((bitField & 117506048) >>> 16)) return;
  4257. if (value === this) {
  4258. var err = makeSelfResolutionError();
  4259. this._attachExtraTrace(err);
  4260. return this._reject(err);
  4261. }
  4262. this._setFulfilled();
  4263. this._rejectionHandler0 = value;
  4264. if ((bitField & 65535) > 0) {
  4265. if (((bitField & 134217728) !== 0)) {
  4266. this._settlePromises();
  4267. } else {
  4268. async.settlePromises(this);
  4269. }
  4270. }
  4271. };
  4272. Promise.prototype._reject = function (reason) {
  4273. var bitField = this._bitField;
  4274. if (((bitField & 117506048) >>> 16)) return;
  4275. this._setRejected();
  4276. this._fulfillmentHandler0 = reason;
  4277. if (this._isFinal()) {
  4278. return async.fatalError(reason, util.isNode);
  4279. }
  4280. if ((bitField & 65535) > 0) {
  4281. async.settlePromises(this);
  4282. } else {
  4283. this._ensurePossibleRejectionHandled();
  4284. }
  4285. };
  4286. Promise.prototype._fulfillPromises = function (len, value) {
  4287. for (var i = 1; i < len; i++) {
  4288. var handler = this._fulfillmentHandlerAt(i);
  4289. var promise = this._promiseAt(i);
  4290. var receiver = this._receiverAt(i);
  4291. this._clearCallbackDataAtIndex(i);
  4292. this._settlePromise(promise, handler, receiver, value);
  4293. }
  4294. };
  4295. Promise.prototype._rejectPromises = function (len, reason) {
  4296. for (var i = 1; i < len; i++) {
  4297. var handler = this._rejectionHandlerAt(i);
  4298. var promise = this._promiseAt(i);
  4299. var receiver = this._receiverAt(i);
  4300. this._clearCallbackDataAtIndex(i);
  4301. this._settlePromise(promise, handler, receiver, reason);
  4302. }
  4303. };
  4304. Promise.prototype._settlePromises = function () {
  4305. var bitField = this._bitField;
  4306. var len = (bitField & 65535);
  4307. if (len > 0) {
  4308. if (((bitField & 16842752) !== 0)) {
  4309. var reason = this._fulfillmentHandler0;
  4310. this._settlePromise0(this._rejectionHandler0, reason, bitField);
  4311. this._rejectPromises(len, reason);
  4312. } else {
  4313. var value = this._rejectionHandler0;
  4314. this._settlePromise0(this._fulfillmentHandler0, value, bitField);
  4315. this._fulfillPromises(len, value);
  4316. }
  4317. this._setLength(0);
  4318. }
  4319. this._clearCancellationData();
  4320. };
  4321. Promise.prototype._settledValue = function() {
  4322. var bitField = this._bitField;
  4323. if (((bitField & 33554432) !== 0)) {
  4324. return this._rejectionHandler0;
  4325. } else if (((bitField & 16777216) !== 0)) {
  4326. return this._fulfillmentHandler0;
  4327. }
  4328. };
  4329. function deferResolve(v) {this.promise._resolveCallback(v);}
  4330. function deferReject(v) {this.promise._rejectCallback(v, false);}
  4331. Promise.defer = Promise.pending = function() {
  4332. debug.deprecated("Promise.defer", "new Promise");
  4333. var promise = new Promise(INTERNAL);
  4334. return {
  4335. promise: promise,
  4336. resolve: deferResolve,
  4337. reject: deferReject
  4338. };
  4339. };
  4340. util.notEnumerableProp(Promise,
  4341. "_makeSelfResolutionError",
  4342. makeSelfResolutionError);
  4343. _dereq_("./method")(Promise, INTERNAL, tryConvertToPromise, apiRejection,
  4344. debug);
  4345. _dereq_("./bind")(Promise, INTERNAL, tryConvertToPromise, debug);
  4346. _dereq_("./cancel")(Promise, PromiseArray, apiRejection, debug);
  4347. _dereq_("./direct_resolve")(Promise);
  4348. _dereq_("./synchronous_inspection")(Promise);
  4349. _dereq_("./join")(
  4350. Promise, PromiseArray, tryConvertToPromise, INTERNAL, async, getDomain);
  4351. Promise.Promise = Promise;
  4352. Promise.version = "3.4.6";
  4353. _dereq_('./map.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug);
  4354. _dereq_('./call_get.js')(Promise);
  4355. _dereq_('./using.js')(Promise, apiRejection, tryConvertToPromise, createContext, INTERNAL, debug);
  4356. _dereq_('./timers.js')(Promise, INTERNAL, debug);
  4357. _dereq_('./generators.js')(Promise, apiRejection, INTERNAL, tryConvertToPromise, Proxyable, debug);
  4358. _dereq_('./nodeify.js')(Promise);
  4359. _dereq_('./promisify.js')(Promise, INTERNAL);
  4360. _dereq_('./props.js')(Promise, PromiseArray, tryConvertToPromise, apiRejection);
  4361. _dereq_('./race.js')(Promise, INTERNAL, tryConvertToPromise, apiRejection);
  4362. _dereq_('./reduce.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug);
  4363. _dereq_('./settle.js')(Promise, PromiseArray, debug);
  4364. _dereq_('./some.js')(Promise, PromiseArray, apiRejection);
  4365. _dereq_('./filter.js')(Promise, INTERNAL);
  4366. _dereq_('./each.js')(Promise, INTERNAL);
  4367. _dereq_('./any.js')(Promise);
  4368. util.toFastProperties(Promise);
  4369. util.toFastProperties(Promise.prototype);
  4370. function fillTypes(value) {
  4371. var p = new Promise(INTERNAL);
  4372. p._fulfillmentHandler0 = value;
  4373. p._rejectionHandler0 = value;
  4374. p._promise0 = value;
  4375. p._receiver0 = value;
  4376. }
  4377. // Complete slack tracking, opt out of field-type tracking and
  4378. // stabilize map
  4379. fillTypes({a: 1});
  4380. fillTypes({b: 2});
  4381. fillTypes({c: 3});
  4382. fillTypes(1);
  4383. fillTypes(function(){});
  4384. fillTypes(undefined);
  4385. fillTypes(false);
  4386. fillTypes(new Promise(INTERNAL));
  4387. debug.setBounds(Async.firstLineError, util.lastLineError);
  4388. return Promise;
  4389. };
  4390. },{"./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){
  4391. "use strict";
  4392. module.exports = function(Promise, INTERNAL, tryConvertToPromise,
  4393. apiRejection, Proxyable) {
  4394. var util = _dereq_("./util");
  4395. var isArray = util.isArray;
  4396. function toResolutionValue(val) {
  4397. switch(val) {
  4398. case -2: return [];
  4399. case -3: return {};
  4400. }
  4401. }
  4402. function PromiseArray(values) {
  4403. var promise = this._promise = new Promise(INTERNAL);
  4404. if (values instanceof Promise) {
  4405. promise._propagateFrom(values, 3);
  4406. }
  4407. promise._setOnCancel(this);
  4408. this._values = values;
  4409. this._length = 0;
  4410. this._totalResolved = 0;
  4411. this._init(undefined, -2);
  4412. }
  4413. util.inherits(PromiseArray, Proxyable);
  4414. PromiseArray.prototype.length = function () {
  4415. return this._length;
  4416. };
  4417. PromiseArray.prototype.promise = function () {
  4418. return this._promise;
  4419. };
  4420. PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) {
  4421. var values = tryConvertToPromise(this._values, this._promise);
  4422. if (values instanceof Promise) {
  4423. values = values._target();
  4424. var bitField = values._bitField;
  4425. ;
  4426. this._values = values;
  4427. if (((bitField & 50397184) === 0)) {
  4428. this._promise._setAsyncGuaranteed();
  4429. return values._then(
  4430. init,
  4431. this._reject,
  4432. undefined,
  4433. this,
  4434. resolveValueIfEmpty
  4435. );
  4436. } else if (((bitField & 33554432) !== 0)) {
  4437. values = values._value();
  4438. } else if (((bitField & 16777216) !== 0)) {
  4439. return this._reject(values._reason());
  4440. } else {
  4441. return this._cancel();
  4442. }
  4443. }
  4444. values = util.asArray(values);
  4445. if (values === null) {
  4446. var err = apiRejection(
  4447. "expecting an array or an iterable object but got " + util.classString(values)).reason();
  4448. this._promise._rejectCallback(err, false);
  4449. return;
  4450. }
  4451. if (values.length === 0) {
  4452. if (resolveValueIfEmpty === -5) {
  4453. this._resolveEmptyArray();
  4454. }
  4455. else {
  4456. this._resolve(toResolutionValue(resolveValueIfEmpty));
  4457. }
  4458. return;
  4459. }
  4460. this._iterate(values);
  4461. };
  4462. PromiseArray.prototype._iterate = function(values) {
  4463. var len = this.getActualLength(values.length);
  4464. this._length = len;
  4465. this._values = this.shouldCopyValues() ? new Array(len) : this._values;
  4466. var result = this._promise;
  4467. var isResolved = false;
  4468. var bitField = null;
  4469. for (var i = 0; i < len; ++i) {
  4470. var maybePromise = tryConvertToPromise(values[i], result);
  4471. if (maybePromise instanceof Promise) {
  4472. maybePromise = maybePromise._target();
  4473. bitField = maybePromise._bitField;
  4474. } else {
  4475. bitField = null;
  4476. }
  4477. if (isResolved) {
  4478. if (bitField !== null) {
  4479. maybePromise.suppressUnhandledRejections();
  4480. }
  4481. } else if (bitField !== null) {
  4482. if (((bitField & 50397184) === 0)) {
  4483. maybePromise._proxy(this, i);
  4484. this._values[i] = maybePromise;
  4485. } else if (((bitField & 33554432) !== 0)) {
  4486. isResolved = this._promiseFulfilled(maybePromise._value(), i);
  4487. } else if (((bitField & 16777216) !== 0)) {
  4488. isResolved = this._promiseRejected(maybePromise._reason(), i);
  4489. } else {
  4490. isResolved = this._promiseCancelled(i);
  4491. }
  4492. } else {
  4493. isResolved = this._promiseFulfilled(maybePromise, i);
  4494. }
  4495. }
  4496. if (!isResolved) result._setAsyncGuaranteed();
  4497. };
  4498. PromiseArray.prototype._isResolved = function () {
  4499. return this._values === null;
  4500. };
  4501. PromiseArray.prototype._resolve = function (value) {
  4502. this._values = null;
  4503. this._promise._fulfill(value);
  4504. };
  4505. PromiseArray.prototype._cancel = function() {
  4506. if (this._isResolved() || !this._promise._isCancellable()) return;
  4507. this._values = null;
  4508. this._promise._cancel();
  4509. };
  4510. PromiseArray.prototype._reject = function (reason) {
  4511. this._values = null;
  4512. this._promise._rejectCallback(reason, false);
  4513. };
  4514. PromiseArray.prototype._promiseFulfilled = function (value, index) {
  4515. this._values[index] = value;
  4516. var totalResolved = ++this._totalResolved;
  4517. if (totalResolved >= this._length) {
  4518. this._resolve(this._values);
  4519. return true;
  4520. }
  4521. return false;
  4522. };
  4523. PromiseArray.prototype._promiseCancelled = function() {
  4524. this._cancel();
  4525. return true;
  4526. };
  4527. PromiseArray.prototype._promiseRejected = function (reason) {
  4528. this._totalResolved++;
  4529. this._reject(reason);
  4530. return true;
  4531. };
  4532. PromiseArray.prototype._resultCancelled = function() {
  4533. if (this._isResolved()) return;
  4534. var values = this._values;
  4535. this._cancel();
  4536. if (values instanceof Promise) {
  4537. values.cancel();
  4538. } else {
  4539. for (var i = 0; i < values.length; ++i) {
  4540. if (values[i] instanceof Promise) {
  4541. values[i].cancel();
  4542. }
  4543. }
  4544. }
  4545. };
  4546. PromiseArray.prototype.shouldCopyValues = function () {
  4547. return true;
  4548. };
  4549. PromiseArray.prototype.getActualLength = function (len) {
  4550. return len;
  4551. };
  4552. return PromiseArray;
  4553. };
  4554. },{"./util":36}],24:[function(_dereq_,module,exports){
  4555. "use strict";
  4556. module.exports = function(Promise, INTERNAL) {
  4557. var THIS = {};
  4558. var util = _dereq_("./util");
  4559. var nodebackForPromise = _dereq_("./nodeback");
  4560. var withAppended = util.withAppended;
  4561. var maybeWrapAsError = util.maybeWrapAsError;
  4562. var canEvaluate = util.canEvaluate;
  4563. var TypeError = _dereq_("./errors").TypeError;
  4564. var defaultSuffix = "Async";
  4565. var defaultPromisified = {__isPromisified__: true};
  4566. var noCopyProps = [
  4567. "arity", "length",
  4568. "name",
  4569. "arguments",
  4570. "caller",
  4571. "callee",
  4572. "prototype",
  4573. "__isPromisified__"
  4574. ];
  4575. var noCopyPropsPattern = new RegExp("^(?:" + noCopyProps.join("|") + ")$");
  4576. var defaultFilter = function(name) {
  4577. return util.isIdentifier(name) &&
  4578. name.charAt(0) !== "_" &&
  4579. name !== "constructor";
  4580. };
  4581. function propsFilter(key) {
  4582. return !noCopyPropsPattern.test(key);
  4583. }
  4584. function isPromisified(fn) {
  4585. try {
  4586. return fn.__isPromisified__ === true;
  4587. }
  4588. catch (e) {
  4589. return false;
  4590. }
  4591. }
  4592. function hasPromisified(obj, key, suffix) {
  4593. var val = util.getDataPropertyOrDefault(obj, key + suffix,
  4594. defaultPromisified);
  4595. return val ? isPromisified(val) : false;
  4596. }
  4597. function checkValid(ret, suffix, suffixRegexp) {
  4598. for (var i = 0; i < ret.length; i += 2) {
  4599. var key = ret[i];
  4600. if (suffixRegexp.test(key)) {
  4601. var keyWithoutAsyncSuffix = key.replace(suffixRegexp, "");
  4602. for (var j = 0; j < ret.length; j += 2) {
  4603. if (ret[j] === keyWithoutAsyncSuffix) {
  4604. throw new TypeError("Cannot promisify an API that has normal methods with '%s'-suffix\u000a\u000a See http://goo.gl/MqrFmX\u000a"
  4605. .replace("%s", suffix));
  4606. }
  4607. }
  4608. }
  4609. }
  4610. }
  4611. function promisifiableMethods(obj, suffix, suffixRegexp, filter) {
  4612. var keys = util.inheritedDataKeys(obj);
  4613. var ret = [];
  4614. for (var i = 0; i < keys.length; ++i) {
  4615. var key = keys[i];
  4616. var value = obj[key];
  4617. var passesDefaultFilter = filter === defaultFilter
  4618. ? true : defaultFilter(key, value, obj);
  4619. if (typeof value === "function" &&
  4620. !isPromisified(value) &&
  4621. !hasPromisified(obj, key, suffix) &&
  4622. filter(key, value, obj, passesDefaultFilter)) {
  4623. ret.push(key, value);
  4624. }
  4625. }
  4626. checkValid(ret, suffix, suffixRegexp);
  4627. return ret;
  4628. }
  4629. var escapeIdentRegex = function(str) {
  4630. return str.replace(/([$])/, "\\$");
  4631. };
  4632. var makeNodePromisifiedEval;
  4633. if (!true) {
  4634. var switchCaseArgumentOrder = function(likelyArgumentCount) {
  4635. var ret = [likelyArgumentCount];
  4636. var min = Math.max(0, likelyArgumentCount - 1 - 3);
  4637. for(var i = likelyArgumentCount - 1; i >= min; --i) {
  4638. ret.push(i);
  4639. }
  4640. for(var i = likelyArgumentCount + 1; i <= 3; ++i) {
  4641. ret.push(i);
  4642. }
  4643. return ret;
  4644. };
  4645. var argumentSequence = function(argumentCount) {
  4646. return util.filledRange(argumentCount, "_arg", "");
  4647. };
  4648. var parameterDeclaration = function(parameterCount) {
  4649. return util.filledRange(
  4650. Math.max(parameterCount, 3), "_arg", "");
  4651. };
  4652. var parameterCount = function(fn) {
  4653. if (typeof fn.length === "number") {
  4654. return Math.max(Math.min(fn.length, 1023 + 1), 0);
  4655. }
  4656. return 0;
  4657. };
  4658. makeNodePromisifiedEval =
  4659. function(callback, receiver, originalName, fn, _, multiArgs) {
  4660. var newParameterCount = Math.max(0, parameterCount(fn) - 1);
  4661. var argumentOrder = switchCaseArgumentOrder(newParameterCount);
  4662. var shouldProxyThis = typeof callback === "string" || receiver === THIS;
  4663. function generateCallForArgumentCount(count) {
  4664. var args = argumentSequence(count).join(", ");
  4665. var comma = count > 0 ? ", " : "";
  4666. var ret;
  4667. if (shouldProxyThis) {
  4668. ret = "ret = callback.call(this, {{args}}, nodeback); break;\n";
  4669. } else {
  4670. ret = receiver === undefined
  4671. ? "ret = callback({{args}}, nodeback); break;\n"
  4672. : "ret = callback.call(receiver, {{args}}, nodeback); break;\n";
  4673. }
  4674. return ret.replace("{{args}}", args).replace(", ", comma);
  4675. }
  4676. function generateArgumentSwitchCase() {
  4677. var ret = "";
  4678. for (var i = 0; i < argumentOrder.length; ++i) {
  4679. ret += "case " + argumentOrder[i] +":" +
  4680. generateCallForArgumentCount(argumentOrder[i]);
  4681. }
  4682. ret += " \n\
  4683. default: \n\
  4684. var args = new Array(len + 1); \n\
  4685. var i = 0; \n\
  4686. for (var i = 0; i < len; ++i) { \n\
  4687. args[i] = arguments[i]; \n\
  4688. } \n\
  4689. args[i] = nodeback; \n\
  4690. [CodeForCall] \n\
  4691. break; \n\
  4692. ".replace("[CodeForCall]", (shouldProxyThis
  4693. ? "ret = callback.apply(this, args);\n"
  4694. : "ret = callback.apply(receiver, args);\n"));
  4695. return ret;
  4696. }
  4697. var getFunctionCode = typeof callback === "string"
  4698. ? ("this != null ? this['"+callback+"'] : fn")
  4699. : "fn";
  4700. var body = "'use strict'; \n\
  4701. var ret = function (Parameters) { \n\
  4702. 'use strict'; \n\
  4703. var len = arguments.length; \n\
  4704. var promise = new Promise(INTERNAL); \n\
  4705. promise._captureStackTrace(); \n\
  4706. var nodeback = nodebackForPromise(promise, " + multiArgs + "); \n\
  4707. var ret; \n\
  4708. var callback = tryCatch([GetFunctionCode]); \n\
  4709. switch(len) { \n\
  4710. [CodeForSwitchCase] \n\
  4711. } \n\
  4712. if (ret === errorObj) { \n\
  4713. promise._rejectCallback(maybeWrapAsError(ret.e), true, true);\n\
  4714. } \n\
  4715. if (!promise._isFateSealed()) promise._setAsyncGuaranteed(); \n\
  4716. return promise; \n\
  4717. }; \n\
  4718. notEnumerableProp(ret, '__isPromisified__', true); \n\
  4719. return ret; \n\
  4720. ".replace("[CodeForSwitchCase]", generateArgumentSwitchCase())
  4721. .replace("[GetFunctionCode]", getFunctionCode);
  4722. body = body.replace("Parameters", parameterDeclaration(newParameterCount));
  4723. return new Function("Promise",
  4724. "fn",
  4725. "receiver",
  4726. "withAppended",
  4727. "maybeWrapAsError",
  4728. "nodebackForPromise",
  4729. "tryCatch",
  4730. "errorObj",
  4731. "notEnumerableProp",
  4732. "INTERNAL",
  4733. body)(
  4734. Promise,
  4735. fn,
  4736. receiver,
  4737. withAppended,
  4738. maybeWrapAsError,
  4739. nodebackForPromise,
  4740. util.tryCatch,
  4741. util.errorObj,
  4742. util.notEnumerableProp,
  4743. INTERNAL);
  4744. };
  4745. }
  4746. function makeNodePromisifiedClosure(callback, receiver, _, fn, __, multiArgs) {
  4747. var defaultThis = (function() {return this;})();
  4748. var method = callback;
  4749. if (typeof method === "string") {
  4750. callback = fn;
  4751. }
  4752. function promisified() {
  4753. var _receiver = receiver;
  4754. if (receiver === THIS) _receiver = this;
  4755. var promise = new Promise(INTERNAL);
  4756. promise._captureStackTrace();
  4757. var cb = typeof method === "string" && this !== defaultThis
  4758. ? this[method] : callback;
  4759. var fn = nodebackForPromise(promise, multiArgs);
  4760. try {
  4761. cb.apply(_receiver, withAppended(arguments, fn));
  4762. } catch(e) {
  4763. promise._rejectCallback(maybeWrapAsError(e), true, true);
  4764. }
  4765. if (!promise._isFateSealed()) promise._setAsyncGuaranteed();
  4766. return promise;
  4767. }
  4768. util.notEnumerableProp(promisified, "__isPromisified__", true);
  4769. return promisified;
  4770. }
  4771. var makeNodePromisified = canEvaluate
  4772. ? makeNodePromisifiedEval
  4773. : makeNodePromisifiedClosure;
  4774. function promisifyAll(obj, suffix, filter, promisifier, multiArgs) {
  4775. var suffixRegexp = new RegExp(escapeIdentRegex(suffix) + "$");
  4776. var methods =
  4777. promisifiableMethods(obj, suffix, suffixRegexp, filter);
  4778. for (var i = 0, len = methods.length; i < len; i+= 2) {
  4779. var key = methods[i];
  4780. var fn = methods[i+1];
  4781. var promisifiedKey = key + suffix;
  4782. if (promisifier === makeNodePromisified) {
  4783. obj[promisifiedKey] =
  4784. makeNodePromisified(key, THIS, key, fn, suffix, multiArgs);
  4785. } else {
  4786. var promisified = promisifier(fn, function() {
  4787. return makeNodePromisified(key, THIS, key,
  4788. fn, suffix, multiArgs);
  4789. });
  4790. util.notEnumerableProp(promisified, "__isPromisified__", true);
  4791. obj[promisifiedKey] = promisified;
  4792. }
  4793. }
  4794. util.toFastProperties(obj);
  4795. return obj;
  4796. }
  4797. function promisify(callback, receiver, multiArgs) {
  4798. return makeNodePromisified(callback, receiver, undefined,
  4799. callback, null, multiArgs);
  4800. }
  4801. Promise.promisify = function (fn, options) {
  4802. if (typeof fn !== "function") {
  4803. throw new TypeError("expecting a function but got " + util.classString(fn));
  4804. }
  4805. if (isPromisified(fn)) {
  4806. return fn;
  4807. }
  4808. options = Object(options);
  4809. var receiver = options.context === undefined ? THIS : options.context;
  4810. var multiArgs = !!options.multiArgs;
  4811. var ret = promisify(fn, receiver, multiArgs);
  4812. util.copyDescriptors(fn, ret, propsFilter);
  4813. return ret;
  4814. };
  4815. Promise.promisifyAll = function (target, options) {
  4816. if (typeof target !== "function" && typeof target !== "object") {
  4817. throw new TypeError("the target of promisifyAll must be an object or a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  4818. }
  4819. options = Object(options);
  4820. var multiArgs = !!options.multiArgs;
  4821. var suffix = options.suffix;
  4822. if (typeof suffix !== "string") suffix = defaultSuffix;
  4823. var filter = options.filter;
  4824. if (typeof filter !== "function") filter = defaultFilter;
  4825. var promisifier = options.promisifier;
  4826. if (typeof promisifier !== "function") promisifier = makeNodePromisified;
  4827. if (!util.isIdentifier(suffix)) {
  4828. throw new RangeError("suffix must be a valid identifier\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  4829. }
  4830. var keys = util.inheritedDataKeys(target);
  4831. for (var i = 0; i < keys.length; ++i) {
  4832. var value = target[keys[i]];
  4833. if (keys[i] !== "constructor" &&
  4834. util.isClass(value)) {
  4835. promisifyAll(value.prototype, suffix, filter, promisifier,
  4836. multiArgs);
  4837. promisifyAll(value, suffix, filter, promisifier, multiArgs);
  4838. }
  4839. }
  4840. return promisifyAll(target, suffix, filter, promisifier, multiArgs);
  4841. };
  4842. };
  4843. },{"./errors":12,"./nodeback":20,"./util":36}],25:[function(_dereq_,module,exports){
  4844. "use strict";
  4845. module.exports = function(
  4846. Promise, PromiseArray, tryConvertToPromise, apiRejection) {
  4847. var util = _dereq_("./util");
  4848. var isObject = util.isObject;
  4849. var es5 = _dereq_("./es5");
  4850. var Es6Map;
  4851. if (typeof Map === "function") Es6Map = Map;
  4852. var mapToEntries = (function() {
  4853. var index = 0;
  4854. var size = 0;
  4855. function extractEntry(value, key) {
  4856. this[index] = value;
  4857. this[index + size] = key;
  4858. index++;
  4859. }
  4860. return function mapToEntries(map) {
  4861. size = map.size;
  4862. index = 0;
  4863. var ret = new Array(map.size * 2);
  4864. map.forEach(extractEntry, ret);
  4865. return ret;
  4866. };
  4867. })();
  4868. var entriesToMap = function(entries) {
  4869. var ret = new Es6Map();
  4870. var length = entries.length / 2 | 0;
  4871. for (var i = 0; i < length; ++i) {
  4872. var key = entries[length + i];
  4873. var value = entries[i];
  4874. ret.set(key, value);
  4875. }
  4876. return ret;
  4877. };
  4878. function PropertiesPromiseArray(obj) {
  4879. var isMap = false;
  4880. var entries;
  4881. if (Es6Map !== undefined && obj instanceof Es6Map) {
  4882. entries = mapToEntries(obj);
  4883. isMap = true;
  4884. } else {
  4885. var keys = es5.keys(obj);
  4886. var len = keys.length;
  4887. entries = new Array(len * 2);
  4888. for (var i = 0; i < len; ++i) {
  4889. var key = keys[i];
  4890. entries[i] = obj[key];
  4891. entries[i + len] = key;
  4892. }
  4893. }
  4894. this.constructor$(entries);
  4895. this._isMap = isMap;
  4896. this._init$(undefined, -3);
  4897. }
  4898. util.inherits(PropertiesPromiseArray, PromiseArray);
  4899. PropertiesPromiseArray.prototype._init = function () {};
  4900. PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) {
  4901. this._values[index] = value;
  4902. var totalResolved = ++this._totalResolved;
  4903. if (totalResolved >= this._length) {
  4904. var val;
  4905. if (this._isMap) {
  4906. val = entriesToMap(this._values);
  4907. } else {
  4908. val = {};
  4909. var keyOffset = this.length();
  4910. for (var i = 0, len = this.length(); i < len; ++i) {
  4911. val[this._values[i + keyOffset]] = this._values[i];
  4912. }
  4913. }
  4914. this._resolve(val);
  4915. return true;
  4916. }
  4917. return false;
  4918. };
  4919. PropertiesPromiseArray.prototype.shouldCopyValues = function () {
  4920. return false;
  4921. };
  4922. PropertiesPromiseArray.prototype.getActualLength = function (len) {
  4923. return len >> 1;
  4924. };
  4925. function props(promises) {
  4926. var ret;
  4927. var castValue = tryConvertToPromise(promises);
  4928. if (!isObject(castValue)) {
  4929. return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  4930. } else if (castValue instanceof Promise) {
  4931. ret = castValue._then(
  4932. Promise.props, undefined, undefined, undefined, undefined);
  4933. } else {
  4934. ret = new PropertiesPromiseArray(castValue).promise();
  4935. }
  4936. if (castValue instanceof Promise) {
  4937. ret._propagateFrom(castValue, 2);
  4938. }
  4939. return ret;
  4940. }
  4941. Promise.prototype.props = function () {
  4942. return props(this);
  4943. };
  4944. Promise.props = function (promises) {
  4945. return props(promises);
  4946. };
  4947. };
  4948. },{"./es5":13,"./util":36}],26:[function(_dereq_,module,exports){
  4949. "use strict";
  4950. function arrayMove(src, srcIndex, dst, dstIndex, len) {
  4951. for (var j = 0; j < len; ++j) {
  4952. dst[j + dstIndex] = src[j + srcIndex];
  4953. src[j + srcIndex] = void 0;
  4954. }
  4955. }
  4956. function Queue(capacity) {
  4957. this._capacity = capacity;
  4958. this._length = 0;
  4959. this._front = 0;
  4960. }
  4961. Queue.prototype._willBeOverCapacity = function (size) {
  4962. return this._capacity < size;
  4963. };
  4964. Queue.prototype._pushOne = function (arg) {
  4965. var length = this.length();
  4966. this._checkCapacity(length + 1);
  4967. var i = (this._front + length) & (this._capacity - 1);
  4968. this[i] = arg;
  4969. this._length = length + 1;
  4970. };
  4971. Queue.prototype._unshiftOne = function(value) {
  4972. var capacity = this._capacity;
  4973. this._checkCapacity(this.length() + 1);
  4974. var front = this._front;
  4975. var i = (((( front - 1 ) &
  4976. ( capacity - 1) ) ^ capacity ) - capacity );
  4977. this[i] = value;
  4978. this._front = i;
  4979. this._length = this.length() + 1;
  4980. };
  4981. Queue.prototype.unshift = function(fn, receiver, arg) {
  4982. this._unshiftOne(arg);
  4983. this._unshiftOne(receiver);
  4984. this._unshiftOne(fn);
  4985. };
  4986. Queue.prototype.push = function (fn, receiver, arg) {
  4987. var length = this.length() + 3;
  4988. if (this._willBeOverCapacity(length)) {
  4989. this._pushOne(fn);
  4990. this._pushOne(receiver);
  4991. this._pushOne(arg);
  4992. return;
  4993. }
  4994. var j = this._front + length - 3;
  4995. this._checkCapacity(length);
  4996. var wrapMask = this._capacity - 1;
  4997. this[(j + 0) & wrapMask] = fn;
  4998. this[(j + 1) & wrapMask] = receiver;
  4999. this[(j + 2) & wrapMask] = arg;
  5000. this._length = length;
  5001. };
  5002. Queue.prototype.shift = function () {
  5003. var front = this._front,
  5004. ret = this[front];
  5005. this[front] = undefined;
  5006. this._front = (front + 1) & (this._capacity - 1);
  5007. this._length--;
  5008. return ret;
  5009. };
  5010. Queue.prototype.length = function () {
  5011. return this._length;
  5012. };
  5013. Queue.prototype._checkCapacity = function (size) {
  5014. if (this._capacity < size) {
  5015. this._resizeTo(this._capacity << 1);
  5016. }
  5017. };
  5018. Queue.prototype._resizeTo = function (capacity) {
  5019. var oldCapacity = this._capacity;
  5020. this._capacity = capacity;
  5021. var front = this._front;
  5022. var length = this._length;
  5023. var moveItemsCount = (front + length) & (oldCapacity - 1);
  5024. arrayMove(this, 0, this, oldCapacity, moveItemsCount);
  5025. };
  5026. module.exports = Queue;
  5027. },{}],27:[function(_dereq_,module,exports){
  5028. "use strict";
  5029. module.exports = function(
  5030. Promise, INTERNAL, tryConvertToPromise, apiRejection) {
  5031. var util = _dereq_("./util");
  5032. var raceLater = function (promise) {
  5033. return promise.then(function(array) {
  5034. return race(array, promise);
  5035. });
  5036. };
  5037. function race(promises, parent) {
  5038. var maybePromise = tryConvertToPromise(promises);
  5039. if (maybePromise instanceof Promise) {
  5040. return raceLater(maybePromise);
  5041. } else {
  5042. promises = util.asArray(promises);
  5043. if (promises === null)
  5044. return apiRejection("expecting an array or an iterable object but got " + util.classString(promises));
  5045. }
  5046. var ret = new Promise(INTERNAL);
  5047. if (parent !== undefined) {
  5048. ret._propagateFrom(parent, 3);
  5049. }
  5050. var fulfill = ret._fulfill;
  5051. var reject = ret._reject;
  5052. for (var i = 0, len = promises.length; i < len; ++i) {
  5053. var val = promises[i];
  5054. if (val === undefined && !(i in promises)) {
  5055. continue;
  5056. }
  5057. Promise.cast(val)._then(fulfill, reject, undefined, ret, null);
  5058. }
  5059. return ret;
  5060. }
  5061. Promise.race = function (promises) {
  5062. return race(promises, undefined);
  5063. };
  5064. Promise.prototype.race = function () {
  5065. return race(this, undefined);
  5066. };
  5067. };
  5068. },{"./util":36}],28:[function(_dereq_,module,exports){
  5069. "use strict";
  5070. module.exports = function(Promise,
  5071. PromiseArray,
  5072. apiRejection,
  5073. tryConvertToPromise,
  5074. INTERNAL,
  5075. debug) {
  5076. var getDomain = Promise._getDomain;
  5077. var util = _dereq_("./util");
  5078. var tryCatch = util.tryCatch;
  5079. function ReductionPromiseArray(promises, fn, initialValue, _each) {
  5080. this.constructor$(promises);
  5081. var domain = getDomain();
  5082. this._fn = domain === null ? fn : util.domainBind(domain, fn);
  5083. if (initialValue !== undefined) {
  5084. initialValue = Promise.resolve(initialValue);
  5085. initialValue._attachCancellationCallback(this);
  5086. }
  5087. this._initialValue = initialValue;
  5088. this._currentCancellable = null;
  5089. if(_each === INTERNAL) {
  5090. this._eachValues = Array(this._length);
  5091. } else if (_each === 0) {
  5092. this._eachValues = null;
  5093. } else {
  5094. this._eachValues = undefined;
  5095. }
  5096. this._promise._captureStackTrace();
  5097. this._init$(undefined, -5);
  5098. }
  5099. util.inherits(ReductionPromiseArray, PromiseArray);
  5100. ReductionPromiseArray.prototype._gotAccum = function(accum) {
  5101. if (this._eachValues !== undefined &&
  5102. this._eachValues !== null &&
  5103. accum !== INTERNAL) {
  5104. this._eachValues.push(accum);
  5105. }
  5106. };
  5107. ReductionPromiseArray.prototype._eachComplete = function(value) {
  5108. if (this._eachValues !== null) {
  5109. this._eachValues.push(value);
  5110. }
  5111. return this._eachValues;
  5112. };
  5113. ReductionPromiseArray.prototype._init = function() {};
  5114. ReductionPromiseArray.prototype._resolveEmptyArray = function() {
  5115. this._resolve(this._eachValues !== undefined ? this._eachValues
  5116. : this._initialValue);
  5117. };
  5118. ReductionPromiseArray.prototype.shouldCopyValues = function () {
  5119. return false;
  5120. };
  5121. ReductionPromiseArray.prototype._resolve = function(value) {
  5122. this._promise._resolveCallback(value);
  5123. this._values = null;
  5124. };
  5125. ReductionPromiseArray.prototype._resultCancelled = function(sender) {
  5126. if (sender === this._initialValue) return this._cancel();
  5127. if (this._isResolved()) return;
  5128. this._resultCancelled$();
  5129. if (this._currentCancellable instanceof Promise) {
  5130. this._currentCancellable.cancel();
  5131. }
  5132. if (this._initialValue instanceof Promise) {
  5133. this._initialValue.cancel();
  5134. }
  5135. };
  5136. ReductionPromiseArray.prototype._iterate = function (values) {
  5137. this._values = values;
  5138. var value;
  5139. var i;
  5140. var length = values.length;
  5141. if (this._initialValue !== undefined) {
  5142. value = this._initialValue;
  5143. i = 0;
  5144. } else {
  5145. value = Promise.resolve(values[0]);
  5146. i = 1;
  5147. }
  5148. this._currentCancellable = value;
  5149. if (!value.isRejected()) {
  5150. for (; i < length; ++i) {
  5151. var ctx = {
  5152. accum: null,
  5153. value: values[i],
  5154. index: i,
  5155. length: length,
  5156. array: this
  5157. };
  5158. value = value._then(gotAccum, undefined, undefined, ctx, undefined);
  5159. }
  5160. }
  5161. if (this._eachValues !== undefined) {
  5162. value = value
  5163. ._then(this._eachComplete, undefined, undefined, this, undefined);
  5164. }
  5165. value._then(completed, completed, undefined, value, this);
  5166. };
  5167. Promise.prototype.reduce = function (fn, initialValue) {
  5168. return reduce(this, fn, initialValue, null);
  5169. };
  5170. Promise.reduce = function (promises, fn, initialValue, _each) {
  5171. return reduce(promises, fn, initialValue, _each);
  5172. };
  5173. function completed(valueOrReason, array) {
  5174. if (this.isFulfilled()) {
  5175. array._resolve(valueOrReason);
  5176. } else {
  5177. array._reject(valueOrReason);
  5178. }
  5179. }
  5180. function reduce(promises, fn, initialValue, _each) {
  5181. if (typeof fn !== "function") {
  5182. return apiRejection("expecting a function but got " + util.classString(fn));
  5183. }
  5184. var array = new ReductionPromiseArray(promises, fn, initialValue, _each);
  5185. return array.promise();
  5186. }
  5187. function gotAccum(accum) {
  5188. this.accum = accum;
  5189. this.array._gotAccum(accum);
  5190. var value = tryConvertToPromise(this.value, this.array._promise);
  5191. if (value instanceof Promise) {
  5192. this.array._currentCancellable = value;
  5193. return value._then(gotValue, undefined, undefined, this, undefined);
  5194. } else {
  5195. return gotValue.call(this, value);
  5196. }
  5197. }
  5198. function gotValue(value) {
  5199. var array = this.array;
  5200. var promise = array._promise;
  5201. var fn = tryCatch(array._fn);
  5202. promise._pushContext();
  5203. var ret;
  5204. if (array._eachValues !== undefined) {
  5205. ret = fn.call(promise._boundValue(), value, this.index, this.length);
  5206. } else {
  5207. ret = fn.call(promise._boundValue(),
  5208. this.accum, value, this.index, this.length);
  5209. }
  5210. if (ret instanceof Promise) {
  5211. array._currentCancellable = ret;
  5212. }
  5213. var promiseCreated = promise._popContext();
  5214. debug.checkForgottenReturns(
  5215. ret,
  5216. promiseCreated,
  5217. array._eachValues !== undefined ? "Promise.each" : "Promise.reduce",
  5218. promise
  5219. );
  5220. return ret;
  5221. }
  5222. };
  5223. },{"./util":36}],29:[function(_dereq_,module,exports){
  5224. "use strict";
  5225. var util = _dereq_("./util");
  5226. var schedule;
  5227. var noAsyncScheduler = function() {
  5228. throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  5229. };
  5230. var NativePromise = util.getNativePromise();
  5231. if (util.isNode && typeof MutationObserver === "undefined") {
  5232. var GlobalSetImmediate = global.setImmediate;
  5233. var ProcessNextTick = process.nextTick;
  5234. schedule = util.isRecentNode
  5235. ? function(fn) { GlobalSetImmediate.call(global, fn); }
  5236. : function(fn) { ProcessNextTick.call(process, fn); };
  5237. } else if (typeof NativePromise === "function" &&
  5238. typeof NativePromise.resolve === "function") {
  5239. var nativePromise = NativePromise.resolve();
  5240. schedule = function(fn) {
  5241. nativePromise.then(fn);
  5242. };
  5243. } else if ((typeof MutationObserver !== "undefined") &&
  5244. !(typeof window !== "undefined" &&
  5245. window.navigator &&
  5246. (window.navigator.standalone || window.cordova))) {
  5247. schedule = (function() {
  5248. var div = document.createElement("div");
  5249. var opts = {attributes: true};
  5250. var toggleScheduled = false;
  5251. var div2 = document.createElement("div");
  5252. var o2 = new MutationObserver(function() {
  5253. div.classList.toggle("foo");
  5254. toggleScheduled = false;
  5255. });
  5256. o2.observe(div2, opts);
  5257. var scheduleToggle = function() {
  5258. if (toggleScheduled) return;
  5259. toggleScheduled = true;
  5260. div2.classList.toggle("foo");
  5261. };
  5262. return function schedule(fn) {
  5263. var o = new MutationObserver(function() {
  5264. o.disconnect();
  5265. fn();
  5266. });
  5267. o.observe(div, opts);
  5268. scheduleToggle();
  5269. };
  5270. })();
  5271. } else if (typeof setImmediate !== "undefined") {
  5272. schedule = function (fn) {
  5273. setImmediate(fn);
  5274. };
  5275. } else if (typeof setTimeout !== "undefined") {
  5276. schedule = function (fn) {
  5277. setTimeout(fn, 0);
  5278. };
  5279. } else {
  5280. schedule = noAsyncScheduler;
  5281. }
  5282. module.exports = schedule;
  5283. },{"./util":36}],30:[function(_dereq_,module,exports){
  5284. "use strict";
  5285. module.exports =
  5286. function(Promise, PromiseArray, debug) {
  5287. var PromiseInspection = Promise.PromiseInspection;
  5288. var util = _dereq_("./util");
  5289. function SettledPromiseArray(values) {
  5290. this.constructor$(values);
  5291. }
  5292. util.inherits(SettledPromiseArray, PromiseArray);
  5293. SettledPromiseArray.prototype._promiseResolved = function (index, inspection) {
  5294. this._values[index] = inspection;
  5295. var totalResolved = ++this._totalResolved;
  5296. if (totalResolved >= this._length) {
  5297. this._resolve(this._values);
  5298. return true;
  5299. }
  5300. return false;
  5301. };
  5302. SettledPromiseArray.prototype._promiseFulfilled = function (value, index) {
  5303. var ret = new PromiseInspection();
  5304. ret._bitField = 33554432;
  5305. ret._settledValueField = value;
  5306. return this._promiseResolved(index, ret);
  5307. };
  5308. SettledPromiseArray.prototype._promiseRejected = function (reason, index) {
  5309. var ret = new PromiseInspection();
  5310. ret._bitField = 16777216;
  5311. ret._settledValueField = reason;
  5312. return this._promiseResolved(index, ret);
  5313. };
  5314. Promise.settle = function (promises) {
  5315. debug.deprecated(".settle()", ".reflect()");
  5316. return new SettledPromiseArray(promises).promise();
  5317. };
  5318. Promise.prototype.settle = function () {
  5319. return Promise.settle(this);
  5320. };
  5321. };
  5322. },{"./util":36}],31:[function(_dereq_,module,exports){
  5323. "use strict";
  5324. module.exports =
  5325. function(Promise, PromiseArray, apiRejection) {
  5326. var util = _dereq_("./util");
  5327. var RangeError = _dereq_("./errors").RangeError;
  5328. var AggregateError = _dereq_("./errors").AggregateError;
  5329. var isArray = util.isArray;
  5330. var CANCELLATION = {};
  5331. function SomePromiseArray(values) {
  5332. this.constructor$(values);
  5333. this._howMany = 0;
  5334. this._unwrap = false;
  5335. this._initialized = false;
  5336. }
  5337. util.inherits(SomePromiseArray, PromiseArray);
  5338. SomePromiseArray.prototype._init = function () {
  5339. if (!this._initialized) {
  5340. return;
  5341. }
  5342. if (this._howMany === 0) {
  5343. this._resolve([]);
  5344. return;
  5345. }
  5346. this._init$(undefined, -5);
  5347. var isArrayResolved = isArray(this._values);
  5348. if (!this._isResolved() &&
  5349. isArrayResolved &&
  5350. this._howMany > this._canPossiblyFulfill()) {
  5351. this._reject(this._getRangeError(this.length()));
  5352. }
  5353. };
  5354. SomePromiseArray.prototype.init = function () {
  5355. this._initialized = true;
  5356. this._init();
  5357. };
  5358. SomePromiseArray.prototype.setUnwrap = function () {
  5359. this._unwrap = true;
  5360. };
  5361. SomePromiseArray.prototype.howMany = function () {
  5362. return this._howMany;
  5363. };
  5364. SomePromiseArray.prototype.setHowMany = function (count) {
  5365. this._howMany = count;
  5366. };
  5367. SomePromiseArray.prototype._promiseFulfilled = function (value) {
  5368. this._addFulfilled(value);
  5369. if (this._fulfilled() === this.howMany()) {
  5370. this._values.length = this.howMany();
  5371. if (this.howMany() === 1 && this._unwrap) {
  5372. this._resolve(this._values[0]);
  5373. } else {
  5374. this._resolve(this._values);
  5375. }
  5376. return true;
  5377. }
  5378. return false;
  5379. };
  5380. SomePromiseArray.prototype._promiseRejected = function (reason) {
  5381. this._addRejected(reason);
  5382. return this._checkOutcome();
  5383. };
  5384. SomePromiseArray.prototype._promiseCancelled = function () {
  5385. if (this._values instanceof Promise || this._values == null) {
  5386. return this._cancel();
  5387. }
  5388. this._addRejected(CANCELLATION);
  5389. return this._checkOutcome();
  5390. };
  5391. SomePromiseArray.prototype._checkOutcome = function() {
  5392. if (this.howMany() > this._canPossiblyFulfill()) {
  5393. var e = new AggregateError();
  5394. for (var i = this.length(); i < this._values.length; ++i) {
  5395. if (this._values[i] !== CANCELLATION) {
  5396. e.push(this._values[i]);
  5397. }
  5398. }
  5399. if (e.length > 0) {
  5400. this._reject(e);
  5401. } else {
  5402. this._cancel();
  5403. }
  5404. return true;
  5405. }
  5406. return false;
  5407. };
  5408. SomePromiseArray.prototype._fulfilled = function () {
  5409. return this._totalResolved;
  5410. };
  5411. SomePromiseArray.prototype._rejected = function () {
  5412. return this._values.length - this.length();
  5413. };
  5414. SomePromiseArray.prototype._addRejected = function (reason) {
  5415. this._values.push(reason);
  5416. };
  5417. SomePromiseArray.prototype._addFulfilled = function (value) {
  5418. this._values[this._totalResolved++] = value;
  5419. };
  5420. SomePromiseArray.prototype._canPossiblyFulfill = function () {
  5421. return this.length() - this._rejected();
  5422. };
  5423. SomePromiseArray.prototype._getRangeError = function (count) {
  5424. var message = "Input array must contain at least " +
  5425. this._howMany + " items but contains only " + count + " items";
  5426. return new RangeError(message);
  5427. };
  5428. SomePromiseArray.prototype._resolveEmptyArray = function () {
  5429. this._reject(this._getRangeError(0));
  5430. };
  5431. function some(promises, howMany) {
  5432. if ((howMany | 0) !== howMany || howMany < 0) {
  5433. return apiRejection("expecting a positive integer\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  5434. }
  5435. var ret = new SomePromiseArray(promises);
  5436. var promise = ret.promise();
  5437. ret.setHowMany(howMany);
  5438. ret.init();
  5439. return promise;
  5440. }
  5441. Promise.some = function (promises, howMany) {
  5442. return some(promises, howMany);
  5443. };
  5444. Promise.prototype.some = function (howMany) {
  5445. return some(this, howMany);
  5446. };
  5447. Promise._SomePromiseArray = SomePromiseArray;
  5448. };
  5449. },{"./errors":12,"./util":36}],32:[function(_dereq_,module,exports){
  5450. "use strict";
  5451. module.exports = function(Promise) {
  5452. function PromiseInspection(promise) {
  5453. if (promise !== undefined) {
  5454. promise = promise._target();
  5455. this._bitField = promise._bitField;
  5456. this._settledValueField = promise._isFateSealed()
  5457. ? promise._settledValue() : undefined;
  5458. }
  5459. else {
  5460. this._bitField = 0;
  5461. this._settledValueField = undefined;
  5462. }
  5463. }
  5464. PromiseInspection.prototype._settledValue = function() {
  5465. return this._settledValueField;
  5466. };
  5467. var value = PromiseInspection.prototype.value = function () {
  5468. if (!this.isFulfilled()) {
  5469. throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  5470. }
  5471. return this._settledValue();
  5472. };
  5473. var reason = PromiseInspection.prototype.error =
  5474. PromiseInspection.prototype.reason = function () {
  5475. if (!this.isRejected()) {
  5476. throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  5477. }
  5478. return this._settledValue();
  5479. };
  5480. var isFulfilled = PromiseInspection.prototype.isFulfilled = function() {
  5481. return (this._bitField & 33554432) !== 0;
  5482. };
  5483. var isRejected = PromiseInspection.prototype.isRejected = function () {
  5484. return (this._bitField & 16777216) !== 0;
  5485. };
  5486. var isPending = PromiseInspection.prototype.isPending = function () {
  5487. return (this._bitField & 50397184) === 0;
  5488. };
  5489. var isResolved = PromiseInspection.prototype.isResolved = function () {
  5490. return (this._bitField & 50331648) !== 0;
  5491. };
  5492. PromiseInspection.prototype.isCancelled = function() {
  5493. return (this._bitField & 8454144) !== 0;
  5494. };
  5495. Promise.prototype.__isCancelled = function() {
  5496. return (this._bitField & 65536) === 65536;
  5497. };
  5498. Promise.prototype._isCancelled = function() {
  5499. return this._target().__isCancelled();
  5500. };
  5501. Promise.prototype.isCancelled = function() {
  5502. return (this._target()._bitField & 8454144) !== 0;
  5503. };
  5504. Promise.prototype.isPending = function() {
  5505. return isPending.call(this._target());
  5506. };
  5507. Promise.prototype.isRejected = function() {
  5508. return isRejected.call(this._target());
  5509. };
  5510. Promise.prototype.isFulfilled = function() {
  5511. return isFulfilled.call(this._target());
  5512. };
  5513. Promise.prototype.isResolved = function() {
  5514. return isResolved.call(this._target());
  5515. };
  5516. Promise.prototype.value = function() {
  5517. return value.call(this._target());
  5518. };
  5519. Promise.prototype.reason = function() {
  5520. var target = this._target();
  5521. target._unsetRejectionIsUnhandled();
  5522. return reason.call(target);
  5523. };
  5524. Promise.prototype._value = function() {
  5525. return this._settledValue();
  5526. };
  5527. Promise.prototype._reason = function() {
  5528. this._unsetRejectionIsUnhandled();
  5529. return this._settledValue();
  5530. };
  5531. Promise.PromiseInspection = PromiseInspection;
  5532. };
  5533. },{}],33:[function(_dereq_,module,exports){
  5534. "use strict";
  5535. module.exports = function(Promise, INTERNAL) {
  5536. var util = _dereq_("./util");
  5537. var errorObj = util.errorObj;
  5538. var isObject = util.isObject;
  5539. function tryConvertToPromise(obj, context) {
  5540. if (isObject(obj)) {
  5541. if (obj instanceof Promise) return obj;
  5542. var then = getThen(obj);
  5543. if (then === errorObj) {
  5544. if (context) context._pushContext();
  5545. var ret = Promise.reject(then.e);
  5546. if (context) context._popContext();
  5547. return ret;
  5548. } else if (typeof then === "function") {
  5549. if (isAnyBluebirdPromise(obj)) {
  5550. var ret = new Promise(INTERNAL);
  5551. obj._then(
  5552. ret._fulfill,
  5553. ret._reject,
  5554. undefined,
  5555. ret,
  5556. null
  5557. );
  5558. return ret;
  5559. }
  5560. return doThenable(obj, then, context);
  5561. }
  5562. }
  5563. return obj;
  5564. }
  5565. function doGetThen(obj) {
  5566. return obj.then;
  5567. }
  5568. function getThen(obj) {
  5569. try {
  5570. return doGetThen(obj);
  5571. } catch (e) {
  5572. errorObj.e = e;
  5573. return errorObj;
  5574. }
  5575. }
  5576. var hasProp = {}.hasOwnProperty;
  5577. function isAnyBluebirdPromise(obj) {
  5578. try {
  5579. return hasProp.call(obj, "_promise0");
  5580. } catch (e) {
  5581. return false;
  5582. }
  5583. }
  5584. function doThenable(x, then, context) {
  5585. var promise = new Promise(INTERNAL);
  5586. var ret = promise;
  5587. if (context) context._pushContext();
  5588. promise._captureStackTrace();
  5589. if (context) context._popContext();
  5590. var synchronous = true;
  5591. var result = util.tryCatch(then).call(x, resolve, reject);
  5592. synchronous = false;
  5593. if (promise && result === errorObj) {
  5594. promise._rejectCallback(result.e, true, true);
  5595. promise = null;
  5596. }
  5597. function resolve(value) {
  5598. if (!promise) return;
  5599. promise._resolveCallback(value);
  5600. promise = null;
  5601. }
  5602. function reject(reason) {
  5603. if (!promise) return;
  5604. promise._rejectCallback(reason, synchronous, true);
  5605. promise = null;
  5606. }
  5607. return ret;
  5608. }
  5609. return tryConvertToPromise;
  5610. };
  5611. },{"./util":36}],34:[function(_dereq_,module,exports){
  5612. "use strict";
  5613. module.exports = function(Promise, INTERNAL, debug) {
  5614. var util = _dereq_("./util");
  5615. var TimeoutError = Promise.TimeoutError;
  5616. function HandleWrapper(handle) {
  5617. this.handle = handle;
  5618. }
  5619. HandleWrapper.prototype._resultCancelled = function() {
  5620. clearTimeout(this.handle);
  5621. };
  5622. var afterValue = function(value) { return delay(+this).thenReturn(value); };
  5623. var delay = Promise.delay = function (ms, value) {
  5624. var ret;
  5625. var handle;
  5626. if (value !== undefined) {
  5627. ret = Promise.resolve(value)
  5628. ._then(afterValue, null, null, ms, undefined);
  5629. if (debug.cancellation() && value instanceof Promise) {
  5630. ret._setOnCancel(value);
  5631. }
  5632. } else {
  5633. ret = new Promise(INTERNAL);
  5634. handle = setTimeout(function() { ret._fulfill(); }, +ms);
  5635. if (debug.cancellation()) {
  5636. ret._setOnCancel(new HandleWrapper(handle));
  5637. }
  5638. ret._captureStackTrace();
  5639. }
  5640. ret._setAsyncGuaranteed();
  5641. return ret;
  5642. };
  5643. Promise.prototype.delay = function (ms) {
  5644. return delay(ms, this);
  5645. };
  5646. var afterTimeout = function (promise, message, parent) {
  5647. var err;
  5648. if (typeof message !== "string") {
  5649. if (message instanceof Error) {
  5650. err = message;
  5651. } else {
  5652. err = new TimeoutError("operation timed out");
  5653. }
  5654. } else {
  5655. err = new TimeoutError(message);
  5656. }
  5657. util.markAsOriginatingFromRejection(err);
  5658. promise._attachExtraTrace(err);
  5659. promise._reject(err);
  5660. if (parent != null) {
  5661. parent.cancel();
  5662. }
  5663. };
  5664. function successClear(value) {
  5665. clearTimeout(this.handle);
  5666. return value;
  5667. }
  5668. function failureClear(reason) {
  5669. clearTimeout(this.handle);
  5670. throw reason;
  5671. }
  5672. Promise.prototype.timeout = function (ms, message) {
  5673. ms = +ms;
  5674. var ret, parent;
  5675. var handleWrapper = new HandleWrapper(setTimeout(function timeoutTimeout() {
  5676. if (ret.isPending()) {
  5677. afterTimeout(ret, message, parent);
  5678. }
  5679. }, ms));
  5680. if (debug.cancellation()) {
  5681. parent = this.then();
  5682. ret = parent._then(successClear, failureClear,
  5683. undefined, handleWrapper, undefined);
  5684. ret._setOnCancel(handleWrapper);
  5685. } else {
  5686. ret = this._then(successClear, failureClear,
  5687. undefined, handleWrapper, undefined);
  5688. }
  5689. return ret;
  5690. };
  5691. };
  5692. },{"./util":36}],35:[function(_dereq_,module,exports){
  5693. "use strict";
  5694. module.exports = function (Promise, apiRejection, tryConvertToPromise,
  5695. createContext, INTERNAL, debug) {
  5696. var util = _dereq_("./util");
  5697. var TypeError = _dereq_("./errors").TypeError;
  5698. var inherits = _dereq_("./util").inherits;
  5699. var errorObj = util.errorObj;
  5700. var tryCatch = util.tryCatch;
  5701. var NULL = {};
  5702. function thrower(e) {
  5703. setTimeout(function(){throw e;}, 0);
  5704. }
  5705. function castPreservingDisposable(thenable) {
  5706. var maybePromise = tryConvertToPromise(thenable);
  5707. if (maybePromise !== thenable &&
  5708. typeof thenable._isDisposable === "function" &&
  5709. typeof thenable._getDisposer === "function" &&
  5710. thenable._isDisposable()) {
  5711. maybePromise._setDisposable(thenable._getDisposer());
  5712. }
  5713. return maybePromise;
  5714. }
  5715. function dispose(resources, inspection) {
  5716. var i = 0;
  5717. var len = resources.length;
  5718. var ret = new Promise(INTERNAL);
  5719. function iterator() {
  5720. if (i >= len) return ret._fulfill();
  5721. var maybePromise = castPreservingDisposable(resources[i++]);
  5722. if (maybePromise instanceof Promise &&
  5723. maybePromise._isDisposable()) {
  5724. try {
  5725. maybePromise = tryConvertToPromise(
  5726. maybePromise._getDisposer().tryDispose(inspection),
  5727. resources.promise);
  5728. } catch (e) {
  5729. return thrower(e);
  5730. }
  5731. if (maybePromise instanceof Promise) {
  5732. return maybePromise._then(iterator, thrower,
  5733. null, null, null);
  5734. }
  5735. }
  5736. iterator();
  5737. }
  5738. iterator();
  5739. return ret;
  5740. }
  5741. function Disposer(data, promise, context) {
  5742. this._data = data;
  5743. this._promise = promise;
  5744. this._context = context;
  5745. }
  5746. Disposer.prototype.data = function () {
  5747. return this._data;
  5748. };
  5749. Disposer.prototype.promise = function () {
  5750. return this._promise;
  5751. };
  5752. Disposer.prototype.resource = function () {
  5753. if (this.promise().isFulfilled()) {
  5754. return this.promise().value();
  5755. }
  5756. return NULL;
  5757. };
  5758. Disposer.prototype.tryDispose = function(inspection) {
  5759. var resource = this.resource();
  5760. var context = this._context;
  5761. if (context !== undefined) context._pushContext();
  5762. var ret = resource !== NULL
  5763. ? this.doDispose(resource, inspection) : null;
  5764. if (context !== undefined) context._popContext();
  5765. this._promise._unsetDisposable();
  5766. this._data = null;
  5767. return ret;
  5768. };
  5769. Disposer.isDisposer = function (d) {
  5770. return (d != null &&
  5771. typeof d.resource === "function" &&
  5772. typeof d.tryDispose === "function");
  5773. };
  5774. function FunctionDisposer(fn, promise, context) {
  5775. this.constructor$(fn, promise, context);
  5776. }
  5777. inherits(FunctionDisposer, Disposer);
  5778. FunctionDisposer.prototype.doDispose = function (resource, inspection) {
  5779. var fn = this.data();
  5780. return fn.call(resource, resource, inspection);
  5781. };
  5782. function maybeUnwrapDisposer(value) {
  5783. if (Disposer.isDisposer(value)) {
  5784. this.resources[this.index]._setDisposable(value);
  5785. return value.promise();
  5786. }
  5787. return value;
  5788. }
  5789. function ResourceList(length) {
  5790. this.length = length;
  5791. this.promise = null;
  5792. this[length-1] = null;
  5793. }
  5794. ResourceList.prototype._resultCancelled = function() {
  5795. var len = this.length;
  5796. for (var i = 0; i < len; ++i) {
  5797. var item = this[i];
  5798. if (item instanceof Promise) {
  5799. item.cancel();
  5800. }
  5801. }
  5802. };
  5803. Promise.using = function () {
  5804. var len = arguments.length;
  5805. if (len < 2) return apiRejection(
  5806. "you must pass at least 2 arguments to Promise.using");
  5807. var fn = arguments[len - 1];
  5808. if (typeof fn !== "function") {
  5809. return apiRejection("expecting a function but got " + util.classString(fn));
  5810. }
  5811. var input;
  5812. var spreadArgs = true;
  5813. if (len === 2 && Array.isArray(arguments[0])) {
  5814. input = arguments[0];
  5815. len = input.length;
  5816. spreadArgs = false;
  5817. } else {
  5818. input = arguments;
  5819. len--;
  5820. }
  5821. var resources = new ResourceList(len);
  5822. for (var i = 0; i < len; ++i) {
  5823. var resource = input[i];
  5824. if (Disposer.isDisposer(resource)) {
  5825. var disposer = resource;
  5826. resource = resource.promise();
  5827. resource._setDisposable(disposer);
  5828. } else {
  5829. var maybePromise = tryConvertToPromise(resource);
  5830. if (maybePromise instanceof Promise) {
  5831. resource =
  5832. maybePromise._then(maybeUnwrapDisposer, null, null, {
  5833. resources: resources,
  5834. index: i
  5835. }, undefined);
  5836. }
  5837. }
  5838. resources[i] = resource;
  5839. }
  5840. var reflectedResources = new Array(resources.length);
  5841. for (var i = 0; i < reflectedResources.length; ++i) {
  5842. reflectedResources[i] = Promise.resolve(resources[i]).reflect();
  5843. }
  5844. var resultPromise = Promise.all(reflectedResources)
  5845. .then(function(inspections) {
  5846. for (var i = 0; i < inspections.length; ++i) {
  5847. var inspection = inspections[i];
  5848. if (inspection.isRejected()) {
  5849. errorObj.e = inspection.error();
  5850. return errorObj;
  5851. } else if (!inspection.isFulfilled()) {
  5852. resultPromise.cancel();
  5853. return;
  5854. }
  5855. inspections[i] = inspection.value();
  5856. }
  5857. promise._pushContext();
  5858. fn = tryCatch(fn);
  5859. var ret = spreadArgs
  5860. ? fn.apply(undefined, inspections) : fn(inspections);
  5861. var promiseCreated = promise._popContext();
  5862. debug.checkForgottenReturns(
  5863. ret, promiseCreated, "Promise.using", promise);
  5864. return ret;
  5865. });
  5866. var promise = resultPromise.lastly(function() {
  5867. var inspection = new Promise.PromiseInspection(resultPromise);
  5868. return dispose(resources, inspection);
  5869. });
  5870. resources.promise = promise;
  5871. promise._setOnCancel(resources);
  5872. return promise;
  5873. };
  5874. Promise.prototype._setDisposable = function (disposer) {
  5875. this._bitField = this._bitField | 131072;
  5876. this._disposer = disposer;
  5877. };
  5878. Promise.prototype._isDisposable = function () {
  5879. return (this._bitField & 131072) > 0;
  5880. };
  5881. Promise.prototype._getDisposer = function () {
  5882. return this._disposer;
  5883. };
  5884. Promise.prototype._unsetDisposable = function () {
  5885. this._bitField = this._bitField & (~131072);
  5886. this._disposer = undefined;
  5887. };
  5888. Promise.prototype.disposer = function (fn) {
  5889. if (typeof fn === "function") {
  5890. return new FunctionDisposer(fn, this, createContext());
  5891. }
  5892. throw new TypeError();
  5893. };
  5894. };
  5895. },{"./errors":12,"./util":36}],36:[function(_dereq_,module,exports){
  5896. "use strict";
  5897. var es5 = _dereq_("./es5");
  5898. var canEvaluate = typeof navigator == "undefined";
  5899. var errorObj = {e: {}};
  5900. var tryCatchTarget;
  5901. var globalObject = typeof self !== "undefined" ? self :
  5902. typeof window !== "undefined" ? window :
  5903. typeof global !== "undefined" ? global :
  5904. this !== undefined ? this : null;
  5905. function tryCatcher() {
  5906. try {
  5907. var target = tryCatchTarget;
  5908. tryCatchTarget = null;
  5909. return target.apply(this, arguments);
  5910. } catch (e) {
  5911. errorObj.e = e;
  5912. return errorObj;
  5913. }
  5914. }
  5915. function tryCatch(fn) {
  5916. tryCatchTarget = fn;
  5917. return tryCatcher;
  5918. }
  5919. var inherits = function(Child, Parent) {
  5920. var hasProp = {}.hasOwnProperty;
  5921. function T() {
  5922. this.constructor = Child;
  5923. this.constructor$ = Parent;
  5924. for (var propertyName in Parent.prototype) {
  5925. if (hasProp.call(Parent.prototype, propertyName) &&
  5926. propertyName.charAt(propertyName.length-1) !== "$"
  5927. ) {
  5928. this[propertyName + "$"] = Parent.prototype[propertyName];
  5929. }
  5930. }
  5931. }
  5932. T.prototype = Parent.prototype;
  5933. Child.prototype = new T();
  5934. return Child.prototype;
  5935. };
  5936. function isPrimitive(val) {
  5937. return val == null || val === true || val === false ||
  5938. typeof val === "string" || typeof val === "number";
  5939. }
  5940. function isObject(value) {
  5941. return typeof value === "function" ||
  5942. typeof value === "object" && value !== null;
  5943. }
  5944. function maybeWrapAsError(maybeError) {
  5945. if (!isPrimitive(maybeError)) return maybeError;
  5946. return new Error(safeToString(maybeError));
  5947. }
  5948. function withAppended(target, appendee) {
  5949. var len = target.length;
  5950. var ret = new Array(len + 1);
  5951. var i;
  5952. for (i = 0; i < len; ++i) {
  5953. ret[i] = target[i];
  5954. }
  5955. ret[i] = appendee;
  5956. return ret;
  5957. }
  5958. function getDataPropertyOrDefault(obj, key, defaultValue) {
  5959. if (es5.isES5) {
  5960. var desc = Object.getOwnPropertyDescriptor(obj, key);
  5961. if (desc != null) {
  5962. return desc.get == null && desc.set == null
  5963. ? desc.value
  5964. : defaultValue;
  5965. }
  5966. } else {
  5967. return {}.hasOwnProperty.call(obj, key) ? obj[key] : undefined;
  5968. }
  5969. }
  5970. function notEnumerableProp(obj, name, value) {
  5971. if (isPrimitive(obj)) return obj;
  5972. var descriptor = {
  5973. value: value,
  5974. configurable: true,
  5975. enumerable: false,
  5976. writable: true
  5977. };
  5978. es5.defineProperty(obj, name, descriptor);
  5979. return obj;
  5980. }
  5981. function thrower(r) {
  5982. throw r;
  5983. }
  5984. var inheritedDataKeys = (function() {
  5985. var excludedPrototypes = [
  5986. Array.prototype,
  5987. Object.prototype,
  5988. Function.prototype
  5989. ];
  5990. var isExcludedProto = function(val) {
  5991. for (var i = 0; i < excludedPrototypes.length; ++i) {
  5992. if (excludedPrototypes[i] === val) {
  5993. return true;
  5994. }
  5995. }
  5996. return false;
  5997. };
  5998. if (es5.isES5) {
  5999. var getKeys = Object.getOwnPropertyNames;
  6000. return function(obj) {
  6001. var ret = [];
  6002. var visitedKeys = Object.create(null);
  6003. while (obj != null && !isExcludedProto(obj)) {
  6004. var keys;
  6005. try {
  6006. keys = getKeys(obj);
  6007. } catch (e) {
  6008. return ret;
  6009. }
  6010. for (var i = 0; i < keys.length; ++i) {
  6011. var key = keys[i];
  6012. if (visitedKeys[key]) continue;
  6013. visitedKeys[key] = true;
  6014. var desc = Object.getOwnPropertyDescriptor(obj, key);
  6015. if (desc != null && desc.get == null && desc.set == null) {
  6016. ret.push(key);
  6017. }
  6018. }
  6019. obj = es5.getPrototypeOf(obj);
  6020. }
  6021. return ret;
  6022. };
  6023. } else {
  6024. var hasProp = {}.hasOwnProperty;
  6025. return function(obj) {
  6026. if (isExcludedProto(obj)) return [];
  6027. var ret = [];
  6028. /*jshint forin:false */
  6029. enumeration: for (var key in obj) {
  6030. if (hasProp.call(obj, key)) {
  6031. ret.push(key);
  6032. } else {
  6033. for (var i = 0; i < excludedPrototypes.length; ++i) {
  6034. if (hasProp.call(excludedPrototypes[i], key)) {
  6035. continue enumeration;
  6036. }
  6037. }
  6038. ret.push(key);
  6039. }
  6040. }
  6041. return ret;
  6042. };
  6043. }
  6044. })();
  6045. var thisAssignmentPattern = /this\s*\.\s*\S+\s*=/;
  6046. function isClass(fn) {
  6047. try {
  6048. if (typeof fn === "function") {
  6049. var keys = es5.names(fn.prototype);
  6050. var hasMethods = es5.isES5 && keys.length > 1;
  6051. var hasMethodsOtherThanConstructor = keys.length > 0 &&
  6052. !(keys.length === 1 && keys[0] === "constructor");
  6053. var hasThisAssignmentAndStaticMethods =
  6054. thisAssignmentPattern.test(fn + "") && es5.names(fn).length > 0;
  6055. if (hasMethods || hasMethodsOtherThanConstructor ||
  6056. hasThisAssignmentAndStaticMethods) {
  6057. return true;
  6058. }
  6059. }
  6060. return false;
  6061. } catch (e) {
  6062. return false;
  6063. }
  6064. }
  6065. function toFastProperties(obj) {
  6066. /*jshint -W027,-W055,-W031*/
  6067. function FakeConstructor() {}
  6068. FakeConstructor.prototype = obj;
  6069. var l = 8;
  6070. while (l--) new FakeConstructor();
  6071. return obj;
  6072. eval(obj);
  6073. }
  6074. var rident = /^[a-z$_][a-z$_0-9]*$/i;
  6075. function isIdentifier(str) {
  6076. return rident.test(str);
  6077. }
  6078. function filledRange(count, prefix, suffix) {
  6079. var ret = new Array(count);
  6080. for(var i = 0; i < count; ++i) {
  6081. ret[i] = prefix + i + suffix;
  6082. }
  6083. return ret;
  6084. }
  6085. function safeToString(obj) {
  6086. try {
  6087. return obj + "";
  6088. } catch (e) {
  6089. return "[no string representation]";
  6090. }
  6091. }
  6092. function isError(obj) {
  6093. return obj !== null &&
  6094. typeof obj === "object" &&
  6095. typeof obj.message === "string" &&
  6096. typeof obj.name === "string";
  6097. }
  6098. function markAsOriginatingFromRejection(e) {
  6099. try {
  6100. notEnumerableProp(e, "isOperational", true);
  6101. }
  6102. catch(ignore) {}
  6103. }
  6104. function originatesFromRejection(e) {
  6105. if (e == null) return false;
  6106. return ((e instanceof Error["__BluebirdErrorTypes__"].OperationalError) ||
  6107. e["isOperational"] === true);
  6108. }
  6109. function canAttachTrace(obj) {
  6110. return isError(obj) && es5.propertyIsWritable(obj, "stack");
  6111. }
  6112. var ensureErrorObject = (function() {
  6113. if (!("stack" in new Error())) {
  6114. return function(value) {
  6115. if (canAttachTrace(value)) return value;
  6116. try {throw new Error(safeToString(value));}
  6117. catch(err) {return err;}
  6118. };
  6119. } else {
  6120. return function(value) {
  6121. if (canAttachTrace(value)) return value;
  6122. return new Error(safeToString(value));
  6123. };
  6124. }
  6125. })();
  6126. function classString(obj) {
  6127. return {}.toString.call(obj);
  6128. }
  6129. function copyDescriptors(from, to, filter) {
  6130. var keys = es5.names(from);
  6131. for (var i = 0; i < keys.length; ++i) {
  6132. var key = keys[i];
  6133. if (filter(key)) {
  6134. try {
  6135. es5.defineProperty(to, key, es5.getDescriptor(from, key));
  6136. } catch (ignore) {}
  6137. }
  6138. }
  6139. }
  6140. var asArray = function(v) {
  6141. if (es5.isArray(v)) {
  6142. return v;
  6143. }
  6144. return null;
  6145. };
  6146. if (typeof Symbol !== "undefined" && Symbol.iterator) {
  6147. var ArrayFrom = typeof Array.from === "function" ? function(v) {
  6148. return Array.from(v);
  6149. } : function(v) {
  6150. var ret = [];
  6151. var it = v[Symbol.iterator]();
  6152. var itResult;
  6153. while (!((itResult = it.next()).done)) {
  6154. ret.push(itResult.value);
  6155. }
  6156. return ret;
  6157. };
  6158. asArray = function(v) {
  6159. if (es5.isArray(v)) {
  6160. return v;
  6161. } else if (v != null && typeof v[Symbol.iterator] === "function") {
  6162. return ArrayFrom(v);
  6163. }
  6164. return null;
  6165. };
  6166. }
  6167. var isNode = typeof process !== "undefined" &&
  6168. classString(process).toLowerCase() === "[object process]";
  6169. function env(key, def) {
  6170. return isNode ? process.env[key] : def;
  6171. }
  6172. function getNativePromise() {
  6173. if (typeof Promise === "function") {
  6174. try {
  6175. var promise = new Promise(function(){});
  6176. if ({}.toString.call(promise) === "[object Promise]") {
  6177. return Promise;
  6178. }
  6179. } catch (e) {}
  6180. }
  6181. }
  6182. function domainBind(self, cb) {
  6183. return self.bind(cb);
  6184. }
  6185. var ret = {
  6186. isClass: isClass,
  6187. isIdentifier: isIdentifier,
  6188. inheritedDataKeys: inheritedDataKeys,
  6189. getDataPropertyOrDefault: getDataPropertyOrDefault,
  6190. thrower: thrower,
  6191. isArray: es5.isArray,
  6192. asArray: asArray,
  6193. notEnumerableProp: notEnumerableProp,
  6194. isPrimitive: isPrimitive,
  6195. isObject: isObject,
  6196. isError: isError,
  6197. canEvaluate: canEvaluate,
  6198. errorObj: errorObj,
  6199. tryCatch: tryCatch,
  6200. inherits: inherits,
  6201. withAppended: withAppended,
  6202. maybeWrapAsError: maybeWrapAsError,
  6203. toFastProperties: toFastProperties,
  6204. filledRange: filledRange,
  6205. toString: safeToString,
  6206. canAttachTrace: canAttachTrace,
  6207. ensureErrorObject: ensureErrorObject,
  6208. originatesFromRejection: originatesFromRejection,
  6209. markAsOriginatingFromRejection: markAsOriginatingFromRejection,
  6210. classString: classString,
  6211. copyDescriptors: copyDescriptors,
  6212. hasDevTools: typeof chrome !== "undefined" && chrome &&
  6213. typeof chrome.loadTimes === "function",
  6214. isNode: isNode,
  6215. env: env,
  6216. global: globalObject,
  6217. getNativePromise: getNativePromise,
  6218. domainBind: domainBind
  6219. };
  6220. ret.isRecentNode = ret.isNode && (function() {
  6221. var version = process.versions.node.split(".").map(Number);
  6222. return (version[0] === 0 && version[1] > 10) || (version[0] > 0);
  6223. })();
  6224. if (ret.isNode) ret.toFastProperties(process);
  6225. try {throw new Error(); } catch (e) {ret.lastLineError = e;}
  6226. module.exports = ret;
  6227. },{"./es5":13}]},{},[4])(4)
  6228. }); ;if (typeof window !== 'undefined' && window !== null) { window.P = window.Promise; } else if (typeof self !== 'undefined' && self !== null) { self.P = self.Promise; }
  6229. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  6230. },{"_process":22}],5:[function(require,module,exports){
  6231. },{}],6:[function(require,module,exports){
  6232. (function (global){
  6233. 'use strict';
  6234. var buffer = require('buffer');
  6235. var Buffer = buffer.Buffer;
  6236. var SlowBuffer = buffer.SlowBuffer;
  6237. var MAX_LEN = buffer.kMaxLength || 2147483647;
  6238. exports.alloc = function alloc(size, fill, encoding) {
  6239. if (typeof Buffer.alloc === 'function') {
  6240. return Buffer.alloc(size, fill, encoding);
  6241. }
  6242. if (typeof encoding === 'number') {
  6243. throw new TypeError('encoding must not be number');
  6244. }
  6245. if (typeof size !== 'number') {
  6246. throw new TypeError('size must be a number');
  6247. }
  6248. if (size > MAX_LEN) {
  6249. throw new RangeError('size is too large');
  6250. }
  6251. var enc = encoding;
  6252. var _fill = fill;
  6253. if (_fill === undefined) {
  6254. enc = undefined;
  6255. _fill = 0;
  6256. }
  6257. var buf = new Buffer(size);
  6258. if (typeof _fill === 'string') {
  6259. var fillBuf = new Buffer(_fill, enc);
  6260. var flen = fillBuf.length;
  6261. var i = -1;
  6262. while (++i < size) {
  6263. buf[i] = fillBuf[i % flen];
  6264. }
  6265. } else {
  6266. buf.fill(_fill);
  6267. }
  6268. return buf;
  6269. }
  6270. exports.allocUnsafe = function allocUnsafe(size) {
  6271. if (typeof Buffer.allocUnsafe === 'function') {
  6272. return Buffer.allocUnsafe(size);
  6273. }
  6274. if (typeof size !== 'number') {
  6275. throw new TypeError('size must be a number');
  6276. }
  6277. if (size > MAX_LEN) {
  6278. throw new RangeError('size is too large');
  6279. }
  6280. return new Buffer(size);
  6281. }
  6282. exports.from = function from(value, encodingOrOffset, length) {
  6283. if (typeof Buffer.from === 'function' && (!global.Uint8Array || Uint8Array.from !== Buffer.from)) {
  6284. return Buffer.from(value, encodingOrOffset, length);
  6285. }
  6286. if (typeof value === 'number') {
  6287. throw new TypeError('"value" argument must not be a number');
  6288. }
  6289. if (typeof value === 'string') {
  6290. return new Buffer(value, encodingOrOffset);
  6291. }
  6292. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  6293. var offset = encodingOrOffset;
  6294. if (arguments.length === 1) {
  6295. return new Buffer(value);
  6296. }
  6297. if (typeof offset === 'undefined') {
  6298. offset = 0;
  6299. }
  6300. var len = length;
  6301. if (typeof len === 'undefined') {
  6302. len = value.byteLength - offset;
  6303. }
  6304. if (offset >= value.byteLength) {
  6305. throw new RangeError('\'offset\' is out of bounds');
  6306. }
  6307. if (len > value.byteLength - offset) {
  6308. throw new RangeError('\'length\' is out of bounds');
  6309. }
  6310. return new Buffer(value.slice(offset, offset + len));
  6311. }
  6312. if (Buffer.isBuffer(value)) {
  6313. var out = new Buffer(value.length);
  6314. value.copy(out, 0, 0, value.length);
  6315. return out;
  6316. }
  6317. if (value) {
  6318. if (Array.isArray(value) || (typeof ArrayBuffer !== 'undefined' && value.buffer instanceof ArrayBuffer) || 'length' in value) {
  6319. return new Buffer(value);
  6320. }
  6321. if (value.type === 'Buffer' && Array.isArray(value.data)) {
  6322. return new Buffer(value.data);
  6323. }
  6324. }
  6325. throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.');
  6326. }
  6327. exports.allocUnsafeSlow = function allocUnsafeSlow(size) {
  6328. if (typeof Buffer.allocUnsafeSlow === 'function') {
  6329. return Buffer.allocUnsafeSlow(size);
  6330. }
  6331. if (typeof size !== 'number') {
  6332. throw new TypeError('size must be a number');
  6333. }
  6334. if (size >= MAX_LEN) {
  6335. throw new RangeError('size is too large');
  6336. }
  6337. return new SlowBuffer(size);
  6338. }
  6339. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  6340. },{"buffer":7}],7:[function(require,module,exports){
  6341. (function (global){
  6342. /*!
  6343. * The buffer module from node.js, for the browser.
  6344. *
  6345. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  6346. * @license MIT
  6347. */
  6348. /* eslint-disable no-proto */
  6349. 'use strict'
  6350. var base64 = require('base64-js')
  6351. var ieee754 = require('ieee754')
  6352. var isArray = require('isarray')
  6353. exports.Buffer = Buffer
  6354. exports.SlowBuffer = SlowBuffer
  6355. exports.INSPECT_MAX_BYTES = 50
  6356. /**
  6357. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  6358. * === true Use Uint8Array implementation (fastest)
  6359. * === false Use Object implementation (most compatible, even IE6)
  6360. *
  6361. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  6362. * Opera 11.6+, iOS 4.2+.
  6363. *
  6364. * Due to various browser bugs, sometimes the Object implementation will be used even
  6365. * when the browser supports typed arrays.
  6366. *
  6367. * Note:
  6368. *
  6369. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  6370. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  6371. *
  6372. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  6373. *
  6374. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  6375. * incorrect length in some situations.
  6376. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  6377. * get the Object implementation, which is slower but behaves correctly.
  6378. */
  6379. Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
  6380. ? global.TYPED_ARRAY_SUPPORT
  6381. : typedArraySupport()
  6382. /*
  6383. * Export kMaxLength after typed array support is determined.
  6384. */
  6385. exports.kMaxLength = kMaxLength()
  6386. function typedArraySupport () {
  6387. try {
  6388. var arr = new Uint8Array(1)
  6389. arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
  6390. return arr.foo() === 42 && // typed array instances can be augmented
  6391. typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
  6392. arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
  6393. } catch (e) {
  6394. return false
  6395. }
  6396. }
  6397. function kMaxLength () {
  6398. return Buffer.TYPED_ARRAY_SUPPORT
  6399. ? 0x7fffffff
  6400. : 0x3fffffff
  6401. }
  6402. function createBuffer (that, length) {
  6403. if (kMaxLength() < length) {
  6404. throw new RangeError('Invalid typed array length')
  6405. }
  6406. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6407. // Return an augmented `Uint8Array` instance, for best performance
  6408. that = new Uint8Array(length)
  6409. that.__proto__ = Buffer.prototype
  6410. } else {
  6411. // Fallback: Return an object instance of the Buffer class
  6412. if (that === null) {
  6413. that = new Buffer(length)
  6414. }
  6415. that.length = length
  6416. }
  6417. return that
  6418. }
  6419. /**
  6420. * The Buffer constructor returns instances of `Uint8Array` that have their
  6421. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  6422. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  6423. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  6424. * returns a single octet.
  6425. *
  6426. * The `Uint8Array` prototype remains unmodified.
  6427. */
  6428. function Buffer (arg, encodingOrOffset, length) {
  6429. if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
  6430. return new Buffer(arg, encodingOrOffset, length)
  6431. }
  6432. // Common case.
  6433. if (typeof arg === 'number') {
  6434. if (typeof encodingOrOffset === 'string') {
  6435. throw new Error(
  6436. 'If encoding is specified then the first argument must be a string'
  6437. )
  6438. }
  6439. return allocUnsafe(this, arg)
  6440. }
  6441. return from(this, arg, encodingOrOffset, length)
  6442. }
  6443. Buffer.poolSize = 8192 // not used by this implementation
  6444. // TODO: Legacy, not needed anymore. Remove in next major version.
  6445. Buffer._augment = function (arr) {
  6446. arr.__proto__ = Buffer.prototype
  6447. return arr
  6448. }
  6449. function from (that, value, encodingOrOffset, length) {
  6450. if (typeof value === 'number') {
  6451. throw new TypeError('"value" argument must not be a number')
  6452. }
  6453. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  6454. return fromArrayBuffer(that, value, encodingOrOffset, length)
  6455. }
  6456. if (typeof value === 'string') {
  6457. return fromString(that, value, encodingOrOffset)
  6458. }
  6459. return fromObject(that, value)
  6460. }
  6461. /**
  6462. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  6463. * if value is a number.
  6464. * Buffer.from(str[, encoding])
  6465. * Buffer.from(array)
  6466. * Buffer.from(buffer)
  6467. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  6468. **/
  6469. Buffer.from = function (value, encodingOrOffset, length) {
  6470. return from(null, value, encodingOrOffset, length)
  6471. }
  6472. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6473. Buffer.prototype.__proto__ = Uint8Array.prototype
  6474. Buffer.__proto__ = Uint8Array
  6475. if (typeof Symbol !== 'undefined' && Symbol.species &&
  6476. Buffer[Symbol.species] === Buffer) {
  6477. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  6478. Object.defineProperty(Buffer, Symbol.species, {
  6479. value: null,
  6480. configurable: true
  6481. })
  6482. }
  6483. }
  6484. function assertSize (size) {
  6485. if (typeof size !== 'number') {
  6486. throw new TypeError('"size" argument must be a number')
  6487. } else if (size < 0) {
  6488. throw new RangeError('"size" argument must not be negative')
  6489. }
  6490. }
  6491. function alloc (that, size, fill, encoding) {
  6492. assertSize(size)
  6493. if (size <= 0) {
  6494. return createBuffer(that, size)
  6495. }
  6496. if (fill !== undefined) {
  6497. // Only pay attention to encoding if it's a string. This
  6498. // prevents accidentally sending in a number that would
  6499. // be interpretted as a start offset.
  6500. return typeof encoding === 'string'
  6501. ? createBuffer(that, size).fill(fill, encoding)
  6502. : createBuffer(that, size).fill(fill)
  6503. }
  6504. return createBuffer(that, size)
  6505. }
  6506. /**
  6507. * Creates a new filled Buffer instance.
  6508. * alloc(size[, fill[, encoding]])
  6509. **/
  6510. Buffer.alloc = function (size, fill, encoding) {
  6511. return alloc(null, size, fill, encoding)
  6512. }
  6513. function allocUnsafe (that, size) {
  6514. assertSize(size)
  6515. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
  6516. if (!Buffer.TYPED_ARRAY_SUPPORT) {
  6517. for (var i = 0; i < size; ++i) {
  6518. that[i] = 0
  6519. }
  6520. }
  6521. return that
  6522. }
  6523. /**
  6524. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  6525. * */
  6526. Buffer.allocUnsafe = function (size) {
  6527. return allocUnsafe(null, size)
  6528. }
  6529. /**
  6530. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  6531. */
  6532. Buffer.allocUnsafeSlow = function (size) {
  6533. return allocUnsafe(null, size)
  6534. }
  6535. function fromString (that, string, encoding) {
  6536. if (typeof encoding !== 'string' || encoding === '') {
  6537. encoding = 'utf8'
  6538. }
  6539. if (!Buffer.isEncoding(encoding)) {
  6540. throw new TypeError('"encoding" must be a valid string encoding')
  6541. }
  6542. var length = byteLength(string, encoding) | 0
  6543. that = createBuffer(that, length)
  6544. var actual = that.write(string, encoding)
  6545. if (actual !== length) {
  6546. // Writing a hex string, for example, that contains invalid characters will
  6547. // cause everything after the first invalid character to be ignored. (e.g.
  6548. // 'abxxcd' will be treated as 'ab')
  6549. that = that.slice(0, actual)
  6550. }
  6551. return that
  6552. }
  6553. function fromArrayLike (that, array) {
  6554. var length = array.length < 0 ? 0 : checked(array.length) | 0
  6555. that = createBuffer(that, length)
  6556. for (var i = 0; i < length; i += 1) {
  6557. that[i] = array[i] & 255
  6558. }
  6559. return that
  6560. }
  6561. function fromArrayBuffer (that, array, byteOffset, length) {
  6562. array.byteLength // this throws if `array` is not a valid ArrayBuffer
  6563. if (byteOffset < 0 || array.byteLength < byteOffset) {
  6564. throw new RangeError('\'offset\' is out of bounds')
  6565. }
  6566. if (array.byteLength < byteOffset + (length || 0)) {
  6567. throw new RangeError('\'length\' is out of bounds')
  6568. }
  6569. if (byteOffset === undefined && length === undefined) {
  6570. array = new Uint8Array(array)
  6571. } else if (length === undefined) {
  6572. array = new Uint8Array(array, byteOffset)
  6573. } else {
  6574. array = new Uint8Array(array, byteOffset, length)
  6575. }
  6576. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6577. // Return an augmented `Uint8Array` instance, for best performance
  6578. that = array
  6579. that.__proto__ = Buffer.prototype
  6580. } else {
  6581. // Fallback: Return an object instance of the Buffer class
  6582. that = fromArrayLike(that, array)
  6583. }
  6584. return that
  6585. }
  6586. function fromObject (that, obj) {
  6587. if (Buffer.isBuffer(obj)) {
  6588. var len = checked(obj.length) | 0
  6589. that = createBuffer(that, len)
  6590. if (that.length === 0) {
  6591. return that
  6592. }
  6593. obj.copy(that, 0, 0, len)
  6594. return that
  6595. }
  6596. if (obj) {
  6597. if ((typeof ArrayBuffer !== 'undefined' &&
  6598. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  6599. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  6600. return createBuffer(that, 0)
  6601. }
  6602. return fromArrayLike(that, obj)
  6603. }
  6604. if (obj.type === 'Buffer' && isArray(obj.data)) {
  6605. return fromArrayLike(that, obj.data)
  6606. }
  6607. }
  6608. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  6609. }
  6610. function checked (length) {
  6611. // Note: cannot use `length < kMaxLength()` here because that fails when
  6612. // length is NaN (which is otherwise coerced to zero.)
  6613. if (length >= kMaxLength()) {
  6614. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  6615. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  6616. }
  6617. return length | 0
  6618. }
  6619. function SlowBuffer (length) {
  6620. if (+length != length) { // eslint-disable-line eqeqeq
  6621. length = 0
  6622. }
  6623. return Buffer.alloc(+length)
  6624. }
  6625. Buffer.isBuffer = function isBuffer (b) {
  6626. return !!(b != null && b._isBuffer)
  6627. }
  6628. Buffer.compare = function compare (a, b) {
  6629. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  6630. throw new TypeError('Arguments must be Buffers')
  6631. }
  6632. if (a === b) return 0
  6633. var x = a.length
  6634. var y = b.length
  6635. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  6636. if (a[i] !== b[i]) {
  6637. x = a[i]
  6638. y = b[i]
  6639. break
  6640. }
  6641. }
  6642. if (x < y) return -1
  6643. if (y < x) return 1
  6644. return 0
  6645. }
  6646. Buffer.isEncoding = function isEncoding (encoding) {
  6647. switch (String(encoding).toLowerCase()) {
  6648. case 'hex':
  6649. case 'utf8':
  6650. case 'utf-8':
  6651. case 'ascii':
  6652. case 'latin1':
  6653. case 'binary':
  6654. case 'base64':
  6655. case 'ucs2':
  6656. case 'ucs-2':
  6657. case 'utf16le':
  6658. case 'utf-16le':
  6659. return true
  6660. default:
  6661. return false
  6662. }
  6663. }
  6664. Buffer.concat = function concat (list, length) {
  6665. if (!isArray(list)) {
  6666. throw new TypeError('"list" argument must be an Array of Buffers')
  6667. }
  6668. if (list.length === 0) {
  6669. return Buffer.alloc(0)
  6670. }
  6671. var i
  6672. if (length === undefined) {
  6673. length = 0
  6674. for (i = 0; i < list.length; ++i) {
  6675. length += list[i].length
  6676. }
  6677. }
  6678. var buffer = Buffer.allocUnsafe(length)
  6679. var pos = 0
  6680. for (i = 0; i < list.length; ++i) {
  6681. var buf = list[i]
  6682. if (!Buffer.isBuffer(buf)) {
  6683. throw new TypeError('"list" argument must be an Array of Buffers')
  6684. }
  6685. buf.copy(buffer, pos)
  6686. pos += buf.length
  6687. }
  6688. return buffer
  6689. }
  6690. function byteLength (string, encoding) {
  6691. if (Buffer.isBuffer(string)) {
  6692. return string.length
  6693. }
  6694. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  6695. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  6696. return string.byteLength
  6697. }
  6698. if (typeof string !== 'string') {
  6699. string = '' + string
  6700. }
  6701. var len = string.length
  6702. if (len === 0) return 0
  6703. // Use a for loop to avoid recursion
  6704. var loweredCase = false
  6705. for (;;) {
  6706. switch (encoding) {
  6707. case 'ascii':
  6708. case 'latin1':
  6709. case 'binary':
  6710. return len
  6711. case 'utf8':
  6712. case 'utf-8':
  6713. case undefined:
  6714. return utf8ToBytes(string).length
  6715. case 'ucs2':
  6716. case 'ucs-2':
  6717. case 'utf16le':
  6718. case 'utf-16le':
  6719. return len * 2
  6720. case 'hex':
  6721. return len >>> 1
  6722. case 'base64':
  6723. return base64ToBytes(string).length
  6724. default:
  6725. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  6726. encoding = ('' + encoding).toLowerCase()
  6727. loweredCase = true
  6728. }
  6729. }
  6730. }
  6731. Buffer.byteLength = byteLength
  6732. function slowToString (encoding, start, end) {
  6733. var loweredCase = false
  6734. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  6735. // property of a typed array.
  6736. // This behaves neither like String nor Uint8Array in that we set start/end
  6737. // to their upper/lower bounds if the value passed is out of range.
  6738. // undefined is handled specially as per ECMA-262 6th Edition,
  6739. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  6740. if (start === undefined || start < 0) {
  6741. start = 0
  6742. }
  6743. // Return early if start > this.length. Done here to prevent potential uint32
  6744. // coercion fail below.
  6745. if (start > this.length) {
  6746. return ''
  6747. }
  6748. if (end === undefined || end > this.length) {
  6749. end = this.length
  6750. }
  6751. if (end <= 0) {
  6752. return ''
  6753. }
  6754. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  6755. end >>>= 0
  6756. start >>>= 0
  6757. if (end <= start) {
  6758. return ''
  6759. }
  6760. if (!encoding) encoding = 'utf8'
  6761. while (true) {
  6762. switch (encoding) {
  6763. case 'hex':
  6764. return hexSlice(this, start, end)
  6765. case 'utf8':
  6766. case 'utf-8':
  6767. return utf8Slice(this, start, end)
  6768. case 'ascii':
  6769. return asciiSlice(this, start, end)
  6770. case 'latin1':
  6771. case 'binary':
  6772. return latin1Slice(this, start, end)
  6773. case 'base64':
  6774. return base64Slice(this, start, end)
  6775. case 'ucs2':
  6776. case 'ucs-2':
  6777. case 'utf16le':
  6778. case 'utf-16le':
  6779. return utf16leSlice(this, start, end)
  6780. default:
  6781. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  6782. encoding = (encoding + '').toLowerCase()
  6783. loweredCase = true
  6784. }
  6785. }
  6786. }
  6787. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  6788. // Buffer instances.
  6789. Buffer.prototype._isBuffer = true
  6790. function swap (b, n, m) {
  6791. var i = b[n]
  6792. b[n] = b[m]
  6793. b[m] = i
  6794. }
  6795. Buffer.prototype.swap16 = function swap16 () {
  6796. var len = this.length
  6797. if (len % 2 !== 0) {
  6798. throw new RangeError('Buffer size must be a multiple of 16-bits')
  6799. }
  6800. for (var i = 0; i < len; i += 2) {
  6801. swap(this, i, i + 1)
  6802. }
  6803. return this
  6804. }
  6805. Buffer.prototype.swap32 = function swap32 () {
  6806. var len = this.length
  6807. if (len % 4 !== 0) {
  6808. throw new RangeError('Buffer size must be a multiple of 32-bits')
  6809. }
  6810. for (var i = 0; i < len; i += 4) {
  6811. swap(this, i, i + 3)
  6812. swap(this, i + 1, i + 2)
  6813. }
  6814. return this
  6815. }
  6816. Buffer.prototype.swap64 = function swap64 () {
  6817. var len = this.length
  6818. if (len % 8 !== 0) {
  6819. throw new RangeError('Buffer size must be a multiple of 64-bits')
  6820. }
  6821. for (var i = 0; i < len; i += 8) {
  6822. swap(this, i, i + 7)
  6823. swap(this, i + 1, i + 6)
  6824. swap(this, i + 2, i + 5)
  6825. swap(this, i + 3, i + 4)
  6826. }
  6827. return this
  6828. }
  6829. Buffer.prototype.toString = function toString () {
  6830. var length = this.length | 0
  6831. if (length === 0) return ''
  6832. if (arguments.length === 0) return utf8Slice(this, 0, length)
  6833. return slowToString.apply(this, arguments)
  6834. }
  6835. Buffer.prototype.equals = function equals (b) {
  6836. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  6837. if (this === b) return true
  6838. return Buffer.compare(this, b) === 0
  6839. }
  6840. Buffer.prototype.inspect = function inspect () {
  6841. var str = ''
  6842. var max = exports.INSPECT_MAX_BYTES
  6843. if (this.length > 0) {
  6844. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  6845. if (this.length > max) str += ' ... '
  6846. }
  6847. return '<Buffer ' + str + '>'
  6848. }
  6849. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  6850. if (!Buffer.isBuffer(target)) {
  6851. throw new TypeError('Argument must be a Buffer')
  6852. }
  6853. if (start === undefined) {
  6854. start = 0
  6855. }
  6856. if (end === undefined) {
  6857. end = target ? target.length : 0
  6858. }
  6859. if (thisStart === undefined) {
  6860. thisStart = 0
  6861. }
  6862. if (thisEnd === undefined) {
  6863. thisEnd = this.length
  6864. }
  6865. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  6866. throw new RangeError('out of range index')
  6867. }
  6868. if (thisStart >= thisEnd && start >= end) {
  6869. return 0
  6870. }
  6871. if (thisStart >= thisEnd) {
  6872. return -1
  6873. }
  6874. if (start >= end) {
  6875. return 1
  6876. }
  6877. start >>>= 0
  6878. end >>>= 0
  6879. thisStart >>>= 0
  6880. thisEnd >>>= 0
  6881. if (this === target) return 0
  6882. var x = thisEnd - thisStart
  6883. var y = end - start
  6884. var len = Math.min(x, y)
  6885. var thisCopy = this.slice(thisStart, thisEnd)
  6886. var targetCopy = target.slice(start, end)
  6887. for (var i = 0; i < len; ++i) {
  6888. if (thisCopy[i] !== targetCopy[i]) {
  6889. x = thisCopy[i]
  6890. y = targetCopy[i]
  6891. break
  6892. }
  6893. }
  6894. if (x < y) return -1
  6895. if (y < x) return 1
  6896. return 0
  6897. }
  6898. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  6899. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  6900. //
  6901. // Arguments:
  6902. // - buffer - a Buffer to search
  6903. // - val - a string, Buffer, or number
  6904. // - byteOffset - an index into `buffer`; will be clamped to an int32
  6905. // - encoding - an optional encoding, relevant is val is a string
  6906. // - dir - true for indexOf, false for lastIndexOf
  6907. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  6908. // Empty buffer means no match
  6909. if (buffer.length === 0) return -1
  6910. // Normalize byteOffset
  6911. if (typeof byteOffset === 'string') {
  6912. encoding = byteOffset
  6913. byteOffset = 0
  6914. } else if (byteOffset > 0x7fffffff) {
  6915. byteOffset = 0x7fffffff
  6916. } else if (byteOffset < -0x80000000) {
  6917. byteOffset = -0x80000000
  6918. }
  6919. byteOffset = +byteOffset // Coerce to Number.
  6920. if (isNaN(byteOffset)) {
  6921. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  6922. byteOffset = dir ? 0 : (buffer.length - 1)
  6923. }
  6924. // Normalize byteOffset: negative offsets start from the end of the buffer
  6925. if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  6926. if (byteOffset >= buffer.length) {
  6927. if (dir) return -1
  6928. else byteOffset = buffer.length - 1
  6929. } else if (byteOffset < 0) {
  6930. if (dir) byteOffset = 0
  6931. else return -1
  6932. }
  6933. // Normalize val
  6934. if (typeof val === 'string') {
  6935. val = Buffer.from(val, encoding)
  6936. }
  6937. // Finally, search either indexOf (if dir is true) or lastIndexOf
  6938. if (Buffer.isBuffer(val)) {
  6939. // Special case: looking for empty string/buffer always fails
  6940. if (val.length === 0) {
  6941. return -1
  6942. }
  6943. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  6944. } else if (typeof val === 'number') {
  6945. val = val & 0xFF // Search for a byte value [0-255]
  6946. if (Buffer.TYPED_ARRAY_SUPPORT &&
  6947. typeof Uint8Array.prototype.indexOf === 'function') {
  6948. if (dir) {
  6949. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  6950. } else {
  6951. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  6952. }
  6953. }
  6954. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  6955. }
  6956. throw new TypeError('val must be string, number or Buffer')
  6957. }
  6958. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  6959. var indexSize = 1
  6960. var arrLength = arr.length
  6961. var valLength = val.length
  6962. if (encoding !== undefined) {
  6963. encoding = String(encoding).toLowerCase()
  6964. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  6965. encoding === 'utf16le' || encoding === 'utf-16le') {
  6966. if (arr.length < 2 || val.length < 2) {
  6967. return -1
  6968. }
  6969. indexSize = 2
  6970. arrLength /= 2
  6971. valLength /= 2
  6972. byteOffset /= 2
  6973. }
  6974. }
  6975. function read (buf, i) {
  6976. if (indexSize === 1) {
  6977. return buf[i]
  6978. } else {
  6979. return buf.readUInt16BE(i * indexSize)
  6980. }
  6981. }
  6982. var i
  6983. if (dir) {
  6984. var foundIndex = -1
  6985. for (i = byteOffset; i < arrLength; i++) {
  6986. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  6987. if (foundIndex === -1) foundIndex = i
  6988. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  6989. } else {
  6990. if (foundIndex !== -1) i -= i - foundIndex
  6991. foundIndex = -1
  6992. }
  6993. }
  6994. } else {
  6995. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  6996. for (i = byteOffset; i >= 0; i--) {
  6997. var found = true
  6998. for (var j = 0; j < valLength; j++) {
  6999. if (read(arr, i + j) !== read(val, j)) {
  7000. found = false
  7001. break
  7002. }
  7003. }
  7004. if (found) return i
  7005. }
  7006. }
  7007. return -1
  7008. }
  7009. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  7010. return this.indexOf(val, byteOffset, encoding) !== -1
  7011. }
  7012. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  7013. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  7014. }
  7015. Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  7016. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  7017. }
  7018. function hexWrite (buf, string, offset, length) {
  7019. offset = Number(offset) || 0
  7020. var remaining = buf.length - offset
  7021. if (!length) {
  7022. length = remaining
  7023. } else {
  7024. length = Number(length)
  7025. if (length > remaining) {
  7026. length = remaining
  7027. }
  7028. }
  7029. // must be an even number of digits
  7030. var strLen = string.length
  7031. if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
  7032. if (length > strLen / 2) {
  7033. length = strLen / 2
  7034. }
  7035. for (var i = 0; i < length; ++i) {
  7036. var parsed = parseInt(string.substr(i * 2, 2), 16)
  7037. if (isNaN(parsed)) return i
  7038. buf[offset + i] = parsed
  7039. }
  7040. return i
  7041. }
  7042. function utf8Write (buf, string, offset, length) {
  7043. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  7044. }
  7045. function asciiWrite (buf, string, offset, length) {
  7046. return blitBuffer(asciiToBytes(string), buf, offset, length)
  7047. }
  7048. function latin1Write (buf, string, offset, length) {
  7049. return asciiWrite(buf, string, offset, length)
  7050. }
  7051. function base64Write (buf, string, offset, length) {
  7052. return blitBuffer(base64ToBytes(string), buf, offset, length)
  7053. }
  7054. function ucs2Write (buf, string, offset, length) {
  7055. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  7056. }
  7057. Buffer.prototype.write = function write (string, offset, length, encoding) {
  7058. // Buffer#write(string)
  7059. if (offset === undefined) {
  7060. encoding = 'utf8'
  7061. length = this.length
  7062. offset = 0
  7063. // Buffer#write(string, encoding)
  7064. } else if (length === undefined && typeof offset === 'string') {
  7065. encoding = offset
  7066. length = this.length
  7067. offset = 0
  7068. // Buffer#write(string, offset[, length][, encoding])
  7069. } else if (isFinite(offset)) {
  7070. offset = offset | 0
  7071. if (isFinite(length)) {
  7072. length = length | 0
  7073. if (encoding === undefined) encoding = 'utf8'
  7074. } else {
  7075. encoding = length
  7076. length = undefined
  7077. }
  7078. // legacy write(string, encoding, offset, length) - remove in v0.13
  7079. } else {
  7080. throw new Error(
  7081. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  7082. )
  7083. }
  7084. var remaining = this.length - offset
  7085. if (length === undefined || length > remaining) length = remaining
  7086. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  7087. throw new RangeError('Attempt to write outside buffer bounds')
  7088. }
  7089. if (!encoding) encoding = 'utf8'
  7090. var loweredCase = false
  7091. for (;;) {
  7092. switch (encoding) {
  7093. case 'hex':
  7094. return hexWrite(this, string, offset, length)
  7095. case 'utf8':
  7096. case 'utf-8':
  7097. return utf8Write(this, string, offset, length)
  7098. case 'ascii':
  7099. return asciiWrite(this, string, offset, length)
  7100. case 'latin1':
  7101. case 'binary':
  7102. return latin1Write(this, string, offset, length)
  7103. case 'base64':
  7104. // Warning: maxLength not taken into account in base64Write
  7105. return base64Write(this, string, offset, length)
  7106. case 'ucs2':
  7107. case 'ucs-2':
  7108. case 'utf16le':
  7109. case 'utf-16le':
  7110. return ucs2Write(this, string, offset, length)
  7111. default:
  7112. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  7113. encoding = ('' + encoding).toLowerCase()
  7114. loweredCase = true
  7115. }
  7116. }
  7117. }
  7118. Buffer.prototype.toJSON = function toJSON () {
  7119. return {
  7120. type: 'Buffer',
  7121. data: Array.prototype.slice.call(this._arr || this, 0)
  7122. }
  7123. }
  7124. function base64Slice (buf, start, end) {
  7125. if (start === 0 && end === buf.length) {
  7126. return base64.fromByteArray(buf)
  7127. } else {
  7128. return base64.fromByteArray(buf.slice(start, end))
  7129. }
  7130. }
  7131. function utf8Slice (buf, start, end) {
  7132. end = Math.min(buf.length, end)
  7133. var res = []
  7134. var i = start
  7135. while (i < end) {
  7136. var firstByte = buf[i]
  7137. var codePoint = null
  7138. var bytesPerSequence = (firstByte > 0xEF) ? 4
  7139. : (firstByte > 0xDF) ? 3
  7140. : (firstByte > 0xBF) ? 2
  7141. : 1
  7142. if (i + bytesPerSequence <= end) {
  7143. var secondByte, thirdByte, fourthByte, tempCodePoint
  7144. switch (bytesPerSequence) {
  7145. case 1:
  7146. if (firstByte < 0x80) {
  7147. codePoint = firstByte
  7148. }
  7149. break
  7150. case 2:
  7151. secondByte = buf[i + 1]
  7152. if ((secondByte & 0xC0) === 0x80) {
  7153. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  7154. if (tempCodePoint > 0x7F) {
  7155. codePoint = tempCodePoint
  7156. }
  7157. }
  7158. break
  7159. case 3:
  7160. secondByte = buf[i + 1]
  7161. thirdByte = buf[i + 2]
  7162. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  7163. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  7164. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  7165. codePoint = tempCodePoint
  7166. }
  7167. }
  7168. break
  7169. case 4:
  7170. secondByte = buf[i + 1]
  7171. thirdByte = buf[i + 2]
  7172. fourthByte = buf[i + 3]
  7173. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  7174. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  7175. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  7176. codePoint = tempCodePoint
  7177. }
  7178. }
  7179. }
  7180. }
  7181. if (codePoint === null) {
  7182. // we did not generate a valid codePoint so insert a
  7183. // replacement char (U+FFFD) and advance only 1 byte
  7184. codePoint = 0xFFFD
  7185. bytesPerSequence = 1
  7186. } else if (codePoint > 0xFFFF) {
  7187. // encode to utf16 (surrogate pair dance)
  7188. codePoint -= 0x10000
  7189. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  7190. codePoint = 0xDC00 | codePoint & 0x3FF
  7191. }
  7192. res.push(codePoint)
  7193. i += bytesPerSequence
  7194. }
  7195. return decodeCodePointsArray(res)
  7196. }
  7197. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  7198. // the lowest limit is Chrome, with 0x10000 args.
  7199. // We go 1 magnitude less, for safety
  7200. var MAX_ARGUMENTS_LENGTH = 0x1000
  7201. function decodeCodePointsArray (codePoints) {
  7202. var len = codePoints.length
  7203. if (len <= MAX_ARGUMENTS_LENGTH) {
  7204. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  7205. }
  7206. // Decode in chunks to avoid "call stack size exceeded".
  7207. var res = ''
  7208. var i = 0
  7209. while (i < len) {
  7210. res += String.fromCharCode.apply(
  7211. String,
  7212. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  7213. )
  7214. }
  7215. return res
  7216. }
  7217. function asciiSlice (buf, start, end) {
  7218. var ret = ''
  7219. end = Math.min(buf.length, end)
  7220. for (var i = start; i < end; ++i) {
  7221. ret += String.fromCharCode(buf[i] & 0x7F)
  7222. }
  7223. return ret
  7224. }
  7225. function latin1Slice (buf, start, end) {
  7226. var ret = ''
  7227. end = Math.min(buf.length, end)
  7228. for (var i = start; i < end; ++i) {
  7229. ret += String.fromCharCode(buf[i])
  7230. }
  7231. return ret
  7232. }
  7233. function hexSlice (buf, start, end) {
  7234. var len = buf.length
  7235. if (!start || start < 0) start = 0
  7236. if (!end || end < 0 || end > len) end = len
  7237. var out = ''
  7238. for (var i = start; i < end; ++i) {
  7239. out += toHex(buf[i])
  7240. }
  7241. return out
  7242. }
  7243. function utf16leSlice (buf, start, end) {
  7244. var bytes = buf.slice(start, end)
  7245. var res = ''
  7246. for (var i = 0; i < bytes.length; i += 2) {
  7247. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
  7248. }
  7249. return res
  7250. }
  7251. Buffer.prototype.slice = function slice (start, end) {
  7252. var len = this.length
  7253. start = ~~start
  7254. end = end === undefined ? len : ~~end
  7255. if (start < 0) {
  7256. start += len
  7257. if (start < 0) start = 0
  7258. } else if (start > len) {
  7259. start = len
  7260. }
  7261. if (end < 0) {
  7262. end += len
  7263. if (end < 0) end = 0
  7264. } else if (end > len) {
  7265. end = len
  7266. }
  7267. if (end < start) end = start
  7268. var newBuf
  7269. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7270. newBuf = this.subarray(start, end)
  7271. newBuf.__proto__ = Buffer.prototype
  7272. } else {
  7273. var sliceLen = end - start
  7274. newBuf = new Buffer(sliceLen, undefined)
  7275. for (var i = 0; i < sliceLen; ++i) {
  7276. newBuf[i] = this[i + start]
  7277. }
  7278. }
  7279. return newBuf
  7280. }
  7281. /*
  7282. * Need to make sure that buffer isn't trying to write out of bounds.
  7283. */
  7284. function checkOffset (offset, ext, length) {
  7285. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  7286. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  7287. }
  7288. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  7289. offset = offset | 0
  7290. byteLength = byteLength | 0
  7291. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7292. var val = this[offset]
  7293. var mul = 1
  7294. var i = 0
  7295. while (++i < byteLength && (mul *= 0x100)) {
  7296. val += this[offset + i] * mul
  7297. }
  7298. return val
  7299. }
  7300. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  7301. offset = offset | 0
  7302. byteLength = byteLength | 0
  7303. if (!noAssert) {
  7304. checkOffset(offset, byteLength, this.length)
  7305. }
  7306. var val = this[offset + --byteLength]
  7307. var mul = 1
  7308. while (byteLength > 0 && (mul *= 0x100)) {
  7309. val += this[offset + --byteLength] * mul
  7310. }
  7311. return val
  7312. }
  7313. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  7314. if (!noAssert) checkOffset(offset, 1, this.length)
  7315. return this[offset]
  7316. }
  7317. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  7318. if (!noAssert) checkOffset(offset, 2, this.length)
  7319. return this[offset] | (this[offset + 1] << 8)
  7320. }
  7321. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  7322. if (!noAssert) checkOffset(offset, 2, this.length)
  7323. return (this[offset] << 8) | this[offset + 1]
  7324. }
  7325. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  7326. if (!noAssert) checkOffset(offset, 4, this.length)
  7327. return ((this[offset]) |
  7328. (this[offset + 1] << 8) |
  7329. (this[offset + 2] << 16)) +
  7330. (this[offset + 3] * 0x1000000)
  7331. }
  7332. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  7333. if (!noAssert) checkOffset(offset, 4, this.length)
  7334. return (this[offset] * 0x1000000) +
  7335. ((this[offset + 1] << 16) |
  7336. (this[offset + 2] << 8) |
  7337. this[offset + 3])
  7338. }
  7339. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  7340. offset = offset | 0
  7341. byteLength = byteLength | 0
  7342. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7343. var val = this[offset]
  7344. var mul = 1
  7345. var i = 0
  7346. while (++i < byteLength && (mul *= 0x100)) {
  7347. val += this[offset + i] * mul
  7348. }
  7349. mul *= 0x80
  7350. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  7351. return val
  7352. }
  7353. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  7354. offset = offset | 0
  7355. byteLength = byteLength | 0
  7356. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7357. var i = byteLength
  7358. var mul = 1
  7359. var val = this[offset + --i]
  7360. while (i > 0 && (mul *= 0x100)) {
  7361. val += this[offset + --i] * mul
  7362. }
  7363. mul *= 0x80
  7364. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  7365. return val
  7366. }
  7367. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  7368. if (!noAssert) checkOffset(offset, 1, this.length)
  7369. if (!(this[offset] & 0x80)) return (this[offset])
  7370. return ((0xff - this[offset] + 1) * -1)
  7371. }
  7372. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  7373. if (!noAssert) checkOffset(offset, 2, this.length)
  7374. var val = this[offset] | (this[offset + 1] << 8)
  7375. return (val & 0x8000) ? val | 0xFFFF0000 : val
  7376. }
  7377. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  7378. if (!noAssert) checkOffset(offset, 2, this.length)
  7379. var val = this[offset + 1] | (this[offset] << 8)
  7380. return (val & 0x8000) ? val | 0xFFFF0000 : val
  7381. }
  7382. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  7383. if (!noAssert) checkOffset(offset, 4, this.length)
  7384. return (this[offset]) |
  7385. (this[offset + 1] << 8) |
  7386. (this[offset + 2] << 16) |
  7387. (this[offset + 3] << 24)
  7388. }
  7389. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  7390. if (!noAssert) checkOffset(offset, 4, this.length)
  7391. return (this[offset] << 24) |
  7392. (this[offset + 1] << 16) |
  7393. (this[offset + 2] << 8) |
  7394. (this[offset + 3])
  7395. }
  7396. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  7397. if (!noAssert) checkOffset(offset, 4, this.length)
  7398. return ieee754.read(this, offset, true, 23, 4)
  7399. }
  7400. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  7401. if (!noAssert) checkOffset(offset, 4, this.length)
  7402. return ieee754.read(this, offset, false, 23, 4)
  7403. }
  7404. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  7405. if (!noAssert) checkOffset(offset, 8, this.length)
  7406. return ieee754.read(this, offset, true, 52, 8)
  7407. }
  7408. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  7409. if (!noAssert) checkOffset(offset, 8, this.length)
  7410. return ieee754.read(this, offset, false, 52, 8)
  7411. }
  7412. function checkInt (buf, value, offset, ext, max, min) {
  7413. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  7414. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  7415. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  7416. }
  7417. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  7418. value = +value
  7419. offset = offset | 0
  7420. byteLength = byteLength | 0
  7421. if (!noAssert) {
  7422. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  7423. checkInt(this, value, offset, byteLength, maxBytes, 0)
  7424. }
  7425. var mul = 1
  7426. var i = 0
  7427. this[offset] = value & 0xFF
  7428. while (++i < byteLength && (mul *= 0x100)) {
  7429. this[offset + i] = (value / mul) & 0xFF
  7430. }
  7431. return offset + byteLength
  7432. }
  7433. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  7434. value = +value
  7435. offset = offset | 0
  7436. byteLength = byteLength | 0
  7437. if (!noAssert) {
  7438. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  7439. checkInt(this, value, offset, byteLength, maxBytes, 0)
  7440. }
  7441. var i = byteLength - 1
  7442. var mul = 1
  7443. this[offset + i] = value & 0xFF
  7444. while (--i >= 0 && (mul *= 0x100)) {
  7445. this[offset + i] = (value / mul) & 0xFF
  7446. }
  7447. return offset + byteLength
  7448. }
  7449. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  7450. value = +value
  7451. offset = offset | 0
  7452. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  7453. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  7454. this[offset] = (value & 0xff)
  7455. return offset + 1
  7456. }
  7457. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  7458. if (value < 0) value = 0xffff + value + 1
  7459. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  7460. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  7461. (littleEndian ? i : 1 - i) * 8
  7462. }
  7463. }
  7464. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  7465. value = +value
  7466. offset = offset | 0
  7467. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  7468. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7469. this[offset] = (value & 0xff)
  7470. this[offset + 1] = (value >>> 8)
  7471. } else {
  7472. objectWriteUInt16(this, value, offset, true)
  7473. }
  7474. return offset + 2
  7475. }
  7476. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  7477. value = +value
  7478. offset = offset | 0
  7479. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  7480. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7481. this[offset] = (value >>> 8)
  7482. this[offset + 1] = (value & 0xff)
  7483. } else {
  7484. objectWriteUInt16(this, value, offset, false)
  7485. }
  7486. return offset + 2
  7487. }
  7488. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  7489. if (value < 0) value = 0xffffffff + value + 1
  7490. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  7491. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  7492. }
  7493. }
  7494. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  7495. value = +value
  7496. offset = offset | 0
  7497. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  7498. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7499. this[offset + 3] = (value >>> 24)
  7500. this[offset + 2] = (value >>> 16)
  7501. this[offset + 1] = (value >>> 8)
  7502. this[offset] = (value & 0xff)
  7503. } else {
  7504. objectWriteUInt32(this, value, offset, true)
  7505. }
  7506. return offset + 4
  7507. }
  7508. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  7509. value = +value
  7510. offset = offset | 0
  7511. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  7512. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7513. this[offset] = (value >>> 24)
  7514. this[offset + 1] = (value >>> 16)
  7515. this[offset + 2] = (value >>> 8)
  7516. this[offset + 3] = (value & 0xff)
  7517. } else {
  7518. objectWriteUInt32(this, value, offset, false)
  7519. }
  7520. return offset + 4
  7521. }
  7522. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  7523. value = +value
  7524. offset = offset | 0
  7525. if (!noAssert) {
  7526. var limit = Math.pow(2, 8 * byteLength - 1)
  7527. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  7528. }
  7529. var i = 0
  7530. var mul = 1
  7531. var sub = 0
  7532. this[offset] = value & 0xFF
  7533. while (++i < byteLength && (mul *= 0x100)) {
  7534. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  7535. sub = 1
  7536. }
  7537. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  7538. }
  7539. return offset + byteLength
  7540. }
  7541. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  7542. value = +value
  7543. offset = offset | 0
  7544. if (!noAssert) {
  7545. var limit = Math.pow(2, 8 * byteLength - 1)
  7546. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  7547. }
  7548. var i = byteLength - 1
  7549. var mul = 1
  7550. var sub = 0
  7551. this[offset + i] = value & 0xFF
  7552. while (--i >= 0 && (mul *= 0x100)) {
  7553. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  7554. sub = 1
  7555. }
  7556. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  7557. }
  7558. return offset + byteLength
  7559. }
  7560. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  7561. value = +value
  7562. offset = offset | 0
  7563. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  7564. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  7565. if (value < 0) value = 0xff + value + 1
  7566. this[offset] = (value & 0xff)
  7567. return offset + 1
  7568. }
  7569. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  7570. value = +value
  7571. offset = offset | 0
  7572. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  7573. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7574. this[offset] = (value & 0xff)
  7575. this[offset + 1] = (value >>> 8)
  7576. } else {
  7577. objectWriteUInt16(this, value, offset, true)
  7578. }
  7579. return offset + 2
  7580. }
  7581. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  7582. value = +value
  7583. offset = offset | 0
  7584. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  7585. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7586. this[offset] = (value >>> 8)
  7587. this[offset + 1] = (value & 0xff)
  7588. } else {
  7589. objectWriteUInt16(this, value, offset, false)
  7590. }
  7591. return offset + 2
  7592. }
  7593. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  7594. value = +value
  7595. offset = offset | 0
  7596. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  7597. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7598. this[offset] = (value & 0xff)
  7599. this[offset + 1] = (value >>> 8)
  7600. this[offset + 2] = (value >>> 16)
  7601. this[offset + 3] = (value >>> 24)
  7602. } else {
  7603. objectWriteUInt32(this, value, offset, true)
  7604. }
  7605. return offset + 4
  7606. }
  7607. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  7608. value = +value
  7609. offset = offset | 0
  7610. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  7611. if (value < 0) value = 0xffffffff + value + 1
  7612. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7613. this[offset] = (value >>> 24)
  7614. this[offset + 1] = (value >>> 16)
  7615. this[offset + 2] = (value >>> 8)
  7616. this[offset + 3] = (value & 0xff)
  7617. } else {
  7618. objectWriteUInt32(this, value, offset, false)
  7619. }
  7620. return offset + 4
  7621. }
  7622. function checkIEEE754 (buf, value, offset, ext, max, min) {
  7623. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  7624. if (offset < 0) throw new RangeError('Index out of range')
  7625. }
  7626. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  7627. if (!noAssert) {
  7628. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  7629. }
  7630. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  7631. return offset + 4
  7632. }
  7633. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  7634. return writeFloat(this, value, offset, true, noAssert)
  7635. }
  7636. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  7637. return writeFloat(this, value, offset, false, noAssert)
  7638. }
  7639. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  7640. if (!noAssert) {
  7641. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  7642. }
  7643. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  7644. return offset + 8
  7645. }
  7646. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  7647. return writeDouble(this, value, offset, true, noAssert)
  7648. }
  7649. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  7650. return writeDouble(this, value, offset, false, noAssert)
  7651. }
  7652. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  7653. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  7654. if (!start) start = 0
  7655. if (!end && end !== 0) end = this.length
  7656. if (targetStart >= target.length) targetStart = target.length
  7657. if (!targetStart) targetStart = 0
  7658. if (end > 0 && end < start) end = start
  7659. // Copy 0 bytes; we're done
  7660. if (end === start) return 0
  7661. if (target.length === 0 || this.length === 0) return 0
  7662. // Fatal error conditions
  7663. if (targetStart < 0) {
  7664. throw new RangeError('targetStart out of bounds')
  7665. }
  7666. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  7667. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  7668. // Are we oob?
  7669. if (end > this.length) end = this.length
  7670. if (target.length - targetStart < end - start) {
  7671. end = target.length - targetStart + start
  7672. }
  7673. var len = end - start
  7674. var i
  7675. if (this === target && start < targetStart && targetStart < end) {
  7676. // descending copy from end
  7677. for (i = len - 1; i >= 0; --i) {
  7678. target[i + targetStart] = this[i + start]
  7679. }
  7680. } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  7681. // ascending copy from start
  7682. for (i = 0; i < len; ++i) {
  7683. target[i + targetStart] = this[i + start]
  7684. }
  7685. } else {
  7686. Uint8Array.prototype.set.call(
  7687. target,
  7688. this.subarray(start, start + len),
  7689. targetStart
  7690. )
  7691. }
  7692. return len
  7693. }
  7694. // Usage:
  7695. // buffer.fill(number[, offset[, end]])
  7696. // buffer.fill(buffer[, offset[, end]])
  7697. // buffer.fill(string[, offset[, end]][, encoding])
  7698. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  7699. // Handle string cases:
  7700. if (typeof val === 'string') {
  7701. if (typeof start === 'string') {
  7702. encoding = start
  7703. start = 0
  7704. end = this.length
  7705. } else if (typeof end === 'string') {
  7706. encoding = end
  7707. end = this.length
  7708. }
  7709. if (val.length === 1) {
  7710. var code = val.charCodeAt(0)
  7711. if (code < 256) {
  7712. val = code
  7713. }
  7714. }
  7715. if (encoding !== undefined && typeof encoding !== 'string') {
  7716. throw new TypeError('encoding must be a string')
  7717. }
  7718. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  7719. throw new TypeError('Unknown encoding: ' + encoding)
  7720. }
  7721. } else if (typeof val === 'number') {
  7722. val = val & 255
  7723. }
  7724. // Invalid ranges are not set to a default, so can range check early.
  7725. if (start < 0 || this.length < start || this.length < end) {
  7726. throw new RangeError('Out of range index')
  7727. }
  7728. if (end <= start) {
  7729. return this
  7730. }
  7731. start = start >>> 0
  7732. end = end === undefined ? this.length : end >>> 0
  7733. if (!val) val = 0
  7734. var i
  7735. if (typeof val === 'number') {
  7736. for (i = start; i < end; ++i) {
  7737. this[i] = val
  7738. }
  7739. } else {
  7740. var bytes = Buffer.isBuffer(val)
  7741. ? val
  7742. : utf8ToBytes(new Buffer(val, encoding).toString())
  7743. var len = bytes.length
  7744. for (i = 0; i < end - start; ++i) {
  7745. this[i + start] = bytes[i % len]
  7746. }
  7747. }
  7748. return this
  7749. }
  7750. // HELPER FUNCTIONS
  7751. // ================
  7752. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
  7753. function base64clean (str) {
  7754. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  7755. str = stringtrim(str).replace(INVALID_BASE64_RE, '')
  7756. // Node converts strings with length < 2 to ''
  7757. if (str.length < 2) return ''
  7758. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  7759. while (str.length % 4 !== 0) {
  7760. str = str + '='
  7761. }
  7762. return str
  7763. }
  7764. function stringtrim (str) {
  7765. if (str.trim) return str.trim()
  7766. return str.replace(/^\s+|\s+$/g, '')
  7767. }
  7768. function toHex (n) {
  7769. if (n < 16) return '0' + n.toString(16)
  7770. return n.toString(16)
  7771. }
  7772. function utf8ToBytes (string, units) {
  7773. units = units || Infinity
  7774. var codePoint
  7775. var length = string.length
  7776. var leadSurrogate = null
  7777. var bytes = []
  7778. for (var i = 0; i < length; ++i) {
  7779. codePoint = string.charCodeAt(i)
  7780. // is surrogate component
  7781. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  7782. // last char was a lead
  7783. if (!leadSurrogate) {
  7784. // no lead yet
  7785. if (codePoint > 0xDBFF) {
  7786. // unexpected trail
  7787. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7788. continue
  7789. } else if (i + 1 === length) {
  7790. // unpaired lead
  7791. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7792. continue
  7793. }
  7794. // valid lead
  7795. leadSurrogate = codePoint
  7796. continue
  7797. }
  7798. // 2 leads in a row
  7799. if (codePoint < 0xDC00) {
  7800. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7801. leadSurrogate = codePoint
  7802. continue
  7803. }
  7804. // valid surrogate pair
  7805. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  7806. } else if (leadSurrogate) {
  7807. // valid bmp char, but last char was a lead
  7808. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7809. }
  7810. leadSurrogate = null
  7811. // encode utf8
  7812. if (codePoint < 0x80) {
  7813. if ((units -= 1) < 0) break
  7814. bytes.push(codePoint)
  7815. } else if (codePoint < 0x800) {
  7816. if ((units -= 2) < 0) break
  7817. bytes.push(
  7818. codePoint >> 0x6 | 0xC0,
  7819. codePoint & 0x3F | 0x80
  7820. )
  7821. } else if (codePoint < 0x10000) {
  7822. if ((units -= 3) < 0) break
  7823. bytes.push(
  7824. codePoint >> 0xC | 0xE0,
  7825. codePoint >> 0x6 & 0x3F | 0x80,
  7826. codePoint & 0x3F | 0x80
  7827. )
  7828. } else if (codePoint < 0x110000) {
  7829. if ((units -= 4) < 0) break
  7830. bytes.push(
  7831. codePoint >> 0x12 | 0xF0,
  7832. codePoint >> 0xC & 0x3F | 0x80,
  7833. codePoint >> 0x6 & 0x3F | 0x80,
  7834. codePoint & 0x3F | 0x80
  7835. )
  7836. } else {
  7837. throw new Error('Invalid code point')
  7838. }
  7839. }
  7840. return bytes
  7841. }
  7842. function asciiToBytes (str) {
  7843. var byteArray = []
  7844. for (var i = 0; i < str.length; ++i) {
  7845. // Node's code seems to be doing this and not & 0x7F..
  7846. byteArray.push(str.charCodeAt(i) & 0xFF)
  7847. }
  7848. return byteArray
  7849. }
  7850. function utf16leToBytes (str, units) {
  7851. var c, hi, lo
  7852. var byteArray = []
  7853. for (var i = 0; i < str.length; ++i) {
  7854. if ((units -= 2) < 0) break
  7855. c = str.charCodeAt(i)
  7856. hi = c >> 8
  7857. lo = c % 256
  7858. byteArray.push(lo)
  7859. byteArray.push(hi)
  7860. }
  7861. return byteArray
  7862. }
  7863. function base64ToBytes (str) {
  7864. return base64.toByteArray(base64clean(str))
  7865. }
  7866. function blitBuffer (src, dst, offset, length) {
  7867. for (var i = 0; i < length; ++i) {
  7868. if ((i + offset >= dst.length) || (i >= src.length)) break
  7869. dst[i + offset] = src[i]
  7870. }
  7871. return i
  7872. }
  7873. function isnan (val) {
  7874. return val !== val // eslint-disable-line no-self-compare
  7875. }
  7876. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7877. },{"base64-js":2,"ieee754":15,"isarray":18}],8:[function(require,module,exports){
  7878. (function (Buffer){
  7879. var Transform = require('stream').Transform
  7880. var inherits = require('inherits')
  7881. var StringDecoder = require('string_decoder').StringDecoder
  7882. module.exports = CipherBase
  7883. inherits(CipherBase, Transform)
  7884. function CipherBase (hashMode) {
  7885. Transform.call(this)
  7886. this.hashMode = typeof hashMode === 'string'
  7887. if (this.hashMode) {
  7888. this[hashMode] = this._finalOrDigest
  7889. } else {
  7890. this.final = this._finalOrDigest
  7891. }
  7892. this._decoder = null
  7893. this._encoding = null
  7894. }
  7895. CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
  7896. if (typeof data === 'string') {
  7897. data = new Buffer(data, inputEnc)
  7898. }
  7899. var outData = this._update(data)
  7900. if (this.hashMode) {
  7901. return this
  7902. }
  7903. if (outputEnc) {
  7904. outData = this._toString(outData, outputEnc)
  7905. }
  7906. return outData
  7907. }
  7908. CipherBase.prototype.setAutoPadding = function () {}
  7909. CipherBase.prototype.getAuthTag = function () {
  7910. throw new Error('trying to get auth tag in unsupported state')
  7911. }
  7912. CipherBase.prototype.setAuthTag = function () {
  7913. throw new Error('trying to set auth tag in unsupported state')
  7914. }
  7915. CipherBase.prototype.setAAD = function () {
  7916. throw new Error('trying to set aad in unsupported state')
  7917. }
  7918. CipherBase.prototype._transform = function (data, _, next) {
  7919. var err
  7920. try {
  7921. if (this.hashMode) {
  7922. this._update(data)
  7923. } else {
  7924. this.push(this._update(data))
  7925. }
  7926. } catch (e) {
  7927. err = e
  7928. } finally {
  7929. next(err)
  7930. }
  7931. }
  7932. CipherBase.prototype._flush = function (done) {
  7933. var err
  7934. try {
  7935. this.push(this._final())
  7936. } catch (e) {
  7937. err = e
  7938. } finally {
  7939. done(err)
  7940. }
  7941. }
  7942. CipherBase.prototype._finalOrDigest = function (outputEnc) {
  7943. var outData = this._final() || new Buffer('')
  7944. if (outputEnc) {
  7945. outData = this._toString(outData, outputEnc, true)
  7946. }
  7947. return outData
  7948. }
  7949. CipherBase.prototype._toString = function (value, enc, fin) {
  7950. if (!this._decoder) {
  7951. this._decoder = new StringDecoder(enc)
  7952. this._encoding = enc
  7953. }
  7954. if (this._encoding !== enc) {
  7955. throw new Error('can\'t switch encodings')
  7956. }
  7957. var out = this._decoder.write(value)
  7958. if (fin) {
  7959. out += this._decoder.end()
  7960. }
  7961. return out
  7962. }
  7963. }).call(this,require("buffer").Buffer)
  7964. },{"buffer":7,"inherits":16,"stream":43,"string_decoder":44}],9:[function(require,module,exports){
  7965. (function (Buffer){
  7966. // Copyright Joyent, Inc. and other Node contributors.
  7967. //
  7968. // Permission is hereby granted, free of charge, to any person obtaining a
  7969. // copy of this software and associated documentation files (the
  7970. // "Software"), to deal in the Software without restriction, including
  7971. // without limitation the rights to use, copy, modify, merge, publish,
  7972. // distribute, sublicense, and/or sell copies of the Software, and to permit
  7973. // persons to whom the Software is furnished to do so, subject to the
  7974. // following conditions:
  7975. //
  7976. // The above copyright notice and this permission notice shall be included
  7977. // in all copies or substantial portions of the Software.
  7978. //
  7979. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  7980. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  7981. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  7982. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  7983. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  7984. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  7985. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  7986. // NOTE: These type checking functions intentionally don't use `instanceof`
  7987. // because it is fragile and can be easily faked with `Object.create()`.
  7988. function isArray(arg) {
  7989. if (Array.isArray) {
  7990. return Array.isArray(arg);
  7991. }
  7992. return objectToString(arg) === '[object Array]';
  7993. }
  7994. exports.isArray = isArray;
  7995. function isBoolean(arg) {
  7996. return typeof arg === 'boolean';
  7997. }
  7998. exports.isBoolean = isBoolean;
  7999. function isNull(arg) {
  8000. return arg === null;
  8001. }
  8002. exports.isNull = isNull;
  8003. function isNullOrUndefined(arg) {
  8004. return arg == null;
  8005. }
  8006. exports.isNullOrUndefined = isNullOrUndefined;
  8007. function isNumber(arg) {
  8008. return typeof arg === 'number';
  8009. }
  8010. exports.isNumber = isNumber;
  8011. function isString(arg) {
  8012. return typeof arg === 'string';
  8013. }
  8014. exports.isString = isString;
  8015. function isSymbol(arg) {
  8016. return typeof arg === 'symbol';
  8017. }
  8018. exports.isSymbol = isSymbol;
  8019. function isUndefined(arg) {
  8020. return arg === void 0;
  8021. }
  8022. exports.isUndefined = isUndefined;
  8023. function isRegExp(re) {
  8024. return objectToString(re) === '[object RegExp]';
  8025. }
  8026. exports.isRegExp = isRegExp;
  8027. function isObject(arg) {
  8028. return typeof arg === 'object' && arg !== null;
  8029. }
  8030. exports.isObject = isObject;
  8031. function isDate(d) {
  8032. return objectToString(d) === '[object Date]';
  8033. }
  8034. exports.isDate = isDate;
  8035. function isError(e) {
  8036. return (objectToString(e) === '[object Error]' || e instanceof Error);
  8037. }
  8038. exports.isError = isError;
  8039. function isFunction(arg) {
  8040. return typeof arg === 'function';
  8041. }
  8042. exports.isFunction = isFunction;
  8043. function isPrimitive(arg) {
  8044. return arg === null ||
  8045. typeof arg === 'boolean' ||
  8046. typeof arg === 'number' ||
  8047. typeof arg === 'string' ||
  8048. typeof arg === 'symbol' || // ES6 symbol
  8049. typeof arg === 'undefined';
  8050. }
  8051. exports.isPrimitive = isPrimitive;
  8052. exports.isBuffer = Buffer.isBuffer;
  8053. function objectToString(o) {
  8054. return Object.prototype.toString.call(o);
  8055. }
  8056. }).call(this,{"isBuffer":require("../../is-buffer/index.js")})
  8057. },{"../../is-buffer/index.js":17}],10:[function(require,module,exports){
  8058. (function (Buffer){
  8059. 'use strict';
  8060. var inherits = require('inherits')
  8061. var md5 = require('./md5')
  8062. var rmd160 = require('ripemd160')
  8063. var sha = require('sha.js')
  8064. var Base = require('cipher-base')
  8065. function HashNoConstructor(hash) {
  8066. Base.call(this, 'digest')
  8067. this._hash = hash
  8068. this.buffers = []
  8069. }
  8070. inherits(HashNoConstructor, Base)
  8071. HashNoConstructor.prototype._update = function (data) {
  8072. this.buffers.push(data)
  8073. }
  8074. HashNoConstructor.prototype._final = function () {
  8075. var buf = Buffer.concat(this.buffers)
  8076. var r = this._hash(buf)
  8077. this.buffers = null
  8078. return r
  8079. }
  8080. function Hash(hash) {
  8081. Base.call(this, 'digest')
  8082. this._hash = hash
  8083. }
  8084. inherits(Hash, Base)
  8085. Hash.prototype._update = function (data) {
  8086. this._hash.update(data)
  8087. }
  8088. Hash.prototype._final = function () {
  8089. return this._hash.digest()
  8090. }
  8091. module.exports = function createHash (alg) {
  8092. alg = alg.toLowerCase()
  8093. if ('md5' === alg) return new HashNoConstructor(md5)
  8094. if ('rmd160' === alg || 'ripemd160' === alg) return new HashNoConstructor(rmd160)
  8095. return new Hash(sha(alg))
  8096. }
  8097. }).call(this,require("buffer").Buffer)
  8098. },{"./md5":12,"buffer":7,"cipher-base":8,"inherits":16,"ripemd160":34,"sha.js":36}],11:[function(require,module,exports){
  8099. (function (Buffer){
  8100. 'use strict';
  8101. var intSize = 4;
  8102. var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0);
  8103. var chrsz = 8;
  8104. function toArray(buf, bigEndian) {
  8105. if ((buf.length % intSize) !== 0) {
  8106. var len = buf.length + (intSize - (buf.length % intSize));
  8107. buf = Buffer.concat([buf, zeroBuffer], len);
  8108. }
  8109. var arr = [];
  8110. var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE;
  8111. for (var i = 0; i < buf.length; i += intSize) {
  8112. arr.push(fn.call(buf, i));
  8113. }
  8114. return arr;
  8115. }
  8116. function toBuffer(arr, size, bigEndian) {
  8117. var buf = new Buffer(size);
  8118. var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE;
  8119. for (var i = 0; i < arr.length; i++) {
  8120. fn.call(buf, arr[i], i * 4, true);
  8121. }
  8122. return buf;
  8123. }
  8124. function hash(buf, fn, hashSize, bigEndian) {
  8125. if (!Buffer.isBuffer(buf)) buf = new Buffer(buf);
  8126. var arr = fn(toArray(buf, bigEndian), buf.length * chrsz);
  8127. return toBuffer(arr, hashSize, bigEndian);
  8128. }
  8129. exports.hash = hash;
  8130. }).call(this,require("buffer").Buffer)
  8131. },{"buffer":7}],12:[function(require,module,exports){
  8132. 'use strict';
  8133. /*
  8134. * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
  8135. * Digest Algorithm, as defined in RFC 1321.
  8136. * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
  8137. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  8138. * Distributed under the BSD License
  8139. * See http://pajhome.org.uk/crypt/md5 for more info.
  8140. */
  8141. var helpers = require('./helpers');
  8142. /*
  8143. * Calculate the MD5 of an array of little-endian words, and a bit length
  8144. */
  8145. function core_md5(x, len)
  8146. {
  8147. /* append padding */
  8148. x[len >> 5] |= 0x80 << ((len) % 32);
  8149. x[(((len + 64) >>> 9) << 4) + 14] = len;
  8150. var a = 1732584193;
  8151. var b = -271733879;
  8152. var c = -1732584194;
  8153. var d = 271733878;
  8154. for(var i = 0; i < x.length; i += 16)
  8155. {
  8156. var olda = a;
  8157. var oldb = b;
  8158. var oldc = c;
  8159. var oldd = d;
  8160. a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
  8161. d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
  8162. c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
  8163. b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
  8164. a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
  8165. d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
  8166. c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
  8167. b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
  8168. a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
  8169. d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
  8170. c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
  8171. b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
  8172. a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
  8173. d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
  8174. c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
  8175. b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
  8176. a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
  8177. d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
  8178. c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
  8179. b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
  8180. a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
  8181. d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
  8182. c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
  8183. b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
  8184. a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
  8185. d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
  8186. c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
  8187. b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
  8188. a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
  8189. d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
  8190. c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
  8191. b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
  8192. a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
  8193. d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
  8194. c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
  8195. b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
  8196. a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
  8197. d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
  8198. c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
  8199. b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
  8200. a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
  8201. d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
  8202. c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
  8203. b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
  8204. a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
  8205. d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
  8206. c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
  8207. b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
  8208. a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
  8209. d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
  8210. c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
  8211. b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
  8212. a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
  8213. d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
  8214. c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
  8215. b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
  8216. a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
  8217. d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
  8218. c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
  8219. b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
  8220. a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
  8221. d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
  8222. c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
  8223. b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
  8224. a = safe_add(a, olda);
  8225. b = safe_add(b, oldb);
  8226. c = safe_add(c, oldc);
  8227. d = safe_add(d, oldd);
  8228. }
  8229. return Array(a, b, c, d);
  8230. }
  8231. /*
  8232. * These functions implement the four basic operations the algorithm uses.
  8233. */
  8234. function md5_cmn(q, a, b, x, s, t)
  8235. {
  8236. return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
  8237. }
  8238. function md5_ff(a, b, c, d, x, s, t)
  8239. {
  8240. return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
  8241. }
  8242. function md5_gg(a, b, c, d, x, s, t)
  8243. {
  8244. return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
  8245. }
  8246. function md5_hh(a, b, c, d, x, s, t)
  8247. {
  8248. return md5_cmn(b ^ c ^ d, a, b, x, s, t);
  8249. }
  8250. function md5_ii(a, b, c, d, x, s, t)
  8251. {
  8252. return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
  8253. }
  8254. /*
  8255. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  8256. * to work around bugs in some JS interpreters.
  8257. */
  8258. function safe_add(x, y)
  8259. {
  8260. var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  8261. var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  8262. return (msw << 16) | (lsw & 0xFFFF);
  8263. }
  8264. /*
  8265. * Bitwise rotate a 32-bit number to the left.
  8266. */
  8267. function bit_rol(num, cnt)
  8268. {
  8269. return (num << cnt) | (num >>> (32 - cnt));
  8270. }
  8271. module.exports = function md5(buf) {
  8272. return helpers.hash(buf, core_md5, 16);
  8273. };
  8274. },{"./helpers":11}],13:[function(require,module,exports){
  8275. (function (Buffer){
  8276. 'use strict';
  8277. var createHash = require('create-hash/browser');
  8278. var inherits = require('inherits')
  8279. var Transform = require('stream').Transform
  8280. var ZEROS = new Buffer(128)
  8281. ZEROS.fill(0)
  8282. function Hmac(alg, key) {
  8283. Transform.call(this)
  8284. alg = alg.toLowerCase()
  8285. if (typeof key === 'string') {
  8286. key = new Buffer(key)
  8287. }
  8288. var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64
  8289. this._alg = alg
  8290. this._key = key
  8291. if (key.length > blocksize) {
  8292. key = createHash(alg).update(key).digest()
  8293. } else if (key.length < blocksize) {
  8294. key = Buffer.concat([key, ZEROS], blocksize)
  8295. }
  8296. var ipad = this._ipad = new Buffer(blocksize)
  8297. var opad = this._opad = new Buffer(blocksize)
  8298. for (var i = 0; i < blocksize; i++) {
  8299. ipad[i] = key[i] ^ 0x36
  8300. opad[i] = key[i] ^ 0x5C
  8301. }
  8302. this._hash = createHash(alg).update(ipad)
  8303. }
  8304. inherits(Hmac, Transform)
  8305. Hmac.prototype.update = function (data, enc) {
  8306. this._hash.update(data, enc)
  8307. return this
  8308. }
  8309. Hmac.prototype._transform = function (data, _, next) {
  8310. this._hash.update(data)
  8311. next()
  8312. }
  8313. Hmac.prototype._flush = function (next) {
  8314. this.push(this.digest())
  8315. next()
  8316. }
  8317. Hmac.prototype.digest = function (enc) {
  8318. var h = this._hash.digest()
  8319. return createHash(this._alg).update(this._opad).update(h).digest(enc)
  8320. }
  8321. module.exports = function createHmac(alg, key) {
  8322. return new Hmac(alg, key)
  8323. }
  8324. }).call(this,require("buffer").Buffer)
  8325. },{"buffer":7,"create-hash/browser":10,"inherits":16,"stream":43}],14:[function(require,module,exports){
  8326. // Copyright Joyent, Inc. and other Node contributors.
  8327. //
  8328. // Permission is hereby granted, free of charge, to any person obtaining a
  8329. // copy of this software and associated documentation files (the
  8330. // "Software"), to deal in the Software without restriction, including
  8331. // without limitation the rights to use, copy, modify, merge, publish,
  8332. // distribute, sublicense, and/or sell copies of the Software, and to permit
  8333. // persons to whom the Software is furnished to do so, subject to the
  8334. // following conditions:
  8335. //
  8336. // The above copyright notice and this permission notice shall be included
  8337. // in all copies or substantial portions of the Software.
  8338. //
  8339. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  8340. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  8341. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  8342. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  8343. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  8344. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  8345. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  8346. function EventEmitter() {
  8347. this._events = this._events || {};
  8348. this._maxListeners = this._maxListeners || undefined;
  8349. }
  8350. module.exports = EventEmitter;
  8351. // Backwards-compat with node 0.10.x
  8352. EventEmitter.EventEmitter = EventEmitter;
  8353. EventEmitter.prototype._events = undefined;
  8354. EventEmitter.prototype._maxListeners = undefined;
  8355. // By default EventEmitters will print a warning if more than 10 listeners are
  8356. // added to it. This is a useful default which helps finding memory leaks.
  8357. EventEmitter.defaultMaxListeners = 10;
  8358. // Obviously not all Emitters should be limited to 10. This function allows
  8359. // that to be increased. Set to zero for unlimited.
  8360. EventEmitter.prototype.setMaxListeners = function(n) {
  8361. if (!isNumber(n) || n < 0 || isNaN(n))
  8362. throw TypeError('n must be a positive number');
  8363. this._maxListeners = n;
  8364. return this;
  8365. };
  8366. EventEmitter.prototype.emit = function(type) {
  8367. var er, handler, len, args, i, listeners;
  8368. if (!this._events)
  8369. this._events = {};
  8370. // If there is no 'error' event listener then throw.
  8371. if (type === 'error') {
  8372. if (!this._events.error ||
  8373. (isObject(this._events.error) && !this._events.error.length)) {
  8374. er = arguments[1];
  8375. if (er instanceof Error) {
  8376. throw er; // Unhandled 'error' event
  8377. } else {
  8378. // At least give some kind of context to the user
  8379. var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
  8380. err.context = er;
  8381. throw err;
  8382. }
  8383. }
  8384. }
  8385. handler = this._events[type];
  8386. if (isUndefined(handler))
  8387. return false;
  8388. if (isFunction(handler)) {
  8389. switch (arguments.length) {
  8390. // fast cases
  8391. case 1:
  8392. handler.call(this);
  8393. break;
  8394. case 2:
  8395. handler.call(this, arguments[1]);
  8396. break;
  8397. case 3:
  8398. handler.call(this, arguments[1], arguments[2]);
  8399. break;
  8400. // slower
  8401. default:
  8402. args = Array.prototype.slice.call(arguments, 1);
  8403. handler.apply(this, args);
  8404. }
  8405. } else if (isObject(handler)) {
  8406. args = Array.prototype.slice.call(arguments, 1);
  8407. listeners = handler.slice();
  8408. len = listeners.length;
  8409. for (i = 0; i < len; i++)
  8410. listeners[i].apply(this, args);
  8411. }
  8412. return true;
  8413. };
  8414. EventEmitter.prototype.addListener = function(type, listener) {
  8415. var m;
  8416. if (!isFunction(listener))
  8417. throw TypeError('listener must be a function');
  8418. if (!this._events)
  8419. this._events = {};
  8420. // To avoid recursion in the case that type === "newListener"! Before
  8421. // adding it to the listeners, first emit "newListener".
  8422. if (this._events.newListener)
  8423. this.emit('newListener', type,
  8424. isFunction(listener.listener) ?
  8425. listener.listener : listener);
  8426. if (!this._events[type])
  8427. // Optimize the case of one listener. Don't need the extra array object.
  8428. this._events[type] = listener;
  8429. else if (isObject(this._events[type]))
  8430. // If we've already got an array, just append.
  8431. this._events[type].push(listener);
  8432. else
  8433. // Adding the second element, need to change to array.
  8434. this._events[type] = [this._events[type], listener];
  8435. // Check for listener leak
  8436. if (isObject(this._events[type]) && !this._events[type].warned) {
  8437. if (!isUndefined(this._maxListeners)) {
  8438. m = this._maxListeners;
  8439. } else {
  8440. m = EventEmitter.defaultMaxListeners;
  8441. }
  8442. if (m && m > 0 && this._events[type].length > m) {
  8443. this._events[type].warned = true;
  8444. console.error('(node) warning: possible EventEmitter memory ' +
  8445. 'leak detected. %d listeners added. ' +
  8446. 'Use emitter.setMaxListeners() to increase limit.',
  8447. this._events[type].length);
  8448. if (typeof console.trace === 'function') {
  8449. // not supported in IE 10
  8450. console.trace();
  8451. }
  8452. }
  8453. }
  8454. return this;
  8455. };
  8456. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  8457. EventEmitter.prototype.once = function(type, listener) {
  8458. if (!isFunction(listener))
  8459. throw TypeError('listener must be a function');
  8460. var fired = false;
  8461. function g() {
  8462. this.removeListener(type, g);
  8463. if (!fired) {
  8464. fired = true;
  8465. listener.apply(this, arguments);
  8466. }
  8467. }
  8468. g.listener = listener;
  8469. this.on(type, g);
  8470. return this;
  8471. };
  8472. // emits a 'removeListener' event iff the listener was removed
  8473. EventEmitter.prototype.removeListener = function(type, listener) {
  8474. var list, position, length, i;
  8475. if (!isFunction(listener))
  8476. throw TypeError('listener must be a function');
  8477. if (!this._events || !this._events[type])
  8478. return this;
  8479. list = this._events[type];
  8480. length = list.length;
  8481. position = -1;
  8482. if (list === listener ||
  8483. (isFunction(list.listener) && list.listener === listener)) {
  8484. delete this._events[type];
  8485. if (this._events.removeListener)
  8486. this.emit('removeListener', type, listener);
  8487. } else if (isObject(list)) {
  8488. for (i = length; i-- > 0;) {
  8489. if (list[i] === listener ||
  8490. (list[i].listener && list[i].listener === listener)) {
  8491. position = i;
  8492. break;
  8493. }
  8494. }
  8495. if (position < 0)
  8496. return this;
  8497. if (list.length === 1) {
  8498. list.length = 0;
  8499. delete this._events[type];
  8500. } else {
  8501. list.splice(position, 1);
  8502. }
  8503. if (this._events.removeListener)
  8504. this.emit('removeListener', type, listener);
  8505. }
  8506. return this;
  8507. };
  8508. EventEmitter.prototype.removeAllListeners = function(type) {
  8509. var key, listeners;
  8510. if (!this._events)
  8511. return this;
  8512. // not listening for removeListener, no need to emit
  8513. if (!this._events.removeListener) {
  8514. if (arguments.length === 0)
  8515. this._events = {};
  8516. else if (this._events[type])
  8517. delete this._events[type];
  8518. return this;
  8519. }
  8520. // emit removeListener for all listeners on all events
  8521. if (arguments.length === 0) {
  8522. for (key in this._events) {
  8523. if (key === 'removeListener') continue;
  8524. this.removeAllListeners(key);
  8525. }
  8526. this.removeAllListeners('removeListener');
  8527. this._events = {};
  8528. return this;
  8529. }
  8530. listeners = this._events[type];
  8531. if (isFunction(listeners)) {
  8532. this.removeListener(type, listeners);
  8533. } else if (listeners) {
  8534. // LIFO order
  8535. while (listeners.length)
  8536. this.removeListener(type, listeners[listeners.length - 1]);
  8537. }
  8538. delete this._events[type];
  8539. return this;
  8540. };
  8541. EventEmitter.prototype.listeners = function(type) {
  8542. var ret;
  8543. if (!this._events || !this._events[type])
  8544. ret = [];
  8545. else if (isFunction(this._events[type]))
  8546. ret = [this._events[type]];
  8547. else
  8548. ret = this._events[type].slice();
  8549. return ret;
  8550. };
  8551. EventEmitter.prototype.listenerCount = function(type) {
  8552. if (this._events) {
  8553. var evlistener = this._events[type];
  8554. if (isFunction(evlistener))
  8555. return 1;
  8556. else if (evlistener)
  8557. return evlistener.length;
  8558. }
  8559. return 0;
  8560. };
  8561. EventEmitter.listenerCount = function(emitter, type) {
  8562. return emitter.listenerCount(type);
  8563. };
  8564. function isFunction(arg) {
  8565. return typeof arg === 'function';
  8566. }
  8567. function isNumber(arg) {
  8568. return typeof arg === 'number';
  8569. }
  8570. function isObject(arg) {
  8571. return typeof arg === 'object' && arg !== null;
  8572. }
  8573. function isUndefined(arg) {
  8574. return arg === void 0;
  8575. }
  8576. },{}],15:[function(require,module,exports){
  8577. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  8578. var e, m
  8579. var eLen = nBytes * 8 - mLen - 1
  8580. var eMax = (1 << eLen) - 1
  8581. var eBias = eMax >> 1
  8582. var nBits = -7
  8583. var i = isLE ? (nBytes - 1) : 0
  8584. var d = isLE ? -1 : 1
  8585. var s = buffer[offset + i]
  8586. i += d
  8587. e = s & ((1 << (-nBits)) - 1)
  8588. s >>= (-nBits)
  8589. nBits += eLen
  8590. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  8591. m = e & ((1 << (-nBits)) - 1)
  8592. e >>= (-nBits)
  8593. nBits += mLen
  8594. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  8595. if (e === 0) {
  8596. e = 1 - eBias
  8597. } else if (e === eMax) {
  8598. return m ? NaN : ((s ? -1 : 1) * Infinity)
  8599. } else {
  8600. m = m + Math.pow(2, mLen)
  8601. e = e - eBias
  8602. }
  8603. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  8604. }
  8605. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  8606. var e, m, c
  8607. var eLen = nBytes * 8 - mLen - 1
  8608. var eMax = (1 << eLen) - 1
  8609. var eBias = eMax >> 1
  8610. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  8611. var i = isLE ? 0 : (nBytes - 1)
  8612. var d = isLE ? 1 : -1
  8613. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  8614. value = Math.abs(value)
  8615. if (isNaN(value) || value === Infinity) {
  8616. m = isNaN(value) ? 1 : 0
  8617. e = eMax
  8618. } else {
  8619. e = Math.floor(Math.log(value) / Math.LN2)
  8620. if (value * (c = Math.pow(2, -e)) < 1) {
  8621. e--
  8622. c *= 2
  8623. }
  8624. if (e + eBias >= 1) {
  8625. value += rt / c
  8626. } else {
  8627. value += rt * Math.pow(2, 1 - eBias)
  8628. }
  8629. if (value * c >= 2) {
  8630. e++
  8631. c /= 2
  8632. }
  8633. if (e + eBias >= eMax) {
  8634. m = 0
  8635. e = eMax
  8636. } else if (e + eBias >= 1) {
  8637. m = (value * c - 1) * Math.pow(2, mLen)
  8638. e = e + eBias
  8639. } else {
  8640. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  8641. e = 0
  8642. }
  8643. }
  8644. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  8645. e = (e << mLen) | m
  8646. eLen += mLen
  8647. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  8648. buffer[offset + i - d] |= s * 128
  8649. }
  8650. },{}],16:[function(require,module,exports){
  8651. if (typeof Object.create === 'function') {
  8652. // implementation from standard node.js 'util' module
  8653. module.exports = function inherits(ctor, superCtor) {
  8654. ctor.super_ = superCtor
  8655. ctor.prototype = Object.create(superCtor.prototype, {
  8656. constructor: {
  8657. value: ctor,
  8658. enumerable: false,
  8659. writable: true,
  8660. configurable: true
  8661. }
  8662. });
  8663. };
  8664. } else {
  8665. // old school shim for old browsers
  8666. module.exports = function inherits(ctor, superCtor) {
  8667. ctor.super_ = superCtor
  8668. var TempCtor = function () {}
  8669. TempCtor.prototype = superCtor.prototype
  8670. ctor.prototype = new TempCtor()
  8671. ctor.prototype.constructor = ctor
  8672. }
  8673. }
  8674. },{}],17:[function(require,module,exports){
  8675. /*!
  8676. * Determine if an object is a Buffer
  8677. *
  8678. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  8679. * @license MIT
  8680. */
  8681. // The _isBuffer check is for Safari 5-7 support, because it's missing
  8682. // Object.prototype.constructor. Remove this eventually
  8683. module.exports = function (obj) {
  8684. return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
  8685. }
  8686. function isBuffer (obj) {
  8687. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  8688. }
  8689. // For Node v0.10 support. Remove this eventually.
  8690. function isSlowBuffer (obj) {
  8691. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
  8692. }
  8693. },{}],18:[function(require,module,exports){
  8694. var toString = {}.toString;
  8695. module.exports = Array.isArray || function (arr) {
  8696. return toString.call(arr) == '[object Array]';
  8697. };
  8698. },{}],19:[function(require,module,exports){
  8699. (function (process,Buffer){
  8700. var createHmac = require('create-hmac')
  8701. var checkParameters = require('./precondition')
  8702. exports.pbkdf2 = function (password, salt, iterations, keylen, digest, callback) {
  8703. if (typeof digest === 'function') {
  8704. callback = digest
  8705. digest = undefined
  8706. }
  8707. checkParameters(iterations, keylen)
  8708. if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2')
  8709. setTimeout(function () {
  8710. callback(null, exports.pbkdf2Sync(password, salt, iterations, keylen, digest))
  8711. })
  8712. }
  8713. var defaultEncoding
  8714. if (process.browser) {
  8715. defaultEncoding = 'utf-8'
  8716. } else {
  8717. var pVersionMajor = parseInt(process.version.split('.')[0].slice(1), 10)
  8718. defaultEncoding = pVersionMajor >= 6 ? 'utf-8' : 'binary'
  8719. }
  8720. exports.pbkdf2Sync = function (password, salt, iterations, keylen, digest) {
  8721. if (!Buffer.isBuffer(password)) password = new Buffer(password, defaultEncoding)
  8722. if (!Buffer.isBuffer(salt)) salt = new Buffer(salt, defaultEncoding)
  8723. checkParameters(iterations, keylen)
  8724. digest = digest || 'sha1'
  8725. var hLen
  8726. var l = 1
  8727. var DK = new Buffer(keylen)
  8728. var block1 = new Buffer(salt.length + 4)
  8729. salt.copy(block1, 0, 0, salt.length)
  8730. var r
  8731. var T
  8732. for (var i = 1; i <= l; i++) {
  8733. block1.writeUInt32BE(i, salt.length)
  8734. var U = createHmac(digest, password).update(block1).digest()
  8735. if (!hLen) {
  8736. hLen = U.length
  8737. T = new Buffer(hLen)
  8738. l = Math.ceil(keylen / hLen)
  8739. r = keylen - (l - 1) * hLen
  8740. }
  8741. U.copy(T, 0, 0, hLen)
  8742. for (var j = 1; j < iterations; j++) {
  8743. U = createHmac(digest, password).update(U).digest()
  8744. for (var k = 0; k < hLen; k++) T[k] ^= U[k]
  8745. }
  8746. var destPos = (i - 1) * hLen
  8747. var len = (i === l ? r : hLen)
  8748. T.copy(DK, destPos, 0, len)
  8749. }
  8750. return DK
  8751. }
  8752. }).call(this,require('_process'),require("buffer").Buffer)
  8753. },{"./precondition":20,"_process":22,"buffer":7,"create-hmac":13}],20:[function(require,module,exports){
  8754. var MAX_ALLOC = Math.pow(2, 30) - 1 // default in iojs
  8755. module.exports = function (iterations, keylen) {
  8756. if (typeof iterations !== 'number') {
  8757. throw new TypeError('Iterations not a number')
  8758. }
  8759. if (iterations < 0) {
  8760. throw new TypeError('Bad iterations')
  8761. }
  8762. if (typeof keylen !== 'number') {
  8763. throw new TypeError('Key length not a number')
  8764. }
  8765. if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) { /* eslint no-self-compare: 0 */
  8766. throw new TypeError('Bad key length')
  8767. }
  8768. }
  8769. },{}],21:[function(require,module,exports){
  8770. (function (process){
  8771. 'use strict';
  8772. if (!process.version ||
  8773. process.version.indexOf('v0.') === 0 ||
  8774. process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
  8775. module.exports = nextTick;
  8776. } else {
  8777. module.exports = process.nextTick;
  8778. }
  8779. function nextTick(fn, arg1, arg2, arg3) {
  8780. if (typeof fn !== 'function') {
  8781. throw new TypeError('"callback" argument must be a function');
  8782. }
  8783. var len = arguments.length;
  8784. var args, i;
  8785. switch (len) {
  8786. case 0:
  8787. case 1:
  8788. return process.nextTick(fn);
  8789. case 2:
  8790. return process.nextTick(function afterTickOne() {
  8791. fn.call(null, arg1);
  8792. });
  8793. case 3:
  8794. return process.nextTick(function afterTickTwo() {
  8795. fn.call(null, arg1, arg2);
  8796. });
  8797. case 4:
  8798. return process.nextTick(function afterTickThree() {
  8799. fn.call(null, arg1, arg2, arg3);
  8800. });
  8801. default:
  8802. args = new Array(len - 1);
  8803. i = 0;
  8804. while (i < args.length) {
  8805. args[i++] = arguments[i];
  8806. }
  8807. return process.nextTick(function afterTick() {
  8808. fn.apply(null, args);
  8809. });
  8810. }
  8811. }
  8812. }).call(this,require('_process'))
  8813. },{"_process":22}],22:[function(require,module,exports){
  8814. // shim for using process in browser
  8815. var process = module.exports = {};
  8816. // cached from whatever global is present so that test runners that stub it
  8817. // don't break things. But we need to wrap it in a try catch in case it is
  8818. // wrapped in strict mode code which doesn't define any globals. It's inside a
  8819. // function because try/catches deoptimize in certain engines.
  8820. var cachedSetTimeout;
  8821. var cachedClearTimeout;
  8822. function defaultSetTimout() {
  8823. throw new Error('setTimeout has not been defined');
  8824. }
  8825. function defaultClearTimeout () {
  8826. throw new Error('clearTimeout has not been defined');
  8827. }
  8828. (function () {
  8829. try {
  8830. if (typeof setTimeout === 'function') {
  8831. cachedSetTimeout = setTimeout;
  8832. } else {
  8833. cachedSetTimeout = defaultSetTimout;
  8834. }
  8835. } catch (e) {
  8836. cachedSetTimeout = defaultSetTimout;
  8837. }
  8838. try {
  8839. if (typeof clearTimeout === 'function') {
  8840. cachedClearTimeout = clearTimeout;
  8841. } else {
  8842. cachedClearTimeout = defaultClearTimeout;
  8843. }
  8844. } catch (e) {
  8845. cachedClearTimeout = defaultClearTimeout;
  8846. }
  8847. } ())
  8848. function runTimeout(fun) {
  8849. if (cachedSetTimeout === setTimeout) {
  8850. //normal enviroments in sane situations
  8851. return setTimeout(fun, 0);
  8852. }
  8853. // if setTimeout wasn't available but was latter defined
  8854. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  8855. cachedSetTimeout = setTimeout;
  8856. return setTimeout(fun, 0);
  8857. }
  8858. try {
  8859. // when when somebody has screwed with setTimeout but no I.E. maddness
  8860. return cachedSetTimeout(fun, 0);
  8861. } catch(e){
  8862. try {
  8863. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  8864. return cachedSetTimeout.call(null, fun, 0);
  8865. } catch(e){
  8866. // 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
  8867. return cachedSetTimeout.call(this, fun, 0);
  8868. }
  8869. }
  8870. }
  8871. function runClearTimeout(marker) {
  8872. if (cachedClearTimeout === clearTimeout) {
  8873. //normal enviroments in sane situations
  8874. return clearTimeout(marker);
  8875. }
  8876. // if clearTimeout wasn't available but was latter defined
  8877. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  8878. cachedClearTimeout = clearTimeout;
  8879. return clearTimeout(marker);
  8880. }
  8881. try {
  8882. // when when somebody has screwed with setTimeout but no I.E. maddness
  8883. return cachedClearTimeout(marker);
  8884. } catch (e){
  8885. try {
  8886. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  8887. return cachedClearTimeout.call(null, marker);
  8888. } catch (e){
  8889. // 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.
  8890. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  8891. return cachedClearTimeout.call(this, marker);
  8892. }
  8893. }
  8894. }
  8895. var queue = [];
  8896. var draining = false;
  8897. var currentQueue;
  8898. var queueIndex = -1;
  8899. function cleanUpNextTick() {
  8900. if (!draining || !currentQueue) {
  8901. return;
  8902. }
  8903. draining = false;
  8904. if (currentQueue.length) {
  8905. queue = currentQueue.concat(queue);
  8906. } else {
  8907. queueIndex = -1;
  8908. }
  8909. if (queue.length) {
  8910. drainQueue();
  8911. }
  8912. }
  8913. function drainQueue() {
  8914. if (draining) {
  8915. return;
  8916. }
  8917. var timeout = runTimeout(cleanUpNextTick);
  8918. draining = true;
  8919. var len = queue.length;
  8920. while(len) {
  8921. currentQueue = queue;
  8922. queue = [];
  8923. while (++queueIndex < len) {
  8924. if (currentQueue) {
  8925. currentQueue[queueIndex].run();
  8926. }
  8927. }
  8928. queueIndex = -1;
  8929. len = queue.length;
  8930. }
  8931. currentQueue = null;
  8932. draining = false;
  8933. runClearTimeout(timeout);
  8934. }
  8935. process.nextTick = function (fun) {
  8936. var args = new Array(arguments.length - 1);
  8937. if (arguments.length > 1) {
  8938. for (var i = 1; i < arguments.length; i++) {
  8939. args[i - 1] = arguments[i];
  8940. }
  8941. }
  8942. queue.push(new Item(fun, args));
  8943. if (queue.length === 1 && !draining) {
  8944. runTimeout(drainQueue);
  8945. }
  8946. };
  8947. // v8 likes predictible objects
  8948. function Item(fun, array) {
  8949. this.fun = fun;
  8950. this.array = array;
  8951. }
  8952. Item.prototype.run = function () {
  8953. this.fun.apply(null, this.array);
  8954. };
  8955. process.title = 'browser';
  8956. process.browser = true;
  8957. process.env = {};
  8958. process.argv = [];
  8959. process.version = ''; // empty string to avoid regexp issues
  8960. process.versions = {};
  8961. function noop() {}
  8962. process.on = noop;
  8963. process.addListener = noop;
  8964. process.once = noop;
  8965. process.off = noop;
  8966. process.removeListener = noop;
  8967. process.removeAllListeners = noop;
  8968. process.emit = noop;
  8969. process.binding = function (name) {
  8970. throw new Error('process.binding is not supported');
  8971. };
  8972. process.cwd = function () { return '/' };
  8973. process.chdir = function (dir) {
  8974. throw new Error('process.chdir is not supported');
  8975. };
  8976. process.umask = function() { return 0; };
  8977. },{}],23:[function(require,module,exports){
  8978. module.exports = require("./lib/_stream_duplex.js")
  8979. },{"./lib/_stream_duplex.js":24}],24:[function(require,module,exports){
  8980. // a duplex stream is just a stream that is both readable and writable.
  8981. // Since JS doesn't have multiple prototypal inheritance, this class
  8982. // prototypally inherits from Readable, and then parasitically from
  8983. // Writable.
  8984. 'use strict';
  8985. /*<replacement>*/
  8986. var objectKeys = Object.keys || function (obj) {
  8987. var keys = [];
  8988. for (var key in obj) {
  8989. keys.push(key);
  8990. }return keys;
  8991. };
  8992. /*</replacement>*/
  8993. module.exports = Duplex;
  8994. /*<replacement>*/
  8995. var processNextTick = require('process-nextick-args');
  8996. /*</replacement>*/
  8997. /*<replacement>*/
  8998. var util = require('core-util-is');
  8999. util.inherits = require('inherits');
  9000. /*</replacement>*/
  9001. var Readable = require('./_stream_readable');
  9002. var Writable = require('./_stream_writable');
  9003. util.inherits(Duplex, Readable);
  9004. var keys = objectKeys(Writable.prototype);
  9005. for (var v = 0; v < keys.length; v++) {
  9006. var method = keys[v];
  9007. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  9008. }
  9009. function Duplex(options) {
  9010. if (!(this instanceof Duplex)) return new Duplex(options);
  9011. Readable.call(this, options);
  9012. Writable.call(this, options);
  9013. if (options && options.readable === false) this.readable = false;
  9014. if (options && options.writable === false) this.writable = false;
  9015. this.allowHalfOpen = true;
  9016. if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
  9017. this.once('end', onend);
  9018. }
  9019. // the no-half-open enforcer
  9020. function onend() {
  9021. // if we allow half-open state, or if the writable side ended,
  9022. // then we're ok.
  9023. if (this.allowHalfOpen || this._writableState.ended) return;
  9024. // no more data can be written.
  9025. // But allow more writes to happen in this tick.
  9026. processNextTick(onEndNT, this);
  9027. }
  9028. function onEndNT(self) {
  9029. self.end();
  9030. }
  9031. function forEach(xs, f) {
  9032. for (var i = 0, l = xs.length; i < l; i++) {
  9033. f(xs[i], i);
  9034. }
  9035. }
  9036. },{"./_stream_readable":26,"./_stream_writable":28,"core-util-is":9,"inherits":16,"process-nextick-args":21}],25:[function(require,module,exports){
  9037. // a passthrough stream.
  9038. // basically just the most minimal sort of Transform stream.
  9039. // Every written chunk gets output as-is.
  9040. 'use strict';
  9041. module.exports = PassThrough;
  9042. var Transform = require('./_stream_transform');
  9043. /*<replacement>*/
  9044. var util = require('core-util-is');
  9045. util.inherits = require('inherits');
  9046. /*</replacement>*/
  9047. util.inherits(PassThrough, Transform);
  9048. function PassThrough(options) {
  9049. if (!(this instanceof PassThrough)) return new PassThrough(options);
  9050. Transform.call(this, options);
  9051. }
  9052. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  9053. cb(null, chunk);
  9054. };
  9055. },{"./_stream_transform":27,"core-util-is":9,"inherits":16}],26:[function(require,module,exports){
  9056. (function (process){
  9057. 'use strict';
  9058. module.exports = Readable;
  9059. /*<replacement>*/
  9060. var processNextTick = require('process-nextick-args');
  9061. /*</replacement>*/
  9062. /*<replacement>*/
  9063. var isArray = require('isarray');
  9064. /*</replacement>*/
  9065. Readable.ReadableState = ReadableState;
  9066. /*<replacement>*/
  9067. var EE = require('events').EventEmitter;
  9068. var EElistenerCount = function (emitter, type) {
  9069. return emitter.listeners(type).length;
  9070. };
  9071. /*</replacement>*/
  9072. /*<replacement>*/
  9073. var Stream;
  9074. (function () {
  9075. try {
  9076. Stream = require('st' + 'ream');
  9077. } catch (_) {} finally {
  9078. if (!Stream) Stream = require('events').EventEmitter;
  9079. }
  9080. })();
  9081. /*</replacement>*/
  9082. var Buffer = require('buffer').Buffer;
  9083. /*<replacement>*/
  9084. var bufferShim = require('buffer-shims');
  9085. /*</replacement>*/
  9086. /*<replacement>*/
  9087. var util = require('core-util-is');
  9088. util.inherits = require('inherits');
  9089. /*</replacement>*/
  9090. /*<replacement>*/
  9091. var debugUtil = require('util');
  9092. var debug = void 0;
  9093. if (debugUtil && debugUtil.debuglog) {
  9094. debug = debugUtil.debuglog('stream');
  9095. } else {
  9096. debug = function () {};
  9097. }
  9098. /*</replacement>*/
  9099. var BufferList = require('./internal/streams/BufferList');
  9100. var StringDecoder;
  9101. util.inherits(Readable, Stream);
  9102. function prependListener(emitter, event, fn) {
  9103. if (typeof emitter.prependListener === 'function') {
  9104. return emitter.prependListener(event, fn);
  9105. } else {
  9106. // This is a hack to make sure that our error handler is attached before any
  9107. // userland ones. NEVER DO THIS. This is here only because this code needs
  9108. // to continue to work with older versions of Node.js that do not include
  9109. // the prependListener() method. The goal is to eventually remove this hack.
  9110. 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]];
  9111. }
  9112. }
  9113. var Duplex;
  9114. function ReadableState(options, stream) {
  9115. Duplex = Duplex || require('./_stream_duplex');
  9116. options = options || {};
  9117. // object stream flag. Used to make read(n) ignore n and to
  9118. // make all the buffer merging and length checks go away
  9119. this.objectMode = !!options.objectMode;
  9120. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
  9121. // the point at which it stops calling _read() to fill the buffer
  9122. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  9123. var hwm = options.highWaterMark;
  9124. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  9125. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  9126. // cast to ints.
  9127. this.highWaterMark = ~ ~this.highWaterMark;
  9128. // A linked list is used to store data chunks instead of an array because the
  9129. // linked list can remove elements from the beginning faster than
  9130. // array.shift()
  9131. this.buffer = new BufferList();
  9132. this.length = 0;
  9133. this.pipes = null;
  9134. this.pipesCount = 0;
  9135. this.flowing = null;
  9136. this.ended = false;
  9137. this.endEmitted = false;
  9138. this.reading = false;
  9139. // a flag to be able to tell if the onwrite cb is called immediately,
  9140. // or on a later tick. We set this to true at first, because any
  9141. // actions that shouldn't happen until "later" should generally also
  9142. // not happen before the first write call.
  9143. this.sync = true;
  9144. // whenever we return null, then we set a flag to say
  9145. // that we're awaiting a 'readable' event emission.
  9146. this.needReadable = false;
  9147. this.emittedReadable = false;
  9148. this.readableListening = false;
  9149. this.resumeScheduled = false;
  9150. // Crypto is kind of old and crusty. Historically, its default string
  9151. // encoding is 'binary' so we have to make this configurable.
  9152. // Everything else in the universe uses 'utf8', though.
  9153. this.defaultEncoding = options.defaultEncoding || 'utf8';
  9154. // when piping, we only care about 'readable' events that happen
  9155. // after read()ing all the bytes and not getting any pushback.
  9156. this.ranOut = false;
  9157. // the number of writers that are awaiting a drain event in .pipe()s
  9158. this.awaitDrain = 0;
  9159. // if true, a maybeReadMore has been scheduled
  9160. this.readingMore = false;
  9161. this.decoder = null;
  9162. this.encoding = null;
  9163. if (options.encoding) {
  9164. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  9165. this.decoder = new StringDecoder(options.encoding);
  9166. this.encoding = options.encoding;
  9167. }
  9168. }
  9169. var Duplex;
  9170. function Readable(options) {
  9171. Duplex = Duplex || require('./_stream_duplex');
  9172. if (!(this instanceof Readable)) return new Readable(options);
  9173. this._readableState = new ReadableState(options, this);
  9174. // legacy
  9175. this.readable = true;
  9176. if (options && typeof options.read === 'function') this._read = options.read;
  9177. Stream.call(this);
  9178. }
  9179. // Manually shove something into the read() buffer.
  9180. // This returns true if the highWaterMark has not been hit yet,
  9181. // similar to how Writable.write() returns true if you should
  9182. // write() some more.
  9183. Readable.prototype.push = function (chunk, encoding) {
  9184. var state = this._readableState;
  9185. if (!state.objectMode && typeof chunk === 'string') {
  9186. encoding = encoding || state.defaultEncoding;
  9187. if (encoding !== state.encoding) {
  9188. chunk = bufferShim.from(chunk, encoding);
  9189. encoding = '';
  9190. }
  9191. }
  9192. return readableAddChunk(this, state, chunk, encoding, false);
  9193. };
  9194. // Unshift should *always* be something directly out of read()
  9195. Readable.prototype.unshift = function (chunk) {
  9196. var state = this._readableState;
  9197. return readableAddChunk(this, state, chunk, '', true);
  9198. };
  9199. Readable.prototype.isPaused = function () {
  9200. return this._readableState.flowing === false;
  9201. };
  9202. function readableAddChunk(stream, state, chunk, encoding, addToFront) {
  9203. var er = chunkInvalid(state, chunk);
  9204. if (er) {
  9205. stream.emit('error', er);
  9206. } else if (chunk === null) {
  9207. state.reading = false;
  9208. onEofChunk(stream, state);
  9209. } else if (state.objectMode || chunk && chunk.length > 0) {
  9210. if (state.ended && !addToFront) {
  9211. var e = new Error('stream.push() after EOF');
  9212. stream.emit('error', e);
  9213. } else if (state.endEmitted && addToFront) {
  9214. var _e = new Error('stream.unshift() after end event');
  9215. stream.emit('error', _e);
  9216. } else {
  9217. var skipAdd;
  9218. if (state.decoder && !addToFront && !encoding) {
  9219. chunk = state.decoder.write(chunk);
  9220. skipAdd = !state.objectMode && chunk.length === 0;
  9221. }
  9222. if (!addToFront) state.reading = false;
  9223. // Don't add to the buffer if we've decoded to an empty string chunk and
  9224. // we're not in object mode
  9225. if (!skipAdd) {
  9226. // if we want the data now, just emit it.
  9227. if (state.flowing && state.length === 0 && !state.sync) {
  9228. stream.emit('data', chunk);
  9229. stream.read(0);
  9230. } else {
  9231. // update the buffer info.
  9232. state.length += state.objectMode ? 1 : chunk.length;
  9233. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  9234. if (state.needReadable) emitReadable(stream);
  9235. }
  9236. }
  9237. maybeReadMore(stream, state);
  9238. }
  9239. } else if (!addToFront) {
  9240. state.reading = false;
  9241. }
  9242. return needMoreData(state);
  9243. }
  9244. // if it's past the high water mark, we can push in some more.
  9245. // Also, if we have no data yet, we can stand some
  9246. // more bytes. This is to work around cases where hwm=0,
  9247. // such as the repl. Also, if the push() triggered a
  9248. // readable event, and the user called read(largeNumber) such that
  9249. // needReadable was set, then we ought to push more, so that another
  9250. // 'readable' event will be triggered.
  9251. function needMoreData(state) {
  9252. return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
  9253. }
  9254. // backwards compatibility.
  9255. Readable.prototype.setEncoding = function (enc) {
  9256. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  9257. this._readableState.decoder = new StringDecoder(enc);
  9258. this._readableState.encoding = enc;
  9259. return this;
  9260. };
  9261. // Don't raise the hwm > 8MB
  9262. var MAX_HWM = 0x800000;
  9263. function computeNewHighWaterMark(n) {
  9264. if (n >= MAX_HWM) {
  9265. n = MAX_HWM;
  9266. } else {
  9267. // Get the next highest power of 2 to prevent increasing hwm excessively in
  9268. // tiny amounts
  9269. n--;
  9270. n |= n >>> 1;
  9271. n |= n >>> 2;
  9272. n |= n >>> 4;
  9273. n |= n >>> 8;
  9274. n |= n >>> 16;
  9275. n++;
  9276. }
  9277. return n;
  9278. }
  9279. // This function is designed to be inlinable, so please take care when making
  9280. // changes to the function body.
  9281. function howMuchToRead(n, state) {
  9282. if (n <= 0 || state.length === 0 && state.ended) return 0;
  9283. if (state.objectMode) return 1;
  9284. if (n !== n) {
  9285. // Only flow one buffer at a time
  9286. if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
  9287. }
  9288. // If we're asking for more than the current hwm, then raise the hwm.
  9289. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  9290. if (n <= state.length) return n;
  9291. // Don't have enough
  9292. if (!state.ended) {
  9293. state.needReadable = true;
  9294. return 0;
  9295. }
  9296. return state.length;
  9297. }
  9298. // you can override either this method, or the async _read(n) below.
  9299. Readable.prototype.read = function (n) {
  9300. debug('read', n);
  9301. n = parseInt(n, 10);
  9302. var state = this._readableState;
  9303. var nOrig = n;
  9304. if (n !== 0) state.emittedReadable = false;
  9305. // if we're doing read(0) to trigger a readable event, but we
  9306. // already have a bunch of data in the buffer, then just trigger
  9307. // the 'readable' event and move on.
  9308. if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
  9309. debug('read: emitReadable', state.length, state.ended);
  9310. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  9311. return null;
  9312. }
  9313. n = howMuchToRead(n, state);
  9314. // if we've ended, and we're now clear, then finish it up.
  9315. if (n === 0 && state.ended) {
  9316. if (state.length === 0) endReadable(this);
  9317. return null;
  9318. }
  9319. // All the actual chunk generation logic needs to be
  9320. // *below* the call to _read. The reason is that in certain
  9321. // synthetic stream cases, such as passthrough streams, _read
  9322. // may be a completely synchronous operation which may change
  9323. // the state of the read buffer, providing enough data when
  9324. // before there was *not* enough.
  9325. //
  9326. // So, the steps are:
  9327. // 1. Figure out what the state of things will be after we do
  9328. // a read from the buffer.
  9329. //
  9330. // 2. If that resulting state will trigger a _read, then call _read.
  9331. // Note that this may be asynchronous, or synchronous. Yes, it is
  9332. // deeply ugly to write APIs this way, but that still doesn't mean
  9333. // that the Readable class should behave improperly, as streams are
  9334. // designed to be sync/async agnostic.
  9335. // Take note if the _read call is sync or async (ie, if the read call
  9336. // has returned yet), so that we know whether or not it's safe to emit
  9337. // 'readable' etc.
  9338. //
  9339. // 3. Actually pull the requested chunks out of the buffer and return.
  9340. // if we need a readable event, then we need to do some reading.
  9341. var doRead = state.needReadable;
  9342. debug('need readable', doRead);
  9343. // if we currently have less than the highWaterMark, then also read some
  9344. if (state.length === 0 || state.length - n < state.highWaterMark) {
  9345. doRead = true;
  9346. debug('length less than watermark', doRead);
  9347. }
  9348. // however, if we've ended, then there's no point, and if we're already
  9349. // reading, then it's unnecessary.
  9350. if (state.ended || state.reading) {
  9351. doRead = false;
  9352. debug('reading or ended', doRead);
  9353. } else if (doRead) {
  9354. debug('do read');
  9355. state.reading = true;
  9356. state.sync = true;
  9357. // if the length is currently zero, then we *need* a readable event.
  9358. if (state.length === 0) state.needReadable = true;
  9359. // call internal read method
  9360. this._read(state.highWaterMark);
  9361. state.sync = false;
  9362. // If _read pushed data synchronously, then `reading` will be false,
  9363. // and we need to re-evaluate how much data we can return to the user.
  9364. if (!state.reading) n = howMuchToRead(nOrig, state);
  9365. }
  9366. var ret;
  9367. if (n > 0) ret = fromList(n, state);else ret = null;
  9368. if (ret === null) {
  9369. state.needReadable = true;
  9370. n = 0;
  9371. } else {
  9372. state.length -= n;
  9373. }
  9374. if (state.length === 0) {
  9375. // If we have nothing in the buffer, then we want to know
  9376. // as soon as we *do* get something into the buffer.
  9377. if (!state.ended) state.needReadable = true;
  9378. // If we tried to read() past the EOF, then emit end on the next tick.
  9379. if (nOrig !== n && state.ended) endReadable(this);
  9380. }
  9381. if (ret !== null) this.emit('data', ret);
  9382. return ret;
  9383. };
  9384. function chunkInvalid(state, chunk) {
  9385. var er = null;
  9386. if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
  9387. er = new TypeError('Invalid non-string/buffer chunk');
  9388. }
  9389. return er;
  9390. }
  9391. function onEofChunk(stream, state) {
  9392. if (state.ended) return;
  9393. if (state.decoder) {
  9394. var chunk = state.decoder.end();
  9395. if (chunk && chunk.length) {
  9396. state.buffer.push(chunk);
  9397. state.length += state.objectMode ? 1 : chunk.length;
  9398. }
  9399. }
  9400. state.ended = true;
  9401. // emit 'readable' now to make sure it gets picked up.
  9402. emitReadable(stream);
  9403. }
  9404. // Don't emit readable right away in sync mode, because this can trigger
  9405. // another read() call => stack overflow. This way, it might trigger
  9406. // a nextTick recursion warning, but that's not so bad.
  9407. function emitReadable(stream) {
  9408. var state = stream._readableState;
  9409. state.needReadable = false;
  9410. if (!state.emittedReadable) {
  9411. debug('emitReadable', state.flowing);
  9412. state.emittedReadable = true;
  9413. if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream);
  9414. }
  9415. }
  9416. function emitReadable_(stream) {
  9417. debug('emit readable');
  9418. stream.emit('readable');
  9419. flow(stream);
  9420. }
  9421. // at this point, the user has presumably seen the 'readable' event,
  9422. // and called read() to consume some data. that may have triggered
  9423. // in turn another _read(n) call, in which case reading = true if
  9424. // it's in progress.
  9425. // However, if we're not ended, or reading, and the length < hwm,
  9426. // then go ahead and try to read some more preemptively.
  9427. function maybeReadMore(stream, state) {
  9428. if (!state.readingMore) {
  9429. state.readingMore = true;
  9430. processNextTick(maybeReadMore_, stream, state);
  9431. }
  9432. }
  9433. function maybeReadMore_(stream, state) {
  9434. var len = state.length;
  9435. while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
  9436. debug('maybeReadMore read 0');
  9437. stream.read(0);
  9438. if (len === state.length)
  9439. // didn't get any data, stop spinning.
  9440. break;else len = state.length;
  9441. }
  9442. state.readingMore = false;
  9443. }
  9444. // abstract method. to be overridden in specific implementation classes.
  9445. // call cb(er, data) where data is <= n in length.
  9446. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  9447. // arbitrary, and perhaps not very meaningful.
  9448. Readable.prototype._read = function (n) {
  9449. this.emit('error', new Error('not implemented'));
  9450. };
  9451. Readable.prototype.pipe = function (dest, pipeOpts) {
  9452. var src = this;
  9453. var state = this._readableState;
  9454. switch (state.pipesCount) {
  9455. case 0:
  9456. state.pipes = dest;
  9457. break;
  9458. case 1:
  9459. state.pipes = [state.pipes, dest];
  9460. break;
  9461. default:
  9462. state.pipes.push(dest);
  9463. break;
  9464. }
  9465. state.pipesCount += 1;
  9466. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  9467. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  9468. var endFn = doEnd ? onend : cleanup;
  9469. if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn);
  9470. dest.on('unpipe', onunpipe);
  9471. function onunpipe(readable) {
  9472. debug('onunpipe');
  9473. if (readable === src) {
  9474. cleanup();
  9475. }
  9476. }
  9477. function onend() {
  9478. debug('onend');
  9479. dest.end();
  9480. }
  9481. // when the dest drains, it reduces the awaitDrain counter
  9482. // on the source. This would be more elegant with a .once()
  9483. // handler in flow(), but adding and removing repeatedly is
  9484. // too slow.
  9485. var ondrain = pipeOnDrain(src);
  9486. dest.on('drain', ondrain);
  9487. var cleanedUp = false;
  9488. function cleanup() {
  9489. debug('cleanup');
  9490. // cleanup event handlers once the pipe is broken
  9491. dest.removeListener('close', onclose);
  9492. dest.removeListener('finish', onfinish);
  9493. dest.removeListener('drain', ondrain);
  9494. dest.removeListener('error', onerror);
  9495. dest.removeListener('unpipe', onunpipe);
  9496. src.removeListener('end', onend);
  9497. src.removeListener('end', cleanup);
  9498. src.removeListener('data', ondata);
  9499. cleanedUp = true;
  9500. // if the reader is waiting for a drain event from this
  9501. // specific writer, then it would cause it to never start
  9502. // flowing again.
  9503. // So, if this is awaiting a drain, then we just call it now.
  9504. // If we don't know, then assume that we are waiting for one.
  9505. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  9506. }
  9507. // If the user pushes more data while we're writing to dest then we'll end up
  9508. // in ondata again. However, we only want to increase awaitDrain once because
  9509. // dest will only emit one 'drain' event for the multiple writes.
  9510. // => Introduce a guard on increasing awaitDrain.
  9511. var increasedAwaitDrain = false;
  9512. src.on('data', ondata);
  9513. function ondata(chunk) {
  9514. debug('ondata');
  9515. increasedAwaitDrain = false;
  9516. var ret = dest.write(chunk);
  9517. if (false === ret && !increasedAwaitDrain) {
  9518. // If the user unpiped during `dest.write()`, it is possible
  9519. // to get stuck in a permanently paused state if that write
  9520. // also returned false.
  9521. // => Check whether `dest` is still a piping destination.
  9522. if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  9523. debug('false write response, pause', src._readableState.awaitDrain);
  9524. src._readableState.awaitDrain++;
  9525. increasedAwaitDrain = true;
  9526. }
  9527. src.pause();
  9528. }
  9529. }
  9530. // if the dest has an error, then stop piping into it.
  9531. // however, don't suppress the throwing behavior for this.
  9532. function onerror(er) {
  9533. debug('onerror', er);
  9534. unpipe();
  9535. dest.removeListener('error', onerror);
  9536. if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
  9537. }
  9538. // Make sure our error handler is attached before userland ones.
  9539. prependListener(dest, 'error', onerror);
  9540. // Both close and finish should trigger unpipe, but only once.
  9541. function onclose() {
  9542. dest.removeListener('finish', onfinish);
  9543. unpipe();
  9544. }
  9545. dest.once('close', onclose);
  9546. function onfinish() {
  9547. debug('onfinish');
  9548. dest.removeListener('close', onclose);
  9549. unpipe();
  9550. }
  9551. dest.once('finish', onfinish);
  9552. function unpipe() {
  9553. debug('unpipe');
  9554. src.unpipe(dest);
  9555. }
  9556. // tell the dest that it's being piped to
  9557. dest.emit('pipe', src);
  9558. // start the flow if it hasn't been started already.
  9559. if (!state.flowing) {
  9560. debug('pipe resume');
  9561. src.resume();
  9562. }
  9563. return dest;
  9564. };
  9565. function pipeOnDrain(src) {
  9566. return function () {
  9567. var state = src._readableState;
  9568. debug('pipeOnDrain', state.awaitDrain);
  9569. if (state.awaitDrain) state.awaitDrain--;
  9570. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  9571. state.flowing = true;
  9572. flow(src);
  9573. }
  9574. };
  9575. }
  9576. Readable.prototype.unpipe = function (dest) {
  9577. var state = this._readableState;
  9578. // if we're not piping anywhere, then do nothing.
  9579. if (state.pipesCount === 0) return this;
  9580. // just one destination. most common case.
  9581. if (state.pipesCount === 1) {
  9582. // passed in one, but it's not the right one.
  9583. if (dest && dest !== state.pipes) return this;
  9584. if (!dest) dest = state.pipes;
  9585. // got a match.
  9586. state.pipes = null;
  9587. state.pipesCount = 0;
  9588. state.flowing = false;
  9589. if (dest) dest.emit('unpipe', this);
  9590. return this;
  9591. }
  9592. // slow case. multiple pipe destinations.
  9593. if (!dest) {
  9594. // remove all.
  9595. var dests = state.pipes;
  9596. var len = state.pipesCount;
  9597. state.pipes = null;
  9598. state.pipesCount = 0;
  9599. state.flowing = false;
  9600. for (var _i = 0; _i < len; _i++) {
  9601. dests[_i].emit('unpipe', this);
  9602. }return this;
  9603. }
  9604. // try to find the right one.
  9605. var i = indexOf(state.pipes, dest);
  9606. if (i === -1) return this;
  9607. state.pipes.splice(i, 1);
  9608. state.pipesCount -= 1;
  9609. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  9610. dest.emit('unpipe', this);
  9611. return this;
  9612. };
  9613. // set up data events if they are asked for
  9614. // Ensure readable listeners eventually get something
  9615. Readable.prototype.on = function (ev, fn) {
  9616. var res = Stream.prototype.on.call(this, ev, fn);
  9617. if (ev === 'data') {
  9618. // Start flowing on next tick if stream isn't explicitly paused
  9619. if (this._readableState.flowing !== false) this.resume();
  9620. } else if (ev === 'readable') {
  9621. var state = this._readableState;
  9622. if (!state.endEmitted && !state.readableListening) {
  9623. state.readableListening = state.needReadable = true;
  9624. state.emittedReadable = false;
  9625. if (!state.reading) {
  9626. processNextTick(nReadingNextTick, this);
  9627. } else if (state.length) {
  9628. emitReadable(this, state);
  9629. }
  9630. }
  9631. }
  9632. return res;
  9633. };
  9634. Readable.prototype.addListener = Readable.prototype.on;
  9635. function nReadingNextTick(self) {
  9636. debug('readable nexttick read 0');
  9637. self.read(0);
  9638. }
  9639. // pause() and resume() are remnants of the legacy readable stream API
  9640. // If the user uses them, then switch into old mode.
  9641. Readable.prototype.resume = function () {
  9642. var state = this._readableState;
  9643. if (!state.flowing) {
  9644. debug('resume');
  9645. state.flowing = true;
  9646. resume(this, state);
  9647. }
  9648. return this;
  9649. };
  9650. function resume(stream, state) {
  9651. if (!state.resumeScheduled) {
  9652. state.resumeScheduled = true;
  9653. processNextTick(resume_, stream, state);
  9654. }
  9655. }
  9656. function resume_(stream, state) {
  9657. if (!state.reading) {
  9658. debug('resume read 0');
  9659. stream.read(0);
  9660. }
  9661. state.resumeScheduled = false;
  9662. state.awaitDrain = 0;
  9663. stream.emit('resume');
  9664. flow(stream);
  9665. if (state.flowing && !state.reading) stream.read(0);
  9666. }
  9667. Readable.prototype.pause = function () {
  9668. debug('call pause flowing=%j', this._readableState.flowing);
  9669. if (false !== this._readableState.flowing) {
  9670. debug('pause');
  9671. this._readableState.flowing = false;
  9672. this.emit('pause');
  9673. }
  9674. return this;
  9675. };
  9676. function flow(stream) {
  9677. var state = stream._readableState;
  9678. debug('flow', state.flowing);
  9679. while (state.flowing && stream.read() !== null) {}
  9680. }
  9681. // wrap an old-style stream as the async data source.
  9682. // This is *not* part of the readable stream interface.
  9683. // It is an ugly unfortunate mess of history.
  9684. Readable.prototype.wrap = function (stream) {
  9685. var state = this._readableState;
  9686. var paused = false;
  9687. var self = this;
  9688. stream.on('end', function () {
  9689. debug('wrapped end');
  9690. if (state.decoder && !state.ended) {
  9691. var chunk = state.decoder.end();
  9692. if (chunk && chunk.length) self.push(chunk);
  9693. }
  9694. self.push(null);
  9695. });
  9696. stream.on('data', function (chunk) {
  9697. debug('wrapped data');
  9698. if (state.decoder) chunk = state.decoder.write(chunk);
  9699. // don't skip over falsy values in objectMode
  9700. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  9701. var ret = self.push(chunk);
  9702. if (!ret) {
  9703. paused = true;
  9704. stream.pause();
  9705. }
  9706. });
  9707. // proxy all the other methods.
  9708. // important when wrapping filters and duplexes.
  9709. for (var i in stream) {
  9710. if (this[i] === undefined && typeof stream[i] === 'function') {
  9711. this[i] = function (method) {
  9712. return function () {
  9713. return stream[method].apply(stream, arguments);
  9714. };
  9715. }(i);
  9716. }
  9717. }
  9718. // proxy certain important events.
  9719. var events = ['error', 'close', 'destroy', 'pause', 'resume'];
  9720. forEach(events, function (ev) {
  9721. stream.on(ev, self.emit.bind(self, ev));
  9722. });
  9723. // when we try to consume some more bytes, simply unpause the
  9724. // underlying stream.
  9725. self._read = function (n) {
  9726. debug('wrapped _read', n);
  9727. if (paused) {
  9728. paused = false;
  9729. stream.resume();
  9730. }
  9731. };
  9732. return self;
  9733. };
  9734. // exposed for testing purposes only.
  9735. Readable._fromList = fromList;
  9736. // Pluck off n bytes from an array of buffers.
  9737. // Length is the combined lengths of all the buffers in the list.
  9738. // This function is designed to be inlinable, so please take care when making
  9739. // changes to the function body.
  9740. function fromList(n, state) {
  9741. // nothing buffered
  9742. if (state.length === 0) return null;
  9743. var ret;
  9744. if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
  9745. // read it all, truncate the list
  9746. 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);
  9747. state.buffer.clear();
  9748. } else {
  9749. // read part of list
  9750. ret = fromListPartial(n, state.buffer, state.decoder);
  9751. }
  9752. return ret;
  9753. }
  9754. // Extracts only enough buffered data to satisfy the amount requested.
  9755. // This function is designed to be inlinable, so please take care when making
  9756. // changes to the function body.
  9757. function fromListPartial(n, list, hasStrings) {
  9758. var ret;
  9759. if (n < list.head.data.length) {
  9760. // slice is the same for buffers and strings
  9761. ret = list.head.data.slice(0, n);
  9762. list.head.data = list.head.data.slice(n);
  9763. } else if (n === list.head.data.length) {
  9764. // first chunk is a perfect match
  9765. ret = list.shift();
  9766. } else {
  9767. // result spans more than one buffer
  9768. ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
  9769. }
  9770. return ret;
  9771. }
  9772. // Copies a specified amount of characters from the list of buffered data
  9773. // chunks.
  9774. // This function is designed to be inlinable, so please take care when making
  9775. // changes to the function body.
  9776. function copyFromBufferString(n, list) {
  9777. var p = list.head;
  9778. var c = 1;
  9779. var ret = p.data;
  9780. n -= ret.length;
  9781. while (p = p.next) {
  9782. var str = p.data;
  9783. var nb = n > str.length ? str.length : n;
  9784. if (nb === str.length) ret += str;else ret += str.slice(0, n);
  9785. n -= nb;
  9786. if (n === 0) {
  9787. if (nb === str.length) {
  9788. ++c;
  9789. if (p.next) list.head = p.next;else list.head = list.tail = null;
  9790. } else {
  9791. list.head = p;
  9792. p.data = str.slice(nb);
  9793. }
  9794. break;
  9795. }
  9796. ++c;
  9797. }
  9798. list.length -= c;
  9799. return ret;
  9800. }
  9801. // Copies a specified amount of bytes from the list of buffered data chunks.
  9802. // This function is designed to be inlinable, so please take care when making
  9803. // changes to the function body.
  9804. function copyFromBuffer(n, list) {
  9805. var ret = bufferShim.allocUnsafe(n);
  9806. var p = list.head;
  9807. var c = 1;
  9808. p.data.copy(ret);
  9809. n -= p.data.length;
  9810. while (p = p.next) {
  9811. var buf = p.data;
  9812. var nb = n > buf.length ? buf.length : n;
  9813. buf.copy(ret, ret.length - n, 0, nb);
  9814. n -= nb;
  9815. if (n === 0) {
  9816. if (nb === buf.length) {
  9817. ++c;
  9818. if (p.next) list.head = p.next;else list.head = list.tail = null;
  9819. } else {
  9820. list.head = p;
  9821. p.data = buf.slice(nb);
  9822. }
  9823. break;
  9824. }
  9825. ++c;
  9826. }
  9827. list.length -= c;
  9828. return ret;
  9829. }
  9830. function endReadable(stream) {
  9831. var state = stream._readableState;
  9832. // If we get here before consuming all the bytes, then that is a
  9833. // bug in node. Should never happen.
  9834. if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
  9835. if (!state.endEmitted) {
  9836. state.ended = true;
  9837. processNextTick(endReadableNT, state, stream);
  9838. }
  9839. }
  9840. function endReadableNT(state, stream) {
  9841. // Check that we didn't get one last unshift.
  9842. if (!state.endEmitted && state.length === 0) {
  9843. state.endEmitted = true;
  9844. stream.readable = false;
  9845. stream.emit('end');
  9846. }
  9847. }
  9848. function forEach(xs, f) {
  9849. for (var i = 0, l = xs.length; i < l; i++) {
  9850. f(xs[i], i);
  9851. }
  9852. }
  9853. function indexOf(xs, x) {
  9854. for (var i = 0, l = xs.length; i < l; i++) {
  9855. if (xs[i] === x) return i;
  9856. }
  9857. return -1;
  9858. }
  9859. }).call(this,require('_process'))
  9860. },{"./_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){
  9861. // a transform stream is a readable/writable stream where you do
  9862. // something with the data. Sometimes it's called a "filter",
  9863. // but that's not a great name for it, since that implies a thing where
  9864. // some bits pass through, and others are simply ignored. (That would
  9865. // be a valid example of a transform, of course.)
  9866. //
  9867. // While the output is causally related to the input, it's not a
  9868. // necessarily symmetric or synchronous transformation. For example,
  9869. // a zlib stream might take multiple plain-text writes(), and then
  9870. // emit a single compressed chunk some time in the future.
  9871. //
  9872. // Here's how this works:
  9873. //
  9874. // The Transform stream has all the aspects of the readable and writable
  9875. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  9876. // internally, and returns false if there's a lot of pending writes
  9877. // buffered up. When you call read(), that calls _read(n) until
  9878. // there's enough pending readable data buffered up.
  9879. //
  9880. // In a transform stream, the written data is placed in a buffer. When
  9881. // _read(n) is called, it transforms the queued up data, calling the
  9882. // buffered _write cb's as it consumes chunks. If consuming a single
  9883. // written chunk would result in multiple output chunks, then the first
  9884. // outputted bit calls the readcb, and subsequent chunks just go into
  9885. // the read buffer, and will cause it to emit 'readable' if necessary.
  9886. //
  9887. // This way, back-pressure is actually determined by the reading side,
  9888. // since _read has to be called to start processing a new chunk. However,
  9889. // a pathological inflate type of transform can cause excessive buffering
  9890. // here. For example, imagine a stream where every byte of input is
  9891. // interpreted as an integer from 0-255, and then results in that many
  9892. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  9893. // 1kb of data being output. In this case, you could write a very small
  9894. // amount of input, and end up with a very large amount of output. In
  9895. // such a pathological inflating mechanism, there'd be no way to tell
  9896. // the system to stop doing the transform. A single 4MB write could
  9897. // cause the system to run out of memory.
  9898. //
  9899. // However, even in such a pathological case, only a single written chunk
  9900. // would be consumed, and then the rest would wait (un-transformed) until
  9901. // the results of the previous transformed chunk were consumed.
  9902. 'use strict';
  9903. module.exports = Transform;
  9904. var Duplex = require('./_stream_duplex');
  9905. /*<replacement>*/
  9906. var util = require('core-util-is');
  9907. util.inherits = require('inherits');
  9908. /*</replacement>*/
  9909. util.inherits(Transform, Duplex);
  9910. function TransformState(stream) {
  9911. this.afterTransform = function (er, data) {
  9912. return afterTransform(stream, er, data);
  9913. };
  9914. this.needTransform = false;
  9915. this.transforming = false;
  9916. this.writecb = null;
  9917. this.writechunk = null;
  9918. this.writeencoding = null;
  9919. }
  9920. function afterTransform(stream, er, data) {
  9921. var ts = stream._transformState;
  9922. ts.transforming = false;
  9923. var cb = ts.writecb;
  9924. if (!cb) return stream.emit('error', new Error('no writecb in Transform class'));
  9925. ts.writechunk = null;
  9926. ts.writecb = null;
  9927. if (data !== null && data !== undefined) stream.push(data);
  9928. cb(er);
  9929. var rs = stream._readableState;
  9930. rs.reading = false;
  9931. if (rs.needReadable || rs.length < rs.highWaterMark) {
  9932. stream._read(rs.highWaterMark);
  9933. }
  9934. }
  9935. function Transform(options) {
  9936. if (!(this instanceof Transform)) return new Transform(options);
  9937. Duplex.call(this, options);
  9938. this._transformState = new TransformState(this);
  9939. // when the writable side finishes, then flush out anything remaining.
  9940. var stream = this;
  9941. // start out asking for a readable event once data is transformed.
  9942. this._readableState.needReadable = true;
  9943. // we have implemented the _read method, and done the other things
  9944. // that Readable wants before the first _read call, so unset the
  9945. // sync guard flag.
  9946. this._readableState.sync = false;
  9947. if (options) {
  9948. if (typeof options.transform === 'function') this._transform = options.transform;
  9949. if (typeof options.flush === 'function') this._flush = options.flush;
  9950. }
  9951. this.once('prefinish', function () {
  9952. if (typeof this._flush === 'function') this._flush(function (er) {
  9953. done(stream, er);
  9954. });else done(stream);
  9955. });
  9956. }
  9957. Transform.prototype.push = function (chunk, encoding) {
  9958. this._transformState.needTransform = false;
  9959. return Duplex.prototype.push.call(this, chunk, encoding);
  9960. };
  9961. // This is the part where you do stuff!
  9962. // override this function in implementation classes.
  9963. // 'chunk' is an input chunk.
  9964. //
  9965. // Call `push(newChunk)` to pass along transformed output
  9966. // to the readable side. You may call 'push' zero or more times.
  9967. //
  9968. // Call `cb(err)` when you are done with this chunk. If you pass
  9969. // an error, then that'll put the hurt on the whole operation. If you
  9970. // never call cb(), then you'll never get another chunk.
  9971. Transform.prototype._transform = function (chunk, encoding, cb) {
  9972. throw new Error('Not implemented');
  9973. };
  9974. Transform.prototype._write = function (chunk, encoding, cb) {
  9975. var ts = this._transformState;
  9976. ts.writecb = cb;
  9977. ts.writechunk = chunk;
  9978. ts.writeencoding = encoding;
  9979. if (!ts.transforming) {
  9980. var rs = this._readableState;
  9981. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  9982. }
  9983. };
  9984. // Doesn't matter what the args are here.
  9985. // _transform does all the work.
  9986. // That we got here means that the readable side wants more data.
  9987. Transform.prototype._read = function (n) {
  9988. var ts = this._transformState;
  9989. if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
  9990. ts.transforming = true;
  9991. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  9992. } else {
  9993. // mark that we need a transform, so that any data that comes in
  9994. // will get processed, now that we've asked for it.
  9995. ts.needTransform = true;
  9996. }
  9997. };
  9998. function done(stream, er) {
  9999. if (er) return stream.emit('error', er);
  10000. // if there's nothing in the write buffer, then that means
  10001. // that nothing more will ever be provided
  10002. var ws = stream._writableState;
  10003. var ts = stream._transformState;
  10004. if (ws.length) throw new Error('Calling transform done when ws.length != 0');
  10005. if (ts.transforming) throw new Error('Calling transform done when still transforming');
  10006. return stream.push(null);
  10007. }
  10008. },{"./_stream_duplex":24,"core-util-is":9,"inherits":16}],28:[function(require,module,exports){
  10009. (function (process){
  10010. // A bit simpler than readable streams.
  10011. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  10012. // the drain event emission and buffering.
  10013. 'use strict';
  10014. module.exports = Writable;
  10015. /*<replacement>*/
  10016. var processNextTick = require('process-nextick-args');
  10017. /*</replacement>*/
  10018. /*<replacement>*/
  10019. var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick;
  10020. /*</replacement>*/
  10021. Writable.WritableState = WritableState;
  10022. /*<replacement>*/
  10023. var util = require('core-util-is');
  10024. util.inherits = require('inherits');
  10025. /*</replacement>*/
  10026. /*<replacement>*/
  10027. var internalUtil = {
  10028. deprecate: require('util-deprecate')
  10029. };
  10030. /*</replacement>*/
  10031. /*<replacement>*/
  10032. var Stream;
  10033. (function () {
  10034. try {
  10035. Stream = require('st' + 'ream');
  10036. } catch (_) {} finally {
  10037. if (!Stream) Stream = require('events').EventEmitter;
  10038. }
  10039. })();
  10040. /*</replacement>*/
  10041. var Buffer = require('buffer').Buffer;
  10042. /*<replacement>*/
  10043. var bufferShim = require('buffer-shims');
  10044. /*</replacement>*/
  10045. util.inherits(Writable, Stream);
  10046. function nop() {}
  10047. function WriteReq(chunk, encoding, cb) {
  10048. this.chunk = chunk;
  10049. this.encoding = encoding;
  10050. this.callback = cb;
  10051. this.next = null;
  10052. }
  10053. var Duplex;
  10054. function WritableState(options, stream) {
  10055. Duplex = Duplex || require('./_stream_duplex');
  10056. options = options || {};
  10057. // object stream flag to indicate whether or not this stream
  10058. // contains buffers or objects.
  10059. this.objectMode = !!options.objectMode;
  10060. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
  10061. // the point at which write() starts returning false
  10062. // Note: 0 is a valid value, means that we always return false if
  10063. // the entire buffer is not flushed immediately on write()
  10064. var hwm = options.highWaterMark;
  10065. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  10066. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  10067. // cast to ints.
  10068. this.highWaterMark = ~ ~this.highWaterMark;
  10069. this.needDrain = false;
  10070. // at the start of calling end()
  10071. this.ending = false;
  10072. // when end() has been called, and returned
  10073. this.ended = false;
  10074. // when 'finish' is emitted
  10075. this.finished = false;
  10076. // should we decode strings into buffers before passing to _write?
  10077. // this is here so that some node-core streams can optimize string
  10078. // handling at a lower level.
  10079. var noDecode = options.decodeStrings === false;
  10080. this.decodeStrings = !noDecode;
  10081. // Crypto is kind of old and crusty. Historically, its default string
  10082. // encoding is 'binary' so we have to make this configurable.
  10083. // Everything else in the universe uses 'utf8', though.
  10084. this.defaultEncoding = options.defaultEncoding || 'utf8';
  10085. // not an actual buffer we keep track of, but a measurement
  10086. // of how much we're waiting to get pushed to some underlying
  10087. // socket or file.
  10088. this.length = 0;
  10089. // a flag to see when we're in the middle of a write.
  10090. this.writing = false;
  10091. // when true all writes will be buffered until .uncork() call
  10092. this.corked = 0;
  10093. // a flag to be able to tell if the onwrite cb is called immediately,
  10094. // or on a later tick. We set this to true at first, because any
  10095. // actions that shouldn't happen until "later" should generally also
  10096. // not happen before the first write call.
  10097. this.sync = true;
  10098. // a flag to know if we're processing previously buffered items, which
  10099. // may call the _write() callback in the same tick, so that we don't
  10100. // end up in an overlapped onwrite situation.
  10101. this.bufferProcessing = false;
  10102. // the callback that's passed to _write(chunk,cb)
  10103. this.onwrite = function (er) {
  10104. onwrite(stream, er);
  10105. };
  10106. // the callback that the user supplies to write(chunk,encoding,cb)
  10107. this.writecb = null;
  10108. // the amount that is being written when _write is called.
  10109. this.writelen = 0;
  10110. this.bufferedRequest = null;
  10111. this.lastBufferedRequest = null;
  10112. // number of pending user-supplied write callbacks
  10113. // this must be 0 before 'finish' can be emitted
  10114. this.pendingcb = 0;
  10115. // emit prefinish if the only thing we're waiting for is _write cbs
  10116. // This is relevant for synchronous Transform streams
  10117. this.prefinished = false;
  10118. // True if the error was already emitted and should not be thrown again
  10119. this.errorEmitted = false;
  10120. // count buffered requests
  10121. this.bufferedRequestCount = 0;
  10122. // allocate the first CorkedRequest, there is always
  10123. // one allocated and free to use, and we maintain at most two
  10124. this.corkedRequestsFree = new CorkedRequest(this);
  10125. }
  10126. WritableState.prototype.getBuffer = function writableStateGetBuffer() {
  10127. var current = this.bufferedRequest;
  10128. var out = [];
  10129. while (current) {
  10130. out.push(current);
  10131. current = current.next;
  10132. }
  10133. return out;
  10134. };
  10135. (function () {
  10136. try {
  10137. Object.defineProperty(WritableState.prototype, 'buffer', {
  10138. get: internalUtil.deprecate(function () {
  10139. return this.getBuffer();
  10140. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
  10141. });
  10142. } catch (_) {}
  10143. })();
  10144. var Duplex;
  10145. function Writable(options) {
  10146. Duplex = Duplex || require('./_stream_duplex');
  10147. // Writable ctor is applied to Duplexes, though they're not
  10148. // instanceof Writable, they're instanceof Readable.
  10149. if (!(this instanceof Writable) && !(this instanceof Duplex)) return new Writable(options);
  10150. this._writableState = new WritableState(options, this);
  10151. // legacy.
  10152. this.writable = true;
  10153. if (options) {
  10154. if (typeof options.write === 'function') this._write = options.write;
  10155. if (typeof options.writev === 'function') this._writev = options.writev;
  10156. }
  10157. Stream.call(this);
  10158. }
  10159. // Otherwise people can pipe Writable streams, which is just wrong.
  10160. Writable.prototype.pipe = function () {
  10161. this.emit('error', new Error('Cannot pipe, not readable'));
  10162. };
  10163. function writeAfterEnd(stream, cb) {
  10164. var er = new Error('write after end');
  10165. // TODO: defer error events consistently everywhere, not just the cb
  10166. stream.emit('error', er);
  10167. processNextTick(cb, er);
  10168. }
  10169. // If we get something that is not a buffer, string, null, or undefined,
  10170. // and we're not in objectMode, then that's an error.
  10171. // Otherwise stream chunks are all considered to be of length=1, and the
  10172. // watermarks determine how many objects to keep in the buffer, rather than
  10173. // how many bytes or characters.
  10174. function validChunk(stream, state, chunk, cb) {
  10175. var valid = true;
  10176. var er = false;
  10177. // Always throw error if a null is written
  10178. // if we are not in object mode then throw
  10179. // if it is not a buffer, string, or undefined.
  10180. if (chunk === null) {
  10181. er = new TypeError('May not write null values to stream');
  10182. } else if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  10183. er = new TypeError('Invalid non-string/buffer chunk');
  10184. }
  10185. if (er) {
  10186. stream.emit('error', er);
  10187. processNextTick(cb, er);
  10188. valid = false;
  10189. }
  10190. return valid;
  10191. }
  10192. Writable.prototype.write = function (chunk, encoding, cb) {
  10193. var state = this._writableState;
  10194. var ret = false;
  10195. if (typeof encoding === 'function') {
  10196. cb = encoding;
  10197. encoding = null;
  10198. }
  10199. if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  10200. if (typeof cb !== 'function') cb = nop;
  10201. if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) {
  10202. state.pendingcb++;
  10203. ret = writeOrBuffer(this, state, chunk, encoding, cb);
  10204. }
  10205. return ret;
  10206. };
  10207. Writable.prototype.cork = function () {
  10208. var state = this._writableState;
  10209. state.corked++;
  10210. };
  10211. Writable.prototype.uncork = function () {
  10212. var state = this._writableState;
  10213. if (state.corked) {
  10214. state.corked--;
  10215. if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  10216. }
  10217. };
  10218. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  10219. // node::ParseEncoding() requires lower case.
  10220. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  10221. 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);
  10222. this._writableState.defaultEncoding = encoding;
  10223. return this;
  10224. };
  10225. function decodeChunk(state, chunk, encoding) {
  10226. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  10227. chunk = bufferShim.from(chunk, encoding);
  10228. }
  10229. return chunk;
  10230. }
  10231. // if we're already writing something, then just put this
  10232. // in the queue, and wait our turn. Otherwise, call _write
  10233. // If we return false, then we need a drain event, so set that flag.
  10234. function writeOrBuffer(stream, state, chunk, encoding, cb) {
  10235. chunk = decodeChunk(state, chunk, encoding);
  10236. if (Buffer.isBuffer(chunk)) encoding = 'buffer';
  10237. var len = state.objectMode ? 1 : chunk.length;
  10238. state.length += len;
  10239. var ret = state.length < state.highWaterMark;
  10240. // we must ensure that previous needDrain will not be reset to false.
  10241. if (!ret) state.needDrain = true;
  10242. if (state.writing || state.corked) {
  10243. var last = state.lastBufferedRequest;
  10244. state.lastBufferedRequest = new WriteReq(chunk, encoding, cb);
  10245. if (last) {
  10246. last.next = state.lastBufferedRequest;
  10247. } else {
  10248. state.bufferedRequest = state.lastBufferedRequest;
  10249. }
  10250. state.bufferedRequestCount += 1;
  10251. } else {
  10252. doWrite(stream, state, false, len, chunk, encoding, cb);
  10253. }
  10254. return ret;
  10255. }
  10256. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  10257. state.writelen = len;
  10258. state.writecb = cb;
  10259. state.writing = true;
  10260. state.sync = true;
  10261. if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  10262. state.sync = false;
  10263. }
  10264. function onwriteError(stream, state, sync, er, cb) {
  10265. --state.pendingcb;
  10266. if (sync) processNextTick(cb, er);else cb(er);
  10267. stream._writableState.errorEmitted = true;
  10268. stream.emit('error', er);
  10269. }
  10270. function onwriteStateUpdate(state) {
  10271. state.writing = false;
  10272. state.writecb = null;
  10273. state.length -= state.writelen;
  10274. state.writelen = 0;
  10275. }
  10276. function onwrite(stream, er) {
  10277. var state = stream._writableState;
  10278. var sync = state.sync;
  10279. var cb = state.writecb;
  10280. onwriteStateUpdate(state);
  10281. if (er) onwriteError(stream, state, sync, er, cb);else {
  10282. // Check if we're actually ready to finish, but don't emit yet
  10283. var finished = needFinish(state);
  10284. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  10285. clearBuffer(stream, state);
  10286. }
  10287. if (sync) {
  10288. /*<replacement>*/
  10289. asyncWrite(afterWrite, stream, state, finished, cb);
  10290. /*</replacement>*/
  10291. } else {
  10292. afterWrite(stream, state, finished, cb);
  10293. }
  10294. }
  10295. }
  10296. function afterWrite(stream, state, finished, cb) {
  10297. if (!finished) onwriteDrain(stream, state);
  10298. state.pendingcb--;
  10299. cb();
  10300. finishMaybe(stream, state);
  10301. }
  10302. // Must force callback to be called on nextTick, so that we don't
  10303. // emit 'drain' before the write() consumer gets the 'false' return
  10304. // value, and has a chance to attach a 'drain' listener.
  10305. function onwriteDrain(stream, state) {
  10306. if (state.length === 0 && state.needDrain) {
  10307. state.needDrain = false;
  10308. stream.emit('drain');
  10309. }
  10310. }
  10311. // if there's something in the buffer waiting, then process it
  10312. function clearBuffer(stream, state) {
  10313. state.bufferProcessing = true;
  10314. var entry = state.bufferedRequest;
  10315. if (stream._writev && entry && entry.next) {
  10316. // Fast case, write everything using _writev()
  10317. var l = state.bufferedRequestCount;
  10318. var buffer = new Array(l);
  10319. var holder = state.corkedRequestsFree;
  10320. holder.entry = entry;
  10321. var count = 0;
  10322. while (entry) {
  10323. buffer[count] = entry;
  10324. entry = entry.next;
  10325. count += 1;
  10326. }
  10327. doWrite(stream, state, true, state.length, buffer, '', holder.finish);
  10328. // doWrite is almost always async, defer these to save a bit of time
  10329. // as the hot path ends with doWrite
  10330. state.pendingcb++;
  10331. state.lastBufferedRequest = null;
  10332. if (holder.next) {
  10333. state.corkedRequestsFree = holder.next;
  10334. holder.next = null;
  10335. } else {
  10336. state.corkedRequestsFree = new CorkedRequest(state);
  10337. }
  10338. } else {
  10339. // Slow case, write chunks one-by-one
  10340. while (entry) {
  10341. var chunk = entry.chunk;
  10342. var encoding = entry.encoding;
  10343. var cb = entry.callback;
  10344. var len = state.objectMode ? 1 : chunk.length;
  10345. doWrite(stream, state, false, len, chunk, encoding, cb);
  10346. entry = entry.next;
  10347. // if we didn't call the onwrite immediately, then
  10348. // it means that we need to wait until it does.
  10349. // also, that means that the chunk and cb are currently
  10350. // being processed, so move the buffer counter past them.
  10351. if (state.writing) {
  10352. break;
  10353. }
  10354. }
  10355. if (entry === null) state.lastBufferedRequest = null;
  10356. }
  10357. state.bufferedRequestCount = 0;
  10358. state.bufferedRequest = entry;
  10359. state.bufferProcessing = false;
  10360. }
  10361. Writable.prototype._write = function (chunk, encoding, cb) {
  10362. cb(new Error('not implemented'));
  10363. };
  10364. Writable.prototype._writev = null;
  10365. Writable.prototype.end = function (chunk, encoding, cb) {
  10366. var state = this._writableState;
  10367. if (typeof chunk === 'function') {
  10368. cb = chunk;
  10369. chunk = null;
  10370. encoding = null;
  10371. } else if (typeof encoding === 'function') {
  10372. cb = encoding;
  10373. encoding = null;
  10374. }
  10375. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
  10376. // .end() fully uncorks
  10377. if (state.corked) {
  10378. state.corked = 1;
  10379. this.uncork();
  10380. }
  10381. // ignore unnecessary end() calls.
  10382. if (!state.ending && !state.finished) endWritable(this, state, cb);
  10383. };
  10384. function needFinish(state) {
  10385. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  10386. }
  10387. function prefinish(stream, state) {
  10388. if (!state.prefinished) {
  10389. state.prefinished = true;
  10390. stream.emit('prefinish');
  10391. }
  10392. }
  10393. function finishMaybe(stream, state) {
  10394. var need = needFinish(state);
  10395. if (need) {
  10396. if (state.pendingcb === 0) {
  10397. prefinish(stream, state);
  10398. state.finished = true;
  10399. stream.emit('finish');
  10400. } else {
  10401. prefinish(stream, state);
  10402. }
  10403. }
  10404. return need;
  10405. }
  10406. function endWritable(stream, state, cb) {
  10407. state.ending = true;
  10408. finishMaybe(stream, state);
  10409. if (cb) {
  10410. if (state.finished) processNextTick(cb);else stream.once('finish', cb);
  10411. }
  10412. state.ended = true;
  10413. stream.writable = false;
  10414. }
  10415. // It seems a linked list but it is not
  10416. // there will be only 2 of these for each stream
  10417. function CorkedRequest(state) {
  10418. var _this = this;
  10419. this.next = null;
  10420. this.entry = null;
  10421. this.finish = function (err) {
  10422. var entry = _this.entry;
  10423. _this.entry = null;
  10424. while (entry) {
  10425. var cb = entry.callback;
  10426. state.pendingcb--;
  10427. cb(err);
  10428. entry = entry.next;
  10429. }
  10430. if (state.corkedRequestsFree) {
  10431. state.corkedRequestsFree.next = _this;
  10432. } else {
  10433. state.corkedRequestsFree = _this;
  10434. }
  10435. };
  10436. }
  10437. }).call(this,require('_process'))
  10438. },{"./_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){
  10439. 'use strict';
  10440. var Buffer = require('buffer').Buffer;
  10441. /*<replacement>*/
  10442. var bufferShim = require('buffer-shims');
  10443. /*</replacement>*/
  10444. module.exports = BufferList;
  10445. function BufferList() {
  10446. this.head = null;
  10447. this.tail = null;
  10448. this.length = 0;
  10449. }
  10450. BufferList.prototype.push = function (v) {
  10451. var entry = { data: v, next: null };
  10452. if (this.length > 0) this.tail.next = entry;else this.head = entry;
  10453. this.tail = entry;
  10454. ++this.length;
  10455. };
  10456. BufferList.prototype.unshift = function (v) {
  10457. var entry = { data: v, next: this.head };
  10458. if (this.length === 0) this.tail = entry;
  10459. this.head = entry;
  10460. ++this.length;
  10461. };
  10462. BufferList.prototype.shift = function () {
  10463. if (this.length === 0) return;
  10464. var ret = this.head.data;
  10465. if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
  10466. --this.length;
  10467. return ret;
  10468. };
  10469. BufferList.prototype.clear = function () {
  10470. this.head = this.tail = null;
  10471. this.length = 0;
  10472. };
  10473. BufferList.prototype.join = function (s) {
  10474. if (this.length === 0) return '';
  10475. var p = this.head;
  10476. var ret = '' + p.data;
  10477. while (p = p.next) {
  10478. ret += s + p.data;
  10479. }return ret;
  10480. };
  10481. BufferList.prototype.concat = function (n) {
  10482. if (this.length === 0) return bufferShim.alloc(0);
  10483. if (this.length === 1) return this.head.data;
  10484. var ret = bufferShim.allocUnsafe(n >>> 0);
  10485. var p = this.head;
  10486. var i = 0;
  10487. while (p) {
  10488. p.data.copy(ret, i);
  10489. i += p.data.length;
  10490. p = p.next;
  10491. }
  10492. return ret;
  10493. };
  10494. },{"buffer":7,"buffer-shims":6}],30:[function(require,module,exports){
  10495. module.exports = require("./lib/_stream_passthrough.js")
  10496. },{"./lib/_stream_passthrough.js":25}],31:[function(require,module,exports){
  10497. (function (process){
  10498. var Stream = (function (){
  10499. try {
  10500. return require('st' + 'ream'); // hack to fix a circular dependency issue when used with browserify
  10501. } catch(_){}
  10502. }());
  10503. exports = module.exports = require('./lib/_stream_readable.js');
  10504. exports.Stream = Stream || exports;
  10505. exports.Readable = exports;
  10506. exports.Writable = require('./lib/_stream_writable.js');
  10507. exports.Duplex = require('./lib/_stream_duplex.js');
  10508. exports.Transform = require('./lib/_stream_transform.js');
  10509. exports.PassThrough = require('./lib/_stream_passthrough.js');
  10510. if (!process.browser && process.env.READABLE_STREAM === 'disable' && Stream) {
  10511. module.exports = Stream;
  10512. }
  10513. }).call(this,require('_process'))
  10514. },{"./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){
  10515. module.exports = require("./lib/_stream_transform.js")
  10516. },{"./lib/_stream_transform.js":27}],33:[function(require,module,exports){
  10517. module.exports = require("./lib/_stream_writable.js")
  10518. },{"./lib/_stream_writable.js":28}],34:[function(require,module,exports){
  10519. (function (Buffer){
  10520. /*
  10521. CryptoJS v3.1.2
  10522. code.google.com/p/crypto-js
  10523. (c) 2009-2013 by Jeff Mott. All rights reserved.
  10524. code.google.com/p/crypto-js/wiki/License
  10525. */
  10526. /** @preserve
  10527. (c) 2012 by Cédric Mesnil. All rights reserved.
  10528. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  10529. - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  10530. - 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.
  10531. 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.
  10532. */
  10533. // constants table
  10534. var zl = [
  10535. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  10536. 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
  10537. 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
  10538. 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
  10539. 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
  10540. ]
  10541. var zr = [
  10542. 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
  10543. 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
  10544. 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
  10545. 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
  10546. 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
  10547. ]
  10548. var sl = [
  10549. 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
  10550. 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
  10551. 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
  10552. 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
  10553. 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
  10554. ]
  10555. var sr = [
  10556. 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
  10557. 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
  10558. 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
  10559. 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
  10560. 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
  10561. ]
  10562. var hl = [0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]
  10563. var hr = [0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]
  10564. function bytesToWords (bytes) {
  10565. var words = []
  10566. for (var i = 0, b = 0; i < bytes.length; i++, b += 8) {
  10567. words[b >>> 5] |= bytes[i] << (24 - b % 32)
  10568. }
  10569. return words
  10570. }
  10571. function wordsToBytes (words) {
  10572. var bytes = []
  10573. for (var b = 0; b < words.length * 32; b += 8) {
  10574. bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF)
  10575. }
  10576. return bytes
  10577. }
  10578. function processBlock (H, M, offset) {
  10579. // swap endian
  10580. for (var i = 0; i < 16; i++) {
  10581. var offset_i = offset + i
  10582. var M_offset_i = M[offset_i]
  10583. // Swap
  10584. M[offset_i] = (
  10585. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  10586. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  10587. )
  10588. }
  10589. // Working variables
  10590. var al, bl, cl, dl, el
  10591. var ar, br, cr, dr, er
  10592. ar = al = H[0]
  10593. br = bl = H[1]
  10594. cr = cl = H[2]
  10595. dr = dl = H[3]
  10596. er = el = H[4]
  10597. // computation
  10598. var t
  10599. for (i = 0; i < 80; i += 1) {
  10600. t = (al + M[offset + zl[i]]) | 0
  10601. if (i < 16) {
  10602. t += f1(bl, cl, dl) + hl[0]
  10603. } else if (i < 32) {
  10604. t += f2(bl, cl, dl) + hl[1]
  10605. } else if (i < 48) {
  10606. t += f3(bl, cl, dl) + hl[2]
  10607. } else if (i < 64) {
  10608. t += f4(bl, cl, dl) + hl[3]
  10609. } else {// if (i<80) {
  10610. t += f5(bl, cl, dl) + hl[4]
  10611. }
  10612. t = t | 0
  10613. t = rotl(t, sl[i])
  10614. t = (t + el) | 0
  10615. al = el
  10616. el = dl
  10617. dl = rotl(cl, 10)
  10618. cl = bl
  10619. bl = t
  10620. t = (ar + M[offset + zr[i]]) | 0
  10621. if (i < 16) {
  10622. t += f5(br, cr, dr) + hr[0]
  10623. } else if (i < 32) {
  10624. t += f4(br, cr, dr) + hr[1]
  10625. } else if (i < 48) {
  10626. t += f3(br, cr, dr) + hr[2]
  10627. } else if (i < 64) {
  10628. t += f2(br, cr, dr) + hr[3]
  10629. } else {// if (i<80) {
  10630. t += f1(br, cr, dr) + hr[4]
  10631. }
  10632. t = t | 0
  10633. t = rotl(t, sr[i])
  10634. t = (t + er) | 0
  10635. ar = er
  10636. er = dr
  10637. dr = rotl(cr, 10)
  10638. cr = br
  10639. br = t
  10640. }
  10641. // intermediate hash value
  10642. t = (H[1] + cl + dr) | 0
  10643. H[1] = (H[2] + dl + er) | 0
  10644. H[2] = (H[3] + el + ar) | 0
  10645. H[3] = (H[4] + al + br) | 0
  10646. H[4] = (H[0] + bl + cr) | 0
  10647. H[0] = t
  10648. }
  10649. function f1 (x, y, z) {
  10650. return ((x) ^ (y) ^ (z))
  10651. }
  10652. function f2 (x, y, z) {
  10653. return (((x) & (y)) | ((~x) & (z)))
  10654. }
  10655. function f3 (x, y, z) {
  10656. return (((x) | (~(y))) ^ (z))
  10657. }
  10658. function f4 (x, y, z) {
  10659. return (((x) & (z)) | ((y) & (~(z))))
  10660. }
  10661. function f5 (x, y, z) {
  10662. return ((x) ^ ((y) | (~(z))))
  10663. }
  10664. function rotl (x, n) {
  10665. return (x << n) | (x >>> (32 - n))
  10666. }
  10667. function ripemd160 (message) {
  10668. var H = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]
  10669. if (typeof message === 'string') {
  10670. message = new Buffer(message, 'utf8')
  10671. }
  10672. var m = bytesToWords(message)
  10673. var nBitsLeft = message.length * 8
  10674. var nBitsTotal = message.length * 8
  10675. // Add padding
  10676. m[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32)
  10677. m[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  10678. (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
  10679. (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00)
  10680. )
  10681. for (var i = 0; i < m.length; i += 16) {
  10682. processBlock(H, m, i)
  10683. }
  10684. // swap endian
  10685. for (i = 0; i < 5; i++) {
  10686. // shortcut
  10687. var H_i = H[i]
  10688. // Swap
  10689. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  10690. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00)
  10691. }
  10692. var digestbytes = wordsToBytes(H)
  10693. return new Buffer(digestbytes)
  10694. }
  10695. module.exports = ripemd160
  10696. }).call(this,require("buffer").Buffer)
  10697. },{"buffer":7}],35:[function(require,module,exports){
  10698. (function (Buffer){
  10699. // prototype class for hash functions
  10700. function Hash (blockSize, finalSize) {
  10701. this._block = new Buffer(blockSize)
  10702. this._finalSize = finalSize
  10703. this._blockSize = blockSize
  10704. this._len = 0
  10705. this._s = 0
  10706. }
  10707. Hash.prototype.update = function (data, enc) {
  10708. if (typeof data === 'string') {
  10709. enc = enc || 'utf8'
  10710. data = new Buffer(data, enc)
  10711. }
  10712. var l = this._len += data.length
  10713. var s = this._s || 0
  10714. var f = 0
  10715. var buffer = this._block
  10716. while (s < l) {
  10717. var t = Math.min(data.length, f + this._blockSize - (s % this._blockSize))
  10718. var ch = (t - f)
  10719. for (var i = 0; i < ch; i++) {
  10720. buffer[(s % this._blockSize) + i] = data[i + f]
  10721. }
  10722. s += ch
  10723. f += ch
  10724. if ((s % this._blockSize) === 0) {
  10725. this._update(buffer)
  10726. }
  10727. }
  10728. this._s = s
  10729. return this
  10730. }
  10731. Hash.prototype.digest = function (enc) {
  10732. // Suppose the length of the message M, in bits, is l
  10733. var l = this._len * 8
  10734. // Append the bit 1 to the end of the message
  10735. this._block[this._len % this._blockSize] = 0x80
  10736. // and then k zero bits, where k is the smallest non-negative solution to the equation (l + 1 + k) === finalSize mod blockSize
  10737. this._block.fill(0, this._len % this._blockSize + 1)
  10738. if (l % (this._blockSize * 8) >= this._finalSize * 8) {
  10739. this._update(this._block)
  10740. this._block.fill(0)
  10741. }
  10742. // to this append the block which is equal to the number l written in binary
  10743. // TODO: handle case where l is > Math.pow(2, 29)
  10744. this._block.writeInt32BE(l, this._blockSize - 4)
  10745. var hash = this._update(this._block) || this._hash()
  10746. return enc ? hash.toString(enc) : hash
  10747. }
  10748. Hash.prototype._update = function () {
  10749. throw new Error('_update must be implemented by subclass')
  10750. }
  10751. module.exports = Hash
  10752. }).call(this,require("buffer").Buffer)
  10753. },{"buffer":7}],36:[function(require,module,exports){
  10754. var exports = module.exports = function SHA (algorithm) {
  10755. algorithm = algorithm.toLowerCase()
  10756. var Algorithm = exports[algorithm]
  10757. if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)')
  10758. return new Algorithm()
  10759. }
  10760. exports.sha = require('./sha')
  10761. exports.sha1 = require('./sha1')
  10762. exports.sha224 = require('./sha224')
  10763. exports.sha256 = require('./sha256')
  10764. exports.sha384 = require('./sha384')
  10765. exports.sha512 = require('./sha512')
  10766. },{"./sha":37,"./sha1":38,"./sha224":39,"./sha256":40,"./sha384":41,"./sha512":42}],37:[function(require,module,exports){
  10767. (function (Buffer){
  10768. /*
  10769. * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
  10770. * in FIPS PUB 180-1
  10771. * This source code is derived from sha1.js of the same repository.
  10772. * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
  10773. * operation was added.
  10774. */
  10775. var inherits = require('inherits')
  10776. var Hash = require('./hash')
  10777. var K = [
  10778. 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
  10779. ]
  10780. var W = new Array(80)
  10781. function Sha () {
  10782. this.init()
  10783. this._w = W
  10784. Hash.call(this, 64, 56)
  10785. }
  10786. inherits(Sha, Hash)
  10787. Sha.prototype.init = function () {
  10788. this._a = 0x67452301
  10789. this._b = 0xefcdab89
  10790. this._c = 0x98badcfe
  10791. this._d = 0x10325476
  10792. this._e = 0xc3d2e1f0
  10793. return this
  10794. }
  10795. function rotl5 (num) {
  10796. return (num << 5) | (num >>> 27)
  10797. }
  10798. function rotl30 (num) {
  10799. return (num << 30) | (num >>> 2)
  10800. }
  10801. function ft (s, b, c, d) {
  10802. if (s === 0) return (b & c) | ((~b) & d)
  10803. if (s === 2) return (b & c) | (b & d) | (c & d)
  10804. return b ^ c ^ d
  10805. }
  10806. Sha.prototype._update = function (M) {
  10807. var W = this._w
  10808. var a = this._a | 0
  10809. var b = this._b | 0
  10810. var c = this._c | 0
  10811. var d = this._d | 0
  10812. var e = this._e | 0
  10813. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  10814. for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]
  10815. for (var j = 0; j < 80; ++j) {
  10816. var s = ~~(j / 20)
  10817. var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
  10818. e = d
  10819. d = c
  10820. c = rotl30(b)
  10821. b = a
  10822. a = t
  10823. }
  10824. this._a = (a + this._a) | 0
  10825. this._b = (b + this._b) | 0
  10826. this._c = (c + this._c) | 0
  10827. this._d = (d + this._d) | 0
  10828. this._e = (e + this._e) | 0
  10829. }
  10830. Sha.prototype._hash = function () {
  10831. var H = new Buffer(20)
  10832. H.writeInt32BE(this._a | 0, 0)
  10833. H.writeInt32BE(this._b | 0, 4)
  10834. H.writeInt32BE(this._c | 0, 8)
  10835. H.writeInt32BE(this._d | 0, 12)
  10836. H.writeInt32BE(this._e | 0, 16)
  10837. return H
  10838. }
  10839. module.exports = Sha
  10840. }).call(this,require("buffer").Buffer)
  10841. },{"./hash":35,"buffer":7,"inherits":16}],38:[function(require,module,exports){
  10842. (function (Buffer){
  10843. /*
  10844. * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
  10845. * in FIPS PUB 180-1
  10846. * Version 2.1a Copyright Paul Johnston 2000 - 2002.
  10847. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  10848. * Distributed under the BSD License
  10849. * See http://pajhome.org.uk/crypt/md5 for details.
  10850. */
  10851. var inherits = require('inherits')
  10852. var Hash = require('./hash')
  10853. var K = [
  10854. 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
  10855. ]
  10856. var W = new Array(80)
  10857. function Sha1 () {
  10858. this.init()
  10859. this._w = W
  10860. Hash.call(this, 64, 56)
  10861. }
  10862. inherits(Sha1, Hash)
  10863. Sha1.prototype.init = function () {
  10864. this._a = 0x67452301
  10865. this._b = 0xefcdab89
  10866. this._c = 0x98badcfe
  10867. this._d = 0x10325476
  10868. this._e = 0xc3d2e1f0
  10869. return this
  10870. }
  10871. function rotl1 (num) {
  10872. return (num << 1) | (num >>> 31)
  10873. }
  10874. function rotl5 (num) {
  10875. return (num << 5) | (num >>> 27)
  10876. }
  10877. function rotl30 (num) {
  10878. return (num << 30) | (num >>> 2)
  10879. }
  10880. function ft (s, b, c, d) {
  10881. if (s === 0) return (b & c) | ((~b) & d)
  10882. if (s === 2) return (b & c) | (b & d) | (c & d)
  10883. return b ^ c ^ d
  10884. }
  10885. Sha1.prototype._update = function (M) {
  10886. var W = this._w
  10887. var a = this._a | 0
  10888. var b = this._b | 0
  10889. var c = this._c | 0
  10890. var d = this._d | 0
  10891. var e = this._e | 0
  10892. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  10893. for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16])
  10894. for (var j = 0; j < 80; ++j) {
  10895. var s = ~~(j / 20)
  10896. var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
  10897. e = d
  10898. d = c
  10899. c = rotl30(b)
  10900. b = a
  10901. a = t
  10902. }
  10903. this._a = (a + this._a) | 0
  10904. this._b = (b + this._b) | 0
  10905. this._c = (c + this._c) | 0
  10906. this._d = (d + this._d) | 0
  10907. this._e = (e + this._e) | 0
  10908. }
  10909. Sha1.prototype._hash = function () {
  10910. var H = new Buffer(20)
  10911. H.writeInt32BE(this._a | 0, 0)
  10912. H.writeInt32BE(this._b | 0, 4)
  10913. H.writeInt32BE(this._c | 0, 8)
  10914. H.writeInt32BE(this._d | 0, 12)
  10915. H.writeInt32BE(this._e | 0, 16)
  10916. return H
  10917. }
  10918. module.exports = Sha1
  10919. }).call(this,require("buffer").Buffer)
  10920. },{"./hash":35,"buffer":7,"inherits":16}],39:[function(require,module,exports){
  10921. (function (Buffer){
  10922. /**
  10923. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  10924. * in FIPS 180-2
  10925. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  10926. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  10927. *
  10928. */
  10929. var inherits = require('inherits')
  10930. var Sha256 = require('./sha256')
  10931. var Hash = require('./hash')
  10932. var W = new Array(64)
  10933. function Sha224 () {
  10934. this.init()
  10935. this._w = W // new Array(64)
  10936. Hash.call(this, 64, 56)
  10937. }
  10938. inherits(Sha224, Sha256)
  10939. Sha224.prototype.init = function () {
  10940. this._a = 0xc1059ed8
  10941. this._b = 0x367cd507
  10942. this._c = 0x3070dd17
  10943. this._d = 0xf70e5939
  10944. this._e = 0xffc00b31
  10945. this._f = 0x68581511
  10946. this._g = 0x64f98fa7
  10947. this._h = 0xbefa4fa4
  10948. return this
  10949. }
  10950. Sha224.prototype._hash = function () {
  10951. var H = new Buffer(28)
  10952. H.writeInt32BE(this._a, 0)
  10953. H.writeInt32BE(this._b, 4)
  10954. H.writeInt32BE(this._c, 8)
  10955. H.writeInt32BE(this._d, 12)
  10956. H.writeInt32BE(this._e, 16)
  10957. H.writeInt32BE(this._f, 20)
  10958. H.writeInt32BE(this._g, 24)
  10959. return H
  10960. }
  10961. module.exports = Sha224
  10962. }).call(this,require("buffer").Buffer)
  10963. },{"./hash":35,"./sha256":40,"buffer":7,"inherits":16}],40:[function(require,module,exports){
  10964. (function (Buffer){
  10965. /**
  10966. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  10967. * in FIPS 180-2
  10968. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  10969. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  10970. *
  10971. */
  10972. var inherits = require('inherits')
  10973. var Hash = require('./hash')
  10974. var K = [
  10975. 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
  10976. 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
  10977. 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
  10978. 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
  10979. 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
  10980. 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
  10981. 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
  10982. 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
  10983. 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
  10984. 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
  10985. 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
  10986. 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
  10987. 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
  10988. 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
  10989. 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
  10990. 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
  10991. ]
  10992. var W = new Array(64)
  10993. function Sha256 () {
  10994. this.init()
  10995. this._w = W // new Array(64)
  10996. Hash.call(this, 64, 56)
  10997. }
  10998. inherits(Sha256, Hash)
  10999. Sha256.prototype.init = function () {
  11000. this._a = 0x6a09e667
  11001. this._b = 0xbb67ae85
  11002. this._c = 0x3c6ef372
  11003. this._d = 0xa54ff53a
  11004. this._e = 0x510e527f
  11005. this._f = 0x9b05688c
  11006. this._g = 0x1f83d9ab
  11007. this._h = 0x5be0cd19
  11008. return this
  11009. }
  11010. function ch (x, y, z) {
  11011. return z ^ (x & (y ^ z))
  11012. }
  11013. function maj (x, y, z) {
  11014. return (x & y) | (z & (x | y))
  11015. }
  11016. function sigma0 (x) {
  11017. return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10)
  11018. }
  11019. function sigma1 (x) {
  11020. return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7)
  11021. }
  11022. function gamma0 (x) {
  11023. return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3)
  11024. }
  11025. function gamma1 (x) {
  11026. return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10)
  11027. }
  11028. Sha256.prototype._update = function (M) {
  11029. var W = this._w
  11030. var a = this._a | 0
  11031. var b = this._b | 0
  11032. var c = this._c | 0
  11033. var d = this._d | 0
  11034. var e = this._e | 0
  11035. var f = this._f | 0
  11036. var g = this._g | 0
  11037. var h = this._h | 0
  11038. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  11039. for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0
  11040. for (var j = 0; j < 64; ++j) {
  11041. var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0
  11042. var T2 = (sigma0(a) + maj(a, b, c)) | 0
  11043. h = g
  11044. g = f
  11045. f = e
  11046. e = (d + T1) | 0
  11047. d = c
  11048. c = b
  11049. b = a
  11050. a = (T1 + T2) | 0
  11051. }
  11052. this._a = (a + this._a) | 0
  11053. this._b = (b + this._b) | 0
  11054. this._c = (c + this._c) | 0
  11055. this._d = (d + this._d) | 0
  11056. this._e = (e + this._e) | 0
  11057. this._f = (f + this._f) | 0
  11058. this._g = (g + this._g) | 0
  11059. this._h = (h + this._h) | 0
  11060. }
  11061. Sha256.prototype._hash = function () {
  11062. var H = new Buffer(32)
  11063. H.writeInt32BE(this._a, 0)
  11064. H.writeInt32BE(this._b, 4)
  11065. H.writeInt32BE(this._c, 8)
  11066. H.writeInt32BE(this._d, 12)
  11067. H.writeInt32BE(this._e, 16)
  11068. H.writeInt32BE(this._f, 20)
  11069. H.writeInt32BE(this._g, 24)
  11070. H.writeInt32BE(this._h, 28)
  11071. return H
  11072. }
  11073. module.exports = Sha256
  11074. }).call(this,require("buffer").Buffer)
  11075. },{"./hash":35,"buffer":7,"inherits":16}],41:[function(require,module,exports){
  11076. (function (Buffer){
  11077. var inherits = require('inherits')
  11078. var SHA512 = require('./sha512')
  11079. var Hash = require('./hash')
  11080. var W = new Array(160)
  11081. function Sha384 () {
  11082. this.init()
  11083. this._w = W
  11084. Hash.call(this, 128, 112)
  11085. }
  11086. inherits(Sha384, SHA512)
  11087. Sha384.prototype.init = function () {
  11088. this._ah = 0xcbbb9d5d
  11089. this._bh = 0x629a292a
  11090. this._ch = 0x9159015a
  11091. this._dh = 0x152fecd8
  11092. this._eh = 0x67332667
  11093. this._fh = 0x8eb44a87
  11094. this._gh = 0xdb0c2e0d
  11095. this._hh = 0x47b5481d
  11096. this._al = 0xc1059ed8
  11097. this._bl = 0x367cd507
  11098. this._cl = 0x3070dd17
  11099. this._dl = 0xf70e5939
  11100. this._el = 0xffc00b31
  11101. this._fl = 0x68581511
  11102. this._gl = 0x64f98fa7
  11103. this._hl = 0xbefa4fa4
  11104. return this
  11105. }
  11106. Sha384.prototype._hash = function () {
  11107. var H = new Buffer(48)
  11108. function writeInt64BE (h, l, offset) {
  11109. H.writeInt32BE(h, offset)
  11110. H.writeInt32BE(l, offset + 4)
  11111. }
  11112. writeInt64BE(this._ah, this._al, 0)
  11113. writeInt64BE(this._bh, this._bl, 8)
  11114. writeInt64BE(this._ch, this._cl, 16)
  11115. writeInt64BE(this._dh, this._dl, 24)
  11116. writeInt64BE(this._eh, this._el, 32)
  11117. writeInt64BE(this._fh, this._fl, 40)
  11118. return H
  11119. }
  11120. module.exports = Sha384
  11121. }).call(this,require("buffer").Buffer)
  11122. },{"./hash":35,"./sha512":42,"buffer":7,"inherits":16}],42:[function(require,module,exports){
  11123. (function (Buffer){
  11124. var inherits = require('inherits')
  11125. var Hash = require('./hash')
  11126. var K = [
  11127. 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
  11128. 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
  11129. 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
  11130. 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
  11131. 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
  11132. 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
  11133. 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
  11134. 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
  11135. 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
  11136. 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
  11137. 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
  11138. 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
  11139. 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
  11140. 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
  11141. 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
  11142. 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
  11143. 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
  11144. 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
  11145. 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
  11146. 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
  11147. 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
  11148. 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
  11149. 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
  11150. 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
  11151. 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
  11152. 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
  11153. 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
  11154. 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
  11155. 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
  11156. 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
  11157. 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
  11158. 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
  11159. 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
  11160. 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
  11161. 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
  11162. 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
  11163. 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
  11164. 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
  11165. 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
  11166. 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
  11167. ]
  11168. var W = new Array(160)
  11169. function Sha512 () {
  11170. this.init()
  11171. this._w = W
  11172. Hash.call(this, 128, 112)
  11173. }
  11174. inherits(Sha512, Hash)
  11175. Sha512.prototype.init = function () {
  11176. this._ah = 0x6a09e667
  11177. this._bh = 0xbb67ae85
  11178. this._ch = 0x3c6ef372
  11179. this._dh = 0xa54ff53a
  11180. this._eh = 0x510e527f
  11181. this._fh = 0x9b05688c
  11182. this._gh = 0x1f83d9ab
  11183. this._hh = 0x5be0cd19
  11184. this._al = 0xf3bcc908
  11185. this._bl = 0x84caa73b
  11186. this._cl = 0xfe94f82b
  11187. this._dl = 0x5f1d36f1
  11188. this._el = 0xade682d1
  11189. this._fl = 0x2b3e6c1f
  11190. this._gl = 0xfb41bd6b
  11191. this._hl = 0x137e2179
  11192. return this
  11193. }
  11194. function Ch (x, y, z) {
  11195. return z ^ (x & (y ^ z))
  11196. }
  11197. function maj (x, y, z) {
  11198. return (x & y) | (z & (x | y))
  11199. }
  11200. function sigma0 (x, xl) {
  11201. return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25)
  11202. }
  11203. function sigma1 (x, xl) {
  11204. return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23)
  11205. }
  11206. function Gamma0 (x, xl) {
  11207. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7)
  11208. }
  11209. function Gamma0l (x, xl) {
  11210. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25)
  11211. }
  11212. function Gamma1 (x, xl) {
  11213. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6)
  11214. }
  11215. function Gamma1l (x, xl) {
  11216. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26)
  11217. }
  11218. function getCarry (a, b) {
  11219. return (a >>> 0) < (b >>> 0) ? 1 : 0
  11220. }
  11221. Sha512.prototype._update = function (M) {
  11222. var W = this._w
  11223. var ah = this._ah | 0
  11224. var bh = this._bh | 0
  11225. var ch = this._ch | 0
  11226. var dh = this._dh | 0
  11227. var eh = this._eh | 0
  11228. var fh = this._fh | 0
  11229. var gh = this._gh | 0
  11230. var hh = this._hh | 0
  11231. var al = this._al | 0
  11232. var bl = this._bl | 0
  11233. var cl = this._cl | 0
  11234. var dl = this._dl | 0
  11235. var el = this._el | 0
  11236. var fl = this._fl | 0
  11237. var gl = this._gl | 0
  11238. var hl = this._hl | 0
  11239. for (var i = 0; i < 32; i += 2) {
  11240. W[i] = M.readInt32BE(i * 4)
  11241. W[i + 1] = M.readInt32BE(i * 4 + 4)
  11242. }
  11243. for (; i < 160; i += 2) {
  11244. var xh = W[i - 15 * 2]
  11245. var xl = W[i - 15 * 2 + 1]
  11246. var gamma0 = Gamma0(xh, xl)
  11247. var gamma0l = Gamma0l(xl, xh)
  11248. xh = W[i - 2 * 2]
  11249. xl = W[i - 2 * 2 + 1]
  11250. var gamma1 = Gamma1(xh, xl)
  11251. var gamma1l = Gamma1l(xl, xh)
  11252. // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  11253. var Wi7h = W[i - 7 * 2]
  11254. var Wi7l = W[i - 7 * 2 + 1]
  11255. var Wi16h = W[i - 16 * 2]
  11256. var Wi16l = W[i - 16 * 2 + 1]
  11257. var Wil = (gamma0l + Wi7l) | 0
  11258. var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0
  11259. Wil = (Wil + gamma1l) | 0
  11260. Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0
  11261. Wil = (Wil + Wi16l) | 0
  11262. Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0
  11263. W[i] = Wih
  11264. W[i + 1] = Wil
  11265. }
  11266. for (var j = 0; j < 160; j += 2) {
  11267. Wih = W[j]
  11268. Wil = W[j + 1]
  11269. var majh = maj(ah, bh, ch)
  11270. var majl = maj(al, bl, cl)
  11271. var sigma0h = sigma0(ah, al)
  11272. var sigma0l = sigma0(al, ah)
  11273. var sigma1h = sigma1(eh, el)
  11274. var sigma1l = sigma1(el, eh)
  11275. // t1 = h + sigma1 + ch + K[j] + W[j]
  11276. var Kih = K[j]
  11277. var Kil = K[j + 1]
  11278. var chh = Ch(eh, fh, gh)
  11279. var chl = Ch(el, fl, gl)
  11280. var t1l = (hl + sigma1l) | 0
  11281. var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0
  11282. t1l = (t1l + chl) | 0
  11283. t1h = (t1h + chh + getCarry(t1l, chl)) | 0
  11284. t1l = (t1l + Kil) | 0
  11285. t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0
  11286. t1l = (t1l + Wil) | 0
  11287. t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0
  11288. // t2 = sigma0 + maj
  11289. var t2l = (sigma0l + majl) | 0
  11290. var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0
  11291. hh = gh
  11292. hl = gl
  11293. gh = fh
  11294. gl = fl
  11295. fh = eh
  11296. fl = el
  11297. el = (dl + t1l) | 0
  11298. eh = (dh + t1h + getCarry(el, dl)) | 0
  11299. dh = ch
  11300. dl = cl
  11301. ch = bh
  11302. cl = bl
  11303. bh = ah
  11304. bl = al
  11305. al = (t1l + t2l) | 0
  11306. ah = (t1h + t2h + getCarry(al, t1l)) | 0
  11307. }
  11308. this._al = (this._al + al) | 0
  11309. this._bl = (this._bl + bl) | 0
  11310. this._cl = (this._cl + cl) | 0
  11311. this._dl = (this._dl + dl) | 0
  11312. this._el = (this._el + el) | 0
  11313. this._fl = (this._fl + fl) | 0
  11314. this._gl = (this._gl + gl) | 0
  11315. this._hl = (this._hl + hl) | 0
  11316. this._ah = (this._ah + ah + getCarry(this._al, al)) | 0
  11317. this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0
  11318. this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0
  11319. this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0
  11320. this._eh = (this._eh + eh + getCarry(this._el, el)) | 0
  11321. this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0
  11322. this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0
  11323. this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0
  11324. }
  11325. Sha512.prototype._hash = function () {
  11326. var H = new Buffer(64)
  11327. function writeInt64BE (h, l, offset) {
  11328. H.writeInt32BE(h, offset)
  11329. H.writeInt32BE(l, offset + 4)
  11330. }
  11331. writeInt64BE(this._ah, this._al, 0)
  11332. writeInt64BE(this._bh, this._bl, 8)
  11333. writeInt64BE(this._ch, this._cl, 16)
  11334. writeInt64BE(this._dh, this._dl, 24)
  11335. writeInt64BE(this._eh, this._el, 32)
  11336. writeInt64BE(this._fh, this._fl, 40)
  11337. writeInt64BE(this._gh, this._gl, 48)
  11338. writeInt64BE(this._hh, this._hl, 56)
  11339. return H
  11340. }
  11341. module.exports = Sha512
  11342. }).call(this,require("buffer").Buffer)
  11343. },{"./hash":35,"buffer":7,"inherits":16}],43:[function(require,module,exports){
  11344. // Copyright Joyent, Inc. and other Node contributors.
  11345. //
  11346. // Permission is hereby granted, free of charge, to any person obtaining a
  11347. // copy of this software and associated documentation files (the
  11348. // "Software"), to deal in the Software without restriction, including
  11349. // without limitation the rights to use, copy, modify, merge, publish,
  11350. // distribute, sublicense, and/or sell copies of the Software, and to permit
  11351. // persons to whom the Software is furnished to do so, subject to the
  11352. // following conditions:
  11353. //
  11354. // The above copyright notice and this permission notice shall be included
  11355. // in all copies or substantial portions of the Software.
  11356. //
  11357. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11358. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11359. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  11360. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  11361. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  11362. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  11363. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  11364. module.exports = Stream;
  11365. var EE = require('events').EventEmitter;
  11366. var inherits = require('inherits');
  11367. inherits(Stream, EE);
  11368. Stream.Readable = require('readable-stream/readable.js');
  11369. Stream.Writable = require('readable-stream/writable.js');
  11370. Stream.Duplex = require('readable-stream/duplex.js');
  11371. Stream.Transform = require('readable-stream/transform.js');
  11372. Stream.PassThrough = require('readable-stream/passthrough.js');
  11373. // Backwards-compat with node 0.4.x
  11374. Stream.Stream = Stream;
  11375. // old-style streams. Note that the pipe method (the only relevant
  11376. // part of this class) is overridden in the Readable class.
  11377. function Stream() {
  11378. EE.call(this);
  11379. }
  11380. Stream.prototype.pipe = function(dest, options) {
  11381. var source = this;
  11382. function ondata(chunk) {
  11383. if (dest.writable) {
  11384. if (false === dest.write(chunk) && source.pause) {
  11385. source.pause();
  11386. }
  11387. }
  11388. }
  11389. source.on('data', ondata);
  11390. function ondrain() {
  11391. if (source.readable && source.resume) {
  11392. source.resume();
  11393. }
  11394. }
  11395. dest.on('drain', ondrain);
  11396. // If the 'end' option is not supplied, dest.end() will be called when
  11397. // source gets the 'end' or 'close' events. Only dest.end() once.
  11398. if (!dest._isStdio && (!options || options.end !== false)) {
  11399. source.on('end', onend);
  11400. source.on('close', onclose);
  11401. }
  11402. var didOnEnd = false;
  11403. function onend() {
  11404. if (didOnEnd) return;
  11405. didOnEnd = true;
  11406. dest.end();
  11407. }
  11408. function onclose() {
  11409. if (didOnEnd) return;
  11410. didOnEnd = true;
  11411. if (typeof dest.destroy === 'function') dest.destroy();
  11412. }
  11413. // don't leave dangling pipes when there are errors.
  11414. function onerror(er) {
  11415. cleanup();
  11416. if (EE.listenerCount(this, 'error') === 0) {
  11417. throw er; // Unhandled stream error in pipe.
  11418. }
  11419. }
  11420. source.on('error', onerror);
  11421. dest.on('error', onerror);
  11422. // remove all the event listeners that were added.
  11423. function cleanup() {
  11424. source.removeListener('data', ondata);
  11425. dest.removeListener('drain', ondrain);
  11426. source.removeListener('end', onend);
  11427. source.removeListener('close', onclose);
  11428. source.removeListener('error', onerror);
  11429. dest.removeListener('error', onerror);
  11430. source.removeListener('end', cleanup);
  11431. source.removeListener('close', cleanup);
  11432. dest.removeListener('close', cleanup);
  11433. }
  11434. source.on('end', cleanup);
  11435. source.on('close', cleanup);
  11436. dest.on('close', cleanup);
  11437. dest.emit('pipe', source);
  11438. // Allow for unix-like usage: A.pipe(B).pipe(C)
  11439. return dest;
  11440. };
  11441. },{"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){
  11442. // Copyright Joyent, Inc. and other Node contributors.
  11443. //
  11444. // Permission is hereby granted, free of charge, to any person obtaining a
  11445. // copy of this software and associated documentation files (the
  11446. // "Software"), to deal in the Software without restriction, including
  11447. // without limitation the rights to use, copy, modify, merge, publish,
  11448. // distribute, sublicense, and/or sell copies of the Software, and to permit
  11449. // persons to whom the Software is furnished to do so, subject to the
  11450. // following conditions:
  11451. //
  11452. // The above copyright notice and this permission notice shall be included
  11453. // in all copies or substantial portions of the Software.
  11454. //
  11455. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11456. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11457. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  11458. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  11459. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  11460. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  11461. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  11462. var Buffer = require('buffer').Buffer;
  11463. var isBufferEncoding = Buffer.isEncoding
  11464. || function(encoding) {
  11465. switch (encoding && encoding.toLowerCase()) {
  11466. 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;
  11467. default: return false;
  11468. }
  11469. }
  11470. function assertEncoding(encoding) {
  11471. if (encoding && !isBufferEncoding(encoding)) {
  11472. throw new Error('Unknown encoding: ' + encoding);
  11473. }
  11474. }
  11475. // StringDecoder provides an interface for efficiently splitting a series of
  11476. // buffers into a series of JS strings without breaking apart multi-byte
  11477. // characters. CESU-8 is handled as part of the UTF-8 encoding.
  11478. //
  11479. // @TODO Handling all encodings inside a single object makes it very difficult
  11480. // to reason about this code, so it should be split up in the future.
  11481. // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
  11482. // points as used by CESU-8.
  11483. var StringDecoder = exports.StringDecoder = function(encoding) {
  11484. this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
  11485. assertEncoding(encoding);
  11486. switch (this.encoding) {
  11487. case 'utf8':
  11488. // CESU-8 represents each of Surrogate Pair by 3-bytes
  11489. this.surrogateSize = 3;
  11490. break;
  11491. case 'ucs2':
  11492. case 'utf16le':
  11493. // UTF-16 represents each of Surrogate Pair by 2-bytes
  11494. this.surrogateSize = 2;
  11495. this.detectIncompleteChar = utf16DetectIncompleteChar;
  11496. break;
  11497. case 'base64':
  11498. // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
  11499. this.surrogateSize = 3;
  11500. this.detectIncompleteChar = base64DetectIncompleteChar;
  11501. break;
  11502. default:
  11503. this.write = passThroughWrite;
  11504. return;
  11505. }
  11506. // Enough space to store all bytes of a single character. UTF-8 needs 4
  11507. // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
  11508. this.charBuffer = new Buffer(6);
  11509. // Number of bytes received for the current incomplete multi-byte character.
  11510. this.charReceived = 0;
  11511. // Number of bytes expected for the current incomplete multi-byte character.
  11512. this.charLength = 0;
  11513. };
  11514. // write decodes the given buffer and returns it as JS string that is
  11515. // guaranteed to not contain any partial multi-byte characters. Any partial
  11516. // character found at the end of the buffer is buffered up, and will be
  11517. // returned when calling write again with the remaining bytes.
  11518. //
  11519. // Note: Converting a Buffer containing an orphan surrogate to a String
  11520. // currently works, but converting a String to a Buffer (via `new Buffer`, or
  11521. // Buffer#write) will replace incomplete surrogates with the unicode
  11522. // replacement character. See https://codereview.chromium.org/121173009/ .
  11523. StringDecoder.prototype.write = function(buffer) {
  11524. var charStr = '';
  11525. // if our last write ended with an incomplete multibyte character
  11526. while (this.charLength) {
  11527. // determine how many remaining bytes this buffer has to offer for this char
  11528. var available = (buffer.length >= this.charLength - this.charReceived) ?
  11529. this.charLength - this.charReceived :
  11530. buffer.length;
  11531. // add the new bytes to the char buffer
  11532. buffer.copy(this.charBuffer, this.charReceived, 0, available);
  11533. this.charReceived += available;
  11534. if (this.charReceived < this.charLength) {
  11535. // still not enough chars in this buffer? wait for more ...
  11536. return '';
  11537. }
  11538. // remove bytes belonging to the current character from the buffer
  11539. buffer = buffer.slice(available, buffer.length);
  11540. // get the character that was split
  11541. charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
  11542. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  11543. var charCode = charStr.charCodeAt(charStr.length - 1);
  11544. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  11545. this.charLength += this.surrogateSize;
  11546. charStr = '';
  11547. continue;
  11548. }
  11549. this.charReceived = this.charLength = 0;
  11550. // if there are no more bytes in this buffer, just emit our char
  11551. if (buffer.length === 0) {
  11552. return charStr;
  11553. }
  11554. break;
  11555. }
  11556. // determine and set charLength / charReceived
  11557. this.detectIncompleteChar(buffer);
  11558. var end = buffer.length;
  11559. if (this.charLength) {
  11560. // buffer the incomplete character bytes we got
  11561. buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
  11562. end -= this.charReceived;
  11563. }
  11564. charStr += buffer.toString(this.encoding, 0, end);
  11565. var end = charStr.length - 1;
  11566. var charCode = charStr.charCodeAt(end);
  11567. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  11568. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  11569. var size = this.surrogateSize;
  11570. this.charLength += size;
  11571. this.charReceived += size;
  11572. this.charBuffer.copy(this.charBuffer, size, 0, size);
  11573. buffer.copy(this.charBuffer, 0, 0, size);
  11574. return charStr.substring(0, end);
  11575. }
  11576. // or just emit the charStr
  11577. return charStr;
  11578. };
  11579. // detectIncompleteChar determines if there is an incomplete UTF-8 character at
  11580. // the end of the given buffer. If so, it sets this.charLength to the byte
  11581. // length that character, and sets this.charReceived to the number of bytes
  11582. // that are available for this character.
  11583. StringDecoder.prototype.detectIncompleteChar = function(buffer) {
  11584. // determine how many bytes we have to check at the end of this buffer
  11585. var i = (buffer.length >= 3) ? 3 : buffer.length;
  11586. // Figure out if one of the last i bytes of our buffer announces an
  11587. // incomplete char.
  11588. for (; i > 0; i--) {
  11589. var c = buffer[buffer.length - i];
  11590. // See http://en.wikipedia.org/wiki/UTF-8#Description
  11591. // 110XXXXX
  11592. if (i == 1 && c >> 5 == 0x06) {
  11593. this.charLength = 2;
  11594. break;
  11595. }
  11596. // 1110XXXX
  11597. if (i <= 2 && c >> 4 == 0x0E) {
  11598. this.charLength = 3;
  11599. break;
  11600. }
  11601. // 11110XXX
  11602. if (i <= 3 && c >> 3 == 0x1E) {
  11603. this.charLength = 4;
  11604. break;
  11605. }
  11606. }
  11607. this.charReceived = i;
  11608. };
  11609. StringDecoder.prototype.end = function(buffer) {
  11610. var res = '';
  11611. if (buffer && buffer.length)
  11612. res = this.write(buffer);
  11613. if (this.charReceived) {
  11614. var cr = this.charReceived;
  11615. var buf = this.charBuffer;
  11616. var enc = this.encoding;
  11617. res += buf.slice(0, cr).toString(enc);
  11618. }
  11619. return res;
  11620. };
  11621. function passThroughWrite(buffer) {
  11622. return buffer.toString(this.encoding);
  11623. }
  11624. function utf16DetectIncompleteChar(buffer) {
  11625. this.charReceived = buffer.length % 2;
  11626. this.charLength = this.charReceived ? 2 : 0;
  11627. }
  11628. function base64DetectIncompleteChar(buffer) {
  11629. this.charReceived = buffer.length % 3;
  11630. this.charLength = this.charReceived ? 3 : 0;
  11631. }
  11632. },{"buffer":7}],45:[function(require,module,exports){
  11633. (function (global){
  11634. /**
  11635. * Module exports.
  11636. */
  11637. module.exports = deprecate;
  11638. /**
  11639. * Mark that a method should not be used.
  11640. * Returns a modified function which warns once by default.
  11641. *
  11642. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  11643. *
  11644. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  11645. * will throw an Error when invoked.
  11646. *
  11647. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  11648. * will invoke `console.trace()` instead of `console.error()`.
  11649. *
  11650. * @param {Function} fn - the function to deprecate
  11651. * @param {String} msg - the string to print to the console when `fn` is invoked
  11652. * @returns {Function} a new "deprecated" version of `fn`
  11653. * @api public
  11654. */
  11655. function deprecate (fn, msg) {
  11656. if (config('noDeprecation')) {
  11657. return fn;
  11658. }
  11659. var warned = false;
  11660. function deprecated() {
  11661. if (!warned) {
  11662. if (config('throwDeprecation')) {
  11663. throw new Error(msg);
  11664. } else if (config('traceDeprecation')) {
  11665. console.trace(msg);
  11666. } else {
  11667. console.warn(msg);
  11668. }
  11669. warned = true;
  11670. }
  11671. return fn.apply(this, arguments);
  11672. }
  11673. return deprecated;
  11674. }
  11675. /**
  11676. * Checks `localStorage` for boolean values for the given `name`.
  11677. *
  11678. * @param {String} name
  11679. * @returns {Boolean}
  11680. * @api private
  11681. */
  11682. function config (name) {
  11683. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  11684. try {
  11685. if (!global.localStorage) return false;
  11686. } catch (_) {
  11687. return false;
  11688. }
  11689. var val = global.localStorage[name];
  11690. if (null == val) return false;
  11691. return String(val).toLowerCase() === 'true';
  11692. }
  11693. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  11694. },{}],46:[function(require,module,exports){
  11695. (function (Buffer){
  11696. var pbkdf2 = require('pbkdf2');
  11697. var createHMAC = require('create-hmac');
  11698. var Promise = require("bluebird");
  11699. module.exports = {
  11700. encryptLogin: encryptLogin,
  11701. renderPassword: renderPassword,
  11702. createFingerprint: createFingerprint,
  11703. _deriveEncryptedLogin: deriveEncryptedLogin,
  11704. _getPasswordTemplate: getPasswordTemplate,
  11705. _prettyPrint: prettyPrint,
  11706. _string2charCodes: string2charCodes,
  11707. _getCharType: getCharType,
  11708. _getPasswordChar: getPasswordChar,
  11709. _createHmac: createHmac,
  11710. };
  11711. function encryptLogin(login, masterPassword, options) {
  11712. var _options = options !== undefined ? options : {};
  11713. var iterations = _options.iterations || 8192;
  11714. var keylen = _options.keylen || 32;
  11715. return new Promise(function (resolve, reject) {
  11716. if (!login || !masterPassword) {
  11717. reject('login and master password parameters could not be empty');
  11718. }
  11719. pbkdf2.pbkdf2(masterPassword, login, iterations, keylen, 'sha256', function (error, key) {
  11720. if (error) {
  11721. reject('error in pbkdf2');
  11722. } else {
  11723. resolve(key.toString('hex'));
  11724. }
  11725. });
  11726. })
  11727. }
  11728. function renderPassword(encryptedLogin, site, passwordOptions) {
  11729. return deriveEncryptedLogin(encryptedLogin, site, passwordOptions).then(function (derivedEncryptedLogin) {
  11730. var template = passwordOptions.template || getPasswordTemplate(passwordOptions);
  11731. return prettyPrint(derivedEncryptedLogin, template);
  11732. });
  11733. }
  11734. function createHmac(encryptedLogin, salt) {
  11735. return new Promise(function (resolve) {
  11736. resolve(createHMAC('sha256', new Buffer(encryptedLogin)).update(salt).digest('hex'));
  11737. });
  11738. }
  11739. function deriveEncryptedLogin(encryptedLogin, site, options) {
  11740. var _options = options !== undefined ? options : {};
  11741. var length = _options.length || 12;
  11742. var counter = _options.counter || 1;
  11743. var salt = site + counter.toString();
  11744. return createHmac(encryptedLogin, salt).then(function (derivedHash) {
  11745. return derivedHash.substring(0, length);
  11746. });
  11747. }
  11748. function getPasswordTemplate(passwordTypes) {
  11749. var templates = {
  11750. lowercase: 'vc',
  11751. uppercase: 'VC',
  11752. numbers: 'n',
  11753. symbols: 's',
  11754. };
  11755. var returnedTemplate = '';
  11756. Object.keys(templates).forEach(function (template) {
  11757. if (passwordTypes.hasOwnProperty(template) && passwordTypes[template]) {
  11758. returnedTemplate += templates[template]
  11759. }
  11760. });
  11761. return returnedTemplate;
  11762. }
  11763. function prettyPrint(hash, template) {
  11764. var password = '';
  11765. string2charCodes(hash).forEach(function (charCode, index) {
  11766. var charType = getCharType(template, index);
  11767. password += getPasswordChar(charType, charCode);
  11768. });
  11769. return password;
  11770. }
  11771. function string2charCodes(text) {
  11772. var charCodes = [];
  11773. for (var i = 0; i < text.length; i++) {
  11774. charCodes.push(text.charCodeAt(i));
  11775. }
  11776. return charCodes;
  11777. }
  11778. function getCharType(template, index) {
  11779. return template[index % template.length];
  11780. }
  11781. function getPasswordChar(charType, index) {
  11782. var passwordsChars = {
  11783. V: 'AEIOUY',
  11784. C: 'BCDFGHJKLMNPQRSTVWXZ',
  11785. v: 'aeiouy',
  11786. c: 'bcdfghjklmnpqrstvwxz',
  11787. A: 'AEIOUYBCDFGHJKLMNPQRSTVWXZ',
  11788. a: 'AEIOUYaeiouyBCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz',
  11789. n: '0123456789',
  11790. s: '@&%?,=[]_:-+*$#!\'^~;()/.',
  11791. x: 'AEIOUYaeiouyBCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz0123456789@&%?,=[]_:-+*$#!\'^~;()/.'
  11792. };
  11793. var passwordChar = passwordsChars[charType];
  11794. return passwordChar[index % passwordChar.length];
  11795. }
  11796. function createFingerprint(str) {
  11797. return new Promise(function (resolve) {
  11798. resolve(createHMAC('sha256', new Buffer(str)).digest('hex'))
  11799. });
  11800. }
  11801. }).call(this,require("buffer").Buffer)
  11802. },{"bluebird":4,"buffer":7,"create-hmac":13,"pbkdf2":19}],47:[function(require,module,exports){
  11803. var Promise = require("bluebird");
  11804. var pbkdf2 = require('pbkdf2');
  11805. var bigInt = require("big-integer");
  11806. module.exports = {
  11807. generatePassword: generatePassword,
  11808. _calcEntropy: calcEntropy,
  11809. _consumeEntropy: consumeEntropy,
  11810. _getSetOfCharacters: getSetOfCharacters,
  11811. _numberSubsetsOfChars: numberSubsetsOfChars,
  11812. _includeOneCharPerSetOfCharacters: includeOneCharPerSetOfCharacters,
  11813. _generateOneCharPerSetOfCharacters: generateOneCharPerSetOfCharacters,
  11814. _renderPassword: renderPassword
  11815. };
  11816. function generatePassword(site, login, masterPassword, passwordProfile) {
  11817. return calcEntropy(site, login, masterPassword, passwordProfile).then(function (entropy) {
  11818. var setOfCharacters = getSetOfCharacters(passwordProfile);
  11819. return renderPassword(entropy, setOfCharacters, passwordProfile)
  11820. });
  11821. }
  11822. function calcEntropy(site, login, masterPassword, passwordProfile) {
  11823. return new Promise(function (resolve, reject) {
  11824. var salt = site + login + passwordProfile.counter.toString(16);
  11825. var iterations = passwordProfile.iterations || 100000;
  11826. var keylen = passwordProfile.keylen || 32;
  11827. var digest = passwordProfile.digest || 'sha256';
  11828. pbkdf2.pbkdf2(masterPassword, salt, iterations, keylen, digest, function (error, key) {
  11829. if (error) {
  11830. reject('error in pbkdf2');
  11831. } else {
  11832. resolve(key.toString('hex'));
  11833. }
  11834. });
  11835. });
  11836. }
  11837. var subsetOfCharacters = {
  11838. lowercase: 'abcdefghijklmnopqrstuvwxyz',
  11839. uppercase: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
  11840. digits: '0123456789',
  11841. symbols: '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
  11842. };
  11843. function getSetOfCharacters(passwordProfile) {
  11844. if (typeof passwordProfile === 'undefined') {
  11845. return subsetOfCharacters.lowercase + subsetOfCharacters.uppercase + subsetOfCharacters.digits + subsetOfCharacters.symbols;
  11846. }
  11847. var setOfCharacters = '';
  11848. ['lowercase', 'uppercase', 'digits', 'symbols'].forEach(function (subset) {
  11849. if (passwordProfile.hasOwnProperty(subset) && passwordProfile[subset]) {
  11850. setOfCharacters += subsetOfCharacters[subset]
  11851. }
  11852. });
  11853. return setOfCharacters;
  11854. }
  11855. function consumeEntropy(generatedPassword, quotient, setOfCharacters, maxLength) {
  11856. if (generatedPassword.length >= maxLength) {
  11857. return {value: generatedPassword, entropy: quotient}
  11858. }
  11859. var longDivision = quotient.divmod(setOfCharacters.length);
  11860. generatedPassword += setOfCharacters[longDivision.remainder];
  11861. return consumeEntropy(generatedPassword, longDivision.quotient, setOfCharacters, maxLength)
  11862. }
  11863. function includeOneCharPerSetOfCharacters(generatedPassword, entropy, oneCharPerSetOfCharacters) {
  11864. var finalPassword = generatedPassword;
  11865. var quotient = entropy;
  11866. for (var i = 0; i < oneCharPerSetOfCharacters.length; i++) {
  11867. var longDivision = quotient.divmod(finalPassword.length);
  11868. finalPassword = finalPassword.slice(0, longDivision.remainder) + oneCharPerSetOfCharacters[i] + finalPassword.slice(longDivision.remainder);
  11869. quotient = longDivision.quotient;
  11870. }
  11871. return finalPassword;
  11872. }
  11873. function generateOneCharPerSetOfCharacters(entropy, passwordProfile) {
  11874. var oneCharPerSetOfCharacters = '';
  11875. var quotient = entropy;
  11876. ['lowercase', 'uppercase', 'digits', 'symbols'].forEach(function (subset) {
  11877. if (passwordProfile.hasOwnProperty(subset) && passwordProfile[subset]) {
  11878. var alphabet = subsetOfCharacters[subset];
  11879. var longDivision = quotient.divmod(alphabet.length);
  11880. oneCharPerSetOfCharacters += alphabet[longDivision.remainder];
  11881. quotient = longDivision.quotient;
  11882. }
  11883. });
  11884. return {value: oneCharPerSetOfCharacters, entropy: quotient};
  11885. }
  11886. function numberSubsetsOfChars(passwordProfile) {
  11887. var numberOfSubsets = 0;
  11888. ['lowercase', 'uppercase', 'digits', 'symbols'].forEach(function (subset) {
  11889. if (passwordProfile.hasOwnProperty(subset) && passwordProfile[subset]) {
  11890. numberOfSubsets += 1;
  11891. }
  11892. });
  11893. return numberOfSubsets;
  11894. }
  11895. function renderPassword(entropy, setOfCharacters, passwordProfile) {
  11896. var _passwordProfile = passwordProfile !== undefined ? passwordProfile : {
  11897. lowercase: true,
  11898. uppercase: true,
  11899. digits: true,
  11900. symbols: true
  11901. };
  11902. var length = _passwordProfile.length || 14;
  11903. var numberCharsWillBeAdded = numberSubsetsOfChars(_passwordProfile);
  11904. var password = consumeEntropy('', bigInt(entropy, 16), setOfCharacters, length - numberCharsWillBeAdded);
  11905. var oneCharPerSetOfCharacters = generateOneCharPerSetOfCharacters(password.entropy, _passwordProfile);
  11906. return includeOneCharPerSetOfCharacters(password.value, oneCharPerSetOfCharacters.entropy, oneCharPerSetOfCharacters.value);
  11907. }
  11908. },{"big-integer":3,"bluebird":4,"pbkdf2":19}]},{},[1])(1)
  11909. });