Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205
  1. (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. (function (process,global){
  3. 'use strict';
  4. /* eslint no-unused-vars: off */
  5. /* eslint-env commonjs */
  6. /**
  7. * Shim process.stdout.
  8. */
  9. process.stdout = require('browser-stdout')();
  10. var Mocha = require('./lib/mocha');
  11. /**
  12. * Create a Mocha instance.
  13. *
  14. * @return {undefined}
  15. */
  16. var mocha = new Mocha({ reporter: 'html' });
  17. /**
  18. * Save timer references to avoid Sinon interfering (see GH-237).
  19. */
  20. var Date = global.Date;
  21. var setTimeout = global.setTimeout;
  22. var setInterval = global.setInterval;
  23. var clearTimeout = global.clearTimeout;
  24. var clearInterval = global.clearInterval;
  25. var uncaughtExceptionHandlers = [];
  26. var originalOnerrorHandler = global.onerror;
  27. /**
  28. * Remove uncaughtException listener.
  29. * Revert to original onerror handler if previously defined.
  30. */
  31. process.removeListener = function (e, fn) {
  32. if (e === 'uncaughtException') {
  33. if (originalOnerrorHandler) {
  34. global.onerror = originalOnerrorHandler;
  35. } else {
  36. global.onerror = function () {};
  37. }
  38. var i = Mocha.utils.indexOf(uncaughtExceptionHandlers, fn);
  39. if (i !== -1) {
  40. uncaughtExceptionHandlers.splice(i, 1);
  41. }
  42. }
  43. };
  44. /**
  45. * Implements uncaughtException listener.
  46. */
  47. process.on = function (e, fn) {
  48. if (e === 'uncaughtException') {
  49. global.onerror = function (err, url, line) {
  50. fn(new Error(err + ' (' + url + ':' + line + ')'));
  51. return !mocha.allowUncaught;
  52. };
  53. uncaughtExceptionHandlers.push(fn);
  54. }
  55. };
  56. // The BDD UI is registered by default, but no UI will be functional in the
  57. // browser without an explicit call to the overridden `mocha.ui` (see below).
  58. // Ensure that this default UI does not expose its methods to the global scope.
  59. mocha.suite.removeAllListeners('pre-require');
  60. var immediateQueue = [];
  61. var immediateTimeout;
  62. function timeslice () {
  63. var immediateStart = new Date().getTime();
  64. while (immediateQueue.length && (new Date().getTime() - immediateStart) < 100) {
  65. immediateQueue.shift()();
  66. }
  67. if (immediateQueue.length) {
  68. immediateTimeout = setTimeout(timeslice, 0);
  69. } else {
  70. immediateTimeout = null;
  71. }
  72. }
  73. /**
  74. * High-performance override of Runner.immediately.
  75. */
  76. Mocha.Runner.immediately = function (callback) {
  77. immediateQueue.push(callback);
  78. if (!immediateTimeout) {
  79. immediateTimeout = setTimeout(timeslice, 0);
  80. }
  81. };
  82. /**
  83. * Function to allow assertion libraries to throw errors directly into mocha.
  84. * This is useful when running tests in a browser because window.onerror will
  85. * only receive the 'message' attribute of the Error.
  86. */
  87. mocha.throwError = function (err) {
  88. Mocha.utils.forEach(uncaughtExceptionHandlers, function (fn) {
  89. fn(err);
  90. });
  91. throw err;
  92. };
  93. /**
  94. * Override ui to ensure that the ui functions are initialized.
  95. * Normally this would happen in Mocha.prototype.loadFiles.
  96. */
  97. mocha.ui = function (ui) {
  98. Mocha.prototype.ui.call(this, ui);
  99. this.suite.emit('pre-require', global, null, this);
  100. return this;
  101. };
  102. /**
  103. * Setup mocha with the given setting options.
  104. */
  105. mocha.setup = function (opts) {
  106. if (typeof opts === 'string') {
  107. opts = { ui: opts };
  108. }
  109. for (var opt in opts) {
  110. if (opts.hasOwnProperty(opt)) {
  111. this[opt](opts[opt]);
  112. }
  113. }
  114. return this;
  115. };
  116. /**
  117. * Run mocha, returning the Runner.
  118. */
  119. mocha.run = function (fn) {
  120. var options = mocha.options;
  121. mocha.globals('location');
  122. var query = Mocha.utils.parseQuery(global.location.search || '');
  123. if (query.grep) {
  124. mocha.grep(query.grep);
  125. }
  126. if (query.fgrep) {
  127. mocha.fgrep(query.fgrep);
  128. }
  129. if (query.invert) {
  130. mocha.invert();
  131. }
  132. return Mocha.prototype.run.call(mocha, function (err) {
  133. // The DOM Document is not available in Web Workers.
  134. var document = global.document;
  135. if (document && document.getElementById('mocha') && options.noHighlighting !== true) {
  136. Mocha.utils.highlightTags('code');
  137. }
  138. if (fn) {
  139. fn(err);
  140. }
  141. });
  142. };
  143. /**
  144. * Expose the process shim.
  145. * https://github.com/mochajs/mocha/pull/916
  146. */
  147. Mocha.process = process;
  148. /**
  149. * Expose mocha.
  150. */
  151. global.Mocha = Mocha;
  152. global.mocha = mocha;
  153. // this allows test/acceptance/required-tokens.js to pass; thus,
  154. // you can now do `const describe = require('mocha').describe` in a
  155. // browser context (assuming browserification). should fix #880
  156. module.exports = global;
  157. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  158. },{"./lib/mocha":14,"_process":82,"browser-stdout":41}],2:[function(require,module,exports){
  159. 'use strict';
  160. function noop () {}
  161. module.exports = function () {
  162. return noop;
  163. };
  164. },{}],3:[function(require,module,exports){
  165. 'use strict';
  166. /**
  167. * Module exports.
  168. */
  169. exports.EventEmitter = EventEmitter;
  170. /**
  171. * Object#toString reference.
  172. */
  173. var objToString = Object.prototype.toString;
  174. /**
  175. * Check if a value is an array.
  176. *
  177. * @api private
  178. * @param {*} val The value to test.
  179. * @return {boolean} true if the value is an array, otherwise false.
  180. */
  181. function isArray (val) {
  182. return objToString.call(val) === '[object Array]';
  183. }
  184. /**
  185. * Event emitter constructor.
  186. *
  187. * @api public
  188. */
  189. function EventEmitter () {}
  190. /**
  191. * Add a listener.
  192. *
  193. * @api public
  194. * @param {string} name Event name.
  195. * @param {Function} fn Event handler.
  196. * @return {EventEmitter} Emitter instance.
  197. */
  198. EventEmitter.prototype.on = function (name, fn) {
  199. if (!this.$events) {
  200. this.$events = {};
  201. }
  202. if (!this.$events[name]) {
  203. this.$events[name] = fn;
  204. } else if (isArray(this.$events[name])) {
  205. this.$events[name].push(fn);
  206. } else {
  207. this.$events[name] = [this.$events[name], fn];
  208. }
  209. return this;
  210. };
  211. EventEmitter.prototype.addListener = EventEmitter.prototype.on;
  212. /**
  213. * Adds a volatile listener.
  214. *
  215. * @api public
  216. * @param {string} name Event name.
  217. * @param {Function} fn Event handler.
  218. * @return {EventEmitter} Emitter instance.
  219. */
  220. EventEmitter.prototype.once = function (name, fn) {
  221. var self = this;
  222. function on () {
  223. self.removeListener(name, on);
  224. fn.apply(this, arguments);
  225. }
  226. on.listener = fn;
  227. this.on(name, on);
  228. return this;
  229. };
  230. /**
  231. * Remove a listener.
  232. *
  233. * @api public
  234. * @param {string} name Event name.
  235. * @param {Function} fn Event handler.
  236. * @return {EventEmitter} Emitter instance.
  237. */
  238. EventEmitter.prototype.removeListener = function (name, fn) {
  239. if (this.$events && this.$events[name]) {
  240. var list = this.$events[name];
  241. if (isArray(list)) {
  242. var pos = -1;
  243. for (var i = 0, l = list.length; i < l; i++) {
  244. if (list[i] === fn || (list[i].listener && list[i].listener === fn)) {
  245. pos = i;
  246. break;
  247. }
  248. }
  249. if (pos < 0) {
  250. return this;
  251. }
  252. list.splice(pos, 1);
  253. if (!list.length) {
  254. delete this.$events[name];
  255. }
  256. } else if (list === fn || (list.listener && list.listener === fn)) {
  257. delete this.$events[name];
  258. }
  259. }
  260. return this;
  261. };
  262. /**
  263. * Remove all listeners for an event.
  264. *
  265. * @api public
  266. * @param {string} name Event name.
  267. * @return {EventEmitter} Emitter instance.
  268. */
  269. EventEmitter.prototype.removeAllListeners = function (name) {
  270. if (name === undefined) {
  271. this.$events = {};
  272. return this;
  273. }
  274. if (this.$events && this.$events[name]) {
  275. this.$events[name] = null;
  276. }
  277. return this;
  278. };
  279. /**
  280. * Get all listeners for a given event.
  281. *
  282. * @api public
  283. * @param {string} name Event name.
  284. * @return {EventEmitter} Emitter instance.
  285. */
  286. EventEmitter.prototype.listeners = function (name) {
  287. if (!this.$events) {
  288. this.$events = {};
  289. }
  290. if (!this.$events[name]) {
  291. this.$events[name] = [];
  292. }
  293. if (!isArray(this.$events[name])) {
  294. this.$events[name] = [this.$events[name]];
  295. }
  296. return this.$events[name];
  297. };
  298. /**
  299. * Emit an event.
  300. *
  301. * @api public
  302. * @param {string} name Event name.
  303. * @return {boolean} true if at least one handler was invoked, else false.
  304. */
  305. EventEmitter.prototype.emit = function (name) {
  306. if (!this.$events) {
  307. return false;
  308. }
  309. var handler = this.$events[name];
  310. if (!handler) {
  311. return false;
  312. }
  313. var args = Array.prototype.slice.call(arguments, 1);
  314. if (typeof handler === 'function') {
  315. handler.apply(this, args);
  316. } else if (isArray(handler)) {
  317. var listeners = handler.slice();
  318. for (var i = 0, l = listeners.length; i < l; i++) {
  319. listeners[i].apply(this, args);
  320. }
  321. } else {
  322. return false;
  323. }
  324. return true;
  325. };
  326. },{}],4:[function(require,module,exports){
  327. 'use strict';
  328. /**
  329. * Expose `Progress`.
  330. */
  331. module.exports = Progress;
  332. /**
  333. * Initialize a new `Progress` indicator.
  334. */
  335. function Progress () {
  336. this.percent = 0;
  337. this.size(0);
  338. this.fontSize(11);
  339. this.font('helvetica, arial, sans-serif');
  340. }
  341. /**
  342. * Set progress size to `size`.
  343. *
  344. * @api public
  345. * @param {number} size
  346. * @return {Progress} Progress instance.
  347. */
  348. Progress.prototype.size = function (size) {
  349. this._size = size;
  350. return this;
  351. };
  352. /**
  353. * Set text to `text`.
  354. *
  355. * @api public
  356. * @param {string} text
  357. * @return {Progress} Progress instance.
  358. */
  359. Progress.prototype.text = function (text) {
  360. this._text = text;
  361. return this;
  362. };
  363. /**
  364. * Set font size to `size`.
  365. *
  366. * @api public
  367. * @param {number} size
  368. * @return {Progress} Progress instance.
  369. */
  370. Progress.prototype.fontSize = function (size) {
  371. this._fontSize = size;
  372. return this;
  373. };
  374. /**
  375. * Set font to `family`.
  376. *
  377. * @param {string} family
  378. * @return {Progress} Progress instance.
  379. */
  380. Progress.prototype.font = function (family) {
  381. this._font = family;
  382. return this;
  383. };
  384. /**
  385. * Update percentage to `n`.
  386. *
  387. * @param {number} n
  388. * @return {Progress} Progress instance.
  389. */
  390. Progress.prototype.update = function (n) {
  391. this.percent = n;
  392. return this;
  393. };
  394. /**
  395. * Draw on `ctx`.
  396. *
  397. * @param {CanvasRenderingContext2d} ctx
  398. * @return {Progress} Progress instance.
  399. */
  400. Progress.prototype.draw = function (ctx) {
  401. try {
  402. var percent = Math.min(this.percent, 100);
  403. var size = this._size;
  404. var half = size / 2;
  405. var x = half;
  406. var y = half;
  407. var rad = half - 1;
  408. var fontSize = this._fontSize;
  409. ctx.font = fontSize + 'px ' + this._font;
  410. var angle = Math.PI * 2 * (percent / 100);
  411. ctx.clearRect(0, 0, size, size);
  412. // outer circle
  413. ctx.strokeStyle = '#9f9f9f';
  414. ctx.beginPath();
  415. ctx.arc(x, y, rad, 0, angle, false);
  416. ctx.stroke();
  417. // inner circle
  418. ctx.strokeStyle = '#eee';
  419. ctx.beginPath();
  420. ctx.arc(x, y, rad - 1, 0, angle, true);
  421. ctx.stroke();
  422. // text
  423. var text = this._text || (percent | 0) + '%';
  424. var w = ctx.measureText(text).width;
  425. ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1);
  426. } catch (err) {
  427. // don't fail if we can't render progress
  428. }
  429. return this;
  430. };
  431. },{}],5:[function(require,module,exports){
  432. (function (global){
  433. 'use strict';
  434. exports.isatty = function isatty () {
  435. return true;
  436. };
  437. exports.getWindowSize = function getWindowSize () {
  438. if ('innerHeight' in global) {
  439. return [global.innerHeight, global.innerWidth];
  440. }
  441. // In a Web Worker, the DOM Window is not available.
  442. return [640, 480];
  443. };
  444. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  445. },{}],6:[function(require,module,exports){
  446. 'use strict';
  447. /**
  448. * Module dependencies.
  449. */
  450. var JSON = require('json3');
  451. /**
  452. * Expose `Context`.
  453. */
  454. module.exports = Context;
  455. /**
  456. * Initialize a new `Context`.
  457. *
  458. * @api private
  459. */
  460. function Context () {}
  461. /**
  462. * Set or get the context `Runnable` to `runnable`.
  463. *
  464. * @api private
  465. * @param {Runnable} runnable
  466. * @return {Context}
  467. */
  468. Context.prototype.runnable = function (runnable) {
  469. if (!arguments.length) {
  470. return this._runnable;
  471. }
  472. this.test = this._runnable = runnable;
  473. return this;
  474. };
  475. /**
  476. * Set test timeout `ms`.
  477. *
  478. * @api private
  479. * @param {number} ms
  480. * @return {Context} self
  481. */
  482. Context.prototype.timeout = function (ms) {
  483. if (!arguments.length) {
  484. return this.runnable().timeout();
  485. }
  486. this.runnable().timeout(ms);
  487. return this;
  488. };
  489. /**
  490. * Set test timeout `enabled`.
  491. *
  492. * @api private
  493. * @param {boolean} enabled
  494. * @return {Context} self
  495. */
  496. Context.prototype.enableTimeouts = function (enabled) {
  497. this.runnable().enableTimeouts(enabled);
  498. return this;
  499. };
  500. /**
  501. * Set test slowness threshold `ms`.
  502. *
  503. * @api private
  504. * @param {number} ms
  505. * @return {Context} self
  506. */
  507. Context.prototype.slow = function (ms) {
  508. this.runnable().slow(ms);
  509. return this;
  510. };
  511. /**
  512. * Mark a test as skipped.
  513. *
  514. * @api private
  515. * @return {Context} self
  516. */
  517. Context.prototype.skip = function () {
  518. this.runnable().skip();
  519. return this;
  520. };
  521. /**
  522. * Allow a number of retries on failed tests
  523. *
  524. * @api private
  525. * @param {number} n
  526. * @return {Context} self
  527. */
  528. Context.prototype.retries = function (n) {
  529. if (!arguments.length) {
  530. return this.runnable().retries();
  531. }
  532. this.runnable().retries(n);
  533. return this;
  534. };
  535. /**
  536. * Inspect the context void of `._runnable`.
  537. *
  538. * @api private
  539. * @return {string}
  540. */
  541. Context.prototype.inspect = function () {
  542. return JSON.stringify(this, function (key, val) {
  543. return key === 'runnable' || key === 'test' ? undefined : val;
  544. }, 2);
  545. };
  546. },{"json3":69}],7:[function(require,module,exports){
  547. 'use strict';
  548. /**
  549. * Module dependencies.
  550. */
  551. var Runnable = require('./runnable');
  552. var inherits = require('./utils').inherits;
  553. /**
  554. * Expose `Hook`.
  555. */
  556. module.exports = Hook;
  557. /**
  558. * Initialize a new `Hook` with the given `title` and callback `fn`.
  559. *
  560. * @param {String} title
  561. * @param {Function} fn
  562. * @api private
  563. */
  564. function Hook (title, fn) {
  565. Runnable.call(this, title, fn);
  566. this.type = 'hook';
  567. }
  568. /**
  569. * Inherit from `Runnable.prototype`.
  570. */
  571. inherits(Hook, Runnable);
  572. /**
  573. * Get or set the test `err`.
  574. *
  575. * @param {Error} err
  576. * @return {Error}
  577. * @api public
  578. */
  579. Hook.prototype.error = function (err) {
  580. if (!arguments.length) {
  581. err = this._error;
  582. this._error = null;
  583. return err;
  584. }
  585. this._error = err;
  586. };
  587. },{"./runnable":33,"./utils":38}],8:[function(require,module,exports){
  588. 'use strict';
  589. /**
  590. * Module dependencies.
  591. */
  592. var Test = require('../test');
  593. /**
  594. * BDD-style interface:
  595. *
  596. * describe('Array', function() {
  597. * describe('#indexOf()', function() {
  598. * it('should return -1 when not present', function() {
  599. * // ...
  600. * });
  601. *
  602. * it('should return the index when present', function() {
  603. * // ...
  604. * });
  605. * });
  606. * });
  607. *
  608. * @param {Suite} suite Root suite.
  609. */
  610. module.exports = function (suite) {
  611. var suites = [suite];
  612. suite.on('pre-require', function (context, file, mocha) {
  613. var common = require('./common')(suites, context, mocha);
  614. context.before = common.before;
  615. context.after = common.after;
  616. context.beforeEach = common.beforeEach;
  617. context.afterEach = common.afterEach;
  618. context.run = mocha.options.delay && common.runWithSuite(suite);
  619. /**
  620. * Describe a "suite" with the given `title`
  621. * and callback `fn` containing nested suites
  622. * and/or tests.
  623. */
  624. context.describe = context.context = function (title, fn) {
  625. return common.suite.create({
  626. title: title,
  627. file: file,
  628. fn: fn
  629. });
  630. };
  631. /**
  632. * Pending describe.
  633. */
  634. context.xdescribe = context.xcontext = context.describe.skip = function (title, fn) {
  635. return common.suite.skip({
  636. title: title,
  637. file: file,
  638. fn: fn
  639. });
  640. };
  641. /**
  642. * Exclusive suite.
  643. */
  644. context.describe.only = function (title, fn) {
  645. return common.suite.only({
  646. title: title,
  647. file: file,
  648. fn: fn
  649. });
  650. };
  651. /**
  652. * Describe a specification or test-case
  653. * with the given `title` and callback `fn`
  654. * acting as a thunk.
  655. */
  656. context.it = context.specify = function (title, fn) {
  657. var suite = suites[0];
  658. if (suite.isPending()) {
  659. fn = null;
  660. }
  661. var test = new Test(title, fn);
  662. test.file = file;
  663. suite.addTest(test);
  664. return test;
  665. };
  666. /**
  667. * Exclusive test-case.
  668. */
  669. context.it.only = function (title, fn) {
  670. return common.test.only(mocha, context.it(title, fn));
  671. };
  672. /**
  673. * Pending test case.
  674. */
  675. context.xit = context.xspecify = context.it.skip = function (title) {
  676. context.it(title);
  677. };
  678. /**
  679. * Number of attempts to retry.
  680. */
  681. context.it.retries = function (n) {
  682. context.retries(n);
  683. };
  684. });
  685. };
  686. },{"../test":36,"./common":9}],9:[function(require,module,exports){
  687. 'use strict';
  688. var Suite = require('../suite');
  689. /**
  690. * Functions common to more than one interface.
  691. *
  692. * @param {Suite[]} suites
  693. * @param {Context} context
  694. * @param {Mocha} mocha
  695. * @return {Object} An object containing common functions.
  696. */
  697. module.exports = function (suites, context, mocha) {
  698. return {
  699. /**
  700. * This is only present if flag --delay is passed into Mocha. It triggers
  701. * root suite execution.
  702. *
  703. * @param {Suite} suite The root suite.
  704. * @return {Function} A function which runs the root suite
  705. */
  706. runWithSuite: function runWithSuite (suite) {
  707. return function run () {
  708. suite.run();
  709. };
  710. },
  711. /**
  712. * Execute before running tests.
  713. *
  714. * @param {string} name
  715. * @param {Function} fn
  716. */
  717. before: function (name, fn) {
  718. suites[0].beforeAll(name, fn);
  719. },
  720. /**
  721. * Execute after running tests.
  722. *
  723. * @param {string} name
  724. * @param {Function} fn
  725. */
  726. after: function (name, fn) {
  727. suites[0].afterAll(name, fn);
  728. },
  729. /**
  730. * Execute before each test case.
  731. *
  732. * @param {string} name
  733. * @param {Function} fn
  734. */
  735. beforeEach: function (name, fn) {
  736. suites[0].beforeEach(name, fn);
  737. },
  738. /**
  739. * Execute after each test case.
  740. *
  741. * @param {string} name
  742. * @param {Function} fn
  743. */
  744. afterEach: function (name, fn) {
  745. suites[0].afterEach(name, fn);
  746. },
  747. suite: {
  748. /**
  749. * Create an exclusive Suite; convenience function
  750. * See docstring for create() below.
  751. *
  752. * @param {Object} opts
  753. * @returns {Suite}
  754. */
  755. only: function only (opts) {
  756. mocha.options.hasOnly = true;
  757. opts.isOnly = true;
  758. return this.create(opts);
  759. },
  760. /**
  761. * Create a Suite, but skip it; convenience function
  762. * See docstring for create() below.
  763. *
  764. * @param {Object} opts
  765. * @returns {Suite}
  766. */
  767. skip: function skip (opts) {
  768. opts.pending = true;
  769. return this.create(opts);
  770. },
  771. /**
  772. * Creates a suite.
  773. * @param {Object} opts Options
  774. * @param {string} opts.title Title of Suite
  775. * @param {Function} [opts.fn] Suite Function (not always applicable)
  776. * @param {boolean} [opts.pending] Is Suite pending?
  777. * @param {string} [opts.file] Filepath where this Suite resides
  778. * @param {boolean} [opts.isOnly] Is Suite exclusive?
  779. * @returns {Suite}
  780. */
  781. create: function create (opts) {
  782. var suite = Suite.create(suites[0], opts.title);
  783. suite.pending = Boolean(opts.pending);
  784. suite.file = opts.file;
  785. suites.unshift(suite);
  786. if (opts.isOnly) {
  787. suite.parent._onlySuites = suite.parent._onlySuites.concat(suite);
  788. mocha.options.hasOnly = true;
  789. }
  790. if (typeof opts.fn === 'function') {
  791. opts.fn.call(suite);
  792. suites.shift();
  793. } else if (typeof opts.fn === 'undefined' && !suite.pending) {
  794. throw new Error('Suite "' + suite.fullTitle() + '" was defined but no callback was supplied. Supply a callback or explicitly skip the suite.');
  795. }
  796. return suite;
  797. }
  798. },
  799. test: {
  800. /**
  801. * Exclusive test-case.
  802. *
  803. * @param {Object} mocha
  804. * @param {Function} test
  805. * @returns {*}
  806. */
  807. only: function (mocha, test) {
  808. test.parent._onlyTests = test.parent._onlyTests.concat(test);
  809. mocha.options.hasOnly = true;
  810. return test;
  811. },
  812. /**
  813. * Pending test case.
  814. *
  815. * @param {string} title
  816. */
  817. skip: function (title) {
  818. context.test(title);
  819. },
  820. /**
  821. * Number of retry attempts
  822. *
  823. * @param {number} n
  824. */
  825. retries: function (n) {
  826. context.retries(n);
  827. }
  828. }
  829. };
  830. };
  831. },{"../suite":35}],10:[function(require,module,exports){
  832. 'use strict';
  833. /**
  834. * Module dependencies.
  835. */
  836. var Suite = require('../suite');
  837. var Test = require('../test');
  838. /**
  839. * Exports-style (as Node.js module) interface:
  840. *
  841. * exports.Array = {
  842. * '#indexOf()': {
  843. * 'should return -1 when the value is not present': function() {
  844. *
  845. * },
  846. *
  847. * 'should return the correct index when the value is present': function() {
  848. *
  849. * }
  850. * }
  851. * };
  852. *
  853. * @param {Suite} suite Root suite.
  854. */
  855. module.exports = function (suite) {
  856. var suites = [suite];
  857. suite.on('require', visit);
  858. function visit (obj, file) {
  859. var suite;
  860. for (var key in obj) {
  861. if (typeof obj[key] === 'function') {
  862. var fn = obj[key];
  863. switch (key) {
  864. case 'before':
  865. suites[0].beforeAll(fn);
  866. break;
  867. case 'after':
  868. suites[0].afterAll(fn);
  869. break;
  870. case 'beforeEach':
  871. suites[0].beforeEach(fn);
  872. break;
  873. case 'afterEach':
  874. suites[0].afterEach(fn);
  875. break;
  876. default:
  877. var test = new Test(key, fn);
  878. test.file = file;
  879. suites[0].addTest(test);
  880. }
  881. } else {
  882. suite = Suite.create(suites[0], key);
  883. suites.unshift(suite);
  884. visit(obj[key], file);
  885. suites.shift();
  886. }
  887. }
  888. }
  889. };
  890. },{"../suite":35,"../test":36}],11:[function(require,module,exports){
  891. 'use strict';
  892. exports.bdd = require('./bdd');
  893. exports.tdd = require('./tdd');
  894. exports.qunit = require('./qunit');
  895. exports.exports = require('./exports');
  896. },{"./bdd":8,"./exports":10,"./qunit":12,"./tdd":13}],12:[function(require,module,exports){
  897. 'use strict';
  898. /**
  899. * Module dependencies.
  900. */
  901. var Test = require('../test');
  902. /**
  903. * QUnit-style interface:
  904. *
  905. * suite('Array');
  906. *
  907. * test('#length', function() {
  908. * var arr = [1,2,3];
  909. * ok(arr.length == 3);
  910. * });
  911. *
  912. * test('#indexOf()', function() {
  913. * var arr = [1,2,3];
  914. * ok(arr.indexOf(1) == 0);
  915. * ok(arr.indexOf(2) == 1);
  916. * ok(arr.indexOf(3) == 2);
  917. * });
  918. *
  919. * suite('String');
  920. *
  921. * test('#length', function() {
  922. * ok('foo'.length == 3);
  923. * });
  924. *
  925. * @param {Suite} suite Root suite.
  926. */
  927. module.exports = function (suite) {
  928. var suites = [suite];
  929. suite.on('pre-require', function (context, file, mocha) {
  930. var common = require('./common')(suites, context, mocha);
  931. context.before = common.before;
  932. context.after = common.after;
  933. context.beforeEach = common.beforeEach;
  934. context.afterEach = common.afterEach;
  935. context.run = mocha.options.delay && common.runWithSuite(suite);
  936. /**
  937. * Describe a "suite" with the given `title`.
  938. */
  939. context.suite = function (title) {
  940. if (suites.length > 1) {
  941. suites.shift();
  942. }
  943. return common.suite.create({
  944. title: title,
  945. file: file,
  946. fn: false
  947. });
  948. };
  949. /**
  950. * Exclusive Suite.
  951. */
  952. context.suite.only = function (title) {
  953. if (suites.length > 1) {
  954. suites.shift();
  955. }
  956. return common.suite.only({
  957. title: title,
  958. file: file,
  959. fn: false
  960. });
  961. };
  962. /**
  963. * Describe a specification or test-case
  964. * with the given `title` and callback `fn`
  965. * acting as a thunk.
  966. */
  967. context.test = function (title, fn) {
  968. var test = new Test(title, fn);
  969. test.file = file;
  970. suites[0].addTest(test);
  971. return test;
  972. };
  973. /**
  974. * Exclusive test-case.
  975. */
  976. context.test.only = function (title, fn) {
  977. return common.test.only(mocha, context.test(title, fn));
  978. };
  979. context.test.skip = common.test.skip;
  980. context.test.retries = common.test.retries;
  981. });
  982. };
  983. },{"../test":36,"./common":9}],13:[function(require,module,exports){
  984. 'use strict';
  985. /**
  986. * Module dependencies.
  987. */
  988. var Test = require('../test');
  989. /**
  990. * TDD-style interface:
  991. *
  992. * suite('Array', function() {
  993. * suite('#indexOf()', function() {
  994. * suiteSetup(function() {
  995. *
  996. * });
  997. *
  998. * test('should return -1 when not present', function() {
  999. *
  1000. * });
  1001. *
  1002. * test('should return the index when present', function() {
  1003. *
  1004. * });
  1005. *
  1006. * suiteTeardown(function() {
  1007. *
  1008. * });
  1009. * });
  1010. * });
  1011. *
  1012. * @param {Suite} suite Root suite.
  1013. */
  1014. module.exports = function (suite) {
  1015. var suites = [suite];
  1016. suite.on('pre-require', function (context, file, mocha) {
  1017. var common = require('./common')(suites, context, mocha);
  1018. context.setup = common.beforeEach;
  1019. context.teardown = common.afterEach;
  1020. context.suiteSetup = common.before;
  1021. context.suiteTeardown = common.after;
  1022. context.run = mocha.options.delay && common.runWithSuite(suite);
  1023. /**
  1024. * Describe a "suite" with the given `title` and callback `fn` containing
  1025. * nested suites and/or tests.
  1026. */
  1027. context.suite = function (title, fn) {
  1028. return common.suite.create({
  1029. title: title,
  1030. file: file,
  1031. fn: fn
  1032. });
  1033. };
  1034. /**
  1035. * Pending suite.
  1036. */
  1037. context.suite.skip = function (title, fn) {
  1038. return common.suite.skip({
  1039. title: title,
  1040. file: file,
  1041. fn: fn
  1042. });
  1043. };
  1044. /**
  1045. * Exclusive test-case.
  1046. */
  1047. context.suite.only = function (title, fn) {
  1048. return common.suite.only({
  1049. title: title,
  1050. file: file,
  1051. fn: fn
  1052. });
  1053. };
  1054. /**
  1055. * Describe a specification or test-case with the given `title` and
  1056. * callback `fn` acting as a thunk.
  1057. */
  1058. context.test = function (title, fn) {
  1059. var suite = suites[0];
  1060. if (suite.isPending()) {
  1061. fn = null;
  1062. }
  1063. var test = new Test(title, fn);
  1064. test.file = file;
  1065. suite.addTest(test);
  1066. return test;
  1067. };
  1068. /**
  1069. * Exclusive test-case.
  1070. */
  1071. context.test.only = function (title, fn) {
  1072. return common.test.only(mocha, context.test(title, fn));
  1073. };
  1074. context.test.skip = common.test.skip;
  1075. context.test.retries = common.test.retries;
  1076. });
  1077. };
  1078. },{"../test":36,"./common":9}],14:[function(require,module,exports){
  1079. (function (process,global,__dirname){
  1080. 'use strict';
  1081. /*!
  1082. * mocha
  1083. * Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
  1084. * MIT Licensed
  1085. */
  1086. /**
  1087. * Module dependencies.
  1088. */
  1089. var escapeRe = require('escape-string-regexp');
  1090. var path = require('path');
  1091. var reporters = require('./reporters');
  1092. var utils = require('./utils');
  1093. /**
  1094. * Expose `Mocha`.
  1095. */
  1096. exports = module.exports = Mocha;
  1097. /**
  1098. * To require local UIs and reporters when running in node.
  1099. */
  1100. if (!process.browser) {
  1101. var cwd = process.cwd();
  1102. module.paths.push(cwd, path.join(cwd, 'node_modules'));
  1103. }
  1104. /**
  1105. * Expose internals.
  1106. */
  1107. exports.utils = utils;
  1108. exports.interfaces = require('./interfaces');
  1109. exports.reporters = reporters;
  1110. exports.Runnable = require('./runnable');
  1111. exports.Context = require('./context');
  1112. exports.Runner = require('./runner');
  1113. exports.Suite = require('./suite');
  1114. exports.Hook = require('./hook');
  1115. exports.Test = require('./test');
  1116. /**
  1117. * Return image `name` path.
  1118. *
  1119. * @api private
  1120. * @param {string} name
  1121. * @return {string}
  1122. */
  1123. function image (name) {
  1124. return path.join(__dirname, '../images', name + '.png');
  1125. }
  1126. /**
  1127. * Set up mocha with `options`.
  1128. *
  1129. * Options:
  1130. *
  1131. * - `ui` name "bdd", "tdd", "exports" etc
  1132. * - `reporter` reporter instance, defaults to `mocha.reporters.spec`
  1133. * - `globals` array of accepted globals
  1134. * - `timeout` timeout in milliseconds
  1135. * - `retries` number of times to retry failed tests
  1136. * - `bail` bail on the first test failure
  1137. * - `slow` milliseconds to wait before considering a test slow
  1138. * - `ignoreLeaks` ignore global leaks
  1139. * - `fullTrace` display the full stack-trace on failing
  1140. * - `grep` string or regexp to filter tests with
  1141. *
  1142. * @param {Object} options
  1143. * @api public
  1144. */
  1145. function Mocha (options) {
  1146. options = options || {};
  1147. this.files = [];
  1148. this.options = options;
  1149. if (options.grep) {
  1150. this.grep(new RegExp(options.grep));
  1151. }
  1152. if (options.fgrep) {
  1153. this.fgrep(options.fgrep);
  1154. }
  1155. this.suite = new exports.Suite('', new exports.Context());
  1156. this.ui(options.ui);
  1157. this.bail(options.bail);
  1158. this.reporter(options.reporter, options.reporterOptions);
  1159. if (typeof options.timeout !== 'undefined' && options.timeout !== null) {
  1160. this.timeout(options.timeout);
  1161. }
  1162. if (typeof options.retries !== 'undefined' && options.retries !== null) {
  1163. this.retries(options.retries);
  1164. }
  1165. this.useColors(options.useColors);
  1166. if (options.enableTimeouts !== null) {
  1167. this.enableTimeouts(options.enableTimeouts);
  1168. }
  1169. if (options.slow) {
  1170. this.slow(options.slow);
  1171. }
  1172. }
  1173. /**
  1174. * Enable or disable bailing on the first failure.
  1175. *
  1176. * @api public
  1177. * @param {boolean} [bail]
  1178. */
  1179. Mocha.prototype.bail = function (bail) {
  1180. if (!arguments.length) {
  1181. bail = true;
  1182. }
  1183. this.suite.bail(bail);
  1184. return this;
  1185. };
  1186. /**
  1187. * Add test `file`.
  1188. *
  1189. * @api public
  1190. * @param {string} file
  1191. */
  1192. Mocha.prototype.addFile = function (file) {
  1193. this.files.push(file);
  1194. return this;
  1195. };
  1196. /**
  1197. * Set reporter to `reporter`, defaults to "spec".
  1198. *
  1199. * @param {String|Function} reporter name or constructor
  1200. * @param {Object} reporterOptions optional options
  1201. * @api public
  1202. * @param {string|Function} reporter name or constructor
  1203. * @param {Object} reporterOptions optional options
  1204. */
  1205. Mocha.prototype.reporter = function (reporter, reporterOptions) {
  1206. if (typeof reporter === 'function') {
  1207. this._reporter = reporter;
  1208. } else {
  1209. reporter = reporter || 'spec';
  1210. var _reporter;
  1211. // Try to load a built-in reporter.
  1212. if (reporters[reporter]) {
  1213. _reporter = reporters[reporter];
  1214. }
  1215. // Try to load reporters from process.cwd() and node_modules
  1216. if (!_reporter) {
  1217. try {
  1218. _reporter = require(reporter);
  1219. } catch (err) {
  1220. if (err.message.indexOf('Cannot find module') !== -1) {
  1221. // Try to load reporters from a path (absolute or relative)
  1222. try {
  1223. _reporter = require(path.resolve(process.cwd(), reporter));
  1224. } catch (_err) {
  1225. err.message.indexOf('Cannot find module') !== -1 ? console.warn('"' + reporter + '" reporter not found')
  1226. : console.warn('"' + reporter + '" reporter blew up with error:\n' + err.stack);
  1227. }
  1228. } else {
  1229. console.warn('"' + reporter + '" reporter blew up with error:\n' + err.stack);
  1230. }
  1231. }
  1232. }
  1233. if (!_reporter && reporter === 'teamcity') {
  1234. console.warn('The Teamcity reporter was moved to a package named ' +
  1235. 'mocha-teamcity-reporter ' +
  1236. '(https://npmjs.org/package/mocha-teamcity-reporter).');
  1237. }
  1238. if (!_reporter) {
  1239. throw new Error('invalid reporter "' + reporter + '"');
  1240. }
  1241. this._reporter = _reporter;
  1242. }
  1243. this.options.reporterOptions = reporterOptions;
  1244. return this;
  1245. };
  1246. /**
  1247. * Set test UI `name`, defaults to "bdd".
  1248. *
  1249. * @api public
  1250. * @param {string} bdd
  1251. */
  1252. Mocha.prototype.ui = function (name) {
  1253. name = name || 'bdd';
  1254. this._ui = exports.interfaces[name];
  1255. if (!this._ui) {
  1256. try {
  1257. this._ui = require(name);
  1258. } catch (err) {
  1259. throw new Error('invalid interface "' + name + '"');
  1260. }
  1261. }
  1262. this._ui = this._ui(this.suite);
  1263. this.suite.on('pre-require', function (context) {
  1264. exports.afterEach = context.afterEach || context.teardown;
  1265. exports.after = context.after || context.suiteTeardown;
  1266. exports.beforeEach = context.beforeEach || context.setup;
  1267. exports.before = context.before || context.suiteSetup;
  1268. exports.describe = context.describe || context.suite;
  1269. exports.it = context.it || context.test;
  1270. exports.setup = context.setup || context.beforeEach;
  1271. exports.suiteSetup = context.suiteSetup || context.before;
  1272. exports.suiteTeardown = context.suiteTeardown || context.after;
  1273. exports.suite = context.suite || context.describe;
  1274. exports.teardown = context.teardown || context.afterEach;
  1275. exports.test = context.test || context.it;
  1276. exports.run = context.run;
  1277. });
  1278. return this;
  1279. };
  1280. /**
  1281. * Load registered files.
  1282. *
  1283. * @api private
  1284. */
  1285. Mocha.prototype.loadFiles = function (fn) {
  1286. var self = this;
  1287. var suite = this.suite;
  1288. this.files.forEach(function (file) {
  1289. file = path.resolve(file);
  1290. suite.emit('pre-require', global, file, self);
  1291. suite.emit('require', require(file), file, self);
  1292. suite.emit('post-require', global, file, self);
  1293. });
  1294. fn && fn();
  1295. };
  1296. /**
  1297. * Enable growl support.
  1298. *
  1299. * @api private
  1300. */
  1301. Mocha.prototype._growl = function (runner, reporter) {
  1302. var notify = require('growl');
  1303. runner.on('end', function () {
  1304. var stats = reporter.stats;
  1305. if (stats.failures) {
  1306. var msg = stats.failures + ' of ' + runner.total + ' tests failed';
  1307. notify(msg, { name: 'mocha', title: 'Failed', image: image('error') });
  1308. } else {
  1309. notify(stats.passes + ' tests passed in ' + stats.duration + 'ms', {
  1310. name: 'mocha',
  1311. title: 'Passed',
  1312. image: image('ok')
  1313. });
  1314. }
  1315. });
  1316. };
  1317. /**
  1318. * Escape string and add it to grep as a regexp.
  1319. *
  1320. * @api public
  1321. * @param str
  1322. * @returns {Mocha}
  1323. */
  1324. Mocha.prototype.fgrep = function (str) {
  1325. return this.grep(new RegExp(escapeRe(str)));
  1326. };
  1327. /**
  1328. * Add regexp to grep, if `re` is a string it is escaped.
  1329. *
  1330. * @param {RegExp|String} re
  1331. * @return {Mocha}
  1332. * @api public
  1333. * @param {RegExp|string} re
  1334. * @return {Mocha}
  1335. */
  1336. Mocha.prototype.grep = function (re) {
  1337. if (utils.isString(re)) {
  1338. // extract args if it's regex-like, i.e: [string, pattern, flag]
  1339. var arg = re.match(/^\/(.*)\/(g|i|)$|.*/);
  1340. this.options.grep = new RegExp(arg[1] || arg[0], arg[2]);
  1341. } else {
  1342. this.options.grep = re;
  1343. }
  1344. return this;
  1345. };
  1346. /**
  1347. * Invert `.grep()` matches.
  1348. *
  1349. * @return {Mocha}
  1350. * @api public
  1351. */
  1352. Mocha.prototype.invert = function () {
  1353. this.options.invert = true;
  1354. return this;
  1355. };
  1356. /**
  1357. * Ignore global leaks.
  1358. *
  1359. * @param {Boolean} ignore
  1360. * @return {Mocha}
  1361. * @api public
  1362. * @param {boolean} ignore
  1363. * @return {Mocha}
  1364. */
  1365. Mocha.prototype.ignoreLeaks = function (ignore) {
  1366. this.options.ignoreLeaks = Boolean(ignore);
  1367. return this;
  1368. };
  1369. /**
  1370. * Enable global leak checking.
  1371. *
  1372. * @return {Mocha}
  1373. * @api public
  1374. */
  1375. Mocha.prototype.checkLeaks = function () {
  1376. this.options.ignoreLeaks = false;
  1377. return this;
  1378. };
  1379. /**
  1380. * Display long stack-trace on failing
  1381. *
  1382. * @return {Mocha}
  1383. * @api public
  1384. */
  1385. Mocha.prototype.fullTrace = function () {
  1386. this.options.fullStackTrace = true;
  1387. return this;
  1388. };
  1389. /**
  1390. * Enable growl support.
  1391. *
  1392. * @return {Mocha}
  1393. * @api public
  1394. */
  1395. Mocha.prototype.growl = function () {
  1396. this.options.growl = true;
  1397. return this;
  1398. };
  1399. /**
  1400. * Ignore `globals` array or string.
  1401. *
  1402. * @param {Array|String} globals
  1403. * @return {Mocha}
  1404. * @api public
  1405. * @param {Array|string} globals
  1406. * @return {Mocha}
  1407. */
  1408. Mocha.prototype.globals = function (globals) {
  1409. this.options.globals = (this.options.globals || []).concat(globals);
  1410. return this;
  1411. };
  1412. /**
  1413. * Emit color output.
  1414. *
  1415. * @param {Boolean} colors
  1416. * @return {Mocha}
  1417. * @api public
  1418. * @param {boolean} colors
  1419. * @return {Mocha}
  1420. */
  1421. Mocha.prototype.useColors = function (colors) {
  1422. if (colors !== undefined) {
  1423. this.options.useColors = colors;
  1424. }
  1425. return this;
  1426. };
  1427. /**
  1428. * Use inline diffs rather than +/-.
  1429. *
  1430. * @param {Boolean} inlineDiffs
  1431. * @return {Mocha}
  1432. * @api public
  1433. * @param {boolean} inlineDiffs
  1434. * @return {Mocha}
  1435. */
  1436. Mocha.prototype.useInlineDiffs = function (inlineDiffs) {
  1437. this.options.useInlineDiffs = inlineDiffs !== undefined && inlineDiffs;
  1438. return this;
  1439. };
  1440. /**
  1441. * Set the timeout in milliseconds.
  1442. *
  1443. * @param {Number} timeout
  1444. * @return {Mocha}
  1445. * @api public
  1446. * @param {number} timeout
  1447. * @return {Mocha}
  1448. */
  1449. Mocha.prototype.timeout = function (timeout) {
  1450. this.suite.timeout(timeout);
  1451. return this;
  1452. };
  1453. /**
  1454. * Set the number of times to retry failed tests.
  1455. *
  1456. * @param {Number} retry times
  1457. * @return {Mocha}
  1458. * @api public
  1459. */
  1460. Mocha.prototype.retries = function (n) {
  1461. this.suite.retries(n);
  1462. return this;
  1463. };
  1464. /**
  1465. * Set slowness threshold in milliseconds.
  1466. *
  1467. * @param {Number} slow
  1468. * @return {Mocha}
  1469. * @api public
  1470. * @param {number} slow
  1471. * @return {Mocha}
  1472. */
  1473. Mocha.prototype.slow = function (slow) {
  1474. this.suite.slow(slow);
  1475. return this;
  1476. };
  1477. /**
  1478. * Enable timeouts.
  1479. *
  1480. * @param {Boolean} enabled
  1481. * @return {Mocha}
  1482. * @api public
  1483. * @param {boolean} enabled
  1484. * @return {Mocha}
  1485. */
  1486. Mocha.prototype.enableTimeouts = function (enabled) {
  1487. this.suite.enableTimeouts(arguments.length && enabled !== undefined ? enabled : true);
  1488. return this;
  1489. };
  1490. /**
  1491. * Makes all tests async (accepting a callback)
  1492. *
  1493. * @return {Mocha}
  1494. * @api public
  1495. */
  1496. Mocha.prototype.asyncOnly = function () {
  1497. this.options.asyncOnly = true;
  1498. return this;
  1499. };
  1500. /**
  1501. * Disable syntax highlighting (in browser).
  1502. *
  1503. * @api public
  1504. */
  1505. Mocha.prototype.noHighlighting = function () {
  1506. this.options.noHighlighting = true;
  1507. return this;
  1508. };
  1509. /**
  1510. * Enable uncaught errors to propagate (in browser).
  1511. *
  1512. * @return {Mocha}
  1513. * @api public
  1514. */
  1515. Mocha.prototype.allowUncaught = function () {
  1516. this.options.allowUncaught = true;
  1517. return this;
  1518. };
  1519. /**
  1520. * Delay root suite execution.
  1521. * @returns {Mocha}
  1522. */
  1523. Mocha.prototype.delay = function delay () {
  1524. this.options.delay = true;
  1525. return this;
  1526. };
  1527. /**
  1528. * Run tests and invoke `fn()` when complete.
  1529. *
  1530. * @api public
  1531. * @param {Function} fn
  1532. * @return {Runner}
  1533. */
  1534. Mocha.prototype.run = function (fn) {
  1535. if (this.files.length) {
  1536. this.loadFiles();
  1537. }
  1538. var suite = this.suite;
  1539. var options = this.options;
  1540. options.files = this.files;
  1541. var runner = new exports.Runner(suite, options.delay);
  1542. var reporter = new this._reporter(runner, options);
  1543. runner.ignoreLeaks = options.ignoreLeaks !== false;
  1544. runner.fullStackTrace = options.fullStackTrace;
  1545. runner.hasOnly = options.hasOnly;
  1546. runner.asyncOnly = options.asyncOnly;
  1547. runner.allowUncaught = options.allowUncaught;
  1548. if (options.grep) {
  1549. runner.grep(options.grep, options.invert);
  1550. }
  1551. if (options.globals) {
  1552. runner.globals(options.globals);
  1553. }
  1554. if (options.growl) {
  1555. this._growl(runner, reporter);
  1556. }
  1557. if (options.useColors !== undefined) {
  1558. exports.reporters.Base.useColors = options.useColors;
  1559. }
  1560. exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
  1561. function done (failures) {
  1562. if (reporter.done) {
  1563. reporter.done(failures, fn);
  1564. } else {
  1565. fn && fn(failures);
  1566. }
  1567. }
  1568. return runner.run(done);
  1569. };
  1570. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},"/lib")
  1571. },{"./context":6,"./hook":7,"./interfaces":11,"./reporters":21,"./runnable":33,"./runner":34,"./suite":35,"./test":36,"./utils":38,"_process":82,"escape-string-regexp":62,"growl":64,"path":42}],15:[function(require,module,exports){
  1572. 'use strict';
  1573. /**
  1574. * Helpers.
  1575. */
  1576. var s = 1000;
  1577. var m = s * 60;
  1578. var h = m * 60;
  1579. var d = h * 24;
  1580. var y = d * 365.25;
  1581. /**
  1582. * Parse or format the given `val`.
  1583. *
  1584. * Options:
  1585. *
  1586. * - `long` verbose formatting [false]
  1587. *
  1588. * @api public
  1589. * @param {string|number} val
  1590. * @param {Object} options
  1591. * @return {string|number}
  1592. */
  1593. module.exports = function (val, options) {
  1594. options = options || {};
  1595. if (typeof val === 'string') {
  1596. return parse(val);
  1597. }
  1598. // https://github.com/mochajs/mocha/pull/1035
  1599. return options['long'] ? longFormat(val) : shortFormat(val);
  1600. };
  1601. /**
  1602. * Parse the given `str` and return milliseconds.
  1603. *
  1604. * @api private
  1605. * @param {string} str
  1606. * @return {number}
  1607. */
  1608. function parse (str) {
  1609. var match = (/^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i).exec(str);
  1610. if (!match) {
  1611. return;
  1612. }
  1613. var n = parseFloat(match[1]);
  1614. var type = (match[2] || 'ms').toLowerCase();
  1615. switch (type) {
  1616. case 'years':
  1617. case 'year':
  1618. case 'y':
  1619. return n * y;
  1620. case 'days':
  1621. case 'day':
  1622. case 'd':
  1623. return n * d;
  1624. case 'hours':
  1625. case 'hour':
  1626. case 'h':
  1627. return n * h;
  1628. case 'minutes':
  1629. case 'minute':
  1630. case 'm':
  1631. return n * m;
  1632. case 'seconds':
  1633. case 'second':
  1634. case 's':
  1635. return n * s;
  1636. case 'ms':
  1637. return n;
  1638. default:
  1639. // No default case
  1640. }
  1641. }
  1642. /**
  1643. * Short format for `ms`.
  1644. *
  1645. * @api private
  1646. * @param {number} ms
  1647. * @return {string}
  1648. */
  1649. function shortFormat (ms) {
  1650. if (ms >= d) {
  1651. return Math.round(ms / d) + 'd';
  1652. }
  1653. if (ms >= h) {
  1654. return Math.round(ms / h) + 'h';
  1655. }
  1656. if (ms >= m) {
  1657. return Math.round(ms / m) + 'm';
  1658. }
  1659. if (ms >= s) {
  1660. return Math.round(ms / s) + 's';
  1661. }
  1662. return ms + 'ms';
  1663. }
  1664. /**
  1665. * Long format for `ms`.
  1666. *
  1667. * @api private
  1668. * @param {number} ms
  1669. * @return {string}
  1670. */
  1671. function longFormat (ms) {
  1672. return plural(ms, d, 'day') ||
  1673. plural(ms, h, 'hour') ||
  1674. plural(ms, m, 'minute') ||
  1675. plural(ms, s, 'second') ||
  1676. ms + ' ms';
  1677. }
  1678. /**
  1679. * Pluralization helper.
  1680. *
  1681. * @api private
  1682. * @param {number} ms
  1683. * @param {number} n
  1684. * @param {string} name
  1685. */
  1686. function plural (ms, n, name) {
  1687. if (ms < n) {
  1688. return;
  1689. }
  1690. if (ms < n * 1.5) {
  1691. return Math.floor(ms / n) + ' ' + name;
  1692. }
  1693. return Math.ceil(ms / n) + ' ' + name + 's';
  1694. }
  1695. },{}],16:[function(require,module,exports){
  1696. 'use strict';
  1697. /**
  1698. * Expose `Pending`.
  1699. */
  1700. module.exports = Pending;
  1701. /**
  1702. * Initialize a new `Pending` error with the given message.
  1703. *
  1704. * @param {string} message
  1705. */
  1706. function Pending (message) {
  1707. this.message = message;
  1708. }
  1709. },{}],17:[function(require,module,exports){
  1710. (function (process,global){
  1711. 'use strict';
  1712. /**
  1713. * Module dependencies.
  1714. */
  1715. var tty = require('tty');
  1716. var diff = require('diff');
  1717. var ms = require('../ms');
  1718. var utils = require('../utils');
  1719. var supportsColor = process.browser ? null : require('supports-color');
  1720. /**
  1721. * Expose `Base`.
  1722. */
  1723. exports = module.exports = Base;
  1724. /**
  1725. * Save timer references to avoid Sinon interfering.
  1726. * See: https://github.com/mochajs/mocha/issues/237
  1727. */
  1728. /* eslint-disable no-unused-vars, no-native-reassign */
  1729. var Date = global.Date;
  1730. var setTimeout = global.setTimeout;
  1731. var setInterval = global.setInterval;
  1732. var clearTimeout = global.clearTimeout;
  1733. var clearInterval = global.clearInterval;
  1734. /* eslint-enable no-unused-vars, no-native-reassign */
  1735. /**
  1736. * Check if both stdio streams are associated with a tty.
  1737. */
  1738. var isatty = tty.isatty(1) && tty.isatty(2);
  1739. /**
  1740. * Enable coloring by default, except in the browser interface.
  1741. */
  1742. exports.useColors = !process.browser && (supportsColor || (process.env.MOCHA_COLORS !== undefined));
  1743. /**
  1744. * Inline diffs instead of +/-
  1745. */
  1746. exports.inlineDiffs = false;
  1747. /**
  1748. * Default color map.
  1749. */
  1750. exports.colors = {
  1751. pass: 90,
  1752. fail: 31,
  1753. 'bright pass': 92,
  1754. 'bright fail': 91,
  1755. 'bright yellow': 93,
  1756. pending: 36,
  1757. suite: 0,
  1758. 'error title': 0,
  1759. 'error message': 31,
  1760. 'error stack': 90,
  1761. checkmark: 32,
  1762. fast: 90,
  1763. medium: 33,
  1764. slow: 31,
  1765. green: 32,
  1766. light: 90,
  1767. 'diff gutter': 90,
  1768. 'diff added': 32,
  1769. 'diff removed': 31
  1770. };
  1771. /**
  1772. * Default symbol map.
  1773. */
  1774. exports.symbols = {
  1775. ok: '✓',
  1776. err: '✖',
  1777. dot: '․',
  1778. comma: ',',
  1779. bang: '!'
  1780. };
  1781. // With node.js on Windows: use symbols available in terminal default fonts
  1782. if (process.platform === 'win32') {
  1783. exports.symbols.ok = '\u221A';
  1784. exports.symbols.err = '\u00D7';
  1785. exports.symbols.dot = '.';
  1786. }
  1787. /**
  1788. * Color `str` with the given `type`,
  1789. * allowing colors to be disabled,
  1790. * as well as user-defined color
  1791. * schemes.
  1792. *
  1793. * @param {string} type
  1794. * @param {string} str
  1795. * @return {string}
  1796. * @api private
  1797. */
  1798. var color = exports.color = function (type, str) {
  1799. if (!exports.useColors) {
  1800. return String(str);
  1801. }
  1802. return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
  1803. };
  1804. /**
  1805. * Expose term window size, with some defaults for when stderr is not a tty.
  1806. */
  1807. exports.window = {
  1808. width: 75
  1809. };
  1810. if (isatty) {
  1811. exports.window.width = process.stdout.getWindowSize
  1812. ? process.stdout.getWindowSize(1)[0]
  1813. : tty.getWindowSize()[1];
  1814. }
  1815. /**
  1816. * Expose some basic cursor interactions that are common among reporters.
  1817. */
  1818. exports.cursor = {
  1819. hide: function () {
  1820. isatty && process.stdout.write('\u001b[?25l');
  1821. },
  1822. show: function () {
  1823. isatty && process.stdout.write('\u001b[?25h');
  1824. },
  1825. deleteLine: function () {
  1826. isatty && process.stdout.write('\u001b[2K');
  1827. },
  1828. beginningOfLine: function () {
  1829. isatty && process.stdout.write('\u001b[0G');
  1830. },
  1831. CR: function () {
  1832. if (isatty) {
  1833. exports.cursor.deleteLine();
  1834. exports.cursor.beginningOfLine();
  1835. } else {
  1836. process.stdout.write('\r');
  1837. }
  1838. }
  1839. };
  1840. /**
  1841. * Outut the given `failures` as a list.
  1842. *
  1843. * @param {Array} failures
  1844. * @api public
  1845. */
  1846. exports.list = function (failures) {
  1847. console.log();
  1848. failures.forEach(function (test, i) {
  1849. // format
  1850. var fmt = color('error title', ' %s) %s:\n') +
  1851. color('error message', ' %s') +
  1852. color('error stack', '\n%s\n');
  1853. // msg
  1854. var msg;
  1855. var err = test.err;
  1856. var message;
  1857. if (err.message && typeof err.message.toString === 'function') {
  1858. message = err.message + '';
  1859. } else if (typeof err.inspect === 'function') {
  1860. message = err.inspect() + '';
  1861. } else {
  1862. message = '';
  1863. }
  1864. var stack = err.stack || message;
  1865. var index = message ? stack.indexOf(message) : -1;
  1866. var actual = err.actual;
  1867. var expected = err.expected;
  1868. var escape = true;
  1869. if (index === -1) {
  1870. msg = message;
  1871. } else {
  1872. index += message.length;
  1873. msg = stack.slice(0, index);
  1874. // remove msg from stack
  1875. stack = stack.slice(index + 1);
  1876. }
  1877. // uncaught
  1878. if (err.uncaught) {
  1879. msg = 'Uncaught ' + msg;
  1880. }
  1881. // explicitly show diff
  1882. if (err.showDiff !== false && sameType(actual, expected) && expected !== undefined) {
  1883. escape = false;
  1884. if (!(utils.isString(actual) && utils.isString(expected))) {
  1885. err.actual = actual = utils.stringify(actual);
  1886. err.expected = expected = utils.stringify(expected);
  1887. }
  1888. fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
  1889. var match = message.match(/^([^:]+): expected/);
  1890. msg = '\n ' + color('error message', match ? match[1] : msg);
  1891. if (exports.inlineDiffs) {
  1892. msg += inlineDiff(err, escape);
  1893. } else {
  1894. msg += unifiedDiff(err, escape);
  1895. }
  1896. }
  1897. // indent stack trace
  1898. stack = stack.replace(/^/gm, ' ');
  1899. console.log(fmt, (i + 1), test.fullTitle(), msg, stack);
  1900. });
  1901. };
  1902. /**
  1903. * Initialize a new `Base` reporter.
  1904. *
  1905. * All other reporters generally
  1906. * inherit from this reporter, providing
  1907. * stats such as test duration, number
  1908. * of tests passed / failed etc.
  1909. *
  1910. * @param {Runner} runner
  1911. * @api public
  1912. */
  1913. function Base (runner) {
  1914. var stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 };
  1915. var failures = this.failures = [];
  1916. if (!runner) {
  1917. return;
  1918. }
  1919. this.runner = runner;
  1920. runner.stats = stats;
  1921. runner.on('start', function () {
  1922. stats.start = new Date();
  1923. });
  1924. runner.on('suite', function (suite) {
  1925. stats.suites = stats.suites || 0;
  1926. suite.root || stats.suites++;
  1927. });
  1928. runner.on('test end', function () {
  1929. stats.tests = stats.tests || 0;
  1930. stats.tests++;
  1931. });
  1932. runner.on('pass', function (test) {
  1933. stats.passes = stats.passes || 0;
  1934. if (test.duration > test.slow()) {
  1935. test.speed = 'slow';
  1936. } else if (test.duration > test.slow() / 2) {
  1937. test.speed = 'medium';
  1938. } else {
  1939. test.speed = 'fast';
  1940. }
  1941. stats.passes++;
  1942. });
  1943. runner.on('fail', function (test, err) {
  1944. stats.failures = stats.failures || 0;
  1945. stats.failures++;
  1946. test.err = err;
  1947. failures.push(test);
  1948. });
  1949. runner.on('end', function () {
  1950. stats.end = new Date();
  1951. stats.duration = new Date() - stats.start;
  1952. });
  1953. runner.on('pending', function () {
  1954. stats.pending++;
  1955. });
  1956. }
  1957. /**
  1958. * Output common epilogue used by many of
  1959. * the bundled reporters.
  1960. *
  1961. * @api public
  1962. */
  1963. Base.prototype.epilogue = function () {
  1964. var stats = this.stats;
  1965. var fmt;
  1966. console.log();
  1967. // passes
  1968. fmt = color('bright pass', ' ') +
  1969. color('green', ' %d passing') +
  1970. color('light', ' (%s)');
  1971. console.log(fmt,
  1972. stats.passes || 0,
  1973. ms(stats.duration));
  1974. // pending
  1975. if (stats.pending) {
  1976. fmt = color('pending', ' ') +
  1977. color('pending', ' %d pending');
  1978. console.log(fmt, stats.pending);
  1979. }
  1980. // failures
  1981. if (stats.failures) {
  1982. fmt = color('fail', ' %d failing');
  1983. console.log(fmt, stats.failures);
  1984. Base.list(this.failures);
  1985. console.log();
  1986. }
  1987. console.log();
  1988. };
  1989. /**
  1990. * Pad the given `str` to `len`.
  1991. *
  1992. * @api private
  1993. * @param {string} str
  1994. * @param {string} len
  1995. * @return {string}
  1996. */
  1997. function pad (str, len) {
  1998. str = String(str);
  1999. return Array(len - str.length + 1).join(' ') + str;
  2000. }
  2001. /**
  2002. * Returns an inline diff between 2 strings with coloured ANSI output
  2003. *
  2004. * @api private
  2005. * @param {Error} err with actual/expected
  2006. * @param {boolean} escape
  2007. * @return {string} Diff
  2008. */
  2009. function inlineDiff (err, escape) {
  2010. var msg = errorDiff(err, 'WordsWithSpace', escape);
  2011. // linenos
  2012. var lines = msg.split('\n');
  2013. if (lines.length > 4) {
  2014. var width = String(lines.length).length;
  2015. msg = lines.map(function (str, i) {
  2016. return pad(++i, width) + ' |' + ' ' + str;
  2017. }).join('\n');
  2018. }
  2019. // legend
  2020. msg = '\n' +
  2021. color('diff removed', 'actual') +
  2022. ' ' +
  2023. color('diff added', 'expected') +
  2024. '\n\n' +
  2025. msg +
  2026. '\n';
  2027. // indent
  2028. msg = msg.replace(/^/gm, ' ');
  2029. return msg;
  2030. }
  2031. /**
  2032. * Returns a unified diff between two strings.
  2033. *
  2034. * @api private
  2035. * @param {Error} err with actual/expected
  2036. * @param {boolean} escape
  2037. * @return {string} The diff.
  2038. */
  2039. function unifiedDiff (err, escape) {
  2040. var indent = ' ';
  2041. function cleanUp (line) {
  2042. if (escape) {
  2043. line = escapeInvisibles(line);
  2044. }
  2045. if (line[0] === '+') {
  2046. return indent + colorLines('diff added', line);
  2047. }
  2048. if (line[0] === '-') {
  2049. return indent + colorLines('diff removed', line);
  2050. }
  2051. if (line.match(/@@/)) {
  2052. return null;
  2053. }
  2054. if (line.match(/\\ No newline/)) {
  2055. return null;
  2056. }
  2057. return indent + line;
  2058. }
  2059. function notBlank (line) {
  2060. return typeof line !== 'undefined' && line !== null;
  2061. }
  2062. var msg = diff.createPatch('string', err.actual, err.expected);
  2063. var lines = msg.split('\n').splice(4);
  2064. return '\n ' +
  2065. colorLines('diff added', '+ expected') + ' ' +
  2066. colorLines('diff removed', '- actual') +
  2067. '\n\n' +
  2068. lines.map(cleanUp).filter(notBlank).join('\n');
  2069. }
  2070. /**
  2071. * Return a character diff for `err`.
  2072. *
  2073. * @api private
  2074. * @param {Error} err
  2075. * @param {string} type
  2076. * @param {boolean} escape
  2077. * @return {string}
  2078. */
  2079. function errorDiff (err, type, escape) {
  2080. var actual = escape ? escapeInvisibles(err.actual) : err.actual;
  2081. var expected = escape ? escapeInvisibles(err.expected) : err.expected;
  2082. return diff['diff' + type](actual, expected).map(function (str) {
  2083. if (str.added) {
  2084. return colorLines('diff added', str.value);
  2085. }
  2086. if (str.removed) {
  2087. return colorLines('diff removed', str.value);
  2088. }
  2089. return str.value;
  2090. }).join('');
  2091. }
  2092. /**
  2093. * Returns a string with all invisible characters in plain text
  2094. *
  2095. * @api private
  2096. * @param {string} line
  2097. * @return {string}
  2098. */
  2099. function escapeInvisibles (line) {
  2100. return line.replace(/\t/g, '<tab>')
  2101. .replace(/\r/g, '<CR>')
  2102. .replace(/\n/g, '<LF>\n');
  2103. }
  2104. /**
  2105. * Color lines for `str`, using the color `name`.
  2106. *
  2107. * @api private
  2108. * @param {string} name
  2109. * @param {string} str
  2110. * @return {string}
  2111. */
  2112. function colorLines (name, str) {
  2113. return str.split('\n').map(function (str) {
  2114. return color(name, str);
  2115. }).join('\n');
  2116. }
  2117. /**
  2118. * Object#toString reference.
  2119. */
  2120. var objToString = Object.prototype.toString;
  2121. /**
  2122. * Check that a / b have the same type.
  2123. *
  2124. * @api private
  2125. * @param {Object} a
  2126. * @param {Object} b
  2127. * @return {boolean}
  2128. */
  2129. function sameType (a, b) {
  2130. return objToString.call(a) === objToString.call(b);
  2131. }
  2132. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2133. },{"../ms":15,"../utils":38,"_process":82,"diff":56,"supports-color":42,"tty":5}],18:[function(require,module,exports){
  2134. 'use strict';
  2135. /**
  2136. * Module dependencies.
  2137. */
  2138. var Base = require('./base');
  2139. var utils = require('../utils');
  2140. /**
  2141. * Expose `Doc`.
  2142. */
  2143. exports = module.exports = Doc;
  2144. /**
  2145. * Initialize a new `Doc` reporter.
  2146. *
  2147. * @param {Runner} runner
  2148. * @api public
  2149. */
  2150. function Doc (runner) {
  2151. Base.call(this, runner);
  2152. var indents = 2;
  2153. function indent () {
  2154. return Array(indents).join(' ');
  2155. }
  2156. runner.on('suite', function (suite) {
  2157. if (suite.root) {
  2158. return;
  2159. }
  2160. ++indents;
  2161. console.log('%s<section class="suite">', indent());
  2162. ++indents;
  2163. console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title));
  2164. console.log('%s<dl>', indent());
  2165. });
  2166. runner.on('suite end', function (suite) {
  2167. if (suite.root) {
  2168. return;
  2169. }
  2170. console.log('%s</dl>', indent());
  2171. --indents;
  2172. console.log('%s</section>', indent());
  2173. --indents;
  2174. });
  2175. runner.on('pass', function (test) {
  2176. console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
  2177. var code = utils.escape(utils.clean(test.body));
  2178. console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
  2179. });
  2180. runner.on('fail', function (test, err) {
  2181. console.log('%s <dt class="error">%s</dt>', indent(), utils.escape(test.title));
  2182. var code = utils.escape(utils.clean(test.body));
  2183. console.log('%s <dd class="error"><pre><code>%s</code></pre></dd>', indent(), code);
  2184. console.log('%s <dd class="error">%s</dd>', indent(), utils.escape(err));
  2185. });
  2186. }
  2187. },{"../utils":38,"./base":17}],19:[function(require,module,exports){
  2188. (function (process){
  2189. 'use strict';
  2190. /**
  2191. * Module dependencies.
  2192. */
  2193. var Base = require('./base');
  2194. var inherits = require('../utils').inherits;
  2195. var color = Base.color;
  2196. /**
  2197. * Expose `Dot`.
  2198. */
  2199. exports = module.exports = Dot;
  2200. /**
  2201. * Initialize a new `Dot` matrix test reporter.
  2202. *
  2203. * @api public
  2204. * @param {Runner} runner
  2205. */
  2206. function Dot (runner) {
  2207. Base.call(this, runner);
  2208. var self = this;
  2209. var width = Base.window.width * 0.75 | 0;
  2210. var n = -1;
  2211. runner.on('start', function () {
  2212. process.stdout.write('\n');
  2213. });
  2214. runner.on('pending', function () {
  2215. if (++n % width === 0) {
  2216. process.stdout.write('\n ');
  2217. }
  2218. process.stdout.write(color('pending', Base.symbols.comma));
  2219. });
  2220. runner.on('pass', function (test) {
  2221. if (++n % width === 0) {
  2222. process.stdout.write('\n ');
  2223. }
  2224. if (test.speed === 'slow') {
  2225. process.stdout.write(color('bright yellow', Base.symbols.dot));
  2226. } else {
  2227. process.stdout.write(color(test.speed, Base.symbols.dot));
  2228. }
  2229. });
  2230. runner.on('fail', function () {
  2231. if (++n % width === 0) {
  2232. process.stdout.write('\n ');
  2233. }
  2234. process.stdout.write(color('fail', Base.symbols.bang));
  2235. });
  2236. runner.on('end', function () {
  2237. console.log();
  2238. self.epilogue();
  2239. });
  2240. }
  2241. /**
  2242. * Inherit from `Base.prototype`.
  2243. */
  2244. inherits(Dot, Base);
  2245. }).call(this,require('_process'))
  2246. },{"../utils":38,"./base":17,"_process":82}],20:[function(require,module,exports){
  2247. (function (global){
  2248. 'use strict';
  2249. /* eslint-env browser */
  2250. /**
  2251. * Module dependencies.
  2252. */
  2253. var Base = require('./base');
  2254. var utils = require('../utils');
  2255. var Progress = require('../browser/progress');
  2256. var escapeRe = require('escape-string-regexp');
  2257. var escape = utils.escape;
  2258. /**
  2259. * Save timer references to avoid Sinon interfering (see GH-237).
  2260. */
  2261. /* eslint-disable no-unused-vars, no-native-reassign */
  2262. var Date = global.Date;
  2263. var setTimeout = global.setTimeout;
  2264. var setInterval = global.setInterval;
  2265. var clearTimeout = global.clearTimeout;
  2266. var clearInterval = global.clearInterval;
  2267. /* eslint-enable no-unused-vars, no-native-reassign */
  2268. /**
  2269. * Expose `HTML`.
  2270. */
  2271. exports = module.exports = HTML;
  2272. /**
  2273. * Stats template.
  2274. */
  2275. var statsTemplate = '<ul id="mocha-stats">' +
  2276. '<li class="progress"><canvas width="40" height="40"></canvas></li>' +
  2277. '<li class="passes"><a href="javascript:void(0);">passes:</a> <em>0</em></li>' +
  2278. '<li class="failures"><a href="javascript:void(0);">failures:</a> <em>0</em></li>' +
  2279. '<li class="duration">duration: <em>0</em>s</li>' +
  2280. '</ul>';
  2281. var playIcon = '&#x2023;';
  2282. /**
  2283. * Initialize a new `HTML` reporter.
  2284. *
  2285. * @api public
  2286. * @param {Runner} runner
  2287. */
  2288. function HTML (runner) {
  2289. Base.call(this, runner);
  2290. var self = this;
  2291. var stats = this.stats;
  2292. var stat = fragment(statsTemplate);
  2293. var items = stat.getElementsByTagName('li');
  2294. var passes = items[1].getElementsByTagName('em')[0];
  2295. var passesLink = items[1].getElementsByTagName('a')[0];
  2296. var failures = items[2].getElementsByTagName('em')[0];
  2297. var failuresLink = items[2].getElementsByTagName('a')[0];
  2298. var duration = items[3].getElementsByTagName('em')[0];
  2299. var canvas = stat.getElementsByTagName('canvas')[0];
  2300. var report = fragment('<ul id="mocha-report"></ul>');
  2301. var stack = [report];
  2302. var progress;
  2303. var ctx;
  2304. var root = document.getElementById('mocha');
  2305. if (canvas.getContext) {
  2306. var ratio = window.devicePixelRatio || 1;
  2307. canvas.style.width = canvas.width;
  2308. canvas.style.height = canvas.height;
  2309. canvas.width *= ratio;
  2310. canvas.height *= ratio;
  2311. ctx = canvas.getContext('2d');
  2312. ctx.scale(ratio, ratio);
  2313. progress = new Progress();
  2314. }
  2315. if (!root) {
  2316. return error('#mocha div missing, add it to your document');
  2317. }
  2318. // pass toggle
  2319. on(passesLink, 'click', function (evt) {
  2320. evt.preventDefault();
  2321. unhide();
  2322. var name = (/pass/).test(report.className) ? '' : ' pass';
  2323. report.className = report.className.replace(/fail|pass/g, '') + name;
  2324. if (report.className.trim()) {
  2325. hideSuitesWithout('test pass');
  2326. }
  2327. });
  2328. // failure toggle
  2329. on(failuresLink, 'click', function (evt) {
  2330. evt.preventDefault();
  2331. unhide();
  2332. var name = (/fail/).test(report.className) ? '' : ' fail';
  2333. report.className = report.className.replace(/fail|pass/g, '') + name;
  2334. if (report.className.trim()) {
  2335. hideSuitesWithout('test fail');
  2336. }
  2337. });
  2338. root.appendChild(stat);
  2339. root.appendChild(report);
  2340. if (progress) {
  2341. progress.size(40);
  2342. }
  2343. runner.on('suite', function (suite) {
  2344. if (suite.root) {
  2345. return;
  2346. }
  2347. // suite
  2348. var url = self.suiteURL(suite);
  2349. var el = fragment('<li class="suite"><h1><a href="%s">%s</a></h1></li>', url, escape(suite.title));
  2350. // container
  2351. stack[0].appendChild(el);
  2352. stack.unshift(document.createElement('ul'));
  2353. el.appendChild(stack[0]);
  2354. });
  2355. runner.on('suite end', function (suite) {
  2356. if (suite.root) {
  2357. updateStats();
  2358. return;
  2359. }
  2360. stack.shift();
  2361. });
  2362. runner.on('pass', function (test) {
  2363. var url = self.testURL(test);
  2364. var markup = '<li class="test pass %e"><h2>%e<span class="duration">%ems</span> ' +
  2365. '<a href="%s" class="replay">' + playIcon + '</a></h2></li>';
  2366. var el = fragment(markup, test.speed, test.title, test.duration, url);
  2367. self.addCodeToggle(el, test.body);
  2368. appendToStack(el);
  2369. updateStats();
  2370. });
  2371. runner.on('fail', function (test) {
  2372. var el = fragment('<li class="test fail"><h2>%e <a href="%e" class="replay">' + playIcon + '</a></h2></li>',
  2373. test.title, self.testURL(test));
  2374. var stackString; // Note: Includes leading newline
  2375. var message = test.err.toString();
  2376. // <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
  2377. // check for the result of the stringifying.
  2378. if (message === '[object Error]') {
  2379. message = test.err.message;
  2380. }
  2381. if (test.err.stack) {
  2382. var indexOfMessage = test.err.stack.indexOf(test.err.message);
  2383. if (indexOfMessage === -1) {
  2384. stackString = test.err.stack;
  2385. } else {
  2386. stackString = test.err.stack.substr(test.err.message.length + indexOfMessage);
  2387. }
  2388. } else if (test.err.sourceURL && test.err.line !== undefined) {
  2389. // Safari doesn't give you a stack. Let's at least provide a source line.
  2390. stackString = '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
  2391. }
  2392. stackString = stackString || '';
  2393. if (test.err.htmlMessage && stackString) {
  2394. el.appendChild(fragment('<div class="html-error">%s\n<pre class="error">%e</pre></div>',
  2395. test.err.htmlMessage, stackString));
  2396. } else if (test.err.htmlMessage) {
  2397. el.appendChild(fragment('<div class="html-error">%s</div>', test.err.htmlMessage));
  2398. } else {
  2399. el.appendChild(fragment('<pre class="error">%e%e</pre>', message, stackString));
  2400. }
  2401. self.addCodeToggle(el, test.body);
  2402. appendToStack(el);
  2403. updateStats();
  2404. });
  2405. runner.on('pending', function (test) {
  2406. var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
  2407. appendToStack(el);
  2408. updateStats();
  2409. });
  2410. function appendToStack (el) {
  2411. // Don't call .appendChild if #mocha-report was already .shift()'ed off the stack.
  2412. if (stack[0]) {
  2413. stack[0].appendChild(el);
  2414. }
  2415. }
  2416. function updateStats () {
  2417. // TODO: add to stats
  2418. var percent = stats.tests / runner.total * 100 | 0;
  2419. if (progress) {
  2420. progress.update(percent).draw(ctx);
  2421. }
  2422. // update stats
  2423. var ms = new Date() - stats.start;
  2424. text(passes, stats.passes);
  2425. text(failures, stats.failures);
  2426. text(duration, (ms / 1000).toFixed(2));
  2427. }
  2428. }
  2429. /**
  2430. * Makes a URL, preserving querystring ("search") parameters.
  2431. *
  2432. * @param {string} s
  2433. * @return {string} A new URL.
  2434. */
  2435. function makeUrl (s) {
  2436. var search = window.location.search;
  2437. // Remove previous grep query parameter if present
  2438. if (search) {
  2439. search = search.replace(/[?&]grep=[^&\s]*/g, '').replace(/^&/, '?');
  2440. }
  2441. return window.location.pathname + (search ? search + '&' : '?') + 'grep=' + encodeURIComponent(escapeRe(s));
  2442. }
  2443. /**
  2444. * Provide suite URL.
  2445. *
  2446. * @param {Object} [suite]
  2447. */
  2448. HTML.prototype.suiteURL = function (suite) {
  2449. return makeUrl(suite.fullTitle());
  2450. };
  2451. /**
  2452. * Provide test URL.
  2453. *
  2454. * @param {Object} [test]
  2455. */
  2456. HTML.prototype.testURL = function (test) {
  2457. return makeUrl(test.fullTitle());
  2458. };
  2459. /**
  2460. * Adds code toggle functionality for the provided test's list element.
  2461. *
  2462. * @param {HTMLLIElement} el
  2463. * @param {string} contents
  2464. */
  2465. HTML.prototype.addCodeToggle = function (el, contents) {
  2466. var h2 = el.getElementsByTagName('h2')[0];
  2467. on(h2, 'click', function () {
  2468. pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
  2469. });
  2470. var pre = fragment('<pre><code>%e</code></pre>', utils.clean(contents));
  2471. el.appendChild(pre);
  2472. pre.style.display = 'none';
  2473. };
  2474. /**
  2475. * Display error `msg`.
  2476. *
  2477. * @param {string} msg
  2478. */
  2479. function error (msg) {
  2480. document.body.appendChild(fragment('<div id="mocha-error">%s</div>', msg));
  2481. }
  2482. /**
  2483. * Return a DOM fragment from `html`.
  2484. *
  2485. * @param {string} html
  2486. */
  2487. function fragment (html) {
  2488. var args = arguments;
  2489. var div = document.createElement('div');
  2490. var i = 1;
  2491. div.innerHTML = html.replace(/%([se])/g, function (_, type) {
  2492. switch (type) {
  2493. case 's': return String(args[i++]);
  2494. case 'e': return escape(args[i++]);
  2495. // no default
  2496. }
  2497. });
  2498. return div.firstChild;
  2499. }
  2500. /**
  2501. * Check for suites that do not have elements
  2502. * with `classname`, and hide them.
  2503. *
  2504. * @param {text} classname
  2505. */
  2506. function hideSuitesWithout (classname) {
  2507. var suites = document.getElementsByClassName('suite');
  2508. for (var i = 0; i < suites.length; i++) {
  2509. var els = suites[i].getElementsByClassName(classname);
  2510. if (!els.length) {
  2511. suites[i].className += ' hidden';
  2512. }
  2513. }
  2514. }
  2515. /**
  2516. * Unhide .hidden suites.
  2517. */
  2518. function unhide () {
  2519. var els = document.getElementsByClassName('suite hidden');
  2520. for (var i = 0; i < els.length; ++i) {
  2521. els[i].className = els[i].className.replace('suite hidden', 'suite');
  2522. }
  2523. }
  2524. /**
  2525. * Set an element's text contents.
  2526. *
  2527. * @param {HTMLElement} el
  2528. * @param {string} contents
  2529. */
  2530. function text (el, contents) {
  2531. if (el.textContent) {
  2532. el.textContent = contents;
  2533. } else {
  2534. el.innerText = contents;
  2535. }
  2536. }
  2537. /**
  2538. * Listen on `event` with callback `fn`.
  2539. */
  2540. function on (el, event, fn) {
  2541. if (el.addEventListener) {
  2542. el.addEventListener(event, fn, false);
  2543. } else {
  2544. el.attachEvent('on' + event, fn);
  2545. }
  2546. }
  2547. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2548. },{"../browser/progress":4,"../utils":38,"./base":17,"escape-string-regexp":62}],21:[function(require,module,exports){
  2549. 'use strict';
  2550. // Alias exports to a their normalized format Mocha#reporter to prevent a need
  2551. // for dynamic (try/catch) requires, which Browserify doesn't handle.
  2552. exports.Base = exports.base = require('./base');
  2553. exports.Dot = exports.dot = require('./dot');
  2554. exports.Doc = exports.doc = require('./doc');
  2555. exports.TAP = exports.tap = require('./tap');
  2556. exports.JSON = exports.json = require('./json');
  2557. exports.HTML = exports.html = require('./html');
  2558. exports.List = exports.list = require('./list');
  2559. exports.Min = exports.min = require('./min');
  2560. exports.Spec = exports.spec = require('./spec');
  2561. exports.Nyan = exports.nyan = require('./nyan');
  2562. exports.XUnit = exports.xunit = require('./xunit');
  2563. exports.Markdown = exports.markdown = require('./markdown');
  2564. exports.Progress = exports.progress = require('./progress');
  2565. exports.Landing = exports.landing = require('./landing');
  2566. exports.JSONStream = exports['json-stream'] = require('./json-stream');
  2567. },{"./base":17,"./doc":18,"./dot":19,"./html":20,"./json":23,"./json-stream":22,"./landing":24,"./list":25,"./markdown":26,"./min":27,"./nyan":28,"./progress":29,"./spec":30,"./tap":31,"./xunit":32}],22:[function(require,module,exports){
  2568. (function (process){
  2569. 'use strict';
  2570. /**
  2571. * Module dependencies.
  2572. */
  2573. var Base = require('./base');
  2574. var JSON = require('json3');
  2575. /**
  2576. * Expose `List`.
  2577. */
  2578. exports = module.exports = List;
  2579. /**
  2580. * Initialize a new `List` test reporter.
  2581. *
  2582. * @api public
  2583. * @param {Runner} runner
  2584. */
  2585. function List (runner) {
  2586. Base.call(this, runner);
  2587. var self = this;
  2588. var total = runner.total;
  2589. runner.on('start', function () {
  2590. console.log(JSON.stringify(['start', { total: total }]));
  2591. });
  2592. runner.on('pass', function (test) {
  2593. console.log(JSON.stringify(['pass', clean(test)]));
  2594. });
  2595. runner.on('fail', function (test, err) {
  2596. test = clean(test);
  2597. test.err = err.message;
  2598. test.stack = err.stack || null;
  2599. console.log(JSON.stringify(['fail', test]));
  2600. });
  2601. runner.on('end', function () {
  2602. process.stdout.write(JSON.stringify(['end', self.stats]));
  2603. });
  2604. }
  2605. /**
  2606. * Return a plain-object representation of `test`
  2607. * free of cyclic properties etc.
  2608. *
  2609. * @api private
  2610. * @param {Object} test
  2611. * @return {Object}
  2612. */
  2613. function clean (test) {
  2614. return {
  2615. title: test.title,
  2616. fullTitle: test.fullTitle(),
  2617. duration: test.duration,
  2618. currentRetry: test.currentRetry()
  2619. };
  2620. }
  2621. }).call(this,require('_process'))
  2622. },{"./base":17,"_process":82,"json3":69}],23:[function(require,module,exports){
  2623. (function (process){
  2624. 'use strict';
  2625. /**
  2626. * Module dependencies.
  2627. */
  2628. var Base = require('./base');
  2629. /**
  2630. * Expose `JSON`.
  2631. */
  2632. exports = module.exports = JSONReporter;
  2633. /**
  2634. * Initialize a new `JSON` reporter.
  2635. *
  2636. * @api public
  2637. * @param {Runner} runner
  2638. */
  2639. function JSONReporter (runner) {
  2640. Base.call(this, runner);
  2641. var self = this;
  2642. var tests = [];
  2643. var pending = [];
  2644. var failures = [];
  2645. var passes = [];
  2646. runner.on('test end', function (test) {
  2647. tests.push(test);
  2648. });
  2649. runner.on('pass', function (test) {
  2650. passes.push(test);
  2651. });
  2652. runner.on('fail', function (test) {
  2653. failures.push(test);
  2654. });
  2655. runner.on('pending', function (test) {
  2656. pending.push(test);
  2657. });
  2658. runner.on('end', function () {
  2659. var obj = {
  2660. stats: self.stats,
  2661. tests: tests.map(clean),
  2662. pending: pending.map(clean),
  2663. failures: failures.map(clean),
  2664. passes: passes.map(clean)
  2665. };
  2666. runner.testResults = obj;
  2667. process.stdout.write(JSON.stringify(obj, null, 2));
  2668. });
  2669. }
  2670. /**
  2671. * Return a plain-object representation of `test`
  2672. * free of cyclic properties etc.
  2673. *
  2674. * @api private
  2675. * @param {Object} test
  2676. * @return {Object}
  2677. */
  2678. function clean (test) {
  2679. return {
  2680. title: test.title,
  2681. fullTitle: test.fullTitle(),
  2682. duration: test.duration,
  2683. currentRetry: test.currentRetry(),
  2684. err: errorJSON(test.err || {})
  2685. };
  2686. }
  2687. /**
  2688. * Transform `error` into a JSON object.
  2689. *
  2690. * @api private
  2691. * @param {Error} err
  2692. * @return {Object}
  2693. */
  2694. function errorJSON (err) {
  2695. var res = {};
  2696. Object.getOwnPropertyNames(err).forEach(function (key) {
  2697. res[key] = err[key];
  2698. }, err);
  2699. return res;
  2700. }
  2701. }).call(this,require('_process'))
  2702. },{"./base":17,"_process":82}],24:[function(require,module,exports){
  2703. (function (process){
  2704. 'use strict';
  2705. /**
  2706. * Module dependencies.
  2707. */
  2708. var Base = require('./base');
  2709. var inherits = require('../utils').inherits;
  2710. var cursor = Base.cursor;
  2711. var color = Base.color;
  2712. /**
  2713. * Expose `Landing`.
  2714. */
  2715. exports = module.exports = Landing;
  2716. /**
  2717. * Airplane color.
  2718. */
  2719. Base.colors.plane = 0;
  2720. /**
  2721. * Airplane crash color.
  2722. */
  2723. Base.colors['plane crash'] = 31;
  2724. /**
  2725. * Runway color.
  2726. */
  2727. Base.colors.runway = 90;
  2728. /**
  2729. * Initialize a new `Landing` reporter.
  2730. *
  2731. * @api public
  2732. * @param {Runner} runner
  2733. */
  2734. function Landing (runner) {
  2735. Base.call(this, runner);
  2736. var self = this;
  2737. var width = Base.window.width * 0.75 | 0;
  2738. var total = runner.total;
  2739. var stream = process.stdout;
  2740. var plane = color('plane', '✈');
  2741. var crashed = -1;
  2742. var n = 0;
  2743. function runway () {
  2744. var buf = Array(width).join('-');
  2745. return ' ' + color('runway', buf);
  2746. }
  2747. runner.on('start', function () {
  2748. stream.write('\n\n\n ');
  2749. cursor.hide();
  2750. });
  2751. runner.on('test end', function (test) {
  2752. // check if the plane crashed
  2753. var col = crashed === -1 ? width * ++n / total | 0 : crashed;
  2754. // show the crash
  2755. if (test.state === 'failed') {
  2756. plane = color('plane crash', '✈');
  2757. crashed = col;
  2758. }
  2759. // render landing strip
  2760. stream.write('\u001b[' + (width + 1) + 'D\u001b[2A');
  2761. stream.write(runway());
  2762. stream.write('\n ');
  2763. stream.write(color('runway', Array(col).join('⋅')));
  2764. stream.write(plane);
  2765. stream.write(color('runway', Array(width - col).join('⋅') + '\n'));
  2766. stream.write(runway());
  2767. stream.write('\u001b[0m');
  2768. });
  2769. runner.on('end', function () {
  2770. cursor.show();
  2771. console.log();
  2772. self.epilogue();
  2773. });
  2774. }
  2775. /**
  2776. * Inherit from `Base.prototype`.
  2777. */
  2778. inherits(Landing, Base);
  2779. }).call(this,require('_process'))
  2780. },{"../utils":38,"./base":17,"_process":82}],25:[function(require,module,exports){
  2781. (function (process){
  2782. 'use strict';
  2783. /**
  2784. * Module dependencies.
  2785. */
  2786. var Base = require('./base');
  2787. var inherits = require('../utils').inherits;
  2788. var color = Base.color;
  2789. var cursor = Base.cursor;
  2790. /**
  2791. * Expose `List`.
  2792. */
  2793. exports = module.exports = List;
  2794. /**
  2795. * Initialize a new `List` test reporter.
  2796. *
  2797. * @api public
  2798. * @param {Runner} runner
  2799. */
  2800. function List (runner) {
  2801. Base.call(this, runner);
  2802. var self = this;
  2803. var n = 0;
  2804. runner.on('start', function () {
  2805. console.log();
  2806. });
  2807. runner.on('test', function (test) {
  2808. process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
  2809. });
  2810. runner.on('pending', function (test) {
  2811. var fmt = color('checkmark', ' -') +
  2812. color('pending', ' %s');
  2813. console.log(fmt, test.fullTitle());
  2814. });
  2815. runner.on('pass', function (test) {
  2816. var fmt = color('checkmark', ' ' + Base.symbols.ok) +
  2817. color('pass', ' %s: ') +
  2818. color(test.speed, '%dms');
  2819. cursor.CR();
  2820. console.log(fmt, test.fullTitle(), test.duration);
  2821. });
  2822. runner.on('fail', function (test) {
  2823. cursor.CR();
  2824. console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
  2825. });
  2826. runner.on('end', self.epilogue.bind(self));
  2827. }
  2828. /**
  2829. * Inherit from `Base.prototype`.
  2830. */
  2831. inherits(List, Base);
  2832. }).call(this,require('_process'))
  2833. },{"../utils":38,"./base":17,"_process":82}],26:[function(require,module,exports){
  2834. (function (process){
  2835. 'use strict';
  2836. /**
  2837. * Module dependencies.
  2838. */
  2839. var Base = require('./base');
  2840. var utils = require('../utils');
  2841. /**
  2842. * Constants
  2843. */
  2844. var SUITE_PREFIX = '$';
  2845. /**
  2846. * Expose `Markdown`.
  2847. */
  2848. exports = module.exports = Markdown;
  2849. /**
  2850. * Initialize a new `Markdown` reporter.
  2851. *
  2852. * @api public
  2853. * @param {Runner} runner
  2854. */
  2855. function Markdown (runner) {
  2856. Base.call(this, runner);
  2857. var level = 0;
  2858. var buf = '';
  2859. function title (str) {
  2860. return Array(level).join('#') + ' ' + str;
  2861. }
  2862. function mapTOC (suite, obj) {
  2863. var ret = obj;
  2864. var key = SUITE_PREFIX + suite.title;
  2865. obj = obj[key] = obj[key] || { suite: suite };
  2866. suite.suites.forEach(function (suite) {
  2867. mapTOC(suite, obj);
  2868. });
  2869. return ret;
  2870. }
  2871. function stringifyTOC (obj, level) {
  2872. ++level;
  2873. var buf = '';
  2874. var link;
  2875. for (var key in obj) {
  2876. if (key === 'suite') {
  2877. continue;
  2878. }
  2879. if (key !== SUITE_PREFIX) {
  2880. link = ' - [' + key.substring(1) + ']';
  2881. link += '(#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
  2882. buf += Array(level).join(' ') + link;
  2883. }
  2884. buf += stringifyTOC(obj[key], level);
  2885. }
  2886. return buf;
  2887. }
  2888. function generateTOC (suite) {
  2889. var obj = mapTOC(suite, {});
  2890. return stringifyTOC(obj, 0);
  2891. }
  2892. generateTOC(runner.suite);
  2893. runner.on('suite', function (suite) {
  2894. ++level;
  2895. var slug = utils.slug(suite.fullTitle());
  2896. buf += '<a name="' + slug + '"></a>' + '\n';
  2897. buf += title(suite.title) + '\n';
  2898. });
  2899. runner.on('suite end', function () {
  2900. --level;
  2901. });
  2902. runner.on('pass', function (test) {
  2903. var code = utils.clean(test.body);
  2904. buf += test.title + '.\n';
  2905. buf += '\n```js\n';
  2906. buf += code + '\n';
  2907. buf += '```\n\n';
  2908. });
  2909. runner.on('end', function () {
  2910. process.stdout.write('# TOC\n');
  2911. process.stdout.write(generateTOC(runner.suite));
  2912. process.stdout.write(buf);
  2913. });
  2914. }
  2915. }).call(this,require('_process'))
  2916. },{"../utils":38,"./base":17,"_process":82}],27:[function(require,module,exports){
  2917. (function (process){
  2918. 'use strict';
  2919. /**
  2920. * Module dependencies.
  2921. */
  2922. var Base = require('./base');
  2923. var inherits = require('../utils').inherits;
  2924. /**
  2925. * Expose `Min`.
  2926. */
  2927. exports = module.exports = Min;
  2928. /**
  2929. * Initialize a new `Min` minimal test reporter (best used with --watch).
  2930. *
  2931. * @api public
  2932. * @param {Runner} runner
  2933. */
  2934. function Min (runner) {
  2935. Base.call(this, runner);
  2936. runner.on('start', function () {
  2937. // clear screen
  2938. process.stdout.write('\u001b[2J');
  2939. // set cursor position
  2940. process.stdout.write('\u001b[1;3H');
  2941. });
  2942. runner.on('end', this.epilogue.bind(this));
  2943. }
  2944. /**
  2945. * Inherit from `Base.prototype`.
  2946. */
  2947. inherits(Min, Base);
  2948. }).call(this,require('_process'))
  2949. },{"../utils":38,"./base":17,"_process":82}],28:[function(require,module,exports){
  2950. (function (process){
  2951. 'use strict';
  2952. /**
  2953. * Module dependencies.
  2954. */
  2955. var Base = require('./base');
  2956. var inherits = require('../utils').inherits;
  2957. /**
  2958. * Expose `Dot`.
  2959. */
  2960. exports = module.exports = NyanCat;
  2961. /**
  2962. * Initialize a new `Dot` matrix test reporter.
  2963. *
  2964. * @param {Runner} runner
  2965. * @api public
  2966. */
  2967. function NyanCat (runner) {
  2968. Base.call(this, runner);
  2969. var self = this;
  2970. var width = Base.window.width * 0.75 | 0;
  2971. var nyanCatWidth = this.nyanCatWidth = 11;
  2972. this.colorIndex = 0;
  2973. this.numberOfLines = 4;
  2974. this.rainbowColors = self.generateColors();
  2975. this.scoreboardWidth = 5;
  2976. this.tick = 0;
  2977. this.trajectories = [[], [], [], []];
  2978. this.trajectoryWidthMax = (width - nyanCatWidth);
  2979. runner.on('start', function () {
  2980. Base.cursor.hide();
  2981. self.draw();
  2982. });
  2983. runner.on('pending', function () {
  2984. self.draw();
  2985. });
  2986. runner.on('pass', function () {
  2987. self.draw();
  2988. });
  2989. runner.on('fail', function () {
  2990. self.draw();
  2991. });
  2992. runner.on('end', function () {
  2993. Base.cursor.show();
  2994. for (var i = 0; i < self.numberOfLines; i++) {
  2995. write('\n');
  2996. }
  2997. self.epilogue();
  2998. });
  2999. }
  3000. /**
  3001. * Inherit from `Base.prototype`.
  3002. */
  3003. inherits(NyanCat, Base);
  3004. /**
  3005. * Draw the nyan cat
  3006. *
  3007. * @api private
  3008. */
  3009. NyanCat.prototype.draw = function () {
  3010. this.appendRainbow();
  3011. this.drawScoreboard();
  3012. this.drawRainbow();
  3013. this.drawNyanCat();
  3014. this.tick = !this.tick;
  3015. };
  3016. /**
  3017. * Draw the "scoreboard" showing the number
  3018. * of passes, failures and pending tests.
  3019. *
  3020. * @api private
  3021. */
  3022. NyanCat.prototype.drawScoreboard = function () {
  3023. var stats = this.stats;
  3024. function draw (type, n) {
  3025. write(' ');
  3026. write(Base.color(type, n));
  3027. write('\n');
  3028. }
  3029. draw('green', stats.passes);
  3030. draw('fail', stats.failures);
  3031. draw('pending', stats.pending);
  3032. write('\n');
  3033. this.cursorUp(this.numberOfLines);
  3034. };
  3035. /**
  3036. * Append the rainbow.
  3037. *
  3038. * @api private
  3039. */
  3040. NyanCat.prototype.appendRainbow = function () {
  3041. var segment = this.tick ? '_' : '-';
  3042. var rainbowified = this.rainbowify(segment);
  3043. for (var index = 0; index < this.numberOfLines; index++) {
  3044. var trajectory = this.trajectories[index];
  3045. if (trajectory.length >= this.trajectoryWidthMax) {
  3046. trajectory.shift();
  3047. }
  3048. trajectory.push(rainbowified);
  3049. }
  3050. };
  3051. /**
  3052. * Draw the rainbow.
  3053. *
  3054. * @api private
  3055. */
  3056. NyanCat.prototype.drawRainbow = function () {
  3057. var self = this;
  3058. this.trajectories.forEach(function (line) {
  3059. write('\u001b[' + self.scoreboardWidth + 'C');
  3060. write(line.join(''));
  3061. write('\n');
  3062. });
  3063. this.cursorUp(this.numberOfLines);
  3064. };
  3065. /**
  3066. * Draw the nyan cat
  3067. *
  3068. * @api private
  3069. */
  3070. NyanCat.prototype.drawNyanCat = function () {
  3071. var self = this;
  3072. var startWidth = this.scoreboardWidth + this.trajectories[0].length;
  3073. var dist = '\u001b[' + startWidth + 'C';
  3074. var padding = '';
  3075. write(dist);
  3076. write('_,------,');
  3077. write('\n');
  3078. write(dist);
  3079. padding = self.tick ? ' ' : ' ';
  3080. write('_|' + padding + '/\\_/\\ ');
  3081. write('\n');
  3082. write(dist);
  3083. padding = self.tick ? '_' : '__';
  3084. var tail = self.tick ? '~' : '^';
  3085. write(tail + '|' + padding + this.face() + ' ');
  3086. write('\n');
  3087. write(dist);
  3088. padding = self.tick ? ' ' : ' ';
  3089. write(padding + '"" "" ');
  3090. write('\n');
  3091. this.cursorUp(this.numberOfLines);
  3092. };
  3093. /**
  3094. * Draw nyan cat face.
  3095. *
  3096. * @api private
  3097. * @return {string}
  3098. */
  3099. NyanCat.prototype.face = function () {
  3100. var stats = this.stats;
  3101. if (stats.failures) {
  3102. return '( x .x)';
  3103. } else if (stats.pending) {
  3104. return '( o .o)';
  3105. } else if (stats.passes) {
  3106. return '( ^ .^)';
  3107. }
  3108. return '( - .-)';
  3109. };
  3110. /**
  3111. * Move cursor up `n`.
  3112. *
  3113. * @api private
  3114. * @param {number} n
  3115. */
  3116. NyanCat.prototype.cursorUp = function (n) {
  3117. write('\u001b[' + n + 'A');
  3118. };
  3119. /**
  3120. * Move cursor down `n`.
  3121. *
  3122. * @api private
  3123. * @param {number} n
  3124. */
  3125. NyanCat.prototype.cursorDown = function (n) {
  3126. write('\u001b[' + n + 'B');
  3127. };
  3128. /**
  3129. * Generate rainbow colors.
  3130. *
  3131. * @api private
  3132. * @return {Array}
  3133. */
  3134. NyanCat.prototype.generateColors = function () {
  3135. var colors = [];
  3136. for (var i = 0; i < (6 * 7); i++) {
  3137. var pi3 = Math.floor(Math.PI / 3);
  3138. var n = (i * (1.0 / 6));
  3139. var r = Math.floor(3 * Math.sin(n) + 3);
  3140. var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
  3141. var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
  3142. colors.push(36 * r + 6 * g + b + 16);
  3143. }
  3144. return colors;
  3145. };
  3146. /**
  3147. * Apply rainbow to the given `str`.
  3148. *
  3149. * @api private
  3150. * @param {string} str
  3151. * @return {string}
  3152. */
  3153. NyanCat.prototype.rainbowify = function (str) {
  3154. if (!Base.useColors) {
  3155. return str;
  3156. }
  3157. var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length];
  3158. this.colorIndex += 1;
  3159. return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';
  3160. };
  3161. /**
  3162. * Stdout helper.
  3163. *
  3164. * @param {string} string A message to write to stdout.
  3165. */
  3166. function write (string) {
  3167. process.stdout.write(string);
  3168. }
  3169. }).call(this,require('_process'))
  3170. },{"../utils":38,"./base":17,"_process":82}],29:[function(require,module,exports){
  3171. (function (process){
  3172. 'use strict';
  3173. /**
  3174. * Module dependencies.
  3175. */
  3176. var Base = require('./base');
  3177. var inherits = require('../utils').inherits;
  3178. var color = Base.color;
  3179. var cursor = Base.cursor;
  3180. /**
  3181. * Expose `Progress`.
  3182. */
  3183. exports = module.exports = Progress;
  3184. /**
  3185. * General progress bar color.
  3186. */
  3187. Base.colors.progress = 90;
  3188. /**
  3189. * Initialize a new `Progress` bar test reporter.
  3190. *
  3191. * @api public
  3192. * @param {Runner} runner
  3193. * @param {Object} options
  3194. */
  3195. function Progress (runner, options) {
  3196. Base.call(this, runner);
  3197. var self = this;
  3198. var width = Base.window.width * 0.50 | 0;
  3199. var total = runner.total;
  3200. var complete = 0;
  3201. var lastN = -1;
  3202. // default chars
  3203. options = options || {};
  3204. options.open = options.open || '[';
  3205. options.complete = options.complete || '▬';
  3206. options.incomplete = options.incomplete || Base.symbols.dot;
  3207. options.close = options.close || ']';
  3208. options.verbose = false;
  3209. // tests started
  3210. runner.on('start', function () {
  3211. console.log();
  3212. cursor.hide();
  3213. });
  3214. // tests complete
  3215. runner.on('test end', function () {
  3216. complete++;
  3217. var percent = complete / total;
  3218. var n = width * percent | 0;
  3219. var i = width - n;
  3220. if (n === lastN && !options.verbose) {
  3221. // Don't re-render the line if it hasn't changed
  3222. return;
  3223. }
  3224. lastN = n;
  3225. cursor.CR();
  3226. process.stdout.write('\u001b[J');
  3227. process.stdout.write(color('progress', ' ' + options.open));
  3228. process.stdout.write(Array(n).join(options.complete));
  3229. process.stdout.write(Array(i).join(options.incomplete));
  3230. process.stdout.write(color('progress', options.close));
  3231. if (options.verbose) {
  3232. process.stdout.write(color('progress', ' ' + complete + ' of ' + total));
  3233. }
  3234. });
  3235. // tests are complete, output some stats
  3236. // and the failures if any
  3237. runner.on('end', function () {
  3238. cursor.show();
  3239. console.log();
  3240. self.epilogue();
  3241. });
  3242. }
  3243. /**
  3244. * Inherit from `Base.prototype`.
  3245. */
  3246. inherits(Progress, Base);
  3247. }).call(this,require('_process'))
  3248. },{"../utils":38,"./base":17,"_process":82}],30:[function(require,module,exports){
  3249. 'use strict';
  3250. /**
  3251. * Module dependencies.
  3252. */
  3253. var Base = require('./base');
  3254. var inherits = require('../utils').inherits;
  3255. var color = Base.color;
  3256. /**
  3257. * Expose `Spec`.
  3258. */
  3259. exports = module.exports = Spec;
  3260. /**
  3261. * Initialize a new `Spec` test reporter.
  3262. *
  3263. * @api public
  3264. * @param {Runner} runner
  3265. */
  3266. function Spec (runner) {
  3267. Base.call(this, runner);
  3268. var self = this;
  3269. var indents = 0;
  3270. var n = 0;
  3271. function indent () {
  3272. return Array(indents).join(' ');
  3273. }
  3274. runner.on('start', function () {
  3275. console.log();
  3276. });
  3277. runner.on('suite', function (suite) {
  3278. ++indents;
  3279. console.log(color('suite', '%s%s'), indent(), suite.title);
  3280. });
  3281. runner.on('suite end', function () {
  3282. --indents;
  3283. if (indents === 1) {
  3284. console.log();
  3285. }
  3286. });
  3287. runner.on('pending', function (test) {
  3288. var fmt = indent() + color('pending', ' - %s');
  3289. console.log(fmt, test.title);
  3290. });
  3291. runner.on('pass', function (test) {
  3292. var fmt;
  3293. if (test.speed === 'fast') {
  3294. fmt = indent() +
  3295. color('checkmark', ' ' + Base.symbols.ok) +
  3296. color('pass', ' %s');
  3297. console.log(fmt, test.title);
  3298. } else {
  3299. fmt = indent() +
  3300. color('checkmark', ' ' + Base.symbols.ok) +
  3301. color('pass', ' %s') +
  3302. color(test.speed, ' (%dms)');
  3303. console.log(fmt, test.title, test.duration);
  3304. }
  3305. });
  3306. runner.on('fail', function (test) {
  3307. console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
  3308. });
  3309. runner.on('end', self.epilogue.bind(self));
  3310. }
  3311. /**
  3312. * Inherit from `Base.prototype`.
  3313. */
  3314. inherits(Spec, Base);
  3315. },{"../utils":38,"./base":17}],31:[function(require,module,exports){
  3316. 'use strict';
  3317. /**
  3318. * Module dependencies.
  3319. */
  3320. var Base = require('./base');
  3321. /**
  3322. * Expose `TAP`.
  3323. */
  3324. exports = module.exports = TAP;
  3325. /**
  3326. * Initialize a new `TAP` reporter.
  3327. *
  3328. * @api public
  3329. * @param {Runner} runner
  3330. */
  3331. function TAP (runner) {
  3332. Base.call(this, runner);
  3333. var n = 1;
  3334. var passes = 0;
  3335. var failures = 0;
  3336. runner.on('start', function () {
  3337. var total = runner.grepTotal(runner.suite);
  3338. console.log('%d..%d', 1, total);
  3339. });
  3340. runner.on('test end', function () {
  3341. ++n;
  3342. });
  3343. runner.on('pending', function (test) {
  3344. console.log('ok %d %s # SKIP -', n, title(test));
  3345. });
  3346. runner.on('pass', function (test) {
  3347. passes++;
  3348. console.log('ok %d %s', n, title(test));
  3349. });
  3350. runner.on('fail', function (test, err) {
  3351. failures++;
  3352. console.log('not ok %d %s', n, title(test));
  3353. if (err.stack) {
  3354. console.log(err.stack.replace(/^/gm, ' '));
  3355. }
  3356. });
  3357. runner.on('end', function () {
  3358. console.log('# tests ' + (passes + failures));
  3359. console.log('# pass ' + passes);
  3360. console.log('# fail ' + failures);
  3361. });
  3362. }
  3363. /**
  3364. * Return a TAP-safe title of `test`
  3365. *
  3366. * @api private
  3367. * @param {Object} test
  3368. * @return {String}
  3369. */
  3370. function title (test) {
  3371. return test.fullTitle().replace(/#/g, '');
  3372. }
  3373. },{"./base":17}],32:[function(require,module,exports){
  3374. (function (process,global){
  3375. 'use strict';
  3376. /**
  3377. * Module dependencies.
  3378. */
  3379. var Base = require('./base');
  3380. var utils = require('../utils');
  3381. var inherits = utils.inherits;
  3382. var fs = require('fs');
  3383. var escape = utils.escape;
  3384. var mkdirp = require('mkdirp');
  3385. var path = require('path');
  3386. /**
  3387. * Save timer references to avoid Sinon interfering (see GH-237).
  3388. */
  3389. /* eslint-disable no-unused-vars, no-native-reassign */
  3390. var Date = global.Date;
  3391. var setTimeout = global.setTimeout;
  3392. var setInterval = global.setInterval;
  3393. var clearTimeout = global.clearTimeout;
  3394. var clearInterval = global.clearInterval;
  3395. /* eslint-enable no-unused-vars, no-native-reassign */
  3396. /**
  3397. * Expose `XUnit`.
  3398. */
  3399. exports = module.exports = XUnit;
  3400. /**
  3401. * Initialize a new `XUnit` reporter.
  3402. *
  3403. * @api public
  3404. * @param {Runner} runner
  3405. */
  3406. function XUnit (runner, options) {
  3407. Base.call(this, runner);
  3408. var stats = this.stats;
  3409. var tests = [];
  3410. var self = this;
  3411. if (options && options.reporterOptions && options.reporterOptions.output) {
  3412. if (!fs.createWriteStream) {
  3413. throw new Error('file output not supported in browser');
  3414. }
  3415. mkdirp.sync(path.dirname(options.reporterOptions.output));
  3416. self.fileStream = fs.createWriteStream(options.reporterOptions.output);
  3417. }
  3418. runner.on('pending', function (test) {
  3419. tests.push(test);
  3420. });
  3421. runner.on('pass', function (test) {
  3422. tests.push(test);
  3423. });
  3424. runner.on('fail', function (test) {
  3425. tests.push(test);
  3426. });
  3427. runner.on('end', function () {
  3428. self.write(tag('testsuite', {
  3429. name: 'Mocha Tests',
  3430. tests: stats.tests,
  3431. failures: stats.failures,
  3432. errors: stats.failures,
  3433. skipped: stats.tests - stats.failures - stats.passes,
  3434. timestamp: (new Date()).toUTCString(),
  3435. time: (stats.duration / 1000) || 0
  3436. }, false));
  3437. tests.forEach(function (t) {
  3438. self.test(t);
  3439. });
  3440. self.write('</testsuite>');
  3441. });
  3442. }
  3443. /**
  3444. * Inherit from `Base.prototype`.
  3445. */
  3446. inherits(XUnit, Base);
  3447. /**
  3448. * Override done to close the stream (if it's a file).
  3449. *
  3450. * @param failures
  3451. * @param {Function} fn
  3452. */
  3453. XUnit.prototype.done = function (failures, fn) {
  3454. if (this.fileStream) {
  3455. this.fileStream.end(function () {
  3456. fn(failures);
  3457. });
  3458. } else {
  3459. fn(failures);
  3460. }
  3461. };
  3462. /**
  3463. * Write out the given line.
  3464. *
  3465. * @param {string} line
  3466. */
  3467. XUnit.prototype.write = function (line) {
  3468. if (this.fileStream) {
  3469. this.fileStream.write(line + '\n');
  3470. } else if (typeof process === 'object' && process.stdout) {
  3471. process.stdout.write(line + '\n');
  3472. } else {
  3473. console.log(line);
  3474. }
  3475. };
  3476. /**
  3477. * Output tag for the given `test.`
  3478. *
  3479. * @param {Test} test
  3480. */
  3481. XUnit.prototype.test = function (test) {
  3482. var attrs = {
  3483. classname: test.parent.fullTitle(),
  3484. name: test.title,
  3485. time: (test.duration / 1000) || 0
  3486. };
  3487. if (test.state === 'failed') {
  3488. var err = test.err;
  3489. this.write(tag('testcase', attrs, false, tag('failure', {}, false, escape(err.message) + '\n' + escape(err.stack))));
  3490. } else if (test.isPending()) {
  3491. this.write(tag('testcase', attrs, false, tag('skipped', {}, true)));
  3492. } else {
  3493. this.write(tag('testcase', attrs, true));
  3494. }
  3495. };
  3496. /**
  3497. * HTML tag helper.
  3498. *
  3499. * @param name
  3500. * @param attrs
  3501. * @param close
  3502. * @param content
  3503. * @return {string}
  3504. */
  3505. function tag (name, attrs, close, content) {
  3506. var end = close ? '/>' : '>';
  3507. var pairs = [];
  3508. var tag;
  3509. for (var key in attrs) {
  3510. if (Object.prototype.hasOwnProperty.call(attrs, key)) {
  3511. pairs.push(key + '="' + escape(attrs[key]) + '"');
  3512. }
  3513. }
  3514. tag = '<' + name + (pairs.length ? ' ' + pairs.join(' ') : '') + end;
  3515. if (content) {
  3516. tag += content + '</' + name + end;
  3517. }
  3518. return tag;
  3519. }
  3520. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3521. },{"../utils":38,"./base":17,"_process":82,"fs":42,"mkdirp":79,"path":42}],33:[function(require,module,exports){
  3522. (function (global){
  3523. 'use strict';
  3524. /**
  3525. * Module dependencies.
  3526. */
  3527. var EventEmitter = require('events').EventEmitter;
  3528. var JSON = require('json3');
  3529. var Pending = require('./pending');
  3530. var debug = require('debug')('mocha:runnable');
  3531. var milliseconds = require('./ms');
  3532. var utils = require('./utils');
  3533. var create = require('lodash.create');
  3534. /**
  3535. * Save timer references to avoid Sinon interfering (see GH-237).
  3536. */
  3537. /* eslint-disable no-unused-vars, no-native-reassign */
  3538. var Date = global.Date;
  3539. var setTimeout = global.setTimeout;
  3540. var setInterval = global.setInterval;
  3541. var clearTimeout = global.clearTimeout;
  3542. var clearInterval = global.clearInterval;
  3543. /* eslint-enable no-unused-vars, no-native-reassign */
  3544. /**
  3545. * Object#toString().
  3546. */
  3547. var toString = Object.prototype.toString;
  3548. /**
  3549. * Expose `Runnable`.
  3550. */
  3551. module.exports = Runnable;
  3552. /**
  3553. * Initialize a new `Runnable` with the given `title` and callback `fn`.
  3554. *
  3555. * @param {String} title
  3556. * @param {Function} fn
  3557. * @api private
  3558. * @param {string} title
  3559. * @param {Function} fn
  3560. */
  3561. function Runnable (title, fn) {
  3562. this.title = title;
  3563. this.fn = fn;
  3564. this.body = (fn || '').toString();
  3565. this.async = fn && fn.length;
  3566. this.sync = !this.async;
  3567. this._timeout = 2000;
  3568. this._slow = 75;
  3569. this._enableTimeouts = true;
  3570. this.timedOut = false;
  3571. this._trace = new Error('done() called multiple times');
  3572. this._retries = -1;
  3573. this._currentRetry = 0;
  3574. this.pending = false;
  3575. }
  3576. /**
  3577. * Inherit from `EventEmitter.prototype`.
  3578. */
  3579. Runnable.prototype = create(EventEmitter.prototype, {
  3580. constructor: Runnable
  3581. });
  3582. /**
  3583. * Set & get timeout `ms`.
  3584. *
  3585. * @api private
  3586. * @param {number|string} ms
  3587. * @return {Runnable|number} ms or Runnable instance.
  3588. */
  3589. Runnable.prototype.timeout = function (ms) {
  3590. if (!arguments.length) {
  3591. return this._timeout;
  3592. }
  3593. // see #1652 for reasoning
  3594. if (ms === 0 || ms > Math.pow(2, 31)) {
  3595. this._enableTimeouts = false;
  3596. }
  3597. if (typeof ms === 'string') {
  3598. ms = milliseconds(ms);
  3599. }
  3600. debug('timeout %d', ms);
  3601. this._timeout = ms;
  3602. if (this.timer) {
  3603. this.resetTimeout();
  3604. }
  3605. return this;
  3606. };
  3607. /**
  3608. * Set & get slow `ms`.
  3609. *
  3610. * @api private
  3611. * @param {number|string} ms
  3612. * @return {Runnable|number} ms or Runnable instance.
  3613. */
  3614. Runnable.prototype.slow = function (ms) {
  3615. if (typeof ms === 'undefined') {
  3616. return this._slow;
  3617. }
  3618. if (typeof ms === 'string') {
  3619. ms = milliseconds(ms);
  3620. }
  3621. debug('timeout %d', ms);
  3622. this._slow = ms;
  3623. return this;
  3624. };
  3625. /**
  3626. * Set and get whether timeout is `enabled`.
  3627. *
  3628. * @api private
  3629. * @param {boolean} enabled
  3630. * @return {Runnable|boolean} enabled or Runnable instance.
  3631. */
  3632. Runnable.prototype.enableTimeouts = function (enabled) {
  3633. if (!arguments.length) {
  3634. return this._enableTimeouts;
  3635. }
  3636. debug('enableTimeouts %s', enabled);
  3637. this._enableTimeouts = enabled;
  3638. return this;
  3639. };
  3640. /**
  3641. * Halt and mark as pending.
  3642. *
  3643. * @api public
  3644. */
  3645. Runnable.prototype.skip = function () {
  3646. throw new Pending('sync skip');
  3647. };
  3648. /**
  3649. * Check if this runnable or its parent suite is marked as pending.
  3650. *
  3651. * @api private
  3652. */
  3653. Runnable.prototype.isPending = function () {
  3654. return this.pending || (this.parent && this.parent.isPending());
  3655. };
  3656. /**
  3657. * Set number of retries.
  3658. *
  3659. * @api private
  3660. */
  3661. Runnable.prototype.retries = function (n) {
  3662. if (!arguments.length) {
  3663. return this._retries;
  3664. }
  3665. this._retries = n;
  3666. };
  3667. /**
  3668. * Get current retry
  3669. *
  3670. * @api private
  3671. */
  3672. Runnable.prototype.currentRetry = function (n) {
  3673. if (!arguments.length) {
  3674. return this._currentRetry;
  3675. }
  3676. this._currentRetry = n;
  3677. };
  3678. /**
  3679. * Return the full title generated by recursively concatenating the parent's
  3680. * full title.
  3681. *
  3682. * @api public
  3683. * @return {string}
  3684. */
  3685. Runnable.prototype.fullTitle = function () {
  3686. return this.parent.fullTitle() + ' ' + this.title;
  3687. };
  3688. /**
  3689. * Clear the timeout.
  3690. *
  3691. * @api private
  3692. */
  3693. Runnable.prototype.clearTimeout = function () {
  3694. clearTimeout(this.timer);
  3695. };
  3696. /**
  3697. * Inspect the runnable void of private properties.
  3698. *
  3699. * @api private
  3700. * @return {string}
  3701. */
  3702. Runnable.prototype.inspect = function () {
  3703. return JSON.stringify(this, function (key, val) {
  3704. if (key[0] === '_') {
  3705. return;
  3706. }
  3707. if (key === 'parent') {
  3708. return '#<Suite>';
  3709. }
  3710. if (key === 'ctx') {
  3711. return '#<Context>';
  3712. }
  3713. return val;
  3714. }, 2);
  3715. };
  3716. /**
  3717. * Reset the timeout.
  3718. *
  3719. * @api private
  3720. */
  3721. Runnable.prototype.resetTimeout = function () {
  3722. var self = this;
  3723. var ms = this.timeout() || 1e9;
  3724. if (!this._enableTimeouts) {
  3725. return;
  3726. }
  3727. this.clearTimeout();
  3728. this.timer = setTimeout(function () {
  3729. if (!self._enableTimeouts) {
  3730. return;
  3731. }
  3732. self.callback(new Error('Timeout of ' + ms +
  3733. 'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.'));
  3734. self.timedOut = true;
  3735. }, ms);
  3736. };
  3737. /**
  3738. * Whitelist a list of globals for this test run.
  3739. *
  3740. * @api private
  3741. * @param {string[]} globals
  3742. */
  3743. Runnable.prototype.globals = function (globals) {
  3744. if (!arguments.length) {
  3745. return this._allowedGlobals;
  3746. }
  3747. this._allowedGlobals = globals;
  3748. };
  3749. /**
  3750. * Run the test and invoke `fn(err)`.
  3751. *
  3752. * @param {Function} fn
  3753. * @api private
  3754. */
  3755. Runnable.prototype.run = function (fn) {
  3756. var self = this;
  3757. var start = new Date();
  3758. var ctx = this.ctx;
  3759. var finished;
  3760. var emitted;
  3761. // Sometimes the ctx exists, but it is not runnable
  3762. if (ctx && ctx.runnable) {
  3763. ctx.runnable(this);
  3764. }
  3765. // called multiple times
  3766. function multiple (err) {
  3767. if (emitted) {
  3768. return;
  3769. }
  3770. emitted = true;
  3771. self.emit('error', err || new Error('done() called multiple times; stacktrace may be inaccurate'));
  3772. }
  3773. // finished
  3774. function done (err) {
  3775. var ms = self.timeout();
  3776. if (self.timedOut) {
  3777. return;
  3778. }
  3779. if (finished) {
  3780. return multiple(err || self._trace);
  3781. }
  3782. self.clearTimeout();
  3783. self.duration = new Date() - start;
  3784. finished = true;
  3785. if (!err && self.duration > ms && self._enableTimeouts) {
  3786. err = new Error('Timeout of ' + ms +
  3787. 'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.');
  3788. }
  3789. fn(err);
  3790. }
  3791. // for .resetTimeout()
  3792. this.callback = done;
  3793. // explicit async with `done` argument
  3794. if (this.async) {
  3795. this.resetTimeout();
  3796. // allows skip() to be used in an explicit async context
  3797. this.skip = function asyncSkip () {
  3798. done(new Pending('async skip call'));
  3799. // halt execution. the Runnable will be marked pending
  3800. // by the previous call, and the uncaught handler will ignore
  3801. // the failure.
  3802. throw new Pending('async skip; aborting execution');
  3803. };
  3804. if (this.allowUncaught) {
  3805. return callFnAsync(this.fn);
  3806. }
  3807. try {
  3808. callFnAsync(this.fn);
  3809. } catch (err) {
  3810. emitted = true;
  3811. done(utils.getError(err));
  3812. }
  3813. return;
  3814. }
  3815. if (this.allowUncaught) {
  3816. if (this.isPending()) {
  3817. done();
  3818. } else {
  3819. callFn(this.fn);
  3820. }
  3821. return;
  3822. }
  3823. // sync or promise-returning
  3824. try {
  3825. if (this.isPending()) {
  3826. done();
  3827. } else {
  3828. callFn(this.fn);
  3829. }
  3830. } catch (err) {
  3831. emitted = true;
  3832. done(utils.getError(err));
  3833. }
  3834. function callFn (fn) {
  3835. var result = fn.call(ctx);
  3836. if (result && typeof result.then === 'function') {
  3837. self.resetTimeout();
  3838. result
  3839. .then(function () {
  3840. done();
  3841. // Return null so libraries like bluebird do not warn about
  3842. // subsequently constructed Promises.
  3843. return null;
  3844. },
  3845. function (reason) {
  3846. done(reason || new Error('Promise rejected with no or falsy reason'));
  3847. });
  3848. } else {
  3849. if (self.asyncOnly) {
  3850. return done(new Error('--async-only option in use without declaring `done()` or returning a promise'));
  3851. }
  3852. done();
  3853. }
  3854. }
  3855. function callFnAsync (fn) {
  3856. var result = fn.call(ctx, function (err) {
  3857. if (err instanceof Error || toString.call(err) === '[object Error]') {
  3858. return done(err);
  3859. }
  3860. if (err) {
  3861. if (Object.prototype.toString.call(err) === '[object Object]') {
  3862. return done(new Error('done() invoked with non-Error: ' +
  3863. JSON.stringify(err)));
  3864. }
  3865. return done(new Error('done() invoked with non-Error: ' + err));
  3866. }
  3867. if (result && utils.isPromise(result)) {
  3868. return done(new Error('Resolution method is overspecified. Specify a callback *or* return a Promise; not both.'));
  3869. }
  3870. done();
  3871. });
  3872. }
  3873. };
  3874. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3875. },{"./ms":15,"./pending":16,"./utils":38,"debug":2,"events":3,"json3":69,"lodash.create":75}],34:[function(require,module,exports){
  3876. (function (process,global){
  3877. 'use strict';
  3878. /**
  3879. * Module dependencies.
  3880. */
  3881. var EventEmitter = require('events').EventEmitter;
  3882. var Pending = require('./pending');
  3883. var utils = require('./utils');
  3884. var inherits = utils.inherits;
  3885. var debug = require('debug')('mocha:runner');
  3886. var Runnable = require('./runnable');
  3887. var filter = utils.filter;
  3888. var indexOf = utils.indexOf;
  3889. var some = utils.some;
  3890. var keys = utils.keys;
  3891. var stackFilter = utils.stackTraceFilter();
  3892. var stringify = utils.stringify;
  3893. var type = utils.type;
  3894. var undefinedError = utils.undefinedError;
  3895. var isArray = utils.isArray;
  3896. /**
  3897. * Non-enumerable globals.
  3898. */
  3899. var globals = [
  3900. 'setTimeout',
  3901. 'clearTimeout',
  3902. 'setInterval',
  3903. 'clearInterval',
  3904. 'XMLHttpRequest',
  3905. 'Date',
  3906. 'setImmediate',
  3907. 'clearImmediate'
  3908. ];
  3909. /**
  3910. * Expose `Runner`.
  3911. */
  3912. module.exports = Runner;
  3913. /**
  3914. * Initialize a `Runner` for the given `suite`.
  3915. *
  3916. * Events:
  3917. *
  3918. * - `start` execution started
  3919. * - `end` execution complete
  3920. * - `suite` (suite) test suite execution started
  3921. * - `suite end` (suite) all tests (and sub-suites) have finished
  3922. * - `test` (test) test execution started
  3923. * - `test end` (test) test completed
  3924. * - `hook` (hook) hook execution started
  3925. * - `hook end` (hook) hook complete
  3926. * - `pass` (test) test passed
  3927. * - `fail` (test, err) test failed
  3928. * - `pending` (test) test pending
  3929. *
  3930. * @api public
  3931. * @param {Suite} suite Root suite
  3932. * @param {boolean} [delay] Whether or not to delay execution of root suite
  3933. * until ready.
  3934. */
  3935. function Runner (suite, delay) {
  3936. var self = this;
  3937. this._globals = [];
  3938. this._abort = false;
  3939. this._delay = delay;
  3940. this.suite = suite;
  3941. this.started = false;
  3942. this.total = suite.total();
  3943. this.failures = 0;
  3944. this.on('test end', function (test) {
  3945. self.checkGlobals(test);
  3946. });
  3947. this.on('hook end', function (hook) {
  3948. self.checkGlobals(hook);
  3949. });
  3950. this._defaultGrep = /.*/;
  3951. this.grep(this._defaultGrep);
  3952. this.globals(this.globalProps().concat(extraGlobals()));
  3953. }
  3954. /**
  3955. * Wrapper for setImmediate, process.nextTick, or browser polyfill.
  3956. *
  3957. * @param {Function} fn
  3958. * @api private
  3959. */
  3960. Runner.immediately = global.setImmediate || process.nextTick;
  3961. /**
  3962. * Inherit from `EventEmitter.prototype`.
  3963. */
  3964. inherits(Runner, EventEmitter);
  3965. /**
  3966. * Run tests with full titles matching `re`. Updates runner.total
  3967. * with number of tests matched.
  3968. *
  3969. * @param {RegExp} re
  3970. * @param {Boolean} invert
  3971. * @return {Runner} for chaining
  3972. * @api public
  3973. * @param {RegExp} re
  3974. * @param {boolean} invert
  3975. * @return {Runner} Runner instance.
  3976. */
  3977. Runner.prototype.grep = function (re, invert) {
  3978. debug('grep %s', re);
  3979. this._grep = re;
  3980. this._invert = invert;
  3981. this.total = this.grepTotal(this.suite);
  3982. return this;
  3983. };
  3984. /**
  3985. * Returns the number of tests matching the grep search for the
  3986. * given suite.
  3987. *
  3988. * @param {Suite} suite
  3989. * @return {Number}
  3990. * @api public
  3991. * @param {Suite} suite
  3992. * @return {number}
  3993. */
  3994. Runner.prototype.grepTotal = function (suite) {
  3995. var self = this;
  3996. var total = 0;
  3997. suite.eachTest(function (test) {
  3998. var match = self._grep.test(test.fullTitle());
  3999. if (self._invert) {
  4000. match = !match;
  4001. }
  4002. if (match) {
  4003. total++;
  4004. }
  4005. });
  4006. return total;
  4007. };
  4008. /**
  4009. * Return a list of global properties.
  4010. *
  4011. * @return {Array}
  4012. * @api private
  4013. */
  4014. Runner.prototype.globalProps = function () {
  4015. var props = keys(global);
  4016. // non-enumerables
  4017. for (var i = 0; i < globals.length; ++i) {
  4018. if (~indexOf(props, globals[i])) {
  4019. continue;
  4020. }
  4021. props.push(globals[i]);
  4022. }
  4023. return props;
  4024. };
  4025. /**
  4026. * Allow the given `arr` of globals.
  4027. *
  4028. * @param {Array} arr
  4029. * @return {Runner} for chaining
  4030. * @api public
  4031. * @param {Array} arr
  4032. * @return {Runner} Runner instance.
  4033. */
  4034. Runner.prototype.globals = function (arr) {
  4035. if (!arguments.length) {
  4036. return this._globals;
  4037. }
  4038. debug('globals %j', arr);
  4039. this._globals = this._globals.concat(arr);
  4040. return this;
  4041. };
  4042. /**
  4043. * Check for global variable leaks.
  4044. *
  4045. * @api private
  4046. */
  4047. Runner.prototype.checkGlobals = function (test) {
  4048. if (this.ignoreLeaks) {
  4049. return;
  4050. }
  4051. var ok = this._globals;
  4052. var globals = this.globalProps();
  4053. var leaks;
  4054. if (test) {
  4055. ok = ok.concat(test._allowedGlobals || []);
  4056. }
  4057. if (this.prevGlobalsLength === globals.length) {
  4058. return;
  4059. }
  4060. this.prevGlobalsLength = globals.length;
  4061. leaks = filterLeaks(ok, globals);
  4062. this._globals = this._globals.concat(leaks);
  4063. if (leaks.length > 1) {
  4064. this.fail(test, new Error('global leaks detected: ' + leaks.join(', ') + ''));
  4065. } else if (leaks.length) {
  4066. this.fail(test, new Error('global leak detected: ' + leaks[0]));
  4067. }
  4068. };
  4069. /**
  4070. * Fail the given `test`.
  4071. *
  4072. * @api private
  4073. * @param {Test} test
  4074. * @param {Error} err
  4075. */
  4076. Runner.prototype.fail = function (test, err) {
  4077. if (test.isPending()) {
  4078. return;
  4079. }
  4080. ++this.failures;
  4081. test.state = 'failed';
  4082. if (!(err instanceof Error || err && typeof err.message === 'string')) {
  4083. err = new Error('the ' + type(err) + ' ' + stringify(err) + ' was thrown, throw an Error :)');
  4084. }
  4085. try {
  4086. err.stack = (this.fullStackTrace || !err.stack)
  4087. ? err.stack
  4088. : stackFilter(err.stack);
  4089. } catch (ignored) {
  4090. // some environments do not take kindly to monkeying with the stack
  4091. }
  4092. this.emit('fail', test, err);
  4093. };
  4094. /**
  4095. * Fail the given `hook` with `err`.
  4096. *
  4097. * Hook failures work in the following pattern:
  4098. * - If bail, then exit
  4099. * - Failed `before` hook skips all tests in a suite and subsuites,
  4100. * but jumps to corresponding `after` hook
  4101. * - Failed `before each` hook skips remaining tests in a
  4102. * suite and jumps to corresponding `after each` hook,
  4103. * which is run only once
  4104. * - Failed `after` hook does not alter
  4105. * execution order
  4106. * - Failed `after each` hook skips remaining tests in a
  4107. * suite and subsuites, but executes other `after each`
  4108. * hooks
  4109. *
  4110. * @api private
  4111. * @param {Hook} hook
  4112. * @param {Error} err
  4113. */
  4114. Runner.prototype.failHook = function (hook, err) {
  4115. if (hook.ctx && hook.ctx.currentTest) {
  4116. hook.originalTitle = hook.originalTitle || hook.title;
  4117. hook.title = hook.originalTitle + ' for "' + hook.ctx.currentTest.title + '"';
  4118. }
  4119. this.fail(hook, err);
  4120. if (this.suite.bail()) {
  4121. this.emit('end');
  4122. }
  4123. };
  4124. /**
  4125. * Run hook `name` callbacks and then invoke `fn()`.
  4126. *
  4127. * @api private
  4128. * @param {string} name
  4129. * @param {Function} fn
  4130. */
  4131. Runner.prototype.hook = function (name, fn) {
  4132. var suite = this.suite;
  4133. var hooks = suite['_' + name];
  4134. var self = this;
  4135. function next (i) {
  4136. var hook = hooks[i];
  4137. if (!hook) {
  4138. return fn();
  4139. }
  4140. self.currentRunnable = hook;
  4141. hook.ctx.currentTest = self.test;
  4142. self.emit('hook', hook);
  4143. if (!hook.listeners('error').length) {
  4144. hook.on('error', function (err) {
  4145. self.failHook(hook, err);
  4146. });
  4147. }
  4148. hook.run(function (err) {
  4149. var testError = hook.error();
  4150. if (testError) {
  4151. self.fail(self.test, testError);
  4152. }
  4153. if (err) {
  4154. if (err instanceof Pending) {
  4155. if (name === 'beforeEach' || name === 'afterEach') {
  4156. self.test.pending = true;
  4157. } else {
  4158. utils.forEach(suite.tests, function (test) {
  4159. test.pending = true;
  4160. });
  4161. // a pending hook won't be executed twice.
  4162. hook.pending = true;
  4163. }
  4164. } else {
  4165. self.failHook(hook, err);
  4166. // stop executing hooks, notify callee of hook err
  4167. return fn(err);
  4168. }
  4169. }
  4170. self.emit('hook end', hook);
  4171. delete hook.ctx.currentTest;
  4172. next(++i);
  4173. });
  4174. }
  4175. Runner.immediately(function () {
  4176. next(0);
  4177. });
  4178. };
  4179. /**
  4180. * Run hook `name` for the given array of `suites`
  4181. * in order, and callback `fn(err, errSuite)`.
  4182. *
  4183. * @api private
  4184. * @param {string} name
  4185. * @param {Array} suites
  4186. * @param {Function} fn
  4187. */
  4188. Runner.prototype.hooks = function (name, suites, fn) {
  4189. var self = this;
  4190. var orig = this.suite;
  4191. function next (suite) {
  4192. self.suite = suite;
  4193. if (!suite) {
  4194. self.suite = orig;
  4195. return fn();
  4196. }
  4197. self.hook(name, function (err) {
  4198. if (err) {
  4199. var errSuite = self.suite;
  4200. self.suite = orig;
  4201. return fn(err, errSuite);
  4202. }
  4203. next(suites.pop());
  4204. });
  4205. }
  4206. next(suites.pop());
  4207. };
  4208. /**
  4209. * Run hooks from the top level down.
  4210. *
  4211. * @param {String} name
  4212. * @param {Function} fn
  4213. * @api private
  4214. */
  4215. Runner.prototype.hookUp = function (name, fn) {
  4216. var suites = [this.suite].concat(this.parents()).reverse();
  4217. this.hooks(name, suites, fn);
  4218. };
  4219. /**
  4220. * Run hooks from the bottom up.
  4221. *
  4222. * @param {String} name
  4223. * @param {Function} fn
  4224. * @api private
  4225. */
  4226. Runner.prototype.hookDown = function (name, fn) {
  4227. var suites = [this.suite].concat(this.parents());
  4228. this.hooks(name, suites, fn);
  4229. };
  4230. /**
  4231. * Return an array of parent Suites from
  4232. * closest to furthest.
  4233. *
  4234. * @return {Array}
  4235. * @api private
  4236. */
  4237. Runner.prototype.parents = function () {
  4238. var suite = this.suite;
  4239. var suites = [];
  4240. while (suite.parent) {
  4241. suite = suite.parent;
  4242. suites.push(suite);
  4243. }
  4244. return suites;
  4245. };
  4246. /**
  4247. * Run the current test and callback `fn(err)`.
  4248. *
  4249. * @param {Function} fn
  4250. * @api private
  4251. */
  4252. Runner.prototype.runTest = function (fn) {
  4253. var self = this;
  4254. var test = this.test;
  4255. if (!test) {
  4256. return;
  4257. }
  4258. if (this.asyncOnly) {
  4259. test.asyncOnly = true;
  4260. }
  4261. test.on('error', function (err) {
  4262. self.fail(test, err);
  4263. });
  4264. if (this.allowUncaught) {
  4265. test.allowUncaught = true;
  4266. return test.run(fn);
  4267. }
  4268. try {
  4269. test.run(fn);
  4270. } catch (err) {
  4271. fn(err);
  4272. }
  4273. };
  4274. /**
  4275. * Run tests in the given `suite` and invoke the callback `fn()` when complete.
  4276. *
  4277. * @api private
  4278. * @param {Suite} suite
  4279. * @param {Function} fn
  4280. */
  4281. Runner.prototype.runTests = function (suite, fn) {
  4282. var self = this;
  4283. var tests = suite.tests.slice();
  4284. var test;
  4285. function hookErr (_, errSuite, after) {
  4286. // before/after Each hook for errSuite failed:
  4287. var orig = self.suite;
  4288. // for failed 'after each' hook start from errSuite parent,
  4289. // otherwise start from errSuite itself
  4290. self.suite = after ? errSuite.parent : errSuite;
  4291. if (self.suite) {
  4292. // call hookUp afterEach
  4293. self.hookUp('afterEach', function (err2, errSuite2) {
  4294. self.suite = orig;
  4295. // some hooks may fail even now
  4296. if (err2) {
  4297. return hookErr(err2, errSuite2, true);
  4298. }
  4299. // report error suite
  4300. fn(errSuite);
  4301. });
  4302. } else {
  4303. // there is no need calling other 'after each' hooks
  4304. self.suite = orig;
  4305. fn(errSuite);
  4306. }
  4307. }
  4308. function next (err, errSuite) {
  4309. // if we bail after first err
  4310. if (self.failures && suite._bail) {
  4311. return fn();
  4312. }
  4313. if (self._abort) {
  4314. return fn();
  4315. }
  4316. if (err) {
  4317. return hookErr(err, errSuite, true);
  4318. }
  4319. // next test
  4320. test = tests.shift();
  4321. // all done
  4322. if (!test) {
  4323. return fn();
  4324. }
  4325. // grep
  4326. var match = self._grep.test(test.fullTitle());
  4327. if (self._invert) {
  4328. match = !match;
  4329. }
  4330. if (!match) {
  4331. // Run immediately only if we have defined a grep. When we
  4332. // define a grep — It can cause maximum callstack error if
  4333. // the grep is doing a large recursive loop by neglecting
  4334. // all tests. The run immediately function also comes with
  4335. // a performance cost. So we don't want to run immediately
  4336. // if we run the whole test suite, because running the whole
  4337. // test suite don't do any immediate recursive loops. Thus,
  4338. // allowing a JS runtime to breathe.
  4339. if (self._grep !== self._defaultGrep) {
  4340. Runner.immediately(next);
  4341. } else {
  4342. next();
  4343. }
  4344. return;
  4345. }
  4346. if (test.isPending()) {
  4347. self.emit('pending', test);
  4348. self.emit('test end', test);
  4349. return next();
  4350. }
  4351. // execute test and hook(s)
  4352. self.emit('test', self.test = test);
  4353. self.hookDown('beforeEach', function (err, errSuite) {
  4354. if (test.isPending()) {
  4355. self.emit('pending', test);
  4356. self.emit('test end', test);
  4357. return next();
  4358. }
  4359. if (err) {
  4360. return hookErr(err, errSuite, false);
  4361. }
  4362. self.currentRunnable = self.test;
  4363. self.runTest(function (err) {
  4364. test = self.test;
  4365. if (err) {
  4366. var retry = test.currentRetry();
  4367. if (err instanceof Pending) {
  4368. test.pending = true;
  4369. self.emit('pending', test);
  4370. } else if (retry < test.retries()) {
  4371. var clonedTest = test.clone();
  4372. clonedTest.currentRetry(retry + 1);
  4373. tests.unshift(clonedTest);
  4374. // Early return + hook trigger so that it doesn't
  4375. // increment the count wrong
  4376. return self.hookUp('afterEach', next);
  4377. } else {
  4378. self.fail(test, err);
  4379. }
  4380. self.emit('test end', test);
  4381. if (err instanceof Pending) {
  4382. return next();
  4383. }
  4384. return self.hookUp('afterEach', next);
  4385. }
  4386. test.state = 'passed';
  4387. self.emit('pass', test);
  4388. self.emit('test end', test);
  4389. self.hookUp('afterEach', next);
  4390. });
  4391. });
  4392. }
  4393. this.next = next;
  4394. this.hookErr = hookErr;
  4395. next();
  4396. };
  4397. /**
  4398. * Run the given `suite` and invoke the callback `fn()` when complete.
  4399. *
  4400. * @api private
  4401. * @param {Suite} suite
  4402. * @param {Function} fn
  4403. */
  4404. Runner.prototype.runSuite = function (suite, fn) {
  4405. var i = 0;
  4406. var self = this;
  4407. var total = this.grepTotal(suite);
  4408. var afterAllHookCalled = false;
  4409. debug('run suite %s', suite.fullTitle());
  4410. if (!total || (self.failures && suite._bail)) {
  4411. return fn();
  4412. }
  4413. this.emit('suite', this.suite = suite);
  4414. function next (errSuite) {
  4415. if (errSuite) {
  4416. // current suite failed on a hook from errSuite
  4417. if (errSuite === suite) {
  4418. // if errSuite is current suite
  4419. // continue to the next sibling suite
  4420. return done();
  4421. }
  4422. // errSuite is among the parents of current suite
  4423. // stop execution of errSuite and all sub-suites
  4424. return done(errSuite);
  4425. }
  4426. if (self._abort) {
  4427. return done();
  4428. }
  4429. var curr = suite.suites[i++];
  4430. if (!curr) {
  4431. return done();
  4432. }
  4433. // Avoid grep neglecting large number of tests causing a
  4434. // huge recursive loop and thus a maximum call stack error.
  4435. // See comment in `this.runTests()` for more information.
  4436. if (self._grep !== self._defaultGrep) {
  4437. Runner.immediately(function () {
  4438. self.runSuite(curr, next);
  4439. });
  4440. } else {
  4441. self.runSuite(curr, next);
  4442. }
  4443. }
  4444. function done (errSuite) {
  4445. self.suite = suite;
  4446. self.nextSuite = next;
  4447. if (afterAllHookCalled) {
  4448. fn(errSuite);
  4449. } else {
  4450. // mark that the afterAll block has been called once
  4451. // and so can be skipped if there is an error in it.
  4452. afterAllHookCalled = true;
  4453. // remove reference to test
  4454. delete self.test;
  4455. self.hook('afterAll', function () {
  4456. self.emit('suite end', suite);
  4457. fn(errSuite);
  4458. });
  4459. }
  4460. }
  4461. this.nextSuite = next;
  4462. this.hook('beforeAll', function (err) {
  4463. if (err) {
  4464. return done();
  4465. }
  4466. self.runTests(suite, next);
  4467. });
  4468. };
  4469. /**
  4470. * Handle uncaught exceptions.
  4471. *
  4472. * @param {Error} err
  4473. * @api private
  4474. */
  4475. Runner.prototype.uncaught = function (err) {
  4476. if (err) {
  4477. debug('uncaught exception %s', err === (function () {
  4478. return this;
  4479. }.call(err)) ? (err.message || err) : err);
  4480. } else {
  4481. debug('uncaught undefined exception');
  4482. err = undefinedError();
  4483. }
  4484. err.uncaught = true;
  4485. var runnable = this.currentRunnable;
  4486. if (!runnable) {
  4487. runnable = new Runnable('Uncaught error outside test suite');
  4488. runnable.parent = this.suite;
  4489. if (this.started) {
  4490. this.fail(runnable, err);
  4491. } else {
  4492. // Can't recover from this failure
  4493. this.emit('start');
  4494. this.fail(runnable, err);
  4495. this.emit('end');
  4496. }
  4497. return;
  4498. }
  4499. runnable.clearTimeout();
  4500. // Ignore errors if complete or pending
  4501. if (runnable.state || runnable.isPending()) {
  4502. return;
  4503. }
  4504. this.fail(runnable, err);
  4505. // recover from test
  4506. if (runnable.type === 'test') {
  4507. this.emit('test end', runnable);
  4508. this.hookUp('afterEach', this.next);
  4509. return;
  4510. }
  4511. // recover from hooks
  4512. if (runnable.type === 'hook') {
  4513. var errSuite = this.suite;
  4514. // if hook failure is in afterEach block
  4515. if (runnable.fullTitle().indexOf('after each') > -1) {
  4516. return this.hookErr(err, errSuite, true);
  4517. }
  4518. // if hook failure is in beforeEach block
  4519. if (runnable.fullTitle().indexOf('before each') > -1) {
  4520. return this.hookErr(err, errSuite, false);
  4521. }
  4522. // if hook failure is in after or before blocks
  4523. return this.nextSuite(errSuite);
  4524. }
  4525. // bail
  4526. this.emit('end');
  4527. };
  4528. /**
  4529. * Cleans up the references to all the deferred functions
  4530. * (before/after/beforeEach/afterEach) and tests of a Suite.
  4531. * These must be deleted otherwise a memory leak can happen,
  4532. * as those functions may reference variables from closures,
  4533. * thus those variables can never be garbage collected as long
  4534. * as the deferred functions exist.
  4535. *
  4536. * @param {Suite} suite
  4537. */
  4538. function cleanSuiteReferences (suite) {
  4539. function cleanArrReferences (arr) {
  4540. for (var i = 0; i < arr.length; i++) {
  4541. delete arr[i].fn;
  4542. }
  4543. }
  4544. if (isArray(suite._beforeAll)) {
  4545. cleanArrReferences(suite._beforeAll);
  4546. }
  4547. if (isArray(suite._beforeEach)) {
  4548. cleanArrReferences(suite._beforeEach);
  4549. }
  4550. if (isArray(suite._afterAll)) {
  4551. cleanArrReferences(suite._afterAll);
  4552. }
  4553. if (isArray(suite._afterEach)) {
  4554. cleanArrReferences(suite._afterEach);
  4555. }
  4556. for (var i = 0; i < suite.tests.length; i++) {
  4557. delete suite.tests[i].fn;
  4558. }
  4559. }
  4560. /**
  4561. * Run the root suite and invoke `fn(failures)`
  4562. * on completion.
  4563. *
  4564. * @param {Function} fn
  4565. * @return {Runner} for chaining
  4566. * @api public
  4567. * @param {Function} fn
  4568. * @return {Runner} Runner instance.
  4569. */
  4570. Runner.prototype.run = function (fn) {
  4571. var self = this;
  4572. var rootSuite = this.suite;
  4573. // If there is an `only` filter
  4574. if (this.hasOnly) {
  4575. filterOnly(rootSuite);
  4576. }
  4577. fn = fn || function () {};
  4578. function uncaught (err) {
  4579. self.uncaught(err);
  4580. }
  4581. function start () {
  4582. self.started = true;
  4583. self.emit('start');
  4584. self.runSuite(rootSuite, function () {
  4585. debug('finished running');
  4586. self.emit('end');
  4587. });
  4588. }
  4589. debug('start');
  4590. // references cleanup to avoid memory leaks
  4591. this.on('suite end', cleanSuiteReferences);
  4592. // callback
  4593. this.on('end', function () {
  4594. debug('end');
  4595. process.removeListener('uncaughtException', uncaught);
  4596. fn(self.failures);
  4597. });
  4598. // uncaught exception
  4599. process.on('uncaughtException', uncaught);
  4600. if (this._delay) {
  4601. // for reporters, I guess.
  4602. // might be nice to debounce some dots while we wait.
  4603. this.emit('waiting', rootSuite);
  4604. rootSuite.once('run', start);
  4605. } else {
  4606. start();
  4607. }
  4608. return this;
  4609. };
  4610. /**
  4611. * Cleanly abort execution.
  4612. *
  4613. * @api public
  4614. * @return {Runner} Runner instance.
  4615. */
  4616. Runner.prototype.abort = function () {
  4617. debug('aborting');
  4618. this._abort = true;
  4619. return this;
  4620. };
  4621. /**
  4622. * Filter suites based on `isOnly` logic.
  4623. *
  4624. * @param {Array} suite
  4625. * @returns {Boolean}
  4626. * @api private
  4627. */
  4628. function filterOnly (suite) {
  4629. if (suite._onlyTests.length) {
  4630. // If the suite contains `only` tests, run those and ignore any nested suites.
  4631. suite.tests = suite._onlyTests;
  4632. suite.suites = [];
  4633. } else {
  4634. // Otherwise, do not run any of the tests in this suite.
  4635. suite.tests = [];
  4636. utils.forEach(suite._onlySuites, function (onlySuite) {
  4637. // If there are other `only` tests/suites nested in the current `only` suite, then filter that `only` suite.
  4638. // Otherwise, all of the tests on this `only` suite should be run, so don't filter it.
  4639. if (hasOnly(onlySuite)) {
  4640. filterOnly(onlySuite);
  4641. }
  4642. });
  4643. // Run the `only` suites, as well as any other suites that have `only` tests/suites as descendants.
  4644. suite.suites = filter(suite.suites, function (childSuite) {
  4645. return indexOf(suite._onlySuites, childSuite) !== -1 || filterOnly(childSuite);
  4646. });
  4647. }
  4648. // Keep the suite only if there is something to run
  4649. return suite.tests.length || suite.suites.length;
  4650. }
  4651. /**
  4652. * Determines whether a suite has an `only` test or suite as a descendant.
  4653. *
  4654. * @param {Array} suite
  4655. * @returns {Boolean}
  4656. * @api private
  4657. */
  4658. function hasOnly (suite) {
  4659. return suite._onlyTests.length || suite._onlySuites.length || some(suite.suites, hasOnly);
  4660. }
  4661. /**
  4662. * Filter leaks with the given globals flagged as `ok`.
  4663. *
  4664. * @api private
  4665. * @param {Array} ok
  4666. * @param {Array} globals
  4667. * @return {Array}
  4668. */
  4669. function filterLeaks (ok, globals) {
  4670. return filter(globals, function (key) {
  4671. // Firefox and Chrome exposes iframes as index inside the window object
  4672. if (/^\d+/.test(key)) {
  4673. return false;
  4674. }
  4675. // in firefox
  4676. // if runner runs in an iframe, this iframe's window.getInterface method
  4677. // not init at first it is assigned in some seconds
  4678. if (global.navigator && (/^getInterface/).test(key)) {
  4679. return false;
  4680. }
  4681. // an iframe could be approached by window[iframeIndex]
  4682. // in ie6,7,8 and opera, iframeIndex is enumerable, this could cause leak
  4683. if (global.navigator && (/^\d+/).test(key)) {
  4684. return false;
  4685. }
  4686. // Opera and IE expose global variables for HTML element IDs (issue #243)
  4687. if (/^mocha-/.test(key)) {
  4688. return false;
  4689. }
  4690. var matched = filter(ok, function (ok) {
  4691. if (~ok.indexOf('*')) {
  4692. return key.indexOf(ok.split('*')[0]) === 0;
  4693. }
  4694. return key === ok;
  4695. });
  4696. return !matched.length && (!global.navigator || key !== 'onerror');
  4697. });
  4698. }
  4699. /**
  4700. * Array of globals dependent on the environment.
  4701. *
  4702. * @return {Array}
  4703. * @api private
  4704. */
  4705. function extraGlobals () {
  4706. if (typeof process === 'object' && typeof process.version === 'string') {
  4707. var parts = process.version.split('.');
  4708. var nodeVersion = utils.reduce(parts, function (a, v) {
  4709. return a << 8 | v;
  4710. });
  4711. // 'errno' was renamed to process._errno in v0.9.11.
  4712. if (nodeVersion < 0x00090B) {
  4713. return ['errno'];
  4714. }
  4715. }
  4716. return [];
  4717. }
  4718. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  4719. },{"./pending":16,"./runnable":33,"./utils":38,"_process":82,"debug":2,"events":3}],35:[function(require,module,exports){
  4720. 'use strict';
  4721. /**
  4722. * Module dependencies.
  4723. */
  4724. var EventEmitter = require('events').EventEmitter;
  4725. var Hook = require('./hook');
  4726. var utils = require('./utils');
  4727. var inherits = utils.inherits;
  4728. var debug = require('debug')('mocha:suite');
  4729. var milliseconds = require('./ms');
  4730. /**
  4731. * Expose `Suite`.
  4732. */
  4733. exports = module.exports = Suite;
  4734. /**
  4735. * Create a new `Suite` with the given `title` and parent `Suite`. When a suite
  4736. * with the same title is already present, that suite is returned to provide
  4737. * nicer reporter and more flexible meta-testing.
  4738. *
  4739. * @api public
  4740. * @param {Suite} parent
  4741. * @param {string} title
  4742. * @return {Suite}
  4743. */
  4744. exports.create = function (parent, title) {
  4745. var suite = new Suite(title, parent.ctx);
  4746. suite.parent = parent;
  4747. title = suite.fullTitle();
  4748. parent.addSuite(suite);
  4749. return suite;
  4750. };
  4751. /**
  4752. * Initialize a new `Suite` with the given `title` and `ctx`.
  4753. *
  4754. * @api private
  4755. * @param {string} title
  4756. * @param {Context} parentContext
  4757. */
  4758. function Suite (title, parentContext) {
  4759. if (!utils.isString(title)) {
  4760. throw new Error('Suite `title` should be a "string" but "' + typeof title + '" was given instead.');
  4761. }
  4762. this.title = title;
  4763. function Context () {}
  4764. Context.prototype = parentContext;
  4765. this.ctx = new Context();
  4766. this.suites = [];
  4767. this.tests = [];
  4768. this.pending = false;
  4769. this._beforeEach = [];
  4770. this._beforeAll = [];
  4771. this._afterEach = [];
  4772. this._afterAll = [];
  4773. this.root = !title;
  4774. this._timeout = 2000;
  4775. this._enableTimeouts = true;
  4776. this._slow = 75;
  4777. this._bail = false;
  4778. this._retries = -1;
  4779. this._onlyTests = [];
  4780. this._onlySuites = [];
  4781. this.delayed = false;
  4782. }
  4783. /**
  4784. * Inherit from `EventEmitter.prototype`.
  4785. */
  4786. inherits(Suite, EventEmitter);
  4787. /**
  4788. * Return a clone of this `Suite`.
  4789. *
  4790. * @api private
  4791. * @return {Suite}
  4792. */
  4793. Suite.prototype.clone = function () {
  4794. var suite = new Suite(this.title);
  4795. debug('clone');
  4796. suite.ctx = this.ctx;
  4797. suite.timeout(this.timeout());
  4798. suite.retries(this.retries());
  4799. suite.enableTimeouts(this.enableTimeouts());
  4800. suite.slow(this.slow());
  4801. suite.bail(this.bail());
  4802. return suite;
  4803. };
  4804. /**
  4805. * Set timeout `ms` or short-hand such as "2s".
  4806. *
  4807. * @api private
  4808. * @param {number|string} ms
  4809. * @return {Suite|number} for chaining
  4810. */
  4811. Suite.prototype.timeout = function (ms) {
  4812. if (!arguments.length) {
  4813. return this._timeout;
  4814. }
  4815. if (ms.toString() === '0') {
  4816. this._enableTimeouts = false;
  4817. }
  4818. if (typeof ms === 'string') {
  4819. ms = milliseconds(ms);
  4820. }
  4821. debug('timeout %d', ms);
  4822. this._timeout = parseInt(ms, 10);
  4823. return this;
  4824. };
  4825. /**
  4826. * Set number of times to retry a failed test.
  4827. *
  4828. * @api private
  4829. * @param {number|string} n
  4830. * @return {Suite|number} for chaining
  4831. */
  4832. Suite.prototype.retries = function (n) {
  4833. if (!arguments.length) {
  4834. return this._retries;
  4835. }
  4836. debug('retries %d', n);
  4837. this._retries = parseInt(n, 10) || 0;
  4838. return this;
  4839. };
  4840. /**
  4841. * Set timeout to `enabled`.
  4842. *
  4843. * @api private
  4844. * @param {boolean} enabled
  4845. * @return {Suite|boolean} self or enabled
  4846. */
  4847. Suite.prototype.enableTimeouts = function (enabled) {
  4848. if (!arguments.length) {
  4849. return this._enableTimeouts;
  4850. }
  4851. debug('enableTimeouts %s', enabled);
  4852. this._enableTimeouts = enabled;
  4853. return this;
  4854. };
  4855. /**
  4856. * Set slow `ms` or short-hand such as "2s".
  4857. *
  4858. * @api private
  4859. * @param {number|string} ms
  4860. * @return {Suite|number} for chaining
  4861. */
  4862. Suite.prototype.slow = function (ms) {
  4863. if (!arguments.length) {
  4864. return this._slow;
  4865. }
  4866. if (typeof ms === 'string') {
  4867. ms = milliseconds(ms);
  4868. }
  4869. debug('slow %d', ms);
  4870. this._slow = ms;
  4871. return this;
  4872. };
  4873. /**
  4874. * Sets whether to bail after first error.
  4875. *
  4876. * @api private
  4877. * @param {boolean} bail
  4878. * @return {Suite|number} for chaining
  4879. */
  4880. Suite.prototype.bail = function (bail) {
  4881. if (!arguments.length) {
  4882. return this._bail;
  4883. }
  4884. debug('bail %s', bail);
  4885. this._bail = bail;
  4886. return this;
  4887. };
  4888. /**
  4889. * Check if this suite or its parent suite is marked as pending.
  4890. *
  4891. * @api private
  4892. */
  4893. Suite.prototype.isPending = function () {
  4894. return this.pending || (this.parent && this.parent.isPending());
  4895. };
  4896. /**
  4897. * Run `fn(test[, done])` before running tests.
  4898. *
  4899. * @api private
  4900. * @param {string} title
  4901. * @param {Function} fn
  4902. * @return {Suite} for chaining
  4903. */
  4904. Suite.prototype.beforeAll = function (title, fn) {
  4905. if (this.isPending()) {
  4906. return this;
  4907. }
  4908. if (typeof title === 'function') {
  4909. fn = title;
  4910. title = fn.name;
  4911. }
  4912. title = '"before all" hook' + (title ? ': ' + title : '');
  4913. var hook = new Hook(title, fn);
  4914. hook.parent = this;
  4915. hook.timeout(this.timeout());
  4916. hook.retries(this.retries());
  4917. hook.enableTimeouts(this.enableTimeouts());
  4918. hook.slow(this.slow());
  4919. hook.ctx = this.ctx;
  4920. this._beforeAll.push(hook);
  4921. this.emit('beforeAll', hook);
  4922. return this;
  4923. };
  4924. /**
  4925. * Run `fn(test[, done])` after running tests.
  4926. *
  4927. * @api private
  4928. * @param {string} title
  4929. * @param {Function} fn
  4930. * @return {Suite} for chaining
  4931. */
  4932. Suite.prototype.afterAll = function (title, fn) {
  4933. if (this.isPending()) {
  4934. return this;
  4935. }
  4936. if (typeof title === 'function') {
  4937. fn = title;
  4938. title = fn.name;
  4939. }
  4940. title = '"after all" hook' + (title ? ': ' + title : '');
  4941. var hook = new Hook(title, fn);
  4942. hook.parent = this;
  4943. hook.timeout(this.timeout());
  4944. hook.retries(this.retries());
  4945. hook.enableTimeouts(this.enableTimeouts());
  4946. hook.slow(this.slow());
  4947. hook.ctx = this.ctx;
  4948. this._afterAll.push(hook);
  4949. this.emit('afterAll', hook);
  4950. return this;
  4951. };
  4952. /**
  4953. * Run `fn(test[, done])` before each test case.
  4954. *
  4955. * @api private
  4956. * @param {string} title
  4957. * @param {Function} fn
  4958. * @return {Suite} for chaining
  4959. */
  4960. Suite.prototype.beforeEach = function (title, fn) {
  4961. if (this.isPending()) {
  4962. return this;
  4963. }
  4964. if (typeof title === 'function') {
  4965. fn = title;
  4966. title = fn.name;
  4967. }
  4968. title = '"before each" hook' + (title ? ': ' + title : '');
  4969. var hook = new Hook(title, fn);
  4970. hook.parent = this;
  4971. hook.timeout(this.timeout());
  4972. hook.retries(this.retries());
  4973. hook.enableTimeouts(this.enableTimeouts());
  4974. hook.slow(this.slow());
  4975. hook.ctx = this.ctx;
  4976. this._beforeEach.push(hook);
  4977. this.emit('beforeEach', hook);
  4978. return this;
  4979. };
  4980. /**
  4981. * Run `fn(test[, done])` after each test case.
  4982. *
  4983. * @api private
  4984. * @param {string} title
  4985. * @param {Function} fn
  4986. * @return {Suite} for chaining
  4987. */
  4988. Suite.prototype.afterEach = function (title, fn) {
  4989. if (this.isPending()) {
  4990. return this;
  4991. }
  4992. if (typeof title === 'function') {
  4993. fn = title;
  4994. title = fn.name;
  4995. }
  4996. title = '"after each" hook' + (title ? ': ' + title : '');
  4997. var hook = new Hook(title, fn);
  4998. hook.parent = this;
  4999. hook.timeout(this.timeout());
  5000. hook.retries(this.retries());
  5001. hook.enableTimeouts(this.enableTimeouts());
  5002. hook.slow(this.slow());
  5003. hook.ctx = this.ctx;
  5004. this._afterEach.push(hook);
  5005. this.emit('afterEach', hook);
  5006. return this;
  5007. };
  5008. /**
  5009. * Add a test `suite`.
  5010. *
  5011. * @api private
  5012. * @param {Suite} suite
  5013. * @return {Suite} for chaining
  5014. */
  5015. Suite.prototype.addSuite = function (suite) {
  5016. suite.parent = this;
  5017. suite.timeout(this.timeout());
  5018. suite.retries(this.retries());
  5019. suite.enableTimeouts(this.enableTimeouts());
  5020. suite.slow(this.slow());
  5021. suite.bail(this.bail());
  5022. this.suites.push(suite);
  5023. this.emit('suite', suite);
  5024. return this;
  5025. };
  5026. /**
  5027. * Add a `test` to this suite.
  5028. *
  5029. * @api private
  5030. * @param {Test} test
  5031. * @return {Suite} for chaining
  5032. */
  5033. Suite.prototype.addTest = function (test) {
  5034. test.parent = this;
  5035. test.timeout(this.timeout());
  5036. test.retries(this.retries());
  5037. test.enableTimeouts(this.enableTimeouts());
  5038. test.slow(this.slow());
  5039. test.ctx = this.ctx;
  5040. this.tests.push(test);
  5041. this.emit('test', test);
  5042. return this;
  5043. };
  5044. /**
  5045. * Return the full title generated by recursively concatenating the parent's
  5046. * full title.
  5047. *
  5048. * @api public
  5049. * @return {string}
  5050. */
  5051. Suite.prototype.fullTitle = function () {
  5052. if (this.parent) {
  5053. var full = this.parent.fullTitle();
  5054. if (full) {
  5055. return full + ' ' + this.title;
  5056. }
  5057. }
  5058. return this.title;
  5059. };
  5060. /**
  5061. * Return the total number of tests.
  5062. *
  5063. * @api public
  5064. * @return {number}
  5065. */
  5066. Suite.prototype.total = function () {
  5067. return utils.reduce(this.suites, function (sum, suite) {
  5068. return sum + suite.total();
  5069. }, 0) + this.tests.length;
  5070. };
  5071. /**
  5072. * Iterates through each suite recursively to find all tests. Applies a
  5073. * function in the format `fn(test)`.
  5074. *
  5075. * @api private
  5076. * @param {Function} fn
  5077. * @return {Suite}
  5078. */
  5079. Suite.prototype.eachTest = function (fn) {
  5080. utils.forEach(this.tests, fn);
  5081. utils.forEach(this.suites, function (suite) {
  5082. suite.eachTest(fn);
  5083. });
  5084. return this;
  5085. };
  5086. /**
  5087. * This will run the root suite if we happen to be running in delayed mode.
  5088. */
  5089. Suite.prototype.run = function run () {
  5090. if (this.root) {
  5091. this.emit('run');
  5092. }
  5093. };
  5094. },{"./hook":7,"./ms":15,"./utils":38,"debug":2,"events":3}],36:[function(require,module,exports){
  5095. 'use strict';
  5096. /**
  5097. * Module dependencies.
  5098. */
  5099. var Runnable = require('./runnable');
  5100. var create = require('lodash.create');
  5101. var isString = require('./utils').isString;
  5102. /**
  5103. * Expose `Test`.
  5104. */
  5105. module.exports = Test;
  5106. /**
  5107. * Initialize a new `Test` with the given `title` and callback `fn`.
  5108. *
  5109. * @api private
  5110. * @param {String} title
  5111. * @param {Function} fn
  5112. */
  5113. function Test (title, fn) {
  5114. if (!isString(title)) {
  5115. throw new Error('Test `title` should be a "string" but "' + typeof title + '" was given instead.');
  5116. }
  5117. Runnable.call(this, title, fn);
  5118. this.pending = !fn;
  5119. this.type = 'test';
  5120. }
  5121. /**
  5122. * Inherit from `Runnable.prototype`.
  5123. */
  5124. Test.prototype = create(Runnable.prototype, {
  5125. constructor: Test
  5126. });
  5127. Test.prototype.clone = function () {
  5128. var test = new Test(this.title, this.fn);
  5129. test.timeout(this.timeout());
  5130. test.slow(this.slow());
  5131. test.enableTimeouts(this.enableTimeouts());
  5132. test.retries(this.retries());
  5133. test.currentRetry(this.currentRetry());
  5134. test.globals(this.globals());
  5135. test.parent = this.parent;
  5136. test.file = this.file;
  5137. test.ctx = this.ctx;
  5138. return test;
  5139. };
  5140. },{"./runnable":33,"./utils":38,"lodash.create":75}],37:[function(require,module,exports){
  5141. 'use strict';
  5142. /**
  5143. * Pad a `number` with a ten's place zero.
  5144. *
  5145. * @param {number} number
  5146. * @return {string}
  5147. */
  5148. function pad(number) {
  5149. var n = number.toString();
  5150. return n.length === 1 ? '0' + n : n;
  5151. }
  5152. /**
  5153. * Turn a `date` into an ISO string.
  5154. *
  5155. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
  5156. *
  5157. * @param {Date} date
  5158. * @return {string}
  5159. */
  5160. function toISOString(date) {
  5161. return date.getUTCFullYear()
  5162. + '-' + pad(date.getUTCMonth() + 1)
  5163. + '-' + pad(date.getUTCDate())
  5164. + 'T' + pad(date.getUTCHours())
  5165. + ':' + pad(date.getUTCMinutes())
  5166. + ':' + pad(date.getUTCSeconds())
  5167. + '.' + String((date.getUTCMilliseconds()/1000).toFixed(3)).slice(2, 5)
  5168. + 'Z';
  5169. }
  5170. /*
  5171. * Exports.
  5172. */
  5173. module.exports = toISOString;
  5174. },{}],38:[function(require,module,exports){
  5175. (function (process,Buffer){
  5176. 'use strict';
  5177. /* eslint-env browser */
  5178. /**
  5179. * Module dependencies.
  5180. */
  5181. var JSON = require('json3');
  5182. var basename = require('path').basename;
  5183. var debug = require('debug')('mocha:watch');
  5184. var exists = require('fs').existsSync || require('path').existsSync;
  5185. var glob = require('glob');
  5186. var path = require('path');
  5187. var join = path.join;
  5188. var readdirSync = require('fs').readdirSync;
  5189. var statSync = require('fs').statSync;
  5190. var watchFile = require('fs').watchFile;
  5191. var lstatSync = require('fs').lstatSync;
  5192. var toISOString = require('./to-iso-string');
  5193. /**
  5194. * Ignored directories.
  5195. */
  5196. var ignore = ['node_modules', '.git'];
  5197. exports.inherits = require('util').inherits;
  5198. /**
  5199. * Escape special characters in the given string of html.
  5200. *
  5201. * @api private
  5202. * @param {string} html
  5203. * @return {string}
  5204. */
  5205. exports.escape = function (html) {
  5206. return String(html)
  5207. .replace(/&/g, '&amp;')
  5208. .replace(/"/g, '&quot;')
  5209. .replace(/</g, '&lt;')
  5210. .replace(/>/g, '&gt;');
  5211. };
  5212. /**
  5213. * Array#forEach (<=IE8)
  5214. *
  5215. * @api private
  5216. * @param {Array} arr
  5217. * @param {Function} fn
  5218. * @param {Object} scope
  5219. */
  5220. exports.forEach = function (arr, fn, scope) {
  5221. for (var i = 0, l = arr.length; i < l; i++) {
  5222. fn.call(scope, arr[i], i);
  5223. }
  5224. };
  5225. /**
  5226. * Test if the given obj is type of string.
  5227. *
  5228. * @api private
  5229. * @param {Object} obj
  5230. * @return {boolean}
  5231. */
  5232. exports.isString = function (obj) {
  5233. return typeof obj === 'string';
  5234. };
  5235. /**
  5236. * Array#map (<=IE8)
  5237. *
  5238. * @api private
  5239. * @param {Array} arr
  5240. * @param {Function} fn
  5241. * @param {Object} scope
  5242. * @return {Array}
  5243. */
  5244. exports.map = function (arr, fn, scope) {
  5245. var result = [];
  5246. for (var i = 0, l = arr.length; i < l; i++) {
  5247. result.push(fn.call(scope, arr[i], i, arr));
  5248. }
  5249. return result;
  5250. };
  5251. /**
  5252. * Array#indexOf (<=IE8)
  5253. *
  5254. * @api private
  5255. * @param {Array} arr
  5256. * @param {Object} obj to find index of
  5257. * @param {number} start
  5258. * @return {number}
  5259. */
  5260. var indexOf = exports.indexOf = function (arr, obj, start) {
  5261. for (var i = start || 0, l = arr.length; i < l; i++) {
  5262. if (arr[i] === obj) {
  5263. return i;
  5264. }
  5265. }
  5266. return -1;
  5267. };
  5268. /**
  5269. * Array#reduce (<=IE8)
  5270. *
  5271. * @api private
  5272. * @param {Array} arr
  5273. * @param {Function} fn
  5274. * @param {Object} val Initial value.
  5275. * @return {*}
  5276. */
  5277. var reduce = exports.reduce = function (arr, fn, val) {
  5278. var rval = val;
  5279. for (var i = 0, l = arr.length; i < l; i++) {
  5280. rval = fn(rval, arr[i], i, arr);
  5281. }
  5282. return rval;
  5283. };
  5284. /**
  5285. * Array#filter (<=IE8)
  5286. *
  5287. * @api private
  5288. * @param {Array} arr
  5289. * @param {Function} fn
  5290. * @return {Array}
  5291. */
  5292. exports.filter = function (arr, fn) {
  5293. var ret = [];
  5294. for (var i = 0, l = arr.length; i < l; i++) {
  5295. var val = arr[i];
  5296. if (fn(val, i, arr)) {
  5297. ret.push(val);
  5298. }
  5299. }
  5300. return ret;
  5301. };
  5302. /**
  5303. * Array#some (<=IE8)
  5304. *
  5305. * @api private
  5306. * @param {Array} arr
  5307. * @param {Function} fn
  5308. * @return {Array}
  5309. */
  5310. exports.some = function (arr, fn) {
  5311. for (var i = 0, l = arr.length; i < l; i++) {
  5312. if (fn(arr[i])) {
  5313. return true;
  5314. }
  5315. }
  5316. return false;
  5317. };
  5318. /**
  5319. * Object.keys (<=IE8)
  5320. *
  5321. * @api private
  5322. * @param {Object} obj
  5323. * @return {Array} keys
  5324. */
  5325. exports.keys = typeof Object.keys === 'function' ? Object.keys : function (obj) {
  5326. var keys = [];
  5327. var has = Object.prototype.hasOwnProperty; // for `window` on <=IE8
  5328. for (var key in obj) {
  5329. if (has.call(obj, key)) {
  5330. keys.push(key);
  5331. }
  5332. }
  5333. return keys;
  5334. };
  5335. /**
  5336. * Watch the given `files` for changes
  5337. * and invoke `fn(file)` on modification.
  5338. *
  5339. * @api private
  5340. * @param {Array} files
  5341. * @param {Function} fn
  5342. */
  5343. exports.watch = function (files, fn) {
  5344. var options = { interval: 100 };
  5345. files.forEach(function (file) {
  5346. debug('file %s', file);
  5347. watchFile(file, options, function (curr, prev) {
  5348. if (prev.mtime < curr.mtime) {
  5349. fn(file);
  5350. }
  5351. });
  5352. });
  5353. };
  5354. /**
  5355. * Array.isArray (<=IE8)
  5356. *
  5357. * @api private
  5358. * @param {Object} obj
  5359. * @return {Boolean}
  5360. */
  5361. var isArray = typeof Array.isArray === 'function' ? Array.isArray : function (obj) {
  5362. return Object.prototype.toString.call(obj) === '[object Array]';
  5363. };
  5364. exports.isArray = isArray;
  5365. /**
  5366. * Buffer.prototype.toJSON polyfill.
  5367. *
  5368. * @type {Function}
  5369. */
  5370. if (typeof Buffer !== 'undefined' && Buffer.prototype) {
  5371. Buffer.prototype.toJSON = Buffer.prototype.toJSON || function () {
  5372. return Array.prototype.slice.call(this, 0);
  5373. };
  5374. }
  5375. /**
  5376. * Ignored files.
  5377. *
  5378. * @api private
  5379. * @param {string} path
  5380. * @return {boolean}
  5381. */
  5382. function ignored (path) {
  5383. return !~ignore.indexOf(path);
  5384. }
  5385. /**
  5386. * Lookup files in the given `dir`.
  5387. *
  5388. * @api private
  5389. * @param {string} dir
  5390. * @param {string[]} [ext=['.js']]
  5391. * @param {Array} [ret=[]]
  5392. * @return {Array}
  5393. */
  5394. exports.files = function (dir, ext, ret) {
  5395. ret = ret || [];
  5396. ext = ext || ['js'];
  5397. var re = new RegExp('\\.(' + ext.join('|') + ')$');
  5398. readdirSync(dir)
  5399. .filter(ignored)
  5400. .forEach(function (path) {
  5401. path = join(dir, path);
  5402. if (lstatSync(path).isDirectory()) {
  5403. exports.files(path, ext, ret);
  5404. } else if (path.match(re)) {
  5405. ret.push(path);
  5406. }
  5407. });
  5408. return ret;
  5409. };
  5410. /**
  5411. * Compute a slug from the given `str`.
  5412. *
  5413. * @api private
  5414. * @param {string} str
  5415. * @return {string}
  5416. */
  5417. exports.slug = function (str) {
  5418. return str
  5419. .toLowerCase()
  5420. .replace(/ +/g, '-')
  5421. .replace(/[^-\w]/g, '');
  5422. };
  5423. /**
  5424. * Strip the function definition from `str`, and re-indent for pre whitespace.
  5425. *
  5426. * @param {string} str
  5427. * @return {string}
  5428. */
  5429. exports.clean = function (str) {
  5430. str = str
  5431. .replace(/\r\n?|[\n\u2028\u2029]/g, '\n').replace(/^\uFEFF/, '')
  5432. // (traditional)-> space/name parameters body (lambda)-> parameters body multi-statement/single keep body content
  5433. .replace(/^function(?:\s*|\s+[^(]*)\([^)]*\)\s*\{((?:.|\n)*?)\s*\}$|^\([^)]*\)\s*=>\s*(?:\{((?:.|\n)*?)\s*\}|((?:.|\n)*))$/, '$1$2$3');
  5434. var spaces = str.match(/^\n?( *)/)[1].length;
  5435. var tabs = str.match(/^\n?(\t*)/)[1].length;
  5436. var re = new RegExp('^\n?' + (tabs ? '\t' : ' ') + '{' + (tabs || spaces) + '}', 'gm');
  5437. str = str.replace(re, '');
  5438. return exports.trim(str);
  5439. };
  5440. /**
  5441. * Trim the given `str`.
  5442. *
  5443. * @api private
  5444. * @param {string} str
  5445. * @return {string}
  5446. */
  5447. exports.trim = function (str) {
  5448. return str.replace(/^\s+|\s+$/g, '');
  5449. };
  5450. /**
  5451. * Parse the given `qs`.
  5452. *
  5453. * @api private
  5454. * @param {string} qs
  5455. * @return {Object}
  5456. */
  5457. exports.parseQuery = function (qs) {
  5458. return reduce(qs.replace('?', '').split('&'), function (obj, pair) {
  5459. var i = pair.indexOf('=');
  5460. var key = pair.slice(0, i);
  5461. var val = pair.slice(++i);
  5462. // Due to how the URLSearchParams API treats spaces
  5463. obj[key] = decodeURIComponent(val.replace(/\+/g, '%20'));
  5464. return obj;
  5465. }, {});
  5466. };
  5467. /**
  5468. * Highlight the given string of `js`.
  5469. *
  5470. * @api private
  5471. * @param {string} js
  5472. * @return {string}
  5473. */
  5474. function highlight (js) {
  5475. return js
  5476. .replace(/</g, '&lt;')
  5477. .replace(/>/g, '&gt;')
  5478. .replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
  5479. .replace(/('.*?')/gm, '<span class="string">$1</span>')
  5480. .replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
  5481. .replace(/(\d+)/gm, '<span class="number">$1</span>')
  5482. .replace(/\bnew[ \t]+(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>')
  5483. .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>');
  5484. }
  5485. /**
  5486. * Highlight the contents of tag `name`.
  5487. *
  5488. * @api private
  5489. * @param {string} name
  5490. */
  5491. exports.highlightTags = function (name) {
  5492. var code = document.getElementById('mocha').getElementsByTagName(name);
  5493. for (var i = 0, len = code.length; i < len; ++i) {
  5494. code[i].innerHTML = highlight(code[i].innerHTML);
  5495. }
  5496. };
  5497. /**
  5498. * If a value could have properties, and has none, this function is called,
  5499. * which returns a string representation of the empty value.
  5500. *
  5501. * Functions w/ no properties return `'[Function]'`
  5502. * Arrays w/ length === 0 return `'[]'`
  5503. * Objects w/ no properties return `'{}'`
  5504. * All else: return result of `value.toString()`
  5505. *
  5506. * @api private
  5507. * @param {*} value The value to inspect.
  5508. * @param {string} typeHint The type of the value
  5509. * @returns {string}
  5510. */
  5511. function emptyRepresentation (value, typeHint) {
  5512. switch (typeHint) {
  5513. case 'function':
  5514. return '[Function]';
  5515. case 'object':
  5516. return '{}';
  5517. case 'array':
  5518. return '[]';
  5519. default:
  5520. return value.toString();
  5521. }
  5522. }
  5523. /**
  5524. * Takes some variable and asks `Object.prototype.toString()` what it thinks it
  5525. * is.
  5526. *
  5527. * @api private
  5528. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
  5529. * @param {*} value The value to test.
  5530. * @returns {string} Computed type
  5531. * @example
  5532. * type({}) // 'object'
  5533. * type([]) // 'array'
  5534. * type(1) // 'number'
  5535. * type(false) // 'boolean'
  5536. * type(Infinity) // 'number'
  5537. * type(null) // 'null'
  5538. * type(new Date()) // 'date'
  5539. * type(/foo/) // 'regexp'
  5540. * type('type') // 'string'
  5541. * type(global) // 'global'
  5542. * type(new String('foo') // 'object'
  5543. */
  5544. var type = exports.type = function type (value) {
  5545. if (value === undefined) {
  5546. return 'undefined';
  5547. } else if (value === null) {
  5548. return 'null';
  5549. } else if (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) {
  5550. return 'buffer';
  5551. }
  5552. return Object.prototype.toString.call(value)
  5553. .replace(/^\[.+\s(.+?)]$/, '$1')
  5554. .toLowerCase();
  5555. };
  5556. /**
  5557. * Stringify `value`. Different behavior depending on type of value:
  5558. *
  5559. * - If `value` is undefined or null, return `'[undefined]'` or `'[null]'`, respectively.
  5560. * - If `value` is not an object, function or array, return result of `value.toString()` wrapped in double-quotes.
  5561. * - If `value` is an *empty* object, function, or array, return result of function
  5562. * {@link emptyRepresentation}.
  5563. * - If `value` has properties, call {@link exports.canonicalize} on it, then return result of
  5564. * JSON.stringify().
  5565. *
  5566. * @api private
  5567. * @see exports.type
  5568. * @param {*} value
  5569. * @return {string}
  5570. */
  5571. exports.stringify = function (value) {
  5572. var typeHint = type(value);
  5573. if (!~indexOf(['object', 'array', 'function'], typeHint)) {
  5574. if (typeHint === 'buffer') {
  5575. var json = value.toJSON();
  5576. // Based on the toJSON result
  5577. return jsonStringify(json.data && json.type ? json.data : json, 2)
  5578. .replace(/,(\n|$)/g, '$1');
  5579. }
  5580. // IE7/IE8 has a bizarre String constructor; needs to be coerced
  5581. // into an array and back to obj.
  5582. if (typeHint === 'string' && typeof value === 'object') {
  5583. value = reduce(value.split(''), function (acc, char, idx) {
  5584. acc[idx] = char;
  5585. return acc;
  5586. }, {});
  5587. typeHint = 'object';
  5588. } else {
  5589. return jsonStringify(value);
  5590. }
  5591. }
  5592. for (var prop in value) {
  5593. if (Object.prototype.hasOwnProperty.call(value, prop)) {
  5594. return jsonStringify(exports.canonicalize(value, null, typeHint), 2).replace(/,(\n|$)/g, '$1');
  5595. }
  5596. }
  5597. return emptyRepresentation(value, typeHint);
  5598. };
  5599. /**
  5600. * like JSON.stringify but more sense.
  5601. *
  5602. * @api private
  5603. * @param {Object} object
  5604. * @param {number=} spaces
  5605. * @param {number=} depth
  5606. * @returns {*}
  5607. */
  5608. function jsonStringify (object, spaces, depth) {
  5609. if (typeof spaces === 'undefined') {
  5610. // primitive types
  5611. return _stringify(object);
  5612. }
  5613. depth = depth || 1;
  5614. var space = spaces * depth;
  5615. var str = isArray(object) ? '[' : '{';
  5616. var end = isArray(object) ? ']' : '}';
  5617. var length = typeof object.length === 'number' ? object.length : exports.keys(object).length;
  5618. // `.repeat()` polyfill
  5619. function repeat (s, n) {
  5620. return new Array(n).join(s);
  5621. }
  5622. function _stringify (val) {
  5623. switch (type(val)) {
  5624. case 'null':
  5625. case 'undefined':
  5626. val = '[' + val + ']';
  5627. break;
  5628. case 'array':
  5629. case 'object':
  5630. val = jsonStringify(val, spaces, depth + 1);
  5631. break;
  5632. case 'boolean':
  5633. case 'regexp':
  5634. case 'symbol':
  5635. case 'number':
  5636. val = val === 0 && (1 / val) === -Infinity // `-0`
  5637. ? '-0'
  5638. : val.toString();
  5639. break;
  5640. case 'date':
  5641. var sDate;
  5642. if (isNaN(val.getTime())) { // Invalid date
  5643. sDate = val.toString();
  5644. } else {
  5645. sDate = val.toISOString ? val.toISOString() : toISOString(val);
  5646. }
  5647. val = '[Date: ' + sDate + ']';
  5648. break;
  5649. case 'buffer':
  5650. var json = val.toJSON();
  5651. // Based on the toJSON result
  5652. json = json.data && json.type ? json.data : json;
  5653. val = '[Buffer: ' + jsonStringify(json, 2, depth + 1) + ']';
  5654. break;
  5655. default:
  5656. val = (val === '[Function]' || val === '[Circular]')
  5657. ? val
  5658. : JSON.stringify(val); // string
  5659. }
  5660. return val;
  5661. }
  5662. for (var i in object) {
  5663. if (!Object.prototype.hasOwnProperty.call(object, i)) {
  5664. continue; // not my business
  5665. }
  5666. --length;
  5667. str += '\n ' + repeat(' ', space) +
  5668. (isArray(object) ? '' : '"' + i + '": ') + // key
  5669. _stringify(object[i]) + // value
  5670. (length ? ',' : ''); // comma
  5671. }
  5672. return str +
  5673. // [], {}
  5674. (str.length !== 1 ? '\n' + repeat(' ', --space) + end : end);
  5675. }
  5676. /**
  5677. * Test if a value is a buffer.
  5678. *
  5679. * @api private
  5680. * @param {*} value The value to test.
  5681. * @return {boolean} True if `value` is a buffer, otherwise false
  5682. */
  5683. exports.isBuffer = function (value) {
  5684. return typeof Buffer !== 'undefined' && Buffer.isBuffer(value);
  5685. };
  5686. /**
  5687. * Return a new Thing that has the keys in sorted order. Recursive.
  5688. *
  5689. * If the Thing...
  5690. * - has already been seen, return string `'[Circular]'`
  5691. * - is `undefined`, return string `'[undefined]'`
  5692. * - is `null`, return value `null`
  5693. * - is some other primitive, return the value
  5694. * - is not a primitive or an `Array`, `Object`, or `Function`, return the value of the Thing's `toString()` method
  5695. * - is a non-empty `Array`, `Object`, or `Function`, return the result of calling this function again.
  5696. * - is an empty `Array`, `Object`, or `Function`, return the result of calling `emptyRepresentation()`
  5697. *
  5698. * @api private
  5699. * @see {@link exports.stringify}
  5700. * @param {*} value Thing to inspect. May or may not have properties.
  5701. * @param {Array} [stack=[]] Stack of seen values
  5702. * @param {string} [typeHint] Type hint
  5703. * @return {(Object|Array|Function|string|undefined)}
  5704. */
  5705. exports.canonicalize = function canonicalize (value, stack, typeHint) {
  5706. var canonicalizedObj;
  5707. /* eslint-disable no-unused-vars */
  5708. var prop;
  5709. /* eslint-enable no-unused-vars */
  5710. typeHint = typeHint || type(value);
  5711. function withStack (value, fn) {
  5712. stack.push(value);
  5713. fn();
  5714. stack.pop();
  5715. }
  5716. stack = stack || [];
  5717. if (indexOf(stack, value) !== -1) {
  5718. return '[Circular]';
  5719. }
  5720. switch (typeHint) {
  5721. case 'undefined':
  5722. case 'buffer':
  5723. case 'null':
  5724. canonicalizedObj = value;
  5725. break;
  5726. case 'array':
  5727. withStack(value, function () {
  5728. canonicalizedObj = exports.map(value, function (item) {
  5729. return exports.canonicalize(item, stack);
  5730. });
  5731. });
  5732. break;
  5733. case 'function':
  5734. /* eslint-disable guard-for-in */
  5735. for (prop in value) {
  5736. canonicalizedObj = {};
  5737. break;
  5738. }
  5739. /* eslint-enable guard-for-in */
  5740. if (!canonicalizedObj) {
  5741. canonicalizedObj = emptyRepresentation(value, typeHint);
  5742. break;
  5743. }
  5744. /* falls through */
  5745. case 'object':
  5746. canonicalizedObj = canonicalizedObj || {};
  5747. withStack(value, function () {
  5748. exports.forEach(exports.keys(value).sort(), function (key) {
  5749. canonicalizedObj[key] = exports.canonicalize(value[key], stack);
  5750. });
  5751. });
  5752. break;
  5753. case 'date':
  5754. case 'number':
  5755. case 'regexp':
  5756. case 'boolean':
  5757. case 'symbol':
  5758. canonicalizedObj = value;
  5759. break;
  5760. default:
  5761. canonicalizedObj = value + '';
  5762. }
  5763. return canonicalizedObj;
  5764. };
  5765. /**
  5766. * Lookup file names at the given `path`.
  5767. *
  5768. * @api public
  5769. * @param {string} path Base path to start searching from.
  5770. * @param {string[]} extensions File extensions to look for.
  5771. * @param {boolean} recursive Whether or not to recurse into subdirectories.
  5772. * @return {string[]} An array of paths.
  5773. */
  5774. exports.lookupFiles = function lookupFiles (path, extensions, recursive) {
  5775. var files = [];
  5776. var re = new RegExp('\\.(' + extensions.join('|') + ')$');
  5777. if (!exists(path)) {
  5778. if (exists(path + '.js')) {
  5779. path += '.js';
  5780. } else {
  5781. files = glob.sync(path);
  5782. if (!files.length) {
  5783. throw new Error("cannot resolve path (or pattern) '" + path + "'");
  5784. }
  5785. return files;
  5786. }
  5787. }
  5788. try {
  5789. var stat = statSync(path);
  5790. if (stat.isFile()) {
  5791. return path;
  5792. }
  5793. } catch (err) {
  5794. // ignore error
  5795. return;
  5796. }
  5797. readdirSync(path).forEach(function (file) {
  5798. file = join(path, file);
  5799. try {
  5800. var stat = statSync(file);
  5801. if (stat.isDirectory()) {
  5802. if (recursive) {
  5803. files = files.concat(lookupFiles(file, extensions, recursive));
  5804. }
  5805. return;
  5806. }
  5807. } catch (err) {
  5808. // ignore error
  5809. return;
  5810. }
  5811. if (!stat.isFile() || !re.test(file) || basename(file)[0] === '.') {
  5812. return;
  5813. }
  5814. files.push(file);
  5815. });
  5816. return files;
  5817. };
  5818. /**
  5819. * Generate an undefined error with a message warning the user.
  5820. *
  5821. * @return {Error}
  5822. */
  5823. exports.undefinedError = function () {
  5824. return new Error('Caught undefined error, did you throw without specifying what?');
  5825. };
  5826. /**
  5827. * Generate an undefined error if `err` is not defined.
  5828. *
  5829. * @param {Error} err
  5830. * @return {Error}
  5831. */
  5832. exports.getError = function (err) {
  5833. return err || exports.undefinedError();
  5834. };
  5835. /**
  5836. * @summary
  5837. * This Filter based on `mocha-clean` module.(see: `github.com/rstacruz/mocha-clean`)
  5838. * @description
  5839. * When invoking this function you get a filter function that get the Error.stack as an input,
  5840. * and return a prettify output.
  5841. * (i.e: strip Mocha and internal node functions from stack trace).
  5842. * @returns {Function}
  5843. */
  5844. exports.stackTraceFilter = function () {
  5845. // TODO: Replace with `process.browser`
  5846. var is = typeof document === 'undefined' ? { node: true } : { browser: true };
  5847. var slash = path.sep;
  5848. var cwd;
  5849. if (is.node) {
  5850. cwd = process.cwd() + slash;
  5851. } else {
  5852. cwd = (typeof location === 'undefined'
  5853. ? window.location
  5854. : location).href.replace(/\/[^/]*$/, '/');
  5855. slash = '/';
  5856. }
  5857. function isMochaInternal (line) {
  5858. return (~line.indexOf('node_modules' + slash + 'mocha' + slash)) ||
  5859. (~line.indexOf('node_modules' + slash + 'mocha.js')) ||
  5860. (~line.indexOf('bower_components' + slash + 'mocha.js')) ||
  5861. (~line.indexOf(slash + 'mocha.js'));
  5862. }
  5863. function isNodeInternal (line) {
  5864. return (~line.indexOf('(timers.js:')) ||
  5865. (~line.indexOf('(events.js:')) ||
  5866. (~line.indexOf('(node.js:')) ||
  5867. (~line.indexOf('(module.js:')) ||
  5868. (~line.indexOf('GeneratorFunctionPrototype.next (native)')) ||
  5869. false;
  5870. }
  5871. return function (stack) {
  5872. stack = stack.split('\n');
  5873. stack = reduce(stack, function (list, line) {
  5874. if (isMochaInternal(line)) {
  5875. return list;
  5876. }
  5877. if (is.node && isNodeInternal(line)) {
  5878. return list;
  5879. }
  5880. // Clean up cwd(absolute)
  5881. if (/\(?.+:\d+:\d+\)?$/.test(line)) {
  5882. line = line.replace(cwd, '');
  5883. }
  5884. list.push(line);
  5885. return list;
  5886. }, []);
  5887. return stack.join('\n');
  5888. };
  5889. };
  5890. /**
  5891. * Crude, but effective.
  5892. * @api
  5893. * @param {*} value
  5894. * @returns {boolean} Whether or not `value` is a Promise
  5895. */
  5896. exports.isPromise = function isPromise (value) {
  5897. return typeof value === 'object' && typeof value.then === 'function';
  5898. };
  5899. /**
  5900. * It's a noop.
  5901. * @api
  5902. */
  5903. exports.noop = function () {};
  5904. }).call(this,require('_process'),require("buffer").Buffer)
  5905. },{"./to-iso-string":37,"_process":82,"buffer":44,"debug":2,"fs":42,"glob":42,"json3":69,"path":42,"util":99}],39:[function(require,module,exports){
  5906. 'use strict'
  5907. exports.byteLength = byteLength
  5908. exports.toByteArray = toByteArray
  5909. exports.fromByteArray = fromByteArray
  5910. var lookup = []
  5911. var revLookup = []
  5912. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  5913. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  5914. for (var i = 0, len = code.length; i < len; ++i) {
  5915. lookup[i] = code[i]
  5916. revLookup[code.charCodeAt(i)] = i
  5917. }
  5918. revLookup['-'.charCodeAt(0)] = 62
  5919. revLookup['_'.charCodeAt(0)] = 63
  5920. function placeHoldersCount (b64) {
  5921. var len = b64.length
  5922. if (len % 4 > 0) {
  5923. throw new Error('Invalid string. Length must be a multiple of 4')
  5924. }
  5925. // the number of equal signs (place holders)
  5926. // if there are two placeholders, than the two characters before it
  5927. // represent one byte
  5928. // if there is only one, then the three characters before it represent 2 bytes
  5929. // this is just a cheap hack to not do indexOf twice
  5930. return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
  5931. }
  5932. function byteLength (b64) {
  5933. // base64 is 4/3 + up to two characters of the original data
  5934. return b64.length * 3 / 4 - placeHoldersCount(b64)
  5935. }
  5936. function toByteArray (b64) {
  5937. var i, j, l, tmp, placeHolders, arr
  5938. var len = b64.length
  5939. placeHolders = placeHoldersCount(b64)
  5940. arr = new Arr(len * 3 / 4 - placeHolders)
  5941. // if there are placeholders, only get up to the last complete 4 chars
  5942. l = placeHolders > 0 ? len - 4 : len
  5943. var L = 0
  5944. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  5945. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
  5946. arr[L++] = (tmp >> 16) & 0xFF
  5947. arr[L++] = (tmp >> 8) & 0xFF
  5948. arr[L++] = tmp & 0xFF
  5949. }
  5950. if (placeHolders === 2) {
  5951. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
  5952. arr[L++] = tmp & 0xFF
  5953. } else if (placeHolders === 1) {
  5954. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
  5955. arr[L++] = (tmp >> 8) & 0xFF
  5956. arr[L++] = tmp & 0xFF
  5957. }
  5958. return arr
  5959. }
  5960. function tripletToBase64 (num) {
  5961. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  5962. }
  5963. function encodeChunk (uint8, start, end) {
  5964. var tmp
  5965. var output = []
  5966. for (var i = start; i < end; i += 3) {
  5967. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  5968. output.push(tripletToBase64(tmp))
  5969. }
  5970. return output.join('')
  5971. }
  5972. function fromByteArray (uint8) {
  5973. var tmp
  5974. var len = uint8.length
  5975. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  5976. var output = ''
  5977. var parts = []
  5978. var maxChunkLength = 16383 // must be multiple of 3
  5979. // go through the array every three bytes, we'll deal with trailing stuff later
  5980. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  5981. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  5982. }
  5983. // pad the end with zeros, but make sure to not forget the extra bytes
  5984. if (extraBytes === 1) {
  5985. tmp = uint8[len - 1]
  5986. output += lookup[tmp >> 2]
  5987. output += lookup[(tmp << 4) & 0x3F]
  5988. output += '=='
  5989. } else if (extraBytes === 2) {
  5990. tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
  5991. output += lookup[tmp >> 10]
  5992. output += lookup[(tmp >> 4) & 0x3F]
  5993. output += lookup[(tmp << 2) & 0x3F]
  5994. output += '='
  5995. }
  5996. parts.push(output)
  5997. return parts.join('')
  5998. }
  5999. },{}],40:[function(require,module,exports){
  6000. },{}],41:[function(require,module,exports){
  6001. (function (process){
  6002. var WritableStream = require('stream').Writable
  6003. var inherits = require('util').inherits
  6004. module.exports = BrowserStdout
  6005. inherits(BrowserStdout, WritableStream)
  6006. function BrowserStdout(opts) {
  6007. if (!(this instanceof BrowserStdout)) return new BrowserStdout(opts)
  6008. opts = opts || {}
  6009. WritableStream.call(this, opts)
  6010. this.label = (opts.label !== undefined) ? opts.label : 'stdout'
  6011. }
  6012. BrowserStdout.prototype._write = function(chunks, encoding, cb) {
  6013. var output = chunks.toString ? chunks.toString() : chunks
  6014. if (this.label === false) {
  6015. console.log(output)
  6016. } else {
  6017. console.log(this.label+':', output)
  6018. }
  6019. process.nextTick(cb)
  6020. }
  6021. }).call(this,require('_process'))
  6022. },{"_process":82,"stream":94,"util":99}],42:[function(require,module,exports){
  6023. arguments[4][40][0].apply(exports,arguments)
  6024. },{"dup":40}],43:[function(require,module,exports){
  6025. (function (global){
  6026. 'use strict';
  6027. var buffer = require('buffer');
  6028. var Buffer = buffer.Buffer;
  6029. var SlowBuffer = buffer.SlowBuffer;
  6030. var MAX_LEN = buffer.kMaxLength || 2147483647;
  6031. exports.alloc = function alloc(size, fill, encoding) {
  6032. if (typeof Buffer.alloc === 'function') {
  6033. return Buffer.alloc(size, fill, encoding);
  6034. }
  6035. if (typeof encoding === 'number') {
  6036. throw new TypeError('encoding must not be number');
  6037. }
  6038. if (typeof size !== 'number') {
  6039. throw new TypeError('size must be a number');
  6040. }
  6041. if (size > MAX_LEN) {
  6042. throw new RangeError('size is too large');
  6043. }
  6044. var enc = encoding;
  6045. var _fill = fill;
  6046. if (_fill === undefined) {
  6047. enc = undefined;
  6048. _fill = 0;
  6049. }
  6050. var buf = new Buffer(size);
  6051. if (typeof _fill === 'string') {
  6052. var fillBuf = new Buffer(_fill, enc);
  6053. var flen = fillBuf.length;
  6054. var i = -1;
  6055. while (++i < size) {
  6056. buf[i] = fillBuf[i % flen];
  6057. }
  6058. } else {
  6059. buf.fill(_fill);
  6060. }
  6061. return buf;
  6062. }
  6063. exports.allocUnsafe = function allocUnsafe(size) {
  6064. if (typeof Buffer.allocUnsafe === 'function') {
  6065. return Buffer.allocUnsafe(size);
  6066. }
  6067. if (typeof size !== 'number') {
  6068. throw new TypeError('size must be a number');
  6069. }
  6070. if (size > MAX_LEN) {
  6071. throw new RangeError('size is too large');
  6072. }
  6073. return new Buffer(size);
  6074. }
  6075. exports.from = function from(value, encodingOrOffset, length) {
  6076. if (typeof Buffer.from === 'function' && (!global.Uint8Array || Uint8Array.from !== Buffer.from)) {
  6077. return Buffer.from(value, encodingOrOffset, length);
  6078. }
  6079. if (typeof value === 'number') {
  6080. throw new TypeError('"value" argument must not be a number');
  6081. }
  6082. if (typeof value === 'string') {
  6083. return new Buffer(value, encodingOrOffset);
  6084. }
  6085. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  6086. var offset = encodingOrOffset;
  6087. if (arguments.length === 1) {
  6088. return new Buffer(value);
  6089. }
  6090. if (typeof offset === 'undefined') {
  6091. offset = 0;
  6092. }
  6093. var len = length;
  6094. if (typeof len === 'undefined') {
  6095. len = value.byteLength - offset;
  6096. }
  6097. if (offset >= value.byteLength) {
  6098. throw new RangeError('\'offset\' is out of bounds');
  6099. }
  6100. if (len > value.byteLength - offset) {
  6101. throw new RangeError('\'length\' is out of bounds');
  6102. }
  6103. return new Buffer(value.slice(offset, offset + len));
  6104. }
  6105. if (Buffer.isBuffer(value)) {
  6106. var out = new Buffer(value.length);
  6107. value.copy(out, 0, 0, value.length);
  6108. return out;
  6109. }
  6110. if (value) {
  6111. if (Array.isArray(value) || (typeof ArrayBuffer !== 'undefined' && value.buffer instanceof ArrayBuffer) || 'length' in value) {
  6112. return new Buffer(value);
  6113. }
  6114. if (value.type === 'Buffer' && Array.isArray(value.data)) {
  6115. return new Buffer(value.data);
  6116. }
  6117. }
  6118. throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.');
  6119. }
  6120. exports.allocUnsafeSlow = function allocUnsafeSlow(size) {
  6121. if (typeof Buffer.allocUnsafeSlow === 'function') {
  6122. return Buffer.allocUnsafeSlow(size);
  6123. }
  6124. if (typeof size !== 'number') {
  6125. throw new TypeError('size must be a number');
  6126. }
  6127. if (size >= MAX_LEN) {
  6128. throw new RangeError('size is too large');
  6129. }
  6130. return new SlowBuffer(size);
  6131. }
  6132. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  6133. },{"buffer":44}],44:[function(require,module,exports){
  6134. (function (global){
  6135. /*!
  6136. * The buffer module from node.js, for the browser.
  6137. *
  6138. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  6139. * @license MIT
  6140. */
  6141. /* eslint-disable no-proto */
  6142. 'use strict'
  6143. var base64 = require('base64-js')
  6144. var ieee754 = require('ieee754')
  6145. var isArray = require('isarray')
  6146. exports.Buffer = Buffer
  6147. exports.SlowBuffer = SlowBuffer
  6148. exports.INSPECT_MAX_BYTES = 50
  6149. /**
  6150. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  6151. * === true Use Uint8Array implementation (fastest)
  6152. * === false Use Object implementation (most compatible, even IE6)
  6153. *
  6154. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  6155. * Opera 11.6+, iOS 4.2+.
  6156. *
  6157. * Due to various browser bugs, sometimes the Object implementation will be used even
  6158. * when the browser supports typed arrays.
  6159. *
  6160. * Note:
  6161. *
  6162. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  6163. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  6164. *
  6165. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  6166. *
  6167. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  6168. * incorrect length in some situations.
  6169. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  6170. * get the Object implementation, which is slower but behaves correctly.
  6171. */
  6172. Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
  6173. ? global.TYPED_ARRAY_SUPPORT
  6174. : typedArraySupport()
  6175. /*
  6176. * Export kMaxLength after typed array support is determined.
  6177. */
  6178. exports.kMaxLength = kMaxLength()
  6179. function typedArraySupport () {
  6180. try {
  6181. var arr = new Uint8Array(1)
  6182. arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
  6183. return arr.foo() === 42 && // typed array instances can be augmented
  6184. typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
  6185. arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
  6186. } catch (e) {
  6187. return false
  6188. }
  6189. }
  6190. function kMaxLength () {
  6191. return Buffer.TYPED_ARRAY_SUPPORT
  6192. ? 0x7fffffff
  6193. : 0x3fffffff
  6194. }
  6195. function createBuffer (that, length) {
  6196. if (kMaxLength() < length) {
  6197. throw new RangeError('Invalid typed array length')
  6198. }
  6199. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6200. // Return an augmented `Uint8Array` instance, for best performance
  6201. that = new Uint8Array(length)
  6202. that.__proto__ = Buffer.prototype
  6203. } else {
  6204. // Fallback: Return an object instance of the Buffer class
  6205. if (that === null) {
  6206. that = new Buffer(length)
  6207. }
  6208. that.length = length
  6209. }
  6210. return that
  6211. }
  6212. /**
  6213. * The Buffer constructor returns instances of `Uint8Array` that have their
  6214. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  6215. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  6216. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  6217. * returns a single octet.
  6218. *
  6219. * The `Uint8Array` prototype remains unmodified.
  6220. */
  6221. function Buffer (arg, encodingOrOffset, length) {
  6222. if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
  6223. return new Buffer(arg, encodingOrOffset, length)
  6224. }
  6225. // Common case.
  6226. if (typeof arg === 'number') {
  6227. if (typeof encodingOrOffset === 'string') {
  6228. throw new Error(
  6229. 'If encoding is specified then the first argument must be a string'
  6230. )
  6231. }
  6232. return allocUnsafe(this, arg)
  6233. }
  6234. return from(this, arg, encodingOrOffset, length)
  6235. }
  6236. Buffer.poolSize = 8192 // not used by this implementation
  6237. // TODO: Legacy, not needed anymore. Remove in next major version.
  6238. Buffer._augment = function (arr) {
  6239. arr.__proto__ = Buffer.prototype
  6240. return arr
  6241. }
  6242. function from (that, value, encodingOrOffset, length) {
  6243. if (typeof value === 'number') {
  6244. throw new TypeError('"value" argument must not be a number')
  6245. }
  6246. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  6247. return fromArrayBuffer(that, value, encodingOrOffset, length)
  6248. }
  6249. if (typeof value === 'string') {
  6250. return fromString(that, value, encodingOrOffset)
  6251. }
  6252. return fromObject(that, value)
  6253. }
  6254. /**
  6255. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  6256. * if value is a number.
  6257. * Buffer.from(str[, encoding])
  6258. * Buffer.from(array)
  6259. * Buffer.from(buffer)
  6260. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  6261. **/
  6262. Buffer.from = function (value, encodingOrOffset, length) {
  6263. return from(null, value, encodingOrOffset, length)
  6264. }
  6265. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6266. Buffer.prototype.__proto__ = Uint8Array.prototype
  6267. Buffer.__proto__ = Uint8Array
  6268. if (typeof Symbol !== 'undefined' && Symbol.species &&
  6269. Buffer[Symbol.species] === Buffer) {
  6270. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  6271. Object.defineProperty(Buffer, Symbol.species, {
  6272. value: null,
  6273. configurable: true
  6274. })
  6275. }
  6276. }
  6277. function assertSize (size) {
  6278. if (typeof size !== 'number') {
  6279. throw new TypeError('"size" argument must be a number')
  6280. } else if (size < 0) {
  6281. throw new RangeError('"size" argument must not be negative')
  6282. }
  6283. }
  6284. function alloc (that, size, fill, encoding) {
  6285. assertSize(size)
  6286. if (size <= 0) {
  6287. return createBuffer(that, size)
  6288. }
  6289. if (fill !== undefined) {
  6290. // Only pay attention to encoding if it's a string. This
  6291. // prevents accidentally sending in a number that would
  6292. // be interpretted as a start offset.
  6293. return typeof encoding === 'string'
  6294. ? createBuffer(that, size).fill(fill, encoding)
  6295. : createBuffer(that, size).fill(fill)
  6296. }
  6297. return createBuffer(that, size)
  6298. }
  6299. /**
  6300. * Creates a new filled Buffer instance.
  6301. * alloc(size[, fill[, encoding]])
  6302. **/
  6303. Buffer.alloc = function (size, fill, encoding) {
  6304. return alloc(null, size, fill, encoding)
  6305. }
  6306. function allocUnsafe (that, size) {
  6307. assertSize(size)
  6308. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
  6309. if (!Buffer.TYPED_ARRAY_SUPPORT) {
  6310. for (var i = 0; i < size; ++i) {
  6311. that[i] = 0
  6312. }
  6313. }
  6314. return that
  6315. }
  6316. /**
  6317. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  6318. * */
  6319. Buffer.allocUnsafe = function (size) {
  6320. return allocUnsafe(null, size)
  6321. }
  6322. /**
  6323. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  6324. */
  6325. Buffer.allocUnsafeSlow = function (size) {
  6326. return allocUnsafe(null, size)
  6327. }
  6328. function fromString (that, string, encoding) {
  6329. if (typeof encoding !== 'string' || encoding === '') {
  6330. encoding = 'utf8'
  6331. }
  6332. if (!Buffer.isEncoding(encoding)) {
  6333. throw new TypeError('"encoding" must be a valid string encoding')
  6334. }
  6335. var length = byteLength(string, encoding) | 0
  6336. that = createBuffer(that, length)
  6337. var actual = that.write(string, encoding)
  6338. if (actual !== length) {
  6339. // Writing a hex string, for example, that contains invalid characters will
  6340. // cause everything after the first invalid character to be ignored. (e.g.
  6341. // 'abxxcd' will be treated as 'ab')
  6342. that = that.slice(0, actual)
  6343. }
  6344. return that
  6345. }
  6346. function fromArrayLike (that, array) {
  6347. var length = array.length < 0 ? 0 : checked(array.length) | 0
  6348. that = createBuffer(that, length)
  6349. for (var i = 0; i < length; i += 1) {
  6350. that[i] = array[i] & 255
  6351. }
  6352. return that
  6353. }
  6354. function fromArrayBuffer (that, array, byteOffset, length) {
  6355. array.byteLength // this throws if `array` is not a valid ArrayBuffer
  6356. if (byteOffset < 0 || array.byteLength < byteOffset) {
  6357. throw new RangeError('\'offset\' is out of bounds')
  6358. }
  6359. if (array.byteLength < byteOffset + (length || 0)) {
  6360. throw new RangeError('\'length\' is out of bounds')
  6361. }
  6362. if (byteOffset === undefined && length === undefined) {
  6363. array = new Uint8Array(array)
  6364. } else if (length === undefined) {
  6365. array = new Uint8Array(array, byteOffset)
  6366. } else {
  6367. array = new Uint8Array(array, byteOffset, length)
  6368. }
  6369. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6370. // Return an augmented `Uint8Array` instance, for best performance
  6371. that = array
  6372. that.__proto__ = Buffer.prototype
  6373. } else {
  6374. // Fallback: Return an object instance of the Buffer class
  6375. that = fromArrayLike(that, array)
  6376. }
  6377. return that
  6378. }
  6379. function fromObject (that, obj) {
  6380. if (Buffer.isBuffer(obj)) {
  6381. var len = checked(obj.length) | 0
  6382. that = createBuffer(that, len)
  6383. if (that.length === 0) {
  6384. return that
  6385. }
  6386. obj.copy(that, 0, 0, len)
  6387. return that
  6388. }
  6389. if (obj) {
  6390. if ((typeof ArrayBuffer !== 'undefined' &&
  6391. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  6392. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  6393. return createBuffer(that, 0)
  6394. }
  6395. return fromArrayLike(that, obj)
  6396. }
  6397. if (obj.type === 'Buffer' && isArray(obj.data)) {
  6398. return fromArrayLike(that, obj.data)
  6399. }
  6400. }
  6401. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  6402. }
  6403. function checked (length) {
  6404. // Note: cannot use `length < kMaxLength()` here because that fails when
  6405. // length is NaN (which is otherwise coerced to zero.)
  6406. if (length >= kMaxLength()) {
  6407. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  6408. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  6409. }
  6410. return length | 0
  6411. }
  6412. function SlowBuffer (length) {
  6413. if (+length != length) { // eslint-disable-line eqeqeq
  6414. length = 0
  6415. }
  6416. return Buffer.alloc(+length)
  6417. }
  6418. Buffer.isBuffer = function isBuffer (b) {
  6419. return !!(b != null && b._isBuffer)
  6420. }
  6421. Buffer.compare = function compare (a, b) {
  6422. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  6423. throw new TypeError('Arguments must be Buffers')
  6424. }
  6425. if (a === b) return 0
  6426. var x = a.length
  6427. var y = b.length
  6428. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  6429. if (a[i] !== b[i]) {
  6430. x = a[i]
  6431. y = b[i]
  6432. break
  6433. }
  6434. }
  6435. if (x < y) return -1
  6436. if (y < x) return 1
  6437. return 0
  6438. }
  6439. Buffer.isEncoding = function isEncoding (encoding) {
  6440. switch (String(encoding).toLowerCase()) {
  6441. case 'hex':
  6442. case 'utf8':
  6443. case 'utf-8':
  6444. case 'ascii':
  6445. case 'latin1':
  6446. case 'binary':
  6447. case 'base64':
  6448. case 'ucs2':
  6449. case 'ucs-2':
  6450. case 'utf16le':
  6451. case 'utf-16le':
  6452. return true
  6453. default:
  6454. return false
  6455. }
  6456. }
  6457. Buffer.concat = function concat (list, length) {
  6458. if (!isArray(list)) {
  6459. throw new TypeError('"list" argument must be an Array of Buffers')
  6460. }
  6461. if (list.length === 0) {
  6462. return Buffer.alloc(0)
  6463. }
  6464. var i
  6465. if (length === undefined) {
  6466. length = 0
  6467. for (i = 0; i < list.length; ++i) {
  6468. length += list[i].length
  6469. }
  6470. }
  6471. var buffer = Buffer.allocUnsafe(length)
  6472. var pos = 0
  6473. for (i = 0; i < list.length; ++i) {
  6474. var buf = list[i]
  6475. if (!Buffer.isBuffer(buf)) {
  6476. throw new TypeError('"list" argument must be an Array of Buffers')
  6477. }
  6478. buf.copy(buffer, pos)
  6479. pos += buf.length
  6480. }
  6481. return buffer
  6482. }
  6483. function byteLength (string, encoding) {
  6484. if (Buffer.isBuffer(string)) {
  6485. return string.length
  6486. }
  6487. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  6488. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  6489. return string.byteLength
  6490. }
  6491. if (typeof string !== 'string') {
  6492. string = '' + string
  6493. }
  6494. var len = string.length
  6495. if (len === 0) return 0
  6496. // Use a for loop to avoid recursion
  6497. var loweredCase = false
  6498. for (;;) {
  6499. switch (encoding) {
  6500. case 'ascii':
  6501. case 'latin1':
  6502. case 'binary':
  6503. return len
  6504. case 'utf8':
  6505. case 'utf-8':
  6506. case undefined:
  6507. return utf8ToBytes(string).length
  6508. case 'ucs2':
  6509. case 'ucs-2':
  6510. case 'utf16le':
  6511. case 'utf-16le':
  6512. return len * 2
  6513. case 'hex':
  6514. return len >>> 1
  6515. case 'base64':
  6516. return base64ToBytes(string).length
  6517. default:
  6518. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  6519. encoding = ('' + encoding).toLowerCase()
  6520. loweredCase = true
  6521. }
  6522. }
  6523. }
  6524. Buffer.byteLength = byteLength
  6525. function slowToString (encoding, start, end) {
  6526. var loweredCase = false
  6527. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  6528. // property of a typed array.
  6529. // This behaves neither like String nor Uint8Array in that we set start/end
  6530. // to their upper/lower bounds if the value passed is out of range.
  6531. // undefined is handled specially as per ECMA-262 6th Edition,
  6532. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  6533. if (start === undefined || start < 0) {
  6534. start = 0
  6535. }
  6536. // Return early if start > this.length. Done here to prevent potential uint32
  6537. // coercion fail below.
  6538. if (start > this.length) {
  6539. return ''
  6540. }
  6541. if (end === undefined || end > this.length) {
  6542. end = this.length
  6543. }
  6544. if (end <= 0) {
  6545. return ''
  6546. }
  6547. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  6548. end >>>= 0
  6549. start >>>= 0
  6550. if (end <= start) {
  6551. return ''
  6552. }
  6553. if (!encoding) encoding = 'utf8'
  6554. while (true) {
  6555. switch (encoding) {
  6556. case 'hex':
  6557. return hexSlice(this, start, end)
  6558. case 'utf8':
  6559. case 'utf-8':
  6560. return utf8Slice(this, start, end)
  6561. case 'ascii':
  6562. return asciiSlice(this, start, end)
  6563. case 'latin1':
  6564. case 'binary':
  6565. return latin1Slice(this, start, end)
  6566. case 'base64':
  6567. return base64Slice(this, start, end)
  6568. case 'ucs2':
  6569. case 'ucs-2':
  6570. case 'utf16le':
  6571. case 'utf-16le':
  6572. return utf16leSlice(this, start, end)
  6573. default:
  6574. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  6575. encoding = (encoding + '').toLowerCase()
  6576. loweredCase = true
  6577. }
  6578. }
  6579. }
  6580. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  6581. // Buffer instances.
  6582. Buffer.prototype._isBuffer = true
  6583. function swap (b, n, m) {
  6584. var i = b[n]
  6585. b[n] = b[m]
  6586. b[m] = i
  6587. }
  6588. Buffer.prototype.swap16 = function swap16 () {
  6589. var len = this.length
  6590. if (len % 2 !== 0) {
  6591. throw new RangeError('Buffer size must be a multiple of 16-bits')
  6592. }
  6593. for (var i = 0; i < len; i += 2) {
  6594. swap(this, i, i + 1)
  6595. }
  6596. return this
  6597. }
  6598. Buffer.prototype.swap32 = function swap32 () {
  6599. var len = this.length
  6600. if (len % 4 !== 0) {
  6601. throw new RangeError('Buffer size must be a multiple of 32-bits')
  6602. }
  6603. for (var i = 0; i < len; i += 4) {
  6604. swap(this, i, i + 3)
  6605. swap(this, i + 1, i + 2)
  6606. }
  6607. return this
  6608. }
  6609. Buffer.prototype.swap64 = function swap64 () {
  6610. var len = this.length
  6611. if (len % 8 !== 0) {
  6612. throw new RangeError('Buffer size must be a multiple of 64-bits')
  6613. }
  6614. for (var i = 0; i < len; i += 8) {
  6615. swap(this, i, i + 7)
  6616. swap(this, i + 1, i + 6)
  6617. swap(this, i + 2, i + 5)
  6618. swap(this, i + 3, i + 4)
  6619. }
  6620. return this
  6621. }
  6622. Buffer.prototype.toString = function toString () {
  6623. var length = this.length | 0
  6624. if (length === 0) return ''
  6625. if (arguments.length === 0) return utf8Slice(this, 0, length)
  6626. return slowToString.apply(this, arguments)
  6627. }
  6628. Buffer.prototype.equals = function equals (b) {
  6629. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  6630. if (this === b) return true
  6631. return Buffer.compare(this, b) === 0
  6632. }
  6633. Buffer.prototype.inspect = function inspect () {
  6634. var str = ''
  6635. var max = exports.INSPECT_MAX_BYTES
  6636. if (this.length > 0) {
  6637. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  6638. if (this.length > max) str += ' ... '
  6639. }
  6640. return '<Buffer ' + str + '>'
  6641. }
  6642. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  6643. if (!Buffer.isBuffer(target)) {
  6644. throw new TypeError('Argument must be a Buffer')
  6645. }
  6646. if (start === undefined) {
  6647. start = 0
  6648. }
  6649. if (end === undefined) {
  6650. end = target ? target.length : 0
  6651. }
  6652. if (thisStart === undefined) {
  6653. thisStart = 0
  6654. }
  6655. if (thisEnd === undefined) {
  6656. thisEnd = this.length
  6657. }
  6658. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  6659. throw new RangeError('out of range index')
  6660. }
  6661. if (thisStart >= thisEnd && start >= end) {
  6662. return 0
  6663. }
  6664. if (thisStart >= thisEnd) {
  6665. return -1
  6666. }
  6667. if (start >= end) {
  6668. return 1
  6669. }
  6670. start >>>= 0
  6671. end >>>= 0
  6672. thisStart >>>= 0
  6673. thisEnd >>>= 0
  6674. if (this === target) return 0
  6675. var x = thisEnd - thisStart
  6676. var y = end - start
  6677. var len = Math.min(x, y)
  6678. var thisCopy = this.slice(thisStart, thisEnd)
  6679. var targetCopy = target.slice(start, end)
  6680. for (var i = 0; i < len; ++i) {
  6681. if (thisCopy[i] !== targetCopy[i]) {
  6682. x = thisCopy[i]
  6683. y = targetCopy[i]
  6684. break
  6685. }
  6686. }
  6687. if (x < y) return -1
  6688. if (y < x) return 1
  6689. return 0
  6690. }
  6691. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  6692. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  6693. //
  6694. // Arguments:
  6695. // - buffer - a Buffer to search
  6696. // - val - a string, Buffer, or number
  6697. // - byteOffset - an index into `buffer`; will be clamped to an int32
  6698. // - encoding - an optional encoding, relevant is val is a string
  6699. // - dir - true for indexOf, false for lastIndexOf
  6700. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  6701. // Empty buffer means no match
  6702. if (buffer.length === 0) return -1
  6703. // Normalize byteOffset
  6704. if (typeof byteOffset === 'string') {
  6705. encoding = byteOffset
  6706. byteOffset = 0
  6707. } else if (byteOffset > 0x7fffffff) {
  6708. byteOffset = 0x7fffffff
  6709. } else if (byteOffset < -0x80000000) {
  6710. byteOffset = -0x80000000
  6711. }
  6712. byteOffset = +byteOffset // Coerce to Number.
  6713. if (isNaN(byteOffset)) {
  6714. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  6715. byteOffset = dir ? 0 : (buffer.length - 1)
  6716. }
  6717. // Normalize byteOffset: negative offsets start from the end of the buffer
  6718. if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  6719. if (byteOffset >= buffer.length) {
  6720. if (dir) return -1
  6721. else byteOffset = buffer.length - 1
  6722. } else if (byteOffset < 0) {
  6723. if (dir) byteOffset = 0
  6724. else return -1
  6725. }
  6726. // Normalize val
  6727. if (typeof val === 'string') {
  6728. val = Buffer.from(val, encoding)
  6729. }
  6730. // Finally, search either indexOf (if dir is true) or lastIndexOf
  6731. if (Buffer.isBuffer(val)) {
  6732. // Special case: looking for empty string/buffer always fails
  6733. if (val.length === 0) {
  6734. return -1
  6735. }
  6736. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  6737. } else if (typeof val === 'number') {
  6738. val = val & 0xFF // Search for a byte value [0-255]
  6739. if (Buffer.TYPED_ARRAY_SUPPORT &&
  6740. typeof Uint8Array.prototype.indexOf === 'function') {
  6741. if (dir) {
  6742. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  6743. } else {
  6744. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  6745. }
  6746. }
  6747. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  6748. }
  6749. throw new TypeError('val must be string, number or Buffer')
  6750. }
  6751. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  6752. var indexSize = 1
  6753. var arrLength = arr.length
  6754. var valLength = val.length
  6755. if (encoding !== undefined) {
  6756. encoding = String(encoding).toLowerCase()
  6757. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  6758. encoding === 'utf16le' || encoding === 'utf-16le') {
  6759. if (arr.length < 2 || val.length < 2) {
  6760. return -1
  6761. }
  6762. indexSize = 2
  6763. arrLength /= 2
  6764. valLength /= 2
  6765. byteOffset /= 2
  6766. }
  6767. }
  6768. function read (buf, i) {
  6769. if (indexSize === 1) {
  6770. return buf[i]
  6771. } else {
  6772. return buf.readUInt16BE(i * indexSize)
  6773. }
  6774. }
  6775. var i
  6776. if (dir) {
  6777. var foundIndex = -1
  6778. for (i = byteOffset; i < arrLength; i++) {
  6779. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  6780. if (foundIndex === -1) foundIndex = i
  6781. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  6782. } else {
  6783. if (foundIndex !== -1) i -= i - foundIndex
  6784. foundIndex = -1
  6785. }
  6786. }
  6787. } else {
  6788. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  6789. for (i = byteOffset; i >= 0; i--) {
  6790. var found = true
  6791. for (var j = 0; j < valLength; j++) {
  6792. if (read(arr, i + j) !== read(val, j)) {
  6793. found = false
  6794. break
  6795. }
  6796. }
  6797. if (found) return i
  6798. }
  6799. }
  6800. return -1
  6801. }
  6802. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  6803. return this.indexOf(val, byteOffset, encoding) !== -1
  6804. }
  6805. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  6806. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  6807. }
  6808. Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  6809. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  6810. }
  6811. function hexWrite (buf, string, offset, length) {
  6812. offset = Number(offset) || 0
  6813. var remaining = buf.length - offset
  6814. if (!length) {
  6815. length = remaining
  6816. } else {
  6817. length = Number(length)
  6818. if (length > remaining) {
  6819. length = remaining
  6820. }
  6821. }
  6822. // must be an even number of digits
  6823. var strLen = string.length
  6824. if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
  6825. if (length > strLen / 2) {
  6826. length = strLen / 2
  6827. }
  6828. for (var i = 0; i < length; ++i) {
  6829. var parsed = parseInt(string.substr(i * 2, 2), 16)
  6830. if (isNaN(parsed)) return i
  6831. buf[offset + i] = parsed
  6832. }
  6833. return i
  6834. }
  6835. function utf8Write (buf, string, offset, length) {
  6836. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  6837. }
  6838. function asciiWrite (buf, string, offset, length) {
  6839. return blitBuffer(asciiToBytes(string), buf, offset, length)
  6840. }
  6841. function latin1Write (buf, string, offset, length) {
  6842. return asciiWrite(buf, string, offset, length)
  6843. }
  6844. function base64Write (buf, string, offset, length) {
  6845. return blitBuffer(base64ToBytes(string), buf, offset, length)
  6846. }
  6847. function ucs2Write (buf, string, offset, length) {
  6848. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  6849. }
  6850. Buffer.prototype.write = function write (string, offset, length, encoding) {
  6851. // Buffer#write(string)
  6852. if (offset === undefined) {
  6853. encoding = 'utf8'
  6854. length = this.length
  6855. offset = 0
  6856. // Buffer#write(string, encoding)
  6857. } else if (length === undefined && typeof offset === 'string') {
  6858. encoding = offset
  6859. length = this.length
  6860. offset = 0
  6861. // Buffer#write(string, offset[, length][, encoding])
  6862. } else if (isFinite(offset)) {
  6863. offset = offset | 0
  6864. if (isFinite(length)) {
  6865. length = length | 0
  6866. if (encoding === undefined) encoding = 'utf8'
  6867. } else {
  6868. encoding = length
  6869. length = undefined
  6870. }
  6871. // legacy write(string, encoding, offset, length) - remove in v0.13
  6872. } else {
  6873. throw new Error(
  6874. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  6875. )
  6876. }
  6877. var remaining = this.length - offset
  6878. if (length === undefined || length > remaining) length = remaining
  6879. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  6880. throw new RangeError('Attempt to write outside buffer bounds')
  6881. }
  6882. if (!encoding) encoding = 'utf8'
  6883. var loweredCase = false
  6884. for (;;) {
  6885. switch (encoding) {
  6886. case 'hex':
  6887. return hexWrite(this, string, offset, length)
  6888. case 'utf8':
  6889. case 'utf-8':
  6890. return utf8Write(this, string, offset, length)
  6891. case 'ascii':
  6892. return asciiWrite(this, string, offset, length)
  6893. case 'latin1':
  6894. case 'binary':
  6895. return latin1Write(this, string, offset, length)
  6896. case 'base64':
  6897. // Warning: maxLength not taken into account in base64Write
  6898. return base64Write(this, string, offset, length)
  6899. case 'ucs2':
  6900. case 'ucs-2':
  6901. case 'utf16le':
  6902. case 'utf-16le':
  6903. return ucs2Write(this, string, offset, length)
  6904. default:
  6905. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  6906. encoding = ('' + encoding).toLowerCase()
  6907. loweredCase = true
  6908. }
  6909. }
  6910. }
  6911. Buffer.prototype.toJSON = function toJSON () {
  6912. return {
  6913. type: 'Buffer',
  6914. data: Array.prototype.slice.call(this._arr || this, 0)
  6915. }
  6916. }
  6917. function base64Slice (buf, start, end) {
  6918. if (start === 0 && end === buf.length) {
  6919. return base64.fromByteArray(buf)
  6920. } else {
  6921. return base64.fromByteArray(buf.slice(start, end))
  6922. }
  6923. }
  6924. function utf8Slice (buf, start, end) {
  6925. end = Math.min(buf.length, end)
  6926. var res = []
  6927. var i = start
  6928. while (i < end) {
  6929. var firstByte = buf[i]
  6930. var codePoint = null
  6931. var bytesPerSequence = (firstByte > 0xEF) ? 4
  6932. : (firstByte > 0xDF) ? 3
  6933. : (firstByte > 0xBF) ? 2
  6934. : 1
  6935. if (i + bytesPerSequence <= end) {
  6936. var secondByte, thirdByte, fourthByte, tempCodePoint
  6937. switch (bytesPerSequence) {
  6938. case 1:
  6939. if (firstByte < 0x80) {
  6940. codePoint = firstByte
  6941. }
  6942. break
  6943. case 2:
  6944. secondByte = buf[i + 1]
  6945. if ((secondByte & 0xC0) === 0x80) {
  6946. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  6947. if (tempCodePoint > 0x7F) {
  6948. codePoint = tempCodePoint
  6949. }
  6950. }
  6951. break
  6952. case 3:
  6953. secondByte = buf[i + 1]
  6954. thirdByte = buf[i + 2]
  6955. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  6956. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  6957. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  6958. codePoint = tempCodePoint
  6959. }
  6960. }
  6961. break
  6962. case 4:
  6963. secondByte = buf[i + 1]
  6964. thirdByte = buf[i + 2]
  6965. fourthByte = buf[i + 3]
  6966. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  6967. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  6968. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  6969. codePoint = tempCodePoint
  6970. }
  6971. }
  6972. }
  6973. }
  6974. if (codePoint === null) {
  6975. // we did not generate a valid codePoint so insert a
  6976. // replacement char (U+FFFD) and advance only 1 byte
  6977. codePoint = 0xFFFD
  6978. bytesPerSequence = 1
  6979. } else if (codePoint > 0xFFFF) {
  6980. // encode to utf16 (surrogate pair dance)
  6981. codePoint -= 0x10000
  6982. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  6983. codePoint = 0xDC00 | codePoint & 0x3FF
  6984. }
  6985. res.push(codePoint)
  6986. i += bytesPerSequence
  6987. }
  6988. return decodeCodePointsArray(res)
  6989. }
  6990. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  6991. // the lowest limit is Chrome, with 0x10000 args.
  6992. // We go 1 magnitude less, for safety
  6993. var MAX_ARGUMENTS_LENGTH = 0x1000
  6994. function decodeCodePointsArray (codePoints) {
  6995. var len = codePoints.length
  6996. if (len <= MAX_ARGUMENTS_LENGTH) {
  6997. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  6998. }
  6999. // Decode in chunks to avoid "call stack size exceeded".
  7000. var res = ''
  7001. var i = 0
  7002. while (i < len) {
  7003. res += String.fromCharCode.apply(
  7004. String,
  7005. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  7006. )
  7007. }
  7008. return res
  7009. }
  7010. function asciiSlice (buf, start, end) {
  7011. var ret = ''
  7012. end = Math.min(buf.length, end)
  7013. for (var i = start; i < end; ++i) {
  7014. ret += String.fromCharCode(buf[i] & 0x7F)
  7015. }
  7016. return ret
  7017. }
  7018. function latin1Slice (buf, start, end) {
  7019. var ret = ''
  7020. end = Math.min(buf.length, end)
  7021. for (var i = start; i < end; ++i) {
  7022. ret += String.fromCharCode(buf[i])
  7023. }
  7024. return ret
  7025. }
  7026. function hexSlice (buf, start, end) {
  7027. var len = buf.length
  7028. if (!start || start < 0) start = 0
  7029. if (!end || end < 0 || end > len) end = len
  7030. var out = ''
  7031. for (var i = start; i < end; ++i) {
  7032. out += toHex(buf[i])
  7033. }
  7034. return out
  7035. }
  7036. function utf16leSlice (buf, start, end) {
  7037. var bytes = buf.slice(start, end)
  7038. var res = ''
  7039. for (var i = 0; i < bytes.length; i += 2) {
  7040. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
  7041. }
  7042. return res
  7043. }
  7044. Buffer.prototype.slice = function slice (start, end) {
  7045. var len = this.length
  7046. start = ~~start
  7047. end = end === undefined ? len : ~~end
  7048. if (start < 0) {
  7049. start += len
  7050. if (start < 0) start = 0
  7051. } else if (start > len) {
  7052. start = len
  7053. }
  7054. if (end < 0) {
  7055. end += len
  7056. if (end < 0) end = 0
  7057. } else if (end > len) {
  7058. end = len
  7059. }
  7060. if (end < start) end = start
  7061. var newBuf
  7062. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7063. newBuf = this.subarray(start, end)
  7064. newBuf.__proto__ = Buffer.prototype
  7065. } else {
  7066. var sliceLen = end - start
  7067. newBuf = new Buffer(sliceLen, undefined)
  7068. for (var i = 0; i < sliceLen; ++i) {
  7069. newBuf[i] = this[i + start]
  7070. }
  7071. }
  7072. return newBuf
  7073. }
  7074. /*
  7075. * Need to make sure that buffer isn't trying to write out of bounds.
  7076. */
  7077. function checkOffset (offset, ext, length) {
  7078. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  7079. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  7080. }
  7081. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  7082. offset = offset | 0
  7083. byteLength = byteLength | 0
  7084. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7085. var val = this[offset]
  7086. var mul = 1
  7087. var i = 0
  7088. while (++i < byteLength && (mul *= 0x100)) {
  7089. val += this[offset + i] * mul
  7090. }
  7091. return val
  7092. }
  7093. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  7094. offset = offset | 0
  7095. byteLength = byteLength | 0
  7096. if (!noAssert) {
  7097. checkOffset(offset, byteLength, this.length)
  7098. }
  7099. var val = this[offset + --byteLength]
  7100. var mul = 1
  7101. while (byteLength > 0 && (mul *= 0x100)) {
  7102. val += this[offset + --byteLength] * mul
  7103. }
  7104. return val
  7105. }
  7106. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  7107. if (!noAssert) checkOffset(offset, 1, this.length)
  7108. return this[offset]
  7109. }
  7110. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  7111. if (!noAssert) checkOffset(offset, 2, this.length)
  7112. return this[offset] | (this[offset + 1] << 8)
  7113. }
  7114. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  7115. if (!noAssert) checkOffset(offset, 2, this.length)
  7116. return (this[offset] << 8) | this[offset + 1]
  7117. }
  7118. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  7119. if (!noAssert) checkOffset(offset, 4, this.length)
  7120. return ((this[offset]) |
  7121. (this[offset + 1] << 8) |
  7122. (this[offset + 2] << 16)) +
  7123. (this[offset + 3] * 0x1000000)
  7124. }
  7125. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  7126. if (!noAssert) checkOffset(offset, 4, this.length)
  7127. return (this[offset] * 0x1000000) +
  7128. ((this[offset + 1] << 16) |
  7129. (this[offset + 2] << 8) |
  7130. this[offset + 3])
  7131. }
  7132. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  7133. offset = offset | 0
  7134. byteLength = byteLength | 0
  7135. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7136. var val = this[offset]
  7137. var mul = 1
  7138. var i = 0
  7139. while (++i < byteLength && (mul *= 0x100)) {
  7140. val += this[offset + i] * mul
  7141. }
  7142. mul *= 0x80
  7143. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  7144. return val
  7145. }
  7146. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  7147. offset = offset | 0
  7148. byteLength = byteLength | 0
  7149. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7150. var i = byteLength
  7151. var mul = 1
  7152. var val = this[offset + --i]
  7153. while (i > 0 && (mul *= 0x100)) {
  7154. val += this[offset + --i] * mul
  7155. }
  7156. mul *= 0x80
  7157. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  7158. return val
  7159. }
  7160. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  7161. if (!noAssert) checkOffset(offset, 1, this.length)
  7162. if (!(this[offset] & 0x80)) return (this[offset])
  7163. return ((0xff - this[offset] + 1) * -1)
  7164. }
  7165. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  7166. if (!noAssert) checkOffset(offset, 2, this.length)
  7167. var val = this[offset] | (this[offset + 1] << 8)
  7168. return (val & 0x8000) ? val | 0xFFFF0000 : val
  7169. }
  7170. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  7171. if (!noAssert) checkOffset(offset, 2, this.length)
  7172. var val = this[offset + 1] | (this[offset] << 8)
  7173. return (val & 0x8000) ? val | 0xFFFF0000 : val
  7174. }
  7175. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  7176. if (!noAssert) checkOffset(offset, 4, this.length)
  7177. return (this[offset]) |
  7178. (this[offset + 1] << 8) |
  7179. (this[offset + 2] << 16) |
  7180. (this[offset + 3] << 24)
  7181. }
  7182. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  7183. if (!noAssert) checkOffset(offset, 4, this.length)
  7184. return (this[offset] << 24) |
  7185. (this[offset + 1] << 16) |
  7186. (this[offset + 2] << 8) |
  7187. (this[offset + 3])
  7188. }
  7189. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  7190. if (!noAssert) checkOffset(offset, 4, this.length)
  7191. return ieee754.read(this, offset, true, 23, 4)
  7192. }
  7193. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  7194. if (!noAssert) checkOffset(offset, 4, this.length)
  7195. return ieee754.read(this, offset, false, 23, 4)
  7196. }
  7197. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  7198. if (!noAssert) checkOffset(offset, 8, this.length)
  7199. return ieee754.read(this, offset, true, 52, 8)
  7200. }
  7201. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  7202. if (!noAssert) checkOffset(offset, 8, this.length)
  7203. return ieee754.read(this, offset, false, 52, 8)
  7204. }
  7205. function checkInt (buf, value, offset, ext, max, min) {
  7206. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  7207. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  7208. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  7209. }
  7210. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  7211. value = +value
  7212. offset = offset | 0
  7213. byteLength = byteLength | 0
  7214. if (!noAssert) {
  7215. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  7216. checkInt(this, value, offset, byteLength, maxBytes, 0)
  7217. }
  7218. var mul = 1
  7219. var i = 0
  7220. this[offset] = value & 0xFF
  7221. while (++i < byteLength && (mul *= 0x100)) {
  7222. this[offset + i] = (value / mul) & 0xFF
  7223. }
  7224. return offset + byteLength
  7225. }
  7226. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  7227. value = +value
  7228. offset = offset | 0
  7229. byteLength = byteLength | 0
  7230. if (!noAssert) {
  7231. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  7232. checkInt(this, value, offset, byteLength, maxBytes, 0)
  7233. }
  7234. var i = byteLength - 1
  7235. var mul = 1
  7236. this[offset + i] = value & 0xFF
  7237. while (--i >= 0 && (mul *= 0x100)) {
  7238. this[offset + i] = (value / mul) & 0xFF
  7239. }
  7240. return offset + byteLength
  7241. }
  7242. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  7243. value = +value
  7244. offset = offset | 0
  7245. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  7246. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  7247. this[offset] = (value & 0xff)
  7248. return offset + 1
  7249. }
  7250. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  7251. if (value < 0) value = 0xffff + value + 1
  7252. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  7253. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  7254. (littleEndian ? i : 1 - i) * 8
  7255. }
  7256. }
  7257. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  7258. value = +value
  7259. offset = offset | 0
  7260. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  7261. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7262. this[offset] = (value & 0xff)
  7263. this[offset + 1] = (value >>> 8)
  7264. } else {
  7265. objectWriteUInt16(this, value, offset, true)
  7266. }
  7267. return offset + 2
  7268. }
  7269. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  7270. value = +value
  7271. offset = offset | 0
  7272. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  7273. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7274. this[offset] = (value >>> 8)
  7275. this[offset + 1] = (value & 0xff)
  7276. } else {
  7277. objectWriteUInt16(this, value, offset, false)
  7278. }
  7279. return offset + 2
  7280. }
  7281. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  7282. if (value < 0) value = 0xffffffff + value + 1
  7283. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  7284. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  7285. }
  7286. }
  7287. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  7288. value = +value
  7289. offset = offset | 0
  7290. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  7291. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7292. this[offset + 3] = (value >>> 24)
  7293. this[offset + 2] = (value >>> 16)
  7294. this[offset + 1] = (value >>> 8)
  7295. this[offset] = (value & 0xff)
  7296. } else {
  7297. objectWriteUInt32(this, value, offset, true)
  7298. }
  7299. return offset + 4
  7300. }
  7301. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  7302. value = +value
  7303. offset = offset | 0
  7304. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  7305. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7306. this[offset] = (value >>> 24)
  7307. this[offset + 1] = (value >>> 16)
  7308. this[offset + 2] = (value >>> 8)
  7309. this[offset + 3] = (value & 0xff)
  7310. } else {
  7311. objectWriteUInt32(this, value, offset, false)
  7312. }
  7313. return offset + 4
  7314. }
  7315. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  7316. value = +value
  7317. offset = offset | 0
  7318. if (!noAssert) {
  7319. var limit = Math.pow(2, 8 * byteLength - 1)
  7320. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  7321. }
  7322. var i = 0
  7323. var mul = 1
  7324. var sub = 0
  7325. this[offset] = value & 0xFF
  7326. while (++i < byteLength && (mul *= 0x100)) {
  7327. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  7328. sub = 1
  7329. }
  7330. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  7331. }
  7332. return offset + byteLength
  7333. }
  7334. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  7335. value = +value
  7336. offset = offset | 0
  7337. if (!noAssert) {
  7338. var limit = Math.pow(2, 8 * byteLength - 1)
  7339. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  7340. }
  7341. var i = byteLength - 1
  7342. var mul = 1
  7343. var sub = 0
  7344. this[offset + i] = value & 0xFF
  7345. while (--i >= 0 && (mul *= 0x100)) {
  7346. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  7347. sub = 1
  7348. }
  7349. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  7350. }
  7351. return offset + byteLength
  7352. }
  7353. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  7354. value = +value
  7355. offset = offset | 0
  7356. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  7357. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  7358. if (value < 0) value = 0xff + value + 1
  7359. this[offset] = (value & 0xff)
  7360. return offset + 1
  7361. }
  7362. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  7363. value = +value
  7364. offset = offset | 0
  7365. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  7366. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7367. this[offset] = (value & 0xff)
  7368. this[offset + 1] = (value >>> 8)
  7369. } else {
  7370. objectWriteUInt16(this, value, offset, true)
  7371. }
  7372. return offset + 2
  7373. }
  7374. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  7375. value = +value
  7376. offset = offset | 0
  7377. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  7378. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7379. this[offset] = (value >>> 8)
  7380. this[offset + 1] = (value & 0xff)
  7381. } else {
  7382. objectWriteUInt16(this, value, offset, false)
  7383. }
  7384. return offset + 2
  7385. }
  7386. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  7387. value = +value
  7388. offset = offset | 0
  7389. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  7390. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7391. this[offset] = (value & 0xff)
  7392. this[offset + 1] = (value >>> 8)
  7393. this[offset + 2] = (value >>> 16)
  7394. this[offset + 3] = (value >>> 24)
  7395. } else {
  7396. objectWriteUInt32(this, value, offset, true)
  7397. }
  7398. return offset + 4
  7399. }
  7400. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  7401. value = +value
  7402. offset = offset | 0
  7403. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  7404. if (value < 0) value = 0xffffffff + value + 1
  7405. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7406. this[offset] = (value >>> 24)
  7407. this[offset + 1] = (value >>> 16)
  7408. this[offset + 2] = (value >>> 8)
  7409. this[offset + 3] = (value & 0xff)
  7410. } else {
  7411. objectWriteUInt32(this, value, offset, false)
  7412. }
  7413. return offset + 4
  7414. }
  7415. function checkIEEE754 (buf, value, offset, ext, max, min) {
  7416. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  7417. if (offset < 0) throw new RangeError('Index out of range')
  7418. }
  7419. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  7420. if (!noAssert) {
  7421. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  7422. }
  7423. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  7424. return offset + 4
  7425. }
  7426. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  7427. return writeFloat(this, value, offset, true, noAssert)
  7428. }
  7429. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  7430. return writeFloat(this, value, offset, false, noAssert)
  7431. }
  7432. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  7433. if (!noAssert) {
  7434. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  7435. }
  7436. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  7437. return offset + 8
  7438. }
  7439. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  7440. return writeDouble(this, value, offset, true, noAssert)
  7441. }
  7442. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  7443. return writeDouble(this, value, offset, false, noAssert)
  7444. }
  7445. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  7446. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  7447. if (!start) start = 0
  7448. if (!end && end !== 0) end = this.length
  7449. if (targetStart >= target.length) targetStart = target.length
  7450. if (!targetStart) targetStart = 0
  7451. if (end > 0 && end < start) end = start
  7452. // Copy 0 bytes; we're done
  7453. if (end === start) return 0
  7454. if (target.length === 0 || this.length === 0) return 0
  7455. // Fatal error conditions
  7456. if (targetStart < 0) {
  7457. throw new RangeError('targetStart out of bounds')
  7458. }
  7459. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  7460. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  7461. // Are we oob?
  7462. if (end > this.length) end = this.length
  7463. if (target.length - targetStart < end - start) {
  7464. end = target.length - targetStart + start
  7465. }
  7466. var len = end - start
  7467. var i
  7468. if (this === target && start < targetStart && targetStart < end) {
  7469. // descending copy from end
  7470. for (i = len - 1; i >= 0; --i) {
  7471. target[i + targetStart] = this[i + start]
  7472. }
  7473. } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  7474. // ascending copy from start
  7475. for (i = 0; i < len; ++i) {
  7476. target[i + targetStart] = this[i + start]
  7477. }
  7478. } else {
  7479. Uint8Array.prototype.set.call(
  7480. target,
  7481. this.subarray(start, start + len),
  7482. targetStart
  7483. )
  7484. }
  7485. return len
  7486. }
  7487. // Usage:
  7488. // buffer.fill(number[, offset[, end]])
  7489. // buffer.fill(buffer[, offset[, end]])
  7490. // buffer.fill(string[, offset[, end]][, encoding])
  7491. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  7492. // Handle string cases:
  7493. if (typeof val === 'string') {
  7494. if (typeof start === 'string') {
  7495. encoding = start
  7496. start = 0
  7497. end = this.length
  7498. } else if (typeof end === 'string') {
  7499. encoding = end
  7500. end = this.length
  7501. }
  7502. if (val.length === 1) {
  7503. var code = val.charCodeAt(0)
  7504. if (code < 256) {
  7505. val = code
  7506. }
  7507. }
  7508. if (encoding !== undefined && typeof encoding !== 'string') {
  7509. throw new TypeError('encoding must be a string')
  7510. }
  7511. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  7512. throw new TypeError('Unknown encoding: ' + encoding)
  7513. }
  7514. } else if (typeof val === 'number') {
  7515. val = val & 255
  7516. }
  7517. // Invalid ranges are not set to a default, so can range check early.
  7518. if (start < 0 || this.length < start || this.length < end) {
  7519. throw new RangeError('Out of range index')
  7520. }
  7521. if (end <= start) {
  7522. return this
  7523. }
  7524. start = start >>> 0
  7525. end = end === undefined ? this.length : end >>> 0
  7526. if (!val) val = 0
  7527. var i
  7528. if (typeof val === 'number') {
  7529. for (i = start; i < end; ++i) {
  7530. this[i] = val
  7531. }
  7532. } else {
  7533. var bytes = Buffer.isBuffer(val)
  7534. ? val
  7535. : utf8ToBytes(new Buffer(val, encoding).toString())
  7536. var len = bytes.length
  7537. for (i = 0; i < end - start; ++i) {
  7538. this[i + start] = bytes[i % len]
  7539. }
  7540. }
  7541. return this
  7542. }
  7543. // HELPER FUNCTIONS
  7544. // ================
  7545. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
  7546. function base64clean (str) {
  7547. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  7548. str = stringtrim(str).replace(INVALID_BASE64_RE, '')
  7549. // Node converts strings with length < 2 to ''
  7550. if (str.length < 2) return ''
  7551. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  7552. while (str.length % 4 !== 0) {
  7553. str = str + '='
  7554. }
  7555. return str
  7556. }
  7557. function stringtrim (str) {
  7558. if (str.trim) return str.trim()
  7559. return str.replace(/^\s+|\s+$/g, '')
  7560. }
  7561. function toHex (n) {
  7562. if (n < 16) return '0' + n.toString(16)
  7563. return n.toString(16)
  7564. }
  7565. function utf8ToBytes (string, units) {
  7566. units = units || Infinity
  7567. var codePoint
  7568. var length = string.length
  7569. var leadSurrogate = null
  7570. var bytes = []
  7571. for (var i = 0; i < length; ++i) {
  7572. codePoint = string.charCodeAt(i)
  7573. // is surrogate component
  7574. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  7575. // last char was a lead
  7576. if (!leadSurrogate) {
  7577. // no lead yet
  7578. if (codePoint > 0xDBFF) {
  7579. // unexpected trail
  7580. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7581. continue
  7582. } else if (i + 1 === length) {
  7583. // unpaired lead
  7584. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7585. continue
  7586. }
  7587. // valid lead
  7588. leadSurrogate = codePoint
  7589. continue
  7590. }
  7591. // 2 leads in a row
  7592. if (codePoint < 0xDC00) {
  7593. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7594. leadSurrogate = codePoint
  7595. continue
  7596. }
  7597. // valid surrogate pair
  7598. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  7599. } else if (leadSurrogate) {
  7600. // valid bmp char, but last char was a lead
  7601. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7602. }
  7603. leadSurrogate = null
  7604. // encode utf8
  7605. if (codePoint < 0x80) {
  7606. if ((units -= 1) < 0) break
  7607. bytes.push(codePoint)
  7608. } else if (codePoint < 0x800) {
  7609. if ((units -= 2) < 0) break
  7610. bytes.push(
  7611. codePoint >> 0x6 | 0xC0,
  7612. codePoint & 0x3F | 0x80
  7613. )
  7614. } else if (codePoint < 0x10000) {
  7615. if ((units -= 3) < 0) break
  7616. bytes.push(
  7617. codePoint >> 0xC | 0xE0,
  7618. codePoint >> 0x6 & 0x3F | 0x80,
  7619. codePoint & 0x3F | 0x80
  7620. )
  7621. } else if (codePoint < 0x110000) {
  7622. if ((units -= 4) < 0) break
  7623. bytes.push(
  7624. codePoint >> 0x12 | 0xF0,
  7625. codePoint >> 0xC & 0x3F | 0x80,
  7626. codePoint >> 0x6 & 0x3F | 0x80,
  7627. codePoint & 0x3F | 0x80
  7628. )
  7629. } else {
  7630. throw new Error('Invalid code point')
  7631. }
  7632. }
  7633. return bytes
  7634. }
  7635. function asciiToBytes (str) {
  7636. var byteArray = []
  7637. for (var i = 0; i < str.length; ++i) {
  7638. // Node's code seems to be doing this and not & 0x7F..
  7639. byteArray.push(str.charCodeAt(i) & 0xFF)
  7640. }
  7641. return byteArray
  7642. }
  7643. function utf16leToBytes (str, units) {
  7644. var c, hi, lo
  7645. var byteArray = []
  7646. for (var i = 0; i < str.length; ++i) {
  7647. if ((units -= 2) < 0) break
  7648. c = str.charCodeAt(i)
  7649. hi = c >> 8
  7650. lo = c % 256
  7651. byteArray.push(lo)
  7652. byteArray.push(hi)
  7653. }
  7654. return byteArray
  7655. }
  7656. function base64ToBytes (str) {
  7657. return base64.toByteArray(base64clean(str))
  7658. }
  7659. function blitBuffer (src, dst, offset, length) {
  7660. for (var i = 0; i < length; ++i) {
  7661. if ((i + offset >= dst.length) || (i >= src.length)) break
  7662. dst[i + offset] = src[i]
  7663. }
  7664. return i
  7665. }
  7666. function isnan (val) {
  7667. return val !== val // eslint-disable-line no-self-compare
  7668. }
  7669. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7670. },{"base64-js":39,"ieee754":65,"isarray":68}],45:[function(require,module,exports){
  7671. (function (Buffer){
  7672. // Copyright Joyent, Inc. and other Node contributors.
  7673. //
  7674. // Permission is hereby granted, free of charge, to any person obtaining a
  7675. // copy of this software and associated documentation files (the
  7676. // "Software"), to deal in the Software without restriction, including
  7677. // without limitation the rights to use, copy, modify, merge, publish,
  7678. // distribute, sublicense, and/or sell copies of the Software, and to permit
  7679. // persons to whom the Software is furnished to do so, subject to the
  7680. // following conditions:
  7681. //
  7682. // The above copyright notice and this permission notice shall be included
  7683. // in all copies or substantial portions of the Software.
  7684. //
  7685. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  7686. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  7687. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  7688. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  7689. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  7690. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  7691. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  7692. // NOTE: These type checking functions intentionally don't use `instanceof`
  7693. // because it is fragile and can be easily faked with `Object.create()`.
  7694. function isArray(arg) {
  7695. if (Array.isArray) {
  7696. return Array.isArray(arg);
  7697. }
  7698. return objectToString(arg) === '[object Array]';
  7699. }
  7700. exports.isArray = isArray;
  7701. function isBoolean(arg) {
  7702. return typeof arg === 'boolean';
  7703. }
  7704. exports.isBoolean = isBoolean;
  7705. function isNull(arg) {
  7706. return arg === null;
  7707. }
  7708. exports.isNull = isNull;
  7709. function isNullOrUndefined(arg) {
  7710. return arg == null;
  7711. }
  7712. exports.isNullOrUndefined = isNullOrUndefined;
  7713. function isNumber(arg) {
  7714. return typeof arg === 'number';
  7715. }
  7716. exports.isNumber = isNumber;
  7717. function isString(arg) {
  7718. return typeof arg === 'string';
  7719. }
  7720. exports.isString = isString;
  7721. function isSymbol(arg) {
  7722. return typeof arg === 'symbol';
  7723. }
  7724. exports.isSymbol = isSymbol;
  7725. function isUndefined(arg) {
  7726. return arg === void 0;
  7727. }
  7728. exports.isUndefined = isUndefined;
  7729. function isRegExp(re) {
  7730. return objectToString(re) === '[object RegExp]';
  7731. }
  7732. exports.isRegExp = isRegExp;
  7733. function isObject(arg) {
  7734. return typeof arg === 'object' && arg !== null;
  7735. }
  7736. exports.isObject = isObject;
  7737. function isDate(d) {
  7738. return objectToString(d) === '[object Date]';
  7739. }
  7740. exports.isDate = isDate;
  7741. function isError(e) {
  7742. return (objectToString(e) === '[object Error]' || e instanceof Error);
  7743. }
  7744. exports.isError = isError;
  7745. function isFunction(arg) {
  7746. return typeof arg === 'function';
  7747. }
  7748. exports.isFunction = isFunction;
  7749. function isPrimitive(arg) {
  7750. return arg === null ||
  7751. typeof arg === 'boolean' ||
  7752. typeof arg === 'number' ||
  7753. typeof arg === 'string' ||
  7754. typeof arg === 'symbol' || // ES6 symbol
  7755. typeof arg === 'undefined';
  7756. }
  7757. exports.isPrimitive = isPrimitive;
  7758. exports.isBuffer = Buffer.isBuffer;
  7759. function objectToString(o) {
  7760. return Object.prototype.toString.call(o);
  7761. }
  7762. }).call(this,{"isBuffer":require("../../is-buffer/index.js")})
  7763. },{"../../is-buffer/index.js":67}],46:[function(require,module,exports){
  7764. /*istanbul ignore start*/"use strict";
  7765. exports.__esModule = true;
  7766. exports. /*istanbul ignore end*/convertChangesToDMP = convertChangesToDMP;
  7767. // See: http://code.google.com/p/google-diff-match-patch/wiki/API
  7768. function convertChangesToDMP(changes) {
  7769. var ret = [],
  7770. change = /*istanbul ignore start*/void 0 /*istanbul ignore end*/,
  7771. operation = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
  7772. for (var i = 0; i < changes.length; i++) {
  7773. change = changes[i];
  7774. if (change.added) {
  7775. operation = 1;
  7776. } else if (change.removed) {
  7777. operation = -1;
  7778. } else {
  7779. operation = 0;
  7780. }
  7781. ret.push([operation, change.value]);
  7782. }
  7783. return ret;
  7784. }
  7785. },{}],47:[function(require,module,exports){
  7786. /*istanbul ignore start*/'use strict';
  7787. exports.__esModule = true;
  7788. exports. /*istanbul ignore end*/convertChangesToXML = convertChangesToXML;
  7789. function convertChangesToXML(changes) {
  7790. var ret = [];
  7791. for (var i = 0; i < changes.length; i++) {
  7792. var change = changes[i];
  7793. if (change.added) {
  7794. ret.push('<ins>');
  7795. } else if (change.removed) {
  7796. ret.push('<del>');
  7797. }
  7798. ret.push(escapeHTML(change.value));
  7799. if (change.added) {
  7800. ret.push('</ins>');
  7801. } else if (change.removed) {
  7802. ret.push('</del>');
  7803. }
  7804. }
  7805. return ret.join('');
  7806. }
  7807. function escapeHTML(s) {
  7808. var n = s;
  7809. n = n.replace(/&/g, '&amp;');
  7810. n = n.replace(/</g, '&lt;');
  7811. n = n.replace(/>/g, '&gt;');
  7812. n = n.replace(/"/g, '&quot;');
  7813. return n;
  7814. }
  7815. },{}],48:[function(require,module,exports){
  7816. /*istanbul ignore start*/'use strict';
  7817. exports.__esModule = true;
  7818. exports.arrayDiff = undefined;
  7819. exports. /*istanbul ignore end*/diffArrays = diffArrays;
  7820. var /*istanbul ignore start*/_base = require('./base') /*istanbul ignore end*/;
  7821. /*istanbul ignore start*/
  7822. var _base2 = _interopRequireDefault(_base);
  7823. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  7824. /*istanbul ignore end*/var arrayDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/arrayDiff = new /*istanbul ignore start*/_base2['default']() /*istanbul ignore end*/;
  7825. arrayDiff.tokenize = arrayDiff.join = function (value) {
  7826. return value.slice();
  7827. };
  7828. function diffArrays(oldArr, newArr, callback) {
  7829. return arrayDiff.diff(oldArr, newArr, callback);
  7830. }
  7831. },{"./base":49}],49:[function(require,module,exports){
  7832. /*istanbul ignore start*/'use strict';
  7833. exports.__esModule = true;
  7834. exports['default'] = /*istanbul ignore end*/Diff;
  7835. function Diff() {}
  7836. Diff.prototype = { /*istanbul ignore start*/
  7837. /*istanbul ignore end*/diff: function diff(oldString, newString) {
  7838. /*istanbul ignore start*/var /*istanbul ignore end*/options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  7839. var callback = options.callback;
  7840. if (typeof options === 'function') {
  7841. callback = options;
  7842. options = {};
  7843. }
  7844. this.options = options;
  7845. var self = this;
  7846. function done(value) {
  7847. if (callback) {
  7848. setTimeout(function () {
  7849. callback(undefined, value);
  7850. }, 0);
  7851. return true;
  7852. } else {
  7853. return value;
  7854. }
  7855. }
  7856. // Allow subclasses to massage the input prior to running
  7857. oldString = this.castInput(oldString);
  7858. newString = this.castInput(newString);
  7859. oldString = this.removeEmpty(this.tokenize(oldString));
  7860. newString = this.removeEmpty(this.tokenize(newString));
  7861. var newLen = newString.length,
  7862. oldLen = oldString.length;
  7863. var editLength = 1;
  7864. var maxEditLength = newLen + oldLen;
  7865. var bestPath = [{ newPos: -1, components: [] }];
  7866. // Seed editLength = 0, i.e. the content starts with the same values
  7867. var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
  7868. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  7869. // Identity per the equality and tokenizer
  7870. return done([{ value: this.join(newString), count: newString.length }]);
  7871. }
  7872. // Main worker method. checks all permutations of a given edit length for acceptance.
  7873. function execEditLength() {
  7874. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  7875. var basePath = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
  7876. var addPath = bestPath[diagonalPath - 1],
  7877. removePath = bestPath[diagonalPath + 1],
  7878. _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  7879. if (addPath) {
  7880. // No one else is going to attempt to use this value, clear it
  7881. bestPath[diagonalPath - 1] = undefined;
  7882. }
  7883. var canAdd = addPath && addPath.newPos + 1 < newLen,
  7884. canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
  7885. if (!canAdd && !canRemove) {
  7886. // If this path is a terminal then prune
  7887. bestPath[diagonalPath] = undefined;
  7888. continue;
  7889. }
  7890. // Select the diagonal that we want to branch from. We select the prior
  7891. // path whose position in the new string is the farthest from the origin
  7892. // and does not pass the bounds of the diff graph
  7893. if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
  7894. basePath = clonePath(removePath);
  7895. self.pushComponent(basePath.components, undefined, true);
  7896. } else {
  7897. basePath = addPath; // No need to clone, we've pulled it from the list
  7898. basePath.newPos++;
  7899. self.pushComponent(basePath.components, true, undefined);
  7900. }
  7901. _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath);
  7902. // If we have hit the end of both strings, then we are done
  7903. if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
  7904. return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
  7905. } else {
  7906. // Otherwise track this path as a potential candidate and continue.
  7907. bestPath[diagonalPath] = basePath;
  7908. }
  7909. }
  7910. editLength++;
  7911. }
  7912. // Performs the length of edit iteration. Is a bit fugly as this has to support the
  7913. // sync and async mode which is never fun. Loops over execEditLength until a value
  7914. // is produced.
  7915. if (callback) {
  7916. (function exec() {
  7917. setTimeout(function () {
  7918. // This should not happen, but we want to be safe.
  7919. /* istanbul ignore next */
  7920. if (editLength > maxEditLength) {
  7921. return callback();
  7922. }
  7923. if (!execEditLength()) {
  7924. exec();
  7925. }
  7926. }, 0);
  7927. })();
  7928. } else {
  7929. while (editLength <= maxEditLength) {
  7930. var ret = execEditLength();
  7931. if (ret) {
  7932. return ret;
  7933. }
  7934. }
  7935. }
  7936. },
  7937. /*istanbul ignore start*/ /*istanbul ignore end*/pushComponent: function pushComponent(components, added, removed) {
  7938. var last = components[components.length - 1];
  7939. if (last && last.added === added && last.removed === removed) {
  7940. // We need to clone here as the component clone operation is just
  7941. // as shallow array clone
  7942. components[components.length - 1] = { count: last.count + 1, added: added, removed: removed };
  7943. } else {
  7944. components.push({ count: 1, added: added, removed: removed });
  7945. }
  7946. },
  7947. /*istanbul ignore start*/ /*istanbul ignore end*/extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
  7948. var newLen = newString.length,
  7949. oldLen = oldString.length,
  7950. newPos = basePath.newPos,
  7951. oldPos = newPos - diagonalPath,
  7952. commonCount = 0;
  7953. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
  7954. newPos++;
  7955. oldPos++;
  7956. commonCount++;
  7957. }
  7958. if (commonCount) {
  7959. basePath.components.push({ count: commonCount });
  7960. }
  7961. basePath.newPos = newPos;
  7962. return oldPos;
  7963. },
  7964. /*istanbul ignore start*/ /*istanbul ignore end*/equals: function equals(left, right) {
  7965. return left === right;
  7966. },
  7967. /*istanbul ignore start*/ /*istanbul ignore end*/removeEmpty: function removeEmpty(array) {
  7968. var ret = [];
  7969. for (var i = 0; i < array.length; i++) {
  7970. if (array[i]) {
  7971. ret.push(array[i]);
  7972. }
  7973. }
  7974. return ret;
  7975. },
  7976. /*istanbul ignore start*/ /*istanbul ignore end*/castInput: function castInput(value) {
  7977. return value;
  7978. },
  7979. /*istanbul ignore start*/ /*istanbul ignore end*/tokenize: function tokenize(value) {
  7980. return value.split('');
  7981. },
  7982. /*istanbul ignore start*/ /*istanbul ignore end*/join: function join(chars) {
  7983. return chars.join('');
  7984. }
  7985. };
  7986. function buildValues(diff, components, newString, oldString, useLongestToken) {
  7987. var componentPos = 0,
  7988. componentLen = components.length,
  7989. newPos = 0,
  7990. oldPos = 0;
  7991. for (; componentPos < componentLen; componentPos++) {
  7992. var component = components[componentPos];
  7993. if (!component.removed) {
  7994. if (!component.added && useLongestToken) {
  7995. var value = newString.slice(newPos, newPos + component.count);
  7996. value = value.map(function (value, i) {
  7997. var oldValue = oldString[oldPos + i];
  7998. return oldValue.length > value.length ? oldValue : value;
  7999. });
  8000. component.value = diff.join(value);
  8001. } else {
  8002. component.value = diff.join(newString.slice(newPos, newPos + component.count));
  8003. }
  8004. newPos += component.count;
  8005. // Common case
  8006. if (!component.added) {
  8007. oldPos += component.count;
  8008. }
  8009. } else {
  8010. component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
  8011. oldPos += component.count;
  8012. // Reverse add and remove so removes are output first to match common convention
  8013. // The diffing algorithm is tied to add then remove output and this is the simplest
  8014. // route to get the desired output with minimal overhead.
  8015. if (componentPos && components[componentPos - 1].added) {
  8016. var tmp = components[componentPos - 1];
  8017. components[componentPos - 1] = components[componentPos];
  8018. components[componentPos] = tmp;
  8019. }
  8020. }
  8021. }
  8022. // Special case handle for when one terminal is ignored. For this case we merge the
  8023. // terminal into the prior string and drop the change.
  8024. var lastComponent = components[componentLen - 1];
  8025. if (componentLen > 1 && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
  8026. components[componentLen - 2].value += lastComponent.value;
  8027. components.pop();
  8028. }
  8029. return components;
  8030. }
  8031. function clonePath(path) {
  8032. return { newPos: path.newPos, components: path.components.slice(0) };
  8033. }
  8034. },{}],50:[function(require,module,exports){
  8035. /*istanbul ignore start*/'use strict';
  8036. exports.__esModule = true;
  8037. exports.characterDiff = undefined;
  8038. exports. /*istanbul ignore end*/diffChars = diffChars;
  8039. var /*istanbul ignore start*/_base = require('./base') /*istanbul ignore end*/;
  8040. /*istanbul ignore start*/
  8041. var _base2 = _interopRequireDefault(_base);
  8042. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  8043. /*istanbul ignore end*/var characterDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/characterDiff = new /*istanbul ignore start*/_base2['default']() /*istanbul ignore end*/;
  8044. function diffChars(oldStr, newStr, callback) {
  8045. return characterDiff.diff(oldStr, newStr, callback);
  8046. }
  8047. },{"./base":49}],51:[function(require,module,exports){
  8048. /*istanbul ignore start*/'use strict';
  8049. exports.__esModule = true;
  8050. exports.cssDiff = undefined;
  8051. exports. /*istanbul ignore end*/diffCss = diffCss;
  8052. var /*istanbul ignore start*/_base = require('./base') /*istanbul ignore end*/;
  8053. /*istanbul ignore start*/
  8054. var _base2 = _interopRequireDefault(_base);
  8055. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  8056. /*istanbul ignore end*/var cssDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/cssDiff = new /*istanbul ignore start*/_base2['default']() /*istanbul ignore end*/;
  8057. cssDiff.tokenize = function (value) {
  8058. return value.split(/([{}:;,]|\s+)/);
  8059. };
  8060. function diffCss(oldStr, newStr, callback) {
  8061. return cssDiff.diff(oldStr, newStr, callback);
  8062. }
  8063. },{"./base":49}],52:[function(require,module,exports){
  8064. /*istanbul ignore start*/'use strict';
  8065. exports.__esModule = true;
  8066. exports.jsonDiff = undefined;
  8067. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
  8068. exports. /*istanbul ignore end*/diffJson = diffJson;
  8069. /*istanbul ignore start*/exports. /*istanbul ignore end*/canonicalize = canonicalize;
  8070. var /*istanbul ignore start*/_base = require('./base') /*istanbul ignore end*/;
  8071. /*istanbul ignore start*/
  8072. var _base2 = _interopRequireDefault(_base);
  8073. /*istanbul ignore end*/
  8074. var /*istanbul ignore start*/_line = require('./line') /*istanbul ignore end*/;
  8075. /*istanbul ignore start*/
  8076. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  8077. /*istanbul ignore end*/
  8078. var objectPrototypeToString = Object.prototype.toString;
  8079. var jsonDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/jsonDiff = new /*istanbul ignore start*/_base2['default']() /*istanbul ignore end*/;
  8080. // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
  8081. // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
  8082. jsonDiff.useLongestToken = true;
  8083. jsonDiff.tokenize = /*istanbul ignore start*/_line.lineDiff. /*istanbul ignore end*/tokenize;
  8084. jsonDiff.castInput = function (value) {
  8085. /*istanbul ignore start*/var /*istanbul ignore end*/undefinedReplacement = this.options.undefinedReplacement;
  8086. return typeof value === 'string' ? value : JSON.stringify(canonicalize(value), function (k, v) {
  8087. if (typeof v === 'undefined') {
  8088. return undefinedReplacement;
  8089. }
  8090. return v;
  8091. }, ' ');
  8092. };
  8093. jsonDiff.equals = function (left, right) {
  8094. return (/*istanbul ignore start*/_base2['default']. /*istanbul ignore end*/prototype.equals(left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'))
  8095. );
  8096. };
  8097. function diffJson(oldObj, newObj, options) {
  8098. return jsonDiff.diff(oldObj, newObj, options);
  8099. }
  8100. // This function handles the presence of circular references by bailing out when encountering an
  8101. // object that is already on the "stack" of items being processed.
  8102. function canonicalize(obj, stack, replacementStack) {
  8103. stack = stack || [];
  8104. replacementStack = replacementStack || [];
  8105. var i = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
  8106. for (i = 0; i < stack.length; i += 1) {
  8107. if (stack[i] === obj) {
  8108. return replacementStack[i];
  8109. }
  8110. }
  8111. var canonicalizedObj = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
  8112. if ('[object Array]' === objectPrototypeToString.call(obj)) {
  8113. stack.push(obj);
  8114. canonicalizedObj = new Array(obj.length);
  8115. replacementStack.push(canonicalizedObj);
  8116. for (i = 0; i < obj.length; i += 1) {
  8117. canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack);
  8118. }
  8119. stack.pop();
  8120. replacementStack.pop();
  8121. return canonicalizedObj;
  8122. }
  8123. if (obj && obj.toJSON) {
  8124. obj = obj.toJSON();
  8125. }
  8126. if ( /*istanbul ignore start*/(typeof /*istanbul ignore end*/obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && obj !== null) {
  8127. stack.push(obj);
  8128. canonicalizedObj = {};
  8129. replacementStack.push(canonicalizedObj);
  8130. var sortedKeys = [],
  8131. key = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
  8132. for (key in obj) {
  8133. /* istanbul ignore else */
  8134. if (obj.hasOwnProperty(key)) {
  8135. sortedKeys.push(key);
  8136. }
  8137. }
  8138. sortedKeys.sort();
  8139. for (i = 0; i < sortedKeys.length; i += 1) {
  8140. key = sortedKeys[i];
  8141. canonicalizedObj[key] = canonicalize(obj[key], stack, replacementStack);
  8142. }
  8143. stack.pop();
  8144. replacementStack.pop();
  8145. } else {
  8146. canonicalizedObj = obj;
  8147. }
  8148. return canonicalizedObj;
  8149. }
  8150. },{"./base":49,"./line":53}],53:[function(require,module,exports){
  8151. /*istanbul ignore start*/'use strict';
  8152. exports.__esModule = true;
  8153. exports.lineDiff = undefined;
  8154. exports. /*istanbul ignore end*/diffLines = diffLines;
  8155. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffTrimmedLines = diffTrimmedLines;
  8156. var /*istanbul ignore start*/_base = require('./base') /*istanbul ignore end*/;
  8157. /*istanbul ignore start*/
  8158. var _base2 = _interopRequireDefault(_base);
  8159. /*istanbul ignore end*/
  8160. var /*istanbul ignore start*/_params = require('../util/params') /*istanbul ignore end*/;
  8161. /*istanbul ignore start*/
  8162. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  8163. /*istanbul ignore end*/var lineDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/lineDiff = new /*istanbul ignore start*/_base2['default']() /*istanbul ignore end*/;
  8164. lineDiff.tokenize = function (value) {
  8165. var retLines = [],
  8166. linesAndNewlines = value.split(/(\n|\r\n)/);
  8167. // Ignore the final empty token that occurs if the string ends with a new line
  8168. if (!linesAndNewlines[linesAndNewlines.length - 1]) {
  8169. linesAndNewlines.pop();
  8170. }
  8171. // Merge the content and line separators into single tokens
  8172. for (var i = 0; i < linesAndNewlines.length; i++) {
  8173. var line = linesAndNewlines[i];
  8174. if (i % 2 && !this.options.newlineIsToken) {
  8175. retLines[retLines.length - 1] += line;
  8176. } else {
  8177. if (this.options.ignoreWhitespace) {
  8178. line = line.trim();
  8179. }
  8180. retLines.push(line);
  8181. }
  8182. }
  8183. return retLines;
  8184. };
  8185. function diffLines(oldStr, newStr, callback) {
  8186. return lineDiff.diff(oldStr, newStr, callback);
  8187. }
  8188. function diffTrimmedLines(oldStr, newStr, callback) {
  8189. var options = /*istanbul ignore start*/(0, _params.generateOptions) /*istanbul ignore end*/(callback, { ignoreWhitespace: true });
  8190. return lineDiff.diff(oldStr, newStr, options);
  8191. }
  8192. },{"../util/params":61,"./base":49}],54:[function(require,module,exports){
  8193. /*istanbul ignore start*/'use strict';
  8194. exports.__esModule = true;
  8195. exports.sentenceDiff = undefined;
  8196. exports. /*istanbul ignore end*/diffSentences = diffSentences;
  8197. var /*istanbul ignore start*/_base = require('./base') /*istanbul ignore end*/;
  8198. /*istanbul ignore start*/
  8199. var _base2 = _interopRequireDefault(_base);
  8200. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  8201. /*istanbul ignore end*/var sentenceDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/sentenceDiff = new /*istanbul ignore start*/_base2['default']() /*istanbul ignore end*/;
  8202. sentenceDiff.tokenize = function (value) {
  8203. return value.split(/(\S.+?[.!?])(?=\s+|$)/);
  8204. };
  8205. function diffSentences(oldStr, newStr, callback) {
  8206. return sentenceDiff.diff(oldStr, newStr, callback);
  8207. }
  8208. },{"./base":49}],55:[function(require,module,exports){
  8209. /*istanbul ignore start*/'use strict';
  8210. exports.__esModule = true;
  8211. exports.wordDiff = undefined;
  8212. exports. /*istanbul ignore end*/diffWords = diffWords;
  8213. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffWordsWithSpace = diffWordsWithSpace;
  8214. var /*istanbul ignore start*/_base = require('./base') /*istanbul ignore end*/;
  8215. /*istanbul ignore start*/
  8216. var _base2 = _interopRequireDefault(_base);
  8217. /*istanbul ignore end*/
  8218. var /*istanbul ignore start*/_params = require('../util/params') /*istanbul ignore end*/;
  8219. /*istanbul ignore start*/
  8220. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  8221. /*istanbul ignore end*/
  8222. // Based on https://en.wikipedia.org/wiki/Latin_script_in_Unicode
  8223. //
  8224. // Ranges and exceptions:
  8225. // Latin-1 Supplement, 0080–00FF
  8226. // - U+00D7 × Multiplication sign
  8227. // - U+00F7 ÷ Division sign
  8228. // Latin Extended-A, 0100–017F
  8229. // Latin Extended-B, 0180–024F
  8230. // IPA Extensions, 0250–02AF
  8231. // Spacing Modifier Letters, 02B0–02FF
  8232. // - U+02C7 ˇ &#711; Caron
  8233. // - U+02D8 ˘ &#728; Breve
  8234. // - U+02D9 ˙ &#729; Dot Above
  8235. // - U+02DA ˚ &#730; Ring Above
  8236. // - U+02DB ˛ &#731; Ogonek
  8237. // - U+02DC ˜ &#732; Small Tilde
  8238. // - U+02DD ˝ &#733; Double Acute Accent
  8239. // Latin Extended Additional, 1E00–1EFF
  8240. var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
  8241. var reWhitespace = /\S/;
  8242. var wordDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/wordDiff = new /*istanbul ignore start*/_base2['default']() /*istanbul ignore end*/;
  8243. wordDiff.equals = function (left, right) {
  8244. return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
  8245. };
  8246. wordDiff.tokenize = function (value) {
  8247. var tokens = value.split(/(\s+|\b)/);
  8248. // Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
  8249. for (var i = 0; i < tokens.length - 1; i++) {
  8250. // If we have an empty string in the next field and we have only word chars before and after, merge
  8251. if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
  8252. tokens[i] += tokens[i + 2];
  8253. tokens.splice(i + 1, 2);
  8254. i--;
  8255. }
  8256. }
  8257. return tokens;
  8258. };
  8259. function diffWords(oldStr, newStr, callback) {
  8260. var options = /*istanbul ignore start*/(0, _params.generateOptions) /*istanbul ignore end*/(callback, { ignoreWhitespace: true });
  8261. return wordDiff.diff(oldStr, newStr, options);
  8262. }
  8263. function diffWordsWithSpace(oldStr, newStr, callback) {
  8264. return wordDiff.diff(oldStr, newStr, callback);
  8265. }
  8266. },{"../util/params":61,"./base":49}],56:[function(require,module,exports){
  8267. /*istanbul ignore start*/'use strict';
  8268. exports.__esModule = true;
  8269. exports.canonicalize = exports.convertChangesToXML = exports.convertChangesToDMP = exports.parsePatch = exports.applyPatches = exports.applyPatch = exports.createPatch = exports.createTwoFilesPatch = exports.structuredPatch = exports.diffArrays = exports.diffJson = exports.diffCss = exports.diffSentences = exports.diffTrimmedLines = exports.diffLines = exports.diffWordsWithSpace = exports.diffWords = exports.diffChars = exports.Diff = undefined;
  8270. /*istanbul ignore end*/
  8271. var /*istanbul ignore start*/_base = require('./diff/base') /*istanbul ignore end*/;
  8272. /*istanbul ignore start*/
  8273. var _base2 = _interopRequireDefault(_base);
  8274. /*istanbul ignore end*/
  8275. var /*istanbul ignore start*/_character = require('./diff/character') /*istanbul ignore end*/;
  8276. var /*istanbul ignore start*/_word = require('./diff/word') /*istanbul ignore end*/;
  8277. var /*istanbul ignore start*/_line = require('./diff/line') /*istanbul ignore end*/;
  8278. var /*istanbul ignore start*/_sentence = require('./diff/sentence') /*istanbul ignore end*/;
  8279. var /*istanbul ignore start*/_css = require('./diff/css') /*istanbul ignore end*/;
  8280. var /*istanbul ignore start*/_json = require('./diff/json') /*istanbul ignore end*/;
  8281. var /*istanbul ignore start*/_array = require('./diff/array') /*istanbul ignore end*/;
  8282. var /*istanbul ignore start*/_apply = require('./patch/apply') /*istanbul ignore end*/;
  8283. var /*istanbul ignore start*/_parse = require('./patch/parse') /*istanbul ignore end*/;
  8284. var /*istanbul ignore start*/_create = require('./patch/create') /*istanbul ignore end*/;
  8285. var /*istanbul ignore start*/_dmp = require('./convert/dmp') /*istanbul ignore end*/;
  8286. var /*istanbul ignore start*/_xml = require('./convert/xml') /*istanbul ignore end*/;
  8287. /*istanbul ignore start*/
  8288. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  8289. exports. /*istanbul ignore end*/Diff = _base2['default'];
  8290. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffChars = _character.diffChars;
  8291. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffWords = _word.diffWords;
  8292. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffWordsWithSpace = _word.diffWordsWithSpace;
  8293. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffLines = _line.diffLines;
  8294. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffTrimmedLines = _line.diffTrimmedLines;
  8295. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffSentences = _sentence.diffSentences;
  8296. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffCss = _css.diffCss;
  8297. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffJson = _json.diffJson;
  8298. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffArrays = _array.diffArrays;
  8299. /*istanbul ignore start*/exports. /*istanbul ignore end*/structuredPatch = _create.structuredPatch;
  8300. /*istanbul ignore start*/exports. /*istanbul ignore end*/createTwoFilesPatch = _create.createTwoFilesPatch;
  8301. /*istanbul ignore start*/exports. /*istanbul ignore end*/createPatch = _create.createPatch;
  8302. /*istanbul ignore start*/exports. /*istanbul ignore end*/applyPatch = _apply.applyPatch;
  8303. /*istanbul ignore start*/exports. /*istanbul ignore end*/applyPatches = _apply.applyPatches;
  8304. /*istanbul ignore start*/exports. /*istanbul ignore end*/parsePatch = _parse.parsePatch;
  8305. /*istanbul ignore start*/exports. /*istanbul ignore end*/convertChangesToDMP = _dmp.convertChangesToDMP;
  8306. /*istanbul ignore start*/exports. /*istanbul ignore end*/convertChangesToXML = _xml.convertChangesToXML;
  8307. /*istanbul ignore start*/exports. /*istanbul ignore end*/canonicalize = _json.canonicalize; /* See LICENSE file for terms of use */
  8308. /*
  8309. * Text diff implementation.
  8310. *
  8311. * This library supports the following APIS:
  8312. * JsDiff.diffChars: Character by character diff
  8313. * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace
  8314. * JsDiff.diffLines: Line based diff
  8315. *
  8316. * JsDiff.diffCss: Diff targeted at CSS content
  8317. *
  8318. * These methods are based on the implementation proposed in
  8319. * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).
  8320. * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927
  8321. */
  8322. },{"./convert/dmp":46,"./convert/xml":47,"./diff/array":48,"./diff/base":49,"./diff/character":50,"./diff/css":51,"./diff/json":52,"./diff/line":53,"./diff/sentence":54,"./diff/word":55,"./patch/apply":57,"./patch/create":58,"./patch/parse":59}],57:[function(require,module,exports){
  8323. /*istanbul ignore start*/'use strict';
  8324. exports.__esModule = true;
  8325. exports. /*istanbul ignore end*/applyPatch = applyPatch;
  8326. /*istanbul ignore start*/exports. /*istanbul ignore end*/applyPatches = applyPatches;
  8327. var /*istanbul ignore start*/_parse = require('./parse') /*istanbul ignore end*/;
  8328. var /*istanbul ignore start*/_distanceIterator = require('../util/distance-iterator') /*istanbul ignore end*/;
  8329. /*istanbul ignore start*/
  8330. var _distanceIterator2 = _interopRequireDefault(_distanceIterator);
  8331. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  8332. /*istanbul ignore end*/function applyPatch(source, uniDiff) {
  8333. /*istanbul ignore start*/var /*istanbul ignore end*/options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  8334. if (typeof uniDiff === 'string') {
  8335. uniDiff = /*istanbul ignore start*/(0, _parse.parsePatch) /*istanbul ignore end*/(uniDiff);
  8336. }
  8337. if (Array.isArray(uniDiff)) {
  8338. if (uniDiff.length > 1) {
  8339. throw new Error('applyPatch only works with a single input.');
  8340. }
  8341. uniDiff = uniDiff[0];
  8342. }
  8343. // Apply the diff to the input
  8344. var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
  8345. delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  8346. hunks = uniDiff.hunks,
  8347. compareLine = options.compareLine || function (lineNumber, line, operation, patchContent) /*istanbul ignore start*/{
  8348. return (/*istanbul ignore end*/line === patchContent
  8349. );
  8350. },
  8351. errorCount = 0,
  8352. fuzzFactor = options.fuzzFactor || 0,
  8353. minLine = 0,
  8354. offset = 0,
  8355. removeEOFNL = /*istanbul ignore start*/void 0 /*istanbul ignore end*/,
  8356. addEOFNL = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
  8357. /**
  8358. * Checks if the hunk exactly fits on the provided location
  8359. */
  8360. function hunkFits(hunk, toPos) {
  8361. for (var j = 0; j < hunk.lines.length; j++) {
  8362. var line = hunk.lines[j],
  8363. operation = line[0],
  8364. content = line.substr(1);
  8365. if (operation === ' ' || operation === '-') {
  8366. // Context sanity check
  8367. if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
  8368. errorCount++;
  8369. if (errorCount > fuzzFactor) {
  8370. return false;
  8371. }
  8372. }
  8373. toPos++;
  8374. }
  8375. }
  8376. return true;
  8377. }
  8378. // Search best fit offsets for each hunk based on the previous ones
  8379. for (var i = 0; i < hunks.length; i++) {
  8380. var hunk = hunks[i],
  8381. maxLine = lines.length - hunk.oldLines,
  8382. localOffset = 0,
  8383. toPos = offset + hunk.oldStart - 1;
  8384. var iterator = /*istanbul ignore start*/(0, _distanceIterator2['default']) /*istanbul ignore end*/(toPos, minLine, maxLine);
  8385. for (; localOffset !== undefined; localOffset = iterator()) {
  8386. if (hunkFits(hunk, toPos + localOffset)) {
  8387. hunk.offset = offset += localOffset;
  8388. break;
  8389. }
  8390. }
  8391. if (localOffset === undefined) {
  8392. return false;
  8393. }
  8394. // Set lower text limit to end of the current hunk, so next ones don't try
  8395. // to fit over already patched text
  8396. minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
  8397. }
  8398. // Apply patch hunks
  8399. for (var _i = 0; _i < hunks.length; _i++) {
  8400. var _hunk = hunks[_i],
  8401. _toPos = _hunk.offset + _hunk.newStart - 1;
  8402. if (_hunk.newLines == 0) {
  8403. _toPos++;
  8404. }
  8405. for (var j = 0; j < _hunk.lines.length; j++) {
  8406. var line = _hunk.lines[j],
  8407. operation = line[0],
  8408. content = line.substr(1),
  8409. delimiter = _hunk.linedelimiters[j];
  8410. if (operation === ' ') {
  8411. _toPos++;
  8412. } else if (operation === '-') {
  8413. lines.splice(_toPos, 1);
  8414. delimiters.splice(_toPos, 1);
  8415. /* istanbul ignore else */
  8416. } else if (operation === '+') {
  8417. lines.splice(_toPos, 0, content);
  8418. delimiters.splice(_toPos, 0, delimiter);
  8419. _toPos++;
  8420. } else if (operation === '\\') {
  8421. var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
  8422. if (previousOperation === '+') {
  8423. removeEOFNL = true;
  8424. } else if (previousOperation === '-') {
  8425. addEOFNL = true;
  8426. }
  8427. }
  8428. }
  8429. }
  8430. // Handle EOFNL insertion/removal
  8431. if (removeEOFNL) {
  8432. while (!lines[lines.length - 1]) {
  8433. lines.pop();
  8434. delimiters.pop();
  8435. }
  8436. } else if (addEOFNL) {
  8437. lines.push('');
  8438. delimiters.push('\n');
  8439. }
  8440. for (var _k = 0; _k < lines.length - 1; _k++) {
  8441. lines[_k] = lines[_k] + delimiters[_k];
  8442. }
  8443. return lines.join('');
  8444. }
  8445. // Wrapper that supports multiple file patches via callbacks.
  8446. function applyPatches(uniDiff, options) {
  8447. if (typeof uniDiff === 'string') {
  8448. uniDiff = /*istanbul ignore start*/(0, _parse.parsePatch) /*istanbul ignore end*/(uniDiff);
  8449. }
  8450. var currentIndex = 0;
  8451. function processIndex() {
  8452. var index = uniDiff[currentIndex++];
  8453. if (!index) {
  8454. return options.complete();
  8455. }
  8456. options.loadFile(index, function (err, data) {
  8457. if (err) {
  8458. return options.complete(err);
  8459. }
  8460. var updatedContent = applyPatch(data, index, options);
  8461. options.patched(index, updatedContent, function (err) {
  8462. if (err) {
  8463. return options.complete(err);
  8464. }
  8465. processIndex();
  8466. });
  8467. });
  8468. }
  8469. processIndex();
  8470. }
  8471. },{"../util/distance-iterator":60,"./parse":59}],58:[function(require,module,exports){
  8472. /*istanbul ignore start*/'use strict';
  8473. exports.__esModule = true;
  8474. exports. /*istanbul ignore end*/structuredPatch = structuredPatch;
  8475. /*istanbul ignore start*/exports. /*istanbul ignore end*/createTwoFilesPatch = createTwoFilesPatch;
  8476. /*istanbul ignore start*/exports. /*istanbul ignore end*/createPatch = createPatch;
  8477. var /*istanbul ignore start*/_line = require('../diff/line') /*istanbul ignore end*/;
  8478. /*istanbul ignore start*/
  8479. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  8480. /*istanbul ignore end*/function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  8481. if (!options) {
  8482. options = {};
  8483. }
  8484. if (typeof options.context === 'undefined') {
  8485. options.context = 4;
  8486. }
  8487. var diff = /*istanbul ignore start*/(0, _line.diffLines) /*istanbul ignore end*/(oldStr, newStr, options);
  8488. diff.push({ value: '', lines: [] }); // Append an empty value to make cleanup easier
  8489. function contextLines(lines) {
  8490. return lines.map(function (entry) {
  8491. return ' ' + entry;
  8492. });
  8493. }
  8494. var hunks = [];
  8495. var oldRangeStart = 0,
  8496. newRangeStart = 0,
  8497. curRange = [],
  8498. oldLine = 1,
  8499. newLine = 1;
  8500. /*istanbul ignore start*/
  8501. var _loop = function _loop( /*istanbul ignore end*/i) {
  8502. var current = diff[i],
  8503. lines = current.lines || current.value.replace(/\n$/, '').split('\n');
  8504. current.lines = lines;
  8505. if (current.added || current.removed) {
  8506. /*istanbul ignore start*/
  8507. var _curRange;
  8508. /*istanbul ignore end*/
  8509. // If we have previous context, start with that
  8510. if (!oldRangeStart) {
  8511. var prev = diff[i - 1];
  8512. oldRangeStart = oldLine;
  8513. newRangeStart = newLine;
  8514. if (prev) {
  8515. curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
  8516. oldRangeStart -= curRange.length;
  8517. newRangeStart -= curRange.length;
  8518. }
  8519. }
  8520. // Output our changes
  8521. /*istanbul ignore start*/(_curRange = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/lines.map(function (entry) {
  8522. return (current.added ? '+' : '-') + entry;
  8523. })));
  8524. // Track the updated file position
  8525. if (current.added) {
  8526. newLine += lines.length;
  8527. } else {
  8528. oldLine += lines.length;
  8529. }
  8530. } else {
  8531. // Identical context lines. Track line changes
  8532. if (oldRangeStart) {
  8533. // Close out any changes that have been output (or join overlapping)
  8534. if (lines.length <= options.context * 2 && i < diff.length - 2) {
  8535. /*istanbul ignore start*/
  8536. var _curRange2;
  8537. /*istanbul ignore end*/
  8538. // Overlapping
  8539. /*istanbul ignore start*/(_curRange2 = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange2 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/contextLines(lines)));
  8540. } else {
  8541. /*istanbul ignore start*/
  8542. var _curRange3;
  8543. /*istanbul ignore end*/
  8544. // end the range and output
  8545. var contextSize = Math.min(lines.length, options.context);
  8546. /*istanbul ignore start*/(_curRange3 = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange3 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/contextLines(lines.slice(0, contextSize))));
  8547. var hunk = {
  8548. oldStart: oldRangeStart,
  8549. oldLines: oldLine - oldRangeStart + contextSize,
  8550. newStart: newRangeStart,
  8551. newLines: newLine - newRangeStart + contextSize,
  8552. lines: curRange
  8553. };
  8554. if (i >= diff.length - 2 && lines.length <= options.context) {
  8555. // EOF is inside this hunk
  8556. var oldEOFNewline = /\n$/.test(oldStr);
  8557. var newEOFNewline = /\n$/.test(newStr);
  8558. if (lines.length == 0 && !oldEOFNewline) {
  8559. // special case: old has no eol and no trailing context; no-nl can end up before adds
  8560. curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
  8561. } else if (!oldEOFNewline || !newEOFNewline) {
  8562. curRange.push('\\ No newline at end of file');
  8563. }
  8564. }
  8565. hunks.push(hunk);
  8566. oldRangeStart = 0;
  8567. newRangeStart = 0;
  8568. curRange = [];
  8569. }
  8570. }
  8571. oldLine += lines.length;
  8572. newLine += lines.length;
  8573. }
  8574. };
  8575. for (var i = 0; i < diff.length; i++) {
  8576. /*istanbul ignore start*/
  8577. _loop( /*istanbul ignore end*/i);
  8578. }
  8579. return {
  8580. oldFileName: oldFileName, newFileName: newFileName,
  8581. oldHeader: oldHeader, newHeader: newHeader,
  8582. hunks: hunks
  8583. };
  8584. }
  8585. function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  8586. var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
  8587. var ret = [];
  8588. if (oldFileName == newFileName) {
  8589. ret.push('Index: ' + oldFileName);
  8590. }
  8591. ret.push('===================================================================');
  8592. ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
  8593. ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
  8594. for (var i = 0; i < diff.hunks.length; i++) {
  8595. var hunk = diff.hunks[i];
  8596. ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
  8597. ret.push.apply(ret, hunk.lines);
  8598. }
  8599. return ret.join('\n') + '\n';
  8600. }
  8601. function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
  8602. return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
  8603. }
  8604. },{"../diff/line":53}],59:[function(require,module,exports){
  8605. /*istanbul ignore start*/'use strict';
  8606. exports.__esModule = true;
  8607. exports. /*istanbul ignore end*/parsePatch = parsePatch;
  8608. function parsePatch(uniDiff) {
  8609. /*istanbul ignore start*/var /*istanbul ignore end*/options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  8610. var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
  8611. delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  8612. list = [],
  8613. i = 0;
  8614. function parseIndex() {
  8615. var index = {};
  8616. list.push(index);
  8617. // Parse diff metadata
  8618. while (i < diffstr.length) {
  8619. var line = diffstr[i];
  8620. // File header found, end parsing diff metadata
  8621. if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
  8622. break;
  8623. }
  8624. // Diff index
  8625. var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
  8626. if (header) {
  8627. index.index = header[1];
  8628. }
  8629. i++;
  8630. }
  8631. // Parse file headers if they are defined. Unified diff requires them, but
  8632. // there's no technical issues to have an isolated hunk without file header
  8633. parseFileHeader(index);
  8634. parseFileHeader(index);
  8635. // Parse hunks
  8636. index.hunks = [];
  8637. while (i < diffstr.length) {
  8638. var _line = diffstr[i];
  8639. if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
  8640. break;
  8641. } else if (/^@@/.test(_line)) {
  8642. index.hunks.push(parseHunk());
  8643. } else if (_line && options.strict) {
  8644. // Ignore unexpected content unless in strict mode
  8645. throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
  8646. } else {
  8647. i++;
  8648. }
  8649. }
  8650. }
  8651. // Parses the --- and +++ headers, if none are found, no lines
  8652. // are consumed.
  8653. function parseFileHeader(index) {
  8654. var headerPattern = /^(---|\+\+\+)\s+([\S ]*)(?:\t(.*?)\s*)?$/;
  8655. var fileHeader = headerPattern.exec(diffstr[i]);
  8656. if (fileHeader) {
  8657. var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
  8658. index[keyPrefix + 'FileName'] = fileHeader[2];
  8659. index[keyPrefix + 'Header'] = fileHeader[3];
  8660. i++;
  8661. }
  8662. }
  8663. // Parses a hunk
  8664. // This assumes that we are at the start of a hunk.
  8665. function parseHunk() {
  8666. var chunkHeaderIndex = i,
  8667. chunkHeaderLine = diffstr[i++],
  8668. chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
  8669. var hunk = {
  8670. oldStart: +chunkHeader[1],
  8671. oldLines: +chunkHeader[2] || 1,
  8672. newStart: +chunkHeader[3],
  8673. newLines: +chunkHeader[4] || 1,
  8674. lines: [],
  8675. linedelimiters: []
  8676. };
  8677. var addCount = 0,
  8678. removeCount = 0;
  8679. for (; i < diffstr.length; i++) {
  8680. // Lines starting with '---' could be mistaken for the "remove line" operation
  8681. // But they could be the header for the next file. Therefore prune such cases out.
  8682. if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
  8683. break;
  8684. }
  8685. var operation = diffstr[i][0];
  8686. if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
  8687. hunk.lines.push(diffstr[i]);
  8688. hunk.linedelimiters.push(delimiters[i] || '\n');
  8689. if (operation === '+') {
  8690. addCount++;
  8691. } else if (operation === '-') {
  8692. removeCount++;
  8693. } else if (operation === ' ') {
  8694. addCount++;
  8695. removeCount++;
  8696. }
  8697. } else {
  8698. break;
  8699. }
  8700. }
  8701. // Handle the empty block count case
  8702. if (!addCount && hunk.newLines === 1) {
  8703. hunk.newLines = 0;
  8704. }
  8705. if (!removeCount && hunk.oldLines === 1) {
  8706. hunk.oldLines = 0;
  8707. }
  8708. // Perform optional sanity checking
  8709. if (options.strict) {
  8710. if (addCount !== hunk.newLines) {
  8711. throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  8712. }
  8713. if (removeCount !== hunk.oldLines) {
  8714. throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  8715. }
  8716. }
  8717. return hunk;
  8718. }
  8719. while (i < diffstr.length) {
  8720. parseIndex();
  8721. }
  8722. return list;
  8723. }
  8724. },{}],60:[function(require,module,exports){
  8725. /*istanbul ignore start*/"use strict";
  8726. exports.__esModule = true;
  8727. exports["default"] = /*istanbul ignore end*/function (start, minLine, maxLine) {
  8728. var wantForward = true,
  8729. backwardExhausted = false,
  8730. forwardExhausted = false,
  8731. localOffset = 1;
  8732. return function iterator() {
  8733. if (wantForward && !forwardExhausted) {
  8734. if (backwardExhausted) {
  8735. localOffset++;
  8736. } else {
  8737. wantForward = false;
  8738. }
  8739. // Check if trying to fit beyond text length, and if not, check it fits
  8740. // after offset location (or desired location on first iteration)
  8741. if (start + localOffset <= maxLine) {
  8742. return localOffset;
  8743. }
  8744. forwardExhausted = true;
  8745. }
  8746. if (!backwardExhausted) {
  8747. if (!forwardExhausted) {
  8748. wantForward = true;
  8749. }
  8750. // Check if trying to fit before text beginning, and if not, check it fits
  8751. // before offset location
  8752. if (minLine <= start - localOffset) {
  8753. return -localOffset++;
  8754. }
  8755. backwardExhausted = true;
  8756. return iterator();
  8757. }
  8758. // We tried to fit hunk before text beginning and beyond text lenght, then
  8759. // hunk can't fit on the text. Return undefined
  8760. };
  8761. };
  8762. },{}],61:[function(require,module,exports){
  8763. /*istanbul ignore start*/'use strict';
  8764. exports.__esModule = true;
  8765. exports. /*istanbul ignore end*/generateOptions = generateOptions;
  8766. function generateOptions(options, defaults) {
  8767. if (typeof options === 'function') {
  8768. defaults.callback = options;
  8769. } else if (options) {
  8770. for (var name in options) {
  8771. /* istanbul ignore else */
  8772. if (options.hasOwnProperty(name)) {
  8773. defaults[name] = options[name];
  8774. }
  8775. }
  8776. }
  8777. return defaults;
  8778. }
  8779. },{}],62:[function(require,module,exports){
  8780. 'use strict';
  8781. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  8782. module.exports = function (str) {
  8783. if (typeof str !== 'string') {
  8784. throw new TypeError('Expected a string');
  8785. }
  8786. return str.replace(matchOperatorsRe, '\\$&');
  8787. };
  8788. },{}],63:[function(require,module,exports){
  8789. // Copyright Joyent, Inc. and other Node contributors.
  8790. //
  8791. // Permission is hereby granted, free of charge, to any person obtaining a
  8792. // copy of this software and associated documentation files (the
  8793. // "Software"), to deal in the Software without restriction, including
  8794. // without limitation the rights to use, copy, modify, merge, publish,
  8795. // distribute, sublicense, and/or sell copies of the Software, and to permit
  8796. // persons to whom the Software is furnished to do so, subject to the
  8797. // following conditions:
  8798. //
  8799. // The above copyright notice and this permission notice shall be included
  8800. // in all copies or substantial portions of the Software.
  8801. //
  8802. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  8803. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  8804. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  8805. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  8806. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  8807. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  8808. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  8809. function EventEmitter() {
  8810. this._events = this._events || {};
  8811. this._maxListeners = this._maxListeners || undefined;
  8812. }
  8813. module.exports = EventEmitter;
  8814. // Backwards-compat with node 0.10.x
  8815. EventEmitter.EventEmitter = EventEmitter;
  8816. EventEmitter.prototype._events = undefined;
  8817. EventEmitter.prototype._maxListeners = undefined;
  8818. // By default EventEmitters will print a warning if more than 10 listeners are
  8819. // added to it. This is a useful default which helps finding memory leaks.
  8820. EventEmitter.defaultMaxListeners = 10;
  8821. // Obviously not all Emitters should be limited to 10. This function allows
  8822. // that to be increased. Set to zero for unlimited.
  8823. EventEmitter.prototype.setMaxListeners = function(n) {
  8824. if (!isNumber(n) || n < 0 || isNaN(n))
  8825. throw TypeError('n must be a positive number');
  8826. this._maxListeners = n;
  8827. return this;
  8828. };
  8829. EventEmitter.prototype.emit = function(type) {
  8830. var er, handler, len, args, i, listeners;
  8831. if (!this._events)
  8832. this._events = {};
  8833. // If there is no 'error' event listener then throw.
  8834. if (type === 'error') {
  8835. if (!this._events.error ||
  8836. (isObject(this._events.error) && !this._events.error.length)) {
  8837. er = arguments[1];
  8838. if (er instanceof Error) {
  8839. throw er; // Unhandled 'error' event
  8840. } else {
  8841. // At least give some kind of context to the user
  8842. var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
  8843. err.context = er;
  8844. throw err;
  8845. }
  8846. }
  8847. }
  8848. handler = this._events[type];
  8849. if (isUndefined(handler))
  8850. return false;
  8851. if (isFunction(handler)) {
  8852. switch (arguments.length) {
  8853. // fast cases
  8854. case 1:
  8855. handler.call(this);
  8856. break;
  8857. case 2:
  8858. handler.call(this, arguments[1]);
  8859. break;
  8860. case 3:
  8861. handler.call(this, arguments[1], arguments[2]);
  8862. break;
  8863. // slower
  8864. default:
  8865. args = Array.prototype.slice.call(arguments, 1);
  8866. handler.apply(this, args);
  8867. }
  8868. } else if (isObject(handler)) {
  8869. args = Array.prototype.slice.call(arguments, 1);
  8870. listeners = handler.slice();
  8871. len = listeners.length;
  8872. for (i = 0; i < len; i++)
  8873. listeners[i].apply(this, args);
  8874. }
  8875. return true;
  8876. };
  8877. EventEmitter.prototype.addListener = function(type, listener) {
  8878. var m;
  8879. if (!isFunction(listener))
  8880. throw TypeError('listener must be a function');
  8881. if (!this._events)
  8882. this._events = {};
  8883. // To avoid recursion in the case that type === "newListener"! Before
  8884. // adding it to the listeners, first emit "newListener".
  8885. if (this._events.newListener)
  8886. this.emit('newListener', type,
  8887. isFunction(listener.listener) ?
  8888. listener.listener : listener);
  8889. if (!this._events[type])
  8890. // Optimize the case of one listener. Don't need the extra array object.
  8891. this._events[type] = listener;
  8892. else if (isObject(this._events[type]))
  8893. // If we've already got an array, just append.
  8894. this._events[type].push(listener);
  8895. else
  8896. // Adding the second element, need to change to array.
  8897. this._events[type] = [this._events[type], listener];
  8898. // Check for listener leak
  8899. if (isObject(this._events[type]) && !this._events[type].warned) {
  8900. if (!isUndefined(this._maxListeners)) {
  8901. m = this._maxListeners;
  8902. } else {
  8903. m = EventEmitter.defaultMaxListeners;
  8904. }
  8905. if (m && m > 0 && this._events[type].length > m) {
  8906. this._events[type].warned = true;
  8907. console.error('(node) warning: possible EventEmitter memory ' +
  8908. 'leak detected. %d listeners added. ' +
  8909. 'Use emitter.setMaxListeners() to increase limit.',
  8910. this._events[type].length);
  8911. if (typeof console.trace === 'function') {
  8912. // not supported in IE 10
  8913. console.trace();
  8914. }
  8915. }
  8916. }
  8917. return this;
  8918. };
  8919. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  8920. EventEmitter.prototype.once = function(type, listener) {
  8921. if (!isFunction(listener))
  8922. throw TypeError('listener must be a function');
  8923. var fired = false;
  8924. function g() {
  8925. this.removeListener(type, g);
  8926. if (!fired) {
  8927. fired = true;
  8928. listener.apply(this, arguments);
  8929. }
  8930. }
  8931. g.listener = listener;
  8932. this.on(type, g);
  8933. return this;
  8934. };
  8935. // emits a 'removeListener' event iff the listener was removed
  8936. EventEmitter.prototype.removeListener = function(type, listener) {
  8937. var list, position, length, i;
  8938. if (!isFunction(listener))
  8939. throw TypeError('listener must be a function');
  8940. if (!this._events || !this._events[type])
  8941. return this;
  8942. list = this._events[type];
  8943. length = list.length;
  8944. position = -1;
  8945. if (list === listener ||
  8946. (isFunction(list.listener) && list.listener === listener)) {
  8947. delete this._events[type];
  8948. if (this._events.removeListener)
  8949. this.emit('removeListener', type, listener);
  8950. } else if (isObject(list)) {
  8951. for (i = length; i-- > 0;) {
  8952. if (list[i] === listener ||
  8953. (list[i].listener && list[i].listener === listener)) {
  8954. position = i;
  8955. break;
  8956. }
  8957. }
  8958. if (position < 0)
  8959. return this;
  8960. if (list.length === 1) {
  8961. list.length = 0;
  8962. delete this._events[type];
  8963. } else {
  8964. list.splice(position, 1);
  8965. }
  8966. if (this._events.removeListener)
  8967. this.emit('removeListener', type, listener);
  8968. }
  8969. return this;
  8970. };
  8971. EventEmitter.prototype.removeAllListeners = function(type) {
  8972. var key, listeners;
  8973. if (!this._events)
  8974. return this;
  8975. // not listening for removeListener, no need to emit
  8976. if (!this._events.removeListener) {
  8977. if (arguments.length === 0)
  8978. this._events = {};
  8979. else if (this._events[type])
  8980. delete this._events[type];
  8981. return this;
  8982. }
  8983. // emit removeListener for all listeners on all events
  8984. if (arguments.length === 0) {
  8985. for (key in this._events) {
  8986. if (key === 'removeListener') continue;
  8987. this.removeAllListeners(key);
  8988. }
  8989. this.removeAllListeners('removeListener');
  8990. this._events = {};
  8991. return this;
  8992. }
  8993. listeners = this._events[type];
  8994. if (isFunction(listeners)) {
  8995. this.removeListener(type, listeners);
  8996. } else if (listeners) {
  8997. // LIFO order
  8998. while (listeners.length)
  8999. this.removeListener(type, listeners[listeners.length - 1]);
  9000. }
  9001. delete this._events[type];
  9002. return this;
  9003. };
  9004. EventEmitter.prototype.listeners = function(type) {
  9005. var ret;
  9006. if (!this._events || !this._events[type])
  9007. ret = [];
  9008. else if (isFunction(this._events[type]))
  9009. ret = [this._events[type]];
  9010. else
  9011. ret = this._events[type].slice();
  9012. return ret;
  9013. };
  9014. EventEmitter.prototype.listenerCount = function(type) {
  9015. if (this._events) {
  9016. var evlistener = this._events[type];
  9017. if (isFunction(evlistener))
  9018. return 1;
  9019. else if (evlistener)
  9020. return evlistener.length;
  9021. }
  9022. return 0;
  9023. };
  9024. EventEmitter.listenerCount = function(emitter, type) {
  9025. return emitter.listenerCount(type);
  9026. };
  9027. function isFunction(arg) {
  9028. return typeof arg === 'function';
  9029. }
  9030. function isNumber(arg) {
  9031. return typeof arg === 'number';
  9032. }
  9033. function isObject(arg) {
  9034. return typeof arg === 'object' && arg !== null;
  9035. }
  9036. function isUndefined(arg) {
  9037. return arg === void 0;
  9038. }
  9039. },{}],64:[function(require,module,exports){
  9040. (function (process){
  9041. // Growl - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
  9042. /**
  9043. * Module dependencies.
  9044. */
  9045. var exec = require('child_process').exec
  9046. , fs = require('fs')
  9047. , path = require('path')
  9048. , exists = fs.existsSync || path.existsSync
  9049. , os = require('os')
  9050. , quote = JSON.stringify
  9051. , cmd;
  9052. function which(name) {
  9053. var paths = process.env.PATH.split(':');
  9054. var loc;
  9055. for (var i = 0, len = paths.length; i < len; ++i) {
  9056. loc = path.join(paths[i], name);
  9057. if (exists(loc)) return loc;
  9058. }
  9059. }
  9060. switch(os.type()) {
  9061. case 'Darwin':
  9062. if (which('terminal-notifier')) {
  9063. cmd = {
  9064. type: "Darwin-NotificationCenter"
  9065. , pkg: "terminal-notifier"
  9066. , msg: '-message'
  9067. , title: '-title'
  9068. , subtitle: '-subtitle'
  9069. , icon: '-appIcon'
  9070. , sound: '-sound'
  9071. , url: '-open'
  9072. , priority: {
  9073. cmd: '-execute'
  9074. , range: []
  9075. }
  9076. };
  9077. } else {
  9078. cmd = {
  9079. type: "Darwin-Growl"
  9080. , pkg: "growlnotify"
  9081. , msg: '-m'
  9082. , sticky: '--sticky'
  9083. , priority: {
  9084. cmd: '--priority'
  9085. , range: [
  9086. -2
  9087. , -1
  9088. , 0
  9089. , 1
  9090. , 2
  9091. , "Very Low"
  9092. , "Moderate"
  9093. , "Normal"
  9094. , "High"
  9095. , "Emergency"
  9096. ]
  9097. }
  9098. };
  9099. }
  9100. break;
  9101. case 'Linux':
  9102. if (which('growl')) {
  9103. cmd = {
  9104. type: "Linux-Growl"
  9105. , pkg: "growl"
  9106. , msg: '-m'
  9107. , title: '-title'
  9108. , subtitle: '-subtitle'
  9109. , host: {
  9110. cmd: '-H'
  9111. , hostname: '192.168.33.1'
  9112. }
  9113. };
  9114. } else {
  9115. cmd = {
  9116. type: "Linux"
  9117. , pkg: "notify-send"
  9118. , msg: ''
  9119. , sticky: '-t 0'
  9120. , icon: '-i'
  9121. , priority: {
  9122. cmd: '-u'
  9123. , range: [
  9124. "low"
  9125. , "normal"
  9126. , "critical"
  9127. ]
  9128. }
  9129. };
  9130. }
  9131. break;
  9132. case 'Windows_NT':
  9133. cmd = {
  9134. type: "Windows"
  9135. , pkg: "growlnotify"
  9136. , msg: ''
  9137. , sticky: '/s:true'
  9138. , title: '/t:'
  9139. , icon: '/i:'
  9140. , url: '/cu:'
  9141. , priority: {
  9142. cmd: '/p:'
  9143. , range: [
  9144. -2
  9145. , -1
  9146. , 0
  9147. , 1
  9148. , 2
  9149. ]
  9150. }
  9151. };
  9152. break;
  9153. }
  9154. /**
  9155. * Expose `growl`.
  9156. */
  9157. exports = module.exports = growl;
  9158. /**
  9159. * Node-growl version.
  9160. */
  9161. exports.version = '1.4.1'
  9162. /**
  9163. * Send growl notification _msg_ with _options_.
  9164. *
  9165. * Options:
  9166. *
  9167. * - title Notification title
  9168. * - sticky Make the notification stick (defaults to false)
  9169. * - priority Specify an int or named key (default is 0)
  9170. * - name Application name (defaults to growlnotify)
  9171. * - sound Sound efect ( in OSx defined in preferences -> sound -> effects) * works only in OSX > 10.8x
  9172. * - image
  9173. * - path to an icon sets --iconpath
  9174. * - path to an image sets --image
  9175. * - capitalized word sets --appIcon
  9176. * - filename uses extname as --icon
  9177. * - otherwise treated as --icon
  9178. *
  9179. * Examples:
  9180. *
  9181. * growl('New email')
  9182. * growl('5 new emails', { title: 'Thunderbird' })
  9183. * growl('5 new emails', { title: 'Thunderbird', sound: 'Purr' })
  9184. * growl('Email sent', function(){
  9185. * // ... notification sent
  9186. * })
  9187. *
  9188. * @param {string} msg
  9189. * @param {object} options
  9190. * @param {function} fn
  9191. * @api public
  9192. */
  9193. function growl(msg, options, fn) {
  9194. var image
  9195. , args
  9196. , options = options || {}
  9197. , fn = fn || function(){};
  9198. if (options.exec) {
  9199. cmd = {
  9200. type: "Custom"
  9201. , pkg: options.exec
  9202. , range: []
  9203. };
  9204. }
  9205. // noop
  9206. if (!cmd) return fn(new Error('growl not supported on this platform'));
  9207. args = [cmd.pkg];
  9208. // image
  9209. if (image = options.image) {
  9210. switch(cmd.type) {
  9211. case 'Darwin-Growl':
  9212. var flag, ext = path.extname(image).substr(1)
  9213. flag = flag || ext == 'icns' && 'iconpath'
  9214. flag = flag || /^[A-Z]/.test(image) && 'appIcon'
  9215. flag = flag || /^png|gif|jpe?g$/.test(ext) && 'image'
  9216. flag = flag || ext && (image = ext) && 'icon'
  9217. flag = flag || 'icon'
  9218. args.push('--' + flag, quote(image))
  9219. break;
  9220. case 'Darwin-NotificationCenter':
  9221. args.push(cmd.icon, quote(image));
  9222. break;
  9223. case 'Linux':
  9224. args.push(cmd.icon, quote(image));
  9225. // libnotify defaults to sticky, set a hint for transient notifications
  9226. if (!options.sticky) args.push('--hint=int:transient:1');
  9227. break;
  9228. case 'Windows':
  9229. args.push(cmd.icon + quote(image));
  9230. break;
  9231. }
  9232. }
  9233. // sticky
  9234. if (options.sticky) args.push(cmd.sticky);
  9235. // priority
  9236. if (options.priority) {
  9237. var priority = options.priority + '';
  9238. var checkindexOf = cmd.priority.range.indexOf(priority);
  9239. if (~cmd.priority.range.indexOf(priority)) {
  9240. args.push(cmd.priority, options.priority);
  9241. }
  9242. }
  9243. //sound
  9244. if(options.sound && cmd.type === 'Darwin-NotificationCenter'){
  9245. args.push(cmd.sound, options.sound)
  9246. }
  9247. // name
  9248. if (options.name && cmd.type === "Darwin-Growl") {
  9249. args.push('--name', options.name);
  9250. }
  9251. switch(cmd.type) {
  9252. case 'Darwin-Growl':
  9253. args.push(cmd.msg);
  9254. args.push(quote(msg).replace(/\\n/g, '\n'));
  9255. if (options.title) args.push(quote(options.title));
  9256. break;
  9257. case 'Darwin-NotificationCenter':
  9258. args.push(cmd.msg);
  9259. var stringifiedMsg = quote(msg);
  9260. var escapedMsg = stringifiedMsg.replace(/\\n/g, '\n');
  9261. args.push(escapedMsg);
  9262. if (options.title) {
  9263. args.push(cmd.title);
  9264. args.push(quote(options.title));
  9265. }
  9266. if (options.subtitle) {
  9267. args.push(cmd.subtitle);
  9268. args.push(quote(options.subtitle));
  9269. }
  9270. if (options.url) {
  9271. args.push(cmd.url);
  9272. args.push(quote(options.url));
  9273. }
  9274. break;
  9275. case 'Linux-Growl':
  9276. args.push(cmd.msg);
  9277. args.push(quote(msg).replace(/\\n/g, '\n'));
  9278. if (options.title) args.push(quote(options.title));
  9279. if (cmd.host) {
  9280. args.push(cmd.host.cmd, cmd.host.hostname)
  9281. }
  9282. break;
  9283. case 'Linux':
  9284. if (options.title) {
  9285. args.push(quote(options.title));
  9286. args.push(cmd.msg);
  9287. args.push(quote(msg).replace(/\\n/g, '\n'));
  9288. } else {
  9289. args.push(quote(msg).replace(/\\n/g, '\n'));
  9290. }
  9291. break;
  9292. case 'Windows':
  9293. args.push(quote(msg).replace(/\\n/g, '\n'));
  9294. if (options.title) args.push(cmd.title + quote(options.title));
  9295. if (options.url) args.push(cmd.url + quote(options.url));
  9296. break;
  9297. case 'Custom':
  9298. args[0] = (function(origCommand) {
  9299. var message = options.title
  9300. ? options.title + ': ' + msg
  9301. : msg;
  9302. var command = origCommand.replace(/(^|[^%])%s/g, '$1' + quote(message));
  9303. if (command === origCommand) args.push(quote(message));
  9304. return command;
  9305. })(args[0]);
  9306. break;
  9307. }
  9308. // execute
  9309. exec(args.join(' '), fn);
  9310. };
  9311. }).call(this,require('_process'))
  9312. },{"_process":82,"child_process":42,"fs":42,"os":80,"path":42}],65:[function(require,module,exports){
  9313. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  9314. var e, m
  9315. var eLen = nBytes * 8 - mLen - 1
  9316. var eMax = (1 << eLen) - 1
  9317. var eBias = eMax >> 1
  9318. var nBits = -7
  9319. var i = isLE ? (nBytes - 1) : 0
  9320. var d = isLE ? -1 : 1
  9321. var s = buffer[offset + i]
  9322. i += d
  9323. e = s & ((1 << (-nBits)) - 1)
  9324. s >>= (-nBits)
  9325. nBits += eLen
  9326. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  9327. m = e & ((1 << (-nBits)) - 1)
  9328. e >>= (-nBits)
  9329. nBits += mLen
  9330. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  9331. if (e === 0) {
  9332. e = 1 - eBias
  9333. } else if (e === eMax) {
  9334. return m ? NaN : ((s ? -1 : 1) * Infinity)
  9335. } else {
  9336. m = m + Math.pow(2, mLen)
  9337. e = e - eBias
  9338. }
  9339. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  9340. }
  9341. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  9342. var e, m, c
  9343. var eLen = nBytes * 8 - mLen - 1
  9344. var eMax = (1 << eLen) - 1
  9345. var eBias = eMax >> 1
  9346. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  9347. var i = isLE ? 0 : (nBytes - 1)
  9348. var d = isLE ? 1 : -1
  9349. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  9350. value = Math.abs(value)
  9351. if (isNaN(value) || value === Infinity) {
  9352. m = isNaN(value) ? 1 : 0
  9353. e = eMax
  9354. } else {
  9355. e = Math.floor(Math.log(value) / Math.LN2)
  9356. if (value * (c = Math.pow(2, -e)) < 1) {
  9357. e--
  9358. c *= 2
  9359. }
  9360. if (e + eBias >= 1) {
  9361. value += rt / c
  9362. } else {
  9363. value += rt * Math.pow(2, 1 - eBias)
  9364. }
  9365. if (value * c >= 2) {
  9366. e++
  9367. c /= 2
  9368. }
  9369. if (e + eBias >= eMax) {
  9370. m = 0
  9371. e = eMax
  9372. } else if (e + eBias >= 1) {
  9373. m = (value * c - 1) * Math.pow(2, mLen)
  9374. e = e + eBias
  9375. } else {
  9376. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  9377. e = 0
  9378. }
  9379. }
  9380. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  9381. e = (e << mLen) | m
  9382. eLen += mLen
  9383. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  9384. buffer[offset + i - d] |= s * 128
  9385. }
  9386. },{}],66:[function(require,module,exports){
  9387. if (typeof Object.create === 'function') {
  9388. // implementation from standard node.js 'util' module
  9389. module.exports = function inherits(ctor, superCtor) {
  9390. ctor.super_ = superCtor
  9391. ctor.prototype = Object.create(superCtor.prototype, {
  9392. constructor: {
  9393. value: ctor,
  9394. enumerable: false,
  9395. writable: true,
  9396. configurable: true
  9397. }
  9398. });
  9399. };
  9400. } else {
  9401. // old school shim for old browsers
  9402. module.exports = function inherits(ctor, superCtor) {
  9403. ctor.super_ = superCtor
  9404. var TempCtor = function () {}
  9405. TempCtor.prototype = superCtor.prototype
  9406. ctor.prototype = new TempCtor()
  9407. ctor.prototype.constructor = ctor
  9408. }
  9409. }
  9410. },{}],67:[function(require,module,exports){
  9411. /*!
  9412. * Determine if an object is a Buffer
  9413. *
  9414. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  9415. * @license MIT
  9416. */
  9417. // The _isBuffer check is for Safari 5-7 support, because it's missing
  9418. // Object.prototype.constructor. Remove this eventually
  9419. module.exports = function (obj) {
  9420. return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
  9421. }
  9422. function isBuffer (obj) {
  9423. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  9424. }
  9425. // For Node v0.10 support. Remove this eventually.
  9426. function isSlowBuffer (obj) {
  9427. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
  9428. }
  9429. },{}],68:[function(require,module,exports){
  9430. var toString = {}.toString;
  9431. module.exports = Array.isArray || function (arr) {
  9432. return toString.call(arr) == '[object Array]';
  9433. };
  9434. },{}],69:[function(require,module,exports){
  9435. (function (global){
  9436. /*! JSON v3.3.2 | http://bestiejs.github.io/json3 | Copyright 2012-2014, Kit Cambridge | http://kit.mit-license.org */
  9437. ;(function () {
  9438. // Detect the `define` function exposed by asynchronous module loaders. The
  9439. // strict `define` check is necessary for compatibility with `r.js`.
  9440. var isLoader = false;
  9441. // A set of types used to distinguish objects from primitives.
  9442. var objectTypes = {
  9443. "function": true,
  9444. "object": true
  9445. };
  9446. // Detect the `exports` object exposed by CommonJS implementations.
  9447. var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
  9448. // Use the `global` object exposed by Node (including Browserify via
  9449. // `insert-module-globals`), Narwhal, and Ringo as the default context,
  9450. // and the `window` object in browsers. Rhino exports a `global` function
  9451. // instead.
  9452. var root = objectTypes[typeof window] && window || this,
  9453. freeGlobal = freeExports && objectTypes[typeof module] && module && !module.nodeType && typeof global == "object" && global;
  9454. if (freeGlobal && (freeGlobal["global"] === freeGlobal || freeGlobal["window"] === freeGlobal || freeGlobal["self"] === freeGlobal)) {
  9455. root = freeGlobal;
  9456. }
  9457. // Public: Initializes JSON 3 using the given `context` object, attaching the
  9458. // `stringify` and `parse` functions to the specified `exports` object.
  9459. function runInContext(context, exports) {
  9460. context || (context = root["Object"]());
  9461. exports || (exports = root["Object"]());
  9462. // Native constructor aliases.
  9463. var Number = context["Number"] || root["Number"],
  9464. String = context["String"] || root["String"],
  9465. Object = context["Object"] || root["Object"],
  9466. Date = context["Date"] || root["Date"],
  9467. SyntaxError = context["SyntaxError"] || root["SyntaxError"],
  9468. TypeError = context["TypeError"] || root["TypeError"],
  9469. Math = context["Math"] || root["Math"],
  9470. nativeJSON = context["JSON"] || root["JSON"];
  9471. // Delegate to the native `stringify` and `parse` implementations.
  9472. if (typeof nativeJSON == "object" && nativeJSON) {
  9473. exports.stringify = nativeJSON.stringify;
  9474. exports.parse = nativeJSON.parse;
  9475. }
  9476. // Convenience aliases.
  9477. var objectProto = Object.prototype,
  9478. getClass = objectProto.toString,
  9479. isProperty, forEach, undef;
  9480. // Test the `Date#getUTC*` methods. Based on work by @Yaffle.
  9481. var isExtended = new Date(-3509827334573292);
  9482. try {
  9483. // The `getUTCFullYear`, `Month`, and `Date` methods return nonsensical
  9484. // results for certain dates in Opera >= 10.53.
  9485. isExtended = isExtended.getUTCFullYear() == -109252 && isExtended.getUTCMonth() === 0 && isExtended.getUTCDate() === 1 &&
  9486. // Safari < 2.0.2 stores the internal millisecond time value correctly,
  9487. // but clips the values returned by the date methods to the range of
  9488. // signed 32-bit integers ([-2 ** 31, 2 ** 31 - 1]).
  9489. isExtended.getUTCHours() == 10 && isExtended.getUTCMinutes() == 37 && isExtended.getUTCSeconds() == 6 && isExtended.getUTCMilliseconds() == 708;
  9490. } catch (exception) {}
  9491. // Internal: Determines whether the native `JSON.stringify` and `parse`
  9492. // implementations are spec-compliant. Based on work by Ken Snyder.
  9493. function has(name) {
  9494. if (has[name] !== undef) {
  9495. // Return cached feature test result.
  9496. return has[name];
  9497. }
  9498. var isSupported;
  9499. if (name == "bug-string-char-index") {
  9500. // IE <= 7 doesn't support accessing string characters using square
  9501. // bracket notation. IE 8 only supports this for primitives.
  9502. isSupported = "a"[0] != "a";
  9503. } else if (name == "json") {
  9504. // Indicates whether both `JSON.stringify` and `JSON.parse` are
  9505. // supported.
  9506. isSupported = has("json-stringify") && has("json-parse");
  9507. } else {
  9508. var value, serialized = '{"a":[1,true,false,null,"\\u0000\\b\\n\\f\\r\\t"]}';
  9509. // Test `JSON.stringify`.
  9510. if (name == "json-stringify") {
  9511. var stringify = exports.stringify, stringifySupported = typeof stringify == "function" && isExtended;
  9512. if (stringifySupported) {
  9513. // A test function object with a custom `toJSON` method.
  9514. (value = function () {
  9515. return 1;
  9516. }).toJSON = value;
  9517. try {
  9518. stringifySupported =
  9519. // Firefox 3.1b1 and b2 serialize string, number, and boolean
  9520. // primitives as object literals.
  9521. stringify(0) === "0" &&
  9522. // FF 3.1b1, b2, and JSON 2 serialize wrapped primitives as object
  9523. // literals.
  9524. stringify(new Number()) === "0" &&
  9525. stringify(new String()) == '""' &&
  9526. // FF 3.1b1, 2 throw an error if the value is `null`, `undefined`, or
  9527. // does not define a canonical JSON representation (this applies to
  9528. // objects with `toJSON` properties as well, *unless* they are nested
  9529. // within an object or array).
  9530. stringify(getClass) === undef &&
  9531. // IE 8 serializes `undefined` as `"undefined"`. Safari <= 5.1.7 and
  9532. // FF 3.1b3 pass this test.
  9533. stringify(undef) === undef &&
  9534. // Safari <= 5.1.7 and FF 3.1b3 throw `Error`s and `TypeError`s,
  9535. // respectively, if the value is omitted entirely.
  9536. stringify() === undef &&
  9537. // FF 3.1b1, 2 throw an error if the given value is not a number,
  9538. // string, array, object, Boolean, or `null` literal. This applies to
  9539. // objects with custom `toJSON` methods as well, unless they are nested
  9540. // inside object or array literals. YUI 3.0.0b1 ignores custom `toJSON`
  9541. // methods entirely.
  9542. stringify(value) === "1" &&
  9543. stringify([value]) == "[1]" &&
  9544. // Prototype <= 1.6.1 serializes `[undefined]` as `"[]"` instead of
  9545. // `"[null]"`.
  9546. stringify([undef]) == "[null]" &&
  9547. // YUI 3.0.0b1 fails to serialize `null` literals.
  9548. stringify(null) == "null" &&
  9549. // FF 3.1b1, 2 halts serialization if an array contains a function:
  9550. // `[1, true, getClass, 1]` serializes as "[1,true,],". FF 3.1b3
  9551. // elides non-JSON values from objects and arrays, unless they
  9552. // define custom `toJSON` methods.
  9553. stringify([undef, getClass, null]) == "[null,null,null]" &&
  9554. // Simple serialization test. FF 3.1b1 uses Unicode escape sequences
  9555. // where character escape codes are expected (e.g., `\b` => `\u0008`).
  9556. stringify({ "a": [value, true, false, null, "\x00\b\n\f\r\t"] }) == serialized &&
  9557. // FF 3.1b1 and b2 ignore the `filter` and `width` arguments.
  9558. stringify(null, value) === "1" &&
  9559. stringify([1, 2], null, 1) == "[\n 1,\n 2\n]" &&
  9560. // JSON 2, Prototype <= 1.7, and older WebKit builds incorrectly
  9561. // serialize extended years.
  9562. stringify(new Date(-8.64e15)) == '"-271821-04-20T00:00:00.000Z"' &&
  9563. // The milliseconds are optional in ES 5, but required in 5.1.
  9564. stringify(new Date(8.64e15)) == '"+275760-09-13T00:00:00.000Z"' &&
  9565. // Firefox <= 11.0 incorrectly serializes years prior to 0 as negative
  9566. // four-digit years instead of six-digit years. Credits: @Yaffle.
  9567. stringify(new Date(-621987552e5)) == '"-000001-01-01T00:00:00.000Z"' &&
  9568. // Safari <= 5.1.5 and Opera >= 10.53 incorrectly serialize millisecond
  9569. // values less than 1000. Credits: @Yaffle.
  9570. stringify(new Date(-1)) == '"1969-12-31T23:59:59.999Z"';
  9571. } catch (exception) {
  9572. stringifySupported = false;
  9573. }
  9574. }
  9575. isSupported = stringifySupported;
  9576. }
  9577. // Test `JSON.parse`.
  9578. if (name == "json-parse") {
  9579. var parse = exports.parse;
  9580. if (typeof parse == "function") {
  9581. try {
  9582. // FF 3.1b1, b2 will throw an exception if a bare literal is provided.
  9583. // Conforming implementations should also coerce the initial argument to
  9584. // a string prior to parsing.
  9585. if (parse("0") === 0 && !parse(false)) {
  9586. // Simple parsing test.
  9587. value = parse(serialized);
  9588. var parseSupported = value["a"].length == 5 && value["a"][0] === 1;
  9589. if (parseSupported) {
  9590. try {
  9591. // Safari <= 5.1.2 and FF 3.1b1 allow unescaped tabs in strings.
  9592. parseSupported = !parse('"\t"');
  9593. } catch (exception) {}
  9594. if (parseSupported) {
  9595. try {
  9596. // FF 4.0 and 4.0.1 allow leading `+` signs and leading
  9597. // decimal points. FF 4.0, 4.0.1, and IE 9-10 also allow
  9598. // certain octal literals.
  9599. parseSupported = parse("01") !== 1;
  9600. } catch (exception) {}
  9601. }
  9602. if (parseSupported) {
  9603. try {
  9604. // FF 4.0, 4.0.1, and Rhino 1.7R3-R4 allow trailing decimal
  9605. // points. These environments, along with FF 3.1b1 and 2,
  9606. // also allow trailing commas in JSON objects and arrays.
  9607. parseSupported = parse("1.") !== 1;
  9608. } catch (exception) {}
  9609. }
  9610. }
  9611. }
  9612. } catch (exception) {
  9613. parseSupported = false;
  9614. }
  9615. }
  9616. isSupported = parseSupported;
  9617. }
  9618. }
  9619. return has[name] = !!isSupported;
  9620. }
  9621. if (!has("json")) {
  9622. // Common `[[Class]]` name aliases.
  9623. var functionClass = "[object Function]",
  9624. dateClass = "[object Date]",
  9625. numberClass = "[object Number]",
  9626. stringClass = "[object String]",
  9627. arrayClass = "[object Array]",
  9628. booleanClass = "[object Boolean]";
  9629. // Detect incomplete support for accessing string characters by index.
  9630. var charIndexBuggy = has("bug-string-char-index");
  9631. // Define additional utility methods if the `Date` methods are buggy.
  9632. if (!isExtended) {
  9633. var floor = Math.floor;
  9634. // A mapping between the months of the year and the number of days between
  9635. // January 1st and the first of the respective month.
  9636. var Months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
  9637. // Internal: Calculates the number of days between the Unix epoch and the
  9638. // first day of the given month.
  9639. var getDay = function (year, month) {
  9640. return Months[month] + 365 * (year - 1970) + floor((year - 1969 + (month = +(month > 1))) / 4) - floor((year - 1901 + month) / 100) + floor((year - 1601 + month) / 400);
  9641. };
  9642. }
  9643. // Internal: Determines if a property is a direct property of the given
  9644. // object. Delegates to the native `Object#hasOwnProperty` method.
  9645. if (!(isProperty = objectProto.hasOwnProperty)) {
  9646. isProperty = function (property) {
  9647. var members = {}, constructor;
  9648. if ((members.__proto__ = null, members.__proto__ = {
  9649. // The *proto* property cannot be set multiple times in recent
  9650. // versions of Firefox and SeaMonkey.
  9651. "toString": 1
  9652. }, members).toString != getClass) {
  9653. // Safari <= 2.0.3 doesn't implement `Object#hasOwnProperty`, but
  9654. // supports the mutable *proto* property.
  9655. isProperty = function (property) {
  9656. // Capture and break the object's prototype chain (see section 8.6.2
  9657. // of the ES 5.1 spec). The parenthesized expression prevents an
  9658. // unsafe transformation by the Closure Compiler.
  9659. var original = this.__proto__, result = property in (this.__proto__ = null, this);
  9660. // Restore the original prototype chain.
  9661. this.__proto__ = original;
  9662. return result;
  9663. };
  9664. } else {
  9665. // Capture a reference to the top-level `Object` constructor.
  9666. constructor = members.constructor;
  9667. // Use the `constructor` property to simulate `Object#hasOwnProperty` in
  9668. // other environments.
  9669. isProperty = function (property) {
  9670. var parent = (this.constructor || constructor).prototype;
  9671. return property in this && !(property in parent && this[property] === parent[property]);
  9672. };
  9673. }
  9674. members = null;
  9675. return isProperty.call(this, property);
  9676. };
  9677. }
  9678. // Internal: Normalizes the `for...in` iteration algorithm across
  9679. // environments. Each enumerated key is yielded to a `callback` function.
  9680. forEach = function (object, callback) {
  9681. var size = 0, Properties, members, property;
  9682. // Tests for bugs in the current environment's `for...in` algorithm. The
  9683. // `valueOf` property inherits the non-enumerable flag from
  9684. // `Object.prototype` in older versions of IE, Netscape, and Mozilla.
  9685. (Properties = function () {
  9686. this.valueOf = 0;
  9687. }).prototype.valueOf = 0;
  9688. // Iterate over a new instance of the `Properties` class.
  9689. members = new Properties();
  9690. for (property in members) {
  9691. // Ignore all properties inherited from `Object.prototype`.
  9692. if (isProperty.call(members, property)) {
  9693. size++;
  9694. }
  9695. }
  9696. Properties = members = null;
  9697. // Normalize the iteration algorithm.
  9698. if (!size) {
  9699. // A list of non-enumerable properties inherited from `Object.prototype`.
  9700. members = ["valueOf", "toString", "toLocaleString", "propertyIsEnumerable", "isPrototypeOf", "hasOwnProperty", "constructor"];
  9701. // IE <= 8, Mozilla 1.0, and Netscape 6.2 ignore shadowed non-enumerable
  9702. // properties.
  9703. forEach = function (object, callback) {
  9704. var isFunction = getClass.call(object) == functionClass, property, length;
  9705. var hasProperty = !isFunction && typeof object.constructor != "function" && objectTypes[typeof object.hasOwnProperty] && object.hasOwnProperty || isProperty;
  9706. for (property in object) {
  9707. // Gecko <= 1.0 enumerates the `prototype` property of functions under
  9708. // certain conditions; IE does not.
  9709. if (!(isFunction && property == "prototype") && hasProperty.call(object, property)) {
  9710. callback(property);
  9711. }
  9712. }
  9713. // Manually invoke the callback for each non-enumerable property.
  9714. for (length = members.length; property = members[--length]; hasProperty.call(object, property) && callback(property));
  9715. };
  9716. } else if (size == 2) {
  9717. // Safari <= 2.0.4 enumerates shadowed properties twice.
  9718. forEach = function (object, callback) {
  9719. // Create a set of iterated properties.
  9720. var members = {}, isFunction = getClass.call(object) == functionClass, property;
  9721. for (property in object) {
  9722. // Store each property name to prevent double enumeration. The
  9723. // `prototype` property of functions is not enumerated due to cross-
  9724. // environment inconsistencies.
  9725. if (!(isFunction && property == "prototype") && !isProperty.call(members, property) && (members[property] = 1) && isProperty.call(object, property)) {
  9726. callback(property);
  9727. }
  9728. }
  9729. };
  9730. } else {
  9731. // No bugs detected; use the standard `for...in` algorithm.
  9732. forEach = function (object, callback) {
  9733. var isFunction = getClass.call(object) == functionClass, property, isConstructor;
  9734. for (property in object) {
  9735. if (!(isFunction && property == "prototype") && isProperty.call(object, property) && !(isConstructor = property === "constructor")) {
  9736. callback(property);
  9737. }
  9738. }
  9739. // Manually invoke the callback for the `constructor` property due to
  9740. // cross-environment inconsistencies.
  9741. if (isConstructor || isProperty.call(object, (property = "constructor"))) {
  9742. callback(property);
  9743. }
  9744. };
  9745. }
  9746. return forEach(object, callback);
  9747. };
  9748. // Public: Serializes a JavaScript `value` as a JSON string. The optional
  9749. // `filter` argument may specify either a function that alters how object and
  9750. // array members are serialized, or an array of strings and numbers that
  9751. // indicates which properties should be serialized. The optional `width`
  9752. // argument may be either a string or number that specifies the indentation
  9753. // level of the output.
  9754. if (!has("json-stringify")) {
  9755. // Internal: A map of control characters and their escaped equivalents.
  9756. var Escapes = {
  9757. 92: "\\\\",
  9758. 34: '\\"',
  9759. 8: "\\b",
  9760. 12: "\\f",
  9761. 10: "\\n",
  9762. 13: "\\r",
  9763. 9: "\\t"
  9764. };
  9765. // Internal: Converts `value` into a zero-padded string such that its
  9766. // length is at least equal to `width`. The `width` must be <= 6.
  9767. var leadingZeroes = "000000";
  9768. var toPaddedString = function (width, value) {
  9769. // The `|| 0` expression is necessary to work around a bug in
  9770. // Opera <= 7.54u2 where `0 == -0`, but `String(-0) !== "0"`.
  9771. return (leadingZeroes + (value || 0)).slice(-width);
  9772. };
  9773. // Internal: Double-quotes a string `value`, replacing all ASCII control
  9774. // characters (characters with code unit values between 0 and 31) with
  9775. // their escaped equivalents. This is an implementation of the
  9776. // `Quote(value)` operation defined in ES 5.1 section 15.12.3.
  9777. var unicodePrefix = "\\u00";
  9778. var quote = function (value) {
  9779. var result = '"', index = 0, length = value.length, useCharIndex = !charIndexBuggy || length > 10;
  9780. var symbols = useCharIndex && (charIndexBuggy ? value.split("") : value);
  9781. for (; index < length; index++) {
  9782. var charCode = value.charCodeAt(index);
  9783. // If the character is a control character, append its Unicode or
  9784. // shorthand escape sequence; otherwise, append the character as-is.
  9785. switch (charCode) {
  9786. case 8: case 9: case 10: case 12: case 13: case 34: case 92:
  9787. result += Escapes[charCode];
  9788. break;
  9789. default:
  9790. if (charCode < 32) {
  9791. result += unicodePrefix + toPaddedString(2, charCode.toString(16));
  9792. break;
  9793. }
  9794. result += useCharIndex ? symbols[index] : value.charAt(index);
  9795. }
  9796. }
  9797. return result + '"';
  9798. };
  9799. // Internal: Recursively serializes an object. Implements the
  9800. // `Str(key, holder)`, `JO(value)`, and `JA(value)` operations.
  9801. var serialize = function (property, object, callback, properties, whitespace, indentation, stack) {
  9802. var value, className, year, month, date, time, hours, minutes, seconds, milliseconds, results, element, index, length, prefix, result;
  9803. try {
  9804. // Necessary for host object support.
  9805. value = object[property];
  9806. } catch (exception) {}
  9807. if (typeof value == "object" && value) {
  9808. className = getClass.call(value);
  9809. if (className == dateClass && !isProperty.call(value, "toJSON")) {
  9810. if (value > -1 / 0 && value < 1 / 0) {
  9811. // Dates are serialized according to the `Date#toJSON` method
  9812. // specified in ES 5.1 section 15.9.5.44. See section 15.9.1.15
  9813. // for the ISO 8601 date time string format.
  9814. if (getDay) {
  9815. // Manually compute the year, month, date, hours, minutes,
  9816. // seconds, and milliseconds if the `getUTC*` methods are
  9817. // buggy. Adapted from @Yaffle's `date-shim` project.
  9818. date = floor(value / 864e5);
  9819. for (year = floor(date / 365.2425) + 1970 - 1; getDay(year + 1, 0) <= date; year++);
  9820. for (month = floor((date - getDay(year, 0)) / 30.42); getDay(year, month + 1) <= date; month++);
  9821. date = 1 + date - getDay(year, month);
  9822. // The `time` value specifies the time within the day (see ES
  9823. // 5.1 section 15.9.1.2). The formula `(A % B + B) % B` is used
  9824. // to compute `A modulo B`, as the `%` operator does not
  9825. // correspond to the `modulo` operation for negative numbers.
  9826. time = (value % 864e5 + 864e5) % 864e5;
  9827. // The hours, minutes, seconds, and milliseconds are obtained by
  9828. // decomposing the time within the day. See section 15.9.1.10.
  9829. hours = floor(time / 36e5) % 24;
  9830. minutes = floor(time / 6e4) % 60;
  9831. seconds = floor(time / 1e3) % 60;
  9832. milliseconds = time % 1e3;
  9833. } else {
  9834. year = value.getUTCFullYear();
  9835. month = value.getUTCMonth();
  9836. date = value.getUTCDate();
  9837. hours = value.getUTCHours();
  9838. minutes = value.getUTCMinutes();
  9839. seconds = value.getUTCSeconds();
  9840. milliseconds = value.getUTCMilliseconds();
  9841. }
  9842. // Serialize extended years correctly.
  9843. value = (year <= 0 || year >= 1e4 ? (year < 0 ? "-" : "+") + toPaddedString(6, year < 0 ? -year : year) : toPaddedString(4, year)) +
  9844. "-" + toPaddedString(2, month + 1) + "-" + toPaddedString(2, date) +
  9845. // Months, dates, hours, minutes, and seconds should have two
  9846. // digits; milliseconds should have three.
  9847. "T" + toPaddedString(2, hours) + ":" + toPaddedString(2, minutes) + ":" + toPaddedString(2, seconds) +
  9848. // Milliseconds are optional in ES 5.0, but required in 5.1.
  9849. "." + toPaddedString(3, milliseconds) + "Z";
  9850. } else {
  9851. value = null;
  9852. }
  9853. } else if (typeof value.toJSON == "function" && ((className != numberClass && className != stringClass && className != arrayClass) || isProperty.call(value, "toJSON"))) {
  9854. // Prototype <= 1.6.1 adds non-standard `toJSON` methods to the
  9855. // `Number`, `String`, `Date`, and `Array` prototypes. JSON 3
  9856. // ignores all `toJSON` methods on these objects unless they are
  9857. // defined directly on an instance.
  9858. value = value.toJSON(property);
  9859. }
  9860. }
  9861. if (callback) {
  9862. // If a replacement function was provided, call it to obtain the value
  9863. // for serialization.
  9864. value = callback.call(object, property, value);
  9865. }
  9866. if (value === null) {
  9867. return "null";
  9868. }
  9869. className = getClass.call(value);
  9870. if (className == booleanClass) {
  9871. // Booleans are represented literally.
  9872. return "" + value;
  9873. } else if (className == numberClass) {
  9874. // JSON numbers must be finite. `Infinity` and `NaN` are serialized as
  9875. // `"null"`.
  9876. return value > -1 / 0 && value < 1 / 0 ? "" + value : "null";
  9877. } else if (className == stringClass) {
  9878. // Strings are double-quoted and escaped.
  9879. return quote("" + value);
  9880. }
  9881. // Recursively serialize objects and arrays.
  9882. if (typeof value == "object") {
  9883. // Check for cyclic structures. This is a linear search; performance
  9884. // is inversely proportional to the number of unique nested objects.
  9885. for (length = stack.length; length--;) {
  9886. if (stack[length] === value) {
  9887. // Cyclic structures cannot be serialized by `JSON.stringify`.
  9888. throw TypeError();
  9889. }
  9890. }
  9891. // Add the object to the stack of traversed objects.
  9892. stack.push(value);
  9893. results = [];
  9894. // Save the current indentation level and indent one additional level.
  9895. prefix = indentation;
  9896. indentation += whitespace;
  9897. if (className == arrayClass) {
  9898. // Recursively serialize array elements.
  9899. for (index = 0, length = value.length; index < length; index++) {
  9900. element = serialize(index, value, callback, properties, whitespace, indentation, stack);
  9901. results.push(element === undef ? "null" : element);
  9902. }
  9903. result = results.length ? (whitespace ? "[\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "]" : ("[" + results.join(",") + "]")) : "[]";
  9904. } else {
  9905. // Recursively serialize object members. Members are selected from
  9906. // either a user-specified list of property names, or the object
  9907. // itself.
  9908. forEach(properties || value, function (property) {
  9909. var element = serialize(property, value, callback, properties, whitespace, indentation, stack);
  9910. if (element !== undef) {
  9911. // According to ES 5.1 section 15.12.3: "If `gap` {whitespace}
  9912. // is not the empty string, let `member` {quote(property) + ":"}
  9913. // be the concatenation of `member` and the `space` character."
  9914. // The "`space` character" refers to the literal space
  9915. // character, not the `space` {width} argument provided to
  9916. // `JSON.stringify`.
  9917. results.push(quote(property) + ":" + (whitespace ? " " : "") + element);
  9918. }
  9919. });
  9920. result = results.length ? (whitespace ? "{\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "}" : ("{" + results.join(",") + "}")) : "{}";
  9921. }
  9922. // Remove the object from the traversed object stack.
  9923. stack.pop();
  9924. return result;
  9925. }
  9926. };
  9927. // Public: `JSON.stringify`. See ES 5.1 section 15.12.3.
  9928. exports.stringify = function (source, filter, width) {
  9929. var whitespace, callback, properties, className;
  9930. if (objectTypes[typeof filter] && filter) {
  9931. if ((className = getClass.call(filter)) == functionClass) {
  9932. callback = filter;
  9933. } else if (className == arrayClass) {
  9934. // Convert the property names array into a makeshift set.
  9935. properties = {};
  9936. for (var index = 0, length = filter.length, value; index < length; value = filter[index++], ((className = getClass.call(value)), className == stringClass || className == numberClass) && (properties[value] = 1));
  9937. }
  9938. }
  9939. if (width) {
  9940. if ((className = getClass.call(width)) == numberClass) {
  9941. // Convert the `width` to an integer and create a string containing
  9942. // `width` number of space characters.
  9943. if ((width -= width % 1) > 0) {
  9944. for (whitespace = "", width > 10 && (width = 10); whitespace.length < width; whitespace += " ");
  9945. }
  9946. } else if (className == stringClass) {
  9947. whitespace = width.length <= 10 ? width : width.slice(0, 10);
  9948. }
  9949. }
  9950. // Opera <= 7.54u2 discards the values associated with empty string keys
  9951. // (`""`) only if they are used directly within an object member list
  9952. // (e.g., `!("" in { "": 1})`).
  9953. return serialize("", (value = {}, value[""] = source, value), callback, properties, whitespace, "", []);
  9954. };
  9955. }
  9956. // Public: Parses a JSON source string.
  9957. if (!has("json-parse")) {
  9958. var fromCharCode = String.fromCharCode;
  9959. // Internal: A map of escaped control characters and their unescaped
  9960. // equivalents.
  9961. var Unescapes = {
  9962. 92: "\\",
  9963. 34: '"',
  9964. 47: "/",
  9965. 98: "\b",
  9966. 116: "\t",
  9967. 110: "\n",
  9968. 102: "\f",
  9969. 114: "\r"
  9970. };
  9971. // Internal: Stores the parser state.
  9972. var Index, Source;
  9973. // Internal: Resets the parser state and throws a `SyntaxError`.
  9974. var abort = function () {
  9975. Index = Source = null;
  9976. throw SyntaxError();
  9977. };
  9978. // Internal: Returns the next token, or `"$"` if the parser has reached
  9979. // the end of the source string. A token may be a string, number, `null`
  9980. // literal, or Boolean literal.
  9981. var lex = function () {
  9982. var source = Source, length = source.length, value, begin, position, isSigned, charCode;
  9983. while (Index < length) {
  9984. charCode = source.charCodeAt(Index);
  9985. switch (charCode) {
  9986. case 9: case 10: case 13: case 32:
  9987. // Skip whitespace tokens, including tabs, carriage returns, line
  9988. // feeds, and space characters.
  9989. Index++;
  9990. break;
  9991. case 123: case 125: case 91: case 93: case 58: case 44:
  9992. // Parse a punctuator token (`{`, `}`, `[`, `]`, `:`, or `,`) at
  9993. // the current position.
  9994. value = charIndexBuggy ? source.charAt(Index) : source[Index];
  9995. Index++;
  9996. return value;
  9997. case 34:
  9998. // `"` delimits a JSON string; advance to the next character and
  9999. // begin parsing the string. String tokens are prefixed with the
  10000. // sentinel `@` character to distinguish them from punctuators and
  10001. // end-of-string tokens.
  10002. for (value = "@", Index++; Index < length;) {
  10003. charCode = source.charCodeAt(Index);
  10004. if (charCode < 32) {
  10005. // Unescaped ASCII control characters (those with a code unit
  10006. // less than the space character) are not permitted.
  10007. abort();
  10008. } else if (charCode == 92) {
  10009. // A reverse solidus (`\`) marks the beginning of an escaped
  10010. // control character (including `"`, `\`, and `/`) or Unicode
  10011. // escape sequence.
  10012. charCode = source.charCodeAt(++Index);
  10013. switch (charCode) {
  10014. case 92: case 34: case 47: case 98: case 116: case 110: case 102: case 114:
  10015. // Revive escaped control characters.
  10016. value += Unescapes[charCode];
  10017. Index++;
  10018. break;
  10019. case 117:
  10020. // `\u` marks the beginning of a Unicode escape sequence.
  10021. // Advance to the first character and validate the
  10022. // four-digit code point.
  10023. begin = ++Index;
  10024. for (position = Index + 4; Index < position; Index++) {
  10025. charCode = source.charCodeAt(Index);
  10026. // A valid sequence comprises four hexdigits (case-
  10027. // insensitive) that form a single hexadecimal value.
  10028. if (!(charCode >= 48 && charCode <= 57 || charCode >= 97 && charCode <= 102 || charCode >= 65 && charCode <= 70)) {
  10029. // Invalid Unicode escape sequence.
  10030. abort();
  10031. }
  10032. }
  10033. // Revive the escaped character.
  10034. value += fromCharCode("0x" + source.slice(begin, Index));
  10035. break;
  10036. default:
  10037. // Invalid escape sequence.
  10038. abort();
  10039. }
  10040. } else {
  10041. if (charCode == 34) {
  10042. // An unescaped double-quote character marks the end of the
  10043. // string.
  10044. break;
  10045. }
  10046. charCode = source.charCodeAt(Index);
  10047. begin = Index;
  10048. // Optimize for the common case where a string is valid.
  10049. while (charCode >= 32 && charCode != 92 && charCode != 34) {
  10050. charCode = source.charCodeAt(++Index);
  10051. }
  10052. // Append the string as-is.
  10053. value += source.slice(begin, Index);
  10054. }
  10055. }
  10056. if (source.charCodeAt(Index) == 34) {
  10057. // Advance to the next character and return the revived string.
  10058. Index++;
  10059. return value;
  10060. }
  10061. // Unterminated string.
  10062. abort();
  10063. default:
  10064. // Parse numbers and literals.
  10065. begin = Index;
  10066. // Advance past the negative sign, if one is specified.
  10067. if (charCode == 45) {
  10068. isSigned = true;
  10069. charCode = source.charCodeAt(++Index);
  10070. }
  10071. // Parse an integer or floating-point value.
  10072. if (charCode >= 48 && charCode <= 57) {
  10073. // Leading zeroes are interpreted as octal literals.
  10074. if (charCode == 48 && ((charCode = source.charCodeAt(Index + 1)), charCode >= 48 && charCode <= 57)) {
  10075. // Illegal octal literal.
  10076. abort();
  10077. }
  10078. isSigned = false;
  10079. // Parse the integer component.
  10080. for (; Index < length && ((charCode = source.charCodeAt(Index)), charCode >= 48 && charCode <= 57); Index++);
  10081. // Floats cannot contain a leading decimal point; however, this
  10082. // case is already accounted for by the parser.
  10083. if (source.charCodeAt(Index) == 46) {
  10084. position = ++Index;
  10085. // Parse the decimal component.
  10086. for (; position < length && ((charCode = source.charCodeAt(position)), charCode >= 48 && charCode <= 57); position++);
  10087. if (position == Index) {
  10088. // Illegal trailing decimal.
  10089. abort();
  10090. }
  10091. Index = position;
  10092. }
  10093. // Parse exponents. The `e` denoting the exponent is
  10094. // case-insensitive.
  10095. charCode = source.charCodeAt(Index);
  10096. if (charCode == 101 || charCode == 69) {
  10097. charCode = source.charCodeAt(++Index);
  10098. // Skip past the sign following the exponent, if one is
  10099. // specified.
  10100. if (charCode == 43 || charCode == 45) {
  10101. Index++;
  10102. }
  10103. // Parse the exponential component.
  10104. for (position = Index; position < length && ((charCode = source.charCodeAt(position)), charCode >= 48 && charCode <= 57); position++);
  10105. if (position == Index) {
  10106. // Illegal empty exponent.
  10107. abort();
  10108. }
  10109. Index = position;
  10110. }
  10111. // Coerce the parsed value to a JavaScript number.
  10112. return +source.slice(begin, Index);
  10113. }
  10114. // A negative sign may only precede numbers.
  10115. if (isSigned) {
  10116. abort();
  10117. }
  10118. // `true`, `false`, and `null` literals.
  10119. if (source.slice(Index, Index + 4) == "true") {
  10120. Index += 4;
  10121. return true;
  10122. } else if (source.slice(Index, Index + 5) == "false") {
  10123. Index += 5;
  10124. return false;
  10125. } else if (source.slice(Index, Index + 4) == "null") {
  10126. Index += 4;
  10127. return null;
  10128. }
  10129. // Unrecognized token.
  10130. abort();
  10131. }
  10132. }
  10133. // Return the sentinel `$` character if the parser has reached the end
  10134. // of the source string.
  10135. return "$";
  10136. };
  10137. // Internal: Parses a JSON `value` token.
  10138. var get = function (value) {
  10139. var results, hasMembers;
  10140. if (value == "$") {
  10141. // Unexpected end of input.
  10142. abort();
  10143. }
  10144. if (typeof value == "string") {
  10145. if ((charIndexBuggy ? value.charAt(0) : value[0]) == "@") {
  10146. // Remove the sentinel `@` character.
  10147. return value.slice(1);
  10148. }
  10149. // Parse object and array literals.
  10150. if (value == "[") {
  10151. // Parses a JSON array, returning a new JavaScript array.
  10152. results = [];
  10153. for (;; hasMembers || (hasMembers = true)) {
  10154. value = lex();
  10155. // A closing square bracket marks the end of the array literal.
  10156. if (value == "]") {
  10157. break;
  10158. }
  10159. // If the array literal contains elements, the current token
  10160. // should be a comma separating the previous element from the
  10161. // next.
  10162. if (hasMembers) {
  10163. if (value == ",") {
  10164. value = lex();
  10165. if (value == "]") {
  10166. // Unexpected trailing `,` in array literal.
  10167. abort();
  10168. }
  10169. } else {
  10170. // A `,` must separate each array element.
  10171. abort();
  10172. }
  10173. }
  10174. // Elisions and leading commas are not permitted.
  10175. if (value == ",") {
  10176. abort();
  10177. }
  10178. results.push(get(value));
  10179. }
  10180. return results;
  10181. } else if (value == "{") {
  10182. // Parses a JSON object, returning a new JavaScript object.
  10183. results = {};
  10184. for (;; hasMembers || (hasMembers = true)) {
  10185. value = lex();
  10186. // A closing curly brace marks the end of the object literal.
  10187. if (value == "}") {
  10188. break;
  10189. }
  10190. // If the object literal contains members, the current token
  10191. // should be a comma separator.
  10192. if (hasMembers) {
  10193. if (value == ",") {
  10194. value = lex();
  10195. if (value == "}") {
  10196. // Unexpected trailing `,` in object literal.
  10197. abort();
  10198. }
  10199. } else {
  10200. // A `,` must separate each object member.
  10201. abort();
  10202. }
  10203. }
  10204. // Leading commas are not permitted, object property names must be
  10205. // double-quoted strings, and a `:` must separate each property
  10206. // name and value.
  10207. if (value == "," || typeof value != "string" || (charIndexBuggy ? value.charAt(0) : value[0]) != "@" || lex() != ":") {
  10208. abort();
  10209. }
  10210. results[value.slice(1)] = get(lex());
  10211. }
  10212. return results;
  10213. }
  10214. // Unexpected token encountered.
  10215. abort();
  10216. }
  10217. return value;
  10218. };
  10219. // Internal: Updates a traversed object member.
  10220. var update = function (source, property, callback) {
  10221. var element = walk(source, property, callback);
  10222. if (element === undef) {
  10223. delete source[property];
  10224. } else {
  10225. source[property] = element;
  10226. }
  10227. };
  10228. // Internal: Recursively traverses a parsed JSON object, invoking the
  10229. // `callback` function for each value. This is an implementation of the
  10230. // `Walk(holder, name)` operation defined in ES 5.1 section 15.12.2.
  10231. var walk = function (source, property, callback) {
  10232. var value = source[property], length;
  10233. if (typeof value == "object" && value) {
  10234. // `forEach` can't be used to traverse an array in Opera <= 8.54
  10235. // because its `Object#hasOwnProperty` implementation returns `false`
  10236. // for array indices (e.g., `![1, 2, 3].hasOwnProperty("0")`).
  10237. if (getClass.call(value) == arrayClass) {
  10238. for (length = value.length; length--;) {
  10239. update(value, length, callback);
  10240. }
  10241. } else {
  10242. forEach(value, function (property) {
  10243. update(value, property, callback);
  10244. });
  10245. }
  10246. }
  10247. return callback.call(source, property, value);
  10248. };
  10249. // Public: `JSON.parse`. See ES 5.1 section 15.12.2.
  10250. exports.parse = function (source, callback) {
  10251. var result, value;
  10252. Index = 0;
  10253. Source = "" + source;
  10254. result = get(lex());
  10255. // If a JSON string contains multiple tokens, it is invalid.
  10256. if (lex() != "$") {
  10257. abort();
  10258. }
  10259. // Reset the parser state.
  10260. Index = Source = null;
  10261. return callback && getClass.call(callback) == functionClass ? walk((value = {}, value[""] = result, value), "", callback) : result;
  10262. };
  10263. }
  10264. }
  10265. exports["runInContext"] = runInContext;
  10266. return exports;
  10267. }
  10268. if (freeExports && !isLoader) {
  10269. // Export for CommonJS environments.
  10270. runInContext(root, freeExports);
  10271. } else {
  10272. // Export for web browsers and JavaScript engines.
  10273. var nativeJSON = root.JSON,
  10274. previousJSON = root["JSON3"],
  10275. isRestored = false;
  10276. var JSON3 = runInContext(root, (root["JSON3"] = {
  10277. // Public: Restores the original value of the global `JSON` object and
  10278. // returns a reference to the `JSON3` object.
  10279. "noConflict": function () {
  10280. if (!isRestored) {
  10281. isRestored = true;
  10282. root.JSON = nativeJSON;
  10283. root["JSON3"] = previousJSON;
  10284. nativeJSON = previousJSON = null;
  10285. }
  10286. return JSON3;
  10287. }
  10288. }));
  10289. root.JSON = {
  10290. "parse": JSON3.parse,
  10291. "stringify": JSON3.stringify
  10292. };
  10293. }
  10294. // Export for asynchronous module loaders.
  10295. if (isLoader) {
  10296. define(function () {
  10297. return JSON3;
  10298. });
  10299. }
  10300. }).call(this);
  10301. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  10302. },{}],70:[function(require,module,exports){
  10303. /**
  10304. * lodash 3.2.0 (Custom Build) <https://lodash.com/>
  10305. * Build: `lodash modern modularize exports="npm" -o ./`
  10306. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10307. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10308. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10309. * Available under MIT license <https://lodash.com/license>
  10310. */
  10311. var baseCopy = require('lodash._basecopy'),
  10312. keys = require('lodash.keys');
  10313. /**
  10314. * The base implementation of `_.assign` without support for argument juggling,
  10315. * multiple sources, and `customizer` functions.
  10316. *
  10317. * @private
  10318. * @param {Object} object The destination object.
  10319. * @param {Object} source The source object.
  10320. * @returns {Object} Returns `object`.
  10321. */
  10322. function baseAssign(object, source) {
  10323. return source == null
  10324. ? object
  10325. : baseCopy(source, keys(source), object);
  10326. }
  10327. module.exports = baseAssign;
  10328. },{"lodash._basecopy":71,"lodash.keys":78}],71:[function(require,module,exports){
  10329. /**
  10330. * lodash 3.0.1 (Custom Build) <https://lodash.com/>
  10331. * Build: `lodash modern modularize exports="npm" -o ./`
  10332. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10333. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10334. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10335. * Available under MIT license <https://lodash.com/license>
  10336. */
  10337. /**
  10338. * Copies properties of `source` to `object`.
  10339. *
  10340. * @private
  10341. * @param {Object} source The object to copy properties from.
  10342. * @param {Array} props The property names to copy.
  10343. * @param {Object} [object={}] The object to copy properties to.
  10344. * @returns {Object} Returns `object`.
  10345. */
  10346. function baseCopy(source, props, object) {
  10347. object || (object = {});
  10348. var index = -1,
  10349. length = props.length;
  10350. while (++index < length) {
  10351. var key = props[index];
  10352. object[key] = source[key];
  10353. }
  10354. return object;
  10355. }
  10356. module.exports = baseCopy;
  10357. },{}],72:[function(require,module,exports){
  10358. /**
  10359. * lodash 3.0.3 (Custom Build) <https://lodash.com/>
  10360. * Build: `lodash modern modularize exports="npm" -o ./`
  10361. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10362. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10363. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10364. * Available under MIT license <https://lodash.com/license>
  10365. */
  10366. /**
  10367. * The base implementation of `_.create` without support for assigning
  10368. * properties to the created object.
  10369. *
  10370. * @private
  10371. * @param {Object} prototype The object to inherit from.
  10372. * @returns {Object} Returns the new object.
  10373. */
  10374. var baseCreate = (function() {
  10375. function object() {}
  10376. return function(prototype) {
  10377. if (isObject(prototype)) {
  10378. object.prototype = prototype;
  10379. var result = new object;
  10380. object.prototype = undefined;
  10381. }
  10382. return result || {};
  10383. };
  10384. }());
  10385. /**
  10386. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  10387. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10388. *
  10389. * @static
  10390. * @memberOf _
  10391. * @category Lang
  10392. * @param {*} value The value to check.
  10393. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10394. * @example
  10395. *
  10396. * _.isObject({});
  10397. * // => true
  10398. *
  10399. * _.isObject([1, 2, 3]);
  10400. * // => true
  10401. *
  10402. * _.isObject(1);
  10403. * // => false
  10404. */
  10405. function isObject(value) {
  10406. // Avoid a V8 JIT bug in Chrome 19-20.
  10407. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  10408. var type = typeof value;
  10409. return !!value && (type == 'object' || type == 'function');
  10410. }
  10411. module.exports = baseCreate;
  10412. },{}],73:[function(require,module,exports){
  10413. /**
  10414. * lodash 3.9.1 (Custom Build) <https://lodash.com/>
  10415. * Build: `lodash modern modularize exports="npm" -o ./`
  10416. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10417. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10418. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10419. * Available under MIT license <https://lodash.com/license>
  10420. */
  10421. /** `Object#toString` result references. */
  10422. var funcTag = '[object Function]';
  10423. /** Used to detect host constructors (Safari > 5). */
  10424. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  10425. /**
  10426. * Checks if `value` is object-like.
  10427. *
  10428. * @private
  10429. * @param {*} value The value to check.
  10430. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10431. */
  10432. function isObjectLike(value) {
  10433. return !!value && typeof value == 'object';
  10434. }
  10435. /** Used for native method references. */
  10436. var objectProto = Object.prototype;
  10437. /** Used to resolve the decompiled source of functions. */
  10438. var fnToString = Function.prototype.toString;
  10439. /** Used to check objects for own properties. */
  10440. var hasOwnProperty = objectProto.hasOwnProperty;
  10441. /**
  10442. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  10443. * of values.
  10444. */
  10445. var objToString = objectProto.toString;
  10446. /** Used to detect if a method is native. */
  10447. var reIsNative = RegExp('^' +
  10448. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  10449. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  10450. );
  10451. /**
  10452. * Gets the native function at `key` of `object`.
  10453. *
  10454. * @private
  10455. * @param {Object} object The object to query.
  10456. * @param {string} key The key of the method to get.
  10457. * @returns {*} Returns the function if it's native, else `undefined`.
  10458. */
  10459. function getNative(object, key) {
  10460. var value = object == null ? undefined : object[key];
  10461. return isNative(value) ? value : undefined;
  10462. }
  10463. /**
  10464. * Checks if `value` is classified as a `Function` object.
  10465. *
  10466. * @static
  10467. * @memberOf _
  10468. * @category Lang
  10469. * @param {*} value The value to check.
  10470. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10471. * @example
  10472. *
  10473. * _.isFunction(_);
  10474. * // => true
  10475. *
  10476. * _.isFunction(/abc/);
  10477. * // => false
  10478. */
  10479. function isFunction(value) {
  10480. // The use of `Object#toString` avoids issues with the `typeof` operator
  10481. // in older versions of Chrome and Safari which return 'function' for regexes
  10482. // and Safari 8 equivalents which return 'object' for typed array constructors.
  10483. return isObject(value) && objToString.call(value) == funcTag;
  10484. }
  10485. /**
  10486. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  10487. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10488. *
  10489. * @static
  10490. * @memberOf _
  10491. * @category Lang
  10492. * @param {*} value The value to check.
  10493. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10494. * @example
  10495. *
  10496. * _.isObject({});
  10497. * // => true
  10498. *
  10499. * _.isObject([1, 2, 3]);
  10500. * // => true
  10501. *
  10502. * _.isObject(1);
  10503. * // => false
  10504. */
  10505. function isObject(value) {
  10506. // Avoid a V8 JIT bug in Chrome 19-20.
  10507. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  10508. var type = typeof value;
  10509. return !!value && (type == 'object' || type == 'function');
  10510. }
  10511. /**
  10512. * Checks if `value` is a native function.
  10513. *
  10514. * @static
  10515. * @memberOf _
  10516. * @category Lang
  10517. * @param {*} value The value to check.
  10518. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  10519. * @example
  10520. *
  10521. * _.isNative(Array.prototype.push);
  10522. * // => true
  10523. *
  10524. * _.isNative(_);
  10525. * // => false
  10526. */
  10527. function isNative(value) {
  10528. if (value == null) {
  10529. return false;
  10530. }
  10531. if (isFunction(value)) {
  10532. return reIsNative.test(fnToString.call(value));
  10533. }
  10534. return isObjectLike(value) && reIsHostCtor.test(value);
  10535. }
  10536. module.exports = getNative;
  10537. },{}],74:[function(require,module,exports){
  10538. /**
  10539. * lodash 3.0.9 (Custom Build) <https://lodash.com/>
  10540. * Build: `lodash modern modularize exports="npm" -o ./`
  10541. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10542. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10543. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10544. * Available under MIT license <https://lodash.com/license>
  10545. */
  10546. /** Used to detect unsigned integer values. */
  10547. var reIsUint = /^\d+$/;
  10548. /**
  10549. * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
  10550. * of an array-like value.
  10551. */
  10552. var MAX_SAFE_INTEGER = 9007199254740991;
  10553. /**
  10554. * The base implementation of `_.property` without support for deep paths.
  10555. *
  10556. * @private
  10557. * @param {string} key The key of the property to get.
  10558. * @returns {Function} Returns the new function.
  10559. */
  10560. function baseProperty(key) {
  10561. return function(object) {
  10562. return object == null ? undefined : object[key];
  10563. };
  10564. }
  10565. /**
  10566. * Gets the "length" property value of `object`.
  10567. *
  10568. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  10569. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  10570. *
  10571. * @private
  10572. * @param {Object} object The object to query.
  10573. * @returns {*} Returns the "length" value.
  10574. */
  10575. var getLength = baseProperty('length');
  10576. /**
  10577. * Checks if `value` is array-like.
  10578. *
  10579. * @private
  10580. * @param {*} value The value to check.
  10581. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10582. */
  10583. function isArrayLike(value) {
  10584. return value != null && isLength(getLength(value));
  10585. }
  10586. /**
  10587. * Checks if `value` is a valid array-like index.
  10588. *
  10589. * @private
  10590. * @param {*} value The value to check.
  10591. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  10592. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  10593. */
  10594. function isIndex(value, length) {
  10595. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  10596. length = length == null ? MAX_SAFE_INTEGER : length;
  10597. return value > -1 && value % 1 == 0 && value < length;
  10598. }
  10599. /**
  10600. * Checks if the provided arguments are from an iteratee call.
  10601. *
  10602. * @private
  10603. * @param {*} value The potential iteratee value argument.
  10604. * @param {*} index The potential iteratee index or key argument.
  10605. * @param {*} object The potential iteratee object argument.
  10606. * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
  10607. */
  10608. function isIterateeCall(value, index, object) {
  10609. if (!isObject(object)) {
  10610. return false;
  10611. }
  10612. var type = typeof index;
  10613. if (type == 'number'
  10614. ? (isArrayLike(object) && isIndex(index, object.length))
  10615. : (type == 'string' && index in object)) {
  10616. var other = object[index];
  10617. return value === value ? (value === other) : (other !== other);
  10618. }
  10619. return false;
  10620. }
  10621. /**
  10622. * Checks if `value` is a valid array-like length.
  10623. *
  10624. * **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
  10625. *
  10626. * @private
  10627. * @param {*} value The value to check.
  10628. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10629. */
  10630. function isLength(value) {
  10631. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10632. }
  10633. /**
  10634. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  10635. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10636. *
  10637. * @static
  10638. * @memberOf _
  10639. * @category Lang
  10640. * @param {*} value The value to check.
  10641. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10642. * @example
  10643. *
  10644. * _.isObject({});
  10645. * // => true
  10646. *
  10647. * _.isObject([1, 2, 3]);
  10648. * // => true
  10649. *
  10650. * _.isObject(1);
  10651. * // => false
  10652. */
  10653. function isObject(value) {
  10654. // Avoid a V8 JIT bug in Chrome 19-20.
  10655. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  10656. var type = typeof value;
  10657. return !!value && (type == 'object' || type == 'function');
  10658. }
  10659. module.exports = isIterateeCall;
  10660. },{}],75:[function(require,module,exports){
  10661. /**
  10662. * lodash 3.1.1 (Custom Build) <https://lodash.com/>
  10663. * Build: `lodash modern modularize exports="npm" -o ./`
  10664. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10665. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10666. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10667. * Available under MIT license <https://lodash.com/license>
  10668. */
  10669. var baseAssign = require('lodash._baseassign'),
  10670. baseCreate = require('lodash._basecreate'),
  10671. isIterateeCall = require('lodash._isiterateecall');
  10672. /**
  10673. * Creates an object that inherits from the given `prototype` object. If a
  10674. * `properties` object is provided its own enumerable properties are assigned
  10675. * to the created object.
  10676. *
  10677. * @static
  10678. * @memberOf _
  10679. * @category Object
  10680. * @param {Object} prototype The object to inherit from.
  10681. * @param {Object} [properties] The properties to assign to the object.
  10682. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10683. * @returns {Object} Returns the new object.
  10684. * @example
  10685. *
  10686. * function Shape() {
  10687. * this.x = 0;
  10688. * this.y = 0;
  10689. * }
  10690. *
  10691. * function Circle() {
  10692. * Shape.call(this);
  10693. * }
  10694. *
  10695. * Circle.prototype = _.create(Shape.prototype, {
  10696. * 'constructor': Circle
  10697. * });
  10698. *
  10699. * var circle = new Circle;
  10700. * circle instanceof Circle;
  10701. * // => true
  10702. *
  10703. * circle instanceof Shape;
  10704. * // => true
  10705. */
  10706. function create(prototype, properties, guard) {
  10707. var result = baseCreate(prototype);
  10708. if (guard && isIterateeCall(prototype, properties, guard)) {
  10709. properties = undefined;
  10710. }
  10711. return properties ? baseAssign(result, properties) : result;
  10712. }
  10713. module.exports = create;
  10714. },{"lodash._baseassign":70,"lodash._basecreate":72,"lodash._isiterateecall":74}],76:[function(require,module,exports){
  10715. /**
  10716. * lodash (Custom Build) <https://lodash.com/>
  10717. * Build: `lodash modularize exports="npm" -o ./`
  10718. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  10719. * Released under MIT license <https://lodash.com/license>
  10720. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10721. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10722. */
  10723. /** Used as references for various `Number` constants. */
  10724. var MAX_SAFE_INTEGER = 9007199254740991;
  10725. /** `Object#toString` result references. */
  10726. var argsTag = '[object Arguments]',
  10727. funcTag = '[object Function]',
  10728. genTag = '[object GeneratorFunction]';
  10729. /** Used for built-in method references. */
  10730. var objectProto = Object.prototype;
  10731. /** Used to check objects for own properties. */
  10732. var hasOwnProperty = objectProto.hasOwnProperty;
  10733. /**
  10734. * Used to resolve the
  10735. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  10736. * of values.
  10737. */
  10738. var objectToString = objectProto.toString;
  10739. /** Built-in value references. */
  10740. var propertyIsEnumerable = objectProto.propertyIsEnumerable;
  10741. /**
  10742. * Checks if `value` is likely an `arguments` object.
  10743. *
  10744. * @static
  10745. * @memberOf _
  10746. * @since 0.1.0
  10747. * @category Lang
  10748. * @param {*} value The value to check.
  10749. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10750. * else `false`.
  10751. * @example
  10752. *
  10753. * _.isArguments(function() { return arguments; }());
  10754. * // => true
  10755. *
  10756. * _.isArguments([1, 2, 3]);
  10757. * // => false
  10758. */
  10759. function isArguments(value) {
  10760. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  10761. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  10762. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  10763. }
  10764. /**
  10765. * Checks if `value` is array-like. A value is considered array-like if it's
  10766. * not a function and has a `value.length` that's an integer greater than or
  10767. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10768. *
  10769. * @static
  10770. * @memberOf _
  10771. * @since 4.0.0
  10772. * @category Lang
  10773. * @param {*} value The value to check.
  10774. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10775. * @example
  10776. *
  10777. * _.isArrayLike([1, 2, 3]);
  10778. * // => true
  10779. *
  10780. * _.isArrayLike(document.body.children);
  10781. * // => true
  10782. *
  10783. * _.isArrayLike('abc');
  10784. * // => true
  10785. *
  10786. * _.isArrayLike(_.noop);
  10787. * // => false
  10788. */
  10789. function isArrayLike(value) {
  10790. return value != null && isLength(value.length) && !isFunction(value);
  10791. }
  10792. /**
  10793. * This method is like `_.isArrayLike` except that it also checks if `value`
  10794. * is an object.
  10795. *
  10796. * @static
  10797. * @memberOf _
  10798. * @since 4.0.0
  10799. * @category Lang
  10800. * @param {*} value The value to check.
  10801. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10802. * else `false`.
  10803. * @example
  10804. *
  10805. * _.isArrayLikeObject([1, 2, 3]);
  10806. * // => true
  10807. *
  10808. * _.isArrayLikeObject(document.body.children);
  10809. * // => true
  10810. *
  10811. * _.isArrayLikeObject('abc');
  10812. * // => false
  10813. *
  10814. * _.isArrayLikeObject(_.noop);
  10815. * // => false
  10816. */
  10817. function isArrayLikeObject(value) {
  10818. return isObjectLike(value) && isArrayLike(value);
  10819. }
  10820. /**
  10821. * Checks if `value` is classified as a `Function` object.
  10822. *
  10823. * @static
  10824. * @memberOf _
  10825. * @since 0.1.0
  10826. * @category Lang
  10827. * @param {*} value The value to check.
  10828. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10829. * @example
  10830. *
  10831. * _.isFunction(_);
  10832. * // => true
  10833. *
  10834. * _.isFunction(/abc/);
  10835. * // => false
  10836. */
  10837. function isFunction(value) {
  10838. // The use of `Object#toString` avoids issues with the `typeof` operator
  10839. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  10840. var tag = isObject(value) ? objectToString.call(value) : '';
  10841. return tag == funcTag || tag == genTag;
  10842. }
  10843. /**
  10844. * Checks if `value` is a valid array-like length.
  10845. *
  10846. * **Note:** This method is loosely based on
  10847. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10848. *
  10849. * @static
  10850. * @memberOf _
  10851. * @since 4.0.0
  10852. * @category Lang
  10853. * @param {*} value The value to check.
  10854. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10855. * @example
  10856. *
  10857. * _.isLength(3);
  10858. * // => true
  10859. *
  10860. * _.isLength(Number.MIN_VALUE);
  10861. * // => false
  10862. *
  10863. * _.isLength(Infinity);
  10864. * // => false
  10865. *
  10866. * _.isLength('3');
  10867. * // => false
  10868. */
  10869. function isLength(value) {
  10870. return typeof value == 'number' &&
  10871. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10872. }
  10873. /**
  10874. * Checks if `value` is the
  10875. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10876. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10877. *
  10878. * @static
  10879. * @memberOf _
  10880. * @since 0.1.0
  10881. * @category Lang
  10882. * @param {*} value The value to check.
  10883. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10884. * @example
  10885. *
  10886. * _.isObject({});
  10887. * // => true
  10888. *
  10889. * _.isObject([1, 2, 3]);
  10890. * // => true
  10891. *
  10892. * _.isObject(_.noop);
  10893. * // => true
  10894. *
  10895. * _.isObject(null);
  10896. * // => false
  10897. */
  10898. function isObject(value) {
  10899. var type = typeof value;
  10900. return !!value && (type == 'object' || type == 'function');
  10901. }
  10902. /**
  10903. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10904. * and has a `typeof` result of "object".
  10905. *
  10906. * @static
  10907. * @memberOf _
  10908. * @since 4.0.0
  10909. * @category Lang
  10910. * @param {*} value The value to check.
  10911. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10912. * @example
  10913. *
  10914. * _.isObjectLike({});
  10915. * // => true
  10916. *
  10917. * _.isObjectLike([1, 2, 3]);
  10918. * // => true
  10919. *
  10920. * _.isObjectLike(_.noop);
  10921. * // => false
  10922. *
  10923. * _.isObjectLike(null);
  10924. * // => false
  10925. */
  10926. function isObjectLike(value) {
  10927. return !!value && typeof value == 'object';
  10928. }
  10929. module.exports = isArguments;
  10930. },{}],77:[function(require,module,exports){
  10931. /**
  10932. * lodash 3.0.4 (Custom Build) <https://lodash.com/>
  10933. * Build: `lodash modern modularize exports="npm" -o ./`
  10934. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10935. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10936. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10937. * Available under MIT license <https://lodash.com/license>
  10938. */
  10939. /** `Object#toString` result references. */
  10940. var arrayTag = '[object Array]',
  10941. funcTag = '[object Function]';
  10942. /** Used to detect host constructors (Safari > 5). */
  10943. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  10944. /**
  10945. * Checks if `value` is object-like.
  10946. *
  10947. * @private
  10948. * @param {*} value The value to check.
  10949. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10950. */
  10951. function isObjectLike(value) {
  10952. return !!value && typeof value == 'object';
  10953. }
  10954. /** Used for native method references. */
  10955. var objectProto = Object.prototype;
  10956. /** Used to resolve the decompiled source of functions. */
  10957. var fnToString = Function.prototype.toString;
  10958. /** Used to check objects for own properties. */
  10959. var hasOwnProperty = objectProto.hasOwnProperty;
  10960. /**
  10961. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  10962. * of values.
  10963. */
  10964. var objToString = objectProto.toString;
  10965. /** Used to detect if a method is native. */
  10966. var reIsNative = RegExp('^' +
  10967. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  10968. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  10969. );
  10970. /* Native method references for those with the same name as other `lodash` methods. */
  10971. var nativeIsArray = getNative(Array, 'isArray');
  10972. /**
  10973. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  10974. * of an array-like value.
  10975. */
  10976. var MAX_SAFE_INTEGER = 9007199254740991;
  10977. /**
  10978. * Gets the native function at `key` of `object`.
  10979. *
  10980. * @private
  10981. * @param {Object} object The object to query.
  10982. * @param {string} key The key of the method to get.
  10983. * @returns {*} Returns the function if it's native, else `undefined`.
  10984. */
  10985. function getNative(object, key) {
  10986. var value = object == null ? undefined : object[key];
  10987. return isNative(value) ? value : undefined;
  10988. }
  10989. /**
  10990. * Checks if `value` is a valid array-like length.
  10991. *
  10992. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  10993. *
  10994. * @private
  10995. * @param {*} value The value to check.
  10996. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10997. */
  10998. function isLength(value) {
  10999. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  11000. }
  11001. /**
  11002. * Checks if `value` is classified as an `Array` object.
  11003. *
  11004. * @static
  11005. * @memberOf _
  11006. * @category Lang
  11007. * @param {*} value The value to check.
  11008. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  11009. * @example
  11010. *
  11011. * _.isArray([1, 2, 3]);
  11012. * // => true
  11013. *
  11014. * _.isArray(function() { return arguments; }());
  11015. * // => false
  11016. */
  11017. var isArray = nativeIsArray || function(value) {
  11018. return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
  11019. };
  11020. /**
  11021. * Checks if `value` is classified as a `Function` object.
  11022. *
  11023. * @static
  11024. * @memberOf _
  11025. * @category Lang
  11026. * @param {*} value The value to check.
  11027. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  11028. * @example
  11029. *
  11030. * _.isFunction(_);
  11031. * // => true
  11032. *
  11033. * _.isFunction(/abc/);
  11034. * // => false
  11035. */
  11036. function isFunction(value) {
  11037. // The use of `Object#toString` avoids issues with the `typeof` operator
  11038. // in older versions of Chrome and Safari which return 'function' for regexes
  11039. // and Safari 8 equivalents which return 'object' for typed array constructors.
  11040. return isObject(value) && objToString.call(value) == funcTag;
  11041. }
  11042. /**
  11043. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  11044. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  11045. *
  11046. * @static
  11047. * @memberOf _
  11048. * @category Lang
  11049. * @param {*} value The value to check.
  11050. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  11051. * @example
  11052. *
  11053. * _.isObject({});
  11054. * // => true
  11055. *
  11056. * _.isObject([1, 2, 3]);
  11057. * // => true
  11058. *
  11059. * _.isObject(1);
  11060. * // => false
  11061. */
  11062. function isObject(value) {
  11063. // Avoid a V8 JIT bug in Chrome 19-20.
  11064. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  11065. var type = typeof value;
  11066. return !!value && (type == 'object' || type == 'function');
  11067. }
  11068. /**
  11069. * Checks if `value` is a native function.
  11070. *
  11071. * @static
  11072. * @memberOf _
  11073. * @category Lang
  11074. * @param {*} value The value to check.
  11075. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  11076. * @example
  11077. *
  11078. * _.isNative(Array.prototype.push);
  11079. * // => true
  11080. *
  11081. * _.isNative(_);
  11082. * // => false
  11083. */
  11084. function isNative(value) {
  11085. if (value == null) {
  11086. return false;
  11087. }
  11088. if (isFunction(value)) {
  11089. return reIsNative.test(fnToString.call(value));
  11090. }
  11091. return isObjectLike(value) && reIsHostCtor.test(value);
  11092. }
  11093. module.exports = isArray;
  11094. },{}],78:[function(require,module,exports){
  11095. /**
  11096. * lodash 3.1.2 (Custom Build) <https://lodash.com/>
  11097. * Build: `lodash modern modularize exports="npm" -o ./`
  11098. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  11099. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  11100. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  11101. * Available under MIT license <https://lodash.com/license>
  11102. */
  11103. var getNative = require('lodash._getnative'),
  11104. isArguments = require('lodash.isarguments'),
  11105. isArray = require('lodash.isarray');
  11106. /** Used to detect unsigned integer values. */
  11107. var reIsUint = /^\d+$/;
  11108. /** Used for native method references. */
  11109. var objectProto = Object.prototype;
  11110. /** Used to check objects for own properties. */
  11111. var hasOwnProperty = objectProto.hasOwnProperty;
  11112. /* Native method references for those with the same name as other `lodash` methods. */
  11113. var nativeKeys = getNative(Object, 'keys');
  11114. /**
  11115. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  11116. * of an array-like value.
  11117. */
  11118. var MAX_SAFE_INTEGER = 9007199254740991;
  11119. /**
  11120. * The base implementation of `_.property` without support for deep paths.
  11121. *
  11122. * @private
  11123. * @param {string} key The key of the property to get.
  11124. * @returns {Function} Returns the new function.
  11125. */
  11126. function baseProperty(key) {
  11127. return function(object) {
  11128. return object == null ? undefined : object[key];
  11129. };
  11130. }
  11131. /**
  11132. * Gets the "length" property value of `object`.
  11133. *
  11134. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  11135. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  11136. *
  11137. * @private
  11138. * @param {Object} object The object to query.
  11139. * @returns {*} Returns the "length" value.
  11140. */
  11141. var getLength = baseProperty('length');
  11142. /**
  11143. * Checks if `value` is array-like.
  11144. *
  11145. * @private
  11146. * @param {*} value The value to check.
  11147. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  11148. */
  11149. function isArrayLike(value) {
  11150. return value != null && isLength(getLength(value));
  11151. }
  11152. /**
  11153. * Checks if `value` is a valid array-like index.
  11154. *
  11155. * @private
  11156. * @param {*} value The value to check.
  11157. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  11158. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  11159. */
  11160. function isIndex(value, length) {
  11161. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  11162. length = length == null ? MAX_SAFE_INTEGER : length;
  11163. return value > -1 && value % 1 == 0 && value < length;
  11164. }
  11165. /**
  11166. * Checks if `value` is a valid array-like length.
  11167. *
  11168. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  11169. *
  11170. * @private
  11171. * @param {*} value The value to check.
  11172. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  11173. */
  11174. function isLength(value) {
  11175. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  11176. }
  11177. /**
  11178. * A fallback implementation of `Object.keys` which creates an array of the
  11179. * own enumerable property names of `object`.
  11180. *
  11181. * @private
  11182. * @param {Object} object The object to query.
  11183. * @returns {Array} Returns the array of property names.
  11184. */
  11185. function shimKeys(object) {
  11186. var props = keysIn(object),
  11187. propsLength = props.length,
  11188. length = propsLength && object.length;
  11189. var allowIndexes = !!length && isLength(length) &&
  11190. (isArray(object) || isArguments(object));
  11191. var index = -1,
  11192. result = [];
  11193. while (++index < propsLength) {
  11194. var key = props[index];
  11195. if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
  11196. result.push(key);
  11197. }
  11198. }
  11199. return result;
  11200. }
  11201. /**
  11202. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  11203. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  11204. *
  11205. * @static
  11206. * @memberOf _
  11207. * @category Lang
  11208. * @param {*} value The value to check.
  11209. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  11210. * @example
  11211. *
  11212. * _.isObject({});
  11213. * // => true
  11214. *
  11215. * _.isObject([1, 2, 3]);
  11216. * // => true
  11217. *
  11218. * _.isObject(1);
  11219. * // => false
  11220. */
  11221. function isObject(value) {
  11222. // Avoid a V8 JIT bug in Chrome 19-20.
  11223. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  11224. var type = typeof value;
  11225. return !!value && (type == 'object' || type == 'function');
  11226. }
  11227. /**
  11228. * Creates an array of the own enumerable property names of `object`.
  11229. *
  11230. * **Note:** Non-object values are coerced to objects. See the
  11231. * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
  11232. * for more details.
  11233. *
  11234. * @static
  11235. * @memberOf _
  11236. * @category Object
  11237. * @param {Object} object The object to query.
  11238. * @returns {Array} Returns the array of property names.
  11239. * @example
  11240. *
  11241. * function Foo() {
  11242. * this.a = 1;
  11243. * this.b = 2;
  11244. * }
  11245. *
  11246. * Foo.prototype.c = 3;
  11247. *
  11248. * _.keys(new Foo);
  11249. * // => ['a', 'b'] (iteration order is not guaranteed)
  11250. *
  11251. * _.keys('hi');
  11252. * // => ['0', '1']
  11253. */
  11254. var keys = !nativeKeys ? shimKeys : function(object) {
  11255. var Ctor = object == null ? undefined : object.constructor;
  11256. if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
  11257. (typeof object != 'function' && isArrayLike(object))) {
  11258. return shimKeys(object);
  11259. }
  11260. return isObject(object) ? nativeKeys(object) : [];
  11261. };
  11262. /**
  11263. * Creates an array of the own and inherited enumerable property names of `object`.
  11264. *
  11265. * **Note:** Non-object values are coerced to objects.
  11266. *
  11267. * @static
  11268. * @memberOf _
  11269. * @category Object
  11270. * @param {Object} object The object to query.
  11271. * @returns {Array} Returns the array of property names.
  11272. * @example
  11273. *
  11274. * function Foo() {
  11275. * this.a = 1;
  11276. * this.b = 2;
  11277. * }
  11278. *
  11279. * Foo.prototype.c = 3;
  11280. *
  11281. * _.keysIn(new Foo);
  11282. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  11283. */
  11284. function keysIn(object) {
  11285. if (object == null) {
  11286. return [];
  11287. }
  11288. if (!isObject(object)) {
  11289. object = Object(object);
  11290. }
  11291. var length = object.length;
  11292. length = (length && isLength(length) &&
  11293. (isArray(object) || isArguments(object)) && length) || 0;
  11294. var Ctor = object.constructor,
  11295. index = -1,
  11296. isProto = typeof Ctor == 'function' && Ctor.prototype === object,
  11297. result = Array(length),
  11298. skipIndexes = length > 0;
  11299. while (++index < length) {
  11300. result[index] = (index + '');
  11301. }
  11302. for (var key in object) {
  11303. if (!(skipIndexes && isIndex(key, length)) &&
  11304. !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  11305. result.push(key);
  11306. }
  11307. }
  11308. return result;
  11309. }
  11310. module.exports = keys;
  11311. },{"lodash._getnative":73,"lodash.isarguments":76,"lodash.isarray":77}],79:[function(require,module,exports){
  11312. (function (process){
  11313. var path = require('path');
  11314. var fs = require('fs');
  11315. var _0777 = parseInt('0777', 8);
  11316. module.exports = mkdirP.mkdirp = mkdirP.mkdirP = mkdirP;
  11317. function mkdirP (p, opts, f, made) {
  11318. if (typeof opts === 'function') {
  11319. f = opts;
  11320. opts = {};
  11321. }
  11322. else if (!opts || typeof opts !== 'object') {
  11323. opts = { mode: opts };
  11324. }
  11325. var mode = opts.mode;
  11326. var xfs = opts.fs || fs;
  11327. if (mode === undefined) {
  11328. mode = _0777 & (~process.umask());
  11329. }
  11330. if (!made) made = null;
  11331. var cb = f || function () {};
  11332. p = path.resolve(p);
  11333. xfs.mkdir(p, mode, function (er) {
  11334. if (!er) {
  11335. made = made || p;
  11336. return cb(null, made);
  11337. }
  11338. switch (er.code) {
  11339. case 'ENOENT':
  11340. mkdirP(path.dirname(p), opts, function (er, made) {
  11341. if (er) cb(er, made);
  11342. else mkdirP(p, opts, cb, made);
  11343. });
  11344. break;
  11345. // In the case of any other error, just see if there's a dir
  11346. // there already. If so, then hooray! If not, then something
  11347. // is borked.
  11348. default:
  11349. xfs.stat(p, function (er2, stat) {
  11350. // if the stat fails, then that's super weird.
  11351. // let the original error be the failure reason.
  11352. if (er2 || !stat.isDirectory()) cb(er, made)
  11353. else cb(null, made);
  11354. });
  11355. break;
  11356. }
  11357. });
  11358. }
  11359. mkdirP.sync = function sync (p, opts, made) {
  11360. if (!opts || typeof opts !== 'object') {
  11361. opts = { mode: opts };
  11362. }
  11363. var mode = opts.mode;
  11364. var xfs = opts.fs || fs;
  11365. if (mode === undefined) {
  11366. mode = _0777 & (~process.umask());
  11367. }
  11368. if (!made) made = null;
  11369. p = path.resolve(p);
  11370. try {
  11371. xfs.mkdirSync(p, mode);
  11372. made = made || p;
  11373. }
  11374. catch (err0) {
  11375. switch (err0.code) {
  11376. case 'ENOENT' :
  11377. made = sync(path.dirname(p), opts, made);
  11378. sync(p, opts, made);
  11379. break;
  11380. // In the case of any other error, just see if there's a dir
  11381. // there already. If so, then hooray! If not, then something
  11382. // is borked.
  11383. default:
  11384. var stat;
  11385. try {
  11386. stat = xfs.statSync(p);
  11387. }
  11388. catch (err1) {
  11389. throw err0;
  11390. }
  11391. if (!stat.isDirectory()) throw err0;
  11392. break;
  11393. }
  11394. }
  11395. return made;
  11396. };
  11397. }).call(this,require('_process'))
  11398. },{"_process":82,"fs":42,"path":42}],80:[function(require,module,exports){
  11399. exports.endianness = function () { return 'LE' };
  11400. exports.hostname = function () {
  11401. if (typeof location !== 'undefined') {
  11402. return location.hostname
  11403. }
  11404. else return '';
  11405. };
  11406. exports.loadavg = function () { return [] };
  11407. exports.uptime = function () { return 0 };
  11408. exports.freemem = function () {
  11409. return Number.MAX_VALUE;
  11410. };
  11411. exports.totalmem = function () {
  11412. return Number.MAX_VALUE;
  11413. };
  11414. exports.cpus = function () { return [] };
  11415. exports.type = function () { return 'Browser' };
  11416. exports.release = function () {
  11417. if (typeof navigator !== 'undefined') {
  11418. return navigator.appVersion;
  11419. }
  11420. return '';
  11421. };
  11422. exports.networkInterfaces
  11423. = exports.getNetworkInterfaces
  11424. = function () { return {} };
  11425. exports.arch = function () { return 'javascript' };
  11426. exports.platform = function () { return 'browser' };
  11427. exports.tmpdir = exports.tmpDir = function () {
  11428. return '/tmp';
  11429. };
  11430. exports.EOL = '\n';
  11431. },{}],81:[function(require,module,exports){
  11432. (function (process){
  11433. 'use strict';
  11434. if (!process.version ||
  11435. process.version.indexOf('v0.') === 0 ||
  11436. process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
  11437. module.exports = nextTick;
  11438. } else {
  11439. module.exports = process.nextTick;
  11440. }
  11441. function nextTick(fn, arg1, arg2, arg3) {
  11442. if (typeof fn !== 'function') {
  11443. throw new TypeError('"callback" argument must be a function');
  11444. }
  11445. var len = arguments.length;
  11446. var args, i;
  11447. switch (len) {
  11448. case 0:
  11449. case 1:
  11450. return process.nextTick(fn);
  11451. case 2:
  11452. return process.nextTick(function afterTickOne() {
  11453. fn.call(null, arg1);
  11454. });
  11455. case 3:
  11456. return process.nextTick(function afterTickTwo() {
  11457. fn.call(null, arg1, arg2);
  11458. });
  11459. case 4:
  11460. return process.nextTick(function afterTickThree() {
  11461. fn.call(null, arg1, arg2, arg3);
  11462. });
  11463. default:
  11464. args = new Array(len - 1);
  11465. i = 0;
  11466. while (i < args.length) {
  11467. args[i++] = arguments[i];
  11468. }
  11469. return process.nextTick(function afterTick() {
  11470. fn.apply(null, args);
  11471. });
  11472. }
  11473. }
  11474. }).call(this,require('_process'))
  11475. },{"_process":82}],82:[function(require,module,exports){
  11476. // shim for using process in browser
  11477. var process = module.exports = {};
  11478. // cached from whatever global is present so that test runners that stub it
  11479. // don't break things. But we need to wrap it in a try catch in case it is
  11480. // wrapped in strict mode code which doesn't define any globals. It's inside a
  11481. // function because try/catches deoptimize in certain engines.
  11482. var cachedSetTimeout;
  11483. var cachedClearTimeout;
  11484. function defaultSetTimout() {
  11485. throw new Error('setTimeout has not been defined');
  11486. }
  11487. function defaultClearTimeout () {
  11488. throw new Error('clearTimeout has not been defined');
  11489. }
  11490. (function () {
  11491. try {
  11492. if (typeof setTimeout === 'function') {
  11493. cachedSetTimeout = setTimeout;
  11494. } else {
  11495. cachedSetTimeout = defaultSetTimout;
  11496. }
  11497. } catch (e) {
  11498. cachedSetTimeout = defaultSetTimout;
  11499. }
  11500. try {
  11501. if (typeof clearTimeout === 'function') {
  11502. cachedClearTimeout = clearTimeout;
  11503. } else {
  11504. cachedClearTimeout = defaultClearTimeout;
  11505. }
  11506. } catch (e) {
  11507. cachedClearTimeout = defaultClearTimeout;
  11508. }
  11509. } ())
  11510. function runTimeout(fun) {
  11511. if (cachedSetTimeout === setTimeout) {
  11512. //normal enviroments in sane situations
  11513. return setTimeout(fun, 0);
  11514. }
  11515. // if setTimeout wasn't available but was latter defined
  11516. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  11517. cachedSetTimeout = setTimeout;
  11518. return setTimeout(fun, 0);
  11519. }
  11520. try {
  11521. // when when somebody has screwed with setTimeout but no I.E. maddness
  11522. return cachedSetTimeout(fun, 0);
  11523. } catch(e){
  11524. try {
  11525. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  11526. return cachedSetTimeout.call(null, fun, 0);
  11527. } catch(e){
  11528. // 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
  11529. return cachedSetTimeout.call(this, fun, 0);
  11530. }
  11531. }
  11532. }
  11533. function runClearTimeout(marker) {
  11534. if (cachedClearTimeout === clearTimeout) {
  11535. //normal enviroments in sane situations
  11536. return clearTimeout(marker);
  11537. }
  11538. // if clearTimeout wasn't available but was latter defined
  11539. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  11540. cachedClearTimeout = clearTimeout;
  11541. return clearTimeout(marker);
  11542. }
  11543. try {
  11544. // when when somebody has screwed with setTimeout but no I.E. maddness
  11545. return cachedClearTimeout(marker);
  11546. } catch (e){
  11547. try {
  11548. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  11549. return cachedClearTimeout.call(null, marker);
  11550. } catch (e){
  11551. // 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.
  11552. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  11553. return cachedClearTimeout.call(this, marker);
  11554. }
  11555. }
  11556. }
  11557. var queue = [];
  11558. var draining = false;
  11559. var currentQueue;
  11560. var queueIndex = -1;
  11561. function cleanUpNextTick() {
  11562. if (!draining || !currentQueue) {
  11563. return;
  11564. }
  11565. draining = false;
  11566. if (currentQueue.length) {
  11567. queue = currentQueue.concat(queue);
  11568. } else {
  11569. queueIndex = -1;
  11570. }
  11571. if (queue.length) {
  11572. drainQueue();
  11573. }
  11574. }
  11575. function drainQueue() {
  11576. if (draining) {
  11577. return;
  11578. }
  11579. var timeout = runTimeout(cleanUpNextTick);
  11580. draining = true;
  11581. var len = queue.length;
  11582. while(len) {
  11583. currentQueue = queue;
  11584. queue = [];
  11585. while (++queueIndex < len) {
  11586. if (currentQueue) {
  11587. currentQueue[queueIndex].run();
  11588. }
  11589. }
  11590. queueIndex = -1;
  11591. len = queue.length;
  11592. }
  11593. currentQueue = null;
  11594. draining = false;
  11595. runClearTimeout(timeout);
  11596. }
  11597. process.nextTick = function (fun) {
  11598. var args = new Array(arguments.length - 1);
  11599. if (arguments.length > 1) {
  11600. for (var i = 1; i < arguments.length; i++) {
  11601. args[i - 1] = arguments[i];
  11602. }
  11603. }
  11604. queue.push(new Item(fun, args));
  11605. if (queue.length === 1 && !draining) {
  11606. runTimeout(drainQueue);
  11607. }
  11608. };
  11609. // v8 likes predictible objects
  11610. function Item(fun, array) {
  11611. this.fun = fun;
  11612. this.array = array;
  11613. }
  11614. Item.prototype.run = function () {
  11615. this.fun.apply(null, this.array);
  11616. };
  11617. process.title = 'browser';
  11618. process.browser = true;
  11619. process.env = {};
  11620. process.argv = [];
  11621. process.version = ''; // empty string to avoid regexp issues
  11622. process.versions = {};
  11623. function noop() {}
  11624. process.on = noop;
  11625. process.addListener = noop;
  11626. process.once = noop;
  11627. process.off = noop;
  11628. process.removeListener = noop;
  11629. process.removeAllListeners = noop;
  11630. process.emit = noop;
  11631. process.binding = function (name) {
  11632. throw new Error('process.binding is not supported');
  11633. };
  11634. process.cwd = function () { return '/' };
  11635. process.chdir = function (dir) {
  11636. throw new Error('process.chdir is not supported');
  11637. };
  11638. process.umask = function() { return 0; };
  11639. },{}],83:[function(require,module,exports){
  11640. module.exports = require("./lib/_stream_duplex.js")
  11641. },{"./lib/_stream_duplex.js":84}],84:[function(require,module,exports){
  11642. // a duplex stream is just a stream that is both readable and writable.
  11643. // Since JS doesn't have multiple prototypal inheritance, this class
  11644. // prototypally inherits from Readable, and then parasitically from
  11645. // Writable.
  11646. 'use strict';
  11647. /*<replacement>*/
  11648. var objectKeys = Object.keys || function (obj) {
  11649. var keys = [];
  11650. for (var key in obj) {
  11651. keys.push(key);
  11652. }return keys;
  11653. };
  11654. /*</replacement>*/
  11655. module.exports = Duplex;
  11656. /*<replacement>*/
  11657. var processNextTick = require('process-nextick-args');
  11658. /*</replacement>*/
  11659. /*<replacement>*/
  11660. var util = require('core-util-is');
  11661. util.inherits = require('inherits');
  11662. /*</replacement>*/
  11663. var Readable = require('./_stream_readable');
  11664. var Writable = require('./_stream_writable');
  11665. util.inherits(Duplex, Readable);
  11666. var keys = objectKeys(Writable.prototype);
  11667. for (var v = 0; v < keys.length; v++) {
  11668. var method = keys[v];
  11669. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  11670. }
  11671. function Duplex(options) {
  11672. if (!(this instanceof Duplex)) return new Duplex(options);
  11673. Readable.call(this, options);
  11674. Writable.call(this, options);
  11675. if (options && options.readable === false) this.readable = false;
  11676. if (options && options.writable === false) this.writable = false;
  11677. this.allowHalfOpen = true;
  11678. if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
  11679. this.once('end', onend);
  11680. }
  11681. // the no-half-open enforcer
  11682. function onend() {
  11683. // if we allow half-open state, or if the writable side ended,
  11684. // then we're ok.
  11685. if (this.allowHalfOpen || this._writableState.ended) return;
  11686. // no more data can be written.
  11687. // But allow more writes to happen in this tick.
  11688. processNextTick(onEndNT, this);
  11689. }
  11690. function onEndNT(self) {
  11691. self.end();
  11692. }
  11693. function forEach(xs, f) {
  11694. for (var i = 0, l = xs.length; i < l; i++) {
  11695. f(xs[i], i);
  11696. }
  11697. }
  11698. },{"./_stream_readable":86,"./_stream_writable":88,"core-util-is":45,"inherits":66,"process-nextick-args":81}],85:[function(require,module,exports){
  11699. // a passthrough stream.
  11700. // basically just the most minimal sort of Transform stream.
  11701. // Every written chunk gets output as-is.
  11702. 'use strict';
  11703. module.exports = PassThrough;
  11704. var Transform = require('./_stream_transform');
  11705. /*<replacement>*/
  11706. var util = require('core-util-is');
  11707. util.inherits = require('inherits');
  11708. /*</replacement>*/
  11709. util.inherits(PassThrough, Transform);
  11710. function PassThrough(options) {
  11711. if (!(this instanceof PassThrough)) return new PassThrough(options);
  11712. Transform.call(this, options);
  11713. }
  11714. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  11715. cb(null, chunk);
  11716. };
  11717. },{"./_stream_transform":87,"core-util-is":45,"inherits":66}],86:[function(require,module,exports){
  11718. (function (process){
  11719. 'use strict';
  11720. module.exports = Readable;
  11721. /*<replacement>*/
  11722. var processNextTick = require('process-nextick-args');
  11723. /*</replacement>*/
  11724. /*<replacement>*/
  11725. var isArray = require('isarray');
  11726. /*</replacement>*/
  11727. Readable.ReadableState = ReadableState;
  11728. /*<replacement>*/
  11729. var EE = require('events').EventEmitter;
  11730. var EElistenerCount = function (emitter, type) {
  11731. return emitter.listeners(type).length;
  11732. };
  11733. /*</replacement>*/
  11734. /*<replacement>*/
  11735. var Stream;
  11736. (function () {
  11737. try {
  11738. Stream = require('st' + 'ream');
  11739. } catch (_) {} finally {
  11740. if (!Stream) Stream = require('events').EventEmitter;
  11741. }
  11742. })();
  11743. /*</replacement>*/
  11744. var Buffer = require('buffer').Buffer;
  11745. /*<replacement>*/
  11746. var bufferShim = require('buffer-shims');
  11747. /*</replacement>*/
  11748. /*<replacement>*/
  11749. var util = require('core-util-is');
  11750. util.inherits = require('inherits');
  11751. /*</replacement>*/
  11752. /*<replacement>*/
  11753. var debugUtil = require('util');
  11754. var debug = void 0;
  11755. if (debugUtil && debugUtil.debuglog) {
  11756. debug = debugUtil.debuglog('stream');
  11757. } else {
  11758. debug = function () {};
  11759. }
  11760. /*</replacement>*/
  11761. var BufferList = require('./internal/streams/BufferList');
  11762. var StringDecoder;
  11763. util.inherits(Readable, Stream);
  11764. function prependListener(emitter, event, fn) {
  11765. if (typeof emitter.prependListener === 'function') {
  11766. return emitter.prependListener(event, fn);
  11767. } else {
  11768. // This is a hack to make sure that our error handler is attached before any
  11769. // userland ones. NEVER DO THIS. This is here only because this code needs
  11770. // to continue to work with older versions of Node.js that do not include
  11771. // the prependListener() method. The goal is to eventually remove this hack.
  11772. 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]];
  11773. }
  11774. }
  11775. var Duplex;
  11776. function ReadableState(options, stream) {
  11777. Duplex = Duplex || require('./_stream_duplex');
  11778. options = options || {};
  11779. // object stream flag. Used to make read(n) ignore n and to
  11780. // make all the buffer merging and length checks go away
  11781. this.objectMode = !!options.objectMode;
  11782. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
  11783. // the point at which it stops calling _read() to fill the buffer
  11784. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  11785. var hwm = options.highWaterMark;
  11786. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  11787. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  11788. // cast to ints.
  11789. this.highWaterMark = ~ ~this.highWaterMark;
  11790. // A linked list is used to store data chunks instead of an array because the
  11791. // linked list can remove elements from the beginning faster than
  11792. // array.shift()
  11793. this.buffer = new BufferList();
  11794. this.length = 0;
  11795. this.pipes = null;
  11796. this.pipesCount = 0;
  11797. this.flowing = null;
  11798. this.ended = false;
  11799. this.endEmitted = false;
  11800. this.reading = false;
  11801. // a flag to be able to tell if the onwrite cb is called immediately,
  11802. // or on a later tick. We set this to true at first, because any
  11803. // actions that shouldn't happen until "later" should generally also
  11804. // not happen before the first write call.
  11805. this.sync = true;
  11806. // whenever we return null, then we set a flag to say
  11807. // that we're awaiting a 'readable' event emission.
  11808. this.needReadable = false;
  11809. this.emittedReadable = false;
  11810. this.readableListening = false;
  11811. this.resumeScheduled = false;
  11812. // Crypto is kind of old and crusty. Historically, its default string
  11813. // encoding is 'binary' so we have to make this configurable.
  11814. // Everything else in the universe uses 'utf8', though.
  11815. this.defaultEncoding = options.defaultEncoding || 'utf8';
  11816. // when piping, we only care about 'readable' events that happen
  11817. // after read()ing all the bytes and not getting any pushback.
  11818. this.ranOut = false;
  11819. // the number of writers that are awaiting a drain event in .pipe()s
  11820. this.awaitDrain = 0;
  11821. // if true, a maybeReadMore has been scheduled
  11822. this.readingMore = false;
  11823. this.decoder = null;
  11824. this.encoding = null;
  11825. if (options.encoding) {
  11826. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  11827. this.decoder = new StringDecoder(options.encoding);
  11828. this.encoding = options.encoding;
  11829. }
  11830. }
  11831. var Duplex;
  11832. function Readable(options) {
  11833. Duplex = Duplex || require('./_stream_duplex');
  11834. if (!(this instanceof Readable)) return new Readable(options);
  11835. this._readableState = new ReadableState(options, this);
  11836. // legacy
  11837. this.readable = true;
  11838. if (options && typeof options.read === 'function') this._read = options.read;
  11839. Stream.call(this);
  11840. }
  11841. // Manually shove something into the read() buffer.
  11842. // This returns true if the highWaterMark has not been hit yet,
  11843. // similar to how Writable.write() returns true if you should
  11844. // write() some more.
  11845. Readable.prototype.push = function (chunk, encoding) {
  11846. var state = this._readableState;
  11847. if (!state.objectMode && typeof chunk === 'string') {
  11848. encoding = encoding || state.defaultEncoding;
  11849. if (encoding !== state.encoding) {
  11850. chunk = bufferShim.from(chunk, encoding);
  11851. encoding = '';
  11852. }
  11853. }
  11854. return readableAddChunk(this, state, chunk, encoding, false);
  11855. };
  11856. // Unshift should *always* be something directly out of read()
  11857. Readable.prototype.unshift = function (chunk) {
  11858. var state = this._readableState;
  11859. return readableAddChunk(this, state, chunk, '', true);
  11860. };
  11861. Readable.prototype.isPaused = function () {
  11862. return this._readableState.flowing === false;
  11863. };
  11864. function readableAddChunk(stream, state, chunk, encoding, addToFront) {
  11865. var er = chunkInvalid(state, chunk);
  11866. if (er) {
  11867. stream.emit('error', er);
  11868. } else if (chunk === null) {
  11869. state.reading = false;
  11870. onEofChunk(stream, state);
  11871. } else if (state.objectMode || chunk && chunk.length > 0) {
  11872. if (state.ended && !addToFront) {
  11873. var e = new Error('stream.push() after EOF');
  11874. stream.emit('error', e);
  11875. } else if (state.endEmitted && addToFront) {
  11876. var _e = new Error('stream.unshift() after end event');
  11877. stream.emit('error', _e);
  11878. } else {
  11879. var skipAdd;
  11880. if (state.decoder && !addToFront && !encoding) {
  11881. chunk = state.decoder.write(chunk);
  11882. skipAdd = !state.objectMode && chunk.length === 0;
  11883. }
  11884. if (!addToFront) state.reading = false;
  11885. // Don't add to the buffer if we've decoded to an empty string chunk and
  11886. // we're not in object mode
  11887. if (!skipAdd) {
  11888. // if we want the data now, just emit it.
  11889. if (state.flowing && state.length === 0 && !state.sync) {
  11890. stream.emit('data', chunk);
  11891. stream.read(0);
  11892. } else {
  11893. // update the buffer info.
  11894. state.length += state.objectMode ? 1 : chunk.length;
  11895. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  11896. if (state.needReadable) emitReadable(stream);
  11897. }
  11898. }
  11899. maybeReadMore(stream, state);
  11900. }
  11901. } else if (!addToFront) {
  11902. state.reading = false;
  11903. }
  11904. return needMoreData(state);
  11905. }
  11906. // if it's past the high water mark, we can push in some more.
  11907. // Also, if we have no data yet, we can stand some
  11908. // more bytes. This is to work around cases where hwm=0,
  11909. // such as the repl. Also, if the push() triggered a
  11910. // readable event, and the user called read(largeNumber) such that
  11911. // needReadable was set, then we ought to push more, so that another
  11912. // 'readable' event will be triggered.
  11913. function needMoreData(state) {
  11914. return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
  11915. }
  11916. // backwards compatibility.
  11917. Readable.prototype.setEncoding = function (enc) {
  11918. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  11919. this._readableState.decoder = new StringDecoder(enc);
  11920. this._readableState.encoding = enc;
  11921. return this;
  11922. };
  11923. // Don't raise the hwm > 8MB
  11924. var MAX_HWM = 0x800000;
  11925. function computeNewHighWaterMark(n) {
  11926. if (n >= MAX_HWM) {
  11927. n = MAX_HWM;
  11928. } else {
  11929. // Get the next highest power of 2 to prevent increasing hwm excessively in
  11930. // tiny amounts
  11931. n--;
  11932. n |= n >>> 1;
  11933. n |= n >>> 2;
  11934. n |= n >>> 4;
  11935. n |= n >>> 8;
  11936. n |= n >>> 16;
  11937. n++;
  11938. }
  11939. return n;
  11940. }
  11941. // This function is designed to be inlinable, so please take care when making
  11942. // changes to the function body.
  11943. function howMuchToRead(n, state) {
  11944. if (n <= 0 || state.length === 0 && state.ended) return 0;
  11945. if (state.objectMode) return 1;
  11946. if (n !== n) {
  11947. // Only flow one buffer at a time
  11948. if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
  11949. }
  11950. // If we're asking for more than the current hwm, then raise the hwm.
  11951. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  11952. if (n <= state.length) return n;
  11953. // Don't have enough
  11954. if (!state.ended) {
  11955. state.needReadable = true;
  11956. return 0;
  11957. }
  11958. return state.length;
  11959. }
  11960. // you can override either this method, or the async _read(n) below.
  11961. Readable.prototype.read = function (n) {
  11962. debug('read', n);
  11963. n = parseInt(n, 10);
  11964. var state = this._readableState;
  11965. var nOrig = n;
  11966. if (n !== 0) state.emittedReadable = false;
  11967. // if we're doing read(0) to trigger a readable event, but we
  11968. // already have a bunch of data in the buffer, then just trigger
  11969. // the 'readable' event and move on.
  11970. if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
  11971. debug('read: emitReadable', state.length, state.ended);
  11972. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  11973. return null;
  11974. }
  11975. n = howMuchToRead(n, state);
  11976. // if we've ended, and we're now clear, then finish it up.
  11977. if (n === 0 && state.ended) {
  11978. if (state.length === 0) endReadable(this);
  11979. return null;
  11980. }
  11981. // All the actual chunk generation logic needs to be
  11982. // *below* the call to _read. The reason is that in certain
  11983. // synthetic stream cases, such as passthrough streams, _read
  11984. // may be a completely synchronous operation which may change
  11985. // the state of the read buffer, providing enough data when
  11986. // before there was *not* enough.
  11987. //
  11988. // So, the steps are:
  11989. // 1. Figure out what the state of things will be after we do
  11990. // a read from the buffer.
  11991. //
  11992. // 2. If that resulting state will trigger a _read, then call _read.
  11993. // Note that this may be asynchronous, or synchronous. Yes, it is
  11994. // deeply ugly to write APIs this way, but that still doesn't mean
  11995. // that the Readable class should behave improperly, as streams are
  11996. // designed to be sync/async agnostic.
  11997. // Take note if the _read call is sync or async (ie, if the read call
  11998. // has returned yet), so that we know whether or not it's safe to emit
  11999. // 'readable' etc.
  12000. //
  12001. // 3. Actually pull the requested chunks out of the buffer and return.
  12002. // if we need a readable event, then we need to do some reading.
  12003. var doRead = state.needReadable;
  12004. debug('need readable', doRead);
  12005. // if we currently have less than the highWaterMark, then also read some
  12006. if (state.length === 0 || state.length - n < state.highWaterMark) {
  12007. doRead = true;
  12008. debug('length less than watermark', doRead);
  12009. }
  12010. // however, if we've ended, then there's no point, and if we're already
  12011. // reading, then it's unnecessary.
  12012. if (state.ended || state.reading) {
  12013. doRead = false;
  12014. debug('reading or ended', doRead);
  12015. } else if (doRead) {
  12016. debug('do read');
  12017. state.reading = true;
  12018. state.sync = true;
  12019. // if the length is currently zero, then we *need* a readable event.
  12020. if (state.length === 0) state.needReadable = true;
  12021. // call internal read method
  12022. this._read(state.highWaterMark);
  12023. state.sync = false;
  12024. // If _read pushed data synchronously, then `reading` will be false,
  12025. // and we need to re-evaluate how much data we can return to the user.
  12026. if (!state.reading) n = howMuchToRead(nOrig, state);
  12027. }
  12028. var ret;
  12029. if (n > 0) ret = fromList(n, state);else ret = null;
  12030. if (ret === null) {
  12031. state.needReadable = true;
  12032. n = 0;
  12033. } else {
  12034. state.length -= n;
  12035. }
  12036. if (state.length === 0) {
  12037. // If we have nothing in the buffer, then we want to know
  12038. // as soon as we *do* get something into the buffer.
  12039. if (!state.ended) state.needReadable = true;
  12040. // If we tried to read() past the EOF, then emit end on the next tick.
  12041. if (nOrig !== n && state.ended) endReadable(this);
  12042. }
  12043. if (ret !== null) this.emit('data', ret);
  12044. return ret;
  12045. };
  12046. function chunkInvalid(state, chunk) {
  12047. var er = null;
  12048. if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
  12049. er = new TypeError('Invalid non-string/buffer chunk');
  12050. }
  12051. return er;
  12052. }
  12053. function onEofChunk(stream, state) {
  12054. if (state.ended) return;
  12055. if (state.decoder) {
  12056. var chunk = state.decoder.end();
  12057. if (chunk && chunk.length) {
  12058. state.buffer.push(chunk);
  12059. state.length += state.objectMode ? 1 : chunk.length;
  12060. }
  12061. }
  12062. state.ended = true;
  12063. // emit 'readable' now to make sure it gets picked up.
  12064. emitReadable(stream);
  12065. }
  12066. // Don't emit readable right away in sync mode, because this can trigger
  12067. // another read() call => stack overflow. This way, it might trigger
  12068. // a nextTick recursion warning, but that's not so bad.
  12069. function emitReadable(stream) {
  12070. var state = stream._readableState;
  12071. state.needReadable = false;
  12072. if (!state.emittedReadable) {
  12073. debug('emitReadable', state.flowing);
  12074. state.emittedReadable = true;
  12075. if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream);
  12076. }
  12077. }
  12078. function emitReadable_(stream) {
  12079. debug('emit readable');
  12080. stream.emit('readable');
  12081. flow(stream);
  12082. }
  12083. // at this point, the user has presumably seen the 'readable' event,
  12084. // and called read() to consume some data. that may have triggered
  12085. // in turn another _read(n) call, in which case reading = true if
  12086. // it's in progress.
  12087. // However, if we're not ended, or reading, and the length < hwm,
  12088. // then go ahead and try to read some more preemptively.
  12089. function maybeReadMore(stream, state) {
  12090. if (!state.readingMore) {
  12091. state.readingMore = true;
  12092. processNextTick(maybeReadMore_, stream, state);
  12093. }
  12094. }
  12095. function maybeReadMore_(stream, state) {
  12096. var len = state.length;
  12097. while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
  12098. debug('maybeReadMore read 0');
  12099. stream.read(0);
  12100. if (len === state.length)
  12101. // didn't get any data, stop spinning.
  12102. break;else len = state.length;
  12103. }
  12104. state.readingMore = false;
  12105. }
  12106. // abstract method. to be overridden in specific implementation classes.
  12107. // call cb(er, data) where data is <= n in length.
  12108. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  12109. // arbitrary, and perhaps not very meaningful.
  12110. Readable.prototype._read = function (n) {
  12111. this.emit('error', new Error('not implemented'));
  12112. };
  12113. Readable.prototype.pipe = function (dest, pipeOpts) {
  12114. var src = this;
  12115. var state = this._readableState;
  12116. switch (state.pipesCount) {
  12117. case 0:
  12118. state.pipes = dest;
  12119. break;
  12120. case 1:
  12121. state.pipes = [state.pipes, dest];
  12122. break;
  12123. default:
  12124. state.pipes.push(dest);
  12125. break;
  12126. }
  12127. state.pipesCount += 1;
  12128. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  12129. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  12130. var endFn = doEnd ? onend : cleanup;
  12131. if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn);
  12132. dest.on('unpipe', onunpipe);
  12133. function onunpipe(readable) {
  12134. debug('onunpipe');
  12135. if (readable === src) {
  12136. cleanup();
  12137. }
  12138. }
  12139. function onend() {
  12140. debug('onend');
  12141. dest.end();
  12142. }
  12143. // when the dest drains, it reduces the awaitDrain counter
  12144. // on the source. This would be more elegant with a .once()
  12145. // handler in flow(), but adding and removing repeatedly is
  12146. // too slow.
  12147. var ondrain = pipeOnDrain(src);
  12148. dest.on('drain', ondrain);
  12149. var cleanedUp = false;
  12150. function cleanup() {
  12151. debug('cleanup');
  12152. // cleanup event handlers once the pipe is broken
  12153. dest.removeListener('close', onclose);
  12154. dest.removeListener('finish', onfinish);
  12155. dest.removeListener('drain', ondrain);
  12156. dest.removeListener('error', onerror);
  12157. dest.removeListener('unpipe', onunpipe);
  12158. src.removeListener('end', onend);
  12159. src.removeListener('end', cleanup);
  12160. src.removeListener('data', ondata);
  12161. cleanedUp = true;
  12162. // if the reader is waiting for a drain event from this
  12163. // specific writer, then it would cause it to never start
  12164. // flowing again.
  12165. // So, if this is awaiting a drain, then we just call it now.
  12166. // If we don't know, then assume that we are waiting for one.
  12167. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  12168. }
  12169. // If the user pushes more data while we're writing to dest then we'll end up
  12170. // in ondata again. However, we only want to increase awaitDrain once because
  12171. // dest will only emit one 'drain' event for the multiple writes.
  12172. // => Introduce a guard on increasing awaitDrain.
  12173. var increasedAwaitDrain = false;
  12174. src.on('data', ondata);
  12175. function ondata(chunk) {
  12176. debug('ondata');
  12177. increasedAwaitDrain = false;
  12178. var ret = dest.write(chunk);
  12179. if (false === ret && !increasedAwaitDrain) {
  12180. // If the user unpiped during `dest.write()`, it is possible
  12181. // to get stuck in a permanently paused state if that write
  12182. // also returned false.
  12183. // => Check whether `dest` is still a piping destination.
  12184. if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  12185. debug('false write response, pause', src._readableState.awaitDrain);
  12186. src._readableState.awaitDrain++;
  12187. increasedAwaitDrain = true;
  12188. }
  12189. src.pause();
  12190. }
  12191. }
  12192. // if the dest has an error, then stop piping into it.
  12193. // however, don't suppress the throwing behavior for this.
  12194. function onerror(er) {
  12195. debug('onerror', er);
  12196. unpipe();
  12197. dest.removeListener('error', onerror);
  12198. if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
  12199. }
  12200. // Make sure our error handler is attached before userland ones.
  12201. prependListener(dest, 'error', onerror);
  12202. // Both close and finish should trigger unpipe, but only once.
  12203. function onclose() {
  12204. dest.removeListener('finish', onfinish);
  12205. unpipe();
  12206. }
  12207. dest.once('close', onclose);
  12208. function onfinish() {
  12209. debug('onfinish');
  12210. dest.removeListener('close', onclose);
  12211. unpipe();
  12212. }
  12213. dest.once('finish', onfinish);
  12214. function unpipe() {
  12215. debug('unpipe');
  12216. src.unpipe(dest);
  12217. }
  12218. // tell the dest that it's being piped to
  12219. dest.emit('pipe', src);
  12220. // start the flow if it hasn't been started already.
  12221. if (!state.flowing) {
  12222. debug('pipe resume');
  12223. src.resume();
  12224. }
  12225. return dest;
  12226. };
  12227. function pipeOnDrain(src) {
  12228. return function () {
  12229. var state = src._readableState;
  12230. debug('pipeOnDrain', state.awaitDrain);
  12231. if (state.awaitDrain) state.awaitDrain--;
  12232. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  12233. state.flowing = true;
  12234. flow(src);
  12235. }
  12236. };
  12237. }
  12238. Readable.prototype.unpipe = function (dest) {
  12239. var state = this._readableState;
  12240. // if we're not piping anywhere, then do nothing.
  12241. if (state.pipesCount === 0) return this;
  12242. // just one destination. most common case.
  12243. if (state.pipesCount === 1) {
  12244. // passed in one, but it's not the right one.
  12245. if (dest && dest !== state.pipes) return this;
  12246. if (!dest) dest = state.pipes;
  12247. // got a match.
  12248. state.pipes = null;
  12249. state.pipesCount = 0;
  12250. state.flowing = false;
  12251. if (dest) dest.emit('unpipe', this);
  12252. return this;
  12253. }
  12254. // slow case. multiple pipe destinations.
  12255. if (!dest) {
  12256. // remove all.
  12257. var dests = state.pipes;
  12258. var len = state.pipesCount;
  12259. state.pipes = null;
  12260. state.pipesCount = 0;
  12261. state.flowing = false;
  12262. for (var _i = 0; _i < len; _i++) {
  12263. dests[_i].emit('unpipe', this);
  12264. }return this;
  12265. }
  12266. // try to find the right one.
  12267. var i = indexOf(state.pipes, dest);
  12268. if (i === -1) return this;
  12269. state.pipes.splice(i, 1);
  12270. state.pipesCount -= 1;
  12271. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  12272. dest.emit('unpipe', this);
  12273. return this;
  12274. };
  12275. // set up data events if they are asked for
  12276. // Ensure readable listeners eventually get something
  12277. Readable.prototype.on = function (ev, fn) {
  12278. var res = Stream.prototype.on.call(this, ev, fn);
  12279. if (ev === 'data') {
  12280. // Start flowing on next tick if stream isn't explicitly paused
  12281. if (this._readableState.flowing !== false) this.resume();
  12282. } else if (ev === 'readable') {
  12283. var state = this._readableState;
  12284. if (!state.endEmitted && !state.readableListening) {
  12285. state.readableListening = state.needReadable = true;
  12286. state.emittedReadable = false;
  12287. if (!state.reading) {
  12288. processNextTick(nReadingNextTick, this);
  12289. } else if (state.length) {
  12290. emitReadable(this, state);
  12291. }
  12292. }
  12293. }
  12294. return res;
  12295. };
  12296. Readable.prototype.addListener = Readable.prototype.on;
  12297. function nReadingNextTick(self) {
  12298. debug('readable nexttick read 0');
  12299. self.read(0);
  12300. }
  12301. // pause() and resume() are remnants of the legacy readable stream API
  12302. // If the user uses them, then switch into old mode.
  12303. Readable.prototype.resume = function () {
  12304. var state = this._readableState;
  12305. if (!state.flowing) {
  12306. debug('resume');
  12307. state.flowing = true;
  12308. resume(this, state);
  12309. }
  12310. return this;
  12311. };
  12312. function resume(stream, state) {
  12313. if (!state.resumeScheduled) {
  12314. state.resumeScheduled = true;
  12315. processNextTick(resume_, stream, state);
  12316. }
  12317. }
  12318. function resume_(stream, state) {
  12319. if (!state.reading) {
  12320. debug('resume read 0');
  12321. stream.read(0);
  12322. }
  12323. state.resumeScheduled = false;
  12324. state.awaitDrain = 0;
  12325. stream.emit('resume');
  12326. flow(stream);
  12327. if (state.flowing && !state.reading) stream.read(0);
  12328. }
  12329. Readable.prototype.pause = function () {
  12330. debug('call pause flowing=%j', this._readableState.flowing);
  12331. if (false !== this._readableState.flowing) {
  12332. debug('pause');
  12333. this._readableState.flowing = false;
  12334. this.emit('pause');
  12335. }
  12336. return this;
  12337. };
  12338. function flow(stream) {
  12339. var state = stream._readableState;
  12340. debug('flow', state.flowing);
  12341. while (state.flowing && stream.read() !== null) {}
  12342. }
  12343. // wrap an old-style stream as the async data source.
  12344. // This is *not* part of the readable stream interface.
  12345. // It is an ugly unfortunate mess of history.
  12346. Readable.prototype.wrap = function (stream) {
  12347. var state = this._readableState;
  12348. var paused = false;
  12349. var self = this;
  12350. stream.on('end', function () {
  12351. debug('wrapped end');
  12352. if (state.decoder && !state.ended) {
  12353. var chunk = state.decoder.end();
  12354. if (chunk && chunk.length) self.push(chunk);
  12355. }
  12356. self.push(null);
  12357. });
  12358. stream.on('data', function (chunk) {
  12359. debug('wrapped data');
  12360. if (state.decoder) chunk = state.decoder.write(chunk);
  12361. // don't skip over falsy values in objectMode
  12362. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  12363. var ret = self.push(chunk);
  12364. if (!ret) {
  12365. paused = true;
  12366. stream.pause();
  12367. }
  12368. });
  12369. // proxy all the other methods.
  12370. // important when wrapping filters and duplexes.
  12371. for (var i in stream) {
  12372. if (this[i] === undefined && typeof stream[i] === 'function') {
  12373. this[i] = function (method) {
  12374. return function () {
  12375. return stream[method].apply(stream, arguments);
  12376. };
  12377. }(i);
  12378. }
  12379. }
  12380. // proxy certain important events.
  12381. var events = ['error', 'close', 'destroy', 'pause', 'resume'];
  12382. forEach(events, function (ev) {
  12383. stream.on(ev, self.emit.bind(self, ev));
  12384. });
  12385. // when we try to consume some more bytes, simply unpause the
  12386. // underlying stream.
  12387. self._read = function (n) {
  12388. debug('wrapped _read', n);
  12389. if (paused) {
  12390. paused = false;
  12391. stream.resume();
  12392. }
  12393. };
  12394. return self;
  12395. };
  12396. // exposed for testing purposes only.
  12397. Readable._fromList = fromList;
  12398. // Pluck off n bytes from an array of buffers.
  12399. // Length is the combined lengths of all the buffers in the list.
  12400. // This function is designed to be inlinable, so please take care when making
  12401. // changes to the function body.
  12402. function fromList(n, state) {
  12403. // nothing buffered
  12404. if (state.length === 0) return null;
  12405. var ret;
  12406. if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
  12407. // read it all, truncate the list
  12408. 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);
  12409. state.buffer.clear();
  12410. } else {
  12411. // read part of list
  12412. ret = fromListPartial(n, state.buffer, state.decoder);
  12413. }
  12414. return ret;
  12415. }
  12416. // Extracts only enough buffered data to satisfy the amount requested.
  12417. // This function is designed to be inlinable, so please take care when making
  12418. // changes to the function body.
  12419. function fromListPartial(n, list, hasStrings) {
  12420. var ret;
  12421. if (n < list.head.data.length) {
  12422. // slice is the same for buffers and strings
  12423. ret = list.head.data.slice(0, n);
  12424. list.head.data = list.head.data.slice(n);
  12425. } else if (n === list.head.data.length) {
  12426. // first chunk is a perfect match
  12427. ret = list.shift();
  12428. } else {
  12429. // result spans more than one buffer
  12430. ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
  12431. }
  12432. return ret;
  12433. }
  12434. // Copies a specified amount of characters from the list of buffered data
  12435. // chunks.
  12436. // This function is designed to be inlinable, so please take care when making
  12437. // changes to the function body.
  12438. function copyFromBufferString(n, list) {
  12439. var p = list.head;
  12440. var c = 1;
  12441. var ret = p.data;
  12442. n -= ret.length;
  12443. while (p = p.next) {
  12444. var str = p.data;
  12445. var nb = n > str.length ? str.length : n;
  12446. if (nb === str.length) ret += str;else ret += str.slice(0, n);
  12447. n -= nb;
  12448. if (n === 0) {
  12449. if (nb === str.length) {
  12450. ++c;
  12451. if (p.next) list.head = p.next;else list.head = list.tail = null;
  12452. } else {
  12453. list.head = p;
  12454. p.data = str.slice(nb);
  12455. }
  12456. break;
  12457. }
  12458. ++c;
  12459. }
  12460. list.length -= c;
  12461. return ret;
  12462. }
  12463. // Copies a specified amount of bytes from the list of buffered data chunks.
  12464. // This function is designed to be inlinable, so please take care when making
  12465. // changes to the function body.
  12466. function copyFromBuffer(n, list) {
  12467. var ret = bufferShim.allocUnsafe(n);
  12468. var p = list.head;
  12469. var c = 1;
  12470. p.data.copy(ret);
  12471. n -= p.data.length;
  12472. while (p = p.next) {
  12473. var buf = p.data;
  12474. var nb = n > buf.length ? buf.length : n;
  12475. buf.copy(ret, ret.length - n, 0, nb);
  12476. n -= nb;
  12477. if (n === 0) {
  12478. if (nb === buf.length) {
  12479. ++c;
  12480. if (p.next) list.head = p.next;else list.head = list.tail = null;
  12481. } else {
  12482. list.head = p;
  12483. p.data = buf.slice(nb);
  12484. }
  12485. break;
  12486. }
  12487. ++c;
  12488. }
  12489. list.length -= c;
  12490. return ret;
  12491. }
  12492. function endReadable(stream) {
  12493. var state = stream._readableState;
  12494. // If we get here before consuming all the bytes, then that is a
  12495. // bug in node. Should never happen.
  12496. if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
  12497. if (!state.endEmitted) {
  12498. state.ended = true;
  12499. processNextTick(endReadableNT, state, stream);
  12500. }
  12501. }
  12502. function endReadableNT(state, stream) {
  12503. // Check that we didn't get one last unshift.
  12504. if (!state.endEmitted && state.length === 0) {
  12505. state.endEmitted = true;
  12506. stream.readable = false;
  12507. stream.emit('end');
  12508. }
  12509. }
  12510. function forEach(xs, f) {
  12511. for (var i = 0, l = xs.length; i < l; i++) {
  12512. f(xs[i], i);
  12513. }
  12514. }
  12515. function indexOf(xs, x) {
  12516. for (var i = 0, l = xs.length; i < l; i++) {
  12517. if (xs[i] === x) return i;
  12518. }
  12519. return -1;
  12520. }
  12521. }).call(this,require('_process'))
  12522. },{"./_stream_duplex":84,"./internal/streams/BufferList":89,"_process":82,"buffer":44,"buffer-shims":43,"core-util-is":45,"events":63,"inherits":66,"isarray":68,"process-nextick-args":81,"string_decoder/":95,"util":40}],87:[function(require,module,exports){
  12523. // a transform stream is a readable/writable stream where you do
  12524. // something with the data. Sometimes it's called a "filter",
  12525. // but that's not a great name for it, since that implies a thing where
  12526. // some bits pass through, and others are simply ignored. (That would
  12527. // be a valid example of a transform, of course.)
  12528. //
  12529. // While the output is causally related to the input, it's not a
  12530. // necessarily symmetric or synchronous transformation. For example,
  12531. // a zlib stream might take multiple plain-text writes(), and then
  12532. // emit a single compressed chunk some time in the future.
  12533. //
  12534. // Here's how this works:
  12535. //
  12536. // The Transform stream has all the aspects of the readable and writable
  12537. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  12538. // internally, and returns false if there's a lot of pending writes
  12539. // buffered up. When you call read(), that calls _read(n) until
  12540. // there's enough pending readable data buffered up.
  12541. //
  12542. // In a transform stream, the written data is placed in a buffer. When
  12543. // _read(n) is called, it transforms the queued up data, calling the
  12544. // buffered _write cb's as it consumes chunks. If consuming a single
  12545. // written chunk would result in multiple output chunks, then the first
  12546. // outputted bit calls the readcb, and subsequent chunks just go into
  12547. // the read buffer, and will cause it to emit 'readable' if necessary.
  12548. //
  12549. // This way, back-pressure is actually determined by the reading side,
  12550. // since _read has to be called to start processing a new chunk. However,
  12551. // a pathological inflate type of transform can cause excessive buffering
  12552. // here. For example, imagine a stream where every byte of input is
  12553. // interpreted as an integer from 0-255, and then results in that many
  12554. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  12555. // 1kb of data being output. In this case, you could write a very small
  12556. // amount of input, and end up with a very large amount of output. In
  12557. // such a pathological inflating mechanism, there'd be no way to tell
  12558. // the system to stop doing the transform. A single 4MB write could
  12559. // cause the system to run out of memory.
  12560. //
  12561. // However, even in such a pathological case, only a single written chunk
  12562. // would be consumed, and then the rest would wait (un-transformed) until
  12563. // the results of the previous transformed chunk were consumed.
  12564. 'use strict';
  12565. module.exports = Transform;
  12566. var Duplex = require('./_stream_duplex');
  12567. /*<replacement>*/
  12568. var util = require('core-util-is');
  12569. util.inherits = require('inherits');
  12570. /*</replacement>*/
  12571. util.inherits(Transform, Duplex);
  12572. function TransformState(stream) {
  12573. this.afterTransform = function (er, data) {
  12574. return afterTransform(stream, er, data);
  12575. };
  12576. this.needTransform = false;
  12577. this.transforming = false;
  12578. this.writecb = null;
  12579. this.writechunk = null;
  12580. this.writeencoding = null;
  12581. }
  12582. function afterTransform(stream, er, data) {
  12583. var ts = stream._transformState;
  12584. ts.transforming = false;
  12585. var cb = ts.writecb;
  12586. if (!cb) return stream.emit('error', new Error('no writecb in Transform class'));
  12587. ts.writechunk = null;
  12588. ts.writecb = null;
  12589. if (data !== null && data !== undefined) stream.push(data);
  12590. cb(er);
  12591. var rs = stream._readableState;
  12592. rs.reading = false;
  12593. if (rs.needReadable || rs.length < rs.highWaterMark) {
  12594. stream._read(rs.highWaterMark);
  12595. }
  12596. }
  12597. function Transform(options) {
  12598. if (!(this instanceof Transform)) return new Transform(options);
  12599. Duplex.call(this, options);
  12600. this._transformState = new TransformState(this);
  12601. // when the writable side finishes, then flush out anything remaining.
  12602. var stream = this;
  12603. // start out asking for a readable event once data is transformed.
  12604. this._readableState.needReadable = true;
  12605. // we have implemented the _read method, and done the other things
  12606. // that Readable wants before the first _read call, so unset the
  12607. // sync guard flag.
  12608. this._readableState.sync = false;
  12609. if (options) {
  12610. if (typeof options.transform === 'function') this._transform = options.transform;
  12611. if (typeof options.flush === 'function') this._flush = options.flush;
  12612. }
  12613. this.once('prefinish', function () {
  12614. if (typeof this._flush === 'function') this._flush(function (er) {
  12615. done(stream, er);
  12616. });else done(stream);
  12617. });
  12618. }
  12619. Transform.prototype.push = function (chunk, encoding) {
  12620. this._transformState.needTransform = false;
  12621. return Duplex.prototype.push.call(this, chunk, encoding);
  12622. };
  12623. // This is the part where you do stuff!
  12624. // override this function in implementation classes.
  12625. // 'chunk' is an input chunk.
  12626. //
  12627. // Call `push(newChunk)` to pass along transformed output
  12628. // to the readable side. You may call 'push' zero or more times.
  12629. //
  12630. // Call `cb(err)` when you are done with this chunk. If you pass
  12631. // an error, then that'll put the hurt on the whole operation. If you
  12632. // never call cb(), then you'll never get another chunk.
  12633. Transform.prototype._transform = function (chunk, encoding, cb) {
  12634. throw new Error('Not implemented');
  12635. };
  12636. Transform.prototype._write = function (chunk, encoding, cb) {
  12637. var ts = this._transformState;
  12638. ts.writecb = cb;
  12639. ts.writechunk = chunk;
  12640. ts.writeencoding = encoding;
  12641. if (!ts.transforming) {
  12642. var rs = this._readableState;
  12643. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  12644. }
  12645. };
  12646. // Doesn't matter what the args are here.
  12647. // _transform does all the work.
  12648. // That we got here means that the readable side wants more data.
  12649. Transform.prototype._read = function (n) {
  12650. var ts = this._transformState;
  12651. if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
  12652. ts.transforming = true;
  12653. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  12654. } else {
  12655. // mark that we need a transform, so that any data that comes in
  12656. // will get processed, now that we've asked for it.
  12657. ts.needTransform = true;
  12658. }
  12659. };
  12660. function done(stream, er) {
  12661. if (er) return stream.emit('error', er);
  12662. // if there's nothing in the write buffer, then that means
  12663. // that nothing more will ever be provided
  12664. var ws = stream._writableState;
  12665. var ts = stream._transformState;
  12666. if (ws.length) throw new Error('Calling transform done when ws.length != 0');
  12667. if (ts.transforming) throw new Error('Calling transform done when still transforming');
  12668. return stream.push(null);
  12669. }
  12670. },{"./_stream_duplex":84,"core-util-is":45,"inherits":66}],88:[function(require,module,exports){
  12671. (function (process){
  12672. // A bit simpler than readable streams.
  12673. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  12674. // the drain event emission and buffering.
  12675. 'use strict';
  12676. module.exports = Writable;
  12677. /*<replacement>*/
  12678. var processNextTick = require('process-nextick-args');
  12679. /*</replacement>*/
  12680. /*<replacement>*/
  12681. var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick;
  12682. /*</replacement>*/
  12683. Writable.WritableState = WritableState;
  12684. /*<replacement>*/
  12685. var util = require('core-util-is');
  12686. util.inherits = require('inherits');
  12687. /*</replacement>*/
  12688. /*<replacement>*/
  12689. var internalUtil = {
  12690. deprecate: require('util-deprecate')
  12691. };
  12692. /*</replacement>*/
  12693. /*<replacement>*/
  12694. var Stream;
  12695. (function () {
  12696. try {
  12697. Stream = require('st' + 'ream');
  12698. } catch (_) {} finally {
  12699. if (!Stream) Stream = require('events').EventEmitter;
  12700. }
  12701. })();
  12702. /*</replacement>*/
  12703. var Buffer = require('buffer').Buffer;
  12704. /*<replacement>*/
  12705. var bufferShim = require('buffer-shims');
  12706. /*</replacement>*/
  12707. util.inherits(Writable, Stream);
  12708. function nop() {}
  12709. function WriteReq(chunk, encoding, cb) {
  12710. this.chunk = chunk;
  12711. this.encoding = encoding;
  12712. this.callback = cb;
  12713. this.next = null;
  12714. }
  12715. var Duplex;
  12716. function WritableState(options, stream) {
  12717. Duplex = Duplex || require('./_stream_duplex');
  12718. options = options || {};
  12719. // object stream flag to indicate whether or not this stream
  12720. // contains buffers or objects.
  12721. this.objectMode = !!options.objectMode;
  12722. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
  12723. // the point at which write() starts returning false
  12724. // Note: 0 is a valid value, means that we always return false if
  12725. // the entire buffer is not flushed immediately on write()
  12726. var hwm = options.highWaterMark;
  12727. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  12728. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  12729. // cast to ints.
  12730. this.highWaterMark = ~ ~this.highWaterMark;
  12731. this.needDrain = false;
  12732. // at the start of calling end()
  12733. this.ending = false;
  12734. // when end() has been called, and returned
  12735. this.ended = false;
  12736. // when 'finish' is emitted
  12737. this.finished = false;
  12738. // should we decode strings into buffers before passing to _write?
  12739. // this is here so that some node-core streams can optimize string
  12740. // handling at a lower level.
  12741. var noDecode = options.decodeStrings === false;
  12742. this.decodeStrings = !noDecode;
  12743. // Crypto is kind of old and crusty. Historically, its default string
  12744. // encoding is 'binary' so we have to make this configurable.
  12745. // Everything else in the universe uses 'utf8', though.
  12746. this.defaultEncoding = options.defaultEncoding || 'utf8';
  12747. // not an actual buffer we keep track of, but a measurement
  12748. // of how much we're waiting to get pushed to some underlying
  12749. // socket or file.
  12750. this.length = 0;
  12751. // a flag to see when we're in the middle of a write.
  12752. this.writing = false;
  12753. // when true all writes will be buffered until .uncork() call
  12754. this.corked = 0;
  12755. // a flag to be able to tell if the onwrite cb is called immediately,
  12756. // or on a later tick. We set this to true at first, because any
  12757. // actions that shouldn't happen until "later" should generally also
  12758. // not happen before the first write call.
  12759. this.sync = true;
  12760. // a flag to know if we're processing previously buffered items, which
  12761. // may call the _write() callback in the same tick, so that we don't
  12762. // end up in an overlapped onwrite situation.
  12763. this.bufferProcessing = false;
  12764. // the callback that's passed to _write(chunk,cb)
  12765. this.onwrite = function (er) {
  12766. onwrite(stream, er);
  12767. };
  12768. // the callback that the user supplies to write(chunk,encoding,cb)
  12769. this.writecb = null;
  12770. // the amount that is being written when _write is called.
  12771. this.writelen = 0;
  12772. this.bufferedRequest = null;
  12773. this.lastBufferedRequest = null;
  12774. // number of pending user-supplied write callbacks
  12775. // this must be 0 before 'finish' can be emitted
  12776. this.pendingcb = 0;
  12777. // emit prefinish if the only thing we're waiting for is _write cbs
  12778. // This is relevant for synchronous Transform streams
  12779. this.prefinished = false;
  12780. // True if the error was already emitted and should not be thrown again
  12781. this.errorEmitted = false;
  12782. // count buffered requests
  12783. this.bufferedRequestCount = 0;
  12784. // allocate the first CorkedRequest, there is always
  12785. // one allocated and free to use, and we maintain at most two
  12786. this.corkedRequestsFree = new CorkedRequest(this);
  12787. }
  12788. WritableState.prototype.getBuffer = function writableStateGetBuffer() {
  12789. var current = this.bufferedRequest;
  12790. var out = [];
  12791. while (current) {
  12792. out.push(current);
  12793. current = current.next;
  12794. }
  12795. return out;
  12796. };
  12797. (function () {
  12798. try {
  12799. Object.defineProperty(WritableState.prototype, 'buffer', {
  12800. get: internalUtil.deprecate(function () {
  12801. return this.getBuffer();
  12802. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
  12803. });
  12804. } catch (_) {}
  12805. })();
  12806. var Duplex;
  12807. function Writable(options) {
  12808. Duplex = Duplex || require('./_stream_duplex');
  12809. // Writable ctor is applied to Duplexes, though they're not
  12810. // instanceof Writable, they're instanceof Readable.
  12811. if (!(this instanceof Writable) && !(this instanceof Duplex)) return new Writable(options);
  12812. this._writableState = new WritableState(options, this);
  12813. // legacy.
  12814. this.writable = true;
  12815. if (options) {
  12816. if (typeof options.write === 'function') this._write = options.write;
  12817. if (typeof options.writev === 'function') this._writev = options.writev;
  12818. }
  12819. Stream.call(this);
  12820. }
  12821. // Otherwise people can pipe Writable streams, which is just wrong.
  12822. Writable.prototype.pipe = function () {
  12823. this.emit('error', new Error('Cannot pipe, not readable'));
  12824. };
  12825. function writeAfterEnd(stream, cb) {
  12826. var er = new Error('write after end');
  12827. // TODO: defer error events consistently everywhere, not just the cb
  12828. stream.emit('error', er);
  12829. processNextTick(cb, er);
  12830. }
  12831. // If we get something that is not a buffer, string, null, or undefined,
  12832. // and we're not in objectMode, then that's an error.
  12833. // Otherwise stream chunks are all considered to be of length=1, and the
  12834. // watermarks determine how many objects to keep in the buffer, rather than
  12835. // how many bytes or characters.
  12836. function validChunk(stream, state, chunk, cb) {
  12837. var valid = true;
  12838. var er = false;
  12839. // Always throw error if a null is written
  12840. // if we are not in object mode then throw
  12841. // if it is not a buffer, string, or undefined.
  12842. if (chunk === null) {
  12843. er = new TypeError('May not write null values to stream');
  12844. } else if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  12845. er = new TypeError('Invalid non-string/buffer chunk');
  12846. }
  12847. if (er) {
  12848. stream.emit('error', er);
  12849. processNextTick(cb, er);
  12850. valid = false;
  12851. }
  12852. return valid;
  12853. }
  12854. Writable.prototype.write = function (chunk, encoding, cb) {
  12855. var state = this._writableState;
  12856. var ret = false;
  12857. if (typeof encoding === 'function') {
  12858. cb = encoding;
  12859. encoding = null;
  12860. }
  12861. if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  12862. if (typeof cb !== 'function') cb = nop;
  12863. if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) {
  12864. state.pendingcb++;
  12865. ret = writeOrBuffer(this, state, chunk, encoding, cb);
  12866. }
  12867. return ret;
  12868. };
  12869. Writable.prototype.cork = function () {
  12870. var state = this._writableState;
  12871. state.corked++;
  12872. };
  12873. Writable.prototype.uncork = function () {
  12874. var state = this._writableState;
  12875. if (state.corked) {
  12876. state.corked--;
  12877. if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  12878. }
  12879. };
  12880. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  12881. // node::ParseEncoding() requires lower case.
  12882. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  12883. 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);
  12884. this._writableState.defaultEncoding = encoding;
  12885. return this;
  12886. };
  12887. function decodeChunk(state, chunk, encoding) {
  12888. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  12889. chunk = bufferShim.from(chunk, encoding);
  12890. }
  12891. return chunk;
  12892. }
  12893. // if we're already writing something, then just put this
  12894. // in the queue, and wait our turn. Otherwise, call _write
  12895. // If we return false, then we need a drain event, so set that flag.
  12896. function writeOrBuffer(stream, state, chunk, encoding, cb) {
  12897. chunk = decodeChunk(state, chunk, encoding);
  12898. if (Buffer.isBuffer(chunk)) encoding = 'buffer';
  12899. var len = state.objectMode ? 1 : chunk.length;
  12900. state.length += len;
  12901. var ret = state.length < state.highWaterMark;
  12902. // we must ensure that previous needDrain will not be reset to false.
  12903. if (!ret) state.needDrain = true;
  12904. if (state.writing || state.corked) {
  12905. var last = state.lastBufferedRequest;
  12906. state.lastBufferedRequest = new WriteReq(chunk, encoding, cb);
  12907. if (last) {
  12908. last.next = state.lastBufferedRequest;
  12909. } else {
  12910. state.bufferedRequest = state.lastBufferedRequest;
  12911. }
  12912. state.bufferedRequestCount += 1;
  12913. } else {
  12914. doWrite(stream, state, false, len, chunk, encoding, cb);
  12915. }
  12916. return ret;
  12917. }
  12918. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  12919. state.writelen = len;
  12920. state.writecb = cb;
  12921. state.writing = true;
  12922. state.sync = true;
  12923. if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  12924. state.sync = false;
  12925. }
  12926. function onwriteError(stream, state, sync, er, cb) {
  12927. --state.pendingcb;
  12928. if (sync) processNextTick(cb, er);else cb(er);
  12929. stream._writableState.errorEmitted = true;
  12930. stream.emit('error', er);
  12931. }
  12932. function onwriteStateUpdate(state) {
  12933. state.writing = false;
  12934. state.writecb = null;
  12935. state.length -= state.writelen;
  12936. state.writelen = 0;
  12937. }
  12938. function onwrite(stream, er) {
  12939. var state = stream._writableState;
  12940. var sync = state.sync;
  12941. var cb = state.writecb;
  12942. onwriteStateUpdate(state);
  12943. if (er) onwriteError(stream, state, sync, er, cb);else {
  12944. // Check if we're actually ready to finish, but don't emit yet
  12945. var finished = needFinish(state);
  12946. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  12947. clearBuffer(stream, state);
  12948. }
  12949. if (sync) {
  12950. /*<replacement>*/
  12951. asyncWrite(afterWrite, stream, state, finished, cb);
  12952. /*</replacement>*/
  12953. } else {
  12954. afterWrite(stream, state, finished, cb);
  12955. }
  12956. }
  12957. }
  12958. function afterWrite(stream, state, finished, cb) {
  12959. if (!finished) onwriteDrain(stream, state);
  12960. state.pendingcb--;
  12961. cb();
  12962. finishMaybe(stream, state);
  12963. }
  12964. // Must force callback to be called on nextTick, so that we don't
  12965. // emit 'drain' before the write() consumer gets the 'false' return
  12966. // value, and has a chance to attach a 'drain' listener.
  12967. function onwriteDrain(stream, state) {
  12968. if (state.length === 0 && state.needDrain) {
  12969. state.needDrain = false;
  12970. stream.emit('drain');
  12971. }
  12972. }
  12973. // if there's something in the buffer waiting, then process it
  12974. function clearBuffer(stream, state) {
  12975. state.bufferProcessing = true;
  12976. var entry = state.bufferedRequest;
  12977. if (stream._writev && entry && entry.next) {
  12978. // Fast case, write everything using _writev()
  12979. var l = state.bufferedRequestCount;
  12980. var buffer = new Array(l);
  12981. var holder = state.corkedRequestsFree;
  12982. holder.entry = entry;
  12983. var count = 0;
  12984. while (entry) {
  12985. buffer[count] = entry;
  12986. entry = entry.next;
  12987. count += 1;
  12988. }
  12989. doWrite(stream, state, true, state.length, buffer, '', holder.finish);
  12990. // doWrite is almost always async, defer these to save a bit of time
  12991. // as the hot path ends with doWrite
  12992. state.pendingcb++;
  12993. state.lastBufferedRequest = null;
  12994. if (holder.next) {
  12995. state.corkedRequestsFree = holder.next;
  12996. holder.next = null;
  12997. } else {
  12998. state.corkedRequestsFree = new CorkedRequest(state);
  12999. }
  13000. } else {
  13001. // Slow case, write chunks one-by-one
  13002. while (entry) {
  13003. var chunk = entry.chunk;
  13004. var encoding = entry.encoding;
  13005. var cb = entry.callback;
  13006. var len = state.objectMode ? 1 : chunk.length;
  13007. doWrite(stream, state, false, len, chunk, encoding, cb);
  13008. entry = entry.next;
  13009. // if we didn't call the onwrite immediately, then
  13010. // it means that we need to wait until it does.
  13011. // also, that means that the chunk and cb are currently
  13012. // being processed, so move the buffer counter past them.
  13013. if (state.writing) {
  13014. break;
  13015. }
  13016. }
  13017. if (entry === null) state.lastBufferedRequest = null;
  13018. }
  13019. state.bufferedRequestCount = 0;
  13020. state.bufferedRequest = entry;
  13021. state.bufferProcessing = false;
  13022. }
  13023. Writable.prototype._write = function (chunk, encoding, cb) {
  13024. cb(new Error('not implemented'));
  13025. };
  13026. Writable.prototype._writev = null;
  13027. Writable.prototype.end = function (chunk, encoding, cb) {
  13028. var state = this._writableState;
  13029. if (typeof chunk === 'function') {
  13030. cb = chunk;
  13031. chunk = null;
  13032. encoding = null;
  13033. } else if (typeof encoding === 'function') {
  13034. cb = encoding;
  13035. encoding = null;
  13036. }
  13037. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
  13038. // .end() fully uncorks
  13039. if (state.corked) {
  13040. state.corked = 1;
  13041. this.uncork();
  13042. }
  13043. // ignore unnecessary end() calls.
  13044. if (!state.ending && !state.finished) endWritable(this, state, cb);
  13045. };
  13046. function needFinish(state) {
  13047. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  13048. }
  13049. function prefinish(stream, state) {
  13050. if (!state.prefinished) {
  13051. state.prefinished = true;
  13052. stream.emit('prefinish');
  13053. }
  13054. }
  13055. function finishMaybe(stream, state) {
  13056. var need = needFinish(state);
  13057. if (need) {
  13058. if (state.pendingcb === 0) {
  13059. prefinish(stream, state);
  13060. state.finished = true;
  13061. stream.emit('finish');
  13062. } else {
  13063. prefinish(stream, state);
  13064. }
  13065. }
  13066. return need;
  13067. }
  13068. function endWritable(stream, state, cb) {
  13069. state.ending = true;
  13070. finishMaybe(stream, state);
  13071. if (cb) {
  13072. if (state.finished) processNextTick(cb);else stream.once('finish', cb);
  13073. }
  13074. state.ended = true;
  13075. stream.writable = false;
  13076. }
  13077. // It seems a linked list but it is not
  13078. // there will be only 2 of these for each stream
  13079. function CorkedRequest(state) {
  13080. var _this = this;
  13081. this.next = null;
  13082. this.entry = null;
  13083. this.finish = function (err) {
  13084. var entry = _this.entry;
  13085. _this.entry = null;
  13086. while (entry) {
  13087. var cb = entry.callback;
  13088. state.pendingcb--;
  13089. cb(err);
  13090. entry = entry.next;
  13091. }
  13092. if (state.corkedRequestsFree) {
  13093. state.corkedRequestsFree.next = _this;
  13094. } else {
  13095. state.corkedRequestsFree = _this;
  13096. }
  13097. };
  13098. }
  13099. }).call(this,require('_process'))
  13100. },{"./_stream_duplex":84,"_process":82,"buffer":44,"buffer-shims":43,"core-util-is":45,"events":63,"inherits":66,"process-nextick-args":81,"util-deprecate":96}],89:[function(require,module,exports){
  13101. 'use strict';
  13102. var Buffer = require('buffer').Buffer;
  13103. /*<replacement>*/
  13104. var bufferShim = require('buffer-shims');
  13105. /*</replacement>*/
  13106. module.exports = BufferList;
  13107. function BufferList() {
  13108. this.head = null;
  13109. this.tail = null;
  13110. this.length = 0;
  13111. }
  13112. BufferList.prototype.push = function (v) {
  13113. var entry = { data: v, next: null };
  13114. if (this.length > 0) this.tail.next = entry;else this.head = entry;
  13115. this.tail = entry;
  13116. ++this.length;
  13117. };
  13118. BufferList.prototype.unshift = function (v) {
  13119. var entry = { data: v, next: this.head };
  13120. if (this.length === 0) this.tail = entry;
  13121. this.head = entry;
  13122. ++this.length;
  13123. };
  13124. BufferList.prototype.shift = function () {
  13125. if (this.length === 0) return;
  13126. var ret = this.head.data;
  13127. if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
  13128. --this.length;
  13129. return ret;
  13130. };
  13131. BufferList.prototype.clear = function () {
  13132. this.head = this.tail = null;
  13133. this.length = 0;
  13134. };
  13135. BufferList.prototype.join = function (s) {
  13136. if (this.length === 0) return '';
  13137. var p = this.head;
  13138. var ret = '' + p.data;
  13139. while (p = p.next) {
  13140. ret += s + p.data;
  13141. }return ret;
  13142. };
  13143. BufferList.prototype.concat = function (n) {
  13144. if (this.length === 0) return bufferShim.alloc(0);
  13145. if (this.length === 1) return this.head.data;
  13146. var ret = bufferShim.allocUnsafe(n >>> 0);
  13147. var p = this.head;
  13148. var i = 0;
  13149. while (p) {
  13150. p.data.copy(ret, i);
  13151. i += p.data.length;
  13152. p = p.next;
  13153. }
  13154. return ret;
  13155. };
  13156. },{"buffer":44,"buffer-shims":43}],90:[function(require,module,exports){
  13157. module.exports = require("./lib/_stream_passthrough.js")
  13158. },{"./lib/_stream_passthrough.js":85}],91:[function(require,module,exports){
  13159. (function (process){
  13160. var Stream = (function (){
  13161. try {
  13162. return require('st' + 'ream'); // hack to fix a circular dependency issue when used with browserify
  13163. } catch(_){}
  13164. }());
  13165. exports = module.exports = require('./lib/_stream_readable.js');
  13166. exports.Stream = Stream || exports;
  13167. exports.Readable = exports;
  13168. exports.Writable = require('./lib/_stream_writable.js');
  13169. exports.Duplex = require('./lib/_stream_duplex.js');
  13170. exports.Transform = require('./lib/_stream_transform.js');
  13171. exports.PassThrough = require('./lib/_stream_passthrough.js');
  13172. if (!process.browser && process.env.READABLE_STREAM === 'disable' && Stream) {
  13173. module.exports = Stream;
  13174. }
  13175. }).call(this,require('_process'))
  13176. },{"./lib/_stream_duplex.js":84,"./lib/_stream_passthrough.js":85,"./lib/_stream_readable.js":86,"./lib/_stream_transform.js":87,"./lib/_stream_writable.js":88,"_process":82}],92:[function(require,module,exports){
  13177. module.exports = require("./lib/_stream_transform.js")
  13178. },{"./lib/_stream_transform.js":87}],93:[function(require,module,exports){
  13179. module.exports = require("./lib/_stream_writable.js")
  13180. },{"./lib/_stream_writable.js":88}],94:[function(require,module,exports){
  13181. // Copyright Joyent, Inc. and other Node contributors.
  13182. //
  13183. // Permission is hereby granted, free of charge, to any person obtaining a
  13184. // copy of this software and associated documentation files (the
  13185. // "Software"), to deal in the Software without restriction, including
  13186. // without limitation the rights to use, copy, modify, merge, publish,
  13187. // distribute, sublicense, and/or sell copies of the Software, and to permit
  13188. // persons to whom the Software is furnished to do so, subject to the
  13189. // following conditions:
  13190. //
  13191. // The above copyright notice and this permission notice shall be included
  13192. // in all copies or substantial portions of the Software.
  13193. //
  13194. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13195. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13196. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  13197. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  13198. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  13199. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  13200. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  13201. module.exports = Stream;
  13202. var EE = require('events').EventEmitter;
  13203. var inherits = require('inherits');
  13204. inherits(Stream, EE);
  13205. Stream.Readable = require('readable-stream/readable.js');
  13206. Stream.Writable = require('readable-stream/writable.js');
  13207. Stream.Duplex = require('readable-stream/duplex.js');
  13208. Stream.Transform = require('readable-stream/transform.js');
  13209. Stream.PassThrough = require('readable-stream/passthrough.js');
  13210. // Backwards-compat with node 0.4.x
  13211. Stream.Stream = Stream;
  13212. // old-style streams. Note that the pipe method (the only relevant
  13213. // part of this class) is overridden in the Readable class.
  13214. function Stream() {
  13215. EE.call(this);
  13216. }
  13217. Stream.prototype.pipe = function(dest, options) {
  13218. var source = this;
  13219. function ondata(chunk) {
  13220. if (dest.writable) {
  13221. if (false === dest.write(chunk) && source.pause) {
  13222. source.pause();
  13223. }
  13224. }
  13225. }
  13226. source.on('data', ondata);
  13227. function ondrain() {
  13228. if (source.readable && source.resume) {
  13229. source.resume();
  13230. }
  13231. }
  13232. dest.on('drain', ondrain);
  13233. // If the 'end' option is not supplied, dest.end() will be called when
  13234. // source gets the 'end' or 'close' events. Only dest.end() once.
  13235. if (!dest._isStdio && (!options || options.end !== false)) {
  13236. source.on('end', onend);
  13237. source.on('close', onclose);
  13238. }
  13239. var didOnEnd = false;
  13240. function onend() {
  13241. if (didOnEnd) return;
  13242. didOnEnd = true;
  13243. dest.end();
  13244. }
  13245. function onclose() {
  13246. if (didOnEnd) return;
  13247. didOnEnd = true;
  13248. if (typeof dest.destroy === 'function') dest.destroy();
  13249. }
  13250. // don't leave dangling pipes when there are errors.
  13251. function onerror(er) {
  13252. cleanup();
  13253. if (EE.listenerCount(this, 'error') === 0) {
  13254. throw er; // Unhandled stream error in pipe.
  13255. }
  13256. }
  13257. source.on('error', onerror);
  13258. dest.on('error', onerror);
  13259. // remove all the event listeners that were added.
  13260. function cleanup() {
  13261. source.removeListener('data', ondata);
  13262. dest.removeListener('drain', ondrain);
  13263. source.removeListener('end', onend);
  13264. source.removeListener('close', onclose);
  13265. source.removeListener('error', onerror);
  13266. dest.removeListener('error', onerror);
  13267. source.removeListener('end', cleanup);
  13268. source.removeListener('close', cleanup);
  13269. dest.removeListener('close', cleanup);
  13270. }
  13271. source.on('end', cleanup);
  13272. source.on('close', cleanup);
  13273. dest.on('close', cleanup);
  13274. dest.emit('pipe', source);
  13275. // Allow for unix-like usage: A.pipe(B).pipe(C)
  13276. return dest;
  13277. };
  13278. },{"events":63,"inherits":66,"readable-stream/duplex.js":83,"readable-stream/passthrough.js":90,"readable-stream/readable.js":91,"readable-stream/transform.js":92,"readable-stream/writable.js":93}],95:[function(require,module,exports){
  13279. // Copyright Joyent, Inc. and other Node contributors.
  13280. //
  13281. // Permission is hereby granted, free of charge, to any person obtaining a
  13282. // copy of this software and associated documentation files (the
  13283. // "Software"), to deal in the Software without restriction, including
  13284. // without limitation the rights to use, copy, modify, merge, publish,
  13285. // distribute, sublicense, and/or sell copies of the Software, and to permit
  13286. // persons to whom the Software is furnished to do so, subject to the
  13287. // following conditions:
  13288. //
  13289. // The above copyright notice and this permission notice shall be included
  13290. // in all copies or substantial portions of the Software.
  13291. //
  13292. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13293. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13294. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  13295. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  13296. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  13297. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  13298. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  13299. var Buffer = require('buffer').Buffer;
  13300. var isBufferEncoding = Buffer.isEncoding
  13301. || function(encoding) {
  13302. switch (encoding && encoding.toLowerCase()) {
  13303. 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;
  13304. default: return false;
  13305. }
  13306. }
  13307. function assertEncoding(encoding) {
  13308. if (encoding && !isBufferEncoding(encoding)) {
  13309. throw new Error('Unknown encoding: ' + encoding);
  13310. }
  13311. }
  13312. // StringDecoder provides an interface for efficiently splitting a series of
  13313. // buffers into a series of JS strings without breaking apart multi-byte
  13314. // characters. CESU-8 is handled as part of the UTF-8 encoding.
  13315. //
  13316. // @TODO Handling all encodings inside a single object makes it very difficult
  13317. // to reason about this code, so it should be split up in the future.
  13318. // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
  13319. // points as used by CESU-8.
  13320. var StringDecoder = exports.StringDecoder = function(encoding) {
  13321. this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
  13322. assertEncoding(encoding);
  13323. switch (this.encoding) {
  13324. case 'utf8':
  13325. // CESU-8 represents each of Surrogate Pair by 3-bytes
  13326. this.surrogateSize = 3;
  13327. break;
  13328. case 'ucs2':
  13329. case 'utf16le':
  13330. // UTF-16 represents each of Surrogate Pair by 2-bytes
  13331. this.surrogateSize = 2;
  13332. this.detectIncompleteChar = utf16DetectIncompleteChar;
  13333. break;
  13334. case 'base64':
  13335. // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
  13336. this.surrogateSize = 3;
  13337. this.detectIncompleteChar = base64DetectIncompleteChar;
  13338. break;
  13339. default:
  13340. this.write = passThroughWrite;
  13341. return;
  13342. }
  13343. // Enough space to store all bytes of a single character. UTF-8 needs 4
  13344. // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
  13345. this.charBuffer = new Buffer(6);
  13346. // Number of bytes received for the current incomplete multi-byte character.
  13347. this.charReceived = 0;
  13348. // Number of bytes expected for the current incomplete multi-byte character.
  13349. this.charLength = 0;
  13350. };
  13351. // write decodes the given buffer and returns it as JS string that is
  13352. // guaranteed to not contain any partial multi-byte characters. Any partial
  13353. // character found at the end of the buffer is buffered up, and will be
  13354. // returned when calling write again with the remaining bytes.
  13355. //
  13356. // Note: Converting a Buffer containing an orphan surrogate to a String
  13357. // currently works, but converting a String to a Buffer (via `new Buffer`, or
  13358. // Buffer#write) will replace incomplete surrogates with the unicode
  13359. // replacement character. See https://codereview.chromium.org/121173009/ .
  13360. StringDecoder.prototype.write = function(buffer) {
  13361. var charStr = '';
  13362. // if our last write ended with an incomplete multibyte character
  13363. while (this.charLength) {
  13364. // determine how many remaining bytes this buffer has to offer for this char
  13365. var available = (buffer.length >= this.charLength - this.charReceived) ?
  13366. this.charLength - this.charReceived :
  13367. buffer.length;
  13368. // add the new bytes to the char buffer
  13369. buffer.copy(this.charBuffer, this.charReceived, 0, available);
  13370. this.charReceived += available;
  13371. if (this.charReceived < this.charLength) {
  13372. // still not enough chars in this buffer? wait for more ...
  13373. return '';
  13374. }
  13375. // remove bytes belonging to the current character from the buffer
  13376. buffer = buffer.slice(available, buffer.length);
  13377. // get the character that was split
  13378. charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
  13379. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  13380. var charCode = charStr.charCodeAt(charStr.length - 1);
  13381. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  13382. this.charLength += this.surrogateSize;
  13383. charStr = '';
  13384. continue;
  13385. }
  13386. this.charReceived = this.charLength = 0;
  13387. // if there are no more bytes in this buffer, just emit our char
  13388. if (buffer.length === 0) {
  13389. return charStr;
  13390. }
  13391. break;
  13392. }
  13393. // determine and set charLength / charReceived
  13394. this.detectIncompleteChar(buffer);
  13395. var end = buffer.length;
  13396. if (this.charLength) {
  13397. // buffer the incomplete character bytes we got
  13398. buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
  13399. end -= this.charReceived;
  13400. }
  13401. charStr += buffer.toString(this.encoding, 0, end);
  13402. var end = charStr.length - 1;
  13403. var charCode = charStr.charCodeAt(end);
  13404. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  13405. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  13406. var size = this.surrogateSize;
  13407. this.charLength += size;
  13408. this.charReceived += size;
  13409. this.charBuffer.copy(this.charBuffer, size, 0, size);
  13410. buffer.copy(this.charBuffer, 0, 0, size);
  13411. return charStr.substring(0, end);
  13412. }
  13413. // or just emit the charStr
  13414. return charStr;
  13415. };
  13416. // detectIncompleteChar determines if there is an incomplete UTF-8 character at
  13417. // the end of the given buffer. If so, it sets this.charLength to the byte
  13418. // length that character, and sets this.charReceived to the number of bytes
  13419. // that are available for this character.
  13420. StringDecoder.prototype.detectIncompleteChar = function(buffer) {
  13421. // determine how many bytes we have to check at the end of this buffer
  13422. var i = (buffer.length >= 3) ? 3 : buffer.length;
  13423. // Figure out if one of the last i bytes of our buffer announces an
  13424. // incomplete char.
  13425. for (; i > 0; i--) {
  13426. var c = buffer[buffer.length - i];
  13427. // See http://en.wikipedia.org/wiki/UTF-8#Description
  13428. // 110XXXXX
  13429. if (i == 1 && c >> 5 == 0x06) {
  13430. this.charLength = 2;
  13431. break;
  13432. }
  13433. // 1110XXXX
  13434. if (i <= 2 && c >> 4 == 0x0E) {
  13435. this.charLength = 3;
  13436. break;
  13437. }
  13438. // 11110XXX
  13439. if (i <= 3 && c >> 3 == 0x1E) {
  13440. this.charLength = 4;
  13441. break;
  13442. }
  13443. }
  13444. this.charReceived = i;
  13445. };
  13446. StringDecoder.prototype.end = function(buffer) {
  13447. var res = '';
  13448. if (buffer && buffer.length)
  13449. res = this.write(buffer);
  13450. if (this.charReceived) {
  13451. var cr = this.charReceived;
  13452. var buf = this.charBuffer;
  13453. var enc = this.encoding;
  13454. res += buf.slice(0, cr).toString(enc);
  13455. }
  13456. return res;
  13457. };
  13458. function passThroughWrite(buffer) {
  13459. return buffer.toString(this.encoding);
  13460. }
  13461. function utf16DetectIncompleteChar(buffer) {
  13462. this.charReceived = buffer.length % 2;
  13463. this.charLength = this.charReceived ? 2 : 0;
  13464. }
  13465. function base64DetectIncompleteChar(buffer) {
  13466. this.charReceived = buffer.length % 3;
  13467. this.charLength = this.charReceived ? 3 : 0;
  13468. }
  13469. },{"buffer":44}],96:[function(require,module,exports){
  13470. (function (global){
  13471. /**
  13472. * Module exports.
  13473. */
  13474. module.exports = deprecate;
  13475. /**
  13476. * Mark that a method should not be used.
  13477. * Returns a modified function which warns once by default.
  13478. *
  13479. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  13480. *
  13481. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  13482. * will throw an Error when invoked.
  13483. *
  13484. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  13485. * will invoke `console.trace()` instead of `console.error()`.
  13486. *
  13487. * @param {Function} fn - the function to deprecate
  13488. * @param {String} msg - the string to print to the console when `fn` is invoked
  13489. * @returns {Function} a new "deprecated" version of `fn`
  13490. * @api public
  13491. */
  13492. function deprecate (fn, msg) {
  13493. if (config('noDeprecation')) {
  13494. return fn;
  13495. }
  13496. var warned = false;
  13497. function deprecated() {
  13498. if (!warned) {
  13499. if (config('throwDeprecation')) {
  13500. throw new Error(msg);
  13501. } else if (config('traceDeprecation')) {
  13502. console.trace(msg);
  13503. } else {
  13504. console.warn(msg);
  13505. }
  13506. warned = true;
  13507. }
  13508. return fn.apply(this, arguments);
  13509. }
  13510. return deprecated;
  13511. }
  13512. /**
  13513. * Checks `localStorage` for boolean values for the given `name`.
  13514. *
  13515. * @param {String} name
  13516. * @returns {Boolean}
  13517. * @api private
  13518. */
  13519. function config (name) {
  13520. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  13521. try {
  13522. if (!global.localStorage) return false;
  13523. } catch (_) {
  13524. return false;
  13525. }
  13526. var val = global.localStorage[name];
  13527. if (null == val) return false;
  13528. return String(val).toLowerCase() === 'true';
  13529. }
  13530. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  13531. },{}],97:[function(require,module,exports){
  13532. arguments[4][66][0].apply(exports,arguments)
  13533. },{"dup":66}],98:[function(require,module,exports){
  13534. module.exports = function isBuffer(arg) {
  13535. return arg && typeof arg === 'object'
  13536. && typeof arg.copy === 'function'
  13537. && typeof arg.fill === 'function'
  13538. && typeof arg.readUInt8 === 'function';
  13539. }
  13540. },{}],99:[function(require,module,exports){
  13541. (function (process,global){
  13542. // Copyright Joyent, Inc. and other Node contributors.
  13543. //
  13544. // Permission is hereby granted, free of charge, to any person obtaining a
  13545. // copy of this software and associated documentation files (the
  13546. // "Software"), to deal in the Software without restriction, including
  13547. // without limitation the rights to use, copy, modify, merge, publish,
  13548. // distribute, sublicense, and/or sell copies of the Software, and to permit
  13549. // persons to whom the Software is furnished to do so, subject to the
  13550. // following conditions:
  13551. //
  13552. // The above copyright notice and this permission notice shall be included
  13553. // in all copies or substantial portions of the Software.
  13554. //
  13555. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13556. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13557. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  13558. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  13559. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  13560. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  13561. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  13562. var formatRegExp = /%[sdj%]/g;
  13563. exports.format = function(f) {
  13564. if (!isString(f)) {
  13565. var objects = [];
  13566. for (var i = 0; i < arguments.length; i++) {
  13567. objects.push(inspect(arguments[i]));
  13568. }
  13569. return objects.join(' ');
  13570. }
  13571. var i = 1;
  13572. var args = arguments;
  13573. var len = args.length;
  13574. var str = String(f).replace(formatRegExp, function(x) {
  13575. if (x === '%%') return '%';
  13576. if (i >= len) return x;
  13577. switch (x) {
  13578. case '%s': return String(args[i++]);
  13579. case '%d': return Number(args[i++]);
  13580. case '%j':
  13581. try {
  13582. return JSON.stringify(args[i++]);
  13583. } catch (_) {
  13584. return '[Circular]';
  13585. }
  13586. default:
  13587. return x;
  13588. }
  13589. });
  13590. for (var x = args[i]; i < len; x = args[++i]) {
  13591. if (isNull(x) || !isObject(x)) {
  13592. str += ' ' + x;
  13593. } else {
  13594. str += ' ' + inspect(x);
  13595. }
  13596. }
  13597. return str;
  13598. };
  13599. // Mark that a method should not be used.
  13600. // Returns a modified function which warns once by default.
  13601. // If --no-deprecation is set, then it is a no-op.
  13602. exports.deprecate = function(fn, msg) {
  13603. // Allow for deprecating things in the process of starting up.
  13604. if (isUndefined(global.process)) {
  13605. return function() {
  13606. return exports.deprecate(fn, msg).apply(this, arguments);
  13607. };
  13608. }
  13609. if (process.noDeprecation === true) {
  13610. return fn;
  13611. }
  13612. var warned = false;
  13613. function deprecated() {
  13614. if (!warned) {
  13615. if (process.throwDeprecation) {
  13616. throw new Error(msg);
  13617. } else if (process.traceDeprecation) {
  13618. console.trace(msg);
  13619. } else {
  13620. console.error(msg);
  13621. }
  13622. warned = true;
  13623. }
  13624. return fn.apply(this, arguments);
  13625. }
  13626. return deprecated;
  13627. };
  13628. var debugs = {};
  13629. var debugEnviron;
  13630. exports.debuglog = function(set) {
  13631. if (isUndefined(debugEnviron))
  13632. debugEnviron = process.env.NODE_DEBUG || '';
  13633. set = set.toUpperCase();
  13634. if (!debugs[set]) {
  13635. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  13636. var pid = process.pid;
  13637. debugs[set] = function() {
  13638. var msg = exports.format.apply(exports, arguments);
  13639. console.error('%s %d: %s', set, pid, msg);
  13640. };
  13641. } else {
  13642. debugs[set] = function() {};
  13643. }
  13644. }
  13645. return debugs[set];
  13646. };
  13647. /**
  13648. * Echos the value of a value. Trys to print the value out
  13649. * in the best way possible given the different types.
  13650. *
  13651. * @param {Object} obj The object to print out.
  13652. * @param {Object} opts Optional options object that alters the output.
  13653. */
  13654. /* legacy: obj, showHidden, depth, colors*/
  13655. function inspect(obj, opts) {
  13656. // default options
  13657. var ctx = {
  13658. seen: [],
  13659. stylize: stylizeNoColor
  13660. };
  13661. // legacy...
  13662. if (arguments.length >= 3) ctx.depth = arguments[2];
  13663. if (arguments.length >= 4) ctx.colors = arguments[3];
  13664. if (isBoolean(opts)) {
  13665. // legacy...
  13666. ctx.showHidden = opts;
  13667. } else if (opts) {
  13668. // got an "options" object
  13669. exports._extend(ctx, opts);
  13670. }
  13671. // set default options
  13672. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  13673. if (isUndefined(ctx.depth)) ctx.depth = 2;
  13674. if (isUndefined(ctx.colors)) ctx.colors = false;
  13675. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  13676. if (ctx.colors) ctx.stylize = stylizeWithColor;
  13677. return formatValue(ctx, obj, ctx.depth);
  13678. }
  13679. exports.inspect = inspect;
  13680. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  13681. inspect.colors = {
  13682. 'bold' : [1, 22],
  13683. 'italic' : [3, 23],
  13684. 'underline' : [4, 24],
  13685. 'inverse' : [7, 27],
  13686. 'white' : [37, 39],
  13687. 'grey' : [90, 39],
  13688. 'black' : [30, 39],
  13689. 'blue' : [34, 39],
  13690. 'cyan' : [36, 39],
  13691. 'green' : [32, 39],
  13692. 'magenta' : [35, 39],
  13693. 'red' : [31, 39],
  13694. 'yellow' : [33, 39]
  13695. };
  13696. // Don't use 'blue' not visible on cmd.exe
  13697. inspect.styles = {
  13698. 'special': 'cyan',
  13699. 'number': 'yellow',
  13700. 'boolean': 'yellow',
  13701. 'undefined': 'grey',
  13702. 'null': 'bold',
  13703. 'string': 'green',
  13704. 'date': 'magenta',
  13705. // "name": intentionally not styling
  13706. 'regexp': 'red'
  13707. };
  13708. function stylizeWithColor(str, styleType) {
  13709. var style = inspect.styles[styleType];
  13710. if (style) {
  13711. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  13712. '\u001b[' + inspect.colors[style][1] + 'm';
  13713. } else {
  13714. return str;
  13715. }
  13716. }
  13717. function stylizeNoColor(str, styleType) {
  13718. return str;
  13719. }
  13720. function arrayToHash(array) {
  13721. var hash = {};
  13722. array.forEach(function(val, idx) {
  13723. hash[val] = true;
  13724. });
  13725. return hash;
  13726. }
  13727. function formatValue(ctx, value, recurseTimes) {
  13728. // Provide a hook for user-specified inspect functions.
  13729. // Check that value is an object with an inspect function on it
  13730. if (ctx.customInspect &&
  13731. value &&
  13732. isFunction(value.inspect) &&
  13733. // Filter out the util module, it's inspect function is special
  13734. value.inspect !== exports.inspect &&
  13735. // Also filter out any prototype objects using the circular check.
  13736. !(value.constructor && value.constructor.prototype === value)) {
  13737. var ret = value.inspect(recurseTimes, ctx);
  13738. if (!isString(ret)) {
  13739. ret = formatValue(ctx, ret, recurseTimes);
  13740. }
  13741. return ret;
  13742. }
  13743. // Primitive types cannot have properties
  13744. var primitive = formatPrimitive(ctx, value);
  13745. if (primitive) {
  13746. return primitive;
  13747. }
  13748. // Look up the keys of the object.
  13749. var keys = Object.keys(value);
  13750. var visibleKeys = arrayToHash(keys);
  13751. if (ctx.showHidden) {
  13752. keys = Object.getOwnPropertyNames(value);
  13753. }
  13754. // IE doesn't make error fields non-enumerable
  13755. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  13756. if (isError(value)
  13757. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  13758. return formatError(value);
  13759. }
  13760. // Some type of object without properties can be shortcutted.
  13761. if (keys.length === 0) {
  13762. if (isFunction(value)) {
  13763. var name = value.name ? ': ' + value.name : '';
  13764. return ctx.stylize('[Function' + name + ']', 'special');
  13765. }
  13766. if (isRegExp(value)) {
  13767. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  13768. }
  13769. if (isDate(value)) {
  13770. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  13771. }
  13772. if (isError(value)) {
  13773. return formatError(value);
  13774. }
  13775. }
  13776. var base = '', array = false, braces = ['{', '}'];
  13777. // Make Array say that they are Array
  13778. if (isArray(value)) {
  13779. array = true;
  13780. braces = ['[', ']'];
  13781. }
  13782. // Make functions say that they are functions
  13783. if (isFunction(value)) {
  13784. var n = value.name ? ': ' + value.name : '';
  13785. base = ' [Function' + n + ']';
  13786. }
  13787. // Make RegExps say that they are RegExps
  13788. if (isRegExp(value)) {
  13789. base = ' ' + RegExp.prototype.toString.call(value);
  13790. }
  13791. // Make dates with properties first say the date
  13792. if (isDate(value)) {
  13793. base = ' ' + Date.prototype.toUTCString.call(value);
  13794. }
  13795. // Make error with message first say the error
  13796. if (isError(value)) {
  13797. base = ' ' + formatError(value);
  13798. }
  13799. if (keys.length === 0 && (!array || value.length == 0)) {
  13800. return braces[0] + base + braces[1];
  13801. }
  13802. if (recurseTimes < 0) {
  13803. if (isRegExp(value)) {
  13804. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  13805. } else {
  13806. return ctx.stylize('[Object]', 'special');
  13807. }
  13808. }
  13809. ctx.seen.push(value);
  13810. var output;
  13811. if (array) {
  13812. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  13813. } else {
  13814. output = keys.map(function(key) {
  13815. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  13816. });
  13817. }
  13818. ctx.seen.pop();
  13819. return reduceToSingleString(output, base, braces);
  13820. }
  13821. function formatPrimitive(ctx, value) {
  13822. if (isUndefined(value))
  13823. return ctx.stylize('undefined', 'undefined');
  13824. if (isString(value)) {
  13825. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  13826. .replace(/'/g, "\\'")
  13827. .replace(/\\"/g, '"') + '\'';
  13828. return ctx.stylize(simple, 'string');
  13829. }
  13830. if (isNumber(value))
  13831. return ctx.stylize('' + value, 'number');
  13832. if (isBoolean(value))
  13833. return ctx.stylize('' + value, 'boolean');
  13834. // For some reason typeof null is "object", so special case here.
  13835. if (isNull(value))
  13836. return ctx.stylize('null', 'null');
  13837. }
  13838. function formatError(value) {
  13839. return '[' + Error.prototype.toString.call(value) + ']';
  13840. }
  13841. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  13842. var output = [];
  13843. for (var i = 0, l = value.length; i < l; ++i) {
  13844. if (hasOwnProperty(value, String(i))) {
  13845. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  13846. String(i), true));
  13847. } else {
  13848. output.push('');
  13849. }
  13850. }
  13851. keys.forEach(function(key) {
  13852. if (!key.match(/^\d+$/)) {
  13853. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  13854. key, true));
  13855. }
  13856. });
  13857. return output;
  13858. }
  13859. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  13860. var name, str, desc;
  13861. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  13862. if (desc.get) {
  13863. if (desc.set) {
  13864. str = ctx.stylize('[Getter/Setter]', 'special');
  13865. } else {
  13866. str = ctx.stylize('[Getter]', 'special');
  13867. }
  13868. } else {
  13869. if (desc.set) {
  13870. str = ctx.stylize('[Setter]', 'special');
  13871. }
  13872. }
  13873. if (!hasOwnProperty(visibleKeys, key)) {
  13874. name = '[' + key + ']';
  13875. }
  13876. if (!str) {
  13877. if (ctx.seen.indexOf(desc.value) < 0) {
  13878. if (isNull(recurseTimes)) {
  13879. str = formatValue(ctx, desc.value, null);
  13880. } else {
  13881. str = formatValue(ctx, desc.value, recurseTimes - 1);
  13882. }
  13883. if (str.indexOf('\n') > -1) {
  13884. if (array) {
  13885. str = str.split('\n').map(function(line) {
  13886. return ' ' + line;
  13887. }).join('\n').substr(2);
  13888. } else {
  13889. str = '\n' + str.split('\n').map(function(line) {
  13890. return ' ' + line;
  13891. }).join('\n');
  13892. }
  13893. }
  13894. } else {
  13895. str = ctx.stylize('[Circular]', 'special');
  13896. }
  13897. }
  13898. if (isUndefined(name)) {
  13899. if (array && key.match(/^\d+$/)) {
  13900. return str;
  13901. }
  13902. name = JSON.stringify('' + key);
  13903. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  13904. name = name.substr(1, name.length - 2);
  13905. name = ctx.stylize(name, 'name');
  13906. } else {
  13907. name = name.replace(/'/g, "\\'")
  13908. .replace(/\\"/g, '"')
  13909. .replace(/(^"|"$)/g, "'");
  13910. name = ctx.stylize(name, 'string');
  13911. }
  13912. }
  13913. return name + ': ' + str;
  13914. }
  13915. function reduceToSingleString(output, base, braces) {
  13916. var numLinesEst = 0;
  13917. var length = output.reduce(function(prev, cur) {
  13918. numLinesEst++;
  13919. if (cur.indexOf('\n') >= 0) numLinesEst++;
  13920. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  13921. }, 0);
  13922. if (length > 60) {
  13923. return braces[0] +
  13924. (base === '' ? '' : base + '\n ') +
  13925. ' ' +
  13926. output.join(',\n ') +
  13927. ' ' +
  13928. braces[1];
  13929. }
  13930. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  13931. }
  13932. // NOTE: These type checking functions intentionally don't use `instanceof`
  13933. // because it is fragile and can be easily faked with `Object.create()`.
  13934. function isArray(ar) {
  13935. return Array.isArray(ar);
  13936. }
  13937. exports.isArray = isArray;
  13938. function isBoolean(arg) {
  13939. return typeof arg === 'boolean';
  13940. }
  13941. exports.isBoolean = isBoolean;
  13942. function isNull(arg) {
  13943. return arg === null;
  13944. }
  13945. exports.isNull = isNull;
  13946. function isNullOrUndefined(arg) {
  13947. return arg == null;
  13948. }
  13949. exports.isNullOrUndefined = isNullOrUndefined;
  13950. function isNumber(arg) {
  13951. return typeof arg === 'number';
  13952. }
  13953. exports.isNumber = isNumber;
  13954. function isString(arg) {
  13955. return typeof arg === 'string';
  13956. }
  13957. exports.isString = isString;
  13958. function isSymbol(arg) {
  13959. return typeof arg === 'symbol';
  13960. }
  13961. exports.isSymbol = isSymbol;
  13962. function isUndefined(arg) {
  13963. return arg === void 0;
  13964. }
  13965. exports.isUndefined = isUndefined;
  13966. function isRegExp(re) {
  13967. return isObject(re) && objectToString(re) === '[object RegExp]';
  13968. }
  13969. exports.isRegExp = isRegExp;
  13970. function isObject(arg) {
  13971. return typeof arg === 'object' && arg !== null;
  13972. }
  13973. exports.isObject = isObject;
  13974. function isDate(d) {
  13975. return isObject(d) && objectToString(d) === '[object Date]';
  13976. }
  13977. exports.isDate = isDate;
  13978. function isError(e) {
  13979. return isObject(e) &&
  13980. (objectToString(e) === '[object Error]' || e instanceof Error);
  13981. }
  13982. exports.isError = isError;
  13983. function isFunction(arg) {
  13984. return typeof arg === 'function';
  13985. }
  13986. exports.isFunction = isFunction;
  13987. function isPrimitive(arg) {
  13988. return arg === null ||
  13989. typeof arg === 'boolean' ||
  13990. typeof arg === 'number' ||
  13991. typeof arg === 'string' ||
  13992. typeof arg === 'symbol' || // ES6 symbol
  13993. typeof arg === 'undefined';
  13994. }
  13995. exports.isPrimitive = isPrimitive;
  13996. exports.isBuffer = require('./support/isBuffer');
  13997. function objectToString(o) {
  13998. return Object.prototype.toString.call(o);
  13999. }
  14000. function pad(n) {
  14001. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  14002. }
  14003. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  14004. 'Oct', 'Nov', 'Dec'];
  14005. // 26 Feb 16:19:34
  14006. function timestamp() {
  14007. var d = new Date();
  14008. var time = [pad(d.getHours()),
  14009. pad(d.getMinutes()),
  14010. pad(d.getSeconds())].join(':');
  14011. return [d.getDate(), months[d.getMonth()], time].join(' ');
  14012. }
  14013. // log is just a thin wrapper to console.log that prepends a timestamp
  14014. exports.log = function() {
  14015. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  14016. };
  14017. /**
  14018. * Inherit the prototype methods from one constructor into another.
  14019. *
  14020. * The Function.prototype.inherits from lang.js rewritten as a standalone
  14021. * function (not on Function.prototype). NOTE: If this file is to be loaded
  14022. * during bootstrapping this function needs to be rewritten using some native
  14023. * functions as prototype setup using normal JavaScript does not work as
  14024. * expected during bootstrapping (see mirror.js in r114903).
  14025. *
  14026. * @param {function} ctor Constructor function which needs to inherit the
  14027. * prototype.
  14028. * @param {function} superCtor Constructor function to inherit prototype from.
  14029. */
  14030. exports.inherits = require('inherits');
  14031. exports._extend = function(origin, add) {
  14032. // Don't do anything if add isn't an object
  14033. if (!add || !isObject(add)) return origin;
  14034. var keys = Object.keys(add);
  14035. var i = keys.length;
  14036. while (i--) {
  14037. origin[keys[i]] = add[keys[i]];
  14038. }
  14039. return origin;
  14040. };
  14041. function hasOwnProperty(obj, prop) {
  14042. return Object.prototype.hasOwnProperty.call(obj, prop);
  14043. }
  14044. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  14045. },{"./support/isBuffer":98,"_process":82,"inherits":97}]},{},[1]);