mocha.js 327 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149
  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. /**
  4. * Shim process.stdout.
  5. */
  6. process.stdout = require('browser-stdout')();
  7. var Mocha = require('./lib/mocha');
  8. /**
  9. * Create a Mocha instance.
  10. *
  11. * @return {undefined}
  12. */
  13. var mocha = new Mocha({ reporter: 'html' });
  14. /**
  15. * Save timer references to avoid Sinon interfering (see GH-237).
  16. */
  17. var Date = global.Date;
  18. var setTimeout = global.setTimeout;
  19. var setInterval = global.setInterval;
  20. var clearTimeout = global.clearTimeout;
  21. var clearInterval = global.clearInterval;
  22. var uncaughtExceptionHandlers = [];
  23. var originalOnerrorHandler = global.onerror;
  24. /**
  25. * Remove uncaughtException listener.
  26. * Revert to original onerror handler if previously defined.
  27. */
  28. process.removeListener = function(e, fn){
  29. if ('uncaughtException' == e) {
  30. if (originalOnerrorHandler) {
  31. global.onerror = originalOnerrorHandler;
  32. } else {
  33. global.onerror = function() {};
  34. }
  35. var i = Mocha.utils.indexOf(uncaughtExceptionHandlers, fn);
  36. if (i != -1) { uncaughtExceptionHandlers.splice(i, 1); }
  37. }
  38. };
  39. /**
  40. * Implements uncaughtException listener.
  41. */
  42. process.on = function(e, fn){
  43. if ('uncaughtException' == e) {
  44. global.onerror = function(err, url, line){
  45. fn(new Error(err + ' (' + url + ':' + line + ')'));
  46. return !mocha.allowUncaught;
  47. };
  48. uncaughtExceptionHandlers.push(fn);
  49. }
  50. };
  51. // The BDD UI is registered by default, but no UI will be functional in the
  52. // browser without an explicit call to the overridden `mocha.ui` (see below).
  53. // Ensure that this default UI does not expose its methods to the global scope.
  54. mocha.suite.removeAllListeners('pre-require');
  55. var immediateQueue = []
  56. , immediateTimeout;
  57. function timeslice() {
  58. var immediateStart = new Date().getTime();
  59. while (immediateQueue.length && (new Date().getTime() - immediateStart) < 100) {
  60. immediateQueue.shift()();
  61. }
  62. if (immediateQueue.length) {
  63. immediateTimeout = setTimeout(timeslice, 0);
  64. } else {
  65. immediateTimeout = null;
  66. }
  67. }
  68. /**
  69. * High-performance override of Runner.immediately.
  70. */
  71. Mocha.Runner.immediately = function(callback) {
  72. immediateQueue.push(callback);
  73. if (!immediateTimeout) {
  74. immediateTimeout = setTimeout(timeslice, 0);
  75. }
  76. };
  77. /**
  78. * Function to allow assertion libraries to throw errors directly into mocha.
  79. * This is useful when running tests in a browser because window.onerror will
  80. * only receive the 'message' attribute of the Error.
  81. */
  82. mocha.throwError = function(err) {
  83. Mocha.utils.forEach(uncaughtExceptionHandlers, function (fn) {
  84. fn(err);
  85. });
  86. throw err;
  87. };
  88. /**
  89. * Override ui to ensure that the ui functions are initialized.
  90. * Normally this would happen in Mocha.prototype.loadFiles.
  91. */
  92. mocha.ui = function(ui){
  93. Mocha.prototype.ui.call(this, ui);
  94. this.suite.emit('pre-require', global, null, this);
  95. return this;
  96. };
  97. /**
  98. * Setup mocha with the given setting options.
  99. */
  100. mocha.setup = function(opts){
  101. if ('string' == typeof opts) opts = { ui: opts };
  102. for (var opt in opts) this[opt](opts[opt]);
  103. return this;
  104. };
  105. /**
  106. * Run mocha, returning the Runner.
  107. */
  108. mocha.run = function(fn){
  109. var options = mocha.options;
  110. mocha.globals('location');
  111. var query = Mocha.utils.parseQuery(global.location.search || '');
  112. if (query.grep) mocha.grep(new RegExp(query.grep));
  113. if (query.fgrep) mocha.grep(query.fgrep);
  114. if (query.invert) mocha.invert();
  115. return Mocha.prototype.run.call(mocha, function(err){
  116. // The DOM Document is not available in Web Workers.
  117. var document = global.document;
  118. if (document && document.getElementById('mocha') && options.noHighlighting !== true) {
  119. Mocha.utils.highlightTags('code');
  120. }
  121. if (fn) fn(err);
  122. });
  123. };
  124. /**
  125. * Expose the process shim.
  126. * https://github.com/mochajs/mocha/pull/916
  127. */
  128. Mocha.process = process;
  129. /**
  130. * Expose mocha.
  131. */
  132. global.Mocha = Mocha;
  133. global.mocha = mocha;
  134. // this allows test/acceptance/required-tokens.js to pass; thus,
  135. // you can now do `const describe = require('mocha').describe` in a
  136. // browser context (assuming browserification). should fix #880
  137. module.exports = global;
  138. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  139. },{"./lib/mocha":14,"_process":58,"browser-stdout":42}],2:[function(require,module,exports){
  140. /* eslint-disable no-unused-vars */
  141. module.exports = function(type) {
  142. return function() {};
  143. };
  144. },{}],3:[function(require,module,exports){
  145. /**
  146. * Module exports.
  147. */
  148. exports.EventEmitter = EventEmitter;
  149. /**
  150. * Object#toString reference.
  151. */
  152. var objToString = Object.prototype.toString;
  153. /**
  154. * Check if a value is an array.
  155. *
  156. * @api private
  157. * @param {*} val The value to test.
  158. * @return {boolean} true if the value is an array, otherwise false.
  159. */
  160. function isArray(val) {
  161. return objToString.call(val) === '[object Array]';
  162. }
  163. /**
  164. * Event emitter constructor.
  165. *
  166. * @api public
  167. */
  168. function EventEmitter() {}
  169. /**
  170. * Add a listener.
  171. *
  172. * @api public
  173. * @param {string} name Event name.
  174. * @param {Function} fn Event handler.
  175. * @return {EventEmitter} Emitter instance.
  176. */
  177. EventEmitter.prototype.on = function(name, fn) {
  178. if (!this.$events) {
  179. this.$events = {};
  180. }
  181. if (!this.$events[name]) {
  182. this.$events[name] = fn;
  183. } else if (isArray(this.$events[name])) {
  184. this.$events[name].push(fn);
  185. } else {
  186. this.$events[name] = [this.$events[name], fn];
  187. }
  188. return this;
  189. };
  190. EventEmitter.prototype.addListener = EventEmitter.prototype.on;
  191. /**
  192. * Adds a volatile listener.
  193. *
  194. * @api public
  195. * @param {string} name Event name.
  196. * @param {Function} fn Event handler.
  197. * @return {EventEmitter} Emitter instance.
  198. */
  199. EventEmitter.prototype.once = function(name, fn) {
  200. var self = this;
  201. function on() {
  202. self.removeListener(name, on);
  203. fn.apply(this, arguments);
  204. }
  205. on.listener = fn;
  206. this.on(name, on);
  207. return this;
  208. };
  209. /**
  210. * Remove a listener.
  211. *
  212. * @api public
  213. * @param {string} name Event name.
  214. * @param {Function} fn Event handler.
  215. * @return {EventEmitter} Emitter instance.
  216. */
  217. EventEmitter.prototype.removeListener = function(name, fn) {
  218. if (this.$events && this.$events[name]) {
  219. var list = this.$events[name];
  220. if (isArray(list)) {
  221. var pos = -1;
  222. for (var i = 0, l = list.length; i < l; i++) {
  223. if (list[i] === fn || (list[i].listener && list[i].listener === fn)) {
  224. pos = i;
  225. break;
  226. }
  227. }
  228. if (pos < 0) {
  229. return this;
  230. }
  231. list.splice(pos, 1);
  232. if (!list.length) {
  233. delete this.$events[name];
  234. }
  235. } else if (list === fn || (list.listener && list.listener === fn)) {
  236. delete this.$events[name];
  237. }
  238. }
  239. return this;
  240. };
  241. /**
  242. * Remove all listeners for an event.
  243. *
  244. * @api public
  245. * @param {string} name Event name.
  246. * @return {EventEmitter} Emitter instance.
  247. */
  248. EventEmitter.prototype.removeAllListeners = function(name) {
  249. if (name === undefined) {
  250. this.$events = {};
  251. return this;
  252. }
  253. if (this.$events && this.$events[name]) {
  254. this.$events[name] = null;
  255. }
  256. return this;
  257. };
  258. /**
  259. * Get all listeners for a given event.
  260. *
  261. * @api public
  262. * @param {string} name Event name.
  263. * @return {EventEmitter} Emitter instance.
  264. */
  265. EventEmitter.prototype.listeners = function(name) {
  266. if (!this.$events) {
  267. this.$events = {};
  268. }
  269. if (!this.$events[name]) {
  270. this.$events[name] = [];
  271. }
  272. if (!isArray(this.$events[name])) {
  273. this.$events[name] = [this.$events[name]];
  274. }
  275. return this.$events[name];
  276. };
  277. /**
  278. * Emit an event.
  279. *
  280. * @api public
  281. * @param {string} name Event name.
  282. * @return {boolean} true if at least one handler was invoked, else false.
  283. */
  284. EventEmitter.prototype.emit = function(name) {
  285. if (!this.$events) {
  286. return false;
  287. }
  288. var handler = this.$events[name];
  289. if (!handler) {
  290. return false;
  291. }
  292. var args = Array.prototype.slice.call(arguments, 1);
  293. if (typeof handler === 'function') {
  294. handler.apply(this, args);
  295. } else if (isArray(handler)) {
  296. var listeners = handler.slice();
  297. for (var i = 0, l = listeners.length; i < l; i++) {
  298. listeners[i].apply(this, args);
  299. }
  300. } else {
  301. return false;
  302. }
  303. return true;
  304. };
  305. },{}],4:[function(require,module,exports){
  306. /**
  307. * Expose `Progress`.
  308. */
  309. module.exports = Progress;
  310. /**
  311. * Initialize a new `Progress` indicator.
  312. */
  313. function Progress() {
  314. this.percent = 0;
  315. this.size(0);
  316. this.fontSize(11);
  317. this.font('helvetica, arial, sans-serif');
  318. }
  319. /**
  320. * Set progress size to `size`.
  321. *
  322. * @api public
  323. * @param {number} size
  324. * @return {Progress} Progress instance.
  325. */
  326. Progress.prototype.size = function(size) {
  327. this._size = size;
  328. return this;
  329. };
  330. /**
  331. * Set text to `text`.
  332. *
  333. * @api public
  334. * @param {string} text
  335. * @return {Progress} Progress instance.
  336. */
  337. Progress.prototype.text = function(text) {
  338. this._text = text;
  339. return this;
  340. };
  341. /**
  342. * Set font size to `size`.
  343. *
  344. * @api public
  345. * @param {number} size
  346. * @return {Progress} Progress instance.
  347. */
  348. Progress.prototype.fontSize = function(size) {
  349. this._fontSize = size;
  350. return this;
  351. };
  352. /**
  353. * Set font to `family`.
  354. *
  355. * @param {string} family
  356. * @return {Progress} Progress instance.
  357. */
  358. Progress.prototype.font = function(family) {
  359. this._font = family;
  360. return this;
  361. };
  362. /**
  363. * Update percentage to `n`.
  364. *
  365. * @param {number} n
  366. * @return {Progress} Progress instance.
  367. */
  368. Progress.prototype.update = function(n) {
  369. this.percent = n;
  370. return this;
  371. };
  372. /**
  373. * Draw on `ctx`.
  374. *
  375. * @param {CanvasRenderingContext2d} ctx
  376. * @return {Progress} Progress instance.
  377. */
  378. Progress.prototype.draw = function(ctx) {
  379. try {
  380. var percent = Math.min(this.percent, 100);
  381. var size = this._size;
  382. var half = size / 2;
  383. var x = half;
  384. var y = half;
  385. var rad = half - 1;
  386. var fontSize = this._fontSize;
  387. ctx.font = fontSize + 'px ' + this._font;
  388. var angle = Math.PI * 2 * (percent / 100);
  389. ctx.clearRect(0, 0, size, size);
  390. // outer circle
  391. ctx.strokeStyle = '#9f9f9f';
  392. ctx.beginPath();
  393. ctx.arc(x, y, rad, 0, angle, false);
  394. ctx.stroke();
  395. // inner circle
  396. ctx.strokeStyle = '#eee';
  397. ctx.beginPath();
  398. ctx.arc(x, y, rad - 1, 0, angle, true);
  399. ctx.stroke();
  400. // text
  401. var text = this._text || (percent | 0) + '%';
  402. var w = ctx.measureText(text).width;
  403. ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1);
  404. } catch (err) {
  405. // don't fail if we can't render progress
  406. }
  407. return this;
  408. };
  409. },{}],5:[function(require,module,exports){
  410. (function (global){
  411. exports.isatty = function isatty() {
  412. return true;
  413. };
  414. exports.getWindowSize = function getWindowSize() {
  415. if ('innerHeight' in global) {
  416. return [global.innerHeight, global.innerWidth];
  417. }
  418. // In a Web Worker, the DOM Window is not available.
  419. return [640, 480];
  420. };
  421. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  422. },{}],6:[function(require,module,exports){
  423. /**
  424. * Expose `Context`.
  425. */
  426. module.exports = Context;
  427. /**
  428. * Initialize a new `Context`.
  429. *
  430. * @api private
  431. */
  432. function Context() {}
  433. /**
  434. * Set or get the context `Runnable` to `runnable`.
  435. *
  436. * @api private
  437. * @param {Runnable} runnable
  438. * @return {Context}
  439. */
  440. Context.prototype.runnable = function(runnable) {
  441. if (!arguments.length) {
  442. return this._runnable;
  443. }
  444. this.test = this._runnable = runnable;
  445. return this;
  446. };
  447. /**
  448. * Set test timeout `ms`.
  449. *
  450. * @api private
  451. * @param {number} ms
  452. * @return {Context} self
  453. */
  454. Context.prototype.timeout = function(ms) {
  455. if (!arguments.length) {
  456. return this.runnable().timeout();
  457. }
  458. this.runnable().timeout(ms);
  459. return this;
  460. };
  461. /**
  462. * Set test timeout `enabled`.
  463. *
  464. * @api private
  465. * @param {boolean} enabled
  466. * @return {Context} self
  467. */
  468. Context.prototype.enableTimeouts = function(enabled) {
  469. this.runnable().enableTimeouts(enabled);
  470. return this;
  471. };
  472. /**
  473. * Set test slowness threshold `ms`.
  474. *
  475. * @api private
  476. * @param {number} ms
  477. * @return {Context} self
  478. */
  479. Context.prototype.slow = function(ms) {
  480. this.runnable().slow(ms);
  481. return this;
  482. };
  483. /**
  484. * Mark a test as skipped.
  485. *
  486. * @api private
  487. * @return {Context} self
  488. */
  489. Context.prototype.skip = function() {
  490. this.runnable().skip();
  491. return this;
  492. };
  493. /**
  494. * Allow a number of retries on failed tests
  495. *
  496. * @api private
  497. * @param {number} n
  498. * @return {Context} self
  499. */
  500. Context.prototype.retries = function(n) {
  501. if (!arguments.length) {
  502. return this.runnable().retries();
  503. }
  504. this.runnable().retries(n);
  505. return this;
  506. };
  507. /**
  508. * Inspect the context void of `._runnable`.
  509. *
  510. * @api private
  511. * @return {string}
  512. */
  513. Context.prototype.inspect = function() {
  514. return JSON.stringify(this, function(key, val) {
  515. return key === 'runnable' || key === 'test' ? undefined : val;
  516. }, 2);
  517. };
  518. },{}],7:[function(require,module,exports){
  519. /**
  520. * Module dependencies.
  521. */
  522. var Runnable = require('./runnable');
  523. var inherits = require('./utils').inherits;
  524. /**
  525. * Expose `Hook`.
  526. */
  527. module.exports = Hook;
  528. /**
  529. * Initialize a new `Hook` with the given `title` and callback `fn`.
  530. *
  531. * @param {String} title
  532. * @param {Function} fn
  533. * @api private
  534. */
  535. function Hook(title, fn) {
  536. Runnable.call(this, title, fn);
  537. this.type = 'hook';
  538. }
  539. /**
  540. * Inherit from `Runnable.prototype`.
  541. */
  542. inherits(Hook, Runnable);
  543. /**
  544. * Get or set the test `err`.
  545. *
  546. * @param {Error} err
  547. * @return {Error}
  548. * @api public
  549. */
  550. Hook.prototype.error = function(err) {
  551. if (!arguments.length) {
  552. err = this._error;
  553. this._error = null;
  554. return err;
  555. }
  556. this._error = err;
  557. };
  558. },{"./runnable":35,"./utils":39}],8:[function(require,module,exports){
  559. /**
  560. * Module dependencies.
  561. */
  562. var Suite = require('../suite');
  563. var Test = require('../test');
  564. var escapeRe = require('escape-string-regexp');
  565. /**
  566. * BDD-style interface:
  567. *
  568. * describe('Array', function() {
  569. * describe('#indexOf()', function() {
  570. * it('should return -1 when not present', function() {
  571. * // ...
  572. * });
  573. *
  574. * it('should return the index when present', function() {
  575. * // ...
  576. * });
  577. * });
  578. * });
  579. *
  580. * @param {Suite} suite Root suite.
  581. */
  582. module.exports = function(suite) {
  583. var suites = [suite];
  584. suite.on('pre-require', function(context, file, mocha) {
  585. var common = require('./common')(suites, context);
  586. context.before = common.before;
  587. context.after = common.after;
  588. context.beforeEach = common.beforeEach;
  589. context.afterEach = common.afterEach;
  590. context.run = mocha.options.delay && common.runWithSuite(suite);
  591. /**
  592. * Describe a "suite" with the given `title`
  593. * and callback `fn` containing nested suites
  594. * and/or tests.
  595. */
  596. context.describe = context.context = function(title, fn) {
  597. var suite = Suite.create(suites[0], title);
  598. suite.file = file;
  599. suites.unshift(suite);
  600. fn.call(suite);
  601. suites.shift();
  602. return suite;
  603. };
  604. /**
  605. * Pending describe.
  606. */
  607. context.xdescribe = context.xcontext = context.describe.skip = function(title, fn) {
  608. var suite = Suite.create(suites[0], title);
  609. suite.pending = true;
  610. suites.unshift(suite);
  611. fn.call(suite);
  612. suites.shift();
  613. };
  614. /**
  615. * Exclusive suite.
  616. */
  617. context.describe.only = function(title, fn) {
  618. var suite = context.describe(title, fn);
  619. mocha.grep(suite.fullTitle());
  620. return suite;
  621. };
  622. /**
  623. * Describe a specification or test-case
  624. * with the given `title` and callback `fn`
  625. * acting as a thunk.
  626. */
  627. var it = context.it = context.specify = function(title, fn) {
  628. var suite = suites[0];
  629. if (suite.isPending()) {
  630. fn = null;
  631. }
  632. var test = new Test(title, fn);
  633. test.file = file;
  634. suite.addTest(test);
  635. return test;
  636. };
  637. /**
  638. * Exclusive test-case.
  639. */
  640. context.it.only = function(title, fn) {
  641. var test = it(title, fn);
  642. var reString = '^' + escapeRe(test.fullTitle()) + '$';
  643. mocha.grep(new RegExp(reString));
  644. return test;
  645. };
  646. /**
  647. * Pending test case.
  648. */
  649. context.xit = context.xspecify = context.it.skip = function(title) {
  650. context.it(title);
  651. };
  652. /**
  653. * Number of attempts to retry.
  654. */
  655. context.it.retries = function(n) {
  656. context.retries(n);
  657. };
  658. });
  659. };
  660. },{"../suite":37,"../test":38,"./common":9,"escape-string-regexp":49}],9:[function(require,module,exports){
  661. 'use strict';
  662. /**
  663. * Functions common to more than one interface.
  664. *
  665. * @param {Suite[]} suites
  666. * @param {Context} context
  667. * @return {Object} An object containing common functions.
  668. */
  669. module.exports = function(suites, context) {
  670. return {
  671. /**
  672. * This is only present if flag --delay is passed into Mocha. It triggers
  673. * root suite execution.
  674. *
  675. * @param {Suite} suite The root wuite.
  676. * @return {Function} A function which runs the root suite
  677. */
  678. runWithSuite: function runWithSuite(suite) {
  679. return function run() {
  680. suite.run();
  681. };
  682. },
  683. /**
  684. * Execute before running tests.
  685. *
  686. * @param {string} name
  687. * @param {Function} fn
  688. */
  689. before: function(name, fn) {
  690. suites[0].beforeAll(name, fn);
  691. },
  692. /**
  693. * Execute after running tests.
  694. *
  695. * @param {string} name
  696. * @param {Function} fn
  697. */
  698. after: function(name, fn) {
  699. suites[0].afterAll(name, fn);
  700. },
  701. /**
  702. * Execute before each test case.
  703. *
  704. * @param {string} name
  705. * @param {Function} fn
  706. */
  707. beforeEach: function(name, fn) {
  708. suites[0].beforeEach(name, fn);
  709. },
  710. /**
  711. * Execute after each test case.
  712. *
  713. * @param {string} name
  714. * @param {Function} fn
  715. */
  716. afterEach: function(name, fn) {
  717. suites[0].afterEach(name, fn);
  718. },
  719. test: {
  720. /**
  721. * Pending test case.
  722. *
  723. * @param {string} title
  724. */
  725. skip: function(title) {
  726. context.test(title);
  727. },
  728. /**
  729. * Number of retry attempts
  730. *
  731. * @param {number} n
  732. */
  733. retries: function(n) {
  734. context.retries(n);
  735. }
  736. }
  737. };
  738. };
  739. },{}],10:[function(require,module,exports){
  740. /**
  741. * Module dependencies.
  742. */
  743. var Suite = require('../suite');
  744. var Test = require('../test');
  745. /**
  746. * Exports-style (as Node.js module) interface:
  747. *
  748. * exports.Array = {
  749. * '#indexOf()': {
  750. * 'should return -1 when the value is not present': function() {
  751. *
  752. * },
  753. *
  754. * 'should return the correct index when the value is present': function() {
  755. *
  756. * }
  757. * }
  758. * };
  759. *
  760. * @param {Suite} suite Root suite.
  761. */
  762. module.exports = function(suite) {
  763. var suites = [suite];
  764. suite.on('require', visit);
  765. function visit(obj, file) {
  766. var suite;
  767. for (var key in obj) {
  768. if (typeof obj[key] === 'function') {
  769. var fn = obj[key];
  770. switch (key) {
  771. case 'before':
  772. suites[0].beforeAll(fn);
  773. break;
  774. case 'after':
  775. suites[0].afterAll(fn);
  776. break;
  777. case 'beforeEach':
  778. suites[0].beforeEach(fn);
  779. break;
  780. case 'afterEach':
  781. suites[0].afterEach(fn);
  782. break;
  783. default:
  784. var test = new Test(key, fn);
  785. test.file = file;
  786. suites[0].addTest(test);
  787. }
  788. } else {
  789. suite = Suite.create(suites[0], key);
  790. suites.unshift(suite);
  791. visit(obj[key], file);
  792. suites.shift();
  793. }
  794. }
  795. }
  796. };
  797. },{"../suite":37,"../test":38}],11:[function(require,module,exports){
  798. exports.bdd = require('./bdd');
  799. exports.tdd = require('./tdd');
  800. exports.qunit = require('./qunit');
  801. exports.exports = require('./exports');
  802. },{"./bdd":8,"./exports":10,"./qunit":12,"./tdd":13}],12:[function(require,module,exports){
  803. /**
  804. * Module dependencies.
  805. */
  806. var Suite = require('../suite');
  807. var Test = require('../test');
  808. var escapeRe = require('escape-string-regexp');
  809. /**
  810. * QUnit-style interface:
  811. *
  812. * suite('Array');
  813. *
  814. * test('#length', function() {
  815. * var arr = [1,2,3];
  816. * ok(arr.length == 3);
  817. * });
  818. *
  819. * test('#indexOf()', function() {
  820. * var arr = [1,2,3];
  821. * ok(arr.indexOf(1) == 0);
  822. * ok(arr.indexOf(2) == 1);
  823. * ok(arr.indexOf(3) == 2);
  824. * });
  825. *
  826. * suite('String');
  827. *
  828. * test('#length', function() {
  829. * ok('foo'.length == 3);
  830. * });
  831. *
  832. * @param {Suite} suite Root suite.
  833. */
  834. module.exports = function(suite) {
  835. var suites = [suite];
  836. suite.on('pre-require', function(context, file, mocha) {
  837. var common = require('./common')(suites, context);
  838. context.before = common.before;
  839. context.after = common.after;
  840. context.beforeEach = common.beforeEach;
  841. context.afterEach = common.afterEach;
  842. context.run = mocha.options.delay && common.runWithSuite(suite);
  843. /**
  844. * Describe a "suite" with the given `title`.
  845. */
  846. context.suite = function(title) {
  847. if (suites.length > 1) {
  848. suites.shift();
  849. }
  850. var suite = Suite.create(suites[0], title);
  851. suite.file = file;
  852. suites.unshift(suite);
  853. return suite;
  854. };
  855. /**
  856. * Exclusive test-case.
  857. */
  858. context.suite.only = function(title, fn) {
  859. var suite = context.suite(title, fn);
  860. mocha.grep(suite.fullTitle());
  861. };
  862. /**
  863. * Describe a specification or test-case
  864. * with the given `title` and callback `fn`
  865. * acting as a thunk.
  866. */
  867. context.test = function(title, fn) {
  868. var test = new Test(title, fn);
  869. test.file = file;
  870. suites[0].addTest(test);
  871. return test;
  872. };
  873. /**
  874. * Exclusive test-case.
  875. */
  876. context.test.only = function(title, fn) {
  877. var test = context.test(title, fn);
  878. var reString = '^' + escapeRe(test.fullTitle()) + '$';
  879. mocha.grep(new RegExp(reString));
  880. };
  881. context.test.skip = common.test.skip;
  882. context.test.retries = common.test.retries;
  883. });
  884. };
  885. },{"../suite":37,"../test":38,"./common":9,"escape-string-regexp":49}],13:[function(require,module,exports){
  886. /**
  887. * Module dependencies.
  888. */
  889. var Suite = require('../suite');
  890. var Test = require('../test');
  891. var escapeRe = require('escape-string-regexp');
  892. /**
  893. * TDD-style interface:
  894. *
  895. * suite('Array', function() {
  896. * suite('#indexOf()', function() {
  897. * suiteSetup(function() {
  898. *
  899. * });
  900. *
  901. * test('should return -1 when not present', function() {
  902. *
  903. * });
  904. *
  905. * test('should return the index when present', function() {
  906. *
  907. * });
  908. *
  909. * suiteTeardown(function() {
  910. *
  911. * });
  912. * });
  913. * });
  914. *
  915. * @param {Suite} suite Root suite.
  916. */
  917. module.exports = function(suite) {
  918. var suites = [suite];
  919. suite.on('pre-require', function(context, file, mocha) {
  920. var common = require('./common')(suites, context);
  921. context.setup = common.beforeEach;
  922. context.teardown = common.afterEach;
  923. context.suiteSetup = common.before;
  924. context.suiteTeardown = common.after;
  925. context.run = mocha.options.delay && common.runWithSuite(suite);
  926. /**
  927. * Describe a "suite" with the given `title` and callback `fn` containing
  928. * nested suites and/or tests.
  929. */
  930. context.suite = function(title, fn) {
  931. var suite = Suite.create(suites[0], title);
  932. suite.file = file;
  933. suites.unshift(suite);
  934. fn.call(suite);
  935. suites.shift();
  936. return suite;
  937. };
  938. /**
  939. * Pending suite.
  940. */
  941. context.suite.skip = function(title, fn) {
  942. var suite = Suite.create(suites[0], title);
  943. suite.pending = true;
  944. suites.unshift(suite);
  945. fn.call(suite);
  946. suites.shift();
  947. };
  948. /**
  949. * Exclusive test-case.
  950. */
  951. context.suite.only = function(title, fn) {
  952. var suite = context.suite(title, fn);
  953. mocha.grep(suite.fullTitle());
  954. };
  955. /**
  956. * Describe a specification or test-case with the given `title` and
  957. * callback `fn` acting as a thunk.
  958. */
  959. context.test = function(title, fn) {
  960. var suite = suites[0];
  961. if (suite.isPending()) {
  962. fn = null;
  963. }
  964. var test = new Test(title, fn);
  965. test.file = file;
  966. suite.addTest(test);
  967. return test;
  968. };
  969. /**
  970. * Exclusive test-case.
  971. */
  972. context.test.only = function(title, fn) {
  973. var test = context.test(title, fn);
  974. var reString = '^' + escapeRe(test.fullTitle()) + '$';
  975. mocha.grep(new RegExp(reString));
  976. };
  977. context.test.skip = common.test.skip;
  978. context.test.retries = common.test.retries;
  979. });
  980. };
  981. },{"../suite":37,"../test":38,"./common":9,"escape-string-regexp":49}],14:[function(require,module,exports){
  982. (function (process,global,__dirname){
  983. /*!
  984. * mocha
  985. * Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
  986. * MIT Licensed
  987. */
  988. /**
  989. * Module dependencies.
  990. */
  991. var escapeRe = require('escape-string-regexp');
  992. var path = require('path');
  993. var reporters = require('./reporters');
  994. var utils = require('./utils');
  995. /**
  996. * Expose `Mocha`.
  997. */
  998. exports = module.exports = Mocha;
  999. /**
  1000. * To require local UIs and reporters when running in node.
  1001. */
  1002. if (!process.browser) {
  1003. var cwd = process.cwd();
  1004. module.paths.push(cwd, path.join(cwd, 'node_modules'));
  1005. }
  1006. /**
  1007. * Expose internals.
  1008. */
  1009. exports.utils = utils;
  1010. exports.interfaces = require('./interfaces');
  1011. exports.reporters = reporters;
  1012. exports.Runnable = require('./runnable');
  1013. exports.Context = require('./context');
  1014. exports.Runner = require('./runner');
  1015. exports.Suite = require('./suite');
  1016. exports.Hook = require('./hook');
  1017. exports.Test = require('./test');
  1018. /**
  1019. * Return image `name` path.
  1020. *
  1021. * @api private
  1022. * @param {string} name
  1023. * @return {string}
  1024. */
  1025. function image(name) {
  1026. return path.join(__dirname, '../images', name + '.png');
  1027. }
  1028. /**
  1029. * Set up mocha with `options`.
  1030. *
  1031. * Options:
  1032. *
  1033. * - `ui` name "bdd", "tdd", "exports" etc
  1034. * - `reporter` reporter instance, defaults to `mocha.reporters.spec`
  1035. * - `globals` array of accepted globals
  1036. * - `timeout` timeout in milliseconds
  1037. * - `retries` number of times to retry failed tests
  1038. * - `bail` bail on the first test failure
  1039. * - `slow` milliseconds to wait before considering a test slow
  1040. * - `ignoreLeaks` ignore global leaks
  1041. * - `fullTrace` display the full stack-trace on failing
  1042. * - `grep` string or regexp to filter tests with
  1043. *
  1044. * @param {Object} options
  1045. * @api public
  1046. */
  1047. function Mocha(options) {
  1048. options = options || {};
  1049. this.files = [];
  1050. this.options = options;
  1051. if (options.grep) {
  1052. this.grep(new RegExp(options.grep));
  1053. }
  1054. if (options.fgrep) {
  1055. this.grep(options.fgrep);
  1056. }
  1057. this.suite = new exports.Suite('', new exports.Context());
  1058. this.ui(options.ui);
  1059. this.bail(options.bail);
  1060. this.reporter(options.reporter, options.reporterOptions);
  1061. if (typeof options.timeout !== 'undefined' && options.timeout !== null) {
  1062. this.timeout(options.timeout);
  1063. }
  1064. if (typeof options.retries !== 'undefined' && options.retries !== null) {
  1065. this.retries(options.retries);
  1066. }
  1067. this.useColors(options.useColors);
  1068. if (options.enableTimeouts !== null) {
  1069. this.enableTimeouts(options.enableTimeouts);
  1070. }
  1071. if (options.slow) {
  1072. this.slow(options.slow);
  1073. }
  1074. }
  1075. /**
  1076. * Enable or disable bailing on the first failure.
  1077. *
  1078. * @api public
  1079. * @param {boolean} [bail]
  1080. */
  1081. Mocha.prototype.bail = function(bail) {
  1082. if (!arguments.length) {
  1083. bail = true;
  1084. }
  1085. this.suite.bail(bail);
  1086. return this;
  1087. };
  1088. /**
  1089. * Add test `file`.
  1090. *
  1091. * @api public
  1092. * @param {string} file
  1093. */
  1094. Mocha.prototype.addFile = function(file) {
  1095. this.files.push(file);
  1096. return this;
  1097. };
  1098. /**
  1099. * Set reporter to `reporter`, defaults to "spec".
  1100. *
  1101. * @param {String|Function} reporter name or constructor
  1102. * @param {Object} reporterOptions optional options
  1103. * @api public
  1104. * @param {string|Function} reporter name or constructor
  1105. * @param {Object} reporterOptions optional options
  1106. */
  1107. Mocha.prototype.reporter = function(reporter, reporterOptions) {
  1108. if (typeof reporter === 'function') {
  1109. this._reporter = reporter;
  1110. } else {
  1111. reporter = reporter || 'spec';
  1112. var _reporter;
  1113. // Try to load a built-in reporter.
  1114. if (reporters[reporter]) {
  1115. _reporter = reporters[reporter];
  1116. }
  1117. // Try to load reporters from process.cwd() and node_modules
  1118. if (!_reporter) {
  1119. try {
  1120. _reporter = require(reporter);
  1121. } catch (err) {
  1122. err.message.indexOf('Cannot find module') !== -1
  1123. ? console.warn('"' + reporter + '" reporter not found')
  1124. : console.warn('"' + reporter + '" reporter blew up with error:\n' + err.stack);
  1125. }
  1126. }
  1127. if (!_reporter && reporter === 'teamcity') {
  1128. console.warn('The Teamcity reporter was moved to a package named '
  1129. + 'mocha-teamcity-reporter '
  1130. + '(https://npmjs.org/package/mocha-teamcity-reporter).');
  1131. }
  1132. if (!_reporter) {
  1133. throw new Error('invalid reporter "' + reporter + '"');
  1134. }
  1135. this._reporter = _reporter;
  1136. }
  1137. this.options.reporterOptions = reporterOptions;
  1138. return this;
  1139. };
  1140. /**
  1141. * Set test UI `name`, defaults to "bdd".
  1142. *
  1143. * @api public
  1144. * @param {string} bdd
  1145. */
  1146. Mocha.prototype.ui = function(name) {
  1147. name = name || 'bdd';
  1148. this._ui = exports.interfaces[name];
  1149. if (!this._ui) {
  1150. try {
  1151. this._ui = require(name);
  1152. } catch (err) {
  1153. throw new Error('invalid interface "' + name + '"');
  1154. }
  1155. }
  1156. this._ui = this._ui(this.suite);
  1157. this.suite.on('pre-require', function(context) {
  1158. exports.afterEach = context.afterEach || context.teardown;
  1159. exports.after = context.after || context.suiteTeardown;
  1160. exports.beforeEach = context.beforeEach || context.setup;
  1161. exports.before = context.before || context.suiteSetup;
  1162. exports.describe = context.describe || context.suite;
  1163. exports.it = context.it || context.test;
  1164. exports.setup = context.setup || context.beforeEach;
  1165. exports.suiteSetup = context.suiteSetup || context.before;
  1166. exports.suiteTeardown = context.suiteTeardown || context.after;
  1167. exports.suite = context.suite || context.describe;
  1168. exports.teardown = context.teardown || context.afterEach;
  1169. exports.test = context.test || context.it;
  1170. exports.run = context.run;
  1171. });
  1172. return this;
  1173. };
  1174. /**
  1175. * Load registered files.
  1176. *
  1177. * @api private
  1178. */
  1179. Mocha.prototype.loadFiles = function(fn) {
  1180. var self = this;
  1181. var suite = this.suite;
  1182. this.files.forEach(function(file) {
  1183. file = path.resolve(file);
  1184. suite.emit('pre-require', global, file, self);
  1185. suite.emit('require', require(file), file, self);
  1186. suite.emit('post-require', global, file, self);
  1187. });
  1188. fn && fn();
  1189. };
  1190. /**
  1191. * Enable growl support.
  1192. *
  1193. * @api private
  1194. */
  1195. Mocha.prototype._growl = function(runner, reporter) {
  1196. var notify = require('growl');
  1197. runner.on('end', function() {
  1198. var stats = reporter.stats;
  1199. if (stats.failures) {
  1200. var msg = stats.failures + ' of ' + runner.total + ' tests failed';
  1201. notify(msg, { name: 'mocha', title: 'Failed', image: image('error') });
  1202. } else {
  1203. notify(stats.passes + ' tests passed in ' + stats.duration + 'ms', {
  1204. name: 'mocha',
  1205. title: 'Passed',
  1206. image: image('ok')
  1207. });
  1208. }
  1209. });
  1210. };
  1211. /**
  1212. * Add regexp to grep, if `re` is a string it is escaped.
  1213. *
  1214. * @param {RegExp|String} re
  1215. * @return {Mocha}
  1216. * @api public
  1217. * @param {RegExp|string} re
  1218. * @return {Mocha}
  1219. */
  1220. Mocha.prototype.grep = function(re) {
  1221. this.options.grep = typeof re === 'string' ? new RegExp(escapeRe(re)) : re;
  1222. return this;
  1223. };
  1224. /**
  1225. * Invert `.grep()` matches.
  1226. *
  1227. * @return {Mocha}
  1228. * @api public
  1229. */
  1230. Mocha.prototype.invert = function() {
  1231. this.options.invert = true;
  1232. return this;
  1233. };
  1234. /**
  1235. * Ignore global leaks.
  1236. *
  1237. * @param {Boolean} ignore
  1238. * @return {Mocha}
  1239. * @api public
  1240. * @param {boolean} ignore
  1241. * @return {Mocha}
  1242. */
  1243. Mocha.prototype.ignoreLeaks = function(ignore) {
  1244. this.options.ignoreLeaks = Boolean(ignore);
  1245. return this;
  1246. };
  1247. /**
  1248. * Enable global leak checking.
  1249. *
  1250. * @return {Mocha}
  1251. * @api public
  1252. */
  1253. Mocha.prototype.checkLeaks = function() {
  1254. this.options.ignoreLeaks = false;
  1255. return this;
  1256. };
  1257. /**
  1258. * Display long stack-trace on failing
  1259. *
  1260. * @return {Mocha}
  1261. * @api public
  1262. */
  1263. Mocha.prototype.fullTrace = function() {
  1264. this.options.fullStackTrace = true;
  1265. return this;
  1266. };
  1267. /**
  1268. * Enable growl support.
  1269. *
  1270. * @return {Mocha}
  1271. * @api public
  1272. */
  1273. Mocha.prototype.growl = function() {
  1274. this.options.growl = true;
  1275. return this;
  1276. };
  1277. /**
  1278. * Ignore `globals` array or string.
  1279. *
  1280. * @param {Array|String} globals
  1281. * @return {Mocha}
  1282. * @api public
  1283. * @param {Array|string} globals
  1284. * @return {Mocha}
  1285. */
  1286. Mocha.prototype.globals = function(globals) {
  1287. this.options.globals = (this.options.globals || []).concat(globals);
  1288. return this;
  1289. };
  1290. /**
  1291. * Emit color output.
  1292. *
  1293. * @param {Boolean} colors
  1294. * @return {Mocha}
  1295. * @api public
  1296. * @param {boolean} colors
  1297. * @return {Mocha}
  1298. */
  1299. Mocha.prototype.useColors = function(colors) {
  1300. if (colors !== undefined) {
  1301. this.options.useColors = colors;
  1302. }
  1303. return this;
  1304. };
  1305. /**
  1306. * Use inline diffs rather than +/-.
  1307. *
  1308. * @param {Boolean} inlineDiffs
  1309. * @return {Mocha}
  1310. * @api public
  1311. * @param {boolean} inlineDiffs
  1312. * @return {Mocha}
  1313. */
  1314. Mocha.prototype.useInlineDiffs = function(inlineDiffs) {
  1315. this.options.useInlineDiffs = inlineDiffs !== undefined && inlineDiffs;
  1316. return this;
  1317. };
  1318. /**
  1319. * Set the timeout in milliseconds.
  1320. *
  1321. * @param {Number} timeout
  1322. * @return {Mocha}
  1323. * @api public
  1324. * @param {number} timeout
  1325. * @return {Mocha}
  1326. */
  1327. Mocha.prototype.timeout = function(timeout) {
  1328. this.suite.timeout(timeout);
  1329. return this;
  1330. };
  1331. /**
  1332. * Set the number of times to retry failed tests.
  1333. *
  1334. * @param {Number} retry times
  1335. * @return {Mocha}
  1336. * @api public
  1337. */
  1338. Mocha.prototype.retries = function(n) {
  1339. this.suite.retries(n);
  1340. return this;
  1341. };
  1342. /**
  1343. * Set slowness threshold in milliseconds.
  1344. *
  1345. * @param {Number} slow
  1346. * @return {Mocha}
  1347. * @api public
  1348. * @param {number} slow
  1349. * @return {Mocha}
  1350. */
  1351. Mocha.prototype.slow = function(slow) {
  1352. this.suite.slow(slow);
  1353. return this;
  1354. };
  1355. /**
  1356. * Enable timeouts.
  1357. *
  1358. * @param {Boolean} enabled
  1359. * @return {Mocha}
  1360. * @api public
  1361. * @param {boolean} enabled
  1362. * @return {Mocha}
  1363. */
  1364. Mocha.prototype.enableTimeouts = function(enabled) {
  1365. this.suite.enableTimeouts(arguments.length && enabled !== undefined ? enabled : true);
  1366. return this;
  1367. };
  1368. /**
  1369. * Makes all tests async (accepting a callback)
  1370. *
  1371. * @return {Mocha}
  1372. * @api public
  1373. */
  1374. Mocha.prototype.asyncOnly = function() {
  1375. this.options.asyncOnly = true;
  1376. return this;
  1377. };
  1378. /**
  1379. * Disable syntax highlighting (in browser).
  1380. *
  1381. * @api public
  1382. */
  1383. Mocha.prototype.noHighlighting = function() {
  1384. this.options.noHighlighting = true;
  1385. return this;
  1386. };
  1387. /**
  1388. * Enable uncaught errors to propagate (in browser).
  1389. *
  1390. * @return {Mocha}
  1391. * @api public
  1392. */
  1393. Mocha.prototype.allowUncaught = function() {
  1394. this.options.allowUncaught = true;
  1395. return this;
  1396. };
  1397. /**
  1398. * Delay root suite execution.
  1399. * @returns {Mocha}
  1400. */
  1401. Mocha.prototype.delay = function delay() {
  1402. this.options.delay = true;
  1403. return this;
  1404. };
  1405. /**
  1406. * Run tests and invoke `fn()` when complete.
  1407. *
  1408. * @api public
  1409. * @param {Function} fn
  1410. * @return {Runner}
  1411. */
  1412. Mocha.prototype.run = function(fn) {
  1413. if (this.files.length) {
  1414. this.loadFiles();
  1415. }
  1416. var suite = this.suite;
  1417. var options = this.options;
  1418. options.files = this.files;
  1419. var runner = new exports.Runner(suite, options.delay);
  1420. var reporter = new this._reporter(runner, options);
  1421. runner.ignoreLeaks = options.ignoreLeaks !== false;
  1422. runner.fullStackTrace = options.fullStackTrace;
  1423. runner.asyncOnly = options.asyncOnly;
  1424. runner.allowUncaught = options.allowUncaught;
  1425. if (options.grep) {
  1426. runner.grep(options.grep, options.invert);
  1427. }
  1428. if (options.globals) {
  1429. runner.globals(options.globals);
  1430. }
  1431. if (options.growl) {
  1432. this._growl(runner, reporter);
  1433. }
  1434. if (options.useColors !== undefined) {
  1435. exports.reporters.Base.useColors = options.useColors;
  1436. }
  1437. exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
  1438. function done(failures) {
  1439. if (reporter.done) {
  1440. reporter.done(failures, fn);
  1441. } else {
  1442. fn && fn(failures);
  1443. }
  1444. }
  1445. return runner.run(done);
  1446. };
  1447. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},"/lib")
  1448. },{"./context":6,"./hook":7,"./interfaces":11,"./reporters":22,"./runnable":35,"./runner":36,"./suite":37,"./test":38,"./utils":39,"_process":58,"escape-string-regexp":49,"growl":51,"path":43}],15:[function(require,module,exports){
  1449. /**
  1450. * Helpers.
  1451. */
  1452. var s = 1000;
  1453. var m = s * 60;
  1454. var h = m * 60;
  1455. var d = h * 24;
  1456. var y = d * 365.25;
  1457. /**
  1458. * Parse or format the given `val`.
  1459. *
  1460. * Options:
  1461. *
  1462. * - `long` verbose formatting [false]
  1463. *
  1464. * @api public
  1465. * @param {string|number} val
  1466. * @param {Object} options
  1467. * @return {string|number}
  1468. */
  1469. module.exports = function(val, options) {
  1470. options = options || {};
  1471. if (typeof val === 'string') {
  1472. return parse(val);
  1473. }
  1474. // https://github.com/mochajs/mocha/pull/1035
  1475. return options['long'] ? longFormat(val) : shortFormat(val);
  1476. };
  1477. /**
  1478. * Parse the given `str` and return milliseconds.
  1479. *
  1480. * @api private
  1481. * @param {string} str
  1482. * @return {number}
  1483. */
  1484. function parse(str) {
  1485. var match = (/^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i).exec(str);
  1486. if (!match) {
  1487. return;
  1488. }
  1489. var n = parseFloat(match[1]);
  1490. var type = (match[2] || 'ms').toLowerCase();
  1491. switch (type) {
  1492. case 'years':
  1493. case 'year':
  1494. case 'y':
  1495. return n * y;
  1496. case 'days':
  1497. case 'day':
  1498. case 'd':
  1499. return n * d;
  1500. case 'hours':
  1501. case 'hour':
  1502. case 'h':
  1503. return n * h;
  1504. case 'minutes':
  1505. case 'minute':
  1506. case 'm':
  1507. return n * m;
  1508. case 'seconds':
  1509. case 'second':
  1510. case 's':
  1511. return n * s;
  1512. case 'ms':
  1513. return n;
  1514. default:
  1515. // No default case
  1516. }
  1517. }
  1518. /**
  1519. * Short format for `ms`.
  1520. *
  1521. * @api private
  1522. * @param {number} ms
  1523. * @return {string}
  1524. */
  1525. function shortFormat(ms) {
  1526. if (ms >= d) {
  1527. return Math.round(ms / d) + 'd';
  1528. }
  1529. if (ms >= h) {
  1530. return Math.round(ms / h) + 'h';
  1531. }
  1532. if (ms >= m) {
  1533. return Math.round(ms / m) + 'm';
  1534. }
  1535. if (ms >= s) {
  1536. return Math.round(ms / s) + 's';
  1537. }
  1538. return ms + 'ms';
  1539. }
  1540. /**
  1541. * Long format for `ms`.
  1542. *
  1543. * @api private
  1544. * @param {number} ms
  1545. * @return {string}
  1546. */
  1547. function longFormat(ms) {
  1548. return plural(ms, d, 'day')
  1549. || plural(ms, h, 'hour')
  1550. || plural(ms, m, 'minute')
  1551. || plural(ms, s, 'second')
  1552. || ms + ' ms';
  1553. }
  1554. /**
  1555. * Pluralization helper.
  1556. *
  1557. * @api private
  1558. * @param {number} ms
  1559. * @param {number} n
  1560. * @param {string} name
  1561. */
  1562. function plural(ms, n, name) {
  1563. if (ms < n) {
  1564. return;
  1565. }
  1566. if (ms < n * 1.5) {
  1567. return Math.floor(ms / n) + ' ' + name;
  1568. }
  1569. return Math.ceil(ms / n) + ' ' + name + 's';
  1570. }
  1571. },{}],16:[function(require,module,exports){
  1572. /**
  1573. * Expose `Pending`.
  1574. */
  1575. module.exports = Pending;
  1576. /**
  1577. * Initialize a new `Pending` error with the given message.
  1578. *
  1579. * @param {string} message
  1580. */
  1581. function Pending(message) {
  1582. this.message = message;
  1583. }
  1584. },{}],17:[function(require,module,exports){
  1585. (function (process,global){
  1586. /**
  1587. * Module dependencies.
  1588. */
  1589. var tty = require('tty');
  1590. var diff = require('diff');
  1591. var ms = require('../ms');
  1592. var utils = require('../utils');
  1593. var supportsColor = process.browser ? null : require('supports-color');
  1594. /**
  1595. * Expose `Base`.
  1596. */
  1597. exports = module.exports = Base;
  1598. /**
  1599. * Save timer references to avoid Sinon interfering.
  1600. * See: https://github.com/mochajs/mocha/issues/237
  1601. */
  1602. /* eslint-disable no-unused-vars, no-native-reassign */
  1603. var Date = global.Date;
  1604. var setTimeout = global.setTimeout;
  1605. var setInterval = global.setInterval;
  1606. var clearTimeout = global.clearTimeout;
  1607. var clearInterval = global.clearInterval;
  1608. /* eslint-enable no-unused-vars, no-native-reassign */
  1609. /**
  1610. * Check if both stdio streams are associated with a tty.
  1611. */
  1612. var isatty = tty.isatty(1) && tty.isatty(2);
  1613. /**
  1614. * Enable coloring by default, except in the browser interface.
  1615. */
  1616. exports.useColors = !process.browser && (supportsColor || (process.env.MOCHA_COLORS !== undefined));
  1617. /**
  1618. * Inline diffs instead of +/-
  1619. */
  1620. exports.inlineDiffs = false;
  1621. /**
  1622. * Default color map.
  1623. */
  1624. exports.colors = {
  1625. pass: 90,
  1626. fail: 31,
  1627. 'bright pass': 92,
  1628. 'bright fail': 91,
  1629. 'bright yellow': 93,
  1630. pending: 36,
  1631. suite: 0,
  1632. 'error title': 0,
  1633. 'error message': 31,
  1634. 'error stack': 90,
  1635. checkmark: 32,
  1636. fast: 90,
  1637. medium: 33,
  1638. slow: 31,
  1639. green: 32,
  1640. light: 90,
  1641. 'diff gutter': 90,
  1642. 'diff added': 32,
  1643. 'diff removed': 31
  1644. };
  1645. /**
  1646. * Default symbol map.
  1647. */
  1648. exports.symbols = {
  1649. ok: '✓',
  1650. err: '✖',
  1651. dot: '․'
  1652. };
  1653. // With node.js on Windows: use symbols available in terminal default fonts
  1654. if (process.platform === 'win32') {
  1655. exports.symbols.ok = '\u221A';
  1656. exports.symbols.err = '\u00D7';
  1657. exports.symbols.dot = '.';
  1658. }
  1659. /**
  1660. * Color `str` with the given `type`,
  1661. * allowing colors to be disabled,
  1662. * as well as user-defined color
  1663. * schemes.
  1664. *
  1665. * @param {string} type
  1666. * @param {string} str
  1667. * @return {string}
  1668. * @api private
  1669. */
  1670. var color = exports.color = function(type, str) {
  1671. if (!exports.useColors) {
  1672. return String(str);
  1673. }
  1674. return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
  1675. };
  1676. /**
  1677. * Expose term window size, with some defaults for when stderr is not a tty.
  1678. */
  1679. exports.window = {
  1680. width: 75
  1681. };
  1682. if (isatty) {
  1683. exports.window.width = process.stdout.getWindowSize
  1684. ? process.stdout.getWindowSize(1)[0]
  1685. : tty.getWindowSize()[1];
  1686. }
  1687. /**
  1688. * Expose some basic cursor interactions that are common among reporters.
  1689. */
  1690. exports.cursor = {
  1691. hide: function() {
  1692. isatty && process.stdout.write('\u001b[?25l');
  1693. },
  1694. show: function() {
  1695. isatty && process.stdout.write('\u001b[?25h');
  1696. },
  1697. deleteLine: function() {
  1698. isatty && process.stdout.write('\u001b[2K');
  1699. },
  1700. beginningOfLine: function() {
  1701. isatty && process.stdout.write('\u001b[0G');
  1702. },
  1703. CR: function() {
  1704. if (isatty) {
  1705. exports.cursor.deleteLine();
  1706. exports.cursor.beginningOfLine();
  1707. } else {
  1708. process.stdout.write('\r');
  1709. }
  1710. }
  1711. };
  1712. /**
  1713. * Outut the given `failures` as a list.
  1714. *
  1715. * @param {Array} failures
  1716. * @api public
  1717. */
  1718. exports.list = function(failures) {
  1719. console.log();
  1720. failures.forEach(function(test, i) {
  1721. // format
  1722. var fmt = color('error title', ' %s) %s:\n')
  1723. + color('error message', ' %s')
  1724. + color('error stack', '\n%s\n');
  1725. // msg
  1726. var msg;
  1727. var err = test.err;
  1728. var message;
  1729. if (err.message && typeof err.message.toString === 'function') {
  1730. message = err.message + '';
  1731. } else if (typeof err.inspect === 'function') {
  1732. message = err.inspect() + '';
  1733. } else {
  1734. message = '';
  1735. }
  1736. var stack = err.stack || message;
  1737. var index = stack.indexOf(message);
  1738. var actual = err.actual;
  1739. var expected = err.expected;
  1740. var escape = true;
  1741. if (index === -1) {
  1742. msg = message;
  1743. } else {
  1744. index += message.length;
  1745. msg = stack.slice(0, index);
  1746. // remove msg from stack
  1747. stack = stack.slice(index + 1);
  1748. }
  1749. // uncaught
  1750. if (err.uncaught) {
  1751. msg = 'Uncaught ' + msg;
  1752. }
  1753. // explicitly show diff
  1754. if (err.showDiff !== false && sameType(actual, expected) && expected !== undefined) {
  1755. escape = false;
  1756. if (!(utils.isString(actual) && utils.isString(expected))) {
  1757. err.actual = actual = utils.stringify(actual);
  1758. err.expected = expected = utils.stringify(expected);
  1759. }
  1760. fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
  1761. var match = message.match(/^([^:]+): expected/);
  1762. msg = '\n ' + color('error message', match ? match[1] : msg);
  1763. if (exports.inlineDiffs) {
  1764. msg += inlineDiff(err, escape);
  1765. } else {
  1766. msg += unifiedDiff(err, escape);
  1767. }
  1768. }
  1769. // indent stack trace
  1770. stack = stack.replace(/^/gm, ' ');
  1771. console.log(fmt, (i + 1), test.fullTitle(), msg, stack);
  1772. });
  1773. };
  1774. /**
  1775. * Initialize a new `Base` reporter.
  1776. *
  1777. * All other reporters generally
  1778. * inherit from this reporter, providing
  1779. * stats such as test duration, number
  1780. * of tests passed / failed etc.
  1781. *
  1782. * @param {Runner} runner
  1783. * @api public
  1784. */
  1785. function Base(runner) {
  1786. var stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 };
  1787. var failures = this.failures = [];
  1788. if (!runner) {
  1789. return;
  1790. }
  1791. this.runner = runner;
  1792. runner.stats = stats;
  1793. runner.on('start', function() {
  1794. stats.start = new Date();
  1795. });
  1796. runner.on('suite', function(suite) {
  1797. stats.suites = stats.suites || 0;
  1798. suite.root || stats.suites++;
  1799. });
  1800. runner.on('test end', function() {
  1801. stats.tests = stats.tests || 0;
  1802. stats.tests++;
  1803. });
  1804. runner.on('pass', function(test) {
  1805. stats.passes = stats.passes || 0;
  1806. if (test.duration > test.slow()) {
  1807. test.speed = 'slow';
  1808. } else if (test.duration > test.slow() / 2) {
  1809. test.speed = 'medium';
  1810. } else {
  1811. test.speed = 'fast';
  1812. }
  1813. stats.passes++;
  1814. });
  1815. runner.on('fail', function(test, err) {
  1816. stats.failures = stats.failures || 0;
  1817. stats.failures++;
  1818. test.err = err;
  1819. failures.push(test);
  1820. });
  1821. runner.on('end', function() {
  1822. stats.end = new Date();
  1823. stats.duration = new Date() - stats.start;
  1824. });
  1825. runner.on('pending', function() {
  1826. stats.pending++;
  1827. });
  1828. }
  1829. /**
  1830. * Output common epilogue used by many of
  1831. * the bundled reporters.
  1832. *
  1833. * @api public
  1834. */
  1835. Base.prototype.epilogue = function() {
  1836. var stats = this.stats;
  1837. var fmt;
  1838. console.log();
  1839. // passes
  1840. fmt = color('bright pass', ' ')
  1841. + color('green', ' %d passing')
  1842. + color('light', ' (%s)');
  1843. console.log(fmt,
  1844. stats.passes || 0,
  1845. ms(stats.duration));
  1846. // pending
  1847. if (stats.pending) {
  1848. fmt = color('pending', ' ')
  1849. + color('pending', ' %d pending');
  1850. console.log(fmt, stats.pending);
  1851. }
  1852. // failures
  1853. if (stats.failures) {
  1854. fmt = color('fail', ' %d failing');
  1855. console.log(fmt, stats.failures);
  1856. Base.list(this.failures);
  1857. console.log();
  1858. }
  1859. console.log();
  1860. };
  1861. /**
  1862. * Pad the given `str` to `len`.
  1863. *
  1864. * @api private
  1865. * @param {string} str
  1866. * @param {string} len
  1867. * @return {string}
  1868. */
  1869. function pad(str, len) {
  1870. str = String(str);
  1871. return Array(len - str.length + 1).join(' ') + str;
  1872. }
  1873. /**
  1874. * Returns an inline diff between 2 strings with coloured ANSI output
  1875. *
  1876. * @api private
  1877. * @param {Error} err with actual/expected
  1878. * @param {boolean} escape
  1879. * @return {string} Diff
  1880. */
  1881. function inlineDiff(err, escape) {
  1882. var msg = errorDiff(err, 'WordsWithSpace', escape);
  1883. // linenos
  1884. var lines = msg.split('\n');
  1885. if (lines.length > 4) {
  1886. var width = String(lines.length).length;
  1887. msg = lines.map(function(str, i) {
  1888. return pad(++i, width) + ' |' + ' ' + str;
  1889. }).join('\n');
  1890. }
  1891. // legend
  1892. msg = '\n'
  1893. + color('diff removed', 'actual')
  1894. + ' '
  1895. + color('diff added', 'expected')
  1896. + '\n\n'
  1897. + msg
  1898. + '\n';
  1899. // indent
  1900. msg = msg.replace(/^/gm, ' ');
  1901. return msg;
  1902. }
  1903. /**
  1904. * Returns a unified diff between two strings.
  1905. *
  1906. * @api private
  1907. * @param {Error} err with actual/expected
  1908. * @param {boolean} escape
  1909. * @return {string} The diff.
  1910. */
  1911. function unifiedDiff(err, escape) {
  1912. var indent = ' ';
  1913. function cleanUp(line) {
  1914. if (escape) {
  1915. line = escapeInvisibles(line);
  1916. }
  1917. if (line[0] === '+') {
  1918. return indent + colorLines('diff added', line);
  1919. }
  1920. if (line[0] === '-') {
  1921. return indent + colorLines('diff removed', line);
  1922. }
  1923. if (line.match(/\@\@/)) {
  1924. return null;
  1925. }
  1926. if (line.match(/\\ No newline/)) {
  1927. return null;
  1928. }
  1929. return indent + line;
  1930. }
  1931. function notBlank(line) {
  1932. return typeof line !== 'undefined' && line !== null;
  1933. }
  1934. var msg = diff.createPatch('string', err.actual, err.expected);
  1935. var lines = msg.split('\n').splice(4);
  1936. return '\n '
  1937. + colorLines('diff added', '+ expected') + ' '
  1938. + colorLines('diff removed', '- actual')
  1939. + '\n\n'
  1940. + lines.map(cleanUp).filter(notBlank).join('\n');
  1941. }
  1942. /**
  1943. * Return a character diff for `err`.
  1944. *
  1945. * @api private
  1946. * @param {Error} err
  1947. * @param {string} type
  1948. * @param {boolean} escape
  1949. * @return {string}
  1950. */
  1951. function errorDiff(err, type, escape) {
  1952. var actual = escape ? escapeInvisibles(err.actual) : err.actual;
  1953. var expected = escape ? escapeInvisibles(err.expected) : err.expected;
  1954. return diff['diff' + type](actual, expected).map(function(str) {
  1955. if (str.added) {
  1956. return colorLines('diff added', str.value);
  1957. }
  1958. if (str.removed) {
  1959. return colorLines('diff removed', str.value);
  1960. }
  1961. return str.value;
  1962. }).join('');
  1963. }
  1964. /**
  1965. * Returns a string with all invisible characters in plain text
  1966. *
  1967. * @api private
  1968. * @param {string} line
  1969. * @return {string}
  1970. */
  1971. function escapeInvisibles(line) {
  1972. return line.replace(/\t/g, '<tab>')
  1973. .replace(/\r/g, '<CR>')
  1974. .replace(/\n/g, '<LF>\n');
  1975. }
  1976. /**
  1977. * Color lines for `str`, using the color `name`.
  1978. *
  1979. * @api private
  1980. * @param {string} name
  1981. * @param {string} str
  1982. * @return {string}
  1983. */
  1984. function colorLines(name, str) {
  1985. return str.split('\n').map(function(str) {
  1986. return color(name, str);
  1987. }).join('\n');
  1988. }
  1989. /**
  1990. * Object#toString reference.
  1991. */
  1992. var objToString = Object.prototype.toString;
  1993. /**
  1994. * Check that a / b have the same type.
  1995. *
  1996. * @api private
  1997. * @param {Object} a
  1998. * @param {Object} b
  1999. * @return {boolean}
  2000. */
  2001. function sameType(a, b) {
  2002. return objToString.call(a) === objToString.call(b);
  2003. }
  2004. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2005. },{"../ms":15,"../utils":39,"_process":58,"diff":48,"supports-color":43,"tty":5}],18:[function(require,module,exports){
  2006. /**
  2007. * Module dependencies.
  2008. */
  2009. var Base = require('./base');
  2010. var utils = require('../utils');
  2011. /**
  2012. * Expose `Doc`.
  2013. */
  2014. exports = module.exports = Doc;
  2015. /**
  2016. * Initialize a new `Doc` reporter.
  2017. *
  2018. * @param {Runner} runner
  2019. * @api public
  2020. */
  2021. function Doc(runner) {
  2022. Base.call(this, runner);
  2023. var indents = 2;
  2024. function indent() {
  2025. return Array(indents).join(' ');
  2026. }
  2027. runner.on('suite', function(suite) {
  2028. if (suite.root) {
  2029. return;
  2030. }
  2031. ++indents;
  2032. console.log('%s<section class="suite">', indent());
  2033. ++indents;
  2034. console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title));
  2035. console.log('%s<dl>', indent());
  2036. });
  2037. runner.on('suite end', function(suite) {
  2038. if (suite.root) {
  2039. return;
  2040. }
  2041. console.log('%s</dl>', indent());
  2042. --indents;
  2043. console.log('%s</section>', indent());
  2044. --indents;
  2045. });
  2046. runner.on('pass', function(test) {
  2047. console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
  2048. var code = utils.escape(utils.clean(test.body));
  2049. console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
  2050. });
  2051. runner.on('fail', function(test, err) {
  2052. console.log('%s <dt class="error">%s</dt>', indent(), utils.escape(test.title));
  2053. var code = utils.escape(utils.clean(test.fn.body));
  2054. console.log('%s <dd class="error"><pre><code>%s</code></pre></dd>', indent(), code);
  2055. console.log('%s <dd class="error">%s</dd>', indent(), utils.escape(err));
  2056. });
  2057. }
  2058. },{"../utils":39,"./base":17}],19:[function(require,module,exports){
  2059. (function (process){
  2060. /**
  2061. * Module dependencies.
  2062. */
  2063. var Base = require('./base');
  2064. var inherits = require('../utils').inherits;
  2065. var color = Base.color;
  2066. /**
  2067. * Expose `Dot`.
  2068. */
  2069. exports = module.exports = Dot;
  2070. /**
  2071. * Initialize a new `Dot` matrix test reporter.
  2072. *
  2073. * @api public
  2074. * @param {Runner} runner
  2075. */
  2076. function Dot(runner) {
  2077. Base.call(this, runner);
  2078. var self = this;
  2079. var width = Base.window.width * .75 | 0;
  2080. var n = -1;
  2081. runner.on('start', function() {
  2082. process.stdout.write('\n');
  2083. });
  2084. runner.on('pending', function() {
  2085. if (++n % width === 0) {
  2086. process.stdout.write('\n ');
  2087. }
  2088. process.stdout.write(color('pending', Base.symbols.dot));
  2089. });
  2090. runner.on('pass', function(test) {
  2091. if (++n % width === 0) {
  2092. process.stdout.write('\n ');
  2093. }
  2094. if (test.speed === 'slow') {
  2095. process.stdout.write(color('bright yellow', Base.symbols.dot));
  2096. } else {
  2097. process.stdout.write(color(test.speed, Base.symbols.dot));
  2098. }
  2099. });
  2100. runner.on('fail', function() {
  2101. if (++n % width === 0) {
  2102. process.stdout.write('\n ');
  2103. }
  2104. process.stdout.write(color('fail', Base.symbols.dot));
  2105. });
  2106. runner.on('end', function() {
  2107. console.log();
  2108. self.epilogue();
  2109. });
  2110. }
  2111. /**
  2112. * Inherit from `Base.prototype`.
  2113. */
  2114. inherits(Dot, Base);
  2115. }).call(this,require('_process'))
  2116. },{"../utils":39,"./base":17,"_process":58}],20:[function(require,module,exports){
  2117. (function (process,__dirname){
  2118. /**
  2119. * Module dependencies.
  2120. */
  2121. var JSONCov = require('./json-cov');
  2122. var readFileSync = require('fs').readFileSync;
  2123. var join = require('path').join;
  2124. /**
  2125. * Expose `HTMLCov`.
  2126. */
  2127. exports = module.exports = HTMLCov;
  2128. /**
  2129. * Initialize a new `JsCoverage` reporter.
  2130. *
  2131. * @api public
  2132. * @param {Runner} runner
  2133. */
  2134. function HTMLCov(runner) {
  2135. var jade = require('jade');
  2136. var file = join(__dirname, '/templates/coverage.jade');
  2137. var str = readFileSync(file, 'utf8');
  2138. var fn = jade.compile(str, { filename: file });
  2139. var self = this;
  2140. JSONCov.call(this, runner, false);
  2141. runner.on('end', function() {
  2142. process.stdout.write(fn({
  2143. cov: self.cov,
  2144. coverageClass: coverageClass
  2145. }));
  2146. });
  2147. }
  2148. /**
  2149. * Return coverage class for a given coverage percentage.
  2150. *
  2151. * @api private
  2152. * @param {number} coveragePctg
  2153. * @return {string}
  2154. */
  2155. function coverageClass(coveragePctg) {
  2156. if (coveragePctg >= 75) {
  2157. return 'high';
  2158. }
  2159. if (coveragePctg >= 50) {
  2160. return 'medium';
  2161. }
  2162. if (coveragePctg >= 25) {
  2163. return 'low';
  2164. }
  2165. return 'terrible';
  2166. }
  2167. }).call(this,require('_process'),"/lib/reporters")
  2168. },{"./json-cov":23,"_process":58,"fs":43,"jade":43,"path":43}],21:[function(require,module,exports){
  2169. (function (global){
  2170. /* eslint-env browser */
  2171. /**
  2172. * Module dependencies.
  2173. */
  2174. var Base = require('./base');
  2175. var utils = require('../utils');
  2176. var Progress = require('../browser/progress');
  2177. var escapeRe = require('escape-string-regexp');
  2178. var escape = utils.escape;
  2179. /**
  2180. * Save timer references to avoid Sinon interfering (see GH-237).
  2181. */
  2182. /* eslint-disable no-unused-vars, no-native-reassign */
  2183. var Date = global.Date;
  2184. var setTimeout = global.setTimeout;
  2185. var setInterval = global.setInterval;
  2186. var clearTimeout = global.clearTimeout;
  2187. var clearInterval = global.clearInterval;
  2188. /* eslint-enable no-unused-vars, no-native-reassign */
  2189. /**
  2190. * Expose `HTML`.
  2191. */
  2192. exports = module.exports = HTML;
  2193. /**
  2194. * Stats template.
  2195. */
  2196. var statsTemplate = '<ul id="mocha-stats">'
  2197. + '<li class="progress"><canvas width="40" height="40"></canvas></li>'
  2198. + '<li class="passes"><a href="javascript:void(0);">passes:</a> <em>0</em></li>'
  2199. + '<li class="failures"><a href="javascript:void(0);">failures:</a> <em>0</em></li>'
  2200. + '<li class="duration">duration: <em>0</em>s</li>'
  2201. + '</ul>';
  2202. /**
  2203. * Initialize a new `HTML` reporter.
  2204. *
  2205. * @api public
  2206. * @param {Runner} runner
  2207. */
  2208. function HTML(runner) {
  2209. Base.call(this, runner);
  2210. var self = this;
  2211. var stats = this.stats;
  2212. var stat = fragment(statsTemplate);
  2213. var items = stat.getElementsByTagName('li');
  2214. var passes = items[1].getElementsByTagName('em')[0];
  2215. var passesLink = items[1].getElementsByTagName('a')[0];
  2216. var failures = items[2].getElementsByTagName('em')[0];
  2217. var failuresLink = items[2].getElementsByTagName('a')[0];
  2218. var duration = items[3].getElementsByTagName('em')[0];
  2219. var canvas = stat.getElementsByTagName('canvas')[0];
  2220. var report = fragment('<ul id="mocha-report"></ul>');
  2221. var stack = [report];
  2222. var progress;
  2223. var ctx;
  2224. var root = document.getElementById('mocha');
  2225. if (canvas.getContext) {
  2226. var ratio = window.devicePixelRatio || 1;
  2227. canvas.style.width = canvas.width;
  2228. canvas.style.height = canvas.height;
  2229. canvas.width *= ratio;
  2230. canvas.height *= ratio;
  2231. ctx = canvas.getContext('2d');
  2232. ctx.scale(ratio, ratio);
  2233. progress = new Progress();
  2234. }
  2235. if (!root) {
  2236. return error('#mocha div missing, add it to your document');
  2237. }
  2238. // pass toggle
  2239. on(passesLink, 'click', function(evt) {
  2240. evt.preventDefault();
  2241. unhide();
  2242. var name = (/pass/).test(report.className) ? '' : ' pass';
  2243. report.className = report.className.replace(/fail|pass/g, '') + name;
  2244. if (report.className.trim()) {
  2245. hideSuitesWithout('test pass');
  2246. }
  2247. });
  2248. // failure toggle
  2249. on(failuresLink, 'click', function(evt) {
  2250. evt.preventDefault();
  2251. unhide();
  2252. var name = (/fail/).test(report.className) ? '' : ' fail';
  2253. report.className = report.className.replace(/fail|pass/g, '') + name;
  2254. if (report.className.trim()) {
  2255. hideSuitesWithout('test fail');
  2256. }
  2257. });
  2258. root.appendChild(stat);
  2259. root.appendChild(report);
  2260. if (progress) {
  2261. progress.size(40);
  2262. }
  2263. runner.on('suite', function(suite) {
  2264. if (suite.root) {
  2265. return;
  2266. }
  2267. // suite
  2268. var url = self.suiteURL(suite);
  2269. var el = fragment('<li class="suite"><h1><a href="%s">%s</a></h1></li>', url, escape(suite.title));
  2270. // container
  2271. stack[0].appendChild(el);
  2272. stack.unshift(document.createElement('ul'));
  2273. el.appendChild(stack[0]);
  2274. });
  2275. runner.on('suite end', function(suite) {
  2276. if (suite.root) {
  2277. return;
  2278. }
  2279. stack.shift();
  2280. });
  2281. runner.on('pass', function(test) {
  2282. var url = self.testURL(test);
  2283. var markup = '<li class="test pass %e"><h2>%e<span class="duration">%ems</span> '
  2284. + '<a href="%s" class="replay">‣</a></h2></li>';
  2285. var el = fragment(markup, test.speed, test.title, test.duration, url);
  2286. self.addCodeToggle(el, test.body);
  2287. appendToStack(el);
  2288. updateStats();
  2289. });
  2290. runner.on('fail', function(test) {
  2291. var el = fragment('<li class="test fail"><h2>%e <a href="%e" class="replay">‣</a></h2></li>',
  2292. test.title, self.testURL(test));
  2293. var stackString; // Note: Includes leading newline
  2294. var message = test.err.toString();
  2295. // <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
  2296. // check for the result of the stringifying.
  2297. if (message === '[object Error]') {
  2298. message = test.err.message;
  2299. }
  2300. if (test.err.stack) {
  2301. var indexOfMessage = test.err.stack.indexOf(test.err.message);
  2302. if (indexOfMessage === -1) {
  2303. stackString = test.err.stack;
  2304. } else {
  2305. stackString = test.err.stack.substr(test.err.message.length + indexOfMessage);
  2306. }
  2307. } else if (test.err.sourceURL && test.err.line !== undefined) {
  2308. // Safari doesn't give you a stack. Let's at least provide a source line.
  2309. stackString = '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
  2310. }
  2311. stackString = stackString || '';
  2312. if (test.err.htmlMessage && stackString) {
  2313. el.appendChild(fragment('<div class="html-error">%s\n<pre class="error">%e</pre></div>',
  2314. test.err.htmlMessage, stackString));
  2315. } else if (test.err.htmlMessage) {
  2316. el.appendChild(fragment('<div class="html-error">%s</div>', test.err.htmlMessage));
  2317. } else {
  2318. el.appendChild(fragment('<pre class="error">%e%e</pre>', message, stackString));
  2319. }
  2320. self.addCodeToggle(el, test.body);
  2321. appendToStack(el);
  2322. updateStats();
  2323. });
  2324. runner.on('pending', function(test) {
  2325. var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
  2326. appendToStack(el);
  2327. updateStats();
  2328. });
  2329. function appendToStack(el) {
  2330. // Don't call .appendChild if #mocha-report was already .shift()'ed off the stack.
  2331. if (stack[0]) {
  2332. stack[0].appendChild(el);
  2333. }
  2334. }
  2335. function updateStats() {
  2336. // TODO: add to stats
  2337. var percent = stats.tests / this.total * 100 | 0;
  2338. if (progress) {
  2339. progress.update(percent).draw(ctx);
  2340. }
  2341. // update stats
  2342. var ms = new Date() - stats.start;
  2343. text(passes, stats.passes);
  2344. text(failures, stats.failures);
  2345. text(duration, (ms / 1000).toFixed(2));
  2346. }
  2347. }
  2348. /**
  2349. * Makes a URL, preserving querystring ("search") parameters.
  2350. *
  2351. * @param {string} s
  2352. * @return {string} A new URL.
  2353. */
  2354. function makeUrl(s) {
  2355. var search = window.location.search;
  2356. // Remove previous grep query parameter if present
  2357. if (search) {
  2358. search = search.replace(/[?&]grep=[^&\s]*/g, '').replace(/^&/, '?');
  2359. }
  2360. return window.location.pathname + (search ? search + '&' : '?') + 'grep=' + encodeURIComponent(escapeRe(s));
  2361. }
  2362. /**
  2363. * Provide suite URL.
  2364. *
  2365. * @param {Object} [suite]
  2366. */
  2367. HTML.prototype.suiteURL = function(suite) {
  2368. return makeUrl(suite.fullTitle());
  2369. };
  2370. /**
  2371. * Provide test URL.
  2372. *
  2373. * @param {Object} [test]
  2374. */
  2375. HTML.prototype.testURL = function(test) {
  2376. return makeUrl(test.fullTitle());
  2377. };
  2378. /**
  2379. * Adds code toggle functionality for the provided test's list element.
  2380. *
  2381. * @param {HTMLLIElement} el
  2382. * @param {string} contents
  2383. */
  2384. HTML.prototype.addCodeToggle = function(el, contents) {
  2385. var h2 = el.getElementsByTagName('h2')[0];
  2386. on(h2, 'click', function() {
  2387. pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
  2388. });
  2389. var pre = fragment('<pre><code>%e</code></pre>', utils.clean(contents));
  2390. el.appendChild(pre);
  2391. pre.style.display = 'none';
  2392. };
  2393. /**
  2394. * Display error `msg`.
  2395. *
  2396. * @param {string} msg
  2397. */
  2398. function error(msg) {
  2399. document.body.appendChild(fragment('<div id="mocha-error">%s</div>', msg));
  2400. }
  2401. /**
  2402. * Return a DOM fragment from `html`.
  2403. *
  2404. * @param {string} html
  2405. */
  2406. function fragment(html) {
  2407. var args = arguments;
  2408. var div = document.createElement('div');
  2409. var i = 1;
  2410. div.innerHTML = html.replace(/%([se])/g, function(_, type) {
  2411. switch (type) {
  2412. case 's': return String(args[i++]);
  2413. case 'e': return escape(args[i++]);
  2414. // no default
  2415. }
  2416. });
  2417. return div.firstChild;
  2418. }
  2419. /**
  2420. * Check for suites that do not have elements
  2421. * with `classname`, and hide them.
  2422. *
  2423. * @param {text} classname
  2424. */
  2425. function hideSuitesWithout(classname) {
  2426. var suites = document.getElementsByClassName('suite');
  2427. for (var i = 0; i < suites.length; i++) {
  2428. var els = suites[i].getElementsByClassName(classname);
  2429. if (!els.length) {
  2430. suites[i].className += ' hidden';
  2431. }
  2432. }
  2433. }
  2434. /**
  2435. * Unhide .hidden suites.
  2436. */
  2437. function unhide() {
  2438. var els = document.getElementsByClassName('suite hidden');
  2439. for (var i = 0; i < els.length; ++i) {
  2440. els[i].className = els[i].className.replace('suite hidden', 'suite');
  2441. }
  2442. }
  2443. /**
  2444. * Set an element's text contents.
  2445. *
  2446. * @param {HTMLElement} el
  2447. * @param {string} contents
  2448. */
  2449. function text(el, contents) {
  2450. if (el.textContent) {
  2451. el.textContent = contents;
  2452. } else {
  2453. el.innerText = contents;
  2454. }
  2455. }
  2456. /**
  2457. * Listen on `event` with callback `fn`.
  2458. */
  2459. function on(el, event, fn) {
  2460. if (el.addEventListener) {
  2461. el.addEventListener(event, fn, false);
  2462. } else {
  2463. el.attachEvent('on' + event, fn);
  2464. }
  2465. }
  2466. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2467. },{"../browser/progress":4,"../utils":39,"./base":17,"escape-string-regexp":49}],22:[function(require,module,exports){
  2468. // Alias exports to a their normalized format Mocha#reporter to prevent a need
  2469. // for dynamic (try/catch) requires, which Browserify doesn't handle.
  2470. exports.Base = exports.base = require('./base');
  2471. exports.Dot = exports.dot = require('./dot');
  2472. exports.Doc = exports.doc = require('./doc');
  2473. exports.TAP = exports.tap = require('./tap');
  2474. exports.JSON = exports.json = require('./json');
  2475. exports.HTML = exports.html = require('./html');
  2476. exports.List = exports.list = require('./list');
  2477. exports.Min = exports.min = require('./min');
  2478. exports.Spec = exports.spec = require('./spec');
  2479. exports.Nyan = exports.nyan = require('./nyan');
  2480. exports.XUnit = exports.xunit = require('./xunit');
  2481. exports.Markdown = exports.markdown = require('./markdown');
  2482. exports.Progress = exports.progress = require('./progress');
  2483. exports.Landing = exports.landing = require('./landing');
  2484. exports.JSONCov = exports['json-cov'] = require('./json-cov');
  2485. exports.HTMLCov = exports['html-cov'] = require('./html-cov');
  2486. exports.JSONStream = exports['json-stream'] = require('./json-stream');
  2487. },{"./base":17,"./doc":18,"./dot":19,"./html":21,"./html-cov":20,"./json":25,"./json-cov":23,"./json-stream":24,"./landing":26,"./list":27,"./markdown":28,"./min":29,"./nyan":30,"./progress":31,"./spec":32,"./tap":33,"./xunit":34}],23:[function(require,module,exports){
  2488. (function (process,global){
  2489. /**
  2490. * Module dependencies.
  2491. */
  2492. var Base = require('./base');
  2493. /**
  2494. * Expose `JSONCov`.
  2495. */
  2496. exports = module.exports = JSONCov;
  2497. /**
  2498. * Initialize a new `JsCoverage` reporter.
  2499. *
  2500. * @api public
  2501. * @param {Runner} runner
  2502. * @param {boolean} output
  2503. */
  2504. function JSONCov(runner, output) {
  2505. Base.call(this, runner);
  2506. output = arguments.length === 1 || output;
  2507. var self = this;
  2508. var tests = [];
  2509. var failures = [];
  2510. var passes = [];
  2511. runner.on('test end', function(test) {
  2512. tests.push(test);
  2513. });
  2514. runner.on('pass', function(test) {
  2515. passes.push(test);
  2516. });
  2517. runner.on('fail', function(test) {
  2518. failures.push(test);
  2519. });
  2520. runner.on('end', function() {
  2521. var cov = global._$jscoverage || {};
  2522. var result = self.cov = map(cov);
  2523. result.stats = self.stats;
  2524. result.tests = tests.map(clean);
  2525. result.failures = failures.map(clean);
  2526. result.passes = passes.map(clean);
  2527. if (!output) {
  2528. return;
  2529. }
  2530. process.stdout.write(JSON.stringify(result, null, 2));
  2531. });
  2532. }
  2533. /**
  2534. * Map jscoverage data to a JSON structure
  2535. * suitable for reporting.
  2536. *
  2537. * @api private
  2538. * @param {Object} cov
  2539. * @return {Object}
  2540. */
  2541. function map(cov) {
  2542. var ret = {
  2543. instrumentation: 'node-jscoverage',
  2544. sloc: 0,
  2545. hits: 0,
  2546. misses: 0,
  2547. coverage: 0,
  2548. files: []
  2549. };
  2550. for (var filename in cov) {
  2551. if (Object.prototype.hasOwnProperty.call(cov, filename)) {
  2552. var data = coverage(filename, cov[filename]);
  2553. ret.files.push(data);
  2554. ret.hits += data.hits;
  2555. ret.misses += data.misses;
  2556. ret.sloc += data.sloc;
  2557. }
  2558. }
  2559. ret.files.sort(function(a, b) {
  2560. return a.filename.localeCompare(b.filename);
  2561. });
  2562. if (ret.sloc > 0) {
  2563. ret.coverage = (ret.hits / ret.sloc) * 100;
  2564. }
  2565. return ret;
  2566. }
  2567. /**
  2568. * Map jscoverage data for a single source file
  2569. * to a JSON structure suitable for reporting.
  2570. *
  2571. * @api private
  2572. * @param {string} filename name of the source file
  2573. * @param {Object} data jscoverage coverage data
  2574. * @return {Object}
  2575. */
  2576. function coverage(filename, data) {
  2577. var ret = {
  2578. filename: filename,
  2579. coverage: 0,
  2580. hits: 0,
  2581. misses: 0,
  2582. sloc: 0,
  2583. source: {}
  2584. };
  2585. data.source.forEach(function(line, num) {
  2586. num++;
  2587. if (data[num] === 0) {
  2588. ret.misses++;
  2589. ret.sloc++;
  2590. } else if (data[num] !== undefined) {
  2591. ret.hits++;
  2592. ret.sloc++;
  2593. }
  2594. ret.source[num] = {
  2595. source: line,
  2596. coverage: data[num] === undefined ? '' : data[num]
  2597. };
  2598. });
  2599. ret.coverage = ret.hits / ret.sloc * 100;
  2600. return ret;
  2601. }
  2602. /**
  2603. * Return a plain-object representation of `test`
  2604. * free of cyclic properties etc.
  2605. *
  2606. * @api private
  2607. * @param {Object} test
  2608. * @return {Object}
  2609. */
  2610. function clean(test) {
  2611. return {
  2612. duration: test.duration,
  2613. currentRetry: test.currentRetry(),
  2614. fullTitle: test.fullTitle(),
  2615. title: test.title
  2616. };
  2617. }
  2618. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2619. },{"./base":17,"_process":58}],24:[function(require,module,exports){
  2620. (function (process){
  2621. /**
  2622. * Module dependencies.
  2623. */
  2624. var Base = require('./base');
  2625. /**
  2626. * Expose `List`.
  2627. */
  2628. exports = module.exports = List;
  2629. /**
  2630. * Initialize a new `List` test reporter.
  2631. *
  2632. * @api public
  2633. * @param {Runner} runner
  2634. */
  2635. function List(runner) {
  2636. Base.call(this, runner);
  2637. var self = this;
  2638. var total = runner.total;
  2639. runner.on('start', function() {
  2640. console.log(JSON.stringify(['start', { total: total }]));
  2641. });
  2642. runner.on('pass', function(test) {
  2643. console.log(JSON.stringify(['pass', clean(test)]));
  2644. });
  2645. runner.on('fail', function(test, err) {
  2646. test = clean(test);
  2647. test.err = err.message;
  2648. test.stack = err.stack || null;
  2649. console.log(JSON.stringify(['fail', test]));
  2650. });
  2651. runner.on('end', function() {
  2652. process.stdout.write(JSON.stringify(['end', self.stats]));
  2653. });
  2654. }
  2655. /**
  2656. * Return a plain-object representation of `test`
  2657. * free of cyclic properties etc.
  2658. *
  2659. * @api private
  2660. * @param {Object} test
  2661. * @return {Object}
  2662. */
  2663. function clean(test) {
  2664. return {
  2665. title: test.title,
  2666. fullTitle: test.fullTitle(),
  2667. duration: test.duration,
  2668. currentRetry: test.currentRetry()
  2669. };
  2670. }
  2671. }).call(this,require('_process'))
  2672. },{"./base":17,"_process":58}],25:[function(require,module,exports){
  2673. (function (process){
  2674. /**
  2675. * Module dependencies.
  2676. */
  2677. var Base = require('./base');
  2678. /**
  2679. * Expose `JSON`.
  2680. */
  2681. exports = module.exports = JSONReporter;
  2682. /**
  2683. * Initialize a new `JSON` reporter.
  2684. *
  2685. * @api public
  2686. * @param {Runner} runner
  2687. */
  2688. function JSONReporter(runner) {
  2689. Base.call(this, runner);
  2690. var self = this;
  2691. var tests = [];
  2692. var pending = [];
  2693. var failures = [];
  2694. var passes = [];
  2695. runner.on('test end', function(test) {
  2696. tests.push(test);
  2697. });
  2698. runner.on('pass', function(test) {
  2699. passes.push(test);
  2700. });
  2701. runner.on('fail', function(test) {
  2702. failures.push(test);
  2703. });
  2704. runner.on('pending', function(test) {
  2705. pending.push(test);
  2706. });
  2707. runner.on('end', function() {
  2708. var obj = {
  2709. stats: self.stats,
  2710. tests: tests.map(clean),
  2711. pending: pending.map(clean),
  2712. failures: failures.map(clean),
  2713. passes: passes.map(clean)
  2714. };
  2715. runner.testResults = obj;
  2716. process.stdout.write(JSON.stringify(obj, null, 2));
  2717. });
  2718. }
  2719. /**
  2720. * Return a plain-object representation of `test`
  2721. * free of cyclic properties etc.
  2722. *
  2723. * @api private
  2724. * @param {Object} test
  2725. * @return {Object}
  2726. */
  2727. function clean(test) {
  2728. return {
  2729. title: test.title,
  2730. fullTitle: test.fullTitle(),
  2731. duration: test.duration,
  2732. currentRetry: test.currentRetry(),
  2733. err: errorJSON(test.err || {})
  2734. };
  2735. }
  2736. /**
  2737. * Transform `error` into a JSON object.
  2738. *
  2739. * @api private
  2740. * @param {Error} err
  2741. * @return {Object}
  2742. */
  2743. function errorJSON(err) {
  2744. var res = {};
  2745. Object.getOwnPropertyNames(err).forEach(function(key) {
  2746. res[key] = err[key];
  2747. }, err);
  2748. return res;
  2749. }
  2750. }).call(this,require('_process'))
  2751. },{"./base":17,"_process":58}],26:[function(require,module,exports){
  2752. (function (process){
  2753. /**
  2754. * Module dependencies.
  2755. */
  2756. var Base = require('./base');
  2757. var inherits = require('../utils').inherits;
  2758. var cursor = Base.cursor;
  2759. var color = Base.color;
  2760. /**
  2761. * Expose `Landing`.
  2762. */
  2763. exports = module.exports = Landing;
  2764. /**
  2765. * Airplane color.
  2766. */
  2767. Base.colors.plane = 0;
  2768. /**
  2769. * Airplane crash color.
  2770. */
  2771. Base.colors['plane crash'] = 31;
  2772. /**
  2773. * Runway color.
  2774. */
  2775. Base.colors.runway = 90;
  2776. /**
  2777. * Initialize a new `Landing` reporter.
  2778. *
  2779. * @api public
  2780. * @param {Runner} runner
  2781. */
  2782. function Landing(runner) {
  2783. Base.call(this, runner);
  2784. var self = this;
  2785. var width = Base.window.width * .75 | 0;
  2786. var total = runner.total;
  2787. var stream = process.stdout;
  2788. var plane = color('plane', '✈');
  2789. var crashed = -1;
  2790. var n = 0;
  2791. function runway() {
  2792. var buf = Array(width).join('-');
  2793. return ' ' + color('runway', buf);
  2794. }
  2795. runner.on('start', function() {
  2796. stream.write('\n\n\n ');
  2797. cursor.hide();
  2798. });
  2799. runner.on('test end', function(test) {
  2800. // check if the plane crashed
  2801. var col = crashed === -1 ? width * ++n / total | 0 : crashed;
  2802. // show the crash
  2803. if (test.state === 'failed') {
  2804. plane = color('plane crash', '✈');
  2805. crashed = col;
  2806. }
  2807. // render landing strip
  2808. stream.write('\u001b[' + (width + 1) + 'D\u001b[2A');
  2809. stream.write(runway());
  2810. stream.write('\n ');
  2811. stream.write(color('runway', Array(col).join('⋅')));
  2812. stream.write(plane);
  2813. stream.write(color('runway', Array(width - col).join('⋅') + '\n'));
  2814. stream.write(runway());
  2815. stream.write('\u001b[0m');
  2816. });
  2817. runner.on('end', function() {
  2818. cursor.show();
  2819. console.log();
  2820. self.epilogue();
  2821. });
  2822. }
  2823. /**
  2824. * Inherit from `Base.prototype`.
  2825. */
  2826. inherits(Landing, Base);
  2827. }).call(this,require('_process'))
  2828. },{"../utils":39,"./base":17,"_process":58}],27:[function(require,module,exports){
  2829. (function (process){
  2830. /**
  2831. * Module dependencies.
  2832. */
  2833. var Base = require('./base');
  2834. var inherits = require('../utils').inherits;
  2835. var color = Base.color;
  2836. var cursor = Base.cursor;
  2837. /**
  2838. * Expose `List`.
  2839. */
  2840. exports = module.exports = List;
  2841. /**
  2842. * Initialize a new `List` test reporter.
  2843. *
  2844. * @api public
  2845. * @param {Runner} runner
  2846. */
  2847. function List(runner) {
  2848. Base.call(this, runner);
  2849. var self = this;
  2850. var n = 0;
  2851. runner.on('start', function() {
  2852. console.log();
  2853. });
  2854. runner.on('test', function(test) {
  2855. process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
  2856. });
  2857. runner.on('pending', function(test) {
  2858. var fmt = color('checkmark', ' -')
  2859. + color('pending', ' %s');
  2860. console.log(fmt, test.fullTitle());
  2861. });
  2862. runner.on('pass', function(test) {
  2863. var fmt = color('checkmark', ' ' + Base.symbols.dot)
  2864. + color('pass', ' %s: ')
  2865. + color(test.speed, '%dms');
  2866. cursor.CR();
  2867. console.log(fmt, test.fullTitle(), test.duration);
  2868. });
  2869. runner.on('fail', function(test) {
  2870. cursor.CR();
  2871. console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
  2872. });
  2873. runner.on('end', self.epilogue.bind(self));
  2874. }
  2875. /**
  2876. * Inherit from `Base.prototype`.
  2877. */
  2878. inherits(List, Base);
  2879. }).call(this,require('_process'))
  2880. },{"../utils":39,"./base":17,"_process":58}],28:[function(require,module,exports){
  2881. (function (process){
  2882. /**
  2883. * Module dependencies.
  2884. */
  2885. var Base = require('./base');
  2886. var utils = require('../utils');
  2887. /**
  2888. * Constants
  2889. */
  2890. var SUITE_PREFIX = '$';
  2891. /**
  2892. * Expose `Markdown`.
  2893. */
  2894. exports = module.exports = Markdown;
  2895. /**
  2896. * Initialize a new `Markdown` reporter.
  2897. *
  2898. * @api public
  2899. * @param {Runner} runner
  2900. */
  2901. function Markdown(runner) {
  2902. Base.call(this, runner);
  2903. var level = 0;
  2904. var buf = '';
  2905. function title(str) {
  2906. return Array(level).join('#') + ' ' + str;
  2907. }
  2908. function mapTOC(suite, obj) {
  2909. var ret = obj;
  2910. var key = SUITE_PREFIX + suite.title;
  2911. obj = obj[key] = obj[key] || { suite: suite };
  2912. suite.suites.forEach(function(suite) {
  2913. mapTOC(suite, obj);
  2914. });
  2915. return ret;
  2916. }
  2917. function stringifyTOC(obj, level) {
  2918. ++level;
  2919. var buf = '';
  2920. var link;
  2921. for (var key in obj) {
  2922. if (key === 'suite') {
  2923. continue;
  2924. }
  2925. if (key !== SUITE_PREFIX) {
  2926. link = ' - [' + key.substring(1) + ']';
  2927. link += '(#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
  2928. buf += Array(level).join(' ') + link;
  2929. }
  2930. buf += stringifyTOC(obj[key], level);
  2931. }
  2932. return buf;
  2933. }
  2934. function generateTOC(suite) {
  2935. var obj = mapTOC(suite, {});
  2936. return stringifyTOC(obj, 0);
  2937. }
  2938. generateTOC(runner.suite);
  2939. runner.on('suite', function(suite) {
  2940. ++level;
  2941. var slug = utils.slug(suite.fullTitle());
  2942. buf += '<a name="' + slug + '"></a>' + '\n';
  2943. buf += title(suite.title) + '\n';
  2944. });
  2945. runner.on('suite end', function() {
  2946. --level;
  2947. });
  2948. runner.on('pass', function(test) {
  2949. var code = utils.clean(test.body);
  2950. buf += test.title + '.\n';
  2951. buf += '\n```js\n';
  2952. buf += code + '\n';
  2953. buf += '```\n\n';
  2954. });
  2955. runner.on('end', function() {
  2956. process.stdout.write('# TOC\n');
  2957. process.stdout.write(generateTOC(runner.suite));
  2958. process.stdout.write(buf);
  2959. });
  2960. }
  2961. }).call(this,require('_process'))
  2962. },{"../utils":39,"./base":17,"_process":58}],29:[function(require,module,exports){
  2963. (function (process){
  2964. /**
  2965. * Module dependencies.
  2966. */
  2967. var Base = require('./base');
  2968. var inherits = require('../utils').inherits;
  2969. /**
  2970. * Expose `Min`.
  2971. */
  2972. exports = module.exports = Min;
  2973. /**
  2974. * Initialize a new `Min` minimal test reporter (best used with --watch).
  2975. *
  2976. * @api public
  2977. * @param {Runner} runner
  2978. */
  2979. function Min(runner) {
  2980. Base.call(this, runner);
  2981. runner.on('start', function() {
  2982. // clear screen
  2983. process.stdout.write('\u001b[2J');
  2984. // set cursor position
  2985. process.stdout.write('\u001b[1;3H');
  2986. });
  2987. runner.on('end', this.epilogue.bind(this));
  2988. }
  2989. /**
  2990. * Inherit from `Base.prototype`.
  2991. */
  2992. inherits(Min, Base);
  2993. }).call(this,require('_process'))
  2994. },{"../utils":39,"./base":17,"_process":58}],30:[function(require,module,exports){
  2995. (function (process){
  2996. /**
  2997. * Module dependencies.
  2998. */
  2999. var Base = require('./base');
  3000. var inherits = require('../utils').inherits;
  3001. /**
  3002. * Expose `Dot`.
  3003. */
  3004. exports = module.exports = NyanCat;
  3005. /**
  3006. * Initialize a new `Dot` matrix test reporter.
  3007. *
  3008. * @param {Runner} runner
  3009. * @api public
  3010. */
  3011. function NyanCat(runner) {
  3012. Base.call(this, runner);
  3013. var self = this;
  3014. var width = Base.window.width * .75 | 0;
  3015. var nyanCatWidth = this.nyanCatWidth = 11;
  3016. this.colorIndex = 0;
  3017. this.numberOfLines = 4;
  3018. this.rainbowColors = self.generateColors();
  3019. this.scoreboardWidth = 5;
  3020. this.tick = 0;
  3021. this.trajectories = [[], [], [], []];
  3022. this.trajectoryWidthMax = (width - nyanCatWidth);
  3023. runner.on('start', function() {
  3024. Base.cursor.hide();
  3025. self.draw();
  3026. });
  3027. runner.on('pending', function() {
  3028. self.draw();
  3029. });
  3030. runner.on('pass', function() {
  3031. self.draw();
  3032. });
  3033. runner.on('fail', function() {
  3034. self.draw();
  3035. });
  3036. runner.on('end', function() {
  3037. Base.cursor.show();
  3038. for (var i = 0; i < self.numberOfLines; i++) {
  3039. write('\n');
  3040. }
  3041. self.epilogue();
  3042. });
  3043. }
  3044. /**
  3045. * Inherit from `Base.prototype`.
  3046. */
  3047. inherits(NyanCat, Base);
  3048. /**
  3049. * Draw the nyan cat
  3050. *
  3051. * @api private
  3052. */
  3053. NyanCat.prototype.draw = function() {
  3054. this.appendRainbow();
  3055. this.drawScoreboard();
  3056. this.drawRainbow();
  3057. this.drawNyanCat();
  3058. this.tick = !this.tick;
  3059. };
  3060. /**
  3061. * Draw the "scoreboard" showing the number
  3062. * of passes, failures and pending tests.
  3063. *
  3064. * @api private
  3065. */
  3066. NyanCat.prototype.drawScoreboard = function() {
  3067. var stats = this.stats;
  3068. function draw(type, n) {
  3069. write(' ');
  3070. write(Base.color(type, n));
  3071. write('\n');
  3072. }
  3073. draw('green', stats.passes);
  3074. draw('fail', stats.failures);
  3075. draw('pending', stats.pending);
  3076. write('\n');
  3077. this.cursorUp(this.numberOfLines);
  3078. };
  3079. /**
  3080. * Append the rainbow.
  3081. *
  3082. * @api private
  3083. */
  3084. NyanCat.prototype.appendRainbow = function() {
  3085. var segment = this.tick ? '_' : '-';
  3086. var rainbowified = this.rainbowify(segment);
  3087. for (var index = 0; index < this.numberOfLines; index++) {
  3088. var trajectory = this.trajectories[index];
  3089. if (trajectory.length >= this.trajectoryWidthMax) {
  3090. trajectory.shift();
  3091. }
  3092. trajectory.push(rainbowified);
  3093. }
  3094. };
  3095. /**
  3096. * Draw the rainbow.
  3097. *
  3098. * @api private
  3099. */
  3100. NyanCat.prototype.drawRainbow = function() {
  3101. var self = this;
  3102. this.trajectories.forEach(function(line) {
  3103. write('\u001b[' + self.scoreboardWidth + 'C');
  3104. write(line.join(''));
  3105. write('\n');
  3106. });
  3107. this.cursorUp(this.numberOfLines);
  3108. };
  3109. /**
  3110. * Draw the nyan cat
  3111. *
  3112. * @api private
  3113. */
  3114. NyanCat.prototype.drawNyanCat = function() {
  3115. var self = this;
  3116. var startWidth = this.scoreboardWidth + this.trajectories[0].length;
  3117. var dist = '\u001b[' + startWidth + 'C';
  3118. var padding = '';
  3119. write(dist);
  3120. write('_,------,');
  3121. write('\n');
  3122. write(dist);
  3123. padding = self.tick ? ' ' : ' ';
  3124. write('_|' + padding + '/\\_/\\ ');
  3125. write('\n');
  3126. write(dist);
  3127. padding = self.tick ? '_' : '__';
  3128. var tail = self.tick ? '~' : '^';
  3129. write(tail + '|' + padding + this.face() + ' ');
  3130. write('\n');
  3131. write(dist);
  3132. padding = self.tick ? ' ' : ' ';
  3133. write(padding + '"" "" ');
  3134. write('\n');
  3135. this.cursorUp(this.numberOfLines);
  3136. };
  3137. /**
  3138. * Draw nyan cat face.
  3139. *
  3140. * @api private
  3141. * @return {string}
  3142. */
  3143. NyanCat.prototype.face = function() {
  3144. var stats = this.stats;
  3145. if (stats.failures) {
  3146. return '( x .x)';
  3147. } else if (stats.pending) {
  3148. return '( o .o)';
  3149. } else if (stats.passes) {
  3150. return '( ^ .^)';
  3151. }
  3152. return '( - .-)';
  3153. };
  3154. /**
  3155. * Move cursor up `n`.
  3156. *
  3157. * @api private
  3158. * @param {number} n
  3159. */
  3160. NyanCat.prototype.cursorUp = function(n) {
  3161. write('\u001b[' + n + 'A');
  3162. };
  3163. /**
  3164. * Move cursor down `n`.
  3165. *
  3166. * @api private
  3167. * @param {number} n
  3168. */
  3169. NyanCat.prototype.cursorDown = function(n) {
  3170. write('\u001b[' + n + 'B');
  3171. };
  3172. /**
  3173. * Generate rainbow colors.
  3174. *
  3175. * @api private
  3176. * @return {Array}
  3177. */
  3178. NyanCat.prototype.generateColors = function() {
  3179. var colors = [];
  3180. for (var i = 0; i < (6 * 7); i++) {
  3181. var pi3 = Math.floor(Math.PI / 3);
  3182. var n = (i * (1.0 / 6));
  3183. var r = Math.floor(3 * Math.sin(n) + 3);
  3184. var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
  3185. var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
  3186. colors.push(36 * r + 6 * g + b + 16);
  3187. }
  3188. return colors;
  3189. };
  3190. /**
  3191. * Apply rainbow to the given `str`.
  3192. *
  3193. * @api private
  3194. * @param {string} str
  3195. * @return {string}
  3196. */
  3197. NyanCat.prototype.rainbowify = function(str) {
  3198. if (!Base.useColors) {
  3199. return str;
  3200. }
  3201. var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length];
  3202. this.colorIndex += 1;
  3203. return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';
  3204. };
  3205. /**
  3206. * Stdout helper.
  3207. *
  3208. * @param {string} string A message to write to stdout.
  3209. */
  3210. function write(string) {
  3211. process.stdout.write(string);
  3212. }
  3213. }).call(this,require('_process'))
  3214. },{"../utils":39,"./base":17,"_process":58}],31:[function(require,module,exports){
  3215. (function (process){
  3216. /**
  3217. * Module dependencies.
  3218. */
  3219. var Base = require('./base');
  3220. var inherits = require('../utils').inherits;
  3221. var color = Base.color;
  3222. var cursor = Base.cursor;
  3223. /**
  3224. * Expose `Progress`.
  3225. */
  3226. exports = module.exports = Progress;
  3227. /**
  3228. * General progress bar color.
  3229. */
  3230. Base.colors.progress = 90;
  3231. /**
  3232. * Initialize a new `Progress` bar test reporter.
  3233. *
  3234. * @api public
  3235. * @param {Runner} runner
  3236. * @param {Object} options
  3237. */
  3238. function Progress(runner, options) {
  3239. Base.call(this, runner);
  3240. var self = this;
  3241. var width = Base.window.width * .50 | 0;
  3242. var total = runner.total;
  3243. var complete = 0;
  3244. var lastN = -1;
  3245. // default chars
  3246. options = options || {};
  3247. options.open = options.open || '[';
  3248. options.complete = options.complete || '▬';
  3249. options.incomplete = options.incomplete || Base.symbols.dot;
  3250. options.close = options.close || ']';
  3251. options.verbose = false;
  3252. // tests started
  3253. runner.on('start', function() {
  3254. console.log();
  3255. cursor.hide();
  3256. });
  3257. // tests complete
  3258. runner.on('test end', function() {
  3259. complete++;
  3260. var percent = complete / total;
  3261. var n = width * percent | 0;
  3262. var i = width - n;
  3263. if (n === lastN && !options.verbose) {
  3264. // Don't re-render the line if it hasn't changed
  3265. return;
  3266. }
  3267. lastN = n;
  3268. cursor.CR();
  3269. process.stdout.write('\u001b[J');
  3270. process.stdout.write(color('progress', ' ' + options.open));
  3271. process.stdout.write(Array(n).join(options.complete));
  3272. process.stdout.write(Array(i).join(options.incomplete));
  3273. process.stdout.write(color('progress', options.close));
  3274. if (options.verbose) {
  3275. process.stdout.write(color('progress', ' ' + complete + ' of ' + total));
  3276. }
  3277. });
  3278. // tests are complete, output some stats
  3279. // and the failures if any
  3280. runner.on('end', function() {
  3281. cursor.show();
  3282. console.log();
  3283. self.epilogue();
  3284. });
  3285. }
  3286. /**
  3287. * Inherit from `Base.prototype`.
  3288. */
  3289. inherits(Progress, Base);
  3290. }).call(this,require('_process'))
  3291. },{"../utils":39,"./base":17,"_process":58}],32:[function(require,module,exports){
  3292. /**
  3293. * Module dependencies.
  3294. */
  3295. var Base = require('./base');
  3296. var inherits = require('../utils').inherits;
  3297. var color = Base.color;
  3298. var cursor = Base.cursor;
  3299. /**
  3300. * Expose `Spec`.
  3301. */
  3302. exports = module.exports = Spec;
  3303. /**
  3304. * Initialize a new `Spec` test reporter.
  3305. *
  3306. * @api public
  3307. * @param {Runner} runner
  3308. */
  3309. function Spec(runner) {
  3310. Base.call(this, runner);
  3311. var self = this;
  3312. var indents = 0;
  3313. var n = 0;
  3314. function indent() {
  3315. return Array(indents).join(' ');
  3316. }
  3317. runner.on('start', function() {
  3318. console.log();
  3319. });
  3320. runner.on('suite', function(suite) {
  3321. ++indents;
  3322. console.log(color('suite', '%s%s'), indent(), suite.title);
  3323. });
  3324. runner.on('suite end', function() {
  3325. --indents;
  3326. if (indents === 1) {
  3327. console.log();
  3328. }
  3329. });
  3330. runner.on('pending', function(test) {
  3331. var fmt = indent() + color('pending', ' - %s');
  3332. console.log(fmt, test.title);
  3333. });
  3334. runner.on('pass', function(test) {
  3335. var fmt;
  3336. if (test.speed === 'fast') {
  3337. fmt = indent()
  3338. + color('checkmark', ' ' + Base.symbols.ok)
  3339. + color('pass', ' %s');
  3340. cursor.CR();
  3341. console.log(fmt, test.title);
  3342. } else {
  3343. fmt = indent()
  3344. + color('checkmark', ' ' + Base.symbols.ok)
  3345. + color('pass', ' %s')
  3346. + color(test.speed, ' (%dms)');
  3347. cursor.CR();
  3348. console.log(fmt, test.title, test.duration);
  3349. }
  3350. });
  3351. runner.on('fail', function(test) {
  3352. cursor.CR();
  3353. console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
  3354. });
  3355. runner.on('end', self.epilogue.bind(self));
  3356. }
  3357. /**
  3358. * Inherit from `Base.prototype`.
  3359. */
  3360. inherits(Spec, Base);
  3361. },{"../utils":39,"./base":17}],33:[function(require,module,exports){
  3362. /**
  3363. * Module dependencies.
  3364. */
  3365. var Base = require('./base');
  3366. /**
  3367. * Expose `TAP`.
  3368. */
  3369. exports = module.exports = TAP;
  3370. /**
  3371. * Initialize a new `TAP` reporter.
  3372. *
  3373. * @api public
  3374. * @param {Runner} runner
  3375. */
  3376. function TAP(runner) {
  3377. Base.call(this, runner);
  3378. var n = 1;
  3379. var passes = 0;
  3380. var failures = 0;
  3381. runner.on('start', function() {
  3382. var total = runner.grepTotal(runner.suite);
  3383. console.log('%d..%d', 1, total);
  3384. });
  3385. runner.on('test end', function() {
  3386. ++n;
  3387. });
  3388. runner.on('pending', function(test) {
  3389. console.log('ok %d %s # SKIP -', n, title(test));
  3390. });
  3391. runner.on('pass', function(test) {
  3392. passes++;
  3393. console.log('ok %d %s', n, title(test));
  3394. });
  3395. runner.on('fail', function(test, err) {
  3396. failures++;
  3397. console.log('not ok %d %s', n, title(test));
  3398. if (err.stack) {
  3399. console.log(err.stack.replace(/^/gm, ' '));
  3400. }
  3401. });
  3402. runner.on('end', function() {
  3403. console.log('# tests ' + (passes + failures));
  3404. console.log('# pass ' + passes);
  3405. console.log('# fail ' + failures);
  3406. });
  3407. }
  3408. /**
  3409. * Return a TAP-safe title of `test`
  3410. *
  3411. * @api private
  3412. * @param {Object} test
  3413. * @return {String}
  3414. */
  3415. function title(test) {
  3416. return test.fullTitle().replace(/#/g, '');
  3417. }
  3418. },{"./base":17}],34:[function(require,module,exports){
  3419. (function (process,global){
  3420. /**
  3421. * Module dependencies.
  3422. */
  3423. var Base = require('./base');
  3424. var utils = require('../utils');
  3425. var inherits = utils.inherits;
  3426. var fs = require('fs');
  3427. var escape = utils.escape;
  3428. var mkdirp = require('mkdirp');
  3429. var path = require('path');
  3430. /**
  3431. * Save timer references to avoid Sinon interfering (see GH-237).
  3432. */
  3433. /* eslint-disable no-unused-vars, no-native-reassign */
  3434. var Date = global.Date;
  3435. var setTimeout = global.setTimeout;
  3436. var setInterval = global.setInterval;
  3437. var clearTimeout = global.clearTimeout;
  3438. var clearInterval = global.clearInterval;
  3439. /* eslint-enable no-unused-vars, no-native-reassign */
  3440. /**
  3441. * Expose `XUnit`.
  3442. */
  3443. exports = module.exports = XUnit;
  3444. /**
  3445. * Initialize a new `XUnit` reporter.
  3446. *
  3447. * @api public
  3448. * @param {Runner} runner
  3449. */
  3450. function XUnit(runner, options) {
  3451. Base.call(this, runner);
  3452. var stats = this.stats;
  3453. var tests = [];
  3454. var self = this;
  3455. if (options.reporterOptions && options.reporterOptions.output) {
  3456. if (!fs.createWriteStream) {
  3457. throw new Error('file output not supported in browser');
  3458. }
  3459. mkdirp.sync(path.dirname(options.reporterOptions.output));
  3460. self.fileStream = fs.createWriteStream(options.reporterOptions.output);
  3461. }
  3462. runner.on('pending', function(test) {
  3463. tests.push(test);
  3464. });
  3465. runner.on('pass', function(test) {
  3466. tests.push(test);
  3467. });
  3468. runner.on('fail', function(test) {
  3469. tests.push(test);
  3470. });
  3471. runner.on('end', function() {
  3472. self.write(tag('testsuite', {
  3473. name: 'Mocha Tests',
  3474. tests: stats.tests,
  3475. failures: stats.failures,
  3476. errors: stats.failures,
  3477. skipped: stats.tests - stats.failures - stats.passes,
  3478. timestamp: (new Date()).toUTCString(),
  3479. time: (stats.duration / 1000) || 0
  3480. }, false));
  3481. tests.forEach(function(t) {
  3482. self.test(t);
  3483. });
  3484. self.write('</testsuite>');
  3485. });
  3486. }
  3487. /**
  3488. * Inherit from `Base.prototype`.
  3489. */
  3490. inherits(XUnit, Base);
  3491. /**
  3492. * Override done to close the stream (if it's a file).
  3493. *
  3494. * @param failures
  3495. * @param {Function} fn
  3496. */
  3497. XUnit.prototype.done = function(failures, fn) {
  3498. if (this.fileStream) {
  3499. this.fileStream.end(function() {
  3500. fn(failures);
  3501. });
  3502. } else {
  3503. fn(failures);
  3504. }
  3505. };
  3506. /**
  3507. * Write out the given line.
  3508. *
  3509. * @param {string} line
  3510. */
  3511. XUnit.prototype.write = function(line) {
  3512. if (this.fileStream) {
  3513. this.fileStream.write(line + '\n');
  3514. } else if (typeof process === 'object' && process.stdout) {
  3515. process.stdout.write(line + '\n');
  3516. } else {
  3517. console.log(line);
  3518. }
  3519. };
  3520. /**
  3521. * Output tag for the given `test.`
  3522. *
  3523. * @param {Test} test
  3524. */
  3525. XUnit.prototype.test = function(test) {
  3526. var attrs = {
  3527. classname: test.parent.fullTitle(),
  3528. name: test.title,
  3529. time: (test.duration / 1000) || 0
  3530. };
  3531. if (test.state === 'failed') {
  3532. var err = test.err;
  3533. this.write(tag('testcase', attrs, false, tag('failure', {}, false, escape(err.message) + '\n' + escape(err.stack))));
  3534. } else if (test.isPending()) {
  3535. this.write(tag('testcase', attrs, false, tag('skipped', {}, true)));
  3536. } else {
  3537. this.write(tag('testcase', attrs, true));
  3538. }
  3539. };
  3540. /**
  3541. * HTML tag helper.
  3542. *
  3543. * @param name
  3544. * @param attrs
  3545. * @param close
  3546. * @param content
  3547. * @return {string}
  3548. */
  3549. function tag(name, attrs, close, content) {
  3550. var end = close ? '/>' : '>';
  3551. var pairs = [];
  3552. var tag;
  3553. for (var key in attrs) {
  3554. if (Object.prototype.hasOwnProperty.call(attrs, key)) {
  3555. pairs.push(key + '="' + escape(attrs[key]) + '"');
  3556. }
  3557. }
  3558. tag = '<' + name + (pairs.length ? ' ' + pairs.join(' ') : '') + end;
  3559. if (content) {
  3560. tag += content + '</' + name + end;
  3561. }
  3562. return tag;
  3563. }
  3564. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3565. },{"../utils":39,"./base":17,"_process":58,"fs":43,"mkdirp":55,"path":43}],35:[function(require,module,exports){
  3566. (function (global){
  3567. /**
  3568. * Module dependencies.
  3569. */
  3570. var EventEmitter = require('events').EventEmitter;
  3571. var Pending = require('./pending');
  3572. var debug = require('debug')('mocha:runnable');
  3573. var milliseconds = require('./ms');
  3574. var utils = require('./utils');
  3575. var inherits = utils.inherits;
  3576. /**
  3577. * Save timer references to avoid Sinon interfering (see GH-237).
  3578. */
  3579. /* eslint-disable no-unused-vars, no-native-reassign */
  3580. var Date = global.Date;
  3581. var setTimeout = global.setTimeout;
  3582. var setInterval = global.setInterval;
  3583. var clearTimeout = global.clearTimeout;
  3584. var clearInterval = global.clearInterval;
  3585. /* eslint-enable no-unused-vars, no-native-reassign */
  3586. /**
  3587. * Object#toString().
  3588. */
  3589. var toString = Object.prototype.toString;
  3590. /**
  3591. * Expose `Runnable`.
  3592. */
  3593. module.exports = Runnable;
  3594. /**
  3595. * Initialize a new `Runnable` with the given `title` and callback `fn`.
  3596. *
  3597. * @param {String} title
  3598. * @param {Function} fn
  3599. * @api private
  3600. * @param {string} title
  3601. * @param {Function} fn
  3602. */
  3603. function Runnable(title, fn) {
  3604. this.title = title;
  3605. this.fn = fn;
  3606. this.body = (fn || '').toString();
  3607. this.async = fn && fn.length;
  3608. this.sync = !this.async;
  3609. this._timeout = 2000;
  3610. this._slow = 75;
  3611. this._enableTimeouts = true;
  3612. this.timedOut = false;
  3613. this._trace = new Error('done() called multiple times');
  3614. this._retries = -1;
  3615. this._currentRetry = 0;
  3616. this.pending = false;
  3617. }
  3618. /**
  3619. * Inherit from `EventEmitter.prototype`.
  3620. */
  3621. inherits(Runnable, EventEmitter);
  3622. /**
  3623. * Set & get timeout `ms`.
  3624. *
  3625. * @api private
  3626. * @param {number|string} ms
  3627. * @return {Runnable|number} ms or Runnable instance.
  3628. */
  3629. Runnable.prototype.timeout = function(ms) {
  3630. if (!arguments.length) {
  3631. return this._timeout;
  3632. }
  3633. if (ms === 0) {
  3634. this._enableTimeouts = false;
  3635. }
  3636. if (typeof ms === 'string') {
  3637. ms = milliseconds(ms);
  3638. }
  3639. debug('timeout %d', ms);
  3640. this._timeout = ms;
  3641. if (this.timer) {
  3642. this.resetTimeout();
  3643. }
  3644. return this;
  3645. };
  3646. /**
  3647. * Set & get slow `ms`.
  3648. *
  3649. * @api private
  3650. * @param {number|string} ms
  3651. * @return {Runnable|number} ms or Runnable instance.
  3652. */
  3653. Runnable.prototype.slow = function(ms) {
  3654. if (!arguments.length) {
  3655. return this._slow;
  3656. }
  3657. if (typeof ms === 'string') {
  3658. ms = milliseconds(ms);
  3659. }
  3660. debug('timeout %d', ms);
  3661. this._slow = ms;
  3662. return this;
  3663. };
  3664. /**
  3665. * Set and get whether timeout is `enabled`.
  3666. *
  3667. * @api private
  3668. * @param {boolean} enabled
  3669. * @return {Runnable|boolean} enabled or Runnable instance.
  3670. */
  3671. Runnable.prototype.enableTimeouts = function(enabled) {
  3672. if (!arguments.length) {
  3673. return this._enableTimeouts;
  3674. }
  3675. debug('enableTimeouts %s', enabled);
  3676. this._enableTimeouts = enabled;
  3677. return this;
  3678. };
  3679. /**
  3680. * Halt and mark as pending.
  3681. *
  3682. * @api public
  3683. */
  3684. Runnable.prototype.skip = function() {
  3685. throw new Pending();
  3686. };
  3687. /**
  3688. * Check if this runnable or its parent suite is marked as pending.
  3689. *
  3690. * @api private
  3691. */
  3692. Runnable.prototype.isPending = function() {
  3693. return this.pending || (this.parent && this.parent.isPending());
  3694. };
  3695. /**
  3696. * Set number of retries.
  3697. *
  3698. * @api private
  3699. */
  3700. Runnable.prototype.retries = function(n) {
  3701. if (!arguments.length) {
  3702. return this._retries;
  3703. }
  3704. this._retries = n;
  3705. };
  3706. /**
  3707. * Get current retry
  3708. *
  3709. * @api private
  3710. */
  3711. Runnable.prototype.currentRetry = function(n) {
  3712. if (!arguments.length) {
  3713. return this._currentRetry;
  3714. }
  3715. this._currentRetry = n;
  3716. };
  3717. /**
  3718. * Return the full title generated by recursively concatenating the parent's
  3719. * full title.
  3720. *
  3721. * @api public
  3722. * @return {string}
  3723. */
  3724. Runnable.prototype.fullTitle = function() {
  3725. return this.parent.fullTitle() + ' ' + this.title;
  3726. };
  3727. /**
  3728. * Clear the timeout.
  3729. *
  3730. * @api private
  3731. */
  3732. Runnable.prototype.clearTimeout = function() {
  3733. clearTimeout(this.timer);
  3734. };
  3735. /**
  3736. * Inspect the runnable void of private properties.
  3737. *
  3738. * @api private
  3739. * @return {string}
  3740. */
  3741. Runnable.prototype.inspect = function() {
  3742. return JSON.stringify(this, function(key, val) {
  3743. if (key[0] === '_') {
  3744. return;
  3745. }
  3746. if (key === 'parent') {
  3747. return '#<Suite>';
  3748. }
  3749. if (key === 'ctx') {
  3750. return '#<Context>';
  3751. }
  3752. return val;
  3753. }, 2);
  3754. };
  3755. /**
  3756. * Reset the timeout.
  3757. *
  3758. * @api private
  3759. */
  3760. Runnable.prototype.resetTimeout = function() {
  3761. var self = this;
  3762. var ms = this.timeout() || 1e9;
  3763. if (!this._enableTimeouts) {
  3764. return;
  3765. }
  3766. this.clearTimeout();
  3767. this.timer = setTimeout(function() {
  3768. if (!self._enableTimeouts) {
  3769. return;
  3770. }
  3771. self.callback(new Error('timeout of ' + ms + 'ms exceeded. Ensure the done() callback is being called in this test.'));
  3772. self.timedOut = true;
  3773. }, ms);
  3774. };
  3775. /**
  3776. * Whitelist a list of globals for this test run.
  3777. *
  3778. * @api private
  3779. * @param {string[]} globals
  3780. */
  3781. Runnable.prototype.globals = function(globals) {
  3782. if (!arguments.length) {
  3783. return this._allowedGlobals;
  3784. }
  3785. this._allowedGlobals = globals;
  3786. };
  3787. /**
  3788. * Run the test and invoke `fn(err)`.
  3789. *
  3790. * @param {Function} fn
  3791. * @api private
  3792. */
  3793. Runnable.prototype.run = function(fn) {
  3794. var self = this;
  3795. var start = new Date();
  3796. var ctx = this.ctx;
  3797. var finished;
  3798. var emitted;
  3799. // Sometimes the ctx exists, but it is not runnable
  3800. if (ctx && ctx.runnable) {
  3801. ctx.runnable(this);
  3802. }
  3803. // called multiple times
  3804. function multiple(err) {
  3805. if (emitted) {
  3806. return;
  3807. }
  3808. emitted = true;
  3809. self.emit('error', err || new Error('done() called multiple times; stacktrace may be inaccurate'));
  3810. }
  3811. // finished
  3812. function done(err) {
  3813. var ms = self.timeout();
  3814. if (self.timedOut) {
  3815. return;
  3816. }
  3817. if (finished) {
  3818. return multiple(err || self._trace);
  3819. }
  3820. self.clearTimeout();
  3821. self.duration = new Date() - start;
  3822. finished = true;
  3823. if (!err && self.duration > ms && self._enableTimeouts) {
  3824. err = new Error('timeout of ' + ms + 'ms exceeded. Ensure the done() callback is being called in this test.');
  3825. }
  3826. fn(err);
  3827. }
  3828. // for .resetTimeout()
  3829. this.callback = done;
  3830. // explicit async with `done` argument
  3831. if (this.async) {
  3832. this.resetTimeout();
  3833. if (this.allowUncaught) {
  3834. return callFnAsync(this.fn);
  3835. }
  3836. try {
  3837. callFnAsync(this.fn);
  3838. } catch (err) {
  3839. done(utils.getError(err));
  3840. }
  3841. return;
  3842. }
  3843. if (this.allowUncaught) {
  3844. callFn(this.fn);
  3845. done();
  3846. return;
  3847. }
  3848. // sync or promise-returning
  3849. try {
  3850. if (this.isPending()) {
  3851. done();
  3852. } else {
  3853. callFn(this.fn);
  3854. }
  3855. } catch (err) {
  3856. done(utils.getError(err));
  3857. }
  3858. function callFn(fn) {
  3859. var result = fn.call(ctx);
  3860. if (result && typeof result.then === 'function') {
  3861. self.resetTimeout();
  3862. result
  3863. .then(function() {
  3864. done();
  3865. // Return null so libraries like bluebird do not warn about
  3866. // subsequently constructed Promises.
  3867. return null;
  3868. },
  3869. function(reason) {
  3870. done(reason || new Error('Promise rejected with no or falsy reason'));
  3871. });
  3872. } else {
  3873. if (self.asyncOnly) {
  3874. return done(new Error('--async-only option in use without declaring `done()` or returning a promise'));
  3875. }
  3876. done();
  3877. }
  3878. }
  3879. function callFnAsync(fn) {
  3880. fn.call(ctx, function(err) {
  3881. if (err instanceof Error || toString.call(err) === '[object Error]') {
  3882. return done(err);
  3883. }
  3884. if (err) {
  3885. if (Object.prototype.toString.call(err) === '[object Object]') {
  3886. return done(new Error('done() invoked with non-Error: '
  3887. + JSON.stringify(err)));
  3888. }
  3889. return done(new Error('done() invoked with non-Error: ' + err));
  3890. }
  3891. done();
  3892. });
  3893. }
  3894. };
  3895. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3896. },{"./ms":15,"./pending":16,"./utils":39,"debug":2,"events":3}],36:[function(require,module,exports){
  3897. (function (process,global){
  3898. /**
  3899. * Module dependencies.
  3900. */
  3901. var EventEmitter = require('events').EventEmitter;
  3902. var Pending = require('./pending');
  3903. var utils = require('./utils');
  3904. var inherits = utils.inherits;
  3905. var debug = require('debug')('mocha:runner');
  3906. var Runnable = require('./runnable');
  3907. var filter = utils.filter;
  3908. var indexOf = utils.indexOf;
  3909. var keys = utils.keys;
  3910. var stackFilter = utils.stackTraceFilter();
  3911. var stringify = utils.stringify;
  3912. var type = utils.type;
  3913. var undefinedError = utils.undefinedError;
  3914. var isArray = utils.isArray;
  3915. /**
  3916. * Non-enumerable globals.
  3917. */
  3918. var globals = [
  3919. 'setTimeout',
  3920. 'clearTimeout',
  3921. 'setInterval',
  3922. 'clearInterval',
  3923. 'XMLHttpRequest',
  3924. 'Date',
  3925. 'setImmediate',
  3926. 'clearImmediate'
  3927. ];
  3928. /**
  3929. * Expose `Runner`.
  3930. */
  3931. module.exports = Runner;
  3932. /**
  3933. * Initialize a `Runner` for the given `suite`.
  3934. *
  3935. * Events:
  3936. *
  3937. * - `start` execution started
  3938. * - `end` execution complete
  3939. * - `suite` (suite) test suite execution started
  3940. * - `suite end` (suite) all tests (and sub-suites) have finished
  3941. * - `test` (test) test execution started
  3942. * - `test end` (test) test completed
  3943. * - `hook` (hook) hook execution started
  3944. * - `hook end` (hook) hook complete
  3945. * - `pass` (test) test passed
  3946. * - `fail` (test, err) test failed
  3947. * - `pending` (test) test pending
  3948. *
  3949. * @api public
  3950. * @param {Suite} suite Root suite
  3951. * @param {boolean} [delay] Whether or not to delay execution of root suite
  3952. * until ready.
  3953. */
  3954. function Runner(suite, delay) {
  3955. var self = this;
  3956. this._globals = [];
  3957. this._abort = false;
  3958. this._delay = delay;
  3959. this.suite = suite;
  3960. this.started = false;
  3961. this.total = suite.total();
  3962. this.failures = 0;
  3963. this.on('test end', function(test) {
  3964. self.checkGlobals(test);
  3965. });
  3966. this.on('hook end', function(hook) {
  3967. self.checkGlobals(hook);
  3968. });
  3969. this._defaultGrep = /.*/;
  3970. this.grep(this._defaultGrep);
  3971. this.globals(this.globalProps().concat(extraGlobals()));
  3972. }
  3973. /**
  3974. * Wrapper for setImmediate, process.nextTick, or browser polyfill.
  3975. *
  3976. * @param {Function} fn
  3977. * @api private
  3978. */
  3979. Runner.immediately = global.setImmediate || process.nextTick;
  3980. /**
  3981. * Inherit from `EventEmitter.prototype`.
  3982. */
  3983. inherits(Runner, EventEmitter);
  3984. /**
  3985. * Run tests with full titles matching `re`. Updates runner.total
  3986. * with number of tests matched.
  3987. *
  3988. * @param {RegExp} re
  3989. * @param {Boolean} invert
  3990. * @return {Runner} for chaining
  3991. * @api public
  3992. * @param {RegExp} re
  3993. * @param {boolean} invert
  3994. * @return {Runner} Runner instance.
  3995. */
  3996. Runner.prototype.grep = function(re, invert) {
  3997. debug('grep %s', re);
  3998. this._grep = re;
  3999. this._invert = invert;
  4000. this.total = this.grepTotal(this.suite);
  4001. return this;
  4002. };
  4003. /**
  4004. * Returns the number of tests matching the grep search for the
  4005. * given suite.
  4006. *
  4007. * @param {Suite} suite
  4008. * @return {Number}
  4009. * @api public
  4010. * @param {Suite} suite
  4011. * @return {number}
  4012. */
  4013. Runner.prototype.grepTotal = function(suite) {
  4014. var self = this;
  4015. var total = 0;
  4016. suite.eachTest(function(test) {
  4017. var match = self._grep.test(test.fullTitle());
  4018. if (self._invert) {
  4019. match = !match;
  4020. }
  4021. if (match) {
  4022. total++;
  4023. }
  4024. });
  4025. return total;
  4026. };
  4027. /**
  4028. * Return a list of global properties.
  4029. *
  4030. * @return {Array}
  4031. * @api private
  4032. */
  4033. Runner.prototype.globalProps = function() {
  4034. var props = keys(global);
  4035. // non-enumerables
  4036. for (var i = 0; i < globals.length; ++i) {
  4037. if (~indexOf(props, globals[i])) {
  4038. continue;
  4039. }
  4040. props.push(globals[i]);
  4041. }
  4042. return props;
  4043. };
  4044. /**
  4045. * Allow the given `arr` of globals.
  4046. *
  4047. * @param {Array} arr
  4048. * @return {Runner} for chaining
  4049. * @api public
  4050. * @param {Array} arr
  4051. * @return {Runner} Runner instance.
  4052. */
  4053. Runner.prototype.globals = function(arr) {
  4054. if (!arguments.length) {
  4055. return this._globals;
  4056. }
  4057. debug('globals %j', arr);
  4058. this._globals = this._globals.concat(arr);
  4059. return this;
  4060. };
  4061. /**
  4062. * Check for global variable leaks.
  4063. *
  4064. * @api private
  4065. */
  4066. Runner.prototype.checkGlobals = function(test) {
  4067. if (this.ignoreLeaks) {
  4068. return;
  4069. }
  4070. var ok = this._globals;
  4071. var globals = this.globalProps();
  4072. var leaks;
  4073. if (test) {
  4074. ok = ok.concat(test._allowedGlobals || []);
  4075. }
  4076. if (this.prevGlobalsLength === globals.length) {
  4077. return;
  4078. }
  4079. this.prevGlobalsLength = globals.length;
  4080. leaks = filterLeaks(ok, globals);
  4081. this._globals = this._globals.concat(leaks);
  4082. if (leaks.length > 1) {
  4083. this.fail(test, new Error('global leaks detected: ' + leaks.join(', ') + ''));
  4084. } else if (leaks.length) {
  4085. this.fail(test, new Error('global leak detected: ' + leaks[0]));
  4086. }
  4087. };
  4088. /**
  4089. * Fail the given `test`.
  4090. *
  4091. * @api private
  4092. * @param {Test} test
  4093. * @param {Error} err
  4094. */
  4095. Runner.prototype.fail = function(test, err) {
  4096. ++this.failures;
  4097. test.state = 'failed';
  4098. if (!(err instanceof Error || err && typeof err.message === 'string')) {
  4099. err = new Error('the ' + type(err) + ' ' + stringify(err) + ' was thrown, throw an Error :)');
  4100. }
  4101. err.stack = (this.fullStackTrace || !err.stack)
  4102. ? err.stack
  4103. : stackFilter(err.stack);
  4104. this.emit('fail', test, err);
  4105. };
  4106. /**
  4107. * Fail the given `hook` with `err`.
  4108. *
  4109. * Hook failures work in the following pattern:
  4110. * - If bail, then exit
  4111. * - Failed `before` hook skips all tests in a suite and subsuites,
  4112. * but jumps to corresponding `after` hook
  4113. * - Failed `before each` hook skips remaining tests in a
  4114. * suite and jumps to corresponding `after each` hook,
  4115. * which is run only once
  4116. * - Failed `after` hook does not alter
  4117. * execution order
  4118. * - Failed `after each` hook skips remaining tests in a
  4119. * suite and subsuites, but executes other `after each`
  4120. * hooks
  4121. *
  4122. * @api private
  4123. * @param {Hook} hook
  4124. * @param {Error} err
  4125. */
  4126. Runner.prototype.failHook = function(hook, err) {
  4127. if (hook.ctx && hook.ctx.currentTest) {
  4128. hook.originalTitle = hook.originalTitle || hook.title;
  4129. hook.title = hook.originalTitle + ' for "' + hook.ctx.currentTest.title + '"';
  4130. }
  4131. this.fail(hook, err);
  4132. if (this.suite.bail()) {
  4133. this.emit('end');
  4134. }
  4135. };
  4136. /**
  4137. * Run hook `name` callbacks and then invoke `fn()`.
  4138. *
  4139. * @api private
  4140. * @param {string} name
  4141. * @param {Function} fn
  4142. */
  4143. Runner.prototype.hook = function(name, fn) {
  4144. var suite = this.suite;
  4145. var hooks = suite['_' + name];
  4146. var self = this;
  4147. function next(i) {
  4148. var hook = hooks[i];
  4149. if (!hook) {
  4150. return fn();
  4151. }
  4152. self.currentRunnable = hook;
  4153. hook.ctx.currentTest = self.test;
  4154. self.emit('hook', hook);
  4155. if (!hook.listeners('error').length) {
  4156. hook.on('error', function(err) {
  4157. self.failHook(hook, err);
  4158. });
  4159. }
  4160. hook.run(function(err) {
  4161. var testError = hook.error();
  4162. if (testError) {
  4163. self.fail(self.test, testError);
  4164. }
  4165. if (err) {
  4166. if (err instanceof Pending) {
  4167. suite.pending = true;
  4168. } else {
  4169. self.failHook(hook, err);
  4170. // stop executing hooks, notify callee of hook err
  4171. return fn(err);
  4172. }
  4173. }
  4174. self.emit('hook end', hook);
  4175. delete hook.ctx.currentTest;
  4176. next(++i);
  4177. });
  4178. }
  4179. Runner.immediately(function() {
  4180. next(0);
  4181. });
  4182. };
  4183. /**
  4184. * Run hook `name` for the given array of `suites`
  4185. * in order, and callback `fn(err, errSuite)`.
  4186. *
  4187. * @api private
  4188. * @param {string} name
  4189. * @param {Array} suites
  4190. * @param {Function} fn
  4191. */
  4192. Runner.prototype.hooks = function(name, suites, fn) {
  4193. var self = this;
  4194. var orig = this.suite;
  4195. function next(suite) {
  4196. self.suite = suite;
  4197. if (!suite) {
  4198. self.suite = orig;
  4199. return fn();
  4200. }
  4201. self.hook(name, function(err) {
  4202. if (err) {
  4203. var errSuite = self.suite;
  4204. self.suite = orig;
  4205. return fn(err, errSuite);
  4206. }
  4207. next(suites.pop());
  4208. });
  4209. }
  4210. next(suites.pop());
  4211. };
  4212. /**
  4213. * Run hooks from the top level down.
  4214. *
  4215. * @param {String} name
  4216. * @param {Function} fn
  4217. * @api private
  4218. */
  4219. Runner.prototype.hookUp = function(name, fn) {
  4220. var suites = [this.suite].concat(this.parents()).reverse();
  4221. this.hooks(name, suites, fn);
  4222. };
  4223. /**
  4224. * Run hooks from the bottom up.
  4225. *
  4226. * @param {String} name
  4227. * @param {Function} fn
  4228. * @api private
  4229. */
  4230. Runner.prototype.hookDown = function(name, fn) {
  4231. var suites = [this.suite].concat(this.parents());
  4232. this.hooks(name, suites, fn);
  4233. };
  4234. /**
  4235. * Return an array of parent Suites from
  4236. * closest to furthest.
  4237. *
  4238. * @return {Array}
  4239. * @api private
  4240. */
  4241. Runner.prototype.parents = function() {
  4242. var suite = this.suite;
  4243. var suites = [];
  4244. while (suite.parent) {
  4245. suite = suite.parent;
  4246. suites.push(suite);
  4247. }
  4248. return suites;
  4249. };
  4250. /**
  4251. * Run the current test and callback `fn(err)`.
  4252. *
  4253. * @param {Function} fn
  4254. * @api private
  4255. */
  4256. Runner.prototype.runTest = function(fn) {
  4257. var self = this;
  4258. var test = this.test;
  4259. if (this.asyncOnly) {
  4260. test.asyncOnly = true;
  4261. }
  4262. if (this.allowUncaught) {
  4263. test.allowUncaught = true;
  4264. return test.run(fn);
  4265. }
  4266. try {
  4267. test.on('error', function(err) {
  4268. self.fail(test, err);
  4269. });
  4270. test.run(fn);
  4271. } catch (err) {
  4272. fn(err);
  4273. }
  4274. };
  4275. /**
  4276. * Run tests in the given `suite` and invoke the callback `fn()` when complete.
  4277. *
  4278. * @api private
  4279. * @param {Suite} suite
  4280. * @param {Function} fn
  4281. */
  4282. Runner.prototype.runTests = function(suite, fn) {
  4283. var self = this;
  4284. var tests = suite.tests.slice();
  4285. var test;
  4286. function hookErr(_, errSuite, after) {
  4287. // before/after Each hook for errSuite failed:
  4288. var orig = self.suite;
  4289. // for failed 'after each' hook start from errSuite parent,
  4290. // otherwise start from errSuite itself
  4291. self.suite = after ? errSuite.parent : errSuite;
  4292. if (self.suite) {
  4293. // call hookUp afterEach
  4294. self.hookUp('afterEach', function(err2, errSuite2) {
  4295. self.suite = orig;
  4296. // some hooks may fail even now
  4297. if (err2) {
  4298. return hookErr(err2, errSuite2, true);
  4299. }
  4300. // report error suite
  4301. fn(errSuite);
  4302. });
  4303. } else {
  4304. // there is no need calling other 'after each' hooks
  4305. self.suite = orig;
  4306. fn(errSuite);
  4307. }
  4308. }
  4309. function next(err, errSuite) {
  4310. // if we bail after first err
  4311. if (self.failures && suite._bail) {
  4312. return fn();
  4313. }
  4314. if (self._abort) {
  4315. return fn();
  4316. }
  4317. if (err) {
  4318. return hookErr(err, errSuite, true);
  4319. }
  4320. // next test
  4321. test = tests.shift();
  4322. // all done
  4323. if (!test) {
  4324. return fn();
  4325. }
  4326. // grep
  4327. var match = self._grep.test(test.fullTitle());
  4328. if (self._invert) {
  4329. match = !match;
  4330. }
  4331. if (!match) {
  4332. // Run immediately only if we have defined a grep. When we
  4333. // define a grep — It can cause maximum callstack error if
  4334. // the grep is doing a large recursive loop by neglecting
  4335. // all tests. The run immediately function also comes with
  4336. // a performance cost. So we don't want to run immediately
  4337. // if we run the whole test suite, because running the whole
  4338. // test suite don't do any immediate recursive loops. Thus,
  4339. // allowing a JS runtime to breathe.
  4340. if (self._grep !== self._defaultGrep) {
  4341. Runner.immediately(next);
  4342. } else {
  4343. next();
  4344. }
  4345. return;
  4346. }
  4347. if (test.isPending()) {
  4348. self.emit('pending', test);
  4349. self.emit('test end', test);
  4350. return next();
  4351. }
  4352. // execute test and hook(s)
  4353. self.emit('test', self.test = test);
  4354. self.hookDown('beforeEach', function(err, errSuite) {
  4355. if (suite.isPending()) {
  4356. self.emit('pending', test);
  4357. self.emit('test end', test);
  4358. return next();
  4359. }
  4360. if (err) {
  4361. return hookErr(err, errSuite, false);
  4362. }
  4363. self.currentRunnable = self.test;
  4364. self.runTest(function(err) {
  4365. test = self.test;
  4366. if (err) {
  4367. var retry = test.currentRetry();
  4368. if (err instanceof Pending) {
  4369. test.pending = true;
  4370. self.emit('pending', test);
  4371. } else if (retry < test.retries()) {
  4372. var clonedTest = test.clone();
  4373. clonedTest.currentRetry(retry + 1);
  4374. tests.unshift(clonedTest);
  4375. // Early return + hook trigger so that it doesn't
  4376. // increment the count wrong
  4377. return self.hookUp('afterEach', next);
  4378. } else {
  4379. self.fail(test, err);
  4380. }
  4381. self.emit('test end', test);
  4382. if (err instanceof Pending) {
  4383. return next();
  4384. }
  4385. return self.hookUp('afterEach', next);
  4386. }
  4387. test.state = 'passed';
  4388. self.emit('pass', test);
  4389. self.emit('test end', test);
  4390. self.hookUp('afterEach', next);
  4391. });
  4392. });
  4393. }
  4394. this.next = next;
  4395. this.hookErr = hookErr;
  4396. next();
  4397. };
  4398. /**
  4399. * Run the given `suite` and invoke the callback `fn()` when complete.
  4400. *
  4401. * @api private
  4402. * @param {Suite} suite
  4403. * @param {Function} fn
  4404. */
  4405. Runner.prototype.runSuite = function(suite, fn) {
  4406. var i = 0;
  4407. var self = this;
  4408. var total = this.grepTotal(suite);
  4409. var afterAllHookCalled = false;
  4410. debug('run suite %s', suite.fullTitle());
  4411. if (!total || (self.failures && suite._bail)) {
  4412. return fn();
  4413. }
  4414. this.emit('suite', this.suite = suite);
  4415. function next(errSuite) {
  4416. if (errSuite) {
  4417. // current suite failed on a hook from errSuite
  4418. if (errSuite === suite) {
  4419. // if errSuite is current suite
  4420. // continue to the next sibling suite
  4421. return done();
  4422. }
  4423. // errSuite is among the parents of current suite
  4424. // stop execution of errSuite and all sub-suites
  4425. return done(errSuite);
  4426. }
  4427. if (self._abort) {
  4428. return done();
  4429. }
  4430. var curr = suite.suites[i++];
  4431. if (!curr) {
  4432. return done();
  4433. }
  4434. // Avoid grep neglecting large number of tests causing a
  4435. // huge recursive loop and thus a maximum call stack error.
  4436. // See comment in `this.runTests()` for more information.
  4437. if (self._grep !== self._defaultGrep) {
  4438. Runner.immediately(function() {
  4439. self.runSuite(curr, next);
  4440. });
  4441. } else {
  4442. self.runSuite(curr, next);
  4443. }
  4444. }
  4445. function done(errSuite) {
  4446. self.suite = suite;
  4447. self.nextSuite = next;
  4448. if (afterAllHookCalled) {
  4449. fn(errSuite);
  4450. } else {
  4451. // mark that the afterAll block has been called once
  4452. // and so can be skipped if there is an error in it.
  4453. afterAllHookCalled = true;
  4454. // remove reference to test
  4455. delete self.test;
  4456. self.hook('afterAll', function() {
  4457. self.emit('suite end', suite);
  4458. fn(errSuite);
  4459. });
  4460. }
  4461. }
  4462. this.nextSuite = next;
  4463. this.hook('beforeAll', function(err) {
  4464. if (err) {
  4465. return done();
  4466. }
  4467. self.runTests(suite, next);
  4468. });
  4469. };
  4470. /**
  4471. * Handle uncaught exceptions.
  4472. *
  4473. * @param {Error} err
  4474. * @api private
  4475. */
  4476. Runner.prototype.uncaught = function(err) {
  4477. if (err) {
  4478. debug('uncaught exception %s', err !== function() {
  4479. return this;
  4480. }.call(err) ? err : (err.message || err));
  4481. } else {
  4482. debug('uncaught undefined exception');
  4483. err = undefinedError();
  4484. }
  4485. err.uncaught = true;
  4486. var runnable = this.currentRunnable;
  4487. if (!runnable) {
  4488. runnable = new Runnable('Uncaught error outside test suite');
  4489. runnable.parent = this.suite;
  4490. if (this.started) {
  4491. this.fail(runnable, err);
  4492. } else {
  4493. // Can't recover from this failure
  4494. this.emit('start');
  4495. this.fail(runnable, err);
  4496. this.emit('end');
  4497. }
  4498. return;
  4499. }
  4500. runnable.clearTimeout();
  4501. // Ignore errors if complete
  4502. if (runnable.state) {
  4503. return;
  4504. }
  4505. this.fail(runnable, err);
  4506. // recover from test
  4507. if (runnable.type === 'test') {
  4508. this.emit('test end', runnable);
  4509. this.hookUp('afterEach', this.next);
  4510. return;
  4511. }
  4512. // recover from hooks
  4513. if (runnable.type === 'hook') {
  4514. var errSuite = this.suite;
  4515. // if hook failure is in afterEach block
  4516. if (runnable.fullTitle().indexOf('after each') > -1) {
  4517. return this.hookErr(err, errSuite, true);
  4518. }
  4519. // if hook failure is in beforeEach block
  4520. if (runnable.fullTitle().indexOf('before each') > -1) {
  4521. return this.hookErr(err, errSuite, false);
  4522. }
  4523. // if hook failure is in after or before blocks
  4524. return this.nextSuite(errSuite);
  4525. }
  4526. // bail
  4527. this.emit('end');
  4528. };
  4529. /**
  4530. * Cleans up the references to all the deferred functions
  4531. * (before/after/beforeEach/afterEach) and tests of a Suite.
  4532. * These must be deleted otherwise a memory leak can happen,
  4533. * as those functions may reference variables from closures,
  4534. * thus those variables can never be garbage collected as long
  4535. * as the deferred functions exist.
  4536. *
  4537. * @param {Suite} suite
  4538. */
  4539. function cleanSuiteReferences(suite) {
  4540. function cleanArrReferences(arr) {
  4541. for (var i = 0; i < arr.length; i++) {
  4542. delete arr[i].fn;
  4543. }
  4544. }
  4545. if (isArray(suite._beforeAll)) {
  4546. cleanArrReferences(suite._beforeAll);
  4547. }
  4548. if (isArray(suite._beforeEach)) {
  4549. cleanArrReferences(suite._beforeEach);
  4550. }
  4551. if (isArray(suite._afterAll)) {
  4552. cleanArrReferences(suite._afterAll);
  4553. }
  4554. if (isArray(suite._afterEach)) {
  4555. cleanArrReferences(suite._afterEach);
  4556. }
  4557. for (var i = 0; i < suite.tests.length; i++) {
  4558. delete suite.tests[i].fn;
  4559. }
  4560. }
  4561. /**
  4562. * Run the root suite and invoke `fn(failures)`
  4563. * on completion.
  4564. *
  4565. * @param {Function} fn
  4566. * @return {Runner} for chaining
  4567. * @api public
  4568. * @param {Function} fn
  4569. * @return {Runner} Runner instance.
  4570. */
  4571. Runner.prototype.run = function(fn) {
  4572. var self = this;
  4573. var rootSuite = this.suite;
  4574. fn = fn || function() {};
  4575. function uncaught(err) {
  4576. self.uncaught(err);
  4577. }
  4578. function start() {
  4579. self.started = true;
  4580. self.emit('start');
  4581. self.runSuite(rootSuite, function() {
  4582. debug('finished running');
  4583. self.emit('end');
  4584. });
  4585. }
  4586. debug('start');
  4587. // references cleanup to avoid memory leaks
  4588. this.on('suite end', cleanSuiteReferences);
  4589. // callback
  4590. this.on('end', function() {
  4591. debug('end');
  4592. process.removeListener('uncaughtException', uncaught);
  4593. fn(self.failures);
  4594. });
  4595. // uncaught exception
  4596. process.on('uncaughtException', uncaught);
  4597. if (this._delay) {
  4598. // for reporters, I guess.
  4599. // might be nice to debounce some dots while we wait.
  4600. this.emit('waiting', rootSuite);
  4601. rootSuite.once('run', start);
  4602. } else {
  4603. start();
  4604. }
  4605. return this;
  4606. };
  4607. /**
  4608. * Cleanly abort execution.
  4609. *
  4610. * @api public
  4611. * @return {Runner} Runner instance.
  4612. */
  4613. Runner.prototype.abort = function() {
  4614. debug('aborting');
  4615. this._abort = true;
  4616. return this;
  4617. };
  4618. /**
  4619. * Filter leaks with the given globals flagged as `ok`.
  4620. *
  4621. * @api private
  4622. * @param {Array} ok
  4623. * @param {Array} globals
  4624. * @return {Array}
  4625. */
  4626. function filterLeaks(ok, globals) {
  4627. return filter(globals, function(key) {
  4628. // Firefox and Chrome exposes iframes as index inside the window object
  4629. if (/^d+/.test(key)) {
  4630. return false;
  4631. }
  4632. // in firefox
  4633. // if runner runs in an iframe, this iframe's window.getInterface method not init at first
  4634. // it is assigned in some seconds
  4635. if (global.navigator && (/^getInterface/).test(key)) {
  4636. return false;
  4637. }
  4638. // an iframe could be approached by window[iframeIndex]
  4639. // in ie6,7,8 and opera, iframeIndex is enumerable, this could cause leak
  4640. if (global.navigator && (/^\d+/).test(key)) {
  4641. return false;
  4642. }
  4643. // Opera and IE expose global variables for HTML element IDs (issue #243)
  4644. if (/^mocha-/.test(key)) {
  4645. return false;
  4646. }
  4647. var matched = filter(ok, function(ok) {
  4648. if (~ok.indexOf('*')) {
  4649. return key.indexOf(ok.split('*')[0]) === 0;
  4650. }
  4651. return key === ok;
  4652. });
  4653. return !matched.length && (!global.navigator || key !== 'onerror');
  4654. });
  4655. }
  4656. /**
  4657. * Array of globals dependent on the environment.
  4658. *
  4659. * @return {Array}
  4660. * @api private
  4661. */
  4662. function extraGlobals() {
  4663. if (typeof process === 'object' && typeof process.version === 'string') {
  4664. var parts = process.version.split('.');
  4665. var nodeVersion = utils.reduce(parts, function(a, v) {
  4666. return a << 8 | v;
  4667. });
  4668. // 'errno' was renamed to process._errno in v0.9.11.
  4669. if (nodeVersion < 0x00090B) {
  4670. return ['errno'];
  4671. }
  4672. }
  4673. return [];
  4674. }
  4675. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  4676. },{"./pending":16,"./runnable":35,"./utils":39,"_process":58,"debug":2,"events":3}],37:[function(require,module,exports){
  4677. /**
  4678. * Module dependencies.
  4679. */
  4680. var EventEmitter = require('events').EventEmitter;
  4681. var Hook = require('./hook');
  4682. var utils = require('./utils');
  4683. var inherits = utils.inherits;
  4684. var debug = require('debug')('mocha:suite');
  4685. var milliseconds = require('./ms');
  4686. /**
  4687. * Expose `Suite`.
  4688. */
  4689. exports = module.exports = Suite;
  4690. /**
  4691. * Create a new `Suite` with the given `title` and parent `Suite`. When a suite
  4692. * with the same title is already present, that suite is returned to provide
  4693. * nicer reporter and more flexible meta-testing.
  4694. *
  4695. * @api public
  4696. * @param {Suite} parent
  4697. * @param {string} title
  4698. * @return {Suite}
  4699. */
  4700. exports.create = function(parent, title) {
  4701. var suite = new Suite(title, parent.ctx);
  4702. suite.parent = parent;
  4703. title = suite.fullTitle();
  4704. parent.addSuite(suite);
  4705. return suite;
  4706. };
  4707. /**
  4708. * Initialize a new `Suite` with the given `title` and `ctx`.
  4709. *
  4710. * @api private
  4711. * @param {string} title
  4712. * @param {Context} parentContext
  4713. */
  4714. function Suite(title, parentContext) {
  4715. this.title = title;
  4716. function Context() {}
  4717. Context.prototype = parentContext;
  4718. this.ctx = new Context();
  4719. this.suites = [];
  4720. this.tests = [];
  4721. this.pending = false;
  4722. this._beforeEach = [];
  4723. this._beforeAll = [];
  4724. this._afterEach = [];
  4725. this._afterAll = [];
  4726. this.root = !title;
  4727. this._timeout = 2000;
  4728. this._enableTimeouts = true;
  4729. this._slow = 75;
  4730. this._bail = false;
  4731. this._retries = -1;
  4732. this.delayed = false;
  4733. }
  4734. /**
  4735. * Inherit from `EventEmitter.prototype`.
  4736. */
  4737. inherits(Suite, EventEmitter);
  4738. /**
  4739. * Return a clone of this `Suite`.
  4740. *
  4741. * @api private
  4742. * @return {Suite}
  4743. */
  4744. Suite.prototype.clone = function() {
  4745. var suite = new Suite(this.title);
  4746. debug('clone');
  4747. suite.ctx = this.ctx;
  4748. suite.timeout(this.timeout());
  4749. suite.retries(this.retries());
  4750. suite.enableTimeouts(this.enableTimeouts());
  4751. suite.slow(this.slow());
  4752. suite.bail(this.bail());
  4753. return suite;
  4754. };
  4755. /**
  4756. * Set timeout `ms` or short-hand such as "2s".
  4757. *
  4758. * @api private
  4759. * @param {number|string} ms
  4760. * @return {Suite|number} for chaining
  4761. */
  4762. Suite.prototype.timeout = function(ms) {
  4763. if (!arguments.length) {
  4764. return this._timeout;
  4765. }
  4766. if (ms.toString() === '0') {
  4767. this._enableTimeouts = false;
  4768. }
  4769. if (typeof ms === 'string') {
  4770. ms = milliseconds(ms);
  4771. }
  4772. debug('timeout %d', ms);
  4773. this._timeout = parseInt(ms, 10);
  4774. return this;
  4775. };
  4776. /**
  4777. * Set number of times to retry a failed test.
  4778. *
  4779. * @api private
  4780. * @param {number|string} n
  4781. * @return {Suite|number} for chaining
  4782. */
  4783. Suite.prototype.retries = function(n) {
  4784. if (!arguments.length) {
  4785. return this._retries;
  4786. }
  4787. debug('retries %d', n);
  4788. this._retries = parseInt(n, 10) || 0;
  4789. return this;
  4790. };
  4791. /**
  4792. * Set timeout to `enabled`.
  4793. *
  4794. * @api private
  4795. * @param {boolean} enabled
  4796. * @return {Suite|boolean} self or enabled
  4797. */
  4798. Suite.prototype.enableTimeouts = function(enabled) {
  4799. if (!arguments.length) {
  4800. return this._enableTimeouts;
  4801. }
  4802. debug('enableTimeouts %s', enabled);
  4803. this._enableTimeouts = enabled;
  4804. return this;
  4805. };
  4806. /**
  4807. * Set slow `ms` or short-hand such as "2s".
  4808. *
  4809. * @api private
  4810. * @param {number|string} ms
  4811. * @return {Suite|number} for chaining
  4812. */
  4813. Suite.prototype.slow = function(ms) {
  4814. if (!arguments.length) {
  4815. return this._slow;
  4816. }
  4817. if (typeof ms === 'string') {
  4818. ms = milliseconds(ms);
  4819. }
  4820. debug('slow %d', ms);
  4821. this._slow = ms;
  4822. return this;
  4823. };
  4824. /**
  4825. * Sets whether to bail after first error.
  4826. *
  4827. * @api private
  4828. * @param {boolean} bail
  4829. * @return {Suite|number} for chaining
  4830. */
  4831. Suite.prototype.bail = function(bail) {
  4832. if (!arguments.length) {
  4833. return this._bail;
  4834. }
  4835. debug('bail %s', bail);
  4836. this._bail = bail;
  4837. return this;
  4838. };
  4839. /**
  4840. * Check if this suite or its parent suite is marked as pending.
  4841. *
  4842. * @api private
  4843. */
  4844. Suite.prototype.isPending = function() {
  4845. return this.pending || (this.parent && this.parent.isPending());
  4846. };
  4847. /**
  4848. * Run `fn(test[, done])` before running tests.
  4849. *
  4850. * @api private
  4851. * @param {string} title
  4852. * @param {Function} fn
  4853. * @return {Suite} for chaining
  4854. */
  4855. Suite.prototype.beforeAll = function(title, fn) {
  4856. if (this.isPending()) {
  4857. return this;
  4858. }
  4859. if (typeof title === 'function') {
  4860. fn = title;
  4861. title = fn.name;
  4862. }
  4863. title = '"before all" hook' + (title ? ': ' + title : '');
  4864. var hook = new Hook(title, fn);
  4865. hook.parent = this;
  4866. hook.timeout(this.timeout());
  4867. hook.retries(this.retries());
  4868. hook.enableTimeouts(this.enableTimeouts());
  4869. hook.slow(this.slow());
  4870. hook.ctx = this.ctx;
  4871. this._beforeAll.push(hook);
  4872. this.emit('beforeAll', hook);
  4873. return this;
  4874. };
  4875. /**
  4876. * Run `fn(test[, done])` after running tests.
  4877. *
  4878. * @api private
  4879. * @param {string} title
  4880. * @param {Function} fn
  4881. * @return {Suite} for chaining
  4882. */
  4883. Suite.prototype.afterAll = function(title, fn) {
  4884. if (this.isPending()) {
  4885. return this;
  4886. }
  4887. if (typeof title === 'function') {
  4888. fn = title;
  4889. title = fn.name;
  4890. }
  4891. title = '"after all" hook' + (title ? ': ' + title : '');
  4892. var hook = new Hook(title, fn);
  4893. hook.parent = this;
  4894. hook.timeout(this.timeout());
  4895. hook.retries(this.retries());
  4896. hook.enableTimeouts(this.enableTimeouts());
  4897. hook.slow(this.slow());
  4898. hook.ctx = this.ctx;
  4899. this._afterAll.push(hook);
  4900. this.emit('afterAll', hook);
  4901. return this;
  4902. };
  4903. /**
  4904. * Run `fn(test[, done])` before each test case.
  4905. *
  4906. * @api private
  4907. * @param {string} title
  4908. * @param {Function} fn
  4909. * @return {Suite} for chaining
  4910. */
  4911. Suite.prototype.beforeEach = function(title, fn) {
  4912. if (this.isPending()) {
  4913. return this;
  4914. }
  4915. if (typeof title === 'function') {
  4916. fn = title;
  4917. title = fn.name;
  4918. }
  4919. title = '"before each" hook' + (title ? ': ' + title : '');
  4920. var hook = new Hook(title, fn);
  4921. hook.parent = this;
  4922. hook.timeout(this.timeout());
  4923. hook.retries(this.retries());
  4924. hook.enableTimeouts(this.enableTimeouts());
  4925. hook.slow(this.slow());
  4926. hook.ctx = this.ctx;
  4927. this._beforeEach.push(hook);
  4928. this.emit('beforeEach', hook);
  4929. return this;
  4930. };
  4931. /**
  4932. * Run `fn(test[, done])` after each test case.
  4933. *
  4934. * @api private
  4935. * @param {string} title
  4936. * @param {Function} fn
  4937. * @return {Suite} for chaining
  4938. */
  4939. Suite.prototype.afterEach = function(title, fn) {
  4940. if (this.isPending()) {
  4941. return this;
  4942. }
  4943. if (typeof title === 'function') {
  4944. fn = title;
  4945. title = fn.name;
  4946. }
  4947. title = '"after each" hook' + (title ? ': ' + title : '');
  4948. var hook = new Hook(title, fn);
  4949. hook.parent = this;
  4950. hook.timeout(this.timeout());
  4951. hook.retries(this.retries());
  4952. hook.enableTimeouts(this.enableTimeouts());
  4953. hook.slow(this.slow());
  4954. hook.ctx = this.ctx;
  4955. this._afterEach.push(hook);
  4956. this.emit('afterEach', hook);
  4957. return this;
  4958. };
  4959. /**
  4960. * Add a test `suite`.
  4961. *
  4962. * @api private
  4963. * @param {Suite} suite
  4964. * @return {Suite} for chaining
  4965. */
  4966. Suite.prototype.addSuite = function(suite) {
  4967. suite.parent = this;
  4968. suite.timeout(this.timeout());
  4969. suite.retries(this.retries());
  4970. suite.enableTimeouts(this.enableTimeouts());
  4971. suite.slow(this.slow());
  4972. suite.bail(this.bail());
  4973. this.suites.push(suite);
  4974. this.emit('suite', suite);
  4975. return this;
  4976. };
  4977. /**
  4978. * Add a `test` to this suite.
  4979. *
  4980. * @api private
  4981. * @param {Test} test
  4982. * @return {Suite} for chaining
  4983. */
  4984. Suite.prototype.addTest = function(test) {
  4985. test.parent = this;
  4986. test.timeout(this.timeout());
  4987. test.retries(this.retries());
  4988. test.enableTimeouts(this.enableTimeouts());
  4989. test.slow(this.slow());
  4990. test.ctx = this.ctx;
  4991. this.tests.push(test);
  4992. this.emit('test', test);
  4993. return this;
  4994. };
  4995. /**
  4996. * Return the full title generated by recursively concatenating the parent's
  4997. * full title.
  4998. *
  4999. * @api public
  5000. * @return {string}
  5001. */
  5002. Suite.prototype.fullTitle = function() {
  5003. if (this.parent) {
  5004. var full = this.parent.fullTitle();
  5005. if (full) {
  5006. return full + ' ' + this.title;
  5007. }
  5008. }
  5009. return this.title;
  5010. };
  5011. /**
  5012. * Return the total number of tests.
  5013. *
  5014. * @api public
  5015. * @return {number}
  5016. */
  5017. Suite.prototype.total = function() {
  5018. return utils.reduce(this.suites, function(sum, suite) {
  5019. return sum + suite.total();
  5020. }, 0) + this.tests.length;
  5021. };
  5022. /**
  5023. * Iterates through each suite recursively to find all tests. Applies a
  5024. * function in the format `fn(test)`.
  5025. *
  5026. * @api private
  5027. * @param {Function} fn
  5028. * @return {Suite}
  5029. */
  5030. Suite.prototype.eachTest = function(fn) {
  5031. utils.forEach(this.tests, fn);
  5032. utils.forEach(this.suites, function(suite) {
  5033. suite.eachTest(fn);
  5034. });
  5035. return this;
  5036. };
  5037. /**
  5038. * This will run the root suite if we happen to be running in delayed mode.
  5039. */
  5040. Suite.prototype.run = function run() {
  5041. if (this.root) {
  5042. this.emit('run');
  5043. }
  5044. };
  5045. },{"./hook":7,"./ms":15,"./utils":39,"debug":2,"events":3}],38:[function(require,module,exports){
  5046. /**
  5047. * Module dependencies.
  5048. */
  5049. var Runnable = require('./runnable');
  5050. var inherits = require('./utils').inherits;
  5051. /**
  5052. * Expose `Test`.
  5053. */
  5054. module.exports = Test;
  5055. /**
  5056. * Initialize a new `Test` with the given `title` and callback `fn`.
  5057. *
  5058. * @api private
  5059. * @param {String} title
  5060. * @param {Function} fn
  5061. */
  5062. function Test(title, fn) {
  5063. Runnable.call(this, title, fn);
  5064. this.pending = !fn;
  5065. this.type = 'test';
  5066. }
  5067. /**
  5068. * Inherit from `Runnable.prototype`.
  5069. */
  5070. inherits(Test, Runnable);
  5071. Test.prototype.clone = function() {
  5072. var test = new Test(this.title, this.fn);
  5073. test.timeout(this.timeout());
  5074. test.slow(this.slow());
  5075. test.enableTimeouts(this.enableTimeouts());
  5076. test.retries(this.retries());
  5077. test.currentRetry(this.currentRetry());
  5078. test.globals(this.globals());
  5079. test.parent = this.parent;
  5080. test.file = this.file;
  5081. test.ctx = this.ctx;
  5082. return test;
  5083. };
  5084. },{"./runnable":35,"./utils":39}],39:[function(require,module,exports){
  5085. (function (process,Buffer){
  5086. /* eslint-env browser */
  5087. /**
  5088. * Module dependencies.
  5089. */
  5090. var basename = require('path').basename;
  5091. var debug = require('debug')('mocha:watch');
  5092. var exists = require('fs').existsSync || require('path').existsSync;
  5093. var glob = require('glob');
  5094. var join = require('path').join;
  5095. var readdirSync = require('fs').readdirSync;
  5096. var statSync = require('fs').statSync;
  5097. var watchFile = require('fs').watchFile;
  5098. var toISOString = require('to-iso-string');
  5099. /**
  5100. * Ignored directories.
  5101. */
  5102. var ignore = ['node_modules', '.git'];
  5103. exports.inherits = require('util').inherits;
  5104. /**
  5105. * Escape special characters in the given string of html.
  5106. *
  5107. * @api private
  5108. * @param {string} html
  5109. * @return {string}
  5110. */
  5111. exports.escape = function(html) {
  5112. return String(html)
  5113. .replace(/&/g, '&amp;')
  5114. .replace(/"/g, '&quot;')
  5115. .replace(/</g, '&lt;')
  5116. .replace(/>/g, '&gt;');
  5117. };
  5118. /**
  5119. * Array#forEach (<=IE8)
  5120. *
  5121. * @api private
  5122. * @param {Array} arr
  5123. * @param {Function} fn
  5124. * @param {Object} scope
  5125. */
  5126. exports.forEach = function(arr, fn, scope) {
  5127. for (var i = 0, l = arr.length; i < l; i++) {
  5128. fn.call(scope, arr[i], i);
  5129. }
  5130. };
  5131. /**
  5132. * Test if the given obj is type of string.
  5133. *
  5134. * @api private
  5135. * @param {Object} obj
  5136. * @return {boolean}
  5137. */
  5138. exports.isString = function(obj) {
  5139. return typeof obj === 'string';
  5140. };
  5141. /**
  5142. * Array#map (<=IE8)
  5143. *
  5144. * @api private
  5145. * @param {Array} arr
  5146. * @param {Function} fn
  5147. * @param {Object} scope
  5148. * @return {Array}
  5149. */
  5150. exports.map = function(arr, fn, scope) {
  5151. var result = [];
  5152. for (var i = 0, l = arr.length; i < l; i++) {
  5153. result.push(fn.call(scope, arr[i], i, arr));
  5154. }
  5155. return result;
  5156. };
  5157. /**
  5158. * Array#indexOf (<=IE8)
  5159. *
  5160. * @api private
  5161. * @param {Array} arr
  5162. * @param {Object} obj to find index of
  5163. * @param {number} start
  5164. * @return {number}
  5165. */
  5166. exports.indexOf = function(arr, obj, start) {
  5167. for (var i = start || 0, l = arr.length; i < l; i++) {
  5168. if (arr[i] === obj) {
  5169. return i;
  5170. }
  5171. }
  5172. return -1;
  5173. };
  5174. /**
  5175. * Array#reduce (<=IE8)
  5176. *
  5177. * @api private
  5178. * @param {Array} arr
  5179. * @param {Function} fn
  5180. * @param {Object} val Initial value.
  5181. * @return {*}
  5182. */
  5183. exports.reduce = function(arr, fn, val) {
  5184. var rval = val;
  5185. for (var i = 0, l = arr.length; i < l; i++) {
  5186. rval = fn(rval, arr[i], i, arr);
  5187. }
  5188. return rval;
  5189. };
  5190. /**
  5191. * Array#filter (<=IE8)
  5192. *
  5193. * @api private
  5194. * @param {Array} arr
  5195. * @param {Function} fn
  5196. * @return {Array}
  5197. */
  5198. exports.filter = function(arr, fn) {
  5199. var ret = [];
  5200. for (var i = 0, l = arr.length; i < l; i++) {
  5201. var val = arr[i];
  5202. if (fn(val, i, arr)) {
  5203. ret.push(val);
  5204. }
  5205. }
  5206. return ret;
  5207. };
  5208. /**
  5209. * Object.keys (<=IE8)
  5210. *
  5211. * @api private
  5212. * @param {Object} obj
  5213. * @return {Array} keys
  5214. */
  5215. exports.keys = typeof Object.keys === 'function' ? Object.keys : function(obj) {
  5216. var keys = [];
  5217. var has = Object.prototype.hasOwnProperty; // for `window` on <=IE8
  5218. for (var key in obj) {
  5219. if (has.call(obj, key)) {
  5220. keys.push(key);
  5221. }
  5222. }
  5223. return keys;
  5224. };
  5225. /**
  5226. * Watch the given `files` for changes
  5227. * and invoke `fn(file)` on modification.
  5228. *
  5229. * @api private
  5230. * @param {Array} files
  5231. * @param {Function} fn
  5232. */
  5233. exports.watch = function(files, fn) {
  5234. var options = { interval: 100 };
  5235. files.forEach(function(file) {
  5236. debug('file %s', file);
  5237. watchFile(file, options, function(curr, prev) {
  5238. if (prev.mtime < curr.mtime) {
  5239. fn(file);
  5240. }
  5241. });
  5242. });
  5243. };
  5244. /**
  5245. * Array.isArray (<=IE8)
  5246. *
  5247. * @api private
  5248. * @param {Object} obj
  5249. * @return {Boolean}
  5250. */
  5251. var isArray = typeof Array.isArray === 'function' ? Array.isArray : function(obj) {
  5252. return Object.prototype.toString.call(obj) === '[object Array]';
  5253. };
  5254. exports.isArray = isArray;
  5255. /**
  5256. * Buffer.prototype.toJSON polyfill.
  5257. *
  5258. * @type {Function}
  5259. */
  5260. if (typeof Buffer !== 'undefined' && Buffer.prototype) {
  5261. Buffer.prototype.toJSON = Buffer.prototype.toJSON || function() {
  5262. return Array.prototype.slice.call(this, 0);
  5263. };
  5264. }
  5265. /**
  5266. * Ignored files.
  5267. *
  5268. * @api private
  5269. * @param {string} path
  5270. * @return {boolean}
  5271. */
  5272. function ignored(path) {
  5273. return !~ignore.indexOf(path);
  5274. }
  5275. /**
  5276. * Lookup files in the given `dir`.
  5277. *
  5278. * @api private
  5279. * @param {string} dir
  5280. * @param {string[]} [ext=['.js']]
  5281. * @param {Array} [ret=[]]
  5282. * @return {Array}
  5283. */
  5284. exports.files = function(dir, ext, ret) {
  5285. ret = ret || [];
  5286. ext = ext || ['js'];
  5287. var re = new RegExp('\\.(' + ext.join('|') + ')$');
  5288. readdirSync(dir)
  5289. .filter(ignored)
  5290. .forEach(function(path) {
  5291. path = join(dir, path);
  5292. if (statSync(path).isDirectory()) {
  5293. exports.files(path, ext, ret);
  5294. } else if (path.match(re)) {
  5295. ret.push(path);
  5296. }
  5297. });
  5298. return ret;
  5299. };
  5300. /**
  5301. * Compute a slug from the given `str`.
  5302. *
  5303. * @api private
  5304. * @param {string} str
  5305. * @return {string}
  5306. */
  5307. exports.slug = function(str) {
  5308. return str
  5309. .toLowerCase()
  5310. .replace(/ +/g, '-')
  5311. .replace(/[^-\w]/g, '');
  5312. };
  5313. /**
  5314. * Strip the function definition from `str`, and re-indent for pre whitespace.
  5315. *
  5316. * @param {string} str
  5317. * @return {string}
  5318. */
  5319. exports.clean = function(str) {
  5320. str = str
  5321. .replace(/\r\n?|[\n\u2028\u2029]/g, '\n').replace(/^\uFEFF/, '')
  5322. .replace(/^function *\(.*\)\s*\{|\(.*\) *=> *\{?/, '')
  5323. .replace(/\s+\}$/, '');
  5324. var spaces = str.match(/^\n?( *)/)[1].length;
  5325. var tabs = str.match(/^\n?(\t*)/)[1].length;
  5326. var re = new RegExp('^\n?' + (tabs ? '\t' : ' ') + '{' + (tabs ? tabs : spaces) + '}', 'gm');
  5327. str = str.replace(re, '');
  5328. return exports.trim(str);
  5329. };
  5330. /**
  5331. * Trim the given `str`.
  5332. *
  5333. * @api private
  5334. * @param {string} str
  5335. * @return {string}
  5336. */
  5337. exports.trim = function(str) {
  5338. return str.replace(/^\s+|\s+$/g, '');
  5339. };
  5340. /**
  5341. * Parse the given `qs`.
  5342. *
  5343. * @api private
  5344. * @param {string} qs
  5345. * @return {Object}
  5346. */
  5347. exports.parseQuery = function(qs) {
  5348. return exports.reduce(qs.replace('?', '').split('&'), function(obj, pair) {
  5349. var i = pair.indexOf('=');
  5350. var key = pair.slice(0, i);
  5351. var val = pair.slice(++i);
  5352. obj[key] = decodeURIComponent(val);
  5353. return obj;
  5354. }, {});
  5355. };
  5356. /**
  5357. * Highlight the given string of `js`.
  5358. *
  5359. * @api private
  5360. * @param {string} js
  5361. * @return {string}
  5362. */
  5363. function highlight(js) {
  5364. return js
  5365. .replace(/</g, '&lt;')
  5366. .replace(/>/g, '&gt;')
  5367. .replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
  5368. .replace(/('.*?')/gm, '<span class="string">$1</span>')
  5369. .replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
  5370. .replace(/(\d+)/gm, '<span class="number">$1</span>')
  5371. .replace(/\bnew[ \t]+(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>')
  5372. .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>');
  5373. }
  5374. /**
  5375. * Highlight the contents of tag `name`.
  5376. *
  5377. * @api private
  5378. * @param {string} name
  5379. */
  5380. exports.highlightTags = function(name) {
  5381. var code = document.getElementById('mocha').getElementsByTagName(name);
  5382. for (var i = 0, len = code.length; i < len; ++i) {
  5383. code[i].innerHTML = highlight(code[i].innerHTML);
  5384. }
  5385. };
  5386. /**
  5387. * If a value could have properties, and has none, this function is called,
  5388. * which returns a string representation of the empty value.
  5389. *
  5390. * Functions w/ no properties return `'[Function]'`
  5391. * Arrays w/ length === 0 return `'[]'`
  5392. * Objects w/ no properties return `'{}'`
  5393. * All else: return result of `value.toString()`
  5394. *
  5395. * @api private
  5396. * @param {*} value The value to inspect.
  5397. * @param {string} [type] The type of the value, if known.
  5398. * @returns {string}
  5399. */
  5400. function emptyRepresentation(value, type) {
  5401. type = type || exports.type(value);
  5402. switch (type) {
  5403. case 'function':
  5404. return '[Function]';
  5405. case 'object':
  5406. return '{}';
  5407. case 'array':
  5408. return '[]';
  5409. default:
  5410. return value.toString();
  5411. }
  5412. }
  5413. /**
  5414. * Takes some variable and asks `Object.prototype.toString()` what it thinks it
  5415. * is.
  5416. *
  5417. * @api private
  5418. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
  5419. * @param {*} value The value to test.
  5420. * @returns {string}
  5421. * @example
  5422. * type({}) // 'object'
  5423. * type([]) // 'array'
  5424. * type(1) // 'number'
  5425. * type(false) // 'boolean'
  5426. * type(Infinity) // 'number'
  5427. * type(null) // 'null'
  5428. * type(new Date()) // 'date'
  5429. * type(/foo/) // 'regexp'
  5430. * type('type') // 'string'
  5431. * type(global) // 'global'
  5432. */
  5433. exports.type = function type(value) {
  5434. if (value === undefined) {
  5435. return 'undefined';
  5436. } else if (value === null) {
  5437. return 'null';
  5438. } else if (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) {
  5439. return 'buffer';
  5440. }
  5441. return Object.prototype.toString.call(value)
  5442. .replace(/^\[.+\s(.+?)\]$/, '$1')
  5443. .toLowerCase();
  5444. };
  5445. /**
  5446. * Stringify `value`. Different behavior depending on type of value:
  5447. *
  5448. * - If `value` is undefined or null, return `'[undefined]'` or `'[null]'`, respectively.
  5449. * - If `value` is not an object, function or array, return result of `value.toString()` wrapped in double-quotes.
  5450. * - If `value` is an *empty* object, function, or array, return result of function
  5451. * {@link emptyRepresentation}.
  5452. * - If `value` has properties, call {@link exports.canonicalize} on it, then return result of
  5453. * JSON.stringify().
  5454. *
  5455. * @api private
  5456. * @see exports.type
  5457. * @param {*} value
  5458. * @return {string}
  5459. */
  5460. exports.stringify = function(value) {
  5461. var type = exports.type(value);
  5462. if (!~exports.indexOf(['object', 'array', 'function'], type)) {
  5463. if (type !== 'buffer') {
  5464. return jsonStringify(value);
  5465. }
  5466. var json = value.toJSON();
  5467. // Based on the toJSON result
  5468. return jsonStringify(json.data && json.type ? json.data : json, 2)
  5469. .replace(/,(\n|$)/g, '$1');
  5470. }
  5471. for (var prop in value) {
  5472. if (Object.prototype.hasOwnProperty.call(value, prop)) {
  5473. return jsonStringify(exports.canonicalize(value), 2).replace(/,(\n|$)/g, '$1');
  5474. }
  5475. }
  5476. return emptyRepresentation(value, type);
  5477. };
  5478. /**
  5479. * like JSON.stringify but more sense.
  5480. *
  5481. * @api private
  5482. * @param {Object} object
  5483. * @param {number=} spaces
  5484. * @param {number=} depth
  5485. * @returns {*}
  5486. */
  5487. function jsonStringify(object, spaces, depth) {
  5488. if (typeof spaces === 'undefined') {
  5489. // primitive types
  5490. return _stringify(object);
  5491. }
  5492. depth = depth || 1;
  5493. var space = spaces * depth;
  5494. var str = isArray(object) ? '[' : '{';
  5495. var end = isArray(object) ? ']' : '}';
  5496. var length = typeof object.length === 'number' ? object.length : exports.keys(object).length;
  5497. // `.repeat()` polyfill
  5498. function repeat(s, n) {
  5499. return new Array(n).join(s);
  5500. }
  5501. function _stringify(val) {
  5502. switch (exports.type(val)) {
  5503. case 'null':
  5504. case 'undefined':
  5505. val = '[' + val + ']';
  5506. break;
  5507. case 'array':
  5508. case 'object':
  5509. val = jsonStringify(val, spaces, depth + 1);
  5510. break;
  5511. case 'boolean':
  5512. case 'regexp':
  5513. case 'symbol':
  5514. case 'number':
  5515. val = val === 0 && (1 / val) === -Infinity // `-0`
  5516. ? '-0'
  5517. : val.toString();
  5518. break;
  5519. case 'date':
  5520. var sDate;
  5521. if (isNaN(val.getTime())) { // Invalid date
  5522. sDate = val.toString();
  5523. } else {
  5524. sDate = val.toISOString ? val.toISOString() : toISOString(val);
  5525. }
  5526. val = '[Date: ' + sDate + ']';
  5527. break;
  5528. case 'buffer':
  5529. var json = val.toJSON();
  5530. // Based on the toJSON result
  5531. json = json.data && json.type ? json.data : json;
  5532. val = '[Buffer: ' + jsonStringify(json, 2, depth + 1) + ']';
  5533. break;
  5534. default:
  5535. val = (val === '[Function]' || val === '[Circular]')
  5536. ? val
  5537. : JSON.stringify(val); // string
  5538. }
  5539. return val;
  5540. }
  5541. for (var i in object) {
  5542. if (!Object.prototype.hasOwnProperty.call(object, i)) {
  5543. continue; // not my business
  5544. }
  5545. --length;
  5546. str += '\n ' + repeat(' ', space)
  5547. + (isArray(object) ? '' : '"' + i + '": ') // key
  5548. + _stringify(object[i]) // value
  5549. + (length ? ',' : ''); // comma
  5550. }
  5551. return str
  5552. // [], {}
  5553. + (str.length !== 1 ? '\n' + repeat(' ', --space) + end : end);
  5554. }
  5555. /**
  5556. * Test if a value is a buffer.
  5557. *
  5558. * @api private
  5559. * @param {*} value The value to test.
  5560. * @return {boolean} True if `value` is a buffer, otherwise false
  5561. */
  5562. exports.isBuffer = function(value) {
  5563. return typeof Buffer !== 'undefined' && Buffer.isBuffer(value);
  5564. };
  5565. /**
  5566. * Return a new Thing that has the keys in sorted order. Recursive.
  5567. *
  5568. * If the Thing...
  5569. * - has already been seen, return string `'[Circular]'`
  5570. * - is `undefined`, return string `'[undefined]'`
  5571. * - is `null`, return value `null`
  5572. * - is some other primitive, return the value
  5573. * - is not a primitive or an `Array`, `Object`, or `Function`, return the value of the Thing's `toString()` method
  5574. * - is a non-empty `Array`, `Object`, or `Function`, return the result of calling this function again.
  5575. * - is an empty `Array`, `Object`, or `Function`, return the result of calling `emptyRepresentation()`
  5576. *
  5577. * @api private
  5578. * @see {@link exports.stringify}
  5579. * @param {*} value Thing to inspect. May or may not have properties.
  5580. * @param {Array} [stack=[]] Stack of seen values
  5581. * @return {(Object|Array|Function|string|undefined)}
  5582. */
  5583. exports.canonicalize = function(value, stack) {
  5584. var canonicalizedObj;
  5585. /* eslint-disable no-unused-vars */
  5586. var prop;
  5587. /* eslint-enable no-unused-vars */
  5588. var type = exports.type(value);
  5589. function withStack(value, fn) {
  5590. stack.push(value);
  5591. fn();
  5592. stack.pop();
  5593. }
  5594. stack = stack || [];
  5595. if (exports.indexOf(stack, value) !== -1) {
  5596. return '[Circular]';
  5597. }
  5598. switch (type) {
  5599. case 'undefined':
  5600. case 'buffer':
  5601. case 'null':
  5602. canonicalizedObj = value;
  5603. break;
  5604. case 'array':
  5605. withStack(value, function() {
  5606. canonicalizedObj = exports.map(value, function(item) {
  5607. return exports.canonicalize(item, stack);
  5608. });
  5609. });
  5610. break;
  5611. case 'function':
  5612. /* eslint-disable guard-for-in */
  5613. for (prop in value) {
  5614. canonicalizedObj = {};
  5615. break;
  5616. }
  5617. /* eslint-enable guard-for-in */
  5618. if (!canonicalizedObj) {
  5619. canonicalizedObj = emptyRepresentation(value, type);
  5620. break;
  5621. }
  5622. /* falls through */
  5623. case 'object':
  5624. canonicalizedObj = canonicalizedObj || {};
  5625. withStack(value, function() {
  5626. exports.forEach(exports.keys(value).sort(), function(key) {
  5627. canonicalizedObj[key] = exports.canonicalize(value[key], stack);
  5628. });
  5629. });
  5630. break;
  5631. case 'date':
  5632. case 'number':
  5633. case 'regexp':
  5634. case 'boolean':
  5635. case 'symbol':
  5636. canonicalizedObj = value;
  5637. break;
  5638. default:
  5639. canonicalizedObj = value + '';
  5640. }
  5641. return canonicalizedObj;
  5642. };
  5643. /**
  5644. * Lookup file names at the given `path`.
  5645. *
  5646. * @api public
  5647. * @param {string} path Base path to start searching from.
  5648. * @param {string[]} extensions File extensions to look for.
  5649. * @param {boolean} recursive Whether or not to recurse into subdirectories.
  5650. * @return {string[]} An array of paths.
  5651. */
  5652. exports.lookupFiles = function lookupFiles(path, extensions, recursive) {
  5653. var files = [];
  5654. var re = new RegExp('\\.(' + extensions.join('|') + ')$');
  5655. if (!exists(path)) {
  5656. if (exists(path + '.js')) {
  5657. path += '.js';
  5658. } else {
  5659. files = glob.sync(path);
  5660. if (!files.length) {
  5661. throw new Error("cannot resolve path (or pattern) '" + path + "'");
  5662. }
  5663. return files;
  5664. }
  5665. }
  5666. try {
  5667. var stat = statSync(path);
  5668. if (stat.isFile()) {
  5669. return path;
  5670. }
  5671. } catch (err) {
  5672. // ignore error
  5673. return;
  5674. }
  5675. readdirSync(path).forEach(function(file) {
  5676. file = join(path, file);
  5677. try {
  5678. var stat = statSync(file);
  5679. if (stat.isDirectory()) {
  5680. if (recursive) {
  5681. files = files.concat(lookupFiles(file, extensions, recursive));
  5682. }
  5683. return;
  5684. }
  5685. } catch (err) {
  5686. // ignore error
  5687. return;
  5688. }
  5689. if (!stat.isFile() || !re.test(file) || basename(file)[0] === '.') {
  5690. return;
  5691. }
  5692. files.push(file);
  5693. });
  5694. return files;
  5695. };
  5696. /**
  5697. * Generate an undefined error with a message warning the user.
  5698. *
  5699. * @return {Error}
  5700. */
  5701. exports.undefinedError = function() {
  5702. return new Error('Caught undefined error, did you throw without specifying what?');
  5703. };
  5704. /**
  5705. * Generate an undefined error if `err` is not defined.
  5706. *
  5707. * @param {Error} err
  5708. * @return {Error}
  5709. */
  5710. exports.getError = function(err) {
  5711. return err || exports.undefinedError();
  5712. };
  5713. /**
  5714. * @summary
  5715. * This Filter based on `mocha-clean` module.(see: `github.com/rstacruz/mocha-clean`)
  5716. * @description
  5717. * When invoking this function you get a filter function that get the Error.stack as an input,
  5718. * and return a prettify output.
  5719. * (i.e: strip Mocha and internal node functions from stack trace).
  5720. * @returns {Function}
  5721. */
  5722. exports.stackTraceFilter = function() {
  5723. // TODO: Replace with `process.browser`
  5724. var slash = '/';
  5725. var is = typeof document === 'undefined' ? { node: true } : { browser: true };
  5726. var cwd = is.node
  5727. ? process.cwd() + slash
  5728. : (typeof location === 'undefined' ? window.location : location).href.replace(/\/[^\/]*$/, '/');
  5729. function isMochaInternal(line) {
  5730. return (~line.indexOf('node_modules' + slash + 'mocha' + slash))
  5731. || (~line.indexOf('components' + slash + 'mochajs' + slash))
  5732. || (~line.indexOf('components' + slash + 'mocha' + slash))
  5733. || (~line.indexOf(slash + 'mocha.js'));
  5734. }
  5735. function isNodeInternal(line) {
  5736. return (~line.indexOf('(timers.js:'))
  5737. || (~line.indexOf('(events.js:'))
  5738. || (~line.indexOf('(node.js:'))
  5739. || (~line.indexOf('(module.js:'))
  5740. || (~line.indexOf('GeneratorFunctionPrototype.next (native)'))
  5741. || false;
  5742. }
  5743. return function(stack) {
  5744. stack = stack.split('\n');
  5745. stack = exports.reduce(stack, function(list, line) {
  5746. if (isMochaInternal(line)) {
  5747. return list;
  5748. }
  5749. if (is.node && isNodeInternal(line)) {
  5750. return list;
  5751. }
  5752. // Clean up cwd(absolute)
  5753. if (/\(?.+:\d+:\d+\)?$/.test(line)) {
  5754. line = line.replace(cwd, '');
  5755. }
  5756. list.push(line);
  5757. return list;
  5758. }, []);
  5759. return stack.join('\n');
  5760. };
  5761. };
  5762. }).call(this,require('_process'),require("buffer").Buffer)
  5763. },{"_process":58,"buffer":45,"debug":2,"fs":43,"glob":43,"path":43,"to-iso-string":72,"util":75}],40:[function(require,module,exports){
  5764. 'use strict'
  5765. exports.toByteArray = toByteArray
  5766. exports.fromByteArray = fromByteArray
  5767. var lookup = []
  5768. var revLookup = []
  5769. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  5770. function init () {
  5771. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  5772. for (var i = 0, len = code.length; i < len; ++i) {
  5773. lookup[i] = code[i]
  5774. revLookup[code.charCodeAt(i)] = i
  5775. }
  5776. revLookup['-'.charCodeAt(0)] = 62
  5777. revLookup['_'.charCodeAt(0)] = 63
  5778. }
  5779. init()
  5780. function toByteArray (b64) {
  5781. var i, j, l, tmp, placeHolders, arr
  5782. var len = b64.length
  5783. if (len % 4 > 0) {
  5784. throw new Error('Invalid string. Length must be a multiple of 4')
  5785. }
  5786. // the number of equal signs (place holders)
  5787. // if there are two placeholders, than the two characters before it
  5788. // represent one byte
  5789. // if there is only one, then the three characters before it represent 2 bytes
  5790. // this is just a cheap hack to not do indexOf twice
  5791. placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
  5792. // base64 is 4/3 + up to two characters of the original data
  5793. arr = new Arr(len * 3 / 4 - placeHolders)
  5794. // if there are placeholders, only get up to the last complete 4 chars
  5795. l = placeHolders > 0 ? len - 4 : len
  5796. var L = 0
  5797. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  5798. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
  5799. arr[L++] = (tmp >> 16) & 0xFF
  5800. arr[L++] = (tmp >> 8) & 0xFF
  5801. arr[L++] = tmp & 0xFF
  5802. }
  5803. if (placeHolders === 2) {
  5804. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
  5805. arr[L++] = tmp & 0xFF
  5806. } else if (placeHolders === 1) {
  5807. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
  5808. arr[L++] = (tmp >> 8) & 0xFF
  5809. arr[L++] = tmp & 0xFF
  5810. }
  5811. return arr
  5812. }
  5813. function tripletToBase64 (num) {
  5814. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  5815. }
  5816. function encodeChunk (uint8, start, end) {
  5817. var tmp
  5818. var output = []
  5819. for (var i = start; i < end; i += 3) {
  5820. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  5821. output.push(tripletToBase64(tmp))
  5822. }
  5823. return output.join('')
  5824. }
  5825. function fromByteArray (uint8) {
  5826. var tmp
  5827. var len = uint8.length
  5828. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  5829. var output = ''
  5830. var parts = []
  5831. var maxChunkLength = 16383 // must be multiple of 3
  5832. // go through the array every three bytes, we'll deal with trailing stuff later
  5833. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  5834. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  5835. }
  5836. // pad the end with zeros, but make sure to not forget the extra bytes
  5837. if (extraBytes === 1) {
  5838. tmp = uint8[len - 1]
  5839. output += lookup[tmp >> 2]
  5840. output += lookup[(tmp << 4) & 0x3F]
  5841. output += '=='
  5842. } else if (extraBytes === 2) {
  5843. tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
  5844. output += lookup[tmp >> 10]
  5845. output += lookup[(tmp >> 4) & 0x3F]
  5846. output += lookup[(tmp << 2) & 0x3F]
  5847. output += '='
  5848. }
  5849. parts.push(output)
  5850. return parts.join('')
  5851. }
  5852. },{}],41:[function(require,module,exports){
  5853. },{}],42:[function(require,module,exports){
  5854. (function (process){
  5855. var WritableStream = require('stream').Writable
  5856. var inherits = require('util').inherits
  5857. module.exports = BrowserStdout
  5858. inherits(BrowserStdout, WritableStream)
  5859. function BrowserStdout(opts) {
  5860. if (!(this instanceof BrowserStdout)) return new BrowserStdout(opts)
  5861. opts = opts || {}
  5862. WritableStream.call(this, opts)
  5863. this.label = (opts.label !== undefined) ? opts.label : 'stdout'
  5864. }
  5865. BrowserStdout.prototype._write = function(chunks, encoding, cb) {
  5866. var output = chunks.toString ? chunks.toString() : chunks
  5867. if (this.label === false) {
  5868. console.log(output)
  5869. } else {
  5870. console.log(this.label+':', output)
  5871. }
  5872. process.nextTick(cb)
  5873. }
  5874. }).call(this,require('_process'))
  5875. },{"_process":58,"stream":59,"util":75}],43:[function(require,module,exports){
  5876. arguments[4][41][0].apply(exports,arguments)
  5877. },{"dup":41}],44:[function(require,module,exports){
  5878. (function (global){
  5879. 'use strict';
  5880. var buffer = require('buffer');
  5881. var Buffer = buffer.Buffer;
  5882. var SlowBuffer = buffer.SlowBuffer;
  5883. var MAX_LEN = buffer.kMaxLength || 2147483647;
  5884. exports.alloc = function alloc(size, fill, encoding) {
  5885. if (typeof Buffer.alloc === 'function') {
  5886. return Buffer.alloc(size, fill, encoding);
  5887. }
  5888. if (typeof encoding === 'number') {
  5889. throw new TypeError('encoding must not be number');
  5890. }
  5891. if (typeof size !== 'number') {
  5892. throw new TypeError('size must be a number');
  5893. }
  5894. if (size > MAX_LEN) {
  5895. throw new RangeError('size is too large');
  5896. }
  5897. var enc = encoding;
  5898. var _fill = fill;
  5899. if (_fill === undefined) {
  5900. enc = undefined;
  5901. _fill = 0;
  5902. }
  5903. var buf = new Buffer(size);
  5904. if (typeof _fill === 'string') {
  5905. var fillBuf = new Buffer(_fill, enc);
  5906. var flen = fillBuf.length;
  5907. var i = -1;
  5908. while (++i < size) {
  5909. buf[i] = fillBuf[i % flen];
  5910. }
  5911. } else {
  5912. buf.fill(_fill);
  5913. }
  5914. return buf;
  5915. }
  5916. exports.allocUnsafe = function allocUnsafe(size) {
  5917. if (typeof Buffer.allocUnsafe === 'function') {
  5918. return Buffer.allocUnsafe(size);
  5919. }
  5920. if (typeof size !== 'number') {
  5921. throw new TypeError('size must be a number');
  5922. }
  5923. if (size > MAX_LEN) {
  5924. throw new RangeError('size is too large');
  5925. }
  5926. return new Buffer(size);
  5927. }
  5928. exports.from = function from(value, encodingOrOffset, length) {
  5929. if (typeof Buffer.from === 'function' && (!global.Uint8Array || Uint8Array.from !== Buffer.from)) {
  5930. return Buffer.from(value, encodingOrOffset, length);
  5931. }
  5932. if (typeof value === 'number') {
  5933. throw new TypeError('"value" argument must not be a number');
  5934. }
  5935. if (typeof value === 'string') {
  5936. return new Buffer(value, encodingOrOffset);
  5937. }
  5938. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  5939. var offset = encodingOrOffset;
  5940. if (arguments.length === 1) {
  5941. return new Buffer(value);
  5942. }
  5943. if (typeof offset === 'undefined') {
  5944. offset = 0;
  5945. }
  5946. var len = length;
  5947. if (typeof len === 'undefined') {
  5948. len = value.byteLength - offset;
  5949. }
  5950. if (offset >= value.byteLength) {
  5951. throw new RangeError('\'offset\' is out of bounds');
  5952. }
  5953. if (len > value.byteLength - offset) {
  5954. throw new RangeError('\'length\' is out of bounds');
  5955. }
  5956. return new Buffer(value.slice(offset, offset + len));
  5957. }
  5958. if (Buffer.isBuffer(value)) {
  5959. var out = new Buffer(value.length);
  5960. value.copy(out, 0, 0, value.length);
  5961. return out;
  5962. }
  5963. if (value) {
  5964. if (Array.isArray(value) || (typeof ArrayBuffer !== 'undefined' && value.buffer instanceof ArrayBuffer) || 'length' in value) {
  5965. return new Buffer(value);
  5966. }
  5967. if (value.type === 'Buffer' && Array.isArray(value.data)) {
  5968. return new Buffer(value.data);
  5969. }
  5970. }
  5971. throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.');
  5972. }
  5973. exports.allocUnsafeSlow = function allocUnsafeSlow(size) {
  5974. if (typeof Buffer.allocUnsafeSlow === 'function') {
  5975. return Buffer.allocUnsafeSlow(size);
  5976. }
  5977. if (typeof size !== 'number') {
  5978. throw new TypeError('size must be a number');
  5979. }
  5980. if (size >= MAX_LEN) {
  5981. throw new RangeError('size is too large');
  5982. }
  5983. return new SlowBuffer(size);
  5984. }
  5985. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  5986. },{"buffer":45}],45:[function(require,module,exports){
  5987. (function (global){
  5988. /*!
  5989. * The buffer module from node.js, for the browser.
  5990. *
  5991. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  5992. * @license MIT
  5993. */
  5994. /* eslint-disable no-proto */
  5995. 'use strict'
  5996. var base64 = require('base64-js')
  5997. var ieee754 = require('ieee754')
  5998. var isArray = require('isarray')
  5999. exports.Buffer = Buffer
  6000. exports.SlowBuffer = SlowBuffer
  6001. exports.INSPECT_MAX_BYTES = 50
  6002. /**
  6003. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  6004. * === true Use Uint8Array implementation (fastest)
  6005. * === false Use Object implementation (most compatible, even IE6)
  6006. *
  6007. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  6008. * Opera 11.6+, iOS 4.2+.
  6009. *
  6010. * Due to various browser bugs, sometimes the Object implementation will be used even
  6011. * when the browser supports typed arrays.
  6012. *
  6013. * Note:
  6014. *
  6015. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  6016. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  6017. *
  6018. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  6019. *
  6020. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  6021. * incorrect length in some situations.
  6022. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  6023. * get the Object implementation, which is slower but behaves correctly.
  6024. */
  6025. Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
  6026. ? global.TYPED_ARRAY_SUPPORT
  6027. : typedArraySupport()
  6028. /*
  6029. * Export kMaxLength after typed array support is determined.
  6030. */
  6031. exports.kMaxLength = kMaxLength()
  6032. function typedArraySupport () {
  6033. try {
  6034. var arr = new Uint8Array(1)
  6035. arr.foo = function () { return 42 }
  6036. return arr.foo() === 42 && // typed array instances can be augmented
  6037. typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
  6038. arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
  6039. } catch (e) {
  6040. return false
  6041. }
  6042. }
  6043. function kMaxLength () {
  6044. return Buffer.TYPED_ARRAY_SUPPORT
  6045. ? 0x7fffffff
  6046. : 0x3fffffff
  6047. }
  6048. function createBuffer (that, length) {
  6049. if (kMaxLength() < length) {
  6050. throw new RangeError('Invalid typed array length')
  6051. }
  6052. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6053. // Return an augmented `Uint8Array` instance, for best performance
  6054. that = new Uint8Array(length)
  6055. that.__proto__ = Buffer.prototype
  6056. } else {
  6057. // Fallback: Return an object instance of the Buffer class
  6058. if (that === null) {
  6059. that = new Buffer(length)
  6060. }
  6061. that.length = length
  6062. }
  6063. return that
  6064. }
  6065. /**
  6066. * The Buffer constructor returns instances of `Uint8Array` that have their
  6067. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  6068. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  6069. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  6070. * returns a single octet.
  6071. *
  6072. * The `Uint8Array` prototype remains unmodified.
  6073. */
  6074. function Buffer (arg, encodingOrOffset, length) {
  6075. if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
  6076. return new Buffer(arg, encodingOrOffset, length)
  6077. }
  6078. // Common case.
  6079. if (typeof arg === 'number') {
  6080. if (typeof encodingOrOffset === 'string') {
  6081. throw new Error(
  6082. 'If encoding is specified then the first argument must be a string'
  6083. )
  6084. }
  6085. return allocUnsafe(this, arg)
  6086. }
  6087. return from(this, arg, encodingOrOffset, length)
  6088. }
  6089. Buffer.poolSize = 8192 // not used by this implementation
  6090. // TODO: Legacy, not needed anymore. Remove in next major version.
  6091. Buffer._augment = function (arr) {
  6092. arr.__proto__ = Buffer.prototype
  6093. return arr
  6094. }
  6095. function from (that, value, encodingOrOffset, length) {
  6096. if (typeof value === 'number') {
  6097. throw new TypeError('"value" argument must not be a number')
  6098. }
  6099. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  6100. return fromArrayBuffer(that, value, encodingOrOffset, length)
  6101. }
  6102. if (typeof value === 'string') {
  6103. return fromString(that, value, encodingOrOffset)
  6104. }
  6105. return fromObject(that, value)
  6106. }
  6107. /**
  6108. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  6109. * if value is a number.
  6110. * Buffer.from(str[, encoding])
  6111. * Buffer.from(array)
  6112. * Buffer.from(buffer)
  6113. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  6114. **/
  6115. Buffer.from = function (value, encodingOrOffset, length) {
  6116. return from(null, value, encodingOrOffset, length)
  6117. }
  6118. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6119. Buffer.prototype.__proto__ = Uint8Array.prototype
  6120. Buffer.__proto__ = Uint8Array
  6121. if (typeof Symbol !== 'undefined' && Symbol.species &&
  6122. Buffer[Symbol.species] === Buffer) {
  6123. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  6124. Object.defineProperty(Buffer, Symbol.species, {
  6125. value: null,
  6126. configurable: true
  6127. })
  6128. }
  6129. }
  6130. function assertSize (size) {
  6131. if (typeof size !== 'number') {
  6132. throw new TypeError('"size" argument must be a number')
  6133. }
  6134. }
  6135. function alloc (that, size, fill, encoding) {
  6136. assertSize(size)
  6137. if (size <= 0) {
  6138. return createBuffer(that, size)
  6139. }
  6140. if (fill !== undefined) {
  6141. // Only pay attention to encoding if it's a string. This
  6142. // prevents accidentally sending in a number that would
  6143. // be interpretted as a start offset.
  6144. return typeof encoding === 'string'
  6145. ? createBuffer(that, size).fill(fill, encoding)
  6146. : createBuffer(that, size).fill(fill)
  6147. }
  6148. return createBuffer(that, size)
  6149. }
  6150. /**
  6151. * Creates a new filled Buffer instance.
  6152. * alloc(size[, fill[, encoding]])
  6153. **/
  6154. Buffer.alloc = function (size, fill, encoding) {
  6155. return alloc(null, size, fill, encoding)
  6156. }
  6157. function allocUnsafe (that, size) {
  6158. assertSize(size)
  6159. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
  6160. if (!Buffer.TYPED_ARRAY_SUPPORT) {
  6161. for (var i = 0; i < size; i++) {
  6162. that[i] = 0
  6163. }
  6164. }
  6165. return that
  6166. }
  6167. /**
  6168. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  6169. * */
  6170. Buffer.allocUnsafe = function (size) {
  6171. return allocUnsafe(null, size)
  6172. }
  6173. /**
  6174. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  6175. */
  6176. Buffer.allocUnsafeSlow = function (size) {
  6177. return allocUnsafe(null, size)
  6178. }
  6179. function fromString (that, string, encoding) {
  6180. if (typeof encoding !== 'string' || encoding === '') {
  6181. encoding = 'utf8'
  6182. }
  6183. if (!Buffer.isEncoding(encoding)) {
  6184. throw new TypeError('"encoding" must be a valid string encoding')
  6185. }
  6186. var length = byteLength(string, encoding) | 0
  6187. that = createBuffer(that, length)
  6188. that.write(string, encoding)
  6189. return that
  6190. }
  6191. function fromArrayLike (that, array) {
  6192. var length = checked(array.length) | 0
  6193. that = createBuffer(that, length)
  6194. for (var i = 0; i < length; i += 1) {
  6195. that[i] = array[i] & 255
  6196. }
  6197. return that
  6198. }
  6199. function fromArrayBuffer (that, array, byteOffset, length) {
  6200. array.byteLength // this throws if `array` is not a valid ArrayBuffer
  6201. if (byteOffset < 0 || array.byteLength < byteOffset) {
  6202. throw new RangeError('\'offset\' is out of bounds')
  6203. }
  6204. if (array.byteLength < byteOffset + (length || 0)) {
  6205. throw new RangeError('\'length\' is out of bounds')
  6206. }
  6207. if (length === undefined) {
  6208. array = new Uint8Array(array, byteOffset)
  6209. } else {
  6210. array = new Uint8Array(array, byteOffset, length)
  6211. }
  6212. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6213. // Return an augmented `Uint8Array` instance, for best performance
  6214. that = array
  6215. that.__proto__ = Buffer.prototype
  6216. } else {
  6217. // Fallback: Return an object instance of the Buffer class
  6218. that = fromArrayLike(that, array)
  6219. }
  6220. return that
  6221. }
  6222. function fromObject (that, obj) {
  6223. if (Buffer.isBuffer(obj)) {
  6224. var len = checked(obj.length) | 0
  6225. that = createBuffer(that, len)
  6226. if (that.length === 0) {
  6227. return that
  6228. }
  6229. obj.copy(that, 0, 0, len)
  6230. return that
  6231. }
  6232. if (obj) {
  6233. if ((typeof ArrayBuffer !== 'undefined' &&
  6234. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  6235. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  6236. return createBuffer(that, 0)
  6237. }
  6238. return fromArrayLike(that, obj)
  6239. }
  6240. if (obj.type === 'Buffer' && isArray(obj.data)) {
  6241. return fromArrayLike(that, obj.data)
  6242. }
  6243. }
  6244. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  6245. }
  6246. function checked (length) {
  6247. // Note: cannot use `length < kMaxLength` here because that fails when
  6248. // length is NaN (which is otherwise coerced to zero.)
  6249. if (length >= kMaxLength()) {
  6250. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  6251. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  6252. }
  6253. return length | 0
  6254. }
  6255. function SlowBuffer (length) {
  6256. if (+length != length) { // eslint-disable-line eqeqeq
  6257. length = 0
  6258. }
  6259. return Buffer.alloc(+length)
  6260. }
  6261. Buffer.isBuffer = function isBuffer (b) {
  6262. return !!(b != null && b._isBuffer)
  6263. }
  6264. Buffer.compare = function compare (a, b) {
  6265. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  6266. throw new TypeError('Arguments must be Buffers')
  6267. }
  6268. if (a === b) return 0
  6269. var x = a.length
  6270. var y = b.length
  6271. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  6272. if (a[i] !== b[i]) {
  6273. x = a[i]
  6274. y = b[i]
  6275. break
  6276. }
  6277. }
  6278. if (x < y) return -1
  6279. if (y < x) return 1
  6280. return 0
  6281. }
  6282. Buffer.isEncoding = function isEncoding (encoding) {
  6283. switch (String(encoding).toLowerCase()) {
  6284. case 'hex':
  6285. case 'utf8':
  6286. case 'utf-8':
  6287. case 'ascii':
  6288. case 'binary':
  6289. case 'base64':
  6290. case 'raw':
  6291. case 'ucs2':
  6292. case 'ucs-2':
  6293. case 'utf16le':
  6294. case 'utf-16le':
  6295. return true
  6296. default:
  6297. return false
  6298. }
  6299. }
  6300. Buffer.concat = function concat (list, length) {
  6301. if (!isArray(list)) {
  6302. throw new TypeError('"list" argument must be an Array of Buffers')
  6303. }
  6304. if (list.length === 0) {
  6305. return Buffer.alloc(0)
  6306. }
  6307. var i
  6308. if (length === undefined) {
  6309. length = 0
  6310. for (i = 0; i < list.length; i++) {
  6311. length += list[i].length
  6312. }
  6313. }
  6314. var buffer = Buffer.allocUnsafe(length)
  6315. var pos = 0
  6316. for (i = 0; i < list.length; i++) {
  6317. var buf = list[i]
  6318. if (!Buffer.isBuffer(buf)) {
  6319. throw new TypeError('"list" argument must be an Array of Buffers')
  6320. }
  6321. buf.copy(buffer, pos)
  6322. pos += buf.length
  6323. }
  6324. return buffer
  6325. }
  6326. function byteLength (string, encoding) {
  6327. if (Buffer.isBuffer(string)) {
  6328. return string.length
  6329. }
  6330. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  6331. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  6332. return string.byteLength
  6333. }
  6334. if (typeof string !== 'string') {
  6335. string = '' + string
  6336. }
  6337. var len = string.length
  6338. if (len === 0) return 0
  6339. // Use a for loop to avoid recursion
  6340. var loweredCase = false
  6341. for (;;) {
  6342. switch (encoding) {
  6343. case 'ascii':
  6344. case 'binary':
  6345. // Deprecated
  6346. case 'raw':
  6347. case 'raws':
  6348. return len
  6349. case 'utf8':
  6350. case 'utf-8':
  6351. case undefined:
  6352. return utf8ToBytes(string).length
  6353. case 'ucs2':
  6354. case 'ucs-2':
  6355. case 'utf16le':
  6356. case 'utf-16le':
  6357. return len * 2
  6358. case 'hex':
  6359. return len >>> 1
  6360. case 'base64':
  6361. return base64ToBytes(string).length
  6362. default:
  6363. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  6364. encoding = ('' + encoding).toLowerCase()
  6365. loweredCase = true
  6366. }
  6367. }
  6368. }
  6369. Buffer.byteLength = byteLength
  6370. function slowToString (encoding, start, end) {
  6371. var loweredCase = false
  6372. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  6373. // property of a typed array.
  6374. // This behaves neither like String nor Uint8Array in that we set start/end
  6375. // to their upper/lower bounds if the value passed is out of range.
  6376. // undefined is handled specially as per ECMA-262 6th Edition,
  6377. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  6378. if (start === undefined || start < 0) {
  6379. start = 0
  6380. }
  6381. // Return early if start > this.length. Done here to prevent potential uint32
  6382. // coercion fail below.
  6383. if (start > this.length) {
  6384. return ''
  6385. }
  6386. if (end === undefined || end > this.length) {
  6387. end = this.length
  6388. }
  6389. if (end <= 0) {
  6390. return ''
  6391. }
  6392. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  6393. end >>>= 0
  6394. start >>>= 0
  6395. if (end <= start) {
  6396. return ''
  6397. }
  6398. if (!encoding) encoding = 'utf8'
  6399. while (true) {
  6400. switch (encoding) {
  6401. case 'hex':
  6402. return hexSlice(this, start, end)
  6403. case 'utf8':
  6404. case 'utf-8':
  6405. return utf8Slice(this, start, end)
  6406. case 'ascii':
  6407. return asciiSlice(this, start, end)
  6408. case 'binary':
  6409. return binarySlice(this, start, end)
  6410. case 'base64':
  6411. return base64Slice(this, start, end)
  6412. case 'ucs2':
  6413. case 'ucs-2':
  6414. case 'utf16le':
  6415. case 'utf-16le':
  6416. return utf16leSlice(this, start, end)
  6417. default:
  6418. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  6419. encoding = (encoding + '').toLowerCase()
  6420. loweredCase = true
  6421. }
  6422. }
  6423. }
  6424. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  6425. // Buffer instances.
  6426. Buffer.prototype._isBuffer = true
  6427. function swap (b, n, m) {
  6428. var i = b[n]
  6429. b[n] = b[m]
  6430. b[m] = i
  6431. }
  6432. Buffer.prototype.swap16 = function swap16 () {
  6433. var len = this.length
  6434. if (len % 2 !== 0) {
  6435. throw new RangeError('Buffer size must be a multiple of 16-bits')
  6436. }
  6437. for (var i = 0; i < len; i += 2) {
  6438. swap(this, i, i + 1)
  6439. }
  6440. return this
  6441. }
  6442. Buffer.prototype.swap32 = function swap32 () {
  6443. var len = this.length
  6444. if (len % 4 !== 0) {
  6445. throw new RangeError('Buffer size must be a multiple of 32-bits')
  6446. }
  6447. for (var i = 0; i < len; i += 4) {
  6448. swap(this, i, i + 3)
  6449. swap(this, i + 1, i + 2)
  6450. }
  6451. return this
  6452. }
  6453. Buffer.prototype.toString = function toString () {
  6454. var length = this.length | 0
  6455. if (length === 0) return ''
  6456. if (arguments.length === 0) return utf8Slice(this, 0, length)
  6457. return slowToString.apply(this, arguments)
  6458. }
  6459. Buffer.prototype.equals = function equals (b) {
  6460. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  6461. if (this === b) return true
  6462. return Buffer.compare(this, b) === 0
  6463. }
  6464. Buffer.prototype.inspect = function inspect () {
  6465. var str = ''
  6466. var max = exports.INSPECT_MAX_BYTES
  6467. if (this.length > 0) {
  6468. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  6469. if (this.length > max) str += ' ... '
  6470. }
  6471. return '<Buffer ' + str + '>'
  6472. }
  6473. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  6474. if (!Buffer.isBuffer(target)) {
  6475. throw new TypeError('Argument must be a Buffer')
  6476. }
  6477. if (start === undefined) {
  6478. start = 0
  6479. }
  6480. if (end === undefined) {
  6481. end = target ? target.length : 0
  6482. }
  6483. if (thisStart === undefined) {
  6484. thisStart = 0
  6485. }
  6486. if (thisEnd === undefined) {
  6487. thisEnd = this.length
  6488. }
  6489. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  6490. throw new RangeError('out of range index')
  6491. }
  6492. if (thisStart >= thisEnd && start >= end) {
  6493. return 0
  6494. }
  6495. if (thisStart >= thisEnd) {
  6496. return -1
  6497. }
  6498. if (start >= end) {
  6499. return 1
  6500. }
  6501. start >>>= 0
  6502. end >>>= 0
  6503. thisStart >>>= 0
  6504. thisEnd >>>= 0
  6505. if (this === target) return 0
  6506. var x = thisEnd - thisStart
  6507. var y = end - start
  6508. var len = Math.min(x, y)
  6509. var thisCopy = this.slice(thisStart, thisEnd)
  6510. var targetCopy = target.slice(start, end)
  6511. for (var i = 0; i < len; ++i) {
  6512. if (thisCopy[i] !== targetCopy[i]) {
  6513. x = thisCopy[i]
  6514. y = targetCopy[i]
  6515. break
  6516. }
  6517. }
  6518. if (x < y) return -1
  6519. if (y < x) return 1
  6520. return 0
  6521. }
  6522. function arrayIndexOf (arr, val, byteOffset, encoding) {
  6523. var indexSize = 1
  6524. var arrLength = arr.length
  6525. var valLength = val.length
  6526. if (encoding !== undefined) {
  6527. encoding = String(encoding).toLowerCase()
  6528. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  6529. encoding === 'utf16le' || encoding === 'utf-16le') {
  6530. if (arr.length < 2 || val.length < 2) {
  6531. return -1
  6532. }
  6533. indexSize = 2
  6534. arrLength /= 2
  6535. valLength /= 2
  6536. byteOffset /= 2
  6537. }
  6538. }
  6539. function read (buf, i) {
  6540. if (indexSize === 1) {
  6541. return buf[i]
  6542. } else {
  6543. return buf.readUInt16BE(i * indexSize)
  6544. }
  6545. }
  6546. var foundIndex = -1
  6547. for (var i = 0; byteOffset + i < arrLength; i++) {
  6548. if (read(arr, byteOffset + i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  6549. if (foundIndex === -1) foundIndex = i
  6550. if (i - foundIndex + 1 === valLength) return (byteOffset + foundIndex) * indexSize
  6551. } else {
  6552. if (foundIndex !== -1) i -= i - foundIndex
  6553. foundIndex = -1
  6554. }
  6555. }
  6556. return -1
  6557. }
  6558. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  6559. if (typeof byteOffset === 'string') {
  6560. encoding = byteOffset
  6561. byteOffset = 0
  6562. } else if (byteOffset > 0x7fffffff) {
  6563. byteOffset = 0x7fffffff
  6564. } else if (byteOffset < -0x80000000) {
  6565. byteOffset = -0x80000000
  6566. }
  6567. byteOffset >>= 0
  6568. if (this.length === 0) return -1
  6569. if (byteOffset >= this.length) return -1
  6570. // Negative offsets start from the end of the buffer
  6571. if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0)
  6572. if (typeof val === 'string') {
  6573. val = Buffer.from(val, encoding)
  6574. }
  6575. if (Buffer.isBuffer(val)) {
  6576. // special case: looking for empty string/buffer always fails
  6577. if (val.length === 0) {
  6578. return -1
  6579. }
  6580. return arrayIndexOf(this, val, byteOffset, encoding)
  6581. }
  6582. if (typeof val === 'number') {
  6583. if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') {
  6584. return Uint8Array.prototype.indexOf.call(this, val, byteOffset)
  6585. }
  6586. return arrayIndexOf(this, [ val ], byteOffset, encoding)
  6587. }
  6588. throw new TypeError('val must be string, number or Buffer')
  6589. }
  6590. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  6591. return this.indexOf(val, byteOffset, encoding) !== -1
  6592. }
  6593. function hexWrite (buf, string, offset, length) {
  6594. offset = Number(offset) || 0
  6595. var remaining = buf.length - offset
  6596. if (!length) {
  6597. length = remaining
  6598. } else {
  6599. length = Number(length)
  6600. if (length > remaining) {
  6601. length = remaining
  6602. }
  6603. }
  6604. // must be an even number of digits
  6605. var strLen = string.length
  6606. if (strLen % 2 !== 0) throw new Error('Invalid hex string')
  6607. if (length > strLen / 2) {
  6608. length = strLen / 2
  6609. }
  6610. for (var i = 0; i < length; i++) {
  6611. var parsed = parseInt(string.substr(i * 2, 2), 16)
  6612. if (isNaN(parsed)) return i
  6613. buf[offset + i] = parsed
  6614. }
  6615. return i
  6616. }
  6617. function utf8Write (buf, string, offset, length) {
  6618. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  6619. }
  6620. function asciiWrite (buf, string, offset, length) {
  6621. return blitBuffer(asciiToBytes(string), buf, offset, length)
  6622. }
  6623. function binaryWrite (buf, string, offset, length) {
  6624. return asciiWrite(buf, string, offset, length)
  6625. }
  6626. function base64Write (buf, string, offset, length) {
  6627. return blitBuffer(base64ToBytes(string), buf, offset, length)
  6628. }
  6629. function ucs2Write (buf, string, offset, length) {
  6630. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  6631. }
  6632. Buffer.prototype.write = function write (string, offset, length, encoding) {
  6633. // Buffer#write(string)
  6634. if (offset === undefined) {
  6635. encoding = 'utf8'
  6636. length = this.length
  6637. offset = 0
  6638. // Buffer#write(string, encoding)
  6639. } else if (length === undefined && typeof offset === 'string') {
  6640. encoding = offset
  6641. length = this.length
  6642. offset = 0
  6643. // Buffer#write(string, offset[, length][, encoding])
  6644. } else if (isFinite(offset)) {
  6645. offset = offset | 0
  6646. if (isFinite(length)) {
  6647. length = length | 0
  6648. if (encoding === undefined) encoding = 'utf8'
  6649. } else {
  6650. encoding = length
  6651. length = undefined
  6652. }
  6653. // legacy write(string, encoding, offset, length) - remove in v0.13
  6654. } else {
  6655. throw new Error(
  6656. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  6657. )
  6658. }
  6659. var remaining = this.length - offset
  6660. if (length === undefined || length > remaining) length = remaining
  6661. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  6662. throw new RangeError('Attempt to write outside buffer bounds')
  6663. }
  6664. if (!encoding) encoding = 'utf8'
  6665. var loweredCase = false
  6666. for (;;) {
  6667. switch (encoding) {
  6668. case 'hex':
  6669. return hexWrite(this, string, offset, length)
  6670. case 'utf8':
  6671. case 'utf-8':
  6672. return utf8Write(this, string, offset, length)
  6673. case 'ascii':
  6674. return asciiWrite(this, string, offset, length)
  6675. case 'binary':
  6676. return binaryWrite(this, string, offset, length)
  6677. case 'base64':
  6678. // Warning: maxLength not taken into account in base64Write
  6679. return base64Write(this, string, offset, length)
  6680. case 'ucs2':
  6681. case 'ucs-2':
  6682. case 'utf16le':
  6683. case 'utf-16le':
  6684. return ucs2Write(this, string, offset, length)
  6685. default:
  6686. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  6687. encoding = ('' + encoding).toLowerCase()
  6688. loweredCase = true
  6689. }
  6690. }
  6691. }
  6692. Buffer.prototype.toJSON = function toJSON () {
  6693. return {
  6694. type: 'Buffer',
  6695. data: Array.prototype.slice.call(this._arr || this, 0)
  6696. }
  6697. }
  6698. function base64Slice (buf, start, end) {
  6699. if (start === 0 && end === buf.length) {
  6700. return base64.fromByteArray(buf)
  6701. } else {
  6702. return base64.fromByteArray(buf.slice(start, end))
  6703. }
  6704. }
  6705. function utf8Slice (buf, start, end) {
  6706. end = Math.min(buf.length, end)
  6707. var res = []
  6708. var i = start
  6709. while (i < end) {
  6710. var firstByte = buf[i]
  6711. var codePoint = null
  6712. var bytesPerSequence = (firstByte > 0xEF) ? 4
  6713. : (firstByte > 0xDF) ? 3
  6714. : (firstByte > 0xBF) ? 2
  6715. : 1
  6716. if (i + bytesPerSequence <= end) {
  6717. var secondByte, thirdByte, fourthByte, tempCodePoint
  6718. switch (bytesPerSequence) {
  6719. case 1:
  6720. if (firstByte < 0x80) {
  6721. codePoint = firstByte
  6722. }
  6723. break
  6724. case 2:
  6725. secondByte = buf[i + 1]
  6726. if ((secondByte & 0xC0) === 0x80) {
  6727. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  6728. if (tempCodePoint > 0x7F) {
  6729. codePoint = tempCodePoint
  6730. }
  6731. }
  6732. break
  6733. case 3:
  6734. secondByte = buf[i + 1]
  6735. thirdByte = buf[i + 2]
  6736. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  6737. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  6738. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  6739. codePoint = tempCodePoint
  6740. }
  6741. }
  6742. break
  6743. case 4:
  6744. secondByte = buf[i + 1]
  6745. thirdByte = buf[i + 2]
  6746. fourthByte = buf[i + 3]
  6747. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  6748. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  6749. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  6750. codePoint = tempCodePoint
  6751. }
  6752. }
  6753. }
  6754. }
  6755. if (codePoint === null) {
  6756. // we did not generate a valid codePoint so insert a
  6757. // replacement char (U+FFFD) and advance only 1 byte
  6758. codePoint = 0xFFFD
  6759. bytesPerSequence = 1
  6760. } else if (codePoint > 0xFFFF) {
  6761. // encode to utf16 (surrogate pair dance)
  6762. codePoint -= 0x10000
  6763. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  6764. codePoint = 0xDC00 | codePoint & 0x3FF
  6765. }
  6766. res.push(codePoint)
  6767. i += bytesPerSequence
  6768. }
  6769. return decodeCodePointsArray(res)
  6770. }
  6771. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  6772. // the lowest limit is Chrome, with 0x10000 args.
  6773. // We go 1 magnitude less, for safety
  6774. var MAX_ARGUMENTS_LENGTH = 0x1000
  6775. function decodeCodePointsArray (codePoints) {
  6776. var len = codePoints.length
  6777. if (len <= MAX_ARGUMENTS_LENGTH) {
  6778. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  6779. }
  6780. // Decode in chunks to avoid "call stack size exceeded".
  6781. var res = ''
  6782. var i = 0
  6783. while (i < len) {
  6784. res += String.fromCharCode.apply(
  6785. String,
  6786. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  6787. )
  6788. }
  6789. return res
  6790. }
  6791. function asciiSlice (buf, start, end) {
  6792. var ret = ''
  6793. end = Math.min(buf.length, end)
  6794. for (var i = start; i < end; i++) {
  6795. ret += String.fromCharCode(buf[i] & 0x7F)
  6796. }
  6797. return ret
  6798. }
  6799. function binarySlice (buf, start, end) {
  6800. var ret = ''
  6801. end = Math.min(buf.length, end)
  6802. for (var i = start; i < end; i++) {
  6803. ret += String.fromCharCode(buf[i])
  6804. }
  6805. return ret
  6806. }
  6807. function hexSlice (buf, start, end) {
  6808. var len = buf.length
  6809. if (!start || start < 0) start = 0
  6810. if (!end || end < 0 || end > len) end = len
  6811. var out = ''
  6812. for (var i = start; i < end; i++) {
  6813. out += toHex(buf[i])
  6814. }
  6815. return out
  6816. }
  6817. function utf16leSlice (buf, start, end) {
  6818. var bytes = buf.slice(start, end)
  6819. var res = ''
  6820. for (var i = 0; i < bytes.length; i += 2) {
  6821. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
  6822. }
  6823. return res
  6824. }
  6825. Buffer.prototype.slice = function slice (start, end) {
  6826. var len = this.length
  6827. start = ~~start
  6828. end = end === undefined ? len : ~~end
  6829. if (start < 0) {
  6830. start += len
  6831. if (start < 0) start = 0
  6832. } else if (start > len) {
  6833. start = len
  6834. }
  6835. if (end < 0) {
  6836. end += len
  6837. if (end < 0) end = 0
  6838. } else if (end > len) {
  6839. end = len
  6840. }
  6841. if (end < start) end = start
  6842. var newBuf
  6843. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6844. newBuf = this.subarray(start, end)
  6845. newBuf.__proto__ = Buffer.prototype
  6846. } else {
  6847. var sliceLen = end - start
  6848. newBuf = new Buffer(sliceLen, undefined)
  6849. for (var i = 0; i < sliceLen; i++) {
  6850. newBuf[i] = this[i + start]
  6851. }
  6852. }
  6853. return newBuf
  6854. }
  6855. /*
  6856. * Need to make sure that buffer isn't trying to write out of bounds.
  6857. */
  6858. function checkOffset (offset, ext, length) {
  6859. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  6860. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  6861. }
  6862. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  6863. offset = offset | 0
  6864. byteLength = byteLength | 0
  6865. if (!noAssert) checkOffset(offset, byteLength, this.length)
  6866. var val = this[offset]
  6867. var mul = 1
  6868. var i = 0
  6869. while (++i < byteLength && (mul *= 0x100)) {
  6870. val += this[offset + i] * mul
  6871. }
  6872. return val
  6873. }
  6874. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  6875. offset = offset | 0
  6876. byteLength = byteLength | 0
  6877. if (!noAssert) {
  6878. checkOffset(offset, byteLength, this.length)
  6879. }
  6880. var val = this[offset + --byteLength]
  6881. var mul = 1
  6882. while (byteLength > 0 && (mul *= 0x100)) {
  6883. val += this[offset + --byteLength] * mul
  6884. }
  6885. return val
  6886. }
  6887. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  6888. if (!noAssert) checkOffset(offset, 1, this.length)
  6889. return this[offset]
  6890. }
  6891. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  6892. if (!noAssert) checkOffset(offset, 2, this.length)
  6893. return this[offset] | (this[offset + 1] << 8)
  6894. }
  6895. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  6896. if (!noAssert) checkOffset(offset, 2, this.length)
  6897. return (this[offset] << 8) | this[offset + 1]
  6898. }
  6899. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  6900. if (!noAssert) checkOffset(offset, 4, this.length)
  6901. return ((this[offset]) |
  6902. (this[offset + 1] << 8) |
  6903. (this[offset + 2] << 16)) +
  6904. (this[offset + 3] * 0x1000000)
  6905. }
  6906. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  6907. if (!noAssert) checkOffset(offset, 4, this.length)
  6908. return (this[offset] * 0x1000000) +
  6909. ((this[offset + 1] << 16) |
  6910. (this[offset + 2] << 8) |
  6911. this[offset + 3])
  6912. }
  6913. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  6914. offset = offset | 0
  6915. byteLength = byteLength | 0
  6916. if (!noAssert) checkOffset(offset, byteLength, this.length)
  6917. var val = this[offset]
  6918. var mul = 1
  6919. var i = 0
  6920. while (++i < byteLength && (mul *= 0x100)) {
  6921. val += this[offset + i] * mul
  6922. }
  6923. mul *= 0x80
  6924. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  6925. return val
  6926. }
  6927. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  6928. offset = offset | 0
  6929. byteLength = byteLength | 0
  6930. if (!noAssert) checkOffset(offset, byteLength, this.length)
  6931. var i = byteLength
  6932. var mul = 1
  6933. var val = this[offset + --i]
  6934. while (i > 0 && (mul *= 0x100)) {
  6935. val += this[offset + --i] * mul
  6936. }
  6937. mul *= 0x80
  6938. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  6939. return val
  6940. }
  6941. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  6942. if (!noAssert) checkOffset(offset, 1, this.length)
  6943. if (!(this[offset] & 0x80)) return (this[offset])
  6944. return ((0xff - this[offset] + 1) * -1)
  6945. }
  6946. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  6947. if (!noAssert) checkOffset(offset, 2, this.length)
  6948. var val = this[offset] | (this[offset + 1] << 8)
  6949. return (val & 0x8000) ? val | 0xFFFF0000 : val
  6950. }
  6951. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  6952. if (!noAssert) checkOffset(offset, 2, this.length)
  6953. var val = this[offset + 1] | (this[offset] << 8)
  6954. return (val & 0x8000) ? val | 0xFFFF0000 : val
  6955. }
  6956. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  6957. if (!noAssert) checkOffset(offset, 4, this.length)
  6958. return (this[offset]) |
  6959. (this[offset + 1] << 8) |
  6960. (this[offset + 2] << 16) |
  6961. (this[offset + 3] << 24)
  6962. }
  6963. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  6964. if (!noAssert) checkOffset(offset, 4, this.length)
  6965. return (this[offset] << 24) |
  6966. (this[offset + 1] << 16) |
  6967. (this[offset + 2] << 8) |
  6968. (this[offset + 3])
  6969. }
  6970. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  6971. if (!noAssert) checkOffset(offset, 4, this.length)
  6972. return ieee754.read(this, offset, true, 23, 4)
  6973. }
  6974. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  6975. if (!noAssert) checkOffset(offset, 4, this.length)
  6976. return ieee754.read(this, offset, false, 23, 4)
  6977. }
  6978. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  6979. if (!noAssert) checkOffset(offset, 8, this.length)
  6980. return ieee754.read(this, offset, true, 52, 8)
  6981. }
  6982. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  6983. if (!noAssert) checkOffset(offset, 8, this.length)
  6984. return ieee754.read(this, offset, false, 52, 8)
  6985. }
  6986. function checkInt (buf, value, offset, ext, max, min) {
  6987. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  6988. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  6989. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  6990. }
  6991. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  6992. value = +value
  6993. offset = offset | 0
  6994. byteLength = byteLength | 0
  6995. if (!noAssert) {
  6996. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  6997. checkInt(this, value, offset, byteLength, maxBytes, 0)
  6998. }
  6999. var mul = 1
  7000. var i = 0
  7001. this[offset] = value & 0xFF
  7002. while (++i < byteLength && (mul *= 0x100)) {
  7003. this[offset + i] = (value / mul) & 0xFF
  7004. }
  7005. return offset + byteLength
  7006. }
  7007. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  7008. value = +value
  7009. offset = offset | 0
  7010. byteLength = byteLength | 0
  7011. if (!noAssert) {
  7012. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  7013. checkInt(this, value, offset, byteLength, maxBytes, 0)
  7014. }
  7015. var i = byteLength - 1
  7016. var mul = 1
  7017. this[offset + i] = value & 0xFF
  7018. while (--i >= 0 && (mul *= 0x100)) {
  7019. this[offset + i] = (value / mul) & 0xFF
  7020. }
  7021. return offset + byteLength
  7022. }
  7023. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  7024. value = +value
  7025. offset = offset | 0
  7026. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  7027. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  7028. this[offset] = (value & 0xff)
  7029. return offset + 1
  7030. }
  7031. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  7032. if (value < 0) value = 0xffff + value + 1
  7033. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) {
  7034. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  7035. (littleEndian ? i : 1 - i) * 8
  7036. }
  7037. }
  7038. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  7039. value = +value
  7040. offset = offset | 0
  7041. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  7042. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7043. this[offset] = (value & 0xff)
  7044. this[offset + 1] = (value >>> 8)
  7045. } else {
  7046. objectWriteUInt16(this, value, offset, true)
  7047. }
  7048. return offset + 2
  7049. }
  7050. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  7051. value = +value
  7052. offset = offset | 0
  7053. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  7054. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7055. this[offset] = (value >>> 8)
  7056. this[offset + 1] = (value & 0xff)
  7057. } else {
  7058. objectWriteUInt16(this, value, offset, false)
  7059. }
  7060. return offset + 2
  7061. }
  7062. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  7063. if (value < 0) value = 0xffffffff + value + 1
  7064. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) {
  7065. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  7066. }
  7067. }
  7068. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  7069. value = +value
  7070. offset = offset | 0
  7071. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  7072. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7073. this[offset + 3] = (value >>> 24)
  7074. this[offset + 2] = (value >>> 16)
  7075. this[offset + 1] = (value >>> 8)
  7076. this[offset] = (value & 0xff)
  7077. } else {
  7078. objectWriteUInt32(this, value, offset, true)
  7079. }
  7080. return offset + 4
  7081. }
  7082. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  7083. value = +value
  7084. offset = offset | 0
  7085. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  7086. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7087. this[offset] = (value >>> 24)
  7088. this[offset + 1] = (value >>> 16)
  7089. this[offset + 2] = (value >>> 8)
  7090. this[offset + 3] = (value & 0xff)
  7091. } else {
  7092. objectWriteUInt32(this, value, offset, false)
  7093. }
  7094. return offset + 4
  7095. }
  7096. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  7097. value = +value
  7098. offset = offset | 0
  7099. if (!noAssert) {
  7100. var limit = Math.pow(2, 8 * byteLength - 1)
  7101. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  7102. }
  7103. var i = 0
  7104. var mul = 1
  7105. var sub = 0
  7106. this[offset] = value & 0xFF
  7107. while (++i < byteLength && (mul *= 0x100)) {
  7108. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  7109. sub = 1
  7110. }
  7111. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  7112. }
  7113. return offset + byteLength
  7114. }
  7115. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  7116. value = +value
  7117. offset = offset | 0
  7118. if (!noAssert) {
  7119. var limit = Math.pow(2, 8 * byteLength - 1)
  7120. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  7121. }
  7122. var i = byteLength - 1
  7123. var mul = 1
  7124. var sub = 0
  7125. this[offset + i] = value & 0xFF
  7126. while (--i >= 0 && (mul *= 0x100)) {
  7127. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  7128. sub = 1
  7129. }
  7130. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  7131. }
  7132. return offset + byteLength
  7133. }
  7134. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  7135. value = +value
  7136. offset = offset | 0
  7137. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  7138. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  7139. if (value < 0) value = 0xff + value + 1
  7140. this[offset] = (value & 0xff)
  7141. return offset + 1
  7142. }
  7143. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  7144. value = +value
  7145. offset = offset | 0
  7146. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  7147. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7148. this[offset] = (value & 0xff)
  7149. this[offset + 1] = (value >>> 8)
  7150. } else {
  7151. objectWriteUInt16(this, value, offset, true)
  7152. }
  7153. return offset + 2
  7154. }
  7155. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  7156. value = +value
  7157. offset = offset | 0
  7158. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  7159. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7160. this[offset] = (value >>> 8)
  7161. this[offset + 1] = (value & 0xff)
  7162. } else {
  7163. objectWriteUInt16(this, value, offset, false)
  7164. }
  7165. return offset + 2
  7166. }
  7167. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  7168. value = +value
  7169. offset = offset | 0
  7170. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  7171. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7172. this[offset] = (value & 0xff)
  7173. this[offset + 1] = (value >>> 8)
  7174. this[offset + 2] = (value >>> 16)
  7175. this[offset + 3] = (value >>> 24)
  7176. } else {
  7177. objectWriteUInt32(this, value, offset, true)
  7178. }
  7179. return offset + 4
  7180. }
  7181. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  7182. value = +value
  7183. offset = offset | 0
  7184. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  7185. if (value < 0) value = 0xffffffff + value + 1
  7186. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7187. this[offset] = (value >>> 24)
  7188. this[offset + 1] = (value >>> 16)
  7189. this[offset + 2] = (value >>> 8)
  7190. this[offset + 3] = (value & 0xff)
  7191. } else {
  7192. objectWriteUInt32(this, value, offset, false)
  7193. }
  7194. return offset + 4
  7195. }
  7196. function checkIEEE754 (buf, value, offset, ext, max, min) {
  7197. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  7198. if (offset < 0) throw new RangeError('Index out of range')
  7199. }
  7200. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  7201. if (!noAssert) {
  7202. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  7203. }
  7204. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  7205. return offset + 4
  7206. }
  7207. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  7208. return writeFloat(this, value, offset, true, noAssert)
  7209. }
  7210. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  7211. return writeFloat(this, value, offset, false, noAssert)
  7212. }
  7213. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  7214. if (!noAssert) {
  7215. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  7216. }
  7217. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  7218. return offset + 8
  7219. }
  7220. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  7221. return writeDouble(this, value, offset, true, noAssert)
  7222. }
  7223. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  7224. return writeDouble(this, value, offset, false, noAssert)
  7225. }
  7226. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  7227. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  7228. if (!start) start = 0
  7229. if (!end && end !== 0) end = this.length
  7230. if (targetStart >= target.length) targetStart = target.length
  7231. if (!targetStart) targetStart = 0
  7232. if (end > 0 && end < start) end = start
  7233. // Copy 0 bytes; we're done
  7234. if (end === start) return 0
  7235. if (target.length === 0 || this.length === 0) return 0
  7236. // Fatal error conditions
  7237. if (targetStart < 0) {
  7238. throw new RangeError('targetStart out of bounds')
  7239. }
  7240. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  7241. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  7242. // Are we oob?
  7243. if (end > this.length) end = this.length
  7244. if (target.length - targetStart < end - start) {
  7245. end = target.length - targetStart + start
  7246. }
  7247. var len = end - start
  7248. var i
  7249. if (this === target && start < targetStart && targetStart < end) {
  7250. // descending copy from end
  7251. for (i = len - 1; i >= 0; i--) {
  7252. target[i + targetStart] = this[i + start]
  7253. }
  7254. } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  7255. // ascending copy from start
  7256. for (i = 0; i < len; i++) {
  7257. target[i + targetStart] = this[i + start]
  7258. }
  7259. } else {
  7260. Uint8Array.prototype.set.call(
  7261. target,
  7262. this.subarray(start, start + len),
  7263. targetStart
  7264. )
  7265. }
  7266. return len
  7267. }
  7268. // Usage:
  7269. // buffer.fill(number[, offset[, end]])
  7270. // buffer.fill(buffer[, offset[, end]])
  7271. // buffer.fill(string[, offset[, end]][, encoding])
  7272. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  7273. // Handle string cases:
  7274. if (typeof val === 'string') {
  7275. if (typeof start === 'string') {
  7276. encoding = start
  7277. start = 0
  7278. end = this.length
  7279. } else if (typeof end === 'string') {
  7280. encoding = end
  7281. end = this.length
  7282. }
  7283. if (val.length === 1) {
  7284. var code = val.charCodeAt(0)
  7285. if (code < 256) {
  7286. val = code
  7287. }
  7288. }
  7289. if (encoding !== undefined && typeof encoding !== 'string') {
  7290. throw new TypeError('encoding must be a string')
  7291. }
  7292. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  7293. throw new TypeError('Unknown encoding: ' + encoding)
  7294. }
  7295. } else if (typeof val === 'number') {
  7296. val = val & 255
  7297. }
  7298. // Invalid ranges are not set to a default, so can range check early.
  7299. if (start < 0 || this.length < start || this.length < end) {
  7300. throw new RangeError('Out of range index')
  7301. }
  7302. if (end <= start) {
  7303. return this
  7304. }
  7305. start = start >>> 0
  7306. end = end === undefined ? this.length : end >>> 0
  7307. if (!val) val = 0
  7308. var i
  7309. if (typeof val === 'number') {
  7310. for (i = start; i < end; i++) {
  7311. this[i] = val
  7312. }
  7313. } else {
  7314. var bytes = Buffer.isBuffer(val)
  7315. ? val
  7316. : utf8ToBytes(new Buffer(val, encoding).toString())
  7317. var len = bytes.length
  7318. for (i = 0; i < end - start; i++) {
  7319. this[i + start] = bytes[i % len]
  7320. }
  7321. }
  7322. return this
  7323. }
  7324. // HELPER FUNCTIONS
  7325. // ================
  7326. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
  7327. function base64clean (str) {
  7328. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  7329. str = stringtrim(str).replace(INVALID_BASE64_RE, '')
  7330. // Node converts strings with length < 2 to ''
  7331. if (str.length < 2) return ''
  7332. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  7333. while (str.length % 4 !== 0) {
  7334. str = str + '='
  7335. }
  7336. return str
  7337. }
  7338. function stringtrim (str) {
  7339. if (str.trim) return str.trim()
  7340. return str.replace(/^\s+|\s+$/g, '')
  7341. }
  7342. function toHex (n) {
  7343. if (n < 16) return '0' + n.toString(16)
  7344. return n.toString(16)
  7345. }
  7346. function utf8ToBytes (string, units) {
  7347. units = units || Infinity
  7348. var codePoint
  7349. var length = string.length
  7350. var leadSurrogate = null
  7351. var bytes = []
  7352. for (var i = 0; i < length; i++) {
  7353. codePoint = string.charCodeAt(i)
  7354. // is surrogate component
  7355. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  7356. // last char was a lead
  7357. if (!leadSurrogate) {
  7358. // no lead yet
  7359. if (codePoint > 0xDBFF) {
  7360. // unexpected trail
  7361. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7362. continue
  7363. } else if (i + 1 === length) {
  7364. // unpaired lead
  7365. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7366. continue
  7367. }
  7368. // valid lead
  7369. leadSurrogate = codePoint
  7370. continue
  7371. }
  7372. // 2 leads in a row
  7373. if (codePoint < 0xDC00) {
  7374. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7375. leadSurrogate = codePoint
  7376. continue
  7377. }
  7378. // valid surrogate pair
  7379. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  7380. } else if (leadSurrogate) {
  7381. // valid bmp char, but last char was a lead
  7382. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7383. }
  7384. leadSurrogate = null
  7385. // encode utf8
  7386. if (codePoint < 0x80) {
  7387. if ((units -= 1) < 0) break
  7388. bytes.push(codePoint)
  7389. } else if (codePoint < 0x800) {
  7390. if ((units -= 2) < 0) break
  7391. bytes.push(
  7392. codePoint >> 0x6 | 0xC0,
  7393. codePoint & 0x3F | 0x80
  7394. )
  7395. } else if (codePoint < 0x10000) {
  7396. if ((units -= 3) < 0) break
  7397. bytes.push(
  7398. codePoint >> 0xC | 0xE0,
  7399. codePoint >> 0x6 & 0x3F | 0x80,
  7400. codePoint & 0x3F | 0x80
  7401. )
  7402. } else if (codePoint < 0x110000) {
  7403. if ((units -= 4) < 0) break
  7404. bytes.push(
  7405. codePoint >> 0x12 | 0xF0,
  7406. codePoint >> 0xC & 0x3F | 0x80,
  7407. codePoint >> 0x6 & 0x3F | 0x80,
  7408. codePoint & 0x3F | 0x80
  7409. )
  7410. } else {
  7411. throw new Error('Invalid code point')
  7412. }
  7413. }
  7414. return bytes
  7415. }
  7416. function asciiToBytes (str) {
  7417. var byteArray = []
  7418. for (var i = 0; i < str.length; i++) {
  7419. // Node's code seems to be doing this and not & 0x7F..
  7420. byteArray.push(str.charCodeAt(i) & 0xFF)
  7421. }
  7422. return byteArray
  7423. }
  7424. function utf16leToBytes (str, units) {
  7425. var c, hi, lo
  7426. var byteArray = []
  7427. for (var i = 0; i < str.length; i++) {
  7428. if ((units -= 2) < 0) break
  7429. c = str.charCodeAt(i)
  7430. hi = c >> 8
  7431. lo = c % 256
  7432. byteArray.push(lo)
  7433. byteArray.push(hi)
  7434. }
  7435. return byteArray
  7436. }
  7437. function base64ToBytes (str) {
  7438. return base64.toByteArray(base64clean(str))
  7439. }
  7440. function blitBuffer (src, dst, offset, length) {
  7441. for (var i = 0; i < length; i++) {
  7442. if ((i + offset >= dst.length) || (i >= src.length)) break
  7443. dst[i + offset] = src[i]
  7444. }
  7445. return i
  7446. }
  7447. function isnan (val) {
  7448. return val !== val // eslint-disable-line no-self-compare
  7449. }
  7450. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7451. },{"base64-js":40,"ieee754":52,"isarray":46}],46:[function(require,module,exports){
  7452. var toString = {}.toString;
  7453. module.exports = Array.isArray || function (arr) {
  7454. return toString.call(arr) == '[object Array]';
  7455. };
  7456. },{}],47:[function(require,module,exports){
  7457. (function (Buffer){
  7458. // Copyright Joyent, Inc. and other Node contributors.
  7459. //
  7460. // Permission is hereby granted, free of charge, to any person obtaining a
  7461. // copy of this software and associated documentation files (the
  7462. // "Software"), to deal in the Software without restriction, including
  7463. // without limitation the rights to use, copy, modify, merge, publish,
  7464. // distribute, sublicense, and/or sell copies of the Software, and to permit
  7465. // persons to whom the Software is furnished to do so, subject to the
  7466. // following conditions:
  7467. //
  7468. // The above copyright notice and this permission notice shall be included
  7469. // in all copies or substantial portions of the Software.
  7470. //
  7471. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  7472. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  7473. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  7474. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  7475. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  7476. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  7477. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  7478. // NOTE: These type checking functions intentionally don't use `instanceof`
  7479. // because it is fragile and can be easily faked with `Object.create()`.
  7480. function isArray(arg) {
  7481. if (Array.isArray) {
  7482. return Array.isArray(arg);
  7483. }
  7484. return objectToString(arg) === '[object Array]';
  7485. }
  7486. exports.isArray = isArray;
  7487. function isBoolean(arg) {
  7488. return typeof arg === 'boolean';
  7489. }
  7490. exports.isBoolean = isBoolean;
  7491. function isNull(arg) {
  7492. return arg === null;
  7493. }
  7494. exports.isNull = isNull;
  7495. function isNullOrUndefined(arg) {
  7496. return arg == null;
  7497. }
  7498. exports.isNullOrUndefined = isNullOrUndefined;
  7499. function isNumber(arg) {
  7500. return typeof arg === 'number';
  7501. }
  7502. exports.isNumber = isNumber;
  7503. function isString(arg) {
  7504. return typeof arg === 'string';
  7505. }
  7506. exports.isString = isString;
  7507. function isSymbol(arg) {
  7508. return typeof arg === 'symbol';
  7509. }
  7510. exports.isSymbol = isSymbol;
  7511. function isUndefined(arg) {
  7512. return arg === void 0;
  7513. }
  7514. exports.isUndefined = isUndefined;
  7515. function isRegExp(re) {
  7516. return objectToString(re) === '[object RegExp]';
  7517. }
  7518. exports.isRegExp = isRegExp;
  7519. function isObject(arg) {
  7520. return typeof arg === 'object' && arg !== null;
  7521. }
  7522. exports.isObject = isObject;
  7523. function isDate(d) {
  7524. return objectToString(d) === '[object Date]';
  7525. }
  7526. exports.isDate = isDate;
  7527. function isError(e) {
  7528. return (objectToString(e) === '[object Error]' || e instanceof Error);
  7529. }
  7530. exports.isError = isError;
  7531. function isFunction(arg) {
  7532. return typeof arg === 'function';
  7533. }
  7534. exports.isFunction = isFunction;
  7535. function isPrimitive(arg) {
  7536. return arg === null ||
  7537. typeof arg === 'boolean' ||
  7538. typeof arg === 'number' ||
  7539. typeof arg === 'string' ||
  7540. typeof arg === 'symbol' || // ES6 symbol
  7541. typeof arg === 'undefined';
  7542. }
  7543. exports.isPrimitive = isPrimitive;
  7544. exports.isBuffer = Buffer.isBuffer;
  7545. function objectToString(o) {
  7546. return Object.prototype.toString.call(o);
  7547. }
  7548. }).call(this,{"isBuffer":require("../../is-buffer/index.js")})
  7549. },{"../../is-buffer/index.js":54}],48:[function(require,module,exports){
  7550. /* See LICENSE file for terms of use */
  7551. /*
  7552. * Text diff implementation.
  7553. *
  7554. * This library supports the following APIS:
  7555. * JsDiff.diffChars: Character by character diff
  7556. * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace
  7557. * JsDiff.diffLines: Line based diff
  7558. *
  7559. * JsDiff.diffCss: Diff targeted at CSS content
  7560. *
  7561. * These methods are based on the implementation proposed in
  7562. * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).
  7563. * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927
  7564. */
  7565. (function(global, undefined) {
  7566. var objectPrototypeToString = Object.prototype.toString;
  7567. /*istanbul ignore next*/
  7568. function map(arr, mapper, that) {
  7569. if (Array.prototype.map) {
  7570. return Array.prototype.map.call(arr, mapper, that);
  7571. }
  7572. var other = new Array(arr.length);
  7573. for (var i = 0, n = arr.length; i < n; i++) {
  7574. other[i] = mapper.call(that, arr[i], i, arr);
  7575. }
  7576. return other;
  7577. }
  7578. function clonePath(path) {
  7579. return { newPos: path.newPos, components: path.components.slice(0) };
  7580. }
  7581. function removeEmpty(array) {
  7582. var ret = [];
  7583. for (var i = 0; i < array.length; i++) {
  7584. if (array[i]) {
  7585. ret.push(array[i]);
  7586. }
  7587. }
  7588. return ret;
  7589. }
  7590. function escapeHTML(s) {
  7591. var n = s;
  7592. n = n.replace(/&/g, '&amp;');
  7593. n = n.replace(/</g, '&lt;');
  7594. n = n.replace(/>/g, '&gt;');
  7595. n = n.replace(/"/g, '&quot;');
  7596. return n;
  7597. }
  7598. // This function handles the presence of circular references by bailing out when encountering an
  7599. // object that is already on the "stack" of items being processed.
  7600. function canonicalize(obj, stack, replacementStack) {
  7601. stack = stack || [];
  7602. replacementStack = replacementStack || [];
  7603. var i;
  7604. for (i = 0; i < stack.length; i += 1) {
  7605. if (stack[i] === obj) {
  7606. return replacementStack[i];
  7607. }
  7608. }
  7609. var canonicalizedObj;
  7610. if ('[object Array]' === objectPrototypeToString.call(obj)) {
  7611. stack.push(obj);
  7612. canonicalizedObj = new Array(obj.length);
  7613. replacementStack.push(canonicalizedObj);
  7614. for (i = 0; i < obj.length; i += 1) {
  7615. canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack);
  7616. }
  7617. stack.pop();
  7618. replacementStack.pop();
  7619. } else if (typeof obj === 'object' && obj !== null) {
  7620. stack.push(obj);
  7621. canonicalizedObj = {};
  7622. replacementStack.push(canonicalizedObj);
  7623. var sortedKeys = [],
  7624. key;
  7625. for (key in obj) {
  7626. sortedKeys.push(key);
  7627. }
  7628. sortedKeys.sort();
  7629. for (i = 0; i < sortedKeys.length; i += 1) {
  7630. key = sortedKeys[i];
  7631. canonicalizedObj[key] = canonicalize(obj[key], stack, replacementStack);
  7632. }
  7633. stack.pop();
  7634. replacementStack.pop();
  7635. } else {
  7636. canonicalizedObj = obj;
  7637. }
  7638. return canonicalizedObj;
  7639. }
  7640. function buildValues(components, newString, oldString, useLongestToken) {
  7641. var componentPos = 0,
  7642. componentLen = components.length,
  7643. newPos = 0,
  7644. oldPos = 0;
  7645. for (; componentPos < componentLen; componentPos++) {
  7646. var component = components[componentPos];
  7647. if (!component.removed) {
  7648. if (!component.added && useLongestToken) {
  7649. var value = newString.slice(newPos, newPos + component.count);
  7650. value = map(value, function(value, i) {
  7651. var oldValue = oldString[oldPos + i];
  7652. return oldValue.length > value.length ? oldValue : value;
  7653. });
  7654. component.value = value.join('');
  7655. } else {
  7656. component.value = newString.slice(newPos, newPos + component.count).join('');
  7657. }
  7658. newPos += component.count;
  7659. // Common case
  7660. if (!component.added) {
  7661. oldPos += component.count;
  7662. }
  7663. } else {
  7664. component.value = oldString.slice(oldPos, oldPos + component.count).join('');
  7665. oldPos += component.count;
  7666. // Reverse add and remove so removes are output first to match common convention
  7667. // The diffing algorithm is tied to add then remove output and this is the simplest
  7668. // route to get the desired output with minimal overhead.
  7669. if (componentPos && components[componentPos - 1].added) {
  7670. var tmp = components[componentPos - 1];
  7671. components[componentPos - 1] = components[componentPos];
  7672. components[componentPos] = tmp;
  7673. }
  7674. }
  7675. }
  7676. return components;
  7677. }
  7678. function Diff(ignoreWhitespace) {
  7679. this.ignoreWhitespace = ignoreWhitespace;
  7680. }
  7681. Diff.prototype = {
  7682. diff: function(oldString, newString, callback) {
  7683. var self = this;
  7684. function done(value) {
  7685. if (callback) {
  7686. setTimeout(function() { callback(undefined, value); }, 0);
  7687. return true;
  7688. } else {
  7689. return value;
  7690. }
  7691. }
  7692. // Handle the identity case (this is due to unrolling editLength == 0
  7693. if (newString === oldString) {
  7694. return done([{ value: newString }]);
  7695. }
  7696. if (!newString) {
  7697. return done([{ value: oldString, removed: true }]);
  7698. }
  7699. if (!oldString) {
  7700. return done([{ value: newString, added: true }]);
  7701. }
  7702. newString = this.tokenize(newString);
  7703. oldString = this.tokenize(oldString);
  7704. var newLen = newString.length, oldLen = oldString.length;
  7705. var editLength = 1;
  7706. var maxEditLength = newLen + oldLen;
  7707. var bestPath = [{ newPos: -1, components: [] }];
  7708. // Seed editLength = 0, i.e. the content starts with the same values
  7709. var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
  7710. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  7711. // Identity per the equality and tokenizer
  7712. return done([{value: newString.join('')}]);
  7713. }
  7714. // Main worker method. checks all permutations of a given edit length for acceptance.
  7715. function execEditLength() {
  7716. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  7717. var basePath;
  7718. var addPath = bestPath[diagonalPath - 1],
  7719. removePath = bestPath[diagonalPath + 1],
  7720. oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  7721. if (addPath) {
  7722. // No one else is going to attempt to use this value, clear it
  7723. bestPath[diagonalPath - 1] = undefined;
  7724. }
  7725. var canAdd = addPath && addPath.newPos + 1 < newLen,
  7726. canRemove = removePath && 0 <= oldPos && oldPos < oldLen;
  7727. if (!canAdd && !canRemove) {
  7728. // If this path is a terminal then prune
  7729. bestPath[diagonalPath] = undefined;
  7730. continue;
  7731. }
  7732. // Select the diagonal that we want to branch from. We select the prior
  7733. // path whose position in the new string is the farthest from the origin
  7734. // and does not pass the bounds of the diff graph
  7735. if (!canAdd || (canRemove && addPath.newPos < removePath.newPos)) {
  7736. basePath = clonePath(removePath);
  7737. self.pushComponent(basePath.components, undefined, true);
  7738. } else {
  7739. basePath = addPath; // No need to clone, we've pulled it from the list
  7740. basePath.newPos++;
  7741. self.pushComponent(basePath.components, true, undefined);
  7742. }
  7743. oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath);
  7744. // If we have hit the end of both strings, then we are done
  7745. if (basePath.newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  7746. return done(buildValues(basePath.components, newString, oldString, self.useLongestToken));
  7747. } else {
  7748. // Otherwise track this path as a potential candidate and continue.
  7749. bestPath[diagonalPath] = basePath;
  7750. }
  7751. }
  7752. editLength++;
  7753. }
  7754. // Performs the length of edit iteration. Is a bit fugly as this has to support the
  7755. // sync and async mode which is never fun. Loops over execEditLength until a value
  7756. // is produced.
  7757. if (callback) {
  7758. (function exec() {
  7759. setTimeout(function() {
  7760. // This should not happen, but we want to be safe.
  7761. /*istanbul ignore next */
  7762. if (editLength > maxEditLength) {
  7763. return callback();
  7764. }
  7765. if (!execEditLength()) {
  7766. exec();
  7767. }
  7768. }, 0);
  7769. }());
  7770. } else {
  7771. while (editLength <= maxEditLength) {
  7772. var ret = execEditLength();
  7773. if (ret) {
  7774. return ret;
  7775. }
  7776. }
  7777. }
  7778. },
  7779. pushComponent: function(components, added, removed) {
  7780. var last = components[components.length - 1];
  7781. if (last && last.added === added && last.removed === removed) {
  7782. // We need to clone here as the component clone operation is just
  7783. // as shallow array clone
  7784. components[components.length - 1] = {count: last.count + 1, added: added, removed: removed };
  7785. } else {
  7786. components.push({count: 1, added: added, removed: removed });
  7787. }
  7788. },
  7789. extractCommon: function(basePath, newString, oldString, diagonalPath) {
  7790. var newLen = newString.length,
  7791. oldLen = oldString.length,
  7792. newPos = basePath.newPos,
  7793. oldPos = newPos - diagonalPath,
  7794. commonCount = 0;
  7795. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
  7796. newPos++;
  7797. oldPos++;
  7798. commonCount++;
  7799. }
  7800. if (commonCount) {
  7801. basePath.components.push({count: commonCount});
  7802. }
  7803. basePath.newPos = newPos;
  7804. return oldPos;
  7805. },
  7806. equals: function(left, right) {
  7807. var reWhitespace = /\S/;
  7808. return left === right || (this.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right));
  7809. },
  7810. tokenize: function(value) {
  7811. return value.split('');
  7812. }
  7813. };
  7814. var CharDiff = new Diff();
  7815. var WordDiff = new Diff(true);
  7816. var WordWithSpaceDiff = new Diff();
  7817. WordDiff.tokenize = WordWithSpaceDiff.tokenize = function(value) {
  7818. return removeEmpty(value.split(/(\s+|\b)/));
  7819. };
  7820. var CssDiff = new Diff(true);
  7821. CssDiff.tokenize = function(value) {
  7822. return removeEmpty(value.split(/([{}:;,]|\s+)/));
  7823. };
  7824. var LineDiff = new Diff();
  7825. var TrimmedLineDiff = new Diff();
  7826. TrimmedLineDiff.ignoreTrim = true;
  7827. LineDiff.tokenize = TrimmedLineDiff.tokenize = function(value) {
  7828. var retLines = [],
  7829. lines = value.split(/^/m);
  7830. for (var i = 0; i < lines.length; i++) {
  7831. var line = lines[i],
  7832. lastLine = lines[i - 1],
  7833. lastLineLastChar = lastLine && lastLine[lastLine.length - 1];
  7834. // Merge lines that may contain windows new lines
  7835. if (line === '\n' && lastLineLastChar === '\r') {
  7836. retLines[retLines.length - 1] = retLines[retLines.length - 1].slice(0, -1) + '\r\n';
  7837. } else {
  7838. if (this.ignoreTrim) {
  7839. line = line.trim();
  7840. // add a newline unless this is the last line.
  7841. if (i < lines.length - 1) {
  7842. line += '\n';
  7843. }
  7844. }
  7845. retLines.push(line);
  7846. }
  7847. }
  7848. return retLines;
  7849. };
  7850. var PatchDiff = new Diff();
  7851. PatchDiff.tokenize = function(value) {
  7852. var ret = [],
  7853. linesAndNewlines = value.split(/(\n|\r\n)/);
  7854. // Ignore the final empty token that occurs if the string ends with a new line
  7855. if (!linesAndNewlines[linesAndNewlines.length - 1]) {
  7856. linesAndNewlines.pop();
  7857. }
  7858. // Merge the content and line separators into single tokens
  7859. for (var i = 0; i < linesAndNewlines.length; i++) {
  7860. var line = linesAndNewlines[i];
  7861. if (i % 2) {
  7862. ret[ret.length - 1] += line;
  7863. } else {
  7864. ret.push(line);
  7865. }
  7866. }
  7867. return ret;
  7868. };
  7869. var SentenceDiff = new Diff();
  7870. SentenceDiff.tokenize = function(value) {
  7871. return removeEmpty(value.split(/(\S.+?[.!?])(?=\s+|$)/));
  7872. };
  7873. var JsonDiff = new Diff();
  7874. // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
  7875. // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
  7876. JsonDiff.useLongestToken = true;
  7877. JsonDiff.tokenize = LineDiff.tokenize;
  7878. JsonDiff.equals = function(left, right) {
  7879. return LineDiff.equals(left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'));
  7880. };
  7881. var JsDiff = {
  7882. Diff: Diff,
  7883. diffChars: function(oldStr, newStr, callback) { return CharDiff.diff(oldStr, newStr, callback); },
  7884. diffWords: function(oldStr, newStr, callback) { return WordDiff.diff(oldStr, newStr, callback); },
  7885. diffWordsWithSpace: function(oldStr, newStr, callback) { return WordWithSpaceDiff.diff(oldStr, newStr, callback); },
  7886. diffLines: function(oldStr, newStr, callback) { return LineDiff.diff(oldStr, newStr, callback); },
  7887. diffTrimmedLines: function(oldStr, newStr, callback) { return TrimmedLineDiff.diff(oldStr, newStr, callback); },
  7888. diffSentences: function(oldStr, newStr, callback) { return SentenceDiff.diff(oldStr, newStr, callback); },
  7889. diffCss: function(oldStr, newStr, callback) { return CssDiff.diff(oldStr, newStr, callback); },
  7890. diffJson: function(oldObj, newObj, callback) {
  7891. return JsonDiff.diff(
  7892. typeof oldObj === 'string' ? oldObj : JSON.stringify(canonicalize(oldObj), undefined, ' '),
  7893. typeof newObj === 'string' ? newObj : JSON.stringify(canonicalize(newObj), undefined, ' '),
  7894. callback
  7895. );
  7896. },
  7897. createTwoFilesPatch: function(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader) {
  7898. var ret = [];
  7899. if (oldFileName == newFileName) {
  7900. ret.push('Index: ' + oldFileName);
  7901. }
  7902. ret.push('===================================================================');
  7903. ret.push('--- ' + oldFileName + (typeof oldHeader === 'undefined' ? '' : '\t' + oldHeader));
  7904. ret.push('+++ ' + newFileName + (typeof newHeader === 'undefined' ? '' : '\t' + newHeader));
  7905. var diff = PatchDiff.diff(oldStr, newStr);
  7906. diff.push({value: '', lines: []}); // Append an empty value to make cleanup easier
  7907. // Formats a given set of lines for printing as context lines in a patch
  7908. function contextLines(lines) {
  7909. return map(lines, function(entry) { return ' ' + entry; });
  7910. }
  7911. // Outputs the no newline at end of file warning if needed
  7912. function eofNL(curRange, i, current) {
  7913. var last = diff[diff.length - 2],
  7914. isLast = i === diff.length - 2,
  7915. isLastOfType = i === diff.length - 3 && current.added !== last.added;
  7916. // Figure out if this is the last line for the given file and missing NL
  7917. if (!(/\n$/.test(current.value)) && (isLast || isLastOfType)) {
  7918. curRange.push('\\ No newline at end of file');
  7919. }
  7920. }
  7921. var oldRangeStart = 0, newRangeStart = 0, curRange = [],
  7922. oldLine = 1, newLine = 1;
  7923. for (var i = 0; i < diff.length; i++) {
  7924. var current = diff[i],
  7925. lines = current.lines || current.value.replace(/\n$/, '').split('\n');
  7926. current.lines = lines;
  7927. if (current.added || current.removed) {
  7928. // If we have previous context, start with that
  7929. if (!oldRangeStart) {
  7930. var prev = diff[i - 1];
  7931. oldRangeStart = oldLine;
  7932. newRangeStart = newLine;
  7933. if (prev) {
  7934. curRange = contextLines(prev.lines.slice(-4));
  7935. oldRangeStart -= curRange.length;
  7936. newRangeStart -= curRange.length;
  7937. }
  7938. }
  7939. // Output our changes
  7940. curRange.push.apply(curRange, map(lines, function(entry) {
  7941. return (current.added ? '+' : '-') + entry;
  7942. }));
  7943. eofNL(curRange, i, current);
  7944. // Track the updated file position
  7945. if (current.added) {
  7946. newLine += lines.length;
  7947. } else {
  7948. oldLine += lines.length;
  7949. }
  7950. } else {
  7951. // Identical context lines. Track line changes
  7952. if (oldRangeStart) {
  7953. // Close out any changes that have been output (or join overlapping)
  7954. if (lines.length <= 8 && i < diff.length - 2) {
  7955. // Overlapping
  7956. curRange.push.apply(curRange, contextLines(lines));
  7957. } else {
  7958. // end the range and output
  7959. var contextSize = Math.min(lines.length, 4);
  7960. ret.push(
  7961. '@@ -' + oldRangeStart + ',' + (oldLine - oldRangeStart + contextSize)
  7962. + ' +' + newRangeStart + ',' + (newLine - newRangeStart + contextSize)
  7963. + ' @@');
  7964. ret.push.apply(ret, curRange);
  7965. ret.push.apply(ret, contextLines(lines.slice(0, contextSize)));
  7966. if (lines.length <= 4) {
  7967. eofNL(ret, i, current);
  7968. }
  7969. oldRangeStart = 0;
  7970. newRangeStart = 0;
  7971. curRange = [];
  7972. }
  7973. }
  7974. oldLine += lines.length;
  7975. newLine += lines.length;
  7976. }
  7977. }
  7978. return ret.join('\n') + '\n';
  7979. },
  7980. createPatch: function(fileName, oldStr, newStr, oldHeader, newHeader) {
  7981. return JsDiff.createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader);
  7982. },
  7983. applyPatch: function(oldStr, uniDiff) {
  7984. var diffstr = uniDiff.split('\n'),
  7985. hunks = [],
  7986. i = 0,
  7987. remEOFNL = false,
  7988. addEOFNL = false;
  7989. // Skip to the first change hunk
  7990. while (i < diffstr.length && !(/^@@/.test(diffstr[i]))) {
  7991. i++;
  7992. }
  7993. // Parse the unified diff
  7994. for (; i < diffstr.length; i++) {
  7995. if (diffstr[i][0] === '@') {
  7996. var chnukHeader = diffstr[i].split(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/);
  7997. hunks.unshift({
  7998. start: chnukHeader[3],
  7999. oldlength: +chnukHeader[2],
  8000. removed: [],
  8001. newlength: chnukHeader[4],
  8002. added: []
  8003. });
  8004. } else if (diffstr[i][0] === '+') {
  8005. hunks[0].added.push(diffstr[i].substr(1));
  8006. } else if (diffstr[i][0] === '-') {
  8007. hunks[0].removed.push(diffstr[i].substr(1));
  8008. } else if (diffstr[i][0] === ' ') {
  8009. hunks[0].added.push(diffstr[i].substr(1));
  8010. hunks[0].removed.push(diffstr[i].substr(1));
  8011. } else if (diffstr[i][0] === '\\') {
  8012. if (diffstr[i - 1][0] === '+') {
  8013. remEOFNL = true;
  8014. } else if (diffstr[i - 1][0] === '-') {
  8015. addEOFNL = true;
  8016. }
  8017. }
  8018. }
  8019. // Apply the diff to the input
  8020. var lines = oldStr.split('\n');
  8021. for (i = hunks.length - 1; i >= 0; i--) {
  8022. var hunk = hunks[i];
  8023. // Sanity check the input string. Bail if we don't match.
  8024. for (var j = 0; j < hunk.oldlength; j++) {
  8025. if (lines[hunk.start - 1 + j] !== hunk.removed[j]) {
  8026. return false;
  8027. }
  8028. }
  8029. Array.prototype.splice.apply(lines, [hunk.start - 1, hunk.oldlength].concat(hunk.added));
  8030. }
  8031. // Handle EOFNL insertion/removal
  8032. if (remEOFNL) {
  8033. while (!lines[lines.length - 1]) {
  8034. lines.pop();
  8035. }
  8036. } else if (addEOFNL) {
  8037. lines.push('');
  8038. }
  8039. return lines.join('\n');
  8040. },
  8041. convertChangesToXML: function(changes) {
  8042. var ret = [];
  8043. for (var i = 0; i < changes.length; i++) {
  8044. var change = changes[i];
  8045. if (change.added) {
  8046. ret.push('<ins>');
  8047. } else if (change.removed) {
  8048. ret.push('<del>');
  8049. }
  8050. ret.push(escapeHTML(change.value));
  8051. if (change.added) {
  8052. ret.push('</ins>');
  8053. } else if (change.removed) {
  8054. ret.push('</del>');
  8055. }
  8056. }
  8057. return ret.join('');
  8058. },
  8059. // See: http://code.google.com/p/google-diff-match-patch/wiki/API
  8060. convertChangesToDMP: function(changes) {
  8061. var ret = [],
  8062. change,
  8063. operation;
  8064. for (var i = 0; i < changes.length; i++) {
  8065. change = changes[i];
  8066. if (change.added) {
  8067. operation = 1;
  8068. } else if (change.removed) {
  8069. operation = -1;
  8070. } else {
  8071. operation = 0;
  8072. }
  8073. ret.push([operation, change.value]);
  8074. }
  8075. return ret;
  8076. },
  8077. canonicalize: canonicalize
  8078. };
  8079. /*istanbul ignore next */
  8080. /*global module */
  8081. if (typeof module !== 'undefined' && module.exports) {
  8082. module.exports = JsDiff;
  8083. } else if (typeof define === 'function' && define.amd) {
  8084. /*global define */
  8085. define([], function() { return JsDiff; });
  8086. } else if (typeof global.JsDiff === 'undefined') {
  8087. global.JsDiff = JsDiff;
  8088. }
  8089. }(this));
  8090. },{}],49:[function(require,module,exports){
  8091. 'use strict';
  8092. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  8093. module.exports = function (str) {
  8094. if (typeof str !== 'string') {
  8095. throw new TypeError('Expected a string');
  8096. }
  8097. return str.replace(matchOperatorsRe, '\\$&');
  8098. };
  8099. },{}],50:[function(require,module,exports){
  8100. // Copyright Joyent, Inc. and other Node contributors.
  8101. //
  8102. // Permission is hereby granted, free of charge, to any person obtaining a
  8103. // copy of this software and associated documentation files (the
  8104. // "Software"), to deal in the Software without restriction, including
  8105. // without limitation the rights to use, copy, modify, merge, publish,
  8106. // distribute, sublicense, and/or sell copies of the Software, and to permit
  8107. // persons to whom the Software is furnished to do so, subject to the
  8108. // following conditions:
  8109. //
  8110. // The above copyright notice and this permission notice shall be included
  8111. // in all copies or substantial portions of the Software.
  8112. //
  8113. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  8114. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  8115. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  8116. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  8117. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  8118. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  8119. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  8120. function EventEmitter() {
  8121. this._events = this._events || {};
  8122. this._maxListeners = this._maxListeners || undefined;
  8123. }
  8124. module.exports = EventEmitter;
  8125. // Backwards-compat with node 0.10.x
  8126. EventEmitter.EventEmitter = EventEmitter;
  8127. EventEmitter.prototype._events = undefined;
  8128. EventEmitter.prototype._maxListeners = undefined;
  8129. // By default EventEmitters will print a warning if more than 10 listeners are
  8130. // added to it. This is a useful default which helps finding memory leaks.
  8131. EventEmitter.defaultMaxListeners = 10;
  8132. // Obviously not all Emitters should be limited to 10. This function allows
  8133. // that to be increased. Set to zero for unlimited.
  8134. EventEmitter.prototype.setMaxListeners = function(n) {
  8135. if (!isNumber(n) || n < 0 || isNaN(n))
  8136. throw TypeError('n must be a positive number');
  8137. this._maxListeners = n;
  8138. return this;
  8139. };
  8140. EventEmitter.prototype.emit = function(type) {
  8141. var er, handler, len, args, i, listeners;
  8142. if (!this._events)
  8143. this._events = {};
  8144. // If there is no 'error' event listener then throw.
  8145. if (type === 'error') {
  8146. if (!this._events.error ||
  8147. (isObject(this._events.error) && !this._events.error.length)) {
  8148. er = arguments[1];
  8149. if (er instanceof Error) {
  8150. throw er; // Unhandled 'error' event
  8151. }
  8152. throw TypeError('Uncaught, unspecified "error" event.');
  8153. }
  8154. }
  8155. handler = this._events[type];
  8156. if (isUndefined(handler))
  8157. return false;
  8158. if (isFunction(handler)) {
  8159. switch (arguments.length) {
  8160. // fast cases
  8161. case 1:
  8162. handler.call(this);
  8163. break;
  8164. case 2:
  8165. handler.call(this, arguments[1]);
  8166. break;
  8167. case 3:
  8168. handler.call(this, arguments[1], arguments[2]);
  8169. break;
  8170. // slower
  8171. default:
  8172. args = Array.prototype.slice.call(arguments, 1);
  8173. handler.apply(this, args);
  8174. }
  8175. } else if (isObject(handler)) {
  8176. args = Array.prototype.slice.call(arguments, 1);
  8177. listeners = handler.slice();
  8178. len = listeners.length;
  8179. for (i = 0; i < len; i++)
  8180. listeners[i].apply(this, args);
  8181. }
  8182. return true;
  8183. };
  8184. EventEmitter.prototype.addListener = function(type, listener) {
  8185. var m;
  8186. if (!isFunction(listener))
  8187. throw TypeError('listener must be a function');
  8188. if (!this._events)
  8189. this._events = {};
  8190. // To avoid recursion in the case that type === "newListener"! Before
  8191. // adding it to the listeners, first emit "newListener".
  8192. if (this._events.newListener)
  8193. this.emit('newListener', type,
  8194. isFunction(listener.listener) ?
  8195. listener.listener : listener);
  8196. if (!this._events[type])
  8197. // Optimize the case of one listener. Don't need the extra array object.
  8198. this._events[type] = listener;
  8199. else if (isObject(this._events[type]))
  8200. // If we've already got an array, just append.
  8201. this._events[type].push(listener);
  8202. else
  8203. // Adding the second element, need to change to array.
  8204. this._events[type] = [this._events[type], listener];
  8205. // Check for listener leak
  8206. if (isObject(this._events[type]) && !this._events[type].warned) {
  8207. if (!isUndefined(this._maxListeners)) {
  8208. m = this._maxListeners;
  8209. } else {
  8210. m = EventEmitter.defaultMaxListeners;
  8211. }
  8212. if (m && m > 0 && this._events[type].length > m) {
  8213. this._events[type].warned = true;
  8214. console.error('(node) warning: possible EventEmitter memory ' +
  8215. 'leak detected. %d listeners added. ' +
  8216. 'Use emitter.setMaxListeners() to increase limit.',
  8217. this._events[type].length);
  8218. if (typeof console.trace === 'function') {
  8219. // not supported in IE 10
  8220. console.trace();
  8221. }
  8222. }
  8223. }
  8224. return this;
  8225. };
  8226. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  8227. EventEmitter.prototype.once = function(type, listener) {
  8228. if (!isFunction(listener))
  8229. throw TypeError('listener must be a function');
  8230. var fired = false;
  8231. function g() {
  8232. this.removeListener(type, g);
  8233. if (!fired) {
  8234. fired = true;
  8235. listener.apply(this, arguments);
  8236. }
  8237. }
  8238. g.listener = listener;
  8239. this.on(type, g);
  8240. return this;
  8241. };
  8242. // emits a 'removeListener' event iff the listener was removed
  8243. EventEmitter.prototype.removeListener = function(type, listener) {
  8244. var list, position, length, i;
  8245. if (!isFunction(listener))
  8246. throw TypeError('listener must be a function');
  8247. if (!this._events || !this._events[type])
  8248. return this;
  8249. list = this._events[type];
  8250. length = list.length;
  8251. position = -1;
  8252. if (list === listener ||
  8253. (isFunction(list.listener) && list.listener === listener)) {
  8254. delete this._events[type];
  8255. if (this._events.removeListener)
  8256. this.emit('removeListener', type, listener);
  8257. } else if (isObject(list)) {
  8258. for (i = length; i-- > 0;) {
  8259. if (list[i] === listener ||
  8260. (list[i].listener && list[i].listener === listener)) {
  8261. position = i;
  8262. break;
  8263. }
  8264. }
  8265. if (position < 0)
  8266. return this;
  8267. if (list.length === 1) {
  8268. list.length = 0;
  8269. delete this._events[type];
  8270. } else {
  8271. list.splice(position, 1);
  8272. }
  8273. if (this._events.removeListener)
  8274. this.emit('removeListener', type, listener);
  8275. }
  8276. return this;
  8277. };
  8278. EventEmitter.prototype.removeAllListeners = function(type) {
  8279. var key, listeners;
  8280. if (!this._events)
  8281. return this;
  8282. // not listening for removeListener, no need to emit
  8283. if (!this._events.removeListener) {
  8284. if (arguments.length === 0)
  8285. this._events = {};
  8286. else if (this._events[type])
  8287. delete this._events[type];
  8288. return this;
  8289. }
  8290. // emit removeListener for all listeners on all events
  8291. if (arguments.length === 0) {
  8292. for (key in this._events) {
  8293. if (key === 'removeListener') continue;
  8294. this.removeAllListeners(key);
  8295. }
  8296. this.removeAllListeners('removeListener');
  8297. this._events = {};
  8298. return this;
  8299. }
  8300. listeners = this._events[type];
  8301. if (isFunction(listeners)) {
  8302. this.removeListener(type, listeners);
  8303. } else if (listeners) {
  8304. // LIFO order
  8305. while (listeners.length)
  8306. this.removeListener(type, listeners[listeners.length - 1]);
  8307. }
  8308. delete this._events[type];
  8309. return this;
  8310. };
  8311. EventEmitter.prototype.listeners = function(type) {
  8312. var ret;
  8313. if (!this._events || !this._events[type])
  8314. ret = [];
  8315. else if (isFunction(this._events[type]))
  8316. ret = [this._events[type]];
  8317. else
  8318. ret = this._events[type].slice();
  8319. return ret;
  8320. };
  8321. EventEmitter.prototype.listenerCount = function(type) {
  8322. if (this._events) {
  8323. var evlistener = this._events[type];
  8324. if (isFunction(evlistener))
  8325. return 1;
  8326. else if (evlistener)
  8327. return evlistener.length;
  8328. }
  8329. return 0;
  8330. };
  8331. EventEmitter.listenerCount = function(emitter, type) {
  8332. return emitter.listenerCount(type);
  8333. };
  8334. function isFunction(arg) {
  8335. return typeof arg === 'function';
  8336. }
  8337. function isNumber(arg) {
  8338. return typeof arg === 'number';
  8339. }
  8340. function isObject(arg) {
  8341. return typeof arg === 'object' && arg !== null;
  8342. }
  8343. function isUndefined(arg) {
  8344. return arg === void 0;
  8345. }
  8346. },{}],51:[function(require,module,exports){
  8347. (function (process){
  8348. // Growl - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
  8349. /**
  8350. * Module dependencies.
  8351. */
  8352. var exec = require('child_process').exec
  8353. , fs = require('fs')
  8354. , path = require('path')
  8355. , exists = fs.existsSync || path.existsSync
  8356. , os = require('os')
  8357. , quote = JSON.stringify
  8358. , cmd;
  8359. function which(name) {
  8360. var paths = process.env.PATH.split(':');
  8361. var loc;
  8362. for (var i = 0, len = paths.length; i < len; ++i) {
  8363. loc = path.join(paths[i], name);
  8364. if (exists(loc)) return loc;
  8365. }
  8366. }
  8367. switch(os.type()) {
  8368. case 'Darwin':
  8369. if (which('terminal-notifier')) {
  8370. cmd = {
  8371. type: "Darwin-NotificationCenter"
  8372. , pkg: "terminal-notifier"
  8373. , msg: '-message'
  8374. , title: '-title'
  8375. , subtitle: '-subtitle'
  8376. , icon: '-appIcon'
  8377. , sound: '-sound'
  8378. , url: '-open'
  8379. , priority: {
  8380. cmd: '-execute'
  8381. , range: []
  8382. }
  8383. };
  8384. } else {
  8385. cmd = {
  8386. type: "Darwin-Growl"
  8387. , pkg: "growlnotify"
  8388. , msg: '-m'
  8389. , sticky: '--sticky'
  8390. , priority: {
  8391. cmd: '--priority'
  8392. , range: [
  8393. -2
  8394. , -1
  8395. , 0
  8396. , 1
  8397. , 2
  8398. , "Very Low"
  8399. , "Moderate"
  8400. , "Normal"
  8401. , "High"
  8402. , "Emergency"
  8403. ]
  8404. }
  8405. };
  8406. }
  8407. break;
  8408. case 'Linux':
  8409. if (which('growl')) {
  8410. cmd = {
  8411. type: "Linux-Growl"
  8412. , pkg: "growl"
  8413. , msg: '-m'
  8414. , title: '-title'
  8415. , subtitle: '-subtitle'
  8416. , host: {
  8417. cmd: '-H'
  8418. , hostname: '192.168.33.1'
  8419. }
  8420. };
  8421. } else {
  8422. cmd = {
  8423. type: "Linux"
  8424. , pkg: "notify-send"
  8425. , msg: ''
  8426. , sticky: '-t 0'
  8427. , icon: '-i'
  8428. , priority: {
  8429. cmd: '-u'
  8430. , range: [
  8431. "low"
  8432. , "normal"
  8433. , "critical"
  8434. ]
  8435. }
  8436. };
  8437. }
  8438. break;
  8439. case 'Windows_NT':
  8440. cmd = {
  8441. type: "Windows"
  8442. , pkg: "growlnotify"
  8443. , msg: ''
  8444. , sticky: '/s:true'
  8445. , title: '/t:'
  8446. , icon: '/i:'
  8447. , url: '/cu:'
  8448. , priority: {
  8449. cmd: '/p:'
  8450. , range: [
  8451. -2
  8452. , -1
  8453. , 0
  8454. , 1
  8455. , 2
  8456. ]
  8457. }
  8458. };
  8459. break;
  8460. }
  8461. /**
  8462. * Expose `growl`.
  8463. */
  8464. exports = module.exports = growl;
  8465. /**
  8466. * Node-growl version.
  8467. */
  8468. exports.version = '1.4.1'
  8469. /**
  8470. * Send growl notification _msg_ with _options_.
  8471. *
  8472. * Options:
  8473. *
  8474. * - title Notification title
  8475. * - sticky Make the notification stick (defaults to false)
  8476. * - priority Specify an int or named key (default is 0)
  8477. * - name Application name (defaults to growlnotify)
  8478. * - sound Sound efect ( in OSx defined in preferences -> sound -> effects) * works only in OSX > 10.8x
  8479. * - image
  8480. * - path to an icon sets --iconpath
  8481. * - path to an image sets --image
  8482. * - capitalized word sets --appIcon
  8483. * - filename uses extname as --icon
  8484. * - otherwise treated as --icon
  8485. *
  8486. * Examples:
  8487. *
  8488. * growl('New email')
  8489. * growl('5 new emails', { title: 'Thunderbird' })
  8490. * growl('5 new emails', { title: 'Thunderbird', sound: 'Purr' })
  8491. * growl('Email sent', function(){
  8492. * // ... notification sent
  8493. * })
  8494. *
  8495. * @param {string} msg
  8496. * @param {object} options
  8497. * @param {function} fn
  8498. * @api public
  8499. */
  8500. function growl(msg, options, fn) {
  8501. var image
  8502. , args
  8503. , options = options || {}
  8504. , fn = fn || function(){};
  8505. if (options.exec) {
  8506. cmd = {
  8507. type: "Custom"
  8508. , pkg: options.exec
  8509. , range: []
  8510. };
  8511. }
  8512. // noop
  8513. if (!cmd) return fn(new Error('growl not supported on this platform'));
  8514. args = [cmd.pkg];
  8515. // image
  8516. if (image = options.image) {
  8517. switch(cmd.type) {
  8518. case 'Darwin-Growl':
  8519. var flag, ext = path.extname(image).substr(1)
  8520. flag = flag || ext == 'icns' && 'iconpath'
  8521. flag = flag || /^[A-Z]/.test(image) && 'appIcon'
  8522. flag = flag || /^png|gif|jpe?g$/.test(ext) && 'image'
  8523. flag = flag || ext && (image = ext) && 'icon'
  8524. flag = flag || 'icon'
  8525. args.push('--' + flag, quote(image))
  8526. break;
  8527. case 'Darwin-NotificationCenter':
  8528. args.push(cmd.icon, quote(image));
  8529. break;
  8530. case 'Linux':
  8531. args.push(cmd.icon, quote(image));
  8532. // libnotify defaults to sticky, set a hint for transient notifications
  8533. if (!options.sticky) args.push('--hint=int:transient:1');
  8534. break;
  8535. case 'Windows':
  8536. args.push(cmd.icon + quote(image));
  8537. break;
  8538. }
  8539. }
  8540. // sticky
  8541. if (options.sticky) args.push(cmd.sticky);
  8542. // priority
  8543. if (options.priority) {
  8544. var priority = options.priority + '';
  8545. var checkindexOf = cmd.priority.range.indexOf(priority);
  8546. if (~cmd.priority.range.indexOf(priority)) {
  8547. args.push(cmd.priority, options.priority);
  8548. }
  8549. }
  8550. //sound
  8551. if(options.sound && cmd.type === 'Darwin-NotificationCenter'){
  8552. args.push(cmd.sound, options.sound)
  8553. }
  8554. // name
  8555. if (options.name && cmd.type === "Darwin-Growl") {
  8556. args.push('--name', options.name);
  8557. }
  8558. switch(cmd.type) {
  8559. case 'Darwin-Growl':
  8560. args.push(cmd.msg);
  8561. args.push(quote(msg).replace(/\\n/g, '\n'));
  8562. if (options.title) args.push(quote(options.title));
  8563. break;
  8564. case 'Darwin-NotificationCenter':
  8565. args.push(cmd.msg);
  8566. var stringifiedMsg = quote(msg);
  8567. var escapedMsg = stringifiedMsg.replace(/\\n/g, '\n');
  8568. args.push(escapedMsg);
  8569. if (options.title) {
  8570. args.push(cmd.title);
  8571. args.push(quote(options.title));
  8572. }
  8573. if (options.subtitle) {
  8574. args.push(cmd.subtitle);
  8575. args.push(quote(options.subtitle));
  8576. }
  8577. if (options.url) {
  8578. args.push(cmd.url);
  8579. args.push(quote(options.url));
  8580. }
  8581. break;
  8582. case 'Linux-Growl':
  8583. args.push(cmd.msg);
  8584. args.push(quote(msg).replace(/\\n/g, '\n'));
  8585. if (options.title) args.push(quote(options.title));
  8586. if (cmd.host) {
  8587. args.push(cmd.host.cmd, cmd.host.hostname)
  8588. }
  8589. break;
  8590. case 'Linux':
  8591. if (options.title) {
  8592. args.push(quote(options.title));
  8593. args.push(cmd.msg);
  8594. args.push(quote(msg).replace(/\\n/g, '\n'));
  8595. } else {
  8596. args.push(quote(msg).replace(/\\n/g, '\n'));
  8597. }
  8598. break;
  8599. case 'Windows':
  8600. args.push(quote(msg).replace(/\\n/g, '\n'));
  8601. if (options.title) args.push(cmd.title + quote(options.title));
  8602. if (options.url) args.push(cmd.url + quote(options.url));
  8603. break;
  8604. case 'Custom':
  8605. args[0] = (function(origCommand) {
  8606. var message = options.title
  8607. ? options.title + ': ' + msg
  8608. : msg;
  8609. var command = origCommand.replace(/(^|[^%])%s/g, '$1' + quote(message));
  8610. if (command === origCommand) args.push(quote(message));
  8611. return command;
  8612. })(args[0]);
  8613. break;
  8614. }
  8615. // execute
  8616. exec(args.join(' '), fn);
  8617. };
  8618. }).call(this,require('_process'))
  8619. },{"_process":58,"child_process":43,"fs":43,"os":56,"path":43}],52:[function(require,module,exports){
  8620. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  8621. var e, m
  8622. var eLen = nBytes * 8 - mLen - 1
  8623. var eMax = (1 << eLen) - 1
  8624. var eBias = eMax >> 1
  8625. var nBits = -7
  8626. var i = isLE ? (nBytes - 1) : 0
  8627. var d = isLE ? -1 : 1
  8628. var s = buffer[offset + i]
  8629. i += d
  8630. e = s & ((1 << (-nBits)) - 1)
  8631. s >>= (-nBits)
  8632. nBits += eLen
  8633. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  8634. m = e & ((1 << (-nBits)) - 1)
  8635. e >>= (-nBits)
  8636. nBits += mLen
  8637. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  8638. if (e === 0) {
  8639. e = 1 - eBias
  8640. } else if (e === eMax) {
  8641. return m ? NaN : ((s ? -1 : 1) * Infinity)
  8642. } else {
  8643. m = m + Math.pow(2, mLen)
  8644. e = e - eBias
  8645. }
  8646. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  8647. }
  8648. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  8649. var e, m, c
  8650. var eLen = nBytes * 8 - mLen - 1
  8651. var eMax = (1 << eLen) - 1
  8652. var eBias = eMax >> 1
  8653. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  8654. var i = isLE ? 0 : (nBytes - 1)
  8655. var d = isLE ? 1 : -1
  8656. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  8657. value = Math.abs(value)
  8658. if (isNaN(value) || value === Infinity) {
  8659. m = isNaN(value) ? 1 : 0
  8660. e = eMax
  8661. } else {
  8662. e = Math.floor(Math.log(value) / Math.LN2)
  8663. if (value * (c = Math.pow(2, -e)) < 1) {
  8664. e--
  8665. c *= 2
  8666. }
  8667. if (e + eBias >= 1) {
  8668. value += rt / c
  8669. } else {
  8670. value += rt * Math.pow(2, 1 - eBias)
  8671. }
  8672. if (value * c >= 2) {
  8673. e++
  8674. c /= 2
  8675. }
  8676. if (e + eBias >= eMax) {
  8677. m = 0
  8678. e = eMax
  8679. } else if (e + eBias >= 1) {
  8680. m = (value * c - 1) * Math.pow(2, mLen)
  8681. e = e + eBias
  8682. } else {
  8683. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  8684. e = 0
  8685. }
  8686. }
  8687. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  8688. e = (e << mLen) | m
  8689. eLen += mLen
  8690. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  8691. buffer[offset + i - d] |= s * 128
  8692. }
  8693. },{}],53:[function(require,module,exports){
  8694. if (typeof Object.create === 'function') {
  8695. // implementation from standard node.js 'util' module
  8696. module.exports = function inherits(ctor, superCtor) {
  8697. ctor.super_ = superCtor
  8698. ctor.prototype = Object.create(superCtor.prototype, {
  8699. constructor: {
  8700. value: ctor,
  8701. enumerable: false,
  8702. writable: true,
  8703. configurable: true
  8704. }
  8705. });
  8706. };
  8707. } else {
  8708. // old school shim for old browsers
  8709. module.exports = function inherits(ctor, superCtor) {
  8710. ctor.super_ = superCtor
  8711. var TempCtor = function () {}
  8712. TempCtor.prototype = superCtor.prototype
  8713. ctor.prototype = new TempCtor()
  8714. ctor.prototype.constructor = ctor
  8715. }
  8716. }
  8717. },{}],54:[function(require,module,exports){
  8718. /**
  8719. * Determine if an object is Buffer
  8720. *
  8721. * Author: Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  8722. * License: MIT
  8723. *
  8724. * `npm install is-buffer`
  8725. */
  8726. module.exports = function (obj) {
  8727. return !!(obj != null &&
  8728. (obj._isBuffer || // For Safari 5-7 (missing Object.prototype.constructor)
  8729. (obj.constructor &&
  8730. typeof obj.constructor.isBuffer === 'function' &&
  8731. obj.constructor.isBuffer(obj))
  8732. ))
  8733. }
  8734. },{}],55:[function(require,module,exports){
  8735. (function (process){
  8736. var path = require('path');
  8737. var fs = require('fs');
  8738. var _0777 = parseInt('0777', 8);
  8739. module.exports = mkdirP.mkdirp = mkdirP.mkdirP = mkdirP;
  8740. function mkdirP (p, opts, f, made) {
  8741. if (typeof opts === 'function') {
  8742. f = opts;
  8743. opts = {};
  8744. }
  8745. else if (!opts || typeof opts !== 'object') {
  8746. opts = { mode: opts };
  8747. }
  8748. var mode = opts.mode;
  8749. var xfs = opts.fs || fs;
  8750. if (mode === undefined) {
  8751. mode = _0777 & (~process.umask());
  8752. }
  8753. if (!made) made = null;
  8754. var cb = f || function () {};
  8755. p = path.resolve(p);
  8756. xfs.mkdir(p, mode, function (er) {
  8757. if (!er) {
  8758. made = made || p;
  8759. return cb(null, made);
  8760. }
  8761. switch (er.code) {
  8762. case 'ENOENT':
  8763. mkdirP(path.dirname(p), opts, function (er, made) {
  8764. if (er) cb(er, made);
  8765. else mkdirP(p, opts, cb, made);
  8766. });
  8767. break;
  8768. // In the case of any other error, just see if there's a dir
  8769. // there already. If so, then hooray! If not, then something
  8770. // is borked.
  8771. default:
  8772. xfs.stat(p, function (er2, stat) {
  8773. // if the stat fails, then that's super weird.
  8774. // let the original error be the failure reason.
  8775. if (er2 || !stat.isDirectory()) cb(er, made)
  8776. else cb(null, made);
  8777. });
  8778. break;
  8779. }
  8780. });
  8781. }
  8782. mkdirP.sync = function sync (p, opts, made) {
  8783. if (!opts || typeof opts !== 'object') {
  8784. opts = { mode: opts };
  8785. }
  8786. var mode = opts.mode;
  8787. var xfs = opts.fs || fs;
  8788. if (mode === undefined) {
  8789. mode = _0777 & (~process.umask());
  8790. }
  8791. if (!made) made = null;
  8792. p = path.resolve(p);
  8793. try {
  8794. xfs.mkdirSync(p, mode);
  8795. made = made || p;
  8796. }
  8797. catch (err0) {
  8798. switch (err0.code) {
  8799. case 'ENOENT' :
  8800. made = sync(path.dirname(p), opts, made);
  8801. sync(p, opts, made);
  8802. break;
  8803. // In the case of any other error, just see if there's a dir
  8804. // there already. If so, then hooray! If not, then something
  8805. // is borked.
  8806. default:
  8807. var stat;
  8808. try {
  8809. stat = xfs.statSync(p);
  8810. }
  8811. catch (err1) {
  8812. throw err0;
  8813. }
  8814. if (!stat.isDirectory()) throw err0;
  8815. break;
  8816. }
  8817. }
  8818. return made;
  8819. };
  8820. }).call(this,require('_process'))
  8821. },{"_process":58,"fs":43,"path":43}],56:[function(require,module,exports){
  8822. exports.endianness = function () { return 'LE' };
  8823. exports.hostname = function () {
  8824. if (typeof location !== 'undefined') {
  8825. return location.hostname
  8826. }
  8827. else return '';
  8828. };
  8829. exports.loadavg = function () { return [] };
  8830. exports.uptime = function () { return 0 };
  8831. exports.freemem = function () {
  8832. return Number.MAX_VALUE;
  8833. };
  8834. exports.totalmem = function () {
  8835. return Number.MAX_VALUE;
  8836. };
  8837. exports.cpus = function () { return [] };
  8838. exports.type = function () { return 'Browser' };
  8839. exports.release = function () {
  8840. if (typeof navigator !== 'undefined') {
  8841. return navigator.appVersion;
  8842. }
  8843. return '';
  8844. };
  8845. exports.networkInterfaces
  8846. = exports.getNetworkInterfaces
  8847. = function () { return {} };
  8848. exports.arch = function () { return 'javascript' };
  8849. exports.platform = function () { return 'browser' };
  8850. exports.tmpdir = exports.tmpDir = function () {
  8851. return '/tmp';
  8852. };
  8853. exports.EOL = '\n';
  8854. },{}],57:[function(require,module,exports){
  8855. (function (process){
  8856. 'use strict';
  8857. if (!process.version ||
  8858. process.version.indexOf('v0.') === 0 ||
  8859. process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
  8860. module.exports = nextTick;
  8861. } else {
  8862. module.exports = process.nextTick;
  8863. }
  8864. function nextTick(fn, arg1, arg2, arg3) {
  8865. if (typeof fn !== 'function') {
  8866. throw new TypeError('"callback" argument must be a function');
  8867. }
  8868. var len = arguments.length;
  8869. var args, i;
  8870. switch (len) {
  8871. case 0:
  8872. case 1:
  8873. return process.nextTick(fn);
  8874. case 2:
  8875. return process.nextTick(function afterTickOne() {
  8876. fn.call(null, arg1);
  8877. });
  8878. case 3:
  8879. return process.nextTick(function afterTickTwo() {
  8880. fn.call(null, arg1, arg2);
  8881. });
  8882. case 4:
  8883. return process.nextTick(function afterTickThree() {
  8884. fn.call(null, arg1, arg2, arg3);
  8885. });
  8886. default:
  8887. args = new Array(len - 1);
  8888. i = 0;
  8889. while (i < args.length) {
  8890. args[i++] = arguments[i];
  8891. }
  8892. return process.nextTick(function afterTick() {
  8893. fn.apply(null, args);
  8894. });
  8895. }
  8896. }
  8897. }).call(this,require('_process'))
  8898. },{"_process":58}],58:[function(require,module,exports){
  8899. // shim for using process in browser
  8900. var process = module.exports = {};
  8901. var queue = [];
  8902. var draining = false;
  8903. var currentQueue;
  8904. var queueIndex = -1;
  8905. function cleanUpNextTick() {
  8906. if (!draining || !currentQueue) {
  8907. return;
  8908. }
  8909. draining = false;
  8910. if (currentQueue.length) {
  8911. queue = currentQueue.concat(queue);
  8912. } else {
  8913. queueIndex = -1;
  8914. }
  8915. if (queue.length) {
  8916. drainQueue();
  8917. }
  8918. }
  8919. function drainQueue() {
  8920. if (draining) {
  8921. return;
  8922. }
  8923. var timeout = setTimeout(cleanUpNextTick);
  8924. draining = true;
  8925. var len = queue.length;
  8926. while(len) {
  8927. currentQueue = queue;
  8928. queue = [];
  8929. while (++queueIndex < len) {
  8930. if (currentQueue) {
  8931. currentQueue[queueIndex].run();
  8932. }
  8933. }
  8934. queueIndex = -1;
  8935. len = queue.length;
  8936. }
  8937. currentQueue = null;
  8938. draining = false;
  8939. clearTimeout(timeout);
  8940. }
  8941. process.nextTick = function (fun) {
  8942. var args = new Array(arguments.length - 1);
  8943. if (arguments.length > 1) {
  8944. for (var i = 1; i < arguments.length; i++) {
  8945. args[i - 1] = arguments[i];
  8946. }
  8947. }
  8948. queue.push(new Item(fun, args));
  8949. if (queue.length === 1 && !draining) {
  8950. setTimeout(drainQueue, 0);
  8951. }
  8952. };
  8953. // v8 likes predictible objects
  8954. function Item(fun, array) {
  8955. this.fun = fun;
  8956. this.array = array;
  8957. }
  8958. Item.prototype.run = function () {
  8959. this.fun.apply(null, this.array);
  8960. };
  8961. process.title = 'browser';
  8962. process.browser = true;
  8963. process.env = {};
  8964. process.argv = [];
  8965. process.version = ''; // empty string to avoid regexp issues
  8966. process.versions = {};
  8967. function noop() {}
  8968. process.on = noop;
  8969. process.addListener = noop;
  8970. process.once = noop;
  8971. process.off = noop;
  8972. process.removeListener = noop;
  8973. process.removeAllListeners = noop;
  8974. process.emit = noop;
  8975. process.binding = function (name) {
  8976. throw new Error('process.binding is not supported');
  8977. };
  8978. process.cwd = function () { return '/' };
  8979. process.chdir = function (dir) {
  8980. throw new Error('process.chdir is not supported');
  8981. };
  8982. process.umask = function() { return 0; };
  8983. },{}],59:[function(require,module,exports){
  8984. // Copyright Joyent, Inc. and other Node contributors.
  8985. //
  8986. // Permission is hereby granted, free of charge, to any person obtaining a
  8987. // copy of this software and associated documentation files (the
  8988. // "Software"), to deal in the Software without restriction, including
  8989. // without limitation the rights to use, copy, modify, merge, publish,
  8990. // distribute, sublicense, and/or sell copies of the Software, and to permit
  8991. // persons to whom the Software is furnished to do so, subject to the
  8992. // following conditions:
  8993. //
  8994. // The above copyright notice and this permission notice shall be included
  8995. // in all copies or substantial portions of the Software.
  8996. //
  8997. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  8998. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  8999. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  9000. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  9001. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  9002. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  9003. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  9004. module.exports = Stream;
  9005. var EE = require('events').EventEmitter;
  9006. var inherits = require('inherits');
  9007. inherits(Stream, EE);
  9008. Stream.Readable = require('readable-stream/readable.js');
  9009. Stream.Writable = require('readable-stream/writable.js');
  9010. Stream.Duplex = require('readable-stream/duplex.js');
  9011. Stream.Transform = require('readable-stream/transform.js');
  9012. Stream.PassThrough = require('readable-stream/passthrough.js');
  9013. // Backwards-compat with node 0.4.x
  9014. Stream.Stream = Stream;
  9015. // old-style streams. Note that the pipe method (the only relevant
  9016. // part of this class) is overridden in the Readable class.
  9017. function Stream() {
  9018. EE.call(this);
  9019. }
  9020. Stream.prototype.pipe = function(dest, options) {
  9021. var source = this;
  9022. function ondata(chunk) {
  9023. if (dest.writable) {
  9024. if (false === dest.write(chunk) && source.pause) {
  9025. source.pause();
  9026. }
  9027. }
  9028. }
  9029. source.on('data', ondata);
  9030. function ondrain() {
  9031. if (source.readable && source.resume) {
  9032. source.resume();
  9033. }
  9034. }
  9035. dest.on('drain', ondrain);
  9036. // If the 'end' option is not supplied, dest.end() will be called when
  9037. // source gets the 'end' or 'close' events. Only dest.end() once.
  9038. if (!dest._isStdio && (!options || options.end !== false)) {
  9039. source.on('end', onend);
  9040. source.on('close', onclose);
  9041. }
  9042. var didOnEnd = false;
  9043. function onend() {
  9044. if (didOnEnd) return;
  9045. didOnEnd = true;
  9046. dest.end();
  9047. }
  9048. function onclose() {
  9049. if (didOnEnd) return;
  9050. didOnEnd = true;
  9051. if (typeof dest.destroy === 'function') dest.destroy();
  9052. }
  9053. // don't leave dangling pipes when there are errors.
  9054. function onerror(er) {
  9055. cleanup();
  9056. if (EE.listenerCount(this, 'error') === 0) {
  9057. throw er; // Unhandled stream error in pipe.
  9058. }
  9059. }
  9060. source.on('error', onerror);
  9061. dest.on('error', onerror);
  9062. // remove all the event listeners that were added.
  9063. function cleanup() {
  9064. source.removeListener('data', ondata);
  9065. dest.removeListener('drain', ondrain);
  9066. source.removeListener('end', onend);
  9067. source.removeListener('close', onclose);
  9068. source.removeListener('error', onerror);
  9069. dest.removeListener('error', onerror);
  9070. source.removeListener('end', cleanup);
  9071. source.removeListener('close', cleanup);
  9072. dest.removeListener('close', cleanup);
  9073. }
  9074. source.on('end', cleanup);
  9075. source.on('close', cleanup);
  9076. dest.on('close', cleanup);
  9077. dest.emit('pipe', source);
  9078. // Allow for unix-like usage: A.pipe(B).pipe(C)
  9079. return dest;
  9080. };
  9081. },{"events":50,"inherits":53,"readable-stream/duplex.js":61,"readable-stream/passthrough.js":67,"readable-stream/readable.js":68,"readable-stream/transform.js":69,"readable-stream/writable.js":70}],60:[function(require,module,exports){
  9082. arguments[4][46][0].apply(exports,arguments)
  9083. },{"dup":46}],61:[function(require,module,exports){
  9084. module.exports = require("./lib/_stream_duplex.js")
  9085. },{"./lib/_stream_duplex.js":62}],62:[function(require,module,exports){
  9086. // a duplex stream is just a stream that is both readable and writable.
  9087. // Since JS doesn't have multiple prototypal inheritance, this class
  9088. // prototypally inherits from Readable, and then parasitically from
  9089. // Writable.
  9090. 'use strict';
  9091. /*<replacement>*/
  9092. var objectKeys = Object.keys || function (obj) {
  9093. var keys = [];
  9094. for (var key in obj) {
  9095. keys.push(key);
  9096. }return keys;
  9097. };
  9098. /*</replacement>*/
  9099. module.exports = Duplex;
  9100. /*<replacement>*/
  9101. var processNextTick = require('process-nextick-args');
  9102. /*</replacement>*/
  9103. /*<replacement>*/
  9104. var util = require('core-util-is');
  9105. util.inherits = require('inherits');
  9106. /*</replacement>*/
  9107. var Readable = require('./_stream_readable');
  9108. var Writable = require('./_stream_writable');
  9109. util.inherits(Duplex, Readable);
  9110. var keys = objectKeys(Writable.prototype);
  9111. for (var v = 0; v < keys.length; v++) {
  9112. var method = keys[v];
  9113. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  9114. }
  9115. function Duplex(options) {
  9116. if (!(this instanceof Duplex)) return new Duplex(options);
  9117. Readable.call(this, options);
  9118. Writable.call(this, options);
  9119. if (options && options.readable === false) this.readable = false;
  9120. if (options && options.writable === false) this.writable = false;
  9121. this.allowHalfOpen = true;
  9122. if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
  9123. this.once('end', onend);
  9124. }
  9125. // the no-half-open enforcer
  9126. function onend() {
  9127. // if we allow half-open state, or if the writable side ended,
  9128. // then we're ok.
  9129. if (this.allowHalfOpen || this._writableState.ended) return;
  9130. // no more data can be written.
  9131. // But allow more writes to happen in this tick.
  9132. processNextTick(onEndNT, this);
  9133. }
  9134. function onEndNT(self) {
  9135. self.end();
  9136. }
  9137. function forEach(xs, f) {
  9138. for (var i = 0, l = xs.length; i < l; i++) {
  9139. f(xs[i], i);
  9140. }
  9141. }
  9142. },{"./_stream_readable":64,"./_stream_writable":66,"core-util-is":47,"inherits":53,"process-nextick-args":57}],63:[function(require,module,exports){
  9143. // a passthrough stream.
  9144. // basically just the most minimal sort of Transform stream.
  9145. // Every written chunk gets output as-is.
  9146. 'use strict';
  9147. module.exports = PassThrough;
  9148. var Transform = require('./_stream_transform');
  9149. /*<replacement>*/
  9150. var util = require('core-util-is');
  9151. util.inherits = require('inherits');
  9152. /*</replacement>*/
  9153. util.inherits(PassThrough, Transform);
  9154. function PassThrough(options) {
  9155. if (!(this instanceof PassThrough)) return new PassThrough(options);
  9156. Transform.call(this, options);
  9157. }
  9158. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  9159. cb(null, chunk);
  9160. };
  9161. },{"./_stream_transform":65,"core-util-is":47,"inherits":53}],64:[function(require,module,exports){
  9162. (function (process){
  9163. 'use strict';
  9164. module.exports = Readable;
  9165. /*<replacement>*/
  9166. var processNextTick = require('process-nextick-args');
  9167. /*</replacement>*/
  9168. /*<replacement>*/
  9169. var isArray = require('isarray');
  9170. /*</replacement>*/
  9171. Readable.ReadableState = ReadableState;
  9172. /*<replacement>*/
  9173. var EE = require('events').EventEmitter;
  9174. var EElistenerCount = function (emitter, type) {
  9175. return emitter.listeners(type).length;
  9176. };
  9177. /*</replacement>*/
  9178. /*<replacement>*/
  9179. var Stream;
  9180. (function () {
  9181. try {
  9182. Stream = require('st' + 'ream');
  9183. } catch (_) {} finally {
  9184. if (!Stream) Stream = require('events').EventEmitter;
  9185. }
  9186. })();
  9187. /*</replacement>*/
  9188. var Buffer = require('buffer').Buffer;
  9189. /*<replacement>*/
  9190. var bufferShim = require('buffer-shims');
  9191. /*</replacement>*/
  9192. /*<replacement>*/
  9193. var util = require('core-util-is');
  9194. util.inherits = require('inherits');
  9195. /*</replacement>*/
  9196. /*<replacement>*/
  9197. var debugUtil = require('util');
  9198. var debug = void 0;
  9199. if (debugUtil && debugUtil.debuglog) {
  9200. debug = debugUtil.debuglog('stream');
  9201. } else {
  9202. debug = function () {};
  9203. }
  9204. /*</replacement>*/
  9205. var StringDecoder;
  9206. util.inherits(Readable, Stream);
  9207. var hasPrependListener = typeof EE.prototype.prependListener === 'function';
  9208. function prependListener(emitter, event, fn) {
  9209. if (hasPrependListener) return emitter.prependListener(event, fn);
  9210. // This is a brutally ugly hack to make sure that our error handler
  9211. // is attached before any userland ones. NEVER DO THIS. This is here
  9212. // only because this code needs to continue to work with older versions
  9213. // of Node.js that do not include the prependListener() method. The goal
  9214. // is to eventually remove this hack.
  9215. 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]];
  9216. }
  9217. var Duplex;
  9218. function ReadableState(options, stream) {
  9219. Duplex = Duplex || require('./_stream_duplex');
  9220. options = options || {};
  9221. // object stream flag. Used to make read(n) ignore n and to
  9222. // make all the buffer merging and length checks go away
  9223. this.objectMode = !!options.objectMode;
  9224. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
  9225. // the point at which it stops calling _read() to fill the buffer
  9226. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  9227. var hwm = options.highWaterMark;
  9228. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  9229. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  9230. // cast to ints.
  9231. this.highWaterMark = ~ ~this.highWaterMark;
  9232. this.buffer = [];
  9233. this.length = 0;
  9234. this.pipes = null;
  9235. this.pipesCount = 0;
  9236. this.flowing = null;
  9237. this.ended = false;
  9238. this.endEmitted = false;
  9239. this.reading = false;
  9240. // a flag to be able to tell if the onwrite cb is called immediately,
  9241. // or on a later tick. We set this to true at first, because any
  9242. // actions that shouldn't happen until "later" should generally also
  9243. // not happen before the first write call.
  9244. this.sync = true;
  9245. // whenever we return null, then we set a flag to say
  9246. // that we're awaiting a 'readable' event emission.
  9247. this.needReadable = false;
  9248. this.emittedReadable = false;
  9249. this.readableListening = false;
  9250. this.resumeScheduled = false;
  9251. // Crypto is kind of old and crusty. Historically, its default string
  9252. // encoding is 'binary' so we have to make this configurable.
  9253. // Everything else in the universe uses 'utf8', though.
  9254. this.defaultEncoding = options.defaultEncoding || 'utf8';
  9255. // when piping, we only care about 'readable' events that happen
  9256. // after read()ing all the bytes and not getting any pushback.
  9257. this.ranOut = false;
  9258. // the number of writers that are awaiting a drain event in .pipe()s
  9259. this.awaitDrain = 0;
  9260. // if true, a maybeReadMore has been scheduled
  9261. this.readingMore = false;
  9262. this.decoder = null;
  9263. this.encoding = null;
  9264. if (options.encoding) {
  9265. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  9266. this.decoder = new StringDecoder(options.encoding);
  9267. this.encoding = options.encoding;
  9268. }
  9269. }
  9270. var Duplex;
  9271. function Readable(options) {
  9272. Duplex = Duplex || require('./_stream_duplex');
  9273. if (!(this instanceof Readable)) return new Readable(options);
  9274. this._readableState = new ReadableState(options, this);
  9275. // legacy
  9276. this.readable = true;
  9277. if (options && typeof options.read === 'function') this._read = options.read;
  9278. Stream.call(this);
  9279. }
  9280. // Manually shove something into the read() buffer.
  9281. // This returns true if the highWaterMark has not been hit yet,
  9282. // similar to how Writable.write() returns true if you should
  9283. // write() some more.
  9284. Readable.prototype.push = function (chunk, encoding) {
  9285. var state = this._readableState;
  9286. if (!state.objectMode && typeof chunk === 'string') {
  9287. encoding = encoding || state.defaultEncoding;
  9288. if (encoding !== state.encoding) {
  9289. chunk = bufferShim.from(chunk, encoding);
  9290. encoding = '';
  9291. }
  9292. }
  9293. return readableAddChunk(this, state, chunk, encoding, false);
  9294. };
  9295. // Unshift should *always* be something directly out of read()
  9296. Readable.prototype.unshift = function (chunk) {
  9297. var state = this._readableState;
  9298. return readableAddChunk(this, state, chunk, '', true);
  9299. };
  9300. Readable.prototype.isPaused = function () {
  9301. return this._readableState.flowing === false;
  9302. };
  9303. function readableAddChunk(stream, state, chunk, encoding, addToFront) {
  9304. var er = chunkInvalid(state, chunk);
  9305. if (er) {
  9306. stream.emit('error', er);
  9307. } else if (chunk === null) {
  9308. state.reading = false;
  9309. onEofChunk(stream, state);
  9310. } else if (state.objectMode || chunk && chunk.length > 0) {
  9311. if (state.ended && !addToFront) {
  9312. var e = new Error('stream.push() after EOF');
  9313. stream.emit('error', e);
  9314. } else if (state.endEmitted && addToFront) {
  9315. var _e = new Error('stream.unshift() after end event');
  9316. stream.emit('error', _e);
  9317. } else {
  9318. var skipAdd;
  9319. if (state.decoder && !addToFront && !encoding) {
  9320. chunk = state.decoder.write(chunk);
  9321. skipAdd = !state.objectMode && chunk.length === 0;
  9322. }
  9323. if (!addToFront) state.reading = false;
  9324. // Don't add to the buffer if we've decoded to an empty string chunk and
  9325. // we're not in object mode
  9326. if (!skipAdd) {
  9327. // if we want the data now, just emit it.
  9328. if (state.flowing && state.length === 0 && !state.sync) {
  9329. stream.emit('data', chunk);
  9330. stream.read(0);
  9331. } else {
  9332. // update the buffer info.
  9333. state.length += state.objectMode ? 1 : chunk.length;
  9334. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  9335. if (state.needReadable) emitReadable(stream);
  9336. }
  9337. }
  9338. maybeReadMore(stream, state);
  9339. }
  9340. } else if (!addToFront) {
  9341. state.reading = false;
  9342. }
  9343. return needMoreData(state);
  9344. }
  9345. // if it's past the high water mark, we can push in some more.
  9346. // Also, if we have no data yet, we can stand some
  9347. // more bytes. This is to work around cases where hwm=0,
  9348. // such as the repl. Also, if the push() triggered a
  9349. // readable event, and the user called read(largeNumber) such that
  9350. // needReadable was set, then we ought to push more, so that another
  9351. // 'readable' event will be triggered.
  9352. function needMoreData(state) {
  9353. return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
  9354. }
  9355. // backwards compatibility.
  9356. Readable.prototype.setEncoding = function (enc) {
  9357. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  9358. this._readableState.decoder = new StringDecoder(enc);
  9359. this._readableState.encoding = enc;
  9360. return this;
  9361. };
  9362. // Don't raise the hwm > 8MB
  9363. var MAX_HWM = 0x800000;
  9364. function computeNewHighWaterMark(n) {
  9365. if (n >= MAX_HWM) {
  9366. n = MAX_HWM;
  9367. } else {
  9368. // Get the next highest power of 2
  9369. n--;
  9370. n |= n >>> 1;
  9371. n |= n >>> 2;
  9372. n |= n >>> 4;
  9373. n |= n >>> 8;
  9374. n |= n >>> 16;
  9375. n++;
  9376. }
  9377. return n;
  9378. }
  9379. function howMuchToRead(n, state) {
  9380. if (state.length === 0 && state.ended) return 0;
  9381. if (state.objectMode) return n === 0 ? 0 : 1;
  9382. if (n === null || isNaN(n)) {
  9383. // only flow one buffer at a time
  9384. if (state.flowing && state.buffer.length) return state.buffer[0].length;else return state.length;
  9385. }
  9386. if (n <= 0) return 0;
  9387. // If we're asking for more than the target buffer level,
  9388. // then raise the water mark. Bump up to the next highest
  9389. // power of 2, to prevent increasing it excessively in tiny
  9390. // amounts.
  9391. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  9392. // don't have that much. return null, unless we've ended.
  9393. if (n > state.length) {
  9394. if (!state.ended) {
  9395. state.needReadable = true;
  9396. return 0;
  9397. } else {
  9398. return state.length;
  9399. }
  9400. }
  9401. return n;
  9402. }
  9403. // you can override either this method, or the async _read(n) below.
  9404. Readable.prototype.read = function (n) {
  9405. debug('read', n);
  9406. var state = this._readableState;
  9407. var nOrig = n;
  9408. if (typeof n !== 'number' || n > 0) state.emittedReadable = false;
  9409. // if we're doing read(0) to trigger a readable event, but we
  9410. // already have a bunch of data in the buffer, then just trigger
  9411. // the 'readable' event and move on.
  9412. if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
  9413. debug('read: emitReadable', state.length, state.ended);
  9414. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  9415. return null;
  9416. }
  9417. n = howMuchToRead(n, state);
  9418. // if we've ended, and we're now clear, then finish it up.
  9419. if (n === 0 && state.ended) {
  9420. if (state.length === 0) endReadable(this);
  9421. return null;
  9422. }
  9423. // All the actual chunk generation logic needs to be
  9424. // *below* the call to _read. The reason is that in certain
  9425. // synthetic stream cases, such as passthrough streams, _read
  9426. // may be a completely synchronous operation which may change
  9427. // the state of the read buffer, providing enough data when
  9428. // before there was *not* enough.
  9429. //
  9430. // So, the steps are:
  9431. // 1. Figure out what the state of things will be after we do
  9432. // a read from the buffer.
  9433. //
  9434. // 2. If that resulting state will trigger a _read, then call _read.
  9435. // Note that this may be asynchronous, or synchronous. Yes, it is
  9436. // deeply ugly to write APIs this way, but that still doesn't mean
  9437. // that the Readable class should behave improperly, as streams are
  9438. // designed to be sync/async agnostic.
  9439. // Take note if the _read call is sync or async (ie, if the read call
  9440. // has returned yet), so that we know whether or not it's safe to emit
  9441. // 'readable' etc.
  9442. //
  9443. // 3. Actually pull the requested chunks out of the buffer and return.
  9444. // if we need a readable event, then we need to do some reading.
  9445. var doRead = state.needReadable;
  9446. debug('need readable', doRead);
  9447. // if we currently have less than the highWaterMark, then also read some
  9448. if (state.length === 0 || state.length - n < state.highWaterMark) {
  9449. doRead = true;
  9450. debug('length less than watermark', doRead);
  9451. }
  9452. // however, if we've ended, then there's no point, and if we're already
  9453. // reading, then it's unnecessary.
  9454. if (state.ended || state.reading) {
  9455. doRead = false;
  9456. debug('reading or ended', doRead);
  9457. }
  9458. if (doRead) {
  9459. debug('do read');
  9460. state.reading = true;
  9461. state.sync = true;
  9462. // if the length is currently zero, then we *need* a readable event.
  9463. if (state.length === 0) state.needReadable = true;
  9464. // call internal read method
  9465. this._read(state.highWaterMark);
  9466. state.sync = false;
  9467. }
  9468. // If _read pushed data synchronously, then `reading` will be false,
  9469. // and we need to re-evaluate how much data we can return to the user.
  9470. if (doRead && !state.reading) n = howMuchToRead(nOrig, state);
  9471. var ret;
  9472. if (n > 0) ret = fromList(n, state);else ret = null;
  9473. if (ret === null) {
  9474. state.needReadable = true;
  9475. n = 0;
  9476. }
  9477. state.length -= n;
  9478. // If we have nothing in the buffer, then we want to know
  9479. // as soon as we *do* get something into the buffer.
  9480. if (state.length === 0 && !state.ended) state.needReadable = true;
  9481. // If we tried to read() past the EOF, then emit end on the next tick.
  9482. if (nOrig !== n && state.ended && state.length === 0) endReadable(this);
  9483. if (ret !== null) this.emit('data', ret);
  9484. return ret;
  9485. };
  9486. function chunkInvalid(state, chunk) {
  9487. var er = null;
  9488. if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
  9489. er = new TypeError('Invalid non-string/buffer chunk');
  9490. }
  9491. return er;
  9492. }
  9493. function onEofChunk(stream, state) {
  9494. if (state.ended) return;
  9495. if (state.decoder) {
  9496. var chunk = state.decoder.end();
  9497. if (chunk && chunk.length) {
  9498. state.buffer.push(chunk);
  9499. state.length += state.objectMode ? 1 : chunk.length;
  9500. }
  9501. }
  9502. state.ended = true;
  9503. // emit 'readable' now to make sure it gets picked up.
  9504. emitReadable(stream);
  9505. }
  9506. // Don't emit readable right away in sync mode, because this can trigger
  9507. // another read() call => stack overflow. This way, it might trigger
  9508. // a nextTick recursion warning, but that's not so bad.
  9509. function emitReadable(stream) {
  9510. var state = stream._readableState;
  9511. state.needReadable = false;
  9512. if (!state.emittedReadable) {
  9513. debug('emitReadable', state.flowing);
  9514. state.emittedReadable = true;
  9515. if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream);
  9516. }
  9517. }
  9518. function emitReadable_(stream) {
  9519. debug('emit readable');
  9520. stream.emit('readable');
  9521. flow(stream);
  9522. }
  9523. // at this point, the user has presumably seen the 'readable' event,
  9524. // and called read() to consume some data. that may have triggered
  9525. // in turn another _read(n) call, in which case reading = true if
  9526. // it's in progress.
  9527. // However, if we're not ended, or reading, and the length < hwm,
  9528. // then go ahead and try to read some more preemptively.
  9529. function maybeReadMore(stream, state) {
  9530. if (!state.readingMore) {
  9531. state.readingMore = true;
  9532. processNextTick(maybeReadMore_, stream, state);
  9533. }
  9534. }
  9535. function maybeReadMore_(stream, state) {
  9536. var len = state.length;
  9537. while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
  9538. debug('maybeReadMore read 0');
  9539. stream.read(0);
  9540. if (len === state.length)
  9541. // didn't get any data, stop spinning.
  9542. break;else len = state.length;
  9543. }
  9544. state.readingMore = false;
  9545. }
  9546. // abstract method. to be overridden in specific implementation classes.
  9547. // call cb(er, data) where data is <= n in length.
  9548. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  9549. // arbitrary, and perhaps not very meaningful.
  9550. Readable.prototype._read = function (n) {
  9551. this.emit('error', new Error('not implemented'));
  9552. };
  9553. Readable.prototype.pipe = function (dest, pipeOpts) {
  9554. var src = this;
  9555. var state = this._readableState;
  9556. switch (state.pipesCount) {
  9557. case 0:
  9558. state.pipes = dest;
  9559. break;
  9560. case 1:
  9561. state.pipes = [state.pipes, dest];
  9562. break;
  9563. default:
  9564. state.pipes.push(dest);
  9565. break;
  9566. }
  9567. state.pipesCount += 1;
  9568. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  9569. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  9570. var endFn = doEnd ? onend : cleanup;
  9571. if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn);
  9572. dest.on('unpipe', onunpipe);
  9573. function onunpipe(readable) {
  9574. debug('onunpipe');
  9575. if (readable === src) {
  9576. cleanup();
  9577. }
  9578. }
  9579. function onend() {
  9580. debug('onend');
  9581. dest.end();
  9582. }
  9583. // when the dest drains, it reduces the awaitDrain counter
  9584. // on the source. This would be more elegant with a .once()
  9585. // handler in flow(), but adding and removing repeatedly is
  9586. // too slow.
  9587. var ondrain = pipeOnDrain(src);
  9588. dest.on('drain', ondrain);
  9589. var cleanedUp = false;
  9590. function cleanup() {
  9591. debug('cleanup');
  9592. // cleanup event handlers once the pipe is broken
  9593. dest.removeListener('close', onclose);
  9594. dest.removeListener('finish', onfinish);
  9595. dest.removeListener('drain', ondrain);
  9596. dest.removeListener('error', onerror);
  9597. dest.removeListener('unpipe', onunpipe);
  9598. src.removeListener('end', onend);
  9599. src.removeListener('end', cleanup);
  9600. src.removeListener('data', ondata);
  9601. cleanedUp = true;
  9602. // if the reader is waiting for a drain event from this
  9603. // specific writer, then it would cause it to never start
  9604. // flowing again.
  9605. // So, if this is awaiting a drain, then we just call it now.
  9606. // If we don't know, then assume that we are waiting for one.
  9607. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  9608. }
  9609. src.on('data', ondata);
  9610. function ondata(chunk) {
  9611. debug('ondata');
  9612. var ret = dest.write(chunk);
  9613. if (false === ret) {
  9614. // If the user unpiped during `dest.write()`, it is possible
  9615. // to get stuck in a permanently paused state if that write
  9616. // also returned false.
  9617. // => Check whether `dest` is still a piping destination.
  9618. if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  9619. debug('false write response, pause', src._readableState.awaitDrain);
  9620. src._readableState.awaitDrain++;
  9621. }
  9622. src.pause();
  9623. }
  9624. }
  9625. // if the dest has an error, then stop piping into it.
  9626. // however, don't suppress the throwing behavior for this.
  9627. function onerror(er) {
  9628. debug('onerror', er);
  9629. unpipe();
  9630. dest.removeListener('error', onerror);
  9631. if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
  9632. }
  9633. // Make sure our error handler is attached before userland ones.
  9634. prependListener(dest, 'error', onerror);
  9635. // Both close and finish should trigger unpipe, but only once.
  9636. function onclose() {
  9637. dest.removeListener('finish', onfinish);
  9638. unpipe();
  9639. }
  9640. dest.once('close', onclose);
  9641. function onfinish() {
  9642. debug('onfinish');
  9643. dest.removeListener('close', onclose);
  9644. unpipe();
  9645. }
  9646. dest.once('finish', onfinish);
  9647. function unpipe() {
  9648. debug('unpipe');
  9649. src.unpipe(dest);
  9650. }
  9651. // tell the dest that it's being piped to
  9652. dest.emit('pipe', src);
  9653. // start the flow if it hasn't been started already.
  9654. if (!state.flowing) {
  9655. debug('pipe resume');
  9656. src.resume();
  9657. }
  9658. return dest;
  9659. };
  9660. function pipeOnDrain(src) {
  9661. return function () {
  9662. var state = src._readableState;
  9663. debug('pipeOnDrain', state.awaitDrain);
  9664. if (state.awaitDrain) state.awaitDrain--;
  9665. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  9666. state.flowing = true;
  9667. flow(src);
  9668. }
  9669. };
  9670. }
  9671. Readable.prototype.unpipe = function (dest) {
  9672. var state = this._readableState;
  9673. // if we're not piping anywhere, then do nothing.
  9674. if (state.pipesCount === 0) return this;
  9675. // just one destination. most common case.
  9676. if (state.pipesCount === 1) {
  9677. // passed in one, but it's not the right one.
  9678. if (dest && dest !== state.pipes) return this;
  9679. if (!dest) dest = state.pipes;
  9680. // got a match.
  9681. state.pipes = null;
  9682. state.pipesCount = 0;
  9683. state.flowing = false;
  9684. if (dest) dest.emit('unpipe', this);
  9685. return this;
  9686. }
  9687. // slow case. multiple pipe destinations.
  9688. if (!dest) {
  9689. // remove all.
  9690. var dests = state.pipes;
  9691. var len = state.pipesCount;
  9692. state.pipes = null;
  9693. state.pipesCount = 0;
  9694. state.flowing = false;
  9695. for (var _i = 0; _i < len; _i++) {
  9696. dests[_i].emit('unpipe', this);
  9697. }return this;
  9698. }
  9699. // try to find the right one.
  9700. var i = indexOf(state.pipes, dest);
  9701. if (i === -1) return this;
  9702. state.pipes.splice(i, 1);
  9703. state.pipesCount -= 1;
  9704. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  9705. dest.emit('unpipe', this);
  9706. return this;
  9707. };
  9708. // set up data events if they are asked for
  9709. // Ensure readable listeners eventually get something
  9710. Readable.prototype.on = function (ev, fn) {
  9711. var res = Stream.prototype.on.call(this, ev, fn);
  9712. // If listening to data, and it has not explicitly been paused,
  9713. // then call resume to start the flow of data on the next tick.
  9714. if (ev === 'data' && false !== this._readableState.flowing) {
  9715. this.resume();
  9716. }
  9717. if (ev === 'readable' && !this._readableState.endEmitted) {
  9718. var state = this._readableState;
  9719. if (!state.readableListening) {
  9720. state.readableListening = true;
  9721. state.emittedReadable = false;
  9722. state.needReadable = true;
  9723. if (!state.reading) {
  9724. processNextTick(nReadingNextTick, this);
  9725. } else if (state.length) {
  9726. emitReadable(this, state);
  9727. }
  9728. }
  9729. }
  9730. return res;
  9731. };
  9732. Readable.prototype.addListener = Readable.prototype.on;
  9733. function nReadingNextTick(self) {
  9734. debug('readable nexttick read 0');
  9735. self.read(0);
  9736. }
  9737. // pause() and resume() are remnants of the legacy readable stream API
  9738. // If the user uses them, then switch into old mode.
  9739. Readable.prototype.resume = function () {
  9740. var state = this._readableState;
  9741. if (!state.flowing) {
  9742. debug('resume');
  9743. state.flowing = true;
  9744. resume(this, state);
  9745. }
  9746. return this;
  9747. };
  9748. function resume(stream, state) {
  9749. if (!state.resumeScheduled) {
  9750. state.resumeScheduled = true;
  9751. processNextTick(resume_, stream, state);
  9752. }
  9753. }
  9754. function resume_(stream, state) {
  9755. if (!state.reading) {
  9756. debug('resume read 0');
  9757. stream.read(0);
  9758. }
  9759. state.resumeScheduled = false;
  9760. stream.emit('resume');
  9761. flow(stream);
  9762. if (state.flowing && !state.reading) stream.read(0);
  9763. }
  9764. Readable.prototype.pause = function () {
  9765. debug('call pause flowing=%j', this._readableState.flowing);
  9766. if (false !== this._readableState.flowing) {
  9767. debug('pause');
  9768. this._readableState.flowing = false;
  9769. this.emit('pause');
  9770. }
  9771. return this;
  9772. };
  9773. function flow(stream) {
  9774. var state = stream._readableState;
  9775. debug('flow', state.flowing);
  9776. if (state.flowing) {
  9777. do {
  9778. var chunk = stream.read();
  9779. } while (null !== chunk && state.flowing);
  9780. }
  9781. }
  9782. // wrap an old-style stream as the async data source.
  9783. // This is *not* part of the readable stream interface.
  9784. // It is an ugly unfortunate mess of history.
  9785. Readable.prototype.wrap = function (stream) {
  9786. var state = this._readableState;
  9787. var paused = false;
  9788. var self = this;
  9789. stream.on('end', function () {
  9790. debug('wrapped end');
  9791. if (state.decoder && !state.ended) {
  9792. var chunk = state.decoder.end();
  9793. if (chunk && chunk.length) self.push(chunk);
  9794. }
  9795. self.push(null);
  9796. });
  9797. stream.on('data', function (chunk) {
  9798. debug('wrapped data');
  9799. if (state.decoder) chunk = state.decoder.write(chunk);
  9800. // don't skip over falsy values in objectMode
  9801. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  9802. var ret = self.push(chunk);
  9803. if (!ret) {
  9804. paused = true;
  9805. stream.pause();
  9806. }
  9807. });
  9808. // proxy all the other methods.
  9809. // important when wrapping filters and duplexes.
  9810. for (var i in stream) {
  9811. if (this[i] === undefined && typeof stream[i] === 'function') {
  9812. this[i] = function (method) {
  9813. return function () {
  9814. return stream[method].apply(stream, arguments);
  9815. };
  9816. }(i);
  9817. }
  9818. }
  9819. // proxy certain important events.
  9820. var events = ['error', 'close', 'destroy', 'pause', 'resume'];
  9821. forEach(events, function (ev) {
  9822. stream.on(ev, self.emit.bind(self, ev));
  9823. });
  9824. // when we try to consume some more bytes, simply unpause the
  9825. // underlying stream.
  9826. self._read = function (n) {
  9827. debug('wrapped _read', n);
  9828. if (paused) {
  9829. paused = false;
  9830. stream.resume();
  9831. }
  9832. };
  9833. return self;
  9834. };
  9835. // exposed for testing purposes only.
  9836. Readable._fromList = fromList;
  9837. // Pluck off n bytes from an array of buffers.
  9838. // Length is the combined lengths of all the buffers in the list.
  9839. function fromList(n, state) {
  9840. var list = state.buffer;
  9841. var length = state.length;
  9842. var stringMode = !!state.decoder;
  9843. var objectMode = !!state.objectMode;
  9844. var ret;
  9845. // nothing in the list, definitely empty.
  9846. if (list.length === 0) return null;
  9847. if (length === 0) ret = null;else if (objectMode) ret = list.shift();else if (!n || n >= length) {
  9848. // read it all, truncate the array.
  9849. if (stringMode) ret = list.join('');else if (list.length === 1) ret = list[0];else ret = Buffer.concat(list, length);
  9850. list.length = 0;
  9851. } else {
  9852. // read just some of it.
  9853. if (n < list[0].length) {
  9854. // just take a part of the first list item.
  9855. // slice is the same for buffers and strings.
  9856. var buf = list[0];
  9857. ret = buf.slice(0, n);
  9858. list[0] = buf.slice(n);
  9859. } else if (n === list[0].length) {
  9860. // first list is a perfect match
  9861. ret = list.shift();
  9862. } else {
  9863. // complex case.
  9864. // we have enough to cover it, but it spans past the first buffer.
  9865. if (stringMode) ret = '';else ret = bufferShim.allocUnsafe(n);
  9866. var c = 0;
  9867. for (var i = 0, l = list.length; i < l && c < n; i++) {
  9868. var _buf = list[0];
  9869. var cpy = Math.min(n - c, _buf.length);
  9870. if (stringMode) ret += _buf.slice(0, cpy);else _buf.copy(ret, c, 0, cpy);
  9871. if (cpy < _buf.length) list[0] = _buf.slice(cpy);else list.shift();
  9872. c += cpy;
  9873. }
  9874. }
  9875. }
  9876. return ret;
  9877. }
  9878. function endReadable(stream) {
  9879. var state = stream._readableState;
  9880. // If we get here before consuming all the bytes, then that is a
  9881. // bug in node. Should never happen.
  9882. if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
  9883. if (!state.endEmitted) {
  9884. state.ended = true;
  9885. processNextTick(endReadableNT, state, stream);
  9886. }
  9887. }
  9888. function endReadableNT(state, stream) {
  9889. // Check that we didn't get one last unshift.
  9890. if (!state.endEmitted && state.length === 0) {
  9891. state.endEmitted = true;
  9892. stream.readable = false;
  9893. stream.emit('end');
  9894. }
  9895. }
  9896. function forEach(xs, f) {
  9897. for (var i = 0, l = xs.length; i < l; i++) {
  9898. f(xs[i], i);
  9899. }
  9900. }
  9901. function indexOf(xs, x) {
  9902. for (var i = 0, l = xs.length; i < l; i++) {
  9903. if (xs[i] === x) return i;
  9904. }
  9905. return -1;
  9906. }
  9907. }).call(this,require('_process'))
  9908. },{"./_stream_duplex":62,"_process":58,"buffer":45,"buffer-shims":44,"core-util-is":47,"events":50,"inherits":53,"isarray":60,"process-nextick-args":57,"string_decoder/":71,"util":41}],65:[function(require,module,exports){
  9909. // a transform stream is a readable/writable stream where you do
  9910. // something with the data. Sometimes it's called a "filter",
  9911. // but that's not a great name for it, since that implies a thing where
  9912. // some bits pass through, and others are simply ignored. (That would
  9913. // be a valid example of a transform, of course.)
  9914. //
  9915. // While the output is causally related to the input, it's not a
  9916. // necessarily symmetric or synchronous transformation. For example,
  9917. // a zlib stream might take multiple plain-text writes(), and then
  9918. // emit a single compressed chunk some time in the future.
  9919. //
  9920. // Here's how this works:
  9921. //
  9922. // The Transform stream has all the aspects of the readable and writable
  9923. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  9924. // internally, and returns false if there's a lot of pending writes
  9925. // buffered up. When you call read(), that calls _read(n) until
  9926. // there's enough pending readable data buffered up.
  9927. //
  9928. // In a transform stream, the written data is placed in a buffer. When
  9929. // _read(n) is called, it transforms the queued up data, calling the
  9930. // buffered _write cb's as it consumes chunks. If consuming a single
  9931. // written chunk would result in multiple output chunks, then the first
  9932. // outputted bit calls the readcb, and subsequent chunks just go into
  9933. // the read buffer, and will cause it to emit 'readable' if necessary.
  9934. //
  9935. // This way, back-pressure is actually determined by the reading side,
  9936. // since _read has to be called to start processing a new chunk. However,
  9937. // a pathological inflate type of transform can cause excessive buffering
  9938. // here. For example, imagine a stream where every byte of input is
  9939. // interpreted as an integer from 0-255, and then results in that many
  9940. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  9941. // 1kb of data being output. In this case, you could write a very small
  9942. // amount of input, and end up with a very large amount of output. In
  9943. // such a pathological inflating mechanism, there'd be no way to tell
  9944. // the system to stop doing the transform. A single 4MB write could
  9945. // cause the system to run out of memory.
  9946. //
  9947. // However, even in such a pathological case, only a single written chunk
  9948. // would be consumed, and then the rest would wait (un-transformed) until
  9949. // the results of the previous transformed chunk were consumed.
  9950. 'use strict';
  9951. module.exports = Transform;
  9952. var Duplex = require('./_stream_duplex');
  9953. /*<replacement>*/
  9954. var util = require('core-util-is');
  9955. util.inherits = require('inherits');
  9956. /*</replacement>*/
  9957. util.inherits(Transform, Duplex);
  9958. function TransformState(stream) {
  9959. this.afterTransform = function (er, data) {
  9960. return afterTransform(stream, er, data);
  9961. };
  9962. this.needTransform = false;
  9963. this.transforming = false;
  9964. this.writecb = null;
  9965. this.writechunk = null;
  9966. this.writeencoding = null;
  9967. }
  9968. function afterTransform(stream, er, data) {
  9969. var ts = stream._transformState;
  9970. ts.transforming = false;
  9971. var cb = ts.writecb;
  9972. if (!cb) return stream.emit('error', new Error('no writecb in Transform class'));
  9973. ts.writechunk = null;
  9974. ts.writecb = null;
  9975. if (data !== null && data !== undefined) stream.push(data);
  9976. cb(er);
  9977. var rs = stream._readableState;
  9978. rs.reading = false;
  9979. if (rs.needReadable || rs.length < rs.highWaterMark) {
  9980. stream._read(rs.highWaterMark);
  9981. }
  9982. }
  9983. function Transform(options) {
  9984. if (!(this instanceof Transform)) return new Transform(options);
  9985. Duplex.call(this, options);
  9986. this._transformState = new TransformState(this);
  9987. // when the writable side finishes, then flush out anything remaining.
  9988. var stream = this;
  9989. // start out asking for a readable event once data is transformed.
  9990. this._readableState.needReadable = true;
  9991. // we have implemented the _read method, and done the other things
  9992. // that Readable wants before the first _read call, so unset the
  9993. // sync guard flag.
  9994. this._readableState.sync = false;
  9995. if (options) {
  9996. if (typeof options.transform === 'function') this._transform = options.transform;
  9997. if (typeof options.flush === 'function') this._flush = options.flush;
  9998. }
  9999. this.once('prefinish', function () {
  10000. if (typeof this._flush === 'function') this._flush(function (er) {
  10001. done(stream, er);
  10002. });else done(stream);
  10003. });
  10004. }
  10005. Transform.prototype.push = function (chunk, encoding) {
  10006. this._transformState.needTransform = false;
  10007. return Duplex.prototype.push.call(this, chunk, encoding);
  10008. };
  10009. // This is the part where you do stuff!
  10010. // override this function in implementation classes.
  10011. // 'chunk' is an input chunk.
  10012. //
  10013. // Call `push(newChunk)` to pass along transformed output
  10014. // to the readable side. You may call 'push' zero or more times.
  10015. //
  10016. // Call `cb(err)` when you are done with this chunk. If you pass
  10017. // an error, then that'll put the hurt on the whole operation. If you
  10018. // never call cb(), then you'll never get another chunk.
  10019. Transform.prototype._transform = function (chunk, encoding, cb) {
  10020. throw new Error('Not implemented');
  10021. };
  10022. Transform.prototype._write = function (chunk, encoding, cb) {
  10023. var ts = this._transformState;
  10024. ts.writecb = cb;
  10025. ts.writechunk = chunk;
  10026. ts.writeencoding = encoding;
  10027. if (!ts.transforming) {
  10028. var rs = this._readableState;
  10029. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  10030. }
  10031. };
  10032. // Doesn't matter what the args are here.
  10033. // _transform does all the work.
  10034. // That we got here means that the readable side wants more data.
  10035. Transform.prototype._read = function (n) {
  10036. var ts = this._transformState;
  10037. if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
  10038. ts.transforming = true;
  10039. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  10040. } else {
  10041. // mark that we need a transform, so that any data that comes in
  10042. // will get processed, now that we've asked for it.
  10043. ts.needTransform = true;
  10044. }
  10045. };
  10046. function done(stream, er) {
  10047. if (er) return stream.emit('error', er);
  10048. // if there's nothing in the write buffer, then that means
  10049. // that nothing more will ever be provided
  10050. var ws = stream._writableState;
  10051. var ts = stream._transformState;
  10052. if (ws.length) throw new Error('Calling transform done when ws.length != 0');
  10053. if (ts.transforming) throw new Error('Calling transform done when still transforming');
  10054. return stream.push(null);
  10055. }
  10056. },{"./_stream_duplex":62,"core-util-is":47,"inherits":53}],66:[function(require,module,exports){
  10057. (function (process){
  10058. // A bit simpler than readable streams.
  10059. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  10060. // the drain event emission and buffering.
  10061. 'use strict';
  10062. module.exports = Writable;
  10063. /*<replacement>*/
  10064. var processNextTick = require('process-nextick-args');
  10065. /*</replacement>*/
  10066. /*<replacement>*/
  10067. var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick;
  10068. /*</replacement>*/
  10069. Writable.WritableState = WritableState;
  10070. /*<replacement>*/
  10071. var util = require('core-util-is');
  10072. util.inherits = require('inherits');
  10073. /*</replacement>*/
  10074. /*<replacement>*/
  10075. var internalUtil = {
  10076. deprecate: require('util-deprecate')
  10077. };
  10078. /*</replacement>*/
  10079. /*<replacement>*/
  10080. var Stream;
  10081. (function () {
  10082. try {
  10083. Stream = require('st' + 'ream');
  10084. } catch (_) {} finally {
  10085. if (!Stream) Stream = require('events').EventEmitter;
  10086. }
  10087. })();
  10088. /*</replacement>*/
  10089. var Buffer = require('buffer').Buffer;
  10090. /*<replacement>*/
  10091. var bufferShim = require('buffer-shims');
  10092. /*</replacement>*/
  10093. util.inherits(Writable, Stream);
  10094. function nop() {}
  10095. function WriteReq(chunk, encoding, cb) {
  10096. this.chunk = chunk;
  10097. this.encoding = encoding;
  10098. this.callback = cb;
  10099. this.next = null;
  10100. }
  10101. var Duplex;
  10102. function WritableState(options, stream) {
  10103. Duplex = Duplex || require('./_stream_duplex');
  10104. options = options || {};
  10105. // object stream flag to indicate whether or not this stream
  10106. // contains buffers or objects.
  10107. this.objectMode = !!options.objectMode;
  10108. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
  10109. // the point at which write() starts returning false
  10110. // Note: 0 is a valid value, means that we always return false if
  10111. // the entire buffer is not flushed immediately on write()
  10112. var hwm = options.highWaterMark;
  10113. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  10114. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  10115. // cast to ints.
  10116. this.highWaterMark = ~ ~this.highWaterMark;
  10117. this.needDrain = false;
  10118. // at the start of calling end()
  10119. this.ending = false;
  10120. // when end() has been called, and returned
  10121. this.ended = false;
  10122. // when 'finish' is emitted
  10123. this.finished = false;
  10124. // should we decode strings into buffers before passing to _write?
  10125. // this is here so that some node-core streams can optimize string
  10126. // handling at a lower level.
  10127. var noDecode = options.decodeStrings === false;
  10128. this.decodeStrings = !noDecode;
  10129. // Crypto is kind of old and crusty. Historically, its default string
  10130. // encoding is 'binary' so we have to make this configurable.
  10131. // Everything else in the universe uses 'utf8', though.
  10132. this.defaultEncoding = options.defaultEncoding || 'utf8';
  10133. // not an actual buffer we keep track of, but a measurement
  10134. // of how much we're waiting to get pushed to some underlying
  10135. // socket or file.
  10136. this.length = 0;
  10137. // a flag to see when we're in the middle of a write.
  10138. this.writing = false;
  10139. // when true all writes will be buffered until .uncork() call
  10140. this.corked = 0;
  10141. // a flag to be able to tell if the onwrite cb is called immediately,
  10142. // or on a later tick. We set this to true at first, because any
  10143. // actions that shouldn't happen until "later" should generally also
  10144. // not happen before the first write call.
  10145. this.sync = true;
  10146. // a flag to know if we're processing previously buffered items, which
  10147. // may call the _write() callback in the same tick, so that we don't
  10148. // end up in an overlapped onwrite situation.
  10149. this.bufferProcessing = false;
  10150. // the callback that's passed to _write(chunk,cb)
  10151. this.onwrite = function (er) {
  10152. onwrite(stream, er);
  10153. };
  10154. // the callback that the user supplies to write(chunk,encoding,cb)
  10155. this.writecb = null;
  10156. // the amount that is being written when _write is called.
  10157. this.writelen = 0;
  10158. this.bufferedRequest = null;
  10159. this.lastBufferedRequest = null;
  10160. // number of pending user-supplied write callbacks
  10161. // this must be 0 before 'finish' can be emitted
  10162. this.pendingcb = 0;
  10163. // emit prefinish if the only thing we're waiting for is _write cbs
  10164. // This is relevant for synchronous Transform streams
  10165. this.prefinished = false;
  10166. // True if the error was already emitted and should not be thrown again
  10167. this.errorEmitted = false;
  10168. // count buffered requests
  10169. this.bufferedRequestCount = 0;
  10170. // allocate the first CorkedRequest, there is always
  10171. // one allocated and free to use, and we maintain at most two
  10172. this.corkedRequestsFree = new CorkedRequest(this);
  10173. }
  10174. WritableState.prototype.getBuffer = function writableStateGetBuffer() {
  10175. var current = this.bufferedRequest;
  10176. var out = [];
  10177. while (current) {
  10178. out.push(current);
  10179. current = current.next;
  10180. }
  10181. return out;
  10182. };
  10183. (function () {
  10184. try {
  10185. Object.defineProperty(WritableState.prototype, 'buffer', {
  10186. get: internalUtil.deprecate(function () {
  10187. return this.getBuffer();
  10188. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
  10189. });
  10190. } catch (_) {}
  10191. })();
  10192. var Duplex;
  10193. function Writable(options) {
  10194. Duplex = Duplex || require('./_stream_duplex');
  10195. // Writable ctor is applied to Duplexes, though they're not
  10196. // instanceof Writable, they're instanceof Readable.
  10197. if (!(this instanceof Writable) && !(this instanceof Duplex)) return new Writable(options);
  10198. this._writableState = new WritableState(options, this);
  10199. // legacy.
  10200. this.writable = true;
  10201. if (options) {
  10202. if (typeof options.write === 'function') this._write = options.write;
  10203. if (typeof options.writev === 'function') this._writev = options.writev;
  10204. }
  10205. Stream.call(this);
  10206. }
  10207. // Otherwise people can pipe Writable streams, which is just wrong.
  10208. Writable.prototype.pipe = function () {
  10209. this.emit('error', new Error('Cannot pipe, not readable'));
  10210. };
  10211. function writeAfterEnd(stream, cb) {
  10212. var er = new Error('write after end');
  10213. // TODO: defer error events consistently everywhere, not just the cb
  10214. stream.emit('error', er);
  10215. processNextTick(cb, er);
  10216. }
  10217. // If we get something that is not a buffer, string, null, or undefined,
  10218. // and we're not in objectMode, then that's an error.
  10219. // Otherwise stream chunks are all considered to be of length=1, and the
  10220. // watermarks determine how many objects to keep in the buffer, rather than
  10221. // how many bytes or characters.
  10222. function validChunk(stream, state, chunk, cb) {
  10223. var valid = true;
  10224. var er = false;
  10225. // Always throw error if a null is written
  10226. // if we are not in object mode then throw
  10227. // if it is not a buffer, string, or undefined.
  10228. if (chunk === null) {
  10229. er = new TypeError('May not write null values to stream');
  10230. } else if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  10231. er = new TypeError('Invalid non-string/buffer chunk');
  10232. }
  10233. if (er) {
  10234. stream.emit('error', er);
  10235. processNextTick(cb, er);
  10236. valid = false;
  10237. }
  10238. return valid;
  10239. }
  10240. Writable.prototype.write = function (chunk, encoding, cb) {
  10241. var state = this._writableState;
  10242. var ret = false;
  10243. if (typeof encoding === 'function') {
  10244. cb = encoding;
  10245. encoding = null;
  10246. }
  10247. if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  10248. if (typeof cb !== 'function') cb = nop;
  10249. if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) {
  10250. state.pendingcb++;
  10251. ret = writeOrBuffer(this, state, chunk, encoding, cb);
  10252. }
  10253. return ret;
  10254. };
  10255. Writable.prototype.cork = function () {
  10256. var state = this._writableState;
  10257. state.corked++;
  10258. };
  10259. Writable.prototype.uncork = function () {
  10260. var state = this._writableState;
  10261. if (state.corked) {
  10262. state.corked--;
  10263. if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  10264. }
  10265. };
  10266. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  10267. // node::ParseEncoding() requires lower case.
  10268. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  10269. 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);
  10270. this._writableState.defaultEncoding = encoding;
  10271. return this;
  10272. };
  10273. function decodeChunk(state, chunk, encoding) {
  10274. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  10275. chunk = bufferShim.from(chunk, encoding);
  10276. }
  10277. return chunk;
  10278. }
  10279. // if we're already writing something, then just put this
  10280. // in the queue, and wait our turn. Otherwise, call _write
  10281. // If we return false, then we need a drain event, so set that flag.
  10282. function writeOrBuffer(stream, state, chunk, encoding, cb) {
  10283. chunk = decodeChunk(state, chunk, encoding);
  10284. if (Buffer.isBuffer(chunk)) encoding = 'buffer';
  10285. var len = state.objectMode ? 1 : chunk.length;
  10286. state.length += len;
  10287. var ret = state.length < state.highWaterMark;
  10288. // we must ensure that previous needDrain will not be reset to false.
  10289. if (!ret) state.needDrain = true;
  10290. if (state.writing || state.corked) {
  10291. var last = state.lastBufferedRequest;
  10292. state.lastBufferedRequest = new WriteReq(chunk, encoding, cb);
  10293. if (last) {
  10294. last.next = state.lastBufferedRequest;
  10295. } else {
  10296. state.bufferedRequest = state.lastBufferedRequest;
  10297. }
  10298. state.bufferedRequestCount += 1;
  10299. } else {
  10300. doWrite(stream, state, false, len, chunk, encoding, cb);
  10301. }
  10302. return ret;
  10303. }
  10304. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  10305. state.writelen = len;
  10306. state.writecb = cb;
  10307. state.writing = true;
  10308. state.sync = true;
  10309. if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  10310. state.sync = false;
  10311. }
  10312. function onwriteError(stream, state, sync, er, cb) {
  10313. --state.pendingcb;
  10314. if (sync) processNextTick(cb, er);else cb(er);
  10315. stream._writableState.errorEmitted = true;
  10316. stream.emit('error', er);
  10317. }
  10318. function onwriteStateUpdate(state) {
  10319. state.writing = false;
  10320. state.writecb = null;
  10321. state.length -= state.writelen;
  10322. state.writelen = 0;
  10323. }
  10324. function onwrite(stream, er) {
  10325. var state = stream._writableState;
  10326. var sync = state.sync;
  10327. var cb = state.writecb;
  10328. onwriteStateUpdate(state);
  10329. if (er) onwriteError(stream, state, sync, er, cb);else {
  10330. // Check if we're actually ready to finish, but don't emit yet
  10331. var finished = needFinish(state);
  10332. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  10333. clearBuffer(stream, state);
  10334. }
  10335. if (sync) {
  10336. /*<replacement>*/
  10337. asyncWrite(afterWrite, stream, state, finished, cb);
  10338. /*</replacement>*/
  10339. } else {
  10340. afterWrite(stream, state, finished, cb);
  10341. }
  10342. }
  10343. }
  10344. function afterWrite(stream, state, finished, cb) {
  10345. if (!finished) onwriteDrain(stream, state);
  10346. state.pendingcb--;
  10347. cb();
  10348. finishMaybe(stream, state);
  10349. }
  10350. // Must force callback to be called on nextTick, so that we don't
  10351. // emit 'drain' before the write() consumer gets the 'false' return
  10352. // value, and has a chance to attach a 'drain' listener.
  10353. function onwriteDrain(stream, state) {
  10354. if (state.length === 0 && state.needDrain) {
  10355. state.needDrain = false;
  10356. stream.emit('drain');
  10357. }
  10358. }
  10359. // if there's something in the buffer waiting, then process it
  10360. function clearBuffer(stream, state) {
  10361. state.bufferProcessing = true;
  10362. var entry = state.bufferedRequest;
  10363. if (stream._writev && entry && entry.next) {
  10364. // Fast case, write everything using _writev()
  10365. var l = state.bufferedRequestCount;
  10366. var buffer = new Array(l);
  10367. var holder = state.corkedRequestsFree;
  10368. holder.entry = entry;
  10369. var count = 0;
  10370. while (entry) {
  10371. buffer[count] = entry;
  10372. entry = entry.next;
  10373. count += 1;
  10374. }
  10375. doWrite(stream, state, true, state.length, buffer, '', holder.finish);
  10376. // doWrite is almost always async, defer these to save a bit of time
  10377. // as the hot path ends with doWrite
  10378. state.pendingcb++;
  10379. state.lastBufferedRequest = null;
  10380. if (holder.next) {
  10381. state.corkedRequestsFree = holder.next;
  10382. holder.next = null;
  10383. } else {
  10384. state.corkedRequestsFree = new CorkedRequest(state);
  10385. }
  10386. } else {
  10387. // Slow case, write chunks one-by-one
  10388. while (entry) {
  10389. var chunk = entry.chunk;
  10390. var encoding = entry.encoding;
  10391. var cb = entry.callback;
  10392. var len = state.objectMode ? 1 : chunk.length;
  10393. doWrite(stream, state, false, len, chunk, encoding, cb);
  10394. entry = entry.next;
  10395. // if we didn't call the onwrite immediately, then
  10396. // it means that we need to wait until it does.
  10397. // also, that means that the chunk and cb are currently
  10398. // being processed, so move the buffer counter past them.
  10399. if (state.writing) {
  10400. break;
  10401. }
  10402. }
  10403. if (entry === null) state.lastBufferedRequest = null;
  10404. }
  10405. state.bufferedRequestCount = 0;
  10406. state.bufferedRequest = entry;
  10407. state.bufferProcessing = false;
  10408. }
  10409. Writable.prototype._write = function (chunk, encoding, cb) {
  10410. cb(new Error('not implemented'));
  10411. };
  10412. Writable.prototype._writev = null;
  10413. Writable.prototype.end = function (chunk, encoding, cb) {
  10414. var state = this._writableState;
  10415. if (typeof chunk === 'function') {
  10416. cb = chunk;
  10417. chunk = null;
  10418. encoding = null;
  10419. } else if (typeof encoding === 'function') {
  10420. cb = encoding;
  10421. encoding = null;
  10422. }
  10423. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
  10424. // .end() fully uncorks
  10425. if (state.corked) {
  10426. state.corked = 1;
  10427. this.uncork();
  10428. }
  10429. // ignore unnecessary end() calls.
  10430. if (!state.ending && !state.finished) endWritable(this, state, cb);
  10431. };
  10432. function needFinish(state) {
  10433. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  10434. }
  10435. function prefinish(stream, state) {
  10436. if (!state.prefinished) {
  10437. state.prefinished = true;
  10438. stream.emit('prefinish');
  10439. }
  10440. }
  10441. function finishMaybe(stream, state) {
  10442. var need = needFinish(state);
  10443. if (need) {
  10444. if (state.pendingcb === 0) {
  10445. prefinish(stream, state);
  10446. state.finished = true;
  10447. stream.emit('finish');
  10448. } else {
  10449. prefinish(stream, state);
  10450. }
  10451. }
  10452. return need;
  10453. }
  10454. function endWritable(stream, state, cb) {
  10455. state.ending = true;
  10456. finishMaybe(stream, state);
  10457. if (cb) {
  10458. if (state.finished) processNextTick(cb);else stream.once('finish', cb);
  10459. }
  10460. state.ended = true;
  10461. stream.writable = false;
  10462. }
  10463. // It seems a linked list but it is not
  10464. // there will be only 2 of these for each stream
  10465. function CorkedRequest(state) {
  10466. var _this = this;
  10467. this.next = null;
  10468. this.entry = null;
  10469. this.finish = function (err) {
  10470. var entry = _this.entry;
  10471. _this.entry = null;
  10472. while (entry) {
  10473. var cb = entry.callback;
  10474. state.pendingcb--;
  10475. cb(err);
  10476. entry = entry.next;
  10477. }
  10478. if (state.corkedRequestsFree) {
  10479. state.corkedRequestsFree.next = _this;
  10480. } else {
  10481. state.corkedRequestsFree = _this;
  10482. }
  10483. };
  10484. }
  10485. }).call(this,require('_process'))
  10486. },{"./_stream_duplex":62,"_process":58,"buffer":45,"buffer-shims":44,"core-util-is":47,"events":50,"inherits":53,"process-nextick-args":57,"util-deprecate":73}],67:[function(require,module,exports){
  10487. module.exports = require("./lib/_stream_passthrough.js")
  10488. },{"./lib/_stream_passthrough.js":63}],68:[function(require,module,exports){
  10489. (function (process){
  10490. var Stream = (function (){
  10491. try {
  10492. return require('st' + 'ream'); // hack to fix a circular dependency issue when used with browserify
  10493. } catch(_){}
  10494. }());
  10495. exports = module.exports = require('./lib/_stream_readable.js');
  10496. exports.Stream = Stream || exports;
  10497. exports.Readable = exports;
  10498. exports.Writable = require('./lib/_stream_writable.js');
  10499. exports.Duplex = require('./lib/_stream_duplex.js');
  10500. exports.Transform = require('./lib/_stream_transform.js');
  10501. exports.PassThrough = require('./lib/_stream_passthrough.js');
  10502. if (!process.browser && process.env.READABLE_STREAM === 'disable' && Stream) {
  10503. module.exports = Stream;
  10504. }
  10505. }).call(this,require('_process'))
  10506. },{"./lib/_stream_duplex.js":62,"./lib/_stream_passthrough.js":63,"./lib/_stream_readable.js":64,"./lib/_stream_transform.js":65,"./lib/_stream_writable.js":66,"_process":58}],69:[function(require,module,exports){
  10507. module.exports = require("./lib/_stream_transform.js")
  10508. },{"./lib/_stream_transform.js":65}],70:[function(require,module,exports){
  10509. module.exports = require("./lib/_stream_writable.js")
  10510. },{"./lib/_stream_writable.js":66}],71:[function(require,module,exports){
  10511. // Copyright Joyent, Inc. and other Node contributors.
  10512. //
  10513. // Permission is hereby granted, free of charge, to any person obtaining a
  10514. // copy of this software and associated documentation files (the
  10515. // "Software"), to deal in the Software without restriction, including
  10516. // without limitation the rights to use, copy, modify, merge, publish,
  10517. // distribute, sublicense, and/or sell copies of the Software, and to permit
  10518. // persons to whom the Software is furnished to do so, subject to the
  10519. // following conditions:
  10520. //
  10521. // The above copyright notice and this permission notice shall be included
  10522. // in all copies or substantial portions of the Software.
  10523. //
  10524. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  10525. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10526. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  10527. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  10528. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  10529. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  10530. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  10531. var Buffer = require('buffer').Buffer;
  10532. var isBufferEncoding = Buffer.isEncoding
  10533. || function(encoding) {
  10534. switch (encoding && encoding.toLowerCase()) {
  10535. 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;
  10536. default: return false;
  10537. }
  10538. }
  10539. function assertEncoding(encoding) {
  10540. if (encoding && !isBufferEncoding(encoding)) {
  10541. throw new Error('Unknown encoding: ' + encoding);
  10542. }
  10543. }
  10544. // StringDecoder provides an interface for efficiently splitting a series of
  10545. // buffers into a series of JS strings without breaking apart multi-byte
  10546. // characters. CESU-8 is handled as part of the UTF-8 encoding.
  10547. //
  10548. // @TODO Handling all encodings inside a single object makes it very difficult
  10549. // to reason about this code, so it should be split up in the future.
  10550. // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
  10551. // points as used by CESU-8.
  10552. var StringDecoder = exports.StringDecoder = function(encoding) {
  10553. this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
  10554. assertEncoding(encoding);
  10555. switch (this.encoding) {
  10556. case 'utf8':
  10557. // CESU-8 represents each of Surrogate Pair by 3-bytes
  10558. this.surrogateSize = 3;
  10559. break;
  10560. case 'ucs2':
  10561. case 'utf16le':
  10562. // UTF-16 represents each of Surrogate Pair by 2-bytes
  10563. this.surrogateSize = 2;
  10564. this.detectIncompleteChar = utf16DetectIncompleteChar;
  10565. break;
  10566. case 'base64':
  10567. // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
  10568. this.surrogateSize = 3;
  10569. this.detectIncompleteChar = base64DetectIncompleteChar;
  10570. break;
  10571. default:
  10572. this.write = passThroughWrite;
  10573. return;
  10574. }
  10575. // Enough space to store all bytes of a single character. UTF-8 needs 4
  10576. // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
  10577. this.charBuffer = new Buffer(6);
  10578. // Number of bytes received for the current incomplete multi-byte character.
  10579. this.charReceived = 0;
  10580. // Number of bytes expected for the current incomplete multi-byte character.
  10581. this.charLength = 0;
  10582. };
  10583. // write decodes the given buffer and returns it as JS string that is
  10584. // guaranteed to not contain any partial multi-byte characters. Any partial
  10585. // character found at the end of the buffer is buffered up, and will be
  10586. // returned when calling write again with the remaining bytes.
  10587. //
  10588. // Note: Converting a Buffer containing an orphan surrogate to a String
  10589. // currently works, but converting a String to a Buffer (via `new Buffer`, or
  10590. // Buffer#write) will replace incomplete surrogates with the unicode
  10591. // replacement character. See https://codereview.chromium.org/121173009/ .
  10592. StringDecoder.prototype.write = function(buffer) {
  10593. var charStr = '';
  10594. // if our last write ended with an incomplete multibyte character
  10595. while (this.charLength) {
  10596. // determine how many remaining bytes this buffer has to offer for this char
  10597. var available = (buffer.length >= this.charLength - this.charReceived) ?
  10598. this.charLength - this.charReceived :
  10599. buffer.length;
  10600. // add the new bytes to the char buffer
  10601. buffer.copy(this.charBuffer, this.charReceived, 0, available);
  10602. this.charReceived += available;
  10603. if (this.charReceived < this.charLength) {
  10604. // still not enough chars in this buffer? wait for more ...
  10605. return '';
  10606. }
  10607. // remove bytes belonging to the current character from the buffer
  10608. buffer = buffer.slice(available, buffer.length);
  10609. // get the character that was split
  10610. charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
  10611. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  10612. var charCode = charStr.charCodeAt(charStr.length - 1);
  10613. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  10614. this.charLength += this.surrogateSize;
  10615. charStr = '';
  10616. continue;
  10617. }
  10618. this.charReceived = this.charLength = 0;
  10619. // if there are no more bytes in this buffer, just emit our char
  10620. if (buffer.length === 0) {
  10621. return charStr;
  10622. }
  10623. break;
  10624. }
  10625. // determine and set charLength / charReceived
  10626. this.detectIncompleteChar(buffer);
  10627. var end = buffer.length;
  10628. if (this.charLength) {
  10629. // buffer the incomplete character bytes we got
  10630. buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
  10631. end -= this.charReceived;
  10632. }
  10633. charStr += buffer.toString(this.encoding, 0, end);
  10634. var end = charStr.length - 1;
  10635. var charCode = charStr.charCodeAt(end);
  10636. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  10637. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  10638. var size = this.surrogateSize;
  10639. this.charLength += size;
  10640. this.charReceived += size;
  10641. this.charBuffer.copy(this.charBuffer, size, 0, size);
  10642. buffer.copy(this.charBuffer, 0, 0, size);
  10643. return charStr.substring(0, end);
  10644. }
  10645. // or just emit the charStr
  10646. return charStr;
  10647. };
  10648. // detectIncompleteChar determines if there is an incomplete UTF-8 character at
  10649. // the end of the given buffer. If so, it sets this.charLength to the byte
  10650. // length that character, and sets this.charReceived to the number of bytes
  10651. // that are available for this character.
  10652. StringDecoder.prototype.detectIncompleteChar = function(buffer) {
  10653. // determine how many bytes we have to check at the end of this buffer
  10654. var i = (buffer.length >= 3) ? 3 : buffer.length;
  10655. // Figure out if one of the last i bytes of our buffer announces an
  10656. // incomplete char.
  10657. for (; i > 0; i--) {
  10658. var c = buffer[buffer.length - i];
  10659. // See http://en.wikipedia.org/wiki/UTF-8#Description
  10660. // 110XXXXX
  10661. if (i == 1 && c >> 5 == 0x06) {
  10662. this.charLength = 2;
  10663. break;
  10664. }
  10665. // 1110XXXX
  10666. if (i <= 2 && c >> 4 == 0x0E) {
  10667. this.charLength = 3;
  10668. break;
  10669. }
  10670. // 11110XXX
  10671. if (i <= 3 && c >> 3 == 0x1E) {
  10672. this.charLength = 4;
  10673. break;
  10674. }
  10675. }
  10676. this.charReceived = i;
  10677. };
  10678. StringDecoder.prototype.end = function(buffer) {
  10679. var res = '';
  10680. if (buffer && buffer.length)
  10681. res = this.write(buffer);
  10682. if (this.charReceived) {
  10683. var cr = this.charReceived;
  10684. var buf = this.charBuffer;
  10685. var enc = this.encoding;
  10686. res += buf.slice(0, cr).toString(enc);
  10687. }
  10688. return res;
  10689. };
  10690. function passThroughWrite(buffer) {
  10691. return buffer.toString(this.encoding);
  10692. }
  10693. function utf16DetectIncompleteChar(buffer) {
  10694. this.charReceived = buffer.length % 2;
  10695. this.charLength = this.charReceived ? 2 : 0;
  10696. }
  10697. function base64DetectIncompleteChar(buffer) {
  10698. this.charReceived = buffer.length % 3;
  10699. this.charLength = this.charReceived ? 3 : 0;
  10700. }
  10701. },{"buffer":45}],72:[function(require,module,exports){
  10702. /**
  10703. * Expose `toIsoString`.
  10704. */
  10705. module.exports = toIsoString;
  10706. /**
  10707. * Turn a `date` into an ISO string.
  10708. *
  10709. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
  10710. *
  10711. * @param {Date} date
  10712. * @return {String}
  10713. */
  10714. function toIsoString (date) {
  10715. return date.getUTCFullYear()
  10716. + '-' + pad(date.getUTCMonth() + 1)
  10717. + '-' + pad(date.getUTCDate())
  10718. + 'T' + pad(date.getUTCHours())
  10719. + ':' + pad(date.getUTCMinutes())
  10720. + ':' + pad(date.getUTCSeconds())
  10721. + '.' + String((date.getUTCMilliseconds()/1000).toFixed(3)).slice(2, 5)
  10722. + 'Z';
  10723. }
  10724. /**
  10725. * Pad a `number` with a ten's place zero.
  10726. *
  10727. * @param {Number} number
  10728. * @return {String}
  10729. */
  10730. function pad (number) {
  10731. var n = number.toString();
  10732. return n.length === 1 ? '0' + n : n;
  10733. }
  10734. },{}],73:[function(require,module,exports){
  10735. (function (global){
  10736. /**
  10737. * Module exports.
  10738. */
  10739. module.exports = deprecate;
  10740. /**
  10741. * Mark that a method should not be used.
  10742. * Returns a modified function which warns once by default.
  10743. *
  10744. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  10745. *
  10746. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  10747. * will throw an Error when invoked.
  10748. *
  10749. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  10750. * will invoke `console.trace()` instead of `console.error()`.
  10751. *
  10752. * @param {Function} fn - the function to deprecate
  10753. * @param {String} msg - the string to print to the console when `fn` is invoked
  10754. * @returns {Function} a new "deprecated" version of `fn`
  10755. * @api public
  10756. */
  10757. function deprecate (fn, msg) {
  10758. if (config('noDeprecation')) {
  10759. return fn;
  10760. }
  10761. var warned = false;
  10762. function deprecated() {
  10763. if (!warned) {
  10764. if (config('throwDeprecation')) {
  10765. throw new Error(msg);
  10766. } else if (config('traceDeprecation')) {
  10767. console.trace(msg);
  10768. } else {
  10769. console.warn(msg);
  10770. }
  10771. warned = true;
  10772. }
  10773. return fn.apply(this, arguments);
  10774. }
  10775. return deprecated;
  10776. }
  10777. /**
  10778. * Checks `localStorage` for boolean values for the given `name`.
  10779. *
  10780. * @param {String} name
  10781. * @returns {Boolean}
  10782. * @api private
  10783. */
  10784. function config (name) {
  10785. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  10786. try {
  10787. if (!global.localStorage) return false;
  10788. } catch (_) {
  10789. return false;
  10790. }
  10791. var val = global.localStorage[name];
  10792. if (null == val) return false;
  10793. return String(val).toLowerCase() === 'true';
  10794. }
  10795. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  10796. },{}],74:[function(require,module,exports){
  10797. module.exports = function isBuffer(arg) {
  10798. return arg && typeof arg === 'object'
  10799. && typeof arg.copy === 'function'
  10800. && typeof arg.fill === 'function'
  10801. && typeof arg.readUInt8 === 'function';
  10802. }
  10803. },{}],75:[function(require,module,exports){
  10804. (function (process,global){
  10805. // Copyright Joyent, Inc. and other Node contributors.
  10806. //
  10807. // Permission is hereby granted, free of charge, to any person obtaining a
  10808. // copy of this software and associated documentation files (the
  10809. // "Software"), to deal in the Software without restriction, including
  10810. // without limitation the rights to use, copy, modify, merge, publish,
  10811. // distribute, sublicense, and/or sell copies of the Software, and to permit
  10812. // persons to whom the Software is furnished to do so, subject to the
  10813. // following conditions:
  10814. //
  10815. // The above copyright notice and this permission notice shall be included
  10816. // in all copies or substantial portions of the Software.
  10817. //
  10818. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  10819. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10820. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  10821. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  10822. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  10823. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  10824. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  10825. var formatRegExp = /%[sdj%]/g;
  10826. exports.format = function(f) {
  10827. if (!isString(f)) {
  10828. var objects = [];
  10829. for (var i = 0; i < arguments.length; i++) {
  10830. objects.push(inspect(arguments[i]));
  10831. }
  10832. return objects.join(' ');
  10833. }
  10834. var i = 1;
  10835. var args = arguments;
  10836. var len = args.length;
  10837. var str = String(f).replace(formatRegExp, function(x) {
  10838. if (x === '%%') return '%';
  10839. if (i >= len) return x;
  10840. switch (x) {
  10841. case '%s': return String(args[i++]);
  10842. case '%d': return Number(args[i++]);
  10843. case '%j':
  10844. try {
  10845. return JSON.stringify(args[i++]);
  10846. } catch (_) {
  10847. return '[Circular]';
  10848. }
  10849. default:
  10850. return x;
  10851. }
  10852. });
  10853. for (var x = args[i]; i < len; x = args[++i]) {
  10854. if (isNull(x) || !isObject(x)) {
  10855. str += ' ' + x;
  10856. } else {
  10857. str += ' ' + inspect(x);
  10858. }
  10859. }
  10860. return str;
  10861. };
  10862. // Mark that a method should not be used.
  10863. // Returns a modified function which warns once by default.
  10864. // If --no-deprecation is set, then it is a no-op.
  10865. exports.deprecate = function(fn, msg) {
  10866. // Allow for deprecating things in the process of starting up.
  10867. if (isUndefined(global.process)) {
  10868. return function() {
  10869. return exports.deprecate(fn, msg).apply(this, arguments);
  10870. };
  10871. }
  10872. if (process.noDeprecation === true) {
  10873. return fn;
  10874. }
  10875. var warned = false;
  10876. function deprecated() {
  10877. if (!warned) {
  10878. if (process.throwDeprecation) {
  10879. throw new Error(msg);
  10880. } else if (process.traceDeprecation) {
  10881. console.trace(msg);
  10882. } else {
  10883. console.error(msg);
  10884. }
  10885. warned = true;
  10886. }
  10887. return fn.apply(this, arguments);
  10888. }
  10889. return deprecated;
  10890. };
  10891. var debugs = {};
  10892. var debugEnviron;
  10893. exports.debuglog = function(set) {
  10894. if (isUndefined(debugEnviron))
  10895. debugEnviron = process.env.NODE_DEBUG || '';
  10896. set = set.toUpperCase();
  10897. if (!debugs[set]) {
  10898. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  10899. var pid = process.pid;
  10900. debugs[set] = function() {
  10901. var msg = exports.format.apply(exports, arguments);
  10902. console.error('%s %d: %s', set, pid, msg);
  10903. };
  10904. } else {
  10905. debugs[set] = function() {};
  10906. }
  10907. }
  10908. return debugs[set];
  10909. };
  10910. /**
  10911. * Echos the value of a value. Trys to print the value out
  10912. * in the best way possible given the different types.
  10913. *
  10914. * @param {Object} obj The object to print out.
  10915. * @param {Object} opts Optional options object that alters the output.
  10916. */
  10917. /* legacy: obj, showHidden, depth, colors*/
  10918. function inspect(obj, opts) {
  10919. // default options
  10920. var ctx = {
  10921. seen: [],
  10922. stylize: stylizeNoColor
  10923. };
  10924. // legacy...
  10925. if (arguments.length >= 3) ctx.depth = arguments[2];
  10926. if (arguments.length >= 4) ctx.colors = arguments[3];
  10927. if (isBoolean(opts)) {
  10928. // legacy...
  10929. ctx.showHidden = opts;
  10930. } else if (opts) {
  10931. // got an "options" object
  10932. exports._extend(ctx, opts);
  10933. }
  10934. // set default options
  10935. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  10936. if (isUndefined(ctx.depth)) ctx.depth = 2;
  10937. if (isUndefined(ctx.colors)) ctx.colors = false;
  10938. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  10939. if (ctx.colors) ctx.stylize = stylizeWithColor;
  10940. return formatValue(ctx, obj, ctx.depth);
  10941. }
  10942. exports.inspect = inspect;
  10943. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  10944. inspect.colors = {
  10945. 'bold' : [1, 22],
  10946. 'italic' : [3, 23],
  10947. 'underline' : [4, 24],
  10948. 'inverse' : [7, 27],
  10949. 'white' : [37, 39],
  10950. 'grey' : [90, 39],
  10951. 'black' : [30, 39],
  10952. 'blue' : [34, 39],
  10953. 'cyan' : [36, 39],
  10954. 'green' : [32, 39],
  10955. 'magenta' : [35, 39],
  10956. 'red' : [31, 39],
  10957. 'yellow' : [33, 39]
  10958. };
  10959. // Don't use 'blue' not visible on cmd.exe
  10960. inspect.styles = {
  10961. 'special': 'cyan',
  10962. 'number': 'yellow',
  10963. 'boolean': 'yellow',
  10964. 'undefined': 'grey',
  10965. 'null': 'bold',
  10966. 'string': 'green',
  10967. 'date': 'magenta',
  10968. // "name": intentionally not styling
  10969. 'regexp': 'red'
  10970. };
  10971. function stylizeWithColor(str, styleType) {
  10972. var style = inspect.styles[styleType];
  10973. if (style) {
  10974. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  10975. '\u001b[' + inspect.colors[style][1] + 'm';
  10976. } else {
  10977. return str;
  10978. }
  10979. }
  10980. function stylizeNoColor(str, styleType) {
  10981. return str;
  10982. }
  10983. function arrayToHash(array) {
  10984. var hash = {};
  10985. array.forEach(function(val, idx) {
  10986. hash[val] = true;
  10987. });
  10988. return hash;
  10989. }
  10990. function formatValue(ctx, value, recurseTimes) {
  10991. // Provide a hook for user-specified inspect functions.
  10992. // Check that value is an object with an inspect function on it
  10993. if (ctx.customInspect &&
  10994. value &&
  10995. isFunction(value.inspect) &&
  10996. // Filter out the util module, it's inspect function is special
  10997. value.inspect !== exports.inspect &&
  10998. // Also filter out any prototype objects using the circular check.
  10999. !(value.constructor && value.constructor.prototype === value)) {
  11000. var ret = value.inspect(recurseTimes, ctx);
  11001. if (!isString(ret)) {
  11002. ret = formatValue(ctx, ret, recurseTimes);
  11003. }
  11004. return ret;
  11005. }
  11006. // Primitive types cannot have properties
  11007. var primitive = formatPrimitive(ctx, value);
  11008. if (primitive) {
  11009. return primitive;
  11010. }
  11011. // Look up the keys of the object.
  11012. var keys = Object.keys(value);
  11013. var visibleKeys = arrayToHash(keys);
  11014. if (ctx.showHidden) {
  11015. keys = Object.getOwnPropertyNames(value);
  11016. }
  11017. // IE doesn't make error fields non-enumerable
  11018. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  11019. if (isError(value)
  11020. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  11021. return formatError(value);
  11022. }
  11023. // Some type of object without properties can be shortcutted.
  11024. if (keys.length === 0) {
  11025. if (isFunction(value)) {
  11026. var name = value.name ? ': ' + value.name : '';
  11027. return ctx.stylize('[Function' + name + ']', 'special');
  11028. }
  11029. if (isRegExp(value)) {
  11030. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  11031. }
  11032. if (isDate(value)) {
  11033. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  11034. }
  11035. if (isError(value)) {
  11036. return formatError(value);
  11037. }
  11038. }
  11039. var base = '', array = false, braces = ['{', '}'];
  11040. // Make Array say that they are Array
  11041. if (isArray(value)) {
  11042. array = true;
  11043. braces = ['[', ']'];
  11044. }
  11045. // Make functions say that they are functions
  11046. if (isFunction(value)) {
  11047. var n = value.name ? ': ' + value.name : '';
  11048. base = ' [Function' + n + ']';
  11049. }
  11050. // Make RegExps say that they are RegExps
  11051. if (isRegExp(value)) {
  11052. base = ' ' + RegExp.prototype.toString.call(value);
  11053. }
  11054. // Make dates with properties first say the date
  11055. if (isDate(value)) {
  11056. base = ' ' + Date.prototype.toUTCString.call(value);
  11057. }
  11058. // Make error with message first say the error
  11059. if (isError(value)) {
  11060. base = ' ' + formatError(value);
  11061. }
  11062. if (keys.length === 0 && (!array || value.length == 0)) {
  11063. return braces[0] + base + braces[1];
  11064. }
  11065. if (recurseTimes < 0) {
  11066. if (isRegExp(value)) {
  11067. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  11068. } else {
  11069. return ctx.stylize('[Object]', 'special');
  11070. }
  11071. }
  11072. ctx.seen.push(value);
  11073. var output;
  11074. if (array) {
  11075. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  11076. } else {
  11077. output = keys.map(function(key) {
  11078. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  11079. });
  11080. }
  11081. ctx.seen.pop();
  11082. return reduceToSingleString(output, base, braces);
  11083. }
  11084. function formatPrimitive(ctx, value) {
  11085. if (isUndefined(value))
  11086. return ctx.stylize('undefined', 'undefined');
  11087. if (isString(value)) {
  11088. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  11089. .replace(/'/g, "\\'")
  11090. .replace(/\\"/g, '"') + '\'';
  11091. return ctx.stylize(simple, 'string');
  11092. }
  11093. if (isNumber(value))
  11094. return ctx.stylize('' + value, 'number');
  11095. if (isBoolean(value))
  11096. return ctx.stylize('' + value, 'boolean');
  11097. // For some reason typeof null is "object", so special case here.
  11098. if (isNull(value))
  11099. return ctx.stylize('null', 'null');
  11100. }
  11101. function formatError(value) {
  11102. return '[' + Error.prototype.toString.call(value) + ']';
  11103. }
  11104. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  11105. var output = [];
  11106. for (var i = 0, l = value.length; i < l; ++i) {
  11107. if (hasOwnProperty(value, String(i))) {
  11108. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  11109. String(i), true));
  11110. } else {
  11111. output.push('');
  11112. }
  11113. }
  11114. keys.forEach(function(key) {
  11115. if (!key.match(/^\d+$/)) {
  11116. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  11117. key, true));
  11118. }
  11119. });
  11120. return output;
  11121. }
  11122. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  11123. var name, str, desc;
  11124. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  11125. if (desc.get) {
  11126. if (desc.set) {
  11127. str = ctx.stylize('[Getter/Setter]', 'special');
  11128. } else {
  11129. str = ctx.stylize('[Getter]', 'special');
  11130. }
  11131. } else {
  11132. if (desc.set) {
  11133. str = ctx.stylize('[Setter]', 'special');
  11134. }
  11135. }
  11136. if (!hasOwnProperty(visibleKeys, key)) {
  11137. name = '[' + key + ']';
  11138. }
  11139. if (!str) {
  11140. if (ctx.seen.indexOf(desc.value) < 0) {
  11141. if (isNull(recurseTimes)) {
  11142. str = formatValue(ctx, desc.value, null);
  11143. } else {
  11144. str = formatValue(ctx, desc.value, recurseTimes - 1);
  11145. }
  11146. if (str.indexOf('\n') > -1) {
  11147. if (array) {
  11148. str = str.split('\n').map(function(line) {
  11149. return ' ' + line;
  11150. }).join('\n').substr(2);
  11151. } else {
  11152. str = '\n' + str.split('\n').map(function(line) {
  11153. return ' ' + line;
  11154. }).join('\n');
  11155. }
  11156. }
  11157. } else {
  11158. str = ctx.stylize('[Circular]', 'special');
  11159. }
  11160. }
  11161. if (isUndefined(name)) {
  11162. if (array && key.match(/^\d+$/)) {
  11163. return str;
  11164. }
  11165. name = JSON.stringify('' + key);
  11166. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  11167. name = name.substr(1, name.length - 2);
  11168. name = ctx.stylize(name, 'name');
  11169. } else {
  11170. name = name.replace(/'/g, "\\'")
  11171. .replace(/\\"/g, '"')
  11172. .replace(/(^"|"$)/g, "'");
  11173. name = ctx.stylize(name, 'string');
  11174. }
  11175. }
  11176. return name + ': ' + str;
  11177. }
  11178. function reduceToSingleString(output, base, braces) {
  11179. var numLinesEst = 0;
  11180. var length = output.reduce(function(prev, cur) {
  11181. numLinesEst++;
  11182. if (cur.indexOf('\n') >= 0) numLinesEst++;
  11183. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  11184. }, 0);
  11185. if (length > 60) {
  11186. return braces[0] +
  11187. (base === '' ? '' : base + '\n ') +
  11188. ' ' +
  11189. output.join(',\n ') +
  11190. ' ' +
  11191. braces[1];
  11192. }
  11193. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  11194. }
  11195. // NOTE: These type checking functions intentionally don't use `instanceof`
  11196. // because it is fragile and can be easily faked with `Object.create()`.
  11197. function isArray(ar) {
  11198. return Array.isArray(ar);
  11199. }
  11200. exports.isArray = isArray;
  11201. function isBoolean(arg) {
  11202. return typeof arg === 'boolean';
  11203. }
  11204. exports.isBoolean = isBoolean;
  11205. function isNull(arg) {
  11206. return arg === null;
  11207. }
  11208. exports.isNull = isNull;
  11209. function isNullOrUndefined(arg) {
  11210. return arg == null;
  11211. }
  11212. exports.isNullOrUndefined = isNullOrUndefined;
  11213. function isNumber(arg) {
  11214. return typeof arg === 'number';
  11215. }
  11216. exports.isNumber = isNumber;
  11217. function isString(arg) {
  11218. return typeof arg === 'string';
  11219. }
  11220. exports.isString = isString;
  11221. function isSymbol(arg) {
  11222. return typeof arg === 'symbol';
  11223. }
  11224. exports.isSymbol = isSymbol;
  11225. function isUndefined(arg) {
  11226. return arg === void 0;
  11227. }
  11228. exports.isUndefined = isUndefined;
  11229. function isRegExp(re) {
  11230. return isObject(re) && objectToString(re) === '[object RegExp]';
  11231. }
  11232. exports.isRegExp = isRegExp;
  11233. function isObject(arg) {
  11234. return typeof arg === 'object' && arg !== null;
  11235. }
  11236. exports.isObject = isObject;
  11237. function isDate(d) {
  11238. return isObject(d) && objectToString(d) === '[object Date]';
  11239. }
  11240. exports.isDate = isDate;
  11241. function isError(e) {
  11242. return isObject(e) &&
  11243. (objectToString(e) === '[object Error]' || e instanceof Error);
  11244. }
  11245. exports.isError = isError;
  11246. function isFunction(arg) {
  11247. return typeof arg === 'function';
  11248. }
  11249. exports.isFunction = isFunction;
  11250. function isPrimitive(arg) {
  11251. return arg === null ||
  11252. typeof arg === 'boolean' ||
  11253. typeof arg === 'number' ||
  11254. typeof arg === 'string' ||
  11255. typeof arg === 'symbol' || // ES6 symbol
  11256. typeof arg === 'undefined';
  11257. }
  11258. exports.isPrimitive = isPrimitive;
  11259. exports.isBuffer = require('./support/isBuffer');
  11260. function objectToString(o) {
  11261. return Object.prototype.toString.call(o);
  11262. }
  11263. function pad(n) {
  11264. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  11265. }
  11266. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  11267. 'Oct', 'Nov', 'Dec'];
  11268. // 26 Feb 16:19:34
  11269. function timestamp() {
  11270. var d = new Date();
  11271. var time = [pad(d.getHours()),
  11272. pad(d.getMinutes()),
  11273. pad(d.getSeconds())].join(':');
  11274. return [d.getDate(), months[d.getMonth()], time].join(' ');
  11275. }
  11276. // log is just a thin wrapper to console.log that prepends a timestamp
  11277. exports.log = function() {
  11278. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  11279. };
  11280. /**
  11281. * Inherit the prototype methods from one constructor into another.
  11282. *
  11283. * The Function.prototype.inherits from lang.js rewritten as a standalone
  11284. * function (not on Function.prototype). NOTE: If this file is to be loaded
  11285. * during bootstrapping this function needs to be rewritten using some native
  11286. * functions as prototype setup using normal JavaScript does not work as
  11287. * expected during bootstrapping (see mirror.js in r114903).
  11288. *
  11289. * @param {function} ctor Constructor function which needs to inherit the
  11290. * prototype.
  11291. * @param {function} superCtor Constructor function to inherit prototype from.
  11292. */
  11293. exports.inherits = require('inherits');
  11294. exports._extend = function(origin, add) {
  11295. // Don't do anything if add isn't an object
  11296. if (!add || !isObject(add)) return origin;
  11297. var keys = Object.keys(add);
  11298. var i = keys.length;
  11299. while (i--) {
  11300. origin[keys[i]] = add[keys[i]];
  11301. }
  11302. return origin;
  11303. };
  11304. function hasOwnProperty(obj, prop) {
  11305. return Object.prototype.hasOwnProperty.call(obj, prop);
  11306. }
  11307. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  11308. },{"./support/isBuffer":74,"_process":58,"inherits":53}]},{},[1]);