1
0

mermaidAPI.slim.js 1.6 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571455724557345574455754557645577455784557945580455814558245583455844558545586455874558845589455904559145592455934559445595455964559745598455994560045601456024560345604456054560645607456084560945610456114561245613456144561545616456174561845619456204562145622456234562445625456264562745628456294563045631456324563345634456354563645637456384563945640456414564245643456444564545646456474564845649456504565145652456534565445655456564565745658456594566045661456624566345664456654566645667456684566945670456714567245673456744567545676456774567845679456804568145682456834568445685456864568745688456894569045691456924569345694456954569645697456984569945700457014570245703457044570545706457074570845709457104571145712457134571445715457164571745718457194572045721457224572345724457254572645727457284572945730457314573245733457344573545736457374573845739457404574145742457434574445745457464574745748457494575045751457524575345754457554575645757457584575945760457614576245763457644576545766457674576845769457704577145772457734577445775457764577745778457794578045781457824578345784457854578645787457884578945790457914579245793457944579545796457974579845799458004580145802458034580445805458064580745808458094581045811458124581345814458154581645817458184581945820458214582245823458244582545826458274582845829458304583145832458334583445835458364583745838458394584045841458424584345844458454584645847458484584945850458514585245853458544585545856458574585845859458604586145862458634586445865458664586745868458694587045871458724587345874458754587645877458784587945880458814588245883458844588545886458874588845889458904589145892458934589445895458964589745898458994590045901459024590345904459054590645907459084590945910459114591245913459144591545916459174591845919459204592145922459234592445925459264592745928459294593045931459324593345934459354593645937459384593945940459414594245943459444594545946459474594845949459504595145952459534595445955459564595745958459594596045961459624596345964459654596645967459684596945970459714597245973459744597545976459774597845979459804598145982459834598445985459864598745988459894599045991459924599345994459954599645997459984599946000460014600246003460044600546006460074600846009460104601146012460134601446015460164601746018460194602046021460224602346024460254602646027460284602946030460314603246033460344603546036460374603846039460404604146042460434604446045460464604746048460494605046051460524605346054460554605646057460584605946060460614606246063460644606546066460674606846069460704607146072460734607446075460764607746078460794608046081460824608346084460854608646087460884608946090460914609246093460944609546096460974609846099461004610146102461034610446105461064610746108461094611046111461124611346114461154611646117461184611946120461214612246123461244612546126461274612846129461304613146132461334613446135461364613746138461394614046141461424614346144461454614646147461484614946150461514615246153461544615546156461574615846159461604616146162461634616446165461664616746168461694617046171461724617346174461754617646177461784617946180461814618246183461844618546186461874618846189461904619146192461934619446195461964619746198461994620046201462024620346204462054620646207462084620946210462114621246213462144621546216462174621846219462204622146222462234622446225462264622746228462294623046231462324623346234462354623646237462384623946240462414624246243462444624546246462474624846249462504625146252462534625446255462564625746258462594626046261462624626346264462654626646267462684626946270462714627246273462744627546276462774627846279462804628146282462834628446285462864628746288462894629046291462924629346294462954629646297462984629946300463014630246303463044630546306463074630846309463104631146312463134631446315463164631746318463194632046321463224632346324463254632646327463284632946330463314633246333463344633546336463374633846339463404634146342463434634446345463464634746348463494635046351463524635346354463554635646357463584635946360463614636246363463644636546366463674636846369463704637146372463734637446375463764637746378463794638046381463824638346384463854638646387463884638946390463914639246393463944639546396463974639846399464004640146402464034640446405464064640746408464094641046411464124641346414464154641646417464184641946420464214642246423464244642546426464274642846429464304643146432464334643446435464364643746438464394644046441464424644346444464454644646447464484644946450464514645246453464544645546456464574645846459464604646146462464634646446465464664646746468464694647046471464724647346474464754647646477464784647946480464814648246483464844648546486464874648846489464904649146492464934649446495464964649746498464994650046501465024650346504465054650646507465084650946510465114651246513465144651546516465174651846519465204652146522465234652446525465264652746528465294653046531465324653346534465354653646537465384653946540465414654246543465444654546546465474654846549465504655146552465534655446555465564655746558465594656046561465624656346564465654656646567465684656946570465714657246573465744657546576465774657846579465804658146582465834658446585465864658746588465894659046591465924659346594465954659646597465984659946600466014660246603466044660546606466074660846609466104661146612466134661446615466164661746618466194662046621466224662346624466254662646627466284662946630466314663246633466344663546636466374663846639466404664146642466434664446645466464664746648466494665046651466524665346654466554665646657466584665946660466614666246663466644666546666466674666846669466704667146672466734667446675466764667746678466794668046681466824668346684466854668646687466884668946690466914669246693466944669546696466974669846699467004670146702467034670446705467064670746708467094671046711467124671346714467154671646717467184671946720467214672246723467244672546726467274672846729467304673146732467334673446735467364673746738467394674046741467424674346744467454674646747467484674946750467514675246753467544675546756467574675846759467604676146762467634676446765467664676746768467694677046771467724677346774467754677646777467784677946780467814678246783467844678546786467874678846789467904679146792467934679446795467964679746798467994680046801468024680346804468054680646807468084680946810468114681246813468144681546816468174681846819468204682146822468234682446825468264682746828468294683046831468324683346834468354683646837468384683946840468414684246843468444684546846468474684846849468504685146852468534685446855468564685746858468594686046861468624686346864468654686646867468684686946870468714687246873468744687546876468774687846879468804688146882468834688446885468864688746888468894689046891468924689346894468954689646897468984689946900469014690246903469044690546906469074690846909469104691146912469134691446915469164691746918469194692046921469224692346924469254692646927469284692946930469314693246933469344693546936469374693846939469404694146942469434694446945469464694746948469494695046951469524695346954469554695646957469584695946960469614696246963469644696546966469674696846969469704697146972469734697446975469764697746978469794698046981469824698346984469854698646987469884698946990469914699246993469944699546996469974699846999470004700147002470034700447005470064700747008470094701047011470124701347014470154701647017470184701947020470214702247023470244702547026470274702847029470304703147032470334703447035470364703747038470394704047041470424704347044470454704647047470484704947050470514705247053470544705547056470574705847059470604706147062470634706447065470664706747068470694707047071470724707347074470754707647077470784707947080470814708247083470844708547086470874708847089470904709147092470934709447095470964709747098470994710047101471024710347104471054710647107471084710947110471114711247113471144711547116471174711847119471204712147122471234712447125471264712747128471294713047131471324713347134471354713647137471384713947140471414714247143471444714547146471474714847149471504715147152471534715447155471564715747158471594716047161471624716347164471654716647167471684716947170471714717247173471744717547176471774717847179471804718147182471834718447185471864718747188471894719047191471924719347194471954719647197471984719947200472014720247203472044720547206472074720847209472104721147212472134721447215472164721747218472194722047221472224722347224472254722647227472284722947230472314723247233472344723547236472374723847239472404724147242472434724447245472464724747248472494725047251472524725347254472554725647257472584725947260472614726247263472644726547266472674726847269472704727147272472734727447275472764727747278472794728047281472824728347284472854728647287472884728947290472914729247293472944729547296472974729847299473004730147302473034730447305473064730747308473094731047311473124731347314473154731647317473184731947320473214732247323473244732547326473274732847329473304733147332473334733447335473364733747338473394734047341473424734347344473454734647347473484734947350473514735247353473544735547356473574735847359473604736147362473634736447365473664736747368473694737047371473724737347374473754737647377473784737947380473814738247383473844738547386473874738847389473904739147392473934739447395473964739747398473994740047401474024740347404474054740647407474084740947410474114741247413474144741547416474174741847419474204742147422474234742447425474264742747428474294743047431474324743347434474354743647437474384743947440474414744247443474444744547446474474744847449474504745147452474534745447455474564745747458474594746047461474624746347464474654746647467474684746947470474714747247473474744747547476474774747847479474804748147482474834748447485474864748747488474894749047491474924749347494474954749647497474984749947500475014750247503475044750547506475074750847509475104751147512475134751447515475164751747518475194752047521475224752347524475254752647527475284752947530475314753247533475344753547536475374753847539475404754147542475434754447545475464754747548475494755047551475524755347554475554755647557475584755947560475614756247563475644756547566475674756847569475704757147572475734757447575475764757747578475794758047581475824758347584475854758647587475884758947590475914759247593475944759547596475974759847599476004760147602476034760447605476064760747608476094761047611476124761347614476154761647617476184761947620476214762247623476244762547626476274762847629476304763147632476334763447635476364763747638476394764047641476424764347644476454764647647476484764947650476514765247653476544765547656476574765847659476604766147662476634766447665476664766747668476694767047671476724767347674476754767647677476784767947680476814768247683476844768547686476874768847689476904769147692476934769447695476964769747698476994770047701477024770347704477054770647707477084770947710477114771247713477144771547716477174771847719477204772147722477234772447725477264772747728477294773047731477324773347734477354773647737477384773947740477414774247743477444774547746477474774847749477504775147752477534775447755477564775747758477594776047761477624776347764477654776647767477684776947770477714777247773477744777547776477774777847779477804778147782477834778447785477864778747788477894779047791477924779347794477954779647797477984779947800478014780247803478044780547806478074780847809478104781147812478134781447815478164781747818478194782047821478224782347824478254782647827478284782947830478314783247833478344783547836478374783847839478404784147842478434784447845478464784747848478494785047851478524785347854478554785647857478584785947860478614786247863478644786547866478674786847869478704787147872478734787447875478764787747878478794788047881478824788347884478854788647887478884788947890478914789247893478944789547896478974789847899479004790147902479034790447905479064790747908479094791047911479124791347914479154791647917479184791947920479214792247923479244792547926479274792847929479304793147932479334793447935479364793747938479394794047941479424794347944479454794647947479484794947950479514795247953479544795547956479574795847959479604796147962479634796447965479664796747968479694797047971479724797347974479754797647977479784797947980479814798247983479844798547986479874798847989479904799147992479934799447995479964799747998479994800048001480024800348004480054800648007480084800948010480114801248013480144801548016480174801848019480204802148022480234802448025480264802748028480294803048031480324803348034480354803648037480384803948040480414804248043480444804548046480474804848049480504805148052480534805448055480564805748058480594806048061480624806348064480654806648067480684806948070480714807248073480744807548076480774807848079480804808148082480834808448085480864808748088480894809048091480924809348094480954809648097480984809948100481014810248103481044810548106481074810848109481104811148112481134811448115481164811748118481194812048121481224812348124481254812648127481284812948130481314813248133481344813548136481374813848139481404814148142481434814448145481464814748148481494815048151481524815348154481554815648157481584815948160481614816248163481644816548166481674816848169481704817148172481734817448175481764817748178481794818048181481824818348184481854818648187481884818948190481914819248193481944819548196481974819848199482004820148202482034820448205482064820748208482094821048211482124821348214482154821648217482184821948220482214822248223482244822548226482274822848229482304823148232482334823448235482364823748238482394824048241482424824348244482454824648247482484824948250482514825248253482544825548256482574825848259482604826148262482634826448265482664826748268482694827048271482724827348274482754827648277482784827948280482814828248283482844828548286482874828848289482904829148292482934829448295482964829748298482994830048301483024830348304483054830648307483084830948310483114831248313483144831548316483174831848319483204832148322483234832448325483264832748328483294833048331483324833348334483354833648337483384833948340483414834248343483444834548346483474834848349483504835148352483534835448355483564835748358483594836048361483624836348364483654836648367483684836948370483714837248373483744837548376483774837848379483804838148382483834838448385483864838748388483894839048391483924839348394483954839648397483984839948400484014840248403484044840548406484074840848409484104841148412484134841448415484164841748418484194842048421484224842348424484254842648427484284842948430484314843248433484344843548436484374843848439484404844148442484434844448445484464844748448484494845048451484524845348454484554845648457484584845948460484614846248463484644846548466484674846848469484704847148472484734847448475484764847748478484794848048481484824848348484484854848648487484884848948490484914849248493484944849548496484974849848499485004850148502485034850448505485064850748508485094851048511485124851348514485154851648517485184851948520485214852248523485244852548526485274852848529485304853148532485334853448535485364853748538485394854048541485424854348544485454854648547485484854948550485514855248553485544855548556485574855848559485604856148562485634856448565485664856748568485694857048571485724857348574485754857648577485784857948580485814858248583485844858548586485874858848589485904859148592485934859448595485964859748598485994860048601486024860348604486054860648607486084860948610486114861248613486144861548616486174861848619486204862148622486234862448625486264862748628486294863048631486324863348634486354863648637486384863948640486414864248643486444864548646486474864848649486504865148652486534865448655486564865748658486594866048661486624866348664486654866648667486684866948670486714867248673486744867548676486774867848679486804868148682486834868448685486864868748688486894869048691486924869348694486954869648697486984869948700487014870248703487044870548706487074870848709487104871148712487134871448715487164871748718487194872048721487224872348724487254872648727487284872948730487314873248733487344873548736487374873848739487404874148742487434874448745487464874748748487494875048751487524875348754487554875648757487584875948760487614876248763487644876548766487674876848769487704877148772487734877448775487764877748778487794878048781487824878348784487854878648787487884878948790487914879248793487944879548796487974879848799488004880148802488034880448805488064880748808488094881048811488124881348814488154881648817488184881948820488214882248823488244882548826488274882848829488304883148832488334883448835488364883748838488394884048841488424884348844488454884648847488484884948850488514885248853488544885548856488574885848859488604886148862488634886448865488664886748868488694887048871488724887348874488754887648877488784887948880488814888248883488844888548886488874888848889488904889148892488934889448895488964889748898488994890048901489024890348904489054890648907489084890948910489114891248913489144891548916489174891848919489204892148922489234892448925489264892748928489294893048931489324893348934489354893648937489384893948940489414894248943489444894548946489474894848949489504895148952489534895448955489564895748958489594896048961489624896348964489654896648967489684896948970489714897248973489744897548976489774897848979489804898148982489834898448985489864898748988489894899048991489924899348994489954899648997489984899949000490014900249003490044900549006490074900849009490104901149012490134901449015490164901749018490194902049021490224902349024490254902649027490284902949030490314903249033490344903549036490374903849039490404904149042490434904449045490464904749048490494905049051490524905349054490554905649057490584905949060490614906249063
  1. !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.mermaidAPI=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof 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. },{}],2:[function(require,module,exports){
  3. /**
  4. * @license
  5. * Copyright (c) 2012-2013 Chris Pettitt
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. * THE SOFTWARE.
  24. */
  25. module.exports = {
  26. graphlib: require("./lib/graphlib"),
  27. dagre: require("./lib/dagre"),
  28. intersect: require("./lib/intersect"),
  29. render: require("./lib/render"),
  30. util: require("./lib/util"),
  31. version: require("./lib/version")
  32. };
  33. },{"./lib/dagre":9,"./lib/graphlib":10,"./lib/intersect":11,"./lib/render":26,"./lib/util":28,"./lib/version":29}],3:[function(require,module,exports){
  34. var util = require("./util");
  35. module.exports = {
  36. "default": normal,
  37. "normal": normal,
  38. "vee": vee,
  39. "undirected": undirected
  40. };
  41. function normal(parent, id, edge, type) {
  42. var marker = parent.append("marker")
  43. .attr("id", id)
  44. .attr("viewBox", "0 0 10 10")
  45. .attr("refX", 9)
  46. .attr("refY", 5)
  47. .attr("markerUnits", "strokeWidth")
  48. .attr("markerWidth", 8)
  49. .attr("markerHeight", 6)
  50. .attr("orient", "auto");
  51. var path = marker.append("path")
  52. .attr("d", "M 0 0 L 10 5 L 0 10 z")
  53. .style("stroke-width", 1)
  54. .style("stroke-dasharray", "1,0");
  55. util.applyStyle(path, edge[type + "Style"]);
  56. }
  57. function vee(parent, id, edge, type) {
  58. var marker = parent.append("marker")
  59. .attr("id", id)
  60. .attr("viewBox", "0 0 10 10")
  61. .attr("refX", 9)
  62. .attr("refY", 5)
  63. .attr("markerUnits", "strokeWidth")
  64. .attr("markerWidth", 8)
  65. .attr("markerHeight", 6)
  66. .attr("orient", "auto");
  67. var path = marker.append("path")
  68. .attr("d", "M 0 0 L 10 5 L 0 10 L 4 5 z")
  69. .style("stroke-width", 1)
  70. .style("stroke-dasharray", "1,0");
  71. util.applyStyle(path, edge[type + "Style"]);
  72. }
  73. function undirected(parent, id, edge, type) {
  74. var marker = parent.append("marker")
  75. .attr("id", id)
  76. .attr("viewBox", "0 0 10 10")
  77. .attr("refX", 9)
  78. .attr("refY", 5)
  79. .attr("markerUnits", "strokeWidth")
  80. .attr("markerWidth", 8)
  81. .attr("markerHeight", 6)
  82. .attr("orient", "auto");
  83. var path = marker.append("path")
  84. .attr("d", "M 0 5 L 10 5")
  85. .style("stroke-width", 1)
  86. .style("stroke-dasharray", "1,0");
  87. util.applyStyle(path, edge[type + "Style"]);
  88. }
  89. },{"./util":28}],4:[function(require,module,exports){
  90. var util = require("./util"),
  91. addLabel = require("./label/add-label");
  92. module.exports = createClusters;
  93. function createClusters(selection, g) {
  94. var clusters = g.nodes().filter(function(v) { return util.isSubgraph(g, v); }),
  95. svgClusters = selection.selectAll("g.cluster")
  96. .data(clusters, function(v) { return v; });
  97. svgClusters.selectAll("*").remove();
  98. svgClusters.enter()
  99. .append("g")
  100. .attr("class", "cluster")
  101. .attr("id",function(v){
  102. var node = g.node(v);
  103. return node.id;
  104. })
  105. .style("opacity", 0);
  106. util.applyTransition(svgClusters, g)
  107. .style("opacity", 1);
  108. svgClusters.each(function(v) {
  109. var node = g.node(v),
  110. thisGroup = d3.select(this);
  111. d3.select(this).append("rect");
  112. var labelGroup = thisGroup.append("g").attr("class", "label");
  113. addLabel(labelGroup, node, node.clusterLabelPos);
  114. });
  115. svgClusters.selectAll("rect").each(function(c) {
  116. var node = g.node(c);
  117. var domCluster = d3.select(this);
  118. util.applyStyle(domCluster, node.style);
  119. });
  120. util.applyTransition(svgClusters.exit(), g)
  121. .style("opacity", 0)
  122. .remove();
  123. return svgClusters;
  124. }
  125. },{"./label/add-label":19,"./util":28}],5:[function(require,module,exports){
  126. "use strict";
  127. var _ = require("./lodash"),
  128. addLabel = require("./label/add-label"),
  129. util = require("./util"),
  130. d3 = require("./d3");
  131. module.exports = createEdgeLabels;
  132. function createEdgeLabels(selection, g) {
  133. var svgEdgeLabels = selection.selectAll("g.edgeLabel")
  134. .data(g.edges(), function(e) { return util.edgeToId(e); })
  135. .classed("update", true);
  136. svgEdgeLabels.selectAll("*").remove();
  137. svgEdgeLabels.enter()
  138. .append("g")
  139. .classed("edgeLabel", true)
  140. .style("opacity", 0);
  141. svgEdgeLabels.each(function(e) {
  142. var edge = g.edge(e),
  143. label = addLabel(d3.select(this), g.edge(e), 0, 0).classed("label", true),
  144. bbox = label.node().getBBox();
  145. if (edge.labelId) { label.attr("id", edge.labelId); }
  146. if (!_.has(edge, "width")) { edge.width = bbox.width; }
  147. if (!_.has(edge, "height")) { edge.height = bbox.height; }
  148. });
  149. util.applyTransition(svgEdgeLabels.exit(), g)
  150. .style("opacity", 0)
  151. .remove();
  152. return svgEdgeLabels;
  153. }
  154. },{"./d3":8,"./label/add-label":19,"./lodash":22,"./util":28}],6:[function(require,module,exports){
  155. "use strict";
  156. var _ = require("./lodash"),
  157. intersectNode = require("./intersect/intersect-node"),
  158. util = require("./util"),
  159. d3 = require("./d3");
  160. module.exports = createEdgePaths;
  161. function createEdgePaths(selection, g, arrows) {
  162. var svgPaths = selection.selectAll("g.edgePath")
  163. .data(g.edges(), function(e) { return util.edgeToId(e); })
  164. .classed("update", true);
  165. enter(svgPaths, g);
  166. exit(svgPaths, g);
  167. util.applyTransition(svgPaths, g)
  168. .style("opacity", 1);
  169. // Save DOM element in the path group, and set ID and class
  170. svgPaths.each(function(e) {
  171. var domEdge = d3.select(this);
  172. var edge = g.edge(e);
  173. edge.elem = this;
  174. if (edge.id) {
  175. domEdge.attr("id", edge.id);
  176. }
  177. util.applyClass(domEdge, edge["class"],
  178. (domEdge.classed("update") ? "update " : "") + "edgePath");
  179. });
  180. svgPaths.selectAll("path.path")
  181. .each(function(e) {
  182. var edge = g.edge(e);
  183. edge.arrowheadId = _.uniqueId("arrowhead");
  184. var domEdge = d3.select(this)
  185. .attr("marker-end", function() {
  186. return "url(#" + edge.arrowheadId + ")";
  187. })
  188. .style("fill", "none");
  189. util.applyTransition(domEdge, g)
  190. .attr("d", function(e) { return calcPoints(g, e); });
  191. util.applyStyle(domEdge, edge.style);
  192. });
  193. svgPaths.selectAll("defs *").remove();
  194. svgPaths.selectAll("defs")
  195. .each(function(e) {
  196. var edge = g.edge(e),
  197. arrowhead = arrows[edge.arrowhead];
  198. arrowhead(d3.select(this), edge.arrowheadId, edge, "arrowhead");
  199. });
  200. return svgPaths;
  201. }
  202. function calcPoints(g, e) {
  203. var edge = g.edge(e),
  204. tail = g.node(e.v),
  205. head = g.node(e.w),
  206. points = edge.points.slice(1, edge.points.length - 1);
  207. points.unshift(intersectNode(tail, points[0]));
  208. points.push(intersectNode(head, points[points.length - 1]));
  209. return createLine(edge, points);
  210. }
  211. function createLine(edge, points) {
  212. var line = d3.svg.line()
  213. .x(function(d) { return d.x; })
  214. .y(function(d) { return d.y; });
  215. if (_.has(edge, "lineInterpolate")) {
  216. line.interpolate(edge.lineInterpolate);
  217. }
  218. if (_.has(edge, "lineTension")) {
  219. line.tension(Number(edge.lineTension));
  220. }
  221. return line(points);
  222. }
  223. function getCoords(elem) {
  224. var bbox = elem.getBBox(),
  225. matrix = elem.getTransformToElement(elem.ownerSVGElement)
  226. .translate(bbox.width / 2, bbox.height / 2);
  227. return { x: matrix.e, y: matrix.f };
  228. }
  229. function enter(svgPaths, g) {
  230. var svgPathsEnter = svgPaths.enter()
  231. .append("g")
  232. .attr("class", "edgePath")
  233. .style("opacity", 0);
  234. svgPathsEnter.append("path")
  235. .attr("class", "path")
  236. .attr("d", function(e) {
  237. var edge = g.edge(e),
  238. sourceElem = g.node(e.v).elem,
  239. points = _.range(edge.points.length).map(function() { return getCoords(sourceElem); });
  240. return createLine(edge, points);
  241. });
  242. svgPathsEnter.append("defs");
  243. }
  244. function exit(svgPaths, g) {
  245. var svgPathExit = svgPaths.exit();
  246. util.applyTransition(svgPathExit, g)
  247. .style("opacity", 0)
  248. .remove();
  249. util.applyTransition(svgPathExit.select("path.path"), g)
  250. .attr("d", function(e) {
  251. var source = g.node(e.v);
  252. if (source) {
  253. var points = _.range(this.pathSegList.length).map(function() { return source; });
  254. return createLine({}, points);
  255. } else {
  256. return d3.select(this).attr("d");
  257. }
  258. });
  259. }
  260. },{"./d3":8,"./intersect/intersect-node":15,"./lodash":22,"./util":28}],7:[function(require,module,exports){
  261. "use strict";
  262. var _ = require("./lodash"),
  263. addLabel = require("./label/add-label"),
  264. util = require("./util"),
  265. d3 = require("./d3");
  266. module.exports = createNodes;
  267. function createNodes(selection, g, shapes) {
  268. var simpleNodes = g.nodes().filter(function(v) { return !util.isSubgraph(g, v); });
  269. var svgNodes = selection.selectAll("g.node")
  270. .data(simpleNodes, function(v) { return v; })
  271. .classed("update", true);
  272. svgNodes.selectAll("*").remove();
  273. svgNodes.enter()
  274. .append("g")
  275. .attr("class", "node")
  276. .style("opacity", 0);
  277. svgNodes.each(function(v) {
  278. var node = g.node(v),
  279. thisGroup = d3.select(this),
  280. labelGroup = thisGroup.append("g").attr("class", "label"),
  281. labelDom = addLabel(labelGroup, node),
  282. shape = shapes[node.shape],
  283. bbox = _.pick(labelDom.node().getBBox(), "width", "height");
  284. node.elem = this;
  285. if (node.id) { thisGroup.attr("id", node.id); }
  286. if (node.labelId) { labelGroup.attr("id", node.labelId); }
  287. util.applyClass(thisGroup, node["class"],
  288. (thisGroup.classed("update") ? "update " : "") + "node");
  289. if (_.has(node, "width")) { bbox.width = node.width; }
  290. if (_.has(node, "height")) { bbox.height = node.height; }
  291. bbox.width += node.paddingLeft + node.paddingRight;
  292. bbox.height += node.paddingTop + node.paddingBottom;
  293. labelGroup.attr("transform", "translate(" +
  294. ((node.paddingLeft - node.paddingRight) / 2) + "," +
  295. ((node.paddingTop - node.paddingBottom) / 2) + ")");
  296. var shapeSvg = shape(d3.select(this), bbox, node);
  297. util.applyStyle(shapeSvg, node.style);
  298. var shapeBBox = shapeSvg.node().getBBox();
  299. node.width = shapeBBox.width;
  300. node.height = shapeBBox.height;
  301. });
  302. util.applyTransition(svgNodes.exit(), g)
  303. .style("opacity", 0)
  304. .remove();
  305. return svgNodes;
  306. }
  307. },{"./d3":8,"./label/add-label":19,"./lodash":22,"./util":28}],8:[function(require,module,exports){
  308. // Stub to get D3 either via NPM or from the global object
  309. module.exports = window.d3;
  310. },{}],9:[function(require,module,exports){
  311. /* global window */
  312. var dagre;
  313. if (require) {
  314. try {
  315. dagre = require("dagre");
  316. } catch (e) {}
  317. }
  318. if (!dagre) {
  319. dagre = window.dagre;
  320. }
  321. module.exports = dagre;
  322. },{"dagre":51}],10:[function(require,module,exports){
  323. /* global window */
  324. var graphlib;
  325. if (require) {
  326. try {
  327. graphlib = require("graphlib");
  328. } catch (e) {}
  329. }
  330. if (!graphlib) {
  331. graphlib = window.graphlib;
  332. }
  333. module.exports = graphlib;
  334. },{"graphlib":30}],11:[function(require,module,exports){
  335. module.exports = {
  336. node: require("./intersect-node"),
  337. circle: require("./intersect-circle"),
  338. ellipse: require("./intersect-ellipse"),
  339. polygon: require("./intersect-polygon"),
  340. rect: require("./intersect-rect")
  341. };
  342. },{"./intersect-circle":12,"./intersect-ellipse":13,"./intersect-node":15,"./intersect-polygon":16,"./intersect-rect":17}],12:[function(require,module,exports){
  343. var intersectEllipse = require("./intersect-ellipse");
  344. module.exports = intersectCircle;
  345. function intersectCircle(node, rx, point) {
  346. return intersectEllipse(node, rx, rx, point);
  347. }
  348. },{"./intersect-ellipse":13}],13:[function(require,module,exports){
  349. module.exports = intersectEllipse;
  350. function intersectEllipse(node, rx, ry, point) {
  351. // Formulae from: http://mathworld.wolfram.com/Ellipse-LineIntersection.html
  352. var cx = node.x;
  353. var cy = node.y;
  354. var px = cx - point.x;
  355. var py = cy - point.y;
  356. var det = Math.sqrt(rx * rx * py * py + ry * ry * px * px);
  357. var dx = Math.abs(rx * ry * px / det);
  358. if (point.x < cx) {
  359. dx = -dx;
  360. }
  361. var dy = Math.abs(rx * ry * py / det);
  362. if (point.y < cy) {
  363. dy = -dy;
  364. }
  365. return {x: cx + dx, y: cy + dy};
  366. }
  367. },{}],14:[function(require,module,exports){
  368. module.exports = intersectLine;
  369. /*
  370. * Returns the point at which two lines, p and q, intersect or returns
  371. * undefined if they do not intersect.
  372. */
  373. function intersectLine(p1, p2, q1, q2) {
  374. // Algorithm from J. Avro, (ed.) Graphics Gems, No 2, Morgan Kaufmann, 1994,
  375. // p7 and p473.
  376. var a1, a2, b1, b2, c1, c2;
  377. var r1, r2 , r3, r4;
  378. var denom, offset, num;
  379. var x, y;
  380. // Compute a1, b1, c1, where line joining points 1 and 2 is F(x,y) = a1 x +
  381. // b1 y + c1 = 0.
  382. a1 = p2.y - p1.y;
  383. b1 = p1.x - p2.x;
  384. c1 = (p2.x * p1.y) - (p1.x * p2.y);
  385. // Compute r3 and r4.
  386. r3 = ((a1 * q1.x) + (b1 * q1.y) + c1);
  387. r4 = ((a1 * q2.x) + (b1 * q2.y) + c1);
  388. // Check signs of r3 and r4. If both point 3 and point 4 lie on
  389. // same side of line 1, the line segments do not intersect.
  390. if ((r3 !== 0) && (r4 !== 0) && sameSign(r3, r4)) {
  391. return /*DONT_INTERSECT*/;
  392. }
  393. // Compute a2, b2, c2 where line joining points 3 and 4 is G(x,y) = a2 x + b2 y + c2 = 0
  394. a2 = q2.y - q1.y;
  395. b2 = q1.x - q2.x;
  396. c2 = (q2.x * q1.y) - (q1.x * q2.y);
  397. // Compute r1 and r2
  398. r1 = (a2 * p1.x) + (b2 * p1.yy) + c2;
  399. r2 = (a2 * p2.x) + (b2 * p2.y) + c2;
  400. // Check signs of r1 and r2. If both point 1 and point 2 lie
  401. // on same side of second line segment, the line segments do
  402. // not intersect.
  403. if ((r1 !== 0) && (r2 !== 0) && (sameSign(r1, r2))) {
  404. return /*DONT_INTERSECT*/;
  405. }
  406. // Line segments intersect: compute intersection point.
  407. denom = (a1 * b2) - (a2 * b1);
  408. if (denom === 0) {
  409. return /*COLLINEAR*/;
  410. }
  411. offset = Math.abs(denom / 2);
  412. // The denom/2 is to get rounding instead of truncating. It
  413. // is added or subtracted to the numerator, depending upon the
  414. // sign of the numerator.
  415. num = (b1 * c2) - (b2 * c1);
  416. x = (num < 0) ? ((num - offset) / denom) : ((num + offset) / denom);
  417. num = (a2 * c1) - (a1 * c2);
  418. y = (num < 0) ? ((num - offset) / denom) : ((num + offset) / denom);
  419. return { x: x, y: y };
  420. }
  421. function sameSign(r1, r2) {
  422. return r1 * r2 > 0;
  423. }
  424. },{}],15:[function(require,module,exports){
  425. module.exports = intersectNode;
  426. function intersectNode(node, point) {
  427. return node.intersect(point);
  428. }
  429. },{}],16:[function(require,module,exports){
  430. var intersectLine = require("./intersect-line");
  431. module.exports = intersectPolygon;
  432. /*
  433. * Returns the point ({x, y}) at which the point argument intersects with the
  434. * node argument assuming that it has the shape specified by polygon.
  435. */
  436. function intersectPolygon(node, polyPoints, point) {
  437. var x1 = node.x;
  438. var y1 = node.y;
  439. var intersections = [];
  440. var minX = Number.POSITIVE_INFINITY,
  441. minY = Number.POSITIVE_INFINITY;
  442. polyPoints.forEach(function(entry) {
  443. minX = Math.min(minX, entry.x);
  444. minY = Math.min(minY, entry.y);
  445. });
  446. var left = x1 - node.width / 2 - minX;
  447. var top = y1 - node.height / 2 - minY;
  448. for (var i = 0; i < polyPoints.length; i++) {
  449. var p1 = polyPoints[i];
  450. var p2 = polyPoints[i < polyPoints.length - 1 ? i + 1 : 0];
  451. var intersect = intersectLine(node, point,
  452. {x: left + p1.x, y: top + p1.y}, {x: left + p2.x, y: top + p2.y});
  453. if (intersect) {
  454. intersections.push(intersect);
  455. }
  456. }
  457. if (!intersections.length) {
  458. console.log("NO INTERSECTION FOUND, RETURN NODE CENTER", node);
  459. return node;
  460. }
  461. if (intersections.length > 1) {
  462. // More intersections, find the one nearest to edge end point
  463. intersections.sort(function(p, q) {
  464. var pdx = p.x - point.x,
  465. pdy = p.y - point.y,
  466. distp = Math.sqrt(pdx * pdx + pdy * pdy),
  467. qdx = q.x - point.x,
  468. qdy = q.y - point.y,
  469. distq = Math.sqrt(qdx * qdx + qdy * qdy);
  470. return (distp < distq) ? -1 : (distp === distq ? 0 : 1);
  471. });
  472. }
  473. return intersections[0];
  474. }
  475. },{"./intersect-line":14}],17:[function(require,module,exports){
  476. module.exports = intersectRect;
  477. function intersectRect(node, point) {
  478. var x = node.x;
  479. var y = node.y;
  480. // Rectangle intersection algorithm from:
  481. // http://math.stackexchange.com/questions/108113/find-edge-between-two-boxes
  482. var dx = point.x - x;
  483. var dy = point.y - y;
  484. var w = node.width / 2;
  485. var h = node.height / 2;
  486. var sx, sy;
  487. if (Math.abs(dy) * w > Math.abs(dx) * h) {
  488. // Intersection is top or bottom of rect.
  489. if (dy < 0) {
  490. h = -h;
  491. }
  492. sx = dy === 0 ? 0 : h * dx / dy;
  493. sy = h;
  494. } else {
  495. // Intersection is left or right of rect.
  496. if (dx < 0) {
  497. w = -w;
  498. }
  499. sx = w;
  500. sy = dx === 0 ? 0 : w * dy / dx;
  501. }
  502. return {x: x + sx, y: y + sy};
  503. }
  504. },{}],18:[function(require,module,exports){
  505. var util = require("../util");
  506. module.exports = addHtmlLabel;
  507. function addHtmlLabel(root, node) {
  508. var fo = root
  509. .append("foreignObject")
  510. .attr("width", "100000");
  511. var div = fo
  512. .append("xhtml:div");
  513. var label = node.label;
  514. switch(typeof label) {
  515. case "function":
  516. div.insert(label);
  517. break;
  518. case "object":
  519. // Currently we assume this is a DOM object.
  520. div.insert(function() { return label; });
  521. break;
  522. default: div.html(label);
  523. }
  524. util.applyStyle(div, node.labelStyle);
  525. div.style("display", "inline-block");
  526. // Fix for firefox
  527. div.style("white-space", "nowrap");
  528. // TODO find a better way to get dimensions for foreignObjects...
  529. var w, h;
  530. div
  531. .each(function() {
  532. w = this.clientWidth;
  533. h = this.clientHeight;
  534. });
  535. fo
  536. .attr("width", w)
  537. .attr("height", h);
  538. return fo;
  539. }
  540. },{"../util":28}],19:[function(require,module,exports){
  541. var addTextLabel = require("./add-text-label"),
  542. addHtmlLabel = require("./add-html-label"),
  543. addSVGLabel = require("./add-svg-label");
  544. module.exports = addLabel;
  545. function addLabel(root, node, location) {
  546. var label = node.label;
  547. var labelSvg = root.append("g");
  548. // Allow the label to be a string, a function that returns a DOM element, or
  549. // a DOM element itself.
  550. if (node.labelType === "svg") {
  551. addSVGLabel(labelSvg, node);
  552. } else if (typeof label !== "string" || node.labelType === "html") {
  553. addHtmlLabel(labelSvg, node);
  554. } else {
  555. addTextLabel(labelSvg, node);
  556. }
  557. var labelBBox = labelSvg.node().getBBox();
  558. var y;
  559. switch(location) {
  560. case "top":
  561. y = (-node.height / 2);
  562. break;
  563. case "bottom":
  564. y = (node.height / 2) - labelBBox.height;
  565. break;
  566. default:
  567. y = (-labelBBox.height / 2);
  568. }
  569. labelSvg.attr("transform",
  570. "translate(" + (-labelBBox.width / 2) + "," + y + ")");
  571. return labelSvg;
  572. }
  573. },{"./add-html-label":18,"./add-svg-label":20,"./add-text-label":21}],20:[function(require,module,exports){
  574. var util = require("../util");
  575. module.exports = addSVGLabel;
  576. function addSVGLabel(root, node) {
  577. var domNode = root;
  578. domNode.node().appendChild(node.label);
  579. util.applyStyle(domNode, node.labelStyle);
  580. return domNode;
  581. }
  582. },{"../util":28}],21:[function(require,module,exports){
  583. var util = require("../util");
  584. module.exports = addTextLabel;
  585. /*
  586. * Attaches a text label to the specified root. Handles escape sequences.
  587. */
  588. function addTextLabel(root, node) {
  589. var domNode = root.append("text");
  590. var lines = processEscapeSequences(node.label).split("\n");
  591. for (var i = 0; i < lines.length; i++) {
  592. domNode
  593. .append("tspan")
  594. .attr("xml:space", "preserve")
  595. .attr("dy", "1em")
  596. .attr("x", "1")
  597. .text(lines[i]);
  598. }
  599. util.applyStyle(domNode, node.labelStyle);
  600. return domNode;
  601. }
  602. function processEscapeSequences(text) {
  603. var newText = "",
  604. escaped = false,
  605. ch;
  606. for (var i = 0; i < text.length; ++i) {
  607. ch = text[i];
  608. if (escaped) {
  609. switch(ch) {
  610. case "n": newText += "\n"; break;
  611. default: newText += ch;
  612. }
  613. escaped = false;
  614. } else if (ch === "\\") {
  615. escaped = true;
  616. } else {
  617. newText += ch;
  618. }
  619. }
  620. return newText;
  621. }
  622. },{"../util":28}],22:[function(require,module,exports){
  623. /* global window */
  624. var lodash;
  625. if (require) {
  626. try {
  627. lodash = require("lodash");
  628. } catch (e) {}
  629. }
  630. if (!lodash) {
  631. lodash = window._;
  632. }
  633. module.exports = lodash;
  634. },{"lodash":50}],23:[function(require,module,exports){
  635. "use strict";
  636. var util = require("./util"),
  637. d3 = require("./d3");
  638. module.exports = positionClusters;
  639. function positionClusters(selection, g) {
  640. var created = selection.filter(function() { return !d3.select(this).classed("update"); });
  641. function translate(v) {
  642. var node = g.node(v);
  643. return "translate(" + node.x + "," + node.y + ")";
  644. }
  645. created.attr("transform", translate);
  646. util.applyTransition(selection, g)
  647. .style("opacity", 1)
  648. .attr("transform", translate);
  649. util.applyTransition(created.selectAll("rect"), g)
  650. .attr("width", function(v) { return g.node(v).width; })
  651. .attr("height", function(v) { return g.node(v).height; })
  652. .attr("x", function(v) {
  653. var node = g.node(v);
  654. return -node.width / 2;
  655. })
  656. .attr("y", function(v) {
  657. var node = g.node(v);
  658. return -node.height / 2;
  659. });
  660. }
  661. },{"./d3":8,"./util":28}],24:[function(require,module,exports){
  662. "use strict";
  663. var util = require("./util"),
  664. d3 = require("./d3"),
  665. _ = require("./lodash");
  666. module.exports = positionEdgeLabels;
  667. function positionEdgeLabels(selection, g) {
  668. var created = selection.filter(function() { return !d3.select(this).classed("update"); });
  669. function translate(e) {
  670. var edge = g.edge(e);
  671. return _.has(edge, "x") ? "translate(" + edge.x + "," + edge.y + ")" : "";
  672. }
  673. created.attr("transform", translate);
  674. util.applyTransition(selection, g)
  675. .style("opacity", 1)
  676. .attr("transform", translate);
  677. }
  678. },{"./d3":8,"./lodash":22,"./util":28}],25:[function(require,module,exports){
  679. "use strict";
  680. var util = require("./util"),
  681. d3 = require("./d3");
  682. module.exports = positionNodes;
  683. function positionNodes(selection, g) {
  684. var created = selection.filter(function() { return !d3.select(this).classed("update"); });
  685. function translate(v) {
  686. var node = g.node(v);
  687. return "translate(" + node.x + "," + node.y + ")";
  688. }
  689. created.attr("transform", translate);
  690. util.applyTransition(selection, g)
  691. .style("opacity", 1)
  692. .attr("transform", translate);
  693. }
  694. },{"./d3":8,"./util":28}],26:[function(require,module,exports){
  695. var _ = require("./lodash"),
  696. layout = require("./dagre").layout;
  697. module.exports = render;
  698. // This design is based on http://bost.ocks.org/mike/chart/.
  699. function render() {
  700. var createNodes = require("./create-nodes"),
  701. createClusters = require("./create-clusters"),
  702. createEdgeLabels = require("./create-edge-labels"),
  703. createEdgePaths = require("./create-edge-paths"),
  704. positionNodes = require("./position-nodes"),
  705. positionEdgeLabels = require("./position-edge-labels"),
  706. positionClusters = require("./position-clusters"),
  707. shapes = require("./shapes"),
  708. arrows = require("./arrows");
  709. var fn = function(svg, g) {
  710. preProcessGraph(g);
  711. var outputGroup = createOrSelectGroup(svg, "output"),
  712. clustersGroup = createOrSelectGroup(outputGroup, "clusters"),
  713. edgePathsGroup = createOrSelectGroup(outputGroup, "edgePaths"),
  714. edgeLabels = createEdgeLabels(createOrSelectGroup(outputGroup, "edgeLabels"), g),
  715. nodes = createNodes(createOrSelectGroup(outputGroup, "nodes"), g, shapes);
  716. layout(g);
  717. positionNodes(nodes, g);
  718. positionEdgeLabels(edgeLabels, g);
  719. createEdgePaths(edgePathsGroup, g, arrows);
  720. var clusters = createClusters(clustersGroup, g);
  721. positionClusters(clusters, g);
  722. postProcessGraph(g);
  723. };
  724. fn.createNodes = function(value) {
  725. if (!arguments.length) return createNodes;
  726. createNodes = value;
  727. return fn;
  728. };
  729. fn.createClusters = function(value) {
  730. if (!arguments.length) return createClusters;
  731. createClusters = value;
  732. return fn;
  733. };
  734. fn.createEdgeLabels = function(value) {
  735. if (!arguments.length) return createEdgeLabels;
  736. createEdgeLabels = value;
  737. return fn;
  738. };
  739. fn.createEdgePaths = function(value) {
  740. if (!arguments.length) return createEdgePaths;
  741. createEdgePaths = value;
  742. return fn;
  743. };
  744. fn.shapes = function(value) {
  745. if (!arguments.length) return shapes;
  746. shapes = value;
  747. return fn;
  748. };
  749. fn.arrows = function(value) {
  750. if (!arguments.length) return arrows;
  751. arrows = value;
  752. return fn;
  753. };
  754. return fn;
  755. }
  756. var NODE_DEFAULT_ATTRS = {
  757. paddingLeft: 10,
  758. paddingRight: 10,
  759. paddingTop: 10,
  760. paddingBottom: 10,
  761. rx: 0,
  762. ry: 0,
  763. shape: "rect"
  764. };
  765. var EDGE_DEFAULT_ATTRS = {
  766. arrowhead: "normal",
  767. lineInterpolate: "linear"
  768. };
  769. function preProcessGraph(g) {
  770. g.nodes().forEach(function(v) {
  771. var node = g.node(v);
  772. if (!_.has(node, "label") && !g.children(v).length) { node.label = v; }
  773. if (_.has(node, "paddingX")) {
  774. _.defaults(node, {
  775. paddingLeft: node.paddingX,
  776. paddingRight: node.paddingX
  777. });
  778. }
  779. if (_.has(node, "paddingY")) {
  780. _.defaults(node, {
  781. paddingTop: node.paddingY,
  782. paddingBottom: node.paddingY
  783. });
  784. }
  785. if (_.has(node, "padding")) {
  786. _.defaults(node, {
  787. paddingLeft: node.padding,
  788. paddingRight: node.padding,
  789. paddingTop: node.padding,
  790. paddingBottom: node.padding
  791. });
  792. }
  793. _.defaults(node, NODE_DEFAULT_ATTRS);
  794. _.each(["paddingLeft", "paddingRight", "paddingTop", "paddingBottom"], function(k) {
  795. node[k] = Number(node[k]);
  796. });
  797. // Save dimensions for restore during post-processing
  798. if (_.has(node, "width")) { node._prevWidth = node.width; }
  799. if (_.has(node, "height")) { node._prevHeight = node.height; }
  800. });
  801. g.edges().forEach(function(e) {
  802. var edge = g.edge(e);
  803. if (!_.has(edge, "label")) { edge.label = ""; }
  804. _.defaults(edge, EDGE_DEFAULT_ATTRS);
  805. });
  806. }
  807. function postProcessGraph(g) {
  808. _.each(g.nodes(), function(v) {
  809. var node = g.node(v);
  810. // Restore original dimensions
  811. if (_.has(node, "_prevWidth")) {
  812. node.width = node._prevWidth;
  813. } else {
  814. delete node.width;
  815. }
  816. if (_.has(node, "_prevHeight")) {
  817. node.height = node._prevHeight;
  818. } else {
  819. delete node.height;
  820. }
  821. delete node._prevWidth;
  822. delete node._prevHeight;
  823. });
  824. }
  825. function createOrSelectGroup(root, name) {
  826. var selection = root.select("g." + name);
  827. if (selection.empty()) {
  828. selection = root.append("g").attr("class", name);
  829. }
  830. return selection;
  831. }
  832. },{"./arrows":3,"./create-clusters":4,"./create-edge-labels":5,"./create-edge-paths":6,"./create-nodes":7,"./dagre":9,"./lodash":22,"./position-clusters":23,"./position-edge-labels":24,"./position-nodes":25,"./shapes":27}],27:[function(require,module,exports){
  833. "use strict";
  834. var intersectRect = require("./intersect/intersect-rect"),
  835. intersectEllipse = require("./intersect/intersect-ellipse"),
  836. intersectCircle = require("./intersect/intersect-circle"),
  837. intersectPolygon = require("./intersect/intersect-polygon");
  838. module.exports = {
  839. rect: rect,
  840. ellipse: ellipse,
  841. circle: circle,
  842. diamond: diamond
  843. };
  844. function rect(parent, bbox, node) {
  845. var shapeSvg = parent.insert("rect", ":first-child")
  846. .attr("rx", node.rx)
  847. .attr("ry", node.ry)
  848. .attr("x", -bbox.width / 2)
  849. .attr("y", -bbox.height / 2)
  850. .attr("width", bbox.width)
  851. .attr("height", bbox.height);
  852. node.intersect = function(point) {
  853. return intersectRect(node, point);
  854. };
  855. return shapeSvg;
  856. }
  857. function ellipse(parent, bbox, node) {
  858. var rx = bbox.width / 2,
  859. ry = bbox.height / 2,
  860. shapeSvg = parent.insert("ellipse", ":first-child")
  861. .attr("x", -bbox.width / 2)
  862. .attr("y", -bbox.height / 2)
  863. .attr("rx", rx)
  864. .attr("ry", ry);
  865. node.intersect = function(point) {
  866. return intersectEllipse(node, rx, ry, point);
  867. };
  868. return shapeSvg;
  869. }
  870. function circle(parent, bbox, node) {
  871. var r = Math.max(bbox.width, bbox.height) / 2,
  872. shapeSvg = parent.insert("circle", ":first-child")
  873. .attr("x", -bbox.width / 2)
  874. .attr("y", -bbox.height / 2)
  875. .attr("r", r);
  876. node.intersect = function(point) {
  877. return intersectCircle(node, r, point);
  878. };
  879. return shapeSvg;
  880. }
  881. // Circumscribe an ellipse for the bounding box with a diamond shape. I derived
  882. // the function to calculate the diamond shape from:
  883. // http://mathforum.org/kb/message.jspa?messageID=3750236
  884. function diamond(parent, bbox, node) {
  885. var w = (bbox.width * Math.SQRT2) / 2,
  886. h = (bbox.height * Math.SQRT2) / 2,
  887. points = [
  888. { x: 0, y: -h },
  889. { x: -w, y: 0 },
  890. { x: 0, y: h },
  891. { x: w, y: 0 }
  892. ],
  893. shapeSvg = parent.insert("polygon", ":first-child")
  894. .attr("points", points.map(function(p) { return p.x + "," + p.y; }).join(" "));
  895. node.intersect = function(p) {
  896. return intersectPolygon(node, points, p);
  897. };
  898. return shapeSvg;
  899. }
  900. },{"./intersect/intersect-circle":12,"./intersect/intersect-ellipse":13,"./intersect/intersect-polygon":16,"./intersect/intersect-rect":17}],28:[function(require,module,exports){
  901. var _ = require("./lodash");
  902. // Public utility functions
  903. module.exports = {
  904. isSubgraph: isSubgraph,
  905. edgeToId: edgeToId,
  906. applyStyle: applyStyle,
  907. applyClass: applyClass,
  908. applyTransition: applyTransition
  909. };
  910. /*
  911. * Returns true if the specified node in the graph is a subgraph node. A
  912. * subgraph node is one that contains other nodes.
  913. */
  914. function isSubgraph(g, v) {
  915. return !!g.children(v).length;
  916. }
  917. function edgeToId(e) {
  918. return escapeId(e.v) + ":" + escapeId(e.w) + ":" + escapeId(e.name);
  919. }
  920. var ID_DELIM = /:/g;
  921. function escapeId(str) {
  922. return str ? String(str).replace(ID_DELIM, "\\:") : "";
  923. }
  924. function applyStyle(dom, styleFn) {
  925. if (styleFn) {
  926. dom.attr("style", styleFn);
  927. }
  928. }
  929. function applyClass(dom, classFn, otherClasses) {
  930. if (classFn) {
  931. dom
  932. .attr("class", classFn)
  933. .attr("class", otherClasses + " " + dom.attr("class"));
  934. }
  935. }
  936. function applyTransition(selection, g) {
  937. var graph = g.graph();
  938. if (_.isPlainObject(graph)) {
  939. var transition = graph.transition;
  940. if (_.isFunction(transition)) {
  941. return transition(selection);
  942. }
  943. }
  944. return selection;
  945. }
  946. },{"./lodash":22}],29:[function(require,module,exports){
  947. module.exports = "0.4.10";
  948. },{}],30:[function(require,module,exports){
  949. /**
  950. * Copyright (c) 2014, Chris Pettitt
  951. * All rights reserved.
  952. *
  953. * Redistribution and use in source and binary forms, with or without
  954. * modification, are permitted provided that the following conditions are met:
  955. *
  956. * 1. Redistributions of source code must retain the above copyright notice, this
  957. * list of conditions and the following disclaimer.
  958. *
  959. * 2. Redistributions in binary form must reproduce the above copyright notice,
  960. * this list of conditions and the following disclaimer in the documentation
  961. * and/or other materials provided with the distribution.
  962. *
  963. * 3. Neither the name of the copyright holder nor the names of its contributors
  964. * may be used to endorse or promote products derived from this software without
  965. * specific prior written permission.
  966. *
  967. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  968. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  969. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  970. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  971. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  972. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  973. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  974. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  975. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  976. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  977. */
  978. var lib = require("./lib");
  979. module.exports = {
  980. Graph: lib.Graph,
  981. json: require("./lib/json"),
  982. alg: require("./lib/alg"),
  983. version: lib.version
  984. };
  985. },{"./lib":46,"./lib/alg":37,"./lib/json":47}],31:[function(require,module,exports){
  986. var _ = require("../lodash");
  987. module.exports = components;
  988. function components(g) {
  989. var visited = {},
  990. cmpts = [],
  991. cmpt;
  992. function dfs(v) {
  993. if (_.has(visited, v)) return;
  994. visited[v] = true;
  995. cmpt.push(v);
  996. _.each(g.successors(v), dfs);
  997. _.each(g.predecessors(v), dfs);
  998. }
  999. _.each(g.nodes(), function(v) {
  1000. cmpt = [];
  1001. dfs(v);
  1002. if (cmpt.length) {
  1003. cmpts.push(cmpt);
  1004. }
  1005. });
  1006. return cmpts;
  1007. }
  1008. },{"../lodash":48}],32:[function(require,module,exports){
  1009. var _ = require("../lodash");
  1010. module.exports = dfs;
  1011. /*
  1012. * A helper that preforms a pre- or post-order traversal on the input graph
  1013. * and returns the nodes in the order they were visited. This algorithm treats
  1014. * the input as undirected.
  1015. *
  1016. * Order must be one of "pre" or "post".
  1017. */
  1018. function dfs(g, vs, order) {
  1019. if (!_.isArray(vs)) {
  1020. vs = [vs];
  1021. }
  1022. var acc = [],
  1023. visited = {};
  1024. _.each(vs, function(v) {
  1025. if (!g.hasNode(v)) {
  1026. throw new Error("Graph does not have node: " + v);
  1027. }
  1028. doDfs(g, v, order === "post", visited, acc);
  1029. });
  1030. return acc;
  1031. }
  1032. function doDfs(g, v, postorder, visited, acc) {
  1033. if (!_.has(visited, v)) {
  1034. visited[v] = true;
  1035. if (!postorder) { acc.push(v); }
  1036. _.each(g.neighbors(v), function(w) {
  1037. doDfs(g, w, postorder, visited, acc);
  1038. });
  1039. if (postorder) { acc.push(v); }
  1040. }
  1041. }
  1042. },{"../lodash":48}],33:[function(require,module,exports){
  1043. var dijkstra = require("./dijkstra"),
  1044. _ = require("../lodash");
  1045. module.exports = dijkstraAll;
  1046. function dijkstraAll(g, weightFunc, edgeFunc) {
  1047. return _.transform(g.nodes(), function(acc, v) {
  1048. acc[v] = dijkstra(g, v, weightFunc, edgeFunc);
  1049. }, {});
  1050. }
  1051. },{"../lodash":48,"./dijkstra":34}],34:[function(require,module,exports){
  1052. var _ = require("../lodash"),
  1053. PriorityQueue = require("../data/priority-queue");
  1054. module.exports = dijkstra;
  1055. var DEFAULT_WEIGHT_FUNC = _.constant(1);
  1056. function dijkstra(g, source, weightFn, edgeFn) {
  1057. return runDijkstra(g, String(source),
  1058. weightFn || DEFAULT_WEIGHT_FUNC,
  1059. edgeFn || function(v) { return g.outEdges(v); });
  1060. }
  1061. function runDijkstra(g, source, weightFn, edgeFn) {
  1062. var results = {},
  1063. pq = new PriorityQueue(),
  1064. v, vEntry;
  1065. var updateNeighbors = function(edge) {
  1066. var w = edge.v !== v ? edge.v : edge.w,
  1067. wEntry = results[w],
  1068. weight = weightFn(edge),
  1069. distance = vEntry.distance + weight;
  1070. if (weight < 0) {
  1071. throw new Error("dijkstra does not allow negative edge weights. " +
  1072. "Bad edge: " + edge + " Weight: " + weight);
  1073. }
  1074. if (distance < wEntry.distance) {
  1075. wEntry.distance = distance;
  1076. wEntry.predecessor = v;
  1077. pq.decrease(w, distance);
  1078. }
  1079. };
  1080. g.nodes().forEach(function(v) {
  1081. var distance = v === source ? 0 : Number.POSITIVE_INFINITY;
  1082. results[v] = { distance: distance };
  1083. pq.add(v, distance);
  1084. });
  1085. while (pq.size() > 0) {
  1086. v = pq.removeMin();
  1087. vEntry = results[v];
  1088. if (vEntry.distance === Number.POSITIVE_INFINITY) {
  1089. break;
  1090. }
  1091. edgeFn(v).forEach(updateNeighbors);
  1092. }
  1093. return results;
  1094. }
  1095. },{"../data/priority-queue":44,"../lodash":48}],35:[function(require,module,exports){
  1096. var _ = require("../lodash"),
  1097. tarjan = require("./tarjan");
  1098. module.exports = findCycles;
  1099. function findCycles(g) {
  1100. return _.filter(tarjan(g), function(cmpt) {
  1101. return cmpt.length > 1 || (cmpt.length === 1 && g.hasEdge(cmpt[0], cmpt[0]));
  1102. });
  1103. }
  1104. },{"../lodash":48,"./tarjan":42}],36:[function(require,module,exports){
  1105. var _ = require("../lodash");
  1106. module.exports = floydWarshall;
  1107. var DEFAULT_WEIGHT_FUNC = _.constant(1);
  1108. function floydWarshall(g, weightFn, edgeFn) {
  1109. return runFloydWarshall(g,
  1110. weightFn || DEFAULT_WEIGHT_FUNC,
  1111. edgeFn || function(v) { return g.outEdges(v); });
  1112. }
  1113. function runFloydWarshall(g, weightFn, edgeFn) {
  1114. var results = {},
  1115. nodes = g.nodes();
  1116. nodes.forEach(function(v) {
  1117. results[v] = {};
  1118. results[v][v] = { distance: 0 };
  1119. nodes.forEach(function(w) {
  1120. if (v !== w) {
  1121. results[v][w] = { distance: Number.POSITIVE_INFINITY };
  1122. }
  1123. });
  1124. edgeFn(v).forEach(function(edge) {
  1125. var w = edge.v === v ? edge.w : edge.v,
  1126. d = weightFn(edge);
  1127. results[v][w] = { distance: d, predecessor: v };
  1128. });
  1129. });
  1130. nodes.forEach(function(k) {
  1131. var rowK = results[k];
  1132. nodes.forEach(function(i) {
  1133. var rowI = results[i];
  1134. nodes.forEach(function(j) {
  1135. var ik = rowI[k];
  1136. var kj = rowK[j];
  1137. var ij = rowI[j];
  1138. var altDistance = ik.distance + kj.distance;
  1139. if (altDistance < ij.distance) {
  1140. ij.distance = altDistance;
  1141. ij.predecessor = kj.predecessor;
  1142. }
  1143. });
  1144. });
  1145. });
  1146. return results;
  1147. }
  1148. },{"../lodash":48}],37:[function(require,module,exports){
  1149. module.exports = {
  1150. components: require("./components"),
  1151. dijkstra: require("./dijkstra"),
  1152. dijkstraAll: require("./dijkstra-all"),
  1153. findCycles: require("./find-cycles"),
  1154. floydWarshall: require("./floyd-warshall"),
  1155. isAcyclic: require("./is-acyclic"),
  1156. postorder: require("./postorder"),
  1157. preorder: require("./preorder"),
  1158. prim: require("./prim"),
  1159. tarjan: require("./tarjan"),
  1160. topsort: require("./topsort")
  1161. };
  1162. },{"./components":31,"./dijkstra":34,"./dijkstra-all":33,"./find-cycles":35,"./floyd-warshall":36,"./is-acyclic":38,"./postorder":39,"./preorder":40,"./prim":41,"./tarjan":42,"./topsort":43}],38:[function(require,module,exports){
  1163. var topsort = require("./topsort");
  1164. module.exports = isAcyclic;
  1165. function isAcyclic(g) {
  1166. try {
  1167. topsort(g);
  1168. } catch (e) {
  1169. if (e instanceof topsort.CycleException) {
  1170. return false;
  1171. }
  1172. throw e;
  1173. }
  1174. return true;
  1175. }
  1176. },{"./topsort":43}],39:[function(require,module,exports){
  1177. var dfs = require("./dfs");
  1178. module.exports = postorder;
  1179. function postorder(g, vs) {
  1180. return dfs(g, vs, "post");
  1181. }
  1182. },{"./dfs":32}],40:[function(require,module,exports){
  1183. var dfs = require("./dfs");
  1184. module.exports = preorder;
  1185. function preorder(g, vs) {
  1186. return dfs(g, vs, "pre");
  1187. }
  1188. },{"./dfs":32}],41:[function(require,module,exports){
  1189. var _ = require("../lodash"),
  1190. Graph = require("../graph"),
  1191. PriorityQueue = require("../data/priority-queue");
  1192. module.exports = prim;
  1193. function prim(g, weightFunc) {
  1194. var result = new Graph(),
  1195. parents = {},
  1196. pq = new PriorityQueue(),
  1197. v;
  1198. function updateNeighbors(edge) {
  1199. var w = edge.v === v ? edge.w : edge.v,
  1200. pri = pq.priority(w);
  1201. if (pri !== undefined) {
  1202. var edgeWeight = weightFunc(edge);
  1203. if (edgeWeight < pri) {
  1204. parents[w] = v;
  1205. pq.decrease(w, edgeWeight);
  1206. }
  1207. }
  1208. }
  1209. if (g.nodeCount() === 0) {
  1210. return result;
  1211. }
  1212. _.each(g.nodes(), function(v) {
  1213. pq.add(v, Number.POSITIVE_INFINITY);
  1214. result.setNode(v);
  1215. });
  1216. // Start from an arbitrary node
  1217. pq.decrease(g.nodes()[0], 0);
  1218. var init = false;
  1219. while (pq.size() > 0) {
  1220. v = pq.removeMin();
  1221. if (_.has(parents, v)) {
  1222. result.setEdge(v, parents[v]);
  1223. } else if (init) {
  1224. throw new Error("Input graph is not connected: " + g);
  1225. } else {
  1226. init = true;
  1227. }
  1228. g.nodeEdges(v).forEach(updateNeighbors);
  1229. }
  1230. return result;
  1231. }
  1232. },{"../data/priority-queue":44,"../graph":45,"../lodash":48}],42:[function(require,module,exports){
  1233. var _ = require("../lodash");
  1234. module.exports = tarjan;
  1235. function tarjan(g) {
  1236. var index = 0,
  1237. stack = [],
  1238. visited = {}, // node id -> { onStack, lowlink, index }
  1239. results = [];
  1240. function dfs(v) {
  1241. var entry = visited[v] = {
  1242. onStack: true,
  1243. lowlink: index,
  1244. index: index++
  1245. };
  1246. stack.push(v);
  1247. g.successors(v).forEach(function(w) {
  1248. if (!_.has(visited, w)) {
  1249. dfs(w);
  1250. entry.lowlink = Math.min(entry.lowlink, visited[w].lowlink);
  1251. } else if (visited[w].onStack) {
  1252. entry.lowlink = Math.min(entry.lowlink, visited[w].index);
  1253. }
  1254. });
  1255. if (entry.lowlink === entry.index) {
  1256. var cmpt = [],
  1257. w;
  1258. do {
  1259. w = stack.pop();
  1260. visited[w].onStack = false;
  1261. cmpt.push(w);
  1262. } while (v !== w);
  1263. results.push(cmpt);
  1264. }
  1265. }
  1266. g.nodes().forEach(function(v) {
  1267. if (!_.has(visited, v)) {
  1268. dfs(v);
  1269. }
  1270. });
  1271. return results;
  1272. }
  1273. },{"../lodash":48}],43:[function(require,module,exports){
  1274. var _ = require("../lodash");
  1275. module.exports = topsort;
  1276. topsort.CycleException = CycleException;
  1277. function topsort(g) {
  1278. var visited = {},
  1279. stack = {},
  1280. results = [];
  1281. function visit(node) {
  1282. if (_.has(stack, node)) {
  1283. throw new CycleException();
  1284. }
  1285. if (!_.has(visited, node)) {
  1286. stack[node] = true;
  1287. visited[node] = true;
  1288. _.each(g.predecessors(node), visit);
  1289. delete stack[node];
  1290. results.push(node);
  1291. }
  1292. }
  1293. _.each(g.sinks(), visit);
  1294. if (_.size(visited) !== g.nodeCount()) {
  1295. throw new CycleException();
  1296. }
  1297. return results;
  1298. }
  1299. function CycleException() {}
  1300. },{"../lodash":48}],44:[function(require,module,exports){
  1301. var _ = require("../lodash");
  1302. module.exports = PriorityQueue;
  1303. /**
  1304. * A min-priority queue data structure. This algorithm is derived from Cormen,
  1305. * et al., "Introduction to Algorithms". The basic idea of a min-priority
  1306. * queue is that you can efficiently (in O(1) time) get the smallest key in
  1307. * the queue. Adding and removing elements takes O(log n) time. A key can
  1308. * have its priority decreased in O(log n) time.
  1309. */
  1310. function PriorityQueue() {
  1311. this._arr = [];
  1312. this._keyIndices = {};
  1313. }
  1314. /**
  1315. * Returns the number of elements in the queue. Takes `O(1)` time.
  1316. */
  1317. PriorityQueue.prototype.size = function() {
  1318. return this._arr.length;
  1319. };
  1320. /**
  1321. * Returns the keys that are in the queue. Takes `O(n)` time.
  1322. */
  1323. PriorityQueue.prototype.keys = function() {
  1324. return this._arr.map(function(x) { return x.key; });
  1325. };
  1326. /**
  1327. * Returns `true` if **key** is in the queue and `false` if not.
  1328. */
  1329. PriorityQueue.prototype.has = function(key) {
  1330. return _.has(this._keyIndices, key);
  1331. };
  1332. /**
  1333. * Returns the priority for **key**. If **key** is not present in the queue
  1334. * then this function returns `undefined`. Takes `O(1)` time.
  1335. *
  1336. * @param {Object} key
  1337. */
  1338. PriorityQueue.prototype.priority = function(key) {
  1339. var index = this._keyIndices[key];
  1340. if (index !== undefined) {
  1341. return this._arr[index].priority;
  1342. }
  1343. };
  1344. /**
  1345. * Returns the key for the minimum element in this queue. If the queue is
  1346. * empty this function throws an Error. Takes `O(1)` time.
  1347. */
  1348. PriorityQueue.prototype.min = function() {
  1349. if (this.size() === 0) {
  1350. throw new Error("Queue underflow");
  1351. }
  1352. return this._arr[0].key;
  1353. };
  1354. /**
  1355. * Inserts a new key into the priority queue. If the key already exists in
  1356. * the queue this function returns `false`; otherwise it will return `true`.
  1357. * Takes `O(n)` time.
  1358. *
  1359. * @param {Object} key the key to add
  1360. * @param {Number} priority the initial priority for the key
  1361. */
  1362. PriorityQueue.prototype.add = function(key, priority) {
  1363. var keyIndices = this._keyIndices;
  1364. key = String(key);
  1365. if (!_.has(keyIndices, key)) {
  1366. var arr = this._arr;
  1367. var index = arr.length;
  1368. keyIndices[key] = index;
  1369. arr.push({key: key, priority: priority});
  1370. this._decrease(index);
  1371. return true;
  1372. }
  1373. return false;
  1374. };
  1375. /**
  1376. * Removes and returns the smallest key in the queue. Takes `O(log n)` time.
  1377. */
  1378. PriorityQueue.prototype.removeMin = function() {
  1379. this._swap(0, this._arr.length - 1);
  1380. var min = this._arr.pop();
  1381. delete this._keyIndices[min.key];
  1382. this._heapify(0);
  1383. return min.key;
  1384. };
  1385. /**
  1386. * Decreases the priority for **key** to **priority**. If the new priority is
  1387. * greater than the previous priority, this function will throw an Error.
  1388. *
  1389. * @param {Object} key the key for which to raise priority
  1390. * @param {Number} priority the new priority for the key
  1391. */
  1392. PriorityQueue.prototype.decrease = function(key, priority) {
  1393. var index = this._keyIndices[key];
  1394. if (priority > this._arr[index].priority) {
  1395. throw new Error("New priority is greater than current priority. " +
  1396. "Key: " + key + " Old: " + this._arr[index].priority + " New: " + priority);
  1397. }
  1398. this._arr[index].priority = priority;
  1399. this._decrease(index);
  1400. };
  1401. PriorityQueue.prototype._heapify = function(i) {
  1402. var arr = this._arr;
  1403. var l = 2 * i,
  1404. r = l + 1,
  1405. largest = i;
  1406. if (l < arr.length) {
  1407. largest = arr[l].priority < arr[largest].priority ? l : largest;
  1408. if (r < arr.length) {
  1409. largest = arr[r].priority < arr[largest].priority ? r : largest;
  1410. }
  1411. if (largest !== i) {
  1412. this._swap(i, largest);
  1413. this._heapify(largest);
  1414. }
  1415. }
  1416. };
  1417. PriorityQueue.prototype._decrease = function(index) {
  1418. var arr = this._arr;
  1419. var priority = arr[index].priority;
  1420. var parent;
  1421. while (index !== 0) {
  1422. parent = index >> 1;
  1423. if (arr[parent].priority < priority) {
  1424. break;
  1425. }
  1426. this._swap(index, parent);
  1427. index = parent;
  1428. }
  1429. };
  1430. PriorityQueue.prototype._swap = function(i, j) {
  1431. var arr = this._arr;
  1432. var keyIndices = this._keyIndices;
  1433. var origArrI = arr[i];
  1434. var origArrJ = arr[j];
  1435. arr[i] = origArrJ;
  1436. arr[j] = origArrI;
  1437. keyIndices[origArrJ.key] = i;
  1438. keyIndices[origArrI.key] = j;
  1439. };
  1440. },{"../lodash":48}],45:[function(require,module,exports){
  1441. "use strict";
  1442. var _ = require("./lodash");
  1443. module.exports = Graph;
  1444. var DEFAULT_EDGE_NAME = "\x00",
  1445. GRAPH_NODE = "\x00",
  1446. EDGE_KEY_DELIM = "\x01";
  1447. // Implementation notes:
  1448. //
  1449. // * Node id query functions should return string ids for the nodes
  1450. // * Edge id query functions should return an "edgeObj", edge object, that is
  1451. // composed of enough information to uniquely identify an edge: {v, w, name}.
  1452. // * Internally we use an "edgeId", a stringified form of the edgeObj, to
  1453. // reference edges. This is because we need a performant way to look these
  1454. // edges up and, object properties, which have string keys, are the closest
  1455. // we're going to get to a performant hashtable in JavaScript.
  1456. function Graph(opts) {
  1457. this._isDirected = _.has(opts, "directed") ? opts.directed : true;
  1458. this._isMultigraph = _.has(opts, "multigraph") ? opts.multigraph : false;
  1459. this._isCompound = _.has(opts, "compound") ? opts.compound : false;
  1460. // Label for the graph itself
  1461. this._label = undefined;
  1462. // Defaults to be set when creating a new node
  1463. this._defaultNodeLabelFn = _.constant(undefined);
  1464. // Defaults to be set when creating a new edge
  1465. this._defaultEdgeLabelFn = _.constant(undefined);
  1466. // v -> label
  1467. this._nodes = {};
  1468. if (this._isCompound) {
  1469. // v -> parent
  1470. this._parent = {};
  1471. // v -> children
  1472. this._children = {};
  1473. this._children[GRAPH_NODE] = {};
  1474. }
  1475. // v -> edgeObj
  1476. this._in = {};
  1477. // u -> v -> Number
  1478. this._preds = {};
  1479. // v -> edgeObj
  1480. this._out = {};
  1481. // v -> w -> Number
  1482. this._sucs = {};
  1483. // e -> edgeObj
  1484. this._edgeObjs = {};
  1485. // e -> label
  1486. this._edgeLabels = {};
  1487. }
  1488. /* Number of nodes in the graph. Should only be changed by the implementation. */
  1489. Graph.prototype._nodeCount = 0;
  1490. /* Number of edges in the graph. Should only be changed by the implementation. */
  1491. Graph.prototype._edgeCount = 0;
  1492. /* === Graph functions ========= */
  1493. Graph.prototype.isDirected = function() {
  1494. return this._isDirected;
  1495. };
  1496. Graph.prototype.isMultigraph = function() {
  1497. return this._isMultigraph;
  1498. };
  1499. Graph.prototype.isCompound = function() {
  1500. return this._isCompound;
  1501. };
  1502. Graph.prototype.setGraph = function(label) {
  1503. this._label = label;
  1504. return this;
  1505. };
  1506. Graph.prototype.graph = function() {
  1507. return this._label;
  1508. };
  1509. /* === Node functions ========== */
  1510. Graph.prototype.setDefaultNodeLabel = function(newDefault) {
  1511. if (!_.isFunction(newDefault)) {
  1512. newDefault = _.constant(newDefault);
  1513. }
  1514. this._defaultNodeLabelFn = newDefault;
  1515. return this;
  1516. };
  1517. Graph.prototype.nodeCount = function() {
  1518. return this._nodeCount;
  1519. };
  1520. Graph.prototype.nodes = function() {
  1521. return _.keys(this._nodes);
  1522. };
  1523. Graph.prototype.sources = function() {
  1524. return _.filter(this.nodes(), function(v) {
  1525. return _.isEmpty(this._in[v]);
  1526. }, this);
  1527. };
  1528. Graph.prototype.sinks = function() {
  1529. return _.filter(this.nodes(), function(v) {
  1530. return _.isEmpty(this._out[v]);
  1531. }, this);
  1532. };
  1533. Graph.prototype.setNodes = function(vs, value) {
  1534. var args = arguments;
  1535. _.each(vs, function(v) {
  1536. if (args.length > 1) {
  1537. this.setNode(v, value);
  1538. } else {
  1539. this.setNode(v);
  1540. }
  1541. }, this);
  1542. return this;
  1543. };
  1544. Graph.prototype.setNode = function(v, value) {
  1545. if (_.has(this._nodes, v)) {
  1546. if (arguments.length > 1) {
  1547. this._nodes[v] = value;
  1548. }
  1549. return this;
  1550. }
  1551. this._nodes[v] = arguments.length > 1 ? value : this._defaultNodeLabelFn(v);
  1552. if (this._isCompound) {
  1553. this._parent[v] = GRAPH_NODE;
  1554. this._children[v] = {};
  1555. this._children[GRAPH_NODE][v] = true;
  1556. }
  1557. this._in[v] = {};
  1558. this._preds[v] = {};
  1559. this._out[v] = {};
  1560. this._sucs[v] = {};
  1561. ++this._nodeCount;
  1562. return this;
  1563. };
  1564. Graph.prototype.node = function(v) {
  1565. return this._nodes[v];
  1566. };
  1567. Graph.prototype.hasNode = function(v) {
  1568. return _.has(this._nodes, v);
  1569. };
  1570. Graph.prototype.removeNode = function(v) {
  1571. var self = this;
  1572. if (_.has(this._nodes, v)) {
  1573. var removeEdge = function(e) { self.removeEdge(self._edgeObjs[e]); };
  1574. delete this._nodes[v];
  1575. if (this._isCompound) {
  1576. this._removeFromParentsChildList(v);
  1577. delete this._parent[v];
  1578. _.each(this.children(v), function(child) {
  1579. this.setParent(child);
  1580. }, this);
  1581. delete this._children[v];
  1582. }
  1583. _.each(_.keys(this._in[v]), removeEdge);
  1584. delete this._in[v];
  1585. delete this._preds[v];
  1586. _.each(_.keys(this._out[v]), removeEdge);
  1587. delete this._out[v];
  1588. delete this._sucs[v];
  1589. --this._nodeCount;
  1590. }
  1591. return this;
  1592. };
  1593. Graph.prototype.setParent = function(v, parent) {
  1594. if (!this._isCompound) {
  1595. throw new Error("Cannot set parent in a non-compound graph");
  1596. }
  1597. if (_.isUndefined(parent)) {
  1598. parent = GRAPH_NODE;
  1599. } else {
  1600. // Coerce parent to string
  1601. parent += "";
  1602. for (var ancestor = parent;
  1603. !_.isUndefined(ancestor);
  1604. ancestor = this.parent(ancestor)) {
  1605. if (ancestor === v) {
  1606. throw new Error("Setting " + parent+ " as parent of " + v +
  1607. " would create create a cycle");
  1608. }
  1609. }
  1610. this.setNode(parent);
  1611. }
  1612. this.setNode(v);
  1613. this._removeFromParentsChildList(v);
  1614. this._parent[v] = parent;
  1615. this._children[parent][v] = true;
  1616. return this;
  1617. };
  1618. Graph.prototype._removeFromParentsChildList = function(v) {
  1619. delete this._children[this._parent[v]][v];
  1620. };
  1621. Graph.prototype.parent = function(v) {
  1622. if (this._isCompound) {
  1623. var parent = this._parent[v];
  1624. if (parent !== GRAPH_NODE) {
  1625. return parent;
  1626. }
  1627. }
  1628. };
  1629. Graph.prototype.children = function(v) {
  1630. if (_.isUndefined(v)) {
  1631. v = GRAPH_NODE;
  1632. }
  1633. if (this._isCompound) {
  1634. var children = this._children[v];
  1635. if (children) {
  1636. return _.keys(children);
  1637. }
  1638. } else if (v === GRAPH_NODE) {
  1639. return this.nodes();
  1640. } else if (this.hasNode(v)) {
  1641. return [];
  1642. }
  1643. };
  1644. Graph.prototype.predecessors = function(v) {
  1645. var predsV = this._preds[v];
  1646. if (predsV) {
  1647. return _.keys(predsV);
  1648. }
  1649. };
  1650. Graph.prototype.successors = function(v) {
  1651. var sucsV = this._sucs[v];
  1652. if (sucsV) {
  1653. return _.keys(sucsV);
  1654. }
  1655. };
  1656. Graph.prototype.neighbors = function(v) {
  1657. var preds = this.predecessors(v);
  1658. if (preds) {
  1659. return _.union(preds, this.successors(v));
  1660. }
  1661. };
  1662. Graph.prototype.filterNodes = function(filter) {
  1663. var copy = new this.constructor({
  1664. directed: this._isDirected,
  1665. multigraph: this._isMultigraph,
  1666. compound: this._isCompound
  1667. });
  1668. copy.setGraph(this.graph());
  1669. _.each(this._nodes, function(value, v) {
  1670. if (filter(v)) {
  1671. copy.setNode(v, value);
  1672. }
  1673. }, this);
  1674. _.each(this._edgeObjs, function(e) {
  1675. if (copy.hasNode(e.v) && copy.hasNode(e.w)) {
  1676. copy.setEdge(e, this.edge(e));
  1677. }
  1678. }, this);
  1679. var self = this;
  1680. var parents = {};
  1681. function findParent(v) {
  1682. var parent = self.parent(v);
  1683. if (parent === undefined || copy.hasNode(parent)) {
  1684. parents[v] = parent;
  1685. return parent;
  1686. } else if (parent in parents) {
  1687. return parents[parent];
  1688. } else {
  1689. return findParent(parent);
  1690. }
  1691. }
  1692. if (this._isCompound) {
  1693. _.each(copy.nodes(), function(v) {
  1694. copy.setParent(v, findParent(v));
  1695. });
  1696. }
  1697. return copy;
  1698. };
  1699. /* === Edge functions ========== */
  1700. Graph.prototype.setDefaultEdgeLabel = function(newDefault) {
  1701. if (!_.isFunction(newDefault)) {
  1702. newDefault = _.constant(newDefault);
  1703. }
  1704. this._defaultEdgeLabelFn = newDefault;
  1705. return this;
  1706. };
  1707. Graph.prototype.edgeCount = function() {
  1708. return this._edgeCount;
  1709. };
  1710. Graph.prototype.edges = function() {
  1711. return _.values(this._edgeObjs);
  1712. };
  1713. Graph.prototype.setPath = function(vs, value) {
  1714. var self = this,
  1715. args = arguments;
  1716. _.reduce(vs, function(v, w) {
  1717. if (args.length > 1) {
  1718. self.setEdge(v, w, value);
  1719. } else {
  1720. self.setEdge(v, w);
  1721. }
  1722. return w;
  1723. });
  1724. return this;
  1725. };
  1726. /*
  1727. * setEdge(v, w, [value, [name]])
  1728. * setEdge({ v, w, [name] }, [value])
  1729. */
  1730. Graph.prototype.setEdge = function() {
  1731. var v, w, name, value,
  1732. valueSpecified = false,
  1733. arg0 = arguments[0];
  1734. if (typeof arg0 === "object" && arg0 !== null && "v" in arg0) {
  1735. v = arg0.v;
  1736. w = arg0.w;
  1737. name = arg0.name;
  1738. if (arguments.length === 2) {
  1739. value = arguments[1];
  1740. valueSpecified = true;
  1741. }
  1742. } else {
  1743. v = arg0;
  1744. w = arguments[1];
  1745. name = arguments[3];
  1746. if (arguments.length > 2) {
  1747. value = arguments[2];
  1748. valueSpecified = true;
  1749. }
  1750. }
  1751. v = "" + v;
  1752. w = "" + w;
  1753. if (!_.isUndefined(name)) {
  1754. name = "" + name;
  1755. }
  1756. var e = edgeArgsToId(this._isDirected, v, w, name);
  1757. if (_.has(this._edgeLabels, e)) {
  1758. if (valueSpecified) {
  1759. this._edgeLabels[e] = value;
  1760. }
  1761. return this;
  1762. }
  1763. if (!_.isUndefined(name) && !this._isMultigraph) {
  1764. throw new Error("Cannot set a named edge when isMultigraph = false");
  1765. }
  1766. // It didn't exist, so we need to create it.
  1767. // First ensure the nodes exist.
  1768. this.setNode(v);
  1769. this.setNode(w);
  1770. this._edgeLabels[e] = valueSpecified ? value : this._defaultEdgeLabelFn(v, w, name);
  1771. var edgeObj = edgeArgsToObj(this._isDirected, v, w, name);
  1772. // Ensure we add undirected edges in a consistent way.
  1773. v = edgeObj.v;
  1774. w = edgeObj.w;
  1775. Object.freeze(edgeObj);
  1776. this._edgeObjs[e] = edgeObj;
  1777. incrementOrInitEntry(this._preds[w], v);
  1778. incrementOrInitEntry(this._sucs[v], w);
  1779. this._in[w][e] = edgeObj;
  1780. this._out[v][e] = edgeObj;
  1781. this._edgeCount++;
  1782. return this;
  1783. };
  1784. Graph.prototype.edge = function(v, w, name) {
  1785. var e = (arguments.length === 1
  1786. ? edgeObjToId(this._isDirected, arguments[0])
  1787. : edgeArgsToId(this._isDirected, v, w, name));
  1788. return this._edgeLabels[e];
  1789. };
  1790. Graph.prototype.hasEdge = function(v, w, name) {
  1791. var e = (arguments.length === 1
  1792. ? edgeObjToId(this._isDirected, arguments[0])
  1793. : edgeArgsToId(this._isDirected, v, w, name));
  1794. return _.has(this._edgeLabels, e);
  1795. };
  1796. Graph.prototype.removeEdge = function(v, w, name) {
  1797. var e = (arguments.length === 1
  1798. ? edgeObjToId(this._isDirected, arguments[0])
  1799. : edgeArgsToId(this._isDirected, v, w, name)),
  1800. edge = this._edgeObjs[e];
  1801. if (edge) {
  1802. v = edge.v;
  1803. w = edge.w;
  1804. delete this._edgeLabels[e];
  1805. delete this._edgeObjs[e];
  1806. decrementOrRemoveEntry(this._preds[w], v);
  1807. decrementOrRemoveEntry(this._sucs[v], w);
  1808. delete this._in[w][e];
  1809. delete this._out[v][e];
  1810. this._edgeCount--;
  1811. }
  1812. return this;
  1813. };
  1814. Graph.prototype.inEdges = function(v, u) {
  1815. var inV = this._in[v];
  1816. if (inV) {
  1817. var edges = _.values(inV);
  1818. if (!u) {
  1819. return edges;
  1820. }
  1821. return _.filter(edges, function(edge) { return edge.v === u; });
  1822. }
  1823. };
  1824. Graph.prototype.outEdges = function(v, w) {
  1825. var outV = this._out[v];
  1826. if (outV) {
  1827. var edges = _.values(outV);
  1828. if (!w) {
  1829. return edges;
  1830. }
  1831. return _.filter(edges, function(edge) { return edge.w === w; });
  1832. }
  1833. };
  1834. Graph.prototype.nodeEdges = function(v, w) {
  1835. var inEdges = this.inEdges(v, w);
  1836. if (inEdges) {
  1837. return inEdges.concat(this.outEdges(v, w));
  1838. }
  1839. };
  1840. function incrementOrInitEntry(map, k) {
  1841. if (map[k]) {
  1842. map[k]++;
  1843. } else {
  1844. map[k] = 1;
  1845. }
  1846. }
  1847. function decrementOrRemoveEntry(map, k) {
  1848. if (!--map[k]) { delete map[k]; }
  1849. }
  1850. function edgeArgsToId(isDirected, v_, w_, name) {
  1851. var v = "" + v_;
  1852. var w = "" + w_;
  1853. if (!isDirected && v > w) {
  1854. var tmp = v;
  1855. v = w;
  1856. w = tmp;
  1857. }
  1858. return v + EDGE_KEY_DELIM + w + EDGE_KEY_DELIM +
  1859. (_.isUndefined(name) ? DEFAULT_EDGE_NAME : name);
  1860. }
  1861. function edgeArgsToObj(isDirected, v_, w_, name) {
  1862. var v = "" + v_;
  1863. var w = "" + w_;
  1864. if (!isDirected && v > w) {
  1865. var tmp = v;
  1866. v = w;
  1867. w = tmp;
  1868. }
  1869. var edgeObj = { v: v, w: w };
  1870. if (name) {
  1871. edgeObj.name = name;
  1872. }
  1873. return edgeObj;
  1874. }
  1875. function edgeObjToId(isDirected, edgeObj) {
  1876. return edgeArgsToId(isDirected, edgeObj.v, edgeObj.w, edgeObj.name);
  1877. }
  1878. },{"./lodash":48}],46:[function(require,module,exports){
  1879. // Includes only the "core" of graphlib
  1880. module.exports = {
  1881. Graph: require("./graph"),
  1882. version: require("./version")
  1883. };
  1884. },{"./graph":45,"./version":49}],47:[function(require,module,exports){
  1885. var _ = require("./lodash"),
  1886. Graph = require("./graph");
  1887. module.exports = {
  1888. write: write,
  1889. read: read
  1890. };
  1891. function write(g) {
  1892. var json = {
  1893. options: {
  1894. directed: g.isDirected(),
  1895. multigraph: g.isMultigraph(),
  1896. compound: g.isCompound()
  1897. },
  1898. nodes: writeNodes(g),
  1899. edges: writeEdges(g)
  1900. };
  1901. if (!_.isUndefined(g.graph())) {
  1902. json.value = _.clone(g.graph());
  1903. }
  1904. return json;
  1905. }
  1906. function writeNodes(g) {
  1907. return _.map(g.nodes(), function(v) {
  1908. var nodeValue = g.node(v),
  1909. parent = g.parent(v),
  1910. node = { v: v };
  1911. if (!_.isUndefined(nodeValue)) {
  1912. node.value = nodeValue;
  1913. }
  1914. if (!_.isUndefined(parent)) {
  1915. node.parent = parent;
  1916. }
  1917. return node;
  1918. });
  1919. }
  1920. function writeEdges(g) {
  1921. return _.map(g.edges(), function(e) {
  1922. var edgeValue = g.edge(e),
  1923. edge = { v: e.v, w: e.w };
  1924. if (!_.isUndefined(e.name)) {
  1925. edge.name = e.name;
  1926. }
  1927. if (!_.isUndefined(edgeValue)) {
  1928. edge.value = edgeValue;
  1929. }
  1930. return edge;
  1931. });
  1932. }
  1933. function read(json) {
  1934. var g = new Graph(json.options).setGraph(json.value);
  1935. _.each(json.nodes, function(entry) {
  1936. g.setNode(entry.v, entry.value);
  1937. if (entry.parent) {
  1938. g.setParent(entry.v, entry.parent);
  1939. }
  1940. });
  1941. _.each(json.edges, function(entry) {
  1942. g.setEdge({ v: entry.v, w: entry.w, name: entry.name }, entry.value);
  1943. });
  1944. return g;
  1945. }
  1946. },{"./graph":45,"./lodash":48}],48:[function(require,module,exports){
  1947. /* global window */
  1948. var lodash;
  1949. if (typeof require === "function") {
  1950. try {
  1951. lodash = require("lodash");
  1952. } catch (e) {}
  1953. }
  1954. if (!lodash) {
  1955. lodash = window._;
  1956. }
  1957. module.exports = lodash;
  1958. },{"lodash":50}],49:[function(require,module,exports){
  1959. module.exports = '1.0.7';
  1960. },{}],50:[function(require,module,exports){
  1961. (function (global){
  1962. /**
  1963. * @license
  1964. * lodash 3.10.1 (Custom Build) <https://lodash.com/>
  1965. * Build: `lodash modern -d -o ./index.js`
  1966. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  1967. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  1968. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  1969. * Available under MIT license <https://lodash.com/license>
  1970. */
  1971. ;(function() {
  1972. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  1973. var undefined;
  1974. /** Used as the semantic version number. */
  1975. var VERSION = '3.10.1';
  1976. /** Used to compose bitmasks for wrapper metadata. */
  1977. var BIND_FLAG = 1,
  1978. BIND_KEY_FLAG = 2,
  1979. CURRY_BOUND_FLAG = 4,
  1980. CURRY_FLAG = 8,
  1981. CURRY_RIGHT_FLAG = 16,
  1982. PARTIAL_FLAG = 32,
  1983. PARTIAL_RIGHT_FLAG = 64,
  1984. ARY_FLAG = 128,
  1985. REARG_FLAG = 256;
  1986. /** Used as default options for `_.trunc`. */
  1987. var DEFAULT_TRUNC_LENGTH = 30,
  1988. DEFAULT_TRUNC_OMISSION = '...';
  1989. /** Used to detect when a function becomes hot. */
  1990. var HOT_COUNT = 150,
  1991. HOT_SPAN = 16;
  1992. /** Used as the size to enable large array optimizations. */
  1993. var LARGE_ARRAY_SIZE = 200;
  1994. /** Used to indicate the type of lazy iteratees. */
  1995. var LAZY_FILTER_FLAG = 1,
  1996. LAZY_MAP_FLAG = 2;
  1997. /** Used as the `TypeError` message for "Functions" methods. */
  1998. var FUNC_ERROR_TEXT = 'Expected a function';
  1999. /** Used as the internal argument placeholder. */
  2000. var PLACEHOLDER = '__lodash_placeholder__';
  2001. /** `Object#toString` result references. */
  2002. var argsTag = '[object Arguments]',
  2003. arrayTag = '[object Array]',
  2004. boolTag = '[object Boolean]',
  2005. dateTag = '[object Date]',
  2006. errorTag = '[object Error]',
  2007. funcTag = '[object Function]',
  2008. mapTag = '[object Map]',
  2009. numberTag = '[object Number]',
  2010. objectTag = '[object Object]',
  2011. regexpTag = '[object RegExp]',
  2012. setTag = '[object Set]',
  2013. stringTag = '[object String]',
  2014. weakMapTag = '[object WeakMap]';
  2015. var arrayBufferTag = '[object ArrayBuffer]',
  2016. float32Tag = '[object Float32Array]',
  2017. float64Tag = '[object Float64Array]',
  2018. int8Tag = '[object Int8Array]',
  2019. int16Tag = '[object Int16Array]',
  2020. int32Tag = '[object Int32Array]',
  2021. uint8Tag = '[object Uint8Array]',
  2022. uint8ClampedTag = '[object Uint8ClampedArray]',
  2023. uint16Tag = '[object Uint16Array]',
  2024. uint32Tag = '[object Uint32Array]';
  2025. /** Used to match empty string literals in compiled template source. */
  2026. var reEmptyStringLeading = /\b__p \+= '';/g,
  2027. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  2028. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  2029. /** Used to match HTML entities and HTML characters. */
  2030. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
  2031. reUnescapedHtml = /[&<>"'`]/g,
  2032. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  2033. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  2034. /** Used to match template delimiters. */
  2035. var reEscape = /<%-([\s\S]+?)%>/g,
  2036. reEvaluate = /<%([\s\S]+?)%>/g,
  2037. reInterpolate = /<%=([\s\S]+?)%>/g;
  2038. /** Used to match property names within property paths. */
  2039. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,
  2040. reIsPlainProp = /^\w*$/,
  2041. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
  2042. /**
  2043. * Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns)
  2044. * and those outlined by [`EscapeRegExpPattern`](http://ecma-international.org/ecma-262/6.0/#sec-escaperegexppattern).
  2045. */
  2046. var reRegExpChars = /^[:!,]|[\\^$.*+?()[\]{}|\/]|(^[0-9a-fA-Fnrtuvx])|([\n\r\u2028\u2029])/g,
  2047. reHasRegExpChars = RegExp(reRegExpChars.source);
  2048. /** Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). */
  2049. var reComboMark = /[\u0300-\u036f\ufe20-\ufe23]/g;
  2050. /** Used to match backslashes in property paths. */
  2051. var reEscapeChar = /\\(\\)?/g;
  2052. /** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */
  2053. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  2054. /** Used to match `RegExp` flags from their coerced string values. */
  2055. var reFlags = /\w*$/;
  2056. /** Used to detect hexadecimal string values. */
  2057. var reHasHexPrefix = /^0[xX]/;
  2058. /** Used to detect host constructors (Safari > 5). */
  2059. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  2060. /** Used to detect unsigned integer values. */
  2061. var reIsUint = /^\d+$/;
  2062. /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
  2063. var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
  2064. /** Used to ensure capturing order of template delimiters. */
  2065. var reNoMatch = /($^)/;
  2066. /** Used to match unescaped characters in compiled string literals. */
  2067. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  2068. /** Used to match words to create compound words. */
  2069. var reWords = (function() {
  2070. var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]',
  2071. lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
  2072. return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
  2073. }());
  2074. /** Used to assign default `context` object properties. */
  2075. var contextProps = [
  2076. 'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
  2077. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number',
  2078. 'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'isFinite',
  2079. 'parseFloat', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array',
  2080. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap'
  2081. ];
  2082. /** Used to make template sourceURLs easier to identify. */
  2083. var templateCounter = -1;
  2084. /** Used to identify `toStringTag` values of typed arrays. */
  2085. var typedArrayTags = {};
  2086. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  2087. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  2088. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  2089. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  2090. typedArrayTags[uint32Tag] = true;
  2091. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  2092. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  2093. typedArrayTags[dateTag] = typedArrayTags[errorTag] =
  2094. typedArrayTags[funcTag] = typedArrayTags[mapTag] =
  2095. typedArrayTags[numberTag] = typedArrayTags[objectTag] =
  2096. typedArrayTags[regexpTag] = typedArrayTags[setTag] =
  2097. typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
  2098. /** Used to identify `toStringTag` values supported by `_.clone`. */
  2099. var cloneableTags = {};
  2100. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  2101. cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
  2102. cloneableTags[dateTag] = cloneableTags[float32Tag] =
  2103. cloneableTags[float64Tag] = cloneableTags[int8Tag] =
  2104. cloneableTags[int16Tag] = cloneableTags[int32Tag] =
  2105. cloneableTags[numberTag] = cloneableTags[objectTag] =
  2106. cloneableTags[regexpTag] = cloneableTags[stringTag] =
  2107. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  2108. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  2109. cloneableTags[errorTag] = cloneableTags[funcTag] =
  2110. cloneableTags[mapTag] = cloneableTags[setTag] =
  2111. cloneableTags[weakMapTag] = false;
  2112. /** Used to map latin-1 supplementary letters to basic latin letters. */
  2113. var deburredLetters = {
  2114. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  2115. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  2116. '\xc7': 'C', '\xe7': 'c',
  2117. '\xd0': 'D', '\xf0': 'd',
  2118. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  2119. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  2120. '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  2121. '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  2122. '\xd1': 'N', '\xf1': 'n',
  2123. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  2124. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  2125. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  2126. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  2127. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  2128. '\xc6': 'Ae', '\xe6': 'ae',
  2129. '\xde': 'Th', '\xfe': 'th',
  2130. '\xdf': 'ss'
  2131. };
  2132. /** Used to map characters to HTML entities. */
  2133. var htmlEscapes = {
  2134. '&': '&amp;',
  2135. '<': '&lt;',
  2136. '>': '&gt;',
  2137. '"': '&quot;',
  2138. "'": '&#39;',
  2139. '`': '&#96;'
  2140. };
  2141. /** Used to map HTML entities to characters. */
  2142. var htmlUnescapes = {
  2143. '&amp;': '&',
  2144. '&lt;': '<',
  2145. '&gt;': '>',
  2146. '&quot;': '"',
  2147. '&#39;': "'",
  2148. '&#96;': '`'
  2149. };
  2150. /** Used to determine if values are of the language type `Object`. */
  2151. var objectTypes = {
  2152. 'function': true,
  2153. 'object': true
  2154. };
  2155. /** Used to escape characters for inclusion in compiled regexes. */
  2156. var regexpEscapes = {
  2157. '0': 'x30', '1': 'x31', '2': 'x32', '3': 'x33', '4': 'x34',
  2158. '5': 'x35', '6': 'x36', '7': 'x37', '8': 'x38', '9': 'x39',
  2159. 'A': 'x41', 'B': 'x42', 'C': 'x43', 'D': 'x44', 'E': 'x45', 'F': 'x46',
  2160. 'a': 'x61', 'b': 'x62', 'c': 'x63', 'd': 'x64', 'e': 'x65', 'f': 'x66',
  2161. 'n': 'x6e', 'r': 'x72', 't': 'x74', 'u': 'x75', 'v': 'x76', 'x': 'x78'
  2162. };
  2163. /** Used to escape characters for inclusion in compiled string literals. */
  2164. var stringEscapes = {
  2165. '\\': '\\',
  2166. "'": "'",
  2167. '\n': 'n',
  2168. '\r': 'r',
  2169. '\u2028': 'u2028',
  2170. '\u2029': 'u2029'
  2171. };
  2172. /** Detect free variable `exports`. */
  2173. var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
  2174. /** Detect free variable `module`. */
  2175. var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
  2176. /** Detect free variable `global` from Node.js. */
  2177. var freeGlobal = freeExports && freeModule && typeof global == 'object' && global && global.Object && global;
  2178. /** Detect free variable `self`. */
  2179. var freeSelf = objectTypes[typeof self] && self && self.Object && self;
  2180. /** Detect free variable `window`. */
  2181. var freeWindow = objectTypes[typeof window] && window && window.Object && window;
  2182. /** Detect the popular CommonJS extension `module.exports`. */
  2183. var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
  2184. /**
  2185. * Used as a reference to the global object.
  2186. *
  2187. * The `this` value is used if it's the global object to avoid Greasemonkey's
  2188. * restricted `window` object, otherwise the `window` object is used.
  2189. */
  2190. var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this;
  2191. /*--------------------------------------------------------------------------*/
  2192. /**
  2193. * The base implementation of `compareAscending` which compares values and
  2194. * sorts them in ascending order without guaranteeing a stable sort.
  2195. *
  2196. * @private
  2197. * @param {*} value The value to compare.
  2198. * @param {*} other The other value to compare.
  2199. * @returns {number} Returns the sort order indicator for `value`.
  2200. */
  2201. function baseCompareAscending(value, other) {
  2202. if (value !== other) {
  2203. var valIsNull = value === null,
  2204. valIsUndef = value === undefined,
  2205. valIsReflexive = value === value;
  2206. var othIsNull = other === null,
  2207. othIsUndef = other === undefined,
  2208. othIsReflexive = other === other;
  2209. if ((value > other && !othIsNull) || !valIsReflexive ||
  2210. (valIsNull && !othIsUndef && othIsReflexive) ||
  2211. (valIsUndef && othIsReflexive)) {
  2212. return 1;
  2213. }
  2214. if ((value < other && !valIsNull) || !othIsReflexive ||
  2215. (othIsNull && !valIsUndef && valIsReflexive) ||
  2216. (othIsUndef && valIsReflexive)) {
  2217. return -1;
  2218. }
  2219. }
  2220. return 0;
  2221. }
  2222. /**
  2223. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  2224. * support for callback shorthands and `this` binding.
  2225. *
  2226. * @private
  2227. * @param {Array} array The array to search.
  2228. * @param {Function} predicate The function invoked per iteration.
  2229. * @param {boolean} [fromRight] Specify iterating from right to left.
  2230. * @returns {number} Returns the index of the matched value, else `-1`.
  2231. */
  2232. function baseFindIndex(array, predicate, fromRight) {
  2233. var length = array.length,
  2234. index = fromRight ? length : -1;
  2235. while ((fromRight ? index-- : ++index < length)) {
  2236. if (predicate(array[index], index, array)) {
  2237. return index;
  2238. }
  2239. }
  2240. return -1;
  2241. }
  2242. /**
  2243. * The base implementation of `_.indexOf` without support for binary searches.
  2244. *
  2245. * @private
  2246. * @param {Array} array The array to search.
  2247. * @param {*} value The value to search for.
  2248. * @param {number} fromIndex The index to search from.
  2249. * @returns {number} Returns the index of the matched value, else `-1`.
  2250. */
  2251. function baseIndexOf(array, value, fromIndex) {
  2252. if (value !== value) {
  2253. return indexOfNaN(array, fromIndex);
  2254. }
  2255. var index = fromIndex - 1,
  2256. length = array.length;
  2257. while (++index < length) {
  2258. if (array[index] === value) {
  2259. return index;
  2260. }
  2261. }
  2262. return -1;
  2263. }
  2264. /**
  2265. * The base implementation of `_.isFunction` without support for environments
  2266. * with incorrect `typeof` results.
  2267. *
  2268. * @private
  2269. * @param {*} value The value to check.
  2270. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  2271. */
  2272. function baseIsFunction(value) {
  2273. // Avoid a Chakra JIT bug in compatibility modes of IE 11.
  2274. // See https://github.com/jashkenas/underscore/issues/1621 for more details.
  2275. return typeof value == 'function' || false;
  2276. }
  2277. /**
  2278. * Converts `value` to a string if it's not one. An empty string is returned
  2279. * for `null` or `undefined` values.
  2280. *
  2281. * @private
  2282. * @param {*} value The value to process.
  2283. * @returns {string} Returns the string.
  2284. */
  2285. function baseToString(value) {
  2286. return value == null ? '' : (value + '');
  2287. }
  2288. /**
  2289. * Used by `_.trim` and `_.trimLeft` to get the index of the first character
  2290. * of `string` that is not found in `chars`.
  2291. *
  2292. * @private
  2293. * @param {string} string The string to inspect.
  2294. * @param {string} chars The characters to find.
  2295. * @returns {number} Returns the index of the first character not found in `chars`.
  2296. */
  2297. function charsLeftIndex(string, chars) {
  2298. var index = -1,
  2299. length = string.length;
  2300. while (++index < length && chars.indexOf(string.charAt(index)) > -1) {}
  2301. return index;
  2302. }
  2303. /**
  2304. * Used by `_.trim` and `_.trimRight` to get the index of the last character
  2305. * of `string` that is not found in `chars`.
  2306. *
  2307. * @private
  2308. * @param {string} string The string to inspect.
  2309. * @param {string} chars The characters to find.
  2310. * @returns {number} Returns the index of the last character not found in `chars`.
  2311. */
  2312. function charsRightIndex(string, chars) {
  2313. var index = string.length;
  2314. while (index-- && chars.indexOf(string.charAt(index)) > -1) {}
  2315. return index;
  2316. }
  2317. /**
  2318. * Used by `_.sortBy` to compare transformed elements of a collection and stable
  2319. * sort them in ascending order.
  2320. *
  2321. * @private
  2322. * @param {Object} object The object to compare.
  2323. * @param {Object} other The other object to compare.
  2324. * @returns {number} Returns the sort order indicator for `object`.
  2325. */
  2326. function compareAscending(object, other) {
  2327. return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index);
  2328. }
  2329. /**
  2330. * Used by `_.sortByOrder` to compare multiple properties of a value to another
  2331. * and stable sort them.
  2332. *
  2333. * If `orders` is unspecified, all valuess are sorted in ascending order. Otherwise,
  2334. * a value is sorted in ascending order if its corresponding order is "asc", and
  2335. * descending if "desc".
  2336. *
  2337. * @private
  2338. * @param {Object} object The object to compare.
  2339. * @param {Object} other The other object to compare.
  2340. * @param {boolean[]} orders The order to sort by for each property.
  2341. * @returns {number} Returns the sort order indicator for `object`.
  2342. */
  2343. function compareMultiple(object, other, orders) {
  2344. var index = -1,
  2345. objCriteria = object.criteria,
  2346. othCriteria = other.criteria,
  2347. length = objCriteria.length,
  2348. ordersLength = orders.length;
  2349. while (++index < length) {
  2350. var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
  2351. if (result) {
  2352. if (index >= ordersLength) {
  2353. return result;
  2354. }
  2355. var order = orders[index];
  2356. return result * ((order === 'asc' || order === true) ? 1 : -1);
  2357. }
  2358. }
  2359. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  2360. // that causes it, under certain circumstances, to provide the same value for
  2361. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  2362. // for more details.
  2363. //
  2364. // This also ensures a stable sort in V8 and other engines.
  2365. // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
  2366. return object.index - other.index;
  2367. }
  2368. /**
  2369. * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
  2370. *
  2371. * @private
  2372. * @param {string} letter The matched letter to deburr.
  2373. * @returns {string} Returns the deburred letter.
  2374. */
  2375. function deburrLetter(letter) {
  2376. return deburredLetters[letter];
  2377. }
  2378. /**
  2379. * Used by `_.escape` to convert characters to HTML entities.
  2380. *
  2381. * @private
  2382. * @param {string} chr The matched character to escape.
  2383. * @returns {string} Returns the escaped character.
  2384. */
  2385. function escapeHtmlChar(chr) {
  2386. return htmlEscapes[chr];
  2387. }
  2388. /**
  2389. * Used by `_.escapeRegExp` to escape characters for inclusion in compiled regexes.
  2390. *
  2391. * @private
  2392. * @param {string} chr The matched character to escape.
  2393. * @param {string} leadingChar The capture group for a leading character.
  2394. * @param {string} whitespaceChar The capture group for a whitespace character.
  2395. * @returns {string} Returns the escaped character.
  2396. */
  2397. function escapeRegExpChar(chr, leadingChar, whitespaceChar) {
  2398. if (leadingChar) {
  2399. chr = regexpEscapes[chr];
  2400. } else if (whitespaceChar) {
  2401. chr = stringEscapes[chr];
  2402. }
  2403. return '\\' + chr;
  2404. }
  2405. /**
  2406. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  2407. *
  2408. * @private
  2409. * @param {string} chr The matched character to escape.
  2410. * @returns {string} Returns the escaped character.
  2411. */
  2412. function escapeStringChar(chr) {
  2413. return '\\' + stringEscapes[chr];
  2414. }
  2415. /**
  2416. * Gets the index at which the first occurrence of `NaN` is found in `array`.
  2417. *
  2418. * @private
  2419. * @param {Array} array The array to search.
  2420. * @param {number} fromIndex The index to search from.
  2421. * @param {boolean} [fromRight] Specify iterating from right to left.
  2422. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
  2423. */
  2424. function indexOfNaN(array, fromIndex, fromRight) {
  2425. var length = array.length,
  2426. index = fromIndex + (fromRight ? 0 : -1);
  2427. while ((fromRight ? index-- : ++index < length)) {
  2428. var other = array[index];
  2429. if (other !== other) {
  2430. return index;
  2431. }
  2432. }
  2433. return -1;
  2434. }
  2435. /**
  2436. * Checks if `value` is object-like.
  2437. *
  2438. * @private
  2439. * @param {*} value The value to check.
  2440. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  2441. */
  2442. function isObjectLike(value) {
  2443. return !!value && typeof value == 'object';
  2444. }
  2445. /**
  2446. * Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
  2447. * character code is whitespace.
  2448. *
  2449. * @private
  2450. * @param {number} charCode The character code to inspect.
  2451. * @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
  2452. */
  2453. function isSpace(charCode) {
  2454. return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 ||
  2455. (charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279)));
  2456. }
  2457. /**
  2458. * Replaces all `placeholder` elements in `array` with an internal placeholder
  2459. * and returns an array of their indexes.
  2460. *
  2461. * @private
  2462. * @param {Array} array The array to modify.
  2463. * @param {*} placeholder The placeholder to replace.
  2464. * @returns {Array} Returns the new array of placeholder indexes.
  2465. */
  2466. function replaceHolders(array, placeholder) {
  2467. var index = -1,
  2468. length = array.length,
  2469. resIndex = -1,
  2470. result = [];
  2471. while (++index < length) {
  2472. if (array[index] === placeholder) {
  2473. array[index] = PLACEHOLDER;
  2474. result[++resIndex] = index;
  2475. }
  2476. }
  2477. return result;
  2478. }
  2479. /**
  2480. * An implementation of `_.uniq` optimized for sorted arrays without support
  2481. * for callback shorthands and `this` binding.
  2482. *
  2483. * @private
  2484. * @param {Array} array The array to inspect.
  2485. * @param {Function} [iteratee] The function invoked per iteration.
  2486. * @returns {Array} Returns the new duplicate-value-free array.
  2487. */
  2488. function sortedUniq(array, iteratee) {
  2489. var seen,
  2490. index = -1,
  2491. length = array.length,
  2492. resIndex = -1,
  2493. result = [];
  2494. while (++index < length) {
  2495. var value = array[index],
  2496. computed = iteratee ? iteratee(value, index, array) : value;
  2497. if (!index || seen !== computed) {
  2498. seen = computed;
  2499. result[++resIndex] = value;
  2500. }
  2501. }
  2502. return result;
  2503. }
  2504. /**
  2505. * Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
  2506. * character of `string`.
  2507. *
  2508. * @private
  2509. * @param {string} string The string to inspect.
  2510. * @returns {number} Returns the index of the first non-whitespace character.
  2511. */
  2512. function trimmedLeftIndex(string) {
  2513. var index = -1,
  2514. length = string.length;
  2515. while (++index < length && isSpace(string.charCodeAt(index))) {}
  2516. return index;
  2517. }
  2518. /**
  2519. * Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
  2520. * character of `string`.
  2521. *
  2522. * @private
  2523. * @param {string} string The string to inspect.
  2524. * @returns {number} Returns the index of the last non-whitespace character.
  2525. */
  2526. function trimmedRightIndex(string) {
  2527. var index = string.length;
  2528. while (index-- && isSpace(string.charCodeAt(index))) {}
  2529. return index;
  2530. }
  2531. /**
  2532. * Used by `_.unescape` to convert HTML entities to characters.
  2533. *
  2534. * @private
  2535. * @param {string} chr The matched character to unescape.
  2536. * @returns {string} Returns the unescaped character.
  2537. */
  2538. function unescapeHtmlChar(chr) {
  2539. return htmlUnescapes[chr];
  2540. }
  2541. /*--------------------------------------------------------------------------*/
  2542. /**
  2543. * Create a new pristine `lodash` function using the given `context` object.
  2544. *
  2545. * @static
  2546. * @memberOf _
  2547. * @category Utility
  2548. * @param {Object} [context=root] The context object.
  2549. * @returns {Function} Returns a new `lodash` function.
  2550. * @example
  2551. *
  2552. * _.mixin({ 'foo': _.constant('foo') });
  2553. *
  2554. * var lodash = _.runInContext();
  2555. * lodash.mixin({ 'bar': lodash.constant('bar') });
  2556. *
  2557. * _.isFunction(_.foo);
  2558. * // => true
  2559. * _.isFunction(_.bar);
  2560. * // => false
  2561. *
  2562. * lodash.isFunction(lodash.foo);
  2563. * // => false
  2564. * lodash.isFunction(lodash.bar);
  2565. * // => true
  2566. *
  2567. * // using `context` to mock `Date#getTime` use in `_.now`
  2568. * var mock = _.runInContext({
  2569. * 'Date': function() {
  2570. * return { 'getTime': getTimeMock };
  2571. * }
  2572. * });
  2573. *
  2574. * // or creating a suped-up `defer` in Node.js
  2575. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  2576. */
  2577. function runInContext(context) {
  2578. // Avoid issues with some ES3 environments that attempt to use values, named
  2579. // after built-in constructors like `Object`, for the creation of literals.
  2580. // ES5 clears this up by stating that literals must use built-in constructors.
  2581. // See https://es5.github.io/#x11.1.5 for more details.
  2582. context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
  2583. /** Native constructor references. */
  2584. var Array = context.Array,
  2585. Date = context.Date,
  2586. Error = context.Error,
  2587. Function = context.Function,
  2588. Math = context.Math,
  2589. Number = context.Number,
  2590. Object = context.Object,
  2591. RegExp = context.RegExp,
  2592. String = context.String,
  2593. TypeError = context.TypeError;
  2594. /** Used for native method references. */
  2595. var arrayProto = Array.prototype,
  2596. objectProto = Object.prototype,
  2597. stringProto = String.prototype;
  2598. /** Used to resolve the decompiled source of functions. */
  2599. var fnToString = Function.prototype.toString;
  2600. /** Used to check objects for own properties. */
  2601. var hasOwnProperty = objectProto.hasOwnProperty;
  2602. /** Used to generate unique IDs. */
  2603. var idCounter = 0;
  2604. /**
  2605. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  2606. * of values.
  2607. */
  2608. var objToString = objectProto.toString;
  2609. /** Used to restore the original `_` reference in `_.noConflict`. */
  2610. var oldDash = root._;
  2611. /** Used to detect if a method is native. */
  2612. var reIsNative = RegExp('^' +
  2613. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  2614. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  2615. );
  2616. /** Native method references. */
  2617. var ArrayBuffer = context.ArrayBuffer,
  2618. clearTimeout = context.clearTimeout,
  2619. parseFloat = context.parseFloat,
  2620. pow = Math.pow,
  2621. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  2622. Set = getNative(context, 'Set'),
  2623. setTimeout = context.setTimeout,
  2624. splice = arrayProto.splice,
  2625. Uint8Array = context.Uint8Array,
  2626. WeakMap = getNative(context, 'WeakMap');
  2627. /* Native method references for those with the same name as other `lodash` methods. */
  2628. var nativeCeil = Math.ceil,
  2629. nativeCreate = getNative(Object, 'create'),
  2630. nativeFloor = Math.floor,
  2631. nativeIsArray = getNative(Array, 'isArray'),
  2632. nativeIsFinite = context.isFinite,
  2633. nativeKeys = getNative(Object, 'keys'),
  2634. nativeMax = Math.max,
  2635. nativeMin = Math.min,
  2636. nativeNow = getNative(Date, 'now'),
  2637. nativeParseInt = context.parseInt,
  2638. nativeRandom = Math.random;
  2639. /** Used as references for `-Infinity` and `Infinity`. */
  2640. var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
  2641. POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
  2642. /** Used as references for the maximum length and index of an array. */
  2643. var MAX_ARRAY_LENGTH = 4294967295,
  2644. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  2645. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  2646. /**
  2647. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  2648. * of an array-like value.
  2649. */
  2650. var MAX_SAFE_INTEGER = 9007199254740991;
  2651. /** Used to store function metadata. */
  2652. var metaMap = WeakMap && new WeakMap;
  2653. /** Used to lookup unminified function names. */
  2654. var realNames = {};
  2655. /*------------------------------------------------------------------------*/
  2656. /**
  2657. * Creates a `lodash` object which wraps `value` to enable implicit chaining.
  2658. * Methods that operate on and return arrays, collections, and functions can
  2659. * be chained together. Methods that retrieve a single value or may return a
  2660. * primitive value will automatically end the chain returning the unwrapped
  2661. * value. Explicit chaining may be enabled using `_.chain`. The execution of
  2662. * chained methods is lazy, that is, execution is deferred until `_#value`
  2663. * is implicitly or explicitly called.
  2664. *
  2665. * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
  2666. * fusion is an optimization strategy which merge iteratee calls; this can help
  2667. * to avoid the creation of intermediate data structures and greatly reduce the
  2668. * number of iteratee executions.
  2669. *
  2670. * Chaining is supported in custom builds as long as the `_#value` method is
  2671. * directly or indirectly included in the build.
  2672. *
  2673. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  2674. *
  2675. * The wrapper `Array` methods are:
  2676. * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
  2677. * `splice`, and `unshift`
  2678. *
  2679. * The wrapper `String` methods are:
  2680. * `replace` and `split`
  2681. *
  2682. * The wrapper methods that support shortcut fusion are:
  2683. * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
  2684. * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
  2685. * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
  2686. * and `where`
  2687. *
  2688. * The chainable wrapper methods are:
  2689. * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
  2690. * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
  2691. * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defaultsDeep`,
  2692. * `defer`, `delay`, `difference`, `drop`, `dropRight`, `dropRightWhile`,
  2693. * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`,
  2694. * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
  2695. * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
  2696. * `invoke`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`,
  2697. * `matchesProperty`, `memoize`, `merge`, `method`, `methodOf`, `mixin`,
  2698. * `modArgs`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
  2699. * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
  2700. * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `restParam`,
  2701. * `reverse`, `set`, `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`,
  2702. * `sortByOrder`, `splice`, `spread`, `take`, `takeRight`, `takeRightWhile`,
  2703. * `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
  2704. * `transform`, `union`, `uniq`, `unshift`, `unzip`, `unzipWith`, `values`,
  2705. * `valuesIn`, `where`, `without`, `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
  2706. *
  2707. * The wrapper methods that are **not** chainable by default are:
  2708. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
  2709. * `deburr`, `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`,
  2710. * `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`,
  2711. * `floor`, `get`, `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`,
  2712. * `inRange`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
  2713. * `isEmpty`, `isEqual`, `isError`, `isFinite` `isFunction`, `isMatch`,
  2714. * `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`,
  2715. * `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
  2716. * `last`, `lastIndexOf`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
  2717. * `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
  2718. * `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
  2719. * `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`,
  2720. * `startsWith`, `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`,
  2721. * `unescape`, `uniqueId`, `value`, and `words`
  2722. *
  2723. * The wrapper method `sample` will return a wrapped value when `n` is provided,
  2724. * otherwise an unwrapped value is returned.
  2725. *
  2726. * @name _
  2727. * @constructor
  2728. * @category Chain
  2729. * @param {*} value The value to wrap in a `lodash` instance.
  2730. * @returns {Object} Returns the new `lodash` wrapper instance.
  2731. * @example
  2732. *
  2733. * var wrapped = _([1, 2, 3]);
  2734. *
  2735. * // returns an unwrapped value
  2736. * wrapped.reduce(function(total, n) {
  2737. * return total + n;
  2738. * });
  2739. * // => 6
  2740. *
  2741. * // returns a wrapped value
  2742. * var squares = wrapped.map(function(n) {
  2743. * return n * n;
  2744. * });
  2745. *
  2746. * _.isArray(squares);
  2747. * // => false
  2748. *
  2749. * _.isArray(squares.value());
  2750. * // => true
  2751. */
  2752. function lodash(value) {
  2753. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  2754. if (value instanceof LodashWrapper) {
  2755. return value;
  2756. }
  2757. if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
  2758. return wrapperClone(value);
  2759. }
  2760. }
  2761. return new LodashWrapper(value);
  2762. }
  2763. /**
  2764. * The function whose prototype all chaining wrappers inherit from.
  2765. *
  2766. * @private
  2767. */
  2768. function baseLodash() {
  2769. // No operation performed.
  2770. }
  2771. /**
  2772. * The base constructor for creating `lodash` wrapper objects.
  2773. *
  2774. * @private
  2775. * @param {*} value The value to wrap.
  2776. * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
  2777. * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
  2778. */
  2779. function LodashWrapper(value, chainAll, actions) {
  2780. this.__wrapped__ = value;
  2781. this.__actions__ = actions || [];
  2782. this.__chain__ = !!chainAll;
  2783. }
  2784. /**
  2785. * An object environment feature flags.
  2786. *
  2787. * @static
  2788. * @memberOf _
  2789. * @type Object
  2790. */
  2791. var support = lodash.support = {};
  2792. /**
  2793. * By default, the template delimiters used by lodash are like those in
  2794. * embedded Ruby (ERB). Change the following template settings to use
  2795. * alternative delimiters.
  2796. *
  2797. * @static
  2798. * @memberOf _
  2799. * @type Object
  2800. */
  2801. lodash.templateSettings = {
  2802. /**
  2803. * Used to detect `data` property values to be HTML-escaped.
  2804. *
  2805. * @memberOf _.templateSettings
  2806. * @type RegExp
  2807. */
  2808. 'escape': reEscape,
  2809. /**
  2810. * Used to detect code to be evaluated.
  2811. *
  2812. * @memberOf _.templateSettings
  2813. * @type RegExp
  2814. */
  2815. 'evaluate': reEvaluate,
  2816. /**
  2817. * Used to detect `data` property values to inject.
  2818. *
  2819. * @memberOf _.templateSettings
  2820. * @type RegExp
  2821. */
  2822. 'interpolate': reInterpolate,
  2823. /**
  2824. * Used to reference the data object in the template text.
  2825. *
  2826. * @memberOf _.templateSettings
  2827. * @type string
  2828. */
  2829. 'variable': '',
  2830. /**
  2831. * Used to import variables into the compiled template.
  2832. *
  2833. * @memberOf _.templateSettings
  2834. * @type Object
  2835. */
  2836. 'imports': {
  2837. /**
  2838. * A reference to the `lodash` function.
  2839. *
  2840. * @memberOf _.templateSettings.imports
  2841. * @type Function
  2842. */
  2843. '_': lodash
  2844. }
  2845. };
  2846. /*------------------------------------------------------------------------*/
  2847. /**
  2848. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  2849. *
  2850. * @private
  2851. * @param {*} value The value to wrap.
  2852. */
  2853. function LazyWrapper(value) {
  2854. this.__wrapped__ = value;
  2855. this.__actions__ = [];
  2856. this.__dir__ = 1;
  2857. this.__filtered__ = false;
  2858. this.__iteratees__ = [];
  2859. this.__takeCount__ = POSITIVE_INFINITY;
  2860. this.__views__ = [];
  2861. }
  2862. /**
  2863. * Creates a clone of the lazy wrapper object.
  2864. *
  2865. * @private
  2866. * @name clone
  2867. * @memberOf LazyWrapper
  2868. * @returns {Object} Returns the cloned `LazyWrapper` object.
  2869. */
  2870. function lazyClone() {
  2871. var result = new LazyWrapper(this.__wrapped__);
  2872. result.__actions__ = arrayCopy(this.__actions__);
  2873. result.__dir__ = this.__dir__;
  2874. result.__filtered__ = this.__filtered__;
  2875. result.__iteratees__ = arrayCopy(this.__iteratees__);
  2876. result.__takeCount__ = this.__takeCount__;
  2877. result.__views__ = arrayCopy(this.__views__);
  2878. return result;
  2879. }
  2880. /**
  2881. * Reverses the direction of lazy iteration.
  2882. *
  2883. * @private
  2884. * @name reverse
  2885. * @memberOf LazyWrapper
  2886. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  2887. */
  2888. function lazyReverse() {
  2889. if (this.__filtered__) {
  2890. var result = new LazyWrapper(this);
  2891. result.__dir__ = -1;
  2892. result.__filtered__ = true;
  2893. } else {
  2894. result = this.clone();
  2895. result.__dir__ *= -1;
  2896. }
  2897. return result;
  2898. }
  2899. /**
  2900. * Extracts the unwrapped value from its lazy wrapper.
  2901. *
  2902. * @private
  2903. * @name value
  2904. * @memberOf LazyWrapper
  2905. * @returns {*} Returns the unwrapped value.
  2906. */
  2907. function lazyValue() {
  2908. var array = this.__wrapped__.value(),
  2909. dir = this.__dir__,
  2910. isArr = isArray(array),
  2911. isRight = dir < 0,
  2912. arrLength = isArr ? array.length : 0,
  2913. view = getView(0, arrLength, this.__views__),
  2914. start = view.start,
  2915. end = view.end,
  2916. length = end - start,
  2917. index = isRight ? end : (start - 1),
  2918. iteratees = this.__iteratees__,
  2919. iterLength = iteratees.length,
  2920. resIndex = 0,
  2921. takeCount = nativeMin(length, this.__takeCount__);
  2922. if (!isArr || arrLength < LARGE_ARRAY_SIZE || (arrLength == length && takeCount == length)) {
  2923. return baseWrapperValue((isRight && isArr) ? array.reverse() : array, this.__actions__);
  2924. }
  2925. var result = [];
  2926. outer:
  2927. while (length-- && resIndex < takeCount) {
  2928. index += dir;
  2929. var iterIndex = -1,
  2930. value = array[index];
  2931. while (++iterIndex < iterLength) {
  2932. var data = iteratees[iterIndex],
  2933. iteratee = data.iteratee,
  2934. type = data.type,
  2935. computed = iteratee(value);
  2936. if (type == LAZY_MAP_FLAG) {
  2937. value = computed;
  2938. } else if (!computed) {
  2939. if (type == LAZY_FILTER_FLAG) {
  2940. continue outer;
  2941. } else {
  2942. break outer;
  2943. }
  2944. }
  2945. }
  2946. result[resIndex++] = value;
  2947. }
  2948. return result;
  2949. }
  2950. /*------------------------------------------------------------------------*/
  2951. /**
  2952. * Creates a cache object to store key/value pairs.
  2953. *
  2954. * @private
  2955. * @static
  2956. * @name Cache
  2957. * @memberOf _.memoize
  2958. */
  2959. function MapCache() {
  2960. this.__data__ = {};
  2961. }
  2962. /**
  2963. * Removes `key` and its value from the cache.
  2964. *
  2965. * @private
  2966. * @name delete
  2967. * @memberOf _.memoize.Cache
  2968. * @param {string} key The key of the value to remove.
  2969. * @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
  2970. */
  2971. function mapDelete(key) {
  2972. return this.has(key) && delete this.__data__[key];
  2973. }
  2974. /**
  2975. * Gets the cached value for `key`.
  2976. *
  2977. * @private
  2978. * @name get
  2979. * @memberOf _.memoize.Cache
  2980. * @param {string} key The key of the value to get.
  2981. * @returns {*} Returns the cached value.
  2982. */
  2983. function mapGet(key) {
  2984. return key == '__proto__' ? undefined : this.__data__[key];
  2985. }
  2986. /**
  2987. * Checks if a cached value for `key` exists.
  2988. *
  2989. * @private
  2990. * @name has
  2991. * @memberOf _.memoize.Cache
  2992. * @param {string} key The key of the entry to check.
  2993. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2994. */
  2995. function mapHas(key) {
  2996. return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
  2997. }
  2998. /**
  2999. * Sets `value` to `key` of the cache.
  3000. *
  3001. * @private
  3002. * @name set
  3003. * @memberOf _.memoize.Cache
  3004. * @param {string} key The key of the value to cache.
  3005. * @param {*} value The value to cache.
  3006. * @returns {Object} Returns the cache object.
  3007. */
  3008. function mapSet(key, value) {
  3009. if (key != '__proto__') {
  3010. this.__data__[key] = value;
  3011. }
  3012. return this;
  3013. }
  3014. /*------------------------------------------------------------------------*/
  3015. /**
  3016. *
  3017. * Creates a cache object to store unique values.
  3018. *
  3019. * @private
  3020. * @param {Array} [values] The values to cache.
  3021. */
  3022. function SetCache(values) {
  3023. var length = values ? values.length : 0;
  3024. this.data = { 'hash': nativeCreate(null), 'set': new Set };
  3025. while (length--) {
  3026. this.push(values[length]);
  3027. }
  3028. }
  3029. /**
  3030. * Checks if `value` is in `cache` mimicking the return signature of
  3031. * `_.indexOf` by returning `0` if the value is found, else `-1`.
  3032. *
  3033. * @private
  3034. * @param {Object} cache The cache to search.
  3035. * @param {*} value The value to search for.
  3036. * @returns {number} Returns `0` if `value` is found, else `-1`.
  3037. */
  3038. function cacheIndexOf(cache, value) {
  3039. var data = cache.data,
  3040. result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
  3041. return result ? 0 : -1;
  3042. }
  3043. /**
  3044. * Adds `value` to the cache.
  3045. *
  3046. * @private
  3047. * @name push
  3048. * @memberOf SetCache
  3049. * @param {*} value The value to cache.
  3050. */
  3051. function cachePush(value) {
  3052. var data = this.data;
  3053. if (typeof value == 'string' || isObject(value)) {
  3054. data.set.add(value);
  3055. } else {
  3056. data.hash[value] = true;
  3057. }
  3058. }
  3059. /*------------------------------------------------------------------------*/
  3060. /**
  3061. * Creates a new array joining `array` with `other`.
  3062. *
  3063. * @private
  3064. * @param {Array} array The array to join.
  3065. * @param {Array} other The other array to join.
  3066. * @returns {Array} Returns the new concatenated array.
  3067. */
  3068. function arrayConcat(array, other) {
  3069. var index = -1,
  3070. length = array.length,
  3071. othIndex = -1,
  3072. othLength = other.length,
  3073. result = Array(length + othLength);
  3074. while (++index < length) {
  3075. result[index] = array[index];
  3076. }
  3077. while (++othIndex < othLength) {
  3078. result[index++] = other[othIndex];
  3079. }
  3080. return result;
  3081. }
  3082. /**
  3083. * Copies the values of `source` to `array`.
  3084. *
  3085. * @private
  3086. * @param {Array} source The array to copy values from.
  3087. * @param {Array} [array=[]] The array to copy values to.
  3088. * @returns {Array} Returns `array`.
  3089. */
  3090. function arrayCopy(source, array) {
  3091. var index = -1,
  3092. length = source.length;
  3093. array || (array = Array(length));
  3094. while (++index < length) {
  3095. array[index] = source[index];
  3096. }
  3097. return array;
  3098. }
  3099. /**
  3100. * A specialized version of `_.forEach` for arrays without support for callback
  3101. * shorthands and `this` binding.
  3102. *
  3103. * @private
  3104. * @param {Array} array The array to iterate over.
  3105. * @param {Function} iteratee The function invoked per iteration.
  3106. * @returns {Array} Returns `array`.
  3107. */
  3108. function arrayEach(array, iteratee) {
  3109. var index = -1,
  3110. length = array.length;
  3111. while (++index < length) {
  3112. if (iteratee(array[index], index, array) === false) {
  3113. break;
  3114. }
  3115. }
  3116. return array;
  3117. }
  3118. /**
  3119. * A specialized version of `_.forEachRight` for arrays without support for
  3120. * callback shorthands and `this` binding.
  3121. *
  3122. * @private
  3123. * @param {Array} array The array to iterate over.
  3124. * @param {Function} iteratee The function invoked per iteration.
  3125. * @returns {Array} Returns `array`.
  3126. */
  3127. function arrayEachRight(array, iteratee) {
  3128. var length = array.length;
  3129. while (length--) {
  3130. if (iteratee(array[length], length, array) === false) {
  3131. break;
  3132. }
  3133. }
  3134. return array;
  3135. }
  3136. /**
  3137. * A specialized version of `_.every` for arrays without support for callback
  3138. * shorthands and `this` binding.
  3139. *
  3140. * @private
  3141. * @param {Array} array The array to iterate over.
  3142. * @param {Function} predicate The function invoked per iteration.
  3143. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  3144. * else `false`.
  3145. */
  3146. function arrayEvery(array, predicate) {
  3147. var index = -1,
  3148. length = array.length;
  3149. while (++index < length) {
  3150. if (!predicate(array[index], index, array)) {
  3151. return false;
  3152. }
  3153. }
  3154. return true;
  3155. }
  3156. /**
  3157. * A specialized version of `baseExtremum` for arrays which invokes `iteratee`
  3158. * with one argument: (value).
  3159. *
  3160. * @private
  3161. * @param {Array} array The array to iterate over.
  3162. * @param {Function} iteratee The function invoked per iteration.
  3163. * @param {Function} comparator The function used to compare values.
  3164. * @param {*} exValue The initial extremum value.
  3165. * @returns {*} Returns the extremum value.
  3166. */
  3167. function arrayExtremum(array, iteratee, comparator, exValue) {
  3168. var index = -1,
  3169. length = array.length,
  3170. computed = exValue,
  3171. result = computed;
  3172. while (++index < length) {
  3173. var value = array[index],
  3174. current = +iteratee(value);
  3175. if (comparator(current, computed)) {
  3176. computed = current;
  3177. result = value;
  3178. }
  3179. }
  3180. return result;
  3181. }
  3182. /**
  3183. * A specialized version of `_.filter` for arrays without support for callback
  3184. * shorthands and `this` binding.
  3185. *
  3186. * @private
  3187. * @param {Array} array The array to iterate over.
  3188. * @param {Function} predicate The function invoked per iteration.
  3189. * @returns {Array} Returns the new filtered array.
  3190. */
  3191. function arrayFilter(array, predicate) {
  3192. var index = -1,
  3193. length = array.length,
  3194. resIndex = -1,
  3195. result = [];
  3196. while (++index < length) {
  3197. var value = array[index];
  3198. if (predicate(value, index, array)) {
  3199. result[++resIndex] = value;
  3200. }
  3201. }
  3202. return result;
  3203. }
  3204. /**
  3205. * A specialized version of `_.map` for arrays without support for callback
  3206. * shorthands and `this` binding.
  3207. *
  3208. * @private
  3209. * @param {Array} array The array to iterate over.
  3210. * @param {Function} iteratee The function invoked per iteration.
  3211. * @returns {Array} Returns the new mapped array.
  3212. */
  3213. function arrayMap(array, iteratee) {
  3214. var index = -1,
  3215. length = array.length,
  3216. result = Array(length);
  3217. while (++index < length) {
  3218. result[index] = iteratee(array[index], index, array);
  3219. }
  3220. return result;
  3221. }
  3222. /**
  3223. * Appends the elements of `values` to `array`.
  3224. *
  3225. * @private
  3226. * @param {Array} array The array to modify.
  3227. * @param {Array} values The values to append.
  3228. * @returns {Array} Returns `array`.
  3229. */
  3230. function arrayPush(array, values) {
  3231. var index = -1,
  3232. length = values.length,
  3233. offset = array.length;
  3234. while (++index < length) {
  3235. array[offset + index] = values[index];
  3236. }
  3237. return array;
  3238. }
  3239. /**
  3240. * A specialized version of `_.reduce` for arrays without support for callback
  3241. * shorthands and `this` binding.
  3242. *
  3243. * @private
  3244. * @param {Array} array The array to iterate over.
  3245. * @param {Function} iteratee The function invoked per iteration.
  3246. * @param {*} [accumulator] The initial value.
  3247. * @param {boolean} [initFromArray] Specify using the first element of `array`
  3248. * as the initial value.
  3249. * @returns {*} Returns the accumulated value.
  3250. */
  3251. function arrayReduce(array, iteratee, accumulator, initFromArray) {
  3252. var index = -1,
  3253. length = array.length;
  3254. if (initFromArray && length) {
  3255. accumulator = array[++index];
  3256. }
  3257. while (++index < length) {
  3258. accumulator = iteratee(accumulator, array[index], index, array);
  3259. }
  3260. return accumulator;
  3261. }
  3262. /**
  3263. * A specialized version of `_.reduceRight` for arrays without support for
  3264. * callback shorthands and `this` binding.
  3265. *
  3266. * @private
  3267. * @param {Array} array The array to iterate over.
  3268. * @param {Function} iteratee The function invoked per iteration.
  3269. * @param {*} [accumulator] The initial value.
  3270. * @param {boolean} [initFromArray] Specify using the last element of `array`
  3271. * as the initial value.
  3272. * @returns {*} Returns the accumulated value.
  3273. */
  3274. function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
  3275. var length = array.length;
  3276. if (initFromArray && length) {
  3277. accumulator = array[--length];
  3278. }
  3279. while (length--) {
  3280. accumulator = iteratee(accumulator, array[length], length, array);
  3281. }
  3282. return accumulator;
  3283. }
  3284. /**
  3285. * A specialized version of `_.some` for arrays without support for callback
  3286. * shorthands and `this` binding.
  3287. *
  3288. * @private
  3289. * @param {Array} array The array to iterate over.
  3290. * @param {Function} predicate The function invoked per iteration.
  3291. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3292. * else `false`.
  3293. */
  3294. function arraySome(array, predicate) {
  3295. var index = -1,
  3296. length = array.length;
  3297. while (++index < length) {
  3298. if (predicate(array[index], index, array)) {
  3299. return true;
  3300. }
  3301. }
  3302. return false;
  3303. }
  3304. /**
  3305. * A specialized version of `_.sum` for arrays without support for callback
  3306. * shorthands and `this` binding..
  3307. *
  3308. * @private
  3309. * @param {Array} array The array to iterate over.
  3310. * @param {Function} iteratee The function invoked per iteration.
  3311. * @returns {number} Returns the sum.
  3312. */
  3313. function arraySum(array, iteratee) {
  3314. var length = array.length,
  3315. result = 0;
  3316. while (length--) {
  3317. result += +iteratee(array[length]) || 0;
  3318. }
  3319. return result;
  3320. }
  3321. /**
  3322. * Used by `_.defaults` to customize its `_.assign` use.
  3323. *
  3324. * @private
  3325. * @param {*} objectValue The destination object property value.
  3326. * @param {*} sourceValue The source object property value.
  3327. * @returns {*} Returns the value to assign to the destination object.
  3328. */
  3329. function assignDefaults(objectValue, sourceValue) {
  3330. return objectValue === undefined ? sourceValue : objectValue;
  3331. }
  3332. /**
  3333. * Used by `_.template` to customize its `_.assign` use.
  3334. *
  3335. * **Note:** This function is like `assignDefaults` except that it ignores
  3336. * inherited property values when checking if a property is `undefined`.
  3337. *
  3338. * @private
  3339. * @param {*} objectValue The destination object property value.
  3340. * @param {*} sourceValue The source object property value.
  3341. * @param {string} key The key associated with the object and source values.
  3342. * @param {Object} object The destination object.
  3343. * @returns {*} Returns the value to assign to the destination object.
  3344. */
  3345. function assignOwnDefaults(objectValue, sourceValue, key, object) {
  3346. return (objectValue === undefined || !hasOwnProperty.call(object, key))
  3347. ? sourceValue
  3348. : objectValue;
  3349. }
  3350. /**
  3351. * A specialized version of `_.assign` for customizing assigned values without
  3352. * support for argument juggling, multiple sources, and `this` binding `customizer`
  3353. * functions.
  3354. *
  3355. * @private
  3356. * @param {Object} object The destination object.
  3357. * @param {Object} source The source object.
  3358. * @param {Function} customizer The function to customize assigned values.
  3359. * @returns {Object} Returns `object`.
  3360. */
  3361. function assignWith(object, source, customizer) {
  3362. var index = -1,
  3363. props = keys(source),
  3364. length = props.length;
  3365. while (++index < length) {
  3366. var key = props[index],
  3367. value = object[key],
  3368. result = customizer(value, source[key], key, object, source);
  3369. if ((result === result ? (result !== value) : (value === value)) ||
  3370. (value === undefined && !(key in object))) {
  3371. object[key] = result;
  3372. }
  3373. }
  3374. return object;
  3375. }
  3376. /**
  3377. * The base implementation of `_.assign` without support for argument juggling,
  3378. * multiple sources, and `customizer` functions.
  3379. *
  3380. * @private
  3381. * @param {Object} object The destination object.
  3382. * @param {Object} source The source object.
  3383. * @returns {Object} Returns `object`.
  3384. */
  3385. function baseAssign(object, source) {
  3386. return source == null
  3387. ? object
  3388. : baseCopy(source, keys(source), object);
  3389. }
  3390. /**
  3391. * The base implementation of `_.at` without support for string collections
  3392. * and individual key arguments.
  3393. *
  3394. * @private
  3395. * @param {Array|Object} collection The collection to iterate over.
  3396. * @param {number[]|string[]} props The property names or indexes of elements to pick.
  3397. * @returns {Array} Returns the new array of picked elements.
  3398. */
  3399. function baseAt(collection, props) {
  3400. var index = -1,
  3401. isNil = collection == null,
  3402. isArr = !isNil && isArrayLike(collection),
  3403. length = isArr ? collection.length : 0,
  3404. propsLength = props.length,
  3405. result = Array(propsLength);
  3406. while(++index < propsLength) {
  3407. var key = props[index];
  3408. if (isArr) {
  3409. result[index] = isIndex(key, length) ? collection[key] : undefined;
  3410. } else {
  3411. result[index] = isNil ? undefined : collection[key];
  3412. }
  3413. }
  3414. return result;
  3415. }
  3416. /**
  3417. * Copies properties of `source` to `object`.
  3418. *
  3419. * @private
  3420. * @param {Object} source The object to copy properties from.
  3421. * @param {Array} props The property names to copy.
  3422. * @param {Object} [object={}] The object to copy properties to.
  3423. * @returns {Object} Returns `object`.
  3424. */
  3425. function baseCopy(source, props, object) {
  3426. object || (object = {});
  3427. var index = -1,
  3428. length = props.length;
  3429. while (++index < length) {
  3430. var key = props[index];
  3431. object[key] = source[key];
  3432. }
  3433. return object;
  3434. }
  3435. /**
  3436. * The base implementation of `_.callback` which supports specifying the
  3437. * number of arguments to provide to `func`.
  3438. *
  3439. * @private
  3440. * @param {*} [func=_.identity] The value to convert to a callback.
  3441. * @param {*} [thisArg] The `this` binding of `func`.
  3442. * @param {number} [argCount] The number of arguments to provide to `func`.
  3443. * @returns {Function} Returns the callback.
  3444. */
  3445. function baseCallback(func, thisArg, argCount) {
  3446. var type = typeof func;
  3447. if (type == 'function') {
  3448. return thisArg === undefined
  3449. ? func
  3450. : bindCallback(func, thisArg, argCount);
  3451. }
  3452. if (func == null) {
  3453. return identity;
  3454. }
  3455. if (type == 'object') {
  3456. return baseMatches(func);
  3457. }
  3458. return thisArg === undefined
  3459. ? property(func)
  3460. : baseMatchesProperty(func, thisArg);
  3461. }
  3462. /**
  3463. * The base implementation of `_.clone` without support for argument juggling
  3464. * and `this` binding `customizer` functions.
  3465. *
  3466. * @private
  3467. * @param {*} value The value to clone.
  3468. * @param {boolean} [isDeep] Specify a deep clone.
  3469. * @param {Function} [customizer] The function to customize cloning values.
  3470. * @param {string} [key] The key of `value`.
  3471. * @param {Object} [object] The object `value` belongs to.
  3472. * @param {Array} [stackA=[]] Tracks traversed source objects.
  3473. * @param {Array} [stackB=[]] Associates clones with source counterparts.
  3474. * @returns {*} Returns the cloned value.
  3475. */
  3476. function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
  3477. var result;
  3478. if (customizer) {
  3479. result = object ? customizer(value, key, object) : customizer(value);
  3480. }
  3481. if (result !== undefined) {
  3482. return result;
  3483. }
  3484. if (!isObject(value)) {
  3485. return value;
  3486. }
  3487. var isArr = isArray(value);
  3488. if (isArr) {
  3489. result = initCloneArray(value);
  3490. if (!isDeep) {
  3491. return arrayCopy(value, result);
  3492. }
  3493. } else {
  3494. var tag = objToString.call(value),
  3495. isFunc = tag == funcTag;
  3496. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  3497. result = initCloneObject(isFunc ? {} : value);
  3498. if (!isDeep) {
  3499. return baseAssign(result, value);
  3500. }
  3501. } else {
  3502. return cloneableTags[tag]
  3503. ? initCloneByTag(value, tag, isDeep)
  3504. : (object ? value : {});
  3505. }
  3506. }
  3507. // Check for circular references and return its corresponding clone.
  3508. stackA || (stackA = []);
  3509. stackB || (stackB = []);
  3510. var length = stackA.length;
  3511. while (length--) {
  3512. if (stackA[length] == value) {
  3513. return stackB[length];
  3514. }
  3515. }
  3516. // Add the source value to the stack of traversed objects and associate it with its clone.
  3517. stackA.push(value);
  3518. stackB.push(result);
  3519. // Recursively populate clone (susceptible to call stack limits).
  3520. (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
  3521. result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB);
  3522. });
  3523. return result;
  3524. }
  3525. /**
  3526. * The base implementation of `_.create` without support for assigning
  3527. * properties to the created object.
  3528. *
  3529. * @private
  3530. * @param {Object} prototype The object to inherit from.
  3531. * @returns {Object} Returns the new object.
  3532. */
  3533. var baseCreate = (function() {
  3534. function object() {}
  3535. return function(prototype) {
  3536. if (isObject(prototype)) {
  3537. object.prototype = prototype;
  3538. var result = new object;
  3539. object.prototype = undefined;
  3540. }
  3541. return result || {};
  3542. };
  3543. }());
  3544. /**
  3545. * The base implementation of `_.delay` and `_.defer` which accepts an index
  3546. * of where to slice the arguments to provide to `func`.
  3547. *
  3548. * @private
  3549. * @param {Function} func The function to delay.
  3550. * @param {number} wait The number of milliseconds to delay invocation.
  3551. * @param {Object} args The arguments provide to `func`.
  3552. * @returns {number} Returns the timer id.
  3553. */
  3554. function baseDelay(func, wait, args) {
  3555. if (typeof func != 'function') {
  3556. throw new TypeError(FUNC_ERROR_TEXT);
  3557. }
  3558. return setTimeout(function() { func.apply(undefined, args); }, wait);
  3559. }
  3560. /**
  3561. * The base implementation of `_.difference` which accepts a single array
  3562. * of values to exclude.
  3563. *
  3564. * @private
  3565. * @param {Array} array The array to inspect.
  3566. * @param {Array} values The values to exclude.
  3567. * @returns {Array} Returns the new array of filtered values.
  3568. */
  3569. function baseDifference(array, values) {
  3570. var length = array ? array.length : 0,
  3571. result = [];
  3572. if (!length) {
  3573. return result;
  3574. }
  3575. var index = -1,
  3576. indexOf = getIndexOf(),
  3577. isCommon = indexOf == baseIndexOf,
  3578. cache = (isCommon && values.length >= LARGE_ARRAY_SIZE) ? createCache(values) : null,
  3579. valuesLength = values.length;
  3580. if (cache) {
  3581. indexOf = cacheIndexOf;
  3582. isCommon = false;
  3583. values = cache;
  3584. }
  3585. outer:
  3586. while (++index < length) {
  3587. var value = array[index];
  3588. if (isCommon && value === value) {
  3589. var valuesIndex = valuesLength;
  3590. while (valuesIndex--) {
  3591. if (values[valuesIndex] === value) {
  3592. continue outer;
  3593. }
  3594. }
  3595. result.push(value);
  3596. }
  3597. else if (indexOf(values, value, 0) < 0) {
  3598. result.push(value);
  3599. }
  3600. }
  3601. return result;
  3602. }
  3603. /**
  3604. * The base implementation of `_.forEach` without support for callback
  3605. * shorthands and `this` binding.
  3606. *
  3607. * @private
  3608. * @param {Array|Object|string} collection The collection to iterate over.
  3609. * @param {Function} iteratee The function invoked per iteration.
  3610. * @returns {Array|Object|string} Returns `collection`.
  3611. */
  3612. var baseEach = createBaseEach(baseForOwn);
  3613. /**
  3614. * The base implementation of `_.forEachRight` without support for callback
  3615. * shorthands and `this` binding.
  3616. *
  3617. * @private
  3618. * @param {Array|Object|string} collection The collection to iterate over.
  3619. * @param {Function} iteratee The function invoked per iteration.
  3620. * @returns {Array|Object|string} Returns `collection`.
  3621. */
  3622. var baseEachRight = createBaseEach(baseForOwnRight, true);
  3623. /**
  3624. * The base implementation of `_.every` without support for callback
  3625. * shorthands and `this` binding.
  3626. *
  3627. * @private
  3628. * @param {Array|Object|string} collection The collection to iterate over.
  3629. * @param {Function} predicate The function invoked per iteration.
  3630. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  3631. * else `false`
  3632. */
  3633. function baseEvery(collection, predicate) {
  3634. var result = true;
  3635. baseEach(collection, function(value, index, collection) {
  3636. result = !!predicate(value, index, collection);
  3637. return result;
  3638. });
  3639. return result;
  3640. }
  3641. /**
  3642. * Gets the extremum value of `collection` invoking `iteratee` for each value
  3643. * in `collection` to generate the criterion by which the value is ranked.
  3644. * The `iteratee` is invoked with three arguments: (value, index|key, collection).
  3645. *
  3646. * @private
  3647. * @param {Array|Object|string} collection The collection to iterate over.
  3648. * @param {Function} iteratee The function invoked per iteration.
  3649. * @param {Function} comparator The function used to compare values.
  3650. * @param {*} exValue The initial extremum value.
  3651. * @returns {*} Returns the extremum value.
  3652. */
  3653. function baseExtremum(collection, iteratee, comparator, exValue) {
  3654. var computed = exValue,
  3655. result = computed;
  3656. baseEach(collection, function(value, index, collection) {
  3657. var current = +iteratee(value, index, collection);
  3658. if (comparator(current, computed) || (current === exValue && current === result)) {
  3659. computed = current;
  3660. result = value;
  3661. }
  3662. });
  3663. return result;
  3664. }
  3665. /**
  3666. * The base implementation of `_.fill` without an iteratee call guard.
  3667. *
  3668. * @private
  3669. * @param {Array} array The array to fill.
  3670. * @param {*} value The value to fill `array` with.
  3671. * @param {number} [start=0] The start position.
  3672. * @param {number} [end=array.length] The end position.
  3673. * @returns {Array} Returns `array`.
  3674. */
  3675. function baseFill(array, value, start, end) {
  3676. var length = array.length;
  3677. start = start == null ? 0 : (+start || 0);
  3678. if (start < 0) {
  3679. start = -start > length ? 0 : (length + start);
  3680. }
  3681. end = (end === undefined || end > length) ? length : (+end || 0);
  3682. if (end < 0) {
  3683. end += length;
  3684. }
  3685. length = start > end ? 0 : (end >>> 0);
  3686. start >>>= 0;
  3687. while (start < length) {
  3688. array[start++] = value;
  3689. }
  3690. return array;
  3691. }
  3692. /**
  3693. * The base implementation of `_.filter` without support for callback
  3694. * shorthands and `this` binding.
  3695. *
  3696. * @private
  3697. * @param {Array|Object|string} collection The collection to iterate over.
  3698. * @param {Function} predicate The function invoked per iteration.
  3699. * @returns {Array} Returns the new filtered array.
  3700. */
  3701. function baseFilter(collection, predicate) {
  3702. var result = [];
  3703. baseEach(collection, function(value, index, collection) {
  3704. if (predicate(value, index, collection)) {
  3705. result.push(value);
  3706. }
  3707. });
  3708. return result;
  3709. }
  3710. /**
  3711. * The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.findLastKey`,
  3712. * without support for callback shorthands and `this` binding, which iterates
  3713. * over `collection` using the provided `eachFunc`.
  3714. *
  3715. * @private
  3716. * @param {Array|Object|string} collection The collection to search.
  3717. * @param {Function} predicate The function invoked per iteration.
  3718. * @param {Function} eachFunc The function to iterate over `collection`.
  3719. * @param {boolean} [retKey] Specify returning the key of the found element
  3720. * instead of the element itself.
  3721. * @returns {*} Returns the found element or its key, else `undefined`.
  3722. */
  3723. function baseFind(collection, predicate, eachFunc, retKey) {
  3724. var result;
  3725. eachFunc(collection, function(value, key, collection) {
  3726. if (predicate(value, key, collection)) {
  3727. result = retKey ? key : value;
  3728. return false;
  3729. }
  3730. });
  3731. return result;
  3732. }
  3733. /**
  3734. * The base implementation of `_.flatten` with added support for restricting
  3735. * flattening and specifying the start index.
  3736. *
  3737. * @private
  3738. * @param {Array} array The array to flatten.
  3739. * @param {boolean} [isDeep] Specify a deep flatten.
  3740. * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
  3741. * @param {Array} [result=[]] The initial result value.
  3742. * @returns {Array} Returns the new flattened array.
  3743. */
  3744. function baseFlatten(array, isDeep, isStrict, result) {
  3745. result || (result = []);
  3746. var index = -1,
  3747. length = array.length;
  3748. while (++index < length) {
  3749. var value = array[index];
  3750. if (isObjectLike(value) && isArrayLike(value) &&
  3751. (isStrict || isArray(value) || isArguments(value))) {
  3752. if (isDeep) {
  3753. // Recursively flatten arrays (susceptible to call stack limits).
  3754. baseFlatten(value, isDeep, isStrict, result);
  3755. } else {
  3756. arrayPush(result, value);
  3757. }
  3758. } else if (!isStrict) {
  3759. result[result.length] = value;
  3760. }
  3761. }
  3762. return result;
  3763. }
  3764. /**
  3765. * The base implementation of `baseForIn` and `baseForOwn` which iterates
  3766. * over `object` properties returned by `keysFunc` invoking `iteratee` for
  3767. * each property. Iteratee functions may exit iteration early by explicitly
  3768. * returning `false`.
  3769. *
  3770. * @private
  3771. * @param {Object} object The object to iterate over.
  3772. * @param {Function} iteratee The function invoked per iteration.
  3773. * @param {Function} keysFunc The function to get the keys of `object`.
  3774. * @returns {Object} Returns `object`.
  3775. */
  3776. var baseFor = createBaseFor();
  3777. /**
  3778. * This function is like `baseFor` except that it iterates over properties
  3779. * in the opposite order.
  3780. *
  3781. * @private
  3782. * @param {Object} object The object to iterate over.
  3783. * @param {Function} iteratee The function invoked per iteration.
  3784. * @param {Function} keysFunc The function to get the keys of `object`.
  3785. * @returns {Object} Returns `object`.
  3786. */
  3787. var baseForRight = createBaseFor(true);
  3788. /**
  3789. * The base implementation of `_.forIn` without support for callback
  3790. * shorthands and `this` binding.
  3791. *
  3792. * @private
  3793. * @param {Object} object The object to iterate over.
  3794. * @param {Function} iteratee The function invoked per iteration.
  3795. * @returns {Object} Returns `object`.
  3796. */
  3797. function baseForIn(object, iteratee) {
  3798. return baseFor(object, iteratee, keysIn);
  3799. }
  3800. /**
  3801. * The base implementation of `_.forOwn` without support for callback
  3802. * shorthands and `this` binding.
  3803. *
  3804. * @private
  3805. * @param {Object} object The object to iterate over.
  3806. * @param {Function} iteratee The function invoked per iteration.
  3807. * @returns {Object} Returns `object`.
  3808. */
  3809. function baseForOwn(object, iteratee) {
  3810. return baseFor(object, iteratee, keys);
  3811. }
  3812. /**
  3813. * The base implementation of `_.forOwnRight` without support for callback
  3814. * shorthands and `this` binding.
  3815. *
  3816. * @private
  3817. * @param {Object} object The object to iterate over.
  3818. * @param {Function} iteratee The function invoked per iteration.
  3819. * @returns {Object} Returns `object`.
  3820. */
  3821. function baseForOwnRight(object, iteratee) {
  3822. return baseForRight(object, iteratee, keys);
  3823. }
  3824. /**
  3825. * The base implementation of `_.functions` which creates an array of
  3826. * `object` function property names filtered from those provided.
  3827. *
  3828. * @private
  3829. * @param {Object} object The object to inspect.
  3830. * @param {Array} props The property names to filter.
  3831. * @returns {Array} Returns the new array of filtered property names.
  3832. */
  3833. function baseFunctions(object, props) {
  3834. var index = -1,
  3835. length = props.length,
  3836. resIndex = -1,
  3837. result = [];
  3838. while (++index < length) {
  3839. var key = props[index];
  3840. if (isFunction(object[key])) {
  3841. result[++resIndex] = key;
  3842. }
  3843. }
  3844. return result;
  3845. }
  3846. /**
  3847. * The base implementation of `get` without support for string paths
  3848. * and default values.
  3849. *
  3850. * @private
  3851. * @param {Object} object The object to query.
  3852. * @param {Array} path The path of the property to get.
  3853. * @param {string} [pathKey] The key representation of path.
  3854. * @returns {*} Returns the resolved value.
  3855. */
  3856. function baseGet(object, path, pathKey) {
  3857. if (object == null) {
  3858. return;
  3859. }
  3860. if (pathKey !== undefined && pathKey in toObject(object)) {
  3861. path = [pathKey];
  3862. }
  3863. var index = 0,
  3864. length = path.length;
  3865. while (object != null && index < length) {
  3866. object = object[path[index++]];
  3867. }
  3868. return (index && index == length) ? object : undefined;
  3869. }
  3870. /**
  3871. * The base implementation of `_.isEqual` without support for `this` binding
  3872. * `customizer` functions.
  3873. *
  3874. * @private
  3875. * @param {*} value The value to compare.
  3876. * @param {*} other The other value to compare.
  3877. * @param {Function} [customizer] The function to customize comparing values.
  3878. * @param {boolean} [isLoose] Specify performing partial comparisons.
  3879. * @param {Array} [stackA] Tracks traversed `value` objects.
  3880. * @param {Array} [stackB] Tracks traversed `other` objects.
  3881. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  3882. */
  3883. function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
  3884. if (value === other) {
  3885. return true;
  3886. }
  3887. if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
  3888. return value !== value && other !== other;
  3889. }
  3890. return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
  3891. }
  3892. /**
  3893. * A specialized version of `baseIsEqual` for arrays and objects which performs
  3894. * deep comparisons and tracks traversed objects enabling objects with circular
  3895. * references to be compared.
  3896. *
  3897. * @private
  3898. * @param {Object} object The object to compare.
  3899. * @param {Object} other The other object to compare.
  3900. * @param {Function} equalFunc The function to determine equivalents of values.
  3901. * @param {Function} [customizer] The function to customize comparing objects.
  3902. * @param {boolean} [isLoose] Specify performing partial comparisons.
  3903. * @param {Array} [stackA=[]] Tracks traversed `value` objects.
  3904. * @param {Array} [stackB=[]] Tracks traversed `other` objects.
  3905. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3906. */
  3907. function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
  3908. var objIsArr = isArray(object),
  3909. othIsArr = isArray(other),
  3910. objTag = arrayTag,
  3911. othTag = arrayTag;
  3912. if (!objIsArr) {
  3913. objTag = objToString.call(object);
  3914. if (objTag == argsTag) {
  3915. objTag = objectTag;
  3916. } else if (objTag != objectTag) {
  3917. objIsArr = isTypedArray(object);
  3918. }
  3919. }
  3920. if (!othIsArr) {
  3921. othTag = objToString.call(other);
  3922. if (othTag == argsTag) {
  3923. othTag = objectTag;
  3924. } else if (othTag != objectTag) {
  3925. othIsArr = isTypedArray(other);
  3926. }
  3927. }
  3928. var objIsObj = objTag == objectTag,
  3929. othIsObj = othTag == objectTag,
  3930. isSameTag = objTag == othTag;
  3931. if (isSameTag && !(objIsArr || objIsObj)) {
  3932. return equalByTag(object, other, objTag);
  3933. }
  3934. if (!isLoose) {
  3935. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  3936. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  3937. if (objIsWrapped || othIsWrapped) {
  3938. return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
  3939. }
  3940. }
  3941. if (!isSameTag) {
  3942. return false;
  3943. }
  3944. // Assume cyclic values are equal.
  3945. // For more information on detecting circular references see https://es5.github.io/#JO.
  3946. stackA || (stackA = []);
  3947. stackB || (stackB = []);
  3948. var length = stackA.length;
  3949. while (length--) {
  3950. if (stackA[length] == object) {
  3951. return stackB[length] == other;
  3952. }
  3953. }
  3954. // Add `object` and `other` to the stack of traversed objects.
  3955. stackA.push(object);
  3956. stackB.push(other);
  3957. var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB);
  3958. stackA.pop();
  3959. stackB.pop();
  3960. return result;
  3961. }
  3962. /**
  3963. * The base implementation of `_.isMatch` without support for callback
  3964. * shorthands and `this` binding.
  3965. *
  3966. * @private
  3967. * @param {Object} object The object to inspect.
  3968. * @param {Array} matchData The propery names, values, and compare flags to match.
  3969. * @param {Function} [customizer] The function to customize comparing objects.
  3970. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  3971. */
  3972. function baseIsMatch(object, matchData, customizer) {
  3973. var index = matchData.length,
  3974. length = index,
  3975. noCustomizer = !customizer;
  3976. if (object == null) {
  3977. return !length;
  3978. }
  3979. object = toObject(object);
  3980. while (index--) {
  3981. var data = matchData[index];
  3982. if ((noCustomizer && data[2])
  3983. ? data[1] !== object[data[0]]
  3984. : !(data[0] in object)
  3985. ) {
  3986. return false;
  3987. }
  3988. }
  3989. while (++index < length) {
  3990. data = matchData[index];
  3991. var key = data[0],
  3992. objValue = object[key],
  3993. srcValue = data[1];
  3994. if (noCustomizer && data[2]) {
  3995. if (objValue === undefined && !(key in object)) {
  3996. return false;
  3997. }
  3998. } else {
  3999. var result = customizer ? customizer(objValue, srcValue, key) : undefined;
  4000. if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) {
  4001. return false;
  4002. }
  4003. }
  4004. }
  4005. return true;
  4006. }
  4007. /**
  4008. * The base implementation of `_.map` without support for callback shorthands
  4009. * and `this` binding.
  4010. *
  4011. * @private
  4012. * @param {Array|Object|string} collection The collection to iterate over.
  4013. * @param {Function} iteratee The function invoked per iteration.
  4014. * @returns {Array} Returns the new mapped array.
  4015. */
  4016. function baseMap(collection, iteratee) {
  4017. var index = -1,
  4018. result = isArrayLike(collection) ? Array(collection.length) : [];
  4019. baseEach(collection, function(value, key, collection) {
  4020. result[++index] = iteratee(value, key, collection);
  4021. });
  4022. return result;
  4023. }
  4024. /**
  4025. * The base implementation of `_.matches` which does not clone `source`.
  4026. *
  4027. * @private
  4028. * @param {Object} source The object of property values to match.
  4029. * @returns {Function} Returns the new function.
  4030. */
  4031. function baseMatches(source) {
  4032. var matchData = getMatchData(source);
  4033. if (matchData.length == 1 && matchData[0][2]) {
  4034. var key = matchData[0][0],
  4035. value = matchData[0][1];
  4036. return function(object) {
  4037. if (object == null) {
  4038. return false;
  4039. }
  4040. return object[key] === value && (value !== undefined || (key in toObject(object)));
  4041. };
  4042. }
  4043. return function(object) {
  4044. return baseIsMatch(object, matchData);
  4045. };
  4046. }
  4047. /**
  4048. * The base implementation of `_.matchesProperty` which does not clone `srcValue`.
  4049. *
  4050. * @private
  4051. * @param {string} path The path of the property to get.
  4052. * @param {*} srcValue The value to compare.
  4053. * @returns {Function} Returns the new function.
  4054. */
  4055. function baseMatchesProperty(path, srcValue) {
  4056. var isArr = isArray(path),
  4057. isCommon = isKey(path) && isStrictComparable(srcValue),
  4058. pathKey = (path + '');
  4059. path = toPath(path);
  4060. return function(object) {
  4061. if (object == null) {
  4062. return false;
  4063. }
  4064. var key = pathKey;
  4065. object = toObject(object);
  4066. if ((isArr || !isCommon) && !(key in object)) {
  4067. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  4068. if (object == null) {
  4069. return false;
  4070. }
  4071. key = last(path);
  4072. object = toObject(object);
  4073. }
  4074. return object[key] === srcValue
  4075. ? (srcValue !== undefined || (key in object))
  4076. : baseIsEqual(srcValue, object[key], undefined, true);
  4077. };
  4078. }
  4079. /**
  4080. * The base implementation of `_.merge` without support for argument juggling,
  4081. * multiple sources, and `this` binding `customizer` functions.
  4082. *
  4083. * @private
  4084. * @param {Object} object The destination object.
  4085. * @param {Object} source The source object.
  4086. * @param {Function} [customizer] The function to customize merged values.
  4087. * @param {Array} [stackA=[]] Tracks traversed source objects.
  4088. * @param {Array} [stackB=[]] Associates values with source counterparts.
  4089. * @returns {Object} Returns `object`.
  4090. */
  4091. function baseMerge(object, source, customizer, stackA, stackB) {
  4092. if (!isObject(object)) {
  4093. return object;
  4094. }
  4095. var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
  4096. props = isSrcArr ? undefined : keys(source);
  4097. arrayEach(props || source, function(srcValue, key) {
  4098. if (props) {
  4099. key = srcValue;
  4100. srcValue = source[key];
  4101. }
  4102. if (isObjectLike(srcValue)) {
  4103. stackA || (stackA = []);
  4104. stackB || (stackB = []);
  4105. baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
  4106. }
  4107. else {
  4108. var value = object[key],
  4109. result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
  4110. isCommon = result === undefined;
  4111. if (isCommon) {
  4112. result = srcValue;
  4113. }
  4114. if ((result !== undefined || (isSrcArr && !(key in object))) &&
  4115. (isCommon || (result === result ? (result !== value) : (value === value)))) {
  4116. object[key] = result;
  4117. }
  4118. }
  4119. });
  4120. return object;
  4121. }
  4122. /**
  4123. * A specialized version of `baseMerge` for arrays and objects which performs
  4124. * deep merges and tracks traversed objects enabling objects with circular
  4125. * references to be merged.
  4126. *
  4127. * @private
  4128. * @param {Object} object The destination object.
  4129. * @param {Object} source The source object.
  4130. * @param {string} key The key of the value to merge.
  4131. * @param {Function} mergeFunc The function to merge values.
  4132. * @param {Function} [customizer] The function to customize merged values.
  4133. * @param {Array} [stackA=[]] Tracks traversed source objects.
  4134. * @param {Array} [stackB=[]] Associates values with source counterparts.
  4135. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  4136. */
  4137. function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
  4138. var length = stackA.length,
  4139. srcValue = source[key];
  4140. while (length--) {
  4141. if (stackA[length] == srcValue) {
  4142. object[key] = stackB[length];
  4143. return;
  4144. }
  4145. }
  4146. var value = object[key],
  4147. result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
  4148. isCommon = result === undefined;
  4149. if (isCommon) {
  4150. result = srcValue;
  4151. if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
  4152. result = isArray(value)
  4153. ? value
  4154. : (isArrayLike(value) ? arrayCopy(value) : []);
  4155. }
  4156. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  4157. result = isArguments(value)
  4158. ? toPlainObject(value)
  4159. : (isPlainObject(value) ? value : {});
  4160. }
  4161. else {
  4162. isCommon = false;
  4163. }
  4164. }
  4165. // Add the source value to the stack of traversed objects and associate
  4166. // it with its merged value.
  4167. stackA.push(srcValue);
  4168. stackB.push(result);
  4169. if (isCommon) {
  4170. // Recursively merge objects and arrays (susceptible to call stack limits).
  4171. object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
  4172. } else if (result === result ? (result !== value) : (value === value)) {
  4173. object[key] = result;
  4174. }
  4175. }
  4176. /**
  4177. * The base implementation of `_.property` without support for deep paths.
  4178. *
  4179. * @private
  4180. * @param {string} key The key of the property to get.
  4181. * @returns {Function} Returns the new function.
  4182. */
  4183. function baseProperty(key) {
  4184. return function(object) {
  4185. return object == null ? undefined : object[key];
  4186. };
  4187. }
  4188. /**
  4189. * A specialized version of `baseProperty` which supports deep paths.
  4190. *
  4191. * @private
  4192. * @param {Array|string} path The path of the property to get.
  4193. * @returns {Function} Returns the new function.
  4194. */
  4195. function basePropertyDeep(path) {
  4196. var pathKey = (path + '');
  4197. path = toPath(path);
  4198. return function(object) {
  4199. return baseGet(object, path, pathKey);
  4200. };
  4201. }
  4202. /**
  4203. * The base implementation of `_.pullAt` without support for individual
  4204. * index arguments and capturing the removed elements.
  4205. *
  4206. * @private
  4207. * @param {Array} array The array to modify.
  4208. * @param {number[]} indexes The indexes of elements to remove.
  4209. * @returns {Array} Returns `array`.
  4210. */
  4211. function basePullAt(array, indexes) {
  4212. var length = array ? indexes.length : 0;
  4213. while (length--) {
  4214. var index = indexes[length];
  4215. if (index != previous && isIndex(index)) {
  4216. var previous = index;
  4217. splice.call(array, index, 1);
  4218. }
  4219. }
  4220. return array;
  4221. }
  4222. /**
  4223. * The base implementation of `_.random` without support for argument juggling
  4224. * and returning floating-point numbers.
  4225. *
  4226. * @private
  4227. * @param {number} min The minimum possible value.
  4228. * @param {number} max The maximum possible value.
  4229. * @returns {number} Returns the random number.
  4230. */
  4231. function baseRandom(min, max) {
  4232. return min + nativeFloor(nativeRandom() * (max - min + 1));
  4233. }
  4234. /**
  4235. * The base implementation of `_.reduce` and `_.reduceRight` without support
  4236. * for callback shorthands and `this` binding, which iterates over `collection`
  4237. * using the provided `eachFunc`.
  4238. *
  4239. * @private
  4240. * @param {Array|Object|string} collection The collection to iterate over.
  4241. * @param {Function} iteratee The function invoked per iteration.
  4242. * @param {*} accumulator The initial value.
  4243. * @param {boolean} initFromCollection Specify using the first or last element
  4244. * of `collection` as the initial value.
  4245. * @param {Function} eachFunc The function to iterate over `collection`.
  4246. * @returns {*} Returns the accumulated value.
  4247. */
  4248. function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
  4249. eachFunc(collection, function(value, index, collection) {
  4250. accumulator = initFromCollection
  4251. ? (initFromCollection = false, value)
  4252. : iteratee(accumulator, value, index, collection);
  4253. });
  4254. return accumulator;
  4255. }
  4256. /**
  4257. * The base implementation of `setData` without support for hot loop detection.
  4258. *
  4259. * @private
  4260. * @param {Function} func The function to associate metadata with.
  4261. * @param {*} data The metadata.
  4262. * @returns {Function} Returns `func`.
  4263. */
  4264. var baseSetData = !metaMap ? identity : function(func, data) {
  4265. metaMap.set(func, data);
  4266. return func;
  4267. };
  4268. /**
  4269. * The base implementation of `_.slice` without an iteratee call guard.
  4270. *
  4271. * @private
  4272. * @param {Array} array The array to slice.
  4273. * @param {number} [start=0] The start position.
  4274. * @param {number} [end=array.length] The end position.
  4275. * @returns {Array} Returns the slice of `array`.
  4276. */
  4277. function baseSlice(array, start, end) {
  4278. var index = -1,
  4279. length = array.length;
  4280. start = start == null ? 0 : (+start || 0);
  4281. if (start < 0) {
  4282. start = -start > length ? 0 : (length + start);
  4283. }
  4284. end = (end === undefined || end > length) ? length : (+end || 0);
  4285. if (end < 0) {
  4286. end += length;
  4287. }
  4288. length = start > end ? 0 : ((end - start) >>> 0);
  4289. start >>>= 0;
  4290. var result = Array(length);
  4291. while (++index < length) {
  4292. result[index] = array[index + start];
  4293. }
  4294. return result;
  4295. }
  4296. /**
  4297. * The base implementation of `_.some` without support for callback shorthands
  4298. * and `this` binding.
  4299. *
  4300. * @private
  4301. * @param {Array|Object|string} collection The collection to iterate over.
  4302. * @param {Function} predicate The function invoked per iteration.
  4303. * @returns {boolean} Returns `true` if any element passes the predicate check,
  4304. * else `false`.
  4305. */
  4306. function baseSome(collection, predicate) {
  4307. var result;
  4308. baseEach(collection, function(value, index, collection) {
  4309. result = predicate(value, index, collection);
  4310. return !result;
  4311. });
  4312. return !!result;
  4313. }
  4314. /**
  4315. * The base implementation of `_.sortBy` which uses `comparer` to define
  4316. * the sort order of `array` and replaces criteria objects with their
  4317. * corresponding values.
  4318. *
  4319. * @private
  4320. * @param {Array} array The array to sort.
  4321. * @param {Function} comparer The function to define sort order.
  4322. * @returns {Array} Returns `array`.
  4323. */
  4324. function baseSortBy(array, comparer) {
  4325. var length = array.length;
  4326. array.sort(comparer);
  4327. while (length--) {
  4328. array[length] = array[length].value;
  4329. }
  4330. return array;
  4331. }
  4332. /**
  4333. * The base implementation of `_.sortByOrder` without param guards.
  4334. *
  4335. * @private
  4336. * @param {Array|Object|string} collection The collection to iterate over.
  4337. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  4338. * @param {boolean[]} orders The sort orders of `iteratees`.
  4339. * @returns {Array} Returns the new sorted array.
  4340. */
  4341. function baseSortByOrder(collection, iteratees, orders) {
  4342. var callback = getCallback(),
  4343. index = -1;
  4344. iteratees = arrayMap(iteratees, function(iteratee) { return callback(iteratee); });
  4345. var result = baseMap(collection, function(value) {
  4346. var criteria = arrayMap(iteratees, function(iteratee) { return iteratee(value); });
  4347. return { 'criteria': criteria, 'index': ++index, 'value': value };
  4348. });
  4349. return baseSortBy(result, function(object, other) {
  4350. return compareMultiple(object, other, orders);
  4351. });
  4352. }
  4353. /**
  4354. * The base implementation of `_.sum` without support for callback shorthands
  4355. * and `this` binding.
  4356. *
  4357. * @private
  4358. * @param {Array|Object|string} collection The collection to iterate over.
  4359. * @param {Function} iteratee The function invoked per iteration.
  4360. * @returns {number} Returns the sum.
  4361. */
  4362. function baseSum(collection, iteratee) {
  4363. var result = 0;
  4364. baseEach(collection, function(value, index, collection) {
  4365. result += +iteratee(value, index, collection) || 0;
  4366. });
  4367. return result;
  4368. }
  4369. /**
  4370. * The base implementation of `_.uniq` without support for callback shorthands
  4371. * and `this` binding.
  4372. *
  4373. * @private
  4374. * @param {Array} array The array to inspect.
  4375. * @param {Function} [iteratee] The function invoked per iteration.
  4376. * @returns {Array} Returns the new duplicate-value-free array.
  4377. */
  4378. function baseUniq(array, iteratee) {
  4379. var index = -1,
  4380. indexOf = getIndexOf(),
  4381. length = array.length,
  4382. isCommon = indexOf == baseIndexOf,
  4383. isLarge = isCommon && length >= LARGE_ARRAY_SIZE,
  4384. seen = isLarge ? createCache() : null,
  4385. result = [];
  4386. if (seen) {
  4387. indexOf = cacheIndexOf;
  4388. isCommon = false;
  4389. } else {
  4390. isLarge = false;
  4391. seen = iteratee ? [] : result;
  4392. }
  4393. outer:
  4394. while (++index < length) {
  4395. var value = array[index],
  4396. computed = iteratee ? iteratee(value, index, array) : value;
  4397. if (isCommon && value === value) {
  4398. var seenIndex = seen.length;
  4399. while (seenIndex--) {
  4400. if (seen[seenIndex] === computed) {
  4401. continue outer;
  4402. }
  4403. }
  4404. if (iteratee) {
  4405. seen.push(computed);
  4406. }
  4407. result.push(value);
  4408. }
  4409. else if (indexOf(seen, computed, 0) < 0) {
  4410. if (iteratee || isLarge) {
  4411. seen.push(computed);
  4412. }
  4413. result.push(value);
  4414. }
  4415. }
  4416. return result;
  4417. }
  4418. /**
  4419. * The base implementation of `_.values` and `_.valuesIn` which creates an
  4420. * array of `object` property values corresponding to the property names
  4421. * of `props`.
  4422. *
  4423. * @private
  4424. * @param {Object} object The object to query.
  4425. * @param {Array} props The property names to get values for.
  4426. * @returns {Object} Returns the array of property values.
  4427. */
  4428. function baseValues(object, props) {
  4429. var index = -1,
  4430. length = props.length,
  4431. result = Array(length);
  4432. while (++index < length) {
  4433. result[index] = object[props[index]];
  4434. }
  4435. return result;
  4436. }
  4437. /**
  4438. * The base implementation of `_.dropRightWhile`, `_.dropWhile`, `_.takeRightWhile`,
  4439. * and `_.takeWhile` without support for callback shorthands and `this` binding.
  4440. *
  4441. * @private
  4442. * @param {Array} array The array to query.
  4443. * @param {Function} predicate The function invoked per iteration.
  4444. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  4445. * @param {boolean} [fromRight] Specify iterating from right to left.
  4446. * @returns {Array} Returns the slice of `array`.
  4447. */
  4448. function baseWhile(array, predicate, isDrop, fromRight) {
  4449. var length = array.length,
  4450. index = fromRight ? length : -1;
  4451. while ((fromRight ? index-- : ++index < length) && predicate(array[index], index, array)) {}
  4452. return isDrop
  4453. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  4454. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  4455. }
  4456. /**
  4457. * The base implementation of `wrapperValue` which returns the result of
  4458. * performing a sequence of actions on the unwrapped `value`, where each
  4459. * successive action is supplied the return value of the previous.
  4460. *
  4461. * @private
  4462. * @param {*} value The unwrapped value.
  4463. * @param {Array} actions Actions to peform to resolve the unwrapped value.
  4464. * @returns {*} Returns the resolved value.
  4465. */
  4466. function baseWrapperValue(value, actions) {
  4467. var result = value;
  4468. if (result instanceof LazyWrapper) {
  4469. result = result.value();
  4470. }
  4471. var index = -1,
  4472. length = actions.length;
  4473. while (++index < length) {
  4474. var action = actions[index];
  4475. result = action.func.apply(action.thisArg, arrayPush([result], action.args));
  4476. }
  4477. return result;
  4478. }
  4479. /**
  4480. * Performs a binary search of `array` to determine the index at which `value`
  4481. * should be inserted into `array` in order to maintain its sort order.
  4482. *
  4483. * @private
  4484. * @param {Array} array The sorted array to inspect.
  4485. * @param {*} value The value to evaluate.
  4486. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  4487. * @returns {number} Returns the index at which `value` should be inserted
  4488. * into `array`.
  4489. */
  4490. function binaryIndex(array, value, retHighest) {
  4491. var low = 0,
  4492. high = array ? array.length : low;
  4493. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  4494. while (low < high) {
  4495. var mid = (low + high) >>> 1,
  4496. computed = array[mid];
  4497. if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) {
  4498. low = mid + 1;
  4499. } else {
  4500. high = mid;
  4501. }
  4502. }
  4503. return high;
  4504. }
  4505. return binaryIndexBy(array, value, identity, retHighest);
  4506. }
  4507. /**
  4508. * This function is like `binaryIndex` except that it invokes `iteratee` for
  4509. * `value` and each element of `array` to compute their sort ranking. The
  4510. * iteratee is invoked with one argument; (value).
  4511. *
  4512. * @private
  4513. * @param {Array} array The sorted array to inspect.
  4514. * @param {*} value The value to evaluate.
  4515. * @param {Function} iteratee The function invoked per iteration.
  4516. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  4517. * @returns {number} Returns the index at which `value` should be inserted
  4518. * into `array`.
  4519. */
  4520. function binaryIndexBy(array, value, iteratee, retHighest) {
  4521. value = iteratee(value);
  4522. var low = 0,
  4523. high = array ? array.length : 0,
  4524. valIsNaN = value !== value,
  4525. valIsNull = value === null,
  4526. valIsUndef = value === undefined;
  4527. while (low < high) {
  4528. var mid = nativeFloor((low + high) / 2),
  4529. computed = iteratee(array[mid]),
  4530. isDef = computed !== undefined,
  4531. isReflexive = computed === computed;
  4532. if (valIsNaN) {
  4533. var setLow = isReflexive || retHighest;
  4534. } else if (valIsNull) {
  4535. setLow = isReflexive && isDef && (retHighest || computed != null);
  4536. } else if (valIsUndef) {
  4537. setLow = isReflexive && (retHighest || isDef);
  4538. } else if (computed == null) {
  4539. setLow = false;
  4540. } else {
  4541. setLow = retHighest ? (computed <= value) : (computed < value);
  4542. }
  4543. if (setLow) {
  4544. low = mid + 1;
  4545. } else {
  4546. high = mid;
  4547. }
  4548. }
  4549. return nativeMin(high, MAX_ARRAY_INDEX);
  4550. }
  4551. /**
  4552. * A specialized version of `baseCallback` which only supports `this` binding
  4553. * and specifying the number of arguments to provide to `func`.
  4554. *
  4555. * @private
  4556. * @param {Function} func The function to bind.
  4557. * @param {*} thisArg The `this` binding of `func`.
  4558. * @param {number} [argCount] The number of arguments to provide to `func`.
  4559. * @returns {Function} Returns the callback.
  4560. */
  4561. function bindCallback(func, thisArg, argCount) {
  4562. if (typeof func != 'function') {
  4563. return identity;
  4564. }
  4565. if (thisArg === undefined) {
  4566. return func;
  4567. }
  4568. switch (argCount) {
  4569. case 1: return function(value) {
  4570. return func.call(thisArg, value);
  4571. };
  4572. case 3: return function(value, index, collection) {
  4573. return func.call(thisArg, value, index, collection);
  4574. };
  4575. case 4: return function(accumulator, value, index, collection) {
  4576. return func.call(thisArg, accumulator, value, index, collection);
  4577. };
  4578. case 5: return function(value, other, key, object, source) {
  4579. return func.call(thisArg, value, other, key, object, source);
  4580. };
  4581. }
  4582. return function() {
  4583. return func.apply(thisArg, arguments);
  4584. };
  4585. }
  4586. /**
  4587. * Creates a clone of the given array buffer.
  4588. *
  4589. * @private
  4590. * @param {ArrayBuffer} buffer The array buffer to clone.
  4591. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4592. */
  4593. function bufferClone(buffer) {
  4594. var result = new ArrayBuffer(buffer.byteLength),
  4595. view = new Uint8Array(result);
  4596. view.set(new Uint8Array(buffer));
  4597. return result;
  4598. }
  4599. /**
  4600. * Creates an array that is the composition of partially applied arguments,
  4601. * placeholders, and provided arguments into a single array of arguments.
  4602. *
  4603. * @private
  4604. * @param {Array|Object} args The provided arguments.
  4605. * @param {Array} partials The arguments to prepend to those provided.
  4606. * @param {Array} holders The `partials` placeholder indexes.
  4607. * @returns {Array} Returns the new array of composed arguments.
  4608. */
  4609. function composeArgs(args, partials, holders) {
  4610. var holdersLength = holders.length,
  4611. argsIndex = -1,
  4612. argsLength = nativeMax(args.length - holdersLength, 0),
  4613. leftIndex = -1,
  4614. leftLength = partials.length,
  4615. result = Array(leftLength + argsLength);
  4616. while (++leftIndex < leftLength) {
  4617. result[leftIndex] = partials[leftIndex];
  4618. }
  4619. while (++argsIndex < holdersLength) {
  4620. result[holders[argsIndex]] = args[argsIndex];
  4621. }
  4622. while (argsLength--) {
  4623. result[leftIndex++] = args[argsIndex++];
  4624. }
  4625. return result;
  4626. }
  4627. /**
  4628. * This function is like `composeArgs` except that the arguments composition
  4629. * is tailored for `_.partialRight`.
  4630. *
  4631. * @private
  4632. * @param {Array|Object} args The provided arguments.
  4633. * @param {Array} partials The arguments to append to those provided.
  4634. * @param {Array} holders The `partials` placeholder indexes.
  4635. * @returns {Array} Returns the new array of composed arguments.
  4636. */
  4637. function composeArgsRight(args, partials, holders) {
  4638. var holdersIndex = -1,
  4639. holdersLength = holders.length,
  4640. argsIndex = -1,
  4641. argsLength = nativeMax(args.length - holdersLength, 0),
  4642. rightIndex = -1,
  4643. rightLength = partials.length,
  4644. result = Array(argsLength + rightLength);
  4645. while (++argsIndex < argsLength) {
  4646. result[argsIndex] = args[argsIndex];
  4647. }
  4648. var offset = argsIndex;
  4649. while (++rightIndex < rightLength) {
  4650. result[offset + rightIndex] = partials[rightIndex];
  4651. }
  4652. while (++holdersIndex < holdersLength) {
  4653. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4654. }
  4655. return result;
  4656. }
  4657. /**
  4658. * Creates a `_.countBy`, `_.groupBy`, `_.indexBy`, or `_.partition` function.
  4659. *
  4660. * @private
  4661. * @param {Function} setter The function to set keys and values of the accumulator object.
  4662. * @param {Function} [initializer] The function to initialize the accumulator object.
  4663. * @returns {Function} Returns the new aggregator function.
  4664. */
  4665. function createAggregator(setter, initializer) {
  4666. return function(collection, iteratee, thisArg) {
  4667. var result = initializer ? initializer() : {};
  4668. iteratee = getCallback(iteratee, thisArg, 3);
  4669. if (isArray(collection)) {
  4670. var index = -1,
  4671. length = collection.length;
  4672. while (++index < length) {
  4673. var value = collection[index];
  4674. setter(result, value, iteratee(value, index, collection), collection);
  4675. }
  4676. } else {
  4677. baseEach(collection, function(value, key, collection) {
  4678. setter(result, value, iteratee(value, key, collection), collection);
  4679. });
  4680. }
  4681. return result;
  4682. };
  4683. }
  4684. /**
  4685. * Creates a `_.assign`, `_.defaults`, or `_.merge` function.
  4686. *
  4687. * @private
  4688. * @param {Function} assigner The function to assign values.
  4689. * @returns {Function} Returns the new assigner function.
  4690. */
  4691. function createAssigner(assigner) {
  4692. return restParam(function(object, sources) {
  4693. var index = -1,
  4694. length = object == null ? 0 : sources.length,
  4695. customizer = length > 2 ? sources[length - 2] : undefined,
  4696. guard = length > 2 ? sources[2] : undefined,
  4697. thisArg = length > 1 ? sources[length - 1] : undefined;
  4698. if (typeof customizer == 'function') {
  4699. customizer = bindCallback(customizer, thisArg, 5);
  4700. length -= 2;
  4701. } else {
  4702. customizer = typeof thisArg == 'function' ? thisArg : undefined;
  4703. length -= (customizer ? 1 : 0);
  4704. }
  4705. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4706. customizer = length < 3 ? undefined : customizer;
  4707. length = 1;
  4708. }
  4709. while (++index < length) {
  4710. var source = sources[index];
  4711. if (source) {
  4712. assigner(object, source, customizer);
  4713. }
  4714. }
  4715. return object;
  4716. });
  4717. }
  4718. /**
  4719. * Creates a `baseEach` or `baseEachRight` function.
  4720. *
  4721. * @private
  4722. * @param {Function} eachFunc The function to iterate over a collection.
  4723. * @param {boolean} [fromRight] Specify iterating from right to left.
  4724. * @returns {Function} Returns the new base function.
  4725. */
  4726. function createBaseEach(eachFunc, fromRight) {
  4727. return function(collection, iteratee) {
  4728. var length = collection ? getLength(collection) : 0;
  4729. if (!isLength(length)) {
  4730. return eachFunc(collection, iteratee);
  4731. }
  4732. var index = fromRight ? length : -1,
  4733. iterable = toObject(collection);
  4734. while ((fromRight ? index-- : ++index < length)) {
  4735. if (iteratee(iterable[index], index, iterable) === false) {
  4736. break;
  4737. }
  4738. }
  4739. return collection;
  4740. };
  4741. }
  4742. /**
  4743. * Creates a base function for `_.forIn` or `_.forInRight`.
  4744. *
  4745. * @private
  4746. * @param {boolean} [fromRight] Specify iterating from right to left.
  4747. * @returns {Function} Returns the new base function.
  4748. */
  4749. function createBaseFor(fromRight) {
  4750. return function(object, iteratee, keysFunc) {
  4751. var iterable = toObject(object),
  4752. props = keysFunc(object),
  4753. length = props.length,
  4754. index = fromRight ? length : -1;
  4755. while ((fromRight ? index-- : ++index < length)) {
  4756. var key = props[index];
  4757. if (iteratee(iterable[key], key, iterable) === false) {
  4758. break;
  4759. }
  4760. }
  4761. return object;
  4762. };
  4763. }
  4764. /**
  4765. * Creates a function that wraps `func` and invokes it with the `this`
  4766. * binding of `thisArg`.
  4767. *
  4768. * @private
  4769. * @param {Function} func The function to bind.
  4770. * @param {*} [thisArg] The `this` binding of `func`.
  4771. * @returns {Function} Returns the new bound function.
  4772. */
  4773. function createBindWrapper(func, thisArg) {
  4774. var Ctor = createCtorWrapper(func);
  4775. function wrapper() {
  4776. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4777. return fn.apply(thisArg, arguments);
  4778. }
  4779. return wrapper;
  4780. }
  4781. /**
  4782. * Creates a `Set` cache object to optimize linear searches of large arrays.
  4783. *
  4784. * @private
  4785. * @param {Array} [values] The values to cache.
  4786. * @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
  4787. */
  4788. function createCache(values) {
  4789. return (nativeCreate && Set) ? new SetCache(values) : null;
  4790. }
  4791. /**
  4792. * Creates a function that produces compound words out of the words in a
  4793. * given string.
  4794. *
  4795. * @private
  4796. * @param {Function} callback The function to combine each word.
  4797. * @returns {Function} Returns the new compounder function.
  4798. */
  4799. function createCompounder(callback) {
  4800. return function(string) {
  4801. var index = -1,
  4802. array = words(deburr(string)),
  4803. length = array.length,
  4804. result = '';
  4805. while (++index < length) {
  4806. result = callback(result, array[index], index);
  4807. }
  4808. return result;
  4809. };
  4810. }
  4811. /**
  4812. * Creates a function that produces an instance of `Ctor` regardless of
  4813. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4814. *
  4815. * @private
  4816. * @param {Function} Ctor The constructor to wrap.
  4817. * @returns {Function} Returns the new wrapped function.
  4818. */
  4819. function createCtorWrapper(Ctor) {
  4820. return function() {
  4821. // Use a `switch` statement to work with class constructors.
  4822. // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4823. // for more details.
  4824. var args = arguments;
  4825. switch (args.length) {
  4826. case 0: return new Ctor;
  4827. case 1: return new Ctor(args[0]);
  4828. case 2: return new Ctor(args[0], args[1]);
  4829. case 3: return new Ctor(args[0], args[1], args[2]);
  4830. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4831. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4832. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4833. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4834. }
  4835. var thisBinding = baseCreate(Ctor.prototype),
  4836. result = Ctor.apply(thisBinding, args);
  4837. // Mimic the constructor's `return` behavior.
  4838. // See https://es5.github.io/#x13.2.2 for more details.
  4839. return isObject(result) ? result : thisBinding;
  4840. };
  4841. }
  4842. /**
  4843. * Creates a `_.curry` or `_.curryRight` function.
  4844. *
  4845. * @private
  4846. * @param {boolean} flag The curry bit flag.
  4847. * @returns {Function} Returns the new curry function.
  4848. */
  4849. function createCurry(flag) {
  4850. function curryFunc(func, arity, guard) {
  4851. if (guard && isIterateeCall(func, arity, guard)) {
  4852. arity = undefined;
  4853. }
  4854. var result = createWrapper(func, flag, undefined, undefined, undefined, undefined, undefined, arity);
  4855. result.placeholder = curryFunc.placeholder;
  4856. return result;
  4857. }
  4858. return curryFunc;
  4859. }
  4860. /**
  4861. * Creates a `_.defaults` or `_.defaultsDeep` function.
  4862. *
  4863. * @private
  4864. * @param {Function} assigner The function to assign values.
  4865. * @param {Function} customizer The function to customize assigned values.
  4866. * @returns {Function} Returns the new defaults function.
  4867. */
  4868. function createDefaults(assigner, customizer) {
  4869. return restParam(function(args) {
  4870. var object = args[0];
  4871. if (object == null) {
  4872. return object;
  4873. }
  4874. args.push(customizer);
  4875. return assigner.apply(undefined, args);
  4876. });
  4877. }
  4878. /**
  4879. * Creates a `_.max` or `_.min` function.
  4880. *
  4881. * @private
  4882. * @param {Function} comparator The function used to compare values.
  4883. * @param {*} exValue The initial extremum value.
  4884. * @returns {Function} Returns the new extremum function.
  4885. */
  4886. function createExtremum(comparator, exValue) {
  4887. return function(collection, iteratee, thisArg) {
  4888. if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
  4889. iteratee = undefined;
  4890. }
  4891. iteratee = getCallback(iteratee, thisArg, 3);
  4892. if (iteratee.length == 1) {
  4893. collection = isArray(collection) ? collection : toIterable(collection);
  4894. var result = arrayExtremum(collection, iteratee, comparator, exValue);
  4895. if (!(collection.length && result === exValue)) {
  4896. return result;
  4897. }
  4898. }
  4899. return baseExtremum(collection, iteratee, comparator, exValue);
  4900. };
  4901. }
  4902. /**
  4903. * Creates a `_.find` or `_.findLast` function.
  4904. *
  4905. * @private
  4906. * @param {Function} eachFunc The function to iterate over a collection.
  4907. * @param {boolean} [fromRight] Specify iterating from right to left.
  4908. * @returns {Function} Returns the new find function.
  4909. */
  4910. function createFind(eachFunc, fromRight) {
  4911. return function(collection, predicate, thisArg) {
  4912. predicate = getCallback(predicate, thisArg, 3);
  4913. if (isArray(collection)) {
  4914. var index = baseFindIndex(collection, predicate, fromRight);
  4915. return index > -1 ? collection[index] : undefined;
  4916. }
  4917. return baseFind(collection, predicate, eachFunc);
  4918. };
  4919. }
  4920. /**
  4921. * Creates a `_.findIndex` or `_.findLastIndex` function.
  4922. *
  4923. * @private
  4924. * @param {boolean} [fromRight] Specify iterating from right to left.
  4925. * @returns {Function} Returns the new find function.
  4926. */
  4927. function createFindIndex(fromRight) {
  4928. return function(array, predicate, thisArg) {
  4929. if (!(array && array.length)) {
  4930. return -1;
  4931. }
  4932. predicate = getCallback(predicate, thisArg, 3);
  4933. return baseFindIndex(array, predicate, fromRight);
  4934. };
  4935. }
  4936. /**
  4937. * Creates a `_.findKey` or `_.findLastKey` function.
  4938. *
  4939. * @private
  4940. * @param {Function} objectFunc The function to iterate over an object.
  4941. * @returns {Function} Returns the new find function.
  4942. */
  4943. function createFindKey(objectFunc) {
  4944. return function(object, predicate, thisArg) {
  4945. predicate = getCallback(predicate, thisArg, 3);
  4946. return baseFind(object, predicate, objectFunc, true);
  4947. };
  4948. }
  4949. /**
  4950. * Creates a `_.flow` or `_.flowRight` function.
  4951. *
  4952. * @private
  4953. * @param {boolean} [fromRight] Specify iterating from right to left.
  4954. * @returns {Function} Returns the new flow function.
  4955. */
  4956. function createFlow(fromRight) {
  4957. return function() {
  4958. var wrapper,
  4959. length = arguments.length,
  4960. index = fromRight ? length : -1,
  4961. leftIndex = 0,
  4962. funcs = Array(length);
  4963. while ((fromRight ? index-- : ++index < length)) {
  4964. var func = funcs[leftIndex++] = arguments[index];
  4965. if (typeof func != 'function') {
  4966. throw new TypeError(FUNC_ERROR_TEXT);
  4967. }
  4968. if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') {
  4969. wrapper = new LodashWrapper([], true);
  4970. }
  4971. }
  4972. index = wrapper ? -1 : length;
  4973. while (++index < length) {
  4974. func = funcs[index];
  4975. var funcName = getFuncName(func),
  4976. data = funcName == 'wrapper' ? getData(func) : undefined;
  4977. if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
  4978. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4979. } else {
  4980. wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func);
  4981. }
  4982. }
  4983. return function() {
  4984. var args = arguments,
  4985. value = args[0];
  4986. if (wrapper && args.length == 1 && isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
  4987. return wrapper.plant(value).value();
  4988. }
  4989. var index = 0,
  4990. result = length ? funcs[index].apply(this, args) : value;
  4991. while (++index < length) {
  4992. result = funcs[index].call(this, result);
  4993. }
  4994. return result;
  4995. };
  4996. };
  4997. }
  4998. /**
  4999. * Creates a function for `_.forEach` or `_.forEachRight`.
  5000. *
  5001. * @private
  5002. * @param {Function} arrayFunc The function to iterate over an array.
  5003. * @param {Function} eachFunc The function to iterate over a collection.
  5004. * @returns {Function} Returns the new each function.
  5005. */
  5006. function createForEach(arrayFunc, eachFunc) {
  5007. return function(collection, iteratee, thisArg) {
  5008. return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
  5009. ? arrayFunc(collection, iteratee)
  5010. : eachFunc(collection, bindCallback(iteratee, thisArg, 3));
  5011. };
  5012. }
  5013. /**
  5014. * Creates a function for `_.forIn` or `_.forInRight`.
  5015. *
  5016. * @private
  5017. * @param {Function} objectFunc The function to iterate over an object.
  5018. * @returns {Function} Returns the new each function.
  5019. */
  5020. function createForIn(objectFunc) {
  5021. return function(object, iteratee, thisArg) {
  5022. if (typeof iteratee != 'function' || thisArg !== undefined) {
  5023. iteratee = bindCallback(iteratee, thisArg, 3);
  5024. }
  5025. return objectFunc(object, iteratee, keysIn);
  5026. };
  5027. }
  5028. /**
  5029. * Creates a function for `_.forOwn` or `_.forOwnRight`.
  5030. *
  5031. * @private
  5032. * @param {Function} objectFunc The function to iterate over an object.
  5033. * @returns {Function} Returns the new each function.
  5034. */
  5035. function createForOwn(objectFunc) {
  5036. return function(object, iteratee, thisArg) {
  5037. if (typeof iteratee != 'function' || thisArg !== undefined) {
  5038. iteratee = bindCallback(iteratee, thisArg, 3);
  5039. }
  5040. return objectFunc(object, iteratee);
  5041. };
  5042. }
  5043. /**
  5044. * Creates a function for `_.mapKeys` or `_.mapValues`.
  5045. *
  5046. * @private
  5047. * @param {boolean} [isMapKeys] Specify mapping keys instead of values.
  5048. * @returns {Function} Returns the new map function.
  5049. */
  5050. function createObjectMapper(isMapKeys) {
  5051. return function(object, iteratee, thisArg) {
  5052. var result = {};
  5053. iteratee = getCallback(iteratee, thisArg, 3);
  5054. baseForOwn(object, function(value, key, object) {
  5055. var mapped = iteratee(value, key, object);
  5056. key = isMapKeys ? mapped : key;
  5057. value = isMapKeys ? value : mapped;
  5058. result[key] = value;
  5059. });
  5060. return result;
  5061. };
  5062. }
  5063. /**
  5064. * Creates a function for `_.padLeft` or `_.padRight`.
  5065. *
  5066. * @private
  5067. * @param {boolean} [fromRight] Specify padding from the right.
  5068. * @returns {Function} Returns the new pad function.
  5069. */
  5070. function createPadDir(fromRight) {
  5071. return function(string, length, chars) {
  5072. string = baseToString(string);
  5073. return (fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string);
  5074. };
  5075. }
  5076. /**
  5077. * Creates a `_.partial` or `_.partialRight` function.
  5078. *
  5079. * @private
  5080. * @param {boolean} flag The partial bit flag.
  5081. * @returns {Function} Returns the new partial function.
  5082. */
  5083. function createPartial(flag) {
  5084. var partialFunc = restParam(function(func, partials) {
  5085. var holders = replaceHolders(partials, partialFunc.placeholder);
  5086. return createWrapper(func, flag, undefined, partials, holders);
  5087. });
  5088. return partialFunc;
  5089. }
  5090. /**
  5091. * Creates a function for `_.reduce` or `_.reduceRight`.
  5092. *
  5093. * @private
  5094. * @param {Function} arrayFunc The function to iterate over an array.
  5095. * @param {Function} eachFunc The function to iterate over a collection.
  5096. * @returns {Function} Returns the new each function.
  5097. */
  5098. function createReduce(arrayFunc, eachFunc) {
  5099. return function(collection, iteratee, accumulator, thisArg) {
  5100. var initFromArray = arguments.length < 3;
  5101. return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
  5102. ? arrayFunc(collection, iteratee, accumulator, initFromArray)
  5103. : baseReduce(collection, getCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
  5104. };
  5105. }
  5106. /**
  5107. * Creates a function that wraps `func` and invokes it with optional `this`
  5108. * binding of, partial application, and currying.
  5109. *
  5110. * @private
  5111. * @param {Function|string} func The function or method name to reference.
  5112. * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
  5113. * @param {*} [thisArg] The `this` binding of `func`.
  5114. * @param {Array} [partials] The arguments to prepend to those provided to the new function.
  5115. * @param {Array} [holders] The `partials` placeholder indexes.
  5116. * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
  5117. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  5118. * @param {Array} [argPos] The argument positions of the new function.
  5119. * @param {number} [ary] The arity cap of `func`.
  5120. * @param {number} [arity] The arity of `func`.
  5121. * @returns {Function} Returns the new wrapped function.
  5122. */
  5123. function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  5124. var isAry = bitmask & ARY_FLAG,
  5125. isBind = bitmask & BIND_FLAG,
  5126. isBindKey = bitmask & BIND_KEY_FLAG,
  5127. isCurry = bitmask & CURRY_FLAG,
  5128. isCurryBound = bitmask & CURRY_BOUND_FLAG,
  5129. isCurryRight = bitmask & CURRY_RIGHT_FLAG,
  5130. Ctor = isBindKey ? undefined : createCtorWrapper(func);
  5131. function wrapper() {
  5132. // Avoid `arguments` object use disqualifying optimizations by
  5133. // converting it to an array before providing it to other functions.
  5134. var length = arguments.length,
  5135. index = length,
  5136. args = Array(length);
  5137. while (index--) {
  5138. args[index] = arguments[index];
  5139. }
  5140. if (partials) {
  5141. args = composeArgs(args, partials, holders);
  5142. }
  5143. if (partialsRight) {
  5144. args = composeArgsRight(args, partialsRight, holdersRight);
  5145. }
  5146. if (isCurry || isCurryRight) {
  5147. var placeholder = wrapper.placeholder,
  5148. argsHolders = replaceHolders(args, placeholder);
  5149. length -= argsHolders.length;
  5150. if (length < arity) {
  5151. var newArgPos = argPos ? arrayCopy(argPos) : undefined,
  5152. newArity = nativeMax(arity - length, 0),
  5153. newsHolders = isCurry ? argsHolders : undefined,
  5154. newHoldersRight = isCurry ? undefined : argsHolders,
  5155. newPartials = isCurry ? args : undefined,
  5156. newPartialsRight = isCurry ? undefined : args;
  5157. bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
  5158. bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
  5159. if (!isCurryBound) {
  5160. bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
  5161. }
  5162. var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity],
  5163. result = createHybridWrapper.apply(undefined, newData);
  5164. if (isLaziable(func)) {
  5165. setData(result, newData);
  5166. }
  5167. result.placeholder = placeholder;
  5168. return result;
  5169. }
  5170. }
  5171. var thisBinding = isBind ? thisArg : this,
  5172. fn = isBindKey ? thisBinding[func] : func;
  5173. if (argPos) {
  5174. args = reorder(args, argPos);
  5175. }
  5176. if (isAry && ary < args.length) {
  5177. args.length = ary;
  5178. }
  5179. if (this && this !== root && this instanceof wrapper) {
  5180. fn = Ctor || createCtorWrapper(func);
  5181. }
  5182. return fn.apply(thisBinding, args);
  5183. }
  5184. return wrapper;
  5185. }
  5186. /**
  5187. * Creates the padding required for `string` based on the given `length`.
  5188. * The `chars` string is truncated if the number of characters exceeds `length`.
  5189. *
  5190. * @private
  5191. * @param {string} string The string to create padding for.
  5192. * @param {number} [length=0] The padding length.
  5193. * @param {string} [chars=' '] The string used as padding.
  5194. * @returns {string} Returns the pad for `string`.
  5195. */
  5196. function createPadding(string, length, chars) {
  5197. var strLength = string.length;
  5198. length = +length;
  5199. if (strLength >= length || !nativeIsFinite(length)) {
  5200. return '';
  5201. }
  5202. var padLength = length - strLength;
  5203. chars = chars == null ? ' ' : (chars + '');
  5204. return repeat(chars, nativeCeil(padLength / chars.length)).slice(0, padLength);
  5205. }
  5206. /**
  5207. * Creates a function that wraps `func` and invokes it with the optional `this`
  5208. * binding of `thisArg` and the `partials` prepended to those provided to
  5209. * the wrapper.
  5210. *
  5211. * @private
  5212. * @param {Function} func The function to partially apply arguments to.
  5213. * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
  5214. * @param {*} thisArg The `this` binding of `func`.
  5215. * @param {Array} partials The arguments to prepend to those provided to the new function.
  5216. * @returns {Function} Returns the new bound function.
  5217. */
  5218. function createPartialWrapper(func, bitmask, thisArg, partials) {
  5219. var isBind = bitmask & BIND_FLAG,
  5220. Ctor = createCtorWrapper(func);
  5221. function wrapper() {
  5222. // Avoid `arguments` object use disqualifying optimizations by
  5223. // converting it to an array before providing it `func`.
  5224. var argsIndex = -1,
  5225. argsLength = arguments.length,
  5226. leftIndex = -1,
  5227. leftLength = partials.length,
  5228. args = Array(leftLength + argsLength);
  5229. while (++leftIndex < leftLength) {
  5230. args[leftIndex] = partials[leftIndex];
  5231. }
  5232. while (argsLength--) {
  5233. args[leftIndex++] = arguments[++argsIndex];
  5234. }
  5235. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  5236. return fn.apply(isBind ? thisArg : this, args);
  5237. }
  5238. return wrapper;
  5239. }
  5240. /**
  5241. * Creates a `_.ceil`, `_.floor`, or `_.round` function.
  5242. *
  5243. * @private
  5244. * @param {string} methodName The name of the `Math` method to use when rounding.
  5245. * @returns {Function} Returns the new round function.
  5246. */
  5247. function createRound(methodName) {
  5248. var func = Math[methodName];
  5249. return function(number, precision) {
  5250. precision = precision === undefined ? 0 : (+precision || 0);
  5251. if (precision) {
  5252. precision = pow(10, precision);
  5253. return func(number * precision) / precision;
  5254. }
  5255. return func(number);
  5256. };
  5257. }
  5258. /**
  5259. * Creates a `_.sortedIndex` or `_.sortedLastIndex` function.
  5260. *
  5261. * @private
  5262. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  5263. * @returns {Function} Returns the new index function.
  5264. */
  5265. function createSortedIndex(retHighest) {
  5266. return function(array, value, iteratee, thisArg) {
  5267. var callback = getCallback(iteratee);
  5268. return (iteratee == null && callback === baseCallback)
  5269. ? binaryIndex(array, value, retHighest)
  5270. : binaryIndexBy(array, value, callback(iteratee, thisArg, 1), retHighest);
  5271. };
  5272. }
  5273. /**
  5274. * Creates a function that either curries or invokes `func` with optional
  5275. * `this` binding and partially applied arguments.
  5276. *
  5277. * @private
  5278. * @param {Function|string} func The function or method name to reference.
  5279. * @param {number} bitmask The bitmask of flags.
  5280. * The bitmask may be composed of the following flags:
  5281. * 1 - `_.bind`
  5282. * 2 - `_.bindKey`
  5283. * 4 - `_.curry` or `_.curryRight` of a bound function
  5284. * 8 - `_.curry`
  5285. * 16 - `_.curryRight`
  5286. * 32 - `_.partial`
  5287. * 64 - `_.partialRight`
  5288. * 128 - `_.rearg`
  5289. * 256 - `_.ary`
  5290. * @param {*} [thisArg] The `this` binding of `func`.
  5291. * @param {Array} [partials] The arguments to be partially applied.
  5292. * @param {Array} [holders] The `partials` placeholder indexes.
  5293. * @param {Array} [argPos] The argument positions of the new function.
  5294. * @param {number} [ary] The arity cap of `func`.
  5295. * @param {number} [arity] The arity of `func`.
  5296. * @returns {Function} Returns the new wrapped function.
  5297. */
  5298. function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  5299. var isBindKey = bitmask & BIND_KEY_FLAG;
  5300. if (!isBindKey && typeof func != 'function') {
  5301. throw new TypeError(FUNC_ERROR_TEXT);
  5302. }
  5303. var length = partials ? partials.length : 0;
  5304. if (!length) {
  5305. bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
  5306. partials = holders = undefined;
  5307. }
  5308. length -= (holders ? holders.length : 0);
  5309. if (bitmask & PARTIAL_RIGHT_FLAG) {
  5310. var partialsRight = partials,
  5311. holdersRight = holders;
  5312. partials = holders = undefined;
  5313. }
  5314. var data = isBindKey ? undefined : getData(func),
  5315. newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
  5316. if (data) {
  5317. mergeData(newData, data);
  5318. bitmask = newData[1];
  5319. arity = newData[9];
  5320. }
  5321. newData[9] = arity == null
  5322. ? (isBindKey ? 0 : func.length)
  5323. : (nativeMax(arity - length, 0) || 0);
  5324. if (bitmask == BIND_FLAG) {
  5325. var result = createBindWrapper(newData[0], newData[2]);
  5326. } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
  5327. result = createPartialWrapper.apply(undefined, newData);
  5328. } else {
  5329. result = createHybridWrapper.apply(undefined, newData);
  5330. }
  5331. var setter = data ? baseSetData : setData;
  5332. return setter(result, newData);
  5333. }
  5334. /**
  5335. * A specialized version of `baseIsEqualDeep` for arrays with support for
  5336. * partial deep comparisons.
  5337. *
  5338. * @private
  5339. * @param {Array} array The array to compare.
  5340. * @param {Array} other The other array to compare.
  5341. * @param {Function} equalFunc The function to determine equivalents of values.
  5342. * @param {Function} [customizer] The function to customize comparing arrays.
  5343. * @param {boolean} [isLoose] Specify performing partial comparisons.
  5344. * @param {Array} [stackA] Tracks traversed `value` objects.
  5345. * @param {Array} [stackB] Tracks traversed `other` objects.
  5346. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  5347. */
  5348. function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
  5349. var index = -1,
  5350. arrLength = array.length,
  5351. othLength = other.length;
  5352. if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
  5353. return false;
  5354. }
  5355. // Ignore non-index properties.
  5356. while (++index < arrLength) {
  5357. var arrValue = array[index],
  5358. othValue = other[index],
  5359. result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined;
  5360. if (result !== undefined) {
  5361. if (result) {
  5362. continue;
  5363. }
  5364. return false;
  5365. }
  5366. // Recursively compare arrays (susceptible to call stack limits).
  5367. if (isLoose) {
  5368. if (!arraySome(other, function(othValue) {
  5369. return arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
  5370. })) {
  5371. return false;
  5372. }
  5373. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB))) {
  5374. return false;
  5375. }
  5376. }
  5377. return true;
  5378. }
  5379. /**
  5380. * A specialized version of `baseIsEqualDeep` for comparing objects of
  5381. * the same `toStringTag`.
  5382. *
  5383. * **Note:** This function only supports comparing values with tags of
  5384. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5385. *
  5386. * @private
  5387. * @param {Object} object The object to compare.
  5388. * @param {Object} other The other object to compare.
  5389. * @param {string} tag The `toStringTag` of the objects to compare.
  5390. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5391. */
  5392. function equalByTag(object, other, tag) {
  5393. switch (tag) {
  5394. case boolTag:
  5395. case dateTag:
  5396. // Coerce dates and booleans to numbers, dates to milliseconds and booleans
  5397. // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
  5398. return +object == +other;
  5399. case errorTag:
  5400. return object.name == other.name && object.message == other.message;
  5401. case numberTag:
  5402. // Treat `NaN` vs. `NaN` as equal.
  5403. return (object != +object)
  5404. ? other != +other
  5405. : object == +other;
  5406. case regexpTag:
  5407. case stringTag:
  5408. // Coerce regexes to strings and treat strings primitives and string
  5409. // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
  5410. return object == (other + '');
  5411. }
  5412. return false;
  5413. }
  5414. /**
  5415. * A specialized version of `baseIsEqualDeep` for objects with support for
  5416. * partial deep comparisons.
  5417. *
  5418. * @private
  5419. * @param {Object} object The object to compare.
  5420. * @param {Object} other The other object to compare.
  5421. * @param {Function} equalFunc The function to determine equivalents of values.
  5422. * @param {Function} [customizer] The function to customize comparing values.
  5423. * @param {boolean} [isLoose] Specify performing partial comparisons.
  5424. * @param {Array} [stackA] Tracks traversed `value` objects.
  5425. * @param {Array} [stackB] Tracks traversed `other` objects.
  5426. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5427. */
  5428. function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
  5429. var objProps = keys(object),
  5430. objLength = objProps.length,
  5431. othProps = keys(other),
  5432. othLength = othProps.length;
  5433. if (objLength != othLength && !isLoose) {
  5434. return false;
  5435. }
  5436. var index = objLength;
  5437. while (index--) {
  5438. var key = objProps[index];
  5439. if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) {
  5440. return false;
  5441. }
  5442. }
  5443. var skipCtor = isLoose;
  5444. while (++index < objLength) {
  5445. key = objProps[index];
  5446. var objValue = object[key],
  5447. othValue = other[key],
  5448. result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined;
  5449. // Recursively compare objects (susceptible to call stack limits).
  5450. if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) {
  5451. return false;
  5452. }
  5453. skipCtor || (skipCtor = key == 'constructor');
  5454. }
  5455. if (!skipCtor) {
  5456. var objCtor = object.constructor,
  5457. othCtor = other.constructor;
  5458. // Non `Object` object instances with different constructors are not equal.
  5459. if (objCtor != othCtor &&
  5460. ('constructor' in object && 'constructor' in other) &&
  5461. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5462. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5463. return false;
  5464. }
  5465. }
  5466. return true;
  5467. }
  5468. /**
  5469. * Gets the appropriate "callback" function. If the `_.callback` method is
  5470. * customized this function returns the custom method, otherwise it returns
  5471. * the `baseCallback` function. If arguments are provided the chosen function
  5472. * is invoked with them and its result is returned.
  5473. *
  5474. * @private
  5475. * @returns {Function} Returns the chosen function or its result.
  5476. */
  5477. function getCallback(func, thisArg, argCount) {
  5478. var result = lodash.callback || callback;
  5479. result = result === callback ? baseCallback : result;
  5480. return argCount ? result(func, thisArg, argCount) : result;
  5481. }
  5482. /**
  5483. * Gets metadata for `func`.
  5484. *
  5485. * @private
  5486. * @param {Function} func The function to query.
  5487. * @returns {*} Returns the metadata for `func`.
  5488. */
  5489. var getData = !metaMap ? noop : function(func) {
  5490. return metaMap.get(func);
  5491. };
  5492. /**
  5493. * Gets the name of `func`.
  5494. *
  5495. * @private
  5496. * @param {Function} func The function to query.
  5497. * @returns {string} Returns the function name.
  5498. */
  5499. function getFuncName(func) {
  5500. var result = func.name,
  5501. array = realNames[result],
  5502. length = array ? array.length : 0;
  5503. while (length--) {
  5504. var data = array[length],
  5505. otherFunc = data.func;
  5506. if (otherFunc == null || otherFunc == func) {
  5507. return data.name;
  5508. }
  5509. }
  5510. return result;
  5511. }
  5512. /**
  5513. * Gets the appropriate "indexOf" function. If the `_.indexOf` method is
  5514. * customized this function returns the custom method, otherwise it returns
  5515. * the `baseIndexOf` function. If arguments are provided the chosen function
  5516. * is invoked with them and its result is returned.
  5517. *
  5518. * @private
  5519. * @returns {Function|number} Returns the chosen function or its result.
  5520. */
  5521. function getIndexOf(collection, target, fromIndex) {
  5522. var result = lodash.indexOf || indexOf;
  5523. result = result === indexOf ? baseIndexOf : result;
  5524. return collection ? result(collection, target, fromIndex) : result;
  5525. }
  5526. /**
  5527. * Gets the "length" property value of `object`.
  5528. *
  5529. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  5530. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  5531. *
  5532. * @private
  5533. * @param {Object} object The object to query.
  5534. * @returns {*} Returns the "length" value.
  5535. */
  5536. var getLength = baseProperty('length');
  5537. /**
  5538. * Gets the propery names, values, and compare flags of `object`.
  5539. *
  5540. * @private
  5541. * @param {Object} object The object to query.
  5542. * @returns {Array} Returns the match data of `object`.
  5543. */
  5544. function getMatchData(object) {
  5545. var result = pairs(object),
  5546. length = result.length;
  5547. while (length--) {
  5548. result[length][2] = isStrictComparable(result[length][1]);
  5549. }
  5550. return result;
  5551. }
  5552. /**
  5553. * Gets the native function at `key` of `object`.
  5554. *
  5555. * @private
  5556. * @param {Object} object The object to query.
  5557. * @param {string} key The key of the method to get.
  5558. * @returns {*} Returns the function if it's native, else `undefined`.
  5559. */
  5560. function getNative(object, key) {
  5561. var value = object == null ? undefined : object[key];
  5562. return isNative(value) ? value : undefined;
  5563. }
  5564. /**
  5565. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5566. *
  5567. * @private
  5568. * @param {number} start The start of the view.
  5569. * @param {number} end The end of the view.
  5570. * @param {Array} transforms The transformations to apply to the view.
  5571. * @returns {Object} Returns an object containing the `start` and `end`
  5572. * positions of the view.
  5573. */
  5574. function getView(start, end, transforms) {
  5575. var index = -1,
  5576. length = transforms.length;
  5577. while (++index < length) {
  5578. var data = transforms[index],
  5579. size = data.size;
  5580. switch (data.type) {
  5581. case 'drop': start += size; break;
  5582. case 'dropRight': end -= size; break;
  5583. case 'take': end = nativeMin(end, start + size); break;
  5584. case 'takeRight': start = nativeMax(start, end - size); break;
  5585. }
  5586. }
  5587. return { 'start': start, 'end': end };
  5588. }
  5589. /**
  5590. * Initializes an array clone.
  5591. *
  5592. * @private
  5593. * @param {Array} array The array to clone.
  5594. * @returns {Array} Returns the initialized clone.
  5595. */
  5596. function initCloneArray(array) {
  5597. var length = array.length,
  5598. result = new array.constructor(length);
  5599. // Add array properties assigned by `RegExp#exec`.
  5600. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5601. result.index = array.index;
  5602. result.input = array.input;
  5603. }
  5604. return result;
  5605. }
  5606. /**
  5607. * Initializes an object clone.
  5608. *
  5609. * @private
  5610. * @param {Object} object The object to clone.
  5611. * @returns {Object} Returns the initialized clone.
  5612. */
  5613. function initCloneObject(object) {
  5614. var Ctor = object.constructor;
  5615. if (!(typeof Ctor == 'function' && Ctor instanceof Ctor)) {
  5616. Ctor = Object;
  5617. }
  5618. return new Ctor;
  5619. }
  5620. /**
  5621. * Initializes an object clone based on its `toStringTag`.
  5622. *
  5623. * **Note:** This function only supports cloning values with tags of
  5624. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5625. *
  5626. * @private
  5627. * @param {Object} object The object to clone.
  5628. * @param {string} tag The `toStringTag` of the object to clone.
  5629. * @param {boolean} [isDeep] Specify a deep clone.
  5630. * @returns {Object} Returns the initialized clone.
  5631. */
  5632. function initCloneByTag(object, tag, isDeep) {
  5633. var Ctor = object.constructor;
  5634. switch (tag) {
  5635. case arrayBufferTag:
  5636. return bufferClone(object);
  5637. case boolTag:
  5638. case dateTag:
  5639. return new Ctor(+object);
  5640. case float32Tag: case float64Tag:
  5641. case int8Tag: case int16Tag: case int32Tag:
  5642. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5643. var buffer = object.buffer;
  5644. return new Ctor(isDeep ? bufferClone(buffer) : buffer, object.byteOffset, object.length);
  5645. case numberTag:
  5646. case stringTag:
  5647. return new Ctor(object);
  5648. case regexpTag:
  5649. var result = new Ctor(object.source, reFlags.exec(object));
  5650. result.lastIndex = object.lastIndex;
  5651. }
  5652. return result;
  5653. }
  5654. /**
  5655. * Invokes the method at `path` on `object`.
  5656. *
  5657. * @private
  5658. * @param {Object} object The object to query.
  5659. * @param {Array|string} path The path of the method to invoke.
  5660. * @param {Array} args The arguments to invoke the method with.
  5661. * @returns {*} Returns the result of the invoked method.
  5662. */
  5663. function invokePath(object, path, args) {
  5664. if (object != null && !isKey(path, object)) {
  5665. path = toPath(path);
  5666. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  5667. path = last(path);
  5668. }
  5669. var func = object == null ? object : object[path];
  5670. return func == null ? undefined : func.apply(object, args);
  5671. }
  5672. /**
  5673. * Checks if `value` is array-like.
  5674. *
  5675. * @private
  5676. * @param {*} value The value to check.
  5677. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  5678. */
  5679. function isArrayLike(value) {
  5680. return value != null && isLength(getLength(value));
  5681. }
  5682. /**
  5683. * Checks if `value` is a valid array-like index.
  5684. *
  5685. * @private
  5686. * @param {*} value The value to check.
  5687. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5688. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5689. */
  5690. function isIndex(value, length) {
  5691. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  5692. length = length == null ? MAX_SAFE_INTEGER : length;
  5693. return value > -1 && value % 1 == 0 && value < length;
  5694. }
  5695. /**
  5696. * Checks if the provided arguments are from an iteratee call.
  5697. *
  5698. * @private
  5699. * @param {*} value The potential iteratee value argument.
  5700. * @param {*} index The potential iteratee index or key argument.
  5701. * @param {*} object The potential iteratee object argument.
  5702. * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
  5703. */
  5704. function isIterateeCall(value, index, object) {
  5705. if (!isObject(object)) {
  5706. return false;
  5707. }
  5708. var type = typeof index;
  5709. if (type == 'number'
  5710. ? (isArrayLike(object) && isIndex(index, object.length))
  5711. : (type == 'string' && index in object)) {
  5712. var other = object[index];
  5713. return value === value ? (value === other) : (other !== other);
  5714. }
  5715. return false;
  5716. }
  5717. /**
  5718. * Checks if `value` is a property name and not a property path.
  5719. *
  5720. * @private
  5721. * @param {*} value The value to check.
  5722. * @param {Object} [object] The object to query keys on.
  5723. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5724. */
  5725. function isKey(value, object) {
  5726. var type = typeof value;
  5727. if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') {
  5728. return true;
  5729. }
  5730. if (isArray(value)) {
  5731. return false;
  5732. }
  5733. var result = !reIsDeepProp.test(value);
  5734. return result || (object != null && value in toObject(object));
  5735. }
  5736. /**
  5737. * Checks if `func` has a lazy counterpart.
  5738. *
  5739. * @private
  5740. * @param {Function} func The function to check.
  5741. * @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
  5742. */
  5743. function isLaziable(func) {
  5744. var funcName = getFuncName(func);
  5745. if (!(funcName in LazyWrapper.prototype)) {
  5746. return false;
  5747. }
  5748. var other = lodash[funcName];
  5749. if (func === other) {
  5750. return true;
  5751. }
  5752. var data = getData(other);
  5753. return !!data && func === data[0];
  5754. }
  5755. /**
  5756. * Checks if `value` is a valid array-like length.
  5757. *
  5758. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  5759. *
  5760. * @private
  5761. * @param {*} value The value to check.
  5762. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  5763. */
  5764. function isLength(value) {
  5765. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  5766. }
  5767. /**
  5768. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5769. *
  5770. * @private
  5771. * @param {*} value The value to check.
  5772. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5773. * equality comparisons, else `false`.
  5774. */
  5775. function isStrictComparable(value) {
  5776. return value === value && !isObject(value);
  5777. }
  5778. /**
  5779. * Merges the function metadata of `source` into `data`.
  5780. *
  5781. * Merging metadata reduces the number of wrappers required to invoke a function.
  5782. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  5783. * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
  5784. * augment function arguments, making the order in which they are executed important,
  5785. * preventing the merging of metadata. However, we make an exception for a safe
  5786. * common case where curried functions have `_.ary` and or `_.rearg` applied.
  5787. *
  5788. * @private
  5789. * @param {Array} data The destination metadata.
  5790. * @param {Array} source The source metadata.
  5791. * @returns {Array} Returns `data`.
  5792. */
  5793. function mergeData(data, source) {
  5794. var bitmask = data[1],
  5795. srcBitmask = source[1],
  5796. newBitmask = bitmask | srcBitmask,
  5797. isCommon = newBitmask < ARY_FLAG;
  5798. var isCombo =
  5799. (srcBitmask == ARY_FLAG && bitmask == CURRY_FLAG) ||
  5800. (srcBitmask == ARY_FLAG && bitmask == REARG_FLAG && data[7].length <= source[8]) ||
  5801. (srcBitmask == (ARY_FLAG | REARG_FLAG) && bitmask == CURRY_FLAG);
  5802. // Exit early if metadata can't be merged.
  5803. if (!(isCommon || isCombo)) {
  5804. return data;
  5805. }
  5806. // Use source `thisArg` if available.
  5807. if (srcBitmask & BIND_FLAG) {
  5808. data[2] = source[2];
  5809. // Set when currying a bound function.
  5810. newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
  5811. }
  5812. // Compose partial arguments.
  5813. var value = source[3];
  5814. if (value) {
  5815. var partials = data[3];
  5816. data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
  5817. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
  5818. }
  5819. // Compose partial right arguments.
  5820. value = source[5];
  5821. if (value) {
  5822. partials = data[5];
  5823. data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
  5824. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
  5825. }
  5826. // Use source `argPos` if available.
  5827. value = source[7];
  5828. if (value) {
  5829. data[7] = arrayCopy(value);
  5830. }
  5831. // Use source `ary` if it's smaller.
  5832. if (srcBitmask & ARY_FLAG) {
  5833. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  5834. }
  5835. // Use source `arity` if one is not provided.
  5836. if (data[9] == null) {
  5837. data[9] = source[9];
  5838. }
  5839. // Use source `func` and merge bitmasks.
  5840. data[0] = source[0];
  5841. data[1] = newBitmask;
  5842. return data;
  5843. }
  5844. /**
  5845. * Used by `_.defaultsDeep` to customize its `_.merge` use.
  5846. *
  5847. * @private
  5848. * @param {*} objectValue The destination object property value.
  5849. * @param {*} sourceValue The source object property value.
  5850. * @returns {*} Returns the value to assign to the destination object.
  5851. */
  5852. function mergeDefaults(objectValue, sourceValue) {
  5853. return objectValue === undefined ? sourceValue : merge(objectValue, sourceValue, mergeDefaults);
  5854. }
  5855. /**
  5856. * A specialized version of `_.pick` which picks `object` properties specified
  5857. * by `props`.
  5858. *
  5859. * @private
  5860. * @param {Object} object The source object.
  5861. * @param {string[]} props The property names to pick.
  5862. * @returns {Object} Returns the new object.
  5863. */
  5864. function pickByArray(object, props) {
  5865. object = toObject(object);
  5866. var index = -1,
  5867. length = props.length,
  5868. result = {};
  5869. while (++index < length) {
  5870. var key = props[index];
  5871. if (key in object) {
  5872. result[key] = object[key];
  5873. }
  5874. }
  5875. return result;
  5876. }
  5877. /**
  5878. * A specialized version of `_.pick` which picks `object` properties `predicate`
  5879. * returns truthy for.
  5880. *
  5881. * @private
  5882. * @param {Object} object The source object.
  5883. * @param {Function} predicate The function invoked per iteration.
  5884. * @returns {Object} Returns the new object.
  5885. */
  5886. function pickByCallback(object, predicate) {
  5887. var result = {};
  5888. baseForIn(object, function(value, key, object) {
  5889. if (predicate(value, key, object)) {
  5890. result[key] = value;
  5891. }
  5892. });
  5893. return result;
  5894. }
  5895. /**
  5896. * Reorder `array` according to the specified indexes where the element at
  5897. * the first index is assigned as the first element, the element at
  5898. * the second index is assigned as the second element, and so on.
  5899. *
  5900. * @private
  5901. * @param {Array} array The array to reorder.
  5902. * @param {Array} indexes The arranged array indexes.
  5903. * @returns {Array} Returns `array`.
  5904. */
  5905. function reorder(array, indexes) {
  5906. var arrLength = array.length,
  5907. length = nativeMin(indexes.length, arrLength),
  5908. oldArray = arrayCopy(array);
  5909. while (length--) {
  5910. var index = indexes[length];
  5911. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  5912. }
  5913. return array;
  5914. }
  5915. /**
  5916. * Sets metadata for `func`.
  5917. *
  5918. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  5919. * period of time, it will trip its breaker and transition to an identity function
  5920. * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
  5921. * for more details.
  5922. *
  5923. * @private
  5924. * @param {Function} func The function to associate metadata with.
  5925. * @param {*} data The metadata.
  5926. * @returns {Function} Returns `func`.
  5927. */
  5928. var setData = (function() {
  5929. var count = 0,
  5930. lastCalled = 0;
  5931. return function(key, value) {
  5932. var stamp = now(),
  5933. remaining = HOT_SPAN - (stamp - lastCalled);
  5934. lastCalled = stamp;
  5935. if (remaining > 0) {
  5936. if (++count >= HOT_COUNT) {
  5937. return key;
  5938. }
  5939. } else {
  5940. count = 0;
  5941. }
  5942. return baseSetData(key, value);
  5943. };
  5944. }());
  5945. /**
  5946. * A fallback implementation of `Object.keys` which creates an array of the
  5947. * own enumerable property names of `object`.
  5948. *
  5949. * @private
  5950. * @param {Object} object The object to query.
  5951. * @returns {Array} Returns the array of property names.
  5952. */
  5953. function shimKeys(object) {
  5954. var props = keysIn(object),
  5955. propsLength = props.length,
  5956. length = propsLength && object.length;
  5957. var allowIndexes = !!length && isLength(length) &&
  5958. (isArray(object) || isArguments(object));
  5959. var index = -1,
  5960. result = [];
  5961. while (++index < propsLength) {
  5962. var key = props[index];
  5963. if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
  5964. result.push(key);
  5965. }
  5966. }
  5967. return result;
  5968. }
  5969. /**
  5970. * Converts `value` to an array-like object if it's not one.
  5971. *
  5972. * @private
  5973. * @param {*} value The value to process.
  5974. * @returns {Array|Object} Returns the array-like object.
  5975. */
  5976. function toIterable(value) {
  5977. if (value == null) {
  5978. return [];
  5979. }
  5980. if (!isArrayLike(value)) {
  5981. return values(value);
  5982. }
  5983. return isObject(value) ? value : Object(value);
  5984. }
  5985. /**
  5986. * Converts `value` to an object if it's not one.
  5987. *
  5988. * @private
  5989. * @param {*} value The value to process.
  5990. * @returns {Object} Returns the object.
  5991. */
  5992. function toObject(value) {
  5993. return isObject(value) ? value : Object(value);
  5994. }
  5995. /**
  5996. * Converts `value` to property path array if it's not one.
  5997. *
  5998. * @private
  5999. * @param {*} value The value to process.
  6000. * @returns {Array} Returns the property path array.
  6001. */
  6002. function toPath(value) {
  6003. if (isArray(value)) {
  6004. return value;
  6005. }
  6006. var result = [];
  6007. baseToString(value).replace(rePropName, function(match, number, quote, string) {
  6008. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  6009. });
  6010. return result;
  6011. }
  6012. /**
  6013. * Creates a clone of `wrapper`.
  6014. *
  6015. * @private
  6016. * @param {Object} wrapper The wrapper to clone.
  6017. * @returns {Object} Returns the cloned wrapper.
  6018. */
  6019. function wrapperClone(wrapper) {
  6020. return wrapper instanceof LazyWrapper
  6021. ? wrapper.clone()
  6022. : new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
  6023. }
  6024. /*------------------------------------------------------------------------*/
  6025. /**
  6026. * Creates an array of elements split into groups the length of `size`.
  6027. * If `collection` can't be split evenly, the final chunk will be the remaining
  6028. * elements.
  6029. *
  6030. * @static
  6031. * @memberOf _
  6032. * @category Array
  6033. * @param {Array} array The array to process.
  6034. * @param {number} [size=1] The length of each chunk.
  6035. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  6036. * @returns {Array} Returns the new array containing chunks.
  6037. * @example
  6038. *
  6039. * _.chunk(['a', 'b', 'c', 'd'], 2);
  6040. * // => [['a', 'b'], ['c', 'd']]
  6041. *
  6042. * _.chunk(['a', 'b', 'c', 'd'], 3);
  6043. * // => [['a', 'b', 'c'], ['d']]
  6044. */
  6045. function chunk(array, size, guard) {
  6046. if (guard ? isIterateeCall(array, size, guard) : size == null) {
  6047. size = 1;
  6048. } else {
  6049. size = nativeMax(nativeFloor(size) || 1, 1);
  6050. }
  6051. var index = 0,
  6052. length = array ? array.length : 0,
  6053. resIndex = -1,
  6054. result = Array(nativeCeil(length / size));
  6055. while (index < length) {
  6056. result[++resIndex] = baseSlice(array, index, (index += size));
  6057. }
  6058. return result;
  6059. }
  6060. /**
  6061. * Creates an array with all falsey values removed. The values `false`, `null`,
  6062. * `0`, `""`, `undefined`, and `NaN` are falsey.
  6063. *
  6064. * @static
  6065. * @memberOf _
  6066. * @category Array
  6067. * @param {Array} array The array to compact.
  6068. * @returns {Array} Returns the new array of filtered values.
  6069. * @example
  6070. *
  6071. * _.compact([0, 1, false, 2, '', 3]);
  6072. * // => [1, 2, 3]
  6073. */
  6074. function compact(array) {
  6075. var index = -1,
  6076. length = array ? array.length : 0,
  6077. resIndex = -1,
  6078. result = [];
  6079. while (++index < length) {
  6080. var value = array[index];
  6081. if (value) {
  6082. result[++resIndex] = value;
  6083. }
  6084. }
  6085. return result;
  6086. }
  6087. /**
  6088. * Creates an array of unique `array` values not included in the other
  6089. * provided arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  6090. * for equality comparisons.
  6091. *
  6092. * @static
  6093. * @memberOf _
  6094. * @category Array
  6095. * @param {Array} array The array to inspect.
  6096. * @param {...Array} [values] The arrays of values to exclude.
  6097. * @returns {Array} Returns the new array of filtered values.
  6098. * @example
  6099. *
  6100. * _.difference([1, 2, 3], [4, 2]);
  6101. * // => [1, 3]
  6102. */
  6103. var difference = restParam(function(array, values) {
  6104. return (isObjectLike(array) && isArrayLike(array))
  6105. ? baseDifference(array, baseFlatten(values, false, true))
  6106. : [];
  6107. });
  6108. /**
  6109. * Creates a slice of `array` with `n` elements dropped from the beginning.
  6110. *
  6111. * @static
  6112. * @memberOf _
  6113. * @category Array
  6114. * @param {Array} array The array to query.
  6115. * @param {number} [n=1] The number of elements to drop.
  6116. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  6117. * @returns {Array} Returns the slice of `array`.
  6118. * @example
  6119. *
  6120. * _.drop([1, 2, 3]);
  6121. * // => [2, 3]
  6122. *
  6123. * _.drop([1, 2, 3], 2);
  6124. * // => [3]
  6125. *
  6126. * _.drop([1, 2, 3], 5);
  6127. * // => []
  6128. *
  6129. * _.drop([1, 2, 3], 0);
  6130. * // => [1, 2, 3]
  6131. */
  6132. function drop(array, n, guard) {
  6133. var length = array ? array.length : 0;
  6134. if (!length) {
  6135. return [];
  6136. }
  6137. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  6138. n = 1;
  6139. }
  6140. return baseSlice(array, n < 0 ? 0 : n);
  6141. }
  6142. /**
  6143. * Creates a slice of `array` with `n` elements dropped from the end.
  6144. *
  6145. * @static
  6146. * @memberOf _
  6147. * @category Array
  6148. * @param {Array} array The array to query.
  6149. * @param {number} [n=1] The number of elements to drop.
  6150. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  6151. * @returns {Array} Returns the slice of `array`.
  6152. * @example
  6153. *
  6154. * _.dropRight([1, 2, 3]);
  6155. * // => [1, 2]
  6156. *
  6157. * _.dropRight([1, 2, 3], 2);
  6158. * // => [1]
  6159. *
  6160. * _.dropRight([1, 2, 3], 5);
  6161. * // => []
  6162. *
  6163. * _.dropRight([1, 2, 3], 0);
  6164. * // => [1, 2, 3]
  6165. */
  6166. function dropRight(array, n, guard) {
  6167. var length = array ? array.length : 0;
  6168. if (!length) {
  6169. return [];
  6170. }
  6171. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  6172. n = 1;
  6173. }
  6174. n = length - (+n || 0);
  6175. return baseSlice(array, 0, n < 0 ? 0 : n);
  6176. }
  6177. /**
  6178. * Creates a slice of `array` excluding elements dropped from the end.
  6179. * Elements are dropped until `predicate` returns falsey. The predicate is
  6180. * bound to `thisArg` and invoked with three arguments: (value, index, array).
  6181. *
  6182. * If a property name is provided for `predicate` the created `_.property`
  6183. * style callback returns the property value of the given element.
  6184. *
  6185. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6186. * style callback returns `true` for elements that have a matching property
  6187. * value, else `false`.
  6188. *
  6189. * If an object is provided for `predicate` the created `_.matches` style
  6190. * callback returns `true` for elements that match the properties of the given
  6191. * object, else `false`.
  6192. *
  6193. * @static
  6194. * @memberOf _
  6195. * @category Array
  6196. * @param {Array} array The array to query.
  6197. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6198. * per iteration.
  6199. * @param {*} [thisArg] The `this` binding of `predicate`.
  6200. * @returns {Array} Returns the slice of `array`.
  6201. * @example
  6202. *
  6203. * _.dropRightWhile([1, 2, 3], function(n) {
  6204. * return n > 1;
  6205. * });
  6206. * // => [1]
  6207. *
  6208. * var users = [
  6209. * { 'user': 'barney', 'active': true },
  6210. * { 'user': 'fred', 'active': false },
  6211. * { 'user': 'pebbles', 'active': false }
  6212. * ];
  6213. *
  6214. * // using the `_.matches` callback shorthand
  6215. * _.pluck(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
  6216. * // => ['barney', 'fred']
  6217. *
  6218. * // using the `_.matchesProperty` callback shorthand
  6219. * _.pluck(_.dropRightWhile(users, 'active', false), 'user');
  6220. * // => ['barney']
  6221. *
  6222. * // using the `_.property` callback shorthand
  6223. * _.pluck(_.dropRightWhile(users, 'active'), 'user');
  6224. * // => ['barney', 'fred', 'pebbles']
  6225. */
  6226. function dropRightWhile(array, predicate, thisArg) {
  6227. return (array && array.length)
  6228. ? baseWhile(array, getCallback(predicate, thisArg, 3), true, true)
  6229. : [];
  6230. }
  6231. /**
  6232. * Creates a slice of `array` excluding elements dropped from the beginning.
  6233. * Elements are dropped until `predicate` returns falsey. The predicate is
  6234. * bound to `thisArg` and invoked with three arguments: (value, index, array).
  6235. *
  6236. * If a property name is provided for `predicate` the created `_.property`
  6237. * style callback returns the property value of the given element.
  6238. *
  6239. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6240. * style callback returns `true` for elements that have a matching property
  6241. * value, else `false`.
  6242. *
  6243. * If an object is provided for `predicate` the created `_.matches` style
  6244. * callback returns `true` for elements that have the properties of the given
  6245. * object, else `false`.
  6246. *
  6247. * @static
  6248. * @memberOf _
  6249. * @category Array
  6250. * @param {Array} array The array to query.
  6251. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6252. * per iteration.
  6253. * @param {*} [thisArg] The `this` binding of `predicate`.
  6254. * @returns {Array} Returns the slice of `array`.
  6255. * @example
  6256. *
  6257. * _.dropWhile([1, 2, 3], function(n) {
  6258. * return n < 3;
  6259. * });
  6260. * // => [3]
  6261. *
  6262. * var users = [
  6263. * { 'user': 'barney', 'active': false },
  6264. * { 'user': 'fred', 'active': false },
  6265. * { 'user': 'pebbles', 'active': true }
  6266. * ];
  6267. *
  6268. * // using the `_.matches` callback shorthand
  6269. * _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
  6270. * // => ['fred', 'pebbles']
  6271. *
  6272. * // using the `_.matchesProperty` callback shorthand
  6273. * _.pluck(_.dropWhile(users, 'active', false), 'user');
  6274. * // => ['pebbles']
  6275. *
  6276. * // using the `_.property` callback shorthand
  6277. * _.pluck(_.dropWhile(users, 'active'), 'user');
  6278. * // => ['barney', 'fred', 'pebbles']
  6279. */
  6280. function dropWhile(array, predicate, thisArg) {
  6281. return (array && array.length)
  6282. ? baseWhile(array, getCallback(predicate, thisArg, 3), true)
  6283. : [];
  6284. }
  6285. /**
  6286. * Fills elements of `array` with `value` from `start` up to, but not
  6287. * including, `end`.
  6288. *
  6289. * **Note:** This method mutates `array`.
  6290. *
  6291. * @static
  6292. * @memberOf _
  6293. * @category Array
  6294. * @param {Array} array The array to fill.
  6295. * @param {*} value The value to fill `array` with.
  6296. * @param {number} [start=0] The start position.
  6297. * @param {number} [end=array.length] The end position.
  6298. * @returns {Array} Returns `array`.
  6299. * @example
  6300. *
  6301. * var array = [1, 2, 3];
  6302. *
  6303. * _.fill(array, 'a');
  6304. * console.log(array);
  6305. * // => ['a', 'a', 'a']
  6306. *
  6307. * _.fill(Array(3), 2);
  6308. * // => [2, 2, 2]
  6309. *
  6310. * _.fill([4, 6, 8], '*', 1, 2);
  6311. * // => [4, '*', 8]
  6312. */
  6313. function fill(array, value, start, end) {
  6314. var length = array ? array.length : 0;
  6315. if (!length) {
  6316. return [];
  6317. }
  6318. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6319. start = 0;
  6320. end = length;
  6321. }
  6322. return baseFill(array, value, start, end);
  6323. }
  6324. /**
  6325. * This method is like `_.find` except that it returns the index of the first
  6326. * element `predicate` returns truthy for instead of the element itself.
  6327. *
  6328. * If a property name is provided for `predicate` the created `_.property`
  6329. * style callback returns the property value of the given element.
  6330. *
  6331. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6332. * style callback returns `true` for elements that have a matching property
  6333. * value, else `false`.
  6334. *
  6335. * If an object is provided for `predicate` the created `_.matches` style
  6336. * callback returns `true` for elements that have the properties of the given
  6337. * object, else `false`.
  6338. *
  6339. * @static
  6340. * @memberOf _
  6341. * @category Array
  6342. * @param {Array} array The array to search.
  6343. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6344. * per iteration.
  6345. * @param {*} [thisArg] The `this` binding of `predicate`.
  6346. * @returns {number} Returns the index of the found element, else `-1`.
  6347. * @example
  6348. *
  6349. * var users = [
  6350. * { 'user': 'barney', 'active': false },
  6351. * { 'user': 'fred', 'active': false },
  6352. * { 'user': 'pebbles', 'active': true }
  6353. * ];
  6354. *
  6355. * _.findIndex(users, function(chr) {
  6356. * return chr.user == 'barney';
  6357. * });
  6358. * // => 0
  6359. *
  6360. * // using the `_.matches` callback shorthand
  6361. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6362. * // => 1
  6363. *
  6364. * // using the `_.matchesProperty` callback shorthand
  6365. * _.findIndex(users, 'active', false);
  6366. * // => 0
  6367. *
  6368. * // using the `_.property` callback shorthand
  6369. * _.findIndex(users, 'active');
  6370. * // => 2
  6371. */
  6372. var findIndex = createFindIndex();
  6373. /**
  6374. * This method is like `_.findIndex` except that it iterates over elements
  6375. * of `collection` from right to left.
  6376. *
  6377. * If a property name is provided for `predicate` the created `_.property`
  6378. * style callback returns the property value of the given element.
  6379. *
  6380. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6381. * style callback returns `true` for elements that have a matching property
  6382. * value, else `false`.
  6383. *
  6384. * If an object is provided for `predicate` the created `_.matches` style
  6385. * callback returns `true` for elements that have the properties of the given
  6386. * object, else `false`.
  6387. *
  6388. * @static
  6389. * @memberOf _
  6390. * @category Array
  6391. * @param {Array} array The array to search.
  6392. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6393. * per iteration.
  6394. * @param {*} [thisArg] The `this` binding of `predicate`.
  6395. * @returns {number} Returns the index of the found element, else `-1`.
  6396. * @example
  6397. *
  6398. * var users = [
  6399. * { 'user': 'barney', 'active': true },
  6400. * { 'user': 'fred', 'active': false },
  6401. * { 'user': 'pebbles', 'active': false }
  6402. * ];
  6403. *
  6404. * _.findLastIndex(users, function(chr) {
  6405. * return chr.user == 'pebbles';
  6406. * });
  6407. * // => 2
  6408. *
  6409. * // using the `_.matches` callback shorthand
  6410. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6411. * // => 0
  6412. *
  6413. * // using the `_.matchesProperty` callback shorthand
  6414. * _.findLastIndex(users, 'active', false);
  6415. * // => 2
  6416. *
  6417. * // using the `_.property` callback shorthand
  6418. * _.findLastIndex(users, 'active');
  6419. * // => 0
  6420. */
  6421. var findLastIndex = createFindIndex(true);
  6422. /**
  6423. * Gets the first element of `array`.
  6424. *
  6425. * @static
  6426. * @memberOf _
  6427. * @alias head
  6428. * @category Array
  6429. * @param {Array} array The array to query.
  6430. * @returns {*} Returns the first element of `array`.
  6431. * @example
  6432. *
  6433. * _.first([1, 2, 3]);
  6434. * // => 1
  6435. *
  6436. * _.first([]);
  6437. * // => undefined
  6438. */
  6439. function first(array) {
  6440. return array ? array[0] : undefined;
  6441. }
  6442. /**
  6443. * Flattens a nested array. If `isDeep` is `true` the array is recursively
  6444. * flattened, otherwise it is only flattened a single level.
  6445. *
  6446. * @static
  6447. * @memberOf _
  6448. * @category Array
  6449. * @param {Array} array The array to flatten.
  6450. * @param {boolean} [isDeep] Specify a deep flatten.
  6451. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  6452. * @returns {Array} Returns the new flattened array.
  6453. * @example
  6454. *
  6455. * _.flatten([1, [2, 3, [4]]]);
  6456. * // => [1, 2, 3, [4]]
  6457. *
  6458. * // using `isDeep`
  6459. * _.flatten([1, [2, 3, [4]]], true);
  6460. * // => [1, 2, 3, 4]
  6461. */
  6462. function flatten(array, isDeep, guard) {
  6463. var length = array ? array.length : 0;
  6464. if (guard && isIterateeCall(array, isDeep, guard)) {
  6465. isDeep = false;
  6466. }
  6467. return length ? baseFlatten(array, isDeep) : [];
  6468. }
  6469. /**
  6470. * Recursively flattens a nested array.
  6471. *
  6472. * @static
  6473. * @memberOf _
  6474. * @category Array
  6475. * @param {Array} array The array to recursively flatten.
  6476. * @returns {Array} Returns the new flattened array.
  6477. * @example
  6478. *
  6479. * _.flattenDeep([1, [2, 3, [4]]]);
  6480. * // => [1, 2, 3, 4]
  6481. */
  6482. function flattenDeep(array) {
  6483. var length = array ? array.length : 0;
  6484. return length ? baseFlatten(array, true) : [];
  6485. }
  6486. /**
  6487. * Gets the index at which the first occurrence of `value` is found in `array`
  6488. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  6489. * for equality comparisons. If `fromIndex` is negative, it is used as the offset
  6490. * from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
  6491. * performs a faster binary search.
  6492. *
  6493. * @static
  6494. * @memberOf _
  6495. * @category Array
  6496. * @param {Array} array The array to search.
  6497. * @param {*} value The value to search for.
  6498. * @param {boolean|number} [fromIndex=0] The index to search from or `true`
  6499. * to perform a binary search on a sorted array.
  6500. * @returns {number} Returns the index of the matched value, else `-1`.
  6501. * @example
  6502. *
  6503. * _.indexOf([1, 2, 1, 2], 2);
  6504. * // => 1
  6505. *
  6506. * // using `fromIndex`
  6507. * _.indexOf([1, 2, 1, 2], 2, 2);
  6508. * // => 3
  6509. *
  6510. * // performing a binary search
  6511. * _.indexOf([1, 1, 2, 2], 2, true);
  6512. * // => 2
  6513. */
  6514. function indexOf(array, value, fromIndex) {
  6515. var length = array ? array.length : 0;
  6516. if (!length) {
  6517. return -1;
  6518. }
  6519. if (typeof fromIndex == 'number') {
  6520. fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
  6521. } else if (fromIndex) {
  6522. var index = binaryIndex(array, value);
  6523. if (index < length &&
  6524. (value === value ? (value === array[index]) : (array[index] !== array[index]))) {
  6525. return index;
  6526. }
  6527. return -1;
  6528. }
  6529. return baseIndexOf(array, value, fromIndex || 0);
  6530. }
  6531. /**
  6532. * Gets all but the last element of `array`.
  6533. *
  6534. * @static
  6535. * @memberOf _
  6536. * @category Array
  6537. * @param {Array} array The array to query.
  6538. * @returns {Array} Returns the slice of `array`.
  6539. * @example
  6540. *
  6541. * _.initial([1, 2, 3]);
  6542. * // => [1, 2]
  6543. */
  6544. function initial(array) {
  6545. return dropRight(array, 1);
  6546. }
  6547. /**
  6548. * Creates an array of unique values that are included in all of the provided
  6549. * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  6550. * for equality comparisons.
  6551. *
  6552. * @static
  6553. * @memberOf _
  6554. * @category Array
  6555. * @param {...Array} [arrays] The arrays to inspect.
  6556. * @returns {Array} Returns the new array of shared values.
  6557. * @example
  6558. * _.intersection([1, 2], [4, 2], [2, 1]);
  6559. * // => [2]
  6560. */
  6561. var intersection = restParam(function(arrays) {
  6562. var othLength = arrays.length,
  6563. othIndex = othLength,
  6564. caches = Array(length),
  6565. indexOf = getIndexOf(),
  6566. isCommon = indexOf == baseIndexOf,
  6567. result = [];
  6568. while (othIndex--) {
  6569. var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : [];
  6570. caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null;
  6571. }
  6572. var array = arrays[0],
  6573. index = -1,
  6574. length = array ? array.length : 0,
  6575. seen = caches[0];
  6576. outer:
  6577. while (++index < length) {
  6578. value = array[index];
  6579. if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
  6580. var othIndex = othLength;
  6581. while (--othIndex) {
  6582. var cache = caches[othIndex];
  6583. if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) {
  6584. continue outer;
  6585. }
  6586. }
  6587. if (seen) {
  6588. seen.push(value);
  6589. }
  6590. result.push(value);
  6591. }
  6592. }
  6593. return result;
  6594. });
  6595. /**
  6596. * Gets the last element of `array`.
  6597. *
  6598. * @static
  6599. * @memberOf _
  6600. * @category Array
  6601. * @param {Array} array The array to query.
  6602. * @returns {*} Returns the last element of `array`.
  6603. * @example
  6604. *
  6605. * _.last([1, 2, 3]);
  6606. * // => 3
  6607. */
  6608. function last(array) {
  6609. var length = array ? array.length : 0;
  6610. return length ? array[length - 1] : undefined;
  6611. }
  6612. /**
  6613. * This method is like `_.indexOf` except that it iterates over elements of
  6614. * `array` from right to left.
  6615. *
  6616. * @static
  6617. * @memberOf _
  6618. * @category Array
  6619. * @param {Array} array The array to search.
  6620. * @param {*} value The value to search for.
  6621. * @param {boolean|number} [fromIndex=array.length-1] The index to search from
  6622. * or `true` to perform a binary search on a sorted array.
  6623. * @returns {number} Returns the index of the matched value, else `-1`.
  6624. * @example
  6625. *
  6626. * _.lastIndexOf([1, 2, 1, 2], 2);
  6627. * // => 3
  6628. *
  6629. * // using `fromIndex`
  6630. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  6631. * // => 1
  6632. *
  6633. * // performing a binary search
  6634. * _.lastIndexOf([1, 1, 2, 2], 2, true);
  6635. * // => 3
  6636. */
  6637. function lastIndexOf(array, value, fromIndex) {
  6638. var length = array ? array.length : 0;
  6639. if (!length) {
  6640. return -1;
  6641. }
  6642. var index = length;
  6643. if (typeof fromIndex == 'number') {
  6644. index = (fromIndex < 0 ? nativeMax(length + fromIndex, 0) : nativeMin(fromIndex || 0, length - 1)) + 1;
  6645. } else if (fromIndex) {
  6646. index = binaryIndex(array, value, true) - 1;
  6647. var other = array[index];
  6648. if (value === value ? (value === other) : (other !== other)) {
  6649. return index;
  6650. }
  6651. return -1;
  6652. }
  6653. if (value !== value) {
  6654. return indexOfNaN(array, index, true);
  6655. }
  6656. while (index--) {
  6657. if (array[index] === value) {
  6658. return index;
  6659. }
  6660. }
  6661. return -1;
  6662. }
  6663. /**
  6664. * Removes all provided values from `array` using
  6665. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  6666. * for equality comparisons.
  6667. *
  6668. * **Note:** Unlike `_.without`, this method mutates `array`.
  6669. *
  6670. * @static
  6671. * @memberOf _
  6672. * @category Array
  6673. * @param {Array} array The array to modify.
  6674. * @param {...*} [values] The values to remove.
  6675. * @returns {Array} Returns `array`.
  6676. * @example
  6677. *
  6678. * var array = [1, 2, 3, 1, 2, 3];
  6679. *
  6680. * _.pull(array, 2, 3);
  6681. * console.log(array);
  6682. * // => [1, 1]
  6683. */
  6684. function pull() {
  6685. var args = arguments,
  6686. array = args[0];
  6687. if (!(array && array.length)) {
  6688. return array;
  6689. }
  6690. var index = 0,
  6691. indexOf = getIndexOf(),
  6692. length = args.length;
  6693. while (++index < length) {
  6694. var fromIndex = 0,
  6695. value = args[index];
  6696. while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
  6697. splice.call(array, fromIndex, 1);
  6698. }
  6699. }
  6700. return array;
  6701. }
  6702. /**
  6703. * Removes elements from `array` corresponding to the given indexes and returns
  6704. * an array of the removed elements. Indexes may be specified as an array of
  6705. * indexes or as individual arguments.
  6706. *
  6707. * **Note:** Unlike `_.at`, this method mutates `array`.
  6708. *
  6709. * @static
  6710. * @memberOf _
  6711. * @category Array
  6712. * @param {Array} array The array to modify.
  6713. * @param {...(number|number[])} [indexes] The indexes of elements to remove,
  6714. * specified as individual indexes or arrays of indexes.
  6715. * @returns {Array} Returns the new array of removed elements.
  6716. * @example
  6717. *
  6718. * var array = [5, 10, 15, 20];
  6719. * var evens = _.pullAt(array, 1, 3);
  6720. *
  6721. * console.log(array);
  6722. * // => [5, 15]
  6723. *
  6724. * console.log(evens);
  6725. * // => [10, 20]
  6726. */
  6727. var pullAt = restParam(function(array, indexes) {
  6728. indexes = baseFlatten(indexes);
  6729. var result = baseAt(array, indexes);
  6730. basePullAt(array, indexes.sort(baseCompareAscending));
  6731. return result;
  6732. });
  6733. /**
  6734. * Removes all elements from `array` that `predicate` returns truthy for
  6735. * and returns an array of the removed elements. The predicate is bound to
  6736. * `thisArg` and invoked with three arguments: (value, index, array).
  6737. *
  6738. * If a property name is provided for `predicate` the created `_.property`
  6739. * style callback returns the property value of the given element.
  6740. *
  6741. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6742. * style callback returns `true` for elements that have a matching property
  6743. * value, else `false`.
  6744. *
  6745. * If an object is provided for `predicate` the created `_.matches` style
  6746. * callback returns `true` for elements that have the properties of the given
  6747. * object, else `false`.
  6748. *
  6749. * **Note:** Unlike `_.filter`, this method mutates `array`.
  6750. *
  6751. * @static
  6752. * @memberOf _
  6753. * @category Array
  6754. * @param {Array} array The array to modify.
  6755. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6756. * per iteration.
  6757. * @param {*} [thisArg] The `this` binding of `predicate`.
  6758. * @returns {Array} Returns the new array of removed elements.
  6759. * @example
  6760. *
  6761. * var array = [1, 2, 3, 4];
  6762. * var evens = _.remove(array, function(n) {
  6763. * return n % 2 == 0;
  6764. * });
  6765. *
  6766. * console.log(array);
  6767. * // => [1, 3]
  6768. *
  6769. * console.log(evens);
  6770. * // => [2, 4]
  6771. */
  6772. function remove(array, predicate, thisArg) {
  6773. var result = [];
  6774. if (!(array && array.length)) {
  6775. return result;
  6776. }
  6777. var index = -1,
  6778. indexes = [],
  6779. length = array.length;
  6780. predicate = getCallback(predicate, thisArg, 3);
  6781. while (++index < length) {
  6782. var value = array[index];
  6783. if (predicate(value, index, array)) {
  6784. result.push(value);
  6785. indexes.push(index);
  6786. }
  6787. }
  6788. basePullAt(array, indexes);
  6789. return result;
  6790. }
  6791. /**
  6792. * Gets all but the first element of `array`.
  6793. *
  6794. * @static
  6795. * @memberOf _
  6796. * @alias tail
  6797. * @category Array
  6798. * @param {Array} array The array to query.
  6799. * @returns {Array} Returns the slice of `array`.
  6800. * @example
  6801. *
  6802. * _.rest([1, 2, 3]);
  6803. * // => [2, 3]
  6804. */
  6805. function rest(array) {
  6806. return drop(array, 1);
  6807. }
  6808. /**
  6809. * Creates a slice of `array` from `start` up to, but not including, `end`.
  6810. *
  6811. * **Note:** This method is used instead of `Array#slice` to support node
  6812. * lists in IE < 9 and to ensure dense arrays are returned.
  6813. *
  6814. * @static
  6815. * @memberOf _
  6816. * @category Array
  6817. * @param {Array} array The array to slice.
  6818. * @param {number} [start=0] The start position.
  6819. * @param {number} [end=array.length] The end position.
  6820. * @returns {Array} Returns the slice of `array`.
  6821. */
  6822. function slice(array, start, end) {
  6823. var length = array ? array.length : 0;
  6824. if (!length) {
  6825. return [];
  6826. }
  6827. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  6828. start = 0;
  6829. end = length;
  6830. }
  6831. return baseSlice(array, start, end);
  6832. }
  6833. /**
  6834. * Uses a binary search to determine the lowest index at which `value` should
  6835. * be inserted into `array` in order to maintain its sort order. If an iteratee
  6836. * function is provided it is invoked for `value` and each element of `array`
  6837. * to compute their sort ranking. The iteratee is bound to `thisArg` and
  6838. * invoked with one argument; (value).
  6839. *
  6840. * If a property name is provided for `iteratee` the created `_.property`
  6841. * style callback returns the property value of the given element.
  6842. *
  6843. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6844. * style callback returns `true` for elements that have a matching property
  6845. * value, else `false`.
  6846. *
  6847. * If an object is provided for `iteratee` the created `_.matches` style
  6848. * callback returns `true` for elements that have the properties of the given
  6849. * object, else `false`.
  6850. *
  6851. * @static
  6852. * @memberOf _
  6853. * @category Array
  6854. * @param {Array} array The sorted array to inspect.
  6855. * @param {*} value The value to evaluate.
  6856. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  6857. * per iteration.
  6858. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6859. * @returns {number} Returns the index at which `value` should be inserted
  6860. * into `array`.
  6861. * @example
  6862. *
  6863. * _.sortedIndex([30, 50], 40);
  6864. * // => 1
  6865. *
  6866. * _.sortedIndex([4, 4, 5, 5], 5);
  6867. * // => 2
  6868. *
  6869. * var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
  6870. *
  6871. * // using an iteratee function
  6872. * _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
  6873. * return this.data[word];
  6874. * }, dict);
  6875. * // => 1
  6876. *
  6877. * // using the `_.property` callback shorthand
  6878. * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
  6879. * // => 1
  6880. */
  6881. var sortedIndex = createSortedIndex();
  6882. /**
  6883. * This method is like `_.sortedIndex` except that it returns the highest
  6884. * index at which `value` should be inserted into `array` in order to
  6885. * maintain its sort order.
  6886. *
  6887. * @static
  6888. * @memberOf _
  6889. * @category Array
  6890. * @param {Array} array The sorted array to inspect.
  6891. * @param {*} value The value to evaluate.
  6892. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  6893. * per iteration.
  6894. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6895. * @returns {number} Returns the index at which `value` should be inserted
  6896. * into `array`.
  6897. * @example
  6898. *
  6899. * _.sortedLastIndex([4, 4, 5, 5], 5);
  6900. * // => 4
  6901. */
  6902. var sortedLastIndex = createSortedIndex(true);
  6903. /**
  6904. * Creates a slice of `array` with `n` elements taken from the beginning.
  6905. *
  6906. * @static
  6907. * @memberOf _
  6908. * @category Array
  6909. * @param {Array} array The array to query.
  6910. * @param {number} [n=1] The number of elements to take.
  6911. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  6912. * @returns {Array} Returns the slice of `array`.
  6913. * @example
  6914. *
  6915. * _.take([1, 2, 3]);
  6916. * // => [1]
  6917. *
  6918. * _.take([1, 2, 3], 2);
  6919. * // => [1, 2]
  6920. *
  6921. * _.take([1, 2, 3], 5);
  6922. * // => [1, 2, 3]
  6923. *
  6924. * _.take([1, 2, 3], 0);
  6925. * // => []
  6926. */
  6927. function take(array, n, guard) {
  6928. var length = array ? array.length : 0;
  6929. if (!length) {
  6930. return [];
  6931. }
  6932. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  6933. n = 1;
  6934. }
  6935. return baseSlice(array, 0, n < 0 ? 0 : n);
  6936. }
  6937. /**
  6938. * Creates a slice of `array` with `n` elements taken from the end.
  6939. *
  6940. * @static
  6941. * @memberOf _
  6942. * @category Array
  6943. * @param {Array} array The array to query.
  6944. * @param {number} [n=1] The number of elements to take.
  6945. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  6946. * @returns {Array} Returns the slice of `array`.
  6947. * @example
  6948. *
  6949. * _.takeRight([1, 2, 3]);
  6950. * // => [3]
  6951. *
  6952. * _.takeRight([1, 2, 3], 2);
  6953. * // => [2, 3]
  6954. *
  6955. * _.takeRight([1, 2, 3], 5);
  6956. * // => [1, 2, 3]
  6957. *
  6958. * _.takeRight([1, 2, 3], 0);
  6959. * // => []
  6960. */
  6961. function takeRight(array, n, guard) {
  6962. var length = array ? array.length : 0;
  6963. if (!length) {
  6964. return [];
  6965. }
  6966. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  6967. n = 1;
  6968. }
  6969. n = length - (+n || 0);
  6970. return baseSlice(array, n < 0 ? 0 : n);
  6971. }
  6972. /**
  6973. * Creates a slice of `array` with elements taken from the end. Elements are
  6974. * taken until `predicate` returns falsey. The predicate is bound to `thisArg`
  6975. * and invoked with three arguments: (value, index, array).
  6976. *
  6977. * If a property name is provided for `predicate` the created `_.property`
  6978. * style callback returns the property value of the given element.
  6979. *
  6980. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6981. * style callback returns `true` for elements that have a matching property
  6982. * value, else `false`.
  6983. *
  6984. * If an object is provided for `predicate` the created `_.matches` style
  6985. * callback returns `true` for elements that have the properties of the given
  6986. * object, else `false`.
  6987. *
  6988. * @static
  6989. * @memberOf _
  6990. * @category Array
  6991. * @param {Array} array The array to query.
  6992. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6993. * per iteration.
  6994. * @param {*} [thisArg] The `this` binding of `predicate`.
  6995. * @returns {Array} Returns the slice of `array`.
  6996. * @example
  6997. *
  6998. * _.takeRightWhile([1, 2, 3], function(n) {
  6999. * return n > 1;
  7000. * });
  7001. * // => [2, 3]
  7002. *
  7003. * var users = [
  7004. * { 'user': 'barney', 'active': true },
  7005. * { 'user': 'fred', 'active': false },
  7006. * { 'user': 'pebbles', 'active': false }
  7007. * ];
  7008. *
  7009. * // using the `_.matches` callback shorthand
  7010. * _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
  7011. * // => ['pebbles']
  7012. *
  7013. * // using the `_.matchesProperty` callback shorthand
  7014. * _.pluck(_.takeRightWhile(users, 'active', false), 'user');
  7015. * // => ['fred', 'pebbles']
  7016. *
  7017. * // using the `_.property` callback shorthand
  7018. * _.pluck(_.takeRightWhile(users, 'active'), 'user');
  7019. * // => []
  7020. */
  7021. function takeRightWhile(array, predicate, thisArg) {
  7022. return (array && array.length)
  7023. ? baseWhile(array, getCallback(predicate, thisArg, 3), false, true)
  7024. : [];
  7025. }
  7026. /**
  7027. * Creates a slice of `array` with elements taken from the beginning. Elements
  7028. * are taken until `predicate` returns falsey. The predicate is bound to
  7029. * `thisArg` and invoked with three arguments: (value, index, array).
  7030. *
  7031. * If a property name is provided for `predicate` the created `_.property`
  7032. * style callback returns the property value of the given element.
  7033. *
  7034. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  7035. * style callback returns `true` for elements that have a matching property
  7036. * value, else `false`.
  7037. *
  7038. * If an object is provided for `predicate` the created `_.matches` style
  7039. * callback returns `true` for elements that have the properties of the given
  7040. * object, else `false`.
  7041. *
  7042. * @static
  7043. * @memberOf _
  7044. * @category Array
  7045. * @param {Array} array The array to query.
  7046. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  7047. * per iteration.
  7048. * @param {*} [thisArg] The `this` binding of `predicate`.
  7049. * @returns {Array} Returns the slice of `array`.
  7050. * @example
  7051. *
  7052. * _.takeWhile([1, 2, 3], function(n) {
  7053. * return n < 3;
  7054. * });
  7055. * // => [1, 2]
  7056. *
  7057. * var users = [
  7058. * { 'user': 'barney', 'active': false },
  7059. * { 'user': 'fred', 'active': false},
  7060. * { 'user': 'pebbles', 'active': true }
  7061. * ];
  7062. *
  7063. * // using the `_.matches` callback shorthand
  7064. * _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
  7065. * // => ['barney']
  7066. *
  7067. * // using the `_.matchesProperty` callback shorthand
  7068. * _.pluck(_.takeWhile(users, 'active', false), 'user');
  7069. * // => ['barney', 'fred']
  7070. *
  7071. * // using the `_.property` callback shorthand
  7072. * _.pluck(_.takeWhile(users, 'active'), 'user');
  7073. * // => []
  7074. */
  7075. function takeWhile(array, predicate, thisArg) {
  7076. return (array && array.length)
  7077. ? baseWhile(array, getCallback(predicate, thisArg, 3))
  7078. : [];
  7079. }
  7080. /**
  7081. * Creates an array of unique values, in order, from all of the provided arrays
  7082. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  7083. * for equality comparisons.
  7084. *
  7085. * @static
  7086. * @memberOf _
  7087. * @category Array
  7088. * @param {...Array} [arrays] The arrays to inspect.
  7089. * @returns {Array} Returns the new array of combined values.
  7090. * @example
  7091. *
  7092. * _.union([1, 2], [4, 2], [2, 1]);
  7093. * // => [1, 2, 4]
  7094. */
  7095. var union = restParam(function(arrays) {
  7096. return baseUniq(baseFlatten(arrays, false, true));
  7097. });
  7098. /**
  7099. * Creates a duplicate-free version of an array, using
  7100. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  7101. * for equality comparisons, in which only the first occurence of each element
  7102. * is kept. Providing `true` for `isSorted` performs a faster search algorithm
  7103. * for sorted arrays. If an iteratee function is provided it is invoked for
  7104. * each element in the array to generate the criterion by which uniqueness
  7105. * is computed. The `iteratee` is bound to `thisArg` and invoked with three
  7106. * arguments: (value, index, array).
  7107. *
  7108. * If a property name is provided for `iteratee` the created `_.property`
  7109. * style callback returns the property value of the given element.
  7110. *
  7111. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  7112. * style callback returns `true` for elements that have a matching property
  7113. * value, else `false`.
  7114. *
  7115. * If an object is provided for `iteratee` the created `_.matches` style
  7116. * callback returns `true` for elements that have the properties of the given
  7117. * object, else `false`.
  7118. *
  7119. * @static
  7120. * @memberOf _
  7121. * @alias unique
  7122. * @category Array
  7123. * @param {Array} array The array to inspect.
  7124. * @param {boolean} [isSorted] Specify the array is sorted.
  7125. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  7126. * @param {*} [thisArg] The `this` binding of `iteratee`.
  7127. * @returns {Array} Returns the new duplicate-value-free array.
  7128. * @example
  7129. *
  7130. * _.uniq([2, 1, 2]);
  7131. * // => [2, 1]
  7132. *
  7133. * // using `isSorted`
  7134. * _.uniq([1, 1, 2], true);
  7135. * // => [1, 2]
  7136. *
  7137. * // using an iteratee function
  7138. * _.uniq([1, 2.5, 1.5, 2], function(n) {
  7139. * return this.floor(n);
  7140. * }, Math);
  7141. * // => [1, 2.5]
  7142. *
  7143. * // using the `_.property` callback shorthand
  7144. * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7145. * // => [{ 'x': 1 }, { 'x': 2 }]
  7146. */
  7147. function uniq(array, isSorted, iteratee, thisArg) {
  7148. var length = array ? array.length : 0;
  7149. if (!length) {
  7150. return [];
  7151. }
  7152. if (isSorted != null && typeof isSorted != 'boolean') {
  7153. thisArg = iteratee;
  7154. iteratee = isIterateeCall(array, isSorted, thisArg) ? undefined : isSorted;
  7155. isSorted = false;
  7156. }
  7157. var callback = getCallback();
  7158. if (!(iteratee == null && callback === baseCallback)) {
  7159. iteratee = callback(iteratee, thisArg, 3);
  7160. }
  7161. return (isSorted && getIndexOf() == baseIndexOf)
  7162. ? sortedUniq(array, iteratee)
  7163. : baseUniq(array, iteratee);
  7164. }
  7165. /**
  7166. * This method is like `_.zip` except that it accepts an array of grouped
  7167. * elements and creates an array regrouping the elements to their pre-zip
  7168. * configuration.
  7169. *
  7170. * @static
  7171. * @memberOf _
  7172. * @category Array
  7173. * @param {Array} array The array of grouped elements to process.
  7174. * @returns {Array} Returns the new array of regrouped elements.
  7175. * @example
  7176. *
  7177. * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
  7178. * // => [['fred', 30, true], ['barney', 40, false]]
  7179. *
  7180. * _.unzip(zipped);
  7181. * // => [['fred', 'barney'], [30, 40], [true, false]]
  7182. */
  7183. function unzip(array) {
  7184. if (!(array && array.length)) {
  7185. return [];
  7186. }
  7187. var index = -1,
  7188. length = 0;
  7189. array = arrayFilter(array, function(group) {
  7190. if (isArrayLike(group)) {
  7191. length = nativeMax(group.length, length);
  7192. return true;
  7193. }
  7194. });
  7195. var result = Array(length);
  7196. while (++index < length) {
  7197. result[index] = arrayMap(array, baseProperty(index));
  7198. }
  7199. return result;
  7200. }
  7201. /**
  7202. * This method is like `_.unzip` except that it accepts an iteratee to specify
  7203. * how regrouped values should be combined. The `iteratee` is bound to `thisArg`
  7204. * and invoked with four arguments: (accumulator, value, index, group).
  7205. *
  7206. * @static
  7207. * @memberOf _
  7208. * @category Array
  7209. * @param {Array} array The array of grouped elements to process.
  7210. * @param {Function} [iteratee] The function to combine regrouped values.
  7211. * @param {*} [thisArg] The `this` binding of `iteratee`.
  7212. * @returns {Array} Returns the new array of regrouped elements.
  7213. * @example
  7214. *
  7215. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7216. * // => [[1, 10, 100], [2, 20, 200]]
  7217. *
  7218. * _.unzipWith(zipped, _.add);
  7219. * // => [3, 30, 300]
  7220. */
  7221. function unzipWith(array, iteratee, thisArg) {
  7222. var length = array ? array.length : 0;
  7223. if (!length) {
  7224. return [];
  7225. }
  7226. var result = unzip(array);
  7227. if (iteratee == null) {
  7228. return result;
  7229. }
  7230. iteratee = bindCallback(iteratee, thisArg, 4);
  7231. return arrayMap(result, function(group) {
  7232. return arrayReduce(group, iteratee, undefined, true);
  7233. });
  7234. }
  7235. /**
  7236. * Creates an array excluding all provided values using
  7237. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  7238. * for equality comparisons.
  7239. *
  7240. * @static
  7241. * @memberOf _
  7242. * @category Array
  7243. * @param {Array} array The array to filter.
  7244. * @param {...*} [values] The values to exclude.
  7245. * @returns {Array} Returns the new array of filtered values.
  7246. * @example
  7247. *
  7248. * _.without([1, 2, 1, 3], 1, 2);
  7249. * // => [3]
  7250. */
  7251. var without = restParam(function(array, values) {
  7252. return isArrayLike(array)
  7253. ? baseDifference(array, values)
  7254. : [];
  7255. });
  7256. /**
  7257. * Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7258. * of the provided arrays.
  7259. *
  7260. * @static
  7261. * @memberOf _
  7262. * @category Array
  7263. * @param {...Array} [arrays] The arrays to inspect.
  7264. * @returns {Array} Returns the new array of values.
  7265. * @example
  7266. *
  7267. * _.xor([1, 2], [4, 2]);
  7268. * // => [1, 4]
  7269. */
  7270. function xor() {
  7271. var index = -1,
  7272. length = arguments.length;
  7273. while (++index < length) {
  7274. var array = arguments[index];
  7275. if (isArrayLike(array)) {
  7276. var result = result
  7277. ? arrayPush(baseDifference(result, array), baseDifference(array, result))
  7278. : array;
  7279. }
  7280. }
  7281. return result ? baseUniq(result) : [];
  7282. }
  7283. /**
  7284. * Creates an array of grouped elements, the first of which contains the first
  7285. * elements of the given arrays, the second of which contains the second elements
  7286. * of the given arrays, and so on.
  7287. *
  7288. * @static
  7289. * @memberOf _
  7290. * @category Array
  7291. * @param {...Array} [arrays] The arrays to process.
  7292. * @returns {Array} Returns the new array of grouped elements.
  7293. * @example
  7294. *
  7295. * _.zip(['fred', 'barney'], [30, 40], [true, false]);
  7296. * // => [['fred', 30, true], ['barney', 40, false]]
  7297. */
  7298. var zip = restParam(unzip);
  7299. /**
  7300. * The inverse of `_.pairs`; this method returns an object composed from arrays
  7301. * of property names and values. Provide either a single two dimensional array,
  7302. * e.g. `[[key1, value1], [key2, value2]]` or two arrays, one of property names
  7303. * and one of corresponding values.
  7304. *
  7305. * @static
  7306. * @memberOf _
  7307. * @alias object
  7308. * @category Array
  7309. * @param {Array} props The property names.
  7310. * @param {Array} [values=[]] The property values.
  7311. * @returns {Object} Returns the new object.
  7312. * @example
  7313. *
  7314. * _.zipObject([['fred', 30], ['barney', 40]]);
  7315. * // => { 'fred': 30, 'barney': 40 }
  7316. *
  7317. * _.zipObject(['fred', 'barney'], [30, 40]);
  7318. * // => { 'fred': 30, 'barney': 40 }
  7319. */
  7320. function zipObject(props, values) {
  7321. var index = -1,
  7322. length = props ? props.length : 0,
  7323. result = {};
  7324. if (length && !values && !isArray(props[0])) {
  7325. values = [];
  7326. }
  7327. while (++index < length) {
  7328. var key = props[index];
  7329. if (values) {
  7330. result[key] = values[index];
  7331. } else if (key) {
  7332. result[key[0]] = key[1];
  7333. }
  7334. }
  7335. return result;
  7336. }
  7337. /**
  7338. * This method is like `_.zip` except that it accepts an iteratee to specify
  7339. * how grouped values should be combined. The `iteratee` is bound to `thisArg`
  7340. * and invoked with four arguments: (accumulator, value, index, group).
  7341. *
  7342. * @static
  7343. * @memberOf _
  7344. * @category Array
  7345. * @param {...Array} [arrays] The arrays to process.
  7346. * @param {Function} [iteratee] The function to combine grouped values.
  7347. * @param {*} [thisArg] The `this` binding of `iteratee`.
  7348. * @returns {Array} Returns the new array of grouped elements.
  7349. * @example
  7350. *
  7351. * _.zipWith([1, 2], [10, 20], [100, 200], _.add);
  7352. * // => [111, 222]
  7353. */
  7354. var zipWith = restParam(function(arrays) {
  7355. var length = arrays.length,
  7356. iteratee = length > 2 ? arrays[length - 2] : undefined,
  7357. thisArg = length > 1 ? arrays[length - 1] : undefined;
  7358. if (length > 2 && typeof iteratee == 'function') {
  7359. length -= 2;
  7360. } else {
  7361. iteratee = (length > 1 && typeof thisArg == 'function') ? (--length, thisArg) : undefined;
  7362. thisArg = undefined;
  7363. }
  7364. arrays.length = length;
  7365. return unzipWith(arrays, iteratee, thisArg);
  7366. });
  7367. /*------------------------------------------------------------------------*/
  7368. /**
  7369. * Creates a `lodash` object that wraps `value` with explicit method
  7370. * chaining enabled.
  7371. *
  7372. * @static
  7373. * @memberOf _
  7374. * @category Chain
  7375. * @param {*} value The value to wrap.
  7376. * @returns {Object} Returns the new `lodash` wrapper instance.
  7377. * @example
  7378. *
  7379. * var users = [
  7380. * { 'user': 'barney', 'age': 36 },
  7381. * { 'user': 'fred', 'age': 40 },
  7382. * { 'user': 'pebbles', 'age': 1 }
  7383. * ];
  7384. *
  7385. * var youngest = _.chain(users)
  7386. * .sortBy('age')
  7387. * .map(function(chr) {
  7388. * return chr.user + ' is ' + chr.age;
  7389. * })
  7390. * .first()
  7391. * .value();
  7392. * // => 'pebbles is 1'
  7393. */
  7394. function chain(value) {
  7395. var result = lodash(value);
  7396. result.__chain__ = true;
  7397. return result;
  7398. }
  7399. /**
  7400. * This method invokes `interceptor` and returns `value`. The interceptor is
  7401. * bound to `thisArg` and invoked with one argument; (value). The purpose of
  7402. * this method is to "tap into" a method chain in order to perform operations
  7403. * on intermediate results within the chain.
  7404. *
  7405. * @static
  7406. * @memberOf _
  7407. * @category Chain
  7408. * @param {*} value The value to provide to `interceptor`.
  7409. * @param {Function} interceptor The function to invoke.
  7410. * @param {*} [thisArg] The `this` binding of `interceptor`.
  7411. * @returns {*} Returns `value`.
  7412. * @example
  7413. *
  7414. * _([1, 2, 3])
  7415. * .tap(function(array) {
  7416. * array.pop();
  7417. * })
  7418. * .reverse()
  7419. * .value();
  7420. * // => [2, 1]
  7421. */
  7422. function tap(value, interceptor, thisArg) {
  7423. interceptor.call(thisArg, value);
  7424. return value;
  7425. }
  7426. /**
  7427. * This method is like `_.tap` except that it returns the result of `interceptor`.
  7428. *
  7429. * @static
  7430. * @memberOf _
  7431. * @category Chain
  7432. * @param {*} value The value to provide to `interceptor`.
  7433. * @param {Function} interceptor The function to invoke.
  7434. * @param {*} [thisArg] The `this` binding of `interceptor`.
  7435. * @returns {*} Returns the result of `interceptor`.
  7436. * @example
  7437. *
  7438. * _(' abc ')
  7439. * .chain()
  7440. * .trim()
  7441. * .thru(function(value) {
  7442. * return [value];
  7443. * })
  7444. * .value();
  7445. * // => ['abc']
  7446. */
  7447. function thru(value, interceptor, thisArg) {
  7448. return interceptor.call(thisArg, value);
  7449. }
  7450. /**
  7451. * Enables explicit method chaining on the wrapper object.
  7452. *
  7453. * @name chain
  7454. * @memberOf _
  7455. * @category Chain
  7456. * @returns {Object} Returns the new `lodash` wrapper instance.
  7457. * @example
  7458. *
  7459. * var users = [
  7460. * { 'user': 'barney', 'age': 36 },
  7461. * { 'user': 'fred', 'age': 40 }
  7462. * ];
  7463. *
  7464. * // without explicit chaining
  7465. * _(users).first();
  7466. * // => { 'user': 'barney', 'age': 36 }
  7467. *
  7468. * // with explicit chaining
  7469. * _(users).chain()
  7470. * .first()
  7471. * .pick('user')
  7472. * .value();
  7473. * // => { 'user': 'barney' }
  7474. */
  7475. function wrapperChain() {
  7476. return chain(this);
  7477. }
  7478. /**
  7479. * Executes the chained sequence and returns the wrapped result.
  7480. *
  7481. * @name commit
  7482. * @memberOf _
  7483. * @category Chain
  7484. * @returns {Object} Returns the new `lodash` wrapper instance.
  7485. * @example
  7486. *
  7487. * var array = [1, 2];
  7488. * var wrapped = _(array).push(3);
  7489. *
  7490. * console.log(array);
  7491. * // => [1, 2]
  7492. *
  7493. * wrapped = wrapped.commit();
  7494. * console.log(array);
  7495. * // => [1, 2, 3]
  7496. *
  7497. * wrapped.last();
  7498. * // => 3
  7499. *
  7500. * console.log(array);
  7501. * // => [1, 2, 3]
  7502. */
  7503. function wrapperCommit() {
  7504. return new LodashWrapper(this.value(), this.__chain__);
  7505. }
  7506. /**
  7507. * Creates a new array joining a wrapped array with any additional arrays
  7508. * and/or values.
  7509. *
  7510. * @name concat
  7511. * @memberOf _
  7512. * @category Chain
  7513. * @param {...*} [values] The values to concatenate.
  7514. * @returns {Array} Returns the new concatenated array.
  7515. * @example
  7516. *
  7517. * var array = [1];
  7518. * var wrapped = _(array).concat(2, [3], [[4]]);
  7519. *
  7520. * console.log(wrapped.value());
  7521. * // => [1, 2, 3, [4]]
  7522. *
  7523. * console.log(array);
  7524. * // => [1]
  7525. */
  7526. var wrapperConcat = restParam(function(values) {
  7527. values = baseFlatten(values);
  7528. return this.thru(function(array) {
  7529. return arrayConcat(isArray(array) ? array : [toObject(array)], values);
  7530. });
  7531. });
  7532. /**
  7533. * Creates a clone of the chained sequence planting `value` as the wrapped value.
  7534. *
  7535. * @name plant
  7536. * @memberOf _
  7537. * @category Chain
  7538. * @returns {Object} Returns the new `lodash` wrapper instance.
  7539. * @example
  7540. *
  7541. * var array = [1, 2];
  7542. * var wrapped = _(array).map(function(value) {
  7543. * return Math.pow(value, 2);
  7544. * });
  7545. *
  7546. * var other = [3, 4];
  7547. * var otherWrapped = wrapped.plant(other);
  7548. *
  7549. * otherWrapped.value();
  7550. * // => [9, 16]
  7551. *
  7552. * wrapped.value();
  7553. * // => [1, 4]
  7554. */
  7555. function wrapperPlant(value) {
  7556. var result,
  7557. parent = this;
  7558. while (parent instanceof baseLodash) {
  7559. var clone = wrapperClone(parent);
  7560. if (result) {
  7561. previous.__wrapped__ = clone;
  7562. } else {
  7563. result = clone;
  7564. }
  7565. var previous = clone;
  7566. parent = parent.__wrapped__;
  7567. }
  7568. previous.__wrapped__ = value;
  7569. return result;
  7570. }
  7571. /**
  7572. * Reverses the wrapped array so the first element becomes the last, the
  7573. * second element becomes the second to last, and so on.
  7574. *
  7575. * **Note:** This method mutates the wrapped array.
  7576. *
  7577. * @name reverse
  7578. * @memberOf _
  7579. * @category Chain
  7580. * @returns {Object} Returns the new reversed `lodash` wrapper instance.
  7581. * @example
  7582. *
  7583. * var array = [1, 2, 3];
  7584. *
  7585. * _(array).reverse().value()
  7586. * // => [3, 2, 1]
  7587. *
  7588. * console.log(array);
  7589. * // => [3, 2, 1]
  7590. */
  7591. function wrapperReverse() {
  7592. var value = this.__wrapped__;
  7593. var interceptor = function(value) {
  7594. return (wrapped && wrapped.__dir__ < 0) ? value : value.reverse();
  7595. };
  7596. if (value instanceof LazyWrapper) {
  7597. var wrapped = value;
  7598. if (this.__actions__.length) {
  7599. wrapped = new LazyWrapper(this);
  7600. }
  7601. wrapped = wrapped.reverse();
  7602. wrapped.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  7603. return new LodashWrapper(wrapped, this.__chain__);
  7604. }
  7605. return this.thru(interceptor);
  7606. }
  7607. /**
  7608. * Produces the result of coercing the unwrapped value to a string.
  7609. *
  7610. * @name toString
  7611. * @memberOf _
  7612. * @category Chain
  7613. * @returns {string} Returns the coerced string value.
  7614. * @example
  7615. *
  7616. * _([1, 2, 3]).toString();
  7617. * // => '1,2,3'
  7618. */
  7619. function wrapperToString() {
  7620. return (this.value() + '');
  7621. }
  7622. /**
  7623. * Executes the chained sequence to extract the unwrapped value.
  7624. *
  7625. * @name value
  7626. * @memberOf _
  7627. * @alias run, toJSON, valueOf
  7628. * @category Chain
  7629. * @returns {*} Returns the resolved unwrapped value.
  7630. * @example
  7631. *
  7632. * _([1, 2, 3]).value();
  7633. * // => [1, 2, 3]
  7634. */
  7635. function wrapperValue() {
  7636. return baseWrapperValue(this.__wrapped__, this.__actions__);
  7637. }
  7638. /*------------------------------------------------------------------------*/
  7639. /**
  7640. * Creates an array of elements corresponding to the given keys, or indexes,
  7641. * of `collection`. Keys may be specified as individual arguments or as arrays
  7642. * of keys.
  7643. *
  7644. * @static
  7645. * @memberOf _
  7646. * @category Collection
  7647. * @param {Array|Object|string} collection The collection to iterate over.
  7648. * @param {...(number|number[]|string|string[])} [props] The property names
  7649. * or indexes of elements to pick, specified individually or in arrays.
  7650. * @returns {Array} Returns the new array of picked elements.
  7651. * @example
  7652. *
  7653. * _.at(['a', 'b', 'c'], [0, 2]);
  7654. * // => ['a', 'c']
  7655. *
  7656. * _.at(['barney', 'fred', 'pebbles'], 0, 2);
  7657. * // => ['barney', 'pebbles']
  7658. */
  7659. var at = restParam(function(collection, props) {
  7660. return baseAt(collection, baseFlatten(props));
  7661. });
  7662. /**
  7663. * Creates an object composed of keys generated from the results of running
  7664. * each element of `collection` through `iteratee`. The corresponding value
  7665. * of each key is the number of times the key was returned by `iteratee`.
  7666. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  7667. * (value, index|key, collection).
  7668. *
  7669. * If a property name is provided for `iteratee` the created `_.property`
  7670. * style callback returns the property value of the given element.
  7671. *
  7672. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  7673. * style callback returns `true` for elements that have a matching property
  7674. * value, else `false`.
  7675. *
  7676. * If an object is provided for `iteratee` the created `_.matches` style
  7677. * callback returns `true` for elements that have the properties of the given
  7678. * object, else `false`.
  7679. *
  7680. * @static
  7681. * @memberOf _
  7682. * @category Collection
  7683. * @param {Array|Object|string} collection The collection to iterate over.
  7684. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  7685. * per iteration.
  7686. * @param {*} [thisArg] The `this` binding of `iteratee`.
  7687. * @returns {Object} Returns the composed aggregate object.
  7688. * @example
  7689. *
  7690. * _.countBy([4.3, 6.1, 6.4], function(n) {
  7691. * return Math.floor(n);
  7692. * });
  7693. * // => { '4': 1, '6': 2 }
  7694. *
  7695. * _.countBy([4.3, 6.1, 6.4], function(n) {
  7696. * return this.floor(n);
  7697. * }, Math);
  7698. * // => { '4': 1, '6': 2 }
  7699. *
  7700. * _.countBy(['one', 'two', 'three'], 'length');
  7701. * // => { '3': 2, '5': 1 }
  7702. */
  7703. var countBy = createAggregator(function(result, value, key) {
  7704. hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
  7705. });
  7706. /**
  7707. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  7708. * The predicate is bound to `thisArg` and invoked with three arguments:
  7709. * (value, index|key, collection).
  7710. *
  7711. * If a property name is provided for `predicate` the created `_.property`
  7712. * style callback returns the property value of the given element.
  7713. *
  7714. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  7715. * style callback returns `true` for elements that have a matching property
  7716. * value, else `false`.
  7717. *
  7718. * If an object is provided for `predicate` the created `_.matches` style
  7719. * callback returns `true` for elements that have the properties of the given
  7720. * object, else `false`.
  7721. *
  7722. * @static
  7723. * @memberOf _
  7724. * @alias all
  7725. * @category Collection
  7726. * @param {Array|Object|string} collection The collection to iterate over.
  7727. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  7728. * per iteration.
  7729. * @param {*} [thisArg] The `this` binding of `predicate`.
  7730. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  7731. * else `false`.
  7732. * @example
  7733. *
  7734. * _.every([true, 1, null, 'yes'], Boolean);
  7735. * // => false
  7736. *
  7737. * var users = [
  7738. * { 'user': 'barney', 'active': false },
  7739. * { 'user': 'fred', 'active': false }
  7740. * ];
  7741. *
  7742. * // using the `_.matches` callback shorthand
  7743. * _.every(users, { 'user': 'barney', 'active': false });
  7744. * // => false
  7745. *
  7746. * // using the `_.matchesProperty` callback shorthand
  7747. * _.every(users, 'active', false);
  7748. * // => true
  7749. *
  7750. * // using the `_.property` callback shorthand
  7751. * _.every(users, 'active');
  7752. * // => false
  7753. */
  7754. function every(collection, predicate, thisArg) {
  7755. var func = isArray(collection) ? arrayEvery : baseEvery;
  7756. if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
  7757. predicate = undefined;
  7758. }
  7759. if (typeof predicate != 'function' || thisArg !== undefined) {
  7760. predicate = getCallback(predicate, thisArg, 3);
  7761. }
  7762. return func(collection, predicate);
  7763. }
  7764. /**
  7765. * Iterates over elements of `collection`, returning an array of all elements
  7766. * `predicate` returns truthy for. The predicate is bound to `thisArg` and
  7767. * invoked with three arguments: (value, index|key, collection).
  7768. *
  7769. * If a property name is provided for `predicate` the created `_.property`
  7770. * style callback returns the property value of the given element.
  7771. *
  7772. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  7773. * style callback returns `true` for elements that have a matching property
  7774. * value, else `false`.
  7775. *
  7776. * If an object is provided for `predicate` the created `_.matches` style
  7777. * callback returns `true` for elements that have the properties of the given
  7778. * object, else `false`.
  7779. *
  7780. * @static
  7781. * @memberOf _
  7782. * @alias select
  7783. * @category Collection
  7784. * @param {Array|Object|string} collection The collection to iterate over.
  7785. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  7786. * per iteration.
  7787. * @param {*} [thisArg] The `this` binding of `predicate`.
  7788. * @returns {Array} Returns the new filtered array.
  7789. * @example
  7790. *
  7791. * _.filter([4, 5, 6], function(n) {
  7792. * return n % 2 == 0;
  7793. * });
  7794. * // => [4, 6]
  7795. *
  7796. * var users = [
  7797. * { 'user': 'barney', 'age': 36, 'active': true },
  7798. * { 'user': 'fred', 'age': 40, 'active': false }
  7799. * ];
  7800. *
  7801. * // using the `_.matches` callback shorthand
  7802. * _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
  7803. * // => ['barney']
  7804. *
  7805. * // using the `_.matchesProperty` callback shorthand
  7806. * _.pluck(_.filter(users, 'active', false), 'user');
  7807. * // => ['fred']
  7808. *
  7809. * // using the `_.property` callback shorthand
  7810. * _.pluck(_.filter(users, 'active'), 'user');
  7811. * // => ['barney']
  7812. */
  7813. function filter(collection, predicate, thisArg) {
  7814. var func = isArray(collection) ? arrayFilter : baseFilter;
  7815. predicate = getCallback(predicate, thisArg, 3);
  7816. return func(collection, predicate);
  7817. }
  7818. /**
  7819. * Iterates over elements of `collection`, returning the first element
  7820. * `predicate` returns truthy for. The predicate is bound to `thisArg` and
  7821. * invoked with three arguments: (value, index|key, collection).
  7822. *
  7823. * If a property name is provided for `predicate` the created `_.property`
  7824. * style callback returns the property value of the given element.
  7825. *
  7826. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  7827. * style callback returns `true` for elements that have a matching property
  7828. * value, else `false`.
  7829. *
  7830. * If an object is provided for `predicate` the created `_.matches` style
  7831. * callback returns `true` for elements that have the properties of the given
  7832. * object, else `false`.
  7833. *
  7834. * @static
  7835. * @memberOf _
  7836. * @alias detect
  7837. * @category Collection
  7838. * @param {Array|Object|string} collection The collection to search.
  7839. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  7840. * per iteration.
  7841. * @param {*} [thisArg] The `this` binding of `predicate`.
  7842. * @returns {*} Returns the matched element, else `undefined`.
  7843. * @example
  7844. *
  7845. * var users = [
  7846. * { 'user': 'barney', 'age': 36, 'active': true },
  7847. * { 'user': 'fred', 'age': 40, 'active': false },
  7848. * { 'user': 'pebbles', 'age': 1, 'active': true }
  7849. * ];
  7850. *
  7851. * _.result(_.find(users, function(chr) {
  7852. * return chr.age < 40;
  7853. * }), 'user');
  7854. * // => 'barney'
  7855. *
  7856. * // using the `_.matches` callback shorthand
  7857. * _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
  7858. * // => 'pebbles'
  7859. *
  7860. * // using the `_.matchesProperty` callback shorthand
  7861. * _.result(_.find(users, 'active', false), 'user');
  7862. * // => 'fred'
  7863. *
  7864. * // using the `_.property` callback shorthand
  7865. * _.result(_.find(users, 'active'), 'user');
  7866. * // => 'barney'
  7867. */
  7868. var find = createFind(baseEach);
  7869. /**
  7870. * This method is like `_.find` except that it iterates over elements of
  7871. * `collection` from right to left.
  7872. *
  7873. * @static
  7874. * @memberOf _
  7875. * @category Collection
  7876. * @param {Array|Object|string} collection The collection to search.
  7877. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  7878. * per iteration.
  7879. * @param {*} [thisArg] The `this` binding of `predicate`.
  7880. * @returns {*} Returns the matched element, else `undefined`.
  7881. * @example
  7882. *
  7883. * _.findLast([1, 2, 3, 4], function(n) {
  7884. * return n % 2 == 1;
  7885. * });
  7886. * // => 3
  7887. */
  7888. var findLast = createFind(baseEachRight, true);
  7889. /**
  7890. * Performs a deep comparison between each element in `collection` and the
  7891. * source object, returning the first element that has equivalent property
  7892. * values.
  7893. *
  7894. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  7895. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  7896. * their own, not inherited, enumerable properties. For comparing a single
  7897. * own or inherited property value see `_.matchesProperty`.
  7898. *
  7899. * @static
  7900. * @memberOf _
  7901. * @category Collection
  7902. * @param {Array|Object|string} collection The collection to search.
  7903. * @param {Object} source The object of property values to match.
  7904. * @returns {*} Returns the matched element, else `undefined`.
  7905. * @example
  7906. *
  7907. * var users = [
  7908. * { 'user': 'barney', 'age': 36, 'active': true },
  7909. * { 'user': 'fred', 'age': 40, 'active': false }
  7910. * ];
  7911. *
  7912. * _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user');
  7913. * // => 'barney'
  7914. *
  7915. * _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user');
  7916. * // => 'fred'
  7917. */
  7918. function findWhere(collection, source) {
  7919. return find(collection, baseMatches(source));
  7920. }
  7921. /**
  7922. * Iterates over elements of `collection` invoking `iteratee` for each element.
  7923. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  7924. * (value, index|key, collection). Iteratee functions may exit iteration early
  7925. * by explicitly returning `false`.
  7926. *
  7927. * **Note:** As with other "Collections" methods, objects with a "length" property
  7928. * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
  7929. * may be used for object iteration.
  7930. *
  7931. * @static
  7932. * @memberOf _
  7933. * @alias each
  7934. * @category Collection
  7935. * @param {Array|Object|string} collection The collection to iterate over.
  7936. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  7937. * @param {*} [thisArg] The `this` binding of `iteratee`.
  7938. * @returns {Array|Object|string} Returns `collection`.
  7939. * @example
  7940. *
  7941. * _([1, 2]).forEach(function(n) {
  7942. * console.log(n);
  7943. * }).value();
  7944. * // => logs each value from left to right and returns the array
  7945. *
  7946. * _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
  7947. * console.log(n, key);
  7948. * });
  7949. * // => logs each value-key pair and returns the object (iteration order is not guaranteed)
  7950. */
  7951. var forEach = createForEach(arrayEach, baseEach);
  7952. /**
  7953. * This method is like `_.forEach` except that it iterates over elements of
  7954. * `collection` from right to left.
  7955. *
  7956. * @static
  7957. * @memberOf _
  7958. * @alias eachRight
  7959. * @category Collection
  7960. * @param {Array|Object|string} collection The collection to iterate over.
  7961. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  7962. * @param {*} [thisArg] The `this` binding of `iteratee`.
  7963. * @returns {Array|Object|string} Returns `collection`.
  7964. * @example
  7965. *
  7966. * _([1, 2]).forEachRight(function(n) {
  7967. * console.log(n);
  7968. * }).value();
  7969. * // => logs each value from right to left and returns the array
  7970. */
  7971. var forEachRight = createForEach(arrayEachRight, baseEachRight);
  7972. /**
  7973. * Creates an object composed of keys generated from the results of running
  7974. * each element of `collection` through `iteratee`. The corresponding value
  7975. * of each key is an array of the elements responsible for generating the key.
  7976. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  7977. * (value, index|key, collection).
  7978. *
  7979. * If a property name is provided for `iteratee` the created `_.property`
  7980. * style callback returns the property value of the given element.
  7981. *
  7982. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  7983. * style callback returns `true` for elements that have a matching property
  7984. * value, else `false`.
  7985. *
  7986. * If an object is provided for `iteratee` the created `_.matches` style
  7987. * callback returns `true` for elements that have the properties of the given
  7988. * object, else `false`.
  7989. *
  7990. * @static
  7991. * @memberOf _
  7992. * @category Collection
  7993. * @param {Array|Object|string} collection The collection to iterate over.
  7994. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  7995. * per iteration.
  7996. * @param {*} [thisArg] The `this` binding of `iteratee`.
  7997. * @returns {Object} Returns the composed aggregate object.
  7998. * @example
  7999. *
  8000. * _.groupBy([4.2, 6.1, 6.4], function(n) {
  8001. * return Math.floor(n);
  8002. * });
  8003. * // => { '4': [4.2], '6': [6.1, 6.4] }
  8004. *
  8005. * _.groupBy([4.2, 6.1, 6.4], function(n) {
  8006. * return this.floor(n);
  8007. * }, Math);
  8008. * // => { '4': [4.2], '6': [6.1, 6.4] }
  8009. *
  8010. * // using the `_.property` callback shorthand
  8011. * _.groupBy(['one', 'two', 'three'], 'length');
  8012. * // => { '3': ['one', 'two'], '5': ['three'] }
  8013. */
  8014. var groupBy = createAggregator(function(result, value, key) {
  8015. if (hasOwnProperty.call(result, key)) {
  8016. result[key].push(value);
  8017. } else {
  8018. result[key] = [value];
  8019. }
  8020. });
  8021. /**
  8022. * Checks if `value` is in `collection` using
  8023. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  8024. * for equality comparisons. If `fromIndex` is negative, it is used as the offset
  8025. * from the end of `collection`.
  8026. *
  8027. * @static
  8028. * @memberOf _
  8029. * @alias contains, include
  8030. * @category Collection
  8031. * @param {Array|Object|string} collection The collection to search.
  8032. * @param {*} target The value to search for.
  8033. * @param {number} [fromIndex=0] The index to search from.
  8034. * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
  8035. * @returns {boolean} Returns `true` if a matching element is found, else `false`.
  8036. * @example
  8037. *
  8038. * _.includes([1, 2, 3], 1);
  8039. * // => true
  8040. *
  8041. * _.includes([1, 2, 3], 1, 2);
  8042. * // => false
  8043. *
  8044. * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
  8045. * // => true
  8046. *
  8047. * _.includes('pebbles', 'eb');
  8048. * // => true
  8049. */
  8050. function includes(collection, target, fromIndex, guard) {
  8051. var length = collection ? getLength(collection) : 0;
  8052. if (!isLength(length)) {
  8053. collection = values(collection);
  8054. length = collection.length;
  8055. }
  8056. if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
  8057. fromIndex = 0;
  8058. } else {
  8059. fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
  8060. }
  8061. return (typeof collection == 'string' || !isArray(collection) && isString(collection))
  8062. ? (fromIndex <= length && collection.indexOf(target, fromIndex) > -1)
  8063. : (!!length && getIndexOf(collection, target, fromIndex) > -1);
  8064. }
  8065. /**
  8066. * Creates an object composed of keys generated from the results of running
  8067. * each element of `collection` through `iteratee`. The corresponding value
  8068. * of each key is the last element responsible for generating the key. The
  8069. * iteratee function is bound to `thisArg` and invoked with three arguments:
  8070. * (value, index|key, collection).
  8071. *
  8072. * If a property name is provided for `iteratee` the created `_.property`
  8073. * style callback returns the property value of the given element.
  8074. *
  8075. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  8076. * style callback returns `true` for elements that have a matching property
  8077. * value, else `false`.
  8078. *
  8079. * If an object is provided for `iteratee` the created `_.matches` style
  8080. * callback returns `true` for elements that have the properties of the given
  8081. * object, else `false`.
  8082. *
  8083. * @static
  8084. * @memberOf _
  8085. * @category Collection
  8086. * @param {Array|Object|string} collection The collection to iterate over.
  8087. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  8088. * per iteration.
  8089. * @param {*} [thisArg] The `this` binding of `iteratee`.
  8090. * @returns {Object} Returns the composed aggregate object.
  8091. * @example
  8092. *
  8093. * var keyData = [
  8094. * { 'dir': 'left', 'code': 97 },
  8095. * { 'dir': 'right', 'code': 100 }
  8096. * ];
  8097. *
  8098. * _.indexBy(keyData, 'dir');
  8099. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8100. *
  8101. * _.indexBy(keyData, function(object) {
  8102. * return String.fromCharCode(object.code);
  8103. * });
  8104. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8105. *
  8106. * _.indexBy(keyData, function(object) {
  8107. * return this.fromCharCode(object.code);
  8108. * }, String);
  8109. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8110. */
  8111. var indexBy = createAggregator(function(result, value, key) {
  8112. result[key] = value;
  8113. });
  8114. /**
  8115. * Invokes the method at `path` of each element in `collection`, returning
  8116. * an array of the results of each invoked method. Any additional arguments
  8117. * are provided to each invoked method. If `methodName` is a function it is
  8118. * invoked for, and `this` bound to, each element in `collection`.
  8119. *
  8120. * @static
  8121. * @memberOf _
  8122. * @category Collection
  8123. * @param {Array|Object|string} collection The collection to iterate over.
  8124. * @param {Array|Function|string} path The path of the method to invoke or
  8125. * the function invoked per iteration.
  8126. * @param {...*} [args] The arguments to invoke the method with.
  8127. * @returns {Array} Returns the array of results.
  8128. * @example
  8129. *
  8130. * _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
  8131. * // => [[1, 5, 7], [1, 2, 3]]
  8132. *
  8133. * _.invoke([123, 456], String.prototype.split, '');
  8134. * // => [['1', '2', '3'], ['4', '5', '6']]
  8135. */
  8136. var invoke = restParam(function(collection, path, args) {
  8137. var index = -1,
  8138. isFunc = typeof path == 'function',
  8139. isProp = isKey(path),
  8140. result = isArrayLike(collection) ? Array(collection.length) : [];
  8141. baseEach(collection, function(value) {
  8142. var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
  8143. result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
  8144. });
  8145. return result;
  8146. });
  8147. /**
  8148. * Creates an array of values by running each element in `collection` through
  8149. * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
  8150. * arguments: (value, index|key, collection).
  8151. *
  8152. * If a property name is provided for `iteratee` the created `_.property`
  8153. * style callback returns the property value of the given element.
  8154. *
  8155. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  8156. * style callback returns `true` for elements that have a matching property
  8157. * value, else `false`.
  8158. *
  8159. * If an object is provided for `iteratee` the created `_.matches` style
  8160. * callback returns `true` for elements that have the properties of the given
  8161. * object, else `false`.
  8162. *
  8163. * Many lodash methods are guarded to work as iteratees for methods like
  8164. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8165. *
  8166. * The guarded methods are:
  8167. * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
  8168. * `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
  8169. * `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
  8170. * `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
  8171. * `sum`, `uniq`, and `words`
  8172. *
  8173. * @static
  8174. * @memberOf _
  8175. * @alias collect
  8176. * @category Collection
  8177. * @param {Array|Object|string} collection The collection to iterate over.
  8178. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  8179. * per iteration.
  8180. * @param {*} [thisArg] The `this` binding of `iteratee`.
  8181. * @returns {Array} Returns the new mapped array.
  8182. * @example
  8183. *
  8184. * function timesThree(n) {
  8185. * return n * 3;
  8186. * }
  8187. *
  8188. * _.map([1, 2], timesThree);
  8189. * // => [3, 6]
  8190. *
  8191. * _.map({ 'a': 1, 'b': 2 }, timesThree);
  8192. * // => [3, 6] (iteration order is not guaranteed)
  8193. *
  8194. * var users = [
  8195. * { 'user': 'barney' },
  8196. * { 'user': 'fred' }
  8197. * ];
  8198. *
  8199. * // using the `_.property` callback shorthand
  8200. * _.map(users, 'user');
  8201. * // => ['barney', 'fred']
  8202. */
  8203. function map(collection, iteratee, thisArg) {
  8204. var func = isArray(collection) ? arrayMap : baseMap;
  8205. iteratee = getCallback(iteratee, thisArg, 3);
  8206. return func(collection, iteratee);
  8207. }
  8208. /**
  8209. * Creates an array of elements split into two groups, the first of which
  8210. * contains elements `predicate` returns truthy for, while the second of which
  8211. * contains elements `predicate` returns falsey for. The predicate is bound
  8212. * to `thisArg` and invoked with three arguments: (value, index|key, collection).
  8213. *
  8214. * If a property name is provided for `predicate` the created `_.property`
  8215. * style callback returns the property value of the given element.
  8216. *
  8217. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  8218. * style callback returns `true` for elements that have a matching property
  8219. * value, else `false`.
  8220. *
  8221. * If an object is provided for `predicate` the created `_.matches` style
  8222. * callback returns `true` for elements that have the properties of the given
  8223. * object, else `false`.
  8224. *
  8225. * @static
  8226. * @memberOf _
  8227. * @category Collection
  8228. * @param {Array|Object|string} collection The collection to iterate over.
  8229. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  8230. * per iteration.
  8231. * @param {*} [thisArg] The `this` binding of `predicate`.
  8232. * @returns {Array} Returns the array of grouped elements.
  8233. * @example
  8234. *
  8235. * _.partition([1, 2, 3], function(n) {
  8236. * return n % 2;
  8237. * });
  8238. * // => [[1, 3], [2]]
  8239. *
  8240. * _.partition([1.2, 2.3, 3.4], function(n) {
  8241. * return this.floor(n) % 2;
  8242. * }, Math);
  8243. * // => [[1.2, 3.4], [2.3]]
  8244. *
  8245. * var users = [
  8246. * { 'user': 'barney', 'age': 36, 'active': false },
  8247. * { 'user': 'fred', 'age': 40, 'active': true },
  8248. * { 'user': 'pebbles', 'age': 1, 'active': false }
  8249. * ];
  8250. *
  8251. * var mapper = function(array) {
  8252. * return _.pluck(array, 'user');
  8253. * };
  8254. *
  8255. * // using the `_.matches` callback shorthand
  8256. * _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
  8257. * // => [['pebbles'], ['barney', 'fred']]
  8258. *
  8259. * // using the `_.matchesProperty` callback shorthand
  8260. * _.map(_.partition(users, 'active', false), mapper);
  8261. * // => [['barney', 'pebbles'], ['fred']]
  8262. *
  8263. * // using the `_.property` callback shorthand
  8264. * _.map(_.partition(users, 'active'), mapper);
  8265. * // => [['fred'], ['barney', 'pebbles']]
  8266. */
  8267. var partition = createAggregator(function(result, value, key) {
  8268. result[key ? 0 : 1].push(value);
  8269. }, function() { return [[], []]; });
  8270. /**
  8271. * Gets the property value of `path` from all elements in `collection`.
  8272. *
  8273. * @static
  8274. * @memberOf _
  8275. * @category Collection
  8276. * @param {Array|Object|string} collection The collection to iterate over.
  8277. * @param {Array|string} path The path of the property to pluck.
  8278. * @returns {Array} Returns the property values.
  8279. * @example
  8280. *
  8281. * var users = [
  8282. * { 'user': 'barney', 'age': 36 },
  8283. * { 'user': 'fred', 'age': 40 }
  8284. * ];
  8285. *
  8286. * _.pluck(users, 'user');
  8287. * // => ['barney', 'fred']
  8288. *
  8289. * var userIndex = _.indexBy(users, 'user');
  8290. * _.pluck(userIndex, 'age');
  8291. * // => [36, 40] (iteration order is not guaranteed)
  8292. */
  8293. function pluck(collection, path) {
  8294. return map(collection, property(path));
  8295. }
  8296. /**
  8297. * Reduces `collection` to a value which is the accumulated result of running
  8298. * each element in `collection` through `iteratee`, where each successive
  8299. * invocation is supplied the return value of the previous. If `accumulator`
  8300. * is not provided the first element of `collection` is used as the initial
  8301. * value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
  8302. * (accumulator, value, index|key, collection).
  8303. *
  8304. * Many lodash methods are guarded to work as iteratees for methods like
  8305. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  8306. *
  8307. * The guarded methods are:
  8308. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `sortByAll`,
  8309. * and `sortByOrder`
  8310. *
  8311. * @static
  8312. * @memberOf _
  8313. * @alias foldl, inject
  8314. * @category Collection
  8315. * @param {Array|Object|string} collection The collection to iterate over.
  8316. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8317. * @param {*} [accumulator] The initial value.
  8318. * @param {*} [thisArg] The `this` binding of `iteratee`.
  8319. * @returns {*} Returns the accumulated value.
  8320. * @example
  8321. *
  8322. * _.reduce([1, 2], function(total, n) {
  8323. * return total + n;
  8324. * });
  8325. * // => 3
  8326. *
  8327. * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
  8328. * result[key] = n * 3;
  8329. * return result;
  8330. * }, {});
  8331. * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
  8332. */
  8333. var reduce = createReduce(arrayReduce, baseEach);
  8334. /**
  8335. * This method is like `_.reduce` except that it iterates over elements of
  8336. * `collection` from right to left.
  8337. *
  8338. * @static
  8339. * @memberOf _
  8340. * @alias foldr
  8341. * @category Collection
  8342. * @param {Array|Object|string} collection The collection to iterate over.
  8343. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8344. * @param {*} [accumulator] The initial value.
  8345. * @param {*} [thisArg] The `this` binding of `iteratee`.
  8346. * @returns {*} Returns the accumulated value.
  8347. * @example
  8348. *
  8349. * var array = [[0, 1], [2, 3], [4, 5]];
  8350. *
  8351. * _.reduceRight(array, function(flattened, other) {
  8352. * return flattened.concat(other);
  8353. * }, []);
  8354. * // => [4, 5, 2, 3, 0, 1]
  8355. */
  8356. var reduceRight = createReduce(arrayReduceRight, baseEachRight);
  8357. /**
  8358. * The opposite of `_.filter`; this method returns the elements of `collection`
  8359. * that `predicate` does **not** return truthy for.
  8360. *
  8361. * @static
  8362. * @memberOf _
  8363. * @category Collection
  8364. * @param {Array|Object|string} collection The collection to iterate over.
  8365. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  8366. * per iteration.
  8367. * @param {*} [thisArg] The `this` binding of `predicate`.
  8368. * @returns {Array} Returns the new filtered array.
  8369. * @example
  8370. *
  8371. * _.reject([1, 2, 3, 4], function(n) {
  8372. * return n % 2 == 0;
  8373. * });
  8374. * // => [1, 3]
  8375. *
  8376. * var users = [
  8377. * { 'user': 'barney', 'age': 36, 'active': false },
  8378. * { 'user': 'fred', 'age': 40, 'active': true }
  8379. * ];
  8380. *
  8381. * // using the `_.matches` callback shorthand
  8382. * _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
  8383. * // => ['barney']
  8384. *
  8385. * // using the `_.matchesProperty` callback shorthand
  8386. * _.pluck(_.reject(users, 'active', false), 'user');
  8387. * // => ['fred']
  8388. *
  8389. * // using the `_.property` callback shorthand
  8390. * _.pluck(_.reject(users, 'active'), 'user');
  8391. * // => ['barney']
  8392. */
  8393. function reject(collection, predicate, thisArg) {
  8394. var func = isArray(collection) ? arrayFilter : baseFilter;
  8395. predicate = getCallback(predicate, thisArg, 3);
  8396. return func(collection, function(value, index, collection) {
  8397. return !predicate(value, index, collection);
  8398. });
  8399. }
  8400. /**
  8401. * Gets a random element or `n` random elements from a collection.
  8402. *
  8403. * @static
  8404. * @memberOf _
  8405. * @category Collection
  8406. * @param {Array|Object|string} collection The collection to sample.
  8407. * @param {number} [n] The number of elements to sample.
  8408. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  8409. * @returns {*} Returns the random sample(s).
  8410. * @example
  8411. *
  8412. * _.sample([1, 2, 3, 4]);
  8413. * // => 2
  8414. *
  8415. * _.sample([1, 2, 3, 4], 2);
  8416. * // => [3, 1]
  8417. */
  8418. function sample(collection, n, guard) {
  8419. if (guard ? isIterateeCall(collection, n, guard) : n == null) {
  8420. collection = toIterable(collection);
  8421. var length = collection.length;
  8422. return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
  8423. }
  8424. var index = -1,
  8425. result = toArray(collection),
  8426. length = result.length,
  8427. lastIndex = length - 1;
  8428. n = nativeMin(n < 0 ? 0 : (+n || 0), length);
  8429. while (++index < n) {
  8430. var rand = baseRandom(index, lastIndex),
  8431. value = result[rand];
  8432. result[rand] = result[index];
  8433. result[index] = value;
  8434. }
  8435. result.length = n;
  8436. return result;
  8437. }
  8438. /**
  8439. * Creates an array of shuffled values, using a version of the
  8440. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  8441. *
  8442. * @static
  8443. * @memberOf _
  8444. * @category Collection
  8445. * @param {Array|Object|string} collection The collection to shuffle.
  8446. * @returns {Array} Returns the new shuffled array.
  8447. * @example
  8448. *
  8449. * _.shuffle([1, 2, 3, 4]);
  8450. * // => [4, 1, 3, 2]
  8451. */
  8452. function shuffle(collection) {
  8453. return sample(collection, POSITIVE_INFINITY);
  8454. }
  8455. /**
  8456. * Gets the size of `collection` by returning its length for array-like
  8457. * values or the number of own enumerable properties for objects.
  8458. *
  8459. * @static
  8460. * @memberOf _
  8461. * @category Collection
  8462. * @param {Array|Object|string} collection The collection to inspect.
  8463. * @returns {number} Returns the size of `collection`.
  8464. * @example
  8465. *
  8466. * _.size([1, 2, 3]);
  8467. * // => 3
  8468. *
  8469. * _.size({ 'a': 1, 'b': 2 });
  8470. * // => 2
  8471. *
  8472. * _.size('pebbles');
  8473. * // => 7
  8474. */
  8475. function size(collection) {
  8476. var length = collection ? getLength(collection) : 0;
  8477. return isLength(length) ? length : keys(collection).length;
  8478. }
  8479. /**
  8480. * Checks if `predicate` returns truthy for **any** element of `collection`.
  8481. * The function returns as soon as it finds a passing value and does not iterate
  8482. * over the entire collection. The predicate is bound to `thisArg` and invoked
  8483. * with three arguments: (value, index|key, collection).
  8484. *
  8485. * If a property name is provided for `predicate` the created `_.property`
  8486. * style callback returns the property value of the given element.
  8487. *
  8488. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  8489. * style callback returns `true` for elements that have a matching property
  8490. * value, else `false`.
  8491. *
  8492. * If an object is provided for `predicate` the created `_.matches` style
  8493. * callback returns `true` for elements that have the properties of the given
  8494. * object, else `false`.
  8495. *
  8496. * @static
  8497. * @memberOf _
  8498. * @alias any
  8499. * @category Collection
  8500. * @param {Array|Object|string} collection The collection to iterate over.
  8501. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  8502. * per iteration.
  8503. * @param {*} [thisArg] The `this` binding of `predicate`.
  8504. * @returns {boolean} Returns `true` if any element passes the predicate check,
  8505. * else `false`.
  8506. * @example
  8507. *
  8508. * _.some([null, 0, 'yes', false], Boolean);
  8509. * // => true
  8510. *
  8511. * var users = [
  8512. * { 'user': 'barney', 'active': true },
  8513. * { 'user': 'fred', 'active': false }
  8514. * ];
  8515. *
  8516. * // using the `_.matches` callback shorthand
  8517. * _.some(users, { 'user': 'barney', 'active': false });
  8518. * // => false
  8519. *
  8520. * // using the `_.matchesProperty` callback shorthand
  8521. * _.some(users, 'active', false);
  8522. * // => true
  8523. *
  8524. * // using the `_.property` callback shorthand
  8525. * _.some(users, 'active');
  8526. * // => true
  8527. */
  8528. function some(collection, predicate, thisArg) {
  8529. var func = isArray(collection) ? arraySome : baseSome;
  8530. if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
  8531. predicate = undefined;
  8532. }
  8533. if (typeof predicate != 'function' || thisArg !== undefined) {
  8534. predicate = getCallback(predicate, thisArg, 3);
  8535. }
  8536. return func(collection, predicate);
  8537. }
  8538. /**
  8539. * Creates an array of elements, sorted in ascending order by the results of
  8540. * running each element in a collection through `iteratee`. This method performs
  8541. * a stable sort, that is, it preserves the original sort order of equal elements.
  8542. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  8543. * (value, index|key, collection).
  8544. *
  8545. * If a property name is provided for `iteratee` the created `_.property`
  8546. * style callback returns the property value of the given element.
  8547. *
  8548. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  8549. * style callback returns `true` for elements that have a matching property
  8550. * value, else `false`.
  8551. *
  8552. * If an object is provided for `iteratee` the created `_.matches` style
  8553. * callback returns `true` for elements that have the properties of the given
  8554. * object, else `false`.
  8555. *
  8556. * @static
  8557. * @memberOf _
  8558. * @category Collection
  8559. * @param {Array|Object|string} collection The collection to iterate over.
  8560. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  8561. * per iteration.
  8562. * @param {*} [thisArg] The `this` binding of `iteratee`.
  8563. * @returns {Array} Returns the new sorted array.
  8564. * @example
  8565. *
  8566. * _.sortBy([1, 2, 3], function(n) {
  8567. * return Math.sin(n);
  8568. * });
  8569. * // => [3, 1, 2]
  8570. *
  8571. * _.sortBy([1, 2, 3], function(n) {
  8572. * return this.sin(n);
  8573. * }, Math);
  8574. * // => [3, 1, 2]
  8575. *
  8576. * var users = [
  8577. * { 'user': 'fred' },
  8578. * { 'user': 'pebbles' },
  8579. * { 'user': 'barney' }
  8580. * ];
  8581. *
  8582. * // using the `_.property` callback shorthand
  8583. * _.pluck(_.sortBy(users, 'user'), 'user');
  8584. * // => ['barney', 'fred', 'pebbles']
  8585. */
  8586. function sortBy(collection, iteratee, thisArg) {
  8587. if (collection == null) {
  8588. return [];
  8589. }
  8590. if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
  8591. iteratee = undefined;
  8592. }
  8593. var index = -1;
  8594. iteratee = getCallback(iteratee, thisArg, 3);
  8595. var result = baseMap(collection, function(value, key, collection) {
  8596. return { 'criteria': iteratee(value, key, collection), 'index': ++index, 'value': value };
  8597. });
  8598. return baseSortBy(result, compareAscending);
  8599. }
  8600. /**
  8601. * This method is like `_.sortBy` except that it can sort by multiple iteratees
  8602. * or property names.
  8603. *
  8604. * If a property name is provided for an iteratee the created `_.property`
  8605. * style callback returns the property value of the given element.
  8606. *
  8607. * If an object is provided for an iteratee the created `_.matches` style
  8608. * callback returns `true` for elements that have the properties of the given
  8609. * object, else `false`.
  8610. *
  8611. * @static
  8612. * @memberOf _
  8613. * @category Collection
  8614. * @param {Array|Object|string} collection The collection to iterate over.
  8615. * @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees
  8616. * The iteratees to sort by, specified as individual values or arrays of values.
  8617. * @returns {Array} Returns the new sorted array.
  8618. * @example
  8619. *
  8620. * var users = [
  8621. * { 'user': 'fred', 'age': 48 },
  8622. * { 'user': 'barney', 'age': 36 },
  8623. * { 'user': 'fred', 'age': 42 },
  8624. * { 'user': 'barney', 'age': 34 }
  8625. * ];
  8626. *
  8627. * _.map(_.sortByAll(users, ['user', 'age']), _.values);
  8628. * // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
  8629. *
  8630. * _.map(_.sortByAll(users, 'user', function(chr) {
  8631. * return Math.floor(chr.age / 10);
  8632. * }), _.values);
  8633. * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
  8634. */
  8635. var sortByAll = restParam(function(collection, iteratees) {
  8636. if (collection == null) {
  8637. return [];
  8638. }
  8639. var guard = iteratees[2];
  8640. if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {
  8641. iteratees.length = 1;
  8642. }
  8643. return baseSortByOrder(collection, baseFlatten(iteratees), []);
  8644. });
  8645. /**
  8646. * This method is like `_.sortByAll` except that it allows specifying the
  8647. * sort orders of the iteratees to sort by. If `orders` is unspecified, all
  8648. * values are sorted in ascending order. Otherwise, a value is sorted in
  8649. * ascending order if its corresponding order is "asc", and descending if "desc".
  8650. *
  8651. * If a property name is provided for an iteratee the created `_.property`
  8652. * style callback returns the property value of the given element.
  8653. *
  8654. * If an object is provided for an iteratee the created `_.matches` style
  8655. * callback returns `true` for elements that have the properties of the given
  8656. * object, else `false`.
  8657. *
  8658. * @static
  8659. * @memberOf _
  8660. * @category Collection
  8661. * @param {Array|Object|string} collection The collection to iterate over.
  8662. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  8663. * @param {boolean[]} [orders] The sort orders of `iteratees`.
  8664. * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
  8665. * @returns {Array} Returns the new sorted array.
  8666. * @example
  8667. *
  8668. * var users = [
  8669. * { 'user': 'fred', 'age': 48 },
  8670. * { 'user': 'barney', 'age': 34 },
  8671. * { 'user': 'fred', 'age': 42 },
  8672. * { 'user': 'barney', 'age': 36 }
  8673. * ];
  8674. *
  8675. * // sort by `user` in ascending order and by `age` in descending order
  8676. * _.map(_.sortByOrder(users, ['user', 'age'], ['asc', 'desc']), _.values);
  8677. * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
  8678. */
  8679. function sortByOrder(collection, iteratees, orders, guard) {
  8680. if (collection == null) {
  8681. return [];
  8682. }
  8683. if (guard && isIterateeCall(iteratees, orders, guard)) {
  8684. orders = undefined;
  8685. }
  8686. if (!isArray(iteratees)) {
  8687. iteratees = iteratees == null ? [] : [iteratees];
  8688. }
  8689. if (!isArray(orders)) {
  8690. orders = orders == null ? [] : [orders];
  8691. }
  8692. return baseSortByOrder(collection, iteratees, orders);
  8693. }
  8694. /**
  8695. * Performs a deep comparison between each element in `collection` and the
  8696. * source object, returning an array of all elements that have equivalent
  8697. * property values.
  8698. *
  8699. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  8700. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  8701. * their own, not inherited, enumerable properties. For comparing a single
  8702. * own or inherited property value see `_.matchesProperty`.
  8703. *
  8704. * @static
  8705. * @memberOf _
  8706. * @category Collection
  8707. * @param {Array|Object|string} collection The collection to search.
  8708. * @param {Object} source The object of property values to match.
  8709. * @returns {Array} Returns the new filtered array.
  8710. * @example
  8711. *
  8712. * var users = [
  8713. * { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] },
  8714. * { 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] }
  8715. * ];
  8716. *
  8717. * _.pluck(_.where(users, { 'age': 36, 'active': false }), 'user');
  8718. * // => ['barney']
  8719. *
  8720. * _.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
  8721. * // => ['fred']
  8722. */
  8723. function where(collection, source) {
  8724. return filter(collection, baseMatches(source));
  8725. }
  8726. /*------------------------------------------------------------------------*/
  8727. /**
  8728. * Gets the number of milliseconds that have elapsed since the Unix epoch
  8729. * (1 January 1970 00:00:00 UTC).
  8730. *
  8731. * @static
  8732. * @memberOf _
  8733. * @category Date
  8734. * @example
  8735. *
  8736. * _.defer(function(stamp) {
  8737. * console.log(_.now() - stamp);
  8738. * }, _.now());
  8739. * // => logs the number of milliseconds it took for the deferred function to be invoked
  8740. */
  8741. var now = nativeNow || function() {
  8742. return new Date().getTime();
  8743. };
  8744. /*------------------------------------------------------------------------*/
  8745. /**
  8746. * The opposite of `_.before`; this method creates a function that invokes
  8747. * `func` once it is called `n` or more times.
  8748. *
  8749. * @static
  8750. * @memberOf _
  8751. * @category Function
  8752. * @param {number} n The number of calls before `func` is invoked.
  8753. * @param {Function} func The function to restrict.
  8754. * @returns {Function} Returns the new restricted function.
  8755. * @example
  8756. *
  8757. * var saves = ['profile', 'settings'];
  8758. *
  8759. * var done = _.after(saves.length, function() {
  8760. * console.log('done saving!');
  8761. * });
  8762. *
  8763. * _.forEach(saves, function(type) {
  8764. * asyncSave({ 'type': type, 'complete': done });
  8765. * });
  8766. * // => logs 'done saving!' after the two async saves have completed
  8767. */
  8768. function after(n, func) {
  8769. if (typeof func != 'function') {
  8770. if (typeof n == 'function') {
  8771. var temp = n;
  8772. n = func;
  8773. func = temp;
  8774. } else {
  8775. throw new TypeError(FUNC_ERROR_TEXT);
  8776. }
  8777. }
  8778. n = nativeIsFinite(n = +n) ? n : 0;
  8779. return function() {
  8780. if (--n < 1) {
  8781. return func.apply(this, arguments);
  8782. }
  8783. };
  8784. }
  8785. /**
  8786. * Creates a function that accepts up to `n` arguments ignoring any
  8787. * additional arguments.
  8788. *
  8789. * @static
  8790. * @memberOf _
  8791. * @category Function
  8792. * @param {Function} func The function to cap arguments for.
  8793. * @param {number} [n=func.length] The arity cap.
  8794. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  8795. * @returns {Function} Returns the new function.
  8796. * @example
  8797. *
  8798. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  8799. * // => [6, 8, 10]
  8800. */
  8801. function ary(func, n, guard) {
  8802. if (guard && isIterateeCall(func, n, guard)) {
  8803. n = undefined;
  8804. }
  8805. n = (func && n == null) ? func.length : nativeMax(+n || 0, 0);
  8806. return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
  8807. }
  8808. /**
  8809. * Creates a function that invokes `func`, with the `this` binding and arguments
  8810. * of the created function, while it is called less than `n` times. Subsequent
  8811. * calls to the created function return the result of the last `func` invocation.
  8812. *
  8813. * @static
  8814. * @memberOf _
  8815. * @category Function
  8816. * @param {number} n The number of calls at which `func` is no longer invoked.
  8817. * @param {Function} func The function to restrict.
  8818. * @returns {Function} Returns the new restricted function.
  8819. * @example
  8820. *
  8821. * jQuery('#add').on('click', _.before(5, addContactToList));
  8822. * // => allows adding up to 4 contacts to the list
  8823. */
  8824. function before(n, func) {
  8825. var result;
  8826. if (typeof func != 'function') {
  8827. if (typeof n == 'function') {
  8828. var temp = n;
  8829. n = func;
  8830. func = temp;
  8831. } else {
  8832. throw new TypeError(FUNC_ERROR_TEXT);
  8833. }
  8834. }
  8835. return function() {
  8836. if (--n > 0) {
  8837. result = func.apply(this, arguments);
  8838. }
  8839. if (n <= 1) {
  8840. func = undefined;
  8841. }
  8842. return result;
  8843. };
  8844. }
  8845. /**
  8846. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  8847. * and prepends any additional `_.bind` arguments to those provided to the
  8848. * bound function.
  8849. *
  8850. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  8851. * may be used as a placeholder for partially applied arguments.
  8852. *
  8853. * **Note:** Unlike native `Function#bind` this method does not set the "length"
  8854. * property of bound functions.
  8855. *
  8856. * @static
  8857. * @memberOf _
  8858. * @category Function
  8859. * @param {Function} func The function to bind.
  8860. * @param {*} thisArg The `this` binding of `func`.
  8861. * @param {...*} [partials] The arguments to be partially applied.
  8862. * @returns {Function} Returns the new bound function.
  8863. * @example
  8864. *
  8865. * var greet = function(greeting, punctuation) {
  8866. * return greeting + ' ' + this.user + punctuation;
  8867. * };
  8868. *
  8869. * var object = { 'user': 'fred' };
  8870. *
  8871. * var bound = _.bind(greet, object, 'hi');
  8872. * bound('!');
  8873. * // => 'hi fred!'
  8874. *
  8875. * // using placeholders
  8876. * var bound = _.bind(greet, object, _, '!');
  8877. * bound('hi');
  8878. * // => 'hi fred!'
  8879. */
  8880. var bind = restParam(function(func, thisArg, partials) {
  8881. var bitmask = BIND_FLAG;
  8882. if (partials.length) {
  8883. var holders = replaceHolders(partials, bind.placeholder);
  8884. bitmask |= PARTIAL_FLAG;
  8885. }
  8886. return createWrapper(func, bitmask, thisArg, partials, holders);
  8887. });
  8888. /**
  8889. * Binds methods of an object to the object itself, overwriting the existing
  8890. * method. Method names may be specified as individual arguments or as arrays
  8891. * of method names. If no method names are provided all enumerable function
  8892. * properties, own and inherited, of `object` are bound.
  8893. *
  8894. * **Note:** This method does not set the "length" property of bound functions.
  8895. *
  8896. * @static
  8897. * @memberOf _
  8898. * @category Function
  8899. * @param {Object} object The object to bind and assign the bound methods to.
  8900. * @param {...(string|string[])} [methodNames] The object method names to bind,
  8901. * specified as individual method names or arrays of method names.
  8902. * @returns {Object} Returns `object`.
  8903. * @example
  8904. *
  8905. * var view = {
  8906. * 'label': 'docs',
  8907. * 'onClick': function() {
  8908. * console.log('clicked ' + this.label);
  8909. * }
  8910. * };
  8911. *
  8912. * _.bindAll(view);
  8913. * jQuery('#docs').on('click', view.onClick);
  8914. * // => logs 'clicked docs' when the element is clicked
  8915. */
  8916. var bindAll = restParam(function(object, methodNames) {
  8917. methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object);
  8918. var index = -1,
  8919. length = methodNames.length;
  8920. while (++index < length) {
  8921. var key = methodNames[index];
  8922. object[key] = createWrapper(object[key], BIND_FLAG, object);
  8923. }
  8924. return object;
  8925. });
  8926. /**
  8927. * Creates a function that invokes the method at `object[key]` and prepends
  8928. * any additional `_.bindKey` arguments to those provided to the bound function.
  8929. *
  8930. * This method differs from `_.bind` by allowing bound functions to reference
  8931. * methods that may be redefined or don't yet exist.
  8932. * See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  8933. * for more details.
  8934. *
  8935. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  8936. * builds, may be used as a placeholder for partially applied arguments.
  8937. *
  8938. * @static
  8939. * @memberOf _
  8940. * @category Function
  8941. * @param {Object} object The object the method belongs to.
  8942. * @param {string} key The key of the method.
  8943. * @param {...*} [partials] The arguments to be partially applied.
  8944. * @returns {Function} Returns the new bound function.
  8945. * @example
  8946. *
  8947. * var object = {
  8948. * 'user': 'fred',
  8949. * 'greet': function(greeting, punctuation) {
  8950. * return greeting + ' ' + this.user + punctuation;
  8951. * }
  8952. * };
  8953. *
  8954. * var bound = _.bindKey(object, 'greet', 'hi');
  8955. * bound('!');
  8956. * // => 'hi fred!'
  8957. *
  8958. * object.greet = function(greeting, punctuation) {
  8959. * return greeting + 'ya ' + this.user + punctuation;
  8960. * };
  8961. *
  8962. * bound('!');
  8963. * // => 'hiya fred!'
  8964. *
  8965. * // using placeholders
  8966. * var bound = _.bindKey(object, 'greet', _, '!');
  8967. * bound('hi');
  8968. * // => 'hiya fred!'
  8969. */
  8970. var bindKey = restParam(function(object, key, partials) {
  8971. var bitmask = BIND_FLAG | BIND_KEY_FLAG;
  8972. if (partials.length) {
  8973. var holders = replaceHolders(partials, bindKey.placeholder);
  8974. bitmask |= PARTIAL_FLAG;
  8975. }
  8976. return createWrapper(key, bitmask, object, partials, holders);
  8977. });
  8978. /**
  8979. * Creates a function that accepts one or more arguments of `func` that when
  8980. * called either invokes `func` returning its result, if all `func` arguments
  8981. * have been provided, or returns a function that accepts one or more of the
  8982. * remaining `func` arguments, and so on. The arity of `func` may be specified
  8983. * if `func.length` is not sufficient.
  8984. *
  8985. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  8986. * may be used as a placeholder for provided arguments.
  8987. *
  8988. * **Note:** This method does not set the "length" property of curried functions.
  8989. *
  8990. * @static
  8991. * @memberOf _
  8992. * @category Function
  8993. * @param {Function} func The function to curry.
  8994. * @param {number} [arity=func.length] The arity of `func`.
  8995. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  8996. * @returns {Function} Returns the new curried function.
  8997. * @example
  8998. *
  8999. * var abc = function(a, b, c) {
  9000. * return [a, b, c];
  9001. * };
  9002. *
  9003. * var curried = _.curry(abc);
  9004. *
  9005. * curried(1)(2)(3);
  9006. * // => [1, 2, 3]
  9007. *
  9008. * curried(1, 2)(3);
  9009. * // => [1, 2, 3]
  9010. *
  9011. * curried(1, 2, 3);
  9012. * // => [1, 2, 3]
  9013. *
  9014. * // using placeholders
  9015. * curried(1)(_, 3)(2);
  9016. * // => [1, 2, 3]
  9017. */
  9018. var curry = createCurry(CURRY_FLAG);
  9019. /**
  9020. * This method is like `_.curry` except that arguments are applied to `func`
  9021. * in the manner of `_.partialRight` instead of `_.partial`.
  9022. *
  9023. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9024. * builds, may be used as a placeholder for provided arguments.
  9025. *
  9026. * **Note:** This method does not set the "length" property of curried functions.
  9027. *
  9028. * @static
  9029. * @memberOf _
  9030. * @category Function
  9031. * @param {Function} func The function to curry.
  9032. * @param {number} [arity=func.length] The arity of `func`.
  9033. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  9034. * @returns {Function} Returns the new curried function.
  9035. * @example
  9036. *
  9037. * var abc = function(a, b, c) {
  9038. * return [a, b, c];
  9039. * };
  9040. *
  9041. * var curried = _.curryRight(abc);
  9042. *
  9043. * curried(3)(2)(1);
  9044. * // => [1, 2, 3]
  9045. *
  9046. * curried(2, 3)(1);
  9047. * // => [1, 2, 3]
  9048. *
  9049. * curried(1, 2, 3);
  9050. * // => [1, 2, 3]
  9051. *
  9052. * // using placeholders
  9053. * curried(3)(1, _)(2);
  9054. * // => [1, 2, 3]
  9055. */
  9056. var curryRight = createCurry(CURRY_RIGHT_FLAG);
  9057. /**
  9058. * Creates a debounced function that delays invoking `func` until after `wait`
  9059. * milliseconds have elapsed since the last time the debounced function was
  9060. * invoked. The debounced function comes with a `cancel` method to cancel
  9061. * delayed invocations. Provide an options object to indicate that `func`
  9062. * should be invoked on the leading and/or trailing edge of the `wait` timeout.
  9063. * Subsequent calls to the debounced function return the result of the last
  9064. * `func` invocation.
  9065. *
  9066. * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
  9067. * on the trailing edge of the timeout only if the the debounced function is
  9068. * invoked more than once during the `wait` timeout.
  9069. *
  9070. * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
  9071. * for details over the differences between `_.debounce` and `_.throttle`.
  9072. *
  9073. * @static
  9074. * @memberOf _
  9075. * @category Function
  9076. * @param {Function} func The function to debounce.
  9077. * @param {number} [wait=0] The number of milliseconds to delay.
  9078. * @param {Object} [options] The options object.
  9079. * @param {boolean} [options.leading=false] Specify invoking on the leading
  9080. * edge of the timeout.
  9081. * @param {number} [options.maxWait] The maximum time `func` is allowed to be
  9082. * delayed before it is invoked.
  9083. * @param {boolean} [options.trailing=true] Specify invoking on the trailing
  9084. * edge of the timeout.
  9085. * @returns {Function} Returns the new debounced function.
  9086. * @example
  9087. *
  9088. * // avoid costly calculations while the window size is in flux
  9089. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9090. *
  9091. * // invoke `sendMail` when the click event is fired, debouncing subsequent calls
  9092. * jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
  9093. * 'leading': true,
  9094. * 'trailing': false
  9095. * }));
  9096. *
  9097. * // ensure `batchLog` is invoked once after 1 second of debounced calls
  9098. * var source = new EventSource('/stream');
  9099. * jQuery(source).on('message', _.debounce(batchLog, 250, {
  9100. * 'maxWait': 1000
  9101. * }));
  9102. *
  9103. * // cancel a debounced call
  9104. * var todoChanges = _.debounce(batchLog, 1000);
  9105. * Object.observe(models.todo, todoChanges);
  9106. *
  9107. * Object.observe(models, function(changes) {
  9108. * if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
  9109. * todoChanges.cancel();
  9110. * }
  9111. * }, ['delete']);
  9112. *
  9113. * // ...at some point `models.todo` is changed
  9114. * models.todo.completed = true;
  9115. *
  9116. * // ...before 1 second has passed `models.todo` is deleted
  9117. * // which cancels the debounced `todoChanges` call
  9118. * delete models.todo;
  9119. */
  9120. function debounce(func, wait, options) {
  9121. var args,
  9122. maxTimeoutId,
  9123. result,
  9124. stamp,
  9125. thisArg,
  9126. timeoutId,
  9127. trailingCall,
  9128. lastCalled = 0,
  9129. maxWait = false,
  9130. trailing = true;
  9131. if (typeof func != 'function') {
  9132. throw new TypeError(FUNC_ERROR_TEXT);
  9133. }
  9134. wait = wait < 0 ? 0 : (+wait || 0);
  9135. if (options === true) {
  9136. var leading = true;
  9137. trailing = false;
  9138. } else if (isObject(options)) {
  9139. leading = !!options.leading;
  9140. maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
  9141. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9142. }
  9143. function cancel() {
  9144. if (timeoutId) {
  9145. clearTimeout(timeoutId);
  9146. }
  9147. if (maxTimeoutId) {
  9148. clearTimeout(maxTimeoutId);
  9149. }
  9150. lastCalled = 0;
  9151. maxTimeoutId = timeoutId = trailingCall = undefined;
  9152. }
  9153. function complete(isCalled, id) {
  9154. if (id) {
  9155. clearTimeout(id);
  9156. }
  9157. maxTimeoutId = timeoutId = trailingCall = undefined;
  9158. if (isCalled) {
  9159. lastCalled = now();
  9160. result = func.apply(thisArg, args);
  9161. if (!timeoutId && !maxTimeoutId) {
  9162. args = thisArg = undefined;
  9163. }
  9164. }
  9165. }
  9166. function delayed() {
  9167. var remaining = wait - (now() - stamp);
  9168. if (remaining <= 0 || remaining > wait) {
  9169. complete(trailingCall, maxTimeoutId);
  9170. } else {
  9171. timeoutId = setTimeout(delayed, remaining);
  9172. }
  9173. }
  9174. function maxDelayed() {
  9175. complete(trailing, timeoutId);
  9176. }
  9177. function debounced() {
  9178. args = arguments;
  9179. stamp = now();
  9180. thisArg = this;
  9181. trailingCall = trailing && (timeoutId || !leading);
  9182. if (maxWait === false) {
  9183. var leadingCall = leading && !timeoutId;
  9184. } else {
  9185. if (!maxTimeoutId && !leading) {
  9186. lastCalled = stamp;
  9187. }
  9188. var remaining = maxWait - (stamp - lastCalled),
  9189. isCalled = remaining <= 0 || remaining > maxWait;
  9190. if (isCalled) {
  9191. if (maxTimeoutId) {
  9192. maxTimeoutId = clearTimeout(maxTimeoutId);
  9193. }
  9194. lastCalled = stamp;
  9195. result = func.apply(thisArg, args);
  9196. }
  9197. else if (!maxTimeoutId) {
  9198. maxTimeoutId = setTimeout(maxDelayed, remaining);
  9199. }
  9200. }
  9201. if (isCalled && timeoutId) {
  9202. timeoutId = clearTimeout(timeoutId);
  9203. }
  9204. else if (!timeoutId && wait !== maxWait) {
  9205. timeoutId = setTimeout(delayed, wait);
  9206. }
  9207. if (leadingCall) {
  9208. isCalled = true;
  9209. result = func.apply(thisArg, args);
  9210. }
  9211. if (isCalled && !timeoutId && !maxTimeoutId) {
  9212. args = thisArg = undefined;
  9213. }
  9214. return result;
  9215. }
  9216. debounced.cancel = cancel;
  9217. return debounced;
  9218. }
  9219. /**
  9220. * Defers invoking the `func` until the current call stack has cleared. Any
  9221. * additional arguments are provided to `func` when it is invoked.
  9222. *
  9223. * @static
  9224. * @memberOf _
  9225. * @category Function
  9226. * @param {Function} func The function to defer.
  9227. * @param {...*} [args] The arguments to invoke the function with.
  9228. * @returns {number} Returns the timer id.
  9229. * @example
  9230. *
  9231. * _.defer(function(text) {
  9232. * console.log(text);
  9233. * }, 'deferred');
  9234. * // logs 'deferred' after one or more milliseconds
  9235. */
  9236. var defer = restParam(function(func, args) {
  9237. return baseDelay(func, 1, args);
  9238. });
  9239. /**
  9240. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9241. * provided to `func` when it is invoked.
  9242. *
  9243. * @static
  9244. * @memberOf _
  9245. * @category Function
  9246. * @param {Function} func The function to delay.
  9247. * @param {number} wait The number of milliseconds to delay invocation.
  9248. * @param {...*} [args] The arguments to invoke the function with.
  9249. * @returns {number} Returns the timer id.
  9250. * @example
  9251. *
  9252. * _.delay(function(text) {
  9253. * console.log(text);
  9254. * }, 1000, 'later');
  9255. * // => logs 'later' after one second
  9256. */
  9257. var delay = restParam(function(func, wait, args) {
  9258. return baseDelay(func, wait, args);
  9259. });
  9260. /**
  9261. * Creates a function that returns the result of invoking the provided
  9262. * functions with the `this` binding of the created function, where each
  9263. * successive invocation is supplied the return value of the previous.
  9264. *
  9265. * @static
  9266. * @memberOf _
  9267. * @category Function
  9268. * @param {...Function} [funcs] Functions to invoke.
  9269. * @returns {Function} Returns the new function.
  9270. * @example
  9271. *
  9272. * function square(n) {
  9273. * return n * n;
  9274. * }
  9275. *
  9276. * var addSquare = _.flow(_.add, square);
  9277. * addSquare(1, 2);
  9278. * // => 9
  9279. */
  9280. var flow = createFlow();
  9281. /**
  9282. * This method is like `_.flow` except that it creates a function that
  9283. * invokes the provided functions from right to left.
  9284. *
  9285. * @static
  9286. * @memberOf _
  9287. * @alias backflow, compose
  9288. * @category Function
  9289. * @param {...Function} [funcs] Functions to invoke.
  9290. * @returns {Function} Returns the new function.
  9291. * @example
  9292. *
  9293. * function square(n) {
  9294. * return n * n;
  9295. * }
  9296. *
  9297. * var addSquare = _.flowRight(square, _.add);
  9298. * addSquare(1, 2);
  9299. * // => 9
  9300. */
  9301. var flowRight = createFlow(true);
  9302. /**
  9303. * Creates a function that memoizes the result of `func`. If `resolver` is
  9304. * provided it determines the cache key for storing the result based on the
  9305. * arguments provided to the memoized function. By default, the first argument
  9306. * provided to the memoized function is coerced to a string and used as the
  9307. * cache key. The `func` is invoked with the `this` binding of the memoized
  9308. * function.
  9309. *
  9310. * **Note:** The cache is exposed as the `cache` property on the memoized
  9311. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9312. * constructor with one whose instances implement the [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
  9313. * method interface of `get`, `has`, and `set`.
  9314. *
  9315. * @static
  9316. * @memberOf _
  9317. * @category Function
  9318. * @param {Function} func The function to have its output memoized.
  9319. * @param {Function} [resolver] The function to resolve the cache key.
  9320. * @returns {Function} Returns the new memoizing function.
  9321. * @example
  9322. *
  9323. * var upperCase = _.memoize(function(string) {
  9324. * return string.toUpperCase();
  9325. * });
  9326. *
  9327. * upperCase('fred');
  9328. * // => 'FRED'
  9329. *
  9330. * // modifying the result cache
  9331. * upperCase.cache.set('fred', 'BARNEY');
  9332. * upperCase('fred');
  9333. * // => 'BARNEY'
  9334. *
  9335. * // replacing `_.memoize.Cache`
  9336. * var object = { 'user': 'fred' };
  9337. * var other = { 'user': 'barney' };
  9338. * var identity = _.memoize(_.identity);
  9339. *
  9340. * identity(object);
  9341. * // => { 'user': 'fred' }
  9342. * identity(other);
  9343. * // => { 'user': 'fred' }
  9344. *
  9345. * _.memoize.Cache = WeakMap;
  9346. * var identity = _.memoize(_.identity);
  9347. *
  9348. * identity(object);
  9349. * // => { 'user': 'fred' }
  9350. * identity(other);
  9351. * // => { 'user': 'barney' }
  9352. */
  9353. function memoize(func, resolver) {
  9354. if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
  9355. throw new TypeError(FUNC_ERROR_TEXT);
  9356. }
  9357. var memoized = function() {
  9358. var args = arguments,
  9359. key = resolver ? resolver.apply(this, args) : args[0],
  9360. cache = memoized.cache;
  9361. if (cache.has(key)) {
  9362. return cache.get(key);
  9363. }
  9364. var result = func.apply(this, args);
  9365. memoized.cache = cache.set(key, result);
  9366. return result;
  9367. };
  9368. memoized.cache = new memoize.Cache;
  9369. return memoized;
  9370. }
  9371. /**
  9372. * Creates a function that runs each argument through a corresponding
  9373. * transform function.
  9374. *
  9375. * @static
  9376. * @memberOf _
  9377. * @category Function
  9378. * @param {Function} func The function to wrap.
  9379. * @param {...(Function|Function[])} [transforms] The functions to transform
  9380. * arguments, specified as individual functions or arrays of functions.
  9381. * @returns {Function} Returns the new function.
  9382. * @example
  9383. *
  9384. * function doubled(n) {
  9385. * return n * 2;
  9386. * }
  9387. *
  9388. * function square(n) {
  9389. * return n * n;
  9390. * }
  9391. *
  9392. * var modded = _.modArgs(function(x, y) {
  9393. * return [x, y];
  9394. * }, square, doubled);
  9395. *
  9396. * modded(1, 2);
  9397. * // => [1, 4]
  9398. *
  9399. * modded(5, 10);
  9400. * // => [25, 20]
  9401. */
  9402. var modArgs = restParam(function(func, transforms) {
  9403. transforms = baseFlatten(transforms);
  9404. if (typeof func != 'function' || !arrayEvery(transforms, baseIsFunction)) {
  9405. throw new TypeError(FUNC_ERROR_TEXT);
  9406. }
  9407. var length = transforms.length;
  9408. return restParam(function(args) {
  9409. var index = nativeMin(args.length, length);
  9410. while (index--) {
  9411. args[index] = transforms[index](args[index]);
  9412. }
  9413. return func.apply(this, args);
  9414. });
  9415. });
  9416. /**
  9417. * Creates a function that negates the result of the predicate `func`. The
  9418. * `func` predicate is invoked with the `this` binding and arguments of the
  9419. * created function.
  9420. *
  9421. * @static
  9422. * @memberOf _
  9423. * @category Function
  9424. * @param {Function} predicate The predicate to negate.
  9425. * @returns {Function} Returns the new function.
  9426. * @example
  9427. *
  9428. * function isEven(n) {
  9429. * return n % 2 == 0;
  9430. * }
  9431. *
  9432. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9433. * // => [1, 3, 5]
  9434. */
  9435. function negate(predicate) {
  9436. if (typeof predicate != 'function') {
  9437. throw new TypeError(FUNC_ERROR_TEXT);
  9438. }
  9439. return function() {
  9440. return !predicate.apply(this, arguments);
  9441. };
  9442. }
  9443. /**
  9444. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9445. * to the function return the value of the first call. The `func` is invoked
  9446. * with the `this` binding and arguments of the created function.
  9447. *
  9448. * @static
  9449. * @memberOf _
  9450. * @category Function
  9451. * @param {Function} func The function to restrict.
  9452. * @returns {Function} Returns the new restricted function.
  9453. * @example
  9454. *
  9455. * var initialize = _.once(createApplication);
  9456. * initialize();
  9457. * initialize();
  9458. * // `initialize` invokes `createApplication` once
  9459. */
  9460. function once(func) {
  9461. return before(2, func);
  9462. }
  9463. /**
  9464. * Creates a function that invokes `func` with `partial` arguments prepended
  9465. * to those provided to the new function. This method is like `_.bind` except
  9466. * it does **not** alter the `this` binding.
  9467. *
  9468. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  9469. * builds, may be used as a placeholder for partially applied arguments.
  9470. *
  9471. * **Note:** This method does not set the "length" property of partially
  9472. * applied functions.
  9473. *
  9474. * @static
  9475. * @memberOf _
  9476. * @category Function
  9477. * @param {Function} func The function to partially apply arguments to.
  9478. * @param {...*} [partials] The arguments to be partially applied.
  9479. * @returns {Function} Returns the new partially applied function.
  9480. * @example
  9481. *
  9482. * var greet = function(greeting, name) {
  9483. * return greeting + ' ' + name;
  9484. * };
  9485. *
  9486. * var sayHelloTo = _.partial(greet, 'hello');
  9487. * sayHelloTo('fred');
  9488. * // => 'hello fred'
  9489. *
  9490. * // using placeholders
  9491. * var greetFred = _.partial(greet, _, 'fred');
  9492. * greetFred('hi');
  9493. * // => 'hi fred'
  9494. */
  9495. var partial = createPartial(PARTIAL_FLAG);
  9496. /**
  9497. * This method is like `_.partial` except that partially applied arguments
  9498. * are appended to those provided to the new function.
  9499. *
  9500. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  9501. * builds, may be used as a placeholder for partially applied arguments.
  9502. *
  9503. * **Note:** This method does not set the "length" property of partially
  9504. * applied functions.
  9505. *
  9506. * @static
  9507. * @memberOf _
  9508. * @category Function
  9509. * @param {Function} func The function to partially apply arguments to.
  9510. * @param {...*} [partials] The arguments to be partially applied.
  9511. * @returns {Function} Returns the new partially applied function.
  9512. * @example
  9513. *
  9514. * var greet = function(greeting, name) {
  9515. * return greeting + ' ' + name;
  9516. * };
  9517. *
  9518. * var greetFred = _.partialRight(greet, 'fred');
  9519. * greetFred('hi');
  9520. * // => 'hi fred'
  9521. *
  9522. * // using placeholders
  9523. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  9524. * sayHelloTo('fred');
  9525. * // => 'hello fred'
  9526. */
  9527. var partialRight = createPartial(PARTIAL_RIGHT_FLAG);
  9528. /**
  9529. * Creates a function that invokes `func` with arguments arranged according
  9530. * to the specified indexes where the argument value at the first index is
  9531. * provided as the first argument, the argument value at the second index is
  9532. * provided as the second argument, and so on.
  9533. *
  9534. * @static
  9535. * @memberOf _
  9536. * @category Function
  9537. * @param {Function} func The function to rearrange arguments for.
  9538. * @param {...(number|number[])} indexes The arranged argument indexes,
  9539. * specified as individual indexes or arrays of indexes.
  9540. * @returns {Function} Returns the new function.
  9541. * @example
  9542. *
  9543. * var rearged = _.rearg(function(a, b, c) {
  9544. * return [a, b, c];
  9545. * }, 2, 0, 1);
  9546. *
  9547. * rearged('b', 'c', 'a')
  9548. * // => ['a', 'b', 'c']
  9549. *
  9550. * var map = _.rearg(_.map, [1, 0]);
  9551. * map(function(n) {
  9552. * return n * 3;
  9553. * }, [1, 2, 3]);
  9554. * // => [3, 6, 9]
  9555. */
  9556. var rearg = restParam(function(func, indexes) {
  9557. return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes));
  9558. });
  9559. /**
  9560. * Creates a function that invokes `func` with the `this` binding of the
  9561. * created function and arguments from `start` and beyond provided as an array.
  9562. *
  9563. * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
  9564. *
  9565. * @static
  9566. * @memberOf _
  9567. * @category Function
  9568. * @param {Function} func The function to apply a rest parameter to.
  9569. * @param {number} [start=func.length-1] The start position of the rest parameter.
  9570. * @returns {Function} Returns the new function.
  9571. * @example
  9572. *
  9573. * var say = _.restParam(function(what, names) {
  9574. * return what + ' ' + _.initial(names).join(', ') +
  9575. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  9576. * });
  9577. *
  9578. * say('hello', 'fred', 'barney', 'pebbles');
  9579. * // => 'hello fred, barney, & pebbles'
  9580. */
  9581. function restParam(func, start) {
  9582. if (typeof func != 'function') {
  9583. throw new TypeError(FUNC_ERROR_TEXT);
  9584. }
  9585. start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
  9586. return function() {
  9587. var args = arguments,
  9588. index = -1,
  9589. length = nativeMax(args.length - start, 0),
  9590. rest = Array(length);
  9591. while (++index < length) {
  9592. rest[index] = args[start + index];
  9593. }
  9594. switch (start) {
  9595. case 0: return func.call(this, rest);
  9596. case 1: return func.call(this, args[0], rest);
  9597. case 2: return func.call(this, args[0], args[1], rest);
  9598. }
  9599. var otherArgs = Array(start + 1);
  9600. index = -1;
  9601. while (++index < start) {
  9602. otherArgs[index] = args[index];
  9603. }
  9604. otherArgs[start] = rest;
  9605. return func.apply(this, otherArgs);
  9606. };
  9607. }
  9608. /**
  9609. * Creates a function that invokes `func` with the `this` binding of the created
  9610. * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
  9611. *
  9612. * **Note:** This method is based on the [spread operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator).
  9613. *
  9614. * @static
  9615. * @memberOf _
  9616. * @category Function
  9617. * @param {Function} func The function to spread arguments over.
  9618. * @returns {Function} Returns the new function.
  9619. * @example
  9620. *
  9621. * var say = _.spread(function(who, what) {
  9622. * return who + ' says ' + what;
  9623. * });
  9624. *
  9625. * say(['fred', 'hello']);
  9626. * // => 'fred says hello'
  9627. *
  9628. * // with a Promise
  9629. * var numbers = Promise.all([
  9630. * Promise.resolve(40),
  9631. * Promise.resolve(36)
  9632. * ]);
  9633. *
  9634. * numbers.then(_.spread(function(x, y) {
  9635. * return x + y;
  9636. * }));
  9637. * // => a Promise of 76
  9638. */
  9639. function spread(func) {
  9640. if (typeof func != 'function') {
  9641. throw new TypeError(FUNC_ERROR_TEXT);
  9642. }
  9643. return function(array) {
  9644. return func.apply(this, array);
  9645. };
  9646. }
  9647. /**
  9648. * Creates a throttled function that only invokes `func` at most once per
  9649. * every `wait` milliseconds. The throttled function comes with a `cancel`
  9650. * method to cancel delayed invocations. Provide an options object to indicate
  9651. * that `func` should be invoked on the leading and/or trailing edge of the
  9652. * `wait` timeout. Subsequent calls to the throttled function return the
  9653. * result of the last `func` call.
  9654. *
  9655. * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
  9656. * on the trailing edge of the timeout only if the the throttled function is
  9657. * invoked more than once during the `wait` timeout.
  9658. *
  9659. * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
  9660. * for details over the differences between `_.throttle` and `_.debounce`.
  9661. *
  9662. * @static
  9663. * @memberOf _
  9664. * @category Function
  9665. * @param {Function} func The function to throttle.
  9666. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  9667. * @param {Object} [options] The options object.
  9668. * @param {boolean} [options.leading=true] Specify invoking on the leading
  9669. * edge of the timeout.
  9670. * @param {boolean} [options.trailing=true] Specify invoking on the trailing
  9671. * edge of the timeout.
  9672. * @returns {Function} Returns the new throttled function.
  9673. * @example
  9674. *
  9675. * // avoid excessively updating the position while scrolling
  9676. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  9677. *
  9678. * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
  9679. * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
  9680. * 'trailing': false
  9681. * }));
  9682. *
  9683. * // cancel a trailing throttled call
  9684. * jQuery(window).on('popstate', throttled.cancel);
  9685. */
  9686. function throttle(func, wait, options) {
  9687. var leading = true,
  9688. trailing = true;
  9689. if (typeof func != 'function') {
  9690. throw new TypeError(FUNC_ERROR_TEXT);
  9691. }
  9692. if (options === false) {
  9693. leading = false;
  9694. } else if (isObject(options)) {
  9695. leading = 'leading' in options ? !!options.leading : leading;
  9696. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9697. }
  9698. return debounce(func, wait, { 'leading': leading, 'maxWait': +wait, 'trailing': trailing });
  9699. }
  9700. /**
  9701. * Creates a function that provides `value` to the wrapper function as its
  9702. * first argument. Any additional arguments provided to the function are
  9703. * appended to those provided to the wrapper function. The wrapper is invoked
  9704. * with the `this` binding of the created function.
  9705. *
  9706. * @static
  9707. * @memberOf _
  9708. * @category Function
  9709. * @param {*} value The value to wrap.
  9710. * @param {Function} wrapper The wrapper function.
  9711. * @returns {Function} Returns the new function.
  9712. * @example
  9713. *
  9714. * var p = _.wrap(_.escape, function(func, text) {
  9715. * return '<p>' + func(text) + '</p>';
  9716. * });
  9717. *
  9718. * p('fred, barney, & pebbles');
  9719. * // => '<p>fred, barney, &amp; pebbles</p>'
  9720. */
  9721. function wrap(value, wrapper) {
  9722. wrapper = wrapper == null ? identity : wrapper;
  9723. return createWrapper(wrapper, PARTIAL_FLAG, undefined, [value], []);
  9724. }
  9725. /*------------------------------------------------------------------------*/
  9726. /**
  9727. * Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,
  9728. * otherwise they are assigned by reference. If `customizer` is provided it is
  9729. * invoked to produce the cloned values. If `customizer` returns `undefined`
  9730. * cloning is handled by the method instead. The `customizer` is bound to
  9731. * `thisArg` and invoked with two argument; (value [, index|key, object]).
  9732. *
  9733. * **Note:** This method is loosely based on the
  9734. * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
  9735. * The enumerable properties of `arguments` objects and objects created by
  9736. * constructors other than `Object` are cloned to plain `Object` objects. An
  9737. * empty object is returned for uncloneable values such as functions, DOM nodes,
  9738. * Maps, Sets, and WeakMaps.
  9739. *
  9740. * @static
  9741. * @memberOf _
  9742. * @category Lang
  9743. * @param {*} value The value to clone.
  9744. * @param {boolean} [isDeep] Specify a deep clone.
  9745. * @param {Function} [customizer] The function to customize cloning values.
  9746. * @param {*} [thisArg] The `this` binding of `customizer`.
  9747. * @returns {*} Returns the cloned value.
  9748. * @example
  9749. *
  9750. * var users = [
  9751. * { 'user': 'barney' },
  9752. * { 'user': 'fred' }
  9753. * ];
  9754. *
  9755. * var shallow = _.clone(users);
  9756. * shallow[0] === users[0];
  9757. * // => true
  9758. *
  9759. * var deep = _.clone(users, true);
  9760. * deep[0] === users[0];
  9761. * // => false
  9762. *
  9763. * // using a customizer callback
  9764. * var el = _.clone(document.body, function(value) {
  9765. * if (_.isElement(value)) {
  9766. * return value.cloneNode(false);
  9767. * }
  9768. * });
  9769. *
  9770. * el === document.body
  9771. * // => false
  9772. * el.nodeName
  9773. * // => BODY
  9774. * el.childNodes.length;
  9775. * // => 0
  9776. */
  9777. function clone(value, isDeep, customizer, thisArg) {
  9778. if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
  9779. isDeep = false;
  9780. }
  9781. else if (typeof isDeep == 'function') {
  9782. thisArg = customizer;
  9783. customizer = isDeep;
  9784. isDeep = false;
  9785. }
  9786. return typeof customizer == 'function'
  9787. ? baseClone(value, isDeep, bindCallback(customizer, thisArg, 1))
  9788. : baseClone(value, isDeep);
  9789. }
  9790. /**
  9791. * Creates a deep clone of `value`. If `customizer` is provided it is invoked
  9792. * to produce the cloned values. If `customizer` returns `undefined` cloning
  9793. * is handled by the method instead. The `customizer` is bound to `thisArg`
  9794. * and invoked with two argument; (value [, index|key, object]).
  9795. *
  9796. * **Note:** This method is loosely based on the
  9797. * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
  9798. * The enumerable properties of `arguments` objects and objects created by
  9799. * constructors other than `Object` are cloned to plain `Object` objects. An
  9800. * empty object is returned for uncloneable values such as functions, DOM nodes,
  9801. * Maps, Sets, and WeakMaps.
  9802. *
  9803. * @static
  9804. * @memberOf _
  9805. * @category Lang
  9806. * @param {*} value The value to deep clone.
  9807. * @param {Function} [customizer] The function to customize cloning values.
  9808. * @param {*} [thisArg] The `this` binding of `customizer`.
  9809. * @returns {*} Returns the deep cloned value.
  9810. * @example
  9811. *
  9812. * var users = [
  9813. * { 'user': 'barney' },
  9814. * { 'user': 'fred' }
  9815. * ];
  9816. *
  9817. * var deep = _.cloneDeep(users);
  9818. * deep[0] === users[0];
  9819. * // => false
  9820. *
  9821. * // using a customizer callback
  9822. * var el = _.cloneDeep(document.body, function(value) {
  9823. * if (_.isElement(value)) {
  9824. * return value.cloneNode(true);
  9825. * }
  9826. * });
  9827. *
  9828. * el === document.body
  9829. * // => false
  9830. * el.nodeName
  9831. * // => BODY
  9832. * el.childNodes.length;
  9833. * // => 20
  9834. */
  9835. function cloneDeep(value, customizer, thisArg) {
  9836. return typeof customizer == 'function'
  9837. ? baseClone(value, true, bindCallback(customizer, thisArg, 1))
  9838. : baseClone(value, true);
  9839. }
  9840. /**
  9841. * Checks if `value` is greater than `other`.
  9842. *
  9843. * @static
  9844. * @memberOf _
  9845. * @category Lang
  9846. * @param {*} value The value to compare.
  9847. * @param {*} other The other value to compare.
  9848. * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
  9849. * @example
  9850. *
  9851. * _.gt(3, 1);
  9852. * // => true
  9853. *
  9854. * _.gt(3, 3);
  9855. * // => false
  9856. *
  9857. * _.gt(1, 3);
  9858. * // => false
  9859. */
  9860. function gt(value, other) {
  9861. return value > other;
  9862. }
  9863. /**
  9864. * Checks if `value` is greater than or equal to `other`.
  9865. *
  9866. * @static
  9867. * @memberOf _
  9868. * @category Lang
  9869. * @param {*} value The value to compare.
  9870. * @param {*} other The other value to compare.
  9871. * @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`.
  9872. * @example
  9873. *
  9874. * _.gte(3, 1);
  9875. * // => true
  9876. *
  9877. * _.gte(3, 3);
  9878. * // => true
  9879. *
  9880. * _.gte(1, 3);
  9881. * // => false
  9882. */
  9883. function gte(value, other) {
  9884. return value >= other;
  9885. }
  9886. /**
  9887. * Checks if `value` is classified as an `arguments` object.
  9888. *
  9889. * @static
  9890. * @memberOf _
  9891. * @category Lang
  9892. * @param {*} value The value to check.
  9893. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  9894. * @example
  9895. *
  9896. * _.isArguments(function() { return arguments; }());
  9897. * // => true
  9898. *
  9899. * _.isArguments([1, 2, 3]);
  9900. * // => false
  9901. */
  9902. function isArguments(value) {
  9903. return isObjectLike(value) && isArrayLike(value) &&
  9904. hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
  9905. }
  9906. /**
  9907. * Checks if `value` is classified as an `Array` object.
  9908. *
  9909. * @static
  9910. * @memberOf _
  9911. * @category Lang
  9912. * @param {*} value The value to check.
  9913. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  9914. * @example
  9915. *
  9916. * _.isArray([1, 2, 3]);
  9917. * // => true
  9918. *
  9919. * _.isArray(function() { return arguments; }());
  9920. * // => false
  9921. */
  9922. var isArray = nativeIsArray || function(value) {
  9923. return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
  9924. };
  9925. /**
  9926. * Checks if `value` is classified as a boolean primitive or object.
  9927. *
  9928. * @static
  9929. * @memberOf _
  9930. * @category Lang
  9931. * @param {*} value The value to check.
  9932. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  9933. * @example
  9934. *
  9935. * _.isBoolean(false);
  9936. * // => true
  9937. *
  9938. * _.isBoolean(null);
  9939. * // => false
  9940. */
  9941. function isBoolean(value) {
  9942. return value === true || value === false || (isObjectLike(value) && objToString.call(value) == boolTag);
  9943. }
  9944. /**
  9945. * Checks if `value` is classified as a `Date` object.
  9946. *
  9947. * @static
  9948. * @memberOf _
  9949. * @category Lang
  9950. * @param {*} value The value to check.
  9951. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  9952. * @example
  9953. *
  9954. * _.isDate(new Date);
  9955. * // => true
  9956. *
  9957. * _.isDate('Mon April 23 2012');
  9958. * // => false
  9959. */
  9960. function isDate(value) {
  9961. return isObjectLike(value) && objToString.call(value) == dateTag;
  9962. }
  9963. /**
  9964. * Checks if `value` is a DOM element.
  9965. *
  9966. * @static
  9967. * @memberOf _
  9968. * @category Lang
  9969. * @param {*} value The value to check.
  9970. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  9971. * @example
  9972. *
  9973. * _.isElement(document.body);
  9974. * // => true
  9975. *
  9976. * _.isElement('<body>');
  9977. * // => false
  9978. */
  9979. function isElement(value) {
  9980. return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
  9981. }
  9982. /**
  9983. * Checks if `value` is empty. A value is considered empty unless it is an
  9984. * `arguments` object, array, string, or jQuery-like collection with a length
  9985. * greater than `0` or an object with own enumerable properties.
  9986. *
  9987. * @static
  9988. * @memberOf _
  9989. * @category Lang
  9990. * @param {Array|Object|string} value The value to inspect.
  9991. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  9992. * @example
  9993. *
  9994. * _.isEmpty(null);
  9995. * // => true
  9996. *
  9997. * _.isEmpty(true);
  9998. * // => true
  9999. *
  10000. * _.isEmpty(1);
  10001. * // => true
  10002. *
  10003. * _.isEmpty([1, 2, 3]);
  10004. * // => false
  10005. *
  10006. * _.isEmpty({ 'a': 1 });
  10007. * // => false
  10008. */
  10009. function isEmpty(value) {
  10010. if (value == null) {
  10011. return true;
  10012. }
  10013. if (isArrayLike(value) && (isArray(value) || isString(value) || isArguments(value) ||
  10014. (isObjectLike(value) && isFunction(value.splice)))) {
  10015. return !value.length;
  10016. }
  10017. return !keys(value).length;
  10018. }
  10019. /**
  10020. * Performs a deep comparison between two values to determine if they are
  10021. * equivalent. If `customizer` is provided it is invoked to compare values.
  10022. * If `customizer` returns `undefined` comparisons are handled by the method
  10023. * instead. The `customizer` is bound to `thisArg` and invoked with three
  10024. * arguments: (value, other [, index|key]).
  10025. *
  10026. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  10027. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  10028. * their own, not inherited, enumerable properties. Functions and DOM nodes
  10029. * are **not** supported. Provide a customizer function to extend support
  10030. * for comparing other values.
  10031. *
  10032. * @static
  10033. * @memberOf _
  10034. * @alias eq
  10035. * @category Lang
  10036. * @param {*} value The value to compare.
  10037. * @param {*} other The other value to compare.
  10038. * @param {Function} [customizer] The function to customize value comparisons.
  10039. * @param {*} [thisArg] The `this` binding of `customizer`.
  10040. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10041. * @example
  10042. *
  10043. * var object = { 'user': 'fred' };
  10044. * var other = { 'user': 'fred' };
  10045. *
  10046. * object == other;
  10047. * // => false
  10048. *
  10049. * _.isEqual(object, other);
  10050. * // => true
  10051. *
  10052. * // using a customizer callback
  10053. * var array = ['hello', 'goodbye'];
  10054. * var other = ['hi', 'goodbye'];
  10055. *
  10056. * _.isEqual(array, other, function(value, other) {
  10057. * if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
  10058. * return true;
  10059. * }
  10060. * });
  10061. * // => true
  10062. */
  10063. function isEqual(value, other, customizer, thisArg) {
  10064. customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
  10065. var result = customizer ? customizer(value, other) : undefined;
  10066. return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
  10067. }
  10068. /**
  10069. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10070. * `SyntaxError`, `TypeError`, or `URIError` object.
  10071. *
  10072. * @static
  10073. * @memberOf _
  10074. * @category Lang
  10075. * @param {*} value The value to check.
  10076. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  10077. * @example
  10078. *
  10079. * _.isError(new Error);
  10080. * // => true
  10081. *
  10082. * _.isError(Error);
  10083. * // => false
  10084. */
  10085. function isError(value) {
  10086. return isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag;
  10087. }
  10088. /**
  10089. * Checks if `value` is a finite primitive number.
  10090. *
  10091. * **Note:** This method is based on [`Number.isFinite`](http://ecma-international.org/ecma-262/6.0/#sec-number.isfinite).
  10092. *
  10093. * @static
  10094. * @memberOf _
  10095. * @category Lang
  10096. * @param {*} value The value to check.
  10097. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  10098. * @example
  10099. *
  10100. * _.isFinite(10);
  10101. * // => true
  10102. *
  10103. * _.isFinite('10');
  10104. * // => false
  10105. *
  10106. * _.isFinite(true);
  10107. * // => false
  10108. *
  10109. * _.isFinite(Object(10));
  10110. * // => false
  10111. *
  10112. * _.isFinite(Infinity);
  10113. * // => false
  10114. */
  10115. function isFinite(value) {
  10116. return typeof value == 'number' && nativeIsFinite(value);
  10117. }
  10118. /**
  10119. * Checks if `value` is classified as a `Function` object.
  10120. *
  10121. * @static
  10122. * @memberOf _
  10123. * @category Lang
  10124. * @param {*} value The value to check.
  10125. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10126. * @example
  10127. *
  10128. * _.isFunction(_);
  10129. * // => true
  10130. *
  10131. * _.isFunction(/abc/);
  10132. * // => false
  10133. */
  10134. function isFunction(value) {
  10135. // The use of `Object#toString` avoids issues with the `typeof` operator
  10136. // in older versions of Chrome and Safari which return 'function' for regexes
  10137. // and Safari 8 equivalents which return 'object' for typed array constructors.
  10138. return isObject(value) && objToString.call(value) == funcTag;
  10139. }
  10140. /**
  10141. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  10142. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10143. *
  10144. * @static
  10145. * @memberOf _
  10146. * @category Lang
  10147. * @param {*} value The value to check.
  10148. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10149. * @example
  10150. *
  10151. * _.isObject({});
  10152. * // => true
  10153. *
  10154. * _.isObject([1, 2, 3]);
  10155. * // => true
  10156. *
  10157. * _.isObject(1);
  10158. * // => false
  10159. */
  10160. function isObject(value) {
  10161. // Avoid a V8 JIT bug in Chrome 19-20.
  10162. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  10163. var type = typeof value;
  10164. return !!value && (type == 'object' || type == 'function');
  10165. }
  10166. /**
  10167. * Performs a deep comparison between `object` and `source` to determine if
  10168. * `object` contains equivalent property values. If `customizer` is provided
  10169. * it is invoked to compare values. If `customizer` returns `undefined`
  10170. * comparisons are handled by the method instead. The `customizer` is bound
  10171. * to `thisArg` and invoked with three arguments: (value, other, index|key).
  10172. *
  10173. * **Note:** This method supports comparing properties of arrays, booleans,
  10174. * `Date` objects, numbers, `Object` objects, regexes, and strings. Functions
  10175. * and DOM nodes are **not** supported. Provide a customizer function to extend
  10176. * support for comparing other values.
  10177. *
  10178. * @static
  10179. * @memberOf _
  10180. * @category Lang
  10181. * @param {Object} object The object to inspect.
  10182. * @param {Object} source The object of property values to match.
  10183. * @param {Function} [customizer] The function to customize value comparisons.
  10184. * @param {*} [thisArg] The `this` binding of `customizer`.
  10185. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  10186. * @example
  10187. *
  10188. * var object = { 'user': 'fred', 'age': 40 };
  10189. *
  10190. * _.isMatch(object, { 'age': 40 });
  10191. * // => true
  10192. *
  10193. * _.isMatch(object, { 'age': 36 });
  10194. * // => false
  10195. *
  10196. * // using a customizer callback
  10197. * var object = { 'greeting': 'hello' };
  10198. * var source = { 'greeting': 'hi' };
  10199. *
  10200. * _.isMatch(object, source, function(value, other) {
  10201. * return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
  10202. * });
  10203. * // => true
  10204. */
  10205. function isMatch(object, source, customizer, thisArg) {
  10206. customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
  10207. return baseIsMatch(object, getMatchData(source), customizer);
  10208. }
  10209. /**
  10210. * Checks if `value` is `NaN`.
  10211. *
  10212. * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
  10213. * which returns `true` for `undefined` and other non-numeric values.
  10214. *
  10215. * @static
  10216. * @memberOf _
  10217. * @category Lang
  10218. * @param {*} value The value to check.
  10219. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  10220. * @example
  10221. *
  10222. * _.isNaN(NaN);
  10223. * // => true
  10224. *
  10225. * _.isNaN(new Number(NaN));
  10226. * // => true
  10227. *
  10228. * isNaN(undefined);
  10229. * // => true
  10230. *
  10231. * _.isNaN(undefined);
  10232. * // => false
  10233. */
  10234. function isNaN(value) {
  10235. // An `NaN` primitive is the only value that is not equal to itself.
  10236. // Perform the `toStringTag` check first to avoid errors with some host objects in IE.
  10237. return isNumber(value) && value != +value;
  10238. }
  10239. /**
  10240. * Checks if `value` is a native function.
  10241. *
  10242. * @static
  10243. * @memberOf _
  10244. * @category Lang
  10245. * @param {*} value The value to check.
  10246. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  10247. * @example
  10248. *
  10249. * _.isNative(Array.prototype.push);
  10250. * // => true
  10251. *
  10252. * _.isNative(_);
  10253. * // => false
  10254. */
  10255. function isNative(value) {
  10256. if (value == null) {
  10257. return false;
  10258. }
  10259. if (isFunction(value)) {
  10260. return reIsNative.test(fnToString.call(value));
  10261. }
  10262. return isObjectLike(value) && reIsHostCtor.test(value);
  10263. }
  10264. /**
  10265. * Checks if `value` is `null`.
  10266. *
  10267. * @static
  10268. * @memberOf _
  10269. * @category Lang
  10270. * @param {*} value The value to check.
  10271. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  10272. * @example
  10273. *
  10274. * _.isNull(null);
  10275. * // => true
  10276. *
  10277. * _.isNull(void 0);
  10278. * // => false
  10279. */
  10280. function isNull(value) {
  10281. return value === null;
  10282. }
  10283. /**
  10284. * Checks if `value` is classified as a `Number` primitive or object.
  10285. *
  10286. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
  10287. * as numbers, use the `_.isFinite` method.
  10288. *
  10289. * @static
  10290. * @memberOf _
  10291. * @category Lang
  10292. * @param {*} value The value to check.
  10293. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10294. * @example
  10295. *
  10296. * _.isNumber(8.4);
  10297. * // => true
  10298. *
  10299. * _.isNumber(NaN);
  10300. * // => true
  10301. *
  10302. * _.isNumber('8.4');
  10303. * // => false
  10304. */
  10305. function isNumber(value) {
  10306. return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag);
  10307. }
  10308. /**
  10309. * Checks if `value` is a plain object, that is, an object created by the
  10310. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  10311. *
  10312. * **Note:** This method assumes objects created by the `Object` constructor
  10313. * have no inherited enumerable properties.
  10314. *
  10315. * @static
  10316. * @memberOf _
  10317. * @category Lang
  10318. * @param {*} value The value to check.
  10319. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  10320. * @example
  10321. *
  10322. * function Foo() {
  10323. * this.a = 1;
  10324. * }
  10325. *
  10326. * _.isPlainObject(new Foo);
  10327. * // => false
  10328. *
  10329. * _.isPlainObject([1, 2, 3]);
  10330. * // => false
  10331. *
  10332. * _.isPlainObject({ 'x': 0, 'y': 0 });
  10333. * // => true
  10334. *
  10335. * _.isPlainObject(Object.create(null));
  10336. * // => true
  10337. */
  10338. function isPlainObject(value) {
  10339. var Ctor;
  10340. // Exit early for non `Object` objects.
  10341. if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isArguments(value)) ||
  10342. (!hasOwnProperty.call(value, 'constructor') && (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
  10343. return false;
  10344. }
  10345. // IE < 9 iterates inherited properties before own properties. If the first
  10346. // iterated property is an object's own property then there are no inherited
  10347. // enumerable properties.
  10348. var result;
  10349. // In most environments an object's own properties are iterated before
  10350. // its inherited properties. If the last iterated property is an object's
  10351. // own property then there are no inherited enumerable properties.
  10352. baseForIn(value, function(subValue, key) {
  10353. result = key;
  10354. });
  10355. return result === undefined || hasOwnProperty.call(value, result);
  10356. }
  10357. /**
  10358. * Checks if `value` is classified as a `RegExp` object.
  10359. *
  10360. * @static
  10361. * @memberOf _
  10362. * @category Lang
  10363. * @param {*} value The value to check.
  10364. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10365. * @example
  10366. *
  10367. * _.isRegExp(/abc/);
  10368. * // => true
  10369. *
  10370. * _.isRegExp('/abc/');
  10371. * // => false
  10372. */
  10373. function isRegExp(value) {
  10374. return isObject(value) && objToString.call(value) == regexpTag;
  10375. }
  10376. /**
  10377. * Checks if `value` is classified as a `String` primitive or object.
  10378. *
  10379. * @static
  10380. * @memberOf _
  10381. * @category Lang
  10382. * @param {*} value The value to check.
  10383. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10384. * @example
  10385. *
  10386. * _.isString('abc');
  10387. * // => true
  10388. *
  10389. * _.isString(1);
  10390. * // => false
  10391. */
  10392. function isString(value) {
  10393. return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag);
  10394. }
  10395. /**
  10396. * Checks if `value` is classified as a typed array.
  10397. *
  10398. * @static
  10399. * @memberOf _
  10400. * @category Lang
  10401. * @param {*} value The value to check.
  10402. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10403. * @example
  10404. *
  10405. * _.isTypedArray(new Uint8Array);
  10406. * // => true
  10407. *
  10408. * _.isTypedArray([]);
  10409. * // => false
  10410. */
  10411. function isTypedArray(value) {
  10412. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
  10413. }
  10414. /**
  10415. * Checks if `value` is `undefined`.
  10416. *
  10417. * @static
  10418. * @memberOf _
  10419. * @category Lang
  10420. * @param {*} value The value to check.
  10421. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  10422. * @example
  10423. *
  10424. * _.isUndefined(void 0);
  10425. * // => true
  10426. *
  10427. * _.isUndefined(null);
  10428. * // => false
  10429. */
  10430. function isUndefined(value) {
  10431. return value === undefined;
  10432. }
  10433. /**
  10434. * Checks if `value` is less than `other`.
  10435. *
  10436. * @static
  10437. * @memberOf _
  10438. * @category Lang
  10439. * @param {*} value The value to compare.
  10440. * @param {*} other The other value to compare.
  10441. * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
  10442. * @example
  10443. *
  10444. * _.lt(1, 3);
  10445. * // => true
  10446. *
  10447. * _.lt(3, 3);
  10448. * // => false
  10449. *
  10450. * _.lt(3, 1);
  10451. * // => false
  10452. */
  10453. function lt(value, other) {
  10454. return value < other;
  10455. }
  10456. /**
  10457. * Checks if `value` is less than or equal to `other`.
  10458. *
  10459. * @static
  10460. * @memberOf _
  10461. * @category Lang
  10462. * @param {*} value The value to compare.
  10463. * @param {*} other The other value to compare.
  10464. * @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`.
  10465. * @example
  10466. *
  10467. * _.lte(1, 3);
  10468. * // => true
  10469. *
  10470. * _.lte(3, 3);
  10471. * // => true
  10472. *
  10473. * _.lte(3, 1);
  10474. * // => false
  10475. */
  10476. function lte(value, other) {
  10477. return value <= other;
  10478. }
  10479. /**
  10480. * Converts `value` to an array.
  10481. *
  10482. * @static
  10483. * @memberOf _
  10484. * @category Lang
  10485. * @param {*} value The value to convert.
  10486. * @returns {Array} Returns the converted array.
  10487. * @example
  10488. *
  10489. * (function() {
  10490. * return _.toArray(arguments).slice(1);
  10491. * }(1, 2, 3));
  10492. * // => [2, 3]
  10493. */
  10494. function toArray(value) {
  10495. var length = value ? getLength(value) : 0;
  10496. if (!isLength(length)) {
  10497. return values(value);
  10498. }
  10499. if (!length) {
  10500. return [];
  10501. }
  10502. return arrayCopy(value);
  10503. }
  10504. /**
  10505. * Converts `value` to a plain object flattening inherited enumerable
  10506. * properties of `value` to own properties of the plain object.
  10507. *
  10508. * @static
  10509. * @memberOf _
  10510. * @category Lang
  10511. * @param {*} value The value to convert.
  10512. * @returns {Object} Returns the converted plain object.
  10513. * @example
  10514. *
  10515. * function Foo() {
  10516. * this.b = 2;
  10517. * }
  10518. *
  10519. * Foo.prototype.c = 3;
  10520. *
  10521. * _.assign({ 'a': 1 }, new Foo);
  10522. * // => { 'a': 1, 'b': 2 }
  10523. *
  10524. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  10525. * // => { 'a': 1, 'b': 2, 'c': 3 }
  10526. */
  10527. function toPlainObject(value) {
  10528. return baseCopy(value, keysIn(value));
  10529. }
  10530. /*------------------------------------------------------------------------*/
  10531. /**
  10532. * Recursively merges own enumerable properties of the source object(s), that
  10533. * don't resolve to `undefined` into the destination object. Subsequent sources
  10534. * overwrite property assignments of previous sources. If `customizer` is
  10535. * provided it is invoked to produce the merged values of the destination and
  10536. * source properties. If `customizer` returns `undefined` merging is handled
  10537. * by the method instead. The `customizer` is bound to `thisArg` and invoked
  10538. * with five arguments: (objectValue, sourceValue, key, object, source).
  10539. *
  10540. * @static
  10541. * @memberOf _
  10542. * @category Object
  10543. * @param {Object} object The destination object.
  10544. * @param {...Object} [sources] The source objects.
  10545. * @param {Function} [customizer] The function to customize assigned values.
  10546. * @param {*} [thisArg] The `this` binding of `customizer`.
  10547. * @returns {Object} Returns `object`.
  10548. * @example
  10549. *
  10550. * var users = {
  10551. * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
  10552. * };
  10553. *
  10554. * var ages = {
  10555. * 'data': [{ 'age': 36 }, { 'age': 40 }]
  10556. * };
  10557. *
  10558. * _.merge(users, ages);
  10559. * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
  10560. *
  10561. * // using a customizer callback
  10562. * var object = {
  10563. * 'fruits': ['apple'],
  10564. * 'vegetables': ['beet']
  10565. * };
  10566. *
  10567. * var other = {
  10568. * 'fruits': ['banana'],
  10569. * 'vegetables': ['carrot']
  10570. * };
  10571. *
  10572. * _.merge(object, other, function(a, b) {
  10573. * if (_.isArray(a)) {
  10574. * return a.concat(b);
  10575. * }
  10576. * });
  10577. * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
  10578. */
  10579. var merge = createAssigner(baseMerge);
  10580. /**
  10581. * Assigns own enumerable properties of source object(s) to the destination
  10582. * object. Subsequent sources overwrite property assignments of previous sources.
  10583. * If `customizer` is provided it is invoked to produce the assigned values.
  10584. * The `customizer` is bound to `thisArg` and invoked with five arguments:
  10585. * (objectValue, sourceValue, key, object, source).
  10586. *
  10587. * **Note:** This method mutates `object` and is based on
  10588. * [`Object.assign`](http://ecma-international.org/ecma-262/6.0/#sec-object.assign).
  10589. *
  10590. * @static
  10591. * @memberOf _
  10592. * @alias extend
  10593. * @category Object
  10594. * @param {Object} object The destination object.
  10595. * @param {...Object} [sources] The source objects.
  10596. * @param {Function} [customizer] The function to customize assigned values.
  10597. * @param {*} [thisArg] The `this` binding of `customizer`.
  10598. * @returns {Object} Returns `object`.
  10599. * @example
  10600. *
  10601. * _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
  10602. * // => { 'user': 'fred', 'age': 40 }
  10603. *
  10604. * // using a customizer callback
  10605. * var defaults = _.partialRight(_.assign, function(value, other) {
  10606. * return _.isUndefined(value) ? other : value;
  10607. * });
  10608. *
  10609. * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
  10610. * // => { 'user': 'barney', 'age': 36 }
  10611. */
  10612. var assign = createAssigner(function(object, source, customizer) {
  10613. return customizer
  10614. ? assignWith(object, source, customizer)
  10615. : baseAssign(object, source);
  10616. });
  10617. /**
  10618. * Creates an object that inherits from the given `prototype` object. If a
  10619. * `properties` object is provided its own enumerable properties are assigned
  10620. * to the created object.
  10621. *
  10622. * @static
  10623. * @memberOf _
  10624. * @category Object
  10625. * @param {Object} prototype The object to inherit from.
  10626. * @param {Object} [properties] The properties to assign to the object.
  10627. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10628. * @returns {Object} Returns the new object.
  10629. * @example
  10630. *
  10631. * function Shape() {
  10632. * this.x = 0;
  10633. * this.y = 0;
  10634. * }
  10635. *
  10636. * function Circle() {
  10637. * Shape.call(this);
  10638. * }
  10639. *
  10640. * Circle.prototype = _.create(Shape.prototype, {
  10641. * 'constructor': Circle
  10642. * });
  10643. *
  10644. * var circle = new Circle;
  10645. * circle instanceof Circle;
  10646. * // => true
  10647. *
  10648. * circle instanceof Shape;
  10649. * // => true
  10650. */
  10651. function create(prototype, properties, guard) {
  10652. var result = baseCreate(prototype);
  10653. if (guard && isIterateeCall(prototype, properties, guard)) {
  10654. properties = undefined;
  10655. }
  10656. return properties ? baseAssign(result, properties) : result;
  10657. }
  10658. /**
  10659. * Assigns own enumerable properties of source object(s) to the destination
  10660. * object for all destination properties that resolve to `undefined`. Once a
  10661. * property is set, additional values of the same property are ignored.
  10662. *
  10663. * **Note:** This method mutates `object`.
  10664. *
  10665. * @static
  10666. * @memberOf _
  10667. * @category Object
  10668. * @param {Object} object The destination object.
  10669. * @param {...Object} [sources] The source objects.
  10670. * @returns {Object} Returns `object`.
  10671. * @example
  10672. *
  10673. * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
  10674. * // => { 'user': 'barney', 'age': 36 }
  10675. */
  10676. var defaults = createDefaults(assign, assignDefaults);
  10677. /**
  10678. * This method is like `_.defaults` except that it recursively assigns
  10679. * default properties.
  10680. *
  10681. * **Note:** This method mutates `object`.
  10682. *
  10683. * @static
  10684. * @memberOf _
  10685. * @category Object
  10686. * @param {Object} object The destination object.
  10687. * @param {...Object} [sources] The source objects.
  10688. * @returns {Object} Returns `object`.
  10689. * @example
  10690. *
  10691. * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
  10692. * // => { 'user': { 'name': 'barney', 'age': 36 } }
  10693. *
  10694. */
  10695. var defaultsDeep = createDefaults(merge, mergeDefaults);
  10696. /**
  10697. * This method is like `_.find` except that it returns the key of the first
  10698. * element `predicate` returns truthy for instead of the element itself.
  10699. *
  10700. * If a property name is provided for `predicate` the created `_.property`
  10701. * style callback returns the property value of the given element.
  10702. *
  10703. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  10704. * style callback returns `true` for elements that have a matching property
  10705. * value, else `false`.
  10706. *
  10707. * If an object is provided for `predicate` the created `_.matches` style
  10708. * callback returns `true` for elements that have the properties of the given
  10709. * object, else `false`.
  10710. *
  10711. * @static
  10712. * @memberOf _
  10713. * @category Object
  10714. * @param {Object} object The object to search.
  10715. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  10716. * per iteration.
  10717. * @param {*} [thisArg] The `this` binding of `predicate`.
  10718. * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
  10719. * @example
  10720. *
  10721. * var users = {
  10722. * 'barney': { 'age': 36, 'active': true },
  10723. * 'fred': { 'age': 40, 'active': false },
  10724. * 'pebbles': { 'age': 1, 'active': true }
  10725. * };
  10726. *
  10727. * _.findKey(users, function(chr) {
  10728. * return chr.age < 40;
  10729. * });
  10730. * // => 'barney' (iteration order is not guaranteed)
  10731. *
  10732. * // using the `_.matches` callback shorthand
  10733. * _.findKey(users, { 'age': 1, 'active': true });
  10734. * // => 'pebbles'
  10735. *
  10736. * // using the `_.matchesProperty` callback shorthand
  10737. * _.findKey(users, 'active', false);
  10738. * // => 'fred'
  10739. *
  10740. * // using the `_.property` callback shorthand
  10741. * _.findKey(users, 'active');
  10742. * // => 'barney'
  10743. */
  10744. var findKey = createFindKey(baseForOwn);
  10745. /**
  10746. * This method is like `_.findKey` except that it iterates over elements of
  10747. * a collection in the opposite order.
  10748. *
  10749. * If a property name is provided for `predicate` the created `_.property`
  10750. * style callback returns the property value of the given element.
  10751. *
  10752. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  10753. * style callback returns `true` for elements that have a matching property
  10754. * value, else `false`.
  10755. *
  10756. * If an object is provided for `predicate` the created `_.matches` style
  10757. * callback returns `true` for elements that have the properties of the given
  10758. * object, else `false`.
  10759. *
  10760. * @static
  10761. * @memberOf _
  10762. * @category Object
  10763. * @param {Object} object The object to search.
  10764. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  10765. * per iteration.
  10766. * @param {*} [thisArg] The `this` binding of `predicate`.
  10767. * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
  10768. * @example
  10769. *
  10770. * var users = {
  10771. * 'barney': { 'age': 36, 'active': true },
  10772. * 'fred': { 'age': 40, 'active': false },
  10773. * 'pebbles': { 'age': 1, 'active': true }
  10774. * };
  10775. *
  10776. * _.findLastKey(users, function(chr) {
  10777. * return chr.age < 40;
  10778. * });
  10779. * // => returns `pebbles` assuming `_.findKey` returns `barney`
  10780. *
  10781. * // using the `_.matches` callback shorthand
  10782. * _.findLastKey(users, { 'age': 36, 'active': true });
  10783. * // => 'barney'
  10784. *
  10785. * // using the `_.matchesProperty` callback shorthand
  10786. * _.findLastKey(users, 'active', false);
  10787. * // => 'fred'
  10788. *
  10789. * // using the `_.property` callback shorthand
  10790. * _.findLastKey(users, 'active');
  10791. * // => 'pebbles'
  10792. */
  10793. var findLastKey = createFindKey(baseForOwnRight);
  10794. /**
  10795. * Iterates over own and inherited enumerable properties of an object invoking
  10796. * `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
  10797. * with three arguments: (value, key, object). Iteratee functions may exit
  10798. * iteration early by explicitly returning `false`.
  10799. *
  10800. * @static
  10801. * @memberOf _
  10802. * @category Object
  10803. * @param {Object} object The object to iterate over.
  10804. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  10805. * @param {*} [thisArg] The `this` binding of `iteratee`.
  10806. * @returns {Object} Returns `object`.
  10807. * @example
  10808. *
  10809. * function Foo() {
  10810. * this.a = 1;
  10811. * this.b = 2;
  10812. * }
  10813. *
  10814. * Foo.prototype.c = 3;
  10815. *
  10816. * _.forIn(new Foo, function(value, key) {
  10817. * console.log(key);
  10818. * });
  10819. * // => logs 'a', 'b', and 'c' (iteration order is not guaranteed)
  10820. */
  10821. var forIn = createForIn(baseFor);
  10822. /**
  10823. * This method is like `_.forIn` except that it iterates over properties of
  10824. * `object` in the opposite order.
  10825. *
  10826. * @static
  10827. * @memberOf _
  10828. * @category Object
  10829. * @param {Object} object The object to iterate over.
  10830. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  10831. * @param {*} [thisArg] The `this` binding of `iteratee`.
  10832. * @returns {Object} Returns `object`.
  10833. * @example
  10834. *
  10835. * function Foo() {
  10836. * this.a = 1;
  10837. * this.b = 2;
  10838. * }
  10839. *
  10840. * Foo.prototype.c = 3;
  10841. *
  10842. * _.forInRight(new Foo, function(value, key) {
  10843. * console.log(key);
  10844. * });
  10845. * // => logs 'c', 'b', and 'a' assuming `_.forIn ` logs 'a', 'b', and 'c'
  10846. */
  10847. var forInRight = createForIn(baseForRight);
  10848. /**
  10849. * Iterates over own enumerable properties of an object invoking `iteratee`
  10850. * for each property. The `iteratee` is bound to `thisArg` and invoked with
  10851. * three arguments: (value, key, object). Iteratee functions may exit iteration
  10852. * early by explicitly returning `false`.
  10853. *
  10854. * @static
  10855. * @memberOf _
  10856. * @category Object
  10857. * @param {Object} object The object to iterate over.
  10858. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  10859. * @param {*} [thisArg] The `this` binding of `iteratee`.
  10860. * @returns {Object} Returns `object`.
  10861. * @example
  10862. *
  10863. * function Foo() {
  10864. * this.a = 1;
  10865. * this.b = 2;
  10866. * }
  10867. *
  10868. * Foo.prototype.c = 3;
  10869. *
  10870. * _.forOwn(new Foo, function(value, key) {
  10871. * console.log(key);
  10872. * });
  10873. * // => logs 'a' and 'b' (iteration order is not guaranteed)
  10874. */
  10875. var forOwn = createForOwn(baseForOwn);
  10876. /**
  10877. * This method is like `_.forOwn` except that it iterates over properties of
  10878. * `object` in the opposite order.
  10879. *
  10880. * @static
  10881. * @memberOf _
  10882. * @category Object
  10883. * @param {Object} object The object to iterate over.
  10884. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  10885. * @param {*} [thisArg] The `this` binding of `iteratee`.
  10886. * @returns {Object} Returns `object`.
  10887. * @example
  10888. *
  10889. * function Foo() {
  10890. * this.a = 1;
  10891. * this.b = 2;
  10892. * }
  10893. *
  10894. * Foo.prototype.c = 3;
  10895. *
  10896. * _.forOwnRight(new Foo, function(value, key) {
  10897. * console.log(key);
  10898. * });
  10899. * // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
  10900. */
  10901. var forOwnRight = createForOwn(baseForOwnRight);
  10902. /**
  10903. * Creates an array of function property names from all enumerable properties,
  10904. * own and inherited, of `object`.
  10905. *
  10906. * @static
  10907. * @memberOf _
  10908. * @alias methods
  10909. * @category Object
  10910. * @param {Object} object The object to inspect.
  10911. * @returns {Array} Returns the new array of property names.
  10912. * @example
  10913. *
  10914. * _.functions(_);
  10915. * // => ['after', 'ary', 'assign', ...]
  10916. */
  10917. function functions(object) {
  10918. return baseFunctions(object, keysIn(object));
  10919. }
  10920. /**
  10921. * Gets the property value at `path` of `object`. If the resolved value is
  10922. * `undefined` the `defaultValue` is used in its place.
  10923. *
  10924. * @static
  10925. * @memberOf _
  10926. * @category Object
  10927. * @param {Object} object The object to query.
  10928. * @param {Array|string} path The path of the property to get.
  10929. * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
  10930. * @returns {*} Returns the resolved value.
  10931. * @example
  10932. *
  10933. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  10934. *
  10935. * _.get(object, 'a[0].b.c');
  10936. * // => 3
  10937. *
  10938. * _.get(object, ['a', '0', 'b', 'c']);
  10939. * // => 3
  10940. *
  10941. * _.get(object, 'a.b.c', 'default');
  10942. * // => 'default'
  10943. */
  10944. function get(object, path, defaultValue) {
  10945. var result = object == null ? undefined : baseGet(object, toPath(path), path + '');
  10946. return result === undefined ? defaultValue : result;
  10947. }
  10948. /**
  10949. * Checks if `path` is a direct property.
  10950. *
  10951. * @static
  10952. * @memberOf _
  10953. * @category Object
  10954. * @param {Object} object The object to query.
  10955. * @param {Array|string} path The path to check.
  10956. * @returns {boolean} Returns `true` if `path` is a direct property, else `false`.
  10957. * @example
  10958. *
  10959. * var object = { 'a': { 'b': { 'c': 3 } } };
  10960. *
  10961. * _.has(object, 'a');
  10962. * // => true
  10963. *
  10964. * _.has(object, 'a.b.c');
  10965. * // => true
  10966. *
  10967. * _.has(object, ['a', 'b', 'c']);
  10968. * // => true
  10969. */
  10970. function has(object, path) {
  10971. if (object == null) {
  10972. return false;
  10973. }
  10974. var result = hasOwnProperty.call(object, path);
  10975. if (!result && !isKey(path)) {
  10976. path = toPath(path);
  10977. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  10978. if (object == null) {
  10979. return false;
  10980. }
  10981. path = last(path);
  10982. result = hasOwnProperty.call(object, path);
  10983. }
  10984. return result || (isLength(object.length) && isIndex(path, object.length) &&
  10985. (isArray(object) || isArguments(object)));
  10986. }
  10987. /**
  10988. * Creates an object composed of the inverted keys and values of `object`.
  10989. * If `object` contains duplicate values, subsequent values overwrite property
  10990. * assignments of previous values unless `multiValue` is `true`.
  10991. *
  10992. * @static
  10993. * @memberOf _
  10994. * @category Object
  10995. * @param {Object} object The object to invert.
  10996. * @param {boolean} [multiValue] Allow multiple values per key.
  10997. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10998. * @returns {Object} Returns the new inverted object.
  10999. * @example
  11000. *
  11001. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  11002. *
  11003. * _.invert(object);
  11004. * // => { '1': 'c', '2': 'b' }
  11005. *
  11006. * // with `multiValue`
  11007. * _.invert(object, true);
  11008. * // => { '1': ['a', 'c'], '2': ['b'] }
  11009. */
  11010. function invert(object, multiValue, guard) {
  11011. if (guard && isIterateeCall(object, multiValue, guard)) {
  11012. multiValue = undefined;
  11013. }
  11014. var index = -1,
  11015. props = keys(object),
  11016. length = props.length,
  11017. result = {};
  11018. while (++index < length) {
  11019. var key = props[index],
  11020. value = object[key];
  11021. if (multiValue) {
  11022. if (hasOwnProperty.call(result, value)) {
  11023. result[value].push(key);
  11024. } else {
  11025. result[value] = [key];
  11026. }
  11027. }
  11028. else {
  11029. result[value] = key;
  11030. }
  11031. }
  11032. return result;
  11033. }
  11034. /**
  11035. * Creates an array of the own enumerable property names of `object`.
  11036. *
  11037. * **Note:** Non-object values are coerced to objects. See the
  11038. * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
  11039. * for more details.
  11040. *
  11041. * @static
  11042. * @memberOf _
  11043. * @category Object
  11044. * @param {Object} object The object to query.
  11045. * @returns {Array} Returns the array of property names.
  11046. * @example
  11047. *
  11048. * function Foo() {
  11049. * this.a = 1;
  11050. * this.b = 2;
  11051. * }
  11052. *
  11053. * Foo.prototype.c = 3;
  11054. *
  11055. * _.keys(new Foo);
  11056. * // => ['a', 'b'] (iteration order is not guaranteed)
  11057. *
  11058. * _.keys('hi');
  11059. * // => ['0', '1']
  11060. */
  11061. var keys = !nativeKeys ? shimKeys : function(object) {
  11062. var Ctor = object == null ? undefined : object.constructor;
  11063. if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
  11064. (typeof object != 'function' && isArrayLike(object))) {
  11065. return shimKeys(object);
  11066. }
  11067. return isObject(object) ? nativeKeys(object) : [];
  11068. };
  11069. /**
  11070. * Creates an array of the own and inherited enumerable property names of `object`.
  11071. *
  11072. * **Note:** Non-object values are coerced to objects.
  11073. *
  11074. * @static
  11075. * @memberOf _
  11076. * @category Object
  11077. * @param {Object} object The object to query.
  11078. * @returns {Array} Returns the array of property names.
  11079. * @example
  11080. *
  11081. * function Foo() {
  11082. * this.a = 1;
  11083. * this.b = 2;
  11084. * }
  11085. *
  11086. * Foo.prototype.c = 3;
  11087. *
  11088. * _.keysIn(new Foo);
  11089. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  11090. */
  11091. function keysIn(object) {
  11092. if (object == null) {
  11093. return [];
  11094. }
  11095. if (!isObject(object)) {
  11096. object = Object(object);
  11097. }
  11098. var length = object.length;
  11099. length = (length && isLength(length) &&
  11100. (isArray(object) || isArguments(object)) && length) || 0;
  11101. var Ctor = object.constructor,
  11102. index = -1,
  11103. isProto = typeof Ctor == 'function' && Ctor.prototype === object,
  11104. result = Array(length),
  11105. skipIndexes = length > 0;
  11106. while (++index < length) {
  11107. result[index] = (index + '');
  11108. }
  11109. for (var key in object) {
  11110. if (!(skipIndexes && isIndex(key, length)) &&
  11111. !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  11112. result.push(key);
  11113. }
  11114. }
  11115. return result;
  11116. }
  11117. /**
  11118. * The opposite of `_.mapValues`; this method creates an object with the
  11119. * same values as `object` and keys generated by running each own enumerable
  11120. * property of `object` through `iteratee`.
  11121. *
  11122. * @static
  11123. * @memberOf _
  11124. * @category Object
  11125. * @param {Object} object The object to iterate over.
  11126. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  11127. * per iteration.
  11128. * @param {*} [thisArg] The `this` binding of `iteratee`.
  11129. * @returns {Object} Returns the new mapped object.
  11130. * @example
  11131. *
  11132. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  11133. * return key + value;
  11134. * });
  11135. * // => { 'a1': 1, 'b2': 2 }
  11136. */
  11137. var mapKeys = createObjectMapper(true);
  11138. /**
  11139. * Creates an object with the same keys as `object` and values generated by
  11140. * running each own enumerable property of `object` through `iteratee`. The
  11141. * iteratee function is bound to `thisArg` and invoked with three arguments:
  11142. * (value, key, object).
  11143. *
  11144. * If a property name is provided for `iteratee` the created `_.property`
  11145. * style callback returns the property value of the given element.
  11146. *
  11147. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  11148. * style callback returns `true` for elements that have a matching property
  11149. * value, else `false`.
  11150. *
  11151. * If an object is provided for `iteratee` the created `_.matches` style
  11152. * callback returns `true` for elements that have the properties of the given
  11153. * object, else `false`.
  11154. *
  11155. * @static
  11156. * @memberOf _
  11157. * @category Object
  11158. * @param {Object} object The object to iterate over.
  11159. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  11160. * per iteration.
  11161. * @param {*} [thisArg] The `this` binding of `iteratee`.
  11162. * @returns {Object} Returns the new mapped object.
  11163. * @example
  11164. *
  11165. * _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
  11166. * return n * 3;
  11167. * });
  11168. * // => { 'a': 3, 'b': 6 }
  11169. *
  11170. * var users = {
  11171. * 'fred': { 'user': 'fred', 'age': 40 },
  11172. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  11173. * };
  11174. *
  11175. * // using the `_.property` callback shorthand
  11176. * _.mapValues(users, 'age');
  11177. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  11178. */
  11179. var mapValues = createObjectMapper();
  11180. /**
  11181. * The opposite of `_.pick`; this method creates an object composed of the
  11182. * own and inherited enumerable properties of `object` that are not omitted.
  11183. *
  11184. * @static
  11185. * @memberOf _
  11186. * @category Object
  11187. * @param {Object} object The source object.
  11188. * @param {Function|...(string|string[])} [predicate] The function invoked per
  11189. * iteration or property names to omit, specified as individual property
  11190. * names or arrays of property names.
  11191. * @param {*} [thisArg] The `this` binding of `predicate`.
  11192. * @returns {Object} Returns the new object.
  11193. * @example
  11194. *
  11195. * var object = { 'user': 'fred', 'age': 40 };
  11196. *
  11197. * _.omit(object, 'age');
  11198. * // => { 'user': 'fred' }
  11199. *
  11200. * _.omit(object, _.isNumber);
  11201. * // => { 'user': 'fred' }
  11202. */
  11203. var omit = restParam(function(object, props) {
  11204. if (object == null) {
  11205. return {};
  11206. }
  11207. if (typeof props[0] != 'function') {
  11208. var props = arrayMap(baseFlatten(props), String);
  11209. return pickByArray(object, baseDifference(keysIn(object), props));
  11210. }
  11211. var predicate = bindCallback(props[0], props[1], 3);
  11212. return pickByCallback(object, function(value, key, object) {
  11213. return !predicate(value, key, object);
  11214. });
  11215. });
  11216. /**
  11217. * Creates a two dimensional array of the key-value pairs for `object`,
  11218. * e.g. `[[key1, value1], [key2, value2]]`.
  11219. *
  11220. * @static
  11221. * @memberOf _
  11222. * @category Object
  11223. * @param {Object} object The object to query.
  11224. * @returns {Array} Returns the new array of key-value pairs.
  11225. * @example
  11226. *
  11227. * _.pairs({ 'barney': 36, 'fred': 40 });
  11228. * // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
  11229. */
  11230. function pairs(object) {
  11231. object = toObject(object);
  11232. var index = -1,
  11233. props = keys(object),
  11234. length = props.length,
  11235. result = Array(length);
  11236. while (++index < length) {
  11237. var key = props[index];
  11238. result[index] = [key, object[key]];
  11239. }
  11240. return result;
  11241. }
  11242. /**
  11243. * Creates an object composed of the picked `object` properties. Property
  11244. * names may be specified as individual arguments or as arrays of property
  11245. * names. If `predicate` is provided it is invoked for each property of `object`
  11246. * picking the properties `predicate` returns truthy for. The predicate is
  11247. * bound to `thisArg` and invoked with three arguments: (value, key, object).
  11248. *
  11249. * @static
  11250. * @memberOf _
  11251. * @category Object
  11252. * @param {Object} object The source object.
  11253. * @param {Function|...(string|string[])} [predicate] The function invoked per
  11254. * iteration or property names to pick, specified as individual property
  11255. * names or arrays of property names.
  11256. * @param {*} [thisArg] The `this` binding of `predicate`.
  11257. * @returns {Object} Returns the new object.
  11258. * @example
  11259. *
  11260. * var object = { 'user': 'fred', 'age': 40 };
  11261. *
  11262. * _.pick(object, 'user');
  11263. * // => { 'user': 'fred' }
  11264. *
  11265. * _.pick(object, _.isString);
  11266. * // => { 'user': 'fred' }
  11267. */
  11268. var pick = restParam(function(object, props) {
  11269. if (object == null) {
  11270. return {};
  11271. }
  11272. return typeof props[0] == 'function'
  11273. ? pickByCallback(object, bindCallback(props[0], props[1], 3))
  11274. : pickByArray(object, baseFlatten(props));
  11275. });
  11276. /**
  11277. * This method is like `_.get` except that if the resolved value is a function
  11278. * it is invoked with the `this` binding of its parent object and its result
  11279. * is returned.
  11280. *
  11281. * @static
  11282. * @memberOf _
  11283. * @category Object
  11284. * @param {Object} object The object to query.
  11285. * @param {Array|string} path The path of the property to resolve.
  11286. * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
  11287. * @returns {*} Returns the resolved value.
  11288. * @example
  11289. *
  11290. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  11291. *
  11292. * _.result(object, 'a[0].b.c1');
  11293. * // => 3
  11294. *
  11295. * _.result(object, 'a[0].b.c2');
  11296. * // => 4
  11297. *
  11298. * _.result(object, 'a.b.c', 'default');
  11299. * // => 'default'
  11300. *
  11301. * _.result(object, 'a.b.c', _.constant('default'));
  11302. * // => 'default'
  11303. */
  11304. function result(object, path, defaultValue) {
  11305. var result = object == null ? undefined : object[path];
  11306. if (result === undefined) {
  11307. if (object != null && !isKey(path, object)) {
  11308. path = toPath(path);
  11309. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  11310. result = object == null ? undefined : object[last(path)];
  11311. }
  11312. result = result === undefined ? defaultValue : result;
  11313. }
  11314. return isFunction(result) ? result.call(object) : result;
  11315. }
  11316. /**
  11317. * Sets the property value of `path` on `object`. If a portion of `path`
  11318. * does not exist it is created.
  11319. *
  11320. * @static
  11321. * @memberOf _
  11322. * @category Object
  11323. * @param {Object} object The object to augment.
  11324. * @param {Array|string} path The path of the property to set.
  11325. * @param {*} value The value to set.
  11326. * @returns {Object} Returns `object`.
  11327. * @example
  11328. *
  11329. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  11330. *
  11331. * _.set(object, 'a[0].b.c', 4);
  11332. * console.log(object.a[0].b.c);
  11333. * // => 4
  11334. *
  11335. * _.set(object, 'x[0].y.z', 5);
  11336. * console.log(object.x[0].y.z);
  11337. * // => 5
  11338. */
  11339. function set(object, path, value) {
  11340. if (object == null) {
  11341. return object;
  11342. }
  11343. var pathKey = (path + '');
  11344. path = (object[pathKey] != null || isKey(path, object)) ? [pathKey] : toPath(path);
  11345. var index = -1,
  11346. length = path.length,
  11347. lastIndex = length - 1,
  11348. nested = object;
  11349. while (nested != null && ++index < length) {
  11350. var key = path[index];
  11351. if (isObject(nested)) {
  11352. if (index == lastIndex) {
  11353. nested[key] = value;
  11354. } else if (nested[key] == null) {
  11355. nested[key] = isIndex(path[index + 1]) ? [] : {};
  11356. }
  11357. }
  11358. nested = nested[key];
  11359. }
  11360. return object;
  11361. }
  11362. /**
  11363. * An alternative to `_.reduce`; this method transforms `object` to a new
  11364. * `accumulator` object which is the result of running each of its own enumerable
  11365. * properties through `iteratee`, with each invocation potentially mutating
  11366. * the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
  11367. * with four arguments: (accumulator, value, key, object). Iteratee functions
  11368. * may exit iteration early by explicitly returning `false`.
  11369. *
  11370. * @static
  11371. * @memberOf _
  11372. * @category Object
  11373. * @param {Array|Object} object The object to iterate over.
  11374. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11375. * @param {*} [accumulator] The custom accumulator value.
  11376. * @param {*} [thisArg] The `this` binding of `iteratee`.
  11377. * @returns {*} Returns the accumulated value.
  11378. * @example
  11379. *
  11380. * _.transform([2, 3, 4], function(result, n) {
  11381. * result.push(n *= n);
  11382. * return n % 2 == 0;
  11383. * });
  11384. * // => [4, 9]
  11385. *
  11386. * _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
  11387. * result[key] = n * 3;
  11388. * });
  11389. * // => { 'a': 3, 'b': 6 }
  11390. */
  11391. function transform(object, iteratee, accumulator, thisArg) {
  11392. var isArr = isArray(object) || isTypedArray(object);
  11393. iteratee = getCallback(iteratee, thisArg, 4);
  11394. if (accumulator == null) {
  11395. if (isArr || isObject(object)) {
  11396. var Ctor = object.constructor;
  11397. if (isArr) {
  11398. accumulator = isArray(object) ? new Ctor : [];
  11399. } else {
  11400. accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
  11401. }
  11402. } else {
  11403. accumulator = {};
  11404. }
  11405. }
  11406. (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
  11407. return iteratee(accumulator, value, index, object);
  11408. });
  11409. return accumulator;
  11410. }
  11411. /**
  11412. * Creates an array of the own enumerable property values of `object`.
  11413. *
  11414. * **Note:** Non-object values are coerced to objects.
  11415. *
  11416. * @static
  11417. * @memberOf _
  11418. * @category Object
  11419. * @param {Object} object The object to query.
  11420. * @returns {Array} Returns the array of property values.
  11421. * @example
  11422. *
  11423. * function Foo() {
  11424. * this.a = 1;
  11425. * this.b = 2;
  11426. * }
  11427. *
  11428. * Foo.prototype.c = 3;
  11429. *
  11430. * _.values(new Foo);
  11431. * // => [1, 2] (iteration order is not guaranteed)
  11432. *
  11433. * _.values('hi');
  11434. * // => ['h', 'i']
  11435. */
  11436. function values(object) {
  11437. return baseValues(object, keys(object));
  11438. }
  11439. /**
  11440. * Creates an array of the own and inherited enumerable property values
  11441. * of `object`.
  11442. *
  11443. * **Note:** Non-object values are coerced to objects.
  11444. *
  11445. * @static
  11446. * @memberOf _
  11447. * @category Object
  11448. * @param {Object} object The object to query.
  11449. * @returns {Array} Returns the array of property values.
  11450. * @example
  11451. *
  11452. * function Foo() {
  11453. * this.a = 1;
  11454. * this.b = 2;
  11455. * }
  11456. *
  11457. * Foo.prototype.c = 3;
  11458. *
  11459. * _.valuesIn(new Foo);
  11460. * // => [1, 2, 3] (iteration order is not guaranteed)
  11461. */
  11462. function valuesIn(object) {
  11463. return baseValues(object, keysIn(object));
  11464. }
  11465. /*------------------------------------------------------------------------*/
  11466. /**
  11467. * Checks if `n` is between `start` and up to but not including, `end`. If
  11468. * `end` is not specified it is set to `start` with `start` then set to `0`.
  11469. *
  11470. * @static
  11471. * @memberOf _
  11472. * @category Number
  11473. * @param {number} n The number to check.
  11474. * @param {number} [start=0] The start of the range.
  11475. * @param {number} end The end of the range.
  11476. * @returns {boolean} Returns `true` if `n` is in the range, else `false`.
  11477. * @example
  11478. *
  11479. * _.inRange(3, 2, 4);
  11480. * // => true
  11481. *
  11482. * _.inRange(4, 8);
  11483. * // => true
  11484. *
  11485. * _.inRange(4, 2);
  11486. * // => false
  11487. *
  11488. * _.inRange(2, 2);
  11489. * // => false
  11490. *
  11491. * _.inRange(1.2, 2);
  11492. * // => true
  11493. *
  11494. * _.inRange(5.2, 4);
  11495. * // => false
  11496. */
  11497. function inRange(value, start, end) {
  11498. start = +start || 0;
  11499. if (end === undefined) {
  11500. end = start;
  11501. start = 0;
  11502. } else {
  11503. end = +end || 0;
  11504. }
  11505. return value >= nativeMin(start, end) && value < nativeMax(start, end);
  11506. }
  11507. /**
  11508. * Produces a random number between `min` and `max` (inclusive). If only one
  11509. * argument is provided a number between `0` and the given number is returned.
  11510. * If `floating` is `true`, or either `min` or `max` are floats, a floating-point
  11511. * number is returned instead of an integer.
  11512. *
  11513. * @static
  11514. * @memberOf _
  11515. * @category Number
  11516. * @param {number} [min=0] The minimum possible value.
  11517. * @param {number} [max=1] The maximum possible value.
  11518. * @param {boolean} [floating] Specify returning a floating-point number.
  11519. * @returns {number} Returns the random number.
  11520. * @example
  11521. *
  11522. * _.random(0, 5);
  11523. * // => an integer between 0 and 5
  11524. *
  11525. * _.random(5);
  11526. * // => also an integer between 0 and 5
  11527. *
  11528. * _.random(5, true);
  11529. * // => a floating-point number between 0 and 5
  11530. *
  11531. * _.random(1.2, 5.2);
  11532. * // => a floating-point number between 1.2 and 5.2
  11533. */
  11534. function random(min, max, floating) {
  11535. if (floating && isIterateeCall(min, max, floating)) {
  11536. max = floating = undefined;
  11537. }
  11538. var noMin = min == null,
  11539. noMax = max == null;
  11540. if (floating == null) {
  11541. if (noMax && typeof min == 'boolean') {
  11542. floating = min;
  11543. min = 1;
  11544. }
  11545. else if (typeof max == 'boolean') {
  11546. floating = max;
  11547. noMax = true;
  11548. }
  11549. }
  11550. if (noMin && noMax) {
  11551. max = 1;
  11552. noMax = false;
  11553. }
  11554. min = +min || 0;
  11555. if (noMax) {
  11556. max = min;
  11557. min = 0;
  11558. } else {
  11559. max = +max || 0;
  11560. }
  11561. if (floating || min % 1 || max % 1) {
  11562. var rand = nativeRandom();
  11563. return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1)))), max);
  11564. }
  11565. return baseRandom(min, max);
  11566. }
  11567. /*------------------------------------------------------------------------*/
  11568. /**
  11569. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  11570. *
  11571. * @static
  11572. * @memberOf _
  11573. * @category String
  11574. * @param {string} [string=''] The string to convert.
  11575. * @returns {string} Returns the camel cased string.
  11576. * @example
  11577. *
  11578. * _.camelCase('Foo Bar');
  11579. * // => 'fooBar'
  11580. *
  11581. * _.camelCase('--foo-bar');
  11582. * // => 'fooBar'
  11583. *
  11584. * _.camelCase('__foo_bar__');
  11585. * // => 'fooBar'
  11586. */
  11587. var camelCase = createCompounder(function(result, word, index) {
  11588. word = word.toLowerCase();
  11589. return result + (index ? (word.charAt(0).toUpperCase() + word.slice(1)) : word);
  11590. });
  11591. /**
  11592. * Capitalizes the first character of `string`.
  11593. *
  11594. * @static
  11595. * @memberOf _
  11596. * @category String
  11597. * @param {string} [string=''] The string to capitalize.
  11598. * @returns {string} Returns the capitalized string.
  11599. * @example
  11600. *
  11601. * _.capitalize('fred');
  11602. * // => 'Fred'
  11603. */
  11604. function capitalize(string) {
  11605. string = baseToString(string);
  11606. return string && (string.charAt(0).toUpperCase() + string.slice(1));
  11607. }
  11608. /**
  11609. * Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  11610. * to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  11611. *
  11612. * @static
  11613. * @memberOf _
  11614. * @category String
  11615. * @param {string} [string=''] The string to deburr.
  11616. * @returns {string} Returns the deburred string.
  11617. * @example
  11618. *
  11619. * _.deburr('déjà vu');
  11620. * // => 'deja vu'
  11621. */
  11622. function deburr(string) {
  11623. string = baseToString(string);
  11624. return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
  11625. }
  11626. /**
  11627. * Checks if `string` ends with the given target string.
  11628. *
  11629. * @static
  11630. * @memberOf _
  11631. * @category String
  11632. * @param {string} [string=''] The string to search.
  11633. * @param {string} [target] The string to search for.
  11634. * @param {number} [position=string.length] The position to search from.
  11635. * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
  11636. * @example
  11637. *
  11638. * _.endsWith('abc', 'c');
  11639. * // => true
  11640. *
  11641. * _.endsWith('abc', 'b');
  11642. * // => false
  11643. *
  11644. * _.endsWith('abc', 'b', 2);
  11645. * // => true
  11646. */
  11647. function endsWith(string, target, position) {
  11648. string = baseToString(string);
  11649. target = (target + '');
  11650. var length = string.length;
  11651. position = position === undefined
  11652. ? length
  11653. : nativeMin(position < 0 ? 0 : (+position || 0), length);
  11654. position -= target.length;
  11655. return position >= 0 && string.indexOf(target, position) == position;
  11656. }
  11657. /**
  11658. * Converts the characters "&", "<", ">", '"', "'", and "\`", in `string` to
  11659. * their corresponding HTML entities.
  11660. *
  11661. * **Note:** No other characters are escaped. To escape additional characters
  11662. * use a third-party library like [_he_](https://mths.be/he).
  11663. *
  11664. * Though the ">" character is escaped for symmetry, characters like
  11665. * ">" and "/" don't need escaping in HTML and have no special meaning
  11666. * unless they're part of a tag or unquoted attribute value.
  11667. * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  11668. * (under "semi-related fun fact") for more details.
  11669. *
  11670. * Backticks are escaped because in Internet Explorer < 9, they can break out
  11671. * of attribute values or HTML comments. See [#59](https://html5sec.org/#59),
  11672. * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
  11673. * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
  11674. * for more details.
  11675. *
  11676. * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
  11677. * to reduce XSS vectors.
  11678. *
  11679. * @static
  11680. * @memberOf _
  11681. * @category String
  11682. * @param {string} [string=''] The string to escape.
  11683. * @returns {string} Returns the escaped string.
  11684. * @example
  11685. *
  11686. * _.escape('fred, barney, & pebbles');
  11687. * // => 'fred, barney, &amp; pebbles'
  11688. */
  11689. function escape(string) {
  11690. // Reset `lastIndex` because in IE < 9 `String#replace` does not.
  11691. string = baseToString(string);
  11692. return (string && reHasUnescapedHtml.test(string))
  11693. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  11694. : string;
  11695. }
  11696. /**
  11697. * Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
  11698. * "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
  11699. *
  11700. * @static
  11701. * @memberOf _
  11702. * @category String
  11703. * @param {string} [string=''] The string to escape.
  11704. * @returns {string} Returns the escaped string.
  11705. * @example
  11706. *
  11707. * _.escapeRegExp('[lodash](https://lodash.com/)');
  11708. * // => '\[lodash\]\(https:\/\/lodash\.com\/\)'
  11709. */
  11710. function escapeRegExp(string) {
  11711. string = baseToString(string);
  11712. return (string && reHasRegExpChars.test(string))
  11713. ? string.replace(reRegExpChars, escapeRegExpChar)
  11714. : (string || '(?:)');
  11715. }
  11716. /**
  11717. * Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  11718. *
  11719. * @static
  11720. * @memberOf _
  11721. * @category String
  11722. * @param {string} [string=''] The string to convert.
  11723. * @returns {string} Returns the kebab cased string.
  11724. * @example
  11725. *
  11726. * _.kebabCase('Foo Bar');
  11727. * // => 'foo-bar'
  11728. *
  11729. * _.kebabCase('fooBar');
  11730. * // => 'foo-bar'
  11731. *
  11732. * _.kebabCase('__foo_bar__');
  11733. * // => 'foo-bar'
  11734. */
  11735. var kebabCase = createCompounder(function(result, word, index) {
  11736. return result + (index ? '-' : '') + word.toLowerCase();
  11737. });
  11738. /**
  11739. * Pads `string` on the left and right sides if it's shorter than `length`.
  11740. * Padding characters are truncated if they can't be evenly divided by `length`.
  11741. *
  11742. * @static
  11743. * @memberOf _
  11744. * @category String
  11745. * @param {string} [string=''] The string to pad.
  11746. * @param {number} [length=0] The padding length.
  11747. * @param {string} [chars=' '] The string used as padding.
  11748. * @returns {string} Returns the padded string.
  11749. * @example
  11750. *
  11751. * _.pad('abc', 8);
  11752. * // => ' abc '
  11753. *
  11754. * _.pad('abc', 8, '_-');
  11755. * // => '_-abc_-_'
  11756. *
  11757. * _.pad('abc', 3);
  11758. * // => 'abc'
  11759. */
  11760. function pad(string, length, chars) {
  11761. string = baseToString(string);
  11762. length = +length;
  11763. var strLength = string.length;
  11764. if (strLength >= length || !nativeIsFinite(length)) {
  11765. return string;
  11766. }
  11767. var mid = (length - strLength) / 2,
  11768. leftLength = nativeFloor(mid),
  11769. rightLength = nativeCeil(mid);
  11770. chars = createPadding('', rightLength, chars);
  11771. return chars.slice(0, leftLength) + string + chars;
  11772. }
  11773. /**
  11774. * Pads `string` on the left side if it's shorter than `length`. Padding
  11775. * characters are truncated if they exceed `length`.
  11776. *
  11777. * @static
  11778. * @memberOf _
  11779. * @category String
  11780. * @param {string} [string=''] The string to pad.
  11781. * @param {number} [length=0] The padding length.
  11782. * @param {string} [chars=' '] The string used as padding.
  11783. * @returns {string} Returns the padded string.
  11784. * @example
  11785. *
  11786. * _.padLeft('abc', 6);
  11787. * // => ' abc'
  11788. *
  11789. * _.padLeft('abc', 6, '_-');
  11790. * // => '_-_abc'
  11791. *
  11792. * _.padLeft('abc', 3);
  11793. * // => 'abc'
  11794. */
  11795. var padLeft = createPadDir();
  11796. /**
  11797. * Pads `string` on the right side if it's shorter than `length`. Padding
  11798. * characters are truncated if they exceed `length`.
  11799. *
  11800. * @static
  11801. * @memberOf _
  11802. * @category String
  11803. * @param {string} [string=''] The string to pad.
  11804. * @param {number} [length=0] The padding length.
  11805. * @param {string} [chars=' '] The string used as padding.
  11806. * @returns {string} Returns the padded string.
  11807. * @example
  11808. *
  11809. * _.padRight('abc', 6);
  11810. * // => 'abc '
  11811. *
  11812. * _.padRight('abc', 6, '_-');
  11813. * // => 'abc_-_'
  11814. *
  11815. * _.padRight('abc', 3);
  11816. * // => 'abc'
  11817. */
  11818. var padRight = createPadDir(true);
  11819. /**
  11820. * Converts `string` to an integer of the specified radix. If `radix` is
  11821. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
  11822. * in which case a `radix` of `16` is used.
  11823. *
  11824. * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)
  11825. * of `parseInt`.
  11826. *
  11827. * @static
  11828. * @memberOf _
  11829. * @category String
  11830. * @param {string} string The string to convert.
  11831. * @param {number} [radix] The radix to interpret `value` by.
  11832. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  11833. * @returns {number} Returns the converted integer.
  11834. * @example
  11835. *
  11836. * _.parseInt('08');
  11837. * // => 8
  11838. *
  11839. * _.map(['6', '08', '10'], _.parseInt);
  11840. * // => [6, 8, 10]
  11841. */
  11842. function parseInt(string, radix, guard) {
  11843. // Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
  11844. // Chrome fails to trim leading <BOM> whitespace characters.
  11845. // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
  11846. if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
  11847. radix = 0;
  11848. } else if (radix) {
  11849. radix = +radix;
  11850. }
  11851. string = trim(string);
  11852. return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
  11853. }
  11854. /**
  11855. * Repeats the given string `n` times.
  11856. *
  11857. * @static
  11858. * @memberOf _
  11859. * @category String
  11860. * @param {string} [string=''] The string to repeat.
  11861. * @param {number} [n=0] The number of times to repeat the string.
  11862. * @returns {string} Returns the repeated string.
  11863. * @example
  11864. *
  11865. * _.repeat('*', 3);
  11866. * // => '***'
  11867. *
  11868. * _.repeat('abc', 2);
  11869. * // => 'abcabc'
  11870. *
  11871. * _.repeat('abc', 0);
  11872. * // => ''
  11873. */
  11874. function repeat(string, n) {
  11875. var result = '';
  11876. string = baseToString(string);
  11877. n = +n;
  11878. if (n < 1 || !string || !nativeIsFinite(n)) {
  11879. return result;
  11880. }
  11881. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  11882. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  11883. do {
  11884. if (n % 2) {
  11885. result += string;
  11886. }
  11887. n = nativeFloor(n / 2);
  11888. string += string;
  11889. } while (n);
  11890. return result;
  11891. }
  11892. /**
  11893. * Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
  11894. *
  11895. * @static
  11896. * @memberOf _
  11897. * @category String
  11898. * @param {string} [string=''] The string to convert.
  11899. * @returns {string} Returns the snake cased string.
  11900. * @example
  11901. *
  11902. * _.snakeCase('Foo Bar');
  11903. * // => 'foo_bar'
  11904. *
  11905. * _.snakeCase('fooBar');
  11906. * // => 'foo_bar'
  11907. *
  11908. * _.snakeCase('--foo-bar');
  11909. * // => 'foo_bar'
  11910. */
  11911. var snakeCase = createCompounder(function(result, word, index) {
  11912. return result + (index ? '_' : '') + word.toLowerCase();
  11913. });
  11914. /**
  11915. * Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  11916. *
  11917. * @static
  11918. * @memberOf _
  11919. * @category String
  11920. * @param {string} [string=''] The string to convert.
  11921. * @returns {string} Returns the start cased string.
  11922. * @example
  11923. *
  11924. * _.startCase('--foo-bar');
  11925. * // => 'Foo Bar'
  11926. *
  11927. * _.startCase('fooBar');
  11928. * // => 'Foo Bar'
  11929. *
  11930. * _.startCase('__foo_bar__');
  11931. * // => 'Foo Bar'
  11932. */
  11933. var startCase = createCompounder(function(result, word, index) {
  11934. return result + (index ? ' ' : '') + (word.charAt(0).toUpperCase() + word.slice(1));
  11935. });
  11936. /**
  11937. * Checks if `string` starts with the given target string.
  11938. *
  11939. * @static
  11940. * @memberOf _
  11941. * @category String
  11942. * @param {string} [string=''] The string to search.
  11943. * @param {string} [target] The string to search for.
  11944. * @param {number} [position=0] The position to search from.
  11945. * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
  11946. * @example
  11947. *
  11948. * _.startsWith('abc', 'a');
  11949. * // => true
  11950. *
  11951. * _.startsWith('abc', 'b');
  11952. * // => false
  11953. *
  11954. * _.startsWith('abc', 'b', 1);
  11955. * // => true
  11956. */
  11957. function startsWith(string, target, position) {
  11958. string = baseToString(string);
  11959. position = position == null
  11960. ? 0
  11961. : nativeMin(position < 0 ? 0 : (+position || 0), string.length);
  11962. return string.lastIndexOf(target, position) == position;
  11963. }
  11964. /**
  11965. * Creates a compiled template function that can interpolate data properties
  11966. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  11967. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  11968. * properties may be accessed as free variables in the template. If a setting
  11969. * object is provided it takes precedence over `_.templateSettings` values.
  11970. *
  11971. * **Note:** In the development build `_.template` utilizes
  11972. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  11973. * for easier debugging.
  11974. *
  11975. * For more information on precompiling templates see
  11976. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  11977. *
  11978. * For more information on Chrome extension sandboxes see
  11979. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  11980. *
  11981. * @static
  11982. * @memberOf _
  11983. * @category String
  11984. * @param {string} [string=''] The template string.
  11985. * @param {Object} [options] The options object.
  11986. * @param {RegExp} [options.escape] The HTML "escape" delimiter.
  11987. * @param {RegExp} [options.evaluate] The "evaluate" delimiter.
  11988. * @param {Object} [options.imports] An object to import into the template as free variables.
  11989. * @param {RegExp} [options.interpolate] The "interpolate" delimiter.
  11990. * @param {string} [options.sourceURL] The sourceURL of the template's compiled source.
  11991. * @param {string} [options.variable] The data object variable name.
  11992. * @param- {Object} [otherOptions] Enables the legacy `options` param signature.
  11993. * @returns {Function} Returns the compiled template function.
  11994. * @example
  11995. *
  11996. * // using the "interpolate" delimiter to create a compiled template
  11997. * var compiled = _.template('hello <%= user %>!');
  11998. * compiled({ 'user': 'fred' });
  11999. * // => 'hello fred!'
  12000. *
  12001. * // using the HTML "escape" delimiter to escape data property values
  12002. * var compiled = _.template('<b><%- value %></b>');
  12003. * compiled({ 'value': '<script>' });
  12004. * // => '<b>&lt;script&gt;</b>'
  12005. *
  12006. * // using the "evaluate" delimiter to execute JavaScript and generate HTML
  12007. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  12008. * compiled({ 'users': ['fred', 'barney'] });
  12009. * // => '<li>fred</li><li>barney</li>'
  12010. *
  12011. * // using the internal `print` function in "evaluate" delimiters
  12012. * var compiled = _.template('<% print("hello " + user); %>!');
  12013. * compiled({ 'user': 'barney' });
  12014. * // => 'hello barney!'
  12015. *
  12016. * // using the ES delimiter as an alternative to the default "interpolate" delimiter
  12017. * var compiled = _.template('hello ${ user }!');
  12018. * compiled({ 'user': 'pebbles' });
  12019. * // => 'hello pebbles!'
  12020. *
  12021. * // using custom template delimiters
  12022. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  12023. * var compiled = _.template('hello {{ user }}!');
  12024. * compiled({ 'user': 'mustache' });
  12025. * // => 'hello mustache!'
  12026. *
  12027. * // using backslashes to treat delimiters as plain text
  12028. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  12029. * compiled({ 'value': 'ignored' });
  12030. * // => '<%- value %>'
  12031. *
  12032. * // using the `imports` option to import `jQuery` as `jq`
  12033. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  12034. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  12035. * compiled({ 'users': ['fred', 'barney'] });
  12036. * // => '<li>fred</li><li>barney</li>'
  12037. *
  12038. * // using the `sourceURL` option to specify a custom sourceURL for the template
  12039. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  12040. * compiled(data);
  12041. * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
  12042. *
  12043. * // using the `variable` option to ensure a with-statement isn't used in the compiled template
  12044. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  12045. * compiled.source;
  12046. * // => function(data) {
  12047. * // var __t, __p = '';
  12048. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  12049. * // return __p;
  12050. * // }
  12051. *
  12052. * // using the `source` property to inline compiled templates for meaningful
  12053. * // line numbers in error messages and a stack trace
  12054. * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
  12055. * var JST = {\
  12056. * "main": ' + _.template(mainText).source + '\
  12057. * };\
  12058. * ');
  12059. */
  12060. function template(string, options, otherOptions) {
  12061. // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
  12062. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  12063. var settings = lodash.templateSettings;
  12064. if (otherOptions && isIterateeCall(string, options, otherOptions)) {
  12065. options = otherOptions = undefined;
  12066. }
  12067. string = baseToString(string);
  12068. options = assignWith(baseAssign({}, otherOptions || options), settings, assignOwnDefaults);
  12069. var imports = assignWith(baseAssign({}, options.imports), settings.imports, assignOwnDefaults),
  12070. importsKeys = keys(imports),
  12071. importsValues = baseValues(imports, importsKeys);
  12072. var isEscaping,
  12073. isEvaluating,
  12074. index = 0,
  12075. interpolate = options.interpolate || reNoMatch,
  12076. source = "__p += '";
  12077. // Compile the regexp to match each delimiter.
  12078. var reDelimiters = RegExp(
  12079. (options.escape || reNoMatch).source + '|' +
  12080. interpolate.source + '|' +
  12081. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  12082. (options.evaluate || reNoMatch).source + '|$'
  12083. , 'g');
  12084. // Use a sourceURL for easier debugging.
  12085. var sourceURL = '//# sourceURL=' +
  12086. ('sourceURL' in options
  12087. ? options.sourceURL
  12088. : ('lodash.templateSources[' + (++templateCounter) + ']')
  12089. ) + '\n';
  12090. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  12091. interpolateValue || (interpolateValue = esTemplateValue);
  12092. // Escape characters that can't be included in string literals.
  12093. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  12094. // Replace delimiters with snippets.
  12095. if (escapeValue) {
  12096. isEscaping = true;
  12097. source += "' +\n__e(" + escapeValue + ") +\n'";
  12098. }
  12099. if (evaluateValue) {
  12100. isEvaluating = true;
  12101. source += "';\n" + evaluateValue + ";\n__p += '";
  12102. }
  12103. if (interpolateValue) {
  12104. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  12105. }
  12106. index = offset + match.length;
  12107. // The JS engine embedded in Adobe products requires returning the `match`
  12108. // string in order to produce the correct `offset` value.
  12109. return match;
  12110. });
  12111. source += "';\n";
  12112. // If `variable` is not specified wrap a with-statement around the generated
  12113. // code to add the data object to the top of the scope chain.
  12114. var variable = options.variable;
  12115. if (!variable) {
  12116. source = 'with (obj) {\n' + source + '\n}\n';
  12117. }
  12118. // Cleanup code by stripping empty strings.
  12119. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  12120. .replace(reEmptyStringMiddle, '$1')
  12121. .replace(reEmptyStringTrailing, '$1;');
  12122. // Frame code as the function body.
  12123. source = 'function(' + (variable || 'obj') + ') {\n' +
  12124. (variable
  12125. ? ''
  12126. : 'obj || (obj = {});\n'
  12127. ) +
  12128. "var __t, __p = ''" +
  12129. (isEscaping
  12130. ? ', __e = _.escape'
  12131. : ''
  12132. ) +
  12133. (isEvaluating
  12134. ? ', __j = Array.prototype.join;\n' +
  12135. "function print() { __p += __j.call(arguments, '') }\n"
  12136. : ';\n'
  12137. ) +
  12138. source +
  12139. 'return __p\n}';
  12140. var result = attempt(function() {
  12141. return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues);
  12142. });
  12143. // Provide the compiled function's source by its `toString` method or
  12144. // the `source` property as a convenience for inlining compiled templates.
  12145. result.source = source;
  12146. if (isError(result)) {
  12147. throw result;
  12148. }
  12149. return result;
  12150. }
  12151. /**
  12152. * Removes leading and trailing whitespace or specified characters from `string`.
  12153. *
  12154. * @static
  12155. * @memberOf _
  12156. * @category String
  12157. * @param {string} [string=''] The string to trim.
  12158. * @param {string} [chars=whitespace] The characters to trim.
  12159. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  12160. * @returns {string} Returns the trimmed string.
  12161. * @example
  12162. *
  12163. * _.trim(' abc ');
  12164. * // => 'abc'
  12165. *
  12166. * _.trim('-_-abc-_-', '_-');
  12167. * // => 'abc'
  12168. *
  12169. * _.map([' foo ', ' bar '], _.trim);
  12170. * // => ['foo', 'bar']
  12171. */
  12172. function trim(string, chars, guard) {
  12173. var value = string;
  12174. string = baseToString(string);
  12175. if (!string) {
  12176. return string;
  12177. }
  12178. if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
  12179. return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
  12180. }
  12181. chars = (chars + '');
  12182. return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
  12183. }
  12184. /**
  12185. * Removes leading whitespace or specified characters from `string`.
  12186. *
  12187. * @static
  12188. * @memberOf _
  12189. * @category String
  12190. * @param {string} [string=''] The string to trim.
  12191. * @param {string} [chars=whitespace] The characters to trim.
  12192. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  12193. * @returns {string} Returns the trimmed string.
  12194. * @example
  12195. *
  12196. * _.trimLeft(' abc ');
  12197. * // => 'abc '
  12198. *
  12199. * _.trimLeft('-_-abc-_-', '_-');
  12200. * // => 'abc-_-'
  12201. */
  12202. function trimLeft(string, chars, guard) {
  12203. var value = string;
  12204. string = baseToString(string);
  12205. if (!string) {
  12206. return string;
  12207. }
  12208. if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
  12209. return string.slice(trimmedLeftIndex(string));
  12210. }
  12211. return string.slice(charsLeftIndex(string, (chars + '')));
  12212. }
  12213. /**
  12214. * Removes trailing whitespace or specified characters from `string`.
  12215. *
  12216. * @static
  12217. * @memberOf _
  12218. * @category String
  12219. * @param {string} [string=''] The string to trim.
  12220. * @param {string} [chars=whitespace] The characters to trim.
  12221. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  12222. * @returns {string} Returns the trimmed string.
  12223. * @example
  12224. *
  12225. * _.trimRight(' abc ');
  12226. * // => ' abc'
  12227. *
  12228. * _.trimRight('-_-abc-_-', '_-');
  12229. * // => '-_-abc'
  12230. */
  12231. function trimRight(string, chars, guard) {
  12232. var value = string;
  12233. string = baseToString(string);
  12234. if (!string) {
  12235. return string;
  12236. }
  12237. if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
  12238. return string.slice(0, trimmedRightIndex(string) + 1);
  12239. }
  12240. return string.slice(0, charsRightIndex(string, (chars + '')) + 1);
  12241. }
  12242. /**
  12243. * Truncates `string` if it's longer than the given maximum string length.
  12244. * The last characters of the truncated string are replaced with the omission
  12245. * string which defaults to "...".
  12246. *
  12247. * @static
  12248. * @memberOf _
  12249. * @category String
  12250. * @param {string} [string=''] The string to truncate.
  12251. * @param {Object|number} [options] The options object or maximum string length.
  12252. * @param {number} [options.length=30] The maximum string length.
  12253. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  12254. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  12255. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  12256. * @returns {string} Returns the truncated string.
  12257. * @example
  12258. *
  12259. * _.trunc('hi-diddly-ho there, neighborino');
  12260. * // => 'hi-diddly-ho there, neighbo...'
  12261. *
  12262. * _.trunc('hi-diddly-ho there, neighborino', 24);
  12263. * // => 'hi-diddly-ho there, n...'
  12264. *
  12265. * _.trunc('hi-diddly-ho there, neighborino', {
  12266. * 'length': 24,
  12267. * 'separator': ' '
  12268. * });
  12269. * // => 'hi-diddly-ho there,...'
  12270. *
  12271. * _.trunc('hi-diddly-ho there, neighborino', {
  12272. * 'length': 24,
  12273. * 'separator': /,? +/
  12274. * });
  12275. * // => 'hi-diddly-ho there...'
  12276. *
  12277. * _.trunc('hi-diddly-ho there, neighborino', {
  12278. * 'omission': ' [...]'
  12279. * });
  12280. * // => 'hi-diddly-ho there, neig [...]'
  12281. */
  12282. function trunc(string, options, guard) {
  12283. if (guard && isIterateeCall(string, options, guard)) {
  12284. options = undefined;
  12285. }
  12286. var length = DEFAULT_TRUNC_LENGTH,
  12287. omission = DEFAULT_TRUNC_OMISSION;
  12288. if (options != null) {
  12289. if (isObject(options)) {
  12290. var separator = 'separator' in options ? options.separator : separator;
  12291. length = 'length' in options ? (+options.length || 0) : length;
  12292. omission = 'omission' in options ? baseToString(options.omission) : omission;
  12293. } else {
  12294. length = +options || 0;
  12295. }
  12296. }
  12297. string = baseToString(string);
  12298. if (length >= string.length) {
  12299. return string;
  12300. }
  12301. var end = length - omission.length;
  12302. if (end < 1) {
  12303. return omission;
  12304. }
  12305. var result = string.slice(0, end);
  12306. if (separator == null) {
  12307. return result + omission;
  12308. }
  12309. if (isRegExp(separator)) {
  12310. if (string.slice(end).search(separator)) {
  12311. var match,
  12312. newEnd,
  12313. substring = string.slice(0, end);
  12314. if (!separator.global) {
  12315. separator = RegExp(separator.source, (reFlags.exec(separator) || '') + 'g');
  12316. }
  12317. separator.lastIndex = 0;
  12318. while ((match = separator.exec(substring))) {
  12319. newEnd = match.index;
  12320. }
  12321. result = result.slice(0, newEnd == null ? end : newEnd);
  12322. }
  12323. } else if (string.indexOf(separator, end) != end) {
  12324. var index = result.lastIndexOf(separator);
  12325. if (index > -1) {
  12326. result = result.slice(0, index);
  12327. }
  12328. }
  12329. return result + omission;
  12330. }
  12331. /**
  12332. * The inverse of `_.escape`; this method converts the HTML entities
  12333. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&#39;`, and `&#96;` in `string` to their
  12334. * corresponding characters.
  12335. *
  12336. * **Note:** No other HTML entities are unescaped. To unescape additional HTML
  12337. * entities use a third-party library like [_he_](https://mths.be/he).
  12338. *
  12339. * @static
  12340. * @memberOf _
  12341. * @category String
  12342. * @param {string} [string=''] The string to unescape.
  12343. * @returns {string} Returns the unescaped string.
  12344. * @example
  12345. *
  12346. * _.unescape('fred, barney, &amp; pebbles');
  12347. * // => 'fred, barney, & pebbles'
  12348. */
  12349. function unescape(string) {
  12350. string = baseToString(string);
  12351. return (string && reHasEscapedHtml.test(string))
  12352. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  12353. : string;
  12354. }
  12355. /**
  12356. * Splits `string` into an array of its words.
  12357. *
  12358. * @static
  12359. * @memberOf _
  12360. * @category String
  12361. * @param {string} [string=''] The string to inspect.
  12362. * @param {RegExp|string} [pattern] The pattern to match words.
  12363. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  12364. * @returns {Array} Returns the words of `string`.
  12365. * @example
  12366. *
  12367. * _.words('fred, barney, & pebbles');
  12368. * // => ['fred', 'barney', 'pebbles']
  12369. *
  12370. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  12371. * // => ['fred', 'barney', '&', 'pebbles']
  12372. */
  12373. function words(string, pattern, guard) {
  12374. if (guard && isIterateeCall(string, pattern, guard)) {
  12375. pattern = undefined;
  12376. }
  12377. string = baseToString(string);
  12378. return string.match(pattern || reWords) || [];
  12379. }
  12380. /*------------------------------------------------------------------------*/
  12381. /**
  12382. * Attempts to invoke `func`, returning either the result or the caught error
  12383. * object. Any additional arguments are provided to `func` when it is invoked.
  12384. *
  12385. * @static
  12386. * @memberOf _
  12387. * @category Utility
  12388. * @param {Function} func The function to attempt.
  12389. * @returns {*} Returns the `func` result or error object.
  12390. * @example
  12391. *
  12392. * // avoid throwing errors for invalid selectors
  12393. * var elements = _.attempt(function(selector) {
  12394. * return document.querySelectorAll(selector);
  12395. * }, '>_>');
  12396. *
  12397. * if (_.isError(elements)) {
  12398. * elements = [];
  12399. * }
  12400. */
  12401. var attempt = restParam(function(func, args) {
  12402. try {
  12403. return func.apply(undefined, args);
  12404. } catch(e) {
  12405. return isError(e) ? e : new Error(e);
  12406. }
  12407. });
  12408. /**
  12409. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  12410. * and arguments of the created function. If `func` is a property name the
  12411. * created callback returns the property value for a given element. If `func`
  12412. * is an object the created callback returns `true` for elements that contain
  12413. * the equivalent object properties, otherwise it returns `false`.
  12414. *
  12415. * @static
  12416. * @memberOf _
  12417. * @alias iteratee
  12418. * @category Utility
  12419. * @param {*} [func=_.identity] The value to convert to a callback.
  12420. * @param {*} [thisArg] The `this` binding of `func`.
  12421. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  12422. * @returns {Function} Returns the callback.
  12423. * @example
  12424. *
  12425. * var users = [
  12426. * { 'user': 'barney', 'age': 36 },
  12427. * { 'user': 'fred', 'age': 40 }
  12428. * ];
  12429. *
  12430. * // wrap to create custom callback shorthands
  12431. * _.callback = _.wrap(_.callback, function(callback, func, thisArg) {
  12432. * var match = /^(.+?)__([gl]t)(.+)$/.exec(func);
  12433. * if (!match) {
  12434. * return callback(func, thisArg);
  12435. * }
  12436. * return function(object) {
  12437. * return match[2] == 'gt'
  12438. * ? object[match[1]] > match[3]
  12439. * : object[match[1]] < match[3];
  12440. * };
  12441. * });
  12442. *
  12443. * _.filter(users, 'age__gt36');
  12444. * // => [{ 'user': 'fred', 'age': 40 }]
  12445. */
  12446. function callback(func, thisArg, guard) {
  12447. if (guard && isIterateeCall(func, thisArg, guard)) {
  12448. thisArg = undefined;
  12449. }
  12450. return isObjectLike(func)
  12451. ? matches(func)
  12452. : baseCallback(func, thisArg);
  12453. }
  12454. /**
  12455. * Creates a function that returns `value`.
  12456. *
  12457. * @static
  12458. * @memberOf _
  12459. * @category Utility
  12460. * @param {*} value The value to return from the new function.
  12461. * @returns {Function} Returns the new function.
  12462. * @example
  12463. *
  12464. * var object = { 'user': 'fred' };
  12465. * var getter = _.constant(object);
  12466. *
  12467. * getter() === object;
  12468. * // => true
  12469. */
  12470. function constant(value) {
  12471. return function() {
  12472. return value;
  12473. };
  12474. }
  12475. /**
  12476. * This method returns the first argument provided to it.
  12477. *
  12478. * @static
  12479. * @memberOf _
  12480. * @category Utility
  12481. * @param {*} value Any value.
  12482. * @returns {*} Returns `value`.
  12483. * @example
  12484. *
  12485. * var object = { 'user': 'fred' };
  12486. *
  12487. * _.identity(object) === object;
  12488. * // => true
  12489. */
  12490. function identity(value) {
  12491. return value;
  12492. }
  12493. /**
  12494. * Creates a function that performs a deep comparison between a given object
  12495. * and `source`, returning `true` if the given object has equivalent property
  12496. * values, else `false`.
  12497. *
  12498. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  12499. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  12500. * their own, not inherited, enumerable properties. For comparing a single
  12501. * own or inherited property value see `_.matchesProperty`.
  12502. *
  12503. * @static
  12504. * @memberOf _
  12505. * @category Utility
  12506. * @param {Object} source The object of property values to match.
  12507. * @returns {Function} Returns the new function.
  12508. * @example
  12509. *
  12510. * var users = [
  12511. * { 'user': 'barney', 'age': 36, 'active': true },
  12512. * { 'user': 'fred', 'age': 40, 'active': false }
  12513. * ];
  12514. *
  12515. * _.filter(users, _.matches({ 'age': 40, 'active': false }));
  12516. * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
  12517. */
  12518. function matches(source) {
  12519. return baseMatches(baseClone(source, true));
  12520. }
  12521. /**
  12522. * Creates a function that compares the property value of `path` on a given
  12523. * object to `value`.
  12524. *
  12525. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  12526. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  12527. * their own, not inherited, enumerable properties.
  12528. *
  12529. * @static
  12530. * @memberOf _
  12531. * @category Utility
  12532. * @param {Array|string} path The path of the property to get.
  12533. * @param {*} srcValue The value to match.
  12534. * @returns {Function} Returns the new function.
  12535. * @example
  12536. *
  12537. * var users = [
  12538. * { 'user': 'barney' },
  12539. * { 'user': 'fred' }
  12540. * ];
  12541. *
  12542. * _.find(users, _.matchesProperty('user', 'fred'));
  12543. * // => { 'user': 'fred' }
  12544. */
  12545. function matchesProperty(path, srcValue) {
  12546. return baseMatchesProperty(path, baseClone(srcValue, true));
  12547. }
  12548. /**
  12549. * Creates a function that invokes the method at `path` on a given object.
  12550. * Any additional arguments are provided to the invoked method.
  12551. *
  12552. * @static
  12553. * @memberOf _
  12554. * @category Utility
  12555. * @param {Array|string} path The path of the method to invoke.
  12556. * @param {...*} [args] The arguments to invoke the method with.
  12557. * @returns {Function} Returns the new function.
  12558. * @example
  12559. *
  12560. * var objects = [
  12561. * { 'a': { 'b': { 'c': _.constant(2) } } },
  12562. * { 'a': { 'b': { 'c': _.constant(1) } } }
  12563. * ];
  12564. *
  12565. * _.map(objects, _.method('a.b.c'));
  12566. * // => [2, 1]
  12567. *
  12568. * _.invoke(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c');
  12569. * // => [1, 2]
  12570. */
  12571. var method = restParam(function(path, args) {
  12572. return function(object) {
  12573. return invokePath(object, path, args);
  12574. };
  12575. });
  12576. /**
  12577. * The opposite of `_.method`; this method creates a function that invokes
  12578. * the method at a given path on `object`. Any additional arguments are
  12579. * provided to the invoked method.
  12580. *
  12581. * @static
  12582. * @memberOf _
  12583. * @category Utility
  12584. * @param {Object} object The object to query.
  12585. * @param {...*} [args] The arguments to invoke the method with.
  12586. * @returns {Function} Returns the new function.
  12587. * @example
  12588. *
  12589. * var array = _.times(3, _.constant),
  12590. * object = { 'a': array, 'b': array, 'c': array };
  12591. *
  12592. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  12593. * // => [2, 0]
  12594. *
  12595. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  12596. * // => [2, 0]
  12597. */
  12598. var methodOf = restParam(function(object, args) {
  12599. return function(path) {
  12600. return invokePath(object, path, args);
  12601. };
  12602. });
  12603. /**
  12604. * Adds all own enumerable function properties of a source object to the
  12605. * destination object. If `object` is a function then methods are added to
  12606. * its prototype as well.
  12607. *
  12608. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  12609. * avoid conflicts caused by modifying the original.
  12610. *
  12611. * @static
  12612. * @memberOf _
  12613. * @category Utility
  12614. * @param {Function|Object} [object=lodash] The destination object.
  12615. * @param {Object} source The object of functions to add.
  12616. * @param {Object} [options] The options object.
  12617. * @param {boolean} [options.chain=true] Specify whether the functions added
  12618. * are chainable.
  12619. * @returns {Function|Object} Returns `object`.
  12620. * @example
  12621. *
  12622. * function vowels(string) {
  12623. * return _.filter(string, function(v) {
  12624. * return /[aeiou]/i.test(v);
  12625. * });
  12626. * }
  12627. *
  12628. * _.mixin({ 'vowels': vowels });
  12629. * _.vowels('fred');
  12630. * // => ['e']
  12631. *
  12632. * _('fred').vowels().value();
  12633. * // => ['e']
  12634. *
  12635. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  12636. * _('fred').vowels();
  12637. * // => ['e']
  12638. */
  12639. function mixin(object, source, options) {
  12640. if (options == null) {
  12641. var isObj = isObject(source),
  12642. props = isObj ? keys(source) : undefined,
  12643. methodNames = (props && props.length) ? baseFunctions(source, props) : undefined;
  12644. if (!(methodNames ? methodNames.length : isObj)) {
  12645. methodNames = false;
  12646. options = source;
  12647. source = object;
  12648. object = this;
  12649. }
  12650. }
  12651. if (!methodNames) {
  12652. methodNames = baseFunctions(source, keys(source));
  12653. }
  12654. var chain = true,
  12655. index = -1,
  12656. isFunc = isFunction(object),
  12657. length = methodNames.length;
  12658. if (options === false) {
  12659. chain = false;
  12660. } else if (isObject(options) && 'chain' in options) {
  12661. chain = options.chain;
  12662. }
  12663. while (++index < length) {
  12664. var methodName = methodNames[index],
  12665. func = source[methodName];
  12666. object[methodName] = func;
  12667. if (isFunc) {
  12668. object.prototype[methodName] = (function(func) {
  12669. return function() {
  12670. var chainAll = this.__chain__;
  12671. if (chain || chainAll) {
  12672. var result = object(this.__wrapped__),
  12673. actions = result.__actions__ = arrayCopy(this.__actions__);
  12674. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  12675. result.__chain__ = chainAll;
  12676. return result;
  12677. }
  12678. return func.apply(object, arrayPush([this.value()], arguments));
  12679. };
  12680. }(func));
  12681. }
  12682. }
  12683. return object;
  12684. }
  12685. /**
  12686. * Reverts the `_` variable to its previous value and returns a reference to
  12687. * the `lodash` function.
  12688. *
  12689. * @static
  12690. * @memberOf _
  12691. * @category Utility
  12692. * @returns {Function} Returns the `lodash` function.
  12693. * @example
  12694. *
  12695. * var lodash = _.noConflict();
  12696. */
  12697. function noConflict() {
  12698. root._ = oldDash;
  12699. return this;
  12700. }
  12701. /**
  12702. * A no-operation function that returns `undefined` regardless of the
  12703. * arguments it receives.
  12704. *
  12705. * @static
  12706. * @memberOf _
  12707. * @category Utility
  12708. * @example
  12709. *
  12710. * var object = { 'user': 'fred' };
  12711. *
  12712. * _.noop(object) === undefined;
  12713. * // => true
  12714. */
  12715. function noop() {
  12716. // No operation performed.
  12717. }
  12718. /**
  12719. * Creates a function that returns the property value at `path` on a
  12720. * given object.
  12721. *
  12722. * @static
  12723. * @memberOf _
  12724. * @category Utility
  12725. * @param {Array|string} path The path of the property to get.
  12726. * @returns {Function} Returns the new function.
  12727. * @example
  12728. *
  12729. * var objects = [
  12730. * { 'a': { 'b': { 'c': 2 } } },
  12731. * { 'a': { 'b': { 'c': 1 } } }
  12732. * ];
  12733. *
  12734. * _.map(objects, _.property('a.b.c'));
  12735. * // => [2, 1]
  12736. *
  12737. * _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
  12738. * // => [1, 2]
  12739. */
  12740. function property(path) {
  12741. return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
  12742. }
  12743. /**
  12744. * The opposite of `_.property`; this method creates a function that returns
  12745. * the property value at a given path on `object`.
  12746. *
  12747. * @static
  12748. * @memberOf _
  12749. * @category Utility
  12750. * @param {Object} object The object to query.
  12751. * @returns {Function} Returns the new function.
  12752. * @example
  12753. *
  12754. * var array = [0, 1, 2],
  12755. * object = { 'a': array, 'b': array, 'c': array };
  12756. *
  12757. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  12758. * // => [2, 0]
  12759. *
  12760. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  12761. * // => [2, 0]
  12762. */
  12763. function propertyOf(object) {
  12764. return function(path) {
  12765. return baseGet(object, toPath(path), path + '');
  12766. };
  12767. }
  12768. /**
  12769. * Creates an array of numbers (positive and/or negative) progressing from
  12770. * `start` up to, but not including, `end`. If `end` is not specified it is
  12771. * set to `start` with `start` then set to `0`. If `end` is less than `start`
  12772. * a zero-length range is created unless a negative `step` is specified.
  12773. *
  12774. * @static
  12775. * @memberOf _
  12776. * @category Utility
  12777. * @param {number} [start=0] The start of the range.
  12778. * @param {number} end The end of the range.
  12779. * @param {number} [step=1] The value to increment or decrement by.
  12780. * @returns {Array} Returns the new array of numbers.
  12781. * @example
  12782. *
  12783. * _.range(4);
  12784. * // => [0, 1, 2, 3]
  12785. *
  12786. * _.range(1, 5);
  12787. * // => [1, 2, 3, 4]
  12788. *
  12789. * _.range(0, 20, 5);
  12790. * // => [0, 5, 10, 15]
  12791. *
  12792. * _.range(0, -4, -1);
  12793. * // => [0, -1, -2, -3]
  12794. *
  12795. * _.range(1, 4, 0);
  12796. * // => [1, 1, 1]
  12797. *
  12798. * _.range(0);
  12799. * // => []
  12800. */
  12801. function range(start, end, step) {
  12802. if (step && isIterateeCall(start, end, step)) {
  12803. end = step = undefined;
  12804. }
  12805. start = +start || 0;
  12806. step = step == null ? 1 : (+step || 0);
  12807. if (end == null) {
  12808. end = start;
  12809. start = 0;
  12810. } else {
  12811. end = +end || 0;
  12812. }
  12813. // Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
  12814. // See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
  12815. var index = -1,
  12816. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  12817. result = Array(length);
  12818. while (++index < length) {
  12819. result[index] = start;
  12820. start += step;
  12821. }
  12822. return result;
  12823. }
  12824. /**
  12825. * Invokes the iteratee function `n` times, returning an array of the results
  12826. * of each invocation. The `iteratee` is bound to `thisArg` and invoked with
  12827. * one argument; (index).
  12828. *
  12829. * @static
  12830. * @memberOf _
  12831. * @category Utility
  12832. * @param {number} n The number of times to invoke `iteratee`.
  12833. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12834. * @param {*} [thisArg] The `this` binding of `iteratee`.
  12835. * @returns {Array} Returns the array of results.
  12836. * @example
  12837. *
  12838. * var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
  12839. * // => [3, 6, 4]
  12840. *
  12841. * _.times(3, function(n) {
  12842. * mage.castSpell(n);
  12843. * });
  12844. * // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2`
  12845. *
  12846. * _.times(3, function(n) {
  12847. * this.cast(n);
  12848. * }, mage);
  12849. * // => also invokes `mage.castSpell(n)` three times
  12850. */
  12851. function times(n, iteratee, thisArg) {
  12852. n = nativeFloor(n);
  12853. // Exit early to avoid a JSC JIT bug in Safari 8
  12854. // where `Array(0)` is treated as `Array(1)`.
  12855. if (n < 1 || !nativeIsFinite(n)) {
  12856. return [];
  12857. }
  12858. var index = -1,
  12859. result = Array(nativeMin(n, MAX_ARRAY_LENGTH));
  12860. iteratee = bindCallback(iteratee, thisArg, 1);
  12861. while (++index < n) {
  12862. if (index < MAX_ARRAY_LENGTH) {
  12863. result[index] = iteratee(index);
  12864. } else {
  12865. iteratee(index);
  12866. }
  12867. }
  12868. return result;
  12869. }
  12870. /**
  12871. * Generates a unique ID. If `prefix` is provided the ID is appended to it.
  12872. *
  12873. * @static
  12874. * @memberOf _
  12875. * @category Utility
  12876. * @param {string} [prefix] The value to prefix the ID with.
  12877. * @returns {string} Returns the unique ID.
  12878. * @example
  12879. *
  12880. * _.uniqueId('contact_');
  12881. * // => 'contact_104'
  12882. *
  12883. * _.uniqueId();
  12884. * // => '105'
  12885. */
  12886. function uniqueId(prefix) {
  12887. var id = ++idCounter;
  12888. return baseToString(prefix) + id;
  12889. }
  12890. /*------------------------------------------------------------------------*/
  12891. /**
  12892. * Adds two numbers.
  12893. *
  12894. * @static
  12895. * @memberOf _
  12896. * @category Math
  12897. * @param {number} augend The first number to add.
  12898. * @param {number} addend The second number to add.
  12899. * @returns {number} Returns the sum.
  12900. * @example
  12901. *
  12902. * _.add(6, 4);
  12903. * // => 10
  12904. */
  12905. function add(augend, addend) {
  12906. return (+augend || 0) + (+addend || 0);
  12907. }
  12908. /**
  12909. * Calculates `n` rounded up to `precision`.
  12910. *
  12911. * @static
  12912. * @memberOf _
  12913. * @category Math
  12914. * @param {number} n The number to round up.
  12915. * @param {number} [precision=0] The precision to round up to.
  12916. * @returns {number} Returns the rounded up number.
  12917. * @example
  12918. *
  12919. * _.ceil(4.006);
  12920. * // => 5
  12921. *
  12922. * _.ceil(6.004, 2);
  12923. * // => 6.01
  12924. *
  12925. * _.ceil(6040, -2);
  12926. * // => 6100
  12927. */
  12928. var ceil = createRound('ceil');
  12929. /**
  12930. * Calculates `n` rounded down to `precision`.
  12931. *
  12932. * @static
  12933. * @memberOf _
  12934. * @category Math
  12935. * @param {number} n The number to round down.
  12936. * @param {number} [precision=0] The precision to round down to.
  12937. * @returns {number} Returns the rounded down number.
  12938. * @example
  12939. *
  12940. * _.floor(4.006);
  12941. * // => 4
  12942. *
  12943. * _.floor(0.046, 2);
  12944. * // => 0.04
  12945. *
  12946. * _.floor(4060, -2);
  12947. * // => 4000
  12948. */
  12949. var floor = createRound('floor');
  12950. /**
  12951. * Gets the maximum value of `collection`. If `collection` is empty or falsey
  12952. * `-Infinity` is returned. If an iteratee function is provided it is invoked
  12953. * for each value in `collection` to generate the criterion by which the value
  12954. * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
  12955. * arguments: (value, index, collection).
  12956. *
  12957. * If a property name is provided for `iteratee` the created `_.property`
  12958. * style callback returns the property value of the given element.
  12959. *
  12960. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  12961. * style callback returns `true` for elements that have a matching property
  12962. * value, else `false`.
  12963. *
  12964. * If an object is provided for `iteratee` the created `_.matches` style
  12965. * callback returns `true` for elements that have the properties of the given
  12966. * object, else `false`.
  12967. *
  12968. * @static
  12969. * @memberOf _
  12970. * @category Math
  12971. * @param {Array|Object|string} collection The collection to iterate over.
  12972. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  12973. * @param {*} [thisArg] The `this` binding of `iteratee`.
  12974. * @returns {*} Returns the maximum value.
  12975. * @example
  12976. *
  12977. * _.max([4, 2, 8, 6]);
  12978. * // => 8
  12979. *
  12980. * _.max([]);
  12981. * // => -Infinity
  12982. *
  12983. * var users = [
  12984. * { 'user': 'barney', 'age': 36 },
  12985. * { 'user': 'fred', 'age': 40 }
  12986. * ];
  12987. *
  12988. * _.max(users, function(chr) {
  12989. * return chr.age;
  12990. * });
  12991. * // => { 'user': 'fred', 'age': 40 }
  12992. *
  12993. * // using the `_.property` callback shorthand
  12994. * _.max(users, 'age');
  12995. * // => { 'user': 'fred', 'age': 40 }
  12996. */
  12997. var max = createExtremum(gt, NEGATIVE_INFINITY);
  12998. /**
  12999. * Gets the minimum value of `collection`. If `collection` is empty or falsey
  13000. * `Infinity` is returned. If an iteratee function is provided it is invoked
  13001. * for each value in `collection` to generate the criterion by which the value
  13002. * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
  13003. * arguments: (value, index, collection).
  13004. *
  13005. * If a property name is provided for `iteratee` the created `_.property`
  13006. * style callback returns the property value of the given element.
  13007. *
  13008. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  13009. * style callback returns `true` for elements that have a matching property
  13010. * value, else `false`.
  13011. *
  13012. * If an object is provided for `iteratee` the created `_.matches` style
  13013. * callback returns `true` for elements that have the properties of the given
  13014. * object, else `false`.
  13015. *
  13016. * @static
  13017. * @memberOf _
  13018. * @category Math
  13019. * @param {Array|Object|string} collection The collection to iterate over.
  13020. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  13021. * @param {*} [thisArg] The `this` binding of `iteratee`.
  13022. * @returns {*} Returns the minimum value.
  13023. * @example
  13024. *
  13025. * _.min([4, 2, 8, 6]);
  13026. * // => 2
  13027. *
  13028. * _.min([]);
  13029. * // => Infinity
  13030. *
  13031. * var users = [
  13032. * { 'user': 'barney', 'age': 36 },
  13033. * { 'user': 'fred', 'age': 40 }
  13034. * ];
  13035. *
  13036. * _.min(users, function(chr) {
  13037. * return chr.age;
  13038. * });
  13039. * // => { 'user': 'barney', 'age': 36 }
  13040. *
  13041. * // using the `_.property` callback shorthand
  13042. * _.min(users, 'age');
  13043. * // => { 'user': 'barney', 'age': 36 }
  13044. */
  13045. var min = createExtremum(lt, POSITIVE_INFINITY);
  13046. /**
  13047. * Calculates `n` rounded to `precision`.
  13048. *
  13049. * @static
  13050. * @memberOf _
  13051. * @category Math
  13052. * @param {number} n The number to round.
  13053. * @param {number} [precision=0] The precision to round to.
  13054. * @returns {number} Returns the rounded number.
  13055. * @example
  13056. *
  13057. * _.round(4.006);
  13058. * // => 4
  13059. *
  13060. * _.round(4.006, 2);
  13061. * // => 4.01
  13062. *
  13063. * _.round(4060, -2);
  13064. * // => 4100
  13065. */
  13066. var round = createRound('round');
  13067. /**
  13068. * Gets the sum of the values in `collection`.
  13069. *
  13070. * @static
  13071. * @memberOf _
  13072. * @category Math
  13073. * @param {Array|Object|string} collection The collection to iterate over.
  13074. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  13075. * @param {*} [thisArg] The `this` binding of `iteratee`.
  13076. * @returns {number} Returns the sum.
  13077. * @example
  13078. *
  13079. * _.sum([4, 6]);
  13080. * // => 10
  13081. *
  13082. * _.sum({ 'a': 4, 'b': 6 });
  13083. * // => 10
  13084. *
  13085. * var objects = [
  13086. * { 'n': 4 },
  13087. * { 'n': 6 }
  13088. * ];
  13089. *
  13090. * _.sum(objects, function(object) {
  13091. * return object.n;
  13092. * });
  13093. * // => 10
  13094. *
  13095. * // using the `_.property` callback shorthand
  13096. * _.sum(objects, 'n');
  13097. * // => 10
  13098. */
  13099. function sum(collection, iteratee, thisArg) {
  13100. if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
  13101. iteratee = undefined;
  13102. }
  13103. iteratee = getCallback(iteratee, thisArg, 3);
  13104. return iteratee.length == 1
  13105. ? arraySum(isArray(collection) ? collection : toIterable(collection), iteratee)
  13106. : baseSum(collection, iteratee);
  13107. }
  13108. /*------------------------------------------------------------------------*/
  13109. // Ensure wrappers are instances of `baseLodash`.
  13110. lodash.prototype = baseLodash.prototype;
  13111. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  13112. LodashWrapper.prototype.constructor = LodashWrapper;
  13113. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  13114. LazyWrapper.prototype.constructor = LazyWrapper;
  13115. // Add functions to the `Map` cache.
  13116. MapCache.prototype['delete'] = mapDelete;
  13117. MapCache.prototype.get = mapGet;
  13118. MapCache.prototype.has = mapHas;
  13119. MapCache.prototype.set = mapSet;
  13120. // Add functions to the `Set` cache.
  13121. SetCache.prototype.push = cachePush;
  13122. // Assign cache to `_.memoize`.
  13123. memoize.Cache = MapCache;
  13124. // Add functions that return wrapped values when chaining.
  13125. lodash.after = after;
  13126. lodash.ary = ary;
  13127. lodash.assign = assign;
  13128. lodash.at = at;
  13129. lodash.before = before;
  13130. lodash.bind = bind;
  13131. lodash.bindAll = bindAll;
  13132. lodash.bindKey = bindKey;
  13133. lodash.callback = callback;
  13134. lodash.chain = chain;
  13135. lodash.chunk = chunk;
  13136. lodash.compact = compact;
  13137. lodash.constant = constant;
  13138. lodash.countBy = countBy;
  13139. lodash.create = create;
  13140. lodash.curry = curry;
  13141. lodash.curryRight = curryRight;
  13142. lodash.debounce = debounce;
  13143. lodash.defaults = defaults;
  13144. lodash.defaultsDeep = defaultsDeep;
  13145. lodash.defer = defer;
  13146. lodash.delay = delay;
  13147. lodash.difference = difference;
  13148. lodash.drop = drop;
  13149. lodash.dropRight = dropRight;
  13150. lodash.dropRightWhile = dropRightWhile;
  13151. lodash.dropWhile = dropWhile;
  13152. lodash.fill = fill;
  13153. lodash.filter = filter;
  13154. lodash.flatten = flatten;
  13155. lodash.flattenDeep = flattenDeep;
  13156. lodash.flow = flow;
  13157. lodash.flowRight = flowRight;
  13158. lodash.forEach = forEach;
  13159. lodash.forEachRight = forEachRight;
  13160. lodash.forIn = forIn;
  13161. lodash.forInRight = forInRight;
  13162. lodash.forOwn = forOwn;
  13163. lodash.forOwnRight = forOwnRight;
  13164. lodash.functions = functions;
  13165. lodash.groupBy = groupBy;
  13166. lodash.indexBy = indexBy;
  13167. lodash.initial = initial;
  13168. lodash.intersection = intersection;
  13169. lodash.invert = invert;
  13170. lodash.invoke = invoke;
  13171. lodash.keys = keys;
  13172. lodash.keysIn = keysIn;
  13173. lodash.map = map;
  13174. lodash.mapKeys = mapKeys;
  13175. lodash.mapValues = mapValues;
  13176. lodash.matches = matches;
  13177. lodash.matchesProperty = matchesProperty;
  13178. lodash.memoize = memoize;
  13179. lodash.merge = merge;
  13180. lodash.method = method;
  13181. lodash.methodOf = methodOf;
  13182. lodash.mixin = mixin;
  13183. lodash.modArgs = modArgs;
  13184. lodash.negate = negate;
  13185. lodash.omit = omit;
  13186. lodash.once = once;
  13187. lodash.pairs = pairs;
  13188. lodash.partial = partial;
  13189. lodash.partialRight = partialRight;
  13190. lodash.partition = partition;
  13191. lodash.pick = pick;
  13192. lodash.pluck = pluck;
  13193. lodash.property = property;
  13194. lodash.propertyOf = propertyOf;
  13195. lodash.pull = pull;
  13196. lodash.pullAt = pullAt;
  13197. lodash.range = range;
  13198. lodash.rearg = rearg;
  13199. lodash.reject = reject;
  13200. lodash.remove = remove;
  13201. lodash.rest = rest;
  13202. lodash.restParam = restParam;
  13203. lodash.set = set;
  13204. lodash.shuffle = shuffle;
  13205. lodash.slice = slice;
  13206. lodash.sortBy = sortBy;
  13207. lodash.sortByAll = sortByAll;
  13208. lodash.sortByOrder = sortByOrder;
  13209. lodash.spread = spread;
  13210. lodash.take = take;
  13211. lodash.takeRight = takeRight;
  13212. lodash.takeRightWhile = takeRightWhile;
  13213. lodash.takeWhile = takeWhile;
  13214. lodash.tap = tap;
  13215. lodash.throttle = throttle;
  13216. lodash.thru = thru;
  13217. lodash.times = times;
  13218. lodash.toArray = toArray;
  13219. lodash.toPlainObject = toPlainObject;
  13220. lodash.transform = transform;
  13221. lodash.union = union;
  13222. lodash.uniq = uniq;
  13223. lodash.unzip = unzip;
  13224. lodash.unzipWith = unzipWith;
  13225. lodash.values = values;
  13226. lodash.valuesIn = valuesIn;
  13227. lodash.where = where;
  13228. lodash.without = without;
  13229. lodash.wrap = wrap;
  13230. lodash.xor = xor;
  13231. lodash.zip = zip;
  13232. lodash.zipObject = zipObject;
  13233. lodash.zipWith = zipWith;
  13234. // Add aliases.
  13235. lodash.backflow = flowRight;
  13236. lodash.collect = map;
  13237. lodash.compose = flowRight;
  13238. lodash.each = forEach;
  13239. lodash.eachRight = forEachRight;
  13240. lodash.extend = assign;
  13241. lodash.iteratee = callback;
  13242. lodash.methods = functions;
  13243. lodash.object = zipObject;
  13244. lodash.select = filter;
  13245. lodash.tail = rest;
  13246. lodash.unique = uniq;
  13247. // Add functions to `lodash.prototype`.
  13248. mixin(lodash, lodash);
  13249. /*------------------------------------------------------------------------*/
  13250. // Add functions that return unwrapped values when chaining.
  13251. lodash.add = add;
  13252. lodash.attempt = attempt;
  13253. lodash.camelCase = camelCase;
  13254. lodash.capitalize = capitalize;
  13255. lodash.ceil = ceil;
  13256. lodash.clone = clone;
  13257. lodash.cloneDeep = cloneDeep;
  13258. lodash.deburr = deburr;
  13259. lodash.endsWith = endsWith;
  13260. lodash.escape = escape;
  13261. lodash.escapeRegExp = escapeRegExp;
  13262. lodash.every = every;
  13263. lodash.find = find;
  13264. lodash.findIndex = findIndex;
  13265. lodash.findKey = findKey;
  13266. lodash.findLast = findLast;
  13267. lodash.findLastIndex = findLastIndex;
  13268. lodash.findLastKey = findLastKey;
  13269. lodash.findWhere = findWhere;
  13270. lodash.first = first;
  13271. lodash.floor = floor;
  13272. lodash.get = get;
  13273. lodash.gt = gt;
  13274. lodash.gte = gte;
  13275. lodash.has = has;
  13276. lodash.identity = identity;
  13277. lodash.includes = includes;
  13278. lodash.indexOf = indexOf;
  13279. lodash.inRange = inRange;
  13280. lodash.isArguments = isArguments;
  13281. lodash.isArray = isArray;
  13282. lodash.isBoolean = isBoolean;
  13283. lodash.isDate = isDate;
  13284. lodash.isElement = isElement;
  13285. lodash.isEmpty = isEmpty;
  13286. lodash.isEqual = isEqual;
  13287. lodash.isError = isError;
  13288. lodash.isFinite = isFinite;
  13289. lodash.isFunction = isFunction;
  13290. lodash.isMatch = isMatch;
  13291. lodash.isNaN = isNaN;
  13292. lodash.isNative = isNative;
  13293. lodash.isNull = isNull;
  13294. lodash.isNumber = isNumber;
  13295. lodash.isObject = isObject;
  13296. lodash.isPlainObject = isPlainObject;
  13297. lodash.isRegExp = isRegExp;
  13298. lodash.isString = isString;
  13299. lodash.isTypedArray = isTypedArray;
  13300. lodash.isUndefined = isUndefined;
  13301. lodash.kebabCase = kebabCase;
  13302. lodash.last = last;
  13303. lodash.lastIndexOf = lastIndexOf;
  13304. lodash.lt = lt;
  13305. lodash.lte = lte;
  13306. lodash.max = max;
  13307. lodash.min = min;
  13308. lodash.noConflict = noConflict;
  13309. lodash.noop = noop;
  13310. lodash.now = now;
  13311. lodash.pad = pad;
  13312. lodash.padLeft = padLeft;
  13313. lodash.padRight = padRight;
  13314. lodash.parseInt = parseInt;
  13315. lodash.random = random;
  13316. lodash.reduce = reduce;
  13317. lodash.reduceRight = reduceRight;
  13318. lodash.repeat = repeat;
  13319. lodash.result = result;
  13320. lodash.round = round;
  13321. lodash.runInContext = runInContext;
  13322. lodash.size = size;
  13323. lodash.snakeCase = snakeCase;
  13324. lodash.some = some;
  13325. lodash.sortedIndex = sortedIndex;
  13326. lodash.sortedLastIndex = sortedLastIndex;
  13327. lodash.startCase = startCase;
  13328. lodash.startsWith = startsWith;
  13329. lodash.sum = sum;
  13330. lodash.template = template;
  13331. lodash.trim = trim;
  13332. lodash.trimLeft = trimLeft;
  13333. lodash.trimRight = trimRight;
  13334. lodash.trunc = trunc;
  13335. lodash.unescape = unescape;
  13336. lodash.uniqueId = uniqueId;
  13337. lodash.words = words;
  13338. // Add aliases.
  13339. lodash.all = every;
  13340. lodash.any = some;
  13341. lodash.contains = includes;
  13342. lodash.eq = isEqual;
  13343. lodash.detect = find;
  13344. lodash.foldl = reduce;
  13345. lodash.foldr = reduceRight;
  13346. lodash.head = first;
  13347. lodash.include = includes;
  13348. lodash.inject = reduce;
  13349. mixin(lodash, (function() {
  13350. var source = {};
  13351. baseForOwn(lodash, function(func, methodName) {
  13352. if (!lodash.prototype[methodName]) {
  13353. source[methodName] = func;
  13354. }
  13355. });
  13356. return source;
  13357. }()), false);
  13358. /*------------------------------------------------------------------------*/
  13359. // Add functions capable of returning wrapped and unwrapped values when chaining.
  13360. lodash.sample = sample;
  13361. lodash.prototype.sample = function(n) {
  13362. if (!this.__chain__ && n == null) {
  13363. return sample(this.value());
  13364. }
  13365. return this.thru(function(value) {
  13366. return sample(value, n);
  13367. });
  13368. };
  13369. /*------------------------------------------------------------------------*/
  13370. /**
  13371. * The semantic version number.
  13372. *
  13373. * @static
  13374. * @memberOf _
  13375. * @type string
  13376. */
  13377. lodash.VERSION = VERSION;
  13378. // Assign default placeholders.
  13379. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  13380. lodash[methodName].placeholder = lodash;
  13381. });
  13382. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  13383. arrayEach(['drop', 'take'], function(methodName, index) {
  13384. LazyWrapper.prototype[methodName] = function(n) {
  13385. var filtered = this.__filtered__;
  13386. if (filtered && !index) {
  13387. return new LazyWrapper(this);
  13388. }
  13389. n = n == null ? 1 : nativeMax(nativeFloor(n) || 0, 0);
  13390. var result = this.clone();
  13391. if (filtered) {
  13392. result.__takeCount__ = nativeMin(result.__takeCount__, n);
  13393. } else {
  13394. result.__views__.push({ 'size': n, 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') });
  13395. }
  13396. return result;
  13397. };
  13398. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  13399. return this.reverse()[methodName](n).reverse();
  13400. };
  13401. });
  13402. // Add `LazyWrapper` methods that accept an `iteratee` value.
  13403. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  13404. var type = index + 1,
  13405. isFilter = type != LAZY_MAP_FLAG;
  13406. LazyWrapper.prototype[methodName] = function(iteratee, thisArg) {
  13407. var result = this.clone();
  13408. result.__iteratees__.push({ 'iteratee': getCallback(iteratee, thisArg, 1), 'type': type });
  13409. result.__filtered__ = result.__filtered__ || isFilter;
  13410. return result;
  13411. };
  13412. });
  13413. // Add `LazyWrapper` methods for `_.first` and `_.last`.
  13414. arrayEach(['first', 'last'], function(methodName, index) {
  13415. var takeName = 'take' + (index ? 'Right' : '');
  13416. LazyWrapper.prototype[methodName] = function() {
  13417. return this[takeName](1).value()[0];
  13418. };
  13419. });
  13420. // Add `LazyWrapper` methods for `_.initial` and `_.rest`.
  13421. arrayEach(['initial', 'rest'], function(methodName, index) {
  13422. var dropName = 'drop' + (index ? '' : 'Right');
  13423. LazyWrapper.prototype[methodName] = function() {
  13424. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  13425. };
  13426. });
  13427. // Add `LazyWrapper` methods for `_.pluck` and `_.where`.
  13428. arrayEach(['pluck', 'where'], function(methodName, index) {
  13429. var operationName = index ? 'filter' : 'map',
  13430. createCallback = index ? baseMatches : property;
  13431. LazyWrapper.prototype[methodName] = function(value) {
  13432. return this[operationName](createCallback(value));
  13433. };
  13434. });
  13435. LazyWrapper.prototype.compact = function() {
  13436. return this.filter(identity);
  13437. };
  13438. LazyWrapper.prototype.reject = function(predicate, thisArg) {
  13439. predicate = getCallback(predicate, thisArg, 1);
  13440. return this.filter(function(value) {
  13441. return !predicate(value);
  13442. });
  13443. };
  13444. LazyWrapper.prototype.slice = function(start, end) {
  13445. start = start == null ? 0 : (+start || 0);
  13446. var result = this;
  13447. if (result.__filtered__ && (start > 0 || end < 0)) {
  13448. return new LazyWrapper(result);
  13449. }
  13450. if (start < 0) {
  13451. result = result.takeRight(-start);
  13452. } else if (start) {
  13453. result = result.drop(start);
  13454. }
  13455. if (end !== undefined) {
  13456. end = (+end || 0);
  13457. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  13458. }
  13459. return result;
  13460. };
  13461. LazyWrapper.prototype.takeRightWhile = function(predicate, thisArg) {
  13462. return this.reverse().takeWhile(predicate, thisArg).reverse();
  13463. };
  13464. LazyWrapper.prototype.toArray = function() {
  13465. return this.take(POSITIVE_INFINITY);
  13466. };
  13467. // Add `LazyWrapper` methods to `lodash.prototype`.
  13468. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  13469. var checkIteratee = /^(?:filter|map|reject)|While$/.test(methodName),
  13470. retUnwrapped = /^(?:first|last)$/.test(methodName),
  13471. lodashFunc = lodash[retUnwrapped ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName];
  13472. if (!lodashFunc) {
  13473. return;
  13474. }
  13475. lodash.prototype[methodName] = function() {
  13476. var args = retUnwrapped ? [1] : arguments,
  13477. chainAll = this.__chain__,
  13478. value = this.__wrapped__,
  13479. isHybrid = !!this.__actions__.length,
  13480. isLazy = value instanceof LazyWrapper,
  13481. iteratee = args[0],
  13482. useLazy = isLazy || isArray(value);
  13483. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  13484. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  13485. isLazy = useLazy = false;
  13486. }
  13487. var interceptor = function(value) {
  13488. return (retUnwrapped && chainAll)
  13489. ? lodashFunc(value, 1)[0]
  13490. : lodashFunc.apply(undefined, arrayPush([value], args));
  13491. };
  13492. var action = { 'func': thru, 'args': [interceptor], 'thisArg': undefined },
  13493. onlyLazy = isLazy && !isHybrid;
  13494. if (retUnwrapped && !chainAll) {
  13495. if (onlyLazy) {
  13496. value = value.clone();
  13497. value.__actions__.push(action);
  13498. return func.call(value);
  13499. }
  13500. return lodashFunc.call(undefined, this.value())[0];
  13501. }
  13502. if (!retUnwrapped && useLazy) {
  13503. value = onlyLazy ? value : new LazyWrapper(this);
  13504. var result = func.apply(value, args);
  13505. result.__actions__.push(action);
  13506. return new LodashWrapper(result, chainAll);
  13507. }
  13508. return this.thru(interceptor);
  13509. };
  13510. });
  13511. // Add `Array` and `String` methods to `lodash.prototype`.
  13512. arrayEach(['join', 'pop', 'push', 'replace', 'shift', 'sort', 'splice', 'split', 'unshift'], function(methodName) {
  13513. var func = (/^(?:replace|split)$/.test(methodName) ? stringProto : arrayProto)[methodName],
  13514. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  13515. retUnwrapped = /^(?:join|pop|replace|shift)$/.test(methodName);
  13516. lodash.prototype[methodName] = function() {
  13517. var args = arguments;
  13518. if (retUnwrapped && !this.__chain__) {
  13519. return func.apply(this.value(), args);
  13520. }
  13521. return this[chainName](function(value) {
  13522. return func.apply(value, args);
  13523. });
  13524. };
  13525. });
  13526. // Map minified function names to their real names.
  13527. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  13528. var lodashFunc = lodash[methodName];
  13529. if (lodashFunc) {
  13530. var key = lodashFunc.name,
  13531. names = realNames[key] || (realNames[key] = []);
  13532. names.push({ 'name': methodName, 'func': lodashFunc });
  13533. }
  13534. });
  13535. realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': undefined }];
  13536. // Add functions to the lazy wrapper.
  13537. LazyWrapper.prototype.clone = lazyClone;
  13538. LazyWrapper.prototype.reverse = lazyReverse;
  13539. LazyWrapper.prototype.value = lazyValue;
  13540. // Add chaining functions to the `lodash` wrapper.
  13541. lodash.prototype.chain = wrapperChain;
  13542. lodash.prototype.commit = wrapperCommit;
  13543. lodash.prototype.concat = wrapperConcat;
  13544. lodash.prototype.plant = wrapperPlant;
  13545. lodash.prototype.reverse = wrapperReverse;
  13546. lodash.prototype.toString = wrapperToString;
  13547. lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  13548. // Add function aliases to the `lodash` wrapper.
  13549. lodash.prototype.collect = lodash.prototype.map;
  13550. lodash.prototype.head = lodash.prototype.first;
  13551. lodash.prototype.select = lodash.prototype.filter;
  13552. lodash.prototype.tail = lodash.prototype.rest;
  13553. return lodash;
  13554. }
  13555. /*--------------------------------------------------------------------------*/
  13556. // Export lodash.
  13557. var _ = runInContext();
  13558. // Some AMD build optimizers like r.js check for condition patterns like the following:
  13559. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  13560. // Expose lodash to the global object when an AMD loader is present to avoid
  13561. // errors in cases where lodash is loaded by a script tag and not intended
  13562. // as an AMD module. See http://requirejs.org/docs/errors.html#mismatch for
  13563. // more details.
  13564. root._ = _;
  13565. // Define as an anonymous module so, through path mapping, it can be
  13566. // referenced as the "underscore" module.
  13567. define(function() {
  13568. return _;
  13569. });
  13570. }
  13571. // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
  13572. else if (freeExports && freeModule) {
  13573. // Export for Node.js or RingoJS.
  13574. if (moduleExports) {
  13575. (freeModule.exports = _)._ = _;
  13576. }
  13577. // Export for Rhino with CommonJS support.
  13578. else {
  13579. freeExports._ = _;
  13580. }
  13581. }
  13582. else {
  13583. // Export for a browser or Rhino.
  13584. root._ = _;
  13585. }
  13586. }.call(this));
  13587. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  13588. },{}],51:[function(require,module,exports){
  13589. /*
  13590. Copyright (c) 2012-2014 Chris Pettitt
  13591. Permission is hereby granted, free of charge, to any person obtaining a copy
  13592. of this software and associated documentation files (the "Software"), to deal
  13593. in the Software without restriction, including without limitation the rights
  13594. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13595. copies of the Software, and to permit persons to whom the Software is
  13596. furnished to do so, subject to the following conditions:
  13597. The above copyright notice and this permission notice shall be included in
  13598. all copies or substantial portions of the Software.
  13599. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13600. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13601. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13602. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  13603. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  13604. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  13605. THE SOFTWARE.
  13606. */
  13607. module.exports = {
  13608. graphlib: require("./lib/graphlib"),
  13609. layout: require("./lib/layout"),
  13610. debug: require("./lib/debug"),
  13611. util: {
  13612. time: require("./lib/util").time,
  13613. notime: require("./lib/util").notime
  13614. },
  13615. version: require("./lib/version")
  13616. };
  13617. },{"./lib/debug":56,"./lib/graphlib":57,"./lib/layout":59,"./lib/util":79,"./lib/version":80}],52:[function(require,module,exports){
  13618. "use strict";
  13619. var _ = require("./lodash"),
  13620. greedyFAS = require("./greedy-fas");
  13621. module.exports = {
  13622. run: run,
  13623. undo: undo
  13624. };
  13625. function run(g) {
  13626. var fas = (g.graph().acyclicer === "greedy"
  13627. ? greedyFAS(g, weightFn(g))
  13628. : dfsFAS(g));
  13629. _.each(fas, function(e) {
  13630. var label = g.edge(e);
  13631. g.removeEdge(e);
  13632. label.forwardName = e.name;
  13633. label.reversed = true;
  13634. g.setEdge(e.w, e.v, label, _.uniqueId("rev"));
  13635. });
  13636. function weightFn(g) {
  13637. return function(e) {
  13638. return g.edge(e).weight;
  13639. };
  13640. }
  13641. }
  13642. function dfsFAS(g) {
  13643. var fas = [],
  13644. stack = {},
  13645. visited = {};
  13646. function dfs(v) {
  13647. if (_.has(visited, v)) {
  13648. return;
  13649. }
  13650. visited[v] = true;
  13651. stack[v] = true;
  13652. _.each(g.outEdges(v), function(e) {
  13653. if (_.has(stack, e.w)) {
  13654. fas.push(e);
  13655. } else {
  13656. dfs(e.w);
  13657. }
  13658. });
  13659. delete stack[v];
  13660. }
  13661. _.each(g.nodes(), dfs);
  13662. return fas;
  13663. }
  13664. function undo(g) {
  13665. _.each(g.edges(), function(e) {
  13666. var label = g.edge(e);
  13667. if (label.reversed) {
  13668. g.removeEdge(e);
  13669. var forwardName = label.forwardName;
  13670. delete label.reversed;
  13671. delete label.forwardName;
  13672. g.setEdge(e.w, e.v, label, forwardName);
  13673. }
  13674. });
  13675. }
  13676. },{"./greedy-fas":58,"./lodash":60}],53:[function(require,module,exports){
  13677. var _ = require("./lodash"),
  13678. util = require("./util");
  13679. module.exports = addBorderSegments;
  13680. function addBorderSegments(g) {
  13681. function dfs(v) {
  13682. var children = g.children(v),
  13683. node = g.node(v);
  13684. if (children.length) {
  13685. _.each(children, dfs);
  13686. }
  13687. if (_.has(node, "minRank")) {
  13688. node.borderLeft = [];
  13689. node.borderRight = [];
  13690. for (var rank = node.minRank, maxRank = node.maxRank + 1;
  13691. rank < maxRank;
  13692. ++rank) {
  13693. addBorderNode(g, "borderLeft", "_bl", v, node, rank);
  13694. addBorderNode(g, "borderRight", "_br", v, node, rank);
  13695. }
  13696. }
  13697. }
  13698. _.each(g.children(), dfs);
  13699. }
  13700. function addBorderNode(g, prop, prefix, sg, sgNode, rank) {
  13701. var label = { width: 0, height: 0, rank: rank, borderType: prop },
  13702. prev = sgNode[prop][rank - 1],
  13703. curr = util.addDummyNode(g, "border", label, prefix);
  13704. sgNode[prop][rank] = curr;
  13705. g.setParent(curr, sg);
  13706. if (prev) {
  13707. g.setEdge(prev, curr, { weight: 1 });
  13708. }
  13709. }
  13710. },{"./lodash":60,"./util":79}],54:[function(require,module,exports){
  13711. "use strict";
  13712. var _ = require("./lodash");
  13713. module.exports = {
  13714. adjust: adjust,
  13715. undo: undo
  13716. };
  13717. function adjust(g) {
  13718. var rankDir = g.graph().rankdir.toLowerCase();
  13719. if (rankDir === "lr" || rankDir === "rl") {
  13720. swapWidthHeight(g);
  13721. }
  13722. }
  13723. function undo(g) {
  13724. var rankDir = g.graph().rankdir.toLowerCase();
  13725. if (rankDir === "bt" || rankDir === "rl") {
  13726. reverseY(g);
  13727. }
  13728. if (rankDir === "lr" || rankDir === "rl") {
  13729. swapXY(g);
  13730. swapWidthHeight(g);
  13731. }
  13732. }
  13733. function swapWidthHeight(g) {
  13734. _.each(g.nodes(), function(v) { swapWidthHeightOne(g.node(v)); });
  13735. _.each(g.edges(), function(e) { swapWidthHeightOne(g.edge(e)); });
  13736. }
  13737. function swapWidthHeightOne(attrs) {
  13738. var w = attrs.width;
  13739. attrs.width = attrs.height;
  13740. attrs.height = w;
  13741. }
  13742. function reverseY(g) {
  13743. _.each(g.nodes(), function(v) { reverseYOne(g.node(v)); });
  13744. _.each(g.edges(), function(e) {
  13745. var edge = g.edge(e);
  13746. _.each(edge.points, reverseYOne);
  13747. if (_.has(edge, "y")) {
  13748. reverseYOne(edge);
  13749. }
  13750. });
  13751. }
  13752. function reverseYOne(attrs) {
  13753. attrs.y = -attrs.y;
  13754. }
  13755. function swapXY(g) {
  13756. _.each(g.nodes(), function(v) { swapXYOne(g.node(v)); });
  13757. _.each(g.edges(), function(e) {
  13758. var edge = g.edge(e);
  13759. _.each(edge.points, swapXYOne);
  13760. if (_.has(edge, "x")) {
  13761. swapXYOne(edge);
  13762. }
  13763. });
  13764. }
  13765. function swapXYOne(attrs) {
  13766. var x = attrs.x;
  13767. attrs.x = attrs.y;
  13768. attrs.y = x;
  13769. }
  13770. },{"./lodash":60}],55:[function(require,module,exports){
  13771. /*
  13772. * Simple doubly linked list implementation derived from Cormen, et al.,
  13773. * "Introduction to Algorithms".
  13774. */
  13775. module.exports = List;
  13776. function List() {
  13777. var sentinel = {};
  13778. sentinel._next = sentinel._prev = sentinel;
  13779. this._sentinel = sentinel;
  13780. }
  13781. List.prototype.dequeue = function() {
  13782. var sentinel = this._sentinel,
  13783. entry = sentinel._prev;
  13784. if (entry !== sentinel) {
  13785. unlink(entry);
  13786. return entry;
  13787. }
  13788. };
  13789. List.prototype.enqueue = function(entry) {
  13790. var sentinel = this._sentinel;
  13791. if (entry._prev && entry._next) {
  13792. unlink(entry);
  13793. }
  13794. entry._next = sentinel._next;
  13795. sentinel._next._prev = entry;
  13796. sentinel._next = entry;
  13797. entry._prev = sentinel;
  13798. };
  13799. List.prototype.toString = function() {
  13800. var strs = [],
  13801. sentinel = this._sentinel,
  13802. curr = sentinel._prev;
  13803. while (curr !== sentinel) {
  13804. strs.push(JSON.stringify(curr, filterOutLinks));
  13805. curr = curr._prev;
  13806. }
  13807. return "[" + strs.join(", ") + "]";
  13808. };
  13809. function unlink(entry) {
  13810. entry._prev._next = entry._next;
  13811. entry._next._prev = entry._prev;
  13812. delete entry._next;
  13813. delete entry._prev;
  13814. }
  13815. function filterOutLinks(k, v) {
  13816. if (k !== "_next" && k !== "_prev") {
  13817. return v;
  13818. }
  13819. }
  13820. },{}],56:[function(require,module,exports){
  13821. var _ = require("./lodash"),
  13822. util = require("./util"),
  13823. Graph = require("./graphlib").Graph;
  13824. module.exports = {
  13825. debugOrdering: debugOrdering
  13826. };
  13827. /* istanbul ignore next */
  13828. function debugOrdering(g) {
  13829. var layerMatrix = util.buildLayerMatrix(g);
  13830. var h = new Graph({ compound: true, multigraph: true }).setGraph({});
  13831. _.each(g.nodes(), function(v) {
  13832. h.setNode(v, { label: v });
  13833. h.setParent(v, "layer" + g.node(v).rank);
  13834. });
  13835. _.each(g.edges(), function(e) {
  13836. h.setEdge(e.v, e.w, {}, e.name);
  13837. });
  13838. _.each(layerMatrix, function(layer, i) {
  13839. var layerV = "layer" + i;
  13840. h.setNode(layerV, { rank: "same" });
  13841. _.reduce(layer, function(u, v) {
  13842. h.setEdge(u, v, { style: "invis" });
  13843. return v;
  13844. });
  13845. });
  13846. return h;
  13847. }
  13848. },{"./graphlib":57,"./lodash":60,"./util":79}],57:[function(require,module,exports){
  13849. /* global window */
  13850. var graphlib;
  13851. if (typeof require === "function") {
  13852. try {
  13853. graphlib = require("graphlib");
  13854. } catch (e) {}
  13855. }
  13856. if (!graphlib) {
  13857. graphlib = window.graphlib;
  13858. }
  13859. module.exports = graphlib;
  13860. },{"graphlib":81}],58:[function(require,module,exports){
  13861. var _ = require("./lodash"),
  13862. Graph = require("./graphlib").Graph,
  13863. List = require("./data/list");
  13864. /*
  13865. * A greedy heuristic for finding a feedback arc set for a graph. A feedback
  13866. * arc set is a set of edges that can be removed to make a graph acyclic.
  13867. * The algorithm comes from: P. Eades, X. Lin, and W. F. Smyth, "A fast and
  13868. * effective heuristic for the feedback arc set problem." This implementation
  13869. * adjusts that from the paper to allow for weighted edges.
  13870. */
  13871. module.exports = greedyFAS;
  13872. var DEFAULT_WEIGHT_FN = _.constant(1);
  13873. function greedyFAS(g, weightFn) {
  13874. if (g.nodeCount() <= 1) {
  13875. return [];
  13876. }
  13877. var state = buildState(g, weightFn || DEFAULT_WEIGHT_FN);
  13878. var results = doGreedyFAS(state.graph, state.buckets, state.zeroIdx);
  13879. // Expand multi-edges
  13880. return _.flatten(_.map(results, function(e) {
  13881. return g.outEdges(e.v, e.w);
  13882. }), true);
  13883. }
  13884. function doGreedyFAS(g, buckets, zeroIdx) {
  13885. var results = [],
  13886. sources = buckets[buckets.length - 1],
  13887. sinks = buckets[0];
  13888. var entry;
  13889. while (g.nodeCount()) {
  13890. while ((entry = sinks.dequeue())) { removeNode(g, buckets, zeroIdx, entry); }
  13891. while ((entry = sources.dequeue())) { removeNode(g, buckets, zeroIdx, entry); }
  13892. if (g.nodeCount()) {
  13893. for (var i = buckets.length - 2; i > 0; --i) {
  13894. entry = buckets[i].dequeue();
  13895. if (entry) {
  13896. results = results.concat(removeNode(g, buckets, zeroIdx, entry, true));
  13897. break;
  13898. }
  13899. }
  13900. }
  13901. }
  13902. return results;
  13903. }
  13904. function removeNode(g, buckets, zeroIdx, entry, collectPredecessors) {
  13905. var results = collectPredecessors ? [] : undefined;
  13906. _.each(g.inEdges(entry.v), function(edge) {
  13907. var weight = g.edge(edge),
  13908. uEntry = g.node(edge.v);
  13909. if (collectPredecessors) {
  13910. results.push({ v: edge.v, w: edge.w });
  13911. }
  13912. uEntry.out -= weight;
  13913. assignBucket(buckets, zeroIdx, uEntry);
  13914. });
  13915. _.each(g.outEdges(entry.v), function(edge) {
  13916. var weight = g.edge(edge),
  13917. w = edge.w,
  13918. wEntry = g.node(w);
  13919. wEntry["in"] -= weight;
  13920. assignBucket(buckets, zeroIdx, wEntry);
  13921. });
  13922. g.removeNode(entry.v);
  13923. return results;
  13924. }
  13925. function buildState(g, weightFn) {
  13926. var fasGraph = new Graph(),
  13927. maxIn = 0,
  13928. maxOut = 0;
  13929. _.each(g.nodes(), function(v) {
  13930. fasGraph.setNode(v, { v: v, "in": 0, out: 0 });
  13931. });
  13932. // Aggregate weights on nodes, but also sum the weights across multi-edges
  13933. // into a single edge for the fasGraph.
  13934. _.each(g.edges(), function(e) {
  13935. var prevWeight = fasGraph.edge(e.v, e.w) || 0,
  13936. weight = weightFn(e),
  13937. edgeWeight = prevWeight + weight;
  13938. fasGraph.setEdge(e.v, e.w, edgeWeight);
  13939. maxOut = Math.max(maxOut, fasGraph.node(e.v).out += weight);
  13940. maxIn = Math.max(maxIn, fasGraph.node(e.w)["in"] += weight);
  13941. });
  13942. var buckets = _.range(maxOut + maxIn + 3).map(function() { return new List(); });
  13943. var zeroIdx = maxIn + 1;
  13944. _.each(fasGraph.nodes(), function(v) {
  13945. assignBucket(buckets, zeroIdx, fasGraph.node(v));
  13946. });
  13947. return { graph: fasGraph, buckets: buckets, zeroIdx: zeroIdx };
  13948. }
  13949. function assignBucket(buckets, zeroIdx, entry) {
  13950. if (!entry.out) {
  13951. buckets[0].enqueue(entry);
  13952. } else if (!entry["in"]) {
  13953. buckets[buckets.length - 1].enqueue(entry);
  13954. } else {
  13955. buckets[entry.out - entry["in"] + zeroIdx].enqueue(entry);
  13956. }
  13957. }
  13958. },{"./data/list":55,"./graphlib":57,"./lodash":60}],59:[function(require,module,exports){
  13959. "use strict";
  13960. var _ = require("./lodash"),
  13961. acyclic = require("./acyclic"),
  13962. normalize = require("./normalize"),
  13963. rank = require("./rank"),
  13964. normalizeRanks = require("./util").normalizeRanks,
  13965. parentDummyChains = require("./parent-dummy-chains"),
  13966. removeEmptyRanks = require("./util").removeEmptyRanks,
  13967. nestingGraph = require("./nesting-graph"),
  13968. addBorderSegments = require("./add-border-segments"),
  13969. coordinateSystem = require("./coordinate-system"),
  13970. order = require("./order"),
  13971. position = require("./position"),
  13972. util = require("./util"),
  13973. Graph = require("./graphlib").Graph;
  13974. module.exports = layout;
  13975. function layout(g, opts) {
  13976. var time = opts && opts.debugTiming ? util.time : util.notime;
  13977. time("layout", function() {
  13978. var layoutGraph = time(" buildLayoutGraph",
  13979. function() { return buildLayoutGraph(g); });
  13980. time(" runLayout", function() { runLayout(layoutGraph, time); });
  13981. time(" updateInputGraph", function() { updateInputGraph(g, layoutGraph); });
  13982. });
  13983. }
  13984. function runLayout(g, time) {
  13985. time(" makeSpaceForEdgeLabels", function() { makeSpaceForEdgeLabels(g); });
  13986. time(" removeSelfEdges", function() { removeSelfEdges(g); });
  13987. time(" acyclic", function() { acyclic.run(g); });
  13988. time(" nestingGraph.run", function() { nestingGraph.run(g); });
  13989. time(" rank", function() { rank(util.asNonCompoundGraph(g)); });
  13990. time(" injectEdgeLabelProxies", function() { injectEdgeLabelProxies(g); });
  13991. time(" removeEmptyRanks", function() { removeEmptyRanks(g); });
  13992. time(" nestingGraph.cleanup", function() { nestingGraph.cleanup(g); });
  13993. time(" normalizeRanks", function() { normalizeRanks(g); });
  13994. time(" assignRankMinMax", function() { assignRankMinMax(g); });
  13995. time(" removeEdgeLabelProxies", function() { removeEdgeLabelProxies(g); });
  13996. time(" normalize.run", function() { normalize.run(g); });
  13997. time(" parentDummyChains", function() { parentDummyChains(g); });
  13998. time(" addBorderSegments", function() { addBorderSegments(g); });
  13999. time(" order", function() { order(g); });
  14000. time(" insertSelfEdges", function() { insertSelfEdges(g); });
  14001. time(" adjustCoordinateSystem", function() { coordinateSystem.adjust(g); });
  14002. time(" position", function() { position(g); });
  14003. time(" positionSelfEdges", function() { positionSelfEdges(g); });
  14004. time(" removeBorderNodes", function() { removeBorderNodes(g); });
  14005. time(" normalize.undo", function() { normalize.undo(g); });
  14006. time(" fixupEdgeLabelCoords", function() { fixupEdgeLabelCoords(g); });
  14007. time(" undoCoordinateSystem", function() { coordinateSystem.undo(g); });
  14008. time(" translateGraph", function() { translateGraph(g); });
  14009. time(" assignNodeIntersects", function() { assignNodeIntersects(g); });
  14010. time(" reversePoints", function() { reversePointsForReversedEdges(g); });
  14011. time(" acyclic.undo", function() { acyclic.undo(g); });
  14012. }
  14013. /*
  14014. * Copies final layout information from the layout graph back to the input
  14015. * graph. This process only copies whitelisted attributes from the layout graph
  14016. * to the input graph, so it serves as a good place to determine what
  14017. * attributes can influence layout.
  14018. */
  14019. function updateInputGraph(inputGraph, layoutGraph) {
  14020. _.each(inputGraph.nodes(), function(v) {
  14021. var inputLabel = inputGraph.node(v),
  14022. layoutLabel = layoutGraph.node(v);
  14023. if (inputLabel) {
  14024. inputLabel.x = layoutLabel.x;
  14025. inputLabel.y = layoutLabel.y;
  14026. if (layoutGraph.children(v).length) {
  14027. inputLabel.width = layoutLabel.width;
  14028. inputLabel.height = layoutLabel.height;
  14029. }
  14030. }
  14031. });
  14032. _.each(inputGraph.edges(), function(e) {
  14033. var inputLabel = inputGraph.edge(e),
  14034. layoutLabel = layoutGraph.edge(e);
  14035. inputLabel.points = layoutLabel.points;
  14036. if (_.has(layoutLabel, "x")) {
  14037. inputLabel.x = layoutLabel.x;
  14038. inputLabel.y = layoutLabel.y;
  14039. }
  14040. });
  14041. inputGraph.graph().width = layoutGraph.graph().width;
  14042. inputGraph.graph().height = layoutGraph.graph().height;
  14043. }
  14044. var graphNumAttrs = ["nodesep", "edgesep", "ranksep", "marginx", "marginy"],
  14045. graphDefaults = { ranksep: 50, edgesep: 20, nodesep: 50, rankdir: "tb" },
  14046. graphAttrs = ["acyclicer", "ranker", "rankdir", "align"],
  14047. nodeNumAttrs = ["width", "height"],
  14048. nodeDefaults = { width: 0, height: 0 },
  14049. edgeNumAttrs = ["minlen", "weight", "width", "height", "labeloffset"],
  14050. edgeDefaults = {
  14051. minlen: 1, weight: 1, width: 0, height: 0,
  14052. labeloffset: 10, labelpos: "r"
  14053. },
  14054. edgeAttrs = ["labelpos"];
  14055. /*
  14056. * Constructs a new graph from the input graph, which can be used for layout.
  14057. * This process copies only whitelisted attributes from the input graph to the
  14058. * layout graph. Thus this function serves as a good place to determine what
  14059. * attributes can influence layout.
  14060. */
  14061. function buildLayoutGraph(inputGraph) {
  14062. var g = new Graph({ multigraph: true, compound: true }),
  14063. graph = canonicalize(inputGraph.graph());
  14064. g.setGraph(_.merge({},
  14065. graphDefaults,
  14066. selectNumberAttrs(graph, graphNumAttrs),
  14067. _.pick(graph, graphAttrs)));
  14068. _.each(inputGraph.nodes(), function(v) {
  14069. var node = canonicalize(inputGraph.node(v));
  14070. g.setNode(v, _.defaults(selectNumberAttrs(node, nodeNumAttrs), nodeDefaults));
  14071. g.setParent(v, inputGraph.parent(v));
  14072. });
  14073. _.each(inputGraph.edges(), function(e) {
  14074. var edge = canonicalize(inputGraph.edge(e));
  14075. g.setEdge(e, _.merge({},
  14076. edgeDefaults,
  14077. selectNumberAttrs(edge, edgeNumAttrs),
  14078. _.pick(edge, edgeAttrs)));
  14079. });
  14080. return g;
  14081. }
  14082. /*
  14083. * This idea comes from the Gansner paper: to account for edge labels in our
  14084. * layout we split each rank in half by doubling minlen and halving ranksep.
  14085. * Then we can place labels at these mid-points between nodes.
  14086. *
  14087. * We also add some minimal padding to the width to push the label for the edge
  14088. * away from the edge itself a bit.
  14089. */
  14090. function makeSpaceForEdgeLabels(g) {
  14091. var graph = g.graph();
  14092. graph.ranksep /= 2;
  14093. _.each(g.edges(), function(e) {
  14094. var edge = g.edge(e);
  14095. edge.minlen *= 2;
  14096. if (edge.labelpos.toLowerCase() !== "c") {
  14097. if (graph.rankdir === "TB" || graph.rankdir === "BT") {
  14098. edge.width += edge.labeloffset;
  14099. } else {
  14100. edge.height += edge.labeloffset;
  14101. }
  14102. }
  14103. });
  14104. }
  14105. /*
  14106. * Creates temporary dummy nodes that capture the rank in which each edge's
  14107. * label is going to, if it has one of non-zero width and height. We do this
  14108. * so that we can safely remove empty ranks while preserving balance for the
  14109. * label's position.
  14110. */
  14111. function injectEdgeLabelProxies(g) {
  14112. _.each(g.edges(), function(e) {
  14113. var edge = g.edge(e);
  14114. if (edge.width && edge.height) {
  14115. var v = g.node(e.v),
  14116. w = g.node(e.w),
  14117. label = { rank: (w.rank - v.rank) / 2 + v.rank, e: e };
  14118. util.addDummyNode(g, "edge-proxy", label, "_ep");
  14119. }
  14120. });
  14121. }
  14122. function assignRankMinMax(g) {
  14123. var maxRank = 0;
  14124. _.each(g.nodes(), function(v) {
  14125. var node = g.node(v);
  14126. if (node.borderTop) {
  14127. node.minRank = g.node(node.borderTop).rank;
  14128. node.maxRank = g.node(node.borderBottom).rank;
  14129. maxRank = _.max(maxRank, node.maxRank);
  14130. }
  14131. });
  14132. g.graph().maxRank = maxRank;
  14133. }
  14134. function removeEdgeLabelProxies(g) {
  14135. _.each(g.nodes(), function(v) {
  14136. var node = g.node(v);
  14137. if (node.dummy === "edge-proxy") {
  14138. g.edge(node.e).labelRank = node.rank;
  14139. g.removeNode(v);
  14140. }
  14141. });
  14142. }
  14143. function translateGraph(g) {
  14144. var minX = Number.POSITIVE_INFINITY,
  14145. maxX = 0,
  14146. minY = Number.POSITIVE_INFINITY,
  14147. maxY = 0,
  14148. graphLabel = g.graph(),
  14149. marginX = graphLabel.marginx || 0,
  14150. marginY = graphLabel.marginy || 0;
  14151. function getExtremes(attrs) {
  14152. var x = attrs.x,
  14153. y = attrs.y,
  14154. w = attrs.width,
  14155. h = attrs.height;
  14156. minX = Math.min(minX, x - w / 2);
  14157. maxX = Math.max(maxX, x + w / 2);
  14158. minY = Math.min(minY, y - h / 2);
  14159. maxY = Math.max(maxY, y + h / 2);
  14160. }
  14161. _.each(g.nodes(), function(v) { getExtremes(g.node(v)); });
  14162. _.each(g.edges(), function(e) {
  14163. var edge = g.edge(e);
  14164. if (_.has(edge, "x")) {
  14165. getExtremes(edge);
  14166. }
  14167. });
  14168. minX -= marginX;
  14169. minY -= marginY;
  14170. _.each(g.nodes(), function(v) {
  14171. var node = g.node(v);
  14172. node.x -= minX;
  14173. node.y -= minY;
  14174. });
  14175. _.each(g.edges(), function(e) {
  14176. var edge = g.edge(e);
  14177. _.each(edge.points, function(p) {
  14178. p.x -= minX;
  14179. p.y -= minY;
  14180. });
  14181. if (_.has(edge, "x")) { edge.x -= minX; }
  14182. if (_.has(edge, "y")) { edge.y -= minY; }
  14183. });
  14184. graphLabel.width = maxX - minX + marginX;
  14185. graphLabel.height = maxY - minY + marginY;
  14186. }
  14187. function assignNodeIntersects(g) {
  14188. _.each(g.edges(), function(e) {
  14189. var edge = g.edge(e),
  14190. nodeV = g.node(e.v),
  14191. nodeW = g.node(e.w),
  14192. p1, p2;
  14193. if (!edge.points) {
  14194. edge.points = [];
  14195. p1 = nodeW;
  14196. p2 = nodeV;
  14197. } else {
  14198. p1 = edge.points[0];
  14199. p2 = edge.points[edge.points.length - 1];
  14200. }
  14201. edge.points.unshift(util.intersectRect(nodeV, p1));
  14202. edge.points.push(util.intersectRect(nodeW, p2));
  14203. });
  14204. }
  14205. function fixupEdgeLabelCoords(g) {
  14206. _.each(g.edges(), function(e) {
  14207. var edge = g.edge(e);
  14208. if (_.has(edge, "x")) {
  14209. if (edge.labelpos === "l" || edge.labelpos === "r") {
  14210. edge.width -= edge.labeloffset;
  14211. }
  14212. switch (edge.labelpos) {
  14213. case "l": edge.x -= edge.width / 2 + edge.labeloffset; break;
  14214. case "r": edge.x += edge.width / 2 + edge.labeloffset; break;
  14215. }
  14216. }
  14217. });
  14218. }
  14219. function reversePointsForReversedEdges(g) {
  14220. _.each(g.edges(), function(e) {
  14221. var edge = g.edge(e);
  14222. if (edge.reversed) {
  14223. edge.points.reverse();
  14224. }
  14225. });
  14226. }
  14227. function removeBorderNodes(g) {
  14228. _.each(g.nodes(), function(v) {
  14229. if (g.children(v).length) {
  14230. var node = g.node(v),
  14231. t = g.node(node.borderTop),
  14232. b = g.node(node.borderBottom),
  14233. l = g.node(_.last(node.borderLeft)),
  14234. r = g.node(_.last(node.borderRight));
  14235. node.width = Math.abs(r.x - l.x);
  14236. node.height = Math.abs(b.y - t.y);
  14237. node.x = l.x + node.width / 2;
  14238. node.y = t.y + node.height / 2;
  14239. }
  14240. });
  14241. _.each(g.nodes(), function(v) {
  14242. if (g.node(v).dummy === "border") {
  14243. g.removeNode(v);
  14244. }
  14245. });
  14246. }
  14247. function removeSelfEdges(g) {
  14248. _.each(g.edges(), function(e) {
  14249. if (e.v === e.w) {
  14250. var node = g.node(e.v);
  14251. if (!node.selfEdges) {
  14252. node.selfEdges = [];
  14253. }
  14254. node.selfEdges.push({ e: e, label: g.edge(e) });
  14255. g.removeEdge(e);
  14256. }
  14257. });
  14258. }
  14259. function insertSelfEdges(g) {
  14260. var layers = util.buildLayerMatrix(g);
  14261. _.each(layers, function(layer) {
  14262. var orderShift = 0;
  14263. _.each(layer, function(v, i) {
  14264. var node = g.node(v);
  14265. node.order = i + orderShift;
  14266. _.each(node.selfEdges, function(selfEdge) {
  14267. util.addDummyNode(g, "selfedge", {
  14268. width: selfEdge.label.width,
  14269. height: selfEdge.label.height,
  14270. rank: node.rank,
  14271. order: i + (++orderShift),
  14272. e: selfEdge.e,
  14273. label: selfEdge.label
  14274. }, "_se");
  14275. });
  14276. delete node.selfEdges;
  14277. });
  14278. });
  14279. }
  14280. function positionSelfEdges(g) {
  14281. _.each(g.nodes(), function(v) {
  14282. var node = g.node(v);
  14283. if (node.dummy === "selfedge") {
  14284. var selfNode = g.node(node.e.v),
  14285. x = selfNode.x + selfNode.width / 2,
  14286. y = selfNode.y,
  14287. dx = node.x - x,
  14288. dy = selfNode.height / 2;
  14289. g.setEdge(node.e, node.label);
  14290. g.removeNode(v);
  14291. node.label.points = [
  14292. { x: x + 2 * dx / 3, y: y - dy },
  14293. { x: x + 5 * dx / 6, y: y - dy },
  14294. { x: x + dx , y: y },
  14295. { x: x + 5 * dx / 6, y: y + dy },
  14296. { x: x + 2 * dx / 3, y: y + dy },
  14297. ];
  14298. node.label.x = node.x;
  14299. node.label.y = node.y;
  14300. }
  14301. });
  14302. }
  14303. function selectNumberAttrs(obj, attrs) {
  14304. return _.mapValues(_.pick(obj, attrs), Number);
  14305. }
  14306. function canonicalize(attrs) {
  14307. var newAttrs = {};
  14308. _.each(attrs, function(v, k) {
  14309. newAttrs[k.toLowerCase()] = v;
  14310. });
  14311. return newAttrs;
  14312. }
  14313. },{"./acyclic":52,"./add-border-segments":53,"./coordinate-system":54,"./graphlib":57,"./lodash":60,"./nesting-graph":61,"./normalize":62,"./order":67,"./parent-dummy-chains":72,"./position":74,"./rank":76,"./util":79}],60:[function(require,module,exports){
  14314. module.exports=require(48)
  14315. },{"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/lodash.js":48,"lodash":101}],61:[function(require,module,exports){
  14316. var _ = require("./lodash"),
  14317. util = require("./util");
  14318. module.exports = {
  14319. run: run,
  14320. cleanup: cleanup
  14321. };
  14322. /*
  14323. * A nesting graph creates dummy nodes for the tops and bottoms of subgraphs,
  14324. * adds appropriate edges to ensure that all cluster nodes are placed between
  14325. * these boundries, and ensures that the graph is connected.
  14326. *
  14327. * In addition we ensure, through the use of the minlen property, that nodes
  14328. * and subgraph border nodes to not end up on the same rank.
  14329. *
  14330. * Preconditions:
  14331. *
  14332. * 1. Input graph is a DAG
  14333. * 2. Nodes in the input graph has a minlen attribute
  14334. *
  14335. * Postconditions:
  14336. *
  14337. * 1. Input graph is connected.
  14338. * 2. Dummy nodes are added for the tops and bottoms of subgraphs.
  14339. * 3. The minlen attribute for nodes is adjusted to ensure nodes do not
  14340. * get placed on the same rank as subgraph border nodes.
  14341. *
  14342. * The nesting graph idea comes from Sander, "Layout of Compound Directed
  14343. * Graphs."
  14344. */
  14345. function run(g) {
  14346. var root = util.addDummyNode(g, "root", {}, "_root"),
  14347. depths = treeDepths(g),
  14348. height = _.max(depths) - 1,
  14349. nodeSep = 2 * height + 1;
  14350. g.graph().nestingRoot = root;
  14351. // Multiply minlen by nodeSep to align nodes on non-border ranks.
  14352. _.each(g.edges(), function(e) { g.edge(e).minlen *= nodeSep; });
  14353. // Calculate a weight that is sufficient to keep subgraphs vertically compact
  14354. var weight = sumWeights(g) + 1;
  14355. // Create border nodes and link them up
  14356. _.each(g.children(), function(child) {
  14357. dfs(g, root, nodeSep, weight, height, depths, child);
  14358. });
  14359. // Save the multiplier for node layers for later removal of empty border
  14360. // layers.
  14361. g.graph().nodeRankFactor = nodeSep;
  14362. }
  14363. function dfs(g, root, nodeSep, weight, height, depths, v) {
  14364. var children = g.children(v);
  14365. if (!children.length) {
  14366. if (v !== root) {
  14367. g.setEdge(root, v, { weight: 0, minlen: nodeSep });
  14368. }
  14369. return;
  14370. }
  14371. var top = util.addBorderNode(g, "_bt"),
  14372. bottom = util.addBorderNode(g, "_bb"),
  14373. label = g.node(v);
  14374. g.setParent(top, v);
  14375. label.borderTop = top;
  14376. g.setParent(bottom, v);
  14377. label.borderBottom = bottom;
  14378. _.each(children, function(child) {
  14379. dfs(g, root, nodeSep, weight, height, depths, child);
  14380. var childNode = g.node(child),
  14381. childTop = childNode.borderTop ? childNode.borderTop : child,
  14382. childBottom = childNode.borderBottom ? childNode.borderBottom : child,
  14383. thisWeight = childNode.borderTop ? weight : 2 * weight,
  14384. minlen = childTop !== childBottom ? 1 : height - depths[v] + 1;
  14385. g.setEdge(top, childTop, {
  14386. weight: thisWeight,
  14387. minlen: minlen,
  14388. nestingEdge: true
  14389. });
  14390. g.setEdge(childBottom, bottom, {
  14391. weight: thisWeight,
  14392. minlen: minlen,
  14393. nestingEdge: true
  14394. });
  14395. });
  14396. if (!g.parent(v)) {
  14397. g.setEdge(root, top, { weight: 0, minlen: height + depths[v] });
  14398. }
  14399. }
  14400. function treeDepths(g) {
  14401. var depths = {};
  14402. function dfs(v, depth) {
  14403. var children = g.children(v);
  14404. if (children && children.length) {
  14405. _.each(children, function(child) {
  14406. dfs(child, depth + 1);
  14407. });
  14408. }
  14409. depths[v] = depth;
  14410. }
  14411. _.each(g.children(), function(v) { dfs(v, 1); });
  14412. return depths;
  14413. }
  14414. function sumWeights(g) {
  14415. return _.reduce(g.edges(), function(acc, e) {
  14416. return acc + g.edge(e).weight;
  14417. }, 0);
  14418. }
  14419. function cleanup(g) {
  14420. var graphLabel = g.graph();
  14421. g.removeNode(graphLabel.nestingRoot);
  14422. delete graphLabel.nestingRoot;
  14423. _.each(g.edges(), function(e) {
  14424. var edge = g.edge(e);
  14425. if (edge.nestingEdge) {
  14426. g.removeEdge(e);
  14427. }
  14428. });
  14429. }
  14430. },{"./lodash":60,"./util":79}],62:[function(require,module,exports){
  14431. "use strict";
  14432. var _ = require("./lodash"),
  14433. util = require("./util");
  14434. module.exports = {
  14435. run: run,
  14436. undo: undo
  14437. };
  14438. /*
  14439. * Breaks any long edges in the graph into short segments that span 1 layer
  14440. * each. This operation is undoable with the denormalize function.
  14441. *
  14442. * Pre-conditions:
  14443. *
  14444. * 1. The input graph is a DAG.
  14445. * 2. Each node in the graph has a "rank" property.
  14446. *
  14447. * Post-condition:
  14448. *
  14449. * 1. All edges in the graph have a length of 1.
  14450. * 2. Dummy nodes are added where edges have been split into segments.
  14451. * 3. The graph is augmented with a "dummyChains" attribute which contains
  14452. * the first dummy in each chain of dummy nodes produced.
  14453. */
  14454. function run(g) {
  14455. g.graph().dummyChains = [];
  14456. _.each(g.edges(), function(edge) { normalizeEdge(g, edge); });
  14457. }
  14458. function normalizeEdge(g, e) {
  14459. var v = e.v,
  14460. vRank = g.node(v).rank,
  14461. w = e.w,
  14462. wRank = g.node(w).rank,
  14463. name = e.name,
  14464. edgeLabel = g.edge(e),
  14465. labelRank = edgeLabel.labelRank;
  14466. if (wRank === vRank + 1) return;
  14467. g.removeEdge(e);
  14468. var dummy, attrs, i;
  14469. for (i = 0, ++vRank; vRank < wRank; ++i, ++vRank) {
  14470. edgeLabel.points = [];
  14471. attrs = {
  14472. width: 0, height: 0,
  14473. edgeLabel: edgeLabel, edgeObj: e,
  14474. rank: vRank
  14475. };
  14476. dummy = util.addDummyNode(g, "edge", attrs, "_d");
  14477. if (vRank === labelRank) {
  14478. attrs.width = edgeLabel.width;
  14479. attrs.height = edgeLabel.height;
  14480. attrs.dummy = "edge-label";
  14481. attrs.labelpos = edgeLabel.labelpos;
  14482. }
  14483. g.setEdge(v, dummy, { weight: edgeLabel.weight }, name);
  14484. if (i === 0) {
  14485. g.graph().dummyChains.push(dummy);
  14486. }
  14487. v = dummy;
  14488. }
  14489. g.setEdge(v, w, { weight: edgeLabel.weight }, name);
  14490. }
  14491. function undo(g) {
  14492. _.each(g.graph().dummyChains, function(v) {
  14493. var node = g.node(v),
  14494. origLabel = node.edgeLabel,
  14495. w;
  14496. g.setEdge(node.edgeObj, origLabel);
  14497. while (node.dummy) {
  14498. w = g.successors(v)[0];
  14499. g.removeNode(v);
  14500. origLabel.points.push({ x: node.x, y: node.y });
  14501. if (node.dummy === "edge-label") {
  14502. origLabel.x = node.x;
  14503. origLabel.y = node.y;
  14504. origLabel.width = node.width;
  14505. origLabel.height = node.height;
  14506. }
  14507. v = w;
  14508. node = g.node(v);
  14509. }
  14510. });
  14511. }
  14512. },{"./lodash":60,"./util":79}],63:[function(require,module,exports){
  14513. var _ = require("../lodash");
  14514. module.exports = addSubgraphConstraints;
  14515. function addSubgraphConstraints(g, cg, vs) {
  14516. var prev = {},
  14517. rootPrev;
  14518. _.each(vs, function(v) {
  14519. var child = g.parent(v),
  14520. parent,
  14521. prevChild;
  14522. while (child) {
  14523. parent = g.parent(child);
  14524. if (parent) {
  14525. prevChild = prev[parent];
  14526. prev[parent] = child;
  14527. } else {
  14528. prevChild = rootPrev;
  14529. rootPrev = child;
  14530. }
  14531. if (prevChild && prevChild !== child) {
  14532. cg.setEdge(prevChild, child);
  14533. return;
  14534. }
  14535. child = parent;
  14536. }
  14537. });
  14538. /*
  14539. function dfs(v) {
  14540. var children = v ? g.children(v) : g.children();
  14541. if (children.length) {
  14542. var min = Number.POSITIVE_INFINITY,
  14543. subgraphs = [];
  14544. _.each(children, function(child) {
  14545. var childMin = dfs(child);
  14546. if (g.children(child).length) {
  14547. subgraphs.push({ v: child, order: childMin });
  14548. }
  14549. min = Math.min(min, childMin);
  14550. });
  14551. _.reduce(_.sortBy(subgraphs, "order"), function(prev, curr) {
  14552. cg.setEdge(prev.v, curr.v);
  14553. return curr;
  14554. });
  14555. return min;
  14556. }
  14557. return g.node(v).order;
  14558. }
  14559. dfs(undefined);
  14560. */
  14561. }
  14562. },{"../lodash":60}],64:[function(require,module,exports){
  14563. var _ = require("../lodash");
  14564. module.exports = barycenter;
  14565. function barycenter(g, movable) {
  14566. return _.map(movable, function(v) {
  14567. var inV = g.inEdges(v);
  14568. if (!inV.length) {
  14569. return { v: v };
  14570. } else {
  14571. var result = _.reduce(inV, function(acc, e) {
  14572. var edge = g.edge(e),
  14573. nodeU = g.node(e.v);
  14574. return {
  14575. sum: acc.sum + (edge.weight * nodeU.order),
  14576. weight: acc.weight + edge.weight
  14577. };
  14578. }, { sum: 0, weight: 0 });
  14579. return {
  14580. v: v,
  14581. barycenter: result.sum / result.weight,
  14582. weight: result.weight
  14583. };
  14584. }
  14585. });
  14586. }
  14587. },{"../lodash":60}],65:[function(require,module,exports){
  14588. var _ = require("../lodash"),
  14589. Graph = require("../graphlib").Graph;
  14590. module.exports = buildLayerGraph;
  14591. /*
  14592. * Constructs a graph that can be used to sort a layer of nodes. The graph will
  14593. * contain all base and subgraph nodes from the request layer in their original
  14594. * hierarchy and any edges that are incident on these nodes and are of the type
  14595. * requested by the "relationship" parameter.
  14596. *
  14597. * Nodes from the requested rank that do not have parents are assigned a root
  14598. * node in the output graph, which is set in the root graph attribute. This
  14599. * makes it easy to walk the hierarchy of movable nodes during ordering.
  14600. *
  14601. * Pre-conditions:
  14602. *
  14603. * 1. Input graph is a DAG
  14604. * 2. Base nodes in the input graph have a rank attribute
  14605. * 3. Subgraph nodes in the input graph has minRank and maxRank attributes
  14606. * 4. Edges have an assigned weight
  14607. *
  14608. * Post-conditions:
  14609. *
  14610. * 1. Output graph has all nodes in the movable rank with preserved
  14611. * hierarchy.
  14612. * 2. Root nodes in the movable layer are made children of the node
  14613. * indicated by the root attribute of the graph.
  14614. * 3. Non-movable nodes incident on movable nodes, selected by the
  14615. * relationship parameter, are included in the graph (without hierarchy).
  14616. * 4. Edges incident on movable nodes, selected by the relationship
  14617. * parameter, are added to the output graph.
  14618. * 5. The weights for copied edges are aggregated as need, since the output
  14619. * graph is not a multi-graph.
  14620. */
  14621. function buildLayerGraph(g, rank, relationship) {
  14622. var root = createRootNode(g),
  14623. result = new Graph({ compound: true }).setGraph({ root: root })
  14624. .setDefaultNodeLabel(function(v) { return g.node(v); });
  14625. _.each(g.nodes(), function(v) {
  14626. var node = g.node(v),
  14627. parent = g.parent(v);
  14628. if (node.rank === rank || node.minRank <= rank && rank <= node.maxRank) {
  14629. result.setNode(v);
  14630. result.setParent(v, parent || root);
  14631. // This assumes we have only short edges!
  14632. _.each(g[relationship](v), function(e) {
  14633. var u = e.v === v ? e.w : e.v,
  14634. edge = result.edge(u, v),
  14635. weight = !_.isUndefined(edge) ? edge.weight : 0;
  14636. result.setEdge(u, v, { weight: g.edge(e).weight + weight });
  14637. });
  14638. if (_.has(node, "minRank")) {
  14639. result.setNode(v, {
  14640. borderLeft: node.borderLeft[rank],
  14641. borderRight: node.borderRight[rank]
  14642. });
  14643. }
  14644. }
  14645. });
  14646. return result;
  14647. }
  14648. function createRootNode(g) {
  14649. var v;
  14650. while (g.hasNode((v = _.uniqueId("_root"))));
  14651. return v;
  14652. }
  14653. },{"../graphlib":57,"../lodash":60}],66:[function(require,module,exports){
  14654. "use strict";
  14655. var _ = require("../lodash");
  14656. module.exports = crossCount;
  14657. /*
  14658. * A function that takes a layering (an array of layers, each with an array of
  14659. * ordererd nodes) and a graph and returns a weighted crossing count.
  14660. *
  14661. * Pre-conditions:
  14662. *
  14663. * 1. Input graph must be simple (not a multigraph), directed, and include
  14664. * only simple edges.
  14665. * 2. Edges in the input graph must have assigned weights.
  14666. *
  14667. * Post-conditions:
  14668. *
  14669. * 1. The graph and layering matrix are left unchanged.
  14670. *
  14671. * This algorithm is derived from Barth, et al., "Bilayer Cross Counting."
  14672. */
  14673. function crossCount(g, layering) {
  14674. var cc = 0;
  14675. for (var i = 1; i < layering.length; ++i) {
  14676. cc += twoLayerCrossCount(g, layering[i-1], layering[i]);
  14677. }
  14678. return cc;
  14679. }
  14680. function twoLayerCrossCount(g, northLayer, southLayer) {
  14681. // Sort all of the edges between the north and south layers by their position
  14682. // in the north layer and then the south. Map these edges to the position of
  14683. // their head in the south layer.
  14684. var southPos = _.zipObject(southLayer,
  14685. _.map(southLayer, function (v, i) { return i; }));
  14686. var southEntries = _.flatten(_.map(northLayer, function(v) {
  14687. return _.chain(g.outEdges(v))
  14688. .map(function(e) {
  14689. return { pos: southPos[e.w], weight: g.edge(e).weight };
  14690. })
  14691. .sortBy("pos")
  14692. .value();
  14693. }), true);
  14694. // Build the accumulator tree
  14695. var firstIndex = 1;
  14696. while (firstIndex < southLayer.length) firstIndex <<= 1;
  14697. var treeSize = 2 * firstIndex - 1;
  14698. firstIndex -= 1;
  14699. var tree = _.map(new Array(treeSize), function() { return 0; });
  14700. // Calculate the weighted crossings
  14701. var cc = 0;
  14702. _.each(southEntries.forEach(function(entry) {
  14703. var index = entry.pos + firstIndex;
  14704. tree[index] += entry.weight;
  14705. var weightSum = 0;
  14706. while (index > 0) {
  14707. if (index % 2) {
  14708. weightSum += tree[index + 1];
  14709. }
  14710. index = (index - 1) >> 1;
  14711. tree[index] += entry.weight;
  14712. }
  14713. cc += entry.weight * weightSum;
  14714. }));
  14715. return cc;
  14716. }
  14717. },{"../lodash":60}],67:[function(require,module,exports){
  14718. "use strict";
  14719. var _ = require("../lodash"),
  14720. initOrder = require("./init-order"),
  14721. crossCount = require("./cross-count"),
  14722. sortSubgraph = require("./sort-subgraph"),
  14723. buildLayerGraph = require("./build-layer-graph"),
  14724. addSubgraphConstraints = require("./add-subgraph-constraints"),
  14725. Graph = require("../graphlib").Graph,
  14726. util = require("../util");
  14727. module.exports = order;
  14728. /*
  14729. * Applies heuristics to minimize edge crossings in the graph and sets the best
  14730. * order solution as an order attribute on each node.
  14731. *
  14732. * Pre-conditions:
  14733. *
  14734. * 1. Graph must be DAG
  14735. * 2. Graph nodes must be objects with a "rank" attribute
  14736. * 3. Graph edges must have the "weight" attribute
  14737. *
  14738. * Post-conditions:
  14739. *
  14740. * 1. Graph nodes will have an "order" attribute based on the results of the
  14741. * algorithm.
  14742. */
  14743. function order(g) {
  14744. var maxRank = util.maxRank(g),
  14745. downLayerGraphs = buildLayerGraphs(g, _.range(1, maxRank + 1), "inEdges"),
  14746. upLayerGraphs = buildLayerGraphs(g, _.range(maxRank - 1, -1, -1), "outEdges");
  14747. var layering = initOrder(g);
  14748. assignOrder(g, layering);
  14749. var bestCC = Number.POSITIVE_INFINITY,
  14750. best;
  14751. for (var i = 0, lastBest = 0; lastBest < 4; ++i, ++lastBest) {
  14752. sweepLayerGraphs(i % 2 ? downLayerGraphs : upLayerGraphs, i % 4 >= 2);
  14753. layering = util.buildLayerMatrix(g);
  14754. var cc = crossCount(g, layering);
  14755. if (cc < bestCC) {
  14756. lastBest = 0;
  14757. best = _.cloneDeep(layering);
  14758. bestCC = cc;
  14759. }
  14760. }
  14761. assignOrder(g, best);
  14762. }
  14763. function buildLayerGraphs(g, ranks, relationship) {
  14764. return _.map(ranks, function(rank) {
  14765. return buildLayerGraph(g, rank, relationship);
  14766. });
  14767. }
  14768. function sweepLayerGraphs(layerGraphs, biasRight) {
  14769. var cg = new Graph();
  14770. _.each(layerGraphs, function(lg) {
  14771. var root = lg.graph().root;
  14772. var sorted = sortSubgraph(lg, root, cg, biasRight);
  14773. _.each(sorted.vs, function(v, i) {
  14774. lg.node(v).order = i;
  14775. });
  14776. addSubgraphConstraints(lg, cg, sorted.vs);
  14777. });
  14778. }
  14779. function assignOrder(g, layering) {
  14780. _.each(layering, function(layer) {
  14781. _.each(layer, function(v, i) {
  14782. g.node(v).order = i;
  14783. });
  14784. });
  14785. }
  14786. },{"../graphlib":57,"../lodash":60,"../util":79,"./add-subgraph-constraints":63,"./build-layer-graph":65,"./cross-count":66,"./init-order":68,"./sort-subgraph":70}],68:[function(require,module,exports){
  14787. "use strict";
  14788. var _ = require("../lodash");
  14789. module.exports = initOrder;
  14790. /*
  14791. * Assigns an initial order value for each node by performing a DFS search
  14792. * starting from nodes in the first rank. Nodes are assigned an order in their
  14793. * rank as they are first visited.
  14794. *
  14795. * This approach comes from Gansner, et al., "A Technique for Drawing Directed
  14796. * Graphs."
  14797. *
  14798. * Returns a layering matrix with an array per layer and each layer sorted by
  14799. * the order of its nodes.
  14800. */
  14801. function initOrder(g) {
  14802. var visited = {},
  14803. simpleNodes = _.filter(g.nodes(), function(v) {
  14804. return !g.children(v).length;
  14805. }),
  14806. maxRank = _.max(_.map(simpleNodes, function(v) { return g.node(v).rank; })),
  14807. layers = _.map(_.range(maxRank + 1), function() { return []; });
  14808. function dfs(v) {
  14809. if (_.has(visited, v)) return;
  14810. visited[v] = true;
  14811. var node = g.node(v);
  14812. layers[node.rank].push(v);
  14813. _.each(g.successors(v), dfs);
  14814. }
  14815. var orderedVs = _.sortBy(simpleNodes, function(v) { return g.node(v).rank; });
  14816. _.each(orderedVs, dfs);
  14817. return layers;
  14818. }
  14819. },{"../lodash":60}],69:[function(require,module,exports){
  14820. "use strict";
  14821. var _ = require("../lodash");
  14822. module.exports = resolveConflicts;
  14823. /*
  14824. * Given a list of entries of the form {v, barycenter, weight} and a
  14825. * constraint graph this function will resolve any conflicts between the
  14826. * constraint graph and the barycenters for the entries. If the barycenters for
  14827. * an entry would violate a constraint in the constraint graph then we coalesce
  14828. * the nodes in the conflict into a new node that respects the contraint and
  14829. * aggregates barycenter and weight information.
  14830. *
  14831. * This implementation is based on the description in Forster, "A Fast and
  14832. * Simple Hueristic for Constrained Two-Level Crossing Reduction," thought it
  14833. * differs in some specific details.
  14834. *
  14835. * Pre-conditions:
  14836. *
  14837. * 1. Each entry has the form {v, barycenter, weight}, or if the node has
  14838. * no barycenter, then {v}.
  14839. *
  14840. * Returns:
  14841. *
  14842. * A new list of entries of the form {vs, i, barycenter, weight}. The list
  14843. * `vs` may either be a singleton or it may be an aggregation of nodes
  14844. * ordered such that they do not violate constraints from the constraint
  14845. * graph. The property `i` is the lowest original index of any of the
  14846. * elements in `vs`.
  14847. */
  14848. function resolveConflicts(entries, cg) {
  14849. var mappedEntries = {};
  14850. _.each(entries, function(entry, i) {
  14851. var tmp = mappedEntries[entry.v] = {
  14852. indegree: 0,
  14853. "in": [],
  14854. out: [],
  14855. vs: [entry.v],
  14856. i: i
  14857. };
  14858. if (!_.isUndefined(entry.barycenter)) {
  14859. tmp.barycenter = entry.barycenter;
  14860. tmp.weight = entry.weight;
  14861. }
  14862. });
  14863. _.each(cg.edges(), function(e) {
  14864. var entryV = mappedEntries[e.v],
  14865. entryW = mappedEntries[e.w];
  14866. if (!_.isUndefined(entryV) && !_.isUndefined(entryW)) {
  14867. entryW.indegree++;
  14868. entryV.out.push(mappedEntries[e.w]);
  14869. }
  14870. });
  14871. var sourceSet = _.filter(mappedEntries, function(entry) {
  14872. return !entry.indegree;
  14873. });
  14874. return doResolveConflicts(sourceSet);
  14875. }
  14876. function doResolveConflicts(sourceSet) {
  14877. var entries = [];
  14878. function handleIn(vEntry) {
  14879. return function(uEntry) {
  14880. if (uEntry.merged) {
  14881. return;
  14882. }
  14883. if (_.isUndefined(uEntry.barycenter) ||
  14884. _.isUndefined(vEntry.barycenter) ||
  14885. uEntry.barycenter >= vEntry.barycenter) {
  14886. mergeEntries(vEntry, uEntry);
  14887. }
  14888. };
  14889. }
  14890. function handleOut(vEntry) {
  14891. return function(wEntry) {
  14892. wEntry["in"].push(vEntry);
  14893. if (--wEntry.indegree === 0) {
  14894. sourceSet.push(wEntry);
  14895. }
  14896. };
  14897. }
  14898. while (sourceSet.length) {
  14899. var entry = sourceSet.pop();
  14900. entries.push(entry);
  14901. _.each(entry["in"].reverse(), handleIn(entry));
  14902. _.each(entry.out, handleOut(entry));
  14903. }
  14904. return _.chain(entries)
  14905. .filter(function(entry) { return !entry.merged; })
  14906. .map(function(entry) {
  14907. return _.pick(entry, ["vs", "i", "barycenter", "weight"]);
  14908. })
  14909. .value();
  14910. }
  14911. function mergeEntries(target, source) {
  14912. var sum = 0,
  14913. weight = 0;
  14914. if (target.weight) {
  14915. sum += target.barycenter * target.weight;
  14916. weight += target.weight;
  14917. }
  14918. if (source.weight) {
  14919. sum += source.barycenter * source.weight;
  14920. weight += source.weight;
  14921. }
  14922. target.vs = source.vs.concat(target.vs);
  14923. target.barycenter = sum / weight;
  14924. target.weight = weight;
  14925. target.i = Math.min(source.i, target.i);
  14926. source.merged = true;
  14927. }
  14928. },{"../lodash":60}],70:[function(require,module,exports){
  14929. var _ = require("../lodash"),
  14930. barycenter = require("./barycenter"),
  14931. resolveConflicts = require("./resolve-conflicts"),
  14932. sort = require("./sort");
  14933. module.exports = sortSubgraph;
  14934. function sortSubgraph(g, v, cg, biasRight) {
  14935. var movable = g.children(v),
  14936. node = g.node(v),
  14937. bl = node ? node.borderLeft : undefined,
  14938. br = node ? node.borderRight: undefined,
  14939. subgraphs = {};
  14940. if (bl) {
  14941. movable = _.filter(movable, function(w) {
  14942. return w !== bl && w !== br;
  14943. });
  14944. }
  14945. var barycenters = barycenter(g, movable);
  14946. _.each(barycenters, function(entry) {
  14947. if (g.children(entry.v).length) {
  14948. var subgraphResult = sortSubgraph(g, entry.v, cg, biasRight);
  14949. subgraphs[entry.v] = subgraphResult;
  14950. if (_.has(subgraphResult, "barycenter")) {
  14951. mergeBarycenters(entry, subgraphResult);
  14952. }
  14953. }
  14954. });
  14955. var entries = resolveConflicts(barycenters, cg);
  14956. expandSubgraphs(entries, subgraphs);
  14957. var result = sort(entries, biasRight);
  14958. if (bl) {
  14959. result.vs = _.flatten([bl, result.vs, br], true);
  14960. if (g.predecessors(bl).length) {
  14961. var blPred = g.node(g.predecessors(bl)[0]),
  14962. brPred = g.node(g.predecessors(br)[0]);
  14963. if (!_.has(result, "barycenter")) {
  14964. result.barycenter = 0;
  14965. result.weight = 0;
  14966. }
  14967. result.barycenter = (result.barycenter * result.weight +
  14968. blPred.order + brPred.order) / (result.weight + 2);
  14969. result.weight += 2;
  14970. }
  14971. }
  14972. return result;
  14973. }
  14974. function expandSubgraphs(entries, subgraphs) {
  14975. _.each(entries, function(entry) {
  14976. entry.vs = _.flatten(entry.vs.map(function(v) {
  14977. if (subgraphs[v]) {
  14978. return subgraphs[v].vs;
  14979. }
  14980. return v;
  14981. }), true);
  14982. });
  14983. }
  14984. function mergeBarycenters(target, other) {
  14985. if (!_.isUndefined(target.barycenter)) {
  14986. target.barycenter = (target.barycenter * target.weight +
  14987. other.barycenter * other.weight) /
  14988. (target.weight + other.weight);
  14989. target.weight += other.weight;
  14990. } else {
  14991. target.barycenter = other.barycenter;
  14992. target.weight = other.weight;
  14993. }
  14994. }
  14995. },{"../lodash":60,"./barycenter":64,"./resolve-conflicts":69,"./sort":71}],71:[function(require,module,exports){
  14996. var _ = require("../lodash"),
  14997. util = require("../util");
  14998. module.exports = sort;
  14999. function sort(entries, biasRight) {
  15000. var parts = util.partition(entries, function(entry) {
  15001. return _.has(entry, "barycenter");
  15002. });
  15003. var sortable = parts.lhs,
  15004. unsortable = _.sortBy(parts.rhs, function(entry) { return -entry.i; }),
  15005. vs = [],
  15006. sum = 0,
  15007. weight = 0,
  15008. vsIndex = 0;
  15009. sortable.sort(compareWithBias(!!biasRight));
  15010. vsIndex = consumeUnsortable(vs, unsortable, vsIndex);
  15011. _.each(sortable, function (entry) {
  15012. vsIndex += entry.vs.length;
  15013. vs.push(entry.vs);
  15014. sum += entry.barycenter * entry.weight;
  15015. weight += entry.weight;
  15016. vsIndex = consumeUnsortable(vs, unsortable, vsIndex);
  15017. });
  15018. var result = { vs: _.flatten(vs, true) };
  15019. if (weight) {
  15020. result.barycenter = sum / weight;
  15021. result.weight = weight;
  15022. }
  15023. return result;
  15024. }
  15025. function consumeUnsortable(vs, unsortable, index) {
  15026. var last;
  15027. while (unsortable.length && (last = _.last(unsortable)).i <= index) {
  15028. unsortable.pop();
  15029. vs.push(last.vs);
  15030. index++;
  15031. }
  15032. return index;
  15033. }
  15034. function compareWithBias(bias) {
  15035. return function(entryV, entryW) {
  15036. if (entryV.barycenter < entryW.barycenter) {
  15037. return -1;
  15038. } else if (entryV.barycenter > entryW.barycenter) {
  15039. return 1;
  15040. }
  15041. return !bias ? entryV.i - entryW.i : entryW.i - entryV.i;
  15042. };
  15043. }
  15044. },{"../lodash":60,"../util":79}],72:[function(require,module,exports){
  15045. var _ = require("./lodash");
  15046. module.exports = parentDummyChains;
  15047. function parentDummyChains(g) {
  15048. var postorderNums = postorder(g);
  15049. _.each(g.graph().dummyChains, function(v) {
  15050. var node = g.node(v),
  15051. edgeObj = node.edgeObj,
  15052. pathData = findPath(g, postorderNums, edgeObj.v, edgeObj.w),
  15053. path = pathData.path,
  15054. lca = pathData.lca,
  15055. pathIdx = 0,
  15056. pathV = path[pathIdx],
  15057. ascending = true;
  15058. while (v !== edgeObj.w) {
  15059. node = g.node(v);
  15060. if (ascending) {
  15061. while ((pathV = path[pathIdx]) !== lca &&
  15062. g.node(pathV).maxRank < node.rank) {
  15063. pathIdx++;
  15064. }
  15065. if (pathV === lca) {
  15066. ascending = false;
  15067. }
  15068. }
  15069. if (!ascending) {
  15070. while (pathIdx < path.length - 1 &&
  15071. g.node(pathV = path[pathIdx + 1]).minRank <= node.rank) {
  15072. pathIdx++;
  15073. }
  15074. pathV = path[pathIdx];
  15075. }
  15076. g.setParent(v, pathV);
  15077. v = g.successors(v)[0];
  15078. }
  15079. });
  15080. }
  15081. // Find a path from v to w through the lowest common ancestor (LCA). Return the
  15082. // full path and the LCA.
  15083. function findPath(g, postorderNums, v, w) {
  15084. var vPath = [],
  15085. wPath = [],
  15086. low = Math.min(postorderNums[v].low, postorderNums[w].low),
  15087. lim = Math.max(postorderNums[v].lim, postorderNums[w].lim),
  15088. parent,
  15089. lca;
  15090. // Traverse up from v to find the LCA
  15091. parent = v;
  15092. do {
  15093. parent = g.parent(parent);
  15094. vPath.push(parent);
  15095. } while (parent &&
  15096. (postorderNums[parent].low > low || lim > postorderNums[parent].lim));
  15097. lca = parent;
  15098. // Traverse from w to LCA
  15099. parent = w;
  15100. while ((parent = g.parent(parent)) !== lca) {
  15101. wPath.push(parent);
  15102. }
  15103. return { path: vPath.concat(wPath.reverse()), lca: lca };
  15104. }
  15105. function postorder(g) {
  15106. var result = {},
  15107. lim = 0;
  15108. function dfs(v) {
  15109. var low = lim;
  15110. _.each(g.children(v), dfs);
  15111. result[v] = { low: low, lim: lim++ };
  15112. }
  15113. _.each(g.children(), dfs);
  15114. return result;
  15115. }
  15116. },{"./lodash":60}],73:[function(require,module,exports){
  15117. "use strict";
  15118. var _ = require("../lodash"),
  15119. Graph = require("../graphlib").Graph,
  15120. util = require("../util");
  15121. /*
  15122. * This module provides coordinate assignment based on Brandes and Köpf, "Fast
  15123. * and Simple Horizontal Coordinate Assignment."
  15124. */
  15125. module.exports = {
  15126. positionX: positionX,
  15127. findType1Conflicts: findType1Conflicts,
  15128. findType2Conflicts: findType2Conflicts,
  15129. addConflict: addConflict,
  15130. hasConflict: hasConflict,
  15131. verticalAlignment: verticalAlignment,
  15132. horizontalCompaction: horizontalCompaction,
  15133. alignCoordinates: alignCoordinates,
  15134. findSmallestWidthAlignment: findSmallestWidthAlignment,
  15135. balance: balance
  15136. };
  15137. /*
  15138. * Marks all edges in the graph with a type-1 conflict with the "type1Conflict"
  15139. * property. A type-1 conflict is one where a non-inner segment crosses an
  15140. * inner segment. An inner segment is an edge with both incident nodes marked
  15141. * with the "dummy" property.
  15142. *
  15143. * This algorithm scans layer by layer, starting with the second, for type-1
  15144. * conflicts between the current layer and the previous layer. For each layer
  15145. * it scans the nodes from left to right until it reaches one that is incident
  15146. * on an inner segment. It then scans predecessors to determine if they have
  15147. * edges that cross that inner segment. At the end a final scan is done for all
  15148. * nodes on the current rank to see if they cross the last visited inner
  15149. * segment.
  15150. *
  15151. * This algorithm (safely) assumes that a dummy node will only be incident on a
  15152. * single node in the layers being scanned.
  15153. */
  15154. function findType1Conflicts(g, layering) {
  15155. var conflicts = {};
  15156. function visitLayer(prevLayer, layer) {
  15157. var
  15158. // last visited node in the previous layer that is incident on an inner
  15159. // segment.
  15160. k0 = 0,
  15161. // Tracks the last node in this layer scanned for crossings with a type-1
  15162. // segment.
  15163. scanPos = 0,
  15164. prevLayerLength = prevLayer.length,
  15165. lastNode = _.last(layer);
  15166. _.each(layer, function(v, i) {
  15167. var w = findOtherInnerSegmentNode(g, v),
  15168. k1 = w ? g.node(w).order : prevLayerLength;
  15169. if (w || v === lastNode) {
  15170. _.each(layer.slice(scanPos, i +1), function(scanNode) {
  15171. _.each(g.predecessors(scanNode), function(u) {
  15172. var uLabel = g.node(u),
  15173. uPos = uLabel.order;
  15174. if ((uPos < k0 || k1 < uPos) &&
  15175. !(uLabel.dummy && g.node(scanNode).dummy)) {
  15176. addConflict(conflicts, u, scanNode);
  15177. }
  15178. });
  15179. });
  15180. scanPos = i + 1;
  15181. k0 = k1;
  15182. }
  15183. });
  15184. return layer;
  15185. }
  15186. _.reduce(layering, visitLayer);
  15187. return conflicts;
  15188. }
  15189. function findType2Conflicts(g, layering) {
  15190. var conflicts = {};
  15191. function scan(south, southPos, southEnd, prevNorthBorder, nextNorthBorder) {
  15192. var v;
  15193. _.each(_.range(southPos, southEnd), function(i) {
  15194. v = south[i];
  15195. if (g.node(v).dummy) {
  15196. _.each(g.predecessors(v), function(u) {
  15197. var uNode = g.node(u);
  15198. if (uNode.dummy &&
  15199. (uNode.order < prevNorthBorder || uNode.order > nextNorthBorder)) {
  15200. addConflict(conflicts, u, v);
  15201. }
  15202. });
  15203. }
  15204. });
  15205. }
  15206. function visitLayer(north, south) {
  15207. var prevNorthPos = -1,
  15208. nextNorthPos,
  15209. southPos = 0;
  15210. _.each(south, function(v, southLookahead) {
  15211. if (g.node(v).dummy === "border") {
  15212. var predecessors = g.predecessors(v);
  15213. if (predecessors.length) {
  15214. nextNorthPos = g.node(predecessors[0]).order;
  15215. scan(south, southPos, southLookahead, prevNorthPos, nextNorthPos);
  15216. southPos = southLookahead;
  15217. prevNorthPos = nextNorthPos;
  15218. }
  15219. }
  15220. scan(south, southPos, south.length, nextNorthPos, north.length);
  15221. });
  15222. return south;
  15223. }
  15224. _.reduce(layering, visitLayer);
  15225. return conflicts;
  15226. }
  15227. function findOtherInnerSegmentNode(g, v) {
  15228. if (g.node(v).dummy) {
  15229. return _.find(g.predecessors(v), function(u) {
  15230. return g.node(u).dummy;
  15231. });
  15232. }
  15233. }
  15234. function addConflict(conflicts, v, w) {
  15235. if (v > w) {
  15236. var tmp = v;
  15237. v = w;
  15238. w = tmp;
  15239. }
  15240. var conflictsV = conflicts[v];
  15241. if (!conflictsV) {
  15242. conflicts[v] = conflictsV = {};
  15243. }
  15244. conflictsV[w] = true;
  15245. }
  15246. function hasConflict(conflicts, v, w) {
  15247. if (v > w) {
  15248. var tmp = v;
  15249. v = w;
  15250. w = tmp;
  15251. }
  15252. return _.has(conflicts[v], w);
  15253. }
  15254. /*
  15255. * Try to align nodes into vertical "blocks" where possible. This algorithm
  15256. * attempts to align a node with one of its median neighbors. If the edge
  15257. * connecting a neighbor is a type-1 conflict then we ignore that possibility.
  15258. * If a previous node has already formed a block with a node after the node
  15259. * we're trying to form a block with, we also ignore that possibility - our
  15260. * blocks would be split in that scenario.
  15261. */
  15262. function verticalAlignment(g, layering, conflicts, neighborFn) {
  15263. var root = {},
  15264. align = {},
  15265. pos = {};
  15266. // We cache the position here based on the layering because the graph and
  15267. // layering may be out of sync. The layering matrix is manipulated to
  15268. // generate different extreme alignments.
  15269. _.each(layering, function(layer) {
  15270. _.each(layer, function(v, order) {
  15271. root[v] = v;
  15272. align[v] = v;
  15273. pos[v] = order;
  15274. });
  15275. });
  15276. _.each(layering, function(layer) {
  15277. var prevIdx = -1;
  15278. _.each(layer, function(v) {
  15279. var ws = neighborFn(v);
  15280. if (ws.length) {
  15281. ws = _.sortBy(ws, function(w) { return pos[w]; });
  15282. var mp = (ws.length - 1) / 2;
  15283. for (var i = Math.floor(mp), il = Math.ceil(mp); i <= il; ++i) {
  15284. var w = ws[i];
  15285. if (align[v] === v &&
  15286. prevIdx < pos[w] &&
  15287. !hasConflict(conflicts, v, w)) {
  15288. align[w] = v;
  15289. align[v] = root[v] = root[w];
  15290. prevIdx = pos[w];
  15291. }
  15292. }
  15293. }
  15294. });
  15295. });
  15296. return { root: root, align: align };
  15297. }
  15298. function horizontalCompaction(g, layering, root, align, reverseSep) {
  15299. // This portion of the algorithm differs from BK due to a number of problems.
  15300. // Instead of their algorithm we construct a new block graph and do two
  15301. // sweeps. The first sweep places blocks with the smallest possible
  15302. // coordinates. The second sweep removes unused space by moving blocks to the
  15303. // greatest coordinates without violating separation.
  15304. var xs = {},
  15305. blockG = buildBlockGraph(g, layering, root, reverseSep);
  15306. // First pass, assign smallest coordinates via DFS
  15307. var visited = {};
  15308. function pass1(v) {
  15309. if (!_.has(visited, v)) {
  15310. visited[v] = true;
  15311. xs[v] = _.reduce(blockG.inEdges(v), function(max, e) {
  15312. pass1(e.v);
  15313. return Math.max(max, xs[e.v] + blockG.edge(e));
  15314. }, 0);
  15315. }
  15316. }
  15317. _.each(blockG.nodes(), pass1);
  15318. var borderType = reverseSep ? "borderLeft" : "borderRight";
  15319. function pass2(v) {
  15320. if (visited[v] !== 2) {
  15321. visited[v]++;
  15322. var node = g.node(v);
  15323. var min = _.reduce(blockG.outEdges(v), function(min, e) {
  15324. pass2(e.w);
  15325. return Math.min(min, xs[e.w] - blockG.edge(e));
  15326. }, Number.POSITIVE_INFINITY);
  15327. if (min !== Number.POSITIVE_INFINITY && node.borderType !== borderType) {
  15328. xs[v] = Math.max(xs[v], min);
  15329. }
  15330. }
  15331. }
  15332. _.each(blockG.nodes(), pass2);
  15333. // Assign x coordinates to all nodes
  15334. _.each(align, function(v) {
  15335. xs[v] = xs[root[v]];
  15336. });
  15337. return xs;
  15338. }
  15339. function buildBlockGraph(g, layering, root, reverseSep) {
  15340. var blockGraph = new Graph(),
  15341. graphLabel = g.graph(),
  15342. sepFn = sep(graphLabel.nodesep, graphLabel.edgesep, reverseSep);
  15343. _.each(layering, function(layer) {
  15344. var u;
  15345. _.each(layer, function(v) {
  15346. var vRoot = root[v];
  15347. blockGraph.setNode(vRoot);
  15348. if (u) {
  15349. var uRoot = root[u],
  15350. prevMax = blockGraph.edge(uRoot, vRoot);
  15351. blockGraph.setEdge(uRoot, vRoot, Math.max(sepFn(g, v, u), prevMax || 0));
  15352. }
  15353. u = v;
  15354. });
  15355. });
  15356. return blockGraph;
  15357. }
  15358. /*
  15359. * Returns the alignment that has the smallest width of the given alignments.
  15360. */
  15361. function findSmallestWidthAlignment(g, xss) {
  15362. return _.min(xss, function(xs) {
  15363. var min = _.min(xs, function(x, v) { return x - width(g, v) / 2; }),
  15364. max = _.max(xs, function(x, v) { return x + width(g, v) / 2; });
  15365. return max - min;
  15366. });
  15367. }
  15368. /*
  15369. * Align the coordinates of each of the layout alignments such that
  15370. * left-biased alignments have their minimum coordinate at the same point as
  15371. * the minimum coordinate of the smallest width alignment and right-biased
  15372. * alignments have their maximum coordinate at the same point as the maximum
  15373. * coordinate of the smallest width alignment.
  15374. */
  15375. function alignCoordinates(xss, alignTo) {
  15376. var alignToMin = _.min(alignTo),
  15377. alignToMax = _.max(alignTo);
  15378. _.each(["u", "d"], function(vert) {
  15379. _.each(["l", "r"], function(horiz) {
  15380. var alignment = vert + horiz,
  15381. xs = xss[alignment],
  15382. delta;
  15383. if (xs === alignTo) return;
  15384. delta = horiz === "l" ? alignToMin - _.min(xs) : alignToMax - _.max(xs);
  15385. if (delta) {
  15386. xss[alignment] = _.mapValues(xs, function(x) { return x + delta; });
  15387. }
  15388. });
  15389. });
  15390. }
  15391. function balance(xss, align) {
  15392. return _.mapValues(xss.ul, function(ignore, v) {
  15393. if (align) {
  15394. return xss[align.toLowerCase()][v];
  15395. } else {
  15396. var xs = _.sortBy(_.pluck(xss, v));
  15397. return (xs[1] + xs[2]) / 2;
  15398. }
  15399. });
  15400. }
  15401. function positionX(g) {
  15402. var layering = util.buildLayerMatrix(g),
  15403. conflicts = _.merge(findType1Conflicts(g, layering),
  15404. findType2Conflicts(g, layering));
  15405. var xss = {},
  15406. adjustedLayering;
  15407. _.each(["u", "d"], function(vert) {
  15408. adjustedLayering = vert === "u" ? layering : _.values(layering).reverse();
  15409. _.each(["l", "r"], function(horiz) {
  15410. if (horiz === "r") {
  15411. adjustedLayering = _.map(adjustedLayering, function(inner) {
  15412. return _.values(inner).reverse();
  15413. });
  15414. }
  15415. var neighborFn = _.bind(vert === "u" ? g.predecessors : g.successors, g);
  15416. var align = verticalAlignment(g, adjustedLayering, conflicts, neighborFn);
  15417. var xs = horizontalCompaction(g, adjustedLayering,
  15418. align.root, align.align,
  15419. horiz === "r");
  15420. if (horiz === "r") {
  15421. xs = _.mapValues(xs, function(x) { return -x; });
  15422. }
  15423. xss[vert + horiz] = xs;
  15424. });
  15425. });
  15426. var smallestWidth = findSmallestWidthAlignment(g, xss);
  15427. alignCoordinates(xss, smallestWidth);
  15428. return balance(xss, g.graph().align);
  15429. }
  15430. function sep(nodeSep, edgeSep, reverseSep) {
  15431. return function(g, v, w) {
  15432. var vLabel = g.node(v),
  15433. wLabel = g.node(w),
  15434. sum = 0,
  15435. delta;
  15436. sum += vLabel.width / 2;
  15437. if (_.has(vLabel, "labelpos")) {
  15438. switch (vLabel.labelpos.toLowerCase()) {
  15439. case "l": delta = -vLabel.width / 2; break;
  15440. case "r": delta = vLabel.width / 2; break;
  15441. }
  15442. }
  15443. if (delta) {
  15444. sum += reverseSep ? delta : -delta;
  15445. }
  15446. delta = 0;
  15447. sum += (vLabel.dummy ? edgeSep : nodeSep) / 2;
  15448. sum += (wLabel.dummy ? edgeSep : nodeSep) / 2;
  15449. sum += wLabel.width / 2;
  15450. if (_.has(wLabel, "labelpos")) {
  15451. switch (wLabel.labelpos.toLowerCase()) {
  15452. case "l": delta = wLabel.width / 2; break;
  15453. case "r": delta = -wLabel.width / 2; break;
  15454. }
  15455. }
  15456. if (delta) {
  15457. sum += reverseSep ? delta : -delta;
  15458. }
  15459. delta = 0;
  15460. return sum;
  15461. };
  15462. }
  15463. function width(g, v) {
  15464. return g.node(v).width;
  15465. }
  15466. },{"../graphlib":57,"../lodash":60,"../util":79}],74:[function(require,module,exports){
  15467. "use strict";
  15468. var _ = require("../lodash"),
  15469. util = require("../util"),
  15470. positionX = require("./bk").positionX;
  15471. module.exports = position;
  15472. function position(g) {
  15473. g = util.asNonCompoundGraph(g);
  15474. positionY(g);
  15475. _.each(positionX(g), function(x, v) {
  15476. g.node(v).x = x;
  15477. });
  15478. }
  15479. function positionY(g) {
  15480. var layering = util.buildLayerMatrix(g),
  15481. rankSep = g.graph().ranksep,
  15482. prevY = 0;
  15483. _.each(layering, function(layer) {
  15484. var maxHeight = _.max(_.map(layer, function(v) { return g.node(v).height; }));
  15485. _.each(layer, function(v) {
  15486. g.node(v).y = prevY + maxHeight / 2;
  15487. });
  15488. prevY += maxHeight + rankSep;
  15489. });
  15490. }
  15491. },{"../lodash":60,"../util":79,"./bk":73}],75:[function(require,module,exports){
  15492. "use strict";
  15493. var _ = require("../lodash"),
  15494. Graph = require("../graphlib").Graph,
  15495. slack = require("./util").slack;
  15496. module.exports = feasibleTree;
  15497. /*
  15498. * Constructs a spanning tree with tight edges and adjusted the input node's
  15499. * ranks to achieve this. A tight edge is one that is has a length that matches
  15500. * its "minlen" attribute.
  15501. *
  15502. * The basic structure for this function is derived from Gansner, et al., "A
  15503. * Technique for Drawing Directed Graphs."
  15504. *
  15505. * Pre-conditions:
  15506. *
  15507. * 1. Graph must be a DAG.
  15508. * 2. Graph must be connected.
  15509. * 3. Graph must have at least one node.
  15510. * 5. Graph nodes must have been previously assigned a "rank" property that
  15511. * respects the "minlen" property of incident edges.
  15512. * 6. Graph edges must have a "minlen" property.
  15513. *
  15514. * Post-conditions:
  15515. *
  15516. * - Graph nodes will have their rank adjusted to ensure that all edges are
  15517. * tight.
  15518. *
  15519. * Returns a tree (undirected graph) that is constructed using only "tight"
  15520. * edges.
  15521. */
  15522. function feasibleTree(g) {
  15523. var t = new Graph({ directed: false });
  15524. // Choose arbitrary node from which to start our tree
  15525. var start = g.nodes()[0],
  15526. size = g.nodeCount();
  15527. t.setNode(start, {});
  15528. var edge, delta;
  15529. while (tightTree(t, g) < size) {
  15530. edge = findMinSlackEdge(t, g);
  15531. delta = t.hasNode(edge.v) ? slack(g, edge) : -slack(g, edge);
  15532. shiftRanks(t, g, delta);
  15533. }
  15534. return t;
  15535. }
  15536. /*
  15537. * Finds a maximal tree of tight edges and returns the number of nodes in the
  15538. * tree.
  15539. */
  15540. function tightTree(t, g) {
  15541. function dfs(v) {
  15542. _.each(g.nodeEdges(v), function(e) {
  15543. var edgeV = e.v,
  15544. w = (v === edgeV) ? e.w : edgeV;
  15545. if (!t.hasNode(w) && !slack(g, e)) {
  15546. t.setNode(w, {});
  15547. t.setEdge(v, w, {});
  15548. dfs(w);
  15549. }
  15550. });
  15551. }
  15552. _.each(t.nodes(), dfs);
  15553. return t.nodeCount();
  15554. }
  15555. /*
  15556. * Finds the edge with the smallest slack that is incident on tree and returns
  15557. * it.
  15558. */
  15559. function findMinSlackEdge(t, g) {
  15560. return _.min(g.edges(), function(e) {
  15561. if (t.hasNode(e.v) !== t.hasNode(e.w)) {
  15562. return slack(g, e);
  15563. }
  15564. });
  15565. }
  15566. function shiftRanks(t, g, delta) {
  15567. _.each(t.nodes(), function(v) {
  15568. g.node(v).rank += delta;
  15569. });
  15570. }
  15571. },{"../graphlib":57,"../lodash":60,"./util":78}],76:[function(require,module,exports){
  15572. "use strict";
  15573. var rankUtil = require("./util"),
  15574. longestPath = rankUtil.longestPath,
  15575. feasibleTree = require("./feasible-tree"),
  15576. networkSimplex = require("./network-simplex");
  15577. module.exports = rank;
  15578. /*
  15579. * Assigns a rank to each node in the input graph that respects the "minlen"
  15580. * constraint specified on edges between nodes.
  15581. *
  15582. * This basic structure is derived from Gansner, et al., "A Technique for
  15583. * Drawing Directed Graphs."
  15584. *
  15585. * Pre-conditions:
  15586. *
  15587. * 1. Graph must be a connected DAG
  15588. * 2. Graph nodes must be objects
  15589. * 3. Graph edges must have "weight" and "minlen" attributes
  15590. *
  15591. * Post-conditions:
  15592. *
  15593. * 1. Graph nodes will have a "rank" attribute based on the results of the
  15594. * algorithm. Ranks can start at any index (including negative), we'll
  15595. * fix them up later.
  15596. */
  15597. function rank(g) {
  15598. switch(g.graph().ranker) {
  15599. case "network-simplex": networkSimplexRanker(g); break;
  15600. case "tight-tree": tightTreeRanker(g); break;
  15601. case "longest-path": longestPathRanker(g); break;
  15602. default: networkSimplexRanker(g);
  15603. }
  15604. }
  15605. // A fast and simple ranker, but results are far from optimal.
  15606. var longestPathRanker = longestPath;
  15607. function tightTreeRanker(g) {
  15608. longestPath(g);
  15609. feasibleTree(g);
  15610. }
  15611. function networkSimplexRanker(g) {
  15612. networkSimplex(g);
  15613. }
  15614. },{"./feasible-tree":75,"./network-simplex":77,"./util":78}],77:[function(require,module,exports){
  15615. "use strict";
  15616. var _ = require("../lodash"),
  15617. feasibleTree = require("./feasible-tree"),
  15618. slack = require("./util").slack,
  15619. initRank = require("./util").longestPath,
  15620. preorder = require("../graphlib").alg.preorder,
  15621. postorder = require("../graphlib").alg.postorder,
  15622. simplify = require("../util").simplify;
  15623. module.exports = networkSimplex;
  15624. // Expose some internals for testing purposes
  15625. networkSimplex.initLowLimValues = initLowLimValues;
  15626. networkSimplex.initCutValues = initCutValues;
  15627. networkSimplex.calcCutValue = calcCutValue;
  15628. networkSimplex.leaveEdge = leaveEdge;
  15629. networkSimplex.enterEdge = enterEdge;
  15630. networkSimplex.exchangeEdges = exchangeEdges;
  15631. /*
  15632. * The network simplex algorithm assigns ranks to each node in the input graph
  15633. * and iteratively improves the ranking to reduce the length of edges.
  15634. *
  15635. * Preconditions:
  15636. *
  15637. * 1. The input graph must be a DAG.
  15638. * 2. All nodes in the graph must have an object value.
  15639. * 3. All edges in the graph must have "minlen" and "weight" attributes.
  15640. *
  15641. * Postconditions:
  15642. *
  15643. * 1. All nodes in the graph will have an assigned "rank" attribute that has
  15644. * been optimized by the network simplex algorithm. Ranks start at 0.
  15645. *
  15646. *
  15647. * A rough sketch of the algorithm is as follows:
  15648. *
  15649. * 1. Assign initial ranks to each node. We use the longest path algorithm,
  15650. * which assigns ranks to the lowest position possible. In general this
  15651. * leads to very wide bottom ranks and unnecessarily long edges.
  15652. * 2. Construct a feasible tight tree. A tight tree is one such that all
  15653. * edges in the tree have no slack (difference between length of edge
  15654. * and minlen for the edge). This by itself greatly improves the assigned
  15655. * rankings by shorting edges.
  15656. * 3. Iteratively find edges that have negative cut values. Generally a
  15657. * negative cut value indicates that the edge could be removed and a new
  15658. * tree edge could be added to produce a more compact graph.
  15659. *
  15660. * Much of the algorithms here are derived from Gansner, et al., "A Technique
  15661. * for Drawing Directed Graphs." The structure of the file roughly follows the
  15662. * structure of the overall algorithm.
  15663. */
  15664. function networkSimplex(g) {
  15665. g = simplify(g);
  15666. initRank(g);
  15667. var t = feasibleTree(g);
  15668. initLowLimValues(t);
  15669. initCutValues(t, g);
  15670. var e, f;
  15671. while ((e = leaveEdge(t))) {
  15672. f = enterEdge(t, g, e);
  15673. exchangeEdges(t, g, e, f);
  15674. }
  15675. }
  15676. /*
  15677. * Initializes cut values for all edges in the tree.
  15678. */
  15679. function initCutValues(t, g) {
  15680. var vs = postorder(t, t.nodes());
  15681. vs = vs.slice(0, vs.length - 1);
  15682. _.each(vs, function(v) {
  15683. assignCutValue(t, g, v);
  15684. });
  15685. }
  15686. function assignCutValue(t, g, child) {
  15687. var childLab = t.node(child),
  15688. parent = childLab.parent;
  15689. t.edge(child, parent).cutvalue = calcCutValue(t, g, child);
  15690. }
  15691. /*
  15692. * Given the tight tree, its graph, and a child in the graph calculate and
  15693. * return the cut value for the edge between the child and its parent.
  15694. */
  15695. function calcCutValue(t, g, child) {
  15696. var childLab = t.node(child),
  15697. parent = childLab.parent,
  15698. // True if the child is on the tail end of the edge in the directed graph
  15699. childIsTail = true,
  15700. // The graph's view of the tree edge we're inspecting
  15701. graphEdge = g.edge(child, parent),
  15702. // The accumulated cut value for the edge between this node and its parent
  15703. cutValue = 0;
  15704. if (!graphEdge) {
  15705. childIsTail = false;
  15706. graphEdge = g.edge(parent, child);
  15707. }
  15708. cutValue = graphEdge.weight;
  15709. _.each(g.nodeEdges(child), function(e) {
  15710. var isOutEdge = e.v === child,
  15711. other = isOutEdge ? e.w : e.v;
  15712. if (other !== parent) {
  15713. var pointsToHead = isOutEdge === childIsTail,
  15714. otherWeight = g.edge(e).weight;
  15715. cutValue += pointsToHead ? otherWeight : -otherWeight;
  15716. if (isTreeEdge(t, child, other)) {
  15717. var otherCutValue = t.edge(child, other).cutvalue;
  15718. cutValue += pointsToHead ? -otherCutValue : otherCutValue;
  15719. }
  15720. }
  15721. });
  15722. return cutValue;
  15723. }
  15724. function initLowLimValues(tree, root) {
  15725. if (arguments.length < 2) {
  15726. root = tree.nodes()[0];
  15727. }
  15728. dfsAssignLowLim(tree, {}, 1, root);
  15729. }
  15730. function dfsAssignLowLim(tree, visited, nextLim, v, parent) {
  15731. var low = nextLim,
  15732. label = tree.node(v);
  15733. visited[v] = true;
  15734. _.each(tree.neighbors(v), function(w) {
  15735. if (!_.has(visited, w)) {
  15736. nextLim = dfsAssignLowLim(tree, visited, nextLim, w, v);
  15737. }
  15738. });
  15739. label.low = low;
  15740. label.lim = nextLim++;
  15741. if (parent) {
  15742. label.parent = parent;
  15743. } else {
  15744. // TODO should be able to remove this when we incrementally update low lim
  15745. delete label.parent;
  15746. }
  15747. return nextLim;
  15748. }
  15749. function leaveEdge(tree) {
  15750. return _.find(tree.edges(), function(e) {
  15751. return tree.edge(e).cutvalue < 0;
  15752. });
  15753. }
  15754. function enterEdge(t, g, edge) {
  15755. var v = edge.v,
  15756. w = edge.w;
  15757. // For the rest of this function we assume that v is the tail and w is the
  15758. // head, so if we don't have this edge in the graph we should flip it to
  15759. // match the correct orientation.
  15760. if (!g.hasEdge(v, w)) {
  15761. v = edge.w;
  15762. w = edge.v;
  15763. }
  15764. var vLabel = t.node(v),
  15765. wLabel = t.node(w),
  15766. tailLabel = vLabel,
  15767. flip = false;
  15768. // If the root is in the tail of the edge then we need to flip the logic that
  15769. // checks for the head and tail nodes in the candidates function below.
  15770. if (vLabel.lim > wLabel.lim) {
  15771. tailLabel = wLabel;
  15772. flip = true;
  15773. }
  15774. var candidates = _.filter(g.edges(), function(edge) {
  15775. return flip === isDescendant(t, t.node(edge.v), tailLabel) &&
  15776. flip !== isDescendant(t, t.node(edge.w), tailLabel);
  15777. });
  15778. return _.min(candidates, function(edge) { return slack(g, edge); });
  15779. }
  15780. function exchangeEdges(t, g, e, f) {
  15781. var v = e.v,
  15782. w = e.w;
  15783. t.removeEdge(v, w);
  15784. t.setEdge(f.v, f.w, {});
  15785. initLowLimValues(t);
  15786. initCutValues(t, g);
  15787. updateRanks(t, g);
  15788. }
  15789. function updateRanks(t, g) {
  15790. var root = _.find(t.nodes(), function(v) { return !g.node(v).parent; }),
  15791. vs = preorder(t, root);
  15792. vs = vs.slice(1);
  15793. _.each(vs, function(v) {
  15794. var parent = t.node(v).parent,
  15795. edge = g.edge(v, parent),
  15796. flipped = false;
  15797. if (!edge) {
  15798. edge = g.edge(parent, v);
  15799. flipped = true;
  15800. }
  15801. g.node(v).rank = g.node(parent).rank + (flipped ? edge.minlen : -edge.minlen);
  15802. });
  15803. }
  15804. /*
  15805. * Returns true if the edge is in the tree.
  15806. */
  15807. function isTreeEdge(tree, u, v) {
  15808. return tree.hasEdge(u, v);
  15809. }
  15810. /*
  15811. * Returns true if the specified node is descendant of the root node per the
  15812. * assigned low and lim attributes in the tree.
  15813. */
  15814. function isDescendant(tree, vLabel, rootLabel) {
  15815. return rootLabel.low <= vLabel.lim && vLabel.lim <= rootLabel.lim;
  15816. }
  15817. },{"../graphlib":57,"../lodash":60,"../util":79,"./feasible-tree":75,"./util":78}],78:[function(require,module,exports){
  15818. "use strict";
  15819. var _ = require("../lodash");
  15820. module.exports = {
  15821. longestPath: longestPath,
  15822. slack: slack
  15823. };
  15824. /*
  15825. * Initializes ranks for the input graph using the longest path algorithm. This
  15826. * algorithm scales well and is fast in practice, it yields rather poor
  15827. * solutions. Nodes are pushed to the lowest layer possible, leaving the bottom
  15828. * ranks wide and leaving edges longer than necessary. However, due to its
  15829. * speed, this algorithm is good for getting an initial ranking that can be fed
  15830. * into other algorithms.
  15831. *
  15832. * This algorithm does not normalize layers because it will be used by other
  15833. * algorithms in most cases. If using this algorithm directly, be sure to
  15834. * run normalize at the end.
  15835. *
  15836. * Pre-conditions:
  15837. *
  15838. * 1. Input graph is a DAG.
  15839. * 2. Input graph node labels can be assigned properties.
  15840. *
  15841. * Post-conditions:
  15842. *
  15843. * 1. Each node will be assign an (unnormalized) "rank" property.
  15844. */
  15845. function longestPath(g) {
  15846. var visited = {};
  15847. function dfs(v) {
  15848. var label = g.node(v);
  15849. if (_.has(visited, v)) {
  15850. return label.rank;
  15851. }
  15852. visited[v] = true;
  15853. var rank = _.min(_.map(g.outEdges(v), function(e) {
  15854. return dfs(e.w) - g.edge(e).minlen;
  15855. }));
  15856. if (rank === Number.POSITIVE_INFINITY) {
  15857. rank = 0;
  15858. }
  15859. return (label.rank = rank);
  15860. }
  15861. _.each(g.sources(), dfs);
  15862. }
  15863. /*
  15864. * Returns the amount of slack for the given edge. The slack is defined as the
  15865. * difference between the length of the edge and its minimum length.
  15866. */
  15867. function slack(g, e) {
  15868. return g.node(e.w).rank - g.node(e.v).rank - g.edge(e).minlen;
  15869. }
  15870. },{"../lodash":60}],79:[function(require,module,exports){
  15871. "use strict";
  15872. var _ = require("./lodash"),
  15873. Graph = require("./graphlib").Graph;
  15874. module.exports = {
  15875. addDummyNode: addDummyNode,
  15876. simplify: simplify,
  15877. asNonCompoundGraph: asNonCompoundGraph,
  15878. successorWeights: successorWeights,
  15879. predecessorWeights: predecessorWeights,
  15880. intersectRect: intersectRect,
  15881. buildLayerMatrix: buildLayerMatrix,
  15882. normalizeRanks: normalizeRanks,
  15883. removeEmptyRanks: removeEmptyRanks,
  15884. addBorderNode: addBorderNode,
  15885. maxRank: maxRank,
  15886. partition: partition,
  15887. time: time,
  15888. notime: notime
  15889. };
  15890. /*
  15891. * Adds a dummy node to the graph and return v.
  15892. */
  15893. function addDummyNode(g, type, attrs, name) {
  15894. var v;
  15895. do {
  15896. v = _.uniqueId(name);
  15897. } while (g.hasNode(v));
  15898. attrs.dummy = type;
  15899. g.setNode(v, attrs);
  15900. return v;
  15901. }
  15902. /*
  15903. * Returns a new graph with only simple edges. Handles aggregation of data
  15904. * associated with multi-edges.
  15905. */
  15906. function simplify(g) {
  15907. var simplified = new Graph().setGraph(g.graph());
  15908. _.each(g.nodes(), function(v) { simplified.setNode(v, g.node(v)); });
  15909. _.each(g.edges(), function(e) {
  15910. var simpleLabel = simplified.edge(e.v, e.w) || { weight: 0, minlen: 1 },
  15911. label = g.edge(e);
  15912. simplified.setEdge(e.v, e.w, {
  15913. weight: simpleLabel.weight + label.weight,
  15914. minlen: Math.max(simpleLabel.minlen, label.minlen)
  15915. });
  15916. });
  15917. return simplified;
  15918. }
  15919. function asNonCompoundGraph(g) {
  15920. var simplified = new Graph({ multigraph: g.isMultigraph() }).setGraph(g.graph());
  15921. _.each(g.nodes(), function(v) {
  15922. if (!g.children(v).length) {
  15923. simplified.setNode(v, g.node(v));
  15924. }
  15925. });
  15926. _.each(g.edges(), function(e) {
  15927. simplified.setEdge(e, g.edge(e));
  15928. });
  15929. return simplified;
  15930. }
  15931. function successorWeights(g) {
  15932. var weightMap = _.map(g.nodes(), function(v) {
  15933. var sucs = {};
  15934. _.each(g.outEdges(v), function(e) {
  15935. sucs[e.w] = (sucs[e.w] || 0) + g.edge(e).weight;
  15936. });
  15937. return sucs;
  15938. });
  15939. return _.zipObject(g.nodes(), weightMap);
  15940. }
  15941. function predecessorWeights(g) {
  15942. var weightMap = _.map(g.nodes(), function(v) {
  15943. var preds = {};
  15944. _.each(g.inEdges(v), function(e) {
  15945. preds[e.v] = (preds[e.v] || 0) + g.edge(e).weight;
  15946. });
  15947. return preds;
  15948. });
  15949. return _.zipObject(g.nodes(), weightMap);
  15950. }
  15951. /*
  15952. * Finds where a line starting at point ({x, y}) would intersect a rectangle
  15953. * ({x, y, width, height}) if it were pointing at the rectangle's center.
  15954. */
  15955. function intersectRect(rect, point) {
  15956. var x = rect.x;
  15957. var y = rect.y;
  15958. // Rectangle intersection algorithm from:
  15959. // http://math.stackexchange.com/questions/108113/find-edge-between-two-boxes
  15960. var dx = point.x - x;
  15961. var dy = point.y - y;
  15962. var w = rect.width / 2;
  15963. var h = rect.height / 2;
  15964. if (!dx && !dy) {
  15965. throw new Error("Not possible to find intersection inside of the rectangle");
  15966. }
  15967. var sx, sy;
  15968. if (Math.abs(dy) * w > Math.abs(dx) * h) {
  15969. // Intersection is top or bottom of rect.
  15970. if (dy < 0) {
  15971. h = -h;
  15972. }
  15973. sx = h * dx / dy;
  15974. sy = h;
  15975. } else {
  15976. // Intersection is left or right of rect.
  15977. if (dx < 0) {
  15978. w = -w;
  15979. }
  15980. sx = w;
  15981. sy = w * dy / dx;
  15982. }
  15983. return { x: x + sx, y: y + sy };
  15984. }
  15985. /*
  15986. * Given a DAG with each node assigned "rank" and "order" properties, this
  15987. * function will produce a matrix with the ids of each node.
  15988. */
  15989. function buildLayerMatrix(g) {
  15990. var layering = _.map(_.range(maxRank(g) + 1), function() { return []; });
  15991. _.each(g.nodes(), function(v) {
  15992. var node = g.node(v),
  15993. rank = node.rank;
  15994. if (!_.isUndefined(rank)) {
  15995. layering[rank][node.order] = v;
  15996. }
  15997. });
  15998. return layering;
  15999. }
  16000. /*
  16001. * Adjusts the ranks for all nodes in the graph such that all nodes v have
  16002. * rank(v) >= 0 and at least one node w has rank(w) = 0.
  16003. */
  16004. function normalizeRanks(g) {
  16005. var min = _.min(_.map(g.nodes(), function(v) { return g.node(v).rank; }));
  16006. _.each(g.nodes(), function(v) {
  16007. var node = g.node(v);
  16008. if (_.has(node, "rank")) {
  16009. node.rank -= min;
  16010. }
  16011. });
  16012. }
  16013. function removeEmptyRanks(g) {
  16014. // Ranks may not start at 0, so we need to offset them
  16015. var offset = _.min(_.map(g.nodes(), function(v) { return g.node(v).rank; }));
  16016. var layers = [];
  16017. _.each(g.nodes(), function(v) {
  16018. var rank = g.node(v).rank - offset;
  16019. if (!layers[rank]) {
  16020. layers[rank] = [];
  16021. }
  16022. layers[rank].push(v);
  16023. });
  16024. var delta = 0,
  16025. nodeRankFactor = g.graph().nodeRankFactor;
  16026. _.each(layers, function(vs, i) {
  16027. if (_.isUndefined(vs) && i % nodeRankFactor !== 0) {
  16028. --delta;
  16029. } else if (delta) {
  16030. _.each(vs, function(v) { g.node(v).rank += delta; });
  16031. }
  16032. });
  16033. }
  16034. function addBorderNode(g, prefix, rank, order) {
  16035. var node = {
  16036. width: 0,
  16037. height: 0
  16038. };
  16039. if (arguments.length >= 4) {
  16040. node.rank = rank;
  16041. node.order = order;
  16042. }
  16043. return addDummyNode(g, "border", node, prefix);
  16044. }
  16045. function maxRank(g) {
  16046. return _.max(_.map(g.nodes(), function(v) {
  16047. var rank = g.node(v).rank;
  16048. if (!_.isUndefined(rank)) {
  16049. return rank;
  16050. }
  16051. }));
  16052. }
  16053. /*
  16054. * Partition a collection into two groups: `lhs` and `rhs`. If the supplied
  16055. * function returns true for an entry it goes into `lhs`. Otherwise it goes
  16056. * into `rhs.
  16057. */
  16058. function partition(collection, fn) {
  16059. var result = { lhs: [], rhs: [] };
  16060. _.each(collection, function(value) {
  16061. if (fn(value)) {
  16062. result.lhs.push(value);
  16063. } else {
  16064. result.rhs.push(value);
  16065. }
  16066. });
  16067. return result;
  16068. }
  16069. /*
  16070. * Returns a new function that wraps `fn` with a timer. The wrapper logs the
  16071. * time it takes to execute the function.
  16072. */
  16073. function time(name, fn) {
  16074. var start = _.now();
  16075. try {
  16076. return fn();
  16077. } finally {
  16078. console.log(name + " time: " + (_.now() - start) + "ms");
  16079. }
  16080. }
  16081. function notime(name, fn) {
  16082. return fn();
  16083. }
  16084. },{"./graphlib":57,"./lodash":60}],80:[function(require,module,exports){
  16085. module.exports = "0.7.4";
  16086. },{}],81:[function(require,module,exports){
  16087. module.exports=require(30)
  16088. },{"./lib":97,"./lib/alg":88,"./lib/json":98,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/index.js":30}],82:[function(require,module,exports){
  16089. module.exports=require(31)
  16090. },{"../lodash":99,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/alg/components.js":31}],83:[function(require,module,exports){
  16091. module.exports=require(32)
  16092. },{"../lodash":99,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/alg/dfs.js":32}],84:[function(require,module,exports){
  16093. module.exports=require(33)
  16094. },{"../lodash":99,"./dijkstra":85,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/alg/dijkstra-all.js":33}],85:[function(require,module,exports){
  16095. module.exports=require(34)
  16096. },{"../data/priority-queue":95,"../lodash":99,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/alg/dijkstra.js":34}],86:[function(require,module,exports){
  16097. module.exports=require(35)
  16098. },{"../lodash":99,"./tarjan":93,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/alg/find-cycles.js":35}],87:[function(require,module,exports){
  16099. module.exports=require(36)
  16100. },{"../lodash":99,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/alg/floyd-warshall.js":36}],88:[function(require,module,exports){
  16101. module.exports=require(37)
  16102. },{"./components":82,"./dijkstra":85,"./dijkstra-all":84,"./find-cycles":86,"./floyd-warshall":87,"./is-acyclic":89,"./postorder":90,"./preorder":91,"./prim":92,"./tarjan":93,"./topsort":94,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/alg/index.js":37}],89:[function(require,module,exports){
  16103. module.exports=require(38)
  16104. },{"./topsort":94,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/alg/is-acyclic.js":38}],90:[function(require,module,exports){
  16105. module.exports=require(39)
  16106. },{"./dfs":83,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/alg/postorder.js":39}],91:[function(require,module,exports){
  16107. module.exports=require(40)
  16108. },{"./dfs":83,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/alg/preorder.js":40}],92:[function(require,module,exports){
  16109. module.exports=require(41)
  16110. },{"../data/priority-queue":95,"../graph":96,"../lodash":99,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/alg/prim.js":41}],93:[function(require,module,exports){
  16111. module.exports=require(42)
  16112. },{"../lodash":99,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/alg/tarjan.js":42}],94:[function(require,module,exports){
  16113. module.exports=require(43)
  16114. },{"../lodash":99,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/alg/topsort.js":43}],95:[function(require,module,exports){
  16115. module.exports=require(44)
  16116. },{"../lodash":99,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/data/priority-queue.js":44}],96:[function(require,module,exports){
  16117. module.exports=require(45)
  16118. },{"./lodash":99,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/graph.js":45}],97:[function(require,module,exports){
  16119. module.exports=require(46)
  16120. },{"./graph":96,"./version":100,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/index.js":46}],98:[function(require,module,exports){
  16121. module.exports=require(47)
  16122. },{"./graph":96,"./lodash":99,"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/json.js":47}],99:[function(require,module,exports){
  16123. module.exports=require(48)
  16124. },{"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/lodash.js":48,"lodash":101}],100:[function(require,module,exports){
  16125. module.exports=require(49)
  16126. },{"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/graphlib/lib/version.js":49}],101:[function(require,module,exports){
  16127. module.exports=require(50)
  16128. },{"/Users/knut/source/mermaid/node_modules/dagre-d3/node_modules/lodash/index.js":50}],102:[function(require,module,exports){
  16129. (function (global){
  16130. /**
  16131. * @license
  16132. * lodash <https://lodash.com/>
  16133. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  16134. * Released under MIT license <https://lodash.com/license>
  16135. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  16136. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  16137. */
  16138. ;(function() {
  16139. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  16140. var undefined;
  16141. /** Used as the semantic version number. */
  16142. var VERSION = '4.13.1';
  16143. /** Used as the size to enable large array optimizations. */
  16144. var LARGE_ARRAY_SIZE = 200;
  16145. /** Used as the `TypeError` message for "Functions" methods. */
  16146. var FUNC_ERROR_TEXT = 'Expected a function';
  16147. /** Used to stand-in for `undefined` hash values. */
  16148. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  16149. /** Used as the internal argument placeholder. */
  16150. var PLACEHOLDER = '__lodash_placeholder__';
  16151. /** Used to compose bitmasks for wrapper metadata. */
  16152. var BIND_FLAG = 1,
  16153. BIND_KEY_FLAG = 2,
  16154. CURRY_BOUND_FLAG = 4,
  16155. CURRY_FLAG = 8,
  16156. CURRY_RIGHT_FLAG = 16,
  16157. PARTIAL_FLAG = 32,
  16158. PARTIAL_RIGHT_FLAG = 64,
  16159. ARY_FLAG = 128,
  16160. REARG_FLAG = 256,
  16161. FLIP_FLAG = 512;
  16162. /** Used to compose bitmasks for comparison styles. */
  16163. var UNORDERED_COMPARE_FLAG = 1,
  16164. PARTIAL_COMPARE_FLAG = 2;
  16165. /** Used as default options for `_.truncate`. */
  16166. var DEFAULT_TRUNC_LENGTH = 30,
  16167. DEFAULT_TRUNC_OMISSION = '...';
  16168. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  16169. var HOT_COUNT = 150,
  16170. HOT_SPAN = 16;
  16171. /** Used to indicate the type of lazy iteratees. */
  16172. var LAZY_FILTER_FLAG = 1,
  16173. LAZY_MAP_FLAG = 2,
  16174. LAZY_WHILE_FLAG = 3;
  16175. /** Used as references for various `Number` constants. */
  16176. var INFINITY = 1 / 0,
  16177. MAX_SAFE_INTEGER = 9007199254740991,
  16178. MAX_INTEGER = 1.7976931348623157e+308,
  16179. NAN = 0 / 0;
  16180. /** Used as references for the maximum length and index of an array. */
  16181. var MAX_ARRAY_LENGTH = 4294967295,
  16182. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  16183. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  16184. /** `Object#toString` result references. */
  16185. var argsTag = '[object Arguments]',
  16186. arrayTag = '[object Array]',
  16187. boolTag = '[object Boolean]',
  16188. dateTag = '[object Date]',
  16189. errorTag = '[object Error]',
  16190. funcTag = '[object Function]',
  16191. genTag = '[object GeneratorFunction]',
  16192. mapTag = '[object Map]',
  16193. numberTag = '[object Number]',
  16194. objectTag = '[object Object]',
  16195. promiseTag = '[object Promise]',
  16196. regexpTag = '[object RegExp]',
  16197. setTag = '[object Set]',
  16198. stringTag = '[object String]',
  16199. symbolTag = '[object Symbol]',
  16200. weakMapTag = '[object WeakMap]',
  16201. weakSetTag = '[object WeakSet]';
  16202. var arrayBufferTag = '[object ArrayBuffer]',
  16203. dataViewTag = '[object DataView]',
  16204. float32Tag = '[object Float32Array]',
  16205. float64Tag = '[object Float64Array]',
  16206. int8Tag = '[object Int8Array]',
  16207. int16Tag = '[object Int16Array]',
  16208. int32Tag = '[object Int32Array]',
  16209. uint8Tag = '[object Uint8Array]',
  16210. uint8ClampedTag = '[object Uint8ClampedArray]',
  16211. uint16Tag = '[object Uint16Array]',
  16212. uint32Tag = '[object Uint32Array]';
  16213. /** Used to match empty string literals in compiled template source. */
  16214. var reEmptyStringLeading = /\b__p \+= '';/g,
  16215. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  16216. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  16217. /** Used to match HTML entities and HTML characters. */
  16218. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
  16219. reUnescapedHtml = /[&<>"'`]/g,
  16220. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  16221. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  16222. /** Used to match template delimiters. */
  16223. var reEscape = /<%-([\s\S]+?)%>/g,
  16224. reEvaluate = /<%([\s\S]+?)%>/g,
  16225. reInterpolate = /<%=([\s\S]+?)%>/g;
  16226. /** Used to match property names within property paths. */
  16227. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  16228. reIsPlainProp = /^\w*$/,
  16229. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(\.|\[\])(?:\4|$))/g;
  16230. /**
  16231. * Used to match `RegExp`
  16232. * [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns).
  16233. */
  16234. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  16235. reHasRegExpChar = RegExp(reRegExpChar.source);
  16236. /** Used to match leading and trailing whitespace. */
  16237. var reTrim = /^\s+|\s+$/g,
  16238. reTrimStart = /^\s+/,
  16239. reTrimEnd = /\s+$/;
  16240. /** Used to match non-compound words composed of alphanumeric characters. */
  16241. var reBasicWord = /[a-zA-Z0-9]+/g;
  16242. /** Used to match backslashes in property paths. */
  16243. var reEscapeChar = /\\(\\)?/g;
  16244. /**
  16245. * Used to match
  16246. * [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components).
  16247. */
  16248. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  16249. /** Used to match `RegExp` flags from their coerced string values. */
  16250. var reFlags = /\w*$/;
  16251. /** Used to detect hexadecimal string values. */
  16252. var reHasHexPrefix = /^0x/i;
  16253. /** Used to detect bad signed hexadecimal string values. */
  16254. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  16255. /** Used to detect binary string values. */
  16256. var reIsBinary = /^0b[01]+$/i;
  16257. /** Used to detect host constructors (Safari). */
  16258. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  16259. /** Used to detect octal string values. */
  16260. var reIsOctal = /^0o[0-7]+$/i;
  16261. /** Used to detect unsigned integer values. */
  16262. var reIsUint = /^(?:0|[1-9]\d*)$/;
  16263. /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
  16264. var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
  16265. /** Used to ensure capturing order of template delimiters. */
  16266. var reNoMatch = /($^)/;
  16267. /** Used to match unescaped characters in compiled string literals. */
  16268. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  16269. /** Used to compose unicode character classes. */
  16270. var rsAstralRange = '\\ud800-\\udfff',
  16271. rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
  16272. rsComboSymbolsRange = '\\u20d0-\\u20f0',
  16273. rsDingbatRange = '\\u2700-\\u27bf',
  16274. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  16275. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  16276. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  16277. rsPunctuationRange = '\\u2000-\\u206f',
  16278. rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
  16279. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  16280. rsVarRange = '\\ufe0e\\ufe0f',
  16281. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  16282. /** Used to compose unicode capture groups. */
  16283. var rsApos = "['\u2019]",
  16284. rsAstral = '[' + rsAstralRange + ']',
  16285. rsBreak = '[' + rsBreakRange + ']',
  16286. rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
  16287. rsDigits = '\\d+',
  16288. rsDingbat = '[' + rsDingbatRange + ']',
  16289. rsLower = '[' + rsLowerRange + ']',
  16290. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  16291. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  16292. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  16293. rsNonAstral = '[^' + rsAstralRange + ']',
  16294. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  16295. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  16296. rsUpper = '[' + rsUpperRange + ']',
  16297. rsZWJ = '\\u200d';
  16298. /** Used to compose unicode regexes. */
  16299. var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')',
  16300. rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')',
  16301. rsOptLowerContr = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  16302. rsOptUpperContr = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  16303. reOptMod = rsModifier + '?',
  16304. rsOptVar = '[' + rsVarRange + ']?',
  16305. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  16306. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  16307. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  16308. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  16309. /** Used to match apostrophes. */
  16310. var reApos = RegExp(rsApos, 'g');
  16311. /**
  16312. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  16313. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  16314. */
  16315. var reComboMark = RegExp(rsCombo, 'g');
  16316. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  16317. var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  16318. /** Used to match complex or compound words. */
  16319. var reComplexWord = RegExp([
  16320. rsUpper + '?' + rsLower + '+' + rsOptLowerContr + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  16321. rsUpperMisc + '+' + rsOptUpperContr + '(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')',
  16322. rsUpper + '?' + rsLowerMisc + '+' + rsOptLowerContr,
  16323. rsUpper + '+' + rsOptUpperContr,
  16324. rsDigits,
  16325. rsEmoji
  16326. ].join('|'), 'g');
  16327. /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
  16328. var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
  16329. /** Used to detect strings that need a more robust regexp to match words. */
  16330. var reHasComplexWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
  16331. /** Used to assign default `context` object properties. */
  16332. var contextProps = [
  16333. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  16334. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  16335. 'Promise', 'Reflect', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError',
  16336. 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  16337. '_', 'isFinite', 'parseInt', 'setTimeout'
  16338. ];
  16339. /** Used to make template sourceURLs easier to identify. */
  16340. var templateCounter = -1;
  16341. /** Used to identify `toStringTag` values of typed arrays. */
  16342. var typedArrayTags = {};
  16343. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  16344. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  16345. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  16346. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  16347. typedArrayTags[uint32Tag] = true;
  16348. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  16349. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  16350. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  16351. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  16352. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  16353. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  16354. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  16355. typedArrayTags[weakMapTag] = false;
  16356. /** Used to identify `toStringTag` values supported by `_.clone`. */
  16357. var cloneableTags = {};
  16358. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  16359. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  16360. cloneableTags[boolTag] = cloneableTags[dateTag] =
  16361. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  16362. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  16363. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  16364. cloneableTags[numberTag] = cloneableTags[objectTag] =
  16365. cloneableTags[regexpTag] = cloneableTags[setTag] =
  16366. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  16367. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  16368. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  16369. cloneableTags[errorTag] = cloneableTags[funcTag] =
  16370. cloneableTags[weakMapTag] = false;
  16371. /** Used to map latin-1 supplementary letters to basic latin letters. */
  16372. var deburredLetters = {
  16373. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  16374. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  16375. '\xc7': 'C', '\xe7': 'c',
  16376. '\xd0': 'D', '\xf0': 'd',
  16377. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  16378. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  16379. '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  16380. '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  16381. '\xd1': 'N', '\xf1': 'n',
  16382. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  16383. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  16384. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  16385. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  16386. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  16387. '\xc6': 'Ae', '\xe6': 'ae',
  16388. '\xde': 'Th', '\xfe': 'th',
  16389. '\xdf': 'ss'
  16390. };
  16391. /** Used to map characters to HTML entities. */
  16392. var htmlEscapes = {
  16393. '&': '&amp;',
  16394. '<': '&lt;',
  16395. '>': '&gt;',
  16396. '"': '&quot;',
  16397. "'": '&#39;',
  16398. '`': '&#96;'
  16399. };
  16400. /** Used to map HTML entities to characters. */
  16401. var htmlUnescapes = {
  16402. '&amp;': '&',
  16403. '&lt;': '<',
  16404. '&gt;': '>',
  16405. '&quot;': '"',
  16406. '&#39;': "'",
  16407. '&#96;': '`'
  16408. };
  16409. /** Used to escape characters for inclusion in compiled string literals. */
  16410. var stringEscapes = {
  16411. '\\': '\\',
  16412. "'": "'",
  16413. '\n': 'n',
  16414. '\r': 'r',
  16415. '\u2028': 'u2028',
  16416. '\u2029': 'u2029'
  16417. };
  16418. /** Built-in method references without a dependency on `root`. */
  16419. var freeParseFloat = parseFloat,
  16420. freeParseInt = parseInt;
  16421. /** Detect free variable `exports`. */
  16422. var freeExports = typeof exports == 'object' && exports;
  16423. /** Detect free variable `module`. */
  16424. var freeModule = freeExports && typeof module == 'object' && module;
  16425. /** Detect the popular CommonJS extension `module.exports`. */
  16426. var moduleExports = freeModule && freeModule.exports === freeExports;
  16427. /** Detect free variable `global` from Node.js. */
  16428. var freeGlobal = checkGlobal(typeof global == 'object' && global);
  16429. /** Detect free variable `self`. */
  16430. var freeSelf = checkGlobal(typeof self == 'object' && self);
  16431. /** Detect `this` as the global object. */
  16432. var thisGlobal = checkGlobal(typeof this == 'object' && this);
  16433. /** Used as a reference to the global object. */
  16434. var root = freeGlobal || freeSelf || thisGlobal || Function('return this')();
  16435. /*--------------------------------------------------------------------------*/
  16436. /**
  16437. * Adds the key-value `pair` to `map`.
  16438. *
  16439. * @private
  16440. * @param {Object} map The map to modify.
  16441. * @param {Array} pair The key-value pair to add.
  16442. * @returns {Object} Returns `map`.
  16443. */
  16444. function addMapEntry(map, pair) {
  16445. // Don't return `Map#set` because it doesn't return the map instance in IE 11.
  16446. map.set(pair[0], pair[1]);
  16447. return map;
  16448. }
  16449. /**
  16450. * Adds `value` to `set`.
  16451. *
  16452. * @private
  16453. * @param {Object} set The set to modify.
  16454. * @param {*} value The value to add.
  16455. * @returns {Object} Returns `set`.
  16456. */
  16457. function addSetEntry(set, value) {
  16458. set.add(value);
  16459. return set;
  16460. }
  16461. /**
  16462. * A faster alternative to `Function#apply`, this function invokes `func`
  16463. * with the `this` binding of `thisArg` and the arguments of `args`.
  16464. *
  16465. * @private
  16466. * @param {Function} func The function to invoke.
  16467. * @param {*} thisArg The `this` binding of `func`.
  16468. * @param {Array} args The arguments to invoke `func` with.
  16469. * @returns {*} Returns the result of `func`.
  16470. */
  16471. function apply(func, thisArg, args) {
  16472. var length = args.length;
  16473. switch (length) {
  16474. case 0: return func.call(thisArg);
  16475. case 1: return func.call(thisArg, args[0]);
  16476. case 2: return func.call(thisArg, args[0], args[1]);
  16477. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  16478. }
  16479. return func.apply(thisArg, args);
  16480. }
  16481. /**
  16482. * A specialized version of `baseAggregator` for arrays.
  16483. *
  16484. * @private
  16485. * @param {Array} [array] The array to iterate over.
  16486. * @param {Function} setter The function to set `accumulator` values.
  16487. * @param {Function} iteratee The iteratee to transform keys.
  16488. * @param {Object} accumulator The initial aggregated object.
  16489. * @returns {Function} Returns `accumulator`.
  16490. */
  16491. function arrayAggregator(array, setter, iteratee, accumulator) {
  16492. var index = -1,
  16493. length = array ? array.length : 0;
  16494. while (++index < length) {
  16495. var value = array[index];
  16496. setter(accumulator, value, iteratee(value), array);
  16497. }
  16498. return accumulator;
  16499. }
  16500. /**
  16501. * A specialized version of `_.forEach` for arrays without support for
  16502. * iteratee shorthands.
  16503. *
  16504. * @private
  16505. * @param {Array} [array] The array to iterate over.
  16506. * @param {Function} iteratee The function invoked per iteration.
  16507. * @returns {Array} Returns `array`.
  16508. */
  16509. function arrayEach(array, iteratee) {
  16510. var index = -1,
  16511. length = array ? array.length : 0;
  16512. while (++index < length) {
  16513. if (iteratee(array[index], index, array) === false) {
  16514. break;
  16515. }
  16516. }
  16517. return array;
  16518. }
  16519. /**
  16520. * A specialized version of `_.forEachRight` for arrays without support for
  16521. * iteratee shorthands.
  16522. *
  16523. * @private
  16524. * @param {Array} [array] The array to iterate over.
  16525. * @param {Function} iteratee The function invoked per iteration.
  16526. * @returns {Array} Returns `array`.
  16527. */
  16528. function arrayEachRight(array, iteratee) {
  16529. var length = array ? array.length : 0;
  16530. while (length--) {
  16531. if (iteratee(array[length], length, array) === false) {
  16532. break;
  16533. }
  16534. }
  16535. return array;
  16536. }
  16537. /**
  16538. * A specialized version of `_.every` for arrays without support for
  16539. * iteratee shorthands.
  16540. *
  16541. * @private
  16542. * @param {Array} [array] The array to iterate over.
  16543. * @param {Function} predicate The function invoked per iteration.
  16544. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  16545. * else `false`.
  16546. */
  16547. function arrayEvery(array, predicate) {
  16548. var index = -1,
  16549. length = array ? array.length : 0;
  16550. while (++index < length) {
  16551. if (!predicate(array[index], index, array)) {
  16552. return false;
  16553. }
  16554. }
  16555. return true;
  16556. }
  16557. /**
  16558. * A specialized version of `_.filter` for arrays without support for
  16559. * iteratee shorthands.
  16560. *
  16561. * @private
  16562. * @param {Array} [array] The array to iterate over.
  16563. * @param {Function} predicate The function invoked per iteration.
  16564. * @returns {Array} Returns the new filtered array.
  16565. */
  16566. function arrayFilter(array, predicate) {
  16567. var index = -1,
  16568. length = array ? array.length : 0,
  16569. resIndex = 0,
  16570. result = [];
  16571. while (++index < length) {
  16572. var value = array[index];
  16573. if (predicate(value, index, array)) {
  16574. result[resIndex++] = value;
  16575. }
  16576. }
  16577. return result;
  16578. }
  16579. /**
  16580. * A specialized version of `_.includes` for arrays without support for
  16581. * specifying an index to search from.
  16582. *
  16583. * @private
  16584. * @param {Array} [array] The array to search.
  16585. * @param {*} target The value to search for.
  16586. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  16587. */
  16588. function arrayIncludes(array, value) {
  16589. var length = array ? array.length : 0;
  16590. return !!length && baseIndexOf(array, value, 0) > -1;
  16591. }
  16592. /**
  16593. * This function is like `arrayIncludes` except that it accepts a comparator.
  16594. *
  16595. * @private
  16596. * @param {Array} [array] The array to search.
  16597. * @param {*} target The value to search for.
  16598. * @param {Function} comparator The comparator invoked per element.
  16599. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  16600. */
  16601. function arrayIncludesWith(array, value, comparator) {
  16602. var index = -1,
  16603. length = array ? array.length : 0;
  16604. while (++index < length) {
  16605. if (comparator(value, array[index])) {
  16606. return true;
  16607. }
  16608. }
  16609. return false;
  16610. }
  16611. /**
  16612. * A specialized version of `_.map` for arrays without support for iteratee
  16613. * shorthands.
  16614. *
  16615. * @private
  16616. * @param {Array} [array] The array to iterate over.
  16617. * @param {Function} iteratee The function invoked per iteration.
  16618. * @returns {Array} Returns the new mapped array.
  16619. */
  16620. function arrayMap(array, iteratee) {
  16621. var index = -1,
  16622. length = array ? array.length : 0,
  16623. result = Array(length);
  16624. while (++index < length) {
  16625. result[index] = iteratee(array[index], index, array);
  16626. }
  16627. return result;
  16628. }
  16629. /**
  16630. * Appends the elements of `values` to `array`.
  16631. *
  16632. * @private
  16633. * @param {Array} array The array to modify.
  16634. * @param {Array} values The values to append.
  16635. * @returns {Array} Returns `array`.
  16636. */
  16637. function arrayPush(array, values) {
  16638. var index = -1,
  16639. length = values.length,
  16640. offset = array.length;
  16641. while (++index < length) {
  16642. array[offset + index] = values[index];
  16643. }
  16644. return array;
  16645. }
  16646. /**
  16647. * A specialized version of `_.reduce` for arrays without support for
  16648. * iteratee shorthands.
  16649. *
  16650. * @private
  16651. * @param {Array} [array] The array to iterate over.
  16652. * @param {Function} iteratee The function invoked per iteration.
  16653. * @param {*} [accumulator] The initial value.
  16654. * @param {boolean} [initAccum] Specify using the first element of `array` as
  16655. * the initial value.
  16656. * @returns {*} Returns the accumulated value.
  16657. */
  16658. function arrayReduce(array, iteratee, accumulator, initAccum) {
  16659. var index = -1,
  16660. length = array ? array.length : 0;
  16661. if (initAccum && length) {
  16662. accumulator = array[++index];
  16663. }
  16664. while (++index < length) {
  16665. accumulator = iteratee(accumulator, array[index], index, array);
  16666. }
  16667. return accumulator;
  16668. }
  16669. /**
  16670. * A specialized version of `_.reduceRight` for arrays without support for
  16671. * iteratee shorthands.
  16672. *
  16673. * @private
  16674. * @param {Array} [array] The array to iterate over.
  16675. * @param {Function} iteratee The function invoked per iteration.
  16676. * @param {*} [accumulator] The initial value.
  16677. * @param {boolean} [initAccum] Specify using the last element of `array` as
  16678. * the initial value.
  16679. * @returns {*} Returns the accumulated value.
  16680. */
  16681. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  16682. var length = array ? array.length : 0;
  16683. if (initAccum && length) {
  16684. accumulator = array[--length];
  16685. }
  16686. while (length--) {
  16687. accumulator = iteratee(accumulator, array[length], length, array);
  16688. }
  16689. return accumulator;
  16690. }
  16691. /**
  16692. * A specialized version of `_.some` for arrays without support for iteratee
  16693. * shorthands.
  16694. *
  16695. * @private
  16696. * @param {Array} [array] The array to iterate over.
  16697. * @param {Function} predicate The function invoked per iteration.
  16698. * @returns {boolean} Returns `true` if any element passes the predicate check,
  16699. * else `false`.
  16700. */
  16701. function arraySome(array, predicate) {
  16702. var index = -1,
  16703. length = array ? array.length : 0;
  16704. while (++index < length) {
  16705. if (predicate(array[index], index, array)) {
  16706. return true;
  16707. }
  16708. }
  16709. return false;
  16710. }
  16711. /**
  16712. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  16713. * without support for iteratee shorthands, which iterates over `collection`
  16714. * using `eachFunc`.
  16715. *
  16716. * @private
  16717. * @param {Array|Object} collection The collection to search.
  16718. * @param {Function} predicate The function invoked per iteration.
  16719. * @param {Function} eachFunc The function to iterate over `collection`.
  16720. * @returns {*} Returns the found element or its key, else `undefined`.
  16721. */
  16722. function baseFindKey(collection, predicate, eachFunc) {
  16723. var result;
  16724. eachFunc(collection, function(value, key, collection) {
  16725. if (predicate(value, key, collection)) {
  16726. result = key;
  16727. return false;
  16728. }
  16729. });
  16730. return result;
  16731. }
  16732. /**
  16733. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  16734. * support for iteratee shorthands.
  16735. *
  16736. * @private
  16737. * @param {Array} array The array to search.
  16738. * @param {Function} predicate The function invoked per iteration.
  16739. * @param {number} fromIndex The index to search from.
  16740. * @param {boolean} [fromRight] Specify iterating from right to left.
  16741. * @returns {number} Returns the index of the matched value, else `-1`.
  16742. */
  16743. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  16744. var length = array.length,
  16745. index = fromIndex + (fromRight ? 1 : -1);
  16746. while ((fromRight ? index-- : ++index < length)) {
  16747. if (predicate(array[index], index, array)) {
  16748. return index;
  16749. }
  16750. }
  16751. return -1;
  16752. }
  16753. /**
  16754. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  16755. *
  16756. * @private
  16757. * @param {Array} array The array to search.
  16758. * @param {*} value The value to search for.
  16759. * @param {number} fromIndex The index to search from.
  16760. * @returns {number} Returns the index of the matched value, else `-1`.
  16761. */
  16762. function baseIndexOf(array, value, fromIndex) {
  16763. if (value !== value) {
  16764. return indexOfNaN(array, fromIndex);
  16765. }
  16766. var index = fromIndex - 1,
  16767. length = array.length;
  16768. while (++index < length) {
  16769. if (array[index] === value) {
  16770. return index;
  16771. }
  16772. }
  16773. return -1;
  16774. }
  16775. /**
  16776. * This function is like `baseIndexOf` except that it accepts a comparator.
  16777. *
  16778. * @private
  16779. * @param {Array} array The array to search.
  16780. * @param {*} value The value to search for.
  16781. * @param {number} fromIndex The index to search from.
  16782. * @param {Function} comparator The comparator invoked per element.
  16783. * @returns {number} Returns the index of the matched value, else `-1`.
  16784. */
  16785. function baseIndexOfWith(array, value, fromIndex, comparator) {
  16786. var index = fromIndex - 1,
  16787. length = array.length;
  16788. while (++index < length) {
  16789. if (comparator(array[index], value)) {
  16790. return index;
  16791. }
  16792. }
  16793. return -1;
  16794. }
  16795. /**
  16796. * The base implementation of `_.mean` and `_.meanBy` without support for
  16797. * iteratee shorthands.
  16798. *
  16799. * @private
  16800. * @param {Array} array The array to iterate over.
  16801. * @param {Function} iteratee The function invoked per iteration.
  16802. * @returns {number} Returns the mean.
  16803. */
  16804. function baseMean(array, iteratee) {
  16805. var length = array ? array.length : 0;
  16806. return length ? (baseSum(array, iteratee) / length) : NAN;
  16807. }
  16808. /**
  16809. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  16810. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  16811. *
  16812. * @private
  16813. * @param {Array|Object} collection The collection to iterate over.
  16814. * @param {Function} iteratee The function invoked per iteration.
  16815. * @param {*} accumulator The initial value.
  16816. * @param {boolean} initAccum Specify using the first or last element of
  16817. * `collection` as the initial value.
  16818. * @param {Function} eachFunc The function to iterate over `collection`.
  16819. * @returns {*} Returns the accumulated value.
  16820. */
  16821. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  16822. eachFunc(collection, function(value, index, collection) {
  16823. accumulator = initAccum
  16824. ? (initAccum = false, value)
  16825. : iteratee(accumulator, value, index, collection);
  16826. });
  16827. return accumulator;
  16828. }
  16829. /**
  16830. * The base implementation of `_.sortBy` which uses `comparer` to define the
  16831. * sort order of `array` and replaces criteria objects with their corresponding
  16832. * values.
  16833. *
  16834. * @private
  16835. * @param {Array} array The array to sort.
  16836. * @param {Function} comparer The function to define sort order.
  16837. * @returns {Array} Returns `array`.
  16838. */
  16839. function baseSortBy(array, comparer) {
  16840. var length = array.length;
  16841. array.sort(comparer);
  16842. while (length--) {
  16843. array[length] = array[length].value;
  16844. }
  16845. return array;
  16846. }
  16847. /**
  16848. * The base implementation of `_.sum` and `_.sumBy` without support for
  16849. * iteratee shorthands.
  16850. *
  16851. * @private
  16852. * @param {Array} array The array to iterate over.
  16853. * @param {Function} iteratee The function invoked per iteration.
  16854. * @returns {number} Returns the sum.
  16855. */
  16856. function baseSum(array, iteratee) {
  16857. var result,
  16858. index = -1,
  16859. length = array.length;
  16860. while (++index < length) {
  16861. var current = iteratee(array[index]);
  16862. if (current !== undefined) {
  16863. result = result === undefined ? current : (result + current);
  16864. }
  16865. }
  16866. return result;
  16867. }
  16868. /**
  16869. * The base implementation of `_.times` without support for iteratee shorthands
  16870. * or max array length checks.
  16871. *
  16872. * @private
  16873. * @param {number} n The number of times to invoke `iteratee`.
  16874. * @param {Function} iteratee The function invoked per iteration.
  16875. * @returns {Array} Returns the array of results.
  16876. */
  16877. function baseTimes(n, iteratee) {
  16878. var index = -1,
  16879. result = Array(n);
  16880. while (++index < n) {
  16881. result[index] = iteratee(index);
  16882. }
  16883. return result;
  16884. }
  16885. /**
  16886. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  16887. * of key-value pairs for `object` corresponding to the property names of `props`.
  16888. *
  16889. * @private
  16890. * @param {Object} object The object to query.
  16891. * @param {Array} props The property names to get values for.
  16892. * @returns {Object} Returns the key-value pairs.
  16893. */
  16894. function baseToPairs(object, props) {
  16895. return arrayMap(props, function(key) {
  16896. return [key, object[key]];
  16897. });
  16898. }
  16899. /**
  16900. * The base implementation of `_.unary` without support for storing wrapper metadata.
  16901. *
  16902. * @private
  16903. * @param {Function} func The function to cap arguments for.
  16904. * @returns {Function} Returns the new capped function.
  16905. */
  16906. function baseUnary(func) {
  16907. return function(value) {
  16908. return func(value);
  16909. };
  16910. }
  16911. /**
  16912. * The base implementation of `_.values` and `_.valuesIn` which creates an
  16913. * array of `object` property values corresponding to the property names
  16914. * of `props`.
  16915. *
  16916. * @private
  16917. * @param {Object} object The object to query.
  16918. * @param {Array} props The property names to get values for.
  16919. * @returns {Object} Returns the array of property values.
  16920. */
  16921. function baseValues(object, props) {
  16922. return arrayMap(props, function(key) {
  16923. return object[key];
  16924. });
  16925. }
  16926. /**
  16927. * Checks if a cache value for `key` exists.
  16928. *
  16929. * @private
  16930. * @param {Object} cache The cache to query.
  16931. * @param {string} key The key of the entry to check.
  16932. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  16933. */
  16934. function cacheHas(cache, key) {
  16935. return cache.has(key);
  16936. }
  16937. /**
  16938. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  16939. * that is not found in the character symbols.
  16940. *
  16941. * @private
  16942. * @param {Array} strSymbols The string symbols to inspect.
  16943. * @param {Array} chrSymbols The character symbols to find.
  16944. * @returns {number} Returns the index of the first unmatched string symbol.
  16945. */
  16946. function charsStartIndex(strSymbols, chrSymbols) {
  16947. var index = -1,
  16948. length = strSymbols.length;
  16949. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  16950. return index;
  16951. }
  16952. /**
  16953. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  16954. * that is not found in the character symbols.
  16955. *
  16956. * @private
  16957. * @param {Array} strSymbols The string symbols to inspect.
  16958. * @param {Array} chrSymbols The character symbols to find.
  16959. * @returns {number} Returns the index of the last unmatched string symbol.
  16960. */
  16961. function charsEndIndex(strSymbols, chrSymbols) {
  16962. var index = strSymbols.length;
  16963. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  16964. return index;
  16965. }
  16966. /**
  16967. * Checks if `value` is a global object.
  16968. *
  16969. * @private
  16970. * @param {*} value The value to check.
  16971. * @returns {null|Object} Returns `value` if it's a global object, else `null`.
  16972. */
  16973. function checkGlobal(value) {
  16974. return (value && value.Object === Object) ? value : null;
  16975. }
  16976. /**
  16977. * Gets the number of `placeholder` occurrences in `array`.
  16978. *
  16979. * @private
  16980. * @param {Array} array The array to inspect.
  16981. * @param {*} placeholder The placeholder to search for.
  16982. * @returns {number} Returns the placeholder count.
  16983. */
  16984. function countHolders(array, placeholder) {
  16985. var length = array.length,
  16986. result = 0;
  16987. while (length--) {
  16988. if (array[length] === placeholder) {
  16989. result++;
  16990. }
  16991. }
  16992. return result;
  16993. }
  16994. /**
  16995. * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
  16996. *
  16997. * @private
  16998. * @param {string} letter The matched letter to deburr.
  16999. * @returns {string} Returns the deburred letter.
  17000. */
  17001. function deburrLetter(letter) {
  17002. return deburredLetters[letter];
  17003. }
  17004. /**
  17005. * Used by `_.escape` to convert characters to HTML entities.
  17006. *
  17007. * @private
  17008. * @param {string} chr The matched character to escape.
  17009. * @returns {string} Returns the escaped character.
  17010. */
  17011. function escapeHtmlChar(chr) {
  17012. return htmlEscapes[chr];
  17013. }
  17014. /**
  17015. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  17016. *
  17017. * @private
  17018. * @param {string} chr The matched character to escape.
  17019. * @returns {string} Returns the escaped character.
  17020. */
  17021. function escapeStringChar(chr) {
  17022. return '\\' + stringEscapes[chr];
  17023. }
  17024. /**
  17025. * Gets the value at `key` of `object`.
  17026. *
  17027. * @private
  17028. * @param {Object} [object] The object to query.
  17029. * @param {string} key The key of the property to get.
  17030. * @returns {*} Returns the property value.
  17031. */
  17032. function getValue(object, key) {
  17033. return object == null ? undefined : object[key];
  17034. }
  17035. /**
  17036. * Gets the index at which the first occurrence of `NaN` is found in `array`.
  17037. *
  17038. * @private
  17039. * @param {Array} array The array to search.
  17040. * @param {number} fromIndex The index to search from.
  17041. * @param {boolean} [fromRight] Specify iterating from right to left.
  17042. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
  17043. */
  17044. function indexOfNaN(array, fromIndex, fromRight) {
  17045. var length = array.length,
  17046. index = fromIndex + (fromRight ? 1 : -1);
  17047. while ((fromRight ? index-- : ++index < length)) {
  17048. var other = array[index];
  17049. if (other !== other) {
  17050. return index;
  17051. }
  17052. }
  17053. return -1;
  17054. }
  17055. /**
  17056. * Checks if `value` is a host object in IE < 9.
  17057. *
  17058. * @private
  17059. * @param {*} value The value to check.
  17060. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  17061. */
  17062. function isHostObject(value) {
  17063. // Many host objects are `Object` objects that can coerce to strings
  17064. // despite having improperly defined `toString` methods.
  17065. var result = false;
  17066. if (value != null && typeof value.toString != 'function') {
  17067. try {
  17068. result = !!(value + '');
  17069. } catch (e) {}
  17070. }
  17071. return result;
  17072. }
  17073. /**
  17074. * Converts `iterator` to an array.
  17075. *
  17076. * @private
  17077. * @param {Object} iterator The iterator to convert.
  17078. * @returns {Array} Returns the converted array.
  17079. */
  17080. function iteratorToArray(iterator) {
  17081. var data,
  17082. result = [];
  17083. while (!(data = iterator.next()).done) {
  17084. result.push(data.value);
  17085. }
  17086. return result;
  17087. }
  17088. /**
  17089. * Converts `map` to its key-value pairs.
  17090. *
  17091. * @private
  17092. * @param {Object} map The map to convert.
  17093. * @returns {Array} Returns the key-value pairs.
  17094. */
  17095. function mapToArray(map) {
  17096. var index = -1,
  17097. result = Array(map.size);
  17098. map.forEach(function(value, key) {
  17099. result[++index] = [key, value];
  17100. });
  17101. return result;
  17102. }
  17103. /**
  17104. * Replaces all `placeholder` elements in `array` with an internal placeholder
  17105. * and returns an array of their indexes.
  17106. *
  17107. * @private
  17108. * @param {Array} array The array to modify.
  17109. * @param {*} placeholder The placeholder to replace.
  17110. * @returns {Array} Returns the new array of placeholder indexes.
  17111. */
  17112. function replaceHolders(array, placeholder) {
  17113. var index = -1,
  17114. length = array.length,
  17115. resIndex = 0,
  17116. result = [];
  17117. while (++index < length) {
  17118. var value = array[index];
  17119. if (value === placeholder || value === PLACEHOLDER) {
  17120. array[index] = PLACEHOLDER;
  17121. result[resIndex++] = index;
  17122. }
  17123. }
  17124. return result;
  17125. }
  17126. /**
  17127. * Converts `set` to an array of its values.
  17128. *
  17129. * @private
  17130. * @param {Object} set The set to convert.
  17131. * @returns {Array} Returns the values.
  17132. */
  17133. function setToArray(set) {
  17134. var index = -1,
  17135. result = Array(set.size);
  17136. set.forEach(function(value) {
  17137. result[++index] = value;
  17138. });
  17139. return result;
  17140. }
  17141. /**
  17142. * Converts `set` to its value-value pairs.
  17143. *
  17144. * @private
  17145. * @param {Object} set The set to convert.
  17146. * @returns {Array} Returns the value-value pairs.
  17147. */
  17148. function setToPairs(set) {
  17149. var index = -1,
  17150. result = Array(set.size);
  17151. set.forEach(function(value) {
  17152. result[++index] = [value, value];
  17153. });
  17154. return result;
  17155. }
  17156. /**
  17157. * Gets the number of symbols in `string`.
  17158. *
  17159. * @private
  17160. * @param {string} string The string to inspect.
  17161. * @returns {number} Returns the string size.
  17162. */
  17163. function stringSize(string) {
  17164. if (!(string && reHasComplexSymbol.test(string))) {
  17165. return string.length;
  17166. }
  17167. var result = reComplexSymbol.lastIndex = 0;
  17168. while (reComplexSymbol.test(string)) {
  17169. result++;
  17170. }
  17171. return result;
  17172. }
  17173. /**
  17174. * Converts `string` to an array.
  17175. *
  17176. * @private
  17177. * @param {string} string The string to convert.
  17178. * @returns {Array} Returns the converted array.
  17179. */
  17180. function stringToArray(string) {
  17181. return string.match(reComplexSymbol);
  17182. }
  17183. /**
  17184. * Used by `_.unescape` to convert HTML entities to characters.
  17185. *
  17186. * @private
  17187. * @param {string} chr The matched character to unescape.
  17188. * @returns {string} Returns the unescaped character.
  17189. */
  17190. function unescapeHtmlChar(chr) {
  17191. return htmlUnescapes[chr];
  17192. }
  17193. /*--------------------------------------------------------------------------*/
  17194. /**
  17195. * Create a new pristine `lodash` function using the `context` object.
  17196. *
  17197. * @static
  17198. * @memberOf _
  17199. * @since 1.1.0
  17200. * @category Util
  17201. * @param {Object} [context=root] The context object.
  17202. * @returns {Function} Returns a new `lodash` function.
  17203. * @example
  17204. *
  17205. * _.mixin({ 'foo': _.constant('foo') });
  17206. *
  17207. * var lodash = _.runInContext();
  17208. * lodash.mixin({ 'bar': lodash.constant('bar') });
  17209. *
  17210. * _.isFunction(_.foo);
  17211. * // => true
  17212. * _.isFunction(_.bar);
  17213. * // => false
  17214. *
  17215. * lodash.isFunction(lodash.foo);
  17216. * // => false
  17217. * lodash.isFunction(lodash.bar);
  17218. * // => true
  17219. *
  17220. * // Use `context` to stub `Date#getTime` use in `_.now`.
  17221. * var stubbed = _.runInContext({
  17222. * 'Date': function() {
  17223. * return { 'getTime': stubGetTime };
  17224. * }
  17225. * });
  17226. *
  17227. * // Create a suped-up `defer` in Node.js.
  17228. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  17229. */
  17230. function runInContext(context) {
  17231. context = context ? _.defaults({}, context, _.pick(root, contextProps)) : root;
  17232. /** Built-in constructor references. */
  17233. var Date = context.Date,
  17234. Error = context.Error,
  17235. Math = context.Math,
  17236. RegExp = context.RegExp,
  17237. TypeError = context.TypeError;
  17238. /** Used for built-in method references. */
  17239. var arrayProto = context.Array.prototype,
  17240. objectProto = context.Object.prototype,
  17241. stringProto = context.String.prototype;
  17242. /** Used to detect overreaching core-js shims. */
  17243. var coreJsData = context['__core-js_shared__'];
  17244. /** Used to detect methods masquerading as native. */
  17245. var maskSrcKey = (function() {
  17246. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  17247. return uid ? ('Symbol(src)_1.' + uid) : '';
  17248. }());
  17249. /** Used to resolve the decompiled source of functions. */
  17250. var funcToString = context.Function.prototype.toString;
  17251. /** Used to check objects for own properties. */
  17252. var hasOwnProperty = objectProto.hasOwnProperty;
  17253. /** Used to generate unique IDs. */
  17254. var idCounter = 0;
  17255. /** Used to infer the `Object` constructor. */
  17256. var objectCtorString = funcToString.call(Object);
  17257. /**
  17258. * Used to resolve the
  17259. * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  17260. * of values.
  17261. */
  17262. var objectToString = objectProto.toString;
  17263. /** Used to restore the original `_` reference in `_.noConflict`. */
  17264. var oldDash = root._;
  17265. /** Used to detect if a method is native. */
  17266. var reIsNative = RegExp('^' +
  17267. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  17268. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  17269. );
  17270. /** Built-in value references. */
  17271. var Buffer = moduleExports ? context.Buffer : undefined,
  17272. Reflect = context.Reflect,
  17273. Symbol = context.Symbol,
  17274. Uint8Array = context.Uint8Array,
  17275. enumerate = Reflect ? Reflect.enumerate : undefined,
  17276. getOwnPropertySymbols = Object.getOwnPropertySymbols,
  17277. iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined,
  17278. objectCreate = Object.create,
  17279. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  17280. splice = arrayProto.splice;
  17281. /** Built-in method references that are mockable. */
  17282. var setTimeout = function(func, wait) { return context.setTimeout.call(root, func, wait); };
  17283. /* Built-in method references for those with the same name as other `lodash` methods. */
  17284. var nativeCeil = Math.ceil,
  17285. nativeFloor = Math.floor,
  17286. nativeGetPrototype = Object.getPrototypeOf,
  17287. nativeIsFinite = context.isFinite,
  17288. nativeJoin = arrayProto.join,
  17289. nativeKeys = Object.keys,
  17290. nativeMax = Math.max,
  17291. nativeMin = Math.min,
  17292. nativeParseInt = context.parseInt,
  17293. nativeRandom = Math.random,
  17294. nativeReplace = stringProto.replace,
  17295. nativeReverse = arrayProto.reverse,
  17296. nativeSplit = stringProto.split;
  17297. /* Built-in method references that are verified to be native. */
  17298. var DataView = getNative(context, 'DataView'),
  17299. Map = getNative(context, 'Map'),
  17300. Promise = getNative(context, 'Promise'),
  17301. Set = getNative(context, 'Set'),
  17302. WeakMap = getNative(context, 'WeakMap'),
  17303. nativeCreate = getNative(Object, 'create');
  17304. /** Used to store function metadata. */
  17305. var metaMap = WeakMap && new WeakMap;
  17306. /** Detect if properties shadowing those on `Object.prototype` are non-enumerable. */
  17307. var nonEnumShadows = !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf');
  17308. /** Used to lookup unminified function names. */
  17309. var realNames = {};
  17310. /** Used to detect maps, sets, and weakmaps. */
  17311. var dataViewCtorString = toSource(DataView),
  17312. mapCtorString = toSource(Map),
  17313. promiseCtorString = toSource(Promise),
  17314. setCtorString = toSource(Set),
  17315. weakMapCtorString = toSource(WeakMap);
  17316. /** Used to convert symbols to primitives and strings. */
  17317. var symbolProto = Symbol ? Symbol.prototype : undefined,
  17318. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  17319. symbolToString = symbolProto ? symbolProto.toString : undefined;
  17320. /*------------------------------------------------------------------------*/
  17321. /**
  17322. * Creates a `lodash` object which wraps `value` to enable implicit method
  17323. * chain sequences. Methods that operate on and return arrays, collections,
  17324. * and functions can be chained together. Methods that retrieve a single value
  17325. * or may return a primitive value will automatically end the chain sequence
  17326. * and return the unwrapped value. Otherwise, the value must be unwrapped
  17327. * with `_#value`.
  17328. *
  17329. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  17330. * enabled using `_.chain`.
  17331. *
  17332. * The execution of chained methods is lazy, that is, it's deferred until
  17333. * `_#value` is implicitly or explicitly called.
  17334. *
  17335. * Lazy evaluation allows several methods to support shortcut fusion.
  17336. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  17337. * the creation of intermediate arrays and can greatly reduce the number of
  17338. * iteratee executions. Sections of a chain sequence qualify for shortcut
  17339. * fusion if the section is applied to an array of at least `200` elements
  17340. * and any iteratees accept only one argument. The heuristic for whether a
  17341. * section qualifies for shortcut fusion is subject to change.
  17342. *
  17343. * Chaining is supported in custom builds as long as the `_#value` method is
  17344. * directly or indirectly included in the build.
  17345. *
  17346. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  17347. *
  17348. * The wrapper `Array` methods are:
  17349. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  17350. *
  17351. * The wrapper `String` methods are:
  17352. * `replace` and `split`
  17353. *
  17354. * The wrapper methods that support shortcut fusion are:
  17355. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  17356. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  17357. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  17358. *
  17359. * The chainable wrapper methods are:
  17360. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  17361. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  17362. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  17363. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  17364. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  17365. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  17366. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  17367. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  17368. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  17369. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  17370. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  17371. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  17372. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  17373. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  17374. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  17375. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  17376. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  17377. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  17378. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  17379. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  17380. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  17381. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  17382. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  17383. * `zipObject`, `zipObjectDeep`, and `zipWith`
  17384. *
  17385. * The wrapper methods that are **not** chainable by default are:
  17386. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  17387. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `divide`, `each`,
  17388. * `eachRight`, `endsWith`, `eq`, `escape`, `escapeRegExp`, `every`, `find`,
  17389. * `findIndex`, `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `first`,
  17390. * `floor`, `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`,
  17391. * `forOwnRight`, `get`, `gt`, `gte`, `has`, `hasIn`, `head`, `identity`,
  17392. * `includes`, `indexOf`, `inRange`, `invoke`, `isArguments`, `isArray`,
  17393. * `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`,
  17394. * `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`,
  17395. * `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMap`,
  17396. * `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  17397. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  17398. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  17399. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  17400. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  17401. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  17402. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  17403. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  17404. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  17405. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  17406. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  17407. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  17408. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  17409. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  17410. * `upperFirst`, `value`, and `words`
  17411. *
  17412. * @name _
  17413. * @constructor
  17414. * @category Seq
  17415. * @param {*} value The value to wrap in a `lodash` instance.
  17416. * @returns {Object} Returns the new `lodash` wrapper instance.
  17417. * @example
  17418. *
  17419. * function square(n) {
  17420. * return n * n;
  17421. * }
  17422. *
  17423. * var wrapped = _([1, 2, 3]);
  17424. *
  17425. * // Returns an unwrapped value.
  17426. * wrapped.reduce(_.add);
  17427. * // => 6
  17428. *
  17429. * // Returns a wrapped value.
  17430. * var squares = wrapped.map(square);
  17431. *
  17432. * _.isArray(squares);
  17433. * // => false
  17434. *
  17435. * _.isArray(squares.value());
  17436. * // => true
  17437. */
  17438. function lodash(value) {
  17439. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  17440. if (value instanceof LodashWrapper) {
  17441. return value;
  17442. }
  17443. if (hasOwnProperty.call(value, '__wrapped__')) {
  17444. return wrapperClone(value);
  17445. }
  17446. }
  17447. return new LodashWrapper(value);
  17448. }
  17449. /**
  17450. * The function whose prototype chain sequence wrappers inherit from.
  17451. *
  17452. * @private
  17453. */
  17454. function baseLodash() {
  17455. // No operation performed.
  17456. }
  17457. /**
  17458. * The base constructor for creating `lodash` wrapper objects.
  17459. *
  17460. * @private
  17461. * @param {*} value The value to wrap.
  17462. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  17463. */
  17464. function LodashWrapper(value, chainAll) {
  17465. this.__wrapped__ = value;
  17466. this.__actions__ = [];
  17467. this.__chain__ = !!chainAll;
  17468. this.__index__ = 0;
  17469. this.__values__ = undefined;
  17470. }
  17471. /**
  17472. * By default, the template delimiters used by lodash are like those in
  17473. * embedded Ruby (ERB). Change the following template settings to use
  17474. * alternative delimiters.
  17475. *
  17476. * @static
  17477. * @memberOf _
  17478. * @type {Object}
  17479. */
  17480. lodash.templateSettings = {
  17481. /**
  17482. * Used to detect `data` property values to be HTML-escaped.
  17483. *
  17484. * @memberOf _.templateSettings
  17485. * @type {RegExp}
  17486. */
  17487. 'escape': reEscape,
  17488. /**
  17489. * Used to detect code to be evaluated.
  17490. *
  17491. * @memberOf _.templateSettings
  17492. * @type {RegExp}
  17493. */
  17494. 'evaluate': reEvaluate,
  17495. /**
  17496. * Used to detect `data` property values to inject.
  17497. *
  17498. * @memberOf _.templateSettings
  17499. * @type {RegExp}
  17500. */
  17501. 'interpolate': reInterpolate,
  17502. /**
  17503. * Used to reference the data object in the template text.
  17504. *
  17505. * @memberOf _.templateSettings
  17506. * @type {string}
  17507. */
  17508. 'variable': '',
  17509. /**
  17510. * Used to import variables into the compiled template.
  17511. *
  17512. * @memberOf _.templateSettings
  17513. * @type {Object}
  17514. */
  17515. 'imports': {
  17516. /**
  17517. * A reference to the `lodash` function.
  17518. *
  17519. * @memberOf _.templateSettings.imports
  17520. * @type {Function}
  17521. */
  17522. '_': lodash
  17523. }
  17524. };
  17525. // Ensure wrappers are instances of `baseLodash`.
  17526. lodash.prototype = baseLodash.prototype;
  17527. lodash.prototype.constructor = lodash;
  17528. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  17529. LodashWrapper.prototype.constructor = LodashWrapper;
  17530. /*------------------------------------------------------------------------*/
  17531. /**
  17532. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  17533. *
  17534. * @private
  17535. * @constructor
  17536. * @param {*} value The value to wrap.
  17537. */
  17538. function LazyWrapper(value) {
  17539. this.__wrapped__ = value;
  17540. this.__actions__ = [];
  17541. this.__dir__ = 1;
  17542. this.__filtered__ = false;
  17543. this.__iteratees__ = [];
  17544. this.__takeCount__ = MAX_ARRAY_LENGTH;
  17545. this.__views__ = [];
  17546. }
  17547. /**
  17548. * Creates a clone of the lazy wrapper object.
  17549. *
  17550. * @private
  17551. * @name clone
  17552. * @memberOf LazyWrapper
  17553. * @returns {Object} Returns the cloned `LazyWrapper` object.
  17554. */
  17555. function lazyClone() {
  17556. var result = new LazyWrapper(this.__wrapped__);
  17557. result.__actions__ = copyArray(this.__actions__);
  17558. result.__dir__ = this.__dir__;
  17559. result.__filtered__ = this.__filtered__;
  17560. result.__iteratees__ = copyArray(this.__iteratees__);
  17561. result.__takeCount__ = this.__takeCount__;
  17562. result.__views__ = copyArray(this.__views__);
  17563. return result;
  17564. }
  17565. /**
  17566. * Reverses the direction of lazy iteration.
  17567. *
  17568. * @private
  17569. * @name reverse
  17570. * @memberOf LazyWrapper
  17571. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  17572. */
  17573. function lazyReverse() {
  17574. if (this.__filtered__) {
  17575. var result = new LazyWrapper(this);
  17576. result.__dir__ = -1;
  17577. result.__filtered__ = true;
  17578. } else {
  17579. result = this.clone();
  17580. result.__dir__ *= -1;
  17581. }
  17582. return result;
  17583. }
  17584. /**
  17585. * Extracts the unwrapped value from its lazy wrapper.
  17586. *
  17587. * @private
  17588. * @name value
  17589. * @memberOf LazyWrapper
  17590. * @returns {*} Returns the unwrapped value.
  17591. */
  17592. function lazyValue() {
  17593. var array = this.__wrapped__.value(),
  17594. dir = this.__dir__,
  17595. isArr = isArray(array),
  17596. isRight = dir < 0,
  17597. arrLength = isArr ? array.length : 0,
  17598. view = getView(0, arrLength, this.__views__),
  17599. start = view.start,
  17600. end = view.end,
  17601. length = end - start,
  17602. index = isRight ? end : (start - 1),
  17603. iteratees = this.__iteratees__,
  17604. iterLength = iteratees.length,
  17605. resIndex = 0,
  17606. takeCount = nativeMin(length, this.__takeCount__);
  17607. if (!isArr || arrLength < LARGE_ARRAY_SIZE ||
  17608. (arrLength == length && takeCount == length)) {
  17609. return baseWrapperValue(array, this.__actions__);
  17610. }
  17611. var result = [];
  17612. outer:
  17613. while (length-- && resIndex < takeCount) {
  17614. index += dir;
  17615. var iterIndex = -1,
  17616. value = array[index];
  17617. while (++iterIndex < iterLength) {
  17618. var data = iteratees[iterIndex],
  17619. iteratee = data.iteratee,
  17620. type = data.type,
  17621. computed = iteratee(value);
  17622. if (type == LAZY_MAP_FLAG) {
  17623. value = computed;
  17624. } else if (!computed) {
  17625. if (type == LAZY_FILTER_FLAG) {
  17626. continue outer;
  17627. } else {
  17628. break outer;
  17629. }
  17630. }
  17631. }
  17632. result[resIndex++] = value;
  17633. }
  17634. return result;
  17635. }
  17636. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  17637. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  17638. LazyWrapper.prototype.constructor = LazyWrapper;
  17639. /*------------------------------------------------------------------------*/
  17640. /**
  17641. * Creates a hash object.
  17642. *
  17643. * @private
  17644. * @constructor
  17645. * @param {Array} [entries] The key-value pairs to cache.
  17646. */
  17647. function Hash(entries) {
  17648. var index = -1,
  17649. length = entries ? entries.length : 0;
  17650. this.clear();
  17651. while (++index < length) {
  17652. var entry = entries[index];
  17653. this.set(entry[0], entry[1]);
  17654. }
  17655. }
  17656. /**
  17657. * Removes all key-value entries from the hash.
  17658. *
  17659. * @private
  17660. * @name clear
  17661. * @memberOf Hash
  17662. */
  17663. function hashClear() {
  17664. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  17665. }
  17666. /**
  17667. * Removes `key` and its value from the hash.
  17668. *
  17669. * @private
  17670. * @name delete
  17671. * @memberOf Hash
  17672. * @param {Object} hash The hash to modify.
  17673. * @param {string} key The key of the value to remove.
  17674. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  17675. */
  17676. function hashDelete(key) {
  17677. return this.has(key) && delete this.__data__[key];
  17678. }
  17679. /**
  17680. * Gets the hash value for `key`.
  17681. *
  17682. * @private
  17683. * @name get
  17684. * @memberOf Hash
  17685. * @param {string} key The key of the value to get.
  17686. * @returns {*} Returns the entry value.
  17687. */
  17688. function hashGet(key) {
  17689. var data = this.__data__;
  17690. if (nativeCreate) {
  17691. var result = data[key];
  17692. return result === HASH_UNDEFINED ? undefined : result;
  17693. }
  17694. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  17695. }
  17696. /**
  17697. * Checks if a hash value for `key` exists.
  17698. *
  17699. * @private
  17700. * @name has
  17701. * @memberOf Hash
  17702. * @param {string} key The key of the entry to check.
  17703. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  17704. */
  17705. function hashHas(key) {
  17706. var data = this.__data__;
  17707. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  17708. }
  17709. /**
  17710. * Sets the hash `key` to `value`.
  17711. *
  17712. * @private
  17713. * @name set
  17714. * @memberOf Hash
  17715. * @param {string} key The key of the value to set.
  17716. * @param {*} value The value to set.
  17717. * @returns {Object} Returns the hash instance.
  17718. */
  17719. function hashSet(key, value) {
  17720. var data = this.__data__;
  17721. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  17722. return this;
  17723. }
  17724. // Add methods to `Hash`.
  17725. Hash.prototype.clear = hashClear;
  17726. Hash.prototype['delete'] = hashDelete;
  17727. Hash.prototype.get = hashGet;
  17728. Hash.prototype.has = hashHas;
  17729. Hash.prototype.set = hashSet;
  17730. /*------------------------------------------------------------------------*/
  17731. /**
  17732. * Creates an list cache object.
  17733. *
  17734. * @private
  17735. * @constructor
  17736. * @param {Array} [entries] The key-value pairs to cache.
  17737. */
  17738. function ListCache(entries) {
  17739. var index = -1,
  17740. length = entries ? entries.length : 0;
  17741. this.clear();
  17742. while (++index < length) {
  17743. var entry = entries[index];
  17744. this.set(entry[0], entry[1]);
  17745. }
  17746. }
  17747. /**
  17748. * Removes all key-value entries from the list cache.
  17749. *
  17750. * @private
  17751. * @name clear
  17752. * @memberOf ListCache
  17753. */
  17754. function listCacheClear() {
  17755. this.__data__ = [];
  17756. }
  17757. /**
  17758. * Removes `key` and its value from the list cache.
  17759. *
  17760. * @private
  17761. * @name delete
  17762. * @memberOf ListCache
  17763. * @param {string} key The key of the value to remove.
  17764. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  17765. */
  17766. function listCacheDelete(key) {
  17767. var data = this.__data__,
  17768. index = assocIndexOf(data, key);
  17769. if (index < 0) {
  17770. return false;
  17771. }
  17772. var lastIndex = data.length - 1;
  17773. if (index == lastIndex) {
  17774. data.pop();
  17775. } else {
  17776. splice.call(data, index, 1);
  17777. }
  17778. return true;
  17779. }
  17780. /**
  17781. * Gets the list cache value for `key`.
  17782. *
  17783. * @private
  17784. * @name get
  17785. * @memberOf ListCache
  17786. * @param {string} key The key of the value to get.
  17787. * @returns {*} Returns the entry value.
  17788. */
  17789. function listCacheGet(key) {
  17790. var data = this.__data__,
  17791. index = assocIndexOf(data, key);
  17792. return index < 0 ? undefined : data[index][1];
  17793. }
  17794. /**
  17795. * Checks if a list cache value for `key` exists.
  17796. *
  17797. * @private
  17798. * @name has
  17799. * @memberOf ListCache
  17800. * @param {string} key The key of the entry to check.
  17801. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  17802. */
  17803. function listCacheHas(key) {
  17804. return assocIndexOf(this.__data__, key) > -1;
  17805. }
  17806. /**
  17807. * Sets the list cache `key` to `value`.
  17808. *
  17809. * @private
  17810. * @name set
  17811. * @memberOf ListCache
  17812. * @param {string} key The key of the value to set.
  17813. * @param {*} value The value to set.
  17814. * @returns {Object} Returns the list cache instance.
  17815. */
  17816. function listCacheSet(key, value) {
  17817. var data = this.__data__,
  17818. index = assocIndexOf(data, key);
  17819. if (index < 0) {
  17820. data.push([key, value]);
  17821. } else {
  17822. data[index][1] = value;
  17823. }
  17824. return this;
  17825. }
  17826. // Add methods to `ListCache`.
  17827. ListCache.prototype.clear = listCacheClear;
  17828. ListCache.prototype['delete'] = listCacheDelete;
  17829. ListCache.prototype.get = listCacheGet;
  17830. ListCache.prototype.has = listCacheHas;
  17831. ListCache.prototype.set = listCacheSet;
  17832. /*------------------------------------------------------------------------*/
  17833. /**
  17834. * Creates a map cache object to store key-value pairs.
  17835. *
  17836. * @private
  17837. * @constructor
  17838. * @param {Array} [entries] The key-value pairs to cache.
  17839. */
  17840. function MapCache(entries) {
  17841. var index = -1,
  17842. length = entries ? entries.length : 0;
  17843. this.clear();
  17844. while (++index < length) {
  17845. var entry = entries[index];
  17846. this.set(entry[0], entry[1]);
  17847. }
  17848. }
  17849. /**
  17850. * Removes all key-value entries from the map.
  17851. *
  17852. * @private
  17853. * @name clear
  17854. * @memberOf MapCache
  17855. */
  17856. function mapCacheClear() {
  17857. this.__data__ = {
  17858. 'hash': new Hash,
  17859. 'map': new (Map || ListCache),
  17860. 'string': new Hash
  17861. };
  17862. }
  17863. /**
  17864. * Removes `key` and its value from the map.
  17865. *
  17866. * @private
  17867. * @name delete
  17868. * @memberOf MapCache
  17869. * @param {string} key The key of the value to remove.
  17870. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  17871. */
  17872. function mapCacheDelete(key) {
  17873. return getMapData(this, key)['delete'](key);
  17874. }
  17875. /**
  17876. * Gets the map value for `key`.
  17877. *
  17878. * @private
  17879. * @name get
  17880. * @memberOf MapCache
  17881. * @param {string} key The key of the value to get.
  17882. * @returns {*} Returns the entry value.
  17883. */
  17884. function mapCacheGet(key) {
  17885. return getMapData(this, key).get(key);
  17886. }
  17887. /**
  17888. * Checks if a map value for `key` exists.
  17889. *
  17890. * @private
  17891. * @name has
  17892. * @memberOf MapCache
  17893. * @param {string} key The key of the entry to check.
  17894. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  17895. */
  17896. function mapCacheHas(key) {
  17897. return getMapData(this, key).has(key);
  17898. }
  17899. /**
  17900. * Sets the map `key` to `value`.
  17901. *
  17902. * @private
  17903. * @name set
  17904. * @memberOf MapCache
  17905. * @param {string} key The key of the value to set.
  17906. * @param {*} value The value to set.
  17907. * @returns {Object} Returns the map cache instance.
  17908. */
  17909. function mapCacheSet(key, value) {
  17910. getMapData(this, key).set(key, value);
  17911. return this;
  17912. }
  17913. // Add methods to `MapCache`.
  17914. MapCache.prototype.clear = mapCacheClear;
  17915. MapCache.prototype['delete'] = mapCacheDelete;
  17916. MapCache.prototype.get = mapCacheGet;
  17917. MapCache.prototype.has = mapCacheHas;
  17918. MapCache.prototype.set = mapCacheSet;
  17919. /*------------------------------------------------------------------------*/
  17920. /**
  17921. *
  17922. * Creates an array cache object to store unique values.
  17923. *
  17924. * @private
  17925. * @constructor
  17926. * @param {Array} [values] The values to cache.
  17927. */
  17928. function SetCache(values) {
  17929. var index = -1,
  17930. length = values ? values.length : 0;
  17931. this.__data__ = new MapCache;
  17932. while (++index < length) {
  17933. this.add(values[index]);
  17934. }
  17935. }
  17936. /**
  17937. * Adds `value` to the array cache.
  17938. *
  17939. * @private
  17940. * @name add
  17941. * @memberOf SetCache
  17942. * @alias push
  17943. * @param {*} value The value to cache.
  17944. * @returns {Object} Returns the cache instance.
  17945. */
  17946. function setCacheAdd(value) {
  17947. this.__data__.set(value, HASH_UNDEFINED);
  17948. return this;
  17949. }
  17950. /**
  17951. * Checks if `value` is in the array cache.
  17952. *
  17953. * @private
  17954. * @name has
  17955. * @memberOf SetCache
  17956. * @param {*} value The value to search for.
  17957. * @returns {number} Returns `true` if `value` is found, else `false`.
  17958. */
  17959. function setCacheHas(value) {
  17960. return this.__data__.has(value);
  17961. }
  17962. // Add methods to `SetCache`.
  17963. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  17964. SetCache.prototype.has = setCacheHas;
  17965. /*------------------------------------------------------------------------*/
  17966. /**
  17967. * Creates a stack cache object to store key-value pairs.
  17968. *
  17969. * @private
  17970. * @constructor
  17971. * @param {Array} [entries] The key-value pairs to cache.
  17972. */
  17973. function Stack(entries) {
  17974. this.__data__ = new ListCache(entries);
  17975. }
  17976. /**
  17977. * Removes all key-value entries from the stack.
  17978. *
  17979. * @private
  17980. * @name clear
  17981. * @memberOf Stack
  17982. */
  17983. function stackClear() {
  17984. this.__data__ = new ListCache;
  17985. }
  17986. /**
  17987. * Removes `key` and its value from the stack.
  17988. *
  17989. * @private
  17990. * @name delete
  17991. * @memberOf Stack
  17992. * @param {string} key The key of the value to remove.
  17993. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  17994. */
  17995. function stackDelete(key) {
  17996. return this.__data__['delete'](key);
  17997. }
  17998. /**
  17999. * Gets the stack value for `key`.
  18000. *
  18001. * @private
  18002. * @name get
  18003. * @memberOf Stack
  18004. * @param {string} key The key of the value to get.
  18005. * @returns {*} Returns the entry value.
  18006. */
  18007. function stackGet(key) {
  18008. return this.__data__.get(key);
  18009. }
  18010. /**
  18011. * Checks if a stack value for `key` exists.
  18012. *
  18013. * @private
  18014. * @name has
  18015. * @memberOf Stack
  18016. * @param {string} key The key of the entry to check.
  18017. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  18018. */
  18019. function stackHas(key) {
  18020. return this.__data__.has(key);
  18021. }
  18022. /**
  18023. * Sets the stack `key` to `value`.
  18024. *
  18025. * @private
  18026. * @name set
  18027. * @memberOf Stack
  18028. * @param {string} key The key of the value to set.
  18029. * @param {*} value The value to set.
  18030. * @returns {Object} Returns the stack cache instance.
  18031. */
  18032. function stackSet(key, value) {
  18033. var cache = this.__data__;
  18034. if (cache instanceof ListCache && cache.__data__.length == LARGE_ARRAY_SIZE) {
  18035. cache = this.__data__ = new MapCache(cache.__data__);
  18036. }
  18037. cache.set(key, value);
  18038. return this;
  18039. }
  18040. // Add methods to `Stack`.
  18041. Stack.prototype.clear = stackClear;
  18042. Stack.prototype['delete'] = stackDelete;
  18043. Stack.prototype.get = stackGet;
  18044. Stack.prototype.has = stackHas;
  18045. Stack.prototype.set = stackSet;
  18046. /*------------------------------------------------------------------------*/
  18047. /**
  18048. * Used by `_.defaults` to customize its `_.assignIn` use.
  18049. *
  18050. * @private
  18051. * @param {*} objValue The destination value.
  18052. * @param {*} srcValue The source value.
  18053. * @param {string} key The key of the property to assign.
  18054. * @param {Object} object The parent object of `objValue`.
  18055. * @returns {*} Returns the value to assign.
  18056. */
  18057. function assignInDefaults(objValue, srcValue, key, object) {
  18058. if (objValue === undefined ||
  18059. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  18060. return srcValue;
  18061. }
  18062. return objValue;
  18063. }
  18064. /**
  18065. * This function is like `assignValue` except that it doesn't assign
  18066. * `undefined` values.
  18067. *
  18068. * @private
  18069. * @param {Object} object The object to modify.
  18070. * @param {string} key The key of the property to assign.
  18071. * @param {*} value The value to assign.
  18072. */
  18073. function assignMergeValue(object, key, value) {
  18074. if ((value !== undefined && !eq(object[key], value)) ||
  18075. (typeof key == 'number' && value === undefined && !(key in object))) {
  18076. object[key] = value;
  18077. }
  18078. }
  18079. /**
  18080. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  18081. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  18082. * for equality comparisons.
  18083. *
  18084. * @private
  18085. * @param {Object} object The object to modify.
  18086. * @param {string} key The key of the property to assign.
  18087. * @param {*} value The value to assign.
  18088. */
  18089. function assignValue(object, key, value) {
  18090. var objValue = object[key];
  18091. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  18092. (value === undefined && !(key in object))) {
  18093. object[key] = value;
  18094. }
  18095. }
  18096. /**
  18097. * Gets the index at which the `key` is found in `array` of key-value pairs.
  18098. *
  18099. * @private
  18100. * @param {Array} array The array to search.
  18101. * @param {*} key The key to search for.
  18102. * @returns {number} Returns the index of the matched value, else `-1`.
  18103. */
  18104. function assocIndexOf(array, key) {
  18105. var length = array.length;
  18106. while (length--) {
  18107. if (eq(array[length][0], key)) {
  18108. return length;
  18109. }
  18110. }
  18111. return -1;
  18112. }
  18113. /**
  18114. * Aggregates elements of `collection` on `accumulator` with keys transformed
  18115. * by `iteratee` and values set by `setter`.
  18116. *
  18117. * @private
  18118. * @param {Array|Object} collection The collection to iterate over.
  18119. * @param {Function} setter The function to set `accumulator` values.
  18120. * @param {Function} iteratee The iteratee to transform keys.
  18121. * @param {Object} accumulator The initial aggregated object.
  18122. * @returns {Function} Returns `accumulator`.
  18123. */
  18124. function baseAggregator(collection, setter, iteratee, accumulator) {
  18125. baseEach(collection, function(value, key, collection) {
  18126. setter(accumulator, value, iteratee(value), collection);
  18127. });
  18128. return accumulator;
  18129. }
  18130. /**
  18131. * The base implementation of `_.assign` without support for multiple sources
  18132. * or `customizer` functions.
  18133. *
  18134. * @private
  18135. * @param {Object} object The destination object.
  18136. * @param {Object} source The source object.
  18137. * @returns {Object} Returns `object`.
  18138. */
  18139. function baseAssign(object, source) {
  18140. return object && copyObject(source, keys(source), object);
  18141. }
  18142. /**
  18143. * The base implementation of `_.at` without support for individual paths.
  18144. *
  18145. * @private
  18146. * @param {Object} object The object to iterate over.
  18147. * @param {string[]} paths The property paths of elements to pick.
  18148. * @returns {Array} Returns the picked elements.
  18149. */
  18150. function baseAt(object, paths) {
  18151. var index = -1,
  18152. isNil = object == null,
  18153. length = paths.length,
  18154. result = Array(length);
  18155. while (++index < length) {
  18156. result[index] = isNil ? undefined : get(object, paths[index]);
  18157. }
  18158. return result;
  18159. }
  18160. /**
  18161. * The base implementation of `_.clamp` which doesn't coerce arguments to numbers.
  18162. *
  18163. * @private
  18164. * @param {number} number The number to clamp.
  18165. * @param {number} [lower] The lower bound.
  18166. * @param {number} upper The upper bound.
  18167. * @returns {number} Returns the clamped number.
  18168. */
  18169. function baseClamp(number, lower, upper) {
  18170. if (number === number) {
  18171. if (upper !== undefined) {
  18172. number = number <= upper ? number : upper;
  18173. }
  18174. if (lower !== undefined) {
  18175. number = number >= lower ? number : lower;
  18176. }
  18177. }
  18178. return number;
  18179. }
  18180. /**
  18181. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  18182. * traversed objects.
  18183. *
  18184. * @private
  18185. * @param {*} value The value to clone.
  18186. * @param {boolean} [isDeep] Specify a deep clone.
  18187. * @param {boolean} [isFull] Specify a clone including symbols.
  18188. * @param {Function} [customizer] The function to customize cloning.
  18189. * @param {string} [key] The key of `value`.
  18190. * @param {Object} [object] The parent object of `value`.
  18191. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  18192. * @returns {*} Returns the cloned value.
  18193. */
  18194. function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
  18195. var result;
  18196. if (customizer) {
  18197. result = object ? customizer(value, key, object, stack) : customizer(value);
  18198. }
  18199. if (result !== undefined) {
  18200. return result;
  18201. }
  18202. if (!isObject(value)) {
  18203. return value;
  18204. }
  18205. var isArr = isArray(value);
  18206. if (isArr) {
  18207. result = initCloneArray(value);
  18208. if (!isDeep) {
  18209. return copyArray(value, result);
  18210. }
  18211. } else {
  18212. var tag = getTag(value),
  18213. isFunc = tag == funcTag || tag == genTag;
  18214. if (isBuffer(value)) {
  18215. return cloneBuffer(value, isDeep);
  18216. }
  18217. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  18218. if (isHostObject(value)) {
  18219. return object ? value : {};
  18220. }
  18221. result = initCloneObject(isFunc ? {} : value);
  18222. if (!isDeep) {
  18223. return copySymbols(value, baseAssign(result, value));
  18224. }
  18225. } else {
  18226. if (!cloneableTags[tag]) {
  18227. return object ? value : {};
  18228. }
  18229. result = initCloneByTag(value, tag, baseClone, isDeep);
  18230. }
  18231. }
  18232. // Check for circular references and return its corresponding clone.
  18233. stack || (stack = new Stack);
  18234. var stacked = stack.get(value);
  18235. if (stacked) {
  18236. return stacked;
  18237. }
  18238. stack.set(value, result);
  18239. if (!isArr) {
  18240. var props = isFull ? getAllKeys(value) : keys(value);
  18241. }
  18242. // Recursively populate clone (susceptible to call stack limits).
  18243. arrayEach(props || value, function(subValue, key) {
  18244. if (props) {
  18245. key = subValue;
  18246. subValue = value[key];
  18247. }
  18248. assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
  18249. });
  18250. return result;
  18251. }
  18252. /**
  18253. * The base implementation of `_.conforms` which doesn't clone `source`.
  18254. *
  18255. * @private
  18256. * @param {Object} source The object of property predicates to conform to.
  18257. * @returns {Function} Returns the new spec function.
  18258. */
  18259. function baseConforms(source) {
  18260. var props = keys(source),
  18261. length = props.length;
  18262. return function(object) {
  18263. if (object == null) {
  18264. return !length;
  18265. }
  18266. var index = length;
  18267. while (index--) {
  18268. var key = props[index],
  18269. predicate = source[key],
  18270. value = object[key];
  18271. if ((value === undefined &&
  18272. !(key in Object(object))) || !predicate(value)) {
  18273. return false;
  18274. }
  18275. }
  18276. return true;
  18277. };
  18278. }
  18279. /**
  18280. * The base implementation of `_.create` without support for assigning
  18281. * properties to the created object.
  18282. *
  18283. * @private
  18284. * @param {Object} prototype The object to inherit from.
  18285. * @returns {Object} Returns the new object.
  18286. */
  18287. function baseCreate(proto) {
  18288. return isObject(proto) ? objectCreate(proto) : {};
  18289. }
  18290. /**
  18291. * The base implementation of `_.delay` and `_.defer` which accepts an array
  18292. * of `func` arguments.
  18293. *
  18294. * @private
  18295. * @param {Function} func The function to delay.
  18296. * @param {number} wait The number of milliseconds to delay invocation.
  18297. * @param {Object} args The arguments to provide to `func`.
  18298. * @returns {number} Returns the timer id.
  18299. */
  18300. function baseDelay(func, wait, args) {
  18301. if (typeof func != 'function') {
  18302. throw new TypeError(FUNC_ERROR_TEXT);
  18303. }
  18304. return setTimeout(function() { func.apply(undefined, args); }, wait);
  18305. }
  18306. /**
  18307. * The base implementation of methods like `_.difference` without support
  18308. * for excluding multiple arrays or iteratee shorthands.
  18309. *
  18310. * @private
  18311. * @param {Array} array The array to inspect.
  18312. * @param {Array} values The values to exclude.
  18313. * @param {Function} [iteratee] The iteratee invoked per element.
  18314. * @param {Function} [comparator] The comparator invoked per element.
  18315. * @returns {Array} Returns the new array of filtered values.
  18316. */
  18317. function baseDifference(array, values, iteratee, comparator) {
  18318. var index = -1,
  18319. includes = arrayIncludes,
  18320. isCommon = true,
  18321. length = array.length,
  18322. result = [],
  18323. valuesLength = values.length;
  18324. if (!length) {
  18325. return result;
  18326. }
  18327. if (iteratee) {
  18328. values = arrayMap(values, baseUnary(iteratee));
  18329. }
  18330. if (comparator) {
  18331. includes = arrayIncludesWith;
  18332. isCommon = false;
  18333. }
  18334. else if (values.length >= LARGE_ARRAY_SIZE) {
  18335. includes = cacheHas;
  18336. isCommon = false;
  18337. values = new SetCache(values);
  18338. }
  18339. outer:
  18340. while (++index < length) {
  18341. var value = array[index],
  18342. computed = iteratee ? iteratee(value) : value;
  18343. value = (comparator || value !== 0) ? value : 0;
  18344. if (isCommon && computed === computed) {
  18345. var valuesIndex = valuesLength;
  18346. while (valuesIndex--) {
  18347. if (values[valuesIndex] === computed) {
  18348. continue outer;
  18349. }
  18350. }
  18351. result.push(value);
  18352. }
  18353. else if (!includes(values, computed, comparator)) {
  18354. result.push(value);
  18355. }
  18356. }
  18357. return result;
  18358. }
  18359. /**
  18360. * The base implementation of `_.forEach` without support for iteratee shorthands.
  18361. *
  18362. * @private
  18363. * @param {Array|Object} collection The collection to iterate over.
  18364. * @param {Function} iteratee The function invoked per iteration.
  18365. * @returns {Array|Object} Returns `collection`.
  18366. */
  18367. var baseEach = createBaseEach(baseForOwn);
  18368. /**
  18369. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  18370. *
  18371. * @private
  18372. * @param {Array|Object} collection The collection to iterate over.
  18373. * @param {Function} iteratee The function invoked per iteration.
  18374. * @returns {Array|Object} Returns `collection`.
  18375. */
  18376. var baseEachRight = createBaseEach(baseForOwnRight, true);
  18377. /**
  18378. * The base implementation of `_.every` without support for iteratee shorthands.
  18379. *
  18380. * @private
  18381. * @param {Array|Object} collection The collection to iterate over.
  18382. * @param {Function} predicate The function invoked per iteration.
  18383. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  18384. * else `false`
  18385. */
  18386. function baseEvery(collection, predicate) {
  18387. var result = true;
  18388. baseEach(collection, function(value, index, collection) {
  18389. result = !!predicate(value, index, collection);
  18390. return result;
  18391. });
  18392. return result;
  18393. }
  18394. /**
  18395. * The base implementation of methods like `_.max` and `_.min` which accepts a
  18396. * `comparator` to determine the extremum value.
  18397. *
  18398. * @private
  18399. * @param {Array} array The array to iterate over.
  18400. * @param {Function} iteratee The iteratee invoked per iteration.
  18401. * @param {Function} comparator The comparator used to compare values.
  18402. * @returns {*} Returns the extremum value.
  18403. */
  18404. function baseExtremum(array, iteratee, comparator) {
  18405. var index = -1,
  18406. length = array.length;
  18407. while (++index < length) {
  18408. var value = array[index],
  18409. current = iteratee(value);
  18410. if (current != null && (computed === undefined
  18411. ? (current === current && !isSymbol(current))
  18412. : comparator(current, computed)
  18413. )) {
  18414. var computed = current,
  18415. result = value;
  18416. }
  18417. }
  18418. return result;
  18419. }
  18420. /**
  18421. * The base implementation of `_.fill` without an iteratee call guard.
  18422. *
  18423. * @private
  18424. * @param {Array} array The array to fill.
  18425. * @param {*} value The value to fill `array` with.
  18426. * @param {number} [start=0] The start position.
  18427. * @param {number} [end=array.length] The end position.
  18428. * @returns {Array} Returns `array`.
  18429. */
  18430. function baseFill(array, value, start, end) {
  18431. var length = array.length;
  18432. start = toInteger(start);
  18433. if (start < 0) {
  18434. start = -start > length ? 0 : (length + start);
  18435. }
  18436. end = (end === undefined || end > length) ? length : toInteger(end);
  18437. if (end < 0) {
  18438. end += length;
  18439. }
  18440. end = start > end ? 0 : toLength(end);
  18441. while (start < end) {
  18442. array[start++] = value;
  18443. }
  18444. return array;
  18445. }
  18446. /**
  18447. * The base implementation of `_.filter` without support for iteratee shorthands.
  18448. *
  18449. * @private
  18450. * @param {Array|Object} collection The collection to iterate over.
  18451. * @param {Function} predicate The function invoked per iteration.
  18452. * @returns {Array} Returns the new filtered array.
  18453. */
  18454. function baseFilter(collection, predicate) {
  18455. var result = [];
  18456. baseEach(collection, function(value, index, collection) {
  18457. if (predicate(value, index, collection)) {
  18458. result.push(value);
  18459. }
  18460. });
  18461. return result;
  18462. }
  18463. /**
  18464. * The base implementation of `_.flatten` with support for restricting flattening.
  18465. *
  18466. * @private
  18467. * @param {Array} array The array to flatten.
  18468. * @param {number} depth The maximum recursion depth.
  18469. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  18470. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  18471. * @param {Array} [result=[]] The initial result value.
  18472. * @returns {Array} Returns the new flattened array.
  18473. */
  18474. function baseFlatten(array, depth, predicate, isStrict, result) {
  18475. var index = -1,
  18476. length = array.length;
  18477. predicate || (predicate = isFlattenable);
  18478. result || (result = []);
  18479. while (++index < length) {
  18480. var value = array[index];
  18481. if (depth > 0 && predicate(value)) {
  18482. if (depth > 1) {
  18483. // Recursively flatten arrays (susceptible to call stack limits).
  18484. baseFlatten(value, depth - 1, predicate, isStrict, result);
  18485. } else {
  18486. arrayPush(result, value);
  18487. }
  18488. } else if (!isStrict) {
  18489. result[result.length] = value;
  18490. }
  18491. }
  18492. return result;
  18493. }
  18494. /**
  18495. * The base implementation of `baseForOwn` which iterates over `object`
  18496. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  18497. * Iteratee functions may exit iteration early by explicitly returning `false`.
  18498. *
  18499. * @private
  18500. * @param {Object} object The object to iterate over.
  18501. * @param {Function} iteratee The function invoked per iteration.
  18502. * @param {Function} keysFunc The function to get the keys of `object`.
  18503. * @returns {Object} Returns `object`.
  18504. */
  18505. var baseFor = createBaseFor();
  18506. /**
  18507. * This function is like `baseFor` except that it iterates over properties
  18508. * in the opposite order.
  18509. *
  18510. * @private
  18511. * @param {Object} object The object to iterate over.
  18512. * @param {Function} iteratee The function invoked per iteration.
  18513. * @param {Function} keysFunc The function to get the keys of `object`.
  18514. * @returns {Object} Returns `object`.
  18515. */
  18516. var baseForRight = createBaseFor(true);
  18517. /**
  18518. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  18519. *
  18520. * @private
  18521. * @param {Object} object The object to iterate over.
  18522. * @param {Function} iteratee The function invoked per iteration.
  18523. * @returns {Object} Returns `object`.
  18524. */
  18525. function baseForOwn(object, iteratee) {
  18526. return object && baseFor(object, iteratee, keys);
  18527. }
  18528. /**
  18529. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  18530. *
  18531. * @private
  18532. * @param {Object} object The object to iterate over.
  18533. * @param {Function} iteratee The function invoked per iteration.
  18534. * @returns {Object} Returns `object`.
  18535. */
  18536. function baseForOwnRight(object, iteratee) {
  18537. return object && baseForRight(object, iteratee, keys);
  18538. }
  18539. /**
  18540. * The base implementation of `_.functions` which creates an array of
  18541. * `object` function property names filtered from `props`.
  18542. *
  18543. * @private
  18544. * @param {Object} object The object to inspect.
  18545. * @param {Array} props The property names to filter.
  18546. * @returns {Array} Returns the function names.
  18547. */
  18548. function baseFunctions(object, props) {
  18549. return arrayFilter(props, function(key) {
  18550. return isFunction(object[key]);
  18551. });
  18552. }
  18553. /**
  18554. * The base implementation of `_.get` without support for default values.
  18555. *
  18556. * @private
  18557. * @param {Object} object The object to query.
  18558. * @param {Array|string} path The path of the property to get.
  18559. * @returns {*} Returns the resolved value.
  18560. */
  18561. function baseGet(object, path) {
  18562. path = isKey(path, object) ? [path] : castPath(path);
  18563. var index = 0,
  18564. length = path.length;
  18565. while (object != null && index < length) {
  18566. object = object[toKey(path[index++])];
  18567. }
  18568. return (index && index == length) ? object : undefined;
  18569. }
  18570. /**
  18571. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  18572. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  18573. * symbols of `object`.
  18574. *
  18575. * @private
  18576. * @param {Object} object The object to query.
  18577. * @param {Function} keysFunc The function to get the keys of `object`.
  18578. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  18579. * @returns {Array} Returns the array of property names and symbols.
  18580. */
  18581. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  18582. var result = keysFunc(object);
  18583. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  18584. }
  18585. /**
  18586. * The base implementation of `_.gt` which doesn't coerce arguments to numbers.
  18587. *
  18588. * @private
  18589. * @param {*} value The value to compare.
  18590. * @param {*} other The other value to compare.
  18591. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  18592. * else `false`.
  18593. */
  18594. function baseGt(value, other) {
  18595. return value > other;
  18596. }
  18597. /**
  18598. * The base implementation of `_.has` without support for deep paths.
  18599. *
  18600. * @private
  18601. * @param {Object} [object] The object to query.
  18602. * @param {Array|string} key The key to check.
  18603. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  18604. */
  18605. function baseHas(object, key) {
  18606. // Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
  18607. // that are composed entirely of index properties, return `false` for
  18608. // `hasOwnProperty` checks of them.
  18609. return object != null &&
  18610. (hasOwnProperty.call(object, key) ||
  18611. (typeof object == 'object' && key in object && getPrototype(object) === null));
  18612. }
  18613. /**
  18614. * The base implementation of `_.hasIn` without support for deep paths.
  18615. *
  18616. * @private
  18617. * @param {Object} [object] The object to query.
  18618. * @param {Array|string} key The key to check.
  18619. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  18620. */
  18621. function baseHasIn(object, key) {
  18622. return object != null && key in Object(object);
  18623. }
  18624. /**
  18625. * The base implementation of `_.inRange` which doesn't coerce arguments to numbers.
  18626. *
  18627. * @private
  18628. * @param {number} number The number to check.
  18629. * @param {number} start The start of the range.
  18630. * @param {number} end The end of the range.
  18631. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  18632. */
  18633. function baseInRange(number, start, end) {
  18634. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  18635. }
  18636. /**
  18637. * The base implementation of methods like `_.intersection`, without support
  18638. * for iteratee shorthands, that accepts an array of arrays to inspect.
  18639. *
  18640. * @private
  18641. * @param {Array} arrays The arrays to inspect.
  18642. * @param {Function} [iteratee] The iteratee invoked per element.
  18643. * @param {Function} [comparator] The comparator invoked per element.
  18644. * @returns {Array} Returns the new array of shared values.
  18645. */
  18646. function baseIntersection(arrays, iteratee, comparator) {
  18647. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  18648. length = arrays[0].length,
  18649. othLength = arrays.length,
  18650. othIndex = othLength,
  18651. caches = Array(othLength),
  18652. maxLength = Infinity,
  18653. result = [];
  18654. while (othIndex--) {
  18655. var array = arrays[othIndex];
  18656. if (othIndex && iteratee) {
  18657. array = arrayMap(array, baseUnary(iteratee));
  18658. }
  18659. maxLength = nativeMin(array.length, maxLength);
  18660. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  18661. ? new SetCache(othIndex && array)
  18662. : undefined;
  18663. }
  18664. array = arrays[0];
  18665. var index = -1,
  18666. seen = caches[0];
  18667. outer:
  18668. while (++index < length && result.length < maxLength) {
  18669. var value = array[index],
  18670. computed = iteratee ? iteratee(value) : value;
  18671. value = (comparator || value !== 0) ? value : 0;
  18672. if (!(seen
  18673. ? cacheHas(seen, computed)
  18674. : includes(result, computed, comparator)
  18675. )) {
  18676. othIndex = othLength;
  18677. while (--othIndex) {
  18678. var cache = caches[othIndex];
  18679. if (!(cache
  18680. ? cacheHas(cache, computed)
  18681. : includes(arrays[othIndex], computed, comparator))
  18682. ) {
  18683. continue outer;
  18684. }
  18685. }
  18686. if (seen) {
  18687. seen.push(computed);
  18688. }
  18689. result.push(value);
  18690. }
  18691. }
  18692. return result;
  18693. }
  18694. /**
  18695. * The base implementation of `_.invert` and `_.invertBy` which inverts
  18696. * `object` with values transformed by `iteratee` and set by `setter`.
  18697. *
  18698. * @private
  18699. * @param {Object} object The object to iterate over.
  18700. * @param {Function} setter The function to set `accumulator` values.
  18701. * @param {Function} iteratee The iteratee to transform values.
  18702. * @param {Object} accumulator The initial inverted object.
  18703. * @returns {Function} Returns `accumulator`.
  18704. */
  18705. function baseInverter(object, setter, iteratee, accumulator) {
  18706. baseForOwn(object, function(value, key, object) {
  18707. setter(accumulator, iteratee(value), key, object);
  18708. });
  18709. return accumulator;
  18710. }
  18711. /**
  18712. * The base implementation of `_.invoke` without support for individual
  18713. * method arguments.
  18714. *
  18715. * @private
  18716. * @param {Object} object The object to query.
  18717. * @param {Array|string} path The path of the method to invoke.
  18718. * @param {Array} args The arguments to invoke the method with.
  18719. * @returns {*} Returns the result of the invoked method.
  18720. */
  18721. function baseInvoke(object, path, args) {
  18722. if (!isKey(path, object)) {
  18723. path = castPath(path);
  18724. object = parent(object, path);
  18725. path = last(path);
  18726. }
  18727. var func = object == null ? object : object[toKey(path)];
  18728. return func == null ? undefined : apply(func, object, args);
  18729. }
  18730. /**
  18731. * The base implementation of `_.isEqual` which supports partial comparisons
  18732. * and tracks traversed objects.
  18733. *
  18734. * @private
  18735. * @param {*} value The value to compare.
  18736. * @param {*} other The other value to compare.
  18737. * @param {Function} [customizer] The function to customize comparisons.
  18738. * @param {boolean} [bitmask] The bitmask of comparison flags.
  18739. * The bitmask may be composed of the following flags:
  18740. * 1 - Unordered comparison
  18741. * 2 - Partial comparison
  18742. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  18743. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  18744. */
  18745. function baseIsEqual(value, other, customizer, bitmask, stack) {
  18746. if (value === other) {
  18747. return true;
  18748. }
  18749. if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
  18750. return value !== value && other !== other;
  18751. }
  18752. return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
  18753. }
  18754. /**
  18755. * A specialized version of `baseIsEqual` for arrays and objects which performs
  18756. * deep comparisons and tracks traversed objects enabling objects with circular
  18757. * references to be compared.
  18758. *
  18759. * @private
  18760. * @param {Object} object The object to compare.
  18761. * @param {Object} other The other object to compare.
  18762. * @param {Function} equalFunc The function to determine equivalents of values.
  18763. * @param {Function} [customizer] The function to customize comparisons.
  18764. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
  18765. * for more details.
  18766. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  18767. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  18768. */
  18769. function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
  18770. var objIsArr = isArray(object),
  18771. othIsArr = isArray(other),
  18772. objTag = arrayTag,
  18773. othTag = arrayTag;
  18774. if (!objIsArr) {
  18775. objTag = getTag(object);
  18776. objTag = objTag == argsTag ? objectTag : objTag;
  18777. }
  18778. if (!othIsArr) {
  18779. othTag = getTag(other);
  18780. othTag = othTag == argsTag ? objectTag : othTag;
  18781. }
  18782. var objIsObj = objTag == objectTag && !isHostObject(object),
  18783. othIsObj = othTag == objectTag && !isHostObject(other),
  18784. isSameTag = objTag == othTag;
  18785. if (isSameTag && !objIsObj) {
  18786. stack || (stack = new Stack);
  18787. return (objIsArr || isTypedArray(object))
  18788. ? equalArrays(object, other, equalFunc, customizer, bitmask, stack)
  18789. : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
  18790. }
  18791. if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
  18792. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  18793. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  18794. if (objIsWrapped || othIsWrapped) {
  18795. var objUnwrapped = objIsWrapped ? object.value() : object,
  18796. othUnwrapped = othIsWrapped ? other.value() : other;
  18797. stack || (stack = new Stack);
  18798. return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
  18799. }
  18800. }
  18801. if (!isSameTag) {
  18802. return false;
  18803. }
  18804. stack || (stack = new Stack);
  18805. return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
  18806. }
  18807. /**
  18808. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  18809. *
  18810. * @private
  18811. * @param {Object} object The object to inspect.
  18812. * @param {Object} source The object of property values to match.
  18813. * @param {Array} matchData The property names, values, and compare flags to match.
  18814. * @param {Function} [customizer] The function to customize comparisons.
  18815. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  18816. */
  18817. function baseIsMatch(object, source, matchData, customizer) {
  18818. var index = matchData.length,
  18819. length = index,
  18820. noCustomizer = !customizer;
  18821. if (object == null) {
  18822. return !length;
  18823. }
  18824. object = Object(object);
  18825. while (index--) {
  18826. var data = matchData[index];
  18827. if ((noCustomizer && data[2])
  18828. ? data[1] !== object[data[0]]
  18829. : !(data[0] in object)
  18830. ) {
  18831. return false;
  18832. }
  18833. }
  18834. while (++index < length) {
  18835. data = matchData[index];
  18836. var key = data[0],
  18837. objValue = object[key],
  18838. srcValue = data[1];
  18839. if (noCustomizer && data[2]) {
  18840. if (objValue === undefined && !(key in object)) {
  18841. return false;
  18842. }
  18843. } else {
  18844. var stack = new Stack;
  18845. if (customizer) {
  18846. var result = customizer(objValue, srcValue, key, object, source, stack);
  18847. }
  18848. if (!(result === undefined
  18849. ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack)
  18850. : result
  18851. )) {
  18852. return false;
  18853. }
  18854. }
  18855. }
  18856. return true;
  18857. }
  18858. /**
  18859. * The base implementation of `_.isNative` without bad shim checks.
  18860. *
  18861. * @private
  18862. * @param {*} value The value to check.
  18863. * @returns {boolean} Returns `true` if `value` is a native function,
  18864. * else `false`.
  18865. */
  18866. function baseIsNative(value) {
  18867. if (!isObject(value) || isMasked(value)) {
  18868. return false;
  18869. }
  18870. var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
  18871. return pattern.test(toSource(value));
  18872. }
  18873. /**
  18874. * The base implementation of `_.iteratee`.
  18875. *
  18876. * @private
  18877. * @param {*} [value=_.identity] The value to convert to an iteratee.
  18878. * @returns {Function} Returns the iteratee.
  18879. */
  18880. function baseIteratee(value) {
  18881. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  18882. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  18883. if (typeof value == 'function') {
  18884. return value;
  18885. }
  18886. if (value == null) {
  18887. return identity;
  18888. }
  18889. if (typeof value == 'object') {
  18890. return isArray(value)
  18891. ? baseMatchesProperty(value[0], value[1])
  18892. : baseMatches(value);
  18893. }
  18894. return property(value);
  18895. }
  18896. /**
  18897. * The base implementation of `_.keys` which doesn't skip the constructor
  18898. * property of prototypes or treat sparse arrays as dense.
  18899. *
  18900. * @private
  18901. * @param {Object} object The object to query.
  18902. * @returns {Array} Returns the array of property names.
  18903. */
  18904. function baseKeys(object) {
  18905. return nativeKeys(Object(object));
  18906. }
  18907. /**
  18908. * The base implementation of `_.keysIn` which doesn't skip the constructor
  18909. * property of prototypes or treat sparse arrays as dense.
  18910. *
  18911. * @private
  18912. * @param {Object} object The object to query.
  18913. * @returns {Array} Returns the array of property names.
  18914. */
  18915. function baseKeysIn(object) {
  18916. object = object == null ? object : Object(object);
  18917. var result = [];
  18918. for (var key in object) {
  18919. result.push(key);
  18920. }
  18921. return result;
  18922. }
  18923. // Fallback for IE < 9 with es6-shim.
  18924. if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
  18925. baseKeysIn = function(object) {
  18926. return iteratorToArray(enumerate(object));
  18927. };
  18928. }
  18929. /**
  18930. * The base implementation of `_.lt` which doesn't coerce arguments to numbers.
  18931. *
  18932. * @private
  18933. * @param {*} value The value to compare.
  18934. * @param {*} other The other value to compare.
  18935. * @returns {boolean} Returns `true` if `value` is less than `other`,
  18936. * else `false`.
  18937. */
  18938. function baseLt(value, other) {
  18939. return value < other;
  18940. }
  18941. /**
  18942. * The base implementation of `_.map` without support for iteratee shorthands.
  18943. *
  18944. * @private
  18945. * @param {Array|Object} collection The collection to iterate over.
  18946. * @param {Function} iteratee The function invoked per iteration.
  18947. * @returns {Array} Returns the new mapped array.
  18948. */
  18949. function baseMap(collection, iteratee) {
  18950. var index = -1,
  18951. result = isArrayLike(collection) ? Array(collection.length) : [];
  18952. baseEach(collection, function(value, key, collection) {
  18953. result[++index] = iteratee(value, key, collection);
  18954. });
  18955. return result;
  18956. }
  18957. /**
  18958. * The base implementation of `_.matches` which doesn't clone `source`.
  18959. *
  18960. * @private
  18961. * @param {Object} source The object of property values to match.
  18962. * @returns {Function} Returns the new spec function.
  18963. */
  18964. function baseMatches(source) {
  18965. var matchData = getMatchData(source);
  18966. if (matchData.length == 1 && matchData[0][2]) {
  18967. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  18968. }
  18969. return function(object) {
  18970. return object === source || baseIsMatch(object, source, matchData);
  18971. };
  18972. }
  18973. /**
  18974. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  18975. *
  18976. * @private
  18977. * @param {string} path The path of the property to get.
  18978. * @param {*} srcValue The value to match.
  18979. * @returns {Function} Returns the new spec function.
  18980. */
  18981. function baseMatchesProperty(path, srcValue) {
  18982. if (isKey(path) && isStrictComparable(srcValue)) {
  18983. return matchesStrictComparable(toKey(path), srcValue);
  18984. }
  18985. return function(object) {
  18986. var objValue = get(object, path);
  18987. return (objValue === undefined && objValue === srcValue)
  18988. ? hasIn(object, path)
  18989. : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
  18990. };
  18991. }
  18992. /**
  18993. * The base implementation of `_.merge` without support for multiple sources.
  18994. *
  18995. * @private
  18996. * @param {Object} object The destination object.
  18997. * @param {Object} source The source object.
  18998. * @param {number} srcIndex The index of `source`.
  18999. * @param {Function} [customizer] The function to customize merged values.
  19000. * @param {Object} [stack] Tracks traversed source values and their merged
  19001. * counterparts.
  19002. */
  19003. function baseMerge(object, source, srcIndex, customizer, stack) {
  19004. if (object === source) {
  19005. return;
  19006. }
  19007. if (!(isArray(source) || isTypedArray(source))) {
  19008. var props = keysIn(source);
  19009. }
  19010. arrayEach(props || source, function(srcValue, key) {
  19011. if (props) {
  19012. key = srcValue;
  19013. srcValue = source[key];
  19014. }
  19015. if (isObject(srcValue)) {
  19016. stack || (stack = new Stack);
  19017. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  19018. }
  19019. else {
  19020. var newValue = customizer
  19021. ? customizer(object[key], srcValue, (key + ''), object, source, stack)
  19022. : undefined;
  19023. if (newValue === undefined) {
  19024. newValue = srcValue;
  19025. }
  19026. assignMergeValue(object, key, newValue);
  19027. }
  19028. });
  19029. }
  19030. /**
  19031. * A specialized version of `baseMerge` for arrays and objects which performs
  19032. * deep merges and tracks traversed objects enabling objects with circular
  19033. * references to be merged.
  19034. *
  19035. * @private
  19036. * @param {Object} object The destination object.
  19037. * @param {Object} source The source object.
  19038. * @param {string} key The key of the value to merge.
  19039. * @param {number} srcIndex The index of `source`.
  19040. * @param {Function} mergeFunc The function to merge values.
  19041. * @param {Function} [customizer] The function to customize assigned values.
  19042. * @param {Object} [stack] Tracks traversed source values and their merged
  19043. * counterparts.
  19044. */
  19045. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  19046. var objValue = object[key],
  19047. srcValue = source[key],
  19048. stacked = stack.get(srcValue);
  19049. if (stacked) {
  19050. assignMergeValue(object, key, stacked);
  19051. return;
  19052. }
  19053. var newValue = customizer
  19054. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  19055. : undefined;
  19056. var isCommon = newValue === undefined;
  19057. if (isCommon) {
  19058. newValue = srcValue;
  19059. if (isArray(srcValue) || isTypedArray(srcValue)) {
  19060. if (isArray(objValue)) {
  19061. newValue = objValue;
  19062. }
  19063. else if (isArrayLikeObject(objValue)) {
  19064. newValue = copyArray(objValue);
  19065. }
  19066. else {
  19067. isCommon = false;
  19068. newValue = baseClone(srcValue, true);
  19069. }
  19070. }
  19071. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  19072. if (isArguments(objValue)) {
  19073. newValue = toPlainObject(objValue);
  19074. }
  19075. else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
  19076. isCommon = false;
  19077. newValue = baseClone(srcValue, true);
  19078. }
  19079. else {
  19080. newValue = objValue;
  19081. }
  19082. }
  19083. else {
  19084. isCommon = false;
  19085. }
  19086. }
  19087. stack.set(srcValue, newValue);
  19088. if (isCommon) {
  19089. // Recursively merge objects and arrays (susceptible to call stack limits).
  19090. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  19091. }
  19092. stack['delete'](srcValue);
  19093. assignMergeValue(object, key, newValue);
  19094. }
  19095. /**
  19096. * The base implementation of `_.nth` which doesn't coerce `n` to an integer.
  19097. *
  19098. * @private
  19099. * @param {Array} array The array to query.
  19100. * @param {number} n The index of the element to return.
  19101. * @returns {*} Returns the nth element of `array`.
  19102. */
  19103. function baseNth(array, n) {
  19104. var length = array.length;
  19105. if (!length) {
  19106. return;
  19107. }
  19108. n += n < 0 ? length : 0;
  19109. return isIndex(n, length) ? array[n] : undefined;
  19110. }
  19111. /**
  19112. * The base implementation of `_.orderBy` without param guards.
  19113. *
  19114. * @private
  19115. * @param {Array|Object} collection The collection to iterate over.
  19116. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  19117. * @param {string[]} orders The sort orders of `iteratees`.
  19118. * @returns {Array} Returns the new sorted array.
  19119. */
  19120. function baseOrderBy(collection, iteratees, orders) {
  19121. var index = -1;
  19122. iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
  19123. var result = baseMap(collection, function(value, key, collection) {
  19124. var criteria = arrayMap(iteratees, function(iteratee) {
  19125. return iteratee(value);
  19126. });
  19127. return { 'criteria': criteria, 'index': ++index, 'value': value };
  19128. });
  19129. return baseSortBy(result, function(object, other) {
  19130. return compareMultiple(object, other, orders);
  19131. });
  19132. }
  19133. /**
  19134. * The base implementation of `_.pick` without support for individual
  19135. * property identifiers.
  19136. *
  19137. * @private
  19138. * @param {Object} object The source object.
  19139. * @param {string[]} props The property identifiers to pick.
  19140. * @returns {Object} Returns the new object.
  19141. */
  19142. function basePick(object, props) {
  19143. object = Object(object);
  19144. return arrayReduce(props, function(result, key) {
  19145. if (key in object) {
  19146. result[key] = object[key];
  19147. }
  19148. return result;
  19149. }, {});
  19150. }
  19151. /**
  19152. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  19153. *
  19154. * @private
  19155. * @param {Object} object The source object.
  19156. * @param {Function} predicate The function invoked per property.
  19157. * @returns {Object} Returns the new object.
  19158. */
  19159. function basePickBy(object, predicate) {
  19160. var index = -1,
  19161. props = getAllKeysIn(object),
  19162. length = props.length,
  19163. result = {};
  19164. while (++index < length) {
  19165. var key = props[index],
  19166. value = object[key];
  19167. if (predicate(value, key)) {
  19168. result[key] = value;
  19169. }
  19170. }
  19171. return result;
  19172. }
  19173. /**
  19174. * The base implementation of `_.property` without support for deep paths.
  19175. *
  19176. * @private
  19177. * @param {string} key The key of the property to get.
  19178. * @returns {Function} Returns the new accessor function.
  19179. */
  19180. function baseProperty(key) {
  19181. return function(object) {
  19182. return object == null ? undefined : object[key];
  19183. };
  19184. }
  19185. /**
  19186. * A specialized version of `baseProperty` which supports deep paths.
  19187. *
  19188. * @private
  19189. * @param {Array|string} path The path of the property to get.
  19190. * @returns {Function} Returns the new accessor function.
  19191. */
  19192. function basePropertyDeep(path) {
  19193. return function(object) {
  19194. return baseGet(object, path);
  19195. };
  19196. }
  19197. /**
  19198. * The base implementation of `_.pullAllBy` without support for iteratee
  19199. * shorthands.
  19200. *
  19201. * @private
  19202. * @param {Array} array The array to modify.
  19203. * @param {Array} values The values to remove.
  19204. * @param {Function} [iteratee] The iteratee invoked per element.
  19205. * @param {Function} [comparator] The comparator invoked per element.
  19206. * @returns {Array} Returns `array`.
  19207. */
  19208. function basePullAll(array, values, iteratee, comparator) {
  19209. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  19210. index = -1,
  19211. length = values.length,
  19212. seen = array;
  19213. if (array === values) {
  19214. values = copyArray(values);
  19215. }
  19216. if (iteratee) {
  19217. seen = arrayMap(array, baseUnary(iteratee));
  19218. }
  19219. while (++index < length) {
  19220. var fromIndex = 0,
  19221. value = values[index],
  19222. computed = iteratee ? iteratee(value) : value;
  19223. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  19224. if (seen !== array) {
  19225. splice.call(seen, fromIndex, 1);
  19226. }
  19227. splice.call(array, fromIndex, 1);
  19228. }
  19229. }
  19230. return array;
  19231. }
  19232. /**
  19233. * The base implementation of `_.pullAt` without support for individual
  19234. * indexes or capturing the removed elements.
  19235. *
  19236. * @private
  19237. * @param {Array} array The array to modify.
  19238. * @param {number[]} indexes The indexes of elements to remove.
  19239. * @returns {Array} Returns `array`.
  19240. */
  19241. function basePullAt(array, indexes) {
  19242. var length = array ? indexes.length : 0,
  19243. lastIndex = length - 1;
  19244. while (length--) {
  19245. var index = indexes[length];
  19246. if (length == lastIndex || index !== previous) {
  19247. var previous = index;
  19248. if (isIndex(index)) {
  19249. splice.call(array, index, 1);
  19250. }
  19251. else if (!isKey(index, array)) {
  19252. var path = castPath(index),
  19253. object = parent(array, path);
  19254. if (object != null) {
  19255. delete object[toKey(last(path))];
  19256. }
  19257. }
  19258. else {
  19259. delete array[toKey(index)];
  19260. }
  19261. }
  19262. }
  19263. return array;
  19264. }
  19265. /**
  19266. * The base implementation of `_.random` without support for returning
  19267. * floating-point numbers.
  19268. *
  19269. * @private
  19270. * @param {number} lower The lower bound.
  19271. * @param {number} upper The upper bound.
  19272. * @returns {number} Returns the random number.
  19273. */
  19274. function baseRandom(lower, upper) {
  19275. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  19276. }
  19277. /**
  19278. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  19279. * coerce arguments to numbers.
  19280. *
  19281. * @private
  19282. * @param {number} start The start of the range.
  19283. * @param {number} end The end of the range.
  19284. * @param {number} step The value to increment or decrement by.
  19285. * @param {boolean} [fromRight] Specify iterating from right to left.
  19286. * @returns {Array} Returns the range of numbers.
  19287. */
  19288. function baseRange(start, end, step, fromRight) {
  19289. var index = -1,
  19290. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  19291. result = Array(length);
  19292. while (length--) {
  19293. result[fromRight ? length : ++index] = start;
  19294. start += step;
  19295. }
  19296. return result;
  19297. }
  19298. /**
  19299. * The base implementation of `_.repeat` which doesn't coerce arguments.
  19300. *
  19301. * @private
  19302. * @param {string} string The string to repeat.
  19303. * @param {number} n The number of times to repeat the string.
  19304. * @returns {string} Returns the repeated string.
  19305. */
  19306. function baseRepeat(string, n) {
  19307. var result = '';
  19308. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  19309. return result;
  19310. }
  19311. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  19312. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  19313. do {
  19314. if (n % 2) {
  19315. result += string;
  19316. }
  19317. n = nativeFloor(n / 2);
  19318. if (n) {
  19319. string += string;
  19320. }
  19321. } while (n);
  19322. return result;
  19323. }
  19324. /**
  19325. * The base implementation of `_.set`.
  19326. *
  19327. * @private
  19328. * @param {Object} object The object to query.
  19329. * @param {Array|string} path The path of the property to set.
  19330. * @param {*} value The value to set.
  19331. * @param {Function} [customizer] The function to customize path creation.
  19332. * @returns {Object} Returns `object`.
  19333. */
  19334. function baseSet(object, path, value, customizer) {
  19335. path = isKey(path, object) ? [path] : castPath(path);
  19336. var index = -1,
  19337. length = path.length,
  19338. lastIndex = length - 1,
  19339. nested = object;
  19340. while (nested != null && ++index < length) {
  19341. var key = toKey(path[index]);
  19342. if (isObject(nested)) {
  19343. var newValue = value;
  19344. if (index != lastIndex) {
  19345. var objValue = nested[key];
  19346. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  19347. if (newValue === undefined) {
  19348. newValue = objValue == null
  19349. ? (isIndex(path[index + 1]) ? [] : {})
  19350. : objValue;
  19351. }
  19352. }
  19353. assignValue(nested, key, newValue);
  19354. }
  19355. nested = nested[key];
  19356. }
  19357. return object;
  19358. }
  19359. /**
  19360. * The base implementation of `setData` without support for hot loop detection.
  19361. *
  19362. * @private
  19363. * @param {Function} func The function to associate metadata with.
  19364. * @param {*} data The metadata.
  19365. * @returns {Function} Returns `func`.
  19366. */
  19367. var baseSetData = !metaMap ? identity : function(func, data) {
  19368. metaMap.set(func, data);
  19369. return func;
  19370. };
  19371. /**
  19372. * The base implementation of `_.slice` without an iteratee call guard.
  19373. *
  19374. * @private
  19375. * @param {Array} array The array to slice.
  19376. * @param {number} [start=0] The start position.
  19377. * @param {number} [end=array.length] The end position.
  19378. * @returns {Array} Returns the slice of `array`.
  19379. */
  19380. function baseSlice(array, start, end) {
  19381. var index = -1,
  19382. length = array.length;
  19383. if (start < 0) {
  19384. start = -start > length ? 0 : (length + start);
  19385. }
  19386. end = end > length ? length : end;
  19387. if (end < 0) {
  19388. end += length;
  19389. }
  19390. length = start > end ? 0 : ((end - start) >>> 0);
  19391. start >>>= 0;
  19392. var result = Array(length);
  19393. while (++index < length) {
  19394. result[index] = array[index + start];
  19395. }
  19396. return result;
  19397. }
  19398. /**
  19399. * The base implementation of `_.some` without support for iteratee shorthands.
  19400. *
  19401. * @private
  19402. * @param {Array|Object} collection The collection to iterate over.
  19403. * @param {Function} predicate The function invoked per iteration.
  19404. * @returns {boolean} Returns `true` if any element passes the predicate check,
  19405. * else `false`.
  19406. */
  19407. function baseSome(collection, predicate) {
  19408. var result;
  19409. baseEach(collection, function(value, index, collection) {
  19410. result = predicate(value, index, collection);
  19411. return !result;
  19412. });
  19413. return !!result;
  19414. }
  19415. /**
  19416. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  19417. * performs a binary search of `array` to determine the index at which `value`
  19418. * should be inserted into `array` in order to maintain its sort order.
  19419. *
  19420. * @private
  19421. * @param {Array} array The sorted array to inspect.
  19422. * @param {*} value The value to evaluate.
  19423. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  19424. * @returns {number} Returns the index at which `value` should be inserted
  19425. * into `array`.
  19426. */
  19427. function baseSortedIndex(array, value, retHighest) {
  19428. var low = 0,
  19429. high = array ? array.length : low;
  19430. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  19431. while (low < high) {
  19432. var mid = (low + high) >>> 1,
  19433. computed = array[mid];
  19434. if (computed !== null && !isSymbol(computed) &&
  19435. (retHighest ? (computed <= value) : (computed < value))) {
  19436. low = mid + 1;
  19437. } else {
  19438. high = mid;
  19439. }
  19440. }
  19441. return high;
  19442. }
  19443. return baseSortedIndexBy(array, value, identity, retHighest);
  19444. }
  19445. /**
  19446. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  19447. * which invokes `iteratee` for `value` and each element of `array` to compute
  19448. * their sort ranking. The iteratee is invoked with one argument; (value).
  19449. *
  19450. * @private
  19451. * @param {Array} array The sorted array to inspect.
  19452. * @param {*} value The value to evaluate.
  19453. * @param {Function} iteratee The iteratee invoked per element.
  19454. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  19455. * @returns {number} Returns the index at which `value` should be inserted
  19456. * into `array`.
  19457. */
  19458. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  19459. value = iteratee(value);
  19460. var low = 0,
  19461. high = array ? array.length : 0,
  19462. valIsNaN = value !== value,
  19463. valIsNull = value === null,
  19464. valIsSymbol = isSymbol(value),
  19465. valIsUndefined = value === undefined;
  19466. while (low < high) {
  19467. var mid = nativeFloor((low + high) / 2),
  19468. computed = iteratee(array[mid]),
  19469. othIsDefined = computed !== undefined,
  19470. othIsNull = computed === null,
  19471. othIsReflexive = computed === computed,
  19472. othIsSymbol = isSymbol(computed);
  19473. if (valIsNaN) {
  19474. var setLow = retHighest || othIsReflexive;
  19475. } else if (valIsUndefined) {
  19476. setLow = othIsReflexive && (retHighest || othIsDefined);
  19477. } else if (valIsNull) {
  19478. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  19479. } else if (valIsSymbol) {
  19480. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  19481. } else if (othIsNull || othIsSymbol) {
  19482. setLow = false;
  19483. } else {
  19484. setLow = retHighest ? (computed <= value) : (computed < value);
  19485. }
  19486. if (setLow) {
  19487. low = mid + 1;
  19488. } else {
  19489. high = mid;
  19490. }
  19491. }
  19492. return nativeMin(high, MAX_ARRAY_INDEX);
  19493. }
  19494. /**
  19495. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  19496. * support for iteratee shorthands.
  19497. *
  19498. * @private
  19499. * @param {Array} array The array to inspect.
  19500. * @param {Function} [iteratee] The iteratee invoked per element.
  19501. * @returns {Array} Returns the new duplicate free array.
  19502. */
  19503. function baseSortedUniq(array, iteratee) {
  19504. var index = -1,
  19505. length = array.length,
  19506. resIndex = 0,
  19507. result = [];
  19508. while (++index < length) {
  19509. var value = array[index],
  19510. computed = iteratee ? iteratee(value) : value;
  19511. if (!index || !eq(computed, seen)) {
  19512. var seen = computed;
  19513. result[resIndex++] = value === 0 ? 0 : value;
  19514. }
  19515. }
  19516. return result;
  19517. }
  19518. /**
  19519. * The base implementation of `_.toNumber` which doesn't ensure correct
  19520. * conversions of binary, hexadecimal, or octal string values.
  19521. *
  19522. * @private
  19523. * @param {*} value The value to process.
  19524. * @returns {number} Returns the number.
  19525. */
  19526. function baseToNumber(value) {
  19527. if (typeof value == 'number') {
  19528. return value;
  19529. }
  19530. if (isSymbol(value)) {
  19531. return NAN;
  19532. }
  19533. return +value;
  19534. }
  19535. /**
  19536. * The base implementation of `_.toString` which doesn't convert nullish
  19537. * values to empty strings.
  19538. *
  19539. * @private
  19540. * @param {*} value The value to process.
  19541. * @returns {string} Returns the string.
  19542. */
  19543. function baseToString(value) {
  19544. // Exit early for strings to avoid a performance hit in some environments.
  19545. if (typeof value == 'string') {
  19546. return value;
  19547. }
  19548. if (isSymbol(value)) {
  19549. return symbolToString ? symbolToString.call(value) : '';
  19550. }
  19551. var result = (value + '');
  19552. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  19553. }
  19554. /**
  19555. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  19556. *
  19557. * @private
  19558. * @param {Array} array The array to inspect.
  19559. * @param {Function} [iteratee] The iteratee invoked per element.
  19560. * @param {Function} [comparator] The comparator invoked per element.
  19561. * @returns {Array} Returns the new duplicate free array.
  19562. */
  19563. function baseUniq(array, iteratee, comparator) {
  19564. var index = -1,
  19565. includes = arrayIncludes,
  19566. length = array.length,
  19567. isCommon = true,
  19568. result = [],
  19569. seen = result;
  19570. if (comparator) {
  19571. isCommon = false;
  19572. includes = arrayIncludesWith;
  19573. }
  19574. else if (length >= LARGE_ARRAY_SIZE) {
  19575. var set = iteratee ? null : createSet(array);
  19576. if (set) {
  19577. return setToArray(set);
  19578. }
  19579. isCommon = false;
  19580. includes = cacheHas;
  19581. seen = new SetCache;
  19582. }
  19583. else {
  19584. seen = iteratee ? [] : result;
  19585. }
  19586. outer:
  19587. while (++index < length) {
  19588. var value = array[index],
  19589. computed = iteratee ? iteratee(value) : value;
  19590. value = (comparator || value !== 0) ? value : 0;
  19591. if (isCommon && computed === computed) {
  19592. var seenIndex = seen.length;
  19593. while (seenIndex--) {
  19594. if (seen[seenIndex] === computed) {
  19595. continue outer;
  19596. }
  19597. }
  19598. if (iteratee) {
  19599. seen.push(computed);
  19600. }
  19601. result.push(value);
  19602. }
  19603. else if (!includes(seen, computed, comparator)) {
  19604. if (seen !== result) {
  19605. seen.push(computed);
  19606. }
  19607. result.push(value);
  19608. }
  19609. }
  19610. return result;
  19611. }
  19612. /**
  19613. * The base implementation of `_.unset`.
  19614. *
  19615. * @private
  19616. * @param {Object} object The object to modify.
  19617. * @param {Array|string} path The path of the property to unset.
  19618. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  19619. */
  19620. function baseUnset(object, path) {
  19621. path = isKey(path, object) ? [path] : castPath(path);
  19622. object = parent(object, path);
  19623. var key = toKey(last(path));
  19624. return !(object != null && baseHas(object, key)) || delete object[key];
  19625. }
  19626. /**
  19627. * The base implementation of `_.update`.
  19628. *
  19629. * @private
  19630. * @param {Object} object The object to query.
  19631. * @param {Array|string} path The path of the property to update.
  19632. * @param {Function} updater The function to produce the updated value.
  19633. * @param {Function} [customizer] The function to customize path creation.
  19634. * @returns {Object} Returns `object`.
  19635. */
  19636. function baseUpdate(object, path, updater, customizer) {
  19637. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  19638. }
  19639. /**
  19640. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  19641. * without support for iteratee shorthands.
  19642. *
  19643. * @private
  19644. * @param {Array} array The array to query.
  19645. * @param {Function} predicate The function invoked per iteration.
  19646. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  19647. * @param {boolean} [fromRight] Specify iterating from right to left.
  19648. * @returns {Array} Returns the slice of `array`.
  19649. */
  19650. function baseWhile(array, predicate, isDrop, fromRight) {
  19651. var length = array.length,
  19652. index = fromRight ? length : -1;
  19653. while ((fromRight ? index-- : ++index < length) &&
  19654. predicate(array[index], index, array)) {}
  19655. return isDrop
  19656. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  19657. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  19658. }
  19659. /**
  19660. * The base implementation of `wrapperValue` which returns the result of
  19661. * performing a sequence of actions on the unwrapped `value`, where each
  19662. * successive action is supplied the return value of the previous.
  19663. *
  19664. * @private
  19665. * @param {*} value The unwrapped value.
  19666. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  19667. * @returns {*} Returns the resolved value.
  19668. */
  19669. function baseWrapperValue(value, actions) {
  19670. var result = value;
  19671. if (result instanceof LazyWrapper) {
  19672. result = result.value();
  19673. }
  19674. return arrayReduce(actions, function(result, action) {
  19675. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  19676. }, result);
  19677. }
  19678. /**
  19679. * The base implementation of methods like `_.xor`, without support for
  19680. * iteratee shorthands, that accepts an array of arrays to inspect.
  19681. *
  19682. * @private
  19683. * @param {Array} arrays The arrays to inspect.
  19684. * @param {Function} [iteratee] The iteratee invoked per element.
  19685. * @param {Function} [comparator] The comparator invoked per element.
  19686. * @returns {Array} Returns the new array of values.
  19687. */
  19688. function baseXor(arrays, iteratee, comparator) {
  19689. var index = -1,
  19690. length = arrays.length;
  19691. while (++index < length) {
  19692. var result = result
  19693. ? arrayPush(
  19694. baseDifference(result, arrays[index], iteratee, comparator),
  19695. baseDifference(arrays[index], result, iteratee, comparator)
  19696. )
  19697. : arrays[index];
  19698. }
  19699. return (result && result.length) ? baseUniq(result, iteratee, comparator) : [];
  19700. }
  19701. /**
  19702. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  19703. *
  19704. * @private
  19705. * @param {Array} props The property identifiers.
  19706. * @param {Array} values The property values.
  19707. * @param {Function} assignFunc The function to assign values.
  19708. * @returns {Object} Returns the new object.
  19709. */
  19710. function baseZipObject(props, values, assignFunc) {
  19711. var index = -1,
  19712. length = props.length,
  19713. valsLength = values.length,
  19714. result = {};
  19715. while (++index < length) {
  19716. var value = index < valsLength ? values[index] : undefined;
  19717. assignFunc(result, props[index], value);
  19718. }
  19719. return result;
  19720. }
  19721. /**
  19722. * Casts `value` to an empty array if it's not an array like object.
  19723. *
  19724. * @private
  19725. * @param {*} value The value to inspect.
  19726. * @returns {Array|Object} Returns the cast array-like object.
  19727. */
  19728. function castArrayLikeObject(value) {
  19729. return isArrayLikeObject(value) ? value : [];
  19730. }
  19731. /**
  19732. * Casts `value` to `identity` if it's not a function.
  19733. *
  19734. * @private
  19735. * @param {*} value The value to inspect.
  19736. * @returns {Function} Returns cast function.
  19737. */
  19738. function castFunction(value) {
  19739. return typeof value == 'function' ? value : identity;
  19740. }
  19741. /**
  19742. * Casts `value` to a path array if it's not one.
  19743. *
  19744. * @private
  19745. * @param {*} value The value to inspect.
  19746. * @returns {Array} Returns the cast property path array.
  19747. */
  19748. function castPath(value) {
  19749. return isArray(value) ? value : stringToPath(value);
  19750. }
  19751. /**
  19752. * Casts `array` to a slice if it's needed.
  19753. *
  19754. * @private
  19755. * @param {Array} array The array to inspect.
  19756. * @param {number} start The start position.
  19757. * @param {number} [end=array.length] The end position.
  19758. * @returns {Array} Returns the cast slice.
  19759. */
  19760. function castSlice(array, start, end) {
  19761. var length = array.length;
  19762. end = end === undefined ? length : end;
  19763. return (!start && end >= length) ? array : baseSlice(array, start, end);
  19764. }
  19765. /**
  19766. * Creates a clone of `buffer`.
  19767. *
  19768. * @private
  19769. * @param {Buffer} buffer The buffer to clone.
  19770. * @param {boolean} [isDeep] Specify a deep clone.
  19771. * @returns {Buffer} Returns the cloned buffer.
  19772. */
  19773. function cloneBuffer(buffer, isDeep) {
  19774. if (isDeep) {
  19775. return buffer.slice();
  19776. }
  19777. var result = new buffer.constructor(buffer.length);
  19778. buffer.copy(result);
  19779. return result;
  19780. }
  19781. /**
  19782. * Creates a clone of `arrayBuffer`.
  19783. *
  19784. * @private
  19785. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  19786. * @returns {ArrayBuffer} Returns the cloned array buffer.
  19787. */
  19788. function cloneArrayBuffer(arrayBuffer) {
  19789. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  19790. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  19791. return result;
  19792. }
  19793. /**
  19794. * Creates a clone of `dataView`.
  19795. *
  19796. * @private
  19797. * @param {Object} dataView The data view to clone.
  19798. * @param {boolean} [isDeep] Specify a deep clone.
  19799. * @returns {Object} Returns the cloned data view.
  19800. */
  19801. function cloneDataView(dataView, isDeep) {
  19802. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  19803. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  19804. }
  19805. /**
  19806. * Creates a clone of `map`.
  19807. *
  19808. * @private
  19809. * @param {Object} map The map to clone.
  19810. * @param {Function} cloneFunc The function to clone values.
  19811. * @param {boolean} [isDeep] Specify a deep clone.
  19812. * @returns {Object} Returns the cloned map.
  19813. */
  19814. function cloneMap(map, isDeep, cloneFunc) {
  19815. var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map);
  19816. return arrayReduce(array, addMapEntry, new map.constructor);
  19817. }
  19818. /**
  19819. * Creates a clone of `regexp`.
  19820. *
  19821. * @private
  19822. * @param {Object} regexp The regexp to clone.
  19823. * @returns {Object} Returns the cloned regexp.
  19824. */
  19825. function cloneRegExp(regexp) {
  19826. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  19827. result.lastIndex = regexp.lastIndex;
  19828. return result;
  19829. }
  19830. /**
  19831. * Creates a clone of `set`.
  19832. *
  19833. * @private
  19834. * @param {Object} set The set to clone.
  19835. * @param {Function} cloneFunc The function to clone values.
  19836. * @param {boolean} [isDeep] Specify a deep clone.
  19837. * @returns {Object} Returns the cloned set.
  19838. */
  19839. function cloneSet(set, isDeep, cloneFunc) {
  19840. var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set);
  19841. return arrayReduce(array, addSetEntry, new set.constructor);
  19842. }
  19843. /**
  19844. * Creates a clone of the `symbol` object.
  19845. *
  19846. * @private
  19847. * @param {Object} symbol The symbol object to clone.
  19848. * @returns {Object} Returns the cloned symbol object.
  19849. */
  19850. function cloneSymbol(symbol) {
  19851. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  19852. }
  19853. /**
  19854. * Creates a clone of `typedArray`.
  19855. *
  19856. * @private
  19857. * @param {Object} typedArray The typed array to clone.
  19858. * @param {boolean} [isDeep] Specify a deep clone.
  19859. * @returns {Object} Returns the cloned typed array.
  19860. */
  19861. function cloneTypedArray(typedArray, isDeep) {
  19862. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  19863. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  19864. }
  19865. /**
  19866. * Compares values to sort them in ascending order.
  19867. *
  19868. * @private
  19869. * @param {*} value The value to compare.
  19870. * @param {*} other The other value to compare.
  19871. * @returns {number} Returns the sort order indicator for `value`.
  19872. */
  19873. function compareAscending(value, other) {
  19874. if (value !== other) {
  19875. var valIsDefined = value !== undefined,
  19876. valIsNull = value === null,
  19877. valIsReflexive = value === value,
  19878. valIsSymbol = isSymbol(value);
  19879. var othIsDefined = other !== undefined,
  19880. othIsNull = other === null,
  19881. othIsReflexive = other === other,
  19882. othIsSymbol = isSymbol(other);
  19883. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  19884. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  19885. (valIsNull && othIsDefined && othIsReflexive) ||
  19886. (!valIsDefined && othIsReflexive) ||
  19887. !valIsReflexive) {
  19888. return 1;
  19889. }
  19890. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  19891. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  19892. (othIsNull && valIsDefined && valIsReflexive) ||
  19893. (!othIsDefined && valIsReflexive) ||
  19894. !othIsReflexive) {
  19895. return -1;
  19896. }
  19897. }
  19898. return 0;
  19899. }
  19900. /**
  19901. * Used by `_.orderBy` to compare multiple properties of a value to another
  19902. * and stable sort them.
  19903. *
  19904. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  19905. * specify an order of "desc" for descending or "asc" for ascending sort order
  19906. * of corresponding values.
  19907. *
  19908. * @private
  19909. * @param {Object} object The object to compare.
  19910. * @param {Object} other The other object to compare.
  19911. * @param {boolean[]|string[]} orders The order to sort by for each property.
  19912. * @returns {number} Returns the sort order indicator for `object`.
  19913. */
  19914. function compareMultiple(object, other, orders) {
  19915. var index = -1,
  19916. objCriteria = object.criteria,
  19917. othCriteria = other.criteria,
  19918. length = objCriteria.length,
  19919. ordersLength = orders.length;
  19920. while (++index < length) {
  19921. var result = compareAscending(objCriteria[index], othCriteria[index]);
  19922. if (result) {
  19923. if (index >= ordersLength) {
  19924. return result;
  19925. }
  19926. var order = orders[index];
  19927. return result * (order == 'desc' ? -1 : 1);
  19928. }
  19929. }
  19930. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  19931. // that causes it, under certain circumstances, to provide the same value for
  19932. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  19933. // for more details.
  19934. //
  19935. // This also ensures a stable sort in V8 and other engines.
  19936. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  19937. return object.index - other.index;
  19938. }
  19939. /**
  19940. * Creates an array that is the composition of partially applied arguments,
  19941. * placeholders, and provided arguments into a single array of arguments.
  19942. *
  19943. * @private
  19944. * @param {Array} args The provided arguments.
  19945. * @param {Array} partials The arguments to prepend to those provided.
  19946. * @param {Array} holders The `partials` placeholder indexes.
  19947. * @params {boolean} [isCurried] Specify composing for a curried function.
  19948. * @returns {Array} Returns the new array of composed arguments.
  19949. */
  19950. function composeArgs(args, partials, holders, isCurried) {
  19951. var argsIndex = -1,
  19952. argsLength = args.length,
  19953. holdersLength = holders.length,
  19954. leftIndex = -1,
  19955. leftLength = partials.length,
  19956. rangeLength = nativeMax(argsLength - holdersLength, 0),
  19957. result = Array(leftLength + rangeLength),
  19958. isUncurried = !isCurried;
  19959. while (++leftIndex < leftLength) {
  19960. result[leftIndex] = partials[leftIndex];
  19961. }
  19962. while (++argsIndex < holdersLength) {
  19963. if (isUncurried || argsIndex < argsLength) {
  19964. result[holders[argsIndex]] = args[argsIndex];
  19965. }
  19966. }
  19967. while (rangeLength--) {
  19968. result[leftIndex++] = args[argsIndex++];
  19969. }
  19970. return result;
  19971. }
  19972. /**
  19973. * This function is like `composeArgs` except that the arguments composition
  19974. * is tailored for `_.partialRight`.
  19975. *
  19976. * @private
  19977. * @param {Array} args The provided arguments.
  19978. * @param {Array} partials The arguments to append to those provided.
  19979. * @param {Array} holders The `partials` placeholder indexes.
  19980. * @params {boolean} [isCurried] Specify composing for a curried function.
  19981. * @returns {Array} Returns the new array of composed arguments.
  19982. */
  19983. function composeArgsRight(args, partials, holders, isCurried) {
  19984. var argsIndex = -1,
  19985. argsLength = args.length,
  19986. holdersIndex = -1,
  19987. holdersLength = holders.length,
  19988. rightIndex = -1,
  19989. rightLength = partials.length,
  19990. rangeLength = nativeMax(argsLength - holdersLength, 0),
  19991. result = Array(rangeLength + rightLength),
  19992. isUncurried = !isCurried;
  19993. while (++argsIndex < rangeLength) {
  19994. result[argsIndex] = args[argsIndex];
  19995. }
  19996. var offset = argsIndex;
  19997. while (++rightIndex < rightLength) {
  19998. result[offset + rightIndex] = partials[rightIndex];
  19999. }
  20000. while (++holdersIndex < holdersLength) {
  20001. if (isUncurried || argsIndex < argsLength) {
  20002. result[offset + holders[holdersIndex]] = args[argsIndex++];
  20003. }
  20004. }
  20005. return result;
  20006. }
  20007. /**
  20008. * Copies the values of `source` to `array`.
  20009. *
  20010. * @private
  20011. * @param {Array} source The array to copy values from.
  20012. * @param {Array} [array=[]] The array to copy values to.
  20013. * @returns {Array} Returns `array`.
  20014. */
  20015. function copyArray(source, array) {
  20016. var index = -1,
  20017. length = source.length;
  20018. array || (array = Array(length));
  20019. while (++index < length) {
  20020. array[index] = source[index];
  20021. }
  20022. return array;
  20023. }
  20024. /**
  20025. * Copies properties of `source` to `object`.
  20026. *
  20027. * @private
  20028. * @param {Object} source The object to copy properties from.
  20029. * @param {Array} props The property identifiers to copy.
  20030. * @param {Object} [object={}] The object to copy properties to.
  20031. * @param {Function} [customizer] The function to customize copied values.
  20032. * @returns {Object} Returns `object`.
  20033. */
  20034. function copyObject(source, props, object, customizer) {
  20035. object || (object = {});
  20036. var index = -1,
  20037. length = props.length;
  20038. while (++index < length) {
  20039. var key = props[index];
  20040. var newValue = customizer
  20041. ? customizer(object[key], source[key], key, object, source)
  20042. : source[key];
  20043. assignValue(object, key, newValue);
  20044. }
  20045. return object;
  20046. }
  20047. /**
  20048. * Copies own symbol properties of `source` to `object`.
  20049. *
  20050. * @private
  20051. * @param {Object} source The object to copy symbols from.
  20052. * @param {Object} [object={}] The object to copy symbols to.
  20053. * @returns {Object} Returns `object`.
  20054. */
  20055. function copySymbols(source, object) {
  20056. return copyObject(source, getSymbols(source), object);
  20057. }
  20058. /**
  20059. * Creates a function like `_.groupBy`.
  20060. *
  20061. * @private
  20062. * @param {Function} setter The function to set accumulator values.
  20063. * @param {Function} [initializer] The accumulator object initializer.
  20064. * @returns {Function} Returns the new aggregator function.
  20065. */
  20066. function createAggregator(setter, initializer) {
  20067. return function(collection, iteratee) {
  20068. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  20069. accumulator = initializer ? initializer() : {};
  20070. return func(collection, setter, getIteratee(iteratee), accumulator);
  20071. };
  20072. }
  20073. /**
  20074. * Creates a function like `_.assign`.
  20075. *
  20076. * @private
  20077. * @param {Function} assigner The function to assign values.
  20078. * @returns {Function} Returns the new assigner function.
  20079. */
  20080. function createAssigner(assigner) {
  20081. return rest(function(object, sources) {
  20082. var index = -1,
  20083. length = sources.length,
  20084. customizer = length > 1 ? sources[length - 1] : undefined,
  20085. guard = length > 2 ? sources[2] : undefined;
  20086. customizer = (assigner.length > 3 && typeof customizer == 'function')
  20087. ? (length--, customizer)
  20088. : undefined;
  20089. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  20090. customizer = length < 3 ? undefined : customizer;
  20091. length = 1;
  20092. }
  20093. object = Object(object);
  20094. while (++index < length) {
  20095. var source = sources[index];
  20096. if (source) {
  20097. assigner(object, source, index, customizer);
  20098. }
  20099. }
  20100. return object;
  20101. });
  20102. }
  20103. /**
  20104. * Creates a `baseEach` or `baseEachRight` function.
  20105. *
  20106. * @private
  20107. * @param {Function} eachFunc The function to iterate over a collection.
  20108. * @param {boolean} [fromRight] Specify iterating from right to left.
  20109. * @returns {Function} Returns the new base function.
  20110. */
  20111. function createBaseEach(eachFunc, fromRight) {
  20112. return function(collection, iteratee) {
  20113. if (collection == null) {
  20114. return collection;
  20115. }
  20116. if (!isArrayLike(collection)) {
  20117. return eachFunc(collection, iteratee);
  20118. }
  20119. var length = collection.length,
  20120. index = fromRight ? length : -1,
  20121. iterable = Object(collection);
  20122. while ((fromRight ? index-- : ++index < length)) {
  20123. if (iteratee(iterable[index], index, iterable) === false) {
  20124. break;
  20125. }
  20126. }
  20127. return collection;
  20128. };
  20129. }
  20130. /**
  20131. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  20132. *
  20133. * @private
  20134. * @param {boolean} [fromRight] Specify iterating from right to left.
  20135. * @returns {Function} Returns the new base function.
  20136. */
  20137. function createBaseFor(fromRight) {
  20138. return function(object, iteratee, keysFunc) {
  20139. var index = -1,
  20140. iterable = Object(object),
  20141. props = keysFunc(object),
  20142. length = props.length;
  20143. while (length--) {
  20144. var key = props[fromRight ? length : ++index];
  20145. if (iteratee(iterable[key], key, iterable) === false) {
  20146. break;
  20147. }
  20148. }
  20149. return object;
  20150. };
  20151. }
  20152. /**
  20153. * Creates a function that wraps `func` to invoke it with the optional `this`
  20154. * binding of `thisArg`.
  20155. *
  20156. * @private
  20157. * @param {Function} func The function to wrap.
  20158. * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
  20159. * for more details.
  20160. * @param {*} [thisArg] The `this` binding of `func`.
  20161. * @returns {Function} Returns the new wrapped function.
  20162. */
  20163. function createBaseWrapper(func, bitmask, thisArg) {
  20164. var isBind = bitmask & BIND_FLAG,
  20165. Ctor = createCtorWrapper(func);
  20166. function wrapper() {
  20167. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  20168. return fn.apply(isBind ? thisArg : this, arguments);
  20169. }
  20170. return wrapper;
  20171. }
  20172. /**
  20173. * Creates a function like `_.lowerFirst`.
  20174. *
  20175. * @private
  20176. * @param {string} methodName The name of the `String` case method to use.
  20177. * @returns {Function} Returns the new case function.
  20178. */
  20179. function createCaseFirst(methodName) {
  20180. return function(string) {
  20181. string = toString(string);
  20182. var strSymbols = reHasComplexSymbol.test(string)
  20183. ? stringToArray(string)
  20184. : undefined;
  20185. var chr = strSymbols
  20186. ? strSymbols[0]
  20187. : string.charAt(0);
  20188. var trailing = strSymbols
  20189. ? castSlice(strSymbols, 1).join('')
  20190. : string.slice(1);
  20191. return chr[methodName]() + trailing;
  20192. };
  20193. }
  20194. /**
  20195. * Creates a function like `_.camelCase`.
  20196. *
  20197. * @private
  20198. * @param {Function} callback The function to combine each word.
  20199. * @returns {Function} Returns the new compounder function.
  20200. */
  20201. function createCompounder(callback) {
  20202. return function(string) {
  20203. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  20204. };
  20205. }
  20206. /**
  20207. * Creates a function that produces an instance of `Ctor` regardless of
  20208. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  20209. *
  20210. * @private
  20211. * @param {Function} Ctor The constructor to wrap.
  20212. * @returns {Function} Returns the new wrapped function.
  20213. */
  20214. function createCtorWrapper(Ctor) {
  20215. return function() {
  20216. // Use a `switch` statement to work with class constructors. See
  20217. // http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  20218. // for more details.
  20219. var args = arguments;
  20220. switch (args.length) {
  20221. case 0: return new Ctor;
  20222. case 1: return new Ctor(args[0]);
  20223. case 2: return new Ctor(args[0], args[1]);
  20224. case 3: return new Ctor(args[0], args[1], args[2]);
  20225. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  20226. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  20227. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  20228. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  20229. }
  20230. var thisBinding = baseCreate(Ctor.prototype),
  20231. result = Ctor.apply(thisBinding, args);
  20232. // Mimic the constructor's `return` behavior.
  20233. // See https://es5.github.io/#x13.2.2 for more details.
  20234. return isObject(result) ? result : thisBinding;
  20235. };
  20236. }
  20237. /**
  20238. * Creates a function that wraps `func` to enable currying.
  20239. *
  20240. * @private
  20241. * @param {Function} func The function to wrap.
  20242. * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
  20243. * for more details.
  20244. * @param {number} arity The arity of `func`.
  20245. * @returns {Function} Returns the new wrapped function.
  20246. */
  20247. function createCurryWrapper(func, bitmask, arity) {
  20248. var Ctor = createCtorWrapper(func);
  20249. function wrapper() {
  20250. var length = arguments.length,
  20251. args = Array(length),
  20252. index = length,
  20253. placeholder = getHolder(wrapper);
  20254. while (index--) {
  20255. args[index] = arguments[index];
  20256. }
  20257. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  20258. ? []
  20259. : replaceHolders(args, placeholder);
  20260. length -= holders.length;
  20261. if (length < arity) {
  20262. return createRecurryWrapper(
  20263. func, bitmask, createHybridWrapper, wrapper.placeholder, undefined,
  20264. args, holders, undefined, undefined, arity - length);
  20265. }
  20266. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  20267. return apply(fn, this, args);
  20268. }
  20269. return wrapper;
  20270. }
  20271. /**
  20272. * Creates a `_.find` or `_.findLast` function.
  20273. *
  20274. * @private
  20275. * @param {Function} findIndexFunc The function to find the collection index.
  20276. * @returns {Function} Returns the new find function.
  20277. */
  20278. function createFind(findIndexFunc) {
  20279. return function(collection, predicate, fromIndex) {
  20280. var iterable = Object(collection);
  20281. predicate = getIteratee(predicate, 3);
  20282. if (!isArrayLike(collection)) {
  20283. var props = keys(collection);
  20284. }
  20285. var index = findIndexFunc(props || collection, function(value, key) {
  20286. if (props) {
  20287. key = value;
  20288. value = iterable[key];
  20289. }
  20290. return predicate(value, key, iterable);
  20291. }, fromIndex);
  20292. return index > -1 ? collection[props ? props[index] : index] : undefined;
  20293. };
  20294. }
  20295. /**
  20296. * Creates a `_.flow` or `_.flowRight` function.
  20297. *
  20298. * @private
  20299. * @param {boolean} [fromRight] Specify iterating from right to left.
  20300. * @returns {Function} Returns the new flow function.
  20301. */
  20302. function createFlow(fromRight) {
  20303. return rest(function(funcs) {
  20304. funcs = baseFlatten(funcs, 1);
  20305. var length = funcs.length,
  20306. index = length,
  20307. prereq = LodashWrapper.prototype.thru;
  20308. if (fromRight) {
  20309. funcs.reverse();
  20310. }
  20311. while (index--) {
  20312. var func = funcs[index];
  20313. if (typeof func != 'function') {
  20314. throw new TypeError(FUNC_ERROR_TEXT);
  20315. }
  20316. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  20317. var wrapper = new LodashWrapper([], true);
  20318. }
  20319. }
  20320. index = wrapper ? index : length;
  20321. while (++index < length) {
  20322. func = funcs[index];
  20323. var funcName = getFuncName(func),
  20324. data = funcName == 'wrapper' ? getData(func) : undefined;
  20325. if (data && isLaziable(data[0]) &&
  20326. data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) &&
  20327. !data[4].length && data[9] == 1
  20328. ) {
  20329. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  20330. } else {
  20331. wrapper = (func.length == 1 && isLaziable(func))
  20332. ? wrapper[funcName]()
  20333. : wrapper.thru(func);
  20334. }
  20335. }
  20336. return function() {
  20337. var args = arguments,
  20338. value = args[0];
  20339. if (wrapper && args.length == 1 &&
  20340. isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
  20341. return wrapper.plant(value).value();
  20342. }
  20343. var index = 0,
  20344. result = length ? funcs[index].apply(this, args) : value;
  20345. while (++index < length) {
  20346. result = funcs[index].call(this, result);
  20347. }
  20348. return result;
  20349. };
  20350. });
  20351. }
  20352. /**
  20353. * Creates a function that wraps `func` to invoke it with optional `this`
  20354. * binding of `thisArg`, partial application, and currying.
  20355. *
  20356. * @private
  20357. * @param {Function|string} func The function or method name to wrap.
  20358. * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
  20359. * for more details.
  20360. * @param {*} [thisArg] The `this` binding of `func`.
  20361. * @param {Array} [partials] The arguments to prepend to those provided to
  20362. * the new function.
  20363. * @param {Array} [holders] The `partials` placeholder indexes.
  20364. * @param {Array} [partialsRight] The arguments to append to those provided
  20365. * to the new function.
  20366. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  20367. * @param {Array} [argPos] The argument positions of the new function.
  20368. * @param {number} [ary] The arity cap of `func`.
  20369. * @param {number} [arity] The arity of `func`.
  20370. * @returns {Function} Returns the new wrapped function.
  20371. */
  20372. function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  20373. var isAry = bitmask & ARY_FLAG,
  20374. isBind = bitmask & BIND_FLAG,
  20375. isBindKey = bitmask & BIND_KEY_FLAG,
  20376. isCurried = bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG),
  20377. isFlip = bitmask & FLIP_FLAG,
  20378. Ctor = isBindKey ? undefined : createCtorWrapper(func);
  20379. function wrapper() {
  20380. var length = arguments.length,
  20381. args = Array(length),
  20382. index = length;
  20383. while (index--) {
  20384. args[index] = arguments[index];
  20385. }
  20386. if (isCurried) {
  20387. var placeholder = getHolder(wrapper),
  20388. holdersCount = countHolders(args, placeholder);
  20389. }
  20390. if (partials) {
  20391. args = composeArgs(args, partials, holders, isCurried);
  20392. }
  20393. if (partialsRight) {
  20394. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  20395. }
  20396. length -= holdersCount;
  20397. if (isCurried && length < arity) {
  20398. var newHolders = replaceHolders(args, placeholder);
  20399. return createRecurryWrapper(
  20400. func, bitmask, createHybridWrapper, wrapper.placeholder, thisArg,
  20401. args, newHolders, argPos, ary, arity - length
  20402. );
  20403. }
  20404. var thisBinding = isBind ? thisArg : this,
  20405. fn = isBindKey ? thisBinding[func] : func;
  20406. length = args.length;
  20407. if (argPos) {
  20408. args = reorder(args, argPos);
  20409. } else if (isFlip && length > 1) {
  20410. args.reverse();
  20411. }
  20412. if (isAry && ary < length) {
  20413. args.length = ary;
  20414. }
  20415. if (this && this !== root && this instanceof wrapper) {
  20416. fn = Ctor || createCtorWrapper(fn);
  20417. }
  20418. return fn.apply(thisBinding, args);
  20419. }
  20420. return wrapper;
  20421. }
  20422. /**
  20423. * Creates a function like `_.invertBy`.
  20424. *
  20425. * @private
  20426. * @param {Function} setter The function to set accumulator values.
  20427. * @param {Function} toIteratee The function to resolve iteratees.
  20428. * @returns {Function} Returns the new inverter function.
  20429. */
  20430. function createInverter(setter, toIteratee) {
  20431. return function(object, iteratee) {
  20432. return baseInverter(object, setter, toIteratee(iteratee), {});
  20433. };
  20434. }
  20435. /**
  20436. * Creates a function that performs a mathematical operation on two values.
  20437. *
  20438. * @private
  20439. * @param {Function} operator The function to perform the operation.
  20440. * @returns {Function} Returns the new mathematical operation function.
  20441. */
  20442. function createMathOperation(operator) {
  20443. return function(value, other) {
  20444. var result;
  20445. if (value === undefined && other === undefined) {
  20446. return 0;
  20447. }
  20448. if (value !== undefined) {
  20449. result = value;
  20450. }
  20451. if (other !== undefined) {
  20452. if (result === undefined) {
  20453. return other;
  20454. }
  20455. if (typeof value == 'string' || typeof other == 'string') {
  20456. value = baseToString(value);
  20457. other = baseToString(other);
  20458. } else {
  20459. value = baseToNumber(value);
  20460. other = baseToNumber(other);
  20461. }
  20462. result = operator(value, other);
  20463. }
  20464. return result;
  20465. };
  20466. }
  20467. /**
  20468. * Creates a function like `_.over`.
  20469. *
  20470. * @private
  20471. * @param {Function} arrayFunc The function to iterate over iteratees.
  20472. * @returns {Function} Returns the new over function.
  20473. */
  20474. function createOver(arrayFunc) {
  20475. return rest(function(iteratees) {
  20476. iteratees = (iteratees.length == 1 && isArray(iteratees[0]))
  20477. ? arrayMap(iteratees[0], baseUnary(getIteratee()))
  20478. : arrayMap(baseFlatten(iteratees, 1, isFlattenableIteratee), baseUnary(getIteratee()));
  20479. return rest(function(args) {
  20480. var thisArg = this;
  20481. return arrayFunc(iteratees, function(iteratee) {
  20482. return apply(iteratee, thisArg, args);
  20483. });
  20484. });
  20485. });
  20486. }
  20487. /**
  20488. * Creates the padding for `string` based on `length`. The `chars` string
  20489. * is truncated if the number of characters exceeds `length`.
  20490. *
  20491. * @private
  20492. * @param {number} length The padding length.
  20493. * @param {string} [chars=' '] The string used as padding.
  20494. * @returns {string} Returns the padding for `string`.
  20495. */
  20496. function createPadding(length, chars) {
  20497. chars = chars === undefined ? ' ' : baseToString(chars);
  20498. var charsLength = chars.length;
  20499. if (charsLength < 2) {
  20500. return charsLength ? baseRepeat(chars, length) : chars;
  20501. }
  20502. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  20503. return reHasComplexSymbol.test(chars)
  20504. ? castSlice(stringToArray(result), 0, length).join('')
  20505. : result.slice(0, length);
  20506. }
  20507. /**
  20508. * Creates a function that wraps `func` to invoke it with the `this` binding
  20509. * of `thisArg` and `partials` prepended to the arguments it receives.
  20510. *
  20511. * @private
  20512. * @param {Function} func The function to wrap.
  20513. * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
  20514. * for more details.
  20515. * @param {*} thisArg The `this` binding of `func`.
  20516. * @param {Array} partials The arguments to prepend to those provided to
  20517. * the new function.
  20518. * @returns {Function} Returns the new wrapped function.
  20519. */
  20520. function createPartialWrapper(func, bitmask, thisArg, partials) {
  20521. var isBind = bitmask & BIND_FLAG,
  20522. Ctor = createCtorWrapper(func);
  20523. function wrapper() {
  20524. var argsIndex = -1,
  20525. argsLength = arguments.length,
  20526. leftIndex = -1,
  20527. leftLength = partials.length,
  20528. args = Array(leftLength + argsLength),
  20529. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  20530. while (++leftIndex < leftLength) {
  20531. args[leftIndex] = partials[leftIndex];
  20532. }
  20533. while (argsLength--) {
  20534. args[leftIndex++] = arguments[++argsIndex];
  20535. }
  20536. return apply(fn, isBind ? thisArg : this, args);
  20537. }
  20538. return wrapper;
  20539. }
  20540. /**
  20541. * Creates a `_.range` or `_.rangeRight` function.
  20542. *
  20543. * @private
  20544. * @param {boolean} [fromRight] Specify iterating from right to left.
  20545. * @returns {Function} Returns the new range function.
  20546. */
  20547. function createRange(fromRight) {
  20548. return function(start, end, step) {
  20549. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  20550. end = step = undefined;
  20551. }
  20552. // Ensure the sign of `-0` is preserved.
  20553. start = toNumber(start);
  20554. start = start === start ? start : 0;
  20555. if (end === undefined) {
  20556. end = start;
  20557. start = 0;
  20558. } else {
  20559. end = toNumber(end) || 0;
  20560. }
  20561. step = step === undefined ? (start < end ? 1 : -1) : (toNumber(step) || 0);
  20562. return baseRange(start, end, step, fromRight);
  20563. };
  20564. }
  20565. /**
  20566. * Creates a function that performs a relational operation on two values.
  20567. *
  20568. * @private
  20569. * @param {Function} operator The function to perform the operation.
  20570. * @returns {Function} Returns the new relational operation function.
  20571. */
  20572. function createRelationalOperation(operator) {
  20573. return function(value, other) {
  20574. if (!(typeof value == 'string' && typeof other == 'string')) {
  20575. value = toNumber(value);
  20576. other = toNumber(other);
  20577. }
  20578. return operator(value, other);
  20579. };
  20580. }
  20581. /**
  20582. * Creates a function that wraps `func` to continue currying.
  20583. *
  20584. * @private
  20585. * @param {Function} func The function to wrap.
  20586. * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
  20587. * for more details.
  20588. * @param {Function} wrapFunc The function to create the `func` wrapper.
  20589. * @param {*} placeholder The placeholder value.
  20590. * @param {*} [thisArg] The `this` binding of `func`.
  20591. * @param {Array} [partials] The arguments to prepend to those provided to
  20592. * the new function.
  20593. * @param {Array} [holders] The `partials` placeholder indexes.
  20594. * @param {Array} [argPos] The argument positions of the new function.
  20595. * @param {number} [ary] The arity cap of `func`.
  20596. * @param {number} [arity] The arity of `func`.
  20597. * @returns {Function} Returns the new wrapped function.
  20598. */
  20599. function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  20600. var isCurry = bitmask & CURRY_FLAG,
  20601. newHolders = isCurry ? holders : undefined,
  20602. newHoldersRight = isCurry ? undefined : holders,
  20603. newPartials = isCurry ? partials : undefined,
  20604. newPartialsRight = isCurry ? undefined : partials;
  20605. bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
  20606. bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
  20607. if (!(bitmask & CURRY_BOUND_FLAG)) {
  20608. bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
  20609. }
  20610. var newData = [
  20611. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  20612. newHoldersRight, argPos, ary, arity
  20613. ];
  20614. var result = wrapFunc.apply(undefined, newData);
  20615. if (isLaziable(func)) {
  20616. setData(result, newData);
  20617. }
  20618. result.placeholder = placeholder;
  20619. return result;
  20620. }
  20621. /**
  20622. * Creates a function like `_.round`.
  20623. *
  20624. * @private
  20625. * @param {string} methodName The name of the `Math` method to use when rounding.
  20626. * @returns {Function} Returns the new round function.
  20627. */
  20628. function createRound(methodName) {
  20629. var func = Math[methodName];
  20630. return function(number, precision) {
  20631. number = toNumber(number);
  20632. precision = nativeMin(toInteger(precision), 292);
  20633. if (precision) {
  20634. // Shift with exponential notation to avoid floating-point issues.
  20635. // See [MDN](https://mdn.io/round#Examples) for more details.
  20636. var pair = (toString(number) + 'e').split('e'),
  20637. value = func(pair[0] + 'e' + (+pair[1] + precision));
  20638. pair = (toString(value) + 'e').split('e');
  20639. return +(pair[0] + 'e' + (+pair[1] - precision));
  20640. }
  20641. return func(number);
  20642. };
  20643. }
  20644. /**
  20645. * Creates a set of `values`.
  20646. *
  20647. * @private
  20648. * @param {Array} values The values to add to the set.
  20649. * @returns {Object} Returns the new set.
  20650. */
  20651. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  20652. return new Set(values);
  20653. };
  20654. /**
  20655. * Creates a `_.toPairs` or `_.toPairsIn` function.
  20656. *
  20657. * @private
  20658. * @param {Function} keysFunc The function to get the keys of a given object.
  20659. * @returns {Function} Returns the new pairs function.
  20660. */
  20661. function createToPairs(keysFunc) {
  20662. return function(object) {
  20663. var tag = getTag(object);
  20664. if (tag == mapTag) {
  20665. return mapToArray(object);
  20666. }
  20667. if (tag == setTag) {
  20668. return setToPairs(object);
  20669. }
  20670. return baseToPairs(object, keysFunc(object));
  20671. };
  20672. }
  20673. /**
  20674. * Creates a function that either curries or invokes `func` with optional
  20675. * `this` binding and partially applied arguments.
  20676. *
  20677. * @private
  20678. * @param {Function|string} func The function or method name to wrap.
  20679. * @param {number} bitmask The bitmask of wrapper flags.
  20680. * The bitmask may be composed of the following flags:
  20681. * 1 - `_.bind`
  20682. * 2 - `_.bindKey`
  20683. * 4 - `_.curry` or `_.curryRight` of a bound function
  20684. * 8 - `_.curry`
  20685. * 16 - `_.curryRight`
  20686. * 32 - `_.partial`
  20687. * 64 - `_.partialRight`
  20688. * 128 - `_.rearg`
  20689. * 256 - `_.ary`
  20690. * 512 - `_.flip`
  20691. * @param {*} [thisArg] The `this` binding of `func`.
  20692. * @param {Array} [partials] The arguments to be partially applied.
  20693. * @param {Array} [holders] The `partials` placeholder indexes.
  20694. * @param {Array} [argPos] The argument positions of the new function.
  20695. * @param {number} [ary] The arity cap of `func`.
  20696. * @param {number} [arity] The arity of `func`.
  20697. * @returns {Function} Returns the new wrapped function.
  20698. */
  20699. function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  20700. var isBindKey = bitmask & BIND_KEY_FLAG;
  20701. if (!isBindKey && typeof func != 'function') {
  20702. throw new TypeError(FUNC_ERROR_TEXT);
  20703. }
  20704. var length = partials ? partials.length : 0;
  20705. if (!length) {
  20706. bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
  20707. partials = holders = undefined;
  20708. }
  20709. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  20710. arity = arity === undefined ? arity : toInteger(arity);
  20711. length -= holders ? holders.length : 0;
  20712. if (bitmask & PARTIAL_RIGHT_FLAG) {
  20713. var partialsRight = partials,
  20714. holdersRight = holders;
  20715. partials = holders = undefined;
  20716. }
  20717. var data = isBindKey ? undefined : getData(func);
  20718. var newData = [
  20719. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  20720. argPos, ary, arity
  20721. ];
  20722. if (data) {
  20723. mergeData(newData, data);
  20724. }
  20725. func = newData[0];
  20726. bitmask = newData[1];
  20727. thisArg = newData[2];
  20728. partials = newData[3];
  20729. holders = newData[4];
  20730. arity = newData[9] = newData[9] == null
  20731. ? (isBindKey ? 0 : func.length)
  20732. : nativeMax(newData[9] - length, 0);
  20733. if (!arity && bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG)) {
  20734. bitmask &= ~(CURRY_FLAG | CURRY_RIGHT_FLAG);
  20735. }
  20736. if (!bitmask || bitmask == BIND_FLAG) {
  20737. var result = createBaseWrapper(func, bitmask, thisArg);
  20738. } else if (bitmask == CURRY_FLAG || bitmask == CURRY_RIGHT_FLAG) {
  20739. result = createCurryWrapper(func, bitmask, arity);
  20740. } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) {
  20741. result = createPartialWrapper(func, bitmask, thisArg, partials);
  20742. } else {
  20743. result = createHybridWrapper.apply(undefined, newData);
  20744. }
  20745. var setter = data ? baseSetData : setData;
  20746. return setter(result, newData);
  20747. }
  20748. /**
  20749. * A specialized version of `baseIsEqualDeep` for arrays with support for
  20750. * partial deep comparisons.
  20751. *
  20752. * @private
  20753. * @param {Array} array The array to compare.
  20754. * @param {Array} other The other array to compare.
  20755. * @param {Function} equalFunc The function to determine equivalents of values.
  20756. * @param {Function} customizer The function to customize comparisons.
  20757. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  20758. * for more details.
  20759. * @param {Object} stack Tracks traversed `array` and `other` objects.
  20760. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  20761. */
  20762. function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
  20763. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  20764. arrLength = array.length,
  20765. othLength = other.length;
  20766. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  20767. return false;
  20768. }
  20769. // Assume cyclic values are equal.
  20770. var stacked = stack.get(array);
  20771. if (stacked) {
  20772. return stacked == other;
  20773. }
  20774. var index = -1,
  20775. result = true,
  20776. seen = (bitmask & UNORDERED_COMPARE_FLAG) ? new SetCache : undefined;
  20777. stack.set(array, other);
  20778. // Ignore non-index properties.
  20779. while (++index < arrLength) {
  20780. var arrValue = array[index],
  20781. othValue = other[index];
  20782. if (customizer) {
  20783. var compared = isPartial
  20784. ? customizer(othValue, arrValue, index, other, array, stack)
  20785. : customizer(arrValue, othValue, index, array, other, stack);
  20786. }
  20787. if (compared !== undefined) {
  20788. if (compared) {
  20789. continue;
  20790. }
  20791. result = false;
  20792. break;
  20793. }
  20794. // Recursively compare arrays (susceptible to call stack limits).
  20795. if (seen) {
  20796. if (!arraySome(other, function(othValue, othIndex) {
  20797. if (!seen.has(othIndex) &&
  20798. (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  20799. return seen.add(othIndex);
  20800. }
  20801. })) {
  20802. result = false;
  20803. break;
  20804. }
  20805. } else if (!(
  20806. arrValue === othValue ||
  20807. equalFunc(arrValue, othValue, customizer, bitmask, stack)
  20808. )) {
  20809. result = false;
  20810. break;
  20811. }
  20812. }
  20813. stack['delete'](array);
  20814. return result;
  20815. }
  20816. /**
  20817. * A specialized version of `baseIsEqualDeep` for comparing objects of
  20818. * the same `toStringTag`.
  20819. *
  20820. * **Note:** This function only supports comparing values with tags of
  20821. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  20822. *
  20823. * @private
  20824. * @param {Object} object The object to compare.
  20825. * @param {Object} other The other object to compare.
  20826. * @param {string} tag The `toStringTag` of the objects to compare.
  20827. * @param {Function} equalFunc The function to determine equivalents of values.
  20828. * @param {Function} customizer The function to customize comparisons.
  20829. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  20830. * for more details.
  20831. * @param {Object} stack Tracks traversed `object` and `other` objects.
  20832. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  20833. */
  20834. function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
  20835. switch (tag) {
  20836. case dataViewTag:
  20837. if ((object.byteLength != other.byteLength) ||
  20838. (object.byteOffset != other.byteOffset)) {
  20839. return false;
  20840. }
  20841. object = object.buffer;
  20842. other = other.buffer;
  20843. case arrayBufferTag:
  20844. if ((object.byteLength != other.byteLength) ||
  20845. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  20846. return false;
  20847. }
  20848. return true;
  20849. case boolTag:
  20850. case dateTag:
  20851. // Coerce dates and booleans to numbers, dates to milliseconds and
  20852. // booleans to `1` or `0` treating invalid dates coerced to `NaN` as
  20853. // not equal.
  20854. return +object == +other;
  20855. case errorTag:
  20856. return object.name == other.name && object.message == other.message;
  20857. case numberTag:
  20858. // Treat `NaN` vs. `NaN` as equal.
  20859. return (object != +object) ? other != +other : object == +other;
  20860. case regexpTag:
  20861. case stringTag:
  20862. // Coerce regexes to strings and treat strings, primitives and objects,
  20863. // as equal. See http://www.ecma-international.org/ecma-262/6.0/#sec-regexp.prototype.tostring
  20864. // for more details.
  20865. return object == (other + '');
  20866. case mapTag:
  20867. var convert = mapToArray;
  20868. case setTag:
  20869. var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
  20870. convert || (convert = setToArray);
  20871. if (object.size != other.size && !isPartial) {
  20872. return false;
  20873. }
  20874. // Assume cyclic values are equal.
  20875. var stacked = stack.get(object);
  20876. if (stacked) {
  20877. return stacked == other;
  20878. }
  20879. bitmask |= UNORDERED_COMPARE_FLAG;
  20880. stack.set(object, other);
  20881. // Recursively compare objects (susceptible to call stack limits).
  20882. return equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
  20883. case symbolTag:
  20884. if (symbolValueOf) {
  20885. return symbolValueOf.call(object) == symbolValueOf.call(other);
  20886. }
  20887. }
  20888. return false;
  20889. }
  20890. /**
  20891. * A specialized version of `baseIsEqualDeep` for objects with support for
  20892. * partial deep comparisons.
  20893. *
  20894. * @private
  20895. * @param {Object} object The object to compare.
  20896. * @param {Object} other The other object to compare.
  20897. * @param {Function} equalFunc The function to determine equivalents of values.
  20898. * @param {Function} customizer The function to customize comparisons.
  20899. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  20900. * for more details.
  20901. * @param {Object} stack Tracks traversed `object` and `other` objects.
  20902. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  20903. */
  20904. function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
  20905. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  20906. objProps = keys(object),
  20907. objLength = objProps.length,
  20908. othProps = keys(other),
  20909. othLength = othProps.length;
  20910. if (objLength != othLength && !isPartial) {
  20911. return false;
  20912. }
  20913. var index = objLength;
  20914. while (index--) {
  20915. var key = objProps[index];
  20916. if (!(isPartial ? key in other : baseHas(other, key))) {
  20917. return false;
  20918. }
  20919. }
  20920. // Assume cyclic values are equal.
  20921. var stacked = stack.get(object);
  20922. if (stacked) {
  20923. return stacked == other;
  20924. }
  20925. var result = true;
  20926. stack.set(object, other);
  20927. var skipCtor = isPartial;
  20928. while (++index < objLength) {
  20929. key = objProps[index];
  20930. var objValue = object[key],
  20931. othValue = other[key];
  20932. if (customizer) {
  20933. var compared = isPartial
  20934. ? customizer(othValue, objValue, key, other, object, stack)
  20935. : customizer(objValue, othValue, key, object, other, stack);
  20936. }
  20937. // Recursively compare objects (susceptible to call stack limits).
  20938. if (!(compared === undefined
  20939. ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
  20940. : compared
  20941. )) {
  20942. result = false;
  20943. break;
  20944. }
  20945. skipCtor || (skipCtor = key == 'constructor');
  20946. }
  20947. if (result && !skipCtor) {
  20948. var objCtor = object.constructor,
  20949. othCtor = other.constructor;
  20950. // Non `Object` object instances with different constructors are not equal.
  20951. if (objCtor != othCtor &&
  20952. ('constructor' in object && 'constructor' in other) &&
  20953. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  20954. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  20955. result = false;
  20956. }
  20957. }
  20958. stack['delete'](object);
  20959. return result;
  20960. }
  20961. /**
  20962. * Creates an array of own enumerable property names and symbols of `object`.
  20963. *
  20964. * @private
  20965. * @param {Object} object The object to query.
  20966. * @returns {Array} Returns the array of property names and symbols.
  20967. */
  20968. function getAllKeys(object) {
  20969. return baseGetAllKeys(object, keys, getSymbols);
  20970. }
  20971. /**
  20972. * Creates an array of own and inherited enumerable property names and
  20973. * symbols of `object`.
  20974. *
  20975. * @private
  20976. * @param {Object} object The object to query.
  20977. * @returns {Array} Returns the array of property names and symbols.
  20978. */
  20979. function getAllKeysIn(object) {
  20980. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  20981. }
  20982. /**
  20983. * Gets metadata for `func`.
  20984. *
  20985. * @private
  20986. * @param {Function} func The function to query.
  20987. * @returns {*} Returns the metadata for `func`.
  20988. */
  20989. var getData = !metaMap ? noop : function(func) {
  20990. return metaMap.get(func);
  20991. };
  20992. /**
  20993. * Gets the name of `func`.
  20994. *
  20995. * @private
  20996. * @param {Function} func The function to query.
  20997. * @returns {string} Returns the function name.
  20998. */
  20999. function getFuncName(func) {
  21000. var result = (func.name + ''),
  21001. array = realNames[result],
  21002. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  21003. while (length--) {
  21004. var data = array[length],
  21005. otherFunc = data.func;
  21006. if (otherFunc == null || otherFunc == func) {
  21007. return data.name;
  21008. }
  21009. }
  21010. return result;
  21011. }
  21012. /**
  21013. * Gets the argument placeholder value for `func`.
  21014. *
  21015. * @private
  21016. * @param {Function} func The function to inspect.
  21017. * @returns {*} Returns the placeholder value.
  21018. */
  21019. function getHolder(func) {
  21020. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  21021. return object.placeholder;
  21022. }
  21023. /**
  21024. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  21025. * this function returns the custom method, otherwise it returns `baseIteratee`.
  21026. * If arguments are provided, the chosen function is invoked with them and
  21027. * its result is returned.
  21028. *
  21029. * @private
  21030. * @param {*} [value] The value to convert to an iteratee.
  21031. * @param {number} [arity] The arity of the created iteratee.
  21032. * @returns {Function} Returns the chosen function or its result.
  21033. */
  21034. function getIteratee() {
  21035. var result = lodash.iteratee || iteratee;
  21036. result = result === iteratee ? baseIteratee : result;
  21037. return arguments.length ? result(arguments[0], arguments[1]) : result;
  21038. }
  21039. /**
  21040. * Gets the "length" property value of `object`.
  21041. *
  21042. * **Note:** This function is used to avoid a
  21043. * [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects
  21044. * Safari on at least iOS 8.1-8.3 ARM64.
  21045. *
  21046. * @private
  21047. * @param {Object} object The object to query.
  21048. * @returns {*} Returns the "length" value.
  21049. */
  21050. var getLength = baseProperty('length');
  21051. /**
  21052. * Gets the data for `map`.
  21053. *
  21054. * @private
  21055. * @param {Object} map The map to query.
  21056. * @param {string} key The reference key.
  21057. * @returns {*} Returns the map data.
  21058. */
  21059. function getMapData(map, key) {
  21060. var data = map.__data__;
  21061. return isKeyable(key)
  21062. ? data[typeof key == 'string' ? 'string' : 'hash']
  21063. : data.map;
  21064. }
  21065. /**
  21066. * Gets the property names, values, and compare flags of `object`.
  21067. *
  21068. * @private
  21069. * @param {Object} object The object to query.
  21070. * @returns {Array} Returns the match data of `object`.
  21071. */
  21072. function getMatchData(object) {
  21073. var result = keys(object),
  21074. length = result.length;
  21075. while (length--) {
  21076. var key = result[length],
  21077. value = object[key];
  21078. result[length] = [key, value, isStrictComparable(value)];
  21079. }
  21080. return result;
  21081. }
  21082. /**
  21083. * Gets the native function at `key` of `object`.
  21084. *
  21085. * @private
  21086. * @param {Object} object The object to query.
  21087. * @param {string} key The key of the method to get.
  21088. * @returns {*} Returns the function if it's native, else `undefined`.
  21089. */
  21090. function getNative(object, key) {
  21091. var value = getValue(object, key);
  21092. return baseIsNative(value) ? value : undefined;
  21093. }
  21094. /**
  21095. * Gets the `[[Prototype]]` of `value`.
  21096. *
  21097. * @private
  21098. * @param {*} value The value to query.
  21099. * @returns {null|Object} Returns the `[[Prototype]]`.
  21100. */
  21101. function getPrototype(value) {
  21102. return nativeGetPrototype(Object(value));
  21103. }
  21104. /**
  21105. * Creates an array of the own enumerable symbol properties of `object`.
  21106. *
  21107. * @private
  21108. * @param {Object} object The object to query.
  21109. * @returns {Array} Returns the array of symbols.
  21110. */
  21111. function getSymbols(object) {
  21112. // Coerce `object` to an object to avoid non-object errors in V8.
  21113. // See https://bugs.chromium.org/p/v8/issues/detail?id=3443 for more details.
  21114. return getOwnPropertySymbols(Object(object));
  21115. }
  21116. // Fallback for IE < 11.
  21117. if (!getOwnPropertySymbols) {
  21118. getSymbols = stubArray;
  21119. }
  21120. /**
  21121. * Creates an array of the own and inherited enumerable symbol properties
  21122. * of `object`.
  21123. *
  21124. * @private
  21125. * @param {Object} object The object to query.
  21126. * @returns {Array} Returns the array of symbols.
  21127. */
  21128. var getSymbolsIn = !getOwnPropertySymbols ? getSymbols : function(object) {
  21129. var result = [];
  21130. while (object) {
  21131. arrayPush(result, getSymbols(object));
  21132. object = getPrototype(object);
  21133. }
  21134. return result;
  21135. };
  21136. /**
  21137. * Gets the `toStringTag` of `value`.
  21138. *
  21139. * @private
  21140. * @param {*} value The value to query.
  21141. * @returns {string} Returns the `toStringTag`.
  21142. */
  21143. function getTag(value) {
  21144. return objectToString.call(value);
  21145. }
  21146. // Fallback for data views, maps, sets, and weak maps in IE 11,
  21147. // for data views in Edge, and promises in Node.js.
  21148. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  21149. (Map && getTag(new Map) != mapTag) ||
  21150. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  21151. (Set && getTag(new Set) != setTag) ||
  21152. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  21153. getTag = function(value) {
  21154. var result = objectToString.call(value),
  21155. Ctor = result == objectTag ? value.constructor : undefined,
  21156. ctorString = Ctor ? toSource(Ctor) : undefined;
  21157. if (ctorString) {
  21158. switch (ctorString) {
  21159. case dataViewCtorString: return dataViewTag;
  21160. case mapCtorString: return mapTag;
  21161. case promiseCtorString: return promiseTag;
  21162. case setCtorString: return setTag;
  21163. case weakMapCtorString: return weakMapTag;
  21164. }
  21165. }
  21166. return result;
  21167. };
  21168. }
  21169. /**
  21170. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  21171. *
  21172. * @private
  21173. * @param {number} start The start of the view.
  21174. * @param {number} end The end of the view.
  21175. * @param {Array} transforms The transformations to apply to the view.
  21176. * @returns {Object} Returns an object containing the `start` and `end`
  21177. * positions of the view.
  21178. */
  21179. function getView(start, end, transforms) {
  21180. var index = -1,
  21181. length = transforms.length;
  21182. while (++index < length) {
  21183. var data = transforms[index],
  21184. size = data.size;
  21185. switch (data.type) {
  21186. case 'drop': start += size; break;
  21187. case 'dropRight': end -= size; break;
  21188. case 'take': end = nativeMin(end, start + size); break;
  21189. case 'takeRight': start = nativeMax(start, end - size); break;
  21190. }
  21191. }
  21192. return { 'start': start, 'end': end };
  21193. }
  21194. /**
  21195. * Checks if `path` exists on `object`.
  21196. *
  21197. * @private
  21198. * @param {Object} object The object to query.
  21199. * @param {Array|string} path The path to check.
  21200. * @param {Function} hasFunc The function to check properties.
  21201. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  21202. */
  21203. function hasPath(object, path, hasFunc) {
  21204. path = isKey(path, object) ? [path] : castPath(path);
  21205. var result,
  21206. index = -1,
  21207. length = path.length;
  21208. while (++index < length) {
  21209. var key = toKey(path[index]);
  21210. if (!(result = object != null && hasFunc(object, key))) {
  21211. break;
  21212. }
  21213. object = object[key];
  21214. }
  21215. if (result) {
  21216. return result;
  21217. }
  21218. var length = object ? object.length : 0;
  21219. return !!length && isLength(length) && isIndex(key, length) &&
  21220. (isArray(object) || isString(object) || isArguments(object));
  21221. }
  21222. /**
  21223. * Initializes an array clone.
  21224. *
  21225. * @private
  21226. * @param {Array} array The array to clone.
  21227. * @returns {Array} Returns the initialized clone.
  21228. */
  21229. function initCloneArray(array) {
  21230. var length = array.length,
  21231. result = array.constructor(length);
  21232. // Add properties assigned by `RegExp#exec`.
  21233. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  21234. result.index = array.index;
  21235. result.input = array.input;
  21236. }
  21237. return result;
  21238. }
  21239. /**
  21240. * Initializes an object clone.
  21241. *
  21242. * @private
  21243. * @param {Object} object The object to clone.
  21244. * @returns {Object} Returns the initialized clone.
  21245. */
  21246. function initCloneObject(object) {
  21247. return (typeof object.constructor == 'function' && !isPrototype(object))
  21248. ? baseCreate(getPrototype(object))
  21249. : {};
  21250. }
  21251. /**
  21252. * Initializes an object clone based on its `toStringTag`.
  21253. *
  21254. * **Note:** This function only supports cloning values with tags of
  21255. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  21256. *
  21257. * @private
  21258. * @param {Object} object The object to clone.
  21259. * @param {string} tag The `toStringTag` of the object to clone.
  21260. * @param {Function} cloneFunc The function to clone values.
  21261. * @param {boolean} [isDeep] Specify a deep clone.
  21262. * @returns {Object} Returns the initialized clone.
  21263. */
  21264. function initCloneByTag(object, tag, cloneFunc, isDeep) {
  21265. var Ctor = object.constructor;
  21266. switch (tag) {
  21267. case arrayBufferTag:
  21268. return cloneArrayBuffer(object);
  21269. case boolTag:
  21270. case dateTag:
  21271. return new Ctor(+object);
  21272. case dataViewTag:
  21273. return cloneDataView(object, isDeep);
  21274. case float32Tag: case float64Tag:
  21275. case int8Tag: case int16Tag: case int32Tag:
  21276. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  21277. return cloneTypedArray(object, isDeep);
  21278. case mapTag:
  21279. return cloneMap(object, isDeep, cloneFunc);
  21280. case numberTag:
  21281. case stringTag:
  21282. return new Ctor(object);
  21283. case regexpTag:
  21284. return cloneRegExp(object);
  21285. case setTag:
  21286. return cloneSet(object, isDeep, cloneFunc);
  21287. case symbolTag:
  21288. return cloneSymbol(object);
  21289. }
  21290. }
  21291. /**
  21292. * Creates an array of index keys for `object` values of arrays,
  21293. * `arguments` objects, and strings, otherwise `null` is returned.
  21294. *
  21295. * @private
  21296. * @param {Object} object The object to query.
  21297. * @returns {Array|null} Returns index keys, else `null`.
  21298. */
  21299. function indexKeys(object) {
  21300. var length = object ? object.length : undefined;
  21301. if (isLength(length) &&
  21302. (isArray(object) || isString(object) || isArguments(object))) {
  21303. return baseTimes(length, String);
  21304. }
  21305. return null;
  21306. }
  21307. /**
  21308. * Checks if `value` is a flattenable `arguments` object or array.
  21309. *
  21310. * @private
  21311. * @param {*} value The value to check.
  21312. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  21313. */
  21314. function isFlattenable(value) {
  21315. return isArray(value) || isArguments(value);
  21316. }
  21317. /**
  21318. * Checks if `value` is a flattenable array and not a `_.matchesProperty`
  21319. * iteratee shorthand.
  21320. *
  21321. * @private
  21322. * @param {*} value The value to check.
  21323. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  21324. */
  21325. function isFlattenableIteratee(value) {
  21326. return isArray(value) && !(value.length == 2 && !isFunction(value[0]));
  21327. }
  21328. /**
  21329. * Checks if `value` is a valid array-like index.
  21330. *
  21331. * @private
  21332. * @param {*} value The value to check.
  21333. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  21334. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  21335. */
  21336. function isIndex(value, length) {
  21337. length = length == null ? MAX_SAFE_INTEGER : length;
  21338. return !!length &&
  21339. (typeof value == 'number' || reIsUint.test(value)) &&
  21340. (value > -1 && value % 1 == 0 && value < length);
  21341. }
  21342. /**
  21343. * Checks if the given arguments are from an iteratee call.
  21344. *
  21345. * @private
  21346. * @param {*} value The potential iteratee value argument.
  21347. * @param {*} index The potential iteratee index or key argument.
  21348. * @param {*} object The potential iteratee object argument.
  21349. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  21350. * else `false`.
  21351. */
  21352. function isIterateeCall(value, index, object) {
  21353. if (!isObject(object)) {
  21354. return false;
  21355. }
  21356. var type = typeof index;
  21357. if (type == 'number'
  21358. ? (isArrayLike(object) && isIndex(index, object.length))
  21359. : (type == 'string' && index in object)
  21360. ) {
  21361. return eq(object[index], value);
  21362. }
  21363. return false;
  21364. }
  21365. /**
  21366. * Checks if `value` is a property name and not a property path.
  21367. *
  21368. * @private
  21369. * @param {*} value The value to check.
  21370. * @param {Object} [object] The object to query keys on.
  21371. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  21372. */
  21373. function isKey(value, object) {
  21374. if (isArray(value)) {
  21375. return false;
  21376. }
  21377. var type = typeof value;
  21378. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  21379. value == null || isSymbol(value)) {
  21380. return true;
  21381. }
  21382. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  21383. (object != null && value in Object(object));
  21384. }
  21385. /**
  21386. * Checks if `value` is suitable for use as unique object key.
  21387. *
  21388. * @private
  21389. * @param {*} value The value to check.
  21390. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  21391. */
  21392. function isKeyable(value) {
  21393. var type = typeof value;
  21394. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  21395. ? (value !== '__proto__')
  21396. : (value === null);
  21397. }
  21398. /**
  21399. * Checks if `func` has a lazy counterpart.
  21400. *
  21401. * @private
  21402. * @param {Function} func The function to check.
  21403. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  21404. * else `false`.
  21405. */
  21406. function isLaziable(func) {
  21407. var funcName = getFuncName(func),
  21408. other = lodash[funcName];
  21409. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  21410. return false;
  21411. }
  21412. if (func === other) {
  21413. return true;
  21414. }
  21415. var data = getData(other);
  21416. return !!data && func === data[0];
  21417. }
  21418. /**
  21419. * Checks if `func` has its source masked.
  21420. *
  21421. * @private
  21422. * @param {Function} func The function to check.
  21423. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  21424. */
  21425. function isMasked(func) {
  21426. return !!maskSrcKey && (maskSrcKey in func);
  21427. }
  21428. /**
  21429. * Checks if `func` is capable of being masked.
  21430. *
  21431. * @private
  21432. * @param {*} value The value to check.
  21433. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  21434. */
  21435. var isMaskable = coreJsData ? isFunction : stubFalse;
  21436. /**
  21437. * Checks if `value` is likely a prototype object.
  21438. *
  21439. * @private
  21440. * @param {*} value The value to check.
  21441. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  21442. */
  21443. function isPrototype(value) {
  21444. var Ctor = value && value.constructor,
  21445. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  21446. return value === proto;
  21447. }
  21448. /**
  21449. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  21450. *
  21451. * @private
  21452. * @param {*} value The value to check.
  21453. * @returns {boolean} Returns `true` if `value` if suitable for strict
  21454. * equality comparisons, else `false`.
  21455. */
  21456. function isStrictComparable(value) {
  21457. return value === value && !isObject(value);
  21458. }
  21459. /**
  21460. * A specialized version of `matchesProperty` for source values suitable
  21461. * for strict equality comparisons, i.e. `===`.
  21462. *
  21463. * @private
  21464. * @param {string} key The key of the property to get.
  21465. * @param {*} srcValue The value to match.
  21466. * @returns {Function} Returns the new spec function.
  21467. */
  21468. function matchesStrictComparable(key, srcValue) {
  21469. return function(object) {
  21470. if (object == null) {
  21471. return false;
  21472. }
  21473. return object[key] === srcValue &&
  21474. (srcValue !== undefined || (key in Object(object)));
  21475. };
  21476. }
  21477. /**
  21478. * Merges the function metadata of `source` into `data`.
  21479. *
  21480. * Merging metadata reduces the number of wrappers used to invoke a function.
  21481. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  21482. * may be applied regardless of execution order. Methods like `_.ary` and
  21483. * `_.rearg` modify function arguments, making the order in which they are
  21484. * executed important, preventing the merging of metadata. However, we make
  21485. * an exception for a safe combined case where curried functions have `_.ary`
  21486. * and or `_.rearg` applied.
  21487. *
  21488. * @private
  21489. * @param {Array} data The destination metadata.
  21490. * @param {Array} source The source metadata.
  21491. * @returns {Array} Returns `data`.
  21492. */
  21493. function mergeData(data, source) {
  21494. var bitmask = data[1],
  21495. srcBitmask = source[1],
  21496. newBitmask = bitmask | srcBitmask,
  21497. isCommon = newBitmask < (BIND_FLAG | BIND_KEY_FLAG | ARY_FLAG);
  21498. var isCombo =
  21499. ((srcBitmask == ARY_FLAG) && (bitmask == CURRY_FLAG)) ||
  21500. ((srcBitmask == ARY_FLAG) && (bitmask == REARG_FLAG) && (data[7].length <= source[8])) ||
  21501. ((srcBitmask == (ARY_FLAG | REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == CURRY_FLAG));
  21502. // Exit early if metadata can't be merged.
  21503. if (!(isCommon || isCombo)) {
  21504. return data;
  21505. }
  21506. // Use source `thisArg` if available.
  21507. if (srcBitmask & BIND_FLAG) {
  21508. data[2] = source[2];
  21509. // Set when currying a bound function.
  21510. newBitmask |= bitmask & BIND_FLAG ? 0 : CURRY_BOUND_FLAG;
  21511. }
  21512. // Compose partial arguments.
  21513. var value = source[3];
  21514. if (value) {
  21515. var partials = data[3];
  21516. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  21517. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  21518. }
  21519. // Compose partial right arguments.
  21520. value = source[5];
  21521. if (value) {
  21522. partials = data[5];
  21523. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  21524. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  21525. }
  21526. // Use source `argPos` if available.
  21527. value = source[7];
  21528. if (value) {
  21529. data[7] = value;
  21530. }
  21531. // Use source `ary` if it's smaller.
  21532. if (srcBitmask & ARY_FLAG) {
  21533. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  21534. }
  21535. // Use source `arity` if one is not provided.
  21536. if (data[9] == null) {
  21537. data[9] = source[9];
  21538. }
  21539. // Use source `func` and merge bitmasks.
  21540. data[0] = source[0];
  21541. data[1] = newBitmask;
  21542. return data;
  21543. }
  21544. /**
  21545. * Used by `_.defaultsDeep` to customize its `_.merge` use.
  21546. *
  21547. * @private
  21548. * @param {*} objValue The destination value.
  21549. * @param {*} srcValue The source value.
  21550. * @param {string} key The key of the property to merge.
  21551. * @param {Object} object The parent object of `objValue`.
  21552. * @param {Object} source The parent object of `srcValue`.
  21553. * @param {Object} [stack] Tracks traversed source values and their merged
  21554. * counterparts.
  21555. * @returns {*} Returns the value to assign.
  21556. */
  21557. function mergeDefaults(objValue, srcValue, key, object, source, stack) {
  21558. if (isObject(objValue) && isObject(srcValue)) {
  21559. baseMerge(objValue, srcValue, undefined, mergeDefaults, stack.set(srcValue, objValue));
  21560. }
  21561. return objValue;
  21562. }
  21563. /**
  21564. * Gets the parent value at `path` of `object`.
  21565. *
  21566. * @private
  21567. * @param {Object} object The object to query.
  21568. * @param {Array} path The path to get the parent value of.
  21569. * @returns {*} Returns the parent value.
  21570. */
  21571. function parent(object, path) {
  21572. return path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  21573. }
  21574. /**
  21575. * Reorder `array` according to the specified indexes where the element at
  21576. * the first index is assigned as the first element, the element at
  21577. * the second index is assigned as the second element, and so on.
  21578. *
  21579. * @private
  21580. * @param {Array} array The array to reorder.
  21581. * @param {Array} indexes The arranged array indexes.
  21582. * @returns {Array} Returns `array`.
  21583. */
  21584. function reorder(array, indexes) {
  21585. var arrLength = array.length,
  21586. length = nativeMin(indexes.length, arrLength),
  21587. oldArray = copyArray(array);
  21588. while (length--) {
  21589. var index = indexes[length];
  21590. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  21591. }
  21592. return array;
  21593. }
  21594. /**
  21595. * Sets metadata for `func`.
  21596. *
  21597. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  21598. * period of time, it will trip its breaker and transition to an identity
  21599. * function to avoid garbage collection pauses in V8. See
  21600. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  21601. * for more details.
  21602. *
  21603. * @private
  21604. * @param {Function} func The function to associate metadata with.
  21605. * @param {*} data The metadata.
  21606. * @returns {Function} Returns `func`.
  21607. */
  21608. var setData = (function() {
  21609. var count = 0,
  21610. lastCalled = 0;
  21611. return function(key, value) {
  21612. var stamp = now(),
  21613. remaining = HOT_SPAN - (stamp - lastCalled);
  21614. lastCalled = stamp;
  21615. if (remaining > 0) {
  21616. if (++count >= HOT_COUNT) {
  21617. return key;
  21618. }
  21619. } else {
  21620. count = 0;
  21621. }
  21622. return baseSetData(key, value);
  21623. };
  21624. }());
  21625. /**
  21626. * Converts `string` to a property path array.
  21627. *
  21628. * @private
  21629. * @param {string} string The string to convert.
  21630. * @returns {Array} Returns the property path array.
  21631. */
  21632. var stringToPath = memoize(function(string) {
  21633. var result = [];
  21634. toString(string).replace(rePropName, function(match, number, quote, string) {
  21635. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  21636. });
  21637. return result;
  21638. });
  21639. /**
  21640. * Converts `value` to a string key if it's not a string or symbol.
  21641. *
  21642. * @private
  21643. * @param {*} value The value to inspect.
  21644. * @returns {string|symbol} Returns the key.
  21645. */
  21646. function toKey(value) {
  21647. if (typeof value == 'string' || isSymbol(value)) {
  21648. return value;
  21649. }
  21650. var result = (value + '');
  21651. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  21652. }
  21653. /**
  21654. * Converts `func` to its source code.
  21655. *
  21656. * @private
  21657. * @param {Function} func The function to process.
  21658. * @returns {string} Returns the source code.
  21659. */
  21660. function toSource(func) {
  21661. if (func != null) {
  21662. try {
  21663. return funcToString.call(func);
  21664. } catch (e) {}
  21665. try {
  21666. return (func + '');
  21667. } catch (e) {}
  21668. }
  21669. return '';
  21670. }
  21671. /**
  21672. * Creates a clone of `wrapper`.
  21673. *
  21674. * @private
  21675. * @param {Object} wrapper The wrapper to clone.
  21676. * @returns {Object} Returns the cloned wrapper.
  21677. */
  21678. function wrapperClone(wrapper) {
  21679. if (wrapper instanceof LazyWrapper) {
  21680. return wrapper.clone();
  21681. }
  21682. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  21683. result.__actions__ = copyArray(wrapper.__actions__);
  21684. result.__index__ = wrapper.__index__;
  21685. result.__values__ = wrapper.__values__;
  21686. return result;
  21687. }
  21688. /*------------------------------------------------------------------------*/
  21689. /**
  21690. * Creates an array of elements split into groups the length of `size`.
  21691. * If `array` can't be split evenly, the final chunk will be the remaining
  21692. * elements.
  21693. *
  21694. * @static
  21695. * @memberOf _
  21696. * @since 3.0.0
  21697. * @category Array
  21698. * @param {Array} array The array to process.
  21699. * @param {number} [size=1] The length of each chunk
  21700. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  21701. * @returns {Array} Returns the new array of chunks.
  21702. * @example
  21703. *
  21704. * _.chunk(['a', 'b', 'c', 'd'], 2);
  21705. * // => [['a', 'b'], ['c', 'd']]
  21706. *
  21707. * _.chunk(['a', 'b', 'c', 'd'], 3);
  21708. * // => [['a', 'b', 'c'], ['d']]
  21709. */
  21710. function chunk(array, size, guard) {
  21711. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  21712. size = 1;
  21713. } else {
  21714. size = nativeMax(toInteger(size), 0);
  21715. }
  21716. var length = array ? array.length : 0;
  21717. if (!length || size < 1) {
  21718. return [];
  21719. }
  21720. var index = 0,
  21721. resIndex = 0,
  21722. result = Array(nativeCeil(length / size));
  21723. while (index < length) {
  21724. result[resIndex++] = baseSlice(array, index, (index += size));
  21725. }
  21726. return result;
  21727. }
  21728. /**
  21729. * Creates an array with all falsey values removed. The values `false`, `null`,
  21730. * `0`, `""`, `undefined`, and `NaN` are falsey.
  21731. *
  21732. * @static
  21733. * @memberOf _
  21734. * @since 0.1.0
  21735. * @category Array
  21736. * @param {Array} array The array to compact.
  21737. * @returns {Array} Returns the new array of filtered values.
  21738. * @example
  21739. *
  21740. * _.compact([0, 1, false, 2, '', 3]);
  21741. * // => [1, 2, 3]
  21742. */
  21743. function compact(array) {
  21744. var index = -1,
  21745. length = array ? array.length : 0,
  21746. resIndex = 0,
  21747. result = [];
  21748. while (++index < length) {
  21749. var value = array[index];
  21750. if (value) {
  21751. result[resIndex++] = value;
  21752. }
  21753. }
  21754. return result;
  21755. }
  21756. /**
  21757. * Creates a new array concatenating `array` with any additional arrays
  21758. * and/or values.
  21759. *
  21760. * @static
  21761. * @memberOf _
  21762. * @since 4.0.0
  21763. * @category Array
  21764. * @param {Array} array The array to concatenate.
  21765. * @param {...*} [values] The values to concatenate.
  21766. * @returns {Array} Returns the new concatenated array.
  21767. * @example
  21768. *
  21769. * var array = [1];
  21770. * var other = _.concat(array, 2, [3], [[4]]);
  21771. *
  21772. * console.log(other);
  21773. * // => [1, 2, 3, [4]]
  21774. *
  21775. * console.log(array);
  21776. * // => [1]
  21777. */
  21778. function concat() {
  21779. var length = arguments.length,
  21780. args = Array(length ? length - 1 : 0),
  21781. array = arguments[0],
  21782. index = length;
  21783. while (index--) {
  21784. args[index - 1] = arguments[index];
  21785. }
  21786. return length
  21787. ? arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1))
  21788. : [];
  21789. }
  21790. /**
  21791. * Creates an array of unique `array` values not included in the other given
  21792. * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  21793. * for equality comparisons. The order of result values is determined by the
  21794. * order they occur in the first array.
  21795. *
  21796. * @static
  21797. * @memberOf _
  21798. * @since 0.1.0
  21799. * @category Array
  21800. * @param {Array} array The array to inspect.
  21801. * @param {...Array} [values] The values to exclude.
  21802. * @returns {Array} Returns the new array of filtered values.
  21803. * @see _.without, _.xor
  21804. * @example
  21805. *
  21806. * _.difference([2, 1], [2, 3]);
  21807. * // => [1]
  21808. */
  21809. var difference = rest(function(array, values) {
  21810. return isArrayLikeObject(array)
  21811. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  21812. : [];
  21813. });
  21814. /**
  21815. * This method is like `_.difference` except that it accepts `iteratee` which
  21816. * is invoked for each element of `array` and `values` to generate the criterion
  21817. * by which they're compared. Result values are chosen from the first array.
  21818. * The iteratee is invoked with one argument: (value).
  21819. *
  21820. * @static
  21821. * @memberOf _
  21822. * @since 4.0.0
  21823. * @category Array
  21824. * @param {Array} array The array to inspect.
  21825. * @param {...Array} [values] The values to exclude.
  21826. * @param {Array|Function|Object|string} [iteratee=_.identity]
  21827. * The iteratee invoked per element.
  21828. * @returns {Array} Returns the new array of filtered values.
  21829. * @example
  21830. *
  21831. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  21832. * // => [1.2]
  21833. *
  21834. * // The `_.property` iteratee shorthand.
  21835. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  21836. * // => [{ 'x': 2 }]
  21837. */
  21838. var differenceBy = rest(function(array, values) {
  21839. var iteratee = last(values);
  21840. if (isArrayLikeObject(iteratee)) {
  21841. iteratee = undefined;
  21842. }
  21843. return isArrayLikeObject(array)
  21844. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee))
  21845. : [];
  21846. });
  21847. /**
  21848. * This method is like `_.difference` except that it accepts `comparator`
  21849. * which is invoked to compare elements of `array` to `values`. Result values
  21850. * are chosen from the first array. The comparator is invoked with two arguments:
  21851. * (arrVal, othVal).
  21852. *
  21853. * @static
  21854. * @memberOf _
  21855. * @since 4.0.0
  21856. * @category Array
  21857. * @param {Array} array The array to inspect.
  21858. * @param {...Array} [values] The values to exclude.
  21859. * @param {Function} [comparator] The comparator invoked per element.
  21860. * @returns {Array} Returns the new array of filtered values.
  21861. * @example
  21862. *
  21863. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  21864. *
  21865. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  21866. * // => [{ 'x': 2, 'y': 1 }]
  21867. */
  21868. var differenceWith = rest(function(array, values) {
  21869. var comparator = last(values);
  21870. if (isArrayLikeObject(comparator)) {
  21871. comparator = undefined;
  21872. }
  21873. return isArrayLikeObject(array)
  21874. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  21875. : [];
  21876. });
  21877. /**
  21878. * Creates a slice of `array` with `n` elements dropped from the beginning.
  21879. *
  21880. * @static
  21881. * @memberOf _
  21882. * @since 0.5.0
  21883. * @category Array
  21884. * @param {Array} array The array to query.
  21885. * @param {number} [n=1] The number of elements to drop.
  21886. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  21887. * @returns {Array} Returns the slice of `array`.
  21888. * @example
  21889. *
  21890. * _.drop([1, 2, 3]);
  21891. * // => [2, 3]
  21892. *
  21893. * _.drop([1, 2, 3], 2);
  21894. * // => [3]
  21895. *
  21896. * _.drop([1, 2, 3], 5);
  21897. * // => []
  21898. *
  21899. * _.drop([1, 2, 3], 0);
  21900. * // => [1, 2, 3]
  21901. */
  21902. function drop(array, n, guard) {
  21903. var length = array ? array.length : 0;
  21904. if (!length) {
  21905. return [];
  21906. }
  21907. n = (guard || n === undefined) ? 1 : toInteger(n);
  21908. return baseSlice(array, n < 0 ? 0 : n, length);
  21909. }
  21910. /**
  21911. * Creates a slice of `array` with `n` elements dropped from the end.
  21912. *
  21913. * @static
  21914. * @memberOf _
  21915. * @since 3.0.0
  21916. * @category Array
  21917. * @param {Array} array The array to query.
  21918. * @param {number} [n=1] The number of elements to drop.
  21919. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  21920. * @returns {Array} Returns the slice of `array`.
  21921. * @example
  21922. *
  21923. * _.dropRight([1, 2, 3]);
  21924. * // => [1, 2]
  21925. *
  21926. * _.dropRight([1, 2, 3], 2);
  21927. * // => [1]
  21928. *
  21929. * _.dropRight([1, 2, 3], 5);
  21930. * // => []
  21931. *
  21932. * _.dropRight([1, 2, 3], 0);
  21933. * // => [1, 2, 3]
  21934. */
  21935. function dropRight(array, n, guard) {
  21936. var length = array ? array.length : 0;
  21937. if (!length) {
  21938. return [];
  21939. }
  21940. n = (guard || n === undefined) ? 1 : toInteger(n);
  21941. n = length - n;
  21942. return baseSlice(array, 0, n < 0 ? 0 : n);
  21943. }
  21944. /**
  21945. * Creates a slice of `array` excluding elements dropped from the end.
  21946. * Elements are dropped until `predicate` returns falsey. The predicate is
  21947. * invoked with three arguments: (value, index, array).
  21948. *
  21949. * @static
  21950. * @memberOf _
  21951. * @since 3.0.0
  21952. * @category Array
  21953. * @param {Array} array The array to query.
  21954. * @param {Array|Function|Object|string} [predicate=_.identity]
  21955. * The function invoked per iteration.
  21956. * @returns {Array} Returns the slice of `array`.
  21957. * @example
  21958. *
  21959. * var users = [
  21960. * { 'user': 'barney', 'active': true },
  21961. * { 'user': 'fred', 'active': false },
  21962. * { 'user': 'pebbles', 'active': false }
  21963. * ];
  21964. *
  21965. * _.dropRightWhile(users, function(o) { return !o.active; });
  21966. * // => objects for ['barney']
  21967. *
  21968. * // The `_.matches` iteratee shorthand.
  21969. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  21970. * // => objects for ['barney', 'fred']
  21971. *
  21972. * // The `_.matchesProperty` iteratee shorthand.
  21973. * _.dropRightWhile(users, ['active', false]);
  21974. * // => objects for ['barney']
  21975. *
  21976. * // The `_.property` iteratee shorthand.
  21977. * _.dropRightWhile(users, 'active');
  21978. * // => objects for ['barney', 'fred', 'pebbles']
  21979. */
  21980. function dropRightWhile(array, predicate) {
  21981. return (array && array.length)
  21982. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  21983. : [];
  21984. }
  21985. /**
  21986. * Creates a slice of `array` excluding elements dropped from the beginning.
  21987. * Elements are dropped until `predicate` returns falsey. The predicate is
  21988. * invoked with three arguments: (value, index, array).
  21989. *
  21990. * @static
  21991. * @memberOf _
  21992. * @since 3.0.0
  21993. * @category Array
  21994. * @param {Array} array The array to query.
  21995. * @param {Array|Function|Object|string} [predicate=_.identity]
  21996. * The function invoked per iteration.
  21997. * @returns {Array} Returns the slice of `array`.
  21998. * @example
  21999. *
  22000. * var users = [
  22001. * { 'user': 'barney', 'active': false },
  22002. * { 'user': 'fred', 'active': false },
  22003. * { 'user': 'pebbles', 'active': true }
  22004. * ];
  22005. *
  22006. * _.dropWhile(users, function(o) { return !o.active; });
  22007. * // => objects for ['pebbles']
  22008. *
  22009. * // The `_.matches` iteratee shorthand.
  22010. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  22011. * // => objects for ['fred', 'pebbles']
  22012. *
  22013. * // The `_.matchesProperty` iteratee shorthand.
  22014. * _.dropWhile(users, ['active', false]);
  22015. * // => objects for ['pebbles']
  22016. *
  22017. * // The `_.property` iteratee shorthand.
  22018. * _.dropWhile(users, 'active');
  22019. * // => objects for ['barney', 'fred', 'pebbles']
  22020. */
  22021. function dropWhile(array, predicate) {
  22022. return (array && array.length)
  22023. ? baseWhile(array, getIteratee(predicate, 3), true)
  22024. : [];
  22025. }
  22026. /**
  22027. * Fills elements of `array` with `value` from `start` up to, but not
  22028. * including, `end`.
  22029. *
  22030. * **Note:** This method mutates `array`.
  22031. *
  22032. * @static
  22033. * @memberOf _
  22034. * @since 3.2.0
  22035. * @category Array
  22036. * @param {Array} array The array to fill.
  22037. * @param {*} value The value to fill `array` with.
  22038. * @param {number} [start=0] The start position.
  22039. * @param {number} [end=array.length] The end position.
  22040. * @returns {Array} Returns `array`.
  22041. * @example
  22042. *
  22043. * var array = [1, 2, 3];
  22044. *
  22045. * _.fill(array, 'a');
  22046. * console.log(array);
  22047. * // => ['a', 'a', 'a']
  22048. *
  22049. * _.fill(Array(3), 2);
  22050. * // => [2, 2, 2]
  22051. *
  22052. * _.fill([4, 6, 8, 10], '*', 1, 3);
  22053. * // => [4, '*', '*', 10]
  22054. */
  22055. function fill(array, value, start, end) {
  22056. var length = array ? array.length : 0;
  22057. if (!length) {
  22058. return [];
  22059. }
  22060. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  22061. start = 0;
  22062. end = length;
  22063. }
  22064. return baseFill(array, value, start, end);
  22065. }
  22066. /**
  22067. * This method is like `_.find` except that it returns the index of the first
  22068. * element `predicate` returns truthy for instead of the element itself.
  22069. *
  22070. * @static
  22071. * @memberOf _
  22072. * @since 1.1.0
  22073. * @category Array
  22074. * @param {Array} array The array to search.
  22075. * @param {Array|Function|Object|string} [predicate=_.identity]
  22076. * The function invoked per iteration.
  22077. * @param {number} [fromIndex=0] The index to search from.
  22078. * @returns {number} Returns the index of the found element, else `-1`.
  22079. * @example
  22080. *
  22081. * var users = [
  22082. * { 'user': 'barney', 'active': false },
  22083. * { 'user': 'fred', 'active': false },
  22084. * { 'user': 'pebbles', 'active': true }
  22085. * ];
  22086. *
  22087. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  22088. * // => 0
  22089. *
  22090. * // The `_.matches` iteratee shorthand.
  22091. * _.findIndex(users, { 'user': 'fred', 'active': false });
  22092. * // => 1
  22093. *
  22094. * // The `_.matchesProperty` iteratee shorthand.
  22095. * _.findIndex(users, ['active', false]);
  22096. * // => 0
  22097. *
  22098. * // The `_.property` iteratee shorthand.
  22099. * _.findIndex(users, 'active');
  22100. * // => 2
  22101. */
  22102. function findIndex(array, predicate, fromIndex) {
  22103. var length = array ? array.length : 0;
  22104. if (!length) {
  22105. return -1;
  22106. }
  22107. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  22108. if (index < 0) {
  22109. index = nativeMax(length + index, 0);
  22110. }
  22111. return baseFindIndex(array, getIteratee(predicate, 3), index);
  22112. }
  22113. /**
  22114. * This method is like `_.findIndex` except that it iterates over elements
  22115. * of `collection` from right to left.
  22116. *
  22117. * @static
  22118. * @memberOf _
  22119. * @since 2.0.0
  22120. * @category Array
  22121. * @param {Array} array The array to search.
  22122. * @param {Array|Function|Object|string} [predicate=_.identity]
  22123. * The function invoked per iteration.
  22124. * @param {number} [fromIndex=array.length-1] The index to search from.
  22125. * @returns {number} Returns the index of the found element, else `-1`.
  22126. * @example
  22127. *
  22128. * var users = [
  22129. * { 'user': 'barney', 'active': true },
  22130. * { 'user': 'fred', 'active': false },
  22131. * { 'user': 'pebbles', 'active': false }
  22132. * ];
  22133. *
  22134. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  22135. * // => 2
  22136. *
  22137. * // The `_.matches` iteratee shorthand.
  22138. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  22139. * // => 0
  22140. *
  22141. * // The `_.matchesProperty` iteratee shorthand.
  22142. * _.findLastIndex(users, ['active', false]);
  22143. * // => 2
  22144. *
  22145. * // The `_.property` iteratee shorthand.
  22146. * _.findLastIndex(users, 'active');
  22147. * // => 0
  22148. */
  22149. function findLastIndex(array, predicate, fromIndex) {
  22150. var length = array ? array.length : 0;
  22151. if (!length) {
  22152. return -1;
  22153. }
  22154. var index = length - 1;
  22155. if (fromIndex !== undefined) {
  22156. index = toInteger(fromIndex);
  22157. index = fromIndex < 0
  22158. ? nativeMax(length + index, 0)
  22159. : nativeMin(index, length - 1);
  22160. }
  22161. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  22162. }
  22163. /**
  22164. * Flattens `array` a single level deep.
  22165. *
  22166. * @static
  22167. * @memberOf _
  22168. * @since 0.1.0
  22169. * @category Array
  22170. * @param {Array} array The array to flatten.
  22171. * @returns {Array} Returns the new flattened array.
  22172. * @example
  22173. *
  22174. * _.flatten([1, [2, [3, [4]], 5]]);
  22175. * // => [1, 2, [3, [4]], 5]
  22176. */
  22177. function flatten(array) {
  22178. var length = array ? array.length : 0;
  22179. return length ? baseFlatten(array, 1) : [];
  22180. }
  22181. /**
  22182. * Recursively flattens `array`.
  22183. *
  22184. * @static
  22185. * @memberOf _
  22186. * @since 3.0.0
  22187. * @category Array
  22188. * @param {Array} array The array to flatten.
  22189. * @returns {Array} Returns the new flattened array.
  22190. * @example
  22191. *
  22192. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  22193. * // => [1, 2, 3, 4, 5]
  22194. */
  22195. function flattenDeep(array) {
  22196. var length = array ? array.length : 0;
  22197. return length ? baseFlatten(array, INFINITY) : [];
  22198. }
  22199. /**
  22200. * Recursively flatten `array` up to `depth` times.
  22201. *
  22202. * @static
  22203. * @memberOf _
  22204. * @since 4.4.0
  22205. * @category Array
  22206. * @param {Array} array The array to flatten.
  22207. * @param {number} [depth=1] The maximum recursion depth.
  22208. * @returns {Array} Returns the new flattened array.
  22209. * @example
  22210. *
  22211. * var array = [1, [2, [3, [4]], 5]];
  22212. *
  22213. * _.flattenDepth(array, 1);
  22214. * // => [1, 2, [3, [4]], 5]
  22215. *
  22216. * _.flattenDepth(array, 2);
  22217. * // => [1, 2, 3, [4], 5]
  22218. */
  22219. function flattenDepth(array, depth) {
  22220. var length = array ? array.length : 0;
  22221. if (!length) {
  22222. return [];
  22223. }
  22224. depth = depth === undefined ? 1 : toInteger(depth);
  22225. return baseFlatten(array, depth);
  22226. }
  22227. /**
  22228. * The inverse of `_.toPairs`; this method returns an object composed
  22229. * from key-value `pairs`.
  22230. *
  22231. * @static
  22232. * @memberOf _
  22233. * @since 4.0.0
  22234. * @category Array
  22235. * @param {Array} pairs The key-value pairs.
  22236. * @returns {Object} Returns the new object.
  22237. * @example
  22238. *
  22239. * _.fromPairs([['fred', 30], ['barney', 40]]);
  22240. * // => { 'fred': 30, 'barney': 40 }
  22241. */
  22242. function fromPairs(pairs) {
  22243. var index = -1,
  22244. length = pairs ? pairs.length : 0,
  22245. result = {};
  22246. while (++index < length) {
  22247. var pair = pairs[index];
  22248. result[pair[0]] = pair[1];
  22249. }
  22250. return result;
  22251. }
  22252. /**
  22253. * Gets the first element of `array`.
  22254. *
  22255. * @static
  22256. * @memberOf _
  22257. * @since 0.1.0
  22258. * @alias first
  22259. * @category Array
  22260. * @param {Array} array The array to query.
  22261. * @returns {*} Returns the first element of `array`.
  22262. * @example
  22263. *
  22264. * _.head([1, 2, 3]);
  22265. * // => 1
  22266. *
  22267. * _.head([]);
  22268. * // => undefined
  22269. */
  22270. function head(array) {
  22271. return (array && array.length) ? array[0] : undefined;
  22272. }
  22273. /**
  22274. * Gets the index at which the first occurrence of `value` is found in `array`
  22275. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  22276. * for equality comparisons. If `fromIndex` is negative, it's used as the
  22277. * offset from the end of `array`.
  22278. *
  22279. * @static
  22280. * @memberOf _
  22281. * @since 0.1.0
  22282. * @category Array
  22283. * @param {Array} array The array to search.
  22284. * @param {*} value The value to search for.
  22285. * @param {number} [fromIndex=0] The index to search from.
  22286. * @returns {number} Returns the index of the matched value, else `-1`.
  22287. * @example
  22288. *
  22289. * _.indexOf([1, 2, 1, 2], 2);
  22290. * // => 1
  22291. *
  22292. * // Search from the `fromIndex`.
  22293. * _.indexOf([1, 2, 1, 2], 2, 2);
  22294. * // => 3
  22295. */
  22296. function indexOf(array, value, fromIndex) {
  22297. var length = array ? array.length : 0;
  22298. if (!length) {
  22299. return -1;
  22300. }
  22301. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  22302. if (index < 0) {
  22303. index = nativeMax(length + index, 0);
  22304. }
  22305. return baseIndexOf(array, value, index);
  22306. }
  22307. /**
  22308. * Gets all but the last element of `array`.
  22309. *
  22310. * @static
  22311. * @memberOf _
  22312. * @since 0.1.0
  22313. * @category Array
  22314. * @param {Array} array The array to query.
  22315. * @returns {Array} Returns the slice of `array`.
  22316. * @example
  22317. *
  22318. * _.initial([1, 2, 3]);
  22319. * // => [1, 2]
  22320. */
  22321. function initial(array) {
  22322. return dropRight(array, 1);
  22323. }
  22324. /**
  22325. * Creates an array of unique values that are included in all given arrays
  22326. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  22327. * for equality comparisons. The order of result values is determined by the
  22328. * order they occur in the first array.
  22329. *
  22330. * @static
  22331. * @memberOf _
  22332. * @since 0.1.0
  22333. * @category Array
  22334. * @param {...Array} [arrays] The arrays to inspect.
  22335. * @returns {Array} Returns the new array of intersecting values.
  22336. * @example
  22337. *
  22338. * _.intersection([2, 1], [2, 3]);
  22339. * // => [2]
  22340. */
  22341. var intersection = rest(function(arrays) {
  22342. var mapped = arrayMap(arrays, castArrayLikeObject);
  22343. return (mapped.length && mapped[0] === arrays[0])
  22344. ? baseIntersection(mapped)
  22345. : [];
  22346. });
  22347. /**
  22348. * This method is like `_.intersection` except that it accepts `iteratee`
  22349. * which is invoked for each element of each `arrays` to generate the criterion
  22350. * by which they're compared. Result values are chosen from the first array.
  22351. * The iteratee is invoked with one argument: (value).
  22352. *
  22353. * @static
  22354. * @memberOf _
  22355. * @since 4.0.0
  22356. * @category Array
  22357. * @param {...Array} [arrays] The arrays to inspect.
  22358. * @param {Array|Function|Object|string} [iteratee=_.identity]
  22359. * The iteratee invoked per element.
  22360. * @returns {Array} Returns the new array of intersecting values.
  22361. * @example
  22362. *
  22363. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  22364. * // => [2.1]
  22365. *
  22366. * // The `_.property` iteratee shorthand.
  22367. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  22368. * // => [{ 'x': 1 }]
  22369. */
  22370. var intersectionBy = rest(function(arrays) {
  22371. var iteratee = last(arrays),
  22372. mapped = arrayMap(arrays, castArrayLikeObject);
  22373. if (iteratee === last(mapped)) {
  22374. iteratee = undefined;
  22375. } else {
  22376. mapped.pop();
  22377. }
  22378. return (mapped.length && mapped[0] === arrays[0])
  22379. ? baseIntersection(mapped, getIteratee(iteratee))
  22380. : [];
  22381. });
  22382. /**
  22383. * This method is like `_.intersection` except that it accepts `comparator`
  22384. * which is invoked to compare elements of `arrays`. Result values are chosen
  22385. * from the first array. The comparator is invoked with two arguments:
  22386. * (arrVal, othVal).
  22387. *
  22388. * @static
  22389. * @memberOf _
  22390. * @since 4.0.0
  22391. * @category Array
  22392. * @param {...Array} [arrays] The arrays to inspect.
  22393. * @param {Function} [comparator] The comparator invoked per element.
  22394. * @returns {Array} Returns the new array of intersecting values.
  22395. * @example
  22396. *
  22397. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  22398. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  22399. *
  22400. * _.intersectionWith(objects, others, _.isEqual);
  22401. * // => [{ 'x': 1, 'y': 2 }]
  22402. */
  22403. var intersectionWith = rest(function(arrays) {
  22404. var comparator = last(arrays),
  22405. mapped = arrayMap(arrays, castArrayLikeObject);
  22406. if (comparator === last(mapped)) {
  22407. comparator = undefined;
  22408. } else {
  22409. mapped.pop();
  22410. }
  22411. return (mapped.length && mapped[0] === arrays[0])
  22412. ? baseIntersection(mapped, undefined, comparator)
  22413. : [];
  22414. });
  22415. /**
  22416. * Converts all elements in `array` into a string separated by `separator`.
  22417. *
  22418. * @static
  22419. * @memberOf _
  22420. * @since 4.0.0
  22421. * @category Array
  22422. * @param {Array} array The array to convert.
  22423. * @param {string} [separator=','] The element separator.
  22424. * @returns {string} Returns the joined string.
  22425. * @example
  22426. *
  22427. * _.join(['a', 'b', 'c'], '~');
  22428. * // => 'a~b~c'
  22429. */
  22430. function join(array, separator) {
  22431. return array ? nativeJoin.call(array, separator) : '';
  22432. }
  22433. /**
  22434. * Gets the last element of `array`.
  22435. *
  22436. * @static
  22437. * @memberOf _
  22438. * @since 0.1.0
  22439. * @category Array
  22440. * @param {Array} array The array to query.
  22441. * @returns {*} Returns the last element of `array`.
  22442. * @example
  22443. *
  22444. * _.last([1, 2, 3]);
  22445. * // => 3
  22446. */
  22447. function last(array) {
  22448. var length = array ? array.length : 0;
  22449. return length ? array[length - 1] : undefined;
  22450. }
  22451. /**
  22452. * This method is like `_.indexOf` except that it iterates over elements of
  22453. * `array` from right to left.
  22454. *
  22455. * @static
  22456. * @memberOf _
  22457. * @since 0.1.0
  22458. * @category Array
  22459. * @param {Array} array The array to search.
  22460. * @param {*} value The value to search for.
  22461. * @param {number} [fromIndex=array.length-1] The index to search from.
  22462. * @returns {number} Returns the index of the matched value, else `-1`.
  22463. * @example
  22464. *
  22465. * _.lastIndexOf([1, 2, 1, 2], 2);
  22466. * // => 3
  22467. *
  22468. * // Search from the `fromIndex`.
  22469. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  22470. * // => 1
  22471. */
  22472. function lastIndexOf(array, value, fromIndex) {
  22473. var length = array ? array.length : 0;
  22474. if (!length) {
  22475. return -1;
  22476. }
  22477. var index = length;
  22478. if (fromIndex !== undefined) {
  22479. index = toInteger(fromIndex);
  22480. index = (
  22481. index < 0
  22482. ? nativeMax(length + index, 0)
  22483. : nativeMin(index, length - 1)
  22484. ) + 1;
  22485. }
  22486. if (value !== value) {
  22487. return indexOfNaN(array, index - 1, true);
  22488. }
  22489. while (index--) {
  22490. if (array[index] === value) {
  22491. return index;
  22492. }
  22493. }
  22494. return -1;
  22495. }
  22496. /**
  22497. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  22498. * element from the end is returned.
  22499. *
  22500. * @static
  22501. * @memberOf _
  22502. * @since 4.11.0
  22503. * @category Array
  22504. * @param {Array} array The array to query.
  22505. * @param {number} [n=0] The index of the element to return.
  22506. * @returns {*} Returns the nth element of `array`.
  22507. * @example
  22508. *
  22509. * var array = ['a', 'b', 'c', 'd'];
  22510. *
  22511. * _.nth(array, 1);
  22512. * // => 'b'
  22513. *
  22514. * _.nth(array, -2);
  22515. * // => 'c';
  22516. */
  22517. function nth(array, n) {
  22518. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  22519. }
  22520. /**
  22521. * Removes all given values from `array` using
  22522. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  22523. * for equality comparisons.
  22524. *
  22525. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  22526. * to remove elements from an array by predicate.
  22527. *
  22528. * @static
  22529. * @memberOf _
  22530. * @since 2.0.0
  22531. * @category Array
  22532. * @param {Array} array The array to modify.
  22533. * @param {...*} [values] The values to remove.
  22534. * @returns {Array} Returns `array`.
  22535. * @example
  22536. *
  22537. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  22538. *
  22539. * _.pull(array, 'a', 'c');
  22540. * console.log(array);
  22541. * // => ['b', 'b']
  22542. */
  22543. var pull = rest(pullAll);
  22544. /**
  22545. * This method is like `_.pull` except that it accepts an array of values to remove.
  22546. *
  22547. * **Note:** Unlike `_.difference`, this method mutates `array`.
  22548. *
  22549. * @static
  22550. * @memberOf _
  22551. * @since 4.0.0
  22552. * @category Array
  22553. * @param {Array} array The array to modify.
  22554. * @param {Array} values The values to remove.
  22555. * @returns {Array} Returns `array`.
  22556. * @example
  22557. *
  22558. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  22559. *
  22560. * _.pullAll(array, ['a', 'c']);
  22561. * console.log(array);
  22562. * // => ['b', 'b']
  22563. */
  22564. function pullAll(array, values) {
  22565. return (array && array.length && values && values.length)
  22566. ? basePullAll(array, values)
  22567. : array;
  22568. }
  22569. /**
  22570. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  22571. * invoked for each element of `array` and `values` to generate the criterion
  22572. * by which they're compared. The iteratee is invoked with one argument: (value).
  22573. *
  22574. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  22575. *
  22576. * @static
  22577. * @memberOf _
  22578. * @since 4.0.0
  22579. * @category Array
  22580. * @param {Array} array The array to modify.
  22581. * @param {Array} values The values to remove.
  22582. * @param {Array|Function|Object|string} [iteratee=_.identity]
  22583. * The iteratee invoked per element.
  22584. * @returns {Array} Returns `array`.
  22585. * @example
  22586. *
  22587. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  22588. *
  22589. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  22590. * console.log(array);
  22591. * // => [{ 'x': 2 }]
  22592. */
  22593. function pullAllBy(array, values, iteratee) {
  22594. return (array && array.length && values && values.length)
  22595. ? basePullAll(array, values, getIteratee(iteratee))
  22596. : array;
  22597. }
  22598. /**
  22599. * This method is like `_.pullAll` except that it accepts `comparator` which
  22600. * is invoked to compare elements of `array` to `values`. The comparator is
  22601. * invoked with two arguments: (arrVal, othVal).
  22602. *
  22603. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  22604. *
  22605. * @static
  22606. * @memberOf _
  22607. * @since 4.6.0
  22608. * @category Array
  22609. * @param {Array} array The array to modify.
  22610. * @param {Array} values The values to remove.
  22611. * @param {Function} [comparator] The comparator invoked per element.
  22612. * @returns {Array} Returns `array`.
  22613. * @example
  22614. *
  22615. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  22616. *
  22617. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  22618. * console.log(array);
  22619. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  22620. */
  22621. function pullAllWith(array, values, comparator) {
  22622. return (array && array.length && values && values.length)
  22623. ? basePullAll(array, values, undefined, comparator)
  22624. : array;
  22625. }
  22626. /**
  22627. * Removes elements from `array` corresponding to `indexes` and returns an
  22628. * array of removed elements.
  22629. *
  22630. * **Note:** Unlike `_.at`, this method mutates `array`.
  22631. *
  22632. * @static
  22633. * @memberOf _
  22634. * @since 3.0.0
  22635. * @category Array
  22636. * @param {Array} array The array to modify.
  22637. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  22638. * @returns {Array} Returns the new array of removed elements.
  22639. * @example
  22640. *
  22641. * var array = ['a', 'b', 'c', 'd'];
  22642. * var pulled = _.pullAt(array, [1, 3]);
  22643. *
  22644. * console.log(array);
  22645. * // => ['a', 'c']
  22646. *
  22647. * console.log(pulled);
  22648. * // => ['b', 'd']
  22649. */
  22650. var pullAt = rest(function(array, indexes) {
  22651. indexes = baseFlatten(indexes, 1);
  22652. var length = array ? array.length : 0,
  22653. result = baseAt(array, indexes);
  22654. basePullAt(array, arrayMap(indexes, function(index) {
  22655. return isIndex(index, length) ? +index : index;
  22656. }).sort(compareAscending));
  22657. return result;
  22658. });
  22659. /**
  22660. * Removes all elements from `array` that `predicate` returns truthy for
  22661. * and returns an array of the removed elements. The predicate is invoked
  22662. * with three arguments: (value, index, array).
  22663. *
  22664. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  22665. * to pull elements from an array by value.
  22666. *
  22667. * @static
  22668. * @memberOf _
  22669. * @since 2.0.0
  22670. * @category Array
  22671. * @param {Array} array The array to modify.
  22672. * @param {Array|Function|Object|string} [predicate=_.identity]
  22673. * The function invoked per iteration.
  22674. * @returns {Array} Returns the new array of removed elements.
  22675. * @example
  22676. *
  22677. * var array = [1, 2, 3, 4];
  22678. * var evens = _.remove(array, function(n) {
  22679. * return n % 2 == 0;
  22680. * });
  22681. *
  22682. * console.log(array);
  22683. * // => [1, 3]
  22684. *
  22685. * console.log(evens);
  22686. * // => [2, 4]
  22687. */
  22688. function remove(array, predicate) {
  22689. var result = [];
  22690. if (!(array && array.length)) {
  22691. return result;
  22692. }
  22693. var index = -1,
  22694. indexes = [],
  22695. length = array.length;
  22696. predicate = getIteratee(predicate, 3);
  22697. while (++index < length) {
  22698. var value = array[index];
  22699. if (predicate(value, index, array)) {
  22700. result.push(value);
  22701. indexes.push(index);
  22702. }
  22703. }
  22704. basePullAt(array, indexes);
  22705. return result;
  22706. }
  22707. /**
  22708. * Reverses `array` so that the first element becomes the last, the second
  22709. * element becomes the second to last, and so on.
  22710. *
  22711. * **Note:** This method mutates `array` and is based on
  22712. * [`Array#reverse`](https://mdn.io/Array/reverse).
  22713. *
  22714. * @static
  22715. * @memberOf _
  22716. * @since 4.0.0
  22717. * @category Array
  22718. * @param {Array} array The array to modify.
  22719. * @returns {Array} Returns `array`.
  22720. * @example
  22721. *
  22722. * var array = [1, 2, 3];
  22723. *
  22724. * _.reverse(array);
  22725. * // => [3, 2, 1]
  22726. *
  22727. * console.log(array);
  22728. * // => [3, 2, 1]
  22729. */
  22730. function reverse(array) {
  22731. return array ? nativeReverse.call(array) : array;
  22732. }
  22733. /**
  22734. * Creates a slice of `array` from `start` up to, but not including, `end`.
  22735. *
  22736. * **Note:** This method is used instead of
  22737. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  22738. * returned.
  22739. *
  22740. * @static
  22741. * @memberOf _
  22742. * @since 3.0.0
  22743. * @category Array
  22744. * @param {Array} array The array to slice.
  22745. * @param {number} [start=0] The start position.
  22746. * @param {number} [end=array.length] The end position.
  22747. * @returns {Array} Returns the slice of `array`.
  22748. */
  22749. function slice(array, start, end) {
  22750. var length = array ? array.length : 0;
  22751. if (!length) {
  22752. return [];
  22753. }
  22754. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  22755. start = 0;
  22756. end = length;
  22757. }
  22758. else {
  22759. start = start == null ? 0 : toInteger(start);
  22760. end = end === undefined ? length : toInteger(end);
  22761. }
  22762. return baseSlice(array, start, end);
  22763. }
  22764. /**
  22765. * Uses a binary search to determine the lowest index at which `value`
  22766. * should be inserted into `array` in order to maintain its sort order.
  22767. *
  22768. * @static
  22769. * @memberOf _
  22770. * @since 0.1.0
  22771. * @category Array
  22772. * @param {Array} array The sorted array to inspect.
  22773. * @param {*} value The value to evaluate.
  22774. * @returns {number} Returns the index at which `value` should be inserted
  22775. * into `array`.
  22776. * @example
  22777. *
  22778. * _.sortedIndex([30, 50], 40);
  22779. * // => 1
  22780. */
  22781. function sortedIndex(array, value) {
  22782. return baseSortedIndex(array, value);
  22783. }
  22784. /**
  22785. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  22786. * which is invoked for `value` and each element of `array` to compute their
  22787. * sort ranking. The iteratee is invoked with one argument: (value).
  22788. *
  22789. * @static
  22790. * @memberOf _
  22791. * @since 4.0.0
  22792. * @category Array
  22793. * @param {Array} array The sorted array to inspect.
  22794. * @param {*} value The value to evaluate.
  22795. * @param {Array|Function|Object|string} [iteratee=_.identity]
  22796. * The iteratee invoked per element.
  22797. * @returns {number} Returns the index at which `value` should be inserted
  22798. * into `array`.
  22799. * @example
  22800. *
  22801. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  22802. *
  22803. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  22804. * // => 0
  22805. *
  22806. * // The `_.property` iteratee shorthand.
  22807. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  22808. * // => 0
  22809. */
  22810. function sortedIndexBy(array, value, iteratee) {
  22811. return baseSortedIndexBy(array, value, getIteratee(iteratee));
  22812. }
  22813. /**
  22814. * This method is like `_.indexOf` except that it performs a binary
  22815. * search on a sorted `array`.
  22816. *
  22817. * @static
  22818. * @memberOf _
  22819. * @since 4.0.0
  22820. * @category Array
  22821. * @param {Array} array The array to search.
  22822. * @param {*} value The value to search for.
  22823. * @returns {number} Returns the index of the matched value, else `-1`.
  22824. * @example
  22825. *
  22826. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  22827. * // => 1
  22828. */
  22829. function sortedIndexOf(array, value) {
  22830. var length = array ? array.length : 0;
  22831. if (length) {
  22832. var index = baseSortedIndex(array, value);
  22833. if (index < length && eq(array[index], value)) {
  22834. return index;
  22835. }
  22836. }
  22837. return -1;
  22838. }
  22839. /**
  22840. * This method is like `_.sortedIndex` except that it returns the highest
  22841. * index at which `value` should be inserted into `array` in order to
  22842. * maintain its sort order.
  22843. *
  22844. * @static
  22845. * @memberOf _
  22846. * @since 3.0.0
  22847. * @category Array
  22848. * @param {Array} array The sorted array to inspect.
  22849. * @param {*} value The value to evaluate.
  22850. * @returns {number} Returns the index at which `value` should be inserted
  22851. * into `array`.
  22852. * @example
  22853. *
  22854. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  22855. * // => 4
  22856. */
  22857. function sortedLastIndex(array, value) {
  22858. return baseSortedIndex(array, value, true);
  22859. }
  22860. /**
  22861. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  22862. * which is invoked for `value` and each element of `array` to compute their
  22863. * sort ranking. The iteratee is invoked with one argument: (value).
  22864. *
  22865. * @static
  22866. * @memberOf _
  22867. * @since 4.0.0
  22868. * @category Array
  22869. * @param {Array} array The sorted array to inspect.
  22870. * @param {*} value The value to evaluate.
  22871. * @param {Array|Function|Object|string} [iteratee=_.identity]
  22872. * The iteratee invoked per element.
  22873. * @returns {number} Returns the index at which `value` should be inserted
  22874. * into `array`.
  22875. * @example
  22876. *
  22877. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  22878. *
  22879. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  22880. * // => 1
  22881. *
  22882. * // The `_.property` iteratee shorthand.
  22883. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  22884. * // => 1
  22885. */
  22886. function sortedLastIndexBy(array, value, iteratee) {
  22887. return baseSortedIndexBy(array, value, getIteratee(iteratee), true);
  22888. }
  22889. /**
  22890. * This method is like `_.lastIndexOf` except that it performs a binary
  22891. * search on a sorted `array`.
  22892. *
  22893. * @static
  22894. * @memberOf _
  22895. * @since 4.0.0
  22896. * @category Array
  22897. * @param {Array} array The array to search.
  22898. * @param {*} value The value to search for.
  22899. * @returns {number} Returns the index of the matched value, else `-1`.
  22900. * @example
  22901. *
  22902. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  22903. * // => 3
  22904. */
  22905. function sortedLastIndexOf(array, value) {
  22906. var length = array ? array.length : 0;
  22907. if (length) {
  22908. var index = baseSortedIndex(array, value, true) - 1;
  22909. if (eq(array[index], value)) {
  22910. return index;
  22911. }
  22912. }
  22913. return -1;
  22914. }
  22915. /**
  22916. * This method is like `_.uniq` except that it's designed and optimized
  22917. * for sorted arrays.
  22918. *
  22919. * @static
  22920. * @memberOf _
  22921. * @since 4.0.0
  22922. * @category Array
  22923. * @param {Array} array The array to inspect.
  22924. * @returns {Array} Returns the new duplicate free array.
  22925. * @example
  22926. *
  22927. * _.sortedUniq([1, 1, 2]);
  22928. * // => [1, 2]
  22929. */
  22930. function sortedUniq(array) {
  22931. return (array && array.length)
  22932. ? baseSortedUniq(array)
  22933. : [];
  22934. }
  22935. /**
  22936. * This method is like `_.uniqBy` except that it's designed and optimized
  22937. * for sorted arrays.
  22938. *
  22939. * @static
  22940. * @memberOf _
  22941. * @since 4.0.0
  22942. * @category Array
  22943. * @param {Array} array The array to inspect.
  22944. * @param {Function} [iteratee] The iteratee invoked per element.
  22945. * @returns {Array} Returns the new duplicate free array.
  22946. * @example
  22947. *
  22948. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  22949. * // => [1.1, 2.3]
  22950. */
  22951. function sortedUniqBy(array, iteratee) {
  22952. return (array && array.length)
  22953. ? baseSortedUniq(array, getIteratee(iteratee))
  22954. : [];
  22955. }
  22956. /**
  22957. * Gets all but the first element of `array`.
  22958. *
  22959. * @static
  22960. * @memberOf _
  22961. * @since 4.0.0
  22962. * @category Array
  22963. * @param {Array} array The array to query.
  22964. * @returns {Array} Returns the slice of `array`.
  22965. * @example
  22966. *
  22967. * _.tail([1, 2, 3]);
  22968. * // => [2, 3]
  22969. */
  22970. function tail(array) {
  22971. return drop(array, 1);
  22972. }
  22973. /**
  22974. * Creates a slice of `array` with `n` elements taken from the beginning.
  22975. *
  22976. * @static
  22977. * @memberOf _
  22978. * @since 0.1.0
  22979. * @category Array
  22980. * @param {Array} array The array to query.
  22981. * @param {number} [n=1] The number of elements to take.
  22982. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  22983. * @returns {Array} Returns the slice of `array`.
  22984. * @example
  22985. *
  22986. * _.take([1, 2, 3]);
  22987. * // => [1]
  22988. *
  22989. * _.take([1, 2, 3], 2);
  22990. * // => [1, 2]
  22991. *
  22992. * _.take([1, 2, 3], 5);
  22993. * // => [1, 2, 3]
  22994. *
  22995. * _.take([1, 2, 3], 0);
  22996. * // => []
  22997. */
  22998. function take(array, n, guard) {
  22999. if (!(array && array.length)) {
  23000. return [];
  23001. }
  23002. n = (guard || n === undefined) ? 1 : toInteger(n);
  23003. return baseSlice(array, 0, n < 0 ? 0 : n);
  23004. }
  23005. /**
  23006. * Creates a slice of `array` with `n` elements taken from the end.
  23007. *
  23008. * @static
  23009. * @memberOf _
  23010. * @since 3.0.0
  23011. * @category Array
  23012. * @param {Array} array The array to query.
  23013. * @param {number} [n=1] The number of elements to take.
  23014. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  23015. * @returns {Array} Returns the slice of `array`.
  23016. * @example
  23017. *
  23018. * _.takeRight([1, 2, 3]);
  23019. * // => [3]
  23020. *
  23021. * _.takeRight([1, 2, 3], 2);
  23022. * // => [2, 3]
  23023. *
  23024. * _.takeRight([1, 2, 3], 5);
  23025. * // => [1, 2, 3]
  23026. *
  23027. * _.takeRight([1, 2, 3], 0);
  23028. * // => []
  23029. */
  23030. function takeRight(array, n, guard) {
  23031. var length = array ? array.length : 0;
  23032. if (!length) {
  23033. return [];
  23034. }
  23035. n = (guard || n === undefined) ? 1 : toInteger(n);
  23036. n = length - n;
  23037. return baseSlice(array, n < 0 ? 0 : n, length);
  23038. }
  23039. /**
  23040. * Creates a slice of `array` with elements taken from the end. Elements are
  23041. * taken until `predicate` returns falsey. The predicate is invoked with
  23042. * three arguments: (value, index, array).
  23043. *
  23044. * @static
  23045. * @memberOf _
  23046. * @since 3.0.0
  23047. * @category Array
  23048. * @param {Array} array The array to query.
  23049. * @param {Array|Function|Object|string} [predicate=_.identity]
  23050. * The function invoked per iteration.
  23051. * @returns {Array} Returns the slice of `array`.
  23052. * @example
  23053. *
  23054. * var users = [
  23055. * { 'user': 'barney', 'active': true },
  23056. * { 'user': 'fred', 'active': false },
  23057. * { 'user': 'pebbles', 'active': false }
  23058. * ];
  23059. *
  23060. * _.takeRightWhile(users, function(o) { return !o.active; });
  23061. * // => objects for ['fred', 'pebbles']
  23062. *
  23063. * // The `_.matches` iteratee shorthand.
  23064. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  23065. * // => objects for ['pebbles']
  23066. *
  23067. * // The `_.matchesProperty` iteratee shorthand.
  23068. * _.takeRightWhile(users, ['active', false]);
  23069. * // => objects for ['fred', 'pebbles']
  23070. *
  23071. * // The `_.property` iteratee shorthand.
  23072. * _.takeRightWhile(users, 'active');
  23073. * // => []
  23074. */
  23075. function takeRightWhile(array, predicate) {
  23076. return (array && array.length)
  23077. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  23078. : [];
  23079. }
  23080. /**
  23081. * Creates a slice of `array` with elements taken from the beginning. Elements
  23082. * are taken until `predicate` returns falsey. The predicate is invoked with
  23083. * three arguments: (value, index, array).
  23084. *
  23085. * @static
  23086. * @memberOf _
  23087. * @since 3.0.0
  23088. * @category Array
  23089. * @param {Array} array The array to query.
  23090. * @param {Array|Function|Object|string} [predicate=_.identity]
  23091. * The function invoked per iteration.
  23092. * @returns {Array} Returns the slice of `array`.
  23093. * @example
  23094. *
  23095. * var users = [
  23096. * { 'user': 'barney', 'active': false },
  23097. * { 'user': 'fred', 'active': false},
  23098. * { 'user': 'pebbles', 'active': true }
  23099. * ];
  23100. *
  23101. * _.takeWhile(users, function(o) { return !o.active; });
  23102. * // => objects for ['barney', 'fred']
  23103. *
  23104. * // The `_.matches` iteratee shorthand.
  23105. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  23106. * // => objects for ['barney']
  23107. *
  23108. * // The `_.matchesProperty` iteratee shorthand.
  23109. * _.takeWhile(users, ['active', false]);
  23110. * // => objects for ['barney', 'fred']
  23111. *
  23112. * // The `_.property` iteratee shorthand.
  23113. * _.takeWhile(users, 'active');
  23114. * // => []
  23115. */
  23116. function takeWhile(array, predicate) {
  23117. return (array && array.length)
  23118. ? baseWhile(array, getIteratee(predicate, 3))
  23119. : [];
  23120. }
  23121. /**
  23122. * Creates an array of unique values, in order, from all given arrays using
  23123. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  23124. * for equality comparisons.
  23125. *
  23126. * @static
  23127. * @memberOf _
  23128. * @since 0.1.0
  23129. * @category Array
  23130. * @param {...Array} [arrays] The arrays to inspect.
  23131. * @returns {Array} Returns the new array of combined values.
  23132. * @example
  23133. *
  23134. * _.union([2], [1, 2]);
  23135. * // => [2, 1]
  23136. */
  23137. var union = rest(function(arrays) {
  23138. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  23139. });
  23140. /**
  23141. * This method is like `_.union` except that it accepts `iteratee` which is
  23142. * invoked for each element of each `arrays` to generate the criterion by
  23143. * which uniqueness is computed. The iteratee is invoked with one argument:
  23144. * (value).
  23145. *
  23146. * @static
  23147. * @memberOf _
  23148. * @since 4.0.0
  23149. * @category Array
  23150. * @param {...Array} [arrays] The arrays to inspect.
  23151. * @param {Array|Function|Object|string} [iteratee=_.identity]
  23152. * The iteratee invoked per element.
  23153. * @returns {Array} Returns the new array of combined values.
  23154. * @example
  23155. *
  23156. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  23157. * // => [2.1, 1.2]
  23158. *
  23159. * // The `_.property` iteratee shorthand.
  23160. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  23161. * // => [{ 'x': 1 }, { 'x': 2 }]
  23162. */
  23163. var unionBy = rest(function(arrays) {
  23164. var iteratee = last(arrays);
  23165. if (isArrayLikeObject(iteratee)) {
  23166. iteratee = undefined;
  23167. }
  23168. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee));
  23169. });
  23170. /**
  23171. * This method is like `_.union` except that it accepts `comparator` which
  23172. * is invoked to compare elements of `arrays`. The comparator is invoked
  23173. * with two arguments: (arrVal, othVal).
  23174. *
  23175. * @static
  23176. * @memberOf _
  23177. * @since 4.0.0
  23178. * @category Array
  23179. * @param {...Array} [arrays] The arrays to inspect.
  23180. * @param {Function} [comparator] The comparator invoked per element.
  23181. * @returns {Array} Returns the new array of combined values.
  23182. * @example
  23183. *
  23184. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  23185. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  23186. *
  23187. * _.unionWith(objects, others, _.isEqual);
  23188. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  23189. */
  23190. var unionWith = rest(function(arrays) {
  23191. var comparator = last(arrays);
  23192. if (isArrayLikeObject(comparator)) {
  23193. comparator = undefined;
  23194. }
  23195. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  23196. });
  23197. /**
  23198. * Creates a duplicate-free version of an array, using
  23199. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  23200. * for equality comparisons, in which only the first occurrence of each
  23201. * element is kept.
  23202. *
  23203. * @static
  23204. * @memberOf _
  23205. * @since 0.1.0
  23206. * @category Array
  23207. * @param {Array} array The array to inspect.
  23208. * @returns {Array} Returns the new duplicate free array.
  23209. * @example
  23210. *
  23211. * _.uniq([2, 1, 2]);
  23212. * // => [2, 1]
  23213. */
  23214. function uniq(array) {
  23215. return (array && array.length)
  23216. ? baseUniq(array)
  23217. : [];
  23218. }
  23219. /**
  23220. * This method is like `_.uniq` except that it accepts `iteratee` which is
  23221. * invoked for each element in `array` to generate the criterion by which
  23222. * uniqueness is computed. The iteratee is invoked with one argument: (value).
  23223. *
  23224. * @static
  23225. * @memberOf _
  23226. * @since 4.0.0
  23227. * @category Array
  23228. * @param {Array} array The array to inspect.
  23229. * @param {Array|Function|Object|string} [iteratee=_.identity]
  23230. * The iteratee invoked per element.
  23231. * @returns {Array} Returns the new duplicate free array.
  23232. * @example
  23233. *
  23234. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  23235. * // => [2.1, 1.2]
  23236. *
  23237. * // The `_.property` iteratee shorthand.
  23238. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  23239. * // => [{ 'x': 1 }, { 'x': 2 }]
  23240. */
  23241. function uniqBy(array, iteratee) {
  23242. return (array && array.length)
  23243. ? baseUniq(array, getIteratee(iteratee))
  23244. : [];
  23245. }
  23246. /**
  23247. * This method is like `_.uniq` except that it accepts `comparator` which
  23248. * is invoked to compare elements of `array`. The comparator is invoked with
  23249. * two arguments: (arrVal, othVal).
  23250. *
  23251. * @static
  23252. * @memberOf _
  23253. * @since 4.0.0
  23254. * @category Array
  23255. * @param {Array} array The array to inspect.
  23256. * @param {Function} [comparator] The comparator invoked per element.
  23257. * @returns {Array} Returns the new duplicate free array.
  23258. * @example
  23259. *
  23260. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  23261. *
  23262. * _.uniqWith(objects, _.isEqual);
  23263. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  23264. */
  23265. function uniqWith(array, comparator) {
  23266. return (array && array.length)
  23267. ? baseUniq(array, undefined, comparator)
  23268. : [];
  23269. }
  23270. /**
  23271. * This method is like `_.zip` except that it accepts an array of grouped
  23272. * elements and creates an array regrouping the elements to their pre-zip
  23273. * configuration.
  23274. *
  23275. * @static
  23276. * @memberOf _
  23277. * @since 1.2.0
  23278. * @category Array
  23279. * @param {Array} array The array of grouped elements to process.
  23280. * @returns {Array} Returns the new array of regrouped elements.
  23281. * @example
  23282. *
  23283. * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
  23284. * // => [['fred', 30, true], ['barney', 40, false]]
  23285. *
  23286. * _.unzip(zipped);
  23287. * // => [['fred', 'barney'], [30, 40], [true, false]]
  23288. */
  23289. function unzip(array) {
  23290. if (!(array && array.length)) {
  23291. return [];
  23292. }
  23293. var length = 0;
  23294. array = arrayFilter(array, function(group) {
  23295. if (isArrayLikeObject(group)) {
  23296. length = nativeMax(group.length, length);
  23297. return true;
  23298. }
  23299. });
  23300. return baseTimes(length, function(index) {
  23301. return arrayMap(array, baseProperty(index));
  23302. });
  23303. }
  23304. /**
  23305. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  23306. * how regrouped values should be combined. The iteratee is invoked with the
  23307. * elements of each group: (...group).
  23308. *
  23309. * @static
  23310. * @memberOf _
  23311. * @since 3.8.0
  23312. * @category Array
  23313. * @param {Array} array The array of grouped elements to process.
  23314. * @param {Function} [iteratee=_.identity] The function to combine
  23315. * regrouped values.
  23316. * @returns {Array} Returns the new array of regrouped elements.
  23317. * @example
  23318. *
  23319. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  23320. * // => [[1, 10, 100], [2, 20, 200]]
  23321. *
  23322. * _.unzipWith(zipped, _.add);
  23323. * // => [3, 30, 300]
  23324. */
  23325. function unzipWith(array, iteratee) {
  23326. if (!(array && array.length)) {
  23327. return [];
  23328. }
  23329. var result = unzip(array);
  23330. if (iteratee == null) {
  23331. return result;
  23332. }
  23333. return arrayMap(result, function(group) {
  23334. return apply(iteratee, undefined, group);
  23335. });
  23336. }
  23337. /**
  23338. * Creates an array excluding all given values using
  23339. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  23340. * for equality comparisons.
  23341. *
  23342. * @static
  23343. * @memberOf _
  23344. * @since 0.1.0
  23345. * @category Array
  23346. * @param {Array} array The array to inspect.
  23347. * @param {...*} [values] The values to exclude.
  23348. * @returns {Array} Returns the new array of filtered values.
  23349. * @see _.difference, _.xor
  23350. * @example
  23351. *
  23352. * _.without([2, 1, 2, 3], 1, 2);
  23353. * // => [3]
  23354. */
  23355. var without = rest(function(array, values) {
  23356. return isArrayLikeObject(array)
  23357. ? baseDifference(array, values)
  23358. : [];
  23359. });
  23360. /**
  23361. * Creates an array of unique values that is the
  23362. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  23363. * of the given arrays. The order of result values is determined by the order
  23364. * they occur in the arrays.
  23365. *
  23366. * @static
  23367. * @memberOf _
  23368. * @since 2.4.0
  23369. * @category Array
  23370. * @param {...Array} [arrays] The arrays to inspect.
  23371. * @returns {Array} Returns the new array of filtered values.
  23372. * @see _.difference, _.without
  23373. * @example
  23374. *
  23375. * _.xor([2, 1], [2, 3]);
  23376. * // => [1, 3]
  23377. */
  23378. var xor = rest(function(arrays) {
  23379. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  23380. });
  23381. /**
  23382. * This method is like `_.xor` except that it accepts `iteratee` which is
  23383. * invoked for each element of each `arrays` to generate the criterion by
  23384. * which by which they're compared. The iteratee is invoked with one argument:
  23385. * (value).
  23386. *
  23387. * @static
  23388. * @memberOf _
  23389. * @since 4.0.0
  23390. * @category Array
  23391. * @param {...Array} [arrays] The arrays to inspect.
  23392. * @param {Array|Function|Object|string} [iteratee=_.identity]
  23393. * The iteratee invoked per element.
  23394. * @returns {Array} Returns the new array of filtered values.
  23395. * @example
  23396. *
  23397. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  23398. * // => [1.2, 3.4]
  23399. *
  23400. * // The `_.property` iteratee shorthand.
  23401. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  23402. * // => [{ 'x': 2 }]
  23403. */
  23404. var xorBy = rest(function(arrays) {
  23405. var iteratee = last(arrays);
  23406. if (isArrayLikeObject(iteratee)) {
  23407. iteratee = undefined;
  23408. }
  23409. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee));
  23410. });
  23411. /**
  23412. * This method is like `_.xor` except that it accepts `comparator` which is
  23413. * invoked to compare elements of `arrays`. The comparator is invoked with
  23414. * two arguments: (arrVal, othVal).
  23415. *
  23416. * @static
  23417. * @memberOf _
  23418. * @since 4.0.0
  23419. * @category Array
  23420. * @param {...Array} [arrays] The arrays to inspect.
  23421. * @param {Function} [comparator] The comparator invoked per element.
  23422. * @returns {Array} Returns the new array of filtered values.
  23423. * @example
  23424. *
  23425. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  23426. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  23427. *
  23428. * _.xorWith(objects, others, _.isEqual);
  23429. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  23430. */
  23431. var xorWith = rest(function(arrays) {
  23432. var comparator = last(arrays);
  23433. if (isArrayLikeObject(comparator)) {
  23434. comparator = undefined;
  23435. }
  23436. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  23437. });
  23438. /**
  23439. * Creates an array of grouped elements, the first of which contains the
  23440. * first elements of the given arrays, the second of which contains the
  23441. * second elements of the given arrays, and so on.
  23442. *
  23443. * @static
  23444. * @memberOf _
  23445. * @since 0.1.0
  23446. * @category Array
  23447. * @param {...Array} [arrays] The arrays to process.
  23448. * @returns {Array} Returns the new array of grouped elements.
  23449. * @example
  23450. *
  23451. * _.zip(['fred', 'barney'], [30, 40], [true, false]);
  23452. * // => [['fred', 30, true], ['barney', 40, false]]
  23453. */
  23454. var zip = rest(unzip);
  23455. /**
  23456. * This method is like `_.fromPairs` except that it accepts two arrays,
  23457. * one of property identifiers and one of corresponding values.
  23458. *
  23459. * @static
  23460. * @memberOf _
  23461. * @since 0.4.0
  23462. * @category Array
  23463. * @param {Array} [props=[]] The property identifiers.
  23464. * @param {Array} [values=[]] The property values.
  23465. * @returns {Object} Returns the new object.
  23466. * @example
  23467. *
  23468. * _.zipObject(['a', 'b'], [1, 2]);
  23469. * // => { 'a': 1, 'b': 2 }
  23470. */
  23471. function zipObject(props, values) {
  23472. return baseZipObject(props || [], values || [], assignValue);
  23473. }
  23474. /**
  23475. * This method is like `_.zipObject` except that it supports property paths.
  23476. *
  23477. * @static
  23478. * @memberOf _
  23479. * @since 4.1.0
  23480. * @category Array
  23481. * @param {Array} [props=[]] The property identifiers.
  23482. * @param {Array} [values=[]] The property values.
  23483. * @returns {Object} Returns the new object.
  23484. * @example
  23485. *
  23486. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  23487. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  23488. */
  23489. function zipObjectDeep(props, values) {
  23490. return baseZipObject(props || [], values || [], baseSet);
  23491. }
  23492. /**
  23493. * This method is like `_.zip` except that it accepts `iteratee` to specify
  23494. * how grouped values should be combined. The iteratee is invoked with the
  23495. * elements of each group: (...group).
  23496. *
  23497. * @static
  23498. * @memberOf _
  23499. * @since 3.8.0
  23500. * @category Array
  23501. * @param {...Array} [arrays] The arrays to process.
  23502. * @param {Function} [iteratee=_.identity] The function to combine grouped values.
  23503. * @returns {Array} Returns the new array of grouped elements.
  23504. * @example
  23505. *
  23506. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  23507. * return a + b + c;
  23508. * });
  23509. * // => [111, 222]
  23510. */
  23511. var zipWith = rest(function(arrays) {
  23512. var length = arrays.length,
  23513. iteratee = length > 1 ? arrays[length - 1] : undefined;
  23514. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  23515. return unzipWith(arrays, iteratee);
  23516. });
  23517. /*------------------------------------------------------------------------*/
  23518. /**
  23519. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  23520. * chain sequences enabled. The result of such sequences must be unwrapped
  23521. * with `_#value`.
  23522. *
  23523. * @static
  23524. * @memberOf _
  23525. * @since 1.3.0
  23526. * @category Seq
  23527. * @param {*} value The value to wrap.
  23528. * @returns {Object} Returns the new `lodash` wrapper instance.
  23529. * @example
  23530. *
  23531. * var users = [
  23532. * { 'user': 'barney', 'age': 36 },
  23533. * { 'user': 'fred', 'age': 40 },
  23534. * { 'user': 'pebbles', 'age': 1 }
  23535. * ];
  23536. *
  23537. * var youngest = _
  23538. * .chain(users)
  23539. * .sortBy('age')
  23540. * .map(function(o) {
  23541. * return o.user + ' is ' + o.age;
  23542. * })
  23543. * .head()
  23544. * .value();
  23545. * // => 'pebbles is 1'
  23546. */
  23547. function chain(value) {
  23548. var result = lodash(value);
  23549. result.__chain__ = true;
  23550. return result;
  23551. }
  23552. /**
  23553. * This method invokes `interceptor` and returns `value`. The interceptor
  23554. * is invoked with one argument; (value). The purpose of this method is to
  23555. * "tap into" a method chain sequence in order to modify intermediate results.
  23556. *
  23557. * @static
  23558. * @memberOf _
  23559. * @since 0.1.0
  23560. * @category Seq
  23561. * @param {*} value The value to provide to `interceptor`.
  23562. * @param {Function} interceptor The function to invoke.
  23563. * @returns {*} Returns `value`.
  23564. * @example
  23565. *
  23566. * _([1, 2, 3])
  23567. * .tap(function(array) {
  23568. * // Mutate input array.
  23569. * array.pop();
  23570. * })
  23571. * .reverse()
  23572. * .value();
  23573. * // => [2, 1]
  23574. */
  23575. function tap(value, interceptor) {
  23576. interceptor(value);
  23577. return value;
  23578. }
  23579. /**
  23580. * This method is like `_.tap` except that it returns the result of `interceptor`.
  23581. * The purpose of this method is to "pass thru" values replacing intermediate
  23582. * results in a method chain sequence.
  23583. *
  23584. * @static
  23585. * @memberOf _
  23586. * @since 3.0.0
  23587. * @category Seq
  23588. * @param {*} value The value to provide to `interceptor`.
  23589. * @param {Function} interceptor The function to invoke.
  23590. * @returns {*} Returns the result of `interceptor`.
  23591. * @example
  23592. *
  23593. * _(' abc ')
  23594. * .chain()
  23595. * .trim()
  23596. * .thru(function(value) {
  23597. * return [value];
  23598. * })
  23599. * .value();
  23600. * // => ['abc']
  23601. */
  23602. function thru(value, interceptor) {
  23603. return interceptor(value);
  23604. }
  23605. /**
  23606. * This method is the wrapper version of `_.at`.
  23607. *
  23608. * @name at
  23609. * @memberOf _
  23610. * @since 1.0.0
  23611. * @category Seq
  23612. * @param {...(string|string[])} [paths] The property paths of elements to pick.
  23613. * @returns {Object} Returns the new `lodash` wrapper instance.
  23614. * @example
  23615. *
  23616. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  23617. *
  23618. * _(object).at(['a[0].b.c', 'a[1]']).value();
  23619. * // => [3, 4]
  23620. */
  23621. var wrapperAt = rest(function(paths) {
  23622. paths = baseFlatten(paths, 1);
  23623. var length = paths.length,
  23624. start = length ? paths[0] : 0,
  23625. value = this.__wrapped__,
  23626. interceptor = function(object) { return baseAt(object, paths); };
  23627. if (length > 1 || this.__actions__.length ||
  23628. !(value instanceof LazyWrapper) || !isIndex(start)) {
  23629. return this.thru(interceptor);
  23630. }
  23631. value = value.slice(start, +start + (length ? 1 : 0));
  23632. value.__actions__.push({
  23633. 'func': thru,
  23634. 'args': [interceptor],
  23635. 'thisArg': undefined
  23636. });
  23637. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  23638. if (length && !array.length) {
  23639. array.push(undefined);
  23640. }
  23641. return array;
  23642. });
  23643. });
  23644. /**
  23645. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  23646. *
  23647. * @name chain
  23648. * @memberOf _
  23649. * @since 0.1.0
  23650. * @category Seq
  23651. * @returns {Object} Returns the new `lodash` wrapper instance.
  23652. * @example
  23653. *
  23654. * var users = [
  23655. * { 'user': 'barney', 'age': 36 },
  23656. * { 'user': 'fred', 'age': 40 }
  23657. * ];
  23658. *
  23659. * // A sequence without explicit chaining.
  23660. * _(users).head();
  23661. * // => { 'user': 'barney', 'age': 36 }
  23662. *
  23663. * // A sequence with explicit chaining.
  23664. * _(users)
  23665. * .chain()
  23666. * .head()
  23667. * .pick('user')
  23668. * .value();
  23669. * // => { 'user': 'barney' }
  23670. */
  23671. function wrapperChain() {
  23672. return chain(this);
  23673. }
  23674. /**
  23675. * Executes the chain sequence and returns the wrapped result.
  23676. *
  23677. * @name commit
  23678. * @memberOf _
  23679. * @since 3.2.0
  23680. * @category Seq
  23681. * @returns {Object} Returns the new `lodash` wrapper instance.
  23682. * @example
  23683. *
  23684. * var array = [1, 2];
  23685. * var wrapped = _(array).push(3);
  23686. *
  23687. * console.log(array);
  23688. * // => [1, 2]
  23689. *
  23690. * wrapped = wrapped.commit();
  23691. * console.log(array);
  23692. * // => [1, 2, 3]
  23693. *
  23694. * wrapped.last();
  23695. * // => 3
  23696. *
  23697. * console.log(array);
  23698. * // => [1, 2, 3]
  23699. */
  23700. function wrapperCommit() {
  23701. return new LodashWrapper(this.value(), this.__chain__);
  23702. }
  23703. /**
  23704. * Gets the next value on a wrapped object following the
  23705. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  23706. *
  23707. * @name next
  23708. * @memberOf _
  23709. * @since 4.0.0
  23710. * @category Seq
  23711. * @returns {Object} Returns the next iterator value.
  23712. * @example
  23713. *
  23714. * var wrapped = _([1, 2]);
  23715. *
  23716. * wrapped.next();
  23717. * // => { 'done': false, 'value': 1 }
  23718. *
  23719. * wrapped.next();
  23720. * // => { 'done': false, 'value': 2 }
  23721. *
  23722. * wrapped.next();
  23723. * // => { 'done': true, 'value': undefined }
  23724. */
  23725. function wrapperNext() {
  23726. if (this.__values__ === undefined) {
  23727. this.__values__ = toArray(this.value());
  23728. }
  23729. var done = this.__index__ >= this.__values__.length,
  23730. value = done ? undefined : this.__values__[this.__index__++];
  23731. return { 'done': done, 'value': value };
  23732. }
  23733. /**
  23734. * Enables the wrapper to be iterable.
  23735. *
  23736. * @name Symbol.iterator
  23737. * @memberOf _
  23738. * @since 4.0.0
  23739. * @category Seq
  23740. * @returns {Object} Returns the wrapper object.
  23741. * @example
  23742. *
  23743. * var wrapped = _([1, 2]);
  23744. *
  23745. * wrapped[Symbol.iterator]() === wrapped;
  23746. * // => true
  23747. *
  23748. * Array.from(wrapped);
  23749. * // => [1, 2]
  23750. */
  23751. function wrapperToIterator() {
  23752. return this;
  23753. }
  23754. /**
  23755. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  23756. *
  23757. * @name plant
  23758. * @memberOf _
  23759. * @since 3.2.0
  23760. * @category Seq
  23761. * @param {*} value The value to plant.
  23762. * @returns {Object} Returns the new `lodash` wrapper instance.
  23763. * @example
  23764. *
  23765. * function square(n) {
  23766. * return n * n;
  23767. * }
  23768. *
  23769. * var wrapped = _([1, 2]).map(square);
  23770. * var other = wrapped.plant([3, 4]);
  23771. *
  23772. * other.value();
  23773. * // => [9, 16]
  23774. *
  23775. * wrapped.value();
  23776. * // => [1, 4]
  23777. */
  23778. function wrapperPlant(value) {
  23779. var result,
  23780. parent = this;
  23781. while (parent instanceof baseLodash) {
  23782. var clone = wrapperClone(parent);
  23783. clone.__index__ = 0;
  23784. clone.__values__ = undefined;
  23785. if (result) {
  23786. previous.__wrapped__ = clone;
  23787. } else {
  23788. result = clone;
  23789. }
  23790. var previous = clone;
  23791. parent = parent.__wrapped__;
  23792. }
  23793. previous.__wrapped__ = value;
  23794. return result;
  23795. }
  23796. /**
  23797. * This method is the wrapper version of `_.reverse`.
  23798. *
  23799. * **Note:** This method mutates the wrapped array.
  23800. *
  23801. * @name reverse
  23802. * @memberOf _
  23803. * @since 0.1.0
  23804. * @category Seq
  23805. * @returns {Object} Returns the new `lodash` wrapper instance.
  23806. * @example
  23807. *
  23808. * var array = [1, 2, 3];
  23809. *
  23810. * _(array).reverse().value()
  23811. * // => [3, 2, 1]
  23812. *
  23813. * console.log(array);
  23814. * // => [3, 2, 1]
  23815. */
  23816. function wrapperReverse() {
  23817. var value = this.__wrapped__;
  23818. if (value instanceof LazyWrapper) {
  23819. var wrapped = value;
  23820. if (this.__actions__.length) {
  23821. wrapped = new LazyWrapper(this);
  23822. }
  23823. wrapped = wrapped.reverse();
  23824. wrapped.__actions__.push({
  23825. 'func': thru,
  23826. 'args': [reverse],
  23827. 'thisArg': undefined
  23828. });
  23829. return new LodashWrapper(wrapped, this.__chain__);
  23830. }
  23831. return this.thru(reverse);
  23832. }
  23833. /**
  23834. * Executes the chain sequence to resolve the unwrapped value.
  23835. *
  23836. * @name value
  23837. * @memberOf _
  23838. * @since 0.1.0
  23839. * @alias toJSON, valueOf
  23840. * @category Seq
  23841. * @returns {*} Returns the resolved unwrapped value.
  23842. * @example
  23843. *
  23844. * _([1, 2, 3]).value();
  23845. * // => [1, 2, 3]
  23846. */
  23847. function wrapperValue() {
  23848. return baseWrapperValue(this.__wrapped__, this.__actions__);
  23849. }
  23850. /*------------------------------------------------------------------------*/
  23851. /**
  23852. * Creates an object composed of keys generated from the results of running
  23853. * each element of `collection` thru `iteratee`. The corresponding value of
  23854. * each key is the number of times the key was returned by `iteratee`. The
  23855. * iteratee is invoked with one argument: (value).
  23856. *
  23857. * @static
  23858. * @memberOf _
  23859. * @since 0.5.0
  23860. * @category Collection
  23861. * @param {Array|Object} collection The collection to iterate over.
  23862. * @param {Array|Function|Object|string} [iteratee=_.identity]
  23863. * The iteratee to transform keys.
  23864. * @returns {Object} Returns the composed aggregate object.
  23865. * @example
  23866. *
  23867. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  23868. * // => { '4': 1, '6': 2 }
  23869. *
  23870. * // The `_.property` iteratee shorthand.
  23871. * _.countBy(['one', 'two', 'three'], 'length');
  23872. * // => { '3': 2, '5': 1 }
  23873. */
  23874. var countBy = createAggregator(function(result, value, key) {
  23875. hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
  23876. });
  23877. /**
  23878. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  23879. * Iteration is stopped once `predicate` returns falsey. The predicate is
  23880. * invoked with three arguments: (value, index|key, collection).
  23881. *
  23882. * @static
  23883. * @memberOf _
  23884. * @since 0.1.0
  23885. * @category Collection
  23886. * @param {Array|Object} collection The collection to iterate over.
  23887. * @param {Array|Function|Object|string} [predicate=_.identity]
  23888. * The function invoked per iteration.
  23889. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  23890. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  23891. * else `false`.
  23892. * @example
  23893. *
  23894. * _.every([true, 1, null, 'yes'], Boolean);
  23895. * // => false
  23896. *
  23897. * var users = [
  23898. * { 'user': 'barney', 'age': 36, 'active': false },
  23899. * { 'user': 'fred', 'age': 40, 'active': false }
  23900. * ];
  23901. *
  23902. * // The `_.matches` iteratee shorthand.
  23903. * _.every(users, { 'user': 'barney', 'active': false });
  23904. * // => false
  23905. *
  23906. * // The `_.matchesProperty` iteratee shorthand.
  23907. * _.every(users, ['active', false]);
  23908. * // => true
  23909. *
  23910. * // The `_.property` iteratee shorthand.
  23911. * _.every(users, 'active');
  23912. * // => false
  23913. */
  23914. function every(collection, predicate, guard) {
  23915. var func = isArray(collection) ? arrayEvery : baseEvery;
  23916. if (guard && isIterateeCall(collection, predicate, guard)) {
  23917. predicate = undefined;
  23918. }
  23919. return func(collection, getIteratee(predicate, 3));
  23920. }
  23921. /**
  23922. * Iterates over elements of `collection`, returning an array of all elements
  23923. * `predicate` returns truthy for. The predicate is invoked with three
  23924. * arguments: (value, index|key, collection).
  23925. *
  23926. * @static
  23927. * @memberOf _
  23928. * @since 0.1.0
  23929. * @category Collection
  23930. * @param {Array|Object} collection The collection to iterate over.
  23931. * @param {Array|Function|Object|string} [predicate=_.identity]
  23932. * The function invoked per iteration.
  23933. * @returns {Array} Returns the new filtered array.
  23934. * @see _.reject
  23935. * @example
  23936. *
  23937. * var users = [
  23938. * { 'user': 'barney', 'age': 36, 'active': true },
  23939. * { 'user': 'fred', 'age': 40, 'active': false }
  23940. * ];
  23941. *
  23942. * _.filter(users, function(o) { return !o.active; });
  23943. * // => objects for ['fred']
  23944. *
  23945. * // The `_.matches` iteratee shorthand.
  23946. * _.filter(users, { 'age': 36, 'active': true });
  23947. * // => objects for ['barney']
  23948. *
  23949. * // The `_.matchesProperty` iteratee shorthand.
  23950. * _.filter(users, ['active', false]);
  23951. * // => objects for ['fred']
  23952. *
  23953. * // The `_.property` iteratee shorthand.
  23954. * _.filter(users, 'active');
  23955. * // => objects for ['barney']
  23956. */
  23957. function filter(collection, predicate) {
  23958. var func = isArray(collection) ? arrayFilter : baseFilter;
  23959. return func(collection, getIteratee(predicate, 3));
  23960. }
  23961. /**
  23962. * Iterates over elements of `collection`, returning the first element
  23963. * `predicate` returns truthy for. The predicate is invoked with three
  23964. * arguments: (value, index|key, collection).
  23965. *
  23966. * @static
  23967. * @memberOf _
  23968. * @since 0.1.0
  23969. * @category Collection
  23970. * @param {Array|Object} collection The collection to search.
  23971. * @param {Array|Function|Object|string} [predicate=_.identity]
  23972. * The function invoked per iteration.
  23973. * @param {number} [fromIndex=0] The index to search from.
  23974. * @returns {*} Returns the matched element, else `undefined`.
  23975. * @example
  23976. *
  23977. * var users = [
  23978. * { 'user': 'barney', 'age': 36, 'active': true },
  23979. * { 'user': 'fred', 'age': 40, 'active': false },
  23980. * { 'user': 'pebbles', 'age': 1, 'active': true }
  23981. * ];
  23982. *
  23983. * _.find(users, function(o) { return o.age < 40; });
  23984. * // => object for 'barney'
  23985. *
  23986. * // The `_.matches` iteratee shorthand.
  23987. * _.find(users, { 'age': 1, 'active': true });
  23988. * // => object for 'pebbles'
  23989. *
  23990. * // The `_.matchesProperty` iteratee shorthand.
  23991. * _.find(users, ['active', false]);
  23992. * // => object for 'fred'
  23993. *
  23994. * // The `_.property` iteratee shorthand.
  23995. * _.find(users, 'active');
  23996. * // => object for 'barney'
  23997. */
  23998. var find = createFind(findIndex);
  23999. /**
  24000. * This method is like `_.find` except that it iterates over elements of
  24001. * `collection` from right to left.
  24002. *
  24003. * @static
  24004. * @memberOf _
  24005. * @since 2.0.0
  24006. * @category Collection
  24007. * @param {Array|Object} collection The collection to search.
  24008. * @param {Array|Function|Object|string} [predicate=_.identity]
  24009. * The function invoked per iteration.
  24010. * @param {number} [fromIndex=collection.length-1] The index to search from.
  24011. * @returns {*} Returns the matched element, else `undefined`.
  24012. * @example
  24013. *
  24014. * _.findLast([1, 2, 3, 4], function(n) {
  24015. * return n % 2 == 1;
  24016. * });
  24017. * // => 3
  24018. */
  24019. var findLast = createFind(findLastIndex);
  24020. /**
  24021. * Creates a flattened array of values by running each element in `collection`
  24022. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  24023. * with three arguments: (value, index|key, collection).
  24024. *
  24025. * @static
  24026. * @memberOf _
  24027. * @since 4.0.0
  24028. * @category Collection
  24029. * @param {Array|Object} collection The collection to iterate over.
  24030. * @param {Array|Function|Object|string} [iteratee=_.identity]
  24031. * The function invoked per iteration.
  24032. * @returns {Array} Returns the new flattened array.
  24033. * @example
  24034. *
  24035. * function duplicate(n) {
  24036. * return [n, n];
  24037. * }
  24038. *
  24039. * _.flatMap([1, 2], duplicate);
  24040. * // => [1, 1, 2, 2]
  24041. */
  24042. function flatMap(collection, iteratee) {
  24043. return baseFlatten(map(collection, iteratee), 1);
  24044. }
  24045. /**
  24046. * This method is like `_.flatMap` except that it recursively flattens the
  24047. * mapped results.
  24048. *
  24049. * @static
  24050. * @memberOf _
  24051. * @since 4.7.0
  24052. * @category Collection
  24053. * @param {Array|Object} collection The collection to iterate over.
  24054. * @param {Array|Function|Object|string} [iteratee=_.identity]
  24055. * The function invoked per iteration.
  24056. * @returns {Array} Returns the new flattened array.
  24057. * @example
  24058. *
  24059. * function duplicate(n) {
  24060. * return [[[n, n]]];
  24061. * }
  24062. *
  24063. * _.flatMapDeep([1, 2], duplicate);
  24064. * // => [1, 1, 2, 2]
  24065. */
  24066. function flatMapDeep(collection, iteratee) {
  24067. return baseFlatten(map(collection, iteratee), INFINITY);
  24068. }
  24069. /**
  24070. * This method is like `_.flatMap` except that it recursively flattens the
  24071. * mapped results up to `depth` times.
  24072. *
  24073. * @static
  24074. * @memberOf _
  24075. * @since 4.7.0
  24076. * @category Collection
  24077. * @param {Array|Object} collection The collection to iterate over.
  24078. * @param {Array|Function|Object|string} [iteratee=_.identity]
  24079. * The function invoked per iteration.
  24080. * @param {number} [depth=1] The maximum recursion depth.
  24081. * @returns {Array} Returns the new flattened array.
  24082. * @example
  24083. *
  24084. * function duplicate(n) {
  24085. * return [[[n, n]]];
  24086. * }
  24087. *
  24088. * _.flatMapDepth([1, 2], duplicate, 2);
  24089. * // => [[1, 1], [2, 2]]
  24090. */
  24091. function flatMapDepth(collection, iteratee, depth) {
  24092. depth = depth === undefined ? 1 : toInteger(depth);
  24093. return baseFlatten(map(collection, iteratee), depth);
  24094. }
  24095. /**
  24096. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  24097. * The iteratee is invoked with three arguments: (value, index|key, collection).
  24098. * Iteratee functions may exit iteration early by explicitly returning `false`.
  24099. *
  24100. * **Note:** As with other "Collections" methods, objects with a "length"
  24101. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  24102. * or `_.forOwn` for object iteration.
  24103. *
  24104. * @static
  24105. * @memberOf _
  24106. * @since 0.1.0
  24107. * @alias each
  24108. * @category Collection
  24109. * @param {Array|Object} collection The collection to iterate over.
  24110. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  24111. * @returns {Array|Object} Returns `collection`.
  24112. * @see _.forEachRight
  24113. * @example
  24114. *
  24115. * _([1, 2]).forEach(function(value) {
  24116. * console.log(value);
  24117. * });
  24118. * // => Logs `1` then `2`.
  24119. *
  24120. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  24121. * console.log(key);
  24122. * });
  24123. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  24124. */
  24125. function forEach(collection, iteratee) {
  24126. var func = isArray(collection) ? arrayEach : baseEach;
  24127. return func(collection, getIteratee(iteratee, 3));
  24128. }
  24129. /**
  24130. * This method is like `_.forEach` except that it iterates over elements of
  24131. * `collection` from right to left.
  24132. *
  24133. * @static
  24134. * @memberOf _
  24135. * @since 2.0.0
  24136. * @alias eachRight
  24137. * @category Collection
  24138. * @param {Array|Object} collection The collection to iterate over.
  24139. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  24140. * @returns {Array|Object} Returns `collection`.
  24141. * @see _.forEach
  24142. * @example
  24143. *
  24144. * _.forEachRight([1, 2], function(value) {
  24145. * console.log(value);
  24146. * });
  24147. * // => Logs `2` then `1`.
  24148. */
  24149. function forEachRight(collection, iteratee) {
  24150. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  24151. return func(collection, getIteratee(iteratee, 3));
  24152. }
  24153. /**
  24154. * Creates an object composed of keys generated from the results of running
  24155. * each element of `collection` thru `iteratee`. The order of grouped values
  24156. * is determined by the order they occur in `collection`. The corresponding
  24157. * value of each key is an array of elements responsible for generating the
  24158. * key. The iteratee is invoked with one argument: (value).
  24159. *
  24160. * @static
  24161. * @memberOf _
  24162. * @since 0.1.0
  24163. * @category Collection
  24164. * @param {Array|Object} collection The collection to iterate over.
  24165. * @param {Array|Function|Object|string} [iteratee=_.identity]
  24166. * The iteratee to transform keys.
  24167. * @returns {Object} Returns the composed aggregate object.
  24168. * @example
  24169. *
  24170. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  24171. * // => { '4': [4.2], '6': [6.1, 6.3] }
  24172. *
  24173. * // The `_.property` iteratee shorthand.
  24174. * _.groupBy(['one', 'two', 'three'], 'length');
  24175. * // => { '3': ['one', 'two'], '5': ['three'] }
  24176. */
  24177. var groupBy = createAggregator(function(result, value, key) {
  24178. if (hasOwnProperty.call(result, key)) {
  24179. result[key].push(value);
  24180. } else {
  24181. result[key] = [value];
  24182. }
  24183. });
  24184. /**
  24185. * Checks if `value` is in `collection`. If `collection` is a string, it's
  24186. * checked for a substring of `value`, otherwise
  24187. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  24188. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  24189. * the offset from the end of `collection`.
  24190. *
  24191. * @static
  24192. * @memberOf _
  24193. * @since 0.1.0
  24194. * @category Collection
  24195. * @param {Array|Object|string} collection The collection to search.
  24196. * @param {*} value The value to search for.
  24197. * @param {number} [fromIndex=0] The index to search from.
  24198. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  24199. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  24200. * @example
  24201. *
  24202. * _.includes([1, 2, 3], 1);
  24203. * // => true
  24204. *
  24205. * _.includes([1, 2, 3], 1, 2);
  24206. * // => false
  24207. *
  24208. * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
  24209. * // => true
  24210. *
  24211. * _.includes('pebbles', 'eb');
  24212. * // => true
  24213. */
  24214. function includes(collection, value, fromIndex, guard) {
  24215. collection = isArrayLike(collection) ? collection : values(collection);
  24216. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  24217. var length = collection.length;
  24218. if (fromIndex < 0) {
  24219. fromIndex = nativeMax(length + fromIndex, 0);
  24220. }
  24221. return isString(collection)
  24222. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  24223. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  24224. }
  24225. /**
  24226. * Invokes the method at `path` of each element in `collection`, returning
  24227. * an array of the results of each invoked method. Any additional arguments
  24228. * are provided to each invoked method. If `methodName` is a function, it's
  24229. * invoked for and `this` bound to, each element in `collection`.
  24230. *
  24231. * @static
  24232. * @memberOf _
  24233. * @since 4.0.0
  24234. * @category Collection
  24235. * @param {Array|Object} collection The collection to iterate over.
  24236. * @param {Array|Function|string} path The path of the method to invoke or
  24237. * the function invoked per iteration.
  24238. * @param {...*} [args] The arguments to invoke each method with.
  24239. * @returns {Array} Returns the array of results.
  24240. * @example
  24241. *
  24242. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  24243. * // => [[1, 5, 7], [1, 2, 3]]
  24244. *
  24245. * _.invokeMap([123, 456], String.prototype.split, '');
  24246. * // => [['1', '2', '3'], ['4', '5', '6']]
  24247. */
  24248. var invokeMap = rest(function(collection, path, args) {
  24249. var index = -1,
  24250. isFunc = typeof path == 'function',
  24251. isProp = isKey(path),
  24252. result = isArrayLike(collection) ? Array(collection.length) : [];
  24253. baseEach(collection, function(value) {
  24254. var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
  24255. result[++index] = func ? apply(func, value, args) : baseInvoke(value, path, args);
  24256. });
  24257. return result;
  24258. });
  24259. /**
  24260. * Creates an object composed of keys generated from the results of running
  24261. * each element of `collection` thru `iteratee`. The corresponding value of
  24262. * each key is the last element responsible for generating the key. The
  24263. * iteratee is invoked with one argument: (value).
  24264. *
  24265. * @static
  24266. * @memberOf _
  24267. * @since 4.0.0
  24268. * @category Collection
  24269. * @param {Array|Object} collection The collection to iterate over.
  24270. * @param {Array|Function|Object|string} [iteratee=_.identity]
  24271. * The iteratee to transform keys.
  24272. * @returns {Object} Returns the composed aggregate object.
  24273. * @example
  24274. *
  24275. * var array = [
  24276. * { 'dir': 'left', 'code': 97 },
  24277. * { 'dir': 'right', 'code': 100 }
  24278. * ];
  24279. *
  24280. * _.keyBy(array, function(o) {
  24281. * return String.fromCharCode(o.code);
  24282. * });
  24283. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  24284. *
  24285. * _.keyBy(array, 'dir');
  24286. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  24287. */
  24288. var keyBy = createAggregator(function(result, value, key) {
  24289. result[key] = value;
  24290. });
  24291. /**
  24292. * Creates an array of values by running each element in `collection` thru
  24293. * `iteratee`. The iteratee is invoked with three arguments:
  24294. * (value, index|key, collection).
  24295. *
  24296. * Many lodash methods are guarded to work as iteratees for methods like
  24297. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  24298. *
  24299. * The guarded methods are:
  24300. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  24301. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  24302. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  24303. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  24304. *
  24305. * @static
  24306. * @memberOf _
  24307. * @since 0.1.0
  24308. * @category Collection
  24309. * @param {Array|Object} collection The collection to iterate over.
  24310. * @param {Array|Function|Object|string} [iteratee=_.identity]
  24311. * The function invoked per iteration.
  24312. * @returns {Array} Returns the new mapped array.
  24313. * @example
  24314. *
  24315. * function square(n) {
  24316. * return n * n;
  24317. * }
  24318. *
  24319. * _.map([4, 8], square);
  24320. * // => [16, 64]
  24321. *
  24322. * _.map({ 'a': 4, 'b': 8 }, square);
  24323. * // => [16, 64] (iteration order is not guaranteed)
  24324. *
  24325. * var users = [
  24326. * { 'user': 'barney' },
  24327. * { 'user': 'fred' }
  24328. * ];
  24329. *
  24330. * // The `_.property` iteratee shorthand.
  24331. * _.map(users, 'user');
  24332. * // => ['barney', 'fred']
  24333. */
  24334. function map(collection, iteratee) {
  24335. var func = isArray(collection) ? arrayMap : baseMap;
  24336. return func(collection, getIteratee(iteratee, 3));
  24337. }
  24338. /**
  24339. * This method is like `_.sortBy` except that it allows specifying the sort
  24340. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  24341. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  24342. * descending or "asc" for ascending sort order of corresponding values.
  24343. *
  24344. * @static
  24345. * @memberOf _
  24346. * @since 4.0.0
  24347. * @category Collection
  24348. * @param {Array|Object} collection The collection to iterate over.
  24349. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  24350. * The iteratees to sort by.
  24351. * @param {string[]} [orders] The sort orders of `iteratees`.
  24352. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  24353. * @returns {Array} Returns the new sorted array.
  24354. * @example
  24355. *
  24356. * var users = [
  24357. * { 'user': 'fred', 'age': 48 },
  24358. * { 'user': 'barney', 'age': 34 },
  24359. * { 'user': 'fred', 'age': 40 },
  24360. * { 'user': 'barney', 'age': 36 }
  24361. * ];
  24362. *
  24363. * // Sort by `user` in ascending order and by `age` in descending order.
  24364. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  24365. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  24366. */
  24367. function orderBy(collection, iteratees, orders, guard) {
  24368. if (collection == null) {
  24369. return [];
  24370. }
  24371. if (!isArray(iteratees)) {
  24372. iteratees = iteratees == null ? [] : [iteratees];
  24373. }
  24374. orders = guard ? undefined : orders;
  24375. if (!isArray(orders)) {
  24376. orders = orders == null ? [] : [orders];
  24377. }
  24378. return baseOrderBy(collection, iteratees, orders);
  24379. }
  24380. /**
  24381. * Creates an array of elements split into two groups, the first of which
  24382. * contains elements `predicate` returns truthy for, the second of which
  24383. * contains elements `predicate` returns falsey for. The predicate is
  24384. * invoked with one argument: (value).
  24385. *
  24386. * @static
  24387. * @memberOf _
  24388. * @since 3.0.0
  24389. * @category Collection
  24390. * @param {Array|Object} collection The collection to iterate over.
  24391. * @param {Array|Function|Object|string} [predicate=_.identity]
  24392. * The function invoked per iteration.
  24393. * @returns {Array} Returns the array of grouped elements.
  24394. * @example
  24395. *
  24396. * var users = [
  24397. * { 'user': 'barney', 'age': 36, 'active': false },
  24398. * { 'user': 'fred', 'age': 40, 'active': true },
  24399. * { 'user': 'pebbles', 'age': 1, 'active': false }
  24400. * ];
  24401. *
  24402. * _.partition(users, function(o) { return o.active; });
  24403. * // => objects for [['fred'], ['barney', 'pebbles']]
  24404. *
  24405. * // The `_.matches` iteratee shorthand.
  24406. * _.partition(users, { 'age': 1, 'active': false });
  24407. * // => objects for [['pebbles'], ['barney', 'fred']]
  24408. *
  24409. * // The `_.matchesProperty` iteratee shorthand.
  24410. * _.partition(users, ['active', false]);
  24411. * // => objects for [['barney', 'pebbles'], ['fred']]
  24412. *
  24413. * // The `_.property` iteratee shorthand.
  24414. * _.partition(users, 'active');
  24415. * // => objects for [['fred'], ['barney', 'pebbles']]
  24416. */
  24417. var partition = createAggregator(function(result, value, key) {
  24418. result[key ? 0 : 1].push(value);
  24419. }, function() { return [[], []]; });
  24420. /**
  24421. * Reduces `collection` to a value which is the accumulated result of running
  24422. * each element in `collection` thru `iteratee`, where each successive
  24423. * invocation is supplied the return value of the previous. If `accumulator`
  24424. * is not given, the first element of `collection` is used as the initial
  24425. * value. The iteratee is invoked with four arguments:
  24426. * (accumulator, value, index|key, collection).
  24427. *
  24428. * Many lodash methods are guarded to work as iteratees for methods like
  24429. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  24430. *
  24431. * The guarded methods are:
  24432. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  24433. * and `sortBy`
  24434. *
  24435. * @static
  24436. * @memberOf _
  24437. * @since 0.1.0
  24438. * @category Collection
  24439. * @param {Array|Object} collection The collection to iterate over.
  24440. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  24441. * @param {*} [accumulator] The initial value.
  24442. * @returns {*} Returns the accumulated value.
  24443. * @see _.reduceRight
  24444. * @example
  24445. *
  24446. * _.reduce([1, 2], function(sum, n) {
  24447. * return sum + n;
  24448. * }, 0);
  24449. * // => 3
  24450. *
  24451. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  24452. * (result[value] || (result[value] = [])).push(key);
  24453. * return result;
  24454. * }, {});
  24455. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  24456. */
  24457. function reduce(collection, iteratee, accumulator) {
  24458. var func = isArray(collection) ? arrayReduce : baseReduce,
  24459. initAccum = arguments.length < 3;
  24460. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  24461. }
  24462. /**
  24463. * This method is like `_.reduce` except that it iterates over elements of
  24464. * `collection` from right to left.
  24465. *
  24466. * @static
  24467. * @memberOf _
  24468. * @since 0.1.0
  24469. * @category Collection
  24470. * @param {Array|Object} collection The collection to iterate over.
  24471. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  24472. * @param {*} [accumulator] The initial value.
  24473. * @returns {*} Returns the accumulated value.
  24474. * @see _.reduce
  24475. * @example
  24476. *
  24477. * var array = [[0, 1], [2, 3], [4, 5]];
  24478. *
  24479. * _.reduceRight(array, function(flattened, other) {
  24480. * return flattened.concat(other);
  24481. * }, []);
  24482. * // => [4, 5, 2, 3, 0, 1]
  24483. */
  24484. function reduceRight(collection, iteratee, accumulator) {
  24485. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  24486. initAccum = arguments.length < 3;
  24487. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  24488. }
  24489. /**
  24490. * The opposite of `_.filter`; this method returns the elements of `collection`
  24491. * that `predicate` does **not** return truthy for.
  24492. *
  24493. * @static
  24494. * @memberOf _
  24495. * @since 0.1.0
  24496. * @category Collection
  24497. * @param {Array|Object} collection The collection to iterate over.
  24498. * @param {Array|Function|Object|string} [predicate=_.identity]
  24499. * The function invoked per iteration.
  24500. * @returns {Array} Returns the new filtered array.
  24501. * @see _.filter
  24502. * @example
  24503. *
  24504. * var users = [
  24505. * { 'user': 'barney', 'age': 36, 'active': false },
  24506. * { 'user': 'fred', 'age': 40, 'active': true }
  24507. * ];
  24508. *
  24509. * _.reject(users, function(o) { return !o.active; });
  24510. * // => objects for ['fred']
  24511. *
  24512. * // The `_.matches` iteratee shorthand.
  24513. * _.reject(users, { 'age': 40, 'active': true });
  24514. * // => objects for ['barney']
  24515. *
  24516. * // The `_.matchesProperty` iteratee shorthand.
  24517. * _.reject(users, ['active', false]);
  24518. * // => objects for ['fred']
  24519. *
  24520. * // The `_.property` iteratee shorthand.
  24521. * _.reject(users, 'active');
  24522. * // => objects for ['barney']
  24523. */
  24524. function reject(collection, predicate) {
  24525. var func = isArray(collection) ? arrayFilter : baseFilter;
  24526. predicate = getIteratee(predicate, 3);
  24527. return func(collection, function(value, index, collection) {
  24528. return !predicate(value, index, collection);
  24529. });
  24530. }
  24531. /**
  24532. * Gets a random element from `collection`.
  24533. *
  24534. * @static
  24535. * @memberOf _
  24536. * @since 2.0.0
  24537. * @category Collection
  24538. * @param {Array|Object} collection The collection to sample.
  24539. * @returns {*} Returns the random element.
  24540. * @example
  24541. *
  24542. * _.sample([1, 2, 3, 4]);
  24543. * // => 2
  24544. */
  24545. function sample(collection) {
  24546. var array = isArrayLike(collection) ? collection : values(collection),
  24547. length = array.length;
  24548. return length > 0 ? array[baseRandom(0, length - 1)] : undefined;
  24549. }
  24550. /**
  24551. * Gets `n` random elements at unique keys from `collection` up to the
  24552. * size of `collection`.
  24553. *
  24554. * @static
  24555. * @memberOf _
  24556. * @since 4.0.0
  24557. * @category Collection
  24558. * @param {Array|Object} collection The collection to sample.
  24559. * @param {number} [n=1] The number of elements to sample.
  24560. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  24561. * @returns {Array} Returns the random elements.
  24562. * @example
  24563. *
  24564. * _.sampleSize([1, 2, 3], 2);
  24565. * // => [3, 1]
  24566. *
  24567. * _.sampleSize([1, 2, 3], 4);
  24568. * // => [2, 3, 1]
  24569. */
  24570. function sampleSize(collection, n, guard) {
  24571. var index = -1,
  24572. result = toArray(collection),
  24573. length = result.length,
  24574. lastIndex = length - 1;
  24575. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  24576. n = 1;
  24577. } else {
  24578. n = baseClamp(toInteger(n), 0, length);
  24579. }
  24580. while (++index < n) {
  24581. var rand = baseRandom(index, lastIndex),
  24582. value = result[rand];
  24583. result[rand] = result[index];
  24584. result[index] = value;
  24585. }
  24586. result.length = n;
  24587. return result;
  24588. }
  24589. /**
  24590. * Creates an array of shuffled values, using a version of the
  24591. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  24592. *
  24593. * @static
  24594. * @memberOf _
  24595. * @since 0.1.0
  24596. * @category Collection
  24597. * @param {Array|Object} collection The collection to shuffle.
  24598. * @returns {Array} Returns the new shuffled array.
  24599. * @example
  24600. *
  24601. * _.shuffle([1, 2, 3, 4]);
  24602. * // => [4, 1, 3, 2]
  24603. */
  24604. function shuffle(collection) {
  24605. return sampleSize(collection, MAX_ARRAY_LENGTH);
  24606. }
  24607. /**
  24608. * Gets the size of `collection` by returning its length for array-like
  24609. * values or the number of own enumerable string keyed properties for objects.
  24610. *
  24611. * @static
  24612. * @memberOf _
  24613. * @since 0.1.0
  24614. * @category Collection
  24615. * @param {Array|Object} collection The collection to inspect.
  24616. * @returns {number} Returns the collection size.
  24617. * @example
  24618. *
  24619. * _.size([1, 2, 3]);
  24620. * // => 3
  24621. *
  24622. * _.size({ 'a': 1, 'b': 2 });
  24623. * // => 2
  24624. *
  24625. * _.size('pebbles');
  24626. * // => 7
  24627. */
  24628. function size(collection) {
  24629. if (collection == null) {
  24630. return 0;
  24631. }
  24632. if (isArrayLike(collection)) {
  24633. var result = collection.length;
  24634. return (result && isString(collection)) ? stringSize(collection) : result;
  24635. }
  24636. if (isObjectLike(collection)) {
  24637. var tag = getTag(collection);
  24638. if (tag == mapTag || tag == setTag) {
  24639. return collection.size;
  24640. }
  24641. }
  24642. return keys(collection).length;
  24643. }
  24644. /**
  24645. * Checks if `predicate` returns truthy for **any** element of `collection`.
  24646. * Iteration is stopped once `predicate` returns truthy. The predicate is
  24647. * invoked with three arguments: (value, index|key, collection).
  24648. *
  24649. * @static
  24650. * @memberOf _
  24651. * @since 0.1.0
  24652. * @category Collection
  24653. * @param {Array|Object} collection The collection to iterate over.
  24654. * @param {Array|Function|Object|string} [predicate=_.identity]
  24655. * The function invoked per iteration.
  24656. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  24657. * @returns {boolean} Returns `true` if any element passes the predicate check,
  24658. * else `false`.
  24659. * @example
  24660. *
  24661. * _.some([null, 0, 'yes', false], Boolean);
  24662. * // => true
  24663. *
  24664. * var users = [
  24665. * { 'user': 'barney', 'active': true },
  24666. * { 'user': 'fred', 'active': false }
  24667. * ];
  24668. *
  24669. * // The `_.matches` iteratee shorthand.
  24670. * _.some(users, { 'user': 'barney', 'active': false });
  24671. * // => false
  24672. *
  24673. * // The `_.matchesProperty` iteratee shorthand.
  24674. * _.some(users, ['active', false]);
  24675. * // => true
  24676. *
  24677. * // The `_.property` iteratee shorthand.
  24678. * _.some(users, 'active');
  24679. * // => true
  24680. */
  24681. function some(collection, predicate, guard) {
  24682. var func = isArray(collection) ? arraySome : baseSome;
  24683. if (guard && isIterateeCall(collection, predicate, guard)) {
  24684. predicate = undefined;
  24685. }
  24686. return func(collection, getIteratee(predicate, 3));
  24687. }
  24688. /**
  24689. * Creates an array of elements, sorted in ascending order by the results of
  24690. * running each element in a collection thru each iteratee. This method
  24691. * performs a stable sort, that is, it preserves the original sort order of
  24692. * equal elements. The iteratees are invoked with one argument: (value).
  24693. *
  24694. * @static
  24695. * @memberOf _
  24696. * @since 0.1.0
  24697. * @category Collection
  24698. * @param {Array|Object} collection The collection to iterate over.
  24699. * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
  24700. * [iteratees=[_.identity]] The iteratees to sort by.
  24701. * @returns {Array} Returns the new sorted array.
  24702. * @example
  24703. *
  24704. * var users = [
  24705. * { 'user': 'fred', 'age': 48 },
  24706. * { 'user': 'barney', 'age': 36 },
  24707. * { 'user': 'fred', 'age': 40 },
  24708. * { 'user': 'barney', 'age': 34 }
  24709. * ];
  24710. *
  24711. * _.sortBy(users, function(o) { return o.user; });
  24712. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  24713. *
  24714. * _.sortBy(users, ['user', 'age']);
  24715. * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
  24716. *
  24717. * _.sortBy(users, 'user', function(o) {
  24718. * return Math.floor(o.age / 10);
  24719. * });
  24720. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  24721. */
  24722. var sortBy = rest(function(collection, iteratees) {
  24723. if (collection == null) {
  24724. return [];
  24725. }
  24726. var length = iteratees.length;
  24727. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  24728. iteratees = [];
  24729. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  24730. iteratees = [iteratees[0]];
  24731. }
  24732. iteratees = (iteratees.length == 1 && isArray(iteratees[0]))
  24733. ? iteratees[0]
  24734. : baseFlatten(iteratees, 1, isFlattenableIteratee);
  24735. return baseOrderBy(collection, iteratees, []);
  24736. });
  24737. /*------------------------------------------------------------------------*/
  24738. /**
  24739. * Gets the timestamp of the number of milliseconds that have elapsed since
  24740. * the Unix epoch (1 January 1970 00:00:00 UTC).
  24741. *
  24742. * @static
  24743. * @memberOf _
  24744. * @since 2.4.0
  24745. * @category Date
  24746. * @returns {number} Returns the timestamp.
  24747. * @example
  24748. *
  24749. * _.defer(function(stamp) {
  24750. * console.log(_.now() - stamp);
  24751. * }, _.now());
  24752. * // => Logs the number of milliseconds it took for the deferred invocation.
  24753. */
  24754. function now() {
  24755. return Date.now();
  24756. }
  24757. /*------------------------------------------------------------------------*/
  24758. /**
  24759. * The opposite of `_.before`; this method creates a function that invokes
  24760. * `func` once it's called `n` or more times.
  24761. *
  24762. * @static
  24763. * @memberOf _
  24764. * @since 0.1.0
  24765. * @category Function
  24766. * @param {number} n The number of calls before `func` is invoked.
  24767. * @param {Function} func The function to restrict.
  24768. * @returns {Function} Returns the new restricted function.
  24769. * @example
  24770. *
  24771. * var saves = ['profile', 'settings'];
  24772. *
  24773. * var done = _.after(saves.length, function() {
  24774. * console.log('done saving!');
  24775. * });
  24776. *
  24777. * _.forEach(saves, function(type) {
  24778. * asyncSave({ 'type': type, 'complete': done });
  24779. * });
  24780. * // => Logs 'done saving!' after the two async saves have completed.
  24781. */
  24782. function after(n, func) {
  24783. if (typeof func != 'function') {
  24784. throw new TypeError(FUNC_ERROR_TEXT);
  24785. }
  24786. n = toInteger(n);
  24787. return function() {
  24788. if (--n < 1) {
  24789. return func.apply(this, arguments);
  24790. }
  24791. };
  24792. }
  24793. /**
  24794. * Creates a function that invokes `func`, with up to `n` arguments,
  24795. * ignoring any additional arguments.
  24796. *
  24797. * @static
  24798. * @memberOf _
  24799. * @since 3.0.0
  24800. * @category Function
  24801. * @param {Function} func The function to cap arguments for.
  24802. * @param {number} [n=func.length] The arity cap.
  24803. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  24804. * @returns {Function} Returns the new capped function.
  24805. * @example
  24806. *
  24807. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  24808. * // => [6, 8, 10]
  24809. */
  24810. function ary(func, n, guard) {
  24811. n = guard ? undefined : n;
  24812. n = (func && n == null) ? func.length : n;
  24813. return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
  24814. }
  24815. /**
  24816. * Creates a function that invokes `func`, with the `this` binding and arguments
  24817. * of the created function, while it's called less than `n` times. Subsequent
  24818. * calls to the created function return the result of the last `func` invocation.
  24819. *
  24820. * @static
  24821. * @memberOf _
  24822. * @since 3.0.0
  24823. * @category Function
  24824. * @param {number} n The number of calls at which `func` is no longer invoked.
  24825. * @param {Function} func The function to restrict.
  24826. * @returns {Function} Returns the new restricted function.
  24827. * @example
  24828. *
  24829. * jQuery(element).on('click', _.before(5, addContactToList));
  24830. * // => allows adding up to 4 contacts to the list
  24831. */
  24832. function before(n, func) {
  24833. var result;
  24834. if (typeof func != 'function') {
  24835. throw new TypeError(FUNC_ERROR_TEXT);
  24836. }
  24837. n = toInteger(n);
  24838. return function() {
  24839. if (--n > 0) {
  24840. result = func.apply(this, arguments);
  24841. }
  24842. if (n <= 1) {
  24843. func = undefined;
  24844. }
  24845. return result;
  24846. };
  24847. }
  24848. /**
  24849. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  24850. * and `partials` prepended to the arguments it receives.
  24851. *
  24852. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  24853. * may be used as a placeholder for partially applied arguments.
  24854. *
  24855. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  24856. * property of bound functions.
  24857. *
  24858. * @static
  24859. * @memberOf _
  24860. * @since 0.1.0
  24861. * @category Function
  24862. * @param {Function} func The function to bind.
  24863. * @param {*} thisArg The `this` binding of `func`.
  24864. * @param {...*} [partials] The arguments to be partially applied.
  24865. * @returns {Function} Returns the new bound function.
  24866. * @example
  24867. *
  24868. * var greet = function(greeting, punctuation) {
  24869. * return greeting + ' ' + this.user + punctuation;
  24870. * };
  24871. *
  24872. * var object = { 'user': 'fred' };
  24873. *
  24874. * var bound = _.bind(greet, object, 'hi');
  24875. * bound('!');
  24876. * // => 'hi fred!'
  24877. *
  24878. * // Bound with placeholders.
  24879. * var bound = _.bind(greet, object, _, '!');
  24880. * bound('hi');
  24881. * // => 'hi fred!'
  24882. */
  24883. var bind = rest(function(func, thisArg, partials) {
  24884. var bitmask = BIND_FLAG;
  24885. if (partials.length) {
  24886. var holders = replaceHolders(partials, getHolder(bind));
  24887. bitmask |= PARTIAL_FLAG;
  24888. }
  24889. return createWrapper(func, bitmask, thisArg, partials, holders);
  24890. });
  24891. /**
  24892. * Creates a function that invokes the method at `object[key]` with `partials`
  24893. * prepended to the arguments it receives.
  24894. *
  24895. * This method differs from `_.bind` by allowing bound functions to reference
  24896. * methods that may be redefined or don't yet exist. See
  24897. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  24898. * for more details.
  24899. *
  24900. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  24901. * builds, may be used as a placeholder for partially applied arguments.
  24902. *
  24903. * @static
  24904. * @memberOf _
  24905. * @since 0.10.0
  24906. * @category Function
  24907. * @param {Object} object The object to invoke the method on.
  24908. * @param {string} key The key of the method.
  24909. * @param {...*} [partials] The arguments to be partially applied.
  24910. * @returns {Function} Returns the new bound function.
  24911. * @example
  24912. *
  24913. * var object = {
  24914. * 'user': 'fred',
  24915. * 'greet': function(greeting, punctuation) {
  24916. * return greeting + ' ' + this.user + punctuation;
  24917. * }
  24918. * };
  24919. *
  24920. * var bound = _.bindKey(object, 'greet', 'hi');
  24921. * bound('!');
  24922. * // => 'hi fred!'
  24923. *
  24924. * object.greet = function(greeting, punctuation) {
  24925. * return greeting + 'ya ' + this.user + punctuation;
  24926. * };
  24927. *
  24928. * bound('!');
  24929. * // => 'hiya fred!'
  24930. *
  24931. * // Bound with placeholders.
  24932. * var bound = _.bindKey(object, 'greet', _, '!');
  24933. * bound('hi');
  24934. * // => 'hiya fred!'
  24935. */
  24936. var bindKey = rest(function(object, key, partials) {
  24937. var bitmask = BIND_FLAG | BIND_KEY_FLAG;
  24938. if (partials.length) {
  24939. var holders = replaceHolders(partials, getHolder(bindKey));
  24940. bitmask |= PARTIAL_FLAG;
  24941. }
  24942. return createWrapper(key, bitmask, object, partials, holders);
  24943. });
  24944. /**
  24945. * Creates a function that accepts arguments of `func` and either invokes
  24946. * `func` returning its result, if at least `arity` number of arguments have
  24947. * been provided, or returns a function that accepts the remaining `func`
  24948. * arguments, and so on. The arity of `func` may be specified if `func.length`
  24949. * is not sufficient.
  24950. *
  24951. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  24952. * may be used as a placeholder for provided arguments.
  24953. *
  24954. * **Note:** This method doesn't set the "length" property of curried functions.
  24955. *
  24956. * @static
  24957. * @memberOf _
  24958. * @since 2.0.0
  24959. * @category Function
  24960. * @param {Function} func The function to curry.
  24961. * @param {number} [arity=func.length] The arity of `func`.
  24962. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  24963. * @returns {Function} Returns the new curried function.
  24964. * @example
  24965. *
  24966. * var abc = function(a, b, c) {
  24967. * return [a, b, c];
  24968. * };
  24969. *
  24970. * var curried = _.curry(abc);
  24971. *
  24972. * curried(1)(2)(3);
  24973. * // => [1, 2, 3]
  24974. *
  24975. * curried(1, 2)(3);
  24976. * // => [1, 2, 3]
  24977. *
  24978. * curried(1, 2, 3);
  24979. * // => [1, 2, 3]
  24980. *
  24981. * // Curried with placeholders.
  24982. * curried(1)(_, 3)(2);
  24983. * // => [1, 2, 3]
  24984. */
  24985. function curry(func, arity, guard) {
  24986. arity = guard ? undefined : arity;
  24987. var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  24988. result.placeholder = curry.placeholder;
  24989. return result;
  24990. }
  24991. /**
  24992. * This method is like `_.curry` except that arguments are applied to `func`
  24993. * in the manner of `_.partialRight` instead of `_.partial`.
  24994. *
  24995. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  24996. * builds, may be used as a placeholder for provided arguments.
  24997. *
  24998. * **Note:** This method doesn't set the "length" property of curried functions.
  24999. *
  25000. * @static
  25001. * @memberOf _
  25002. * @since 3.0.0
  25003. * @category Function
  25004. * @param {Function} func The function to curry.
  25005. * @param {number} [arity=func.length] The arity of `func`.
  25006. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  25007. * @returns {Function} Returns the new curried function.
  25008. * @example
  25009. *
  25010. * var abc = function(a, b, c) {
  25011. * return [a, b, c];
  25012. * };
  25013. *
  25014. * var curried = _.curryRight(abc);
  25015. *
  25016. * curried(3)(2)(1);
  25017. * // => [1, 2, 3]
  25018. *
  25019. * curried(2, 3)(1);
  25020. * // => [1, 2, 3]
  25021. *
  25022. * curried(1, 2, 3);
  25023. * // => [1, 2, 3]
  25024. *
  25025. * // Curried with placeholders.
  25026. * curried(3)(1, _)(2);
  25027. * // => [1, 2, 3]
  25028. */
  25029. function curryRight(func, arity, guard) {
  25030. arity = guard ? undefined : arity;
  25031. var result = createWrapper(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  25032. result.placeholder = curryRight.placeholder;
  25033. return result;
  25034. }
  25035. /**
  25036. * Creates a debounced function that delays invoking `func` until after `wait`
  25037. * milliseconds have elapsed since the last time the debounced function was
  25038. * invoked. The debounced function comes with a `cancel` method to cancel
  25039. * delayed `func` invocations and a `flush` method to immediately invoke them.
  25040. * Provide an options object to indicate whether `func` should be invoked on
  25041. * the leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  25042. * with the last arguments provided to the debounced function. Subsequent calls
  25043. * to the debounced function return the result of the last `func` invocation.
  25044. *
  25045. * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
  25046. * on the trailing edge of the timeout only if the debounced function is
  25047. * invoked more than once during the `wait` timeout.
  25048. *
  25049. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  25050. * for details over the differences between `_.debounce` and `_.throttle`.
  25051. *
  25052. * @static
  25053. * @memberOf _
  25054. * @since 0.1.0
  25055. * @category Function
  25056. * @param {Function} func The function to debounce.
  25057. * @param {number} [wait=0] The number of milliseconds to delay.
  25058. * @param {Object} [options={}] The options object.
  25059. * @param {boolean} [options.leading=false]
  25060. * Specify invoking on the leading edge of the timeout.
  25061. * @param {number} [options.maxWait]
  25062. * The maximum time `func` is allowed to be delayed before it's invoked.
  25063. * @param {boolean} [options.trailing=true]
  25064. * Specify invoking on the trailing edge of the timeout.
  25065. * @returns {Function} Returns the new debounced function.
  25066. * @example
  25067. *
  25068. * // Avoid costly calculations while the window size is in flux.
  25069. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  25070. *
  25071. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  25072. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  25073. * 'leading': true,
  25074. * 'trailing': false
  25075. * }));
  25076. *
  25077. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  25078. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  25079. * var source = new EventSource('/stream');
  25080. * jQuery(source).on('message', debounced);
  25081. *
  25082. * // Cancel the trailing debounced invocation.
  25083. * jQuery(window).on('popstate', debounced.cancel);
  25084. */
  25085. function debounce(func, wait, options) {
  25086. var lastArgs,
  25087. lastThis,
  25088. maxWait,
  25089. result,
  25090. timerId,
  25091. lastCallTime,
  25092. lastInvokeTime = 0,
  25093. leading = false,
  25094. maxing = false,
  25095. trailing = true;
  25096. if (typeof func != 'function') {
  25097. throw new TypeError(FUNC_ERROR_TEXT);
  25098. }
  25099. wait = toNumber(wait) || 0;
  25100. if (isObject(options)) {
  25101. leading = !!options.leading;
  25102. maxing = 'maxWait' in options;
  25103. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  25104. trailing = 'trailing' in options ? !!options.trailing : trailing;
  25105. }
  25106. function invokeFunc(time) {
  25107. var args = lastArgs,
  25108. thisArg = lastThis;
  25109. lastArgs = lastThis = undefined;
  25110. lastInvokeTime = time;
  25111. result = func.apply(thisArg, args);
  25112. return result;
  25113. }
  25114. function leadingEdge(time) {
  25115. // Reset any `maxWait` timer.
  25116. lastInvokeTime = time;
  25117. // Start the timer for the trailing edge.
  25118. timerId = setTimeout(timerExpired, wait);
  25119. // Invoke the leading edge.
  25120. return leading ? invokeFunc(time) : result;
  25121. }
  25122. function remainingWait(time) {
  25123. var timeSinceLastCall = time - lastCallTime,
  25124. timeSinceLastInvoke = time - lastInvokeTime,
  25125. result = wait - timeSinceLastCall;
  25126. return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;
  25127. }
  25128. function shouldInvoke(time) {
  25129. var timeSinceLastCall = time - lastCallTime,
  25130. timeSinceLastInvoke = time - lastInvokeTime;
  25131. // Either this is the first call, activity has stopped and we're at the
  25132. // trailing edge, the system time has gone backwards and we're treating
  25133. // it as the trailing edge, or we've hit the `maxWait` limit.
  25134. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  25135. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  25136. }
  25137. function timerExpired() {
  25138. var time = now();
  25139. if (shouldInvoke(time)) {
  25140. return trailingEdge(time);
  25141. }
  25142. // Restart the timer.
  25143. timerId = setTimeout(timerExpired, remainingWait(time));
  25144. }
  25145. function trailingEdge(time) {
  25146. timerId = undefined;
  25147. // Only invoke if we have `lastArgs` which means `func` has been
  25148. // debounced at least once.
  25149. if (trailing && lastArgs) {
  25150. return invokeFunc(time);
  25151. }
  25152. lastArgs = lastThis = undefined;
  25153. return result;
  25154. }
  25155. function cancel() {
  25156. lastInvokeTime = 0;
  25157. lastArgs = lastCallTime = lastThis = timerId = undefined;
  25158. }
  25159. function flush() {
  25160. return timerId === undefined ? result : trailingEdge(now());
  25161. }
  25162. function debounced() {
  25163. var time = now(),
  25164. isInvoking = shouldInvoke(time);
  25165. lastArgs = arguments;
  25166. lastThis = this;
  25167. lastCallTime = time;
  25168. if (isInvoking) {
  25169. if (timerId === undefined) {
  25170. return leadingEdge(lastCallTime);
  25171. }
  25172. if (maxing) {
  25173. // Handle invocations in a tight loop.
  25174. timerId = setTimeout(timerExpired, wait);
  25175. return invokeFunc(lastCallTime);
  25176. }
  25177. }
  25178. if (timerId === undefined) {
  25179. timerId = setTimeout(timerExpired, wait);
  25180. }
  25181. return result;
  25182. }
  25183. debounced.cancel = cancel;
  25184. debounced.flush = flush;
  25185. return debounced;
  25186. }
  25187. /**
  25188. * Defers invoking the `func` until the current call stack has cleared. Any
  25189. * additional arguments are provided to `func` when it's invoked.
  25190. *
  25191. * @static
  25192. * @memberOf _
  25193. * @since 0.1.0
  25194. * @category Function
  25195. * @param {Function} func The function to defer.
  25196. * @param {...*} [args] The arguments to invoke `func` with.
  25197. * @returns {number} Returns the timer id.
  25198. * @example
  25199. *
  25200. * _.defer(function(text) {
  25201. * console.log(text);
  25202. * }, 'deferred');
  25203. * // => Logs 'deferred' after one or more milliseconds.
  25204. */
  25205. var defer = rest(function(func, args) {
  25206. return baseDelay(func, 1, args);
  25207. });
  25208. /**
  25209. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  25210. * provided to `func` when it's invoked.
  25211. *
  25212. * @static
  25213. * @memberOf _
  25214. * @since 0.1.0
  25215. * @category Function
  25216. * @param {Function} func The function to delay.
  25217. * @param {number} wait The number of milliseconds to delay invocation.
  25218. * @param {...*} [args] The arguments to invoke `func` with.
  25219. * @returns {number} Returns the timer id.
  25220. * @example
  25221. *
  25222. * _.delay(function(text) {
  25223. * console.log(text);
  25224. * }, 1000, 'later');
  25225. * // => Logs 'later' after one second.
  25226. */
  25227. var delay = rest(function(func, wait, args) {
  25228. return baseDelay(func, toNumber(wait) || 0, args);
  25229. });
  25230. /**
  25231. * Creates a function that invokes `func` with arguments reversed.
  25232. *
  25233. * @static
  25234. * @memberOf _
  25235. * @since 4.0.0
  25236. * @category Function
  25237. * @param {Function} func The function to flip arguments for.
  25238. * @returns {Function} Returns the new flipped function.
  25239. * @example
  25240. *
  25241. * var flipped = _.flip(function() {
  25242. * return _.toArray(arguments);
  25243. * });
  25244. *
  25245. * flipped('a', 'b', 'c', 'd');
  25246. * // => ['d', 'c', 'b', 'a']
  25247. */
  25248. function flip(func) {
  25249. return createWrapper(func, FLIP_FLAG);
  25250. }
  25251. /**
  25252. * Creates a function that memoizes the result of `func`. If `resolver` is
  25253. * provided, it determines the cache key for storing the result based on the
  25254. * arguments provided to the memoized function. By default, the first argument
  25255. * provided to the memoized function is used as the map cache key. The `func`
  25256. * is invoked with the `this` binding of the memoized function.
  25257. *
  25258. * **Note:** The cache is exposed as the `cache` property on the memoized
  25259. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  25260. * constructor with one whose instances implement the
  25261. * [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
  25262. * method interface of `delete`, `get`, `has`, and `set`.
  25263. *
  25264. * @static
  25265. * @memberOf _
  25266. * @since 0.1.0
  25267. * @category Function
  25268. * @param {Function} func The function to have its output memoized.
  25269. * @param {Function} [resolver] The function to resolve the cache key.
  25270. * @returns {Function} Returns the new memoized function.
  25271. * @example
  25272. *
  25273. * var object = { 'a': 1, 'b': 2 };
  25274. * var other = { 'c': 3, 'd': 4 };
  25275. *
  25276. * var values = _.memoize(_.values);
  25277. * values(object);
  25278. * // => [1, 2]
  25279. *
  25280. * values(other);
  25281. * // => [3, 4]
  25282. *
  25283. * object.a = 2;
  25284. * values(object);
  25285. * // => [1, 2]
  25286. *
  25287. * // Modify the result cache.
  25288. * values.cache.set(object, ['a', 'b']);
  25289. * values(object);
  25290. * // => ['a', 'b']
  25291. *
  25292. * // Replace `_.memoize.Cache`.
  25293. * _.memoize.Cache = WeakMap;
  25294. */
  25295. function memoize(func, resolver) {
  25296. if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
  25297. throw new TypeError(FUNC_ERROR_TEXT);
  25298. }
  25299. var memoized = function() {
  25300. var args = arguments,
  25301. key = resolver ? resolver.apply(this, args) : args[0],
  25302. cache = memoized.cache;
  25303. if (cache.has(key)) {
  25304. return cache.get(key);
  25305. }
  25306. var result = func.apply(this, args);
  25307. memoized.cache = cache.set(key, result);
  25308. return result;
  25309. };
  25310. memoized.cache = new (memoize.Cache || MapCache);
  25311. return memoized;
  25312. }
  25313. // Assign cache to `_.memoize`.
  25314. memoize.Cache = MapCache;
  25315. /**
  25316. * Creates a function that negates the result of the predicate `func`. The
  25317. * `func` predicate is invoked with the `this` binding and arguments of the
  25318. * created function.
  25319. *
  25320. * @static
  25321. * @memberOf _
  25322. * @since 3.0.0
  25323. * @category Function
  25324. * @param {Function} predicate The predicate to negate.
  25325. * @returns {Function} Returns the new negated function.
  25326. * @example
  25327. *
  25328. * function isEven(n) {
  25329. * return n % 2 == 0;
  25330. * }
  25331. *
  25332. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  25333. * // => [1, 3, 5]
  25334. */
  25335. function negate(predicate) {
  25336. if (typeof predicate != 'function') {
  25337. throw new TypeError(FUNC_ERROR_TEXT);
  25338. }
  25339. return function() {
  25340. return !predicate.apply(this, arguments);
  25341. };
  25342. }
  25343. /**
  25344. * Creates a function that is restricted to invoking `func` once. Repeat calls
  25345. * to the function return the value of the first invocation. The `func` is
  25346. * invoked with the `this` binding and arguments of the created function.
  25347. *
  25348. * @static
  25349. * @memberOf _
  25350. * @since 0.1.0
  25351. * @category Function
  25352. * @param {Function} func The function to restrict.
  25353. * @returns {Function} Returns the new restricted function.
  25354. * @example
  25355. *
  25356. * var initialize = _.once(createApplication);
  25357. * initialize();
  25358. * initialize();
  25359. * // `initialize` invokes `createApplication` once
  25360. */
  25361. function once(func) {
  25362. return before(2, func);
  25363. }
  25364. /**
  25365. * Creates a function that invokes `func` with arguments transformed by
  25366. * corresponding `transforms`.
  25367. *
  25368. * @static
  25369. * @since 4.0.0
  25370. * @memberOf _
  25371. * @category Function
  25372. * @param {Function} func The function to wrap.
  25373. * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
  25374. * [transforms[_.identity]] The functions to transform.
  25375. * @returns {Function} Returns the new function.
  25376. * @example
  25377. *
  25378. * function doubled(n) {
  25379. * return n * 2;
  25380. * }
  25381. *
  25382. * function square(n) {
  25383. * return n * n;
  25384. * }
  25385. *
  25386. * var func = _.overArgs(function(x, y) {
  25387. * return [x, y];
  25388. * }, [square, doubled]);
  25389. *
  25390. * func(9, 3);
  25391. * // => [81, 6]
  25392. *
  25393. * func(10, 5);
  25394. * // => [100, 10]
  25395. */
  25396. var overArgs = rest(function(func, transforms) {
  25397. transforms = (transforms.length == 1 && isArray(transforms[0]))
  25398. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  25399. : arrayMap(baseFlatten(transforms, 1, isFlattenableIteratee), baseUnary(getIteratee()));
  25400. var funcsLength = transforms.length;
  25401. return rest(function(args) {
  25402. var index = -1,
  25403. length = nativeMin(args.length, funcsLength);
  25404. while (++index < length) {
  25405. args[index] = transforms[index].call(this, args[index]);
  25406. }
  25407. return apply(func, this, args);
  25408. });
  25409. });
  25410. /**
  25411. * Creates a function that invokes `func` with `partials` prepended to the
  25412. * arguments it receives. This method is like `_.bind` except it does **not**
  25413. * alter the `this` binding.
  25414. *
  25415. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  25416. * builds, may be used as a placeholder for partially applied arguments.
  25417. *
  25418. * **Note:** This method doesn't set the "length" property of partially
  25419. * applied functions.
  25420. *
  25421. * @static
  25422. * @memberOf _
  25423. * @since 0.2.0
  25424. * @category Function
  25425. * @param {Function} func The function to partially apply arguments to.
  25426. * @param {...*} [partials] The arguments to be partially applied.
  25427. * @returns {Function} Returns the new partially applied function.
  25428. * @example
  25429. *
  25430. * var greet = function(greeting, name) {
  25431. * return greeting + ' ' + name;
  25432. * };
  25433. *
  25434. * var sayHelloTo = _.partial(greet, 'hello');
  25435. * sayHelloTo('fred');
  25436. * // => 'hello fred'
  25437. *
  25438. * // Partially applied with placeholders.
  25439. * var greetFred = _.partial(greet, _, 'fred');
  25440. * greetFred('hi');
  25441. * // => 'hi fred'
  25442. */
  25443. var partial = rest(function(func, partials) {
  25444. var holders = replaceHolders(partials, getHolder(partial));
  25445. return createWrapper(func, PARTIAL_FLAG, undefined, partials, holders);
  25446. });
  25447. /**
  25448. * This method is like `_.partial` except that partially applied arguments
  25449. * are appended to the arguments it receives.
  25450. *
  25451. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  25452. * builds, may be used as a placeholder for partially applied arguments.
  25453. *
  25454. * **Note:** This method doesn't set the "length" property of partially
  25455. * applied functions.
  25456. *
  25457. * @static
  25458. * @memberOf _
  25459. * @since 1.0.0
  25460. * @category Function
  25461. * @param {Function} func The function to partially apply arguments to.
  25462. * @param {...*} [partials] The arguments to be partially applied.
  25463. * @returns {Function} Returns the new partially applied function.
  25464. * @example
  25465. *
  25466. * var greet = function(greeting, name) {
  25467. * return greeting + ' ' + name;
  25468. * };
  25469. *
  25470. * var greetFred = _.partialRight(greet, 'fred');
  25471. * greetFred('hi');
  25472. * // => 'hi fred'
  25473. *
  25474. * // Partially applied with placeholders.
  25475. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  25476. * sayHelloTo('fred');
  25477. * // => 'hello fred'
  25478. */
  25479. var partialRight = rest(function(func, partials) {
  25480. var holders = replaceHolders(partials, getHolder(partialRight));
  25481. return createWrapper(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  25482. });
  25483. /**
  25484. * Creates a function that invokes `func` with arguments arranged according
  25485. * to the specified `indexes` where the argument value at the first index is
  25486. * provided as the first argument, the argument value at the second index is
  25487. * provided as the second argument, and so on.
  25488. *
  25489. * @static
  25490. * @memberOf _
  25491. * @since 3.0.0
  25492. * @category Function
  25493. * @param {Function} func The function to rearrange arguments for.
  25494. * @param {...(number|number[])} indexes The arranged argument indexes.
  25495. * @returns {Function} Returns the new function.
  25496. * @example
  25497. *
  25498. * var rearged = _.rearg(function(a, b, c) {
  25499. * return [a, b, c];
  25500. * }, [2, 0, 1]);
  25501. *
  25502. * rearged('b', 'c', 'a')
  25503. * // => ['a', 'b', 'c']
  25504. */
  25505. var rearg = rest(function(func, indexes) {
  25506. return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes, 1));
  25507. });
  25508. /**
  25509. * Creates a function that invokes `func` with the `this` binding of the
  25510. * created function and arguments from `start` and beyond provided as
  25511. * an array.
  25512. *
  25513. * **Note:** This method is based on the
  25514. * [rest parameter](https://mdn.io/rest_parameters).
  25515. *
  25516. * @static
  25517. * @memberOf _
  25518. * @since 4.0.0
  25519. * @category Function
  25520. * @param {Function} func The function to apply a rest parameter to.
  25521. * @param {number} [start=func.length-1] The start position of the rest parameter.
  25522. * @returns {Function} Returns the new function.
  25523. * @example
  25524. *
  25525. * var say = _.rest(function(what, names) {
  25526. * return what + ' ' + _.initial(names).join(', ') +
  25527. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  25528. * });
  25529. *
  25530. * say('hello', 'fred', 'barney', 'pebbles');
  25531. * // => 'hello fred, barney, & pebbles'
  25532. */
  25533. function rest(func, start) {
  25534. if (typeof func != 'function') {
  25535. throw new TypeError(FUNC_ERROR_TEXT);
  25536. }
  25537. start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
  25538. return function() {
  25539. var args = arguments,
  25540. index = -1,
  25541. length = nativeMax(args.length - start, 0),
  25542. array = Array(length);
  25543. while (++index < length) {
  25544. array[index] = args[start + index];
  25545. }
  25546. switch (start) {
  25547. case 0: return func.call(this, array);
  25548. case 1: return func.call(this, args[0], array);
  25549. case 2: return func.call(this, args[0], args[1], array);
  25550. }
  25551. var otherArgs = Array(start + 1);
  25552. index = -1;
  25553. while (++index < start) {
  25554. otherArgs[index] = args[index];
  25555. }
  25556. otherArgs[start] = array;
  25557. return apply(func, this, otherArgs);
  25558. };
  25559. }
  25560. /**
  25561. * Creates a function that invokes `func` with the `this` binding of the
  25562. * create function and an array of arguments much like
  25563. * [`Function#apply`](http://www.ecma-international.org/ecma-262/6.0/#sec-function.prototype.apply).
  25564. *
  25565. * **Note:** This method is based on the
  25566. * [spread operator](https://mdn.io/spread_operator).
  25567. *
  25568. * @static
  25569. * @memberOf _
  25570. * @since 3.2.0
  25571. * @category Function
  25572. * @param {Function} func The function to spread arguments over.
  25573. * @param {number} [start=0] The start position of the spread.
  25574. * @returns {Function} Returns the new function.
  25575. * @example
  25576. *
  25577. * var say = _.spread(function(who, what) {
  25578. * return who + ' says ' + what;
  25579. * });
  25580. *
  25581. * say(['fred', 'hello']);
  25582. * // => 'fred says hello'
  25583. *
  25584. * var numbers = Promise.all([
  25585. * Promise.resolve(40),
  25586. * Promise.resolve(36)
  25587. * ]);
  25588. *
  25589. * numbers.then(_.spread(function(x, y) {
  25590. * return x + y;
  25591. * }));
  25592. * // => a Promise of 76
  25593. */
  25594. function spread(func, start) {
  25595. if (typeof func != 'function') {
  25596. throw new TypeError(FUNC_ERROR_TEXT);
  25597. }
  25598. start = start === undefined ? 0 : nativeMax(toInteger(start), 0);
  25599. return rest(function(args) {
  25600. var array = args[start],
  25601. otherArgs = castSlice(args, 0, start);
  25602. if (array) {
  25603. arrayPush(otherArgs, array);
  25604. }
  25605. return apply(func, this, otherArgs);
  25606. });
  25607. }
  25608. /**
  25609. * Creates a throttled function that only invokes `func` at most once per
  25610. * every `wait` milliseconds. The throttled function comes with a `cancel`
  25611. * method to cancel delayed `func` invocations and a `flush` method to
  25612. * immediately invoke them. Provide an options object to indicate whether
  25613. * `func` should be invoked on the leading and/or trailing edge of the `wait`
  25614. * timeout. The `func` is invoked with the last arguments provided to the
  25615. * throttled function. Subsequent calls to the throttled function return the
  25616. * result of the last `func` invocation.
  25617. *
  25618. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  25619. * invoked on the trailing edge of the timeout only if the throttled function
  25620. * is invoked more than once during the `wait` timeout.
  25621. *
  25622. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  25623. * for details over the differences between `_.throttle` and `_.debounce`.
  25624. *
  25625. * @static
  25626. * @memberOf _
  25627. * @since 0.1.0
  25628. * @category Function
  25629. * @param {Function} func The function to throttle.
  25630. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  25631. * @param {Object} [options={}] The options object.
  25632. * @param {boolean} [options.leading=true]
  25633. * Specify invoking on the leading edge of the timeout.
  25634. * @param {boolean} [options.trailing=true]
  25635. * Specify invoking on the trailing edge of the timeout.
  25636. * @returns {Function} Returns the new throttled function.
  25637. * @example
  25638. *
  25639. * // Avoid excessively updating the position while scrolling.
  25640. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  25641. *
  25642. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  25643. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  25644. * jQuery(element).on('click', throttled);
  25645. *
  25646. * // Cancel the trailing throttled invocation.
  25647. * jQuery(window).on('popstate', throttled.cancel);
  25648. */
  25649. function throttle(func, wait, options) {
  25650. var leading = true,
  25651. trailing = true;
  25652. if (typeof func != 'function') {
  25653. throw new TypeError(FUNC_ERROR_TEXT);
  25654. }
  25655. if (isObject(options)) {
  25656. leading = 'leading' in options ? !!options.leading : leading;
  25657. trailing = 'trailing' in options ? !!options.trailing : trailing;
  25658. }
  25659. return debounce(func, wait, {
  25660. 'leading': leading,
  25661. 'maxWait': wait,
  25662. 'trailing': trailing
  25663. });
  25664. }
  25665. /**
  25666. * Creates a function that accepts up to one argument, ignoring any
  25667. * additional arguments.
  25668. *
  25669. * @static
  25670. * @memberOf _
  25671. * @since 4.0.0
  25672. * @category Function
  25673. * @param {Function} func The function to cap arguments for.
  25674. * @returns {Function} Returns the new capped function.
  25675. * @example
  25676. *
  25677. * _.map(['6', '8', '10'], _.unary(parseInt));
  25678. * // => [6, 8, 10]
  25679. */
  25680. function unary(func) {
  25681. return ary(func, 1);
  25682. }
  25683. /**
  25684. * Creates a function that provides `value` to the wrapper function as its
  25685. * first argument. Any additional arguments provided to the function are
  25686. * appended to those provided to the wrapper function. The wrapper is invoked
  25687. * with the `this` binding of the created function.
  25688. *
  25689. * @static
  25690. * @memberOf _
  25691. * @since 0.1.0
  25692. * @category Function
  25693. * @param {*} value The value to wrap.
  25694. * @param {Function} [wrapper=identity] The wrapper function.
  25695. * @returns {Function} Returns the new function.
  25696. * @example
  25697. *
  25698. * var p = _.wrap(_.escape, function(func, text) {
  25699. * return '<p>' + func(text) + '</p>';
  25700. * });
  25701. *
  25702. * p('fred, barney, & pebbles');
  25703. * // => '<p>fred, barney, &amp; pebbles</p>'
  25704. */
  25705. function wrap(value, wrapper) {
  25706. wrapper = wrapper == null ? identity : wrapper;
  25707. return partial(wrapper, value);
  25708. }
  25709. /*------------------------------------------------------------------------*/
  25710. /**
  25711. * Casts `value` as an array if it's not one.
  25712. *
  25713. * @static
  25714. * @memberOf _
  25715. * @since 4.4.0
  25716. * @category Lang
  25717. * @param {*} value The value to inspect.
  25718. * @returns {Array} Returns the cast array.
  25719. * @example
  25720. *
  25721. * _.castArray(1);
  25722. * // => [1]
  25723. *
  25724. * _.castArray({ 'a': 1 });
  25725. * // => [{ 'a': 1 }]
  25726. *
  25727. * _.castArray('abc');
  25728. * // => ['abc']
  25729. *
  25730. * _.castArray(null);
  25731. * // => [null]
  25732. *
  25733. * _.castArray(undefined);
  25734. * // => [undefined]
  25735. *
  25736. * _.castArray();
  25737. * // => []
  25738. *
  25739. * var array = [1, 2, 3];
  25740. * console.log(_.castArray(array) === array);
  25741. * // => true
  25742. */
  25743. function castArray() {
  25744. if (!arguments.length) {
  25745. return [];
  25746. }
  25747. var value = arguments[0];
  25748. return isArray(value) ? value : [value];
  25749. }
  25750. /**
  25751. * Creates a shallow clone of `value`.
  25752. *
  25753. * **Note:** This method is loosely based on the
  25754. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  25755. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  25756. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  25757. * arrays. The own enumerable properties of `arguments` objects are cloned
  25758. * as plain objects. An empty object is returned for uncloneable values such
  25759. * as error objects, functions, DOM nodes, and WeakMaps.
  25760. *
  25761. * @static
  25762. * @memberOf _
  25763. * @since 0.1.0
  25764. * @category Lang
  25765. * @param {*} value The value to clone.
  25766. * @returns {*} Returns the cloned value.
  25767. * @see _.cloneDeep
  25768. * @example
  25769. *
  25770. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  25771. *
  25772. * var shallow = _.clone(objects);
  25773. * console.log(shallow[0] === objects[0]);
  25774. * // => true
  25775. */
  25776. function clone(value) {
  25777. return baseClone(value, false, true);
  25778. }
  25779. /**
  25780. * This method is like `_.clone` except that it accepts `customizer` which
  25781. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  25782. * cloning is handled by the method instead. The `customizer` is invoked with
  25783. * up to four arguments; (value [, index|key, object, stack]).
  25784. *
  25785. * @static
  25786. * @memberOf _
  25787. * @since 4.0.0
  25788. * @category Lang
  25789. * @param {*} value The value to clone.
  25790. * @param {Function} [customizer] The function to customize cloning.
  25791. * @returns {*} Returns the cloned value.
  25792. * @see _.cloneDeepWith
  25793. * @example
  25794. *
  25795. * function customizer(value) {
  25796. * if (_.isElement(value)) {
  25797. * return value.cloneNode(false);
  25798. * }
  25799. * }
  25800. *
  25801. * var el = _.cloneWith(document.body, customizer);
  25802. *
  25803. * console.log(el === document.body);
  25804. * // => false
  25805. * console.log(el.nodeName);
  25806. * // => 'BODY'
  25807. * console.log(el.childNodes.length);
  25808. * // => 0
  25809. */
  25810. function cloneWith(value, customizer) {
  25811. return baseClone(value, false, true, customizer);
  25812. }
  25813. /**
  25814. * This method is like `_.clone` except that it recursively clones `value`.
  25815. *
  25816. * @static
  25817. * @memberOf _
  25818. * @since 1.0.0
  25819. * @category Lang
  25820. * @param {*} value The value to recursively clone.
  25821. * @returns {*} Returns the deep cloned value.
  25822. * @see _.clone
  25823. * @example
  25824. *
  25825. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  25826. *
  25827. * var deep = _.cloneDeep(objects);
  25828. * console.log(deep[0] === objects[0]);
  25829. * // => false
  25830. */
  25831. function cloneDeep(value) {
  25832. return baseClone(value, true, true);
  25833. }
  25834. /**
  25835. * This method is like `_.cloneWith` except that it recursively clones `value`.
  25836. *
  25837. * @static
  25838. * @memberOf _
  25839. * @since 4.0.0
  25840. * @category Lang
  25841. * @param {*} value The value to recursively clone.
  25842. * @param {Function} [customizer] The function to customize cloning.
  25843. * @returns {*} Returns the deep cloned value.
  25844. * @see _.cloneWith
  25845. * @example
  25846. *
  25847. * function customizer(value) {
  25848. * if (_.isElement(value)) {
  25849. * return value.cloneNode(true);
  25850. * }
  25851. * }
  25852. *
  25853. * var el = _.cloneDeepWith(document.body, customizer);
  25854. *
  25855. * console.log(el === document.body);
  25856. * // => false
  25857. * console.log(el.nodeName);
  25858. * // => 'BODY'
  25859. * console.log(el.childNodes.length);
  25860. * // => 20
  25861. */
  25862. function cloneDeepWith(value, customizer) {
  25863. return baseClone(value, true, true, customizer);
  25864. }
  25865. /**
  25866. * Performs a
  25867. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  25868. * comparison between two values to determine if they are equivalent.
  25869. *
  25870. * @static
  25871. * @memberOf _
  25872. * @since 4.0.0
  25873. * @category Lang
  25874. * @param {*} value The value to compare.
  25875. * @param {*} other The other value to compare.
  25876. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  25877. * @example
  25878. *
  25879. * var object = { 'user': 'fred' };
  25880. * var other = { 'user': 'fred' };
  25881. *
  25882. * _.eq(object, object);
  25883. * // => true
  25884. *
  25885. * _.eq(object, other);
  25886. * // => false
  25887. *
  25888. * _.eq('a', 'a');
  25889. * // => true
  25890. *
  25891. * _.eq('a', Object('a'));
  25892. * // => false
  25893. *
  25894. * _.eq(NaN, NaN);
  25895. * // => true
  25896. */
  25897. function eq(value, other) {
  25898. return value === other || (value !== value && other !== other);
  25899. }
  25900. /**
  25901. * Checks if `value` is greater than `other`.
  25902. *
  25903. * @static
  25904. * @memberOf _
  25905. * @since 3.9.0
  25906. * @category Lang
  25907. * @param {*} value The value to compare.
  25908. * @param {*} other The other value to compare.
  25909. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  25910. * else `false`.
  25911. * @see _.lt
  25912. * @example
  25913. *
  25914. * _.gt(3, 1);
  25915. * // => true
  25916. *
  25917. * _.gt(3, 3);
  25918. * // => false
  25919. *
  25920. * _.gt(1, 3);
  25921. * // => false
  25922. */
  25923. var gt = createRelationalOperation(baseGt);
  25924. /**
  25925. * Checks if `value` is greater than or equal to `other`.
  25926. *
  25927. * @static
  25928. * @memberOf _
  25929. * @since 3.9.0
  25930. * @category Lang
  25931. * @param {*} value The value to compare.
  25932. * @param {*} other The other value to compare.
  25933. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  25934. * `other`, else `false`.
  25935. * @see _.lte
  25936. * @example
  25937. *
  25938. * _.gte(3, 1);
  25939. * // => true
  25940. *
  25941. * _.gte(3, 3);
  25942. * // => true
  25943. *
  25944. * _.gte(1, 3);
  25945. * // => false
  25946. */
  25947. var gte = createRelationalOperation(function(value, other) {
  25948. return value >= other;
  25949. });
  25950. /**
  25951. * Checks if `value` is likely an `arguments` object.
  25952. *
  25953. * @static
  25954. * @memberOf _
  25955. * @since 0.1.0
  25956. * @category Lang
  25957. * @param {*} value The value to check.
  25958. * @returns {boolean} Returns `true` if `value` is correctly classified,
  25959. * else `false`.
  25960. * @example
  25961. *
  25962. * _.isArguments(function() { return arguments; }());
  25963. * // => true
  25964. *
  25965. * _.isArguments([1, 2, 3]);
  25966. * // => false
  25967. */
  25968. function isArguments(value) {
  25969. // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
  25970. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  25971. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  25972. }
  25973. /**
  25974. * Checks if `value` is classified as an `Array` object.
  25975. *
  25976. * @static
  25977. * @memberOf _
  25978. * @since 0.1.0
  25979. * @type {Function}
  25980. * @category Lang
  25981. * @param {*} value The value to check.
  25982. * @returns {boolean} Returns `true` if `value` is correctly classified,
  25983. * else `false`.
  25984. * @example
  25985. *
  25986. * _.isArray([1, 2, 3]);
  25987. * // => true
  25988. *
  25989. * _.isArray(document.body.children);
  25990. * // => false
  25991. *
  25992. * _.isArray('abc');
  25993. * // => false
  25994. *
  25995. * _.isArray(_.noop);
  25996. * // => false
  25997. */
  25998. var isArray = Array.isArray;
  25999. /**
  26000. * Checks if `value` is classified as an `ArrayBuffer` object.
  26001. *
  26002. * @static
  26003. * @memberOf _
  26004. * @since 4.3.0
  26005. * @category Lang
  26006. * @param {*} value The value to check.
  26007. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26008. * else `false`.
  26009. * @example
  26010. *
  26011. * _.isArrayBuffer(new ArrayBuffer(2));
  26012. * // => true
  26013. *
  26014. * _.isArrayBuffer(new Array(2));
  26015. * // => false
  26016. */
  26017. function isArrayBuffer(value) {
  26018. return isObjectLike(value) && objectToString.call(value) == arrayBufferTag;
  26019. }
  26020. /**
  26021. * Checks if `value` is array-like. A value is considered array-like if it's
  26022. * not a function and has a `value.length` that's an integer greater than or
  26023. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  26024. *
  26025. * @static
  26026. * @memberOf _
  26027. * @since 4.0.0
  26028. * @category Lang
  26029. * @param {*} value The value to check.
  26030. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  26031. * @example
  26032. *
  26033. * _.isArrayLike([1, 2, 3]);
  26034. * // => true
  26035. *
  26036. * _.isArrayLike(document.body.children);
  26037. * // => true
  26038. *
  26039. * _.isArrayLike('abc');
  26040. * // => true
  26041. *
  26042. * _.isArrayLike(_.noop);
  26043. * // => false
  26044. */
  26045. function isArrayLike(value) {
  26046. return value != null && isLength(getLength(value)) && !isFunction(value);
  26047. }
  26048. /**
  26049. * This method is like `_.isArrayLike` except that it also checks if `value`
  26050. * is an object.
  26051. *
  26052. * @static
  26053. * @memberOf _
  26054. * @since 4.0.0
  26055. * @category Lang
  26056. * @param {*} value The value to check.
  26057. * @returns {boolean} Returns `true` if `value` is an array-like object,
  26058. * else `false`.
  26059. * @example
  26060. *
  26061. * _.isArrayLikeObject([1, 2, 3]);
  26062. * // => true
  26063. *
  26064. * _.isArrayLikeObject(document.body.children);
  26065. * // => true
  26066. *
  26067. * _.isArrayLikeObject('abc');
  26068. * // => false
  26069. *
  26070. * _.isArrayLikeObject(_.noop);
  26071. * // => false
  26072. */
  26073. function isArrayLikeObject(value) {
  26074. return isObjectLike(value) && isArrayLike(value);
  26075. }
  26076. /**
  26077. * Checks if `value` is classified as a boolean primitive or object.
  26078. *
  26079. * @static
  26080. * @memberOf _
  26081. * @since 0.1.0
  26082. * @category Lang
  26083. * @param {*} value The value to check.
  26084. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26085. * else `false`.
  26086. * @example
  26087. *
  26088. * _.isBoolean(false);
  26089. * // => true
  26090. *
  26091. * _.isBoolean(null);
  26092. * // => false
  26093. */
  26094. function isBoolean(value) {
  26095. return value === true || value === false ||
  26096. (isObjectLike(value) && objectToString.call(value) == boolTag);
  26097. }
  26098. /**
  26099. * Checks if `value` is a buffer.
  26100. *
  26101. * @static
  26102. * @memberOf _
  26103. * @since 4.3.0
  26104. * @category Lang
  26105. * @param {*} value The value to check.
  26106. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  26107. * @example
  26108. *
  26109. * _.isBuffer(new Buffer(2));
  26110. * // => true
  26111. *
  26112. * _.isBuffer(new Uint8Array(2));
  26113. * // => false
  26114. */
  26115. var isBuffer = !Buffer ? stubFalse : function(value) {
  26116. return value instanceof Buffer;
  26117. };
  26118. /**
  26119. * Checks if `value` is classified as a `Date` object.
  26120. *
  26121. * @static
  26122. * @memberOf _
  26123. * @since 0.1.0
  26124. * @category Lang
  26125. * @param {*} value The value to check.
  26126. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26127. * else `false`.
  26128. * @example
  26129. *
  26130. * _.isDate(new Date);
  26131. * // => true
  26132. *
  26133. * _.isDate('Mon April 23 2012');
  26134. * // => false
  26135. */
  26136. function isDate(value) {
  26137. return isObjectLike(value) && objectToString.call(value) == dateTag;
  26138. }
  26139. /**
  26140. * Checks if `value` is likely a DOM element.
  26141. *
  26142. * @static
  26143. * @memberOf _
  26144. * @since 0.1.0
  26145. * @category Lang
  26146. * @param {*} value The value to check.
  26147. * @returns {boolean} Returns `true` if `value` is a DOM element,
  26148. * else `false`.
  26149. * @example
  26150. *
  26151. * _.isElement(document.body);
  26152. * // => true
  26153. *
  26154. * _.isElement('<body>');
  26155. * // => false
  26156. */
  26157. function isElement(value) {
  26158. return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
  26159. }
  26160. /**
  26161. * Checks if `value` is an empty object, collection, map, or set.
  26162. *
  26163. * Objects are considered empty if they have no own enumerable string keyed
  26164. * properties.
  26165. *
  26166. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  26167. * jQuery-like collections are considered empty if they have a `length` of `0`.
  26168. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  26169. *
  26170. * @static
  26171. * @memberOf _
  26172. * @since 0.1.0
  26173. * @category Lang
  26174. * @param {*} value The value to check.
  26175. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  26176. * @example
  26177. *
  26178. * _.isEmpty(null);
  26179. * // => true
  26180. *
  26181. * _.isEmpty(true);
  26182. * // => true
  26183. *
  26184. * _.isEmpty(1);
  26185. * // => true
  26186. *
  26187. * _.isEmpty([1, 2, 3]);
  26188. * // => false
  26189. *
  26190. * _.isEmpty({ 'a': 1 });
  26191. * // => false
  26192. */
  26193. function isEmpty(value) {
  26194. if (isArrayLike(value) &&
  26195. (isArray(value) || isString(value) || isFunction(value.splice) ||
  26196. isArguments(value) || isBuffer(value))) {
  26197. return !value.length;
  26198. }
  26199. if (isObjectLike(value)) {
  26200. var tag = getTag(value);
  26201. if (tag == mapTag || tag == setTag) {
  26202. return !value.size;
  26203. }
  26204. }
  26205. for (var key in value) {
  26206. if (hasOwnProperty.call(value, key)) {
  26207. return false;
  26208. }
  26209. }
  26210. return !(nonEnumShadows && keys(value).length);
  26211. }
  26212. /**
  26213. * Performs a deep comparison between two values to determine if they are
  26214. * equivalent.
  26215. *
  26216. * **Note:** This method supports comparing arrays, array buffers, booleans,
  26217. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  26218. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  26219. * by their own, not inherited, enumerable properties. Functions and DOM
  26220. * nodes are **not** supported.
  26221. *
  26222. * @static
  26223. * @memberOf _
  26224. * @since 0.1.0
  26225. * @category Lang
  26226. * @param {*} value The value to compare.
  26227. * @param {*} other The other value to compare.
  26228. * @returns {boolean} Returns `true` if the values are equivalent,
  26229. * else `false`.
  26230. * @example
  26231. *
  26232. * var object = { 'user': 'fred' };
  26233. * var other = { 'user': 'fred' };
  26234. *
  26235. * _.isEqual(object, other);
  26236. * // => true
  26237. *
  26238. * object === other;
  26239. * // => false
  26240. */
  26241. function isEqual(value, other) {
  26242. return baseIsEqual(value, other);
  26243. }
  26244. /**
  26245. * This method is like `_.isEqual` except that it accepts `customizer` which
  26246. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  26247. * are handled by the method instead. The `customizer` is invoked with up to
  26248. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  26249. *
  26250. * @static
  26251. * @memberOf _
  26252. * @since 4.0.0
  26253. * @category Lang
  26254. * @param {*} value The value to compare.
  26255. * @param {*} other The other value to compare.
  26256. * @param {Function} [customizer] The function to customize comparisons.
  26257. * @returns {boolean} Returns `true` if the values are equivalent,
  26258. * else `false`.
  26259. * @example
  26260. *
  26261. * function isGreeting(value) {
  26262. * return /^h(?:i|ello)$/.test(value);
  26263. * }
  26264. *
  26265. * function customizer(objValue, othValue) {
  26266. * if (isGreeting(objValue) && isGreeting(othValue)) {
  26267. * return true;
  26268. * }
  26269. * }
  26270. *
  26271. * var array = ['hello', 'goodbye'];
  26272. * var other = ['hi', 'goodbye'];
  26273. *
  26274. * _.isEqualWith(array, other, customizer);
  26275. * // => true
  26276. */
  26277. function isEqualWith(value, other, customizer) {
  26278. customizer = typeof customizer == 'function' ? customizer : undefined;
  26279. var result = customizer ? customizer(value, other) : undefined;
  26280. return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
  26281. }
  26282. /**
  26283. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  26284. * `SyntaxError`, `TypeError`, or `URIError` object.
  26285. *
  26286. * @static
  26287. * @memberOf _
  26288. * @since 3.0.0
  26289. * @category Lang
  26290. * @param {*} value The value to check.
  26291. * @returns {boolean} Returns `true` if `value` is an error object,
  26292. * else `false`.
  26293. * @example
  26294. *
  26295. * _.isError(new Error);
  26296. * // => true
  26297. *
  26298. * _.isError(Error);
  26299. * // => false
  26300. */
  26301. function isError(value) {
  26302. if (!isObjectLike(value)) {
  26303. return false;
  26304. }
  26305. return (objectToString.call(value) == errorTag) ||
  26306. (typeof value.message == 'string' && typeof value.name == 'string');
  26307. }
  26308. /**
  26309. * Checks if `value` is a finite primitive number.
  26310. *
  26311. * **Note:** This method is based on
  26312. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  26313. *
  26314. * @static
  26315. * @memberOf _
  26316. * @since 0.1.0
  26317. * @category Lang
  26318. * @param {*} value The value to check.
  26319. * @returns {boolean} Returns `true` if `value` is a finite number,
  26320. * else `false`.
  26321. * @example
  26322. *
  26323. * _.isFinite(3);
  26324. * // => true
  26325. *
  26326. * _.isFinite(Number.MIN_VALUE);
  26327. * // => true
  26328. *
  26329. * _.isFinite(Infinity);
  26330. * // => false
  26331. *
  26332. * _.isFinite('3');
  26333. * // => false
  26334. */
  26335. function isFinite(value) {
  26336. return typeof value == 'number' && nativeIsFinite(value);
  26337. }
  26338. /**
  26339. * Checks if `value` is classified as a `Function` object.
  26340. *
  26341. * @static
  26342. * @memberOf _
  26343. * @since 0.1.0
  26344. * @category Lang
  26345. * @param {*} value The value to check.
  26346. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26347. * else `false`.
  26348. * @example
  26349. *
  26350. * _.isFunction(_);
  26351. * // => true
  26352. *
  26353. * _.isFunction(/abc/);
  26354. * // => false
  26355. */
  26356. function isFunction(value) {
  26357. // The use of `Object#toString` avoids issues with the `typeof` operator
  26358. // in Safari 8 which returns 'object' for typed array and weak map constructors,
  26359. // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
  26360. var tag = isObject(value) ? objectToString.call(value) : '';
  26361. return tag == funcTag || tag == genTag;
  26362. }
  26363. /**
  26364. * Checks if `value` is an integer.
  26365. *
  26366. * **Note:** This method is based on
  26367. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  26368. *
  26369. * @static
  26370. * @memberOf _
  26371. * @since 4.0.0
  26372. * @category Lang
  26373. * @param {*} value The value to check.
  26374. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  26375. * @example
  26376. *
  26377. * _.isInteger(3);
  26378. * // => true
  26379. *
  26380. * _.isInteger(Number.MIN_VALUE);
  26381. * // => false
  26382. *
  26383. * _.isInteger(Infinity);
  26384. * // => false
  26385. *
  26386. * _.isInteger('3');
  26387. * // => false
  26388. */
  26389. function isInteger(value) {
  26390. return typeof value == 'number' && value == toInteger(value);
  26391. }
  26392. /**
  26393. * Checks if `value` is a valid array-like length.
  26394. *
  26395. * **Note:** This function is loosely based on
  26396. * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  26397. *
  26398. * @static
  26399. * @memberOf _
  26400. * @since 4.0.0
  26401. * @category Lang
  26402. * @param {*} value The value to check.
  26403. * @returns {boolean} Returns `true` if `value` is a valid length,
  26404. * else `false`.
  26405. * @example
  26406. *
  26407. * _.isLength(3);
  26408. * // => true
  26409. *
  26410. * _.isLength(Number.MIN_VALUE);
  26411. * // => false
  26412. *
  26413. * _.isLength(Infinity);
  26414. * // => false
  26415. *
  26416. * _.isLength('3');
  26417. * // => false
  26418. */
  26419. function isLength(value) {
  26420. return typeof value == 'number' &&
  26421. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  26422. }
  26423. /**
  26424. * Checks if `value` is the
  26425. * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types)
  26426. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  26427. *
  26428. * @static
  26429. * @memberOf _
  26430. * @since 0.1.0
  26431. * @category Lang
  26432. * @param {*} value The value to check.
  26433. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  26434. * @example
  26435. *
  26436. * _.isObject({});
  26437. * // => true
  26438. *
  26439. * _.isObject([1, 2, 3]);
  26440. * // => true
  26441. *
  26442. * _.isObject(_.noop);
  26443. * // => true
  26444. *
  26445. * _.isObject(null);
  26446. * // => false
  26447. */
  26448. function isObject(value) {
  26449. var type = typeof value;
  26450. return !!value && (type == 'object' || type == 'function');
  26451. }
  26452. /**
  26453. * Checks if `value` is object-like. A value is object-like if it's not `null`
  26454. * and has a `typeof` result of "object".
  26455. *
  26456. * @static
  26457. * @memberOf _
  26458. * @since 4.0.0
  26459. * @category Lang
  26460. * @param {*} value The value to check.
  26461. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  26462. * @example
  26463. *
  26464. * _.isObjectLike({});
  26465. * // => true
  26466. *
  26467. * _.isObjectLike([1, 2, 3]);
  26468. * // => true
  26469. *
  26470. * _.isObjectLike(_.noop);
  26471. * // => false
  26472. *
  26473. * _.isObjectLike(null);
  26474. * // => false
  26475. */
  26476. function isObjectLike(value) {
  26477. return !!value && typeof value == 'object';
  26478. }
  26479. /**
  26480. * Checks if `value` is classified as a `Map` object.
  26481. *
  26482. * @static
  26483. * @memberOf _
  26484. * @since 4.3.0
  26485. * @category Lang
  26486. * @param {*} value The value to check.
  26487. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26488. * else `false`.
  26489. * @example
  26490. *
  26491. * _.isMap(new Map);
  26492. * // => true
  26493. *
  26494. * _.isMap(new WeakMap);
  26495. * // => false
  26496. */
  26497. function isMap(value) {
  26498. return isObjectLike(value) && getTag(value) == mapTag;
  26499. }
  26500. /**
  26501. * Performs a partial deep comparison between `object` and `source` to
  26502. * determine if `object` contains equivalent property values. This method is
  26503. * equivalent to a `_.matches` function when `source` is partially applied.
  26504. *
  26505. * **Note:** This method supports comparing the same values as `_.isEqual`.
  26506. *
  26507. * @static
  26508. * @memberOf _
  26509. * @since 3.0.0
  26510. * @category Lang
  26511. * @param {Object} object The object to inspect.
  26512. * @param {Object} source The object of property values to match.
  26513. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  26514. * @example
  26515. *
  26516. * var object = { 'user': 'fred', 'age': 40 };
  26517. *
  26518. * _.isMatch(object, { 'age': 40 });
  26519. * // => true
  26520. *
  26521. * _.isMatch(object, { 'age': 36 });
  26522. * // => false
  26523. */
  26524. function isMatch(object, source) {
  26525. return object === source || baseIsMatch(object, source, getMatchData(source));
  26526. }
  26527. /**
  26528. * This method is like `_.isMatch` except that it accepts `customizer` which
  26529. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  26530. * are handled by the method instead. The `customizer` is invoked with five
  26531. * arguments: (objValue, srcValue, index|key, object, source).
  26532. *
  26533. * @static
  26534. * @memberOf _
  26535. * @since 4.0.0
  26536. * @category Lang
  26537. * @param {Object} object The object to inspect.
  26538. * @param {Object} source The object of property values to match.
  26539. * @param {Function} [customizer] The function to customize comparisons.
  26540. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  26541. * @example
  26542. *
  26543. * function isGreeting(value) {
  26544. * return /^h(?:i|ello)$/.test(value);
  26545. * }
  26546. *
  26547. * function customizer(objValue, srcValue) {
  26548. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  26549. * return true;
  26550. * }
  26551. * }
  26552. *
  26553. * var object = { 'greeting': 'hello' };
  26554. * var source = { 'greeting': 'hi' };
  26555. *
  26556. * _.isMatchWith(object, source, customizer);
  26557. * // => true
  26558. */
  26559. function isMatchWith(object, source, customizer) {
  26560. customizer = typeof customizer == 'function' ? customizer : undefined;
  26561. return baseIsMatch(object, source, getMatchData(source), customizer);
  26562. }
  26563. /**
  26564. * Checks if `value` is `NaN`.
  26565. *
  26566. * **Note:** This method is based on
  26567. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  26568. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  26569. * `undefined` and other non-number values.
  26570. *
  26571. * @static
  26572. * @memberOf _
  26573. * @since 0.1.0
  26574. * @category Lang
  26575. * @param {*} value The value to check.
  26576. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  26577. * @example
  26578. *
  26579. * _.isNaN(NaN);
  26580. * // => true
  26581. *
  26582. * _.isNaN(new Number(NaN));
  26583. * // => true
  26584. *
  26585. * isNaN(undefined);
  26586. * // => true
  26587. *
  26588. * _.isNaN(undefined);
  26589. * // => false
  26590. */
  26591. function isNaN(value) {
  26592. // An `NaN` primitive is the only value that is not equal to itself.
  26593. // Perform the `toStringTag` check first to avoid errors with some
  26594. // ActiveX objects in IE.
  26595. return isNumber(value) && value != +value;
  26596. }
  26597. /**
  26598. * Checks if `value` is a pristine native function.
  26599. *
  26600. * **Note:** This method can't reliably detect native functions in the
  26601. * presence of the `core-js` package because `core-js` circumvents this kind
  26602. * of detection. Despite multiple requests, the `core-js` maintainer has made
  26603. * it clear: any attempt to fix the detection will be obstructed. As a result,
  26604. * we're left with little choice but to throw an error. Unfortunately, this
  26605. * also affects packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  26606. * which rely on `core-js`.
  26607. *
  26608. * @static
  26609. * @memberOf _
  26610. * @since 3.0.0
  26611. * @category Lang
  26612. * @param {*} value The value to check.
  26613. * @returns {boolean} Returns `true` if `value` is a native function,
  26614. * else `false`.
  26615. * @example
  26616. *
  26617. * _.isNative(Array.prototype.push);
  26618. * // => true
  26619. *
  26620. * _.isNative(_);
  26621. * // => false
  26622. */
  26623. function isNative(value) {
  26624. if (isMaskable(value)) {
  26625. throw new Error('This method is not supported with `core-js`. Try https://github.com/es-shims.');
  26626. }
  26627. return baseIsNative(value);
  26628. }
  26629. /**
  26630. * Checks if `value` is `null`.
  26631. *
  26632. * @static
  26633. * @memberOf _
  26634. * @since 0.1.0
  26635. * @category Lang
  26636. * @param {*} value The value to check.
  26637. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  26638. * @example
  26639. *
  26640. * _.isNull(null);
  26641. * // => true
  26642. *
  26643. * _.isNull(void 0);
  26644. * // => false
  26645. */
  26646. function isNull(value) {
  26647. return value === null;
  26648. }
  26649. /**
  26650. * Checks if `value` is `null` or `undefined`.
  26651. *
  26652. * @static
  26653. * @memberOf _
  26654. * @since 4.0.0
  26655. * @category Lang
  26656. * @param {*} value The value to check.
  26657. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  26658. * @example
  26659. *
  26660. * _.isNil(null);
  26661. * // => true
  26662. *
  26663. * _.isNil(void 0);
  26664. * // => true
  26665. *
  26666. * _.isNil(NaN);
  26667. * // => false
  26668. */
  26669. function isNil(value) {
  26670. return value == null;
  26671. }
  26672. /**
  26673. * Checks if `value` is classified as a `Number` primitive or object.
  26674. *
  26675. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  26676. * classified as numbers, use the `_.isFinite` method.
  26677. *
  26678. * @static
  26679. * @memberOf _
  26680. * @since 0.1.0
  26681. * @category Lang
  26682. * @param {*} value The value to check.
  26683. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26684. * else `false`.
  26685. * @example
  26686. *
  26687. * _.isNumber(3);
  26688. * // => true
  26689. *
  26690. * _.isNumber(Number.MIN_VALUE);
  26691. * // => true
  26692. *
  26693. * _.isNumber(Infinity);
  26694. * // => true
  26695. *
  26696. * _.isNumber('3');
  26697. * // => false
  26698. */
  26699. function isNumber(value) {
  26700. return typeof value == 'number' ||
  26701. (isObjectLike(value) && objectToString.call(value) == numberTag);
  26702. }
  26703. /**
  26704. * Checks if `value` is a plain object, that is, an object created by the
  26705. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  26706. *
  26707. * @static
  26708. * @memberOf _
  26709. * @since 0.8.0
  26710. * @category Lang
  26711. * @param {*} value The value to check.
  26712. * @returns {boolean} Returns `true` if `value` is a plain object,
  26713. * else `false`.
  26714. * @example
  26715. *
  26716. * function Foo() {
  26717. * this.a = 1;
  26718. * }
  26719. *
  26720. * _.isPlainObject(new Foo);
  26721. * // => false
  26722. *
  26723. * _.isPlainObject([1, 2, 3]);
  26724. * // => false
  26725. *
  26726. * _.isPlainObject({ 'x': 0, 'y': 0 });
  26727. * // => true
  26728. *
  26729. * _.isPlainObject(Object.create(null));
  26730. * // => true
  26731. */
  26732. function isPlainObject(value) {
  26733. if (!isObjectLike(value) ||
  26734. objectToString.call(value) != objectTag || isHostObject(value)) {
  26735. return false;
  26736. }
  26737. var proto = getPrototype(value);
  26738. if (proto === null) {
  26739. return true;
  26740. }
  26741. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  26742. return (typeof Ctor == 'function' &&
  26743. Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
  26744. }
  26745. /**
  26746. * Checks if `value` is classified as a `RegExp` object.
  26747. *
  26748. * @static
  26749. * @memberOf _
  26750. * @since 0.1.0
  26751. * @category Lang
  26752. * @param {*} value The value to check.
  26753. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26754. * else `false`.
  26755. * @example
  26756. *
  26757. * _.isRegExp(/abc/);
  26758. * // => true
  26759. *
  26760. * _.isRegExp('/abc/');
  26761. * // => false
  26762. */
  26763. function isRegExp(value) {
  26764. return isObject(value) && objectToString.call(value) == regexpTag;
  26765. }
  26766. /**
  26767. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  26768. * double precision number which isn't the result of a rounded unsafe integer.
  26769. *
  26770. * **Note:** This method is based on
  26771. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  26772. *
  26773. * @static
  26774. * @memberOf _
  26775. * @since 4.0.0
  26776. * @category Lang
  26777. * @param {*} value The value to check.
  26778. * @returns {boolean} Returns `true` if `value` is a safe integer,
  26779. * else `false`.
  26780. * @example
  26781. *
  26782. * _.isSafeInteger(3);
  26783. * // => true
  26784. *
  26785. * _.isSafeInteger(Number.MIN_VALUE);
  26786. * // => false
  26787. *
  26788. * _.isSafeInteger(Infinity);
  26789. * // => false
  26790. *
  26791. * _.isSafeInteger('3');
  26792. * // => false
  26793. */
  26794. function isSafeInteger(value) {
  26795. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  26796. }
  26797. /**
  26798. * Checks if `value` is classified as a `Set` object.
  26799. *
  26800. * @static
  26801. * @memberOf _
  26802. * @since 4.3.0
  26803. * @category Lang
  26804. * @param {*} value The value to check.
  26805. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26806. * else `false`.
  26807. * @example
  26808. *
  26809. * _.isSet(new Set);
  26810. * // => true
  26811. *
  26812. * _.isSet(new WeakSet);
  26813. * // => false
  26814. */
  26815. function isSet(value) {
  26816. return isObjectLike(value) && getTag(value) == setTag;
  26817. }
  26818. /**
  26819. * Checks if `value` is classified as a `String` primitive or object.
  26820. *
  26821. * @static
  26822. * @since 0.1.0
  26823. * @memberOf _
  26824. * @category Lang
  26825. * @param {*} value The value to check.
  26826. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26827. * else `false`.
  26828. * @example
  26829. *
  26830. * _.isString('abc');
  26831. * // => true
  26832. *
  26833. * _.isString(1);
  26834. * // => false
  26835. */
  26836. function isString(value) {
  26837. return typeof value == 'string' ||
  26838. (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
  26839. }
  26840. /**
  26841. * Checks if `value` is classified as a `Symbol` primitive or object.
  26842. *
  26843. * @static
  26844. * @memberOf _
  26845. * @since 4.0.0
  26846. * @category Lang
  26847. * @param {*} value The value to check.
  26848. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26849. * else `false`.
  26850. * @example
  26851. *
  26852. * _.isSymbol(Symbol.iterator);
  26853. * // => true
  26854. *
  26855. * _.isSymbol('abc');
  26856. * // => false
  26857. */
  26858. function isSymbol(value) {
  26859. return typeof value == 'symbol' ||
  26860. (isObjectLike(value) && objectToString.call(value) == symbolTag);
  26861. }
  26862. /**
  26863. * Checks if `value` is classified as a typed array.
  26864. *
  26865. * @static
  26866. * @memberOf _
  26867. * @since 3.0.0
  26868. * @category Lang
  26869. * @param {*} value The value to check.
  26870. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26871. * else `false`.
  26872. * @example
  26873. *
  26874. * _.isTypedArray(new Uint8Array);
  26875. * // => true
  26876. *
  26877. * _.isTypedArray([]);
  26878. * // => false
  26879. */
  26880. function isTypedArray(value) {
  26881. return isObjectLike(value) &&
  26882. isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
  26883. }
  26884. /**
  26885. * Checks if `value` is `undefined`.
  26886. *
  26887. * @static
  26888. * @since 0.1.0
  26889. * @memberOf _
  26890. * @category Lang
  26891. * @param {*} value The value to check.
  26892. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  26893. * @example
  26894. *
  26895. * _.isUndefined(void 0);
  26896. * // => true
  26897. *
  26898. * _.isUndefined(null);
  26899. * // => false
  26900. */
  26901. function isUndefined(value) {
  26902. return value === undefined;
  26903. }
  26904. /**
  26905. * Checks if `value` is classified as a `WeakMap` object.
  26906. *
  26907. * @static
  26908. * @memberOf _
  26909. * @since 4.3.0
  26910. * @category Lang
  26911. * @param {*} value The value to check.
  26912. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26913. * else `false`.
  26914. * @example
  26915. *
  26916. * _.isWeakMap(new WeakMap);
  26917. * // => true
  26918. *
  26919. * _.isWeakMap(new Map);
  26920. * // => false
  26921. */
  26922. function isWeakMap(value) {
  26923. return isObjectLike(value) && getTag(value) == weakMapTag;
  26924. }
  26925. /**
  26926. * Checks if `value` is classified as a `WeakSet` object.
  26927. *
  26928. * @static
  26929. * @memberOf _
  26930. * @since 4.3.0
  26931. * @category Lang
  26932. * @param {*} value The value to check.
  26933. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26934. * else `false`.
  26935. * @example
  26936. *
  26937. * _.isWeakSet(new WeakSet);
  26938. * // => true
  26939. *
  26940. * _.isWeakSet(new Set);
  26941. * // => false
  26942. */
  26943. function isWeakSet(value) {
  26944. return isObjectLike(value) && objectToString.call(value) == weakSetTag;
  26945. }
  26946. /**
  26947. * Checks if `value` is less than `other`.
  26948. *
  26949. * @static
  26950. * @memberOf _
  26951. * @since 3.9.0
  26952. * @category Lang
  26953. * @param {*} value The value to compare.
  26954. * @param {*} other The other value to compare.
  26955. * @returns {boolean} Returns `true` if `value` is less than `other`,
  26956. * else `false`.
  26957. * @see _.gt
  26958. * @example
  26959. *
  26960. * _.lt(1, 3);
  26961. * // => true
  26962. *
  26963. * _.lt(3, 3);
  26964. * // => false
  26965. *
  26966. * _.lt(3, 1);
  26967. * // => false
  26968. */
  26969. var lt = createRelationalOperation(baseLt);
  26970. /**
  26971. * Checks if `value` is less than or equal to `other`.
  26972. *
  26973. * @static
  26974. * @memberOf _
  26975. * @since 3.9.0
  26976. * @category Lang
  26977. * @param {*} value The value to compare.
  26978. * @param {*} other The other value to compare.
  26979. * @returns {boolean} Returns `true` if `value` is less than or equal to
  26980. * `other`, else `false`.
  26981. * @see _.gte
  26982. * @example
  26983. *
  26984. * _.lte(1, 3);
  26985. * // => true
  26986. *
  26987. * _.lte(3, 3);
  26988. * // => true
  26989. *
  26990. * _.lte(3, 1);
  26991. * // => false
  26992. */
  26993. var lte = createRelationalOperation(function(value, other) {
  26994. return value <= other;
  26995. });
  26996. /**
  26997. * Converts `value` to an array.
  26998. *
  26999. * @static
  27000. * @since 0.1.0
  27001. * @memberOf _
  27002. * @category Lang
  27003. * @param {*} value The value to convert.
  27004. * @returns {Array} Returns the converted array.
  27005. * @example
  27006. *
  27007. * _.toArray({ 'a': 1, 'b': 2 });
  27008. * // => [1, 2]
  27009. *
  27010. * _.toArray('abc');
  27011. * // => ['a', 'b', 'c']
  27012. *
  27013. * _.toArray(1);
  27014. * // => []
  27015. *
  27016. * _.toArray(null);
  27017. * // => []
  27018. */
  27019. function toArray(value) {
  27020. if (!value) {
  27021. return [];
  27022. }
  27023. if (isArrayLike(value)) {
  27024. return isString(value) ? stringToArray(value) : copyArray(value);
  27025. }
  27026. if (iteratorSymbol && value[iteratorSymbol]) {
  27027. return iteratorToArray(value[iteratorSymbol]());
  27028. }
  27029. var tag = getTag(value),
  27030. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  27031. return func(value);
  27032. }
  27033. /**
  27034. * Converts `value` to a finite number.
  27035. *
  27036. * @static
  27037. * @memberOf _
  27038. * @since 4.12.0
  27039. * @category Lang
  27040. * @param {*} value The value to convert.
  27041. * @returns {number} Returns the converted number.
  27042. * @example
  27043. *
  27044. * _.toFinite(3.2);
  27045. * // => 3.2
  27046. *
  27047. * _.toFinite(Number.MIN_VALUE);
  27048. * // => 5e-324
  27049. *
  27050. * _.toFinite(Infinity);
  27051. * // => 1.7976931348623157e+308
  27052. *
  27053. * _.toFinite('3.2');
  27054. * // => 3.2
  27055. */
  27056. function toFinite(value) {
  27057. if (!value) {
  27058. return value === 0 ? value : 0;
  27059. }
  27060. value = toNumber(value);
  27061. if (value === INFINITY || value === -INFINITY) {
  27062. var sign = (value < 0 ? -1 : 1);
  27063. return sign * MAX_INTEGER;
  27064. }
  27065. return value === value ? value : 0;
  27066. }
  27067. /**
  27068. * Converts `value` to an integer.
  27069. *
  27070. * **Note:** This method is loosely based on
  27071. * [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
  27072. *
  27073. * @static
  27074. * @memberOf _
  27075. * @since 4.0.0
  27076. * @category Lang
  27077. * @param {*} value The value to convert.
  27078. * @returns {number} Returns the converted integer.
  27079. * @example
  27080. *
  27081. * _.toInteger(3.2);
  27082. * // => 3
  27083. *
  27084. * _.toInteger(Number.MIN_VALUE);
  27085. * // => 0
  27086. *
  27087. * _.toInteger(Infinity);
  27088. * // => 1.7976931348623157e+308
  27089. *
  27090. * _.toInteger('3.2');
  27091. * // => 3
  27092. */
  27093. function toInteger(value) {
  27094. var result = toFinite(value),
  27095. remainder = result % 1;
  27096. return result === result ? (remainder ? result - remainder : result) : 0;
  27097. }
  27098. /**
  27099. * Converts `value` to an integer suitable for use as the length of an
  27100. * array-like object.
  27101. *
  27102. * **Note:** This method is based on
  27103. * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  27104. *
  27105. * @static
  27106. * @memberOf _
  27107. * @since 4.0.0
  27108. * @category Lang
  27109. * @param {*} value The value to convert.
  27110. * @returns {number} Returns the converted integer.
  27111. * @example
  27112. *
  27113. * _.toLength(3.2);
  27114. * // => 3
  27115. *
  27116. * _.toLength(Number.MIN_VALUE);
  27117. * // => 0
  27118. *
  27119. * _.toLength(Infinity);
  27120. * // => 4294967295
  27121. *
  27122. * _.toLength('3.2');
  27123. * // => 3
  27124. */
  27125. function toLength(value) {
  27126. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  27127. }
  27128. /**
  27129. * Converts `value` to a number.
  27130. *
  27131. * @static
  27132. * @memberOf _
  27133. * @since 4.0.0
  27134. * @category Lang
  27135. * @param {*} value The value to process.
  27136. * @returns {number} Returns the number.
  27137. * @example
  27138. *
  27139. * _.toNumber(3.2);
  27140. * // => 3.2
  27141. *
  27142. * _.toNumber(Number.MIN_VALUE);
  27143. * // => 5e-324
  27144. *
  27145. * _.toNumber(Infinity);
  27146. * // => Infinity
  27147. *
  27148. * _.toNumber('3.2');
  27149. * // => 3.2
  27150. */
  27151. function toNumber(value) {
  27152. if (typeof value == 'number') {
  27153. return value;
  27154. }
  27155. if (isSymbol(value)) {
  27156. return NAN;
  27157. }
  27158. if (isObject(value)) {
  27159. var other = isFunction(value.valueOf) ? value.valueOf() : value;
  27160. value = isObject(other) ? (other + '') : other;
  27161. }
  27162. if (typeof value != 'string') {
  27163. return value === 0 ? value : +value;
  27164. }
  27165. value = value.replace(reTrim, '');
  27166. var isBinary = reIsBinary.test(value);
  27167. return (isBinary || reIsOctal.test(value))
  27168. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  27169. : (reIsBadHex.test(value) ? NAN : +value);
  27170. }
  27171. /**
  27172. * Converts `value` to a plain object flattening inherited enumerable string
  27173. * keyed properties of `value` to own properties of the plain object.
  27174. *
  27175. * @static
  27176. * @memberOf _
  27177. * @since 3.0.0
  27178. * @category Lang
  27179. * @param {*} value The value to convert.
  27180. * @returns {Object} Returns the converted plain object.
  27181. * @example
  27182. *
  27183. * function Foo() {
  27184. * this.b = 2;
  27185. * }
  27186. *
  27187. * Foo.prototype.c = 3;
  27188. *
  27189. * _.assign({ 'a': 1 }, new Foo);
  27190. * // => { 'a': 1, 'b': 2 }
  27191. *
  27192. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  27193. * // => { 'a': 1, 'b': 2, 'c': 3 }
  27194. */
  27195. function toPlainObject(value) {
  27196. return copyObject(value, keysIn(value));
  27197. }
  27198. /**
  27199. * Converts `value` to a safe integer. A safe integer can be compared and
  27200. * represented correctly.
  27201. *
  27202. * @static
  27203. * @memberOf _
  27204. * @since 4.0.0
  27205. * @category Lang
  27206. * @param {*} value The value to convert.
  27207. * @returns {number} Returns the converted integer.
  27208. * @example
  27209. *
  27210. * _.toSafeInteger(3.2);
  27211. * // => 3
  27212. *
  27213. * _.toSafeInteger(Number.MIN_VALUE);
  27214. * // => 0
  27215. *
  27216. * _.toSafeInteger(Infinity);
  27217. * // => 9007199254740991
  27218. *
  27219. * _.toSafeInteger('3.2');
  27220. * // => 3
  27221. */
  27222. function toSafeInteger(value) {
  27223. return baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
  27224. }
  27225. /**
  27226. * Converts `value` to a string. An empty string is returned for `null`
  27227. * and `undefined` values. The sign of `-0` is preserved.
  27228. *
  27229. * @static
  27230. * @memberOf _
  27231. * @since 4.0.0
  27232. * @category Lang
  27233. * @param {*} value The value to process.
  27234. * @returns {string} Returns the string.
  27235. * @example
  27236. *
  27237. * _.toString(null);
  27238. * // => ''
  27239. *
  27240. * _.toString(-0);
  27241. * // => '-0'
  27242. *
  27243. * _.toString([1, 2, 3]);
  27244. * // => '1,2,3'
  27245. */
  27246. function toString(value) {
  27247. return value == null ? '' : baseToString(value);
  27248. }
  27249. /*------------------------------------------------------------------------*/
  27250. /**
  27251. * Assigns own enumerable string keyed properties of source objects to the
  27252. * destination object. Source objects are applied from left to right.
  27253. * Subsequent sources overwrite property assignments of previous sources.
  27254. *
  27255. * **Note:** This method mutates `object` and is loosely based on
  27256. * [`Object.assign`](https://mdn.io/Object/assign).
  27257. *
  27258. * @static
  27259. * @memberOf _
  27260. * @since 0.10.0
  27261. * @category Object
  27262. * @param {Object} object The destination object.
  27263. * @param {...Object} [sources] The source objects.
  27264. * @returns {Object} Returns `object`.
  27265. * @see _.assignIn
  27266. * @example
  27267. *
  27268. * function Foo() {
  27269. * this.c = 3;
  27270. * }
  27271. *
  27272. * function Bar() {
  27273. * this.e = 5;
  27274. * }
  27275. *
  27276. * Foo.prototype.d = 4;
  27277. * Bar.prototype.f = 6;
  27278. *
  27279. * _.assign({ 'a': 1 }, new Foo, new Bar);
  27280. * // => { 'a': 1, 'c': 3, 'e': 5 }
  27281. */
  27282. var assign = createAssigner(function(object, source) {
  27283. if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) {
  27284. copyObject(source, keys(source), object);
  27285. return;
  27286. }
  27287. for (var key in source) {
  27288. if (hasOwnProperty.call(source, key)) {
  27289. assignValue(object, key, source[key]);
  27290. }
  27291. }
  27292. });
  27293. /**
  27294. * This method is like `_.assign` except that it iterates over own and
  27295. * inherited source properties.
  27296. *
  27297. * **Note:** This method mutates `object`.
  27298. *
  27299. * @static
  27300. * @memberOf _
  27301. * @since 4.0.0
  27302. * @alias extend
  27303. * @category Object
  27304. * @param {Object} object The destination object.
  27305. * @param {...Object} [sources] The source objects.
  27306. * @returns {Object} Returns `object`.
  27307. * @see _.assign
  27308. * @example
  27309. *
  27310. * function Foo() {
  27311. * this.b = 2;
  27312. * }
  27313. *
  27314. * function Bar() {
  27315. * this.d = 4;
  27316. * }
  27317. *
  27318. * Foo.prototype.c = 3;
  27319. * Bar.prototype.e = 5;
  27320. *
  27321. * _.assignIn({ 'a': 1 }, new Foo, new Bar);
  27322. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
  27323. */
  27324. var assignIn = createAssigner(function(object, source) {
  27325. if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) {
  27326. copyObject(source, keysIn(source), object);
  27327. return;
  27328. }
  27329. for (var key in source) {
  27330. assignValue(object, key, source[key]);
  27331. }
  27332. });
  27333. /**
  27334. * This method is like `_.assignIn` except that it accepts `customizer`
  27335. * which is invoked to produce the assigned values. If `customizer` returns
  27336. * `undefined`, assignment is handled by the method instead. The `customizer`
  27337. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  27338. *
  27339. * **Note:** This method mutates `object`.
  27340. *
  27341. * @static
  27342. * @memberOf _
  27343. * @since 4.0.0
  27344. * @alias extendWith
  27345. * @category Object
  27346. * @param {Object} object The destination object.
  27347. * @param {...Object} sources The source objects.
  27348. * @param {Function} [customizer] The function to customize assigned values.
  27349. * @returns {Object} Returns `object`.
  27350. * @see _.assignWith
  27351. * @example
  27352. *
  27353. * function customizer(objValue, srcValue) {
  27354. * return _.isUndefined(objValue) ? srcValue : objValue;
  27355. * }
  27356. *
  27357. * var defaults = _.partialRight(_.assignInWith, customizer);
  27358. *
  27359. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  27360. * // => { 'a': 1, 'b': 2 }
  27361. */
  27362. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  27363. copyObject(source, keysIn(source), object, customizer);
  27364. });
  27365. /**
  27366. * This method is like `_.assign` except that it accepts `customizer`
  27367. * which is invoked to produce the assigned values. If `customizer` returns
  27368. * `undefined`, assignment is handled by the method instead. The `customizer`
  27369. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  27370. *
  27371. * **Note:** This method mutates `object`.
  27372. *
  27373. * @static
  27374. * @memberOf _
  27375. * @since 4.0.0
  27376. * @category Object
  27377. * @param {Object} object The destination object.
  27378. * @param {...Object} sources The source objects.
  27379. * @param {Function} [customizer] The function to customize assigned values.
  27380. * @returns {Object} Returns `object`.
  27381. * @see _.assignInWith
  27382. * @example
  27383. *
  27384. * function customizer(objValue, srcValue) {
  27385. * return _.isUndefined(objValue) ? srcValue : objValue;
  27386. * }
  27387. *
  27388. * var defaults = _.partialRight(_.assignWith, customizer);
  27389. *
  27390. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  27391. * // => { 'a': 1, 'b': 2 }
  27392. */
  27393. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  27394. copyObject(source, keys(source), object, customizer);
  27395. });
  27396. /**
  27397. * Creates an array of values corresponding to `paths` of `object`.
  27398. *
  27399. * @static
  27400. * @memberOf _
  27401. * @since 1.0.0
  27402. * @category Object
  27403. * @param {Object} object The object to iterate over.
  27404. * @param {...(string|string[])} [paths] The property paths of elements to pick.
  27405. * @returns {Array} Returns the picked values.
  27406. * @example
  27407. *
  27408. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  27409. *
  27410. * _.at(object, ['a[0].b.c', 'a[1]']);
  27411. * // => [3, 4]
  27412. */
  27413. var at = rest(function(object, paths) {
  27414. return baseAt(object, baseFlatten(paths, 1));
  27415. });
  27416. /**
  27417. * Creates an object that inherits from the `prototype` object. If a
  27418. * `properties` object is given, its own enumerable string keyed properties
  27419. * are assigned to the created object.
  27420. *
  27421. * @static
  27422. * @memberOf _
  27423. * @since 2.3.0
  27424. * @category Object
  27425. * @param {Object} prototype The object to inherit from.
  27426. * @param {Object} [properties] The properties to assign to the object.
  27427. * @returns {Object} Returns the new object.
  27428. * @example
  27429. *
  27430. * function Shape() {
  27431. * this.x = 0;
  27432. * this.y = 0;
  27433. * }
  27434. *
  27435. * function Circle() {
  27436. * Shape.call(this);
  27437. * }
  27438. *
  27439. * Circle.prototype = _.create(Shape.prototype, {
  27440. * 'constructor': Circle
  27441. * });
  27442. *
  27443. * var circle = new Circle;
  27444. * circle instanceof Circle;
  27445. * // => true
  27446. *
  27447. * circle instanceof Shape;
  27448. * // => true
  27449. */
  27450. function create(prototype, properties) {
  27451. var result = baseCreate(prototype);
  27452. return properties ? baseAssign(result, properties) : result;
  27453. }
  27454. /**
  27455. * Assigns own and inherited enumerable string keyed properties of source
  27456. * objects to the destination object for all destination properties that
  27457. * resolve to `undefined`. Source objects are applied from left to right.
  27458. * Once a property is set, additional values of the same property are ignored.
  27459. *
  27460. * **Note:** This method mutates `object`.
  27461. *
  27462. * @static
  27463. * @since 0.1.0
  27464. * @memberOf _
  27465. * @category Object
  27466. * @param {Object} object The destination object.
  27467. * @param {...Object} [sources] The source objects.
  27468. * @returns {Object} Returns `object`.
  27469. * @see _.defaultsDeep
  27470. * @example
  27471. *
  27472. * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
  27473. * // => { 'user': 'barney', 'age': 36 }
  27474. */
  27475. var defaults = rest(function(args) {
  27476. args.push(undefined, assignInDefaults);
  27477. return apply(assignInWith, undefined, args);
  27478. });
  27479. /**
  27480. * This method is like `_.defaults` except that it recursively assigns
  27481. * default properties.
  27482. *
  27483. * **Note:** This method mutates `object`.
  27484. *
  27485. * @static
  27486. * @memberOf _
  27487. * @since 3.10.0
  27488. * @category Object
  27489. * @param {Object} object The destination object.
  27490. * @param {...Object} [sources] The source objects.
  27491. * @returns {Object} Returns `object`.
  27492. * @see _.defaults
  27493. * @example
  27494. *
  27495. * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
  27496. * // => { 'user': { 'name': 'barney', 'age': 36 } }
  27497. *
  27498. */
  27499. var defaultsDeep = rest(function(args) {
  27500. args.push(undefined, mergeDefaults);
  27501. return apply(mergeWith, undefined, args);
  27502. });
  27503. /**
  27504. * This method is like `_.find` except that it returns the key of the first
  27505. * element `predicate` returns truthy for instead of the element itself.
  27506. *
  27507. * @static
  27508. * @memberOf _
  27509. * @since 1.1.0
  27510. * @category Object
  27511. * @param {Object} object The object to search.
  27512. * @param {Array|Function|Object|string} [predicate=_.identity]
  27513. * The function invoked per iteration.
  27514. * @returns {string|undefined} Returns the key of the matched element,
  27515. * else `undefined`.
  27516. * @example
  27517. *
  27518. * var users = {
  27519. * 'barney': { 'age': 36, 'active': true },
  27520. * 'fred': { 'age': 40, 'active': false },
  27521. * 'pebbles': { 'age': 1, 'active': true }
  27522. * };
  27523. *
  27524. * _.findKey(users, function(o) { return o.age < 40; });
  27525. * // => 'barney' (iteration order is not guaranteed)
  27526. *
  27527. * // The `_.matches` iteratee shorthand.
  27528. * _.findKey(users, { 'age': 1, 'active': true });
  27529. * // => 'pebbles'
  27530. *
  27531. * // The `_.matchesProperty` iteratee shorthand.
  27532. * _.findKey(users, ['active', false]);
  27533. * // => 'fred'
  27534. *
  27535. * // The `_.property` iteratee shorthand.
  27536. * _.findKey(users, 'active');
  27537. * // => 'barney'
  27538. */
  27539. function findKey(object, predicate) {
  27540. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  27541. }
  27542. /**
  27543. * This method is like `_.findKey` except that it iterates over elements of
  27544. * a collection in the opposite order.
  27545. *
  27546. * @static
  27547. * @memberOf _
  27548. * @since 2.0.0
  27549. * @category Object
  27550. * @param {Object} object The object to search.
  27551. * @param {Array|Function|Object|string} [predicate=_.identity]
  27552. * The function invoked per iteration.
  27553. * @returns {string|undefined} Returns the key of the matched element,
  27554. * else `undefined`.
  27555. * @example
  27556. *
  27557. * var users = {
  27558. * 'barney': { 'age': 36, 'active': true },
  27559. * 'fred': { 'age': 40, 'active': false },
  27560. * 'pebbles': { 'age': 1, 'active': true }
  27561. * };
  27562. *
  27563. * _.findLastKey(users, function(o) { return o.age < 40; });
  27564. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  27565. *
  27566. * // The `_.matches` iteratee shorthand.
  27567. * _.findLastKey(users, { 'age': 36, 'active': true });
  27568. * // => 'barney'
  27569. *
  27570. * // The `_.matchesProperty` iteratee shorthand.
  27571. * _.findLastKey(users, ['active', false]);
  27572. * // => 'fred'
  27573. *
  27574. * // The `_.property` iteratee shorthand.
  27575. * _.findLastKey(users, 'active');
  27576. * // => 'pebbles'
  27577. */
  27578. function findLastKey(object, predicate) {
  27579. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  27580. }
  27581. /**
  27582. * Iterates over own and inherited enumerable string keyed properties of an
  27583. * object and invokes `iteratee` for each property. The iteratee is invoked
  27584. * with three arguments: (value, key, object). Iteratee functions may exit
  27585. * iteration early by explicitly returning `false`.
  27586. *
  27587. * @static
  27588. * @memberOf _
  27589. * @since 0.3.0
  27590. * @category Object
  27591. * @param {Object} object The object to iterate over.
  27592. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  27593. * @returns {Object} Returns `object`.
  27594. * @see _.forInRight
  27595. * @example
  27596. *
  27597. * function Foo() {
  27598. * this.a = 1;
  27599. * this.b = 2;
  27600. * }
  27601. *
  27602. * Foo.prototype.c = 3;
  27603. *
  27604. * _.forIn(new Foo, function(value, key) {
  27605. * console.log(key);
  27606. * });
  27607. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  27608. */
  27609. function forIn(object, iteratee) {
  27610. return object == null
  27611. ? object
  27612. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  27613. }
  27614. /**
  27615. * This method is like `_.forIn` except that it iterates over properties of
  27616. * `object` in the opposite order.
  27617. *
  27618. * @static
  27619. * @memberOf _
  27620. * @since 2.0.0
  27621. * @category Object
  27622. * @param {Object} object The object to iterate over.
  27623. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  27624. * @returns {Object} Returns `object`.
  27625. * @see _.forIn
  27626. * @example
  27627. *
  27628. * function Foo() {
  27629. * this.a = 1;
  27630. * this.b = 2;
  27631. * }
  27632. *
  27633. * Foo.prototype.c = 3;
  27634. *
  27635. * _.forInRight(new Foo, function(value, key) {
  27636. * console.log(key);
  27637. * });
  27638. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  27639. */
  27640. function forInRight(object, iteratee) {
  27641. return object == null
  27642. ? object
  27643. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  27644. }
  27645. /**
  27646. * Iterates over own enumerable string keyed properties of an object and
  27647. * invokes `iteratee` for each property. The iteratee is invoked with three
  27648. * arguments: (value, key, object). Iteratee functions may exit iteration
  27649. * early by explicitly returning `false`.
  27650. *
  27651. * @static
  27652. * @memberOf _
  27653. * @since 0.3.0
  27654. * @category Object
  27655. * @param {Object} object The object to iterate over.
  27656. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  27657. * @returns {Object} Returns `object`.
  27658. * @see _.forOwnRight
  27659. * @example
  27660. *
  27661. * function Foo() {
  27662. * this.a = 1;
  27663. * this.b = 2;
  27664. * }
  27665. *
  27666. * Foo.prototype.c = 3;
  27667. *
  27668. * _.forOwn(new Foo, function(value, key) {
  27669. * console.log(key);
  27670. * });
  27671. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  27672. */
  27673. function forOwn(object, iteratee) {
  27674. return object && baseForOwn(object, getIteratee(iteratee, 3));
  27675. }
  27676. /**
  27677. * This method is like `_.forOwn` except that it iterates over properties of
  27678. * `object` in the opposite order.
  27679. *
  27680. * @static
  27681. * @memberOf _
  27682. * @since 2.0.0
  27683. * @category Object
  27684. * @param {Object} object The object to iterate over.
  27685. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  27686. * @returns {Object} Returns `object`.
  27687. * @see _.forOwn
  27688. * @example
  27689. *
  27690. * function Foo() {
  27691. * this.a = 1;
  27692. * this.b = 2;
  27693. * }
  27694. *
  27695. * Foo.prototype.c = 3;
  27696. *
  27697. * _.forOwnRight(new Foo, function(value, key) {
  27698. * console.log(key);
  27699. * });
  27700. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  27701. */
  27702. function forOwnRight(object, iteratee) {
  27703. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  27704. }
  27705. /**
  27706. * Creates an array of function property names from own enumerable properties
  27707. * of `object`.
  27708. *
  27709. * @static
  27710. * @since 0.1.0
  27711. * @memberOf _
  27712. * @category Object
  27713. * @param {Object} object The object to inspect.
  27714. * @returns {Array} Returns the function names.
  27715. * @see _.functionsIn
  27716. * @example
  27717. *
  27718. * function Foo() {
  27719. * this.a = _.constant('a');
  27720. * this.b = _.constant('b');
  27721. * }
  27722. *
  27723. * Foo.prototype.c = _.constant('c');
  27724. *
  27725. * _.functions(new Foo);
  27726. * // => ['a', 'b']
  27727. */
  27728. function functions(object) {
  27729. return object == null ? [] : baseFunctions(object, keys(object));
  27730. }
  27731. /**
  27732. * Creates an array of function property names from own and inherited
  27733. * enumerable properties of `object`.
  27734. *
  27735. * @static
  27736. * @memberOf _
  27737. * @since 4.0.0
  27738. * @category Object
  27739. * @param {Object} object The object to inspect.
  27740. * @returns {Array} Returns the function names.
  27741. * @see _.functions
  27742. * @example
  27743. *
  27744. * function Foo() {
  27745. * this.a = _.constant('a');
  27746. * this.b = _.constant('b');
  27747. * }
  27748. *
  27749. * Foo.prototype.c = _.constant('c');
  27750. *
  27751. * _.functionsIn(new Foo);
  27752. * // => ['a', 'b', 'c']
  27753. */
  27754. function functionsIn(object) {
  27755. return object == null ? [] : baseFunctions(object, keysIn(object));
  27756. }
  27757. /**
  27758. * Gets the value at `path` of `object`. If the resolved value is
  27759. * `undefined`, the `defaultValue` is used in its place.
  27760. *
  27761. * @static
  27762. * @memberOf _
  27763. * @since 3.7.0
  27764. * @category Object
  27765. * @param {Object} object The object to query.
  27766. * @param {Array|string} path The path of the property to get.
  27767. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  27768. * @returns {*} Returns the resolved value.
  27769. * @example
  27770. *
  27771. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  27772. *
  27773. * _.get(object, 'a[0].b.c');
  27774. * // => 3
  27775. *
  27776. * _.get(object, ['a', '0', 'b', 'c']);
  27777. * // => 3
  27778. *
  27779. * _.get(object, 'a.b.c', 'default');
  27780. * // => 'default'
  27781. */
  27782. function get(object, path, defaultValue) {
  27783. var result = object == null ? undefined : baseGet(object, path);
  27784. return result === undefined ? defaultValue : result;
  27785. }
  27786. /**
  27787. * Checks if `path` is a direct property of `object`.
  27788. *
  27789. * @static
  27790. * @since 0.1.0
  27791. * @memberOf _
  27792. * @category Object
  27793. * @param {Object} object The object to query.
  27794. * @param {Array|string} path The path to check.
  27795. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  27796. * @example
  27797. *
  27798. * var object = { 'a': { 'b': 2 } };
  27799. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  27800. *
  27801. * _.has(object, 'a');
  27802. * // => true
  27803. *
  27804. * _.has(object, 'a.b');
  27805. * // => true
  27806. *
  27807. * _.has(object, ['a', 'b']);
  27808. * // => true
  27809. *
  27810. * _.has(other, 'a');
  27811. * // => false
  27812. */
  27813. function has(object, path) {
  27814. return object != null && hasPath(object, path, baseHas);
  27815. }
  27816. /**
  27817. * Checks if `path` is a direct or inherited property of `object`.
  27818. *
  27819. * @static
  27820. * @memberOf _
  27821. * @since 4.0.0
  27822. * @category Object
  27823. * @param {Object} object The object to query.
  27824. * @param {Array|string} path The path to check.
  27825. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  27826. * @example
  27827. *
  27828. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  27829. *
  27830. * _.hasIn(object, 'a');
  27831. * // => true
  27832. *
  27833. * _.hasIn(object, 'a.b');
  27834. * // => true
  27835. *
  27836. * _.hasIn(object, ['a', 'b']);
  27837. * // => true
  27838. *
  27839. * _.hasIn(object, 'b');
  27840. * // => false
  27841. */
  27842. function hasIn(object, path) {
  27843. return object != null && hasPath(object, path, baseHasIn);
  27844. }
  27845. /**
  27846. * Creates an object composed of the inverted keys and values of `object`.
  27847. * If `object` contains duplicate values, subsequent values overwrite
  27848. * property assignments of previous values.
  27849. *
  27850. * @static
  27851. * @memberOf _
  27852. * @since 0.7.0
  27853. * @category Object
  27854. * @param {Object} object The object to invert.
  27855. * @returns {Object} Returns the new inverted object.
  27856. * @example
  27857. *
  27858. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  27859. *
  27860. * _.invert(object);
  27861. * // => { '1': 'c', '2': 'b' }
  27862. */
  27863. var invert = createInverter(function(result, value, key) {
  27864. result[value] = key;
  27865. }, constant(identity));
  27866. /**
  27867. * This method is like `_.invert` except that the inverted object is generated
  27868. * from the results of running each element of `object` thru `iteratee`. The
  27869. * corresponding inverted value of each inverted key is an array of keys
  27870. * responsible for generating the inverted value. The iteratee is invoked
  27871. * with one argument: (value).
  27872. *
  27873. * @static
  27874. * @memberOf _
  27875. * @since 4.1.0
  27876. * @category Object
  27877. * @param {Object} object The object to invert.
  27878. * @param {Array|Function|Object|string} [iteratee=_.identity]
  27879. * The iteratee invoked per element.
  27880. * @returns {Object} Returns the new inverted object.
  27881. * @example
  27882. *
  27883. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  27884. *
  27885. * _.invertBy(object);
  27886. * // => { '1': ['a', 'c'], '2': ['b'] }
  27887. *
  27888. * _.invertBy(object, function(value) {
  27889. * return 'group' + value;
  27890. * });
  27891. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  27892. */
  27893. var invertBy = createInverter(function(result, value, key) {
  27894. if (hasOwnProperty.call(result, value)) {
  27895. result[value].push(key);
  27896. } else {
  27897. result[value] = [key];
  27898. }
  27899. }, getIteratee);
  27900. /**
  27901. * Invokes the method at `path` of `object`.
  27902. *
  27903. * @static
  27904. * @memberOf _
  27905. * @since 4.0.0
  27906. * @category Object
  27907. * @param {Object} object The object to query.
  27908. * @param {Array|string} path The path of the method to invoke.
  27909. * @param {...*} [args] The arguments to invoke the method with.
  27910. * @returns {*} Returns the result of the invoked method.
  27911. * @example
  27912. *
  27913. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  27914. *
  27915. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  27916. * // => [2, 3]
  27917. */
  27918. var invoke = rest(baseInvoke);
  27919. /**
  27920. * Creates an array of the own enumerable property names of `object`.
  27921. *
  27922. * **Note:** Non-object values are coerced to objects. See the
  27923. * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
  27924. * for more details.
  27925. *
  27926. * @static
  27927. * @since 0.1.0
  27928. * @memberOf _
  27929. * @category Object
  27930. * @param {Object} object The object to query.
  27931. * @returns {Array} Returns the array of property names.
  27932. * @example
  27933. *
  27934. * function Foo() {
  27935. * this.a = 1;
  27936. * this.b = 2;
  27937. * }
  27938. *
  27939. * Foo.prototype.c = 3;
  27940. *
  27941. * _.keys(new Foo);
  27942. * // => ['a', 'b'] (iteration order is not guaranteed)
  27943. *
  27944. * _.keys('hi');
  27945. * // => ['0', '1']
  27946. */
  27947. function keys(object) {
  27948. var isProto = isPrototype(object);
  27949. if (!(isProto || isArrayLike(object))) {
  27950. return baseKeys(object);
  27951. }
  27952. var indexes = indexKeys(object),
  27953. skipIndexes = !!indexes,
  27954. result = indexes || [],
  27955. length = result.length;
  27956. for (var key in object) {
  27957. if (baseHas(object, key) &&
  27958. !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
  27959. !(isProto && key == 'constructor')) {
  27960. result.push(key);
  27961. }
  27962. }
  27963. return result;
  27964. }
  27965. /**
  27966. * Creates an array of the own and inherited enumerable property names of `object`.
  27967. *
  27968. * **Note:** Non-object values are coerced to objects.
  27969. *
  27970. * @static
  27971. * @memberOf _
  27972. * @since 3.0.0
  27973. * @category Object
  27974. * @param {Object} object The object to query.
  27975. * @returns {Array} Returns the array of property names.
  27976. * @example
  27977. *
  27978. * function Foo() {
  27979. * this.a = 1;
  27980. * this.b = 2;
  27981. * }
  27982. *
  27983. * Foo.prototype.c = 3;
  27984. *
  27985. * _.keysIn(new Foo);
  27986. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  27987. */
  27988. function keysIn(object) {
  27989. var index = -1,
  27990. isProto = isPrototype(object),
  27991. props = baseKeysIn(object),
  27992. propsLength = props.length,
  27993. indexes = indexKeys(object),
  27994. skipIndexes = !!indexes,
  27995. result = indexes || [],
  27996. length = result.length;
  27997. while (++index < propsLength) {
  27998. var key = props[index];
  27999. if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
  28000. !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  28001. result.push(key);
  28002. }
  28003. }
  28004. return result;
  28005. }
  28006. /**
  28007. * The opposite of `_.mapValues`; this method creates an object with the
  28008. * same values as `object` and keys generated by running each own enumerable
  28009. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  28010. * with three arguments: (value, key, object).
  28011. *
  28012. * @static
  28013. * @memberOf _
  28014. * @since 3.8.0
  28015. * @category Object
  28016. * @param {Object} object The object to iterate over.
  28017. * @param {Array|Function|Object|string} [iteratee=_.identity]
  28018. * The function invoked per iteration.
  28019. * @returns {Object} Returns the new mapped object.
  28020. * @see _.mapValues
  28021. * @example
  28022. *
  28023. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  28024. * return key + value;
  28025. * });
  28026. * // => { 'a1': 1, 'b2': 2 }
  28027. */
  28028. function mapKeys(object, iteratee) {
  28029. var result = {};
  28030. iteratee = getIteratee(iteratee, 3);
  28031. baseForOwn(object, function(value, key, object) {
  28032. result[iteratee(value, key, object)] = value;
  28033. });
  28034. return result;
  28035. }
  28036. /**
  28037. * Creates an object with the same keys as `object` and values generated
  28038. * by running each own enumerable string keyed property of `object` thru
  28039. * `iteratee`. The iteratee is invoked with three arguments:
  28040. * (value, key, object).
  28041. *
  28042. * @static
  28043. * @memberOf _
  28044. * @since 2.4.0
  28045. * @category Object
  28046. * @param {Object} object The object to iterate over.
  28047. * @param {Array|Function|Object|string} [iteratee=_.identity]
  28048. * The function invoked per iteration.
  28049. * @returns {Object} Returns the new mapped object.
  28050. * @see _.mapKeys
  28051. * @example
  28052. *
  28053. * var users = {
  28054. * 'fred': { 'user': 'fred', 'age': 40 },
  28055. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  28056. * };
  28057. *
  28058. * _.mapValues(users, function(o) { return o.age; });
  28059. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  28060. *
  28061. * // The `_.property` iteratee shorthand.
  28062. * _.mapValues(users, 'age');
  28063. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  28064. */
  28065. function mapValues(object, iteratee) {
  28066. var result = {};
  28067. iteratee = getIteratee(iteratee, 3);
  28068. baseForOwn(object, function(value, key, object) {
  28069. result[key] = iteratee(value, key, object);
  28070. });
  28071. return result;
  28072. }
  28073. /**
  28074. * This method is like `_.assign` except that it recursively merges own and
  28075. * inherited enumerable string keyed properties of source objects into the
  28076. * destination object. Source properties that resolve to `undefined` are
  28077. * skipped if a destination value exists. Array and plain object properties
  28078. * are merged recursively. Other objects and value types are overridden by
  28079. * assignment. Source objects are applied from left to right. Subsequent
  28080. * sources overwrite property assignments of previous sources.
  28081. *
  28082. * **Note:** This method mutates `object`.
  28083. *
  28084. * @static
  28085. * @memberOf _
  28086. * @since 0.5.0
  28087. * @category Object
  28088. * @param {Object} object The destination object.
  28089. * @param {...Object} [sources] The source objects.
  28090. * @returns {Object} Returns `object`.
  28091. * @example
  28092. *
  28093. * var users = {
  28094. * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
  28095. * };
  28096. *
  28097. * var ages = {
  28098. * 'data': [{ 'age': 36 }, { 'age': 40 }]
  28099. * };
  28100. *
  28101. * _.merge(users, ages);
  28102. * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
  28103. */
  28104. var merge = createAssigner(function(object, source, srcIndex) {
  28105. baseMerge(object, source, srcIndex);
  28106. });
  28107. /**
  28108. * This method is like `_.merge` except that it accepts `customizer` which
  28109. * is invoked to produce the merged values of the destination and source
  28110. * properties. If `customizer` returns `undefined`, merging is handled by the
  28111. * method instead. The `customizer` is invoked with seven arguments:
  28112. * (objValue, srcValue, key, object, source, stack).
  28113. *
  28114. * **Note:** This method mutates `object`.
  28115. *
  28116. * @static
  28117. * @memberOf _
  28118. * @since 4.0.0
  28119. * @category Object
  28120. * @param {Object} object The destination object.
  28121. * @param {...Object} sources The source objects.
  28122. * @param {Function} customizer The function to customize assigned values.
  28123. * @returns {Object} Returns `object`.
  28124. * @example
  28125. *
  28126. * function customizer(objValue, srcValue) {
  28127. * if (_.isArray(objValue)) {
  28128. * return objValue.concat(srcValue);
  28129. * }
  28130. * }
  28131. *
  28132. * var object = {
  28133. * 'fruits': ['apple'],
  28134. * 'vegetables': ['beet']
  28135. * };
  28136. *
  28137. * var other = {
  28138. * 'fruits': ['banana'],
  28139. * 'vegetables': ['carrot']
  28140. * };
  28141. *
  28142. * _.mergeWith(object, other, customizer);
  28143. * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
  28144. */
  28145. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  28146. baseMerge(object, source, srcIndex, customizer);
  28147. });
  28148. /**
  28149. * The opposite of `_.pick`; this method creates an object composed of the
  28150. * own and inherited enumerable string keyed properties of `object` that are
  28151. * not omitted.
  28152. *
  28153. * @static
  28154. * @since 0.1.0
  28155. * @memberOf _
  28156. * @category Object
  28157. * @param {Object} object The source object.
  28158. * @param {...(string|string[])} [props] The property identifiers to omit.
  28159. * @returns {Object} Returns the new object.
  28160. * @example
  28161. *
  28162. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  28163. *
  28164. * _.omit(object, ['a', 'c']);
  28165. * // => { 'b': '2' }
  28166. */
  28167. var omit = rest(function(object, props) {
  28168. if (object == null) {
  28169. return {};
  28170. }
  28171. props = arrayMap(baseFlatten(props, 1), toKey);
  28172. return basePick(object, baseDifference(getAllKeysIn(object), props));
  28173. });
  28174. /**
  28175. * The opposite of `_.pickBy`; this method creates an object composed of
  28176. * the own and inherited enumerable string keyed properties of `object` that
  28177. * `predicate` doesn't return truthy for. The predicate is invoked with two
  28178. * arguments: (value, key).
  28179. *
  28180. * @static
  28181. * @memberOf _
  28182. * @since 4.0.0
  28183. * @category Object
  28184. * @param {Object} object The source object.
  28185. * @param {Array|Function|Object|string} [predicate=_.identity]
  28186. * The function invoked per property.
  28187. * @returns {Object} Returns the new object.
  28188. * @example
  28189. *
  28190. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  28191. *
  28192. * _.omitBy(object, _.isNumber);
  28193. * // => { 'b': '2' }
  28194. */
  28195. function omitBy(object, predicate) {
  28196. predicate = getIteratee(predicate);
  28197. return basePickBy(object, function(value, key) {
  28198. return !predicate(value, key);
  28199. });
  28200. }
  28201. /**
  28202. * Creates an object composed of the picked `object` properties.
  28203. *
  28204. * @static
  28205. * @since 0.1.0
  28206. * @memberOf _
  28207. * @category Object
  28208. * @param {Object} object The source object.
  28209. * @param {...(string|string[])} [props] The property identifiers to pick.
  28210. * @returns {Object} Returns the new object.
  28211. * @example
  28212. *
  28213. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  28214. *
  28215. * _.pick(object, ['a', 'c']);
  28216. * // => { 'a': 1, 'c': 3 }
  28217. */
  28218. var pick = rest(function(object, props) {
  28219. return object == null ? {} : basePick(object, arrayMap(baseFlatten(props, 1), toKey));
  28220. });
  28221. /**
  28222. * Creates an object composed of the `object` properties `predicate` returns
  28223. * truthy for. The predicate is invoked with two arguments: (value, key).
  28224. *
  28225. * @static
  28226. * @memberOf _
  28227. * @since 4.0.0
  28228. * @category Object
  28229. * @param {Object} object The source object.
  28230. * @param {Array|Function|Object|string} [predicate=_.identity]
  28231. * The function invoked per property.
  28232. * @returns {Object} Returns the new object.
  28233. * @example
  28234. *
  28235. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  28236. *
  28237. * _.pickBy(object, _.isNumber);
  28238. * // => { 'a': 1, 'c': 3 }
  28239. */
  28240. function pickBy(object, predicate) {
  28241. return object == null ? {} : basePickBy(object, getIteratee(predicate));
  28242. }
  28243. /**
  28244. * This method is like `_.get` except that if the resolved value is a
  28245. * function it's invoked with the `this` binding of its parent object and
  28246. * its result is returned.
  28247. *
  28248. * @static
  28249. * @since 0.1.0
  28250. * @memberOf _
  28251. * @category Object
  28252. * @param {Object} object The object to query.
  28253. * @param {Array|string} path The path of the property to resolve.
  28254. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  28255. * @returns {*} Returns the resolved value.
  28256. * @example
  28257. *
  28258. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  28259. *
  28260. * _.result(object, 'a[0].b.c1');
  28261. * // => 3
  28262. *
  28263. * _.result(object, 'a[0].b.c2');
  28264. * // => 4
  28265. *
  28266. * _.result(object, 'a[0].b.c3', 'default');
  28267. * // => 'default'
  28268. *
  28269. * _.result(object, 'a[0].b.c3', _.constant('default'));
  28270. * // => 'default'
  28271. */
  28272. function result(object, path, defaultValue) {
  28273. path = isKey(path, object) ? [path] : castPath(path);
  28274. var index = -1,
  28275. length = path.length;
  28276. // Ensure the loop is entered when path is empty.
  28277. if (!length) {
  28278. object = undefined;
  28279. length = 1;
  28280. }
  28281. while (++index < length) {
  28282. var value = object == null ? undefined : object[toKey(path[index])];
  28283. if (value === undefined) {
  28284. index = length;
  28285. value = defaultValue;
  28286. }
  28287. object = isFunction(value) ? value.call(object) : value;
  28288. }
  28289. return object;
  28290. }
  28291. /**
  28292. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  28293. * it's created. Arrays are created for missing index properties while objects
  28294. * are created for all other missing properties. Use `_.setWith` to customize
  28295. * `path` creation.
  28296. *
  28297. * **Note:** This method mutates `object`.
  28298. *
  28299. * @static
  28300. * @memberOf _
  28301. * @since 3.7.0
  28302. * @category Object
  28303. * @param {Object} object The object to modify.
  28304. * @param {Array|string} path The path of the property to set.
  28305. * @param {*} value The value to set.
  28306. * @returns {Object} Returns `object`.
  28307. * @example
  28308. *
  28309. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  28310. *
  28311. * _.set(object, 'a[0].b.c', 4);
  28312. * console.log(object.a[0].b.c);
  28313. * // => 4
  28314. *
  28315. * _.set(object, ['x', '0', 'y', 'z'], 5);
  28316. * console.log(object.x[0].y.z);
  28317. * // => 5
  28318. */
  28319. function set(object, path, value) {
  28320. return object == null ? object : baseSet(object, path, value);
  28321. }
  28322. /**
  28323. * This method is like `_.set` except that it accepts `customizer` which is
  28324. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  28325. * path creation is handled by the method instead. The `customizer` is invoked
  28326. * with three arguments: (nsValue, key, nsObject).
  28327. *
  28328. * **Note:** This method mutates `object`.
  28329. *
  28330. * @static
  28331. * @memberOf _
  28332. * @since 4.0.0
  28333. * @category Object
  28334. * @param {Object} object The object to modify.
  28335. * @param {Array|string} path The path of the property to set.
  28336. * @param {*} value The value to set.
  28337. * @param {Function} [customizer] The function to customize assigned values.
  28338. * @returns {Object} Returns `object`.
  28339. * @example
  28340. *
  28341. * var object = {};
  28342. *
  28343. * _.setWith(object, '[0][1]', 'a', Object);
  28344. * // => { '0': { '1': 'a' } }
  28345. */
  28346. function setWith(object, path, value, customizer) {
  28347. customizer = typeof customizer == 'function' ? customizer : undefined;
  28348. return object == null ? object : baseSet(object, path, value, customizer);
  28349. }
  28350. /**
  28351. * Creates an array of own enumerable string keyed-value pairs for `object`
  28352. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  28353. * entries are returned.
  28354. *
  28355. * @static
  28356. * @memberOf _
  28357. * @since 4.0.0
  28358. * @alias entries
  28359. * @category Object
  28360. * @param {Object} object The object to query.
  28361. * @returns {Array} Returns the key-value pairs.
  28362. * @example
  28363. *
  28364. * function Foo() {
  28365. * this.a = 1;
  28366. * this.b = 2;
  28367. * }
  28368. *
  28369. * Foo.prototype.c = 3;
  28370. *
  28371. * _.toPairs(new Foo);
  28372. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  28373. */
  28374. var toPairs = createToPairs(keys);
  28375. /**
  28376. * Creates an array of own and inherited enumerable string keyed-value pairs
  28377. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  28378. * or set, its entries are returned.
  28379. *
  28380. * @static
  28381. * @memberOf _
  28382. * @since 4.0.0
  28383. * @alias entriesIn
  28384. * @category Object
  28385. * @param {Object} object The object to query.
  28386. * @returns {Array} Returns the key-value pairs.
  28387. * @example
  28388. *
  28389. * function Foo() {
  28390. * this.a = 1;
  28391. * this.b = 2;
  28392. * }
  28393. *
  28394. * Foo.prototype.c = 3;
  28395. *
  28396. * _.toPairsIn(new Foo);
  28397. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  28398. */
  28399. var toPairsIn = createToPairs(keysIn);
  28400. /**
  28401. * An alternative to `_.reduce`; this method transforms `object` to a new
  28402. * `accumulator` object which is the result of running each of its own
  28403. * enumerable string keyed properties thru `iteratee`, with each invocation
  28404. * potentially mutating the `accumulator` object. If `accumulator` is not
  28405. * provided, a new object with the same `[[Prototype]]` will be used. The
  28406. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  28407. * Iteratee functions may exit iteration early by explicitly returning `false`.
  28408. *
  28409. * @static
  28410. * @memberOf _
  28411. * @since 1.3.0
  28412. * @category Object
  28413. * @param {Object} object The object to iterate over.
  28414. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  28415. * @param {*} [accumulator] The custom accumulator value.
  28416. * @returns {*} Returns the accumulated value.
  28417. * @example
  28418. *
  28419. * _.transform([2, 3, 4], function(result, n) {
  28420. * result.push(n *= n);
  28421. * return n % 2 == 0;
  28422. * }, []);
  28423. * // => [4, 9]
  28424. *
  28425. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  28426. * (result[value] || (result[value] = [])).push(key);
  28427. * }, {});
  28428. * // => { '1': ['a', 'c'], '2': ['b'] }
  28429. */
  28430. function transform(object, iteratee, accumulator) {
  28431. var isArr = isArray(object) || isTypedArray(object);
  28432. iteratee = getIteratee(iteratee, 4);
  28433. if (accumulator == null) {
  28434. if (isArr || isObject(object)) {
  28435. var Ctor = object.constructor;
  28436. if (isArr) {
  28437. accumulator = isArray(object) ? new Ctor : [];
  28438. } else {
  28439. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  28440. }
  28441. } else {
  28442. accumulator = {};
  28443. }
  28444. }
  28445. (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
  28446. return iteratee(accumulator, value, index, object);
  28447. });
  28448. return accumulator;
  28449. }
  28450. /**
  28451. * Removes the property at `path` of `object`.
  28452. *
  28453. * **Note:** This method mutates `object`.
  28454. *
  28455. * @static
  28456. * @memberOf _
  28457. * @since 4.0.0
  28458. * @category Object
  28459. * @param {Object} object The object to modify.
  28460. * @param {Array|string} path The path of the property to unset.
  28461. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  28462. * @example
  28463. *
  28464. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  28465. * _.unset(object, 'a[0].b.c');
  28466. * // => true
  28467. *
  28468. * console.log(object);
  28469. * // => { 'a': [{ 'b': {} }] };
  28470. *
  28471. * _.unset(object, ['a', '0', 'b', 'c']);
  28472. * // => true
  28473. *
  28474. * console.log(object);
  28475. * // => { 'a': [{ 'b': {} }] };
  28476. */
  28477. function unset(object, path) {
  28478. return object == null ? true : baseUnset(object, path);
  28479. }
  28480. /**
  28481. * This method is like `_.set` except that accepts `updater` to produce the
  28482. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  28483. * is invoked with one argument: (value).
  28484. *
  28485. * **Note:** This method mutates `object`.
  28486. *
  28487. * @static
  28488. * @memberOf _
  28489. * @since 4.6.0
  28490. * @category Object
  28491. * @param {Object} object The object to modify.
  28492. * @param {Array|string} path The path of the property to set.
  28493. * @param {Function} updater The function to produce the updated value.
  28494. * @returns {Object} Returns `object`.
  28495. * @example
  28496. *
  28497. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  28498. *
  28499. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  28500. * console.log(object.a[0].b.c);
  28501. * // => 9
  28502. *
  28503. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  28504. * console.log(object.x[0].y.z);
  28505. * // => 0
  28506. */
  28507. function update(object, path, updater) {
  28508. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  28509. }
  28510. /**
  28511. * This method is like `_.update` except that it accepts `customizer` which is
  28512. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  28513. * path creation is handled by the method instead. The `customizer` is invoked
  28514. * with three arguments: (nsValue, key, nsObject).
  28515. *
  28516. * **Note:** This method mutates `object`.
  28517. *
  28518. * @static
  28519. * @memberOf _
  28520. * @since 4.6.0
  28521. * @category Object
  28522. * @param {Object} object The object to modify.
  28523. * @param {Array|string} path The path of the property to set.
  28524. * @param {Function} updater The function to produce the updated value.
  28525. * @param {Function} [customizer] The function to customize assigned values.
  28526. * @returns {Object} Returns `object`.
  28527. * @example
  28528. *
  28529. * var object = {};
  28530. *
  28531. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  28532. * // => { '0': { '1': 'a' } }
  28533. */
  28534. function updateWith(object, path, updater, customizer) {
  28535. customizer = typeof customizer == 'function' ? customizer : undefined;
  28536. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  28537. }
  28538. /**
  28539. * Creates an array of the own enumerable string keyed property values of `object`.
  28540. *
  28541. * **Note:** Non-object values are coerced to objects.
  28542. *
  28543. * @static
  28544. * @since 0.1.0
  28545. * @memberOf _
  28546. * @category Object
  28547. * @param {Object} object The object to query.
  28548. * @returns {Array} Returns the array of property values.
  28549. * @example
  28550. *
  28551. * function Foo() {
  28552. * this.a = 1;
  28553. * this.b = 2;
  28554. * }
  28555. *
  28556. * Foo.prototype.c = 3;
  28557. *
  28558. * _.values(new Foo);
  28559. * // => [1, 2] (iteration order is not guaranteed)
  28560. *
  28561. * _.values('hi');
  28562. * // => ['h', 'i']
  28563. */
  28564. function values(object) {
  28565. return object ? baseValues(object, keys(object)) : [];
  28566. }
  28567. /**
  28568. * Creates an array of the own and inherited enumerable string keyed property
  28569. * values of `object`.
  28570. *
  28571. * **Note:** Non-object values are coerced to objects.
  28572. *
  28573. * @static
  28574. * @memberOf _
  28575. * @since 3.0.0
  28576. * @category Object
  28577. * @param {Object} object The object to query.
  28578. * @returns {Array} Returns the array of property values.
  28579. * @example
  28580. *
  28581. * function Foo() {
  28582. * this.a = 1;
  28583. * this.b = 2;
  28584. * }
  28585. *
  28586. * Foo.prototype.c = 3;
  28587. *
  28588. * _.valuesIn(new Foo);
  28589. * // => [1, 2, 3] (iteration order is not guaranteed)
  28590. */
  28591. function valuesIn(object) {
  28592. return object == null ? [] : baseValues(object, keysIn(object));
  28593. }
  28594. /*------------------------------------------------------------------------*/
  28595. /**
  28596. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  28597. *
  28598. * @static
  28599. * @memberOf _
  28600. * @since 4.0.0
  28601. * @category Number
  28602. * @param {number} number The number to clamp.
  28603. * @param {number} [lower] The lower bound.
  28604. * @param {number} upper The upper bound.
  28605. * @returns {number} Returns the clamped number.
  28606. * @example
  28607. *
  28608. * _.clamp(-10, -5, 5);
  28609. * // => -5
  28610. *
  28611. * _.clamp(10, -5, 5);
  28612. * // => 5
  28613. */
  28614. function clamp(number, lower, upper) {
  28615. if (upper === undefined) {
  28616. upper = lower;
  28617. lower = undefined;
  28618. }
  28619. if (upper !== undefined) {
  28620. upper = toNumber(upper);
  28621. upper = upper === upper ? upper : 0;
  28622. }
  28623. if (lower !== undefined) {
  28624. lower = toNumber(lower);
  28625. lower = lower === lower ? lower : 0;
  28626. }
  28627. return baseClamp(toNumber(number), lower, upper);
  28628. }
  28629. /**
  28630. * Checks if `n` is between `start` and up to, but not including, `end`. If
  28631. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  28632. * If `start` is greater than `end` the params are swapped to support
  28633. * negative ranges.
  28634. *
  28635. * @static
  28636. * @memberOf _
  28637. * @since 3.3.0
  28638. * @category Number
  28639. * @param {number} number The number to check.
  28640. * @param {number} [start=0] The start of the range.
  28641. * @param {number} end The end of the range.
  28642. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  28643. * @see _.range, _.rangeRight
  28644. * @example
  28645. *
  28646. * _.inRange(3, 2, 4);
  28647. * // => true
  28648. *
  28649. * _.inRange(4, 8);
  28650. * // => true
  28651. *
  28652. * _.inRange(4, 2);
  28653. * // => false
  28654. *
  28655. * _.inRange(2, 2);
  28656. * // => false
  28657. *
  28658. * _.inRange(1.2, 2);
  28659. * // => true
  28660. *
  28661. * _.inRange(5.2, 4);
  28662. * // => false
  28663. *
  28664. * _.inRange(-3, -2, -6);
  28665. * // => true
  28666. */
  28667. function inRange(number, start, end) {
  28668. start = toNumber(start) || 0;
  28669. if (end === undefined) {
  28670. end = start;
  28671. start = 0;
  28672. } else {
  28673. end = toNumber(end) || 0;
  28674. }
  28675. number = toNumber(number);
  28676. return baseInRange(number, start, end);
  28677. }
  28678. /**
  28679. * Produces a random number between the inclusive `lower` and `upper` bounds.
  28680. * If only one argument is provided a number between `0` and the given number
  28681. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  28682. * floats, a floating-point number is returned instead of an integer.
  28683. *
  28684. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  28685. * floating-point values which can produce unexpected results.
  28686. *
  28687. * @static
  28688. * @memberOf _
  28689. * @since 0.7.0
  28690. * @category Number
  28691. * @param {number} [lower=0] The lower bound.
  28692. * @param {number} [upper=1] The upper bound.
  28693. * @param {boolean} [floating] Specify returning a floating-point number.
  28694. * @returns {number} Returns the random number.
  28695. * @example
  28696. *
  28697. * _.random(0, 5);
  28698. * // => an integer between 0 and 5
  28699. *
  28700. * _.random(5);
  28701. * // => also an integer between 0 and 5
  28702. *
  28703. * _.random(5, true);
  28704. * // => a floating-point number between 0 and 5
  28705. *
  28706. * _.random(1.2, 5.2);
  28707. * // => a floating-point number between 1.2 and 5.2
  28708. */
  28709. function random(lower, upper, floating) {
  28710. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  28711. upper = floating = undefined;
  28712. }
  28713. if (floating === undefined) {
  28714. if (typeof upper == 'boolean') {
  28715. floating = upper;
  28716. upper = undefined;
  28717. }
  28718. else if (typeof lower == 'boolean') {
  28719. floating = lower;
  28720. lower = undefined;
  28721. }
  28722. }
  28723. if (lower === undefined && upper === undefined) {
  28724. lower = 0;
  28725. upper = 1;
  28726. }
  28727. else {
  28728. lower = toNumber(lower) || 0;
  28729. if (upper === undefined) {
  28730. upper = lower;
  28731. lower = 0;
  28732. } else {
  28733. upper = toNumber(upper) || 0;
  28734. }
  28735. }
  28736. if (lower > upper) {
  28737. var temp = lower;
  28738. lower = upper;
  28739. upper = temp;
  28740. }
  28741. if (floating || lower % 1 || upper % 1) {
  28742. var rand = nativeRandom();
  28743. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  28744. }
  28745. return baseRandom(lower, upper);
  28746. }
  28747. /*------------------------------------------------------------------------*/
  28748. /**
  28749. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  28750. *
  28751. * @static
  28752. * @memberOf _
  28753. * @since 3.0.0
  28754. * @category String
  28755. * @param {string} [string=''] The string to convert.
  28756. * @returns {string} Returns the camel cased string.
  28757. * @example
  28758. *
  28759. * _.camelCase('Foo Bar');
  28760. * // => 'fooBar'
  28761. *
  28762. * _.camelCase('--foo-bar--');
  28763. * // => 'fooBar'
  28764. *
  28765. * _.camelCase('__FOO_BAR__');
  28766. * // => 'fooBar'
  28767. */
  28768. var camelCase = createCompounder(function(result, word, index) {
  28769. word = word.toLowerCase();
  28770. return result + (index ? capitalize(word) : word);
  28771. });
  28772. /**
  28773. * Converts the first character of `string` to upper case and the remaining
  28774. * to lower case.
  28775. *
  28776. * @static
  28777. * @memberOf _
  28778. * @since 3.0.0
  28779. * @category String
  28780. * @param {string} [string=''] The string to capitalize.
  28781. * @returns {string} Returns the capitalized string.
  28782. * @example
  28783. *
  28784. * _.capitalize('FRED');
  28785. * // => 'Fred'
  28786. */
  28787. function capitalize(string) {
  28788. return upperFirst(toString(string).toLowerCase());
  28789. }
  28790. /**
  28791. * Deburrs `string` by converting
  28792. * [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  28793. * to basic latin letters and removing
  28794. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  28795. *
  28796. * @static
  28797. * @memberOf _
  28798. * @since 3.0.0
  28799. * @category String
  28800. * @param {string} [string=''] The string to deburr.
  28801. * @returns {string} Returns the deburred string.
  28802. * @example
  28803. *
  28804. * _.deburr('déjà vu');
  28805. * // => 'deja vu'
  28806. */
  28807. function deburr(string) {
  28808. string = toString(string);
  28809. return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
  28810. }
  28811. /**
  28812. * Checks if `string` ends with the given target string.
  28813. *
  28814. * @static
  28815. * @memberOf _
  28816. * @since 3.0.0
  28817. * @category String
  28818. * @param {string} [string=''] The string to search.
  28819. * @param {string} [target] The string to search for.
  28820. * @param {number} [position=string.length] The position to search up to.
  28821. * @returns {boolean} Returns `true` if `string` ends with `target`,
  28822. * else `false`.
  28823. * @example
  28824. *
  28825. * _.endsWith('abc', 'c');
  28826. * // => true
  28827. *
  28828. * _.endsWith('abc', 'b');
  28829. * // => false
  28830. *
  28831. * _.endsWith('abc', 'b', 2);
  28832. * // => true
  28833. */
  28834. function endsWith(string, target, position) {
  28835. string = toString(string);
  28836. target = baseToString(target);
  28837. var length = string.length;
  28838. position = position === undefined
  28839. ? length
  28840. : baseClamp(toInteger(position), 0, length);
  28841. position -= target.length;
  28842. return position >= 0 && string.indexOf(target, position) == position;
  28843. }
  28844. /**
  28845. * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
  28846. * their corresponding HTML entities.
  28847. *
  28848. * **Note:** No other characters are escaped. To escape additional
  28849. * characters use a third-party library like [_he_](https://mths.be/he).
  28850. *
  28851. * Though the ">" character is escaped for symmetry, characters like
  28852. * ">" and "/" don't need escaping in HTML and have no special meaning
  28853. * unless they're part of a tag or unquoted attribute value. See
  28854. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  28855. * (under "semi-related fun fact") for more details.
  28856. *
  28857. * Backticks are escaped because in IE < 9, they can break out of
  28858. * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
  28859. * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
  28860. * [#133](https://html5sec.org/#133) of the
  28861. * [HTML5 Security Cheatsheet](https://html5sec.org/) for more details.
  28862. *
  28863. * When working with HTML you should always
  28864. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  28865. * XSS vectors.
  28866. *
  28867. * @static
  28868. * @since 0.1.0
  28869. * @memberOf _
  28870. * @category String
  28871. * @param {string} [string=''] The string to escape.
  28872. * @returns {string} Returns the escaped string.
  28873. * @example
  28874. *
  28875. * _.escape('fred, barney, & pebbles');
  28876. * // => 'fred, barney, &amp; pebbles'
  28877. */
  28878. function escape(string) {
  28879. string = toString(string);
  28880. return (string && reHasUnescapedHtml.test(string))
  28881. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  28882. : string;
  28883. }
  28884. /**
  28885. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  28886. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  28887. *
  28888. * @static
  28889. * @memberOf _
  28890. * @since 3.0.0
  28891. * @category String
  28892. * @param {string} [string=''] The string to escape.
  28893. * @returns {string} Returns the escaped string.
  28894. * @example
  28895. *
  28896. * _.escapeRegExp('[lodash](https://lodash.com/)');
  28897. * // => '\[lodash\]\(https://lodash\.com/\)'
  28898. */
  28899. function escapeRegExp(string) {
  28900. string = toString(string);
  28901. return (string && reHasRegExpChar.test(string))
  28902. ? string.replace(reRegExpChar, '\\$&')
  28903. : string;
  28904. }
  28905. /**
  28906. * Converts `string` to
  28907. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  28908. *
  28909. * @static
  28910. * @memberOf _
  28911. * @since 3.0.0
  28912. * @category String
  28913. * @param {string} [string=''] The string to convert.
  28914. * @returns {string} Returns the kebab cased string.
  28915. * @example
  28916. *
  28917. * _.kebabCase('Foo Bar');
  28918. * // => 'foo-bar'
  28919. *
  28920. * _.kebabCase('fooBar');
  28921. * // => 'foo-bar'
  28922. *
  28923. * _.kebabCase('__FOO_BAR__');
  28924. * // => 'foo-bar'
  28925. */
  28926. var kebabCase = createCompounder(function(result, word, index) {
  28927. return result + (index ? '-' : '') + word.toLowerCase();
  28928. });
  28929. /**
  28930. * Converts `string`, as space separated words, to lower case.
  28931. *
  28932. * @static
  28933. * @memberOf _
  28934. * @since 4.0.0
  28935. * @category String
  28936. * @param {string} [string=''] The string to convert.
  28937. * @returns {string} Returns the lower cased string.
  28938. * @example
  28939. *
  28940. * _.lowerCase('--Foo-Bar--');
  28941. * // => 'foo bar'
  28942. *
  28943. * _.lowerCase('fooBar');
  28944. * // => 'foo bar'
  28945. *
  28946. * _.lowerCase('__FOO_BAR__');
  28947. * // => 'foo bar'
  28948. */
  28949. var lowerCase = createCompounder(function(result, word, index) {
  28950. return result + (index ? ' ' : '') + word.toLowerCase();
  28951. });
  28952. /**
  28953. * Converts the first character of `string` to lower case.
  28954. *
  28955. * @static
  28956. * @memberOf _
  28957. * @since 4.0.0
  28958. * @category String
  28959. * @param {string} [string=''] The string to convert.
  28960. * @returns {string} Returns the converted string.
  28961. * @example
  28962. *
  28963. * _.lowerFirst('Fred');
  28964. * // => 'fred'
  28965. *
  28966. * _.lowerFirst('FRED');
  28967. * // => 'fRED'
  28968. */
  28969. var lowerFirst = createCaseFirst('toLowerCase');
  28970. /**
  28971. * Pads `string` on the left and right sides if it's shorter than `length`.
  28972. * Padding characters are truncated if they can't be evenly divided by `length`.
  28973. *
  28974. * @static
  28975. * @memberOf _
  28976. * @since 3.0.0
  28977. * @category String
  28978. * @param {string} [string=''] The string to pad.
  28979. * @param {number} [length=0] The padding length.
  28980. * @param {string} [chars=' '] The string used as padding.
  28981. * @returns {string} Returns the padded string.
  28982. * @example
  28983. *
  28984. * _.pad('abc', 8);
  28985. * // => ' abc '
  28986. *
  28987. * _.pad('abc', 8, '_-');
  28988. * // => '_-abc_-_'
  28989. *
  28990. * _.pad('abc', 3);
  28991. * // => 'abc'
  28992. */
  28993. function pad(string, length, chars) {
  28994. string = toString(string);
  28995. length = toInteger(length);
  28996. var strLength = length ? stringSize(string) : 0;
  28997. if (!length || strLength >= length) {
  28998. return string;
  28999. }
  29000. var mid = (length - strLength) / 2;
  29001. return (
  29002. createPadding(nativeFloor(mid), chars) +
  29003. string +
  29004. createPadding(nativeCeil(mid), chars)
  29005. );
  29006. }
  29007. /**
  29008. * Pads `string` on the right side if it's shorter than `length`. Padding
  29009. * characters are truncated if they exceed `length`.
  29010. *
  29011. * @static
  29012. * @memberOf _
  29013. * @since 4.0.0
  29014. * @category String
  29015. * @param {string} [string=''] The string to pad.
  29016. * @param {number} [length=0] The padding length.
  29017. * @param {string} [chars=' '] The string used as padding.
  29018. * @returns {string} Returns the padded string.
  29019. * @example
  29020. *
  29021. * _.padEnd('abc', 6);
  29022. * // => 'abc '
  29023. *
  29024. * _.padEnd('abc', 6, '_-');
  29025. * // => 'abc_-_'
  29026. *
  29027. * _.padEnd('abc', 3);
  29028. * // => 'abc'
  29029. */
  29030. function padEnd(string, length, chars) {
  29031. string = toString(string);
  29032. length = toInteger(length);
  29033. var strLength = length ? stringSize(string) : 0;
  29034. return (length && strLength < length)
  29035. ? (string + createPadding(length - strLength, chars))
  29036. : string;
  29037. }
  29038. /**
  29039. * Pads `string` on the left side if it's shorter than `length`. Padding
  29040. * characters are truncated if they exceed `length`.
  29041. *
  29042. * @static
  29043. * @memberOf _
  29044. * @since 4.0.0
  29045. * @category String
  29046. * @param {string} [string=''] The string to pad.
  29047. * @param {number} [length=0] The padding length.
  29048. * @param {string} [chars=' '] The string used as padding.
  29049. * @returns {string} Returns the padded string.
  29050. * @example
  29051. *
  29052. * _.padStart('abc', 6);
  29053. * // => ' abc'
  29054. *
  29055. * _.padStart('abc', 6, '_-');
  29056. * // => '_-_abc'
  29057. *
  29058. * _.padStart('abc', 3);
  29059. * // => 'abc'
  29060. */
  29061. function padStart(string, length, chars) {
  29062. string = toString(string);
  29063. length = toInteger(length);
  29064. var strLength = length ? stringSize(string) : 0;
  29065. return (length && strLength < length)
  29066. ? (createPadding(length - strLength, chars) + string)
  29067. : string;
  29068. }
  29069. /**
  29070. * Converts `string` to an integer of the specified radix. If `radix` is
  29071. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  29072. * hexadecimal, in which case a `radix` of `16` is used.
  29073. *
  29074. * **Note:** This method aligns with the
  29075. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  29076. *
  29077. * @static
  29078. * @memberOf _
  29079. * @since 1.1.0
  29080. * @category String
  29081. * @param {string} string The string to convert.
  29082. * @param {number} [radix=10] The radix to interpret `value` by.
  29083. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  29084. * @returns {number} Returns the converted integer.
  29085. * @example
  29086. *
  29087. * _.parseInt('08');
  29088. * // => 8
  29089. *
  29090. * _.map(['6', '08', '10'], _.parseInt);
  29091. * // => [6, 8, 10]
  29092. */
  29093. function parseInt(string, radix, guard) {
  29094. // Chrome fails to trim leading <BOM> whitespace characters.
  29095. // See https://bugs.chromium.org/p/v8/issues/detail?id=3109 for more details.
  29096. if (guard || radix == null) {
  29097. radix = 0;
  29098. } else if (radix) {
  29099. radix = +radix;
  29100. }
  29101. string = toString(string).replace(reTrim, '');
  29102. return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
  29103. }
  29104. /**
  29105. * Repeats the given string `n` times.
  29106. *
  29107. * @static
  29108. * @memberOf _
  29109. * @since 3.0.0
  29110. * @category String
  29111. * @param {string} [string=''] The string to repeat.
  29112. * @param {number} [n=1] The number of times to repeat the string.
  29113. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  29114. * @returns {string} Returns the repeated string.
  29115. * @example
  29116. *
  29117. * _.repeat('*', 3);
  29118. * // => '***'
  29119. *
  29120. * _.repeat('abc', 2);
  29121. * // => 'abcabc'
  29122. *
  29123. * _.repeat('abc', 0);
  29124. * // => ''
  29125. */
  29126. function repeat(string, n, guard) {
  29127. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  29128. n = 1;
  29129. } else {
  29130. n = toInteger(n);
  29131. }
  29132. return baseRepeat(toString(string), n);
  29133. }
  29134. /**
  29135. * Replaces matches for `pattern` in `string` with `replacement`.
  29136. *
  29137. * **Note:** This method is based on
  29138. * [`String#replace`](https://mdn.io/String/replace).
  29139. *
  29140. * @static
  29141. * @memberOf _
  29142. * @since 4.0.0
  29143. * @category String
  29144. * @param {string} [string=''] The string to modify.
  29145. * @param {RegExp|string} pattern The pattern to replace.
  29146. * @param {Function|string} replacement The match replacement.
  29147. * @returns {string} Returns the modified string.
  29148. * @example
  29149. *
  29150. * _.replace('Hi Fred', 'Fred', 'Barney');
  29151. * // => 'Hi Barney'
  29152. */
  29153. function replace() {
  29154. var args = arguments,
  29155. string = toString(args[0]);
  29156. return args.length < 3 ? string : nativeReplace.call(string, args[1], args[2]);
  29157. }
  29158. /**
  29159. * Converts `string` to
  29160. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  29161. *
  29162. * @static
  29163. * @memberOf _
  29164. * @since 3.0.0
  29165. * @category String
  29166. * @param {string} [string=''] The string to convert.
  29167. * @returns {string} Returns the snake cased string.
  29168. * @example
  29169. *
  29170. * _.snakeCase('Foo Bar');
  29171. * // => 'foo_bar'
  29172. *
  29173. * _.snakeCase('fooBar');
  29174. * // => 'foo_bar'
  29175. *
  29176. * _.snakeCase('--FOO-BAR--');
  29177. * // => 'foo_bar'
  29178. */
  29179. var snakeCase = createCompounder(function(result, word, index) {
  29180. return result + (index ? '_' : '') + word.toLowerCase();
  29181. });
  29182. /**
  29183. * Splits `string` by `separator`.
  29184. *
  29185. * **Note:** This method is based on
  29186. * [`String#split`](https://mdn.io/String/split).
  29187. *
  29188. * @static
  29189. * @memberOf _
  29190. * @since 4.0.0
  29191. * @category String
  29192. * @param {string} [string=''] The string to split.
  29193. * @param {RegExp|string} separator The separator pattern to split by.
  29194. * @param {number} [limit] The length to truncate results to.
  29195. * @returns {Array} Returns the string segments.
  29196. * @example
  29197. *
  29198. * _.split('a-b-c', '-', 2);
  29199. * // => ['a', 'b']
  29200. */
  29201. function split(string, separator, limit) {
  29202. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  29203. separator = limit = undefined;
  29204. }
  29205. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  29206. if (!limit) {
  29207. return [];
  29208. }
  29209. string = toString(string);
  29210. if (string && (
  29211. typeof separator == 'string' ||
  29212. (separator != null && !isRegExp(separator))
  29213. )) {
  29214. separator = baseToString(separator);
  29215. if (separator == '' && reHasComplexSymbol.test(string)) {
  29216. return castSlice(stringToArray(string), 0, limit);
  29217. }
  29218. }
  29219. return nativeSplit.call(string, separator, limit);
  29220. }
  29221. /**
  29222. * Converts `string` to
  29223. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  29224. *
  29225. * @static
  29226. * @memberOf _
  29227. * @since 3.1.0
  29228. * @category String
  29229. * @param {string} [string=''] The string to convert.
  29230. * @returns {string} Returns the start cased string.
  29231. * @example
  29232. *
  29233. * _.startCase('--foo-bar--');
  29234. * // => 'Foo Bar'
  29235. *
  29236. * _.startCase('fooBar');
  29237. * // => 'Foo Bar'
  29238. *
  29239. * _.startCase('__FOO_BAR__');
  29240. * // => 'FOO BAR'
  29241. */
  29242. var startCase = createCompounder(function(result, word, index) {
  29243. return result + (index ? ' ' : '') + upperFirst(word);
  29244. });
  29245. /**
  29246. * Checks if `string` starts with the given target string.
  29247. *
  29248. * @static
  29249. * @memberOf _
  29250. * @since 3.0.0
  29251. * @category String
  29252. * @param {string} [string=''] The string to search.
  29253. * @param {string} [target] The string to search for.
  29254. * @param {number} [position=0] The position to search from.
  29255. * @returns {boolean} Returns `true` if `string` starts with `target`,
  29256. * else `false`.
  29257. * @example
  29258. *
  29259. * _.startsWith('abc', 'a');
  29260. * // => true
  29261. *
  29262. * _.startsWith('abc', 'b');
  29263. * // => false
  29264. *
  29265. * _.startsWith('abc', 'b', 1);
  29266. * // => true
  29267. */
  29268. function startsWith(string, target, position) {
  29269. string = toString(string);
  29270. position = baseClamp(toInteger(position), 0, string.length);
  29271. return string.lastIndexOf(baseToString(target), position) == position;
  29272. }
  29273. /**
  29274. * Creates a compiled template function that can interpolate data properties
  29275. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  29276. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  29277. * properties may be accessed as free variables in the template. If a setting
  29278. * object is given, it takes precedence over `_.templateSettings` values.
  29279. *
  29280. * **Note:** In the development build `_.template` utilizes
  29281. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  29282. * for easier debugging.
  29283. *
  29284. * For more information on precompiling templates see
  29285. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  29286. *
  29287. * For more information on Chrome extension sandboxes see
  29288. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  29289. *
  29290. * @static
  29291. * @since 0.1.0
  29292. * @memberOf _
  29293. * @category String
  29294. * @param {string} [string=''] The template string.
  29295. * @param {Object} [options={}] The options object.
  29296. * @param {RegExp} [options.escape=_.templateSettings.escape]
  29297. * The HTML "escape" delimiter.
  29298. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  29299. * The "evaluate" delimiter.
  29300. * @param {Object} [options.imports=_.templateSettings.imports]
  29301. * An object to import into the template as free variables.
  29302. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  29303. * The "interpolate" delimiter.
  29304. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  29305. * The sourceURL of the compiled template.
  29306. * @param {string} [options.variable='obj']
  29307. * The data object variable name.
  29308. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  29309. * @returns {Function} Returns the compiled template function.
  29310. * @example
  29311. *
  29312. * // Use the "interpolate" delimiter to create a compiled template.
  29313. * var compiled = _.template('hello <%= user %>!');
  29314. * compiled({ 'user': 'fred' });
  29315. * // => 'hello fred!'
  29316. *
  29317. * // Use the HTML "escape" delimiter to escape data property values.
  29318. * var compiled = _.template('<b><%- value %></b>');
  29319. * compiled({ 'value': '<script>' });
  29320. * // => '<b>&lt;script&gt;</b>'
  29321. *
  29322. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  29323. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  29324. * compiled({ 'users': ['fred', 'barney'] });
  29325. * // => '<li>fred</li><li>barney</li>'
  29326. *
  29327. * // Use the internal `print` function in "evaluate" delimiters.
  29328. * var compiled = _.template('<% print("hello " + user); %>!');
  29329. * compiled({ 'user': 'barney' });
  29330. * // => 'hello barney!'
  29331. *
  29332. * // Use the ES delimiter as an alternative to the default "interpolate" delimiter.
  29333. * var compiled = _.template('hello ${ user }!');
  29334. * compiled({ 'user': 'pebbles' });
  29335. * // => 'hello pebbles!'
  29336. *
  29337. * // Use backslashes to treat delimiters as plain text.
  29338. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  29339. * compiled({ 'value': 'ignored' });
  29340. * // => '<%- value %>'
  29341. *
  29342. * // Use the `imports` option to import `jQuery` as `jq`.
  29343. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  29344. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  29345. * compiled({ 'users': ['fred', 'barney'] });
  29346. * // => '<li>fred</li><li>barney</li>'
  29347. *
  29348. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  29349. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  29350. * compiled(data);
  29351. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  29352. *
  29353. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  29354. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  29355. * compiled.source;
  29356. * // => function(data) {
  29357. * // var __t, __p = '';
  29358. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  29359. * // return __p;
  29360. * // }
  29361. *
  29362. * // Use custom template delimiters.
  29363. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  29364. * var compiled = _.template('hello {{ user }}!');
  29365. * compiled({ 'user': 'mustache' });
  29366. * // => 'hello mustache!'
  29367. *
  29368. * // Use the `source` property to inline compiled templates for meaningful
  29369. * // line numbers in error messages and stack traces.
  29370. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  29371. * var JST = {\
  29372. * "main": ' + _.template(mainText).source + '\
  29373. * };\
  29374. * ');
  29375. */
  29376. function template(string, options, guard) {
  29377. // Based on John Resig's `tmpl` implementation
  29378. // (http://ejohn.org/blog/javascript-micro-templating/)
  29379. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  29380. var settings = lodash.templateSettings;
  29381. if (guard && isIterateeCall(string, options, guard)) {
  29382. options = undefined;
  29383. }
  29384. string = toString(string);
  29385. options = assignInWith({}, options, settings, assignInDefaults);
  29386. var imports = assignInWith({}, options.imports, settings.imports, assignInDefaults),
  29387. importsKeys = keys(imports),
  29388. importsValues = baseValues(imports, importsKeys);
  29389. var isEscaping,
  29390. isEvaluating,
  29391. index = 0,
  29392. interpolate = options.interpolate || reNoMatch,
  29393. source = "__p += '";
  29394. // Compile the regexp to match each delimiter.
  29395. var reDelimiters = RegExp(
  29396. (options.escape || reNoMatch).source + '|' +
  29397. interpolate.source + '|' +
  29398. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  29399. (options.evaluate || reNoMatch).source + '|$'
  29400. , 'g');
  29401. // Use a sourceURL for easier debugging.
  29402. var sourceURL = '//# sourceURL=' +
  29403. ('sourceURL' in options
  29404. ? options.sourceURL
  29405. : ('lodash.templateSources[' + (++templateCounter) + ']')
  29406. ) + '\n';
  29407. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  29408. interpolateValue || (interpolateValue = esTemplateValue);
  29409. // Escape characters that can't be included in string literals.
  29410. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  29411. // Replace delimiters with snippets.
  29412. if (escapeValue) {
  29413. isEscaping = true;
  29414. source += "' +\n__e(" + escapeValue + ") +\n'";
  29415. }
  29416. if (evaluateValue) {
  29417. isEvaluating = true;
  29418. source += "';\n" + evaluateValue + ";\n__p += '";
  29419. }
  29420. if (interpolateValue) {
  29421. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  29422. }
  29423. index = offset + match.length;
  29424. // The JS engine embedded in Adobe products needs `match` returned in
  29425. // order to produce the correct `offset` value.
  29426. return match;
  29427. });
  29428. source += "';\n";
  29429. // If `variable` is not specified wrap a with-statement around the generated
  29430. // code to add the data object to the top of the scope chain.
  29431. var variable = options.variable;
  29432. if (!variable) {
  29433. source = 'with (obj) {\n' + source + '\n}\n';
  29434. }
  29435. // Cleanup code by stripping empty strings.
  29436. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  29437. .replace(reEmptyStringMiddle, '$1')
  29438. .replace(reEmptyStringTrailing, '$1;');
  29439. // Frame code as the function body.
  29440. source = 'function(' + (variable || 'obj') + ') {\n' +
  29441. (variable
  29442. ? ''
  29443. : 'obj || (obj = {});\n'
  29444. ) +
  29445. "var __t, __p = ''" +
  29446. (isEscaping
  29447. ? ', __e = _.escape'
  29448. : ''
  29449. ) +
  29450. (isEvaluating
  29451. ? ', __j = Array.prototype.join;\n' +
  29452. "function print() { __p += __j.call(arguments, '') }\n"
  29453. : ';\n'
  29454. ) +
  29455. source +
  29456. 'return __p\n}';
  29457. var result = attempt(function() {
  29458. return Function(importsKeys, sourceURL + 'return ' + source)
  29459. .apply(undefined, importsValues);
  29460. });
  29461. // Provide the compiled function's source by its `toString` method or
  29462. // the `source` property as a convenience for inlining compiled templates.
  29463. result.source = source;
  29464. if (isError(result)) {
  29465. throw result;
  29466. }
  29467. return result;
  29468. }
  29469. /**
  29470. * Converts `string`, as a whole, to lower case just like
  29471. * [String#toLowerCase](https://mdn.io/toLowerCase).
  29472. *
  29473. * @static
  29474. * @memberOf _
  29475. * @since 4.0.0
  29476. * @category String
  29477. * @param {string} [string=''] The string to convert.
  29478. * @returns {string} Returns the lower cased string.
  29479. * @example
  29480. *
  29481. * _.toLower('--Foo-Bar--');
  29482. * // => '--foo-bar--'
  29483. *
  29484. * _.toLower('fooBar');
  29485. * // => 'foobar'
  29486. *
  29487. * _.toLower('__FOO_BAR__');
  29488. * // => '__foo_bar__'
  29489. */
  29490. function toLower(value) {
  29491. return toString(value).toLowerCase();
  29492. }
  29493. /**
  29494. * Converts `string`, as a whole, to upper case just like
  29495. * [String#toUpperCase](https://mdn.io/toUpperCase).
  29496. *
  29497. * @static
  29498. * @memberOf _
  29499. * @since 4.0.0
  29500. * @category String
  29501. * @param {string} [string=''] The string to convert.
  29502. * @returns {string} Returns the upper cased string.
  29503. * @example
  29504. *
  29505. * _.toUpper('--foo-bar--');
  29506. * // => '--FOO-BAR--'
  29507. *
  29508. * _.toUpper('fooBar');
  29509. * // => 'FOOBAR'
  29510. *
  29511. * _.toUpper('__foo_bar__');
  29512. * // => '__FOO_BAR__'
  29513. */
  29514. function toUpper(value) {
  29515. return toString(value).toUpperCase();
  29516. }
  29517. /**
  29518. * Removes leading and trailing whitespace or specified characters from `string`.
  29519. *
  29520. * @static
  29521. * @memberOf _
  29522. * @since 3.0.0
  29523. * @category String
  29524. * @param {string} [string=''] The string to trim.
  29525. * @param {string} [chars=whitespace] The characters to trim.
  29526. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  29527. * @returns {string} Returns the trimmed string.
  29528. * @example
  29529. *
  29530. * _.trim(' abc ');
  29531. * // => 'abc'
  29532. *
  29533. * _.trim('-_-abc-_-', '_-');
  29534. * // => 'abc'
  29535. *
  29536. * _.map([' foo ', ' bar '], _.trim);
  29537. * // => ['foo', 'bar']
  29538. */
  29539. function trim(string, chars, guard) {
  29540. string = toString(string);
  29541. if (string && (guard || chars === undefined)) {
  29542. return string.replace(reTrim, '');
  29543. }
  29544. if (!string || !(chars = baseToString(chars))) {
  29545. return string;
  29546. }
  29547. var strSymbols = stringToArray(string),
  29548. chrSymbols = stringToArray(chars),
  29549. start = charsStartIndex(strSymbols, chrSymbols),
  29550. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  29551. return castSlice(strSymbols, start, end).join('');
  29552. }
  29553. /**
  29554. * Removes trailing whitespace or specified characters from `string`.
  29555. *
  29556. * @static
  29557. * @memberOf _
  29558. * @since 4.0.0
  29559. * @category String
  29560. * @param {string} [string=''] The string to trim.
  29561. * @param {string} [chars=whitespace] The characters to trim.
  29562. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  29563. * @returns {string} Returns the trimmed string.
  29564. * @example
  29565. *
  29566. * _.trimEnd(' abc ');
  29567. * // => ' abc'
  29568. *
  29569. * _.trimEnd('-_-abc-_-', '_-');
  29570. * // => '-_-abc'
  29571. */
  29572. function trimEnd(string, chars, guard) {
  29573. string = toString(string);
  29574. if (string && (guard || chars === undefined)) {
  29575. return string.replace(reTrimEnd, '');
  29576. }
  29577. if (!string || !(chars = baseToString(chars))) {
  29578. return string;
  29579. }
  29580. var strSymbols = stringToArray(string),
  29581. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  29582. return castSlice(strSymbols, 0, end).join('');
  29583. }
  29584. /**
  29585. * Removes leading whitespace or specified characters from `string`.
  29586. *
  29587. * @static
  29588. * @memberOf _
  29589. * @since 4.0.0
  29590. * @category String
  29591. * @param {string} [string=''] The string to trim.
  29592. * @param {string} [chars=whitespace] The characters to trim.
  29593. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  29594. * @returns {string} Returns the trimmed string.
  29595. * @example
  29596. *
  29597. * _.trimStart(' abc ');
  29598. * // => 'abc '
  29599. *
  29600. * _.trimStart('-_-abc-_-', '_-');
  29601. * // => 'abc-_-'
  29602. */
  29603. function trimStart(string, chars, guard) {
  29604. string = toString(string);
  29605. if (string && (guard || chars === undefined)) {
  29606. return string.replace(reTrimStart, '');
  29607. }
  29608. if (!string || !(chars = baseToString(chars))) {
  29609. return string;
  29610. }
  29611. var strSymbols = stringToArray(string),
  29612. start = charsStartIndex(strSymbols, stringToArray(chars));
  29613. return castSlice(strSymbols, start).join('');
  29614. }
  29615. /**
  29616. * Truncates `string` if it's longer than the given maximum string length.
  29617. * The last characters of the truncated string are replaced with the omission
  29618. * string which defaults to "...".
  29619. *
  29620. * @static
  29621. * @memberOf _
  29622. * @since 4.0.0
  29623. * @category String
  29624. * @param {string} [string=''] The string to truncate.
  29625. * @param {Object} [options={}] The options object.
  29626. * @param {number} [options.length=30] The maximum string length.
  29627. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  29628. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  29629. * @returns {string} Returns the truncated string.
  29630. * @example
  29631. *
  29632. * _.truncate('hi-diddly-ho there, neighborino');
  29633. * // => 'hi-diddly-ho there, neighbo...'
  29634. *
  29635. * _.truncate('hi-diddly-ho there, neighborino', {
  29636. * 'length': 24,
  29637. * 'separator': ' '
  29638. * });
  29639. * // => 'hi-diddly-ho there,...'
  29640. *
  29641. * _.truncate('hi-diddly-ho there, neighborino', {
  29642. * 'length': 24,
  29643. * 'separator': /,? +/
  29644. * });
  29645. * // => 'hi-diddly-ho there...'
  29646. *
  29647. * _.truncate('hi-diddly-ho there, neighborino', {
  29648. * 'omission': ' [...]'
  29649. * });
  29650. * // => 'hi-diddly-ho there, neig [...]'
  29651. */
  29652. function truncate(string, options) {
  29653. var length = DEFAULT_TRUNC_LENGTH,
  29654. omission = DEFAULT_TRUNC_OMISSION;
  29655. if (isObject(options)) {
  29656. var separator = 'separator' in options ? options.separator : separator;
  29657. length = 'length' in options ? toInteger(options.length) : length;
  29658. omission = 'omission' in options ? baseToString(options.omission) : omission;
  29659. }
  29660. string = toString(string);
  29661. var strLength = string.length;
  29662. if (reHasComplexSymbol.test(string)) {
  29663. var strSymbols = stringToArray(string);
  29664. strLength = strSymbols.length;
  29665. }
  29666. if (length >= strLength) {
  29667. return string;
  29668. }
  29669. var end = length - stringSize(omission);
  29670. if (end < 1) {
  29671. return omission;
  29672. }
  29673. var result = strSymbols
  29674. ? castSlice(strSymbols, 0, end).join('')
  29675. : string.slice(0, end);
  29676. if (separator === undefined) {
  29677. return result + omission;
  29678. }
  29679. if (strSymbols) {
  29680. end += (result.length - end);
  29681. }
  29682. if (isRegExp(separator)) {
  29683. if (string.slice(end).search(separator)) {
  29684. var match,
  29685. substring = result;
  29686. if (!separator.global) {
  29687. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  29688. }
  29689. separator.lastIndex = 0;
  29690. while ((match = separator.exec(substring))) {
  29691. var newEnd = match.index;
  29692. }
  29693. result = result.slice(0, newEnd === undefined ? end : newEnd);
  29694. }
  29695. } else if (string.indexOf(baseToString(separator), end) != end) {
  29696. var index = result.lastIndexOf(separator);
  29697. if (index > -1) {
  29698. result = result.slice(0, index);
  29699. }
  29700. }
  29701. return result + omission;
  29702. }
  29703. /**
  29704. * The inverse of `_.escape`; this method converts the HTML entities
  29705. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&#39;`, and `&#96;` in `string` to
  29706. * their corresponding characters.
  29707. *
  29708. * **Note:** No other HTML entities are unescaped. To unescape additional
  29709. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  29710. *
  29711. * @static
  29712. * @memberOf _
  29713. * @since 0.6.0
  29714. * @category String
  29715. * @param {string} [string=''] The string to unescape.
  29716. * @returns {string} Returns the unescaped string.
  29717. * @example
  29718. *
  29719. * _.unescape('fred, barney, &amp; pebbles');
  29720. * // => 'fred, barney, & pebbles'
  29721. */
  29722. function unescape(string) {
  29723. string = toString(string);
  29724. return (string && reHasEscapedHtml.test(string))
  29725. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  29726. : string;
  29727. }
  29728. /**
  29729. * Converts `string`, as space separated words, to upper case.
  29730. *
  29731. * @static
  29732. * @memberOf _
  29733. * @since 4.0.0
  29734. * @category String
  29735. * @param {string} [string=''] The string to convert.
  29736. * @returns {string} Returns the upper cased string.
  29737. * @example
  29738. *
  29739. * _.upperCase('--foo-bar');
  29740. * // => 'FOO BAR'
  29741. *
  29742. * _.upperCase('fooBar');
  29743. * // => 'FOO BAR'
  29744. *
  29745. * _.upperCase('__foo_bar__');
  29746. * // => 'FOO BAR'
  29747. */
  29748. var upperCase = createCompounder(function(result, word, index) {
  29749. return result + (index ? ' ' : '') + word.toUpperCase();
  29750. });
  29751. /**
  29752. * Converts the first character of `string` to upper case.
  29753. *
  29754. * @static
  29755. * @memberOf _
  29756. * @since 4.0.0
  29757. * @category String
  29758. * @param {string} [string=''] The string to convert.
  29759. * @returns {string} Returns the converted string.
  29760. * @example
  29761. *
  29762. * _.upperFirst('fred');
  29763. * // => 'Fred'
  29764. *
  29765. * _.upperFirst('FRED');
  29766. * // => 'FRED'
  29767. */
  29768. var upperFirst = createCaseFirst('toUpperCase');
  29769. /**
  29770. * Splits `string` into an array of its words.
  29771. *
  29772. * @static
  29773. * @memberOf _
  29774. * @since 3.0.0
  29775. * @category String
  29776. * @param {string} [string=''] The string to inspect.
  29777. * @param {RegExp|string} [pattern] The pattern to match words.
  29778. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  29779. * @returns {Array} Returns the words of `string`.
  29780. * @example
  29781. *
  29782. * _.words('fred, barney, & pebbles');
  29783. * // => ['fred', 'barney', 'pebbles']
  29784. *
  29785. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  29786. * // => ['fred', 'barney', '&', 'pebbles']
  29787. */
  29788. function words(string, pattern, guard) {
  29789. string = toString(string);
  29790. pattern = guard ? undefined : pattern;
  29791. if (pattern === undefined) {
  29792. pattern = reHasComplexWord.test(string) ? reComplexWord : reBasicWord;
  29793. }
  29794. return string.match(pattern) || [];
  29795. }
  29796. /*------------------------------------------------------------------------*/
  29797. /**
  29798. * Attempts to invoke `func`, returning either the result or the caught error
  29799. * object. Any additional arguments are provided to `func` when it's invoked.
  29800. *
  29801. * @static
  29802. * @memberOf _
  29803. * @since 3.0.0
  29804. * @category Util
  29805. * @param {Function} func The function to attempt.
  29806. * @param {...*} [args] The arguments to invoke `func` with.
  29807. * @returns {*} Returns the `func` result or error object.
  29808. * @example
  29809. *
  29810. * // Avoid throwing errors for invalid selectors.
  29811. * var elements = _.attempt(function(selector) {
  29812. * return document.querySelectorAll(selector);
  29813. * }, '>_>');
  29814. *
  29815. * if (_.isError(elements)) {
  29816. * elements = [];
  29817. * }
  29818. */
  29819. var attempt = rest(function(func, args) {
  29820. try {
  29821. return apply(func, undefined, args);
  29822. } catch (e) {
  29823. return isError(e) ? e : new Error(e);
  29824. }
  29825. });
  29826. /**
  29827. * Binds methods of an object to the object itself, overwriting the existing
  29828. * method.
  29829. *
  29830. * **Note:** This method doesn't set the "length" property of bound functions.
  29831. *
  29832. * @static
  29833. * @since 0.1.0
  29834. * @memberOf _
  29835. * @category Util
  29836. * @param {Object} object The object to bind and assign the bound methods to.
  29837. * @param {...(string|string[])} methodNames The object method names to bind.
  29838. * @returns {Object} Returns `object`.
  29839. * @example
  29840. *
  29841. * var view = {
  29842. * 'label': 'docs',
  29843. * 'onClick': function() {
  29844. * console.log('clicked ' + this.label);
  29845. * }
  29846. * };
  29847. *
  29848. * _.bindAll(view, ['onClick']);
  29849. * jQuery(element).on('click', view.onClick);
  29850. * // => Logs 'clicked docs' when clicked.
  29851. */
  29852. var bindAll = rest(function(object, methodNames) {
  29853. arrayEach(baseFlatten(methodNames, 1), function(key) {
  29854. key = toKey(key);
  29855. object[key] = bind(object[key], object);
  29856. });
  29857. return object;
  29858. });
  29859. /**
  29860. * Creates a function that iterates over `pairs` and invokes the corresponding
  29861. * function of the first predicate to return truthy. The predicate-function
  29862. * pairs are invoked with the `this` binding and arguments of the created
  29863. * function.
  29864. *
  29865. * @static
  29866. * @memberOf _
  29867. * @since 4.0.0
  29868. * @category Util
  29869. * @param {Array} pairs The predicate-function pairs.
  29870. * @returns {Function} Returns the new composite function.
  29871. * @example
  29872. *
  29873. * var func = _.cond([
  29874. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  29875. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  29876. * [_.constant(true), _.constant('no match')]
  29877. * ]);
  29878. *
  29879. * func({ 'a': 1, 'b': 2 });
  29880. * // => 'matches A'
  29881. *
  29882. * func({ 'a': 0, 'b': 1 });
  29883. * // => 'matches B'
  29884. *
  29885. * func({ 'a': '1', 'b': '2' });
  29886. * // => 'no match'
  29887. */
  29888. function cond(pairs) {
  29889. var length = pairs ? pairs.length : 0,
  29890. toIteratee = getIteratee();
  29891. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  29892. if (typeof pair[1] != 'function') {
  29893. throw new TypeError(FUNC_ERROR_TEXT);
  29894. }
  29895. return [toIteratee(pair[0]), pair[1]];
  29896. });
  29897. return rest(function(args) {
  29898. var index = -1;
  29899. while (++index < length) {
  29900. var pair = pairs[index];
  29901. if (apply(pair[0], this, args)) {
  29902. return apply(pair[1], this, args);
  29903. }
  29904. }
  29905. });
  29906. }
  29907. /**
  29908. * Creates a function that invokes the predicate properties of `source` with
  29909. * the corresponding property values of a given object, returning `true` if
  29910. * all predicates return truthy, else `false`.
  29911. *
  29912. * @static
  29913. * @memberOf _
  29914. * @since 4.0.0
  29915. * @category Util
  29916. * @param {Object} source The object of property predicates to conform to.
  29917. * @returns {Function} Returns the new spec function.
  29918. * @example
  29919. *
  29920. * var users = [
  29921. * { 'user': 'barney', 'age': 36 },
  29922. * { 'user': 'fred', 'age': 40 }
  29923. * ];
  29924. *
  29925. * _.filter(users, _.conforms({ 'age': function(n) { return n > 38; } }));
  29926. * // => [{ 'user': 'fred', 'age': 40 }]
  29927. */
  29928. function conforms(source) {
  29929. return baseConforms(baseClone(source, true));
  29930. }
  29931. /**
  29932. * Creates a function that returns `value`.
  29933. *
  29934. * @static
  29935. * @memberOf _
  29936. * @since 2.4.0
  29937. * @category Util
  29938. * @param {*} value The value to return from the new function.
  29939. * @returns {Function} Returns the new constant function.
  29940. * @example
  29941. *
  29942. * var objects = _.times(2, _.constant({ 'a': 1 }));
  29943. *
  29944. * console.log(objects);
  29945. * // => [{ 'a': 1 }, { 'a': 1 }]
  29946. *
  29947. * console.log(objects[0] === objects[1]);
  29948. * // => true
  29949. */
  29950. function constant(value) {
  29951. return function() {
  29952. return value;
  29953. };
  29954. }
  29955. /**
  29956. * Creates a function that returns the result of invoking the given functions
  29957. * with the `this` binding of the created function, where each successive
  29958. * invocation is supplied the return value of the previous.
  29959. *
  29960. * @static
  29961. * @memberOf _
  29962. * @since 3.0.0
  29963. * @category Util
  29964. * @param {...(Function|Function[])} [funcs] Functions to invoke.
  29965. * @returns {Function} Returns the new composite function.
  29966. * @see _.flowRight
  29967. * @example
  29968. *
  29969. * function square(n) {
  29970. * return n * n;
  29971. * }
  29972. *
  29973. * var addSquare = _.flow([_.add, square]);
  29974. * addSquare(1, 2);
  29975. * // => 9
  29976. */
  29977. var flow = createFlow();
  29978. /**
  29979. * This method is like `_.flow` except that it creates a function that
  29980. * invokes the given functions from right to left.
  29981. *
  29982. * @static
  29983. * @since 3.0.0
  29984. * @memberOf _
  29985. * @category Util
  29986. * @param {...(Function|Function[])} [funcs] Functions to invoke.
  29987. * @returns {Function} Returns the new composite function.
  29988. * @see _.flow
  29989. * @example
  29990. *
  29991. * function square(n) {
  29992. * return n * n;
  29993. * }
  29994. *
  29995. * var addSquare = _.flowRight([square, _.add]);
  29996. * addSquare(1, 2);
  29997. * // => 9
  29998. */
  29999. var flowRight = createFlow(true);
  30000. /**
  30001. * This method returns the first argument given to it.
  30002. *
  30003. * @static
  30004. * @since 0.1.0
  30005. * @memberOf _
  30006. * @category Util
  30007. * @param {*} value Any value.
  30008. * @returns {*} Returns `value`.
  30009. * @example
  30010. *
  30011. * var object = { 'user': 'fred' };
  30012. *
  30013. * console.log(_.identity(object) === object);
  30014. * // => true
  30015. */
  30016. function identity(value) {
  30017. return value;
  30018. }
  30019. /**
  30020. * Creates a function that invokes `func` with the arguments of the created
  30021. * function. If `func` is a property name, the created function returns the
  30022. * property value for a given element. If `func` is an array or object, the
  30023. * created function returns `true` for elements that contain the equivalent
  30024. * source properties, otherwise it returns `false`.
  30025. *
  30026. * @static
  30027. * @since 4.0.0
  30028. * @memberOf _
  30029. * @category Util
  30030. * @param {*} [func=_.identity] The value to convert to a callback.
  30031. * @returns {Function} Returns the callback.
  30032. * @example
  30033. *
  30034. * var users = [
  30035. * { 'user': 'barney', 'age': 36, 'active': true },
  30036. * { 'user': 'fred', 'age': 40, 'active': false }
  30037. * ];
  30038. *
  30039. * // The `_.matches` iteratee shorthand.
  30040. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  30041. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  30042. *
  30043. * // The `_.matchesProperty` iteratee shorthand.
  30044. * _.filter(users, _.iteratee(['user', 'fred']));
  30045. * // => [{ 'user': 'fred', 'age': 40 }]
  30046. *
  30047. * // The `_.property` iteratee shorthand.
  30048. * _.map(users, _.iteratee('user'));
  30049. * // => ['barney', 'fred']
  30050. *
  30051. * // Create custom iteratee shorthands.
  30052. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  30053. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  30054. * return func.test(string);
  30055. * };
  30056. * });
  30057. *
  30058. * _.filter(['abc', 'def'], /ef/);
  30059. * // => ['def']
  30060. */
  30061. function iteratee(func) {
  30062. return baseIteratee(typeof func == 'function' ? func : baseClone(func, true));
  30063. }
  30064. /**
  30065. * Creates a function that performs a partial deep comparison between a given
  30066. * object and `source`, returning `true` if the given object has equivalent
  30067. * property values, else `false`. The created function is equivalent to
  30068. * `_.isMatch` with a `source` partially applied.
  30069. *
  30070. * **Note:** This method supports comparing the same values as `_.isEqual`.
  30071. *
  30072. * @static
  30073. * @memberOf _
  30074. * @since 3.0.0
  30075. * @category Util
  30076. * @param {Object} source The object of property values to match.
  30077. * @returns {Function} Returns the new spec function.
  30078. * @example
  30079. *
  30080. * var users = [
  30081. * { 'user': 'barney', 'age': 36, 'active': true },
  30082. * { 'user': 'fred', 'age': 40, 'active': false }
  30083. * ];
  30084. *
  30085. * _.filter(users, _.matches({ 'age': 40, 'active': false }));
  30086. * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
  30087. */
  30088. function matches(source) {
  30089. return baseMatches(baseClone(source, true));
  30090. }
  30091. /**
  30092. * Creates a function that performs a partial deep comparison between the
  30093. * value at `path` of a given object to `srcValue`, returning `true` if the
  30094. * object value is equivalent, else `false`.
  30095. *
  30096. * **Note:** This method supports comparing the same values as `_.isEqual`.
  30097. *
  30098. * @static
  30099. * @memberOf _
  30100. * @since 3.2.0
  30101. * @category Util
  30102. * @param {Array|string} path The path of the property to get.
  30103. * @param {*} srcValue The value to match.
  30104. * @returns {Function} Returns the new spec function.
  30105. * @example
  30106. *
  30107. * var users = [
  30108. * { 'user': 'barney' },
  30109. * { 'user': 'fred' }
  30110. * ];
  30111. *
  30112. * _.find(users, _.matchesProperty('user', 'fred'));
  30113. * // => { 'user': 'fred' }
  30114. */
  30115. function matchesProperty(path, srcValue) {
  30116. return baseMatchesProperty(path, baseClone(srcValue, true));
  30117. }
  30118. /**
  30119. * Creates a function that invokes the method at `path` of a given object.
  30120. * Any additional arguments are provided to the invoked method.
  30121. *
  30122. * @static
  30123. * @memberOf _
  30124. * @since 3.7.0
  30125. * @category Util
  30126. * @param {Array|string} path The path of the method to invoke.
  30127. * @param {...*} [args] The arguments to invoke the method with.
  30128. * @returns {Function} Returns the new invoker function.
  30129. * @example
  30130. *
  30131. * var objects = [
  30132. * { 'a': { 'b': _.constant(2) } },
  30133. * { 'a': { 'b': _.constant(1) } }
  30134. * ];
  30135. *
  30136. * _.map(objects, _.method('a.b'));
  30137. * // => [2, 1]
  30138. *
  30139. * _.map(objects, _.method(['a', 'b']));
  30140. * // => [2, 1]
  30141. */
  30142. var method = rest(function(path, args) {
  30143. return function(object) {
  30144. return baseInvoke(object, path, args);
  30145. };
  30146. });
  30147. /**
  30148. * The opposite of `_.method`; this method creates a function that invokes
  30149. * the method at a given path of `object`. Any additional arguments are
  30150. * provided to the invoked method.
  30151. *
  30152. * @static
  30153. * @memberOf _
  30154. * @since 3.7.0
  30155. * @category Util
  30156. * @param {Object} object The object to query.
  30157. * @param {...*} [args] The arguments to invoke the method with.
  30158. * @returns {Function} Returns the new invoker function.
  30159. * @example
  30160. *
  30161. * var array = _.times(3, _.constant),
  30162. * object = { 'a': array, 'b': array, 'c': array };
  30163. *
  30164. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  30165. * // => [2, 0]
  30166. *
  30167. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  30168. * // => [2, 0]
  30169. */
  30170. var methodOf = rest(function(object, args) {
  30171. return function(path) {
  30172. return baseInvoke(object, path, args);
  30173. };
  30174. });
  30175. /**
  30176. * Adds all own enumerable string keyed function properties of a source
  30177. * object to the destination object. If `object` is a function, then methods
  30178. * are added to its prototype as well.
  30179. *
  30180. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  30181. * avoid conflicts caused by modifying the original.
  30182. *
  30183. * @static
  30184. * @since 0.1.0
  30185. * @memberOf _
  30186. * @category Util
  30187. * @param {Function|Object} [object=lodash] The destination object.
  30188. * @param {Object} source The object of functions to add.
  30189. * @param {Object} [options={}] The options object.
  30190. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  30191. * @returns {Function|Object} Returns `object`.
  30192. * @example
  30193. *
  30194. * function vowels(string) {
  30195. * return _.filter(string, function(v) {
  30196. * return /[aeiou]/i.test(v);
  30197. * });
  30198. * }
  30199. *
  30200. * _.mixin({ 'vowels': vowels });
  30201. * _.vowels('fred');
  30202. * // => ['e']
  30203. *
  30204. * _('fred').vowels().value();
  30205. * // => ['e']
  30206. *
  30207. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  30208. * _('fred').vowels();
  30209. * // => ['e']
  30210. */
  30211. function mixin(object, source, options) {
  30212. var props = keys(source),
  30213. methodNames = baseFunctions(source, props);
  30214. if (options == null &&
  30215. !(isObject(source) && (methodNames.length || !props.length))) {
  30216. options = source;
  30217. source = object;
  30218. object = this;
  30219. methodNames = baseFunctions(source, keys(source));
  30220. }
  30221. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  30222. isFunc = isFunction(object);
  30223. arrayEach(methodNames, function(methodName) {
  30224. var func = source[methodName];
  30225. object[methodName] = func;
  30226. if (isFunc) {
  30227. object.prototype[methodName] = function() {
  30228. var chainAll = this.__chain__;
  30229. if (chain || chainAll) {
  30230. var result = object(this.__wrapped__),
  30231. actions = result.__actions__ = copyArray(this.__actions__);
  30232. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  30233. result.__chain__ = chainAll;
  30234. return result;
  30235. }
  30236. return func.apply(object, arrayPush([this.value()], arguments));
  30237. };
  30238. }
  30239. });
  30240. return object;
  30241. }
  30242. /**
  30243. * Reverts the `_` variable to its previous value and returns a reference to
  30244. * the `lodash` function.
  30245. *
  30246. * @static
  30247. * @since 0.1.0
  30248. * @memberOf _
  30249. * @category Util
  30250. * @returns {Function} Returns the `lodash` function.
  30251. * @example
  30252. *
  30253. * var lodash = _.noConflict();
  30254. */
  30255. function noConflict() {
  30256. if (root._ === this) {
  30257. root._ = oldDash;
  30258. }
  30259. return this;
  30260. }
  30261. /**
  30262. * A method that returns `undefined`.
  30263. *
  30264. * @static
  30265. * @memberOf _
  30266. * @since 2.3.0
  30267. * @category Util
  30268. * @example
  30269. *
  30270. * _.times(2, _.noop);
  30271. * // => [undefined, undefined]
  30272. */
  30273. function noop() {
  30274. // No operation performed.
  30275. }
  30276. /**
  30277. * Creates a function that gets the argument at index `n`. If `n` is negative,
  30278. * the nth argument from the end is returned.
  30279. *
  30280. * @static
  30281. * @memberOf _
  30282. * @since 4.0.0
  30283. * @category Util
  30284. * @param {number} [n=0] The index of the argument to return.
  30285. * @returns {Function} Returns the new pass-thru function.
  30286. * @example
  30287. *
  30288. * var func = _.nthArg(1);
  30289. * func('a', 'b', 'c', 'd');
  30290. * // => 'b'
  30291. *
  30292. * var func = _.nthArg(-2);
  30293. * func('a', 'b', 'c', 'd');
  30294. * // => 'c'
  30295. */
  30296. function nthArg(n) {
  30297. n = toInteger(n);
  30298. return rest(function(args) {
  30299. return baseNth(args, n);
  30300. });
  30301. }
  30302. /**
  30303. * Creates a function that invokes `iteratees` with the arguments it receives
  30304. * and returns their results.
  30305. *
  30306. * @static
  30307. * @memberOf _
  30308. * @since 4.0.0
  30309. * @category Util
  30310. * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
  30311. * [iteratees=[_.identity]] The iteratees to invoke.
  30312. * @returns {Function} Returns the new function.
  30313. * @example
  30314. *
  30315. * var func = _.over([Math.max, Math.min]);
  30316. *
  30317. * func(1, 2, 3, 4);
  30318. * // => [4, 1]
  30319. */
  30320. var over = createOver(arrayMap);
  30321. /**
  30322. * Creates a function that checks if **all** of the `predicates` return
  30323. * truthy when invoked with the arguments it receives.
  30324. *
  30325. * @static
  30326. * @memberOf _
  30327. * @since 4.0.0
  30328. * @category Util
  30329. * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
  30330. * [predicates=[_.identity]] The predicates to check.
  30331. * @returns {Function} Returns the new function.
  30332. * @example
  30333. *
  30334. * var func = _.overEvery([Boolean, isFinite]);
  30335. *
  30336. * func('1');
  30337. * // => true
  30338. *
  30339. * func(null);
  30340. * // => false
  30341. *
  30342. * func(NaN);
  30343. * // => false
  30344. */
  30345. var overEvery = createOver(arrayEvery);
  30346. /**
  30347. * Creates a function that checks if **any** of the `predicates` return
  30348. * truthy when invoked with the arguments it receives.
  30349. *
  30350. * @static
  30351. * @memberOf _
  30352. * @since 4.0.0
  30353. * @category Util
  30354. * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
  30355. * [predicates=[_.identity]] The predicates to check.
  30356. * @returns {Function} Returns the new function.
  30357. * @example
  30358. *
  30359. * var func = _.overSome([Boolean, isFinite]);
  30360. *
  30361. * func('1');
  30362. * // => true
  30363. *
  30364. * func(null);
  30365. * // => true
  30366. *
  30367. * func(NaN);
  30368. * // => false
  30369. */
  30370. var overSome = createOver(arraySome);
  30371. /**
  30372. * Creates a function that returns the value at `path` of a given object.
  30373. *
  30374. * @static
  30375. * @memberOf _
  30376. * @since 2.4.0
  30377. * @category Util
  30378. * @param {Array|string} path The path of the property to get.
  30379. * @returns {Function} Returns the new accessor function.
  30380. * @example
  30381. *
  30382. * var objects = [
  30383. * { 'a': { 'b': 2 } },
  30384. * { 'a': { 'b': 1 } }
  30385. * ];
  30386. *
  30387. * _.map(objects, _.property('a.b'));
  30388. * // => [2, 1]
  30389. *
  30390. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  30391. * // => [1, 2]
  30392. */
  30393. function property(path) {
  30394. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  30395. }
  30396. /**
  30397. * The opposite of `_.property`; this method creates a function that returns
  30398. * the value at a given path of `object`.
  30399. *
  30400. * @static
  30401. * @memberOf _
  30402. * @since 3.0.0
  30403. * @category Util
  30404. * @param {Object} object The object to query.
  30405. * @returns {Function} Returns the new accessor function.
  30406. * @example
  30407. *
  30408. * var array = [0, 1, 2],
  30409. * object = { 'a': array, 'b': array, 'c': array };
  30410. *
  30411. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  30412. * // => [2, 0]
  30413. *
  30414. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  30415. * // => [2, 0]
  30416. */
  30417. function propertyOf(object) {
  30418. return function(path) {
  30419. return object == null ? undefined : baseGet(object, path);
  30420. };
  30421. }
  30422. /**
  30423. * Creates an array of numbers (positive and/or negative) progressing from
  30424. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  30425. * `start` is specified without an `end` or `step`. If `end` is not specified,
  30426. * it's set to `start` with `start` then set to `0`.
  30427. *
  30428. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  30429. * floating-point values which can produce unexpected results.
  30430. *
  30431. * @static
  30432. * @since 0.1.0
  30433. * @memberOf _
  30434. * @category Util
  30435. * @param {number} [start=0] The start of the range.
  30436. * @param {number} end The end of the range.
  30437. * @param {number} [step=1] The value to increment or decrement by.
  30438. * @returns {Array} Returns the range of numbers.
  30439. * @see _.inRange, _.rangeRight
  30440. * @example
  30441. *
  30442. * _.range(4);
  30443. * // => [0, 1, 2, 3]
  30444. *
  30445. * _.range(-4);
  30446. * // => [0, -1, -2, -3]
  30447. *
  30448. * _.range(1, 5);
  30449. * // => [1, 2, 3, 4]
  30450. *
  30451. * _.range(0, 20, 5);
  30452. * // => [0, 5, 10, 15]
  30453. *
  30454. * _.range(0, -4, -1);
  30455. * // => [0, -1, -2, -3]
  30456. *
  30457. * _.range(1, 4, 0);
  30458. * // => [1, 1, 1]
  30459. *
  30460. * _.range(0);
  30461. * // => []
  30462. */
  30463. var range = createRange();
  30464. /**
  30465. * This method is like `_.range` except that it populates values in
  30466. * descending order.
  30467. *
  30468. * @static
  30469. * @memberOf _
  30470. * @since 4.0.0
  30471. * @category Util
  30472. * @param {number} [start=0] The start of the range.
  30473. * @param {number} end The end of the range.
  30474. * @param {number} [step=1] The value to increment or decrement by.
  30475. * @returns {Array} Returns the range of numbers.
  30476. * @see _.inRange, _.range
  30477. * @example
  30478. *
  30479. * _.rangeRight(4);
  30480. * // => [3, 2, 1, 0]
  30481. *
  30482. * _.rangeRight(-4);
  30483. * // => [-3, -2, -1, 0]
  30484. *
  30485. * _.rangeRight(1, 5);
  30486. * // => [4, 3, 2, 1]
  30487. *
  30488. * _.rangeRight(0, 20, 5);
  30489. * // => [15, 10, 5, 0]
  30490. *
  30491. * _.rangeRight(0, -4, -1);
  30492. * // => [-3, -2, -1, 0]
  30493. *
  30494. * _.rangeRight(1, 4, 0);
  30495. * // => [1, 1, 1]
  30496. *
  30497. * _.rangeRight(0);
  30498. * // => []
  30499. */
  30500. var rangeRight = createRange(true);
  30501. /**
  30502. * A method that returns a new empty array.
  30503. *
  30504. * @static
  30505. * @memberOf _
  30506. * @since 4.13.0
  30507. * @category Util
  30508. * @returns {Array} Returns the new empty array.
  30509. * @example
  30510. *
  30511. * var arrays = _.times(2, _.stubArray);
  30512. *
  30513. * console.log(arrays);
  30514. * // => [[], []]
  30515. *
  30516. * console.log(arrays[0] === arrays[1]);
  30517. * // => false
  30518. */
  30519. function stubArray() {
  30520. return [];
  30521. }
  30522. /**
  30523. * A method that returns `false`.
  30524. *
  30525. * @static
  30526. * @memberOf _
  30527. * @since 4.13.0
  30528. * @category Util
  30529. * @returns {boolean} Returns `false`.
  30530. * @example
  30531. *
  30532. * _.times(2, _.stubFalse);
  30533. * // => [false, false]
  30534. */
  30535. function stubFalse() {
  30536. return false;
  30537. }
  30538. /**
  30539. * A method that returns a new empty object.
  30540. *
  30541. * @static
  30542. * @memberOf _
  30543. * @since 4.13.0
  30544. * @category Util
  30545. * @returns {Object} Returns the new empty object.
  30546. * @example
  30547. *
  30548. * var objects = _.times(2, _.stubObject);
  30549. *
  30550. * console.log(objects);
  30551. * // => [{}, {}]
  30552. *
  30553. * console.log(objects[0] === objects[1]);
  30554. * // => false
  30555. */
  30556. function stubObject() {
  30557. return {};
  30558. }
  30559. /**
  30560. * A method that returns an empty string.
  30561. *
  30562. * @static
  30563. * @memberOf _
  30564. * @since 4.13.0
  30565. * @category Util
  30566. * @returns {string} Returns the empty string.
  30567. * @example
  30568. *
  30569. * _.times(2, _.stubString);
  30570. * // => ['', '']
  30571. */
  30572. function stubString() {
  30573. return '';
  30574. }
  30575. /**
  30576. * A method that returns `true`.
  30577. *
  30578. * @static
  30579. * @memberOf _
  30580. * @since 4.13.0
  30581. * @category Util
  30582. * @returns {boolean} Returns `true`.
  30583. * @example
  30584. *
  30585. * _.times(2, _.stubTrue);
  30586. * // => [true, true]
  30587. */
  30588. function stubTrue() {
  30589. return true;
  30590. }
  30591. /**
  30592. * Invokes the iteratee `n` times, returning an array of the results of
  30593. * each invocation. The iteratee is invoked with one argument; (index).
  30594. *
  30595. * @static
  30596. * @since 0.1.0
  30597. * @memberOf _
  30598. * @category Util
  30599. * @param {number} n The number of times to invoke `iteratee`.
  30600. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  30601. * @returns {Array} Returns the array of results.
  30602. * @example
  30603. *
  30604. * _.times(3, String);
  30605. * // => ['0', '1', '2']
  30606. *
  30607. * _.times(4, _.constant(0));
  30608. * // => [0, 0, 0, 0]
  30609. */
  30610. function times(n, iteratee) {
  30611. n = toInteger(n);
  30612. if (n < 1 || n > MAX_SAFE_INTEGER) {
  30613. return [];
  30614. }
  30615. var index = MAX_ARRAY_LENGTH,
  30616. length = nativeMin(n, MAX_ARRAY_LENGTH);
  30617. iteratee = getIteratee(iteratee);
  30618. n -= MAX_ARRAY_LENGTH;
  30619. var result = baseTimes(length, iteratee);
  30620. while (++index < n) {
  30621. iteratee(index);
  30622. }
  30623. return result;
  30624. }
  30625. /**
  30626. * Converts `value` to a property path array.
  30627. *
  30628. * @static
  30629. * @memberOf _
  30630. * @since 4.0.0
  30631. * @category Util
  30632. * @param {*} value The value to convert.
  30633. * @returns {Array} Returns the new property path array.
  30634. * @example
  30635. *
  30636. * _.toPath('a.b.c');
  30637. * // => ['a', 'b', 'c']
  30638. *
  30639. * _.toPath('a[0].b.c');
  30640. * // => ['a', '0', 'b', 'c']
  30641. */
  30642. function toPath(value) {
  30643. if (isArray(value)) {
  30644. return arrayMap(value, toKey);
  30645. }
  30646. return isSymbol(value) ? [value] : copyArray(stringToPath(value));
  30647. }
  30648. /**
  30649. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  30650. *
  30651. * @static
  30652. * @since 0.1.0
  30653. * @memberOf _
  30654. * @category Util
  30655. * @param {string} [prefix=''] The value to prefix the ID with.
  30656. * @returns {string} Returns the unique ID.
  30657. * @example
  30658. *
  30659. * _.uniqueId('contact_');
  30660. * // => 'contact_104'
  30661. *
  30662. * _.uniqueId();
  30663. * // => '105'
  30664. */
  30665. function uniqueId(prefix) {
  30666. var id = ++idCounter;
  30667. return toString(prefix) + id;
  30668. }
  30669. /*------------------------------------------------------------------------*/
  30670. /**
  30671. * Adds two numbers.
  30672. *
  30673. * @static
  30674. * @memberOf _
  30675. * @since 3.4.0
  30676. * @category Math
  30677. * @param {number} augend The first number in an addition.
  30678. * @param {number} addend The second number in an addition.
  30679. * @returns {number} Returns the total.
  30680. * @example
  30681. *
  30682. * _.add(6, 4);
  30683. * // => 10
  30684. */
  30685. var add = createMathOperation(function(augend, addend) {
  30686. return augend + addend;
  30687. });
  30688. /**
  30689. * Computes `number` rounded up to `precision`.
  30690. *
  30691. * @static
  30692. * @memberOf _
  30693. * @since 3.10.0
  30694. * @category Math
  30695. * @param {number} number The number to round up.
  30696. * @param {number} [precision=0] The precision to round up to.
  30697. * @returns {number} Returns the rounded up number.
  30698. * @example
  30699. *
  30700. * _.ceil(4.006);
  30701. * // => 5
  30702. *
  30703. * _.ceil(6.004, 2);
  30704. * // => 6.01
  30705. *
  30706. * _.ceil(6040, -2);
  30707. * // => 6100
  30708. */
  30709. var ceil = createRound('ceil');
  30710. /**
  30711. * Divide two numbers.
  30712. *
  30713. * @static
  30714. * @memberOf _
  30715. * @since 4.7.0
  30716. * @category Math
  30717. * @param {number} dividend The first number in a division.
  30718. * @param {number} divisor The second number in a division.
  30719. * @returns {number} Returns the quotient.
  30720. * @example
  30721. *
  30722. * _.divide(6, 4);
  30723. * // => 1.5
  30724. */
  30725. var divide = createMathOperation(function(dividend, divisor) {
  30726. return dividend / divisor;
  30727. });
  30728. /**
  30729. * Computes `number` rounded down to `precision`.
  30730. *
  30731. * @static
  30732. * @memberOf _
  30733. * @since 3.10.0
  30734. * @category Math
  30735. * @param {number} number The number to round down.
  30736. * @param {number} [precision=0] The precision to round down to.
  30737. * @returns {number} Returns the rounded down number.
  30738. * @example
  30739. *
  30740. * _.floor(4.006);
  30741. * // => 4
  30742. *
  30743. * _.floor(0.046, 2);
  30744. * // => 0.04
  30745. *
  30746. * _.floor(4060, -2);
  30747. * // => 4000
  30748. */
  30749. var floor = createRound('floor');
  30750. /**
  30751. * Computes the maximum value of `array`. If `array` is empty or falsey,
  30752. * `undefined` is returned.
  30753. *
  30754. * @static
  30755. * @since 0.1.0
  30756. * @memberOf _
  30757. * @category Math
  30758. * @param {Array} array The array to iterate over.
  30759. * @returns {*} Returns the maximum value.
  30760. * @example
  30761. *
  30762. * _.max([4, 2, 8, 6]);
  30763. * // => 8
  30764. *
  30765. * _.max([]);
  30766. * // => undefined
  30767. */
  30768. function max(array) {
  30769. return (array && array.length)
  30770. ? baseExtremum(array, identity, baseGt)
  30771. : undefined;
  30772. }
  30773. /**
  30774. * This method is like `_.max` except that it accepts `iteratee` which is
  30775. * invoked for each element in `array` to generate the criterion by which
  30776. * the value is ranked. The iteratee is invoked with one argument: (value).
  30777. *
  30778. * @static
  30779. * @memberOf _
  30780. * @since 4.0.0
  30781. * @category Math
  30782. * @param {Array} array The array to iterate over.
  30783. * @param {Array|Function|Object|string} [iteratee=_.identity]
  30784. * The iteratee invoked per element.
  30785. * @returns {*} Returns the maximum value.
  30786. * @example
  30787. *
  30788. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  30789. *
  30790. * _.maxBy(objects, function(o) { return o.n; });
  30791. * // => { 'n': 2 }
  30792. *
  30793. * // The `_.property` iteratee shorthand.
  30794. * _.maxBy(objects, 'n');
  30795. * // => { 'n': 2 }
  30796. */
  30797. function maxBy(array, iteratee) {
  30798. return (array && array.length)
  30799. ? baseExtremum(array, getIteratee(iteratee), baseGt)
  30800. : undefined;
  30801. }
  30802. /**
  30803. * Computes the mean of the values in `array`.
  30804. *
  30805. * @static
  30806. * @memberOf _
  30807. * @since 4.0.0
  30808. * @category Math
  30809. * @param {Array} array The array to iterate over.
  30810. * @returns {number} Returns the mean.
  30811. * @example
  30812. *
  30813. * _.mean([4, 2, 8, 6]);
  30814. * // => 5
  30815. */
  30816. function mean(array) {
  30817. return baseMean(array, identity);
  30818. }
  30819. /**
  30820. * This method is like `_.mean` except that it accepts `iteratee` which is
  30821. * invoked for each element in `array` to generate the value to be averaged.
  30822. * The iteratee is invoked with one argument: (value).
  30823. *
  30824. * @static
  30825. * @memberOf _
  30826. * @since 4.7.0
  30827. * @category Math
  30828. * @param {Array} array The array to iterate over.
  30829. * @param {Array|Function|Object|string} [iteratee=_.identity]
  30830. * The iteratee invoked per element.
  30831. * @returns {number} Returns the mean.
  30832. * @example
  30833. *
  30834. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  30835. *
  30836. * _.meanBy(objects, function(o) { return o.n; });
  30837. * // => 5
  30838. *
  30839. * // The `_.property` iteratee shorthand.
  30840. * _.meanBy(objects, 'n');
  30841. * // => 5
  30842. */
  30843. function meanBy(array, iteratee) {
  30844. return baseMean(array, getIteratee(iteratee));
  30845. }
  30846. /**
  30847. * Computes the minimum value of `array`. If `array` is empty or falsey,
  30848. * `undefined` is returned.
  30849. *
  30850. * @static
  30851. * @since 0.1.0
  30852. * @memberOf _
  30853. * @category Math
  30854. * @param {Array} array The array to iterate over.
  30855. * @returns {*} Returns the minimum value.
  30856. * @example
  30857. *
  30858. * _.min([4, 2, 8, 6]);
  30859. * // => 2
  30860. *
  30861. * _.min([]);
  30862. * // => undefined
  30863. */
  30864. function min(array) {
  30865. return (array && array.length)
  30866. ? baseExtremum(array, identity, baseLt)
  30867. : undefined;
  30868. }
  30869. /**
  30870. * This method is like `_.min` except that it accepts `iteratee` which is
  30871. * invoked for each element in `array` to generate the criterion by which
  30872. * the value is ranked. The iteratee is invoked with one argument: (value).
  30873. *
  30874. * @static
  30875. * @memberOf _
  30876. * @since 4.0.0
  30877. * @category Math
  30878. * @param {Array} array The array to iterate over.
  30879. * @param {Array|Function|Object|string} [iteratee=_.identity]
  30880. * The iteratee invoked per element.
  30881. * @returns {*} Returns the minimum value.
  30882. * @example
  30883. *
  30884. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  30885. *
  30886. * _.minBy(objects, function(o) { return o.n; });
  30887. * // => { 'n': 1 }
  30888. *
  30889. * // The `_.property` iteratee shorthand.
  30890. * _.minBy(objects, 'n');
  30891. * // => { 'n': 1 }
  30892. */
  30893. function minBy(array, iteratee) {
  30894. return (array && array.length)
  30895. ? baseExtremum(array, getIteratee(iteratee), baseLt)
  30896. : undefined;
  30897. }
  30898. /**
  30899. * Multiply two numbers.
  30900. *
  30901. * @static
  30902. * @memberOf _
  30903. * @since 4.7.0
  30904. * @category Math
  30905. * @param {number} multiplier The first number in a multiplication.
  30906. * @param {number} multiplicand The second number in a multiplication.
  30907. * @returns {number} Returns the product.
  30908. * @example
  30909. *
  30910. * _.multiply(6, 4);
  30911. * // => 24
  30912. */
  30913. var multiply = createMathOperation(function(multiplier, multiplicand) {
  30914. return multiplier * multiplicand;
  30915. });
  30916. /**
  30917. * Computes `number` rounded to `precision`.
  30918. *
  30919. * @static
  30920. * @memberOf _
  30921. * @since 3.10.0
  30922. * @category Math
  30923. * @param {number} number The number to round.
  30924. * @param {number} [precision=0] The precision to round to.
  30925. * @returns {number} Returns the rounded number.
  30926. * @example
  30927. *
  30928. * _.round(4.006);
  30929. * // => 4
  30930. *
  30931. * _.round(4.006, 2);
  30932. * // => 4.01
  30933. *
  30934. * _.round(4060, -2);
  30935. * // => 4100
  30936. */
  30937. var round = createRound('round');
  30938. /**
  30939. * Subtract two numbers.
  30940. *
  30941. * @static
  30942. * @memberOf _
  30943. * @since 4.0.0
  30944. * @category Math
  30945. * @param {number} minuend The first number in a subtraction.
  30946. * @param {number} subtrahend The second number in a subtraction.
  30947. * @returns {number} Returns the difference.
  30948. * @example
  30949. *
  30950. * _.subtract(6, 4);
  30951. * // => 2
  30952. */
  30953. var subtract = createMathOperation(function(minuend, subtrahend) {
  30954. return minuend - subtrahend;
  30955. });
  30956. /**
  30957. * Computes the sum of the values in `array`.
  30958. *
  30959. * @static
  30960. * @memberOf _
  30961. * @since 3.4.0
  30962. * @category Math
  30963. * @param {Array} array The array to iterate over.
  30964. * @returns {number} Returns the sum.
  30965. * @example
  30966. *
  30967. * _.sum([4, 2, 8, 6]);
  30968. * // => 20
  30969. */
  30970. function sum(array) {
  30971. return (array && array.length)
  30972. ? baseSum(array, identity)
  30973. : 0;
  30974. }
  30975. /**
  30976. * This method is like `_.sum` except that it accepts `iteratee` which is
  30977. * invoked for each element in `array` to generate the value to be summed.
  30978. * The iteratee is invoked with one argument: (value).
  30979. *
  30980. * @static
  30981. * @memberOf _
  30982. * @since 4.0.0
  30983. * @category Math
  30984. * @param {Array} array The array to iterate over.
  30985. * @param {Array|Function|Object|string} [iteratee=_.identity]
  30986. * The iteratee invoked per element.
  30987. * @returns {number} Returns the sum.
  30988. * @example
  30989. *
  30990. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  30991. *
  30992. * _.sumBy(objects, function(o) { return o.n; });
  30993. * // => 20
  30994. *
  30995. * // The `_.property` iteratee shorthand.
  30996. * _.sumBy(objects, 'n');
  30997. * // => 20
  30998. */
  30999. function sumBy(array, iteratee) {
  31000. return (array && array.length)
  31001. ? baseSum(array, getIteratee(iteratee))
  31002. : 0;
  31003. }
  31004. /*------------------------------------------------------------------------*/
  31005. // Add methods that return wrapped values in chain sequences.
  31006. lodash.after = after;
  31007. lodash.ary = ary;
  31008. lodash.assign = assign;
  31009. lodash.assignIn = assignIn;
  31010. lodash.assignInWith = assignInWith;
  31011. lodash.assignWith = assignWith;
  31012. lodash.at = at;
  31013. lodash.before = before;
  31014. lodash.bind = bind;
  31015. lodash.bindAll = bindAll;
  31016. lodash.bindKey = bindKey;
  31017. lodash.castArray = castArray;
  31018. lodash.chain = chain;
  31019. lodash.chunk = chunk;
  31020. lodash.compact = compact;
  31021. lodash.concat = concat;
  31022. lodash.cond = cond;
  31023. lodash.conforms = conforms;
  31024. lodash.constant = constant;
  31025. lodash.countBy = countBy;
  31026. lodash.create = create;
  31027. lodash.curry = curry;
  31028. lodash.curryRight = curryRight;
  31029. lodash.debounce = debounce;
  31030. lodash.defaults = defaults;
  31031. lodash.defaultsDeep = defaultsDeep;
  31032. lodash.defer = defer;
  31033. lodash.delay = delay;
  31034. lodash.difference = difference;
  31035. lodash.differenceBy = differenceBy;
  31036. lodash.differenceWith = differenceWith;
  31037. lodash.drop = drop;
  31038. lodash.dropRight = dropRight;
  31039. lodash.dropRightWhile = dropRightWhile;
  31040. lodash.dropWhile = dropWhile;
  31041. lodash.fill = fill;
  31042. lodash.filter = filter;
  31043. lodash.flatMap = flatMap;
  31044. lodash.flatMapDeep = flatMapDeep;
  31045. lodash.flatMapDepth = flatMapDepth;
  31046. lodash.flatten = flatten;
  31047. lodash.flattenDeep = flattenDeep;
  31048. lodash.flattenDepth = flattenDepth;
  31049. lodash.flip = flip;
  31050. lodash.flow = flow;
  31051. lodash.flowRight = flowRight;
  31052. lodash.fromPairs = fromPairs;
  31053. lodash.functions = functions;
  31054. lodash.functionsIn = functionsIn;
  31055. lodash.groupBy = groupBy;
  31056. lodash.initial = initial;
  31057. lodash.intersection = intersection;
  31058. lodash.intersectionBy = intersectionBy;
  31059. lodash.intersectionWith = intersectionWith;
  31060. lodash.invert = invert;
  31061. lodash.invertBy = invertBy;
  31062. lodash.invokeMap = invokeMap;
  31063. lodash.iteratee = iteratee;
  31064. lodash.keyBy = keyBy;
  31065. lodash.keys = keys;
  31066. lodash.keysIn = keysIn;
  31067. lodash.map = map;
  31068. lodash.mapKeys = mapKeys;
  31069. lodash.mapValues = mapValues;
  31070. lodash.matches = matches;
  31071. lodash.matchesProperty = matchesProperty;
  31072. lodash.memoize = memoize;
  31073. lodash.merge = merge;
  31074. lodash.mergeWith = mergeWith;
  31075. lodash.method = method;
  31076. lodash.methodOf = methodOf;
  31077. lodash.mixin = mixin;
  31078. lodash.negate = negate;
  31079. lodash.nthArg = nthArg;
  31080. lodash.omit = omit;
  31081. lodash.omitBy = omitBy;
  31082. lodash.once = once;
  31083. lodash.orderBy = orderBy;
  31084. lodash.over = over;
  31085. lodash.overArgs = overArgs;
  31086. lodash.overEvery = overEvery;
  31087. lodash.overSome = overSome;
  31088. lodash.partial = partial;
  31089. lodash.partialRight = partialRight;
  31090. lodash.partition = partition;
  31091. lodash.pick = pick;
  31092. lodash.pickBy = pickBy;
  31093. lodash.property = property;
  31094. lodash.propertyOf = propertyOf;
  31095. lodash.pull = pull;
  31096. lodash.pullAll = pullAll;
  31097. lodash.pullAllBy = pullAllBy;
  31098. lodash.pullAllWith = pullAllWith;
  31099. lodash.pullAt = pullAt;
  31100. lodash.range = range;
  31101. lodash.rangeRight = rangeRight;
  31102. lodash.rearg = rearg;
  31103. lodash.reject = reject;
  31104. lodash.remove = remove;
  31105. lodash.rest = rest;
  31106. lodash.reverse = reverse;
  31107. lodash.sampleSize = sampleSize;
  31108. lodash.set = set;
  31109. lodash.setWith = setWith;
  31110. lodash.shuffle = shuffle;
  31111. lodash.slice = slice;
  31112. lodash.sortBy = sortBy;
  31113. lodash.sortedUniq = sortedUniq;
  31114. lodash.sortedUniqBy = sortedUniqBy;
  31115. lodash.split = split;
  31116. lodash.spread = spread;
  31117. lodash.tail = tail;
  31118. lodash.take = take;
  31119. lodash.takeRight = takeRight;
  31120. lodash.takeRightWhile = takeRightWhile;
  31121. lodash.takeWhile = takeWhile;
  31122. lodash.tap = tap;
  31123. lodash.throttle = throttle;
  31124. lodash.thru = thru;
  31125. lodash.toArray = toArray;
  31126. lodash.toPairs = toPairs;
  31127. lodash.toPairsIn = toPairsIn;
  31128. lodash.toPath = toPath;
  31129. lodash.toPlainObject = toPlainObject;
  31130. lodash.transform = transform;
  31131. lodash.unary = unary;
  31132. lodash.union = union;
  31133. lodash.unionBy = unionBy;
  31134. lodash.unionWith = unionWith;
  31135. lodash.uniq = uniq;
  31136. lodash.uniqBy = uniqBy;
  31137. lodash.uniqWith = uniqWith;
  31138. lodash.unset = unset;
  31139. lodash.unzip = unzip;
  31140. lodash.unzipWith = unzipWith;
  31141. lodash.update = update;
  31142. lodash.updateWith = updateWith;
  31143. lodash.values = values;
  31144. lodash.valuesIn = valuesIn;
  31145. lodash.without = without;
  31146. lodash.words = words;
  31147. lodash.wrap = wrap;
  31148. lodash.xor = xor;
  31149. lodash.xorBy = xorBy;
  31150. lodash.xorWith = xorWith;
  31151. lodash.zip = zip;
  31152. lodash.zipObject = zipObject;
  31153. lodash.zipObjectDeep = zipObjectDeep;
  31154. lodash.zipWith = zipWith;
  31155. // Add aliases.
  31156. lodash.entries = toPairs;
  31157. lodash.entriesIn = toPairsIn;
  31158. lodash.extend = assignIn;
  31159. lodash.extendWith = assignInWith;
  31160. // Add methods to `lodash.prototype`.
  31161. mixin(lodash, lodash);
  31162. /*------------------------------------------------------------------------*/
  31163. // Add methods that return unwrapped values in chain sequences.
  31164. lodash.add = add;
  31165. lodash.attempt = attempt;
  31166. lodash.camelCase = camelCase;
  31167. lodash.capitalize = capitalize;
  31168. lodash.ceil = ceil;
  31169. lodash.clamp = clamp;
  31170. lodash.clone = clone;
  31171. lodash.cloneDeep = cloneDeep;
  31172. lodash.cloneDeepWith = cloneDeepWith;
  31173. lodash.cloneWith = cloneWith;
  31174. lodash.deburr = deburr;
  31175. lodash.divide = divide;
  31176. lodash.endsWith = endsWith;
  31177. lodash.eq = eq;
  31178. lodash.escape = escape;
  31179. lodash.escapeRegExp = escapeRegExp;
  31180. lodash.every = every;
  31181. lodash.find = find;
  31182. lodash.findIndex = findIndex;
  31183. lodash.findKey = findKey;
  31184. lodash.findLast = findLast;
  31185. lodash.findLastIndex = findLastIndex;
  31186. lodash.findLastKey = findLastKey;
  31187. lodash.floor = floor;
  31188. lodash.forEach = forEach;
  31189. lodash.forEachRight = forEachRight;
  31190. lodash.forIn = forIn;
  31191. lodash.forInRight = forInRight;
  31192. lodash.forOwn = forOwn;
  31193. lodash.forOwnRight = forOwnRight;
  31194. lodash.get = get;
  31195. lodash.gt = gt;
  31196. lodash.gte = gte;
  31197. lodash.has = has;
  31198. lodash.hasIn = hasIn;
  31199. lodash.head = head;
  31200. lodash.identity = identity;
  31201. lodash.includes = includes;
  31202. lodash.indexOf = indexOf;
  31203. lodash.inRange = inRange;
  31204. lodash.invoke = invoke;
  31205. lodash.isArguments = isArguments;
  31206. lodash.isArray = isArray;
  31207. lodash.isArrayBuffer = isArrayBuffer;
  31208. lodash.isArrayLike = isArrayLike;
  31209. lodash.isArrayLikeObject = isArrayLikeObject;
  31210. lodash.isBoolean = isBoolean;
  31211. lodash.isBuffer = isBuffer;
  31212. lodash.isDate = isDate;
  31213. lodash.isElement = isElement;
  31214. lodash.isEmpty = isEmpty;
  31215. lodash.isEqual = isEqual;
  31216. lodash.isEqualWith = isEqualWith;
  31217. lodash.isError = isError;
  31218. lodash.isFinite = isFinite;
  31219. lodash.isFunction = isFunction;
  31220. lodash.isInteger = isInteger;
  31221. lodash.isLength = isLength;
  31222. lodash.isMap = isMap;
  31223. lodash.isMatch = isMatch;
  31224. lodash.isMatchWith = isMatchWith;
  31225. lodash.isNaN = isNaN;
  31226. lodash.isNative = isNative;
  31227. lodash.isNil = isNil;
  31228. lodash.isNull = isNull;
  31229. lodash.isNumber = isNumber;
  31230. lodash.isObject = isObject;
  31231. lodash.isObjectLike = isObjectLike;
  31232. lodash.isPlainObject = isPlainObject;
  31233. lodash.isRegExp = isRegExp;
  31234. lodash.isSafeInteger = isSafeInteger;
  31235. lodash.isSet = isSet;
  31236. lodash.isString = isString;
  31237. lodash.isSymbol = isSymbol;
  31238. lodash.isTypedArray = isTypedArray;
  31239. lodash.isUndefined = isUndefined;
  31240. lodash.isWeakMap = isWeakMap;
  31241. lodash.isWeakSet = isWeakSet;
  31242. lodash.join = join;
  31243. lodash.kebabCase = kebabCase;
  31244. lodash.last = last;
  31245. lodash.lastIndexOf = lastIndexOf;
  31246. lodash.lowerCase = lowerCase;
  31247. lodash.lowerFirst = lowerFirst;
  31248. lodash.lt = lt;
  31249. lodash.lte = lte;
  31250. lodash.max = max;
  31251. lodash.maxBy = maxBy;
  31252. lodash.mean = mean;
  31253. lodash.meanBy = meanBy;
  31254. lodash.min = min;
  31255. lodash.minBy = minBy;
  31256. lodash.stubArray = stubArray;
  31257. lodash.stubFalse = stubFalse;
  31258. lodash.stubObject = stubObject;
  31259. lodash.stubString = stubString;
  31260. lodash.stubTrue = stubTrue;
  31261. lodash.multiply = multiply;
  31262. lodash.nth = nth;
  31263. lodash.noConflict = noConflict;
  31264. lodash.noop = noop;
  31265. lodash.now = now;
  31266. lodash.pad = pad;
  31267. lodash.padEnd = padEnd;
  31268. lodash.padStart = padStart;
  31269. lodash.parseInt = parseInt;
  31270. lodash.random = random;
  31271. lodash.reduce = reduce;
  31272. lodash.reduceRight = reduceRight;
  31273. lodash.repeat = repeat;
  31274. lodash.replace = replace;
  31275. lodash.result = result;
  31276. lodash.round = round;
  31277. lodash.runInContext = runInContext;
  31278. lodash.sample = sample;
  31279. lodash.size = size;
  31280. lodash.snakeCase = snakeCase;
  31281. lodash.some = some;
  31282. lodash.sortedIndex = sortedIndex;
  31283. lodash.sortedIndexBy = sortedIndexBy;
  31284. lodash.sortedIndexOf = sortedIndexOf;
  31285. lodash.sortedLastIndex = sortedLastIndex;
  31286. lodash.sortedLastIndexBy = sortedLastIndexBy;
  31287. lodash.sortedLastIndexOf = sortedLastIndexOf;
  31288. lodash.startCase = startCase;
  31289. lodash.startsWith = startsWith;
  31290. lodash.subtract = subtract;
  31291. lodash.sum = sum;
  31292. lodash.sumBy = sumBy;
  31293. lodash.template = template;
  31294. lodash.times = times;
  31295. lodash.toFinite = toFinite;
  31296. lodash.toInteger = toInteger;
  31297. lodash.toLength = toLength;
  31298. lodash.toLower = toLower;
  31299. lodash.toNumber = toNumber;
  31300. lodash.toSafeInteger = toSafeInteger;
  31301. lodash.toString = toString;
  31302. lodash.toUpper = toUpper;
  31303. lodash.trim = trim;
  31304. lodash.trimEnd = trimEnd;
  31305. lodash.trimStart = trimStart;
  31306. lodash.truncate = truncate;
  31307. lodash.unescape = unescape;
  31308. lodash.uniqueId = uniqueId;
  31309. lodash.upperCase = upperCase;
  31310. lodash.upperFirst = upperFirst;
  31311. // Add aliases.
  31312. lodash.each = forEach;
  31313. lodash.eachRight = forEachRight;
  31314. lodash.first = head;
  31315. mixin(lodash, (function() {
  31316. var source = {};
  31317. baseForOwn(lodash, function(func, methodName) {
  31318. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  31319. source[methodName] = func;
  31320. }
  31321. });
  31322. return source;
  31323. }()), { 'chain': false });
  31324. /*------------------------------------------------------------------------*/
  31325. /**
  31326. * The semantic version number.
  31327. *
  31328. * @static
  31329. * @memberOf _
  31330. * @type {string}
  31331. */
  31332. lodash.VERSION = VERSION;
  31333. // Assign default placeholders.
  31334. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  31335. lodash[methodName].placeholder = lodash;
  31336. });
  31337. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  31338. arrayEach(['drop', 'take'], function(methodName, index) {
  31339. LazyWrapper.prototype[methodName] = function(n) {
  31340. var filtered = this.__filtered__;
  31341. if (filtered && !index) {
  31342. return new LazyWrapper(this);
  31343. }
  31344. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  31345. var result = this.clone();
  31346. if (filtered) {
  31347. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  31348. } else {
  31349. result.__views__.push({
  31350. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  31351. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  31352. });
  31353. }
  31354. return result;
  31355. };
  31356. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  31357. return this.reverse()[methodName](n).reverse();
  31358. };
  31359. });
  31360. // Add `LazyWrapper` methods that accept an `iteratee` value.
  31361. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  31362. var type = index + 1,
  31363. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  31364. LazyWrapper.prototype[methodName] = function(iteratee) {
  31365. var result = this.clone();
  31366. result.__iteratees__.push({
  31367. 'iteratee': getIteratee(iteratee, 3),
  31368. 'type': type
  31369. });
  31370. result.__filtered__ = result.__filtered__ || isFilter;
  31371. return result;
  31372. };
  31373. });
  31374. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  31375. arrayEach(['head', 'last'], function(methodName, index) {
  31376. var takeName = 'take' + (index ? 'Right' : '');
  31377. LazyWrapper.prototype[methodName] = function() {
  31378. return this[takeName](1).value()[0];
  31379. };
  31380. });
  31381. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  31382. arrayEach(['initial', 'tail'], function(methodName, index) {
  31383. var dropName = 'drop' + (index ? '' : 'Right');
  31384. LazyWrapper.prototype[methodName] = function() {
  31385. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  31386. };
  31387. });
  31388. LazyWrapper.prototype.compact = function() {
  31389. return this.filter(identity);
  31390. };
  31391. LazyWrapper.prototype.find = function(predicate) {
  31392. return this.filter(predicate).head();
  31393. };
  31394. LazyWrapper.prototype.findLast = function(predicate) {
  31395. return this.reverse().find(predicate);
  31396. };
  31397. LazyWrapper.prototype.invokeMap = rest(function(path, args) {
  31398. if (typeof path == 'function') {
  31399. return new LazyWrapper(this);
  31400. }
  31401. return this.map(function(value) {
  31402. return baseInvoke(value, path, args);
  31403. });
  31404. });
  31405. LazyWrapper.prototype.reject = function(predicate) {
  31406. predicate = getIteratee(predicate, 3);
  31407. return this.filter(function(value) {
  31408. return !predicate(value);
  31409. });
  31410. };
  31411. LazyWrapper.prototype.slice = function(start, end) {
  31412. start = toInteger(start);
  31413. var result = this;
  31414. if (result.__filtered__ && (start > 0 || end < 0)) {
  31415. return new LazyWrapper(result);
  31416. }
  31417. if (start < 0) {
  31418. result = result.takeRight(-start);
  31419. } else if (start) {
  31420. result = result.drop(start);
  31421. }
  31422. if (end !== undefined) {
  31423. end = toInteger(end);
  31424. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  31425. }
  31426. return result;
  31427. };
  31428. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  31429. return this.reverse().takeWhile(predicate).reverse();
  31430. };
  31431. LazyWrapper.prototype.toArray = function() {
  31432. return this.take(MAX_ARRAY_LENGTH);
  31433. };
  31434. // Add `LazyWrapper` methods to `lodash.prototype`.
  31435. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  31436. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  31437. isTaker = /^(?:head|last)$/.test(methodName),
  31438. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  31439. retUnwrapped = isTaker || /^find/.test(methodName);
  31440. if (!lodashFunc) {
  31441. return;
  31442. }
  31443. lodash.prototype[methodName] = function() {
  31444. var value = this.__wrapped__,
  31445. args = isTaker ? [1] : arguments,
  31446. isLazy = value instanceof LazyWrapper,
  31447. iteratee = args[0],
  31448. useLazy = isLazy || isArray(value);
  31449. var interceptor = function(value) {
  31450. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  31451. return (isTaker && chainAll) ? result[0] : result;
  31452. };
  31453. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  31454. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  31455. isLazy = useLazy = false;
  31456. }
  31457. var chainAll = this.__chain__,
  31458. isHybrid = !!this.__actions__.length,
  31459. isUnwrapped = retUnwrapped && !chainAll,
  31460. onlyLazy = isLazy && !isHybrid;
  31461. if (!retUnwrapped && useLazy) {
  31462. value = onlyLazy ? value : new LazyWrapper(this);
  31463. var result = func.apply(value, args);
  31464. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  31465. return new LodashWrapper(result, chainAll);
  31466. }
  31467. if (isUnwrapped && onlyLazy) {
  31468. return func.apply(this, args);
  31469. }
  31470. result = this.thru(interceptor);
  31471. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  31472. };
  31473. });
  31474. // Add `Array` methods to `lodash.prototype`.
  31475. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  31476. var func = arrayProto[methodName],
  31477. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  31478. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  31479. lodash.prototype[methodName] = function() {
  31480. var args = arguments;
  31481. if (retUnwrapped && !this.__chain__) {
  31482. var value = this.value();
  31483. return func.apply(isArray(value) ? value : [], args);
  31484. }
  31485. return this[chainName](function(value) {
  31486. return func.apply(isArray(value) ? value : [], args);
  31487. });
  31488. };
  31489. });
  31490. // Map minified method names to their real names.
  31491. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  31492. var lodashFunc = lodash[methodName];
  31493. if (lodashFunc) {
  31494. var key = (lodashFunc.name + ''),
  31495. names = realNames[key] || (realNames[key] = []);
  31496. names.push({ 'name': methodName, 'func': lodashFunc });
  31497. }
  31498. });
  31499. realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{
  31500. 'name': 'wrapper',
  31501. 'func': undefined
  31502. }];
  31503. // Add methods to `LazyWrapper`.
  31504. LazyWrapper.prototype.clone = lazyClone;
  31505. LazyWrapper.prototype.reverse = lazyReverse;
  31506. LazyWrapper.prototype.value = lazyValue;
  31507. // Add chain sequence methods to the `lodash` wrapper.
  31508. lodash.prototype.at = wrapperAt;
  31509. lodash.prototype.chain = wrapperChain;
  31510. lodash.prototype.commit = wrapperCommit;
  31511. lodash.prototype.next = wrapperNext;
  31512. lodash.prototype.plant = wrapperPlant;
  31513. lodash.prototype.reverse = wrapperReverse;
  31514. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  31515. if (iteratorSymbol) {
  31516. lodash.prototype[iteratorSymbol] = wrapperToIterator;
  31517. }
  31518. return lodash;
  31519. }
  31520. /*--------------------------------------------------------------------------*/
  31521. // Export lodash.
  31522. var _ = runInContext();
  31523. // Expose Lodash on the free variable `window` or `self` when available so it's
  31524. // globally accessible, even when bundled with Browserify, Webpack, etc. This
  31525. // also prevents errors in cases where Lodash is loaded by a script tag in the
  31526. // presence of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch
  31527. // for more details. Use `_.noConflict` to remove Lodash from the global object.
  31528. (freeSelf || {})._ = _;
  31529. // Some AMD build optimizers like r.js check for condition patterns like the following:
  31530. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  31531. // Define as an anonymous module so, through path mapping, it can be
  31532. // referenced as the "underscore" module.
  31533. define(function() {
  31534. return _;
  31535. });
  31536. }
  31537. // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
  31538. else if (freeModule) {
  31539. // Export for Node.js.
  31540. (freeModule.exports = _)._ = _;
  31541. // Export for CommonJS support.
  31542. freeExports._ = _;
  31543. }
  31544. else {
  31545. // Export to the global object.
  31546. root._ = _;
  31547. }
  31548. }.call(this));
  31549. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  31550. },{}],103:[function(require,module,exports){
  31551. //! moment.js
  31552. //! version : 2.13.0
  31553. //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
  31554. //! license : MIT
  31555. //! momentjs.com
  31556. ;(function (global, factory) {
  31557. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  31558. typeof define === 'function' && define.amd ? define(factory) :
  31559. global.moment = factory()
  31560. }(this, function () { 'use strict';
  31561. var hookCallback;
  31562. function utils_hooks__hooks () {
  31563. return hookCallback.apply(null, arguments);
  31564. }
  31565. // This is done to register the method called with moment()
  31566. // without creating circular dependencies.
  31567. function setHookCallback (callback) {
  31568. hookCallback = callback;
  31569. }
  31570. function isArray(input) {
  31571. return input instanceof Array || Object.prototype.toString.call(input) === '[object Array]';
  31572. }
  31573. function isDate(input) {
  31574. return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';
  31575. }
  31576. function map(arr, fn) {
  31577. var res = [], i;
  31578. for (i = 0; i < arr.length; ++i) {
  31579. res.push(fn(arr[i], i));
  31580. }
  31581. return res;
  31582. }
  31583. function hasOwnProp(a, b) {
  31584. return Object.prototype.hasOwnProperty.call(a, b);
  31585. }
  31586. function extend(a, b) {
  31587. for (var i in b) {
  31588. if (hasOwnProp(b, i)) {
  31589. a[i] = b[i];
  31590. }
  31591. }
  31592. if (hasOwnProp(b, 'toString')) {
  31593. a.toString = b.toString;
  31594. }
  31595. if (hasOwnProp(b, 'valueOf')) {
  31596. a.valueOf = b.valueOf;
  31597. }
  31598. return a;
  31599. }
  31600. function create_utc__createUTC (input, format, locale, strict) {
  31601. return createLocalOrUTC(input, format, locale, strict, true).utc();
  31602. }
  31603. function defaultParsingFlags() {
  31604. // We need to deep clone this object.
  31605. return {
  31606. empty : false,
  31607. unusedTokens : [],
  31608. unusedInput : [],
  31609. overflow : -2,
  31610. charsLeftOver : 0,
  31611. nullInput : false,
  31612. invalidMonth : null,
  31613. invalidFormat : false,
  31614. userInvalidated : false,
  31615. iso : false,
  31616. parsedDateParts : [],
  31617. meridiem : null
  31618. };
  31619. }
  31620. function getParsingFlags(m) {
  31621. if (m._pf == null) {
  31622. m._pf = defaultParsingFlags();
  31623. }
  31624. return m._pf;
  31625. }
  31626. var some;
  31627. if (Array.prototype.some) {
  31628. some = Array.prototype.some;
  31629. } else {
  31630. some = function (fun) {
  31631. var t = Object(this);
  31632. var len = t.length >>> 0;
  31633. for (var i = 0; i < len; i++) {
  31634. if (i in t && fun.call(this, t[i], i, t)) {
  31635. return true;
  31636. }
  31637. }
  31638. return false;
  31639. };
  31640. }
  31641. function valid__isValid(m) {
  31642. if (m._isValid == null) {
  31643. var flags = getParsingFlags(m);
  31644. var parsedParts = some.call(flags.parsedDateParts, function (i) {
  31645. return i != null;
  31646. });
  31647. m._isValid = !isNaN(m._d.getTime()) &&
  31648. flags.overflow < 0 &&
  31649. !flags.empty &&
  31650. !flags.invalidMonth &&
  31651. !flags.invalidWeekday &&
  31652. !flags.nullInput &&
  31653. !flags.invalidFormat &&
  31654. !flags.userInvalidated &&
  31655. (!flags.meridiem || (flags.meridiem && parsedParts));
  31656. if (m._strict) {
  31657. m._isValid = m._isValid &&
  31658. flags.charsLeftOver === 0 &&
  31659. flags.unusedTokens.length === 0 &&
  31660. flags.bigHour === undefined;
  31661. }
  31662. }
  31663. return m._isValid;
  31664. }
  31665. function valid__createInvalid (flags) {
  31666. var m = create_utc__createUTC(NaN);
  31667. if (flags != null) {
  31668. extend(getParsingFlags(m), flags);
  31669. }
  31670. else {
  31671. getParsingFlags(m).userInvalidated = true;
  31672. }
  31673. return m;
  31674. }
  31675. function isUndefined(input) {
  31676. return input === void 0;
  31677. }
  31678. // Plugins that add properties should also add the key here (null value),
  31679. // so we can properly clone ourselves.
  31680. var momentProperties = utils_hooks__hooks.momentProperties = [];
  31681. function copyConfig(to, from) {
  31682. var i, prop, val;
  31683. if (!isUndefined(from._isAMomentObject)) {
  31684. to._isAMomentObject = from._isAMomentObject;
  31685. }
  31686. if (!isUndefined(from._i)) {
  31687. to._i = from._i;
  31688. }
  31689. if (!isUndefined(from._f)) {
  31690. to._f = from._f;
  31691. }
  31692. if (!isUndefined(from._l)) {
  31693. to._l = from._l;
  31694. }
  31695. if (!isUndefined(from._strict)) {
  31696. to._strict = from._strict;
  31697. }
  31698. if (!isUndefined(from._tzm)) {
  31699. to._tzm = from._tzm;
  31700. }
  31701. if (!isUndefined(from._isUTC)) {
  31702. to._isUTC = from._isUTC;
  31703. }
  31704. if (!isUndefined(from._offset)) {
  31705. to._offset = from._offset;
  31706. }
  31707. if (!isUndefined(from._pf)) {
  31708. to._pf = getParsingFlags(from);
  31709. }
  31710. if (!isUndefined(from._locale)) {
  31711. to._locale = from._locale;
  31712. }
  31713. if (momentProperties.length > 0) {
  31714. for (i in momentProperties) {
  31715. prop = momentProperties[i];
  31716. val = from[prop];
  31717. if (!isUndefined(val)) {
  31718. to[prop] = val;
  31719. }
  31720. }
  31721. }
  31722. return to;
  31723. }
  31724. var updateInProgress = false;
  31725. // Moment prototype object
  31726. function Moment(config) {
  31727. copyConfig(this, config);
  31728. this._d = new Date(config._d != null ? config._d.getTime() : NaN);
  31729. // Prevent infinite loop in case updateOffset creates new moment
  31730. // objects.
  31731. if (updateInProgress === false) {
  31732. updateInProgress = true;
  31733. utils_hooks__hooks.updateOffset(this);
  31734. updateInProgress = false;
  31735. }
  31736. }
  31737. function isMoment (obj) {
  31738. return obj instanceof Moment || (obj != null && obj._isAMomentObject != null);
  31739. }
  31740. function absFloor (number) {
  31741. if (number < 0) {
  31742. return Math.ceil(number);
  31743. } else {
  31744. return Math.floor(number);
  31745. }
  31746. }
  31747. function toInt(argumentForCoercion) {
  31748. var coercedNumber = +argumentForCoercion,
  31749. value = 0;
  31750. if (coercedNumber !== 0 && isFinite(coercedNumber)) {
  31751. value = absFloor(coercedNumber);
  31752. }
  31753. return value;
  31754. }
  31755. // compare two arrays, return the number of differences
  31756. function compareArrays(array1, array2, dontConvert) {
  31757. var len = Math.min(array1.length, array2.length),
  31758. lengthDiff = Math.abs(array1.length - array2.length),
  31759. diffs = 0,
  31760. i;
  31761. for (i = 0; i < len; i++) {
  31762. if ((dontConvert && array1[i] !== array2[i]) ||
  31763. (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
  31764. diffs++;
  31765. }
  31766. }
  31767. return diffs + lengthDiff;
  31768. }
  31769. function warn(msg) {
  31770. if (utils_hooks__hooks.suppressDeprecationWarnings === false &&
  31771. (typeof console !== 'undefined') && console.warn) {
  31772. console.warn('Deprecation warning: ' + msg);
  31773. }
  31774. }
  31775. function deprecate(msg, fn) {
  31776. var firstTime = true;
  31777. return extend(function () {
  31778. if (utils_hooks__hooks.deprecationHandler != null) {
  31779. utils_hooks__hooks.deprecationHandler(null, msg);
  31780. }
  31781. if (firstTime) {
  31782. warn(msg + '\nArguments: ' + Array.prototype.slice.call(arguments).join(', ') + '\n' + (new Error()).stack);
  31783. firstTime = false;
  31784. }
  31785. return fn.apply(this, arguments);
  31786. }, fn);
  31787. }
  31788. var deprecations = {};
  31789. function deprecateSimple(name, msg) {
  31790. if (utils_hooks__hooks.deprecationHandler != null) {
  31791. utils_hooks__hooks.deprecationHandler(name, msg);
  31792. }
  31793. if (!deprecations[name]) {
  31794. warn(msg);
  31795. deprecations[name] = true;
  31796. }
  31797. }
  31798. utils_hooks__hooks.suppressDeprecationWarnings = false;
  31799. utils_hooks__hooks.deprecationHandler = null;
  31800. function isFunction(input) {
  31801. return input instanceof Function || Object.prototype.toString.call(input) === '[object Function]';
  31802. }
  31803. function isObject(input) {
  31804. return Object.prototype.toString.call(input) === '[object Object]';
  31805. }
  31806. function locale_set__set (config) {
  31807. var prop, i;
  31808. for (i in config) {
  31809. prop = config[i];
  31810. if (isFunction(prop)) {
  31811. this[i] = prop;
  31812. } else {
  31813. this['_' + i] = prop;
  31814. }
  31815. }
  31816. this._config = config;
  31817. // Lenient ordinal parsing accepts just a number in addition to
  31818. // number + (possibly) stuff coming from _ordinalParseLenient.
  31819. this._ordinalParseLenient = new RegExp(this._ordinalParse.source + '|' + (/\d{1,2}/).source);
  31820. }
  31821. function mergeConfigs(parentConfig, childConfig) {
  31822. var res = extend({}, parentConfig), prop;
  31823. for (prop in childConfig) {
  31824. if (hasOwnProp(childConfig, prop)) {
  31825. if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) {
  31826. res[prop] = {};
  31827. extend(res[prop], parentConfig[prop]);
  31828. extend(res[prop], childConfig[prop]);
  31829. } else if (childConfig[prop] != null) {
  31830. res[prop] = childConfig[prop];
  31831. } else {
  31832. delete res[prop];
  31833. }
  31834. }
  31835. }
  31836. return res;
  31837. }
  31838. function Locale(config) {
  31839. if (config != null) {
  31840. this.set(config);
  31841. }
  31842. }
  31843. var keys;
  31844. if (Object.keys) {
  31845. keys = Object.keys;
  31846. } else {
  31847. keys = function (obj) {
  31848. var i, res = [];
  31849. for (i in obj) {
  31850. if (hasOwnProp(obj, i)) {
  31851. res.push(i);
  31852. }
  31853. }
  31854. return res;
  31855. };
  31856. }
  31857. // internal storage for locale config files
  31858. var locales = {};
  31859. var globalLocale;
  31860. function normalizeLocale(key) {
  31861. return key ? key.toLowerCase().replace('_', '-') : key;
  31862. }
  31863. // pick the locale from the array
  31864. // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
  31865. // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
  31866. function chooseLocale(names) {
  31867. var i = 0, j, next, locale, split;
  31868. while (i < names.length) {
  31869. split = normalizeLocale(names[i]).split('-');
  31870. j = split.length;
  31871. next = normalizeLocale(names[i + 1]);
  31872. next = next ? next.split('-') : null;
  31873. while (j > 0) {
  31874. locale = loadLocale(split.slice(0, j).join('-'));
  31875. if (locale) {
  31876. return locale;
  31877. }
  31878. if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
  31879. //the next array item is better than a shallower substring of this one
  31880. break;
  31881. }
  31882. j--;
  31883. }
  31884. i++;
  31885. }
  31886. return null;
  31887. }
  31888. function loadLocale(name) {
  31889. var oldLocale = null;
  31890. // TODO: Find a better way to register and load all the locales in Node
  31891. if (!locales[name] && (typeof module !== 'undefined') &&
  31892. module && module.exports) {
  31893. try {
  31894. oldLocale = globalLocale._abbr;
  31895. require('./locale/' + name);
  31896. // because defineLocale currently also sets the global locale, we
  31897. // want to undo that for lazy loaded locales
  31898. locale_locales__getSetGlobalLocale(oldLocale);
  31899. } catch (e) { }
  31900. }
  31901. return locales[name];
  31902. }
  31903. // This function will load locale and then set the global locale. If
  31904. // no arguments are passed in, it will simply return the current global
  31905. // locale key.
  31906. function locale_locales__getSetGlobalLocale (key, values) {
  31907. var data;
  31908. if (key) {
  31909. if (isUndefined(values)) {
  31910. data = locale_locales__getLocale(key);
  31911. }
  31912. else {
  31913. data = defineLocale(key, values);
  31914. }
  31915. if (data) {
  31916. // moment.duration._locale = moment._locale = data;
  31917. globalLocale = data;
  31918. }
  31919. }
  31920. return globalLocale._abbr;
  31921. }
  31922. function defineLocale (name, config) {
  31923. if (config !== null) {
  31924. config.abbr = name;
  31925. if (locales[name] != null) {
  31926. deprecateSimple('defineLocaleOverride',
  31927. 'use moment.updateLocale(localeName, config) to change ' +
  31928. 'an existing locale. moment.defineLocale(localeName, ' +
  31929. 'config) should only be used for creating a new locale');
  31930. config = mergeConfigs(locales[name]._config, config);
  31931. } else if (config.parentLocale != null) {
  31932. if (locales[config.parentLocale] != null) {
  31933. config = mergeConfigs(locales[config.parentLocale]._config, config);
  31934. } else {
  31935. // treat as if there is no base config
  31936. deprecateSimple('parentLocaleUndefined',
  31937. 'specified parentLocale is not defined yet');
  31938. }
  31939. }
  31940. locales[name] = new Locale(config);
  31941. // backwards compat for now: also set the locale
  31942. locale_locales__getSetGlobalLocale(name);
  31943. return locales[name];
  31944. } else {
  31945. // useful for testing
  31946. delete locales[name];
  31947. return null;
  31948. }
  31949. }
  31950. function updateLocale(name, config) {
  31951. if (config != null) {
  31952. var locale;
  31953. if (locales[name] != null) {
  31954. config = mergeConfigs(locales[name]._config, config);
  31955. }
  31956. locale = new Locale(config);
  31957. locale.parentLocale = locales[name];
  31958. locales[name] = locale;
  31959. // backwards compat for now: also set the locale
  31960. locale_locales__getSetGlobalLocale(name);
  31961. } else {
  31962. // pass null for config to unupdate, useful for tests
  31963. if (locales[name] != null) {
  31964. if (locales[name].parentLocale != null) {
  31965. locales[name] = locales[name].parentLocale;
  31966. } else if (locales[name] != null) {
  31967. delete locales[name];
  31968. }
  31969. }
  31970. }
  31971. return locales[name];
  31972. }
  31973. // returns locale data
  31974. function locale_locales__getLocale (key) {
  31975. var locale;
  31976. if (key && key._locale && key._locale._abbr) {
  31977. key = key._locale._abbr;
  31978. }
  31979. if (!key) {
  31980. return globalLocale;
  31981. }
  31982. if (!isArray(key)) {
  31983. //short-circuit everything else
  31984. locale = loadLocale(key);
  31985. if (locale) {
  31986. return locale;
  31987. }
  31988. key = [key];
  31989. }
  31990. return chooseLocale(key);
  31991. }
  31992. function locale_locales__listLocales() {
  31993. return keys(locales);
  31994. }
  31995. var aliases = {};
  31996. function addUnitAlias (unit, shorthand) {
  31997. var lowerCase = unit.toLowerCase();
  31998. aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
  31999. }
  32000. function normalizeUnits(units) {
  32001. return typeof units === 'string' ? aliases[units] || aliases[units.toLowerCase()] : undefined;
  32002. }
  32003. function normalizeObjectUnits(inputObject) {
  32004. var normalizedInput = {},
  32005. normalizedProp,
  32006. prop;
  32007. for (prop in inputObject) {
  32008. if (hasOwnProp(inputObject, prop)) {
  32009. normalizedProp = normalizeUnits(prop);
  32010. if (normalizedProp) {
  32011. normalizedInput[normalizedProp] = inputObject[prop];
  32012. }
  32013. }
  32014. }
  32015. return normalizedInput;
  32016. }
  32017. function makeGetSet (unit, keepTime) {
  32018. return function (value) {
  32019. if (value != null) {
  32020. get_set__set(this, unit, value);
  32021. utils_hooks__hooks.updateOffset(this, keepTime);
  32022. return this;
  32023. } else {
  32024. return get_set__get(this, unit);
  32025. }
  32026. };
  32027. }
  32028. function get_set__get (mom, unit) {
  32029. return mom.isValid() ?
  32030. mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]() : NaN;
  32031. }
  32032. function get_set__set (mom, unit, value) {
  32033. if (mom.isValid()) {
  32034. mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
  32035. }
  32036. }
  32037. // MOMENTS
  32038. function getSet (units, value) {
  32039. var unit;
  32040. if (typeof units === 'object') {
  32041. for (unit in units) {
  32042. this.set(unit, units[unit]);
  32043. }
  32044. } else {
  32045. units = normalizeUnits(units);
  32046. if (isFunction(this[units])) {
  32047. return this[units](value);
  32048. }
  32049. }
  32050. return this;
  32051. }
  32052. function zeroFill(number, targetLength, forceSign) {
  32053. var absNumber = '' + Math.abs(number),
  32054. zerosToFill = targetLength - absNumber.length,
  32055. sign = number >= 0;
  32056. return (sign ? (forceSign ? '+' : '') : '-') +
  32057. Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber;
  32058. }
  32059. var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;
  32060. var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;
  32061. var formatFunctions = {};
  32062. var formatTokenFunctions = {};
  32063. // token: 'M'
  32064. // padded: ['MM', 2]
  32065. // ordinal: 'Mo'
  32066. // callback: function () { this.month() + 1 }
  32067. function addFormatToken (token, padded, ordinal, callback) {
  32068. var func = callback;
  32069. if (typeof callback === 'string') {
  32070. func = function () {
  32071. return this[callback]();
  32072. };
  32073. }
  32074. if (token) {
  32075. formatTokenFunctions[token] = func;
  32076. }
  32077. if (padded) {
  32078. formatTokenFunctions[padded[0]] = function () {
  32079. return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
  32080. };
  32081. }
  32082. if (ordinal) {
  32083. formatTokenFunctions[ordinal] = function () {
  32084. return this.localeData().ordinal(func.apply(this, arguments), token);
  32085. };
  32086. }
  32087. }
  32088. function removeFormattingTokens(input) {
  32089. if (input.match(/\[[\s\S]/)) {
  32090. return input.replace(/^\[|\]$/g, '');
  32091. }
  32092. return input.replace(/\\/g, '');
  32093. }
  32094. function makeFormatFunction(format) {
  32095. var array = format.match(formattingTokens), i, length;
  32096. for (i = 0, length = array.length; i < length; i++) {
  32097. if (formatTokenFunctions[array[i]]) {
  32098. array[i] = formatTokenFunctions[array[i]];
  32099. } else {
  32100. array[i] = removeFormattingTokens(array[i]);
  32101. }
  32102. }
  32103. return function (mom) {
  32104. var output = '', i;
  32105. for (i = 0; i < length; i++) {
  32106. output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];
  32107. }
  32108. return output;
  32109. };
  32110. }
  32111. // format date using native date object
  32112. function formatMoment(m, format) {
  32113. if (!m.isValid()) {
  32114. return m.localeData().invalidDate();
  32115. }
  32116. format = expandFormat(format, m.localeData());
  32117. formatFunctions[format] = formatFunctions[format] || makeFormatFunction(format);
  32118. return formatFunctions[format](m);
  32119. }
  32120. function expandFormat(format, locale) {
  32121. var i = 5;
  32122. function replaceLongDateFormatTokens(input) {
  32123. return locale.longDateFormat(input) || input;
  32124. }
  32125. localFormattingTokens.lastIndex = 0;
  32126. while (i >= 0 && localFormattingTokens.test(format)) {
  32127. format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
  32128. localFormattingTokens.lastIndex = 0;
  32129. i -= 1;
  32130. }
  32131. return format;
  32132. }
  32133. var match1 = /\d/; // 0 - 9
  32134. var match2 = /\d\d/; // 00 - 99
  32135. var match3 = /\d{3}/; // 000 - 999
  32136. var match4 = /\d{4}/; // 0000 - 9999
  32137. var match6 = /[+-]?\d{6}/; // -999999 - 999999
  32138. var match1to2 = /\d\d?/; // 0 - 99
  32139. var match3to4 = /\d\d\d\d?/; // 999 - 9999
  32140. var match5to6 = /\d\d\d\d\d\d?/; // 99999 - 999999
  32141. var match1to3 = /\d{1,3}/; // 0 - 999
  32142. var match1to4 = /\d{1,4}/; // 0 - 9999
  32143. var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999
  32144. var matchUnsigned = /\d+/; // 0 - inf
  32145. var matchSigned = /[+-]?\d+/; // -inf - inf
  32146. var matchOffset = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
  32147. var matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z
  32148. var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
  32149. // any word (or two) characters or numbers including two/three word month in arabic.
  32150. // includes scottish gaelic two word and hyphenated months
  32151. var matchWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i;
  32152. var regexes = {};
  32153. function addRegexToken (token, regex, strictRegex) {
  32154. regexes[token] = isFunction(regex) ? regex : function (isStrict, localeData) {
  32155. return (isStrict && strictRegex) ? strictRegex : regex;
  32156. };
  32157. }
  32158. function getParseRegexForToken (token, config) {
  32159. if (!hasOwnProp(regexes, token)) {
  32160. return new RegExp(unescapeFormat(token));
  32161. }
  32162. return regexes[token](config._strict, config._locale);
  32163. }
  32164. // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
  32165. function unescapeFormat(s) {
  32166. return regexEscape(s.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
  32167. return p1 || p2 || p3 || p4;
  32168. }));
  32169. }
  32170. function regexEscape(s) {
  32171. return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  32172. }
  32173. var tokens = {};
  32174. function addParseToken (token, callback) {
  32175. var i, func = callback;
  32176. if (typeof token === 'string') {
  32177. token = [token];
  32178. }
  32179. if (typeof callback === 'number') {
  32180. func = function (input, array) {
  32181. array[callback] = toInt(input);
  32182. };
  32183. }
  32184. for (i = 0; i < token.length; i++) {
  32185. tokens[token[i]] = func;
  32186. }
  32187. }
  32188. function addWeekParseToken (token, callback) {
  32189. addParseToken(token, function (input, array, config, token) {
  32190. config._w = config._w || {};
  32191. callback(input, config._w, config, token);
  32192. });
  32193. }
  32194. function addTimeToArrayFromToken(token, input, config) {
  32195. if (input != null && hasOwnProp(tokens, token)) {
  32196. tokens[token](input, config._a, config, token);
  32197. }
  32198. }
  32199. var YEAR = 0;
  32200. var MONTH = 1;
  32201. var DATE = 2;
  32202. var HOUR = 3;
  32203. var MINUTE = 4;
  32204. var SECOND = 5;
  32205. var MILLISECOND = 6;
  32206. var WEEK = 7;
  32207. var WEEKDAY = 8;
  32208. var indexOf;
  32209. if (Array.prototype.indexOf) {
  32210. indexOf = Array.prototype.indexOf;
  32211. } else {
  32212. indexOf = function (o) {
  32213. // I know
  32214. var i;
  32215. for (i = 0; i < this.length; ++i) {
  32216. if (this[i] === o) {
  32217. return i;
  32218. }
  32219. }
  32220. return -1;
  32221. };
  32222. }
  32223. function daysInMonth(year, month) {
  32224. return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
  32225. }
  32226. // FORMATTING
  32227. addFormatToken('M', ['MM', 2], 'Mo', function () {
  32228. return this.month() + 1;
  32229. });
  32230. addFormatToken('MMM', 0, 0, function (format) {
  32231. return this.localeData().monthsShort(this, format);
  32232. });
  32233. addFormatToken('MMMM', 0, 0, function (format) {
  32234. return this.localeData().months(this, format);
  32235. });
  32236. // ALIASES
  32237. addUnitAlias('month', 'M');
  32238. // PARSING
  32239. addRegexToken('M', match1to2);
  32240. addRegexToken('MM', match1to2, match2);
  32241. addRegexToken('MMM', function (isStrict, locale) {
  32242. return locale.monthsShortRegex(isStrict);
  32243. });
  32244. addRegexToken('MMMM', function (isStrict, locale) {
  32245. return locale.monthsRegex(isStrict);
  32246. });
  32247. addParseToken(['M', 'MM'], function (input, array) {
  32248. array[MONTH] = toInt(input) - 1;
  32249. });
  32250. addParseToken(['MMM', 'MMMM'], function (input, array, config, token) {
  32251. var month = config._locale.monthsParse(input, token, config._strict);
  32252. // if we didn't find a month name, mark the date as invalid.
  32253. if (month != null) {
  32254. array[MONTH] = month;
  32255. } else {
  32256. getParsingFlags(config).invalidMonth = input;
  32257. }
  32258. });
  32259. // LOCALES
  32260. var MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/;
  32261. var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');
  32262. function localeMonths (m, format) {
  32263. return isArray(this._months) ? this._months[m.month()] :
  32264. this._months[MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'][m.month()];
  32265. }
  32266. var defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
  32267. function localeMonthsShort (m, format) {
  32268. return isArray(this._monthsShort) ? this._monthsShort[m.month()] :
  32269. this._monthsShort[MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'][m.month()];
  32270. }
  32271. function units_month__handleStrictParse(monthName, format, strict) {
  32272. var i, ii, mom, llc = monthName.toLocaleLowerCase();
  32273. if (!this._monthsParse) {
  32274. // this is not used
  32275. this._monthsParse = [];
  32276. this._longMonthsParse = [];
  32277. this._shortMonthsParse = [];
  32278. for (i = 0; i < 12; ++i) {
  32279. mom = create_utc__createUTC([2000, i]);
  32280. this._shortMonthsParse[i] = this.monthsShort(mom, '').toLocaleLowerCase();
  32281. this._longMonthsParse[i] = this.months(mom, '').toLocaleLowerCase();
  32282. }
  32283. }
  32284. if (strict) {
  32285. if (format === 'MMM') {
  32286. ii = indexOf.call(this._shortMonthsParse, llc);
  32287. return ii !== -1 ? ii : null;
  32288. } else {
  32289. ii = indexOf.call(this._longMonthsParse, llc);
  32290. return ii !== -1 ? ii : null;
  32291. }
  32292. } else {
  32293. if (format === 'MMM') {
  32294. ii = indexOf.call(this._shortMonthsParse, llc);
  32295. if (ii !== -1) {
  32296. return ii;
  32297. }
  32298. ii = indexOf.call(this._longMonthsParse, llc);
  32299. return ii !== -1 ? ii : null;
  32300. } else {
  32301. ii = indexOf.call(this._longMonthsParse, llc);
  32302. if (ii !== -1) {
  32303. return ii;
  32304. }
  32305. ii = indexOf.call(this._shortMonthsParse, llc);
  32306. return ii !== -1 ? ii : null;
  32307. }
  32308. }
  32309. }
  32310. function localeMonthsParse (monthName, format, strict) {
  32311. var i, mom, regex;
  32312. if (this._monthsParseExact) {
  32313. return units_month__handleStrictParse.call(this, monthName, format, strict);
  32314. }
  32315. if (!this._monthsParse) {
  32316. this._monthsParse = [];
  32317. this._longMonthsParse = [];
  32318. this._shortMonthsParse = [];
  32319. }
  32320. // TODO: add sorting
  32321. // Sorting makes sure if one month (or abbr) is a prefix of another
  32322. // see sorting in computeMonthsParse
  32323. for (i = 0; i < 12; i++) {
  32324. // make the regex if we don't have it already
  32325. mom = create_utc__createUTC([2000, i]);
  32326. if (strict && !this._longMonthsParse[i]) {
  32327. this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i');
  32328. this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i');
  32329. }
  32330. if (!strict && !this._monthsParse[i]) {
  32331. regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
  32332. this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
  32333. }
  32334. // test the regex
  32335. if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) {
  32336. return i;
  32337. } else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) {
  32338. return i;
  32339. } else if (!strict && this._monthsParse[i].test(monthName)) {
  32340. return i;
  32341. }
  32342. }
  32343. }
  32344. // MOMENTS
  32345. function setMonth (mom, value) {
  32346. var dayOfMonth;
  32347. if (!mom.isValid()) {
  32348. // No op
  32349. return mom;
  32350. }
  32351. if (typeof value === 'string') {
  32352. if (/^\d+$/.test(value)) {
  32353. value = toInt(value);
  32354. } else {
  32355. value = mom.localeData().monthsParse(value);
  32356. // TODO: Another silent failure?
  32357. if (typeof value !== 'number') {
  32358. return mom;
  32359. }
  32360. }
  32361. }
  32362. dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
  32363. mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
  32364. return mom;
  32365. }
  32366. function getSetMonth (value) {
  32367. if (value != null) {
  32368. setMonth(this, value);
  32369. utils_hooks__hooks.updateOffset(this, true);
  32370. return this;
  32371. } else {
  32372. return get_set__get(this, 'Month');
  32373. }
  32374. }
  32375. function getDaysInMonth () {
  32376. return daysInMonth(this.year(), this.month());
  32377. }
  32378. var defaultMonthsShortRegex = matchWord;
  32379. function monthsShortRegex (isStrict) {
  32380. if (this._monthsParseExact) {
  32381. if (!hasOwnProp(this, '_monthsRegex')) {
  32382. computeMonthsParse.call(this);
  32383. }
  32384. if (isStrict) {
  32385. return this._monthsShortStrictRegex;
  32386. } else {
  32387. return this._monthsShortRegex;
  32388. }
  32389. } else {
  32390. return this._monthsShortStrictRegex && isStrict ?
  32391. this._monthsShortStrictRegex : this._monthsShortRegex;
  32392. }
  32393. }
  32394. var defaultMonthsRegex = matchWord;
  32395. function monthsRegex (isStrict) {
  32396. if (this._monthsParseExact) {
  32397. if (!hasOwnProp(this, '_monthsRegex')) {
  32398. computeMonthsParse.call(this);
  32399. }
  32400. if (isStrict) {
  32401. return this._monthsStrictRegex;
  32402. } else {
  32403. return this._monthsRegex;
  32404. }
  32405. } else {
  32406. return this._monthsStrictRegex && isStrict ?
  32407. this._monthsStrictRegex : this._monthsRegex;
  32408. }
  32409. }
  32410. function computeMonthsParse () {
  32411. function cmpLenRev(a, b) {
  32412. return b.length - a.length;
  32413. }
  32414. var shortPieces = [], longPieces = [], mixedPieces = [],
  32415. i, mom;
  32416. for (i = 0; i < 12; i++) {
  32417. // make the regex if we don't have it already
  32418. mom = create_utc__createUTC([2000, i]);
  32419. shortPieces.push(this.monthsShort(mom, ''));
  32420. longPieces.push(this.months(mom, ''));
  32421. mixedPieces.push(this.months(mom, ''));
  32422. mixedPieces.push(this.monthsShort(mom, ''));
  32423. }
  32424. // Sorting makes sure if one month (or abbr) is a prefix of another it
  32425. // will match the longer piece.
  32426. shortPieces.sort(cmpLenRev);
  32427. longPieces.sort(cmpLenRev);
  32428. mixedPieces.sort(cmpLenRev);
  32429. for (i = 0; i < 12; i++) {
  32430. shortPieces[i] = regexEscape(shortPieces[i]);
  32431. longPieces[i] = regexEscape(longPieces[i]);
  32432. mixedPieces[i] = regexEscape(mixedPieces[i]);
  32433. }
  32434. this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
  32435. this._monthsShortRegex = this._monthsRegex;
  32436. this._monthsStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
  32437. this._monthsShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
  32438. }
  32439. function checkOverflow (m) {
  32440. var overflow;
  32441. var a = m._a;
  32442. if (a && getParsingFlags(m).overflow === -2) {
  32443. overflow =
  32444. a[MONTH] < 0 || a[MONTH] > 11 ? MONTH :
  32445. a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH]) ? DATE :
  32446. a[HOUR] < 0 || a[HOUR] > 24 || (a[HOUR] === 24 && (a[MINUTE] !== 0 || a[SECOND] !== 0 || a[MILLISECOND] !== 0)) ? HOUR :
  32447. a[MINUTE] < 0 || a[MINUTE] > 59 ? MINUTE :
  32448. a[SECOND] < 0 || a[SECOND] > 59 ? SECOND :
  32449. a[MILLISECOND] < 0 || a[MILLISECOND] > 999 ? MILLISECOND :
  32450. -1;
  32451. if (getParsingFlags(m)._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
  32452. overflow = DATE;
  32453. }
  32454. if (getParsingFlags(m)._overflowWeeks && overflow === -1) {
  32455. overflow = WEEK;
  32456. }
  32457. if (getParsingFlags(m)._overflowWeekday && overflow === -1) {
  32458. overflow = WEEKDAY;
  32459. }
  32460. getParsingFlags(m).overflow = overflow;
  32461. }
  32462. return m;
  32463. }
  32464. // iso 8601 regex
  32465. // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00)
  32466. var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/;
  32467. var basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/;
  32468. var tzRegex = /Z|[+-]\d\d(?::?\d\d)?/;
  32469. var isoDates = [
  32470. ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
  32471. ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
  32472. ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
  32473. ['GGGG-[W]WW', /\d{4}-W\d\d/, false],
  32474. ['YYYY-DDD', /\d{4}-\d{3}/],
  32475. ['YYYY-MM', /\d{4}-\d\d/, false],
  32476. ['YYYYYYMMDD', /[+-]\d{10}/],
  32477. ['YYYYMMDD', /\d{8}/],
  32478. // YYYYMM is NOT allowed by the standard
  32479. ['GGGG[W]WWE', /\d{4}W\d{3}/],
  32480. ['GGGG[W]WW', /\d{4}W\d{2}/, false],
  32481. ['YYYYDDD', /\d{7}/]
  32482. ];
  32483. // iso time formats and regexes
  32484. var isoTimes = [
  32485. ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
  32486. ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
  32487. ['HH:mm:ss', /\d\d:\d\d:\d\d/],
  32488. ['HH:mm', /\d\d:\d\d/],
  32489. ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
  32490. ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
  32491. ['HHmmss', /\d\d\d\d\d\d/],
  32492. ['HHmm', /\d\d\d\d/],
  32493. ['HH', /\d\d/]
  32494. ];
  32495. var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i;
  32496. // date from iso format
  32497. function configFromISO(config) {
  32498. var i, l,
  32499. string = config._i,
  32500. match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string),
  32501. allowTime, dateFormat, timeFormat, tzFormat;
  32502. if (match) {
  32503. getParsingFlags(config).iso = true;
  32504. for (i = 0, l = isoDates.length; i < l; i++) {
  32505. if (isoDates[i][1].exec(match[1])) {
  32506. dateFormat = isoDates[i][0];
  32507. allowTime = isoDates[i][2] !== false;
  32508. break;
  32509. }
  32510. }
  32511. if (dateFormat == null) {
  32512. config._isValid = false;
  32513. return;
  32514. }
  32515. if (match[3]) {
  32516. for (i = 0, l = isoTimes.length; i < l; i++) {
  32517. if (isoTimes[i][1].exec(match[3])) {
  32518. // match[2] should be 'T' or space
  32519. timeFormat = (match[2] || ' ') + isoTimes[i][0];
  32520. break;
  32521. }
  32522. }
  32523. if (timeFormat == null) {
  32524. config._isValid = false;
  32525. return;
  32526. }
  32527. }
  32528. if (!allowTime && timeFormat != null) {
  32529. config._isValid = false;
  32530. return;
  32531. }
  32532. if (match[4]) {
  32533. if (tzRegex.exec(match[4])) {
  32534. tzFormat = 'Z';
  32535. } else {
  32536. config._isValid = false;
  32537. return;
  32538. }
  32539. }
  32540. config._f = dateFormat + (timeFormat || '') + (tzFormat || '');
  32541. configFromStringAndFormat(config);
  32542. } else {
  32543. config._isValid = false;
  32544. }
  32545. }
  32546. // date from iso format or fallback
  32547. function configFromString(config) {
  32548. var matched = aspNetJsonRegex.exec(config._i);
  32549. if (matched !== null) {
  32550. config._d = new Date(+matched[1]);
  32551. return;
  32552. }
  32553. configFromISO(config);
  32554. if (config._isValid === false) {
  32555. delete config._isValid;
  32556. utils_hooks__hooks.createFromInputFallback(config);
  32557. }
  32558. }
  32559. utils_hooks__hooks.createFromInputFallback = deprecate(
  32560. 'moment construction falls back to js Date. This is ' +
  32561. 'discouraged and will be removed in upcoming major ' +
  32562. 'release. Please refer to ' +
  32563. 'https://github.com/moment/moment/issues/1407 for more info.',
  32564. function (config) {
  32565. config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
  32566. }
  32567. );
  32568. function createDate (y, m, d, h, M, s, ms) {
  32569. //can't just apply() to create a date:
  32570. //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply
  32571. var date = new Date(y, m, d, h, M, s, ms);
  32572. //the date constructor remaps years 0-99 to 1900-1999
  32573. if (y < 100 && y >= 0 && isFinite(date.getFullYear())) {
  32574. date.setFullYear(y);
  32575. }
  32576. return date;
  32577. }
  32578. function createUTCDate (y) {
  32579. var date = new Date(Date.UTC.apply(null, arguments));
  32580. //the Date.UTC function remaps years 0-99 to 1900-1999
  32581. if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) {
  32582. date.setUTCFullYear(y);
  32583. }
  32584. return date;
  32585. }
  32586. // FORMATTING
  32587. addFormatToken('Y', 0, 0, function () {
  32588. var y = this.year();
  32589. return y <= 9999 ? '' + y : '+' + y;
  32590. });
  32591. addFormatToken(0, ['YY', 2], 0, function () {
  32592. return this.year() % 100;
  32593. });
  32594. addFormatToken(0, ['YYYY', 4], 0, 'year');
  32595. addFormatToken(0, ['YYYYY', 5], 0, 'year');
  32596. addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
  32597. // ALIASES
  32598. addUnitAlias('year', 'y');
  32599. // PARSING
  32600. addRegexToken('Y', matchSigned);
  32601. addRegexToken('YY', match1to2, match2);
  32602. addRegexToken('YYYY', match1to4, match4);
  32603. addRegexToken('YYYYY', match1to6, match6);
  32604. addRegexToken('YYYYYY', match1to6, match6);
  32605. addParseToken(['YYYYY', 'YYYYYY'], YEAR);
  32606. addParseToken('YYYY', function (input, array) {
  32607. array[YEAR] = input.length === 2 ? utils_hooks__hooks.parseTwoDigitYear(input) : toInt(input);
  32608. });
  32609. addParseToken('YY', function (input, array) {
  32610. array[YEAR] = utils_hooks__hooks.parseTwoDigitYear(input);
  32611. });
  32612. addParseToken('Y', function (input, array) {
  32613. array[YEAR] = parseInt(input, 10);
  32614. });
  32615. // HELPERS
  32616. function daysInYear(year) {
  32617. return isLeapYear(year) ? 366 : 365;
  32618. }
  32619. function isLeapYear(year) {
  32620. return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
  32621. }
  32622. // HOOKS
  32623. utils_hooks__hooks.parseTwoDigitYear = function (input) {
  32624. return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
  32625. };
  32626. // MOMENTS
  32627. var getSetYear = makeGetSet('FullYear', true);
  32628. function getIsLeapYear () {
  32629. return isLeapYear(this.year());
  32630. }
  32631. // start-of-first-week - start-of-year
  32632. function firstWeekOffset(year, dow, doy) {
  32633. var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
  32634. fwd = 7 + dow - doy,
  32635. // first-week day local weekday -- which local weekday is fwd
  32636. fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7;
  32637. return -fwdlw + fwd - 1;
  32638. }
  32639. //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
  32640. function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
  32641. var localWeekday = (7 + weekday - dow) % 7,
  32642. weekOffset = firstWeekOffset(year, dow, doy),
  32643. dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset,
  32644. resYear, resDayOfYear;
  32645. if (dayOfYear <= 0) {
  32646. resYear = year - 1;
  32647. resDayOfYear = daysInYear(resYear) + dayOfYear;
  32648. } else if (dayOfYear > daysInYear(year)) {
  32649. resYear = year + 1;
  32650. resDayOfYear = dayOfYear - daysInYear(year);
  32651. } else {
  32652. resYear = year;
  32653. resDayOfYear = dayOfYear;
  32654. }
  32655. return {
  32656. year: resYear,
  32657. dayOfYear: resDayOfYear
  32658. };
  32659. }
  32660. function weekOfYear(mom, dow, doy) {
  32661. var weekOffset = firstWeekOffset(mom.year(), dow, doy),
  32662. week = Math.floor((mom.dayOfYear() - weekOffset - 1) / 7) + 1,
  32663. resWeek, resYear;
  32664. if (week < 1) {
  32665. resYear = mom.year() - 1;
  32666. resWeek = week + weeksInYear(resYear, dow, doy);
  32667. } else if (week > weeksInYear(mom.year(), dow, doy)) {
  32668. resWeek = week - weeksInYear(mom.year(), dow, doy);
  32669. resYear = mom.year() + 1;
  32670. } else {
  32671. resYear = mom.year();
  32672. resWeek = week;
  32673. }
  32674. return {
  32675. week: resWeek,
  32676. year: resYear
  32677. };
  32678. }
  32679. function weeksInYear(year, dow, doy) {
  32680. var weekOffset = firstWeekOffset(year, dow, doy),
  32681. weekOffsetNext = firstWeekOffset(year + 1, dow, doy);
  32682. return (daysInYear(year) - weekOffset + weekOffsetNext) / 7;
  32683. }
  32684. // Pick the first defined of two or three arguments.
  32685. function defaults(a, b, c) {
  32686. if (a != null) {
  32687. return a;
  32688. }
  32689. if (b != null) {
  32690. return b;
  32691. }
  32692. return c;
  32693. }
  32694. function currentDateArray(config) {
  32695. // hooks is actually the exported moment object
  32696. var nowValue = new Date(utils_hooks__hooks.now());
  32697. if (config._useUTC) {
  32698. return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()];
  32699. }
  32700. return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
  32701. }
  32702. // convert an array to a date.
  32703. // the array should mirror the parameters below
  32704. // note: all values past the year are optional and will default to the lowest possible value.
  32705. // [year, month, day , hour, minute, second, millisecond]
  32706. function configFromArray (config) {
  32707. var i, date, input = [], currentDate, yearToUse;
  32708. if (config._d) {
  32709. return;
  32710. }
  32711. currentDate = currentDateArray(config);
  32712. //compute day of the year from weeks and weekdays
  32713. if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
  32714. dayOfYearFromWeekInfo(config);
  32715. }
  32716. //if the day of the year is set, figure out what it is
  32717. if (config._dayOfYear) {
  32718. yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
  32719. if (config._dayOfYear > daysInYear(yearToUse)) {
  32720. getParsingFlags(config)._overflowDayOfYear = true;
  32721. }
  32722. date = createUTCDate(yearToUse, 0, config._dayOfYear);
  32723. config._a[MONTH] = date.getUTCMonth();
  32724. config._a[DATE] = date.getUTCDate();
  32725. }
  32726. // Default to current date.
  32727. // * if no year, month, day of month are given, default to today
  32728. // * if day of month is given, default month and year
  32729. // * if month is given, default only year
  32730. // * if year is given, don't default anything
  32731. for (i = 0; i < 3 && config._a[i] == null; ++i) {
  32732. config._a[i] = input[i] = currentDate[i];
  32733. }
  32734. // Zero out whatever was not defaulted, including time
  32735. for (; i < 7; i++) {
  32736. config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
  32737. }
  32738. // Check for 24:00:00.000
  32739. if (config._a[HOUR] === 24 &&
  32740. config._a[MINUTE] === 0 &&
  32741. config._a[SECOND] === 0 &&
  32742. config._a[MILLISECOND] === 0) {
  32743. config._nextDay = true;
  32744. config._a[HOUR] = 0;
  32745. }
  32746. config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input);
  32747. // Apply timezone offset from input. The actual utcOffset can be changed
  32748. // with parseZone.
  32749. if (config._tzm != null) {
  32750. config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
  32751. }
  32752. if (config._nextDay) {
  32753. config._a[HOUR] = 24;
  32754. }
  32755. }
  32756. function dayOfYearFromWeekInfo(config) {
  32757. var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow;
  32758. w = config._w;
  32759. if (w.GG != null || w.W != null || w.E != null) {
  32760. dow = 1;
  32761. doy = 4;
  32762. // TODO: We need to take the current isoWeekYear, but that depends on
  32763. // how we interpret now (local, utc, fixed offset). So create
  32764. // a now version of current config (take local/utc/offset flags, and
  32765. // create now).
  32766. weekYear = defaults(w.GG, config._a[YEAR], weekOfYear(local__createLocal(), 1, 4).year);
  32767. week = defaults(w.W, 1);
  32768. weekday = defaults(w.E, 1);
  32769. if (weekday < 1 || weekday > 7) {
  32770. weekdayOverflow = true;
  32771. }
  32772. } else {
  32773. dow = config._locale._week.dow;
  32774. doy = config._locale._week.doy;
  32775. weekYear = defaults(w.gg, config._a[YEAR], weekOfYear(local__createLocal(), dow, doy).year);
  32776. week = defaults(w.w, 1);
  32777. if (w.d != null) {
  32778. // weekday -- low day numbers are considered next week
  32779. weekday = w.d;
  32780. if (weekday < 0 || weekday > 6) {
  32781. weekdayOverflow = true;
  32782. }
  32783. } else if (w.e != null) {
  32784. // local weekday -- counting starts from begining of week
  32785. weekday = w.e + dow;
  32786. if (w.e < 0 || w.e > 6) {
  32787. weekdayOverflow = true;
  32788. }
  32789. } else {
  32790. // default to begining of week
  32791. weekday = dow;
  32792. }
  32793. }
  32794. if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
  32795. getParsingFlags(config)._overflowWeeks = true;
  32796. } else if (weekdayOverflow != null) {
  32797. getParsingFlags(config)._overflowWeekday = true;
  32798. } else {
  32799. temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
  32800. config._a[YEAR] = temp.year;
  32801. config._dayOfYear = temp.dayOfYear;
  32802. }
  32803. }
  32804. // constant that refers to the ISO standard
  32805. utils_hooks__hooks.ISO_8601 = function () {};
  32806. // date from string and format string
  32807. function configFromStringAndFormat(config) {
  32808. // TODO: Move this to another part of the creation flow to prevent circular deps
  32809. if (config._f === utils_hooks__hooks.ISO_8601) {
  32810. configFromISO(config);
  32811. return;
  32812. }
  32813. config._a = [];
  32814. getParsingFlags(config).empty = true;
  32815. // This array is used to make a Date, either with `new Date` or `Date.UTC`
  32816. var string = '' + config._i,
  32817. i, parsedInput, tokens, token, skipped,
  32818. stringLength = string.length,
  32819. totalParsedInputLength = 0;
  32820. tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];
  32821. for (i = 0; i < tokens.length; i++) {
  32822. token = tokens[i];
  32823. parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
  32824. // console.log('token', token, 'parsedInput', parsedInput,
  32825. // 'regex', getParseRegexForToken(token, config));
  32826. if (parsedInput) {
  32827. skipped = string.substr(0, string.indexOf(parsedInput));
  32828. if (skipped.length > 0) {
  32829. getParsingFlags(config).unusedInput.push(skipped);
  32830. }
  32831. string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
  32832. totalParsedInputLength += parsedInput.length;
  32833. }
  32834. // don't parse if it's not a known token
  32835. if (formatTokenFunctions[token]) {
  32836. if (parsedInput) {
  32837. getParsingFlags(config).empty = false;
  32838. }
  32839. else {
  32840. getParsingFlags(config).unusedTokens.push(token);
  32841. }
  32842. addTimeToArrayFromToken(token, parsedInput, config);
  32843. }
  32844. else if (config._strict && !parsedInput) {
  32845. getParsingFlags(config).unusedTokens.push(token);
  32846. }
  32847. }
  32848. // add remaining unparsed input length to the string
  32849. getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength;
  32850. if (string.length > 0) {
  32851. getParsingFlags(config).unusedInput.push(string);
  32852. }
  32853. // clear _12h flag if hour is <= 12
  32854. if (getParsingFlags(config).bigHour === true &&
  32855. config._a[HOUR] <= 12 &&
  32856. config._a[HOUR] > 0) {
  32857. getParsingFlags(config).bigHour = undefined;
  32858. }
  32859. getParsingFlags(config).parsedDateParts = config._a.slice(0);
  32860. getParsingFlags(config).meridiem = config._meridiem;
  32861. // handle meridiem
  32862. config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR], config._meridiem);
  32863. configFromArray(config);
  32864. checkOverflow(config);
  32865. }
  32866. function meridiemFixWrap (locale, hour, meridiem) {
  32867. var isPm;
  32868. if (meridiem == null) {
  32869. // nothing to do
  32870. return hour;
  32871. }
  32872. if (locale.meridiemHour != null) {
  32873. return locale.meridiemHour(hour, meridiem);
  32874. } else if (locale.isPM != null) {
  32875. // Fallback
  32876. isPm = locale.isPM(meridiem);
  32877. if (isPm && hour < 12) {
  32878. hour += 12;
  32879. }
  32880. if (!isPm && hour === 12) {
  32881. hour = 0;
  32882. }
  32883. return hour;
  32884. } else {
  32885. // this is not supposed to happen
  32886. return hour;
  32887. }
  32888. }
  32889. // date from string and array of format strings
  32890. function configFromStringAndArray(config) {
  32891. var tempConfig,
  32892. bestMoment,
  32893. scoreToBeat,
  32894. i,
  32895. currentScore;
  32896. if (config._f.length === 0) {
  32897. getParsingFlags(config).invalidFormat = true;
  32898. config._d = new Date(NaN);
  32899. return;
  32900. }
  32901. for (i = 0; i < config._f.length; i++) {
  32902. currentScore = 0;
  32903. tempConfig = copyConfig({}, config);
  32904. if (config._useUTC != null) {
  32905. tempConfig._useUTC = config._useUTC;
  32906. }
  32907. tempConfig._f = config._f[i];
  32908. configFromStringAndFormat(tempConfig);
  32909. if (!valid__isValid(tempConfig)) {
  32910. continue;
  32911. }
  32912. // if there is any input that was not parsed add a penalty for that format
  32913. currentScore += getParsingFlags(tempConfig).charsLeftOver;
  32914. //or tokens
  32915. currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
  32916. getParsingFlags(tempConfig).score = currentScore;
  32917. if (scoreToBeat == null || currentScore < scoreToBeat) {
  32918. scoreToBeat = currentScore;
  32919. bestMoment = tempConfig;
  32920. }
  32921. }
  32922. extend(config, bestMoment || tempConfig);
  32923. }
  32924. function configFromObject(config) {
  32925. if (config._d) {
  32926. return;
  32927. }
  32928. var i = normalizeObjectUnits(config._i);
  32929. config._a = map([i.year, i.month, i.day || i.date, i.hour, i.minute, i.second, i.millisecond], function (obj) {
  32930. return obj && parseInt(obj, 10);
  32931. });
  32932. configFromArray(config);
  32933. }
  32934. function createFromConfig (config) {
  32935. var res = new Moment(checkOverflow(prepareConfig(config)));
  32936. if (res._nextDay) {
  32937. // Adding is smart enough around DST
  32938. res.add(1, 'd');
  32939. res._nextDay = undefined;
  32940. }
  32941. return res;
  32942. }
  32943. function prepareConfig (config) {
  32944. var input = config._i,
  32945. format = config._f;
  32946. config._locale = config._locale || locale_locales__getLocale(config._l);
  32947. if (input === null || (format === undefined && input === '')) {
  32948. return valid__createInvalid({nullInput: true});
  32949. }
  32950. if (typeof input === 'string') {
  32951. config._i = input = config._locale.preparse(input);
  32952. }
  32953. if (isMoment(input)) {
  32954. return new Moment(checkOverflow(input));
  32955. } else if (isArray(format)) {
  32956. configFromStringAndArray(config);
  32957. } else if (format) {
  32958. configFromStringAndFormat(config);
  32959. } else if (isDate(input)) {
  32960. config._d = input;
  32961. } else {
  32962. configFromInput(config);
  32963. }
  32964. if (!valid__isValid(config)) {
  32965. config._d = null;
  32966. }
  32967. return config;
  32968. }
  32969. function configFromInput(config) {
  32970. var input = config._i;
  32971. if (input === undefined) {
  32972. config._d = new Date(utils_hooks__hooks.now());
  32973. } else if (isDate(input)) {
  32974. config._d = new Date(input.valueOf());
  32975. } else if (typeof input === 'string') {
  32976. configFromString(config);
  32977. } else if (isArray(input)) {
  32978. config._a = map(input.slice(0), function (obj) {
  32979. return parseInt(obj, 10);
  32980. });
  32981. configFromArray(config);
  32982. } else if (typeof(input) === 'object') {
  32983. configFromObject(config);
  32984. } else if (typeof(input) === 'number') {
  32985. // from milliseconds
  32986. config._d = new Date(input);
  32987. } else {
  32988. utils_hooks__hooks.createFromInputFallback(config);
  32989. }
  32990. }
  32991. function createLocalOrUTC (input, format, locale, strict, isUTC) {
  32992. var c = {};
  32993. if (typeof(locale) === 'boolean') {
  32994. strict = locale;
  32995. locale = undefined;
  32996. }
  32997. // object construction must be done this way.
  32998. // https://github.com/moment/moment/issues/1423
  32999. c._isAMomentObject = true;
  33000. c._useUTC = c._isUTC = isUTC;
  33001. c._l = locale;
  33002. c._i = input;
  33003. c._f = format;
  33004. c._strict = strict;
  33005. return createFromConfig(c);
  33006. }
  33007. function local__createLocal (input, format, locale, strict) {
  33008. return createLocalOrUTC(input, format, locale, strict, false);
  33009. }
  33010. var prototypeMin = deprecate(
  33011. 'moment().min is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548',
  33012. function () {
  33013. var other = local__createLocal.apply(null, arguments);
  33014. if (this.isValid() && other.isValid()) {
  33015. return other < this ? this : other;
  33016. } else {
  33017. return valid__createInvalid();
  33018. }
  33019. }
  33020. );
  33021. var prototypeMax = deprecate(
  33022. 'moment().max is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548',
  33023. function () {
  33024. var other = local__createLocal.apply(null, arguments);
  33025. if (this.isValid() && other.isValid()) {
  33026. return other > this ? this : other;
  33027. } else {
  33028. return valid__createInvalid();
  33029. }
  33030. }
  33031. );
  33032. // Pick a moment m from moments so that m[fn](other) is true for all
  33033. // other. This relies on the function fn to be transitive.
  33034. //
  33035. // moments should either be an array of moment objects or an array, whose
  33036. // first element is an array of moment objects.
  33037. function pickBy(fn, moments) {
  33038. var res, i;
  33039. if (moments.length === 1 && isArray(moments[0])) {
  33040. moments = moments[0];
  33041. }
  33042. if (!moments.length) {
  33043. return local__createLocal();
  33044. }
  33045. res = moments[0];
  33046. for (i = 1; i < moments.length; ++i) {
  33047. if (!moments[i].isValid() || moments[i][fn](res)) {
  33048. res = moments[i];
  33049. }
  33050. }
  33051. return res;
  33052. }
  33053. // TODO: Use [].sort instead?
  33054. function min () {
  33055. var args = [].slice.call(arguments, 0);
  33056. return pickBy('isBefore', args);
  33057. }
  33058. function max () {
  33059. var args = [].slice.call(arguments, 0);
  33060. return pickBy('isAfter', args);
  33061. }
  33062. var now = function () {
  33063. return Date.now ? Date.now() : +(new Date());
  33064. };
  33065. function Duration (duration) {
  33066. var normalizedInput = normalizeObjectUnits(duration),
  33067. years = normalizedInput.year || 0,
  33068. quarters = normalizedInput.quarter || 0,
  33069. months = normalizedInput.month || 0,
  33070. weeks = normalizedInput.week || 0,
  33071. days = normalizedInput.day || 0,
  33072. hours = normalizedInput.hour || 0,
  33073. minutes = normalizedInput.minute || 0,
  33074. seconds = normalizedInput.second || 0,
  33075. milliseconds = normalizedInput.millisecond || 0;
  33076. // representation for dateAddRemove
  33077. this._milliseconds = +milliseconds +
  33078. seconds * 1e3 + // 1000
  33079. minutes * 6e4 + // 1000 * 60
  33080. hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
  33081. // Because of dateAddRemove treats 24 hours as different from a
  33082. // day when working around DST, we need to store them separately
  33083. this._days = +days +
  33084. weeks * 7;
  33085. // It is impossible translate months into days without knowing
  33086. // which months you are are talking about, so we have to store
  33087. // it separately.
  33088. this._months = +months +
  33089. quarters * 3 +
  33090. years * 12;
  33091. this._data = {};
  33092. this._locale = locale_locales__getLocale();
  33093. this._bubble();
  33094. }
  33095. function isDuration (obj) {
  33096. return obj instanceof Duration;
  33097. }
  33098. // FORMATTING
  33099. function offset (token, separator) {
  33100. addFormatToken(token, 0, 0, function () {
  33101. var offset = this.utcOffset();
  33102. var sign = '+';
  33103. if (offset < 0) {
  33104. offset = -offset;
  33105. sign = '-';
  33106. }
  33107. return sign + zeroFill(~~(offset / 60), 2) + separator + zeroFill(~~(offset) % 60, 2);
  33108. });
  33109. }
  33110. offset('Z', ':');
  33111. offset('ZZ', '');
  33112. // PARSING
  33113. addRegexToken('Z', matchShortOffset);
  33114. addRegexToken('ZZ', matchShortOffset);
  33115. addParseToken(['Z', 'ZZ'], function (input, array, config) {
  33116. config._useUTC = true;
  33117. config._tzm = offsetFromString(matchShortOffset, input);
  33118. });
  33119. // HELPERS
  33120. // timezone chunker
  33121. // '+10:00' > ['10', '00']
  33122. // '-1530' > ['-15', '30']
  33123. var chunkOffset = /([\+\-]|\d\d)/gi;
  33124. function offsetFromString(matcher, string) {
  33125. var matches = ((string || '').match(matcher) || []);
  33126. var chunk = matches[matches.length - 1] || [];
  33127. var parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];
  33128. var minutes = +(parts[1] * 60) + toInt(parts[2]);
  33129. return parts[0] === '+' ? minutes : -minutes;
  33130. }
  33131. // Return a moment from input, that is local/utc/zone equivalent to model.
  33132. function cloneWithOffset(input, model) {
  33133. var res, diff;
  33134. if (model._isUTC) {
  33135. res = model.clone();
  33136. diff = (isMoment(input) || isDate(input) ? input.valueOf() : local__createLocal(input).valueOf()) - res.valueOf();
  33137. // Use low-level api, because this fn is low-level api.
  33138. res._d.setTime(res._d.valueOf() + diff);
  33139. utils_hooks__hooks.updateOffset(res, false);
  33140. return res;
  33141. } else {
  33142. return local__createLocal(input).local();
  33143. }
  33144. }
  33145. function getDateOffset (m) {
  33146. // On Firefox.24 Date#getTimezoneOffset returns a floating point.
  33147. // https://github.com/moment/moment/pull/1871
  33148. return -Math.round(m._d.getTimezoneOffset() / 15) * 15;
  33149. }
  33150. // HOOKS
  33151. // This function will be called whenever a moment is mutated.
  33152. // It is intended to keep the offset in sync with the timezone.
  33153. utils_hooks__hooks.updateOffset = function () {};
  33154. // MOMENTS
  33155. // keepLocalTime = true means only change the timezone, without
  33156. // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
  33157. // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
  33158. // +0200, so we adjust the time as needed, to be valid.
  33159. //
  33160. // Keeping the time actually adds/subtracts (one hour)
  33161. // from the actual represented time. That is why we call updateOffset
  33162. // a second time. In case it wants us to change the offset again
  33163. // _changeInProgress == true case, then we have to adjust, because
  33164. // there is no such time in the given timezone.
  33165. function getSetOffset (input, keepLocalTime) {
  33166. var offset = this._offset || 0,
  33167. localAdjust;
  33168. if (!this.isValid()) {
  33169. return input != null ? this : NaN;
  33170. }
  33171. if (input != null) {
  33172. if (typeof input === 'string') {
  33173. input = offsetFromString(matchShortOffset, input);
  33174. } else if (Math.abs(input) < 16) {
  33175. input = input * 60;
  33176. }
  33177. if (!this._isUTC && keepLocalTime) {
  33178. localAdjust = getDateOffset(this);
  33179. }
  33180. this._offset = input;
  33181. this._isUTC = true;
  33182. if (localAdjust != null) {
  33183. this.add(localAdjust, 'm');
  33184. }
  33185. if (offset !== input) {
  33186. if (!keepLocalTime || this._changeInProgress) {
  33187. add_subtract__addSubtract(this, create__createDuration(input - offset, 'm'), 1, false);
  33188. } else if (!this._changeInProgress) {
  33189. this._changeInProgress = true;
  33190. utils_hooks__hooks.updateOffset(this, true);
  33191. this._changeInProgress = null;
  33192. }
  33193. }
  33194. return this;
  33195. } else {
  33196. return this._isUTC ? offset : getDateOffset(this);
  33197. }
  33198. }
  33199. function getSetZone (input, keepLocalTime) {
  33200. if (input != null) {
  33201. if (typeof input !== 'string') {
  33202. input = -input;
  33203. }
  33204. this.utcOffset(input, keepLocalTime);
  33205. return this;
  33206. } else {
  33207. return -this.utcOffset();
  33208. }
  33209. }
  33210. function setOffsetToUTC (keepLocalTime) {
  33211. return this.utcOffset(0, keepLocalTime);
  33212. }
  33213. function setOffsetToLocal (keepLocalTime) {
  33214. if (this._isUTC) {
  33215. this.utcOffset(0, keepLocalTime);
  33216. this._isUTC = false;
  33217. if (keepLocalTime) {
  33218. this.subtract(getDateOffset(this), 'm');
  33219. }
  33220. }
  33221. return this;
  33222. }
  33223. function setOffsetToParsedOffset () {
  33224. if (this._tzm) {
  33225. this.utcOffset(this._tzm);
  33226. } else if (typeof this._i === 'string') {
  33227. this.utcOffset(offsetFromString(matchOffset, this._i));
  33228. }
  33229. return this;
  33230. }
  33231. function hasAlignedHourOffset (input) {
  33232. if (!this.isValid()) {
  33233. return false;
  33234. }
  33235. input = input ? local__createLocal(input).utcOffset() : 0;
  33236. return (this.utcOffset() - input) % 60 === 0;
  33237. }
  33238. function isDaylightSavingTime () {
  33239. return (
  33240. this.utcOffset() > this.clone().month(0).utcOffset() ||
  33241. this.utcOffset() > this.clone().month(5).utcOffset()
  33242. );
  33243. }
  33244. function isDaylightSavingTimeShifted () {
  33245. if (!isUndefined(this._isDSTShifted)) {
  33246. return this._isDSTShifted;
  33247. }
  33248. var c = {};
  33249. copyConfig(c, this);
  33250. c = prepareConfig(c);
  33251. if (c._a) {
  33252. var other = c._isUTC ? create_utc__createUTC(c._a) : local__createLocal(c._a);
  33253. this._isDSTShifted = this.isValid() &&
  33254. compareArrays(c._a, other.toArray()) > 0;
  33255. } else {
  33256. this._isDSTShifted = false;
  33257. }
  33258. return this._isDSTShifted;
  33259. }
  33260. function isLocal () {
  33261. return this.isValid() ? !this._isUTC : false;
  33262. }
  33263. function isUtcOffset () {
  33264. return this.isValid() ? this._isUTC : false;
  33265. }
  33266. function isUtc () {
  33267. return this.isValid() ? this._isUTC && this._offset === 0 : false;
  33268. }
  33269. // ASP.NET json date format regex
  33270. var aspNetRegex = /^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?\d*)?$/;
  33271. // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
  33272. // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
  33273. // and further modified to allow for strings containing both week and day
  33274. var isoRegex = /^(-)?P(?:(-?[0-9,.]*)Y)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)W)?(?:(-?[0-9,.]*)D)?(?:T(?:(-?[0-9,.]*)H)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)S)?)?$/;
  33275. function create__createDuration (input, key) {
  33276. var duration = input,
  33277. // matching against regexp is expensive, do it on demand
  33278. match = null,
  33279. sign,
  33280. ret,
  33281. diffRes;
  33282. if (isDuration(input)) {
  33283. duration = {
  33284. ms : input._milliseconds,
  33285. d : input._days,
  33286. M : input._months
  33287. };
  33288. } else if (typeof input === 'number') {
  33289. duration = {};
  33290. if (key) {
  33291. duration[key] = input;
  33292. } else {
  33293. duration.milliseconds = input;
  33294. }
  33295. } else if (!!(match = aspNetRegex.exec(input))) {
  33296. sign = (match[1] === '-') ? -1 : 1;
  33297. duration = {
  33298. y : 0,
  33299. d : toInt(match[DATE]) * sign,
  33300. h : toInt(match[HOUR]) * sign,
  33301. m : toInt(match[MINUTE]) * sign,
  33302. s : toInt(match[SECOND]) * sign,
  33303. ms : toInt(match[MILLISECOND]) * sign
  33304. };
  33305. } else if (!!(match = isoRegex.exec(input))) {
  33306. sign = (match[1] === '-') ? -1 : 1;
  33307. duration = {
  33308. y : parseIso(match[2], sign),
  33309. M : parseIso(match[3], sign),
  33310. w : parseIso(match[4], sign),
  33311. d : parseIso(match[5], sign),
  33312. h : parseIso(match[6], sign),
  33313. m : parseIso(match[7], sign),
  33314. s : parseIso(match[8], sign)
  33315. };
  33316. } else if (duration == null) {// checks for null or undefined
  33317. duration = {};
  33318. } else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) {
  33319. diffRes = momentsDifference(local__createLocal(duration.from), local__createLocal(duration.to));
  33320. duration = {};
  33321. duration.ms = diffRes.milliseconds;
  33322. duration.M = diffRes.months;
  33323. }
  33324. ret = new Duration(duration);
  33325. if (isDuration(input) && hasOwnProp(input, '_locale')) {
  33326. ret._locale = input._locale;
  33327. }
  33328. return ret;
  33329. }
  33330. create__createDuration.fn = Duration.prototype;
  33331. function parseIso (inp, sign) {
  33332. // We'd normally use ~~inp for this, but unfortunately it also
  33333. // converts floats to ints.
  33334. // inp may be undefined, so careful calling replace on it.
  33335. var res = inp && parseFloat(inp.replace(',', '.'));
  33336. // apply sign while we're at it
  33337. return (isNaN(res) ? 0 : res) * sign;
  33338. }
  33339. function positiveMomentsDifference(base, other) {
  33340. var res = {milliseconds: 0, months: 0};
  33341. res.months = other.month() - base.month() +
  33342. (other.year() - base.year()) * 12;
  33343. if (base.clone().add(res.months, 'M').isAfter(other)) {
  33344. --res.months;
  33345. }
  33346. res.milliseconds = +other - +(base.clone().add(res.months, 'M'));
  33347. return res;
  33348. }
  33349. function momentsDifference(base, other) {
  33350. var res;
  33351. if (!(base.isValid() && other.isValid())) {
  33352. return {milliseconds: 0, months: 0};
  33353. }
  33354. other = cloneWithOffset(other, base);
  33355. if (base.isBefore(other)) {
  33356. res = positiveMomentsDifference(base, other);
  33357. } else {
  33358. res = positiveMomentsDifference(other, base);
  33359. res.milliseconds = -res.milliseconds;
  33360. res.months = -res.months;
  33361. }
  33362. return res;
  33363. }
  33364. function absRound (number) {
  33365. if (number < 0) {
  33366. return Math.round(-1 * number) * -1;
  33367. } else {
  33368. return Math.round(number);
  33369. }
  33370. }
  33371. // TODO: remove 'name' arg after deprecation is removed
  33372. function createAdder(direction, name) {
  33373. return function (val, period) {
  33374. var dur, tmp;
  33375. //invert the arguments, but complain about it
  33376. if (period !== null && !isNaN(+period)) {
  33377. deprecateSimple(name, 'moment().' + name + '(period, number) is deprecated. Please use moment().' + name + '(number, period).');
  33378. tmp = val; val = period; period = tmp;
  33379. }
  33380. val = typeof val === 'string' ? +val : val;
  33381. dur = create__createDuration(val, period);
  33382. add_subtract__addSubtract(this, dur, direction);
  33383. return this;
  33384. };
  33385. }
  33386. function add_subtract__addSubtract (mom, duration, isAdding, updateOffset) {
  33387. var milliseconds = duration._milliseconds,
  33388. days = absRound(duration._days),
  33389. months = absRound(duration._months);
  33390. if (!mom.isValid()) {
  33391. // No op
  33392. return;
  33393. }
  33394. updateOffset = updateOffset == null ? true : updateOffset;
  33395. if (milliseconds) {
  33396. mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding);
  33397. }
  33398. if (days) {
  33399. get_set__set(mom, 'Date', get_set__get(mom, 'Date') + days * isAdding);
  33400. }
  33401. if (months) {
  33402. setMonth(mom, get_set__get(mom, 'Month') + months * isAdding);
  33403. }
  33404. if (updateOffset) {
  33405. utils_hooks__hooks.updateOffset(mom, days || months);
  33406. }
  33407. }
  33408. var add_subtract__add = createAdder(1, 'add');
  33409. var add_subtract__subtract = createAdder(-1, 'subtract');
  33410. function moment_calendar__calendar (time, formats) {
  33411. // We want to compare the start of today, vs this.
  33412. // Getting start-of-today depends on whether we're local/utc/offset or not.
  33413. var now = time || local__createLocal(),
  33414. sod = cloneWithOffset(now, this).startOf('day'),
  33415. diff = this.diff(sod, 'days', true),
  33416. format = diff < -6 ? 'sameElse' :
  33417. diff < -1 ? 'lastWeek' :
  33418. diff < 0 ? 'lastDay' :
  33419. diff < 1 ? 'sameDay' :
  33420. diff < 2 ? 'nextDay' :
  33421. diff < 7 ? 'nextWeek' : 'sameElse';
  33422. var output = formats && (isFunction(formats[format]) ? formats[format]() : formats[format]);
  33423. return this.format(output || this.localeData().calendar(format, this, local__createLocal(now)));
  33424. }
  33425. function clone () {
  33426. return new Moment(this);
  33427. }
  33428. function isAfter (input, units) {
  33429. var localInput = isMoment(input) ? input : local__createLocal(input);
  33430. if (!(this.isValid() && localInput.isValid())) {
  33431. return false;
  33432. }
  33433. units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
  33434. if (units === 'millisecond') {
  33435. return this.valueOf() > localInput.valueOf();
  33436. } else {
  33437. return localInput.valueOf() < this.clone().startOf(units).valueOf();
  33438. }
  33439. }
  33440. function isBefore (input, units) {
  33441. var localInput = isMoment(input) ? input : local__createLocal(input);
  33442. if (!(this.isValid() && localInput.isValid())) {
  33443. return false;
  33444. }
  33445. units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
  33446. if (units === 'millisecond') {
  33447. return this.valueOf() < localInput.valueOf();
  33448. } else {
  33449. return this.clone().endOf(units).valueOf() < localInput.valueOf();
  33450. }
  33451. }
  33452. function isBetween (from, to, units, inclusivity) {
  33453. inclusivity = inclusivity || '()';
  33454. return (inclusivity[0] === '(' ? this.isAfter(from, units) : !this.isBefore(from, units)) &&
  33455. (inclusivity[1] === ')' ? this.isBefore(to, units) : !this.isAfter(to, units));
  33456. }
  33457. function isSame (input, units) {
  33458. var localInput = isMoment(input) ? input : local__createLocal(input),
  33459. inputMs;
  33460. if (!(this.isValid() && localInput.isValid())) {
  33461. return false;
  33462. }
  33463. units = normalizeUnits(units || 'millisecond');
  33464. if (units === 'millisecond') {
  33465. return this.valueOf() === localInput.valueOf();
  33466. } else {
  33467. inputMs = localInput.valueOf();
  33468. return this.clone().startOf(units).valueOf() <= inputMs && inputMs <= this.clone().endOf(units).valueOf();
  33469. }
  33470. }
  33471. function isSameOrAfter (input, units) {
  33472. return this.isSame(input, units) || this.isAfter(input,units);
  33473. }
  33474. function isSameOrBefore (input, units) {
  33475. return this.isSame(input, units) || this.isBefore(input,units);
  33476. }
  33477. function diff (input, units, asFloat) {
  33478. var that,
  33479. zoneDelta,
  33480. delta, output;
  33481. if (!this.isValid()) {
  33482. return NaN;
  33483. }
  33484. that = cloneWithOffset(input, this);
  33485. if (!that.isValid()) {
  33486. return NaN;
  33487. }
  33488. zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
  33489. units = normalizeUnits(units);
  33490. if (units === 'year' || units === 'month' || units === 'quarter') {
  33491. output = monthDiff(this, that);
  33492. if (units === 'quarter') {
  33493. output = output / 3;
  33494. } else if (units === 'year') {
  33495. output = output / 12;
  33496. }
  33497. } else {
  33498. delta = this - that;
  33499. output = units === 'second' ? delta / 1e3 : // 1000
  33500. units === 'minute' ? delta / 6e4 : // 1000 * 60
  33501. units === 'hour' ? delta / 36e5 : // 1000 * 60 * 60
  33502. units === 'day' ? (delta - zoneDelta) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
  33503. units === 'week' ? (delta - zoneDelta) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
  33504. delta;
  33505. }
  33506. return asFloat ? output : absFloor(output);
  33507. }
  33508. function monthDiff (a, b) {
  33509. // difference in months
  33510. var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()),
  33511. // b is in (anchor - 1 month, anchor + 1 month)
  33512. anchor = a.clone().add(wholeMonthDiff, 'months'),
  33513. anchor2, adjust;
  33514. if (b - anchor < 0) {
  33515. anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
  33516. // linear across the month
  33517. adjust = (b - anchor) / (anchor - anchor2);
  33518. } else {
  33519. anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
  33520. // linear across the month
  33521. adjust = (b - anchor) / (anchor2 - anchor);
  33522. }
  33523. //check for negative zero, return zero if negative zero
  33524. return -(wholeMonthDiff + adjust) || 0;
  33525. }
  33526. utils_hooks__hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
  33527. utils_hooks__hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]';
  33528. function toString () {
  33529. return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
  33530. }
  33531. function moment_format__toISOString () {
  33532. var m = this.clone().utc();
  33533. if (0 < m.year() && m.year() <= 9999) {
  33534. if (isFunction(Date.prototype.toISOString)) {
  33535. // native implementation is ~50x faster, use it when we can
  33536. return this.toDate().toISOString();
  33537. } else {
  33538. return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
  33539. }
  33540. } else {
  33541. return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
  33542. }
  33543. }
  33544. function format (inputString) {
  33545. if (!inputString) {
  33546. inputString = this.isUtc() ? utils_hooks__hooks.defaultFormatUtc : utils_hooks__hooks.defaultFormat;
  33547. }
  33548. var output = formatMoment(this, inputString);
  33549. return this.localeData().postformat(output);
  33550. }
  33551. function from (time, withoutSuffix) {
  33552. if (this.isValid() &&
  33553. ((isMoment(time) && time.isValid()) ||
  33554. local__createLocal(time).isValid())) {
  33555. return create__createDuration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);
  33556. } else {
  33557. return this.localeData().invalidDate();
  33558. }
  33559. }
  33560. function fromNow (withoutSuffix) {
  33561. return this.from(local__createLocal(), withoutSuffix);
  33562. }
  33563. function to (time, withoutSuffix) {
  33564. if (this.isValid() &&
  33565. ((isMoment(time) && time.isValid()) ||
  33566. local__createLocal(time).isValid())) {
  33567. return create__createDuration({from: this, to: time}).locale(this.locale()).humanize(!withoutSuffix);
  33568. } else {
  33569. return this.localeData().invalidDate();
  33570. }
  33571. }
  33572. function toNow (withoutSuffix) {
  33573. return this.to(local__createLocal(), withoutSuffix);
  33574. }
  33575. // If passed a locale key, it will set the locale for this
  33576. // instance. Otherwise, it will return the locale configuration
  33577. // variables for this instance.
  33578. function locale (key) {
  33579. var newLocaleData;
  33580. if (key === undefined) {
  33581. return this._locale._abbr;
  33582. } else {
  33583. newLocaleData = locale_locales__getLocale(key);
  33584. if (newLocaleData != null) {
  33585. this._locale = newLocaleData;
  33586. }
  33587. return this;
  33588. }
  33589. }
  33590. var lang = deprecate(
  33591. 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
  33592. function (key) {
  33593. if (key === undefined) {
  33594. return this.localeData();
  33595. } else {
  33596. return this.locale(key);
  33597. }
  33598. }
  33599. );
  33600. function localeData () {
  33601. return this._locale;
  33602. }
  33603. function startOf (units) {
  33604. units = normalizeUnits(units);
  33605. // the following switch intentionally omits break keywords
  33606. // to utilize falling through the cases.
  33607. switch (units) {
  33608. case 'year':
  33609. this.month(0);
  33610. /* falls through */
  33611. case 'quarter':
  33612. case 'month':
  33613. this.date(1);
  33614. /* falls through */
  33615. case 'week':
  33616. case 'isoWeek':
  33617. case 'day':
  33618. case 'date':
  33619. this.hours(0);
  33620. /* falls through */
  33621. case 'hour':
  33622. this.minutes(0);
  33623. /* falls through */
  33624. case 'minute':
  33625. this.seconds(0);
  33626. /* falls through */
  33627. case 'second':
  33628. this.milliseconds(0);
  33629. }
  33630. // weeks are a special case
  33631. if (units === 'week') {
  33632. this.weekday(0);
  33633. }
  33634. if (units === 'isoWeek') {
  33635. this.isoWeekday(1);
  33636. }
  33637. // quarters are also special
  33638. if (units === 'quarter') {
  33639. this.month(Math.floor(this.month() / 3) * 3);
  33640. }
  33641. return this;
  33642. }
  33643. function endOf (units) {
  33644. units = normalizeUnits(units);
  33645. if (units === undefined || units === 'millisecond') {
  33646. return this;
  33647. }
  33648. // 'date' is an alias for 'day', so it should be considered as such.
  33649. if (units === 'date') {
  33650. units = 'day';
  33651. }
  33652. return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
  33653. }
  33654. function to_type__valueOf () {
  33655. return this._d.valueOf() - ((this._offset || 0) * 60000);
  33656. }
  33657. function unix () {
  33658. return Math.floor(this.valueOf() / 1000);
  33659. }
  33660. function toDate () {
  33661. return this._offset ? new Date(this.valueOf()) : this._d;
  33662. }
  33663. function toArray () {
  33664. var m = this;
  33665. return [m.year(), m.month(), m.date(), m.hour(), m.minute(), m.second(), m.millisecond()];
  33666. }
  33667. function toObject () {
  33668. var m = this;
  33669. return {
  33670. years: m.year(),
  33671. months: m.month(),
  33672. date: m.date(),
  33673. hours: m.hours(),
  33674. minutes: m.minutes(),
  33675. seconds: m.seconds(),
  33676. milliseconds: m.milliseconds()
  33677. };
  33678. }
  33679. function toJSON () {
  33680. // new Date(NaN).toJSON() === null
  33681. return this.isValid() ? this.toISOString() : null;
  33682. }
  33683. function moment_valid__isValid () {
  33684. return valid__isValid(this);
  33685. }
  33686. function parsingFlags () {
  33687. return extend({}, getParsingFlags(this));
  33688. }
  33689. function invalidAt () {
  33690. return getParsingFlags(this).overflow;
  33691. }
  33692. function creationData() {
  33693. return {
  33694. input: this._i,
  33695. format: this._f,
  33696. locale: this._locale,
  33697. isUTC: this._isUTC,
  33698. strict: this._strict
  33699. };
  33700. }
  33701. // FORMATTING
  33702. addFormatToken(0, ['gg', 2], 0, function () {
  33703. return this.weekYear() % 100;
  33704. });
  33705. addFormatToken(0, ['GG', 2], 0, function () {
  33706. return this.isoWeekYear() % 100;
  33707. });
  33708. function addWeekYearFormatToken (token, getter) {
  33709. addFormatToken(0, [token, token.length], 0, getter);
  33710. }
  33711. addWeekYearFormatToken('gggg', 'weekYear');
  33712. addWeekYearFormatToken('ggggg', 'weekYear');
  33713. addWeekYearFormatToken('GGGG', 'isoWeekYear');
  33714. addWeekYearFormatToken('GGGGG', 'isoWeekYear');
  33715. // ALIASES
  33716. addUnitAlias('weekYear', 'gg');
  33717. addUnitAlias('isoWeekYear', 'GG');
  33718. // PARSING
  33719. addRegexToken('G', matchSigned);
  33720. addRegexToken('g', matchSigned);
  33721. addRegexToken('GG', match1to2, match2);
  33722. addRegexToken('gg', match1to2, match2);
  33723. addRegexToken('GGGG', match1to4, match4);
  33724. addRegexToken('gggg', match1to4, match4);
  33725. addRegexToken('GGGGG', match1to6, match6);
  33726. addRegexToken('ggggg', match1to6, match6);
  33727. addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input, week, config, token) {
  33728. week[token.substr(0, 2)] = toInt(input);
  33729. });
  33730. addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
  33731. week[token] = utils_hooks__hooks.parseTwoDigitYear(input);
  33732. });
  33733. // MOMENTS
  33734. function getSetWeekYear (input) {
  33735. return getSetWeekYearHelper.call(this,
  33736. input,
  33737. this.week(),
  33738. this.weekday(),
  33739. this.localeData()._week.dow,
  33740. this.localeData()._week.doy);
  33741. }
  33742. function getSetISOWeekYear (input) {
  33743. return getSetWeekYearHelper.call(this,
  33744. input, this.isoWeek(), this.isoWeekday(), 1, 4);
  33745. }
  33746. function getISOWeeksInYear () {
  33747. return weeksInYear(this.year(), 1, 4);
  33748. }
  33749. function getWeeksInYear () {
  33750. var weekInfo = this.localeData()._week;
  33751. return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
  33752. }
  33753. function getSetWeekYearHelper(input, week, weekday, dow, doy) {
  33754. var weeksTarget;
  33755. if (input == null) {
  33756. return weekOfYear(this, dow, doy).year;
  33757. } else {
  33758. weeksTarget = weeksInYear(input, dow, doy);
  33759. if (week > weeksTarget) {
  33760. week = weeksTarget;
  33761. }
  33762. return setWeekAll.call(this, input, week, weekday, dow, doy);
  33763. }
  33764. }
  33765. function setWeekAll(weekYear, week, weekday, dow, doy) {
  33766. var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy),
  33767. date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear);
  33768. this.year(date.getUTCFullYear());
  33769. this.month(date.getUTCMonth());
  33770. this.date(date.getUTCDate());
  33771. return this;
  33772. }
  33773. // FORMATTING
  33774. addFormatToken('Q', 0, 'Qo', 'quarter');
  33775. // ALIASES
  33776. addUnitAlias('quarter', 'Q');
  33777. // PARSING
  33778. addRegexToken('Q', match1);
  33779. addParseToken('Q', function (input, array) {
  33780. array[MONTH] = (toInt(input) - 1) * 3;
  33781. });
  33782. // MOMENTS
  33783. function getSetQuarter (input) {
  33784. return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);
  33785. }
  33786. // FORMATTING
  33787. addFormatToken('w', ['ww', 2], 'wo', 'week');
  33788. addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
  33789. // ALIASES
  33790. addUnitAlias('week', 'w');
  33791. addUnitAlias('isoWeek', 'W');
  33792. // PARSING
  33793. addRegexToken('w', match1to2);
  33794. addRegexToken('ww', match1to2, match2);
  33795. addRegexToken('W', match1to2);
  33796. addRegexToken('WW', match1to2, match2);
  33797. addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) {
  33798. week[token.substr(0, 1)] = toInt(input);
  33799. });
  33800. // HELPERS
  33801. // LOCALES
  33802. function localeWeek (mom) {
  33803. return weekOfYear(mom, this._week.dow, this._week.doy).week;
  33804. }
  33805. var defaultLocaleWeek = {
  33806. dow : 0, // Sunday is the first day of the week.
  33807. doy : 6 // The week that contains Jan 1st is the first week of the year.
  33808. };
  33809. function localeFirstDayOfWeek () {
  33810. return this._week.dow;
  33811. }
  33812. function localeFirstDayOfYear () {
  33813. return this._week.doy;
  33814. }
  33815. // MOMENTS
  33816. function getSetWeek (input) {
  33817. var week = this.localeData().week(this);
  33818. return input == null ? week : this.add((input - week) * 7, 'd');
  33819. }
  33820. function getSetISOWeek (input) {
  33821. var week = weekOfYear(this, 1, 4).week;
  33822. return input == null ? week : this.add((input - week) * 7, 'd');
  33823. }
  33824. // FORMATTING
  33825. addFormatToken('D', ['DD', 2], 'Do', 'date');
  33826. // ALIASES
  33827. addUnitAlias('date', 'D');
  33828. // PARSING
  33829. addRegexToken('D', match1to2);
  33830. addRegexToken('DD', match1to2, match2);
  33831. addRegexToken('Do', function (isStrict, locale) {
  33832. return isStrict ? locale._ordinalParse : locale._ordinalParseLenient;
  33833. });
  33834. addParseToken(['D', 'DD'], DATE);
  33835. addParseToken('Do', function (input, array) {
  33836. array[DATE] = toInt(input.match(match1to2)[0], 10);
  33837. });
  33838. // MOMENTS
  33839. var getSetDayOfMonth = makeGetSet('Date', true);
  33840. // FORMATTING
  33841. addFormatToken('d', 0, 'do', 'day');
  33842. addFormatToken('dd', 0, 0, function (format) {
  33843. return this.localeData().weekdaysMin(this, format);
  33844. });
  33845. addFormatToken('ddd', 0, 0, function (format) {
  33846. return this.localeData().weekdaysShort(this, format);
  33847. });
  33848. addFormatToken('dddd', 0, 0, function (format) {
  33849. return this.localeData().weekdays(this, format);
  33850. });
  33851. addFormatToken('e', 0, 0, 'weekday');
  33852. addFormatToken('E', 0, 0, 'isoWeekday');
  33853. // ALIASES
  33854. addUnitAlias('day', 'd');
  33855. addUnitAlias('weekday', 'e');
  33856. addUnitAlias('isoWeekday', 'E');
  33857. // PARSING
  33858. addRegexToken('d', match1to2);
  33859. addRegexToken('e', match1to2);
  33860. addRegexToken('E', match1to2);
  33861. addRegexToken('dd', function (isStrict, locale) {
  33862. return locale.weekdaysMinRegex(isStrict);
  33863. });
  33864. addRegexToken('ddd', function (isStrict, locale) {
  33865. return locale.weekdaysShortRegex(isStrict);
  33866. });
  33867. addRegexToken('dddd', function (isStrict, locale) {
  33868. return locale.weekdaysRegex(isStrict);
  33869. });
  33870. addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) {
  33871. var weekday = config._locale.weekdaysParse(input, token, config._strict);
  33872. // if we didn't get a weekday name, mark the date as invalid
  33873. if (weekday != null) {
  33874. week.d = weekday;
  33875. } else {
  33876. getParsingFlags(config).invalidWeekday = input;
  33877. }
  33878. });
  33879. addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) {
  33880. week[token] = toInt(input);
  33881. });
  33882. // HELPERS
  33883. function parseWeekday(input, locale) {
  33884. if (typeof input !== 'string') {
  33885. return input;
  33886. }
  33887. if (!isNaN(input)) {
  33888. return parseInt(input, 10);
  33889. }
  33890. input = locale.weekdaysParse(input);
  33891. if (typeof input === 'number') {
  33892. return input;
  33893. }
  33894. return null;
  33895. }
  33896. // LOCALES
  33897. var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
  33898. function localeWeekdays (m, format) {
  33899. return isArray(this._weekdays) ? this._weekdays[m.day()] :
  33900. this._weekdays[this._weekdays.isFormat.test(format) ? 'format' : 'standalone'][m.day()];
  33901. }
  33902. var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
  33903. function localeWeekdaysShort (m) {
  33904. return this._weekdaysShort[m.day()];
  33905. }
  33906. var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
  33907. function localeWeekdaysMin (m) {
  33908. return this._weekdaysMin[m.day()];
  33909. }
  33910. function day_of_week__handleStrictParse(weekdayName, format, strict) {
  33911. var i, ii, mom, llc = weekdayName.toLocaleLowerCase();
  33912. if (!this._weekdaysParse) {
  33913. this._weekdaysParse = [];
  33914. this._shortWeekdaysParse = [];
  33915. this._minWeekdaysParse = [];
  33916. for (i = 0; i < 7; ++i) {
  33917. mom = create_utc__createUTC([2000, 1]).day(i);
  33918. this._minWeekdaysParse[i] = this.weekdaysMin(mom, '').toLocaleLowerCase();
  33919. this._shortWeekdaysParse[i] = this.weekdaysShort(mom, '').toLocaleLowerCase();
  33920. this._weekdaysParse[i] = this.weekdays(mom, '').toLocaleLowerCase();
  33921. }
  33922. }
  33923. if (strict) {
  33924. if (format === 'dddd') {
  33925. ii = indexOf.call(this._weekdaysParse, llc);
  33926. return ii !== -1 ? ii : null;
  33927. } else if (format === 'ddd') {
  33928. ii = indexOf.call(this._shortWeekdaysParse, llc);
  33929. return ii !== -1 ? ii : null;
  33930. } else {
  33931. ii = indexOf.call(this._minWeekdaysParse, llc);
  33932. return ii !== -1 ? ii : null;
  33933. }
  33934. } else {
  33935. if (format === 'dddd') {
  33936. ii = indexOf.call(this._weekdaysParse, llc);
  33937. if (ii !== -1) {
  33938. return ii;
  33939. }
  33940. ii = indexOf.call(this._shortWeekdaysParse, llc);
  33941. if (ii !== -1) {
  33942. return ii;
  33943. }
  33944. ii = indexOf.call(this._minWeekdaysParse, llc);
  33945. return ii !== -1 ? ii : null;
  33946. } else if (format === 'ddd') {
  33947. ii = indexOf.call(this._shortWeekdaysParse, llc);
  33948. if (ii !== -1) {
  33949. return ii;
  33950. }
  33951. ii = indexOf.call(this._weekdaysParse, llc);
  33952. if (ii !== -1) {
  33953. return ii;
  33954. }
  33955. ii = indexOf.call(this._minWeekdaysParse, llc);
  33956. return ii !== -1 ? ii : null;
  33957. } else {
  33958. ii = indexOf.call(this._minWeekdaysParse, llc);
  33959. if (ii !== -1) {
  33960. return ii;
  33961. }
  33962. ii = indexOf.call(this._weekdaysParse, llc);
  33963. if (ii !== -1) {
  33964. return ii;
  33965. }
  33966. ii = indexOf.call(this._shortWeekdaysParse, llc);
  33967. return ii !== -1 ? ii : null;
  33968. }
  33969. }
  33970. }
  33971. function localeWeekdaysParse (weekdayName, format, strict) {
  33972. var i, mom, regex;
  33973. if (this._weekdaysParseExact) {
  33974. return day_of_week__handleStrictParse.call(this, weekdayName, format, strict);
  33975. }
  33976. if (!this._weekdaysParse) {
  33977. this._weekdaysParse = [];
  33978. this._minWeekdaysParse = [];
  33979. this._shortWeekdaysParse = [];
  33980. this._fullWeekdaysParse = [];
  33981. }
  33982. for (i = 0; i < 7; i++) {
  33983. // make the regex if we don't have it already
  33984. mom = create_utc__createUTC([2000, 1]).day(i);
  33985. if (strict && !this._fullWeekdaysParse[i]) {
  33986. this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\.?') + '$', 'i');
  33987. this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\.?') + '$', 'i');
  33988. this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\.?') + '$', 'i');
  33989. }
  33990. if (!this._weekdaysParse[i]) {
  33991. regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
  33992. this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
  33993. }
  33994. // test the regex
  33995. if (strict && format === 'dddd' && this._fullWeekdaysParse[i].test(weekdayName)) {
  33996. return i;
  33997. } else if (strict && format === 'ddd' && this._shortWeekdaysParse[i].test(weekdayName)) {
  33998. return i;
  33999. } else if (strict && format === 'dd' && this._minWeekdaysParse[i].test(weekdayName)) {
  34000. return i;
  34001. } else if (!strict && this._weekdaysParse[i].test(weekdayName)) {
  34002. return i;
  34003. }
  34004. }
  34005. }
  34006. // MOMENTS
  34007. function getSetDayOfWeek (input) {
  34008. if (!this.isValid()) {
  34009. return input != null ? this : NaN;
  34010. }
  34011. var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
  34012. if (input != null) {
  34013. input = parseWeekday(input, this.localeData());
  34014. return this.add(input - day, 'd');
  34015. } else {
  34016. return day;
  34017. }
  34018. }
  34019. function getSetLocaleDayOfWeek (input) {
  34020. if (!this.isValid()) {
  34021. return input != null ? this : NaN;
  34022. }
  34023. var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
  34024. return input == null ? weekday : this.add(input - weekday, 'd');
  34025. }
  34026. function getSetISODayOfWeek (input) {
  34027. if (!this.isValid()) {
  34028. return input != null ? this : NaN;
  34029. }
  34030. // behaves the same as moment#day except
  34031. // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
  34032. // as a setter, sunday should belong to the previous week.
  34033. return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7);
  34034. }
  34035. var defaultWeekdaysRegex = matchWord;
  34036. function weekdaysRegex (isStrict) {
  34037. if (this._weekdaysParseExact) {
  34038. if (!hasOwnProp(this, '_weekdaysRegex')) {
  34039. computeWeekdaysParse.call(this);
  34040. }
  34041. if (isStrict) {
  34042. return this._weekdaysStrictRegex;
  34043. } else {
  34044. return this._weekdaysRegex;
  34045. }
  34046. } else {
  34047. return this._weekdaysStrictRegex && isStrict ?
  34048. this._weekdaysStrictRegex : this._weekdaysRegex;
  34049. }
  34050. }
  34051. var defaultWeekdaysShortRegex = matchWord;
  34052. function weekdaysShortRegex (isStrict) {
  34053. if (this._weekdaysParseExact) {
  34054. if (!hasOwnProp(this, '_weekdaysRegex')) {
  34055. computeWeekdaysParse.call(this);
  34056. }
  34057. if (isStrict) {
  34058. return this._weekdaysShortStrictRegex;
  34059. } else {
  34060. return this._weekdaysShortRegex;
  34061. }
  34062. } else {
  34063. return this._weekdaysShortStrictRegex && isStrict ?
  34064. this._weekdaysShortStrictRegex : this._weekdaysShortRegex;
  34065. }
  34066. }
  34067. var defaultWeekdaysMinRegex = matchWord;
  34068. function weekdaysMinRegex (isStrict) {
  34069. if (this._weekdaysParseExact) {
  34070. if (!hasOwnProp(this, '_weekdaysRegex')) {
  34071. computeWeekdaysParse.call(this);
  34072. }
  34073. if (isStrict) {
  34074. return this._weekdaysMinStrictRegex;
  34075. } else {
  34076. return this._weekdaysMinRegex;
  34077. }
  34078. } else {
  34079. return this._weekdaysMinStrictRegex && isStrict ?
  34080. this._weekdaysMinStrictRegex : this._weekdaysMinRegex;
  34081. }
  34082. }
  34083. function computeWeekdaysParse () {
  34084. function cmpLenRev(a, b) {
  34085. return b.length - a.length;
  34086. }
  34087. var minPieces = [], shortPieces = [], longPieces = [], mixedPieces = [],
  34088. i, mom, minp, shortp, longp;
  34089. for (i = 0; i < 7; i++) {
  34090. // make the regex if we don't have it already
  34091. mom = create_utc__createUTC([2000, 1]).day(i);
  34092. minp = this.weekdaysMin(mom, '');
  34093. shortp = this.weekdaysShort(mom, '');
  34094. longp = this.weekdays(mom, '');
  34095. minPieces.push(minp);
  34096. shortPieces.push(shortp);
  34097. longPieces.push(longp);
  34098. mixedPieces.push(minp);
  34099. mixedPieces.push(shortp);
  34100. mixedPieces.push(longp);
  34101. }
  34102. // Sorting makes sure if one weekday (or abbr) is a prefix of another it
  34103. // will match the longer piece.
  34104. minPieces.sort(cmpLenRev);
  34105. shortPieces.sort(cmpLenRev);
  34106. longPieces.sort(cmpLenRev);
  34107. mixedPieces.sort(cmpLenRev);
  34108. for (i = 0; i < 7; i++) {
  34109. shortPieces[i] = regexEscape(shortPieces[i]);
  34110. longPieces[i] = regexEscape(longPieces[i]);
  34111. mixedPieces[i] = regexEscape(mixedPieces[i]);
  34112. }
  34113. this._weekdaysRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
  34114. this._weekdaysShortRegex = this._weekdaysRegex;
  34115. this._weekdaysMinRegex = this._weekdaysRegex;
  34116. this._weekdaysStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
  34117. this._weekdaysShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
  34118. this._weekdaysMinStrictRegex = new RegExp('^(' + minPieces.join('|') + ')', 'i');
  34119. }
  34120. // FORMATTING
  34121. addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
  34122. // ALIASES
  34123. addUnitAlias('dayOfYear', 'DDD');
  34124. // PARSING
  34125. addRegexToken('DDD', match1to3);
  34126. addRegexToken('DDDD', match3);
  34127. addParseToken(['DDD', 'DDDD'], function (input, array, config) {
  34128. config._dayOfYear = toInt(input);
  34129. });
  34130. // HELPERS
  34131. // MOMENTS
  34132. function getSetDayOfYear (input) {
  34133. var dayOfYear = Math.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5) + 1;
  34134. return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
  34135. }
  34136. // FORMATTING
  34137. function hFormat() {
  34138. return this.hours() % 12 || 12;
  34139. }
  34140. function kFormat() {
  34141. return this.hours() || 24;
  34142. }
  34143. addFormatToken('H', ['HH', 2], 0, 'hour');
  34144. addFormatToken('h', ['hh', 2], 0, hFormat);
  34145. addFormatToken('k', ['kk', 2], 0, kFormat);
  34146. addFormatToken('hmm', 0, 0, function () {
  34147. return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2);
  34148. });
  34149. addFormatToken('hmmss', 0, 0, function () {
  34150. return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2) +
  34151. zeroFill(this.seconds(), 2);
  34152. });
  34153. addFormatToken('Hmm', 0, 0, function () {
  34154. return '' + this.hours() + zeroFill(this.minutes(), 2);
  34155. });
  34156. addFormatToken('Hmmss', 0, 0, function () {
  34157. return '' + this.hours() + zeroFill(this.minutes(), 2) +
  34158. zeroFill(this.seconds(), 2);
  34159. });
  34160. function meridiem (token, lowercase) {
  34161. addFormatToken(token, 0, 0, function () {
  34162. return this.localeData().meridiem(this.hours(), this.minutes(), lowercase);
  34163. });
  34164. }
  34165. meridiem('a', true);
  34166. meridiem('A', false);
  34167. // ALIASES
  34168. addUnitAlias('hour', 'h');
  34169. // PARSING
  34170. function matchMeridiem (isStrict, locale) {
  34171. return locale._meridiemParse;
  34172. }
  34173. addRegexToken('a', matchMeridiem);
  34174. addRegexToken('A', matchMeridiem);
  34175. addRegexToken('H', match1to2);
  34176. addRegexToken('h', match1to2);
  34177. addRegexToken('HH', match1to2, match2);
  34178. addRegexToken('hh', match1to2, match2);
  34179. addRegexToken('hmm', match3to4);
  34180. addRegexToken('hmmss', match5to6);
  34181. addRegexToken('Hmm', match3to4);
  34182. addRegexToken('Hmmss', match5to6);
  34183. addParseToken(['H', 'HH'], HOUR);
  34184. addParseToken(['a', 'A'], function (input, array, config) {
  34185. config._isPm = config._locale.isPM(input);
  34186. config._meridiem = input;
  34187. });
  34188. addParseToken(['h', 'hh'], function (input, array, config) {
  34189. array[HOUR] = toInt(input);
  34190. getParsingFlags(config).bigHour = true;
  34191. });
  34192. addParseToken('hmm', function (input, array, config) {
  34193. var pos = input.length - 2;
  34194. array[HOUR] = toInt(input.substr(0, pos));
  34195. array[MINUTE] = toInt(input.substr(pos));
  34196. getParsingFlags(config).bigHour = true;
  34197. });
  34198. addParseToken('hmmss', function (input, array, config) {
  34199. var pos1 = input.length - 4;
  34200. var pos2 = input.length - 2;
  34201. array[HOUR] = toInt(input.substr(0, pos1));
  34202. array[MINUTE] = toInt(input.substr(pos1, 2));
  34203. array[SECOND] = toInt(input.substr(pos2));
  34204. getParsingFlags(config).bigHour = true;
  34205. });
  34206. addParseToken('Hmm', function (input, array, config) {
  34207. var pos = input.length - 2;
  34208. array[HOUR] = toInt(input.substr(0, pos));
  34209. array[MINUTE] = toInt(input.substr(pos));
  34210. });
  34211. addParseToken('Hmmss', function (input, array, config) {
  34212. var pos1 = input.length - 4;
  34213. var pos2 = input.length - 2;
  34214. array[HOUR] = toInt(input.substr(0, pos1));
  34215. array[MINUTE] = toInt(input.substr(pos1, 2));
  34216. array[SECOND] = toInt(input.substr(pos2));
  34217. });
  34218. // LOCALES
  34219. function localeIsPM (input) {
  34220. // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
  34221. // Using charAt should be more compatible.
  34222. return ((input + '').toLowerCase().charAt(0) === 'p');
  34223. }
  34224. var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i;
  34225. function localeMeridiem (hours, minutes, isLower) {
  34226. if (hours > 11) {
  34227. return isLower ? 'pm' : 'PM';
  34228. } else {
  34229. return isLower ? 'am' : 'AM';
  34230. }
  34231. }
  34232. // MOMENTS
  34233. // Setting the hour should keep the time, because the user explicitly
  34234. // specified which hour he wants. So trying to maintain the same hour (in
  34235. // a new timezone) makes sense. Adding/subtracting hours does not follow
  34236. // this rule.
  34237. var getSetHour = makeGetSet('Hours', true);
  34238. // FORMATTING
  34239. addFormatToken('m', ['mm', 2], 0, 'minute');
  34240. // ALIASES
  34241. addUnitAlias('minute', 'm');
  34242. // PARSING
  34243. addRegexToken('m', match1to2);
  34244. addRegexToken('mm', match1to2, match2);
  34245. addParseToken(['m', 'mm'], MINUTE);
  34246. // MOMENTS
  34247. var getSetMinute = makeGetSet('Minutes', false);
  34248. // FORMATTING
  34249. addFormatToken('s', ['ss', 2], 0, 'second');
  34250. // ALIASES
  34251. addUnitAlias('second', 's');
  34252. // PARSING
  34253. addRegexToken('s', match1to2);
  34254. addRegexToken('ss', match1to2, match2);
  34255. addParseToken(['s', 'ss'], SECOND);
  34256. // MOMENTS
  34257. var getSetSecond = makeGetSet('Seconds', false);
  34258. // FORMATTING
  34259. addFormatToken('S', 0, 0, function () {
  34260. return ~~(this.millisecond() / 100);
  34261. });
  34262. addFormatToken(0, ['SS', 2], 0, function () {
  34263. return ~~(this.millisecond() / 10);
  34264. });
  34265. addFormatToken(0, ['SSS', 3], 0, 'millisecond');
  34266. addFormatToken(0, ['SSSS', 4], 0, function () {
  34267. return this.millisecond() * 10;
  34268. });
  34269. addFormatToken(0, ['SSSSS', 5], 0, function () {
  34270. return this.millisecond() * 100;
  34271. });
  34272. addFormatToken(0, ['SSSSSS', 6], 0, function () {
  34273. return this.millisecond() * 1000;
  34274. });
  34275. addFormatToken(0, ['SSSSSSS', 7], 0, function () {
  34276. return this.millisecond() * 10000;
  34277. });
  34278. addFormatToken(0, ['SSSSSSSS', 8], 0, function () {
  34279. return this.millisecond() * 100000;
  34280. });
  34281. addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
  34282. return this.millisecond() * 1000000;
  34283. });
  34284. // ALIASES
  34285. addUnitAlias('millisecond', 'ms');
  34286. // PARSING
  34287. addRegexToken('S', match1to3, match1);
  34288. addRegexToken('SS', match1to3, match2);
  34289. addRegexToken('SSS', match1to3, match3);
  34290. var token;
  34291. for (token = 'SSSS'; token.length <= 9; token += 'S') {
  34292. addRegexToken(token, matchUnsigned);
  34293. }
  34294. function parseMs(input, array) {
  34295. array[MILLISECOND] = toInt(('0.' + input) * 1000);
  34296. }
  34297. for (token = 'S'; token.length <= 9; token += 'S') {
  34298. addParseToken(token, parseMs);
  34299. }
  34300. // MOMENTS
  34301. var getSetMillisecond = makeGetSet('Milliseconds', false);
  34302. // FORMATTING
  34303. addFormatToken('z', 0, 0, 'zoneAbbr');
  34304. addFormatToken('zz', 0, 0, 'zoneName');
  34305. // MOMENTS
  34306. function getZoneAbbr () {
  34307. return this._isUTC ? 'UTC' : '';
  34308. }
  34309. function getZoneName () {
  34310. return this._isUTC ? 'Coordinated Universal Time' : '';
  34311. }
  34312. var momentPrototype__proto = Moment.prototype;
  34313. momentPrototype__proto.add = add_subtract__add;
  34314. momentPrototype__proto.calendar = moment_calendar__calendar;
  34315. momentPrototype__proto.clone = clone;
  34316. momentPrototype__proto.diff = diff;
  34317. momentPrototype__proto.endOf = endOf;
  34318. momentPrototype__proto.format = format;
  34319. momentPrototype__proto.from = from;
  34320. momentPrototype__proto.fromNow = fromNow;
  34321. momentPrototype__proto.to = to;
  34322. momentPrototype__proto.toNow = toNow;
  34323. momentPrototype__proto.get = getSet;
  34324. momentPrototype__proto.invalidAt = invalidAt;
  34325. momentPrototype__proto.isAfter = isAfter;
  34326. momentPrototype__proto.isBefore = isBefore;
  34327. momentPrototype__proto.isBetween = isBetween;
  34328. momentPrototype__proto.isSame = isSame;
  34329. momentPrototype__proto.isSameOrAfter = isSameOrAfter;
  34330. momentPrototype__proto.isSameOrBefore = isSameOrBefore;
  34331. momentPrototype__proto.isValid = moment_valid__isValid;
  34332. momentPrototype__proto.lang = lang;
  34333. momentPrototype__proto.locale = locale;
  34334. momentPrototype__proto.localeData = localeData;
  34335. momentPrototype__proto.max = prototypeMax;
  34336. momentPrototype__proto.min = prototypeMin;
  34337. momentPrototype__proto.parsingFlags = parsingFlags;
  34338. momentPrototype__proto.set = getSet;
  34339. momentPrototype__proto.startOf = startOf;
  34340. momentPrototype__proto.subtract = add_subtract__subtract;
  34341. momentPrototype__proto.toArray = toArray;
  34342. momentPrototype__proto.toObject = toObject;
  34343. momentPrototype__proto.toDate = toDate;
  34344. momentPrototype__proto.toISOString = moment_format__toISOString;
  34345. momentPrototype__proto.toJSON = toJSON;
  34346. momentPrototype__proto.toString = toString;
  34347. momentPrototype__proto.unix = unix;
  34348. momentPrototype__proto.valueOf = to_type__valueOf;
  34349. momentPrototype__proto.creationData = creationData;
  34350. // Year
  34351. momentPrototype__proto.year = getSetYear;
  34352. momentPrototype__proto.isLeapYear = getIsLeapYear;
  34353. // Week Year
  34354. momentPrototype__proto.weekYear = getSetWeekYear;
  34355. momentPrototype__proto.isoWeekYear = getSetISOWeekYear;
  34356. // Quarter
  34357. momentPrototype__proto.quarter = momentPrototype__proto.quarters = getSetQuarter;
  34358. // Month
  34359. momentPrototype__proto.month = getSetMonth;
  34360. momentPrototype__proto.daysInMonth = getDaysInMonth;
  34361. // Week
  34362. momentPrototype__proto.week = momentPrototype__proto.weeks = getSetWeek;
  34363. momentPrototype__proto.isoWeek = momentPrototype__proto.isoWeeks = getSetISOWeek;
  34364. momentPrototype__proto.weeksInYear = getWeeksInYear;
  34365. momentPrototype__proto.isoWeeksInYear = getISOWeeksInYear;
  34366. // Day
  34367. momentPrototype__proto.date = getSetDayOfMonth;
  34368. momentPrototype__proto.day = momentPrototype__proto.days = getSetDayOfWeek;
  34369. momentPrototype__proto.weekday = getSetLocaleDayOfWeek;
  34370. momentPrototype__proto.isoWeekday = getSetISODayOfWeek;
  34371. momentPrototype__proto.dayOfYear = getSetDayOfYear;
  34372. // Hour
  34373. momentPrototype__proto.hour = momentPrototype__proto.hours = getSetHour;
  34374. // Minute
  34375. momentPrototype__proto.minute = momentPrototype__proto.minutes = getSetMinute;
  34376. // Second
  34377. momentPrototype__proto.second = momentPrototype__proto.seconds = getSetSecond;
  34378. // Millisecond
  34379. momentPrototype__proto.millisecond = momentPrototype__proto.milliseconds = getSetMillisecond;
  34380. // Offset
  34381. momentPrototype__proto.utcOffset = getSetOffset;
  34382. momentPrototype__proto.utc = setOffsetToUTC;
  34383. momentPrototype__proto.local = setOffsetToLocal;
  34384. momentPrototype__proto.parseZone = setOffsetToParsedOffset;
  34385. momentPrototype__proto.hasAlignedHourOffset = hasAlignedHourOffset;
  34386. momentPrototype__proto.isDST = isDaylightSavingTime;
  34387. momentPrototype__proto.isDSTShifted = isDaylightSavingTimeShifted;
  34388. momentPrototype__proto.isLocal = isLocal;
  34389. momentPrototype__proto.isUtcOffset = isUtcOffset;
  34390. momentPrototype__proto.isUtc = isUtc;
  34391. momentPrototype__proto.isUTC = isUtc;
  34392. // Timezone
  34393. momentPrototype__proto.zoneAbbr = getZoneAbbr;
  34394. momentPrototype__proto.zoneName = getZoneName;
  34395. // Deprecations
  34396. momentPrototype__proto.dates = deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth);
  34397. momentPrototype__proto.months = deprecate('months accessor is deprecated. Use month instead', getSetMonth);
  34398. momentPrototype__proto.years = deprecate('years accessor is deprecated. Use year instead', getSetYear);
  34399. momentPrototype__proto.zone = deprecate('moment().zone is deprecated, use moment().utcOffset instead. https://github.com/moment/moment/issues/1779', getSetZone);
  34400. var momentPrototype = momentPrototype__proto;
  34401. function moment__createUnix (input) {
  34402. return local__createLocal(input * 1000);
  34403. }
  34404. function moment__createInZone () {
  34405. return local__createLocal.apply(null, arguments).parseZone();
  34406. }
  34407. var defaultCalendar = {
  34408. sameDay : '[Today at] LT',
  34409. nextDay : '[Tomorrow at] LT',
  34410. nextWeek : 'dddd [at] LT',
  34411. lastDay : '[Yesterday at] LT',
  34412. lastWeek : '[Last] dddd [at] LT',
  34413. sameElse : 'L'
  34414. };
  34415. function locale_calendar__calendar (key, mom, now) {
  34416. var output = this._calendar[key];
  34417. return isFunction(output) ? output.call(mom, now) : output;
  34418. }
  34419. var defaultLongDateFormat = {
  34420. LTS : 'h:mm:ss A',
  34421. LT : 'h:mm A',
  34422. L : 'MM/DD/YYYY',
  34423. LL : 'MMMM D, YYYY',
  34424. LLL : 'MMMM D, YYYY h:mm A',
  34425. LLLL : 'dddd, MMMM D, YYYY h:mm A'
  34426. };
  34427. function longDateFormat (key) {
  34428. var format = this._longDateFormat[key],
  34429. formatUpper = this._longDateFormat[key.toUpperCase()];
  34430. if (format || !formatUpper) {
  34431. return format;
  34432. }
  34433. this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) {
  34434. return val.slice(1);
  34435. });
  34436. return this._longDateFormat[key];
  34437. }
  34438. var defaultInvalidDate = 'Invalid date';
  34439. function invalidDate () {
  34440. return this._invalidDate;
  34441. }
  34442. var defaultOrdinal = '%d';
  34443. var defaultOrdinalParse = /\d{1,2}/;
  34444. function ordinal (number) {
  34445. return this._ordinal.replace('%d', number);
  34446. }
  34447. function preParsePostFormat (string) {
  34448. return string;
  34449. }
  34450. var defaultRelativeTime = {
  34451. future : 'in %s',
  34452. past : '%s ago',
  34453. s : 'a few seconds',
  34454. m : 'a minute',
  34455. mm : '%d minutes',
  34456. h : 'an hour',
  34457. hh : '%d hours',
  34458. d : 'a day',
  34459. dd : '%d days',
  34460. M : 'a month',
  34461. MM : '%d months',
  34462. y : 'a year',
  34463. yy : '%d years'
  34464. };
  34465. function relative__relativeTime (number, withoutSuffix, string, isFuture) {
  34466. var output = this._relativeTime[string];
  34467. return (isFunction(output)) ?
  34468. output(number, withoutSuffix, string, isFuture) :
  34469. output.replace(/%d/i, number);
  34470. }
  34471. function pastFuture (diff, output) {
  34472. var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
  34473. return isFunction(format) ? format(output) : format.replace(/%s/i, output);
  34474. }
  34475. var prototype__proto = Locale.prototype;
  34476. prototype__proto._calendar = defaultCalendar;
  34477. prototype__proto.calendar = locale_calendar__calendar;
  34478. prototype__proto._longDateFormat = defaultLongDateFormat;
  34479. prototype__proto.longDateFormat = longDateFormat;
  34480. prototype__proto._invalidDate = defaultInvalidDate;
  34481. prototype__proto.invalidDate = invalidDate;
  34482. prototype__proto._ordinal = defaultOrdinal;
  34483. prototype__proto.ordinal = ordinal;
  34484. prototype__proto._ordinalParse = defaultOrdinalParse;
  34485. prototype__proto.preparse = preParsePostFormat;
  34486. prototype__proto.postformat = preParsePostFormat;
  34487. prototype__proto._relativeTime = defaultRelativeTime;
  34488. prototype__proto.relativeTime = relative__relativeTime;
  34489. prototype__proto.pastFuture = pastFuture;
  34490. prototype__proto.set = locale_set__set;
  34491. // Month
  34492. prototype__proto.months = localeMonths;
  34493. prototype__proto._months = defaultLocaleMonths;
  34494. prototype__proto.monthsShort = localeMonthsShort;
  34495. prototype__proto._monthsShort = defaultLocaleMonthsShort;
  34496. prototype__proto.monthsParse = localeMonthsParse;
  34497. prototype__proto._monthsRegex = defaultMonthsRegex;
  34498. prototype__proto.monthsRegex = monthsRegex;
  34499. prototype__proto._monthsShortRegex = defaultMonthsShortRegex;
  34500. prototype__proto.monthsShortRegex = monthsShortRegex;
  34501. // Week
  34502. prototype__proto.week = localeWeek;
  34503. prototype__proto._week = defaultLocaleWeek;
  34504. prototype__proto.firstDayOfYear = localeFirstDayOfYear;
  34505. prototype__proto.firstDayOfWeek = localeFirstDayOfWeek;
  34506. // Day of Week
  34507. prototype__proto.weekdays = localeWeekdays;
  34508. prototype__proto._weekdays = defaultLocaleWeekdays;
  34509. prototype__proto.weekdaysMin = localeWeekdaysMin;
  34510. prototype__proto._weekdaysMin = defaultLocaleWeekdaysMin;
  34511. prototype__proto.weekdaysShort = localeWeekdaysShort;
  34512. prototype__proto._weekdaysShort = defaultLocaleWeekdaysShort;
  34513. prototype__proto.weekdaysParse = localeWeekdaysParse;
  34514. prototype__proto._weekdaysRegex = defaultWeekdaysRegex;
  34515. prototype__proto.weekdaysRegex = weekdaysRegex;
  34516. prototype__proto._weekdaysShortRegex = defaultWeekdaysShortRegex;
  34517. prototype__proto.weekdaysShortRegex = weekdaysShortRegex;
  34518. prototype__proto._weekdaysMinRegex = defaultWeekdaysMinRegex;
  34519. prototype__proto.weekdaysMinRegex = weekdaysMinRegex;
  34520. // Hours
  34521. prototype__proto.isPM = localeIsPM;
  34522. prototype__proto._meridiemParse = defaultLocaleMeridiemParse;
  34523. prototype__proto.meridiem = localeMeridiem;
  34524. function lists__get (format, index, field, setter) {
  34525. var locale = locale_locales__getLocale();
  34526. var utc = create_utc__createUTC().set(setter, index);
  34527. return locale[field](utc, format);
  34528. }
  34529. function listMonthsImpl (format, index, field) {
  34530. if (typeof format === 'number') {
  34531. index = format;
  34532. format = undefined;
  34533. }
  34534. format = format || '';
  34535. if (index != null) {
  34536. return lists__get(format, index, field, 'month');
  34537. }
  34538. var i;
  34539. var out = [];
  34540. for (i = 0; i < 12; i++) {
  34541. out[i] = lists__get(format, i, field, 'month');
  34542. }
  34543. return out;
  34544. }
  34545. // ()
  34546. // (5)
  34547. // (fmt, 5)
  34548. // (fmt)
  34549. // (true)
  34550. // (true, 5)
  34551. // (true, fmt, 5)
  34552. // (true, fmt)
  34553. function listWeekdaysImpl (localeSorted, format, index, field) {
  34554. if (typeof localeSorted === 'boolean') {
  34555. if (typeof format === 'number') {
  34556. index = format;
  34557. format = undefined;
  34558. }
  34559. format = format || '';
  34560. } else {
  34561. format = localeSorted;
  34562. index = format;
  34563. localeSorted = false;
  34564. if (typeof format === 'number') {
  34565. index = format;
  34566. format = undefined;
  34567. }
  34568. format = format || '';
  34569. }
  34570. var locale = locale_locales__getLocale(),
  34571. shift = localeSorted ? locale._week.dow : 0;
  34572. if (index != null) {
  34573. return lists__get(format, (index + shift) % 7, field, 'day');
  34574. }
  34575. var i;
  34576. var out = [];
  34577. for (i = 0; i < 7; i++) {
  34578. out[i] = lists__get(format, (i + shift) % 7, field, 'day');
  34579. }
  34580. return out;
  34581. }
  34582. function lists__listMonths (format, index) {
  34583. return listMonthsImpl(format, index, 'months');
  34584. }
  34585. function lists__listMonthsShort (format, index) {
  34586. return listMonthsImpl(format, index, 'monthsShort');
  34587. }
  34588. function lists__listWeekdays (localeSorted, format, index) {
  34589. return listWeekdaysImpl(localeSorted, format, index, 'weekdays');
  34590. }
  34591. function lists__listWeekdaysShort (localeSorted, format, index) {
  34592. return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort');
  34593. }
  34594. function lists__listWeekdaysMin (localeSorted, format, index) {
  34595. return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin');
  34596. }
  34597. locale_locales__getSetGlobalLocale('en', {
  34598. ordinalParse: /\d{1,2}(th|st|nd|rd)/,
  34599. ordinal : function (number) {
  34600. var b = number % 10,
  34601. output = (toInt(number % 100 / 10) === 1) ? 'th' :
  34602. (b === 1) ? 'st' :
  34603. (b === 2) ? 'nd' :
  34604. (b === 3) ? 'rd' : 'th';
  34605. return number + output;
  34606. }
  34607. });
  34608. // Side effect imports
  34609. utils_hooks__hooks.lang = deprecate('moment.lang is deprecated. Use moment.locale instead.', locale_locales__getSetGlobalLocale);
  34610. utils_hooks__hooks.langData = deprecate('moment.langData is deprecated. Use moment.localeData instead.', locale_locales__getLocale);
  34611. var mathAbs = Math.abs;
  34612. function duration_abs__abs () {
  34613. var data = this._data;
  34614. this._milliseconds = mathAbs(this._milliseconds);
  34615. this._days = mathAbs(this._days);
  34616. this._months = mathAbs(this._months);
  34617. data.milliseconds = mathAbs(data.milliseconds);
  34618. data.seconds = mathAbs(data.seconds);
  34619. data.minutes = mathAbs(data.minutes);
  34620. data.hours = mathAbs(data.hours);
  34621. data.months = mathAbs(data.months);
  34622. data.years = mathAbs(data.years);
  34623. return this;
  34624. }
  34625. function duration_add_subtract__addSubtract (duration, input, value, direction) {
  34626. var other = create__createDuration(input, value);
  34627. duration._milliseconds += direction * other._milliseconds;
  34628. duration._days += direction * other._days;
  34629. duration._months += direction * other._months;
  34630. return duration._bubble();
  34631. }
  34632. // supports only 2.0-style add(1, 's') or add(duration)
  34633. function duration_add_subtract__add (input, value) {
  34634. return duration_add_subtract__addSubtract(this, input, value, 1);
  34635. }
  34636. // supports only 2.0-style subtract(1, 's') or subtract(duration)
  34637. function duration_add_subtract__subtract (input, value) {
  34638. return duration_add_subtract__addSubtract(this, input, value, -1);
  34639. }
  34640. function absCeil (number) {
  34641. if (number < 0) {
  34642. return Math.floor(number);
  34643. } else {
  34644. return Math.ceil(number);
  34645. }
  34646. }
  34647. function bubble () {
  34648. var milliseconds = this._milliseconds;
  34649. var days = this._days;
  34650. var months = this._months;
  34651. var data = this._data;
  34652. var seconds, minutes, hours, years, monthsFromDays;
  34653. // if we have a mix of positive and negative values, bubble down first
  34654. // check: https://github.com/moment/moment/issues/2166
  34655. if (!((milliseconds >= 0 && days >= 0 && months >= 0) ||
  34656. (milliseconds <= 0 && days <= 0 && months <= 0))) {
  34657. milliseconds += absCeil(monthsToDays(months) + days) * 864e5;
  34658. days = 0;
  34659. months = 0;
  34660. }
  34661. // The following code bubbles up values, see the tests for
  34662. // examples of what that means.
  34663. data.milliseconds = milliseconds % 1000;
  34664. seconds = absFloor(milliseconds / 1000);
  34665. data.seconds = seconds % 60;
  34666. minutes = absFloor(seconds / 60);
  34667. data.minutes = minutes % 60;
  34668. hours = absFloor(minutes / 60);
  34669. data.hours = hours % 24;
  34670. days += absFloor(hours / 24);
  34671. // convert days to months
  34672. monthsFromDays = absFloor(daysToMonths(days));
  34673. months += monthsFromDays;
  34674. days -= absCeil(monthsToDays(monthsFromDays));
  34675. // 12 months -> 1 year
  34676. years = absFloor(months / 12);
  34677. months %= 12;
  34678. data.days = days;
  34679. data.months = months;
  34680. data.years = years;
  34681. return this;
  34682. }
  34683. function daysToMonths (days) {
  34684. // 400 years have 146097 days (taking into account leap year rules)
  34685. // 400 years have 12 months === 4800
  34686. return days * 4800 / 146097;
  34687. }
  34688. function monthsToDays (months) {
  34689. // the reverse of daysToMonths
  34690. return months * 146097 / 4800;
  34691. }
  34692. function as (units) {
  34693. var days;
  34694. var months;
  34695. var milliseconds = this._milliseconds;
  34696. units = normalizeUnits(units);
  34697. if (units === 'month' || units === 'year') {
  34698. days = this._days + milliseconds / 864e5;
  34699. months = this._months + daysToMonths(days);
  34700. return units === 'month' ? months : months / 12;
  34701. } else {
  34702. // handle milliseconds separately because of floating point math errors (issue #1867)
  34703. days = this._days + Math.round(monthsToDays(this._months));
  34704. switch (units) {
  34705. case 'week' : return days / 7 + milliseconds / 6048e5;
  34706. case 'day' : return days + milliseconds / 864e5;
  34707. case 'hour' : return days * 24 + milliseconds / 36e5;
  34708. case 'minute' : return days * 1440 + milliseconds / 6e4;
  34709. case 'second' : return days * 86400 + milliseconds / 1000;
  34710. // Math.floor prevents floating point math errors here
  34711. case 'millisecond': return Math.floor(days * 864e5) + milliseconds;
  34712. default: throw new Error('Unknown unit ' + units);
  34713. }
  34714. }
  34715. }
  34716. // TODO: Use this.as('ms')?
  34717. function duration_as__valueOf () {
  34718. return (
  34719. this._milliseconds +
  34720. this._days * 864e5 +
  34721. (this._months % 12) * 2592e6 +
  34722. toInt(this._months / 12) * 31536e6
  34723. );
  34724. }
  34725. function makeAs (alias) {
  34726. return function () {
  34727. return this.as(alias);
  34728. };
  34729. }
  34730. var asMilliseconds = makeAs('ms');
  34731. var asSeconds = makeAs('s');
  34732. var asMinutes = makeAs('m');
  34733. var asHours = makeAs('h');
  34734. var asDays = makeAs('d');
  34735. var asWeeks = makeAs('w');
  34736. var asMonths = makeAs('M');
  34737. var asYears = makeAs('y');
  34738. function duration_get__get (units) {
  34739. units = normalizeUnits(units);
  34740. return this[units + 's']();
  34741. }
  34742. function makeGetter(name) {
  34743. return function () {
  34744. return this._data[name];
  34745. };
  34746. }
  34747. var milliseconds = makeGetter('milliseconds');
  34748. var seconds = makeGetter('seconds');
  34749. var minutes = makeGetter('minutes');
  34750. var hours = makeGetter('hours');
  34751. var days = makeGetter('days');
  34752. var months = makeGetter('months');
  34753. var years = makeGetter('years');
  34754. function weeks () {
  34755. return absFloor(this.days() / 7);
  34756. }
  34757. var round = Math.round;
  34758. var thresholds = {
  34759. s: 45, // seconds to minute
  34760. m: 45, // minutes to hour
  34761. h: 22, // hours to day
  34762. d: 26, // days to month
  34763. M: 11 // months to year
  34764. };
  34765. // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
  34766. function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
  34767. return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
  34768. }
  34769. function duration_humanize__relativeTime (posNegDuration, withoutSuffix, locale) {
  34770. var duration = create__createDuration(posNegDuration).abs();
  34771. var seconds = round(duration.as('s'));
  34772. var minutes = round(duration.as('m'));
  34773. var hours = round(duration.as('h'));
  34774. var days = round(duration.as('d'));
  34775. var months = round(duration.as('M'));
  34776. var years = round(duration.as('y'));
  34777. var a = seconds < thresholds.s && ['s', seconds] ||
  34778. minutes <= 1 && ['m'] ||
  34779. minutes < thresholds.m && ['mm', minutes] ||
  34780. hours <= 1 && ['h'] ||
  34781. hours < thresholds.h && ['hh', hours] ||
  34782. days <= 1 && ['d'] ||
  34783. days < thresholds.d && ['dd', days] ||
  34784. months <= 1 && ['M'] ||
  34785. months < thresholds.M && ['MM', months] ||
  34786. years <= 1 && ['y'] || ['yy', years];
  34787. a[2] = withoutSuffix;
  34788. a[3] = +posNegDuration > 0;
  34789. a[4] = locale;
  34790. return substituteTimeAgo.apply(null, a);
  34791. }
  34792. // This function allows you to set a threshold for relative time strings
  34793. function duration_humanize__getSetRelativeTimeThreshold (threshold, limit) {
  34794. if (thresholds[threshold] === undefined) {
  34795. return false;
  34796. }
  34797. if (limit === undefined) {
  34798. return thresholds[threshold];
  34799. }
  34800. thresholds[threshold] = limit;
  34801. return true;
  34802. }
  34803. function humanize (withSuffix) {
  34804. var locale = this.localeData();
  34805. var output = duration_humanize__relativeTime(this, !withSuffix, locale);
  34806. if (withSuffix) {
  34807. output = locale.pastFuture(+this, output);
  34808. }
  34809. return locale.postformat(output);
  34810. }
  34811. var iso_string__abs = Math.abs;
  34812. function iso_string__toISOString() {
  34813. // for ISO strings we do not use the normal bubbling rules:
  34814. // * milliseconds bubble up until they become hours
  34815. // * days do not bubble at all
  34816. // * months bubble up until they become years
  34817. // This is because there is no context-free conversion between hours and days
  34818. // (think of clock changes)
  34819. // and also not between days and months (28-31 days per month)
  34820. var seconds = iso_string__abs(this._milliseconds) / 1000;
  34821. var days = iso_string__abs(this._days);
  34822. var months = iso_string__abs(this._months);
  34823. var minutes, hours, years;
  34824. // 3600 seconds -> 60 minutes -> 1 hour
  34825. minutes = absFloor(seconds / 60);
  34826. hours = absFloor(minutes / 60);
  34827. seconds %= 60;
  34828. minutes %= 60;
  34829. // 12 months -> 1 year
  34830. years = absFloor(months / 12);
  34831. months %= 12;
  34832. // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
  34833. var Y = years;
  34834. var M = months;
  34835. var D = days;
  34836. var h = hours;
  34837. var m = minutes;
  34838. var s = seconds;
  34839. var total = this.asSeconds();
  34840. if (!total) {
  34841. // this is the same as C#'s (Noda) and python (isodate)...
  34842. // but not other JS (goog.date)
  34843. return 'P0D';
  34844. }
  34845. return (total < 0 ? '-' : '') +
  34846. 'P' +
  34847. (Y ? Y + 'Y' : '') +
  34848. (M ? M + 'M' : '') +
  34849. (D ? D + 'D' : '') +
  34850. ((h || m || s) ? 'T' : '') +
  34851. (h ? h + 'H' : '') +
  34852. (m ? m + 'M' : '') +
  34853. (s ? s + 'S' : '');
  34854. }
  34855. var duration_prototype__proto = Duration.prototype;
  34856. duration_prototype__proto.abs = duration_abs__abs;
  34857. duration_prototype__proto.add = duration_add_subtract__add;
  34858. duration_prototype__proto.subtract = duration_add_subtract__subtract;
  34859. duration_prototype__proto.as = as;
  34860. duration_prototype__proto.asMilliseconds = asMilliseconds;
  34861. duration_prototype__proto.asSeconds = asSeconds;
  34862. duration_prototype__proto.asMinutes = asMinutes;
  34863. duration_prototype__proto.asHours = asHours;
  34864. duration_prototype__proto.asDays = asDays;
  34865. duration_prototype__proto.asWeeks = asWeeks;
  34866. duration_prototype__proto.asMonths = asMonths;
  34867. duration_prototype__proto.asYears = asYears;
  34868. duration_prototype__proto.valueOf = duration_as__valueOf;
  34869. duration_prototype__proto._bubble = bubble;
  34870. duration_prototype__proto.get = duration_get__get;
  34871. duration_prototype__proto.milliseconds = milliseconds;
  34872. duration_prototype__proto.seconds = seconds;
  34873. duration_prototype__proto.minutes = minutes;
  34874. duration_prototype__proto.hours = hours;
  34875. duration_prototype__proto.days = days;
  34876. duration_prototype__proto.weeks = weeks;
  34877. duration_prototype__proto.months = months;
  34878. duration_prototype__proto.years = years;
  34879. duration_prototype__proto.humanize = humanize;
  34880. duration_prototype__proto.toISOString = iso_string__toISOString;
  34881. duration_prototype__proto.toString = iso_string__toISOString;
  34882. duration_prototype__proto.toJSON = iso_string__toISOString;
  34883. duration_prototype__proto.locale = locale;
  34884. duration_prototype__proto.localeData = localeData;
  34885. // Deprecations
  34886. duration_prototype__proto.toIsoString = deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', iso_string__toISOString);
  34887. duration_prototype__proto.lang = lang;
  34888. // Side effect imports
  34889. // FORMATTING
  34890. addFormatToken('X', 0, 0, 'unix');
  34891. addFormatToken('x', 0, 0, 'valueOf');
  34892. // PARSING
  34893. addRegexToken('x', matchSigned);
  34894. addRegexToken('X', matchTimestamp);
  34895. addParseToken('X', function (input, array, config) {
  34896. config._d = new Date(parseFloat(input, 10) * 1000);
  34897. });
  34898. addParseToken('x', function (input, array, config) {
  34899. config._d = new Date(toInt(input));
  34900. });
  34901. // Side effect imports
  34902. utils_hooks__hooks.version = '2.13.0';
  34903. setHookCallback(local__createLocal);
  34904. utils_hooks__hooks.fn = momentPrototype;
  34905. utils_hooks__hooks.min = min;
  34906. utils_hooks__hooks.max = max;
  34907. utils_hooks__hooks.now = now;
  34908. utils_hooks__hooks.utc = create_utc__createUTC;
  34909. utils_hooks__hooks.unix = moment__createUnix;
  34910. utils_hooks__hooks.months = lists__listMonths;
  34911. utils_hooks__hooks.isDate = isDate;
  34912. utils_hooks__hooks.locale = locale_locales__getSetGlobalLocale;
  34913. utils_hooks__hooks.invalid = valid__createInvalid;
  34914. utils_hooks__hooks.duration = create__createDuration;
  34915. utils_hooks__hooks.isMoment = isMoment;
  34916. utils_hooks__hooks.weekdays = lists__listWeekdays;
  34917. utils_hooks__hooks.parseZone = moment__createInZone;
  34918. utils_hooks__hooks.localeData = locale_locales__getLocale;
  34919. utils_hooks__hooks.isDuration = isDuration;
  34920. utils_hooks__hooks.monthsShort = lists__listMonthsShort;
  34921. utils_hooks__hooks.weekdaysMin = lists__listWeekdaysMin;
  34922. utils_hooks__hooks.defineLocale = defineLocale;
  34923. utils_hooks__hooks.updateLocale = updateLocale;
  34924. utils_hooks__hooks.locales = locale_locales__listLocales;
  34925. utils_hooks__hooks.weekdaysShort = lists__listWeekdaysShort;
  34926. utils_hooks__hooks.normalizeUnits = normalizeUnits;
  34927. utils_hooks__hooks.relativeTimeThreshold = duration_humanize__getSetRelativeTimeThreshold;
  34928. utils_hooks__hooks.prototype = momentPrototype;
  34929. var _moment = utils_hooks__hooks;
  34930. return _moment;
  34931. }));
  34932. },{}],104:[function(require,module,exports){
  34933. (function (process){
  34934. // Copyright Joyent, Inc. and other Node contributors.
  34935. //
  34936. // Permission is hereby granted, free of charge, to any person obtaining a
  34937. // copy of this software and associated documentation files (the
  34938. // "Software"), to deal in the Software without restriction, including
  34939. // without limitation the rights to use, copy, modify, merge, publish,
  34940. // distribute, sublicense, and/or sell copies of the Software, and to permit
  34941. // persons to whom the Software is furnished to do so, subject to the
  34942. // following conditions:
  34943. //
  34944. // The above copyright notice and this permission notice shall be included
  34945. // in all copies or substantial portions of the Software.
  34946. //
  34947. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  34948. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  34949. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  34950. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  34951. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  34952. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  34953. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  34954. // resolves . and .. elements in a path array with directory names there
  34955. // must be no slashes, empty elements, or device names (c:\) in the array
  34956. // (so also no leading and trailing slashes - it does not distinguish
  34957. // relative and absolute paths)
  34958. function normalizeArray(parts, allowAboveRoot) {
  34959. // if the path tries to go above the root, `up` ends up > 0
  34960. var up = 0;
  34961. for (var i = parts.length - 1; i >= 0; i--) {
  34962. var last = parts[i];
  34963. if (last === '.') {
  34964. parts.splice(i, 1);
  34965. } else if (last === '..') {
  34966. parts.splice(i, 1);
  34967. up++;
  34968. } else if (up) {
  34969. parts.splice(i, 1);
  34970. up--;
  34971. }
  34972. }
  34973. // if the path is allowed to go above the root, restore leading ..s
  34974. if (allowAboveRoot) {
  34975. for (; up--; up) {
  34976. parts.unshift('..');
  34977. }
  34978. }
  34979. return parts;
  34980. }
  34981. // Split a filename into [root, dir, basename, ext], unix version
  34982. // 'root' is just a slash, or nothing.
  34983. var splitPathRe =
  34984. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  34985. var splitPath = function(filename) {
  34986. return splitPathRe.exec(filename).slice(1);
  34987. };
  34988. // path.resolve([from ...], to)
  34989. // posix version
  34990. exports.resolve = function() {
  34991. var resolvedPath = '',
  34992. resolvedAbsolute = false;
  34993. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  34994. var path = (i >= 0) ? arguments[i] : process.cwd();
  34995. // Skip empty and invalid entries
  34996. if (typeof path !== 'string') {
  34997. throw new TypeError('Arguments to path.resolve must be strings');
  34998. } else if (!path) {
  34999. continue;
  35000. }
  35001. resolvedPath = path + '/' + resolvedPath;
  35002. resolvedAbsolute = path.charAt(0) === '/';
  35003. }
  35004. // At this point the path should be resolved to a full absolute path, but
  35005. // handle relative paths to be safe (might happen when process.cwd() fails)
  35006. // Normalize the path
  35007. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  35008. return !!p;
  35009. }), !resolvedAbsolute).join('/');
  35010. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  35011. };
  35012. // path.normalize(path)
  35013. // posix version
  35014. exports.normalize = function(path) {
  35015. var isAbsolute = exports.isAbsolute(path),
  35016. trailingSlash = substr(path, -1) === '/';
  35017. // Normalize the path
  35018. path = normalizeArray(filter(path.split('/'), function(p) {
  35019. return !!p;
  35020. }), !isAbsolute).join('/');
  35021. if (!path && !isAbsolute) {
  35022. path = '.';
  35023. }
  35024. if (path && trailingSlash) {
  35025. path += '/';
  35026. }
  35027. return (isAbsolute ? '/' : '') + path;
  35028. };
  35029. // posix version
  35030. exports.isAbsolute = function(path) {
  35031. return path.charAt(0) === '/';
  35032. };
  35033. // posix version
  35034. exports.join = function() {
  35035. var paths = Array.prototype.slice.call(arguments, 0);
  35036. return exports.normalize(filter(paths, function(p, index) {
  35037. if (typeof p !== 'string') {
  35038. throw new TypeError('Arguments to path.join must be strings');
  35039. }
  35040. return p;
  35041. }).join('/'));
  35042. };
  35043. // path.relative(from, to)
  35044. // posix version
  35045. exports.relative = function(from, to) {
  35046. from = exports.resolve(from).substr(1);
  35047. to = exports.resolve(to).substr(1);
  35048. function trim(arr) {
  35049. var start = 0;
  35050. for (; start < arr.length; start++) {
  35051. if (arr[start] !== '') break;
  35052. }
  35053. var end = arr.length - 1;
  35054. for (; end >= 0; end--) {
  35055. if (arr[end] !== '') break;
  35056. }
  35057. if (start > end) return [];
  35058. return arr.slice(start, end - start + 1);
  35059. }
  35060. var fromParts = trim(from.split('/'));
  35061. var toParts = trim(to.split('/'));
  35062. var length = Math.min(fromParts.length, toParts.length);
  35063. var samePartsLength = length;
  35064. for (var i = 0; i < length; i++) {
  35065. if (fromParts[i] !== toParts[i]) {
  35066. samePartsLength = i;
  35067. break;
  35068. }
  35069. }
  35070. var outputParts = [];
  35071. for (var i = samePartsLength; i < fromParts.length; i++) {
  35072. outputParts.push('..');
  35073. }
  35074. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  35075. return outputParts.join('/');
  35076. };
  35077. exports.sep = '/';
  35078. exports.delimiter = ':';
  35079. exports.dirname = function(path) {
  35080. var result = splitPath(path),
  35081. root = result[0],
  35082. dir = result[1];
  35083. if (!root && !dir) {
  35084. // No dirname whatsoever
  35085. return '.';
  35086. }
  35087. if (dir) {
  35088. // It has a dirname, strip trailing slash
  35089. dir = dir.substr(0, dir.length - 1);
  35090. }
  35091. return root + dir;
  35092. };
  35093. exports.basename = function(path, ext) {
  35094. var f = splitPath(path)[2];
  35095. // TODO: make this comparison case-insensitive on windows?
  35096. if (ext && f.substr(-1 * ext.length) === ext) {
  35097. f = f.substr(0, f.length - ext.length);
  35098. }
  35099. return f;
  35100. };
  35101. exports.extname = function(path) {
  35102. return splitPath(path)[3];
  35103. };
  35104. function filter (xs, f) {
  35105. if (xs.filter) return xs.filter(f);
  35106. var res = [];
  35107. for (var i = 0; i < xs.length; i++) {
  35108. if (f(xs[i], i, xs)) res.push(xs[i]);
  35109. }
  35110. return res;
  35111. }
  35112. // String.prototype.substr - negative index don't work in IE8
  35113. var substr = 'ab'.substr(-1) === 'b'
  35114. ? function (str, start, len) { return str.substr(start, len) }
  35115. : function (str, start, len) {
  35116. if (start < 0) start = str.length + start;
  35117. return str.substr(start, len);
  35118. }
  35119. ;
  35120. }).call(this,require('_process'))
  35121. },{"_process":105}],105:[function(require,module,exports){
  35122. // shim for using process in browser
  35123. var process = module.exports = {};
  35124. process.nextTick = (function () {
  35125. var canSetImmediate = typeof window !== 'undefined'
  35126. && window.setImmediate;
  35127. var canMutationObserver = typeof window !== 'undefined'
  35128. && window.MutationObserver;
  35129. var canPost = typeof window !== 'undefined'
  35130. && window.postMessage && window.addEventListener
  35131. ;
  35132. if (canSetImmediate) {
  35133. return function (f) { return window.setImmediate(f) };
  35134. }
  35135. var queue = [];
  35136. if (canMutationObserver) {
  35137. var hiddenDiv = document.createElement("div");
  35138. var observer = new MutationObserver(function () {
  35139. var queueList = queue.slice();
  35140. queue.length = 0;
  35141. queueList.forEach(function (fn) {
  35142. fn();
  35143. });
  35144. });
  35145. observer.observe(hiddenDiv, { attributes: true });
  35146. return function nextTick(fn) {
  35147. if (!queue.length) {
  35148. hiddenDiv.setAttribute('yes', 'no');
  35149. }
  35150. queue.push(fn);
  35151. };
  35152. }
  35153. if (canPost) {
  35154. window.addEventListener('message', function (ev) {
  35155. var source = ev.source;
  35156. if ((source === window || source === null) && ev.data === 'process-tick') {
  35157. ev.stopPropagation();
  35158. if (queue.length > 0) {
  35159. var fn = queue.shift();
  35160. fn();
  35161. }
  35162. }
  35163. }, true);
  35164. return function nextTick(fn) {
  35165. queue.push(fn);
  35166. window.postMessage('process-tick', '*');
  35167. };
  35168. }
  35169. return function nextTick(fn) {
  35170. setTimeout(fn, 0);
  35171. };
  35172. })();
  35173. process.title = 'browser';
  35174. process.browser = true;
  35175. process.env = {};
  35176. process.argv = [];
  35177. function noop() {}
  35178. process.on = noop;
  35179. process.addListener = noop;
  35180. process.once = noop;
  35181. process.off = noop;
  35182. process.removeListener = noop;
  35183. process.removeAllListeners = noop;
  35184. process.emit = noop;
  35185. process.binding = function (name) {
  35186. throw new Error('process.binding is not supported');
  35187. };
  35188. // TODO(shtylman)
  35189. process.cwd = function () { return '/' };
  35190. process.chdir = function (dir) {
  35191. throw new Error('process.chdir is not supported');
  35192. };
  35193. },{}],106:[function(require,module,exports){
  35194. module.exports= {
  35195. "name": "mermaid",
  35196. "version": "7.0.0",
  35197. "description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams and gantt charts.",
  35198. "main": "src/mermaid.js",
  35199. "keywords": [
  35200. "diagram",
  35201. "markdown",
  35202. "flowchart",
  35203. "sequence diagram",
  35204. "gantt"
  35205. ],
  35206. "bin": {
  35207. "mermaid": "./bin/mermaid.js"
  35208. },
  35209. "scripts": {
  35210. "live": "live-server ./test/examples",
  35211. "lint": "node node_modules/eslint/bin/eslint.js src",
  35212. "jison": "gulp jison_legacy",
  35213. "karma": "node node_modules/karma/bin/karma start karma.conf.js --single-run",
  35214. "watch": "source ./scripts/watch.sh",
  35215. "doc": "rm -r build;rm -r dist/www;gulp vartree;cp dist/www/all.html ../mermaid-pages/index.html;cp dist/mermaid.js ../mermaid-pages/javascripts/lib;cp dist/mermaid.forest.css ../mermaid-pages/stylesheets",
  35216. "tape": "node node_modules/tape/bin/tape test/cli_test-*.js",
  35217. "jasmine": "npm run jison &&node node_modules/jasmine-es6/bin/jasmine.js",
  35218. "pretest": "npm run jison",
  35219. "test": "npm run dist && npm run karma && npm run tape",
  35220. "dist-slim-mermaid": "node node_modules/browserify/bin/cmd.js src/mermaid.js -t babelify -s mermaid -o dist/mermaid.slim.js -x d3 && cat dist/mermaid.slim.js | node node_modules/uglifyjs/bin/uglifyjs -mc > dist/mermaid.slim.min.js",
  35221. "dist-slim-mermaidAPI": "node node_modules/browserify/bin/cmd.js src/mermaidAPI.js -t babelify -s mermaidAPI -o dist/mermaidAPI.slim.js -x d3 && cat dist/mermaidAPI.slim.js | node node_modules/uglifyjs/bin/uglifyjs -mc > dist/mermaidAPI.slim.min.js",
  35222. "dist-mermaid": "node node_modules/browserify/bin/cmd.js src/mermaid.js -t babelify -s mermaid -o dist/mermaid.js && cat dist/mermaid.js | node node_modules/uglifyjs/bin/uglifyjs -mc > dist/mermaid.min.js",
  35223. "dist-mermaid-nomin": "node node_modules/browserify/bin/cmd.js src/mermaid.js -t babelify -s mermaid -o dist/mermaid.js",
  35224. "dist-mermaidAPI": "node node_modules/browserify/bin/cmd.js src/mermaidAPI.js -t babelify -s mermaidAPI -o dist/mermaidAPI.js && cat dist/mermaidAPI.js | node node_modules/uglifyjs/bin/uglifyjs -mc > dist/mermaidAPI.min.js",
  35225. "dist": "npm run dist-slim-mermaid && npm run dist-slim-mermaidAPI && npm run dist-mermaid && npm run dist-mermaidAPI"
  35226. },
  35227. "repository": {
  35228. "type": "git",
  35229. "url": "https://github.com/knsv/mermaid"
  35230. },
  35231. "author": "Knut Sveidqvist",
  35232. "license": "MIT",
  35233. "dependencies": {
  35234. "chalk": "^0.5.1",
  35235. "d3": "3.5.6",
  35236. "dagre": "^0.7.4",
  35237. "dagre-d3": "0.4.10",
  35238. "he": "^0.5.0",
  35239. "lodash": "^4.6.1",
  35240. "minimist": "^1.1.0",
  35241. "mkdirp": "^0.5.0",
  35242. "moment": "^2.9.0",
  35243. "semver": "^4.1.1",
  35244. "which": "^1.0.8"
  35245. },
  35246. "devDependencies": {
  35247. "async": "^0.9.0",
  35248. "babel-eslint": "^4.1.3",
  35249. "babelify": "^6.4.0",
  35250. "browserify": "~6.2.0",
  35251. "clone": "^0.2.0",
  35252. "codeclimate-test-reporter": "0.0.4",
  35253. "dateformat": "^1.0.11",
  35254. "dox": "^0.8.0",
  35255. "eslint": "^1.6.0",
  35256. "eslint-watch": "^2.1.2",
  35257. "event-stream": "^3.2.0",
  35258. "foundation": "^4.2.1-1",
  35259. "front-matter": "^0.2.0",
  35260. "gulp": "~3.9.0",
  35261. "gulp-bower": "0.0.10",
  35262. "gulp-browserify": "^0.5.0",
  35263. "gulp-bump": "^0.1.11",
  35264. "gulp-concat": "~2.4.1",
  35265. "gulp-data": "^1.1.1",
  35266. "gulp-dox": "^0.1.6",
  35267. "gulp-ext-replace": "^0.2.0",
  35268. "gulp-filelog": "^0.4.1",
  35269. "gulp-front-matter": "^1.2.3",
  35270. "gulp-hogan": "^1.1.0",
  35271. "gulp-if": "^1.2.5",
  35272. "gulp-insert": "^0.4.0",
  35273. "gulp-istanbul": "^0.4.0",
  35274. "gulp-jasmine": "~2.1.0",
  35275. "gulp-jasmine-browser": "^0.2.3",
  35276. "gulp-jison": "~1.2.0",
  35277. "gulp-jshint": "^1.9.0",
  35278. "gulp-less": "^3.0.1",
  35279. "gulp-livereload": "^3.8.0",
  35280. "gulp-marked": "^1.0.0",
  35281. "gulp-mdvars": "^2.0.0",
  35282. "gulp-qunit": "~1.2.1",
  35283. "gulp-rename": "~1.2.0",
  35284. "gulp-shell": "^0.2.10",
  35285. "gulp-tag-version": "^1.2.1",
  35286. "gulp-uglify": "~1.0.1",
  35287. "gulp-util": "^3.0.7",
  35288. "gulp-vartree": "^2.0.1",
  35289. "hogan.js": "^3.0.2",
  35290. "jasmine": "2.3.2",
  35291. "jasmine-es6": "0.0.18",
  35292. "jison": "zaach/jison",
  35293. "jsdom": "^7.0.2",
  35294. "jshint-stylish": "^2.0.1",
  35295. "karma": "^0.13.15",
  35296. "karma-babel-preprocessor": "^6.0.1",
  35297. "karma-browserify": "^4.4.0",
  35298. "karma-jasmine": "^0.3.6",
  35299. "karma-phantomjs-launcher": "^0.2.1",
  35300. "live-server": "^0.9.0",
  35301. "map-stream": "0.0.6",
  35302. "marked": "^0.3.2",
  35303. "mock-browser": "^0.91.34",
  35304. "path": "^0.4.9",
  35305. "phantomjs": "^2.1.3",
  35306. "proxyquire": "^1.7.3",
  35307. "proxyquire-universal": "^1.0.8",
  35308. "proxyquireify": "^3.0.0",
  35309. "require-dir": "^0.3.0",
  35310. "rewire": "^2.1.3",
  35311. "rimraf": "^2.2.8",
  35312. "tape": "^3.0.3",
  35313. "testdom": "^2.0.0",
  35314. "uglifyjs": "^2.4.10",
  35315. "vinyl-source-stream": "^1.1.0",
  35316. "watchify": "^3.6.1"
  35317. }
  35318. }
  35319. },{}],107:[function(require,module,exports){
  35320. /* global window */
  35321. //log.debug('Setting up d3');
  35322. 'use strict';
  35323. var d3;
  35324. if (typeof require !== 'undefined') {
  35325. try {
  35326. d3 = require('d3');
  35327. } catch (e) {
  35328. //log.debug('Exception ... but ok');
  35329. //log.debug(e);
  35330. }
  35331. }
  35332. //log.debug(d3);
  35333. if (!d3) {
  35334. //if(typeof window !== 'undefined')
  35335. d3 = window.d3;
  35336. }
  35337. //if(typeof window === 'undefined'){
  35338. // window = {};
  35339. // window.d3 = d3;
  35340. //}
  35341. //log.debug('window');
  35342. //log.debug(window);
  35343. module.exports = d3;
  35344. /* jshint ignore:start */
  35345. /*
  35346. D3 Text Wrap
  35347. By Vijith Assar
  35348. http://www.vijithassar.com
  35349. http://www.github.com/vijithassar
  35350. @vijithassar
  35351. Detailed instructions at http://www.github.com/vijithassar/d3textwrap
  35352. */
  35353. (function () {
  35354. // set this variable to a string value to always force a particular
  35355. // wrap method for development purposes, for example to check tspan
  35356. // rendering using a foreignobject-enabled browser. set to 'tspan' to
  35357. // use tspans and 'foreignobject' to use foreignobject
  35358. var force_wrap_method = false; // by default no wrap method is forced
  35359. force_wrap_method = 'tspans'; // uncomment this statement to force tspans
  35360. // force_wrap_method = 'foreignobjects'; // uncomment this statement to force foreignobjects
  35361. // exit immediately if something in this location
  35362. // has already been defined; the plugin will defer to whatever
  35363. // else you're doing in your code
  35364. if (d3.selection.prototype.textwrap) {
  35365. return false;
  35366. }
  35367. // double check the force_wrap_method flag
  35368. // and reset if someone screwed up the above
  35369. // settings
  35370. if (typeof force_wrap_method == 'undefined') {
  35371. var force_wrap_method = false;
  35372. }
  35373. // create the plugin method twice, both for regular use
  35374. // and again for use inside the enter() selection
  35375. d3.selection.prototype.textwrap = d3.selection.enter.prototype.textwrap = function (bounds, padding) {
  35376. // default value of padding is zero if it's undefined
  35377. var padding = parseInt(padding) || 0;
  35378. // save callee into a variable so we can continue to refer to it
  35379. // as the function scope changes
  35380. var selection = this;
  35381. // create a variable to store desired return values in
  35382. var return_value;
  35383. // extract wrap boundaries from any d3-selected rect and return them
  35384. // in a format that matches the simpler object argument option
  35385. var extract_bounds = function extract_bounds(bounds) {
  35386. // discard the nested array wrappers added by d3
  35387. var bounding_rect = bounds[0][0];
  35388. // sanitize the svg element name so we can test against it
  35389. var element_type = bounding_rect.tagName.toString();
  35390. // if it's not a rect, exit
  35391. if (element_type !== 'rect') {
  35392. return false;
  35393. // if it's a rect, proceed to extracting the position attributes
  35394. } else {
  35395. var bounds_extracted = {};
  35396. bounds_extracted.x = d3.select(bounding_rect).attr('x') || 0;
  35397. bounds_extracted.y = d3.select(bounding_rect).attr('y') || 0;
  35398. bounds_extracted.width = d3.select(bounding_rect).attr('width') || 0;
  35399. bounds_extracted.height = d3.select(bounding_rect).attr('height') || 0;
  35400. // also pass along the getter function
  35401. bounds_extracted.attr = bounds.attr;
  35402. }
  35403. return bounds_extracted;
  35404. };
  35405. // double check the input argument for the wrapping
  35406. // boundaries to make sure it actually contains all
  35407. // the information we'll need in order to wrap successfully
  35408. var verify_bounds = function verify_bounds(bounds) {
  35409. // quickly add a simple getter method so you can use either
  35410. // bounds.x or bounds.attr('x') as your notation,
  35411. // the latter being a common convention among D3
  35412. // developers
  35413. if (!bounds.attr) {
  35414. bounds.attr = function (property) {
  35415. if (this[property]) {
  35416. return this[property];
  35417. }
  35418. };
  35419. }
  35420. // if it's an associative array, make sure it has all the
  35421. // necessary properties represented directly
  35422. if (typeof bounds == 'object' && typeof bounds.x !== 'undefined' && typeof bounds.y !== 'undefined' && typeof bounds.width !== 'undefined' && typeof bounds.height !== 'undefined'
  35423. // if that's the case, then the bounds are fine
  35424. ) {
  35425. // return the lightly modified bounds
  35426. return bounds;
  35427. // if it's a numerically indexed array, assume it's a
  35428. // d3-selected rect and try to extract the positions
  35429. } else if (
  35430. // first try to make sure it's an array using Array.isArray
  35431. typeof Array.isArray == 'function' && Array.isArray(bounds) ||
  35432. // but since Array.isArray isn't always supported, fall
  35433. // back to casting to the object to string when it's not
  35434. Object.prototype.toString.call(bounds) === '[object Array]') {
  35435. // once you're sure it's an array, extract the boundaries
  35436. // from the rect
  35437. var extracted_bounds = extract_bounds(bounds);
  35438. return extracted_bounds;
  35439. } else {
  35440. // but if the bounds are neither an object nor a numerical
  35441. // array, then the bounds argument is invalid and you'll
  35442. // need to fix it
  35443. return false;
  35444. }
  35445. };
  35446. var apply_padding = function apply_padding(bounds, padding) {
  35447. var padded_bounds = bounds;
  35448. if (padding !== 0) {
  35449. padded_bounds.x = parseInt(padded_bounds.x) + padding;
  35450. padded_bounds.y = parseInt(padded_bounds.y) + padding;
  35451. padded_bounds.width -= padding * 2;
  35452. padded_bounds.height -= padding * 2;
  35453. }
  35454. return padded_bounds;
  35455. };
  35456. // verify bounds
  35457. var verified_bounds = verify_bounds(bounds);
  35458. // modify bounds if a padding value is provided
  35459. if (padding) {
  35460. verified_bounds = apply_padding(verified_bounds, padding);
  35461. }
  35462. // check that we have the necessary conditions for this function to operate properly
  35463. if (
  35464. // selection it's operating on cannot be not empty
  35465. selection.length == 0 ||
  35466. // d3 must be available
  35467. !d3 ||
  35468. // desired wrapping bounds must be provided as an input argument
  35469. !bounds ||
  35470. // input bounds must validate
  35471. !verified_bounds) {
  35472. // try to return the calling selection if possible
  35473. // so as not to interfere with methods downstream in the
  35474. // chain
  35475. if (selection) {
  35476. return selection;
  35477. // if all else fails, just return false. if you hit this point then you're
  35478. // almost certainly trying to call the textwrap() method on something that
  35479. // doesn't make sense!
  35480. } else {
  35481. return false;
  35482. }
  35483. // if we've validated everything then we can finally proceed
  35484. // to the meat of this operation
  35485. } else {
  35486. // reassign the verified bounds as the set we want
  35487. // to work with from here on; this ensures that we're
  35488. // using the same data structure for our bounds regardless
  35489. // of whether the input argument was a simple object or
  35490. // a d3 selection
  35491. bounds = verified_bounds;
  35492. // wrap using html and foreignObjects if they are supported
  35493. var wrap_with_foreignobjects = function wrap_with_foreignobjects(item) {
  35494. // establish variables to quickly reference target nodes later
  35495. var parent = d3.select(item[0].parentNode);
  35496. var text_node = parent.select('text');
  35497. var styled_line_height = text_node.style('line-height');
  35498. // extract our desired content from the single text element
  35499. var text_to_wrap = text_node.text();
  35500. // remove the text node and replace with a foreign object
  35501. text_node.remove();
  35502. var foreign_object = parent.append('foreignObject');
  35503. // add foreign object and set dimensions, position, etc
  35504. foreign_object.attr('requiredFeatures', 'http://www.w3.org/TR/SVG11/feature#Extensibility').attr('x', bounds.x).attr('y', bounds.y).attr('width', bounds.width).attr('height', bounds.height);
  35505. // insert an HTML div
  35506. var wrap_div = foreign_object.append('xhtml:div')
  35507. // this class is currently hardcoded
  35508. // probably not necessary but easy to
  35509. // override using .classed() and for now
  35510. // it's nice to avoid a litany of input
  35511. // arguments
  35512. .attr('class', 'wrapped');
  35513. // set div to same dimensions as foreign object
  35514. wrap_div.style('height', bounds.height).style('width', bounds.width)
  35515. // insert text content
  35516. .html(text_to_wrap);
  35517. if (styled_line_height) {
  35518. wrap_div.style('line-height', styled_line_height);
  35519. }
  35520. return_value = parent.select('foreignObject');
  35521. };
  35522. // wrap with tspans if foreignObject is undefined
  35523. var wrap_with_tspans = function wrap_with_tspans(item) {
  35524. // operate on the first text item in the selection
  35525. var text_node = item[0];
  35526. var parent = text_node.parentNode;
  35527. var text_node_selected = d3.select(text_node);
  35528. // measure initial size of the text node as rendered
  35529. var text_node_height = text_node.getBBox().height;
  35530. var text_node_width = text_node.getBBox().width;
  35531. // figure out the line height, either from rendered height
  35532. // of the font or attached styling
  35533. var line_height;
  35534. var rendered_line_height = text_node_height;
  35535. var styled_line_height = text_node_selected.style('line-height');
  35536. if (styled_line_height && parseInt(styled_line_height)) {
  35537. line_height = parseInt(styled_line_height.replace('px', ''));
  35538. } else {
  35539. line_height = rendered_line_height;
  35540. }
  35541. // only fire the rest of this if the text content
  35542. // overflows the desired dimensions
  35543. if (text_node_width > bounds.width) {
  35544. // store whatever is inside the text node
  35545. // in a variable and then zero out the
  35546. // initial content; we'll reinsert in a moment
  35547. // using tspan elements.
  35548. var text_to_wrap = text_node_selected.text();
  35549. text_node_selected.text('');
  35550. if (text_to_wrap) {
  35551. // keep track of whether we are splitting by spaces
  35552. // so we know whether to reinsert those spaces later
  35553. var break_delimiter;
  35554. // split at spaces to create an array of individual words
  35555. var text_to_wrap_array;
  35556. if (text_to_wrap.indexOf(' ') !== -1) {
  35557. var break_delimiter = ' ';
  35558. text_to_wrap_array = text_to_wrap.split(' ');
  35559. } else {
  35560. // if there are no spaces, figure out the split
  35561. // points by comparing rendered text width against
  35562. // bounds and translating that into character position
  35563. // cuts
  35564. break_delimiter = '';
  35565. var string_length = text_to_wrap.length;
  35566. var number_of_substrings = Math.ceil(text_node_width / bounds.width);
  35567. var splice_interval = Math.floor(string_length / number_of_substrings);
  35568. if (!(splice_interval * number_of_substrings >= string_length)) {
  35569. number_of_substrings++;
  35570. }
  35571. var text_to_wrap_array = [];
  35572. var substring;
  35573. var start_position;
  35574. for (var i = 0; i < number_of_substrings; i++) {
  35575. start_position = i * splice_interval;
  35576. substring = text_to_wrap.substr(start_position, splice_interval);
  35577. text_to_wrap_array.push(substring);
  35578. }
  35579. }
  35580. // new array where we'll store the words re-assembled into
  35581. // substrings that have been tested against the desired
  35582. // maximum wrapping width
  35583. var substrings = [];
  35584. // computed text length is arguably incorrectly reported for
  35585. // all tspans after the first one, in that they will include
  35586. // the width of previous separate tspans. to compensate we need
  35587. // to manually track the computed text length of all those
  35588. // previous tspans and substrings, and then use that to offset
  35589. // the miscalculation. this then gives us the actual correct
  35590. // position we want to use in rendering the text in the SVG.
  35591. var total_offset = 0;
  35592. // object for storing the results of text length computations later
  35593. var temp = {};
  35594. // loop through the words and test the computed text length
  35595. // of the string against the maximum desired wrapping width
  35596. for (var i = 0; i < text_to_wrap_array.length; i++) {
  35597. var word = text_to_wrap_array[i];
  35598. var previous_string = text_node_selected.text();
  35599. var previous_width = text_node.getComputedTextLength();
  35600. // initialize the current word as the first word
  35601. // or append to the previous string if one exists
  35602. var new_string;
  35603. if (previous_string) {
  35604. new_string = previous_string + break_delimiter + word;
  35605. } else {
  35606. new_string = word;
  35607. }
  35608. // add the newest substring back to the text node and
  35609. // measure the length
  35610. text_node_selected.text(new_string);
  35611. var new_width = text_node.getComputedTextLength();
  35612. // adjust the length by the offset we've tracked
  35613. // due to the misreported length discussed above
  35614. var test_width = new_width - total_offset;
  35615. // if our latest version of the string is too
  35616. // big for the bounds, use the previous
  35617. // version of the string (without the newest word
  35618. // added) and use the latest word to restart the
  35619. // process with a new tspan
  35620. if (new_width > bounds.width) {
  35621. if (previous_string && previous_string !== '') {
  35622. total_offset = total_offset + previous_width;
  35623. temp = { string: previous_string, width: previous_width, offset: total_offset };
  35624. substrings.push(temp);
  35625. text_node_selected.text('');
  35626. text_node_selected.text(word);
  35627. // Handle case where there is just one more word to be wrapped
  35628. if (i == text_to_wrap_array.length - 1) {
  35629. new_string = word;
  35630. text_node_selected.text(new_string);
  35631. new_width = text_node.getComputedTextLength();
  35632. }
  35633. }
  35634. }
  35635. // if we're up to the last word in the array,
  35636. // get the computed length as is without
  35637. // appending anything further to it
  35638. if (i == text_to_wrap_array.length - 1) {
  35639. text_node_selected.text('');
  35640. var final_string = new_string;
  35641. if (final_string && final_string !== '') {
  35642. if (new_width - total_offset > 0) {
  35643. new_width = new_width - total_offset;
  35644. }
  35645. temp = { string: final_string, width: new_width, offset: total_offset };
  35646. substrings.push(temp);
  35647. }
  35648. }
  35649. }
  35650. // append each substring as a tspan
  35651. var current_tspan;
  35652. var tspan_count;
  35653. // double check that the text content has been removed
  35654. // before we start appending tspans
  35655. text_node_selected.text('');
  35656. for (var i = 0; i < substrings.length; i++) {
  35657. var substring = substrings[i].string;
  35658. if (i > 0) {
  35659. var previous_substring = substrings[i - 1];
  35660. }
  35661. // only append if we're sure it won't make the tspans
  35662. // overflow the bounds.
  35663. if (i * line_height < bounds.height - line_height * 1.5) {
  35664. current_tspan = text_node_selected.append('tspan').text(substring);
  35665. // vertical shift to all tspans after the first one
  35666. current_tspan.attr('dy', function (d) {
  35667. if (i > 0) {
  35668. return line_height;
  35669. }
  35670. });
  35671. // shift left from default position, which
  35672. // is probably based on the full length of the
  35673. // text string until we make this adjustment
  35674. current_tspan.attr('x', function () {
  35675. var x_offset = bounds.x;
  35676. if (padding) {
  35677. x_offset += padding;
  35678. }
  35679. return x_offset;
  35680. });
  35681. // .attr('dx', function() {
  35682. // if(i == 0) {
  35683. // var render_offset = 0;
  35684. // } else if(i > 0) {
  35685. // render_offset = substrings[i - 1].width;
  35686. // render_offset = render_offset * -1;
  35687. // }
  35688. // return render_offset;
  35689. // });
  35690. }
  35691. }
  35692. }
  35693. }
  35694. // position the overall text node, whether wrapped or not
  35695. text_node_selected.attr('y', function () {
  35696. var y_offset = bounds.y;
  35697. // shift by line-height to move the baseline into
  35698. // the bounds – otherwise the text baseline would be
  35699. // at the top of the bounds
  35700. if (line_height) {
  35701. y_offset += line_height;
  35702. }
  35703. // shift by padding, if it's there
  35704. if (padding) {
  35705. y_offset += padding;
  35706. }
  35707. return y_offset;
  35708. });
  35709. // shift to the right by the padding value
  35710. text_node_selected.attr('x', function () {
  35711. var x_offset = bounds.x;
  35712. if (padding) {
  35713. x_offset += padding;
  35714. }
  35715. return x_offset;
  35716. });
  35717. // assign our modified text node with tspans
  35718. // to the return value
  35719. return_value = d3.select(parent).selectAll('text');
  35720. };
  35721. // variable used to hold the functions that let us
  35722. // switch between the wrap methods
  35723. var wrap_method;
  35724. // if a wrap method if being forced, assign that
  35725. // function
  35726. if (force_wrap_method) {
  35727. if (force_wrap_method == 'foreignobjects') {
  35728. wrap_method = wrap_with_foreignobjects;
  35729. } else if (force_wrap_method == 'tspans') {
  35730. wrap_method = wrap_with_tspans;
  35731. }
  35732. }
  35733. // if no wrap method is being forced, then instead
  35734. // test for browser support of foreignobject and
  35735. // use whichever wrap method makes sense accordingly
  35736. if (!force_wrap_method) {
  35737. if (typeof SVGForeignObjectElement !== 'undefined') {
  35738. wrap_method = wrap_with_foreignobjects;
  35739. } else {
  35740. wrap_method = wrap_with_tspans;
  35741. }
  35742. }
  35743. // run the desired wrap function for each item
  35744. // in the d3 selection that called .textwrap()
  35745. for (var i = 0; i < selection.length; i++) {
  35746. var item = selection[i];
  35747. wrap_method(item);
  35748. }
  35749. // return the modified nodes so we can chain other
  35750. // methods to them.
  35751. return return_value;
  35752. }
  35753. };
  35754. })();
  35755. /* jshint ignore:end */
  35756. },{"d3":"d3"}],108:[function(require,module,exports){
  35757. 'use strict';
  35758. var Logger = require('../../logger');
  35759. var log = new Logger.Log();
  35760. var relations = [];
  35761. var classes;
  35762. var idCache;
  35763. classes = {};
  35764. // Functions to be run after graph rendering
  35765. var funs = [];
  35766. /**
  35767. * Function called by parser when a node definition has been found.
  35768. * @param id
  35769. * @param text
  35770. * @param type
  35771. * @param style
  35772. */
  35773. exports.addClass = function (id) {
  35774. if (typeof classes[id] === 'undefined') {
  35775. classes[id] = {
  35776. id: id,
  35777. methods: [],
  35778. members: []
  35779. };
  35780. }
  35781. };
  35782. exports.clear = function () {
  35783. relations = [];
  35784. classes = {};
  35785. };
  35786. module.exports.getClass = function (id) {
  35787. return classes[id];
  35788. };
  35789. module.exports.getClasses = function () {
  35790. return classes;
  35791. };
  35792. module.exports.getRelations = function () {
  35793. return relations;
  35794. };
  35795. exports.addRelation = function (relation) {
  35796. log.warn('Adding relation: ' + JSON.stringify(relation));
  35797. exports.addClass(relation.id1);
  35798. exports.addClass(relation.id2);
  35799. relations.push(relation);
  35800. };
  35801. exports.addMembers = function (className, MembersArr) {
  35802. var theClass = classes[className];
  35803. if (typeof MembersArr === 'string') {
  35804. if (MembersArr.substr(-1) === ')') {
  35805. theClass.methods.push(MembersArr);
  35806. } else {
  35807. theClass.members.push(MembersArr);
  35808. }
  35809. }
  35810. };
  35811. exports.cleanupLabel = function (label) {
  35812. if (label.substring(0, 1) === ':') {
  35813. return label.substr(2).trim();
  35814. } else {
  35815. return label.trim();
  35816. }
  35817. };
  35818. exports.lineType = {
  35819. LINE: 0,
  35820. DOTTED_LINE: 1
  35821. };
  35822. exports.relationType = {
  35823. AGGREGATION: 0,
  35824. EXTENSION: 1,
  35825. COMPOSITION: 2,
  35826. DEPENDENCY: 3
  35827. };
  35828. },{"../../logger":129}],109:[function(require,module,exports){
  35829. /**
  35830. * Created by knut on 14-11-23.
  35831. */
  35832. 'use strict';
  35833. var cd = require('./parser/classDiagram').parser;
  35834. var cDDb = require('./classDb');
  35835. cd.yy = cDDb;
  35836. var d3 = require('../../d3');
  35837. var Logger = require('../../logger');
  35838. var dagre = require('dagre');
  35839. var log = new Logger.Log();
  35840. var idCache;
  35841. idCache = {};
  35842. var classCnt = 0;
  35843. var conf = {
  35844. dividerMargin: 10,
  35845. padding: 5,
  35846. textHeight: 14
  35847. };
  35848. // Todo optimize
  35849. var getGraphId = function getGraphId(label) {
  35850. var keys = Object.keys(idCache);
  35851. var i;
  35852. for (i = 0; i < keys.length; i++) {
  35853. if (idCache[keys[i]].label === label) {
  35854. return keys[i];
  35855. }
  35856. }
  35857. return undefined;
  35858. };
  35859. /**
  35860. * Setup arrow head and define the marker. The result is appended to the svg.
  35861. */
  35862. var insertMarkers = function insertMarkers(elem) {
  35863. elem.append('defs').append('marker').attr('id', 'extensionStart').attr('class', 'extension').attr('refX', 0).attr('refY', 7).attr('markerWidth', 190).attr('markerHeight', 240).attr('orient', 'auto').append('path').attr('d', 'M 1,7 L18,13 V 1 Z');
  35864. elem.append('defs').append('marker').attr('id', 'extensionEnd').attr('refX', 19).attr('refY', 7).attr('markerWidth', 20).attr('markerHeight', 28).attr('orient', 'auto').append('path').attr('d', 'M 1,1 V 13 L18,7 Z'); //this is actual shape for arrowhead
  35865. elem.append('defs').append('marker').attr('id', 'compositionStart').attr('class', 'extension').attr('refX', 0).attr('refY', 7).attr('markerWidth', 190).attr('markerHeight', 240).attr('orient', 'auto').append('path').attr('d', 'M 18,7 L9,13 L1,7 L9,1 Z');
  35866. elem.append('defs').append('marker').attr('id', 'compositionEnd').attr('refX', 19).attr('refY', 7).attr('markerWidth', 20).attr('markerHeight', 28).attr('orient', 'auto').append('path').attr('d', 'M 18,7 L9,13 L1,7 L9,1 Z');
  35867. elem.append('defs').append('marker').attr('id', 'aggregationStart').attr('class', 'extension').attr('refX', 0).attr('refY', 7).attr('markerWidth', 190).attr('markerHeight', 240).attr('orient', 'auto').append('path').attr('d', 'M 18,7 L9,13 L1,7 L9,1 Z');
  35868. elem.append('defs').append('marker').attr('id', 'aggregationEnd').attr('refX', 19).attr('refY', 7).attr('markerWidth', 20).attr('markerHeight', 28).attr('orient', 'auto').append('path').attr('d', 'M 18,7 L9,13 L1,7 L9,1 Z');
  35869. elem.append('defs').append('marker').attr('id', 'dependencyStart').attr('class', 'extension').attr('refX', 0).attr('refY', 7).attr('markerWidth', 190).attr('markerHeight', 240).attr('orient', 'auto').append('path').attr('d', 'M 5,7 L9,13 L1,7 L9,1 Z');
  35870. elem.append('defs').append('marker').attr('id', 'dependencyEnd').attr('refX', 19).attr('refY', 7).attr('markerWidth', 20).attr('markerHeight', 28).attr('orient', 'auto').append('path').attr('d', 'M 18,7 L9,13 L14,7 L9,1 Z');
  35871. };
  35872. var edgeCount = 0;
  35873. var drawEdge = function drawEdge(elem, path, relation) {
  35874. var getRelationType = function getRelationType(type) {
  35875. switch (type) {
  35876. case cDDb.relationType.AGGREGATION:
  35877. return 'aggregation';
  35878. case cDDb.relationType.EXTENSION:
  35879. return 'extension';
  35880. case cDDb.relationType.COMPOSITION:
  35881. return 'composition';
  35882. case cDDb.relationType.DEPENDENCY:
  35883. return 'dependency';
  35884. }
  35885. };
  35886. //The data for our line
  35887. var lineData = path.points;
  35888. //This is the accessor function we talked about above
  35889. var lineFunction = d3.svg.line().x(function (d) {
  35890. return d.x;
  35891. }).y(function (d) {
  35892. return d.y;
  35893. })
  35894. //.interpolate('cardinal');
  35895. .interpolate('basis');
  35896. var svgPath = elem.append('path').attr('d', lineFunction(lineData)).attr('id', 'edge' + edgeCount).attr('class', 'relation');
  35897. var url = '';
  35898. if (conf.arrowMarkerAbsolute) {
  35899. url = window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search;
  35900. url = url.replace(/\(/g, '\\(');
  35901. url = url.replace(/\)/g, '\\)');
  35902. }
  35903. //console.log(relation.relation.type1);
  35904. if (relation.relation.type1 !== 'none') {
  35905. svgPath.attr('marker-start', 'url(' + url + '#' + getRelationType(relation.relation.type1) + 'Start' + ')');
  35906. }
  35907. if (relation.relation.type2 !== 'none') {
  35908. svgPath.attr('marker-end', 'url(' + url + '#' + getRelationType(relation.relation.type2) + 'End' + ')');
  35909. }
  35910. //var bbox = svgPath[0][0].getBBox();
  35911. //var x = Math.floor(bbox.x + bbox.width/2.0);
  35912. //var y = Math.floor(bbox.y + bbox.height/2.0);
  35913. var x, y;
  35914. var l = path.points.length;
  35915. if (l % 2 !== 0) {
  35916. var p1 = path.points[Math.floor(l / 2)];
  35917. var p2 = path.points[Math.ceil(l / 2)];
  35918. x = (p1.x + p2.x) / 2;
  35919. y = (p1.y + p2.y) / 2;
  35920. } else {
  35921. var p = path.points[Math.floor(l / 2)];
  35922. x = p.x;
  35923. y = p.y;
  35924. }
  35925. if (typeof relation.title !== 'undefined') {
  35926. var g = elem.append('g').attr('class', 'classLabel');
  35927. var label = g.append('text').attr('class', 'label').attr('x', x).attr('y', y).attr('fill', 'red').attr('text-anchor', 'middle').text(relation.title);
  35928. window.label = label;
  35929. var bounds = label.node().getBBox();
  35930. g.insert('rect', ':first-child').attr('class', 'box').attr('x', bounds.x - conf.padding / 2).attr('y', bounds.y - conf.padding / 2).attr('width', bounds.width + 2 * conf.padding / 2).attr('height', bounds.height + 2 * conf.padding / 2);
  35931. //.append('textpath')
  35932. //.attr('xlink:href','#edge'+edgeCount)
  35933. //.attr('text-anchor','middle')
  35934. //.attr('startOffset','50%')
  35935. }
  35936. edgeCount++;
  35937. };
  35938. var drawClass = function drawClass(elem, classDef) {
  35939. log.info('Rendering class ' + classDef);
  35940. var addTspan = function addTspan(textEl, txt, isFirst) {
  35941. var tSpan = textEl.append('tspan').attr('x', conf.padding).text(txt);
  35942. if (!isFirst) {
  35943. tSpan.attr('dy', conf.textHeight);
  35944. }
  35945. };
  35946. var id = 'classId' + classCnt;
  35947. var classInfo = {
  35948. id: id,
  35949. label: classDef.id,
  35950. width: 0,
  35951. height: 0
  35952. };
  35953. var g = elem.append('g').attr('id', id).attr('class', 'classGroup');
  35954. var title = g.append('text').attr('x', conf.padding).attr('y', conf.textHeight + conf.padding).text(classDef.id);
  35955. var titleHeight = title.node().getBBox().height;
  35956. var membersLine = g.append('line') // text label for the x axis
  35957. .attr('x1', 0).attr('y1', conf.padding + titleHeight + conf.dividerMargin / 2).attr('y2', conf.padding + titleHeight + conf.dividerMargin / 2);
  35958. var members = g.append('text') // text label for the x axis
  35959. .attr('x', conf.padding).attr('y', titleHeight + conf.dividerMargin + conf.textHeight).attr('fill', 'white').attr('class', 'classText');
  35960. var isFirst = true;
  35961. classDef.members.forEach(function (member) {
  35962. addTspan(members, member, isFirst);
  35963. isFirst = false;
  35964. });
  35965. //for (var member of classDef.members) {
  35966. // addTspan(members, member, isFirst);
  35967. // isFirst = false;
  35968. //}
  35969. var membersBox = members.node().getBBox();
  35970. var methodsLine = g.append('line') // text label for the x axis
  35971. .attr('x1', 0).attr('y1', conf.padding + titleHeight + 3 * conf.dividerMargin / 2 + membersBox.height).attr('y2', conf.padding + titleHeight + 3 * conf.dividerMargin / 2 + membersBox.height);
  35972. var methods = g.append('text') // text label for the x axis
  35973. .attr('x', conf.padding).attr('y', titleHeight + 2 * conf.dividerMargin + membersBox.height + conf.textHeight).attr('fill', 'white').attr('class', 'classText');
  35974. isFirst = true;
  35975. classDef.methods.forEach(function (method) {
  35976. addTspan(methods, method, isFirst);
  35977. isFirst = false;
  35978. });
  35979. //for (var method of classDef.methods) {
  35980. // addTspan(methods, method, isFirst);
  35981. // isFirst = false;
  35982. //}
  35983. var classBox = g.node().getBBox();
  35984. g.insert('rect', ':first-child').attr('x', 0).attr('y', 0).attr('width', classBox.width + 2 * conf.padding).attr('height', classBox.height + conf.padding + 0.5 * conf.dividerMargin);
  35985. membersLine.attr('x2', classBox.width + 2 * conf.padding);
  35986. methodsLine.attr('x2', classBox.width + 2 * conf.padding);
  35987. classInfo.width = classBox.width + 2 * conf.padding;
  35988. classInfo.height = classBox.height + conf.padding + 0.5 * conf.dividerMargin;
  35989. idCache[id] = classInfo;
  35990. classCnt++;
  35991. return classInfo;
  35992. };
  35993. module.exports.setConf = function (cnf) {
  35994. var keys = Object.keys(cnf);
  35995. keys.forEach(function (key) {
  35996. conf[key] = cnf[key];
  35997. });
  35998. };
  35999. /**
  36000. * Draws a flowchart in the tag with id: id based on the graph definition in text.
  36001. * @param text
  36002. * @param id
  36003. */
  36004. module.exports.draw = function (text, id) {
  36005. cd.yy.clear();
  36006. cd.parse(text);
  36007. log.info('Rendering diagram ' + text);
  36008. //// Fetch the default direction, use TD if none was found
  36009. var diagram = d3.select('#' + id);
  36010. insertMarkers(diagram);
  36011. //var svg = diagram.append('svg');
  36012. // Layout graph, Create a new directed graph
  36013. var g = new dagre.graphlib.Graph({
  36014. multigraph: true
  36015. });
  36016. // Set an object for the graph label
  36017. g.setGraph({
  36018. isMultiGraph: true
  36019. });
  36020. // Default to assigning a new object as a label for each new edge.
  36021. g.setDefaultEdgeLabel(function () {
  36022. return {};
  36023. });
  36024. var classes = cDDb.getClasses();
  36025. var keys = Object.keys(classes);
  36026. var i;
  36027. for (i = 0; i < keys.length; i++) {
  36028. var classDef = classes[keys[i]];
  36029. var node = drawClass(diagram, classDef);
  36030. // Add nodes to the graph. The first argument is the node id. The second is
  36031. // metadata about the node. In this case we're going to add labels to each of
  36032. // our nodes.
  36033. g.setNode(node.id, node);
  36034. log.info('Org height: ' + node.height);
  36035. //g.setNode("swilliams", { label: "Saul Williams", width: 160, height: 100 });
  36036. //g.setNode("bpitt", { label: "Brad Pitt", width: 108, height: 100 });
  36037. //g.setNode("hford", { label: "Harrison Ford", width: 168, height: 100 });
  36038. //g.setNode("lwilson", { label: "Luke Wilson", width: 144, height: 100 });
  36039. //g.setNode("kbacon", { label: "Kevin Bacon", width: 121, height: 100 });
  36040. }
  36041. var relations = cDDb.getRelations();
  36042. var i = 0;
  36043. relations.forEach(function (relation) {
  36044. i = i + 1;
  36045. log.info('tjoho' + getGraphId(relation.id1) + getGraphId(relation.id2) + JSON.stringify(relation));
  36046. g.setEdge(getGraphId(relation.id1), getGraphId(relation.id2), { relation: relation });
  36047. });
  36048. //for (var relation of relations) {
  36049. // i = i + 1;
  36050. // log.info('tjoho' + getGraphId(relation.id1) + getGraphId(relation.id2) + JSON.stringify(relation));
  36051. // g.setEdge(getGraphId(relation.id1), getGraphId(relation.id2), {relation: relation});
  36052. //}
  36053. dagre.layout(g);
  36054. g.nodes().forEach(function (v) {
  36055. if (typeof v !== 'undefined') {
  36056. log.debug('Node ' + v + ': ' + JSON.stringify(g.node(v)));
  36057. d3.select('#' + v).attr('transform', 'translate(' + (g.node(v).x - g.node(v).width / 2) + ',' + (g.node(v).y - g.node(v).height / 2) + ' )');
  36058. //d3.select('#' +v +' rect').attr('x',(g.node(v).x-(g.node(v).width/2)))
  36059. //.attr('y',(g.node(v).y-(g.node(v).height/2)));
  36060. }
  36061. });
  36062. g.edges().forEach(function (e) {
  36063. log.debug('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(g.edge(e)));
  36064. drawEdge(diagram, g.edge(e), g.edge(e).relation);
  36065. });
  36066. //
  36067. diagram.attr('height', '100%');
  36068. diagram.attr('width', '100%');
  36069. //
  36070. //
  36071. //
  36072. //
  36073. //if(conf.useMaxWidth) {
  36074. // diagram.attr('height', '100%');
  36075. // diagram.attr('width', '100%');
  36076. // diagram.attr('style', 'max-width:' + (width) + 'px;');
  36077. //}else{
  36078. // diagram.attr('height',height);
  36079. // diagram.attr('width', width );
  36080. //}
  36081. //diagram.attr('viewBox', (box.startx-conf.diagramMarginX) + ' -' +conf.diagramMarginY + ' ' + width + ' ' + height);
  36082. };
  36083. },{"../../d3":107,"../../logger":129,"./classDb":108,"./parser/classDiagram":110,"dagre":51}],110:[function(require,module,exports){
  36084. (function (process){
  36085. /* parser generated by jison 0.4.17 */
  36086. /*
  36087. Returns a Parser object of the following structure:
  36088. Parser: {
  36089. yy: {}
  36090. }
  36091. Parser.prototype: {
  36092. yy: {},
  36093. trace: function(),
  36094. symbols_: {associative list: name ==> number},
  36095. terminals_: {associative list: number ==> name},
  36096. productions_: [...],
  36097. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  36098. table: [...],
  36099. defaultActions: {...},
  36100. parseError: function(str, hash),
  36101. parse: function(input),
  36102. lexer: {
  36103. EOF: 1,
  36104. parseError: function(str, hash),
  36105. setInput: function(input),
  36106. input: function(),
  36107. unput: function(str),
  36108. more: function(),
  36109. less: function(n),
  36110. pastInput: function(),
  36111. upcomingInput: function(),
  36112. showPosition: function(),
  36113. test_match: function(regex_match_array, rule_index),
  36114. next: function(),
  36115. lex: function(),
  36116. begin: function(condition),
  36117. popState: function(),
  36118. _currentRules: function(),
  36119. topState: function(),
  36120. pushState: function(condition),
  36121. options: {
  36122. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  36123. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  36124. backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code)
  36125. },
  36126. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  36127. rules: [...],
  36128. conditions: {associative list: name ==> set},
  36129. }
  36130. }
  36131. token location info (@$, _$, etc.): {
  36132. first_line: n,
  36133. last_line: n,
  36134. first_column: n,
  36135. last_column: n,
  36136. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  36137. }
  36138. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  36139. text: (matched text)
  36140. token: (the produced terminal token, if any)
  36141. line: (yylineno)
  36142. }
  36143. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  36144. loc: (yylloc)
  36145. expected: (string describing the set of expected tokens)
  36146. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  36147. }
  36148. */
  36149. "use strict";
  36150. var parser = (function () {
  36151. var o = function o(k, v, _o, l) {
  36152. for (_o = _o || {}, l = k.length; l--; _o[k[l]] = v);return _o;
  36153. },
  36154. $V0 = [1, 11],
  36155. $V1 = [1, 12],
  36156. $V2 = [1, 13],
  36157. $V3 = [1, 15],
  36158. $V4 = [1, 16],
  36159. $V5 = [1, 17],
  36160. $V6 = [6, 8],
  36161. $V7 = [1, 26],
  36162. $V8 = [1, 27],
  36163. $V9 = [1, 28],
  36164. $Va = [1, 29],
  36165. $Vb = [1, 30],
  36166. $Vc = [1, 31],
  36167. $Vd = [6, 8, 13, 17, 23, 26, 27, 28, 29, 30, 31],
  36168. $Ve = [6, 8, 13, 17, 23, 26, 27, 28, 29, 30, 31, 45, 46, 47],
  36169. $Vf = [23, 45, 46, 47],
  36170. $Vg = [23, 30, 31, 45, 46, 47],
  36171. $Vh = [23, 26, 27, 28, 29, 45, 46, 47],
  36172. $Vi = [6, 8, 13],
  36173. $Vj = [1, 46];
  36174. var parser = { trace: function trace() {},
  36175. yy: {},
  36176. symbols_: { "error": 2, "mermaidDoc": 3, "graphConfig": 4, "CLASS_DIAGRAM": 5, "NEWLINE": 6, "statements": 7, "EOF": 8, "statement": 9, "className": 10, "alphaNumToken": 11, "relationStatement": 12, "LABEL": 13, "classStatement": 14, "methodStatement": 15, "CLASS": 16, "STRUCT_START": 17, "members": 18, "STRUCT_STOP": 19, "MEMBER": 20, "SEPARATOR": 21, "relation": 22, "STR": 23, "relationType": 24, "lineType": 25, "AGGREGATION": 26, "EXTENSION": 27, "COMPOSITION": 28, "DEPENDENCY": 29, "LINE": 30, "DOTTED_LINE": 31, "commentToken": 32, "textToken": 33, "graphCodeTokens": 34, "textNoTagsToken": 35, "TAGSTART": 36, "TAGEND": 37, "==": 38, "--": 39, "PCT": 40, "DEFAULT": 41, "SPACE": 42, "MINUS": 43, "keywords": 44, "UNICODE_TEXT": 45, "NUM": 46, "ALPHA": 47, "$accept": 0, "$end": 1 },
  36177. terminals_: { 2: "error", 5: "CLASS_DIAGRAM", 6: "NEWLINE", 8: "EOF", 13: "LABEL", 16: "CLASS", 17: "STRUCT_START", 19: "STRUCT_STOP", 20: "MEMBER", 21: "SEPARATOR", 23: "STR", 26: "AGGREGATION", 27: "EXTENSION", 28: "COMPOSITION", 29: "DEPENDENCY", 30: "LINE", 31: "DOTTED_LINE", 34: "graphCodeTokens", 36: "TAGSTART", 37: "TAGEND", 38: "==", 39: "--", 40: "PCT", 41: "DEFAULT", 42: "SPACE", 43: "MINUS", 44: "keywords", 45: "UNICODE_TEXT", 46: "NUM", 47: "ALPHA" },
  36178. productions_: [0, [3, 1], [4, 4], [7, 1], [7, 3], [10, 2], [10, 1], [9, 1], [9, 2], [9, 1], [9, 1], [14, 2], [14, 5], [18, 1], [18, 2], [15, 1], [15, 2], [15, 1], [15, 1], [12, 3], [12, 4], [12, 4], [12, 5], [22, 3], [22, 2], [22, 2], [22, 1], [24, 1], [24, 1], [24, 1], [24, 1], [25, 1], [25, 1], [32, 1], [32, 1], [33, 1], [33, 1], [33, 1], [33, 1], [33, 1], [33, 1], [33, 1], [35, 1], [35, 1], [35, 1], [35, 1], [11, 1], [11, 1], [11, 1]],
  36179. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, /* action[1] */$$, /* vstack */_$ /* lstack */) {
  36180. /* this == yyval */
  36181. var $0 = $$.length - 1;
  36182. switch (yystate) {
  36183. case 5:
  36184. this.$ = $$[$0 - 1] + $$[$0];
  36185. break;
  36186. case 6:
  36187. this.$ = $$[$0];
  36188. break;
  36189. case 7:
  36190. yy.addRelation($$[$0]);
  36191. break;
  36192. case 8:
  36193. $$[$0 - 1].title = yy.cleanupLabel($$[$0]);yy.addRelation($$[$0 - 1]);
  36194. break;
  36195. case 12:
  36196. /*console.log($$[$0-3],JSON.stringify($$[$0-1]));*/yy.addMembers($$[$0 - 3], $$[$0 - 1]);
  36197. break;
  36198. case 13:
  36199. this.$ = [$$[$0]];
  36200. break;
  36201. case 14:
  36202. $$[$0].push($$[$0 - 1]);this.$ = $$[$0];
  36203. break;
  36204. case 15:
  36205. /*console.log('Rel found',$$[$0]);*/
  36206. break;
  36207. case 16:
  36208. yy.addMembers($$[$0 - 1], yy.cleanupLabel($$[$0]));
  36209. break;
  36210. case 17:
  36211. console.warn('Member', $$[$0]);
  36212. break;
  36213. case 18:
  36214. /*console.log('sep found',$$[$0]);*/
  36215. break;
  36216. case 19:
  36217. this.$ = { 'id1': $$[$0 - 2], 'id2': $$[$0], relation: $$[$0 - 1], relationTitle1: 'none', relationTitle2: 'none' };
  36218. break;
  36219. case 20:
  36220. this.$ = { id1: $$[$0 - 3], id2: $$[$0], relation: $$[$0 - 1], relationTitle1: $$[$0 - 2], relationTitle2: 'none' };
  36221. break;
  36222. case 21:
  36223. this.$ = { id1: $$[$0 - 3], id2: $$[$0], relation: $$[$0 - 2], relationTitle1: 'none', relationTitle2: $$[$0 - 1] };
  36224. break;
  36225. case 22:
  36226. this.$ = { id1: $$[$0 - 4], id2: $$[$0], relation: $$[$0 - 2], relationTitle1: $$[$0 - 3], relationTitle2: $$[$0 - 1] };
  36227. break;
  36228. case 23:
  36229. this.$ = { type1: $$[$0 - 2], type2: $$[$0], lineType: $$[$0 - 1] };
  36230. break;
  36231. case 24:
  36232. this.$ = { type1: 'none', type2: $$[$0], lineType: $$[$0 - 1] };
  36233. break;
  36234. case 25:
  36235. this.$ = { type1: $$[$0 - 1], type2: 'none', lineType: $$[$0] };
  36236. break;
  36237. case 26:
  36238. this.$ = { type1: 'none', type2: 'none', lineType: $$[$0] };
  36239. break;
  36240. case 27:
  36241. this.$ = yy.relationType.AGGREGATION;
  36242. break;
  36243. case 28:
  36244. this.$ = yy.relationType.EXTENSION;
  36245. break;
  36246. case 29:
  36247. this.$ = yy.relationType.COMPOSITION;
  36248. break;
  36249. case 30:
  36250. this.$ = yy.relationType.DEPENDENCY;
  36251. break;
  36252. case 31:
  36253. this.$ = yy.lineType.LINE;
  36254. break;
  36255. case 32:
  36256. this.$ = yy.lineType.DOTTED_LINE;
  36257. break;
  36258. }
  36259. },
  36260. table: [{ 3: 1, 4: 2, 5: [1, 3] }, { 1: [3] }, { 1: [2, 1] }, { 6: [1, 4] }, { 7: 5, 9: 6, 10: 10, 11: 14, 12: 7, 14: 8, 15: 9, 16: $V0, 20: $V1, 21: $V2, 45: $V3, 46: $V4, 47: $V5 }, { 8: [1, 18] }, { 6: [1, 19], 8: [2, 3] }, o($V6, [2, 7], { 13: [1, 20] }), o($V6, [2, 9]), o($V6, [2, 10]), o($V6, [2, 15], { 22: 21, 24: 24, 25: 25, 13: [1, 23], 23: [1, 22], 26: $V7, 27: $V8, 28: $V9, 29: $Va, 30: $Vb, 31: $Vc }), { 10: 32, 11: 14, 45: $V3, 46: $V4, 47: $V5 }, o($V6, [2, 17]), o($V6, [2, 18]), o($Vd, [2, 6], { 11: 14, 10: 33, 45: $V3, 46: $V4, 47: $V5 }), o($Ve, [2, 46]), o($Ve, [2, 47]), o($Ve, [2, 48]), { 1: [2, 2] }, { 7: 34, 9: 6, 10: 10, 11: 14, 12: 7, 14: 8, 15: 9, 16: $V0, 20: $V1, 21: $V2, 45: $V3, 46: $V4, 47: $V5 }, o($V6, [2, 8]), { 10: 35, 11: 14, 23: [1, 36], 45: $V3, 46: $V4, 47: $V5 }, { 22: 37, 24: 24, 25: 25, 26: $V7, 27: $V8, 28: $V9, 29: $Va, 30: $Vb, 31: $Vc }, o($V6, [2, 16]), { 25: 38, 30: $Vb, 31: $Vc }, o($Vf, [2, 26], { 24: 39, 26: $V7, 27: $V8, 28: $V9, 29: $Va }), o($Vg, [2, 27]), o($Vg, [2, 28]), o($Vg, [2, 29]), o($Vg, [2, 30]), o($Vh, [2, 31]), o($Vh, [2, 32]), o($V6, [2, 11], { 17: [1, 40] }), o($Vd, [2, 5]), { 8: [2, 4] }, o($Vi, [2, 19]), { 10: 41, 11: 14, 45: $V3, 46: $V4, 47: $V5 }, { 10: 42, 11: 14, 23: [1, 43], 45: $V3, 46: $V4, 47: $V5 }, o($Vf, [2, 25], { 24: 44, 26: $V7, 27: $V8, 28: $V9, 29: $Va }), o($Vf, [2, 24]), { 18: 45, 20: $Vj }, o($Vi, [2, 21]), o($Vi, [2, 20]), { 10: 47, 11: 14, 45: $V3, 46: $V4, 47: $V5 }, o($Vf, [2, 23]), { 19: [1, 48] }, { 18: 49, 19: [2, 13], 20: $Vj }, o($Vi, [2, 22]), o($V6, [2, 12]), { 19: [2, 14] }],
  36261. defaultActions: { 2: [2, 1], 18: [2, 2], 34: [2, 4], 49: [2, 14] },
  36262. parseError: function parseError(str, hash) {
  36263. if (hash.recoverable) {
  36264. this.trace(str);
  36265. } else {
  36266. var _parseError = function _parseError(msg, hash) {
  36267. this.message = msg;
  36268. this.hash = hash;
  36269. };
  36270. _parseError.prototype = Error;
  36271. throw new _parseError(str, hash);
  36272. }
  36273. },
  36274. parse: function parse(input) {
  36275. var self = this,
  36276. stack = [0],
  36277. tstack = [],
  36278. vstack = [null],
  36279. lstack = [],
  36280. table = this.table,
  36281. yytext = '',
  36282. yylineno = 0,
  36283. yyleng = 0,
  36284. recovering = 0,
  36285. TERROR = 2,
  36286. EOF = 1;
  36287. var args = lstack.slice.call(arguments, 1);
  36288. var lexer = Object.create(this.lexer);
  36289. var sharedState = { yy: {} };
  36290. for (var k in this.yy) {
  36291. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  36292. sharedState.yy[k] = this.yy[k];
  36293. }
  36294. }
  36295. lexer.setInput(input, sharedState.yy);
  36296. sharedState.yy.lexer = lexer;
  36297. sharedState.yy.parser = this;
  36298. if (typeof lexer.yylloc == 'undefined') {
  36299. lexer.yylloc = {};
  36300. }
  36301. var yyloc = lexer.yylloc;
  36302. lstack.push(yyloc);
  36303. var ranges = lexer.options && lexer.options.ranges;
  36304. if (typeof sharedState.yy.parseError === 'function') {
  36305. this.parseError = sharedState.yy.parseError;
  36306. } else {
  36307. this.parseError = Object.getPrototypeOf(this).parseError;
  36308. }
  36309. function popStack(n) {
  36310. stack.length = stack.length - 2 * n;
  36311. vstack.length = vstack.length - n;
  36312. lstack.length = lstack.length - n;
  36313. }
  36314. _token_stack: var lex = function lex() {
  36315. var token;
  36316. token = lexer.lex() || EOF;
  36317. if (typeof token !== 'number') {
  36318. token = self.symbols_[token] || token;
  36319. }
  36320. return token;
  36321. };
  36322. var symbol,
  36323. preErrorSymbol,
  36324. state,
  36325. action,
  36326. a,
  36327. r,
  36328. yyval = {},
  36329. p,
  36330. len,
  36331. newState,
  36332. expected;
  36333. while (true) {
  36334. state = stack[stack.length - 1];
  36335. if (this.defaultActions[state]) {
  36336. action = this.defaultActions[state];
  36337. } else {
  36338. if (symbol === null || typeof symbol == 'undefined') {
  36339. symbol = lex();
  36340. }
  36341. action = table[state] && table[state][symbol];
  36342. }
  36343. if (typeof action === 'undefined' || !action.length || !action[0]) {
  36344. var errStr = '';
  36345. expected = [];
  36346. for (p in table[state]) {
  36347. if (this.terminals_[p] && p > TERROR) {
  36348. expected.push('\'' + this.terminals_[p] + '\'');
  36349. }
  36350. }
  36351. if (lexer.showPosition) {
  36352. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  36353. } else {
  36354. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  36355. }
  36356. this.parseError(errStr, {
  36357. text: lexer.match,
  36358. token: this.terminals_[symbol] || symbol,
  36359. line: lexer.yylineno,
  36360. loc: yyloc,
  36361. expected: expected
  36362. });
  36363. }
  36364. if (action[0] instanceof Array && action.length > 1) {
  36365. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  36366. }
  36367. switch (action[0]) {
  36368. case 1:
  36369. stack.push(symbol);
  36370. vstack.push(lexer.yytext);
  36371. lstack.push(lexer.yylloc);
  36372. stack.push(action[1]);
  36373. symbol = null;
  36374. if (!preErrorSymbol) {
  36375. yyleng = lexer.yyleng;
  36376. yytext = lexer.yytext;
  36377. yylineno = lexer.yylineno;
  36378. yyloc = lexer.yylloc;
  36379. if (recovering > 0) {
  36380. recovering--;
  36381. }
  36382. } else {
  36383. symbol = preErrorSymbol;
  36384. preErrorSymbol = null;
  36385. }
  36386. break;
  36387. case 2:
  36388. len = this.productions_[action[1]][1];
  36389. yyval.$ = vstack[vstack.length - len];
  36390. yyval._$ = {
  36391. first_line: lstack[lstack.length - (len || 1)].first_line,
  36392. last_line: lstack[lstack.length - 1].last_line,
  36393. first_column: lstack[lstack.length - (len || 1)].first_column,
  36394. last_column: lstack[lstack.length - 1].last_column
  36395. };
  36396. if (ranges) {
  36397. yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
  36398. }
  36399. r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
  36400. if (typeof r !== 'undefined') {
  36401. return r;
  36402. }
  36403. if (len) {
  36404. stack = stack.slice(0, -1 * len * 2);
  36405. vstack = vstack.slice(0, -1 * len);
  36406. lstack = lstack.slice(0, -1 * len);
  36407. }
  36408. stack.push(this.productions_[action[1]][0]);
  36409. vstack.push(yyval.$);
  36410. lstack.push(yyval._$);
  36411. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  36412. stack.push(newState);
  36413. break;
  36414. case 3:
  36415. return true;
  36416. }
  36417. }
  36418. return true;
  36419. } };
  36420. /* generated by jison-lex 0.3.4 */
  36421. var lexer = (function () {
  36422. var lexer = {
  36423. EOF: 1,
  36424. parseError: function parseError(str, hash) {
  36425. if (this.yy.parser) {
  36426. this.yy.parser.parseError(str, hash);
  36427. } else {
  36428. throw new Error(str);
  36429. }
  36430. },
  36431. // resets the lexer, sets new input
  36432. setInput: function setInput(input, yy) {
  36433. this.yy = yy || this.yy || {};
  36434. this._input = input;
  36435. this._more = this._backtrack = this.done = false;
  36436. this.yylineno = this.yyleng = 0;
  36437. this.yytext = this.matched = this.match = '';
  36438. this.conditionStack = ['INITIAL'];
  36439. this.yylloc = {
  36440. first_line: 1,
  36441. first_column: 0,
  36442. last_line: 1,
  36443. last_column: 0
  36444. };
  36445. if (this.options.ranges) {
  36446. this.yylloc.range = [0, 0];
  36447. }
  36448. this.offset = 0;
  36449. return this;
  36450. },
  36451. // consumes and returns one char from the input
  36452. input: function input() {
  36453. var ch = this._input[0];
  36454. this.yytext += ch;
  36455. this.yyleng++;
  36456. this.offset++;
  36457. this.match += ch;
  36458. this.matched += ch;
  36459. var lines = ch.match(/(?:\r\n?|\n).*/g);
  36460. if (lines) {
  36461. this.yylineno++;
  36462. this.yylloc.last_line++;
  36463. } else {
  36464. this.yylloc.last_column++;
  36465. }
  36466. if (this.options.ranges) {
  36467. this.yylloc.range[1]++;
  36468. }
  36469. this._input = this._input.slice(1);
  36470. return ch;
  36471. },
  36472. // unshifts one char (or a string) into the input
  36473. unput: function unput(ch) {
  36474. var len = ch.length;
  36475. var lines = ch.split(/(?:\r\n?|\n)/g);
  36476. this._input = ch + this._input;
  36477. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  36478. //this.yyleng -= len;
  36479. this.offset -= len;
  36480. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  36481. this.match = this.match.substr(0, this.match.length - 1);
  36482. this.matched = this.matched.substr(0, this.matched.length - 1);
  36483. if (lines.length - 1) {
  36484. this.yylineno -= lines.length - 1;
  36485. }
  36486. var r = this.yylloc.range;
  36487. this.yylloc = {
  36488. first_line: this.yylloc.first_line,
  36489. last_line: this.yylineno + 1,
  36490. first_column: this.yylloc.first_column,
  36491. last_column: lines ? (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length : this.yylloc.first_column - len
  36492. };
  36493. if (this.options.ranges) {
  36494. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  36495. }
  36496. this.yyleng = this.yytext.length;
  36497. return this;
  36498. },
  36499. // When called from action, caches matched text and appends it on next action
  36500. more: function more() {
  36501. this._more = true;
  36502. return this;
  36503. },
  36504. // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
  36505. reject: function reject() {
  36506. if (this.options.backtrack_lexer) {
  36507. this._backtrack = true;
  36508. } else {
  36509. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), {
  36510. text: "",
  36511. token: null,
  36512. line: this.yylineno
  36513. });
  36514. }
  36515. return this;
  36516. },
  36517. // retain first n characters of the match
  36518. less: function less(n) {
  36519. this.unput(this.match.slice(n));
  36520. },
  36521. // displays already matched input, i.e. for error messages
  36522. pastInput: function pastInput() {
  36523. var past = this.matched.substr(0, this.matched.length - this.match.length);
  36524. return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
  36525. },
  36526. // displays upcoming input, i.e. for error messages
  36527. upcomingInput: function upcomingInput() {
  36528. var next = this.match;
  36529. if (next.length < 20) {
  36530. next += this._input.substr(0, 20 - next.length);
  36531. }
  36532. return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  36533. },
  36534. // displays the character position where the lexing error occurred, i.e. for error messages
  36535. showPosition: function showPosition() {
  36536. var pre = this.pastInput();
  36537. var c = new Array(pre.length + 1).join("-");
  36538. return pre + this.upcomingInput() + "\n" + c + "^";
  36539. },
  36540. // test the lexed token: return FALSE when not a match, otherwise return token
  36541. test_match: function test_match(match, indexed_rule) {
  36542. var token, lines, backup;
  36543. if (this.options.backtrack_lexer) {
  36544. // save context
  36545. backup = {
  36546. yylineno: this.yylineno,
  36547. yylloc: {
  36548. first_line: this.yylloc.first_line,
  36549. last_line: this.last_line,
  36550. first_column: this.yylloc.first_column,
  36551. last_column: this.yylloc.last_column
  36552. },
  36553. yytext: this.yytext,
  36554. match: this.match,
  36555. matches: this.matches,
  36556. matched: this.matched,
  36557. yyleng: this.yyleng,
  36558. offset: this.offset,
  36559. _more: this._more,
  36560. _input: this._input,
  36561. yy: this.yy,
  36562. conditionStack: this.conditionStack.slice(0),
  36563. done: this.done
  36564. };
  36565. if (this.options.ranges) {
  36566. backup.yylloc.range = this.yylloc.range.slice(0);
  36567. }
  36568. }
  36569. lines = match[0].match(/(?:\r\n?|\n).*/g);
  36570. if (lines) {
  36571. this.yylineno += lines.length;
  36572. }
  36573. this.yylloc = {
  36574. first_line: this.yylloc.last_line,
  36575. last_line: this.yylineno + 1,
  36576. first_column: this.yylloc.last_column,
  36577. last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
  36578. };
  36579. this.yytext += match[0];
  36580. this.match += match[0];
  36581. this.matches = match;
  36582. this.yyleng = this.yytext.length;
  36583. if (this.options.ranges) {
  36584. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  36585. }
  36586. this._more = false;
  36587. this._backtrack = false;
  36588. this._input = this._input.slice(match[0].length);
  36589. this.matched += match[0];
  36590. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  36591. if (this.done && this._input) {
  36592. this.done = false;
  36593. }
  36594. if (token) {
  36595. return token;
  36596. } else if (this._backtrack) {
  36597. // recover context
  36598. for (var k in backup) {
  36599. this[k] = backup[k];
  36600. }
  36601. return false; // rule action called reject() implying the next rule should be tested instead.
  36602. }
  36603. return false;
  36604. },
  36605. // return next match in input
  36606. next: function next() {
  36607. if (this.done) {
  36608. return this.EOF;
  36609. }
  36610. if (!this._input) {
  36611. this.done = true;
  36612. }
  36613. var token, match, tempMatch, index;
  36614. if (!this._more) {
  36615. this.yytext = '';
  36616. this.match = '';
  36617. }
  36618. var rules = this._currentRules();
  36619. for (var i = 0; i < rules.length; i++) {
  36620. tempMatch = this._input.match(this.rules[rules[i]]);
  36621. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  36622. match = tempMatch;
  36623. index = i;
  36624. if (this.options.backtrack_lexer) {
  36625. token = this.test_match(tempMatch, rules[i]);
  36626. if (token !== false) {
  36627. return token;
  36628. } else if (this._backtrack) {
  36629. match = false;
  36630. continue; // rule action called reject() implying a rule MISmatch.
  36631. } else {
  36632. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  36633. return false;
  36634. }
  36635. } else if (!this.options.flex) {
  36636. break;
  36637. }
  36638. }
  36639. }
  36640. if (match) {
  36641. token = this.test_match(match, rules[index]);
  36642. if (token !== false) {
  36643. return token;
  36644. }
  36645. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  36646. return false;
  36647. }
  36648. if (this._input === "") {
  36649. return this.EOF;
  36650. } else {
  36651. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  36652. text: "",
  36653. token: null,
  36654. line: this.yylineno
  36655. });
  36656. }
  36657. },
  36658. // return next match that has a token
  36659. lex: function lex() {
  36660. var r = this.next();
  36661. if (r) {
  36662. return r;
  36663. } else {
  36664. return this.lex();
  36665. }
  36666. },
  36667. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  36668. begin: function begin(condition) {
  36669. this.conditionStack.push(condition);
  36670. },
  36671. // pop the previously active lexer condition state off the condition stack
  36672. popState: function popState() {
  36673. var n = this.conditionStack.length - 1;
  36674. if (n > 0) {
  36675. return this.conditionStack.pop();
  36676. } else {
  36677. return this.conditionStack[0];
  36678. }
  36679. },
  36680. // produce the lexer rule set which is active for the currently active lexer condition state
  36681. _currentRules: function _currentRules() {
  36682. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  36683. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  36684. } else {
  36685. return this.conditions["INITIAL"].rules;
  36686. }
  36687. },
  36688. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  36689. topState: function topState(n) {
  36690. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  36691. if (n >= 0) {
  36692. return this.conditionStack[n];
  36693. } else {
  36694. return "INITIAL";
  36695. }
  36696. },
  36697. // alias for begin(condition)
  36698. pushState: function pushState(condition) {
  36699. this.begin(condition);
  36700. },
  36701. // return the number of states currently on the stack
  36702. stateStackSize: function stateStackSize() {
  36703. return this.conditionStack.length;
  36704. },
  36705. options: {},
  36706. performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
  36707. var YYSTATE = YY_START;
  36708. switch ($avoiding_name_collisions) {
  36709. case 0:
  36710. /* do nothing */
  36711. break;
  36712. case 1:
  36713. return 6;
  36714. break;
  36715. case 2:
  36716. /* skip whitespace */
  36717. break;
  36718. case 3:
  36719. return 5;
  36720. break;
  36721. case 4:
  36722. this.begin("struct"); /*console.log('Starting struct');*/return 17;
  36723. break;
  36724. case 5:
  36725. /*console.log('Ending struct');*/this.popState();return 19;
  36726. break;
  36727. case 6:
  36728. /* nothing */
  36729. break;
  36730. case 7:
  36731. /*console.log('lex-member: ' + yy_.yytext);*/return "MEMBER";
  36732. break;
  36733. case 8:
  36734. return 16;
  36735. break;
  36736. case 9:
  36737. this.begin("string");
  36738. break;
  36739. case 10:
  36740. this.popState();
  36741. break;
  36742. case 11:
  36743. return "STR";
  36744. break;
  36745. case 12:
  36746. return 27;
  36747. break;
  36748. case 13:
  36749. return 27;
  36750. break;
  36751. case 14:
  36752. return 29;
  36753. break;
  36754. case 15:
  36755. return 29;
  36756. break;
  36757. case 16:
  36758. return 28;
  36759. break;
  36760. case 17:
  36761. return 26;
  36762. break;
  36763. case 18:
  36764. return 30;
  36765. break;
  36766. case 19:
  36767. return 31;
  36768. break;
  36769. case 20:
  36770. return 13;
  36771. break;
  36772. case 21:
  36773. return 43;
  36774. break;
  36775. case 22:
  36776. return 'DOT';
  36777. break;
  36778. case 23:
  36779. return 'PLUS';
  36780. break;
  36781. case 24:
  36782. return 40;
  36783. break;
  36784. case 25:
  36785. return 'EQUALS';
  36786. break;
  36787. case 26:
  36788. return 'EQUALS';
  36789. break;
  36790. case 27:
  36791. return 47;
  36792. break;
  36793. case 28:
  36794. return 'PUNCTUATION';
  36795. break;
  36796. case 29:
  36797. return 46;
  36798. break;
  36799. case 30:
  36800. return 45;
  36801. break;
  36802. case 31:
  36803. return 42;
  36804. break;
  36805. case 32:
  36806. return 8;
  36807. break;
  36808. }
  36809. },
  36810. rules: [/^(?:%%[^\n]*)/, /^(?:\n+)/, /^(?:\s+)/, /^(?:classDiagram\b)/, /^(?:[\{])/, /^(?:\})/, /^(?:[\n])/, /^(?:[^\{\}\n]*)/, /^(?:class\b)/, /^(?:["])/, /^(?:["])/, /^(?:[^"]*)/, /^(?:\s*<\|)/, /^(?:\s*\|>)/, /^(?:\s*>)/, /^(?:\s*<)/, /^(?:\s*\*)/, /^(?:\s*o\b)/, /^(?:--)/, /^(?:\.\.)/, /^(?::[^#\n;]+)/, /^(?:-)/, /^(?:\.)/, /^(?:\+)/, /^(?:%)/, /^(?:=)/, /^(?:=)/, /^(?:[A-Za-z]+)/, /^(?:[!"#$%&'*+,-.`?\\_\/])/, /^(?:[0-9]+)/, /^(?:[\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6]|[\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377]|[\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5]|[\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA]|[\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE]|[\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA]|[\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0]|[\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977]|[\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2]|[\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A]|[\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39]|[\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8]|[\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C]|[\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C]|[\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99]|[\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0]|[\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D]|[\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3]|[\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10]|[\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1]|[\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81]|[\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3]|[\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6]|[\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A]|[\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081]|[\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D]|[\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0]|[\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310]|[\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C]|[\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711]|[\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7]|[\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C]|[\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16]|[\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF]|[\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC]|[\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D]|[\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D]|[\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3]|[\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F]|[\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128]|[\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184]|[\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3]|[\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6]|[\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE]|[\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C]|[\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D]|[\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC]|[\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B]|[\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788]|[\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805]|[\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB]|[\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28]|[\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5]|[\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4]|[\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E]|[\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D]|[\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36]|[\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D]|[\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC]|[\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF]|[\uFFD2-\uFFD7\uFFDA-\uFFDC])/, /^(?:\s)/, /^(?:$)/],
  36811. conditions: { "string": { "rules": [10, 11], "inclusive": false }, "struct": { "rules": [5, 6, 7], "inclusive": false }, "INITIAL": { "rules": [0, 1, 2, 3, 4, 8, 9, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32], "inclusive": true } }
  36812. };
  36813. return lexer;
  36814. })();
  36815. parser.lexer = lexer;
  36816. function Parser() {
  36817. this.yy = {};
  36818. }
  36819. Parser.prototype = parser;parser.Parser = Parser;
  36820. return new Parser();
  36821. })();
  36822. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  36823. exports.parser = parser;
  36824. exports.Parser = parser.Parser;
  36825. exports.parse = function () {
  36826. return parser.parse.apply(parser, arguments);
  36827. };
  36828. exports.main = function commonjsMain(args) {
  36829. if (!args[1]) {
  36830. console.log('Usage: ' + args[0] + ' FILE');
  36831. process.exit(1);
  36832. }
  36833. var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
  36834. return exports.parser.parse(source);
  36835. };
  36836. if (typeof module !== 'undefined' && require.main === module) {
  36837. exports.main(process.argv.slice(1));
  36838. }
  36839. }
  36840. }).call(this,require('_process'))
  36841. },{"_process":105,"fs":1,"path":104}],111:[function(require,module,exports){
  36842. (function (global){
  36843. /**
  36844. * Created by knut on 15-01-14.
  36845. */
  36846. 'use strict';
  36847. var Logger = require('../../logger');
  36848. var log = new Logger.Log();
  36849. var message = '';
  36850. var info = false;
  36851. exports.setMessage = function (txt) {
  36852. log.debug('Setting message to: ' + txt);
  36853. message = txt;
  36854. };
  36855. exports.getMessage = function () {
  36856. return message;
  36857. };
  36858. exports.setInfo = function (inf) {
  36859. info = inf;
  36860. };
  36861. exports.getInfo = function () {
  36862. return info;
  36863. };
  36864. exports.parseError = function (err, hash) {
  36865. global.mermaidAPI.parseError(err, hash);
  36866. };
  36867. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  36868. },{"../../logger":129}],112:[function(require,module,exports){
  36869. /**
  36870. * Created by knut on 14-12-11.
  36871. */
  36872. 'use strict';
  36873. var db = require('./exampleDb');
  36874. var exampleParser = require('./parser/example.js');
  36875. var d3 = require('../../d3');
  36876. var Logger = require('../../logger');
  36877. var log = new Logger.Log();
  36878. /**
  36879. * Draws a an info picture in the tag with id: id based on the graph definition in text.
  36880. * @param text
  36881. * @param id
  36882. */
  36883. exports.draw = function (txt, id, ver) {
  36884. var parser;
  36885. parser = exampleParser.parser;
  36886. parser.yy = db;
  36887. log.debug('Renering example diagram');
  36888. // Parse the graph definition
  36889. parser.parse(txt);
  36890. // Fetch the default direction, use TD if none was found
  36891. var svg = d3.select('#' + id);
  36892. var g = svg.append('g');
  36893. g.append('text') // text label for the x axis
  36894. .attr('x', 100).attr('y', 40).attr('class', 'version').attr('font-size', '32px').style('text-anchor', 'middle').text('mermaid ' + ver);
  36895. /*
  36896. var box = exports.bounds.getBounds();
  36897. var height = box.stopy-box.starty+2*conf.diagramMarginY;
  36898. var width = box.stopx-box.startx+2*conf.diagramMarginX;*/
  36899. svg.attr('height', 100);
  36900. svg.attr('width', 400);
  36901. //svg.attr('viewBox', '0 0 300 150');
  36902. };
  36903. },{"../../d3":107,"../../logger":129,"./exampleDb":111,"./parser/example.js":113}],113:[function(require,module,exports){
  36904. (function (process){
  36905. /* parser generated by jison 0.4.17 */
  36906. /*
  36907. Returns a Parser object of the following structure:
  36908. Parser: {
  36909. yy: {}
  36910. }
  36911. Parser.prototype: {
  36912. yy: {},
  36913. trace: function(),
  36914. symbols_: {associative list: name ==> number},
  36915. terminals_: {associative list: number ==> name},
  36916. productions_: [...],
  36917. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  36918. table: [...],
  36919. defaultActions: {...},
  36920. parseError: function(str, hash),
  36921. parse: function(input),
  36922. lexer: {
  36923. EOF: 1,
  36924. parseError: function(str, hash),
  36925. setInput: function(input),
  36926. input: function(),
  36927. unput: function(str),
  36928. more: function(),
  36929. less: function(n),
  36930. pastInput: function(),
  36931. upcomingInput: function(),
  36932. showPosition: function(),
  36933. test_match: function(regex_match_array, rule_index),
  36934. next: function(),
  36935. lex: function(),
  36936. begin: function(condition),
  36937. popState: function(),
  36938. _currentRules: function(),
  36939. topState: function(),
  36940. pushState: function(condition),
  36941. options: {
  36942. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  36943. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  36944. backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code)
  36945. },
  36946. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  36947. rules: [...],
  36948. conditions: {associative list: name ==> set},
  36949. }
  36950. }
  36951. token location info (@$, _$, etc.): {
  36952. first_line: n,
  36953. last_line: n,
  36954. first_column: n,
  36955. last_column: n,
  36956. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  36957. }
  36958. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  36959. text: (matched text)
  36960. token: (the produced terminal token, if any)
  36961. line: (yylineno)
  36962. }
  36963. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  36964. loc: (yylloc)
  36965. expected: (string describing the set of expected tokens)
  36966. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  36967. }
  36968. */
  36969. "use strict";
  36970. var parser = (function () {
  36971. var o = function o(k, v, _o, l) {
  36972. for (_o = _o || {}, l = k.length; l--; _o[k[l]] = v);return _o;
  36973. },
  36974. $V0 = [6, 9, 10, 12];
  36975. var parser = { trace: function trace() {},
  36976. yy: {},
  36977. symbols_: { "error": 2, "start": 3, "info": 4, "document": 5, "EOF": 6, "line": 7, "statement": 8, "NL": 9, "showInfo": 10, "message": 11, "say": 12, "TXT": 13, "$accept": 0, "$end": 1 },
  36978. terminals_: { 2: "error", 4: "info", 6: "EOF", 9: "NL", 10: "showInfo", 12: "say", 13: "TXT" },
  36979. productions_: [0, [3, 3], [5, 0], [5, 2], [7, 1], [7, 1], [8, 1], [8, 1], [11, 2]],
  36980. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, /* action[1] */$$, /* vstack */_$ /* lstack */) {
  36981. /* this == yyval */
  36982. var $0 = $$.length - 1;
  36983. switch (yystate) {
  36984. case 1:
  36985. return yy;
  36986. break;
  36987. case 4:
  36988. break;
  36989. case 6:
  36990. yy.setInfo(true);
  36991. break;
  36992. case 7:
  36993. yy.setMessage($$[$0]);
  36994. break;
  36995. case 8:
  36996. this.$ = $$[$0 - 1].substring(1).trim().replace(/\\n/gm, "\n");
  36997. break;
  36998. }
  36999. },
  37000. table: [{ 3: 1, 4: [1, 2] }, { 1: [3] }, o($V0, [2, 2], { 5: 3 }), { 6: [1, 4], 7: 5, 8: 6, 9: [1, 7], 10: [1, 8], 11: 9, 12: [1, 10] }, { 1: [2, 1] }, o($V0, [2, 3]), o($V0, [2, 4]), o($V0, [2, 5]), o($V0, [2, 6]), o($V0, [2, 7]), { 13: [1, 11] }, o($V0, [2, 8])],
  37001. defaultActions: { 4: [2, 1] },
  37002. parseError: function parseError(str, hash) {
  37003. if (hash.recoverable) {
  37004. this.trace(str);
  37005. } else {
  37006. var _parseError = function _parseError(msg, hash) {
  37007. this.message = msg;
  37008. this.hash = hash;
  37009. };
  37010. _parseError.prototype = Error;
  37011. throw new _parseError(str, hash);
  37012. }
  37013. },
  37014. parse: function parse(input) {
  37015. var self = this,
  37016. stack = [0],
  37017. tstack = [],
  37018. vstack = [null],
  37019. lstack = [],
  37020. table = this.table,
  37021. yytext = '',
  37022. yylineno = 0,
  37023. yyleng = 0,
  37024. recovering = 0,
  37025. TERROR = 2,
  37026. EOF = 1;
  37027. var args = lstack.slice.call(arguments, 1);
  37028. var lexer = Object.create(this.lexer);
  37029. var sharedState = { yy: {} };
  37030. for (var k in this.yy) {
  37031. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  37032. sharedState.yy[k] = this.yy[k];
  37033. }
  37034. }
  37035. lexer.setInput(input, sharedState.yy);
  37036. sharedState.yy.lexer = lexer;
  37037. sharedState.yy.parser = this;
  37038. if (typeof lexer.yylloc == 'undefined') {
  37039. lexer.yylloc = {};
  37040. }
  37041. var yyloc = lexer.yylloc;
  37042. lstack.push(yyloc);
  37043. var ranges = lexer.options && lexer.options.ranges;
  37044. if (typeof sharedState.yy.parseError === 'function') {
  37045. this.parseError = sharedState.yy.parseError;
  37046. } else {
  37047. this.parseError = Object.getPrototypeOf(this).parseError;
  37048. }
  37049. function popStack(n) {
  37050. stack.length = stack.length - 2 * n;
  37051. vstack.length = vstack.length - n;
  37052. lstack.length = lstack.length - n;
  37053. }
  37054. _token_stack: var lex = function lex() {
  37055. var token;
  37056. token = lexer.lex() || EOF;
  37057. if (typeof token !== 'number') {
  37058. token = self.symbols_[token] || token;
  37059. }
  37060. return token;
  37061. };
  37062. var symbol,
  37063. preErrorSymbol,
  37064. state,
  37065. action,
  37066. a,
  37067. r,
  37068. yyval = {},
  37069. p,
  37070. len,
  37071. newState,
  37072. expected;
  37073. while (true) {
  37074. state = stack[stack.length - 1];
  37075. if (this.defaultActions[state]) {
  37076. action = this.defaultActions[state];
  37077. } else {
  37078. if (symbol === null || typeof symbol == 'undefined') {
  37079. symbol = lex();
  37080. }
  37081. action = table[state] && table[state][symbol];
  37082. }
  37083. if (typeof action === 'undefined' || !action.length || !action[0]) {
  37084. var errStr = '';
  37085. expected = [];
  37086. for (p in table[state]) {
  37087. if (this.terminals_[p] && p > TERROR) {
  37088. expected.push('\'' + this.terminals_[p] + '\'');
  37089. }
  37090. }
  37091. if (lexer.showPosition) {
  37092. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  37093. } else {
  37094. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  37095. }
  37096. this.parseError(errStr, {
  37097. text: lexer.match,
  37098. token: this.terminals_[symbol] || symbol,
  37099. line: lexer.yylineno,
  37100. loc: yyloc,
  37101. expected: expected
  37102. });
  37103. }
  37104. if (action[0] instanceof Array && action.length > 1) {
  37105. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  37106. }
  37107. switch (action[0]) {
  37108. case 1:
  37109. stack.push(symbol);
  37110. vstack.push(lexer.yytext);
  37111. lstack.push(lexer.yylloc);
  37112. stack.push(action[1]);
  37113. symbol = null;
  37114. if (!preErrorSymbol) {
  37115. yyleng = lexer.yyleng;
  37116. yytext = lexer.yytext;
  37117. yylineno = lexer.yylineno;
  37118. yyloc = lexer.yylloc;
  37119. if (recovering > 0) {
  37120. recovering--;
  37121. }
  37122. } else {
  37123. symbol = preErrorSymbol;
  37124. preErrorSymbol = null;
  37125. }
  37126. break;
  37127. case 2:
  37128. len = this.productions_[action[1]][1];
  37129. yyval.$ = vstack[vstack.length - len];
  37130. yyval._$ = {
  37131. first_line: lstack[lstack.length - (len || 1)].first_line,
  37132. last_line: lstack[lstack.length - 1].last_line,
  37133. first_column: lstack[lstack.length - (len || 1)].first_column,
  37134. last_column: lstack[lstack.length - 1].last_column
  37135. };
  37136. if (ranges) {
  37137. yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
  37138. }
  37139. r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
  37140. if (typeof r !== 'undefined') {
  37141. return r;
  37142. }
  37143. if (len) {
  37144. stack = stack.slice(0, -1 * len * 2);
  37145. vstack = vstack.slice(0, -1 * len);
  37146. lstack = lstack.slice(0, -1 * len);
  37147. }
  37148. stack.push(this.productions_[action[1]][0]);
  37149. vstack.push(yyval.$);
  37150. lstack.push(yyval._$);
  37151. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  37152. stack.push(newState);
  37153. break;
  37154. case 3:
  37155. return true;
  37156. }
  37157. }
  37158. return true;
  37159. } };
  37160. /* generated by jison-lex 0.3.4 */
  37161. var lexer = (function () {
  37162. var lexer = {
  37163. EOF: 1,
  37164. parseError: function parseError(str, hash) {
  37165. if (this.yy.parser) {
  37166. this.yy.parser.parseError(str, hash);
  37167. } else {
  37168. throw new Error(str);
  37169. }
  37170. },
  37171. // resets the lexer, sets new input
  37172. setInput: function setInput(input, yy) {
  37173. this.yy = yy || this.yy || {};
  37174. this._input = input;
  37175. this._more = this._backtrack = this.done = false;
  37176. this.yylineno = this.yyleng = 0;
  37177. this.yytext = this.matched = this.match = '';
  37178. this.conditionStack = ['INITIAL'];
  37179. this.yylloc = {
  37180. first_line: 1,
  37181. first_column: 0,
  37182. last_line: 1,
  37183. last_column: 0
  37184. };
  37185. if (this.options.ranges) {
  37186. this.yylloc.range = [0, 0];
  37187. }
  37188. this.offset = 0;
  37189. return this;
  37190. },
  37191. // consumes and returns one char from the input
  37192. input: function input() {
  37193. var ch = this._input[0];
  37194. this.yytext += ch;
  37195. this.yyleng++;
  37196. this.offset++;
  37197. this.match += ch;
  37198. this.matched += ch;
  37199. var lines = ch.match(/(?:\r\n?|\n).*/g);
  37200. if (lines) {
  37201. this.yylineno++;
  37202. this.yylloc.last_line++;
  37203. } else {
  37204. this.yylloc.last_column++;
  37205. }
  37206. if (this.options.ranges) {
  37207. this.yylloc.range[1]++;
  37208. }
  37209. this._input = this._input.slice(1);
  37210. return ch;
  37211. },
  37212. // unshifts one char (or a string) into the input
  37213. unput: function unput(ch) {
  37214. var len = ch.length;
  37215. var lines = ch.split(/(?:\r\n?|\n)/g);
  37216. this._input = ch + this._input;
  37217. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  37218. //this.yyleng -= len;
  37219. this.offset -= len;
  37220. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  37221. this.match = this.match.substr(0, this.match.length - 1);
  37222. this.matched = this.matched.substr(0, this.matched.length - 1);
  37223. if (lines.length - 1) {
  37224. this.yylineno -= lines.length - 1;
  37225. }
  37226. var r = this.yylloc.range;
  37227. this.yylloc = {
  37228. first_line: this.yylloc.first_line,
  37229. last_line: this.yylineno + 1,
  37230. first_column: this.yylloc.first_column,
  37231. last_column: lines ? (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length : this.yylloc.first_column - len
  37232. };
  37233. if (this.options.ranges) {
  37234. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  37235. }
  37236. this.yyleng = this.yytext.length;
  37237. return this;
  37238. },
  37239. // When called from action, caches matched text and appends it on next action
  37240. more: function more() {
  37241. this._more = true;
  37242. return this;
  37243. },
  37244. // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
  37245. reject: function reject() {
  37246. if (this.options.backtrack_lexer) {
  37247. this._backtrack = true;
  37248. } else {
  37249. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), {
  37250. text: "",
  37251. token: null,
  37252. line: this.yylineno
  37253. });
  37254. }
  37255. return this;
  37256. },
  37257. // retain first n characters of the match
  37258. less: function less(n) {
  37259. this.unput(this.match.slice(n));
  37260. },
  37261. // displays already matched input, i.e. for error messages
  37262. pastInput: function pastInput() {
  37263. var past = this.matched.substr(0, this.matched.length - this.match.length);
  37264. return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
  37265. },
  37266. // displays upcoming input, i.e. for error messages
  37267. upcomingInput: function upcomingInput() {
  37268. var next = this.match;
  37269. if (next.length < 20) {
  37270. next += this._input.substr(0, 20 - next.length);
  37271. }
  37272. return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  37273. },
  37274. // displays the character position where the lexing error occurred, i.e. for error messages
  37275. showPosition: function showPosition() {
  37276. var pre = this.pastInput();
  37277. var c = new Array(pre.length + 1).join("-");
  37278. return pre + this.upcomingInput() + "\n" + c + "^";
  37279. },
  37280. // test the lexed token: return FALSE when not a match, otherwise return token
  37281. test_match: function test_match(match, indexed_rule) {
  37282. var token, lines, backup;
  37283. if (this.options.backtrack_lexer) {
  37284. // save context
  37285. backup = {
  37286. yylineno: this.yylineno,
  37287. yylloc: {
  37288. first_line: this.yylloc.first_line,
  37289. last_line: this.last_line,
  37290. first_column: this.yylloc.first_column,
  37291. last_column: this.yylloc.last_column
  37292. },
  37293. yytext: this.yytext,
  37294. match: this.match,
  37295. matches: this.matches,
  37296. matched: this.matched,
  37297. yyleng: this.yyleng,
  37298. offset: this.offset,
  37299. _more: this._more,
  37300. _input: this._input,
  37301. yy: this.yy,
  37302. conditionStack: this.conditionStack.slice(0),
  37303. done: this.done
  37304. };
  37305. if (this.options.ranges) {
  37306. backup.yylloc.range = this.yylloc.range.slice(0);
  37307. }
  37308. }
  37309. lines = match[0].match(/(?:\r\n?|\n).*/g);
  37310. if (lines) {
  37311. this.yylineno += lines.length;
  37312. }
  37313. this.yylloc = {
  37314. first_line: this.yylloc.last_line,
  37315. last_line: this.yylineno + 1,
  37316. first_column: this.yylloc.last_column,
  37317. last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
  37318. };
  37319. this.yytext += match[0];
  37320. this.match += match[0];
  37321. this.matches = match;
  37322. this.yyleng = this.yytext.length;
  37323. if (this.options.ranges) {
  37324. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  37325. }
  37326. this._more = false;
  37327. this._backtrack = false;
  37328. this._input = this._input.slice(match[0].length);
  37329. this.matched += match[0];
  37330. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  37331. if (this.done && this._input) {
  37332. this.done = false;
  37333. }
  37334. if (token) {
  37335. return token;
  37336. } else if (this._backtrack) {
  37337. // recover context
  37338. for (var k in backup) {
  37339. this[k] = backup[k];
  37340. }
  37341. return false; // rule action called reject() implying the next rule should be tested instead.
  37342. }
  37343. return false;
  37344. },
  37345. // return next match in input
  37346. next: function next() {
  37347. if (this.done) {
  37348. return this.EOF;
  37349. }
  37350. if (!this._input) {
  37351. this.done = true;
  37352. }
  37353. var token, match, tempMatch, index;
  37354. if (!this._more) {
  37355. this.yytext = '';
  37356. this.match = '';
  37357. }
  37358. var rules = this._currentRules();
  37359. for (var i = 0; i < rules.length; i++) {
  37360. tempMatch = this._input.match(this.rules[rules[i]]);
  37361. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  37362. match = tempMatch;
  37363. index = i;
  37364. if (this.options.backtrack_lexer) {
  37365. token = this.test_match(tempMatch, rules[i]);
  37366. if (token !== false) {
  37367. return token;
  37368. } else if (this._backtrack) {
  37369. match = false;
  37370. continue; // rule action called reject() implying a rule MISmatch.
  37371. } else {
  37372. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  37373. return false;
  37374. }
  37375. } else if (!this.options.flex) {
  37376. break;
  37377. }
  37378. }
  37379. }
  37380. if (match) {
  37381. token = this.test_match(match, rules[index]);
  37382. if (token !== false) {
  37383. return token;
  37384. }
  37385. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  37386. return false;
  37387. }
  37388. if (this._input === "") {
  37389. return this.EOF;
  37390. } else {
  37391. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  37392. text: "",
  37393. token: null,
  37394. line: this.yylineno
  37395. });
  37396. }
  37397. },
  37398. // return next match that has a token
  37399. lex: function lex() {
  37400. var r = this.next();
  37401. if (r) {
  37402. return r;
  37403. } else {
  37404. return this.lex();
  37405. }
  37406. },
  37407. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  37408. begin: function begin(condition) {
  37409. this.conditionStack.push(condition);
  37410. },
  37411. // pop the previously active lexer condition state off the condition stack
  37412. popState: function popState() {
  37413. var n = this.conditionStack.length - 1;
  37414. if (n > 0) {
  37415. return this.conditionStack.pop();
  37416. } else {
  37417. return this.conditionStack[0];
  37418. }
  37419. },
  37420. // produce the lexer rule set which is active for the currently active lexer condition state
  37421. _currentRules: function _currentRules() {
  37422. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  37423. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  37424. } else {
  37425. return this.conditions["INITIAL"].rules;
  37426. }
  37427. },
  37428. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  37429. topState: function topState(n) {
  37430. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  37431. if (n >= 0) {
  37432. return this.conditionStack[n];
  37433. } else {
  37434. return "INITIAL";
  37435. }
  37436. },
  37437. // alias for begin(condition)
  37438. pushState: function pushState(condition) {
  37439. this.begin(condition);
  37440. },
  37441. // return the number of states currently on the stack
  37442. stateStackSize: function stateStackSize() {
  37443. return this.conditionStack.length;
  37444. },
  37445. options: { "case-insensitive": true },
  37446. performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
  37447. // Pre-lexer code can go here
  37448. var YYSTATE = YY_START;
  37449. switch ($avoiding_name_collisions) {
  37450. case 0:
  37451. return 9;
  37452. break;
  37453. case 1:
  37454. return 10;
  37455. break;
  37456. case 2:
  37457. return 4;
  37458. break;
  37459. case 3:
  37460. return 12;
  37461. break;
  37462. case 4:
  37463. return 13;
  37464. break;
  37465. case 5:
  37466. return 6;
  37467. break;
  37468. case 6:
  37469. return 'INVALID';
  37470. break;
  37471. }
  37472. },
  37473. rules: [/^(?:[\n]+)/i, /^(?:showInfo\b)/i, /^(?:info\b)/i, /^(?:say\b)/i, /^(?::[^#\n;]+)/i, /^(?:$)/i, /^(?:.)/i],
  37474. conditions: { "INITIAL": { "rules": [0, 1, 2, 3, 4, 5, 6], "inclusive": true } }
  37475. };
  37476. return lexer;
  37477. })();
  37478. parser.lexer = lexer;
  37479. function Parser() {
  37480. this.yy = {};
  37481. }
  37482. Parser.prototype = parser;parser.Parser = Parser;
  37483. return new Parser();
  37484. })();
  37485. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  37486. exports.parser = parser;
  37487. exports.Parser = parser.Parser;
  37488. exports.parse = function () {
  37489. return parser.parse.apply(parser, arguments);
  37490. };
  37491. exports.main = function commonjsMain(args) {
  37492. if (!args[1]) {
  37493. console.log('Usage: ' + args[0] + ' FILE');
  37494. process.exit(1);
  37495. }
  37496. var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
  37497. return exports.parser.parse(source);
  37498. };
  37499. if (typeof module !== 'undefined' && require.main === module) {
  37500. exports.main(process.argv.slice(1));
  37501. }
  37502. }
  37503. }).call(this,require('_process'))
  37504. },{"_process":105,"fs":1,"path":104}],114:[function(require,module,exports){
  37505. /* global window */
  37506. 'use strict';
  37507. var Logger = require('../../logger');
  37508. var log = new Logger.Log();
  37509. var dagreD3;
  37510. //log.debug('setting up dagre-d3');
  37511. if (require) {
  37512. try {
  37513. dagreD3 = require('dagre-d3');
  37514. //log.debug('Got it (dagre-d3)');
  37515. } catch (e) {
  37516. log.debug('Could not load dagre-d3');
  37517. }
  37518. }
  37519. if (!dagreD3) {
  37520. dagreD3 = window.dagreD3;
  37521. }
  37522. module.exports = dagreD3;
  37523. },{"../../logger":129,"dagre-d3":2}],115:[function(require,module,exports){
  37524. /**
  37525. * Created by knut on 14-12-11.
  37526. */
  37527. 'use strict';
  37528. var graph = require('./graphDb');
  37529. var flow = require('./parser/flow');
  37530. var dot = require('./parser/dot');
  37531. var d3 = require('../../d3');
  37532. var dagreD3 = require('./dagre-d3');
  37533. var Logger = require('../../logger');
  37534. var log = new Logger.Log();
  37535. var conf = {};
  37536. module.exports.setConf = function (cnf) {
  37537. var keys = Object.keys(cnf);
  37538. var i;
  37539. for (i = 0; i < keys.length; i++) {
  37540. conf[keys[i]] = cnf[keys[i]];
  37541. }
  37542. };
  37543. /**
  37544. * Function that adds the vertices found in the graph definition to the graph to be rendered.
  37545. * @param vert Object containing the vertices.
  37546. * @param g The graph that is to be drawn.
  37547. */
  37548. exports.addVertices = function (vert, g) {
  37549. var keys = Object.keys(vert);
  37550. var styleFromStyleArr = function styleFromStyleArr(styleStr, arr) {
  37551. var i;
  37552. // Create a compound style definition from the style definitions found for the node in the graph definition
  37553. for (i = 0; i < arr.length; i++) {
  37554. if (typeof arr[i] !== 'undefined') {
  37555. styleStr = styleStr + arr[i] + ';';
  37556. }
  37557. }
  37558. return styleStr;
  37559. };
  37560. // Iterate through each item in the vertice object (containing all the vertices found) in the graph definition
  37561. keys.forEach(function (id) {
  37562. var vertice = vert[id];
  37563. var verticeText;
  37564. /**
  37565. * Variable for storing the classes for the vertice
  37566. * @type {string}
  37567. */
  37568. var classStr = '';
  37569. //log.debug(vertice.classes);
  37570. if (vertice.classes.length > 0) {
  37571. classStr = vertice.classes.join(' ');
  37572. }
  37573. /**
  37574. * Variable for storing the extracted style for the vertice
  37575. * @type {string}
  37576. */
  37577. var style = '';
  37578. // Create a compound style definition from the style definitions found for the node in the graph definition
  37579. style = styleFromStyleArr(style, vertice.styles);
  37580. // Use vertice id as text in the box if no text is provided by the graph definition
  37581. if (typeof vertice.text === 'undefined') {
  37582. verticeText = vertice.id;
  37583. } else {
  37584. verticeText = vertice.text;
  37585. }
  37586. var labelTypeStr = '';
  37587. if (conf.htmlLabels) {
  37588. labelTypeStr = 'html';
  37589. verticeText = verticeText.replace(/fa:fa[\w\-]+/g, function (s) {
  37590. return '<i class="fa ' + s.substring(3) + '"></i>';
  37591. });
  37592. } else {
  37593. var svg_label = document.createElementNS('http://www.w3.org/2000/svg', 'text');
  37594. var rows = verticeText.split(/<br>/);
  37595. var j = 0;
  37596. for (j = 0; j < rows.length; j++) {
  37597. var tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan');
  37598. tspan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  37599. tspan.setAttribute('dy', '1em');
  37600. tspan.setAttribute('x', '1');
  37601. tspan.textContent = rows[j];
  37602. svg_label.appendChild(tspan);
  37603. }
  37604. labelTypeStr = 'svg';
  37605. verticeText = svg_label;
  37606. //verticeText = verticeText.replace(/<br\/>/g, '\n');
  37607. //labelTypeStr = 'text';
  37608. }
  37609. var radious = 0;
  37610. var _shape = '';
  37611. // Set the shape based parameters
  37612. switch (vertice.type) {
  37613. case 'round':
  37614. radious = 5;
  37615. _shape = 'rect';
  37616. break;
  37617. case 'square':
  37618. _shape = 'rect';
  37619. break;
  37620. case 'diamond':
  37621. _shape = 'question';
  37622. break;
  37623. case 'odd':
  37624. _shape = 'rect_left_inv_arrow';
  37625. break;
  37626. case 'odd_right':
  37627. _shape = 'rect_left_inv_arrow';
  37628. break;
  37629. case 'circle':
  37630. _shape = 'circle';
  37631. break;
  37632. case 'ellipse':
  37633. _shape = 'ellipse';
  37634. break;
  37635. case 'group':
  37636. _shape = 'rect';
  37637. // Need to create a text node if using svg labels, see #367
  37638. verticeText = conf.htmlLabels ? '' : document.createElementNS('http://www.w3.org/2000/svg', 'text');
  37639. break;
  37640. default:
  37641. _shape = 'rect';
  37642. }
  37643. // Add the node
  37644. g.setNode(vertice.id, { labelType: labelTypeStr, shape: _shape, label: verticeText, rx: radious, ry: radious, 'class': classStr, style: style, id: vertice.id });
  37645. });
  37646. };
  37647. /**
  37648. * Add edges to graph based on parsed graph defninition
  37649. * @param {Object} edges The edges to add to the graph
  37650. * @param {Object} g The graph object
  37651. */
  37652. exports.addEdges = function (edges, g) {
  37653. var cnt = 0;
  37654. var defaultStyle;
  37655. if (typeof edges.defaultStyle !== 'undefined') {
  37656. defaultStyle = edges.defaultStyle.toString().replace(/,/g, ';');
  37657. }
  37658. edges.forEach(function (edge) {
  37659. cnt++;
  37660. var edgeData = {};
  37661. // Set link type for rendering
  37662. if (edge.type === 'arrow_open') {
  37663. edgeData.arrowhead = 'none';
  37664. } else {
  37665. edgeData.arrowhead = 'normal';
  37666. }
  37667. var style = '';
  37668. if (typeof edge.style !== 'undefined') {
  37669. edge.style.forEach(function (s) {
  37670. style = style + s + ';';
  37671. });
  37672. } else {
  37673. switch (edge.stroke) {
  37674. case 'normal':
  37675. style = 'fill:none';
  37676. if (typeof defaultStyle !== 'undefined') {
  37677. style = defaultStyle;
  37678. }
  37679. break;
  37680. case 'dotted':
  37681. style = 'stroke: #333; fill:none;stroke-width:2px;stroke-dasharray:3;';
  37682. break;
  37683. case 'thick':
  37684. style = 'stroke: #333; stroke-width: 3.5px;fill:none';
  37685. break;
  37686. }
  37687. }
  37688. edgeData.style = style;
  37689. if (typeof edge.interpolate !== 'undefined') {
  37690. edgeData.lineInterpolate = edge.interpolate;
  37691. } else {
  37692. if (typeof edges.defaultInterpolate !== 'undefined') {
  37693. edgeData.lineInterpolate = edges.defaultInterpolate;
  37694. }
  37695. }
  37696. if (typeof edge.text === 'undefined') {
  37697. if (typeof edge.style !== 'undefined') {
  37698. edgeData.arrowheadStyle = 'fill: #333';
  37699. }
  37700. } else {
  37701. edgeData.arrowheadStyle = 'fill: #333';
  37702. if (typeof edge.style === 'undefined') {
  37703. edgeData.labelpos = 'c';
  37704. if (conf.htmlLabels) {
  37705. edgeData.labelType = 'html';
  37706. edgeData.label = '<span class="edgeLabel">' + edge.text + '</span>';
  37707. } else {
  37708. edgeData.labelType = 'text';
  37709. edgeData.style = 'stroke: #333; stroke-width: 1.5px;fill:none';
  37710. edgeData.label = edge.text.replace(/<br>/g, '\n');
  37711. }
  37712. } else {
  37713. edgeData.label = edge.text.replace(/<br>/g, '\n');
  37714. }
  37715. }
  37716. // Add the edge to the graph
  37717. g.setEdge(edge.start, edge.end, edgeData, cnt);
  37718. });
  37719. };
  37720. /**
  37721. * Returns the all the styles from classDef statements in the graph definition.
  37722. * @returns {object} classDef styles
  37723. */
  37724. exports.getClasses = function (text, isDot) {
  37725. var parser;
  37726. graph.clear();
  37727. if (isDot) {
  37728. parser = dot.parser;
  37729. } else {
  37730. parser = flow.parser;
  37731. }
  37732. parser.yy = graph;
  37733. // Parse the graph definition
  37734. parser.parse(text);
  37735. var classes = graph.getClasses();
  37736. // Add default class if undefined
  37737. if (typeof classes['default'] === 'undefined') {
  37738. classes['default'] = { id: 'default' };
  37739. //classes.default.styles = ['fill:#ffa','stroke:#666','stroke-width:3px'];
  37740. classes['default'].styles = [];
  37741. classes['default'].clusterStyles = ['rx:4px', 'fill: rgb(255, 255, 222)', 'rx: 4px', 'stroke: rgb(170, 170, 51)', 'stroke-width: 1px'];
  37742. classes['default'].nodeLabelStyles = ['fill:#000', 'stroke:none', 'font-weight:300', 'font-family:"Helvetica Neue",Helvetica,Arial,sans-serf', 'font-size:14px'];
  37743. classes['default'].edgeLabelStyles = ['fill:#000', 'stroke:none', 'font-weight:300', 'font-family:"Helvetica Neue",Helvetica,Arial,sans-serf', 'font-size:14px'];
  37744. }
  37745. return classes;
  37746. };
  37747. /**
  37748. * Draws a flowchart in the tag with id: id based on the graph definition in text.
  37749. * @param text
  37750. * @param id
  37751. */
  37752. exports.draw = function (text, id, isDot) {
  37753. log.debug('Drawing flowchart');
  37754. var parser;
  37755. graph.clear();
  37756. if (isDot) {
  37757. parser = dot.parser;
  37758. } else {
  37759. parser = flow.parser;
  37760. }
  37761. parser.yy = graph;
  37762. // Parse the graph definition
  37763. try {
  37764. parser.parse(text);
  37765. } catch (err) {
  37766. log.debug('Parsing failed');
  37767. }
  37768. // Fetch the default direction, use TD if none was found
  37769. var dir;
  37770. dir = graph.getDirection();
  37771. if (typeof dir === 'undefined') {
  37772. dir = 'TD';
  37773. }
  37774. // Create the input mermaid.graph
  37775. var g = new dagreD3.graphlib.Graph({
  37776. multigraph: true,
  37777. compound: true
  37778. }).setGraph({
  37779. rankdir: dir,
  37780. marginx: 20,
  37781. marginy: 20
  37782. }).setDefaultEdgeLabel(function () {
  37783. return {};
  37784. });
  37785. var subG;
  37786. var subGraphs = graph.getSubGraphs();
  37787. var i = 0;
  37788. for (i = subGraphs.length - 1; i >= 0; i--) {
  37789. subG = subGraphs[i];
  37790. graph.addVertex(subG.id, subG.title, 'group', undefined);
  37791. }
  37792. // Fetch the verices/nodes and edges/links from the parsed graph definition
  37793. var vert = graph.getVertices();
  37794. //log.debug(vert);
  37795. var edges = graph.getEdges();
  37796. i = 0;
  37797. var j;
  37798. for (i = subGraphs.length - 1; i >= 0; i--) {
  37799. subG = subGraphs[i];
  37800. d3.selectAll('cluster').append('text');
  37801. for (j = 0; j < subG.nodes.length; j++) {
  37802. //log.debug('Setting node',subG.nodes[j],' to subgraph '+id);
  37803. g.setParent(subG.nodes[j], subG.id);
  37804. }
  37805. }
  37806. exports.addVertices(vert, g);
  37807. exports.addEdges(edges, g);
  37808. // Create the renderer
  37809. var render = new dagreD3.render();
  37810. // Add custom shape for rhombus type of boc (decision)
  37811. render.shapes().question = function (parent, bbox, node) {
  37812. var w = bbox.width,
  37813. h = bbox.height,
  37814. s = (w + h) * 0.8,
  37815. points = [{ x: s / 2, y: 0 }, { x: s, y: -s / 2 }, { x: s / 2, y: -s }, { x: 0, y: -s / 2 }];
  37816. var shapeSvg = parent.insert('polygon', ':first-child').attr('points', points.map(function (d) {
  37817. return d.x + ',' + d.y;
  37818. }).join(' ')).attr('rx', 5).attr('ry', 5).attr('transform', 'translate(' + -s / 2 + ',' + s * 2 / 4 + ')');
  37819. node.intersect = function (point) {
  37820. return dagreD3.intersect.polygon(node, points, point);
  37821. };
  37822. return shapeSvg;
  37823. };
  37824. // Add custom shape for box with inverted arrow on left side
  37825. render.shapes().rect_left_inv_arrow = function (parent, bbox, node) {
  37826. var w = bbox.width,
  37827. h = bbox.height,
  37828. points = [{ x: -h / 2, y: 0 }, { x: w, y: 0 }, { x: w, y: -h }, { x: -h / 2, y: -h }, { x: 0, y: -h / 2 }];
  37829. var shapeSvg = parent.insert('polygon', ':first-child').attr('points', points.map(function (d) {
  37830. return d.x + ',' + d.y;
  37831. }).join(' ')).attr('transform', 'translate(' + -w / 2 + ',' + h * 2 / 4 + ')');
  37832. node.intersect = function (point) {
  37833. return dagreD3.intersect.polygon(node, points, point);
  37834. };
  37835. return shapeSvg;
  37836. };
  37837. // Add custom shape for box with inverted arrow on right side
  37838. render.shapes().rect_right_inv_arrow = function (parent, bbox, node) {
  37839. var w = bbox.width,
  37840. h = bbox.height,
  37841. points = [{ x: 0, y: 0 }, { x: w + h / 2, y: 0 }, { x: w, y: -h / 2 }, { x: w + h / 2, y: -h }, { x: 0, y: -h }];
  37842. var shapeSvg = parent.insert('polygon', ':first-child').attr('points', points.map(function (d) {
  37843. return d.x + ',' + d.y;
  37844. }).join(' ')).attr('transform', 'translate(' + -w / 2 + ',' + h * 2 / 4 + ')');
  37845. node.intersect = function (point) {
  37846. return dagreD3.intersect.polygon(node, points, point);
  37847. };
  37848. return shapeSvg;
  37849. };
  37850. // Add our custom arrow - an empty arrowhead
  37851. render.arrows().none = function normal(parent, id, edge, type) {
  37852. var marker = parent.append('marker').attr('id', id).attr('viewBox', '0 0 10 10').attr('refX', 9).attr('refY', 5).attr('markerUnits', 'strokeWidth').attr('markerWidth', 8).attr('markerHeight', 6).attr('orient', 'auto');
  37853. var path = marker.append('path').attr('d', 'M 0 0 L 0 0 L 0 0 z');
  37854. dagreD3.util.applyStyle(path, edge[type + 'Style']);
  37855. };
  37856. // Override normal arrowhead defined in d3. Remove style & add class to allow css styling.
  37857. render.arrows().normal = function normal(parent, id, edge, type) {
  37858. var marker = parent.append("marker").attr("id", id).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerUnits", "strokeWidth").attr("markerWidth", 8).attr("markerHeight", 6).attr("orient", "auto");
  37859. var path = marker.append("path").attr("d", "M 0 0 L 10 5 L 0 10 z").attr("class", "arrowheadPath").style("stroke-width", 1).style("stroke-dasharray", "1,0");
  37860. };
  37861. // Set up an SVG group so that we can translate the final graph.
  37862. var svg = d3.select('#' + id);
  37863. //svgGroup = d3.select('#' + id + ' g');
  37864. // Run the renderer. This is what draws the final graph.
  37865. var element = d3.select('#' + id + ' g');
  37866. render(element, g);
  37867. //var tip = d3.tip().html(function(d) { return d; });
  37868. element.selectAll('g.node').attr('title', function () {
  37869. return graph.getTooltip(this.id);
  37870. });
  37871. /*
  37872. var xPos = document.querySelectorAll('.clusters rect')[0].x.baseVal.value;
  37873. var width = document.querySelectorAll('.clusters rect')[0].width.baseVal.value;
  37874. var cluster = d3.selectAll('.cluster');
  37875. var te = cluster.append('text');
  37876. te.attr('x', xPos+width/2);
  37877. te.attr('y', 12);
  37878. //te.stroke('black');
  37879. te.attr('id', 'apa12');
  37880. te.style('text-anchor', 'middle');
  37881. te.text('Title for cluster');
  37882. */
  37883. if (conf.useMaxWidth) {
  37884. // Center the graph
  37885. svg.attr('height', '100%');
  37886. svg.attr('width', conf.width);
  37887. //svg.attr('viewBox', svgb.getBBox().x + ' 0 '+ g.graph().width+' '+ g.graph().height);
  37888. svg.attr('viewBox', '0 0 ' + (g.graph().width + 20) + ' ' + (g.graph().height + 20));
  37889. svg.attr('style', 'max-width:' + (g.graph().width + 20) + 'px;');
  37890. } else {
  37891. // Center the graph
  37892. svg.attr('height', g.graph().height);
  37893. if (typeof conf.width === 'undefined') {
  37894. svg.attr('width', g.graph().width);
  37895. } else {
  37896. svg.attr('width', conf.width);
  37897. }
  37898. //svg.attr('viewBox', svgb.getBBox().x + ' 0 '+ g.graph().width+' '+ g.graph().height);
  37899. svg.attr('viewBox', '0 0 ' + (g.graph().width + 20) + ' ' + (g.graph().height + 20));
  37900. }
  37901. // Index nodes
  37902. graph.indexNodes('subGraph' + i);
  37903. for (i = 0; i < subGraphs.length; i++) {
  37904. subG = subGraphs[i];
  37905. if (subG.title !== 'undefined') {
  37906. var clusterRects = document.querySelectorAll('#' + id + ' #' + subG.id + ' rect');
  37907. //log.debug('looking up: #' + id + ' #' + subG.id)
  37908. var clusterEl = document.querySelectorAll('#' + id + ' #' + subG.id);
  37909. var xPos = clusterRects[0].x.baseVal.value;
  37910. var yPos = clusterRects[0].y.baseVal.value;
  37911. var width = clusterRects[0].width.baseVal.value;
  37912. var cluster = d3.select(clusterEl[0]);
  37913. var te = cluster.append('text');
  37914. te.attr('x', xPos + width / 2);
  37915. te.attr('y', yPos + 14);
  37916. te.attr('fill', 'black');
  37917. te.attr('stroke', 'none');
  37918. te.attr('id', id + 'Text');
  37919. te.style('text-anchor', 'middle');
  37920. if (typeof subG.title === 'undefined') {
  37921. te.text('Undef');
  37922. } else {
  37923. //te.text(subGraphs[subGraphs.length-i-1].title);
  37924. te.text(subG.title);
  37925. }
  37926. }
  37927. }
  37928. // Add label rects for non html labels
  37929. if (!conf.htmlLabels) {
  37930. var labels = document.querySelectorAll('#' + id + ' .edgeLabel .label');
  37931. var i;
  37932. for (i = 0; i < labels.length; i++) {
  37933. var label = labels[i];
  37934. // Get dimensions of label
  37935. var dim = label.getBBox();
  37936. var rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
  37937. rect.setAttribute('rx', 0);
  37938. rect.setAttribute('ry', 0);
  37939. rect.setAttribute('width', dim.width);
  37940. rect.setAttribute('height', dim.height);
  37941. rect.setAttribute('style', 'fill:#e8e8e8;');
  37942. label.insertBefore(rect, label.firstChild);
  37943. }
  37944. }
  37945. };
  37946. },{"../../d3":107,"../../logger":129,"./dagre-d3":114,"./graphDb":116,"./parser/dot":117,"./parser/flow":118}],116:[function(require,module,exports){
  37947. (function (global){
  37948. /**
  37949. * Created by knut on 14-11-03.
  37950. */
  37951. 'use strict';
  37952. var Logger = require('../../logger');
  37953. var log = new Logger.Log();
  37954. var utils = require('../../utils');
  37955. var d3 = require('../../d3');
  37956. var vertices = {};
  37957. var edges = [];
  37958. var classes = [];
  37959. var subGraphs = [];
  37960. var tooltips = {};
  37961. var subCount = 0;
  37962. var direction;
  37963. // Functions to be run after graph rendering
  37964. var funs = [];
  37965. /**
  37966. * Function called by parser when a node definition has been found
  37967. * @param id
  37968. * @param text
  37969. * @param type
  37970. * @param style
  37971. */
  37972. exports.addVertex = function (id, text, type, style) {
  37973. var txt;
  37974. if (typeof id === 'undefined') {
  37975. return;
  37976. }
  37977. if (id.trim().length === 0) {
  37978. return;
  37979. }
  37980. if (typeof vertices[id] === 'undefined') {
  37981. vertices[id] = { id: id, styles: [], classes: [] };
  37982. }
  37983. if (typeof text !== 'undefined') {
  37984. txt = text.trim();
  37985. // strip quotes if string starts and exnds with a quote
  37986. if (txt[0] === '"' && txt[txt.length - 1] === '"') {
  37987. txt = txt.substring(1, txt.length - 1);
  37988. }
  37989. vertices[id].text = txt;
  37990. }
  37991. if (typeof type !== 'undefined') {
  37992. vertices[id].type = type;
  37993. }
  37994. if (typeof type !== 'undefined') {
  37995. vertices[id].type = type;
  37996. }
  37997. if (typeof style !== 'undefined') {
  37998. if (style !== null) {
  37999. style.forEach(function (s) {
  38000. vertices[id].styles.push(s);
  38001. });
  38002. }
  38003. }
  38004. };
  38005. /**
  38006. * Function called by parser when a link/edge definition has been found
  38007. * @param start
  38008. * @param end
  38009. * @param type
  38010. * @param linktext
  38011. */
  38012. exports.addLink = function (start, end, type, linktext) {
  38013. log.info('Got edge...', start, end);
  38014. var edge = { start: start, end: end, type: undefined, text: '' };
  38015. linktext = type.text;
  38016. if (typeof linktext !== 'undefined') {
  38017. edge.text = linktext.trim();
  38018. // strip quotes if string starts and exnds with a quote
  38019. if (edge.text[0] === '"' && edge.text[edge.text.length - 1] === '"') {
  38020. edge.text = edge.text.substring(1, edge.text.length - 1);
  38021. }
  38022. }
  38023. if (typeof type !== 'undefined') {
  38024. edge.type = type.type;
  38025. edge.stroke = type.stroke;
  38026. }
  38027. edges.push(edge);
  38028. };
  38029. /**
  38030. * Updates a link's line interpolation algorithm
  38031. * @param pos
  38032. * @param interpolate
  38033. */
  38034. exports.updateLinkInterpolate = function (pos, interp) {
  38035. if (pos === 'default') {
  38036. edges.defaultInterpolate = interp;
  38037. } else {
  38038. edges[pos].interpolate = interp;
  38039. }
  38040. };
  38041. /**
  38042. * Updates a link with a style
  38043. * @param pos
  38044. * @param style
  38045. */
  38046. exports.updateLink = function (pos, style) {
  38047. if (pos === 'default') {
  38048. edges.defaultStyle = style;
  38049. } else {
  38050. if (utils.isSubstringInArray('fill', style) === -1) {
  38051. style.push('fill:none');
  38052. }
  38053. edges[pos].style = style;
  38054. }
  38055. };
  38056. exports.addClass = function (id, style) {
  38057. if (typeof classes[id] === 'undefined') {
  38058. classes[id] = { id: id, styles: [] };
  38059. }
  38060. if (typeof style !== 'undefined') {
  38061. if (style !== null) {
  38062. style.forEach(function (s) {
  38063. classes[id].styles.push(s);
  38064. });
  38065. }
  38066. }
  38067. };
  38068. /**
  38069. * Called by parser when a graph definition is found, stores the direction of the chart.
  38070. * @param dir
  38071. */
  38072. exports.setDirection = function (dir) {
  38073. direction = dir;
  38074. };
  38075. /**
  38076. * Called by parser when a graph definition is found, stores the direction of the chart.
  38077. * @param dir
  38078. */
  38079. exports.setClass = function (id, className) {
  38080. if (id.indexOf(',') > 0) {
  38081. id.split(',').forEach(function (id2) {
  38082. if (typeof vertices[id2] !== 'undefined') {
  38083. vertices[id2].classes.push(className);
  38084. }
  38085. });
  38086. } else {
  38087. if (typeof vertices[id] !== 'undefined') {
  38088. vertices[id].classes.push(className);
  38089. }
  38090. }
  38091. };
  38092. var setTooltip = function setTooltip(id, tooltip) {
  38093. if (typeof tooltip !== 'undefined') {
  38094. tooltips[id] = tooltip;
  38095. }
  38096. };
  38097. var setClickFun = function setClickFun(id, functionName) {
  38098. if (typeof functionName === 'undefined') {
  38099. return;
  38100. }
  38101. if (typeof vertices[id] !== 'undefined') {
  38102. funs.push(function (element) {
  38103. var elem = d3.select(element).select('#' + id);
  38104. if (elem !== null) {
  38105. elem.on('click', function () {
  38106. eval(functionName + '(\'' + id + '\')'); // jshint ignore:line
  38107. });
  38108. }
  38109. });
  38110. }
  38111. };
  38112. var setLink = function setLink(id, linkStr) {
  38113. if (typeof linkStr === 'undefined') {
  38114. return;
  38115. }
  38116. if (typeof vertices[id] !== 'undefined') {
  38117. funs.push(function (element) {
  38118. var elem = d3.select(element).select('#' + id);
  38119. if (elem !== null) {
  38120. elem.on('click', function () {
  38121. window.open(linkStr, 'newTab'); // jshint ignore:line
  38122. });
  38123. }
  38124. });
  38125. }
  38126. };
  38127. exports.getTooltip = function (id) {
  38128. return tooltips[id];
  38129. };
  38130. /**
  38131. * Called by parser when a graph definition is found, stores the direction of the chart.
  38132. * @param dir
  38133. */
  38134. exports.setClickEvent = function (id, functionName, link, tooltip) {
  38135. if (id.indexOf(',') > 0) {
  38136. id.split(',').forEach(function (id2) {
  38137. setTooltip(id2, tooltip);
  38138. setClickFun(id2, functionName);
  38139. setLink(id2, link);
  38140. });
  38141. } else {
  38142. setTooltip(id, tooltip);
  38143. setClickFun(id, functionName);
  38144. setLink(id, link);
  38145. }
  38146. };
  38147. exports.bindFunctions = function (element) {
  38148. funs.forEach(function (fun) {
  38149. fun(element);
  38150. });
  38151. };
  38152. exports.getDirection = function () {
  38153. return direction;
  38154. };
  38155. /**
  38156. * Retrieval function for fetching the found nodes after parsing has completed.
  38157. * @returns {{}|*|vertices}
  38158. */
  38159. exports.getVertices = function () {
  38160. return vertices;
  38161. };
  38162. /**
  38163. * Retrieval function for fetching the found links after parsing has completed.
  38164. * @returns {{}|*|edges}
  38165. */
  38166. exports.getEdges = function () {
  38167. return edges;
  38168. };
  38169. /**
  38170. * Retrieval function for fetching the found class definitions after parsing has completed.
  38171. * @returns {{}|*|classes}
  38172. */
  38173. exports.getClasses = function () {
  38174. return classes;
  38175. };
  38176. var setupToolTips = function setupToolTips(element) {
  38177. var tooltipElem = d3.select('.mermaidTooltip');
  38178. if (tooltipElem[0][0] === null) {
  38179. tooltipElem = d3.select('body').append('div').attr('class', 'mermaidTooltip').style('opacity', 0);
  38180. }
  38181. var svg = d3.select(element).select('svg');
  38182. var nodes = svg.selectAll('g.node');
  38183. nodes.on('mouseover', function () {
  38184. var el = d3.select(this);
  38185. var title = el.attr('title');
  38186. // Dont try to draw a tooltip if no data is provided
  38187. if (title === null) {
  38188. return;
  38189. }
  38190. var rect = this.getBoundingClientRect();
  38191. tooltipElem.transition().duration(200).style('opacity', '.9');
  38192. tooltipElem.html(el.attr('title')).style('left', rect.left + (rect.right - rect.left) / 2 + 'px').style('top', rect.top - 14 + document.body.scrollTop + 'px');
  38193. el.classed('hover', true);
  38194. }).on('mouseout', function () {
  38195. tooltipElem.transition().duration(500).style('opacity', 0);
  38196. var el = d3.select(this);
  38197. el.classed('hover', false);
  38198. });
  38199. };
  38200. funs.push(setupToolTips);
  38201. /**
  38202. * Clears the internal graph db so that a new graph can be parsed.
  38203. */
  38204. exports.clear = function () {
  38205. vertices = {};
  38206. classes = {};
  38207. edges = [];
  38208. funs = [];
  38209. funs.push(setupToolTips);
  38210. subGraphs = [];
  38211. subCount = 0;
  38212. tooltips = [];
  38213. };
  38214. /**
  38215. *
  38216. * @returns {string}
  38217. */
  38218. exports.defaultStyle = function () {
  38219. return 'fill:#ffa;stroke: #f66; stroke-width: 3px; stroke-dasharray: 5, 5;fill:#ffa;stroke: #666;';
  38220. };
  38221. /**
  38222. * Clears the internal graph db so that a new graph can be parsed.
  38223. */
  38224. exports.addSubGraph = function (list, title) {
  38225. function uniq(a) {
  38226. var prims = { 'boolean': {}, 'number': {}, 'string': {} },
  38227. objs = [];
  38228. return a.filter(function (item) {
  38229. var type = typeof item;
  38230. if (item === ' ') {
  38231. return false;
  38232. }
  38233. if (type in prims) return prims[type].hasOwnProperty(item) ? false : prims[type][item] = true;else return objs.indexOf(item) >= 0 ? false : objs.push(item);
  38234. });
  38235. }
  38236. var nodeList = [];
  38237. nodeList = uniq(nodeList.concat.apply(nodeList, list));
  38238. var subGraph = { id: 'subGraph' + subCount, nodes: nodeList, title: title };
  38239. //log.debug('subGraph:' + subGraph.title + subGraph.id);
  38240. //log.debug(subGraph.nodes);
  38241. subGraphs.push(subGraph);
  38242. subCount = subCount + 1;
  38243. return subGraph.id;
  38244. };
  38245. var getPosForId = function getPosForId(id) {
  38246. var i;
  38247. for (i = 0; i < subGraphs.length; i++) {
  38248. if (subGraphs[i].id === id) {
  38249. //log.debug('Found pos for ',id,' ',i);
  38250. return i;
  38251. }
  38252. }
  38253. //log.debug('No pos found for ',id,' ',i);
  38254. return -1;
  38255. };
  38256. var secCount = -1;
  38257. var posCrossRef = [];
  38258. var indexNodes = function indexNodes(id, pos) {
  38259. var nodes = subGraphs[pos].nodes;
  38260. secCount = secCount + 1;
  38261. if (secCount > 2000) {
  38262. return;
  38263. }
  38264. //var nPos = getPosForId(subGraphs[pos].id);
  38265. posCrossRef[secCount] = pos;
  38266. // Check if match
  38267. if (subGraphs[pos].id === id) {
  38268. return {
  38269. result: true,
  38270. count: 0
  38271. };
  38272. }
  38273. var count = 0;
  38274. var posCount = 1;
  38275. while (count < nodes.length) {
  38276. var childPos = getPosForId(nodes[count]);
  38277. // Ignore regular nodes (pos will be -1)
  38278. if (childPos >= 0) {
  38279. var res = indexNodes(id, childPos);
  38280. if (res.result) {
  38281. return {
  38282. result: true,
  38283. count: posCount + res.count
  38284. };
  38285. } else {
  38286. posCount = posCount + res.count;
  38287. }
  38288. }
  38289. count = count + 1;
  38290. }
  38291. return {
  38292. result: false,
  38293. count: posCount
  38294. };
  38295. };
  38296. exports.getDepthFirstPos = function (pos) {
  38297. return posCrossRef[pos];
  38298. };
  38299. exports.indexNodes = function () {
  38300. secCount = -1;
  38301. if (subGraphs.length > 0) {
  38302. indexNodes('none', subGraphs.length - 1, 0);
  38303. }
  38304. };
  38305. exports.getSubGraphs = function () {
  38306. return subGraphs;
  38307. };
  38308. exports.parseError = function (err, hash) {
  38309. global.mermaidAPI.parseError(err, hash);
  38310. };
  38311. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  38312. },{"../../d3":107,"../../logger":129,"../../utils":131}],117:[function(require,module,exports){
  38313. (function (process){
  38314. /* parser generated by jison 0.4.17 */
  38315. /*
  38316. Returns a Parser object of the following structure:
  38317. Parser: {
  38318. yy: {}
  38319. }
  38320. Parser.prototype: {
  38321. yy: {},
  38322. trace: function(),
  38323. symbols_: {associative list: name ==> number},
  38324. terminals_: {associative list: number ==> name},
  38325. productions_: [...],
  38326. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  38327. table: [...],
  38328. defaultActions: {...},
  38329. parseError: function(str, hash),
  38330. parse: function(input),
  38331. lexer: {
  38332. EOF: 1,
  38333. parseError: function(str, hash),
  38334. setInput: function(input),
  38335. input: function(),
  38336. unput: function(str),
  38337. more: function(),
  38338. less: function(n),
  38339. pastInput: function(),
  38340. upcomingInput: function(),
  38341. showPosition: function(),
  38342. test_match: function(regex_match_array, rule_index),
  38343. next: function(),
  38344. lex: function(),
  38345. begin: function(condition),
  38346. popState: function(),
  38347. _currentRules: function(),
  38348. topState: function(),
  38349. pushState: function(condition),
  38350. options: {
  38351. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  38352. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  38353. backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code)
  38354. },
  38355. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  38356. rules: [...],
  38357. conditions: {associative list: name ==> set},
  38358. }
  38359. }
  38360. token location info (@$, _$, etc.): {
  38361. first_line: n,
  38362. last_line: n,
  38363. first_column: n,
  38364. last_column: n,
  38365. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  38366. }
  38367. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  38368. text: (matched text)
  38369. token: (the produced terminal token, if any)
  38370. line: (yylineno)
  38371. }
  38372. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  38373. loc: (yylloc)
  38374. expected: (string describing the set of expected tokens)
  38375. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  38376. }
  38377. */
  38378. "use strict";
  38379. var parser = (function () {
  38380. var o = function o(k, v, _o, l) {
  38381. for (_o = _o || {}, l = k.length; l--; _o[k[l]] = v);return _o;
  38382. },
  38383. $V0 = [1, 5],
  38384. $V1 = [1, 6],
  38385. $V2 = [1, 12],
  38386. $V3 = [1, 13],
  38387. $V4 = [1, 14],
  38388. $V5 = [1, 15],
  38389. $V6 = [1, 16],
  38390. $V7 = [1, 17],
  38391. $V8 = [1, 18],
  38392. $V9 = [1, 19],
  38393. $Va = [1, 20],
  38394. $Vb = [1, 21],
  38395. $Vc = [1, 22],
  38396. $Vd = [8, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26],
  38397. $Ve = [1, 37],
  38398. $Vf = [1, 33],
  38399. $Vg = [1, 34],
  38400. $Vh = [1, 35],
  38401. $Vi = [1, 36],
  38402. $Vj = [8, 10, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 32, 37, 39, 40, 45, 57, 58],
  38403. $Vk = [10, 28],
  38404. $Vl = [10, 28, 37, 57, 58],
  38405. $Vm = [2, 49],
  38406. $Vn = [1, 45],
  38407. $Vo = [1, 48],
  38408. $Vp = [1, 49],
  38409. $Vq = [1, 52],
  38410. $Vr = [2, 65],
  38411. $Vs = [1, 65],
  38412. $Vt = [1, 66],
  38413. $Vu = [1, 67],
  38414. $Vv = [1, 68],
  38415. $Vw = [1, 69],
  38416. $Vx = [1, 70],
  38417. $Vy = [1, 71],
  38418. $Vz = [1, 72],
  38419. $VA = [1, 73],
  38420. $VB = [8, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 47],
  38421. $VC = [10, 28, 37];
  38422. var parser = { trace: function trace() {},
  38423. yy: {},
  38424. symbols_: { "error": 2, "expressions": 3, "graph": 4, "EOF": 5, "graphStatement": 6, "idStatement": 7, "{": 8, "stmt_list": 9, "}": 10, "strict": 11, "GRAPH": 12, "DIGRAPH": 13, "textNoTags": 14, "textNoTagsToken": 15, "ALPHA": 16, "NUM": 17, "COLON": 18, "PLUS": 19, "EQUALS": 20, "MULT": 21, "DOT": 22, "BRKT": 23, "SPACE": 24, "MINUS": 25, "keywords": 26, "stmt": 27, ";": 28, "node_stmt": 29, "edge_stmt": 30, "attr_stmt": 31, "=": 32, "subgraph": 33, "attr_list": 34, "NODE": 35, "EDGE": 36, "[": 37, "a_list": 38, "]": 39, ",": 40, "edgeRHS": 41, "node_id": 42, "edgeop": 43, "port": 44, ":": 45, "compass_pt": 46, "SUBGRAPH": 47, "n": 48, "ne": 49, "e": 50, "se": 51, "s": 52, "sw": 53, "w": 54, "nw": 55, "c": 56, "ARROW_POINT": 57, "ARROW_OPEN": 58, "$accept": 0, "$end": 1 },
  38425. terminals_: { 2: "error", 5: "EOF", 8: "{", 10: "}", 11: "strict", 12: "GRAPH", 13: "DIGRAPH", 16: "ALPHA", 17: "NUM", 18: "COLON", 19: "PLUS", 20: "EQUALS", 21: "MULT", 22: "DOT", 23: "BRKT", 24: "SPACE", 25: "MINUS", 26: "keywords", 28: ";", 32: "=", 35: "NODE", 36: "EDGE", 37: "[", 39: "]", 40: ",", 45: ":", 47: "SUBGRAPH", 48: "n", 49: "ne", 50: "e", 51: "se", 52: "s", 53: "sw", 54: "w", 55: "nw", 56: "c", 57: "ARROW_POINT", 58: "ARROW_OPEN" },
  38426. productions_: [0, [3, 2], [4, 5], [4, 6], [4, 4], [6, 1], [6, 1], [7, 1], [14, 1], [14, 2], [15, 1], [15, 1], [15, 1], [15, 1], [15, 1], [15, 1], [15, 1], [15, 1], [15, 1], [15, 1], [15, 1], [9, 1], [9, 3], [27, 1], [27, 1], [27, 1], [27, 3], [27, 1], [31, 2], [31, 2], [31, 2], [34, 4], [34, 3], [34, 3], [34, 2], [38, 5], [38, 5], [38, 3], [30, 3], [30, 3], [30, 2], [30, 2], [41, 3], [41, 3], [41, 2], [41, 2], [29, 2], [29, 1], [42, 2], [42, 1], [44, 4], [44, 2], [44, 2], [33, 5], [33, 4], [33, 3], [46, 1], [46, 1], [46, 1], [46, 1], [46, 1], [46, 1], [46, 1], [46, 1], [46, 1], [46, 0], [43, 1], [43, 1]],
  38427. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, /* action[1] */$$, /* vstack */_$ /* lstack */) {
  38428. /* this == yyval */
  38429. var $0 = $$.length - 1;
  38430. switch (yystate) {
  38431. case 1:
  38432. this.$ = $$[$0 - 1];
  38433. break;
  38434. case 2:
  38435. this.$ = $$[$0 - 4];
  38436. break;
  38437. case 3:
  38438. this.$ = $$[$0 - 5];
  38439. break;
  38440. case 4:
  38441. this.$ = $$[$0 - 3];
  38442. break;
  38443. case 8:case 10:case 11:
  38444. this.$ = $$[$0];
  38445. break;
  38446. case 9:
  38447. this.$ = $$[$0 - 1] + '' + $$[$0];
  38448. break;
  38449. case 12:case 13:case 14:case 15:case 16:case 18:case 19:case 20:
  38450. this.$ = $$[$0];
  38451. break;
  38452. case 17:
  38453. this.$ = '<br>';
  38454. break;
  38455. case 39:
  38456. this.$ = 'oy';
  38457. break;
  38458. case 40:
  38459. yy.addLink($$[$0 - 1], $$[$0].id, $$[$0].op);
  38460. this.$ = 'oy';
  38461. break;
  38462. case 42:
  38463. yy.addLink($$[$0 - 1], $$[$0].id, $$[$0].op);
  38464. this.$ = { op: $$[$0 - 2], id: $$[$0 - 1] };
  38465. break;
  38466. case 44:
  38467. this.$ = { op: $$[$0 - 1], id: $$[$0] };
  38468. break;
  38469. case 48:
  38470. yy.addVertex($$[$0 - 1]);this.$ = $$[$0 - 1];
  38471. break;
  38472. case 49:
  38473. yy.addVertex($$[$0]);this.$ = $$[$0];
  38474. break;
  38475. case 66:
  38476. this.$ = 'arrow';
  38477. break;
  38478. case 67:
  38479. this.$ = 'arrow_open';
  38480. break;
  38481. }
  38482. },
  38483. table: [{ 3: 1, 4: 2, 6: 3, 11: [1, 4], 12: $V0, 13: $V1 }, { 1: [3] }, { 5: [1, 7] }, { 7: 8, 8: [1, 9], 14: 10, 15: 11, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc }, { 6: 23, 12: $V0, 13: $V1 }, o($Vd, [2, 5]), o($Vd, [2, 6]), { 1: [2, 1] }, { 8: [1, 24] }, { 7: 30, 8: $Ve, 9: 25, 12: $Vf, 14: 10, 15: 11, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc, 27: 26, 29: 27, 30: 28, 31: 29, 33: 31, 35: $Vg, 36: $Vh, 42: 32, 47: $Vi }, o([8, 10, 28, 32, 37, 39, 40, 45, 57, 58], [2, 7], { 15: 38, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc }), o($Vj, [2, 8]), o($Vj, [2, 10]), o($Vj, [2, 11]), o($Vj, [2, 12]), o($Vj, [2, 13]), o($Vj, [2, 14]), o($Vj, [2, 15]), o($Vj, [2, 16]), o($Vj, [2, 17]), o($Vj, [2, 18]), o($Vj, [2, 19]), o($Vj, [2, 20]), { 7: 39, 14: 10, 15: 11, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc }, { 7: 30, 8: $Ve, 9: 40, 12: $Vf, 14: 10, 15: 11, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc, 27: 26, 29: 27, 30: 28, 31: 29, 33: 31, 35: $Vg, 36: $Vh, 42: 32, 47: $Vi }, { 10: [1, 41] }, { 10: [2, 21], 28: [1, 42] }, o($Vk, [2, 23]), o($Vk, [2, 24]), o($Vk, [2, 25]), o($Vl, $Vm, { 44: 44, 32: [1, 43], 45: $Vn }), o($Vk, [2, 27], { 41: 46, 43: 47, 57: $Vo, 58: $Vp }), o($Vk, [2, 47], { 43: 47, 34: 50, 41: 51, 37: $Vq, 57: $Vo, 58: $Vp }), { 34: 53, 37: $Vq }, { 34: 54, 37: $Vq }, { 34: 55, 37: $Vq }, { 7: 56, 8: [1, 57], 14: 10, 15: 11, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc }, { 7: 30, 8: $Ve, 9: 58, 12: $Vf, 14: 10, 15: 11, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc, 27: 26, 29: 27, 30: 28, 31: 29, 33: 31, 35: $Vg, 36: $Vh, 42: 32, 47: $Vi }, o($Vj, [2, 9]), { 8: [1, 59] }, { 10: [1, 60] }, { 5: [2, 4] }, { 7: 30, 8: $Ve, 9: 61, 12: $Vf, 14: 10, 15: 11, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc, 27: 26, 29: 27, 30: 28, 31: 29, 33: 31, 35: $Vg, 36: $Vh, 42: 32, 47: $Vi }, { 7: 62, 14: 10, 15: 11, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc }, o($Vl, [2, 48]), o($Vl, $Vr, { 14: 10, 15: 11, 7: 63, 46: 64, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc, 48: $Vs, 49: $Vt, 50: $Vu, 51: $Vv, 52: $Vw, 53: $Vx, 54: $Vy, 55: $Vz, 56: $VA }), o($Vk, [2, 41], { 34: 74, 37: $Vq }), { 7: 77, 8: $Ve, 14: 10, 15: 11, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc, 33: 76, 42: 75, 47: $Vi }, o($VB, [2, 66]), o($VB, [2, 67]), o($Vk, [2, 46]), o($Vk, [2, 40], { 34: 78, 37: $Vq }), { 7: 81, 14: 10, 15: 11, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc, 38: 79, 39: [1, 80] }, o($Vk, [2, 28]), o($Vk, [2, 29]), o($Vk, [2, 30]), { 8: [1, 82] }, { 7: 30, 8: $Ve, 9: 83, 12: $Vf, 14: 10, 15: 11, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc, 27: 26, 29: 27, 30: 28, 31: 29, 33: 31, 35: $Vg, 36: $Vh, 42: 32, 47: $Vi }, { 10: [1, 84] }, { 7: 30, 8: $Ve, 9: 85, 12: $Vf, 14: 10, 15: 11, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc, 27: 26, 29: 27, 30: 28, 31: 29, 33: 31, 35: $Vg, 36: $Vh, 42: 32, 47: $Vi }, { 5: [2, 2] }, { 10: [2, 22] }, o($Vk, [2, 26]), o($Vl, [2, 51], { 45: [1, 86] }), o($Vl, [2, 52]), o($Vl, [2, 56]), o($Vl, [2, 57]), o($Vl, [2, 58]), o($Vl, [2, 59]), o($Vl, [2, 60]), o($Vl, [2, 61]), o($Vl, [2, 62]), o($Vl, [2, 63]), o($Vl, [2, 64]), o($Vk, [2, 38]), o($VC, [2, 44], { 43: 47, 41: 87, 57: $Vo, 58: $Vp }), o($VC, [2, 45], { 43: 47, 41: 88, 57: $Vo, 58: $Vp }), o($Vl, $Vm, { 44: 44, 45: $Vn }), o($Vk, [2, 39]), { 39: [1, 89] }, o($Vk, [2, 34], { 34: 90, 37: $Vq }), { 32: [1, 91] }, { 7: 30, 8: $Ve, 9: 92, 12: $Vf, 14: 10, 15: 11, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc, 27: 26, 29: 27, 30: 28, 31: 29, 33: 31, 35: $Vg, 36: $Vh, 42: 32, 47: $Vi }, { 10: [1, 93] }, o($Vl, [2, 55]), { 10: [1, 94] }, o($Vl, $Vr, { 46: 95, 48: $Vs, 49: $Vt, 50: $Vu, 51: $Vv, 52: $Vw, 53: $Vx, 54: $Vy, 55: $Vz, 56: $VA }), o($VC, [2, 42]), o($VC, [2, 43]), o($Vk, [2, 33], { 34: 96, 37: $Vq }), o($Vk, [2, 32]), { 7: 97, 14: 10, 15: 11, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc }, { 10: [1, 98] }, o($Vl, [2, 54]), { 5: [2, 3] }, o($Vl, [2, 50]), o($Vk, [2, 31]), { 28: [1, 99], 39: [2, 37], 40: [1, 100] }, o($Vl, [2, 53]), { 7: 81, 14: 10, 15: 11, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc, 38: 101 }, { 7: 81, 14: 10, 15: 11, 16: $V2, 17: $V3, 18: $V4, 19: $V5, 20: $V6, 21: $V7, 22: $V8, 23: $V9, 24: $Va, 25: $Vb, 26: $Vc, 38: 102 }, { 39: [2, 35] }, { 39: [2, 36] }],
  38484. defaultActions: { 7: [2, 1], 41: [2, 4], 60: [2, 2], 61: [2, 22], 94: [2, 3], 101: [2, 35], 102: [2, 36] },
  38485. parseError: function parseError(str, hash) {
  38486. if (hash.recoverable) {
  38487. this.trace(str);
  38488. } else {
  38489. var _parseError = function _parseError(msg, hash) {
  38490. this.message = msg;
  38491. this.hash = hash;
  38492. };
  38493. _parseError.prototype = Error;
  38494. throw new _parseError(str, hash);
  38495. }
  38496. },
  38497. parse: function parse(input) {
  38498. var self = this,
  38499. stack = [0],
  38500. tstack = [],
  38501. vstack = [null],
  38502. lstack = [],
  38503. table = this.table,
  38504. yytext = '',
  38505. yylineno = 0,
  38506. yyleng = 0,
  38507. recovering = 0,
  38508. TERROR = 2,
  38509. EOF = 1;
  38510. var args = lstack.slice.call(arguments, 1);
  38511. var lexer = Object.create(this.lexer);
  38512. var sharedState = { yy: {} };
  38513. for (var k in this.yy) {
  38514. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  38515. sharedState.yy[k] = this.yy[k];
  38516. }
  38517. }
  38518. lexer.setInput(input, sharedState.yy);
  38519. sharedState.yy.lexer = lexer;
  38520. sharedState.yy.parser = this;
  38521. if (typeof lexer.yylloc == 'undefined') {
  38522. lexer.yylloc = {};
  38523. }
  38524. var yyloc = lexer.yylloc;
  38525. lstack.push(yyloc);
  38526. var ranges = lexer.options && lexer.options.ranges;
  38527. if (typeof sharedState.yy.parseError === 'function') {
  38528. this.parseError = sharedState.yy.parseError;
  38529. } else {
  38530. this.parseError = Object.getPrototypeOf(this).parseError;
  38531. }
  38532. function popStack(n) {
  38533. stack.length = stack.length - 2 * n;
  38534. vstack.length = vstack.length - n;
  38535. lstack.length = lstack.length - n;
  38536. }
  38537. _token_stack: var lex = function lex() {
  38538. var token;
  38539. token = lexer.lex() || EOF;
  38540. if (typeof token !== 'number') {
  38541. token = self.symbols_[token] || token;
  38542. }
  38543. return token;
  38544. };
  38545. var symbol,
  38546. preErrorSymbol,
  38547. state,
  38548. action,
  38549. a,
  38550. r,
  38551. yyval = {},
  38552. p,
  38553. len,
  38554. newState,
  38555. expected;
  38556. while (true) {
  38557. state = stack[stack.length - 1];
  38558. if (this.defaultActions[state]) {
  38559. action = this.defaultActions[state];
  38560. } else {
  38561. if (symbol === null || typeof symbol == 'undefined') {
  38562. symbol = lex();
  38563. }
  38564. action = table[state] && table[state][symbol];
  38565. }
  38566. if (typeof action === 'undefined' || !action.length || !action[0]) {
  38567. var errStr = '';
  38568. expected = [];
  38569. for (p in table[state]) {
  38570. if (this.terminals_[p] && p > TERROR) {
  38571. expected.push('\'' + this.terminals_[p] + '\'');
  38572. }
  38573. }
  38574. if (lexer.showPosition) {
  38575. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  38576. } else {
  38577. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  38578. }
  38579. this.parseError(errStr, {
  38580. text: lexer.match,
  38581. token: this.terminals_[symbol] || symbol,
  38582. line: lexer.yylineno,
  38583. loc: yyloc,
  38584. expected: expected
  38585. });
  38586. }
  38587. if (action[0] instanceof Array && action.length > 1) {
  38588. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  38589. }
  38590. switch (action[0]) {
  38591. case 1:
  38592. stack.push(symbol);
  38593. vstack.push(lexer.yytext);
  38594. lstack.push(lexer.yylloc);
  38595. stack.push(action[1]);
  38596. symbol = null;
  38597. if (!preErrorSymbol) {
  38598. yyleng = lexer.yyleng;
  38599. yytext = lexer.yytext;
  38600. yylineno = lexer.yylineno;
  38601. yyloc = lexer.yylloc;
  38602. if (recovering > 0) {
  38603. recovering--;
  38604. }
  38605. } else {
  38606. symbol = preErrorSymbol;
  38607. preErrorSymbol = null;
  38608. }
  38609. break;
  38610. case 2:
  38611. len = this.productions_[action[1]][1];
  38612. yyval.$ = vstack[vstack.length - len];
  38613. yyval._$ = {
  38614. first_line: lstack[lstack.length - (len || 1)].first_line,
  38615. last_line: lstack[lstack.length - 1].last_line,
  38616. first_column: lstack[lstack.length - (len || 1)].first_column,
  38617. last_column: lstack[lstack.length - 1].last_column
  38618. };
  38619. if (ranges) {
  38620. yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
  38621. }
  38622. r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
  38623. if (typeof r !== 'undefined') {
  38624. return r;
  38625. }
  38626. if (len) {
  38627. stack = stack.slice(0, -1 * len * 2);
  38628. vstack = vstack.slice(0, -1 * len);
  38629. lstack = lstack.slice(0, -1 * len);
  38630. }
  38631. stack.push(this.productions_[action[1]][0]);
  38632. vstack.push(yyval.$);
  38633. lstack.push(yyval._$);
  38634. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  38635. stack.push(newState);
  38636. break;
  38637. case 3:
  38638. return true;
  38639. }
  38640. }
  38641. return true;
  38642. } };
  38643. /* generated by jison-lex 0.3.4 */
  38644. var lexer = (function () {
  38645. var lexer = {
  38646. EOF: 1,
  38647. parseError: function parseError(str, hash) {
  38648. if (this.yy.parser) {
  38649. this.yy.parser.parseError(str, hash);
  38650. } else {
  38651. throw new Error(str);
  38652. }
  38653. },
  38654. // resets the lexer, sets new input
  38655. setInput: function setInput(input, yy) {
  38656. this.yy = yy || this.yy || {};
  38657. this._input = input;
  38658. this._more = this._backtrack = this.done = false;
  38659. this.yylineno = this.yyleng = 0;
  38660. this.yytext = this.matched = this.match = '';
  38661. this.conditionStack = ['INITIAL'];
  38662. this.yylloc = {
  38663. first_line: 1,
  38664. first_column: 0,
  38665. last_line: 1,
  38666. last_column: 0
  38667. };
  38668. if (this.options.ranges) {
  38669. this.yylloc.range = [0, 0];
  38670. }
  38671. this.offset = 0;
  38672. return this;
  38673. },
  38674. // consumes and returns one char from the input
  38675. input: function input() {
  38676. var ch = this._input[0];
  38677. this.yytext += ch;
  38678. this.yyleng++;
  38679. this.offset++;
  38680. this.match += ch;
  38681. this.matched += ch;
  38682. var lines = ch.match(/(?:\r\n?|\n).*/g);
  38683. if (lines) {
  38684. this.yylineno++;
  38685. this.yylloc.last_line++;
  38686. } else {
  38687. this.yylloc.last_column++;
  38688. }
  38689. if (this.options.ranges) {
  38690. this.yylloc.range[1]++;
  38691. }
  38692. this._input = this._input.slice(1);
  38693. return ch;
  38694. },
  38695. // unshifts one char (or a string) into the input
  38696. unput: function unput(ch) {
  38697. var len = ch.length;
  38698. var lines = ch.split(/(?:\r\n?|\n)/g);
  38699. this._input = ch + this._input;
  38700. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  38701. //this.yyleng -= len;
  38702. this.offset -= len;
  38703. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  38704. this.match = this.match.substr(0, this.match.length - 1);
  38705. this.matched = this.matched.substr(0, this.matched.length - 1);
  38706. if (lines.length - 1) {
  38707. this.yylineno -= lines.length - 1;
  38708. }
  38709. var r = this.yylloc.range;
  38710. this.yylloc = {
  38711. first_line: this.yylloc.first_line,
  38712. last_line: this.yylineno + 1,
  38713. first_column: this.yylloc.first_column,
  38714. last_column: lines ? (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length : this.yylloc.first_column - len
  38715. };
  38716. if (this.options.ranges) {
  38717. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  38718. }
  38719. this.yyleng = this.yytext.length;
  38720. return this;
  38721. },
  38722. // When called from action, caches matched text and appends it on next action
  38723. more: function more() {
  38724. this._more = true;
  38725. return this;
  38726. },
  38727. // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
  38728. reject: function reject() {
  38729. if (this.options.backtrack_lexer) {
  38730. this._backtrack = true;
  38731. } else {
  38732. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), {
  38733. text: "",
  38734. token: null,
  38735. line: this.yylineno
  38736. });
  38737. }
  38738. return this;
  38739. },
  38740. // retain first n characters of the match
  38741. less: function less(n) {
  38742. this.unput(this.match.slice(n));
  38743. },
  38744. // displays already matched input, i.e. for error messages
  38745. pastInput: function pastInput() {
  38746. var past = this.matched.substr(0, this.matched.length - this.match.length);
  38747. return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
  38748. },
  38749. // displays upcoming input, i.e. for error messages
  38750. upcomingInput: function upcomingInput() {
  38751. var next = this.match;
  38752. if (next.length < 20) {
  38753. next += this._input.substr(0, 20 - next.length);
  38754. }
  38755. return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  38756. },
  38757. // displays the character position where the lexing error occurred, i.e. for error messages
  38758. showPosition: function showPosition() {
  38759. var pre = this.pastInput();
  38760. var c = new Array(pre.length + 1).join("-");
  38761. return pre + this.upcomingInput() + "\n" + c + "^";
  38762. },
  38763. // test the lexed token: return FALSE when not a match, otherwise return token
  38764. test_match: function test_match(match, indexed_rule) {
  38765. var token, lines, backup;
  38766. if (this.options.backtrack_lexer) {
  38767. // save context
  38768. backup = {
  38769. yylineno: this.yylineno,
  38770. yylloc: {
  38771. first_line: this.yylloc.first_line,
  38772. last_line: this.last_line,
  38773. first_column: this.yylloc.first_column,
  38774. last_column: this.yylloc.last_column
  38775. },
  38776. yytext: this.yytext,
  38777. match: this.match,
  38778. matches: this.matches,
  38779. matched: this.matched,
  38780. yyleng: this.yyleng,
  38781. offset: this.offset,
  38782. _more: this._more,
  38783. _input: this._input,
  38784. yy: this.yy,
  38785. conditionStack: this.conditionStack.slice(0),
  38786. done: this.done
  38787. };
  38788. if (this.options.ranges) {
  38789. backup.yylloc.range = this.yylloc.range.slice(0);
  38790. }
  38791. }
  38792. lines = match[0].match(/(?:\r\n?|\n).*/g);
  38793. if (lines) {
  38794. this.yylineno += lines.length;
  38795. }
  38796. this.yylloc = {
  38797. first_line: this.yylloc.last_line,
  38798. last_line: this.yylineno + 1,
  38799. first_column: this.yylloc.last_column,
  38800. last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
  38801. };
  38802. this.yytext += match[0];
  38803. this.match += match[0];
  38804. this.matches = match;
  38805. this.yyleng = this.yytext.length;
  38806. if (this.options.ranges) {
  38807. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  38808. }
  38809. this._more = false;
  38810. this._backtrack = false;
  38811. this._input = this._input.slice(match[0].length);
  38812. this.matched += match[0];
  38813. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  38814. if (this.done && this._input) {
  38815. this.done = false;
  38816. }
  38817. if (token) {
  38818. return token;
  38819. } else if (this._backtrack) {
  38820. // recover context
  38821. for (var k in backup) {
  38822. this[k] = backup[k];
  38823. }
  38824. return false; // rule action called reject() implying the next rule should be tested instead.
  38825. }
  38826. return false;
  38827. },
  38828. // return next match in input
  38829. next: function next() {
  38830. if (this.done) {
  38831. return this.EOF;
  38832. }
  38833. if (!this._input) {
  38834. this.done = true;
  38835. }
  38836. var token, match, tempMatch, index;
  38837. if (!this._more) {
  38838. this.yytext = '';
  38839. this.match = '';
  38840. }
  38841. var rules = this._currentRules();
  38842. for (var i = 0; i < rules.length; i++) {
  38843. tempMatch = this._input.match(this.rules[rules[i]]);
  38844. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  38845. match = tempMatch;
  38846. index = i;
  38847. if (this.options.backtrack_lexer) {
  38848. token = this.test_match(tempMatch, rules[i]);
  38849. if (token !== false) {
  38850. return token;
  38851. } else if (this._backtrack) {
  38852. match = false;
  38853. continue; // rule action called reject() implying a rule MISmatch.
  38854. } else {
  38855. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  38856. return false;
  38857. }
  38858. } else if (!this.options.flex) {
  38859. break;
  38860. }
  38861. }
  38862. }
  38863. if (match) {
  38864. token = this.test_match(match, rules[index]);
  38865. if (token !== false) {
  38866. return token;
  38867. }
  38868. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  38869. return false;
  38870. }
  38871. if (this._input === "") {
  38872. return this.EOF;
  38873. } else {
  38874. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  38875. text: "",
  38876. token: null,
  38877. line: this.yylineno
  38878. });
  38879. }
  38880. },
  38881. // return next match that has a token
  38882. lex: function lex() {
  38883. var r = this.next();
  38884. if (r) {
  38885. return r;
  38886. } else {
  38887. return this.lex();
  38888. }
  38889. },
  38890. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  38891. begin: function begin(condition) {
  38892. this.conditionStack.push(condition);
  38893. },
  38894. // pop the previously active lexer condition state off the condition stack
  38895. popState: function popState() {
  38896. var n = this.conditionStack.length - 1;
  38897. if (n > 0) {
  38898. return this.conditionStack.pop();
  38899. } else {
  38900. return this.conditionStack[0];
  38901. }
  38902. },
  38903. // produce the lexer rule set which is active for the currently active lexer condition state
  38904. _currentRules: function _currentRules() {
  38905. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  38906. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  38907. } else {
  38908. return this.conditions["INITIAL"].rules;
  38909. }
  38910. },
  38911. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  38912. topState: function topState(n) {
  38913. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  38914. if (n >= 0) {
  38915. return this.conditionStack[n];
  38916. } else {
  38917. return "INITIAL";
  38918. }
  38919. },
  38920. // alias for begin(condition)
  38921. pushState: function pushState(condition) {
  38922. this.begin(condition);
  38923. },
  38924. // return the number of states currently on the stack
  38925. stateStackSize: function stateStackSize() {
  38926. return this.conditionStack.length;
  38927. },
  38928. options: {},
  38929. performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
  38930. var YYSTATE = YY_START;
  38931. switch ($avoiding_name_collisions) {
  38932. case 0:
  38933. return 'STYLE';
  38934. break;
  38935. case 1:
  38936. return 'LINKSTYLE';
  38937. break;
  38938. case 2:
  38939. return 'CLASSDEF';
  38940. break;
  38941. case 3:
  38942. return 'CLASS';
  38943. break;
  38944. case 4:
  38945. return 'CLICK';
  38946. break;
  38947. case 5:
  38948. return 12;
  38949. break;
  38950. case 6:
  38951. return 13;
  38952. break;
  38953. case 7:
  38954. return 47;
  38955. break;
  38956. case 8:
  38957. return 35;
  38958. break;
  38959. case 9:
  38960. return 36;
  38961. break;
  38962. case 10:
  38963. return 'DIR';
  38964. break;
  38965. case 11:
  38966. return 'DIR';
  38967. break;
  38968. case 12:
  38969. return 'DIR';
  38970. break;
  38971. case 13:
  38972. return 'DIR';
  38973. break;
  38974. case 14:
  38975. return 'DIR';
  38976. break;
  38977. case 15:
  38978. return 'DIR';
  38979. break;
  38980. case 16:
  38981. return 17;
  38982. break;
  38983. case 17:
  38984. return 23;
  38985. break;
  38986. case 18:
  38987. return 18;
  38988. break;
  38989. case 19:
  38990. return 28;
  38991. break;
  38992. case 20:
  38993. return 40;
  38994. break;
  38995. case 21:
  38996. return 32;
  38997. break;
  38998. case 22:
  38999. return 21;
  39000. break;
  39001. case 23:
  39002. return 22;
  39003. break;
  39004. case 24:
  39005. return 'ARROW_CROSS';
  39006. break;
  39007. case 25:
  39008. return 57;
  39009. break;
  39010. case 26:
  39011. return 'ARROW_CIRCLE';
  39012. break;
  39013. case 27:
  39014. return 58;
  39015. break;
  39016. case 28:
  39017. return 25;
  39018. break;
  39019. case 29:
  39020. return 19;
  39021. break;
  39022. case 30:
  39023. return 20;
  39024. break;
  39025. case 31:
  39026. return 16;
  39027. break;
  39028. case 32:
  39029. return 'PIPE';
  39030. break;
  39031. case 33:
  39032. return 'PS';
  39033. break;
  39034. case 34:
  39035. return 'PE';
  39036. break;
  39037. case 35:
  39038. return 37;
  39039. break;
  39040. case 36:
  39041. return 39;
  39042. break;
  39043. case 37:
  39044. return 8;
  39045. break;
  39046. case 38:
  39047. return 10;
  39048. break;
  39049. case 39:
  39050. return 'QUOTE';
  39051. break;
  39052. case 40:
  39053. return 24;
  39054. break;
  39055. case 41:
  39056. return 'NEWLINE';
  39057. break;
  39058. case 42:
  39059. return 5;
  39060. break;
  39061. }
  39062. },
  39063. rules: [/^(?:style\b)/, /^(?:linkStyle\b)/, /^(?:classDef\b)/, /^(?:class\b)/, /^(?:click\b)/, /^(?:graph\b)/, /^(?:digraph\b)/, /^(?:subgraph\b)/, /^(?:node\b)/, /^(?:edge\b)/, /^(?:LR\b)/, /^(?:RL\b)/, /^(?:TB\b)/, /^(?:BT\b)/, /^(?:TD\b)/, /^(?:BR\b)/, /^(?:[0-9])/, /^(?:#)/, /^(?::)/, /^(?:;)/, /^(?:,)/, /^(?:=)/, /^(?:\*)/, /^(?:\.)/, /^(?:--[x])/, /^(?:->)/, /^(?:--[o])/, /^(?:--)/, /^(?:-)/, /^(?:\+)/, /^(?:=)/, /^(?:[\u0021-\u0027\u002A-\u002E\u003F\u0041-\u005A\u0061-\u007A\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6]|[\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377]|[\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5]|[\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA]|[\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE]|[\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA]|[\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0]|[\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977]|[\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2]|[\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A]|[\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39]|[\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8]|[\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C]|[\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C]|[\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99]|[\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0]|[\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D]|[\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3]|[\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10]|[\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1]|[\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81]|[\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3]|[\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6]|[\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A]|[\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081]|[\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D]|[\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0]|[\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310]|[\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C]|[\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711]|[\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7]|[\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C]|[\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16]|[\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF]|[\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC]|[\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D]|[\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D]|[\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3]|[\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F]|[\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128]|[\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184]|[\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3]|[\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6]|[\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE]|[\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C]|[\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D]|[\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC]|[\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B]|[\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788]|[\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805]|[\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB]|[\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28]|[\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5]|[\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4]|[\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E]|[\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D]|[\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36]|[\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D]|[\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC]|[\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF]|[\uFFD2-\uFFD7\uFFDA-\uFFDC_])/, /^(?:\|)/, /^(?:\()/, /^(?:\))/, /^(?:\[)/, /^(?:\])/, /^(?:\{)/, /^(?:\})/, /^(?:")/, /^(?:\s)/, /^(?:\n)/, /^(?:$)/],
  39064. conditions: { "INITIAL": { "rules": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42], "inclusive": true } }
  39065. };
  39066. return lexer;
  39067. })();
  39068. parser.lexer = lexer;
  39069. function Parser() {
  39070. this.yy = {};
  39071. }
  39072. Parser.prototype = parser;parser.Parser = Parser;
  39073. return new Parser();
  39074. })();
  39075. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  39076. exports.parser = parser;
  39077. exports.Parser = parser.Parser;
  39078. exports.parse = function () {
  39079. return parser.parse.apply(parser, arguments);
  39080. };
  39081. exports.main = function commonjsMain(args) {
  39082. if (!args[1]) {
  39083. console.log('Usage: ' + args[0] + ' FILE');
  39084. process.exit(1);
  39085. }
  39086. var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
  39087. return exports.parser.parse(source);
  39088. };
  39089. if (typeof module !== 'undefined' && require.main === module) {
  39090. exports.main(process.argv.slice(1));
  39091. }
  39092. }
  39093. }).call(this,require('_process'))
  39094. },{"_process":105,"fs":1,"path":104}],118:[function(require,module,exports){
  39095. (function (process){
  39096. /* parser generated by jison 0.4.17 */
  39097. /*
  39098. Returns a Parser object of the following structure:
  39099. Parser: {
  39100. yy: {}
  39101. }
  39102. Parser.prototype: {
  39103. yy: {},
  39104. trace: function(),
  39105. symbols_: {associative list: name ==> number},
  39106. terminals_: {associative list: number ==> name},
  39107. productions_: [...],
  39108. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  39109. table: [...],
  39110. defaultActions: {...},
  39111. parseError: function(str, hash),
  39112. parse: function(input),
  39113. lexer: {
  39114. EOF: 1,
  39115. parseError: function(str, hash),
  39116. setInput: function(input),
  39117. input: function(),
  39118. unput: function(str),
  39119. more: function(),
  39120. less: function(n),
  39121. pastInput: function(),
  39122. upcomingInput: function(),
  39123. showPosition: function(),
  39124. test_match: function(regex_match_array, rule_index),
  39125. next: function(),
  39126. lex: function(),
  39127. begin: function(condition),
  39128. popState: function(),
  39129. _currentRules: function(),
  39130. topState: function(),
  39131. pushState: function(condition),
  39132. options: {
  39133. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  39134. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  39135. backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code)
  39136. },
  39137. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  39138. rules: [...],
  39139. conditions: {associative list: name ==> set},
  39140. }
  39141. }
  39142. token location info (@$, _$, etc.): {
  39143. first_line: n,
  39144. last_line: n,
  39145. first_column: n,
  39146. last_column: n,
  39147. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  39148. }
  39149. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  39150. text: (matched text)
  39151. token: (the produced terminal token, if any)
  39152. line: (yylineno)
  39153. }
  39154. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  39155. loc: (yylloc)
  39156. expected: (string describing the set of expected tokens)
  39157. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  39158. }
  39159. */
  39160. "use strict";
  39161. var parser = (function () {
  39162. var o = function o(k, v, _o, l) {
  39163. for (_o = _o || {}, l = k.length; l--; _o[k[l]] = v);return _o;
  39164. },
  39165. $V0 = [1, 4],
  39166. $V1 = [1, 3],
  39167. $V2 = [1, 5],
  39168. $V3 = [1, 8, 9, 10, 11, 13, 18, 30, 46, 71, 72, 73, 74, 75, 81, 86, 88, 89, 91, 92, 94, 95, 96, 97, 98],
  39169. $V4 = [2, 2],
  39170. $V5 = [1, 12],
  39171. $V6 = [1, 13],
  39172. $V7 = [1, 14],
  39173. $V8 = [1, 15],
  39174. $V9 = [1, 31],
  39175. $Va = [1, 33],
  39176. $Vb = [1, 22],
  39177. $Vc = [1, 34],
  39178. $Vd = [1, 24],
  39179. $Ve = [1, 25],
  39180. $Vf = [1, 26],
  39181. $Vg = [1, 27],
  39182. $Vh = [1, 28],
  39183. $Vi = [1, 38],
  39184. $Vj = [1, 40],
  39185. $Vk = [1, 35],
  39186. $Vl = [1, 39],
  39187. $Vm = [1, 45],
  39188. $Vn = [1, 44],
  39189. $Vo = [1, 36],
  39190. $Vp = [1, 37],
  39191. $Vq = [1, 41],
  39192. $Vr = [1, 42],
  39193. $Vs = [1, 43],
  39194. $Vt = [1, 8, 9, 10, 11, 13, 18, 30, 32, 46, 71, 72, 73, 74, 75, 81, 86, 88, 89, 91, 92, 94, 95, 96, 97, 98],
  39195. $Vu = [1, 53],
  39196. $Vv = [1, 52],
  39197. $Vw = [1, 54],
  39198. $Vx = [1, 72],
  39199. $Vy = [1, 80],
  39200. $Vz = [1, 81],
  39201. $VA = [1, 66],
  39202. $VB = [1, 65],
  39203. $VC = [1, 85],
  39204. $VD = [1, 84],
  39205. $VE = [1, 82],
  39206. $VF = [1, 83],
  39207. $VG = [1, 73],
  39208. $VH = [1, 68],
  39209. $VI = [1, 67],
  39210. $VJ = [1, 63],
  39211. $VK = [1, 75],
  39212. $VL = [1, 76],
  39213. $VM = [1, 77],
  39214. $VN = [1, 78],
  39215. $VO = [1, 79],
  39216. $VP = [1, 70],
  39217. $VQ = [1, 69],
  39218. $VR = [8, 9, 11],
  39219. $VS = [8, 9, 11, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64],
  39220. $VT = [1, 115],
  39221. $VU = [8, 9, 10, 11, 13, 15, 18, 36, 38, 40, 42, 46, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 81, 86, 88, 89, 91, 92, 94, 95, 96, 97, 98],
  39222. $VV = [8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 30, 32, 36, 37, 38, 39, 40, 41, 42, 43, 46, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 71, 72, 73, 74, 75, 78, 81, 84, 86, 88, 89, 91, 92, 94, 95, 96, 97, 98],
  39223. $VW = [1, 117],
  39224. $VX = [1, 118],
  39225. $VY = [8, 9, 10, 11, 13, 18, 30, 32, 46, 71, 72, 73, 74, 75, 81, 86, 88, 89, 91, 92, 94, 95, 96, 97, 98],
  39226. $VZ = [8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 30, 32, 37, 39, 41, 43, 46, 50, 51, 52, 53, 54, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 71, 72, 73, 74, 75, 78, 81, 84, 86, 88, 89, 91, 92, 94, 95, 96, 97, 98],
  39227. $V_ = [13, 18, 46, 81, 86, 88, 89, 91, 92, 94, 95, 96, 97, 98],
  39228. $V$ = [13, 18, 46, 49, 65, 81, 86, 88, 89, 91, 92, 94, 95, 96, 97, 98],
  39229. $V01 = [1, 191],
  39230. $V11 = [1, 188],
  39231. $V21 = [1, 195],
  39232. $V31 = [1, 192],
  39233. $V41 = [1, 189],
  39234. $V51 = [1, 196],
  39235. $V61 = [1, 186],
  39236. $V71 = [1, 187],
  39237. $V81 = [1, 190],
  39238. $V91 = [1, 193],
  39239. $Va1 = [1, 194],
  39240. $Vb1 = [1, 213],
  39241. $Vc1 = [8, 9, 11, 86],
  39242. $Vd1 = [8, 9, 10, 11, 46, 71, 80, 81, 84, 86, 88, 89, 90, 91, 92];
  39243. var parser = { trace: function trace() {},
  39244. yy: {},
  39245. symbols_: { "error": 2, "mermaidDoc": 3, "graphConfig": 4, "document": 5, "line": 6, "statement": 7, "SEMI": 8, "NEWLINE": 9, "SPACE": 10, "EOF": 11, "GRAPH": 12, "DIR": 13, "FirstStmtSeperator": 14, "TAGEND": 15, "TAGSTART": 16, "UP": 17, "DOWN": 18, "ending": 19, "endToken": 20, "spaceList": 21, "spaceListNewline": 22, "verticeStatement": 23, "separator": 24, "styleStatement": 25, "linkStyleStatement": 26, "classDefStatement": 27, "classStatement": 28, "clickStatement": 29, "subgraph": 30, "text": 31, "end": 32, "vertex": 33, "link": 34, "alphaNum": 35, "SQS": 36, "SQE": 37, "PS": 38, "PE": 39, "(-": 40, "-)": 41, "DIAMOND_START": 42, "DIAMOND_STOP": 43, "alphaNumStatement": 44, "alphaNumToken": 45, "MINUS": 46, "linkStatement": 47, "arrowText": 48, "TESTSTR": 49, "--": 50, "ARROW_POINT": 51, "ARROW_CIRCLE": 52, "ARROW_CROSS": 53, "ARROW_OPEN": 54, "-.": 55, "DOTTED_ARROW_POINT": 56, "DOTTED_ARROW_CIRCLE": 57, "DOTTED_ARROW_CROSS": 58, "DOTTED_ARROW_OPEN": 59, "==": 60, "THICK_ARROW_POINT": 61, "THICK_ARROW_CIRCLE": 62, "THICK_ARROW_CROSS": 63, "THICK_ARROW_OPEN": 64, "PIPE": 65, "textToken": 66, "STR": 67, "commentText": 68, "commentToken": 69, "keywords": 70, "STYLE": 71, "LINKSTYLE": 72, "CLASSDEF": 73, "CLASS": 74, "CLICK": 75, "textNoTags": 76, "textNoTagsToken": 77, "DEFAULT": 78, "stylesOpt": 79, "HEX": 80, "NUM": 81, "INTERPOLATE": 82, "commentStatement": 83, "PCT": 84, "style": 85, "COMMA": 86, "styleComponent": 87, "ALPHA": 88, "COLON": 89, "UNIT": 90, "BRKT": 91, "DOT": 92, "graphCodeTokens": 93, "PUNCTUATION": 94, "UNICODE_TEXT": 95, "PLUS": 96, "EQUALS": 97, "MULT": 98, "TAG_START": 99, "TAG_END": 100, "QUOTE": 101, "$accept": 0, "$end": 1 },
  39246. terminals_: { 2: "error", 8: "SEMI", 9: "NEWLINE", 10: "SPACE", 11: "EOF", 12: "GRAPH", 13: "DIR", 15: "TAGEND", 16: "TAGSTART", 17: "UP", 18: "DOWN", 30: "subgraph", 32: "end", 36: "SQS", 37: "SQE", 38: "PS", 39: "PE", 40: "(-", 41: "-)", 42: "DIAMOND_START", 43: "DIAMOND_STOP", 46: "MINUS", 49: "TESTSTR", 50: "--", 51: "ARROW_POINT", 52: "ARROW_CIRCLE", 53: "ARROW_CROSS", 54: "ARROW_OPEN", 55: "-.", 56: "DOTTED_ARROW_POINT", 57: "DOTTED_ARROW_CIRCLE", 58: "DOTTED_ARROW_CROSS", 59: "DOTTED_ARROW_OPEN", 60: "==", 61: "THICK_ARROW_POINT", 62: "THICK_ARROW_CIRCLE", 63: "THICK_ARROW_CROSS", 64: "THICK_ARROW_OPEN", 65: "PIPE", 67: "STR", 71: "STYLE", 72: "LINKSTYLE", 73: "CLASSDEF", 74: "CLASS", 75: "CLICK", 78: "DEFAULT", 80: "HEX", 81: "NUM", 82: "INTERPOLATE", 84: "PCT", 86: "COMMA", 88: "ALPHA", 89: "COLON", 90: "UNIT", 91: "BRKT", 92: "DOT", 94: "PUNCTUATION", 95: "UNICODE_TEXT", 96: "PLUS", 97: "EQUALS", 98: "MULT", 99: "TAG_START", 100: "TAG_END", 101: "QUOTE" },
  39247. productions_: [0, [3, 2], [5, 0], [5, 2], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [4, 2], [4, 2], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [19, 2], [19, 1], [20, 1], [20, 1], [20, 1], [14, 1], [14, 1], [14, 2], [22, 2], [22, 2], [22, 1], [22, 1], [21, 2], [21, 1], [7, 2], [7, 2], [7, 2], [7, 2], [7, 2], [7, 2], [7, 5], [7, 4], [24, 1], [24, 1], [24, 1], [23, 3], [23, 1], [33, 4], [33, 5], [33, 6], [33, 7], [33, 4], [33, 5], [33, 4], [33, 5], [33, 4], [33, 5], [33, 4], [33, 5], [33, 1], [33, 2], [35, 1], [35, 2], [44, 1], [44, 1], [44, 1], [44, 1], [34, 2], [34, 3], [34, 3], [34, 1], [34, 3], [34, 3], [34, 3], [34, 3], [34, 3], [34, 3], [34, 3], [34, 3], [34, 3], [34, 3], [34, 3], [34, 3], [47, 1], [47, 1], [47, 1], [47, 1], [47, 1], [47, 1], [47, 1], [47, 1], [47, 1], [47, 1], [47, 1], [47, 1], [48, 3], [31, 1], [31, 2], [31, 1], [68, 1], [68, 2], [70, 1], [70, 1], [70, 1], [70, 1], [70, 1], [70, 1], [70, 1], [70, 1], [70, 1], [70, 1], [70, 1], [76, 1], [76, 2], [27, 5], [27, 5], [28, 5], [29, 5], [29, 7], [29, 5], [29, 7], [25, 5], [25, 5], [26, 5], [26, 5], [26, 9], [26, 9], [26, 7], [26, 7], [83, 3], [79, 1], [79, 3], [85, 1], [85, 2], [87, 1], [87, 1], [87, 1], [87, 1], [87, 1], [87, 1], [87, 1], [87, 1], [87, 1], [87, 1], [87, 1], [69, 1], [69, 1], [66, 1], [66, 1], [66, 1], [66, 1], [66, 1], [66, 1], [66, 1], [77, 1], [77, 1], [77, 1], [77, 1], [45, 1], [45, 1], [45, 1], [45, 1], [45, 1], [45, 1], [45, 1], [45, 1], [45, 1], [45, 1], [45, 1], [93, 1], [93, 1], [93, 1], [93, 1], [93, 1], [93, 1], [93, 1], [93, 1], [93, 1], [93, 1], [93, 1], [93, 1], [93, 1], [93, 1], [93, 1]],
  39248. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, /* action[1] */$$, /* vstack */_$ /* lstack */) {
  39249. /* this == yyval */
  39250. var $0 = $$.length - 1;
  39251. switch (yystate) {
  39252. case 2:
  39253. this.$ = [];
  39254. break;
  39255. case 3:
  39256. if ($$[$0] !== []) {
  39257. $$[$0 - 1].push($$[$0]);
  39258. }
  39259. this.$ = $$[$0 - 1];
  39260. break;
  39261. case 4:case 57:case 59:case 60:case 92:case 94:case 95:case 108:
  39262. this.$ = $$[$0];
  39263. break;
  39264. case 11:
  39265. yy.setDirection($$[$0 - 1]);this.$ = $$[$0 - 1];
  39266. break;
  39267. case 12:
  39268. yy.setDirection("LR");this.$ = $$[$0 - 1];
  39269. break;
  39270. case 13:
  39271. yy.setDirection("RL");this.$ = $$[$0 - 1];
  39272. break;
  39273. case 14:
  39274. yy.setDirection("BT");this.$ = $$[$0 - 1];
  39275. break;
  39276. case 15:
  39277. yy.setDirection("TB");this.$ = $$[$0 - 1];
  39278. break;
  39279. case 30:
  39280. this.$ = $$[$0 - 1];
  39281. break;
  39282. case 31:case 32:case 33:case 34:case 35:
  39283. this.$ = [];
  39284. break;
  39285. case 36:
  39286. this.$ = yy.addSubGraph($$[$0 - 1], $$[$0 - 3]);
  39287. break;
  39288. case 37:
  39289. this.$ = yy.addSubGraph($$[$0 - 1], undefined);
  39290. break;
  39291. case 41:
  39292. yy.addLink($$[$0 - 2], $$[$0], $$[$0 - 1]);this.$ = [$$[$0 - 2], $$[$0]];
  39293. break;
  39294. case 42:
  39295. this.$ = [$$[$0]];
  39296. break;
  39297. case 43:
  39298. this.$ = $$[$0 - 3];yy.addVertex($$[$0 - 3], $$[$0 - 1], 'square');
  39299. break;
  39300. case 44:
  39301. this.$ = $$[$0 - 4];yy.addVertex($$[$0 - 4], $$[$0 - 2], 'square');
  39302. break;
  39303. case 45:
  39304. this.$ = $$[$0 - 5];yy.addVertex($$[$0 - 5], $$[$0 - 2], 'circle');
  39305. break;
  39306. case 46:
  39307. this.$ = $$[$0 - 6];yy.addVertex($$[$0 - 6], $$[$0 - 3], 'circle');
  39308. break;
  39309. case 47:
  39310. this.$ = $$[$0 - 3];yy.addVertex($$[$0 - 3], $$[$0 - 1], 'ellipse');
  39311. break;
  39312. case 48:
  39313. this.$ = $$[$0 - 4];yy.addVertex($$[$0 - 4], $$[$0 - 2], 'ellipse');
  39314. break;
  39315. case 49:
  39316. this.$ = $$[$0 - 3];yy.addVertex($$[$0 - 3], $$[$0 - 1], 'round');
  39317. break;
  39318. case 50:
  39319. this.$ = $$[$0 - 4];yy.addVertex($$[$0 - 4], $$[$0 - 2], 'round');
  39320. break;
  39321. case 51:
  39322. this.$ = $$[$0 - 3];yy.addVertex($$[$0 - 3], $$[$0 - 1], 'diamond');
  39323. break;
  39324. case 52:
  39325. this.$ = $$[$0 - 4];yy.addVertex($$[$0 - 4], $$[$0 - 2], 'diamond');
  39326. break;
  39327. case 53:
  39328. this.$ = $$[$0 - 3];yy.addVertex($$[$0 - 3], $$[$0 - 1], 'odd');
  39329. break;
  39330. case 54:
  39331. this.$ = $$[$0 - 4];yy.addVertex($$[$0 - 4], $$[$0 - 2], 'odd');
  39332. break;
  39333. case 55:
  39334. this.$ = $$[$0];yy.addVertex($$[$0]);
  39335. break;
  39336. case 56:
  39337. this.$ = $$[$0 - 1];yy.addVertex($$[$0 - 1]);
  39338. break;
  39339. case 58:case 93:case 96:case 109:
  39340. this.$ = $$[$0 - 1] + '' + $$[$0];
  39341. break;
  39342. case 61:
  39343. this.$ = 'v';
  39344. break;
  39345. case 62:
  39346. this.$ = '-';
  39347. break;
  39348. case 63:
  39349. $$[$0 - 1].text = $$[$0];this.$ = $$[$0 - 1];
  39350. break;
  39351. case 64:case 65:
  39352. $$[$0 - 2].text = $$[$0 - 1];this.$ = $$[$0 - 2];
  39353. break;
  39354. case 66:
  39355. this.$ = $$[$0];
  39356. break;
  39357. case 67:
  39358. this.$ = { "type": "arrow", "stroke": "normal", "text": $$[$0 - 1] };
  39359. break;
  39360. case 68:
  39361. this.$ = { "type": "arrow_circle", "stroke": "normal", "text": $$[$0 - 1] };
  39362. break;
  39363. case 69:
  39364. this.$ = { "type": "arrow_cross", "stroke": "normal", "text": $$[$0 - 1] };
  39365. break;
  39366. case 70:
  39367. this.$ = { "type": "arrow_open", "stroke": "normal", "text": $$[$0 - 1] };
  39368. break;
  39369. case 71:
  39370. this.$ = { "type": "arrow", "stroke": "dotted", "text": $$[$0 - 1] };
  39371. break;
  39372. case 72:
  39373. this.$ = { "type": "arrow_circle", "stroke": "dotted", "text": $$[$0 - 1] };
  39374. break;
  39375. case 73:
  39376. this.$ = { "type": "arrow_cross", "stroke": "dotted", "text": $$[$0 - 1] };
  39377. break;
  39378. case 74:
  39379. this.$ = { "type": "arrow_open", "stroke": "dotted", "text": $$[$0 - 1] };
  39380. break;
  39381. case 75:
  39382. this.$ = { "type": "arrow", "stroke": "thick", "text": $$[$0 - 1] };
  39383. break;
  39384. case 76:
  39385. this.$ = { "type": "arrow_circle", "stroke": "thick", "text": $$[$0 - 1] };
  39386. break;
  39387. case 77:
  39388. this.$ = { "type": "arrow_cross", "stroke": "thick", "text": $$[$0 - 1] };
  39389. break;
  39390. case 78:
  39391. this.$ = { "type": "arrow_open", "stroke": "thick", "text": $$[$0 - 1] };
  39392. break;
  39393. case 79:
  39394. this.$ = { "type": "arrow", "stroke": "normal" };
  39395. break;
  39396. case 80:
  39397. this.$ = { "type": "arrow_circle", "stroke": "normal" };
  39398. break;
  39399. case 81:
  39400. this.$ = { "type": "arrow_cross", "stroke": "normal" };
  39401. break;
  39402. case 82:
  39403. this.$ = { "type": "arrow_open", "stroke": "normal" };
  39404. break;
  39405. case 83:
  39406. this.$ = { "type": "arrow", "stroke": "dotted" };
  39407. break;
  39408. case 84:
  39409. this.$ = { "type": "arrow_circle", "stroke": "dotted" };
  39410. break;
  39411. case 85:
  39412. this.$ = { "type": "arrow_cross", "stroke": "dotted" };
  39413. break;
  39414. case 86:
  39415. this.$ = { "type": "arrow_open", "stroke": "dotted" };
  39416. break;
  39417. case 87:
  39418. this.$ = { "type": "arrow", "stroke": "thick" };
  39419. break;
  39420. case 88:
  39421. this.$ = { "type": "arrow_circle", "stroke": "thick" };
  39422. break;
  39423. case 89:
  39424. this.$ = { "type": "arrow_cross", "stroke": "thick" };
  39425. break;
  39426. case 90:
  39427. this.$ = { "type": "arrow_open", "stroke": "thick" };
  39428. break;
  39429. case 91:
  39430. this.$ = $$[$0 - 1];
  39431. break;
  39432. case 110:case 111:
  39433. this.$ = $$[$0 - 4];yy.addClass($$[$0 - 2], $$[$0]);
  39434. break;
  39435. case 112:
  39436. this.$ = $$[$0 - 4];yy.setClass($$[$0 - 2], $$[$0]);
  39437. break;
  39438. case 113:
  39439. this.$ = $$[$0 - 4];yy.setClickEvent($$[$0 - 2], $$[$0], undefined, undefined);
  39440. break;
  39441. case 114:
  39442. this.$ = $$[$0 - 6];yy.setClickEvent($$[$0 - 4], $$[$0 - 2], undefined, $$[$0]);
  39443. break;
  39444. case 115:
  39445. this.$ = $$[$0 - 4];yy.setClickEvent($$[$0 - 2], undefined, $$[$0], undefined);
  39446. break;
  39447. case 116:
  39448. this.$ = $$[$0 - 6];yy.setClickEvent($$[$0 - 4], undefined, $$[$0 - 2], $$[$0]);
  39449. break;
  39450. case 117:
  39451. this.$ = $$[$0 - 4];yy.addVertex($$[$0 - 2], undefined, undefined, $$[$0]);
  39452. break;
  39453. case 118:case 119:case 120:
  39454. this.$ = $$[$0 - 4];yy.updateLink($$[$0 - 2], $$[$0]);
  39455. break;
  39456. case 121:case 122:
  39457. this.$ = $$[$0 - 8];yy.updateLinkInterpolate($$[$0 - 6], $$[$0 - 2]);yy.updateLink($$[$0 - 6], $$[$0]);
  39458. break;
  39459. case 123:case 124:
  39460. this.$ = $$[$0 - 6];yy.updateLinkInterpolate($$[$0 - 4], $$[$0]);
  39461. break;
  39462. case 126:
  39463. this.$ = [$$[$0]];
  39464. break;
  39465. case 127:
  39466. $$[$0 - 2].push($$[$0]);this.$ = $$[$0 - 2];
  39467. break;
  39468. case 129:
  39469. this.$ = $$[$0 - 1] + $$[$0];
  39470. break;
  39471. }
  39472. },
  39473. table: [{ 3: 1, 4: 2, 9: $V0, 10: $V1, 12: $V2 }, { 1: [3] }, o($V3, $V4, { 5: 6 }), { 4: 7, 9: $V0, 10: $V1, 12: $V2 }, { 4: 8, 9: $V0, 10: $V1, 12: $V2 }, { 10: [1, 9] }, { 1: [2, 1], 6: 10, 7: 11, 8: $V5, 9: $V6, 10: $V7, 11: $V8, 13: $V9, 18: $Va, 23: 16, 25: 17, 26: 18, 27: 19, 28: 20, 29: 21, 30: $Vb, 33: 23, 35: 29, 44: 30, 45: 32, 46: $Vc, 71: $Vd, 72: $Ve, 73: $Vf, 74: $Vg, 75: $Vh, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, o($V3, [2, 9]), o($V3, [2, 10]), { 13: [1, 46], 15: [1, 47], 16: [1, 48], 17: [1, 49], 18: [1, 50] }, o($Vt, [2, 3]), o($Vt, [2, 4]), o($Vt, [2, 5]), o($Vt, [2, 6]), o($Vt, [2, 7]), o($Vt, [2, 8]), { 8: $Vu, 9: $Vv, 11: $Vw, 24: 51 }, { 8: $Vu, 9: $Vv, 11: $Vw, 24: 55 }, { 8: $Vu, 9: $Vv, 11: $Vw, 24: 56 }, { 8: $Vu, 9: $Vv, 11: $Vw, 24: 57 }, { 8: $Vu, 9: $Vv, 11: $Vw, 24: 58 }, { 8: $Vu, 9: $Vv, 11: $Vw, 24: 59 }, { 8: $Vu, 9: $Vv, 10: $Vx, 11: $Vw, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 24: 61, 30: $VE, 31: 60, 32: $VF, 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 62, 67: $VJ, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, o($VR, [2, 42], { 34: 86, 47: 87, 50: [1, 88], 51: [1, 91], 52: [1, 92], 53: [1, 93], 54: [1, 94], 55: [1, 89], 56: [1, 95], 57: [1, 96], 58: [1, 97], 59: [1, 98], 60: [1, 90], 61: [1, 99], 62: [1, 100], 63: [1, 101], 64: [1, 102] }), { 10: [1, 103] }, { 10: [1, 104] }, { 10: [1, 105] }, { 10: [1, 106] }, { 10: [1, 107] }, o($VS, [2, 55], { 45: 32, 21: 113, 44: 114, 10: $VT, 13: $V9, 15: [1, 112], 18: $Va, 36: [1, 108], 38: [1, 109], 40: [1, 110], 42: [1, 111], 46: $Vc, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }), o($VU, [2, 57]), o($VU, [2, 59]), o($VU, [2, 60]), o($VU, [2, 61]), o($VU, [2, 62]), o($VV, [2, 154]), o($VV, [2, 155]), o($VV, [2, 156]), o($VV, [2, 157]), o($VV, [2, 158]), o($VV, [2, 159]), o($VV, [2, 160]), o($VV, [2, 161]), o($VV, [2, 162]), o($VV, [2, 163]), o($VV, [2, 164]), { 8: $VW, 9: $VX, 10: $VT, 14: 116, 21: 119 }, { 8: $VW, 9: $VX, 10: $VT, 14: 120, 21: 119 }, { 8: $VW, 9: $VX, 10: $VT, 14: 121, 21: 119 }, { 8: $VW, 9: $VX, 10: $VT, 14: 122, 21: 119 }, { 8: $VW, 9: $VX, 10: $VT, 14: 123, 21: 119 }, o($Vt, [2, 30]), o($Vt, [2, 38]), o($Vt, [2, 39]), o($Vt, [2, 40]), o($Vt, [2, 31]), o($Vt, [2, 32]), o($Vt, [2, 33]), o($Vt, [2, 34]), o($Vt, [2, 35]), { 8: $Vu, 9: $Vv, 10: $Vx, 11: $Vw, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 24: 124, 30: $VE, 32: $VF, 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 125, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, o($VY, $V4, { 5: 126 }), o($VZ, [2, 92]), o($VZ, [2, 94]), o($VZ, [2, 143]), o($VZ, [2, 144]), o($VZ, [2, 145]), o($VZ, [2, 146]), o($VZ, [2, 147]), o($VZ, [2, 148]), o($VZ, [2, 149]), o($VZ, [2, 150]), o($VZ, [2, 151]), o($VZ, [2, 152]), o($VZ, [2, 153]), o($VZ, [2, 97]), o($VZ, [2, 98]), o($VZ, [2, 99]), o($VZ, [2, 100]), o($VZ, [2, 101]), o($VZ, [2, 102]), o($VZ, [2, 103]), o($VZ, [2, 104]), o($VZ, [2, 105]), o($VZ, [2, 106]), o($VZ, [2, 107]), { 13: $V9, 18: $Va, 33: 127, 35: 29, 44: 30, 45: 32, 46: $Vc, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, o($V_, [2, 66], { 48: 128, 49: [1, 129], 65: [1, 130] }), { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 31: 131, 32: $VF, 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 62, 67: $VJ, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 31: 132, 32: $VF, 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 62, 67: $VJ, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 31: 133, 32: $VF, 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 62, 67: $VJ, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, o($V$, [2, 79]), o($V$, [2, 80]), o($V$, [2, 81]), o($V$, [2, 82]), o($V$, [2, 83]), o($V$, [2, 84]), o($V$, [2, 85]), o($V$, [2, 86]), o($V$, [2, 87]), o($V$, [2, 88]), o($V$, [2, 89]), o($V$, [2, 90]), { 13: $V9, 18: $Va, 35: 134, 44: 30, 45: 32, 46: $Vc, 80: [1, 135], 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 78: [1, 136], 81: [1, 137] }, { 13: $V9, 18: $Va, 35: 139, 44: 30, 45: 32, 46: $Vc, 78: [1, 138], 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 13: $V9, 18: $Va, 35: 140, 44: 30, 45: 32, 46: $Vc, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 13: $V9, 18: $Va, 35: 141, 44: 30, 45: 32, 46: $Vc, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 31: 142, 32: $VF, 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 62, 67: $VJ, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 31: 144, 32: $VF, 38: [1, 143], 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 62, 67: $VJ, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 31: 145, 32: $VF, 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 62, 67: $VJ, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 31: 146, 32: $VF, 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 62, 67: $VJ, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 31: 147, 32: $VF, 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 62, 67: $VJ, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, o($VS, [2, 56]), o($VU, [2, 58]), o($VS, [2, 29], { 21: 148, 10: $VT }), o($V3, [2, 11]), o($V3, [2, 21]), o($V3, [2, 22]), { 9: [1, 149] }, o($V3, [2, 12]), o($V3, [2, 13]), o($V3, [2, 14]), o($V3, [2, 15]), o($VY, $V4, { 5: 150 }), o($VZ, [2, 93]), { 6: 10, 7: 11, 8: $V5, 9: $V6, 10: $V7, 11: $V8, 13: $V9, 18: $Va, 23: 16, 25: 17, 26: 18, 27: 19, 28: 20, 29: 21, 30: $Vb, 32: [1, 151], 33: 23, 35: 29, 44: 30, 45: 32, 46: $Vc, 71: $Vd, 72: $Ve, 73: $Vf, 74: $Vg, 75: $Vh, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, o($VR, [2, 41]), o($V_, [2, 63], { 10: [1, 152] }), { 10: [1, 153] }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 31: 154, 32: $VF, 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 62, 67: $VJ, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 32: $VF, 45: 71, 46: $VG, 50: $VH, 51: [1, 155], 52: [1, 156], 53: [1, 157], 54: [1, 158], 60: $VI, 66: 125, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 32: $VF, 45: 71, 46: $VG, 50: $VH, 56: [1, 159], 57: [1, 160], 58: [1, 161], 59: [1, 162], 60: $VI, 66: 125, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 32: $VF, 45: 71, 46: $VG, 50: $VH, 60: $VI, 61: [1, 163], 62: [1, 164], 63: [1, 165], 64: [1, 166], 66: 125, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: [1, 167], 13: $V9, 18: $Va, 44: 114, 45: 32, 46: $Vc, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: [1, 168] }, { 10: [1, 169] }, { 10: [1, 170] }, { 10: [1, 171] }, { 10: [1, 172], 13: $V9, 18: $Va, 44: 114, 45: 32, 46: $Vc, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: [1, 173], 13: $V9, 18: $Va, 44: 114, 45: 32, 46: $Vc, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: [1, 174], 13: $V9, 18: $Va, 44: 114, 45: 32, 46: $Vc, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 32: $VF, 37: [1, 175], 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 125, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 31: 176, 32: $VF, 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 62, 67: $VJ, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 32: $VF, 39: [1, 177], 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 125, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 32: $VF, 41: [1, 178], 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 125, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 32: $VF, 43: [1, 179], 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 125, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 32: $VF, 37: [1, 180], 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 125, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, o($VS, [2, 28]), o($V3, [2, 23]), { 6: 10, 7: 11, 8: $V5, 9: $V6, 10: $V7, 11: $V8, 13: $V9, 18: $Va, 23: 16, 25: 17, 26: 18, 27: 19, 28: 20, 29: 21, 30: $Vb, 32: [1, 181], 33: 23, 35: 29, 44: 30, 45: 32, 46: $Vc, 71: $Vd, 72: $Ve, 73: $Vf, 74: $Vg, 75: $Vh, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, o($Vt, [2, 37]), o($V_, [2, 65]), o($V_, [2, 64]), { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 32: $VF, 45: 71, 46: $VG, 50: $VH, 60: $VI, 65: [1, 182], 66: 125, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, o($V_, [2, 67]), o($V_, [2, 68]), o($V_, [2, 69]), o($V_, [2, 70]), o($V_, [2, 71]), o($V_, [2, 72]), o($V_, [2, 73]), o($V_, [2, 74]), o($V_, [2, 75]), o($V_, [2, 76]), o($V_, [2, 77]), o($V_, [2, 78]), { 10: $V01, 46: $V11, 71: $V21, 79: 183, 80: $V31, 81: $V41, 84: $V51, 85: 184, 87: 185, 88: $V61, 89: $V71, 90: $V81, 91: $V91, 92: $Va1 }, { 10: $V01, 46: $V11, 71: $V21, 79: 197, 80: $V31, 81: $V41, 84: $V51, 85: 184, 87: 185, 88: $V61, 89: $V71, 90: $V81, 91: $V91, 92: $Va1 }, { 10: $V01, 46: $V11, 71: $V21, 79: 198, 80: $V31, 81: $V41, 82: [1, 199], 84: $V51, 85: 184, 87: 185, 88: $V61, 89: $V71, 90: $V81, 91: $V91, 92: $Va1 }, { 10: $V01, 46: $V11, 71: $V21, 79: 200, 80: $V31, 81: $V41, 82: [1, 201], 84: $V51, 85: 184, 87: 185, 88: $V61, 89: $V71, 90: $V81, 91: $V91, 92: $Va1 }, { 10: $V01, 46: $V11, 71: $V21, 79: 202, 80: $V31, 81: $V41, 84: $V51, 85: 184, 87: 185, 88: $V61, 89: $V71, 90: $V81, 91: $V91, 92: $Va1 }, { 10: $V01, 46: $V11, 71: $V21, 79: 203, 80: $V31, 81: $V41, 84: $V51, 85: 184, 87: 185, 88: $V61, 89: $V71, 90: $V81, 91: $V91, 92: $Va1 }, { 13: $V9, 18: $Va, 35: 204, 44: 30, 45: 32, 46: $Vc, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 13: $V9, 18: $Va, 35: 205, 44: 30, 45: 32, 46: $Vc, 67: [1, 206], 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, o($VS, [2, 43], { 21: 207, 10: $VT }), { 10: $Vx, 12: $Vy, 13: $Vz, 15: $VA, 16: $VB, 17: $VC, 18: $VD, 30: $VE, 32: $VF, 39: [1, 208], 45: 71, 46: $VG, 50: $VH, 60: $VI, 66: 125, 70: 74, 71: $VK, 72: $VL, 73: $VM, 74: $VN, 75: $VO, 77: 64, 78: $VP, 81: $Vi, 84: $VQ, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, o($VS, [2, 49], { 21: 209, 10: $VT }), o($VS, [2, 47], { 21: 210, 10: $VT }), o($VS, [2, 51], { 21: 211, 10: $VT }), o($VS, [2, 53], { 21: 212, 10: $VT }), o($Vt, [2, 36]), o([10, 13, 18, 46, 81, 86, 88, 89, 91, 92, 94, 95, 96, 97, 98], [2, 91]), o($VR, [2, 117], { 86: $Vb1 }), o($Vc1, [2, 126], { 87: 214, 10: $V01, 46: $V11, 71: $V21, 80: $V31, 81: $V41, 84: $V51, 88: $V61, 89: $V71, 90: $V81, 91: $V91, 92: $Va1 }), o($Vd1, [2, 128]), o($Vd1, [2, 130]), o($Vd1, [2, 131]), o($Vd1, [2, 132]), o($Vd1, [2, 133]), o($Vd1, [2, 134]), o($Vd1, [2, 135]), o($Vd1, [2, 136]), o($Vd1, [2, 137]), o($Vd1, [2, 138]), o($Vd1, [2, 139]), o($Vd1, [2, 140]), o($VR, [2, 118], { 86: $Vb1 }), o($VR, [2, 119], { 86: $Vb1 }), { 10: [1, 215] }, o($VR, [2, 120], { 86: $Vb1 }), { 10: [1, 216] }, o($VR, [2, 110], { 86: $Vb1 }), o($VR, [2, 111], { 86: $Vb1 }), o($VR, [2, 112], { 45: 32, 44: 114, 13: $V9, 18: $Va, 46: $Vc, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }), o($VR, [2, 113], { 45: 32, 44: 114, 10: [1, 217], 13: $V9, 18: $Va, 46: $Vc, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }), o($VR, [2, 115], { 10: [1, 218] }), o($VS, [2, 44]), { 39: [1, 219] }, o($VS, [2, 50]), o($VS, [2, 48]), o($VS, [2, 52]), o($VS, [2, 54]), { 10: $V01, 46: $V11, 71: $V21, 80: $V31, 81: $V41, 84: $V51, 85: 220, 87: 185, 88: $V61, 89: $V71, 90: $V81, 91: $V91, 92: $Va1 }, o($Vd1, [2, 129]), { 13: $V9, 18: $Va, 35: 221, 44: 30, 45: 32, 46: $Vc, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 13: $V9, 18: $Va, 35: 222, 44: 30, 45: 32, 46: $Vc, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }, { 67: [1, 223] }, { 67: [1, 224] }, o($VS, [2, 45], { 21: 225, 10: $VT }), o($Vc1, [2, 127], { 87: 214, 10: $V01, 46: $V11, 71: $V21, 80: $V31, 81: $V41, 84: $V51, 88: $V61, 89: $V71, 90: $V81, 91: $V91, 92: $Va1 }), o($VR, [2, 123], { 45: 32, 44: 114, 10: [1, 226], 13: $V9, 18: $Va, 46: $Vc, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }), o($VR, [2, 124], { 45: 32, 44: 114, 10: [1, 227], 13: $V9, 18: $Va, 46: $Vc, 81: $Vi, 86: $Vj, 88: $Vk, 89: $Vl, 91: $Vm, 92: $Vn, 94: $Vo, 95: $Vp, 96: $Vq, 97: $Vr, 98: $Vs }), o($VR, [2, 114]), o($VR, [2, 116]), o($VS, [2, 46]), { 10: $V01, 46: $V11, 71: $V21, 79: 228, 80: $V31, 81: $V41, 84: $V51, 85: 184, 87: 185, 88: $V61, 89: $V71, 90: $V81, 91: $V91, 92: $Va1 }, { 10: $V01, 46: $V11, 71: $V21, 79: 229, 80: $V31, 81: $V41, 84: $V51, 85: 184, 87: 185, 88: $V61, 89: $V71, 90: $V81, 91: $V91, 92: $Va1 }, o($VR, [2, 121], { 86: $Vb1 }), o($VR, [2, 122], { 86: $Vb1 })],
  39474. defaultActions: {},
  39475. parseError: function parseError(str, hash) {
  39476. if (hash.recoverable) {
  39477. this.trace(str);
  39478. } else {
  39479. var _parseError = function _parseError(msg, hash) {
  39480. this.message = msg;
  39481. this.hash = hash;
  39482. };
  39483. _parseError.prototype = Error;
  39484. throw new _parseError(str, hash);
  39485. }
  39486. },
  39487. parse: function parse(input) {
  39488. var self = this,
  39489. stack = [0],
  39490. tstack = [],
  39491. vstack = [null],
  39492. lstack = [],
  39493. table = this.table,
  39494. yytext = '',
  39495. yylineno = 0,
  39496. yyleng = 0,
  39497. recovering = 0,
  39498. TERROR = 2,
  39499. EOF = 1;
  39500. var args = lstack.slice.call(arguments, 1);
  39501. var lexer = Object.create(this.lexer);
  39502. var sharedState = { yy: {} };
  39503. for (var k in this.yy) {
  39504. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  39505. sharedState.yy[k] = this.yy[k];
  39506. }
  39507. }
  39508. lexer.setInput(input, sharedState.yy);
  39509. sharedState.yy.lexer = lexer;
  39510. sharedState.yy.parser = this;
  39511. if (typeof lexer.yylloc == 'undefined') {
  39512. lexer.yylloc = {};
  39513. }
  39514. var yyloc = lexer.yylloc;
  39515. lstack.push(yyloc);
  39516. var ranges = lexer.options && lexer.options.ranges;
  39517. if (typeof sharedState.yy.parseError === 'function') {
  39518. this.parseError = sharedState.yy.parseError;
  39519. } else {
  39520. this.parseError = Object.getPrototypeOf(this).parseError;
  39521. }
  39522. function popStack(n) {
  39523. stack.length = stack.length - 2 * n;
  39524. vstack.length = vstack.length - n;
  39525. lstack.length = lstack.length - n;
  39526. }
  39527. _token_stack: var lex = function lex() {
  39528. var token;
  39529. token = lexer.lex() || EOF;
  39530. if (typeof token !== 'number') {
  39531. token = self.symbols_[token] || token;
  39532. }
  39533. return token;
  39534. };
  39535. var symbol,
  39536. preErrorSymbol,
  39537. state,
  39538. action,
  39539. a,
  39540. r,
  39541. yyval = {},
  39542. p,
  39543. len,
  39544. newState,
  39545. expected;
  39546. while (true) {
  39547. state = stack[stack.length - 1];
  39548. if (this.defaultActions[state]) {
  39549. action = this.defaultActions[state];
  39550. } else {
  39551. if (symbol === null || typeof symbol == 'undefined') {
  39552. symbol = lex();
  39553. }
  39554. action = table[state] && table[state][symbol];
  39555. }
  39556. if (typeof action === 'undefined' || !action.length || !action[0]) {
  39557. var errStr = '';
  39558. expected = [];
  39559. for (p in table[state]) {
  39560. if (this.terminals_[p] && p > TERROR) {
  39561. expected.push('\'' + this.terminals_[p] + '\'');
  39562. }
  39563. }
  39564. if (lexer.showPosition) {
  39565. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  39566. } else {
  39567. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  39568. }
  39569. this.parseError(errStr, {
  39570. text: lexer.match,
  39571. token: this.terminals_[symbol] || symbol,
  39572. line: lexer.yylineno,
  39573. loc: yyloc,
  39574. expected: expected
  39575. });
  39576. }
  39577. if (action[0] instanceof Array && action.length > 1) {
  39578. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  39579. }
  39580. switch (action[0]) {
  39581. case 1:
  39582. stack.push(symbol);
  39583. vstack.push(lexer.yytext);
  39584. lstack.push(lexer.yylloc);
  39585. stack.push(action[1]);
  39586. symbol = null;
  39587. if (!preErrorSymbol) {
  39588. yyleng = lexer.yyleng;
  39589. yytext = lexer.yytext;
  39590. yylineno = lexer.yylineno;
  39591. yyloc = lexer.yylloc;
  39592. if (recovering > 0) {
  39593. recovering--;
  39594. }
  39595. } else {
  39596. symbol = preErrorSymbol;
  39597. preErrorSymbol = null;
  39598. }
  39599. break;
  39600. case 2:
  39601. len = this.productions_[action[1]][1];
  39602. yyval.$ = vstack[vstack.length - len];
  39603. yyval._$ = {
  39604. first_line: lstack[lstack.length - (len || 1)].first_line,
  39605. last_line: lstack[lstack.length - 1].last_line,
  39606. first_column: lstack[lstack.length - (len || 1)].first_column,
  39607. last_column: lstack[lstack.length - 1].last_column
  39608. };
  39609. if (ranges) {
  39610. yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
  39611. }
  39612. r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
  39613. if (typeof r !== 'undefined') {
  39614. return r;
  39615. }
  39616. if (len) {
  39617. stack = stack.slice(0, -1 * len * 2);
  39618. vstack = vstack.slice(0, -1 * len);
  39619. lstack = lstack.slice(0, -1 * len);
  39620. }
  39621. stack.push(this.productions_[action[1]][0]);
  39622. vstack.push(yyval.$);
  39623. lstack.push(yyval._$);
  39624. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  39625. stack.push(newState);
  39626. break;
  39627. case 3:
  39628. return true;
  39629. }
  39630. }
  39631. return true;
  39632. } };
  39633. /* generated by jison-lex 0.3.4 */
  39634. var lexer = (function () {
  39635. var lexer = {
  39636. EOF: 1,
  39637. parseError: function parseError(str, hash) {
  39638. if (this.yy.parser) {
  39639. this.yy.parser.parseError(str, hash);
  39640. } else {
  39641. throw new Error(str);
  39642. }
  39643. },
  39644. // resets the lexer, sets new input
  39645. setInput: function setInput(input, yy) {
  39646. this.yy = yy || this.yy || {};
  39647. this._input = input;
  39648. this._more = this._backtrack = this.done = false;
  39649. this.yylineno = this.yyleng = 0;
  39650. this.yytext = this.matched = this.match = '';
  39651. this.conditionStack = ['INITIAL'];
  39652. this.yylloc = {
  39653. first_line: 1,
  39654. first_column: 0,
  39655. last_line: 1,
  39656. last_column: 0
  39657. };
  39658. if (this.options.ranges) {
  39659. this.yylloc.range = [0, 0];
  39660. }
  39661. this.offset = 0;
  39662. return this;
  39663. },
  39664. // consumes and returns one char from the input
  39665. input: function input() {
  39666. var ch = this._input[0];
  39667. this.yytext += ch;
  39668. this.yyleng++;
  39669. this.offset++;
  39670. this.match += ch;
  39671. this.matched += ch;
  39672. var lines = ch.match(/(?:\r\n?|\n).*/g);
  39673. if (lines) {
  39674. this.yylineno++;
  39675. this.yylloc.last_line++;
  39676. } else {
  39677. this.yylloc.last_column++;
  39678. }
  39679. if (this.options.ranges) {
  39680. this.yylloc.range[1]++;
  39681. }
  39682. this._input = this._input.slice(1);
  39683. return ch;
  39684. },
  39685. // unshifts one char (or a string) into the input
  39686. unput: function unput(ch) {
  39687. var len = ch.length;
  39688. var lines = ch.split(/(?:\r\n?|\n)/g);
  39689. this._input = ch + this._input;
  39690. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  39691. //this.yyleng -= len;
  39692. this.offset -= len;
  39693. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  39694. this.match = this.match.substr(0, this.match.length - 1);
  39695. this.matched = this.matched.substr(0, this.matched.length - 1);
  39696. if (lines.length - 1) {
  39697. this.yylineno -= lines.length - 1;
  39698. }
  39699. var r = this.yylloc.range;
  39700. this.yylloc = {
  39701. first_line: this.yylloc.first_line,
  39702. last_line: this.yylineno + 1,
  39703. first_column: this.yylloc.first_column,
  39704. last_column: lines ? (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length : this.yylloc.first_column - len
  39705. };
  39706. if (this.options.ranges) {
  39707. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  39708. }
  39709. this.yyleng = this.yytext.length;
  39710. return this;
  39711. },
  39712. // When called from action, caches matched text and appends it on next action
  39713. more: function more() {
  39714. this._more = true;
  39715. return this;
  39716. },
  39717. // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
  39718. reject: function reject() {
  39719. if (this.options.backtrack_lexer) {
  39720. this._backtrack = true;
  39721. } else {
  39722. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), {
  39723. text: "",
  39724. token: null,
  39725. line: this.yylineno
  39726. });
  39727. }
  39728. return this;
  39729. },
  39730. // retain first n characters of the match
  39731. less: function less(n) {
  39732. this.unput(this.match.slice(n));
  39733. },
  39734. // displays already matched input, i.e. for error messages
  39735. pastInput: function pastInput() {
  39736. var past = this.matched.substr(0, this.matched.length - this.match.length);
  39737. return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
  39738. },
  39739. // displays upcoming input, i.e. for error messages
  39740. upcomingInput: function upcomingInput() {
  39741. var next = this.match;
  39742. if (next.length < 20) {
  39743. next += this._input.substr(0, 20 - next.length);
  39744. }
  39745. return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  39746. },
  39747. // displays the character position where the lexing error occurred, i.e. for error messages
  39748. showPosition: function showPosition() {
  39749. var pre = this.pastInput();
  39750. var c = new Array(pre.length + 1).join("-");
  39751. return pre + this.upcomingInput() + "\n" + c + "^";
  39752. },
  39753. // test the lexed token: return FALSE when not a match, otherwise return token
  39754. test_match: function test_match(match, indexed_rule) {
  39755. var token, lines, backup;
  39756. if (this.options.backtrack_lexer) {
  39757. // save context
  39758. backup = {
  39759. yylineno: this.yylineno,
  39760. yylloc: {
  39761. first_line: this.yylloc.first_line,
  39762. last_line: this.last_line,
  39763. first_column: this.yylloc.first_column,
  39764. last_column: this.yylloc.last_column
  39765. },
  39766. yytext: this.yytext,
  39767. match: this.match,
  39768. matches: this.matches,
  39769. matched: this.matched,
  39770. yyleng: this.yyleng,
  39771. offset: this.offset,
  39772. _more: this._more,
  39773. _input: this._input,
  39774. yy: this.yy,
  39775. conditionStack: this.conditionStack.slice(0),
  39776. done: this.done
  39777. };
  39778. if (this.options.ranges) {
  39779. backup.yylloc.range = this.yylloc.range.slice(0);
  39780. }
  39781. }
  39782. lines = match[0].match(/(?:\r\n?|\n).*/g);
  39783. if (lines) {
  39784. this.yylineno += lines.length;
  39785. }
  39786. this.yylloc = {
  39787. first_line: this.yylloc.last_line,
  39788. last_line: this.yylineno + 1,
  39789. first_column: this.yylloc.last_column,
  39790. last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
  39791. };
  39792. this.yytext += match[0];
  39793. this.match += match[0];
  39794. this.matches = match;
  39795. this.yyleng = this.yytext.length;
  39796. if (this.options.ranges) {
  39797. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  39798. }
  39799. this._more = false;
  39800. this._backtrack = false;
  39801. this._input = this._input.slice(match[0].length);
  39802. this.matched += match[0];
  39803. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  39804. if (this.done && this._input) {
  39805. this.done = false;
  39806. }
  39807. if (token) {
  39808. return token;
  39809. } else if (this._backtrack) {
  39810. // recover context
  39811. for (var k in backup) {
  39812. this[k] = backup[k];
  39813. }
  39814. return false; // rule action called reject() implying the next rule should be tested instead.
  39815. }
  39816. return false;
  39817. },
  39818. // return next match in input
  39819. next: function next() {
  39820. if (this.done) {
  39821. return this.EOF;
  39822. }
  39823. if (!this._input) {
  39824. this.done = true;
  39825. }
  39826. var token, match, tempMatch, index;
  39827. if (!this._more) {
  39828. this.yytext = '';
  39829. this.match = '';
  39830. }
  39831. var rules = this._currentRules();
  39832. for (var i = 0; i < rules.length; i++) {
  39833. tempMatch = this._input.match(this.rules[rules[i]]);
  39834. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  39835. match = tempMatch;
  39836. index = i;
  39837. if (this.options.backtrack_lexer) {
  39838. token = this.test_match(tempMatch, rules[i]);
  39839. if (token !== false) {
  39840. return token;
  39841. } else if (this._backtrack) {
  39842. match = false;
  39843. continue; // rule action called reject() implying a rule MISmatch.
  39844. } else {
  39845. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  39846. return false;
  39847. }
  39848. } else if (!this.options.flex) {
  39849. break;
  39850. }
  39851. }
  39852. }
  39853. if (match) {
  39854. token = this.test_match(match, rules[index]);
  39855. if (token !== false) {
  39856. return token;
  39857. }
  39858. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  39859. return false;
  39860. }
  39861. if (this._input === "") {
  39862. return this.EOF;
  39863. } else {
  39864. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  39865. text: "",
  39866. token: null,
  39867. line: this.yylineno
  39868. });
  39869. }
  39870. },
  39871. // return next match that has a token
  39872. lex: function lex() {
  39873. var r = this.next();
  39874. if (r) {
  39875. return r;
  39876. } else {
  39877. return this.lex();
  39878. }
  39879. },
  39880. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  39881. begin: function begin(condition) {
  39882. this.conditionStack.push(condition);
  39883. },
  39884. // pop the previously active lexer condition state off the condition stack
  39885. popState: function popState() {
  39886. var n = this.conditionStack.length - 1;
  39887. if (n > 0) {
  39888. return this.conditionStack.pop();
  39889. } else {
  39890. return this.conditionStack[0];
  39891. }
  39892. },
  39893. // produce the lexer rule set which is active for the currently active lexer condition state
  39894. _currentRules: function _currentRules() {
  39895. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  39896. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  39897. } else {
  39898. return this.conditions["INITIAL"].rules;
  39899. }
  39900. },
  39901. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  39902. topState: function topState(n) {
  39903. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  39904. if (n >= 0) {
  39905. return this.conditionStack[n];
  39906. } else {
  39907. return "INITIAL";
  39908. }
  39909. },
  39910. // alias for begin(condition)
  39911. pushState: function pushState(condition) {
  39912. this.begin(condition);
  39913. },
  39914. // return the number of states currently on the stack
  39915. stateStackSize: function stateStackSize() {
  39916. return this.conditionStack.length;
  39917. },
  39918. options: {},
  39919. performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
  39920. var YYSTATE = YY_START;
  39921. switch ($avoiding_name_collisions) {
  39922. case 0:
  39923. /* do nothing */
  39924. break;
  39925. case 1:
  39926. this.begin("string");
  39927. break;
  39928. case 2:
  39929. this.popState();
  39930. break;
  39931. case 3:
  39932. return "STR";
  39933. break;
  39934. case 4:
  39935. return 71;
  39936. break;
  39937. case 5:
  39938. return 78;
  39939. break;
  39940. case 6:
  39941. return 72;
  39942. break;
  39943. case 7:
  39944. return 82;
  39945. break;
  39946. case 8:
  39947. return 73;
  39948. break;
  39949. case 9:
  39950. return 74;
  39951. break;
  39952. case 10:
  39953. return 75;
  39954. break;
  39955. case 11:
  39956. return 12;
  39957. break;
  39958. case 12:
  39959. return 30;
  39960. break;
  39961. case 13:
  39962. return 32;
  39963. break;
  39964. case 14:
  39965. return 13;
  39966. break;
  39967. case 15:
  39968. return 13;
  39969. break;
  39970. case 16:
  39971. return 13;
  39972. break;
  39973. case 17:
  39974. return 13;
  39975. break;
  39976. case 18:
  39977. return 13;
  39978. break;
  39979. case 19:
  39980. return 13;
  39981. break;
  39982. case 20:
  39983. return 81;
  39984. break;
  39985. case 21:
  39986. return 91;
  39987. break;
  39988. case 22:
  39989. return 89;
  39990. break;
  39991. case 23:
  39992. return 8;
  39993. break;
  39994. case 24:
  39995. return 86;
  39996. break;
  39997. case 25:
  39998. return 98;
  39999. break;
  40000. case 26:
  40001. return 16;
  40002. break;
  40003. case 27:
  40004. return 15;
  40005. break;
  40006. case 28:
  40007. return 17;
  40008. break;
  40009. case 29:
  40010. return 18;
  40011. break;
  40012. case 30:
  40013. return 53;
  40014. break;
  40015. case 31:
  40016. return 51;
  40017. break;
  40018. case 32:
  40019. return 52;
  40020. break;
  40021. case 33:
  40022. return 54;
  40023. break;
  40024. case 34:
  40025. return 58;
  40026. break;
  40027. case 35:
  40028. return 56;
  40029. break;
  40030. case 36:
  40031. return 57;
  40032. break;
  40033. case 37:
  40034. return 59;
  40035. break;
  40036. case 38:
  40037. return 58;
  40038. break;
  40039. case 39:
  40040. return 56;
  40041. break;
  40042. case 40:
  40043. return 57;
  40044. break;
  40045. case 41:
  40046. return 59;
  40047. break;
  40048. case 42:
  40049. return 63;
  40050. break;
  40051. case 43:
  40052. return 61;
  40053. break;
  40054. case 44:
  40055. return 62;
  40056. break;
  40057. case 45:
  40058. return 64;
  40059. break;
  40060. case 46:
  40061. return 50;
  40062. break;
  40063. case 47:
  40064. return 55;
  40065. break;
  40066. case 48:
  40067. return 60;
  40068. break;
  40069. case 49:
  40070. return 40;
  40071. break;
  40072. case 50:
  40073. return 41;
  40074. break;
  40075. case 51:
  40076. return 46;
  40077. break;
  40078. case 52:
  40079. return 92;
  40080. break;
  40081. case 53:
  40082. return 96;
  40083. break;
  40084. case 54:
  40085. return 84;
  40086. break;
  40087. case 55:
  40088. return 97;
  40089. break;
  40090. case 56:
  40091. return 97;
  40092. break;
  40093. case 57:
  40094. return 88;
  40095. break;
  40096. case 58:
  40097. return 94;
  40098. break;
  40099. case 59:
  40100. return 95;
  40101. break;
  40102. case 60:
  40103. return 65;
  40104. break;
  40105. case 61:
  40106. return 38;
  40107. break;
  40108. case 62:
  40109. return 39;
  40110. break;
  40111. case 63:
  40112. return 36;
  40113. break;
  40114. case 64:
  40115. return 37;
  40116. break;
  40117. case 65:
  40118. return 42;
  40119. break;
  40120. case 66:
  40121. return 43;
  40122. break;
  40123. case 67:
  40124. return 101;
  40125. break;
  40126. case 68:
  40127. return 9;
  40128. break;
  40129. case 69:
  40130. return 10;
  40131. break;
  40132. case 70:
  40133. return 11;
  40134. break;
  40135. }
  40136. },
  40137. rules: [/^(?:%%[^\n]*)/, /^(?:["])/, /^(?:["])/, /^(?:[^"]*)/, /^(?:style\b)/, /^(?:default\b)/, /^(?:linkStyle\b)/, /^(?:interpolate\b)/, /^(?:classDef\b)/, /^(?:class\b)/, /^(?:click\b)/, /^(?:graph\b)/, /^(?:subgraph\b)/, /^(?:end\b\s*)/, /^(?:LR\b)/, /^(?:RL\b)/, /^(?:TB\b)/, /^(?:BT\b)/, /^(?:TD\b)/, /^(?:BR\b)/, /^(?:[0-9]+)/, /^(?:#)/, /^(?::)/, /^(?:;)/, /^(?:,)/, /^(?:\*)/, /^(?:<)/, /^(?:>)/, /^(?:\^)/, /^(?:v\b)/, /^(?:\s*--[x]\s*)/, /^(?:\s*-->\s*)/, /^(?:\s*--[o]\s*)/, /^(?:\s*---\s*)/, /^(?:\s*-\.-[x]\s*)/, /^(?:\s*-\.->\s*)/, /^(?:\s*-\.-[o]\s*)/, /^(?:\s*-\.-\s*)/, /^(?:\s*.-[x]\s*)/, /^(?:\s*\.->\s*)/, /^(?:\s*\.-[o]\s*)/, /^(?:\s*\.-\s*)/, /^(?:\s*==[x]\s*)/, /^(?:\s*==>\s*)/, /^(?:\s*==[o]\s*)/, /^(?:\s*==[\=]\s*)/, /^(?:\s*--\s*)/, /^(?:\s*-\.\s*)/, /^(?:\s*==\s*)/, /^(?:\(-)/, /^(?:-\))/, /^(?:-)/, /^(?:\.)/, /^(?:\+)/, /^(?:%)/, /^(?:=)/, /^(?:=)/, /^(?:[A-Za-z]+)/, /^(?:[!"#$%&'*+,-.`?\\_\/])/, /^(?:[\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6]|[\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377]|[\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5]|[\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA]|[\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE]|[\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA]|[\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0]|[\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977]|[\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2]|[\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A]|[\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39]|[\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8]|[\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C]|[\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C]|[\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99]|[\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0]|[\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D]|[\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3]|[\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10]|[\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1]|[\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81]|[\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3]|[\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6]|[\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A]|[\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081]|[\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D]|[\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0]|[\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310]|[\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C]|[\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711]|[\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7]|[\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C]|[\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16]|[\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF]|[\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC]|[\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D]|[\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D]|[\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3]|[\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F]|[\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128]|[\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184]|[\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3]|[\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6]|[\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE]|[\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C]|[\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D]|[\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC]|[\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B]|[\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788]|[\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805]|[\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB]|[\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28]|[\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5]|[\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4]|[\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E]|[\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D]|[\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36]|[\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D]|[\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC]|[\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF]|[\uFFD2-\uFFD7\uFFDA-\uFFDC])/, /^(?:\|)/, /^(?:\()/, /^(?:\))/, /^(?:\[)/, /^(?:\])/, /^(?:\{)/, /^(?:\})/, /^(?:")/, /^(?:\n+)/, /^(?:\s)/, /^(?:$)/],
  40138. conditions: { "string": { "rules": [2, 3], "inclusive": false }, "INITIAL": { "rules": [0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70], "inclusive": true } }
  40139. };
  40140. return lexer;
  40141. })();
  40142. parser.lexer = lexer;
  40143. function Parser() {
  40144. this.yy = {};
  40145. }
  40146. Parser.prototype = parser;parser.Parser = Parser;
  40147. return new Parser();
  40148. })();
  40149. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  40150. exports.parser = parser;
  40151. exports.Parser = parser.Parser;
  40152. exports.parse = function () {
  40153. return parser.parse.apply(parser, arguments);
  40154. };
  40155. exports.main = function commonjsMain(args) {
  40156. if (!args[1]) {
  40157. console.log('Usage: ' + args[0] + ' FILE');
  40158. process.exit(1);
  40159. }
  40160. var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
  40161. return exports.parser.parse(source);
  40162. };
  40163. if (typeof module !== 'undefined' && require.main === module) {
  40164. exports.main(process.argv.slice(1));
  40165. }
  40166. }
  40167. }).call(this,require('_process'))
  40168. },{"_process":105,"fs":1,"path":104}],119:[function(require,module,exports){
  40169. (function (global){
  40170. /**
  40171. * Created by knut on 15-01-14.
  40172. */
  40173. 'use strict';
  40174. var moment = require('moment');
  40175. var Logger = require('../../logger');
  40176. var log = new Logger.Log();
  40177. var dateFormat = '';
  40178. var title = '';
  40179. var sections = [];
  40180. var tasks = [];
  40181. var currentSection = '';
  40182. exports.clear = function () {
  40183. sections = [];
  40184. tasks = [];
  40185. currentSection = '';
  40186. title = '';
  40187. taskCnt = 0;
  40188. lastTask = undefined;
  40189. lastTaskID = undefined;
  40190. rawTasks = [];
  40191. };
  40192. exports.setDateFormat = function (txt) {
  40193. dateFormat = txt;
  40194. };
  40195. exports.getDateFormat = function () {
  40196. return dateFormat;
  40197. };
  40198. exports.setTitle = function (txt) {
  40199. title = txt;
  40200. };
  40201. exports.getTitle = function () {
  40202. return title;
  40203. };
  40204. exports.addSection = function (txt) {
  40205. currentSection = txt;
  40206. sections.push(txt);
  40207. };
  40208. exports.getTasks = function () {
  40209. var allItemsPricessed = compileTasks();
  40210. var maxDepth = 10;
  40211. var iterationCount = 0;
  40212. while (!allItemsPricessed && iterationCount < maxDepth) {
  40213. allItemsPricessed = compileTasks();
  40214. iterationCount++;
  40215. }
  40216. tasks = rawTasks;
  40217. //var i;
  40218. //for(i=10000;i<tasks.length;i++){
  40219. // tasks[i].startTime = moment(tasks[i].startTime).format(dateFormat);
  40220. // tasks[i].endTime = moment(tasks[i].endTime).format(dateFormat);
  40221. //}
  40222. return tasks;
  40223. };
  40224. var getStartDate = function getStartDate(prevTime, dateFormat, str) {
  40225. //console.log('Deciding start date:'+JSON.stringify(str));
  40226. //log.debug('Deciding start date:'+str);
  40227. //log.debug('with dateformat:'+dateFormat);
  40228. str = str.trim();
  40229. // Test for after
  40230. var re = /^after\s+([\d\w\-]+)/;
  40231. var afterStatement = re.exec(str.trim());
  40232. if (afterStatement !== null) {
  40233. var task = exports.findTaskById(afterStatement[1]);
  40234. if (typeof task === 'undefined') {
  40235. var dt = new Date();
  40236. dt.setHours(0, 0, 0, 0);
  40237. return dt;
  40238. //return undefined;
  40239. }
  40240. return task.endTime;
  40241. }
  40242. // Check for actual date set
  40243. if (moment(str, dateFormat.trim(), true).isValid()) {
  40244. return moment(str, dateFormat.trim(), true).toDate();
  40245. } else {
  40246. log.debug('Invalid date:' + str);
  40247. log.debug('With date format:' + dateFormat.trim());
  40248. //log.debug('----');
  40249. }
  40250. // Default date - now
  40251. return new Date();
  40252. };
  40253. var getEndDate = function getEndDate(prevTime, dateFormat, str) {
  40254. str = str.trim();
  40255. // Check for actual date
  40256. if (moment(str, dateFormat.trim(), true).isValid()) {
  40257. return moment(str, dateFormat.trim()).toDate();
  40258. }
  40259. var d = moment(prevTime);
  40260. // Check for length
  40261. var re = /^([\d]+)([wdhms])/;
  40262. var durationStatement = re.exec(str.trim());
  40263. if (durationStatement !== null) {
  40264. switch (durationStatement[2]) {
  40265. case 's':
  40266. d.add(durationStatement[1], 'seconds');
  40267. break;
  40268. case 'm':
  40269. d.add(durationStatement[1], 'minutes');
  40270. break;
  40271. case 'h':
  40272. d.add(durationStatement[1], 'hours');
  40273. break;
  40274. case 'd':
  40275. d.add(durationStatement[1], 'days');
  40276. break;
  40277. case 'w':
  40278. d.add(durationStatement[1], 'weeks');
  40279. break;
  40280. }
  40281. return d.toDate();
  40282. }
  40283. // Default date - now
  40284. return d.toDate();
  40285. };
  40286. var taskCnt = 0;
  40287. var parseId = function parseId(idStr) {
  40288. if (typeof idStr === 'undefined') {
  40289. taskCnt = taskCnt + 1;
  40290. return 'task' + taskCnt;
  40291. }
  40292. return idStr;
  40293. };
  40294. // id, startDate, endDate
  40295. // id, startDate, length
  40296. // id, after x, endDate
  40297. // id, after x, length
  40298. // startDate, endDate
  40299. // startDate, length
  40300. // after x, endDate
  40301. // after x, length
  40302. // endDate
  40303. // length
  40304. var compileData = function compileData(prevTask, dataStr) {
  40305. var ds;
  40306. if (dataStr.substr(0, 1) === ':') {
  40307. ds = dataStr.substr(1, dataStr.length);
  40308. } else {
  40309. ds = dataStr;
  40310. }
  40311. var data = ds.split(',');
  40312. var task = {};
  40313. var df = exports.getDateFormat();
  40314. // Get tags like active, done cand crit
  40315. var matchFound = true;
  40316. while (matchFound) {
  40317. matchFound = false;
  40318. if (data[0].match(/^\s*active\s*$/)) {
  40319. task.active = true;
  40320. data.shift(1);
  40321. matchFound = true;
  40322. }
  40323. if (data[0].match(/^\s*done\s*$/)) {
  40324. task.done = true;
  40325. data.shift(1);
  40326. matchFound = true;
  40327. }
  40328. if (data[0].match(/^\s*crit\s*$/)) {
  40329. task.crit = true;
  40330. data.shift(1);
  40331. matchFound = true;
  40332. }
  40333. }
  40334. var i;
  40335. for (i = 0; i < data.length; i++) {
  40336. data[i] = data[i].trim();
  40337. }
  40338. switch (data.length) {
  40339. case 1:
  40340. task.id = parseId();
  40341. task.startTime = prevTask.endTime;
  40342. task.endTime = getEndDate(task.startTime, df, data[0]);
  40343. break;
  40344. case 2:
  40345. task.id = parseId();
  40346. task.startTime = getStartDate(undefined, df, data[0]);
  40347. task.endTime = getEndDate(task.startTime, df, data[1]);
  40348. break;
  40349. case 3:
  40350. task.id = parseId(data[0]);
  40351. task.startTime = getStartDate(undefined, df, data[1]);
  40352. task.endTime = getEndDate(task.startTime, df, data[2]);
  40353. break;
  40354. default:
  40355. }
  40356. return task;
  40357. };
  40358. var parseData = function parseData(prevTaskId, dataStr) {
  40359. var ds;
  40360. if (dataStr.substr(0, 1) === ':') {
  40361. ds = dataStr.substr(1, dataStr.length);
  40362. } else {
  40363. ds = dataStr;
  40364. }
  40365. var data = ds.split(',');
  40366. var task = {};
  40367. // Get tags like active, done cand crit
  40368. var matchFound = true;
  40369. while (matchFound) {
  40370. matchFound = false;
  40371. if (data[0].match(/^\s*active\s*$/)) {
  40372. task.active = true;
  40373. data.shift(1);
  40374. matchFound = true;
  40375. }
  40376. if (data[0].match(/^\s*done\s*$/)) {
  40377. task.done = true;
  40378. data.shift(1);
  40379. matchFound = true;
  40380. }
  40381. if (data[0].match(/^\s*crit\s*$/)) {
  40382. task.crit = true;
  40383. data.shift(1);
  40384. matchFound = true;
  40385. }
  40386. }
  40387. var i;
  40388. for (i = 0; i < data.length; i++) {
  40389. data[i] = data[i].trim();
  40390. }
  40391. switch (data.length) {
  40392. case 1:
  40393. task.id = parseId();
  40394. task.startTime = { type: 'prevTaskEnd', id: prevTaskId };
  40395. task.endTime = { data: data[0] };
  40396. break;
  40397. case 2:
  40398. task.id = parseId();
  40399. task.startTime = { type: 'getStartDate', startData: data[0] };
  40400. task.endTime = { data: data[1] };
  40401. break;
  40402. case 3:
  40403. task.id = parseId(data[0]);
  40404. task.startTime = { type: 'getStartDate', startData: data[1] };
  40405. task.endTime = { data: data[2] };
  40406. break;
  40407. default:
  40408. }
  40409. return task;
  40410. };
  40411. var lastTask;
  40412. var lastTaskID;
  40413. var rawTasks = [];
  40414. var taskDb = {};
  40415. exports.addTask = function (descr, data) {
  40416. var rawTask = {
  40417. section: currentSection,
  40418. type: currentSection,
  40419. processed: false,
  40420. raw: { data: data },
  40421. task: descr
  40422. };
  40423. var taskInfo = parseData(lastTaskID, data);
  40424. rawTask.raw.startTime = taskInfo.startTime;
  40425. rawTask.raw.endTime = taskInfo.endTime;
  40426. rawTask.id = taskInfo.id;
  40427. rawTask.prevTaskId = lastTaskID;
  40428. rawTask.active = taskInfo.active;
  40429. rawTask.done = taskInfo.done;
  40430. rawTask.crit = taskInfo.crit;
  40431. var pos = rawTasks.push(rawTask);
  40432. lastTaskID = rawTask.id;
  40433. // Store cross ref
  40434. taskDb[rawTask.id] = pos - 1;
  40435. };
  40436. exports.findTaskById = function (id) {
  40437. //var i;
  40438. //for(i=0;i<tasks.length;i++){
  40439. // if(tasks[i].id === id){
  40440. // return tasks[i];
  40441. // }
  40442. //}
  40443. var pos = taskDb[id];
  40444. return rawTasks[pos];
  40445. };
  40446. exports.addTaskOrg = function (descr, data) {
  40447. var newTask = {
  40448. section: currentSection,
  40449. type: currentSection,
  40450. description: descr,
  40451. task: descr
  40452. };
  40453. var taskInfo = compileData(lastTask, data);
  40454. newTask.startTime = taskInfo.startTime;
  40455. newTask.endTime = taskInfo.endTime;
  40456. newTask.id = taskInfo.id;
  40457. newTask.active = taskInfo.active;
  40458. newTask.done = taskInfo.done;
  40459. newTask.crit = taskInfo.crit;
  40460. lastTask = newTask;
  40461. tasks.push(newTask);
  40462. };
  40463. var compileTasks = function compileTasks() {
  40464. var df = exports.getDateFormat();
  40465. var compileTask = function compileTask(pos) {
  40466. var task = rawTasks[pos];
  40467. var startTime = '';
  40468. switch (rawTasks[pos].raw.startTime.type) {
  40469. case 'prevTaskEnd':
  40470. var prevTask = exports.findTaskById(task.prevTaskId);
  40471. task.startTime = prevTask.endTime;
  40472. break;
  40473. case 'getStartDate':
  40474. startTime = getStartDate(undefined, df, rawTasks[pos].raw.startTime.startData);
  40475. if (startTime) {
  40476. rawTasks[pos].startTime = startTime;
  40477. }
  40478. break;
  40479. }
  40480. if (rawTasks[pos].startTime) {
  40481. rawTasks[pos].endTime = getEndDate(rawTasks[pos].startTime, df, rawTasks[pos].raw.endTime.data);
  40482. if (rawTasks[pos].endTime) {
  40483. rawTasks[pos].processed = true;
  40484. }
  40485. }
  40486. return rawTasks[pos].processed;
  40487. };
  40488. var i;
  40489. var allProcessed = true;
  40490. for (i = 0; i < rawTasks.length; i++) {
  40491. compileTask(i);
  40492. allProcessed = allProcessed && rawTasks[i].processed;
  40493. }
  40494. return allProcessed;
  40495. };
  40496. exports.parseError = function (err, hash) {
  40497. global.mermaidAPI.parseError(err, hash);
  40498. };
  40499. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  40500. },{"../../logger":129,"moment":103}],120:[function(require,module,exports){
  40501. 'use strict';
  40502. var gantt = require('./parser/gantt').parser;
  40503. gantt.yy = require('./ganttDb');
  40504. var d3 = require('../../d3');
  40505. var moment = require('moment');
  40506. //var log = require('../../logger').create();
  40507. var daysInChart;
  40508. var conf = {
  40509. titleTopMargin: 25,
  40510. barHeight: 20,
  40511. barGap: 4,
  40512. topPadding: 50,
  40513. rightPadding: 75,
  40514. leftPadding: 75,
  40515. gridLineStartPadding: 35,
  40516. fontSize: 11,
  40517. fontFamily: '"Open-Sans", "sans-serif"'
  40518. };
  40519. module.exports.setConf = function (cnf) {
  40520. var keys = Object.keys(cnf);
  40521. keys.forEach(function (key) {
  40522. conf[key] = cnf[key];
  40523. });
  40524. };
  40525. var w;
  40526. module.exports.draw = function (text, id) {
  40527. gantt.yy.clear();
  40528. gantt.parse(text);
  40529. var elem = document.getElementById(id);
  40530. w = elem.parentElement.offsetWidth;
  40531. if (typeof w === 'undefined') {
  40532. w = 1200;
  40533. }
  40534. if (typeof conf.useWidth !== 'undefined') {
  40535. w = conf.useWidth;
  40536. }
  40537. var taskArray = gantt.yy.getTasks();
  40538. // Set height based on number of tasks
  40539. var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding;
  40540. elem.setAttribute('height', '100%');
  40541. // Set viewBox
  40542. elem.setAttribute('viewBox', '0 0 ' + w + ' ' + h);
  40543. var svg = d3.select('#' + id);
  40544. //var dateFormat = d3.time.format('%Y-%m-%d');
  40545. var startDate = d3.min(taskArray, function (d) {
  40546. return d.startTime;
  40547. });
  40548. var endDate = d3.max(taskArray, function (d) {
  40549. return d.endTime;
  40550. });
  40551. // Set timescale
  40552. var timeScale = d3.time.scale().domain([d3.min(taskArray, function (d) {
  40553. return d.startTime;
  40554. }), d3.max(taskArray, function (d) {
  40555. return d.endTime;
  40556. })]).rangeRound([0, w - conf.leftPadding - conf.rightPadding]);
  40557. //.nice(d3.time.monday);
  40558. var categories = [];
  40559. daysInChart = moment.duration(endDate - startDate).asDays();
  40560. for (var i = 0; i < taskArray.length; i++) {
  40561. categories.push(taskArray[i].type);
  40562. }
  40563. var catsUnfiltered = categories; //for vert labels
  40564. categories = checkUnique(categories);
  40565. makeGant(taskArray, w, h);
  40566. if (typeof conf.useWidth !== 'undefined') {
  40567. elem.setAttribute('width', w);
  40568. }
  40569. svg.append('text').text(gantt.yy.getTitle()).attr('x', w / 2).attr('y', conf.titleTopMargin).attr('class', 'titleText');
  40570. function makeGant(tasks, pageWidth, pageHeight) {
  40571. var barHeight = conf.barHeight;
  40572. var gap = barHeight + conf.barGap;
  40573. var topPadding = conf.topPadding;
  40574. var leftPadding = conf.leftPadding;
  40575. var colorScale = d3.scale.linear().domain([0, categories.length]).range(['#00B9FA', '#F95002']).interpolate(d3.interpolateHcl);
  40576. makeGrid(leftPadding, topPadding, pageWidth, pageHeight);
  40577. drawRects(tasks, gap, topPadding, leftPadding, barHeight, colorScale, pageWidth, pageHeight);
  40578. vertLabels(gap, topPadding, leftPadding, barHeight, colorScale);
  40579. drawToday(leftPadding, topPadding, pageWidth, pageHeight);
  40580. }
  40581. function drawRects(theArray, theGap, theTopPad, theSidePad, theBarHeight, theColorScale, w, h) {
  40582. //eslint-disable-line no-unused-vars
  40583. svg.append('g').selectAll('rect').data(theArray).enter().append('rect').attr('x', 0).attr('y', function (d, i) {
  40584. return i * theGap + theTopPad - 2;
  40585. }).attr('width', function () {
  40586. return w - conf.rightPadding / 2;
  40587. }).attr('height', theGap).attr('class', function (d) {
  40588. //eslint-disable-line no-unused-vars
  40589. for (var i = 0; i < categories.length; i++) {
  40590. if (d.type === categories[i]) {
  40591. return 'section section' + i % conf.numberSectionStyles;
  40592. }
  40593. }
  40594. return 'section section0';
  40595. });
  40596. var rectangles = svg.append('g').selectAll('rect').data(theArray).enter();
  40597. rectangles.append('rect').attr('rx', 3).attr('ry', 3).attr('x', function (d) {
  40598. return timeScale(d.startTime) + theSidePad;
  40599. }).attr('y', function (d, i) {
  40600. return i * theGap + theTopPad;
  40601. }).attr('width', function (d) {
  40602. return timeScale(d.endTime) - timeScale(d.startTime);
  40603. }).attr('height', theBarHeight).attr('class', function (d) {
  40604. var res = 'task ';
  40605. var secNum = 0;
  40606. for (var i = 0; i < categories.length; i++) {
  40607. if (d.type === categories[i]) {
  40608. secNum = i % conf.numberSectionStyles;
  40609. }
  40610. }
  40611. if (d.active) {
  40612. if (d.crit) {
  40613. return res + ' activeCrit' + secNum;
  40614. } else {
  40615. return res + ' active' + secNum;
  40616. }
  40617. }
  40618. if (d.done) {
  40619. if (d.crit) {
  40620. return res + ' doneCrit' + secNum;
  40621. } else {
  40622. return res + ' done' + secNum;
  40623. }
  40624. }
  40625. if (d.crit) {
  40626. return res + ' crit' + secNum;
  40627. }
  40628. return res + ' task' + secNum;
  40629. });
  40630. rectangles.append('text').text(function (d) {
  40631. return d.task;
  40632. }).attr('font-size', conf.fontSize)
  40633. //.attr('font-family',conf.fontFamily)
  40634. .attr('x', function (d) {
  40635. var startX = timeScale(d.startTime),
  40636. endX = timeScale(d.endTime),
  40637. textWidth = this.getBBox().width;
  40638. // Check id text width > width of rectangle
  40639. if (textWidth > endX - startX) {
  40640. if (endX + textWidth + 1.5 * conf.leftPadding > w) {
  40641. return startX + theSidePad - 5;
  40642. } else {
  40643. return endX + theSidePad + 5;
  40644. }
  40645. } else {
  40646. return (endX - startX) / 2 + startX + theSidePad;
  40647. }
  40648. }).attr('y', function (d, i) {
  40649. return i * theGap + conf.barHeight / 2 + (conf.fontSize / 2 - 2) + theTopPad;
  40650. })
  40651. //.attr('text-anchor', 'middle')
  40652. .attr('text-height', theBarHeight).attr('class', function (d) {
  40653. var startX = timeScale(d.startTime),
  40654. endX = timeScale(d.endTime),
  40655. textWidth = this.getBBox().width;
  40656. var secNum = 0;
  40657. for (var i = 0; i < categories.length; i++) {
  40658. if (d.type === categories[i]) {
  40659. secNum = i % conf.numberSectionStyles;
  40660. }
  40661. }
  40662. var taskType = '';
  40663. if (d.active) {
  40664. if (d.crit) {
  40665. taskType = 'activeCritText' + secNum;
  40666. } else {
  40667. taskType = 'activeText' + secNum;
  40668. }
  40669. }
  40670. if (d.done) {
  40671. if (d.crit) {
  40672. taskType = taskType + ' doneCritText' + secNum;
  40673. } else {
  40674. taskType = taskType + ' doneText' + secNum;
  40675. }
  40676. } else {
  40677. if (d.crit) {
  40678. taskType = taskType + ' critText' + secNum;
  40679. }
  40680. }
  40681. // Check id text width > width of rectangle
  40682. if (textWidth > endX - startX) {
  40683. if (endX + textWidth + 1.5 * conf.leftPadding > w) {
  40684. return 'taskTextOutsideLeft taskTextOutside' + secNum + ' ' + taskType;
  40685. } else {
  40686. return 'taskTextOutsideRight taskTextOutside' + secNum + ' ' + taskType;
  40687. }
  40688. } else {
  40689. return 'taskText taskText' + secNum + ' ' + taskType;
  40690. }
  40691. });
  40692. }
  40693. function makeGrid(theSidePad, theTopPad, w, h) {
  40694. var pre = [['.%L', function (d) {
  40695. return d.getMilliseconds();
  40696. }], [':%S', function (d) {
  40697. return d.getSeconds();
  40698. }],
  40699. // Within a hour
  40700. ['h1 %I:%M', function (d) {
  40701. return d.getMinutes();
  40702. }]];
  40703. var post = [['%Y', function () {
  40704. return true;
  40705. }]];
  40706. var mid = [
  40707. // Within a day
  40708. ['%I:%M', function (d) {
  40709. return d.getHours();
  40710. }],
  40711. // Day within a week (not monday)
  40712. ['%a %d', function (d) {
  40713. //return d.getDay() ==1;
  40714. return d.getDay() && d.getDate() != 1;
  40715. }],
  40716. // within a month
  40717. ['%b %d', function (d) {
  40718. return d.getDate() != 1;
  40719. }],
  40720. // Month
  40721. ['%B', function (d) {
  40722. return d.getMonth();
  40723. }]];
  40724. var formatter;
  40725. if (typeof conf.axisFormatter !== 'undefined') {
  40726. mid = [];
  40727. conf.axisFormatter.forEach(function (item) {
  40728. var n = [];
  40729. n[0] = item[0];
  40730. n[1] = item[1];
  40731. mid.push(n);
  40732. });
  40733. }
  40734. formatter = pre.concat(mid).concat(post);
  40735. var xAxis = d3.svg.axis().scale(timeScale).orient('bottom').tickSize(-h + theTopPad + conf.gridLineStartPadding, 0, 0).tickFormat(d3.time.format.multi(formatter));
  40736. if (daysInChart > 7 && daysInChart < 230) {
  40737. xAxis = xAxis.ticks(d3.time.monday.range);
  40738. }
  40739. svg.append('g').attr('class', 'grid').attr('transform', 'translate(' + theSidePad + ', ' + (h - 50) + ')').call(xAxis).selectAll('text').style('text-anchor', 'middle').attr('fill', '#000').attr('stroke', 'none').attr('font-size', 10).attr('dy', '1em');
  40740. }
  40741. function vertLabels(theGap, theTopPad) {
  40742. var numOccurances = [];
  40743. var prevGap = 0;
  40744. for (var i = 0; i < categories.length; i++) {
  40745. numOccurances[i] = [categories[i], getCount(categories[i], catsUnfiltered)];
  40746. }
  40747. svg.append('g') //without doing this, impossible to put grid lines behind text
  40748. .selectAll('text').data(numOccurances).enter().append('text').text(function (d) {
  40749. return d[0];
  40750. }).attr('x', 10).attr('y', function (d, i) {
  40751. if (i > 0) {
  40752. for (var j = 0; j < i; j++) {
  40753. prevGap += numOccurances[i - 1][1];
  40754. // log.debug(prevGap);
  40755. return d[1] * theGap / 2 + prevGap * theGap + theTopPad;
  40756. }
  40757. } else {
  40758. return d[1] * theGap / 2 + theTopPad;
  40759. }
  40760. }).attr('class', function (d) {
  40761. for (var i = 0; i < categories.length; i++) {
  40762. if (d[0] === categories[i]) {
  40763. return 'sectionTitle sectionTitle' + i % conf.numberSectionStyles;
  40764. }
  40765. }
  40766. return 'sectionTitle';
  40767. });
  40768. }
  40769. function drawToday(theSidePad, theTopPad, w, h) {
  40770. var todayG = svg.append('g').attr('class', 'today');
  40771. var today = new Date();
  40772. todayG.append('line').attr('x1', timeScale(today) + theSidePad).attr('x2', timeScale(today) + theSidePad).attr('y1', conf.titleTopMargin).attr('y2', h - conf.titleTopMargin).attr('class', 'today');
  40773. }
  40774. //from this stackexchange question: http://stackoverflow.com/questions/1890203/unique-for-arrays-in-javascript
  40775. function checkUnique(arr) {
  40776. var hash = {},
  40777. result = [];
  40778. for (var i = 0, l = arr.length; i < l; ++i) {
  40779. if (!hash.hasOwnProperty(arr[i])) {
  40780. //it works with objects! in FF, at least
  40781. hash[arr[i]] = true;
  40782. result.push(arr[i]);
  40783. }
  40784. }
  40785. return result;
  40786. }
  40787. //from this stackexchange question: http://stackoverflow.com/questions/14227981/count-how-many-strings-in-an-array-have-duplicates-in-the-same-array
  40788. function getCounts(arr) {
  40789. var i = arr.length,
  40790. // var to loop over
  40791. obj = {}; // obj to store results
  40792. while (i) {
  40793. obj[arr[--i]] = (obj[arr[i]] || 0) + 1; // count occurrences
  40794. }
  40795. return obj;
  40796. }
  40797. // get specific from everything
  40798. function getCount(word, arr) {
  40799. return getCounts(arr)[word] || 0;
  40800. }
  40801. };
  40802. },{"../../d3":107,"./ganttDb":119,"./parser/gantt":121,"moment":103}],121:[function(require,module,exports){
  40803. (function (process){
  40804. /* parser generated by jison 0.4.17 */
  40805. /*
  40806. Returns a Parser object of the following structure:
  40807. Parser: {
  40808. yy: {}
  40809. }
  40810. Parser.prototype: {
  40811. yy: {},
  40812. trace: function(),
  40813. symbols_: {associative list: name ==> number},
  40814. terminals_: {associative list: number ==> name},
  40815. productions_: [...],
  40816. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  40817. table: [...],
  40818. defaultActions: {...},
  40819. parseError: function(str, hash),
  40820. parse: function(input),
  40821. lexer: {
  40822. EOF: 1,
  40823. parseError: function(str, hash),
  40824. setInput: function(input),
  40825. input: function(),
  40826. unput: function(str),
  40827. more: function(),
  40828. less: function(n),
  40829. pastInput: function(),
  40830. upcomingInput: function(),
  40831. showPosition: function(),
  40832. test_match: function(regex_match_array, rule_index),
  40833. next: function(),
  40834. lex: function(),
  40835. begin: function(condition),
  40836. popState: function(),
  40837. _currentRules: function(),
  40838. topState: function(),
  40839. pushState: function(condition),
  40840. options: {
  40841. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  40842. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  40843. backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code)
  40844. },
  40845. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  40846. rules: [...],
  40847. conditions: {associative list: name ==> set},
  40848. }
  40849. }
  40850. token location info (@$, _$, etc.): {
  40851. first_line: n,
  40852. last_line: n,
  40853. first_column: n,
  40854. last_column: n,
  40855. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  40856. }
  40857. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  40858. text: (matched text)
  40859. token: (the produced terminal token, if any)
  40860. line: (yylineno)
  40861. }
  40862. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  40863. loc: (yylloc)
  40864. expected: (string describing the set of expected tokens)
  40865. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  40866. }
  40867. */
  40868. "use strict";
  40869. var parser = (function () {
  40870. var o = function o(k, v, _o, l) {
  40871. for (_o = _o || {}, l = k.length; l--; _o[k[l]] = v);return _o;
  40872. },
  40873. $V0 = [6, 8, 10, 11, 12, 13, 14],
  40874. $V1 = [1, 9],
  40875. $V2 = [1, 10],
  40876. $V3 = [1, 11],
  40877. $V4 = [1, 12];
  40878. var parser = { trace: function trace() {},
  40879. yy: {},
  40880. symbols_: { "error": 2, "start": 3, "gantt": 4, "document": 5, "EOF": 6, "line": 7, "SPACE": 8, "statement": 9, "NL": 10, "dateFormat": 11, "title": 12, "section": 13, "taskTxt": 14, "taskData": 15, "$accept": 0, "$end": 1 },
  40881. terminals_: { 2: "error", 4: "gantt", 6: "EOF", 8: "SPACE", 10: "NL", 11: "dateFormat", 12: "title", 13: "section", 14: "taskTxt", 15: "taskData" },
  40882. productions_: [0, [3, 3], [5, 0], [5, 2], [7, 2], [7, 1], [7, 1], [7, 1], [9, 1], [9, 1], [9, 1], [9, 2]],
  40883. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, /* action[1] */$$, /* vstack */_$ /* lstack */) {
  40884. /* this == yyval */
  40885. var $0 = $$.length - 1;
  40886. switch (yystate) {
  40887. case 1:
  40888. return $$[$0 - 1];
  40889. break;
  40890. case 2:
  40891. this.$ = [];
  40892. break;
  40893. case 3:
  40894. $$[$0 - 1].push($$[$0]);this.$ = $$[$0 - 1];
  40895. break;
  40896. case 4:case 5:
  40897. this.$ = $$[$0];
  40898. break;
  40899. case 6:case 7:
  40900. this.$ = [];
  40901. break;
  40902. case 8:
  40903. yy.setDateFormat($$[$0].substr(11));this.$ = $$[$0].substr(11);
  40904. break;
  40905. case 9:
  40906. yy.setTitle($$[$0].substr(6));this.$ = $$[$0].substr(6);
  40907. break;
  40908. case 10:
  40909. yy.addSection($$[$0].substr(8));this.$ = $$[$0].substr(8);
  40910. break;
  40911. case 11:
  40912. yy.addTask($$[$0 - 1], $$[$0]);this.$ = 'task';
  40913. break;
  40914. }
  40915. },
  40916. table: [{ 3: 1, 4: [1, 2] }, { 1: [3] }, o($V0, [2, 2], { 5: 3 }), { 6: [1, 4], 7: 5, 8: [1, 6], 9: 7, 10: [1, 8], 11: $V1, 12: $V2, 13: $V3, 14: $V4 }, o($V0, [2, 7], { 1: [2, 1] }), o($V0, [2, 3]), { 9: 13, 11: $V1, 12: $V2, 13: $V3, 14: $V4 }, o($V0, [2, 5]), o($V0, [2, 6]), o($V0, [2, 8]), o($V0, [2, 9]), o($V0, [2, 10]), { 15: [1, 14] }, o($V0, [2, 4]), o($V0, [2, 11])],
  40917. defaultActions: {},
  40918. parseError: function parseError(str, hash) {
  40919. if (hash.recoverable) {
  40920. this.trace(str);
  40921. } else {
  40922. var _parseError = function _parseError(msg, hash) {
  40923. this.message = msg;
  40924. this.hash = hash;
  40925. };
  40926. _parseError.prototype = Error;
  40927. throw new _parseError(str, hash);
  40928. }
  40929. },
  40930. parse: function parse(input) {
  40931. var self = this,
  40932. stack = [0],
  40933. tstack = [],
  40934. vstack = [null],
  40935. lstack = [],
  40936. table = this.table,
  40937. yytext = '',
  40938. yylineno = 0,
  40939. yyleng = 0,
  40940. recovering = 0,
  40941. TERROR = 2,
  40942. EOF = 1;
  40943. var args = lstack.slice.call(arguments, 1);
  40944. var lexer = Object.create(this.lexer);
  40945. var sharedState = { yy: {} };
  40946. for (var k in this.yy) {
  40947. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  40948. sharedState.yy[k] = this.yy[k];
  40949. }
  40950. }
  40951. lexer.setInput(input, sharedState.yy);
  40952. sharedState.yy.lexer = lexer;
  40953. sharedState.yy.parser = this;
  40954. if (typeof lexer.yylloc == 'undefined') {
  40955. lexer.yylloc = {};
  40956. }
  40957. var yyloc = lexer.yylloc;
  40958. lstack.push(yyloc);
  40959. var ranges = lexer.options && lexer.options.ranges;
  40960. if (typeof sharedState.yy.parseError === 'function') {
  40961. this.parseError = sharedState.yy.parseError;
  40962. } else {
  40963. this.parseError = Object.getPrototypeOf(this).parseError;
  40964. }
  40965. function popStack(n) {
  40966. stack.length = stack.length - 2 * n;
  40967. vstack.length = vstack.length - n;
  40968. lstack.length = lstack.length - n;
  40969. }
  40970. _token_stack: var lex = function lex() {
  40971. var token;
  40972. token = lexer.lex() || EOF;
  40973. if (typeof token !== 'number') {
  40974. token = self.symbols_[token] || token;
  40975. }
  40976. return token;
  40977. };
  40978. var symbol,
  40979. preErrorSymbol,
  40980. state,
  40981. action,
  40982. a,
  40983. r,
  40984. yyval = {},
  40985. p,
  40986. len,
  40987. newState,
  40988. expected;
  40989. while (true) {
  40990. state = stack[stack.length - 1];
  40991. if (this.defaultActions[state]) {
  40992. action = this.defaultActions[state];
  40993. } else {
  40994. if (symbol === null || typeof symbol == 'undefined') {
  40995. symbol = lex();
  40996. }
  40997. action = table[state] && table[state][symbol];
  40998. }
  40999. if (typeof action === 'undefined' || !action.length || !action[0]) {
  41000. var errStr = '';
  41001. expected = [];
  41002. for (p in table[state]) {
  41003. if (this.terminals_[p] && p > TERROR) {
  41004. expected.push('\'' + this.terminals_[p] + '\'');
  41005. }
  41006. }
  41007. if (lexer.showPosition) {
  41008. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  41009. } else {
  41010. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  41011. }
  41012. this.parseError(errStr, {
  41013. text: lexer.match,
  41014. token: this.terminals_[symbol] || symbol,
  41015. line: lexer.yylineno,
  41016. loc: yyloc,
  41017. expected: expected
  41018. });
  41019. }
  41020. if (action[0] instanceof Array && action.length > 1) {
  41021. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  41022. }
  41023. switch (action[0]) {
  41024. case 1:
  41025. stack.push(symbol);
  41026. vstack.push(lexer.yytext);
  41027. lstack.push(lexer.yylloc);
  41028. stack.push(action[1]);
  41029. symbol = null;
  41030. if (!preErrorSymbol) {
  41031. yyleng = lexer.yyleng;
  41032. yytext = lexer.yytext;
  41033. yylineno = lexer.yylineno;
  41034. yyloc = lexer.yylloc;
  41035. if (recovering > 0) {
  41036. recovering--;
  41037. }
  41038. } else {
  41039. symbol = preErrorSymbol;
  41040. preErrorSymbol = null;
  41041. }
  41042. break;
  41043. case 2:
  41044. len = this.productions_[action[1]][1];
  41045. yyval.$ = vstack[vstack.length - len];
  41046. yyval._$ = {
  41047. first_line: lstack[lstack.length - (len || 1)].first_line,
  41048. last_line: lstack[lstack.length - 1].last_line,
  41049. first_column: lstack[lstack.length - (len || 1)].first_column,
  41050. last_column: lstack[lstack.length - 1].last_column
  41051. };
  41052. if (ranges) {
  41053. yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
  41054. }
  41055. r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
  41056. if (typeof r !== 'undefined') {
  41057. return r;
  41058. }
  41059. if (len) {
  41060. stack = stack.slice(0, -1 * len * 2);
  41061. vstack = vstack.slice(0, -1 * len);
  41062. lstack = lstack.slice(0, -1 * len);
  41063. }
  41064. stack.push(this.productions_[action[1]][0]);
  41065. vstack.push(yyval.$);
  41066. lstack.push(yyval._$);
  41067. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  41068. stack.push(newState);
  41069. break;
  41070. case 3:
  41071. return true;
  41072. }
  41073. }
  41074. return true;
  41075. } };
  41076. /* generated by jison-lex 0.3.4 */
  41077. var lexer = (function () {
  41078. var lexer = {
  41079. EOF: 1,
  41080. parseError: function parseError(str, hash) {
  41081. if (this.yy.parser) {
  41082. this.yy.parser.parseError(str, hash);
  41083. } else {
  41084. throw new Error(str);
  41085. }
  41086. },
  41087. // resets the lexer, sets new input
  41088. setInput: function setInput(input, yy) {
  41089. this.yy = yy || this.yy || {};
  41090. this._input = input;
  41091. this._more = this._backtrack = this.done = false;
  41092. this.yylineno = this.yyleng = 0;
  41093. this.yytext = this.matched = this.match = '';
  41094. this.conditionStack = ['INITIAL'];
  41095. this.yylloc = {
  41096. first_line: 1,
  41097. first_column: 0,
  41098. last_line: 1,
  41099. last_column: 0
  41100. };
  41101. if (this.options.ranges) {
  41102. this.yylloc.range = [0, 0];
  41103. }
  41104. this.offset = 0;
  41105. return this;
  41106. },
  41107. // consumes and returns one char from the input
  41108. input: function input() {
  41109. var ch = this._input[0];
  41110. this.yytext += ch;
  41111. this.yyleng++;
  41112. this.offset++;
  41113. this.match += ch;
  41114. this.matched += ch;
  41115. var lines = ch.match(/(?:\r\n?|\n).*/g);
  41116. if (lines) {
  41117. this.yylineno++;
  41118. this.yylloc.last_line++;
  41119. } else {
  41120. this.yylloc.last_column++;
  41121. }
  41122. if (this.options.ranges) {
  41123. this.yylloc.range[1]++;
  41124. }
  41125. this._input = this._input.slice(1);
  41126. return ch;
  41127. },
  41128. // unshifts one char (or a string) into the input
  41129. unput: function unput(ch) {
  41130. var len = ch.length;
  41131. var lines = ch.split(/(?:\r\n?|\n)/g);
  41132. this._input = ch + this._input;
  41133. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  41134. //this.yyleng -= len;
  41135. this.offset -= len;
  41136. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  41137. this.match = this.match.substr(0, this.match.length - 1);
  41138. this.matched = this.matched.substr(0, this.matched.length - 1);
  41139. if (lines.length - 1) {
  41140. this.yylineno -= lines.length - 1;
  41141. }
  41142. var r = this.yylloc.range;
  41143. this.yylloc = {
  41144. first_line: this.yylloc.first_line,
  41145. last_line: this.yylineno + 1,
  41146. first_column: this.yylloc.first_column,
  41147. last_column: lines ? (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length : this.yylloc.first_column - len
  41148. };
  41149. if (this.options.ranges) {
  41150. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  41151. }
  41152. this.yyleng = this.yytext.length;
  41153. return this;
  41154. },
  41155. // When called from action, caches matched text and appends it on next action
  41156. more: function more() {
  41157. this._more = true;
  41158. return this;
  41159. },
  41160. // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
  41161. reject: function reject() {
  41162. if (this.options.backtrack_lexer) {
  41163. this._backtrack = true;
  41164. } else {
  41165. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), {
  41166. text: "",
  41167. token: null,
  41168. line: this.yylineno
  41169. });
  41170. }
  41171. return this;
  41172. },
  41173. // retain first n characters of the match
  41174. less: function less(n) {
  41175. this.unput(this.match.slice(n));
  41176. },
  41177. // displays already matched input, i.e. for error messages
  41178. pastInput: function pastInput() {
  41179. var past = this.matched.substr(0, this.matched.length - this.match.length);
  41180. return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
  41181. },
  41182. // displays upcoming input, i.e. for error messages
  41183. upcomingInput: function upcomingInput() {
  41184. var next = this.match;
  41185. if (next.length < 20) {
  41186. next += this._input.substr(0, 20 - next.length);
  41187. }
  41188. return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  41189. },
  41190. // displays the character position where the lexing error occurred, i.e. for error messages
  41191. showPosition: function showPosition() {
  41192. var pre = this.pastInput();
  41193. var c = new Array(pre.length + 1).join("-");
  41194. return pre + this.upcomingInput() + "\n" + c + "^";
  41195. },
  41196. // test the lexed token: return FALSE when not a match, otherwise return token
  41197. test_match: function test_match(match, indexed_rule) {
  41198. var token, lines, backup;
  41199. if (this.options.backtrack_lexer) {
  41200. // save context
  41201. backup = {
  41202. yylineno: this.yylineno,
  41203. yylloc: {
  41204. first_line: this.yylloc.first_line,
  41205. last_line: this.last_line,
  41206. first_column: this.yylloc.first_column,
  41207. last_column: this.yylloc.last_column
  41208. },
  41209. yytext: this.yytext,
  41210. match: this.match,
  41211. matches: this.matches,
  41212. matched: this.matched,
  41213. yyleng: this.yyleng,
  41214. offset: this.offset,
  41215. _more: this._more,
  41216. _input: this._input,
  41217. yy: this.yy,
  41218. conditionStack: this.conditionStack.slice(0),
  41219. done: this.done
  41220. };
  41221. if (this.options.ranges) {
  41222. backup.yylloc.range = this.yylloc.range.slice(0);
  41223. }
  41224. }
  41225. lines = match[0].match(/(?:\r\n?|\n).*/g);
  41226. if (lines) {
  41227. this.yylineno += lines.length;
  41228. }
  41229. this.yylloc = {
  41230. first_line: this.yylloc.last_line,
  41231. last_line: this.yylineno + 1,
  41232. first_column: this.yylloc.last_column,
  41233. last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
  41234. };
  41235. this.yytext += match[0];
  41236. this.match += match[0];
  41237. this.matches = match;
  41238. this.yyleng = this.yytext.length;
  41239. if (this.options.ranges) {
  41240. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  41241. }
  41242. this._more = false;
  41243. this._backtrack = false;
  41244. this._input = this._input.slice(match[0].length);
  41245. this.matched += match[0];
  41246. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  41247. if (this.done && this._input) {
  41248. this.done = false;
  41249. }
  41250. if (token) {
  41251. return token;
  41252. } else if (this._backtrack) {
  41253. // recover context
  41254. for (var k in backup) {
  41255. this[k] = backup[k];
  41256. }
  41257. return false; // rule action called reject() implying the next rule should be tested instead.
  41258. }
  41259. return false;
  41260. },
  41261. // return next match in input
  41262. next: function next() {
  41263. if (this.done) {
  41264. return this.EOF;
  41265. }
  41266. if (!this._input) {
  41267. this.done = true;
  41268. }
  41269. var token, match, tempMatch, index;
  41270. if (!this._more) {
  41271. this.yytext = '';
  41272. this.match = '';
  41273. }
  41274. var rules = this._currentRules();
  41275. for (var i = 0; i < rules.length; i++) {
  41276. tempMatch = this._input.match(this.rules[rules[i]]);
  41277. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  41278. match = tempMatch;
  41279. index = i;
  41280. if (this.options.backtrack_lexer) {
  41281. token = this.test_match(tempMatch, rules[i]);
  41282. if (token !== false) {
  41283. return token;
  41284. } else if (this._backtrack) {
  41285. match = false;
  41286. continue; // rule action called reject() implying a rule MISmatch.
  41287. } else {
  41288. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  41289. return false;
  41290. }
  41291. } else if (!this.options.flex) {
  41292. break;
  41293. }
  41294. }
  41295. }
  41296. if (match) {
  41297. token = this.test_match(match, rules[index]);
  41298. if (token !== false) {
  41299. return token;
  41300. }
  41301. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  41302. return false;
  41303. }
  41304. if (this._input === "") {
  41305. return this.EOF;
  41306. } else {
  41307. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  41308. text: "",
  41309. token: null,
  41310. line: this.yylineno
  41311. });
  41312. }
  41313. },
  41314. // return next match that has a token
  41315. lex: function lex() {
  41316. var r = this.next();
  41317. if (r) {
  41318. return r;
  41319. } else {
  41320. return this.lex();
  41321. }
  41322. },
  41323. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  41324. begin: function begin(condition) {
  41325. this.conditionStack.push(condition);
  41326. },
  41327. // pop the previously active lexer condition state off the condition stack
  41328. popState: function popState() {
  41329. var n = this.conditionStack.length - 1;
  41330. if (n > 0) {
  41331. return this.conditionStack.pop();
  41332. } else {
  41333. return this.conditionStack[0];
  41334. }
  41335. },
  41336. // produce the lexer rule set which is active for the currently active lexer condition state
  41337. _currentRules: function _currentRules() {
  41338. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  41339. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  41340. } else {
  41341. return this.conditions["INITIAL"].rules;
  41342. }
  41343. },
  41344. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  41345. topState: function topState(n) {
  41346. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  41347. if (n >= 0) {
  41348. return this.conditionStack[n];
  41349. } else {
  41350. return "INITIAL";
  41351. }
  41352. },
  41353. // alias for begin(condition)
  41354. pushState: function pushState(condition) {
  41355. this.begin(condition);
  41356. },
  41357. // return the number of states currently on the stack
  41358. stateStackSize: function stateStackSize() {
  41359. return this.conditionStack.length;
  41360. },
  41361. options: { "case-insensitive": true },
  41362. performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
  41363. // Pre-lexer code can go here
  41364. var YYSTATE = YY_START;
  41365. switch ($avoiding_name_collisions) {
  41366. case 0:
  41367. return 10;
  41368. break;
  41369. case 1:
  41370. /* skip whitespace */
  41371. break;
  41372. case 2:
  41373. /* skip comments */
  41374. break;
  41375. case 3:
  41376. /* skip comments */
  41377. break;
  41378. case 4:
  41379. return 4;
  41380. break;
  41381. case 5:
  41382. return 11;
  41383. break;
  41384. case 6:
  41385. return 'date';
  41386. break;
  41387. case 7:
  41388. return 12;
  41389. break;
  41390. case 8:
  41391. return 13;
  41392. break;
  41393. case 9:
  41394. return 14;
  41395. break;
  41396. case 10:
  41397. return 15;
  41398. break;
  41399. case 11:
  41400. return ':';
  41401. break;
  41402. case 12:
  41403. return 6;
  41404. break;
  41405. case 13:
  41406. return 'INVALID';
  41407. break;
  41408. }
  41409. },
  41410. rules: [/^(?:[\n]+)/i, /^(?:\s+)/i, /^(?:#[^\n]*)/i, /^(?:%[^\n]*)/i, /^(?:gantt\b)/i, /^(?:dateFormat\s[^#\n;]+)/i, /^(?:\d\d\d\d-\d\d-\d\d\b)/i, /^(?:title\s[^#\n;]+)/i, /^(?:section\s[^#:\n;]+)/i, /^(?:[^#:\n;]+)/i, /^(?::[^#\n;]+)/i, /^(?::)/i, /^(?:$)/i, /^(?:.)/i],
  41411. conditions: { "INITIAL": { "rules": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], "inclusive": true } }
  41412. };
  41413. return lexer;
  41414. })();
  41415. parser.lexer = lexer;
  41416. function Parser() {
  41417. this.yy = {};
  41418. }
  41419. Parser.prototype = parser;parser.Parser = Parser;
  41420. return new Parser();
  41421. })();
  41422. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  41423. exports.parser = parser;
  41424. exports.Parser = parser.Parser;
  41425. exports.parse = function () {
  41426. return parser.parse.apply(parser, arguments);
  41427. };
  41428. exports.main = function commonjsMain(args) {
  41429. if (!args[1]) {
  41430. console.log('Usage: ' + args[0] + ' FILE');
  41431. process.exit(1);
  41432. }
  41433. var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
  41434. return exports.parser.parse(source);
  41435. };
  41436. if (typeof module !== 'undefined' && require.main === module) {
  41437. exports.main(process.argv.slice(1));
  41438. }
  41439. }
  41440. }).call(this,require('_process'))
  41441. },{"_process":105,"fs":1,"path":104}],122:[function(require,module,exports){
  41442. 'use strict';
  41443. var Logger = require('../../logger');
  41444. var _ = require('lodash');
  41445. //var log = new Logger.Log();
  41446. var log = new Logger.Log(1);
  41447. var commits = {};
  41448. var head = null;
  41449. var branches = { 'master': head };
  41450. var curBranch = 'master';
  41451. var direction = 'LR';
  41452. var seq = 0;
  41453. function getRandomInt(min, max) {
  41454. return Math.floor(Math.random() * (max - min)) + min;
  41455. }
  41456. function getId() {
  41457. var pool = '0123456789abcdef';
  41458. var id = '';
  41459. for (var i = 0; i < 7; i++) {
  41460. id += pool[getRandomInt(0, 16)];
  41461. }
  41462. return id;
  41463. }
  41464. function isfastforwardable(_x, _x2) {
  41465. var _left;
  41466. var _again = true;
  41467. _function: while (_again) {
  41468. var currentCommit = _x,
  41469. otherCommit = _x2;
  41470. _again = false;
  41471. log.debug('Entering isfastforwardable:', currentCommit.id, otherCommit.id);
  41472. while (currentCommit.seq <= otherCommit.seq && currentCommit != otherCommit) {
  41473. // only if other branch has more commits
  41474. if (otherCommit.parent == null) break;
  41475. if (Array.isArray(otherCommit.parent)) {
  41476. log.debug('In merge commit:', otherCommit.parent);
  41477. if (_left = isfastforwardable(currentCommit, commits[otherCommit.parent[0]])) {
  41478. return _left;
  41479. }
  41480. _x = currentCommit;
  41481. _x2 = commits[otherCommit.parent[1]];
  41482. _again = true;
  41483. continue _function;
  41484. } else {
  41485. otherCommit = commits[otherCommit.parent];
  41486. }
  41487. }
  41488. log.debug(currentCommit.id, otherCommit.id);
  41489. return currentCommit.id == otherCommit.id;
  41490. }
  41491. }
  41492. function isReachableFrom(currentCommit, otherCommit) {
  41493. var currentSeq = currentCommit.seq;
  41494. var otherSeq = otherCommit.seq;
  41495. if (currentSeq > otherSeq) return isfastforwardable(otherCommit, currentCommit);
  41496. return false;
  41497. }
  41498. exports.setDirection = function (dir) {
  41499. direction = dir;
  41500. };
  41501. var options = {};
  41502. exports.setOptions = function (rawOptString) {
  41503. log.debug('options str', rawOptString);
  41504. rawOptString = rawOptString && rawOptString.trim();
  41505. rawOptString = rawOptString || '{}';
  41506. try {
  41507. options = JSON.parse(rawOptString);
  41508. } catch (e) {
  41509. log.error('error while parsing gitGraph options', e.message);
  41510. }
  41511. };
  41512. exports.getOptions = function () {
  41513. return options;
  41514. };
  41515. exports.commit = function (msg) {
  41516. var commit = { id: getId(),
  41517. message: msg,
  41518. seq: seq++,
  41519. parent: head == null ? null : head.id };
  41520. head = commit;
  41521. commits[commit.id] = commit;
  41522. branches[curBranch] = commit.id;
  41523. log.debug('in pushCommit ' + commit.id);
  41524. };
  41525. exports.branch = function (name) {
  41526. branches[name] = head != null ? head.id : null;
  41527. log.debug('in createBranch');
  41528. };
  41529. exports.merge = function (otherBranch) {
  41530. var currentCommit = commits[branches[curBranch]];
  41531. var otherCommit = commits[branches[otherBranch]];
  41532. if (isReachableFrom(currentCommit, otherCommit)) {
  41533. log.debug('Already merged');
  41534. return;
  41535. }
  41536. if (isfastforwardable(currentCommit, otherCommit)) {
  41537. branches[curBranch] = branches[otherBranch];
  41538. head = commits[branches[curBranch]];
  41539. } else {
  41540. // create merge commit
  41541. var commit = {
  41542. id: getId(),
  41543. message: 'merged branch ' + otherBranch + ' into ' + curBranch,
  41544. seq: seq++,
  41545. parent: [head == null ? null : head.id, branches[otherBranch]]
  41546. };
  41547. head = commit;
  41548. commits[commit.id] = commit;
  41549. branches[curBranch] = commit.id;
  41550. }
  41551. log.debug(branches);
  41552. log.debug('in mergeBranch');
  41553. };
  41554. exports.checkout = function (branch) {
  41555. log.debug('in checkout');
  41556. curBranch = branch;
  41557. var id = branches[curBranch];
  41558. head = commits[id];
  41559. };
  41560. exports.reset = function (commitRef) {
  41561. log.debug('in reset', commitRef);
  41562. var ref = commitRef.split(':')[0];
  41563. var parentCount = parseInt(commitRef.split(':')[1]);
  41564. var commit = ref == 'HEAD' ? head : commits[branches[ref]];
  41565. log.debug(commit, parentCount);
  41566. while (parentCount > 0) {
  41567. commit = commits[commit.parent];
  41568. parentCount--;
  41569. if (!commit) {
  41570. var err = 'Critical error - unique parent commit not found during reset';
  41571. log.error(err);
  41572. throw err;
  41573. }
  41574. }
  41575. head = commit;
  41576. branches[curBranch] = commit.id;
  41577. };
  41578. function upsert(arr, key, newval) {
  41579. var match = _.find(arr, key);
  41580. if (match) {
  41581. var index = _.indexOf(arr, _.find(arr, key));
  41582. arr.splice(index, 1, newval);
  41583. } else {
  41584. arr.push(newval);
  41585. }
  41586. //console.log(arr);
  41587. }
  41588. function prettyPrintCommitHistory(commitArr) {
  41589. var commit = _.maxBy(commitArr, 'seq');
  41590. var line = '';
  41591. _.each(commitArr, function (c) {
  41592. if (c == commit) {
  41593. line += '\t*';
  41594. } else {
  41595. line += '\t|';
  41596. }
  41597. });
  41598. var label = [line, commit.id, commit.seq];
  41599. _.each(branches, function (v, k) {
  41600. if (v == commit.id) label.push(k);
  41601. });
  41602. log.debug(label.join(' '));
  41603. if (Array.isArray(commit.parent)) {
  41604. //console.log("here", commit.parent);
  41605. var newCommit = commits[commit.parent[0]];
  41606. upsert(commitArr, commit, newCommit);
  41607. commitArr.push(commits[commit.parent[1]]);
  41608. //console.log("shoudl have 2", commitArr);
  41609. } else if (commit.parent == null) {
  41610. return;
  41611. } else {
  41612. var nextCommit = commits[commit.parent];
  41613. upsert(commitArr, commit, nextCommit);
  41614. }
  41615. commitArr = _.uniqBy(commitArr, 'id');
  41616. prettyPrintCommitHistory(commitArr);
  41617. }
  41618. exports.prettyPrint = function () {
  41619. log.debug(commits);
  41620. var node = exports.getCommitsArray()[0];
  41621. prettyPrintCommitHistory([node]);
  41622. };
  41623. exports.clear = function () {
  41624. commits = {};
  41625. head = null;
  41626. branches = { 'master': head };
  41627. curBranch = 'master';
  41628. seq = 0;
  41629. };
  41630. exports.getBranchesAsObjArray = function () {
  41631. var branchArr = _.map(branches, function (v, k) {
  41632. return { 'name': k, 'commit': commits[v] };
  41633. });
  41634. //return _.orderBy(branchArr, [function(b) { return b.commit.seq}], ['desc']);
  41635. return branchArr;
  41636. };
  41637. exports.getBranches = function () {
  41638. return branches;
  41639. };
  41640. exports.getCommits = function () {
  41641. return commits;
  41642. };
  41643. exports.getCommitsArray = function () {
  41644. var commitArr = Object.keys(commits).map(function (key) {
  41645. return commits[key];
  41646. });
  41647. _.each(commitArr, function (o) {
  41648. log.debug(o.id);
  41649. });
  41650. return _.orderBy(commitArr, ['seq'], ['desc']);
  41651. };
  41652. exports.getCurrentBranch = function () {
  41653. return curBranch;
  41654. };
  41655. exports.getDirection = function () {
  41656. return direction;
  41657. };
  41658. exports.getHead = function () {
  41659. return head;
  41660. };
  41661. },{"../../logger":129,"lodash":102}],123:[function(require,module,exports){
  41662. 'use strict';
  41663. var db = require('./gitGraphAst');
  41664. var _ = require('lodash');
  41665. var gitGraphParser = require('./parser/gitGraph');
  41666. var d3 = require('../../d3');
  41667. var Logger = require('../../logger');
  41668. var log = new Logger.Log();
  41669. var allCommitsDict = {};
  41670. var branchNum;
  41671. var config = {
  41672. nodeSpacing: 75,
  41673. nodeFillColor: 'yellow',
  41674. nodeStrokeWidth: 2,
  41675. nodeStrokeColor: 'grey',
  41676. lineStrokeWidth: 4,
  41677. branchOffset: 50,
  41678. lineColor: 'grey',
  41679. leftMargin: 50,
  41680. branchColors: ['#442f74', '#983351', '#609732', '#AA9A39'],
  41681. nodeRadius: 15,
  41682. nodeLabel: {
  41683. width: 75,
  41684. height: 100,
  41685. x: -25,
  41686. y: 15
  41687. }
  41688. };
  41689. var apiConfig = {};
  41690. exports.setConf = function (c) {
  41691. apiConfig = c;
  41692. };
  41693. function svgCreateDefs(svg) {
  41694. svg.append('defs').append('g').attr('id', 'def-commit').append('circle').attr('r', config.nodeRadius).attr('cx', 0).attr('cy', 0);
  41695. svg.select('#def-commit').append('foreignObject').attr('width', config.nodeLabel.width).attr('height', config.nodeLabel.height).attr('x', config.nodeLabel.x).attr('y', config.nodeLabel.y).attr('class', 'node-label').attr('requiredFeatures', 'http://www.w3.org/TR/SVG11/feature#Extensibility').append('xhtml:p').html('');
  41696. }
  41697. function svgDrawLine(svg, points, colorIdx, interpolate) {
  41698. interpolate = interpolate || 'basis';
  41699. var color = config.branchColors[colorIdx % config.branchColors.length];
  41700. var lineGen = d3.svg.line().x(function (d) {
  41701. return Math.round(d.x);
  41702. }).y(function (d) {
  41703. return Math.round(d.y);
  41704. }).interpolate(interpolate);
  41705. svg.append('svg:path').attr('d', lineGen(points)).style('stroke', color).style('stroke-width', config.lineStrokeWidth).style('fill', 'none');
  41706. }
  41707. // Pass in the element and its pre-transform coords
  41708. function getElementCoords(element, coords) {
  41709. coords = coords || element.node().getBBox();
  41710. var ctm = element.node().getCTM(),
  41711. xn = ctm.e + coords.x * ctm.a,
  41712. yn = ctm.f + coords.y * ctm.d;
  41713. //log.debug(ctm, coords);
  41714. return {
  41715. left: xn,
  41716. top: yn,
  41717. width: coords.width,
  41718. height: coords.height
  41719. };
  41720. }
  41721. function svgDrawLineForCommits(svg, fromId, toId, direction, color) {
  41722. log.debug('svgDrawLineForCommits: ', fromId, toId);
  41723. var fromBbox = getElementCoords(svg.select('#node-' + fromId + ' circle'));
  41724. var toBbox = getElementCoords(svg.select('#node-' + toId + ' circle'));
  41725. //log.debug('svgDrawLineForCommits: ', fromBbox, toBbox);
  41726. switch (direction) {
  41727. case 'LR':
  41728. // (toBbox)
  41729. // +--------
  41730. // + (fromBbox)
  41731. if (fromBbox.left - toBbox.left > config.nodeSpacing) {
  41732. var lineStart = { x: fromBbox.left - config.nodeSpacing, y: toBbox.top + toBbox.height / 2 };
  41733. var lineEnd = { x: toBbox.left + toBbox.width, y: toBbox.top + toBbox.height / 2 };
  41734. svgDrawLine(svg, [lineStart, lineEnd], color, 'linear');
  41735. svgDrawLine(svg, [{ x: fromBbox.left, y: fromBbox.top + fromBbox.height / 2 }, { x: fromBbox.left - config.nodeSpacing / 2, y: fromBbox.top + fromBbox.height / 2 }, { x: fromBbox.left - config.nodeSpacing / 2, y: lineStart.y }, lineStart], color);
  41736. } else {
  41737. svgDrawLine(svg, [{
  41738. 'x': fromBbox.left,
  41739. 'y': fromBbox.top + fromBbox.height / 2
  41740. }, {
  41741. 'x': fromBbox.left - config.nodeSpacing / 2,
  41742. 'y': fromBbox.top + fromBbox.height / 2
  41743. }, {
  41744. 'x': fromBbox.left - config.nodeSpacing / 2,
  41745. 'y': toBbox.top + toBbox.height / 2
  41746. }, {
  41747. 'x': toBbox.left + toBbox.width,
  41748. 'y': toBbox.top + toBbox.height / 2
  41749. }], color);
  41750. }
  41751. break;
  41752. case 'BT':
  41753. // + (fromBbox)
  41754. // |
  41755. // |
  41756. // + (toBbox)
  41757. if (toBbox.top - fromBbox.top > config.nodeSpacing) {
  41758. lineStart = { x: toBbox.left + toBbox.width / 2, y: fromBbox.top + fromBbox.height + config.nodeSpacing };
  41759. lineEnd = { x: toBbox.left + toBbox.width / 2, y: toBbox.top };
  41760. svgDrawLine(svg, [lineStart, lineEnd], color, 'linear');
  41761. svgDrawLine(svg, [{ x: fromBbox.left + fromBbox.width / 2, y: fromBbox.top + fromBbox.height }, { x: fromBbox.left + fromBbox.width / 2, y: fromBbox.top + fromBbox.height + config.nodeSpacing / 2 }, { x: toBbox.left + toBbox.width / 2, y: lineStart.y - config.nodeSpacing / 2 }, lineStart], color);
  41762. } else {
  41763. svgDrawLine(svg, [{
  41764. 'x': fromBbox.left + fromBbox.width / 2,
  41765. 'y': fromBbox.top + fromBbox.height
  41766. }, {
  41767. 'x': fromBbox.left + fromBbox.width / 2,
  41768. 'y': fromBbox.top + config.nodeSpacing / 2
  41769. }, {
  41770. 'x': toBbox.left + toBbox.width / 2,
  41771. 'y': toBbox.top - config.nodeSpacing / 2
  41772. }, {
  41773. 'x': toBbox.left + toBbox.width / 2,
  41774. 'y': toBbox.top
  41775. }], color);
  41776. }
  41777. break;
  41778. }
  41779. }
  41780. function cloneNode(svg, selector) {
  41781. return svg.select(selector).node().cloneNode(true);
  41782. }
  41783. function renderCommitHistory(svg, commitid, branches, direction) {
  41784. var commit;
  41785. var numCommits = Object.keys(allCommitsDict).length;
  41786. if (_.isString(commitid)) {
  41787. do {
  41788. commit = allCommitsDict[commitid];
  41789. log.debug('in renderCommitHistory', commit.id, commit.seq);
  41790. if (svg.select('#node-' + commitid).size() > 0) {
  41791. return;
  41792. }
  41793. svg.append(function () {
  41794. return cloneNode(svg, '#def-commit');
  41795. }).attr('class', 'commit').attr('id', function () {
  41796. return 'node-' + commit.id;
  41797. }).attr('transform', function () {
  41798. switch (direction) {
  41799. case 'LR':
  41800. return 'translate(' + (commit.seq * config.nodeSpacing + config.leftMargin) + ', ' + branchNum * config.branchOffset + ')';
  41801. case 'BT':
  41802. return 'translate(' + (branchNum * config.branchOffset + config.leftMargin) + ', ' + (numCommits - commit.seq) * config.nodeSpacing + ')';
  41803. }
  41804. }).attr('fill', config.nodeFillColor).attr('stroke', config.nodeStrokeColor).attr('stroke-width', config.nodeStrokeWidth);
  41805. var branch = _.find(branches, ['commit', commit]);
  41806. if (branch) {
  41807. log.debug('found branch ', branch.name);
  41808. svg.select('#node-' + commit.id + ' p').append('xhtml:span').attr('class', 'branch-label').text(branch.name + ', ');
  41809. }
  41810. svg.select('#node-' + commit.id + ' p').append('xhtml:span').attr('class', 'commit-id').text(commit.id);
  41811. if (commit.message !== '' && direction === 'BT') {
  41812. svg.select('#node-' + commit.id + ' p').append('xhtml:span').attr('class', 'commit-msg').text(', ' + commit.message);
  41813. }
  41814. commitid = commit.parent;
  41815. } while (commitid && allCommitsDict[commitid]);
  41816. }
  41817. if (_.isArray(commitid)) {
  41818. log.debug('found merge commmit', commitid);
  41819. renderCommitHistory(svg, commitid[0], branches, direction);
  41820. branchNum++;
  41821. renderCommitHistory(svg, commitid[1], branches, direction);
  41822. branchNum--;
  41823. }
  41824. }
  41825. function renderLines(svg, commit, direction, branchColor) {
  41826. branchColor = branchColor || 0;
  41827. while (commit.seq > 0 && !commit.lineDrawn) {
  41828. if (_.isString(commit.parent)) {
  41829. svgDrawLineForCommits(svg, commit.id, commit.parent, direction, branchColor);
  41830. commit.lineDrawn = true;
  41831. commit = allCommitsDict[commit.parent];
  41832. } else if (_.isArray(commit.parent)) {
  41833. svgDrawLineForCommits(svg, commit.id, commit.parent[0], direction, branchColor);
  41834. svgDrawLineForCommits(svg, commit.id, commit.parent[1], direction, branchColor + 1);
  41835. renderLines(svg, allCommitsDict[commit.parent[1]], direction, branchColor + 1);
  41836. commit.lineDrawn = true;
  41837. commit = allCommitsDict[commit.parent[0]];
  41838. }
  41839. }
  41840. }
  41841. exports.draw = function (txt, id, ver) {
  41842. try {
  41843. var parser;
  41844. parser = gitGraphParser.parser;
  41845. parser.yy = db;
  41846. log.debug('in gitgraph renderer', txt, id, ver);
  41847. // Parse the graph definition
  41848. parser.parse(txt + '\n');
  41849. config = _.extend(config, apiConfig, db.getOptions());
  41850. log.debug('effective options', config);
  41851. var direction = db.getDirection();
  41852. allCommitsDict = db.getCommits();
  41853. var branches = db.getBranchesAsObjArray();
  41854. if (direction === 'BT') {
  41855. config.nodeLabel.x = branches.length * config.branchOffset;
  41856. config.nodeLabel.width = '100%';
  41857. config.nodeLabel.y = -1 * 2 * config.nodeRadius;
  41858. }
  41859. var svg = d3.select('#' + id);
  41860. svgCreateDefs(svg);
  41861. branchNum = 1;
  41862. _.each(branches, function (v) {
  41863. renderCommitHistory(svg, v.commit.id, branches, direction);
  41864. renderLines(svg, v.commit, direction);
  41865. branchNum++;
  41866. });
  41867. svg.attr('height', function () {
  41868. if (direction === 'BT') return Object.keys(allCommitsDict).length * config.nodeSpacing;
  41869. return (branches.length + 1) * config.branchOffset;
  41870. });
  41871. //svg.attr('width', function() {
  41872. //if (direction === 'LR') return Object.keys(allCommitsDict).length * config.nodeSpacing + config.leftMargin;
  41873. //return (branches.length + 1) * config.branchOffset;
  41874. //});
  41875. } catch (e) {
  41876. log.error('Error while rendering gitgraph');
  41877. log.error(e.message);
  41878. }
  41879. };
  41880. },{"../../d3":107,"../../logger":129,"./gitGraphAst":122,"./parser/gitGraph":124,"lodash":102}],124:[function(require,module,exports){
  41881. (function (process){
  41882. /* parser generated by jison 0.4.17 */
  41883. /*
  41884. Returns a Parser object of the following structure:
  41885. Parser: {
  41886. yy: {}
  41887. }
  41888. Parser.prototype: {
  41889. yy: {},
  41890. trace: function(),
  41891. symbols_: {associative list: name ==> number},
  41892. terminals_: {associative list: number ==> name},
  41893. productions_: [...],
  41894. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  41895. table: [...],
  41896. defaultActions: {...},
  41897. parseError: function(str, hash),
  41898. parse: function(input),
  41899. lexer: {
  41900. EOF: 1,
  41901. parseError: function(str, hash),
  41902. setInput: function(input),
  41903. input: function(),
  41904. unput: function(str),
  41905. more: function(),
  41906. less: function(n),
  41907. pastInput: function(),
  41908. upcomingInput: function(),
  41909. showPosition: function(),
  41910. test_match: function(regex_match_array, rule_index),
  41911. next: function(),
  41912. lex: function(),
  41913. begin: function(condition),
  41914. popState: function(),
  41915. _currentRules: function(),
  41916. topState: function(),
  41917. pushState: function(condition),
  41918. options: {
  41919. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  41920. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  41921. backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code)
  41922. },
  41923. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  41924. rules: [...],
  41925. conditions: {associative list: name ==> set},
  41926. }
  41927. }
  41928. token location info (@$, _$, etc.): {
  41929. first_line: n,
  41930. last_line: n,
  41931. first_column: n,
  41932. last_column: n,
  41933. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  41934. }
  41935. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  41936. text: (matched text)
  41937. token: (the produced terminal token, if any)
  41938. line: (yylineno)
  41939. }
  41940. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  41941. loc: (yylloc)
  41942. expected: (string describing the set of expected tokens)
  41943. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  41944. }
  41945. */
  41946. "use strict";
  41947. var parser = (function () {
  41948. var o = function o(k, v, _o, l) {
  41949. for (_o = _o || {}, l = k.length; l--; _o[k[l]] = v);return _o;
  41950. },
  41951. $V0 = [2, 3],
  41952. $V1 = [1, 7],
  41953. $V2 = [7, 12, 15, 17, 19, 20, 21],
  41954. $V3 = [7, 11, 12, 15, 17, 19, 20, 21],
  41955. $V4 = [2, 20],
  41956. $V5 = [1, 32];
  41957. var parser = { trace: function trace() {},
  41958. yy: {},
  41959. symbols_: { "error": 2, "start": 3, "GG": 4, ":": 5, "document": 6, "EOF": 7, "DIR": 8, "options": 9, "body": 10, "OPT": 11, "NL": 12, "line": 13, "statement": 14, "COMMIT": 15, "commit_arg": 16, "BRANCH": 17, "ID": 18, "CHECKOUT": 19, "MERGE": 20, "RESET": 21, "reset_arg": 22, "STR": 23, "HEAD": 24, "reset_parents": 25, "CARET": 26, "$accept": 0, "$end": 1 },
  41960. terminals_: { 2: "error", 4: "GG", 5: ":", 7: "EOF", 8: "DIR", 11: "OPT", 12: "NL", 15: "COMMIT", 17: "BRANCH", 18: "ID", 19: "CHECKOUT", 20: "MERGE", 21: "RESET", 23: "STR", 24: "HEAD", 26: "CARET" },
  41961. productions_: [0, [3, 4], [3, 5], [6, 0], [6, 2], [9, 2], [9, 1], [10, 0], [10, 2], [13, 2], [13, 1], [14, 2], [14, 2], [14, 2], [14, 2], [14, 2], [16, 0], [16, 1], [22, 2], [22, 2], [25, 0], [25, 2]],
  41962. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, /* action[1] */$$, /* vstack */_$ /* lstack */) {
  41963. /* this == yyval */
  41964. var $0 = $$.length - 1;
  41965. switch (yystate) {
  41966. case 1:
  41967. return $$[$0 - 1];
  41968. break;
  41969. case 2:
  41970. yy.setDirection($$[$0 - 3]);return $$[$0 - 1];
  41971. break;
  41972. case 4:
  41973. yy.setOptions($$[$0 - 1]);this.$ = $$[$0];
  41974. break;
  41975. case 5:
  41976. $$[$0 - 1] += $$[$0];this.$ = $$[$0 - 1];
  41977. break;
  41978. case 7:
  41979. this.$ = [];
  41980. break;
  41981. case 8:
  41982. $$[$0 - 1].push($$[$0]);this.$ = $$[$0 - 1];
  41983. break;
  41984. case 9:
  41985. this.$ = $$[$0 - 1];
  41986. break;
  41987. case 11:
  41988. yy.commit($$[$0]);
  41989. break;
  41990. case 12:
  41991. yy.branch($$[$0]);
  41992. break;
  41993. case 13:
  41994. yy.checkout($$[$0]);
  41995. break;
  41996. case 14:
  41997. yy.merge($$[$0]);
  41998. break;
  41999. case 15:
  42000. yy.reset($$[$0]);
  42001. break;
  42002. case 16:
  42003. this.$ = "";
  42004. break;
  42005. case 17:
  42006. this.$ = $$[$0];
  42007. break;
  42008. case 18:
  42009. this.$ = $$[$0 - 1] + ":" + $$[$0];
  42010. break;
  42011. case 19:
  42012. this.$ = $$[$0 - 1] + ":" + yy.count;yy.count = 0;
  42013. break;
  42014. case 20:
  42015. yy.count = 0;
  42016. break;
  42017. case 21:
  42018. yy.count += 1;
  42019. break;
  42020. }
  42021. },
  42022. table: [{ 3: 1, 4: [1, 2] }, { 1: [3] }, { 5: [1, 3], 8: [1, 4] }, { 6: 5, 7: $V0, 9: 6, 12: $V1 }, { 5: [1, 8] }, { 7: [1, 9] }, o($V2, [2, 7], { 10: 10, 11: [1, 11] }), o($V3, [2, 6]), { 6: 12, 7: $V0, 9: 6, 12: $V1 }, { 1: [2, 1] }, { 7: [2, 4], 12: [1, 15], 13: 13, 14: 14, 15: [1, 16], 17: [1, 17], 19: [1, 18], 20: [1, 19], 21: [1, 20] }, o($V3, [2, 5]), { 7: [1, 21] }, o($V2, [2, 8]), { 12: [1, 22] }, o($V2, [2, 10]), { 12: [2, 16], 16: 23, 23: [1, 24] }, { 18: [1, 25] }, { 18: [1, 26] }, { 18: [1, 27] }, { 18: [1, 30], 22: 28, 24: [1, 29] }, { 1: [2, 2] }, o($V2, [2, 9]), { 12: [2, 11] }, { 12: [2, 17] }, { 12: [2, 12] }, { 12: [2, 13] }, { 12: [2, 14] }, { 12: [2, 15] }, { 12: $V4, 25: 31, 26: $V5 }, { 12: $V4, 25: 33, 26: $V5 }, { 12: [2, 18] }, { 12: $V4, 25: 34, 26: $V5 }, { 12: [2, 19] }, { 12: [2, 21] }],
  42023. defaultActions: { 9: [2, 1], 21: [2, 2], 23: [2, 11], 24: [2, 17], 25: [2, 12], 26: [2, 13], 27: [2, 14], 28: [2, 15], 31: [2, 18], 33: [2, 19], 34: [2, 21] },
  42024. parseError: function parseError(str, hash) {
  42025. if (hash.recoverable) {
  42026. this.trace(str);
  42027. } else {
  42028. var _parseError = function _parseError(msg, hash) {
  42029. this.message = msg;
  42030. this.hash = hash;
  42031. };
  42032. _parseError.prototype = Error;
  42033. throw new _parseError(str, hash);
  42034. }
  42035. },
  42036. parse: function parse(input) {
  42037. var self = this,
  42038. stack = [0],
  42039. tstack = [],
  42040. vstack = [null],
  42041. lstack = [],
  42042. table = this.table,
  42043. yytext = '',
  42044. yylineno = 0,
  42045. yyleng = 0,
  42046. recovering = 0,
  42047. TERROR = 2,
  42048. EOF = 1;
  42049. var args = lstack.slice.call(arguments, 1);
  42050. var lexer = Object.create(this.lexer);
  42051. var sharedState = { yy: {} };
  42052. for (var k in this.yy) {
  42053. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  42054. sharedState.yy[k] = this.yy[k];
  42055. }
  42056. }
  42057. lexer.setInput(input, sharedState.yy);
  42058. sharedState.yy.lexer = lexer;
  42059. sharedState.yy.parser = this;
  42060. if (typeof lexer.yylloc == 'undefined') {
  42061. lexer.yylloc = {};
  42062. }
  42063. var yyloc = lexer.yylloc;
  42064. lstack.push(yyloc);
  42065. var ranges = lexer.options && lexer.options.ranges;
  42066. if (typeof sharedState.yy.parseError === 'function') {
  42067. this.parseError = sharedState.yy.parseError;
  42068. } else {
  42069. this.parseError = Object.getPrototypeOf(this).parseError;
  42070. }
  42071. function popStack(n) {
  42072. stack.length = stack.length - 2 * n;
  42073. vstack.length = vstack.length - n;
  42074. lstack.length = lstack.length - n;
  42075. }
  42076. _token_stack: var lex = function lex() {
  42077. var token;
  42078. token = lexer.lex() || EOF;
  42079. if (typeof token !== 'number') {
  42080. token = self.symbols_[token] || token;
  42081. }
  42082. return token;
  42083. };
  42084. var symbol,
  42085. preErrorSymbol,
  42086. state,
  42087. action,
  42088. a,
  42089. r,
  42090. yyval = {},
  42091. p,
  42092. len,
  42093. newState,
  42094. expected;
  42095. while (true) {
  42096. state = stack[stack.length - 1];
  42097. if (this.defaultActions[state]) {
  42098. action = this.defaultActions[state];
  42099. } else {
  42100. if (symbol === null || typeof symbol == 'undefined') {
  42101. symbol = lex();
  42102. }
  42103. action = table[state] && table[state][symbol];
  42104. }
  42105. if (typeof action === 'undefined' || !action.length || !action[0]) {
  42106. var errStr = '';
  42107. expected = [];
  42108. for (p in table[state]) {
  42109. if (this.terminals_[p] && p > TERROR) {
  42110. expected.push('\'' + this.terminals_[p] + '\'');
  42111. }
  42112. }
  42113. if (lexer.showPosition) {
  42114. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  42115. } else {
  42116. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  42117. }
  42118. this.parseError(errStr, {
  42119. text: lexer.match,
  42120. token: this.terminals_[symbol] || symbol,
  42121. line: lexer.yylineno,
  42122. loc: yyloc,
  42123. expected: expected
  42124. });
  42125. }
  42126. if (action[0] instanceof Array && action.length > 1) {
  42127. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  42128. }
  42129. switch (action[0]) {
  42130. case 1:
  42131. stack.push(symbol);
  42132. vstack.push(lexer.yytext);
  42133. lstack.push(lexer.yylloc);
  42134. stack.push(action[1]);
  42135. symbol = null;
  42136. if (!preErrorSymbol) {
  42137. yyleng = lexer.yyleng;
  42138. yytext = lexer.yytext;
  42139. yylineno = lexer.yylineno;
  42140. yyloc = lexer.yylloc;
  42141. if (recovering > 0) {
  42142. recovering--;
  42143. }
  42144. } else {
  42145. symbol = preErrorSymbol;
  42146. preErrorSymbol = null;
  42147. }
  42148. break;
  42149. case 2:
  42150. len = this.productions_[action[1]][1];
  42151. yyval.$ = vstack[vstack.length - len];
  42152. yyval._$ = {
  42153. first_line: lstack[lstack.length - (len || 1)].first_line,
  42154. last_line: lstack[lstack.length - 1].last_line,
  42155. first_column: lstack[lstack.length - (len || 1)].first_column,
  42156. last_column: lstack[lstack.length - 1].last_column
  42157. };
  42158. if (ranges) {
  42159. yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
  42160. }
  42161. r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
  42162. if (typeof r !== 'undefined') {
  42163. return r;
  42164. }
  42165. if (len) {
  42166. stack = stack.slice(0, -1 * len * 2);
  42167. vstack = vstack.slice(0, -1 * len);
  42168. lstack = lstack.slice(0, -1 * len);
  42169. }
  42170. stack.push(this.productions_[action[1]][0]);
  42171. vstack.push(yyval.$);
  42172. lstack.push(yyval._$);
  42173. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  42174. stack.push(newState);
  42175. break;
  42176. case 3:
  42177. return true;
  42178. }
  42179. }
  42180. return true;
  42181. } };
  42182. /* generated by jison-lex 0.3.4 */
  42183. var lexer = (function () {
  42184. var lexer = {
  42185. EOF: 1,
  42186. parseError: function parseError(str, hash) {
  42187. if (this.yy.parser) {
  42188. this.yy.parser.parseError(str, hash);
  42189. } else {
  42190. throw new Error(str);
  42191. }
  42192. },
  42193. // resets the lexer, sets new input
  42194. setInput: function setInput(input, yy) {
  42195. this.yy = yy || this.yy || {};
  42196. this._input = input;
  42197. this._more = this._backtrack = this.done = false;
  42198. this.yylineno = this.yyleng = 0;
  42199. this.yytext = this.matched = this.match = '';
  42200. this.conditionStack = ['INITIAL'];
  42201. this.yylloc = {
  42202. first_line: 1,
  42203. first_column: 0,
  42204. last_line: 1,
  42205. last_column: 0
  42206. };
  42207. if (this.options.ranges) {
  42208. this.yylloc.range = [0, 0];
  42209. }
  42210. this.offset = 0;
  42211. return this;
  42212. },
  42213. // consumes and returns one char from the input
  42214. input: function input() {
  42215. var ch = this._input[0];
  42216. this.yytext += ch;
  42217. this.yyleng++;
  42218. this.offset++;
  42219. this.match += ch;
  42220. this.matched += ch;
  42221. var lines = ch.match(/(?:\r\n?|\n).*/g);
  42222. if (lines) {
  42223. this.yylineno++;
  42224. this.yylloc.last_line++;
  42225. } else {
  42226. this.yylloc.last_column++;
  42227. }
  42228. if (this.options.ranges) {
  42229. this.yylloc.range[1]++;
  42230. }
  42231. this._input = this._input.slice(1);
  42232. return ch;
  42233. },
  42234. // unshifts one char (or a string) into the input
  42235. unput: function unput(ch) {
  42236. var len = ch.length;
  42237. var lines = ch.split(/(?:\r\n?|\n)/g);
  42238. this._input = ch + this._input;
  42239. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  42240. //this.yyleng -= len;
  42241. this.offset -= len;
  42242. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  42243. this.match = this.match.substr(0, this.match.length - 1);
  42244. this.matched = this.matched.substr(0, this.matched.length - 1);
  42245. if (lines.length - 1) {
  42246. this.yylineno -= lines.length - 1;
  42247. }
  42248. var r = this.yylloc.range;
  42249. this.yylloc = {
  42250. first_line: this.yylloc.first_line,
  42251. last_line: this.yylineno + 1,
  42252. first_column: this.yylloc.first_column,
  42253. last_column: lines ? (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length : this.yylloc.first_column - len
  42254. };
  42255. if (this.options.ranges) {
  42256. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  42257. }
  42258. this.yyleng = this.yytext.length;
  42259. return this;
  42260. },
  42261. // When called from action, caches matched text and appends it on next action
  42262. more: function more() {
  42263. this._more = true;
  42264. return this;
  42265. },
  42266. // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
  42267. reject: function reject() {
  42268. if (this.options.backtrack_lexer) {
  42269. this._backtrack = true;
  42270. } else {
  42271. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), {
  42272. text: "",
  42273. token: null,
  42274. line: this.yylineno
  42275. });
  42276. }
  42277. return this;
  42278. },
  42279. // retain first n characters of the match
  42280. less: function less(n) {
  42281. this.unput(this.match.slice(n));
  42282. },
  42283. // displays already matched input, i.e. for error messages
  42284. pastInput: function pastInput() {
  42285. var past = this.matched.substr(0, this.matched.length - this.match.length);
  42286. return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
  42287. },
  42288. // displays upcoming input, i.e. for error messages
  42289. upcomingInput: function upcomingInput() {
  42290. var next = this.match;
  42291. if (next.length < 20) {
  42292. next += this._input.substr(0, 20 - next.length);
  42293. }
  42294. return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  42295. },
  42296. // displays the character position where the lexing error occurred, i.e. for error messages
  42297. showPosition: function showPosition() {
  42298. var pre = this.pastInput();
  42299. var c = new Array(pre.length + 1).join("-");
  42300. return pre + this.upcomingInput() + "\n" + c + "^";
  42301. },
  42302. // test the lexed token: return FALSE when not a match, otherwise return token
  42303. test_match: function test_match(match, indexed_rule) {
  42304. var token, lines, backup;
  42305. if (this.options.backtrack_lexer) {
  42306. // save context
  42307. backup = {
  42308. yylineno: this.yylineno,
  42309. yylloc: {
  42310. first_line: this.yylloc.first_line,
  42311. last_line: this.last_line,
  42312. first_column: this.yylloc.first_column,
  42313. last_column: this.yylloc.last_column
  42314. },
  42315. yytext: this.yytext,
  42316. match: this.match,
  42317. matches: this.matches,
  42318. matched: this.matched,
  42319. yyleng: this.yyleng,
  42320. offset: this.offset,
  42321. _more: this._more,
  42322. _input: this._input,
  42323. yy: this.yy,
  42324. conditionStack: this.conditionStack.slice(0),
  42325. done: this.done
  42326. };
  42327. if (this.options.ranges) {
  42328. backup.yylloc.range = this.yylloc.range.slice(0);
  42329. }
  42330. }
  42331. lines = match[0].match(/(?:\r\n?|\n).*/g);
  42332. if (lines) {
  42333. this.yylineno += lines.length;
  42334. }
  42335. this.yylloc = {
  42336. first_line: this.yylloc.last_line,
  42337. last_line: this.yylineno + 1,
  42338. first_column: this.yylloc.last_column,
  42339. last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
  42340. };
  42341. this.yytext += match[0];
  42342. this.match += match[0];
  42343. this.matches = match;
  42344. this.yyleng = this.yytext.length;
  42345. if (this.options.ranges) {
  42346. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  42347. }
  42348. this._more = false;
  42349. this._backtrack = false;
  42350. this._input = this._input.slice(match[0].length);
  42351. this.matched += match[0];
  42352. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  42353. if (this.done && this._input) {
  42354. this.done = false;
  42355. }
  42356. if (token) {
  42357. return token;
  42358. } else if (this._backtrack) {
  42359. // recover context
  42360. for (var k in backup) {
  42361. this[k] = backup[k];
  42362. }
  42363. return false; // rule action called reject() implying the next rule should be tested instead.
  42364. }
  42365. return false;
  42366. },
  42367. // return next match in input
  42368. next: function next() {
  42369. if (this.done) {
  42370. return this.EOF;
  42371. }
  42372. if (!this._input) {
  42373. this.done = true;
  42374. }
  42375. var token, match, tempMatch, index;
  42376. if (!this._more) {
  42377. this.yytext = '';
  42378. this.match = '';
  42379. }
  42380. var rules = this._currentRules();
  42381. for (var i = 0; i < rules.length; i++) {
  42382. tempMatch = this._input.match(this.rules[rules[i]]);
  42383. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  42384. match = tempMatch;
  42385. index = i;
  42386. if (this.options.backtrack_lexer) {
  42387. token = this.test_match(tempMatch, rules[i]);
  42388. if (token !== false) {
  42389. return token;
  42390. } else if (this._backtrack) {
  42391. match = false;
  42392. continue; // rule action called reject() implying a rule MISmatch.
  42393. } else {
  42394. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  42395. return false;
  42396. }
  42397. } else if (!this.options.flex) {
  42398. break;
  42399. }
  42400. }
  42401. }
  42402. if (match) {
  42403. token = this.test_match(match, rules[index]);
  42404. if (token !== false) {
  42405. return token;
  42406. }
  42407. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  42408. return false;
  42409. }
  42410. if (this._input === "") {
  42411. return this.EOF;
  42412. } else {
  42413. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  42414. text: "",
  42415. token: null,
  42416. line: this.yylineno
  42417. });
  42418. }
  42419. },
  42420. // return next match that has a token
  42421. lex: function lex() {
  42422. var r = this.next();
  42423. if (r) {
  42424. return r;
  42425. } else {
  42426. return this.lex();
  42427. }
  42428. },
  42429. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  42430. begin: function begin(condition) {
  42431. this.conditionStack.push(condition);
  42432. },
  42433. // pop the previously active lexer condition state off the condition stack
  42434. popState: function popState() {
  42435. var n = this.conditionStack.length - 1;
  42436. if (n > 0) {
  42437. return this.conditionStack.pop();
  42438. } else {
  42439. return this.conditionStack[0];
  42440. }
  42441. },
  42442. // produce the lexer rule set which is active for the currently active lexer condition state
  42443. _currentRules: function _currentRules() {
  42444. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  42445. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  42446. } else {
  42447. return this.conditions["INITIAL"].rules;
  42448. }
  42449. },
  42450. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  42451. topState: function topState(n) {
  42452. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  42453. if (n >= 0) {
  42454. return this.conditionStack[n];
  42455. } else {
  42456. return "INITIAL";
  42457. }
  42458. },
  42459. // alias for begin(condition)
  42460. pushState: function pushState(condition) {
  42461. this.begin(condition);
  42462. },
  42463. // return the number of states currently on the stack
  42464. stateStackSize: function stateStackSize() {
  42465. return this.conditionStack.length;
  42466. },
  42467. options: { "case-insensitive": true },
  42468. performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
  42469. var YYSTATE = YY_START;
  42470. switch ($avoiding_name_collisions) {
  42471. case 0:
  42472. return 12;
  42473. break;
  42474. case 1:
  42475. /* skip all whitespace */
  42476. break;
  42477. case 2:
  42478. /* skip comments */
  42479. break;
  42480. case 3:
  42481. /* skip comments */
  42482. break;
  42483. case 4:
  42484. return 4;
  42485. break;
  42486. case 5:
  42487. return 15;
  42488. break;
  42489. case 6:
  42490. return 17;
  42491. break;
  42492. case 7:
  42493. return 20;
  42494. break;
  42495. case 8:
  42496. return 21;
  42497. break;
  42498. case 9:
  42499. return 19;
  42500. break;
  42501. case 10:
  42502. return 8;
  42503. break;
  42504. case 11:
  42505. return 8;
  42506. break;
  42507. case 12:
  42508. return 5;
  42509. break;
  42510. case 13:
  42511. return 26;
  42512. break;
  42513. case 14:
  42514. this.begin("options");
  42515. break;
  42516. case 15:
  42517. this.popState();
  42518. break;
  42519. case 16:
  42520. return 11;
  42521. break;
  42522. case 17:
  42523. this.begin("string");
  42524. break;
  42525. case 18:
  42526. this.popState();
  42527. break;
  42528. case 19:
  42529. return 23;
  42530. break;
  42531. case 20:
  42532. return 18;
  42533. break;
  42534. case 21:
  42535. return 7;
  42536. break;
  42537. }
  42538. },
  42539. rules: [/^(?:(\r?\n)+)/i, /^(?:\s+)/i, /^(?:#[^\n]*)/i, /^(?:%[^\n]*)/i, /^(?:gitGraph\b)/i, /^(?:commit\b)/i, /^(?:branch\b)/i, /^(?:merge\b)/i, /^(?:reset\b)/i, /^(?:checkout\b)/i, /^(?:LR\b)/i, /^(?:BT\b)/i, /^(?::)/i, /^(?:\^)/i, /^(?:options\r?\n)/i, /^(?:end\r?\n)/i, /^(?:[^\n]+\r?\n)/i, /^(?:["])/i, /^(?:["])/i, /^(?:[^"]*)/i, /^(?:[a-zA-Z][a-zA-Z0-9_]+)/i, /^(?:$)/i],
  42540. conditions: { "options": { "rules": [15, 16], "inclusive": false }, "string": { "rules": [18, 19], "inclusive": false }, "INITIAL": { "rules": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 20, 21], "inclusive": true } }
  42541. };
  42542. return lexer;
  42543. })();
  42544. parser.lexer = lexer;
  42545. function Parser() {
  42546. this.yy = {};
  42547. }
  42548. Parser.prototype = parser;parser.Parser = Parser;
  42549. return new Parser();
  42550. })();
  42551. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  42552. exports.parser = parser;
  42553. exports.Parser = parser.Parser;
  42554. exports.parse = function () {
  42555. return parser.parse.apply(parser, arguments);
  42556. };
  42557. exports.main = function commonjsMain(args) {
  42558. if (!args[1]) {
  42559. console.log('Usage: ' + args[0] + ' FILE');
  42560. process.exit(1);
  42561. }
  42562. var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
  42563. return exports.parser.parse(source);
  42564. };
  42565. if (typeof module !== 'undefined' && require.main === module) {
  42566. exports.main(process.argv.slice(1));
  42567. }
  42568. }
  42569. }).call(this,require('_process'))
  42570. },{"_process":105,"fs":1,"path":104}],125:[function(require,module,exports){
  42571. (function (process){
  42572. /* parser generated by jison 0.4.17 */
  42573. /*
  42574. Returns a Parser object of the following structure:
  42575. Parser: {
  42576. yy: {}
  42577. }
  42578. Parser.prototype: {
  42579. yy: {},
  42580. trace: function(),
  42581. symbols_: {associative list: name ==> number},
  42582. terminals_: {associative list: number ==> name},
  42583. productions_: [...],
  42584. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  42585. table: [...],
  42586. defaultActions: {...},
  42587. parseError: function(str, hash),
  42588. parse: function(input),
  42589. lexer: {
  42590. EOF: 1,
  42591. parseError: function(str, hash),
  42592. setInput: function(input),
  42593. input: function(),
  42594. unput: function(str),
  42595. more: function(),
  42596. less: function(n),
  42597. pastInput: function(),
  42598. upcomingInput: function(),
  42599. showPosition: function(),
  42600. test_match: function(regex_match_array, rule_index),
  42601. next: function(),
  42602. lex: function(),
  42603. begin: function(condition),
  42604. popState: function(),
  42605. _currentRules: function(),
  42606. topState: function(),
  42607. pushState: function(condition),
  42608. options: {
  42609. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  42610. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  42611. backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code)
  42612. },
  42613. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  42614. rules: [...],
  42615. conditions: {associative list: name ==> set},
  42616. }
  42617. }
  42618. token location info (@$, _$, etc.): {
  42619. first_line: n,
  42620. last_line: n,
  42621. first_column: n,
  42622. last_column: n,
  42623. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  42624. }
  42625. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  42626. text: (matched text)
  42627. token: (the produced terminal token, if any)
  42628. line: (yylineno)
  42629. }
  42630. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  42631. loc: (yylloc)
  42632. expected: (string describing the set of expected tokens)
  42633. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  42634. }
  42635. */
  42636. "use strict";
  42637. var parser = (function () {
  42638. var o = function o(k, v, _o, l) {
  42639. for (_o = _o || {}, l = k.length; l--; _o[k[l]] = v);return _o;
  42640. },
  42641. $V0 = [1, 2],
  42642. $V1 = [1, 3],
  42643. $V2 = [1, 4],
  42644. $V3 = [2, 4],
  42645. $V4 = [1, 9],
  42646. $V5 = [1, 11],
  42647. $V6 = [1, 12],
  42648. $V7 = [1, 14],
  42649. $V8 = [1, 15],
  42650. $V9 = [1, 17],
  42651. $Va = [1, 18],
  42652. $Vb = [1, 19],
  42653. $Vc = [1, 20],
  42654. $Vd = [1, 22],
  42655. $Ve = [1, 23],
  42656. $Vf = [1, 4, 5, 10, 15, 16, 18, 20, 21, 22, 23, 24, 25, 36],
  42657. $Vg = [1, 31],
  42658. $Vh = [4, 5, 10, 15, 16, 18, 20, 21, 22, 23, 25, 36],
  42659. $Vi = [34, 35, 36];
  42660. var parser = { trace: function trace() {},
  42661. yy: {},
  42662. symbols_: { "error": 2, "start": 3, "SPACE": 4, "NL": 5, "SD": 6, "document": 7, "line": 8, "statement": 9, "participant": 10, "actor": 11, "AS": 12, "restOfLine": 13, "signal": 14, "activate": 15, "deactivate": 16, "note_statement": 17, "title": 18, "text2": 19, "loop": 20, "end": 21, "opt": 22, "alt": 23, "else": 24, "note": 25, "placement": 26, "over": 27, "actor_pair": 28, "spaceList": 29, ",": 30, "left_of": 31, "right_of": 32, "signaltype": 33, "+": 34, "-": 35, "ACTOR": 36, "SOLID_OPEN_ARROW": 37, "DOTTED_OPEN_ARROW": 38, "SOLID_ARROW": 39, "DOTTED_ARROW": 40, "SOLID_CROSS": 41, "DOTTED_CROSS": 42, "TXT": 43, "$accept": 0, "$end": 1 },
  42663. terminals_: { 2: "error", 4: "SPACE", 5: "NL", 6: "SD", 10: "participant", 12: "AS", 13: "restOfLine", 15: "activate", 16: "deactivate", 18: "title", 20: "loop", 21: "end", 22: "opt", 23: "alt", 24: "else", 25: "note", 27: "over", 30: ",", 31: "left_of", 32: "right_of", 34: "+", 35: "-", 36: "ACTOR", 37: "SOLID_OPEN_ARROW", 38: "DOTTED_OPEN_ARROW", 39: "SOLID_ARROW", 40: "DOTTED_ARROW", 41: "SOLID_CROSS", 42: "DOTTED_CROSS", 43: "TXT" },
  42664. productions_: [0, [3, 2], [3, 2], [3, 2], [7, 0], [7, 2], [8, 2], [8, 1], [8, 1], [9, 5], [9, 3], [9, 2], [9, 3], [9, 3], [9, 2], [9, 3], [9, 4], [9, 4], [9, 7], [17, 4], [17, 4], [29, 2], [29, 1], [28, 3], [28, 1], [26, 1], [26, 1], [14, 5], [14, 5], [14, 4], [11, 1], [33, 1], [33, 1], [33, 1], [33, 1], [33, 1], [33, 1], [19, 1]],
  42665. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, /* action[1] */$$, /* vstack */_$ /* lstack */) {
  42666. /* this == yyval */
  42667. var $0 = $$.length - 1;
  42668. switch (yystate) {
  42669. case 3:
  42670. yy.apply($$[$0]);return $$[$0];
  42671. break;
  42672. case 4:
  42673. this.$ = [];
  42674. break;
  42675. case 5:
  42676. $$[$0 - 1].push($$[$0]);this.$ = $$[$0 - 1];
  42677. break;
  42678. case 6:case 7:
  42679. this.$ = $$[$0];
  42680. break;
  42681. case 8:
  42682. this.$ = [];
  42683. break;
  42684. case 9:
  42685. $$[$0 - 3].description = $$[$0 - 1];this.$ = $$[$0 - 3];
  42686. break;
  42687. case 10:
  42688. this.$ = $$[$0 - 1];
  42689. break;
  42690. case 12:
  42691. this.$ = { type: 'activeStart', signalType: yy.LINETYPE.ACTIVE_START, actor: $$[$0 - 1] };
  42692. break;
  42693. case 13:
  42694. this.$ = { type: 'activeEnd', signalType: yy.LINETYPE.ACTIVE_END, actor: $$[$0 - 1] };
  42695. break;
  42696. case 15:
  42697. this.$ = [{ type: 'setTitle', text: $$[$0 - 1] }];
  42698. break;
  42699. case 16:
  42700. $$[$0 - 1].unshift({ type: 'loopStart', loopText: $$[$0 - 2], signalType: yy.LINETYPE.LOOP_START });
  42701. $$[$0 - 1].push({ type: 'loopEnd', loopText: $$[$0 - 2], signalType: yy.LINETYPE.LOOP_END });
  42702. this.$ = $$[$0 - 1];
  42703. break;
  42704. case 17:
  42705. $$[$0 - 1].unshift({ type: 'optStart', optText: $$[$0 - 2], signalType: yy.LINETYPE.OPT_START });
  42706. $$[$0 - 1].push({ type: 'optEnd', optText: $$[$0 - 2], signalType: yy.LINETYPE.OPT_END });
  42707. this.$ = $$[$0 - 1];
  42708. break;
  42709. case 18:
  42710. // Alt start
  42711. $$[$0 - 4].unshift({ type: 'altStart', altText: $$[$0 - 5], signalType: yy.LINETYPE.ALT_START });
  42712. // Content in alt is already in $$[$0-4]
  42713. // Else
  42714. $$[$0 - 4].push({ type: 'else', altText: $$[$0 - 2], signalType: yy.LINETYPE.ALT_ELSE });
  42715. // Content in other alt
  42716. $$[$0 - 4] = $$[$0 - 4].concat($$[$0 - 1]);
  42717. // End
  42718. $$[$0 - 4].push({ type: 'altEnd', signalType: yy.LINETYPE.ALT_END });
  42719. this.$ = $$[$0 - 4];
  42720. break;
  42721. case 19:
  42722. this.$ = [$$[$0 - 1], { type: 'addNote', placement: $$[$0 - 2], actor: $$[$0 - 1].actor, text: $$[$0] }];
  42723. break;
  42724. case 20:
  42725. // Coerce actor_pair into a [to, from, ...] array
  42726. $$[$0 - 2] = [].concat($$[$0 - 1], $$[$0 - 1]).slice(0, 2);
  42727. $$[$0 - 2][0] = $$[$0 - 2][0].actor;
  42728. $$[$0 - 2][1] = $$[$0 - 2][1].actor;
  42729. this.$ = [$$[$0 - 1], { type: 'addNote', placement: yy.PLACEMENT.OVER, actor: $$[$0 - 2].slice(0, 2), text: $$[$0] }];
  42730. break;
  42731. case 23:
  42732. this.$ = [$$[$0 - 2], $$[$0]];
  42733. break;
  42734. case 24:
  42735. this.$ = $$[$0];
  42736. break;
  42737. case 25:
  42738. this.$ = yy.PLACEMENT.LEFTOF;
  42739. break;
  42740. case 26:
  42741. this.$ = yy.PLACEMENT.RIGHTOF;
  42742. break;
  42743. case 27:
  42744. this.$ = [$$[$0 - 4], $$[$0 - 1], { type: 'addMessage', from: $$[$0 - 4].actor, to: $$[$0 - 1].actor, signalType: $$[$0 - 3], msg: $$[$0] }, { type: 'activeStart', signalType: yy.LINETYPE.ACTIVE_START, actor: $$[$0 - 1] }];
  42745. break;
  42746. case 28:
  42747. this.$ = [$$[$0 - 4], $$[$0 - 1], { type: 'addMessage', from: $$[$0 - 4].actor, to: $$[$0 - 1].actor, signalType: $$[$0 - 3], msg: $$[$0] }, { type: 'activeEnd', signalType: yy.LINETYPE.ACTIVE_END, actor: $$[$0 - 4] }];
  42748. break;
  42749. case 29:
  42750. this.$ = [$$[$0 - 3], $$[$0 - 1], { type: 'addMessage', from: $$[$0 - 3].actor, to: $$[$0 - 1].actor, signalType: $$[$0 - 2], msg: $$[$0] }];
  42751. break;
  42752. case 30:
  42753. this.$ = { type: 'addActor', actor: $$[$0] };
  42754. break;
  42755. case 31:
  42756. this.$ = yy.LINETYPE.SOLID_OPEN;
  42757. break;
  42758. case 32:
  42759. this.$ = yy.LINETYPE.DOTTED_OPEN;
  42760. break;
  42761. case 33:
  42762. this.$ = yy.LINETYPE.SOLID;
  42763. break;
  42764. case 34:
  42765. this.$ = yy.LINETYPE.DOTTED;
  42766. break;
  42767. case 35:
  42768. this.$ = yy.LINETYPE.SOLID_CROSS;
  42769. break;
  42770. case 36:
  42771. this.$ = yy.LINETYPE.DOTTED_CROSS;
  42772. break;
  42773. case 37:
  42774. this.$ = $$[$0].substring(1).trim().replace(/\\n/gm, "\n");
  42775. break;
  42776. }
  42777. },
  42778. table: [{ 3: 1, 4: $V0, 5: $V1, 6: $V2 }, { 1: [3] }, { 3: 5, 4: $V0, 5: $V1, 6: $V2 }, { 3: 6, 4: $V0, 5: $V1, 6: $V2 }, o([1, 4, 5, 10, 15, 16, 18, 20, 22, 23, 25, 36], $V3, { 7: 7 }), { 1: [2, 1] }, { 1: [2, 2] }, { 1: [2, 3], 4: $V4, 5: $V5, 8: 8, 9: 10, 10: $V6, 11: 21, 14: 13, 15: $V7, 16: $V8, 17: 16, 18: $V9, 20: $Va, 22: $Vb, 23: $Vc, 25: $Vd, 36: $Ve }, o($Vf, [2, 5]), { 9: 24, 10: $V6, 11: 21, 14: 13, 15: $V7, 16: $V8, 17: 16, 18: $V9, 20: $Va, 22: $Vb, 23: $Vc, 25: $Vd, 36: $Ve }, o($Vf, [2, 7]), o($Vf, [2, 8]), { 11: 25, 36: $Ve }, { 5: [1, 26] }, { 11: 27, 36: $Ve }, { 11: 28, 36: $Ve }, { 5: [1, 29] }, { 19: 30, 43: $Vg }, { 13: [1, 32] }, { 13: [1, 33] }, { 13: [1, 34] }, { 33: 35, 37: [1, 36], 38: [1, 37], 39: [1, 38], 40: [1, 39], 41: [1, 40], 42: [1, 41] }, { 26: 42, 27: [1, 43], 31: [1, 44], 32: [1, 45] }, o([5, 12, 30, 37, 38, 39, 40, 41, 42, 43], [2, 30]), o($Vf, [2, 6]), { 5: [1, 47], 12: [1, 46] }, o($Vf, [2, 11]), { 5: [1, 48] }, { 5: [1, 49] }, o($Vf, [2, 14]), { 5: [1, 50] }, { 5: [2, 37] }, o($Vh, $V3, { 7: 51 }), o($Vh, $V3, { 7: 52 }), o([4, 5, 10, 15, 16, 18, 20, 22, 23, 24, 25, 36], $V3, { 7: 53 }), { 11: 56, 34: [1, 54], 35: [1, 55], 36: $Ve }, o($Vi, [2, 31]), o($Vi, [2, 32]), o($Vi, [2, 33]), o($Vi, [2, 34]), o($Vi, [2, 35]), o($Vi, [2, 36]), { 11: 57, 36: $Ve }, { 11: 59, 28: 58, 36: $Ve }, { 36: [2, 25] }, { 36: [2, 26] }, { 13: [1, 60] }, o($Vf, [2, 10]), o($Vf, [2, 12]), o($Vf, [2, 13]), o($Vf, [2, 15]), { 4: $V4, 5: $V5, 8: 8, 9: 10, 10: $V6, 11: 21, 14: 13, 15: $V7, 16: $V8, 17: 16, 18: $V9, 20: $Va, 21: [1, 61], 22: $Vb, 23: $Vc, 25: $Vd, 36: $Ve }, { 4: $V4, 5: $V5, 8: 8, 9: 10, 10: $V6, 11: 21, 14: 13, 15: $V7, 16: $V8, 17: 16, 18: $V9, 20: $Va, 21: [1, 62], 22: $Vb, 23: $Vc, 25: $Vd, 36: $Ve }, { 4: $V4, 5: $V5, 8: 8, 9: 10, 10: $V6, 11: 21, 14: 13, 15: $V7, 16: $V8, 17: 16, 18: $V9, 20: $Va, 22: $Vb, 23: $Vc, 24: [1, 63], 25: $Vd, 36: $Ve }, { 11: 64, 36: $Ve }, { 11: 65, 36: $Ve }, { 19: 66, 43: $Vg }, { 19: 67, 43: $Vg }, { 19: 68, 43: $Vg }, { 30: [1, 69], 43: [2, 24] }, { 5: [1, 70] }, o($Vf, [2, 16]), o($Vf, [2, 17]), { 13: [1, 71] }, { 19: 72, 43: $Vg }, { 19: 73, 43: $Vg }, { 5: [2, 29] }, { 5: [2, 19] }, { 5: [2, 20] }, { 11: 74, 36: $Ve }, o($Vf, [2, 9]), o($Vh, $V3, { 7: 75 }), { 5: [2, 27] }, { 5: [2, 28] }, { 43: [2, 23] }, { 4: $V4, 5: $V5, 8: 8, 9: 10, 10: $V6, 11: 21, 14: 13, 15: $V7, 16: $V8, 17: 16, 18: $V9, 20: $Va, 21: [1, 76], 22: $Vb, 23: $Vc, 25: $Vd, 36: $Ve }, o($Vf, [2, 18])],
  42779. defaultActions: { 5: [2, 1], 6: [2, 2], 31: [2, 37], 44: [2, 25], 45: [2, 26], 66: [2, 29], 67: [2, 19], 68: [2, 20], 72: [2, 27], 73: [2, 28], 74: [2, 23] },
  42780. parseError: function parseError(str, hash) {
  42781. if (hash.recoverable) {
  42782. this.trace(str);
  42783. } else {
  42784. var _parseError = function _parseError(msg, hash) {
  42785. this.message = msg;
  42786. this.hash = hash;
  42787. };
  42788. _parseError.prototype = Error;
  42789. throw new _parseError(str, hash);
  42790. }
  42791. },
  42792. parse: function parse(input) {
  42793. var self = this,
  42794. stack = [0],
  42795. tstack = [],
  42796. vstack = [null],
  42797. lstack = [],
  42798. table = this.table,
  42799. yytext = '',
  42800. yylineno = 0,
  42801. yyleng = 0,
  42802. recovering = 0,
  42803. TERROR = 2,
  42804. EOF = 1;
  42805. var args = lstack.slice.call(arguments, 1);
  42806. var lexer = Object.create(this.lexer);
  42807. var sharedState = { yy: {} };
  42808. for (var k in this.yy) {
  42809. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  42810. sharedState.yy[k] = this.yy[k];
  42811. }
  42812. }
  42813. lexer.setInput(input, sharedState.yy);
  42814. sharedState.yy.lexer = lexer;
  42815. sharedState.yy.parser = this;
  42816. if (typeof lexer.yylloc == 'undefined') {
  42817. lexer.yylloc = {};
  42818. }
  42819. var yyloc = lexer.yylloc;
  42820. lstack.push(yyloc);
  42821. var ranges = lexer.options && lexer.options.ranges;
  42822. if (typeof sharedState.yy.parseError === 'function') {
  42823. this.parseError = sharedState.yy.parseError;
  42824. } else {
  42825. this.parseError = Object.getPrototypeOf(this).parseError;
  42826. }
  42827. function popStack(n) {
  42828. stack.length = stack.length - 2 * n;
  42829. vstack.length = vstack.length - n;
  42830. lstack.length = lstack.length - n;
  42831. }
  42832. _token_stack: var lex = function lex() {
  42833. var token;
  42834. token = lexer.lex() || EOF;
  42835. if (typeof token !== 'number') {
  42836. token = self.symbols_[token] || token;
  42837. }
  42838. return token;
  42839. };
  42840. var symbol,
  42841. preErrorSymbol,
  42842. state,
  42843. action,
  42844. a,
  42845. r,
  42846. yyval = {},
  42847. p,
  42848. len,
  42849. newState,
  42850. expected;
  42851. while (true) {
  42852. state = stack[stack.length - 1];
  42853. if (this.defaultActions[state]) {
  42854. action = this.defaultActions[state];
  42855. } else {
  42856. if (symbol === null || typeof symbol == 'undefined') {
  42857. symbol = lex();
  42858. }
  42859. action = table[state] && table[state][symbol];
  42860. }
  42861. if (typeof action === 'undefined' || !action.length || !action[0]) {
  42862. var errStr = '';
  42863. expected = [];
  42864. for (p in table[state]) {
  42865. if (this.terminals_[p] && p > TERROR) {
  42866. expected.push('\'' + this.terminals_[p] + '\'');
  42867. }
  42868. }
  42869. if (lexer.showPosition) {
  42870. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  42871. } else {
  42872. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  42873. }
  42874. this.parseError(errStr, {
  42875. text: lexer.match,
  42876. token: this.terminals_[symbol] || symbol,
  42877. line: lexer.yylineno,
  42878. loc: yyloc,
  42879. expected: expected
  42880. });
  42881. }
  42882. if (action[0] instanceof Array && action.length > 1) {
  42883. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  42884. }
  42885. switch (action[0]) {
  42886. case 1:
  42887. stack.push(symbol);
  42888. vstack.push(lexer.yytext);
  42889. lstack.push(lexer.yylloc);
  42890. stack.push(action[1]);
  42891. symbol = null;
  42892. if (!preErrorSymbol) {
  42893. yyleng = lexer.yyleng;
  42894. yytext = lexer.yytext;
  42895. yylineno = lexer.yylineno;
  42896. yyloc = lexer.yylloc;
  42897. if (recovering > 0) {
  42898. recovering--;
  42899. }
  42900. } else {
  42901. symbol = preErrorSymbol;
  42902. preErrorSymbol = null;
  42903. }
  42904. break;
  42905. case 2:
  42906. len = this.productions_[action[1]][1];
  42907. yyval.$ = vstack[vstack.length - len];
  42908. yyval._$ = {
  42909. first_line: lstack[lstack.length - (len || 1)].first_line,
  42910. last_line: lstack[lstack.length - 1].last_line,
  42911. first_column: lstack[lstack.length - (len || 1)].first_column,
  42912. last_column: lstack[lstack.length - 1].last_column
  42913. };
  42914. if (ranges) {
  42915. yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
  42916. }
  42917. r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
  42918. if (typeof r !== 'undefined') {
  42919. return r;
  42920. }
  42921. if (len) {
  42922. stack = stack.slice(0, -1 * len * 2);
  42923. vstack = vstack.slice(0, -1 * len);
  42924. lstack = lstack.slice(0, -1 * len);
  42925. }
  42926. stack.push(this.productions_[action[1]][0]);
  42927. vstack.push(yyval.$);
  42928. lstack.push(yyval._$);
  42929. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  42930. stack.push(newState);
  42931. break;
  42932. case 3:
  42933. return true;
  42934. }
  42935. }
  42936. return true;
  42937. } };
  42938. /* generated by jison-lex 0.3.4 */
  42939. var lexer = (function () {
  42940. var lexer = {
  42941. EOF: 1,
  42942. parseError: function parseError(str, hash) {
  42943. if (this.yy.parser) {
  42944. this.yy.parser.parseError(str, hash);
  42945. } else {
  42946. throw new Error(str);
  42947. }
  42948. },
  42949. // resets the lexer, sets new input
  42950. setInput: function setInput(input, yy) {
  42951. this.yy = yy || this.yy || {};
  42952. this._input = input;
  42953. this._more = this._backtrack = this.done = false;
  42954. this.yylineno = this.yyleng = 0;
  42955. this.yytext = this.matched = this.match = '';
  42956. this.conditionStack = ['INITIAL'];
  42957. this.yylloc = {
  42958. first_line: 1,
  42959. first_column: 0,
  42960. last_line: 1,
  42961. last_column: 0
  42962. };
  42963. if (this.options.ranges) {
  42964. this.yylloc.range = [0, 0];
  42965. }
  42966. this.offset = 0;
  42967. return this;
  42968. },
  42969. // consumes and returns one char from the input
  42970. input: function input() {
  42971. var ch = this._input[0];
  42972. this.yytext += ch;
  42973. this.yyleng++;
  42974. this.offset++;
  42975. this.match += ch;
  42976. this.matched += ch;
  42977. var lines = ch.match(/(?:\r\n?|\n).*/g);
  42978. if (lines) {
  42979. this.yylineno++;
  42980. this.yylloc.last_line++;
  42981. } else {
  42982. this.yylloc.last_column++;
  42983. }
  42984. if (this.options.ranges) {
  42985. this.yylloc.range[1]++;
  42986. }
  42987. this._input = this._input.slice(1);
  42988. return ch;
  42989. },
  42990. // unshifts one char (or a string) into the input
  42991. unput: function unput(ch) {
  42992. var len = ch.length;
  42993. var lines = ch.split(/(?:\r\n?|\n)/g);
  42994. this._input = ch + this._input;
  42995. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  42996. //this.yyleng -= len;
  42997. this.offset -= len;
  42998. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  42999. this.match = this.match.substr(0, this.match.length - 1);
  43000. this.matched = this.matched.substr(0, this.matched.length - 1);
  43001. if (lines.length - 1) {
  43002. this.yylineno -= lines.length - 1;
  43003. }
  43004. var r = this.yylloc.range;
  43005. this.yylloc = {
  43006. first_line: this.yylloc.first_line,
  43007. last_line: this.yylineno + 1,
  43008. first_column: this.yylloc.first_column,
  43009. last_column: lines ? (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length : this.yylloc.first_column - len
  43010. };
  43011. if (this.options.ranges) {
  43012. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  43013. }
  43014. this.yyleng = this.yytext.length;
  43015. return this;
  43016. },
  43017. // When called from action, caches matched text and appends it on next action
  43018. more: function more() {
  43019. this._more = true;
  43020. return this;
  43021. },
  43022. // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
  43023. reject: function reject() {
  43024. if (this.options.backtrack_lexer) {
  43025. this._backtrack = true;
  43026. } else {
  43027. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), {
  43028. text: "",
  43029. token: null,
  43030. line: this.yylineno
  43031. });
  43032. }
  43033. return this;
  43034. },
  43035. // retain first n characters of the match
  43036. less: function less(n) {
  43037. this.unput(this.match.slice(n));
  43038. },
  43039. // displays already matched input, i.e. for error messages
  43040. pastInput: function pastInput() {
  43041. var past = this.matched.substr(0, this.matched.length - this.match.length);
  43042. return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
  43043. },
  43044. // displays upcoming input, i.e. for error messages
  43045. upcomingInput: function upcomingInput() {
  43046. var next = this.match;
  43047. if (next.length < 20) {
  43048. next += this._input.substr(0, 20 - next.length);
  43049. }
  43050. return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  43051. },
  43052. // displays the character position where the lexing error occurred, i.e. for error messages
  43053. showPosition: function showPosition() {
  43054. var pre = this.pastInput();
  43055. var c = new Array(pre.length + 1).join("-");
  43056. return pre + this.upcomingInput() + "\n" + c + "^";
  43057. },
  43058. // test the lexed token: return FALSE when not a match, otherwise return token
  43059. test_match: function test_match(match, indexed_rule) {
  43060. var token, lines, backup;
  43061. if (this.options.backtrack_lexer) {
  43062. // save context
  43063. backup = {
  43064. yylineno: this.yylineno,
  43065. yylloc: {
  43066. first_line: this.yylloc.first_line,
  43067. last_line: this.last_line,
  43068. first_column: this.yylloc.first_column,
  43069. last_column: this.yylloc.last_column
  43070. },
  43071. yytext: this.yytext,
  43072. match: this.match,
  43073. matches: this.matches,
  43074. matched: this.matched,
  43075. yyleng: this.yyleng,
  43076. offset: this.offset,
  43077. _more: this._more,
  43078. _input: this._input,
  43079. yy: this.yy,
  43080. conditionStack: this.conditionStack.slice(0),
  43081. done: this.done
  43082. };
  43083. if (this.options.ranges) {
  43084. backup.yylloc.range = this.yylloc.range.slice(0);
  43085. }
  43086. }
  43087. lines = match[0].match(/(?:\r\n?|\n).*/g);
  43088. if (lines) {
  43089. this.yylineno += lines.length;
  43090. }
  43091. this.yylloc = {
  43092. first_line: this.yylloc.last_line,
  43093. last_line: this.yylineno + 1,
  43094. first_column: this.yylloc.last_column,
  43095. last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
  43096. };
  43097. this.yytext += match[0];
  43098. this.match += match[0];
  43099. this.matches = match;
  43100. this.yyleng = this.yytext.length;
  43101. if (this.options.ranges) {
  43102. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  43103. }
  43104. this._more = false;
  43105. this._backtrack = false;
  43106. this._input = this._input.slice(match[0].length);
  43107. this.matched += match[0];
  43108. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  43109. if (this.done && this._input) {
  43110. this.done = false;
  43111. }
  43112. if (token) {
  43113. return token;
  43114. } else if (this._backtrack) {
  43115. // recover context
  43116. for (var k in backup) {
  43117. this[k] = backup[k];
  43118. }
  43119. return false; // rule action called reject() implying the next rule should be tested instead.
  43120. }
  43121. return false;
  43122. },
  43123. // return next match in input
  43124. next: function next() {
  43125. if (this.done) {
  43126. return this.EOF;
  43127. }
  43128. if (!this._input) {
  43129. this.done = true;
  43130. }
  43131. var token, match, tempMatch, index;
  43132. if (!this._more) {
  43133. this.yytext = '';
  43134. this.match = '';
  43135. }
  43136. var rules = this._currentRules();
  43137. for (var i = 0; i < rules.length; i++) {
  43138. tempMatch = this._input.match(this.rules[rules[i]]);
  43139. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  43140. match = tempMatch;
  43141. index = i;
  43142. if (this.options.backtrack_lexer) {
  43143. token = this.test_match(tempMatch, rules[i]);
  43144. if (token !== false) {
  43145. return token;
  43146. } else if (this._backtrack) {
  43147. match = false;
  43148. continue; // rule action called reject() implying a rule MISmatch.
  43149. } else {
  43150. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  43151. return false;
  43152. }
  43153. } else if (!this.options.flex) {
  43154. break;
  43155. }
  43156. }
  43157. }
  43158. if (match) {
  43159. token = this.test_match(match, rules[index]);
  43160. if (token !== false) {
  43161. return token;
  43162. }
  43163. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  43164. return false;
  43165. }
  43166. if (this._input === "") {
  43167. return this.EOF;
  43168. } else {
  43169. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  43170. text: "",
  43171. token: null,
  43172. line: this.yylineno
  43173. });
  43174. }
  43175. },
  43176. // return next match that has a token
  43177. lex: function lex() {
  43178. var r = this.next();
  43179. if (r) {
  43180. return r;
  43181. } else {
  43182. return this.lex();
  43183. }
  43184. },
  43185. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  43186. begin: function begin(condition) {
  43187. this.conditionStack.push(condition);
  43188. },
  43189. // pop the previously active lexer condition state off the condition stack
  43190. popState: function popState() {
  43191. var n = this.conditionStack.length - 1;
  43192. if (n > 0) {
  43193. return this.conditionStack.pop();
  43194. } else {
  43195. return this.conditionStack[0];
  43196. }
  43197. },
  43198. // produce the lexer rule set which is active for the currently active lexer condition state
  43199. _currentRules: function _currentRules() {
  43200. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  43201. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  43202. } else {
  43203. return this.conditions["INITIAL"].rules;
  43204. }
  43205. },
  43206. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  43207. topState: function topState(n) {
  43208. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  43209. if (n >= 0) {
  43210. return this.conditionStack[n];
  43211. } else {
  43212. return "INITIAL";
  43213. }
  43214. },
  43215. // alias for begin(condition)
  43216. pushState: function pushState(condition) {
  43217. this.begin(condition);
  43218. },
  43219. // return the number of states currently on the stack
  43220. stateStackSize: function stateStackSize() {
  43221. return this.conditionStack.length;
  43222. },
  43223. options: { "case-insensitive": true },
  43224. performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
  43225. var YYSTATE = YY_START;
  43226. switch ($avoiding_name_collisions) {
  43227. case 0:
  43228. return 5;
  43229. break;
  43230. case 1:
  43231. /* skip all whitespace */
  43232. break;
  43233. case 2:
  43234. /* skip same-line whitespace */
  43235. break;
  43236. case 3:
  43237. /* skip comments */
  43238. break;
  43239. case 4:
  43240. /* skip comments */
  43241. break;
  43242. case 5:
  43243. this.begin('ID');return 10;
  43244. break;
  43245. case 6:
  43246. this.begin('ALIAS');return 36;
  43247. break;
  43248. case 7:
  43249. this.popState();this.popState();this.begin('LINE');return 12;
  43250. break;
  43251. case 8:
  43252. this.popState();this.popState();return 5;
  43253. break;
  43254. case 9:
  43255. this.begin('LINE');return 20;
  43256. break;
  43257. case 10:
  43258. this.begin('LINE');return 22;
  43259. break;
  43260. case 11:
  43261. this.begin('LINE');return 23;
  43262. break;
  43263. case 12:
  43264. this.begin('LINE');return 24;
  43265. break;
  43266. case 13:
  43267. this.popState();return 13;
  43268. break;
  43269. case 14:
  43270. return 21;
  43271. break;
  43272. case 15:
  43273. return 31;
  43274. break;
  43275. case 16:
  43276. return 32;
  43277. break;
  43278. case 17:
  43279. return 27;
  43280. break;
  43281. case 18:
  43282. return 25;
  43283. break;
  43284. case 19:
  43285. this.begin('ID');return 15;
  43286. break;
  43287. case 20:
  43288. this.begin('ID');return 16;
  43289. break;
  43290. case 21:
  43291. return 18;
  43292. break;
  43293. case 22:
  43294. return 6;
  43295. break;
  43296. case 23:
  43297. return 30;
  43298. break;
  43299. case 24:
  43300. return 5;
  43301. break;
  43302. case 25:
  43303. yy_.yytext = yy_.yytext.trim();return 36;
  43304. break;
  43305. case 26:
  43306. return 39;
  43307. break;
  43308. case 27:
  43309. return 40;
  43310. break;
  43311. case 28:
  43312. return 37;
  43313. break;
  43314. case 29:
  43315. return 38;
  43316. break;
  43317. case 30:
  43318. return 41;
  43319. break;
  43320. case 31:
  43321. return 42;
  43322. break;
  43323. case 32:
  43324. return 43;
  43325. break;
  43326. case 33:
  43327. return 34;
  43328. break;
  43329. case 34:
  43330. return 35;
  43331. break;
  43332. case 35:
  43333. return 5;
  43334. break;
  43335. case 36:
  43336. return 'INVALID';
  43337. break;
  43338. }
  43339. },
  43340. rules: [/^(?:[\n]+)/i, /^(?:\s+)/i, /^(?:((?!\n)\s)+)/i, /^(?:#[^\n]*)/i, /^(?:%[^\n]*)/i, /^(?:participant\b)/i, /^(?:[^\->:\n,;]+?(?=((?!\n)\s)+as(?!\n)\s|[#\n;]|$))/i, /^(?:as\b)/i, /^(?:(?:))/i, /^(?:loop\b)/i, /^(?:opt\b)/i, /^(?:alt\b)/i, /^(?:else\b)/i, /^(?:[^#\n;]*)/i, /^(?:end\b)/i, /^(?:left of\b)/i, /^(?:right of\b)/i, /^(?:over\b)/i, /^(?:note\b)/i, /^(?:activate\b)/i, /^(?:deactivate\b)/i, /^(?:title\b)/i, /^(?:sequenceDiagram\b)/i, /^(?:,)/i, /^(?:;)/i, /^(?:[^\+\->:\n,;]+)/i, /^(?:->>)/i, /^(?:-->>)/i, /^(?:->)/i, /^(?:-->)/i, /^(?:-[x])/i, /^(?:--[x])/i, /^(?::[^#\n;]+)/i, /^(?:\+)/i, /^(?:-)/i, /^(?:$)/i, /^(?:.)/i],
  43341. conditions: { "LINE": { "rules": [2, 3, 13], "inclusive": false }, "ALIAS": { "rules": [2, 3, 7, 8], "inclusive": false }, "ID": { "rules": [2, 3, 6], "inclusive": false }, "INITIAL": { "rules": [0, 1, 3, 4, 5, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36], "inclusive": true } }
  43342. };
  43343. return lexer;
  43344. })();
  43345. parser.lexer = lexer;
  43346. function Parser() {
  43347. this.yy = {};
  43348. }
  43349. Parser.prototype = parser;parser.Parser = Parser;
  43350. return new Parser();
  43351. })();
  43352. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  43353. exports.parser = parser;
  43354. exports.Parser = parser.Parser;
  43355. exports.parse = function () {
  43356. return parser.parse.apply(parser, arguments);
  43357. };
  43358. exports.main = function commonjsMain(args) {
  43359. if (!args[1]) {
  43360. console.log('Usage: ' + args[0] + ' FILE');
  43361. process.exit(1);
  43362. }
  43363. var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
  43364. return exports.parser.parse(source);
  43365. };
  43366. if (typeof module !== 'undefined' && require.main === module) {
  43367. exports.main(process.argv.slice(1));
  43368. }
  43369. }
  43370. }).call(this,require('_process'))
  43371. },{"_process":105,"fs":1,"path":104}],126:[function(require,module,exports){
  43372. (function (global){
  43373. /**
  43374. * Created by knut on 14-11-19.
  43375. */
  43376. 'use strict';
  43377. var actors = {};
  43378. var messages = [];
  43379. var notes = [];
  43380. var title = '';
  43381. var Logger = require('../../logger');
  43382. var log = new Logger.Log();
  43383. exports.addActor = function (id, name, description) {
  43384. // Don't allow description nulling
  43385. var old = actors[id];
  43386. if (old && name === old.name && description == null) return;
  43387. // Don't allow null descriptions, either
  43388. if (description == null) description = name;
  43389. actors[id] = { name: name, description: description };
  43390. };
  43391. exports.addMessage = function (idFrom, idTo, message, answer) {
  43392. messages.push({ from: idFrom, to: idTo, message: message, answer: answer });
  43393. };
  43394. /**
  43395. *
  43396. */
  43397. exports.addSignal = function (idFrom, idTo, message, messageType) {
  43398. log.debug('Adding message from=' + idFrom + ' to=' + idTo + ' message=' + message + ' type=' + messageType);
  43399. messages.push({ from: idFrom, to: idTo, message: message, type: messageType });
  43400. };
  43401. exports.getMessages = function () {
  43402. return messages;
  43403. };
  43404. exports.getActors = function () {
  43405. return actors;
  43406. };
  43407. exports.getActor = function (id) {
  43408. return actors[id];
  43409. };
  43410. exports.getActorKeys = function () {
  43411. return Object.keys(actors);
  43412. };
  43413. exports.getTitle = function () {
  43414. return title;
  43415. };
  43416. exports.clear = function () {
  43417. actors = {};
  43418. messages = [];
  43419. };
  43420. exports.LINETYPE = {
  43421. SOLID: 0,
  43422. DOTTED: 1,
  43423. NOTE: 2,
  43424. SOLID_CROSS: 3,
  43425. DOTTED_CROSS: 4,
  43426. SOLID_OPEN: 5,
  43427. DOTTED_OPEN: 6,
  43428. LOOP_START: 10,
  43429. LOOP_END: 11,
  43430. ALT_START: 12,
  43431. ALT_ELSE: 13,
  43432. ALT_END: 14,
  43433. OPT_START: 15,
  43434. OPT_END: 16,
  43435. ACTIVE_START: 17,
  43436. ACTIVE_END: 18
  43437. };
  43438. exports.ARROWTYPE = {
  43439. FILLED: 0,
  43440. OPEN: 1
  43441. };
  43442. exports.PLACEMENT = {
  43443. LEFTOF: 0,
  43444. RIGHTOF: 1,
  43445. OVER: 2
  43446. };
  43447. exports.addNote = function (actor, placement, message) {
  43448. var note = { actor: actor, placement: placement, message: message };
  43449. // Coerce actor into a [to, from, ...] array
  43450. var actors = [].concat(actor, actor);
  43451. notes.push(note);
  43452. messages.push({ from: actors[0], to: actors[1], message: message, type: exports.LINETYPE.NOTE, placement: placement });
  43453. };
  43454. exports.setTitle = function (titleText) {
  43455. title = titleText;
  43456. };
  43457. exports.parseError = function (err, hash) {
  43458. global.mermaidAPI.parseError(err, hash);
  43459. };
  43460. exports.apply = function (param) {
  43461. if (param instanceof Array) {
  43462. param.forEach(function (item) {
  43463. exports.apply(item);
  43464. });
  43465. } else {
  43466. // console.info(param);
  43467. switch (param.type) {
  43468. case 'addActor':
  43469. exports.addActor(param.actor, param.actor, param.description);
  43470. break;
  43471. case 'activeStart':
  43472. exports.addSignal(param.actor, undefined, undefined, param.signalType);
  43473. break;
  43474. case 'activeEnd':
  43475. exports.addSignal(param.actor, undefined, undefined, param.signalType);
  43476. break;
  43477. case 'addNote':
  43478. exports.addNote(param.actor, param.placement, param.text);
  43479. break;
  43480. case 'addMessage':
  43481. exports.addSignal(param.from, param.to, param.msg, param.signalType);
  43482. break;
  43483. case 'loopStart':
  43484. //log.debug('Loop text: ',param.loopText);
  43485. exports.addSignal(undefined, undefined, param.loopText, param.signalType);
  43486. //yy.addSignal(undefined, undefined, $2, yy.LINETYPE.LOOP_START);
  43487. break;
  43488. case 'loopEnd':
  43489. exports.addSignal(undefined, undefined, undefined, param.signalType);
  43490. break;
  43491. case 'optStart':
  43492. //log.debug('Loop text: ',param.loopText);
  43493. exports.addSignal(undefined, undefined, param.optText, param.signalType);
  43494. //yy.addSignal(undefined, undefined, $2, yy.LINETYPE.LOOP_START);
  43495. break;
  43496. case 'optEnd':
  43497. exports.addSignal(undefined, undefined, undefined, param.signalType);
  43498. break;
  43499. case 'altStart':
  43500. //log.debug('Loop text: ',param.loopText);
  43501. exports.addSignal(undefined, undefined, param.altText, param.signalType);
  43502. //yy.addSignal(undefined, undefined, $2, yy.LINETYPE.LOOP_START);
  43503. break;
  43504. case 'else':
  43505. exports.addSignal(undefined, undefined, param.altText, param.signalType);
  43506. break;
  43507. case 'altEnd':
  43508. exports.addSignal(undefined, undefined, undefined, param.signalType);
  43509. break;
  43510. case 'setTitle':
  43511. exports.setTitle(param.text);
  43512. }
  43513. }
  43514. };
  43515. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  43516. },{"../../logger":129}],127:[function(require,module,exports){
  43517. /**
  43518. * Created by knut on 14-11-23.
  43519. */
  43520. 'use strict';
  43521. var sq = require('./parser/sequenceDiagram').parser;
  43522. sq.yy = require('./sequenceDb');
  43523. var svgDraw = require('./svgDraw');
  43524. var d3 = require('../../d3');
  43525. var Logger = require('../../logger');
  43526. var log = new Logger.Log();
  43527. var conf = {
  43528. diagramMarginX: 50,
  43529. diagramMarginY: 30,
  43530. // Margin between actors
  43531. actorMargin: 50,
  43532. // Width of actor boxes
  43533. width: 150,
  43534. // Height of actor boxes
  43535. height: 65,
  43536. // Margin around loop boxes
  43537. boxMargin: 10,
  43538. boxTextMargin: 5,
  43539. noteMargin: 10,
  43540. // Space between messages
  43541. messageMargin: 35,
  43542. //mirror actors under diagram
  43543. mirrorActors: false,
  43544. // Depending on css styling this might need adjustment
  43545. // Prolongs the edge of the diagram downwards
  43546. bottomMarginAdj: 1,
  43547. // width of activation box
  43548. activationWidth: 10,
  43549. //text placement as: tspan | fo | old only text as before
  43550. textPlacement: 'tspan'
  43551. };
  43552. exports.bounds = {
  43553. data: {
  43554. startx: undefined,
  43555. stopx: undefined,
  43556. starty: undefined,
  43557. stopy: undefined
  43558. },
  43559. verticalPos: 0,
  43560. sequenceItems: [],
  43561. activations: [],
  43562. init: function init() {
  43563. this.sequenceItems = [];
  43564. this.activations = [];
  43565. this.data = {
  43566. startx: undefined,
  43567. stopx: undefined,
  43568. starty: undefined,
  43569. stopy: undefined
  43570. };
  43571. this.verticalPos = 0;
  43572. },
  43573. updateVal: function updateVal(obj, key, val, fun) {
  43574. if (typeof obj[key] === 'undefined') {
  43575. obj[key] = val;
  43576. } else {
  43577. obj[key] = fun(val, obj[key]);
  43578. }
  43579. },
  43580. updateBounds: function updateBounds(startx, starty, stopx, stopy) {
  43581. var _self = this;
  43582. var cnt = 0;
  43583. function updateFn(type) {
  43584. return function updateItemBounds(item) {
  43585. cnt++;
  43586. // The loop sequenceItems is a stack so the biggest margins in the beginning of the sequenceItems
  43587. var n = _self.sequenceItems.length - cnt + 1;
  43588. _self.updateVal(item, 'starty', starty - n * conf.boxMargin, Math.min);
  43589. _self.updateVal(item, 'stopy', stopy + n * conf.boxMargin, Math.max);
  43590. _self.updateVal(exports.bounds.data, 'startx', startx - n * conf.boxMargin, Math.min);
  43591. _self.updateVal(exports.bounds.data, 'stopx', stopx + n * conf.boxMargin, Math.max);
  43592. if (!(type == 'activation')) {
  43593. _self.updateVal(item, 'startx', startx - n * conf.boxMargin, Math.min);
  43594. _self.updateVal(item, 'stopx', stopx + n * conf.boxMargin, Math.max);
  43595. _self.updateVal(exports.bounds.data, 'starty', starty - n * conf.boxMargin, Math.min);
  43596. _self.updateVal(exports.bounds.data, 'stopy', stopy + n * conf.boxMargin, Math.max);
  43597. }
  43598. };
  43599. }
  43600. this.sequenceItems.forEach(updateFn());
  43601. this.activations.forEach(updateFn('activation'));
  43602. },
  43603. insert: function insert(startx, starty, stopx, stopy) {
  43604. var _startx, _starty, _stopx, _stopy;
  43605. _startx = Math.min(startx, stopx);
  43606. _stopx = Math.max(startx, stopx);
  43607. _starty = Math.min(starty, stopy);
  43608. _stopy = Math.max(starty, stopy);
  43609. this.updateVal(exports.bounds.data, 'startx', _startx, Math.min);
  43610. this.updateVal(exports.bounds.data, 'starty', _starty, Math.min);
  43611. this.updateVal(exports.bounds.data, 'stopx', _stopx, Math.max);
  43612. this.updateVal(exports.bounds.data, 'stopy', _stopy, Math.max);
  43613. this.updateBounds(_startx, _starty, _stopx, _stopy);
  43614. },
  43615. newActivation: function newActivation(message, diagram) {
  43616. var actorRect = sq.yy.getActors()[message.from.actor];
  43617. var stackedSize = actorActivations(message.from.actor).length;
  43618. var x = actorRect.x + conf.width / 2 + (stackedSize - 1) * conf.activationWidth / 2;
  43619. this.activations.push({ startx: x, starty: this.verticalPos + 2, stopx: x + conf.activationWidth, stopy: undefined,
  43620. actor: message.from.actor,
  43621. anchored: svgDraw.anchorElement(diagram)
  43622. });
  43623. },
  43624. endActivation: function endActivation(message) {
  43625. // find most recent activation for given actor
  43626. var lastActorActivationIdx = this.activations.map(function (activation) {
  43627. return activation.actor;
  43628. }).lastIndexOf(message.from.actor);
  43629. var activation = this.activations.splice(lastActorActivationIdx, 1)[0];
  43630. return activation;
  43631. },
  43632. newLoop: function newLoop(title) {
  43633. this.sequenceItems.push({ startx: undefined, starty: this.verticalPos, stopx: undefined, stopy: undefined, title: title });
  43634. },
  43635. endLoop: function endLoop() {
  43636. var loop = this.sequenceItems.pop();
  43637. return loop;
  43638. },
  43639. addElseToLoop: function addElseToLoop(message) {
  43640. var loop = this.sequenceItems.pop();
  43641. loop.elsey = exports.bounds.getVerticalPos();
  43642. loop.elseText = message;
  43643. this.sequenceItems.push(loop);
  43644. },
  43645. bumpVerticalPos: function bumpVerticalPos(bump) {
  43646. this.verticalPos = this.verticalPos + bump;
  43647. this.data.stopy = this.verticalPos;
  43648. },
  43649. getVerticalPos: function getVerticalPos() {
  43650. return this.verticalPos;
  43651. },
  43652. getBounds: function getBounds() {
  43653. return this.data;
  43654. }
  43655. };
  43656. /**
  43657. * Draws an actor in the diagram with the attaced line
  43658. * @param center - The center of the the actor
  43659. * @param pos The position if the actor in the liost of actors
  43660. * @param description The text in the box
  43661. */
  43662. var drawNote = function drawNote(elem, startx, verticalPos, msg, forceWidth) {
  43663. var rect = svgDraw.getNoteRect();
  43664. rect.x = startx;
  43665. rect.y = verticalPos;
  43666. rect.width = forceWidth || conf.width;
  43667. rect['class'] = 'note';
  43668. var g = elem.append('g');
  43669. var rectElem = svgDraw.drawRect(g, rect);
  43670. var textObj = svgDraw.getTextObj();
  43671. textObj.x = startx - 4;
  43672. textObj.y = verticalPos - 13;
  43673. textObj.textMargin = conf.noteMargin;
  43674. textObj.dy = '1em';
  43675. textObj.text = msg.message;
  43676. textObj['class'] = 'noteText';
  43677. var textElem = svgDraw.drawText(g, textObj, rect.width - conf.noteMargin);
  43678. var textHeight = textElem[0][0].getBBox().height;
  43679. if (!forceWidth && textHeight > conf.width) {
  43680. textElem.remove();
  43681. g = elem.append('g');
  43682. textElem = svgDraw.drawText(g, textObj, 2 * rect.width - conf.noteMargin);
  43683. textHeight = textElem[0][0].getBBox().height;
  43684. rectElem.attr('width', 2 * rect.width);
  43685. exports.bounds.insert(startx, verticalPos, startx + 2 * rect.width, verticalPos + 2 * conf.noteMargin + textHeight);
  43686. } else {
  43687. exports.bounds.insert(startx, verticalPos, startx + rect.width, verticalPos + 2 * conf.noteMargin + textHeight);
  43688. }
  43689. rectElem.attr('height', textHeight + 2 * conf.noteMargin);
  43690. exports.bounds.bumpVerticalPos(textHeight + 2 * conf.noteMargin);
  43691. };
  43692. /**
  43693. * Draws a message
  43694. * @param elem
  43695. * @param startx
  43696. * @param stopx
  43697. * @param verticalPos
  43698. * @param txtCenter
  43699. * @param msg
  43700. */
  43701. var drawMessage = function drawMessage(elem, startx, stopx, verticalPos, msg) {
  43702. var g = elem.append('g');
  43703. var txtCenter = startx + (stopx - startx) / 2;
  43704. var textElem = g.append('text') // text label for the x axis
  43705. .attr('x', txtCenter).attr('y', verticalPos - 7).style('text-anchor', 'middle').attr('class', 'messageText').text(msg.message);
  43706. var textWidth;
  43707. if (typeof textElem[0][0].getBBox !== 'undefined') {
  43708. textWidth = textElem[0][0].getBBox().width;
  43709. } else {
  43710. //textWidth = getBBox(textElem).width; //.getComputedTextLength()
  43711. textWidth = textElem[0][0].getBoundingClientRect();
  43712. //textWidth = textElem[0][0].getComputedTextLength();
  43713. }
  43714. var line;
  43715. if (startx === stopx) {
  43716. line = g.append('path').attr('d', 'M ' + startx + ',' + verticalPos + ' C ' + (startx + 60) + ',' + (verticalPos - 10) + ' ' + (startx + 60) + ',' + (verticalPos + 30) + ' ' + startx + ',' + (verticalPos + 20));
  43717. exports.bounds.bumpVerticalPos(30);
  43718. var dx = Math.max(textWidth / 2, 100);
  43719. exports.bounds.insert(startx - dx, exports.bounds.getVerticalPos() - 10, stopx + dx, exports.bounds.getVerticalPos());
  43720. } else {
  43721. line = g.append('line');
  43722. line.attr('x1', startx);
  43723. line.attr('y1', verticalPos);
  43724. line.attr('x2', stopx);
  43725. line.attr('y2', verticalPos);
  43726. exports.bounds.insert(startx, exports.bounds.getVerticalPos() - 10, stopx, exports.bounds.getVerticalPos());
  43727. }
  43728. //Make an SVG Container
  43729. //Draw the line
  43730. if (msg.type === sq.yy.LINETYPE.DOTTED || msg.type === sq.yy.LINETYPE.DOTTED_CROSS || msg.type === sq.yy.LINETYPE.DOTTED_OPEN) {
  43731. line.style('stroke-dasharray', '3, 3');
  43732. line.attr('class', 'messageLine1');
  43733. } else {
  43734. line.attr('class', 'messageLine0');
  43735. }
  43736. var url = '';
  43737. if (conf.arrowMarkerAbsolute) {
  43738. url = window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search;
  43739. url = url.replace(/\(/g, '\\(');
  43740. url = url.replace(/\)/g, '\\)');
  43741. }
  43742. line.attr('stroke-width', 2);
  43743. line.attr('stroke', 'black');
  43744. line.style('fill', 'none'); // remove any fill colour
  43745. if (msg.type === sq.yy.LINETYPE.SOLID || msg.type === sq.yy.LINETYPE.DOTTED) {
  43746. line.attr('marker-end', 'url(' + url + '#arrowhead)');
  43747. }
  43748. if (msg.type === sq.yy.LINETYPE.SOLID_CROSS || msg.type === sq.yy.LINETYPE.DOTTED_CROSS) {
  43749. line.attr('marker-end', 'url(' + url + '#crosshead)');
  43750. }
  43751. };
  43752. module.exports.drawActors = function (diagram, actors, actorKeys, verticalPos) {
  43753. var i;
  43754. // Draw the actors
  43755. for (i = 0; i < actorKeys.length; i++) {
  43756. var key = actorKeys[i];
  43757. // Add some rendering data to the object
  43758. actors[key].x = i * conf.actorMargin + i * conf.width;
  43759. actors[key].y = verticalPos;
  43760. actors[key].width = conf.diagramMarginX;
  43761. actors[key].height = conf.diagramMarginY;
  43762. // Draw the box with the attached line
  43763. svgDraw.drawActor(diagram, actors[key].x, verticalPos, actors[key].description, conf);
  43764. exports.bounds.insert(actors[key].x, verticalPos, actors[key].x + conf.width, conf.height);
  43765. }
  43766. // Add a margin between the actor boxes and the first arrow
  43767. //exports.bounds.bumpVerticalPos(conf.height+conf.messageMargin);
  43768. exports.bounds.bumpVerticalPos(conf.height);
  43769. };
  43770. module.exports.setConf = function (cnf) {
  43771. var keys = Object.keys(cnf);
  43772. keys.forEach(function (key) {
  43773. conf[key] = cnf[key];
  43774. });
  43775. };
  43776. var actorActivations = function actorActivations(actor) {
  43777. return module.exports.bounds.activations.filter(function (activation) {
  43778. return activation.actor == actor;
  43779. });
  43780. };
  43781. var actorFlowVerticaBounds = function actorFlowVerticaBounds(actor) {
  43782. // handle multiple stacked activations for same actor
  43783. var actors = sq.yy.getActors();
  43784. var activations = actorActivations(actor);
  43785. var left = activations.reduce(function (acc, activation) {
  43786. return Math.min(acc, activation.startx);
  43787. }, actors[actor].x + conf.width / 2);
  43788. var right = activations.reduce(function (acc, activation) {
  43789. return Math.max(acc, activation.stopx);
  43790. }, actors[actor].x + conf.width / 2);
  43791. return [left, right];
  43792. };
  43793. /**
  43794. * Draws a flowchart in the tag with id: id based on the graph definition in text.
  43795. * @param text
  43796. * @param id
  43797. */
  43798. module.exports.draw = function (text, id) {
  43799. sq.yy.clear();
  43800. sq.parse(text + '\n');
  43801. exports.bounds.init();
  43802. var diagram = d3.select('#' + id);
  43803. var startx;
  43804. var stopx;
  43805. var forceWidth;
  43806. // Fetch data from the parsing
  43807. var actors = sq.yy.getActors();
  43808. var actorKeys = sq.yy.getActorKeys();
  43809. var messages = sq.yy.getMessages();
  43810. var title = sq.yy.getTitle();
  43811. module.exports.drawActors(diagram, actors, actorKeys, 0);
  43812. // The arrow head definition is attached to the svg once
  43813. svgDraw.insertArrowHead(diagram);
  43814. svgDraw.insertArrowCrossHead(diagram);
  43815. function activeEnd(msg, verticalPos) {
  43816. var activationData = exports.bounds.endActivation(msg);
  43817. if (activationData.starty + 18 > verticalPos) {
  43818. activationData.starty = verticalPos - 6;
  43819. verticalPos += 12;
  43820. }
  43821. svgDraw.drawActivation(diagram, activationData, verticalPos, conf);
  43822. exports.bounds.insert(activationData.startx, verticalPos - 10, activationData.stopx, verticalPos);
  43823. }
  43824. var lastMsg;
  43825. // Draw the messages/signals
  43826. messages.forEach(function (msg) {
  43827. var loopData;
  43828. switch (msg.type) {
  43829. case sq.yy.LINETYPE.NOTE:
  43830. exports.bounds.bumpVerticalPos(conf.boxMargin);
  43831. startx = actors[msg.from].x;
  43832. stopx = actors[msg.to].x;
  43833. if (msg.placement === sq.yy.PLACEMENT.RIGHTOF) {
  43834. drawNote(diagram, startx + (conf.width + conf.actorMargin) / 2, exports.bounds.getVerticalPos(), msg);
  43835. } else if (msg.placement === sq.yy.PLACEMENT.LEFTOF) {
  43836. drawNote(diagram, startx - (conf.width + conf.actorMargin) / 2, exports.bounds.getVerticalPos(), msg);
  43837. } else if (msg.to === msg.from) {
  43838. // Single-actor over
  43839. drawNote(diagram, startx, exports.bounds.getVerticalPos(), msg);
  43840. } else {
  43841. // Multi-actor over
  43842. forceWidth = Math.abs(startx - stopx) + conf.actorMargin;
  43843. drawNote(diagram, (startx + stopx + conf.width - forceWidth) / 2, exports.bounds.getVerticalPos(), msg, forceWidth);
  43844. }
  43845. break;
  43846. case sq.yy.LINETYPE.ACTIVE_START:
  43847. exports.bounds.newActivation(msg, diagram);
  43848. break;
  43849. case sq.yy.LINETYPE.ACTIVE_END:
  43850. activeEnd(msg, exports.bounds.getVerticalPos());
  43851. break;
  43852. case sq.yy.LINETYPE.LOOP_START:
  43853. exports.bounds.bumpVerticalPos(conf.boxMargin);
  43854. exports.bounds.newLoop(msg.message);
  43855. exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin);
  43856. break;
  43857. case sq.yy.LINETYPE.LOOP_END:
  43858. loopData = exports.bounds.endLoop();
  43859. svgDraw.drawLoop(diagram, loopData, 'loop', conf);
  43860. exports.bounds.bumpVerticalPos(conf.boxMargin);
  43861. break;
  43862. case sq.yy.LINETYPE.OPT_START:
  43863. exports.bounds.bumpVerticalPos(conf.boxMargin);
  43864. exports.bounds.newLoop(msg.message);
  43865. exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin);
  43866. break;
  43867. case sq.yy.LINETYPE.OPT_END:
  43868. loopData = exports.bounds.endLoop();
  43869. svgDraw.drawLoop(diagram, loopData, 'opt', conf);
  43870. exports.bounds.bumpVerticalPos(conf.boxMargin);
  43871. break;
  43872. case sq.yy.LINETYPE.ALT_START:
  43873. exports.bounds.bumpVerticalPos(conf.boxMargin);
  43874. exports.bounds.newLoop(msg.message);
  43875. exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin);
  43876. break;
  43877. case sq.yy.LINETYPE.ALT_ELSE:
  43878. //exports.drawLoop(diagram, loopData);
  43879. exports.bounds.bumpVerticalPos(conf.boxMargin);
  43880. loopData = exports.bounds.addElseToLoop(msg.message);
  43881. exports.bounds.bumpVerticalPos(conf.boxMargin);
  43882. break;
  43883. case sq.yy.LINETYPE.ALT_END:
  43884. loopData = exports.bounds.endLoop();
  43885. svgDraw.drawLoop(diagram, loopData, 'alt', conf);
  43886. exports.bounds.bumpVerticalPos(conf.boxMargin);
  43887. break;
  43888. default:
  43889. try {
  43890. lastMsg = msg;
  43891. exports.bounds.bumpVerticalPos(conf.messageMargin);
  43892. var fromBounds = actorFlowVerticaBounds(msg.from);
  43893. var toBounds = actorFlowVerticaBounds(msg.to);
  43894. var fromIdx = fromBounds[0] <= toBounds[0] ? 1 : 0;
  43895. var toIdx = fromBounds[0] < toBounds[0] ? 0 : 1;
  43896. startx = fromBounds[fromIdx];
  43897. stopx = toBounds[toIdx];
  43898. var verticalPos = exports.bounds.getVerticalPos();
  43899. drawMessage(diagram, startx, stopx, verticalPos, msg);
  43900. var allBounds = fromBounds.concat(toBounds);
  43901. exports.bounds.insert(Math.min.apply(null, allBounds), verticalPos, Math.max.apply(null, allBounds), verticalPos);
  43902. } catch (e) {
  43903. console.error('error while drawing message', e);
  43904. }
  43905. }
  43906. });
  43907. if (conf.mirrorActors) {
  43908. // Draw actors below diagram
  43909. exports.bounds.bumpVerticalPos(conf.boxMargin * 2);
  43910. module.exports.drawActors(diagram, actors, actorKeys, exports.bounds.getVerticalPos());
  43911. }
  43912. var box = exports.bounds.getBounds();
  43913. // Adjust line height of actor lines now that the height of the diagram is known
  43914. log.debug('For line height fix Querying: #' + id + ' .actor-line');
  43915. var actorLines = d3.selectAll('#' + id + ' .actor-line');
  43916. actorLines.attr('y2', box.stopy);
  43917. var height = box.stopy - box.starty + 2 * conf.diagramMarginY;
  43918. if (conf.mirrorActors) {
  43919. height = height - conf.boxMargin + conf.bottomMarginAdj;
  43920. }
  43921. var width = box.stopx - box.startx + 2 * conf.diagramMarginX;
  43922. if (title) {
  43923. diagram.append('text').text(title).attr('x', (box.stopx - box.startx) / 2 - 2 * conf.diagramMarginX).attr('y', -25);
  43924. }
  43925. if (conf.useMaxWidth) {
  43926. diagram.attr('height', '100%');
  43927. diagram.attr('width', '100%');
  43928. diagram.attr('style', 'max-width:' + width + 'px;');
  43929. } else {
  43930. diagram.attr('height', height);
  43931. diagram.attr('width', width);
  43932. }
  43933. var extraVertForTitle = title ? 40 : 0;
  43934. diagram.attr('viewBox', box.startx - conf.diagramMarginX + ' -' + (conf.diagramMarginY + extraVertForTitle) + ' ' + width + ' ' + (height + extraVertForTitle));
  43935. };
  43936. },{"../../d3":107,"../../logger":129,"./parser/sequenceDiagram":125,"./sequenceDb":126,"./svgDraw":128}],128:[function(require,module,exports){
  43937. /**
  43938. * Created by knut on 14-12-20.
  43939. */
  43940. //var log = require('../../logger').create();
  43941. 'use strict';
  43942. exports.drawRect = function (elem, rectData) {
  43943. var rectElem = elem.append('rect');
  43944. rectElem.attr('x', rectData.x);
  43945. rectElem.attr('y', rectData.y);
  43946. rectElem.attr('fill', rectData.fill);
  43947. rectElem.attr('stroke', rectData.stroke);
  43948. rectElem.attr('width', rectData.width);
  43949. rectElem.attr('height', rectData.height);
  43950. rectElem.attr('rx', rectData.rx);
  43951. rectElem.attr('ry', rectData.ry);
  43952. if (typeof rectData['class'] !== 'undefined') {
  43953. rectElem.attr('class', rectData['class']);
  43954. }
  43955. return rectElem;
  43956. };
  43957. exports.drawText = function (elem, textData, width) {
  43958. // Remove and ignore br:s
  43959. var nText = textData.text.replace(/<br\/?>/ig, ' ');
  43960. var textElem = elem.append('text');
  43961. textElem.attr('x', textData.x);
  43962. textElem.attr('y', textData.y);
  43963. textElem.style('text-anchor', textData.anchor);
  43964. textElem.attr('fill', textData.fill);
  43965. if (typeof textData['class'] !== 'undefined') {
  43966. textElem.attr('class', textData['class']);
  43967. }
  43968. /* textData.text.split(/<br\/?>/ig).forEach(function(rowText){
  43969. var span = textElem.append('tspan');
  43970. span.attr('x', textData.x +textData.textMargin);
  43971. span.attr('dy', textData.dy);
  43972. span.text(rowText);
  43973. });*/
  43974. var span = textElem.append('tspan');
  43975. //span.attr('x', textData.x);
  43976. span.attr('x', textData.x + textData.textMargin * 2);
  43977. //span.attr('dy', textData.dy);
  43978. span.text(nText);
  43979. if (typeof textElem.textwrap !== 'undefined') {
  43980. textElem.textwrap({
  43981. x: textData.x, // bounding box is 300 pixels from the left
  43982. y: textData.y, // bounding box is 400 pixels from the top
  43983. width: width, // bounding box is 500 pixels across
  43984. height: 1800 // bounding box is 600 pixels tall
  43985. }, textData.textMargin);
  43986. }
  43987. return textElem;
  43988. };
  43989. exports.drawLabel = function (elem, txtObject) {
  43990. var rectData = exports.getNoteRect();
  43991. rectData.x = txtObject.x;
  43992. rectData.y = txtObject.y;
  43993. rectData.width = 50;
  43994. rectData.height = 20;
  43995. rectData.fill = '#526e52';
  43996. rectData.stroke = 'none';
  43997. rectData['class'] = 'labelBox';
  43998. //rectData.color = 'white';
  43999. exports.drawRect(elem, rectData);
  44000. txtObject.y = txtObject.y + txtObject.labelMargin;
  44001. txtObject.x = txtObject.x + 0.5 * txtObject.labelMargin;
  44002. txtObject.fill = 'white';
  44003. exports.drawText(elem, txtObject);
  44004. //return textElem;
  44005. };
  44006. var actorCnt = -1;
  44007. /**
  44008. * Draws an actor in the diagram with the attaced line
  44009. * @param center - The center of the the actor
  44010. * @param pos The position if the actor in the liost of actors
  44011. * @param description The text in the box
  44012. */
  44013. exports.drawActor = function (elem, left, verticalPos, description, conf) {
  44014. var center = left + conf.width / 2;
  44015. var g = elem.append('g');
  44016. if (verticalPos === 0) {
  44017. actorCnt++;
  44018. g.append('line').attr('id', 'actor' + actorCnt).attr('x1', center).attr('y1', 5).attr('x2', center).attr('y2', 2000).attr('class', 'actor-line').attr('stroke-width', '0.5px').attr('stroke', '#999');
  44019. }
  44020. var rect = exports.getNoteRect();
  44021. rect.x = left;
  44022. rect.y = verticalPos;
  44023. rect.fill = '#eaeaea';
  44024. rect.width = conf.width;
  44025. rect.height = conf.height;
  44026. rect['class'] = 'actor';
  44027. rect.rx = 3;
  44028. rect.ry = 3;
  44029. exports.drawRect(g, rect);
  44030. _drawTextCandidateFunc(conf)(description, g, rect.x, rect.y, rect.width, rect.height, { 'class': 'actor' });
  44031. };
  44032. exports.anchorElement = function (elem) {
  44033. return elem.append('g');
  44034. };
  44035. /**
  44036. * Draws an actor in the diagram with the attaced line
  44037. * @param elem - element to append activation rect
  44038. * @param bounds - activation box bounds
  44039. * @param verticalPos - precise y cooridnate of bottom activation box edge
  44040. */
  44041. exports.drawActivation = function (elem, bounds, verticalPos) {
  44042. var rect = exports.getNoteRect();
  44043. var g = bounds.anchored;
  44044. rect.x = bounds.startx;
  44045. rect.y = bounds.starty;
  44046. rect.fill = '#f4f4f4';
  44047. rect.width = bounds.stopx - bounds.startx;
  44048. rect.height = verticalPos - bounds.starty;
  44049. exports.drawRect(g, rect);
  44050. };
  44051. /**
  44052. * Draws an actor in the diagram with the attaced line
  44053. * @param center - The center of the the actor
  44054. * @param pos The position if the actor in the list of actors
  44055. * @param description The text in the box
  44056. */
  44057. exports.drawLoop = function (elem, bounds, labelText, conf) {
  44058. var g = elem.append('g');
  44059. var drawLoopLine = function drawLoopLine(startx, starty, stopx, stopy) {
  44060. g.append('line').attr('x1', startx).attr('y1', starty).attr('x2', stopx).attr('y2', stopy).attr('stroke-width', 2).attr('stroke', '#526e52').attr('class', 'loopLine');
  44061. };
  44062. drawLoopLine(bounds.startx, bounds.starty, bounds.stopx, bounds.starty);
  44063. drawLoopLine(bounds.stopx, bounds.starty, bounds.stopx, bounds.stopy);
  44064. drawLoopLine(bounds.startx, bounds.stopy, bounds.stopx, bounds.stopy);
  44065. drawLoopLine(bounds.startx, bounds.starty, bounds.startx, bounds.stopy);
  44066. if (typeof bounds.elsey !== 'undefined') {
  44067. drawLoopLine(bounds.startx, bounds.elsey, bounds.stopx, bounds.elsey);
  44068. }
  44069. var txt = exports.getTextObj();
  44070. txt.text = labelText;
  44071. txt.x = bounds.startx;
  44072. txt.y = bounds.starty;
  44073. txt.labelMargin = 1.5 * 10; // This is the small box that says "loop"
  44074. txt['class'] = 'labelText'; // Its size & position are fixed.
  44075. txt.fill = 'white';
  44076. exports.drawLabel(g, txt);
  44077. txt = exports.getTextObj();
  44078. txt.text = '[ ' + bounds.title + ' ]';
  44079. txt.x = bounds.startx + (bounds.stopx - bounds.startx) / 2;
  44080. txt.y = bounds.starty + 1.5 * conf.boxMargin;
  44081. txt.anchor = 'middle';
  44082. txt['class'] = 'loopText';
  44083. exports.drawText(g, txt);
  44084. if (typeof bounds.elseText !== 'undefined') {
  44085. txt.text = '[ ' + bounds.elseText + ' ]';
  44086. txt.y = bounds.elsey + 1.5 * conf.boxMargin;
  44087. exports.drawText(g, txt);
  44088. }
  44089. };
  44090. /**
  44091. * Setup arrow head and define the marker. The result is appended to the svg.
  44092. */
  44093. exports.insertArrowHead = function (elem) {
  44094. elem.append('defs').append('marker').attr('id', 'arrowhead').attr('refX', 5).attr('refY', 2).attr('markerWidth', 6).attr('markerHeight', 4).attr('orient', 'auto').append('path').attr('d', 'M 0,0 V 4 L6,2 Z'); //this is actual shape for arrowhead
  44095. };
  44096. /**
  44097. * Setup arrow head and define the marker. The result is appended to the svg.
  44098. */
  44099. exports.insertArrowCrossHead = function (elem) {
  44100. var defs = elem.append('defs');
  44101. var marker = defs.append('marker').attr('id', 'crosshead').attr('markerWidth', 15).attr('markerHeight', 8).attr('orient', 'auto').attr('refX', 16).attr('refY', 4);
  44102. // The arrow
  44103. marker.append('path').attr('fill', 'black').attr('stroke', '#000000').style('stroke-dasharray', '0, 0').attr('stroke-width', '1px').attr('d', 'M 9,2 V 6 L16,4 Z');
  44104. // The cross
  44105. marker.append('path').attr('fill', 'none').attr('stroke', '#000000').style('stroke-dasharray', '0, 0').attr('stroke-width', '1px').attr('d', 'M 0,1 L 6,7 M 6,1 L 0,7'); //this is actual shape for arrowhead
  44106. };
  44107. exports.getTextObj = function () {
  44108. var txt = {
  44109. x: 0,
  44110. y: 0,
  44111. 'fill': 'black',
  44112. 'text-anchor': 'start',
  44113. style: '#666',
  44114. width: 100,
  44115. height: 100,
  44116. textMargin: 0,
  44117. rx: 0,
  44118. ry: 0
  44119. };
  44120. return txt;
  44121. };
  44122. exports.getNoteRect = function () {
  44123. var rect = {
  44124. x: 0,
  44125. y: 0,
  44126. fill: '#EDF2AE',
  44127. stroke: '#666',
  44128. width: 100,
  44129. anchor: 'start',
  44130. height: 100,
  44131. rx: 0,
  44132. ry: 0
  44133. };
  44134. return rect;
  44135. };
  44136. var _drawTextCandidateFunc = (function () {
  44137. function byText(content, g, x, y, width, height, textAttrs) {
  44138. var text = g.append('text').attr('x', x + width / 2).attr('y', y + height / 2 + 5).style('text-anchor', 'middle').text(content);
  44139. _setTextAttrs(text, textAttrs);
  44140. }
  44141. function byTspan(content, g, x, y, width, height, textAttrs) {
  44142. var text = g.append('text').attr('x', x + width / 2).attr('y', y).style('text-anchor', 'middle');
  44143. text.append('tspan').attr('x', x + width / 2).attr('dy', '0').text(content);
  44144. if (typeof text.textwrap !== 'undefined') {
  44145. text.textwrap({ //d3textwrap
  44146. x: x + width / 2, y: y, width: width, height: height
  44147. }, 0);
  44148. //vertical aligment after d3textwrap expans tspan to multiple tspans
  44149. var tspans = text.selectAll('tspan');
  44150. if (tspans.length > 0 && tspans[0].length > 0) {
  44151. tspans = tspans[0];
  44152. //set y of <text> to the mid y of the first line
  44153. text.attr('y', y + (height / 2.0 - text[0][0].getBBox().height * (1 - 1.0 / tspans.length) / 2.0)).attr("dominant-baseline", "central").attr("alignment-baseline", "central");
  44154. }
  44155. }
  44156. _setTextAttrs(text, textAttrs);
  44157. }
  44158. function byFo(content, g, x, y, width, height, textAttrs) {
  44159. var s = g.append('switch');
  44160. var f = s.append("foreignObject").attr('x', x).attr('y', y).attr('width', width).attr('height', height);
  44161. var text = f.append('div').style('display', 'table').style('height', '100%').style('width', '100%');
  44162. text.append('div').style('display', 'table-cell').style('text-align', 'center').style('vertical-align', 'middle').text(content);
  44163. byTspan(content, s, x, y, width, height, textAttrs);
  44164. _setTextAttrs(text, textAttrs);
  44165. }
  44166. function _setTextAttrs(toText, fromTextAttrsDict) {
  44167. for (var key in fromTextAttrsDict) {
  44168. if (fromTextAttrsDict.hasOwnProperty(key)) {
  44169. toText.attr(key, fromTextAttrsDict[key]);
  44170. }
  44171. }
  44172. }
  44173. return function (conf) {
  44174. return conf.textPlacement === 'fo' ? byFo : conf.textPlacement === 'old' ? byText : byTspan;
  44175. };
  44176. })();
  44177. },{}],129:[function(require,module,exports){
  44178. /**
  44179. * #logger
  44180. * logger = require('logger').create()
  44181. * logger.info("blah")
  44182. * => [2011-3-3T20:24:4.810 info (5021)] blah
  44183. * logger.debug("boom")
  44184. * =>
  44185. * logger.level = Logger.levels.debug
  44186. * logger.debug(function() { return "booom" })
  44187. * => [2011-3-3T20:24:4.810 error (5021)] booom
  44188. */
  44189. 'use strict';
  44190. var LEVELS = {
  44191. debug: 1,
  44192. info: 2,
  44193. warn: 3,
  44194. error: 4,
  44195. fatal: 5,
  44196. 'default': 5
  44197. };
  44198. var defaultLevel = LEVELS.error;
  44199. exports.setLogLevel = function (level) {
  44200. defaultLevel = level;
  44201. };
  44202. function formatTime(timestamp) {
  44203. var hh = timestamp.getUTCHours();
  44204. var mm = timestamp.getUTCMinutes();
  44205. var ss = timestamp.getSeconds();
  44206. var ms = timestamp.getMilliseconds();
  44207. // If you were building a timestamp instead of a duration, you would uncomment the following line to get 12-hour (not 24) time
  44208. // if (hh > 12) {hh = hh % 12;}
  44209. // These lines ensure you have two-digits
  44210. if (hh < 10) {
  44211. hh = '0' + hh;
  44212. }
  44213. if (mm < 10) {
  44214. mm = '0' + mm;
  44215. }
  44216. if (ss < 10) {
  44217. ss = '0' + ss;
  44218. }
  44219. if (ms < 100) {
  44220. ms = '0' + ms;
  44221. }
  44222. if (ms < 10) {
  44223. ms = '00' + ms;
  44224. }
  44225. // This formats your string to HH:MM:SS
  44226. var t = hh + ':' + mm + ':' + ss + ' (' + ms + ')';
  44227. return t;
  44228. }
  44229. function format(level) {
  44230. var time = formatTime(new Date());
  44231. return '%c ' + time + ' :%c' + level + ': ';
  44232. }
  44233. function Log(level) {
  44234. this.level = level;
  44235. this.log = function () {
  44236. var args = Array.prototype.slice.call(arguments);
  44237. var level = args.shift();
  44238. var logLevel = this.level;
  44239. if (typeof logLevel === 'undefined') {
  44240. logLevel = defaultLevel;
  44241. }
  44242. if (logLevel <= level) {
  44243. if (typeof console !== 'undefined') {
  44244. //eslint-disable-line no-console
  44245. if (typeof console.log !== 'undefined') {
  44246. //eslint-disable-line no-console
  44247. //return console.log('[' + formatTime(new Date()) + '] ' , str); //eslint-disable-line no-console
  44248. args.unshift('[' + formatTime(new Date()) + '] ');
  44249. console.log.apply(console, args.map(function (a) {
  44250. if (typeof a === "object") {
  44251. return a.toString() + JSON.stringify(a, null, 2);
  44252. }
  44253. return a;
  44254. }));
  44255. }
  44256. }
  44257. }
  44258. };
  44259. this.trace = window.console.debug.bind(window.console, format('TRACE', name), 'color:grey;', 'color: grey;');
  44260. this.debug = window.console.debug.bind(window.console, format('DEBUG', name), 'color:grey;', 'color: green;');
  44261. this.info = window.console.debug.bind(window.console, format('INFO', name), 'color:grey;', 'color: blue;');
  44262. this.warn = window.console.debug.bind(window.console, format('WARN', name), 'color:grey;', 'color: orange;');
  44263. this.error = window.console.debug.bind(window.console, format('ERROR', name), 'color:grey;', 'color: red;');
  44264. }
  44265. exports.Log = Log;
  44266. },{}],130:[function(require,module,exports){
  44267. (function (global){
  44268. /**
  44269. * ---
  44270. * title: mermaidAPI
  44271. * order: 5
  44272. * ---
  44273. * # mermaidAPI
  44274. * This is the api to be used when handling the integration with the web page instead of using the default integration
  44275. * (mermaid.js).
  44276. *
  44277. * The core of this api is the **render** function that given a graph definitionas text renders the graph/diagram and
  44278. * returns a svg element for the graph. It is is then up to the user of the API to make use of the svg, either insert it
  44279. * somewhere in the page or something completely different.
  44280. */
  44281. 'use strict';
  44282. var Logger = require('./logger');
  44283. var log = new Logger.Log();
  44284. var graph = require('./diagrams/flowchart/graphDb');
  44285. var utils = require('./utils');
  44286. var flowRenderer = require('./diagrams/flowchart/flowRenderer');
  44287. var seq = require('./diagrams/sequenceDiagram/sequenceRenderer');
  44288. var info = require('./diagrams/example/exampleRenderer');
  44289. var infoParser = require('./diagrams/example/parser/example');
  44290. var flowParser = require('./diagrams/flowchart/parser/flow');
  44291. var dotParser = require('./diagrams/flowchart/parser/dot');
  44292. var sequenceParser = require('./diagrams/sequenceDiagram/parser/sequenceDiagram');
  44293. var sequenceDb = require('./diagrams/sequenceDiagram/sequenceDb');
  44294. var infoDb = require('./diagrams/example/exampleDb');
  44295. var gantt = require('./diagrams/gantt/ganttRenderer');
  44296. var ganttParser = require('./diagrams/gantt/parser/gantt');
  44297. var ganttDb = require('./diagrams/gantt/ganttDb');
  44298. var classParser = require('./diagrams/classDiagram/parser/classDiagram');
  44299. var classRenderer = require('./diagrams/classDiagram/classRenderer');
  44300. var classDb = require('./diagrams/classDiagram/classDb');
  44301. var gitGraphParser = require('./diagrams/gitGraph/parser/gitGraph');
  44302. var gitGraphRenderer = require('./diagrams/gitGraph/gitGraphRenderer');
  44303. var gitGraphAst = require('./diagrams/gitGraph/gitGraphAst');
  44304. var d3 = require('./d3');
  44305. SVGElement.prototype.getTransformToElement = SVGElement.prototype.getTransformToElement || function (toElement) {
  44306. return toElement.getScreenCTM().inverse().multiply(this.getScreenCTM());
  44307. };
  44308. /**
  44309. * ## Configuration
  44310. * These are the default options which can be overridden with the initialization call as in the example below:
  44311. * ```
  44312. * mermaid.initialize({
  44313. * flowchart:{
  44314. * htmlLabels: false
  44315. * }
  44316. * });
  44317. * ```
  44318. */
  44319. var config = {
  44320. /**
  44321. * logLevel , decides the amount of logging to be used.
  44322. * * debug: 1
  44323. * * info: 2
  44324. * * warn: 3
  44325. * * error: 4
  44326. * * fatal: 5
  44327. */
  44328. logLevel: 5,
  44329. /**
  44330. * **cloneCssStyles** - This options controls whether or not the css rules should be copied into the generated svg
  44331. */
  44332. cloneCssStyles: true,
  44333. /**
  44334. * **startOnLoad** - This options controls whether or mermaid starts when the page loads
  44335. */
  44336. startOnLoad: true,
  44337. /**
  44338. * **arrowMarkerAbsolute** - This options controls whether or arrow markers in html code will be absolute paths or
  44339. * an anchor, #. This matters if you are using base tag settings.
  44340. */
  44341. arrowMarkerAbsolute: false,
  44342. /**
  44343. * ### flowchart
  44344. * *The object containing configurations specific for flowcharts*
  44345. */
  44346. flowchart: {
  44347. /**
  44348. * **htmlLabels** - Flag for setting whether or not a html tag should be used for rendering labels
  44349. * on the edges
  44350. */
  44351. htmlLabels: true,
  44352. /**
  44353. * **useMaxWidth** - Flag for setting whether or not a all available width should be used for
  44354. * the diagram.
  44355. */
  44356. useMaxWidth: true
  44357. },
  44358. /**
  44359. * ### sequenceDiagram
  44360. * The object containing configurations specific for sequence diagrams
  44361. */
  44362. sequenceDiagram: {
  44363. /**
  44364. * **diagramMarginX** - margin to the right and left of the sequence diagram
  44365. */
  44366. diagramMarginX: 50,
  44367. /**
  44368. * **diagramMarginY** - margin to the over and under the sequence diagram
  44369. */
  44370. diagramMarginY: 10,
  44371. /**
  44372. * **actorMargin** - Margin between actors
  44373. */
  44374. actorMargin: 50,
  44375. /**
  44376. * **width** - Width of actor boxes
  44377. */
  44378. width: 150,
  44379. /**
  44380. * **height** - Height of actor boxes
  44381. */
  44382. height: 65,
  44383. /**
  44384. * **boxMargin** - Margin around loop boxes
  44385. */
  44386. boxMargin: 10,
  44387. /**
  44388. * **boxTextMargin** - margin around the text in loop/alt/opt boxes
  44389. */
  44390. boxTextMargin: 5,
  44391. /**
  44392. * **noteMargin** - margin around notes
  44393. */
  44394. noteMargin: 10,
  44395. /**
  44396. * **messageMargin** - Space between messages
  44397. */
  44398. messageMargin: 35,
  44399. /**
  44400. * **mirrorActors** - mirror actors under diagram
  44401. */
  44402. mirrorActors: true,
  44403. /**
  44404. * **bottomMarginAdj** - Depending on css styling this might need adjustment.
  44405. * Prolongs the edge of the diagram downwards
  44406. */
  44407. bottomMarginAdj: 1,
  44408. /**
  44409. * **useMaxWidth** - when this flag is set the height and width is set to 100% and is then scaling with the
  44410. * available space if not the absolute space required is used
  44411. */
  44412. useMaxWidth: true
  44413. },
  44414. /** ### gantt
  44415. * The object containing configurations specific for gantt diagrams*
  44416. */
  44417. gantt: {
  44418. /**
  44419. * **titleTopMargin** - margin top for the text over the gantt diagram
  44420. */
  44421. titleTopMargin: 25,
  44422. /**
  44423. * **barHeight** - the height of the bars in the graph
  44424. */
  44425. barHeight: 20,
  44426. /**
  44427. * **barGap** - the margin between the different activities in the gantt diagram
  44428. */
  44429. barGap: 4,
  44430. /**
  44431. * **topPadding** - margin between title and gantt diagram and between axis and gantt diagram.
  44432. */
  44433. topPadding: 50,
  44434. /**
  44435. * **leftPadding** - the space allocated for the section name to the left of the activities.
  44436. */
  44437. leftPadding: 75,
  44438. /**
  44439. * **gridLineStartPadding** - Vertical starting position of the grid lines
  44440. */
  44441. gridLineStartPadding: 35,
  44442. /**
  44443. * **fontSize** - font size ...
  44444. */
  44445. fontSize: 11,
  44446. /**
  44447. * **fontFamily** - font family ...
  44448. */
  44449. fontFamily: '"Open-Sans", "sans-serif"',
  44450. /**
  44451. * **numberSectionStyles** - the number of alternating section styles
  44452. */
  44453. numberSectionStyles: 3,
  44454. /**
  44455. * **axisFormatter** - formatting of the axis, this might need adjustment to match your locale and preferences
  44456. */
  44457. axisFormatter: [
  44458. // Within a day
  44459. ['%I:%M', function (d) {
  44460. return d.getHours();
  44461. }],
  44462. // Monday a week
  44463. ['w. %U', function (d) {
  44464. return d.getDay() == 1;
  44465. }],
  44466. // Day within a week (not monday)
  44467. ['%a %d', function (d) {
  44468. return d.getDay() && d.getDate() != 1;
  44469. }],
  44470. // within a month
  44471. ['%b %d', function (d) {
  44472. return d.getDate() != 1;
  44473. }],
  44474. // Month
  44475. ['%m-%y', function (d) {
  44476. return d.getMonth();
  44477. }]]
  44478. },
  44479. classDiagram: {},
  44480. gitGraph: {},
  44481. info: {}
  44482. };
  44483. Logger.setLogLevel(config.logLevel);
  44484. /**
  44485. * ## parse
  44486. * Function that parses a mermaid diagram definition. If parsing fails the parseError callback is called and an error is
  44487. * thrown and
  44488. * @param text
  44489. */
  44490. var parse = function parse(text) {
  44491. var graphType = utils.detectType(text);
  44492. var parser;
  44493. switch (graphType) {
  44494. case 'gitGraph':
  44495. parser = gitGraphParser;
  44496. parser.parser.yy = gitGraphAst;
  44497. break;
  44498. case 'graph':
  44499. parser = flowParser;
  44500. parser.parser.yy = graph;
  44501. break;
  44502. case 'dotGraph':
  44503. parser = dotParser;
  44504. parser.parser.yy = graph;
  44505. break;
  44506. case 'sequenceDiagram':
  44507. parser = sequenceParser;
  44508. parser.parser.yy = sequenceDb;
  44509. break;
  44510. case 'info':
  44511. parser = infoParser;
  44512. parser.parser.yy = infoDb;
  44513. break;
  44514. case 'gantt':
  44515. parser = ganttParser;
  44516. parser.parser.yy = ganttDb;
  44517. break;
  44518. case 'classDiagram':
  44519. parser = classParser;
  44520. parser.parser.yy = classDb;
  44521. break;
  44522. }
  44523. try {
  44524. parser.parse(text);
  44525. return true;
  44526. } catch (err) {
  44527. return false;
  44528. }
  44529. };
  44530. exports.parse = parse;
  44531. /**
  44532. * ## version
  44533. * Function returning version information
  44534. * @returns {string} A string containing the version info
  44535. */
  44536. exports.version = function () {
  44537. return require('../package.json').version;
  44538. };
  44539. exports.encodeEntities = function (text) {
  44540. var txt = text;
  44541. txt = txt.replace(/style.*:\S*#.*;/g, function (s) {
  44542. var innerTxt = s.substring(0, s.length - 1);
  44543. return innerTxt;
  44544. });
  44545. txt = txt.replace(/classDef.*:\S*#.*;/g, function (s) {
  44546. var innerTxt = s.substring(0, s.length - 1);
  44547. return innerTxt;
  44548. });
  44549. txt = txt.replace(/#\w+\;/g, function (s) {
  44550. var innerTxt = s.substring(1, s.length - 1);
  44551. var isInt = /^\+?\d+$/.test(innerTxt);
  44552. if (isInt) {
  44553. return 'fl°°' + innerTxt + '¶ß';
  44554. } else {
  44555. return 'fl°' + innerTxt + '¶ß';
  44556. }
  44557. });
  44558. return txt;
  44559. };
  44560. exports.decodeEntities = function (text) {
  44561. var txt = text;
  44562. txt = txt.replace(/\fl\°\°/g, function () {
  44563. return '&#';
  44564. });
  44565. txt = txt.replace(/\fl\°/g, function () {
  44566. return '&';
  44567. });
  44568. txt = txt.replace(/¶ß/g, function () {
  44569. return ';';
  44570. });
  44571. return txt;
  44572. };
  44573. /**
  44574. * ##render
  44575. * Function that renders an svg with a graph from a chart definition. Usage example below.
  44576. *
  44577. * ```
  44578. * mermaidAPI.initialize({
  44579. * startOnLoad:true
  44580. * });
  44581. * $(function(){
  44582. * var graphDefinition = 'graph TB\na-->b';
  44583. * var cb = function(svgGraph){
  44584. * console.log(svgGraph);
  44585. * };
  44586. * mermaidAPI.render('id1',graphDefinition,cb);
  44587. * });
  44588. *```
  44589. * @param id the id of the element to be rendered
  44590. * @param txt the graph definition
  44591. * @param cb callback which is called after rendering is finished with the svg code as inparam.
  44592. * @param container selector to element in which a div with the graph temporarily will be inserted. In one is
  44593. * provided a hidden div will be inserted in the body of the page instead. The element will be removed when rendering is
  44594. * completed.
  44595. */
  44596. var render = function render(id, txt, cb, container) {
  44597. if (typeof container !== 'undefined') {
  44598. container.innerHTML = '';
  44599. d3.select(container).append('div').attr('id', 'd' + id).append('svg').attr('id', id).attr('width', '100%').attr('xmlns', 'http://www.w3.org/2000/svg').append('g');
  44600. } else {
  44601. var element = document.querySelector('#' + 'd' + id);
  44602. if (element) {
  44603. element.innerHTML = '';
  44604. }
  44605. d3.select('body').append('div').attr('id', 'd' + id).append('svg').attr('id', id).attr('width', '100%').attr('xmlns', 'http://www.w3.org/2000/svg').append('g');
  44606. }
  44607. window.txt = txt;
  44608. txt = exports.encodeEntities(txt);
  44609. //console.warn('mermaid encode: ');
  44610. //console.warn(txt);
  44611. var element = d3.select('#d' + id).node();
  44612. var graphType = utils.detectType(txt);
  44613. var classes = {};
  44614. switch (graphType) {
  44615. case 'gitGraph':
  44616. config.flowchart.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
  44617. gitGraphRenderer.setConf(config.gitGraph);
  44618. gitGraphRenderer.draw(txt, id, false);
  44619. //if(config.cloneCssStyles){
  44620. //classes = gitGraphRenderer.getClasses(txt, false);
  44621. //utils.cloneCssStyles(element.firstChild, classes);
  44622. //}
  44623. break;
  44624. case 'graph':
  44625. config.flowchart.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
  44626. flowRenderer.setConf(config.flowchart);
  44627. flowRenderer.draw(txt, id, false);
  44628. if (config.cloneCssStyles) {
  44629. classes = flowRenderer.getClasses(txt, false);
  44630. utils.cloneCssStyles(element.firstChild, classes);
  44631. }
  44632. break;
  44633. case 'dotGraph':
  44634. config.flowchart.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
  44635. flowRenderer.setConf(config.flowchart);
  44636. flowRenderer.draw(txt, id, true);
  44637. if (config.cloneCssStyles) {
  44638. classes = flowRenderer.getClasses(txt, true);
  44639. utils.cloneCssStyles(element.firstChild, classes);
  44640. }
  44641. break;
  44642. case 'sequenceDiagram':
  44643. config.sequenceDiagram.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
  44644. seq.setConf(config.sequenceDiagram);
  44645. seq.draw(txt, id);
  44646. if (config.cloneCssStyles) {
  44647. utils.cloneCssStyles(element.firstChild, []);
  44648. }
  44649. break;
  44650. case 'gantt':
  44651. config.gantt.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
  44652. gantt.setConf(config.gantt);
  44653. gantt.draw(txt, id);
  44654. if (config.cloneCssStyles) {
  44655. utils.cloneCssStyles(element.firstChild, []);
  44656. }
  44657. break;
  44658. case 'classDiagram':
  44659. config.classDiagram.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
  44660. classRenderer.setConf(config.classDiagram);
  44661. classRenderer.draw(txt, id);
  44662. if (config.cloneCssStyles) {
  44663. utils.cloneCssStyles(element.firstChild, []);
  44664. }
  44665. break;
  44666. case 'info':
  44667. config.info.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
  44668. info.draw(txt, id, exports.version());
  44669. if (config.cloneCssStyles) {
  44670. utils.cloneCssStyles(element.firstChild, []);
  44671. }
  44672. break;
  44673. }
  44674. d3.select('#d' + id).selectAll('foreignobject div').attr('xmlns', 'http://www.w3.org/1999/xhtml');
  44675. var url = '';
  44676. if (config.arrowMarkerAbsolute) {
  44677. url = window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search;
  44678. url = url.replace(/\(/g, '\\(');
  44679. url = url.replace(/\)/g, '\\)');
  44680. }
  44681. // Fix for when the base tag is used
  44682. var svgCode = d3.select('#d' + id).node().innerHTML.replace(/url\(#arrowhead/g, 'url(' + url + '#arrowhead', 'g');
  44683. svgCode = exports.decodeEntities(svgCode);
  44684. //console.warn('mermaid decode: ');
  44685. //console.warn(svgCode);
  44686. //var he = require('he');
  44687. //svgCode = he.decode(svgCode);
  44688. if (typeof cb !== 'undefined') {
  44689. cb(svgCode, graph.bindFunctions);
  44690. } else {
  44691. log.warn('CB = undefined!');
  44692. }
  44693. var node = d3.select('#d' + id).node();
  44694. if (node !== null && typeof node.remove === 'function') {
  44695. d3.select('#d' + id).node().remove();
  44696. }
  44697. return svgCode;
  44698. };
  44699. exports.render = function (id, text, cb, containerElement) {
  44700. try {
  44701. if (arguments.length === 1) {
  44702. text = id;
  44703. id = 'mermaidId0';
  44704. }
  44705. if (typeof document === 'undefined') {
  44706. // Todo handle rendering serverside using phantomjs
  44707. } else {
  44708. // In browser
  44709. return render(id, text, cb, containerElement);
  44710. }
  44711. } catch (e) {
  44712. log.warn(e);
  44713. }
  44714. };
  44715. var setConf = function setConf(cnf) {
  44716. // Top level initially mermaid, gflow, sequenceDiagram and gantt
  44717. var lvl1Keys = Object.keys(cnf);
  44718. var i;
  44719. for (i = 0; i < lvl1Keys.length; i++) {
  44720. if (typeof cnf[lvl1Keys[i]] === 'object') {
  44721. var lvl2Keys = Object.keys(cnf[lvl1Keys[i]]);
  44722. var j;
  44723. for (j = 0; j < lvl2Keys.length; j++) {
  44724. log.debug('Setting conf ', lvl1Keys[i], '-', lvl2Keys[j]);
  44725. if (typeof config[lvl1Keys[i]] === 'undefined') {
  44726. config[lvl1Keys[i]] = {};
  44727. }
  44728. log.debug('Setting config: ' + lvl1Keys[i] + ' ' + lvl2Keys[j] + ' to ' + cnf[lvl1Keys[i]][lvl2Keys[j]]);
  44729. config[lvl1Keys[i]][lvl2Keys[j]] = cnf[lvl1Keys[i]][lvl2Keys[j]];
  44730. }
  44731. } else {
  44732. config[lvl1Keys[i]] = cnf[lvl1Keys[i]];
  44733. }
  44734. }
  44735. };
  44736. exports.initialize = function (options) {
  44737. log.debug('Initializing mermaidAPI');
  44738. // Update default config with options supplied at initialization
  44739. if (typeof options === 'object') {
  44740. setConf(options);
  44741. }
  44742. Logger.setLogLevel(config.logLevel);
  44743. };
  44744. exports.getConfig = function () {
  44745. return config;
  44746. };
  44747. exports.parseError = function (err, hash) {
  44748. if (typeof mermaid !== 'undefined') {
  44749. global.mermaid.parseError(err, hash);
  44750. } else {
  44751. log.debug('Mermaid Syntax error:');
  44752. log.debug(err);
  44753. }
  44754. };
  44755. global.mermaidAPI = {
  44756. render: exports.render,
  44757. parse: exports.parse,
  44758. initialize: exports.initialize,
  44759. detectType: utils.detectType,
  44760. parseError: exports.parseError,
  44761. getConfig: exports.getConfig
  44762. };
  44763. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  44764. },{"../package.json":106,"./d3":107,"./diagrams/classDiagram/classDb":108,"./diagrams/classDiagram/classRenderer":109,"./diagrams/classDiagram/parser/classDiagram":110,"./diagrams/example/exampleDb":111,"./diagrams/example/exampleRenderer":112,"./diagrams/example/parser/example":113,"./diagrams/flowchart/flowRenderer":115,"./diagrams/flowchart/graphDb":116,"./diagrams/flowchart/parser/dot":117,"./diagrams/flowchart/parser/flow":118,"./diagrams/gantt/ganttDb":119,"./diagrams/gantt/ganttRenderer":120,"./diagrams/gantt/parser/gantt":121,"./diagrams/gitGraph/gitGraphAst":122,"./diagrams/gitGraph/gitGraphRenderer":123,"./diagrams/gitGraph/parser/gitGraph":124,"./diagrams/sequenceDiagram/parser/sequenceDiagram":125,"./diagrams/sequenceDiagram/sequenceDb":126,"./diagrams/sequenceDiagram/sequenceRenderer":127,"./logger":129,"./utils":131}],131:[function(require,module,exports){
  44765. /**
  44766. * Created by knut on 14-11-23.
  44767. */
  44768. 'use strict';
  44769. var Logger = require('./logger');
  44770. var log = new Logger.Log();
  44771. /**
  44772. * @function detectType
  44773. * Detects the type of the graph text.
  44774. * ```mermaid
  44775. * graph LR
  44776. * a-->b
  44777. * b-->c
  44778. * c-->d
  44779. * d-->e
  44780. * e-->f
  44781. * f-->g
  44782. * g-->h
  44783. * ```
  44784. *
  44785. * @param {string} text The text defining the graph
  44786. * @returns {string} A graph definition key
  44787. */
  44788. var detectType = function detectType(text) {
  44789. text = text.replace(/^\s*%%.*\n/g, '\n');
  44790. if (text.match(/^\s*sequenceDiagram/)) {
  44791. return 'sequenceDiagram';
  44792. }
  44793. if (text.match(/^\s*digraph/)) {
  44794. //log.debug('Detected dot syntax');
  44795. return 'dotGraph';
  44796. }
  44797. if (text.match(/^\s*info/)) {
  44798. //log.debug('Detected info syntax');
  44799. return 'info';
  44800. }
  44801. if (text.match(/^\s*gantt/)) {
  44802. //log.debug('Detected info syntax');
  44803. return 'gantt';
  44804. }
  44805. if (text.match(/^\s*classDiagram/)) {
  44806. log.debug('Detected classDiagram syntax');
  44807. return 'classDiagram';
  44808. }
  44809. if (text.match(/^\s*gitGraph/)) {
  44810. log.debug('Detected gitGraph syntax');
  44811. return 'gitGraph';
  44812. }
  44813. return 'graph';
  44814. };
  44815. exports.detectType = detectType;
  44816. /**
  44817. * Copies all relevant CSS content into the graph SVG.
  44818. * This allows the SVG to be copied as is while keeping class based styling
  44819. * @param {element} svg The root element of the SVG
  44820. * @param {object} Hash table of class definitions from the graph definition
  44821. */
  44822. var cloneCssStyles = function cloneCssStyles(svg, classes) {
  44823. var usedStyles = '';
  44824. var sheets = document.styleSheets;
  44825. var rule;
  44826. for (var i = 0; i < sheets.length; i++) {
  44827. // Avoid multiple inclusion on pages with multiple graphs
  44828. if (sheets[i].title !== 'mermaid-svg-internal-css') {
  44829. try {
  44830. var rules = sheets[i].cssRules;
  44831. if (rules !== null) {
  44832. for (var j = 0; j < rules.length; j++) {
  44833. rule = rules[j];
  44834. if (typeof rule.style !== 'undefined') {
  44835. var elems;
  44836. elems = svg.querySelectorAll(rule.selectorText);
  44837. if (elems.length > 0) {
  44838. usedStyles += rule.selectorText + ' { ' + rule.style.cssText + '}\n';
  44839. }
  44840. }
  44841. }
  44842. }
  44843. } catch (err) {
  44844. if (typeof rule !== 'undefined') {
  44845. log.warn('Invalid CSS selector "' + rule.selectorText + '"', err);
  44846. }
  44847. }
  44848. }
  44849. }
  44850. var defaultStyles = '';
  44851. var embeddedStyles = '';
  44852. for (var className in classes) {
  44853. if (classes.hasOwnProperty(className) && typeof className != 'undefined') {
  44854. if (className === 'default') {
  44855. if (classes['default'].styles instanceof Array) {
  44856. defaultStyles += '#' + svg.id.trim() + ' .node' + '>rect { ' + classes[className].styles.join('; ') + '; }\n';
  44857. }
  44858. if (classes['default'].nodeLabelStyles instanceof Array) {
  44859. defaultStyles += '#' + svg.id.trim() + ' .node text ' + ' { ' + classes[className].nodeLabelStyles.join('; ') + '; }\n';
  44860. }
  44861. if (classes['default'].edgeLabelStyles instanceof Array) {
  44862. defaultStyles += '#' + svg.id.trim() + ' .edgeLabel text ' + ' { ' + classes[className].edgeLabelStyles.join('; ') + '; }\n';
  44863. }
  44864. if (classes['default'].clusterStyles instanceof Array) {
  44865. defaultStyles += '#' + svg.id.trim() + ' .cluster rect ' + ' { ' + classes[className].clusterStyles.join('; ') + '; }\n';
  44866. }
  44867. } else {
  44868. if (classes[className].styles instanceof Array) {
  44869. embeddedStyles += '#' + svg.id.trim() + ' .' + className + '>rect, .' + className + '>polygon, .' + className + '>circle, .' + className + '>ellipse { ' + classes[className].styles.join('; ') + '; }\n';
  44870. }
  44871. }
  44872. }
  44873. }
  44874. if (usedStyles !== '' || defaultStyles !== '' || embeddedStyles !== '') {
  44875. var s = document.createElement('style');
  44876. s.setAttribute('type', 'text/css');
  44877. s.setAttribute('title', 'mermaid-svg-internal-css');
  44878. s.innerHTML = '/* <![CDATA[ */\n';
  44879. // Make this CSS local to this SVG
  44880. if (defaultStyles !== '') {
  44881. s.innerHTML += defaultStyles;
  44882. }
  44883. if (usedStyles !== '') {
  44884. s.innerHTML += usedStyles;
  44885. }
  44886. if (embeddedStyles !== '') {
  44887. s.innerHTML += embeddedStyles;
  44888. }
  44889. s.innerHTML += '/* ]]> */\n';
  44890. svg.insertBefore(s, svg.firstChild);
  44891. }
  44892. };
  44893. exports.cloneCssStyles = cloneCssStyles;
  44894. /**
  44895. * @function isSubstringInArray
  44896. * Detects whether a substring in present in a given array
  44897. * @param {string} str The substring to detect
  44898. * @param {array} arr The array to search
  44899. * @returns {number} the array index containing the substring or -1 if not present
  44900. **/
  44901. var isSubstringInArray = function isSubstringInArray(str, arr) {
  44902. for (var i = 0; i < arr.length; i++) {
  44903. if (arr[i].match(str)) return i;
  44904. }
  44905. return -1;
  44906. };
  44907. exports.isSubstringInArray = isSubstringInArray;
  44908. },{"./logger":129}]},{},[130])(130)
  44909. });