mocha.js 413 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559
  1. (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. (function (process,global){
  3. 'use strict';
  4. /* eslint no-unused-vars: off */
  5. /* eslint-env commonjs */
  6. /**
  7. * Shim process.stdout.
  8. */
  9. process.stdout = require('browser-stdout')();
  10. var Mocha = require('./lib/mocha');
  11. /**
  12. * Create a Mocha instance.
  13. *
  14. * @return {undefined}
  15. */
  16. var mocha = new Mocha({ reporter: 'html' });
  17. /**
  18. * Save timer references to avoid Sinon interfering (see GH-237).
  19. */
  20. var Date = global.Date;
  21. var setTimeout = global.setTimeout;
  22. var setInterval = global.setInterval;
  23. var clearTimeout = global.clearTimeout;
  24. var clearInterval = global.clearInterval;
  25. var uncaughtExceptionHandlers = [];
  26. var originalOnerrorHandler = global.onerror;
  27. /**
  28. * Remove uncaughtException listener.
  29. * Revert to original onerror handler if previously defined.
  30. */
  31. process.removeListener = function (e, fn) {
  32. if (e === 'uncaughtException') {
  33. if (originalOnerrorHandler) {
  34. global.onerror = originalOnerrorHandler;
  35. } else {
  36. global.onerror = function () {};
  37. }
  38. var i = Mocha.utils.indexOf(uncaughtExceptionHandlers, fn);
  39. if (i !== -1) {
  40. uncaughtExceptionHandlers.splice(i, 1);
  41. }
  42. }
  43. };
  44. /**
  45. * Implements uncaughtException listener.
  46. */
  47. process.on = function (e, fn) {
  48. if (e === 'uncaughtException') {
  49. global.onerror = function (err, url, line) {
  50. fn(new Error(err + ' (' + url + ':' + line + ')'));
  51. return !mocha.allowUncaught;
  52. };
  53. uncaughtExceptionHandlers.push(fn);
  54. }
  55. };
  56. // The BDD UI is registered by default, but no UI will be functional in the
  57. // browser without an explicit call to the overridden `mocha.ui` (see below).
  58. // Ensure that this default UI does not expose its methods to the global scope.
  59. mocha.suite.removeAllListeners('pre-require');
  60. var immediateQueue = [];
  61. var immediateTimeout;
  62. function timeslice () {
  63. var immediateStart = new Date().getTime();
  64. while (immediateQueue.length && (new Date().getTime() - immediateStart) < 100) {
  65. immediateQueue.shift()();
  66. }
  67. if (immediateQueue.length) {
  68. immediateTimeout = setTimeout(timeslice, 0);
  69. } else {
  70. immediateTimeout = null;
  71. }
  72. }
  73. /**
  74. * High-performance override of Runner.immediately.
  75. */
  76. Mocha.Runner.immediately = function (callback) {
  77. immediateQueue.push(callback);
  78. if (!immediateTimeout) {
  79. immediateTimeout = setTimeout(timeslice, 0);
  80. }
  81. };
  82. /**
  83. * Function to allow assertion libraries to throw errors directly into mocha.
  84. * This is useful when running tests in a browser because window.onerror will
  85. * only receive the 'message' attribute of the Error.
  86. */
  87. mocha.throwError = function (err) {
  88. Mocha.utils.forEach(uncaughtExceptionHandlers, function (fn) {
  89. fn(err);
  90. });
  91. throw err;
  92. };
  93. /**
  94. * Override ui to ensure that the ui functions are initialized.
  95. * Normally this would happen in Mocha.prototype.loadFiles.
  96. */
  97. mocha.ui = function (ui) {
  98. Mocha.prototype.ui.call(this, ui);
  99. this.suite.emit('pre-require', global, null, this);
  100. return this;
  101. };
  102. /**
  103. * Setup mocha with the given setting options.
  104. */
  105. mocha.setup = function (opts) {
  106. if (typeof opts === 'string') {
  107. opts = { ui: opts };
  108. }
  109. for (var opt in opts) {
  110. if (opts.hasOwnProperty(opt)) {
  111. this[opt](opts[opt]);
  112. }
  113. }
  114. return this;
  115. };
  116. /**
  117. * Run mocha, returning the Runner.
  118. */
  119. mocha.run = function (fn) {
  120. var options = mocha.options;
  121. mocha.globals('location');
  122. var query = Mocha.utils.parseQuery(global.location.search || '');
  123. if (query.grep) {
  124. mocha.grep(query.grep);
  125. }
  126. if (query.fgrep) {
  127. mocha.fgrep(query.fgrep);
  128. }
  129. if (query.invert) {
  130. mocha.invert();
  131. }
  132. return Mocha.prototype.run.call(mocha, function (err) {
  133. // The DOM Document is not available in Web Workers.
  134. var document = global.document;
  135. if (document && document.getElementById('mocha') && options.noHighlighting !== true) {
  136. Mocha.utils.highlightTags('code');
  137. }
  138. if (fn) {
  139. fn(err);
  140. }
  141. });
  142. };
  143. /**
  144. * Expose the process shim.
  145. * https://github.com/mochajs/mocha/pull/916
  146. */
  147. Mocha.process = process;
  148. /**
  149. * Expose mocha.
  150. */
  151. global.Mocha = Mocha;
  152. global.mocha = mocha;
  153. // this allows test/acceptance/required-tokens.js to pass; thus,
  154. // you can now do `const describe = require('mocha').describe` in a
  155. // browser context (assuming browserification). should fix #880
  156. module.exports = global;
  157. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  158. },{"./lib/mocha":14,"_process":67,"browser-stdout":41}],2:[function(require,module,exports){
  159. 'use strict';
  160. function noop () {}
  161. module.exports = function () {
  162. return noop;
  163. };
  164. },{}],3:[function(require,module,exports){
  165. 'use strict';
  166. /**
  167. * Module exports.
  168. */
  169. exports.EventEmitter = EventEmitter;
  170. /**
  171. * Object#toString reference.
  172. */
  173. var objToString = Object.prototype.toString;
  174. /**
  175. * Check if a value is an array.
  176. *
  177. * @api private
  178. * @param {*} val The value to test.
  179. * @return {boolean} true if the value is an array, otherwise false.
  180. */
  181. function isArray (val) {
  182. return objToString.call(val) === '[object Array]';
  183. }
  184. /**
  185. * Event emitter constructor.
  186. *
  187. * @api public
  188. */
  189. function EventEmitter () {}
  190. /**
  191. * Add a listener.
  192. *
  193. * @api public
  194. * @param {string} name Event name.
  195. * @param {Function} fn Event handler.
  196. * @return {EventEmitter} Emitter instance.
  197. */
  198. EventEmitter.prototype.on = function (name, fn) {
  199. if (!this.$events) {
  200. this.$events = {};
  201. }
  202. if (!this.$events[name]) {
  203. this.$events[name] = fn;
  204. } else if (isArray(this.$events[name])) {
  205. this.$events[name].push(fn);
  206. } else {
  207. this.$events[name] = [this.$events[name], fn];
  208. }
  209. return this;
  210. };
  211. EventEmitter.prototype.addListener = EventEmitter.prototype.on;
  212. /**
  213. * Adds a volatile listener.
  214. *
  215. * @api public
  216. * @param {string} name Event name.
  217. * @param {Function} fn Event handler.
  218. * @return {EventEmitter} Emitter instance.
  219. */
  220. EventEmitter.prototype.once = function (name, fn) {
  221. var self = this;
  222. function on () {
  223. self.removeListener(name, on);
  224. fn.apply(this, arguments);
  225. }
  226. on.listener = fn;
  227. this.on(name, on);
  228. return this;
  229. };
  230. /**
  231. * Remove a listener.
  232. *
  233. * @api public
  234. * @param {string} name Event name.
  235. * @param {Function} fn Event handler.
  236. * @return {EventEmitter} Emitter instance.
  237. */
  238. EventEmitter.prototype.removeListener = function (name, fn) {
  239. if (this.$events && this.$events[name]) {
  240. var list = this.$events[name];
  241. if (isArray(list)) {
  242. var pos = -1;
  243. for (var i = 0, l = list.length; i < l; i++) {
  244. if (list[i] === fn || (list[i].listener && list[i].listener === fn)) {
  245. pos = i;
  246. break;
  247. }
  248. }
  249. if (pos < 0) {
  250. return this;
  251. }
  252. list.splice(pos, 1);
  253. if (!list.length) {
  254. delete this.$events[name];
  255. }
  256. } else if (list === fn || (list.listener && list.listener === fn)) {
  257. delete this.$events[name];
  258. }
  259. }
  260. return this;
  261. };
  262. /**
  263. * Remove all listeners for an event.
  264. *
  265. * @api public
  266. * @param {string} name Event name.
  267. * @return {EventEmitter} Emitter instance.
  268. */
  269. EventEmitter.prototype.removeAllListeners = function (name) {
  270. if (name === undefined) {
  271. this.$events = {};
  272. return this;
  273. }
  274. if (this.$events && this.$events[name]) {
  275. this.$events[name] = null;
  276. }
  277. return this;
  278. };
  279. /**
  280. * Get all listeners for a given event.
  281. *
  282. * @api public
  283. * @param {string} name Event name.
  284. * @return {EventEmitter} Emitter instance.
  285. */
  286. EventEmitter.prototype.listeners = function (name) {
  287. if (!this.$events) {
  288. this.$events = {};
  289. }
  290. if (!this.$events[name]) {
  291. this.$events[name] = [];
  292. }
  293. if (!isArray(this.$events[name])) {
  294. this.$events[name] = [this.$events[name]];
  295. }
  296. return this.$events[name];
  297. };
  298. /**
  299. * Emit an event.
  300. *
  301. * @api public
  302. * @param {string} name Event name.
  303. * @return {boolean} true if at least one handler was invoked, else false.
  304. */
  305. EventEmitter.prototype.emit = function (name) {
  306. if (!this.$events) {
  307. return false;
  308. }
  309. var handler = this.$events[name];
  310. if (!handler) {
  311. return false;
  312. }
  313. var args = Array.prototype.slice.call(arguments, 1);
  314. if (typeof handler === 'function') {
  315. handler.apply(this, args);
  316. } else if (isArray(handler)) {
  317. var listeners = handler.slice();
  318. for (var i = 0, l = listeners.length; i < l; i++) {
  319. listeners[i].apply(this, args);
  320. }
  321. } else {
  322. return false;
  323. }
  324. return true;
  325. };
  326. },{}],4:[function(require,module,exports){
  327. 'use strict';
  328. /**
  329. * Expose `Progress`.
  330. */
  331. module.exports = Progress;
  332. /**
  333. * Initialize a new `Progress` indicator.
  334. */
  335. function Progress () {
  336. this.percent = 0;
  337. this.size(0);
  338. this.fontSize(11);
  339. this.font('helvetica, arial, sans-serif');
  340. }
  341. /**
  342. * Set progress size to `size`.
  343. *
  344. * @api public
  345. * @param {number} size
  346. * @return {Progress} Progress instance.
  347. */
  348. Progress.prototype.size = function (size) {
  349. this._size = size;
  350. return this;
  351. };
  352. /**
  353. * Set text to `text`.
  354. *
  355. * @api public
  356. * @param {string} text
  357. * @return {Progress} Progress instance.
  358. */
  359. Progress.prototype.text = function (text) {
  360. this._text = text;
  361. return this;
  362. };
  363. /**
  364. * Set font size to `size`.
  365. *
  366. * @api public
  367. * @param {number} size
  368. * @return {Progress} Progress instance.
  369. */
  370. Progress.prototype.fontSize = function (size) {
  371. this._fontSize = size;
  372. return this;
  373. };
  374. /**
  375. * Set font to `family`.
  376. *
  377. * @param {string} family
  378. * @return {Progress} Progress instance.
  379. */
  380. Progress.prototype.font = function (family) {
  381. this._font = family;
  382. return this;
  383. };
  384. /**
  385. * Update percentage to `n`.
  386. *
  387. * @param {number} n
  388. * @return {Progress} Progress instance.
  389. */
  390. Progress.prototype.update = function (n) {
  391. this.percent = n;
  392. return this;
  393. };
  394. /**
  395. * Draw on `ctx`.
  396. *
  397. * @param {CanvasRenderingContext2d} ctx
  398. * @return {Progress} Progress instance.
  399. */
  400. Progress.prototype.draw = function (ctx) {
  401. try {
  402. var percent = Math.min(this.percent, 100);
  403. var size = this._size;
  404. var half = size / 2;
  405. var x = half;
  406. var y = half;
  407. var rad = half - 1;
  408. var fontSize = this._fontSize;
  409. ctx.font = fontSize + 'px ' + this._font;
  410. var angle = Math.PI * 2 * (percent / 100);
  411. ctx.clearRect(0, 0, size, size);
  412. // outer circle
  413. ctx.strokeStyle = '#9f9f9f';
  414. ctx.beginPath();
  415. ctx.arc(x, y, rad, 0, angle, false);
  416. ctx.stroke();
  417. // inner circle
  418. ctx.strokeStyle = '#eee';
  419. ctx.beginPath();
  420. ctx.arc(x, y, rad - 1, 0, angle, true);
  421. ctx.stroke();
  422. // text
  423. var text = this._text || (percent | 0) + '%';
  424. var w = ctx.measureText(text).width;
  425. ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1);
  426. } catch (err) {
  427. // don't fail if we can't render progress
  428. }
  429. return this;
  430. };
  431. },{}],5:[function(require,module,exports){
  432. (function (global){
  433. 'use strict';
  434. exports.isatty = function isatty () {
  435. return true;
  436. };
  437. exports.getWindowSize = function getWindowSize () {
  438. if ('innerHeight' in global) {
  439. return [global.innerHeight, global.innerWidth];
  440. }
  441. // In a Web Worker, the DOM Window is not available.
  442. return [640, 480];
  443. };
  444. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  445. },{}],6:[function(require,module,exports){
  446. 'use strict';
  447. /**
  448. * Module dependencies.
  449. */
  450. var JSON = require('json3');
  451. /**
  452. * Expose `Context`.
  453. */
  454. module.exports = Context;
  455. /**
  456. * Initialize a new `Context`.
  457. *
  458. * @api private
  459. */
  460. function Context () {}
  461. /**
  462. * Set or get the context `Runnable` to `runnable`.
  463. *
  464. * @api private
  465. * @param {Runnable} runnable
  466. * @return {Context}
  467. */
  468. Context.prototype.runnable = function (runnable) {
  469. if (!arguments.length) {
  470. return this._runnable;
  471. }
  472. this.test = this._runnable = runnable;
  473. return this;
  474. };
  475. /**
  476. * Set test timeout `ms`.
  477. *
  478. * @api private
  479. * @param {number} ms
  480. * @return {Context} self
  481. */
  482. Context.prototype.timeout = function (ms) {
  483. if (!arguments.length) {
  484. return this.runnable().timeout();
  485. }
  486. this.runnable().timeout(ms);
  487. return this;
  488. };
  489. /**
  490. * Set test timeout `enabled`.
  491. *
  492. * @api private
  493. * @param {boolean} enabled
  494. * @return {Context} self
  495. */
  496. Context.prototype.enableTimeouts = function (enabled) {
  497. this.runnable().enableTimeouts(enabled);
  498. return this;
  499. };
  500. /**
  501. * Set test slowness threshold `ms`.
  502. *
  503. * @api private
  504. * @param {number} ms
  505. * @return {Context} self
  506. */
  507. Context.prototype.slow = function (ms) {
  508. this.runnable().slow(ms);
  509. return this;
  510. };
  511. /**
  512. * Mark a test as skipped.
  513. *
  514. * @api private
  515. * @return {Context} self
  516. */
  517. Context.prototype.skip = function () {
  518. this.runnable().skip();
  519. return this;
  520. };
  521. /**
  522. * Allow a number of retries on failed tests
  523. *
  524. * @api private
  525. * @param {number} n
  526. * @return {Context} self
  527. */
  528. Context.prototype.retries = function (n) {
  529. if (!arguments.length) {
  530. return this.runnable().retries();
  531. }
  532. this.runnable().retries(n);
  533. return this;
  534. };
  535. /**
  536. * Inspect the context void of `._runnable`.
  537. *
  538. * @api private
  539. * @return {string}
  540. */
  541. Context.prototype.inspect = function () {
  542. return JSON.stringify(this, function (key, val) {
  543. return key === 'runnable' || key === 'test' ? undefined : val;
  544. }, 2);
  545. };
  546. },{"json3":54}],7:[function(require,module,exports){
  547. 'use strict';
  548. /**
  549. * Module dependencies.
  550. */
  551. var Runnable = require('./runnable');
  552. var inherits = require('./utils').inherits;
  553. /**
  554. * Expose `Hook`.
  555. */
  556. module.exports = Hook;
  557. /**
  558. * Initialize a new `Hook` with the given `title` and callback `fn`.
  559. *
  560. * @param {String} title
  561. * @param {Function} fn
  562. * @api private
  563. */
  564. function Hook (title, fn) {
  565. Runnable.call(this, title, fn);
  566. this.type = 'hook';
  567. }
  568. /**
  569. * Inherit from `Runnable.prototype`.
  570. */
  571. inherits(Hook, Runnable);
  572. /**
  573. * Get or set the test `err`.
  574. *
  575. * @param {Error} err
  576. * @return {Error}
  577. * @api public
  578. */
  579. Hook.prototype.error = function (err) {
  580. if (!arguments.length) {
  581. err = this._error;
  582. this._error = null;
  583. return err;
  584. }
  585. this._error = err;
  586. };
  587. },{"./runnable":33,"./utils":38}],8:[function(require,module,exports){
  588. 'use strict';
  589. /**
  590. * Module dependencies.
  591. */
  592. var Test = require('../test');
  593. /**
  594. * BDD-style interface:
  595. *
  596. * describe('Array', function() {
  597. * describe('#indexOf()', function() {
  598. * it('should return -1 when not present', function() {
  599. * // ...
  600. * });
  601. *
  602. * it('should return the index when present', function() {
  603. * // ...
  604. * });
  605. * });
  606. * });
  607. *
  608. * @param {Suite} suite Root suite.
  609. */
  610. module.exports = function (suite) {
  611. var suites = [suite];
  612. suite.on('pre-require', function (context, file, mocha) {
  613. var common = require('./common')(suites, context, mocha);
  614. context.before = common.before;
  615. context.after = common.after;
  616. context.beforeEach = common.beforeEach;
  617. context.afterEach = common.afterEach;
  618. context.run = mocha.options.delay && common.runWithSuite(suite);
  619. /**
  620. * Describe a "suite" with the given `title`
  621. * and callback `fn` containing nested suites
  622. * and/or tests.
  623. */
  624. context.describe = context.context = function (title, fn) {
  625. return common.suite.create({
  626. title: title,
  627. file: file,
  628. fn: fn
  629. });
  630. };
  631. /**
  632. * Pending describe.
  633. */
  634. context.xdescribe = context.xcontext = context.describe.skip = function (title, fn) {
  635. return common.suite.skip({
  636. title: title,
  637. file: file,
  638. fn: fn
  639. });
  640. };
  641. /**
  642. * Exclusive suite.
  643. */
  644. context.describe.only = function (title, fn) {
  645. return common.suite.only({
  646. title: title,
  647. file: file,
  648. fn: fn
  649. });
  650. };
  651. /**
  652. * Describe a specification or test-case
  653. * with the given `title` and callback `fn`
  654. * acting as a thunk.
  655. */
  656. context.it = context.specify = function (title, fn) {
  657. var suite = suites[0];
  658. if (suite.isPending()) {
  659. fn = null;
  660. }
  661. var test = new Test(title, fn);
  662. test.file = file;
  663. suite.addTest(test);
  664. return test;
  665. };
  666. /**
  667. * Exclusive test-case.
  668. */
  669. context.it.only = function (title, fn) {
  670. return common.test.only(mocha, context.it(title, fn));
  671. };
  672. /**
  673. * Pending test case.
  674. */
  675. context.xit = context.xspecify = context.it.skip = function (title) {
  676. context.it(title);
  677. };
  678. /**
  679. * Number of attempts to retry.
  680. */
  681. context.it.retries = function (n) {
  682. context.retries(n);
  683. };
  684. });
  685. };
  686. },{"../test":36,"./common":9}],9:[function(require,module,exports){
  687. 'use strict';
  688. var Suite = require('../suite');
  689. /**
  690. * Functions common to more than one interface.
  691. *
  692. * @param {Suite[]} suites
  693. * @param {Context} context
  694. * @param {Mocha} mocha
  695. * @return {Object} An object containing common functions.
  696. */
  697. module.exports = function (suites, context, mocha) {
  698. return {
  699. /**
  700. * This is only present if flag --delay is passed into Mocha. It triggers
  701. * root suite execution.
  702. *
  703. * @param {Suite} suite The root suite.
  704. * @return {Function} A function which runs the root suite
  705. */
  706. runWithSuite: function runWithSuite (suite) {
  707. return function run () {
  708. suite.run();
  709. };
  710. },
  711. /**
  712. * Execute before running tests.
  713. *
  714. * @param {string} name
  715. * @param {Function} fn
  716. */
  717. before: function (name, fn) {
  718. suites[0].beforeAll(name, fn);
  719. },
  720. /**
  721. * Execute after running tests.
  722. *
  723. * @param {string} name
  724. * @param {Function} fn
  725. */
  726. after: function (name, fn) {
  727. suites[0].afterAll(name, fn);
  728. },
  729. /**
  730. * Execute before each test case.
  731. *
  732. * @param {string} name
  733. * @param {Function} fn
  734. */
  735. beforeEach: function (name, fn) {
  736. suites[0].beforeEach(name, fn);
  737. },
  738. /**
  739. * Execute after each test case.
  740. *
  741. * @param {string} name
  742. * @param {Function} fn
  743. */
  744. afterEach: function (name, fn) {
  745. suites[0].afterEach(name, fn);
  746. },
  747. suite: {
  748. /**
  749. * Create an exclusive Suite; convenience function
  750. * See docstring for create() below.
  751. *
  752. * @param {Object} opts
  753. * @returns {Suite}
  754. */
  755. only: function only (opts) {
  756. mocha.options.hasOnly = true;
  757. opts.isOnly = true;
  758. return this.create(opts);
  759. },
  760. /**
  761. * Create a Suite, but skip it; convenience function
  762. * See docstring for create() below.
  763. *
  764. * @param {Object} opts
  765. * @returns {Suite}
  766. */
  767. skip: function skip (opts) {
  768. opts.pending = true;
  769. return this.create(opts);
  770. },
  771. /**
  772. * Creates a suite.
  773. * @param {Object} opts Options
  774. * @param {string} opts.title Title of Suite
  775. * @param {Function} [opts.fn] Suite Function (not always applicable)
  776. * @param {boolean} [opts.pending] Is Suite pending?
  777. * @param {string} [opts.file] Filepath where this Suite resides
  778. * @param {boolean} [opts.isOnly] Is Suite exclusive?
  779. * @returns {Suite}
  780. */
  781. create: function create (opts) {
  782. var suite = Suite.create(suites[0], opts.title);
  783. suite.pending = Boolean(opts.pending);
  784. suite.file = opts.file;
  785. suites.unshift(suite);
  786. if (opts.isOnly) {
  787. suite.parent._onlySuites = suite.parent._onlySuites.concat(suite);
  788. mocha.options.hasOnly = true;
  789. }
  790. if (typeof opts.fn === 'function') {
  791. opts.fn.call(suite);
  792. suites.shift();
  793. } else if (typeof opts.fn === 'undefined' && !suite.pending) {
  794. throw new Error('Suite "' + suite.fullTitle() + '" was defined but no callback was supplied. Supply a callback or explicitly skip the suite.');
  795. }
  796. return suite;
  797. }
  798. },
  799. test: {
  800. /**
  801. * Exclusive test-case.
  802. *
  803. * @param {Object} mocha
  804. * @param {Function} test
  805. * @returns {*}
  806. */
  807. only: function (mocha, test) {
  808. test.parent._onlyTests = test.parent._onlyTests.concat(test);
  809. mocha.options.hasOnly = true;
  810. return test;
  811. },
  812. /**
  813. * Pending test case.
  814. *
  815. * @param {string} title
  816. */
  817. skip: function (title) {
  818. context.test(title);
  819. },
  820. /**
  821. * Number of retry attempts
  822. *
  823. * @param {number} n
  824. */
  825. retries: function (n) {
  826. context.retries(n);
  827. }
  828. }
  829. };
  830. };
  831. },{"../suite":35}],10:[function(require,module,exports){
  832. 'use strict';
  833. /**
  834. * Module dependencies.
  835. */
  836. var Suite = require('../suite');
  837. var Test = require('../test');
  838. /**
  839. * Exports-style (as Node.js module) interface:
  840. *
  841. * exports.Array = {
  842. * '#indexOf()': {
  843. * 'should return -1 when the value is not present': function() {
  844. *
  845. * },
  846. *
  847. * 'should return the correct index when the value is present': function() {
  848. *
  849. * }
  850. * }
  851. * };
  852. *
  853. * @param {Suite} suite Root suite.
  854. */
  855. module.exports = function (suite) {
  856. var suites = [suite];
  857. suite.on('require', visit);
  858. function visit (obj, file) {
  859. var suite;
  860. for (var key in obj) {
  861. if (typeof obj[key] === 'function') {
  862. var fn = obj[key];
  863. switch (key) {
  864. case 'before':
  865. suites[0].beforeAll(fn);
  866. break;
  867. case 'after':
  868. suites[0].afterAll(fn);
  869. break;
  870. case 'beforeEach':
  871. suites[0].beforeEach(fn);
  872. break;
  873. case 'afterEach':
  874. suites[0].afterEach(fn);
  875. break;
  876. default:
  877. var test = new Test(key, fn);
  878. test.file = file;
  879. suites[0].addTest(test);
  880. }
  881. } else {
  882. suite = Suite.create(suites[0], key);
  883. suites.unshift(suite);
  884. visit(obj[key], file);
  885. suites.shift();
  886. }
  887. }
  888. }
  889. };
  890. },{"../suite":35,"../test":36}],11:[function(require,module,exports){
  891. 'use strict';
  892. exports.bdd = require('./bdd');
  893. exports.tdd = require('./tdd');
  894. exports.qunit = require('./qunit');
  895. exports.exports = require('./exports');
  896. },{"./bdd":8,"./exports":10,"./qunit":12,"./tdd":13}],12:[function(require,module,exports){
  897. 'use strict';
  898. /**
  899. * Module dependencies.
  900. */
  901. var Test = require('../test');
  902. /**
  903. * QUnit-style interface:
  904. *
  905. * suite('Array');
  906. *
  907. * test('#length', function() {
  908. * var arr = [1,2,3];
  909. * ok(arr.length == 3);
  910. * });
  911. *
  912. * test('#indexOf()', function() {
  913. * var arr = [1,2,3];
  914. * ok(arr.indexOf(1) == 0);
  915. * ok(arr.indexOf(2) == 1);
  916. * ok(arr.indexOf(3) == 2);
  917. * });
  918. *
  919. * suite('String');
  920. *
  921. * test('#length', function() {
  922. * ok('foo'.length == 3);
  923. * });
  924. *
  925. * @param {Suite} suite Root suite.
  926. */
  927. module.exports = function (suite) {
  928. var suites = [suite];
  929. suite.on('pre-require', function (context, file, mocha) {
  930. var common = require('./common')(suites, context, mocha);
  931. context.before = common.before;
  932. context.after = common.after;
  933. context.beforeEach = common.beforeEach;
  934. context.afterEach = common.afterEach;
  935. context.run = mocha.options.delay && common.runWithSuite(suite);
  936. /**
  937. * Describe a "suite" with the given `title`.
  938. */
  939. context.suite = function (title) {
  940. if (suites.length > 1) {
  941. suites.shift();
  942. }
  943. return common.suite.create({
  944. title: title,
  945. file: file,
  946. fn: false
  947. });
  948. };
  949. /**
  950. * Exclusive Suite.
  951. */
  952. context.suite.only = function (title) {
  953. if (suites.length > 1) {
  954. suites.shift();
  955. }
  956. return common.suite.only({
  957. title: title,
  958. file: file,
  959. fn: false
  960. });
  961. };
  962. /**
  963. * Describe a specification or test-case
  964. * with the given `title` and callback `fn`
  965. * acting as a thunk.
  966. */
  967. context.test = function (title, fn) {
  968. var test = new Test(title, fn);
  969. test.file = file;
  970. suites[0].addTest(test);
  971. return test;
  972. };
  973. /**
  974. * Exclusive test-case.
  975. */
  976. context.test.only = function (title, fn) {
  977. return common.test.only(mocha, context.test(title, fn));
  978. };
  979. context.test.skip = common.test.skip;
  980. context.test.retries = common.test.retries;
  981. });
  982. };
  983. },{"../test":36,"./common":9}],13:[function(require,module,exports){
  984. 'use strict';
  985. /**
  986. * Module dependencies.
  987. */
  988. var Test = require('../test');
  989. /**
  990. * TDD-style interface:
  991. *
  992. * suite('Array', function() {
  993. * suite('#indexOf()', function() {
  994. * suiteSetup(function() {
  995. *
  996. * });
  997. *
  998. * test('should return -1 when not present', function() {
  999. *
  1000. * });
  1001. *
  1002. * test('should return the index when present', function() {
  1003. *
  1004. * });
  1005. *
  1006. * suiteTeardown(function() {
  1007. *
  1008. * });
  1009. * });
  1010. * });
  1011. *
  1012. * @param {Suite} suite Root suite.
  1013. */
  1014. module.exports = function (suite) {
  1015. var suites = [suite];
  1016. suite.on('pre-require', function (context, file, mocha) {
  1017. var common = require('./common')(suites, context, mocha);
  1018. context.setup = common.beforeEach;
  1019. context.teardown = common.afterEach;
  1020. context.suiteSetup = common.before;
  1021. context.suiteTeardown = common.after;
  1022. context.run = mocha.options.delay && common.runWithSuite(suite);
  1023. /**
  1024. * Describe a "suite" with the given `title` and callback `fn` containing
  1025. * nested suites and/or tests.
  1026. */
  1027. context.suite = function (title, fn) {
  1028. return common.suite.create({
  1029. title: title,
  1030. file: file,
  1031. fn: fn
  1032. });
  1033. };
  1034. /**
  1035. * Pending suite.
  1036. */
  1037. context.suite.skip = function (title, fn) {
  1038. return common.suite.skip({
  1039. title: title,
  1040. file: file,
  1041. fn: fn
  1042. });
  1043. };
  1044. /**
  1045. * Exclusive test-case.
  1046. */
  1047. context.suite.only = function (title, fn) {
  1048. return common.suite.only({
  1049. title: title,
  1050. file: file,
  1051. fn: fn
  1052. });
  1053. };
  1054. /**
  1055. * Describe a specification or test-case with the given `title` and
  1056. * callback `fn` acting as a thunk.
  1057. */
  1058. context.test = function (title, fn) {
  1059. var suite = suites[0];
  1060. if (suite.isPending()) {
  1061. fn = null;
  1062. }
  1063. var test = new Test(title, fn);
  1064. test.file = file;
  1065. suite.addTest(test);
  1066. return test;
  1067. };
  1068. /**
  1069. * Exclusive test-case.
  1070. */
  1071. context.test.only = function (title, fn) {
  1072. return common.test.only(mocha, context.test(title, fn));
  1073. };
  1074. context.test.skip = common.test.skip;
  1075. context.test.retries = common.test.retries;
  1076. });
  1077. };
  1078. },{"../test":36,"./common":9}],14:[function(require,module,exports){
  1079. (function (process,global,__dirname){
  1080. 'use strict';
  1081. /*!
  1082. * mocha
  1083. * Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
  1084. * MIT Licensed
  1085. */
  1086. /**
  1087. * Module dependencies.
  1088. */
  1089. var escapeRe = require('escape-string-regexp');
  1090. var path = require('path');
  1091. var reporters = require('./reporters');
  1092. var utils = require('./utils');
  1093. /**
  1094. * Expose `Mocha`.
  1095. */
  1096. exports = module.exports = Mocha;
  1097. /**
  1098. * To require local UIs and reporters when running in node.
  1099. */
  1100. if (!process.browser) {
  1101. var cwd = process.cwd();
  1102. module.paths.push(cwd, path.join(cwd, 'node_modules'));
  1103. }
  1104. /**
  1105. * Expose internals.
  1106. */
  1107. exports.utils = utils;
  1108. exports.interfaces = require('./interfaces');
  1109. exports.reporters = reporters;
  1110. exports.Runnable = require('./runnable');
  1111. exports.Context = require('./context');
  1112. exports.Runner = require('./runner');
  1113. exports.Suite = require('./suite');
  1114. exports.Hook = require('./hook');
  1115. exports.Test = require('./test');
  1116. /**
  1117. * Return image `name` path.
  1118. *
  1119. * @api private
  1120. * @param {string} name
  1121. * @return {string}
  1122. */
  1123. function image (name) {
  1124. return path.join(__dirname, '../images', name + '.png');
  1125. }
  1126. /**
  1127. * Set up mocha with `options`.
  1128. *
  1129. * Options:
  1130. *
  1131. * - `ui` name "bdd", "tdd", "exports" etc
  1132. * - `reporter` reporter instance, defaults to `mocha.reporters.spec`
  1133. * - `globals` array of accepted globals
  1134. * - `timeout` timeout in milliseconds
  1135. * - `retries` number of times to retry failed tests
  1136. * - `bail` bail on the first test failure
  1137. * - `slow` milliseconds to wait before considering a test slow
  1138. * - `ignoreLeaks` ignore global leaks
  1139. * - `fullTrace` display the full stack-trace on failing
  1140. * - `grep` string or regexp to filter tests with
  1141. *
  1142. * @param {Object} options
  1143. * @api public
  1144. */
  1145. function Mocha (options) {
  1146. options = options || {};
  1147. this.files = [];
  1148. this.options = options;
  1149. if (options.grep) {
  1150. this.grep(new RegExp(options.grep));
  1151. }
  1152. if (options.fgrep) {
  1153. this.fgrep(options.fgrep);
  1154. }
  1155. this.suite = new exports.Suite('', new exports.Context());
  1156. this.ui(options.ui);
  1157. this.bail(options.bail);
  1158. this.reporter(options.reporter, options.reporterOptions);
  1159. if (typeof options.timeout !== 'undefined' && options.timeout !== null) {
  1160. this.timeout(options.timeout);
  1161. }
  1162. if (typeof options.retries !== 'undefined' && options.retries !== null) {
  1163. this.retries(options.retries);
  1164. }
  1165. this.useColors(options.useColors);
  1166. if (options.enableTimeouts !== null) {
  1167. this.enableTimeouts(options.enableTimeouts);
  1168. }
  1169. if (options.slow) {
  1170. this.slow(options.slow);
  1171. }
  1172. }
  1173. /**
  1174. * Enable or disable bailing on the first failure.
  1175. *
  1176. * @api public
  1177. * @param {boolean} [bail]
  1178. */
  1179. Mocha.prototype.bail = function (bail) {
  1180. if (!arguments.length) {
  1181. bail = true;
  1182. }
  1183. this.suite.bail(bail);
  1184. return this;
  1185. };
  1186. /**
  1187. * Add test `file`.
  1188. *
  1189. * @api public
  1190. * @param {string} file
  1191. */
  1192. Mocha.prototype.addFile = function (file) {
  1193. this.files.push(file);
  1194. return this;
  1195. };
  1196. /**
  1197. * Set reporter to `reporter`, defaults to "spec".
  1198. *
  1199. * @param {String|Function} reporter name or constructor
  1200. * @param {Object} reporterOptions optional options
  1201. * @api public
  1202. * @param {string|Function} reporter name or constructor
  1203. * @param {Object} reporterOptions optional options
  1204. */
  1205. Mocha.prototype.reporter = function (reporter, reporterOptions) {
  1206. if (typeof reporter === 'function') {
  1207. this._reporter = reporter;
  1208. } else {
  1209. reporter = reporter || 'spec';
  1210. var _reporter;
  1211. // Try to load a built-in reporter.
  1212. if (reporters[reporter]) {
  1213. _reporter = reporters[reporter];
  1214. }
  1215. // Try to load reporters from process.cwd() and node_modules
  1216. if (!_reporter) {
  1217. try {
  1218. _reporter = require(reporter);
  1219. } catch (err) {
  1220. err.message.indexOf('Cannot find module') !== -1
  1221. ? console.warn('"' + reporter + '" reporter not found')
  1222. : console.warn('"' + reporter + '" reporter blew up with error:\n' + err.stack);
  1223. }
  1224. }
  1225. if (!_reporter && reporter === 'teamcity') {
  1226. console.warn('The Teamcity reporter was moved to a package named ' +
  1227. 'mocha-teamcity-reporter ' +
  1228. '(https://npmjs.org/package/mocha-teamcity-reporter).');
  1229. }
  1230. if (!_reporter) {
  1231. throw new Error('invalid reporter "' + reporter + '"');
  1232. }
  1233. this._reporter = _reporter;
  1234. }
  1235. this.options.reporterOptions = reporterOptions;
  1236. return this;
  1237. };
  1238. /**
  1239. * Set test UI `name`, defaults to "bdd".
  1240. *
  1241. * @api public
  1242. * @param {string} bdd
  1243. */
  1244. Mocha.prototype.ui = function (name) {
  1245. name = name || 'bdd';
  1246. this._ui = exports.interfaces[name];
  1247. if (!this._ui) {
  1248. try {
  1249. this._ui = require(name);
  1250. } catch (err) {
  1251. throw new Error('invalid interface "' + name + '"');
  1252. }
  1253. }
  1254. this._ui = this._ui(this.suite);
  1255. this.suite.on('pre-require', function (context) {
  1256. exports.afterEach = context.afterEach || context.teardown;
  1257. exports.after = context.after || context.suiteTeardown;
  1258. exports.beforeEach = context.beforeEach || context.setup;
  1259. exports.before = context.before || context.suiteSetup;
  1260. exports.describe = context.describe || context.suite;
  1261. exports.it = context.it || context.test;
  1262. exports.setup = context.setup || context.beforeEach;
  1263. exports.suiteSetup = context.suiteSetup || context.before;
  1264. exports.suiteTeardown = context.suiteTeardown || context.after;
  1265. exports.suite = context.suite || context.describe;
  1266. exports.teardown = context.teardown || context.afterEach;
  1267. exports.test = context.test || context.it;
  1268. exports.run = context.run;
  1269. });
  1270. return this;
  1271. };
  1272. /**
  1273. * Load registered files.
  1274. *
  1275. * @api private
  1276. */
  1277. Mocha.prototype.loadFiles = function (fn) {
  1278. var self = this;
  1279. var suite = this.suite;
  1280. this.files.forEach(function (file) {
  1281. file = path.resolve(file);
  1282. suite.emit('pre-require', global, file, self);
  1283. suite.emit('require', require(file), file, self);
  1284. suite.emit('post-require', global, file, self);
  1285. });
  1286. fn && fn();
  1287. };
  1288. /**
  1289. * Enable growl support.
  1290. *
  1291. * @api private
  1292. */
  1293. Mocha.prototype._growl = function (runner, reporter) {
  1294. var notify = require('growl');
  1295. runner.on('end', function () {
  1296. var stats = reporter.stats;
  1297. if (stats.failures) {
  1298. var msg = stats.failures + ' of ' + runner.total + ' tests failed';
  1299. notify(msg, { name: 'mocha', title: 'Failed', image: image('error') });
  1300. } else {
  1301. notify(stats.passes + ' tests passed in ' + stats.duration + 'ms', {
  1302. name: 'mocha',
  1303. title: 'Passed',
  1304. image: image('ok')
  1305. });
  1306. }
  1307. });
  1308. };
  1309. /**
  1310. * Escape string and add it to grep as a regexp.
  1311. *
  1312. * @api public
  1313. * @param str
  1314. * @returns {Mocha}
  1315. */
  1316. Mocha.prototype.fgrep = function (str) {
  1317. return this.grep(new RegExp(escapeRe(str)));
  1318. };
  1319. /**
  1320. * Add regexp to grep, if `re` is a string it is escaped.
  1321. *
  1322. * @param {RegExp|String} re
  1323. * @return {Mocha}
  1324. * @api public
  1325. * @param {RegExp|string} re
  1326. * @return {Mocha}
  1327. */
  1328. Mocha.prototype.grep = function (re) {
  1329. if (utils.isString(re)) {
  1330. // extract args if it's regex-like, i.e: [string, pattern, flag]
  1331. var arg = re.match(/^\/(.*)\/(g|i|)$|.*/);
  1332. this.options.grep = new RegExp(arg[1] || arg[0], arg[2]);
  1333. } else {
  1334. this.options.grep = re;
  1335. }
  1336. return this;
  1337. };
  1338. /**
  1339. * Invert `.grep()` matches.
  1340. *
  1341. * @return {Mocha}
  1342. * @api public
  1343. */
  1344. Mocha.prototype.invert = function () {
  1345. this.options.invert = true;
  1346. return this;
  1347. };
  1348. /**
  1349. * Ignore global leaks.
  1350. *
  1351. * @param {Boolean} ignore
  1352. * @return {Mocha}
  1353. * @api public
  1354. * @param {boolean} ignore
  1355. * @return {Mocha}
  1356. */
  1357. Mocha.prototype.ignoreLeaks = function (ignore) {
  1358. this.options.ignoreLeaks = Boolean(ignore);
  1359. return this;
  1360. };
  1361. /**
  1362. * Enable global leak checking.
  1363. *
  1364. * @return {Mocha}
  1365. * @api public
  1366. */
  1367. Mocha.prototype.checkLeaks = function () {
  1368. this.options.ignoreLeaks = false;
  1369. return this;
  1370. };
  1371. /**
  1372. * Display long stack-trace on failing
  1373. *
  1374. * @return {Mocha}
  1375. * @api public
  1376. */
  1377. Mocha.prototype.fullTrace = function () {
  1378. this.options.fullStackTrace = true;
  1379. return this;
  1380. };
  1381. /**
  1382. * Enable growl support.
  1383. *
  1384. * @return {Mocha}
  1385. * @api public
  1386. */
  1387. Mocha.prototype.growl = function () {
  1388. this.options.growl = true;
  1389. return this;
  1390. };
  1391. /**
  1392. * Ignore `globals` array or string.
  1393. *
  1394. * @param {Array|String} globals
  1395. * @return {Mocha}
  1396. * @api public
  1397. * @param {Array|string} globals
  1398. * @return {Mocha}
  1399. */
  1400. Mocha.prototype.globals = function (globals) {
  1401. this.options.globals = (this.options.globals || []).concat(globals);
  1402. return this;
  1403. };
  1404. /**
  1405. * Emit color output.
  1406. *
  1407. * @param {Boolean} colors
  1408. * @return {Mocha}
  1409. * @api public
  1410. * @param {boolean} colors
  1411. * @return {Mocha}
  1412. */
  1413. Mocha.prototype.useColors = function (colors) {
  1414. if (colors !== undefined) {
  1415. this.options.useColors = colors;
  1416. }
  1417. return this;
  1418. };
  1419. /**
  1420. * Use inline diffs rather than +/-.
  1421. *
  1422. * @param {Boolean} inlineDiffs
  1423. * @return {Mocha}
  1424. * @api public
  1425. * @param {boolean} inlineDiffs
  1426. * @return {Mocha}
  1427. */
  1428. Mocha.prototype.useInlineDiffs = function (inlineDiffs) {
  1429. this.options.useInlineDiffs = inlineDiffs !== undefined && inlineDiffs;
  1430. return this;
  1431. };
  1432. /**
  1433. * Set the timeout in milliseconds.
  1434. *
  1435. * @param {Number} timeout
  1436. * @return {Mocha}
  1437. * @api public
  1438. * @param {number} timeout
  1439. * @return {Mocha}
  1440. */
  1441. Mocha.prototype.timeout = function (timeout) {
  1442. this.suite.timeout(timeout);
  1443. return this;
  1444. };
  1445. /**
  1446. * Set the number of times to retry failed tests.
  1447. *
  1448. * @param {Number} retry times
  1449. * @return {Mocha}
  1450. * @api public
  1451. */
  1452. Mocha.prototype.retries = function (n) {
  1453. this.suite.retries(n);
  1454. return this;
  1455. };
  1456. /**
  1457. * Set slowness threshold in milliseconds.
  1458. *
  1459. * @param {Number} slow
  1460. * @return {Mocha}
  1461. * @api public
  1462. * @param {number} slow
  1463. * @return {Mocha}
  1464. */
  1465. Mocha.prototype.slow = function (slow) {
  1466. this.suite.slow(slow);
  1467. return this;
  1468. };
  1469. /**
  1470. * Enable timeouts.
  1471. *
  1472. * @param {Boolean} enabled
  1473. * @return {Mocha}
  1474. * @api public
  1475. * @param {boolean} enabled
  1476. * @return {Mocha}
  1477. */
  1478. Mocha.prototype.enableTimeouts = function (enabled) {
  1479. this.suite.enableTimeouts(arguments.length && enabled !== undefined ? enabled : true);
  1480. return this;
  1481. };
  1482. /**
  1483. * Makes all tests async (accepting a callback)
  1484. *
  1485. * @return {Mocha}
  1486. * @api public
  1487. */
  1488. Mocha.prototype.asyncOnly = function () {
  1489. this.options.asyncOnly = true;
  1490. return this;
  1491. };
  1492. /**
  1493. * Disable syntax highlighting (in browser).
  1494. *
  1495. * @api public
  1496. */
  1497. Mocha.prototype.noHighlighting = function () {
  1498. this.options.noHighlighting = true;
  1499. return this;
  1500. };
  1501. /**
  1502. * Enable uncaught errors to propagate (in browser).
  1503. *
  1504. * @return {Mocha}
  1505. * @api public
  1506. */
  1507. Mocha.prototype.allowUncaught = function () {
  1508. this.options.allowUncaught = true;
  1509. return this;
  1510. };
  1511. /**
  1512. * Delay root suite execution.
  1513. * @returns {Mocha}
  1514. */
  1515. Mocha.prototype.delay = function delay () {
  1516. this.options.delay = true;
  1517. return this;
  1518. };
  1519. /**
  1520. * Run tests and invoke `fn()` when complete.
  1521. *
  1522. * @api public
  1523. * @param {Function} fn
  1524. * @return {Runner}
  1525. */
  1526. Mocha.prototype.run = function (fn) {
  1527. if (this.files.length) {
  1528. this.loadFiles();
  1529. }
  1530. var suite = this.suite;
  1531. var options = this.options;
  1532. options.files = this.files;
  1533. var runner = new exports.Runner(suite, options.delay);
  1534. var reporter = new this._reporter(runner, options);
  1535. runner.ignoreLeaks = options.ignoreLeaks !== false;
  1536. runner.fullStackTrace = options.fullStackTrace;
  1537. runner.hasOnly = options.hasOnly;
  1538. runner.asyncOnly = options.asyncOnly;
  1539. runner.allowUncaught = options.allowUncaught;
  1540. if (options.grep) {
  1541. runner.grep(options.grep, options.invert);
  1542. }
  1543. if (options.globals) {
  1544. runner.globals(options.globals);
  1545. }
  1546. if (options.growl) {
  1547. this._growl(runner, reporter);
  1548. }
  1549. if (options.useColors !== undefined) {
  1550. exports.reporters.Base.useColors = options.useColors;
  1551. }
  1552. exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
  1553. function done (failures) {
  1554. if (reporter.done) {
  1555. reporter.done(failures, fn);
  1556. } else {
  1557. fn && fn(failures);
  1558. }
  1559. }
  1560. return runner.run(done);
  1561. };
  1562. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},"/lib")
  1563. },{"./context":6,"./hook":7,"./interfaces":11,"./reporters":21,"./runnable":33,"./runner":34,"./suite":35,"./test":36,"./utils":38,"_process":67,"escape-string-regexp":47,"growl":49,"path":42}],15:[function(require,module,exports){
  1564. 'use strict';
  1565. /**
  1566. * Helpers.
  1567. */
  1568. var s = 1000;
  1569. var m = s * 60;
  1570. var h = m * 60;
  1571. var d = h * 24;
  1572. var y = d * 365.25;
  1573. /**
  1574. * Parse or format the given `val`.
  1575. *
  1576. * Options:
  1577. *
  1578. * - `long` verbose formatting [false]
  1579. *
  1580. * @api public
  1581. * @param {string|number} val
  1582. * @param {Object} options
  1583. * @return {string|number}
  1584. */
  1585. module.exports = function (val, options) {
  1586. options = options || {};
  1587. if (typeof val === 'string') {
  1588. return parse(val);
  1589. }
  1590. // https://github.com/mochajs/mocha/pull/1035
  1591. return options['long'] ? longFormat(val) : shortFormat(val);
  1592. };
  1593. /**
  1594. * Parse the given `str` and return milliseconds.
  1595. *
  1596. * @api private
  1597. * @param {string} str
  1598. * @return {number}
  1599. */
  1600. function parse (str) {
  1601. var match = (/^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i).exec(str);
  1602. if (!match) {
  1603. return;
  1604. }
  1605. var n = parseFloat(match[1]);
  1606. var type = (match[2] || 'ms').toLowerCase();
  1607. switch (type) {
  1608. case 'years':
  1609. case 'year':
  1610. case 'y':
  1611. return n * y;
  1612. case 'days':
  1613. case 'day':
  1614. case 'd':
  1615. return n * d;
  1616. case 'hours':
  1617. case 'hour':
  1618. case 'h':
  1619. return n * h;
  1620. case 'minutes':
  1621. case 'minute':
  1622. case 'm':
  1623. return n * m;
  1624. case 'seconds':
  1625. case 'second':
  1626. case 's':
  1627. return n * s;
  1628. case 'ms':
  1629. return n;
  1630. default:
  1631. // No default case
  1632. }
  1633. }
  1634. /**
  1635. * Short format for `ms`.
  1636. *
  1637. * @api private
  1638. * @param {number} ms
  1639. * @return {string}
  1640. */
  1641. function shortFormat (ms) {
  1642. if (ms >= d) {
  1643. return Math.round(ms / d) + 'd';
  1644. }
  1645. if (ms >= h) {
  1646. return Math.round(ms / h) + 'h';
  1647. }
  1648. if (ms >= m) {
  1649. return Math.round(ms / m) + 'm';
  1650. }
  1651. if (ms >= s) {
  1652. return Math.round(ms / s) + 's';
  1653. }
  1654. return ms + 'ms';
  1655. }
  1656. /**
  1657. * Long format for `ms`.
  1658. *
  1659. * @api private
  1660. * @param {number} ms
  1661. * @return {string}
  1662. */
  1663. function longFormat (ms) {
  1664. return plural(ms, d, 'day') ||
  1665. plural(ms, h, 'hour') ||
  1666. plural(ms, m, 'minute') ||
  1667. plural(ms, s, 'second') ||
  1668. ms + ' ms';
  1669. }
  1670. /**
  1671. * Pluralization helper.
  1672. *
  1673. * @api private
  1674. * @param {number} ms
  1675. * @param {number} n
  1676. * @param {string} name
  1677. */
  1678. function plural (ms, n, name) {
  1679. if (ms < n) {
  1680. return;
  1681. }
  1682. if (ms < n * 1.5) {
  1683. return Math.floor(ms / n) + ' ' + name;
  1684. }
  1685. return Math.ceil(ms / n) + ' ' + name + 's';
  1686. }
  1687. },{}],16:[function(require,module,exports){
  1688. 'use strict';
  1689. /**
  1690. * Expose `Pending`.
  1691. */
  1692. module.exports = Pending;
  1693. /**
  1694. * Initialize a new `Pending` error with the given message.
  1695. *
  1696. * @param {string} message
  1697. */
  1698. function Pending (message) {
  1699. this.message = message;
  1700. }
  1701. },{}],17:[function(require,module,exports){
  1702. (function (process,global){
  1703. 'use strict';
  1704. /**
  1705. * Module dependencies.
  1706. */
  1707. var tty = require('tty');
  1708. var diff = require('diff');
  1709. var ms = require('../ms');
  1710. var utils = require('../utils');
  1711. var supportsColor = process.browser ? null : require('supports-color');
  1712. /**
  1713. * Expose `Base`.
  1714. */
  1715. exports = module.exports = Base;
  1716. /**
  1717. * Save timer references to avoid Sinon interfering.
  1718. * See: https://github.com/mochajs/mocha/issues/237
  1719. */
  1720. /* eslint-disable no-unused-vars, no-native-reassign */
  1721. var Date = global.Date;
  1722. var setTimeout = global.setTimeout;
  1723. var setInterval = global.setInterval;
  1724. var clearTimeout = global.clearTimeout;
  1725. var clearInterval = global.clearInterval;
  1726. /* eslint-enable no-unused-vars, no-native-reassign */
  1727. /**
  1728. * Check if both stdio streams are associated with a tty.
  1729. */
  1730. var isatty = tty.isatty(1) && tty.isatty(2);
  1731. /**
  1732. * Enable coloring by default, except in the browser interface.
  1733. */
  1734. exports.useColors = !process.browser && (supportsColor || (process.env.MOCHA_COLORS !== undefined));
  1735. /**
  1736. * Inline diffs instead of +/-
  1737. */
  1738. exports.inlineDiffs = false;
  1739. /**
  1740. * Default color map.
  1741. */
  1742. exports.colors = {
  1743. pass: 90,
  1744. fail: 31,
  1745. 'bright pass': 92,
  1746. 'bright fail': 91,
  1747. 'bright yellow': 93,
  1748. pending: 36,
  1749. suite: 0,
  1750. 'error title': 0,
  1751. 'error message': 31,
  1752. 'error stack': 90,
  1753. checkmark: 32,
  1754. fast: 90,
  1755. medium: 33,
  1756. slow: 31,
  1757. green: 32,
  1758. light: 90,
  1759. 'diff gutter': 90,
  1760. 'diff added': 32,
  1761. 'diff removed': 31
  1762. };
  1763. /**
  1764. * Default symbol map.
  1765. */
  1766. exports.symbols = {
  1767. ok: '✓',
  1768. err: '✖',
  1769. dot: '․',
  1770. comma: ',',
  1771. bang: '!'
  1772. };
  1773. // With node.js on Windows: use symbols available in terminal default fonts
  1774. if (process.platform === 'win32') {
  1775. exports.symbols.ok = '\u221A';
  1776. exports.symbols.err = '\u00D7';
  1777. exports.symbols.dot = '.';
  1778. }
  1779. /**
  1780. * Color `str` with the given `type`,
  1781. * allowing colors to be disabled,
  1782. * as well as user-defined color
  1783. * schemes.
  1784. *
  1785. * @param {string} type
  1786. * @param {string} str
  1787. * @return {string}
  1788. * @api private
  1789. */
  1790. var color = exports.color = function (type, str) {
  1791. if (!exports.useColors) {
  1792. return String(str);
  1793. }
  1794. return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
  1795. };
  1796. /**
  1797. * Expose term window size, with some defaults for when stderr is not a tty.
  1798. */
  1799. exports.window = {
  1800. width: 75
  1801. };
  1802. if (isatty) {
  1803. exports.window.width = process.stdout.getWindowSize
  1804. ? process.stdout.getWindowSize(1)[0]
  1805. : tty.getWindowSize()[1];
  1806. }
  1807. /**
  1808. * Expose some basic cursor interactions that are common among reporters.
  1809. */
  1810. exports.cursor = {
  1811. hide: function () {
  1812. isatty && process.stdout.write('\u001b[?25l');
  1813. },
  1814. show: function () {
  1815. isatty && process.stdout.write('\u001b[?25h');
  1816. },
  1817. deleteLine: function () {
  1818. isatty && process.stdout.write('\u001b[2K');
  1819. },
  1820. beginningOfLine: function () {
  1821. isatty && process.stdout.write('\u001b[0G');
  1822. },
  1823. CR: function () {
  1824. if (isatty) {
  1825. exports.cursor.deleteLine();
  1826. exports.cursor.beginningOfLine();
  1827. } else {
  1828. process.stdout.write('\r');
  1829. }
  1830. }
  1831. };
  1832. /**
  1833. * Outut the given `failures` as a list.
  1834. *
  1835. * @param {Array} failures
  1836. * @api public
  1837. */
  1838. exports.list = function (failures) {
  1839. console.log();
  1840. failures.forEach(function (test, i) {
  1841. // format
  1842. var fmt = color('error title', ' %s) %s:\n') +
  1843. color('error message', ' %s') +
  1844. color('error stack', '\n%s\n');
  1845. // msg
  1846. var msg;
  1847. var err = test.err;
  1848. var message;
  1849. if (err.message && typeof err.message.toString === 'function') {
  1850. message = err.message + '';
  1851. } else if (typeof err.inspect === 'function') {
  1852. message = err.inspect() + '';
  1853. } else {
  1854. message = '';
  1855. }
  1856. var stack = err.stack || message;
  1857. var index = message ? stack.indexOf(message) : -1;
  1858. var actual = err.actual;
  1859. var expected = err.expected;
  1860. var escape = true;
  1861. if (index === -1) {
  1862. msg = message;
  1863. } else {
  1864. index += message.length;
  1865. msg = stack.slice(0, index);
  1866. // remove msg from stack
  1867. stack = stack.slice(index + 1);
  1868. }
  1869. // uncaught
  1870. if (err.uncaught) {
  1871. msg = 'Uncaught ' + msg;
  1872. }
  1873. // explicitly show diff
  1874. if (err.showDiff !== false && sameType(actual, expected) && expected !== undefined) {
  1875. escape = false;
  1876. if (!(utils.isString(actual) && utils.isString(expected))) {
  1877. err.actual = actual = utils.stringify(actual);
  1878. err.expected = expected = utils.stringify(expected);
  1879. }
  1880. fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
  1881. var match = message.match(/^([^:]+): expected/);
  1882. msg = '\n ' + color('error message', match ? match[1] : msg);
  1883. if (exports.inlineDiffs) {
  1884. msg += inlineDiff(err, escape);
  1885. } else {
  1886. msg += unifiedDiff(err, escape);
  1887. }
  1888. }
  1889. // indent stack trace
  1890. stack = stack.replace(/^/gm, ' ');
  1891. console.log(fmt, (i + 1), test.fullTitle(), msg, stack);
  1892. });
  1893. };
  1894. /**
  1895. * Initialize a new `Base` reporter.
  1896. *
  1897. * All other reporters generally
  1898. * inherit from this reporter, providing
  1899. * stats such as test duration, number
  1900. * of tests passed / failed etc.
  1901. *
  1902. * @param {Runner} runner
  1903. * @api public
  1904. */
  1905. function Base (runner) {
  1906. var stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 };
  1907. var failures = this.failures = [];
  1908. if (!runner) {
  1909. return;
  1910. }
  1911. this.runner = runner;
  1912. runner.stats = stats;
  1913. runner.on('start', function () {
  1914. stats.start = new Date();
  1915. });
  1916. runner.on('suite', function (suite) {
  1917. stats.suites = stats.suites || 0;
  1918. suite.root || stats.suites++;
  1919. });
  1920. runner.on('test end', function () {
  1921. stats.tests = stats.tests || 0;
  1922. stats.tests++;
  1923. });
  1924. runner.on('pass', function (test) {
  1925. stats.passes = stats.passes || 0;
  1926. if (test.duration > test.slow()) {
  1927. test.speed = 'slow';
  1928. } else if (test.duration > test.slow() / 2) {
  1929. test.speed = 'medium';
  1930. } else {
  1931. test.speed = 'fast';
  1932. }
  1933. stats.passes++;
  1934. });
  1935. runner.on('fail', function (test, err) {
  1936. stats.failures = stats.failures || 0;
  1937. stats.failures++;
  1938. test.err = err;
  1939. failures.push(test);
  1940. });
  1941. runner.on('end', function () {
  1942. stats.end = new Date();
  1943. stats.duration = new Date() - stats.start;
  1944. });
  1945. runner.on('pending', function () {
  1946. stats.pending++;
  1947. });
  1948. }
  1949. /**
  1950. * Output common epilogue used by many of
  1951. * the bundled reporters.
  1952. *
  1953. * @api public
  1954. */
  1955. Base.prototype.epilogue = function () {
  1956. var stats = this.stats;
  1957. var fmt;
  1958. console.log();
  1959. // passes
  1960. fmt = color('bright pass', ' ') +
  1961. color('green', ' %d passing') +
  1962. color('light', ' (%s)');
  1963. console.log(fmt,
  1964. stats.passes || 0,
  1965. ms(stats.duration));
  1966. // pending
  1967. if (stats.pending) {
  1968. fmt = color('pending', ' ') +
  1969. color('pending', ' %d pending');
  1970. console.log(fmt, stats.pending);
  1971. }
  1972. // failures
  1973. if (stats.failures) {
  1974. fmt = color('fail', ' %d failing');
  1975. console.log(fmt, stats.failures);
  1976. Base.list(this.failures);
  1977. console.log();
  1978. }
  1979. console.log();
  1980. };
  1981. /**
  1982. * Pad the given `str` to `len`.
  1983. *
  1984. * @api private
  1985. * @param {string} str
  1986. * @param {string} len
  1987. * @return {string}
  1988. */
  1989. function pad (str, len) {
  1990. str = String(str);
  1991. return Array(len - str.length + 1).join(' ') + str;
  1992. }
  1993. /**
  1994. * Returns an inline diff between 2 strings with coloured ANSI output
  1995. *
  1996. * @api private
  1997. * @param {Error} err with actual/expected
  1998. * @param {boolean} escape
  1999. * @return {string} Diff
  2000. */
  2001. function inlineDiff (err, escape) {
  2002. var msg = errorDiff(err, 'WordsWithSpace', escape);
  2003. // linenos
  2004. var lines = msg.split('\n');
  2005. if (lines.length > 4) {
  2006. var width = String(lines.length).length;
  2007. msg = lines.map(function (str, i) {
  2008. return pad(++i, width) + ' |' + ' ' + str;
  2009. }).join('\n');
  2010. }
  2011. // legend
  2012. msg = '\n' +
  2013. color('diff removed', 'actual') +
  2014. ' ' +
  2015. color('diff added', 'expected') +
  2016. '\n\n' +
  2017. msg +
  2018. '\n';
  2019. // indent
  2020. msg = msg.replace(/^/gm, ' ');
  2021. return msg;
  2022. }
  2023. /**
  2024. * Returns a unified diff between two strings.
  2025. *
  2026. * @api private
  2027. * @param {Error} err with actual/expected
  2028. * @param {boolean} escape
  2029. * @return {string} The diff.
  2030. */
  2031. function unifiedDiff (err, escape) {
  2032. var indent = ' ';
  2033. function cleanUp (line) {
  2034. if (escape) {
  2035. line = escapeInvisibles(line);
  2036. }
  2037. if (line[0] === '+') {
  2038. return indent + colorLines('diff added', line);
  2039. }
  2040. if (line[0] === '-') {
  2041. return indent + colorLines('diff removed', line);
  2042. }
  2043. if (line.match(/@@/)) {
  2044. return null;
  2045. }
  2046. if (line.match(/\\ No newline/)) {
  2047. return null;
  2048. }
  2049. return indent + line;
  2050. }
  2051. function notBlank (line) {
  2052. return typeof line !== 'undefined' && line !== null;
  2053. }
  2054. var msg = diff.createPatch('string', err.actual, err.expected);
  2055. var lines = msg.split('\n').splice(4);
  2056. return '\n ' +
  2057. colorLines('diff added', '+ expected') + ' ' +
  2058. colorLines('diff removed', '- actual') +
  2059. '\n\n' +
  2060. lines.map(cleanUp).filter(notBlank).join('\n');
  2061. }
  2062. /**
  2063. * Return a character diff for `err`.
  2064. *
  2065. * @api private
  2066. * @param {Error} err
  2067. * @param {string} type
  2068. * @param {boolean} escape
  2069. * @return {string}
  2070. */
  2071. function errorDiff (err, type, escape) {
  2072. var actual = escape ? escapeInvisibles(err.actual) : err.actual;
  2073. var expected = escape ? escapeInvisibles(err.expected) : err.expected;
  2074. return diff['diff' + type](actual, expected).map(function (str) {
  2075. if (str.added) {
  2076. return colorLines('diff added', str.value);
  2077. }
  2078. if (str.removed) {
  2079. return colorLines('diff removed', str.value);
  2080. }
  2081. return str.value;
  2082. }).join('');
  2083. }
  2084. /**
  2085. * Returns a string with all invisible characters in plain text
  2086. *
  2087. * @api private
  2088. * @param {string} line
  2089. * @return {string}
  2090. */
  2091. function escapeInvisibles (line) {
  2092. return line.replace(/\t/g, '<tab>')
  2093. .replace(/\r/g, '<CR>')
  2094. .replace(/\n/g, '<LF>\n');
  2095. }
  2096. /**
  2097. * Color lines for `str`, using the color `name`.
  2098. *
  2099. * @api private
  2100. * @param {string} name
  2101. * @param {string} str
  2102. * @return {string}
  2103. */
  2104. function colorLines (name, str) {
  2105. return str.split('\n').map(function (str) {
  2106. return color(name, str);
  2107. }).join('\n');
  2108. }
  2109. /**
  2110. * Object#toString reference.
  2111. */
  2112. var objToString = Object.prototype.toString;
  2113. /**
  2114. * Check that a / b have the same type.
  2115. *
  2116. * @api private
  2117. * @param {Object} a
  2118. * @param {Object} b
  2119. * @return {boolean}
  2120. */
  2121. function sameType (a, b) {
  2122. return objToString.call(a) === objToString.call(b);
  2123. }
  2124. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2125. },{"../ms":15,"../utils":38,"_process":67,"diff":46,"supports-color":42,"tty":5}],18:[function(require,module,exports){
  2126. 'use strict';
  2127. /**
  2128. * Module dependencies.
  2129. */
  2130. var Base = require('./base');
  2131. var utils = require('../utils');
  2132. /**
  2133. * Expose `Doc`.
  2134. */
  2135. exports = module.exports = Doc;
  2136. /**
  2137. * Initialize a new `Doc` reporter.
  2138. *
  2139. * @param {Runner} runner
  2140. * @api public
  2141. */
  2142. function Doc (runner) {
  2143. Base.call(this, runner);
  2144. var indents = 2;
  2145. function indent () {
  2146. return Array(indents).join(' ');
  2147. }
  2148. runner.on('suite', function (suite) {
  2149. if (suite.root) {
  2150. return;
  2151. }
  2152. ++indents;
  2153. console.log('%s<section class="suite">', indent());
  2154. ++indents;
  2155. console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title));
  2156. console.log('%s<dl>', indent());
  2157. });
  2158. runner.on('suite end', function (suite) {
  2159. if (suite.root) {
  2160. return;
  2161. }
  2162. console.log('%s</dl>', indent());
  2163. --indents;
  2164. console.log('%s</section>', indent());
  2165. --indents;
  2166. });
  2167. runner.on('pass', function (test) {
  2168. console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
  2169. var code = utils.escape(utils.clean(test.body));
  2170. console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
  2171. });
  2172. runner.on('fail', function (test, err) {
  2173. console.log('%s <dt class="error">%s</dt>', indent(), utils.escape(test.title));
  2174. var code = utils.escape(utils.clean(test.body));
  2175. console.log('%s <dd class="error"><pre><code>%s</code></pre></dd>', indent(), code);
  2176. console.log('%s <dd class="error">%s</dd>', indent(), utils.escape(err));
  2177. });
  2178. }
  2179. },{"../utils":38,"./base":17}],19:[function(require,module,exports){
  2180. (function (process){
  2181. 'use strict';
  2182. /**
  2183. * Module dependencies.
  2184. */
  2185. var Base = require('./base');
  2186. var inherits = require('../utils').inherits;
  2187. var color = Base.color;
  2188. /**
  2189. * Expose `Dot`.
  2190. */
  2191. exports = module.exports = Dot;
  2192. /**
  2193. * Initialize a new `Dot` matrix test reporter.
  2194. *
  2195. * @api public
  2196. * @param {Runner} runner
  2197. */
  2198. function Dot (runner) {
  2199. Base.call(this, runner);
  2200. var self = this;
  2201. var width = Base.window.width * 0.75 | 0;
  2202. var n = -1;
  2203. runner.on('start', function () {
  2204. process.stdout.write('\n');
  2205. });
  2206. runner.on('pending', function () {
  2207. if (++n % width === 0) {
  2208. process.stdout.write('\n ');
  2209. }
  2210. process.stdout.write(color('pending', Base.symbols.comma));
  2211. });
  2212. runner.on('pass', function (test) {
  2213. if (++n % width === 0) {
  2214. process.stdout.write('\n ');
  2215. }
  2216. if (test.speed === 'slow') {
  2217. process.stdout.write(color('bright yellow', Base.symbols.dot));
  2218. } else {
  2219. process.stdout.write(color(test.speed, Base.symbols.dot));
  2220. }
  2221. });
  2222. runner.on('fail', function () {
  2223. if (++n % width === 0) {
  2224. process.stdout.write('\n ');
  2225. }
  2226. process.stdout.write(color('fail', Base.symbols.bang));
  2227. });
  2228. runner.on('end', function () {
  2229. console.log();
  2230. self.epilogue();
  2231. });
  2232. }
  2233. /**
  2234. * Inherit from `Base.prototype`.
  2235. */
  2236. inherits(Dot, Base);
  2237. }).call(this,require('_process'))
  2238. },{"../utils":38,"./base":17,"_process":67}],20:[function(require,module,exports){
  2239. (function (global){
  2240. 'use strict';
  2241. /* eslint-env browser */
  2242. /**
  2243. * Module dependencies.
  2244. */
  2245. var Base = require('./base');
  2246. var utils = require('../utils');
  2247. var Progress = require('../browser/progress');
  2248. var escapeRe = require('escape-string-regexp');
  2249. var escape = utils.escape;
  2250. /**
  2251. * Save timer references to avoid Sinon interfering (see GH-237).
  2252. */
  2253. /* eslint-disable no-unused-vars, no-native-reassign */
  2254. var Date = global.Date;
  2255. var setTimeout = global.setTimeout;
  2256. var setInterval = global.setInterval;
  2257. var clearTimeout = global.clearTimeout;
  2258. var clearInterval = global.clearInterval;
  2259. /* eslint-enable no-unused-vars, no-native-reassign */
  2260. /**
  2261. * Expose `HTML`.
  2262. */
  2263. exports = module.exports = HTML;
  2264. /**
  2265. * Stats template.
  2266. */
  2267. var statsTemplate = '<ul id="mocha-stats">' +
  2268. '<li class="progress"><canvas width="40" height="40"></canvas></li>' +
  2269. '<li class="passes"><a href="javascript:void(0);">passes:</a> <em>0</em></li>' +
  2270. '<li class="failures"><a href="javascript:void(0);">failures:</a> <em>0</em></li>' +
  2271. '<li class="duration">duration: <em>0</em>s</li>' +
  2272. '</ul>';
  2273. /**
  2274. * Initialize a new `HTML` reporter.
  2275. *
  2276. * @api public
  2277. * @param {Runner} runner
  2278. */
  2279. function HTML (runner) {
  2280. Base.call(this, runner);
  2281. var self = this;
  2282. var stats = this.stats;
  2283. var stat = fragment(statsTemplate);
  2284. var items = stat.getElementsByTagName('li');
  2285. var passes = items[1].getElementsByTagName('em')[0];
  2286. var passesLink = items[1].getElementsByTagName('a')[0];
  2287. var failures = items[2].getElementsByTagName('em')[0];
  2288. var failuresLink = items[2].getElementsByTagName('a')[0];
  2289. var duration = items[3].getElementsByTagName('em')[0];
  2290. var canvas = stat.getElementsByTagName('canvas')[0];
  2291. var report = fragment('<ul id="mocha-report"></ul>');
  2292. var stack = [report];
  2293. var progress;
  2294. var ctx;
  2295. var root = document.getElementById('mocha');
  2296. if (canvas.getContext) {
  2297. var ratio = window.devicePixelRatio || 1;
  2298. canvas.style.width = canvas.width;
  2299. canvas.style.height = canvas.height;
  2300. canvas.width *= ratio;
  2301. canvas.height *= ratio;
  2302. ctx = canvas.getContext('2d');
  2303. ctx.scale(ratio, ratio);
  2304. progress = new Progress();
  2305. }
  2306. if (!root) {
  2307. return error('#mocha div missing, add it to your document');
  2308. }
  2309. // pass toggle
  2310. on(passesLink, 'click', function (evt) {
  2311. evt.preventDefault();
  2312. unhide();
  2313. var name = (/pass/).test(report.className) ? '' : ' pass';
  2314. report.className = report.className.replace(/fail|pass/g, '') + name;
  2315. if (report.className.trim()) {
  2316. hideSuitesWithout('test pass');
  2317. }
  2318. });
  2319. // failure toggle
  2320. on(failuresLink, 'click', function (evt) {
  2321. evt.preventDefault();
  2322. unhide();
  2323. var name = (/fail/).test(report.className) ? '' : ' fail';
  2324. report.className = report.className.replace(/fail|pass/g, '') + name;
  2325. if (report.className.trim()) {
  2326. hideSuitesWithout('test fail');
  2327. }
  2328. });
  2329. root.appendChild(stat);
  2330. root.appendChild(report);
  2331. if (progress) {
  2332. progress.size(40);
  2333. }
  2334. runner.on('suite', function (suite) {
  2335. if (suite.root) {
  2336. return;
  2337. }
  2338. // suite
  2339. var url = self.suiteURL(suite);
  2340. var el = fragment('<li class="suite"><h1><a href="%s">%s</a></h1></li>', url, escape(suite.title));
  2341. // container
  2342. stack[0].appendChild(el);
  2343. stack.unshift(document.createElement('ul'));
  2344. el.appendChild(stack[0]);
  2345. });
  2346. runner.on('suite end', function (suite) {
  2347. if (suite.root) {
  2348. updateStats();
  2349. return;
  2350. }
  2351. stack.shift();
  2352. });
  2353. runner.on('pass', function (test) {
  2354. var url = self.testURL(test);
  2355. var markup = '<li class="test pass %e"><h2>%e<span class="duration">%ems</span> ' +
  2356. '<a href="%s" class="replay">‣</a></h2></li>';
  2357. var el = fragment(markup, test.speed, test.title, test.duration, url);
  2358. self.addCodeToggle(el, test.body);
  2359. appendToStack(el);
  2360. updateStats();
  2361. });
  2362. runner.on('fail', function (test) {
  2363. var el = fragment('<li class="test fail"><h2>%e <a href="%e" class="replay">‣</a></h2></li>',
  2364. test.title, self.testURL(test));
  2365. var stackString; // Note: Includes leading newline
  2366. var message = test.err.toString();
  2367. // <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
  2368. // check for the result of the stringifying.
  2369. if (message === '[object Error]') {
  2370. message = test.err.message;
  2371. }
  2372. if (test.err.stack) {
  2373. var indexOfMessage = test.err.stack.indexOf(test.err.message);
  2374. if (indexOfMessage === -1) {
  2375. stackString = test.err.stack;
  2376. } else {
  2377. stackString = test.err.stack.substr(test.err.message.length + indexOfMessage);
  2378. }
  2379. } else if (test.err.sourceURL && test.err.line !== undefined) {
  2380. // Safari doesn't give you a stack. Let's at least provide a source line.
  2381. stackString = '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
  2382. }
  2383. stackString = stackString || '';
  2384. if (test.err.htmlMessage && stackString) {
  2385. el.appendChild(fragment('<div class="html-error">%s\n<pre class="error">%e</pre></div>',
  2386. test.err.htmlMessage, stackString));
  2387. } else if (test.err.htmlMessage) {
  2388. el.appendChild(fragment('<div class="html-error">%s</div>', test.err.htmlMessage));
  2389. } else {
  2390. el.appendChild(fragment('<pre class="error">%e%e</pre>', message, stackString));
  2391. }
  2392. self.addCodeToggle(el, test.body);
  2393. appendToStack(el);
  2394. updateStats();
  2395. });
  2396. runner.on('pending', function (test) {
  2397. var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
  2398. appendToStack(el);
  2399. updateStats();
  2400. });
  2401. function appendToStack (el) {
  2402. // Don't call .appendChild if #mocha-report was already .shift()'ed off the stack.
  2403. if (stack[0]) {
  2404. stack[0].appendChild(el);
  2405. }
  2406. }
  2407. function updateStats () {
  2408. // TODO: add to stats
  2409. var percent = stats.tests / runner.total * 100 | 0;
  2410. if (progress) {
  2411. progress.update(percent).draw(ctx);
  2412. }
  2413. // update stats
  2414. var ms = new Date() - stats.start;
  2415. text(passes, stats.passes);
  2416. text(failures, stats.failures);
  2417. text(duration, (ms / 1000).toFixed(2));
  2418. }
  2419. }
  2420. /**
  2421. * Makes a URL, preserving querystring ("search") parameters.
  2422. *
  2423. * @param {string} s
  2424. * @return {string} A new URL.
  2425. */
  2426. function makeUrl (s) {
  2427. var search = window.location.search;
  2428. // Remove previous grep query parameter if present
  2429. if (search) {
  2430. search = search.replace(/[?&]grep=[^&\s]*/g, '').replace(/^&/, '?');
  2431. }
  2432. return window.location.pathname + (search ? search + '&' : '?') + 'grep=' + encodeURIComponent(escapeRe(s));
  2433. }
  2434. /**
  2435. * Provide suite URL.
  2436. *
  2437. * @param {Object} [suite]
  2438. */
  2439. HTML.prototype.suiteURL = function (suite) {
  2440. return makeUrl(suite.fullTitle());
  2441. };
  2442. /**
  2443. * Provide test URL.
  2444. *
  2445. * @param {Object} [test]
  2446. */
  2447. HTML.prototype.testURL = function (test) {
  2448. return makeUrl(test.fullTitle());
  2449. };
  2450. /**
  2451. * Adds code toggle functionality for the provided test's list element.
  2452. *
  2453. * @param {HTMLLIElement} el
  2454. * @param {string} contents
  2455. */
  2456. HTML.prototype.addCodeToggle = function (el, contents) {
  2457. var h2 = el.getElementsByTagName('h2')[0];
  2458. on(h2, 'click', function () {
  2459. pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
  2460. });
  2461. var pre = fragment('<pre><code>%e</code></pre>', utils.clean(contents));
  2462. el.appendChild(pre);
  2463. pre.style.display = 'none';
  2464. };
  2465. /**
  2466. * Display error `msg`.
  2467. *
  2468. * @param {string} msg
  2469. */
  2470. function error (msg) {
  2471. document.body.appendChild(fragment('<div id="mocha-error">%s</div>', msg));
  2472. }
  2473. /**
  2474. * Return a DOM fragment from `html`.
  2475. *
  2476. * @param {string} html
  2477. */
  2478. function fragment (html) {
  2479. var args = arguments;
  2480. var div = document.createElement('div');
  2481. var i = 1;
  2482. div.innerHTML = html.replace(/%([se])/g, function (_, type) {
  2483. switch (type) {
  2484. case 's': return String(args[i++]);
  2485. case 'e': return escape(args[i++]);
  2486. // no default
  2487. }
  2488. });
  2489. return div.firstChild;
  2490. }
  2491. /**
  2492. * Check for suites that do not have elements
  2493. * with `classname`, and hide them.
  2494. *
  2495. * @param {text} classname
  2496. */
  2497. function hideSuitesWithout (classname) {
  2498. var suites = document.getElementsByClassName('suite');
  2499. for (var i = 0; i < suites.length; i++) {
  2500. var els = suites[i].getElementsByClassName(classname);
  2501. if (!els.length) {
  2502. suites[i].className += ' hidden';
  2503. }
  2504. }
  2505. }
  2506. /**
  2507. * Unhide .hidden suites.
  2508. */
  2509. function unhide () {
  2510. var els = document.getElementsByClassName('suite hidden');
  2511. for (var i = 0; i < els.length; ++i) {
  2512. els[i].className = els[i].className.replace('suite hidden', 'suite');
  2513. }
  2514. }
  2515. /**
  2516. * Set an element's text contents.
  2517. *
  2518. * @param {HTMLElement} el
  2519. * @param {string} contents
  2520. */
  2521. function text (el, contents) {
  2522. if (el.textContent) {
  2523. el.textContent = contents;
  2524. } else {
  2525. el.innerText = contents;
  2526. }
  2527. }
  2528. /**
  2529. * Listen on `event` with callback `fn`.
  2530. */
  2531. function on (el, event, fn) {
  2532. if (el.addEventListener) {
  2533. el.addEventListener(event, fn, false);
  2534. } else {
  2535. el.attachEvent('on' + event, fn);
  2536. }
  2537. }
  2538. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2539. },{"../browser/progress":4,"../utils":38,"./base":17,"escape-string-regexp":47}],21:[function(require,module,exports){
  2540. 'use strict';
  2541. // Alias exports to a their normalized format Mocha#reporter to prevent a need
  2542. // for dynamic (try/catch) requires, which Browserify doesn't handle.
  2543. exports.Base = exports.base = require('./base');
  2544. exports.Dot = exports.dot = require('./dot');
  2545. exports.Doc = exports.doc = require('./doc');
  2546. exports.TAP = exports.tap = require('./tap');
  2547. exports.JSON = exports.json = require('./json');
  2548. exports.HTML = exports.html = require('./html');
  2549. exports.List = exports.list = require('./list');
  2550. exports.Min = exports.min = require('./min');
  2551. exports.Spec = exports.spec = require('./spec');
  2552. exports.Nyan = exports.nyan = require('./nyan');
  2553. exports.XUnit = exports.xunit = require('./xunit');
  2554. exports.Markdown = exports.markdown = require('./markdown');
  2555. exports.Progress = exports.progress = require('./progress');
  2556. exports.Landing = exports.landing = require('./landing');
  2557. exports.JSONStream = exports['json-stream'] = require('./json-stream');
  2558. },{"./base":17,"./doc":18,"./dot":19,"./html":20,"./json":23,"./json-stream":22,"./landing":24,"./list":25,"./markdown":26,"./min":27,"./nyan":28,"./progress":29,"./spec":30,"./tap":31,"./xunit":32}],22:[function(require,module,exports){
  2559. (function (process){
  2560. 'use strict';
  2561. /**
  2562. * Module dependencies.
  2563. */
  2564. var Base = require('./base');
  2565. var JSON = require('json3');
  2566. /**
  2567. * Expose `List`.
  2568. */
  2569. exports = module.exports = List;
  2570. /**
  2571. * Initialize a new `List` test reporter.
  2572. *
  2573. * @api public
  2574. * @param {Runner} runner
  2575. */
  2576. function List (runner) {
  2577. Base.call(this, runner);
  2578. var self = this;
  2579. var total = runner.total;
  2580. runner.on('start', function () {
  2581. console.log(JSON.stringify(['start', { total: total }]));
  2582. });
  2583. runner.on('pass', function (test) {
  2584. console.log(JSON.stringify(['pass', clean(test)]));
  2585. });
  2586. runner.on('fail', function (test, err) {
  2587. test = clean(test);
  2588. test.err = err.message;
  2589. test.stack = err.stack || null;
  2590. console.log(JSON.stringify(['fail', test]));
  2591. });
  2592. runner.on('end', function () {
  2593. process.stdout.write(JSON.stringify(['end', self.stats]));
  2594. });
  2595. }
  2596. /**
  2597. * Return a plain-object representation of `test`
  2598. * free of cyclic properties etc.
  2599. *
  2600. * @api private
  2601. * @param {Object} test
  2602. * @return {Object}
  2603. */
  2604. function clean (test) {
  2605. return {
  2606. title: test.title,
  2607. fullTitle: test.fullTitle(),
  2608. duration: test.duration,
  2609. currentRetry: test.currentRetry()
  2610. };
  2611. }
  2612. }).call(this,require('_process'))
  2613. },{"./base":17,"_process":67,"json3":54}],23:[function(require,module,exports){
  2614. (function (process){
  2615. 'use strict';
  2616. /**
  2617. * Module dependencies.
  2618. */
  2619. var Base = require('./base');
  2620. /**
  2621. * Expose `JSON`.
  2622. */
  2623. exports = module.exports = JSONReporter;
  2624. /**
  2625. * Initialize a new `JSON` reporter.
  2626. *
  2627. * @api public
  2628. * @param {Runner} runner
  2629. */
  2630. function JSONReporter (runner) {
  2631. Base.call(this, runner);
  2632. var self = this;
  2633. var tests = [];
  2634. var pending = [];
  2635. var failures = [];
  2636. var passes = [];
  2637. runner.on('test end', function (test) {
  2638. tests.push(test);
  2639. });
  2640. runner.on('pass', function (test) {
  2641. passes.push(test);
  2642. });
  2643. runner.on('fail', function (test) {
  2644. failures.push(test);
  2645. });
  2646. runner.on('pending', function (test) {
  2647. pending.push(test);
  2648. });
  2649. runner.on('end', function () {
  2650. var obj = {
  2651. stats: self.stats,
  2652. tests: tests.map(clean),
  2653. pending: pending.map(clean),
  2654. failures: failures.map(clean),
  2655. passes: passes.map(clean)
  2656. };
  2657. runner.testResults = obj;
  2658. process.stdout.write(JSON.stringify(obj, null, 2));
  2659. });
  2660. }
  2661. /**
  2662. * Return a plain-object representation of `test`
  2663. * free of cyclic properties etc.
  2664. *
  2665. * @api private
  2666. * @param {Object} test
  2667. * @return {Object}
  2668. */
  2669. function clean (test) {
  2670. return {
  2671. title: test.title,
  2672. fullTitle: test.fullTitle(),
  2673. duration: test.duration,
  2674. currentRetry: test.currentRetry(),
  2675. err: errorJSON(test.err || {})
  2676. };
  2677. }
  2678. /**
  2679. * Transform `error` into a JSON object.
  2680. *
  2681. * @api private
  2682. * @param {Error} err
  2683. * @return {Object}
  2684. */
  2685. function errorJSON (err) {
  2686. var res = {};
  2687. Object.getOwnPropertyNames(err).forEach(function (key) {
  2688. res[key] = err[key];
  2689. }, err);
  2690. return res;
  2691. }
  2692. }).call(this,require('_process'))
  2693. },{"./base":17,"_process":67}],24:[function(require,module,exports){
  2694. (function (process){
  2695. 'use strict';
  2696. /**
  2697. * Module dependencies.
  2698. */
  2699. var Base = require('./base');
  2700. var inherits = require('../utils').inherits;
  2701. var cursor = Base.cursor;
  2702. var color = Base.color;
  2703. /**
  2704. * Expose `Landing`.
  2705. */
  2706. exports = module.exports = Landing;
  2707. /**
  2708. * Airplane color.
  2709. */
  2710. Base.colors.plane = 0;
  2711. /**
  2712. * Airplane crash color.
  2713. */
  2714. Base.colors['plane crash'] = 31;
  2715. /**
  2716. * Runway color.
  2717. */
  2718. Base.colors.runway = 90;
  2719. /**
  2720. * Initialize a new `Landing` reporter.
  2721. *
  2722. * @api public
  2723. * @param {Runner} runner
  2724. */
  2725. function Landing (runner) {
  2726. Base.call(this, runner);
  2727. var self = this;
  2728. var width = Base.window.width * 0.75 | 0;
  2729. var total = runner.total;
  2730. var stream = process.stdout;
  2731. var plane = color('plane', '✈');
  2732. var crashed = -1;
  2733. var n = 0;
  2734. function runway () {
  2735. var buf = Array(width).join('-');
  2736. return ' ' + color('runway', buf);
  2737. }
  2738. runner.on('start', function () {
  2739. stream.write('\n\n\n ');
  2740. cursor.hide();
  2741. });
  2742. runner.on('test end', function (test) {
  2743. // check if the plane crashed
  2744. var col = crashed === -1 ? width * ++n / total | 0 : crashed;
  2745. // show the crash
  2746. if (test.state === 'failed') {
  2747. plane = color('plane crash', '✈');
  2748. crashed = col;
  2749. }
  2750. // render landing strip
  2751. stream.write('\u001b[' + (width + 1) + 'D\u001b[2A');
  2752. stream.write(runway());
  2753. stream.write('\n ');
  2754. stream.write(color('runway', Array(col).join('⋅')));
  2755. stream.write(plane);
  2756. stream.write(color('runway', Array(width - col).join('⋅') + '\n'));
  2757. stream.write(runway());
  2758. stream.write('\u001b[0m');
  2759. });
  2760. runner.on('end', function () {
  2761. cursor.show();
  2762. console.log();
  2763. self.epilogue();
  2764. });
  2765. }
  2766. /**
  2767. * Inherit from `Base.prototype`.
  2768. */
  2769. inherits(Landing, Base);
  2770. }).call(this,require('_process'))
  2771. },{"../utils":38,"./base":17,"_process":67}],25:[function(require,module,exports){
  2772. (function (process){
  2773. 'use strict';
  2774. /**
  2775. * Module dependencies.
  2776. */
  2777. var Base = require('./base');
  2778. var inherits = require('../utils').inherits;
  2779. var color = Base.color;
  2780. var cursor = Base.cursor;
  2781. /**
  2782. * Expose `List`.
  2783. */
  2784. exports = module.exports = List;
  2785. /**
  2786. * Initialize a new `List` test reporter.
  2787. *
  2788. * @api public
  2789. * @param {Runner} runner
  2790. */
  2791. function List (runner) {
  2792. Base.call(this, runner);
  2793. var self = this;
  2794. var n = 0;
  2795. runner.on('start', function () {
  2796. console.log();
  2797. });
  2798. runner.on('test', function (test) {
  2799. process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
  2800. });
  2801. runner.on('pending', function (test) {
  2802. var fmt = color('checkmark', ' -') +
  2803. color('pending', ' %s');
  2804. console.log(fmt, test.fullTitle());
  2805. });
  2806. runner.on('pass', function (test) {
  2807. var fmt = color('checkmark', ' ' + Base.symbols.ok) +
  2808. color('pass', ' %s: ') +
  2809. color(test.speed, '%dms');
  2810. cursor.CR();
  2811. console.log(fmt, test.fullTitle(), test.duration);
  2812. });
  2813. runner.on('fail', function (test) {
  2814. cursor.CR();
  2815. console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
  2816. });
  2817. runner.on('end', self.epilogue.bind(self));
  2818. }
  2819. /**
  2820. * Inherit from `Base.prototype`.
  2821. */
  2822. inherits(List, Base);
  2823. }).call(this,require('_process'))
  2824. },{"../utils":38,"./base":17,"_process":67}],26:[function(require,module,exports){
  2825. (function (process){
  2826. 'use strict';
  2827. /**
  2828. * Module dependencies.
  2829. */
  2830. var Base = require('./base');
  2831. var utils = require('../utils');
  2832. /**
  2833. * Constants
  2834. */
  2835. var SUITE_PREFIX = '$';
  2836. /**
  2837. * Expose `Markdown`.
  2838. */
  2839. exports = module.exports = Markdown;
  2840. /**
  2841. * Initialize a new `Markdown` reporter.
  2842. *
  2843. * @api public
  2844. * @param {Runner} runner
  2845. */
  2846. function Markdown (runner) {
  2847. Base.call(this, runner);
  2848. var level = 0;
  2849. var buf = '';
  2850. function title (str) {
  2851. return Array(level).join('#') + ' ' + str;
  2852. }
  2853. function mapTOC (suite, obj) {
  2854. var ret = obj;
  2855. var key = SUITE_PREFIX + suite.title;
  2856. obj = obj[key] = obj[key] || { suite: suite };
  2857. suite.suites.forEach(function (suite) {
  2858. mapTOC(suite, obj);
  2859. });
  2860. return ret;
  2861. }
  2862. function stringifyTOC (obj, level) {
  2863. ++level;
  2864. var buf = '';
  2865. var link;
  2866. for (var key in obj) {
  2867. if (key === 'suite') {
  2868. continue;
  2869. }
  2870. if (key !== SUITE_PREFIX) {
  2871. link = ' - [' + key.substring(1) + ']';
  2872. link += '(#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
  2873. buf += Array(level).join(' ') + link;
  2874. }
  2875. buf += stringifyTOC(obj[key], level);
  2876. }
  2877. return buf;
  2878. }
  2879. function generateTOC (suite) {
  2880. var obj = mapTOC(suite, {});
  2881. return stringifyTOC(obj, 0);
  2882. }
  2883. generateTOC(runner.suite);
  2884. runner.on('suite', function (suite) {
  2885. ++level;
  2886. var slug = utils.slug(suite.fullTitle());
  2887. buf += '<a name="' + slug + '"></a>' + '\n';
  2888. buf += title(suite.title) + '\n';
  2889. });
  2890. runner.on('suite end', function () {
  2891. --level;
  2892. });
  2893. runner.on('pass', function (test) {
  2894. var code = utils.clean(test.body);
  2895. buf += test.title + '.\n';
  2896. buf += '\n```js\n';
  2897. buf += code + '\n';
  2898. buf += '```\n\n';
  2899. });
  2900. runner.on('end', function () {
  2901. process.stdout.write('# TOC\n');
  2902. process.stdout.write(generateTOC(runner.suite));
  2903. process.stdout.write(buf);
  2904. });
  2905. }
  2906. }).call(this,require('_process'))
  2907. },{"../utils":38,"./base":17,"_process":67}],27:[function(require,module,exports){
  2908. (function (process){
  2909. 'use strict';
  2910. /**
  2911. * Module dependencies.
  2912. */
  2913. var Base = require('./base');
  2914. var inherits = require('../utils').inherits;
  2915. /**
  2916. * Expose `Min`.
  2917. */
  2918. exports = module.exports = Min;
  2919. /**
  2920. * Initialize a new `Min` minimal test reporter (best used with --watch).
  2921. *
  2922. * @api public
  2923. * @param {Runner} runner
  2924. */
  2925. function Min (runner) {
  2926. Base.call(this, runner);
  2927. runner.on('start', function () {
  2928. // clear screen
  2929. process.stdout.write('\u001b[2J');
  2930. // set cursor position
  2931. process.stdout.write('\u001b[1;3H');
  2932. });
  2933. runner.on('end', this.epilogue.bind(this));
  2934. }
  2935. /**
  2936. * Inherit from `Base.prototype`.
  2937. */
  2938. inherits(Min, Base);
  2939. }).call(this,require('_process'))
  2940. },{"../utils":38,"./base":17,"_process":67}],28:[function(require,module,exports){
  2941. (function (process){
  2942. 'use strict';
  2943. /**
  2944. * Module dependencies.
  2945. */
  2946. var Base = require('./base');
  2947. var inherits = require('../utils').inherits;
  2948. /**
  2949. * Expose `Dot`.
  2950. */
  2951. exports = module.exports = NyanCat;
  2952. /**
  2953. * Initialize a new `Dot` matrix test reporter.
  2954. *
  2955. * @param {Runner} runner
  2956. * @api public
  2957. */
  2958. function NyanCat (runner) {
  2959. Base.call(this, runner);
  2960. var self = this;
  2961. var width = Base.window.width * 0.75 | 0;
  2962. var nyanCatWidth = this.nyanCatWidth = 11;
  2963. this.colorIndex = 0;
  2964. this.numberOfLines = 4;
  2965. this.rainbowColors = self.generateColors();
  2966. this.scoreboardWidth = 5;
  2967. this.tick = 0;
  2968. this.trajectories = [[], [], [], []];
  2969. this.trajectoryWidthMax = (width - nyanCatWidth);
  2970. runner.on('start', function () {
  2971. Base.cursor.hide();
  2972. self.draw();
  2973. });
  2974. runner.on('pending', function () {
  2975. self.draw();
  2976. });
  2977. runner.on('pass', function () {
  2978. self.draw();
  2979. });
  2980. runner.on('fail', function () {
  2981. self.draw();
  2982. });
  2983. runner.on('end', function () {
  2984. Base.cursor.show();
  2985. for (var i = 0; i < self.numberOfLines; i++) {
  2986. write('\n');
  2987. }
  2988. self.epilogue();
  2989. });
  2990. }
  2991. /**
  2992. * Inherit from `Base.prototype`.
  2993. */
  2994. inherits(NyanCat, Base);
  2995. /**
  2996. * Draw the nyan cat
  2997. *
  2998. * @api private
  2999. */
  3000. NyanCat.prototype.draw = function () {
  3001. this.appendRainbow();
  3002. this.drawScoreboard();
  3003. this.drawRainbow();
  3004. this.drawNyanCat();
  3005. this.tick = !this.tick;
  3006. };
  3007. /**
  3008. * Draw the "scoreboard" showing the number
  3009. * of passes, failures and pending tests.
  3010. *
  3011. * @api private
  3012. */
  3013. NyanCat.prototype.drawScoreboard = function () {
  3014. var stats = this.stats;
  3015. function draw (type, n) {
  3016. write(' ');
  3017. write(Base.color(type, n));
  3018. write('\n');
  3019. }
  3020. draw('green', stats.passes);
  3021. draw('fail', stats.failures);
  3022. draw('pending', stats.pending);
  3023. write('\n');
  3024. this.cursorUp(this.numberOfLines);
  3025. };
  3026. /**
  3027. * Append the rainbow.
  3028. *
  3029. * @api private
  3030. */
  3031. NyanCat.prototype.appendRainbow = function () {
  3032. var segment = this.tick ? '_' : '-';
  3033. var rainbowified = this.rainbowify(segment);
  3034. for (var index = 0; index < this.numberOfLines; index++) {
  3035. var trajectory = this.trajectories[index];
  3036. if (trajectory.length >= this.trajectoryWidthMax) {
  3037. trajectory.shift();
  3038. }
  3039. trajectory.push(rainbowified);
  3040. }
  3041. };
  3042. /**
  3043. * Draw the rainbow.
  3044. *
  3045. * @api private
  3046. */
  3047. NyanCat.prototype.drawRainbow = function () {
  3048. var self = this;
  3049. this.trajectories.forEach(function (line) {
  3050. write('\u001b[' + self.scoreboardWidth + 'C');
  3051. write(line.join(''));
  3052. write('\n');
  3053. });
  3054. this.cursorUp(this.numberOfLines);
  3055. };
  3056. /**
  3057. * Draw the nyan cat
  3058. *
  3059. * @api private
  3060. */
  3061. NyanCat.prototype.drawNyanCat = function () {
  3062. var self = this;
  3063. var startWidth = this.scoreboardWidth + this.trajectories[0].length;
  3064. var dist = '\u001b[' + startWidth + 'C';
  3065. var padding = '';
  3066. write(dist);
  3067. write('_,------,');
  3068. write('\n');
  3069. write(dist);
  3070. padding = self.tick ? ' ' : ' ';
  3071. write('_|' + padding + '/\\_/\\ ');
  3072. write('\n');
  3073. write(dist);
  3074. padding = self.tick ? '_' : '__';
  3075. var tail = self.tick ? '~' : '^';
  3076. write(tail + '|' + padding + this.face() + ' ');
  3077. write('\n');
  3078. write(dist);
  3079. padding = self.tick ? ' ' : ' ';
  3080. write(padding + '"" "" ');
  3081. write('\n');
  3082. this.cursorUp(this.numberOfLines);
  3083. };
  3084. /**
  3085. * Draw nyan cat face.
  3086. *
  3087. * @api private
  3088. * @return {string}
  3089. */
  3090. NyanCat.prototype.face = function () {
  3091. var stats = this.stats;
  3092. if (stats.failures) {
  3093. return '( x .x)';
  3094. } else if (stats.pending) {
  3095. return '( o .o)';
  3096. } else if (stats.passes) {
  3097. return '( ^ .^)';
  3098. }
  3099. return '( - .-)';
  3100. };
  3101. /**
  3102. * Move cursor up `n`.
  3103. *
  3104. * @api private
  3105. * @param {number} n
  3106. */
  3107. NyanCat.prototype.cursorUp = function (n) {
  3108. write('\u001b[' + n + 'A');
  3109. };
  3110. /**
  3111. * Move cursor down `n`.
  3112. *
  3113. * @api private
  3114. * @param {number} n
  3115. */
  3116. NyanCat.prototype.cursorDown = function (n) {
  3117. write('\u001b[' + n + 'B');
  3118. };
  3119. /**
  3120. * Generate rainbow colors.
  3121. *
  3122. * @api private
  3123. * @return {Array}
  3124. */
  3125. NyanCat.prototype.generateColors = function () {
  3126. var colors = [];
  3127. for (var i = 0; i < (6 * 7); i++) {
  3128. var pi3 = Math.floor(Math.PI / 3);
  3129. var n = (i * (1.0 / 6));
  3130. var r = Math.floor(3 * Math.sin(n) + 3);
  3131. var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
  3132. var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
  3133. colors.push(36 * r + 6 * g + b + 16);
  3134. }
  3135. return colors;
  3136. };
  3137. /**
  3138. * Apply rainbow to the given `str`.
  3139. *
  3140. * @api private
  3141. * @param {string} str
  3142. * @return {string}
  3143. */
  3144. NyanCat.prototype.rainbowify = function (str) {
  3145. if (!Base.useColors) {
  3146. return str;
  3147. }
  3148. var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length];
  3149. this.colorIndex += 1;
  3150. return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';
  3151. };
  3152. /**
  3153. * Stdout helper.
  3154. *
  3155. * @param {string} string A message to write to stdout.
  3156. */
  3157. function write (string) {
  3158. process.stdout.write(string);
  3159. }
  3160. }).call(this,require('_process'))
  3161. },{"../utils":38,"./base":17,"_process":67}],29:[function(require,module,exports){
  3162. (function (process){
  3163. 'use strict';
  3164. /**
  3165. * Module dependencies.
  3166. */
  3167. var Base = require('./base');
  3168. var inherits = require('../utils').inherits;
  3169. var color = Base.color;
  3170. var cursor = Base.cursor;
  3171. /**
  3172. * Expose `Progress`.
  3173. */
  3174. exports = module.exports = Progress;
  3175. /**
  3176. * General progress bar color.
  3177. */
  3178. Base.colors.progress = 90;
  3179. /**
  3180. * Initialize a new `Progress` bar test reporter.
  3181. *
  3182. * @api public
  3183. * @param {Runner} runner
  3184. * @param {Object} options
  3185. */
  3186. function Progress (runner, options) {
  3187. Base.call(this, runner);
  3188. var self = this;
  3189. var width = Base.window.width * 0.50 | 0;
  3190. var total = runner.total;
  3191. var complete = 0;
  3192. var lastN = -1;
  3193. // default chars
  3194. options = options || {};
  3195. options.open = options.open || '[';
  3196. options.complete = options.complete || '▬';
  3197. options.incomplete = options.incomplete || Base.symbols.dot;
  3198. options.close = options.close || ']';
  3199. options.verbose = false;
  3200. // tests started
  3201. runner.on('start', function () {
  3202. console.log();
  3203. cursor.hide();
  3204. });
  3205. // tests complete
  3206. runner.on('test end', function () {
  3207. complete++;
  3208. var percent = complete / total;
  3209. var n = width * percent | 0;
  3210. var i = width - n;
  3211. if (n === lastN && !options.verbose) {
  3212. // Don't re-render the line if it hasn't changed
  3213. return;
  3214. }
  3215. lastN = n;
  3216. cursor.CR();
  3217. process.stdout.write('\u001b[J');
  3218. process.stdout.write(color('progress', ' ' + options.open));
  3219. process.stdout.write(Array(n).join(options.complete));
  3220. process.stdout.write(Array(i).join(options.incomplete));
  3221. process.stdout.write(color('progress', options.close));
  3222. if (options.verbose) {
  3223. process.stdout.write(color('progress', ' ' + complete + ' of ' + total));
  3224. }
  3225. });
  3226. // tests are complete, output some stats
  3227. // and the failures if any
  3228. runner.on('end', function () {
  3229. cursor.show();
  3230. console.log();
  3231. self.epilogue();
  3232. });
  3233. }
  3234. /**
  3235. * Inherit from `Base.prototype`.
  3236. */
  3237. inherits(Progress, Base);
  3238. }).call(this,require('_process'))
  3239. },{"../utils":38,"./base":17,"_process":67}],30:[function(require,module,exports){
  3240. 'use strict';
  3241. /**
  3242. * Module dependencies.
  3243. */
  3244. var Base = require('./base');
  3245. var inherits = require('../utils').inherits;
  3246. var color = Base.color;
  3247. /**
  3248. * Expose `Spec`.
  3249. */
  3250. exports = module.exports = Spec;
  3251. /**
  3252. * Initialize a new `Spec` test reporter.
  3253. *
  3254. * @api public
  3255. * @param {Runner} runner
  3256. */
  3257. function Spec (runner) {
  3258. Base.call(this, runner);
  3259. var self = this;
  3260. var indents = 0;
  3261. var n = 0;
  3262. function indent () {
  3263. return Array(indents).join(' ');
  3264. }
  3265. runner.on('start', function () {
  3266. console.log();
  3267. });
  3268. runner.on('suite', function (suite) {
  3269. ++indents;
  3270. console.log(color('suite', '%s%s'), indent(), suite.title);
  3271. });
  3272. runner.on('suite end', function () {
  3273. --indents;
  3274. if (indents === 1) {
  3275. console.log();
  3276. }
  3277. });
  3278. runner.on('pending', function (test) {
  3279. var fmt = indent() + color('pending', ' - %s');
  3280. console.log(fmt, test.title);
  3281. });
  3282. runner.on('pass', function (test) {
  3283. var fmt;
  3284. if (test.speed === 'fast') {
  3285. fmt = indent() +
  3286. color('checkmark', ' ' + Base.symbols.ok) +
  3287. color('pass', ' %s');
  3288. console.log(fmt, test.title);
  3289. } else {
  3290. fmt = indent() +
  3291. color('checkmark', ' ' + Base.symbols.ok) +
  3292. color('pass', ' %s') +
  3293. color(test.speed, ' (%dms)');
  3294. console.log(fmt, test.title, test.duration);
  3295. }
  3296. });
  3297. runner.on('fail', function (test) {
  3298. console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
  3299. });
  3300. runner.on('end', self.epilogue.bind(self));
  3301. }
  3302. /**
  3303. * Inherit from `Base.prototype`.
  3304. */
  3305. inherits(Spec, Base);
  3306. },{"../utils":38,"./base":17}],31:[function(require,module,exports){
  3307. 'use strict';
  3308. /**
  3309. * Module dependencies.
  3310. */
  3311. var Base = require('./base');
  3312. /**
  3313. * Expose `TAP`.
  3314. */
  3315. exports = module.exports = TAP;
  3316. /**
  3317. * Initialize a new `TAP` reporter.
  3318. *
  3319. * @api public
  3320. * @param {Runner} runner
  3321. */
  3322. function TAP (runner) {
  3323. Base.call(this, runner);
  3324. var n = 1;
  3325. var passes = 0;
  3326. var failures = 0;
  3327. runner.on('start', function () {
  3328. var total = runner.grepTotal(runner.suite);
  3329. console.log('%d..%d', 1, total);
  3330. });
  3331. runner.on('test end', function () {
  3332. ++n;
  3333. });
  3334. runner.on('pending', function (test) {
  3335. console.log('ok %d %s # SKIP -', n, title(test));
  3336. });
  3337. runner.on('pass', function (test) {
  3338. passes++;
  3339. console.log('ok %d %s', n, title(test));
  3340. });
  3341. runner.on('fail', function (test, err) {
  3342. failures++;
  3343. console.log('not ok %d %s', n, title(test));
  3344. if (err.stack) {
  3345. console.log(err.stack.replace(/^/gm, ' '));
  3346. }
  3347. });
  3348. runner.on('end', function () {
  3349. console.log('# tests ' + (passes + failures));
  3350. console.log('# pass ' + passes);
  3351. console.log('# fail ' + failures);
  3352. });
  3353. }
  3354. /**
  3355. * Return a TAP-safe title of `test`
  3356. *
  3357. * @api private
  3358. * @param {Object} test
  3359. * @return {String}
  3360. */
  3361. function title (test) {
  3362. return test.fullTitle().replace(/#/g, '');
  3363. }
  3364. },{"./base":17}],32:[function(require,module,exports){
  3365. (function (process,global){
  3366. 'use strict';
  3367. /**
  3368. * Module dependencies.
  3369. */
  3370. var Base = require('./base');
  3371. var utils = require('../utils');
  3372. var inherits = utils.inherits;
  3373. var fs = require('fs');
  3374. var escape = utils.escape;
  3375. var mkdirp = require('mkdirp');
  3376. var path = require('path');
  3377. /**
  3378. * Save timer references to avoid Sinon interfering (see GH-237).
  3379. */
  3380. /* eslint-disable no-unused-vars, no-native-reassign */
  3381. var Date = global.Date;
  3382. var setTimeout = global.setTimeout;
  3383. var setInterval = global.setInterval;
  3384. var clearTimeout = global.clearTimeout;
  3385. var clearInterval = global.clearInterval;
  3386. /* eslint-enable no-unused-vars, no-native-reassign */
  3387. /**
  3388. * Expose `XUnit`.
  3389. */
  3390. exports = module.exports = XUnit;
  3391. /**
  3392. * Initialize a new `XUnit` reporter.
  3393. *
  3394. * @api public
  3395. * @param {Runner} runner
  3396. */
  3397. function XUnit (runner, options) {
  3398. Base.call(this, runner);
  3399. var stats = this.stats;
  3400. var tests = [];
  3401. var self = this;
  3402. if (options && options.reporterOptions && options.reporterOptions.output) {
  3403. if (!fs.createWriteStream) {
  3404. throw new Error('file output not supported in browser');
  3405. }
  3406. mkdirp.sync(path.dirname(options.reporterOptions.output));
  3407. self.fileStream = fs.createWriteStream(options.reporterOptions.output);
  3408. }
  3409. runner.on('pending', function (test) {
  3410. tests.push(test);
  3411. });
  3412. runner.on('pass', function (test) {
  3413. tests.push(test);
  3414. });
  3415. runner.on('fail', function (test) {
  3416. tests.push(test);
  3417. });
  3418. runner.on('end', function () {
  3419. self.write(tag('testsuite', {
  3420. name: 'Mocha Tests',
  3421. tests: stats.tests,
  3422. failures: stats.failures,
  3423. errors: stats.failures,
  3424. skipped: stats.tests - stats.failures - stats.passes,
  3425. timestamp: (new Date()).toUTCString(),
  3426. time: (stats.duration / 1000) || 0
  3427. }, false));
  3428. tests.forEach(function (t) {
  3429. self.test(t);
  3430. });
  3431. self.write('</testsuite>');
  3432. });
  3433. }
  3434. /**
  3435. * Inherit from `Base.prototype`.
  3436. */
  3437. inherits(XUnit, Base);
  3438. /**
  3439. * Override done to close the stream (if it's a file).
  3440. *
  3441. * @param failures
  3442. * @param {Function} fn
  3443. */
  3444. XUnit.prototype.done = function (failures, fn) {
  3445. if (this.fileStream) {
  3446. this.fileStream.end(function () {
  3447. fn(failures);
  3448. });
  3449. } else {
  3450. fn(failures);
  3451. }
  3452. };
  3453. /**
  3454. * Write out the given line.
  3455. *
  3456. * @param {string} line
  3457. */
  3458. XUnit.prototype.write = function (line) {
  3459. if (this.fileStream) {
  3460. this.fileStream.write(line + '\n');
  3461. } else if (typeof process === 'object' && process.stdout) {
  3462. process.stdout.write(line + '\n');
  3463. } else {
  3464. console.log(line);
  3465. }
  3466. };
  3467. /**
  3468. * Output tag for the given `test.`
  3469. *
  3470. * @param {Test} test
  3471. */
  3472. XUnit.prototype.test = function (test) {
  3473. var attrs = {
  3474. classname: test.parent.fullTitle(),
  3475. name: test.title,
  3476. time: (test.duration / 1000) || 0
  3477. };
  3478. if (test.state === 'failed') {
  3479. var err = test.err;
  3480. this.write(tag('testcase', attrs, false, tag('failure', {}, false, escape(err.message) + '\n' + escape(err.stack))));
  3481. } else if (test.isPending()) {
  3482. this.write(tag('testcase', attrs, false, tag('skipped', {}, true)));
  3483. } else {
  3484. this.write(tag('testcase', attrs, true));
  3485. }
  3486. };
  3487. /**
  3488. * HTML tag helper.
  3489. *
  3490. * @param name
  3491. * @param attrs
  3492. * @param close
  3493. * @param content
  3494. * @return {string}
  3495. */
  3496. function tag (name, attrs, close, content) {
  3497. var end = close ? '/>' : '>';
  3498. var pairs = [];
  3499. var tag;
  3500. for (var key in attrs) {
  3501. if (Object.prototype.hasOwnProperty.call(attrs, key)) {
  3502. pairs.push(key + '="' + escape(attrs[key]) + '"');
  3503. }
  3504. }
  3505. tag = '<' + name + (pairs.length ? ' ' + pairs.join(' ') : '') + end;
  3506. if (content) {
  3507. tag += content + '</' + name + end;
  3508. }
  3509. return tag;
  3510. }
  3511. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3512. },{"../utils":38,"./base":17,"_process":67,"fs":42,"mkdirp":64,"path":42}],33:[function(require,module,exports){
  3513. (function (global){
  3514. 'use strict';
  3515. /**
  3516. * Module dependencies.
  3517. */
  3518. var EventEmitter = require('events').EventEmitter;
  3519. var JSON = require('json3');
  3520. var Pending = require('./pending');
  3521. var debug = require('debug')('mocha:runnable');
  3522. var milliseconds = require('./ms');
  3523. var utils = require('./utils');
  3524. var create = require('lodash.create');
  3525. /**
  3526. * Save timer references to avoid Sinon interfering (see GH-237).
  3527. */
  3528. /* eslint-disable no-unused-vars, no-native-reassign */
  3529. var Date = global.Date;
  3530. var setTimeout = global.setTimeout;
  3531. var setInterval = global.setInterval;
  3532. var clearTimeout = global.clearTimeout;
  3533. var clearInterval = global.clearInterval;
  3534. /* eslint-enable no-unused-vars, no-native-reassign */
  3535. /**
  3536. * Object#toString().
  3537. */
  3538. var toString = Object.prototype.toString;
  3539. /**
  3540. * Expose `Runnable`.
  3541. */
  3542. module.exports = Runnable;
  3543. /**
  3544. * Initialize a new `Runnable` with the given `title` and callback `fn`.
  3545. *
  3546. * @param {String} title
  3547. * @param {Function} fn
  3548. * @api private
  3549. * @param {string} title
  3550. * @param {Function} fn
  3551. */
  3552. function Runnable (title, fn) {
  3553. this.title = title;
  3554. this.fn = fn;
  3555. this.body = (fn || '').toString();
  3556. this.async = fn && fn.length;
  3557. this.sync = !this.async;
  3558. this._timeout = 2000;
  3559. this._slow = 75;
  3560. this._enableTimeouts = true;
  3561. this.timedOut = false;
  3562. this._trace = new Error('done() called multiple times');
  3563. this._retries = -1;
  3564. this._currentRetry = 0;
  3565. this.pending = false;
  3566. }
  3567. /**
  3568. * Inherit from `EventEmitter.prototype`.
  3569. */
  3570. Runnable.prototype = create(EventEmitter.prototype, {
  3571. constructor: Runnable
  3572. });
  3573. /**
  3574. * Set & get timeout `ms`.
  3575. *
  3576. * @api private
  3577. * @param {number|string} ms
  3578. * @return {Runnable|number} ms or Runnable instance.
  3579. */
  3580. Runnable.prototype.timeout = function (ms) {
  3581. if (!arguments.length) {
  3582. return this._timeout;
  3583. }
  3584. // see #1652 for reasoning
  3585. if (ms === 0 || ms > Math.pow(2, 31)) {
  3586. this._enableTimeouts = false;
  3587. }
  3588. if (typeof ms === 'string') {
  3589. ms = milliseconds(ms);
  3590. }
  3591. debug('timeout %d', ms);
  3592. this._timeout = ms;
  3593. if (this.timer) {
  3594. this.resetTimeout();
  3595. }
  3596. return this;
  3597. };
  3598. /**
  3599. * Set & get slow `ms`.
  3600. *
  3601. * @api private
  3602. * @param {number|string} ms
  3603. * @return {Runnable|number} ms or Runnable instance.
  3604. */
  3605. Runnable.prototype.slow = function (ms) {
  3606. if (typeof ms === 'undefined') {
  3607. return this._slow;
  3608. }
  3609. if (typeof ms === 'string') {
  3610. ms = milliseconds(ms);
  3611. }
  3612. debug('timeout %d', ms);
  3613. this._slow = ms;
  3614. return this;
  3615. };
  3616. /**
  3617. * Set and get whether timeout is `enabled`.
  3618. *
  3619. * @api private
  3620. * @param {boolean} enabled
  3621. * @return {Runnable|boolean} enabled or Runnable instance.
  3622. */
  3623. Runnable.prototype.enableTimeouts = function (enabled) {
  3624. if (!arguments.length) {
  3625. return this._enableTimeouts;
  3626. }
  3627. debug('enableTimeouts %s', enabled);
  3628. this._enableTimeouts = enabled;
  3629. return this;
  3630. };
  3631. /**
  3632. * Halt and mark as pending.
  3633. *
  3634. * @api public
  3635. */
  3636. Runnable.prototype.skip = function () {
  3637. throw new Pending('sync skip');
  3638. };
  3639. /**
  3640. * Check if this runnable or its parent suite is marked as pending.
  3641. *
  3642. * @api private
  3643. */
  3644. Runnable.prototype.isPending = function () {
  3645. return this.pending || (this.parent && this.parent.isPending());
  3646. };
  3647. /**
  3648. * Set number of retries.
  3649. *
  3650. * @api private
  3651. */
  3652. Runnable.prototype.retries = function (n) {
  3653. if (!arguments.length) {
  3654. return this._retries;
  3655. }
  3656. this._retries = n;
  3657. };
  3658. /**
  3659. * Get current retry
  3660. *
  3661. * @api private
  3662. */
  3663. Runnable.prototype.currentRetry = function (n) {
  3664. if (!arguments.length) {
  3665. return this._currentRetry;
  3666. }
  3667. this._currentRetry = n;
  3668. };
  3669. /**
  3670. * Return the full title generated by recursively concatenating the parent's
  3671. * full title.
  3672. *
  3673. * @api public
  3674. * @return {string}
  3675. */
  3676. Runnable.prototype.fullTitle = function () {
  3677. return this.parent.fullTitle() + ' ' + this.title;
  3678. };
  3679. /**
  3680. * Clear the timeout.
  3681. *
  3682. * @api private
  3683. */
  3684. Runnable.prototype.clearTimeout = function () {
  3685. clearTimeout(this.timer);
  3686. };
  3687. /**
  3688. * Inspect the runnable void of private properties.
  3689. *
  3690. * @api private
  3691. * @return {string}
  3692. */
  3693. Runnable.prototype.inspect = function () {
  3694. return JSON.stringify(this, function (key, val) {
  3695. if (key[0] === '_') {
  3696. return;
  3697. }
  3698. if (key === 'parent') {
  3699. return '#<Suite>';
  3700. }
  3701. if (key === 'ctx') {
  3702. return '#<Context>';
  3703. }
  3704. return val;
  3705. }, 2);
  3706. };
  3707. /**
  3708. * Reset the timeout.
  3709. *
  3710. * @api private
  3711. */
  3712. Runnable.prototype.resetTimeout = function () {
  3713. var self = this;
  3714. var ms = this.timeout() || 1e9;
  3715. if (!this._enableTimeouts) {
  3716. return;
  3717. }
  3718. this.clearTimeout();
  3719. this.timer = setTimeout(function () {
  3720. if (!self._enableTimeouts) {
  3721. return;
  3722. }
  3723. self.callback(new Error('Timeout of ' + ms +
  3724. 'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.'));
  3725. self.timedOut = true;
  3726. }, ms);
  3727. };
  3728. /**
  3729. * Whitelist a list of globals for this test run.
  3730. *
  3731. * @api private
  3732. * @param {string[]} globals
  3733. */
  3734. Runnable.prototype.globals = function (globals) {
  3735. if (!arguments.length) {
  3736. return this._allowedGlobals;
  3737. }
  3738. this._allowedGlobals = globals;
  3739. };
  3740. /**
  3741. * Run the test and invoke `fn(err)`.
  3742. *
  3743. * @param {Function} fn
  3744. * @api private
  3745. */
  3746. Runnable.prototype.run = function (fn) {
  3747. var self = this;
  3748. var start = new Date();
  3749. var ctx = this.ctx;
  3750. var finished;
  3751. var emitted;
  3752. // Sometimes the ctx exists, but it is not runnable
  3753. if (ctx && ctx.runnable) {
  3754. ctx.runnable(this);
  3755. }
  3756. // called multiple times
  3757. function multiple (err) {
  3758. if (emitted) {
  3759. return;
  3760. }
  3761. emitted = true;
  3762. self.emit('error', err || new Error('done() called multiple times; stacktrace may be inaccurate'));
  3763. }
  3764. // finished
  3765. function done (err) {
  3766. var ms = self.timeout();
  3767. if (self.timedOut) {
  3768. return;
  3769. }
  3770. if (finished) {
  3771. return multiple(err || self._trace);
  3772. }
  3773. self.clearTimeout();
  3774. self.duration = new Date() - start;
  3775. finished = true;
  3776. if (!err && self.duration > ms && self._enableTimeouts) {
  3777. err = new Error('Timeout of ' + ms +
  3778. 'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.');
  3779. }
  3780. fn(err);
  3781. }
  3782. // for .resetTimeout()
  3783. this.callback = done;
  3784. // explicit async with `done` argument
  3785. if (this.async) {
  3786. this.resetTimeout();
  3787. // allows skip() to be used in an explicit async context
  3788. this.skip = function asyncSkip () {
  3789. done(new Pending('async skip call'));
  3790. // halt execution. the Runnable will be marked pending
  3791. // by the previous call, and the uncaught handler will ignore
  3792. // the failure.
  3793. throw new Pending('async skip; aborting execution');
  3794. };
  3795. if (this.allowUncaught) {
  3796. return callFnAsync(this.fn);
  3797. }
  3798. try {
  3799. callFnAsync(this.fn);
  3800. } catch (err) {
  3801. emitted = true;
  3802. done(utils.getError(err));
  3803. }
  3804. return;
  3805. }
  3806. if (this.allowUncaught) {
  3807. callFn(this.fn);
  3808. done();
  3809. return;
  3810. }
  3811. // sync or promise-returning
  3812. try {
  3813. if (this.isPending()) {
  3814. done();
  3815. } else {
  3816. callFn(this.fn);
  3817. }
  3818. } catch (err) {
  3819. emitted = true;
  3820. done(utils.getError(err));
  3821. }
  3822. function callFn (fn) {
  3823. var result = fn.call(ctx);
  3824. if (result && typeof result.then === 'function') {
  3825. self.resetTimeout();
  3826. result
  3827. .then(function () {
  3828. done();
  3829. // Return null so libraries like bluebird do not warn about
  3830. // subsequently constructed Promises.
  3831. return null;
  3832. },
  3833. function (reason) {
  3834. done(reason || new Error('Promise rejected with no or falsy reason'));
  3835. });
  3836. } else {
  3837. if (self.asyncOnly) {
  3838. return done(new Error('--async-only option in use without declaring `done()` or returning a promise'));
  3839. }
  3840. done();
  3841. }
  3842. }
  3843. function callFnAsync (fn) {
  3844. var result = fn.call(ctx, function (err) {
  3845. if (err instanceof Error || toString.call(err) === '[object Error]') {
  3846. return done(err);
  3847. }
  3848. if (err) {
  3849. if (Object.prototype.toString.call(err) === '[object Object]') {
  3850. return done(new Error('done() invoked with non-Error: ' +
  3851. JSON.stringify(err)));
  3852. }
  3853. return done(new Error('done() invoked with non-Error: ' + err));
  3854. }
  3855. if (result && utils.isPromise(result)) {
  3856. return done(new Error('Resolution method is overspecified. Specify a callback *or* return a Promise; not both.'));
  3857. }
  3858. done();
  3859. });
  3860. }
  3861. };
  3862. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3863. },{"./ms":15,"./pending":16,"./utils":38,"debug":2,"events":3,"json3":54,"lodash.create":60}],34:[function(require,module,exports){
  3864. (function (process,global){
  3865. 'use strict';
  3866. /**
  3867. * Module dependencies.
  3868. */
  3869. var EventEmitter = require('events').EventEmitter;
  3870. var Pending = require('./pending');
  3871. var utils = require('./utils');
  3872. var inherits = utils.inherits;
  3873. var debug = require('debug')('mocha:runner');
  3874. var Runnable = require('./runnable');
  3875. var filter = utils.filter;
  3876. var indexOf = utils.indexOf;
  3877. var some = utils.some;
  3878. var keys = utils.keys;
  3879. var stackFilter = utils.stackTraceFilter();
  3880. var stringify = utils.stringify;
  3881. var type = utils.type;
  3882. var undefinedError = utils.undefinedError;
  3883. var isArray = utils.isArray;
  3884. /**
  3885. * Non-enumerable globals.
  3886. */
  3887. var globals = [
  3888. 'setTimeout',
  3889. 'clearTimeout',
  3890. 'setInterval',
  3891. 'clearInterval',
  3892. 'XMLHttpRequest',
  3893. 'Date',
  3894. 'setImmediate',
  3895. 'clearImmediate'
  3896. ];
  3897. /**
  3898. * Expose `Runner`.
  3899. */
  3900. module.exports = Runner;
  3901. /**
  3902. * Initialize a `Runner` for the given `suite`.
  3903. *
  3904. * Events:
  3905. *
  3906. * - `start` execution started
  3907. * - `end` execution complete
  3908. * - `suite` (suite) test suite execution started
  3909. * - `suite end` (suite) all tests (and sub-suites) have finished
  3910. * - `test` (test) test execution started
  3911. * - `test end` (test) test completed
  3912. * - `hook` (hook) hook execution started
  3913. * - `hook end` (hook) hook complete
  3914. * - `pass` (test) test passed
  3915. * - `fail` (test, err) test failed
  3916. * - `pending` (test) test pending
  3917. *
  3918. * @api public
  3919. * @param {Suite} suite Root suite
  3920. * @param {boolean} [delay] Whether or not to delay execution of root suite
  3921. * until ready.
  3922. */
  3923. function Runner (suite, delay) {
  3924. var self = this;
  3925. this._globals = [];
  3926. this._abort = false;
  3927. this._delay = delay;
  3928. this.suite = suite;
  3929. this.started = false;
  3930. this.total = suite.total();
  3931. this.failures = 0;
  3932. this.on('test end', function (test) {
  3933. self.checkGlobals(test);
  3934. });
  3935. this.on('hook end', function (hook) {
  3936. self.checkGlobals(hook);
  3937. });
  3938. this._defaultGrep = /.*/;
  3939. this.grep(this._defaultGrep);
  3940. this.globals(this.globalProps().concat(extraGlobals()));
  3941. }
  3942. /**
  3943. * Wrapper for setImmediate, process.nextTick, or browser polyfill.
  3944. *
  3945. * @param {Function} fn
  3946. * @api private
  3947. */
  3948. Runner.immediately = global.setImmediate || process.nextTick;
  3949. /**
  3950. * Inherit from `EventEmitter.prototype`.
  3951. */
  3952. inherits(Runner, EventEmitter);
  3953. /**
  3954. * Run tests with full titles matching `re`. Updates runner.total
  3955. * with number of tests matched.
  3956. *
  3957. * @param {RegExp} re
  3958. * @param {Boolean} invert
  3959. * @return {Runner} for chaining
  3960. * @api public
  3961. * @param {RegExp} re
  3962. * @param {boolean} invert
  3963. * @return {Runner} Runner instance.
  3964. */
  3965. Runner.prototype.grep = function (re, invert) {
  3966. debug('grep %s', re);
  3967. this._grep = re;
  3968. this._invert = invert;
  3969. this.total = this.grepTotal(this.suite);
  3970. return this;
  3971. };
  3972. /**
  3973. * Returns the number of tests matching the grep search for the
  3974. * given suite.
  3975. *
  3976. * @param {Suite} suite
  3977. * @return {Number}
  3978. * @api public
  3979. * @param {Suite} suite
  3980. * @return {number}
  3981. */
  3982. Runner.prototype.grepTotal = function (suite) {
  3983. var self = this;
  3984. var total = 0;
  3985. suite.eachTest(function (test) {
  3986. var match = self._grep.test(test.fullTitle());
  3987. if (self._invert) {
  3988. match = !match;
  3989. }
  3990. if (match) {
  3991. total++;
  3992. }
  3993. });
  3994. return total;
  3995. };
  3996. /**
  3997. * Return a list of global properties.
  3998. *
  3999. * @return {Array}
  4000. * @api private
  4001. */
  4002. Runner.prototype.globalProps = function () {
  4003. var props = keys(global);
  4004. // non-enumerables
  4005. for (var i = 0; i < globals.length; ++i) {
  4006. if (~indexOf(props, globals[i])) {
  4007. continue;
  4008. }
  4009. props.push(globals[i]);
  4010. }
  4011. return props;
  4012. };
  4013. /**
  4014. * Allow the given `arr` of globals.
  4015. *
  4016. * @param {Array} arr
  4017. * @return {Runner} for chaining
  4018. * @api public
  4019. * @param {Array} arr
  4020. * @return {Runner} Runner instance.
  4021. */
  4022. Runner.prototype.globals = function (arr) {
  4023. if (!arguments.length) {
  4024. return this._globals;
  4025. }
  4026. debug('globals %j', arr);
  4027. this._globals = this._globals.concat(arr);
  4028. return this;
  4029. };
  4030. /**
  4031. * Check for global variable leaks.
  4032. *
  4033. * @api private
  4034. */
  4035. Runner.prototype.checkGlobals = function (test) {
  4036. if (this.ignoreLeaks) {
  4037. return;
  4038. }
  4039. var ok = this._globals;
  4040. var globals = this.globalProps();
  4041. var leaks;
  4042. if (test) {
  4043. ok = ok.concat(test._allowedGlobals || []);
  4044. }
  4045. if (this.prevGlobalsLength === globals.length) {
  4046. return;
  4047. }
  4048. this.prevGlobalsLength = globals.length;
  4049. leaks = filterLeaks(ok, globals);
  4050. this._globals = this._globals.concat(leaks);
  4051. if (leaks.length > 1) {
  4052. this.fail(test, new Error('global leaks detected: ' + leaks.join(', ') + ''));
  4053. } else if (leaks.length) {
  4054. this.fail(test, new Error('global leak detected: ' + leaks[0]));
  4055. }
  4056. };
  4057. /**
  4058. * Fail the given `test`.
  4059. *
  4060. * @api private
  4061. * @param {Test} test
  4062. * @param {Error} err
  4063. */
  4064. Runner.prototype.fail = function (test, err) {
  4065. if (test.isPending()) {
  4066. return;
  4067. }
  4068. ++this.failures;
  4069. test.state = 'failed';
  4070. if (!(err instanceof Error || err && typeof err.message === 'string')) {
  4071. err = new Error('the ' + type(err) + ' ' + stringify(err) + ' was thrown, throw an Error :)');
  4072. }
  4073. try {
  4074. err.stack = (this.fullStackTrace || !err.stack)
  4075. ? err.stack
  4076. : stackFilter(err.stack);
  4077. } catch (ignored) {
  4078. // some environments do not take kindly to monkeying with the stack
  4079. }
  4080. this.emit('fail', test, err);
  4081. };
  4082. /**
  4083. * Fail the given `hook` with `err`.
  4084. *
  4085. * Hook failures work in the following pattern:
  4086. * - If bail, then exit
  4087. * - Failed `before` hook skips all tests in a suite and subsuites,
  4088. * but jumps to corresponding `after` hook
  4089. * - Failed `before each` hook skips remaining tests in a
  4090. * suite and jumps to corresponding `after each` hook,
  4091. * which is run only once
  4092. * - Failed `after` hook does not alter
  4093. * execution order
  4094. * - Failed `after each` hook skips remaining tests in a
  4095. * suite and subsuites, but executes other `after each`
  4096. * hooks
  4097. *
  4098. * @api private
  4099. * @param {Hook} hook
  4100. * @param {Error} err
  4101. */
  4102. Runner.prototype.failHook = function (hook, err) {
  4103. if (hook.ctx && hook.ctx.currentTest) {
  4104. hook.originalTitle = hook.originalTitle || hook.title;
  4105. hook.title = hook.originalTitle + ' for "' + hook.ctx.currentTest.title + '"';
  4106. }
  4107. this.fail(hook, err);
  4108. if (this.suite.bail()) {
  4109. this.emit('end');
  4110. }
  4111. };
  4112. /**
  4113. * Run hook `name` callbacks and then invoke `fn()`.
  4114. *
  4115. * @api private
  4116. * @param {string} name
  4117. * @param {Function} fn
  4118. */
  4119. Runner.prototype.hook = function (name, fn) {
  4120. var suite = this.suite;
  4121. var hooks = suite['_' + name];
  4122. var self = this;
  4123. function next (i) {
  4124. var hook = hooks[i];
  4125. if (!hook) {
  4126. return fn();
  4127. }
  4128. self.currentRunnable = hook;
  4129. hook.ctx.currentTest = self.test;
  4130. self.emit('hook', hook);
  4131. if (!hook.listeners('error').length) {
  4132. hook.on('error', function (err) {
  4133. self.failHook(hook, err);
  4134. });
  4135. }
  4136. hook.run(function (err) {
  4137. var testError = hook.error();
  4138. if (testError) {
  4139. self.fail(self.test, testError);
  4140. }
  4141. if (err) {
  4142. if (err instanceof Pending) {
  4143. if (name === 'beforeEach' || name === 'afterEach') {
  4144. self.test.pending = true;
  4145. } else {
  4146. utils.forEach(suite.tests, function (test) {
  4147. test.pending = true;
  4148. });
  4149. // a pending hook won't be executed twice.
  4150. hook.pending = true;
  4151. }
  4152. } else {
  4153. self.failHook(hook, err);
  4154. // stop executing hooks, notify callee of hook err
  4155. return fn(err);
  4156. }
  4157. }
  4158. self.emit('hook end', hook);
  4159. delete hook.ctx.currentTest;
  4160. next(++i);
  4161. });
  4162. }
  4163. Runner.immediately(function () {
  4164. next(0);
  4165. });
  4166. };
  4167. /**
  4168. * Run hook `name` for the given array of `suites`
  4169. * in order, and callback `fn(err, errSuite)`.
  4170. *
  4171. * @api private
  4172. * @param {string} name
  4173. * @param {Array} suites
  4174. * @param {Function} fn
  4175. */
  4176. Runner.prototype.hooks = function (name, suites, fn) {
  4177. var self = this;
  4178. var orig = this.suite;
  4179. function next (suite) {
  4180. self.suite = suite;
  4181. if (!suite) {
  4182. self.suite = orig;
  4183. return fn();
  4184. }
  4185. self.hook(name, function (err) {
  4186. if (err) {
  4187. var errSuite = self.suite;
  4188. self.suite = orig;
  4189. return fn(err, errSuite);
  4190. }
  4191. next(suites.pop());
  4192. });
  4193. }
  4194. next(suites.pop());
  4195. };
  4196. /**
  4197. * Run hooks from the top level down.
  4198. *
  4199. * @param {String} name
  4200. * @param {Function} fn
  4201. * @api private
  4202. */
  4203. Runner.prototype.hookUp = function (name, fn) {
  4204. var suites = [this.suite].concat(this.parents()).reverse();
  4205. this.hooks(name, suites, fn);
  4206. };
  4207. /**
  4208. * Run hooks from the bottom up.
  4209. *
  4210. * @param {String} name
  4211. * @param {Function} fn
  4212. * @api private
  4213. */
  4214. Runner.prototype.hookDown = function (name, fn) {
  4215. var suites = [this.suite].concat(this.parents());
  4216. this.hooks(name, suites, fn);
  4217. };
  4218. /**
  4219. * Return an array of parent Suites from
  4220. * closest to furthest.
  4221. *
  4222. * @return {Array}
  4223. * @api private
  4224. */
  4225. Runner.prototype.parents = function () {
  4226. var suite = this.suite;
  4227. var suites = [];
  4228. while (suite.parent) {
  4229. suite = suite.parent;
  4230. suites.push(suite);
  4231. }
  4232. return suites;
  4233. };
  4234. /**
  4235. * Run the current test and callback `fn(err)`.
  4236. *
  4237. * @param {Function} fn
  4238. * @api private
  4239. */
  4240. Runner.prototype.runTest = function (fn) {
  4241. var self = this;
  4242. var test = this.test;
  4243. if (!test) {
  4244. return;
  4245. }
  4246. if (this.asyncOnly) {
  4247. test.asyncOnly = true;
  4248. }
  4249. if (this.allowUncaught) {
  4250. test.allowUncaught = true;
  4251. return test.run(fn);
  4252. }
  4253. try {
  4254. test.on('error', function (err) {
  4255. self.fail(test, err);
  4256. });
  4257. test.run(fn);
  4258. } catch (err) {
  4259. fn(err);
  4260. }
  4261. };
  4262. /**
  4263. * Run tests in the given `suite` and invoke the callback `fn()` when complete.
  4264. *
  4265. * @api private
  4266. * @param {Suite} suite
  4267. * @param {Function} fn
  4268. */
  4269. Runner.prototype.runTests = function (suite, fn) {
  4270. var self = this;
  4271. var tests = suite.tests.slice();
  4272. var test;
  4273. function hookErr (_, errSuite, after) {
  4274. // before/after Each hook for errSuite failed:
  4275. var orig = self.suite;
  4276. // for failed 'after each' hook start from errSuite parent,
  4277. // otherwise start from errSuite itself
  4278. self.suite = after ? errSuite.parent : errSuite;
  4279. if (self.suite) {
  4280. // call hookUp afterEach
  4281. self.hookUp('afterEach', function (err2, errSuite2) {
  4282. self.suite = orig;
  4283. // some hooks may fail even now
  4284. if (err2) {
  4285. return hookErr(err2, errSuite2, true);
  4286. }
  4287. // report error suite
  4288. fn(errSuite);
  4289. });
  4290. } else {
  4291. // there is no need calling other 'after each' hooks
  4292. self.suite = orig;
  4293. fn(errSuite);
  4294. }
  4295. }
  4296. function next (err, errSuite) {
  4297. // if we bail after first err
  4298. if (self.failures && suite._bail) {
  4299. return fn();
  4300. }
  4301. if (self._abort) {
  4302. return fn();
  4303. }
  4304. if (err) {
  4305. return hookErr(err, errSuite, true);
  4306. }
  4307. // next test
  4308. test = tests.shift();
  4309. // all done
  4310. if (!test) {
  4311. return fn();
  4312. }
  4313. // grep
  4314. var match = self._grep.test(test.fullTitle());
  4315. if (self._invert) {
  4316. match = !match;
  4317. }
  4318. if (!match) {
  4319. // Run immediately only if we have defined a grep. When we
  4320. // define a grep — It can cause maximum callstack error if
  4321. // the grep is doing a large recursive loop by neglecting
  4322. // all tests. The run immediately function also comes with
  4323. // a performance cost. So we don't want to run immediately
  4324. // if we run the whole test suite, because running the whole
  4325. // test suite don't do any immediate recursive loops. Thus,
  4326. // allowing a JS runtime to breathe.
  4327. if (self._grep !== self._defaultGrep) {
  4328. Runner.immediately(next);
  4329. } else {
  4330. next();
  4331. }
  4332. return;
  4333. }
  4334. if (test.isPending()) {
  4335. self.emit('pending', test);
  4336. self.emit('test end', test);
  4337. return next();
  4338. }
  4339. // execute test and hook(s)
  4340. self.emit('test', self.test = test);
  4341. self.hookDown('beforeEach', function (err, errSuite) {
  4342. if (test.isPending()) {
  4343. self.emit('pending', test);
  4344. self.emit('test end', test);
  4345. return next();
  4346. }
  4347. if (err) {
  4348. return hookErr(err, errSuite, false);
  4349. }
  4350. self.currentRunnable = self.test;
  4351. self.runTest(function (err) {
  4352. test = self.test;
  4353. if (err) {
  4354. var retry = test.currentRetry();
  4355. if (err instanceof Pending) {
  4356. test.pending = true;
  4357. self.emit('pending', test);
  4358. } else if (retry < test.retries()) {
  4359. var clonedTest = test.clone();
  4360. clonedTest.currentRetry(retry + 1);
  4361. tests.unshift(clonedTest);
  4362. // Early return + hook trigger so that it doesn't
  4363. // increment the count wrong
  4364. return self.hookUp('afterEach', next);
  4365. } else {
  4366. self.fail(test, err);
  4367. }
  4368. self.emit('test end', test);
  4369. if (err instanceof Pending) {
  4370. return next();
  4371. }
  4372. return self.hookUp('afterEach', next);
  4373. }
  4374. test.state = 'passed';
  4375. self.emit('pass', test);
  4376. self.emit('test end', test);
  4377. self.hookUp('afterEach', next);
  4378. });
  4379. });
  4380. }
  4381. this.next = next;
  4382. this.hookErr = hookErr;
  4383. next();
  4384. };
  4385. /**
  4386. * Run the given `suite` and invoke the callback `fn()` when complete.
  4387. *
  4388. * @api private
  4389. * @param {Suite} suite
  4390. * @param {Function} fn
  4391. */
  4392. Runner.prototype.runSuite = function (suite, fn) {
  4393. var i = 0;
  4394. var self = this;
  4395. var total = this.grepTotal(suite);
  4396. var afterAllHookCalled = false;
  4397. debug('run suite %s', suite.fullTitle());
  4398. if (!total || (self.failures && suite._bail)) {
  4399. return fn();
  4400. }
  4401. this.emit('suite', this.suite = suite);
  4402. function next (errSuite) {
  4403. if (errSuite) {
  4404. // current suite failed on a hook from errSuite
  4405. if (errSuite === suite) {
  4406. // if errSuite is current suite
  4407. // continue to the next sibling suite
  4408. return done();
  4409. }
  4410. // errSuite is among the parents of current suite
  4411. // stop execution of errSuite and all sub-suites
  4412. return done(errSuite);
  4413. }
  4414. if (self._abort) {
  4415. return done();
  4416. }
  4417. var curr = suite.suites[i++];
  4418. if (!curr) {
  4419. return done();
  4420. }
  4421. // Avoid grep neglecting large number of tests causing a
  4422. // huge recursive loop and thus a maximum call stack error.
  4423. // See comment in `this.runTests()` for more information.
  4424. if (self._grep !== self._defaultGrep) {
  4425. Runner.immediately(function () {
  4426. self.runSuite(curr, next);
  4427. });
  4428. } else {
  4429. self.runSuite(curr, next);
  4430. }
  4431. }
  4432. function done (errSuite) {
  4433. self.suite = suite;
  4434. self.nextSuite = next;
  4435. if (afterAllHookCalled) {
  4436. fn(errSuite);
  4437. } else {
  4438. // mark that the afterAll block has been called once
  4439. // and so can be skipped if there is an error in it.
  4440. afterAllHookCalled = true;
  4441. // remove reference to test
  4442. delete self.test;
  4443. self.hook('afterAll', function () {
  4444. self.emit('suite end', suite);
  4445. fn(errSuite);
  4446. });
  4447. }
  4448. }
  4449. this.nextSuite = next;
  4450. this.hook('beforeAll', function (err) {
  4451. if (err) {
  4452. return done();
  4453. }
  4454. self.runTests(suite, next);
  4455. });
  4456. };
  4457. /**
  4458. * Handle uncaught exceptions.
  4459. *
  4460. * @param {Error} err
  4461. * @api private
  4462. */
  4463. Runner.prototype.uncaught = function (err) {
  4464. if (err) {
  4465. debug('uncaught exception %s', err !== function () {
  4466. return this;
  4467. }.call(err) ? err : (err.message || err));
  4468. } else {
  4469. debug('uncaught undefined exception');
  4470. err = undefinedError();
  4471. }
  4472. err.uncaught = true;
  4473. var runnable = this.currentRunnable;
  4474. if (!runnable) {
  4475. runnable = new Runnable('Uncaught error outside test suite');
  4476. runnable.parent = this.suite;
  4477. if (this.started) {
  4478. this.fail(runnable, err);
  4479. } else {
  4480. // Can't recover from this failure
  4481. this.emit('start');
  4482. this.fail(runnable, err);
  4483. this.emit('end');
  4484. }
  4485. return;
  4486. }
  4487. runnable.clearTimeout();
  4488. // Ignore errors if complete or pending
  4489. if (runnable.state || runnable.isPending()) {
  4490. return;
  4491. }
  4492. this.fail(runnable, err);
  4493. // recover from test
  4494. if (runnable.type === 'test') {
  4495. this.emit('test end', runnable);
  4496. this.hookUp('afterEach', this.next);
  4497. return;
  4498. }
  4499. // recover from hooks
  4500. if (runnable.type === 'hook') {
  4501. var errSuite = this.suite;
  4502. // if hook failure is in afterEach block
  4503. if (runnable.fullTitle().indexOf('after each') > -1) {
  4504. return this.hookErr(err, errSuite, true);
  4505. }
  4506. // if hook failure is in beforeEach block
  4507. if (runnable.fullTitle().indexOf('before each') > -1) {
  4508. return this.hookErr(err, errSuite, false);
  4509. }
  4510. // if hook failure is in after or before blocks
  4511. return this.nextSuite(errSuite);
  4512. }
  4513. // bail
  4514. this.emit('end');
  4515. };
  4516. /**
  4517. * Cleans up the references to all the deferred functions
  4518. * (before/after/beforeEach/afterEach) and tests of a Suite.
  4519. * These must be deleted otherwise a memory leak can happen,
  4520. * as those functions may reference variables from closures,
  4521. * thus those variables can never be garbage collected as long
  4522. * as the deferred functions exist.
  4523. *
  4524. * @param {Suite} suite
  4525. */
  4526. function cleanSuiteReferences (suite) {
  4527. function cleanArrReferences (arr) {
  4528. for (var i = 0; i < arr.length; i++) {
  4529. delete arr[i].fn;
  4530. }
  4531. }
  4532. if (isArray(suite._beforeAll)) {
  4533. cleanArrReferences(suite._beforeAll);
  4534. }
  4535. if (isArray(suite._beforeEach)) {
  4536. cleanArrReferences(suite._beforeEach);
  4537. }
  4538. if (isArray(suite._afterAll)) {
  4539. cleanArrReferences(suite._afterAll);
  4540. }
  4541. if (isArray(suite._afterEach)) {
  4542. cleanArrReferences(suite._afterEach);
  4543. }
  4544. for (var i = 0; i < suite.tests.length; i++) {
  4545. delete suite.tests[i].fn;
  4546. }
  4547. }
  4548. /**
  4549. * Run the root suite and invoke `fn(failures)`
  4550. * on completion.
  4551. *
  4552. * @param {Function} fn
  4553. * @return {Runner} for chaining
  4554. * @api public
  4555. * @param {Function} fn
  4556. * @return {Runner} Runner instance.
  4557. */
  4558. Runner.prototype.run = function (fn) {
  4559. var self = this;
  4560. var rootSuite = this.suite;
  4561. // If there is an `only` filter
  4562. if (this.hasOnly) {
  4563. filterOnly(rootSuite);
  4564. }
  4565. fn = fn || function () {};
  4566. function uncaught (err) {
  4567. self.uncaught(err);
  4568. }
  4569. function start () {
  4570. self.started = true;
  4571. self.emit('start');
  4572. self.runSuite(rootSuite, function () {
  4573. debug('finished running');
  4574. self.emit('end');
  4575. });
  4576. }
  4577. debug('start');
  4578. // references cleanup to avoid memory leaks
  4579. this.on('suite end', cleanSuiteReferences);
  4580. // callback
  4581. this.on('end', function () {
  4582. debug('end');
  4583. process.removeListener('uncaughtException', uncaught);
  4584. fn(self.failures);
  4585. });
  4586. // uncaught exception
  4587. process.on('uncaughtException', uncaught);
  4588. if (this._delay) {
  4589. // for reporters, I guess.
  4590. // might be nice to debounce some dots while we wait.
  4591. this.emit('waiting', rootSuite);
  4592. rootSuite.once('run', start);
  4593. } else {
  4594. start();
  4595. }
  4596. return this;
  4597. };
  4598. /**
  4599. * Cleanly abort execution.
  4600. *
  4601. * @api public
  4602. * @return {Runner} Runner instance.
  4603. */
  4604. Runner.prototype.abort = function () {
  4605. debug('aborting');
  4606. this._abort = true;
  4607. return this;
  4608. };
  4609. /**
  4610. * Filter suites based on `isOnly` logic.
  4611. *
  4612. * @param {Array} suite
  4613. * @returns {Boolean}
  4614. * @api private
  4615. */
  4616. function filterOnly (suite) {
  4617. if (suite._onlyTests.length) {
  4618. // If the suite contains `only` tests, run those and ignore any nested suites.
  4619. suite.tests = suite._onlyTests;
  4620. suite.suites = [];
  4621. } else {
  4622. // Otherwise, do not run any of the tests in this suite.
  4623. suite.tests = [];
  4624. utils.forEach(suite._onlySuites, function (onlySuite) {
  4625. // If there are other `only` tests/suites nested in the current `only` suite, then filter that `only` suite.
  4626. // Otherwise, all of the tests on this `only` suite should be run, so don't filter it.
  4627. if (hasOnly(onlySuite)) {
  4628. filterOnly(onlySuite);
  4629. }
  4630. });
  4631. // Run the `only` suites, as well as any other suites that have `only` tests/suites as descendants.
  4632. suite.suites = filter(suite.suites, function (childSuite) {
  4633. return indexOf(suite._onlySuites, childSuite) !== -1 || filterOnly(childSuite);
  4634. });
  4635. }
  4636. // Keep the suite only if there is something to run
  4637. return suite.tests.length || suite.suites.length;
  4638. }
  4639. /**
  4640. * Determines whether a suite has an `only` test or suite as a descendant.
  4641. *
  4642. * @param {Array} suite
  4643. * @returns {Boolean}
  4644. * @api private
  4645. */
  4646. function hasOnly (suite) {
  4647. return suite._onlyTests.length || suite._onlySuites.length || some(suite.suites, hasOnly);
  4648. }
  4649. /**
  4650. * Filter leaks with the given globals flagged as `ok`.
  4651. *
  4652. * @api private
  4653. * @param {Array} ok
  4654. * @param {Array} globals
  4655. * @return {Array}
  4656. */
  4657. function filterLeaks (ok, globals) {
  4658. return filter(globals, function (key) {
  4659. // Firefox and Chrome exposes iframes as index inside the window object
  4660. if (/^\d+/.test(key)) {
  4661. return false;
  4662. }
  4663. // in firefox
  4664. // if runner runs in an iframe, this iframe's window.getInterface method
  4665. // not init at first it is assigned in some seconds
  4666. if (global.navigator && (/^getInterface/).test(key)) {
  4667. return false;
  4668. }
  4669. // an iframe could be approached by window[iframeIndex]
  4670. // in ie6,7,8 and opera, iframeIndex is enumerable, this could cause leak
  4671. if (global.navigator && (/^\d+/).test(key)) {
  4672. return false;
  4673. }
  4674. // Opera and IE expose global variables for HTML element IDs (issue #243)
  4675. if (/^mocha-/.test(key)) {
  4676. return false;
  4677. }
  4678. var matched = filter(ok, function (ok) {
  4679. if (~ok.indexOf('*')) {
  4680. return key.indexOf(ok.split('*')[0]) === 0;
  4681. }
  4682. return key === ok;
  4683. });
  4684. return !matched.length && (!global.navigator || key !== 'onerror');
  4685. });
  4686. }
  4687. /**
  4688. * Array of globals dependent on the environment.
  4689. *
  4690. * @return {Array}
  4691. * @api private
  4692. */
  4693. function extraGlobals () {
  4694. if (typeof process === 'object' && typeof process.version === 'string') {
  4695. var parts = process.version.split('.');
  4696. var nodeVersion = utils.reduce(parts, function (a, v) {
  4697. return a << 8 | v;
  4698. });
  4699. // 'errno' was renamed to process._errno in v0.9.11.
  4700. if (nodeVersion < 0x00090B) {
  4701. return ['errno'];
  4702. }
  4703. }
  4704. return [];
  4705. }
  4706. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  4707. },{"./pending":16,"./runnable":33,"./utils":38,"_process":67,"debug":2,"events":3}],35:[function(require,module,exports){
  4708. 'use strict';
  4709. /**
  4710. * Module dependencies.
  4711. */
  4712. var EventEmitter = require('events').EventEmitter;
  4713. var Hook = require('./hook');
  4714. var utils = require('./utils');
  4715. var inherits = utils.inherits;
  4716. var debug = require('debug')('mocha:suite');
  4717. var milliseconds = require('./ms');
  4718. /**
  4719. * Expose `Suite`.
  4720. */
  4721. exports = module.exports = Suite;
  4722. /**
  4723. * Create a new `Suite` with the given `title` and parent `Suite`. When a suite
  4724. * with the same title is already present, that suite is returned to provide
  4725. * nicer reporter and more flexible meta-testing.
  4726. *
  4727. * @api public
  4728. * @param {Suite} parent
  4729. * @param {string} title
  4730. * @return {Suite}
  4731. */
  4732. exports.create = function (parent, title) {
  4733. var suite = new Suite(title, parent.ctx);
  4734. suite.parent = parent;
  4735. title = suite.fullTitle();
  4736. parent.addSuite(suite);
  4737. return suite;
  4738. };
  4739. /**
  4740. * Initialize a new `Suite` with the given `title` and `ctx`.
  4741. *
  4742. * @api private
  4743. * @param {string} title
  4744. * @param {Context} parentContext
  4745. */
  4746. function Suite (title, parentContext) {
  4747. if (!utils.isString(title)) {
  4748. throw new Error('Suite `title` should be a "string" but "' + typeof title + '" was given instead.');
  4749. }
  4750. this.title = title;
  4751. function Context () {}
  4752. Context.prototype = parentContext;
  4753. this.ctx = new Context();
  4754. this.suites = [];
  4755. this.tests = [];
  4756. this.pending = false;
  4757. this._beforeEach = [];
  4758. this._beforeAll = [];
  4759. this._afterEach = [];
  4760. this._afterAll = [];
  4761. this.root = !title;
  4762. this._timeout = 2000;
  4763. this._enableTimeouts = true;
  4764. this._slow = 75;
  4765. this._bail = false;
  4766. this._retries = -1;
  4767. this._onlyTests = [];
  4768. this._onlySuites = [];
  4769. this.delayed = false;
  4770. }
  4771. /**
  4772. * Inherit from `EventEmitter.prototype`.
  4773. */
  4774. inherits(Suite, EventEmitter);
  4775. /**
  4776. * Return a clone of this `Suite`.
  4777. *
  4778. * @api private
  4779. * @return {Suite}
  4780. */
  4781. Suite.prototype.clone = function () {
  4782. var suite = new Suite(this.title);
  4783. debug('clone');
  4784. suite.ctx = this.ctx;
  4785. suite.timeout(this.timeout());
  4786. suite.retries(this.retries());
  4787. suite.enableTimeouts(this.enableTimeouts());
  4788. suite.slow(this.slow());
  4789. suite.bail(this.bail());
  4790. return suite;
  4791. };
  4792. /**
  4793. * Set timeout `ms` or short-hand such as "2s".
  4794. *
  4795. * @api private
  4796. * @param {number|string} ms
  4797. * @return {Suite|number} for chaining
  4798. */
  4799. Suite.prototype.timeout = function (ms) {
  4800. if (!arguments.length) {
  4801. return this._timeout;
  4802. }
  4803. if (ms.toString() === '0') {
  4804. this._enableTimeouts = false;
  4805. }
  4806. if (typeof ms === 'string') {
  4807. ms = milliseconds(ms);
  4808. }
  4809. debug('timeout %d', ms);
  4810. this._timeout = parseInt(ms, 10);
  4811. return this;
  4812. };
  4813. /**
  4814. * Set number of times to retry a failed test.
  4815. *
  4816. * @api private
  4817. * @param {number|string} n
  4818. * @return {Suite|number} for chaining
  4819. */
  4820. Suite.prototype.retries = function (n) {
  4821. if (!arguments.length) {
  4822. return this._retries;
  4823. }
  4824. debug('retries %d', n);
  4825. this._retries = parseInt(n, 10) || 0;
  4826. return this;
  4827. };
  4828. /**
  4829. * Set timeout to `enabled`.
  4830. *
  4831. * @api private
  4832. * @param {boolean} enabled
  4833. * @return {Suite|boolean} self or enabled
  4834. */
  4835. Suite.prototype.enableTimeouts = function (enabled) {
  4836. if (!arguments.length) {
  4837. return this._enableTimeouts;
  4838. }
  4839. debug('enableTimeouts %s', enabled);
  4840. this._enableTimeouts = enabled;
  4841. return this;
  4842. };
  4843. /**
  4844. * Set slow `ms` or short-hand such as "2s".
  4845. *
  4846. * @api private
  4847. * @param {number|string} ms
  4848. * @return {Suite|number} for chaining
  4849. */
  4850. Suite.prototype.slow = function (ms) {
  4851. if (!arguments.length) {
  4852. return this._slow;
  4853. }
  4854. if (typeof ms === 'string') {
  4855. ms = milliseconds(ms);
  4856. }
  4857. debug('slow %d', ms);
  4858. this._slow = ms;
  4859. return this;
  4860. };
  4861. /**
  4862. * Sets whether to bail after first error.
  4863. *
  4864. * @api private
  4865. * @param {boolean} bail
  4866. * @return {Suite|number} for chaining
  4867. */
  4868. Suite.prototype.bail = function (bail) {
  4869. if (!arguments.length) {
  4870. return this._bail;
  4871. }
  4872. debug('bail %s', bail);
  4873. this._bail = bail;
  4874. return this;
  4875. };
  4876. /**
  4877. * Check if this suite or its parent suite is marked as pending.
  4878. *
  4879. * @api private
  4880. */
  4881. Suite.prototype.isPending = function () {
  4882. return this.pending || (this.parent && this.parent.isPending());
  4883. };
  4884. /**
  4885. * Run `fn(test[, done])` before running tests.
  4886. *
  4887. * @api private
  4888. * @param {string} title
  4889. * @param {Function} fn
  4890. * @return {Suite} for chaining
  4891. */
  4892. Suite.prototype.beforeAll = function (title, fn) {
  4893. if (this.isPending()) {
  4894. return this;
  4895. }
  4896. if (typeof title === 'function') {
  4897. fn = title;
  4898. title = fn.name;
  4899. }
  4900. title = '"before all" hook' + (title ? ': ' + title : '');
  4901. var hook = new Hook(title, fn);
  4902. hook.parent = this;
  4903. hook.timeout(this.timeout());
  4904. hook.retries(this.retries());
  4905. hook.enableTimeouts(this.enableTimeouts());
  4906. hook.slow(this.slow());
  4907. hook.ctx = this.ctx;
  4908. this._beforeAll.push(hook);
  4909. this.emit('beforeAll', hook);
  4910. return this;
  4911. };
  4912. /**
  4913. * Run `fn(test[, done])` after running tests.
  4914. *
  4915. * @api private
  4916. * @param {string} title
  4917. * @param {Function} fn
  4918. * @return {Suite} for chaining
  4919. */
  4920. Suite.prototype.afterAll = function (title, fn) {
  4921. if (this.isPending()) {
  4922. return this;
  4923. }
  4924. if (typeof title === 'function') {
  4925. fn = title;
  4926. title = fn.name;
  4927. }
  4928. title = '"after all" hook' + (title ? ': ' + title : '');
  4929. var hook = new Hook(title, fn);
  4930. hook.parent = this;
  4931. hook.timeout(this.timeout());
  4932. hook.retries(this.retries());
  4933. hook.enableTimeouts(this.enableTimeouts());
  4934. hook.slow(this.slow());
  4935. hook.ctx = this.ctx;
  4936. this._afterAll.push(hook);
  4937. this.emit('afterAll', hook);
  4938. return this;
  4939. };
  4940. /**
  4941. * Run `fn(test[, done])` before each test case.
  4942. *
  4943. * @api private
  4944. * @param {string} title
  4945. * @param {Function} fn
  4946. * @return {Suite} for chaining
  4947. */
  4948. Suite.prototype.beforeEach = function (title, fn) {
  4949. if (this.isPending()) {
  4950. return this;
  4951. }
  4952. if (typeof title === 'function') {
  4953. fn = title;
  4954. title = fn.name;
  4955. }
  4956. title = '"before each" hook' + (title ? ': ' + title : '');
  4957. var hook = new Hook(title, fn);
  4958. hook.parent = this;
  4959. hook.timeout(this.timeout());
  4960. hook.retries(this.retries());
  4961. hook.enableTimeouts(this.enableTimeouts());
  4962. hook.slow(this.slow());
  4963. hook.ctx = this.ctx;
  4964. this._beforeEach.push(hook);
  4965. this.emit('beforeEach', hook);
  4966. return this;
  4967. };
  4968. /**
  4969. * Run `fn(test[, done])` after each test case.
  4970. *
  4971. * @api private
  4972. * @param {string} title
  4973. * @param {Function} fn
  4974. * @return {Suite} for chaining
  4975. */
  4976. Suite.prototype.afterEach = function (title, fn) {
  4977. if (this.isPending()) {
  4978. return this;
  4979. }
  4980. if (typeof title === 'function') {
  4981. fn = title;
  4982. title = fn.name;
  4983. }
  4984. title = '"after each" hook' + (title ? ': ' + title : '');
  4985. var hook = new Hook(title, fn);
  4986. hook.parent = this;
  4987. hook.timeout(this.timeout());
  4988. hook.retries(this.retries());
  4989. hook.enableTimeouts(this.enableTimeouts());
  4990. hook.slow(this.slow());
  4991. hook.ctx = this.ctx;
  4992. this._afterEach.push(hook);
  4993. this.emit('afterEach', hook);
  4994. return this;
  4995. };
  4996. /**
  4997. * Add a test `suite`.
  4998. *
  4999. * @api private
  5000. * @param {Suite} suite
  5001. * @return {Suite} for chaining
  5002. */
  5003. Suite.prototype.addSuite = function (suite) {
  5004. suite.parent = this;
  5005. suite.timeout(this.timeout());
  5006. suite.retries(this.retries());
  5007. suite.enableTimeouts(this.enableTimeouts());
  5008. suite.slow(this.slow());
  5009. suite.bail(this.bail());
  5010. this.suites.push(suite);
  5011. this.emit('suite', suite);
  5012. return this;
  5013. };
  5014. /**
  5015. * Add a `test` to this suite.
  5016. *
  5017. * @api private
  5018. * @param {Test} test
  5019. * @return {Suite} for chaining
  5020. */
  5021. Suite.prototype.addTest = function (test) {
  5022. test.parent = this;
  5023. test.timeout(this.timeout());
  5024. test.retries(this.retries());
  5025. test.enableTimeouts(this.enableTimeouts());
  5026. test.slow(this.slow());
  5027. test.ctx = this.ctx;
  5028. this.tests.push(test);
  5029. this.emit('test', test);
  5030. return this;
  5031. };
  5032. /**
  5033. * Return the full title generated by recursively concatenating the parent's
  5034. * full title.
  5035. *
  5036. * @api public
  5037. * @return {string}
  5038. */
  5039. Suite.prototype.fullTitle = function () {
  5040. if (this.parent) {
  5041. var full = this.parent.fullTitle();
  5042. if (full) {
  5043. return full + ' ' + this.title;
  5044. }
  5045. }
  5046. return this.title;
  5047. };
  5048. /**
  5049. * Return the total number of tests.
  5050. *
  5051. * @api public
  5052. * @return {number}
  5053. */
  5054. Suite.prototype.total = function () {
  5055. return utils.reduce(this.suites, function (sum, suite) {
  5056. return sum + suite.total();
  5057. }, 0) + this.tests.length;
  5058. };
  5059. /**
  5060. * Iterates through each suite recursively to find all tests. Applies a
  5061. * function in the format `fn(test)`.
  5062. *
  5063. * @api private
  5064. * @param {Function} fn
  5065. * @return {Suite}
  5066. */
  5067. Suite.prototype.eachTest = function (fn) {
  5068. utils.forEach(this.tests, fn);
  5069. utils.forEach(this.suites, function (suite) {
  5070. suite.eachTest(fn);
  5071. });
  5072. return this;
  5073. };
  5074. /**
  5075. * This will run the root suite if we happen to be running in delayed mode.
  5076. */
  5077. Suite.prototype.run = function run () {
  5078. if (this.root) {
  5079. this.emit('run');
  5080. }
  5081. };
  5082. },{"./hook":7,"./ms":15,"./utils":38,"debug":2,"events":3}],36:[function(require,module,exports){
  5083. 'use strict';
  5084. /**
  5085. * Module dependencies.
  5086. */
  5087. var Runnable = require('./runnable');
  5088. var create = require('lodash.create');
  5089. var isString = require('./utils').isString;
  5090. /**
  5091. * Expose `Test`.
  5092. */
  5093. module.exports = Test;
  5094. /**
  5095. * Initialize a new `Test` with the given `title` and callback `fn`.
  5096. *
  5097. * @api private
  5098. * @param {String} title
  5099. * @param {Function} fn
  5100. */
  5101. function Test (title, fn) {
  5102. if (!isString(title)) {
  5103. throw new Error('Test `title` should be a "string" but "' + typeof title + '" was given instead.');
  5104. }
  5105. Runnable.call(this, title, fn);
  5106. this.pending = !fn;
  5107. this.type = 'test';
  5108. }
  5109. /**
  5110. * Inherit from `Runnable.prototype`.
  5111. */
  5112. Test.prototype = create(Runnable.prototype, {
  5113. constructor: Test
  5114. });
  5115. Test.prototype.clone = function () {
  5116. var test = new Test(this.title, this.fn);
  5117. test.timeout(this.timeout());
  5118. test.slow(this.slow());
  5119. test.enableTimeouts(this.enableTimeouts());
  5120. test.retries(this.retries());
  5121. test.currentRetry(this.currentRetry());
  5122. test.globals(this.globals());
  5123. test.parent = this.parent;
  5124. test.file = this.file;
  5125. test.ctx = this.ctx;
  5126. return test;
  5127. };
  5128. },{"./runnable":33,"./utils":38,"lodash.create":60}],37:[function(require,module,exports){
  5129. 'use strict';
  5130. /**
  5131. * Pad a `number` with a ten's place zero.
  5132. *
  5133. * @param {number} number
  5134. * @return {string}
  5135. */
  5136. function pad(number) {
  5137. var n = number.toString();
  5138. return n.length === 1 ? '0' + n : n;
  5139. }
  5140. /**
  5141. * Turn a `date` into an ISO string.
  5142. *
  5143. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
  5144. *
  5145. * @param {Date} date
  5146. * @return {string}
  5147. */
  5148. function toISOString(date) {
  5149. return date.getUTCFullYear()
  5150. + '-' + pad(date.getUTCMonth() + 1)
  5151. + '-' + pad(date.getUTCDate())
  5152. + 'T' + pad(date.getUTCHours())
  5153. + ':' + pad(date.getUTCMinutes())
  5154. + ':' + pad(date.getUTCSeconds())
  5155. + '.' + String((date.getUTCMilliseconds()/1000).toFixed(3)).slice(2, 5)
  5156. + 'Z';
  5157. }
  5158. /*
  5159. * Exports.
  5160. */
  5161. module.exports = toISOString;
  5162. },{}],38:[function(require,module,exports){
  5163. (function (process,Buffer){
  5164. 'use strict';
  5165. /* eslint-env browser */
  5166. /**
  5167. * Module dependencies.
  5168. */
  5169. var JSON = require('json3');
  5170. var basename = require('path').basename;
  5171. var debug = require('debug')('mocha:watch');
  5172. var exists = require('fs').existsSync || require('path').existsSync;
  5173. var glob = require('glob');
  5174. var path = require('path');
  5175. var join = path.join;
  5176. var readdirSync = require('fs').readdirSync;
  5177. var statSync = require('fs').statSync;
  5178. var watchFile = require('fs').watchFile;
  5179. var lstatSync = require('fs').lstatSync;
  5180. var toISOString = require('./to-iso-string');
  5181. /**
  5182. * Ignored directories.
  5183. */
  5184. var ignore = ['node_modules', '.git'];
  5185. exports.inherits = require('util').inherits;
  5186. /**
  5187. * Escape special characters in the given string of html.
  5188. *
  5189. * @api private
  5190. * @param {string} html
  5191. * @return {string}
  5192. */
  5193. exports.escape = function (html) {
  5194. return String(html)
  5195. .replace(/&/g, '&amp;')
  5196. .replace(/"/g, '&quot;')
  5197. .replace(/</g, '&lt;')
  5198. .replace(/>/g, '&gt;');
  5199. };
  5200. /**
  5201. * Array#forEach (<=IE8)
  5202. *
  5203. * @api private
  5204. * @param {Array} arr
  5205. * @param {Function} fn
  5206. * @param {Object} scope
  5207. */
  5208. exports.forEach = function (arr, fn, scope) {
  5209. for (var i = 0, l = arr.length; i < l; i++) {
  5210. fn.call(scope, arr[i], i);
  5211. }
  5212. };
  5213. /**
  5214. * Test if the given obj is type of string.
  5215. *
  5216. * @api private
  5217. * @param {Object} obj
  5218. * @return {boolean}
  5219. */
  5220. exports.isString = function (obj) {
  5221. return typeof obj === 'string';
  5222. };
  5223. /**
  5224. * Array#map (<=IE8)
  5225. *
  5226. * @api private
  5227. * @param {Array} arr
  5228. * @param {Function} fn
  5229. * @param {Object} scope
  5230. * @return {Array}
  5231. */
  5232. exports.map = function (arr, fn, scope) {
  5233. var result = [];
  5234. for (var i = 0, l = arr.length; i < l; i++) {
  5235. result.push(fn.call(scope, arr[i], i, arr));
  5236. }
  5237. return result;
  5238. };
  5239. /**
  5240. * Array#indexOf (<=IE8)
  5241. *
  5242. * @api private
  5243. * @param {Array} arr
  5244. * @param {Object} obj to find index of
  5245. * @param {number} start
  5246. * @return {number}
  5247. */
  5248. var indexOf = exports.indexOf = function (arr, obj, start) {
  5249. for (var i = start || 0, l = arr.length; i < l; i++) {
  5250. if (arr[i] === obj) {
  5251. return i;
  5252. }
  5253. }
  5254. return -1;
  5255. };
  5256. /**
  5257. * Array#reduce (<=IE8)
  5258. *
  5259. * @api private
  5260. * @param {Array} arr
  5261. * @param {Function} fn
  5262. * @param {Object} val Initial value.
  5263. * @return {*}
  5264. */
  5265. var reduce = exports.reduce = function (arr, fn, val) {
  5266. var rval = val;
  5267. for (var i = 0, l = arr.length; i < l; i++) {
  5268. rval = fn(rval, arr[i], i, arr);
  5269. }
  5270. return rval;
  5271. };
  5272. /**
  5273. * Array#filter (<=IE8)
  5274. *
  5275. * @api private
  5276. * @param {Array} arr
  5277. * @param {Function} fn
  5278. * @return {Array}
  5279. */
  5280. exports.filter = function (arr, fn) {
  5281. var ret = [];
  5282. for (var i = 0, l = arr.length; i < l; i++) {
  5283. var val = arr[i];
  5284. if (fn(val, i, arr)) {
  5285. ret.push(val);
  5286. }
  5287. }
  5288. return ret;
  5289. };
  5290. /**
  5291. * Array#some (<=IE8)
  5292. *
  5293. * @api private
  5294. * @param {Array} arr
  5295. * @param {Function} fn
  5296. * @return {Array}
  5297. */
  5298. exports.some = function (arr, fn) {
  5299. for (var i = 0, l = arr.length; i < l; i++) {
  5300. if (fn(arr[i])) {
  5301. return true;
  5302. }
  5303. }
  5304. return false;
  5305. };
  5306. /**
  5307. * Object.keys (<=IE8)
  5308. *
  5309. * @api private
  5310. * @param {Object} obj
  5311. * @return {Array} keys
  5312. */
  5313. exports.keys = typeof Object.keys === 'function' ? Object.keys : function (obj) {
  5314. var keys = [];
  5315. var has = Object.prototype.hasOwnProperty; // for `window` on <=IE8
  5316. for (var key in obj) {
  5317. if (has.call(obj, key)) {
  5318. keys.push(key);
  5319. }
  5320. }
  5321. return keys;
  5322. };
  5323. /**
  5324. * Watch the given `files` for changes
  5325. * and invoke `fn(file)` on modification.
  5326. *
  5327. * @api private
  5328. * @param {Array} files
  5329. * @param {Function} fn
  5330. */
  5331. exports.watch = function (files, fn) {
  5332. var options = { interval: 100 };
  5333. files.forEach(function (file) {
  5334. debug('file %s', file);
  5335. watchFile(file, options, function (curr, prev) {
  5336. if (prev.mtime < curr.mtime) {
  5337. fn(file);
  5338. }
  5339. });
  5340. });
  5341. };
  5342. /**
  5343. * Array.isArray (<=IE8)
  5344. *
  5345. * @api private
  5346. * @param {Object} obj
  5347. * @return {Boolean}
  5348. */
  5349. var isArray = typeof Array.isArray === 'function' ? Array.isArray : function (obj) {
  5350. return Object.prototype.toString.call(obj) === '[object Array]';
  5351. };
  5352. exports.isArray = isArray;
  5353. /**
  5354. * Buffer.prototype.toJSON polyfill.
  5355. *
  5356. * @type {Function}
  5357. */
  5358. if (typeof Buffer !== 'undefined' && Buffer.prototype) {
  5359. Buffer.prototype.toJSON = Buffer.prototype.toJSON || function () {
  5360. return Array.prototype.slice.call(this, 0);
  5361. };
  5362. }
  5363. /**
  5364. * Ignored files.
  5365. *
  5366. * @api private
  5367. * @param {string} path
  5368. * @return {boolean}
  5369. */
  5370. function ignored (path) {
  5371. return !~ignore.indexOf(path);
  5372. }
  5373. /**
  5374. * Lookup files in the given `dir`.
  5375. *
  5376. * @api private
  5377. * @param {string} dir
  5378. * @param {string[]} [ext=['.js']]
  5379. * @param {Array} [ret=[]]
  5380. * @return {Array}
  5381. */
  5382. exports.files = function (dir, ext, ret) {
  5383. ret = ret || [];
  5384. ext = ext || ['js'];
  5385. var re = new RegExp('\\.(' + ext.join('|') + ')$');
  5386. readdirSync(dir)
  5387. .filter(ignored)
  5388. .forEach(function (path) {
  5389. path = join(dir, path);
  5390. if (lstatSync(path).isDirectory()) {
  5391. exports.files(path, ext, ret);
  5392. } else if (path.match(re)) {
  5393. ret.push(path);
  5394. }
  5395. });
  5396. return ret;
  5397. };
  5398. /**
  5399. * Compute a slug from the given `str`.
  5400. *
  5401. * @api private
  5402. * @param {string} str
  5403. * @return {string}
  5404. */
  5405. exports.slug = function (str) {
  5406. return str
  5407. .toLowerCase()
  5408. .replace(/ +/g, '-')
  5409. .replace(/[^-\w]/g, '');
  5410. };
  5411. /**
  5412. * Strip the function definition from `str`, and re-indent for pre whitespace.
  5413. *
  5414. * @param {string} str
  5415. * @return {string}
  5416. */
  5417. exports.clean = function (str) {
  5418. str = str
  5419. .replace(/\r\n?|[\n\u2028\u2029]/g, '\n').replace(/^\uFEFF/, '')
  5420. // (traditional)-> space/name parameters body (lambda)-> parameters body multi-statement/single keep body content
  5421. .replace(/^function(?:\s*|\s+[^(]*)\([^)]*\)\s*\{((?:.|\n)*?)\s*\}$|^\([^)]*\)\s*=>\s*(?:\{((?:.|\n)*?)\s*\}|((?:.|\n)*))$/, '$1$2$3');
  5422. var spaces = str.match(/^\n?( *)/)[1].length;
  5423. var tabs = str.match(/^\n?(\t*)/)[1].length;
  5424. var re = new RegExp('^\n?' + (tabs ? '\t' : ' ') + '{' + (tabs || spaces) + '}', 'gm');
  5425. str = str.replace(re, '');
  5426. return exports.trim(str);
  5427. };
  5428. /**
  5429. * Trim the given `str`.
  5430. *
  5431. * @api private
  5432. * @param {string} str
  5433. * @return {string}
  5434. */
  5435. exports.trim = function (str) {
  5436. return str.replace(/^\s+|\s+$/g, '');
  5437. };
  5438. /**
  5439. * Parse the given `qs`.
  5440. *
  5441. * @api private
  5442. * @param {string} qs
  5443. * @return {Object}
  5444. */
  5445. exports.parseQuery = function (qs) {
  5446. return reduce(qs.replace('?', '').split('&'), function (obj, pair) {
  5447. var i = pair.indexOf('=');
  5448. var key = pair.slice(0, i);
  5449. var val = pair.slice(++i);
  5450. obj[key] = decodeURIComponent(val);
  5451. return obj;
  5452. }, {});
  5453. };
  5454. /**
  5455. * Highlight the given string of `js`.
  5456. *
  5457. * @api private
  5458. * @param {string} js
  5459. * @return {string}
  5460. */
  5461. function highlight (js) {
  5462. return js
  5463. .replace(/</g, '&lt;')
  5464. .replace(/>/g, '&gt;')
  5465. .replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
  5466. .replace(/('.*?')/gm, '<span class="string">$1</span>')
  5467. .replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
  5468. .replace(/(\d+)/gm, '<span class="number">$1</span>')
  5469. .replace(/\bnew[ \t]+(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>')
  5470. .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>');
  5471. }
  5472. /**
  5473. * Highlight the contents of tag `name`.
  5474. *
  5475. * @api private
  5476. * @param {string} name
  5477. */
  5478. exports.highlightTags = function (name) {
  5479. var code = document.getElementById('mocha').getElementsByTagName(name);
  5480. for (var i = 0, len = code.length; i < len; ++i) {
  5481. code[i].innerHTML = highlight(code[i].innerHTML);
  5482. }
  5483. };
  5484. /**
  5485. * If a value could have properties, and has none, this function is called,
  5486. * which returns a string representation of the empty value.
  5487. *
  5488. * Functions w/ no properties return `'[Function]'`
  5489. * Arrays w/ length === 0 return `'[]'`
  5490. * Objects w/ no properties return `'{}'`
  5491. * All else: return result of `value.toString()`
  5492. *
  5493. * @api private
  5494. * @param {*} value The value to inspect.
  5495. * @param {string} typeHint The type of the value
  5496. * @returns {string}
  5497. */
  5498. function emptyRepresentation (value, typeHint) {
  5499. switch (typeHint) {
  5500. case 'function':
  5501. return '[Function]';
  5502. case 'object':
  5503. return '{}';
  5504. case 'array':
  5505. return '[]';
  5506. default:
  5507. return value.toString();
  5508. }
  5509. }
  5510. /**
  5511. * Takes some variable and asks `Object.prototype.toString()` what it thinks it
  5512. * is.
  5513. *
  5514. * @api private
  5515. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
  5516. * @param {*} value The value to test.
  5517. * @returns {string} Computed type
  5518. * @example
  5519. * type({}) // 'object'
  5520. * type([]) // 'array'
  5521. * type(1) // 'number'
  5522. * type(false) // 'boolean'
  5523. * type(Infinity) // 'number'
  5524. * type(null) // 'null'
  5525. * type(new Date()) // 'date'
  5526. * type(/foo/) // 'regexp'
  5527. * type('type') // 'string'
  5528. * type(global) // 'global'
  5529. * type(new String('foo') // 'object'
  5530. */
  5531. var type = exports.type = function type (value) {
  5532. if (value === undefined) {
  5533. return 'undefined';
  5534. } else if (value === null) {
  5535. return 'null';
  5536. } else if (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) {
  5537. return 'buffer';
  5538. }
  5539. return Object.prototype.toString.call(value)
  5540. .replace(/^\[.+\s(.+?)\]$/, '$1')
  5541. .toLowerCase();
  5542. };
  5543. /**
  5544. * Stringify `value`. Different behavior depending on type of value:
  5545. *
  5546. * - If `value` is undefined or null, return `'[undefined]'` or `'[null]'`, respectively.
  5547. * - If `value` is not an object, function or array, return result of `value.toString()` wrapped in double-quotes.
  5548. * - If `value` is an *empty* object, function, or array, return result of function
  5549. * {@link emptyRepresentation}.
  5550. * - If `value` has properties, call {@link exports.canonicalize} on it, then return result of
  5551. * JSON.stringify().
  5552. *
  5553. * @api private
  5554. * @see exports.type
  5555. * @param {*} value
  5556. * @return {string}
  5557. */
  5558. exports.stringify = function (value) {
  5559. var typeHint = type(value);
  5560. if (!~indexOf(['object', 'array', 'function'], typeHint)) {
  5561. if (typeHint === 'buffer') {
  5562. var json = value.toJSON();
  5563. // Based on the toJSON result
  5564. return jsonStringify(json.data && json.type ? json.data : json, 2)
  5565. .replace(/,(\n|$)/g, '$1');
  5566. }
  5567. // IE7/IE8 has a bizarre String constructor; needs to be coerced
  5568. // into an array and back to obj.
  5569. if (typeHint === 'string' && typeof value === 'object') {
  5570. value = reduce(value.split(''), function (acc, char, idx) {
  5571. acc[idx] = char;
  5572. return acc;
  5573. }, {});
  5574. typeHint = 'object';
  5575. } else {
  5576. return jsonStringify(value);
  5577. }
  5578. }
  5579. for (var prop in value) {
  5580. if (Object.prototype.hasOwnProperty.call(value, prop)) {
  5581. return jsonStringify(exports.canonicalize(value, null, typeHint), 2).replace(/,(\n|$)/g, '$1');
  5582. }
  5583. }
  5584. return emptyRepresentation(value, typeHint);
  5585. };
  5586. /**
  5587. * like JSON.stringify but more sense.
  5588. *
  5589. * @api private
  5590. * @param {Object} object
  5591. * @param {number=} spaces
  5592. * @param {number=} depth
  5593. * @returns {*}
  5594. */
  5595. function jsonStringify (object, spaces, depth) {
  5596. if (typeof spaces === 'undefined') {
  5597. // primitive types
  5598. return _stringify(object);
  5599. }
  5600. depth = depth || 1;
  5601. var space = spaces * depth;
  5602. var str = isArray(object) ? '[' : '{';
  5603. var end = isArray(object) ? ']' : '}';
  5604. var length = typeof object.length === 'number' ? object.length : exports.keys(object).length;
  5605. // `.repeat()` polyfill
  5606. function repeat (s, n) {
  5607. return new Array(n).join(s);
  5608. }
  5609. function _stringify (val) {
  5610. switch (type(val)) {
  5611. case 'null':
  5612. case 'undefined':
  5613. val = '[' + val + ']';
  5614. break;
  5615. case 'array':
  5616. case 'object':
  5617. val = jsonStringify(val, spaces, depth + 1);
  5618. break;
  5619. case 'boolean':
  5620. case 'regexp':
  5621. case 'symbol':
  5622. case 'number':
  5623. val = val === 0 && (1 / val) === -Infinity // `-0`
  5624. ? '-0'
  5625. : val.toString();
  5626. break;
  5627. case 'date':
  5628. var sDate;
  5629. if (isNaN(val.getTime())) { // Invalid date
  5630. sDate = val.toString();
  5631. } else {
  5632. sDate = val.toISOString ? val.toISOString() : toISOString(val);
  5633. }
  5634. val = '[Date: ' + sDate + ']';
  5635. break;
  5636. case 'buffer':
  5637. var json = val.toJSON();
  5638. // Based on the toJSON result
  5639. json = json.data && json.type ? json.data : json;
  5640. val = '[Buffer: ' + jsonStringify(json, 2, depth + 1) + ']';
  5641. break;
  5642. default:
  5643. val = (val === '[Function]' || val === '[Circular]')
  5644. ? val
  5645. : JSON.stringify(val); // string
  5646. }
  5647. return val;
  5648. }
  5649. for (var i in object) {
  5650. if (!Object.prototype.hasOwnProperty.call(object, i)) {
  5651. continue; // not my business
  5652. }
  5653. --length;
  5654. str += '\n ' + repeat(' ', space) +
  5655. (isArray(object) ? '' : '"' + i + '": ') + // key
  5656. _stringify(object[i]) + // value
  5657. (length ? ',' : ''); // comma
  5658. }
  5659. return str +
  5660. // [], {}
  5661. (str.length !== 1 ? '\n' + repeat(' ', --space) + end : end);
  5662. }
  5663. /**
  5664. * Test if a value is a buffer.
  5665. *
  5666. * @api private
  5667. * @param {*} value The value to test.
  5668. * @return {boolean} True if `value` is a buffer, otherwise false
  5669. */
  5670. exports.isBuffer = function (value) {
  5671. return typeof Buffer !== 'undefined' && Buffer.isBuffer(value);
  5672. };
  5673. /**
  5674. * Return a new Thing that has the keys in sorted order. Recursive.
  5675. *
  5676. * If the Thing...
  5677. * - has already been seen, return string `'[Circular]'`
  5678. * - is `undefined`, return string `'[undefined]'`
  5679. * - is `null`, return value `null`
  5680. * - is some other primitive, return the value
  5681. * - is not a primitive or an `Array`, `Object`, or `Function`, return the value of the Thing's `toString()` method
  5682. * - is a non-empty `Array`, `Object`, or `Function`, return the result of calling this function again.
  5683. * - is an empty `Array`, `Object`, or `Function`, return the result of calling `emptyRepresentation()`
  5684. *
  5685. * @api private
  5686. * @see {@link exports.stringify}
  5687. * @param {*} value Thing to inspect. May or may not have properties.
  5688. * @param {Array} [stack=[]] Stack of seen values
  5689. * @param {string} [typeHint] Type hint
  5690. * @return {(Object|Array|Function|string|undefined)}
  5691. */
  5692. exports.canonicalize = function canonicalize (value, stack, typeHint) {
  5693. var canonicalizedObj;
  5694. /* eslint-disable no-unused-vars */
  5695. var prop;
  5696. /* eslint-enable no-unused-vars */
  5697. typeHint = typeHint || type(value);
  5698. function withStack (value, fn) {
  5699. stack.push(value);
  5700. fn();
  5701. stack.pop();
  5702. }
  5703. stack = stack || [];
  5704. if (indexOf(stack, value) !== -1) {
  5705. return '[Circular]';
  5706. }
  5707. switch (typeHint) {
  5708. case 'undefined':
  5709. case 'buffer':
  5710. case 'null':
  5711. canonicalizedObj = value;
  5712. break;
  5713. case 'array':
  5714. withStack(value, function () {
  5715. canonicalizedObj = exports.map(value, function (item) {
  5716. return exports.canonicalize(item, stack);
  5717. });
  5718. });
  5719. break;
  5720. case 'function':
  5721. /* eslint-disable guard-for-in */
  5722. for (prop in value) {
  5723. canonicalizedObj = {};
  5724. break;
  5725. }
  5726. /* eslint-enable guard-for-in */
  5727. if (!canonicalizedObj) {
  5728. canonicalizedObj = emptyRepresentation(value, typeHint);
  5729. break;
  5730. }
  5731. /* falls through */
  5732. case 'object':
  5733. canonicalizedObj = canonicalizedObj || {};
  5734. withStack(value, function () {
  5735. exports.forEach(exports.keys(value).sort(), function (key) {
  5736. canonicalizedObj[key] = exports.canonicalize(value[key], stack);
  5737. });
  5738. });
  5739. break;
  5740. case 'date':
  5741. case 'number':
  5742. case 'regexp':
  5743. case 'boolean':
  5744. case 'symbol':
  5745. canonicalizedObj = value;
  5746. break;
  5747. default:
  5748. canonicalizedObj = value + '';
  5749. }
  5750. return canonicalizedObj;
  5751. };
  5752. /**
  5753. * Lookup file names at the given `path`.
  5754. *
  5755. * @api public
  5756. * @param {string} path Base path to start searching from.
  5757. * @param {string[]} extensions File extensions to look for.
  5758. * @param {boolean} recursive Whether or not to recurse into subdirectories.
  5759. * @return {string[]} An array of paths.
  5760. */
  5761. exports.lookupFiles = function lookupFiles (path, extensions, recursive) {
  5762. var files = [];
  5763. var re = new RegExp('\\.(' + extensions.join('|') + ')$');
  5764. if (!exists(path)) {
  5765. if (exists(path + '.js')) {
  5766. path += '.js';
  5767. } else {
  5768. files = glob.sync(path);
  5769. if (!files.length) {
  5770. throw new Error("cannot resolve path (or pattern) '" + path + "'");
  5771. }
  5772. return files;
  5773. }
  5774. }
  5775. try {
  5776. var stat = statSync(path);
  5777. if (stat.isFile()) {
  5778. return path;
  5779. }
  5780. } catch (err) {
  5781. // ignore error
  5782. return;
  5783. }
  5784. readdirSync(path).forEach(function (file) {
  5785. file = join(path, file);
  5786. try {
  5787. var stat = statSync(file);
  5788. if (stat.isDirectory()) {
  5789. if (recursive) {
  5790. files = files.concat(lookupFiles(file, extensions, recursive));
  5791. }
  5792. return;
  5793. }
  5794. } catch (err) {
  5795. // ignore error
  5796. return;
  5797. }
  5798. if (!stat.isFile() || !re.test(file) || basename(file)[0] === '.') {
  5799. return;
  5800. }
  5801. files.push(file);
  5802. });
  5803. return files;
  5804. };
  5805. /**
  5806. * Generate an undefined error with a message warning the user.
  5807. *
  5808. * @return {Error}
  5809. */
  5810. exports.undefinedError = function () {
  5811. return new Error('Caught undefined error, did you throw without specifying what?');
  5812. };
  5813. /**
  5814. * Generate an undefined error if `err` is not defined.
  5815. *
  5816. * @param {Error} err
  5817. * @return {Error}
  5818. */
  5819. exports.getError = function (err) {
  5820. return err || exports.undefinedError();
  5821. };
  5822. /**
  5823. * @summary
  5824. * This Filter based on `mocha-clean` module.(see: `github.com/rstacruz/mocha-clean`)
  5825. * @description
  5826. * When invoking this function you get a filter function that get the Error.stack as an input,
  5827. * and return a prettify output.
  5828. * (i.e: strip Mocha and internal node functions from stack trace).
  5829. * @returns {Function}
  5830. */
  5831. exports.stackTraceFilter = function () {
  5832. // TODO: Replace with `process.browser`
  5833. var is = typeof document === 'undefined' ? { node: true } : { browser: true };
  5834. var slash = path.sep;
  5835. var cwd;
  5836. if (is.node) {
  5837. cwd = process.cwd() + slash;
  5838. } else {
  5839. cwd = (typeof location === 'undefined' ? window.location : location).href.replace(/\/[^\/]*$/, '/');
  5840. slash = '/';
  5841. }
  5842. function isMochaInternal (line) {
  5843. return (~line.indexOf('node_modules' + slash + 'mocha' + slash)) ||
  5844. (~line.indexOf('node_modules' + slash + 'mocha.js')) ||
  5845. (~line.indexOf('bower_components' + slash + 'mocha.js')) ||
  5846. (~line.indexOf(slash + 'mocha.js'));
  5847. }
  5848. function isNodeInternal (line) {
  5849. return (~line.indexOf('(timers.js:')) ||
  5850. (~line.indexOf('(events.js:')) ||
  5851. (~line.indexOf('(node.js:')) ||
  5852. (~line.indexOf('(module.js:')) ||
  5853. (~line.indexOf('GeneratorFunctionPrototype.next (native)')) ||
  5854. false;
  5855. }
  5856. return function (stack) {
  5857. stack = stack.split('\n');
  5858. stack = reduce(stack, function (list, line) {
  5859. if (isMochaInternal(line)) {
  5860. return list;
  5861. }
  5862. if (is.node && isNodeInternal(line)) {
  5863. return list;
  5864. }
  5865. // Clean up cwd(absolute)
  5866. if (/\(?.+:\d+:\d+\)?$/.test(line)) {
  5867. line = line.replace(cwd, '');
  5868. }
  5869. list.push(line);
  5870. return list;
  5871. }, []);
  5872. return stack.join('\n');
  5873. };
  5874. };
  5875. /**
  5876. * Crude, but effective.
  5877. * @api
  5878. * @param {*} value
  5879. * @returns {boolean} Whether or not `value` is a Promise
  5880. */
  5881. exports.isPromise = function isPromise (value) {
  5882. return typeof value === 'object' && typeof value.then === 'function';
  5883. };
  5884. /**
  5885. * It's a noop.
  5886. * @api
  5887. */
  5888. exports.noop = function () {};
  5889. }).call(this,require('_process'),require("buffer").Buffer)
  5890. },{"./to-iso-string":37,"_process":67,"buffer":44,"debug":2,"fs":42,"glob":42,"json3":54,"path":42,"util":84}],39:[function(require,module,exports){
  5891. 'use strict'
  5892. exports.byteLength = byteLength
  5893. exports.toByteArray = toByteArray
  5894. exports.fromByteArray = fromByteArray
  5895. var lookup = []
  5896. var revLookup = []
  5897. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  5898. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  5899. for (var i = 0, len = code.length; i < len; ++i) {
  5900. lookup[i] = code[i]
  5901. revLookup[code.charCodeAt(i)] = i
  5902. }
  5903. revLookup['-'.charCodeAt(0)] = 62
  5904. revLookup['_'.charCodeAt(0)] = 63
  5905. function placeHoldersCount (b64) {
  5906. var len = b64.length
  5907. if (len % 4 > 0) {
  5908. throw new Error('Invalid string. Length must be a multiple of 4')
  5909. }
  5910. // the number of equal signs (place holders)
  5911. // if there are two placeholders, than the two characters before it
  5912. // represent one byte
  5913. // if there is only one, then the three characters before it represent 2 bytes
  5914. // this is just a cheap hack to not do indexOf twice
  5915. return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
  5916. }
  5917. function byteLength (b64) {
  5918. // base64 is 4/3 + up to two characters of the original data
  5919. return b64.length * 3 / 4 - placeHoldersCount(b64)
  5920. }
  5921. function toByteArray (b64) {
  5922. var i, j, l, tmp, placeHolders, arr
  5923. var len = b64.length
  5924. placeHolders = placeHoldersCount(b64)
  5925. arr = new Arr(len * 3 / 4 - placeHolders)
  5926. // if there are placeholders, only get up to the last complete 4 chars
  5927. l = placeHolders > 0 ? len - 4 : len
  5928. var L = 0
  5929. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  5930. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
  5931. arr[L++] = (tmp >> 16) & 0xFF
  5932. arr[L++] = (tmp >> 8) & 0xFF
  5933. arr[L++] = tmp & 0xFF
  5934. }
  5935. if (placeHolders === 2) {
  5936. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
  5937. arr[L++] = tmp & 0xFF
  5938. } else if (placeHolders === 1) {
  5939. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
  5940. arr[L++] = (tmp >> 8) & 0xFF
  5941. arr[L++] = tmp & 0xFF
  5942. }
  5943. return arr
  5944. }
  5945. function tripletToBase64 (num) {
  5946. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  5947. }
  5948. function encodeChunk (uint8, start, end) {
  5949. var tmp
  5950. var output = []
  5951. for (var i = start; i < end; i += 3) {
  5952. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  5953. output.push(tripletToBase64(tmp))
  5954. }
  5955. return output.join('')
  5956. }
  5957. function fromByteArray (uint8) {
  5958. var tmp
  5959. var len = uint8.length
  5960. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  5961. var output = ''
  5962. var parts = []
  5963. var maxChunkLength = 16383 // must be multiple of 3
  5964. // go through the array every three bytes, we'll deal with trailing stuff later
  5965. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  5966. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  5967. }
  5968. // pad the end with zeros, but make sure to not forget the extra bytes
  5969. if (extraBytes === 1) {
  5970. tmp = uint8[len - 1]
  5971. output += lookup[tmp >> 2]
  5972. output += lookup[(tmp << 4) & 0x3F]
  5973. output += '=='
  5974. } else if (extraBytes === 2) {
  5975. tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
  5976. output += lookup[tmp >> 10]
  5977. output += lookup[(tmp >> 4) & 0x3F]
  5978. output += lookup[(tmp << 2) & 0x3F]
  5979. output += '='
  5980. }
  5981. parts.push(output)
  5982. return parts.join('')
  5983. }
  5984. },{}],40:[function(require,module,exports){
  5985. },{}],41:[function(require,module,exports){
  5986. (function (process){
  5987. var WritableStream = require('stream').Writable
  5988. var inherits = require('util').inherits
  5989. module.exports = BrowserStdout
  5990. inherits(BrowserStdout, WritableStream)
  5991. function BrowserStdout(opts) {
  5992. if (!(this instanceof BrowserStdout)) return new BrowserStdout(opts)
  5993. opts = opts || {}
  5994. WritableStream.call(this, opts)
  5995. this.label = (opts.label !== undefined) ? opts.label : 'stdout'
  5996. }
  5997. BrowserStdout.prototype._write = function(chunks, encoding, cb) {
  5998. var output = chunks.toString ? chunks.toString() : chunks
  5999. if (this.label === false) {
  6000. console.log(output)
  6001. } else {
  6002. console.log(this.label+':', output)
  6003. }
  6004. process.nextTick(cb)
  6005. }
  6006. }).call(this,require('_process'))
  6007. },{"_process":67,"stream":79,"util":84}],42:[function(require,module,exports){
  6008. arguments[4][40][0].apply(exports,arguments)
  6009. },{"dup":40}],43:[function(require,module,exports){
  6010. (function (global){
  6011. 'use strict';
  6012. var buffer = require('buffer');
  6013. var Buffer = buffer.Buffer;
  6014. var SlowBuffer = buffer.SlowBuffer;
  6015. var MAX_LEN = buffer.kMaxLength || 2147483647;
  6016. exports.alloc = function alloc(size, fill, encoding) {
  6017. if (typeof Buffer.alloc === 'function') {
  6018. return Buffer.alloc(size, fill, encoding);
  6019. }
  6020. if (typeof encoding === 'number') {
  6021. throw new TypeError('encoding must not be number');
  6022. }
  6023. if (typeof size !== 'number') {
  6024. throw new TypeError('size must be a number');
  6025. }
  6026. if (size > MAX_LEN) {
  6027. throw new RangeError('size is too large');
  6028. }
  6029. var enc = encoding;
  6030. var _fill = fill;
  6031. if (_fill === undefined) {
  6032. enc = undefined;
  6033. _fill = 0;
  6034. }
  6035. var buf = new Buffer(size);
  6036. if (typeof _fill === 'string') {
  6037. var fillBuf = new Buffer(_fill, enc);
  6038. var flen = fillBuf.length;
  6039. var i = -1;
  6040. while (++i < size) {
  6041. buf[i] = fillBuf[i % flen];
  6042. }
  6043. } else {
  6044. buf.fill(_fill);
  6045. }
  6046. return buf;
  6047. }
  6048. exports.allocUnsafe = function allocUnsafe(size) {
  6049. if (typeof Buffer.allocUnsafe === 'function') {
  6050. return Buffer.allocUnsafe(size);
  6051. }
  6052. if (typeof size !== 'number') {
  6053. throw new TypeError('size must be a number');
  6054. }
  6055. if (size > MAX_LEN) {
  6056. throw new RangeError('size is too large');
  6057. }
  6058. return new Buffer(size);
  6059. }
  6060. exports.from = function from(value, encodingOrOffset, length) {
  6061. if (typeof Buffer.from === 'function' && (!global.Uint8Array || Uint8Array.from !== Buffer.from)) {
  6062. return Buffer.from(value, encodingOrOffset, length);
  6063. }
  6064. if (typeof value === 'number') {
  6065. throw new TypeError('"value" argument must not be a number');
  6066. }
  6067. if (typeof value === 'string') {
  6068. return new Buffer(value, encodingOrOffset);
  6069. }
  6070. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  6071. var offset = encodingOrOffset;
  6072. if (arguments.length === 1) {
  6073. return new Buffer(value);
  6074. }
  6075. if (typeof offset === 'undefined') {
  6076. offset = 0;
  6077. }
  6078. var len = length;
  6079. if (typeof len === 'undefined') {
  6080. len = value.byteLength - offset;
  6081. }
  6082. if (offset >= value.byteLength) {
  6083. throw new RangeError('\'offset\' is out of bounds');
  6084. }
  6085. if (len > value.byteLength - offset) {
  6086. throw new RangeError('\'length\' is out of bounds');
  6087. }
  6088. return new Buffer(value.slice(offset, offset + len));
  6089. }
  6090. if (Buffer.isBuffer(value)) {
  6091. var out = new Buffer(value.length);
  6092. value.copy(out, 0, 0, value.length);
  6093. return out;
  6094. }
  6095. if (value) {
  6096. if (Array.isArray(value) || (typeof ArrayBuffer !== 'undefined' && value.buffer instanceof ArrayBuffer) || 'length' in value) {
  6097. return new Buffer(value);
  6098. }
  6099. if (value.type === 'Buffer' && Array.isArray(value.data)) {
  6100. return new Buffer(value.data);
  6101. }
  6102. }
  6103. throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.');
  6104. }
  6105. exports.allocUnsafeSlow = function allocUnsafeSlow(size) {
  6106. if (typeof Buffer.allocUnsafeSlow === 'function') {
  6107. return Buffer.allocUnsafeSlow(size);
  6108. }
  6109. if (typeof size !== 'number') {
  6110. throw new TypeError('size must be a number');
  6111. }
  6112. if (size >= MAX_LEN) {
  6113. throw new RangeError('size is too large');
  6114. }
  6115. return new SlowBuffer(size);
  6116. }
  6117. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  6118. },{"buffer":44}],44:[function(require,module,exports){
  6119. (function (global){
  6120. /*!
  6121. * The buffer module from node.js, for the browser.
  6122. *
  6123. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  6124. * @license MIT
  6125. */
  6126. /* eslint-disable no-proto */
  6127. 'use strict'
  6128. var base64 = require('base64-js')
  6129. var ieee754 = require('ieee754')
  6130. var isArray = require('isarray')
  6131. exports.Buffer = Buffer
  6132. exports.SlowBuffer = SlowBuffer
  6133. exports.INSPECT_MAX_BYTES = 50
  6134. /**
  6135. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  6136. * === true Use Uint8Array implementation (fastest)
  6137. * === false Use Object implementation (most compatible, even IE6)
  6138. *
  6139. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  6140. * Opera 11.6+, iOS 4.2+.
  6141. *
  6142. * Due to various browser bugs, sometimes the Object implementation will be used even
  6143. * when the browser supports typed arrays.
  6144. *
  6145. * Note:
  6146. *
  6147. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  6148. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  6149. *
  6150. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  6151. *
  6152. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  6153. * incorrect length in some situations.
  6154. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  6155. * get the Object implementation, which is slower but behaves correctly.
  6156. */
  6157. Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
  6158. ? global.TYPED_ARRAY_SUPPORT
  6159. : typedArraySupport()
  6160. /*
  6161. * Export kMaxLength after typed array support is determined.
  6162. */
  6163. exports.kMaxLength = kMaxLength()
  6164. function typedArraySupport () {
  6165. try {
  6166. var arr = new Uint8Array(1)
  6167. arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
  6168. return arr.foo() === 42 && // typed array instances can be augmented
  6169. typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
  6170. arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
  6171. } catch (e) {
  6172. return false
  6173. }
  6174. }
  6175. function kMaxLength () {
  6176. return Buffer.TYPED_ARRAY_SUPPORT
  6177. ? 0x7fffffff
  6178. : 0x3fffffff
  6179. }
  6180. function createBuffer (that, length) {
  6181. if (kMaxLength() < length) {
  6182. throw new RangeError('Invalid typed array length')
  6183. }
  6184. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6185. // Return an augmented `Uint8Array` instance, for best performance
  6186. that = new Uint8Array(length)
  6187. that.__proto__ = Buffer.prototype
  6188. } else {
  6189. // Fallback: Return an object instance of the Buffer class
  6190. if (that === null) {
  6191. that = new Buffer(length)
  6192. }
  6193. that.length = length
  6194. }
  6195. return that
  6196. }
  6197. /**
  6198. * The Buffer constructor returns instances of `Uint8Array` that have their
  6199. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  6200. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  6201. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  6202. * returns a single octet.
  6203. *
  6204. * The `Uint8Array` prototype remains unmodified.
  6205. */
  6206. function Buffer (arg, encodingOrOffset, length) {
  6207. if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
  6208. return new Buffer(arg, encodingOrOffset, length)
  6209. }
  6210. // Common case.
  6211. if (typeof arg === 'number') {
  6212. if (typeof encodingOrOffset === 'string') {
  6213. throw new Error(
  6214. 'If encoding is specified then the first argument must be a string'
  6215. )
  6216. }
  6217. return allocUnsafe(this, arg)
  6218. }
  6219. return from(this, arg, encodingOrOffset, length)
  6220. }
  6221. Buffer.poolSize = 8192 // not used by this implementation
  6222. // TODO: Legacy, not needed anymore. Remove in next major version.
  6223. Buffer._augment = function (arr) {
  6224. arr.__proto__ = Buffer.prototype
  6225. return arr
  6226. }
  6227. function from (that, value, encodingOrOffset, length) {
  6228. if (typeof value === 'number') {
  6229. throw new TypeError('"value" argument must not be a number')
  6230. }
  6231. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  6232. return fromArrayBuffer(that, value, encodingOrOffset, length)
  6233. }
  6234. if (typeof value === 'string') {
  6235. return fromString(that, value, encodingOrOffset)
  6236. }
  6237. return fromObject(that, value)
  6238. }
  6239. /**
  6240. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  6241. * if value is a number.
  6242. * Buffer.from(str[, encoding])
  6243. * Buffer.from(array)
  6244. * Buffer.from(buffer)
  6245. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  6246. **/
  6247. Buffer.from = function (value, encodingOrOffset, length) {
  6248. return from(null, value, encodingOrOffset, length)
  6249. }
  6250. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6251. Buffer.prototype.__proto__ = Uint8Array.prototype
  6252. Buffer.__proto__ = Uint8Array
  6253. if (typeof Symbol !== 'undefined' && Symbol.species &&
  6254. Buffer[Symbol.species] === Buffer) {
  6255. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  6256. Object.defineProperty(Buffer, Symbol.species, {
  6257. value: null,
  6258. configurable: true
  6259. })
  6260. }
  6261. }
  6262. function assertSize (size) {
  6263. if (typeof size !== 'number') {
  6264. throw new TypeError('"size" argument must be a number')
  6265. } else if (size < 0) {
  6266. throw new RangeError('"size" argument must not be negative')
  6267. }
  6268. }
  6269. function alloc (that, size, fill, encoding) {
  6270. assertSize(size)
  6271. if (size <= 0) {
  6272. return createBuffer(that, size)
  6273. }
  6274. if (fill !== undefined) {
  6275. // Only pay attention to encoding if it's a string. This
  6276. // prevents accidentally sending in a number that would
  6277. // be interpretted as a start offset.
  6278. return typeof encoding === 'string'
  6279. ? createBuffer(that, size).fill(fill, encoding)
  6280. : createBuffer(that, size).fill(fill)
  6281. }
  6282. return createBuffer(that, size)
  6283. }
  6284. /**
  6285. * Creates a new filled Buffer instance.
  6286. * alloc(size[, fill[, encoding]])
  6287. **/
  6288. Buffer.alloc = function (size, fill, encoding) {
  6289. return alloc(null, size, fill, encoding)
  6290. }
  6291. function allocUnsafe (that, size) {
  6292. assertSize(size)
  6293. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
  6294. if (!Buffer.TYPED_ARRAY_SUPPORT) {
  6295. for (var i = 0; i < size; ++i) {
  6296. that[i] = 0
  6297. }
  6298. }
  6299. return that
  6300. }
  6301. /**
  6302. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  6303. * */
  6304. Buffer.allocUnsafe = function (size) {
  6305. return allocUnsafe(null, size)
  6306. }
  6307. /**
  6308. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  6309. */
  6310. Buffer.allocUnsafeSlow = function (size) {
  6311. return allocUnsafe(null, size)
  6312. }
  6313. function fromString (that, string, encoding) {
  6314. if (typeof encoding !== 'string' || encoding === '') {
  6315. encoding = 'utf8'
  6316. }
  6317. if (!Buffer.isEncoding(encoding)) {
  6318. throw new TypeError('"encoding" must be a valid string encoding')
  6319. }
  6320. var length = byteLength(string, encoding) | 0
  6321. that = createBuffer(that, length)
  6322. var actual = that.write(string, encoding)
  6323. if (actual !== length) {
  6324. // Writing a hex string, for example, that contains invalid characters will
  6325. // cause everything after the first invalid character to be ignored. (e.g.
  6326. // 'abxxcd' will be treated as 'ab')
  6327. that = that.slice(0, actual)
  6328. }
  6329. return that
  6330. }
  6331. function fromArrayLike (that, array) {
  6332. var length = array.length < 0 ? 0 : checked(array.length) | 0
  6333. that = createBuffer(that, length)
  6334. for (var i = 0; i < length; i += 1) {
  6335. that[i] = array[i] & 255
  6336. }
  6337. return that
  6338. }
  6339. function fromArrayBuffer (that, array, byteOffset, length) {
  6340. array.byteLength // this throws if `array` is not a valid ArrayBuffer
  6341. if (byteOffset < 0 || array.byteLength < byteOffset) {
  6342. throw new RangeError('\'offset\' is out of bounds')
  6343. }
  6344. if (array.byteLength < byteOffset + (length || 0)) {
  6345. throw new RangeError('\'length\' is out of bounds')
  6346. }
  6347. if (byteOffset === undefined && length === undefined) {
  6348. array = new Uint8Array(array)
  6349. } else if (length === undefined) {
  6350. array = new Uint8Array(array, byteOffset)
  6351. } else {
  6352. array = new Uint8Array(array, byteOffset, length)
  6353. }
  6354. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6355. // Return an augmented `Uint8Array` instance, for best performance
  6356. that = array
  6357. that.__proto__ = Buffer.prototype
  6358. } else {
  6359. // Fallback: Return an object instance of the Buffer class
  6360. that = fromArrayLike(that, array)
  6361. }
  6362. return that
  6363. }
  6364. function fromObject (that, obj) {
  6365. if (Buffer.isBuffer(obj)) {
  6366. var len = checked(obj.length) | 0
  6367. that = createBuffer(that, len)
  6368. if (that.length === 0) {
  6369. return that
  6370. }
  6371. obj.copy(that, 0, 0, len)
  6372. return that
  6373. }
  6374. if (obj) {
  6375. if ((typeof ArrayBuffer !== 'undefined' &&
  6376. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  6377. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  6378. return createBuffer(that, 0)
  6379. }
  6380. return fromArrayLike(that, obj)
  6381. }
  6382. if (obj.type === 'Buffer' && isArray(obj.data)) {
  6383. return fromArrayLike(that, obj.data)
  6384. }
  6385. }
  6386. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  6387. }
  6388. function checked (length) {
  6389. // Note: cannot use `length < kMaxLength()` here because that fails when
  6390. // length is NaN (which is otherwise coerced to zero.)
  6391. if (length >= kMaxLength()) {
  6392. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  6393. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  6394. }
  6395. return length | 0
  6396. }
  6397. function SlowBuffer (length) {
  6398. if (+length != length) { // eslint-disable-line eqeqeq
  6399. length = 0
  6400. }
  6401. return Buffer.alloc(+length)
  6402. }
  6403. Buffer.isBuffer = function isBuffer (b) {
  6404. return !!(b != null && b._isBuffer)
  6405. }
  6406. Buffer.compare = function compare (a, b) {
  6407. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  6408. throw new TypeError('Arguments must be Buffers')
  6409. }
  6410. if (a === b) return 0
  6411. var x = a.length
  6412. var y = b.length
  6413. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  6414. if (a[i] !== b[i]) {
  6415. x = a[i]
  6416. y = b[i]
  6417. break
  6418. }
  6419. }
  6420. if (x < y) return -1
  6421. if (y < x) return 1
  6422. return 0
  6423. }
  6424. Buffer.isEncoding = function isEncoding (encoding) {
  6425. switch (String(encoding).toLowerCase()) {
  6426. case 'hex':
  6427. case 'utf8':
  6428. case 'utf-8':
  6429. case 'ascii':
  6430. case 'latin1':
  6431. case 'binary':
  6432. case 'base64':
  6433. case 'ucs2':
  6434. case 'ucs-2':
  6435. case 'utf16le':
  6436. case 'utf-16le':
  6437. return true
  6438. default:
  6439. return false
  6440. }
  6441. }
  6442. Buffer.concat = function concat (list, length) {
  6443. if (!isArray(list)) {
  6444. throw new TypeError('"list" argument must be an Array of Buffers')
  6445. }
  6446. if (list.length === 0) {
  6447. return Buffer.alloc(0)
  6448. }
  6449. var i
  6450. if (length === undefined) {
  6451. length = 0
  6452. for (i = 0; i < list.length; ++i) {
  6453. length += list[i].length
  6454. }
  6455. }
  6456. var buffer = Buffer.allocUnsafe(length)
  6457. var pos = 0
  6458. for (i = 0; i < list.length; ++i) {
  6459. var buf = list[i]
  6460. if (!Buffer.isBuffer(buf)) {
  6461. throw new TypeError('"list" argument must be an Array of Buffers')
  6462. }
  6463. buf.copy(buffer, pos)
  6464. pos += buf.length
  6465. }
  6466. return buffer
  6467. }
  6468. function byteLength (string, encoding) {
  6469. if (Buffer.isBuffer(string)) {
  6470. return string.length
  6471. }
  6472. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  6473. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  6474. return string.byteLength
  6475. }
  6476. if (typeof string !== 'string') {
  6477. string = '' + string
  6478. }
  6479. var len = string.length
  6480. if (len === 0) return 0
  6481. // Use a for loop to avoid recursion
  6482. var loweredCase = false
  6483. for (;;) {
  6484. switch (encoding) {
  6485. case 'ascii':
  6486. case 'latin1':
  6487. case 'binary':
  6488. return len
  6489. case 'utf8':
  6490. case 'utf-8':
  6491. case undefined:
  6492. return utf8ToBytes(string).length
  6493. case 'ucs2':
  6494. case 'ucs-2':
  6495. case 'utf16le':
  6496. case 'utf-16le':
  6497. return len * 2
  6498. case 'hex':
  6499. return len >>> 1
  6500. case 'base64':
  6501. return base64ToBytes(string).length
  6502. default:
  6503. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  6504. encoding = ('' + encoding).toLowerCase()
  6505. loweredCase = true
  6506. }
  6507. }
  6508. }
  6509. Buffer.byteLength = byteLength
  6510. function slowToString (encoding, start, end) {
  6511. var loweredCase = false
  6512. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  6513. // property of a typed array.
  6514. // This behaves neither like String nor Uint8Array in that we set start/end
  6515. // to their upper/lower bounds if the value passed is out of range.
  6516. // undefined is handled specially as per ECMA-262 6th Edition,
  6517. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  6518. if (start === undefined || start < 0) {
  6519. start = 0
  6520. }
  6521. // Return early if start > this.length. Done here to prevent potential uint32
  6522. // coercion fail below.
  6523. if (start > this.length) {
  6524. return ''
  6525. }
  6526. if (end === undefined || end > this.length) {
  6527. end = this.length
  6528. }
  6529. if (end <= 0) {
  6530. return ''
  6531. }
  6532. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  6533. end >>>= 0
  6534. start >>>= 0
  6535. if (end <= start) {
  6536. return ''
  6537. }
  6538. if (!encoding) encoding = 'utf8'
  6539. while (true) {
  6540. switch (encoding) {
  6541. case 'hex':
  6542. return hexSlice(this, start, end)
  6543. case 'utf8':
  6544. case 'utf-8':
  6545. return utf8Slice(this, start, end)
  6546. case 'ascii':
  6547. return asciiSlice(this, start, end)
  6548. case 'latin1':
  6549. case 'binary':
  6550. return latin1Slice(this, start, end)
  6551. case 'base64':
  6552. return base64Slice(this, start, end)
  6553. case 'ucs2':
  6554. case 'ucs-2':
  6555. case 'utf16le':
  6556. case 'utf-16le':
  6557. return utf16leSlice(this, start, end)
  6558. default:
  6559. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  6560. encoding = (encoding + '').toLowerCase()
  6561. loweredCase = true
  6562. }
  6563. }
  6564. }
  6565. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  6566. // Buffer instances.
  6567. Buffer.prototype._isBuffer = true
  6568. function swap (b, n, m) {
  6569. var i = b[n]
  6570. b[n] = b[m]
  6571. b[m] = i
  6572. }
  6573. Buffer.prototype.swap16 = function swap16 () {
  6574. var len = this.length
  6575. if (len % 2 !== 0) {
  6576. throw new RangeError('Buffer size must be a multiple of 16-bits')
  6577. }
  6578. for (var i = 0; i < len; i += 2) {
  6579. swap(this, i, i + 1)
  6580. }
  6581. return this
  6582. }
  6583. Buffer.prototype.swap32 = function swap32 () {
  6584. var len = this.length
  6585. if (len % 4 !== 0) {
  6586. throw new RangeError('Buffer size must be a multiple of 32-bits')
  6587. }
  6588. for (var i = 0; i < len; i += 4) {
  6589. swap(this, i, i + 3)
  6590. swap(this, i + 1, i + 2)
  6591. }
  6592. return this
  6593. }
  6594. Buffer.prototype.swap64 = function swap64 () {
  6595. var len = this.length
  6596. if (len % 8 !== 0) {
  6597. throw new RangeError('Buffer size must be a multiple of 64-bits')
  6598. }
  6599. for (var i = 0; i < len; i += 8) {
  6600. swap(this, i, i + 7)
  6601. swap(this, i + 1, i + 6)
  6602. swap(this, i + 2, i + 5)
  6603. swap(this, i + 3, i + 4)
  6604. }
  6605. return this
  6606. }
  6607. Buffer.prototype.toString = function toString () {
  6608. var length = this.length | 0
  6609. if (length === 0) return ''
  6610. if (arguments.length === 0) return utf8Slice(this, 0, length)
  6611. return slowToString.apply(this, arguments)
  6612. }
  6613. Buffer.prototype.equals = function equals (b) {
  6614. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  6615. if (this === b) return true
  6616. return Buffer.compare(this, b) === 0
  6617. }
  6618. Buffer.prototype.inspect = function inspect () {
  6619. var str = ''
  6620. var max = exports.INSPECT_MAX_BYTES
  6621. if (this.length > 0) {
  6622. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  6623. if (this.length > max) str += ' ... '
  6624. }
  6625. return '<Buffer ' + str + '>'
  6626. }
  6627. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  6628. if (!Buffer.isBuffer(target)) {
  6629. throw new TypeError('Argument must be a Buffer')
  6630. }
  6631. if (start === undefined) {
  6632. start = 0
  6633. }
  6634. if (end === undefined) {
  6635. end = target ? target.length : 0
  6636. }
  6637. if (thisStart === undefined) {
  6638. thisStart = 0
  6639. }
  6640. if (thisEnd === undefined) {
  6641. thisEnd = this.length
  6642. }
  6643. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  6644. throw new RangeError('out of range index')
  6645. }
  6646. if (thisStart >= thisEnd && start >= end) {
  6647. return 0
  6648. }
  6649. if (thisStart >= thisEnd) {
  6650. return -1
  6651. }
  6652. if (start >= end) {
  6653. return 1
  6654. }
  6655. start >>>= 0
  6656. end >>>= 0
  6657. thisStart >>>= 0
  6658. thisEnd >>>= 0
  6659. if (this === target) return 0
  6660. var x = thisEnd - thisStart
  6661. var y = end - start
  6662. var len = Math.min(x, y)
  6663. var thisCopy = this.slice(thisStart, thisEnd)
  6664. var targetCopy = target.slice(start, end)
  6665. for (var i = 0; i < len; ++i) {
  6666. if (thisCopy[i] !== targetCopy[i]) {
  6667. x = thisCopy[i]
  6668. y = targetCopy[i]
  6669. break
  6670. }
  6671. }
  6672. if (x < y) return -1
  6673. if (y < x) return 1
  6674. return 0
  6675. }
  6676. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  6677. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  6678. //
  6679. // Arguments:
  6680. // - buffer - a Buffer to search
  6681. // - val - a string, Buffer, or number
  6682. // - byteOffset - an index into `buffer`; will be clamped to an int32
  6683. // - encoding - an optional encoding, relevant is val is a string
  6684. // - dir - true for indexOf, false for lastIndexOf
  6685. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  6686. // Empty buffer means no match
  6687. if (buffer.length === 0) return -1
  6688. // Normalize byteOffset
  6689. if (typeof byteOffset === 'string') {
  6690. encoding = byteOffset
  6691. byteOffset = 0
  6692. } else if (byteOffset > 0x7fffffff) {
  6693. byteOffset = 0x7fffffff
  6694. } else if (byteOffset < -0x80000000) {
  6695. byteOffset = -0x80000000
  6696. }
  6697. byteOffset = +byteOffset // Coerce to Number.
  6698. if (isNaN(byteOffset)) {
  6699. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  6700. byteOffset = dir ? 0 : (buffer.length - 1)
  6701. }
  6702. // Normalize byteOffset: negative offsets start from the end of the buffer
  6703. if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  6704. if (byteOffset >= buffer.length) {
  6705. if (dir) return -1
  6706. else byteOffset = buffer.length - 1
  6707. } else if (byteOffset < 0) {
  6708. if (dir) byteOffset = 0
  6709. else return -1
  6710. }
  6711. // Normalize val
  6712. if (typeof val === 'string') {
  6713. val = Buffer.from(val, encoding)
  6714. }
  6715. // Finally, search either indexOf (if dir is true) or lastIndexOf
  6716. if (Buffer.isBuffer(val)) {
  6717. // Special case: looking for empty string/buffer always fails
  6718. if (val.length === 0) {
  6719. return -1
  6720. }
  6721. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  6722. } else if (typeof val === 'number') {
  6723. val = val & 0xFF // Search for a byte value [0-255]
  6724. if (Buffer.TYPED_ARRAY_SUPPORT &&
  6725. typeof Uint8Array.prototype.indexOf === 'function') {
  6726. if (dir) {
  6727. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  6728. } else {
  6729. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  6730. }
  6731. }
  6732. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  6733. }
  6734. throw new TypeError('val must be string, number or Buffer')
  6735. }
  6736. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  6737. var indexSize = 1
  6738. var arrLength = arr.length
  6739. var valLength = val.length
  6740. if (encoding !== undefined) {
  6741. encoding = String(encoding).toLowerCase()
  6742. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  6743. encoding === 'utf16le' || encoding === 'utf-16le') {
  6744. if (arr.length < 2 || val.length < 2) {
  6745. return -1
  6746. }
  6747. indexSize = 2
  6748. arrLength /= 2
  6749. valLength /= 2
  6750. byteOffset /= 2
  6751. }
  6752. }
  6753. function read (buf, i) {
  6754. if (indexSize === 1) {
  6755. return buf[i]
  6756. } else {
  6757. return buf.readUInt16BE(i * indexSize)
  6758. }
  6759. }
  6760. var i
  6761. if (dir) {
  6762. var foundIndex = -1
  6763. for (i = byteOffset; i < arrLength; i++) {
  6764. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  6765. if (foundIndex === -1) foundIndex = i
  6766. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  6767. } else {
  6768. if (foundIndex !== -1) i -= i - foundIndex
  6769. foundIndex = -1
  6770. }
  6771. }
  6772. } else {
  6773. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  6774. for (i = byteOffset; i >= 0; i--) {
  6775. var found = true
  6776. for (var j = 0; j < valLength; j++) {
  6777. if (read(arr, i + j) !== read(val, j)) {
  6778. found = false
  6779. break
  6780. }
  6781. }
  6782. if (found) return i
  6783. }
  6784. }
  6785. return -1
  6786. }
  6787. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  6788. return this.indexOf(val, byteOffset, encoding) !== -1
  6789. }
  6790. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  6791. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  6792. }
  6793. Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  6794. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  6795. }
  6796. function hexWrite (buf, string, offset, length) {
  6797. offset = Number(offset) || 0
  6798. var remaining = buf.length - offset
  6799. if (!length) {
  6800. length = remaining
  6801. } else {
  6802. length = Number(length)
  6803. if (length > remaining) {
  6804. length = remaining
  6805. }
  6806. }
  6807. // must be an even number of digits
  6808. var strLen = string.length
  6809. if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
  6810. if (length > strLen / 2) {
  6811. length = strLen / 2
  6812. }
  6813. for (var i = 0; i < length; ++i) {
  6814. var parsed = parseInt(string.substr(i * 2, 2), 16)
  6815. if (isNaN(parsed)) return i
  6816. buf[offset + i] = parsed
  6817. }
  6818. return i
  6819. }
  6820. function utf8Write (buf, string, offset, length) {
  6821. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  6822. }
  6823. function asciiWrite (buf, string, offset, length) {
  6824. return blitBuffer(asciiToBytes(string), buf, offset, length)
  6825. }
  6826. function latin1Write (buf, string, offset, length) {
  6827. return asciiWrite(buf, string, offset, length)
  6828. }
  6829. function base64Write (buf, string, offset, length) {
  6830. return blitBuffer(base64ToBytes(string), buf, offset, length)
  6831. }
  6832. function ucs2Write (buf, string, offset, length) {
  6833. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  6834. }
  6835. Buffer.prototype.write = function write (string, offset, length, encoding) {
  6836. // Buffer#write(string)
  6837. if (offset === undefined) {
  6838. encoding = 'utf8'
  6839. length = this.length
  6840. offset = 0
  6841. // Buffer#write(string, encoding)
  6842. } else if (length === undefined && typeof offset === 'string') {
  6843. encoding = offset
  6844. length = this.length
  6845. offset = 0
  6846. // Buffer#write(string, offset[, length][, encoding])
  6847. } else if (isFinite(offset)) {
  6848. offset = offset | 0
  6849. if (isFinite(length)) {
  6850. length = length | 0
  6851. if (encoding === undefined) encoding = 'utf8'
  6852. } else {
  6853. encoding = length
  6854. length = undefined
  6855. }
  6856. // legacy write(string, encoding, offset, length) - remove in v0.13
  6857. } else {
  6858. throw new Error(
  6859. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  6860. )
  6861. }
  6862. var remaining = this.length - offset
  6863. if (length === undefined || length > remaining) length = remaining
  6864. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  6865. throw new RangeError('Attempt to write outside buffer bounds')
  6866. }
  6867. if (!encoding) encoding = 'utf8'
  6868. var loweredCase = false
  6869. for (;;) {
  6870. switch (encoding) {
  6871. case 'hex':
  6872. return hexWrite(this, string, offset, length)
  6873. case 'utf8':
  6874. case 'utf-8':
  6875. return utf8Write(this, string, offset, length)
  6876. case 'ascii':
  6877. return asciiWrite(this, string, offset, length)
  6878. case 'latin1':
  6879. case 'binary':
  6880. return latin1Write(this, string, offset, length)
  6881. case 'base64':
  6882. // Warning: maxLength not taken into account in base64Write
  6883. return base64Write(this, string, offset, length)
  6884. case 'ucs2':
  6885. case 'ucs-2':
  6886. case 'utf16le':
  6887. case 'utf-16le':
  6888. return ucs2Write(this, string, offset, length)
  6889. default:
  6890. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  6891. encoding = ('' + encoding).toLowerCase()
  6892. loweredCase = true
  6893. }
  6894. }
  6895. }
  6896. Buffer.prototype.toJSON = function toJSON () {
  6897. return {
  6898. type: 'Buffer',
  6899. data: Array.prototype.slice.call(this._arr || this, 0)
  6900. }
  6901. }
  6902. function base64Slice (buf, start, end) {
  6903. if (start === 0 && end === buf.length) {
  6904. return base64.fromByteArray(buf)
  6905. } else {
  6906. return base64.fromByteArray(buf.slice(start, end))
  6907. }
  6908. }
  6909. function utf8Slice (buf, start, end) {
  6910. end = Math.min(buf.length, end)
  6911. var res = []
  6912. var i = start
  6913. while (i < end) {
  6914. var firstByte = buf[i]
  6915. var codePoint = null
  6916. var bytesPerSequence = (firstByte > 0xEF) ? 4
  6917. : (firstByte > 0xDF) ? 3
  6918. : (firstByte > 0xBF) ? 2
  6919. : 1
  6920. if (i + bytesPerSequence <= end) {
  6921. var secondByte, thirdByte, fourthByte, tempCodePoint
  6922. switch (bytesPerSequence) {
  6923. case 1:
  6924. if (firstByte < 0x80) {
  6925. codePoint = firstByte
  6926. }
  6927. break
  6928. case 2:
  6929. secondByte = buf[i + 1]
  6930. if ((secondByte & 0xC0) === 0x80) {
  6931. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  6932. if (tempCodePoint > 0x7F) {
  6933. codePoint = tempCodePoint
  6934. }
  6935. }
  6936. break
  6937. case 3:
  6938. secondByte = buf[i + 1]
  6939. thirdByte = buf[i + 2]
  6940. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  6941. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  6942. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  6943. codePoint = tempCodePoint
  6944. }
  6945. }
  6946. break
  6947. case 4:
  6948. secondByte = buf[i + 1]
  6949. thirdByte = buf[i + 2]
  6950. fourthByte = buf[i + 3]
  6951. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  6952. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  6953. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  6954. codePoint = tempCodePoint
  6955. }
  6956. }
  6957. }
  6958. }
  6959. if (codePoint === null) {
  6960. // we did not generate a valid codePoint so insert a
  6961. // replacement char (U+FFFD) and advance only 1 byte
  6962. codePoint = 0xFFFD
  6963. bytesPerSequence = 1
  6964. } else if (codePoint > 0xFFFF) {
  6965. // encode to utf16 (surrogate pair dance)
  6966. codePoint -= 0x10000
  6967. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  6968. codePoint = 0xDC00 | codePoint & 0x3FF
  6969. }
  6970. res.push(codePoint)
  6971. i += bytesPerSequence
  6972. }
  6973. return decodeCodePointsArray(res)
  6974. }
  6975. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  6976. // the lowest limit is Chrome, with 0x10000 args.
  6977. // We go 1 magnitude less, for safety
  6978. var MAX_ARGUMENTS_LENGTH = 0x1000
  6979. function decodeCodePointsArray (codePoints) {
  6980. var len = codePoints.length
  6981. if (len <= MAX_ARGUMENTS_LENGTH) {
  6982. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  6983. }
  6984. // Decode in chunks to avoid "call stack size exceeded".
  6985. var res = ''
  6986. var i = 0
  6987. while (i < len) {
  6988. res += String.fromCharCode.apply(
  6989. String,
  6990. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  6991. )
  6992. }
  6993. return res
  6994. }
  6995. function asciiSlice (buf, start, end) {
  6996. var ret = ''
  6997. end = Math.min(buf.length, end)
  6998. for (var i = start; i < end; ++i) {
  6999. ret += String.fromCharCode(buf[i] & 0x7F)
  7000. }
  7001. return ret
  7002. }
  7003. function latin1Slice (buf, start, end) {
  7004. var ret = ''
  7005. end = Math.min(buf.length, end)
  7006. for (var i = start; i < end; ++i) {
  7007. ret += String.fromCharCode(buf[i])
  7008. }
  7009. return ret
  7010. }
  7011. function hexSlice (buf, start, end) {
  7012. var len = buf.length
  7013. if (!start || start < 0) start = 0
  7014. if (!end || end < 0 || end > len) end = len
  7015. var out = ''
  7016. for (var i = start; i < end; ++i) {
  7017. out += toHex(buf[i])
  7018. }
  7019. return out
  7020. }
  7021. function utf16leSlice (buf, start, end) {
  7022. var bytes = buf.slice(start, end)
  7023. var res = ''
  7024. for (var i = 0; i < bytes.length; i += 2) {
  7025. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
  7026. }
  7027. return res
  7028. }
  7029. Buffer.prototype.slice = function slice (start, end) {
  7030. var len = this.length
  7031. start = ~~start
  7032. end = end === undefined ? len : ~~end
  7033. if (start < 0) {
  7034. start += len
  7035. if (start < 0) start = 0
  7036. } else if (start > len) {
  7037. start = len
  7038. }
  7039. if (end < 0) {
  7040. end += len
  7041. if (end < 0) end = 0
  7042. } else if (end > len) {
  7043. end = len
  7044. }
  7045. if (end < start) end = start
  7046. var newBuf
  7047. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7048. newBuf = this.subarray(start, end)
  7049. newBuf.__proto__ = Buffer.prototype
  7050. } else {
  7051. var sliceLen = end - start
  7052. newBuf = new Buffer(sliceLen, undefined)
  7053. for (var i = 0; i < sliceLen; ++i) {
  7054. newBuf[i] = this[i + start]
  7055. }
  7056. }
  7057. return newBuf
  7058. }
  7059. /*
  7060. * Need to make sure that buffer isn't trying to write out of bounds.
  7061. */
  7062. function checkOffset (offset, ext, length) {
  7063. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  7064. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  7065. }
  7066. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  7067. offset = offset | 0
  7068. byteLength = byteLength | 0
  7069. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7070. var val = this[offset]
  7071. var mul = 1
  7072. var i = 0
  7073. while (++i < byteLength && (mul *= 0x100)) {
  7074. val += this[offset + i] * mul
  7075. }
  7076. return val
  7077. }
  7078. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  7079. offset = offset | 0
  7080. byteLength = byteLength | 0
  7081. if (!noAssert) {
  7082. checkOffset(offset, byteLength, this.length)
  7083. }
  7084. var val = this[offset + --byteLength]
  7085. var mul = 1
  7086. while (byteLength > 0 && (mul *= 0x100)) {
  7087. val += this[offset + --byteLength] * mul
  7088. }
  7089. return val
  7090. }
  7091. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  7092. if (!noAssert) checkOffset(offset, 1, this.length)
  7093. return this[offset]
  7094. }
  7095. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  7096. if (!noAssert) checkOffset(offset, 2, this.length)
  7097. return this[offset] | (this[offset + 1] << 8)
  7098. }
  7099. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  7100. if (!noAssert) checkOffset(offset, 2, this.length)
  7101. return (this[offset] << 8) | this[offset + 1]
  7102. }
  7103. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  7104. if (!noAssert) checkOffset(offset, 4, this.length)
  7105. return ((this[offset]) |
  7106. (this[offset + 1] << 8) |
  7107. (this[offset + 2] << 16)) +
  7108. (this[offset + 3] * 0x1000000)
  7109. }
  7110. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  7111. if (!noAssert) checkOffset(offset, 4, this.length)
  7112. return (this[offset] * 0x1000000) +
  7113. ((this[offset + 1] << 16) |
  7114. (this[offset + 2] << 8) |
  7115. this[offset + 3])
  7116. }
  7117. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  7118. offset = offset | 0
  7119. byteLength = byteLength | 0
  7120. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7121. var val = this[offset]
  7122. var mul = 1
  7123. var i = 0
  7124. while (++i < byteLength && (mul *= 0x100)) {
  7125. val += this[offset + i] * mul
  7126. }
  7127. mul *= 0x80
  7128. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  7129. return val
  7130. }
  7131. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  7132. offset = offset | 0
  7133. byteLength = byteLength | 0
  7134. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7135. var i = byteLength
  7136. var mul = 1
  7137. var val = this[offset + --i]
  7138. while (i > 0 && (mul *= 0x100)) {
  7139. val += this[offset + --i] * mul
  7140. }
  7141. mul *= 0x80
  7142. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  7143. return val
  7144. }
  7145. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  7146. if (!noAssert) checkOffset(offset, 1, this.length)
  7147. if (!(this[offset] & 0x80)) return (this[offset])
  7148. return ((0xff - this[offset] + 1) * -1)
  7149. }
  7150. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  7151. if (!noAssert) checkOffset(offset, 2, this.length)
  7152. var val = this[offset] | (this[offset + 1] << 8)
  7153. return (val & 0x8000) ? val | 0xFFFF0000 : val
  7154. }
  7155. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  7156. if (!noAssert) checkOffset(offset, 2, this.length)
  7157. var val = this[offset + 1] | (this[offset] << 8)
  7158. return (val & 0x8000) ? val | 0xFFFF0000 : val
  7159. }
  7160. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  7161. if (!noAssert) checkOffset(offset, 4, this.length)
  7162. return (this[offset]) |
  7163. (this[offset + 1] << 8) |
  7164. (this[offset + 2] << 16) |
  7165. (this[offset + 3] << 24)
  7166. }
  7167. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  7168. if (!noAssert) checkOffset(offset, 4, this.length)
  7169. return (this[offset] << 24) |
  7170. (this[offset + 1] << 16) |
  7171. (this[offset + 2] << 8) |
  7172. (this[offset + 3])
  7173. }
  7174. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  7175. if (!noAssert) checkOffset(offset, 4, this.length)
  7176. return ieee754.read(this, offset, true, 23, 4)
  7177. }
  7178. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  7179. if (!noAssert) checkOffset(offset, 4, this.length)
  7180. return ieee754.read(this, offset, false, 23, 4)
  7181. }
  7182. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  7183. if (!noAssert) checkOffset(offset, 8, this.length)
  7184. return ieee754.read(this, offset, true, 52, 8)
  7185. }
  7186. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  7187. if (!noAssert) checkOffset(offset, 8, this.length)
  7188. return ieee754.read(this, offset, false, 52, 8)
  7189. }
  7190. function checkInt (buf, value, offset, ext, max, min) {
  7191. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  7192. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  7193. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  7194. }
  7195. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  7196. value = +value
  7197. offset = offset | 0
  7198. byteLength = byteLength | 0
  7199. if (!noAssert) {
  7200. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  7201. checkInt(this, value, offset, byteLength, maxBytes, 0)
  7202. }
  7203. var mul = 1
  7204. var i = 0
  7205. this[offset] = value & 0xFF
  7206. while (++i < byteLength && (mul *= 0x100)) {
  7207. this[offset + i] = (value / mul) & 0xFF
  7208. }
  7209. return offset + byteLength
  7210. }
  7211. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  7212. value = +value
  7213. offset = offset | 0
  7214. byteLength = byteLength | 0
  7215. if (!noAssert) {
  7216. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  7217. checkInt(this, value, offset, byteLength, maxBytes, 0)
  7218. }
  7219. var i = byteLength - 1
  7220. var mul = 1
  7221. this[offset + i] = value & 0xFF
  7222. while (--i >= 0 && (mul *= 0x100)) {
  7223. this[offset + i] = (value / mul) & 0xFF
  7224. }
  7225. return offset + byteLength
  7226. }
  7227. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  7228. value = +value
  7229. offset = offset | 0
  7230. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  7231. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  7232. this[offset] = (value & 0xff)
  7233. return offset + 1
  7234. }
  7235. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  7236. if (value < 0) value = 0xffff + value + 1
  7237. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  7238. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  7239. (littleEndian ? i : 1 - i) * 8
  7240. }
  7241. }
  7242. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  7243. value = +value
  7244. offset = offset | 0
  7245. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  7246. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7247. this[offset] = (value & 0xff)
  7248. this[offset + 1] = (value >>> 8)
  7249. } else {
  7250. objectWriteUInt16(this, value, offset, true)
  7251. }
  7252. return offset + 2
  7253. }
  7254. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  7255. value = +value
  7256. offset = offset | 0
  7257. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  7258. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7259. this[offset] = (value >>> 8)
  7260. this[offset + 1] = (value & 0xff)
  7261. } else {
  7262. objectWriteUInt16(this, value, offset, false)
  7263. }
  7264. return offset + 2
  7265. }
  7266. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  7267. if (value < 0) value = 0xffffffff + value + 1
  7268. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  7269. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  7270. }
  7271. }
  7272. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  7273. value = +value
  7274. offset = offset | 0
  7275. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  7276. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7277. this[offset + 3] = (value >>> 24)
  7278. this[offset + 2] = (value >>> 16)
  7279. this[offset + 1] = (value >>> 8)
  7280. this[offset] = (value & 0xff)
  7281. } else {
  7282. objectWriteUInt32(this, value, offset, true)
  7283. }
  7284. return offset + 4
  7285. }
  7286. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  7287. value = +value
  7288. offset = offset | 0
  7289. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  7290. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7291. this[offset] = (value >>> 24)
  7292. this[offset + 1] = (value >>> 16)
  7293. this[offset + 2] = (value >>> 8)
  7294. this[offset + 3] = (value & 0xff)
  7295. } else {
  7296. objectWriteUInt32(this, value, offset, false)
  7297. }
  7298. return offset + 4
  7299. }
  7300. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  7301. value = +value
  7302. offset = offset | 0
  7303. if (!noAssert) {
  7304. var limit = Math.pow(2, 8 * byteLength - 1)
  7305. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  7306. }
  7307. var i = 0
  7308. var mul = 1
  7309. var sub = 0
  7310. this[offset] = value & 0xFF
  7311. while (++i < byteLength && (mul *= 0x100)) {
  7312. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  7313. sub = 1
  7314. }
  7315. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  7316. }
  7317. return offset + byteLength
  7318. }
  7319. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  7320. value = +value
  7321. offset = offset | 0
  7322. if (!noAssert) {
  7323. var limit = Math.pow(2, 8 * byteLength - 1)
  7324. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  7325. }
  7326. var i = byteLength - 1
  7327. var mul = 1
  7328. var sub = 0
  7329. this[offset + i] = value & 0xFF
  7330. while (--i >= 0 && (mul *= 0x100)) {
  7331. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  7332. sub = 1
  7333. }
  7334. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  7335. }
  7336. return offset + byteLength
  7337. }
  7338. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  7339. value = +value
  7340. offset = offset | 0
  7341. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  7342. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  7343. if (value < 0) value = 0xff + value + 1
  7344. this[offset] = (value & 0xff)
  7345. return offset + 1
  7346. }
  7347. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  7348. value = +value
  7349. offset = offset | 0
  7350. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  7351. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7352. this[offset] = (value & 0xff)
  7353. this[offset + 1] = (value >>> 8)
  7354. } else {
  7355. objectWriteUInt16(this, value, offset, true)
  7356. }
  7357. return offset + 2
  7358. }
  7359. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  7360. value = +value
  7361. offset = offset | 0
  7362. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  7363. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7364. this[offset] = (value >>> 8)
  7365. this[offset + 1] = (value & 0xff)
  7366. } else {
  7367. objectWriteUInt16(this, value, offset, false)
  7368. }
  7369. return offset + 2
  7370. }
  7371. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  7372. value = +value
  7373. offset = offset | 0
  7374. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  7375. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7376. this[offset] = (value & 0xff)
  7377. this[offset + 1] = (value >>> 8)
  7378. this[offset + 2] = (value >>> 16)
  7379. this[offset + 3] = (value >>> 24)
  7380. } else {
  7381. objectWriteUInt32(this, value, offset, true)
  7382. }
  7383. return offset + 4
  7384. }
  7385. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  7386. value = +value
  7387. offset = offset | 0
  7388. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  7389. if (value < 0) value = 0xffffffff + value + 1
  7390. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7391. this[offset] = (value >>> 24)
  7392. this[offset + 1] = (value >>> 16)
  7393. this[offset + 2] = (value >>> 8)
  7394. this[offset + 3] = (value & 0xff)
  7395. } else {
  7396. objectWriteUInt32(this, value, offset, false)
  7397. }
  7398. return offset + 4
  7399. }
  7400. function checkIEEE754 (buf, value, offset, ext, max, min) {
  7401. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  7402. if (offset < 0) throw new RangeError('Index out of range')
  7403. }
  7404. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  7405. if (!noAssert) {
  7406. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  7407. }
  7408. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  7409. return offset + 4
  7410. }
  7411. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  7412. return writeFloat(this, value, offset, true, noAssert)
  7413. }
  7414. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  7415. return writeFloat(this, value, offset, false, noAssert)
  7416. }
  7417. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  7418. if (!noAssert) {
  7419. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  7420. }
  7421. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  7422. return offset + 8
  7423. }
  7424. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  7425. return writeDouble(this, value, offset, true, noAssert)
  7426. }
  7427. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  7428. return writeDouble(this, value, offset, false, noAssert)
  7429. }
  7430. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  7431. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  7432. if (!start) start = 0
  7433. if (!end && end !== 0) end = this.length
  7434. if (targetStart >= target.length) targetStart = target.length
  7435. if (!targetStart) targetStart = 0
  7436. if (end > 0 && end < start) end = start
  7437. // Copy 0 bytes; we're done
  7438. if (end === start) return 0
  7439. if (target.length === 0 || this.length === 0) return 0
  7440. // Fatal error conditions
  7441. if (targetStart < 0) {
  7442. throw new RangeError('targetStart out of bounds')
  7443. }
  7444. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  7445. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  7446. // Are we oob?
  7447. if (end > this.length) end = this.length
  7448. if (target.length - targetStart < end - start) {
  7449. end = target.length - targetStart + start
  7450. }
  7451. var len = end - start
  7452. var i
  7453. if (this === target && start < targetStart && targetStart < end) {
  7454. // descending copy from end
  7455. for (i = len - 1; i >= 0; --i) {
  7456. target[i + targetStart] = this[i + start]
  7457. }
  7458. } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  7459. // ascending copy from start
  7460. for (i = 0; i < len; ++i) {
  7461. target[i + targetStart] = this[i + start]
  7462. }
  7463. } else {
  7464. Uint8Array.prototype.set.call(
  7465. target,
  7466. this.subarray(start, start + len),
  7467. targetStart
  7468. )
  7469. }
  7470. return len
  7471. }
  7472. // Usage:
  7473. // buffer.fill(number[, offset[, end]])
  7474. // buffer.fill(buffer[, offset[, end]])
  7475. // buffer.fill(string[, offset[, end]][, encoding])
  7476. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  7477. // Handle string cases:
  7478. if (typeof val === 'string') {
  7479. if (typeof start === 'string') {
  7480. encoding = start
  7481. start = 0
  7482. end = this.length
  7483. } else if (typeof end === 'string') {
  7484. encoding = end
  7485. end = this.length
  7486. }
  7487. if (val.length === 1) {
  7488. var code = val.charCodeAt(0)
  7489. if (code < 256) {
  7490. val = code
  7491. }
  7492. }
  7493. if (encoding !== undefined && typeof encoding !== 'string') {
  7494. throw new TypeError('encoding must be a string')
  7495. }
  7496. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  7497. throw new TypeError('Unknown encoding: ' + encoding)
  7498. }
  7499. } else if (typeof val === 'number') {
  7500. val = val & 255
  7501. }
  7502. // Invalid ranges are not set to a default, so can range check early.
  7503. if (start < 0 || this.length < start || this.length < end) {
  7504. throw new RangeError('Out of range index')
  7505. }
  7506. if (end <= start) {
  7507. return this
  7508. }
  7509. start = start >>> 0
  7510. end = end === undefined ? this.length : end >>> 0
  7511. if (!val) val = 0
  7512. var i
  7513. if (typeof val === 'number') {
  7514. for (i = start; i < end; ++i) {
  7515. this[i] = val
  7516. }
  7517. } else {
  7518. var bytes = Buffer.isBuffer(val)
  7519. ? val
  7520. : utf8ToBytes(new Buffer(val, encoding).toString())
  7521. var len = bytes.length
  7522. for (i = 0; i < end - start; ++i) {
  7523. this[i + start] = bytes[i % len]
  7524. }
  7525. }
  7526. return this
  7527. }
  7528. // HELPER FUNCTIONS
  7529. // ================
  7530. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
  7531. function base64clean (str) {
  7532. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  7533. str = stringtrim(str).replace(INVALID_BASE64_RE, '')
  7534. // Node converts strings with length < 2 to ''
  7535. if (str.length < 2) return ''
  7536. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  7537. while (str.length % 4 !== 0) {
  7538. str = str + '='
  7539. }
  7540. return str
  7541. }
  7542. function stringtrim (str) {
  7543. if (str.trim) return str.trim()
  7544. return str.replace(/^\s+|\s+$/g, '')
  7545. }
  7546. function toHex (n) {
  7547. if (n < 16) return '0' + n.toString(16)
  7548. return n.toString(16)
  7549. }
  7550. function utf8ToBytes (string, units) {
  7551. units = units || Infinity
  7552. var codePoint
  7553. var length = string.length
  7554. var leadSurrogate = null
  7555. var bytes = []
  7556. for (var i = 0; i < length; ++i) {
  7557. codePoint = string.charCodeAt(i)
  7558. // is surrogate component
  7559. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  7560. // last char was a lead
  7561. if (!leadSurrogate) {
  7562. // no lead yet
  7563. if (codePoint > 0xDBFF) {
  7564. // unexpected trail
  7565. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7566. continue
  7567. } else if (i + 1 === length) {
  7568. // unpaired lead
  7569. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7570. continue
  7571. }
  7572. // valid lead
  7573. leadSurrogate = codePoint
  7574. continue
  7575. }
  7576. // 2 leads in a row
  7577. if (codePoint < 0xDC00) {
  7578. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7579. leadSurrogate = codePoint
  7580. continue
  7581. }
  7582. // valid surrogate pair
  7583. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  7584. } else if (leadSurrogate) {
  7585. // valid bmp char, but last char was a lead
  7586. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7587. }
  7588. leadSurrogate = null
  7589. // encode utf8
  7590. if (codePoint < 0x80) {
  7591. if ((units -= 1) < 0) break
  7592. bytes.push(codePoint)
  7593. } else if (codePoint < 0x800) {
  7594. if ((units -= 2) < 0) break
  7595. bytes.push(
  7596. codePoint >> 0x6 | 0xC0,
  7597. codePoint & 0x3F | 0x80
  7598. )
  7599. } else if (codePoint < 0x10000) {
  7600. if ((units -= 3) < 0) break
  7601. bytes.push(
  7602. codePoint >> 0xC | 0xE0,
  7603. codePoint >> 0x6 & 0x3F | 0x80,
  7604. codePoint & 0x3F | 0x80
  7605. )
  7606. } else if (codePoint < 0x110000) {
  7607. if ((units -= 4) < 0) break
  7608. bytes.push(
  7609. codePoint >> 0x12 | 0xF0,
  7610. codePoint >> 0xC & 0x3F | 0x80,
  7611. codePoint >> 0x6 & 0x3F | 0x80,
  7612. codePoint & 0x3F | 0x80
  7613. )
  7614. } else {
  7615. throw new Error('Invalid code point')
  7616. }
  7617. }
  7618. return bytes
  7619. }
  7620. function asciiToBytes (str) {
  7621. var byteArray = []
  7622. for (var i = 0; i < str.length; ++i) {
  7623. // Node's code seems to be doing this and not & 0x7F..
  7624. byteArray.push(str.charCodeAt(i) & 0xFF)
  7625. }
  7626. return byteArray
  7627. }
  7628. function utf16leToBytes (str, units) {
  7629. var c, hi, lo
  7630. var byteArray = []
  7631. for (var i = 0; i < str.length; ++i) {
  7632. if ((units -= 2) < 0) break
  7633. c = str.charCodeAt(i)
  7634. hi = c >> 8
  7635. lo = c % 256
  7636. byteArray.push(lo)
  7637. byteArray.push(hi)
  7638. }
  7639. return byteArray
  7640. }
  7641. function base64ToBytes (str) {
  7642. return base64.toByteArray(base64clean(str))
  7643. }
  7644. function blitBuffer (src, dst, offset, length) {
  7645. for (var i = 0; i < length; ++i) {
  7646. if ((i + offset >= dst.length) || (i >= src.length)) break
  7647. dst[i + offset] = src[i]
  7648. }
  7649. return i
  7650. }
  7651. function isnan (val) {
  7652. return val !== val // eslint-disable-line no-self-compare
  7653. }
  7654. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7655. },{"base64-js":39,"ieee754":50,"isarray":53}],45:[function(require,module,exports){
  7656. (function (Buffer){
  7657. // Copyright Joyent, Inc. and other Node contributors.
  7658. //
  7659. // Permission is hereby granted, free of charge, to any person obtaining a
  7660. // copy of this software and associated documentation files (the
  7661. // "Software"), to deal in the Software without restriction, including
  7662. // without limitation the rights to use, copy, modify, merge, publish,
  7663. // distribute, sublicense, and/or sell copies of the Software, and to permit
  7664. // persons to whom the Software is furnished to do so, subject to the
  7665. // following conditions:
  7666. //
  7667. // The above copyright notice and this permission notice shall be included
  7668. // in all copies or substantial portions of the Software.
  7669. //
  7670. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  7671. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  7672. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  7673. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  7674. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  7675. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  7676. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  7677. // NOTE: These type checking functions intentionally don't use `instanceof`
  7678. // because it is fragile and can be easily faked with `Object.create()`.
  7679. function isArray(arg) {
  7680. if (Array.isArray) {
  7681. return Array.isArray(arg);
  7682. }
  7683. return objectToString(arg) === '[object Array]';
  7684. }
  7685. exports.isArray = isArray;
  7686. function isBoolean(arg) {
  7687. return typeof arg === 'boolean';
  7688. }
  7689. exports.isBoolean = isBoolean;
  7690. function isNull(arg) {
  7691. return arg === null;
  7692. }
  7693. exports.isNull = isNull;
  7694. function isNullOrUndefined(arg) {
  7695. return arg == null;
  7696. }
  7697. exports.isNullOrUndefined = isNullOrUndefined;
  7698. function isNumber(arg) {
  7699. return typeof arg === 'number';
  7700. }
  7701. exports.isNumber = isNumber;
  7702. function isString(arg) {
  7703. return typeof arg === 'string';
  7704. }
  7705. exports.isString = isString;
  7706. function isSymbol(arg) {
  7707. return typeof arg === 'symbol';
  7708. }
  7709. exports.isSymbol = isSymbol;
  7710. function isUndefined(arg) {
  7711. return arg === void 0;
  7712. }
  7713. exports.isUndefined = isUndefined;
  7714. function isRegExp(re) {
  7715. return objectToString(re) === '[object RegExp]';
  7716. }
  7717. exports.isRegExp = isRegExp;
  7718. function isObject(arg) {
  7719. return typeof arg === 'object' && arg !== null;
  7720. }
  7721. exports.isObject = isObject;
  7722. function isDate(d) {
  7723. return objectToString(d) === '[object Date]';
  7724. }
  7725. exports.isDate = isDate;
  7726. function isError(e) {
  7727. return (objectToString(e) === '[object Error]' || e instanceof Error);
  7728. }
  7729. exports.isError = isError;
  7730. function isFunction(arg) {
  7731. return typeof arg === 'function';
  7732. }
  7733. exports.isFunction = isFunction;
  7734. function isPrimitive(arg) {
  7735. return arg === null ||
  7736. typeof arg === 'boolean' ||
  7737. typeof arg === 'number' ||
  7738. typeof arg === 'string' ||
  7739. typeof arg === 'symbol' || // ES6 symbol
  7740. typeof arg === 'undefined';
  7741. }
  7742. exports.isPrimitive = isPrimitive;
  7743. exports.isBuffer = Buffer.isBuffer;
  7744. function objectToString(o) {
  7745. return Object.prototype.toString.call(o);
  7746. }
  7747. }).call(this,{"isBuffer":require("../../is-buffer/index.js")})
  7748. },{"../../is-buffer/index.js":52}],46:[function(require,module,exports){
  7749. /* See LICENSE file for terms of use */
  7750. /*
  7751. * Text diff implementation.
  7752. *
  7753. * This library supports the following APIS:
  7754. * JsDiff.diffChars: Character by character diff
  7755. * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace
  7756. * JsDiff.diffLines: Line based diff
  7757. *
  7758. * JsDiff.diffCss: Diff targeted at CSS content
  7759. *
  7760. * These methods are based on the implementation proposed in
  7761. * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).
  7762. * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927
  7763. */
  7764. (function(global, undefined) {
  7765. var objectPrototypeToString = Object.prototype.toString;
  7766. /*istanbul ignore next*/
  7767. function map(arr, mapper, that) {
  7768. if (Array.prototype.map) {
  7769. return Array.prototype.map.call(arr, mapper, that);
  7770. }
  7771. var other = new Array(arr.length);
  7772. for (var i = 0, n = arr.length; i < n; i++) {
  7773. other[i] = mapper.call(that, arr[i], i, arr);
  7774. }
  7775. return other;
  7776. }
  7777. function clonePath(path) {
  7778. return { newPos: path.newPos, components: path.components.slice(0) };
  7779. }
  7780. function removeEmpty(array) {
  7781. var ret = [];
  7782. for (var i = 0; i < array.length; i++) {
  7783. if (array[i]) {
  7784. ret.push(array[i]);
  7785. }
  7786. }
  7787. return ret;
  7788. }
  7789. function escapeHTML(s) {
  7790. var n = s;
  7791. n = n.replace(/&/g, '&amp;');
  7792. n = n.replace(/</g, '&lt;');
  7793. n = n.replace(/>/g, '&gt;');
  7794. n = n.replace(/"/g, '&quot;');
  7795. return n;
  7796. }
  7797. // This function handles the presence of circular references by bailing out when encountering an
  7798. // object that is already on the "stack" of items being processed.
  7799. function canonicalize(obj, stack, replacementStack) {
  7800. stack = stack || [];
  7801. replacementStack = replacementStack || [];
  7802. var i;
  7803. for (i = 0; i < stack.length; i += 1) {
  7804. if (stack[i] === obj) {
  7805. return replacementStack[i];
  7806. }
  7807. }
  7808. var canonicalizedObj;
  7809. if ('[object Array]' === objectPrototypeToString.call(obj)) {
  7810. stack.push(obj);
  7811. canonicalizedObj = new Array(obj.length);
  7812. replacementStack.push(canonicalizedObj);
  7813. for (i = 0; i < obj.length; i += 1) {
  7814. canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack);
  7815. }
  7816. stack.pop();
  7817. replacementStack.pop();
  7818. } else if (typeof obj === 'object' && obj !== null) {
  7819. stack.push(obj);
  7820. canonicalizedObj = {};
  7821. replacementStack.push(canonicalizedObj);
  7822. var sortedKeys = [],
  7823. key;
  7824. for (key in obj) {
  7825. sortedKeys.push(key);
  7826. }
  7827. sortedKeys.sort();
  7828. for (i = 0; i < sortedKeys.length; i += 1) {
  7829. key = sortedKeys[i];
  7830. canonicalizedObj[key] = canonicalize(obj[key], stack, replacementStack);
  7831. }
  7832. stack.pop();
  7833. replacementStack.pop();
  7834. } else {
  7835. canonicalizedObj = obj;
  7836. }
  7837. return canonicalizedObj;
  7838. }
  7839. function buildValues(components, newString, oldString, useLongestToken) {
  7840. var componentPos = 0,
  7841. componentLen = components.length,
  7842. newPos = 0,
  7843. oldPos = 0;
  7844. for (; componentPos < componentLen; componentPos++) {
  7845. var component = components[componentPos];
  7846. if (!component.removed) {
  7847. if (!component.added && useLongestToken) {
  7848. var value = newString.slice(newPos, newPos + component.count);
  7849. value = map(value, function(value, i) {
  7850. var oldValue = oldString[oldPos + i];
  7851. return oldValue.length > value.length ? oldValue : value;
  7852. });
  7853. component.value = value.join('');
  7854. } else {
  7855. component.value = newString.slice(newPos, newPos + component.count).join('');
  7856. }
  7857. newPos += component.count;
  7858. // Common case
  7859. if (!component.added) {
  7860. oldPos += component.count;
  7861. }
  7862. } else {
  7863. component.value = oldString.slice(oldPos, oldPos + component.count).join('');
  7864. oldPos += component.count;
  7865. // Reverse add and remove so removes are output first to match common convention
  7866. // The diffing algorithm is tied to add then remove output and this is the simplest
  7867. // route to get the desired output with minimal overhead.
  7868. if (componentPos && components[componentPos - 1].added) {
  7869. var tmp = components[componentPos - 1];
  7870. components[componentPos - 1] = components[componentPos];
  7871. components[componentPos] = tmp;
  7872. }
  7873. }
  7874. }
  7875. return components;
  7876. }
  7877. function Diff(ignoreWhitespace) {
  7878. this.ignoreWhitespace = ignoreWhitespace;
  7879. }
  7880. Diff.prototype = {
  7881. diff: function(oldString, newString, callback) {
  7882. var self = this;
  7883. function done(value) {
  7884. if (callback) {
  7885. setTimeout(function() { callback(undefined, value); }, 0);
  7886. return true;
  7887. } else {
  7888. return value;
  7889. }
  7890. }
  7891. // Handle the identity case (this is due to unrolling editLength == 0
  7892. if (newString === oldString) {
  7893. return done([{ value: newString }]);
  7894. }
  7895. if (!newString) {
  7896. return done([{ value: oldString, removed: true }]);
  7897. }
  7898. if (!oldString) {
  7899. return done([{ value: newString, added: true }]);
  7900. }
  7901. newString = this.tokenize(newString);
  7902. oldString = this.tokenize(oldString);
  7903. var newLen = newString.length, oldLen = oldString.length;
  7904. var editLength = 1;
  7905. var maxEditLength = newLen + oldLen;
  7906. var bestPath = [{ newPos: -1, components: [] }];
  7907. // Seed editLength = 0, i.e. the content starts with the same values
  7908. var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
  7909. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  7910. // Identity per the equality and tokenizer
  7911. return done([{value: newString.join('')}]);
  7912. }
  7913. // Main worker method. checks all permutations of a given edit length for acceptance.
  7914. function execEditLength() {
  7915. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  7916. var basePath;
  7917. var addPath = bestPath[diagonalPath - 1],
  7918. removePath = bestPath[diagonalPath + 1],
  7919. oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  7920. if (addPath) {
  7921. // No one else is going to attempt to use this value, clear it
  7922. bestPath[diagonalPath - 1] = undefined;
  7923. }
  7924. var canAdd = addPath && addPath.newPos + 1 < newLen,
  7925. canRemove = removePath && 0 <= oldPos && oldPos < oldLen;
  7926. if (!canAdd && !canRemove) {
  7927. // If this path is a terminal then prune
  7928. bestPath[diagonalPath] = undefined;
  7929. continue;
  7930. }
  7931. // Select the diagonal that we want to branch from. We select the prior
  7932. // path whose position in the new string is the farthest from the origin
  7933. // and does not pass the bounds of the diff graph
  7934. if (!canAdd || (canRemove && addPath.newPos < removePath.newPos)) {
  7935. basePath = clonePath(removePath);
  7936. self.pushComponent(basePath.components, undefined, true);
  7937. } else {
  7938. basePath = addPath; // No need to clone, we've pulled it from the list
  7939. basePath.newPos++;
  7940. self.pushComponent(basePath.components, true, undefined);
  7941. }
  7942. oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath);
  7943. // If we have hit the end of both strings, then we are done
  7944. if (basePath.newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  7945. return done(buildValues(basePath.components, newString, oldString, self.useLongestToken));
  7946. } else {
  7947. // Otherwise track this path as a potential candidate and continue.
  7948. bestPath[diagonalPath] = basePath;
  7949. }
  7950. }
  7951. editLength++;
  7952. }
  7953. // Performs the length of edit iteration. Is a bit fugly as this has to support the
  7954. // sync and async mode which is never fun. Loops over execEditLength until a value
  7955. // is produced.
  7956. if (callback) {
  7957. (function exec() {
  7958. setTimeout(function() {
  7959. // This should not happen, but we want to be safe.
  7960. /*istanbul ignore next */
  7961. if (editLength > maxEditLength) {
  7962. return callback();
  7963. }
  7964. if (!execEditLength()) {
  7965. exec();
  7966. }
  7967. }, 0);
  7968. }());
  7969. } else {
  7970. while (editLength <= maxEditLength) {
  7971. var ret = execEditLength();
  7972. if (ret) {
  7973. return ret;
  7974. }
  7975. }
  7976. }
  7977. },
  7978. pushComponent: function(components, added, removed) {
  7979. var last = components[components.length - 1];
  7980. if (last && last.added === added && last.removed === removed) {
  7981. // We need to clone here as the component clone operation is just
  7982. // as shallow array clone
  7983. components[components.length - 1] = {count: last.count + 1, added: added, removed: removed };
  7984. } else {
  7985. components.push({count: 1, added: added, removed: removed });
  7986. }
  7987. },
  7988. extractCommon: function(basePath, newString, oldString, diagonalPath) {
  7989. var newLen = newString.length,
  7990. oldLen = oldString.length,
  7991. newPos = basePath.newPos,
  7992. oldPos = newPos - diagonalPath,
  7993. commonCount = 0;
  7994. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
  7995. newPos++;
  7996. oldPos++;
  7997. commonCount++;
  7998. }
  7999. if (commonCount) {
  8000. basePath.components.push({count: commonCount});
  8001. }
  8002. basePath.newPos = newPos;
  8003. return oldPos;
  8004. },
  8005. equals: function(left, right) {
  8006. var reWhitespace = /\S/;
  8007. return left === right || (this.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right));
  8008. },
  8009. tokenize: function(value) {
  8010. return value.split('');
  8011. }
  8012. };
  8013. var CharDiff = new Diff();
  8014. var WordDiff = new Diff(true);
  8015. var WordWithSpaceDiff = new Diff();
  8016. WordDiff.tokenize = WordWithSpaceDiff.tokenize = function(value) {
  8017. return removeEmpty(value.split(/(\s+|\b)/));
  8018. };
  8019. var CssDiff = new Diff(true);
  8020. CssDiff.tokenize = function(value) {
  8021. return removeEmpty(value.split(/([{}:;,]|\s+)/));
  8022. };
  8023. var LineDiff = new Diff();
  8024. var TrimmedLineDiff = new Diff();
  8025. TrimmedLineDiff.ignoreTrim = true;
  8026. LineDiff.tokenize = TrimmedLineDiff.tokenize = function(value) {
  8027. var retLines = [],
  8028. lines = value.split(/^/m);
  8029. for (var i = 0; i < lines.length; i++) {
  8030. var line = lines[i],
  8031. lastLine = lines[i - 1],
  8032. lastLineLastChar = lastLine && lastLine[lastLine.length - 1];
  8033. // Merge lines that may contain windows new lines
  8034. if (line === '\n' && lastLineLastChar === '\r') {
  8035. retLines[retLines.length - 1] = retLines[retLines.length - 1].slice(0, -1) + '\r\n';
  8036. } else {
  8037. if (this.ignoreTrim) {
  8038. line = line.trim();
  8039. // add a newline unless this is the last line.
  8040. if (i < lines.length - 1) {
  8041. line += '\n';
  8042. }
  8043. }
  8044. retLines.push(line);
  8045. }
  8046. }
  8047. return retLines;
  8048. };
  8049. var PatchDiff = new Diff();
  8050. PatchDiff.tokenize = function(value) {
  8051. var ret = [],
  8052. linesAndNewlines = value.split(/(\n|\r\n)/);
  8053. // Ignore the final empty token that occurs if the string ends with a new line
  8054. if (!linesAndNewlines[linesAndNewlines.length - 1]) {
  8055. linesAndNewlines.pop();
  8056. }
  8057. // Merge the content and line separators into single tokens
  8058. for (var i = 0; i < linesAndNewlines.length; i++) {
  8059. var line = linesAndNewlines[i];
  8060. if (i % 2) {
  8061. ret[ret.length - 1] += line;
  8062. } else {
  8063. ret.push(line);
  8064. }
  8065. }
  8066. return ret;
  8067. };
  8068. var SentenceDiff = new Diff();
  8069. SentenceDiff.tokenize = function(value) {
  8070. return removeEmpty(value.split(/(\S.+?[.!?])(?=\s+|$)/));
  8071. };
  8072. var JsonDiff = new Diff();
  8073. // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
  8074. // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
  8075. JsonDiff.useLongestToken = true;
  8076. JsonDiff.tokenize = LineDiff.tokenize;
  8077. JsonDiff.equals = function(left, right) {
  8078. return LineDiff.equals(left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'));
  8079. };
  8080. var JsDiff = {
  8081. Diff: Diff,
  8082. diffChars: function(oldStr, newStr, callback) { return CharDiff.diff(oldStr, newStr, callback); },
  8083. diffWords: function(oldStr, newStr, callback) { return WordDiff.diff(oldStr, newStr, callback); },
  8084. diffWordsWithSpace: function(oldStr, newStr, callback) { return WordWithSpaceDiff.diff(oldStr, newStr, callback); },
  8085. diffLines: function(oldStr, newStr, callback) { return LineDiff.diff(oldStr, newStr, callback); },
  8086. diffTrimmedLines: function(oldStr, newStr, callback) { return TrimmedLineDiff.diff(oldStr, newStr, callback); },
  8087. diffSentences: function(oldStr, newStr, callback) { return SentenceDiff.diff(oldStr, newStr, callback); },
  8088. diffCss: function(oldStr, newStr, callback) { return CssDiff.diff(oldStr, newStr, callback); },
  8089. diffJson: function(oldObj, newObj, callback) {
  8090. return JsonDiff.diff(
  8091. typeof oldObj === 'string' ? oldObj : JSON.stringify(canonicalize(oldObj), undefined, ' '),
  8092. typeof newObj === 'string' ? newObj : JSON.stringify(canonicalize(newObj), undefined, ' '),
  8093. callback
  8094. );
  8095. },
  8096. createTwoFilesPatch: function(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader) {
  8097. var ret = [];
  8098. if (oldFileName == newFileName) {
  8099. ret.push('Index: ' + oldFileName);
  8100. }
  8101. ret.push('===================================================================');
  8102. ret.push('--- ' + oldFileName + (typeof oldHeader === 'undefined' ? '' : '\t' + oldHeader));
  8103. ret.push('+++ ' + newFileName + (typeof newHeader === 'undefined' ? '' : '\t' + newHeader));
  8104. var diff = PatchDiff.diff(oldStr, newStr);
  8105. diff.push({value: '', lines: []}); // Append an empty value to make cleanup easier
  8106. // Formats a given set of lines for printing as context lines in a patch
  8107. function contextLines(lines) {
  8108. return map(lines, function(entry) { return ' ' + entry; });
  8109. }
  8110. // Outputs the no newline at end of file warning if needed
  8111. function eofNL(curRange, i, current) {
  8112. var last = diff[diff.length - 2],
  8113. isLast = i === diff.length - 2,
  8114. isLastOfType = i === diff.length - 3 && current.added !== last.added;
  8115. // Figure out if this is the last line for the given file and missing NL
  8116. if (!(/\n$/.test(current.value)) && (isLast || isLastOfType)) {
  8117. curRange.push('\\ No newline at end of file');
  8118. }
  8119. }
  8120. var oldRangeStart = 0, newRangeStart = 0, curRange = [],
  8121. oldLine = 1, newLine = 1;
  8122. for (var i = 0; i < diff.length; i++) {
  8123. var current = diff[i],
  8124. lines = current.lines || current.value.replace(/\n$/, '').split('\n');
  8125. current.lines = lines;
  8126. if (current.added || current.removed) {
  8127. // If we have previous context, start with that
  8128. if (!oldRangeStart) {
  8129. var prev = diff[i - 1];
  8130. oldRangeStart = oldLine;
  8131. newRangeStart = newLine;
  8132. if (prev) {
  8133. curRange = contextLines(prev.lines.slice(-4));
  8134. oldRangeStart -= curRange.length;
  8135. newRangeStart -= curRange.length;
  8136. }
  8137. }
  8138. // Output our changes
  8139. curRange.push.apply(curRange, map(lines, function(entry) {
  8140. return (current.added ? '+' : '-') + entry;
  8141. }));
  8142. eofNL(curRange, i, current);
  8143. // Track the updated file position
  8144. if (current.added) {
  8145. newLine += lines.length;
  8146. } else {
  8147. oldLine += lines.length;
  8148. }
  8149. } else {
  8150. // Identical context lines. Track line changes
  8151. if (oldRangeStart) {
  8152. // Close out any changes that have been output (or join overlapping)
  8153. if (lines.length <= 8 && i < diff.length - 2) {
  8154. // Overlapping
  8155. curRange.push.apply(curRange, contextLines(lines));
  8156. } else {
  8157. // end the range and output
  8158. var contextSize = Math.min(lines.length, 4);
  8159. ret.push(
  8160. '@@ -' + oldRangeStart + ',' + (oldLine - oldRangeStart + contextSize)
  8161. + ' +' + newRangeStart + ',' + (newLine - newRangeStart + contextSize)
  8162. + ' @@');
  8163. ret.push.apply(ret, curRange);
  8164. ret.push.apply(ret, contextLines(lines.slice(0, contextSize)));
  8165. if (lines.length <= 4) {
  8166. eofNL(ret, i, current);
  8167. }
  8168. oldRangeStart = 0;
  8169. newRangeStart = 0;
  8170. curRange = [];
  8171. }
  8172. }
  8173. oldLine += lines.length;
  8174. newLine += lines.length;
  8175. }
  8176. }
  8177. return ret.join('\n') + '\n';
  8178. },
  8179. createPatch: function(fileName, oldStr, newStr, oldHeader, newHeader) {
  8180. return JsDiff.createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader);
  8181. },
  8182. applyPatch: function(oldStr, uniDiff) {
  8183. var diffstr = uniDiff.split('\n'),
  8184. hunks = [],
  8185. i = 0,
  8186. remEOFNL = false,
  8187. addEOFNL = false;
  8188. // Skip to the first change hunk
  8189. while (i < diffstr.length && !(/^@@/.test(diffstr[i]))) {
  8190. i++;
  8191. }
  8192. // Parse the unified diff
  8193. for (; i < diffstr.length; i++) {
  8194. if (diffstr[i][0] === '@') {
  8195. var chnukHeader = diffstr[i].split(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/);
  8196. hunks.unshift({
  8197. start: chnukHeader[3],
  8198. oldlength: +chnukHeader[2],
  8199. removed: [],
  8200. newlength: chnukHeader[4],
  8201. added: []
  8202. });
  8203. } else if (diffstr[i][0] === '+') {
  8204. hunks[0].added.push(diffstr[i].substr(1));
  8205. } else if (diffstr[i][0] === '-') {
  8206. hunks[0].removed.push(diffstr[i].substr(1));
  8207. } else if (diffstr[i][0] === ' ') {
  8208. hunks[0].added.push(diffstr[i].substr(1));
  8209. hunks[0].removed.push(diffstr[i].substr(1));
  8210. } else if (diffstr[i][0] === '\\') {
  8211. if (diffstr[i - 1][0] === '+') {
  8212. remEOFNL = true;
  8213. } else if (diffstr[i - 1][0] === '-') {
  8214. addEOFNL = true;
  8215. }
  8216. }
  8217. }
  8218. // Apply the diff to the input
  8219. var lines = oldStr.split('\n');
  8220. for (i = hunks.length - 1; i >= 0; i--) {
  8221. var hunk = hunks[i];
  8222. // Sanity check the input string. Bail if we don't match.
  8223. for (var j = 0; j < hunk.oldlength; j++) {
  8224. if (lines[hunk.start - 1 + j] !== hunk.removed[j]) {
  8225. return false;
  8226. }
  8227. }
  8228. Array.prototype.splice.apply(lines, [hunk.start - 1, hunk.oldlength].concat(hunk.added));
  8229. }
  8230. // Handle EOFNL insertion/removal
  8231. if (remEOFNL) {
  8232. while (!lines[lines.length - 1]) {
  8233. lines.pop();
  8234. }
  8235. } else if (addEOFNL) {
  8236. lines.push('');
  8237. }
  8238. return lines.join('\n');
  8239. },
  8240. convertChangesToXML: function(changes) {
  8241. var ret = [];
  8242. for (var i = 0; i < changes.length; i++) {
  8243. var change = changes[i];
  8244. if (change.added) {
  8245. ret.push('<ins>');
  8246. } else if (change.removed) {
  8247. ret.push('<del>');
  8248. }
  8249. ret.push(escapeHTML(change.value));
  8250. if (change.added) {
  8251. ret.push('</ins>');
  8252. } else if (change.removed) {
  8253. ret.push('</del>');
  8254. }
  8255. }
  8256. return ret.join('');
  8257. },
  8258. // See: http://code.google.com/p/google-diff-match-patch/wiki/API
  8259. convertChangesToDMP: function(changes) {
  8260. var ret = [],
  8261. change,
  8262. operation;
  8263. for (var i = 0; i < changes.length; i++) {
  8264. change = changes[i];
  8265. if (change.added) {
  8266. operation = 1;
  8267. } else if (change.removed) {
  8268. operation = -1;
  8269. } else {
  8270. operation = 0;
  8271. }
  8272. ret.push([operation, change.value]);
  8273. }
  8274. return ret;
  8275. },
  8276. canonicalize: canonicalize
  8277. };
  8278. /*istanbul ignore next */
  8279. /*global module */
  8280. if (typeof module !== 'undefined' && module.exports) {
  8281. module.exports = JsDiff;
  8282. } else if (false) {
  8283. /*global define */
  8284. define([], function() { return JsDiff; });
  8285. } else if (typeof global.JsDiff === 'undefined') {
  8286. global.JsDiff = JsDiff;
  8287. }
  8288. }(this));
  8289. },{}],47:[function(require,module,exports){
  8290. 'use strict';
  8291. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  8292. module.exports = function (str) {
  8293. if (typeof str !== 'string') {
  8294. throw new TypeError('Expected a string');
  8295. }
  8296. return str.replace(matchOperatorsRe, '\\$&');
  8297. };
  8298. },{}],48:[function(require,module,exports){
  8299. // Copyright Joyent, Inc. and other Node contributors.
  8300. //
  8301. // Permission is hereby granted, free of charge, to any person obtaining a
  8302. // copy of this software and associated documentation files (the
  8303. // "Software"), to deal in the Software without restriction, including
  8304. // without limitation the rights to use, copy, modify, merge, publish,
  8305. // distribute, sublicense, and/or sell copies of the Software, and to permit
  8306. // persons to whom the Software is furnished to do so, subject to the
  8307. // following conditions:
  8308. //
  8309. // The above copyright notice and this permission notice shall be included
  8310. // in all copies or substantial portions of the Software.
  8311. //
  8312. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  8313. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  8314. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  8315. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  8316. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  8317. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  8318. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  8319. function EventEmitter() {
  8320. this._events = this._events || {};
  8321. this._maxListeners = this._maxListeners || undefined;
  8322. }
  8323. module.exports = EventEmitter;
  8324. // Backwards-compat with node 0.10.x
  8325. EventEmitter.EventEmitter = EventEmitter;
  8326. EventEmitter.prototype._events = undefined;
  8327. EventEmitter.prototype._maxListeners = undefined;
  8328. // By default EventEmitters will print a warning if more than 10 listeners are
  8329. // added to it. This is a useful default which helps finding memory leaks.
  8330. EventEmitter.defaultMaxListeners = 10;
  8331. // Obviously not all Emitters should be limited to 10. This function allows
  8332. // that to be increased. Set to zero for unlimited.
  8333. EventEmitter.prototype.setMaxListeners = function(n) {
  8334. if (!isNumber(n) || n < 0 || isNaN(n))
  8335. throw TypeError('n must be a positive number');
  8336. this._maxListeners = n;
  8337. return this;
  8338. };
  8339. EventEmitter.prototype.emit = function(type) {
  8340. var er, handler, len, args, i, listeners;
  8341. if (!this._events)
  8342. this._events = {};
  8343. // If there is no 'error' event listener then throw.
  8344. if (type === 'error') {
  8345. if (!this._events.error ||
  8346. (isObject(this._events.error) && !this._events.error.length)) {
  8347. er = arguments[1];
  8348. if (er instanceof Error) {
  8349. throw er; // Unhandled 'error' event
  8350. } else {
  8351. // At least give some kind of context to the user
  8352. var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
  8353. err.context = er;
  8354. throw err;
  8355. }
  8356. }
  8357. }
  8358. handler = this._events[type];
  8359. if (isUndefined(handler))
  8360. return false;
  8361. if (isFunction(handler)) {
  8362. switch (arguments.length) {
  8363. // fast cases
  8364. case 1:
  8365. handler.call(this);
  8366. break;
  8367. case 2:
  8368. handler.call(this, arguments[1]);
  8369. break;
  8370. case 3:
  8371. handler.call(this, arguments[1], arguments[2]);
  8372. break;
  8373. // slower
  8374. default:
  8375. args = Array.prototype.slice.call(arguments, 1);
  8376. handler.apply(this, args);
  8377. }
  8378. } else if (isObject(handler)) {
  8379. args = Array.prototype.slice.call(arguments, 1);
  8380. listeners = handler.slice();
  8381. len = listeners.length;
  8382. for (i = 0; i < len; i++)
  8383. listeners[i].apply(this, args);
  8384. }
  8385. return true;
  8386. };
  8387. EventEmitter.prototype.addListener = function(type, listener) {
  8388. var m;
  8389. if (!isFunction(listener))
  8390. throw TypeError('listener must be a function');
  8391. if (!this._events)
  8392. this._events = {};
  8393. // To avoid recursion in the case that type === "newListener"! Before
  8394. // adding it to the listeners, first emit "newListener".
  8395. if (this._events.newListener)
  8396. this.emit('newListener', type,
  8397. isFunction(listener.listener) ?
  8398. listener.listener : listener);
  8399. if (!this._events[type])
  8400. // Optimize the case of one listener. Don't need the extra array object.
  8401. this._events[type] = listener;
  8402. else if (isObject(this._events[type]))
  8403. // If we've already got an array, just append.
  8404. this._events[type].push(listener);
  8405. else
  8406. // Adding the second element, need to change to array.
  8407. this._events[type] = [this._events[type], listener];
  8408. // Check for listener leak
  8409. if (isObject(this._events[type]) && !this._events[type].warned) {
  8410. if (!isUndefined(this._maxListeners)) {
  8411. m = this._maxListeners;
  8412. } else {
  8413. m = EventEmitter.defaultMaxListeners;
  8414. }
  8415. if (m && m > 0 && this._events[type].length > m) {
  8416. this._events[type].warned = true;
  8417. console.error('(node) warning: possible EventEmitter memory ' +
  8418. 'leak detected. %d listeners added. ' +
  8419. 'Use emitter.setMaxListeners() to increase limit.',
  8420. this._events[type].length);
  8421. if (typeof console.trace === 'function') {
  8422. // not supported in IE 10
  8423. console.trace();
  8424. }
  8425. }
  8426. }
  8427. return this;
  8428. };
  8429. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  8430. EventEmitter.prototype.once = function(type, listener) {
  8431. if (!isFunction(listener))
  8432. throw TypeError('listener must be a function');
  8433. var fired = false;
  8434. function g() {
  8435. this.removeListener(type, g);
  8436. if (!fired) {
  8437. fired = true;
  8438. listener.apply(this, arguments);
  8439. }
  8440. }
  8441. g.listener = listener;
  8442. this.on(type, g);
  8443. return this;
  8444. };
  8445. // emits a 'removeListener' event iff the listener was removed
  8446. EventEmitter.prototype.removeListener = function(type, listener) {
  8447. var list, position, length, i;
  8448. if (!isFunction(listener))
  8449. throw TypeError('listener must be a function');
  8450. if (!this._events || !this._events[type])
  8451. return this;
  8452. list = this._events[type];
  8453. length = list.length;
  8454. position = -1;
  8455. if (list === listener ||
  8456. (isFunction(list.listener) && list.listener === listener)) {
  8457. delete this._events[type];
  8458. if (this._events.removeListener)
  8459. this.emit('removeListener', type, listener);
  8460. } else if (isObject(list)) {
  8461. for (i = length; i-- > 0;) {
  8462. if (list[i] === listener ||
  8463. (list[i].listener && list[i].listener === listener)) {
  8464. position = i;
  8465. break;
  8466. }
  8467. }
  8468. if (position < 0)
  8469. return this;
  8470. if (list.length === 1) {
  8471. list.length = 0;
  8472. delete this._events[type];
  8473. } else {
  8474. list.splice(position, 1);
  8475. }
  8476. if (this._events.removeListener)
  8477. this.emit('removeListener', type, listener);
  8478. }
  8479. return this;
  8480. };
  8481. EventEmitter.prototype.removeAllListeners = function(type) {
  8482. var key, listeners;
  8483. if (!this._events)
  8484. return this;
  8485. // not listening for removeListener, no need to emit
  8486. if (!this._events.removeListener) {
  8487. if (arguments.length === 0)
  8488. this._events = {};
  8489. else if (this._events[type])
  8490. delete this._events[type];
  8491. return this;
  8492. }
  8493. // emit removeListener for all listeners on all events
  8494. if (arguments.length === 0) {
  8495. for (key in this._events) {
  8496. if (key === 'removeListener') continue;
  8497. this.removeAllListeners(key);
  8498. }
  8499. this.removeAllListeners('removeListener');
  8500. this._events = {};
  8501. return this;
  8502. }
  8503. listeners = this._events[type];
  8504. if (isFunction(listeners)) {
  8505. this.removeListener(type, listeners);
  8506. } else if (listeners) {
  8507. // LIFO order
  8508. while (listeners.length)
  8509. this.removeListener(type, listeners[listeners.length - 1]);
  8510. }
  8511. delete this._events[type];
  8512. return this;
  8513. };
  8514. EventEmitter.prototype.listeners = function(type) {
  8515. var ret;
  8516. if (!this._events || !this._events[type])
  8517. ret = [];
  8518. else if (isFunction(this._events[type]))
  8519. ret = [this._events[type]];
  8520. else
  8521. ret = this._events[type].slice();
  8522. return ret;
  8523. };
  8524. EventEmitter.prototype.listenerCount = function(type) {
  8525. if (this._events) {
  8526. var evlistener = this._events[type];
  8527. if (isFunction(evlistener))
  8528. return 1;
  8529. else if (evlistener)
  8530. return evlistener.length;
  8531. }
  8532. return 0;
  8533. };
  8534. EventEmitter.listenerCount = function(emitter, type) {
  8535. return emitter.listenerCount(type);
  8536. };
  8537. function isFunction(arg) {
  8538. return typeof arg === 'function';
  8539. }
  8540. function isNumber(arg) {
  8541. return typeof arg === 'number';
  8542. }
  8543. function isObject(arg) {
  8544. return typeof arg === 'object' && arg !== null;
  8545. }
  8546. function isUndefined(arg) {
  8547. return arg === void 0;
  8548. }
  8549. },{}],49:[function(require,module,exports){
  8550. (function (process){
  8551. // Growl - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
  8552. /**
  8553. * Module dependencies.
  8554. */
  8555. var exec = require('child_process').exec
  8556. , fs = require('fs')
  8557. , path = require('path')
  8558. , exists = fs.existsSync || path.existsSync
  8559. , os = require('os')
  8560. , quote = JSON.stringify
  8561. , cmd;
  8562. function which(name) {
  8563. var paths = process.env.PATH.split(':');
  8564. var loc;
  8565. for (var i = 0, len = paths.length; i < len; ++i) {
  8566. loc = path.join(paths[i], name);
  8567. if (exists(loc)) return loc;
  8568. }
  8569. }
  8570. switch(os.type()) {
  8571. case 'Darwin':
  8572. if (which('terminal-notifier')) {
  8573. cmd = {
  8574. type: "Darwin-NotificationCenter"
  8575. , pkg: "terminal-notifier"
  8576. , msg: '-message'
  8577. , title: '-title'
  8578. , subtitle: '-subtitle'
  8579. , icon: '-appIcon'
  8580. , sound: '-sound'
  8581. , url: '-open'
  8582. , priority: {
  8583. cmd: '-execute'
  8584. , range: []
  8585. }
  8586. };
  8587. } else {
  8588. cmd = {
  8589. type: "Darwin-Growl"
  8590. , pkg: "growlnotify"
  8591. , msg: '-m'
  8592. , sticky: '--sticky'
  8593. , priority: {
  8594. cmd: '--priority'
  8595. , range: [
  8596. -2
  8597. , -1
  8598. , 0
  8599. , 1
  8600. , 2
  8601. , "Very Low"
  8602. , "Moderate"
  8603. , "Normal"
  8604. , "High"
  8605. , "Emergency"
  8606. ]
  8607. }
  8608. };
  8609. }
  8610. break;
  8611. case 'Linux':
  8612. if (which('growl')) {
  8613. cmd = {
  8614. type: "Linux-Growl"
  8615. , pkg: "growl"
  8616. , msg: '-m'
  8617. , title: '-title'
  8618. , subtitle: '-subtitle'
  8619. , host: {
  8620. cmd: '-H'
  8621. , hostname: '192.168.33.1'
  8622. }
  8623. };
  8624. } else {
  8625. cmd = {
  8626. type: "Linux"
  8627. , pkg: "notify-send"
  8628. , msg: ''
  8629. , sticky: '-t 0'
  8630. , icon: '-i'
  8631. , priority: {
  8632. cmd: '-u'
  8633. , range: [
  8634. "low"
  8635. , "normal"
  8636. , "critical"
  8637. ]
  8638. }
  8639. };
  8640. }
  8641. break;
  8642. case 'Windows_NT':
  8643. cmd = {
  8644. type: "Windows"
  8645. , pkg: "growlnotify"
  8646. , msg: ''
  8647. , sticky: '/s:true'
  8648. , title: '/t:'
  8649. , icon: '/i:'
  8650. , url: '/cu:'
  8651. , priority: {
  8652. cmd: '/p:'
  8653. , range: [
  8654. -2
  8655. , -1
  8656. , 0
  8657. , 1
  8658. , 2
  8659. ]
  8660. }
  8661. };
  8662. break;
  8663. }
  8664. /**
  8665. * Expose `growl`.
  8666. */
  8667. exports = module.exports = growl;
  8668. /**
  8669. * Node-growl version.
  8670. */
  8671. exports.version = '1.4.1'
  8672. /**
  8673. * Send growl notification _msg_ with _options_.
  8674. *
  8675. * Options:
  8676. *
  8677. * - title Notification title
  8678. * - sticky Make the notification stick (defaults to false)
  8679. * - priority Specify an int or named key (default is 0)
  8680. * - name Application name (defaults to growlnotify)
  8681. * - sound Sound efect ( in OSx defined in preferences -> sound -> effects) * works only in OSX > 10.8x
  8682. * - image
  8683. * - path to an icon sets --iconpath
  8684. * - path to an image sets --image
  8685. * - capitalized word sets --appIcon
  8686. * - filename uses extname as --icon
  8687. * - otherwise treated as --icon
  8688. *
  8689. * Examples:
  8690. *
  8691. * growl('New email')
  8692. * growl('5 new emails', { title: 'Thunderbird' })
  8693. * growl('5 new emails', { title: 'Thunderbird', sound: 'Purr' })
  8694. * growl('Email sent', function(){
  8695. * // ... notification sent
  8696. * })
  8697. *
  8698. * @param {string} msg
  8699. * @param {object} options
  8700. * @param {function} fn
  8701. * @api public
  8702. */
  8703. function growl(msg, options, fn) {
  8704. var image
  8705. , args
  8706. , options = options || {}
  8707. , fn = fn || function(){};
  8708. if (options.exec) {
  8709. cmd = {
  8710. type: "Custom"
  8711. , pkg: options.exec
  8712. , range: []
  8713. };
  8714. }
  8715. // noop
  8716. if (!cmd) return fn(new Error('growl not supported on this platform'));
  8717. args = [cmd.pkg];
  8718. // image
  8719. if (image = options.image) {
  8720. switch(cmd.type) {
  8721. case 'Darwin-Growl':
  8722. var flag, ext = path.extname(image).substr(1)
  8723. flag = flag || ext == 'icns' && 'iconpath'
  8724. flag = flag || /^[A-Z]/.test(image) && 'appIcon'
  8725. flag = flag || /^png|gif|jpe?g$/.test(ext) && 'image'
  8726. flag = flag || ext && (image = ext) && 'icon'
  8727. flag = flag || 'icon'
  8728. args.push('--' + flag, quote(image))
  8729. break;
  8730. case 'Darwin-NotificationCenter':
  8731. args.push(cmd.icon, quote(image));
  8732. break;
  8733. case 'Linux':
  8734. args.push(cmd.icon, quote(image));
  8735. // libnotify defaults to sticky, set a hint for transient notifications
  8736. if (!options.sticky) args.push('--hint=int:transient:1');
  8737. break;
  8738. case 'Windows':
  8739. args.push(cmd.icon + quote(image));
  8740. break;
  8741. }
  8742. }
  8743. // sticky
  8744. if (options.sticky) args.push(cmd.sticky);
  8745. // priority
  8746. if (options.priority) {
  8747. var priority = options.priority + '';
  8748. var checkindexOf = cmd.priority.range.indexOf(priority);
  8749. if (~cmd.priority.range.indexOf(priority)) {
  8750. args.push(cmd.priority, options.priority);
  8751. }
  8752. }
  8753. //sound
  8754. if(options.sound && cmd.type === 'Darwin-NotificationCenter'){
  8755. args.push(cmd.sound, options.sound)
  8756. }
  8757. // name
  8758. if (options.name && cmd.type === "Darwin-Growl") {
  8759. args.push('--name', options.name);
  8760. }
  8761. switch(cmd.type) {
  8762. case 'Darwin-Growl':
  8763. args.push(cmd.msg);
  8764. args.push(quote(msg).replace(/\\n/g, '\n'));
  8765. if (options.title) args.push(quote(options.title));
  8766. break;
  8767. case 'Darwin-NotificationCenter':
  8768. args.push(cmd.msg);
  8769. var stringifiedMsg = quote(msg);
  8770. var escapedMsg = stringifiedMsg.replace(/\\n/g, '\n');
  8771. args.push(escapedMsg);
  8772. if (options.title) {
  8773. args.push(cmd.title);
  8774. args.push(quote(options.title));
  8775. }
  8776. if (options.subtitle) {
  8777. args.push(cmd.subtitle);
  8778. args.push(quote(options.subtitle));
  8779. }
  8780. if (options.url) {
  8781. args.push(cmd.url);
  8782. args.push(quote(options.url));
  8783. }
  8784. break;
  8785. case 'Linux-Growl':
  8786. args.push(cmd.msg);
  8787. args.push(quote(msg).replace(/\\n/g, '\n'));
  8788. if (options.title) args.push(quote(options.title));
  8789. if (cmd.host) {
  8790. args.push(cmd.host.cmd, cmd.host.hostname)
  8791. }
  8792. break;
  8793. case 'Linux':
  8794. if (options.title) {
  8795. args.push(quote(options.title));
  8796. args.push(cmd.msg);
  8797. args.push(quote(msg).replace(/\\n/g, '\n'));
  8798. } else {
  8799. args.push(quote(msg).replace(/\\n/g, '\n'));
  8800. }
  8801. break;
  8802. case 'Windows':
  8803. args.push(quote(msg).replace(/\\n/g, '\n'));
  8804. if (options.title) args.push(cmd.title + quote(options.title));
  8805. if (options.url) args.push(cmd.url + quote(options.url));
  8806. break;
  8807. case 'Custom':
  8808. args[0] = (function(origCommand) {
  8809. var message = options.title
  8810. ? options.title + ': ' + msg
  8811. : msg;
  8812. var command = origCommand.replace(/(^|[^%])%s/g, '$1' + quote(message));
  8813. if (command === origCommand) args.push(quote(message));
  8814. return command;
  8815. })(args[0]);
  8816. break;
  8817. }
  8818. // execute
  8819. exec(args.join(' '), fn);
  8820. };
  8821. }).call(this,require('_process'))
  8822. },{"_process":67,"child_process":42,"fs":42,"os":65,"path":42}],50:[function(require,module,exports){
  8823. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  8824. var e, m
  8825. var eLen = nBytes * 8 - mLen - 1
  8826. var eMax = (1 << eLen) - 1
  8827. var eBias = eMax >> 1
  8828. var nBits = -7
  8829. var i = isLE ? (nBytes - 1) : 0
  8830. var d = isLE ? -1 : 1
  8831. var s = buffer[offset + i]
  8832. i += d
  8833. e = s & ((1 << (-nBits)) - 1)
  8834. s >>= (-nBits)
  8835. nBits += eLen
  8836. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  8837. m = e & ((1 << (-nBits)) - 1)
  8838. e >>= (-nBits)
  8839. nBits += mLen
  8840. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  8841. if (e === 0) {
  8842. e = 1 - eBias
  8843. } else if (e === eMax) {
  8844. return m ? NaN : ((s ? -1 : 1) * Infinity)
  8845. } else {
  8846. m = m + Math.pow(2, mLen)
  8847. e = e - eBias
  8848. }
  8849. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  8850. }
  8851. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  8852. var e, m, c
  8853. var eLen = nBytes * 8 - mLen - 1
  8854. var eMax = (1 << eLen) - 1
  8855. var eBias = eMax >> 1
  8856. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  8857. var i = isLE ? 0 : (nBytes - 1)
  8858. var d = isLE ? 1 : -1
  8859. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  8860. value = Math.abs(value)
  8861. if (isNaN(value) || value === Infinity) {
  8862. m = isNaN(value) ? 1 : 0
  8863. e = eMax
  8864. } else {
  8865. e = Math.floor(Math.log(value) / Math.LN2)
  8866. if (value * (c = Math.pow(2, -e)) < 1) {
  8867. e--
  8868. c *= 2
  8869. }
  8870. if (e + eBias >= 1) {
  8871. value += rt / c
  8872. } else {
  8873. value += rt * Math.pow(2, 1 - eBias)
  8874. }
  8875. if (value * c >= 2) {
  8876. e++
  8877. c /= 2
  8878. }
  8879. if (e + eBias >= eMax) {
  8880. m = 0
  8881. e = eMax
  8882. } else if (e + eBias >= 1) {
  8883. m = (value * c - 1) * Math.pow(2, mLen)
  8884. e = e + eBias
  8885. } else {
  8886. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  8887. e = 0
  8888. }
  8889. }
  8890. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  8891. e = (e << mLen) | m
  8892. eLen += mLen
  8893. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  8894. buffer[offset + i - d] |= s * 128
  8895. }
  8896. },{}],51:[function(require,module,exports){
  8897. if (typeof Object.create === 'function') {
  8898. // implementation from standard node.js 'util' module
  8899. module.exports = function inherits(ctor, superCtor) {
  8900. ctor.super_ = superCtor
  8901. ctor.prototype = Object.create(superCtor.prototype, {
  8902. constructor: {
  8903. value: ctor,
  8904. enumerable: false,
  8905. writable: true,
  8906. configurable: true
  8907. }
  8908. });
  8909. };
  8910. } else {
  8911. // old school shim for old browsers
  8912. module.exports = function inherits(ctor, superCtor) {
  8913. ctor.super_ = superCtor
  8914. var TempCtor = function () {}
  8915. TempCtor.prototype = superCtor.prototype
  8916. ctor.prototype = new TempCtor()
  8917. ctor.prototype.constructor = ctor
  8918. }
  8919. }
  8920. },{}],52:[function(require,module,exports){
  8921. /*!
  8922. * Determine if an object is a Buffer
  8923. *
  8924. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  8925. * @license MIT
  8926. */
  8927. // The _isBuffer check is for Safari 5-7 support, because it's missing
  8928. // Object.prototype.constructor. Remove this eventually
  8929. module.exports = function (obj) {
  8930. return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
  8931. }
  8932. function isBuffer (obj) {
  8933. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  8934. }
  8935. // For Node v0.10 support. Remove this eventually.
  8936. function isSlowBuffer (obj) {
  8937. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
  8938. }
  8939. },{}],53:[function(require,module,exports){
  8940. var toString = {}.toString;
  8941. module.exports = Array.isArray || function (arr) {
  8942. return toString.call(arr) == '[object Array]';
  8943. };
  8944. },{}],54:[function(require,module,exports){
  8945. (function (global){
  8946. /*! JSON v3.3.2 | http://bestiejs.github.io/json3 | Copyright 2012-2014, Kit Cambridge | http://kit.mit-license.org */
  8947. ;(function () {
  8948. // Detect the `define` function exposed by asynchronous module loaders. The
  8949. // strict `define` check is necessary for compatibility with `r.js`.
  8950. var isLoader = false;
  8951. // A set of types used to distinguish objects from primitives.
  8952. var objectTypes = {
  8953. "function": true,
  8954. "object": true
  8955. };
  8956. // Detect the `exports` object exposed by CommonJS implementations.
  8957. var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
  8958. // Use the `global` object exposed by Node (including Browserify via
  8959. // `insert-module-globals`), Narwhal, and Ringo as the default context,
  8960. // and the `window` object in browsers. Rhino exports a `global` function
  8961. // instead.
  8962. var root = objectTypes[typeof window] && window || this,
  8963. freeGlobal = freeExports && objectTypes[typeof module] && module && !module.nodeType && typeof global == "object" && global;
  8964. if (freeGlobal && (freeGlobal["global"] === freeGlobal || freeGlobal["window"] === freeGlobal || freeGlobal["self"] === freeGlobal)) {
  8965. root = freeGlobal;
  8966. }
  8967. // Public: Initializes JSON 3 using the given `context` object, attaching the
  8968. // `stringify` and `parse` functions to the specified `exports` object.
  8969. function runInContext(context, exports) {
  8970. context || (context = root["Object"]());
  8971. exports || (exports = root["Object"]());
  8972. // Native constructor aliases.
  8973. var Number = context["Number"] || root["Number"],
  8974. String = context["String"] || root["String"],
  8975. Object = context["Object"] || root["Object"],
  8976. Date = context["Date"] || root["Date"],
  8977. SyntaxError = context["SyntaxError"] || root["SyntaxError"],
  8978. TypeError = context["TypeError"] || root["TypeError"],
  8979. Math = context["Math"] || root["Math"],
  8980. nativeJSON = context["JSON"] || root["JSON"];
  8981. // Delegate to the native `stringify` and `parse` implementations.
  8982. if (typeof nativeJSON == "object" && nativeJSON) {
  8983. exports.stringify = nativeJSON.stringify;
  8984. exports.parse = nativeJSON.parse;
  8985. }
  8986. // Convenience aliases.
  8987. var objectProto = Object.prototype,
  8988. getClass = objectProto.toString,
  8989. isProperty, forEach, undef;
  8990. // Test the `Date#getUTC*` methods. Based on work by @Yaffle.
  8991. var isExtended = new Date(-3509827334573292);
  8992. try {
  8993. // The `getUTCFullYear`, `Month`, and `Date` methods return nonsensical
  8994. // results for certain dates in Opera >= 10.53.
  8995. isExtended = isExtended.getUTCFullYear() == -109252 && isExtended.getUTCMonth() === 0 && isExtended.getUTCDate() === 1 &&
  8996. // Safari < 2.0.2 stores the internal millisecond time value correctly,
  8997. // but clips the values returned by the date methods to the range of
  8998. // signed 32-bit integers ([-2 ** 31, 2 ** 31 - 1]).
  8999. isExtended.getUTCHours() == 10 && isExtended.getUTCMinutes() == 37 && isExtended.getUTCSeconds() == 6 && isExtended.getUTCMilliseconds() == 708;
  9000. } catch (exception) {}
  9001. // Internal: Determines whether the native `JSON.stringify` and `parse`
  9002. // implementations are spec-compliant. Based on work by Ken Snyder.
  9003. function has(name) {
  9004. if (has[name] !== undef) {
  9005. // Return cached feature test result.
  9006. return has[name];
  9007. }
  9008. var isSupported;
  9009. if (name == "bug-string-char-index") {
  9010. // IE <= 7 doesn't support accessing string characters using square
  9011. // bracket notation. IE 8 only supports this for primitives.
  9012. isSupported = "a"[0] != "a";
  9013. } else if (name == "json") {
  9014. // Indicates whether both `JSON.stringify` and `JSON.parse` are
  9015. // supported.
  9016. isSupported = has("json-stringify") && has("json-parse");
  9017. } else {
  9018. var value, serialized = '{"a":[1,true,false,null,"\\u0000\\b\\n\\f\\r\\t"]}';
  9019. // Test `JSON.stringify`.
  9020. if (name == "json-stringify") {
  9021. var stringify = exports.stringify, stringifySupported = typeof stringify == "function" && isExtended;
  9022. if (stringifySupported) {
  9023. // A test function object with a custom `toJSON` method.
  9024. (value = function () {
  9025. return 1;
  9026. }).toJSON = value;
  9027. try {
  9028. stringifySupported =
  9029. // Firefox 3.1b1 and b2 serialize string, number, and boolean
  9030. // primitives as object literals.
  9031. stringify(0) === "0" &&
  9032. // FF 3.1b1, b2, and JSON 2 serialize wrapped primitives as object
  9033. // literals.
  9034. stringify(new Number()) === "0" &&
  9035. stringify(new String()) == '""' &&
  9036. // FF 3.1b1, 2 throw an error if the value is `null`, `undefined`, or
  9037. // does not define a canonical JSON representation (this applies to
  9038. // objects with `toJSON` properties as well, *unless* they are nested
  9039. // within an object or array).
  9040. stringify(getClass) === undef &&
  9041. // IE 8 serializes `undefined` as `"undefined"`. Safari <= 5.1.7 and
  9042. // FF 3.1b3 pass this test.
  9043. stringify(undef) === undef &&
  9044. // Safari <= 5.1.7 and FF 3.1b3 throw `Error`s and `TypeError`s,
  9045. // respectively, if the value is omitted entirely.
  9046. stringify() === undef &&
  9047. // FF 3.1b1, 2 throw an error if the given value is not a number,
  9048. // string, array, object, Boolean, or `null` literal. This applies to
  9049. // objects with custom `toJSON` methods as well, unless they are nested
  9050. // inside object or array literals. YUI 3.0.0b1 ignores custom `toJSON`
  9051. // methods entirely.
  9052. stringify(value) === "1" &&
  9053. stringify([value]) == "[1]" &&
  9054. // Prototype <= 1.6.1 serializes `[undefined]` as `"[]"` instead of
  9055. // `"[null]"`.
  9056. stringify([undef]) == "[null]" &&
  9057. // YUI 3.0.0b1 fails to serialize `null` literals.
  9058. stringify(null) == "null" &&
  9059. // FF 3.1b1, 2 halts serialization if an array contains a function:
  9060. // `[1, true, getClass, 1]` serializes as "[1,true,],". FF 3.1b3
  9061. // elides non-JSON values from objects and arrays, unless they
  9062. // define custom `toJSON` methods.
  9063. stringify([undef, getClass, null]) == "[null,null,null]" &&
  9064. // Simple serialization test. FF 3.1b1 uses Unicode escape sequences
  9065. // where character escape codes are expected (e.g., `\b` => `\u0008`).
  9066. stringify({ "a": [value, true, false, null, "\x00\b\n\f\r\t"] }) == serialized &&
  9067. // FF 3.1b1 and b2 ignore the `filter` and `width` arguments.
  9068. stringify(null, value) === "1" &&
  9069. stringify([1, 2], null, 1) == "[\n 1,\n 2\n]" &&
  9070. // JSON 2, Prototype <= 1.7, and older WebKit builds incorrectly
  9071. // serialize extended years.
  9072. stringify(new Date(-8.64e15)) == '"-271821-04-20T00:00:00.000Z"' &&
  9073. // The milliseconds are optional in ES 5, but required in 5.1.
  9074. stringify(new Date(8.64e15)) == '"+275760-09-13T00:00:00.000Z"' &&
  9075. // Firefox <= 11.0 incorrectly serializes years prior to 0 as negative
  9076. // four-digit years instead of six-digit years. Credits: @Yaffle.
  9077. stringify(new Date(-621987552e5)) == '"-000001-01-01T00:00:00.000Z"' &&
  9078. // Safari <= 5.1.5 and Opera >= 10.53 incorrectly serialize millisecond
  9079. // values less than 1000. Credits: @Yaffle.
  9080. stringify(new Date(-1)) == '"1969-12-31T23:59:59.999Z"';
  9081. } catch (exception) {
  9082. stringifySupported = false;
  9083. }
  9084. }
  9085. isSupported = stringifySupported;
  9086. }
  9087. // Test `JSON.parse`.
  9088. if (name == "json-parse") {
  9089. var parse = exports.parse;
  9090. if (typeof parse == "function") {
  9091. try {
  9092. // FF 3.1b1, b2 will throw an exception if a bare literal is provided.
  9093. // Conforming implementations should also coerce the initial argument to
  9094. // a string prior to parsing.
  9095. if (parse("0") === 0 && !parse(false)) {
  9096. // Simple parsing test.
  9097. value = parse(serialized);
  9098. var parseSupported = value["a"].length == 5 && value["a"][0] === 1;
  9099. if (parseSupported) {
  9100. try {
  9101. // Safari <= 5.1.2 and FF 3.1b1 allow unescaped tabs in strings.
  9102. parseSupported = !parse('"\t"');
  9103. } catch (exception) {}
  9104. if (parseSupported) {
  9105. try {
  9106. // FF 4.0 and 4.0.1 allow leading `+` signs and leading
  9107. // decimal points. FF 4.0, 4.0.1, and IE 9-10 also allow
  9108. // certain octal literals.
  9109. parseSupported = parse("01") !== 1;
  9110. } catch (exception) {}
  9111. }
  9112. if (parseSupported) {
  9113. try {
  9114. // FF 4.0, 4.0.1, and Rhino 1.7R3-R4 allow trailing decimal
  9115. // points. These environments, along with FF 3.1b1 and 2,
  9116. // also allow trailing commas in JSON objects and arrays.
  9117. parseSupported = parse("1.") !== 1;
  9118. } catch (exception) {}
  9119. }
  9120. }
  9121. }
  9122. } catch (exception) {
  9123. parseSupported = false;
  9124. }
  9125. }
  9126. isSupported = parseSupported;
  9127. }
  9128. }
  9129. return has[name] = !!isSupported;
  9130. }
  9131. if (!has("json")) {
  9132. // Common `[[Class]]` name aliases.
  9133. var functionClass = "[object Function]",
  9134. dateClass = "[object Date]",
  9135. numberClass = "[object Number]",
  9136. stringClass = "[object String]",
  9137. arrayClass = "[object Array]",
  9138. booleanClass = "[object Boolean]";
  9139. // Detect incomplete support for accessing string characters by index.
  9140. var charIndexBuggy = has("bug-string-char-index");
  9141. // Define additional utility methods if the `Date` methods are buggy.
  9142. if (!isExtended) {
  9143. var floor = Math.floor;
  9144. // A mapping between the months of the year and the number of days between
  9145. // January 1st and the first of the respective month.
  9146. var Months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
  9147. // Internal: Calculates the number of days between the Unix epoch and the
  9148. // first day of the given month.
  9149. var getDay = function (year, month) {
  9150. return Months[month] + 365 * (year - 1970) + floor((year - 1969 + (month = +(month > 1))) / 4) - floor((year - 1901 + month) / 100) + floor((year - 1601 + month) / 400);
  9151. };
  9152. }
  9153. // Internal: Determines if a property is a direct property of the given
  9154. // object. Delegates to the native `Object#hasOwnProperty` method.
  9155. if (!(isProperty = objectProto.hasOwnProperty)) {
  9156. isProperty = function (property) {
  9157. var members = {}, constructor;
  9158. if ((members.__proto__ = null, members.__proto__ = {
  9159. // The *proto* property cannot be set multiple times in recent
  9160. // versions of Firefox and SeaMonkey.
  9161. "toString": 1
  9162. }, members).toString != getClass) {
  9163. // Safari <= 2.0.3 doesn't implement `Object#hasOwnProperty`, but
  9164. // supports the mutable *proto* property.
  9165. isProperty = function (property) {
  9166. // Capture and break the object's prototype chain (see section 8.6.2
  9167. // of the ES 5.1 spec). The parenthesized expression prevents an
  9168. // unsafe transformation by the Closure Compiler.
  9169. var original = this.__proto__, result = property in (this.__proto__ = null, this);
  9170. // Restore the original prototype chain.
  9171. this.__proto__ = original;
  9172. return result;
  9173. };
  9174. } else {
  9175. // Capture a reference to the top-level `Object` constructor.
  9176. constructor = members.constructor;
  9177. // Use the `constructor` property to simulate `Object#hasOwnProperty` in
  9178. // other environments.
  9179. isProperty = function (property) {
  9180. var parent = (this.constructor || constructor).prototype;
  9181. return property in this && !(property in parent && this[property] === parent[property]);
  9182. };
  9183. }
  9184. members = null;
  9185. return isProperty.call(this, property);
  9186. };
  9187. }
  9188. // Internal: Normalizes the `for...in` iteration algorithm across
  9189. // environments. Each enumerated key is yielded to a `callback` function.
  9190. forEach = function (object, callback) {
  9191. var size = 0, Properties, members, property;
  9192. // Tests for bugs in the current environment's `for...in` algorithm. The
  9193. // `valueOf` property inherits the non-enumerable flag from
  9194. // `Object.prototype` in older versions of IE, Netscape, and Mozilla.
  9195. (Properties = function () {
  9196. this.valueOf = 0;
  9197. }).prototype.valueOf = 0;
  9198. // Iterate over a new instance of the `Properties` class.
  9199. members = new Properties();
  9200. for (property in members) {
  9201. // Ignore all properties inherited from `Object.prototype`.
  9202. if (isProperty.call(members, property)) {
  9203. size++;
  9204. }
  9205. }
  9206. Properties = members = null;
  9207. // Normalize the iteration algorithm.
  9208. if (!size) {
  9209. // A list of non-enumerable properties inherited from `Object.prototype`.
  9210. members = ["valueOf", "toString", "toLocaleString", "propertyIsEnumerable", "isPrototypeOf", "hasOwnProperty", "constructor"];
  9211. // IE <= 8, Mozilla 1.0, and Netscape 6.2 ignore shadowed non-enumerable
  9212. // properties.
  9213. forEach = function (object, callback) {
  9214. var isFunction = getClass.call(object) == functionClass, property, length;
  9215. var hasProperty = !isFunction && typeof object.constructor != "function" && objectTypes[typeof object.hasOwnProperty] && object.hasOwnProperty || isProperty;
  9216. for (property in object) {
  9217. // Gecko <= 1.0 enumerates the `prototype` property of functions under
  9218. // certain conditions; IE does not.
  9219. if (!(isFunction && property == "prototype") && hasProperty.call(object, property)) {
  9220. callback(property);
  9221. }
  9222. }
  9223. // Manually invoke the callback for each non-enumerable property.
  9224. for (length = members.length; property = members[--length]; hasProperty.call(object, property) && callback(property));
  9225. };
  9226. } else if (size == 2) {
  9227. // Safari <= 2.0.4 enumerates shadowed properties twice.
  9228. forEach = function (object, callback) {
  9229. // Create a set of iterated properties.
  9230. var members = {}, isFunction = getClass.call(object) == functionClass, property;
  9231. for (property in object) {
  9232. // Store each property name to prevent double enumeration. The
  9233. // `prototype` property of functions is not enumerated due to cross-
  9234. // environment inconsistencies.
  9235. if (!(isFunction && property == "prototype") && !isProperty.call(members, property) && (members[property] = 1) && isProperty.call(object, property)) {
  9236. callback(property);
  9237. }
  9238. }
  9239. };
  9240. } else {
  9241. // No bugs detected; use the standard `for...in` algorithm.
  9242. forEach = function (object, callback) {
  9243. var isFunction = getClass.call(object) == functionClass, property, isConstructor;
  9244. for (property in object) {
  9245. if (!(isFunction && property == "prototype") && isProperty.call(object, property) && !(isConstructor = property === "constructor")) {
  9246. callback(property);
  9247. }
  9248. }
  9249. // Manually invoke the callback for the `constructor` property due to
  9250. // cross-environment inconsistencies.
  9251. if (isConstructor || isProperty.call(object, (property = "constructor"))) {
  9252. callback(property);
  9253. }
  9254. };
  9255. }
  9256. return forEach(object, callback);
  9257. };
  9258. // Public: Serializes a JavaScript `value` as a JSON string. The optional
  9259. // `filter` argument may specify either a function that alters how object and
  9260. // array members are serialized, or an array of strings and numbers that
  9261. // indicates which properties should be serialized. The optional `width`
  9262. // argument may be either a string or number that specifies the indentation
  9263. // level of the output.
  9264. if (!has("json-stringify")) {
  9265. // Internal: A map of control characters and their escaped equivalents.
  9266. var Escapes = {
  9267. 92: "\\\\",
  9268. 34: '\\"',
  9269. 8: "\\b",
  9270. 12: "\\f",
  9271. 10: "\\n",
  9272. 13: "\\r",
  9273. 9: "\\t"
  9274. };
  9275. // Internal: Converts `value` into a zero-padded string such that its
  9276. // length is at least equal to `width`. The `width` must be <= 6.
  9277. var leadingZeroes = "000000";
  9278. var toPaddedString = function (width, value) {
  9279. // The `|| 0` expression is necessary to work around a bug in
  9280. // Opera <= 7.54u2 where `0 == -0`, but `String(-0) !== "0"`.
  9281. return (leadingZeroes + (value || 0)).slice(-width);
  9282. };
  9283. // Internal: Double-quotes a string `value`, replacing all ASCII control
  9284. // characters (characters with code unit values between 0 and 31) with
  9285. // their escaped equivalents. This is an implementation of the
  9286. // `Quote(value)` operation defined in ES 5.1 section 15.12.3.
  9287. var unicodePrefix = "\\u00";
  9288. var quote = function (value) {
  9289. var result = '"', index = 0, length = value.length, useCharIndex = !charIndexBuggy || length > 10;
  9290. var symbols = useCharIndex && (charIndexBuggy ? value.split("") : value);
  9291. for (; index < length; index++) {
  9292. var charCode = value.charCodeAt(index);
  9293. // If the character is a control character, append its Unicode or
  9294. // shorthand escape sequence; otherwise, append the character as-is.
  9295. switch (charCode) {
  9296. case 8: case 9: case 10: case 12: case 13: case 34: case 92:
  9297. result += Escapes[charCode];
  9298. break;
  9299. default:
  9300. if (charCode < 32) {
  9301. result += unicodePrefix + toPaddedString(2, charCode.toString(16));
  9302. break;
  9303. }
  9304. result += useCharIndex ? symbols[index] : value.charAt(index);
  9305. }
  9306. }
  9307. return result + '"';
  9308. };
  9309. // Internal: Recursively serializes an object. Implements the
  9310. // `Str(key, holder)`, `JO(value)`, and `JA(value)` operations.
  9311. var serialize = function (property, object, callback, properties, whitespace, indentation, stack) {
  9312. var value, className, year, month, date, time, hours, minutes, seconds, milliseconds, results, element, index, length, prefix, result;
  9313. try {
  9314. // Necessary for host object support.
  9315. value = object[property];
  9316. } catch (exception) {}
  9317. if (typeof value == "object" && value) {
  9318. className = getClass.call(value);
  9319. if (className == dateClass && !isProperty.call(value, "toJSON")) {
  9320. if (value > -1 / 0 && value < 1 / 0) {
  9321. // Dates are serialized according to the `Date#toJSON` method
  9322. // specified in ES 5.1 section 15.9.5.44. See section 15.9.1.15
  9323. // for the ISO 8601 date time string format.
  9324. if (getDay) {
  9325. // Manually compute the year, month, date, hours, minutes,
  9326. // seconds, and milliseconds if the `getUTC*` methods are
  9327. // buggy. Adapted from @Yaffle's `date-shim` project.
  9328. date = floor(value / 864e5);
  9329. for (year = floor(date / 365.2425) + 1970 - 1; getDay(year + 1, 0) <= date; year++);
  9330. for (month = floor((date - getDay(year, 0)) / 30.42); getDay(year, month + 1) <= date; month++);
  9331. date = 1 + date - getDay(year, month);
  9332. // The `time` value specifies the time within the day (see ES
  9333. // 5.1 section 15.9.1.2). The formula `(A % B + B) % B` is used
  9334. // to compute `A modulo B`, as the `%` operator does not
  9335. // correspond to the `modulo` operation for negative numbers.
  9336. time = (value % 864e5 + 864e5) % 864e5;
  9337. // The hours, minutes, seconds, and milliseconds are obtained by
  9338. // decomposing the time within the day. See section 15.9.1.10.
  9339. hours = floor(time / 36e5) % 24;
  9340. minutes = floor(time / 6e4) % 60;
  9341. seconds = floor(time / 1e3) % 60;
  9342. milliseconds = time % 1e3;
  9343. } else {
  9344. year = value.getUTCFullYear();
  9345. month = value.getUTCMonth();
  9346. date = value.getUTCDate();
  9347. hours = value.getUTCHours();
  9348. minutes = value.getUTCMinutes();
  9349. seconds = value.getUTCSeconds();
  9350. milliseconds = value.getUTCMilliseconds();
  9351. }
  9352. // Serialize extended years correctly.
  9353. value = (year <= 0 || year >= 1e4 ? (year < 0 ? "-" : "+") + toPaddedString(6, year < 0 ? -year : year) : toPaddedString(4, year)) +
  9354. "-" + toPaddedString(2, month + 1) + "-" + toPaddedString(2, date) +
  9355. // Months, dates, hours, minutes, and seconds should have two
  9356. // digits; milliseconds should have three.
  9357. "T" + toPaddedString(2, hours) + ":" + toPaddedString(2, minutes) + ":" + toPaddedString(2, seconds) +
  9358. // Milliseconds are optional in ES 5.0, but required in 5.1.
  9359. "." + toPaddedString(3, milliseconds) + "Z";
  9360. } else {
  9361. value = null;
  9362. }
  9363. } else if (typeof value.toJSON == "function" && ((className != numberClass && className != stringClass && className != arrayClass) || isProperty.call(value, "toJSON"))) {
  9364. // Prototype <= 1.6.1 adds non-standard `toJSON` methods to the
  9365. // `Number`, `String`, `Date`, and `Array` prototypes. JSON 3
  9366. // ignores all `toJSON` methods on these objects unless they are
  9367. // defined directly on an instance.
  9368. value = value.toJSON(property);
  9369. }
  9370. }
  9371. if (callback) {
  9372. // If a replacement function was provided, call it to obtain the value
  9373. // for serialization.
  9374. value = callback.call(object, property, value);
  9375. }
  9376. if (value === null) {
  9377. return "null";
  9378. }
  9379. className = getClass.call(value);
  9380. if (className == booleanClass) {
  9381. // Booleans are represented literally.
  9382. return "" + value;
  9383. } else if (className == numberClass) {
  9384. // JSON numbers must be finite. `Infinity` and `NaN` are serialized as
  9385. // `"null"`.
  9386. return value > -1 / 0 && value < 1 / 0 ? "" + value : "null";
  9387. } else if (className == stringClass) {
  9388. // Strings are double-quoted and escaped.
  9389. return quote("" + value);
  9390. }
  9391. // Recursively serialize objects and arrays.
  9392. if (typeof value == "object") {
  9393. // Check for cyclic structures. This is a linear search; performance
  9394. // is inversely proportional to the number of unique nested objects.
  9395. for (length = stack.length; length--;) {
  9396. if (stack[length] === value) {
  9397. // Cyclic structures cannot be serialized by `JSON.stringify`.
  9398. throw TypeError();
  9399. }
  9400. }
  9401. // Add the object to the stack of traversed objects.
  9402. stack.push(value);
  9403. results = [];
  9404. // Save the current indentation level and indent one additional level.
  9405. prefix = indentation;
  9406. indentation += whitespace;
  9407. if (className == arrayClass) {
  9408. // Recursively serialize array elements.
  9409. for (index = 0, length = value.length; index < length; index++) {
  9410. element = serialize(index, value, callback, properties, whitespace, indentation, stack);
  9411. results.push(element === undef ? "null" : element);
  9412. }
  9413. result = results.length ? (whitespace ? "[\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "]" : ("[" + results.join(",") + "]")) : "[]";
  9414. } else {
  9415. // Recursively serialize object members. Members are selected from
  9416. // either a user-specified list of property names, or the object
  9417. // itself.
  9418. forEach(properties || value, function (property) {
  9419. var element = serialize(property, value, callback, properties, whitespace, indentation, stack);
  9420. if (element !== undef) {
  9421. // According to ES 5.1 section 15.12.3: "If `gap` {whitespace}
  9422. // is not the empty string, let `member` {quote(property) + ":"}
  9423. // be the concatenation of `member` and the `space` character."
  9424. // The "`space` character" refers to the literal space
  9425. // character, not the `space` {width} argument provided to
  9426. // `JSON.stringify`.
  9427. results.push(quote(property) + ":" + (whitespace ? " " : "") + element);
  9428. }
  9429. });
  9430. result = results.length ? (whitespace ? "{\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "}" : ("{" + results.join(",") + "}")) : "{}";
  9431. }
  9432. // Remove the object from the traversed object stack.
  9433. stack.pop();
  9434. return result;
  9435. }
  9436. };
  9437. // Public: `JSON.stringify`. See ES 5.1 section 15.12.3.
  9438. exports.stringify = function (source, filter, width) {
  9439. var whitespace, callback, properties, className;
  9440. if (objectTypes[typeof filter] && filter) {
  9441. if ((className = getClass.call(filter)) == functionClass) {
  9442. callback = filter;
  9443. } else if (className == arrayClass) {
  9444. // Convert the property names array into a makeshift set.
  9445. properties = {};
  9446. for (var index = 0, length = filter.length, value; index < length; value = filter[index++], ((className = getClass.call(value)), className == stringClass || className == numberClass) && (properties[value] = 1));
  9447. }
  9448. }
  9449. if (width) {
  9450. if ((className = getClass.call(width)) == numberClass) {
  9451. // Convert the `width` to an integer and create a string containing
  9452. // `width` number of space characters.
  9453. if ((width -= width % 1) > 0) {
  9454. for (whitespace = "", width > 10 && (width = 10); whitespace.length < width; whitespace += " ");
  9455. }
  9456. } else if (className == stringClass) {
  9457. whitespace = width.length <= 10 ? width : width.slice(0, 10);
  9458. }
  9459. }
  9460. // Opera <= 7.54u2 discards the values associated with empty string keys
  9461. // (`""`) only if they are used directly within an object member list
  9462. // (e.g., `!("" in { "": 1})`).
  9463. return serialize("", (value = {}, value[""] = source, value), callback, properties, whitespace, "", []);
  9464. };
  9465. }
  9466. // Public: Parses a JSON source string.
  9467. if (!has("json-parse")) {
  9468. var fromCharCode = String.fromCharCode;
  9469. // Internal: A map of escaped control characters and their unescaped
  9470. // equivalents.
  9471. var Unescapes = {
  9472. 92: "\\",
  9473. 34: '"',
  9474. 47: "/",
  9475. 98: "\b",
  9476. 116: "\t",
  9477. 110: "\n",
  9478. 102: "\f",
  9479. 114: "\r"
  9480. };
  9481. // Internal: Stores the parser state.
  9482. var Index, Source;
  9483. // Internal: Resets the parser state and throws a `SyntaxError`.
  9484. var abort = function () {
  9485. Index = Source = null;
  9486. throw SyntaxError();
  9487. };
  9488. // Internal: Returns the next token, or `"$"` if the parser has reached
  9489. // the end of the source string. A token may be a string, number, `null`
  9490. // literal, or Boolean literal.
  9491. var lex = function () {
  9492. var source = Source, length = source.length, value, begin, position, isSigned, charCode;
  9493. while (Index < length) {
  9494. charCode = source.charCodeAt(Index);
  9495. switch (charCode) {
  9496. case 9: case 10: case 13: case 32:
  9497. // Skip whitespace tokens, including tabs, carriage returns, line
  9498. // feeds, and space characters.
  9499. Index++;
  9500. break;
  9501. case 123: case 125: case 91: case 93: case 58: case 44:
  9502. // Parse a punctuator token (`{`, `}`, `[`, `]`, `:`, or `,`) at
  9503. // the current position.
  9504. value = charIndexBuggy ? source.charAt(Index) : source[Index];
  9505. Index++;
  9506. return value;
  9507. case 34:
  9508. // `"` delimits a JSON string; advance to the next character and
  9509. // begin parsing the string. String tokens are prefixed with the
  9510. // sentinel `@` character to distinguish them from punctuators and
  9511. // end-of-string tokens.
  9512. for (value = "@", Index++; Index < length;) {
  9513. charCode = source.charCodeAt(Index);
  9514. if (charCode < 32) {
  9515. // Unescaped ASCII control characters (those with a code unit
  9516. // less than the space character) are not permitted.
  9517. abort();
  9518. } else if (charCode == 92) {
  9519. // A reverse solidus (`\`) marks the beginning of an escaped
  9520. // control character (including `"`, `\`, and `/`) or Unicode
  9521. // escape sequence.
  9522. charCode = source.charCodeAt(++Index);
  9523. switch (charCode) {
  9524. case 92: case 34: case 47: case 98: case 116: case 110: case 102: case 114:
  9525. // Revive escaped control characters.
  9526. value += Unescapes[charCode];
  9527. Index++;
  9528. break;
  9529. case 117:
  9530. // `\u` marks the beginning of a Unicode escape sequence.
  9531. // Advance to the first character and validate the
  9532. // four-digit code point.
  9533. begin = ++Index;
  9534. for (position = Index + 4; Index < position; Index++) {
  9535. charCode = source.charCodeAt(Index);
  9536. // A valid sequence comprises four hexdigits (case-
  9537. // insensitive) that form a single hexadecimal value.
  9538. if (!(charCode >= 48 && charCode <= 57 || charCode >= 97 && charCode <= 102 || charCode >= 65 && charCode <= 70)) {
  9539. // Invalid Unicode escape sequence.
  9540. abort();
  9541. }
  9542. }
  9543. // Revive the escaped character.
  9544. value += fromCharCode("0x" + source.slice(begin, Index));
  9545. break;
  9546. default:
  9547. // Invalid escape sequence.
  9548. abort();
  9549. }
  9550. } else {
  9551. if (charCode == 34) {
  9552. // An unescaped double-quote character marks the end of the
  9553. // string.
  9554. break;
  9555. }
  9556. charCode = source.charCodeAt(Index);
  9557. begin = Index;
  9558. // Optimize for the common case where a string is valid.
  9559. while (charCode >= 32 && charCode != 92 && charCode != 34) {
  9560. charCode = source.charCodeAt(++Index);
  9561. }
  9562. // Append the string as-is.
  9563. value += source.slice(begin, Index);
  9564. }
  9565. }
  9566. if (source.charCodeAt(Index) == 34) {
  9567. // Advance to the next character and return the revived string.
  9568. Index++;
  9569. return value;
  9570. }
  9571. // Unterminated string.
  9572. abort();
  9573. default:
  9574. // Parse numbers and literals.
  9575. begin = Index;
  9576. // Advance past the negative sign, if one is specified.
  9577. if (charCode == 45) {
  9578. isSigned = true;
  9579. charCode = source.charCodeAt(++Index);
  9580. }
  9581. // Parse an integer or floating-point value.
  9582. if (charCode >= 48 && charCode <= 57) {
  9583. // Leading zeroes are interpreted as octal literals.
  9584. if (charCode == 48 && ((charCode = source.charCodeAt(Index + 1)), charCode >= 48 && charCode <= 57)) {
  9585. // Illegal octal literal.
  9586. abort();
  9587. }
  9588. isSigned = false;
  9589. // Parse the integer component.
  9590. for (; Index < length && ((charCode = source.charCodeAt(Index)), charCode >= 48 && charCode <= 57); Index++);
  9591. // Floats cannot contain a leading decimal point; however, this
  9592. // case is already accounted for by the parser.
  9593. if (source.charCodeAt(Index) == 46) {
  9594. position = ++Index;
  9595. // Parse the decimal component.
  9596. for (; position < length && ((charCode = source.charCodeAt(position)), charCode >= 48 && charCode <= 57); position++);
  9597. if (position == Index) {
  9598. // Illegal trailing decimal.
  9599. abort();
  9600. }
  9601. Index = position;
  9602. }
  9603. // Parse exponents. The `e` denoting the exponent is
  9604. // case-insensitive.
  9605. charCode = source.charCodeAt(Index);
  9606. if (charCode == 101 || charCode == 69) {
  9607. charCode = source.charCodeAt(++Index);
  9608. // Skip past the sign following the exponent, if one is
  9609. // specified.
  9610. if (charCode == 43 || charCode == 45) {
  9611. Index++;
  9612. }
  9613. // Parse the exponential component.
  9614. for (position = Index; position < length && ((charCode = source.charCodeAt(position)), charCode >= 48 && charCode <= 57); position++);
  9615. if (position == Index) {
  9616. // Illegal empty exponent.
  9617. abort();
  9618. }
  9619. Index = position;
  9620. }
  9621. // Coerce the parsed value to a JavaScript number.
  9622. return +source.slice(begin, Index);
  9623. }
  9624. // A negative sign may only precede numbers.
  9625. if (isSigned) {
  9626. abort();
  9627. }
  9628. // `true`, `false`, and `null` literals.
  9629. if (source.slice(Index, Index + 4) == "true") {
  9630. Index += 4;
  9631. return true;
  9632. } else if (source.slice(Index, Index + 5) == "false") {
  9633. Index += 5;
  9634. return false;
  9635. } else if (source.slice(Index, Index + 4) == "null") {
  9636. Index += 4;
  9637. return null;
  9638. }
  9639. // Unrecognized token.
  9640. abort();
  9641. }
  9642. }
  9643. // Return the sentinel `$` character if the parser has reached the end
  9644. // of the source string.
  9645. return "$";
  9646. };
  9647. // Internal: Parses a JSON `value` token.
  9648. var get = function (value) {
  9649. var results, hasMembers;
  9650. if (value == "$") {
  9651. // Unexpected end of input.
  9652. abort();
  9653. }
  9654. if (typeof value == "string") {
  9655. if ((charIndexBuggy ? value.charAt(0) : value[0]) == "@") {
  9656. // Remove the sentinel `@` character.
  9657. return value.slice(1);
  9658. }
  9659. // Parse object and array literals.
  9660. if (value == "[") {
  9661. // Parses a JSON array, returning a new JavaScript array.
  9662. results = [];
  9663. for (;; hasMembers || (hasMembers = true)) {
  9664. value = lex();
  9665. // A closing square bracket marks the end of the array literal.
  9666. if (value == "]") {
  9667. break;
  9668. }
  9669. // If the array literal contains elements, the current token
  9670. // should be a comma separating the previous element from the
  9671. // next.
  9672. if (hasMembers) {
  9673. if (value == ",") {
  9674. value = lex();
  9675. if (value == "]") {
  9676. // Unexpected trailing `,` in array literal.
  9677. abort();
  9678. }
  9679. } else {
  9680. // A `,` must separate each array element.
  9681. abort();
  9682. }
  9683. }
  9684. // Elisions and leading commas are not permitted.
  9685. if (value == ",") {
  9686. abort();
  9687. }
  9688. results.push(get(value));
  9689. }
  9690. return results;
  9691. } else if (value == "{") {
  9692. // Parses a JSON object, returning a new JavaScript object.
  9693. results = {};
  9694. for (;; hasMembers || (hasMembers = true)) {
  9695. value = lex();
  9696. // A closing curly brace marks the end of the object literal.
  9697. if (value == "}") {
  9698. break;
  9699. }
  9700. // If the object literal contains members, the current token
  9701. // should be a comma separator.
  9702. if (hasMembers) {
  9703. if (value == ",") {
  9704. value = lex();
  9705. if (value == "}") {
  9706. // Unexpected trailing `,` in object literal.
  9707. abort();
  9708. }
  9709. } else {
  9710. // A `,` must separate each object member.
  9711. abort();
  9712. }
  9713. }
  9714. // Leading commas are not permitted, object property names must be
  9715. // double-quoted strings, and a `:` must separate each property
  9716. // name and value.
  9717. if (value == "," || typeof value != "string" || (charIndexBuggy ? value.charAt(0) : value[0]) != "@" || lex() != ":") {
  9718. abort();
  9719. }
  9720. results[value.slice(1)] = get(lex());
  9721. }
  9722. return results;
  9723. }
  9724. // Unexpected token encountered.
  9725. abort();
  9726. }
  9727. return value;
  9728. };
  9729. // Internal: Updates a traversed object member.
  9730. var update = function (source, property, callback) {
  9731. var element = walk(source, property, callback);
  9732. if (element === undef) {
  9733. delete source[property];
  9734. } else {
  9735. source[property] = element;
  9736. }
  9737. };
  9738. // Internal: Recursively traverses a parsed JSON object, invoking the
  9739. // `callback` function for each value. This is an implementation of the
  9740. // `Walk(holder, name)` operation defined in ES 5.1 section 15.12.2.
  9741. var walk = function (source, property, callback) {
  9742. var value = source[property], length;
  9743. if (typeof value == "object" && value) {
  9744. // `forEach` can't be used to traverse an array in Opera <= 8.54
  9745. // because its `Object#hasOwnProperty` implementation returns `false`
  9746. // for array indices (e.g., `![1, 2, 3].hasOwnProperty("0")`).
  9747. if (getClass.call(value) == arrayClass) {
  9748. for (length = value.length; length--;) {
  9749. update(value, length, callback);
  9750. }
  9751. } else {
  9752. forEach(value, function (property) {
  9753. update(value, property, callback);
  9754. });
  9755. }
  9756. }
  9757. return callback.call(source, property, value);
  9758. };
  9759. // Public: `JSON.parse`. See ES 5.1 section 15.12.2.
  9760. exports.parse = function (source, callback) {
  9761. var result, value;
  9762. Index = 0;
  9763. Source = "" + source;
  9764. result = get(lex());
  9765. // If a JSON string contains multiple tokens, it is invalid.
  9766. if (lex() != "$") {
  9767. abort();
  9768. }
  9769. // Reset the parser state.
  9770. Index = Source = null;
  9771. return callback && getClass.call(callback) == functionClass ? walk((value = {}, value[""] = result, value), "", callback) : result;
  9772. };
  9773. }
  9774. }
  9775. exports["runInContext"] = runInContext;
  9776. return exports;
  9777. }
  9778. if (freeExports && !isLoader) {
  9779. // Export for CommonJS environments.
  9780. runInContext(root, freeExports);
  9781. } else {
  9782. // Export for web browsers and JavaScript engines.
  9783. var nativeJSON = root.JSON,
  9784. previousJSON = root["JSON3"],
  9785. isRestored = false;
  9786. var JSON3 = runInContext(root, (root["JSON3"] = {
  9787. // Public: Restores the original value of the global `JSON` object and
  9788. // returns a reference to the `JSON3` object.
  9789. "noConflict": function () {
  9790. if (!isRestored) {
  9791. isRestored = true;
  9792. root.JSON = nativeJSON;
  9793. root["JSON3"] = previousJSON;
  9794. nativeJSON = previousJSON = null;
  9795. }
  9796. return JSON3;
  9797. }
  9798. }));
  9799. root.JSON = {
  9800. "parse": JSON3.parse,
  9801. "stringify": JSON3.stringify
  9802. };
  9803. }
  9804. // Export for asynchronous module loaders.
  9805. if (isLoader) {
  9806. define(function () {
  9807. return JSON3;
  9808. });
  9809. }
  9810. }).call(this);
  9811. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  9812. },{}],55:[function(require,module,exports){
  9813. /**
  9814. * lodash 3.2.0 (Custom Build) <https://lodash.com/>
  9815. * Build: `lodash modern modularize exports="npm" -o ./`
  9816. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  9817. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  9818. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9819. * Available under MIT license <https://lodash.com/license>
  9820. */
  9821. var baseCopy = require('lodash._basecopy'),
  9822. keys = require('lodash.keys');
  9823. /**
  9824. * The base implementation of `_.assign` without support for argument juggling,
  9825. * multiple sources, and `customizer` functions.
  9826. *
  9827. * @private
  9828. * @param {Object} object The destination object.
  9829. * @param {Object} source The source object.
  9830. * @returns {Object} Returns `object`.
  9831. */
  9832. function baseAssign(object, source) {
  9833. return source == null
  9834. ? object
  9835. : baseCopy(source, keys(source), object);
  9836. }
  9837. module.exports = baseAssign;
  9838. },{"lodash._basecopy":56,"lodash.keys":63}],56:[function(require,module,exports){
  9839. /**
  9840. * lodash 3.0.1 (Custom Build) <https://lodash.com/>
  9841. * Build: `lodash modern modularize exports="npm" -o ./`
  9842. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  9843. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  9844. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9845. * Available under MIT license <https://lodash.com/license>
  9846. */
  9847. /**
  9848. * Copies properties of `source` to `object`.
  9849. *
  9850. * @private
  9851. * @param {Object} source The object to copy properties from.
  9852. * @param {Array} props The property names to copy.
  9853. * @param {Object} [object={}] The object to copy properties to.
  9854. * @returns {Object} Returns `object`.
  9855. */
  9856. function baseCopy(source, props, object) {
  9857. object || (object = {});
  9858. var index = -1,
  9859. length = props.length;
  9860. while (++index < length) {
  9861. var key = props[index];
  9862. object[key] = source[key];
  9863. }
  9864. return object;
  9865. }
  9866. module.exports = baseCopy;
  9867. },{}],57:[function(require,module,exports){
  9868. /**
  9869. * lodash 3.0.3 (Custom Build) <https://lodash.com/>
  9870. * Build: `lodash modern modularize exports="npm" -o ./`
  9871. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  9872. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  9873. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9874. * Available under MIT license <https://lodash.com/license>
  9875. */
  9876. /**
  9877. * The base implementation of `_.create` without support for assigning
  9878. * properties to the created object.
  9879. *
  9880. * @private
  9881. * @param {Object} prototype The object to inherit from.
  9882. * @returns {Object} Returns the new object.
  9883. */
  9884. var baseCreate = (function() {
  9885. function object() {}
  9886. return function(prototype) {
  9887. if (isObject(prototype)) {
  9888. object.prototype = prototype;
  9889. var result = new object;
  9890. object.prototype = undefined;
  9891. }
  9892. return result || {};
  9893. };
  9894. }());
  9895. /**
  9896. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  9897. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  9898. *
  9899. * @static
  9900. * @memberOf _
  9901. * @category Lang
  9902. * @param {*} value The value to check.
  9903. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  9904. * @example
  9905. *
  9906. * _.isObject({});
  9907. * // => true
  9908. *
  9909. * _.isObject([1, 2, 3]);
  9910. * // => true
  9911. *
  9912. * _.isObject(1);
  9913. * // => false
  9914. */
  9915. function isObject(value) {
  9916. // Avoid a V8 JIT bug in Chrome 19-20.
  9917. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  9918. var type = typeof value;
  9919. return !!value && (type == 'object' || type == 'function');
  9920. }
  9921. module.exports = baseCreate;
  9922. },{}],58:[function(require,module,exports){
  9923. /**
  9924. * lodash 3.9.1 (Custom Build) <https://lodash.com/>
  9925. * Build: `lodash modern modularize exports="npm" -o ./`
  9926. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  9927. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  9928. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9929. * Available under MIT license <https://lodash.com/license>
  9930. */
  9931. /** `Object#toString` result references. */
  9932. var funcTag = '[object Function]';
  9933. /** Used to detect host constructors (Safari > 5). */
  9934. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  9935. /**
  9936. * Checks if `value` is object-like.
  9937. *
  9938. * @private
  9939. * @param {*} value The value to check.
  9940. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  9941. */
  9942. function isObjectLike(value) {
  9943. return !!value && typeof value == 'object';
  9944. }
  9945. /** Used for native method references. */
  9946. var objectProto = Object.prototype;
  9947. /** Used to resolve the decompiled source of functions. */
  9948. var fnToString = Function.prototype.toString;
  9949. /** Used to check objects for own properties. */
  9950. var hasOwnProperty = objectProto.hasOwnProperty;
  9951. /**
  9952. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  9953. * of values.
  9954. */
  9955. var objToString = objectProto.toString;
  9956. /** Used to detect if a method is native. */
  9957. var reIsNative = RegExp('^' +
  9958. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  9959. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  9960. );
  9961. /**
  9962. * Gets the native function at `key` of `object`.
  9963. *
  9964. * @private
  9965. * @param {Object} object The object to query.
  9966. * @param {string} key The key of the method to get.
  9967. * @returns {*} Returns the function if it's native, else `undefined`.
  9968. */
  9969. function getNative(object, key) {
  9970. var value = object == null ? undefined : object[key];
  9971. return isNative(value) ? value : undefined;
  9972. }
  9973. /**
  9974. * Checks if `value` is classified as a `Function` object.
  9975. *
  9976. * @static
  9977. * @memberOf _
  9978. * @category Lang
  9979. * @param {*} value The value to check.
  9980. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  9981. * @example
  9982. *
  9983. * _.isFunction(_);
  9984. * // => true
  9985. *
  9986. * _.isFunction(/abc/);
  9987. * // => false
  9988. */
  9989. function isFunction(value) {
  9990. // The use of `Object#toString` avoids issues with the `typeof` operator
  9991. // in older versions of Chrome and Safari which return 'function' for regexes
  9992. // and Safari 8 equivalents which return 'object' for typed array constructors.
  9993. return isObject(value) && objToString.call(value) == funcTag;
  9994. }
  9995. /**
  9996. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  9997. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  9998. *
  9999. * @static
  10000. * @memberOf _
  10001. * @category Lang
  10002. * @param {*} value The value to check.
  10003. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10004. * @example
  10005. *
  10006. * _.isObject({});
  10007. * // => true
  10008. *
  10009. * _.isObject([1, 2, 3]);
  10010. * // => true
  10011. *
  10012. * _.isObject(1);
  10013. * // => false
  10014. */
  10015. function isObject(value) {
  10016. // Avoid a V8 JIT bug in Chrome 19-20.
  10017. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  10018. var type = typeof value;
  10019. return !!value && (type == 'object' || type == 'function');
  10020. }
  10021. /**
  10022. * Checks if `value` is a native function.
  10023. *
  10024. * @static
  10025. * @memberOf _
  10026. * @category Lang
  10027. * @param {*} value The value to check.
  10028. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  10029. * @example
  10030. *
  10031. * _.isNative(Array.prototype.push);
  10032. * // => true
  10033. *
  10034. * _.isNative(_);
  10035. * // => false
  10036. */
  10037. function isNative(value) {
  10038. if (value == null) {
  10039. return false;
  10040. }
  10041. if (isFunction(value)) {
  10042. return reIsNative.test(fnToString.call(value));
  10043. }
  10044. return isObjectLike(value) && reIsHostCtor.test(value);
  10045. }
  10046. module.exports = getNative;
  10047. },{}],59:[function(require,module,exports){
  10048. /**
  10049. * lodash 3.0.9 (Custom Build) <https://lodash.com/>
  10050. * Build: `lodash modern modularize exports="npm" -o ./`
  10051. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10052. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10053. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10054. * Available under MIT license <https://lodash.com/license>
  10055. */
  10056. /** Used to detect unsigned integer values. */
  10057. var reIsUint = /^\d+$/;
  10058. /**
  10059. * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
  10060. * of an array-like value.
  10061. */
  10062. var MAX_SAFE_INTEGER = 9007199254740991;
  10063. /**
  10064. * The base implementation of `_.property` without support for deep paths.
  10065. *
  10066. * @private
  10067. * @param {string} key The key of the property to get.
  10068. * @returns {Function} Returns the new function.
  10069. */
  10070. function baseProperty(key) {
  10071. return function(object) {
  10072. return object == null ? undefined : object[key];
  10073. };
  10074. }
  10075. /**
  10076. * Gets the "length" property value of `object`.
  10077. *
  10078. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  10079. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  10080. *
  10081. * @private
  10082. * @param {Object} object The object to query.
  10083. * @returns {*} Returns the "length" value.
  10084. */
  10085. var getLength = baseProperty('length');
  10086. /**
  10087. * Checks if `value` is array-like.
  10088. *
  10089. * @private
  10090. * @param {*} value The value to check.
  10091. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10092. */
  10093. function isArrayLike(value) {
  10094. return value != null && isLength(getLength(value));
  10095. }
  10096. /**
  10097. * Checks if `value` is a valid array-like index.
  10098. *
  10099. * @private
  10100. * @param {*} value The value to check.
  10101. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  10102. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  10103. */
  10104. function isIndex(value, length) {
  10105. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  10106. length = length == null ? MAX_SAFE_INTEGER : length;
  10107. return value > -1 && value % 1 == 0 && value < length;
  10108. }
  10109. /**
  10110. * Checks if the provided arguments are from an iteratee call.
  10111. *
  10112. * @private
  10113. * @param {*} value The potential iteratee value argument.
  10114. * @param {*} index The potential iteratee index or key argument.
  10115. * @param {*} object The potential iteratee object argument.
  10116. * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
  10117. */
  10118. function isIterateeCall(value, index, object) {
  10119. if (!isObject(object)) {
  10120. return false;
  10121. }
  10122. var type = typeof index;
  10123. if (type == 'number'
  10124. ? (isArrayLike(object) && isIndex(index, object.length))
  10125. : (type == 'string' && index in object)) {
  10126. var other = object[index];
  10127. return value === value ? (value === other) : (other !== other);
  10128. }
  10129. return false;
  10130. }
  10131. /**
  10132. * Checks if `value` is a valid array-like length.
  10133. *
  10134. * **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
  10135. *
  10136. * @private
  10137. * @param {*} value The value to check.
  10138. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10139. */
  10140. function isLength(value) {
  10141. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10142. }
  10143. /**
  10144. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  10145. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10146. *
  10147. * @static
  10148. * @memberOf _
  10149. * @category Lang
  10150. * @param {*} value The value to check.
  10151. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10152. * @example
  10153. *
  10154. * _.isObject({});
  10155. * // => true
  10156. *
  10157. * _.isObject([1, 2, 3]);
  10158. * // => true
  10159. *
  10160. * _.isObject(1);
  10161. * // => false
  10162. */
  10163. function isObject(value) {
  10164. // Avoid a V8 JIT bug in Chrome 19-20.
  10165. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  10166. var type = typeof value;
  10167. return !!value && (type == 'object' || type == 'function');
  10168. }
  10169. module.exports = isIterateeCall;
  10170. },{}],60:[function(require,module,exports){
  10171. /**
  10172. * lodash 3.1.1 (Custom Build) <https://lodash.com/>
  10173. * Build: `lodash modern modularize exports="npm" -o ./`
  10174. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10175. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10176. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10177. * Available under MIT license <https://lodash.com/license>
  10178. */
  10179. var baseAssign = require('lodash._baseassign'),
  10180. baseCreate = require('lodash._basecreate'),
  10181. isIterateeCall = require('lodash._isiterateecall');
  10182. /**
  10183. * Creates an object that inherits from the given `prototype` object. If a
  10184. * `properties` object is provided its own enumerable properties are assigned
  10185. * to the created object.
  10186. *
  10187. * @static
  10188. * @memberOf _
  10189. * @category Object
  10190. * @param {Object} prototype The object to inherit from.
  10191. * @param {Object} [properties] The properties to assign to the object.
  10192. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10193. * @returns {Object} Returns the new object.
  10194. * @example
  10195. *
  10196. * function Shape() {
  10197. * this.x = 0;
  10198. * this.y = 0;
  10199. * }
  10200. *
  10201. * function Circle() {
  10202. * Shape.call(this);
  10203. * }
  10204. *
  10205. * Circle.prototype = _.create(Shape.prototype, {
  10206. * 'constructor': Circle
  10207. * });
  10208. *
  10209. * var circle = new Circle;
  10210. * circle instanceof Circle;
  10211. * // => true
  10212. *
  10213. * circle instanceof Shape;
  10214. * // => true
  10215. */
  10216. function create(prototype, properties, guard) {
  10217. var result = baseCreate(prototype);
  10218. if (guard && isIterateeCall(prototype, properties, guard)) {
  10219. properties = undefined;
  10220. }
  10221. return properties ? baseAssign(result, properties) : result;
  10222. }
  10223. module.exports = create;
  10224. },{"lodash._baseassign":55,"lodash._basecreate":57,"lodash._isiterateecall":59}],61:[function(require,module,exports){
  10225. /**
  10226. * lodash (Custom Build) <https://lodash.com/>
  10227. * Build: `lodash modularize exports="npm" -o ./`
  10228. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  10229. * Released under MIT license <https://lodash.com/license>
  10230. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10231. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10232. */
  10233. /** Used as references for various `Number` constants. */
  10234. var MAX_SAFE_INTEGER = 9007199254740991;
  10235. /** `Object#toString` result references. */
  10236. var argsTag = '[object Arguments]',
  10237. funcTag = '[object Function]',
  10238. genTag = '[object GeneratorFunction]';
  10239. /** Used for built-in method references. */
  10240. var objectProto = Object.prototype;
  10241. /** Used to check objects for own properties. */
  10242. var hasOwnProperty = objectProto.hasOwnProperty;
  10243. /**
  10244. * Used to resolve the
  10245. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  10246. * of values.
  10247. */
  10248. var objectToString = objectProto.toString;
  10249. /** Built-in value references. */
  10250. var propertyIsEnumerable = objectProto.propertyIsEnumerable;
  10251. /**
  10252. * Checks if `value` is likely an `arguments` object.
  10253. *
  10254. * @static
  10255. * @memberOf _
  10256. * @since 0.1.0
  10257. * @category Lang
  10258. * @param {*} value The value to check.
  10259. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10260. * else `false`.
  10261. * @example
  10262. *
  10263. * _.isArguments(function() { return arguments; }());
  10264. * // => true
  10265. *
  10266. * _.isArguments([1, 2, 3]);
  10267. * // => false
  10268. */
  10269. function isArguments(value) {
  10270. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  10271. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  10272. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  10273. }
  10274. /**
  10275. * Checks if `value` is array-like. A value is considered array-like if it's
  10276. * not a function and has a `value.length` that's an integer greater than or
  10277. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10278. *
  10279. * @static
  10280. * @memberOf _
  10281. * @since 4.0.0
  10282. * @category Lang
  10283. * @param {*} value The value to check.
  10284. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10285. * @example
  10286. *
  10287. * _.isArrayLike([1, 2, 3]);
  10288. * // => true
  10289. *
  10290. * _.isArrayLike(document.body.children);
  10291. * // => true
  10292. *
  10293. * _.isArrayLike('abc');
  10294. * // => true
  10295. *
  10296. * _.isArrayLike(_.noop);
  10297. * // => false
  10298. */
  10299. function isArrayLike(value) {
  10300. return value != null && isLength(value.length) && !isFunction(value);
  10301. }
  10302. /**
  10303. * This method is like `_.isArrayLike` except that it also checks if `value`
  10304. * is an object.
  10305. *
  10306. * @static
  10307. * @memberOf _
  10308. * @since 4.0.0
  10309. * @category Lang
  10310. * @param {*} value The value to check.
  10311. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10312. * else `false`.
  10313. * @example
  10314. *
  10315. * _.isArrayLikeObject([1, 2, 3]);
  10316. * // => true
  10317. *
  10318. * _.isArrayLikeObject(document.body.children);
  10319. * // => true
  10320. *
  10321. * _.isArrayLikeObject('abc');
  10322. * // => false
  10323. *
  10324. * _.isArrayLikeObject(_.noop);
  10325. * // => false
  10326. */
  10327. function isArrayLikeObject(value) {
  10328. return isObjectLike(value) && isArrayLike(value);
  10329. }
  10330. /**
  10331. * Checks if `value` is classified as a `Function` object.
  10332. *
  10333. * @static
  10334. * @memberOf _
  10335. * @since 0.1.0
  10336. * @category Lang
  10337. * @param {*} value The value to check.
  10338. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10339. * @example
  10340. *
  10341. * _.isFunction(_);
  10342. * // => true
  10343. *
  10344. * _.isFunction(/abc/);
  10345. * // => false
  10346. */
  10347. function isFunction(value) {
  10348. // The use of `Object#toString` avoids issues with the `typeof` operator
  10349. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  10350. var tag = isObject(value) ? objectToString.call(value) : '';
  10351. return tag == funcTag || tag == genTag;
  10352. }
  10353. /**
  10354. * Checks if `value` is a valid array-like length.
  10355. *
  10356. * **Note:** This method is loosely based on
  10357. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10358. *
  10359. * @static
  10360. * @memberOf _
  10361. * @since 4.0.0
  10362. * @category Lang
  10363. * @param {*} value The value to check.
  10364. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10365. * @example
  10366. *
  10367. * _.isLength(3);
  10368. * // => true
  10369. *
  10370. * _.isLength(Number.MIN_VALUE);
  10371. * // => false
  10372. *
  10373. * _.isLength(Infinity);
  10374. * // => false
  10375. *
  10376. * _.isLength('3');
  10377. * // => false
  10378. */
  10379. function isLength(value) {
  10380. return typeof value == 'number' &&
  10381. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10382. }
  10383. /**
  10384. * Checks if `value` is the
  10385. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10386. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10387. *
  10388. * @static
  10389. * @memberOf _
  10390. * @since 0.1.0
  10391. * @category Lang
  10392. * @param {*} value The value to check.
  10393. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10394. * @example
  10395. *
  10396. * _.isObject({});
  10397. * // => true
  10398. *
  10399. * _.isObject([1, 2, 3]);
  10400. * // => true
  10401. *
  10402. * _.isObject(_.noop);
  10403. * // => true
  10404. *
  10405. * _.isObject(null);
  10406. * // => false
  10407. */
  10408. function isObject(value) {
  10409. var type = typeof value;
  10410. return !!value && (type == 'object' || type == 'function');
  10411. }
  10412. /**
  10413. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10414. * and has a `typeof` result of "object".
  10415. *
  10416. * @static
  10417. * @memberOf _
  10418. * @since 4.0.0
  10419. * @category Lang
  10420. * @param {*} value The value to check.
  10421. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10422. * @example
  10423. *
  10424. * _.isObjectLike({});
  10425. * // => true
  10426. *
  10427. * _.isObjectLike([1, 2, 3]);
  10428. * // => true
  10429. *
  10430. * _.isObjectLike(_.noop);
  10431. * // => false
  10432. *
  10433. * _.isObjectLike(null);
  10434. * // => false
  10435. */
  10436. function isObjectLike(value) {
  10437. return !!value && typeof value == 'object';
  10438. }
  10439. module.exports = isArguments;
  10440. },{}],62:[function(require,module,exports){
  10441. /**
  10442. * lodash 3.0.4 (Custom Build) <https://lodash.com/>
  10443. * Build: `lodash modern modularize exports="npm" -o ./`
  10444. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10445. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10446. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10447. * Available under MIT license <https://lodash.com/license>
  10448. */
  10449. /** `Object#toString` result references. */
  10450. var arrayTag = '[object Array]',
  10451. funcTag = '[object Function]';
  10452. /** Used to detect host constructors (Safari > 5). */
  10453. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  10454. /**
  10455. * Checks if `value` is object-like.
  10456. *
  10457. * @private
  10458. * @param {*} value The value to check.
  10459. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10460. */
  10461. function isObjectLike(value) {
  10462. return !!value && typeof value == 'object';
  10463. }
  10464. /** Used for native method references. */
  10465. var objectProto = Object.prototype;
  10466. /** Used to resolve the decompiled source of functions. */
  10467. var fnToString = Function.prototype.toString;
  10468. /** Used to check objects for own properties. */
  10469. var hasOwnProperty = objectProto.hasOwnProperty;
  10470. /**
  10471. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  10472. * of values.
  10473. */
  10474. var objToString = objectProto.toString;
  10475. /** Used to detect if a method is native. */
  10476. var reIsNative = RegExp('^' +
  10477. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  10478. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  10479. );
  10480. /* Native method references for those with the same name as other `lodash` methods. */
  10481. var nativeIsArray = getNative(Array, 'isArray');
  10482. /**
  10483. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  10484. * of an array-like value.
  10485. */
  10486. var MAX_SAFE_INTEGER = 9007199254740991;
  10487. /**
  10488. * Gets the native function at `key` of `object`.
  10489. *
  10490. * @private
  10491. * @param {Object} object The object to query.
  10492. * @param {string} key The key of the method to get.
  10493. * @returns {*} Returns the function if it's native, else `undefined`.
  10494. */
  10495. function getNative(object, key) {
  10496. var value = object == null ? undefined : object[key];
  10497. return isNative(value) ? value : undefined;
  10498. }
  10499. /**
  10500. * Checks if `value` is a valid array-like length.
  10501. *
  10502. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  10503. *
  10504. * @private
  10505. * @param {*} value The value to check.
  10506. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10507. */
  10508. function isLength(value) {
  10509. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10510. }
  10511. /**
  10512. * Checks if `value` is classified as an `Array` object.
  10513. *
  10514. * @static
  10515. * @memberOf _
  10516. * @category Lang
  10517. * @param {*} value The value to check.
  10518. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10519. * @example
  10520. *
  10521. * _.isArray([1, 2, 3]);
  10522. * // => true
  10523. *
  10524. * _.isArray(function() { return arguments; }());
  10525. * // => false
  10526. */
  10527. var isArray = nativeIsArray || function(value) {
  10528. return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
  10529. };
  10530. /**
  10531. * Checks if `value` is classified as a `Function` object.
  10532. *
  10533. * @static
  10534. * @memberOf _
  10535. * @category Lang
  10536. * @param {*} value The value to check.
  10537. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10538. * @example
  10539. *
  10540. * _.isFunction(_);
  10541. * // => true
  10542. *
  10543. * _.isFunction(/abc/);
  10544. * // => false
  10545. */
  10546. function isFunction(value) {
  10547. // The use of `Object#toString` avoids issues with the `typeof` operator
  10548. // in older versions of Chrome and Safari which return 'function' for regexes
  10549. // and Safari 8 equivalents which return 'object' for typed array constructors.
  10550. return isObject(value) && objToString.call(value) == funcTag;
  10551. }
  10552. /**
  10553. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  10554. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10555. *
  10556. * @static
  10557. * @memberOf _
  10558. * @category Lang
  10559. * @param {*} value The value to check.
  10560. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10561. * @example
  10562. *
  10563. * _.isObject({});
  10564. * // => true
  10565. *
  10566. * _.isObject([1, 2, 3]);
  10567. * // => true
  10568. *
  10569. * _.isObject(1);
  10570. * // => false
  10571. */
  10572. function isObject(value) {
  10573. // Avoid a V8 JIT bug in Chrome 19-20.
  10574. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  10575. var type = typeof value;
  10576. return !!value && (type == 'object' || type == 'function');
  10577. }
  10578. /**
  10579. * Checks if `value` is a native function.
  10580. *
  10581. * @static
  10582. * @memberOf _
  10583. * @category Lang
  10584. * @param {*} value The value to check.
  10585. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  10586. * @example
  10587. *
  10588. * _.isNative(Array.prototype.push);
  10589. * // => true
  10590. *
  10591. * _.isNative(_);
  10592. * // => false
  10593. */
  10594. function isNative(value) {
  10595. if (value == null) {
  10596. return false;
  10597. }
  10598. if (isFunction(value)) {
  10599. return reIsNative.test(fnToString.call(value));
  10600. }
  10601. return isObjectLike(value) && reIsHostCtor.test(value);
  10602. }
  10603. module.exports = isArray;
  10604. },{}],63:[function(require,module,exports){
  10605. /**
  10606. * lodash 3.1.2 (Custom Build) <https://lodash.com/>
  10607. * Build: `lodash modern modularize exports="npm" -o ./`
  10608. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10609. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10610. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10611. * Available under MIT license <https://lodash.com/license>
  10612. */
  10613. var getNative = require('lodash._getnative'),
  10614. isArguments = require('lodash.isarguments'),
  10615. isArray = require('lodash.isarray');
  10616. /** Used to detect unsigned integer values. */
  10617. var reIsUint = /^\d+$/;
  10618. /** Used for native method references. */
  10619. var objectProto = Object.prototype;
  10620. /** Used to check objects for own properties. */
  10621. var hasOwnProperty = objectProto.hasOwnProperty;
  10622. /* Native method references for those with the same name as other `lodash` methods. */
  10623. var nativeKeys = getNative(Object, 'keys');
  10624. /**
  10625. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  10626. * of an array-like value.
  10627. */
  10628. var MAX_SAFE_INTEGER = 9007199254740991;
  10629. /**
  10630. * The base implementation of `_.property` without support for deep paths.
  10631. *
  10632. * @private
  10633. * @param {string} key The key of the property to get.
  10634. * @returns {Function} Returns the new function.
  10635. */
  10636. function baseProperty(key) {
  10637. return function(object) {
  10638. return object == null ? undefined : object[key];
  10639. };
  10640. }
  10641. /**
  10642. * Gets the "length" property value of `object`.
  10643. *
  10644. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  10645. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  10646. *
  10647. * @private
  10648. * @param {Object} object The object to query.
  10649. * @returns {*} Returns the "length" value.
  10650. */
  10651. var getLength = baseProperty('length');
  10652. /**
  10653. * Checks if `value` is array-like.
  10654. *
  10655. * @private
  10656. * @param {*} value The value to check.
  10657. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10658. */
  10659. function isArrayLike(value) {
  10660. return value != null && isLength(getLength(value));
  10661. }
  10662. /**
  10663. * Checks if `value` is a valid array-like index.
  10664. *
  10665. * @private
  10666. * @param {*} value The value to check.
  10667. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  10668. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  10669. */
  10670. function isIndex(value, length) {
  10671. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  10672. length = length == null ? MAX_SAFE_INTEGER : length;
  10673. return value > -1 && value % 1 == 0 && value < length;
  10674. }
  10675. /**
  10676. * Checks if `value` is a valid array-like length.
  10677. *
  10678. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  10679. *
  10680. * @private
  10681. * @param {*} value The value to check.
  10682. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10683. */
  10684. function isLength(value) {
  10685. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10686. }
  10687. /**
  10688. * A fallback implementation of `Object.keys` which creates an array of the
  10689. * own enumerable property names of `object`.
  10690. *
  10691. * @private
  10692. * @param {Object} object The object to query.
  10693. * @returns {Array} Returns the array of property names.
  10694. */
  10695. function shimKeys(object) {
  10696. var props = keysIn(object),
  10697. propsLength = props.length,
  10698. length = propsLength && object.length;
  10699. var allowIndexes = !!length && isLength(length) &&
  10700. (isArray(object) || isArguments(object));
  10701. var index = -1,
  10702. result = [];
  10703. while (++index < propsLength) {
  10704. var key = props[index];
  10705. if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
  10706. result.push(key);
  10707. }
  10708. }
  10709. return result;
  10710. }
  10711. /**
  10712. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  10713. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10714. *
  10715. * @static
  10716. * @memberOf _
  10717. * @category Lang
  10718. * @param {*} value The value to check.
  10719. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10720. * @example
  10721. *
  10722. * _.isObject({});
  10723. * // => true
  10724. *
  10725. * _.isObject([1, 2, 3]);
  10726. * // => true
  10727. *
  10728. * _.isObject(1);
  10729. * // => false
  10730. */
  10731. function isObject(value) {
  10732. // Avoid a V8 JIT bug in Chrome 19-20.
  10733. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  10734. var type = typeof value;
  10735. return !!value && (type == 'object' || type == 'function');
  10736. }
  10737. /**
  10738. * Creates an array of the own enumerable property names of `object`.
  10739. *
  10740. * **Note:** Non-object values are coerced to objects. See the
  10741. * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
  10742. * for more details.
  10743. *
  10744. * @static
  10745. * @memberOf _
  10746. * @category Object
  10747. * @param {Object} object The object to query.
  10748. * @returns {Array} Returns the array of property names.
  10749. * @example
  10750. *
  10751. * function Foo() {
  10752. * this.a = 1;
  10753. * this.b = 2;
  10754. * }
  10755. *
  10756. * Foo.prototype.c = 3;
  10757. *
  10758. * _.keys(new Foo);
  10759. * // => ['a', 'b'] (iteration order is not guaranteed)
  10760. *
  10761. * _.keys('hi');
  10762. * // => ['0', '1']
  10763. */
  10764. var keys = !nativeKeys ? shimKeys : function(object) {
  10765. var Ctor = object == null ? undefined : object.constructor;
  10766. if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
  10767. (typeof object != 'function' && isArrayLike(object))) {
  10768. return shimKeys(object);
  10769. }
  10770. return isObject(object) ? nativeKeys(object) : [];
  10771. };
  10772. /**
  10773. * Creates an array of the own and inherited enumerable property names of `object`.
  10774. *
  10775. * **Note:** Non-object values are coerced to objects.
  10776. *
  10777. * @static
  10778. * @memberOf _
  10779. * @category Object
  10780. * @param {Object} object The object to query.
  10781. * @returns {Array} Returns the array of property names.
  10782. * @example
  10783. *
  10784. * function Foo() {
  10785. * this.a = 1;
  10786. * this.b = 2;
  10787. * }
  10788. *
  10789. * Foo.prototype.c = 3;
  10790. *
  10791. * _.keysIn(new Foo);
  10792. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  10793. */
  10794. function keysIn(object) {
  10795. if (object == null) {
  10796. return [];
  10797. }
  10798. if (!isObject(object)) {
  10799. object = Object(object);
  10800. }
  10801. var length = object.length;
  10802. length = (length && isLength(length) &&
  10803. (isArray(object) || isArguments(object)) && length) || 0;
  10804. var Ctor = object.constructor,
  10805. index = -1,
  10806. isProto = typeof Ctor == 'function' && Ctor.prototype === object,
  10807. result = Array(length),
  10808. skipIndexes = length > 0;
  10809. while (++index < length) {
  10810. result[index] = (index + '');
  10811. }
  10812. for (var key in object) {
  10813. if (!(skipIndexes && isIndex(key, length)) &&
  10814. !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  10815. result.push(key);
  10816. }
  10817. }
  10818. return result;
  10819. }
  10820. module.exports = keys;
  10821. },{"lodash._getnative":58,"lodash.isarguments":61,"lodash.isarray":62}],64:[function(require,module,exports){
  10822. (function (process){
  10823. var path = require('path');
  10824. var fs = require('fs');
  10825. var _0777 = parseInt('0777', 8);
  10826. module.exports = mkdirP.mkdirp = mkdirP.mkdirP = mkdirP;
  10827. function mkdirP (p, opts, f, made) {
  10828. if (typeof opts === 'function') {
  10829. f = opts;
  10830. opts = {};
  10831. }
  10832. else if (!opts || typeof opts !== 'object') {
  10833. opts = { mode: opts };
  10834. }
  10835. var mode = opts.mode;
  10836. var xfs = opts.fs || fs;
  10837. if (mode === undefined) {
  10838. mode = _0777 & (~process.umask());
  10839. }
  10840. if (!made) made = null;
  10841. var cb = f || function () {};
  10842. p = path.resolve(p);
  10843. xfs.mkdir(p, mode, function (er) {
  10844. if (!er) {
  10845. made = made || p;
  10846. return cb(null, made);
  10847. }
  10848. switch (er.code) {
  10849. case 'ENOENT':
  10850. mkdirP(path.dirname(p), opts, function (er, made) {
  10851. if (er) cb(er, made);
  10852. else mkdirP(p, opts, cb, made);
  10853. });
  10854. break;
  10855. // In the case of any other error, just see if there's a dir
  10856. // there already. If so, then hooray! If not, then something
  10857. // is borked.
  10858. default:
  10859. xfs.stat(p, function (er2, stat) {
  10860. // if the stat fails, then that's super weird.
  10861. // let the original error be the failure reason.
  10862. if (er2 || !stat.isDirectory()) cb(er, made)
  10863. else cb(null, made);
  10864. });
  10865. break;
  10866. }
  10867. });
  10868. }
  10869. mkdirP.sync = function sync (p, opts, made) {
  10870. if (!opts || typeof opts !== 'object') {
  10871. opts = { mode: opts };
  10872. }
  10873. var mode = opts.mode;
  10874. var xfs = opts.fs || fs;
  10875. if (mode === undefined) {
  10876. mode = _0777 & (~process.umask());
  10877. }
  10878. if (!made) made = null;
  10879. p = path.resolve(p);
  10880. try {
  10881. xfs.mkdirSync(p, mode);
  10882. made = made || p;
  10883. }
  10884. catch (err0) {
  10885. switch (err0.code) {
  10886. case 'ENOENT' :
  10887. made = sync(path.dirname(p), opts, made);
  10888. sync(p, opts, made);
  10889. break;
  10890. // In the case of any other error, just see if there's a dir
  10891. // there already. If so, then hooray! If not, then something
  10892. // is borked.
  10893. default:
  10894. var stat;
  10895. try {
  10896. stat = xfs.statSync(p);
  10897. }
  10898. catch (err1) {
  10899. throw err0;
  10900. }
  10901. if (!stat.isDirectory()) throw err0;
  10902. break;
  10903. }
  10904. }
  10905. return made;
  10906. };
  10907. }).call(this,require('_process'))
  10908. },{"_process":67,"fs":42,"path":42}],65:[function(require,module,exports){
  10909. exports.endianness = function () { return 'LE' };
  10910. exports.hostname = function () {
  10911. if (typeof location !== 'undefined') {
  10912. return location.hostname
  10913. }
  10914. else return '';
  10915. };
  10916. exports.loadavg = function () { return [] };
  10917. exports.uptime = function () { return 0 };
  10918. exports.freemem = function () {
  10919. return Number.MAX_VALUE;
  10920. };
  10921. exports.totalmem = function () {
  10922. return Number.MAX_VALUE;
  10923. };
  10924. exports.cpus = function () { return [] };
  10925. exports.type = function () { return 'Browser' };
  10926. exports.release = function () {
  10927. if (typeof navigator !== 'undefined') {
  10928. return navigator.appVersion;
  10929. }
  10930. return '';
  10931. };
  10932. exports.networkInterfaces
  10933. = exports.getNetworkInterfaces
  10934. = function () { return {} };
  10935. exports.arch = function () { return 'javascript' };
  10936. exports.platform = function () { return 'browser' };
  10937. exports.tmpdir = exports.tmpDir = function () {
  10938. return '/tmp';
  10939. };
  10940. exports.EOL = '\n';
  10941. },{}],66:[function(require,module,exports){
  10942. (function (process){
  10943. 'use strict';
  10944. if (!process.version ||
  10945. process.version.indexOf('v0.') === 0 ||
  10946. process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
  10947. module.exports = nextTick;
  10948. } else {
  10949. module.exports = process.nextTick;
  10950. }
  10951. function nextTick(fn, arg1, arg2, arg3) {
  10952. if (typeof fn !== 'function') {
  10953. throw new TypeError('"callback" argument must be a function');
  10954. }
  10955. var len = arguments.length;
  10956. var args, i;
  10957. switch (len) {
  10958. case 0:
  10959. case 1:
  10960. return process.nextTick(fn);
  10961. case 2:
  10962. return process.nextTick(function afterTickOne() {
  10963. fn.call(null, arg1);
  10964. });
  10965. case 3:
  10966. return process.nextTick(function afterTickTwo() {
  10967. fn.call(null, arg1, arg2);
  10968. });
  10969. case 4:
  10970. return process.nextTick(function afterTickThree() {
  10971. fn.call(null, arg1, arg2, arg3);
  10972. });
  10973. default:
  10974. args = new Array(len - 1);
  10975. i = 0;
  10976. while (i < args.length) {
  10977. args[i++] = arguments[i];
  10978. }
  10979. return process.nextTick(function afterTick() {
  10980. fn.apply(null, args);
  10981. });
  10982. }
  10983. }
  10984. }).call(this,require('_process'))
  10985. },{"_process":67}],67:[function(require,module,exports){
  10986. // shim for using process in browser
  10987. var process = module.exports = {};
  10988. // cached from whatever global is present so that test runners that stub it
  10989. // don't break things. But we need to wrap it in a try catch in case it is
  10990. // wrapped in strict mode code which doesn't define any globals. It's inside a
  10991. // function because try/catches deoptimize in certain engines.
  10992. var cachedSetTimeout;
  10993. var cachedClearTimeout;
  10994. function defaultSetTimout() {
  10995. throw new Error('setTimeout has not been defined');
  10996. }
  10997. function defaultClearTimeout () {
  10998. throw new Error('clearTimeout has not been defined');
  10999. }
  11000. (function () {
  11001. try {
  11002. if (typeof setTimeout === 'function') {
  11003. cachedSetTimeout = setTimeout;
  11004. } else {
  11005. cachedSetTimeout = defaultSetTimout;
  11006. }
  11007. } catch (e) {
  11008. cachedSetTimeout = defaultSetTimout;
  11009. }
  11010. try {
  11011. if (typeof clearTimeout === 'function') {
  11012. cachedClearTimeout = clearTimeout;
  11013. } else {
  11014. cachedClearTimeout = defaultClearTimeout;
  11015. }
  11016. } catch (e) {
  11017. cachedClearTimeout = defaultClearTimeout;
  11018. }
  11019. } ())
  11020. function runTimeout(fun) {
  11021. if (cachedSetTimeout === setTimeout) {
  11022. //normal enviroments in sane situations
  11023. return setTimeout(fun, 0);
  11024. }
  11025. // if setTimeout wasn't available but was latter defined
  11026. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  11027. cachedSetTimeout = setTimeout;
  11028. return setTimeout(fun, 0);
  11029. }
  11030. try {
  11031. // when when somebody has screwed with setTimeout but no I.E. maddness
  11032. return cachedSetTimeout(fun, 0);
  11033. } catch(e){
  11034. try {
  11035. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  11036. return cachedSetTimeout.call(null, fun, 0);
  11037. } catch(e){
  11038. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  11039. return cachedSetTimeout.call(this, fun, 0);
  11040. }
  11041. }
  11042. }
  11043. function runClearTimeout(marker) {
  11044. if (cachedClearTimeout === clearTimeout) {
  11045. //normal enviroments in sane situations
  11046. return clearTimeout(marker);
  11047. }
  11048. // if clearTimeout wasn't available but was latter defined
  11049. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  11050. cachedClearTimeout = clearTimeout;
  11051. return clearTimeout(marker);
  11052. }
  11053. try {
  11054. // when when somebody has screwed with setTimeout but no I.E. maddness
  11055. return cachedClearTimeout(marker);
  11056. } catch (e){
  11057. try {
  11058. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  11059. return cachedClearTimeout.call(null, marker);
  11060. } catch (e){
  11061. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  11062. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  11063. return cachedClearTimeout.call(this, marker);
  11064. }
  11065. }
  11066. }
  11067. var queue = [];
  11068. var draining = false;
  11069. var currentQueue;
  11070. var queueIndex = -1;
  11071. function cleanUpNextTick() {
  11072. if (!draining || !currentQueue) {
  11073. return;
  11074. }
  11075. draining = false;
  11076. if (currentQueue.length) {
  11077. queue = currentQueue.concat(queue);
  11078. } else {
  11079. queueIndex = -1;
  11080. }
  11081. if (queue.length) {
  11082. drainQueue();
  11083. }
  11084. }
  11085. function drainQueue() {
  11086. if (draining) {
  11087. return;
  11088. }
  11089. var timeout = runTimeout(cleanUpNextTick);
  11090. draining = true;
  11091. var len = queue.length;
  11092. while(len) {
  11093. currentQueue = queue;
  11094. queue = [];
  11095. while (++queueIndex < len) {
  11096. if (currentQueue) {
  11097. currentQueue[queueIndex].run();
  11098. }
  11099. }
  11100. queueIndex = -1;
  11101. len = queue.length;
  11102. }
  11103. currentQueue = null;
  11104. draining = false;
  11105. runClearTimeout(timeout);
  11106. }
  11107. process.nextTick = function (fun) {
  11108. var args = new Array(arguments.length - 1);
  11109. if (arguments.length > 1) {
  11110. for (var i = 1; i < arguments.length; i++) {
  11111. args[i - 1] = arguments[i];
  11112. }
  11113. }
  11114. queue.push(new Item(fun, args));
  11115. if (queue.length === 1 && !draining) {
  11116. runTimeout(drainQueue);
  11117. }
  11118. };
  11119. // v8 likes predictible objects
  11120. function Item(fun, array) {
  11121. this.fun = fun;
  11122. this.array = array;
  11123. }
  11124. Item.prototype.run = function () {
  11125. this.fun.apply(null, this.array);
  11126. };
  11127. process.title = 'browser';
  11128. process.browser = true;
  11129. process.env = {};
  11130. process.argv = [];
  11131. process.version = ''; // empty string to avoid regexp issues
  11132. process.versions = {};
  11133. function noop() {}
  11134. process.on = noop;
  11135. process.addListener = noop;
  11136. process.once = noop;
  11137. process.off = noop;
  11138. process.removeListener = noop;
  11139. process.removeAllListeners = noop;
  11140. process.emit = noop;
  11141. process.binding = function (name) {
  11142. throw new Error('process.binding is not supported');
  11143. };
  11144. process.cwd = function () { return '/' };
  11145. process.chdir = function (dir) {
  11146. throw new Error('process.chdir is not supported');
  11147. };
  11148. process.umask = function() { return 0; };
  11149. },{}],68:[function(require,module,exports){
  11150. module.exports = require("./lib/_stream_duplex.js")
  11151. },{"./lib/_stream_duplex.js":69}],69:[function(require,module,exports){
  11152. // a duplex stream is just a stream that is both readable and writable.
  11153. // Since JS doesn't have multiple prototypal inheritance, this class
  11154. // prototypally inherits from Readable, and then parasitically from
  11155. // Writable.
  11156. 'use strict';
  11157. /*<replacement>*/
  11158. var objectKeys = Object.keys || function (obj) {
  11159. var keys = [];
  11160. for (var key in obj) {
  11161. keys.push(key);
  11162. }return keys;
  11163. };
  11164. /*</replacement>*/
  11165. module.exports = Duplex;
  11166. /*<replacement>*/
  11167. var processNextTick = require('process-nextick-args');
  11168. /*</replacement>*/
  11169. /*<replacement>*/
  11170. var util = require('core-util-is');
  11171. util.inherits = require('inherits');
  11172. /*</replacement>*/
  11173. var Readable = require('./_stream_readable');
  11174. var Writable = require('./_stream_writable');
  11175. util.inherits(Duplex, Readable);
  11176. var keys = objectKeys(Writable.prototype);
  11177. for (var v = 0; v < keys.length; v++) {
  11178. var method = keys[v];
  11179. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  11180. }
  11181. function Duplex(options) {
  11182. if (!(this instanceof Duplex)) return new Duplex(options);
  11183. Readable.call(this, options);
  11184. Writable.call(this, options);
  11185. if (options && options.readable === false) this.readable = false;
  11186. if (options && options.writable === false) this.writable = false;
  11187. this.allowHalfOpen = true;
  11188. if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
  11189. this.once('end', onend);
  11190. }
  11191. // the no-half-open enforcer
  11192. function onend() {
  11193. // if we allow half-open state, or if the writable side ended,
  11194. // then we're ok.
  11195. if (this.allowHalfOpen || this._writableState.ended) return;
  11196. // no more data can be written.
  11197. // But allow more writes to happen in this tick.
  11198. processNextTick(onEndNT, this);
  11199. }
  11200. function onEndNT(self) {
  11201. self.end();
  11202. }
  11203. function forEach(xs, f) {
  11204. for (var i = 0, l = xs.length; i < l; i++) {
  11205. f(xs[i], i);
  11206. }
  11207. }
  11208. },{"./_stream_readable":71,"./_stream_writable":73,"core-util-is":45,"inherits":51,"process-nextick-args":66}],70:[function(require,module,exports){
  11209. // a passthrough stream.
  11210. // basically just the most minimal sort of Transform stream.
  11211. // Every written chunk gets output as-is.
  11212. 'use strict';
  11213. module.exports = PassThrough;
  11214. var Transform = require('./_stream_transform');
  11215. /*<replacement>*/
  11216. var util = require('core-util-is');
  11217. util.inherits = require('inherits');
  11218. /*</replacement>*/
  11219. util.inherits(PassThrough, Transform);
  11220. function PassThrough(options) {
  11221. if (!(this instanceof PassThrough)) return new PassThrough(options);
  11222. Transform.call(this, options);
  11223. }
  11224. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  11225. cb(null, chunk);
  11226. };
  11227. },{"./_stream_transform":72,"core-util-is":45,"inherits":51}],71:[function(require,module,exports){
  11228. (function (process){
  11229. 'use strict';
  11230. module.exports = Readable;
  11231. /*<replacement>*/
  11232. var processNextTick = require('process-nextick-args');
  11233. /*</replacement>*/
  11234. /*<replacement>*/
  11235. var isArray = require('isarray');
  11236. /*</replacement>*/
  11237. Readable.ReadableState = ReadableState;
  11238. /*<replacement>*/
  11239. var EE = require('events').EventEmitter;
  11240. var EElistenerCount = function (emitter, type) {
  11241. return emitter.listeners(type).length;
  11242. };
  11243. /*</replacement>*/
  11244. /*<replacement>*/
  11245. var Stream;
  11246. (function () {
  11247. try {
  11248. Stream = require('st' + 'ream');
  11249. } catch (_) {} finally {
  11250. if (!Stream) Stream = require('events').EventEmitter;
  11251. }
  11252. })();
  11253. /*</replacement>*/
  11254. var Buffer = require('buffer').Buffer;
  11255. /*<replacement>*/
  11256. var bufferShim = require('buffer-shims');
  11257. /*</replacement>*/
  11258. /*<replacement>*/
  11259. var util = require('core-util-is');
  11260. util.inherits = require('inherits');
  11261. /*</replacement>*/
  11262. /*<replacement>*/
  11263. var debugUtil = require('util');
  11264. var debug = void 0;
  11265. if (debugUtil && debugUtil.debuglog) {
  11266. debug = debugUtil.debuglog('stream');
  11267. } else {
  11268. debug = function () {};
  11269. }
  11270. /*</replacement>*/
  11271. var BufferList = require('./internal/streams/BufferList');
  11272. var StringDecoder;
  11273. util.inherits(Readable, Stream);
  11274. function prependListener(emitter, event, fn) {
  11275. if (typeof emitter.prependListener === 'function') {
  11276. return emitter.prependListener(event, fn);
  11277. } else {
  11278. // This is a hack to make sure that our error handler is attached before any
  11279. // userland ones. NEVER DO THIS. This is here only because this code needs
  11280. // to continue to work with older versions of Node.js that do not include
  11281. // the prependListener() method. The goal is to eventually remove this hack.
  11282. 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]];
  11283. }
  11284. }
  11285. var Duplex;
  11286. function ReadableState(options, stream) {
  11287. Duplex = Duplex || require('./_stream_duplex');
  11288. options = options || {};
  11289. // object stream flag. Used to make read(n) ignore n and to
  11290. // make all the buffer merging and length checks go away
  11291. this.objectMode = !!options.objectMode;
  11292. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
  11293. // the point at which it stops calling _read() to fill the buffer
  11294. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  11295. var hwm = options.highWaterMark;
  11296. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  11297. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  11298. // cast to ints.
  11299. this.highWaterMark = ~ ~this.highWaterMark;
  11300. // A linked list is used to store data chunks instead of an array because the
  11301. // linked list can remove elements from the beginning faster than
  11302. // array.shift()
  11303. this.buffer = new BufferList();
  11304. this.length = 0;
  11305. this.pipes = null;
  11306. this.pipesCount = 0;
  11307. this.flowing = null;
  11308. this.ended = false;
  11309. this.endEmitted = false;
  11310. this.reading = false;
  11311. // a flag to be able to tell if the onwrite cb is called immediately,
  11312. // or on a later tick. We set this to true at first, because any
  11313. // actions that shouldn't happen until "later" should generally also
  11314. // not happen before the first write call.
  11315. this.sync = true;
  11316. // whenever we return null, then we set a flag to say
  11317. // that we're awaiting a 'readable' event emission.
  11318. this.needReadable = false;
  11319. this.emittedReadable = false;
  11320. this.readableListening = false;
  11321. this.resumeScheduled = false;
  11322. // Crypto is kind of old and crusty. Historically, its default string
  11323. // encoding is 'binary' so we have to make this configurable.
  11324. // Everything else in the universe uses 'utf8', though.
  11325. this.defaultEncoding = options.defaultEncoding || 'utf8';
  11326. // when piping, we only care about 'readable' events that happen
  11327. // after read()ing all the bytes and not getting any pushback.
  11328. this.ranOut = false;
  11329. // the number of writers that are awaiting a drain event in .pipe()s
  11330. this.awaitDrain = 0;
  11331. // if true, a maybeReadMore has been scheduled
  11332. this.readingMore = false;
  11333. this.decoder = null;
  11334. this.encoding = null;
  11335. if (options.encoding) {
  11336. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  11337. this.decoder = new StringDecoder(options.encoding);
  11338. this.encoding = options.encoding;
  11339. }
  11340. }
  11341. var Duplex;
  11342. function Readable(options) {
  11343. Duplex = Duplex || require('./_stream_duplex');
  11344. if (!(this instanceof Readable)) return new Readable(options);
  11345. this._readableState = new ReadableState(options, this);
  11346. // legacy
  11347. this.readable = true;
  11348. if (options && typeof options.read === 'function') this._read = options.read;
  11349. Stream.call(this);
  11350. }
  11351. // Manually shove something into the read() buffer.
  11352. // This returns true if the highWaterMark has not been hit yet,
  11353. // similar to how Writable.write() returns true if you should
  11354. // write() some more.
  11355. Readable.prototype.push = function (chunk, encoding) {
  11356. var state = this._readableState;
  11357. if (!state.objectMode && typeof chunk === 'string') {
  11358. encoding = encoding || state.defaultEncoding;
  11359. if (encoding !== state.encoding) {
  11360. chunk = bufferShim.from(chunk, encoding);
  11361. encoding = '';
  11362. }
  11363. }
  11364. return readableAddChunk(this, state, chunk, encoding, false);
  11365. };
  11366. // Unshift should *always* be something directly out of read()
  11367. Readable.prototype.unshift = function (chunk) {
  11368. var state = this._readableState;
  11369. return readableAddChunk(this, state, chunk, '', true);
  11370. };
  11371. Readable.prototype.isPaused = function () {
  11372. return this._readableState.flowing === false;
  11373. };
  11374. function readableAddChunk(stream, state, chunk, encoding, addToFront) {
  11375. var er = chunkInvalid(state, chunk);
  11376. if (er) {
  11377. stream.emit('error', er);
  11378. } else if (chunk === null) {
  11379. state.reading = false;
  11380. onEofChunk(stream, state);
  11381. } else if (state.objectMode || chunk && chunk.length > 0) {
  11382. if (state.ended && !addToFront) {
  11383. var e = new Error('stream.push() after EOF');
  11384. stream.emit('error', e);
  11385. } else if (state.endEmitted && addToFront) {
  11386. var _e = new Error('stream.unshift() after end event');
  11387. stream.emit('error', _e);
  11388. } else {
  11389. var skipAdd;
  11390. if (state.decoder && !addToFront && !encoding) {
  11391. chunk = state.decoder.write(chunk);
  11392. skipAdd = !state.objectMode && chunk.length === 0;
  11393. }
  11394. if (!addToFront) state.reading = false;
  11395. // Don't add to the buffer if we've decoded to an empty string chunk and
  11396. // we're not in object mode
  11397. if (!skipAdd) {
  11398. // if we want the data now, just emit it.
  11399. if (state.flowing && state.length === 0 && !state.sync) {
  11400. stream.emit('data', chunk);
  11401. stream.read(0);
  11402. } else {
  11403. // update the buffer info.
  11404. state.length += state.objectMode ? 1 : chunk.length;
  11405. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  11406. if (state.needReadable) emitReadable(stream);
  11407. }
  11408. }
  11409. maybeReadMore(stream, state);
  11410. }
  11411. } else if (!addToFront) {
  11412. state.reading = false;
  11413. }
  11414. return needMoreData(state);
  11415. }
  11416. // if it's past the high water mark, we can push in some more.
  11417. // Also, if we have no data yet, we can stand some
  11418. // more bytes. This is to work around cases where hwm=0,
  11419. // such as the repl. Also, if the push() triggered a
  11420. // readable event, and the user called read(largeNumber) such that
  11421. // needReadable was set, then we ought to push more, so that another
  11422. // 'readable' event will be triggered.
  11423. function needMoreData(state) {
  11424. return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
  11425. }
  11426. // backwards compatibility.
  11427. Readable.prototype.setEncoding = function (enc) {
  11428. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  11429. this._readableState.decoder = new StringDecoder(enc);
  11430. this._readableState.encoding = enc;
  11431. return this;
  11432. };
  11433. // Don't raise the hwm > 8MB
  11434. var MAX_HWM = 0x800000;
  11435. function computeNewHighWaterMark(n) {
  11436. if (n >= MAX_HWM) {
  11437. n = MAX_HWM;
  11438. } else {
  11439. // Get the next highest power of 2 to prevent increasing hwm excessively in
  11440. // tiny amounts
  11441. n--;
  11442. n |= n >>> 1;
  11443. n |= n >>> 2;
  11444. n |= n >>> 4;
  11445. n |= n >>> 8;
  11446. n |= n >>> 16;
  11447. n++;
  11448. }
  11449. return n;
  11450. }
  11451. // This function is designed to be inlinable, so please take care when making
  11452. // changes to the function body.
  11453. function howMuchToRead(n, state) {
  11454. if (n <= 0 || state.length === 0 && state.ended) return 0;
  11455. if (state.objectMode) return 1;
  11456. if (n !== n) {
  11457. // Only flow one buffer at a time
  11458. if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
  11459. }
  11460. // If we're asking for more than the current hwm, then raise the hwm.
  11461. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  11462. if (n <= state.length) return n;
  11463. // Don't have enough
  11464. if (!state.ended) {
  11465. state.needReadable = true;
  11466. return 0;
  11467. }
  11468. return state.length;
  11469. }
  11470. // you can override either this method, or the async _read(n) below.
  11471. Readable.prototype.read = function (n) {
  11472. debug('read', n);
  11473. n = parseInt(n, 10);
  11474. var state = this._readableState;
  11475. var nOrig = n;
  11476. if (n !== 0) state.emittedReadable = false;
  11477. // if we're doing read(0) to trigger a readable event, but we
  11478. // already have a bunch of data in the buffer, then just trigger
  11479. // the 'readable' event and move on.
  11480. if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
  11481. debug('read: emitReadable', state.length, state.ended);
  11482. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  11483. return null;
  11484. }
  11485. n = howMuchToRead(n, state);
  11486. // if we've ended, and we're now clear, then finish it up.
  11487. if (n === 0 && state.ended) {
  11488. if (state.length === 0) endReadable(this);
  11489. return null;
  11490. }
  11491. // All the actual chunk generation logic needs to be
  11492. // *below* the call to _read. The reason is that in certain
  11493. // synthetic stream cases, such as passthrough streams, _read
  11494. // may be a completely synchronous operation which may change
  11495. // the state of the read buffer, providing enough data when
  11496. // before there was *not* enough.
  11497. //
  11498. // So, the steps are:
  11499. // 1. Figure out what the state of things will be after we do
  11500. // a read from the buffer.
  11501. //
  11502. // 2. If that resulting state will trigger a _read, then call _read.
  11503. // Note that this may be asynchronous, or synchronous. Yes, it is
  11504. // deeply ugly to write APIs this way, but that still doesn't mean
  11505. // that the Readable class should behave improperly, as streams are
  11506. // designed to be sync/async agnostic.
  11507. // Take note if the _read call is sync or async (ie, if the read call
  11508. // has returned yet), so that we know whether or not it's safe to emit
  11509. // 'readable' etc.
  11510. //
  11511. // 3. Actually pull the requested chunks out of the buffer and return.
  11512. // if we need a readable event, then we need to do some reading.
  11513. var doRead = state.needReadable;
  11514. debug('need readable', doRead);
  11515. // if we currently have less than the highWaterMark, then also read some
  11516. if (state.length === 0 || state.length - n < state.highWaterMark) {
  11517. doRead = true;
  11518. debug('length less than watermark', doRead);
  11519. }
  11520. // however, if we've ended, then there's no point, and if we're already
  11521. // reading, then it's unnecessary.
  11522. if (state.ended || state.reading) {
  11523. doRead = false;
  11524. debug('reading or ended', doRead);
  11525. } else if (doRead) {
  11526. debug('do read');
  11527. state.reading = true;
  11528. state.sync = true;
  11529. // if the length is currently zero, then we *need* a readable event.
  11530. if (state.length === 0) state.needReadable = true;
  11531. // call internal read method
  11532. this._read(state.highWaterMark);
  11533. state.sync = false;
  11534. // If _read pushed data synchronously, then `reading` will be false,
  11535. // and we need to re-evaluate how much data we can return to the user.
  11536. if (!state.reading) n = howMuchToRead(nOrig, state);
  11537. }
  11538. var ret;
  11539. if (n > 0) ret = fromList(n, state);else ret = null;
  11540. if (ret === null) {
  11541. state.needReadable = true;
  11542. n = 0;
  11543. } else {
  11544. state.length -= n;
  11545. }
  11546. if (state.length === 0) {
  11547. // If we have nothing in the buffer, then we want to know
  11548. // as soon as we *do* get something into the buffer.
  11549. if (!state.ended) state.needReadable = true;
  11550. // If we tried to read() past the EOF, then emit end on the next tick.
  11551. if (nOrig !== n && state.ended) endReadable(this);
  11552. }
  11553. if (ret !== null) this.emit('data', ret);
  11554. return ret;
  11555. };
  11556. function chunkInvalid(state, chunk) {
  11557. var er = null;
  11558. if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
  11559. er = new TypeError('Invalid non-string/buffer chunk');
  11560. }
  11561. return er;
  11562. }
  11563. function onEofChunk(stream, state) {
  11564. if (state.ended) return;
  11565. if (state.decoder) {
  11566. var chunk = state.decoder.end();
  11567. if (chunk && chunk.length) {
  11568. state.buffer.push(chunk);
  11569. state.length += state.objectMode ? 1 : chunk.length;
  11570. }
  11571. }
  11572. state.ended = true;
  11573. // emit 'readable' now to make sure it gets picked up.
  11574. emitReadable(stream);
  11575. }
  11576. // Don't emit readable right away in sync mode, because this can trigger
  11577. // another read() call => stack overflow. This way, it might trigger
  11578. // a nextTick recursion warning, but that's not so bad.
  11579. function emitReadable(stream) {
  11580. var state = stream._readableState;
  11581. state.needReadable = false;
  11582. if (!state.emittedReadable) {
  11583. debug('emitReadable', state.flowing);
  11584. state.emittedReadable = true;
  11585. if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream);
  11586. }
  11587. }
  11588. function emitReadable_(stream) {
  11589. debug('emit readable');
  11590. stream.emit('readable');
  11591. flow(stream);
  11592. }
  11593. // at this point, the user has presumably seen the 'readable' event,
  11594. // and called read() to consume some data. that may have triggered
  11595. // in turn another _read(n) call, in which case reading = true if
  11596. // it's in progress.
  11597. // However, if we're not ended, or reading, and the length < hwm,
  11598. // then go ahead and try to read some more preemptively.
  11599. function maybeReadMore(stream, state) {
  11600. if (!state.readingMore) {
  11601. state.readingMore = true;
  11602. processNextTick(maybeReadMore_, stream, state);
  11603. }
  11604. }
  11605. function maybeReadMore_(stream, state) {
  11606. var len = state.length;
  11607. while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
  11608. debug('maybeReadMore read 0');
  11609. stream.read(0);
  11610. if (len === state.length)
  11611. // didn't get any data, stop spinning.
  11612. break;else len = state.length;
  11613. }
  11614. state.readingMore = false;
  11615. }
  11616. // abstract method. to be overridden in specific implementation classes.
  11617. // call cb(er, data) where data is <= n in length.
  11618. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  11619. // arbitrary, and perhaps not very meaningful.
  11620. Readable.prototype._read = function (n) {
  11621. this.emit('error', new Error('not implemented'));
  11622. };
  11623. Readable.prototype.pipe = function (dest, pipeOpts) {
  11624. var src = this;
  11625. var state = this._readableState;
  11626. switch (state.pipesCount) {
  11627. case 0:
  11628. state.pipes = dest;
  11629. break;
  11630. case 1:
  11631. state.pipes = [state.pipes, dest];
  11632. break;
  11633. default:
  11634. state.pipes.push(dest);
  11635. break;
  11636. }
  11637. state.pipesCount += 1;
  11638. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  11639. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  11640. var endFn = doEnd ? onend : cleanup;
  11641. if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn);
  11642. dest.on('unpipe', onunpipe);
  11643. function onunpipe(readable) {
  11644. debug('onunpipe');
  11645. if (readable === src) {
  11646. cleanup();
  11647. }
  11648. }
  11649. function onend() {
  11650. debug('onend');
  11651. dest.end();
  11652. }
  11653. // when the dest drains, it reduces the awaitDrain counter
  11654. // on the source. This would be more elegant with a .once()
  11655. // handler in flow(), but adding and removing repeatedly is
  11656. // too slow.
  11657. var ondrain = pipeOnDrain(src);
  11658. dest.on('drain', ondrain);
  11659. var cleanedUp = false;
  11660. function cleanup() {
  11661. debug('cleanup');
  11662. // cleanup event handlers once the pipe is broken
  11663. dest.removeListener('close', onclose);
  11664. dest.removeListener('finish', onfinish);
  11665. dest.removeListener('drain', ondrain);
  11666. dest.removeListener('error', onerror);
  11667. dest.removeListener('unpipe', onunpipe);
  11668. src.removeListener('end', onend);
  11669. src.removeListener('end', cleanup);
  11670. src.removeListener('data', ondata);
  11671. cleanedUp = true;
  11672. // if the reader is waiting for a drain event from this
  11673. // specific writer, then it would cause it to never start
  11674. // flowing again.
  11675. // So, if this is awaiting a drain, then we just call it now.
  11676. // If we don't know, then assume that we are waiting for one.
  11677. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  11678. }
  11679. // If the user pushes more data while we're writing to dest then we'll end up
  11680. // in ondata again. However, we only want to increase awaitDrain once because
  11681. // dest will only emit one 'drain' event for the multiple writes.
  11682. // => Introduce a guard on increasing awaitDrain.
  11683. var increasedAwaitDrain = false;
  11684. src.on('data', ondata);
  11685. function ondata(chunk) {
  11686. debug('ondata');
  11687. increasedAwaitDrain = false;
  11688. var ret = dest.write(chunk);
  11689. if (false === ret && !increasedAwaitDrain) {
  11690. // If the user unpiped during `dest.write()`, it is possible
  11691. // to get stuck in a permanently paused state if that write
  11692. // also returned false.
  11693. // => Check whether `dest` is still a piping destination.
  11694. if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  11695. debug('false write response, pause', src._readableState.awaitDrain);
  11696. src._readableState.awaitDrain++;
  11697. increasedAwaitDrain = true;
  11698. }
  11699. src.pause();
  11700. }
  11701. }
  11702. // if the dest has an error, then stop piping into it.
  11703. // however, don't suppress the throwing behavior for this.
  11704. function onerror(er) {
  11705. debug('onerror', er);
  11706. unpipe();
  11707. dest.removeListener('error', onerror);
  11708. if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
  11709. }
  11710. // Make sure our error handler is attached before userland ones.
  11711. prependListener(dest, 'error', onerror);
  11712. // Both close and finish should trigger unpipe, but only once.
  11713. function onclose() {
  11714. dest.removeListener('finish', onfinish);
  11715. unpipe();
  11716. }
  11717. dest.once('close', onclose);
  11718. function onfinish() {
  11719. debug('onfinish');
  11720. dest.removeListener('close', onclose);
  11721. unpipe();
  11722. }
  11723. dest.once('finish', onfinish);
  11724. function unpipe() {
  11725. debug('unpipe');
  11726. src.unpipe(dest);
  11727. }
  11728. // tell the dest that it's being piped to
  11729. dest.emit('pipe', src);
  11730. // start the flow if it hasn't been started already.
  11731. if (!state.flowing) {
  11732. debug('pipe resume');
  11733. src.resume();
  11734. }
  11735. return dest;
  11736. };
  11737. function pipeOnDrain(src) {
  11738. return function () {
  11739. var state = src._readableState;
  11740. debug('pipeOnDrain', state.awaitDrain);
  11741. if (state.awaitDrain) state.awaitDrain--;
  11742. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  11743. state.flowing = true;
  11744. flow(src);
  11745. }
  11746. };
  11747. }
  11748. Readable.prototype.unpipe = function (dest) {
  11749. var state = this._readableState;
  11750. // if we're not piping anywhere, then do nothing.
  11751. if (state.pipesCount === 0) return this;
  11752. // just one destination. most common case.
  11753. if (state.pipesCount === 1) {
  11754. // passed in one, but it's not the right one.
  11755. if (dest && dest !== state.pipes) return this;
  11756. if (!dest) dest = state.pipes;
  11757. // got a match.
  11758. state.pipes = null;
  11759. state.pipesCount = 0;
  11760. state.flowing = false;
  11761. if (dest) dest.emit('unpipe', this);
  11762. return this;
  11763. }
  11764. // slow case. multiple pipe destinations.
  11765. if (!dest) {
  11766. // remove all.
  11767. var dests = state.pipes;
  11768. var len = state.pipesCount;
  11769. state.pipes = null;
  11770. state.pipesCount = 0;
  11771. state.flowing = false;
  11772. for (var _i = 0; _i < len; _i++) {
  11773. dests[_i].emit('unpipe', this);
  11774. }return this;
  11775. }
  11776. // try to find the right one.
  11777. var i = indexOf(state.pipes, dest);
  11778. if (i === -1) return this;
  11779. state.pipes.splice(i, 1);
  11780. state.pipesCount -= 1;
  11781. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  11782. dest.emit('unpipe', this);
  11783. return this;
  11784. };
  11785. // set up data events if they are asked for
  11786. // Ensure readable listeners eventually get something
  11787. Readable.prototype.on = function (ev, fn) {
  11788. var res = Stream.prototype.on.call(this, ev, fn);
  11789. if (ev === 'data') {
  11790. // Start flowing on next tick if stream isn't explicitly paused
  11791. if (this._readableState.flowing !== false) this.resume();
  11792. } else if (ev === 'readable') {
  11793. var state = this._readableState;
  11794. if (!state.endEmitted && !state.readableListening) {
  11795. state.readableListening = state.needReadable = true;
  11796. state.emittedReadable = false;
  11797. if (!state.reading) {
  11798. processNextTick(nReadingNextTick, this);
  11799. } else if (state.length) {
  11800. emitReadable(this, state);
  11801. }
  11802. }
  11803. }
  11804. return res;
  11805. };
  11806. Readable.prototype.addListener = Readable.prototype.on;
  11807. function nReadingNextTick(self) {
  11808. debug('readable nexttick read 0');
  11809. self.read(0);
  11810. }
  11811. // pause() and resume() are remnants of the legacy readable stream API
  11812. // If the user uses them, then switch into old mode.
  11813. Readable.prototype.resume = function () {
  11814. var state = this._readableState;
  11815. if (!state.flowing) {
  11816. debug('resume');
  11817. state.flowing = true;
  11818. resume(this, state);
  11819. }
  11820. return this;
  11821. };
  11822. function resume(stream, state) {
  11823. if (!state.resumeScheduled) {
  11824. state.resumeScheduled = true;
  11825. processNextTick(resume_, stream, state);
  11826. }
  11827. }
  11828. function resume_(stream, state) {
  11829. if (!state.reading) {
  11830. debug('resume read 0');
  11831. stream.read(0);
  11832. }
  11833. state.resumeScheduled = false;
  11834. state.awaitDrain = 0;
  11835. stream.emit('resume');
  11836. flow(stream);
  11837. if (state.flowing && !state.reading) stream.read(0);
  11838. }
  11839. Readable.prototype.pause = function () {
  11840. debug('call pause flowing=%j', this._readableState.flowing);
  11841. if (false !== this._readableState.flowing) {
  11842. debug('pause');
  11843. this._readableState.flowing = false;
  11844. this.emit('pause');
  11845. }
  11846. return this;
  11847. };
  11848. function flow(stream) {
  11849. var state = stream._readableState;
  11850. debug('flow', state.flowing);
  11851. while (state.flowing && stream.read() !== null) {}
  11852. }
  11853. // wrap an old-style stream as the async data source.
  11854. // This is *not* part of the readable stream interface.
  11855. // It is an ugly unfortunate mess of history.
  11856. Readable.prototype.wrap = function (stream) {
  11857. var state = this._readableState;
  11858. var paused = false;
  11859. var self = this;
  11860. stream.on('end', function () {
  11861. debug('wrapped end');
  11862. if (state.decoder && !state.ended) {
  11863. var chunk = state.decoder.end();
  11864. if (chunk && chunk.length) self.push(chunk);
  11865. }
  11866. self.push(null);
  11867. });
  11868. stream.on('data', function (chunk) {
  11869. debug('wrapped data');
  11870. if (state.decoder) chunk = state.decoder.write(chunk);
  11871. // don't skip over falsy values in objectMode
  11872. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  11873. var ret = self.push(chunk);
  11874. if (!ret) {
  11875. paused = true;
  11876. stream.pause();
  11877. }
  11878. });
  11879. // proxy all the other methods.
  11880. // important when wrapping filters and duplexes.
  11881. for (var i in stream) {
  11882. if (this[i] === undefined && typeof stream[i] === 'function') {
  11883. this[i] = function (method) {
  11884. return function () {
  11885. return stream[method].apply(stream, arguments);
  11886. };
  11887. }(i);
  11888. }
  11889. }
  11890. // proxy certain important events.
  11891. var events = ['error', 'close', 'destroy', 'pause', 'resume'];
  11892. forEach(events, function (ev) {
  11893. stream.on(ev, self.emit.bind(self, ev));
  11894. });
  11895. // when we try to consume some more bytes, simply unpause the
  11896. // underlying stream.
  11897. self._read = function (n) {
  11898. debug('wrapped _read', n);
  11899. if (paused) {
  11900. paused = false;
  11901. stream.resume();
  11902. }
  11903. };
  11904. return self;
  11905. };
  11906. // exposed for testing purposes only.
  11907. Readable._fromList = fromList;
  11908. // Pluck off n bytes from an array of buffers.
  11909. // Length is the combined lengths of all the buffers in the list.
  11910. // This function is designed to be inlinable, so please take care when making
  11911. // changes to the function body.
  11912. function fromList(n, state) {
  11913. // nothing buffered
  11914. if (state.length === 0) return null;
  11915. var ret;
  11916. if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
  11917. // read it all, truncate the list
  11918. if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length);
  11919. state.buffer.clear();
  11920. } else {
  11921. // read part of list
  11922. ret = fromListPartial(n, state.buffer, state.decoder);
  11923. }
  11924. return ret;
  11925. }
  11926. // Extracts only enough buffered data to satisfy the amount requested.
  11927. // This function is designed to be inlinable, so please take care when making
  11928. // changes to the function body.
  11929. function fromListPartial(n, list, hasStrings) {
  11930. var ret;
  11931. if (n < list.head.data.length) {
  11932. // slice is the same for buffers and strings
  11933. ret = list.head.data.slice(0, n);
  11934. list.head.data = list.head.data.slice(n);
  11935. } else if (n === list.head.data.length) {
  11936. // first chunk is a perfect match
  11937. ret = list.shift();
  11938. } else {
  11939. // result spans more than one buffer
  11940. ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
  11941. }
  11942. return ret;
  11943. }
  11944. // Copies a specified amount of characters from the list of buffered data
  11945. // chunks.
  11946. // This function is designed to be inlinable, so please take care when making
  11947. // changes to the function body.
  11948. function copyFromBufferString(n, list) {
  11949. var p = list.head;
  11950. var c = 1;
  11951. var ret = p.data;
  11952. n -= ret.length;
  11953. while (p = p.next) {
  11954. var str = p.data;
  11955. var nb = n > str.length ? str.length : n;
  11956. if (nb === str.length) ret += str;else ret += str.slice(0, n);
  11957. n -= nb;
  11958. if (n === 0) {
  11959. if (nb === str.length) {
  11960. ++c;
  11961. if (p.next) list.head = p.next;else list.head = list.tail = null;
  11962. } else {
  11963. list.head = p;
  11964. p.data = str.slice(nb);
  11965. }
  11966. break;
  11967. }
  11968. ++c;
  11969. }
  11970. list.length -= c;
  11971. return ret;
  11972. }
  11973. // Copies a specified amount of bytes from the list of buffered data chunks.
  11974. // This function is designed to be inlinable, so please take care when making
  11975. // changes to the function body.
  11976. function copyFromBuffer(n, list) {
  11977. var ret = bufferShim.allocUnsafe(n);
  11978. var p = list.head;
  11979. var c = 1;
  11980. p.data.copy(ret);
  11981. n -= p.data.length;
  11982. while (p = p.next) {
  11983. var buf = p.data;
  11984. var nb = n > buf.length ? buf.length : n;
  11985. buf.copy(ret, ret.length - n, 0, nb);
  11986. n -= nb;
  11987. if (n === 0) {
  11988. if (nb === buf.length) {
  11989. ++c;
  11990. if (p.next) list.head = p.next;else list.head = list.tail = null;
  11991. } else {
  11992. list.head = p;
  11993. p.data = buf.slice(nb);
  11994. }
  11995. break;
  11996. }
  11997. ++c;
  11998. }
  11999. list.length -= c;
  12000. return ret;
  12001. }
  12002. function endReadable(stream) {
  12003. var state = stream._readableState;
  12004. // If we get here before consuming all the bytes, then that is a
  12005. // bug in node. Should never happen.
  12006. if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
  12007. if (!state.endEmitted) {
  12008. state.ended = true;
  12009. processNextTick(endReadableNT, state, stream);
  12010. }
  12011. }
  12012. function endReadableNT(state, stream) {
  12013. // Check that we didn't get one last unshift.
  12014. if (!state.endEmitted && state.length === 0) {
  12015. state.endEmitted = true;
  12016. stream.readable = false;
  12017. stream.emit('end');
  12018. }
  12019. }
  12020. function forEach(xs, f) {
  12021. for (var i = 0, l = xs.length; i < l; i++) {
  12022. f(xs[i], i);
  12023. }
  12024. }
  12025. function indexOf(xs, x) {
  12026. for (var i = 0, l = xs.length; i < l; i++) {
  12027. if (xs[i] === x) return i;
  12028. }
  12029. return -1;
  12030. }
  12031. }).call(this,require('_process'))
  12032. },{"./_stream_duplex":69,"./internal/streams/BufferList":74,"_process":67,"buffer":44,"buffer-shims":43,"core-util-is":45,"events":48,"inherits":51,"isarray":53,"process-nextick-args":66,"string_decoder/":80,"util":40}],72:[function(require,module,exports){
  12033. // a transform stream is a readable/writable stream where you do
  12034. // something with the data. Sometimes it's called a "filter",
  12035. // but that's not a great name for it, since that implies a thing where
  12036. // some bits pass through, and others are simply ignored. (That would
  12037. // be a valid example of a transform, of course.)
  12038. //
  12039. // While the output is causally related to the input, it's not a
  12040. // necessarily symmetric or synchronous transformation. For example,
  12041. // a zlib stream might take multiple plain-text writes(), and then
  12042. // emit a single compressed chunk some time in the future.
  12043. //
  12044. // Here's how this works:
  12045. //
  12046. // The Transform stream has all the aspects of the readable and writable
  12047. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  12048. // internally, and returns false if there's a lot of pending writes
  12049. // buffered up. When you call read(), that calls _read(n) until
  12050. // there's enough pending readable data buffered up.
  12051. //
  12052. // In a transform stream, the written data is placed in a buffer. When
  12053. // _read(n) is called, it transforms the queued up data, calling the
  12054. // buffered _write cb's as it consumes chunks. If consuming a single
  12055. // written chunk would result in multiple output chunks, then the first
  12056. // outputted bit calls the readcb, and subsequent chunks just go into
  12057. // the read buffer, and will cause it to emit 'readable' if necessary.
  12058. //
  12059. // This way, back-pressure is actually determined by the reading side,
  12060. // since _read has to be called to start processing a new chunk. However,
  12061. // a pathological inflate type of transform can cause excessive buffering
  12062. // here. For example, imagine a stream where every byte of input is
  12063. // interpreted as an integer from 0-255, and then results in that many
  12064. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  12065. // 1kb of data being output. In this case, you could write a very small
  12066. // amount of input, and end up with a very large amount of output. In
  12067. // such a pathological inflating mechanism, there'd be no way to tell
  12068. // the system to stop doing the transform. A single 4MB write could
  12069. // cause the system to run out of memory.
  12070. //
  12071. // However, even in such a pathological case, only a single written chunk
  12072. // would be consumed, and then the rest would wait (un-transformed) until
  12073. // the results of the previous transformed chunk were consumed.
  12074. 'use strict';
  12075. module.exports = Transform;
  12076. var Duplex = require('./_stream_duplex');
  12077. /*<replacement>*/
  12078. var util = require('core-util-is');
  12079. util.inherits = require('inherits');
  12080. /*</replacement>*/
  12081. util.inherits(Transform, Duplex);
  12082. function TransformState(stream) {
  12083. this.afterTransform = function (er, data) {
  12084. return afterTransform(stream, er, data);
  12085. };
  12086. this.needTransform = false;
  12087. this.transforming = false;
  12088. this.writecb = null;
  12089. this.writechunk = null;
  12090. this.writeencoding = null;
  12091. }
  12092. function afterTransform(stream, er, data) {
  12093. var ts = stream._transformState;
  12094. ts.transforming = false;
  12095. var cb = ts.writecb;
  12096. if (!cb) return stream.emit('error', new Error('no writecb in Transform class'));
  12097. ts.writechunk = null;
  12098. ts.writecb = null;
  12099. if (data !== null && data !== undefined) stream.push(data);
  12100. cb(er);
  12101. var rs = stream._readableState;
  12102. rs.reading = false;
  12103. if (rs.needReadable || rs.length < rs.highWaterMark) {
  12104. stream._read(rs.highWaterMark);
  12105. }
  12106. }
  12107. function Transform(options) {
  12108. if (!(this instanceof Transform)) return new Transform(options);
  12109. Duplex.call(this, options);
  12110. this._transformState = new TransformState(this);
  12111. // when the writable side finishes, then flush out anything remaining.
  12112. var stream = this;
  12113. // start out asking for a readable event once data is transformed.
  12114. this._readableState.needReadable = true;
  12115. // we have implemented the _read method, and done the other things
  12116. // that Readable wants before the first _read call, so unset the
  12117. // sync guard flag.
  12118. this._readableState.sync = false;
  12119. if (options) {
  12120. if (typeof options.transform === 'function') this._transform = options.transform;
  12121. if (typeof options.flush === 'function') this._flush = options.flush;
  12122. }
  12123. this.once('prefinish', function () {
  12124. if (typeof this._flush === 'function') this._flush(function (er) {
  12125. done(stream, er);
  12126. });else done(stream);
  12127. });
  12128. }
  12129. Transform.prototype.push = function (chunk, encoding) {
  12130. this._transformState.needTransform = false;
  12131. return Duplex.prototype.push.call(this, chunk, encoding);
  12132. };
  12133. // This is the part where you do stuff!
  12134. // override this function in implementation classes.
  12135. // 'chunk' is an input chunk.
  12136. //
  12137. // Call `push(newChunk)` to pass along transformed output
  12138. // to the readable side. You may call 'push' zero or more times.
  12139. //
  12140. // Call `cb(err)` when you are done with this chunk. If you pass
  12141. // an error, then that'll put the hurt on the whole operation. If you
  12142. // never call cb(), then you'll never get another chunk.
  12143. Transform.prototype._transform = function (chunk, encoding, cb) {
  12144. throw new Error('Not implemented');
  12145. };
  12146. Transform.prototype._write = function (chunk, encoding, cb) {
  12147. var ts = this._transformState;
  12148. ts.writecb = cb;
  12149. ts.writechunk = chunk;
  12150. ts.writeencoding = encoding;
  12151. if (!ts.transforming) {
  12152. var rs = this._readableState;
  12153. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  12154. }
  12155. };
  12156. // Doesn't matter what the args are here.
  12157. // _transform does all the work.
  12158. // That we got here means that the readable side wants more data.
  12159. Transform.prototype._read = function (n) {
  12160. var ts = this._transformState;
  12161. if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
  12162. ts.transforming = true;
  12163. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  12164. } else {
  12165. // mark that we need a transform, so that any data that comes in
  12166. // will get processed, now that we've asked for it.
  12167. ts.needTransform = true;
  12168. }
  12169. };
  12170. function done(stream, er) {
  12171. if (er) return stream.emit('error', er);
  12172. // if there's nothing in the write buffer, then that means
  12173. // that nothing more will ever be provided
  12174. var ws = stream._writableState;
  12175. var ts = stream._transformState;
  12176. if (ws.length) throw new Error('Calling transform done when ws.length != 0');
  12177. if (ts.transforming) throw new Error('Calling transform done when still transforming');
  12178. return stream.push(null);
  12179. }
  12180. },{"./_stream_duplex":69,"core-util-is":45,"inherits":51}],73:[function(require,module,exports){
  12181. (function (process){
  12182. // A bit simpler than readable streams.
  12183. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  12184. // the drain event emission and buffering.
  12185. 'use strict';
  12186. module.exports = Writable;
  12187. /*<replacement>*/
  12188. var processNextTick = require('process-nextick-args');
  12189. /*</replacement>*/
  12190. /*<replacement>*/
  12191. var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick;
  12192. /*</replacement>*/
  12193. Writable.WritableState = WritableState;
  12194. /*<replacement>*/
  12195. var util = require('core-util-is');
  12196. util.inherits = require('inherits');
  12197. /*</replacement>*/
  12198. /*<replacement>*/
  12199. var internalUtil = {
  12200. deprecate: require('util-deprecate')
  12201. };
  12202. /*</replacement>*/
  12203. /*<replacement>*/
  12204. var Stream;
  12205. (function () {
  12206. try {
  12207. Stream = require('st' + 'ream');
  12208. } catch (_) {} finally {
  12209. if (!Stream) Stream = require('events').EventEmitter;
  12210. }
  12211. })();
  12212. /*</replacement>*/
  12213. var Buffer = require('buffer').Buffer;
  12214. /*<replacement>*/
  12215. var bufferShim = require('buffer-shims');
  12216. /*</replacement>*/
  12217. util.inherits(Writable, Stream);
  12218. function nop() {}
  12219. function WriteReq(chunk, encoding, cb) {
  12220. this.chunk = chunk;
  12221. this.encoding = encoding;
  12222. this.callback = cb;
  12223. this.next = null;
  12224. }
  12225. var Duplex;
  12226. function WritableState(options, stream) {
  12227. Duplex = Duplex || require('./_stream_duplex');
  12228. options = options || {};
  12229. // object stream flag to indicate whether or not this stream
  12230. // contains buffers or objects.
  12231. this.objectMode = !!options.objectMode;
  12232. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
  12233. // the point at which write() starts returning false
  12234. // Note: 0 is a valid value, means that we always return false if
  12235. // the entire buffer is not flushed immediately on write()
  12236. var hwm = options.highWaterMark;
  12237. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  12238. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  12239. // cast to ints.
  12240. this.highWaterMark = ~ ~this.highWaterMark;
  12241. this.needDrain = false;
  12242. // at the start of calling end()
  12243. this.ending = false;
  12244. // when end() has been called, and returned
  12245. this.ended = false;
  12246. // when 'finish' is emitted
  12247. this.finished = false;
  12248. // should we decode strings into buffers before passing to _write?
  12249. // this is here so that some node-core streams can optimize string
  12250. // handling at a lower level.
  12251. var noDecode = options.decodeStrings === false;
  12252. this.decodeStrings = !noDecode;
  12253. // Crypto is kind of old and crusty. Historically, its default string
  12254. // encoding is 'binary' so we have to make this configurable.
  12255. // Everything else in the universe uses 'utf8', though.
  12256. this.defaultEncoding = options.defaultEncoding || 'utf8';
  12257. // not an actual buffer we keep track of, but a measurement
  12258. // of how much we're waiting to get pushed to some underlying
  12259. // socket or file.
  12260. this.length = 0;
  12261. // a flag to see when we're in the middle of a write.
  12262. this.writing = false;
  12263. // when true all writes will be buffered until .uncork() call
  12264. this.corked = 0;
  12265. // a flag to be able to tell if the onwrite cb is called immediately,
  12266. // or on a later tick. We set this to true at first, because any
  12267. // actions that shouldn't happen until "later" should generally also
  12268. // not happen before the first write call.
  12269. this.sync = true;
  12270. // a flag to know if we're processing previously buffered items, which
  12271. // may call the _write() callback in the same tick, so that we don't
  12272. // end up in an overlapped onwrite situation.
  12273. this.bufferProcessing = false;
  12274. // the callback that's passed to _write(chunk,cb)
  12275. this.onwrite = function (er) {
  12276. onwrite(stream, er);
  12277. };
  12278. // the callback that the user supplies to write(chunk,encoding,cb)
  12279. this.writecb = null;
  12280. // the amount that is being written when _write is called.
  12281. this.writelen = 0;
  12282. this.bufferedRequest = null;
  12283. this.lastBufferedRequest = null;
  12284. // number of pending user-supplied write callbacks
  12285. // this must be 0 before 'finish' can be emitted
  12286. this.pendingcb = 0;
  12287. // emit prefinish if the only thing we're waiting for is _write cbs
  12288. // This is relevant for synchronous Transform streams
  12289. this.prefinished = false;
  12290. // True if the error was already emitted and should not be thrown again
  12291. this.errorEmitted = false;
  12292. // count buffered requests
  12293. this.bufferedRequestCount = 0;
  12294. // allocate the first CorkedRequest, there is always
  12295. // one allocated and free to use, and we maintain at most two
  12296. this.corkedRequestsFree = new CorkedRequest(this);
  12297. }
  12298. WritableState.prototype.getBuffer = function writableStateGetBuffer() {
  12299. var current = this.bufferedRequest;
  12300. var out = [];
  12301. while (current) {
  12302. out.push(current);
  12303. current = current.next;
  12304. }
  12305. return out;
  12306. };
  12307. (function () {
  12308. try {
  12309. Object.defineProperty(WritableState.prototype, 'buffer', {
  12310. get: internalUtil.deprecate(function () {
  12311. return this.getBuffer();
  12312. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
  12313. });
  12314. } catch (_) {}
  12315. })();
  12316. var Duplex;
  12317. function Writable(options) {
  12318. Duplex = Duplex || require('./_stream_duplex');
  12319. // Writable ctor is applied to Duplexes, though they're not
  12320. // instanceof Writable, they're instanceof Readable.
  12321. if (!(this instanceof Writable) && !(this instanceof Duplex)) return new Writable(options);
  12322. this._writableState = new WritableState(options, this);
  12323. // legacy.
  12324. this.writable = true;
  12325. if (options) {
  12326. if (typeof options.write === 'function') this._write = options.write;
  12327. if (typeof options.writev === 'function') this._writev = options.writev;
  12328. }
  12329. Stream.call(this);
  12330. }
  12331. // Otherwise people can pipe Writable streams, which is just wrong.
  12332. Writable.prototype.pipe = function () {
  12333. this.emit('error', new Error('Cannot pipe, not readable'));
  12334. };
  12335. function writeAfterEnd(stream, cb) {
  12336. var er = new Error('write after end');
  12337. // TODO: defer error events consistently everywhere, not just the cb
  12338. stream.emit('error', er);
  12339. processNextTick(cb, er);
  12340. }
  12341. // If we get something that is not a buffer, string, null, or undefined,
  12342. // and we're not in objectMode, then that's an error.
  12343. // Otherwise stream chunks are all considered to be of length=1, and the
  12344. // watermarks determine how many objects to keep in the buffer, rather than
  12345. // how many bytes or characters.
  12346. function validChunk(stream, state, chunk, cb) {
  12347. var valid = true;
  12348. var er = false;
  12349. // Always throw error if a null is written
  12350. // if we are not in object mode then throw
  12351. // if it is not a buffer, string, or undefined.
  12352. if (chunk === null) {
  12353. er = new TypeError('May not write null values to stream');
  12354. } else if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  12355. er = new TypeError('Invalid non-string/buffer chunk');
  12356. }
  12357. if (er) {
  12358. stream.emit('error', er);
  12359. processNextTick(cb, er);
  12360. valid = false;
  12361. }
  12362. return valid;
  12363. }
  12364. Writable.prototype.write = function (chunk, encoding, cb) {
  12365. var state = this._writableState;
  12366. var ret = false;
  12367. if (typeof encoding === 'function') {
  12368. cb = encoding;
  12369. encoding = null;
  12370. }
  12371. if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  12372. if (typeof cb !== 'function') cb = nop;
  12373. if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) {
  12374. state.pendingcb++;
  12375. ret = writeOrBuffer(this, state, chunk, encoding, cb);
  12376. }
  12377. return ret;
  12378. };
  12379. Writable.prototype.cork = function () {
  12380. var state = this._writableState;
  12381. state.corked++;
  12382. };
  12383. Writable.prototype.uncork = function () {
  12384. var state = this._writableState;
  12385. if (state.corked) {
  12386. state.corked--;
  12387. if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  12388. }
  12389. };
  12390. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  12391. // node::ParseEncoding() requires lower case.
  12392. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  12393. 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);
  12394. this._writableState.defaultEncoding = encoding;
  12395. return this;
  12396. };
  12397. function decodeChunk(state, chunk, encoding) {
  12398. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  12399. chunk = bufferShim.from(chunk, encoding);
  12400. }
  12401. return chunk;
  12402. }
  12403. // if we're already writing something, then just put this
  12404. // in the queue, and wait our turn. Otherwise, call _write
  12405. // If we return false, then we need a drain event, so set that flag.
  12406. function writeOrBuffer(stream, state, chunk, encoding, cb) {
  12407. chunk = decodeChunk(state, chunk, encoding);
  12408. if (Buffer.isBuffer(chunk)) encoding = 'buffer';
  12409. var len = state.objectMode ? 1 : chunk.length;
  12410. state.length += len;
  12411. var ret = state.length < state.highWaterMark;
  12412. // we must ensure that previous needDrain will not be reset to false.
  12413. if (!ret) state.needDrain = true;
  12414. if (state.writing || state.corked) {
  12415. var last = state.lastBufferedRequest;
  12416. state.lastBufferedRequest = new WriteReq(chunk, encoding, cb);
  12417. if (last) {
  12418. last.next = state.lastBufferedRequest;
  12419. } else {
  12420. state.bufferedRequest = state.lastBufferedRequest;
  12421. }
  12422. state.bufferedRequestCount += 1;
  12423. } else {
  12424. doWrite(stream, state, false, len, chunk, encoding, cb);
  12425. }
  12426. return ret;
  12427. }
  12428. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  12429. state.writelen = len;
  12430. state.writecb = cb;
  12431. state.writing = true;
  12432. state.sync = true;
  12433. if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  12434. state.sync = false;
  12435. }
  12436. function onwriteError(stream, state, sync, er, cb) {
  12437. --state.pendingcb;
  12438. if (sync) processNextTick(cb, er);else cb(er);
  12439. stream._writableState.errorEmitted = true;
  12440. stream.emit('error', er);
  12441. }
  12442. function onwriteStateUpdate(state) {
  12443. state.writing = false;
  12444. state.writecb = null;
  12445. state.length -= state.writelen;
  12446. state.writelen = 0;
  12447. }
  12448. function onwrite(stream, er) {
  12449. var state = stream._writableState;
  12450. var sync = state.sync;
  12451. var cb = state.writecb;
  12452. onwriteStateUpdate(state);
  12453. if (er) onwriteError(stream, state, sync, er, cb);else {
  12454. // Check if we're actually ready to finish, but don't emit yet
  12455. var finished = needFinish(state);
  12456. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  12457. clearBuffer(stream, state);
  12458. }
  12459. if (sync) {
  12460. /*<replacement>*/
  12461. asyncWrite(afterWrite, stream, state, finished, cb);
  12462. /*</replacement>*/
  12463. } else {
  12464. afterWrite(stream, state, finished, cb);
  12465. }
  12466. }
  12467. }
  12468. function afterWrite(stream, state, finished, cb) {
  12469. if (!finished) onwriteDrain(stream, state);
  12470. state.pendingcb--;
  12471. cb();
  12472. finishMaybe(stream, state);
  12473. }
  12474. // Must force callback to be called on nextTick, so that we don't
  12475. // emit 'drain' before the write() consumer gets the 'false' return
  12476. // value, and has a chance to attach a 'drain' listener.
  12477. function onwriteDrain(stream, state) {
  12478. if (state.length === 0 && state.needDrain) {
  12479. state.needDrain = false;
  12480. stream.emit('drain');
  12481. }
  12482. }
  12483. // if there's something in the buffer waiting, then process it
  12484. function clearBuffer(stream, state) {
  12485. state.bufferProcessing = true;
  12486. var entry = state.bufferedRequest;
  12487. if (stream._writev && entry && entry.next) {
  12488. // Fast case, write everything using _writev()
  12489. var l = state.bufferedRequestCount;
  12490. var buffer = new Array(l);
  12491. var holder = state.corkedRequestsFree;
  12492. holder.entry = entry;
  12493. var count = 0;
  12494. while (entry) {
  12495. buffer[count] = entry;
  12496. entry = entry.next;
  12497. count += 1;
  12498. }
  12499. doWrite(stream, state, true, state.length, buffer, '', holder.finish);
  12500. // doWrite is almost always async, defer these to save a bit of time
  12501. // as the hot path ends with doWrite
  12502. state.pendingcb++;
  12503. state.lastBufferedRequest = null;
  12504. if (holder.next) {
  12505. state.corkedRequestsFree = holder.next;
  12506. holder.next = null;
  12507. } else {
  12508. state.corkedRequestsFree = new CorkedRequest(state);
  12509. }
  12510. } else {
  12511. // Slow case, write chunks one-by-one
  12512. while (entry) {
  12513. var chunk = entry.chunk;
  12514. var encoding = entry.encoding;
  12515. var cb = entry.callback;
  12516. var len = state.objectMode ? 1 : chunk.length;
  12517. doWrite(stream, state, false, len, chunk, encoding, cb);
  12518. entry = entry.next;
  12519. // if we didn't call the onwrite immediately, then
  12520. // it means that we need to wait until it does.
  12521. // also, that means that the chunk and cb are currently
  12522. // being processed, so move the buffer counter past them.
  12523. if (state.writing) {
  12524. break;
  12525. }
  12526. }
  12527. if (entry === null) state.lastBufferedRequest = null;
  12528. }
  12529. state.bufferedRequestCount = 0;
  12530. state.bufferedRequest = entry;
  12531. state.bufferProcessing = false;
  12532. }
  12533. Writable.prototype._write = function (chunk, encoding, cb) {
  12534. cb(new Error('not implemented'));
  12535. };
  12536. Writable.prototype._writev = null;
  12537. Writable.prototype.end = function (chunk, encoding, cb) {
  12538. var state = this._writableState;
  12539. if (typeof chunk === 'function') {
  12540. cb = chunk;
  12541. chunk = null;
  12542. encoding = null;
  12543. } else if (typeof encoding === 'function') {
  12544. cb = encoding;
  12545. encoding = null;
  12546. }
  12547. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
  12548. // .end() fully uncorks
  12549. if (state.corked) {
  12550. state.corked = 1;
  12551. this.uncork();
  12552. }
  12553. // ignore unnecessary end() calls.
  12554. if (!state.ending && !state.finished) endWritable(this, state, cb);
  12555. };
  12556. function needFinish(state) {
  12557. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  12558. }
  12559. function prefinish(stream, state) {
  12560. if (!state.prefinished) {
  12561. state.prefinished = true;
  12562. stream.emit('prefinish');
  12563. }
  12564. }
  12565. function finishMaybe(stream, state) {
  12566. var need = needFinish(state);
  12567. if (need) {
  12568. if (state.pendingcb === 0) {
  12569. prefinish(stream, state);
  12570. state.finished = true;
  12571. stream.emit('finish');
  12572. } else {
  12573. prefinish(stream, state);
  12574. }
  12575. }
  12576. return need;
  12577. }
  12578. function endWritable(stream, state, cb) {
  12579. state.ending = true;
  12580. finishMaybe(stream, state);
  12581. if (cb) {
  12582. if (state.finished) processNextTick(cb);else stream.once('finish', cb);
  12583. }
  12584. state.ended = true;
  12585. stream.writable = false;
  12586. }
  12587. // It seems a linked list but it is not
  12588. // there will be only 2 of these for each stream
  12589. function CorkedRequest(state) {
  12590. var _this = this;
  12591. this.next = null;
  12592. this.entry = null;
  12593. this.finish = function (err) {
  12594. var entry = _this.entry;
  12595. _this.entry = null;
  12596. while (entry) {
  12597. var cb = entry.callback;
  12598. state.pendingcb--;
  12599. cb(err);
  12600. entry = entry.next;
  12601. }
  12602. if (state.corkedRequestsFree) {
  12603. state.corkedRequestsFree.next = _this;
  12604. } else {
  12605. state.corkedRequestsFree = _this;
  12606. }
  12607. };
  12608. }
  12609. }).call(this,require('_process'))
  12610. },{"./_stream_duplex":69,"_process":67,"buffer":44,"buffer-shims":43,"core-util-is":45,"events":48,"inherits":51,"process-nextick-args":66,"util-deprecate":81}],74:[function(require,module,exports){
  12611. 'use strict';
  12612. var Buffer = require('buffer').Buffer;
  12613. /*<replacement>*/
  12614. var bufferShim = require('buffer-shims');
  12615. /*</replacement>*/
  12616. module.exports = BufferList;
  12617. function BufferList() {
  12618. this.head = null;
  12619. this.tail = null;
  12620. this.length = 0;
  12621. }
  12622. BufferList.prototype.push = function (v) {
  12623. var entry = { data: v, next: null };
  12624. if (this.length > 0) this.tail.next = entry;else this.head = entry;
  12625. this.tail = entry;
  12626. ++this.length;
  12627. };
  12628. BufferList.prototype.unshift = function (v) {
  12629. var entry = { data: v, next: this.head };
  12630. if (this.length === 0) this.tail = entry;
  12631. this.head = entry;
  12632. ++this.length;
  12633. };
  12634. BufferList.prototype.shift = function () {
  12635. if (this.length === 0) return;
  12636. var ret = this.head.data;
  12637. if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
  12638. --this.length;
  12639. return ret;
  12640. };
  12641. BufferList.prototype.clear = function () {
  12642. this.head = this.tail = null;
  12643. this.length = 0;
  12644. };
  12645. BufferList.prototype.join = function (s) {
  12646. if (this.length === 0) return '';
  12647. var p = this.head;
  12648. var ret = '' + p.data;
  12649. while (p = p.next) {
  12650. ret += s + p.data;
  12651. }return ret;
  12652. };
  12653. BufferList.prototype.concat = function (n) {
  12654. if (this.length === 0) return bufferShim.alloc(0);
  12655. if (this.length === 1) return this.head.data;
  12656. var ret = bufferShim.allocUnsafe(n >>> 0);
  12657. var p = this.head;
  12658. var i = 0;
  12659. while (p) {
  12660. p.data.copy(ret, i);
  12661. i += p.data.length;
  12662. p = p.next;
  12663. }
  12664. return ret;
  12665. };
  12666. },{"buffer":44,"buffer-shims":43}],75:[function(require,module,exports){
  12667. module.exports = require("./lib/_stream_passthrough.js")
  12668. },{"./lib/_stream_passthrough.js":70}],76:[function(require,module,exports){
  12669. (function (process){
  12670. var Stream = (function (){
  12671. try {
  12672. return require('st' + 'ream'); // hack to fix a circular dependency issue when used with browserify
  12673. } catch(_){}
  12674. }());
  12675. exports = module.exports = require('./lib/_stream_readable.js');
  12676. exports.Stream = Stream || exports;
  12677. exports.Readable = exports;
  12678. exports.Writable = require('./lib/_stream_writable.js');
  12679. exports.Duplex = require('./lib/_stream_duplex.js');
  12680. exports.Transform = require('./lib/_stream_transform.js');
  12681. exports.PassThrough = require('./lib/_stream_passthrough.js');
  12682. if (!process.browser && process.env.READABLE_STREAM === 'disable' && Stream) {
  12683. module.exports = Stream;
  12684. }
  12685. }).call(this,require('_process'))
  12686. },{"./lib/_stream_duplex.js":69,"./lib/_stream_passthrough.js":70,"./lib/_stream_readable.js":71,"./lib/_stream_transform.js":72,"./lib/_stream_writable.js":73,"_process":67}],77:[function(require,module,exports){
  12687. module.exports = require("./lib/_stream_transform.js")
  12688. },{"./lib/_stream_transform.js":72}],78:[function(require,module,exports){
  12689. module.exports = require("./lib/_stream_writable.js")
  12690. },{"./lib/_stream_writable.js":73}],79:[function(require,module,exports){
  12691. // Copyright Joyent, Inc. and other Node contributors.
  12692. //
  12693. // Permission is hereby granted, free of charge, to any person obtaining a
  12694. // copy of this software and associated documentation files (the
  12695. // "Software"), to deal in the Software without restriction, including
  12696. // without limitation the rights to use, copy, modify, merge, publish,
  12697. // distribute, sublicense, and/or sell copies of the Software, and to permit
  12698. // persons to whom the Software is furnished to do so, subject to the
  12699. // following conditions:
  12700. //
  12701. // The above copyright notice and this permission notice shall be included
  12702. // in all copies or substantial portions of the Software.
  12703. //
  12704. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  12705. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12706. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  12707. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  12708. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  12709. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  12710. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  12711. module.exports = Stream;
  12712. var EE = require('events').EventEmitter;
  12713. var inherits = require('inherits');
  12714. inherits(Stream, EE);
  12715. Stream.Readable = require('readable-stream/readable.js');
  12716. Stream.Writable = require('readable-stream/writable.js');
  12717. Stream.Duplex = require('readable-stream/duplex.js');
  12718. Stream.Transform = require('readable-stream/transform.js');
  12719. Stream.PassThrough = require('readable-stream/passthrough.js');
  12720. // Backwards-compat with node 0.4.x
  12721. Stream.Stream = Stream;
  12722. // old-style streams. Note that the pipe method (the only relevant
  12723. // part of this class) is overridden in the Readable class.
  12724. function Stream() {
  12725. EE.call(this);
  12726. }
  12727. Stream.prototype.pipe = function(dest, options) {
  12728. var source = this;
  12729. function ondata(chunk) {
  12730. if (dest.writable) {
  12731. if (false === dest.write(chunk) && source.pause) {
  12732. source.pause();
  12733. }
  12734. }
  12735. }
  12736. source.on('data', ondata);
  12737. function ondrain() {
  12738. if (source.readable && source.resume) {
  12739. source.resume();
  12740. }
  12741. }
  12742. dest.on('drain', ondrain);
  12743. // If the 'end' option is not supplied, dest.end() will be called when
  12744. // source gets the 'end' or 'close' events. Only dest.end() once.
  12745. if (!dest._isStdio && (!options || options.end !== false)) {
  12746. source.on('end', onend);
  12747. source.on('close', onclose);
  12748. }
  12749. var didOnEnd = false;
  12750. function onend() {
  12751. if (didOnEnd) return;
  12752. didOnEnd = true;
  12753. dest.end();
  12754. }
  12755. function onclose() {
  12756. if (didOnEnd) return;
  12757. didOnEnd = true;
  12758. if (typeof dest.destroy === 'function') dest.destroy();
  12759. }
  12760. // don't leave dangling pipes when there are errors.
  12761. function onerror(er) {
  12762. cleanup();
  12763. if (EE.listenerCount(this, 'error') === 0) {
  12764. throw er; // Unhandled stream error in pipe.
  12765. }
  12766. }
  12767. source.on('error', onerror);
  12768. dest.on('error', onerror);
  12769. // remove all the event listeners that were added.
  12770. function cleanup() {
  12771. source.removeListener('data', ondata);
  12772. dest.removeListener('drain', ondrain);
  12773. source.removeListener('end', onend);
  12774. source.removeListener('close', onclose);
  12775. source.removeListener('error', onerror);
  12776. dest.removeListener('error', onerror);
  12777. source.removeListener('end', cleanup);
  12778. source.removeListener('close', cleanup);
  12779. dest.removeListener('close', cleanup);
  12780. }
  12781. source.on('end', cleanup);
  12782. source.on('close', cleanup);
  12783. dest.on('close', cleanup);
  12784. dest.emit('pipe', source);
  12785. // Allow for unix-like usage: A.pipe(B).pipe(C)
  12786. return dest;
  12787. };
  12788. },{"events":48,"inherits":51,"readable-stream/duplex.js":68,"readable-stream/passthrough.js":75,"readable-stream/readable.js":76,"readable-stream/transform.js":77,"readable-stream/writable.js":78}],80:[function(require,module,exports){
  12789. // Copyright Joyent, Inc. and other Node contributors.
  12790. //
  12791. // Permission is hereby granted, free of charge, to any person obtaining a
  12792. // copy of this software and associated documentation files (the
  12793. // "Software"), to deal in the Software without restriction, including
  12794. // without limitation the rights to use, copy, modify, merge, publish,
  12795. // distribute, sublicense, and/or sell copies of the Software, and to permit
  12796. // persons to whom the Software is furnished to do so, subject to the
  12797. // following conditions:
  12798. //
  12799. // The above copyright notice and this permission notice shall be included
  12800. // in all copies or substantial portions of the Software.
  12801. //
  12802. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  12803. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12804. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  12805. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  12806. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  12807. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  12808. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  12809. var Buffer = require('buffer').Buffer;
  12810. var isBufferEncoding = Buffer.isEncoding
  12811. || function(encoding) {
  12812. switch (encoding && encoding.toLowerCase()) {
  12813. 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;
  12814. default: return false;
  12815. }
  12816. }
  12817. function assertEncoding(encoding) {
  12818. if (encoding && !isBufferEncoding(encoding)) {
  12819. throw new Error('Unknown encoding: ' + encoding);
  12820. }
  12821. }
  12822. // StringDecoder provides an interface for efficiently splitting a series of
  12823. // buffers into a series of JS strings without breaking apart multi-byte
  12824. // characters. CESU-8 is handled as part of the UTF-8 encoding.
  12825. //
  12826. // @TODO Handling all encodings inside a single object makes it very difficult
  12827. // to reason about this code, so it should be split up in the future.
  12828. // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
  12829. // points as used by CESU-8.
  12830. var StringDecoder = exports.StringDecoder = function(encoding) {
  12831. this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
  12832. assertEncoding(encoding);
  12833. switch (this.encoding) {
  12834. case 'utf8':
  12835. // CESU-8 represents each of Surrogate Pair by 3-bytes
  12836. this.surrogateSize = 3;
  12837. break;
  12838. case 'ucs2':
  12839. case 'utf16le':
  12840. // UTF-16 represents each of Surrogate Pair by 2-bytes
  12841. this.surrogateSize = 2;
  12842. this.detectIncompleteChar = utf16DetectIncompleteChar;
  12843. break;
  12844. case 'base64':
  12845. // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
  12846. this.surrogateSize = 3;
  12847. this.detectIncompleteChar = base64DetectIncompleteChar;
  12848. break;
  12849. default:
  12850. this.write = passThroughWrite;
  12851. return;
  12852. }
  12853. // Enough space to store all bytes of a single character. UTF-8 needs 4
  12854. // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
  12855. this.charBuffer = new Buffer(6);
  12856. // Number of bytes received for the current incomplete multi-byte character.
  12857. this.charReceived = 0;
  12858. // Number of bytes expected for the current incomplete multi-byte character.
  12859. this.charLength = 0;
  12860. };
  12861. // write decodes the given buffer and returns it as JS string that is
  12862. // guaranteed to not contain any partial multi-byte characters. Any partial
  12863. // character found at the end of the buffer is buffered up, and will be
  12864. // returned when calling write again with the remaining bytes.
  12865. //
  12866. // Note: Converting a Buffer containing an orphan surrogate to a String
  12867. // currently works, but converting a String to a Buffer (via `new Buffer`, or
  12868. // Buffer#write) will replace incomplete surrogates with the unicode
  12869. // replacement character. See https://codereview.chromium.org/121173009/ .
  12870. StringDecoder.prototype.write = function(buffer) {
  12871. var charStr = '';
  12872. // if our last write ended with an incomplete multibyte character
  12873. while (this.charLength) {
  12874. // determine how many remaining bytes this buffer has to offer for this char
  12875. var available = (buffer.length >= this.charLength - this.charReceived) ?
  12876. this.charLength - this.charReceived :
  12877. buffer.length;
  12878. // add the new bytes to the char buffer
  12879. buffer.copy(this.charBuffer, this.charReceived, 0, available);
  12880. this.charReceived += available;
  12881. if (this.charReceived < this.charLength) {
  12882. // still not enough chars in this buffer? wait for more ...
  12883. return '';
  12884. }
  12885. // remove bytes belonging to the current character from the buffer
  12886. buffer = buffer.slice(available, buffer.length);
  12887. // get the character that was split
  12888. charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
  12889. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  12890. var charCode = charStr.charCodeAt(charStr.length - 1);
  12891. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  12892. this.charLength += this.surrogateSize;
  12893. charStr = '';
  12894. continue;
  12895. }
  12896. this.charReceived = this.charLength = 0;
  12897. // if there are no more bytes in this buffer, just emit our char
  12898. if (buffer.length === 0) {
  12899. return charStr;
  12900. }
  12901. break;
  12902. }
  12903. // determine and set charLength / charReceived
  12904. this.detectIncompleteChar(buffer);
  12905. var end = buffer.length;
  12906. if (this.charLength) {
  12907. // buffer the incomplete character bytes we got
  12908. buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
  12909. end -= this.charReceived;
  12910. }
  12911. charStr += buffer.toString(this.encoding, 0, end);
  12912. var end = charStr.length - 1;
  12913. var charCode = charStr.charCodeAt(end);
  12914. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  12915. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  12916. var size = this.surrogateSize;
  12917. this.charLength += size;
  12918. this.charReceived += size;
  12919. this.charBuffer.copy(this.charBuffer, size, 0, size);
  12920. buffer.copy(this.charBuffer, 0, 0, size);
  12921. return charStr.substring(0, end);
  12922. }
  12923. // or just emit the charStr
  12924. return charStr;
  12925. };
  12926. // detectIncompleteChar determines if there is an incomplete UTF-8 character at
  12927. // the end of the given buffer. If so, it sets this.charLength to the byte
  12928. // length that character, and sets this.charReceived to the number of bytes
  12929. // that are available for this character.
  12930. StringDecoder.prototype.detectIncompleteChar = function(buffer) {
  12931. // determine how many bytes we have to check at the end of this buffer
  12932. var i = (buffer.length >= 3) ? 3 : buffer.length;
  12933. // Figure out if one of the last i bytes of our buffer announces an
  12934. // incomplete char.
  12935. for (; i > 0; i--) {
  12936. var c = buffer[buffer.length - i];
  12937. // See http://en.wikipedia.org/wiki/UTF-8#Description
  12938. // 110XXXXX
  12939. if (i == 1 && c >> 5 == 0x06) {
  12940. this.charLength = 2;
  12941. break;
  12942. }
  12943. // 1110XXXX
  12944. if (i <= 2 && c >> 4 == 0x0E) {
  12945. this.charLength = 3;
  12946. break;
  12947. }
  12948. // 11110XXX
  12949. if (i <= 3 && c >> 3 == 0x1E) {
  12950. this.charLength = 4;
  12951. break;
  12952. }
  12953. }
  12954. this.charReceived = i;
  12955. };
  12956. StringDecoder.prototype.end = function(buffer) {
  12957. var res = '';
  12958. if (buffer && buffer.length)
  12959. res = this.write(buffer);
  12960. if (this.charReceived) {
  12961. var cr = this.charReceived;
  12962. var buf = this.charBuffer;
  12963. var enc = this.encoding;
  12964. res += buf.slice(0, cr).toString(enc);
  12965. }
  12966. return res;
  12967. };
  12968. function passThroughWrite(buffer) {
  12969. return buffer.toString(this.encoding);
  12970. }
  12971. function utf16DetectIncompleteChar(buffer) {
  12972. this.charReceived = buffer.length % 2;
  12973. this.charLength = this.charReceived ? 2 : 0;
  12974. }
  12975. function base64DetectIncompleteChar(buffer) {
  12976. this.charReceived = buffer.length % 3;
  12977. this.charLength = this.charReceived ? 3 : 0;
  12978. }
  12979. },{"buffer":44}],81:[function(require,module,exports){
  12980. (function (global){
  12981. /**
  12982. * Module exports.
  12983. */
  12984. module.exports = deprecate;
  12985. /**
  12986. * Mark that a method should not be used.
  12987. * Returns a modified function which warns once by default.
  12988. *
  12989. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  12990. *
  12991. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  12992. * will throw an Error when invoked.
  12993. *
  12994. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  12995. * will invoke `console.trace()` instead of `console.error()`.
  12996. *
  12997. * @param {Function} fn - the function to deprecate
  12998. * @param {String} msg - the string to print to the console when `fn` is invoked
  12999. * @returns {Function} a new "deprecated" version of `fn`
  13000. * @api public
  13001. */
  13002. function deprecate (fn, msg) {
  13003. if (config('noDeprecation')) {
  13004. return fn;
  13005. }
  13006. var warned = false;
  13007. function deprecated() {
  13008. if (!warned) {
  13009. if (config('throwDeprecation')) {
  13010. throw new Error(msg);
  13011. } else if (config('traceDeprecation')) {
  13012. console.trace(msg);
  13013. } else {
  13014. console.warn(msg);
  13015. }
  13016. warned = true;
  13017. }
  13018. return fn.apply(this, arguments);
  13019. }
  13020. return deprecated;
  13021. }
  13022. /**
  13023. * Checks `localStorage` for boolean values for the given `name`.
  13024. *
  13025. * @param {String} name
  13026. * @returns {Boolean}
  13027. * @api private
  13028. */
  13029. function config (name) {
  13030. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  13031. try {
  13032. if (!global.localStorage) return false;
  13033. } catch (_) {
  13034. return false;
  13035. }
  13036. var val = global.localStorage[name];
  13037. if (null == val) return false;
  13038. return String(val).toLowerCase() === 'true';
  13039. }
  13040. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  13041. },{}],82:[function(require,module,exports){
  13042. arguments[4][51][0].apply(exports,arguments)
  13043. },{"dup":51}],83:[function(require,module,exports){
  13044. module.exports = function isBuffer(arg) {
  13045. return arg && typeof arg === 'object'
  13046. && typeof arg.copy === 'function'
  13047. && typeof arg.fill === 'function'
  13048. && typeof arg.readUInt8 === 'function';
  13049. }
  13050. },{}],84:[function(require,module,exports){
  13051. (function (process,global){
  13052. // Copyright Joyent, Inc. and other Node contributors.
  13053. //
  13054. // Permission is hereby granted, free of charge, to any person obtaining a
  13055. // copy of this software and associated documentation files (the
  13056. // "Software"), to deal in the Software without restriction, including
  13057. // without limitation the rights to use, copy, modify, merge, publish,
  13058. // distribute, sublicense, and/or sell copies of the Software, and to permit
  13059. // persons to whom the Software is furnished to do so, subject to the
  13060. // following conditions:
  13061. //
  13062. // The above copyright notice and this permission notice shall be included
  13063. // in all copies or substantial portions of the Software.
  13064. //
  13065. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13066. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13067. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  13068. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  13069. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  13070. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  13071. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  13072. var formatRegExp = /%[sdj%]/g;
  13073. exports.format = function(f) {
  13074. if (!isString(f)) {
  13075. var objects = [];
  13076. for (var i = 0; i < arguments.length; i++) {
  13077. objects.push(inspect(arguments[i]));
  13078. }
  13079. return objects.join(' ');
  13080. }
  13081. var i = 1;
  13082. var args = arguments;
  13083. var len = args.length;
  13084. var str = String(f).replace(formatRegExp, function(x) {
  13085. if (x === '%%') return '%';
  13086. if (i >= len) return x;
  13087. switch (x) {
  13088. case '%s': return String(args[i++]);
  13089. case '%d': return Number(args[i++]);
  13090. case '%j':
  13091. try {
  13092. return JSON.stringify(args[i++]);
  13093. } catch (_) {
  13094. return '[Circular]';
  13095. }
  13096. default:
  13097. return x;
  13098. }
  13099. });
  13100. for (var x = args[i]; i < len; x = args[++i]) {
  13101. if (isNull(x) || !isObject(x)) {
  13102. str += ' ' + x;
  13103. } else {
  13104. str += ' ' + inspect(x);
  13105. }
  13106. }
  13107. return str;
  13108. };
  13109. // Mark that a method should not be used.
  13110. // Returns a modified function which warns once by default.
  13111. // If --no-deprecation is set, then it is a no-op.
  13112. exports.deprecate = function(fn, msg) {
  13113. // Allow for deprecating things in the process of starting up.
  13114. if (isUndefined(global.process)) {
  13115. return function() {
  13116. return exports.deprecate(fn, msg).apply(this, arguments);
  13117. };
  13118. }
  13119. if (process.noDeprecation === true) {
  13120. return fn;
  13121. }
  13122. var warned = false;
  13123. function deprecated() {
  13124. if (!warned) {
  13125. if (process.throwDeprecation) {
  13126. throw new Error(msg);
  13127. } else if (process.traceDeprecation) {
  13128. console.trace(msg);
  13129. } else {
  13130. console.error(msg);
  13131. }
  13132. warned = true;
  13133. }
  13134. return fn.apply(this, arguments);
  13135. }
  13136. return deprecated;
  13137. };
  13138. var debugs = {};
  13139. var debugEnviron;
  13140. exports.debuglog = function(set) {
  13141. if (isUndefined(debugEnviron))
  13142. debugEnviron = process.env.NODE_DEBUG || '';
  13143. set = set.toUpperCase();
  13144. if (!debugs[set]) {
  13145. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  13146. var pid = process.pid;
  13147. debugs[set] = function() {
  13148. var msg = exports.format.apply(exports, arguments);
  13149. console.error('%s %d: %s', set, pid, msg);
  13150. };
  13151. } else {
  13152. debugs[set] = function() {};
  13153. }
  13154. }
  13155. return debugs[set];
  13156. };
  13157. /**
  13158. * Echos the value of a value. Trys to print the value out
  13159. * in the best way possible given the different types.
  13160. *
  13161. * @param {Object} obj The object to print out.
  13162. * @param {Object} opts Optional options object that alters the output.
  13163. */
  13164. /* legacy: obj, showHidden, depth, colors*/
  13165. function inspect(obj, opts) {
  13166. // default options
  13167. var ctx = {
  13168. seen: [],
  13169. stylize: stylizeNoColor
  13170. };
  13171. // legacy...
  13172. if (arguments.length >= 3) ctx.depth = arguments[2];
  13173. if (arguments.length >= 4) ctx.colors = arguments[3];
  13174. if (isBoolean(opts)) {
  13175. // legacy...
  13176. ctx.showHidden = opts;
  13177. } else if (opts) {
  13178. // got an "options" object
  13179. exports._extend(ctx, opts);
  13180. }
  13181. // set default options
  13182. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  13183. if (isUndefined(ctx.depth)) ctx.depth = 2;
  13184. if (isUndefined(ctx.colors)) ctx.colors = false;
  13185. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  13186. if (ctx.colors) ctx.stylize = stylizeWithColor;
  13187. return formatValue(ctx, obj, ctx.depth);
  13188. }
  13189. exports.inspect = inspect;
  13190. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  13191. inspect.colors = {
  13192. 'bold' : [1, 22],
  13193. 'italic' : [3, 23],
  13194. 'underline' : [4, 24],
  13195. 'inverse' : [7, 27],
  13196. 'white' : [37, 39],
  13197. 'grey' : [90, 39],
  13198. 'black' : [30, 39],
  13199. 'blue' : [34, 39],
  13200. 'cyan' : [36, 39],
  13201. 'green' : [32, 39],
  13202. 'magenta' : [35, 39],
  13203. 'red' : [31, 39],
  13204. 'yellow' : [33, 39]
  13205. };
  13206. // Don't use 'blue' not visible on cmd.exe
  13207. inspect.styles = {
  13208. 'special': 'cyan',
  13209. 'number': 'yellow',
  13210. 'boolean': 'yellow',
  13211. 'undefined': 'grey',
  13212. 'null': 'bold',
  13213. 'string': 'green',
  13214. 'date': 'magenta',
  13215. // "name": intentionally not styling
  13216. 'regexp': 'red'
  13217. };
  13218. function stylizeWithColor(str, styleType) {
  13219. var style = inspect.styles[styleType];
  13220. if (style) {
  13221. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  13222. '\u001b[' + inspect.colors[style][1] + 'm';
  13223. } else {
  13224. return str;
  13225. }
  13226. }
  13227. function stylizeNoColor(str, styleType) {
  13228. return str;
  13229. }
  13230. function arrayToHash(array) {
  13231. var hash = {};
  13232. array.forEach(function(val, idx) {
  13233. hash[val] = true;
  13234. });
  13235. return hash;
  13236. }
  13237. function formatValue(ctx, value, recurseTimes) {
  13238. // Provide a hook for user-specified inspect functions.
  13239. // Check that value is an object with an inspect function on it
  13240. if (ctx.customInspect &&
  13241. value &&
  13242. isFunction(value.inspect) &&
  13243. // Filter out the util module, it's inspect function is special
  13244. value.inspect !== exports.inspect &&
  13245. // Also filter out any prototype objects using the circular check.
  13246. !(value.constructor && value.constructor.prototype === value)) {
  13247. var ret = value.inspect(recurseTimes, ctx);
  13248. if (!isString(ret)) {
  13249. ret = formatValue(ctx, ret, recurseTimes);
  13250. }
  13251. return ret;
  13252. }
  13253. // Primitive types cannot have properties
  13254. var primitive = formatPrimitive(ctx, value);
  13255. if (primitive) {
  13256. return primitive;
  13257. }
  13258. // Look up the keys of the object.
  13259. var keys = Object.keys(value);
  13260. var visibleKeys = arrayToHash(keys);
  13261. if (ctx.showHidden) {
  13262. keys = Object.getOwnPropertyNames(value);
  13263. }
  13264. // IE doesn't make error fields non-enumerable
  13265. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  13266. if (isError(value)
  13267. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  13268. return formatError(value);
  13269. }
  13270. // Some type of object without properties can be shortcutted.
  13271. if (keys.length === 0) {
  13272. if (isFunction(value)) {
  13273. var name = value.name ? ': ' + value.name : '';
  13274. return ctx.stylize('[Function' + name + ']', 'special');
  13275. }
  13276. if (isRegExp(value)) {
  13277. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  13278. }
  13279. if (isDate(value)) {
  13280. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  13281. }
  13282. if (isError(value)) {
  13283. return formatError(value);
  13284. }
  13285. }
  13286. var base = '', array = false, braces = ['{', '}'];
  13287. // Make Array say that they are Array
  13288. if (isArray(value)) {
  13289. array = true;
  13290. braces = ['[', ']'];
  13291. }
  13292. // Make functions say that they are functions
  13293. if (isFunction(value)) {
  13294. var n = value.name ? ': ' + value.name : '';
  13295. base = ' [Function' + n + ']';
  13296. }
  13297. // Make RegExps say that they are RegExps
  13298. if (isRegExp(value)) {
  13299. base = ' ' + RegExp.prototype.toString.call(value);
  13300. }
  13301. // Make dates with properties first say the date
  13302. if (isDate(value)) {
  13303. base = ' ' + Date.prototype.toUTCString.call(value);
  13304. }
  13305. // Make error with message first say the error
  13306. if (isError(value)) {
  13307. base = ' ' + formatError(value);
  13308. }
  13309. if (keys.length === 0 && (!array || value.length == 0)) {
  13310. return braces[0] + base + braces[1];
  13311. }
  13312. if (recurseTimes < 0) {
  13313. if (isRegExp(value)) {
  13314. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  13315. } else {
  13316. return ctx.stylize('[Object]', 'special');
  13317. }
  13318. }
  13319. ctx.seen.push(value);
  13320. var output;
  13321. if (array) {
  13322. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  13323. } else {
  13324. output = keys.map(function(key) {
  13325. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  13326. });
  13327. }
  13328. ctx.seen.pop();
  13329. return reduceToSingleString(output, base, braces);
  13330. }
  13331. function formatPrimitive(ctx, value) {
  13332. if (isUndefined(value))
  13333. return ctx.stylize('undefined', 'undefined');
  13334. if (isString(value)) {
  13335. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  13336. .replace(/'/g, "\\'")
  13337. .replace(/\\"/g, '"') + '\'';
  13338. return ctx.stylize(simple, 'string');
  13339. }
  13340. if (isNumber(value))
  13341. return ctx.stylize('' + value, 'number');
  13342. if (isBoolean(value))
  13343. return ctx.stylize('' + value, 'boolean');
  13344. // For some reason typeof null is "object", so special case here.
  13345. if (isNull(value))
  13346. return ctx.stylize('null', 'null');
  13347. }
  13348. function formatError(value) {
  13349. return '[' + Error.prototype.toString.call(value) + ']';
  13350. }
  13351. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  13352. var output = [];
  13353. for (var i = 0, l = value.length; i < l; ++i) {
  13354. if (hasOwnProperty(value, String(i))) {
  13355. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  13356. String(i), true));
  13357. } else {
  13358. output.push('');
  13359. }
  13360. }
  13361. keys.forEach(function(key) {
  13362. if (!key.match(/^\d+$/)) {
  13363. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  13364. key, true));
  13365. }
  13366. });
  13367. return output;
  13368. }
  13369. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  13370. var name, str, desc;
  13371. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  13372. if (desc.get) {
  13373. if (desc.set) {
  13374. str = ctx.stylize('[Getter/Setter]', 'special');
  13375. } else {
  13376. str = ctx.stylize('[Getter]', 'special');
  13377. }
  13378. } else {
  13379. if (desc.set) {
  13380. str = ctx.stylize('[Setter]', 'special');
  13381. }
  13382. }
  13383. if (!hasOwnProperty(visibleKeys, key)) {
  13384. name = '[' + key + ']';
  13385. }
  13386. if (!str) {
  13387. if (ctx.seen.indexOf(desc.value) < 0) {
  13388. if (isNull(recurseTimes)) {
  13389. str = formatValue(ctx, desc.value, null);
  13390. } else {
  13391. str = formatValue(ctx, desc.value, recurseTimes - 1);
  13392. }
  13393. if (str.indexOf('\n') > -1) {
  13394. if (array) {
  13395. str = str.split('\n').map(function(line) {
  13396. return ' ' + line;
  13397. }).join('\n').substr(2);
  13398. } else {
  13399. str = '\n' + str.split('\n').map(function(line) {
  13400. return ' ' + line;
  13401. }).join('\n');
  13402. }
  13403. }
  13404. } else {
  13405. str = ctx.stylize('[Circular]', 'special');
  13406. }
  13407. }
  13408. if (isUndefined(name)) {
  13409. if (array && key.match(/^\d+$/)) {
  13410. return str;
  13411. }
  13412. name = JSON.stringify('' + key);
  13413. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  13414. name = name.substr(1, name.length - 2);
  13415. name = ctx.stylize(name, 'name');
  13416. } else {
  13417. name = name.replace(/'/g, "\\'")
  13418. .replace(/\\"/g, '"')
  13419. .replace(/(^"|"$)/g, "'");
  13420. name = ctx.stylize(name, 'string');
  13421. }
  13422. }
  13423. return name + ': ' + str;
  13424. }
  13425. function reduceToSingleString(output, base, braces) {
  13426. var numLinesEst = 0;
  13427. var length = output.reduce(function(prev, cur) {
  13428. numLinesEst++;
  13429. if (cur.indexOf('\n') >= 0) numLinesEst++;
  13430. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  13431. }, 0);
  13432. if (length > 60) {
  13433. return braces[0] +
  13434. (base === '' ? '' : base + '\n ') +
  13435. ' ' +
  13436. output.join(',\n ') +
  13437. ' ' +
  13438. braces[1];
  13439. }
  13440. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  13441. }
  13442. // NOTE: These type checking functions intentionally don't use `instanceof`
  13443. // because it is fragile and can be easily faked with `Object.create()`.
  13444. function isArray(ar) {
  13445. return Array.isArray(ar);
  13446. }
  13447. exports.isArray = isArray;
  13448. function isBoolean(arg) {
  13449. return typeof arg === 'boolean';
  13450. }
  13451. exports.isBoolean = isBoolean;
  13452. function isNull(arg) {
  13453. return arg === null;
  13454. }
  13455. exports.isNull = isNull;
  13456. function isNullOrUndefined(arg) {
  13457. return arg == null;
  13458. }
  13459. exports.isNullOrUndefined = isNullOrUndefined;
  13460. function isNumber(arg) {
  13461. return typeof arg === 'number';
  13462. }
  13463. exports.isNumber = isNumber;
  13464. function isString(arg) {
  13465. return typeof arg === 'string';
  13466. }
  13467. exports.isString = isString;
  13468. function isSymbol(arg) {
  13469. return typeof arg === 'symbol';
  13470. }
  13471. exports.isSymbol = isSymbol;
  13472. function isUndefined(arg) {
  13473. return arg === void 0;
  13474. }
  13475. exports.isUndefined = isUndefined;
  13476. function isRegExp(re) {
  13477. return isObject(re) && objectToString(re) === '[object RegExp]';
  13478. }
  13479. exports.isRegExp = isRegExp;
  13480. function isObject(arg) {
  13481. return typeof arg === 'object' && arg !== null;
  13482. }
  13483. exports.isObject = isObject;
  13484. function isDate(d) {
  13485. return isObject(d) && objectToString(d) === '[object Date]';
  13486. }
  13487. exports.isDate = isDate;
  13488. function isError(e) {
  13489. return isObject(e) &&
  13490. (objectToString(e) === '[object Error]' || e instanceof Error);
  13491. }
  13492. exports.isError = isError;
  13493. function isFunction(arg) {
  13494. return typeof arg === 'function';
  13495. }
  13496. exports.isFunction = isFunction;
  13497. function isPrimitive(arg) {
  13498. return arg === null ||
  13499. typeof arg === 'boolean' ||
  13500. typeof arg === 'number' ||
  13501. typeof arg === 'string' ||
  13502. typeof arg === 'symbol' || // ES6 symbol
  13503. typeof arg === 'undefined';
  13504. }
  13505. exports.isPrimitive = isPrimitive;
  13506. exports.isBuffer = require('./support/isBuffer');
  13507. function objectToString(o) {
  13508. return Object.prototype.toString.call(o);
  13509. }
  13510. function pad(n) {
  13511. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  13512. }
  13513. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  13514. 'Oct', 'Nov', 'Dec'];
  13515. // 26 Feb 16:19:34
  13516. function timestamp() {
  13517. var d = new Date();
  13518. var time = [pad(d.getHours()),
  13519. pad(d.getMinutes()),
  13520. pad(d.getSeconds())].join(':');
  13521. return [d.getDate(), months[d.getMonth()], time].join(' ');
  13522. }
  13523. // log is just a thin wrapper to console.log that prepends a timestamp
  13524. exports.log = function() {
  13525. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  13526. };
  13527. /**
  13528. * Inherit the prototype methods from one constructor into another.
  13529. *
  13530. * The Function.prototype.inherits from lang.js rewritten as a standalone
  13531. * function (not on Function.prototype). NOTE: If this file is to be loaded
  13532. * during bootstrapping this function needs to be rewritten using some native
  13533. * functions as prototype setup using normal JavaScript does not work as
  13534. * expected during bootstrapping (see mirror.js in r114903).
  13535. *
  13536. * @param {function} ctor Constructor function which needs to inherit the
  13537. * prototype.
  13538. * @param {function} superCtor Constructor function to inherit prototype from.
  13539. */
  13540. exports.inherits = require('inherits');
  13541. exports._extend = function(origin, add) {
  13542. // Don't do anything if add isn't an object
  13543. if (!add || !isObject(add)) return origin;
  13544. var keys = Object.keys(add);
  13545. var i = keys.length;
  13546. while (i--) {
  13547. origin[keys[i]] = add[keys[i]];
  13548. }
  13549. return origin;
  13550. };
  13551. function hasOwnProperty(obj, prop) {
  13552. return Object.prototype.hasOwnProperty.call(obj, prop);
  13553. }
  13554. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  13555. },{"./support/isBuffer":83,"_process":67,"inherits":82}]},{},[1]);