mocha.js 402 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174
  1. (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. (function (process,global){
  3. /**
  4. * Shim process.stdout.
  5. */
  6. process.stdout = require('browser-stdout')();
  7. var Mocha = require('./lib/mocha');
  8. /**
  9. * Create a Mocha instance.
  10. *
  11. * @return {undefined}
  12. */
  13. var mocha = new Mocha({ reporter: 'html' });
  14. /**
  15. * Save timer references to avoid Sinon interfering (see GH-237).
  16. */
  17. var Date = global.Date;
  18. var setTimeout = global.setTimeout;
  19. var setInterval = global.setInterval;
  20. var clearTimeout = global.clearTimeout;
  21. var clearInterval = global.clearInterval;
  22. var uncaughtExceptionHandlers = [];
  23. var originalOnerrorHandler = global.onerror;
  24. /**
  25. * Remove uncaughtException listener.
  26. * Revert to original onerror handler if previously defined.
  27. */
  28. process.removeListener = function(e, fn){
  29. if ('uncaughtException' == e) {
  30. if (originalOnerrorHandler) {
  31. global.onerror = originalOnerrorHandler;
  32. } else {
  33. global.onerror = function() {};
  34. }
  35. var i = Mocha.utils.indexOf(uncaughtExceptionHandlers, fn);
  36. if (i != -1) { uncaughtExceptionHandlers.splice(i, 1); }
  37. }
  38. };
  39. /**
  40. * Implements uncaughtException listener.
  41. */
  42. process.on = function(e, fn){
  43. if ('uncaughtException' == e) {
  44. global.onerror = function(err, url, line){
  45. fn(new Error(err + ' (' + url + ':' + line + ')'));
  46. return !mocha.allowUncaught;
  47. };
  48. uncaughtExceptionHandlers.push(fn);
  49. }
  50. };
  51. // The BDD UI is registered by default, but no UI will be functional in the
  52. // browser without an explicit call to the overridden `mocha.ui` (see below).
  53. // Ensure that this default UI does not expose its methods to the global scope.
  54. mocha.suite.removeAllListeners('pre-require');
  55. var immediateQueue = []
  56. , immediateTimeout;
  57. function timeslice() {
  58. var immediateStart = new Date().getTime();
  59. while (immediateQueue.length && (new Date().getTime() - immediateStart) < 100) {
  60. immediateQueue.shift()();
  61. }
  62. if (immediateQueue.length) {
  63. immediateTimeout = setTimeout(timeslice, 0);
  64. } else {
  65. immediateTimeout = null;
  66. }
  67. }
  68. /**
  69. * High-performance override of Runner.immediately.
  70. */
  71. Mocha.Runner.immediately = function(callback) {
  72. immediateQueue.push(callback);
  73. if (!immediateTimeout) {
  74. immediateTimeout = setTimeout(timeslice, 0);
  75. }
  76. };
  77. /**
  78. * Function to allow assertion libraries to throw errors directly into mocha.
  79. * This is useful when running tests in a browser because window.onerror will
  80. * only receive the 'message' attribute of the Error.
  81. */
  82. mocha.throwError = function(err) {
  83. Mocha.utils.forEach(uncaughtExceptionHandlers, function (fn) {
  84. fn(err);
  85. });
  86. throw err;
  87. };
  88. /**
  89. * Override ui to ensure that the ui functions are initialized.
  90. * Normally this would happen in Mocha.prototype.loadFiles.
  91. */
  92. mocha.ui = function(ui){
  93. Mocha.prototype.ui.call(this, ui);
  94. this.suite.emit('pre-require', global, null, this);
  95. return this;
  96. };
  97. /**
  98. * Setup mocha with the given setting options.
  99. */
  100. mocha.setup = function(opts){
  101. if ('string' == typeof opts) opts = { ui: opts };
  102. for (var opt in opts) this[opt](opts[opt]);
  103. return this;
  104. };
  105. /**
  106. * Run mocha, returning the Runner.
  107. */
  108. mocha.run = function(fn){
  109. var options = mocha.options;
  110. mocha.globals('location');
  111. var query = Mocha.utils.parseQuery(global.location.search || '');
  112. if (query.grep) mocha.grep(query.grep);
  113. if (query.fgrep) mocha.fgrep(query.fgrep);
  114. if (query.invert) mocha.invert();
  115. return Mocha.prototype.run.call(mocha, function(err){
  116. // The DOM Document is not available in Web Workers.
  117. var document = global.document;
  118. if (document && document.getElementById('mocha') && options.noHighlighting !== true) {
  119. Mocha.utils.highlightTags('code');
  120. }
  121. if (fn) fn(err);
  122. });
  123. };
  124. /**
  125. * Expose the process shim.
  126. * https://github.com/mochajs/mocha/pull/916
  127. */
  128. Mocha.process = process;
  129. /**
  130. * Expose mocha.
  131. */
  132. global.Mocha = Mocha;
  133. global.mocha = mocha;
  134. // this allows test/acceptance/required-tokens.js to pass; thus,
  135. // you can now do `const describe = require('mocha').describe` in a
  136. // browser context (assuming browserification). should fix #880
  137. module.exports = global;
  138. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  139. },{"./lib/mocha":14,"_process":67,"browser-stdout":41}],2:[function(require,module,exports){
  140. /* eslint-disable no-unused-vars */
  141. module.exports = function(type) {
  142. return function() {};
  143. };
  144. },{}],3:[function(require,module,exports){
  145. /**
  146. * Module exports.
  147. */
  148. exports.EventEmitter = EventEmitter;
  149. /**
  150. * Object#toString reference.
  151. */
  152. var objToString = Object.prototype.toString;
  153. /**
  154. * Check if a value is an array.
  155. *
  156. * @api private
  157. * @param {*} val The value to test.
  158. * @return {boolean} true if the value is an array, otherwise false.
  159. */
  160. function isArray(val) {
  161. return objToString.call(val) === '[object Array]';
  162. }
  163. /**
  164. * Event emitter constructor.
  165. *
  166. * @api public
  167. */
  168. function EventEmitter() {}
  169. /**
  170. * Add a listener.
  171. *
  172. * @api public
  173. * @param {string} name Event name.
  174. * @param {Function} fn Event handler.
  175. * @return {EventEmitter} Emitter instance.
  176. */
  177. EventEmitter.prototype.on = function(name, fn) {
  178. if (!this.$events) {
  179. this.$events = {};
  180. }
  181. if (!this.$events[name]) {
  182. this.$events[name] = fn;
  183. } else if (isArray(this.$events[name])) {
  184. this.$events[name].push(fn);
  185. } else {
  186. this.$events[name] = [this.$events[name], fn];
  187. }
  188. return this;
  189. };
  190. EventEmitter.prototype.addListener = EventEmitter.prototype.on;
  191. /**
  192. * Adds a volatile listener.
  193. *
  194. * @api public
  195. * @param {string} name Event name.
  196. * @param {Function} fn Event handler.
  197. * @return {EventEmitter} Emitter instance.
  198. */
  199. EventEmitter.prototype.once = function(name, fn) {
  200. var self = this;
  201. function on() {
  202. self.removeListener(name, on);
  203. fn.apply(this, arguments);
  204. }
  205. on.listener = fn;
  206. this.on(name, on);
  207. return this;
  208. };
  209. /**
  210. * Remove a listener.
  211. *
  212. * @api public
  213. * @param {string} name Event name.
  214. * @param {Function} fn Event handler.
  215. * @return {EventEmitter} Emitter instance.
  216. */
  217. EventEmitter.prototype.removeListener = function(name, fn) {
  218. if (this.$events && this.$events[name]) {
  219. var list = this.$events[name];
  220. if (isArray(list)) {
  221. var pos = -1;
  222. for (var i = 0, l = list.length; i < l; i++) {
  223. if (list[i] === fn || (list[i].listener && list[i].listener === fn)) {
  224. pos = i;
  225. break;
  226. }
  227. }
  228. if (pos < 0) {
  229. return this;
  230. }
  231. list.splice(pos, 1);
  232. if (!list.length) {
  233. delete this.$events[name];
  234. }
  235. } else if (list === fn || (list.listener && list.listener === fn)) {
  236. delete this.$events[name];
  237. }
  238. }
  239. return this;
  240. };
  241. /**
  242. * Remove all listeners for an event.
  243. *
  244. * @api public
  245. * @param {string} name Event name.
  246. * @return {EventEmitter} Emitter instance.
  247. */
  248. EventEmitter.prototype.removeAllListeners = function(name) {
  249. if (name === undefined) {
  250. this.$events = {};
  251. return this;
  252. }
  253. if (this.$events && this.$events[name]) {
  254. this.$events[name] = null;
  255. }
  256. return this;
  257. };
  258. /**
  259. * Get all listeners for a given event.
  260. *
  261. * @api public
  262. * @param {string} name Event name.
  263. * @return {EventEmitter} Emitter instance.
  264. */
  265. EventEmitter.prototype.listeners = function(name) {
  266. if (!this.$events) {
  267. this.$events = {};
  268. }
  269. if (!this.$events[name]) {
  270. this.$events[name] = [];
  271. }
  272. if (!isArray(this.$events[name])) {
  273. this.$events[name] = [this.$events[name]];
  274. }
  275. return this.$events[name];
  276. };
  277. /**
  278. * Emit an event.
  279. *
  280. * @api public
  281. * @param {string} name Event name.
  282. * @return {boolean} true if at least one handler was invoked, else false.
  283. */
  284. EventEmitter.prototype.emit = function(name) {
  285. if (!this.$events) {
  286. return false;
  287. }
  288. var handler = this.$events[name];
  289. if (!handler) {
  290. return false;
  291. }
  292. var args = Array.prototype.slice.call(arguments, 1);
  293. if (typeof handler === 'function') {
  294. handler.apply(this, args);
  295. } else if (isArray(handler)) {
  296. var listeners = handler.slice();
  297. for (var i = 0, l = listeners.length; i < l; i++) {
  298. listeners[i].apply(this, args);
  299. }
  300. } else {
  301. return false;
  302. }
  303. return true;
  304. };
  305. },{}],4:[function(require,module,exports){
  306. /**
  307. * Expose `Progress`.
  308. */
  309. module.exports = Progress;
  310. /**
  311. * Initialize a new `Progress` indicator.
  312. */
  313. function Progress() {
  314. this.percent = 0;
  315. this.size(0);
  316. this.fontSize(11);
  317. this.font('helvetica, arial, sans-serif');
  318. }
  319. /**
  320. * Set progress size to `size`.
  321. *
  322. * @api public
  323. * @param {number} size
  324. * @return {Progress} Progress instance.
  325. */
  326. Progress.prototype.size = function(size) {
  327. this._size = size;
  328. return this;
  329. };
  330. /**
  331. * Set text to `text`.
  332. *
  333. * @api public
  334. * @param {string} text
  335. * @return {Progress} Progress instance.
  336. */
  337. Progress.prototype.text = function(text) {
  338. this._text = text;
  339. return this;
  340. };
  341. /**
  342. * Set font size to `size`.
  343. *
  344. * @api public
  345. * @param {number} size
  346. * @return {Progress} Progress instance.
  347. */
  348. Progress.prototype.fontSize = function(size) {
  349. this._fontSize = size;
  350. return this;
  351. };
  352. /**
  353. * Set font to `family`.
  354. *
  355. * @param {string} family
  356. * @return {Progress} Progress instance.
  357. */
  358. Progress.prototype.font = function(family) {
  359. this._font = family;
  360. return this;
  361. };
  362. /**
  363. * Update percentage to `n`.
  364. *
  365. * @param {number} n
  366. * @return {Progress} Progress instance.
  367. */
  368. Progress.prototype.update = function(n) {
  369. this.percent = n;
  370. return this;
  371. };
  372. /**
  373. * Draw on `ctx`.
  374. *
  375. * @param {CanvasRenderingContext2d} ctx
  376. * @return {Progress} Progress instance.
  377. */
  378. Progress.prototype.draw = function(ctx) {
  379. try {
  380. var percent = Math.min(this.percent, 100);
  381. var size = this._size;
  382. var half = size / 2;
  383. var x = half;
  384. var y = half;
  385. var rad = half - 1;
  386. var fontSize = this._fontSize;
  387. ctx.font = fontSize + 'px ' + this._font;
  388. var angle = Math.PI * 2 * (percent / 100);
  389. ctx.clearRect(0, 0, size, size);
  390. // outer circle
  391. ctx.strokeStyle = '#9f9f9f';
  392. ctx.beginPath();
  393. ctx.arc(x, y, rad, 0, angle, false);
  394. ctx.stroke();
  395. // inner circle
  396. ctx.strokeStyle = '#eee';
  397. ctx.beginPath();
  398. ctx.arc(x, y, rad - 1, 0, angle, true);
  399. ctx.stroke();
  400. // text
  401. var text = this._text || (percent | 0) + '%';
  402. var w = ctx.measureText(text).width;
  403. ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1);
  404. } catch (err) {
  405. // don't fail if we can't render progress
  406. }
  407. return this;
  408. };
  409. },{}],5:[function(require,module,exports){
  410. (function (global){
  411. exports.isatty = function isatty() {
  412. return true;
  413. };
  414. exports.getWindowSize = function getWindowSize() {
  415. if ('innerHeight' in global) {
  416. return [global.innerHeight, global.innerWidth];
  417. }
  418. // In a Web Worker, the DOM Window is not available.
  419. return [640, 480];
  420. };
  421. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  422. },{}],6:[function(require,module,exports){
  423. /**
  424. * Module dependencies.
  425. */
  426. var JSON = require('json3');
  427. /**
  428. * Expose `Context`.
  429. */
  430. module.exports = Context;
  431. /**
  432. * Initialize a new `Context`.
  433. *
  434. * @api private
  435. */
  436. function Context() {}
  437. /**
  438. * Set or get the context `Runnable` to `runnable`.
  439. *
  440. * @api private
  441. * @param {Runnable} runnable
  442. * @return {Context}
  443. */
  444. Context.prototype.runnable = function(runnable) {
  445. if (!arguments.length) {
  446. return this._runnable;
  447. }
  448. this.test = this._runnable = runnable;
  449. return this;
  450. };
  451. /**
  452. * Set test timeout `ms`.
  453. *
  454. * @api private
  455. * @param {number} ms
  456. * @return {Context} self
  457. */
  458. Context.prototype.timeout = function(ms) {
  459. if (!arguments.length) {
  460. return this.runnable().timeout();
  461. }
  462. this.runnable().timeout(ms);
  463. return this;
  464. };
  465. /**
  466. * Set test timeout `enabled`.
  467. *
  468. * @api private
  469. * @param {boolean} enabled
  470. * @return {Context} self
  471. */
  472. Context.prototype.enableTimeouts = function(enabled) {
  473. this.runnable().enableTimeouts(enabled);
  474. return this;
  475. };
  476. /**
  477. * Set test slowness threshold `ms`.
  478. *
  479. * @api private
  480. * @param {number} ms
  481. * @return {Context} self
  482. */
  483. Context.prototype.slow = function(ms) {
  484. this.runnable().slow(ms);
  485. return this;
  486. };
  487. /**
  488. * Mark a test as skipped.
  489. *
  490. * @api private
  491. * @return {Context} self
  492. */
  493. Context.prototype.skip = function() {
  494. this.runnable().skip();
  495. return this;
  496. };
  497. /**
  498. * Allow a number of retries on failed tests
  499. *
  500. * @api private
  501. * @param {number} n
  502. * @return {Context} self
  503. */
  504. Context.prototype.retries = function(n) {
  505. if (!arguments.length) {
  506. return this.runnable().retries();
  507. }
  508. this.runnable().retries(n);
  509. return this;
  510. };
  511. /**
  512. * Inspect the context void of `._runnable`.
  513. *
  514. * @api private
  515. * @return {string}
  516. */
  517. Context.prototype.inspect = function() {
  518. return JSON.stringify(this, function(key, val) {
  519. return key === 'runnable' || key === 'test' ? undefined : val;
  520. }, 2);
  521. };
  522. },{"json3":54}],7:[function(require,module,exports){
  523. /**
  524. * Module dependencies.
  525. */
  526. var Runnable = require('./runnable');
  527. var inherits = require('./utils').inherits;
  528. /**
  529. * Expose `Hook`.
  530. */
  531. module.exports = Hook;
  532. /**
  533. * Initialize a new `Hook` with the given `title` and callback `fn`.
  534. *
  535. * @param {String} title
  536. * @param {Function} fn
  537. * @api private
  538. */
  539. function Hook(title, fn) {
  540. Runnable.call(this, title, fn);
  541. this.type = 'hook';
  542. }
  543. /**
  544. * Inherit from `Runnable.prototype`.
  545. */
  546. inherits(Hook, Runnable);
  547. /**
  548. * Get or set the test `err`.
  549. *
  550. * @param {Error} err
  551. * @return {Error}
  552. * @api public
  553. */
  554. Hook.prototype.error = function(err) {
  555. if (!arguments.length) {
  556. err = this._error;
  557. this._error = null;
  558. return err;
  559. }
  560. this._error = err;
  561. };
  562. },{"./runnable":33,"./utils":38}],8:[function(require,module,exports){
  563. /**
  564. * Module dependencies.
  565. */
  566. var Test = require('../test');
  567. /**
  568. * BDD-style interface:
  569. *
  570. * describe('Array', function() {
  571. * describe('#indexOf()', function() {
  572. * it('should return -1 when not present', function() {
  573. * // ...
  574. * });
  575. *
  576. * it('should return the index when present', function() {
  577. * // ...
  578. * });
  579. * });
  580. * });
  581. *
  582. * @param {Suite} suite Root suite.
  583. */
  584. module.exports = function(suite) {
  585. var suites = [suite];
  586. suite.on('pre-require', function(context, file, mocha) {
  587. var common = require('./common')(suites, context, mocha);
  588. context.before = common.before;
  589. context.after = common.after;
  590. context.beforeEach = common.beforeEach;
  591. context.afterEach = common.afterEach;
  592. context.run = mocha.options.delay && common.runWithSuite(suite);
  593. /**
  594. * Describe a "suite" with the given `title`
  595. * and callback `fn` containing nested suites
  596. * and/or tests.
  597. */
  598. context.describe = context.context = function(title, fn) {
  599. return common.suite.create({
  600. title: title,
  601. file: file,
  602. fn: fn
  603. });
  604. };
  605. /**
  606. * Pending describe.
  607. */
  608. context.xdescribe = context.xcontext = context.describe.skip = function(title, fn) {
  609. return common.suite.skip({
  610. title: title,
  611. file: file,
  612. fn: fn
  613. });
  614. };
  615. /**
  616. * Exclusive suite.
  617. */
  618. context.describe.only = function(title, fn) {
  619. return common.suite.only({
  620. title: title,
  621. file: file,
  622. fn: fn
  623. });
  624. };
  625. /**
  626. * Describe a specification or test-case
  627. * with the given `title` and callback `fn`
  628. * acting as a thunk.
  629. */
  630. context.it = context.specify = function(title, fn) {
  631. var suite = suites[0];
  632. if (suite.isPending()) {
  633. fn = null;
  634. }
  635. var test = new Test(title, fn);
  636. test.file = file;
  637. suite.addTest(test);
  638. return test;
  639. };
  640. /**
  641. * Exclusive test-case.
  642. */
  643. context.it.only = function(title, fn) {
  644. return common.test.only(mocha, context.it(title, fn));
  645. };
  646. /**
  647. * Pending test case.
  648. */
  649. context.xit = context.xspecify = context.it.skip = function(title) {
  650. context.it(title);
  651. };
  652. /**
  653. * Number of attempts to retry.
  654. */
  655. context.it.retries = function(n) {
  656. context.retries(n);
  657. };
  658. });
  659. };
  660. },{"../test":36,"./common":9}],9:[function(require,module,exports){
  661. 'use strict';
  662. var Suite = require('../suite');
  663. /**
  664. * Functions common to more than one interface.
  665. *
  666. * @param {Suite[]} suites
  667. * @param {Context} context
  668. * @param {Mocha} mocha
  669. * @return {Object} An object containing common functions.
  670. */
  671. module.exports = function(suites, context, mocha) {
  672. return {
  673. /**
  674. * This is only present if flag --delay is passed into Mocha. It triggers
  675. * root suite execution.
  676. *
  677. * @param {Suite} suite The root wuite.
  678. * @return {Function} A function which runs the root suite
  679. */
  680. runWithSuite: function runWithSuite(suite) {
  681. return function run() {
  682. suite.run();
  683. };
  684. },
  685. /**
  686. * Execute before running tests.
  687. *
  688. * @param {string} name
  689. * @param {Function} fn
  690. */
  691. before: function(name, fn) {
  692. suites[0].beforeAll(name, fn);
  693. },
  694. /**
  695. * Execute after running tests.
  696. *
  697. * @param {string} name
  698. * @param {Function} fn
  699. */
  700. after: function(name, fn) {
  701. suites[0].afterAll(name, fn);
  702. },
  703. /**
  704. * Execute before each test case.
  705. *
  706. * @param {string} name
  707. * @param {Function} fn
  708. */
  709. beforeEach: function(name, fn) {
  710. suites[0].beforeEach(name, fn);
  711. },
  712. /**
  713. * Execute after each test case.
  714. *
  715. * @param {string} name
  716. * @param {Function} fn
  717. */
  718. afterEach: function(name, fn) {
  719. suites[0].afterEach(name, fn);
  720. },
  721. suite: {
  722. /**
  723. * Create an exclusive Suite; convenience function
  724. * See docstring for create() below.
  725. *
  726. * @param {Object} opts
  727. * @returns {Suite}
  728. */
  729. only: function only(opts) {
  730. mocha.options.hasOnly = true;
  731. opts.isOnly = true;
  732. return this.create(opts);
  733. },
  734. /**
  735. * Create a Suite, but skip it; convenience function
  736. * See docstring for create() below.
  737. *
  738. * @param {Object} opts
  739. * @returns {Suite}
  740. */
  741. skip: function skip(opts) {
  742. opts.pending = true;
  743. return this.create(opts);
  744. },
  745. /**
  746. * Creates a suite.
  747. * @param {Object} opts Options
  748. * @param {string} opts.title Title of Suite
  749. * @param {Function} [opts.fn] Suite Function (not always applicable)
  750. * @param {boolean} [opts.pending] Is Suite pending?
  751. * @param {string} [opts.file] Filepath where this Suite resides
  752. * @param {boolean} [opts.isOnly] Is Suite exclusive?
  753. * @returns {Suite}
  754. */
  755. create: function create(opts) {
  756. var suite = Suite.create(suites[0], opts.title);
  757. suite.pending = Boolean(opts.pending);
  758. suite.file = opts.file;
  759. suites.unshift(suite);
  760. if (opts.isOnly) {
  761. suite.parent._onlySuites = suite.parent._onlySuites.concat(suite);
  762. mocha.options.hasOnly = true;
  763. }
  764. if (typeof opts.fn === 'function') {
  765. opts.fn.call(suite);
  766. suites.shift();
  767. }
  768. return suite;
  769. }
  770. },
  771. test: {
  772. /**
  773. * Exclusive test-case.
  774. *
  775. * @param {Object} mocha
  776. * @param {Function} test
  777. * @returns {*}
  778. */
  779. only: function(mocha, test) {
  780. test.parent._onlyTests = test.parent._onlyTests.concat(test);
  781. mocha.options.hasOnly = true;
  782. return test;
  783. },
  784. /**
  785. * Pending test case.
  786. *
  787. * @param {string} title
  788. */
  789. skip: function(title) {
  790. context.test(title);
  791. },
  792. /**
  793. * Number of retry attempts
  794. *
  795. * @param {number} n
  796. */
  797. retries: function(n) {
  798. context.retries(n);
  799. }
  800. }
  801. };
  802. };
  803. },{"../suite":35}],10:[function(require,module,exports){
  804. /**
  805. * Module dependencies.
  806. */
  807. var Suite = require('../suite');
  808. var Test = require('../test');
  809. /**
  810. * Exports-style (as Node.js module) interface:
  811. *
  812. * exports.Array = {
  813. * '#indexOf()': {
  814. * 'should return -1 when the value is not present': function() {
  815. *
  816. * },
  817. *
  818. * 'should return the correct index when the value is present': function() {
  819. *
  820. * }
  821. * }
  822. * };
  823. *
  824. * @param {Suite} suite Root suite.
  825. */
  826. module.exports = function(suite) {
  827. var suites = [suite];
  828. suite.on('require', visit);
  829. function visit(obj, file) {
  830. var suite;
  831. for (var key in obj) {
  832. if (typeof obj[key] === 'function') {
  833. var fn = obj[key];
  834. switch (key) {
  835. case 'before':
  836. suites[0].beforeAll(fn);
  837. break;
  838. case 'after':
  839. suites[0].afterAll(fn);
  840. break;
  841. case 'beforeEach':
  842. suites[0].beforeEach(fn);
  843. break;
  844. case 'afterEach':
  845. suites[0].afterEach(fn);
  846. break;
  847. default:
  848. var test = new Test(key, fn);
  849. test.file = file;
  850. suites[0].addTest(test);
  851. }
  852. } else {
  853. suite = Suite.create(suites[0], key);
  854. suites.unshift(suite);
  855. visit(obj[key], file);
  856. suites.shift();
  857. }
  858. }
  859. }
  860. };
  861. },{"../suite":35,"../test":36}],11:[function(require,module,exports){
  862. exports.bdd = require('./bdd');
  863. exports.tdd = require('./tdd');
  864. exports.qunit = require('./qunit');
  865. exports.exports = require('./exports');
  866. },{"./bdd":8,"./exports":10,"./qunit":12,"./tdd":13}],12:[function(require,module,exports){
  867. /**
  868. * Module dependencies.
  869. */
  870. var Test = require('../test');
  871. /**
  872. * QUnit-style interface:
  873. *
  874. * suite('Array');
  875. *
  876. * test('#length', function() {
  877. * var arr = [1,2,3];
  878. * ok(arr.length == 3);
  879. * });
  880. *
  881. * test('#indexOf()', function() {
  882. * var arr = [1,2,3];
  883. * ok(arr.indexOf(1) == 0);
  884. * ok(arr.indexOf(2) == 1);
  885. * ok(arr.indexOf(3) == 2);
  886. * });
  887. *
  888. * suite('String');
  889. *
  890. * test('#length', function() {
  891. * ok('foo'.length == 3);
  892. * });
  893. *
  894. * @param {Suite} suite Root suite.
  895. */
  896. module.exports = function(suite) {
  897. var suites = [suite];
  898. suite.on('pre-require', function(context, file, mocha) {
  899. var common = require('./common')(suites, context, mocha);
  900. context.before = common.before;
  901. context.after = common.after;
  902. context.beforeEach = common.beforeEach;
  903. context.afterEach = common.afterEach;
  904. context.run = mocha.options.delay && common.runWithSuite(suite);
  905. /**
  906. * Describe a "suite" with the given `title`.
  907. */
  908. context.suite = function(title) {
  909. if (suites.length > 1) {
  910. suites.shift();
  911. }
  912. return common.suite.create({
  913. title: title,
  914. file: file
  915. });
  916. };
  917. /**
  918. * Exclusive Suite.
  919. */
  920. context.suite.only = function(title) {
  921. if (suites.length > 1) {
  922. suites.shift();
  923. }
  924. return common.suite.only({
  925. title: title,
  926. file: file
  927. });
  928. };
  929. /**
  930. * Describe a specification or test-case
  931. * with the given `title` and callback `fn`
  932. * acting as a thunk.
  933. */
  934. context.test = function(title, fn) {
  935. var test = new Test(title, fn);
  936. test.file = file;
  937. suites[0].addTest(test);
  938. return test;
  939. };
  940. /**
  941. * Exclusive test-case.
  942. */
  943. context.test.only = function(title, fn) {
  944. return common.test.only(mocha, context.test(title, fn));
  945. };
  946. context.test.skip = common.test.skip;
  947. context.test.retries = common.test.retries;
  948. });
  949. };
  950. },{"../test":36,"./common":9}],13:[function(require,module,exports){
  951. /**
  952. * Module dependencies.
  953. */
  954. var Test = require('../test');
  955. /**
  956. * TDD-style interface:
  957. *
  958. * suite('Array', function() {
  959. * suite('#indexOf()', function() {
  960. * suiteSetup(function() {
  961. *
  962. * });
  963. *
  964. * test('should return -1 when not present', function() {
  965. *
  966. * });
  967. *
  968. * test('should return the index when present', function() {
  969. *
  970. * });
  971. *
  972. * suiteTeardown(function() {
  973. *
  974. * });
  975. * });
  976. * });
  977. *
  978. * @param {Suite} suite Root suite.
  979. */
  980. module.exports = function(suite) {
  981. var suites = [suite];
  982. suite.on('pre-require', function(context, file, mocha) {
  983. var common = require('./common')(suites, context, mocha);
  984. context.setup = common.beforeEach;
  985. context.teardown = common.afterEach;
  986. context.suiteSetup = common.before;
  987. context.suiteTeardown = common.after;
  988. context.run = mocha.options.delay && common.runWithSuite(suite);
  989. /**
  990. * Describe a "suite" with the given `title` and callback `fn` containing
  991. * nested suites and/or tests.
  992. */
  993. context.suite = function(title, fn) {
  994. return common.suite.create({
  995. title: title,
  996. file: file,
  997. fn: fn
  998. });
  999. };
  1000. /**
  1001. * Pending suite.
  1002. */
  1003. context.suite.skip = function(title, fn) {
  1004. return common.suite.skip({
  1005. title: title,
  1006. file: file,
  1007. fn: fn
  1008. });
  1009. };
  1010. /**
  1011. * Exclusive test-case.
  1012. */
  1013. context.suite.only = function(title, fn) {
  1014. return common.suite.only({
  1015. title: title,
  1016. file: file,
  1017. fn: fn
  1018. });
  1019. };
  1020. /**
  1021. * Describe a specification or test-case with the given `title` and
  1022. * callback `fn` acting as a thunk.
  1023. */
  1024. context.test = function(title, fn) {
  1025. var suite = suites[0];
  1026. if (suite.isPending()) {
  1027. fn = null;
  1028. }
  1029. var test = new Test(title, fn);
  1030. test.file = file;
  1031. suite.addTest(test);
  1032. return test;
  1033. };
  1034. /**
  1035. * Exclusive test-case.
  1036. */
  1037. context.test.only = function(title, fn) {
  1038. return common.test.only(mocha, context.test(title, fn));
  1039. };
  1040. context.test.skip = common.test.skip;
  1041. context.test.retries = common.test.retries;
  1042. });
  1043. };
  1044. },{"../test":36,"./common":9}],14:[function(require,module,exports){
  1045. (function (process,global,__dirname){
  1046. /*!
  1047. * mocha
  1048. * Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
  1049. * MIT Licensed
  1050. */
  1051. /**
  1052. * Module dependencies.
  1053. */
  1054. var escapeRe = require('escape-string-regexp');
  1055. var path = require('path');
  1056. var reporters = require('./reporters');
  1057. var utils = require('./utils');
  1058. /**
  1059. * Expose `Mocha`.
  1060. */
  1061. exports = module.exports = Mocha;
  1062. /**
  1063. * To require local UIs and reporters when running in node.
  1064. */
  1065. if (!process.browser) {
  1066. var cwd = process.cwd();
  1067. module.paths.push(cwd, path.join(cwd, 'node_modules'));
  1068. }
  1069. /**
  1070. * Expose internals.
  1071. */
  1072. exports.utils = utils;
  1073. exports.interfaces = require('./interfaces');
  1074. exports.reporters = reporters;
  1075. exports.Runnable = require('./runnable');
  1076. exports.Context = require('./context');
  1077. exports.Runner = require('./runner');
  1078. exports.Suite = require('./suite');
  1079. exports.Hook = require('./hook');
  1080. exports.Test = require('./test');
  1081. /**
  1082. * Return image `name` path.
  1083. *
  1084. * @api private
  1085. * @param {string} name
  1086. * @return {string}
  1087. */
  1088. function image(name) {
  1089. return path.join(__dirname, '../images', name + '.png');
  1090. }
  1091. /**
  1092. * Set up mocha with `options`.
  1093. *
  1094. * Options:
  1095. *
  1096. * - `ui` name "bdd", "tdd", "exports" etc
  1097. * - `reporter` reporter instance, defaults to `mocha.reporters.spec`
  1098. * - `globals` array of accepted globals
  1099. * - `timeout` timeout in milliseconds
  1100. * - `retries` number of times to retry failed tests
  1101. * - `bail` bail on the first test failure
  1102. * - `slow` milliseconds to wait before considering a test slow
  1103. * - `ignoreLeaks` ignore global leaks
  1104. * - `fullTrace` display the full stack-trace on failing
  1105. * - `grep` string or regexp to filter tests with
  1106. *
  1107. * @param {Object} options
  1108. * @api public
  1109. */
  1110. function Mocha(options) {
  1111. options = options || {};
  1112. this.files = [];
  1113. this.options = options;
  1114. if (options.grep) {
  1115. this.grep(new RegExp(options.grep));
  1116. }
  1117. if (options.fgrep) {
  1118. this.fgrep(options.fgrep);
  1119. }
  1120. this.suite = new exports.Suite('', new exports.Context());
  1121. this.ui(options.ui);
  1122. this.bail(options.bail);
  1123. this.reporter(options.reporter, options.reporterOptions);
  1124. if (typeof options.timeout !== 'undefined' && options.timeout !== null) {
  1125. this.timeout(options.timeout);
  1126. }
  1127. if (typeof options.retries !== 'undefined' && options.retries !== null) {
  1128. this.retries(options.retries);
  1129. }
  1130. this.useColors(options.useColors);
  1131. if (options.enableTimeouts !== null) {
  1132. this.enableTimeouts(options.enableTimeouts);
  1133. }
  1134. if (options.slow) {
  1135. this.slow(options.slow);
  1136. }
  1137. }
  1138. /**
  1139. * Enable or disable bailing on the first failure.
  1140. *
  1141. * @api public
  1142. * @param {boolean} [bail]
  1143. */
  1144. Mocha.prototype.bail = function(bail) {
  1145. if (!arguments.length) {
  1146. bail = true;
  1147. }
  1148. this.suite.bail(bail);
  1149. return this;
  1150. };
  1151. /**
  1152. * Add test `file`.
  1153. *
  1154. * @api public
  1155. * @param {string} file
  1156. */
  1157. Mocha.prototype.addFile = function(file) {
  1158. this.files.push(file);
  1159. return this;
  1160. };
  1161. /**
  1162. * Set reporter to `reporter`, defaults to "spec".
  1163. *
  1164. * @param {String|Function} reporter name or constructor
  1165. * @param {Object} reporterOptions optional options
  1166. * @api public
  1167. * @param {string|Function} reporter name or constructor
  1168. * @param {Object} reporterOptions optional options
  1169. */
  1170. Mocha.prototype.reporter = function(reporter, reporterOptions) {
  1171. if (typeof reporter === 'function') {
  1172. this._reporter = reporter;
  1173. } else {
  1174. reporter = reporter || 'spec';
  1175. var _reporter;
  1176. // Try to load a built-in reporter.
  1177. if (reporters[reporter]) {
  1178. _reporter = reporters[reporter];
  1179. }
  1180. // Try to load reporters from process.cwd() and node_modules
  1181. if (!_reporter) {
  1182. try {
  1183. _reporter = require(reporter);
  1184. } catch (err) {
  1185. err.message.indexOf('Cannot find module') !== -1
  1186. ? console.warn('"' + reporter + '" reporter not found')
  1187. : console.warn('"' + reporter + '" reporter blew up with error:\n' + err.stack);
  1188. }
  1189. }
  1190. if (!_reporter && reporter === 'teamcity') {
  1191. console.warn('The Teamcity reporter was moved to a package named '
  1192. + 'mocha-teamcity-reporter '
  1193. + '(https://npmjs.org/package/mocha-teamcity-reporter).');
  1194. }
  1195. if (!_reporter) {
  1196. throw new Error('invalid reporter "' + reporter + '"');
  1197. }
  1198. this._reporter = _reporter;
  1199. }
  1200. this.options.reporterOptions = reporterOptions;
  1201. return this;
  1202. };
  1203. /**
  1204. * Set test UI `name`, defaults to "bdd".
  1205. *
  1206. * @api public
  1207. * @param {string} bdd
  1208. */
  1209. Mocha.prototype.ui = function(name) {
  1210. name = name || 'bdd';
  1211. this._ui = exports.interfaces[name];
  1212. if (!this._ui) {
  1213. try {
  1214. this._ui = require(name);
  1215. } catch (err) {
  1216. throw new Error('invalid interface "' + name + '"');
  1217. }
  1218. }
  1219. this._ui = this._ui(this.suite);
  1220. this.suite.on('pre-require', function(context) {
  1221. exports.afterEach = context.afterEach || context.teardown;
  1222. exports.after = context.after || context.suiteTeardown;
  1223. exports.beforeEach = context.beforeEach || context.setup;
  1224. exports.before = context.before || context.suiteSetup;
  1225. exports.describe = context.describe || context.suite;
  1226. exports.it = context.it || context.test;
  1227. exports.setup = context.setup || context.beforeEach;
  1228. exports.suiteSetup = context.suiteSetup || context.before;
  1229. exports.suiteTeardown = context.suiteTeardown || context.after;
  1230. exports.suite = context.suite || context.describe;
  1231. exports.teardown = context.teardown || context.afterEach;
  1232. exports.test = context.test || context.it;
  1233. exports.run = context.run;
  1234. });
  1235. return this;
  1236. };
  1237. /**
  1238. * Load registered files.
  1239. *
  1240. * @api private
  1241. */
  1242. Mocha.prototype.loadFiles = function(fn) {
  1243. var self = this;
  1244. var suite = this.suite;
  1245. this.files.forEach(function(file) {
  1246. file = path.resolve(file);
  1247. suite.emit('pre-require', global, file, self);
  1248. suite.emit('require', require(file), file, self);
  1249. suite.emit('post-require', global, file, self);
  1250. });
  1251. fn && fn();
  1252. };
  1253. /**
  1254. * Enable growl support.
  1255. *
  1256. * @api private
  1257. */
  1258. Mocha.prototype._growl = function(runner, reporter) {
  1259. var notify = require('growl');
  1260. runner.on('end', function() {
  1261. var stats = reporter.stats;
  1262. if (stats.failures) {
  1263. var msg = stats.failures + ' of ' + runner.total + ' tests failed';
  1264. notify(msg, { name: 'mocha', title: 'Failed', image: image('error') });
  1265. } else {
  1266. notify(stats.passes + ' tests passed in ' + stats.duration + 'ms', {
  1267. name: 'mocha',
  1268. title: 'Passed',
  1269. image: image('ok')
  1270. });
  1271. }
  1272. });
  1273. };
  1274. /**
  1275. * Escape string and add it to grep as a regexp.
  1276. *
  1277. * @api public
  1278. * @param str
  1279. * @returns {Mocha}
  1280. */
  1281. Mocha.prototype.fgrep = function(str) {
  1282. return this.grep(new RegExp(escapeRe(str)));
  1283. };
  1284. /**
  1285. * Add regexp to grep, if `re` is a string it is escaped.
  1286. *
  1287. * @param {RegExp|String} re
  1288. * @return {Mocha}
  1289. * @api public
  1290. * @param {RegExp|string} re
  1291. * @return {Mocha}
  1292. */
  1293. Mocha.prototype.grep = function(re) {
  1294. if (utils.isString(re)) {
  1295. // extract args if it's regex-like, i.e: [string, pattern, flag]
  1296. var arg = re.match(/^\/(.*)\/(g|i|)$|.*/);
  1297. this.options.grep = new RegExp(arg[1] || arg[0], arg[2]);
  1298. } else {
  1299. this.options.grep = re;
  1300. }
  1301. return this;
  1302. };
  1303. /**
  1304. * Invert `.grep()` matches.
  1305. *
  1306. * @return {Mocha}
  1307. * @api public
  1308. */
  1309. Mocha.prototype.invert = function() {
  1310. this.options.invert = true;
  1311. return this;
  1312. };
  1313. /**
  1314. * Ignore global leaks.
  1315. *
  1316. * @param {Boolean} ignore
  1317. * @return {Mocha}
  1318. * @api public
  1319. * @param {boolean} ignore
  1320. * @return {Mocha}
  1321. */
  1322. Mocha.prototype.ignoreLeaks = function(ignore) {
  1323. this.options.ignoreLeaks = Boolean(ignore);
  1324. return this;
  1325. };
  1326. /**
  1327. * Enable global leak checking.
  1328. *
  1329. * @return {Mocha}
  1330. * @api public
  1331. */
  1332. Mocha.prototype.checkLeaks = function() {
  1333. this.options.ignoreLeaks = false;
  1334. return this;
  1335. };
  1336. /**
  1337. * Display long stack-trace on failing
  1338. *
  1339. * @return {Mocha}
  1340. * @api public
  1341. */
  1342. Mocha.prototype.fullTrace = function() {
  1343. this.options.fullStackTrace = true;
  1344. return this;
  1345. };
  1346. /**
  1347. * Enable growl support.
  1348. *
  1349. * @return {Mocha}
  1350. * @api public
  1351. */
  1352. Mocha.prototype.growl = function() {
  1353. this.options.growl = true;
  1354. return this;
  1355. };
  1356. /**
  1357. * Ignore `globals` array or string.
  1358. *
  1359. * @param {Array|String} globals
  1360. * @return {Mocha}
  1361. * @api public
  1362. * @param {Array|string} globals
  1363. * @return {Mocha}
  1364. */
  1365. Mocha.prototype.globals = function(globals) {
  1366. this.options.globals = (this.options.globals || []).concat(globals);
  1367. return this;
  1368. };
  1369. /**
  1370. * Emit color output.
  1371. *
  1372. * @param {Boolean} colors
  1373. * @return {Mocha}
  1374. * @api public
  1375. * @param {boolean} colors
  1376. * @return {Mocha}
  1377. */
  1378. Mocha.prototype.useColors = function(colors) {
  1379. if (colors !== undefined) {
  1380. this.options.useColors = colors;
  1381. }
  1382. return this;
  1383. };
  1384. /**
  1385. * Use inline diffs rather than +/-.
  1386. *
  1387. * @param {Boolean} inlineDiffs
  1388. * @return {Mocha}
  1389. * @api public
  1390. * @param {boolean} inlineDiffs
  1391. * @return {Mocha}
  1392. */
  1393. Mocha.prototype.useInlineDiffs = function(inlineDiffs) {
  1394. this.options.useInlineDiffs = inlineDiffs !== undefined && inlineDiffs;
  1395. return this;
  1396. };
  1397. /**
  1398. * Set the timeout in milliseconds.
  1399. *
  1400. * @param {Number} timeout
  1401. * @return {Mocha}
  1402. * @api public
  1403. * @param {number} timeout
  1404. * @return {Mocha}
  1405. */
  1406. Mocha.prototype.timeout = function(timeout) {
  1407. this.suite.timeout(timeout);
  1408. return this;
  1409. };
  1410. /**
  1411. * Set the number of times to retry failed tests.
  1412. *
  1413. * @param {Number} retry times
  1414. * @return {Mocha}
  1415. * @api public
  1416. */
  1417. Mocha.prototype.retries = function(n) {
  1418. this.suite.retries(n);
  1419. return this;
  1420. };
  1421. /**
  1422. * Set slowness threshold in milliseconds.
  1423. *
  1424. * @param {Number} slow
  1425. * @return {Mocha}
  1426. * @api public
  1427. * @param {number} slow
  1428. * @return {Mocha}
  1429. */
  1430. Mocha.prototype.slow = function(slow) {
  1431. this.suite.slow(slow);
  1432. return this;
  1433. };
  1434. /**
  1435. * Enable timeouts.
  1436. *
  1437. * @param {Boolean} enabled
  1438. * @return {Mocha}
  1439. * @api public
  1440. * @param {boolean} enabled
  1441. * @return {Mocha}
  1442. */
  1443. Mocha.prototype.enableTimeouts = function(enabled) {
  1444. this.suite.enableTimeouts(arguments.length && enabled !== undefined ? enabled : true);
  1445. return this;
  1446. };
  1447. /**
  1448. * Makes all tests async (accepting a callback)
  1449. *
  1450. * @return {Mocha}
  1451. * @api public
  1452. */
  1453. Mocha.prototype.asyncOnly = function() {
  1454. this.options.asyncOnly = true;
  1455. return this;
  1456. };
  1457. /**
  1458. * Disable syntax highlighting (in browser).
  1459. *
  1460. * @api public
  1461. */
  1462. Mocha.prototype.noHighlighting = function() {
  1463. this.options.noHighlighting = true;
  1464. return this;
  1465. };
  1466. /**
  1467. * Enable uncaught errors to propagate (in browser).
  1468. *
  1469. * @return {Mocha}
  1470. * @api public
  1471. */
  1472. Mocha.prototype.allowUncaught = function() {
  1473. this.options.allowUncaught = true;
  1474. return this;
  1475. };
  1476. /**
  1477. * Delay root suite execution.
  1478. * @returns {Mocha}
  1479. */
  1480. Mocha.prototype.delay = function delay() {
  1481. this.options.delay = true;
  1482. return this;
  1483. };
  1484. /**
  1485. * Run tests and invoke `fn()` when complete.
  1486. *
  1487. * @api public
  1488. * @param {Function} fn
  1489. * @return {Runner}
  1490. */
  1491. Mocha.prototype.run = function(fn) {
  1492. if (this.files.length) {
  1493. this.loadFiles();
  1494. }
  1495. var suite = this.suite;
  1496. var options = this.options;
  1497. options.files = this.files;
  1498. var runner = new exports.Runner(suite, options.delay);
  1499. var reporter = new this._reporter(runner, options);
  1500. runner.ignoreLeaks = options.ignoreLeaks !== false;
  1501. runner.fullStackTrace = options.fullStackTrace;
  1502. runner.hasOnly = options.hasOnly;
  1503. runner.asyncOnly = options.asyncOnly;
  1504. runner.allowUncaught = options.allowUncaught;
  1505. if (options.grep) {
  1506. runner.grep(options.grep, options.invert);
  1507. }
  1508. if (options.globals) {
  1509. runner.globals(options.globals);
  1510. }
  1511. if (options.growl) {
  1512. this._growl(runner, reporter);
  1513. }
  1514. if (options.useColors !== undefined) {
  1515. exports.reporters.Base.useColors = options.useColors;
  1516. }
  1517. exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
  1518. function done(failures) {
  1519. if (reporter.done) {
  1520. reporter.done(failures, fn);
  1521. } else {
  1522. fn && fn(failures);
  1523. }
  1524. }
  1525. return runner.run(done);
  1526. };
  1527. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},"/lib")
  1528. },{"./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){
  1529. /**
  1530. * Helpers.
  1531. */
  1532. var s = 1000;
  1533. var m = s * 60;
  1534. var h = m * 60;
  1535. var d = h * 24;
  1536. var y = d * 365.25;
  1537. /**
  1538. * Parse or format the given `val`.
  1539. *
  1540. * Options:
  1541. *
  1542. * - `long` verbose formatting [false]
  1543. *
  1544. * @api public
  1545. * @param {string|number} val
  1546. * @param {Object} options
  1547. * @return {string|number}
  1548. */
  1549. module.exports = function(val, options) {
  1550. options = options || {};
  1551. if (typeof val === 'string') {
  1552. return parse(val);
  1553. }
  1554. // https://github.com/mochajs/mocha/pull/1035
  1555. return options['long'] ? longFormat(val) : shortFormat(val);
  1556. };
  1557. /**
  1558. * Parse the given `str` and return milliseconds.
  1559. *
  1560. * @api private
  1561. * @param {string} str
  1562. * @return {number}
  1563. */
  1564. function parse(str) {
  1565. var match = (/^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i).exec(str);
  1566. if (!match) {
  1567. return;
  1568. }
  1569. var n = parseFloat(match[1]);
  1570. var type = (match[2] || 'ms').toLowerCase();
  1571. switch (type) {
  1572. case 'years':
  1573. case 'year':
  1574. case 'y':
  1575. return n * y;
  1576. case 'days':
  1577. case 'day':
  1578. case 'd':
  1579. return n * d;
  1580. case 'hours':
  1581. case 'hour':
  1582. case 'h':
  1583. return n * h;
  1584. case 'minutes':
  1585. case 'minute':
  1586. case 'm':
  1587. return n * m;
  1588. case 'seconds':
  1589. case 'second':
  1590. case 's':
  1591. return n * s;
  1592. case 'ms':
  1593. return n;
  1594. default:
  1595. // No default case
  1596. }
  1597. }
  1598. /**
  1599. * Short format for `ms`.
  1600. *
  1601. * @api private
  1602. * @param {number} ms
  1603. * @return {string}
  1604. */
  1605. function shortFormat(ms) {
  1606. if (ms >= d) {
  1607. return Math.round(ms / d) + 'd';
  1608. }
  1609. if (ms >= h) {
  1610. return Math.round(ms / h) + 'h';
  1611. }
  1612. if (ms >= m) {
  1613. return Math.round(ms / m) + 'm';
  1614. }
  1615. if (ms >= s) {
  1616. return Math.round(ms / s) + 's';
  1617. }
  1618. return ms + 'ms';
  1619. }
  1620. /**
  1621. * Long format for `ms`.
  1622. *
  1623. * @api private
  1624. * @param {number} ms
  1625. * @return {string}
  1626. */
  1627. function longFormat(ms) {
  1628. return plural(ms, d, 'day')
  1629. || plural(ms, h, 'hour')
  1630. || plural(ms, m, 'minute')
  1631. || plural(ms, s, 'second')
  1632. || ms + ' ms';
  1633. }
  1634. /**
  1635. * Pluralization helper.
  1636. *
  1637. * @api private
  1638. * @param {number} ms
  1639. * @param {number} n
  1640. * @param {string} name
  1641. */
  1642. function plural(ms, n, name) {
  1643. if (ms < n) {
  1644. return;
  1645. }
  1646. if (ms < n * 1.5) {
  1647. return Math.floor(ms / n) + ' ' + name;
  1648. }
  1649. return Math.ceil(ms / n) + ' ' + name + 's';
  1650. }
  1651. },{}],16:[function(require,module,exports){
  1652. /**
  1653. * Expose `Pending`.
  1654. */
  1655. module.exports = Pending;
  1656. /**
  1657. * Initialize a new `Pending` error with the given message.
  1658. *
  1659. * @param {string} message
  1660. */
  1661. function Pending(message) {
  1662. this.message = message;
  1663. }
  1664. },{}],17:[function(require,module,exports){
  1665. (function (process,global){
  1666. /**
  1667. * Module dependencies.
  1668. */
  1669. var tty = require('tty');
  1670. var diff = require('diff');
  1671. var ms = require('../ms');
  1672. var utils = require('../utils');
  1673. var supportsColor = process.browser ? null : require('supports-color');
  1674. /**
  1675. * Expose `Base`.
  1676. */
  1677. exports = module.exports = Base;
  1678. /**
  1679. * Save timer references to avoid Sinon interfering.
  1680. * See: https://github.com/mochajs/mocha/issues/237
  1681. */
  1682. /* eslint-disable no-unused-vars, no-native-reassign */
  1683. var Date = global.Date;
  1684. var setTimeout = global.setTimeout;
  1685. var setInterval = global.setInterval;
  1686. var clearTimeout = global.clearTimeout;
  1687. var clearInterval = global.clearInterval;
  1688. /* eslint-enable no-unused-vars, no-native-reassign */
  1689. /**
  1690. * Check if both stdio streams are associated with a tty.
  1691. */
  1692. var isatty = tty.isatty(1) && tty.isatty(2);
  1693. /**
  1694. * Enable coloring by default, except in the browser interface.
  1695. */
  1696. exports.useColors = !process.browser && (supportsColor || (process.env.MOCHA_COLORS !== undefined));
  1697. /**
  1698. * Inline diffs instead of +/-
  1699. */
  1700. exports.inlineDiffs = false;
  1701. /**
  1702. * Default color map.
  1703. */
  1704. exports.colors = {
  1705. pass: 90,
  1706. fail: 31,
  1707. 'bright pass': 92,
  1708. 'bright fail': 91,
  1709. 'bright yellow': 93,
  1710. pending: 36,
  1711. suite: 0,
  1712. 'error title': 0,
  1713. 'error message': 31,
  1714. 'error stack': 90,
  1715. checkmark: 32,
  1716. fast: 90,
  1717. medium: 33,
  1718. slow: 31,
  1719. green: 32,
  1720. light: 90,
  1721. 'diff gutter': 90,
  1722. 'diff added': 32,
  1723. 'diff removed': 31
  1724. };
  1725. /**
  1726. * Default symbol map.
  1727. */
  1728. exports.symbols = {
  1729. ok: '✓',
  1730. err: '✖',
  1731. dot: '․',
  1732. comma: ',',
  1733. bang: '!'
  1734. };
  1735. // With node.js on Windows: use symbols available in terminal default fonts
  1736. if (process.platform === 'win32') {
  1737. exports.symbols.ok = '\u221A';
  1738. exports.symbols.err = '\u00D7';
  1739. exports.symbols.dot = '.';
  1740. }
  1741. /**
  1742. * Color `str` with the given `type`,
  1743. * allowing colors to be disabled,
  1744. * as well as user-defined color
  1745. * schemes.
  1746. *
  1747. * @param {string} type
  1748. * @param {string} str
  1749. * @return {string}
  1750. * @api private
  1751. */
  1752. var color = exports.color = function(type, str) {
  1753. if (!exports.useColors) {
  1754. return String(str);
  1755. }
  1756. return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
  1757. };
  1758. /**
  1759. * Expose term window size, with some defaults for when stderr is not a tty.
  1760. */
  1761. exports.window = {
  1762. width: 75
  1763. };
  1764. if (isatty) {
  1765. exports.window.width = process.stdout.getWindowSize
  1766. ? process.stdout.getWindowSize(1)[0]
  1767. : tty.getWindowSize()[1];
  1768. }
  1769. /**
  1770. * Expose some basic cursor interactions that are common among reporters.
  1771. */
  1772. exports.cursor = {
  1773. hide: function() {
  1774. isatty && process.stdout.write('\u001b[?25l');
  1775. },
  1776. show: function() {
  1777. isatty && process.stdout.write('\u001b[?25h');
  1778. },
  1779. deleteLine: function() {
  1780. isatty && process.stdout.write('\u001b[2K');
  1781. },
  1782. beginningOfLine: function() {
  1783. isatty && process.stdout.write('\u001b[0G');
  1784. },
  1785. CR: function() {
  1786. if (isatty) {
  1787. exports.cursor.deleteLine();
  1788. exports.cursor.beginningOfLine();
  1789. } else {
  1790. process.stdout.write('\r');
  1791. }
  1792. }
  1793. };
  1794. /**
  1795. * Outut the given `failures` as a list.
  1796. *
  1797. * @param {Array} failures
  1798. * @api public
  1799. */
  1800. exports.list = function(failures) {
  1801. console.log();
  1802. failures.forEach(function(test, i) {
  1803. // format
  1804. var fmt = color('error title', ' %s) %s:\n')
  1805. + color('error message', ' %s')
  1806. + color('error stack', '\n%s\n');
  1807. // msg
  1808. var msg;
  1809. var err = test.err;
  1810. var message;
  1811. if (err.message && typeof err.message.toString === 'function') {
  1812. message = err.message + '';
  1813. } else if (typeof err.inspect === 'function') {
  1814. message = err.inspect() + '';
  1815. } else {
  1816. message = '';
  1817. }
  1818. var stack = err.stack || message;
  1819. var index = message ? stack.indexOf(message) : -1;
  1820. var actual = err.actual;
  1821. var expected = err.expected;
  1822. var escape = true;
  1823. if (index === -1) {
  1824. msg = message;
  1825. } else {
  1826. index += message.length;
  1827. msg = stack.slice(0, index);
  1828. // remove msg from stack
  1829. stack = stack.slice(index + 1);
  1830. }
  1831. // uncaught
  1832. if (err.uncaught) {
  1833. msg = 'Uncaught ' + msg;
  1834. }
  1835. // explicitly show diff
  1836. if (err.showDiff !== false && sameType(actual, expected) && expected !== undefined) {
  1837. escape = false;
  1838. if (!(utils.isString(actual) && utils.isString(expected))) {
  1839. err.actual = actual = utils.stringify(actual);
  1840. err.expected = expected = utils.stringify(expected);
  1841. }
  1842. fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
  1843. var match = message.match(/^([^:]+): expected/);
  1844. msg = '\n ' + color('error message', match ? match[1] : msg);
  1845. if (exports.inlineDiffs) {
  1846. msg += inlineDiff(err, escape);
  1847. } else {
  1848. msg += unifiedDiff(err, escape);
  1849. }
  1850. }
  1851. // indent stack trace
  1852. stack = stack.replace(/^/gm, ' ');
  1853. console.log(fmt, (i + 1), test.fullTitle(), msg, stack);
  1854. });
  1855. };
  1856. /**
  1857. * Initialize a new `Base` reporter.
  1858. *
  1859. * All other reporters generally
  1860. * inherit from this reporter, providing
  1861. * stats such as test duration, number
  1862. * of tests passed / failed etc.
  1863. *
  1864. * @param {Runner} runner
  1865. * @api public
  1866. */
  1867. function Base(runner) {
  1868. var stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 };
  1869. var failures = this.failures = [];
  1870. if (!runner) {
  1871. return;
  1872. }
  1873. this.runner = runner;
  1874. runner.stats = stats;
  1875. runner.on('start', function() {
  1876. stats.start = new Date();
  1877. });
  1878. runner.on('suite', function(suite) {
  1879. stats.suites = stats.suites || 0;
  1880. suite.root || stats.suites++;
  1881. });
  1882. runner.on('test end', function() {
  1883. stats.tests = stats.tests || 0;
  1884. stats.tests++;
  1885. });
  1886. runner.on('pass', function(test) {
  1887. stats.passes = stats.passes || 0;
  1888. if (test.duration > test.slow()) {
  1889. test.speed = 'slow';
  1890. } else if (test.duration > test.slow() / 2) {
  1891. test.speed = 'medium';
  1892. } else {
  1893. test.speed = 'fast';
  1894. }
  1895. stats.passes++;
  1896. });
  1897. runner.on('fail', function(test, err) {
  1898. stats.failures = stats.failures || 0;
  1899. stats.failures++;
  1900. test.err = err;
  1901. failures.push(test);
  1902. });
  1903. runner.on('end', function() {
  1904. stats.end = new Date();
  1905. stats.duration = new Date() - stats.start;
  1906. });
  1907. runner.on('pending', function() {
  1908. stats.pending++;
  1909. });
  1910. }
  1911. /**
  1912. * Output common epilogue used by many of
  1913. * the bundled reporters.
  1914. *
  1915. * @api public
  1916. */
  1917. Base.prototype.epilogue = function() {
  1918. var stats = this.stats;
  1919. var fmt;
  1920. console.log();
  1921. // passes
  1922. fmt = color('bright pass', ' ')
  1923. + color('green', ' %d passing')
  1924. + color('light', ' (%s)');
  1925. console.log(fmt,
  1926. stats.passes || 0,
  1927. ms(stats.duration));
  1928. // pending
  1929. if (stats.pending) {
  1930. fmt = color('pending', ' ')
  1931. + color('pending', ' %d pending');
  1932. console.log(fmt, stats.pending);
  1933. }
  1934. // failures
  1935. if (stats.failures) {
  1936. fmt = color('fail', ' %d failing');
  1937. console.log(fmt, stats.failures);
  1938. Base.list(this.failures);
  1939. console.log();
  1940. }
  1941. console.log();
  1942. };
  1943. /**
  1944. * Pad the given `str` to `len`.
  1945. *
  1946. * @api private
  1947. * @param {string} str
  1948. * @param {string} len
  1949. * @return {string}
  1950. */
  1951. function pad(str, len) {
  1952. str = String(str);
  1953. return Array(len - str.length + 1).join(' ') + str;
  1954. }
  1955. /**
  1956. * Returns an inline diff between 2 strings with coloured ANSI output
  1957. *
  1958. * @api private
  1959. * @param {Error} err with actual/expected
  1960. * @param {boolean} escape
  1961. * @return {string} Diff
  1962. */
  1963. function inlineDiff(err, escape) {
  1964. var msg = errorDiff(err, 'WordsWithSpace', escape);
  1965. // linenos
  1966. var lines = msg.split('\n');
  1967. if (lines.length > 4) {
  1968. var width = String(lines.length).length;
  1969. msg = lines.map(function(str, i) {
  1970. return pad(++i, width) + ' |' + ' ' + str;
  1971. }).join('\n');
  1972. }
  1973. // legend
  1974. msg = '\n'
  1975. + color('diff removed', 'actual')
  1976. + ' '
  1977. + color('diff added', 'expected')
  1978. + '\n\n'
  1979. + msg
  1980. + '\n';
  1981. // indent
  1982. msg = msg.replace(/^/gm, ' ');
  1983. return msg;
  1984. }
  1985. /**
  1986. * Returns a unified diff between two strings.
  1987. *
  1988. * @api private
  1989. * @param {Error} err with actual/expected
  1990. * @param {boolean} escape
  1991. * @return {string} The diff.
  1992. */
  1993. function unifiedDiff(err, escape) {
  1994. var indent = ' ';
  1995. function cleanUp(line) {
  1996. if (escape) {
  1997. line = escapeInvisibles(line);
  1998. }
  1999. if (line[0] === '+') {
  2000. return indent + colorLines('diff added', line);
  2001. }
  2002. if (line[0] === '-') {
  2003. return indent + colorLines('diff removed', line);
  2004. }
  2005. if (line.match(/\@\@/)) {
  2006. return null;
  2007. }
  2008. if (line.match(/\\ No newline/)) {
  2009. return null;
  2010. }
  2011. return indent + line;
  2012. }
  2013. function notBlank(line) {
  2014. return typeof line !== 'undefined' && line !== null;
  2015. }
  2016. var msg = diff.createPatch('string', err.actual, err.expected);
  2017. var lines = msg.split('\n').splice(4);
  2018. return '\n '
  2019. + colorLines('diff added', '+ expected') + ' '
  2020. + colorLines('diff removed', '- actual')
  2021. + '\n\n'
  2022. + lines.map(cleanUp).filter(notBlank).join('\n');
  2023. }
  2024. /**
  2025. * Return a character diff for `err`.
  2026. *
  2027. * @api private
  2028. * @param {Error} err
  2029. * @param {string} type
  2030. * @param {boolean} escape
  2031. * @return {string}
  2032. */
  2033. function errorDiff(err, type, escape) {
  2034. var actual = escape ? escapeInvisibles(err.actual) : err.actual;
  2035. var expected = escape ? escapeInvisibles(err.expected) : err.expected;
  2036. return diff['diff' + type](actual, expected).map(function(str) {
  2037. if (str.added) {
  2038. return colorLines('diff added', str.value);
  2039. }
  2040. if (str.removed) {
  2041. return colorLines('diff removed', str.value);
  2042. }
  2043. return str.value;
  2044. }).join('');
  2045. }
  2046. /**
  2047. * Returns a string with all invisible characters in plain text
  2048. *
  2049. * @api private
  2050. * @param {string} line
  2051. * @return {string}
  2052. */
  2053. function escapeInvisibles(line) {
  2054. return line.replace(/\t/g, '<tab>')
  2055. .replace(/\r/g, '<CR>')
  2056. .replace(/\n/g, '<LF>\n');
  2057. }
  2058. /**
  2059. * Color lines for `str`, using the color `name`.
  2060. *
  2061. * @api private
  2062. * @param {string} name
  2063. * @param {string} str
  2064. * @return {string}
  2065. */
  2066. function colorLines(name, str) {
  2067. return str.split('\n').map(function(str) {
  2068. return color(name, str);
  2069. }).join('\n');
  2070. }
  2071. /**
  2072. * Object#toString reference.
  2073. */
  2074. var objToString = Object.prototype.toString;
  2075. /**
  2076. * Check that a / b have the same type.
  2077. *
  2078. * @api private
  2079. * @param {Object} a
  2080. * @param {Object} b
  2081. * @return {boolean}
  2082. */
  2083. function sameType(a, b) {
  2084. return objToString.call(a) === objToString.call(b);
  2085. }
  2086. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2087. },{"../ms":15,"../utils":38,"_process":67,"diff":46,"supports-color":42,"tty":5}],18:[function(require,module,exports){
  2088. /**
  2089. * Module dependencies.
  2090. */
  2091. var Base = require('./base');
  2092. var utils = require('../utils');
  2093. /**
  2094. * Expose `Doc`.
  2095. */
  2096. exports = module.exports = Doc;
  2097. /**
  2098. * Initialize a new `Doc` reporter.
  2099. *
  2100. * @param {Runner} runner
  2101. * @api public
  2102. */
  2103. function Doc(runner) {
  2104. Base.call(this, runner);
  2105. var indents = 2;
  2106. function indent() {
  2107. return Array(indents).join(' ');
  2108. }
  2109. runner.on('suite', function(suite) {
  2110. if (suite.root) {
  2111. return;
  2112. }
  2113. ++indents;
  2114. console.log('%s<section class="suite">', indent());
  2115. ++indents;
  2116. console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title));
  2117. console.log('%s<dl>', indent());
  2118. });
  2119. runner.on('suite end', function(suite) {
  2120. if (suite.root) {
  2121. return;
  2122. }
  2123. console.log('%s</dl>', indent());
  2124. --indents;
  2125. console.log('%s</section>', indent());
  2126. --indents;
  2127. });
  2128. runner.on('pass', function(test) {
  2129. console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
  2130. var code = utils.escape(utils.clean(test.body));
  2131. console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
  2132. });
  2133. runner.on('fail', function(test, err) {
  2134. console.log('%s <dt class="error">%s</dt>', indent(), utils.escape(test.title));
  2135. var code = utils.escape(utils.clean(test.body));
  2136. console.log('%s <dd class="error"><pre><code>%s</code></pre></dd>', indent(), code);
  2137. console.log('%s <dd class="error">%s</dd>', indent(), utils.escape(err));
  2138. });
  2139. }
  2140. },{"../utils":38,"./base":17}],19:[function(require,module,exports){
  2141. (function (process){
  2142. /**
  2143. * Module dependencies.
  2144. */
  2145. var Base = require('./base');
  2146. var inherits = require('../utils').inherits;
  2147. var color = Base.color;
  2148. /**
  2149. * Expose `Dot`.
  2150. */
  2151. exports = module.exports = Dot;
  2152. /**
  2153. * Initialize a new `Dot` matrix test reporter.
  2154. *
  2155. * @api public
  2156. * @param {Runner} runner
  2157. */
  2158. function Dot(runner) {
  2159. Base.call(this, runner);
  2160. var self = this;
  2161. var width = Base.window.width * .75 | 0;
  2162. var n = -1;
  2163. runner.on('start', function() {
  2164. process.stdout.write('\n');
  2165. });
  2166. runner.on('pending', function() {
  2167. if (++n % width === 0) {
  2168. process.stdout.write('\n ');
  2169. }
  2170. process.stdout.write(color('pending', Base.symbols.comma));
  2171. });
  2172. runner.on('pass', function(test) {
  2173. if (++n % width === 0) {
  2174. process.stdout.write('\n ');
  2175. }
  2176. if (test.speed === 'slow') {
  2177. process.stdout.write(color('bright yellow', Base.symbols.dot));
  2178. } else {
  2179. process.stdout.write(color(test.speed, Base.symbols.dot));
  2180. }
  2181. });
  2182. runner.on('fail', function() {
  2183. if (++n % width === 0) {
  2184. process.stdout.write('\n ');
  2185. }
  2186. process.stdout.write(color('fail', Base.symbols.bang));
  2187. });
  2188. runner.on('end', function() {
  2189. console.log();
  2190. self.epilogue();
  2191. });
  2192. }
  2193. /**
  2194. * Inherit from `Base.prototype`.
  2195. */
  2196. inherits(Dot, Base);
  2197. }).call(this,require('_process'))
  2198. },{"../utils":38,"./base":17,"_process":67}],20:[function(require,module,exports){
  2199. (function (global){
  2200. /* eslint-env browser */
  2201. /**
  2202. * Module dependencies.
  2203. */
  2204. var Base = require('./base');
  2205. var utils = require('../utils');
  2206. var Progress = require('../browser/progress');
  2207. var escapeRe = require('escape-string-regexp');
  2208. var escape = utils.escape;
  2209. /**
  2210. * Save timer references to avoid Sinon interfering (see GH-237).
  2211. */
  2212. /* eslint-disable no-unused-vars, no-native-reassign */
  2213. var Date = global.Date;
  2214. var setTimeout = global.setTimeout;
  2215. var setInterval = global.setInterval;
  2216. var clearTimeout = global.clearTimeout;
  2217. var clearInterval = global.clearInterval;
  2218. /* eslint-enable no-unused-vars, no-native-reassign */
  2219. /**
  2220. * Expose `HTML`.
  2221. */
  2222. exports = module.exports = HTML;
  2223. /**
  2224. * Stats template.
  2225. */
  2226. var statsTemplate = '<ul id="mocha-stats">'
  2227. + '<li class="progress"><canvas width="40" height="40"></canvas></li>'
  2228. + '<li class="passes"><a href="javascript:void(0);">passes:</a> <em>0</em></li>'
  2229. + '<li class="failures"><a href="javascript:void(0);">failures:</a> <em>0</em></li>'
  2230. + '<li class="duration">duration: <em>0</em>s</li>'
  2231. + '</ul>';
  2232. /**
  2233. * Initialize a new `HTML` reporter.
  2234. *
  2235. * @api public
  2236. * @param {Runner} runner
  2237. */
  2238. function HTML(runner) {
  2239. Base.call(this, runner);
  2240. var self = this;
  2241. var stats = this.stats;
  2242. var stat = fragment(statsTemplate);
  2243. var items = stat.getElementsByTagName('li');
  2244. var passes = items[1].getElementsByTagName('em')[0];
  2245. var passesLink = items[1].getElementsByTagName('a')[0];
  2246. var failures = items[2].getElementsByTagName('em')[0];
  2247. var failuresLink = items[2].getElementsByTagName('a')[0];
  2248. var duration = items[3].getElementsByTagName('em')[0];
  2249. var canvas = stat.getElementsByTagName('canvas')[0];
  2250. var report = fragment('<ul id="mocha-report"></ul>');
  2251. var stack = [report];
  2252. var progress;
  2253. var ctx;
  2254. var root = document.getElementById('mocha');
  2255. if (canvas.getContext) {
  2256. var ratio = window.devicePixelRatio || 1;
  2257. canvas.style.width = canvas.width;
  2258. canvas.style.height = canvas.height;
  2259. canvas.width *= ratio;
  2260. canvas.height *= ratio;
  2261. ctx = canvas.getContext('2d');
  2262. ctx.scale(ratio, ratio);
  2263. progress = new Progress();
  2264. }
  2265. if (!root) {
  2266. return error('#mocha div missing, add it to your document');
  2267. }
  2268. // pass toggle
  2269. on(passesLink, 'click', function(evt) {
  2270. evt.preventDefault();
  2271. unhide();
  2272. var name = (/pass/).test(report.className) ? '' : ' pass';
  2273. report.className = report.className.replace(/fail|pass/g, '') + name;
  2274. if (report.className.trim()) {
  2275. hideSuitesWithout('test pass');
  2276. }
  2277. });
  2278. // failure toggle
  2279. on(failuresLink, 'click', function(evt) {
  2280. evt.preventDefault();
  2281. unhide();
  2282. var name = (/fail/).test(report.className) ? '' : ' fail';
  2283. report.className = report.className.replace(/fail|pass/g, '') + name;
  2284. if (report.className.trim()) {
  2285. hideSuitesWithout('test fail');
  2286. }
  2287. });
  2288. root.appendChild(stat);
  2289. root.appendChild(report);
  2290. if (progress) {
  2291. progress.size(40);
  2292. }
  2293. runner.on('suite', function(suite) {
  2294. if (suite.root) {
  2295. return;
  2296. }
  2297. // suite
  2298. var url = self.suiteURL(suite);
  2299. var el = fragment('<li class="suite"><h1><a href="%s">%s</a></h1></li>', url, escape(suite.title));
  2300. // container
  2301. stack[0].appendChild(el);
  2302. stack.unshift(document.createElement('ul'));
  2303. el.appendChild(stack[0]);
  2304. });
  2305. runner.on('suite end', function(suite) {
  2306. if (suite.root) {
  2307. updateStats();
  2308. return;
  2309. }
  2310. stack.shift();
  2311. });
  2312. runner.on('pass', function(test) {
  2313. var url = self.testURL(test);
  2314. var markup = '<li class="test pass %e"><h2>%e<span class="duration">%ems</span> '
  2315. + '<a href="%s" class="replay">‣</a></h2></li>';
  2316. var el = fragment(markup, test.speed, test.title, test.duration, url);
  2317. self.addCodeToggle(el, test.body);
  2318. appendToStack(el);
  2319. updateStats();
  2320. });
  2321. runner.on('fail', function(test) {
  2322. var el = fragment('<li class="test fail"><h2>%e <a href="%e" class="replay">‣</a></h2></li>',
  2323. test.title, self.testURL(test));
  2324. var stackString; // Note: Includes leading newline
  2325. var message = test.err.toString();
  2326. // <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
  2327. // check for the result of the stringifying.
  2328. if (message === '[object Error]') {
  2329. message = test.err.message;
  2330. }
  2331. if (test.err.stack) {
  2332. var indexOfMessage = test.err.stack.indexOf(test.err.message);
  2333. if (indexOfMessage === -1) {
  2334. stackString = test.err.stack;
  2335. } else {
  2336. stackString = test.err.stack.substr(test.err.message.length + indexOfMessage);
  2337. }
  2338. } else if (test.err.sourceURL && test.err.line !== undefined) {
  2339. // Safari doesn't give you a stack. Let's at least provide a source line.
  2340. stackString = '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
  2341. }
  2342. stackString = stackString || '';
  2343. if (test.err.htmlMessage && stackString) {
  2344. el.appendChild(fragment('<div class="html-error">%s\n<pre class="error">%e</pre></div>',
  2345. test.err.htmlMessage, stackString));
  2346. } else if (test.err.htmlMessage) {
  2347. el.appendChild(fragment('<div class="html-error">%s</div>', test.err.htmlMessage));
  2348. } else {
  2349. el.appendChild(fragment('<pre class="error">%e%e</pre>', message, stackString));
  2350. }
  2351. self.addCodeToggle(el, test.body);
  2352. appendToStack(el);
  2353. updateStats();
  2354. });
  2355. runner.on('pending', function(test) {
  2356. var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
  2357. appendToStack(el);
  2358. updateStats();
  2359. });
  2360. function appendToStack(el) {
  2361. // Don't call .appendChild if #mocha-report was already .shift()'ed off the stack.
  2362. if (stack[0]) {
  2363. stack[0].appendChild(el);
  2364. }
  2365. }
  2366. function updateStats() {
  2367. // TODO: add to stats
  2368. var percent = stats.tests / runner.total * 100 | 0;
  2369. if (progress) {
  2370. progress.update(percent).draw(ctx);
  2371. }
  2372. // update stats
  2373. var ms = new Date() - stats.start;
  2374. text(passes, stats.passes);
  2375. text(failures, stats.failures);
  2376. text(duration, (ms / 1000).toFixed(2));
  2377. }
  2378. }
  2379. /**
  2380. * Makes a URL, preserving querystring ("search") parameters.
  2381. *
  2382. * @param {string} s
  2383. * @return {string} A new URL.
  2384. */
  2385. function makeUrl(s) {
  2386. var search = window.location.search;
  2387. // Remove previous grep query parameter if present
  2388. if (search) {
  2389. search = search.replace(/[?&]grep=[^&\s]*/g, '').replace(/^&/, '?');
  2390. }
  2391. return window.location.pathname + (search ? search + '&' : '?') + 'grep=' + encodeURIComponent(escapeRe(s));
  2392. }
  2393. /**
  2394. * Provide suite URL.
  2395. *
  2396. * @param {Object} [suite]
  2397. */
  2398. HTML.prototype.suiteURL = function(suite) {
  2399. return makeUrl(suite.fullTitle());
  2400. };
  2401. /**
  2402. * Provide test URL.
  2403. *
  2404. * @param {Object} [test]
  2405. */
  2406. HTML.prototype.testURL = function(test) {
  2407. return makeUrl(test.fullTitle());
  2408. };
  2409. /**
  2410. * Adds code toggle functionality for the provided test's list element.
  2411. *
  2412. * @param {HTMLLIElement} el
  2413. * @param {string} contents
  2414. */
  2415. HTML.prototype.addCodeToggle = function(el, contents) {
  2416. var h2 = el.getElementsByTagName('h2')[0];
  2417. on(h2, 'click', function() {
  2418. pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
  2419. });
  2420. var pre = fragment('<pre><code>%e</code></pre>', utils.clean(contents));
  2421. el.appendChild(pre);
  2422. pre.style.display = 'none';
  2423. };
  2424. /**
  2425. * Display error `msg`.
  2426. *
  2427. * @param {string} msg
  2428. */
  2429. function error(msg) {
  2430. document.body.appendChild(fragment('<div id="mocha-error">%s</div>', msg));
  2431. }
  2432. /**
  2433. * Return a DOM fragment from `html`.
  2434. *
  2435. * @param {string} html
  2436. */
  2437. function fragment(html) {
  2438. var args = arguments;
  2439. var div = document.createElement('div');
  2440. var i = 1;
  2441. div.innerHTML = html.replace(/%([se])/g, function(_, type) {
  2442. switch (type) {
  2443. case 's': return String(args[i++]);
  2444. case 'e': return escape(args[i++]);
  2445. // no default
  2446. }
  2447. });
  2448. return div.firstChild;
  2449. }
  2450. /**
  2451. * Check for suites that do not have elements
  2452. * with `classname`, and hide them.
  2453. *
  2454. * @param {text} classname
  2455. */
  2456. function hideSuitesWithout(classname) {
  2457. var suites = document.getElementsByClassName('suite');
  2458. for (var i = 0; i < suites.length; i++) {
  2459. var els = suites[i].getElementsByClassName(classname);
  2460. if (!els.length) {
  2461. suites[i].className += ' hidden';
  2462. }
  2463. }
  2464. }
  2465. /**
  2466. * Unhide .hidden suites.
  2467. */
  2468. function unhide() {
  2469. var els = document.getElementsByClassName('suite hidden');
  2470. for (var i = 0; i < els.length; ++i) {
  2471. els[i].className = els[i].className.replace('suite hidden', 'suite');
  2472. }
  2473. }
  2474. /**
  2475. * Set an element's text contents.
  2476. *
  2477. * @param {HTMLElement} el
  2478. * @param {string} contents
  2479. */
  2480. function text(el, contents) {
  2481. if (el.textContent) {
  2482. el.textContent = contents;
  2483. } else {
  2484. el.innerText = contents;
  2485. }
  2486. }
  2487. /**
  2488. * Listen on `event` with callback `fn`.
  2489. */
  2490. function on(el, event, fn) {
  2491. if (el.addEventListener) {
  2492. el.addEventListener(event, fn, false);
  2493. } else {
  2494. el.attachEvent('on' + event, fn);
  2495. }
  2496. }
  2497. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2498. },{"../browser/progress":4,"../utils":38,"./base":17,"escape-string-regexp":47}],21:[function(require,module,exports){
  2499. // Alias exports to a their normalized format Mocha#reporter to prevent a need
  2500. // for dynamic (try/catch) requires, which Browserify doesn't handle.
  2501. exports.Base = exports.base = require('./base');
  2502. exports.Dot = exports.dot = require('./dot');
  2503. exports.Doc = exports.doc = require('./doc');
  2504. exports.TAP = exports.tap = require('./tap');
  2505. exports.JSON = exports.json = require('./json');
  2506. exports.HTML = exports.html = require('./html');
  2507. exports.List = exports.list = require('./list');
  2508. exports.Min = exports.min = require('./min');
  2509. exports.Spec = exports.spec = require('./spec');
  2510. exports.Nyan = exports.nyan = require('./nyan');
  2511. exports.XUnit = exports.xunit = require('./xunit');
  2512. exports.Markdown = exports.markdown = require('./markdown');
  2513. exports.Progress = exports.progress = require('./progress');
  2514. exports.Landing = exports.landing = require('./landing');
  2515. exports.JSONStream = exports['json-stream'] = require('./json-stream');
  2516. },{"./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){
  2517. (function (process){
  2518. /**
  2519. * Module dependencies.
  2520. */
  2521. var Base = require('./base');
  2522. var JSON = require('json3');
  2523. /**
  2524. * Expose `List`.
  2525. */
  2526. exports = module.exports = List;
  2527. /**
  2528. * Initialize a new `List` test reporter.
  2529. *
  2530. * @api public
  2531. * @param {Runner} runner
  2532. */
  2533. function List(runner) {
  2534. Base.call(this, runner);
  2535. var self = this;
  2536. var total = runner.total;
  2537. runner.on('start', function() {
  2538. console.log(JSON.stringify(['start', { total: total }]));
  2539. });
  2540. runner.on('pass', function(test) {
  2541. console.log(JSON.stringify(['pass', clean(test)]));
  2542. });
  2543. runner.on('fail', function(test, err) {
  2544. test = clean(test);
  2545. test.err = err.message;
  2546. test.stack = err.stack || null;
  2547. console.log(JSON.stringify(['fail', test]));
  2548. });
  2549. runner.on('end', function() {
  2550. process.stdout.write(JSON.stringify(['end', self.stats]));
  2551. });
  2552. }
  2553. /**
  2554. * Return a plain-object representation of `test`
  2555. * free of cyclic properties etc.
  2556. *
  2557. * @api private
  2558. * @param {Object} test
  2559. * @return {Object}
  2560. */
  2561. function clean(test) {
  2562. return {
  2563. title: test.title,
  2564. fullTitle: test.fullTitle(),
  2565. duration: test.duration,
  2566. currentRetry: test.currentRetry()
  2567. };
  2568. }
  2569. }).call(this,require('_process'))
  2570. },{"./base":17,"_process":67,"json3":54}],23:[function(require,module,exports){
  2571. (function (process){
  2572. /**
  2573. * Module dependencies.
  2574. */
  2575. var Base = require('./base');
  2576. /**
  2577. * Expose `JSON`.
  2578. */
  2579. exports = module.exports = JSONReporter;
  2580. /**
  2581. * Initialize a new `JSON` reporter.
  2582. *
  2583. * @api public
  2584. * @param {Runner} runner
  2585. */
  2586. function JSONReporter(runner) {
  2587. Base.call(this, runner);
  2588. var self = this;
  2589. var tests = [];
  2590. var pending = [];
  2591. var failures = [];
  2592. var passes = [];
  2593. runner.on('test end', function(test) {
  2594. tests.push(test);
  2595. });
  2596. runner.on('pass', function(test) {
  2597. passes.push(test);
  2598. });
  2599. runner.on('fail', function(test) {
  2600. failures.push(test);
  2601. });
  2602. runner.on('pending', function(test) {
  2603. pending.push(test);
  2604. });
  2605. runner.on('end', function() {
  2606. var obj = {
  2607. stats: self.stats,
  2608. tests: tests.map(clean),
  2609. pending: pending.map(clean),
  2610. failures: failures.map(clean),
  2611. passes: passes.map(clean)
  2612. };
  2613. runner.testResults = obj;
  2614. process.stdout.write(JSON.stringify(obj, null, 2));
  2615. });
  2616. }
  2617. /**
  2618. * Return a plain-object representation of `test`
  2619. * free of cyclic properties etc.
  2620. *
  2621. * @api private
  2622. * @param {Object} test
  2623. * @return {Object}
  2624. */
  2625. function clean(test) {
  2626. return {
  2627. title: test.title,
  2628. fullTitle: test.fullTitle(),
  2629. duration: test.duration,
  2630. currentRetry: test.currentRetry(),
  2631. err: errorJSON(test.err || {})
  2632. };
  2633. }
  2634. /**
  2635. * Transform `error` into a JSON object.
  2636. *
  2637. * @api private
  2638. * @param {Error} err
  2639. * @return {Object}
  2640. */
  2641. function errorJSON(err) {
  2642. var res = {};
  2643. Object.getOwnPropertyNames(err).forEach(function(key) {
  2644. res[key] = err[key];
  2645. }, err);
  2646. return res;
  2647. }
  2648. }).call(this,require('_process'))
  2649. },{"./base":17,"_process":67}],24:[function(require,module,exports){
  2650. (function (process){
  2651. /**
  2652. * Module dependencies.
  2653. */
  2654. var Base = require('./base');
  2655. var inherits = require('../utils').inherits;
  2656. var cursor = Base.cursor;
  2657. var color = Base.color;
  2658. /**
  2659. * Expose `Landing`.
  2660. */
  2661. exports = module.exports = Landing;
  2662. /**
  2663. * Airplane color.
  2664. */
  2665. Base.colors.plane = 0;
  2666. /**
  2667. * Airplane crash color.
  2668. */
  2669. Base.colors['plane crash'] = 31;
  2670. /**
  2671. * Runway color.
  2672. */
  2673. Base.colors.runway = 90;
  2674. /**
  2675. * Initialize a new `Landing` reporter.
  2676. *
  2677. * @api public
  2678. * @param {Runner} runner
  2679. */
  2680. function Landing(runner) {
  2681. Base.call(this, runner);
  2682. var self = this;
  2683. var width = Base.window.width * .75 | 0;
  2684. var total = runner.total;
  2685. var stream = process.stdout;
  2686. var plane = color('plane', '✈');
  2687. var crashed = -1;
  2688. var n = 0;
  2689. function runway() {
  2690. var buf = Array(width).join('-');
  2691. return ' ' + color('runway', buf);
  2692. }
  2693. runner.on('start', function() {
  2694. stream.write('\n\n\n ');
  2695. cursor.hide();
  2696. });
  2697. runner.on('test end', function(test) {
  2698. // check if the plane crashed
  2699. var col = crashed === -1 ? width * ++n / total | 0 : crashed;
  2700. // show the crash
  2701. if (test.state === 'failed') {
  2702. plane = color('plane crash', '✈');
  2703. crashed = col;
  2704. }
  2705. // render landing strip
  2706. stream.write('\u001b[' + (width + 1) + 'D\u001b[2A');
  2707. stream.write(runway());
  2708. stream.write('\n ');
  2709. stream.write(color('runway', Array(col).join('⋅')));
  2710. stream.write(plane);
  2711. stream.write(color('runway', Array(width - col).join('⋅') + '\n'));
  2712. stream.write(runway());
  2713. stream.write('\u001b[0m');
  2714. });
  2715. runner.on('end', function() {
  2716. cursor.show();
  2717. console.log();
  2718. self.epilogue();
  2719. });
  2720. }
  2721. /**
  2722. * Inherit from `Base.prototype`.
  2723. */
  2724. inherits(Landing, Base);
  2725. }).call(this,require('_process'))
  2726. },{"../utils":38,"./base":17,"_process":67}],25:[function(require,module,exports){
  2727. (function (process){
  2728. /**
  2729. * Module dependencies.
  2730. */
  2731. var Base = require('./base');
  2732. var inherits = require('../utils').inherits;
  2733. var color = Base.color;
  2734. var cursor = Base.cursor;
  2735. /**
  2736. * Expose `List`.
  2737. */
  2738. exports = module.exports = List;
  2739. /**
  2740. * Initialize a new `List` test reporter.
  2741. *
  2742. * @api public
  2743. * @param {Runner} runner
  2744. */
  2745. function List(runner) {
  2746. Base.call(this, runner);
  2747. var self = this;
  2748. var n = 0;
  2749. runner.on('start', function() {
  2750. console.log();
  2751. });
  2752. runner.on('test', function(test) {
  2753. process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
  2754. });
  2755. runner.on('pending', function(test) {
  2756. var fmt = color('checkmark', ' -')
  2757. + color('pending', ' %s');
  2758. console.log(fmt, test.fullTitle());
  2759. });
  2760. runner.on('pass', function(test) {
  2761. var fmt = color('checkmark', ' ' + Base.symbols.dot)
  2762. + color('pass', ' %s: ')
  2763. + color(test.speed, '%dms');
  2764. cursor.CR();
  2765. console.log(fmt, test.fullTitle(), test.duration);
  2766. });
  2767. runner.on('fail', function(test) {
  2768. cursor.CR();
  2769. console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
  2770. });
  2771. runner.on('end', self.epilogue.bind(self));
  2772. }
  2773. /**
  2774. * Inherit from `Base.prototype`.
  2775. */
  2776. inherits(List, Base);
  2777. }).call(this,require('_process'))
  2778. },{"../utils":38,"./base":17,"_process":67}],26:[function(require,module,exports){
  2779. (function (process){
  2780. /**
  2781. * Module dependencies.
  2782. */
  2783. var Base = require('./base');
  2784. var utils = require('../utils');
  2785. /**
  2786. * Constants
  2787. */
  2788. var SUITE_PREFIX = '$';
  2789. /**
  2790. * Expose `Markdown`.
  2791. */
  2792. exports = module.exports = Markdown;
  2793. /**
  2794. * Initialize a new `Markdown` reporter.
  2795. *
  2796. * @api public
  2797. * @param {Runner} runner
  2798. */
  2799. function Markdown(runner) {
  2800. Base.call(this, runner);
  2801. var level = 0;
  2802. var buf = '';
  2803. function title(str) {
  2804. return Array(level).join('#') + ' ' + str;
  2805. }
  2806. function mapTOC(suite, obj) {
  2807. var ret = obj;
  2808. var key = SUITE_PREFIX + suite.title;
  2809. obj = obj[key] = obj[key] || { suite: suite };
  2810. suite.suites.forEach(function(suite) {
  2811. mapTOC(suite, obj);
  2812. });
  2813. return ret;
  2814. }
  2815. function stringifyTOC(obj, level) {
  2816. ++level;
  2817. var buf = '';
  2818. var link;
  2819. for (var key in obj) {
  2820. if (key === 'suite') {
  2821. continue;
  2822. }
  2823. if (key !== SUITE_PREFIX) {
  2824. link = ' - [' + key.substring(1) + ']';
  2825. link += '(#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
  2826. buf += Array(level).join(' ') + link;
  2827. }
  2828. buf += stringifyTOC(obj[key], level);
  2829. }
  2830. return buf;
  2831. }
  2832. function generateTOC(suite) {
  2833. var obj = mapTOC(suite, {});
  2834. return stringifyTOC(obj, 0);
  2835. }
  2836. generateTOC(runner.suite);
  2837. runner.on('suite', function(suite) {
  2838. ++level;
  2839. var slug = utils.slug(suite.fullTitle());
  2840. buf += '<a name="' + slug + '"></a>' + '\n';
  2841. buf += title(suite.title) + '\n';
  2842. });
  2843. runner.on('suite end', function() {
  2844. --level;
  2845. });
  2846. runner.on('pass', function(test) {
  2847. var code = utils.clean(test.body);
  2848. buf += test.title + '.\n';
  2849. buf += '\n```js\n';
  2850. buf += code + '\n';
  2851. buf += '```\n\n';
  2852. });
  2853. runner.on('end', function() {
  2854. process.stdout.write('# TOC\n');
  2855. process.stdout.write(generateTOC(runner.suite));
  2856. process.stdout.write(buf);
  2857. });
  2858. }
  2859. }).call(this,require('_process'))
  2860. },{"../utils":38,"./base":17,"_process":67}],27:[function(require,module,exports){
  2861. (function (process){
  2862. /**
  2863. * Module dependencies.
  2864. */
  2865. var Base = require('./base');
  2866. var inherits = require('../utils').inherits;
  2867. /**
  2868. * Expose `Min`.
  2869. */
  2870. exports = module.exports = Min;
  2871. /**
  2872. * Initialize a new `Min` minimal test reporter (best used with --watch).
  2873. *
  2874. * @api public
  2875. * @param {Runner} runner
  2876. */
  2877. function Min(runner) {
  2878. Base.call(this, runner);
  2879. runner.on('start', function() {
  2880. // clear screen
  2881. process.stdout.write('\u001b[2J');
  2882. // set cursor position
  2883. process.stdout.write('\u001b[1;3H');
  2884. });
  2885. runner.on('end', this.epilogue.bind(this));
  2886. }
  2887. /**
  2888. * Inherit from `Base.prototype`.
  2889. */
  2890. inherits(Min, Base);
  2891. }).call(this,require('_process'))
  2892. },{"../utils":38,"./base":17,"_process":67}],28:[function(require,module,exports){
  2893. (function (process){
  2894. /**
  2895. * Module dependencies.
  2896. */
  2897. var Base = require('./base');
  2898. var inherits = require('../utils').inherits;
  2899. /**
  2900. * Expose `Dot`.
  2901. */
  2902. exports = module.exports = NyanCat;
  2903. /**
  2904. * Initialize a new `Dot` matrix test reporter.
  2905. *
  2906. * @param {Runner} runner
  2907. * @api public
  2908. */
  2909. function NyanCat(runner) {
  2910. Base.call(this, runner);
  2911. var self = this;
  2912. var width = Base.window.width * .75 | 0;
  2913. var nyanCatWidth = this.nyanCatWidth = 11;
  2914. this.colorIndex = 0;
  2915. this.numberOfLines = 4;
  2916. this.rainbowColors = self.generateColors();
  2917. this.scoreboardWidth = 5;
  2918. this.tick = 0;
  2919. this.trajectories = [[], [], [], []];
  2920. this.trajectoryWidthMax = (width - nyanCatWidth);
  2921. runner.on('start', function() {
  2922. Base.cursor.hide();
  2923. self.draw();
  2924. });
  2925. runner.on('pending', function() {
  2926. self.draw();
  2927. });
  2928. runner.on('pass', function() {
  2929. self.draw();
  2930. });
  2931. runner.on('fail', function() {
  2932. self.draw();
  2933. });
  2934. runner.on('end', function() {
  2935. Base.cursor.show();
  2936. for (var i = 0; i < self.numberOfLines; i++) {
  2937. write('\n');
  2938. }
  2939. self.epilogue();
  2940. });
  2941. }
  2942. /**
  2943. * Inherit from `Base.prototype`.
  2944. */
  2945. inherits(NyanCat, Base);
  2946. /**
  2947. * Draw the nyan cat
  2948. *
  2949. * @api private
  2950. */
  2951. NyanCat.prototype.draw = function() {
  2952. this.appendRainbow();
  2953. this.drawScoreboard();
  2954. this.drawRainbow();
  2955. this.drawNyanCat();
  2956. this.tick = !this.tick;
  2957. };
  2958. /**
  2959. * Draw the "scoreboard" showing the number
  2960. * of passes, failures and pending tests.
  2961. *
  2962. * @api private
  2963. */
  2964. NyanCat.prototype.drawScoreboard = function() {
  2965. var stats = this.stats;
  2966. function draw(type, n) {
  2967. write(' ');
  2968. write(Base.color(type, n));
  2969. write('\n');
  2970. }
  2971. draw('green', stats.passes);
  2972. draw('fail', stats.failures);
  2973. draw('pending', stats.pending);
  2974. write('\n');
  2975. this.cursorUp(this.numberOfLines);
  2976. };
  2977. /**
  2978. * Append the rainbow.
  2979. *
  2980. * @api private
  2981. */
  2982. NyanCat.prototype.appendRainbow = function() {
  2983. var segment = this.tick ? '_' : '-';
  2984. var rainbowified = this.rainbowify(segment);
  2985. for (var index = 0; index < this.numberOfLines; index++) {
  2986. var trajectory = this.trajectories[index];
  2987. if (trajectory.length >= this.trajectoryWidthMax) {
  2988. trajectory.shift();
  2989. }
  2990. trajectory.push(rainbowified);
  2991. }
  2992. };
  2993. /**
  2994. * Draw the rainbow.
  2995. *
  2996. * @api private
  2997. */
  2998. NyanCat.prototype.drawRainbow = function() {
  2999. var self = this;
  3000. this.trajectories.forEach(function(line) {
  3001. write('\u001b[' + self.scoreboardWidth + 'C');
  3002. write(line.join(''));
  3003. write('\n');
  3004. });
  3005. this.cursorUp(this.numberOfLines);
  3006. };
  3007. /**
  3008. * Draw the nyan cat
  3009. *
  3010. * @api private
  3011. */
  3012. NyanCat.prototype.drawNyanCat = function() {
  3013. var self = this;
  3014. var startWidth = this.scoreboardWidth + this.trajectories[0].length;
  3015. var dist = '\u001b[' + startWidth + 'C';
  3016. var padding = '';
  3017. write(dist);
  3018. write('_,------,');
  3019. write('\n');
  3020. write(dist);
  3021. padding = self.tick ? ' ' : ' ';
  3022. write('_|' + padding + '/\\_/\\ ');
  3023. write('\n');
  3024. write(dist);
  3025. padding = self.tick ? '_' : '__';
  3026. var tail = self.tick ? '~' : '^';
  3027. write(tail + '|' + padding + this.face() + ' ');
  3028. write('\n');
  3029. write(dist);
  3030. padding = self.tick ? ' ' : ' ';
  3031. write(padding + '"" "" ');
  3032. write('\n');
  3033. this.cursorUp(this.numberOfLines);
  3034. };
  3035. /**
  3036. * Draw nyan cat face.
  3037. *
  3038. * @api private
  3039. * @return {string}
  3040. */
  3041. NyanCat.prototype.face = function() {
  3042. var stats = this.stats;
  3043. if (stats.failures) {
  3044. return '( x .x)';
  3045. } else if (stats.pending) {
  3046. return '( o .o)';
  3047. } else if (stats.passes) {
  3048. return '( ^ .^)';
  3049. }
  3050. return '( - .-)';
  3051. };
  3052. /**
  3053. * Move cursor up `n`.
  3054. *
  3055. * @api private
  3056. * @param {number} n
  3057. */
  3058. NyanCat.prototype.cursorUp = function(n) {
  3059. write('\u001b[' + n + 'A');
  3060. };
  3061. /**
  3062. * Move cursor down `n`.
  3063. *
  3064. * @api private
  3065. * @param {number} n
  3066. */
  3067. NyanCat.prototype.cursorDown = function(n) {
  3068. write('\u001b[' + n + 'B');
  3069. };
  3070. /**
  3071. * Generate rainbow colors.
  3072. *
  3073. * @api private
  3074. * @return {Array}
  3075. */
  3076. NyanCat.prototype.generateColors = function() {
  3077. var colors = [];
  3078. for (var i = 0; i < (6 * 7); i++) {
  3079. var pi3 = Math.floor(Math.PI / 3);
  3080. var n = (i * (1.0 / 6));
  3081. var r = Math.floor(3 * Math.sin(n) + 3);
  3082. var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
  3083. var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
  3084. colors.push(36 * r + 6 * g + b + 16);
  3085. }
  3086. return colors;
  3087. };
  3088. /**
  3089. * Apply rainbow to the given `str`.
  3090. *
  3091. * @api private
  3092. * @param {string} str
  3093. * @return {string}
  3094. */
  3095. NyanCat.prototype.rainbowify = function(str) {
  3096. if (!Base.useColors) {
  3097. return str;
  3098. }
  3099. var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length];
  3100. this.colorIndex += 1;
  3101. return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';
  3102. };
  3103. /**
  3104. * Stdout helper.
  3105. *
  3106. * @param {string} string A message to write to stdout.
  3107. */
  3108. function write(string) {
  3109. process.stdout.write(string);
  3110. }
  3111. }).call(this,require('_process'))
  3112. },{"../utils":38,"./base":17,"_process":67}],29:[function(require,module,exports){
  3113. (function (process){
  3114. /**
  3115. * Module dependencies.
  3116. */
  3117. var Base = require('./base');
  3118. var inherits = require('../utils').inherits;
  3119. var color = Base.color;
  3120. var cursor = Base.cursor;
  3121. /**
  3122. * Expose `Progress`.
  3123. */
  3124. exports = module.exports = Progress;
  3125. /**
  3126. * General progress bar color.
  3127. */
  3128. Base.colors.progress = 90;
  3129. /**
  3130. * Initialize a new `Progress` bar test reporter.
  3131. *
  3132. * @api public
  3133. * @param {Runner} runner
  3134. * @param {Object} options
  3135. */
  3136. function Progress(runner, options) {
  3137. Base.call(this, runner);
  3138. var self = this;
  3139. var width = Base.window.width * .50 | 0;
  3140. var total = runner.total;
  3141. var complete = 0;
  3142. var lastN = -1;
  3143. // default chars
  3144. options = options || {};
  3145. options.open = options.open || '[';
  3146. options.complete = options.complete || '▬';
  3147. options.incomplete = options.incomplete || Base.symbols.dot;
  3148. options.close = options.close || ']';
  3149. options.verbose = false;
  3150. // tests started
  3151. runner.on('start', function() {
  3152. console.log();
  3153. cursor.hide();
  3154. });
  3155. // tests complete
  3156. runner.on('test end', function() {
  3157. complete++;
  3158. var percent = complete / total;
  3159. var n = width * percent | 0;
  3160. var i = width - n;
  3161. if (n === lastN && !options.verbose) {
  3162. // Don't re-render the line if it hasn't changed
  3163. return;
  3164. }
  3165. lastN = n;
  3166. cursor.CR();
  3167. process.stdout.write('\u001b[J');
  3168. process.stdout.write(color('progress', ' ' + options.open));
  3169. process.stdout.write(Array(n).join(options.complete));
  3170. process.stdout.write(Array(i).join(options.incomplete));
  3171. process.stdout.write(color('progress', options.close));
  3172. if (options.verbose) {
  3173. process.stdout.write(color('progress', ' ' + complete + ' of ' + total));
  3174. }
  3175. });
  3176. // tests are complete, output some stats
  3177. // and the failures if any
  3178. runner.on('end', function() {
  3179. cursor.show();
  3180. console.log();
  3181. self.epilogue();
  3182. });
  3183. }
  3184. /**
  3185. * Inherit from `Base.prototype`.
  3186. */
  3187. inherits(Progress, Base);
  3188. }).call(this,require('_process'))
  3189. },{"../utils":38,"./base":17,"_process":67}],30:[function(require,module,exports){
  3190. /**
  3191. * Module dependencies.
  3192. */
  3193. var Base = require('./base');
  3194. var inherits = require('../utils').inherits;
  3195. var color = Base.color;
  3196. /**
  3197. * Expose `Spec`.
  3198. */
  3199. exports = module.exports = Spec;
  3200. /**
  3201. * Initialize a new `Spec` test reporter.
  3202. *
  3203. * @api public
  3204. * @param {Runner} runner
  3205. */
  3206. function Spec(runner) {
  3207. Base.call(this, runner);
  3208. var self = this;
  3209. var indents = 0;
  3210. var n = 0;
  3211. function indent() {
  3212. return Array(indents).join(' ');
  3213. }
  3214. runner.on('start', function() {
  3215. console.log();
  3216. });
  3217. runner.on('suite', function(suite) {
  3218. ++indents;
  3219. console.log(color('suite', '%s%s'), indent(), suite.title);
  3220. });
  3221. runner.on('suite end', function() {
  3222. --indents;
  3223. if (indents === 1) {
  3224. console.log();
  3225. }
  3226. });
  3227. runner.on('pending', function(test) {
  3228. var fmt = indent() + color('pending', ' - %s');
  3229. console.log(fmt, test.title);
  3230. });
  3231. runner.on('pass', function(test) {
  3232. var fmt;
  3233. if (test.speed === 'fast') {
  3234. fmt = indent()
  3235. + color('checkmark', ' ' + Base.symbols.ok)
  3236. + color('pass', ' %s');
  3237. console.log(fmt, test.title);
  3238. } else {
  3239. fmt = indent()
  3240. + color('checkmark', ' ' + Base.symbols.ok)
  3241. + color('pass', ' %s')
  3242. + color(test.speed, ' (%dms)');
  3243. console.log(fmt, test.title, test.duration);
  3244. }
  3245. });
  3246. runner.on('fail', function(test) {
  3247. console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
  3248. });
  3249. runner.on('end', self.epilogue.bind(self));
  3250. }
  3251. /**
  3252. * Inherit from `Base.prototype`.
  3253. */
  3254. inherits(Spec, Base);
  3255. },{"../utils":38,"./base":17}],31:[function(require,module,exports){
  3256. /**
  3257. * Module dependencies.
  3258. */
  3259. var Base = require('./base');
  3260. /**
  3261. * Expose `TAP`.
  3262. */
  3263. exports = module.exports = TAP;
  3264. /**
  3265. * Initialize a new `TAP` reporter.
  3266. *
  3267. * @api public
  3268. * @param {Runner} runner
  3269. */
  3270. function TAP(runner) {
  3271. Base.call(this, runner);
  3272. var n = 1;
  3273. var passes = 0;
  3274. var failures = 0;
  3275. runner.on('start', function() {
  3276. var total = runner.grepTotal(runner.suite);
  3277. console.log('%d..%d', 1, total);
  3278. });
  3279. runner.on('test end', function() {
  3280. ++n;
  3281. });
  3282. runner.on('pending', function(test) {
  3283. console.log('ok %d %s # SKIP -', n, title(test));
  3284. });
  3285. runner.on('pass', function(test) {
  3286. passes++;
  3287. console.log('ok %d %s', n, title(test));
  3288. });
  3289. runner.on('fail', function(test, err) {
  3290. failures++;
  3291. console.log('not ok %d %s', n, title(test));
  3292. if (err.stack) {
  3293. console.log(err.stack.replace(/^/gm, ' '));
  3294. }
  3295. });
  3296. runner.on('end', function() {
  3297. console.log('# tests ' + (passes + failures));
  3298. console.log('# pass ' + passes);
  3299. console.log('# fail ' + failures);
  3300. });
  3301. }
  3302. /**
  3303. * Return a TAP-safe title of `test`
  3304. *
  3305. * @api private
  3306. * @param {Object} test
  3307. * @return {String}
  3308. */
  3309. function title(test) {
  3310. return test.fullTitle().replace(/#/g, '');
  3311. }
  3312. },{"./base":17}],32:[function(require,module,exports){
  3313. (function (process,global){
  3314. /**
  3315. * Module dependencies.
  3316. */
  3317. var Base = require('./base');
  3318. var utils = require('../utils');
  3319. var inherits = utils.inherits;
  3320. var fs = require('fs');
  3321. var escape = utils.escape;
  3322. var mkdirp = require('mkdirp');
  3323. var path = require('path');
  3324. /**
  3325. * Save timer references to avoid Sinon interfering (see GH-237).
  3326. */
  3327. /* eslint-disable no-unused-vars, no-native-reassign */
  3328. var Date = global.Date;
  3329. var setTimeout = global.setTimeout;
  3330. var setInterval = global.setInterval;
  3331. var clearTimeout = global.clearTimeout;
  3332. var clearInterval = global.clearInterval;
  3333. /* eslint-enable no-unused-vars, no-native-reassign */
  3334. /**
  3335. * Expose `XUnit`.
  3336. */
  3337. exports = module.exports = XUnit;
  3338. /**
  3339. * Initialize a new `XUnit` reporter.
  3340. *
  3341. * @api public
  3342. * @param {Runner} runner
  3343. */
  3344. function XUnit(runner, options) {
  3345. Base.call(this, runner);
  3346. var stats = this.stats;
  3347. var tests = [];
  3348. var self = this;
  3349. if (options.reporterOptions && options.reporterOptions.output) {
  3350. if (!fs.createWriteStream) {
  3351. throw new Error('file output not supported in browser');
  3352. }
  3353. mkdirp.sync(path.dirname(options.reporterOptions.output));
  3354. self.fileStream = fs.createWriteStream(options.reporterOptions.output);
  3355. }
  3356. runner.on('pending', function(test) {
  3357. tests.push(test);
  3358. });
  3359. runner.on('pass', function(test) {
  3360. tests.push(test);
  3361. });
  3362. runner.on('fail', function(test) {
  3363. tests.push(test);
  3364. });
  3365. runner.on('end', function() {
  3366. self.write(tag('testsuite', {
  3367. name: 'Mocha Tests',
  3368. tests: stats.tests,
  3369. failures: stats.failures,
  3370. errors: stats.failures,
  3371. skipped: stats.tests - stats.failures - stats.passes,
  3372. timestamp: (new Date()).toUTCString(),
  3373. time: (stats.duration / 1000) || 0
  3374. }, false));
  3375. tests.forEach(function(t) {
  3376. self.test(t);
  3377. });
  3378. self.write('</testsuite>');
  3379. });
  3380. }
  3381. /**
  3382. * Inherit from `Base.prototype`.
  3383. */
  3384. inherits(XUnit, Base);
  3385. /**
  3386. * Override done to close the stream (if it's a file).
  3387. *
  3388. * @param failures
  3389. * @param {Function} fn
  3390. */
  3391. XUnit.prototype.done = function(failures, fn) {
  3392. if (this.fileStream) {
  3393. this.fileStream.end(function() {
  3394. fn(failures);
  3395. });
  3396. } else {
  3397. fn(failures);
  3398. }
  3399. };
  3400. /**
  3401. * Write out the given line.
  3402. *
  3403. * @param {string} line
  3404. */
  3405. XUnit.prototype.write = function(line) {
  3406. if (this.fileStream) {
  3407. this.fileStream.write(line + '\n');
  3408. } else if (typeof process === 'object' && process.stdout) {
  3409. process.stdout.write(line + '\n');
  3410. } else {
  3411. console.log(line);
  3412. }
  3413. };
  3414. /**
  3415. * Output tag for the given `test.`
  3416. *
  3417. * @param {Test} test
  3418. */
  3419. XUnit.prototype.test = function(test) {
  3420. var attrs = {
  3421. classname: test.parent.fullTitle(),
  3422. name: test.title,
  3423. time: (test.duration / 1000) || 0
  3424. };
  3425. if (test.state === 'failed') {
  3426. var err = test.err;
  3427. this.write(tag('testcase', attrs, false, tag('failure', {}, false, escape(err.message) + '\n' + escape(err.stack))));
  3428. } else if (test.isPending()) {
  3429. this.write(tag('testcase', attrs, false, tag('skipped', {}, true)));
  3430. } else {
  3431. this.write(tag('testcase', attrs, true));
  3432. }
  3433. };
  3434. /**
  3435. * HTML tag helper.
  3436. *
  3437. * @param name
  3438. * @param attrs
  3439. * @param close
  3440. * @param content
  3441. * @return {string}
  3442. */
  3443. function tag(name, attrs, close, content) {
  3444. var end = close ? '/>' : '>';
  3445. var pairs = [];
  3446. var tag;
  3447. for (var key in attrs) {
  3448. if (Object.prototype.hasOwnProperty.call(attrs, key)) {
  3449. pairs.push(key + '="' + escape(attrs[key]) + '"');
  3450. }
  3451. }
  3452. tag = '<' + name + (pairs.length ? ' ' + pairs.join(' ') : '') + end;
  3453. if (content) {
  3454. tag += content + '</' + name + end;
  3455. }
  3456. return tag;
  3457. }
  3458. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3459. },{"../utils":38,"./base":17,"_process":67,"fs":42,"mkdirp":64,"path":42}],33:[function(require,module,exports){
  3460. (function (global){
  3461. /**
  3462. * Module dependencies.
  3463. */
  3464. var EventEmitter = require('events').EventEmitter;
  3465. var JSON = require('json3');
  3466. var Pending = require('./pending');
  3467. var debug = require('debug')('mocha:runnable');
  3468. var milliseconds = require('./ms');
  3469. var utils = require('./utils');
  3470. var create = require('lodash.create');
  3471. /**
  3472. * Save timer references to avoid Sinon interfering (see GH-237).
  3473. */
  3474. /* eslint-disable no-unused-vars, no-native-reassign */
  3475. var Date = global.Date;
  3476. var setTimeout = global.setTimeout;
  3477. var setInterval = global.setInterval;
  3478. var clearTimeout = global.clearTimeout;
  3479. var clearInterval = global.clearInterval;
  3480. /* eslint-enable no-unused-vars, no-native-reassign */
  3481. /**
  3482. * Object#toString().
  3483. */
  3484. var toString = Object.prototype.toString;
  3485. /**
  3486. * Expose `Runnable`.
  3487. */
  3488. module.exports = Runnable;
  3489. /**
  3490. * Initialize a new `Runnable` with the given `title` and callback `fn`.
  3491. *
  3492. * @param {String} title
  3493. * @param {Function} fn
  3494. * @api private
  3495. * @param {string} title
  3496. * @param {Function} fn
  3497. */
  3498. function Runnable(title, fn) {
  3499. this.title = title;
  3500. this.fn = fn;
  3501. this.body = (fn || '').toString();
  3502. this.async = fn && fn.length;
  3503. this.sync = !this.async;
  3504. this._timeout = 2000;
  3505. this._slow = 75;
  3506. this._enableTimeouts = true;
  3507. this.timedOut = false;
  3508. this._trace = new Error('done() called multiple times');
  3509. this._retries = -1;
  3510. this._currentRetry = 0;
  3511. this.pending = false;
  3512. }
  3513. /**
  3514. * Inherit from `EventEmitter.prototype`.
  3515. */
  3516. Runnable.prototype = create(EventEmitter.prototype, {
  3517. constructor: Runnable
  3518. });
  3519. /**
  3520. * Set & get timeout `ms`.
  3521. *
  3522. * @api private
  3523. * @param {number|string} ms
  3524. * @return {Runnable|number} ms or Runnable instance.
  3525. */
  3526. Runnable.prototype.timeout = function(ms) {
  3527. if (!arguments.length) {
  3528. return this._timeout;
  3529. }
  3530. // see #1652 for reasoning
  3531. if (ms === 0 || ms > Math.pow(2, 31)) {
  3532. this._enableTimeouts = false;
  3533. }
  3534. if (typeof ms === 'string') {
  3535. ms = milliseconds(ms);
  3536. }
  3537. debug('timeout %d', ms);
  3538. this._timeout = ms;
  3539. if (this.timer) {
  3540. this.resetTimeout();
  3541. }
  3542. return this;
  3543. };
  3544. /**
  3545. * Set & get slow `ms`.
  3546. *
  3547. * @api private
  3548. * @param {number|string} ms
  3549. * @return {Runnable|number} ms or Runnable instance.
  3550. */
  3551. Runnable.prototype.slow = function(ms) {
  3552. if (typeof ms === 'undefined') {
  3553. return this._slow;
  3554. }
  3555. if (typeof ms === 'string') {
  3556. ms = milliseconds(ms);
  3557. }
  3558. debug('timeout %d', ms);
  3559. this._slow = ms;
  3560. return this;
  3561. };
  3562. /**
  3563. * Set and get whether timeout is `enabled`.
  3564. *
  3565. * @api private
  3566. * @param {boolean} enabled
  3567. * @return {Runnable|boolean} enabled or Runnable instance.
  3568. */
  3569. Runnable.prototype.enableTimeouts = function(enabled) {
  3570. if (!arguments.length) {
  3571. return this._enableTimeouts;
  3572. }
  3573. debug('enableTimeouts %s', enabled);
  3574. this._enableTimeouts = enabled;
  3575. return this;
  3576. };
  3577. /**
  3578. * Halt and mark as pending.
  3579. *
  3580. * @api public
  3581. */
  3582. Runnable.prototype.skip = function() {
  3583. throw new Pending();
  3584. };
  3585. /**
  3586. * Check if this runnable or its parent suite is marked as pending.
  3587. *
  3588. * @api private
  3589. */
  3590. Runnable.prototype.isPending = function() {
  3591. return this.pending || (this.parent && this.parent.isPending());
  3592. };
  3593. /**
  3594. * Set number of retries.
  3595. *
  3596. * @api private
  3597. */
  3598. Runnable.prototype.retries = function(n) {
  3599. if (!arguments.length) {
  3600. return this._retries;
  3601. }
  3602. this._retries = n;
  3603. };
  3604. /**
  3605. * Get current retry
  3606. *
  3607. * @api private
  3608. */
  3609. Runnable.prototype.currentRetry = function(n) {
  3610. if (!arguments.length) {
  3611. return this._currentRetry;
  3612. }
  3613. this._currentRetry = n;
  3614. };
  3615. /**
  3616. * Return the full title generated by recursively concatenating the parent's
  3617. * full title.
  3618. *
  3619. * @api public
  3620. * @return {string}
  3621. */
  3622. Runnable.prototype.fullTitle = function() {
  3623. return this.parent.fullTitle() + ' ' + this.title;
  3624. };
  3625. /**
  3626. * Clear the timeout.
  3627. *
  3628. * @api private
  3629. */
  3630. Runnable.prototype.clearTimeout = function() {
  3631. clearTimeout(this.timer);
  3632. };
  3633. /**
  3634. * Inspect the runnable void of private properties.
  3635. *
  3636. * @api private
  3637. * @return {string}
  3638. */
  3639. Runnable.prototype.inspect = function() {
  3640. return JSON.stringify(this, function(key, val) {
  3641. if (key[0] === '_') {
  3642. return;
  3643. }
  3644. if (key === 'parent') {
  3645. return '#<Suite>';
  3646. }
  3647. if (key === 'ctx') {
  3648. return '#<Context>';
  3649. }
  3650. return val;
  3651. }, 2);
  3652. };
  3653. /**
  3654. * Reset the timeout.
  3655. *
  3656. * @api private
  3657. */
  3658. Runnable.prototype.resetTimeout = function() {
  3659. var self = this;
  3660. var ms = this.timeout() || 1e9;
  3661. if (!this._enableTimeouts) {
  3662. return;
  3663. }
  3664. this.clearTimeout();
  3665. this.timer = setTimeout(function() {
  3666. if (!self._enableTimeouts) {
  3667. return;
  3668. }
  3669. self.callback(new Error('timeout of ' + ms + 'ms exceeded. Ensure the done() callback is being called in this test.'));
  3670. self.timedOut = true;
  3671. }, ms);
  3672. };
  3673. /**
  3674. * Whitelist a list of globals for this test run.
  3675. *
  3676. * @api private
  3677. * @param {string[]} globals
  3678. */
  3679. Runnable.prototype.globals = function(globals) {
  3680. if (!arguments.length) {
  3681. return this._allowedGlobals;
  3682. }
  3683. this._allowedGlobals = globals;
  3684. };
  3685. /**
  3686. * Run the test and invoke `fn(err)`.
  3687. *
  3688. * @param {Function} fn
  3689. * @api private
  3690. */
  3691. Runnable.prototype.run = function(fn) {
  3692. var self = this;
  3693. var start = new Date();
  3694. var ctx = this.ctx;
  3695. var finished;
  3696. var emitted;
  3697. // Sometimes the ctx exists, but it is not runnable
  3698. if (ctx && ctx.runnable) {
  3699. ctx.runnable(this);
  3700. }
  3701. // called multiple times
  3702. function multiple(err) {
  3703. if (emitted) {
  3704. return;
  3705. }
  3706. emitted = true;
  3707. self.emit('error', err || new Error('done() called multiple times; stacktrace may be inaccurate'));
  3708. }
  3709. // finished
  3710. function done(err) {
  3711. var ms = self.timeout();
  3712. if (self.timedOut) {
  3713. return;
  3714. }
  3715. if (finished) {
  3716. return multiple(err || self._trace);
  3717. }
  3718. self.clearTimeout();
  3719. self.duration = new Date() - start;
  3720. finished = true;
  3721. if (!err && self.duration > ms && self._enableTimeouts) {
  3722. err = new Error('timeout of ' + ms + 'ms exceeded. Ensure the done() callback is being called in this test.');
  3723. }
  3724. fn(err);
  3725. }
  3726. // for .resetTimeout()
  3727. this.callback = done;
  3728. // explicit async with `done` argument
  3729. if (this.async) {
  3730. this.resetTimeout();
  3731. if (this.allowUncaught) {
  3732. return callFnAsync(this.fn);
  3733. }
  3734. try {
  3735. // allows skip() to be used in an explicit async context
  3736. this.skip = function() {
  3737. done(new Pending());
  3738. };
  3739. callFnAsync(this.fn);
  3740. } catch (err) {
  3741. done(utils.getError(err));
  3742. }
  3743. return;
  3744. }
  3745. if (this.allowUncaught) {
  3746. callFn(this.fn);
  3747. done();
  3748. return;
  3749. }
  3750. // sync or promise-returning
  3751. try {
  3752. if (this.isPending()) {
  3753. done();
  3754. } else {
  3755. callFn(this.fn);
  3756. }
  3757. } catch (err) {
  3758. done(utils.getError(err));
  3759. }
  3760. function callFn(fn) {
  3761. var result = fn.call(ctx);
  3762. if (result && typeof result.then === 'function') {
  3763. self.resetTimeout();
  3764. result
  3765. .then(function() {
  3766. done();
  3767. // Return null so libraries like bluebird do not warn about
  3768. // subsequently constructed Promises.
  3769. return null;
  3770. },
  3771. function(reason) {
  3772. done(reason || new Error('Promise rejected with no or falsy reason'));
  3773. });
  3774. } else {
  3775. if (self.asyncOnly) {
  3776. return done(new Error('--async-only option in use without declaring `done()` or returning a promise'));
  3777. }
  3778. done();
  3779. }
  3780. }
  3781. function callFnAsync(fn) {
  3782. var result = fn.call(ctx, function(err) {
  3783. if (err instanceof Error || toString.call(err) === '[object Error]') {
  3784. return done(err);
  3785. }
  3786. if (err) {
  3787. if (Object.prototype.toString.call(err) === '[object Object]') {
  3788. return done(new Error('done() invoked with non-Error: '
  3789. + JSON.stringify(err)));
  3790. }
  3791. return done(new Error('done() invoked with non-Error: ' + err));
  3792. }
  3793. if (result && utils.isPromise(result)) {
  3794. return done(new Error('Resolution method is overspecified. Specify a callback *or* return a Promise; not both.'));
  3795. }
  3796. done();
  3797. });
  3798. }
  3799. };
  3800. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3801. },{"./ms":15,"./pending":16,"./utils":38,"debug":2,"events":3,"json3":54,"lodash.create":60}],34:[function(require,module,exports){
  3802. (function (process,global){
  3803. /**
  3804. * Module dependencies.
  3805. */
  3806. var EventEmitter = require('events').EventEmitter;
  3807. var Pending = require('./pending');
  3808. var utils = require('./utils');
  3809. var inherits = utils.inherits;
  3810. var debug = require('debug')('mocha:runner');
  3811. var Runnable = require('./runnable');
  3812. var filter = utils.filter;
  3813. var indexOf = utils.indexOf;
  3814. var some = utils.some;
  3815. var keys = utils.keys;
  3816. var stackFilter = utils.stackTraceFilter();
  3817. var stringify = utils.stringify;
  3818. var type = utils.type;
  3819. var undefinedError = utils.undefinedError;
  3820. var isArray = utils.isArray;
  3821. /**
  3822. * Non-enumerable globals.
  3823. */
  3824. var globals = [
  3825. 'setTimeout',
  3826. 'clearTimeout',
  3827. 'setInterval',
  3828. 'clearInterval',
  3829. 'XMLHttpRequest',
  3830. 'Date',
  3831. 'setImmediate',
  3832. 'clearImmediate'
  3833. ];
  3834. /**
  3835. * Expose `Runner`.
  3836. */
  3837. module.exports = Runner;
  3838. /**
  3839. * Initialize a `Runner` for the given `suite`.
  3840. *
  3841. * Events:
  3842. *
  3843. * - `start` execution started
  3844. * - `end` execution complete
  3845. * - `suite` (suite) test suite execution started
  3846. * - `suite end` (suite) all tests (and sub-suites) have finished
  3847. * - `test` (test) test execution started
  3848. * - `test end` (test) test completed
  3849. * - `hook` (hook) hook execution started
  3850. * - `hook end` (hook) hook complete
  3851. * - `pass` (test) test passed
  3852. * - `fail` (test, err) test failed
  3853. * - `pending` (test) test pending
  3854. *
  3855. * @api public
  3856. * @param {Suite} suite Root suite
  3857. * @param {boolean} [delay] Whether or not to delay execution of root suite
  3858. * until ready.
  3859. */
  3860. function Runner(suite, delay) {
  3861. var self = this;
  3862. this._globals = [];
  3863. this._abort = false;
  3864. this._delay = delay;
  3865. this.suite = suite;
  3866. this.started = false;
  3867. this.total = suite.total();
  3868. this.failures = 0;
  3869. this.on('test end', function(test) {
  3870. self.checkGlobals(test);
  3871. });
  3872. this.on('hook end', function(hook) {
  3873. self.checkGlobals(hook);
  3874. });
  3875. this._defaultGrep = /.*/;
  3876. this.grep(this._defaultGrep);
  3877. this.globals(this.globalProps().concat(extraGlobals()));
  3878. }
  3879. /**
  3880. * Wrapper for setImmediate, process.nextTick, or browser polyfill.
  3881. *
  3882. * @param {Function} fn
  3883. * @api private
  3884. */
  3885. Runner.immediately = global.setImmediate || process.nextTick;
  3886. /**
  3887. * Inherit from `EventEmitter.prototype`.
  3888. */
  3889. inherits(Runner, EventEmitter);
  3890. /**
  3891. * Run tests with full titles matching `re`. Updates runner.total
  3892. * with number of tests matched.
  3893. *
  3894. * @param {RegExp} re
  3895. * @param {Boolean} invert
  3896. * @return {Runner} for chaining
  3897. * @api public
  3898. * @param {RegExp} re
  3899. * @param {boolean} invert
  3900. * @return {Runner} Runner instance.
  3901. */
  3902. Runner.prototype.grep = function(re, invert) {
  3903. debug('grep %s', re);
  3904. this._grep = re;
  3905. this._invert = invert;
  3906. this.total = this.grepTotal(this.suite);
  3907. return this;
  3908. };
  3909. /**
  3910. * Returns the number of tests matching the grep search for the
  3911. * given suite.
  3912. *
  3913. * @param {Suite} suite
  3914. * @return {Number}
  3915. * @api public
  3916. * @param {Suite} suite
  3917. * @return {number}
  3918. */
  3919. Runner.prototype.grepTotal = function(suite) {
  3920. var self = this;
  3921. var total = 0;
  3922. suite.eachTest(function(test) {
  3923. var match = self._grep.test(test.fullTitle());
  3924. if (self._invert) {
  3925. match = !match;
  3926. }
  3927. if (match) {
  3928. total++;
  3929. }
  3930. });
  3931. return total;
  3932. };
  3933. /**
  3934. * Return a list of global properties.
  3935. *
  3936. * @return {Array}
  3937. * @api private
  3938. */
  3939. Runner.prototype.globalProps = function() {
  3940. var props = keys(global);
  3941. // non-enumerables
  3942. for (var i = 0; i < globals.length; ++i) {
  3943. if (~indexOf(props, globals[i])) {
  3944. continue;
  3945. }
  3946. props.push(globals[i]);
  3947. }
  3948. return props;
  3949. };
  3950. /**
  3951. * Allow the given `arr` of globals.
  3952. *
  3953. * @param {Array} arr
  3954. * @return {Runner} for chaining
  3955. * @api public
  3956. * @param {Array} arr
  3957. * @return {Runner} Runner instance.
  3958. */
  3959. Runner.prototype.globals = function(arr) {
  3960. if (!arguments.length) {
  3961. return this._globals;
  3962. }
  3963. debug('globals %j', arr);
  3964. this._globals = this._globals.concat(arr);
  3965. return this;
  3966. };
  3967. /**
  3968. * Check for global variable leaks.
  3969. *
  3970. * @api private
  3971. */
  3972. Runner.prototype.checkGlobals = function(test) {
  3973. if (this.ignoreLeaks) {
  3974. return;
  3975. }
  3976. var ok = this._globals;
  3977. var globals = this.globalProps();
  3978. var leaks;
  3979. if (test) {
  3980. ok = ok.concat(test._allowedGlobals || []);
  3981. }
  3982. if (this.prevGlobalsLength === globals.length) {
  3983. return;
  3984. }
  3985. this.prevGlobalsLength = globals.length;
  3986. leaks = filterLeaks(ok, globals);
  3987. this._globals = this._globals.concat(leaks);
  3988. if (leaks.length > 1) {
  3989. this.fail(test, new Error('global leaks detected: ' + leaks.join(', ') + ''));
  3990. } else if (leaks.length) {
  3991. this.fail(test, new Error('global leak detected: ' + leaks[0]));
  3992. }
  3993. };
  3994. /**
  3995. * Fail the given `test`.
  3996. *
  3997. * @api private
  3998. * @param {Test} test
  3999. * @param {Error} err
  4000. */
  4001. Runner.prototype.fail = function(test, err) {
  4002. ++this.failures;
  4003. test.state = 'failed';
  4004. if (!(err instanceof Error || err && typeof err.message === 'string')) {
  4005. err = new Error('the ' + type(err) + ' ' + stringify(err) + ' was thrown, throw an Error :)');
  4006. }
  4007. err.stack = (this.fullStackTrace || !err.stack)
  4008. ? err.stack
  4009. : stackFilter(err.stack);
  4010. this.emit('fail', test, err);
  4011. };
  4012. /**
  4013. * Fail the given `hook` with `err`.
  4014. *
  4015. * Hook failures work in the following pattern:
  4016. * - If bail, then exit
  4017. * - Failed `before` hook skips all tests in a suite and subsuites,
  4018. * but jumps to corresponding `after` hook
  4019. * - Failed `before each` hook skips remaining tests in a
  4020. * suite and jumps to corresponding `after each` hook,
  4021. * which is run only once
  4022. * - Failed `after` hook does not alter
  4023. * execution order
  4024. * - Failed `after each` hook skips remaining tests in a
  4025. * suite and subsuites, but executes other `after each`
  4026. * hooks
  4027. *
  4028. * @api private
  4029. * @param {Hook} hook
  4030. * @param {Error} err
  4031. */
  4032. Runner.prototype.failHook = function(hook, err) {
  4033. if (hook.ctx && hook.ctx.currentTest) {
  4034. hook.originalTitle = hook.originalTitle || hook.title;
  4035. hook.title = hook.originalTitle + ' for "' + hook.ctx.currentTest.title + '"';
  4036. }
  4037. this.fail(hook, err);
  4038. if (this.suite.bail()) {
  4039. this.emit('end');
  4040. }
  4041. };
  4042. /**
  4043. * Run hook `name` callbacks and then invoke `fn()`.
  4044. *
  4045. * @api private
  4046. * @param {string} name
  4047. * @param {Function} fn
  4048. */
  4049. Runner.prototype.hook = function(name, fn) {
  4050. var suite = this.suite;
  4051. var hooks = suite['_' + name];
  4052. var self = this;
  4053. function next(i) {
  4054. var hook = hooks[i];
  4055. if (!hook) {
  4056. return fn();
  4057. }
  4058. self.currentRunnable = hook;
  4059. hook.ctx.currentTest = self.test;
  4060. self.emit('hook', hook);
  4061. if (!hook.listeners('error').length) {
  4062. hook.on('error', function(err) {
  4063. self.failHook(hook, err);
  4064. });
  4065. }
  4066. hook.run(function(err) {
  4067. var testError = hook.error();
  4068. if (testError) {
  4069. self.fail(self.test, testError);
  4070. }
  4071. if (err) {
  4072. if (err instanceof Pending) {
  4073. if (name === 'beforeEach' || name === 'afterEach') {
  4074. self.test.pending = true;
  4075. } else {
  4076. suite.tests.forEach(function(test) {
  4077. test.pending = true;
  4078. });
  4079. }
  4080. } else {
  4081. self.failHook(hook, err);
  4082. // stop executing hooks, notify callee of hook err
  4083. return fn(err);
  4084. }
  4085. }
  4086. self.emit('hook end', hook);
  4087. delete hook.ctx.currentTest;
  4088. next(++i);
  4089. });
  4090. }
  4091. Runner.immediately(function() {
  4092. next(0);
  4093. });
  4094. };
  4095. /**
  4096. * Run hook `name` for the given array of `suites`
  4097. * in order, and callback `fn(err, errSuite)`.
  4098. *
  4099. * @api private
  4100. * @param {string} name
  4101. * @param {Array} suites
  4102. * @param {Function} fn
  4103. */
  4104. Runner.prototype.hooks = function(name, suites, fn) {
  4105. var self = this;
  4106. var orig = this.suite;
  4107. function next(suite) {
  4108. self.suite = suite;
  4109. if (!suite) {
  4110. self.suite = orig;
  4111. return fn();
  4112. }
  4113. self.hook(name, function(err) {
  4114. if (err) {
  4115. var errSuite = self.suite;
  4116. self.suite = orig;
  4117. return fn(err, errSuite);
  4118. }
  4119. next(suites.pop());
  4120. });
  4121. }
  4122. next(suites.pop());
  4123. };
  4124. /**
  4125. * Run hooks from the top level down.
  4126. *
  4127. * @param {String} name
  4128. * @param {Function} fn
  4129. * @api private
  4130. */
  4131. Runner.prototype.hookUp = function(name, fn) {
  4132. var suites = [this.suite].concat(this.parents()).reverse();
  4133. this.hooks(name, suites, fn);
  4134. };
  4135. /**
  4136. * Run hooks from the bottom up.
  4137. *
  4138. * @param {String} name
  4139. * @param {Function} fn
  4140. * @api private
  4141. */
  4142. Runner.prototype.hookDown = function(name, fn) {
  4143. var suites = [this.suite].concat(this.parents());
  4144. this.hooks(name, suites, fn);
  4145. };
  4146. /**
  4147. * Return an array of parent Suites from
  4148. * closest to furthest.
  4149. *
  4150. * @return {Array}
  4151. * @api private
  4152. */
  4153. Runner.prototype.parents = function() {
  4154. var suite = this.suite;
  4155. var suites = [];
  4156. while (suite.parent) {
  4157. suite = suite.parent;
  4158. suites.push(suite);
  4159. }
  4160. return suites;
  4161. };
  4162. /**
  4163. * Run the current test and callback `fn(err)`.
  4164. *
  4165. * @param {Function} fn
  4166. * @api private
  4167. */
  4168. Runner.prototype.runTest = function(fn) {
  4169. var self = this;
  4170. var test = this.test;
  4171. if (this.asyncOnly) {
  4172. test.asyncOnly = true;
  4173. }
  4174. if (this.allowUncaught) {
  4175. test.allowUncaught = true;
  4176. return test.run(fn);
  4177. }
  4178. try {
  4179. test.on('error', function(err) {
  4180. self.fail(test, err);
  4181. });
  4182. test.run(fn);
  4183. } catch (err) {
  4184. fn(err);
  4185. }
  4186. };
  4187. /**
  4188. * Run tests in the given `suite` and invoke the callback `fn()` when complete.
  4189. *
  4190. * @api private
  4191. * @param {Suite} suite
  4192. * @param {Function} fn
  4193. */
  4194. Runner.prototype.runTests = function(suite, fn) {
  4195. var self = this;
  4196. var tests = suite.tests.slice();
  4197. var test;
  4198. function hookErr(_, errSuite, after) {
  4199. // before/after Each hook for errSuite failed:
  4200. var orig = self.suite;
  4201. // for failed 'after each' hook start from errSuite parent,
  4202. // otherwise start from errSuite itself
  4203. self.suite = after ? errSuite.parent : errSuite;
  4204. if (self.suite) {
  4205. // call hookUp afterEach
  4206. self.hookUp('afterEach', function(err2, errSuite2) {
  4207. self.suite = orig;
  4208. // some hooks may fail even now
  4209. if (err2) {
  4210. return hookErr(err2, errSuite2, true);
  4211. }
  4212. // report error suite
  4213. fn(errSuite);
  4214. });
  4215. } else {
  4216. // there is no need calling other 'after each' hooks
  4217. self.suite = orig;
  4218. fn(errSuite);
  4219. }
  4220. }
  4221. function next(err, errSuite) {
  4222. // if we bail after first err
  4223. if (self.failures && suite._bail) {
  4224. return fn();
  4225. }
  4226. if (self._abort) {
  4227. return fn();
  4228. }
  4229. if (err) {
  4230. return hookErr(err, errSuite, true);
  4231. }
  4232. // next test
  4233. test = tests.shift();
  4234. // all done
  4235. if (!test) {
  4236. return fn();
  4237. }
  4238. // grep
  4239. var match = self._grep.test(test.fullTitle());
  4240. if (self._invert) {
  4241. match = !match;
  4242. }
  4243. if (!match) {
  4244. // Run immediately only if we have defined a grep. When we
  4245. // define a grep — It can cause maximum callstack error if
  4246. // the grep is doing a large recursive loop by neglecting
  4247. // all tests. The run immediately function also comes with
  4248. // a performance cost. So we don't want to run immediately
  4249. // if we run the whole test suite, because running the whole
  4250. // test suite don't do any immediate recursive loops. Thus,
  4251. // allowing a JS runtime to breathe.
  4252. if (self._grep !== self._defaultGrep) {
  4253. Runner.immediately(next);
  4254. } else {
  4255. next();
  4256. }
  4257. return;
  4258. }
  4259. if (test.isPending()) {
  4260. self.emit('pending', test);
  4261. self.emit('test end', test);
  4262. return next();
  4263. }
  4264. // execute test and hook(s)
  4265. self.emit('test', self.test = test);
  4266. self.hookDown('beforeEach', function(err, errSuite) {
  4267. if (test.isPending()) {
  4268. self.emit('pending', test);
  4269. self.emit('test end', test);
  4270. return next();
  4271. }
  4272. if (err) {
  4273. return hookErr(err, errSuite, false);
  4274. }
  4275. self.currentRunnable = self.test;
  4276. self.runTest(function(err) {
  4277. test = self.test;
  4278. if (err) {
  4279. var retry = test.currentRetry();
  4280. if (err instanceof Pending) {
  4281. test.pending = true;
  4282. self.emit('pending', test);
  4283. } else if (retry < test.retries()) {
  4284. var clonedTest = test.clone();
  4285. clonedTest.currentRetry(retry + 1);
  4286. tests.unshift(clonedTest);
  4287. // Early return + hook trigger so that it doesn't
  4288. // increment the count wrong
  4289. return self.hookUp('afterEach', next);
  4290. } else {
  4291. self.fail(test, err);
  4292. }
  4293. self.emit('test end', test);
  4294. if (err instanceof Pending) {
  4295. return next();
  4296. }
  4297. return self.hookUp('afterEach', next);
  4298. }
  4299. test.state = 'passed';
  4300. self.emit('pass', test);
  4301. self.emit('test end', test);
  4302. self.hookUp('afterEach', next);
  4303. });
  4304. });
  4305. }
  4306. this.next = next;
  4307. this.hookErr = hookErr;
  4308. next();
  4309. };
  4310. /**
  4311. * Run the given `suite` and invoke the callback `fn()` when complete.
  4312. *
  4313. * @api private
  4314. * @param {Suite} suite
  4315. * @param {Function} fn
  4316. */
  4317. Runner.prototype.runSuite = function(suite, fn) {
  4318. var i = 0;
  4319. var self = this;
  4320. var total = this.grepTotal(suite);
  4321. var afterAllHookCalled = false;
  4322. debug('run suite %s', suite.fullTitle());
  4323. if (!total || (self.failures && suite._bail)) {
  4324. return fn();
  4325. }
  4326. this.emit('suite', this.suite = suite);
  4327. function next(errSuite) {
  4328. if (errSuite) {
  4329. // current suite failed on a hook from errSuite
  4330. if (errSuite === suite) {
  4331. // if errSuite is current suite
  4332. // continue to the next sibling suite
  4333. return done();
  4334. }
  4335. // errSuite is among the parents of current suite
  4336. // stop execution of errSuite and all sub-suites
  4337. return done(errSuite);
  4338. }
  4339. if (self._abort) {
  4340. return done();
  4341. }
  4342. var curr = suite.suites[i++];
  4343. if (!curr) {
  4344. return done();
  4345. }
  4346. // Avoid grep neglecting large number of tests causing a
  4347. // huge recursive loop and thus a maximum call stack error.
  4348. // See comment in `this.runTests()` for more information.
  4349. if (self._grep !== self._defaultGrep) {
  4350. Runner.immediately(function() {
  4351. self.runSuite(curr, next);
  4352. });
  4353. } else {
  4354. self.runSuite(curr, next);
  4355. }
  4356. }
  4357. function done(errSuite) {
  4358. self.suite = suite;
  4359. self.nextSuite = next;
  4360. if (afterAllHookCalled) {
  4361. fn(errSuite);
  4362. } else {
  4363. // mark that the afterAll block has been called once
  4364. // and so can be skipped if there is an error in it.
  4365. afterAllHookCalled = true;
  4366. // remove reference to test
  4367. delete self.test;
  4368. self.hook('afterAll', function() {
  4369. self.emit('suite end', suite);
  4370. fn(errSuite);
  4371. });
  4372. }
  4373. }
  4374. this.nextSuite = next;
  4375. this.hook('beforeAll', function(err) {
  4376. if (err) {
  4377. return done();
  4378. }
  4379. self.runTests(suite, next);
  4380. });
  4381. };
  4382. /**
  4383. * Handle uncaught exceptions.
  4384. *
  4385. * @param {Error} err
  4386. * @api private
  4387. */
  4388. Runner.prototype.uncaught = function(err) {
  4389. if (err) {
  4390. debug('uncaught exception %s', err !== function() {
  4391. return this;
  4392. }.call(err) ? err : (err.message || err));
  4393. } else {
  4394. debug('uncaught undefined exception');
  4395. err = undefinedError();
  4396. }
  4397. err.uncaught = true;
  4398. var runnable = this.currentRunnable;
  4399. if (!runnable) {
  4400. runnable = new Runnable('Uncaught error outside test suite');
  4401. runnable.parent = this.suite;
  4402. if (this.started) {
  4403. this.fail(runnable, err);
  4404. } else {
  4405. // Can't recover from this failure
  4406. this.emit('start');
  4407. this.fail(runnable, err);
  4408. this.emit('end');
  4409. }
  4410. return;
  4411. }
  4412. runnable.clearTimeout();
  4413. // Ignore errors if complete
  4414. if (runnable.state) {
  4415. return;
  4416. }
  4417. this.fail(runnable, err);
  4418. // recover from test
  4419. if (runnable.type === 'test') {
  4420. this.emit('test end', runnable);
  4421. this.hookUp('afterEach', this.next);
  4422. return;
  4423. }
  4424. // recover from hooks
  4425. if (runnable.type === 'hook') {
  4426. var errSuite = this.suite;
  4427. // if hook failure is in afterEach block
  4428. if (runnable.fullTitle().indexOf('after each') > -1) {
  4429. return this.hookErr(err, errSuite, true);
  4430. }
  4431. // if hook failure is in beforeEach block
  4432. if (runnable.fullTitle().indexOf('before each') > -1) {
  4433. return this.hookErr(err, errSuite, false);
  4434. }
  4435. // if hook failure is in after or before blocks
  4436. return this.nextSuite(errSuite);
  4437. }
  4438. // bail
  4439. this.emit('end');
  4440. };
  4441. /**
  4442. * Cleans up the references to all the deferred functions
  4443. * (before/after/beforeEach/afterEach) and tests of a Suite.
  4444. * These must be deleted otherwise a memory leak can happen,
  4445. * as those functions may reference variables from closures,
  4446. * thus those variables can never be garbage collected as long
  4447. * as the deferred functions exist.
  4448. *
  4449. * @param {Suite} suite
  4450. */
  4451. function cleanSuiteReferences(suite) {
  4452. function cleanArrReferences(arr) {
  4453. for (var i = 0; i < arr.length; i++) {
  4454. delete arr[i].fn;
  4455. }
  4456. }
  4457. if (isArray(suite._beforeAll)) {
  4458. cleanArrReferences(suite._beforeAll);
  4459. }
  4460. if (isArray(suite._beforeEach)) {
  4461. cleanArrReferences(suite._beforeEach);
  4462. }
  4463. if (isArray(suite._afterAll)) {
  4464. cleanArrReferences(suite._afterAll);
  4465. }
  4466. if (isArray(suite._afterEach)) {
  4467. cleanArrReferences(suite._afterEach);
  4468. }
  4469. for (var i = 0; i < suite.tests.length; i++) {
  4470. delete suite.tests[i].fn;
  4471. }
  4472. }
  4473. /**
  4474. * Run the root suite and invoke `fn(failures)`
  4475. * on completion.
  4476. *
  4477. * @param {Function} fn
  4478. * @return {Runner} for chaining
  4479. * @api public
  4480. * @param {Function} fn
  4481. * @return {Runner} Runner instance.
  4482. */
  4483. Runner.prototype.run = function(fn) {
  4484. var self = this;
  4485. var rootSuite = this.suite;
  4486. // If there is an `only` filter
  4487. if (this.hasOnly) {
  4488. filterOnly(rootSuite);
  4489. }
  4490. fn = fn || function() {};
  4491. function uncaught(err) {
  4492. self.uncaught(err);
  4493. }
  4494. function start() {
  4495. self.started = true;
  4496. self.emit('start');
  4497. self.runSuite(rootSuite, function() {
  4498. debug('finished running');
  4499. self.emit('end');
  4500. });
  4501. }
  4502. debug('start');
  4503. // references cleanup to avoid memory leaks
  4504. this.on('suite end', cleanSuiteReferences);
  4505. // callback
  4506. this.on('end', function() {
  4507. debug('end');
  4508. process.removeListener('uncaughtException', uncaught);
  4509. fn(self.failures);
  4510. });
  4511. // uncaught exception
  4512. process.on('uncaughtException', uncaught);
  4513. if (this._delay) {
  4514. // for reporters, I guess.
  4515. // might be nice to debounce some dots while we wait.
  4516. this.emit('waiting', rootSuite);
  4517. rootSuite.once('run', start);
  4518. } else {
  4519. start();
  4520. }
  4521. return this;
  4522. };
  4523. /**
  4524. * Cleanly abort execution.
  4525. *
  4526. * @api public
  4527. * @return {Runner} Runner instance.
  4528. */
  4529. Runner.prototype.abort = function() {
  4530. debug('aborting');
  4531. this._abort = true;
  4532. return this;
  4533. };
  4534. /**
  4535. * Filter suites based on `isOnly` logic.
  4536. *
  4537. * @param {Array} suite
  4538. * @returns {Boolean}
  4539. * @api private
  4540. */
  4541. function filterOnly(suite) {
  4542. if (suite._onlyTests.length) {
  4543. // If the suite contains `only` tests, run those and ignore any nested suites.
  4544. suite.tests = suite._onlyTests;
  4545. suite.suites = [];
  4546. } else {
  4547. // Otherwise, do not run any of the tests in this suite.
  4548. suite.tests = [];
  4549. suite._onlySuites.forEach(function(onlySuite) {
  4550. // If there are other `only` tests/suites nested in the current `only` suite, then filter that `only` suite.
  4551. // Otherwise, all of the tests on this `only` suite should be run, so don't filter it.
  4552. if (hasOnly(onlySuite)) {
  4553. filterOnly(onlySuite);
  4554. }
  4555. });
  4556. // Run the `only` suites, as well as any other suites that have `only` tests/suites as descendants.
  4557. suite.suites = filter(suite.suites, function(childSuite) {
  4558. return indexOf(suite._onlySuites, childSuite) !== -1 || filterOnly(childSuite);
  4559. });
  4560. }
  4561. // Keep the suite only if there is something to run
  4562. return suite.tests.length || suite.suites.length;
  4563. }
  4564. /**
  4565. * Determines whether a suite has an `only` test or suite as a descendant.
  4566. *
  4567. * @param {Array} suite
  4568. * @returns {Boolean}
  4569. * @api private
  4570. */
  4571. function hasOnly(suite) {
  4572. return suite._onlyTests.length || suite._onlySuites.length || some(suite.suites, hasOnly);
  4573. }
  4574. /**
  4575. * Filter leaks with the given globals flagged as `ok`.
  4576. *
  4577. * @api private
  4578. * @param {Array} ok
  4579. * @param {Array} globals
  4580. * @return {Array}
  4581. */
  4582. function filterLeaks(ok, globals) {
  4583. return filter(globals, function(key) {
  4584. // Firefox and Chrome exposes iframes as index inside the window object
  4585. if (/^d+/.test(key)) {
  4586. return false;
  4587. }
  4588. // in firefox
  4589. // if runner runs in an iframe, this iframe's window.getInterface method
  4590. // not init at first it is assigned in some seconds
  4591. if (global.navigator && (/^getInterface/).test(key)) {
  4592. return false;
  4593. }
  4594. // an iframe could be approached by window[iframeIndex]
  4595. // in ie6,7,8 and opera, iframeIndex is enumerable, this could cause leak
  4596. if (global.navigator && (/^\d+/).test(key)) {
  4597. return false;
  4598. }
  4599. // Opera and IE expose global variables for HTML element IDs (issue #243)
  4600. if (/^mocha-/.test(key)) {
  4601. return false;
  4602. }
  4603. var matched = filter(ok, function(ok) {
  4604. if (~ok.indexOf('*')) {
  4605. return key.indexOf(ok.split('*')[0]) === 0;
  4606. }
  4607. return key === ok;
  4608. });
  4609. return !matched.length && (!global.navigator || key !== 'onerror');
  4610. });
  4611. }
  4612. /**
  4613. * Array of globals dependent on the environment.
  4614. *
  4615. * @return {Array}
  4616. * @api private
  4617. */
  4618. function extraGlobals() {
  4619. if (typeof process === 'object' && typeof process.version === 'string') {
  4620. var parts = process.version.split('.');
  4621. var nodeVersion = utils.reduce(parts, function(a, v) {
  4622. return a << 8 | v;
  4623. });
  4624. // 'errno' was renamed to process._errno in v0.9.11.
  4625. if (nodeVersion < 0x00090B) {
  4626. return ['errno'];
  4627. }
  4628. }
  4629. return [];
  4630. }
  4631. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  4632. },{"./pending":16,"./runnable":33,"./utils":38,"_process":67,"debug":2,"events":3}],35:[function(require,module,exports){
  4633. /**
  4634. * Module dependencies.
  4635. */
  4636. var EventEmitter = require('events').EventEmitter;
  4637. var Hook = require('./hook');
  4638. var utils = require('./utils');
  4639. var inherits = utils.inherits;
  4640. var debug = require('debug')('mocha:suite');
  4641. var milliseconds = require('./ms');
  4642. /**
  4643. * Expose `Suite`.
  4644. */
  4645. exports = module.exports = Suite;
  4646. /**
  4647. * Create a new `Suite` with the given `title` and parent `Suite`. When a suite
  4648. * with the same title is already present, that suite is returned to provide
  4649. * nicer reporter and more flexible meta-testing.
  4650. *
  4651. * @api public
  4652. * @param {Suite} parent
  4653. * @param {string} title
  4654. * @return {Suite}
  4655. */
  4656. exports.create = function(parent, title) {
  4657. var suite = new Suite(title, parent.ctx);
  4658. suite.parent = parent;
  4659. title = suite.fullTitle();
  4660. parent.addSuite(suite);
  4661. return suite;
  4662. };
  4663. /**
  4664. * Initialize a new `Suite` with the given `title` and `ctx`.
  4665. *
  4666. * @api private
  4667. * @param {string} title
  4668. * @param {Context} parentContext
  4669. */
  4670. function Suite(title, parentContext) {
  4671. if (!utils.isString(title)) {
  4672. throw new Error('Suite `title` should be a "string" but "' + typeof title + '" was given instead.');
  4673. }
  4674. this.title = title;
  4675. function Context() {}
  4676. Context.prototype = parentContext;
  4677. this.ctx = new Context();
  4678. this.suites = [];
  4679. this.tests = [];
  4680. this.pending = false;
  4681. this._beforeEach = [];
  4682. this._beforeAll = [];
  4683. this._afterEach = [];
  4684. this._afterAll = [];
  4685. this.root = !title;
  4686. this._timeout = 2000;
  4687. this._enableTimeouts = true;
  4688. this._slow = 75;
  4689. this._bail = false;
  4690. this._retries = -1;
  4691. this._onlyTests = [];
  4692. this._onlySuites = [];
  4693. this.delayed = false;
  4694. }
  4695. /**
  4696. * Inherit from `EventEmitter.prototype`.
  4697. */
  4698. inherits(Suite, EventEmitter);
  4699. /**
  4700. * Return a clone of this `Suite`.
  4701. *
  4702. * @api private
  4703. * @return {Suite}
  4704. */
  4705. Suite.prototype.clone = function() {
  4706. var suite = new Suite(this.title);
  4707. debug('clone');
  4708. suite.ctx = this.ctx;
  4709. suite.timeout(this.timeout());
  4710. suite.retries(this.retries());
  4711. suite.enableTimeouts(this.enableTimeouts());
  4712. suite.slow(this.slow());
  4713. suite.bail(this.bail());
  4714. return suite;
  4715. };
  4716. /**
  4717. * Set timeout `ms` or short-hand such as "2s".
  4718. *
  4719. * @api private
  4720. * @param {number|string} ms
  4721. * @return {Suite|number} for chaining
  4722. */
  4723. Suite.prototype.timeout = function(ms) {
  4724. if (!arguments.length) {
  4725. return this._timeout;
  4726. }
  4727. if (ms.toString() === '0') {
  4728. this._enableTimeouts = false;
  4729. }
  4730. if (typeof ms === 'string') {
  4731. ms = milliseconds(ms);
  4732. }
  4733. debug('timeout %d', ms);
  4734. this._timeout = parseInt(ms, 10);
  4735. return this;
  4736. };
  4737. /**
  4738. * Set number of times to retry a failed test.
  4739. *
  4740. * @api private
  4741. * @param {number|string} n
  4742. * @return {Suite|number} for chaining
  4743. */
  4744. Suite.prototype.retries = function(n) {
  4745. if (!arguments.length) {
  4746. return this._retries;
  4747. }
  4748. debug('retries %d', n);
  4749. this._retries = parseInt(n, 10) || 0;
  4750. return this;
  4751. };
  4752. /**
  4753. * Set timeout to `enabled`.
  4754. *
  4755. * @api private
  4756. * @param {boolean} enabled
  4757. * @return {Suite|boolean} self or enabled
  4758. */
  4759. Suite.prototype.enableTimeouts = function(enabled) {
  4760. if (!arguments.length) {
  4761. return this._enableTimeouts;
  4762. }
  4763. debug('enableTimeouts %s', enabled);
  4764. this._enableTimeouts = enabled;
  4765. return this;
  4766. };
  4767. /**
  4768. * Set slow `ms` or short-hand such as "2s".
  4769. *
  4770. * @api private
  4771. * @param {number|string} ms
  4772. * @return {Suite|number} for chaining
  4773. */
  4774. Suite.prototype.slow = function(ms) {
  4775. if (!arguments.length) {
  4776. return this._slow;
  4777. }
  4778. if (typeof ms === 'string') {
  4779. ms = milliseconds(ms);
  4780. }
  4781. debug('slow %d', ms);
  4782. this._slow = ms;
  4783. return this;
  4784. };
  4785. /**
  4786. * Sets whether to bail after first error.
  4787. *
  4788. * @api private
  4789. * @param {boolean} bail
  4790. * @return {Suite|number} for chaining
  4791. */
  4792. Suite.prototype.bail = function(bail) {
  4793. if (!arguments.length) {
  4794. return this._bail;
  4795. }
  4796. debug('bail %s', bail);
  4797. this._bail = bail;
  4798. return this;
  4799. };
  4800. /**
  4801. * Check if this suite or its parent suite is marked as pending.
  4802. *
  4803. * @api private
  4804. */
  4805. Suite.prototype.isPending = function() {
  4806. return this.pending || (this.parent && this.parent.isPending());
  4807. };
  4808. /**
  4809. * Run `fn(test[, done])` before running tests.
  4810. *
  4811. * @api private
  4812. * @param {string} title
  4813. * @param {Function} fn
  4814. * @return {Suite} for chaining
  4815. */
  4816. Suite.prototype.beforeAll = function(title, fn) {
  4817. if (this.isPending()) {
  4818. return this;
  4819. }
  4820. if (typeof title === 'function') {
  4821. fn = title;
  4822. title = fn.name;
  4823. }
  4824. title = '"before all" hook' + (title ? ': ' + title : '');
  4825. var hook = new Hook(title, fn);
  4826. hook.parent = this;
  4827. hook.timeout(this.timeout());
  4828. hook.retries(this.retries());
  4829. hook.enableTimeouts(this.enableTimeouts());
  4830. hook.slow(this.slow());
  4831. hook.ctx = this.ctx;
  4832. this._beforeAll.push(hook);
  4833. this.emit('beforeAll', hook);
  4834. return this;
  4835. };
  4836. /**
  4837. * Run `fn(test[, done])` after running tests.
  4838. *
  4839. * @api private
  4840. * @param {string} title
  4841. * @param {Function} fn
  4842. * @return {Suite} for chaining
  4843. */
  4844. Suite.prototype.afterAll = function(title, fn) {
  4845. if (this.isPending()) {
  4846. return this;
  4847. }
  4848. if (typeof title === 'function') {
  4849. fn = title;
  4850. title = fn.name;
  4851. }
  4852. title = '"after all" hook' + (title ? ': ' + title : '');
  4853. var hook = new Hook(title, fn);
  4854. hook.parent = this;
  4855. hook.timeout(this.timeout());
  4856. hook.retries(this.retries());
  4857. hook.enableTimeouts(this.enableTimeouts());
  4858. hook.slow(this.slow());
  4859. hook.ctx = this.ctx;
  4860. this._afterAll.push(hook);
  4861. this.emit('afterAll', hook);
  4862. return this;
  4863. };
  4864. /**
  4865. * Run `fn(test[, done])` before each test case.
  4866. *
  4867. * @api private
  4868. * @param {string} title
  4869. * @param {Function} fn
  4870. * @return {Suite} for chaining
  4871. */
  4872. Suite.prototype.beforeEach = function(title, fn) {
  4873. if (this.isPending()) {
  4874. return this;
  4875. }
  4876. if (typeof title === 'function') {
  4877. fn = title;
  4878. title = fn.name;
  4879. }
  4880. title = '"before each" hook' + (title ? ': ' + title : '');
  4881. var hook = new Hook(title, fn);
  4882. hook.parent = this;
  4883. hook.timeout(this.timeout());
  4884. hook.retries(this.retries());
  4885. hook.enableTimeouts(this.enableTimeouts());
  4886. hook.slow(this.slow());
  4887. hook.ctx = this.ctx;
  4888. this._beforeEach.push(hook);
  4889. this.emit('beforeEach', hook);
  4890. return this;
  4891. };
  4892. /**
  4893. * Run `fn(test[, done])` after each test case.
  4894. *
  4895. * @api private
  4896. * @param {string} title
  4897. * @param {Function} fn
  4898. * @return {Suite} for chaining
  4899. */
  4900. Suite.prototype.afterEach = function(title, fn) {
  4901. if (this.isPending()) {
  4902. return this;
  4903. }
  4904. if (typeof title === 'function') {
  4905. fn = title;
  4906. title = fn.name;
  4907. }
  4908. title = '"after each" hook' + (title ? ': ' + title : '');
  4909. var hook = new Hook(title, fn);
  4910. hook.parent = this;
  4911. hook.timeout(this.timeout());
  4912. hook.retries(this.retries());
  4913. hook.enableTimeouts(this.enableTimeouts());
  4914. hook.slow(this.slow());
  4915. hook.ctx = this.ctx;
  4916. this._afterEach.push(hook);
  4917. this.emit('afterEach', hook);
  4918. return this;
  4919. };
  4920. /**
  4921. * Add a test `suite`.
  4922. *
  4923. * @api private
  4924. * @param {Suite} suite
  4925. * @return {Suite} for chaining
  4926. */
  4927. Suite.prototype.addSuite = function(suite) {
  4928. suite.parent = this;
  4929. suite.timeout(this.timeout());
  4930. suite.retries(this.retries());
  4931. suite.enableTimeouts(this.enableTimeouts());
  4932. suite.slow(this.slow());
  4933. suite.bail(this.bail());
  4934. this.suites.push(suite);
  4935. this.emit('suite', suite);
  4936. return this;
  4937. };
  4938. /**
  4939. * Add a `test` to this suite.
  4940. *
  4941. * @api private
  4942. * @param {Test} test
  4943. * @return {Suite} for chaining
  4944. */
  4945. Suite.prototype.addTest = function(test) {
  4946. test.parent = this;
  4947. test.timeout(this.timeout());
  4948. test.retries(this.retries());
  4949. test.enableTimeouts(this.enableTimeouts());
  4950. test.slow(this.slow());
  4951. test.ctx = this.ctx;
  4952. this.tests.push(test);
  4953. this.emit('test', test);
  4954. return this;
  4955. };
  4956. /**
  4957. * Return the full title generated by recursively concatenating the parent's
  4958. * full title.
  4959. *
  4960. * @api public
  4961. * @return {string}
  4962. */
  4963. Suite.prototype.fullTitle = function() {
  4964. if (this.parent) {
  4965. var full = this.parent.fullTitle();
  4966. if (full) {
  4967. return full + ' ' + this.title;
  4968. }
  4969. }
  4970. return this.title;
  4971. };
  4972. /**
  4973. * Return the total number of tests.
  4974. *
  4975. * @api public
  4976. * @return {number}
  4977. */
  4978. Suite.prototype.total = function() {
  4979. return utils.reduce(this.suites, function(sum, suite) {
  4980. return sum + suite.total();
  4981. }, 0) + this.tests.length;
  4982. };
  4983. /**
  4984. * Iterates through each suite recursively to find all tests. Applies a
  4985. * function in the format `fn(test)`.
  4986. *
  4987. * @api private
  4988. * @param {Function} fn
  4989. * @return {Suite}
  4990. */
  4991. Suite.prototype.eachTest = function(fn) {
  4992. utils.forEach(this.tests, fn);
  4993. utils.forEach(this.suites, function(suite) {
  4994. suite.eachTest(fn);
  4995. });
  4996. return this;
  4997. };
  4998. /**
  4999. * This will run the root suite if we happen to be running in delayed mode.
  5000. */
  5001. Suite.prototype.run = function run() {
  5002. if (this.root) {
  5003. this.emit('run');
  5004. }
  5005. };
  5006. },{"./hook":7,"./ms":15,"./utils":38,"debug":2,"events":3}],36:[function(require,module,exports){
  5007. /**
  5008. * Module dependencies.
  5009. */
  5010. var Runnable = require('./runnable');
  5011. var create = require('lodash.create');
  5012. var isString = require('./utils').isString;
  5013. /**
  5014. * Expose `Test`.
  5015. */
  5016. module.exports = Test;
  5017. /**
  5018. * Initialize a new `Test` with the given `title` and callback `fn`.
  5019. *
  5020. * @api private
  5021. * @param {String} title
  5022. * @param {Function} fn
  5023. */
  5024. function Test(title, fn) {
  5025. if (!isString(title)) {
  5026. throw new Error('Test `title` should be a "string" but "' + typeof title + '" was given instead.');
  5027. }
  5028. Runnable.call(this, title, fn);
  5029. this.pending = !fn;
  5030. this.type = 'test';
  5031. }
  5032. /**
  5033. * Inherit from `Runnable.prototype`.
  5034. */
  5035. Test.prototype = create(Runnable.prototype, {
  5036. constructor: Test
  5037. });
  5038. Test.prototype.clone = function() {
  5039. var test = new Test(this.title, this.fn);
  5040. test.timeout(this.timeout());
  5041. test.slow(this.slow());
  5042. test.enableTimeouts(this.enableTimeouts());
  5043. test.retries(this.retries());
  5044. test.currentRetry(this.currentRetry());
  5045. test.globals(this.globals());
  5046. test.parent = this.parent;
  5047. test.file = this.file;
  5048. test.ctx = this.ctx;
  5049. return test;
  5050. };
  5051. },{"./runnable":33,"./utils":38,"lodash.create":60}],37:[function(require,module,exports){
  5052. 'use strict';
  5053. /**
  5054. * Pad a `number` with a ten's place zero.
  5055. *
  5056. * @param {number} number
  5057. * @return {string}
  5058. */
  5059. function pad(number) {
  5060. var n = number.toString();
  5061. return n.length === 1 ? '0' + n : n;
  5062. }
  5063. /**
  5064. * Turn a `date` into an ISO string.
  5065. *
  5066. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
  5067. *
  5068. * @param {Date} date
  5069. * @return {string}
  5070. */
  5071. function toISOString(date) {
  5072. return date.getUTCFullYear()
  5073. + '-' + pad(date.getUTCMonth() + 1)
  5074. + '-' + pad(date.getUTCDate())
  5075. + 'T' + pad(date.getUTCHours())
  5076. + ':' + pad(date.getUTCMinutes())
  5077. + ':' + pad(date.getUTCSeconds())
  5078. + '.' + String((date.getUTCMilliseconds()/1000).toFixed(3)).slice(2, 5)
  5079. + 'Z';
  5080. }
  5081. /*
  5082. * Exports.
  5083. */
  5084. module.exports = toISOString;
  5085. },{}],38:[function(require,module,exports){
  5086. (function (process,Buffer){
  5087. /* eslint-env browser */
  5088. /**
  5089. * Module dependencies.
  5090. */
  5091. var JSON = require('json3');
  5092. var basename = require('path').basename;
  5093. var debug = require('debug')('mocha:watch');
  5094. var exists = require('fs').existsSync || require('path').existsSync;
  5095. var glob = require('glob');
  5096. var join = require('path').join;
  5097. var readdirSync = require('fs').readdirSync;
  5098. var statSync = require('fs').statSync;
  5099. var watchFile = require('fs').watchFile;
  5100. var toISOString = require('./to-iso-string');
  5101. /**
  5102. * Ignored directories.
  5103. */
  5104. var ignore = ['node_modules', '.git'];
  5105. exports.inherits = require('util').inherits;
  5106. /**
  5107. * Escape special characters in the given string of html.
  5108. *
  5109. * @api private
  5110. * @param {string} html
  5111. * @return {string}
  5112. */
  5113. exports.escape = function(html) {
  5114. return String(html)
  5115. .replace(/&/g, '&amp;')
  5116. .replace(/"/g, '&quot;')
  5117. .replace(/</g, '&lt;')
  5118. .replace(/>/g, '&gt;');
  5119. };
  5120. /**
  5121. * Array#forEach (<=IE8)
  5122. *
  5123. * @api private
  5124. * @param {Array} arr
  5125. * @param {Function} fn
  5126. * @param {Object} scope
  5127. */
  5128. exports.forEach = function(arr, fn, scope) {
  5129. for (var i = 0, l = arr.length; i < l; i++) {
  5130. fn.call(scope, arr[i], i);
  5131. }
  5132. };
  5133. /**
  5134. * Test if the given obj is type of string.
  5135. *
  5136. * @api private
  5137. * @param {Object} obj
  5138. * @return {boolean}
  5139. */
  5140. exports.isString = function(obj) {
  5141. return typeof obj === 'string';
  5142. };
  5143. /**
  5144. * Array#map (<=IE8)
  5145. *
  5146. * @api private
  5147. * @param {Array} arr
  5148. * @param {Function} fn
  5149. * @param {Object} scope
  5150. * @return {Array}
  5151. */
  5152. exports.map = function(arr, fn, scope) {
  5153. var result = [];
  5154. for (var i = 0, l = arr.length; i < l; i++) {
  5155. result.push(fn.call(scope, arr[i], i, arr));
  5156. }
  5157. return result;
  5158. };
  5159. /**
  5160. * Array#indexOf (<=IE8)
  5161. *
  5162. * @api private
  5163. * @param {Array} arr
  5164. * @param {Object} obj to find index of
  5165. * @param {number} start
  5166. * @return {number}
  5167. */
  5168. exports.indexOf = function(arr, obj, start) {
  5169. for (var i = start || 0, l = arr.length; i < l; i++) {
  5170. if (arr[i] === obj) {
  5171. return i;
  5172. }
  5173. }
  5174. return -1;
  5175. };
  5176. /**
  5177. * Array#reduce (<=IE8)
  5178. *
  5179. * @api private
  5180. * @param {Array} arr
  5181. * @param {Function} fn
  5182. * @param {Object} val Initial value.
  5183. * @return {*}
  5184. */
  5185. exports.reduce = function(arr, fn, val) {
  5186. var rval = val;
  5187. for (var i = 0, l = arr.length; i < l; i++) {
  5188. rval = fn(rval, arr[i], i, arr);
  5189. }
  5190. return rval;
  5191. };
  5192. /**
  5193. * Array#filter (<=IE8)
  5194. *
  5195. * @api private
  5196. * @param {Array} arr
  5197. * @param {Function} fn
  5198. * @return {Array}
  5199. */
  5200. exports.filter = function(arr, fn) {
  5201. var ret = [];
  5202. for (var i = 0, l = arr.length; i < l; i++) {
  5203. var val = arr[i];
  5204. if (fn(val, i, arr)) {
  5205. ret.push(val);
  5206. }
  5207. }
  5208. return ret;
  5209. };
  5210. /**
  5211. * Array#some (<=IE8)
  5212. *
  5213. * @api private
  5214. * @param {Array} arr
  5215. * @param {Function} fn
  5216. * @return {Array}
  5217. */
  5218. exports.some = function(arr, fn) {
  5219. for (var i = 0, l = arr.length; i < l; i++) {
  5220. if (fn(arr[i])) {
  5221. return true;
  5222. }
  5223. }
  5224. return false;
  5225. };
  5226. /**
  5227. * Object.keys (<=IE8)
  5228. *
  5229. * @api private
  5230. * @param {Object} obj
  5231. * @return {Array} keys
  5232. */
  5233. exports.keys = typeof Object.keys === 'function' ? Object.keys : function(obj) {
  5234. var keys = [];
  5235. var has = Object.prototype.hasOwnProperty; // for `window` on <=IE8
  5236. for (var key in obj) {
  5237. if (has.call(obj, key)) {
  5238. keys.push(key);
  5239. }
  5240. }
  5241. return keys;
  5242. };
  5243. /**
  5244. * Watch the given `files` for changes
  5245. * and invoke `fn(file)` on modification.
  5246. *
  5247. * @api private
  5248. * @param {Array} files
  5249. * @param {Function} fn
  5250. */
  5251. exports.watch = function(files, fn) {
  5252. var options = { interval: 100 };
  5253. files.forEach(function(file) {
  5254. debug('file %s', file);
  5255. watchFile(file, options, function(curr, prev) {
  5256. if (prev.mtime < curr.mtime) {
  5257. fn(file);
  5258. }
  5259. });
  5260. });
  5261. };
  5262. /**
  5263. * Array.isArray (<=IE8)
  5264. *
  5265. * @api private
  5266. * @param {Object} obj
  5267. * @return {Boolean}
  5268. */
  5269. var isArray = typeof Array.isArray === 'function' ? Array.isArray : function(obj) {
  5270. return Object.prototype.toString.call(obj) === '[object Array]';
  5271. };
  5272. exports.isArray = isArray;
  5273. /**
  5274. * Buffer.prototype.toJSON polyfill.
  5275. *
  5276. * @type {Function}
  5277. */
  5278. if (typeof Buffer !== 'undefined' && Buffer.prototype) {
  5279. Buffer.prototype.toJSON = Buffer.prototype.toJSON || function() {
  5280. return Array.prototype.slice.call(this, 0);
  5281. };
  5282. }
  5283. /**
  5284. * Ignored files.
  5285. *
  5286. * @api private
  5287. * @param {string} path
  5288. * @return {boolean}
  5289. */
  5290. function ignored(path) {
  5291. return !~ignore.indexOf(path);
  5292. }
  5293. /**
  5294. * Lookup files in the given `dir`.
  5295. *
  5296. * @api private
  5297. * @param {string} dir
  5298. * @param {string[]} [ext=['.js']]
  5299. * @param {Array} [ret=[]]
  5300. * @return {Array}
  5301. */
  5302. exports.files = function(dir, ext, ret) {
  5303. ret = ret || [];
  5304. ext = ext || ['js'];
  5305. var re = new RegExp('\\.(' + ext.join('|') + ')$');
  5306. readdirSync(dir)
  5307. .filter(ignored)
  5308. .forEach(function(path) {
  5309. path = join(dir, path);
  5310. if (statSync(path).isDirectory()) {
  5311. exports.files(path, ext, ret);
  5312. } else if (path.match(re)) {
  5313. ret.push(path);
  5314. }
  5315. });
  5316. return ret;
  5317. };
  5318. /**
  5319. * Compute a slug from the given `str`.
  5320. *
  5321. * @api private
  5322. * @param {string} str
  5323. * @return {string}
  5324. */
  5325. exports.slug = function(str) {
  5326. return str
  5327. .toLowerCase()
  5328. .replace(/ +/g, '-')
  5329. .replace(/[^-\w]/g, '');
  5330. };
  5331. /**
  5332. * Strip the function definition from `str`, and re-indent for pre whitespace.
  5333. *
  5334. * @param {string} str
  5335. * @return {string}
  5336. */
  5337. exports.clean = function(str) {
  5338. str = str
  5339. .replace(/\r\n?|[\n\u2028\u2029]/g, '\n').replace(/^\uFEFF/, '')
  5340. // (traditional)-> space/name parameters body (lambda)-> parameters body multi-statement/single keep body content
  5341. .replace(/^function(?:\s*|\s+[^(]*)\([^)]*\)\s*\{((?:.|\n)*?)\s*\}$|^\([^)]*\)\s*=>\s*(?:\{((?:.|\n)*?)\s*\}|((?:.|\n)*))$/, '$1$2$3');
  5342. var spaces = str.match(/^\n?( *)/)[1].length;
  5343. var tabs = str.match(/^\n?(\t*)/)[1].length;
  5344. var re = new RegExp('^\n?' + (tabs ? '\t' : ' ') + '{' + (tabs ? tabs : spaces) + '}', 'gm');
  5345. str = str.replace(re, '');
  5346. return exports.trim(str);
  5347. };
  5348. /**
  5349. * Trim the given `str`.
  5350. *
  5351. * @api private
  5352. * @param {string} str
  5353. * @return {string}
  5354. */
  5355. exports.trim = function(str) {
  5356. return str.replace(/^\s+|\s+$/g, '');
  5357. };
  5358. /**
  5359. * Parse the given `qs`.
  5360. *
  5361. * @api private
  5362. * @param {string} qs
  5363. * @return {Object}
  5364. */
  5365. exports.parseQuery = function(qs) {
  5366. return exports.reduce(qs.replace('?', '').split('&'), function(obj, pair) {
  5367. var i = pair.indexOf('=');
  5368. var key = pair.slice(0, i);
  5369. var val = pair.slice(++i);
  5370. obj[key] = decodeURIComponent(val);
  5371. return obj;
  5372. }, {});
  5373. };
  5374. /**
  5375. * Highlight the given string of `js`.
  5376. *
  5377. * @api private
  5378. * @param {string} js
  5379. * @return {string}
  5380. */
  5381. function highlight(js) {
  5382. return js
  5383. .replace(/</g, '&lt;')
  5384. .replace(/>/g, '&gt;')
  5385. .replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
  5386. .replace(/('.*?')/gm, '<span class="string">$1</span>')
  5387. .replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
  5388. .replace(/(\d+)/gm, '<span class="number">$1</span>')
  5389. .replace(/\bnew[ \t]+(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>')
  5390. .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>');
  5391. }
  5392. /**
  5393. * Highlight the contents of tag `name`.
  5394. *
  5395. * @api private
  5396. * @param {string} name
  5397. */
  5398. exports.highlightTags = function(name) {
  5399. var code = document.getElementById('mocha').getElementsByTagName(name);
  5400. for (var i = 0, len = code.length; i < len; ++i) {
  5401. code[i].innerHTML = highlight(code[i].innerHTML);
  5402. }
  5403. };
  5404. /**
  5405. * If a value could have properties, and has none, this function is called,
  5406. * which returns a string representation of the empty value.
  5407. *
  5408. * Functions w/ no properties return `'[Function]'`
  5409. * Arrays w/ length === 0 return `'[]'`
  5410. * Objects w/ no properties return `'{}'`
  5411. * All else: return result of `value.toString()`
  5412. *
  5413. * @api private
  5414. * @param {*} value The value to inspect.
  5415. * @param {string} [type] The type of the value, if known.
  5416. * @returns {string}
  5417. */
  5418. function emptyRepresentation(value, type) {
  5419. type = type || exports.type(value);
  5420. switch (type) {
  5421. case 'function':
  5422. return '[Function]';
  5423. case 'object':
  5424. return '{}';
  5425. case 'array':
  5426. return '[]';
  5427. default:
  5428. return value.toString();
  5429. }
  5430. }
  5431. /**
  5432. * Takes some variable and asks `Object.prototype.toString()` what it thinks it
  5433. * is.
  5434. *
  5435. * @api private
  5436. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
  5437. * @param {*} value The value to test.
  5438. * @returns {string}
  5439. * @example
  5440. * type({}) // 'object'
  5441. * type([]) // 'array'
  5442. * type(1) // 'number'
  5443. * type(false) // 'boolean'
  5444. * type(Infinity) // 'number'
  5445. * type(null) // 'null'
  5446. * type(new Date()) // 'date'
  5447. * type(/foo/) // 'regexp'
  5448. * type('type') // 'string'
  5449. * type(global) // 'global'
  5450. */
  5451. exports.type = function type(value) {
  5452. if (value === undefined) {
  5453. return 'undefined';
  5454. } else if (value === null) {
  5455. return 'null';
  5456. } else if (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) {
  5457. return 'buffer';
  5458. }
  5459. return Object.prototype.toString.call(value)
  5460. .replace(/^\[.+\s(.+?)\]$/, '$1')
  5461. .toLowerCase();
  5462. };
  5463. /**
  5464. * Stringify `value`. Different behavior depending on type of value:
  5465. *
  5466. * - If `value` is undefined or null, return `'[undefined]'` or `'[null]'`, respectively.
  5467. * - If `value` is not an object, function or array, return result of `value.toString()` wrapped in double-quotes.
  5468. * - If `value` is an *empty* object, function, or array, return result of function
  5469. * {@link emptyRepresentation}.
  5470. * - If `value` has properties, call {@link exports.canonicalize} on it, then return result of
  5471. * JSON.stringify().
  5472. *
  5473. * @api private
  5474. * @see exports.type
  5475. * @param {*} value
  5476. * @return {string}
  5477. */
  5478. exports.stringify = function(value) {
  5479. var type = exports.type(value);
  5480. if (!~exports.indexOf(['object', 'array', 'function'], type)) {
  5481. if (type !== 'buffer') {
  5482. return jsonStringify(value);
  5483. }
  5484. var json = value.toJSON();
  5485. // Based on the toJSON result
  5486. return jsonStringify(json.data && json.type ? json.data : json, 2)
  5487. .replace(/,(\n|$)/g, '$1');
  5488. }
  5489. for (var prop in value) {
  5490. if (Object.prototype.hasOwnProperty.call(value, prop)) {
  5491. return jsonStringify(exports.canonicalize(value), 2).replace(/,(\n|$)/g, '$1');
  5492. }
  5493. }
  5494. return emptyRepresentation(value, type);
  5495. };
  5496. /**
  5497. * like JSON.stringify but more sense.
  5498. *
  5499. * @api private
  5500. * @param {Object} object
  5501. * @param {number=} spaces
  5502. * @param {number=} depth
  5503. * @returns {*}
  5504. */
  5505. function jsonStringify(object, spaces, depth) {
  5506. if (typeof spaces === 'undefined') {
  5507. // primitive types
  5508. return _stringify(object);
  5509. }
  5510. depth = depth || 1;
  5511. var space = spaces * depth;
  5512. var str = isArray(object) ? '[' : '{';
  5513. var end = isArray(object) ? ']' : '}';
  5514. var length = typeof object.length === 'number' ? object.length : exports.keys(object).length;
  5515. // `.repeat()` polyfill
  5516. function repeat(s, n) {
  5517. return new Array(n).join(s);
  5518. }
  5519. function _stringify(val) {
  5520. switch (exports.type(val)) {
  5521. case 'null':
  5522. case 'undefined':
  5523. val = '[' + val + ']';
  5524. break;
  5525. case 'array':
  5526. case 'object':
  5527. val = jsonStringify(val, spaces, depth + 1);
  5528. break;
  5529. case 'boolean':
  5530. case 'regexp':
  5531. case 'symbol':
  5532. case 'number':
  5533. val = val === 0 && (1 / val) === -Infinity // `-0`
  5534. ? '-0'
  5535. : val.toString();
  5536. break;
  5537. case 'date':
  5538. var sDate;
  5539. if (isNaN(val.getTime())) { // Invalid date
  5540. sDate = val.toString();
  5541. } else {
  5542. sDate = val.toISOString ? val.toISOString() : toISOString(val);
  5543. }
  5544. val = '[Date: ' + sDate + ']';
  5545. break;
  5546. case 'buffer':
  5547. var json = val.toJSON();
  5548. // Based on the toJSON result
  5549. json = json.data && json.type ? json.data : json;
  5550. val = '[Buffer: ' + jsonStringify(json, 2, depth + 1) + ']';
  5551. break;
  5552. default:
  5553. val = (val === '[Function]' || val === '[Circular]')
  5554. ? val
  5555. : JSON.stringify(val); // string
  5556. }
  5557. return val;
  5558. }
  5559. for (var i in object) {
  5560. if (!Object.prototype.hasOwnProperty.call(object, i)) {
  5561. continue; // not my business
  5562. }
  5563. --length;
  5564. str += '\n ' + repeat(' ', space)
  5565. + (isArray(object) ? '' : '"' + i + '": ') // key
  5566. + _stringify(object[i]) // value
  5567. + (length ? ',' : ''); // comma
  5568. }
  5569. return str
  5570. // [], {}
  5571. + (str.length !== 1 ? '\n' + repeat(' ', --space) + end : end);
  5572. }
  5573. /**
  5574. * Test if a value is a buffer.
  5575. *
  5576. * @api private
  5577. * @param {*} value The value to test.
  5578. * @return {boolean} True if `value` is a buffer, otherwise false
  5579. */
  5580. exports.isBuffer = function(value) {
  5581. return typeof Buffer !== 'undefined' && Buffer.isBuffer(value);
  5582. };
  5583. /**
  5584. * Return a new Thing that has the keys in sorted order. Recursive.
  5585. *
  5586. * If the Thing...
  5587. * - has already been seen, return string `'[Circular]'`
  5588. * - is `undefined`, return string `'[undefined]'`
  5589. * - is `null`, return value `null`
  5590. * - is some other primitive, return the value
  5591. * - is not a primitive or an `Array`, `Object`, or `Function`, return the value of the Thing's `toString()` method
  5592. * - is a non-empty `Array`, `Object`, or `Function`, return the result of calling this function again.
  5593. * - is an empty `Array`, `Object`, or `Function`, return the result of calling `emptyRepresentation()`
  5594. *
  5595. * @api private
  5596. * @see {@link exports.stringify}
  5597. * @param {*} value Thing to inspect. May or may not have properties.
  5598. * @param {Array} [stack=[]] Stack of seen values
  5599. * @return {(Object|Array|Function|string|undefined)}
  5600. */
  5601. exports.canonicalize = function(value, stack) {
  5602. var canonicalizedObj;
  5603. /* eslint-disable no-unused-vars */
  5604. var prop;
  5605. /* eslint-enable no-unused-vars */
  5606. var type = exports.type(value);
  5607. function withStack(value, fn) {
  5608. stack.push(value);
  5609. fn();
  5610. stack.pop();
  5611. }
  5612. stack = stack || [];
  5613. if (exports.indexOf(stack, value) !== -1) {
  5614. return '[Circular]';
  5615. }
  5616. switch (type) {
  5617. case 'undefined':
  5618. case 'buffer':
  5619. case 'null':
  5620. canonicalizedObj = value;
  5621. break;
  5622. case 'array':
  5623. withStack(value, function() {
  5624. canonicalizedObj = exports.map(value, function(item) {
  5625. return exports.canonicalize(item, stack);
  5626. });
  5627. });
  5628. break;
  5629. case 'function':
  5630. /* eslint-disable guard-for-in */
  5631. for (prop in value) {
  5632. canonicalizedObj = {};
  5633. break;
  5634. }
  5635. /* eslint-enable guard-for-in */
  5636. if (!canonicalizedObj) {
  5637. canonicalizedObj = emptyRepresentation(value, type);
  5638. break;
  5639. }
  5640. /* falls through */
  5641. case 'object':
  5642. canonicalizedObj = canonicalizedObj || {};
  5643. withStack(value, function() {
  5644. exports.forEach(exports.keys(value).sort(), function(key) {
  5645. canonicalizedObj[key] = exports.canonicalize(value[key], stack);
  5646. });
  5647. });
  5648. break;
  5649. case 'date':
  5650. case 'number':
  5651. case 'regexp':
  5652. case 'boolean':
  5653. case 'symbol':
  5654. canonicalizedObj = value;
  5655. break;
  5656. default:
  5657. canonicalizedObj = value + '';
  5658. }
  5659. return canonicalizedObj;
  5660. };
  5661. /**
  5662. * Lookup file names at the given `path`.
  5663. *
  5664. * @api public
  5665. * @param {string} path Base path to start searching from.
  5666. * @param {string[]} extensions File extensions to look for.
  5667. * @param {boolean} recursive Whether or not to recurse into subdirectories.
  5668. * @return {string[]} An array of paths.
  5669. */
  5670. exports.lookupFiles = function lookupFiles(path, extensions, recursive) {
  5671. var files = [];
  5672. var re = new RegExp('\\.(' + extensions.join('|') + ')$');
  5673. if (!exists(path)) {
  5674. if (exists(path + '.js')) {
  5675. path += '.js';
  5676. } else {
  5677. files = glob.sync(path);
  5678. if (!files.length) {
  5679. throw new Error("cannot resolve path (or pattern) '" + path + "'");
  5680. }
  5681. return files;
  5682. }
  5683. }
  5684. try {
  5685. var stat = statSync(path);
  5686. if (stat.isFile()) {
  5687. return path;
  5688. }
  5689. } catch (err) {
  5690. // ignore error
  5691. return;
  5692. }
  5693. readdirSync(path).forEach(function(file) {
  5694. file = join(path, file);
  5695. try {
  5696. var stat = statSync(file);
  5697. if (stat.isDirectory()) {
  5698. if (recursive) {
  5699. files = files.concat(lookupFiles(file, extensions, recursive));
  5700. }
  5701. return;
  5702. }
  5703. } catch (err) {
  5704. // ignore error
  5705. return;
  5706. }
  5707. if (!stat.isFile() || !re.test(file) || basename(file)[0] === '.') {
  5708. return;
  5709. }
  5710. files.push(file);
  5711. });
  5712. return files;
  5713. };
  5714. /**
  5715. * Generate an undefined error with a message warning the user.
  5716. *
  5717. * @return {Error}
  5718. */
  5719. exports.undefinedError = function() {
  5720. return new Error('Caught undefined error, did you throw without specifying what?');
  5721. };
  5722. /**
  5723. * Generate an undefined error if `err` is not defined.
  5724. *
  5725. * @param {Error} err
  5726. * @return {Error}
  5727. */
  5728. exports.getError = function(err) {
  5729. return err || exports.undefinedError();
  5730. };
  5731. /**
  5732. * @summary
  5733. * This Filter based on `mocha-clean` module.(see: `github.com/rstacruz/mocha-clean`)
  5734. * @description
  5735. * When invoking this function you get a filter function that get the Error.stack as an input,
  5736. * and return a prettify output.
  5737. * (i.e: strip Mocha and internal node functions from stack trace).
  5738. * @returns {Function}
  5739. */
  5740. exports.stackTraceFilter = function() {
  5741. // TODO: Replace with `process.browser`
  5742. var slash = '/';
  5743. var is = typeof document === 'undefined' ? { node: true } : { browser: true };
  5744. var cwd = is.node
  5745. ? process.cwd() + slash
  5746. : (typeof location === 'undefined' ? window.location : location).href.replace(/\/[^\/]*$/, '/');
  5747. function isMochaInternal(line) {
  5748. return (~line.indexOf('node_modules' + slash + 'mocha' + slash))
  5749. || (~line.indexOf('components' + slash + 'mochajs' + slash))
  5750. || (~line.indexOf('components' + slash + 'mocha' + slash))
  5751. || (~line.indexOf(slash + 'mocha.js'));
  5752. }
  5753. function isNodeInternal(line) {
  5754. return (~line.indexOf('(timers.js:'))
  5755. || (~line.indexOf('(events.js:'))
  5756. || (~line.indexOf('(node.js:'))
  5757. || (~line.indexOf('(module.js:'))
  5758. || (~line.indexOf('GeneratorFunctionPrototype.next (native)'))
  5759. || false;
  5760. }
  5761. return function(stack) {
  5762. stack = stack.split('\n');
  5763. stack = exports.reduce(stack, function(list, line) {
  5764. if (isMochaInternal(line)) {
  5765. return list;
  5766. }
  5767. if (is.node && isNodeInternal(line)) {
  5768. return list;
  5769. }
  5770. // Clean up cwd(absolute)
  5771. if (/\(?.+:\d+:\d+\)?$/.test(line)) {
  5772. line = line.replace(cwd, '');
  5773. }
  5774. list.push(line);
  5775. return list;
  5776. }, []);
  5777. return stack.join('\n');
  5778. };
  5779. };
  5780. /**
  5781. * Crude, but effective.
  5782. * @api
  5783. * @param {*} value
  5784. * @returns {boolean} Whether or not `value` is a Promise
  5785. */
  5786. exports.isPromise = function isPromise(value) {
  5787. return typeof value === 'object' && typeof value.then === 'function';
  5788. };
  5789. }).call(this,require('_process'),require("buffer").Buffer)
  5790. },{"./to-iso-string":37,"_process":67,"buffer":44,"debug":2,"fs":42,"glob":42,"json3":54,"path":42,"util":82}],39:[function(require,module,exports){
  5791. 'use strict'
  5792. exports.toByteArray = toByteArray
  5793. exports.fromByteArray = fromByteArray
  5794. var lookup = []
  5795. var revLookup = []
  5796. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  5797. function init () {
  5798. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  5799. for (var i = 0, len = code.length; i < len; ++i) {
  5800. lookup[i] = code[i]
  5801. revLookup[code.charCodeAt(i)] = i
  5802. }
  5803. revLookup['-'.charCodeAt(0)] = 62
  5804. revLookup['_'.charCodeAt(0)] = 63
  5805. }
  5806. init()
  5807. function toByteArray (b64) {
  5808. var i, j, l, tmp, placeHolders, arr
  5809. var len = b64.length
  5810. if (len % 4 > 0) {
  5811. throw new Error('Invalid string. Length must be a multiple of 4')
  5812. }
  5813. // the number of equal signs (place holders)
  5814. // if there are two placeholders, than the two characters before it
  5815. // represent one byte
  5816. // if there is only one, then the three characters before it represent 2 bytes
  5817. // this is just a cheap hack to not do indexOf twice
  5818. placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
  5819. // base64 is 4/3 + up to two characters of the original data
  5820. arr = new Arr(len * 3 / 4 - placeHolders)
  5821. // if there are placeholders, only get up to the last complete 4 chars
  5822. l = placeHolders > 0 ? len - 4 : len
  5823. var L = 0
  5824. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  5825. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
  5826. arr[L++] = (tmp >> 16) & 0xFF
  5827. arr[L++] = (tmp >> 8) & 0xFF
  5828. arr[L++] = tmp & 0xFF
  5829. }
  5830. if (placeHolders === 2) {
  5831. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
  5832. arr[L++] = tmp & 0xFF
  5833. } else if (placeHolders === 1) {
  5834. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
  5835. arr[L++] = (tmp >> 8) & 0xFF
  5836. arr[L++] = tmp & 0xFF
  5837. }
  5838. return arr
  5839. }
  5840. function tripletToBase64 (num) {
  5841. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  5842. }
  5843. function encodeChunk (uint8, start, end) {
  5844. var tmp
  5845. var output = []
  5846. for (var i = start; i < end; i += 3) {
  5847. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  5848. output.push(tripletToBase64(tmp))
  5849. }
  5850. return output.join('')
  5851. }
  5852. function fromByteArray (uint8) {
  5853. var tmp
  5854. var len = uint8.length
  5855. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  5856. var output = ''
  5857. var parts = []
  5858. var maxChunkLength = 16383 // must be multiple of 3
  5859. // go through the array every three bytes, we'll deal with trailing stuff later
  5860. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  5861. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  5862. }
  5863. // pad the end with zeros, but make sure to not forget the extra bytes
  5864. if (extraBytes === 1) {
  5865. tmp = uint8[len - 1]
  5866. output += lookup[tmp >> 2]
  5867. output += lookup[(tmp << 4) & 0x3F]
  5868. output += '=='
  5869. } else if (extraBytes === 2) {
  5870. tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
  5871. output += lookup[tmp >> 10]
  5872. output += lookup[(tmp >> 4) & 0x3F]
  5873. output += lookup[(tmp << 2) & 0x3F]
  5874. output += '='
  5875. }
  5876. parts.push(output)
  5877. return parts.join('')
  5878. }
  5879. },{}],40:[function(require,module,exports){
  5880. },{}],41:[function(require,module,exports){
  5881. (function (process){
  5882. var WritableStream = require('stream').Writable
  5883. var inherits = require('util').inherits
  5884. module.exports = BrowserStdout
  5885. inherits(BrowserStdout, WritableStream)
  5886. function BrowserStdout(opts) {
  5887. if (!(this instanceof BrowserStdout)) return new BrowserStdout(opts)
  5888. opts = opts || {}
  5889. WritableStream.call(this, opts)
  5890. this.label = (opts.label !== undefined) ? opts.label : 'stdout'
  5891. }
  5892. BrowserStdout.prototype._write = function(chunks, encoding, cb) {
  5893. var output = chunks.toString ? chunks.toString() : chunks
  5894. if (this.label === false) {
  5895. console.log(output)
  5896. } else {
  5897. console.log(this.label+':', output)
  5898. }
  5899. process.nextTick(cb)
  5900. }
  5901. }).call(this,require('_process'))
  5902. },{"_process":67,"stream":78,"util":82}],42:[function(require,module,exports){
  5903. arguments[4][40][0].apply(exports,arguments)
  5904. },{"dup":40}],43:[function(require,module,exports){
  5905. (function (global){
  5906. 'use strict';
  5907. var buffer = require('buffer');
  5908. var Buffer = buffer.Buffer;
  5909. var SlowBuffer = buffer.SlowBuffer;
  5910. var MAX_LEN = buffer.kMaxLength || 2147483647;
  5911. exports.alloc = function alloc(size, fill, encoding) {
  5912. if (typeof Buffer.alloc === 'function') {
  5913. return Buffer.alloc(size, fill, encoding);
  5914. }
  5915. if (typeof encoding === 'number') {
  5916. throw new TypeError('encoding must not be number');
  5917. }
  5918. if (typeof size !== 'number') {
  5919. throw new TypeError('size must be a number');
  5920. }
  5921. if (size > MAX_LEN) {
  5922. throw new RangeError('size is too large');
  5923. }
  5924. var enc = encoding;
  5925. var _fill = fill;
  5926. if (_fill === undefined) {
  5927. enc = undefined;
  5928. _fill = 0;
  5929. }
  5930. var buf = new Buffer(size);
  5931. if (typeof _fill === 'string') {
  5932. var fillBuf = new Buffer(_fill, enc);
  5933. var flen = fillBuf.length;
  5934. var i = -1;
  5935. while (++i < size) {
  5936. buf[i] = fillBuf[i % flen];
  5937. }
  5938. } else {
  5939. buf.fill(_fill);
  5940. }
  5941. return buf;
  5942. }
  5943. exports.allocUnsafe = function allocUnsafe(size) {
  5944. if (typeof Buffer.allocUnsafe === 'function') {
  5945. return Buffer.allocUnsafe(size);
  5946. }
  5947. if (typeof size !== 'number') {
  5948. throw new TypeError('size must be a number');
  5949. }
  5950. if (size > MAX_LEN) {
  5951. throw new RangeError('size is too large');
  5952. }
  5953. return new Buffer(size);
  5954. }
  5955. exports.from = function from(value, encodingOrOffset, length) {
  5956. if (typeof Buffer.from === 'function' && (!global.Uint8Array || Uint8Array.from !== Buffer.from)) {
  5957. return Buffer.from(value, encodingOrOffset, length);
  5958. }
  5959. if (typeof value === 'number') {
  5960. throw new TypeError('"value" argument must not be a number');
  5961. }
  5962. if (typeof value === 'string') {
  5963. return new Buffer(value, encodingOrOffset);
  5964. }
  5965. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  5966. var offset = encodingOrOffset;
  5967. if (arguments.length === 1) {
  5968. return new Buffer(value);
  5969. }
  5970. if (typeof offset === 'undefined') {
  5971. offset = 0;
  5972. }
  5973. var len = length;
  5974. if (typeof len === 'undefined') {
  5975. len = value.byteLength - offset;
  5976. }
  5977. if (offset >= value.byteLength) {
  5978. throw new RangeError('\'offset\' is out of bounds');
  5979. }
  5980. if (len > value.byteLength - offset) {
  5981. throw new RangeError('\'length\' is out of bounds');
  5982. }
  5983. return new Buffer(value.slice(offset, offset + len));
  5984. }
  5985. if (Buffer.isBuffer(value)) {
  5986. var out = new Buffer(value.length);
  5987. value.copy(out, 0, 0, value.length);
  5988. return out;
  5989. }
  5990. if (value) {
  5991. if (Array.isArray(value) || (typeof ArrayBuffer !== 'undefined' && value.buffer instanceof ArrayBuffer) || 'length' in value) {
  5992. return new Buffer(value);
  5993. }
  5994. if (value.type === 'Buffer' && Array.isArray(value.data)) {
  5995. return new Buffer(value.data);
  5996. }
  5997. }
  5998. throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.');
  5999. }
  6000. exports.allocUnsafeSlow = function allocUnsafeSlow(size) {
  6001. if (typeof Buffer.allocUnsafeSlow === 'function') {
  6002. return Buffer.allocUnsafeSlow(size);
  6003. }
  6004. if (typeof size !== 'number') {
  6005. throw new TypeError('size must be a number');
  6006. }
  6007. if (size >= MAX_LEN) {
  6008. throw new RangeError('size is too large');
  6009. }
  6010. return new SlowBuffer(size);
  6011. }
  6012. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  6013. },{"buffer":44}],44:[function(require,module,exports){
  6014. (function (global){
  6015. /*!
  6016. * The buffer module from node.js, for the browser.
  6017. *
  6018. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  6019. * @license MIT
  6020. */
  6021. /* eslint-disable no-proto */
  6022. 'use strict'
  6023. var base64 = require('base64-js')
  6024. var ieee754 = require('ieee754')
  6025. var isArray = require('isarray')
  6026. exports.Buffer = Buffer
  6027. exports.SlowBuffer = SlowBuffer
  6028. exports.INSPECT_MAX_BYTES = 50
  6029. /**
  6030. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  6031. * === true Use Uint8Array implementation (fastest)
  6032. * === false Use Object implementation (most compatible, even IE6)
  6033. *
  6034. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  6035. * Opera 11.6+, iOS 4.2+.
  6036. *
  6037. * Due to various browser bugs, sometimes the Object implementation will be used even
  6038. * when the browser supports typed arrays.
  6039. *
  6040. * Note:
  6041. *
  6042. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  6043. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  6044. *
  6045. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  6046. *
  6047. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  6048. * incorrect length in some situations.
  6049. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  6050. * get the Object implementation, which is slower but behaves correctly.
  6051. */
  6052. Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
  6053. ? global.TYPED_ARRAY_SUPPORT
  6054. : typedArraySupport()
  6055. /*
  6056. * Export kMaxLength after typed array support is determined.
  6057. */
  6058. exports.kMaxLength = kMaxLength()
  6059. function typedArraySupport () {
  6060. try {
  6061. var arr = new Uint8Array(1)
  6062. arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
  6063. return arr.foo() === 42 && // typed array instances can be augmented
  6064. typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
  6065. arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
  6066. } catch (e) {
  6067. return false
  6068. }
  6069. }
  6070. function kMaxLength () {
  6071. return Buffer.TYPED_ARRAY_SUPPORT
  6072. ? 0x7fffffff
  6073. : 0x3fffffff
  6074. }
  6075. function createBuffer (that, length) {
  6076. if (kMaxLength() < length) {
  6077. throw new RangeError('Invalid typed array length')
  6078. }
  6079. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6080. // Return an augmented `Uint8Array` instance, for best performance
  6081. that = new Uint8Array(length)
  6082. that.__proto__ = Buffer.prototype
  6083. } else {
  6084. // Fallback: Return an object instance of the Buffer class
  6085. if (that === null) {
  6086. that = new Buffer(length)
  6087. }
  6088. that.length = length
  6089. }
  6090. return that
  6091. }
  6092. /**
  6093. * The Buffer constructor returns instances of `Uint8Array` that have their
  6094. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  6095. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  6096. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  6097. * returns a single octet.
  6098. *
  6099. * The `Uint8Array` prototype remains unmodified.
  6100. */
  6101. function Buffer (arg, encodingOrOffset, length) {
  6102. if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
  6103. return new Buffer(arg, encodingOrOffset, length)
  6104. }
  6105. // Common case.
  6106. if (typeof arg === 'number') {
  6107. if (typeof encodingOrOffset === 'string') {
  6108. throw new Error(
  6109. 'If encoding is specified then the first argument must be a string'
  6110. )
  6111. }
  6112. return allocUnsafe(this, arg)
  6113. }
  6114. return from(this, arg, encodingOrOffset, length)
  6115. }
  6116. Buffer.poolSize = 8192 // not used by this implementation
  6117. // TODO: Legacy, not needed anymore. Remove in next major version.
  6118. Buffer._augment = function (arr) {
  6119. arr.__proto__ = Buffer.prototype
  6120. return arr
  6121. }
  6122. function from (that, value, encodingOrOffset, length) {
  6123. if (typeof value === 'number') {
  6124. throw new TypeError('"value" argument must not be a number')
  6125. }
  6126. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  6127. return fromArrayBuffer(that, value, encodingOrOffset, length)
  6128. }
  6129. if (typeof value === 'string') {
  6130. return fromString(that, value, encodingOrOffset)
  6131. }
  6132. return fromObject(that, value)
  6133. }
  6134. /**
  6135. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  6136. * if value is a number.
  6137. * Buffer.from(str[, encoding])
  6138. * Buffer.from(array)
  6139. * Buffer.from(buffer)
  6140. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  6141. **/
  6142. Buffer.from = function (value, encodingOrOffset, length) {
  6143. return from(null, value, encodingOrOffset, length)
  6144. }
  6145. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6146. Buffer.prototype.__proto__ = Uint8Array.prototype
  6147. Buffer.__proto__ = Uint8Array
  6148. if (typeof Symbol !== 'undefined' && Symbol.species &&
  6149. Buffer[Symbol.species] === Buffer) {
  6150. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  6151. Object.defineProperty(Buffer, Symbol.species, {
  6152. value: null,
  6153. configurable: true
  6154. })
  6155. }
  6156. }
  6157. function assertSize (size) {
  6158. if (typeof size !== 'number') {
  6159. throw new TypeError('"size" argument must be a number')
  6160. }
  6161. }
  6162. function alloc (that, size, fill, encoding) {
  6163. assertSize(size)
  6164. if (size <= 0) {
  6165. return createBuffer(that, size)
  6166. }
  6167. if (fill !== undefined) {
  6168. // Only pay attention to encoding if it's a string. This
  6169. // prevents accidentally sending in a number that would
  6170. // be interpretted as a start offset.
  6171. return typeof encoding === 'string'
  6172. ? createBuffer(that, size).fill(fill, encoding)
  6173. : createBuffer(that, size).fill(fill)
  6174. }
  6175. return createBuffer(that, size)
  6176. }
  6177. /**
  6178. * Creates a new filled Buffer instance.
  6179. * alloc(size[, fill[, encoding]])
  6180. **/
  6181. Buffer.alloc = function (size, fill, encoding) {
  6182. return alloc(null, size, fill, encoding)
  6183. }
  6184. function allocUnsafe (that, size) {
  6185. assertSize(size)
  6186. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
  6187. if (!Buffer.TYPED_ARRAY_SUPPORT) {
  6188. for (var i = 0; i < size; ++i) {
  6189. that[i] = 0
  6190. }
  6191. }
  6192. return that
  6193. }
  6194. /**
  6195. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  6196. * */
  6197. Buffer.allocUnsafe = function (size) {
  6198. return allocUnsafe(null, size)
  6199. }
  6200. /**
  6201. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  6202. */
  6203. Buffer.allocUnsafeSlow = function (size) {
  6204. return allocUnsafe(null, size)
  6205. }
  6206. function fromString (that, string, encoding) {
  6207. if (typeof encoding !== 'string' || encoding === '') {
  6208. encoding = 'utf8'
  6209. }
  6210. if (!Buffer.isEncoding(encoding)) {
  6211. throw new TypeError('"encoding" must be a valid string encoding')
  6212. }
  6213. var length = byteLength(string, encoding) | 0
  6214. that = createBuffer(that, length)
  6215. that.write(string, encoding)
  6216. return that
  6217. }
  6218. function fromArrayLike (that, array) {
  6219. var length = checked(array.length) | 0
  6220. that = createBuffer(that, length)
  6221. for (var i = 0; i < length; i += 1) {
  6222. that[i] = array[i] & 255
  6223. }
  6224. return that
  6225. }
  6226. function fromArrayBuffer (that, array, byteOffset, length) {
  6227. array.byteLength // this throws if `array` is not a valid ArrayBuffer
  6228. if (byteOffset < 0 || array.byteLength < byteOffset) {
  6229. throw new RangeError('\'offset\' is out of bounds')
  6230. }
  6231. if (array.byteLength < byteOffset + (length || 0)) {
  6232. throw new RangeError('\'length\' is out of bounds')
  6233. }
  6234. if (length === undefined) {
  6235. array = new Uint8Array(array, byteOffset)
  6236. } else {
  6237. array = new Uint8Array(array, byteOffset, length)
  6238. }
  6239. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6240. // Return an augmented `Uint8Array` instance, for best performance
  6241. that = array
  6242. that.__proto__ = Buffer.prototype
  6243. } else {
  6244. // Fallback: Return an object instance of the Buffer class
  6245. that = fromArrayLike(that, array)
  6246. }
  6247. return that
  6248. }
  6249. function fromObject (that, obj) {
  6250. if (Buffer.isBuffer(obj)) {
  6251. var len = checked(obj.length) | 0
  6252. that = createBuffer(that, len)
  6253. if (that.length === 0) {
  6254. return that
  6255. }
  6256. obj.copy(that, 0, 0, len)
  6257. return that
  6258. }
  6259. if (obj) {
  6260. if ((typeof ArrayBuffer !== 'undefined' &&
  6261. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  6262. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  6263. return createBuffer(that, 0)
  6264. }
  6265. return fromArrayLike(that, obj)
  6266. }
  6267. if (obj.type === 'Buffer' && isArray(obj.data)) {
  6268. return fromArrayLike(that, obj.data)
  6269. }
  6270. }
  6271. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  6272. }
  6273. function checked (length) {
  6274. // Note: cannot use `length < kMaxLength` here because that fails when
  6275. // length is NaN (which is otherwise coerced to zero.)
  6276. if (length >= kMaxLength()) {
  6277. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  6278. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  6279. }
  6280. return length | 0
  6281. }
  6282. function SlowBuffer (length) {
  6283. if (+length != length) { // eslint-disable-line eqeqeq
  6284. length = 0
  6285. }
  6286. return Buffer.alloc(+length)
  6287. }
  6288. Buffer.isBuffer = function isBuffer (b) {
  6289. return !!(b != null && b._isBuffer)
  6290. }
  6291. Buffer.compare = function compare (a, b) {
  6292. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  6293. throw new TypeError('Arguments must be Buffers')
  6294. }
  6295. if (a === b) return 0
  6296. var x = a.length
  6297. var y = b.length
  6298. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  6299. if (a[i] !== b[i]) {
  6300. x = a[i]
  6301. y = b[i]
  6302. break
  6303. }
  6304. }
  6305. if (x < y) return -1
  6306. if (y < x) return 1
  6307. return 0
  6308. }
  6309. Buffer.isEncoding = function isEncoding (encoding) {
  6310. switch (String(encoding).toLowerCase()) {
  6311. case 'hex':
  6312. case 'utf8':
  6313. case 'utf-8':
  6314. case 'ascii':
  6315. case 'binary':
  6316. case 'base64':
  6317. case 'raw':
  6318. case 'ucs2':
  6319. case 'ucs-2':
  6320. case 'utf16le':
  6321. case 'utf-16le':
  6322. return true
  6323. default:
  6324. return false
  6325. }
  6326. }
  6327. Buffer.concat = function concat (list, length) {
  6328. if (!isArray(list)) {
  6329. throw new TypeError('"list" argument must be an Array of Buffers')
  6330. }
  6331. if (list.length === 0) {
  6332. return Buffer.alloc(0)
  6333. }
  6334. var i
  6335. if (length === undefined) {
  6336. length = 0
  6337. for (i = 0; i < list.length; ++i) {
  6338. length += list[i].length
  6339. }
  6340. }
  6341. var buffer = Buffer.allocUnsafe(length)
  6342. var pos = 0
  6343. for (i = 0; i < list.length; ++i) {
  6344. var buf = list[i]
  6345. if (!Buffer.isBuffer(buf)) {
  6346. throw new TypeError('"list" argument must be an Array of Buffers')
  6347. }
  6348. buf.copy(buffer, pos)
  6349. pos += buf.length
  6350. }
  6351. return buffer
  6352. }
  6353. function byteLength (string, encoding) {
  6354. if (Buffer.isBuffer(string)) {
  6355. return string.length
  6356. }
  6357. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  6358. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  6359. return string.byteLength
  6360. }
  6361. if (typeof string !== 'string') {
  6362. string = '' + string
  6363. }
  6364. var len = string.length
  6365. if (len === 0) return 0
  6366. // Use a for loop to avoid recursion
  6367. var loweredCase = false
  6368. for (;;) {
  6369. switch (encoding) {
  6370. case 'ascii':
  6371. case 'binary':
  6372. case 'raw':
  6373. case 'raws':
  6374. return len
  6375. case 'utf8':
  6376. case 'utf-8':
  6377. case undefined:
  6378. return utf8ToBytes(string).length
  6379. case 'ucs2':
  6380. case 'ucs-2':
  6381. case 'utf16le':
  6382. case 'utf-16le':
  6383. return len * 2
  6384. case 'hex':
  6385. return len >>> 1
  6386. case 'base64':
  6387. return base64ToBytes(string).length
  6388. default:
  6389. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  6390. encoding = ('' + encoding).toLowerCase()
  6391. loweredCase = true
  6392. }
  6393. }
  6394. }
  6395. Buffer.byteLength = byteLength
  6396. function slowToString (encoding, start, end) {
  6397. var loweredCase = false
  6398. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  6399. // property of a typed array.
  6400. // This behaves neither like String nor Uint8Array in that we set start/end
  6401. // to their upper/lower bounds if the value passed is out of range.
  6402. // undefined is handled specially as per ECMA-262 6th Edition,
  6403. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  6404. if (start === undefined || start < 0) {
  6405. start = 0
  6406. }
  6407. // Return early if start > this.length. Done here to prevent potential uint32
  6408. // coercion fail below.
  6409. if (start > this.length) {
  6410. return ''
  6411. }
  6412. if (end === undefined || end > this.length) {
  6413. end = this.length
  6414. }
  6415. if (end <= 0) {
  6416. return ''
  6417. }
  6418. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  6419. end >>>= 0
  6420. start >>>= 0
  6421. if (end <= start) {
  6422. return ''
  6423. }
  6424. if (!encoding) encoding = 'utf8'
  6425. while (true) {
  6426. switch (encoding) {
  6427. case 'hex':
  6428. return hexSlice(this, start, end)
  6429. case 'utf8':
  6430. case 'utf-8':
  6431. return utf8Slice(this, start, end)
  6432. case 'ascii':
  6433. return asciiSlice(this, start, end)
  6434. case 'binary':
  6435. return binarySlice(this, start, end)
  6436. case 'base64':
  6437. return base64Slice(this, start, end)
  6438. case 'ucs2':
  6439. case 'ucs-2':
  6440. case 'utf16le':
  6441. case 'utf-16le':
  6442. return utf16leSlice(this, start, end)
  6443. default:
  6444. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  6445. encoding = (encoding + '').toLowerCase()
  6446. loweredCase = true
  6447. }
  6448. }
  6449. }
  6450. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  6451. // Buffer instances.
  6452. Buffer.prototype._isBuffer = true
  6453. function swap (b, n, m) {
  6454. var i = b[n]
  6455. b[n] = b[m]
  6456. b[m] = i
  6457. }
  6458. Buffer.prototype.swap16 = function swap16 () {
  6459. var len = this.length
  6460. if (len % 2 !== 0) {
  6461. throw new RangeError('Buffer size must be a multiple of 16-bits')
  6462. }
  6463. for (var i = 0; i < len; i += 2) {
  6464. swap(this, i, i + 1)
  6465. }
  6466. return this
  6467. }
  6468. Buffer.prototype.swap32 = function swap32 () {
  6469. var len = this.length
  6470. if (len % 4 !== 0) {
  6471. throw new RangeError('Buffer size must be a multiple of 32-bits')
  6472. }
  6473. for (var i = 0; i < len; i += 4) {
  6474. swap(this, i, i + 3)
  6475. swap(this, i + 1, i + 2)
  6476. }
  6477. return this
  6478. }
  6479. Buffer.prototype.toString = function toString () {
  6480. var length = this.length | 0
  6481. if (length === 0) return ''
  6482. if (arguments.length === 0) return utf8Slice(this, 0, length)
  6483. return slowToString.apply(this, arguments)
  6484. }
  6485. Buffer.prototype.equals = function equals (b) {
  6486. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  6487. if (this === b) return true
  6488. return Buffer.compare(this, b) === 0
  6489. }
  6490. Buffer.prototype.inspect = function inspect () {
  6491. var str = ''
  6492. var max = exports.INSPECT_MAX_BYTES
  6493. if (this.length > 0) {
  6494. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  6495. if (this.length > max) str += ' ... '
  6496. }
  6497. return '<Buffer ' + str + '>'
  6498. }
  6499. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  6500. if (!Buffer.isBuffer(target)) {
  6501. throw new TypeError('Argument must be a Buffer')
  6502. }
  6503. if (start === undefined) {
  6504. start = 0
  6505. }
  6506. if (end === undefined) {
  6507. end = target ? target.length : 0
  6508. }
  6509. if (thisStart === undefined) {
  6510. thisStart = 0
  6511. }
  6512. if (thisEnd === undefined) {
  6513. thisEnd = this.length
  6514. }
  6515. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  6516. throw new RangeError('out of range index')
  6517. }
  6518. if (thisStart >= thisEnd && start >= end) {
  6519. return 0
  6520. }
  6521. if (thisStart >= thisEnd) {
  6522. return -1
  6523. }
  6524. if (start >= end) {
  6525. return 1
  6526. }
  6527. start >>>= 0
  6528. end >>>= 0
  6529. thisStart >>>= 0
  6530. thisEnd >>>= 0
  6531. if (this === target) return 0
  6532. var x = thisEnd - thisStart
  6533. var y = end - start
  6534. var len = Math.min(x, y)
  6535. var thisCopy = this.slice(thisStart, thisEnd)
  6536. var targetCopy = target.slice(start, end)
  6537. for (var i = 0; i < len; ++i) {
  6538. if (thisCopy[i] !== targetCopy[i]) {
  6539. x = thisCopy[i]
  6540. y = targetCopy[i]
  6541. break
  6542. }
  6543. }
  6544. if (x < y) return -1
  6545. if (y < x) return 1
  6546. return 0
  6547. }
  6548. function arrayIndexOf (arr, val, byteOffset, encoding) {
  6549. var indexSize = 1
  6550. var arrLength = arr.length
  6551. var valLength = val.length
  6552. if (encoding !== undefined) {
  6553. encoding = String(encoding).toLowerCase()
  6554. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  6555. encoding === 'utf16le' || encoding === 'utf-16le') {
  6556. if (arr.length < 2 || val.length < 2) {
  6557. return -1
  6558. }
  6559. indexSize = 2
  6560. arrLength /= 2
  6561. valLength /= 2
  6562. byteOffset /= 2
  6563. }
  6564. }
  6565. function read (buf, i) {
  6566. if (indexSize === 1) {
  6567. return buf[i]
  6568. } else {
  6569. return buf.readUInt16BE(i * indexSize)
  6570. }
  6571. }
  6572. var foundIndex = -1
  6573. for (var i = byteOffset; i < arrLength; ++i) {
  6574. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  6575. if (foundIndex === -1) foundIndex = i
  6576. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  6577. } else {
  6578. if (foundIndex !== -1) i -= i - foundIndex
  6579. foundIndex = -1
  6580. }
  6581. }
  6582. return -1
  6583. }
  6584. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  6585. if (typeof byteOffset === 'string') {
  6586. encoding = byteOffset
  6587. byteOffset = 0
  6588. } else if (byteOffset > 0x7fffffff) {
  6589. byteOffset = 0x7fffffff
  6590. } else if (byteOffset < -0x80000000) {
  6591. byteOffset = -0x80000000
  6592. }
  6593. byteOffset >>= 0
  6594. if (this.length === 0) return -1
  6595. if (byteOffset >= this.length) return -1
  6596. // Negative offsets start from the end of the buffer
  6597. if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0)
  6598. if (typeof val === 'string') {
  6599. val = Buffer.from(val, encoding)
  6600. }
  6601. if (Buffer.isBuffer(val)) {
  6602. // special case: looking for empty string/buffer always fails
  6603. if (val.length === 0) {
  6604. return -1
  6605. }
  6606. return arrayIndexOf(this, val, byteOffset, encoding)
  6607. }
  6608. if (typeof val === 'number') {
  6609. if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') {
  6610. return Uint8Array.prototype.indexOf.call(this, val, byteOffset)
  6611. }
  6612. return arrayIndexOf(this, [ val ], byteOffset, encoding)
  6613. }
  6614. throw new TypeError('val must be string, number or Buffer')
  6615. }
  6616. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  6617. return this.indexOf(val, byteOffset, encoding) !== -1
  6618. }
  6619. function hexWrite (buf, string, offset, length) {
  6620. offset = Number(offset) || 0
  6621. var remaining = buf.length - offset
  6622. if (!length) {
  6623. length = remaining
  6624. } else {
  6625. length = Number(length)
  6626. if (length > remaining) {
  6627. length = remaining
  6628. }
  6629. }
  6630. // must be an even number of digits
  6631. var strLen = string.length
  6632. if (strLen % 2 !== 0) throw new Error('Invalid hex string')
  6633. if (length > strLen / 2) {
  6634. length = strLen / 2
  6635. }
  6636. for (var i = 0; i < length; ++i) {
  6637. var parsed = parseInt(string.substr(i * 2, 2), 16)
  6638. if (isNaN(parsed)) return i
  6639. buf[offset + i] = parsed
  6640. }
  6641. return i
  6642. }
  6643. function utf8Write (buf, string, offset, length) {
  6644. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  6645. }
  6646. function asciiWrite (buf, string, offset, length) {
  6647. return blitBuffer(asciiToBytes(string), buf, offset, length)
  6648. }
  6649. function binaryWrite (buf, string, offset, length) {
  6650. return asciiWrite(buf, string, offset, length)
  6651. }
  6652. function base64Write (buf, string, offset, length) {
  6653. return blitBuffer(base64ToBytes(string), buf, offset, length)
  6654. }
  6655. function ucs2Write (buf, string, offset, length) {
  6656. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  6657. }
  6658. Buffer.prototype.write = function write (string, offset, length, encoding) {
  6659. // Buffer#write(string)
  6660. if (offset === undefined) {
  6661. encoding = 'utf8'
  6662. length = this.length
  6663. offset = 0
  6664. // Buffer#write(string, encoding)
  6665. } else if (length === undefined && typeof offset === 'string') {
  6666. encoding = offset
  6667. length = this.length
  6668. offset = 0
  6669. // Buffer#write(string, offset[, length][, encoding])
  6670. } else if (isFinite(offset)) {
  6671. offset = offset | 0
  6672. if (isFinite(length)) {
  6673. length = length | 0
  6674. if (encoding === undefined) encoding = 'utf8'
  6675. } else {
  6676. encoding = length
  6677. length = undefined
  6678. }
  6679. // legacy write(string, encoding, offset, length) - remove in v0.13
  6680. } else {
  6681. throw new Error(
  6682. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  6683. )
  6684. }
  6685. var remaining = this.length - offset
  6686. if (length === undefined || length > remaining) length = remaining
  6687. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  6688. throw new RangeError('Attempt to write outside buffer bounds')
  6689. }
  6690. if (!encoding) encoding = 'utf8'
  6691. var loweredCase = false
  6692. for (;;) {
  6693. switch (encoding) {
  6694. case 'hex':
  6695. return hexWrite(this, string, offset, length)
  6696. case 'utf8':
  6697. case 'utf-8':
  6698. return utf8Write(this, string, offset, length)
  6699. case 'ascii':
  6700. return asciiWrite(this, string, offset, length)
  6701. case 'binary':
  6702. return binaryWrite(this, string, offset, length)
  6703. case 'base64':
  6704. // Warning: maxLength not taken into account in base64Write
  6705. return base64Write(this, string, offset, length)
  6706. case 'ucs2':
  6707. case 'ucs-2':
  6708. case 'utf16le':
  6709. case 'utf-16le':
  6710. return ucs2Write(this, string, offset, length)
  6711. default:
  6712. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  6713. encoding = ('' + encoding).toLowerCase()
  6714. loweredCase = true
  6715. }
  6716. }
  6717. }
  6718. Buffer.prototype.toJSON = function toJSON () {
  6719. return {
  6720. type: 'Buffer',
  6721. data: Array.prototype.slice.call(this._arr || this, 0)
  6722. }
  6723. }
  6724. function base64Slice (buf, start, end) {
  6725. if (start === 0 && end === buf.length) {
  6726. return base64.fromByteArray(buf)
  6727. } else {
  6728. return base64.fromByteArray(buf.slice(start, end))
  6729. }
  6730. }
  6731. function utf8Slice (buf, start, end) {
  6732. end = Math.min(buf.length, end)
  6733. var res = []
  6734. var i = start
  6735. while (i < end) {
  6736. var firstByte = buf[i]
  6737. var codePoint = null
  6738. var bytesPerSequence = (firstByte > 0xEF) ? 4
  6739. : (firstByte > 0xDF) ? 3
  6740. : (firstByte > 0xBF) ? 2
  6741. : 1
  6742. if (i + bytesPerSequence <= end) {
  6743. var secondByte, thirdByte, fourthByte, tempCodePoint
  6744. switch (bytesPerSequence) {
  6745. case 1:
  6746. if (firstByte < 0x80) {
  6747. codePoint = firstByte
  6748. }
  6749. break
  6750. case 2:
  6751. secondByte = buf[i + 1]
  6752. if ((secondByte & 0xC0) === 0x80) {
  6753. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  6754. if (tempCodePoint > 0x7F) {
  6755. codePoint = tempCodePoint
  6756. }
  6757. }
  6758. break
  6759. case 3:
  6760. secondByte = buf[i + 1]
  6761. thirdByte = buf[i + 2]
  6762. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  6763. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  6764. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  6765. codePoint = tempCodePoint
  6766. }
  6767. }
  6768. break
  6769. case 4:
  6770. secondByte = buf[i + 1]
  6771. thirdByte = buf[i + 2]
  6772. fourthByte = buf[i + 3]
  6773. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  6774. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  6775. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  6776. codePoint = tempCodePoint
  6777. }
  6778. }
  6779. }
  6780. }
  6781. if (codePoint === null) {
  6782. // we did not generate a valid codePoint so insert a
  6783. // replacement char (U+FFFD) and advance only 1 byte
  6784. codePoint = 0xFFFD
  6785. bytesPerSequence = 1
  6786. } else if (codePoint > 0xFFFF) {
  6787. // encode to utf16 (surrogate pair dance)
  6788. codePoint -= 0x10000
  6789. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  6790. codePoint = 0xDC00 | codePoint & 0x3FF
  6791. }
  6792. res.push(codePoint)
  6793. i += bytesPerSequence
  6794. }
  6795. return decodeCodePointsArray(res)
  6796. }
  6797. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  6798. // the lowest limit is Chrome, with 0x10000 args.
  6799. // We go 1 magnitude less, for safety
  6800. var MAX_ARGUMENTS_LENGTH = 0x1000
  6801. function decodeCodePointsArray (codePoints) {
  6802. var len = codePoints.length
  6803. if (len <= MAX_ARGUMENTS_LENGTH) {
  6804. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  6805. }
  6806. // Decode in chunks to avoid "call stack size exceeded".
  6807. var res = ''
  6808. var i = 0
  6809. while (i < len) {
  6810. res += String.fromCharCode.apply(
  6811. String,
  6812. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  6813. )
  6814. }
  6815. return res
  6816. }
  6817. function asciiSlice (buf, start, end) {
  6818. var ret = ''
  6819. end = Math.min(buf.length, end)
  6820. for (var i = start; i < end; ++i) {
  6821. ret += String.fromCharCode(buf[i] & 0x7F)
  6822. }
  6823. return ret
  6824. }
  6825. function binarySlice (buf, start, end) {
  6826. var ret = ''
  6827. end = Math.min(buf.length, end)
  6828. for (var i = start; i < end; ++i) {
  6829. ret += String.fromCharCode(buf[i])
  6830. }
  6831. return ret
  6832. }
  6833. function hexSlice (buf, start, end) {
  6834. var len = buf.length
  6835. if (!start || start < 0) start = 0
  6836. if (!end || end < 0 || end > len) end = len
  6837. var out = ''
  6838. for (var i = start; i < end; ++i) {
  6839. out += toHex(buf[i])
  6840. }
  6841. return out
  6842. }
  6843. function utf16leSlice (buf, start, end) {
  6844. var bytes = buf.slice(start, end)
  6845. var res = ''
  6846. for (var i = 0; i < bytes.length; i += 2) {
  6847. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
  6848. }
  6849. return res
  6850. }
  6851. Buffer.prototype.slice = function slice (start, end) {
  6852. var len = this.length
  6853. start = ~~start
  6854. end = end === undefined ? len : ~~end
  6855. if (start < 0) {
  6856. start += len
  6857. if (start < 0) start = 0
  6858. } else if (start > len) {
  6859. start = len
  6860. }
  6861. if (end < 0) {
  6862. end += len
  6863. if (end < 0) end = 0
  6864. } else if (end > len) {
  6865. end = len
  6866. }
  6867. if (end < start) end = start
  6868. var newBuf
  6869. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6870. newBuf = this.subarray(start, end)
  6871. newBuf.__proto__ = Buffer.prototype
  6872. } else {
  6873. var sliceLen = end - start
  6874. newBuf = new Buffer(sliceLen, undefined)
  6875. for (var i = 0; i < sliceLen; ++i) {
  6876. newBuf[i] = this[i + start]
  6877. }
  6878. }
  6879. return newBuf
  6880. }
  6881. /*
  6882. * Need to make sure that buffer isn't trying to write out of bounds.
  6883. */
  6884. function checkOffset (offset, ext, length) {
  6885. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  6886. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  6887. }
  6888. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  6889. offset = offset | 0
  6890. byteLength = byteLength | 0
  6891. if (!noAssert) checkOffset(offset, byteLength, this.length)
  6892. var val = this[offset]
  6893. var mul = 1
  6894. var i = 0
  6895. while (++i < byteLength && (mul *= 0x100)) {
  6896. val += this[offset + i] * mul
  6897. }
  6898. return val
  6899. }
  6900. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  6901. offset = offset | 0
  6902. byteLength = byteLength | 0
  6903. if (!noAssert) {
  6904. checkOffset(offset, byteLength, this.length)
  6905. }
  6906. var val = this[offset + --byteLength]
  6907. var mul = 1
  6908. while (byteLength > 0 && (mul *= 0x100)) {
  6909. val += this[offset + --byteLength] * mul
  6910. }
  6911. return val
  6912. }
  6913. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  6914. if (!noAssert) checkOffset(offset, 1, this.length)
  6915. return this[offset]
  6916. }
  6917. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  6918. if (!noAssert) checkOffset(offset, 2, this.length)
  6919. return this[offset] | (this[offset + 1] << 8)
  6920. }
  6921. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  6922. if (!noAssert) checkOffset(offset, 2, this.length)
  6923. return (this[offset] << 8) | this[offset + 1]
  6924. }
  6925. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  6926. if (!noAssert) checkOffset(offset, 4, this.length)
  6927. return ((this[offset]) |
  6928. (this[offset + 1] << 8) |
  6929. (this[offset + 2] << 16)) +
  6930. (this[offset + 3] * 0x1000000)
  6931. }
  6932. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  6933. if (!noAssert) checkOffset(offset, 4, this.length)
  6934. return (this[offset] * 0x1000000) +
  6935. ((this[offset + 1] << 16) |
  6936. (this[offset + 2] << 8) |
  6937. this[offset + 3])
  6938. }
  6939. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  6940. offset = offset | 0
  6941. byteLength = byteLength | 0
  6942. if (!noAssert) checkOffset(offset, byteLength, this.length)
  6943. var val = this[offset]
  6944. var mul = 1
  6945. var i = 0
  6946. while (++i < byteLength && (mul *= 0x100)) {
  6947. val += this[offset + i] * mul
  6948. }
  6949. mul *= 0x80
  6950. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  6951. return val
  6952. }
  6953. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  6954. offset = offset | 0
  6955. byteLength = byteLength | 0
  6956. if (!noAssert) checkOffset(offset, byteLength, this.length)
  6957. var i = byteLength
  6958. var mul = 1
  6959. var val = this[offset + --i]
  6960. while (i > 0 && (mul *= 0x100)) {
  6961. val += this[offset + --i] * mul
  6962. }
  6963. mul *= 0x80
  6964. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  6965. return val
  6966. }
  6967. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  6968. if (!noAssert) checkOffset(offset, 1, this.length)
  6969. if (!(this[offset] & 0x80)) return (this[offset])
  6970. return ((0xff - this[offset] + 1) * -1)
  6971. }
  6972. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  6973. if (!noAssert) checkOffset(offset, 2, this.length)
  6974. var val = this[offset] | (this[offset + 1] << 8)
  6975. return (val & 0x8000) ? val | 0xFFFF0000 : val
  6976. }
  6977. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  6978. if (!noAssert) checkOffset(offset, 2, this.length)
  6979. var val = this[offset + 1] | (this[offset] << 8)
  6980. return (val & 0x8000) ? val | 0xFFFF0000 : val
  6981. }
  6982. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  6983. if (!noAssert) checkOffset(offset, 4, this.length)
  6984. return (this[offset]) |
  6985. (this[offset + 1] << 8) |
  6986. (this[offset + 2] << 16) |
  6987. (this[offset + 3] << 24)
  6988. }
  6989. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  6990. if (!noAssert) checkOffset(offset, 4, this.length)
  6991. return (this[offset] << 24) |
  6992. (this[offset + 1] << 16) |
  6993. (this[offset + 2] << 8) |
  6994. (this[offset + 3])
  6995. }
  6996. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  6997. if (!noAssert) checkOffset(offset, 4, this.length)
  6998. return ieee754.read(this, offset, true, 23, 4)
  6999. }
  7000. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  7001. if (!noAssert) checkOffset(offset, 4, this.length)
  7002. return ieee754.read(this, offset, false, 23, 4)
  7003. }
  7004. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  7005. if (!noAssert) checkOffset(offset, 8, this.length)
  7006. return ieee754.read(this, offset, true, 52, 8)
  7007. }
  7008. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  7009. if (!noAssert) checkOffset(offset, 8, this.length)
  7010. return ieee754.read(this, offset, false, 52, 8)
  7011. }
  7012. function checkInt (buf, value, offset, ext, max, min) {
  7013. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  7014. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  7015. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  7016. }
  7017. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  7018. value = +value
  7019. offset = offset | 0
  7020. byteLength = byteLength | 0
  7021. if (!noAssert) {
  7022. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  7023. checkInt(this, value, offset, byteLength, maxBytes, 0)
  7024. }
  7025. var mul = 1
  7026. var i = 0
  7027. this[offset] = value & 0xFF
  7028. while (++i < byteLength && (mul *= 0x100)) {
  7029. this[offset + i] = (value / mul) & 0xFF
  7030. }
  7031. return offset + byteLength
  7032. }
  7033. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  7034. value = +value
  7035. offset = offset | 0
  7036. byteLength = byteLength | 0
  7037. if (!noAssert) {
  7038. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  7039. checkInt(this, value, offset, byteLength, maxBytes, 0)
  7040. }
  7041. var i = byteLength - 1
  7042. var mul = 1
  7043. this[offset + i] = value & 0xFF
  7044. while (--i >= 0 && (mul *= 0x100)) {
  7045. this[offset + i] = (value / mul) & 0xFF
  7046. }
  7047. return offset + byteLength
  7048. }
  7049. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  7050. value = +value
  7051. offset = offset | 0
  7052. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  7053. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  7054. this[offset] = (value & 0xff)
  7055. return offset + 1
  7056. }
  7057. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  7058. if (value < 0) value = 0xffff + value + 1
  7059. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  7060. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  7061. (littleEndian ? i : 1 - i) * 8
  7062. }
  7063. }
  7064. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  7065. value = +value
  7066. offset = offset | 0
  7067. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  7068. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7069. this[offset] = (value & 0xff)
  7070. this[offset + 1] = (value >>> 8)
  7071. } else {
  7072. objectWriteUInt16(this, value, offset, true)
  7073. }
  7074. return offset + 2
  7075. }
  7076. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  7077. value = +value
  7078. offset = offset | 0
  7079. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  7080. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7081. this[offset] = (value >>> 8)
  7082. this[offset + 1] = (value & 0xff)
  7083. } else {
  7084. objectWriteUInt16(this, value, offset, false)
  7085. }
  7086. return offset + 2
  7087. }
  7088. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  7089. if (value < 0) value = 0xffffffff + value + 1
  7090. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  7091. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  7092. }
  7093. }
  7094. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  7095. value = +value
  7096. offset = offset | 0
  7097. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  7098. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7099. this[offset + 3] = (value >>> 24)
  7100. this[offset + 2] = (value >>> 16)
  7101. this[offset + 1] = (value >>> 8)
  7102. this[offset] = (value & 0xff)
  7103. } else {
  7104. objectWriteUInt32(this, value, offset, true)
  7105. }
  7106. return offset + 4
  7107. }
  7108. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  7109. value = +value
  7110. offset = offset | 0
  7111. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  7112. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7113. this[offset] = (value >>> 24)
  7114. this[offset + 1] = (value >>> 16)
  7115. this[offset + 2] = (value >>> 8)
  7116. this[offset + 3] = (value & 0xff)
  7117. } else {
  7118. objectWriteUInt32(this, value, offset, false)
  7119. }
  7120. return offset + 4
  7121. }
  7122. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  7123. value = +value
  7124. offset = offset | 0
  7125. if (!noAssert) {
  7126. var limit = Math.pow(2, 8 * byteLength - 1)
  7127. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  7128. }
  7129. var i = 0
  7130. var mul = 1
  7131. var sub = 0
  7132. this[offset] = value & 0xFF
  7133. while (++i < byteLength && (mul *= 0x100)) {
  7134. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  7135. sub = 1
  7136. }
  7137. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  7138. }
  7139. return offset + byteLength
  7140. }
  7141. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  7142. value = +value
  7143. offset = offset | 0
  7144. if (!noAssert) {
  7145. var limit = Math.pow(2, 8 * byteLength - 1)
  7146. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  7147. }
  7148. var i = byteLength - 1
  7149. var mul = 1
  7150. var sub = 0
  7151. this[offset + i] = value & 0xFF
  7152. while (--i >= 0 && (mul *= 0x100)) {
  7153. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  7154. sub = 1
  7155. }
  7156. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  7157. }
  7158. return offset + byteLength
  7159. }
  7160. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  7161. value = +value
  7162. offset = offset | 0
  7163. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  7164. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  7165. if (value < 0) value = 0xff + value + 1
  7166. this[offset] = (value & 0xff)
  7167. return offset + 1
  7168. }
  7169. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  7170. value = +value
  7171. offset = offset | 0
  7172. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  7173. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7174. this[offset] = (value & 0xff)
  7175. this[offset + 1] = (value >>> 8)
  7176. } else {
  7177. objectWriteUInt16(this, value, offset, true)
  7178. }
  7179. return offset + 2
  7180. }
  7181. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  7182. value = +value
  7183. offset = offset | 0
  7184. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  7185. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7186. this[offset] = (value >>> 8)
  7187. this[offset + 1] = (value & 0xff)
  7188. } else {
  7189. objectWriteUInt16(this, value, offset, false)
  7190. }
  7191. return offset + 2
  7192. }
  7193. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  7194. value = +value
  7195. offset = offset | 0
  7196. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  7197. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7198. this[offset] = (value & 0xff)
  7199. this[offset + 1] = (value >>> 8)
  7200. this[offset + 2] = (value >>> 16)
  7201. this[offset + 3] = (value >>> 24)
  7202. } else {
  7203. objectWriteUInt32(this, value, offset, true)
  7204. }
  7205. return offset + 4
  7206. }
  7207. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  7208. value = +value
  7209. offset = offset | 0
  7210. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  7211. if (value < 0) value = 0xffffffff + value + 1
  7212. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7213. this[offset] = (value >>> 24)
  7214. this[offset + 1] = (value >>> 16)
  7215. this[offset + 2] = (value >>> 8)
  7216. this[offset + 3] = (value & 0xff)
  7217. } else {
  7218. objectWriteUInt32(this, value, offset, false)
  7219. }
  7220. return offset + 4
  7221. }
  7222. function checkIEEE754 (buf, value, offset, ext, max, min) {
  7223. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  7224. if (offset < 0) throw new RangeError('Index out of range')
  7225. }
  7226. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  7227. if (!noAssert) {
  7228. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  7229. }
  7230. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  7231. return offset + 4
  7232. }
  7233. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  7234. return writeFloat(this, value, offset, true, noAssert)
  7235. }
  7236. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  7237. return writeFloat(this, value, offset, false, noAssert)
  7238. }
  7239. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  7240. if (!noAssert) {
  7241. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  7242. }
  7243. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  7244. return offset + 8
  7245. }
  7246. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  7247. return writeDouble(this, value, offset, true, noAssert)
  7248. }
  7249. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  7250. return writeDouble(this, value, offset, false, noAssert)
  7251. }
  7252. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  7253. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  7254. if (!start) start = 0
  7255. if (!end && end !== 0) end = this.length
  7256. if (targetStart >= target.length) targetStart = target.length
  7257. if (!targetStart) targetStart = 0
  7258. if (end > 0 && end < start) end = start
  7259. // Copy 0 bytes; we're done
  7260. if (end === start) return 0
  7261. if (target.length === 0 || this.length === 0) return 0
  7262. // Fatal error conditions
  7263. if (targetStart < 0) {
  7264. throw new RangeError('targetStart out of bounds')
  7265. }
  7266. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  7267. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  7268. // Are we oob?
  7269. if (end > this.length) end = this.length
  7270. if (target.length - targetStart < end - start) {
  7271. end = target.length - targetStart + start
  7272. }
  7273. var len = end - start
  7274. var i
  7275. if (this === target && start < targetStart && targetStart < end) {
  7276. // descending copy from end
  7277. for (i = len - 1; i >= 0; --i) {
  7278. target[i + targetStart] = this[i + start]
  7279. }
  7280. } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  7281. // ascending copy from start
  7282. for (i = 0; i < len; ++i) {
  7283. target[i + targetStart] = this[i + start]
  7284. }
  7285. } else {
  7286. Uint8Array.prototype.set.call(
  7287. target,
  7288. this.subarray(start, start + len),
  7289. targetStart
  7290. )
  7291. }
  7292. return len
  7293. }
  7294. // Usage:
  7295. // buffer.fill(number[, offset[, end]])
  7296. // buffer.fill(buffer[, offset[, end]])
  7297. // buffer.fill(string[, offset[, end]][, encoding])
  7298. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  7299. // Handle string cases:
  7300. if (typeof val === 'string') {
  7301. if (typeof start === 'string') {
  7302. encoding = start
  7303. start = 0
  7304. end = this.length
  7305. } else if (typeof end === 'string') {
  7306. encoding = end
  7307. end = this.length
  7308. }
  7309. if (val.length === 1) {
  7310. var code = val.charCodeAt(0)
  7311. if (code < 256) {
  7312. val = code
  7313. }
  7314. }
  7315. if (encoding !== undefined && typeof encoding !== 'string') {
  7316. throw new TypeError('encoding must be a string')
  7317. }
  7318. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  7319. throw new TypeError('Unknown encoding: ' + encoding)
  7320. }
  7321. } else if (typeof val === 'number') {
  7322. val = val & 255
  7323. }
  7324. // Invalid ranges are not set to a default, so can range check early.
  7325. if (start < 0 || this.length < start || this.length < end) {
  7326. throw new RangeError('Out of range index')
  7327. }
  7328. if (end <= start) {
  7329. return this
  7330. }
  7331. start = start >>> 0
  7332. end = end === undefined ? this.length : end >>> 0
  7333. if (!val) val = 0
  7334. var i
  7335. if (typeof val === 'number') {
  7336. for (i = start; i < end; ++i) {
  7337. this[i] = val
  7338. }
  7339. } else {
  7340. var bytes = Buffer.isBuffer(val)
  7341. ? val
  7342. : utf8ToBytes(new Buffer(val, encoding).toString())
  7343. var len = bytes.length
  7344. for (i = 0; i < end - start; ++i) {
  7345. this[i + start] = bytes[i % len]
  7346. }
  7347. }
  7348. return this
  7349. }
  7350. // HELPER FUNCTIONS
  7351. // ================
  7352. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
  7353. function base64clean (str) {
  7354. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  7355. str = stringtrim(str).replace(INVALID_BASE64_RE, '')
  7356. // Node converts strings with length < 2 to ''
  7357. if (str.length < 2) return ''
  7358. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  7359. while (str.length % 4 !== 0) {
  7360. str = str + '='
  7361. }
  7362. return str
  7363. }
  7364. function stringtrim (str) {
  7365. if (str.trim) return str.trim()
  7366. return str.replace(/^\s+|\s+$/g, '')
  7367. }
  7368. function toHex (n) {
  7369. if (n < 16) return '0' + n.toString(16)
  7370. return n.toString(16)
  7371. }
  7372. function utf8ToBytes (string, units) {
  7373. units = units || Infinity
  7374. var codePoint
  7375. var length = string.length
  7376. var leadSurrogate = null
  7377. var bytes = []
  7378. for (var i = 0; i < length; ++i) {
  7379. codePoint = string.charCodeAt(i)
  7380. // is surrogate component
  7381. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  7382. // last char was a lead
  7383. if (!leadSurrogate) {
  7384. // no lead yet
  7385. if (codePoint > 0xDBFF) {
  7386. // unexpected trail
  7387. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7388. continue
  7389. } else if (i + 1 === length) {
  7390. // unpaired lead
  7391. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7392. continue
  7393. }
  7394. // valid lead
  7395. leadSurrogate = codePoint
  7396. continue
  7397. }
  7398. // 2 leads in a row
  7399. if (codePoint < 0xDC00) {
  7400. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7401. leadSurrogate = codePoint
  7402. continue
  7403. }
  7404. // valid surrogate pair
  7405. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  7406. } else if (leadSurrogate) {
  7407. // valid bmp char, but last char was a lead
  7408. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7409. }
  7410. leadSurrogate = null
  7411. // encode utf8
  7412. if (codePoint < 0x80) {
  7413. if ((units -= 1) < 0) break
  7414. bytes.push(codePoint)
  7415. } else if (codePoint < 0x800) {
  7416. if ((units -= 2) < 0) break
  7417. bytes.push(
  7418. codePoint >> 0x6 | 0xC0,
  7419. codePoint & 0x3F | 0x80
  7420. )
  7421. } else if (codePoint < 0x10000) {
  7422. if ((units -= 3) < 0) break
  7423. bytes.push(
  7424. codePoint >> 0xC | 0xE0,
  7425. codePoint >> 0x6 & 0x3F | 0x80,
  7426. codePoint & 0x3F | 0x80
  7427. )
  7428. } else if (codePoint < 0x110000) {
  7429. if ((units -= 4) < 0) break
  7430. bytes.push(
  7431. codePoint >> 0x12 | 0xF0,
  7432. codePoint >> 0xC & 0x3F | 0x80,
  7433. codePoint >> 0x6 & 0x3F | 0x80,
  7434. codePoint & 0x3F | 0x80
  7435. )
  7436. } else {
  7437. throw new Error('Invalid code point')
  7438. }
  7439. }
  7440. return bytes
  7441. }
  7442. function asciiToBytes (str) {
  7443. var byteArray = []
  7444. for (var i = 0; i < str.length; ++i) {
  7445. // Node's code seems to be doing this and not & 0x7F..
  7446. byteArray.push(str.charCodeAt(i) & 0xFF)
  7447. }
  7448. return byteArray
  7449. }
  7450. function utf16leToBytes (str, units) {
  7451. var c, hi, lo
  7452. var byteArray = []
  7453. for (var i = 0; i < str.length; ++i) {
  7454. if ((units -= 2) < 0) break
  7455. c = str.charCodeAt(i)
  7456. hi = c >> 8
  7457. lo = c % 256
  7458. byteArray.push(lo)
  7459. byteArray.push(hi)
  7460. }
  7461. return byteArray
  7462. }
  7463. function base64ToBytes (str) {
  7464. return base64.toByteArray(base64clean(str))
  7465. }
  7466. function blitBuffer (src, dst, offset, length) {
  7467. for (var i = 0; i < length; ++i) {
  7468. if ((i + offset >= dst.length) || (i >= src.length)) break
  7469. dst[i + offset] = src[i]
  7470. }
  7471. return i
  7472. }
  7473. function isnan (val) {
  7474. return val !== val // eslint-disable-line no-self-compare
  7475. }
  7476. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7477. },{"base64-js":39,"ieee754":50,"isarray":53}],45:[function(require,module,exports){
  7478. (function (Buffer){
  7479. // Copyright Joyent, Inc. and other Node contributors.
  7480. //
  7481. // Permission is hereby granted, free of charge, to any person obtaining a
  7482. // copy of this software and associated documentation files (the
  7483. // "Software"), to deal in the Software without restriction, including
  7484. // without limitation the rights to use, copy, modify, merge, publish,
  7485. // distribute, sublicense, and/or sell copies of the Software, and to permit
  7486. // persons to whom the Software is furnished to do so, subject to the
  7487. // following conditions:
  7488. //
  7489. // The above copyright notice and this permission notice shall be included
  7490. // in all copies or substantial portions of the Software.
  7491. //
  7492. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  7493. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  7494. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  7495. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  7496. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  7497. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  7498. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  7499. // NOTE: These type checking functions intentionally don't use `instanceof`
  7500. // because it is fragile and can be easily faked with `Object.create()`.
  7501. function isArray(arg) {
  7502. if (Array.isArray) {
  7503. return Array.isArray(arg);
  7504. }
  7505. return objectToString(arg) === '[object Array]';
  7506. }
  7507. exports.isArray = isArray;
  7508. function isBoolean(arg) {
  7509. return typeof arg === 'boolean';
  7510. }
  7511. exports.isBoolean = isBoolean;
  7512. function isNull(arg) {
  7513. return arg === null;
  7514. }
  7515. exports.isNull = isNull;
  7516. function isNullOrUndefined(arg) {
  7517. return arg == null;
  7518. }
  7519. exports.isNullOrUndefined = isNullOrUndefined;
  7520. function isNumber(arg) {
  7521. return typeof arg === 'number';
  7522. }
  7523. exports.isNumber = isNumber;
  7524. function isString(arg) {
  7525. return typeof arg === 'string';
  7526. }
  7527. exports.isString = isString;
  7528. function isSymbol(arg) {
  7529. return typeof arg === 'symbol';
  7530. }
  7531. exports.isSymbol = isSymbol;
  7532. function isUndefined(arg) {
  7533. return arg === void 0;
  7534. }
  7535. exports.isUndefined = isUndefined;
  7536. function isRegExp(re) {
  7537. return objectToString(re) === '[object RegExp]';
  7538. }
  7539. exports.isRegExp = isRegExp;
  7540. function isObject(arg) {
  7541. return typeof arg === 'object' && arg !== null;
  7542. }
  7543. exports.isObject = isObject;
  7544. function isDate(d) {
  7545. return objectToString(d) === '[object Date]';
  7546. }
  7547. exports.isDate = isDate;
  7548. function isError(e) {
  7549. return (objectToString(e) === '[object Error]' || e instanceof Error);
  7550. }
  7551. exports.isError = isError;
  7552. function isFunction(arg) {
  7553. return typeof arg === 'function';
  7554. }
  7555. exports.isFunction = isFunction;
  7556. function isPrimitive(arg) {
  7557. return arg === null ||
  7558. typeof arg === 'boolean' ||
  7559. typeof arg === 'number' ||
  7560. typeof arg === 'string' ||
  7561. typeof arg === 'symbol' || // ES6 symbol
  7562. typeof arg === 'undefined';
  7563. }
  7564. exports.isPrimitive = isPrimitive;
  7565. exports.isBuffer = Buffer.isBuffer;
  7566. function objectToString(o) {
  7567. return Object.prototype.toString.call(o);
  7568. }
  7569. }).call(this,{"isBuffer":require("../../is-buffer/index.js")})
  7570. },{"../../is-buffer/index.js":52}],46:[function(require,module,exports){
  7571. /* See LICENSE file for terms of use */
  7572. /*
  7573. * Text diff implementation.
  7574. *
  7575. * This library supports the following APIS:
  7576. * JsDiff.diffChars: Character by character diff
  7577. * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace
  7578. * JsDiff.diffLines: Line based diff
  7579. *
  7580. * JsDiff.diffCss: Diff targeted at CSS content
  7581. *
  7582. * These methods are based on the implementation proposed in
  7583. * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).
  7584. * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927
  7585. */
  7586. (function(global, undefined) {
  7587. var objectPrototypeToString = Object.prototype.toString;
  7588. /*istanbul ignore next*/
  7589. function map(arr, mapper, that) {
  7590. if (Array.prototype.map) {
  7591. return Array.prototype.map.call(arr, mapper, that);
  7592. }
  7593. var other = new Array(arr.length);
  7594. for (var i = 0, n = arr.length; i < n; i++) {
  7595. other[i] = mapper.call(that, arr[i], i, arr);
  7596. }
  7597. return other;
  7598. }
  7599. function clonePath(path) {
  7600. return { newPos: path.newPos, components: path.components.slice(0) };
  7601. }
  7602. function removeEmpty(array) {
  7603. var ret = [];
  7604. for (var i = 0; i < array.length; i++) {
  7605. if (array[i]) {
  7606. ret.push(array[i]);
  7607. }
  7608. }
  7609. return ret;
  7610. }
  7611. function escapeHTML(s) {
  7612. var n = s;
  7613. n = n.replace(/&/g, '&amp;');
  7614. n = n.replace(/</g, '&lt;');
  7615. n = n.replace(/>/g, '&gt;');
  7616. n = n.replace(/"/g, '&quot;');
  7617. return n;
  7618. }
  7619. // This function handles the presence of circular references by bailing out when encountering an
  7620. // object that is already on the "stack" of items being processed.
  7621. function canonicalize(obj, stack, replacementStack) {
  7622. stack = stack || [];
  7623. replacementStack = replacementStack || [];
  7624. var i;
  7625. for (i = 0; i < stack.length; i += 1) {
  7626. if (stack[i] === obj) {
  7627. return replacementStack[i];
  7628. }
  7629. }
  7630. var canonicalizedObj;
  7631. if ('[object Array]' === objectPrototypeToString.call(obj)) {
  7632. stack.push(obj);
  7633. canonicalizedObj = new Array(obj.length);
  7634. replacementStack.push(canonicalizedObj);
  7635. for (i = 0; i < obj.length; i += 1) {
  7636. canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack);
  7637. }
  7638. stack.pop();
  7639. replacementStack.pop();
  7640. } else if (typeof obj === 'object' && obj !== null) {
  7641. stack.push(obj);
  7642. canonicalizedObj = {};
  7643. replacementStack.push(canonicalizedObj);
  7644. var sortedKeys = [],
  7645. key;
  7646. for (key in obj) {
  7647. sortedKeys.push(key);
  7648. }
  7649. sortedKeys.sort();
  7650. for (i = 0; i < sortedKeys.length; i += 1) {
  7651. key = sortedKeys[i];
  7652. canonicalizedObj[key] = canonicalize(obj[key], stack, replacementStack);
  7653. }
  7654. stack.pop();
  7655. replacementStack.pop();
  7656. } else {
  7657. canonicalizedObj = obj;
  7658. }
  7659. return canonicalizedObj;
  7660. }
  7661. function buildValues(components, newString, oldString, useLongestToken) {
  7662. var componentPos = 0,
  7663. componentLen = components.length,
  7664. newPos = 0,
  7665. oldPos = 0;
  7666. for (; componentPos < componentLen; componentPos++) {
  7667. var component = components[componentPos];
  7668. if (!component.removed) {
  7669. if (!component.added && useLongestToken) {
  7670. var value = newString.slice(newPos, newPos + component.count);
  7671. value = map(value, function(value, i) {
  7672. var oldValue = oldString[oldPos + i];
  7673. return oldValue.length > value.length ? oldValue : value;
  7674. });
  7675. component.value = value.join('');
  7676. } else {
  7677. component.value = newString.slice(newPos, newPos + component.count).join('');
  7678. }
  7679. newPos += component.count;
  7680. // Common case
  7681. if (!component.added) {
  7682. oldPos += component.count;
  7683. }
  7684. } else {
  7685. component.value = oldString.slice(oldPos, oldPos + component.count).join('');
  7686. oldPos += component.count;
  7687. // Reverse add and remove so removes are output first to match common convention
  7688. // The diffing algorithm is tied to add then remove output and this is the simplest
  7689. // route to get the desired output with minimal overhead.
  7690. if (componentPos && components[componentPos - 1].added) {
  7691. var tmp = components[componentPos - 1];
  7692. components[componentPos - 1] = components[componentPos];
  7693. components[componentPos] = tmp;
  7694. }
  7695. }
  7696. }
  7697. return components;
  7698. }
  7699. function Diff(ignoreWhitespace) {
  7700. this.ignoreWhitespace = ignoreWhitespace;
  7701. }
  7702. Diff.prototype = {
  7703. diff: function(oldString, newString, callback) {
  7704. var self = this;
  7705. function done(value) {
  7706. if (callback) {
  7707. setTimeout(function() { callback(undefined, value); }, 0);
  7708. return true;
  7709. } else {
  7710. return value;
  7711. }
  7712. }
  7713. // Handle the identity case (this is due to unrolling editLength == 0
  7714. if (newString === oldString) {
  7715. return done([{ value: newString }]);
  7716. }
  7717. if (!newString) {
  7718. return done([{ value: oldString, removed: true }]);
  7719. }
  7720. if (!oldString) {
  7721. return done([{ value: newString, added: true }]);
  7722. }
  7723. newString = this.tokenize(newString);
  7724. oldString = this.tokenize(oldString);
  7725. var newLen = newString.length, oldLen = oldString.length;
  7726. var editLength = 1;
  7727. var maxEditLength = newLen + oldLen;
  7728. var bestPath = [{ newPos: -1, components: [] }];
  7729. // Seed editLength = 0, i.e. the content starts with the same values
  7730. var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
  7731. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  7732. // Identity per the equality and tokenizer
  7733. return done([{value: newString.join('')}]);
  7734. }
  7735. // Main worker method. checks all permutations of a given edit length for acceptance.
  7736. function execEditLength() {
  7737. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  7738. var basePath;
  7739. var addPath = bestPath[diagonalPath - 1],
  7740. removePath = bestPath[diagonalPath + 1],
  7741. oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  7742. if (addPath) {
  7743. // No one else is going to attempt to use this value, clear it
  7744. bestPath[diagonalPath - 1] = undefined;
  7745. }
  7746. var canAdd = addPath && addPath.newPos + 1 < newLen,
  7747. canRemove = removePath && 0 <= oldPos && oldPos < oldLen;
  7748. if (!canAdd && !canRemove) {
  7749. // If this path is a terminal then prune
  7750. bestPath[diagonalPath] = undefined;
  7751. continue;
  7752. }
  7753. // Select the diagonal that we want to branch from. We select the prior
  7754. // path whose position in the new string is the farthest from the origin
  7755. // and does not pass the bounds of the diff graph
  7756. if (!canAdd || (canRemove && addPath.newPos < removePath.newPos)) {
  7757. basePath = clonePath(removePath);
  7758. self.pushComponent(basePath.components, undefined, true);
  7759. } else {
  7760. basePath = addPath; // No need to clone, we've pulled it from the list
  7761. basePath.newPos++;
  7762. self.pushComponent(basePath.components, true, undefined);
  7763. }
  7764. oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath);
  7765. // If we have hit the end of both strings, then we are done
  7766. if (basePath.newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  7767. return done(buildValues(basePath.components, newString, oldString, self.useLongestToken));
  7768. } else {
  7769. // Otherwise track this path as a potential candidate and continue.
  7770. bestPath[diagonalPath] = basePath;
  7771. }
  7772. }
  7773. editLength++;
  7774. }
  7775. // Performs the length of edit iteration. Is a bit fugly as this has to support the
  7776. // sync and async mode which is never fun. Loops over execEditLength until a value
  7777. // is produced.
  7778. if (callback) {
  7779. (function exec() {
  7780. setTimeout(function() {
  7781. // This should not happen, but we want to be safe.
  7782. /*istanbul ignore next */
  7783. if (editLength > maxEditLength) {
  7784. return callback();
  7785. }
  7786. if (!execEditLength()) {
  7787. exec();
  7788. }
  7789. }, 0);
  7790. }());
  7791. } else {
  7792. while (editLength <= maxEditLength) {
  7793. var ret = execEditLength();
  7794. if (ret) {
  7795. return ret;
  7796. }
  7797. }
  7798. }
  7799. },
  7800. pushComponent: function(components, added, removed) {
  7801. var last = components[components.length - 1];
  7802. if (last && last.added === added && last.removed === removed) {
  7803. // We need to clone here as the component clone operation is just
  7804. // as shallow array clone
  7805. components[components.length - 1] = {count: last.count + 1, added: added, removed: removed };
  7806. } else {
  7807. components.push({count: 1, added: added, removed: removed });
  7808. }
  7809. },
  7810. extractCommon: function(basePath, newString, oldString, diagonalPath) {
  7811. var newLen = newString.length,
  7812. oldLen = oldString.length,
  7813. newPos = basePath.newPos,
  7814. oldPos = newPos - diagonalPath,
  7815. commonCount = 0;
  7816. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
  7817. newPos++;
  7818. oldPos++;
  7819. commonCount++;
  7820. }
  7821. if (commonCount) {
  7822. basePath.components.push({count: commonCount});
  7823. }
  7824. basePath.newPos = newPos;
  7825. return oldPos;
  7826. },
  7827. equals: function(left, right) {
  7828. var reWhitespace = /\S/;
  7829. return left === right || (this.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right));
  7830. },
  7831. tokenize: function(value) {
  7832. return value.split('');
  7833. }
  7834. };
  7835. var CharDiff = new Diff();
  7836. var WordDiff = new Diff(true);
  7837. var WordWithSpaceDiff = new Diff();
  7838. WordDiff.tokenize = WordWithSpaceDiff.tokenize = function(value) {
  7839. return removeEmpty(value.split(/(\s+|\b)/));
  7840. };
  7841. var CssDiff = new Diff(true);
  7842. CssDiff.tokenize = function(value) {
  7843. return removeEmpty(value.split(/([{}:;,]|\s+)/));
  7844. };
  7845. var LineDiff = new Diff();
  7846. var TrimmedLineDiff = new Diff();
  7847. TrimmedLineDiff.ignoreTrim = true;
  7848. LineDiff.tokenize = TrimmedLineDiff.tokenize = function(value) {
  7849. var retLines = [],
  7850. lines = value.split(/^/m);
  7851. for (var i = 0; i < lines.length; i++) {
  7852. var line = lines[i],
  7853. lastLine = lines[i - 1],
  7854. lastLineLastChar = lastLine && lastLine[lastLine.length - 1];
  7855. // Merge lines that may contain windows new lines
  7856. if (line === '\n' && lastLineLastChar === '\r') {
  7857. retLines[retLines.length - 1] = retLines[retLines.length - 1].slice(0, -1) + '\r\n';
  7858. } else {
  7859. if (this.ignoreTrim) {
  7860. line = line.trim();
  7861. // add a newline unless this is the last line.
  7862. if (i < lines.length - 1) {
  7863. line += '\n';
  7864. }
  7865. }
  7866. retLines.push(line);
  7867. }
  7868. }
  7869. return retLines;
  7870. };
  7871. var PatchDiff = new Diff();
  7872. PatchDiff.tokenize = function(value) {
  7873. var ret = [],
  7874. linesAndNewlines = value.split(/(\n|\r\n)/);
  7875. // Ignore the final empty token that occurs if the string ends with a new line
  7876. if (!linesAndNewlines[linesAndNewlines.length - 1]) {
  7877. linesAndNewlines.pop();
  7878. }
  7879. // Merge the content and line separators into single tokens
  7880. for (var i = 0; i < linesAndNewlines.length; i++) {
  7881. var line = linesAndNewlines[i];
  7882. if (i % 2) {
  7883. ret[ret.length - 1] += line;
  7884. } else {
  7885. ret.push(line);
  7886. }
  7887. }
  7888. return ret;
  7889. };
  7890. var SentenceDiff = new Diff();
  7891. SentenceDiff.tokenize = function(value) {
  7892. return removeEmpty(value.split(/(\S.+?[.!?])(?=\s+|$)/));
  7893. };
  7894. var JsonDiff = new Diff();
  7895. // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
  7896. // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
  7897. JsonDiff.useLongestToken = true;
  7898. JsonDiff.tokenize = LineDiff.tokenize;
  7899. JsonDiff.equals = function(left, right) {
  7900. return LineDiff.equals(left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'));
  7901. };
  7902. var JsDiff = {
  7903. Diff: Diff,
  7904. diffChars: function(oldStr, newStr, callback) { return CharDiff.diff(oldStr, newStr, callback); },
  7905. diffWords: function(oldStr, newStr, callback) { return WordDiff.diff(oldStr, newStr, callback); },
  7906. diffWordsWithSpace: function(oldStr, newStr, callback) { return WordWithSpaceDiff.diff(oldStr, newStr, callback); },
  7907. diffLines: function(oldStr, newStr, callback) { return LineDiff.diff(oldStr, newStr, callback); },
  7908. diffTrimmedLines: function(oldStr, newStr, callback) { return TrimmedLineDiff.diff(oldStr, newStr, callback); },
  7909. diffSentences: function(oldStr, newStr, callback) { return SentenceDiff.diff(oldStr, newStr, callback); },
  7910. diffCss: function(oldStr, newStr, callback) { return CssDiff.diff(oldStr, newStr, callback); },
  7911. diffJson: function(oldObj, newObj, callback) {
  7912. return JsonDiff.diff(
  7913. typeof oldObj === 'string' ? oldObj : JSON.stringify(canonicalize(oldObj), undefined, ' '),
  7914. typeof newObj === 'string' ? newObj : JSON.stringify(canonicalize(newObj), undefined, ' '),
  7915. callback
  7916. );
  7917. },
  7918. createTwoFilesPatch: function(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader) {
  7919. var ret = [];
  7920. if (oldFileName == newFileName) {
  7921. ret.push('Index: ' + oldFileName);
  7922. }
  7923. ret.push('===================================================================');
  7924. ret.push('--- ' + oldFileName + (typeof oldHeader === 'undefined' ? '' : '\t' + oldHeader));
  7925. ret.push('+++ ' + newFileName + (typeof newHeader === 'undefined' ? '' : '\t' + newHeader));
  7926. var diff = PatchDiff.diff(oldStr, newStr);
  7927. diff.push({value: '', lines: []}); // Append an empty value to make cleanup easier
  7928. // Formats a given set of lines for printing as context lines in a patch
  7929. function contextLines(lines) {
  7930. return map(lines, function(entry) { return ' ' + entry; });
  7931. }
  7932. // Outputs the no newline at end of file warning if needed
  7933. function eofNL(curRange, i, current) {
  7934. var last = diff[diff.length - 2],
  7935. isLast = i === diff.length - 2,
  7936. isLastOfType = i === diff.length - 3 && current.added !== last.added;
  7937. // Figure out if this is the last line for the given file and missing NL
  7938. if (!(/\n$/.test(current.value)) && (isLast || isLastOfType)) {
  7939. curRange.push('\\ No newline at end of file');
  7940. }
  7941. }
  7942. var oldRangeStart = 0, newRangeStart = 0, curRange = [],
  7943. oldLine = 1, newLine = 1;
  7944. for (var i = 0; i < diff.length; i++) {
  7945. var current = diff[i],
  7946. lines = current.lines || current.value.replace(/\n$/, '').split('\n');
  7947. current.lines = lines;
  7948. if (current.added || current.removed) {
  7949. // If we have previous context, start with that
  7950. if (!oldRangeStart) {
  7951. var prev = diff[i - 1];
  7952. oldRangeStart = oldLine;
  7953. newRangeStart = newLine;
  7954. if (prev) {
  7955. curRange = contextLines(prev.lines.slice(-4));
  7956. oldRangeStart -= curRange.length;
  7957. newRangeStart -= curRange.length;
  7958. }
  7959. }
  7960. // Output our changes
  7961. curRange.push.apply(curRange, map(lines, function(entry) {
  7962. return (current.added ? '+' : '-') + entry;
  7963. }));
  7964. eofNL(curRange, i, current);
  7965. // Track the updated file position
  7966. if (current.added) {
  7967. newLine += lines.length;
  7968. } else {
  7969. oldLine += lines.length;
  7970. }
  7971. } else {
  7972. // Identical context lines. Track line changes
  7973. if (oldRangeStart) {
  7974. // Close out any changes that have been output (or join overlapping)
  7975. if (lines.length <= 8 && i < diff.length - 2) {
  7976. // Overlapping
  7977. curRange.push.apply(curRange, contextLines(lines));
  7978. } else {
  7979. // end the range and output
  7980. var contextSize = Math.min(lines.length, 4);
  7981. ret.push(
  7982. '@@ -' + oldRangeStart + ',' + (oldLine - oldRangeStart + contextSize)
  7983. + ' +' + newRangeStart + ',' + (newLine - newRangeStart + contextSize)
  7984. + ' @@');
  7985. ret.push.apply(ret, curRange);
  7986. ret.push.apply(ret, contextLines(lines.slice(0, contextSize)));
  7987. if (lines.length <= 4) {
  7988. eofNL(ret, i, current);
  7989. }
  7990. oldRangeStart = 0;
  7991. newRangeStart = 0;
  7992. curRange = [];
  7993. }
  7994. }
  7995. oldLine += lines.length;
  7996. newLine += lines.length;
  7997. }
  7998. }
  7999. return ret.join('\n') + '\n';
  8000. },
  8001. createPatch: function(fileName, oldStr, newStr, oldHeader, newHeader) {
  8002. return JsDiff.createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader);
  8003. },
  8004. applyPatch: function(oldStr, uniDiff) {
  8005. var diffstr = uniDiff.split('\n'),
  8006. hunks = [],
  8007. i = 0,
  8008. remEOFNL = false,
  8009. addEOFNL = false;
  8010. // Skip to the first change hunk
  8011. while (i < diffstr.length && !(/^@@/.test(diffstr[i]))) {
  8012. i++;
  8013. }
  8014. // Parse the unified diff
  8015. for (; i < diffstr.length; i++) {
  8016. if (diffstr[i][0] === '@') {
  8017. var chnukHeader = diffstr[i].split(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/);
  8018. hunks.unshift({
  8019. start: chnukHeader[3],
  8020. oldlength: +chnukHeader[2],
  8021. removed: [],
  8022. newlength: chnukHeader[4],
  8023. added: []
  8024. });
  8025. } else if (diffstr[i][0] === '+') {
  8026. hunks[0].added.push(diffstr[i].substr(1));
  8027. } else if (diffstr[i][0] === '-') {
  8028. hunks[0].removed.push(diffstr[i].substr(1));
  8029. } else if (diffstr[i][0] === ' ') {
  8030. hunks[0].added.push(diffstr[i].substr(1));
  8031. hunks[0].removed.push(diffstr[i].substr(1));
  8032. } else if (diffstr[i][0] === '\\') {
  8033. if (diffstr[i - 1][0] === '+') {
  8034. remEOFNL = true;
  8035. } else if (diffstr[i - 1][0] === '-') {
  8036. addEOFNL = true;
  8037. }
  8038. }
  8039. }
  8040. // Apply the diff to the input
  8041. var lines = oldStr.split('\n');
  8042. for (i = hunks.length - 1; i >= 0; i--) {
  8043. var hunk = hunks[i];
  8044. // Sanity check the input string. Bail if we don't match.
  8045. for (var j = 0; j < hunk.oldlength; j++) {
  8046. if (lines[hunk.start - 1 + j] !== hunk.removed[j]) {
  8047. return false;
  8048. }
  8049. }
  8050. Array.prototype.splice.apply(lines, [hunk.start - 1, hunk.oldlength].concat(hunk.added));
  8051. }
  8052. // Handle EOFNL insertion/removal
  8053. if (remEOFNL) {
  8054. while (!lines[lines.length - 1]) {
  8055. lines.pop();
  8056. }
  8057. } else if (addEOFNL) {
  8058. lines.push('');
  8059. }
  8060. return lines.join('\n');
  8061. },
  8062. convertChangesToXML: function(changes) {
  8063. var ret = [];
  8064. for (var i = 0; i < changes.length; i++) {
  8065. var change = changes[i];
  8066. if (change.added) {
  8067. ret.push('<ins>');
  8068. } else if (change.removed) {
  8069. ret.push('<del>');
  8070. }
  8071. ret.push(escapeHTML(change.value));
  8072. if (change.added) {
  8073. ret.push('</ins>');
  8074. } else if (change.removed) {
  8075. ret.push('</del>');
  8076. }
  8077. }
  8078. return ret.join('');
  8079. },
  8080. // See: http://code.google.com/p/google-diff-match-patch/wiki/API
  8081. convertChangesToDMP: function(changes) {
  8082. var ret = [],
  8083. change,
  8084. operation;
  8085. for (var i = 0; i < changes.length; i++) {
  8086. change = changes[i];
  8087. if (change.added) {
  8088. operation = 1;
  8089. } else if (change.removed) {
  8090. operation = -1;
  8091. } else {
  8092. operation = 0;
  8093. }
  8094. ret.push([operation, change.value]);
  8095. }
  8096. return ret;
  8097. },
  8098. canonicalize: canonicalize
  8099. };
  8100. /*istanbul ignore next */
  8101. /*global module */
  8102. if (typeof module !== 'undefined' && module.exports) {
  8103. module.exports = JsDiff;
  8104. } else if (false) {
  8105. /*global define */
  8106. define([], function() { return JsDiff; });
  8107. } else if (typeof global.JsDiff === 'undefined') {
  8108. global.JsDiff = JsDiff;
  8109. }
  8110. }(this));
  8111. },{}],47:[function(require,module,exports){
  8112. 'use strict';
  8113. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  8114. module.exports = function (str) {
  8115. if (typeof str !== 'string') {
  8116. throw new TypeError('Expected a string');
  8117. }
  8118. return str.replace(matchOperatorsRe, '\\$&');
  8119. };
  8120. },{}],48:[function(require,module,exports){
  8121. // Copyright Joyent, Inc. and other Node contributors.
  8122. //
  8123. // Permission is hereby granted, free of charge, to any person obtaining a
  8124. // copy of this software and associated documentation files (the
  8125. // "Software"), to deal in the Software without restriction, including
  8126. // without limitation the rights to use, copy, modify, merge, publish,
  8127. // distribute, sublicense, and/or sell copies of the Software, and to permit
  8128. // persons to whom the Software is furnished to do so, subject to the
  8129. // following conditions:
  8130. //
  8131. // The above copyright notice and this permission notice shall be included
  8132. // in all copies or substantial portions of the Software.
  8133. //
  8134. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  8135. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  8136. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  8137. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  8138. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  8139. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  8140. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  8141. function EventEmitter() {
  8142. this._events = this._events || {};
  8143. this._maxListeners = this._maxListeners || undefined;
  8144. }
  8145. module.exports = EventEmitter;
  8146. // Backwards-compat with node 0.10.x
  8147. EventEmitter.EventEmitter = EventEmitter;
  8148. EventEmitter.prototype._events = undefined;
  8149. EventEmitter.prototype._maxListeners = undefined;
  8150. // By default EventEmitters will print a warning if more than 10 listeners are
  8151. // added to it. This is a useful default which helps finding memory leaks.
  8152. EventEmitter.defaultMaxListeners = 10;
  8153. // Obviously not all Emitters should be limited to 10. This function allows
  8154. // that to be increased. Set to zero for unlimited.
  8155. EventEmitter.prototype.setMaxListeners = function(n) {
  8156. if (!isNumber(n) || n < 0 || isNaN(n))
  8157. throw TypeError('n must be a positive number');
  8158. this._maxListeners = n;
  8159. return this;
  8160. };
  8161. EventEmitter.prototype.emit = function(type) {
  8162. var er, handler, len, args, i, listeners;
  8163. if (!this._events)
  8164. this._events = {};
  8165. // If there is no 'error' event listener then throw.
  8166. if (type === 'error') {
  8167. if (!this._events.error ||
  8168. (isObject(this._events.error) && !this._events.error.length)) {
  8169. er = arguments[1];
  8170. if (er instanceof Error) {
  8171. throw er; // Unhandled 'error' event
  8172. } else {
  8173. // At least give some kind of context to the user
  8174. var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
  8175. err.context = er;
  8176. throw err;
  8177. }
  8178. }
  8179. }
  8180. handler = this._events[type];
  8181. if (isUndefined(handler))
  8182. return false;
  8183. if (isFunction(handler)) {
  8184. switch (arguments.length) {
  8185. // fast cases
  8186. case 1:
  8187. handler.call(this);
  8188. break;
  8189. case 2:
  8190. handler.call(this, arguments[1]);
  8191. break;
  8192. case 3:
  8193. handler.call(this, arguments[1], arguments[2]);
  8194. break;
  8195. // slower
  8196. default:
  8197. args = Array.prototype.slice.call(arguments, 1);
  8198. handler.apply(this, args);
  8199. }
  8200. } else if (isObject(handler)) {
  8201. args = Array.prototype.slice.call(arguments, 1);
  8202. listeners = handler.slice();
  8203. len = listeners.length;
  8204. for (i = 0; i < len; i++)
  8205. listeners[i].apply(this, args);
  8206. }
  8207. return true;
  8208. };
  8209. EventEmitter.prototype.addListener = function(type, listener) {
  8210. var m;
  8211. if (!isFunction(listener))
  8212. throw TypeError('listener must be a function');
  8213. if (!this._events)
  8214. this._events = {};
  8215. // To avoid recursion in the case that type === "newListener"! Before
  8216. // adding it to the listeners, first emit "newListener".
  8217. if (this._events.newListener)
  8218. this.emit('newListener', type,
  8219. isFunction(listener.listener) ?
  8220. listener.listener : listener);
  8221. if (!this._events[type])
  8222. // Optimize the case of one listener. Don't need the extra array object.
  8223. this._events[type] = listener;
  8224. else if (isObject(this._events[type]))
  8225. // If we've already got an array, just append.
  8226. this._events[type].push(listener);
  8227. else
  8228. // Adding the second element, need to change to array.
  8229. this._events[type] = [this._events[type], listener];
  8230. // Check for listener leak
  8231. if (isObject(this._events[type]) && !this._events[type].warned) {
  8232. if (!isUndefined(this._maxListeners)) {
  8233. m = this._maxListeners;
  8234. } else {
  8235. m = EventEmitter.defaultMaxListeners;
  8236. }
  8237. if (m && m > 0 && this._events[type].length > m) {
  8238. this._events[type].warned = true;
  8239. console.error('(node) warning: possible EventEmitter memory ' +
  8240. 'leak detected. %d listeners added. ' +
  8241. 'Use emitter.setMaxListeners() to increase limit.',
  8242. this._events[type].length);
  8243. if (typeof console.trace === 'function') {
  8244. // not supported in IE 10
  8245. console.trace();
  8246. }
  8247. }
  8248. }
  8249. return this;
  8250. };
  8251. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  8252. EventEmitter.prototype.once = function(type, listener) {
  8253. if (!isFunction(listener))
  8254. throw TypeError('listener must be a function');
  8255. var fired = false;
  8256. function g() {
  8257. this.removeListener(type, g);
  8258. if (!fired) {
  8259. fired = true;
  8260. listener.apply(this, arguments);
  8261. }
  8262. }
  8263. g.listener = listener;
  8264. this.on(type, g);
  8265. return this;
  8266. };
  8267. // emits a 'removeListener' event iff the listener was removed
  8268. EventEmitter.prototype.removeListener = function(type, listener) {
  8269. var list, position, length, i;
  8270. if (!isFunction(listener))
  8271. throw TypeError('listener must be a function');
  8272. if (!this._events || !this._events[type])
  8273. return this;
  8274. list = this._events[type];
  8275. length = list.length;
  8276. position = -1;
  8277. if (list === listener ||
  8278. (isFunction(list.listener) && list.listener === listener)) {
  8279. delete this._events[type];
  8280. if (this._events.removeListener)
  8281. this.emit('removeListener', type, listener);
  8282. } else if (isObject(list)) {
  8283. for (i = length; i-- > 0;) {
  8284. if (list[i] === listener ||
  8285. (list[i].listener && list[i].listener === listener)) {
  8286. position = i;
  8287. break;
  8288. }
  8289. }
  8290. if (position < 0)
  8291. return this;
  8292. if (list.length === 1) {
  8293. list.length = 0;
  8294. delete this._events[type];
  8295. } else {
  8296. list.splice(position, 1);
  8297. }
  8298. if (this._events.removeListener)
  8299. this.emit('removeListener', type, listener);
  8300. }
  8301. return this;
  8302. };
  8303. EventEmitter.prototype.removeAllListeners = function(type) {
  8304. var key, listeners;
  8305. if (!this._events)
  8306. return this;
  8307. // not listening for removeListener, no need to emit
  8308. if (!this._events.removeListener) {
  8309. if (arguments.length === 0)
  8310. this._events = {};
  8311. else if (this._events[type])
  8312. delete this._events[type];
  8313. return this;
  8314. }
  8315. // emit removeListener for all listeners on all events
  8316. if (arguments.length === 0) {
  8317. for (key in this._events) {
  8318. if (key === 'removeListener') continue;
  8319. this.removeAllListeners(key);
  8320. }
  8321. this.removeAllListeners('removeListener');
  8322. this._events = {};
  8323. return this;
  8324. }
  8325. listeners = this._events[type];
  8326. if (isFunction(listeners)) {
  8327. this.removeListener(type, listeners);
  8328. } else if (listeners) {
  8329. // LIFO order
  8330. while (listeners.length)
  8331. this.removeListener(type, listeners[listeners.length - 1]);
  8332. }
  8333. delete this._events[type];
  8334. return this;
  8335. };
  8336. EventEmitter.prototype.listeners = function(type) {
  8337. var ret;
  8338. if (!this._events || !this._events[type])
  8339. ret = [];
  8340. else if (isFunction(this._events[type]))
  8341. ret = [this._events[type]];
  8342. else
  8343. ret = this._events[type].slice();
  8344. return ret;
  8345. };
  8346. EventEmitter.prototype.listenerCount = function(type) {
  8347. if (this._events) {
  8348. var evlistener = this._events[type];
  8349. if (isFunction(evlistener))
  8350. return 1;
  8351. else if (evlistener)
  8352. return evlistener.length;
  8353. }
  8354. return 0;
  8355. };
  8356. EventEmitter.listenerCount = function(emitter, type) {
  8357. return emitter.listenerCount(type);
  8358. };
  8359. function isFunction(arg) {
  8360. return typeof arg === 'function';
  8361. }
  8362. function isNumber(arg) {
  8363. return typeof arg === 'number';
  8364. }
  8365. function isObject(arg) {
  8366. return typeof arg === 'object' && arg !== null;
  8367. }
  8368. function isUndefined(arg) {
  8369. return arg === void 0;
  8370. }
  8371. },{}],49:[function(require,module,exports){
  8372. (function (process){
  8373. // Growl - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
  8374. /**
  8375. * Module dependencies.
  8376. */
  8377. var exec = require('child_process').exec
  8378. , fs = require('fs')
  8379. , path = require('path')
  8380. , exists = fs.existsSync || path.existsSync
  8381. , os = require('os')
  8382. , quote = JSON.stringify
  8383. , cmd;
  8384. function which(name) {
  8385. var paths = process.env.PATH.split(':');
  8386. var loc;
  8387. for (var i = 0, len = paths.length; i < len; ++i) {
  8388. loc = path.join(paths[i], name);
  8389. if (exists(loc)) return loc;
  8390. }
  8391. }
  8392. switch(os.type()) {
  8393. case 'Darwin':
  8394. if (which('terminal-notifier')) {
  8395. cmd = {
  8396. type: "Darwin-NotificationCenter"
  8397. , pkg: "terminal-notifier"
  8398. , msg: '-message'
  8399. , title: '-title'
  8400. , subtitle: '-subtitle'
  8401. , icon: '-appIcon'
  8402. , sound: '-sound'
  8403. , url: '-open'
  8404. , priority: {
  8405. cmd: '-execute'
  8406. , range: []
  8407. }
  8408. };
  8409. } else {
  8410. cmd = {
  8411. type: "Darwin-Growl"
  8412. , pkg: "growlnotify"
  8413. , msg: '-m'
  8414. , sticky: '--sticky'
  8415. , priority: {
  8416. cmd: '--priority'
  8417. , range: [
  8418. -2
  8419. , -1
  8420. , 0
  8421. , 1
  8422. , 2
  8423. , "Very Low"
  8424. , "Moderate"
  8425. , "Normal"
  8426. , "High"
  8427. , "Emergency"
  8428. ]
  8429. }
  8430. };
  8431. }
  8432. break;
  8433. case 'Linux':
  8434. if (which('growl')) {
  8435. cmd = {
  8436. type: "Linux-Growl"
  8437. , pkg: "growl"
  8438. , msg: '-m'
  8439. , title: '-title'
  8440. , subtitle: '-subtitle'
  8441. , host: {
  8442. cmd: '-H'
  8443. , hostname: '192.168.33.1'
  8444. }
  8445. };
  8446. } else {
  8447. cmd = {
  8448. type: "Linux"
  8449. , pkg: "notify-send"
  8450. , msg: ''
  8451. , sticky: '-t 0'
  8452. , icon: '-i'
  8453. , priority: {
  8454. cmd: '-u'
  8455. , range: [
  8456. "low"
  8457. , "normal"
  8458. , "critical"
  8459. ]
  8460. }
  8461. };
  8462. }
  8463. break;
  8464. case 'Windows_NT':
  8465. cmd = {
  8466. type: "Windows"
  8467. , pkg: "growlnotify"
  8468. , msg: ''
  8469. , sticky: '/s:true'
  8470. , title: '/t:'
  8471. , icon: '/i:'
  8472. , url: '/cu:'
  8473. , priority: {
  8474. cmd: '/p:'
  8475. , range: [
  8476. -2
  8477. , -1
  8478. , 0
  8479. , 1
  8480. , 2
  8481. ]
  8482. }
  8483. };
  8484. break;
  8485. }
  8486. /**
  8487. * Expose `growl`.
  8488. */
  8489. exports = module.exports = growl;
  8490. /**
  8491. * Node-growl version.
  8492. */
  8493. exports.version = '1.4.1'
  8494. /**
  8495. * Send growl notification _msg_ with _options_.
  8496. *
  8497. * Options:
  8498. *
  8499. * - title Notification title
  8500. * - sticky Make the notification stick (defaults to false)
  8501. * - priority Specify an int or named key (default is 0)
  8502. * - name Application name (defaults to growlnotify)
  8503. * - sound Sound efect ( in OSx defined in preferences -> sound -> effects) * works only in OSX > 10.8x
  8504. * - image
  8505. * - path to an icon sets --iconpath
  8506. * - path to an image sets --image
  8507. * - capitalized word sets --appIcon
  8508. * - filename uses extname as --icon
  8509. * - otherwise treated as --icon
  8510. *
  8511. * Examples:
  8512. *
  8513. * growl('New email')
  8514. * growl('5 new emails', { title: 'Thunderbird' })
  8515. * growl('5 new emails', { title: 'Thunderbird', sound: 'Purr' })
  8516. * growl('Email sent', function(){
  8517. * // ... notification sent
  8518. * })
  8519. *
  8520. * @param {string} msg
  8521. * @param {object} options
  8522. * @param {function} fn
  8523. * @api public
  8524. */
  8525. function growl(msg, options, fn) {
  8526. var image
  8527. , args
  8528. , options = options || {}
  8529. , fn = fn || function(){};
  8530. if (options.exec) {
  8531. cmd = {
  8532. type: "Custom"
  8533. , pkg: options.exec
  8534. , range: []
  8535. };
  8536. }
  8537. // noop
  8538. if (!cmd) return fn(new Error('growl not supported on this platform'));
  8539. args = [cmd.pkg];
  8540. // image
  8541. if (image = options.image) {
  8542. switch(cmd.type) {
  8543. case 'Darwin-Growl':
  8544. var flag, ext = path.extname(image).substr(1)
  8545. flag = flag || ext == 'icns' && 'iconpath'
  8546. flag = flag || /^[A-Z]/.test(image) && 'appIcon'
  8547. flag = flag || /^png|gif|jpe?g$/.test(ext) && 'image'
  8548. flag = flag || ext && (image = ext) && 'icon'
  8549. flag = flag || 'icon'
  8550. args.push('--' + flag, quote(image))
  8551. break;
  8552. case 'Darwin-NotificationCenter':
  8553. args.push(cmd.icon, quote(image));
  8554. break;
  8555. case 'Linux':
  8556. args.push(cmd.icon, quote(image));
  8557. // libnotify defaults to sticky, set a hint for transient notifications
  8558. if (!options.sticky) args.push('--hint=int:transient:1');
  8559. break;
  8560. case 'Windows':
  8561. args.push(cmd.icon + quote(image));
  8562. break;
  8563. }
  8564. }
  8565. // sticky
  8566. if (options.sticky) args.push(cmd.sticky);
  8567. // priority
  8568. if (options.priority) {
  8569. var priority = options.priority + '';
  8570. var checkindexOf = cmd.priority.range.indexOf(priority);
  8571. if (~cmd.priority.range.indexOf(priority)) {
  8572. args.push(cmd.priority, options.priority);
  8573. }
  8574. }
  8575. //sound
  8576. if(options.sound && cmd.type === 'Darwin-NotificationCenter'){
  8577. args.push(cmd.sound, options.sound)
  8578. }
  8579. // name
  8580. if (options.name && cmd.type === "Darwin-Growl") {
  8581. args.push('--name', options.name);
  8582. }
  8583. switch(cmd.type) {
  8584. case 'Darwin-Growl':
  8585. args.push(cmd.msg);
  8586. args.push(quote(msg).replace(/\\n/g, '\n'));
  8587. if (options.title) args.push(quote(options.title));
  8588. break;
  8589. case 'Darwin-NotificationCenter':
  8590. args.push(cmd.msg);
  8591. var stringifiedMsg = quote(msg);
  8592. var escapedMsg = stringifiedMsg.replace(/\\n/g, '\n');
  8593. args.push(escapedMsg);
  8594. if (options.title) {
  8595. args.push(cmd.title);
  8596. args.push(quote(options.title));
  8597. }
  8598. if (options.subtitle) {
  8599. args.push(cmd.subtitle);
  8600. args.push(quote(options.subtitle));
  8601. }
  8602. if (options.url) {
  8603. args.push(cmd.url);
  8604. args.push(quote(options.url));
  8605. }
  8606. break;
  8607. case 'Linux-Growl':
  8608. args.push(cmd.msg);
  8609. args.push(quote(msg).replace(/\\n/g, '\n'));
  8610. if (options.title) args.push(quote(options.title));
  8611. if (cmd.host) {
  8612. args.push(cmd.host.cmd, cmd.host.hostname)
  8613. }
  8614. break;
  8615. case 'Linux':
  8616. if (options.title) {
  8617. args.push(quote(options.title));
  8618. args.push(cmd.msg);
  8619. args.push(quote(msg).replace(/\\n/g, '\n'));
  8620. } else {
  8621. args.push(quote(msg).replace(/\\n/g, '\n'));
  8622. }
  8623. break;
  8624. case 'Windows':
  8625. args.push(quote(msg).replace(/\\n/g, '\n'));
  8626. if (options.title) args.push(cmd.title + quote(options.title));
  8627. if (options.url) args.push(cmd.url + quote(options.url));
  8628. break;
  8629. case 'Custom':
  8630. args[0] = (function(origCommand) {
  8631. var message = options.title
  8632. ? options.title + ': ' + msg
  8633. : msg;
  8634. var command = origCommand.replace(/(^|[^%])%s/g, '$1' + quote(message));
  8635. if (command === origCommand) args.push(quote(message));
  8636. return command;
  8637. })(args[0]);
  8638. break;
  8639. }
  8640. // execute
  8641. exec(args.join(' '), fn);
  8642. };
  8643. }).call(this,require('_process'))
  8644. },{"_process":67,"child_process":42,"fs":42,"os":65,"path":42}],50:[function(require,module,exports){
  8645. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  8646. var e, m
  8647. var eLen = nBytes * 8 - mLen - 1
  8648. var eMax = (1 << eLen) - 1
  8649. var eBias = eMax >> 1
  8650. var nBits = -7
  8651. var i = isLE ? (nBytes - 1) : 0
  8652. var d = isLE ? -1 : 1
  8653. var s = buffer[offset + i]
  8654. i += d
  8655. e = s & ((1 << (-nBits)) - 1)
  8656. s >>= (-nBits)
  8657. nBits += eLen
  8658. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  8659. m = e & ((1 << (-nBits)) - 1)
  8660. e >>= (-nBits)
  8661. nBits += mLen
  8662. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  8663. if (e === 0) {
  8664. e = 1 - eBias
  8665. } else if (e === eMax) {
  8666. return m ? NaN : ((s ? -1 : 1) * Infinity)
  8667. } else {
  8668. m = m + Math.pow(2, mLen)
  8669. e = e - eBias
  8670. }
  8671. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  8672. }
  8673. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  8674. var e, m, c
  8675. var eLen = nBytes * 8 - mLen - 1
  8676. var eMax = (1 << eLen) - 1
  8677. var eBias = eMax >> 1
  8678. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  8679. var i = isLE ? 0 : (nBytes - 1)
  8680. var d = isLE ? 1 : -1
  8681. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  8682. value = Math.abs(value)
  8683. if (isNaN(value) || value === Infinity) {
  8684. m = isNaN(value) ? 1 : 0
  8685. e = eMax
  8686. } else {
  8687. e = Math.floor(Math.log(value) / Math.LN2)
  8688. if (value * (c = Math.pow(2, -e)) < 1) {
  8689. e--
  8690. c *= 2
  8691. }
  8692. if (e + eBias >= 1) {
  8693. value += rt / c
  8694. } else {
  8695. value += rt * Math.pow(2, 1 - eBias)
  8696. }
  8697. if (value * c >= 2) {
  8698. e++
  8699. c /= 2
  8700. }
  8701. if (e + eBias >= eMax) {
  8702. m = 0
  8703. e = eMax
  8704. } else if (e + eBias >= 1) {
  8705. m = (value * c - 1) * Math.pow(2, mLen)
  8706. e = e + eBias
  8707. } else {
  8708. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  8709. e = 0
  8710. }
  8711. }
  8712. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  8713. e = (e << mLen) | m
  8714. eLen += mLen
  8715. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  8716. buffer[offset + i - d] |= s * 128
  8717. }
  8718. },{}],51:[function(require,module,exports){
  8719. if (typeof Object.create === 'function') {
  8720. // implementation from standard node.js 'util' module
  8721. module.exports = function inherits(ctor, superCtor) {
  8722. ctor.super_ = superCtor
  8723. ctor.prototype = Object.create(superCtor.prototype, {
  8724. constructor: {
  8725. value: ctor,
  8726. enumerable: false,
  8727. writable: true,
  8728. configurable: true
  8729. }
  8730. });
  8731. };
  8732. } else {
  8733. // old school shim for old browsers
  8734. module.exports = function inherits(ctor, superCtor) {
  8735. ctor.super_ = superCtor
  8736. var TempCtor = function () {}
  8737. TempCtor.prototype = superCtor.prototype
  8738. ctor.prototype = new TempCtor()
  8739. ctor.prototype.constructor = ctor
  8740. }
  8741. }
  8742. },{}],52:[function(require,module,exports){
  8743. /**
  8744. * Determine if an object is Buffer
  8745. *
  8746. * Author: Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  8747. * License: MIT
  8748. *
  8749. * `npm install is-buffer`
  8750. */
  8751. module.exports = function (obj) {
  8752. return !!(obj != null &&
  8753. (obj._isBuffer || // For Safari 5-7 (missing Object.prototype.constructor)
  8754. (obj.constructor &&
  8755. typeof obj.constructor.isBuffer === 'function' &&
  8756. obj.constructor.isBuffer(obj))
  8757. ))
  8758. }
  8759. },{}],53:[function(require,module,exports){
  8760. var toString = {}.toString;
  8761. module.exports = Array.isArray || function (arr) {
  8762. return toString.call(arr) == '[object Array]';
  8763. };
  8764. },{}],54:[function(require,module,exports){
  8765. (function (global){
  8766. /*! JSON v3.3.2 | http://bestiejs.github.io/json3 | Copyright 2012-2014, Kit Cambridge | http://kit.mit-license.org */
  8767. ;(function () {
  8768. // Detect the `define` function exposed by asynchronous module loaders. The
  8769. // strict `define` check is necessary for compatibility with `r.js`.
  8770. var isLoader = false;
  8771. // A set of types used to distinguish objects from primitives.
  8772. var objectTypes = {
  8773. "function": true,
  8774. "object": true
  8775. };
  8776. // Detect the `exports` object exposed by CommonJS implementations.
  8777. var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
  8778. // Use the `global` object exposed by Node (including Browserify via
  8779. // `insert-module-globals`), Narwhal, and Ringo as the default context,
  8780. // and the `window` object in browsers. Rhino exports a `global` function
  8781. // instead.
  8782. var root = objectTypes[typeof window] && window || this,
  8783. freeGlobal = freeExports && objectTypes[typeof module] && module && !module.nodeType && typeof global == "object" && global;
  8784. if (freeGlobal && (freeGlobal["global"] === freeGlobal || freeGlobal["window"] === freeGlobal || freeGlobal["self"] === freeGlobal)) {
  8785. root = freeGlobal;
  8786. }
  8787. // Public: Initializes JSON 3 using the given `context` object, attaching the
  8788. // `stringify` and `parse` functions to the specified `exports` object.
  8789. function runInContext(context, exports) {
  8790. context || (context = root["Object"]());
  8791. exports || (exports = root["Object"]());
  8792. // Native constructor aliases.
  8793. var Number = context["Number"] || root["Number"],
  8794. String = context["String"] || root["String"],
  8795. Object = context["Object"] || root["Object"],
  8796. Date = context["Date"] || root["Date"],
  8797. SyntaxError = context["SyntaxError"] || root["SyntaxError"],
  8798. TypeError = context["TypeError"] || root["TypeError"],
  8799. Math = context["Math"] || root["Math"],
  8800. nativeJSON = context["JSON"] || root["JSON"];
  8801. // Delegate to the native `stringify` and `parse` implementations.
  8802. if (typeof nativeJSON == "object" && nativeJSON) {
  8803. exports.stringify = nativeJSON.stringify;
  8804. exports.parse = nativeJSON.parse;
  8805. }
  8806. // Convenience aliases.
  8807. var objectProto = Object.prototype,
  8808. getClass = objectProto.toString,
  8809. isProperty, forEach, undef;
  8810. // Test the `Date#getUTC*` methods. Based on work by @Yaffle.
  8811. var isExtended = new Date(-3509827334573292);
  8812. try {
  8813. // The `getUTCFullYear`, `Month`, and `Date` methods return nonsensical
  8814. // results for certain dates in Opera >= 10.53.
  8815. isExtended = isExtended.getUTCFullYear() == -109252 && isExtended.getUTCMonth() === 0 && isExtended.getUTCDate() === 1 &&
  8816. // Safari < 2.0.2 stores the internal millisecond time value correctly,
  8817. // but clips the values returned by the date methods to the range of
  8818. // signed 32-bit integers ([-2 ** 31, 2 ** 31 - 1]).
  8819. isExtended.getUTCHours() == 10 && isExtended.getUTCMinutes() == 37 && isExtended.getUTCSeconds() == 6 && isExtended.getUTCMilliseconds() == 708;
  8820. } catch (exception) {}
  8821. // Internal: Determines whether the native `JSON.stringify` and `parse`
  8822. // implementations are spec-compliant. Based on work by Ken Snyder.
  8823. function has(name) {
  8824. if (has[name] !== undef) {
  8825. // Return cached feature test result.
  8826. return has[name];
  8827. }
  8828. var isSupported;
  8829. if (name == "bug-string-char-index") {
  8830. // IE <= 7 doesn't support accessing string characters using square
  8831. // bracket notation. IE 8 only supports this for primitives.
  8832. isSupported = "a"[0] != "a";
  8833. } else if (name == "json") {
  8834. // Indicates whether both `JSON.stringify` and `JSON.parse` are
  8835. // supported.
  8836. isSupported = has("json-stringify") && has("json-parse");
  8837. } else {
  8838. var value, serialized = '{"a":[1,true,false,null,"\\u0000\\b\\n\\f\\r\\t"]}';
  8839. // Test `JSON.stringify`.
  8840. if (name == "json-stringify") {
  8841. var stringify = exports.stringify, stringifySupported = typeof stringify == "function" && isExtended;
  8842. if (stringifySupported) {
  8843. // A test function object with a custom `toJSON` method.
  8844. (value = function () {
  8845. return 1;
  8846. }).toJSON = value;
  8847. try {
  8848. stringifySupported =
  8849. // Firefox 3.1b1 and b2 serialize string, number, and boolean
  8850. // primitives as object literals.
  8851. stringify(0) === "0" &&
  8852. // FF 3.1b1, b2, and JSON 2 serialize wrapped primitives as object
  8853. // literals.
  8854. stringify(new Number()) === "0" &&
  8855. stringify(new String()) == '""' &&
  8856. // FF 3.1b1, 2 throw an error if the value is `null`, `undefined`, or
  8857. // does not define a canonical JSON representation (this applies to
  8858. // objects with `toJSON` properties as well, *unless* they are nested
  8859. // within an object or array).
  8860. stringify(getClass) === undef &&
  8861. // IE 8 serializes `undefined` as `"undefined"`. Safari <= 5.1.7 and
  8862. // FF 3.1b3 pass this test.
  8863. stringify(undef) === undef &&
  8864. // Safari <= 5.1.7 and FF 3.1b3 throw `Error`s and `TypeError`s,
  8865. // respectively, if the value is omitted entirely.
  8866. stringify() === undef &&
  8867. // FF 3.1b1, 2 throw an error if the given value is not a number,
  8868. // string, array, object, Boolean, or `null` literal. This applies to
  8869. // objects with custom `toJSON` methods as well, unless they are nested
  8870. // inside object or array literals. YUI 3.0.0b1 ignores custom `toJSON`
  8871. // methods entirely.
  8872. stringify(value) === "1" &&
  8873. stringify([value]) == "[1]" &&
  8874. // Prototype <= 1.6.1 serializes `[undefined]` as `"[]"` instead of
  8875. // `"[null]"`.
  8876. stringify([undef]) == "[null]" &&
  8877. // YUI 3.0.0b1 fails to serialize `null` literals.
  8878. stringify(null) == "null" &&
  8879. // FF 3.1b1, 2 halts serialization if an array contains a function:
  8880. // `[1, true, getClass, 1]` serializes as "[1,true,],". FF 3.1b3
  8881. // elides non-JSON values from objects and arrays, unless they
  8882. // define custom `toJSON` methods.
  8883. stringify([undef, getClass, null]) == "[null,null,null]" &&
  8884. // Simple serialization test. FF 3.1b1 uses Unicode escape sequences
  8885. // where character escape codes are expected (e.g., `\b` => `\u0008`).
  8886. stringify({ "a": [value, true, false, null, "\x00\b\n\f\r\t"] }) == serialized &&
  8887. // FF 3.1b1 and b2 ignore the `filter` and `width` arguments.
  8888. stringify(null, value) === "1" &&
  8889. stringify([1, 2], null, 1) == "[\n 1,\n 2\n]" &&
  8890. // JSON 2, Prototype <= 1.7, and older WebKit builds incorrectly
  8891. // serialize extended years.
  8892. stringify(new Date(-8.64e15)) == '"-271821-04-20T00:00:00.000Z"' &&
  8893. // The milliseconds are optional in ES 5, but required in 5.1.
  8894. stringify(new Date(8.64e15)) == '"+275760-09-13T00:00:00.000Z"' &&
  8895. // Firefox <= 11.0 incorrectly serializes years prior to 0 as negative
  8896. // four-digit years instead of six-digit years. Credits: @Yaffle.
  8897. stringify(new Date(-621987552e5)) == '"-000001-01-01T00:00:00.000Z"' &&
  8898. // Safari <= 5.1.5 and Opera >= 10.53 incorrectly serialize millisecond
  8899. // values less than 1000. Credits: @Yaffle.
  8900. stringify(new Date(-1)) == '"1969-12-31T23:59:59.999Z"';
  8901. } catch (exception) {
  8902. stringifySupported = false;
  8903. }
  8904. }
  8905. isSupported = stringifySupported;
  8906. }
  8907. // Test `JSON.parse`.
  8908. if (name == "json-parse") {
  8909. var parse = exports.parse;
  8910. if (typeof parse == "function") {
  8911. try {
  8912. // FF 3.1b1, b2 will throw an exception if a bare literal is provided.
  8913. // Conforming implementations should also coerce the initial argument to
  8914. // a string prior to parsing.
  8915. if (parse("0") === 0 && !parse(false)) {
  8916. // Simple parsing test.
  8917. value = parse(serialized);
  8918. var parseSupported = value["a"].length == 5 && value["a"][0] === 1;
  8919. if (parseSupported) {
  8920. try {
  8921. // Safari <= 5.1.2 and FF 3.1b1 allow unescaped tabs in strings.
  8922. parseSupported = !parse('"\t"');
  8923. } catch (exception) {}
  8924. if (parseSupported) {
  8925. try {
  8926. // FF 4.0 and 4.0.1 allow leading `+` signs and leading
  8927. // decimal points. FF 4.0, 4.0.1, and IE 9-10 also allow
  8928. // certain octal literals.
  8929. parseSupported = parse("01") !== 1;
  8930. } catch (exception) {}
  8931. }
  8932. if (parseSupported) {
  8933. try {
  8934. // FF 4.0, 4.0.1, and Rhino 1.7R3-R4 allow trailing decimal
  8935. // points. These environments, along with FF 3.1b1 and 2,
  8936. // also allow trailing commas in JSON objects and arrays.
  8937. parseSupported = parse("1.") !== 1;
  8938. } catch (exception) {}
  8939. }
  8940. }
  8941. }
  8942. } catch (exception) {
  8943. parseSupported = false;
  8944. }
  8945. }
  8946. isSupported = parseSupported;
  8947. }
  8948. }
  8949. return has[name] = !!isSupported;
  8950. }
  8951. if (!has("json")) {
  8952. // Common `[[Class]]` name aliases.
  8953. var functionClass = "[object Function]",
  8954. dateClass = "[object Date]",
  8955. numberClass = "[object Number]",
  8956. stringClass = "[object String]",
  8957. arrayClass = "[object Array]",
  8958. booleanClass = "[object Boolean]";
  8959. // Detect incomplete support for accessing string characters by index.
  8960. var charIndexBuggy = has("bug-string-char-index");
  8961. // Define additional utility methods if the `Date` methods are buggy.
  8962. if (!isExtended) {
  8963. var floor = Math.floor;
  8964. // A mapping between the months of the year and the number of days between
  8965. // January 1st and the first of the respective month.
  8966. var Months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
  8967. // Internal: Calculates the number of days between the Unix epoch and the
  8968. // first day of the given month.
  8969. var getDay = function (year, month) {
  8970. return Months[month] + 365 * (year - 1970) + floor((year - 1969 + (month = +(month > 1))) / 4) - floor((year - 1901 + month) / 100) + floor((year - 1601 + month) / 400);
  8971. };
  8972. }
  8973. // Internal: Determines if a property is a direct property of the given
  8974. // object. Delegates to the native `Object#hasOwnProperty` method.
  8975. if (!(isProperty = objectProto.hasOwnProperty)) {
  8976. isProperty = function (property) {
  8977. var members = {}, constructor;
  8978. if ((members.__proto__ = null, members.__proto__ = {
  8979. // The *proto* property cannot be set multiple times in recent
  8980. // versions of Firefox and SeaMonkey.
  8981. "toString": 1
  8982. }, members).toString != getClass) {
  8983. // Safari <= 2.0.3 doesn't implement `Object#hasOwnProperty`, but
  8984. // supports the mutable *proto* property.
  8985. isProperty = function (property) {
  8986. // Capture and break the object's prototype chain (see section 8.6.2
  8987. // of the ES 5.1 spec). The parenthesized expression prevents an
  8988. // unsafe transformation by the Closure Compiler.
  8989. var original = this.__proto__, result = property in (this.__proto__ = null, this);
  8990. // Restore the original prototype chain.
  8991. this.__proto__ = original;
  8992. return result;
  8993. };
  8994. } else {
  8995. // Capture a reference to the top-level `Object` constructor.
  8996. constructor = members.constructor;
  8997. // Use the `constructor` property to simulate `Object#hasOwnProperty` in
  8998. // other environments.
  8999. isProperty = function (property) {
  9000. var parent = (this.constructor || constructor).prototype;
  9001. return property in this && !(property in parent && this[property] === parent[property]);
  9002. };
  9003. }
  9004. members = null;
  9005. return isProperty.call(this, property);
  9006. };
  9007. }
  9008. // Internal: Normalizes the `for...in` iteration algorithm across
  9009. // environments. Each enumerated key is yielded to a `callback` function.
  9010. forEach = function (object, callback) {
  9011. var size = 0, Properties, members, property;
  9012. // Tests for bugs in the current environment's `for...in` algorithm. The
  9013. // `valueOf` property inherits the non-enumerable flag from
  9014. // `Object.prototype` in older versions of IE, Netscape, and Mozilla.
  9015. (Properties = function () {
  9016. this.valueOf = 0;
  9017. }).prototype.valueOf = 0;
  9018. // Iterate over a new instance of the `Properties` class.
  9019. members = new Properties();
  9020. for (property in members) {
  9021. // Ignore all properties inherited from `Object.prototype`.
  9022. if (isProperty.call(members, property)) {
  9023. size++;
  9024. }
  9025. }
  9026. Properties = members = null;
  9027. // Normalize the iteration algorithm.
  9028. if (!size) {
  9029. // A list of non-enumerable properties inherited from `Object.prototype`.
  9030. members = ["valueOf", "toString", "toLocaleString", "propertyIsEnumerable", "isPrototypeOf", "hasOwnProperty", "constructor"];
  9031. // IE <= 8, Mozilla 1.0, and Netscape 6.2 ignore shadowed non-enumerable
  9032. // properties.
  9033. forEach = function (object, callback) {
  9034. var isFunction = getClass.call(object) == functionClass, property, length;
  9035. var hasProperty = !isFunction && typeof object.constructor != "function" && objectTypes[typeof object.hasOwnProperty] && object.hasOwnProperty || isProperty;
  9036. for (property in object) {
  9037. // Gecko <= 1.0 enumerates the `prototype` property of functions under
  9038. // certain conditions; IE does not.
  9039. if (!(isFunction && property == "prototype") && hasProperty.call(object, property)) {
  9040. callback(property);
  9041. }
  9042. }
  9043. // Manually invoke the callback for each non-enumerable property.
  9044. for (length = members.length; property = members[--length]; hasProperty.call(object, property) && callback(property));
  9045. };
  9046. } else if (size == 2) {
  9047. // Safari <= 2.0.4 enumerates shadowed properties twice.
  9048. forEach = function (object, callback) {
  9049. // Create a set of iterated properties.
  9050. var members = {}, isFunction = getClass.call(object) == functionClass, property;
  9051. for (property in object) {
  9052. // Store each property name to prevent double enumeration. The
  9053. // `prototype` property of functions is not enumerated due to cross-
  9054. // environment inconsistencies.
  9055. if (!(isFunction && property == "prototype") && !isProperty.call(members, property) && (members[property] = 1) && isProperty.call(object, property)) {
  9056. callback(property);
  9057. }
  9058. }
  9059. };
  9060. } else {
  9061. // No bugs detected; use the standard `for...in` algorithm.
  9062. forEach = function (object, callback) {
  9063. var isFunction = getClass.call(object) == functionClass, property, isConstructor;
  9064. for (property in object) {
  9065. if (!(isFunction && property == "prototype") && isProperty.call(object, property) && !(isConstructor = property === "constructor")) {
  9066. callback(property);
  9067. }
  9068. }
  9069. // Manually invoke the callback for the `constructor` property due to
  9070. // cross-environment inconsistencies.
  9071. if (isConstructor || isProperty.call(object, (property = "constructor"))) {
  9072. callback(property);
  9073. }
  9074. };
  9075. }
  9076. return forEach(object, callback);
  9077. };
  9078. // Public: Serializes a JavaScript `value` as a JSON string. The optional
  9079. // `filter` argument may specify either a function that alters how object and
  9080. // array members are serialized, or an array of strings and numbers that
  9081. // indicates which properties should be serialized. The optional `width`
  9082. // argument may be either a string or number that specifies the indentation
  9083. // level of the output.
  9084. if (!has("json-stringify")) {
  9085. // Internal: A map of control characters and their escaped equivalents.
  9086. var Escapes = {
  9087. 92: "\\\\",
  9088. 34: '\\"',
  9089. 8: "\\b",
  9090. 12: "\\f",
  9091. 10: "\\n",
  9092. 13: "\\r",
  9093. 9: "\\t"
  9094. };
  9095. // Internal: Converts `value` into a zero-padded string such that its
  9096. // length is at least equal to `width`. The `width` must be <= 6.
  9097. var leadingZeroes = "000000";
  9098. var toPaddedString = function (width, value) {
  9099. // The `|| 0` expression is necessary to work around a bug in
  9100. // Opera <= 7.54u2 where `0 == -0`, but `String(-0) !== "0"`.
  9101. return (leadingZeroes + (value || 0)).slice(-width);
  9102. };
  9103. // Internal: Double-quotes a string `value`, replacing all ASCII control
  9104. // characters (characters with code unit values between 0 and 31) with
  9105. // their escaped equivalents. This is an implementation of the
  9106. // `Quote(value)` operation defined in ES 5.1 section 15.12.3.
  9107. var unicodePrefix = "\\u00";
  9108. var quote = function (value) {
  9109. var result = '"', index = 0, length = value.length, useCharIndex = !charIndexBuggy || length > 10;
  9110. var symbols = useCharIndex && (charIndexBuggy ? value.split("") : value);
  9111. for (; index < length; index++) {
  9112. var charCode = value.charCodeAt(index);
  9113. // If the character is a control character, append its Unicode or
  9114. // shorthand escape sequence; otherwise, append the character as-is.
  9115. switch (charCode) {
  9116. case 8: case 9: case 10: case 12: case 13: case 34: case 92:
  9117. result += Escapes[charCode];
  9118. break;
  9119. default:
  9120. if (charCode < 32) {
  9121. result += unicodePrefix + toPaddedString(2, charCode.toString(16));
  9122. break;
  9123. }
  9124. result += useCharIndex ? symbols[index] : value.charAt(index);
  9125. }
  9126. }
  9127. return result + '"';
  9128. };
  9129. // Internal: Recursively serializes an object. Implements the
  9130. // `Str(key, holder)`, `JO(value)`, and `JA(value)` operations.
  9131. var serialize = function (property, object, callback, properties, whitespace, indentation, stack) {
  9132. var value, className, year, month, date, time, hours, minutes, seconds, milliseconds, results, element, index, length, prefix, result;
  9133. try {
  9134. // Necessary for host object support.
  9135. value = object[property];
  9136. } catch (exception) {}
  9137. if (typeof value == "object" && value) {
  9138. className = getClass.call(value);
  9139. if (className == dateClass && !isProperty.call(value, "toJSON")) {
  9140. if (value > -1 / 0 && value < 1 / 0) {
  9141. // Dates are serialized according to the `Date#toJSON` method
  9142. // specified in ES 5.1 section 15.9.5.44. See section 15.9.1.15
  9143. // for the ISO 8601 date time string format.
  9144. if (getDay) {
  9145. // Manually compute the year, month, date, hours, minutes,
  9146. // seconds, and milliseconds if the `getUTC*` methods are
  9147. // buggy. Adapted from @Yaffle's `date-shim` project.
  9148. date = floor(value / 864e5);
  9149. for (year = floor(date / 365.2425) + 1970 - 1; getDay(year + 1, 0) <= date; year++);
  9150. for (month = floor((date - getDay(year, 0)) / 30.42); getDay(year, month + 1) <= date; month++);
  9151. date = 1 + date - getDay(year, month);
  9152. // The `time` value specifies the time within the day (see ES
  9153. // 5.1 section 15.9.1.2). The formula `(A % B + B) % B` is used
  9154. // to compute `A modulo B`, as the `%` operator does not
  9155. // correspond to the `modulo` operation for negative numbers.
  9156. time = (value % 864e5 + 864e5) % 864e5;
  9157. // The hours, minutes, seconds, and milliseconds are obtained by
  9158. // decomposing the time within the day. See section 15.9.1.10.
  9159. hours = floor(time / 36e5) % 24;
  9160. minutes = floor(time / 6e4) % 60;
  9161. seconds = floor(time / 1e3) % 60;
  9162. milliseconds = time % 1e3;
  9163. } else {
  9164. year = value.getUTCFullYear();
  9165. month = value.getUTCMonth();
  9166. date = value.getUTCDate();
  9167. hours = value.getUTCHours();
  9168. minutes = value.getUTCMinutes();
  9169. seconds = value.getUTCSeconds();
  9170. milliseconds = value.getUTCMilliseconds();
  9171. }
  9172. // Serialize extended years correctly.
  9173. value = (year <= 0 || year >= 1e4 ? (year < 0 ? "-" : "+") + toPaddedString(6, year < 0 ? -year : year) : toPaddedString(4, year)) +
  9174. "-" + toPaddedString(2, month + 1) + "-" + toPaddedString(2, date) +
  9175. // Months, dates, hours, minutes, and seconds should have two
  9176. // digits; milliseconds should have three.
  9177. "T" + toPaddedString(2, hours) + ":" + toPaddedString(2, minutes) + ":" + toPaddedString(2, seconds) +
  9178. // Milliseconds are optional in ES 5.0, but required in 5.1.
  9179. "." + toPaddedString(3, milliseconds) + "Z";
  9180. } else {
  9181. value = null;
  9182. }
  9183. } else if (typeof value.toJSON == "function" && ((className != numberClass && className != stringClass && className != arrayClass) || isProperty.call(value, "toJSON"))) {
  9184. // Prototype <= 1.6.1 adds non-standard `toJSON` methods to the
  9185. // `Number`, `String`, `Date`, and `Array` prototypes. JSON 3
  9186. // ignores all `toJSON` methods on these objects unless they are
  9187. // defined directly on an instance.
  9188. value = value.toJSON(property);
  9189. }
  9190. }
  9191. if (callback) {
  9192. // If a replacement function was provided, call it to obtain the value
  9193. // for serialization.
  9194. value = callback.call(object, property, value);
  9195. }
  9196. if (value === null) {
  9197. return "null";
  9198. }
  9199. className = getClass.call(value);
  9200. if (className == booleanClass) {
  9201. // Booleans are represented literally.
  9202. return "" + value;
  9203. } else if (className == numberClass) {
  9204. // JSON numbers must be finite. `Infinity` and `NaN` are serialized as
  9205. // `"null"`.
  9206. return value > -1 / 0 && value < 1 / 0 ? "" + value : "null";
  9207. } else if (className == stringClass) {
  9208. // Strings are double-quoted and escaped.
  9209. return quote("" + value);
  9210. }
  9211. // Recursively serialize objects and arrays.
  9212. if (typeof value == "object") {
  9213. // Check for cyclic structures. This is a linear search; performance
  9214. // is inversely proportional to the number of unique nested objects.
  9215. for (length = stack.length; length--;) {
  9216. if (stack[length] === value) {
  9217. // Cyclic structures cannot be serialized by `JSON.stringify`.
  9218. throw TypeError();
  9219. }
  9220. }
  9221. // Add the object to the stack of traversed objects.
  9222. stack.push(value);
  9223. results = [];
  9224. // Save the current indentation level and indent one additional level.
  9225. prefix = indentation;
  9226. indentation += whitespace;
  9227. if (className == arrayClass) {
  9228. // Recursively serialize array elements.
  9229. for (index = 0, length = value.length; index < length; index++) {
  9230. element = serialize(index, value, callback, properties, whitespace, indentation, stack);
  9231. results.push(element === undef ? "null" : element);
  9232. }
  9233. result = results.length ? (whitespace ? "[\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "]" : ("[" + results.join(",") + "]")) : "[]";
  9234. } else {
  9235. // Recursively serialize object members. Members are selected from
  9236. // either a user-specified list of property names, or the object
  9237. // itself.
  9238. forEach(properties || value, function (property) {
  9239. var element = serialize(property, value, callback, properties, whitespace, indentation, stack);
  9240. if (element !== undef) {
  9241. // According to ES 5.1 section 15.12.3: "If `gap` {whitespace}
  9242. // is not the empty string, let `member` {quote(property) + ":"}
  9243. // be the concatenation of `member` and the `space` character."
  9244. // The "`space` character" refers to the literal space
  9245. // character, not the `space` {width} argument provided to
  9246. // `JSON.stringify`.
  9247. results.push(quote(property) + ":" + (whitespace ? " " : "") + element);
  9248. }
  9249. });
  9250. result = results.length ? (whitespace ? "{\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "}" : ("{" + results.join(",") + "}")) : "{}";
  9251. }
  9252. // Remove the object from the traversed object stack.
  9253. stack.pop();
  9254. return result;
  9255. }
  9256. };
  9257. // Public: `JSON.stringify`. See ES 5.1 section 15.12.3.
  9258. exports.stringify = function (source, filter, width) {
  9259. var whitespace, callback, properties, className;
  9260. if (objectTypes[typeof filter] && filter) {
  9261. if ((className = getClass.call(filter)) == functionClass) {
  9262. callback = filter;
  9263. } else if (className == arrayClass) {
  9264. // Convert the property names array into a makeshift set.
  9265. properties = {};
  9266. for (var index = 0, length = filter.length, value; index < length; value = filter[index++], ((className = getClass.call(value)), className == stringClass || className == numberClass) && (properties[value] = 1));
  9267. }
  9268. }
  9269. if (width) {
  9270. if ((className = getClass.call(width)) == numberClass) {
  9271. // Convert the `width` to an integer and create a string containing
  9272. // `width` number of space characters.
  9273. if ((width -= width % 1) > 0) {
  9274. for (whitespace = "", width > 10 && (width = 10); whitespace.length < width; whitespace += " ");
  9275. }
  9276. } else if (className == stringClass) {
  9277. whitespace = width.length <= 10 ? width : width.slice(0, 10);
  9278. }
  9279. }
  9280. // Opera <= 7.54u2 discards the values associated with empty string keys
  9281. // (`""`) only if they are used directly within an object member list
  9282. // (e.g., `!("" in { "": 1})`).
  9283. return serialize("", (value = {}, value[""] = source, value), callback, properties, whitespace, "", []);
  9284. };
  9285. }
  9286. // Public: Parses a JSON source string.
  9287. if (!has("json-parse")) {
  9288. var fromCharCode = String.fromCharCode;
  9289. // Internal: A map of escaped control characters and their unescaped
  9290. // equivalents.
  9291. var Unescapes = {
  9292. 92: "\\",
  9293. 34: '"',
  9294. 47: "/",
  9295. 98: "\b",
  9296. 116: "\t",
  9297. 110: "\n",
  9298. 102: "\f",
  9299. 114: "\r"
  9300. };
  9301. // Internal: Stores the parser state.
  9302. var Index, Source;
  9303. // Internal: Resets the parser state and throws a `SyntaxError`.
  9304. var abort = function () {
  9305. Index = Source = null;
  9306. throw SyntaxError();
  9307. };
  9308. // Internal: Returns the next token, or `"$"` if the parser has reached
  9309. // the end of the source string. A token may be a string, number, `null`
  9310. // literal, or Boolean literal.
  9311. var lex = function () {
  9312. var source = Source, length = source.length, value, begin, position, isSigned, charCode;
  9313. while (Index < length) {
  9314. charCode = source.charCodeAt(Index);
  9315. switch (charCode) {
  9316. case 9: case 10: case 13: case 32:
  9317. // Skip whitespace tokens, including tabs, carriage returns, line
  9318. // feeds, and space characters.
  9319. Index++;
  9320. break;
  9321. case 123: case 125: case 91: case 93: case 58: case 44:
  9322. // Parse a punctuator token (`{`, `}`, `[`, `]`, `:`, or `,`) at
  9323. // the current position.
  9324. value = charIndexBuggy ? source.charAt(Index) : source[Index];
  9325. Index++;
  9326. return value;
  9327. case 34:
  9328. // `"` delimits a JSON string; advance to the next character and
  9329. // begin parsing the string. String tokens are prefixed with the
  9330. // sentinel `@` character to distinguish them from punctuators and
  9331. // end-of-string tokens.
  9332. for (value = "@", Index++; Index < length;) {
  9333. charCode = source.charCodeAt(Index);
  9334. if (charCode < 32) {
  9335. // Unescaped ASCII control characters (those with a code unit
  9336. // less than the space character) are not permitted.
  9337. abort();
  9338. } else if (charCode == 92) {
  9339. // A reverse solidus (`\`) marks the beginning of an escaped
  9340. // control character (including `"`, `\`, and `/`) or Unicode
  9341. // escape sequence.
  9342. charCode = source.charCodeAt(++Index);
  9343. switch (charCode) {
  9344. case 92: case 34: case 47: case 98: case 116: case 110: case 102: case 114:
  9345. // Revive escaped control characters.
  9346. value += Unescapes[charCode];
  9347. Index++;
  9348. break;
  9349. case 117:
  9350. // `\u` marks the beginning of a Unicode escape sequence.
  9351. // Advance to the first character and validate the
  9352. // four-digit code point.
  9353. begin = ++Index;
  9354. for (position = Index + 4; Index < position; Index++) {
  9355. charCode = source.charCodeAt(Index);
  9356. // A valid sequence comprises four hexdigits (case-
  9357. // insensitive) that form a single hexadecimal value.
  9358. if (!(charCode >= 48 && charCode <= 57 || charCode >= 97 && charCode <= 102 || charCode >= 65 && charCode <= 70)) {
  9359. // Invalid Unicode escape sequence.
  9360. abort();
  9361. }
  9362. }
  9363. // Revive the escaped character.
  9364. value += fromCharCode("0x" + source.slice(begin, Index));
  9365. break;
  9366. default:
  9367. // Invalid escape sequence.
  9368. abort();
  9369. }
  9370. } else {
  9371. if (charCode == 34) {
  9372. // An unescaped double-quote character marks the end of the
  9373. // string.
  9374. break;
  9375. }
  9376. charCode = source.charCodeAt(Index);
  9377. begin = Index;
  9378. // Optimize for the common case where a string is valid.
  9379. while (charCode >= 32 && charCode != 92 && charCode != 34) {
  9380. charCode = source.charCodeAt(++Index);
  9381. }
  9382. // Append the string as-is.
  9383. value += source.slice(begin, Index);
  9384. }
  9385. }
  9386. if (source.charCodeAt(Index) == 34) {
  9387. // Advance to the next character and return the revived string.
  9388. Index++;
  9389. return value;
  9390. }
  9391. // Unterminated string.
  9392. abort();
  9393. default:
  9394. // Parse numbers and literals.
  9395. begin = Index;
  9396. // Advance past the negative sign, if one is specified.
  9397. if (charCode == 45) {
  9398. isSigned = true;
  9399. charCode = source.charCodeAt(++Index);
  9400. }
  9401. // Parse an integer or floating-point value.
  9402. if (charCode >= 48 && charCode <= 57) {
  9403. // Leading zeroes are interpreted as octal literals.
  9404. if (charCode == 48 && ((charCode = source.charCodeAt(Index + 1)), charCode >= 48 && charCode <= 57)) {
  9405. // Illegal octal literal.
  9406. abort();
  9407. }
  9408. isSigned = false;
  9409. // Parse the integer component.
  9410. for (; Index < length && ((charCode = source.charCodeAt(Index)), charCode >= 48 && charCode <= 57); Index++);
  9411. // Floats cannot contain a leading decimal point; however, this
  9412. // case is already accounted for by the parser.
  9413. if (source.charCodeAt(Index) == 46) {
  9414. position = ++Index;
  9415. // Parse the decimal component.
  9416. for (; position < length && ((charCode = source.charCodeAt(position)), charCode >= 48 && charCode <= 57); position++);
  9417. if (position == Index) {
  9418. // Illegal trailing decimal.
  9419. abort();
  9420. }
  9421. Index = position;
  9422. }
  9423. // Parse exponents. The `e` denoting the exponent is
  9424. // case-insensitive.
  9425. charCode = source.charCodeAt(Index);
  9426. if (charCode == 101 || charCode == 69) {
  9427. charCode = source.charCodeAt(++Index);
  9428. // Skip past the sign following the exponent, if one is
  9429. // specified.
  9430. if (charCode == 43 || charCode == 45) {
  9431. Index++;
  9432. }
  9433. // Parse the exponential component.
  9434. for (position = Index; position < length && ((charCode = source.charCodeAt(position)), charCode >= 48 && charCode <= 57); position++);
  9435. if (position == Index) {
  9436. // Illegal empty exponent.
  9437. abort();
  9438. }
  9439. Index = position;
  9440. }
  9441. // Coerce the parsed value to a JavaScript number.
  9442. return +source.slice(begin, Index);
  9443. }
  9444. // A negative sign may only precede numbers.
  9445. if (isSigned) {
  9446. abort();
  9447. }
  9448. // `true`, `false`, and `null` literals.
  9449. if (source.slice(Index, Index + 4) == "true") {
  9450. Index += 4;
  9451. return true;
  9452. } else if (source.slice(Index, Index + 5) == "false") {
  9453. Index += 5;
  9454. return false;
  9455. } else if (source.slice(Index, Index + 4) == "null") {
  9456. Index += 4;
  9457. return null;
  9458. }
  9459. // Unrecognized token.
  9460. abort();
  9461. }
  9462. }
  9463. // Return the sentinel `$` character if the parser has reached the end
  9464. // of the source string.
  9465. return "$";
  9466. };
  9467. // Internal: Parses a JSON `value` token.
  9468. var get = function (value) {
  9469. var results, hasMembers;
  9470. if (value == "$") {
  9471. // Unexpected end of input.
  9472. abort();
  9473. }
  9474. if (typeof value == "string") {
  9475. if ((charIndexBuggy ? value.charAt(0) : value[0]) == "@") {
  9476. // Remove the sentinel `@` character.
  9477. return value.slice(1);
  9478. }
  9479. // Parse object and array literals.
  9480. if (value == "[") {
  9481. // Parses a JSON array, returning a new JavaScript array.
  9482. results = [];
  9483. for (;; hasMembers || (hasMembers = true)) {
  9484. value = lex();
  9485. // A closing square bracket marks the end of the array literal.
  9486. if (value == "]") {
  9487. break;
  9488. }
  9489. // If the array literal contains elements, the current token
  9490. // should be a comma separating the previous element from the
  9491. // next.
  9492. if (hasMembers) {
  9493. if (value == ",") {
  9494. value = lex();
  9495. if (value == "]") {
  9496. // Unexpected trailing `,` in array literal.
  9497. abort();
  9498. }
  9499. } else {
  9500. // A `,` must separate each array element.
  9501. abort();
  9502. }
  9503. }
  9504. // Elisions and leading commas are not permitted.
  9505. if (value == ",") {
  9506. abort();
  9507. }
  9508. results.push(get(value));
  9509. }
  9510. return results;
  9511. } else if (value == "{") {
  9512. // Parses a JSON object, returning a new JavaScript object.
  9513. results = {};
  9514. for (;; hasMembers || (hasMembers = true)) {
  9515. value = lex();
  9516. // A closing curly brace marks the end of the object literal.
  9517. if (value == "}") {
  9518. break;
  9519. }
  9520. // If the object literal contains members, the current token
  9521. // should be a comma separator.
  9522. if (hasMembers) {
  9523. if (value == ",") {
  9524. value = lex();
  9525. if (value == "}") {
  9526. // Unexpected trailing `,` in object literal.
  9527. abort();
  9528. }
  9529. } else {
  9530. // A `,` must separate each object member.
  9531. abort();
  9532. }
  9533. }
  9534. // Leading commas are not permitted, object property names must be
  9535. // double-quoted strings, and a `:` must separate each property
  9536. // name and value.
  9537. if (value == "," || typeof value != "string" || (charIndexBuggy ? value.charAt(0) : value[0]) != "@" || lex() != ":") {
  9538. abort();
  9539. }
  9540. results[value.slice(1)] = get(lex());
  9541. }
  9542. return results;
  9543. }
  9544. // Unexpected token encountered.
  9545. abort();
  9546. }
  9547. return value;
  9548. };
  9549. // Internal: Updates a traversed object member.
  9550. var update = function (source, property, callback) {
  9551. var element = walk(source, property, callback);
  9552. if (element === undef) {
  9553. delete source[property];
  9554. } else {
  9555. source[property] = element;
  9556. }
  9557. };
  9558. // Internal: Recursively traverses a parsed JSON object, invoking the
  9559. // `callback` function for each value. This is an implementation of the
  9560. // `Walk(holder, name)` operation defined in ES 5.1 section 15.12.2.
  9561. var walk = function (source, property, callback) {
  9562. var value = source[property], length;
  9563. if (typeof value == "object" && value) {
  9564. // `forEach` can't be used to traverse an array in Opera <= 8.54
  9565. // because its `Object#hasOwnProperty` implementation returns `false`
  9566. // for array indices (e.g., `![1, 2, 3].hasOwnProperty("0")`).
  9567. if (getClass.call(value) == arrayClass) {
  9568. for (length = value.length; length--;) {
  9569. update(value, length, callback);
  9570. }
  9571. } else {
  9572. forEach(value, function (property) {
  9573. update(value, property, callback);
  9574. });
  9575. }
  9576. }
  9577. return callback.call(source, property, value);
  9578. };
  9579. // Public: `JSON.parse`. See ES 5.1 section 15.12.2.
  9580. exports.parse = function (source, callback) {
  9581. var result, value;
  9582. Index = 0;
  9583. Source = "" + source;
  9584. result = get(lex());
  9585. // If a JSON string contains multiple tokens, it is invalid.
  9586. if (lex() != "$") {
  9587. abort();
  9588. }
  9589. // Reset the parser state.
  9590. Index = Source = null;
  9591. return callback && getClass.call(callback) == functionClass ? walk((value = {}, value[""] = result, value), "", callback) : result;
  9592. };
  9593. }
  9594. }
  9595. exports["runInContext"] = runInContext;
  9596. return exports;
  9597. }
  9598. if (freeExports && !isLoader) {
  9599. // Export for CommonJS environments.
  9600. runInContext(root, freeExports);
  9601. } else {
  9602. // Export for web browsers and JavaScript engines.
  9603. var nativeJSON = root.JSON,
  9604. previousJSON = root["JSON3"],
  9605. isRestored = false;
  9606. var JSON3 = runInContext(root, (root["JSON3"] = {
  9607. // Public: Restores the original value of the global `JSON` object and
  9608. // returns a reference to the `JSON3` object.
  9609. "noConflict": function () {
  9610. if (!isRestored) {
  9611. isRestored = true;
  9612. root.JSON = nativeJSON;
  9613. root["JSON3"] = previousJSON;
  9614. nativeJSON = previousJSON = null;
  9615. }
  9616. return JSON3;
  9617. }
  9618. }));
  9619. root.JSON = {
  9620. "parse": JSON3.parse,
  9621. "stringify": JSON3.stringify
  9622. };
  9623. }
  9624. // Export for asynchronous module loaders.
  9625. if (isLoader) {
  9626. define(function () {
  9627. return JSON3;
  9628. });
  9629. }
  9630. }).call(this);
  9631. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  9632. },{}],55:[function(require,module,exports){
  9633. /**
  9634. * lodash 3.2.0 (Custom Build) <https://lodash.com/>
  9635. * Build: `lodash modern modularize exports="npm" -o ./`
  9636. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  9637. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  9638. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9639. * Available under MIT license <https://lodash.com/license>
  9640. */
  9641. var baseCopy = require('lodash._basecopy'),
  9642. keys = require('lodash.keys');
  9643. /**
  9644. * The base implementation of `_.assign` without support for argument juggling,
  9645. * multiple sources, and `customizer` functions.
  9646. *
  9647. * @private
  9648. * @param {Object} object The destination object.
  9649. * @param {Object} source The source object.
  9650. * @returns {Object} Returns `object`.
  9651. */
  9652. function baseAssign(object, source) {
  9653. return source == null
  9654. ? object
  9655. : baseCopy(source, keys(source), object);
  9656. }
  9657. module.exports = baseAssign;
  9658. },{"lodash._basecopy":56,"lodash.keys":63}],56:[function(require,module,exports){
  9659. /**
  9660. * lodash 3.0.1 (Custom Build) <https://lodash.com/>
  9661. * Build: `lodash modern modularize exports="npm" -o ./`
  9662. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  9663. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  9664. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9665. * Available under MIT license <https://lodash.com/license>
  9666. */
  9667. /**
  9668. * Copies properties of `source` to `object`.
  9669. *
  9670. * @private
  9671. * @param {Object} source The object to copy properties from.
  9672. * @param {Array} props The property names to copy.
  9673. * @param {Object} [object={}] The object to copy properties to.
  9674. * @returns {Object} Returns `object`.
  9675. */
  9676. function baseCopy(source, props, object) {
  9677. object || (object = {});
  9678. var index = -1,
  9679. length = props.length;
  9680. while (++index < length) {
  9681. var key = props[index];
  9682. object[key] = source[key];
  9683. }
  9684. return object;
  9685. }
  9686. module.exports = baseCopy;
  9687. },{}],57:[function(require,module,exports){
  9688. /**
  9689. * lodash 3.0.3 (Custom Build) <https://lodash.com/>
  9690. * Build: `lodash modern modularize exports="npm" -o ./`
  9691. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  9692. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  9693. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9694. * Available under MIT license <https://lodash.com/license>
  9695. */
  9696. /**
  9697. * The base implementation of `_.create` without support for assigning
  9698. * properties to the created object.
  9699. *
  9700. * @private
  9701. * @param {Object} prototype The object to inherit from.
  9702. * @returns {Object} Returns the new object.
  9703. */
  9704. var baseCreate = (function() {
  9705. function object() {}
  9706. return function(prototype) {
  9707. if (isObject(prototype)) {
  9708. object.prototype = prototype;
  9709. var result = new object;
  9710. object.prototype = undefined;
  9711. }
  9712. return result || {};
  9713. };
  9714. }());
  9715. /**
  9716. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  9717. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  9718. *
  9719. * @static
  9720. * @memberOf _
  9721. * @category Lang
  9722. * @param {*} value The value to check.
  9723. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  9724. * @example
  9725. *
  9726. * _.isObject({});
  9727. * // => true
  9728. *
  9729. * _.isObject([1, 2, 3]);
  9730. * // => true
  9731. *
  9732. * _.isObject(1);
  9733. * // => false
  9734. */
  9735. function isObject(value) {
  9736. // Avoid a V8 JIT bug in Chrome 19-20.
  9737. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  9738. var type = typeof value;
  9739. return !!value && (type == 'object' || type == 'function');
  9740. }
  9741. module.exports = baseCreate;
  9742. },{}],58:[function(require,module,exports){
  9743. /**
  9744. * lodash 3.9.1 (Custom Build) <https://lodash.com/>
  9745. * Build: `lodash modern modularize exports="npm" -o ./`
  9746. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  9747. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  9748. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9749. * Available under MIT license <https://lodash.com/license>
  9750. */
  9751. /** `Object#toString` result references. */
  9752. var funcTag = '[object Function]';
  9753. /** Used to detect host constructors (Safari > 5). */
  9754. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  9755. /**
  9756. * Checks if `value` is object-like.
  9757. *
  9758. * @private
  9759. * @param {*} value The value to check.
  9760. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  9761. */
  9762. function isObjectLike(value) {
  9763. return !!value && typeof value == 'object';
  9764. }
  9765. /** Used for native method references. */
  9766. var objectProto = Object.prototype;
  9767. /** Used to resolve the decompiled source of functions. */
  9768. var fnToString = Function.prototype.toString;
  9769. /** Used to check objects for own properties. */
  9770. var hasOwnProperty = objectProto.hasOwnProperty;
  9771. /**
  9772. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  9773. * of values.
  9774. */
  9775. var objToString = objectProto.toString;
  9776. /** Used to detect if a method is native. */
  9777. var reIsNative = RegExp('^' +
  9778. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  9779. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  9780. );
  9781. /**
  9782. * Gets the native function at `key` of `object`.
  9783. *
  9784. * @private
  9785. * @param {Object} object The object to query.
  9786. * @param {string} key The key of the method to get.
  9787. * @returns {*} Returns the function if it's native, else `undefined`.
  9788. */
  9789. function getNative(object, key) {
  9790. var value = object == null ? undefined : object[key];
  9791. return isNative(value) ? value : undefined;
  9792. }
  9793. /**
  9794. * Checks if `value` is classified as a `Function` object.
  9795. *
  9796. * @static
  9797. * @memberOf _
  9798. * @category Lang
  9799. * @param {*} value The value to check.
  9800. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  9801. * @example
  9802. *
  9803. * _.isFunction(_);
  9804. * // => true
  9805. *
  9806. * _.isFunction(/abc/);
  9807. * // => false
  9808. */
  9809. function isFunction(value) {
  9810. // The use of `Object#toString` avoids issues with the `typeof` operator
  9811. // in older versions of Chrome and Safari which return 'function' for regexes
  9812. // and Safari 8 equivalents which return 'object' for typed array constructors.
  9813. return isObject(value) && objToString.call(value) == funcTag;
  9814. }
  9815. /**
  9816. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  9817. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  9818. *
  9819. * @static
  9820. * @memberOf _
  9821. * @category Lang
  9822. * @param {*} value The value to check.
  9823. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  9824. * @example
  9825. *
  9826. * _.isObject({});
  9827. * // => true
  9828. *
  9829. * _.isObject([1, 2, 3]);
  9830. * // => true
  9831. *
  9832. * _.isObject(1);
  9833. * // => false
  9834. */
  9835. function isObject(value) {
  9836. // Avoid a V8 JIT bug in Chrome 19-20.
  9837. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  9838. var type = typeof value;
  9839. return !!value && (type == 'object' || type == 'function');
  9840. }
  9841. /**
  9842. * Checks if `value` is a native function.
  9843. *
  9844. * @static
  9845. * @memberOf _
  9846. * @category Lang
  9847. * @param {*} value The value to check.
  9848. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  9849. * @example
  9850. *
  9851. * _.isNative(Array.prototype.push);
  9852. * // => true
  9853. *
  9854. * _.isNative(_);
  9855. * // => false
  9856. */
  9857. function isNative(value) {
  9858. if (value == null) {
  9859. return false;
  9860. }
  9861. if (isFunction(value)) {
  9862. return reIsNative.test(fnToString.call(value));
  9863. }
  9864. return isObjectLike(value) && reIsHostCtor.test(value);
  9865. }
  9866. module.exports = getNative;
  9867. },{}],59:[function(require,module,exports){
  9868. /**
  9869. * lodash 3.0.9 (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. /** Used to detect unsigned integer values. */
  9877. var reIsUint = /^\d+$/;
  9878. /**
  9879. * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
  9880. * of an array-like value.
  9881. */
  9882. var MAX_SAFE_INTEGER = 9007199254740991;
  9883. /**
  9884. * The base implementation of `_.property` without support for deep paths.
  9885. *
  9886. * @private
  9887. * @param {string} key The key of the property to get.
  9888. * @returns {Function} Returns the new function.
  9889. */
  9890. function baseProperty(key) {
  9891. return function(object) {
  9892. return object == null ? undefined : object[key];
  9893. };
  9894. }
  9895. /**
  9896. * Gets the "length" property value of `object`.
  9897. *
  9898. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  9899. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  9900. *
  9901. * @private
  9902. * @param {Object} object The object to query.
  9903. * @returns {*} Returns the "length" value.
  9904. */
  9905. var getLength = baseProperty('length');
  9906. /**
  9907. * Checks if `value` is array-like.
  9908. *
  9909. * @private
  9910. * @param {*} value The value to check.
  9911. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  9912. */
  9913. function isArrayLike(value) {
  9914. return value != null && isLength(getLength(value));
  9915. }
  9916. /**
  9917. * Checks if `value` is a valid array-like index.
  9918. *
  9919. * @private
  9920. * @param {*} value The value to check.
  9921. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  9922. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  9923. */
  9924. function isIndex(value, length) {
  9925. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  9926. length = length == null ? MAX_SAFE_INTEGER : length;
  9927. return value > -1 && value % 1 == 0 && value < length;
  9928. }
  9929. /**
  9930. * Checks if the provided arguments are from an iteratee call.
  9931. *
  9932. * @private
  9933. * @param {*} value The potential iteratee value argument.
  9934. * @param {*} index The potential iteratee index or key argument.
  9935. * @param {*} object The potential iteratee object argument.
  9936. * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
  9937. */
  9938. function isIterateeCall(value, index, object) {
  9939. if (!isObject(object)) {
  9940. return false;
  9941. }
  9942. var type = typeof index;
  9943. if (type == 'number'
  9944. ? (isArrayLike(object) && isIndex(index, object.length))
  9945. : (type == 'string' && index in object)) {
  9946. var other = object[index];
  9947. return value === value ? (value === other) : (other !== other);
  9948. }
  9949. return false;
  9950. }
  9951. /**
  9952. * Checks if `value` is a valid array-like length.
  9953. *
  9954. * **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
  9955. *
  9956. * @private
  9957. * @param {*} value The value to check.
  9958. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  9959. */
  9960. function isLength(value) {
  9961. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  9962. }
  9963. /**
  9964. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  9965. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  9966. *
  9967. * @static
  9968. * @memberOf _
  9969. * @category Lang
  9970. * @param {*} value The value to check.
  9971. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  9972. * @example
  9973. *
  9974. * _.isObject({});
  9975. * // => true
  9976. *
  9977. * _.isObject([1, 2, 3]);
  9978. * // => true
  9979. *
  9980. * _.isObject(1);
  9981. * // => false
  9982. */
  9983. function isObject(value) {
  9984. // Avoid a V8 JIT bug in Chrome 19-20.
  9985. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  9986. var type = typeof value;
  9987. return !!value && (type == 'object' || type == 'function');
  9988. }
  9989. module.exports = isIterateeCall;
  9990. },{}],60:[function(require,module,exports){
  9991. /**
  9992. * lodash 3.1.1 (Custom Build) <https://lodash.com/>
  9993. * Build: `lodash modern modularize exports="npm" -o ./`
  9994. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  9995. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  9996. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9997. * Available under MIT license <https://lodash.com/license>
  9998. */
  9999. var baseAssign = require('lodash._baseassign'),
  10000. baseCreate = require('lodash._basecreate'),
  10001. isIterateeCall = require('lodash._isiterateecall');
  10002. /**
  10003. * Creates an object that inherits from the given `prototype` object. If a
  10004. * `properties` object is provided its own enumerable properties are assigned
  10005. * to the created object.
  10006. *
  10007. * @static
  10008. * @memberOf _
  10009. * @category Object
  10010. * @param {Object} prototype The object to inherit from.
  10011. * @param {Object} [properties] The properties to assign to the object.
  10012. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10013. * @returns {Object} Returns the new object.
  10014. * @example
  10015. *
  10016. * function Shape() {
  10017. * this.x = 0;
  10018. * this.y = 0;
  10019. * }
  10020. *
  10021. * function Circle() {
  10022. * Shape.call(this);
  10023. * }
  10024. *
  10025. * Circle.prototype = _.create(Shape.prototype, {
  10026. * 'constructor': Circle
  10027. * });
  10028. *
  10029. * var circle = new Circle;
  10030. * circle instanceof Circle;
  10031. * // => true
  10032. *
  10033. * circle instanceof Shape;
  10034. * // => true
  10035. */
  10036. function create(prototype, properties, guard) {
  10037. var result = baseCreate(prototype);
  10038. if (guard && isIterateeCall(prototype, properties, guard)) {
  10039. properties = undefined;
  10040. }
  10041. return properties ? baseAssign(result, properties) : result;
  10042. }
  10043. module.exports = create;
  10044. },{"lodash._baseassign":55,"lodash._basecreate":57,"lodash._isiterateecall":59}],61:[function(require,module,exports){
  10045. /**
  10046. * lodash 3.0.8 (Custom Build) <https://lodash.com/>
  10047. * Build: `lodash modularize exports="npm" -o ./`
  10048. * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
  10049. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10050. * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10051. * Available under MIT license <https://lodash.com/license>
  10052. */
  10053. /** Used as references for various `Number` constants. */
  10054. var MAX_SAFE_INTEGER = 9007199254740991;
  10055. /** `Object#toString` result references. */
  10056. var argsTag = '[object Arguments]',
  10057. funcTag = '[object Function]',
  10058. genTag = '[object GeneratorFunction]';
  10059. /** Used for built-in method references. */
  10060. var objectProto = Object.prototype;
  10061. /** Used to check objects for own properties. */
  10062. var hasOwnProperty = objectProto.hasOwnProperty;
  10063. /**
  10064. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  10065. * of values.
  10066. */
  10067. var objectToString = objectProto.toString;
  10068. /** Built-in value references. */
  10069. var propertyIsEnumerable = objectProto.propertyIsEnumerable;
  10070. /**
  10071. * The base implementation of `_.property` without support for deep paths.
  10072. *
  10073. * @private
  10074. * @param {string} key The key of the property to get.
  10075. * @returns {Function} Returns the new function.
  10076. */
  10077. function baseProperty(key) {
  10078. return function(object) {
  10079. return object == null ? undefined : object[key];
  10080. };
  10081. }
  10082. /**
  10083. * Gets the "length" property value of `object`.
  10084. *
  10085. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  10086. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  10087. *
  10088. * @private
  10089. * @param {Object} object The object to query.
  10090. * @returns {*} Returns the "length" value.
  10091. */
  10092. var getLength = baseProperty('length');
  10093. /**
  10094. * Checks if `value` is likely an `arguments` object.
  10095. *
  10096. * @static
  10097. * @memberOf _
  10098. * @category Lang
  10099. * @param {*} value The value to check.
  10100. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10101. * @example
  10102. *
  10103. * _.isArguments(function() { return arguments; }());
  10104. * // => true
  10105. *
  10106. * _.isArguments([1, 2, 3]);
  10107. * // => false
  10108. */
  10109. function isArguments(value) {
  10110. // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
  10111. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  10112. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  10113. }
  10114. /**
  10115. * Checks if `value` is array-like. A value is considered array-like if it's
  10116. * not a function and has a `value.length` that's an integer greater than or
  10117. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10118. *
  10119. * @static
  10120. * @memberOf _
  10121. * @category Lang
  10122. * @param {*} value The value to check.
  10123. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10124. * @example
  10125. *
  10126. * _.isArrayLike([1, 2, 3]);
  10127. * // => true
  10128. *
  10129. * _.isArrayLike(document.body.children);
  10130. * // => true
  10131. *
  10132. * _.isArrayLike('abc');
  10133. * // => true
  10134. *
  10135. * _.isArrayLike(_.noop);
  10136. * // => false
  10137. */
  10138. function isArrayLike(value) {
  10139. return value != null && isLength(getLength(value)) && !isFunction(value);
  10140. }
  10141. /**
  10142. * This method is like `_.isArrayLike` except that it also checks if `value`
  10143. * is an object.
  10144. *
  10145. * @static
  10146. * @memberOf _
  10147. * @category Lang
  10148. * @param {*} value The value to check.
  10149. * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`.
  10150. * @example
  10151. *
  10152. * _.isArrayLikeObject([1, 2, 3]);
  10153. * // => true
  10154. *
  10155. * _.isArrayLikeObject(document.body.children);
  10156. * // => true
  10157. *
  10158. * _.isArrayLikeObject('abc');
  10159. * // => false
  10160. *
  10161. * _.isArrayLikeObject(_.noop);
  10162. * // => false
  10163. */
  10164. function isArrayLikeObject(value) {
  10165. return isObjectLike(value) && isArrayLike(value);
  10166. }
  10167. /**
  10168. * Checks if `value` is classified as a `Function` object.
  10169. *
  10170. * @static
  10171. * @memberOf _
  10172. * @category Lang
  10173. * @param {*} value The value to check.
  10174. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10175. * @example
  10176. *
  10177. * _.isFunction(_);
  10178. * // => true
  10179. *
  10180. * _.isFunction(/abc/);
  10181. * // => false
  10182. */
  10183. function isFunction(value) {
  10184. // The use of `Object#toString` avoids issues with the `typeof` operator
  10185. // in Safari 8 which returns 'object' for typed array and weak map constructors,
  10186. // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
  10187. var tag = isObject(value) ? objectToString.call(value) : '';
  10188. return tag == funcTag || tag == genTag;
  10189. }
  10190. /**
  10191. * Checks if `value` is a valid array-like length.
  10192. *
  10193. * **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  10194. *
  10195. * @static
  10196. * @memberOf _
  10197. * @category Lang
  10198. * @param {*} value The value to check.
  10199. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10200. * @example
  10201. *
  10202. * _.isLength(3);
  10203. * // => true
  10204. *
  10205. * _.isLength(Number.MIN_VALUE);
  10206. * // => false
  10207. *
  10208. * _.isLength(Infinity);
  10209. * // => false
  10210. *
  10211. * _.isLength('3');
  10212. * // => false
  10213. */
  10214. function isLength(value) {
  10215. return typeof value == 'number' &&
  10216. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10217. }
  10218. /**
  10219. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  10220. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10221. *
  10222. * @static
  10223. * @memberOf _
  10224. * @category Lang
  10225. * @param {*} value The value to check.
  10226. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10227. * @example
  10228. *
  10229. * _.isObject({});
  10230. * // => true
  10231. *
  10232. * _.isObject([1, 2, 3]);
  10233. * // => true
  10234. *
  10235. * _.isObject(_.noop);
  10236. * // => true
  10237. *
  10238. * _.isObject(null);
  10239. * // => false
  10240. */
  10241. function isObject(value) {
  10242. var type = typeof value;
  10243. return !!value && (type == 'object' || type == 'function');
  10244. }
  10245. /**
  10246. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10247. * and has a `typeof` result of "object".
  10248. *
  10249. * @static
  10250. * @memberOf _
  10251. * @category Lang
  10252. * @param {*} value The value to check.
  10253. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10254. * @example
  10255. *
  10256. * _.isObjectLike({});
  10257. * // => true
  10258. *
  10259. * _.isObjectLike([1, 2, 3]);
  10260. * // => true
  10261. *
  10262. * _.isObjectLike(_.noop);
  10263. * // => false
  10264. *
  10265. * _.isObjectLike(null);
  10266. * // => false
  10267. */
  10268. function isObjectLike(value) {
  10269. return !!value && typeof value == 'object';
  10270. }
  10271. module.exports = isArguments;
  10272. },{}],62:[function(require,module,exports){
  10273. /**
  10274. * lodash 3.0.4 (Custom Build) <https://lodash.com/>
  10275. * Build: `lodash modern modularize exports="npm" -o ./`
  10276. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10277. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10278. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10279. * Available under MIT license <https://lodash.com/license>
  10280. */
  10281. /** `Object#toString` result references. */
  10282. var arrayTag = '[object Array]',
  10283. funcTag = '[object Function]';
  10284. /** Used to detect host constructors (Safari > 5). */
  10285. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  10286. /**
  10287. * Checks if `value` is object-like.
  10288. *
  10289. * @private
  10290. * @param {*} value The value to check.
  10291. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10292. */
  10293. function isObjectLike(value) {
  10294. return !!value && typeof value == 'object';
  10295. }
  10296. /** Used for native method references. */
  10297. var objectProto = Object.prototype;
  10298. /** Used to resolve the decompiled source of functions. */
  10299. var fnToString = Function.prototype.toString;
  10300. /** Used to check objects for own properties. */
  10301. var hasOwnProperty = objectProto.hasOwnProperty;
  10302. /**
  10303. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  10304. * of values.
  10305. */
  10306. var objToString = objectProto.toString;
  10307. /** Used to detect if a method is native. */
  10308. var reIsNative = RegExp('^' +
  10309. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  10310. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  10311. );
  10312. /* Native method references for those with the same name as other `lodash` methods. */
  10313. var nativeIsArray = getNative(Array, 'isArray');
  10314. /**
  10315. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  10316. * of an array-like value.
  10317. */
  10318. var MAX_SAFE_INTEGER = 9007199254740991;
  10319. /**
  10320. * Gets the native function at `key` of `object`.
  10321. *
  10322. * @private
  10323. * @param {Object} object The object to query.
  10324. * @param {string} key The key of the method to get.
  10325. * @returns {*} Returns the function if it's native, else `undefined`.
  10326. */
  10327. function getNative(object, key) {
  10328. var value = object == null ? undefined : object[key];
  10329. return isNative(value) ? value : undefined;
  10330. }
  10331. /**
  10332. * Checks if `value` is a valid array-like length.
  10333. *
  10334. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  10335. *
  10336. * @private
  10337. * @param {*} value The value to check.
  10338. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10339. */
  10340. function isLength(value) {
  10341. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10342. }
  10343. /**
  10344. * Checks if `value` is classified as an `Array` object.
  10345. *
  10346. * @static
  10347. * @memberOf _
  10348. * @category Lang
  10349. * @param {*} value The value to check.
  10350. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10351. * @example
  10352. *
  10353. * _.isArray([1, 2, 3]);
  10354. * // => true
  10355. *
  10356. * _.isArray(function() { return arguments; }());
  10357. * // => false
  10358. */
  10359. var isArray = nativeIsArray || function(value) {
  10360. return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
  10361. };
  10362. /**
  10363. * Checks if `value` is classified as a `Function` object.
  10364. *
  10365. * @static
  10366. * @memberOf _
  10367. * @category Lang
  10368. * @param {*} value The value to check.
  10369. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10370. * @example
  10371. *
  10372. * _.isFunction(_);
  10373. * // => true
  10374. *
  10375. * _.isFunction(/abc/);
  10376. * // => false
  10377. */
  10378. function isFunction(value) {
  10379. // The use of `Object#toString` avoids issues with the `typeof` operator
  10380. // in older versions of Chrome and Safari which return 'function' for regexes
  10381. // and Safari 8 equivalents which return 'object' for typed array constructors.
  10382. return isObject(value) && objToString.call(value) == funcTag;
  10383. }
  10384. /**
  10385. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  10386. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10387. *
  10388. * @static
  10389. * @memberOf _
  10390. * @category Lang
  10391. * @param {*} value The value to check.
  10392. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10393. * @example
  10394. *
  10395. * _.isObject({});
  10396. * // => true
  10397. *
  10398. * _.isObject([1, 2, 3]);
  10399. * // => true
  10400. *
  10401. * _.isObject(1);
  10402. * // => false
  10403. */
  10404. function isObject(value) {
  10405. // Avoid a V8 JIT bug in Chrome 19-20.
  10406. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  10407. var type = typeof value;
  10408. return !!value && (type == 'object' || type == 'function');
  10409. }
  10410. /**
  10411. * Checks if `value` is a native function.
  10412. *
  10413. * @static
  10414. * @memberOf _
  10415. * @category Lang
  10416. * @param {*} value The value to check.
  10417. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  10418. * @example
  10419. *
  10420. * _.isNative(Array.prototype.push);
  10421. * // => true
  10422. *
  10423. * _.isNative(_);
  10424. * // => false
  10425. */
  10426. function isNative(value) {
  10427. if (value == null) {
  10428. return false;
  10429. }
  10430. if (isFunction(value)) {
  10431. return reIsNative.test(fnToString.call(value));
  10432. }
  10433. return isObjectLike(value) && reIsHostCtor.test(value);
  10434. }
  10435. module.exports = isArray;
  10436. },{}],63:[function(require,module,exports){
  10437. /**
  10438. * lodash 3.1.2 (Custom Build) <https://lodash.com/>
  10439. * Build: `lodash modern modularize exports="npm" -o ./`
  10440. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10441. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10442. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10443. * Available under MIT license <https://lodash.com/license>
  10444. */
  10445. var getNative = require('lodash._getnative'),
  10446. isArguments = require('lodash.isarguments'),
  10447. isArray = require('lodash.isarray');
  10448. /** Used to detect unsigned integer values. */
  10449. var reIsUint = /^\d+$/;
  10450. /** Used for native method references. */
  10451. var objectProto = Object.prototype;
  10452. /** Used to check objects for own properties. */
  10453. var hasOwnProperty = objectProto.hasOwnProperty;
  10454. /* Native method references for those with the same name as other `lodash` methods. */
  10455. var nativeKeys = getNative(Object, 'keys');
  10456. /**
  10457. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  10458. * of an array-like value.
  10459. */
  10460. var MAX_SAFE_INTEGER = 9007199254740991;
  10461. /**
  10462. * The base implementation of `_.property` without support for deep paths.
  10463. *
  10464. * @private
  10465. * @param {string} key The key of the property to get.
  10466. * @returns {Function} Returns the new function.
  10467. */
  10468. function baseProperty(key) {
  10469. return function(object) {
  10470. return object == null ? undefined : object[key];
  10471. };
  10472. }
  10473. /**
  10474. * Gets the "length" property value of `object`.
  10475. *
  10476. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  10477. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  10478. *
  10479. * @private
  10480. * @param {Object} object The object to query.
  10481. * @returns {*} Returns the "length" value.
  10482. */
  10483. var getLength = baseProperty('length');
  10484. /**
  10485. * Checks if `value` is array-like.
  10486. *
  10487. * @private
  10488. * @param {*} value The value to check.
  10489. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10490. */
  10491. function isArrayLike(value) {
  10492. return value != null && isLength(getLength(value));
  10493. }
  10494. /**
  10495. * Checks if `value` is a valid array-like index.
  10496. *
  10497. * @private
  10498. * @param {*} value The value to check.
  10499. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  10500. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  10501. */
  10502. function isIndex(value, length) {
  10503. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  10504. length = length == null ? MAX_SAFE_INTEGER : length;
  10505. return value > -1 && value % 1 == 0 && value < length;
  10506. }
  10507. /**
  10508. * Checks if `value` is a valid array-like length.
  10509. *
  10510. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  10511. *
  10512. * @private
  10513. * @param {*} value The value to check.
  10514. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10515. */
  10516. function isLength(value) {
  10517. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10518. }
  10519. /**
  10520. * A fallback implementation of `Object.keys` which creates an array of the
  10521. * own enumerable property names of `object`.
  10522. *
  10523. * @private
  10524. * @param {Object} object The object to query.
  10525. * @returns {Array} Returns the array of property names.
  10526. */
  10527. function shimKeys(object) {
  10528. var props = keysIn(object),
  10529. propsLength = props.length,
  10530. length = propsLength && object.length;
  10531. var allowIndexes = !!length && isLength(length) &&
  10532. (isArray(object) || isArguments(object));
  10533. var index = -1,
  10534. result = [];
  10535. while (++index < propsLength) {
  10536. var key = props[index];
  10537. if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
  10538. result.push(key);
  10539. }
  10540. }
  10541. return result;
  10542. }
  10543. /**
  10544. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  10545. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10546. *
  10547. * @static
  10548. * @memberOf _
  10549. * @category Lang
  10550. * @param {*} value The value to check.
  10551. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10552. * @example
  10553. *
  10554. * _.isObject({});
  10555. * // => true
  10556. *
  10557. * _.isObject([1, 2, 3]);
  10558. * // => true
  10559. *
  10560. * _.isObject(1);
  10561. * // => false
  10562. */
  10563. function isObject(value) {
  10564. // Avoid a V8 JIT bug in Chrome 19-20.
  10565. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  10566. var type = typeof value;
  10567. return !!value && (type == 'object' || type == 'function');
  10568. }
  10569. /**
  10570. * Creates an array of the own enumerable property names of `object`.
  10571. *
  10572. * **Note:** Non-object values are coerced to objects. See the
  10573. * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
  10574. * for more details.
  10575. *
  10576. * @static
  10577. * @memberOf _
  10578. * @category Object
  10579. * @param {Object} object The object to query.
  10580. * @returns {Array} Returns the array of property names.
  10581. * @example
  10582. *
  10583. * function Foo() {
  10584. * this.a = 1;
  10585. * this.b = 2;
  10586. * }
  10587. *
  10588. * Foo.prototype.c = 3;
  10589. *
  10590. * _.keys(new Foo);
  10591. * // => ['a', 'b'] (iteration order is not guaranteed)
  10592. *
  10593. * _.keys('hi');
  10594. * // => ['0', '1']
  10595. */
  10596. var keys = !nativeKeys ? shimKeys : function(object) {
  10597. var Ctor = object == null ? undefined : object.constructor;
  10598. if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
  10599. (typeof object != 'function' && isArrayLike(object))) {
  10600. return shimKeys(object);
  10601. }
  10602. return isObject(object) ? nativeKeys(object) : [];
  10603. };
  10604. /**
  10605. * Creates an array of the own and inherited enumerable property names of `object`.
  10606. *
  10607. * **Note:** Non-object values are coerced to objects.
  10608. *
  10609. * @static
  10610. * @memberOf _
  10611. * @category Object
  10612. * @param {Object} object The object to query.
  10613. * @returns {Array} Returns the array of property names.
  10614. * @example
  10615. *
  10616. * function Foo() {
  10617. * this.a = 1;
  10618. * this.b = 2;
  10619. * }
  10620. *
  10621. * Foo.prototype.c = 3;
  10622. *
  10623. * _.keysIn(new Foo);
  10624. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  10625. */
  10626. function keysIn(object) {
  10627. if (object == null) {
  10628. return [];
  10629. }
  10630. if (!isObject(object)) {
  10631. object = Object(object);
  10632. }
  10633. var length = object.length;
  10634. length = (length && isLength(length) &&
  10635. (isArray(object) || isArguments(object)) && length) || 0;
  10636. var Ctor = object.constructor,
  10637. index = -1,
  10638. isProto = typeof Ctor == 'function' && Ctor.prototype === object,
  10639. result = Array(length),
  10640. skipIndexes = length > 0;
  10641. while (++index < length) {
  10642. result[index] = (index + '');
  10643. }
  10644. for (var key in object) {
  10645. if (!(skipIndexes && isIndex(key, length)) &&
  10646. !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  10647. result.push(key);
  10648. }
  10649. }
  10650. return result;
  10651. }
  10652. module.exports = keys;
  10653. },{"lodash._getnative":58,"lodash.isarguments":61,"lodash.isarray":62}],64:[function(require,module,exports){
  10654. (function (process){
  10655. var path = require('path');
  10656. var fs = require('fs');
  10657. var _0777 = parseInt('0777', 8);
  10658. module.exports = mkdirP.mkdirp = mkdirP.mkdirP = mkdirP;
  10659. function mkdirP (p, opts, f, made) {
  10660. if (typeof opts === 'function') {
  10661. f = opts;
  10662. opts = {};
  10663. }
  10664. else if (!opts || typeof opts !== 'object') {
  10665. opts = { mode: opts };
  10666. }
  10667. var mode = opts.mode;
  10668. var xfs = opts.fs || fs;
  10669. if (mode === undefined) {
  10670. mode = _0777 & (~process.umask());
  10671. }
  10672. if (!made) made = null;
  10673. var cb = f || function () {};
  10674. p = path.resolve(p);
  10675. xfs.mkdir(p, mode, function (er) {
  10676. if (!er) {
  10677. made = made || p;
  10678. return cb(null, made);
  10679. }
  10680. switch (er.code) {
  10681. case 'ENOENT':
  10682. mkdirP(path.dirname(p), opts, function (er, made) {
  10683. if (er) cb(er, made);
  10684. else mkdirP(p, opts, cb, made);
  10685. });
  10686. break;
  10687. // In the case of any other error, just see if there's a dir
  10688. // there already. If so, then hooray! If not, then something
  10689. // is borked.
  10690. default:
  10691. xfs.stat(p, function (er2, stat) {
  10692. // if the stat fails, then that's super weird.
  10693. // let the original error be the failure reason.
  10694. if (er2 || !stat.isDirectory()) cb(er, made)
  10695. else cb(null, made);
  10696. });
  10697. break;
  10698. }
  10699. });
  10700. }
  10701. mkdirP.sync = function sync (p, opts, made) {
  10702. if (!opts || typeof opts !== 'object') {
  10703. opts = { mode: opts };
  10704. }
  10705. var mode = opts.mode;
  10706. var xfs = opts.fs || fs;
  10707. if (mode === undefined) {
  10708. mode = _0777 & (~process.umask());
  10709. }
  10710. if (!made) made = null;
  10711. p = path.resolve(p);
  10712. try {
  10713. xfs.mkdirSync(p, mode);
  10714. made = made || p;
  10715. }
  10716. catch (err0) {
  10717. switch (err0.code) {
  10718. case 'ENOENT' :
  10719. made = sync(path.dirname(p), opts, made);
  10720. sync(p, opts, made);
  10721. break;
  10722. // In the case of any other error, just see if there's a dir
  10723. // there already. If so, then hooray! If not, then something
  10724. // is borked.
  10725. default:
  10726. var stat;
  10727. try {
  10728. stat = xfs.statSync(p);
  10729. }
  10730. catch (err1) {
  10731. throw err0;
  10732. }
  10733. if (!stat.isDirectory()) throw err0;
  10734. break;
  10735. }
  10736. }
  10737. return made;
  10738. };
  10739. }).call(this,require('_process'))
  10740. },{"_process":67,"fs":42,"path":42}],65:[function(require,module,exports){
  10741. exports.endianness = function () { return 'LE' };
  10742. exports.hostname = function () {
  10743. if (typeof location !== 'undefined') {
  10744. return location.hostname
  10745. }
  10746. else return '';
  10747. };
  10748. exports.loadavg = function () { return [] };
  10749. exports.uptime = function () { return 0 };
  10750. exports.freemem = function () {
  10751. return Number.MAX_VALUE;
  10752. };
  10753. exports.totalmem = function () {
  10754. return Number.MAX_VALUE;
  10755. };
  10756. exports.cpus = function () { return [] };
  10757. exports.type = function () { return 'Browser' };
  10758. exports.release = function () {
  10759. if (typeof navigator !== 'undefined') {
  10760. return navigator.appVersion;
  10761. }
  10762. return '';
  10763. };
  10764. exports.networkInterfaces
  10765. = exports.getNetworkInterfaces
  10766. = function () { return {} };
  10767. exports.arch = function () { return 'javascript' };
  10768. exports.platform = function () { return 'browser' };
  10769. exports.tmpdir = exports.tmpDir = function () {
  10770. return '/tmp';
  10771. };
  10772. exports.EOL = '\n';
  10773. },{}],66:[function(require,module,exports){
  10774. (function (process){
  10775. 'use strict';
  10776. if (!process.version ||
  10777. process.version.indexOf('v0.') === 0 ||
  10778. process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
  10779. module.exports = nextTick;
  10780. } else {
  10781. module.exports = process.nextTick;
  10782. }
  10783. function nextTick(fn, arg1, arg2, arg3) {
  10784. if (typeof fn !== 'function') {
  10785. throw new TypeError('"callback" argument must be a function');
  10786. }
  10787. var len = arguments.length;
  10788. var args, i;
  10789. switch (len) {
  10790. case 0:
  10791. case 1:
  10792. return process.nextTick(fn);
  10793. case 2:
  10794. return process.nextTick(function afterTickOne() {
  10795. fn.call(null, arg1);
  10796. });
  10797. case 3:
  10798. return process.nextTick(function afterTickTwo() {
  10799. fn.call(null, arg1, arg2);
  10800. });
  10801. case 4:
  10802. return process.nextTick(function afterTickThree() {
  10803. fn.call(null, arg1, arg2, arg3);
  10804. });
  10805. default:
  10806. args = new Array(len - 1);
  10807. i = 0;
  10808. while (i < args.length) {
  10809. args[i++] = arguments[i];
  10810. }
  10811. return process.nextTick(function afterTick() {
  10812. fn.apply(null, args);
  10813. });
  10814. }
  10815. }
  10816. }).call(this,require('_process'))
  10817. },{"_process":67}],67:[function(require,module,exports){
  10818. // shim for using process in browser
  10819. var process = module.exports = {};
  10820. // cached from whatever global is present so that test runners that stub it
  10821. // don't break things. But we need to wrap it in a try catch in case it is
  10822. // wrapped in strict mode code which doesn't define any globals. It's inside a
  10823. // function because try/catches deoptimize in certain engines.
  10824. var cachedSetTimeout;
  10825. var cachedClearTimeout;
  10826. (function () {
  10827. try {
  10828. cachedSetTimeout = setTimeout;
  10829. } catch (e) {
  10830. cachedSetTimeout = function () {
  10831. throw new Error('setTimeout is not defined');
  10832. }
  10833. }
  10834. try {
  10835. cachedClearTimeout = clearTimeout;
  10836. } catch (e) {
  10837. cachedClearTimeout = function () {
  10838. throw new Error('clearTimeout is not defined');
  10839. }
  10840. }
  10841. } ())
  10842. var queue = [];
  10843. var draining = false;
  10844. var currentQueue;
  10845. var queueIndex = -1;
  10846. function cleanUpNextTick() {
  10847. if (!draining || !currentQueue) {
  10848. return;
  10849. }
  10850. draining = false;
  10851. if (currentQueue.length) {
  10852. queue = currentQueue.concat(queue);
  10853. } else {
  10854. queueIndex = -1;
  10855. }
  10856. if (queue.length) {
  10857. drainQueue();
  10858. }
  10859. }
  10860. function drainQueue() {
  10861. if (draining) {
  10862. return;
  10863. }
  10864. var timeout = cachedSetTimeout(cleanUpNextTick);
  10865. draining = true;
  10866. var len = queue.length;
  10867. while(len) {
  10868. currentQueue = queue;
  10869. queue = [];
  10870. while (++queueIndex < len) {
  10871. if (currentQueue) {
  10872. currentQueue[queueIndex].run();
  10873. }
  10874. }
  10875. queueIndex = -1;
  10876. len = queue.length;
  10877. }
  10878. currentQueue = null;
  10879. draining = false;
  10880. cachedClearTimeout(timeout);
  10881. }
  10882. process.nextTick = function (fun) {
  10883. var args = new Array(arguments.length - 1);
  10884. if (arguments.length > 1) {
  10885. for (var i = 1; i < arguments.length; i++) {
  10886. args[i - 1] = arguments[i];
  10887. }
  10888. }
  10889. queue.push(new Item(fun, args));
  10890. if (queue.length === 1 && !draining) {
  10891. cachedSetTimeout(drainQueue, 0);
  10892. }
  10893. };
  10894. // v8 likes predictible objects
  10895. function Item(fun, array) {
  10896. this.fun = fun;
  10897. this.array = array;
  10898. }
  10899. Item.prototype.run = function () {
  10900. this.fun.apply(null, this.array);
  10901. };
  10902. process.title = 'browser';
  10903. process.browser = true;
  10904. process.env = {};
  10905. process.argv = [];
  10906. process.version = ''; // empty string to avoid regexp issues
  10907. process.versions = {};
  10908. function noop() {}
  10909. process.on = noop;
  10910. process.addListener = noop;
  10911. process.once = noop;
  10912. process.off = noop;
  10913. process.removeListener = noop;
  10914. process.removeAllListeners = noop;
  10915. process.emit = noop;
  10916. process.binding = function (name) {
  10917. throw new Error('process.binding is not supported');
  10918. };
  10919. process.cwd = function () { return '/' };
  10920. process.chdir = function (dir) {
  10921. throw new Error('process.chdir is not supported');
  10922. };
  10923. process.umask = function() { return 0; };
  10924. },{}],68:[function(require,module,exports){
  10925. module.exports = require("./lib/_stream_duplex.js")
  10926. },{"./lib/_stream_duplex.js":69}],69:[function(require,module,exports){
  10927. // a duplex stream is just a stream that is both readable and writable.
  10928. // Since JS doesn't have multiple prototypal inheritance, this class
  10929. // prototypally inherits from Readable, and then parasitically from
  10930. // Writable.
  10931. 'use strict';
  10932. /*<replacement>*/
  10933. var objectKeys = Object.keys || function (obj) {
  10934. var keys = [];
  10935. for (var key in obj) {
  10936. keys.push(key);
  10937. }return keys;
  10938. };
  10939. /*</replacement>*/
  10940. module.exports = Duplex;
  10941. /*<replacement>*/
  10942. var processNextTick = require('process-nextick-args');
  10943. /*</replacement>*/
  10944. /*<replacement>*/
  10945. var util = require('core-util-is');
  10946. util.inherits = require('inherits');
  10947. /*</replacement>*/
  10948. var Readable = require('./_stream_readable');
  10949. var Writable = require('./_stream_writable');
  10950. util.inherits(Duplex, Readable);
  10951. var keys = objectKeys(Writable.prototype);
  10952. for (var v = 0; v < keys.length; v++) {
  10953. var method = keys[v];
  10954. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  10955. }
  10956. function Duplex(options) {
  10957. if (!(this instanceof Duplex)) return new Duplex(options);
  10958. Readable.call(this, options);
  10959. Writable.call(this, options);
  10960. if (options && options.readable === false) this.readable = false;
  10961. if (options && options.writable === false) this.writable = false;
  10962. this.allowHalfOpen = true;
  10963. if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
  10964. this.once('end', onend);
  10965. }
  10966. // the no-half-open enforcer
  10967. function onend() {
  10968. // if we allow half-open state, or if the writable side ended,
  10969. // then we're ok.
  10970. if (this.allowHalfOpen || this._writableState.ended) return;
  10971. // no more data can be written.
  10972. // But allow more writes to happen in this tick.
  10973. processNextTick(onEndNT, this);
  10974. }
  10975. function onEndNT(self) {
  10976. self.end();
  10977. }
  10978. function forEach(xs, f) {
  10979. for (var i = 0, l = xs.length; i < l; i++) {
  10980. f(xs[i], i);
  10981. }
  10982. }
  10983. },{"./_stream_readable":71,"./_stream_writable":73,"core-util-is":45,"inherits":51,"process-nextick-args":66}],70:[function(require,module,exports){
  10984. // a passthrough stream.
  10985. // basically just the most minimal sort of Transform stream.
  10986. // Every written chunk gets output as-is.
  10987. 'use strict';
  10988. module.exports = PassThrough;
  10989. var Transform = require('./_stream_transform');
  10990. /*<replacement>*/
  10991. var util = require('core-util-is');
  10992. util.inherits = require('inherits');
  10993. /*</replacement>*/
  10994. util.inherits(PassThrough, Transform);
  10995. function PassThrough(options) {
  10996. if (!(this instanceof PassThrough)) return new PassThrough(options);
  10997. Transform.call(this, options);
  10998. }
  10999. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  11000. cb(null, chunk);
  11001. };
  11002. },{"./_stream_transform":72,"core-util-is":45,"inherits":51}],71:[function(require,module,exports){
  11003. (function (process){
  11004. 'use strict';
  11005. module.exports = Readable;
  11006. /*<replacement>*/
  11007. var processNextTick = require('process-nextick-args');
  11008. /*</replacement>*/
  11009. /*<replacement>*/
  11010. var isArray = require('isarray');
  11011. /*</replacement>*/
  11012. Readable.ReadableState = ReadableState;
  11013. /*<replacement>*/
  11014. var EE = require('events').EventEmitter;
  11015. var EElistenerCount = function (emitter, type) {
  11016. return emitter.listeners(type).length;
  11017. };
  11018. /*</replacement>*/
  11019. /*<replacement>*/
  11020. var Stream;
  11021. (function () {
  11022. try {
  11023. Stream = require('st' + 'ream');
  11024. } catch (_) {} finally {
  11025. if (!Stream) Stream = require('events').EventEmitter;
  11026. }
  11027. })();
  11028. /*</replacement>*/
  11029. var Buffer = require('buffer').Buffer;
  11030. /*<replacement>*/
  11031. var bufferShim = require('buffer-shims');
  11032. /*</replacement>*/
  11033. /*<replacement>*/
  11034. var util = require('core-util-is');
  11035. util.inherits = require('inherits');
  11036. /*</replacement>*/
  11037. /*<replacement>*/
  11038. var debugUtil = require('util');
  11039. var debug = void 0;
  11040. if (debugUtil && debugUtil.debuglog) {
  11041. debug = debugUtil.debuglog('stream');
  11042. } else {
  11043. debug = function () {};
  11044. }
  11045. /*</replacement>*/
  11046. var StringDecoder;
  11047. util.inherits(Readable, Stream);
  11048. var hasPrependListener = typeof EE.prototype.prependListener === 'function';
  11049. function prependListener(emitter, event, fn) {
  11050. if (hasPrependListener) return emitter.prependListener(event, fn);
  11051. // This is a brutally ugly hack to make sure that our error handler
  11052. // is attached before any userland ones. NEVER DO THIS. This is here
  11053. // only because this code needs to continue to work with older versions
  11054. // of Node.js that do not include the prependListener() method. The goal
  11055. // is to eventually remove this hack.
  11056. 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]];
  11057. }
  11058. var Duplex;
  11059. function ReadableState(options, stream) {
  11060. Duplex = Duplex || require('./_stream_duplex');
  11061. options = options || {};
  11062. // object stream flag. Used to make read(n) ignore n and to
  11063. // make all the buffer merging and length checks go away
  11064. this.objectMode = !!options.objectMode;
  11065. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
  11066. // the point at which it stops calling _read() to fill the buffer
  11067. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  11068. var hwm = options.highWaterMark;
  11069. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  11070. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  11071. // cast to ints.
  11072. this.highWaterMark = ~ ~this.highWaterMark;
  11073. this.buffer = [];
  11074. this.length = 0;
  11075. this.pipes = null;
  11076. this.pipesCount = 0;
  11077. this.flowing = null;
  11078. this.ended = false;
  11079. this.endEmitted = false;
  11080. this.reading = false;
  11081. // a flag to be able to tell if the onwrite cb is called immediately,
  11082. // or on a later tick. We set this to true at first, because any
  11083. // actions that shouldn't happen until "later" should generally also
  11084. // not happen before the first write call.
  11085. this.sync = true;
  11086. // whenever we return null, then we set a flag to say
  11087. // that we're awaiting a 'readable' event emission.
  11088. this.needReadable = false;
  11089. this.emittedReadable = false;
  11090. this.readableListening = false;
  11091. this.resumeScheduled = false;
  11092. // Crypto is kind of old and crusty. Historically, its default string
  11093. // encoding is 'binary' so we have to make this configurable.
  11094. // Everything else in the universe uses 'utf8', though.
  11095. this.defaultEncoding = options.defaultEncoding || 'utf8';
  11096. // when piping, we only care about 'readable' events that happen
  11097. // after read()ing all the bytes and not getting any pushback.
  11098. this.ranOut = false;
  11099. // the number of writers that are awaiting a drain event in .pipe()s
  11100. this.awaitDrain = 0;
  11101. // if true, a maybeReadMore has been scheduled
  11102. this.readingMore = false;
  11103. this.decoder = null;
  11104. this.encoding = null;
  11105. if (options.encoding) {
  11106. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  11107. this.decoder = new StringDecoder(options.encoding);
  11108. this.encoding = options.encoding;
  11109. }
  11110. }
  11111. var Duplex;
  11112. function Readable(options) {
  11113. Duplex = Duplex || require('./_stream_duplex');
  11114. if (!(this instanceof Readable)) return new Readable(options);
  11115. this._readableState = new ReadableState(options, this);
  11116. // legacy
  11117. this.readable = true;
  11118. if (options && typeof options.read === 'function') this._read = options.read;
  11119. Stream.call(this);
  11120. }
  11121. // Manually shove something into the read() buffer.
  11122. // This returns true if the highWaterMark has not been hit yet,
  11123. // similar to how Writable.write() returns true if you should
  11124. // write() some more.
  11125. Readable.prototype.push = function (chunk, encoding) {
  11126. var state = this._readableState;
  11127. if (!state.objectMode && typeof chunk === 'string') {
  11128. encoding = encoding || state.defaultEncoding;
  11129. if (encoding !== state.encoding) {
  11130. chunk = bufferShim.from(chunk, encoding);
  11131. encoding = '';
  11132. }
  11133. }
  11134. return readableAddChunk(this, state, chunk, encoding, false);
  11135. };
  11136. // Unshift should *always* be something directly out of read()
  11137. Readable.prototype.unshift = function (chunk) {
  11138. var state = this._readableState;
  11139. return readableAddChunk(this, state, chunk, '', true);
  11140. };
  11141. Readable.prototype.isPaused = function () {
  11142. return this._readableState.flowing === false;
  11143. };
  11144. function readableAddChunk(stream, state, chunk, encoding, addToFront) {
  11145. var er = chunkInvalid(state, chunk);
  11146. if (er) {
  11147. stream.emit('error', er);
  11148. } else if (chunk === null) {
  11149. state.reading = false;
  11150. onEofChunk(stream, state);
  11151. } else if (state.objectMode || chunk && chunk.length > 0) {
  11152. if (state.ended && !addToFront) {
  11153. var e = new Error('stream.push() after EOF');
  11154. stream.emit('error', e);
  11155. } else if (state.endEmitted && addToFront) {
  11156. var _e = new Error('stream.unshift() after end event');
  11157. stream.emit('error', _e);
  11158. } else {
  11159. var skipAdd;
  11160. if (state.decoder && !addToFront && !encoding) {
  11161. chunk = state.decoder.write(chunk);
  11162. skipAdd = !state.objectMode && chunk.length === 0;
  11163. }
  11164. if (!addToFront) state.reading = false;
  11165. // Don't add to the buffer if we've decoded to an empty string chunk and
  11166. // we're not in object mode
  11167. if (!skipAdd) {
  11168. // if we want the data now, just emit it.
  11169. if (state.flowing && state.length === 0 && !state.sync) {
  11170. stream.emit('data', chunk);
  11171. stream.read(0);
  11172. } else {
  11173. // update the buffer info.
  11174. state.length += state.objectMode ? 1 : chunk.length;
  11175. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  11176. if (state.needReadable) emitReadable(stream);
  11177. }
  11178. }
  11179. maybeReadMore(stream, state);
  11180. }
  11181. } else if (!addToFront) {
  11182. state.reading = false;
  11183. }
  11184. return needMoreData(state);
  11185. }
  11186. // if it's past the high water mark, we can push in some more.
  11187. // Also, if we have no data yet, we can stand some
  11188. // more bytes. This is to work around cases where hwm=0,
  11189. // such as the repl. Also, if the push() triggered a
  11190. // readable event, and the user called read(largeNumber) such that
  11191. // needReadable was set, then we ought to push more, so that another
  11192. // 'readable' event will be triggered.
  11193. function needMoreData(state) {
  11194. return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
  11195. }
  11196. // backwards compatibility.
  11197. Readable.prototype.setEncoding = function (enc) {
  11198. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  11199. this._readableState.decoder = new StringDecoder(enc);
  11200. this._readableState.encoding = enc;
  11201. return this;
  11202. };
  11203. // Don't raise the hwm > 8MB
  11204. var MAX_HWM = 0x800000;
  11205. function computeNewHighWaterMark(n) {
  11206. if (n >= MAX_HWM) {
  11207. n = MAX_HWM;
  11208. } else {
  11209. // Get the next highest power of 2
  11210. n--;
  11211. n |= n >>> 1;
  11212. n |= n >>> 2;
  11213. n |= n >>> 4;
  11214. n |= n >>> 8;
  11215. n |= n >>> 16;
  11216. n++;
  11217. }
  11218. return n;
  11219. }
  11220. function howMuchToRead(n, state) {
  11221. if (state.length === 0 && state.ended) return 0;
  11222. if (state.objectMode) return n === 0 ? 0 : 1;
  11223. if (n === null || isNaN(n)) {
  11224. // only flow one buffer at a time
  11225. if (state.flowing && state.buffer.length) return state.buffer[0].length;else return state.length;
  11226. }
  11227. if (n <= 0) return 0;
  11228. // If we're asking for more than the target buffer level,
  11229. // then raise the water mark. Bump up to the next highest
  11230. // power of 2, to prevent increasing it excessively in tiny
  11231. // amounts.
  11232. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  11233. // don't have that much. return null, unless we've ended.
  11234. if (n > state.length) {
  11235. if (!state.ended) {
  11236. state.needReadable = true;
  11237. return 0;
  11238. } else {
  11239. return state.length;
  11240. }
  11241. }
  11242. return n;
  11243. }
  11244. // you can override either this method, or the async _read(n) below.
  11245. Readable.prototype.read = function (n) {
  11246. debug('read', n);
  11247. var state = this._readableState;
  11248. var nOrig = n;
  11249. if (typeof n !== 'number' || n > 0) state.emittedReadable = false;
  11250. // if we're doing read(0) to trigger a readable event, but we
  11251. // already have a bunch of data in the buffer, then just trigger
  11252. // the 'readable' event and move on.
  11253. if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
  11254. debug('read: emitReadable', state.length, state.ended);
  11255. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  11256. return null;
  11257. }
  11258. n = howMuchToRead(n, state);
  11259. // if we've ended, and we're now clear, then finish it up.
  11260. if (n === 0 && state.ended) {
  11261. if (state.length === 0) endReadable(this);
  11262. return null;
  11263. }
  11264. // All the actual chunk generation logic needs to be
  11265. // *below* the call to _read. The reason is that in certain
  11266. // synthetic stream cases, such as passthrough streams, _read
  11267. // may be a completely synchronous operation which may change
  11268. // the state of the read buffer, providing enough data when
  11269. // before there was *not* enough.
  11270. //
  11271. // So, the steps are:
  11272. // 1. Figure out what the state of things will be after we do
  11273. // a read from the buffer.
  11274. //
  11275. // 2. If that resulting state will trigger a _read, then call _read.
  11276. // Note that this may be asynchronous, or synchronous. Yes, it is
  11277. // deeply ugly to write APIs this way, but that still doesn't mean
  11278. // that the Readable class should behave improperly, as streams are
  11279. // designed to be sync/async agnostic.
  11280. // Take note if the _read call is sync or async (ie, if the read call
  11281. // has returned yet), so that we know whether or not it's safe to emit
  11282. // 'readable' etc.
  11283. //
  11284. // 3. Actually pull the requested chunks out of the buffer and return.
  11285. // if we need a readable event, then we need to do some reading.
  11286. var doRead = state.needReadable;
  11287. debug('need readable', doRead);
  11288. // if we currently have less than the highWaterMark, then also read some
  11289. if (state.length === 0 || state.length - n < state.highWaterMark) {
  11290. doRead = true;
  11291. debug('length less than watermark', doRead);
  11292. }
  11293. // however, if we've ended, then there's no point, and if we're already
  11294. // reading, then it's unnecessary.
  11295. if (state.ended || state.reading) {
  11296. doRead = false;
  11297. debug('reading or ended', doRead);
  11298. }
  11299. if (doRead) {
  11300. debug('do read');
  11301. state.reading = true;
  11302. state.sync = true;
  11303. // if the length is currently zero, then we *need* a readable event.
  11304. if (state.length === 0) state.needReadable = true;
  11305. // call internal read method
  11306. this._read(state.highWaterMark);
  11307. state.sync = false;
  11308. }
  11309. // If _read pushed data synchronously, then `reading` will be false,
  11310. // and we need to re-evaluate how much data we can return to the user.
  11311. if (doRead && !state.reading) n = howMuchToRead(nOrig, state);
  11312. var ret;
  11313. if (n > 0) ret = fromList(n, state);else ret = null;
  11314. if (ret === null) {
  11315. state.needReadable = true;
  11316. n = 0;
  11317. }
  11318. state.length -= n;
  11319. // If we have nothing in the buffer, then we want to know
  11320. // as soon as we *do* get something into the buffer.
  11321. if (state.length === 0 && !state.ended) state.needReadable = true;
  11322. // If we tried to read() past the EOF, then emit end on the next tick.
  11323. if (nOrig !== n && state.ended && state.length === 0) endReadable(this);
  11324. if (ret !== null) this.emit('data', ret);
  11325. return ret;
  11326. };
  11327. function chunkInvalid(state, chunk) {
  11328. var er = null;
  11329. if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
  11330. er = new TypeError('Invalid non-string/buffer chunk');
  11331. }
  11332. return er;
  11333. }
  11334. function onEofChunk(stream, state) {
  11335. if (state.ended) return;
  11336. if (state.decoder) {
  11337. var chunk = state.decoder.end();
  11338. if (chunk && chunk.length) {
  11339. state.buffer.push(chunk);
  11340. state.length += state.objectMode ? 1 : chunk.length;
  11341. }
  11342. }
  11343. state.ended = true;
  11344. // emit 'readable' now to make sure it gets picked up.
  11345. emitReadable(stream);
  11346. }
  11347. // Don't emit readable right away in sync mode, because this can trigger
  11348. // another read() call => stack overflow. This way, it might trigger
  11349. // a nextTick recursion warning, but that's not so bad.
  11350. function emitReadable(stream) {
  11351. var state = stream._readableState;
  11352. state.needReadable = false;
  11353. if (!state.emittedReadable) {
  11354. debug('emitReadable', state.flowing);
  11355. state.emittedReadable = true;
  11356. if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream);
  11357. }
  11358. }
  11359. function emitReadable_(stream) {
  11360. debug('emit readable');
  11361. stream.emit('readable');
  11362. flow(stream);
  11363. }
  11364. // at this point, the user has presumably seen the 'readable' event,
  11365. // and called read() to consume some data. that may have triggered
  11366. // in turn another _read(n) call, in which case reading = true if
  11367. // it's in progress.
  11368. // However, if we're not ended, or reading, and the length < hwm,
  11369. // then go ahead and try to read some more preemptively.
  11370. function maybeReadMore(stream, state) {
  11371. if (!state.readingMore) {
  11372. state.readingMore = true;
  11373. processNextTick(maybeReadMore_, stream, state);
  11374. }
  11375. }
  11376. function maybeReadMore_(stream, state) {
  11377. var len = state.length;
  11378. while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
  11379. debug('maybeReadMore read 0');
  11380. stream.read(0);
  11381. if (len === state.length)
  11382. // didn't get any data, stop spinning.
  11383. break;else len = state.length;
  11384. }
  11385. state.readingMore = false;
  11386. }
  11387. // abstract method. to be overridden in specific implementation classes.
  11388. // call cb(er, data) where data is <= n in length.
  11389. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  11390. // arbitrary, and perhaps not very meaningful.
  11391. Readable.prototype._read = function (n) {
  11392. this.emit('error', new Error('not implemented'));
  11393. };
  11394. Readable.prototype.pipe = function (dest, pipeOpts) {
  11395. var src = this;
  11396. var state = this._readableState;
  11397. switch (state.pipesCount) {
  11398. case 0:
  11399. state.pipes = dest;
  11400. break;
  11401. case 1:
  11402. state.pipes = [state.pipes, dest];
  11403. break;
  11404. default:
  11405. state.pipes.push(dest);
  11406. break;
  11407. }
  11408. state.pipesCount += 1;
  11409. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  11410. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  11411. var endFn = doEnd ? onend : cleanup;
  11412. if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn);
  11413. dest.on('unpipe', onunpipe);
  11414. function onunpipe(readable) {
  11415. debug('onunpipe');
  11416. if (readable === src) {
  11417. cleanup();
  11418. }
  11419. }
  11420. function onend() {
  11421. debug('onend');
  11422. dest.end();
  11423. }
  11424. // when the dest drains, it reduces the awaitDrain counter
  11425. // on the source. This would be more elegant with a .once()
  11426. // handler in flow(), but adding and removing repeatedly is
  11427. // too slow.
  11428. var ondrain = pipeOnDrain(src);
  11429. dest.on('drain', ondrain);
  11430. var cleanedUp = false;
  11431. function cleanup() {
  11432. debug('cleanup');
  11433. // cleanup event handlers once the pipe is broken
  11434. dest.removeListener('close', onclose);
  11435. dest.removeListener('finish', onfinish);
  11436. dest.removeListener('drain', ondrain);
  11437. dest.removeListener('error', onerror);
  11438. dest.removeListener('unpipe', onunpipe);
  11439. src.removeListener('end', onend);
  11440. src.removeListener('end', cleanup);
  11441. src.removeListener('data', ondata);
  11442. cleanedUp = true;
  11443. // if the reader is waiting for a drain event from this
  11444. // specific writer, then it would cause it to never start
  11445. // flowing again.
  11446. // So, if this is awaiting a drain, then we just call it now.
  11447. // If we don't know, then assume that we are waiting for one.
  11448. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  11449. }
  11450. src.on('data', ondata);
  11451. function ondata(chunk) {
  11452. debug('ondata');
  11453. var ret = dest.write(chunk);
  11454. if (false === ret) {
  11455. // If the user unpiped during `dest.write()`, it is possible
  11456. // to get stuck in a permanently paused state if that write
  11457. // also returned false.
  11458. // => Check whether `dest` is still a piping destination.
  11459. if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  11460. debug('false write response, pause', src._readableState.awaitDrain);
  11461. src._readableState.awaitDrain++;
  11462. }
  11463. src.pause();
  11464. }
  11465. }
  11466. // if the dest has an error, then stop piping into it.
  11467. // however, don't suppress the throwing behavior for this.
  11468. function onerror(er) {
  11469. debug('onerror', er);
  11470. unpipe();
  11471. dest.removeListener('error', onerror);
  11472. if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
  11473. }
  11474. // Make sure our error handler is attached before userland ones.
  11475. prependListener(dest, 'error', onerror);
  11476. // Both close and finish should trigger unpipe, but only once.
  11477. function onclose() {
  11478. dest.removeListener('finish', onfinish);
  11479. unpipe();
  11480. }
  11481. dest.once('close', onclose);
  11482. function onfinish() {
  11483. debug('onfinish');
  11484. dest.removeListener('close', onclose);
  11485. unpipe();
  11486. }
  11487. dest.once('finish', onfinish);
  11488. function unpipe() {
  11489. debug('unpipe');
  11490. src.unpipe(dest);
  11491. }
  11492. // tell the dest that it's being piped to
  11493. dest.emit('pipe', src);
  11494. // start the flow if it hasn't been started already.
  11495. if (!state.flowing) {
  11496. debug('pipe resume');
  11497. src.resume();
  11498. }
  11499. return dest;
  11500. };
  11501. function pipeOnDrain(src) {
  11502. return function () {
  11503. var state = src._readableState;
  11504. debug('pipeOnDrain', state.awaitDrain);
  11505. if (state.awaitDrain) state.awaitDrain--;
  11506. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  11507. state.flowing = true;
  11508. flow(src);
  11509. }
  11510. };
  11511. }
  11512. Readable.prototype.unpipe = function (dest) {
  11513. var state = this._readableState;
  11514. // if we're not piping anywhere, then do nothing.
  11515. if (state.pipesCount === 0) return this;
  11516. // just one destination. most common case.
  11517. if (state.pipesCount === 1) {
  11518. // passed in one, but it's not the right one.
  11519. if (dest && dest !== state.pipes) return this;
  11520. if (!dest) dest = state.pipes;
  11521. // got a match.
  11522. state.pipes = null;
  11523. state.pipesCount = 0;
  11524. state.flowing = false;
  11525. if (dest) dest.emit('unpipe', this);
  11526. return this;
  11527. }
  11528. // slow case. multiple pipe destinations.
  11529. if (!dest) {
  11530. // remove all.
  11531. var dests = state.pipes;
  11532. var len = state.pipesCount;
  11533. state.pipes = null;
  11534. state.pipesCount = 0;
  11535. state.flowing = false;
  11536. for (var _i = 0; _i < len; _i++) {
  11537. dests[_i].emit('unpipe', this);
  11538. }return this;
  11539. }
  11540. // try to find the right one.
  11541. var i = indexOf(state.pipes, dest);
  11542. if (i === -1) return this;
  11543. state.pipes.splice(i, 1);
  11544. state.pipesCount -= 1;
  11545. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  11546. dest.emit('unpipe', this);
  11547. return this;
  11548. };
  11549. // set up data events if they are asked for
  11550. // Ensure readable listeners eventually get something
  11551. Readable.prototype.on = function (ev, fn) {
  11552. var res = Stream.prototype.on.call(this, ev, fn);
  11553. // If listening to data, and it has not explicitly been paused,
  11554. // then call resume to start the flow of data on the next tick.
  11555. if (ev === 'data' && false !== this._readableState.flowing) {
  11556. this.resume();
  11557. }
  11558. if (ev === 'readable' && !this._readableState.endEmitted) {
  11559. var state = this._readableState;
  11560. if (!state.readableListening) {
  11561. state.readableListening = true;
  11562. state.emittedReadable = false;
  11563. state.needReadable = true;
  11564. if (!state.reading) {
  11565. processNextTick(nReadingNextTick, this);
  11566. } else if (state.length) {
  11567. emitReadable(this, state);
  11568. }
  11569. }
  11570. }
  11571. return res;
  11572. };
  11573. Readable.prototype.addListener = Readable.prototype.on;
  11574. function nReadingNextTick(self) {
  11575. debug('readable nexttick read 0');
  11576. self.read(0);
  11577. }
  11578. // pause() and resume() are remnants of the legacy readable stream API
  11579. // If the user uses them, then switch into old mode.
  11580. Readable.prototype.resume = function () {
  11581. var state = this._readableState;
  11582. if (!state.flowing) {
  11583. debug('resume');
  11584. state.flowing = true;
  11585. resume(this, state);
  11586. }
  11587. return this;
  11588. };
  11589. function resume(stream, state) {
  11590. if (!state.resumeScheduled) {
  11591. state.resumeScheduled = true;
  11592. processNextTick(resume_, stream, state);
  11593. }
  11594. }
  11595. function resume_(stream, state) {
  11596. if (!state.reading) {
  11597. debug('resume read 0');
  11598. stream.read(0);
  11599. }
  11600. state.resumeScheduled = false;
  11601. stream.emit('resume');
  11602. flow(stream);
  11603. if (state.flowing && !state.reading) stream.read(0);
  11604. }
  11605. Readable.prototype.pause = function () {
  11606. debug('call pause flowing=%j', this._readableState.flowing);
  11607. if (false !== this._readableState.flowing) {
  11608. debug('pause');
  11609. this._readableState.flowing = false;
  11610. this.emit('pause');
  11611. }
  11612. return this;
  11613. };
  11614. function flow(stream) {
  11615. var state = stream._readableState;
  11616. debug('flow', state.flowing);
  11617. if (state.flowing) {
  11618. do {
  11619. var chunk = stream.read();
  11620. } while (null !== chunk && state.flowing);
  11621. }
  11622. }
  11623. // wrap an old-style stream as the async data source.
  11624. // This is *not* part of the readable stream interface.
  11625. // It is an ugly unfortunate mess of history.
  11626. Readable.prototype.wrap = function (stream) {
  11627. var state = this._readableState;
  11628. var paused = false;
  11629. var self = this;
  11630. stream.on('end', function () {
  11631. debug('wrapped end');
  11632. if (state.decoder && !state.ended) {
  11633. var chunk = state.decoder.end();
  11634. if (chunk && chunk.length) self.push(chunk);
  11635. }
  11636. self.push(null);
  11637. });
  11638. stream.on('data', function (chunk) {
  11639. debug('wrapped data');
  11640. if (state.decoder) chunk = state.decoder.write(chunk);
  11641. // don't skip over falsy values in objectMode
  11642. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  11643. var ret = self.push(chunk);
  11644. if (!ret) {
  11645. paused = true;
  11646. stream.pause();
  11647. }
  11648. });
  11649. // proxy all the other methods.
  11650. // important when wrapping filters and duplexes.
  11651. for (var i in stream) {
  11652. if (this[i] === undefined && typeof stream[i] === 'function') {
  11653. this[i] = function (method) {
  11654. return function () {
  11655. return stream[method].apply(stream, arguments);
  11656. };
  11657. }(i);
  11658. }
  11659. }
  11660. // proxy certain important events.
  11661. var events = ['error', 'close', 'destroy', 'pause', 'resume'];
  11662. forEach(events, function (ev) {
  11663. stream.on(ev, self.emit.bind(self, ev));
  11664. });
  11665. // when we try to consume some more bytes, simply unpause the
  11666. // underlying stream.
  11667. self._read = function (n) {
  11668. debug('wrapped _read', n);
  11669. if (paused) {
  11670. paused = false;
  11671. stream.resume();
  11672. }
  11673. };
  11674. return self;
  11675. };
  11676. // exposed for testing purposes only.
  11677. Readable._fromList = fromList;
  11678. // Pluck off n bytes from an array of buffers.
  11679. // Length is the combined lengths of all the buffers in the list.
  11680. function fromList(n, state) {
  11681. var list = state.buffer;
  11682. var length = state.length;
  11683. var stringMode = !!state.decoder;
  11684. var objectMode = !!state.objectMode;
  11685. var ret;
  11686. // nothing in the list, definitely empty.
  11687. if (list.length === 0) return null;
  11688. if (length === 0) ret = null;else if (objectMode) ret = list.shift();else if (!n || n >= length) {
  11689. // read it all, truncate the array.
  11690. if (stringMode) ret = list.join('');else if (list.length === 1) ret = list[0];else ret = Buffer.concat(list, length);
  11691. list.length = 0;
  11692. } else {
  11693. // read just some of it.
  11694. if (n < list[0].length) {
  11695. // just take a part of the first list item.
  11696. // slice is the same for buffers and strings.
  11697. var buf = list[0];
  11698. ret = buf.slice(0, n);
  11699. list[0] = buf.slice(n);
  11700. } else if (n === list[0].length) {
  11701. // first list is a perfect match
  11702. ret = list.shift();
  11703. } else {
  11704. // complex case.
  11705. // we have enough to cover it, but it spans past the first buffer.
  11706. if (stringMode) ret = '';else ret = bufferShim.allocUnsafe(n);
  11707. var c = 0;
  11708. for (var i = 0, l = list.length; i < l && c < n; i++) {
  11709. var _buf = list[0];
  11710. var cpy = Math.min(n - c, _buf.length);
  11711. if (stringMode) ret += _buf.slice(0, cpy);else _buf.copy(ret, c, 0, cpy);
  11712. if (cpy < _buf.length) list[0] = _buf.slice(cpy);else list.shift();
  11713. c += cpy;
  11714. }
  11715. }
  11716. }
  11717. return ret;
  11718. }
  11719. function endReadable(stream) {
  11720. var state = stream._readableState;
  11721. // If we get here before consuming all the bytes, then that is a
  11722. // bug in node. Should never happen.
  11723. if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
  11724. if (!state.endEmitted) {
  11725. state.ended = true;
  11726. processNextTick(endReadableNT, state, stream);
  11727. }
  11728. }
  11729. function endReadableNT(state, stream) {
  11730. // Check that we didn't get one last unshift.
  11731. if (!state.endEmitted && state.length === 0) {
  11732. state.endEmitted = true;
  11733. stream.readable = false;
  11734. stream.emit('end');
  11735. }
  11736. }
  11737. function forEach(xs, f) {
  11738. for (var i = 0, l = xs.length; i < l; i++) {
  11739. f(xs[i], i);
  11740. }
  11741. }
  11742. function indexOf(xs, x) {
  11743. for (var i = 0, l = xs.length; i < l; i++) {
  11744. if (xs[i] === x) return i;
  11745. }
  11746. return -1;
  11747. }
  11748. }).call(this,require('_process'))
  11749. },{"./_stream_duplex":69,"_process":67,"buffer":44,"buffer-shims":43,"core-util-is":45,"events":48,"inherits":51,"isarray":53,"process-nextick-args":66,"string_decoder/":79,"util":40}],72:[function(require,module,exports){
  11750. // a transform stream is a readable/writable stream where you do
  11751. // something with the data. Sometimes it's called a "filter",
  11752. // but that's not a great name for it, since that implies a thing where
  11753. // some bits pass through, and others are simply ignored. (That would
  11754. // be a valid example of a transform, of course.)
  11755. //
  11756. // While the output is causally related to the input, it's not a
  11757. // necessarily symmetric or synchronous transformation. For example,
  11758. // a zlib stream might take multiple plain-text writes(), and then
  11759. // emit a single compressed chunk some time in the future.
  11760. //
  11761. // Here's how this works:
  11762. //
  11763. // The Transform stream has all the aspects of the readable and writable
  11764. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  11765. // internally, and returns false if there's a lot of pending writes
  11766. // buffered up. When you call read(), that calls _read(n) until
  11767. // there's enough pending readable data buffered up.
  11768. //
  11769. // In a transform stream, the written data is placed in a buffer. When
  11770. // _read(n) is called, it transforms the queued up data, calling the
  11771. // buffered _write cb's as it consumes chunks. If consuming a single
  11772. // written chunk would result in multiple output chunks, then the first
  11773. // outputted bit calls the readcb, and subsequent chunks just go into
  11774. // the read buffer, and will cause it to emit 'readable' if necessary.
  11775. //
  11776. // This way, back-pressure is actually determined by the reading side,
  11777. // since _read has to be called to start processing a new chunk. However,
  11778. // a pathological inflate type of transform can cause excessive buffering
  11779. // here. For example, imagine a stream where every byte of input is
  11780. // interpreted as an integer from 0-255, and then results in that many
  11781. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  11782. // 1kb of data being output. In this case, you could write a very small
  11783. // amount of input, and end up with a very large amount of output. In
  11784. // such a pathological inflating mechanism, there'd be no way to tell
  11785. // the system to stop doing the transform. A single 4MB write could
  11786. // cause the system to run out of memory.
  11787. //
  11788. // However, even in such a pathological case, only a single written chunk
  11789. // would be consumed, and then the rest would wait (un-transformed) until
  11790. // the results of the previous transformed chunk were consumed.
  11791. 'use strict';
  11792. module.exports = Transform;
  11793. var Duplex = require('./_stream_duplex');
  11794. /*<replacement>*/
  11795. var util = require('core-util-is');
  11796. util.inherits = require('inherits');
  11797. /*</replacement>*/
  11798. util.inherits(Transform, Duplex);
  11799. function TransformState(stream) {
  11800. this.afterTransform = function (er, data) {
  11801. return afterTransform(stream, er, data);
  11802. };
  11803. this.needTransform = false;
  11804. this.transforming = false;
  11805. this.writecb = null;
  11806. this.writechunk = null;
  11807. this.writeencoding = null;
  11808. }
  11809. function afterTransform(stream, er, data) {
  11810. var ts = stream._transformState;
  11811. ts.transforming = false;
  11812. var cb = ts.writecb;
  11813. if (!cb) return stream.emit('error', new Error('no writecb in Transform class'));
  11814. ts.writechunk = null;
  11815. ts.writecb = null;
  11816. if (data !== null && data !== undefined) stream.push(data);
  11817. cb(er);
  11818. var rs = stream._readableState;
  11819. rs.reading = false;
  11820. if (rs.needReadable || rs.length < rs.highWaterMark) {
  11821. stream._read(rs.highWaterMark);
  11822. }
  11823. }
  11824. function Transform(options) {
  11825. if (!(this instanceof Transform)) return new Transform(options);
  11826. Duplex.call(this, options);
  11827. this._transformState = new TransformState(this);
  11828. // when the writable side finishes, then flush out anything remaining.
  11829. var stream = this;
  11830. // start out asking for a readable event once data is transformed.
  11831. this._readableState.needReadable = true;
  11832. // we have implemented the _read method, and done the other things
  11833. // that Readable wants before the first _read call, so unset the
  11834. // sync guard flag.
  11835. this._readableState.sync = false;
  11836. if (options) {
  11837. if (typeof options.transform === 'function') this._transform = options.transform;
  11838. if (typeof options.flush === 'function') this._flush = options.flush;
  11839. }
  11840. this.once('prefinish', function () {
  11841. if (typeof this._flush === 'function') this._flush(function (er) {
  11842. done(stream, er);
  11843. });else done(stream);
  11844. });
  11845. }
  11846. Transform.prototype.push = function (chunk, encoding) {
  11847. this._transformState.needTransform = false;
  11848. return Duplex.prototype.push.call(this, chunk, encoding);
  11849. };
  11850. // This is the part where you do stuff!
  11851. // override this function in implementation classes.
  11852. // 'chunk' is an input chunk.
  11853. //
  11854. // Call `push(newChunk)` to pass along transformed output
  11855. // to the readable side. You may call 'push' zero or more times.
  11856. //
  11857. // Call `cb(err)` when you are done with this chunk. If you pass
  11858. // an error, then that'll put the hurt on the whole operation. If you
  11859. // never call cb(), then you'll never get another chunk.
  11860. Transform.prototype._transform = function (chunk, encoding, cb) {
  11861. throw new Error('Not implemented');
  11862. };
  11863. Transform.prototype._write = function (chunk, encoding, cb) {
  11864. var ts = this._transformState;
  11865. ts.writecb = cb;
  11866. ts.writechunk = chunk;
  11867. ts.writeencoding = encoding;
  11868. if (!ts.transforming) {
  11869. var rs = this._readableState;
  11870. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  11871. }
  11872. };
  11873. // Doesn't matter what the args are here.
  11874. // _transform does all the work.
  11875. // That we got here means that the readable side wants more data.
  11876. Transform.prototype._read = function (n) {
  11877. var ts = this._transformState;
  11878. if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
  11879. ts.transforming = true;
  11880. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  11881. } else {
  11882. // mark that we need a transform, so that any data that comes in
  11883. // will get processed, now that we've asked for it.
  11884. ts.needTransform = true;
  11885. }
  11886. };
  11887. function done(stream, er) {
  11888. if (er) return stream.emit('error', er);
  11889. // if there's nothing in the write buffer, then that means
  11890. // that nothing more will ever be provided
  11891. var ws = stream._writableState;
  11892. var ts = stream._transformState;
  11893. if (ws.length) throw new Error('Calling transform done when ws.length != 0');
  11894. if (ts.transforming) throw new Error('Calling transform done when still transforming');
  11895. return stream.push(null);
  11896. }
  11897. },{"./_stream_duplex":69,"core-util-is":45,"inherits":51}],73:[function(require,module,exports){
  11898. (function (process){
  11899. // A bit simpler than readable streams.
  11900. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  11901. // the drain event emission and buffering.
  11902. 'use strict';
  11903. module.exports = Writable;
  11904. /*<replacement>*/
  11905. var processNextTick = require('process-nextick-args');
  11906. /*</replacement>*/
  11907. /*<replacement>*/
  11908. var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick;
  11909. /*</replacement>*/
  11910. Writable.WritableState = WritableState;
  11911. /*<replacement>*/
  11912. var util = require('core-util-is');
  11913. util.inherits = require('inherits');
  11914. /*</replacement>*/
  11915. /*<replacement>*/
  11916. var internalUtil = {
  11917. deprecate: require('util-deprecate')
  11918. };
  11919. /*</replacement>*/
  11920. /*<replacement>*/
  11921. var Stream;
  11922. (function () {
  11923. try {
  11924. Stream = require('st' + 'ream');
  11925. } catch (_) {} finally {
  11926. if (!Stream) Stream = require('events').EventEmitter;
  11927. }
  11928. })();
  11929. /*</replacement>*/
  11930. var Buffer = require('buffer').Buffer;
  11931. /*<replacement>*/
  11932. var bufferShim = require('buffer-shims');
  11933. /*</replacement>*/
  11934. util.inherits(Writable, Stream);
  11935. function nop() {}
  11936. function WriteReq(chunk, encoding, cb) {
  11937. this.chunk = chunk;
  11938. this.encoding = encoding;
  11939. this.callback = cb;
  11940. this.next = null;
  11941. }
  11942. var Duplex;
  11943. function WritableState(options, stream) {
  11944. Duplex = Duplex || require('./_stream_duplex');
  11945. options = options || {};
  11946. // object stream flag to indicate whether or not this stream
  11947. // contains buffers or objects.
  11948. this.objectMode = !!options.objectMode;
  11949. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
  11950. // the point at which write() starts returning false
  11951. // Note: 0 is a valid value, means that we always return false if
  11952. // the entire buffer is not flushed immediately on write()
  11953. var hwm = options.highWaterMark;
  11954. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  11955. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  11956. // cast to ints.
  11957. this.highWaterMark = ~ ~this.highWaterMark;
  11958. this.needDrain = false;
  11959. // at the start of calling end()
  11960. this.ending = false;
  11961. // when end() has been called, and returned
  11962. this.ended = false;
  11963. // when 'finish' is emitted
  11964. this.finished = false;
  11965. // should we decode strings into buffers before passing to _write?
  11966. // this is here so that some node-core streams can optimize string
  11967. // handling at a lower level.
  11968. var noDecode = options.decodeStrings === false;
  11969. this.decodeStrings = !noDecode;
  11970. // Crypto is kind of old and crusty. Historically, its default string
  11971. // encoding is 'binary' so we have to make this configurable.
  11972. // Everything else in the universe uses 'utf8', though.
  11973. this.defaultEncoding = options.defaultEncoding || 'utf8';
  11974. // not an actual buffer we keep track of, but a measurement
  11975. // of how much we're waiting to get pushed to some underlying
  11976. // socket or file.
  11977. this.length = 0;
  11978. // a flag to see when we're in the middle of a write.
  11979. this.writing = false;
  11980. // when true all writes will be buffered until .uncork() call
  11981. this.corked = 0;
  11982. // a flag to be able to tell if the onwrite cb is called immediately,
  11983. // or on a later tick. We set this to true at first, because any
  11984. // actions that shouldn't happen until "later" should generally also
  11985. // not happen before the first write call.
  11986. this.sync = true;
  11987. // a flag to know if we're processing previously buffered items, which
  11988. // may call the _write() callback in the same tick, so that we don't
  11989. // end up in an overlapped onwrite situation.
  11990. this.bufferProcessing = false;
  11991. // the callback that's passed to _write(chunk,cb)
  11992. this.onwrite = function (er) {
  11993. onwrite(stream, er);
  11994. };
  11995. // the callback that the user supplies to write(chunk,encoding,cb)
  11996. this.writecb = null;
  11997. // the amount that is being written when _write is called.
  11998. this.writelen = 0;
  11999. this.bufferedRequest = null;
  12000. this.lastBufferedRequest = null;
  12001. // number of pending user-supplied write callbacks
  12002. // this must be 0 before 'finish' can be emitted
  12003. this.pendingcb = 0;
  12004. // emit prefinish if the only thing we're waiting for is _write cbs
  12005. // This is relevant for synchronous Transform streams
  12006. this.prefinished = false;
  12007. // True if the error was already emitted and should not be thrown again
  12008. this.errorEmitted = false;
  12009. // count buffered requests
  12010. this.bufferedRequestCount = 0;
  12011. // allocate the first CorkedRequest, there is always
  12012. // one allocated and free to use, and we maintain at most two
  12013. this.corkedRequestsFree = new CorkedRequest(this);
  12014. }
  12015. WritableState.prototype.getBuffer = function writableStateGetBuffer() {
  12016. var current = this.bufferedRequest;
  12017. var out = [];
  12018. while (current) {
  12019. out.push(current);
  12020. current = current.next;
  12021. }
  12022. return out;
  12023. };
  12024. (function () {
  12025. try {
  12026. Object.defineProperty(WritableState.prototype, 'buffer', {
  12027. get: internalUtil.deprecate(function () {
  12028. return this.getBuffer();
  12029. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
  12030. });
  12031. } catch (_) {}
  12032. })();
  12033. var Duplex;
  12034. function Writable(options) {
  12035. Duplex = Duplex || require('./_stream_duplex');
  12036. // Writable ctor is applied to Duplexes, though they're not
  12037. // instanceof Writable, they're instanceof Readable.
  12038. if (!(this instanceof Writable) && !(this instanceof Duplex)) return new Writable(options);
  12039. this._writableState = new WritableState(options, this);
  12040. // legacy.
  12041. this.writable = true;
  12042. if (options) {
  12043. if (typeof options.write === 'function') this._write = options.write;
  12044. if (typeof options.writev === 'function') this._writev = options.writev;
  12045. }
  12046. Stream.call(this);
  12047. }
  12048. // Otherwise people can pipe Writable streams, which is just wrong.
  12049. Writable.prototype.pipe = function () {
  12050. this.emit('error', new Error('Cannot pipe, not readable'));
  12051. };
  12052. function writeAfterEnd(stream, cb) {
  12053. var er = new Error('write after end');
  12054. // TODO: defer error events consistently everywhere, not just the cb
  12055. stream.emit('error', er);
  12056. processNextTick(cb, er);
  12057. }
  12058. // If we get something that is not a buffer, string, null, or undefined,
  12059. // and we're not in objectMode, then that's an error.
  12060. // Otherwise stream chunks are all considered to be of length=1, and the
  12061. // watermarks determine how many objects to keep in the buffer, rather than
  12062. // how many bytes or characters.
  12063. function validChunk(stream, state, chunk, cb) {
  12064. var valid = true;
  12065. var er = false;
  12066. // Always throw error if a null is written
  12067. // if we are not in object mode then throw
  12068. // if it is not a buffer, string, or undefined.
  12069. if (chunk === null) {
  12070. er = new TypeError('May not write null values to stream');
  12071. } else if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  12072. er = new TypeError('Invalid non-string/buffer chunk');
  12073. }
  12074. if (er) {
  12075. stream.emit('error', er);
  12076. processNextTick(cb, er);
  12077. valid = false;
  12078. }
  12079. return valid;
  12080. }
  12081. Writable.prototype.write = function (chunk, encoding, cb) {
  12082. var state = this._writableState;
  12083. var ret = false;
  12084. if (typeof encoding === 'function') {
  12085. cb = encoding;
  12086. encoding = null;
  12087. }
  12088. if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  12089. if (typeof cb !== 'function') cb = nop;
  12090. if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) {
  12091. state.pendingcb++;
  12092. ret = writeOrBuffer(this, state, chunk, encoding, cb);
  12093. }
  12094. return ret;
  12095. };
  12096. Writable.prototype.cork = function () {
  12097. var state = this._writableState;
  12098. state.corked++;
  12099. };
  12100. Writable.prototype.uncork = function () {
  12101. var state = this._writableState;
  12102. if (state.corked) {
  12103. state.corked--;
  12104. if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  12105. }
  12106. };
  12107. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  12108. // node::ParseEncoding() requires lower case.
  12109. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  12110. 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);
  12111. this._writableState.defaultEncoding = encoding;
  12112. return this;
  12113. };
  12114. function decodeChunk(state, chunk, encoding) {
  12115. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  12116. chunk = bufferShim.from(chunk, encoding);
  12117. }
  12118. return chunk;
  12119. }
  12120. // if we're already writing something, then just put this
  12121. // in the queue, and wait our turn. Otherwise, call _write
  12122. // If we return false, then we need a drain event, so set that flag.
  12123. function writeOrBuffer(stream, state, chunk, encoding, cb) {
  12124. chunk = decodeChunk(state, chunk, encoding);
  12125. if (Buffer.isBuffer(chunk)) encoding = 'buffer';
  12126. var len = state.objectMode ? 1 : chunk.length;
  12127. state.length += len;
  12128. var ret = state.length < state.highWaterMark;
  12129. // we must ensure that previous needDrain will not be reset to false.
  12130. if (!ret) state.needDrain = true;
  12131. if (state.writing || state.corked) {
  12132. var last = state.lastBufferedRequest;
  12133. state.lastBufferedRequest = new WriteReq(chunk, encoding, cb);
  12134. if (last) {
  12135. last.next = state.lastBufferedRequest;
  12136. } else {
  12137. state.bufferedRequest = state.lastBufferedRequest;
  12138. }
  12139. state.bufferedRequestCount += 1;
  12140. } else {
  12141. doWrite(stream, state, false, len, chunk, encoding, cb);
  12142. }
  12143. return ret;
  12144. }
  12145. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  12146. state.writelen = len;
  12147. state.writecb = cb;
  12148. state.writing = true;
  12149. state.sync = true;
  12150. if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  12151. state.sync = false;
  12152. }
  12153. function onwriteError(stream, state, sync, er, cb) {
  12154. --state.pendingcb;
  12155. if (sync) processNextTick(cb, er);else cb(er);
  12156. stream._writableState.errorEmitted = true;
  12157. stream.emit('error', er);
  12158. }
  12159. function onwriteStateUpdate(state) {
  12160. state.writing = false;
  12161. state.writecb = null;
  12162. state.length -= state.writelen;
  12163. state.writelen = 0;
  12164. }
  12165. function onwrite(stream, er) {
  12166. var state = stream._writableState;
  12167. var sync = state.sync;
  12168. var cb = state.writecb;
  12169. onwriteStateUpdate(state);
  12170. if (er) onwriteError(stream, state, sync, er, cb);else {
  12171. // Check if we're actually ready to finish, but don't emit yet
  12172. var finished = needFinish(state);
  12173. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  12174. clearBuffer(stream, state);
  12175. }
  12176. if (sync) {
  12177. /*<replacement>*/
  12178. asyncWrite(afterWrite, stream, state, finished, cb);
  12179. /*</replacement>*/
  12180. } else {
  12181. afterWrite(stream, state, finished, cb);
  12182. }
  12183. }
  12184. }
  12185. function afterWrite(stream, state, finished, cb) {
  12186. if (!finished) onwriteDrain(stream, state);
  12187. state.pendingcb--;
  12188. cb();
  12189. finishMaybe(stream, state);
  12190. }
  12191. // Must force callback to be called on nextTick, so that we don't
  12192. // emit 'drain' before the write() consumer gets the 'false' return
  12193. // value, and has a chance to attach a 'drain' listener.
  12194. function onwriteDrain(stream, state) {
  12195. if (state.length === 0 && state.needDrain) {
  12196. state.needDrain = false;
  12197. stream.emit('drain');
  12198. }
  12199. }
  12200. // if there's something in the buffer waiting, then process it
  12201. function clearBuffer(stream, state) {
  12202. state.bufferProcessing = true;
  12203. var entry = state.bufferedRequest;
  12204. if (stream._writev && entry && entry.next) {
  12205. // Fast case, write everything using _writev()
  12206. var l = state.bufferedRequestCount;
  12207. var buffer = new Array(l);
  12208. var holder = state.corkedRequestsFree;
  12209. holder.entry = entry;
  12210. var count = 0;
  12211. while (entry) {
  12212. buffer[count] = entry;
  12213. entry = entry.next;
  12214. count += 1;
  12215. }
  12216. doWrite(stream, state, true, state.length, buffer, '', holder.finish);
  12217. // doWrite is almost always async, defer these to save a bit of time
  12218. // as the hot path ends with doWrite
  12219. state.pendingcb++;
  12220. state.lastBufferedRequest = null;
  12221. if (holder.next) {
  12222. state.corkedRequestsFree = holder.next;
  12223. holder.next = null;
  12224. } else {
  12225. state.corkedRequestsFree = new CorkedRequest(state);
  12226. }
  12227. } else {
  12228. // Slow case, write chunks one-by-one
  12229. while (entry) {
  12230. var chunk = entry.chunk;
  12231. var encoding = entry.encoding;
  12232. var cb = entry.callback;
  12233. var len = state.objectMode ? 1 : chunk.length;
  12234. doWrite(stream, state, false, len, chunk, encoding, cb);
  12235. entry = entry.next;
  12236. // if we didn't call the onwrite immediately, then
  12237. // it means that we need to wait until it does.
  12238. // also, that means that the chunk and cb are currently
  12239. // being processed, so move the buffer counter past them.
  12240. if (state.writing) {
  12241. break;
  12242. }
  12243. }
  12244. if (entry === null) state.lastBufferedRequest = null;
  12245. }
  12246. state.bufferedRequestCount = 0;
  12247. state.bufferedRequest = entry;
  12248. state.bufferProcessing = false;
  12249. }
  12250. Writable.prototype._write = function (chunk, encoding, cb) {
  12251. cb(new Error('not implemented'));
  12252. };
  12253. Writable.prototype._writev = null;
  12254. Writable.prototype.end = function (chunk, encoding, cb) {
  12255. var state = this._writableState;
  12256. if (typeof chunk === 'function') {
  12257. cb = chunk;
  12258. chunk = null;
  12259. encoding = null;
  12260. } else if (typeof encoding === 'function') {
  12261. cb = encoding;
  12262. encoding = null;
  12263. }
  12264. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
  12265. // .end() fully uncorks
  12266. if (state.corked) {
  12267. state.corked = 1;
  12268. this.uncork();
  12269. }
  12270. // ignore unnecessary end() calls.
  12271. if (!state.ending && !state.finished) endWritable(this, state, cb);
  12272. };
  12273. function needFinish(state) {
  12274. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  12275. }
  12276. function prefinish(stream, state) {
  12277. if (!state.prefinished) {
  12278. state.prefinished = true;
  12279. stream.emit('prefinish');
  12280. }
  12281. }
  12282. function finishMaybe(stream, state) {
  12283. var need = needFinish(state);
  12284. if (need) {
  12285. if (state.pendingcb === 0) {
  12286. prefinish(stream, state);
  12287. state.finished = true;
  12288. stream.emit('finish');
  12289. } else {
  12290. prefinish(stream, state);
  12291. }
  12292. }
  12293. return need;
  12294. }
  12295. function endWritable(stream, state, cb) {
  12296. state.ending = true;
  12297. finishMaybe(stream, state);
  12298. if (cb) {
  12299. if (state.finished) processNextTick(cb);else stream.once('finish', cb);
  12300. }
  12301. state.ended = true;
  12302. stream.writable = false;
  12303. }
  12304. // It seems a linked list but it is not
  12305. // there will be only 2 of these for each stream
  12306. function CorkedRequest(state) {
  12307. var _this = this;
  12308. this.next = null;
  12309. this.entry = null;
  12310. this.finish = function (err) {
  12311. var entry = _this.entry;
  12312. _this.entry = null;
  12313. while (entry) {
  12314. var cb = entry.callback;
  12315. state.pendingcb--;
  12316. cb(err);
  12317. entry = entry.next;
  12318. }
  12319. if (state.corkedRequestsFree) {
  12320. state.corkedRequestsFree.next = _this;
  12321. } else {
  12322. state.corkedRequestsFree = _this;
  12323. }
  12324. };
  12325. }
  12326. }).call(this,require('_process'))
  12327. },{"./_stream_duplex":69,"_process":67,"buffer":44,"buffer-shims":43,"core-util-is":45,"events":48,"inherits":51,"process-nextick-args":66,"util-deprecate":80}],74:[function(require,module,exports){
  12328. module.exports = require("./lib/_stream_passthrough.js")
  12329. },{"./lib/_stream_passthrough.js":70}],75:[function(require,module,exports){
  12330. (function (process){
  12331. var Stream = (function (){
  12332. try {
  12333. return require('st' + 'ream'); // hack to fix a circular dependency issue when used with browserify
  12334. } catch(_){}
  12335. }());
  12336. exports = module.exports = require('./lib/_stream_readable.js');
  12337. exports.Stream = Stream || exports;
  12338. exports.Readable = exports;
  12339. exports.Writable = require('./lib/_stream_writable.js');
  12340. exports.Duplex = require('./lib/_stream_duplex.js');
  12341. exports.Transform = require('./lib/_stream_transform.js');
  12342. exports.PassThrough = require('./lib/_stream_passthrough.js');
  12343. if (!process.browser && process.env.READABLE_STREAM === 'disable' && Stream) {
  12344. module.exports = Stream;
  12345. }
  12346. }).call(this,require('_process'))
  12347. },{"./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}],76:[function(require,module,exports){
  12348. module.exports = require("./lib/_stream_transform.js")
  12349. },{"./lib/_stream_transform.js":72}],77:[function(require,module,exports){
  12350. module.exports = require("./lib/_stream_writable.js")
  12351. },{"./lib/_stream_writable.js":73}],78:[function(require,module,exports){
  12352. // Copyright Joyent, Inc. and other Node contributors.
  12353. //
  12354. // Permission is hereby granted, free of charge, to any person obtaining a
  12355. // copy of this software and associated documentation files (the
  12356. // "Software"), to deal in the Software without restriction, including
  12357. // without limitation the rights to use, copy, modify, merge, publish,
  12358. // distribute, sublicense, and/or sell copies of the Software, and to permit
  12359. // persons to whom the Software is furnished to do so, subject to the
  12360. // following conditions:
  12361. //
  12362. // The above copyright notice and this permission notice shall be included
  12363. // in all copies or substantial portions of the Software.
  12364. //
  12365. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  12366. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12367. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  12368. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  12369. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  12370. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  12371. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  12372. module.exports = Stream;
  12373. var EE = require('events').EventEmitter;
  12374. var inherits = require('inherits');
  12375. inherits(Stream, EE);
  12376. Stream.Readable = require('readable-stream/readable.js');
  12377. Stream.Writable = require('readable-stream/writable.js');
  12378. Stream.Duplex = require('readable-stream/duplex.js');
  12379. Stream.Transform = require('readable-stream/transform.js');
  12380. Stream.PassThrough = require('readable-stream/passthrough.js');
  12381. // Backwards-compat with node 0.4.x
  12382. Stream.Stream = Stream;
  12383. // old-style streams. Note that the pipe method (the only relevant
  12384. // part of this class) is overridden in the Readable class.
  12385. function Stream() {
  12386. EE.call(this);
  12387. }
  12388. Stream.prototype.pipe = function(dest, options) {
  12389. var source = this;
  12390. function ondata(chunk) {
  12391. if (dest.writable) {
  12392. if (false === dest.write(chunk) && source.pause) {
  12393. source.pause();
  12394. }
  12395. }
  12396. }
  12397. source.on('data', ondata);
  12398. function ondrain() {
  12399. if (source.readable && source.resume) {
  12400. source.resume();
  12401. }
  12402. }
  12403. dest.on('drain', ondrain);
  12404. // If the 'end' option is not supplied, dest.end() will be called when
  12405. // source gets the 'end' or 'close' events. Only dest.end() once.
  12406. if (!dest._isStdio && (!options || options.end !== false)) {
  12407. source.on('end', onend);
  12408. source.on('close', onclose);
  12409. }
  12410. var didOnEnd = false;
  12411. function onend() {
  12412. if (didOnEnd) return;
  12413. didOnEnd = true;
  12414. dest.end();
  12415. }
  12416. function onclose() {
  12417. if (didOnEnd) return;
  12418. didOnEnd = true;
  12419. if (typeof dest.destroy === 'function') dest.destroy();
  12420. }
  12421. // don't leave dangling pipes when there are errors.
  12422. function onerror(er) {
  12423. cleanup();
  12424. if (EE.listenerCount(this, 'error') === 0) {
  12425. throw er; // Unhandled stream error in pipe.
  12426. }
  12427. }
  12428. source.on('error', onerror);
  12429. dest.on('error', onerror);
  12430. // remove all the event listeners that were added.
  12431. function cleanup() {
  12432. source.removeListener('data', ondata);
  12433. dest.removeListener('drain', ondrain);
  12434. source.removeListener('end', onend);
  12435. source.removeListener('close', onclose);
  12436. source.removeListener('error', onerror);
  12437. dest.removeListener('error', onerror);
  12438. source.removeListener('end', cleanup);
  12439. source.removeListener('close', cleanup);
  12440. dest.removeListener('close', cleanup);
  12441. }
  12442. source.on('end', cleanup);
  12443. source.on('close', cleanup);
  12444. dest.on('close', cleanup);
  12445. dest.emit('pipe', source);
  12446. // Allow for unix-like usage: A.pipe(B).pipe(C)
  12447. return dest;
  12448. };
  12449. },{"events":48,"inherits":51,"readable-stream/duplex.js":68,"readable-stream/passthrough.js":74,"readable-stream/readable.js":75,"readable-stream/transform.js":76,"readable-stream/writable.js":77}],79:[function(require,module,exports){
  12450. // Copyright Joyent, Inc. and other Node contributors.
  12451. //
  12452. // Permission is hereby granted, free of charge, to any person obtaining a
  12453. // copy of this software and associated documentation files (the
  12454. // "Software"), to deal in the Software without restriction, including
  12455. // without limitation the rights to use, copy, modify, merge, publish,
  12456. // distribute, sublicense, and/or sell copies of the Software, and to permit
  12457. // persons to whom the Software is furnished to do so, subject to the
  12458. // following conditions:
  12459. //
  12460. // The above copyright notice and this permission notice shall be included
  12461. // in all copies or substantial portions of the Software.
  12462. //
  12463. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  12464. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12465. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  12466. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  12467. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  12468. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  12469. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  12470. var Buffer = require('buffer').Buffer;
  12471. var isBufferEncoding = Buffer.isEncoding
  12472. || function(encoding) {
  12473. switch (encoding && encoding.toLowerCase()) {
  12474. 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;
  12475. default: return false;
  12476. }
  12477. }
  12478. function assertEncoding(encoding) {
  12479. if (encoding && !isBufferEncoding(encoding)) {
  12480. throw new Error('Unknown encoding: ' + encoding);
  12481. }
  12482. }
  12483. // StringDecoder provides an interface for efficiently splitting a series of
  12484. // buffers into a series of JS strings without breaking apart multi-byte
  12485. // characters. CESU-8 is handled as part of the UTF-8 encoding.
  12486. //
  12487. // @TODO Handling all encodings inside a single object makes it very difficult
  12488. // to reason about this code, so it should be split up in the future.
  12489. // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
  12490. // points as used by CESU-8.
  12491. var StringDecoder = exports.StringDecoder = function(encoding) {
  12492. this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
  12493. assertEncoding(encoding);
  12494. switch (this.encoding) {
  12495. case 'utf8':
  12496. // CESU-8 represents each of Surrogate Pair by 3-bytes
  12497. this.surrogateSize = 3;
  12498. break;
  12499. case 'ucs2':
  12500. case 'utf16le':
  12501. // UTF-16 represents each of Surrogate Pair by 2-bytes
  12502. this.surrogateSize = 2;
  12503. this.detectIncompleteChar = utf16DetectIncompleteChar;
  12504. break;
  12505. case 'base64':
  12506. // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
  12507. this.surrogateSize = 3;
  12508. this.detectIncompleteChar = base64DetectIncompleteChar;
  12509. break;
  12510. default:
  12511. this.write = passThroughWrite;
  12512. return;
  12513. }
  12514. // Enough space to store all bytes of a single character. UTF-8 needs 4
  12515. // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
  12516. this.charBuffer = new Buffer(6);
  12517. // Number of bytes received for the current incomplete multi-byte character.
  12518. this.charReceived = 0;
  12519. // Number of bytes expected for the current incomplete multi-byte character.
  12520. this.charLength = 0;
  12521. };
  12522. // write decodes the given buffer and returns it as JS string that is
  12523. // guaranteed to not contain any partial multi-byte characters. Any partial
  12524. // character found at the end of the buffer is buffered up, and will be
  12525. // returned when calling write again with the remaining bytes.
  12526. //
  12527. // Note: Converting a Buffer containing an orphan surrogate to a String
  12528. // currently works, but converting a String to a Buffer (via `new Buffer`, or
  12529. // Buffer#write) will replace incomplete surrogates with the unicode
  12530. // replacement character. See https://codereview.chromium.org/121173009/ .
  12531. StringDecoder.prototype.write = function(buffer) {
  12532. var charStr = '';
  12533. // if our last write ended with an incomplete multibyte character
  12534. while (this.charLength) {
  12535. // determine how many remaining bytes this buffer has to offer for this char
  12536. var available = (buffer.length >= this.charLength - this.charReceived) ?
  12537. this.charLength - this.charReceived :
  12538. buffer.length;
  12539. // add the new bytes to the char buffer
  12540. buffer.copy(this.charBuffer, this.charReceived, 0, available);
  12541. this.charReceived += available;
  12542. if (this.charReceived < this.charLength) {
  12543. // still not enough chars in this buffer? wait for more ...
  12544. return '';
  12545. }
  12546. // remove bytes belonging to the current character from the buffer
  12547. buffer = buffer.slice(available, buffer.length);
  12548. // get the character that was split
  12549. charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
  12550. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  12551. var charCode = charStr.charCodeAt(charStr.length - 1);
  12552. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  12553. this.charLength += this.surrogateSize;
  12554. charStr = '';
  12555. continue;
  12556. }
  12557. this.charReceived = this.charLength = 0;
  12558. // if there are no more bytes in this buffer, just emit our char
  12559. if (buffer.length === 0) {
  12560. return charStr;
  12561. }
  12562. break;
  12563. }
  12564. // determine and set charLength / charReceived
  12565. this.detectIncompleteChar(buffer);
  12566. var end = buffer.length;
  12567. if (this.charLength) {
  12568. // buffer the incomplete character bytes we got
  12569. buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
  12570. end -= this.charReceived;
  12571. }
  12572. charStr += buffer.toString(this.encoding, 0, end);
  12573. var end = charStr.length - 1;
  12574. var charCode = charStr.charCodeAt(end);
  12575. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  12576. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  12577. var size = this.surrogateSize;
  12578. this.charLength += size;
  12579. this.charReceived += size;
  12580. this.charBuffer.copy(this.charBuffer, size, 0, size);
  12581. buffer.copy(this.charBuffer, 0, 0, size);
  12582. return charStr.substring(0, end);
  12583. }
  12584. // or just emit the charStr
  12585. return charStr;
  12586. };
  12587. // detectIncompleteChar determines if there is an incomplete UTF-8 character at
  12588. // the end of the given buffer. If so, it sets this.charLength to the byte
  12589. // length that character, and sets this.charReceived to the number of bytes
  12590. // that are available for this character.
  12591. StringDecoder.prototype.detectIncompleteChar = function(buffer) {
  12592. // determine how many bytes we have to check at the end of this buffer
  12593. var i = (buffer.length >= 3) ? 3 : buffer.length;
  12594. // Figure out if one of the last i bytes of our buffer announces an
  12595. // incomplete char.
  12596. for (; i > 0; i--) {
  12597. var c = buffer[buffer.length - i];
  12598. // See http://en.wikipedia.org/wiki/UTF-8#Description
  12599. // 110XXXXX
  12600. if (i == 1 && c >> 5 == 0x06) {
  12601. this.charLength = 2;
  12602. break;
  12603. }
  12604. // 1110XXXX
  12605. if (i <= 2 && c >> 4 == 0x0E) {
  12606. this.charLength = 3;
  12607. break;
  12608. }
  12609. // 11110XXX
  12610. if (i <= 3 && c >> 3 == 0x1E) {
  12611. this.charLength = 4;
  12612. break;
  12613. }
  12614. }
  12615. this.charReceived = i;
  12616. };
  12617. StringDecoder.prototype.end = function(buffer) {
  12618. var res = '';
  12619. if (buffer && buffer.length)
  12620. res = this.write(buffer);
  12621. if (this.charReceived) {
  12622. var cr = this.charReceived;
  12623. var buf = this.charBuffer;
  12624. var enc = this.encoding;
  12625. res += buf.slice(0, cr).toString(enc);
  12626. }
  12627. return res;
  12628. };
  12629. function passThroughWrite(buffer) {
  12630. return buffer.toString(this.encoding);
  12631. }
  12632. function utf16DetectIncompleteChar(buffer) {
  12633. this.charReceived = buffer.length % 2;
  12634. this.charLength = this.charReceived ? 2 : 0;
  12635. }
  12636. function base64DetectIncompleteChar(buffer) {
  12637. this.charReceived = buffer.length % 3;
  12638. this.charLength = this.charReceived ? 3 : 0;
  12639. }
  12640. },{"buffer":44}],80:[function(require,module,exports){
  12641. (function (global){
  12642. /**
  12643. * Module exports.
  12644. */
  12645. module.exports = deprecate;
  12646. /**
  12647. * Mark that a method should not be used.
  12648. * Returns a modified function which warns once by default.
  12649. *
  12650. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  12651. *
  12652. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  12653. * will throw an Error when invoked.
  12654. *
  12655. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  12656. * will invoke `console.trace()` instead of `console.error()`.
  12657. *
  12658. * @param {Function} fn - the function to deprecate
  12659. * @param {String} msg - the string to print to the console when `fn` is invoked
  12660. * @returns {Function} a new "deprecated" version of `fn`
  12661. * @api public
  12662. */
  12663. function deprecate (fn, msg) {
  12664. if (config('noDeprecation')) {
  12665. return fn;
  12666. }
  12667. var warned = false;
  12668. function deprecated() {
  12669. if (!warned) {
  12670. if (config('throwDeprecation')) {
  12671. throw new Error(msg);
  12672. } else if (config('traceDeprecation')) {
  12673. console.trace(msg);
  12674. } else {
  12675. console.warn(msg);
  12676. }
  12677. warned = true;
  12678. }
  12679. return fn.apply(this, arguments);
  12680. }
  12681. return deprecated;
  12682. }
  12683. /**
  12684. * Checks `localStorage` for boolean values for the given `name`.
  12685. *
  12686. * @param {String} name
  12687. * @returns {Boolean}
  12688. * @api private
  12689. */
  12690. function config (name) {
  12691. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  12692. try {
  12693. if (!global.localStorage) return false;
  12694. } catch (_) {
  12695. return false;
  12696. }
  12697. var val = global.localStorage[name];
  12698. if (null == val) return false;
  12699. return String(val).toLowerCase() === 'true';
  12700. }
  12701. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12702. },{}],81:[function(require,module,exports){
  12703. module.exports = function isBuffer(arg) {
  12704. return arg && typeof arg === 'object'
  12705. && typeof arg.copy === 'function'
  12706. && typeof arg.fill === 'function'
  12707. && typeof arg.readUInt8 === 'function';
  12708. }
  12709. },{}],82:[function(require,module,exports){
  12710. (function (process,global){
  12711. // Copyright Joyent, Inc. and other Node contributors.
  12712. //
  12713. // Permission is hereby granted, free of charge, to any person obtaining a
  12714. // copy of this software and associated documentation files (the
  12715. // "Software"), to deal in the Software without restriction, including
  12716. // without limitation the rights to use, copy, modify, merge, publish,
  12717. // distribute, sublicense, and/or sell copies of the Software, and to permit
  12718. // persons to whom the Software is furnished to do so, subject to the
  12719. // following conditions:
  12720. //
  12721. // The above copyright notice and this permission notice shall be included
  12722. // in all copies or substantial portions of the Software.
  12723. //
  12724. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  12725. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12726. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  12727. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  12728. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  12729. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  12730. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  12731. var formatRegExp = /%[sdj%]/g;
  12732. exports.format = function(f) {
  12733. if (!isString(f)) {
  12734. var objects = [];
  12735. for (var i = 0; i < arguments.length; i++) {
  12736. objects.push(inspect(arguments[i]));
  12737. }
  12738. return objects.join(' ');
  12739. }
  12740. var i = 1;
  12741. var args = arguments;
  12742. var len = args.length;
  12743. var str = String(f).replace(formatRegExp, function(x) {
  12744. if (x === '%%') return '%';
  12745. if (i >= len) return x;
  12746. switch (x) {
  12747. case '%s': return String(args[i++]);
  12748. case '%d': return Number(args[i++]);
  12749. case '%j':
  12750. try {
  12751. return JSON.stringify(args[i++]);
  12752. } catch (_) {
  12753. return '[Circular]';
  12754. }
  12755. default:
  12756. return x;
  12757. }
  12758. });
  12759. for (var x = args[i]; i < len; x = args[++i]) {
  12760. if (isNull(x) || !isObject(x)) {
  12761. str += ' ' + x;
  12762. } else {
  12763. str += ' ' + inspect(x);
  12764. }
  12765. }
  12766. return str;
  12767. };
  12768. // Mark that a method should not be used.
  12769. // Returns a modified function which warns once by default.
  12770. // If --no-deprecation is set, then it is a no-op.
  12771. exports.deprecate = function(fn, msg) {
  12772. // Allow for deprecating things in the process of starting up.
  12773. if (isUndefined(global.process)) {
  12774. return function() {
  12775. return exports.deprecate(fn, msg).apply(this, arguments);
  12776. };
  12777. }
  12778. if (process.noDeprecation === true) {
  12779. return fn;
  12780. }
  12781. var warned = false;
  12782. function deprecated() {
  12783. if (!warned) {
  12784. if (process.throwDeprecation) {
  12785. throw new Error(msg);
  12786. } else if (process.traceDeprecation) {
  12787. console.trace(msg);
  12788. } else {
  12789. console.error(msg);
  12790. }
  12791. warned = true;
  12792. }
  12793. return fn.apply(this, arguments);
  12794. }
  12795. return deprecated;
  12796. };
  12797. var debugs = {};
  12798. var debugEnviron;
  12799. exports.debuglog = function(set) {
  12800. if (isUndefined(debugEnviron))
  12801. debugEnviron = process.env.NODE_DEBUG || '';
  12802. set = set.toUpperCase();
  12803. if (!debugs[set]) {
  12804. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  12805. var pid = process.pid;
  12806. debugs[set] = function() {
  12807. var msg = exports.format.apply(exports, arguments);
  12808. console.error('%s %d: %s', set, pid, msg);
  12809. };
  12810. } else {
  12811. debugs[set] = function() {};
  12812. }
  12813. }
  12814. return debugs[set];
  12815. };
  12816. /**
  12817. * Echos the value of a value. Trys to print the value out
  12818. * in the best way possible given the different types.
  12819. *
  12820. * @param {Object} obj The object to print out.
  12821. * @param {Object} opts Optional options object that alters the output.
  12822. */
  12823. /* legacy: obj, showHidden, depth, colors*/
  12824. function inspect(obj, opts) {
  12825. // default options
  12826. var ctx = {
  12827. seen: [],
  12828. stylize: stylizeNoColor
  12829. };
  12830. // legacy...
  12831. if (arguments.length >= 3) ctx.depth = arguments[2];
  12832. if (arguments.length >= 4) ctx.colors = arguments[3];
  12833. if (isBoolean(opts)) {
  12834. // legacy...
  12835. ctx.showHidden = opts;
  12836. } else if (opts) {
  12837. // got an "options" object
  12838. exports._extend(ctx, opts);
  12839. }
  12840. // set default options
  12841. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  12842. if (isUndefined(ctx.depth)) ctx.depth = 2;
  12843. if (isUndefined(ctx.colors)) ctx.colors = false;
  12844. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  12845. if (ctx.colors) ctx.stylize = stylizeWithColor;
  12846. return formatValue(ctx, obj, ctx.depth);
  12847. }
  12848. exports.inspect = inspect;
  12849. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  12850. inspect.colors = {
  12851. 'bold' : [1, 22],
  12852. 'italic' : [3, 23],
  12853. 'underline' : [4, 24],
  12854. 'inverse' : [7, 27],
  12855. 'white' : [37, 39],
  12856. 'grey' : [90, 39],
  12857. 'black' : [30, 39],
  12858. 'blue' : [34, 39],
  12859. 'cyan' : [36, 39],
  12860. 'green' : [32, 39],
  12861. 'magenta' : [35, 39],
  12862. 'red' : [31, 39],
  12863. 'yellow' : [33, 39]
  12864. };
  12865. // Don't use 'blue' not visible on cmd.exe
  12866. inspect.styles = {
  12867. 'special': 'cyan',
  12868. 'number': 'yellow',
  12869. 'boolean': 'yellow',
  12870. 'undefined': 'grey',
  12871. 'null': 'bold',
  12872. 'string': 'green',
  12873. 'date': 'magenta',
  12874. // "name": intentionally not styling
  12875. 'regexp': 'red'
  12876. };
  12877. function stylizeWithColor(str, styleType) {
  12878. var style = inspect.styles[styleType];
  12879. if (style) {
  12880. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  12881. '\u001b[' + inspect.colors[style][1] + 'm';
  12882. } else {
  12883. return str;
  12884. }
  12885. }
  12886. function stylizeNoColor(str, styleType) {
  12887. return str;
  12888. }
  12889. function arrayToHash(array) {
  12890. var hash = {};
  12891. array.forEach(function(val, idx) {
  12892. hash[val] = true;
  12893. });
  12894. return hash;
  12895. }
  12896. function formatValue(ctx, value, recurseTimes) {
  12897. // Provide a hook for user-specified inspect functions.
  12898. // Check that value is an object with an inspect function on it
  12899. if (ctx.customInspect &&
  12900. value &&
  12901. isFunction(value.inspect) &&
  12902. // Filter out the util module, it's inspect function is special
  12903. value.inspect !== exports.inspect &&
  12904. // Also filter out any prototype objects using the circular check.
  12905. !(value.constructor && value.constructor.prototype === value)) {
  12906. var ret = value.inspect(recurseTimes, ctx);
  12907. if (!isString(ret)) {
  12908. ret = formatValue(ctx, ret, recurseTimes);
  12909. }
  12910. return ret;
  12911. }
  12912. // Primitive types cannot have properties
  12913. var primitive = formatPrimitive(ctx, value);
  12914. if (primitive) {
  12915. return primitive;
  12916. }
  12917. // Look up the keys of the object.
  12918. var keys = Object.keys(value);
  12919. var visibleKeys = arrayToHash(keys);
  12920. if (ctx.showHidden) {
  12921. keys = Object.getOwnPropertyNames(value);
  12922. }
  12923. // IE doesn't make error fields non-enumerable
  12924. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  12925. if (isError(value)
  12926. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  12927. return formatError(value);
  12928. }
  12929. // Some type of object without properties can be shortcutted.
  12930. if (keys.length === 0) {
  12931. if (isFunction(value)) {
  12932. var name = value.name ? ': ' + value.name : '';
  12933. return ctx.stylize('[Function' + name + ']', 'special');
  12934. }
  12935. if (isRegExp(value)) {
  12936. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  12937. }
  12938. if (isDate(value)) {
  12939. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  12940. }
  12941. if (isError(value)) {
  12942. return formatError(value);
  12943. }
  12944. }
  12945. var base = '', array = false, braces = ['{', '}'];
  12946. // Make Array say that they are Array
  12947. if (isArray(value)) {
  12948. array = true;
  12949. braces = ['[', ']'];
  12950. }
  12951. // Make functions say that they are functions
  12952. if (isFunction(value)) {
  12953. var n = value.name ? ': ' + value.name : '';
  12954. base = ' [Function' + n + ']';
  12955. }
  12956. // Make RegExps say that they are RegExps
  12957. if (isRegExp(value)) {
  12958. base = ' ' + RegExp.prototype.toString.call(value);
  12959. }
  12960. // Make dates with properties first say the date
  12961. if (isDate(value)) {
  12962. base = ' ' + Date.prototype.toUTCString.call(value);
  12963. }
  12964. // Make error with message first say the error
  12965. if (isError(value)) {
  12966. base = ' ' + formatError(value);
  12967. }
  12968. if (keys.length === 0 && (!array || value.length == 0)) {
  12969. return braces[0] + base + braces[1];
  12970. }
  12971. if (recurseTimes < 0) {
  12972. if (isRegExp(value)) {
  12973. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  12974. } else {
  12975. return ctx.stylize('[Object]', 'special');
  12976. }
  12977. }
  12978. ctx.seen.push(value);
  12979. var output;
  12980. if (array) {
  12981. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  12982. } else {
  12983. output = keys.map(function(key) {
  12984. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  12985. });
  12986. }
  12987. ctx.seen.pop();
  12988. return reduceToSingleString(output, base, braces);
  12989. }
  12990. function formatPrimitive(ctx, value) {
  12991. if (isUndefined(value))
  12992. return ctx.stylize('undefined', 'undefined');
  12993. if (isString(value)) {
  12994. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  12995. .replace(/'/g, "\\'")
  12996. .replace(/\\"/g, '"') + '\'';
  12997. return ctx.stylize(simple, 'string');
  12998. }
  12999. if (isNumber(value))
  13000. return ctx.stylize('' + value, 'number');
  13001. if (isBoolean(value))
  13002. return ctx.stylize('' + value, 'boolean');
  13003. // For some reason typeof null is "object", so special case here.
  13004. if (isNull(value))
  13005. return ctx.stylize('null', 'null');
  13006. }
  13007. function formatError(value) {
  13008. return '[' + Error.prototype.toString.call(value) + ']';
  13009. }
  13010. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  13011. var output = [];
  13012. for (var i = 0, l = value.length; i < l; ++i) {
  13013. if (hasOwnProperty(value, String(i))) {
  13014. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  13015. String(i), true));
  13016. } else {
  13017. output.push('');
  13018. }
  13019. }
  13020. keys.forEach(function(key) {
  13021. if (!key.match(/^\d+$/)) {
  13022. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  13023. key, true));
  13024. }
  13025. });
  13026. return output;
  13027. }
  13028. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  13029. var name, str, desc;
  13030. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  13031. if (desc.get) {
  13032. if (desc.set) {
  13033. str = ctx.stylize('[Getter/Setter]', 'special');
  13034. } else {
  13035. str = ctx.stylize('[Getter]', 'special');
  13036. }
  13037. } else {
  13038. if (desc.set) {
  13039. str = ctx.stylize('[Setter]', 'special');
  13040. }
  13041. }
  13042. if (!hasOwnProperty(visibleKeys, key)) {
  13043. name = '[' + key + ']';
  13044. }
  13045. if (!str) {
  13046. if (ctx.seen.indexOf(desc.value) < 0) {
  13047. if (isNull(recurseTimes)) {
  13048. str = formatValue(ctx, desc.value, null);
  13049. } else {
  13050. str = formatValue(ctx, desc.value, recurseTimes - 1);
  13051. }
  13052. if (str.indexOf('\n') > -1) {
  13053. if (array) {
  13054. str = str.split('\n').map(function(line) {
  13055. return ' ' + line;
  13056. }).join('\n').substr(2);
  13057. } else {
  13058. str = '\n' + str.split('\n').map(function(line) {
  13059. return ' ' + line;
  13060. }).join('\n');
  13061. }
  13062. }
  13063. } else {
  13064. str = ctx.stylize('[Circular]', 'special');
  13065. }
  13066. }
  13067. if (isUndefined(name)) {
  13068. if (array && key.match(/^\d+$/)) {
  13069. return str;
  13070. }
  13071. name = JSON.stringify('' + key);
  13072. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  13073. name = name.substr(1, name.length - 2);
  13074. name = ctx.stylize(name, 'name');
  13075. } else {
  13076. name = name.replace(/'/g, "\\'")
  13077. .replace(/\\"/g, '"')
  13078. .replace(/(^"|"$)/g, "'");
  13079. name = ctx.stylize(name, 'string');
  13080. }
  13081. }
  13082. return name + ': ' + str;
  13083. }
  13084. function reduceToSingleString(output, base, braces) {
  13085. var numLinesEst = 0;
  13086. var length = output.reduce(function(prev, cur) {
  13087. numLinesEst++;
  13088. if (cur.indexOf('\n') >= 0) numLinesEst++;
  13089. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  13090. }, 0);
  13091. if (length > 60) {
  13092. return braces[0] +
  13093. (base === '' ? '' : base + '\n ') +
  13094. ' ' +
  13095. output.join(',\n ') +
  13096. ' ' +
  13097. braces[1];
  13098. }
  13099. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  13100. }
  13101. // NOTE: These type checking functions intentionally don't use `instanceof`
  13102. // because it is fragile and can be easily faked with `Object.create()`.
  13103. function isArray(ar) {
  13104. return Array.isArray(ar);
  13105. }
  13106. exports.isArray = isArray;
  13107. function isBoolean(arg) {
  13108. return typeof arg === 'boolean';
  13109. }
  13110. exports.isBoolean = isBoolean;
  13111. function isNull(arg) {
  13112. return arg === null;
  13113. }
  13114. exports.isNull = isNull;
  13115. function isNullOrUndefined(arg) {
  13116. return arg == null;
  13117. }
  13118. exports.isNullOrUndefined = isNullOrUndefined;
  13119. function isNumber(arg) {
  13120. return typeof arg === 'number';
  13121. }
  13122. exports.isNumber = isNumber;
  13123. function isString(arg) {
  13124. return typeof arg === 'string';
  13125. }
  13126. exports.isString = isString;
  13127. function isSymbol(arg) {
  13128. return typeof arg === 'symbol';
  13129. }
  13130. exports.isSymbol = isSymbol;
  13131. function isUndefined(arg) {
  13132. return arg === void 0;
  13133. }
  13134. exports.isUndefined = isUndefined;
  13135. function isRegExp(re) {
  13136. return isObject(re) && objectToString(re) === '[object RegExp]';
  13137. }
  13138. exports.isRegExp = isRegExp;
  13139. function isObject(arg) {
  13140. return typeof arg === 'object' && arg !== null;
  13141. }
  13142. exports.isObject = isObject;
  13143. function isDate(d) {
  13144. return isObject(d) && objectToString(d) === '[object Date]';
  13145. }
  13146. exports.isDate = isDate;
  13147. function isError(e) {
  13148. return isObject(e) &&
  13149. (objectToString(e) === '[object Error]' || e instanceof Error);
  13150. }
  13151. exports.isError = isError;
  13152. function isFunction(arg) {
  13153. return typeof arg === 'function';
  13154. }
  13155. exports.isFunction = isFunction;
  13156. function isPrimitive(arg) {
  13157. return arg === null ||
  13158. typeof arg === 'boolean' ||
  13159. typeof arg === 'number' ||
  13160. typeof arg === 'string' ||
  13161. typeof arg === 'symbol' || // ES6 symbol
  13162. typeof arg === 'undefined';
  13163. }
  13164. exports.isPrimitive = isPrimitive;
  13165. exports.isBuffer = require('./support/isBuffer');
  13166. function objectToString(o) {
  13167. return Object.prototype.toString.call(o);
  13168. }
  13169. function pad(n) {
  13170. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  13171. }
  13172. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  13173. 'Oct', 'Nov', 'Dec'];
  13174. // 26 Feb 16:19:34
  13175. function timestamp() {
  13176. var d = new Date();
  13177. var time = [pad(d.getHours()),
  13178. pad(d.getMinutes()),
  13179. pad(d.getSeconds())].join(':');
  13180. return [d.getDate(), months[d.getMonth()], time].join(' ');
  13181. }
  13182. // log is just a thin wrapper to console.log that prepends a timestamp
  13183. exports.log = function() {
  13184. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  13185. };
  13186. /**
  13187. * Inherit the prototype methods from one constructor into another.
  13188. *
  13189. * The Function.prototype.inherits from lang.js rewritten as a standalone
  13190. * function (not on Function.prototype). NOTE: If this file is to be loaded
  13191. * during bootstrapping this function needs to be rewritten using some native
  13192. * functions as prototype setup using normal JavaScript does not work as
  13193. * expected during bootstrapping (see mirror.js in r114903).
  13194. *
  13195. * @param {function} ctor Constructor function which needs to inherit the
  13196. * prototype.
  13197. * @param {function} superCtor Constructor function to inherit prototype from.
  13198. */
  13199. exports.inherits = require('inherits');
  13200. exports._extend = function(origin, add) {
  13201. // Don't do anything if add isn't an object
  13202. if (!add || !isObject(add)) return origin;
  13203. var keys = Object.keys(add);
  13204. var i = keys.length;
  13205. while (i--) {
  13206. origin[keys[i]] = add[keys[i]];
  13207. }
  13208. return origin;
  13209. };
  13210. function hasOwnProperty(obj, prop) {
  13211. return Object.prototype.hasOwnProperty.call(obj, prop);
  13212. }
  13213. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  13214. },{"./support/isBuffer":81,"_process":67,"inherits":51}]},{},[1]);