mermaid.slim.js 1.7 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653
  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.mermaid=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. /*! http://mths.be/he v0.5.0 by @mathias | MIT license */
  16131. ;(function(root) {
  16132. // Detect free variables `exports`.
  16133. var freeExports = typeof exports == 'object' && exports;
  16134. // Detect free variable `module`.
  16135. var freeModule = typeof module == 'object' && module &&
  16136. module.exports == freeExports && module;
  16137. // Detect free variable `global`, from Node.js or Browserified code,
  16138. // and use it as `root`.
  16139. var freeGlobal = typeof global == 'object' && global;
  16140. if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
  16141. root = freeGlobal;
  16142. }
  16143. /*--------------------------------------------------------------------------*/
  16144. // All astral symbols.
  16145. var regexAstralSymbols = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
  16146. // All ASCII symbols (not just printable ASCII) except those listed in the
  16147. // first column of the overrides table.
  16148. // http://whatwg.org/html/tokenization.html#table-charref-overrides
  16149. var regexAsciiWhitelist = /[\x01-\x7F]/g;
  16150. // All BMP symbols that are not ASCII newlines, printable ASCII symbols, or
  16151. // code points listed in the first column of the overrides table on
  16152. // http://whatwg.org/html/tokenization.html#table-charref-overrides.
  16153. var regexBmpWhitelist = /[\x01-\t\x0B\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g;
  16154. var regexEncodeNonAscii = /<\u20D2|=\u20E5|>\u20D2|\u205F\u200A|\u219D\u0338|\u2202\u0338|\u2220\u20D2|\u2229\uFE00|\u222A\uFE00|\u223C\u20D2|\u223D\u0331|\u223E\u0333|\u2242\u0338|\u224B\u0338|\u224D\u20D2|\u224E\u0338|\u224F\u0338|\u2250\u0338|\u2261\u20E5|\u2264\u20D2|\u2265\u20D2|\u2266\u0338|\u2267\u0338|\u2268\uFE00|\u2269\uFE00|\u226A\u0338|\u226A\u20D2|\u226B\u0338|\u226B\u20D2|\u227F\u0338|\u2282\u20D2|\u2283\u20D2|\u228A\uFE00|\u228B\uFE00|\u228F\u0338|\u2290\u0338|\u2293\uFE00|\u2294\uFE00|\u22B4\u20D2|\u22B5\u20D2|\u22D8\u0338|\u22D9\u0338|\u22DA\uFE00|\u22DB\uFE00|\u22F5\u0338|\u22F9\u0338|\u2933\u0338|\u29CF\u0338|\u29D0\u0338|\u2A6D\u0338|\u2A70\u0338|\u2A7D\u0338|\u2A7E\u0338|\u2AA1\u0338|\u2AA2\u0338|\u2AAC\uFE00|\u2AAD\uFE00|\u2AAF\u0338|\u2AB0\u0338|\u2AC5\u0338|\u2AC6\u0338|\u2ACB\uFE00|\u2ACC\uFE00|\u2AFD\u20E5|[\xA0-\u0113\u0116-\u0122\u0124-\u012B\u012E-\u014D\u0150-\u017E\u0192\u01B5\u01F5\u0237\u02C6\u02C7\u02D8-\u02DD\u0311\u0391-\u03A1\u03A3-\u03A9\u03B1-\u03C9\u03D1\u03D2\u03D5\u03D6\u03DC\u03DD\u03F0\u03F1\u03F5\u03F6\u0401-\u040C\u040E-\u044F\u0451-\u045C\u045E\u045F\u2002-\u2005\u2007-\u2010\u2013-\u2016\u2018-\u201A\u201C-\u201E\u2020-\u2022\u2025\u2026\u2030-\u2035\u2039\u203A\u203E\u2041\u2043\u2044\u204F\u2057\u205F-\u2063\u20AC\u20DB\u20DC\u2102\u2105\u210A-\u2113\u2115-\u211E\u2122\u2124\u2127-\u2129\u212C\u212D\u212F-\u2131\u2133-\u2138\u2145-\u2148\u2153-\u215E\u2190-\u219B\u219D-\u21A7\u21A9-\u21AE\u21B0-\u21B3\u21B5-\u21B7\u21BA-\u21DB\u21DD\u21E4\u21E5\u21F5\u21FD-\u2205\u2207-\u2209\u220B\u220C\u220F-\u2214\u2216-\u2218\u221A\u221D-\u2238\u223A-\u2257\u2259\u225A\u225C\u225F-\u2262\u2264-\u228B\u228D-\u229B\u229D-\u22A5\u22A7-\u22B0\u22B2-\u22BB\u22BD-\u22DB\u22DE-\u22E3\u22E6-\u22F7\u22F9-\u22FE\u2305\u2306\u2308-\u2310\u2312\u2313\u2315\u2316\u231C-\u231F\u2322\u2323\u232D\u232E\u2336\u233D\u233F\u237C\u23B0\u23B1\u23B4-\u23B6\u23DC-\u23DF\u23E2\u23E7\u2423\u24C8\u2500\u2502\u250C\u2510\u2514\u2518\u251C\u2524\u252C\u2534\u253C\u2550-\u256C\u2580\u2584\u2588\u2591-\u2593\u25A1\u25AA\u25AB\u25AD\u25AE\u25B1\u25B3-\u25B5\u25B8\u25B9\u25BD-\u25BF\u25C2\u25C3\u25CA\u25CB\u25EC\u25EF\u25F8-\u25FC\u2605\u2606\u260E\u2640\u2642\u2660\u2663\u2665\u2666\u266A\u266D-\u266F\u2713\u2717\u2720\u2736\u2758\u2772\u2773\u27C8\u27C9\u27E6-\u27ED\u27F5-\u27FA\u27FC\u27FF\u2902-\u2905\u290C-\u2913\u2916\u2919-\u2920\u2923-\u292A\u2933\u2935-\u2939\u293C\u293D\u2945\u2948-\u294B\u294E-\u2976\u2978\u2979\u297B-\u297F\u2985\u2986\u298B-\u2996\u299A\u299C\u299D\u29A4-\u29B7\u29B9\u29BB\u29BC\u29BE-\u29C5\u29C9\u29CD-\u29D0\u29DC-\u29DE\u29E3-\u29E5\u29EB\u29F4\u29F6\u2A00-\u2A02\u2A04\u2A06\u2A0C\u2A0D\u2A10-\u2A17\u2A22-\u2A27\u2A29\u2A2A\u2A2D-\u2A31\u2A33-\u2A3C\u2A3F\u2A40\u2A42-\u2A4D\u2A50\u2A53-\u2A58\u2A5A-\u2A5D\u2A5F\u2A66\u2A6A\u2A6D-\u2A75\u2A77-\u2A9A\u2A9D-\u2AA2\u2AA4-\u2AB0\u2AB3-\u2AC8\u2ACB\u2ACC\u2ACF-\u2ADB\u2AE4\u2AE6-\u2AE9\u2AEB-\u2AF3\u2AFD\uFB00-\uFB04]|\uD835[\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDCCF\uDD04\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDD6B]/g;
  16155. var encodeMap = {'\xC1':'Aacute','\xE1':'aacute','\u0102':'Abreve','\u0103':'abreve','\u223E':'ac','\u223F':'acd','\u223E\u0333':'acE','\xC2':'Acirc','\xE2':'acirc','\xB4':'acute','\u0410':'Acy','\u0430':'acy','\xC6':'AElig','\xE6':'aelig','\u2061':'af','\uD835\uDD04':'Afr','\uD835\uDD1E':'afr','\xC0':'Agrave','\xE0':'agrave','\u2135':'aleph','\u0391':'Alpha','\u03B1':'alpha','\u0100':'Amacr','\u0101':'amacr','\u2A3F':'amalg','&':'amp','\u2A55':'andand','\u2A53':'And','\u2227':'and','\u2A5C':'andd','\u2A58':'andslope','\u2A5A':'andv','\u2220':'ang','\u29A4':'ange','\u29A8':'angmsdaa','\u29A9':'angmsdab','\u29AA':'angmsdac','\u29AB':'angmsdad','\u29AC':'angmsdae','\u29AD':'angmsdaf','\u29AE':'angmsdag','\u29AF':'angmsdah','\u2221':'angmsd','\u221F':'angrt','\u22BE':'angrtvb','\u299D':'angrtvbd','\u2222':'angsph','\xC5':'angst','\u237C':'angzarr','\u0104':'Aogon','\u0105':'aogon','\uD835\uDD38':'Aopf','\uD835\uDD52':'aopf','\u2A6F':'apacir','\u2248':'ap','\u2A70':'apE','\u224A':'ape','\u224B':'apid','\'':'apos','\xE5':'aring','\uD835\uDC9C':'Ascr','\uD835\uDCB6':'ascr','\u2254':'colone','*':'ast','\u224D':'CupCap','\xC3':'Atilde','\xE3':'atilde','\xC4':'Auml','\xE4':'auml','\u2233':'awconint','\u2A11':'awint','\u224C':'bcong','\u03F6':'bepsi','\u2035':'bprime','\u223D':'bsim','\u22CD':'bsime','\u2216':'setmn','\u2AE7':'Barv','\u22BD':'barvee','\u2305':'barwed','\u2306':'Barwed','\u23B5':'bbrk','\u23B6':'bbrktbrk','\u0411':'Bcy','\u0431':'bcy','\u201E':'bdquo','\u2235':'becaus','\u29B0':'bemptyv','\u212C':'Bscr','\u0392':'Beta','\u03B2':'beta','\u2136':'beth','\u226C':'twixt','\uD835\uDD05':'Bfr','\uD835\uDD1F':'bfr','\u22C2':'xcap','\u25EF':'xcirc','\u22C3':'xcup','\u2A00':'xodot','\u2A01':'xoplus','\u2A02':'xotime','\u2A06':'xsqcup','\u2605':'starf','\u25BD':'xdtri','\u25B3':'xutri','\u2A04':'xuplus','\u22C1':'Vee','\u22C0':'Wedge','\u290D':'rbarr','\u29EB':'lozf','\u25AA':'squf','\u25B4':'utrif','\u25BE':'dtrif','\u25C2':'ltrif','\u25B8':'rtrif','\u2423':'blank','\u2592':'blk12','\u2591':'blk14','\u2593':'blk34','\u2588':'block','=\u20E5':'bne','\u2261\u20E5':'bnequiv','\u2AED':'bNot','\u2310':'bnot','\uD835\uDD39':'Bopf','\uD835\uDD53':'bopf','\u22A5':'bot','\u22C8':'bowtie','\u29C9':'boxbox','\u2510':'boxdl','\u2555':'boxdL','\u2556':'boxDl','\u2557':'boxDL','\u250C':'boxdr','\u2552':'boxdR','\u2553':'boxDr','\u2554':'boxDR','\u2500':'boxh','\u2550':'boxH','\u252C':'boxhd','\u2564':'boxHd','\u2565':'boxhD','\u2566':'boxHD','\u2534':'boxhu','\u2567':'boxHu','\u2568':'boxhU','\u2569':'boxHU','\u229F':'minusb','\u229E':'plusb','\u22A0':'timesb','\u2518':'boxul','\u255B':'boxuL','\u255C':'boxUl','\u255D':'boxUL','\u2514':'boxur','\u2558':'boxuR','\u2559':'boxUr','\u255A':'boxUR','\u2502':'boxv','\u2551':'boxV','\u253C':'boxvh','\u256A':'boxvH','\u256B':'boxVh','\u256C':'boxVH','\u2524':'boxvl','\u2561':'boxvL','\u2562':'boxVl','\u2563':'boxVL','\u251C':'boxvr','\u255E':'boxvR','\u255F':'boxVr','\u2560':'boxVR','\u02D8':'breve','\xA6':'brvbar','\uD835\uDCB7':'bscr','\u204F':'bsemi','\u29C5':'bsolb','\\':'bsol','\u27C8':'bsolhsub','\u2022':'bull','\u224E':'bump','\u2AAE':'bumpE','\u224F':'bumpe','\u0106':'Cacute','\u0107':'cacute','\u2A44':'capand','\u2A49':'capbrcup','\u2A4B':'capcap','\u2229':'cap','\u22D2':'Cap','\u2A47':'capcup','\u2A40':'capdot','\u2145':'DD','\u2229\uFE00':'caps','\u2041':'caret','\u02C7':'caron','\u212D':'Cfr','\u2A4D':'ccaps','\u010C':'Ccaron','\u010D':'ccaron','\xC7':'Ccedil','\xE7':'ccedil','\u0108':'Ccirc','\u0109':'ccirc','\u2230':'Cconint','\u2A4C':'ccups','\u2A50':'ccupssm','\u010A':'Cdot','\u010B':'cdot','\xB8':'cedil','\u29B2':'cemptyv','\xA2':'cent','\xB7':'middot','\uD835\uDD20':'cfr','\u0427':'CHcy','\u0447':'chcy','\u2713':'check','\u03A7':'Chi','\u03C7':'chi','\u02C6':'circ','\u2257':'cire','\u21BA':'olarr','\u21BB':'orarr','\u229B':'oast','\u229A':'ocir','\u229D':'odash','\u2299':'odot','\xAE':'reg','\u24C8':'oS','\u2296':'ominus','\u2295':'oplus','\u2297':'otimes','\u25CB':'cir','\u29C3':'cirE','\u2A10':'cirfnint','\u2AEF':'cirmid','\u29C2':'cirscir','\u2232':'cwconint','\u201D':'rdquo','\u2019':'rsquo','\u2663':'clubs',':':'colon','\u2237':'Colon','\u2A74':'Colone',',':'comma','@':'commat','\u2201':'comp','\u2218':'compfn','\u2102':'Copf','\u2245':'cong','\u2A6D':'congdot','\u2261':'equiv','\u222E':'oint','\u222F':'Conint','\uD835\uDD54':'copf','\u2210':'coprod','\xA9':'copy','\u2117':'copysr','\u21B5':'crarr','\u2717':'cross','\u2A2F':'Cross','\uD835\uDC9E':'Cscr','\uD835\uDCB8':'cscr','\u2ACF':'csub','\u2AD1':'csube','\u2AD0':'csup','\u2AD2':'csupe','\u22EF':'ctdot','\u2938':'cudarrl','\u2935':'cudarrr','\u22DE':'cuepr','\u22DF':'cuesc','\u21B6':'cularr','\u293D':'cularrp','\u2A48':'cupbrcap','\u2A46':'cupcap','\u222A':'cup','\u22D3':'Cup','\u2A4A':'cupcup','\u228D':'cupdot','\u2A45':'cupor','\u222A\uFE00':'cups','\u21B7':'curarr','\u293C':'curarrm','\u22CE':'cuvee','\u22CF':'cuwed','\xA4':'curren','\u2231':'cwint','\u232D':'cylcty','\u2020':'dagger','\u2021':'Dagger','\u2138':'daleth','\u2193':'darr','\u21A1':'Darr','\u21D3':'dArr','\u2010':'dash','\u2AE4':'Dashv','\u22A3':'dashv','\u290F':'rBarr','\u02DD':'dblac','\u010E':'Dcaron','\u010F':'dcaron','\u0414':'Dcy','\u0434':'dcy','\u21CA':'ddarr','\u2146':'dd','\u2911':'DDotrahd','\u2A77':'eDDot','\xB0':'deg','\u2207':'Del','\u0394':'Delta','\u03B4':'delta','\u29B1':'demptyv','\u297F':'dfisht','\uD835\uDD07':'Dfr','\uD835\uDD21':'dfr','\u2965':'dHar','\u21C3':'dharl','\u21C2':'dharr','\u02D9':'dot','`':'grave','\u02DC':'tilde','\u22C4':'diam','\u2666':'diams','\xA8':'die','\u03DD':'gammad','\u22F2':'disin','\xF7':'div','\u22C7':'divonx','\u0402':'DJcy','\u0452':'djcy','\u231E':'dlcorn','\u230D':'dlcrop','$':'dollar','\uD835\uDD3B':'Dopf','\uD835\uDD55':'dopf','\u20DC':'DotDot','\u2250':'doteq','\u2251':'eDot','\u2238':'minusd','\u2214':'plusdo','\u22A1':'sdotb','\u21D0':'lArr','\u21D4':'iff','\u27F8':'xlArr','\u27FA':'xhArr','\u27F9':'xrArr','\u21D2':'rArr','\u22A8':'vDash','\u21D1':'uArr','\u21D5':'vArr','\u2225':'par','\u2913':'DownArrowBar','\u21F5':'duarr','\u0311':'DownBreve','\u2950':'DownLeftRightVector','\u295E':'DownLeftTeeVector','\u2956':'DownLeftVectorBar','\u21BD':'lhard','\u295F':'DownRightTeeVector','\u2957':'DownRightVectorBar','\u21C1':'rhard','\u21A7':'mapstodown','\u22A4':'top','\u2910':'RBarr','\u231F':'drcorn','\u230C':'drcrop','\uD835\uDC9F':'Dscr','\uD835\uDCB9':'dscr','\u0405':'DScy','\u0455':'dscy','\u29F6':'dsol','\u0110':'Dstrok','\u0111':'dstrok','\u22F1':'dtdot','\u25BF':'dtri','\u296F':'duhar','\u29A6':'dwangle','\u040F':'DZcy','\u045F':'dzcy','\u27FF':'dzigrarr','\xC9':'Eacute','\xE9':'eacute','\u2A6E':'easter','\u011A':'Ecaron','\u011B':'ecaron','\xCA':'Ecirc','\xEA':'ecirc','\u2256':'ecir','\u2255':'ecolon','\u042D':'Ecy','\u044D':'ecy','\u0116':'Edot','\u0117':'edot','\u2147':'ee','\u2252':'efDot','\uD835\uDD08':'Efr','\uD835\uDD22':'efr','\u2A9A':'eg','\xC8':'Egrave','\xE8':'egrave','\u2A96':'egs','\u2A98':'egsdot','\u2A99':'el','\u2208':'in','\u23E7':'elinters','\u2113':'ell','\u2A95':'els','\u2A97':'elsdot','\u0112':'Emacr','\u0113':'emacr','\u2205':'empty','\u25FB':'EmptySmallSquare','\u25AB':'EmptyVerySmallSquare','\u2004':'emsp13','\u2005':'emsp14','\u2003':'emsp','\u014A':'ENG','\u014B':'eng','\u2002':'ensp','\u0118':'Eogon','\u0119':'eogon','\uD835\uDD3C':'Eopf','\uD835\uDD56':'eopf','\u22D5':'epar','\u29E3':'eparsl','\u2A71':'eplus','\u03B5':'epsi','\u0395':'Epsilon','\u03F5':'epsiv','\u2242':'esim','\u2A75':'Equal','=':'equals','\u225F':'equest','\u21CC':'rlhar','\u2A78':'equivDD','\u29E5':'eqvparsl','\u2971':'erarr','\u2253':'erDot','\u212F':'escr','\u2130':'Escr','\u2A73':'Esim','\u0397':'Eta','\u03B7':'eta','\xD0':'ETH','\xF0':'eth','\xCB':'Euml','\xEB':'euml','\u20AC':'euro','!':'excl','\u2203':'exist','\u0424':'Fcy','\u0444':'fcy','\u2640':'female','\uFB03':'ffilig','\uFB00':'fflig','\uFB04':'ffllig','\uD835\uDD09':'Ffr','\uD835\uDD23':'ffr','\uFB01':'filig','\u25FC':'FilledSmallSquare','fj':'fjlig','\u266D':'flat','\uFB02':'fllig','\u25B1':'fltns','\u0192':'fnof','\uD835\uDD3D':'Fopf','\uD835\uDD57':'fopf','\u2200':'forall','\u22D4':'fork','\u2AD9':'forkv','\u2131':'Fscr','\u2A0D':'fpartint','\xBD':'half','\u2153':'frac13','\xBC':'frac14','\u2155':'frac15','\u2159':'frac16','\u215B':'frac18','\u2154':'frac23','\u2156':'frac25','\xBE':'frac34','\u2157':'frac35','\u215C':'frac38','\u2158':'frac45','\u215A':'frac56','\u215D':'frac58','\u215E':'frac78','\u2044':'frasl','\u2322':'frown','\uD835\uDCBB':'fscr','\u01F5':'gacute','\u0393':'Gamma','\u03B3':'gamma','\u03DC':'Gammad','\u2A86':'gap','\u011E':'Gbreve','\u011F':'gbreve','\u0122':'Gcedil','\u011C':'Gcirc','\u011D':'gcirc','\u0413':'Gcy','\u0433':'gcy','\u0120':'Gdot','\u0121':'gdot','\u2265':'ge','\u2267':'gE','\u2A8C':'gEl','\u22DB':'gel','\u2A7E':'ges','\u2AA9':'gescc','\u2A80':'gesdot','\u2A82':'gesdoto','\u2A84':'gesdotol','\u22DB\uFE00':'gesl','\u2A94':'gesles','\uD835\uDD0A':'Gfr','\uD835\uDD24':'gfr','\u226B':'gg','\u22D9':'Gg','\u2137':'gimel','\u0403':'GJcy','\u0453':'gjcy','\u2AA5':'gla','\u2277':'gl','\u2A92':'glE','\u2AA4':'glj','\u2A8A':'gnap','\u2A88':'gne','\u2269':'gnE','\u22E7':'gnsim','\uD835\uDD3E':'Gopf','\uD835\uDD58':'gopf','\u2AA2':'GreaterGreater','\u2273':'gsim','\uD835\uDCA2':'Gscr','\u210A':'gscr','\u2A8E':'gsime','\u2A90':'gsiml','\u2AA7':'gtcc','\u2A7A':'gtcir','>':'gt','\u22D7':'gtdot','\u2995':'gtlPar','\u2A7C':'gtquest','\u2978':'gtrarr','\u2269\uFE00':'gvnE','\u200A':'hairsp','\u210B':'Hscr','\u042A':'HARDcy','\u044A':'hardcy','\u2948':'harrcir','\u2194':'harr','\u21AD':'harrw','^':'Hat','\u210F':'hbar','\u0124':'Hcirc','\u0125':'hcirc','\u2665':'hearts','\u2026':'mldr','\u22B9':'hercon','\uD835\uDD25':'hfr','\u210C':'Hfr','\u2925':'searhk','\u2926':'swarhk','\u21FF':'hoarr','\u223B':'homtht','\u21A9':'larrhk','\u21AA':'rarrhk','\uD835\uDD59':'hopf','\u210D':'Hopf','\u2015':'horbar','\uD835\uDCBD':'hscr','\u0126':'Hstrok','\u0127':'hstrok','\u2043':'hybull','\xCD':'Iacute','\xED':'iacute','\u2063':'ic','\xCE':'Icirc','\xEE':'icirc','\u0418':'Icy','\u0438':'icy','\u0130':'Idot','\u0415':'IEcy','\u0435':'iecy','\xA1':'iexcl','\uD835\uDD26':'ifr','\u2111':'Im','\xCC':'Igrave','\xEC':'igrave','\u2148':'ii','\u2A0C':'qint','\u222D':'tint','\u29DC':'iinfin','\u2129':'iiota','\u0132':'IJlig','\u0133':'ijlig','\u012A':'Imacr','\u012B':'imacr','\u2110':'Iscr','\u0131':'imath','\u22B7':'imof','\u01B5':'imped','\u2105':'incare','\u221E':'infin','\u29DD':'infintie','\u22BA':'intcal','\u222B':'int','\u222C':'Int','\u2124':'Zopf','\u2A17':'intlarhk','\u2A3C':'iprod','\u2062':'it','\u0401':'IOcy','\u0451':'iocy','\u012E':'Iogon','\u012F':'iogon','\uD835\uDD40':'Iopf','\uD835\uDD5A':'iopf','\u0399':'Iota','\u03B9':'iota','\xBF':'iquest','\uD835\uDCBE':'iscr','\u22F5':'isindot','\u22F9':'isinE','\u22F4':'isins','\u22F3':'isinsv','\u0128':'Itilde','\u0129':'itilde','\u0406':'Iukcy','\u0456':'iukcy','\xCF':'Iuml','\xEF':'iuml','\u0134':'Jcirc','\u0135':'jcirc','\u0419':'Jcy','\u0439':'jcy','\uD835\uDD0D':'Jfr','\uD835\uDD27':'jfr','\u0237':'jmath','\uD835\uDD41':'Jopf','\uD835\uDD5B':'jopf','\uD835\uDCA5':'Jscr','\uD835\uDCBF':'jscr','\u0408':'Jsercy','\u0458':'jsercy','\u0404':'Jukcy','\u0454':'jukcy','\u039A':'Kappa','\u03BA':'kappa','\u03F0':'kappav','\u0136':'Kcedil','\u0137':'kcedil','\u041A':'Kcy','\u043A':'kcy','\uD835\uDD0E':'Kfr','\uD835\uDD28':'kfr','\u0138':'kgreen','\u0425':'KHcy','\u0445':'khcy','\u040C':'KJcy','\u045C':'kjcy','\uD835\uDD42':'Kopf','\uD835\uDD5C':'kopf','\uD835\uDCA6':'Kscr','\uD835\uDCC0':'kscr','\u21DA':'lAarr','\u0139':'Lacute','\u013A':'lacute','\u29B4':'laemptyv','\u2112':'Lscr','\u039B':'Lambda','\u03BB':'lambda','\u27E8':'lang','\u27EA':'Lang','\u2991':'langd','\u2A85':'lap','\xAB':'laquo','\u21E4':'larrb','\u291F':'larrbfs','\u2190':'larr','\u219E':'Larr','\u291D':'larrfs','\u21AB':'larrlp','\u2939':'larrpl','\u2973':'larrsim','\u21A2':'larrtl','\u2919':'latail','\u291B':'lAtail','\u2AAB':'lat','\u2AAD':'late','\u2AAD\uFE00':'lates','\u290C':'lbarr','\u290E':'lBarr','\u2772':'lbbrk','{':'lcub','[':'lsqb','\u298B':'lbrke','\u298F':'lbrksld','\u298D':'lbrkslu','\u013D':'Lcaron','\u013E':'lcaron','\u013B':'Lcedil','\u013C':'lcedil','\u2308':'lceil','\u041B':'Lcy','\u043B':'lcy','\u2936':'ldca','\u201C':'ldquo','\u2967':'ldrdhar','\u294B':'ldrushar','\u21B2':'ldsh','\u2264':'le','\u2266':'lE','\u21C6':'lrarr','\u27E6':'lobrk','\u2961':'LeftDownTeeVector','\u2959':'LeftDownVectorBar','\u230A':'lfloor','\u21BC':'lharu','\u21C7':'llarr','\u21CB':'lrhar','\u294E':'LeftRightVector','\u21A4':'mapstoleft','\u295A':'LeftTeeVector','\u22CB':'lthree','\u29CF':'LeftTriangleBar','\u22B2':'vltri','\u22B4':'ltrie','\u2951':'LeftUpDownVector','\u2960':'LeftUpTeeVector','\u2958':'LeftUpVectorBar','\u21BF':'uharl','\u2952':'LeftVectorBar','\u2A8B':'lEg','\u22DA':'leg','\u2A7D':'les','\u2AA8':'lescc','\u2A7F':'lesdot','\u2A81':'lesdoto','\u2A83':'lesdotor','\u22DA\uFE00':'lesg','\u2A93':'lesges','\u22D6':'ltdot','\u2276':'lg','\u2AA1':'LessLess','\u2272':'lsim','\u297C':'lfisht','\uD835\uDD0F':'Lfr','\uD835\uDD29':'lfr','\u2A91':'lgE','\u2962':'lHar','\u296A':'lharul','\u2584':'lhblk','\u0409':'LJcy','\u0459':'ljcy','\u226A':'ll','\u22D8':'Ll','\u296B':'llhard','\u25FA':'lltri','\u013F':'Lmidot','\u0140':'lmidot','\u23B0':'lmoust','\u2A89':'lnap','\u2A87':'lne','\u2268':'lnE','\u22E6':'lnsim','\u27EC':'loang','\u21FD':'loarr','\u27F5':'xlarr','\u27F7':'xharr','\u27FC':'xmap','\u27F6':'xrarr','\u21AC':'rarrlp','\u2985':'lopar','\uD835\uDD43':'Lopf','\uD835\uDD5D':'lopf','\u2A2D':'loplus','\u2A34':'lotimes','\u2217':'lowast','_':'lowbar','\u2199':'swarr','\u2198':'searr','\u25CA':'loz','(':'lpar','\u2993':'lparlt','\u296D':'lrhard','\u200E':'lrm','\u22BF':'lrtri','\u2039':'lsaquo','\uD835\uDCC1':'lscr','\u21B0':'lsh','\u2A8D':'lsime','\u2A8F':'lsimg','\u2018':'lsquo','\u201A':'sbquo','\u0141':'Lstrok','\u0142':'lstrok','\u2AA6':'ltcc','\u2A79':'ltcir','<':'lt','\u22C9':'ltimes','\u2976':'ltlarr','\u2A7B':'ltquest','\u25C3':'ltri','\u2996':'ltrPar','\u294A':'lurdshar','\u2966':'luruhar','\u2268\uFE00':'lvnE','\xAF':'macr','\u2642':'male','\u2720':'malt','\u2905':'Map','\u21A6':'map','\u21A5':'mapstoup','\u25AE':'marker','\u2A29':'mcomma','\u041C':'Mcy','\u043C':'mcy','\u2014':'mdash','\u223A':'mDDot','\u205F':'MediumSpace','\u2133':'Mscr','\uD835\uDD10':'Mfr','\uD835\uDD2A':'mfr','\u2127':'mho','\xB5':'micro','\u2AF0':'midcir','\u2223':'mid','\u2212':'minus','\u2A2A':'minusdu','\u2213':'mp','\u2ADB':'mlcp','\u22A7':'models','\uD835\uDD44':'Mopf','\uD835\uDD5E':'mopf','\uD835\uDCC2':'mscr','\u039C':'Mu','\u03BC':'mu','\u22B8':'mumap','\u0143':'Nacute','\u0144':'nacute','\u2220\u20D2':'nang','\u2249':'nap','\u2A70\u0338':'napE','\u224B\u0338':'napid','\u0149':'napos','\u266E':'natur','\u2115':'Nopf','\xA0':'nbsp','\u224E\u0338':'nbump','\u224F\u0338':'nbumpe','\u2A43':'ncap','\u0147':'Ncaron','\u0148':'ncaron','\u0145':'Ncedil','\u0146':'ncedil','\u2247':'ncong','\u2A6D\u0338':'ncongdot','\u2A42':'ncup','\u041D':'Ncy','\u043D':'ncy','\u2013':'ndash','\u2924':'nearhk','\u2197':'nearr','\u21D7':'neArr','\u2260':'ne','\u2250\u0338':'nedot','\u200B':'ZeroWidthSpace','\u2262':'nequiv','\u2928':'toea','\u2242\u0338':'nesim','\n':'NewLine','\u2204':'nexist','\uD835\uDD11':'Nfr','\uD835\uDD2B':'nfr','\u2267\u0338':'ngE','\u2271':'nge','\u2A7E\u0338':'nges','\u22D9\u0338':'nGg','\u2275':'ngsim','\u226B\u20D2':'nGt','\u226F':'ngt','\u226B\u0338':'nGtv','\u21AE':'nharr','\u21CE':'nhArr','\u2AF2':'nhpar','\u220B':'ni','\u22FC':'nis','\u22FA':'nisd','\u040A':'NJcy','\u045A':'njcy','\u219A':'nlarr','\u21CD':'nlArr','\u2025':'nldr','\u2266\u0338':'nlE','\u2270':'nle','\u2A7D\u0338':'nles','\u226E':'nlt','\u22D8\u0338':'nLl','\u2274':'nlsim','\u226A\u20D2':'nLt','\u22EA':'nltri','\u22EC':'nltrie','\u226A\u0338':'nLtv','\u2224':'nmid','\u2060':'NoBreak','\uD835\uDD5F':'nopf','\u2AEC':'Not','\xAC':'not','\u226D':'NotCupCap','\u2226':'npar','\u2209':'notin','\u2279':'ntgl','\u22F5\u0338':'notindot','\u22F9\u0338':'notinE','\u22F7':'notinvb','\u22F6':'notinvc','\u29CF\u0338':'NotLeftTriangleBar','\u2278':'ntlg','\u2AA2\u0338':'NotNestedGreaterGreater','\u2AA1\u0338':'NotNestedLessLess','\u220C':'notni','\u22FE':'notnivb','\u22FD':'notnivc','\u2280':'npr','\u2AAF\u0338':'npre','\u22E0':'nprcue','\u29D0\u0338':'NotRightTriangleBar','\u22EB':'nrtri','\u22ED':'nrtrie','\u228F\u0338':'NotSquareSubset','\u22E2':'nsqsube','\u2290\u0338':'NotSquareSuperset','\u22E3':'nsqsupe','\u2282\u20D2':'vnsub','\u2288':'nsube','\u2281':'nsc','\u2AB0\u0338':'nsce','\u22E1':'nsccue','\u227F\u0338':'NotSucceedsTilde','\u2283\u20D2':'vnsup','\u2289':'nsupe','\u2241':'nsim','\u2244':'nsime','\u2AFD\u20E5':'nparsl','\u2202\u0338':'npart','\u2A14':'npolint','\u2933\u0338':'nrarrc','\u219B':'nrarr','\u21CF':'nrArr','\u219D\u0338':'nrarrw','\uD835\uDCA9':'Nscr','\uD835\uDCC3':'nscr','\u2284':'nsub','\u2AC5\u0338':'nsubE','\u2285':'nsup','\u2AC6\u0338':'nsupE','\xD1':'Ntilde','\xF1':'ntilde','\u039D':'Nu','\u03BD':'nu','#':'num','\u2116':'numero','\u2007':'numsp','\u224D\u20D2':'nvap','\u22AC':'nvdash','\u22AD':'nvDash','\u22AE':'nVdash','\u22AF':'nVDash','\u2265\u20D2':'nvge','>\u20D2':'nvgt','\u2904':'nvHarr','\u29DE':'nvinfin','\u2902':'nvlArr','\u2264\u20D2':'nvle','<\u20D2':'nvlt','\u22B4\u20D2':'nvltrie','\u2903':'nvrArr','\u22B5\u20D2':'nvrtrie','\u223C\u20D2':'nvsim','\u2923':'nwarhk','\u2196':'nwarr','\u21D6':'nwArr','\u2927':'nwnear','\xD3':'Oacute','\xF3':'oacute','\xD4':'Ocirc','\xF4':'ocirc','\u041E':'Ocy','\u043E':'ocy','\u0150':'Odblac','\u0151':'odblac','\u2A38':'odiv','\u29BC':'odsold','\u0152':'OElig','\u0153':'oelig','\u29BF':'ofcir','\uD835\uDD12':'Ofr','\uD835\uDD2C':'ofr','\u02DB':'ogon','\xD2':'Ograve','\xF2':'ograve','\u29C1':'ogt','\u29B5':'ohbar','\u03A9':'ohm','\u29BE':'olcir','\u29BB':'olcross','\u203E':'oline','\u29C0':'olt','\u014C':'Omacr','\u014D':'omacr','\u03C9':'omega','\u039F':'Omicron','\u03BF':'omicron','\u29B6':'omid','\uD835\uDD46':'Oopf','\uD835\uDD60':'oopf','\u29B7':'opar','\u29B9':'operp','\u2A54':'Or','\u2228':'or','\u2A5D':'ord','\u2134':'oscr','\xAA':'ordf','\xBA':'ordm','\u22B6':'origof','\u2A56':'oror','\u2A57':'orslope','\u2A5B':'orv','\uD835\uDCAA':'Oscr','\xD8':'Oslash','\xF8':'oslash','\u2298':'osol','\xD5':'Otilde','\xF5':'otilde','\u2A36':'otimesas','\u2A37':'Otimes','\xD6':'Ouml','\xF6':'ouml','\u233D':'ovbar','\u23DE':'OverBrace','\u23B4':'tbrk','\u23DC':'OverParenthesis','\xB6':'para','\u2AF3':'parsim','\u2AFD':'parsl','\u2202':'part','\u041F':'Pcy','\u043F':'pcy','%':'percnt','.':'period','\u2030':'permil','\u2031':'pertenk','\uD835\uDD13':'Pfr','\uD835\uDD2D':'pfr','\u03A6':'Phi','\u03C6':'phi','\u03D5':'phiv','\u260E':'phone','\u03A0':'Pi','\u03C0':'pi','\u03D6':'piv','\u210E':'planckh','\u2A23':'plusacir','\u2A22':'pluscir','+':'plus','\u2A25':'plusdu','\u2A72':'pluse','\xB1':'pm','\u2A26':'plussim','\u2A27':'plustwo','\u2A15':'pointint','\uD835\uDD61':'popf','\u2119':'Popf','\xA3':'pound','\u2AB7':'prap','\u2ABB':'Pr','\u227A':'pr','\u227C':'prcue','\u2AAF':'pre','\u227E':'prsim','\u2AB9':'prnap','\u2AB5':'prnE','\u22E8':'prnsim','\u2AB3':'prE','\u2032':'prime','\u2033':'Prime','\u220F':'prod','\u232E':'profalar','\u2312':'profline','\u2313':'profsurf','\u221D':'prop','\u22B0':'prurel','\uD835\uDCAB':'Pscr','\uD835\uDCC5':'pscr','\u03A8':'Psi','\u03C8':'psi','\u2008':'puncsp','\uD835\uDD14':'Qfr','\uD835\uDD2E':'qfr','\uD835\uDD62':'qopf','\u211A':'Qopf','\u2057':'qprime','\uD835\uDCAC':'Qscr','\uD835\uDCC6':'qscr','\u2A16':'quatint','?':'quest','"':'quot','\u21DB':'rAarr','\u223D\u0331':'race','\u0154':'Racute','\u0155':'racute','\u221A':'Sqrt','\u29B3':'raemptyv','\u27E9':'rang','\u27EB':'Rang','\u2992':'rangd','\u29A5':'range','\xBB':'raquo','\u2975':'rarrap','\u21E5':'rarrb','\u2920':'rarrbfs','\u2933':'rarrc','\u2192':'rarr','\u21A0':'Rarr','\u291E':'rarrfs','\u2945':'rarrpl','\u2974':'rarrsim','\u2916':'Rarrtl','\u21A3':'rarrtl','\u219D':'rarrw','\u291A':'ratail','\u291C':'rAtail','\u2236':'ratio','\u2773':'rbbrk','}':'rcub',']':'rsqb','\u298C':'rbrke','\u298E':'rbrksld','\u2990':'rbrkslu','\u0158':'Rcaron','\u0159':'rcaron','\u0156':'Rcedil','\u0157':'rcedil','\u2309':'rceil','\u0420':'Rcy','\u0440':'rcy','\u2937':'rdca','\u2969':'rdldhar','\u21B3':'rdsh','\u211C':'Re','\u211B':'Rscr','\u211D':'Ropf','\u25AD':'rect','\u297D':'rfisht','\u230B':'rfloor','\uD835\uDD2F':'rfr','\u2964':'rHar','\u21C0':'rharu','\u296C':'rharul','\u03A1':'Rho','\u03C1':'rho','\u03F1':'rhov','\u21C4':'rlarr','\u27E7':'robrk','\u295D':'RightDownTeeVector','\u2955':'RightDownVectorBar','\u21C9':'rrarr','\u22A2':'vdash','\u295B':'RightTeeVector','\u22CC':'rthree','\u29D0':'RightTriangleBar','\u22B3':'vrtri','\u22B5':'rtrie','\u294F':'RightUpDownVector','\u295C':'RightUpTeeVector','\u2954':'RightUpVectorBar','\u21BE':'uharr','\u2953':'RightVectorBar','\u02DA':'ring','\u200F':'rlm','\u23B1':'rmoust','\u2AEE':'rnmid','\u27ED':'roang','\u21FE':'roarr','\u2986':'ropar','\uD835\uDD63':'ropf','\u2A2E':'roplus','\u2A35':'rotimes','\u2970':'RoundImplies',')':'rpar','\u2994':'rpargt','\u2A12':'rppolint','\u203A':'rsaquo','\uD835\uDCC7':'rscr','\u21B1':'rsh','\u22CA':'rtimes','\u25B9':'rtri','\u29CE':'rtriltri','\u29F4':'RuleDelayed','\u2968':'ruluhar','\u211E':'rx','\u015A':'Sacute','\u015B':'sacute','\u2AB8':'scap','\u0160':'Scaron','\u0161':'scaron','\u2ABC':'Sc','\u227B':'sc','\u227D':'sccue','\u2AB0':'sce','\u2AB4':'scE','\u015E':'Scedil','\u015F':'scedil','\u015C':'Scirc','\u015D':'scirc','\u2ABA':'scnap','\u2AB6':'scnE','\u22E9':'scnsim','\u2A13':'scpolint','\u227F':'scsim','\u0421':'Scy','\u0441':'scy','\u22C5':'sdot','\u2A66':'sdote','\u21D8':'seArr','\xA7':'sect',';':'semi','\u2929':'tosa','\u2736':'sext','\uD835\uDD16':'Sfr','\uD835\uDD30':'sfr','\u266F':'sharp','\u0429':'SHCHcy','\u0449':'shchcy','\u0428':'SHcy','\u0448':'shcy','\u2191':'uarr','\xAD':'shy','\u03A3':'Sigma','\u03C3':'sigma','\u03C2':'sigmaf','\u223C':'sim','\u2A6A':'simdot','\u2243':'sime','\u2A9E':'simg','\u2AA0':'simgE','\u2A9D':'siml','\u2A9F':'simlE','\u2246':'simne','\u2A24':'simplus','\u2972':'simrarr','\u2A33':'smashp','\u29E4':'smeparsl','\u2323':'smile','\u2AAA':'smt','\u2AAC':'smte','\u2AAC\uFE00':'smtes','\u042C':'SOFTcy','\u044C':'softcy','\u233F':'solbar','\u29C4':'solb','/':'sol','\uD835\uDD4A':'Sopf','\uD835\uDD64':'sopf','\u2660':'spades','\u2293':'sqcap','\u2293\uFE00':'sqcaps','\u2294':'sqcup','\u2294\uFE00':'sqcups','\u228F':'sqsub','\u2291':'sqsube','\u2290':'sqsup','\u2292':'sqsupe','\u25A1':'squ','\uD835\uDCAE':'Sscr','\uD835\uDCC8':'sscr','\u22C6':'Star','\u2606':'star','\u2282':'sub','\u22D0':'Sub','\u2ABD':'subdot','\u2AC5':'subE','\u2286':'sube','\u2AC3':'subedot','\u2AC1':'submult','\u2ACB':'subnE','\u228A':'subne','\u2ABF':'subplus','\u2979':'subrarr','\u2AC7':'subsim','\u2AD5':'subsub','\u2AD3':'subsup','\u2211':'sum','\u266A':'sung','\xB9':'sup1','\xB2':'sup2','\xB3':'sup3','\u2283':'sup','\u22D1':'Sup','\u2ABE':'supdot','\u2AD8':'supdsub','\u2AC6':'supE','\u2287':'supe','\u2AC4':'supedot','\u27C9':'suphsol','\u2AD7':'suphsub','\u297B':'suplarr','\u2AC2':'supmult','\u2ACC':'supnE','\u228B':'supne','\u2AC0':'supplus','\u2AC8':'supsim','\u2AD4':'supsub','\u2AD6':'supsup','\u21D9':'swArr','\u292A':'swnwar','\xDF':'szlig','\t':'Tab','\u2316':'target','\u03A4':'Tau','\u03C4':'tau','\u0164':'Tcaron','\u0165':'tcaron','\u0162':'Tcedil','\u0163':'tcedil','\u0422':'Tcy','\u0442':'tcy','\u20DB':'tdot','\u2315':'telrec','\uD835\uDD17':'Tfr','\uD835\uDD31':'tfr','\u2234':'there4','\u0398':'Theta','\u03B8':'theta','\u03D1':'thetav','\u205F\u200A':'ThickSpace','\u2009':'thinsp','\xDE':'THORN','\xFE':'thorn','\u2A31':'timesbar','\xD7':'times','\u2A30':'timesd','\u2336':'topbot','\u2AF1':'topcir','\uD835\uDD4B':'Topf','\uD835\uDD65':'topf','\u2ADA':'topfork','\u2034':'tprime','\u2122':'trade','\u25B5':'utri','\u225C':'trie','\u25EC':'tridot','\u2A3A':'triminus','\u2A39':'triplus','\u29CD':'trisb','\u2A3B':'tritime','\u23E2':'trpezium','\uD835\uDCAF':'Tscr','\uD835\uDCC9':'tscr','\u0426':'TScy','\u0446':'tscy','\u040B':'TSHcy','\u045B':'tshcy','\u0166':'Tstrok','\u0167':'tstrok','\xDA':'Uacute','\xFA':'uacute','\u219F':'Uarr','\u2949':'Uarrocir','\u040E':'Ubrcy','\u045E':'ubrcy','\u016C':'Ubreve','\u016D':'ubreve','\xDB':'Ucirc','\xFB':'ucirc','\u0423':'Ucy','\u0443':'ucy','\u21C5':'udarr','\u0170':'Udblac','\u0171':'udblac','\u296E':'udhar','\u297E':'ufisht','\uD835\uDD18':'Ufr','\uD835\uDD32':'ufr','\xD9':'Ugrave','\xF9':'ugrave','\u2963':'uHar','\u2580':'uhblk','\u231C':'ulcorn','\u230F':'ulcrop','\u25F8':'ultri','\u016A':'Umacr','\u016B':'umacr','\u23DF':'UnderBrace','\u23DD':'UnderParenthesis','\u228E':'uplus','\u0172':'Uogon','\u0173':'uogon','\uD835\uDD4C':'Uopf','\uD835\uDD66':'uopf','\u2912':'UpArrowBar','\u2195':'varr','\u03C5':'upsi','\u03D2':'Upsi','\u03A5':'Upsilon','\u21C8':'uuarr','\u231D':'urcorn','\u230E':'urcrop','\u016E':'Uring','\u016F':'uring','\u25F9':'urtri','\uD835\uDCB0':'Uscr','\uD835\uDCCA':'uscr','\u22F0':'utdot','\u0168':'Utilde','\u0169':'utilde','\xDC':'Uuml','\xFC':'uuml','\u29A7':'uwangle','\u299C':'vangrt','\u228A\uFE00':'vsubne','\u2ACB\uFE00':'vsubnE','\u228B\uFE00':'vsupne','\u2ACC\uFE00':'vsupnE','\u2AE8':'vBar','\u2AEB':'Vbar','\u2AE9':'vBarv','\u0412':'Vcy','\u0432':'vcy','\u22A9':'Vdash','\u22AB':'VDash','\u2AE6':'Vdashl','\u22BB':'veebar','\u225A':'veeeq','\u22EE':'vellip','|':'vert','\u2016':'Vert','\u2758':'VerticalSeparator','\u2240':'wr','\uD835\uDD19':'Vfr','\uD835\uDD33':'vfr','\uD835\uDD4D':'Vopf','\uD835\uDD67':'vopf','\uD835\uDCB1':'Vscr','\uD835\uDCCB':'vscr','\u22AA':'Vvdash','\u299A':'vzigzag','\u0174':'Wcirc','\u0175':'wcirc','\u2A5F':'wedbar','\u2259':'wedgeq','\u2118':'wp','\uD835\uDD1A':'Wfr','\uD835\uDD34':'wfr','\uD835\uDD4E':'Wopf','\uD835\uDD68':'wopf','\uD835\uDCB2':'Wscr','\uD835\uDCCC':'wscr','\uD835\uDD1B':'Xfr','\uD835\uDD35':'xfr','\u039E':'Xi','\u03BE':'xi','\u22FB':'xnis','\uD835\uDD4F':'Xopf','\uD835\uDD69':'xopf','\uD835\uDCB3':'Xscr','\uD835\uDCCD':'xscr','\xDD':'Yacute','\xFD':'yacute','\u042F':'YAcy','\u044F':'yacy','\u0176':'Ycirc','\u0177':'ycirc','\u042B':'Ycy','\u044B':'ycy','\xA5':'yen','\uD835\uDD1C':'Yfr','\uD835\uDD36':'yfr','\u0407':'YIcy','\u0457':'yicy','\uD835\uDD50':'Yopf','\uD835\uDD6A':'yopf','\uD835\uDCB4':'Yscr','\uD835\uDCCE':'yscr','\u042E':'YUcy','\u044E':'yucy','\xFF':'yuml','\u0178':'Yuml','\u0179':'Zacute','\u017A':'zacute','\u017D':'Zcaron','\u017E':'zcaron','\u0417':'Zcy','\u0437':'zcy','\u017B':'Zdot','\u017C':'zdot','\u2128':'Zfr','\u0396':'Zeta','\u03B6':'zeta','\uD835\uDD37':'zfr','\u0416':'ZHcy','\u0436':'zhcy','\u21DD':'zigrarr','\uD835\uDD6B':'zopf','\uD835\uDCB5':'Zscr','\uD835\uDCCF':'zscr','\u200D':'zwj','\u200C':'zwnj'};
  16156. var regexEscape = /["&'<>`]/g;
  16157. var escapeMap = {
  16158. '"': '&quot;',
  16159. '&': '&amp;',
  16160. '\'': '&#x27;',
  16161. '<': '&lt;',
  16162. // See https://mathiasbynens.be/notes/ambiguous-ampersands: in HTML, the
  16163. // following is not strictly necessary unless it’s part of a tag or an
  16164. // unquoted attribute value. We’re only escaping it to support those
  16165. // situations, and for XML support.
  16166. '>': '&gt;',
  16167. // In Internet Explorer ≤ 8, the backtick character can be used
  16168. // to break out of (un)quoted attribute values or HTML comments.
  16169. // See http://html5sec.org/#102, http://html5sec.org/#108, and
  16170. // http://html5sec.org/#133.
  16171. '`': '&#x60;'
  16172. };
  16173. var regexInvalidEntity = /&#(?:[xX][^a-fA-F0-9]|[^0-9xX])/;
  16174. var regexInvalidRawCodePoint = /[\0-\x08\x0B\x0E-\x1F\x7F-\x9F\uFDD0-\uFDEF\uFFFE\uFFFF]|[\uD83F\uD87F\uD8BF\uD8FF\uD93F\uD97F\uD9BF\uD9FF\uDA3F\uDA7F\uDABF\uDAFF\uDB3F\uDB7F\uDBBF\uDBFF][\uDFFE\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
  16175. var regexDecode = /&#([0-9]+)(;?)|&#[xX]([a-fA-F0-9]+)(;?)|&([0-9a-zA-Z]+);|&(Aacute|iacute|Uacute|plusmn|otilde|Otilde|Agrave|agrave|yacute|Yacute|oslash|Oslash|Atilde|atilde|brvbar|Ccedil|ccedil|ograve|curren|divide|Eacute|eacute|Ograve|oacute|Egrave|egrave|ugrave|frac12|frac14|frac34|Ugrave|Oacute|Iacute|ntilde|Ntilde|uacute|middot|Igrave|igrave|iquest|aacute|laquo|THORN|micro|iexcl|icirc|Icirc|Acirc|ucirc|ecirc|Ocirc|ocirc|Ecirc|Ucirc|aring|Aring|aelig|AElig|acute|pound|raquo|acirc|times|thorn|szlig|cedil|COPY|Auml|ordf|ordm|uuml|macr|Uuml|auml|Ouml|ouml|para|nbsp|Euml|quot|QUOT|euml|yuml|cent|sect|copy|sup1|sup2|sup3|Iuml|iuml|shy|eth|reg|not|yen|amp|AMP|REG|uml|ETH|deg|gt|GT|LT|lt)([=a-zA-Z0-9])?/g;
  16176. var decodeMap = {'Aacute':'\xC1','aacute':'\xE1','Abreve':'\u0102','abreve':'\u0103','ac':'\u223E','acd':'\u223F','acE':'\u223E\u0333','Acirc':'\xC2','acirc':'\xE2','acute':'\xB4','Acy':'\u0410','acy':'\u0430','AElig':'\xC6','aelig':'\xE6','af':'\u2061','Afr':'\uD835\uDD04','afr':'\uD835\uDD1E','Agrave':'\xC0','agrave':'\xE0','alefsym':'\u2135','aleph':'\u2135','Alpha':'\u0391','alpha':'\u03B1','Amacr':'\u0100','amacr':'\u0101','amalg':'\u2A3F','amp':'&','AMP':'&','andand':'\u2A55','And':'\u2A53','and':'\u2227','andd':'\u2A5C','andslope':'\u2A58','andv':'\u2A5A','ang':'\u2220','ange':'\u29A4','angle':'\u2220','angmsdaa':'\u29A8','angmsdab':'\u29A9','angmsdac':'\u29AA','angmsdad':'\u29AB','angmsdae':'\u29AC','angmsdaf':'\u29AD','angmsdag':'\u29AE','angmsdah':'\u29AF','angmsd':'\u2221','angrt':'\u221F','angrtvb':'\u22BE','angrtvbd':'\u299D','angsph':'\u2222','angst':'\xC5','angzarr':'\u237C','Aogon':'\u0104','aogon':'\u0105','Aopf':'\uD835\uDD38','aopf':'\uD835\uDD52','apacir':'\u2A6F','ap':'\u2248','apE':'\u2A70','ape':'\u224A','apid':'\u224B','apos':'\'','ApplyFunction':'\u2061','approx':'\u2248','approxeq':'\u224A','Aring':'\xC5','aring':'\xE5','Ascr':'\uD835\uDC9C','ascr':'\uD835\uDCB6','Assign':'\u2254','ast':'*','asymp':'\u2248','asympeq':'\u224D','Atilde':'\xC3','atilde':'\xE3','Auml':'\xC4','auml':'\xE4','awconint':'\u2233','awint':'\u2A11','backcong':'\u224C','backepsilon':'\u03F6','backprime':'\u2035','backsim':'\u223D','backsimeq':'\u22CD','Backslash':'\u2216','Barv':'\u2AE7','barvee':'\u22BD','barwed':'\u2305','Barwed':'\u2306','barwedge':'\u2305','bbrk':'\u23B5','bbrktbrk':'\u23B6','bcong':'\u224C','Bcy':'\u0411','bcy':'\u0431','bdquo':'\u201E','becaus':'\u2235','because':'\u2235','Because':'\u2235','bemptyv':'\u29B0','bepsi':'\u03F6','bernou':'\u212C','Bernoullis':'\u212C','Beta':'\u0392','beta':'\u03B2','beth':'\u2136','between':'\u226C','Bfr':'\uD835\uDD05','bfr':'\uD835\uDD1F','bigcap':'\u22C2','bigcirc':'\u25EF','bigcup':'\u22C3','bigodot':'\u2A00','bigoplus':'\u2A01','bigotimes':'\u2A02','bigsqcup':'\u2A06','bigstar':'\u2605','bigtriangledown':'\u25BD','bigtriangleup':'\u25B3','biguplus':'\u2A04','bigvee':'\u22C1','bigwedge':'\u22C0','bkarow':'\u290D','blacklozenge':'\u29EB','blacksquare':'\u25AA','blacktriangle':'\u25B4','blacktriangledown':'\u25BE','blacktriangleleft':'\u25C2','blacktriangleright':'\u25B8','blank':'\u2423','blk12':'\u2592','blk14':'\u2591','blk34':'\u2593','block':'\u2588','bne':'=\u20E5','bnequiv':'\u2261\u20E5','bNot':'\u2AED','bnot':'\u2310','Bopf':'\uD835\uDD39','bopf':'\uD835\uDD53','bot':'\u22A5','bottom':'\u22A5','bowtie':'\u22C8','boxbox':'\u29C9','boxdl':'\u2510','boxdL':'\u2555','boxDl':'\u2556','boxDL':'\u2557','boxdr':'\u250C','boxdR':'\u2552','boxDr':'\u2553','boxDR':'\u2554','boxh':'\u2500','boxH':'\u2550','boxhd':'\u252C','boxHd':'\u2564','boxhD':'\u2565','boxHD':'\u2566','boxhu':'\u2534','boxHu':'\u2567','boxhU':'\u2568','boxHU':'\u2569','boxminus':'\u229F','boxplus':'\u229E','boxtimes':'\u22A0','boxul':'\u2518','boxuL':'\u255B','boxUl':'\u255C','boxUL':'\u255D','boxur':'\u2514','boxuR':'\u2558','boxUr':'\u2559','boxUR':'\u255A','boxv':'\u2502','boxV':'\u2551','boxvh':'\u253C','boxvH':'\u256A','boxVh':'\u256B','boxVH':'\u256C','boxvl':'\u2524','boxvL':'\u2561','boxVl':'\u2562','boxVL':'\u2563','boxvr':'\u251C','boxvR':'\u255E','boxVr':'\u255F','boxVR':'\u2560','bprime':'\u2035','breve':'\u02D8','Breve':'\u02D8','brvbar':'\xA6','bscr':'\uD835\uDCB7','Bscr':'\u212C','bsemi':'\u204F','bsim':'\u223D','bsime':'\u22CD','bsolb':'\u29C5','bsol':'\\','bsolhsub':'\u27C8','bull':'\u2022','bullet':'\u2022','bump':'\u224E','bumpE':'\u2AAE','bumpe':'\u224F','Bumpeq':'\u224E','bumpeq':'\u224F','Cacute':'\u0106','cacute':'\u0107','capand':'\u2A44','capbrcup':'\u2A49','capcap':'\u2A4B','cap':'\u2229','Cap':'\u22D2','capcup':'\u2A47','capdot':'\u2A40','CapitalDifferentialD':'\u2145','caps':'\u2229\uFE00','caret':'\u2041','caron':'\u02C7','Cayleys':'\u212D','ccaps':'\u2A4D','Ccaron':'\u010C','ccaron':'\u010D','Ccedil':'\xC7','ccedil':'\xE7','Ccirc':'\u0108','ccirc':'\u0109','Cconint':'\u2230','ccups':'\u2A4C','ccupssm':'\u2A50','Cdot':'\u010A','cdot':'\u010B','cedil':'\xB8','Cedilla':'\xB8','cemptyv':'\u29B2','cent':'\xA2','centerdot':'\xB7','CenterDot':'\xB7','cfr':'\uD835\uDD20','Cfr':'\u212D','CHcy':'\u0427','chcy':'\u0447','check':'\u2713','checkmark':'\u2713','Chi':'\u03A7','chi':'\u03C7','circ':'\u02C6','circeq':'\u2257','circlearrowleft':'\u21BA','circlearrowright':'\u21BB','circledast':'\u229B','circledcirc':'\u229A','circleddash':'\u229D','CircleDot':'\u2299','circledR':'\xAE','circledS':'\u24C8','CircleMinus':'\u2296','CirclePlus':'\u2295','CircleTimes':'\u2297','cir':'\u25CB','cirE':'\u29C3','cire':'\u2257','cirfnint':'\u2A10','cirmid':'\u2AEF','cirscir':'\u29C2','ClockwiseContourIntegral':'\u2232','CloseCurlyDoubleQuote':'\u201D','CloseCurlyQuote':'\u2019','clubs':'\u2663','clubsuit':'\u2663','colon':':','Colon':'\u2237','Colone':'\u2A74','colone':'\u2254','coloneq':'\u2254','comma':',','commat':'@','comp':'\u2201','compfn':'\u2218','complement':'\u2201','complexes':'\u2102','cong':'\u2245','congdot':'\u2A6D','Congruent':'\u2261','conint':'\u222E','Conint':'\u222F','ContourIntegral':'\u222E','copf':'\uD835\uDD54','Copf':'\u2102','coprod':'\u2210','Coproduct':'\u2210','copy':'\xA9','COPY':'\xA9','copysr':'\u2117','CounterClockwiseContourIntegral':'\u2233','crarr':'\u21B5','cross':'\u2717','Cross':'\u2A2F','Cscr':'\uD835\uDC9E','cscr':'\uD835\uDCB8','csub':'\u2ACF','csube':'\u2AD1','csup':'\u2AD0','csupe':'\u2AD2','ctdot':'\u22EF','cudarrl':'\u2938','cudarrr':'\u2935','cuepr':'\u22DE','cuesc':'\u22DF','cularr':'\u21B6','cularrp':'\u293D','cupbrcap':'\u2A48','cupcap':'\u2A46','CupCap':'\u224D','cup':'\u222A','Cup':'\u22D3','cupcup':'\u2A4A','cupdot':'\u228D','cupor':'\u2A45','cups':'\u222A\uFE00','curarr':'\u21B7','curarrm':'\u293C','curlyeqprec':'\u22DE','curlyeqsucc':'\u22DF','curlyvee':'\u22CE','curlywedge':'\u22CF','curren':'\xA4','curvearrowleft':'\u21B6','curvearrowright':'\u21B7','cuvee':'\u22CE','cuwed':'\u22CF','cwconint':'\u2232','cwint':'\u2231','cylcty':'\u232D','dagger':'\u2020','Dagger':'\u2021','daleth':'\u2138','darr':'\u2193','Darr':'\u21A1','dArr':'\u21D3','dash':'\u2010','Dashv':'\u2AE4','dashv':'\u22A3','dbkarow':'\u290F','dblac':'\u02DD','Dcaron':'\u010E','dcaron':'\u010F','Dcy':'\u0414','dcy':'\u0434','ddagger':'\u2021','ddarr':'\u21CA','DD':'\u2145','dd':'\u2146','DDotrahd':'\u2911','ddotseq':'\u2A77','deg':'\xB0','Del':'\u2207','Delta':'\u0394','delta':'\u03B4','demptyv':'\u29B1','dfisht':'\u297F','Dfr':'\uD835\uDD07','dfr':'\uD835\uDD21','dHar':'\u2965','dharl':'\u21C3','dharr':'\u21C2','DiacriticalAcute':'\xB4','DiacriticalDot':'\u02D9','DiacriticalDoubleAcute':'\u02DD','DiacriticalGrave':'`','DiacriticalTilde':'\u02DC','diam':'\u22C4','diamond':'\u22C4','Diamond':'\u22C4','diamondsuit':'\u2666','diams':'\u2666','die':'\xA8','DifferentialD':'\u2146','digamma':'\u03DD','disin':'\u22F2','div':'\xF7','divide':'\xF7','divideontimes':'\u22C7','divonx':'\u22C7','DJcy':'\u0402','djcy':'\u0452','dlcorn':'\u231E','dlcrop':'\u230D','dollar':'$','Dopf':'\uD835\uDD3B','dopf':'\uD835\uDD55','Dot':'\xA8','dot':'\u02D9','DotDot':'\u20DC','doteq':'\u2250','doteqdot':'\u2251','DotEqual':'\u2250','dotminus':'\u2238','dotplus':'\u2214','dotsquare':'\u22A1','doublebarwedge':'\u2306','DoubleContourIntegral':'\u222F','DoubleDot':'\xA8','DoubleDownArrow':'\u21D3','DoubleLeftArrow':'\u21D0','DoubleLeftRightArrow':'\u21D4','DoubleLeftTee':'\u2AE4','DoubleLongLeftArrow':'\u27F8','DoubleLongLeftRightArrow':'\u27FA','DoubleLongRightArrow':'\u27F9','DoubleRightArrow':'\u21D2','DoubleRightTee':'\u22A8','DoubleUpArrow':'\u21D1','DoubleUpDownArrow':'\u21D5','DoubleVerticalBar':'\u2225','DownArrowBar':'\u2913','downarrow':'\u2193','DownArrow':'\u2193','Downarrow':'\u21D3','DownArrowUpArrow':'\u21F5','DownBreve':'\u0311','downdownarrows':'\u21CA','downharpoonleft':'\u21C3','downharpoonright':'\u21C2','DownLeftRightVector':'\u2950','DownLeftTeeVector':'\u295E','DownLeftVectorBar':'\u2956','DownLeftVector':'\u21BD','DownRightTeeVector':'\u295F','DownRightVectorBar':'\u2957','DownRightVector':'\u21C1','DownTeeArrow':'\u21A7','DownTee':'\u22A4','drbkarow':'\u2910','drcorn':'\u231F','drcrop':'\u230C','Dscr':'\uD835\uDC9F','dscr':'\uD835\uDCB9','DScy':'\u0405','dscy':'\u0455','dsol':'\u29F6','Dstrok':'\u0110','dstrok':'\u0111','dtdot':'\u22F1','dtri':'\u25BF','dtrif':'\u25BE','duarr':'\u21F5','duhar':'\u296F','dwangle':'\u29A6','DZcy':'\u040F','dzcy':'\u045F','dzigrarr':'\u27FF','Eacute':'\xC9','eacute':'\xE9','easter':'\u2A6E','Ecaron':'\u011A','ecaron':'\u011B','Ecirc':'\xCA','ecirc':'\xEA','ecir':'\u2256','ecolon':'\u2255','Ecy':'\u042D','ecy':'\u044D','eDDot':'\u2A77','Edot':'\u0116','edot':'\u0117','eDot':'\u2251','ee':'\u2147','efDot':'\u2252','Efr':'\uD835\uDD08','efr':'\uD835\uDD22','eg':'\u2A9A','Egrave':'\xC8','egrave':'\xE8','egs':'\u2A96','egsdot':'\u2A98','el':'\u2A99','Element':'\u2208','elinters':'\u23E7','ell':'\u2113','els':'\u2A95','elsdot':'\u2A97','Emacr':'\u0112','emacr':'\u0113','empty':'\u2205','emptyset':'\u2205','EmptySmallSquare':'\u25FB','emptyv':'\u2205','EmptyVerySmallSquare':'\u25AB','emsp13':'\u2004','emsp14':'\u2005','emsp':'\u2003','ENG':'\u014A','eng':'\u014B','ensp':'\u2002','Eogon':'\u0118','eogon':'\u0119','Eopf':'\uD835\uDD3C','eopf':'\uD835\uDD56','epar':'\u22D5','eparsl':'\u29E3','eplus':'\u2A71','epsi':'\u03B5','Epsilon':'\u0395','epsilon':'\u03B5','epsiv':'\u03F5','eqcirc':'\u2256','eqcolon':'\u2255','eqsim':'\u2242','eqslantgtr':'\u2A96','eqslantless':'\u2A95','Equal':'\u2A75','equals':'=','EqualTilde':'\u2242','equest':'\u225F','Equilibrium':'\u21CC','equiv':'\u2261','equivDD':'\u2A78','eqvparsl':'\u29E5','erarr':'\u2971','erDot':'\u2253','escr':'\u212F','Escr':'\u2130','esdot':'\u2250','Esim':'\u2A73','esim':'\u2242','Eta':'\u0397','eta':'\u03B7','ETH':'\xD0','eth':'\xF0','Euml':'\xCB','euml':'\xEB','euro':'\u20AC','excl':'!','exist':'\u2203','Exists':'\u2203','expectation':'\u2130','exponentiale':'\u2147','ExponentialE':'\u2147','fallingdotseq':'\u2252','Fcy':'\u0424','fcy':'\u0444','female':'\u2640','ffilig':'\uFB03','fflig':'\uFB00','ffllig':'\uFB04','Ffr':'\uD835\uDD09','ffr':'\uD835\uDD23','filig':'\uFB01','FilledSmallSquare':'\u25FC','FilledVerySmallSquare':'\u25AA','fjlig':'fj','flat':'\u266D','fllig':'\uFB02','fltns':'\u25B1','fnof':'\u0192','Fopf':'\uD835\uDD3D','fopf':'\uD835\uDD57','forall':'\u2200','ForAll':'\u2200','fork':'\u22D4','forkv':'\u2AD9','Fouriertrf':'\u2131','fpartint':'\u2A0D','frac12':'\xBD','frac13':'\u2153','frac14':'\xBC','frac15':'\u2155','frac16':'\u2159','frac18':'\u215B','frac23':'\u2154','frac25':'\u2156','frac34':'\xBE','frac35':'\u2157','frac38':'\u215C','frac45':'\u2158','frac56':'\u215A','frac58':'\u215D','frac78':'\u215E','frasl':'\u2044','frown':'\u2322','fscr':'\uD835\uDCBB','Fscr':'\u2131','gacute':'\u01F5','Gamma':'\u0393','gamma':'\u03B3','Gammad':'\u03DC','gammad':'\u03DD','gap':'\u2A86','Gbreve':'\u011E','gbreve':'\u011F','Gcedil':'\u0122','Gcirc':'\u011C','gcirc':'\u011D','Gcy':'\u0413','gcy':'\u0433','Gdot':'\u0120','gdot':'\u0121','ge':'\u2265','gE':'\u2267','gEl':'\u2A8C','gel':'\u22DB','geq':'\u2265','geqq':'\u2267','geqslant':'\u2A7E','gescc':'\u2AA9','ges':'\u2A7E','gesdot':'\u2A80','gesdoto':'\u2A82','gesdotol':'\u2A84','gesl':'\u22DB\uFE00','gesles':'\u2A94','Gfr':'\uD835\uDD0A','gfr':'\uD835\uDD24','gg':'\u226B','Gg':'\u22D9','ggg':'\u22D9','gimel':'\u2137','GJcy':'\u0403','gjcy':'\u0453','gla':'\u2AA5','gl':'\u2277','glE':'\u2A92','glj':'\u2AA4','gnap':'\u2A8A','gnapprox':'\u2A8A','gne':'\u2A88','gnE':'\u2269','gneq':'\u2A88','gneqq':'\u2269','gnsim':'\u22E7','Gopf':'\uD835\uDD3E','gopf':'\uD835\uDD58','grave':'`','GreaterEqual':'\u2265','GreaterEqualLess':'\u22DB','GreaterFullEqual':'\u2267','GreaterGreater':'\u2AA2','GreaterLess':'\u2277','GreaterSlantEqual':'\u2A7E','GreaterTilde':'\u2273','Gscr':'\uD835\uDCA2','gscr':'\u210A','gsim':'\u2273','gsime':'\u2A8E','gsiml':'\u2A90','gtcc':'\u2AA7','gtcir':'\u2A7A','gt':'>','GT':'>','Gt':'\u226B','gtdot':'\u22D7','gtlPar':'\u2995','gtquest':'\u2A7C','gtrapprox':'\u2A86','gtrarr':'\u2978','gtrdot':'\u22D7','gtreqless':'\u22DB','gtreqqless':'\u2A8C','gtrless':'\u2277','gtrsim':'\u2273','gvertneqq':'\u2269\uFE00','gvnE':'\u2269\uFE00','Hacek':'\u02C7','hairsp':'\u200A','half':'\xBD','hamilt':'\u210B','HARDcy':'\u042A','hardcy':'\u044A','harrcir':'\u2948','harr':'\u2194','hArr':'\u21D4','harrw':'\u21AD','Hat':'^','hbar':'\u210F','Hcirc':'\u0124','hcirc':'\u0125','hearts':'\u2665','heartsuit':'\u2665','hellip':'\u2026','hercon':'\u22B9','hfr':'\uD835\uDD25','Hfr':'\u210C','HilbertSpace':'\u210B','hksearow':'\u2925','hkswarow':'\u2926','hoarr':'\u21FF','homtht':'\u223B','hookleftarrow':'\u21A9','hookrightarrow':'\u21AA','hopf':'\uD835\uDD59','Hopf':'\u210D','horbar':'\u2015','HorizontalLine':'\u2500','hscr':'\uD835\uDCBD','Hscr':'\u210B','hslash':'\u210F','Hstrok':'\u0126','hstrok':'\u0127','HumpDownHump':'\u224E','HumpEqual':'\u224F','hybull':'\u2043','hyphen':'\u2010','Iacute':'\xCD','iacute':'\xED','ic':'\u2063','Icirc':'\xCE','icirc':'\xEE','Icy':'\u0418','icy':'\u0438','Idot':'\u0130','IEcy':'\u0415','iecy':'\u0435','iexcl':'\xA1','iff':'\u21D4','ifr':'\uD835\uDD26','Ifr':'\u2111','Igrave':'\xCC','igrave':'\xEC','ii':'\u2148','iiiint':'\u2A0C','iiint':'\u222D','iinfin':'\u29DC','iiota':'\u2129','IJlig':'\u0132','ijlig':'\u0133','Imacr':'\u012A','imacr':'\u012B','image':'\u2111','ImaginaryI':'\u2148','imagline':'\u2110','imagpart':'\u2111','imath':'\u0131','Im':'\u2111','imof':'\u22B7','imped':'\u01B5','Implies':'\u21D2','incare':'\u2105','in':'\u2208','infin':'\u221E','infintie':'\u29DD','inodot':'\u0131','intcal':'\u22BA','int':'\u222B','Int':'\u222C','integers':'\u2124','Integral':'\u222B','intercal':'\u22BA','Intersection':'\u22C2','intlarhk':'\u2A17','intprod':'\u2A3C','InvisibleComma':'\u2063','InvisibleTimes':'\u2062','IOcy':'\u0401','iocy':'\u0451','Iogon':'\u012E','iogon':'\u012F','Iopf':'\uD835\uDD40','iopf':'\uD835\uDD5A','Iota':'\u0399','iota':'\u03B9','iprod':'\u2A3C','iquest':'\xBF','iscr':'\uD835\uDCBE','Iscr':'\u2110','isin':'\u2208','isindot':'\u22F5','isinE':'\u22F9','isins':'\u22F4','isinsv':'\u22F3','isinv':'\u2208','it':'\u2062','Itilde':'\u0128','itilde':'\u0129','Iukcy':'\u0406','iukcy':'\u0456','Iuml':'\xCF','iuml':'\xEF','Jcirc':'\u0134','jcirc':'\u0135','Jcy':'\u0419','jcy':'\u0439','Jfr':'\uD835\uDD0D','jfr':'\uD835\uDD27','jmath':'\u0237','Jopf':'\uD835\uDD41','jopf':'\uD835\uDD5B','Jscr':'\uD835\uDCA5','jscr':'\uD835\uDCBF','Jsercy':'\u0408','jsercy':'\u0458','Jukcy':'\u0404','jukcy':'\u0454','Kappa':'\u039A','kappa':'\u03BA','kappav':'\u03F0','Kcedil':'\u0136','kcedil':'\u0137','Kcy':'\u041A','kcy':'\u043A','Kfr':'\uD835\uDD0E','kfr':'\uD835\uDD28','kgreen':'\u0138','KHcy':'\u0425','khcy':'\u0445','KJcy':'\u040C','kjcy':'\u045C','Kopf':'\uD835\uDD42','kopf':'\uD835\uDD5C','Kscr':'\uD835\uDCA6','kscr':'\uD835\uDCC0','lAarr':'\u21DA','Lacute':'\u0139','lacute':'\u013A','laemptyv':'\u29B4','lagran':'\u2112','Lambda':'\u039B','lambda':'\u03BB','lang':'\u27E8','Lang':'\u27EA','langd':'\u2991','langle':'\u27E8','lap':'\u2A85','Laplacetrf':'\u2112','laquo':'\xAB','larrb':'\u21E4','larrbfs':'\u291F','larr':'\u2190','Larr':'\u219E','lArr':'\u21D0','larrfs':'\u291D','larrhk':'\u21A9','larrlp':'\u21AB','larrpl':'\u2939','larrsim':'\u2973','larrtl':'\u21A2','latail':'\u2919','lAtail':'\u291B','lat':'\u2AAB','late':'\u2AAD','lates':'\u2AAD\uFE00','lbarr':'\u290C','lBarr':'\u290E','lbbrk':'\u2772','lbrace':'{','lbrack':'[','lbrke':'\u298B','lbrksld':'\u298F','lbrkslu':'\u298D','Lcaron':'\u013D','lcaron':'\u013E','Lcedil':'\u013B','lcedil':'\u013C','lceil':'\u2308','lcub':'{','Lcy':'\u041B','lcy':'\u043B','ldca':'\u2936','ldquo':'\u201C','ldquor':'\u201E','ldrdhar':'\u2967','ldrushar':'\u294B','ldsh':'\u21B2','le':'\u2264','lE':'\u2266','LeftAngleBracket':'\u27E8','LeftArrowBar':'\u21E4','leftarrow':'\u2190','LeftArrow':'\u2190','Leftarrow':'\u21D0','LeftArrowRightArrow':'\u21C6','leftarrowtail':'\u21A2','LeftCeiling':'\u2308','LeftDoubleBracket':'\u27E6','LeftDownTeeVector':'\u2961','LeftDownVectorBar':'\u2959','LeftDownVector':'\u21C3','LeftFloor':'\u230A','leftharpoondown':'\u21BD','leftharpoonup':'\u21BC','leftleftarrows':'\u21C7','leftrightarrow':'\u2194','LeftRightArrow':'\u2194','Leftrightarrow':'\u21D4','leftrightarrows':'\u21C6','leftrightharpoons':'\u21CB','leftrightsquigarrow':'\u21AD','LeftRightVector':'\u294E','LeftTeeArrow':'\u21A4','LeftTee':'\u22A3','LeftTeeVector':'\u295A','leftthreetimes':'\u22CB','LeftTriangleBar':'\u29CF','LeftTriangle':'\u22B2','LeftTriangleEqual':'\u22B4','LeftUpDownVector':'\u2951','LeftUpTeeVector':'\u2960','LeftUpVectorBar':'\u2958','LeftUpVector':'\u21BF','LeftVectorBar':'\u2952','LeftVector':'\u21BC','lEg':'\u2A8B','leg':'\u22DA','leq':'\u2264','leqq':'\u2266','leqslant':'\u2A7D','lescc':'\u2AA8','les':'\u2A7D','lesdot':'\u2A7F','lesdoto':'\u2A81','lesdotor':'\u2A83','lesg':'\u22DA\uFE00','lesges':'\u2A93','lessapprox':'\u2A85','lessdot':'\u22D6','lesseqgtr':'\u22DA','lesseqqgtr':'\u2A8B','LessEqualGreater':'\u22DA','LessFullEqual':'\u2266','LessGreater':'\u2276','lessgtr':'\u2276','LessLess':'\u2AA1','lesssim':'\u2272','LessSlantEqual':'\u2A7D','LessTilde':'\u2272','lfisht':'\u297C','lfloor':'\u230A','Lfr':'\uD835\uDD0F','lfr':'\uD835\uDD29','lg':'\u2276','lgE':'\u2A91','lHar':'\u2962','lhard':'\u21BD','lharu':'\u21BC','lharul':'\u296A','lhblk':'\u2584','LJcy':'\u0409','ljcy':'\u0459','llarr':'\u21C7','ll':'\u226A','Ll':'\u22D8','llcorner':'\u231E','Lleftarrow':'\u21DA','llhard':'\u296B','lltri':'\u25FA','Lmidot':'\u013F','lmidot':'\u0140','lmoustache':'\u23B0','lmoust':'\u23B0','lnap':'\u2A89','lnapprox':'\u2A89','lne':'\u2A87','lnE':'\u2268','lneq':'\u2A87','lneqq':'\u2268','lnsim':'\u22E6','loang':'\u27EC','loarr':'\u21FD','lobrk':'\u27E6','longleftarrow':'\u27F5','LongLeftArrow':'\u27F5','Longleftarrow':'\u27F8','longleftrightarrow':'\u27F7','LongLeftRightArrow':'\u27F7','Longleftrightarrow':'\u27FA','longmapsto':'\u27FC','longrightarrow':'\u27F6','LongRightArrow':'\u27F6','Longrightarrow':'\u27F9','looparrowleft':'\u21AB','looparrowright':'\u21AC','lopar':'\u2985','Lopf':'\uD835\uDD43','lopf':'\uD835\uDD5D','loplus':'\u2A2D','lotimes':'\u2A34','lowast':'\u2217','lowbar':'_','LowerLeftArrow':'\u2199','LowerRightArrow':'\u2198','loz':'\u25CA','lozenge':'\u25CA','lozf':'\u29EB','lpar':'(','lparlt':'\u2993','lrarr':'\u21C6','lrcorner':'\u231F','lrhar':'\u21CB','lrhard':'\u296D','lrm':'\u200E','lrtri':'\u22BF','lsaquo':'\u2039','lscr':'\uD835\uDCC1','Lscr':'\u2112','lsh':'\u21B0','Lsh':'\u21B0','lsim':'\u2272','lsime':'\u2A8D','lsimg':'\u2A8F','lsqb':'[','lsquo':'\u2018','lsquor':'\u201A','Lstrok':'\u0141','lstrok':'\u0142','ltcc':'\u2AA6','ltcir':'\u2A79','lt':'<','LT':'<','Lt':'\u226A','ltdot':'\u22D6','lthree':'\u22CB','ltimes':'\u22C9','ltlarr':'\u2976','ltquest':'\u2A7B','ltri':'\u25C3','ltrie':'\u22B4','ltrif':'\u25C2','ltrPar':'\u2996','lurdshar':'\u294A','luruhar':'\u2966','lvertneqq':'\u2268\uFE00','lvnE':'\u2268\uFE00','macr':'\xAF','male':'\u2642','malt':'\u2720','maltese':'\u2720','Map':'\u2905','map':'\u21A6','mapsto':'\u21A6','mapstodown':'\u21A7','mapstoleft':'\u21A4','mapstoup':'\u21A5','marker':'\u25AE','mcomma':'\u2A29','Mcy':'\u041C','mcy':'\u043C','mdash':'\u2014','mDDot':'\u223A','measuredangle':'\u2221','MediumSpace':'\u205F','Mellintrf':'\u2133','Mfr':'\uD835\uDD10','mfr':'\uD835\uDD2A','mho':'\u2127','micro':'\xB5','midast':'*','midcir':'\u2AF0','mid':'\u2223','middot':'\xB7','minusb':'\u229F','minus':'\u2212','minusd':'\u2238','minusdu':'\u2A2A','MinusPlus':'\u2213','mlcp':'\u2ADB','mldr':'\u2026','mnplus':'\u2213','models':'\u22A7','Mopf':'\uD835\uDD44','mopf':'\uD835\uDD5E','mp':'\u2213','mscr':'\uD835\uDCC2','Mscr':'\u2133','mstpos':'\u223E','Mu':'\u039C','mu':'\u03BC','multimap':'\u22B8','mumap':'\u22B8','nabla':'\u2207','Nacute':'\u0143','nacute':'\u0144','nang':'\u2220\u20D2','nap':'\u2249','napE':'\u2A70\u0338','napid':'\u224B\u0338','napos':'\u0149','napprox':'\u2249','natural':'\u266E','naturals':'\u2115','natur':'\u266E','nbsp':'\xA0','nbump':'\u224E\u0338','nbumpe':'\u224F\u0338','ncap':'\u2A43','Ncaron':'\u0147','ncaron':'\u0148','Ncedil':'\u0145','ncedil':'\u0146','ncong':'\u2247','ncongdot':'\u2A6D\u0338','ncup':'\u2A42','Ncy':'\u041D','ncy':'\u043D','ndash':'\u2013','nearhk':'\u2924','nearr':'\u2197','neArr':'\u21D7','nearrow':'\u2197','ne':'\u2260','nedot':'\u2250\u0338','NegativeMediumSpace':'\u200B','NegativeThickSpace':'\u200B','NegativeThinSpace':'\u200B','NegativeVeryThinSpace':'\u200B','nequiv':'\u2262','nesear':'\u2928','nesim':'\u2242\u0338','NestedGreaterGreater':'\u226B','NestedLessLess':'\u226A','NewLine':'\n','nexist':'\u2204','nexists':'\u2204','Nfr':'\uD835\uDD11','nfr':'\uD835\uDD2B','ngE':'\u2267\u0338','nge':'\u2271','ngeq':'\u2271','ngeqq':'\u2267\u0338','ngeqslant':'\u2A7E\u0338','nges':'\u2A7E\u0338','nGg':'\u22D9\u0338','ngsim':'\u2275','nGt':'\u226B\u20D2','ngt':'\u226F','ngtr':'\u226F','nGtv':'\u226B\u0338','nharr':'\u21AE','nhArr':'\u21CE','nhpar':'\u2AF2','ni':'\u220B','nis':'\u22FC','nisd':'\u22FA','niv':'\u220B','NJcy':'\u040A','njcy':'\u045A','nlarr':'\u219A','nlArr':'\u21CD','nldr':'\u2025','nlE':'\u2266\u0338','nle':'\u2270','nleftarrow':'\u219A','nLeftarrow':'\u21CD','nleftrightarrow':'\u21AE','nLeftrightarrow':'\u21CE','nleq':'\u2270','nleqq':'\u2266\u0338','nleqslant':'\u2A7D\u0338','nles':'\u2A7D\u0338','nless':'\u226E','nLl':'\u22D8\u0338','nlsim':'\u2274','nLt':'\u226A\u20D2','nlt':'\u226E','nltri':'\u22EA','nltrie':'\u22EC','nLtv':'\u226A\u0338','nmid':'\u2224','NoBreak':'\u2060','NonBreakingSpace':'\xA0','nopf':'\uD835\uDD5F','Nopf':'\u2115','Not':'\u2AEC','not':'\xAC','NotCongruent':'\u2262','NotCupCap':'\u226D','NotDoubleVerticalBar':'\u2226','NotElement':'\u2209','NotEqual':'\u2260','NotEqualTilde':'\u2242\u0338','NotExists':'\u2204','NotGreater':'\u226F','NotGreaterEqual':'\u2271','NotGreaterFullEqual':'\u2267\u0338','NotGreaterGreater':'\u226B\u0338','NotGreaterLess':'\u2279','NotGreaterSlantEqual':'\u2A7E\u0338','NotGreaterTilde':'\u2275','NotHumpDownHump':'\u224E\u0338','NotHumpEqual':'\u224F\u0338','notin':'\u2209','notindot':'\u22F5\u0338','notinE':'\u22F9\u0338','notinva':'\u2209','notinvb':'\u22F7','notinvc':'\u22F6','NotLeftTriangleBar':'\u29CF\u0338','NotLeftTriangle':'\u22EA','NotLeftTriangleEqual':'\u22EC','NotLess':'\u226E','NotLessEqual':'\u2270','NotLessGreater':'\u2278','NotLessLess':'\u226A\u0338','NotLessSlantEqual':'\u2A7D\u0338','NotLessTilde':'\u2274','NotNestedGreaterGreater':'\u2AA2\u0338','NotNestedLessLess':'\u2AA1\u0338','notni':'\u220C','notniva':'\u220C','notnivb':'\u22FE','notnivc':'\u22FD','NotPrecedes':'\u2280','NotPrecedesEqual':'\u2AAF\u0338','NotPrecedesSlantEqual':'\u22E0','NotReverseElement':'\u220C','NotRightTriangleBar':'\u29D0\u0338','NotRightTriangle':'\u22EB','NotRightTriangleEqual':'\u22ED','NotSquareSubset':'\u228F\u0338','NotSquareSubsetEqual':'\u22E2','NotSquareSuperset':'\u2290\u0338','NotSquareSupersetEqual':'\u22E3','NotSubset':'\u2282\u20D2','NotSubsetEqual':'\u2288','NotSucceeds':'\u2281','NotSucceedsEqual':'\u2AB0\u0338','NotSucceedsSlantEqual':'\u22E1','NotSucceedsTilde':'\u227F\u0338','NotSuperset':'\u2283\u20D2','NotSupersetEqual':'\u2289','NotTilde':'\u2241','NotTildeEqual':'\u2244','NotTildeFullEqual':'\u2247','NotTildeTilde':'\u2249','NotVerticalBar':'\u2224','nparallel':'\u2226','npar':'\u2226','nparsl':'\u2AFD\u20E5','npart':'\u2202\u0338','npolint':'\u2A14','npr':'\u2280','nprcue':'\u22E0','nprec':'\u2280','npreceq':'\u2AAF\u0338','npre':'\u2AAF\u0338','nrarrc':'\u2933\u0338','nrarr':'\u219B','nrArr':'\u21CF','nrarrw':'\u219D\u0338','nrightarrow':'\u219B','nRightarrow':'\u21CF','nrtri':'\u22EB','nrtrie':'\u22ED','nsc':'\u2281','nsccue':'\u22E1','nsce':'\u2AB0\u0338','Nscr':'\uD835\uDCA9','nscr':'\uD835\uDCC3','nshortmid':'\u2224','nshortparallel':'\u2226','nsim':'\u2241','nsime':'\u2244','nsimeq':'\u2244','nsmid':'\u2224','nspar':'\u2226','nsqsube':'\u22E2','nsqsupe':'\u22E3','nsub':'\u2284','nsubE':'\u2AC5\u0338','nsube':'\u2288','nsubset':'\u2282\u20D2','nsubseteq':'\u2288','nsubseteqq':'\u2AC5\u0338','nsucc':'\u2281','nsucceq':'\u2AB0\u0338','nsup':'\u2285','nsupE':'\u2AC6\u0338','nsupe':'\u2289','nsupset':'\u2283\u20D2','nsupseteq':'\u2289','nsupseteqq':'\u2AC6\u0338','ntgl':'\u2279','Ntilde':'\xD1','ntilde':'\xF1','ntlg':'\u2278','ntriangleleft':'\u22EA','ntrianglelefteq':'\u22EC','ntriangleright':'\u22EB','ntrianglerighteq':'\u22ED','Nu':'\u039D','nu':'\u03BD','num':'#','numero':'\u2116','numsp':'\u2007','nvap':'\u224D\u20D2','nvdash':'\u22AC','nvDash':'\u22AD','nVdash':'\u22AE','nVDash':'\u22AF','nvge':'\u2265\u20D2','nvgt':'>\u20D2','nvHarr':'\u2904','nvinfin':'\u29DE','nvlArr':'\u2902','nvle':'\u2264\u20D2','nvlt':'<\u20D2','nvltrie':'\u22B4\u20D2','nvrArr':'\u2903','nvrtrie':'\u22B5\u20D2','nvsim':'\u223C\u20D2','nwarhk':'\u2923','nwarr':'\u2196','nwArr':'\u21D6','nwarrow':'\u2196','nwnear':'\u2927','Oacute':'\xD3','oacute':'\xF3','oast':'\u229B','Ocirc':'\xD4','ocirc':'\xF4','ocir':'\u229A','Ocy':'\u041E','ocy':'\u043E','odash':'\u229D','Odblac':'\u0150','odblac':'\u0151','odiv':'\u2A38','odot':'\u2299','odsold':'\u29BC','OElig':'\u0152','oelig':'\u0153','ofcir':'\u29BF','Ofr':'\uD835\uDD12','ofr':'\uD835\uDD2C','ogon':'\u02DB','Ograve':'\xD2','ograve':'\xF2','ogt':'\u29C1','ohbar':'\u29B5','ohm':'\u03A9','oint':'\u222E','olarr':'\u21BA','olcir':'\u29BE','olcross':'\u29BB','oline':'\u203E','olt':'\u29C0','Omacr':'\u014C','omacr':'\u014D','Omega':'\u03A9','omega':'\u03C9','Omicron':'\u039F','omicron':'\u03BF','omid':'\u29B6','ominus':'\u2296','Oopf':'\uD835\uDD46','oopf':'\uD835\uDD60','opar':'\u29B7','OpenCurlyDoubleQuote':'\u201C','OpenCurlyQuote':'\u2018','operp':'\u29B9','oplus':'\u2295','orarr':'\u21BB','Or':'\u2A54','or':'\u2228','ord':'\u2A5D','order':'\u2134','orderof':'\u2134','ordf':'\xAA','ordm':'\xBA','origof':'\u22B6','oror':'\u2A56','orslope':'\u2A57','orv':'\u2A5B','oS':'\u24C8','Oscr':'\uD835\uDCAA','oscr':'\u2134','Oslash':'\xD8','oslash':'\xF8','osol':'\u2298','Otilde':'\xD5','otilde':'\xF5','otimesas':'\u2A36','Otimes':'\u2A37','otimes':'\u2297','Ouml':'\xD6','ouml':'\xF6','ovbar':'\u233D','OverBar':'\u203E','OverBrace':'\u23DE','OverBracket':'\u23B4','OverParenthesis':'\u23DC','para':'\xB6','parallel':'\u2225','par':'\u2225','parsim':'\u2AF3','parsl':'\u2AFD','part':'\u2202','PartialD':'\u2202','Pcy':'\u041F','pcy':'\u043F','percnt':'%','period':'.','permil':'\u2030','perp':'\u22A5','pertenk':'\u2031','Pfr':'\uD835\uDD13','pfr':'\uD835\uDD2D','Phi':'\u03A6','phi':'\u03C6','phiv':'\u03D5','phmmat':'\u2133','phone':'\u260E','Pi':'\u03A0','pi':'\u03C0','pitchfork':'\u22D4','piv':'\u03D6','planck':'\u210F','planckh':'\u210E','plankv':'\u210F','plusacir':'\u2A23','plusb':'\u229E','pluscir':'\u2A22','plus':'+','plusdo':'\u2214','plusdu':'\u2A25','pluse':'\u2A72','PlusMinus':'\xB1','plusmn':'\xB1','plussim':'\u2A26','plustwo':'\u2A27','pm':'\xB1','Poincareplane':'\u210C','pointint':'\u2A15','popf':'\uD835\uDD61','Popf':'\u2119','pound':'\xA3','prap':'\u2AB7','Pr':'\u2ABB','pr':'\u227A','prcue':'\u227C','precapprox':'\u2AB7','prec':'\u227A','preccurlyeq':'\u227C','Precedes':'\u227A','PrecedesEqual':'\u2AAF','PrecedesSlantEqual':'\u227C','PrecedesTilde':'\u227E','preceq':'\u2AAF','precnapprox':'\u2AB9','precneqq':'\u2AB5','precnsim':'\u22E8','pre':'\u2AAF','prE':'\u2AB3','precsim':'\u227E','prime':'\u2032','Prime':'\u2033','primes':'\u2119','prnap':'\u2AB9','prnE':'\u2AB5','prnsim':'\u22E8','prod':'\u220F','Product':'\u220F','profalar':'\u232E','profline':'\u2312','profsurf':'\u2313','prop':'\u221D','Proportional':'\u221D','Proportion':'\u2237','propto':'\u221D','prsim':'\u227E','prurel':'\u22B0','Pscr':'\uD835\uDCAB','pscr':'\uD835\uDCC5','Psi':'\u03A8','psi':'\u03C8','puncsp':'\u2008','Qfr':'\uD835\uDD14','qfr':'\uD835\uDD2E','qint':'\u2A0C','qopf':'\uD835\uDD62','Qopf':'\u211A','qprime':'\u2057','Qscr':'\uD835\uDCAC','qscr':'\uD835\uDCC6','quaternions':'\u210D','quatint':'\u2A16','quest':'?','questeq':'\u225F','quot':'"','QUOT':'"','rAarr':'\u21DB','race':'\u223D\u0331','Racute':'\u0154','racute':'\u0155','radic':'\u221A','raemptyv':'\u29B3','rang':'\u27E9','Rang':'\u27EB','rangd':'\u2992','range':'\u29A5','rangle':'\u27E9','raquo':'\xBB','rarrap':'\u2975','rarrb':'\u21E5','rarrbfs':'\u2920','rarrc':'\u2933','rarr':'\u2192','Rarr':'\u21A0','rArr':'\u21D2','rarrfs':'\u291E','rarrhk':'\u21AA','rarrlp':'\u21AC','rarrpl':'\u2945','rarrsim':'\u2974','Rarrtl':'\u2916','rarrtl':'\u21A3','rarrw':'\u219D','ratail':'\u291A','rAtail':'\u291C','ratio':'\u2236','rationals':'\u211A','rbarr':'\u290D','rBarr':'\u290F','RBarr':'\u2910','rbbrk':'\u2773','rbrace':'}','rbrack':']','rbrke':'\u298C','rbrksld':'\u298E','rbrkslu':'\u2990','Rcaron':'\u0158','rcaron':'\u0159','Rcedil':'\u0156','rcedil':'\u0157','rceil':'\u2309','rcub':'}','Rcy':'\u0420','rcy':'\u0440','rdca':'\u2937','rdldhar':'\u2969','rdquo':'\u201D','rdquor':'\u201D','rdsh':'\u21B3','real':'\u211C','realine':'\u211B','realpart':'\u211C','reals':'\u211D','Re':'\u211C','rect':'\u25AD','reg':'\xAE','REG':'\xAE','ReverseElement':'\u220B','ReverseEquilibrium':'\u21CB','ReverseUpEquilibrium':'\u296F','rfisht':'\u297D','rfloor':'\u230B','rfr':'\uD835\uDD2F','Rfr':'\u211C','rHar':'\u2964','rhard':'\u21C1','rharu':'\u21C0','rharul':'\u296C','Rho':'\u03A1','rho':'\u03C1','rhov':'\u03F1','RightAngleBracket':'\u27E9','RightArrowBar':'\u21E5','rightarrow':'\u2192','RightArrow':'\u2192','Rightarrow':'\u21D2','RightArrowLeftArrow':'\u21C4','rightarrowtail':'\u21A3','RightCeiling':'\u2309','RightDoubleBracket':'\u27E7','RightDownTeeVector':'\u295D','RightDownVectorBar':'\u2955','RightDownVector':'\u21C2','RightFloor':'\u230B','rightharpoondown':'\u21C1','rightharpoonup':'\u21C0','rightleftarrows':'\u21C4','rightleftharpoons':'\u21CC','rightrightarrows':'\u21C9','rightsquigarrow':'\u219D','RightTeeArrow':'\u21A6','RightTee':'\u22A2','RightTeeVector':'\u295B','rightthreetimes':'\u22CC','RightTriangleBar':'\u29D0','RightTriangle':'\u22B3','RightTriangleEqual':'\u22B5','RightUpDownVector':'\u294F','RightUpTeeVector':'\u295C','RightUpVectorBar':'\u2954','RightUpVector':'\u21BE','RightVectorBar':'\u2953','RightVector':'\u21C0','ring':'\u02DA','risingdotseq':'\u2253','rlarr':'\u21C4','rlhar':'\u21CC','rlm':'\u200F','rmoustache':'\u23B1','rmoust':'\u23B1','rnmid':'\u2AEE','roang':'\u27ED','roarr':'\u21FE','robrk':'\u27E7','ropar':'\u2986','ropf':'\uD835\uDD63','Ropf':'\u211D','roplus':'\u2A2E','rotimes':'\u2A35','RoundImplies':'\u2970','rpar':')','rpargt':'\u2994','rppolint':'\u2A12','rrarr':'\u21C9','Rrightarrow':'\u21DB','rsaquo':'\u203A','rscr':'\uD835\uDCC7','Rscr':'\u211B','rsh':'\u21B1','Rsh':'\u21B1','rsqb':']','rsquo':'\u2019','rsquor':'\u2019','rthree':'\u22CC','rtimes':'\u22CA','rtri':'\u25B9','rtrie':'\u22B5','rtrif':'\u25B8','rtriltri':'\u29CE','RuleDelayed':'\u29F4','ruluhar':'\u2968','rx':'\u211E','Sacute':'\u015A','sacute':'\u015B','sbquo':'\u201A','scap':'\u2AB8','Scaron':'\u0160','scaron':'\u0161','Sc':'\u2ABC','sc':'\u227B','sccue':'\u227D','sce':'\u2AB0','scE':'\u2AB4','Scedil':'\u015E','scedil':'\u015F','Scirc':'\u015C','scirc':'\u015D','scnap':'\u2ABA','scnE':'\u2AB6','scnsim':'\u22E9','scpolint':'\u2A13','scsim':'\u227F','Scy':'\u0421','scy':'\u0441','sdotb':'\u22A1','sdot':'\u22C5','sdote':'\u2A66','searhk':'\u2925','searr':'\u2198','seArr':'\u21D8','searrow':'\u2198','sect':'\xA7','semi':';','seswar':'\u2929','setminus':'\u2216','setmn':'\u2216','sext':'\u2736','Sfr':'\uD835\uDD16','sfr':'\uD835\uDD30','sfrown':'\u2322','sharp':'\u266F','SHCHcy':'\u0429','shchcy':'\u0449','SHcy':'\u0428','shcy':'\u0448','ShortDownArrow':'\u2193','ShortLeftArrow':'\u2190','shortmid':'\u2223','shortparallel':'\u2225','ShortRightArrow':'\u2192','ShortUpArrow':'\u2191','shy':'\xAD','Sigma':'\u03A3','sigma':'\u03C3','sigmaf':'\u03C2','sigmav':'\u03C2','sim':'\u223C','simdot':'\u2A6A','sime':'\u2243','simeq':'\u2243','simg':'\u2A9E','simgE':'\u2AA0','siml':'\u2A9D','simlE':'\u2A9F','simne':'\u2246','simplus':'\u2A24','simrarr':'\u2972','slarr':'\u2190','SmallCircle':'\u2218','smallsetminus':'\u2216','smashp':'\u2A33','smeparsl':'\u29E4','smid':'\u2223','smile':'\u2323','smt':'\u2AAA','smte':'\u2AAC','smtes':'\u2AAC\uFE00','SOFTcy':'\u042C','softcy':'\u044C','solbar':'\u233F','solb':'\u29C4','sol':'/','Sopf':'\uD835\uDD4A','sopf':'\uD835\uDD64','spades':'\u2660','spadesuit':'\u2660','spar':'\u2225','sqcap':'\u2293','sqcaps':'\u2293\uFE00','sqcup':'\u2294','sqcups':'\u2294\uFE00','Sqrt':'\u221A','sqsub':'\u228F','sqsube':'\u2291','sqsubset':'\u228F','sqsubseteq':'\u2291','sqsup':'\u2290','sqsupe':'\u2292','sqsupset':'\u2290','sqsupseteq':'\u2292','square':'\u25A1','Square':'\u25A1','SquareIntersection':'\u2293','SquareSubset':'\u228F','SquareSubsetEqual':'\u2291','SquareSuperset':'\u2290','SquareSupersetEqual':'\u2292','SquareUnion':'\u2294','squarf':'\u25AA','squ':'\u25A1','squf':'\u25AA','srarr':'\u2192','Sscr':'\uD835\uDCAE','sscr':'\uD835\uDCC8','ssetmn':'\u2216','ssmile':'\u2323','sstarf':'\u22C6','Star':'\u22C6','star':'\u2606','starf':'\u2605','straightepsilon':'\u03F5','straightphi':'\u03D5','strns':'\xAF','sub':'\u2282','Sub':'\u22D0','subdot':'\u2ABD','subE':'\u2AC5','sube':'\u2286','subedot':'\u2AC3','submult':'\u2AC1','subnE':'\u2ACB','subne':'\u228A','subplus':'\u2ABF','subrarr':'\u2979','subset':'\u2282','Subset':'\u22D0','subseteq':'\u2286','subseteqq':'\u2AC5','SubsetEqual':'\u2286','subsetneq':'\u228A','subsetneqq':'\u2ACB','subsim':'\u2AC7','subsub':'\u2AD5','subsup':'\u2AD3','succapprox':'\u2AB8','succ':'\u227B','succcurlyeq':'\u227D','Succeeds':'\u227B','SucceedsEqual':'\u2AB0','SucceedsSlantEqual':'\u227D','SucceedsTilde':'\u227F','succeq':'\u2AB0','succnapprox':'\u2ABA','succneqq':'\u2AB6','succnsim':'\u22E9','succsim':'\u227F','SuchThat':'\u220B','sum':'\u2211','Sum':'\u2211','sung':'\u266A','sup1':'\xB9','sup2':'\xB2','sup3':'\xB3','sup':'\u2283','Sup':'\u22D1','supdot':'\u2ABE','supdsub':'\u2AD8','supE':'\u2AC6','supe':'\u2287','supedot':'\u2AC4','Superset':'\u2283','SupersetEqual':'\u2287','suphsol':'\u27C9','suphsub':'\u2AD7','suplarr':'\u297B','supmult':'\u2AC2','supnE':'\u2ACC','supne':'\u228B','supplus':'\u2AC0','supset':'\u2283','Supset':'\u22D1','supseteq':'\u2287','supseteqq':'\u2AC6','supsetneq':'\u228B','supsetneqq':'\u2ACC','supsim':'\u2AC8','supsub':'\u2AD4','supsup':'\u2AD6','swarhk':'\u2926','swarr':'\u2199','swArr':'\u21D9','swarrow':'\u2199','swnwar':'\u292A','szlig':'\xDF','Tab':'\t','target':'\u2316','Tau':'\u03A4','tau':'\u03C4','tbrk':'\u23B4','Tcaron':'\u0164','tcaron':'\u0165','Tcedil':'\u0162','tcedil':'\u0163','Tcy':'\u0422','tcy':'\u0442','tdot':'\u20DB','telrec':'\u2315','Tfr':'\uD835\uDD17','tfr':'\uD835\uDD31','there4':'\u2234','therefore':'\u2234','Therefore':'\u2234','Theta':'\u0398','theta':'\u03B8','thetasym':'\u03D1','thetav':'\u03D1','thickapprox':'\u2248','thicksim':'\u223C','ThickSpace':'\u205F\u200A','ThinSpace':'\u2009','thinsp':'\u2009','thkap':'\u2248','thksim':'\u223C','THORN':'\xDE','thorn':'\xFE','tilde':'\u02DC','Tilde':'\u223C','TildeEqual':'\u2243','TildeFullEqual':'\u2245','TildeTilde':'\u2248','timesbar':'\u2A31','timesb':'\u22A0','times':'\xD7','timesd':'\u2A30','tint':'\u222D','toea':'\u2928','topbot':'\u2336','topcir':'\u2AF1','top':'\u22A4','Topf':'\uD835\uDD4B','topf':'\uD835\uDD65','topfork':'\u2ADA','tosa':'\u2929','tprime':'\u2034','trade':'\u2122','TRADE':'\u2122','triangle':'\u25B5','triangledown':'\u25BF','triangleleft':'\u25C3','trianglelefteq':'\u22B4','triangleq':'\u225C','triangleright':'\u25B9','trianglerighteq':'\u22B5','tridot':'\u25EC','trie':'\u225C','triminus':'\u2A3A','TripleDot':'\u20DB','triplus':'\u2A39','trisb':'\u29CD','tritime':'\u2A3B','trpezium':'\u23E2','Tscr':'\uD835\uDCAF','tscr':'\uD835\uDCC9','TScy':'\u0426','tscy':'\u0446','TSHcy':'\u040B','tshcy':'\u045B','Tstrok':'\u0166','tstrok':'\u0167','twixt':'\u226C','twoheadleftarrow':'\u219E','twoheadrightarrow':'\u21A0','Uacute':'\xDA','uacute':'\xFA','uarr':'\u2191','Uarr':'\u219F','uArr':'\u21D1','Uarrocir':'\u2949','Ubrcy':'\u040E','ubrcy':'\u045E','Ubreve':'\u016C','ubreve':'\u016D','Ucirc':'\xDB','ucirc':'\xFB','Ucy':'\u0423','ucy':'\u0443','udarr':'\u21C5','Udblac':'\u0170','udblac':'\u0171','udhar':'\u296E','ufisht':'\u297E','Ufr':'\uD835\uDD18','ufr':'\uD835\uDD32','Ugrave':'\xD9','ugrave':'\xF9','uHar':'\u2963','uharl':'\u21BF','uharr':'\u21BE','uhblk':'\u2580','ulcorn':'\u231C','ulcorner':'\u231C','ulcrop':'\u230F','ultri':'\u25F8','Umacr':'\u016A','umacr':'\u016B','uml':'\xA8','UnderBar':'_','UnderBrace':'\u23DF','UnderBracket':'\u23B5','UnderParenthesis':'\u23DD','Union':'\u22C3','UnionPlus':'\u228E','Uogon':'\u0172','uogon':'\u0173','Uopf':'\uD835\uDD4C','uopf':'\uD835\uDD66','UpArrowBar':'\u2912','uparrow':'\u2191','UpArrow':'\u2191','Uparrow':'\u21D1','UpArrowDownArrow':'\u21C5','updownarrow':'\u2195','UpDownArrow':'\u2195','Updownarrow':'\u21D5','UpEquilibrium':'\u296E','upharpoonleft':'\u21BF','upharpoonright':'\u21BE','uplus':'\u228E','UpperLeftArrow':'\u2196','UpperRightArrow':'\u2197','upsi':'\u03C5','Upsi':'\u03D2','upsih':'\u03D2','Upsilon':'\u03A5','upsilon':'\u03C5','UpTeeArrow':'\u21A5','UpTee':'\u22A5','upuparrows':'\u21C8','urcorn':'\u231D','urcorner':'\u231D','urcrop':'\u230E','Uring':'\u016E','uring':'\u016F','urtri':'\u25F9','Uscr':'\uD835\uDCB0','uscr':'\uD835\uDCCA','utdot':'\u22F0','Utilde':'\u0168','utilde':'\u0169','utri':'\u25B5','utrif':'\u25B4','uuarr':'\u21C8','Uuml':'\xDC','uuml':'\xFC','uwangle':'\u29A7','vangrt':'\u299C','varepsilon':'\u03F5','varkappa':'\u03F0','varnothing':'\u2205','varphi':'\u03D5','varpi':'\u03D6','varpropto':'\u221D','varr':'\u2195','vArr':'\u21D5','varrho':'\u03F1','varsigma':'\u03C2','varsubsetneq':'\u228A\uFE00','varsubsetneqq':'\u2ACB\uFE00','varsupsetneq':'\u228B\uFE00','varsupsetneqq':'\u2ACC\uFE00','vartheta':'\u03D1','vartriangleleft':'\u22B2','vartriangleright':'\u22B3','vBar':'\u2AE8','Vbar':'\u2AEB','vBarv':'\u2AE9','Vcy':'\u0412','vcy':'\u0432','vdash':'\u22A2','vDash':'\u22A8','Vdash':'\u22A9','VDash':'\u22AB','Vdashl':'\u2AE6','veebar':'\u22BB','vee':'\u2228','Vee':'\u22C1','veeeq':'\u225A','vellip':'\u22EE','verbar':'|','Verbar':'\u2016','vert':'|','Vert':'\u2016','VerticalBar':'\u2223','VerticalLine':'|','VerticalSeparator':'\u2758','VerticalTilde':'\u2240','VeryThinSpace':'\u200A','Vfr':'\uD835\uDD19','vfr':'\uD835\uDD33','vltri':'\u22B2','vnsub':'\u2282\u20D2','vnsup':'\u2283\u20D2','Vopf':'\uD835\uDD4D','vopf':'\uD835\uDD67','vprop':'\u221D','vrtri':'\u22B3','Vscr':'\uD835\uDCB1','vscr':'\uD835\uDCCB','vsubnE':'\u2ACB\uFE00','vsubne':'\u228A\uFE00','vsupnE':'\u2ACC\uFE00','vsupne':'\u228B\uFE00','Vvdash':'\u22AA','vzigzag':'\u299A','Wcirc':'\u0174','wcirc':'\u0175','wedbar':'\u2A5F','wedge':'\u2227','Wedge':'\u22C0','wedgeq':'\u2259','weierp':'\u2118','Wfr':'\uD835\uDD1A','wfr':'\uD835\uDD34','Wopf':'\uD835\uDD4E','wopf':'\uD835\uDD68','wp':'\u2118','wr':'\u2240','wreath':'\u2240','Wscr':'\uD835\uDCB2','wscr':'\uD835\uDCCC','xcap':'\u22C2','xcirc':'\u25EF','xcup':'\u22C3','xdtri':'\u25BD','Xfr':'\uD835\uDD1B','xfr':'\uD835\uDD35','xharr':'\u27F7','xhArr':'\u27FA','Xi':'\u039E','xi':'\u03BE','xlarr':'\u27F5','xlArr':'\u27F8','xmap':'\u27FC','xnis':'\u22FB','xodot':'\u2A00','Xopf':'\uD835\uDD4F','xopf':'\uD835\uDD69','xoplus':'\u2A01','xotime':'\u2A02','xrarr':'\u27F6','xrArr':'\u27F9','Xscr':'\uD835\uDCB3','xscr':'\uD835\uDCCD','xsqcup':'\u2A06','xuplus':'\u2A04','xutri':'\u25B3','xvee':'\u22C1','xwedge':'\u22C0','Yacute':'\xDD','yacute':'\xFD','YAcy':'\u042F','yacy':'\u044F','Ycirc':'\u0176','ycirc':'\u0177','Ycy':'\u042B','ycy':'\u044B','yen':'\xA5','Yfr':'\uD835\uDD1C','yfr':'\uD835\uDD36','YIcy':'\u0407','yicy':'\u0457','Yopf':'\uD835\uDD50','yopf':'\uD835\uDD6A','Yscr':'\uD835\uDCB4','yscr':'\uD835\uDCCE','YUcy':'\u042E','yucy':'\u044E','yuml':'\xFF','Yuml':'\u0178','Zacute':'\u0179','zacute':'\u017A','Zcaron':'\u017D','zcaron':'\u017E','Zcy':'\u0417','zcy':'\u0437','Zdot':'\u017B','zdot':'\u017C','zeetrf':'\u2128','ZeroWidthSpace':'\u200B','Zeta':'\u0396','zeta':'\u03B6','zfr':'\uD835\uDD37','Zfr':'\u2128','ZHcy':'\u0416','zhcy':'\u0436','zigrarr':'\u21DD','zopf':'\uD835\uDD6B','Zopf':'\u2124','Zscr':'\uD835\uDCB5','zscr':'\uD835\uDCCF','zwj':'\u200D','zwnj':'\u200C'};
  16177. var decodeMapLegacy = {'Aacute':'\xC1','aacute':'\xE1','Acirc':'\xC2','acirc':'\xE2','acute':'\xB4','AElig':'\xC6','aelig':'\xE6','Agrave':'\xC0','agrave':'\xE0','amp':'&','AMP':'&','Aring':'\xC5','aring':'\xE5','Atilde':'\xC3','atilde':'\xE3','Auml':'\xC4','auml':'\xE4','brvbar':'\xA6','Ccedil':'\xC7','ccedil':'\xE7','cedil':'\xB8','cent':'\xA2','copy':'\xA9','COPY':'\xA9','curren':'\xA4','deg':'\xB0','divide':'\xF7','Eacute':'\xC9','eacute':'\xE9','Ecirc':'\xCA','ecirc':'\xEA','Egrave':'\xC8','egrave':'\xE8','ETH':'\xD0','eth':'\xF0','Euml':'\xCB','euml':'\xEB','frac12':'\xBD','frac14':'\xBC','frac34':'\xBE','gt':'>','GT':'>','Iacute':'\xCD','iacute':'\xED','Icirc':'\xCE','icirc':'\xEE','iexcl':'\xA1','Igrave':'\xCC','igrave':'\xEC','iquest':'\xBF','Iuml':'\xCF','iuml':'\xEF','laquo':'\xAB','lt':'<','LT':'<','macr':'\xAF','micro':'\xB5','middot':'\xB7','nbsp':'\xA0','not':'\xAC','Ntilde':'\xD1','ntilde':'\xF1','Oacute':'\xD3','oacute':'\xF3','Ocirc':'\xD4','ocirc':'\xF4','Ograve':'\xD2','ograve':'\xF2','ordf':'\xAA','ordm':'\xBA','Oslash':'\xD8','oslash':'\xF8','Otilde':'\xD5','otilde':'\xF5','Ouml':'\xD6','ouml':'\xF6','para':'\xB6','plusmn':'\xB1','pound':'\xA3','quot':'"','QUOT':'"','raquo':'\xBB','reg':'\xAE','REG':'\xAE','sect':'\xA7','shy':'\xAD','sup1':'\xB9','sup2':'\xB2','sup3':'\xB3','szlig':'\xDF','THORN':'\xDE','thorn':'\xFE','times':'\xD7','Uacute':'\xDA','uacute':'\xFA','Ucirc':'\xDB','ucirc':'\xFB','Ugrave':'\xD9','ugrave':'\xF9','uml':'\xA8','Uuml':'\xDC','uuml':'\xFC','Yacute':'\xDD','yacute':'\xFD','yen':'\xA5','yuml':'\xFF'};
  16178. var decodeMapNumeric = {'0':'\uFFFD','128':'\u20AC','130':'\u201A','131':'\u0192','132':'\u201E','133':'\u2026','134':'\u2020','135':'\u2021','136':'\u02C6','137':'\u2030','138':'\u0160','139':'\u2039','140':'\u0152','142':'\u017D','145':'\u2018','146':'\u2019','147':'\u201C','148':'\u201D','149':'\u2022','150':'\u2013','151':'\u2014','152':'\u02DC','153':'\u2122','154':'\u0161','155':'\u203A','156':'\u0153','158':'\u017E','159':'\u0178'};
  16179. var invalidReferenceCodePoints = [1,2,3,4,5,6,7,8,11,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,64976,64977,64978,64979,64980,64981,64982,64983,64984,64985,64986,64987,64988,64989,64990,64991,64992,64993,64994,64995,64996,64997,64998,64999,65000,65001,65002,65003,65004,65005,65006,65007,65534,65535,131070,131071,196606,196607,262142,262143,327678,327679,393214,393215,458750,458751,524286,524287,589822,589823,655358,655359,720894,720895,786430,786431,851966,851967,917502,917503,983038,983039,1048574,1048575,1114110,1114111];
  16180. /*--------------------------------------------------------------------------*/
  16181. var stringFromCharCode = String.fromCharCode;
  16182. var object = {};
  16183. var hasOwnProperty = object.hasOwnProperty;
  16184. var has = function(object, propertyName) {
  16185. return hasOwnProperty.call(object, propertyName);
  16186. };
  16187. var contains = function(array, value) {
  16188. var index = -1;
  16189. var length = array.length;
  16190. while (++index < length) {
  16191. if (array[index] == value) {
  16192. return true;
  16193. }
  16194. }
  16195. return false;
  16196. };
  16197. var merge = function(options, defaults) {
  16198. if (!options) {
  16199. return defaults;
  16200. }
  16201. var result = {};
  16202. var key;
  16203. for (key in defaults) {
  16204. // A `hasOwnProperty` check is not needed here, since only recognized
  16205. // option names are used anyway. Any others are ignored.
  16206. result[key] = has(options, key) ? options[key] : defaults[key];
  16207. }
  16208. return result;
  16209. };
  16210. // Modified version of `ucs2encode`; see http://mths.be/punycode.
  16211. var codePointToSymbol = function(codePoint, strict) {
  16212. var output = '';
  16213. if ((codePoint >= 0xD800 && codePoint <= 0xDFFF) || codePoint > 0x10FFFF) {
  16214. // See issue #4:
  16215. // “Otherwise, if the number is in the range 0xD800 to 0xDFFF or is
  16216. // greater than 0x10FFFF, then this is a parse error. Return a U+FFFD
  16217. // REPLACEMENT CHARACTER.”
  16218. if (strict) {
  16219. parseError('character reference outside the permissible Unicode range');
  16220. }
  16221. return '\uFFFD';
  16222. }
  16223. if (has(decodeMapNumeric, codePoint)) {
  16224. if (strict) {
  16225. parseError('disallowed character reference');
  16226. }
  16227. return decodeMapNumeric[codePoint];
  16228. }
  16229. if (strict && contains(invalidReferenceCodePoints, codePoint)) {
  16230. parseError('disallowed character reference');
  16231. }
  16232. if (codePoint > 0xFFFF) {
  16233. codePoint -= 0x10000;
  16234. output += stringFromCharCode(codePoint >>> 10 & 0x3FF | 0xD800);
  16235. codePoint = 0xDC00 | codePoint & 0x3FF;
  16236. }
  16237. output += stringFromCharCode(codePoint);
  16238. return output;
  16239. };
  16240. var hexEscape = function(symbol) {
  16241. return '&#x' + symbol.charCodeAt(0).toString(16).toUpperCase() + ';';
  16242. };
  16243. var parseError = function(message) {
  16244. throw Error('Parse error: ' + message);
  16245. };
  16246. /*--------------------------------------------------------------------------*/
  16247. var encode = function(string, options) {
  16248. options = merge(options, encode.options);
  16249. var strict = options.strict;
  16250. if (strict && regexInvalidRawCodePoint.test(string)) {
  16251. parseError('forbidden code point');
  16252. }
  16253. var encodeEverything = options.encodeEverything;
  16254. var useNamedReferences = options.useNamedReferences;
  16255. var allowUnsafeSymbols = options.allowUnsafeSymbols;
  16256. if (encodeEverything) {
  16257. // Encode ASCII symbols.
  16258. string = string.replace(regexAsciiWhitelist, function(symbol) {
  16259. // Use named references if requested & possible.
  16260. if (useNamedReferences && has(encodeMap, symbol)) {
  16261. return '&' + encodeMap[symbol] + ';';
  16262. }
  16263. return hexEscape(symbol);
  16264. });
  16265. // Shorten a few escapes that represent two symbols, of which at least one
  16266. // is within the ASCII range.
  16267. if (useNamedReferences) {
  16268. string = string
  16269. .replace(/&gt;\u20D2/g, '&nvgt;')
  16270. .replace(/&lt;\u20D2/g, '&nvlt;')
  16271. .replace(/&#x66;&#x6A;/g, '&fjlig;');
  16272. }
  16273. // Encode non-ASCII symbols.
  16274. if (useNamedReferences) {
  16275. // Encode non-ASCII symbols that can be replaced with a named reference.
  16276. string = string.replace(regexEncodeNonAscii, function(string) {
  16277. // Note: there is no need to check `has(encodeMap, string)` here.
  16278. return '&' + encodeMap[string] + ';';
  16279. });
  16280. }
  16281. // Note: any remaining non-ASCII symbols are handled outside of the `if`.
  16282. } else if (useNamedReferences) {
  16283. // Apply named character references.
  16284. // Encode `<>"'&` using named character references.
  16285. if (!allowUnsafeSymbols) {
  16286. string = string.replace(regexEscape, function(string) {
  16287. return '&' + encodeMap[string] + ';'; // no need to check `has()` here
  16288. });
  16289. }
  16290. // Shorten escapes that represent two symbols, of which at least one is
  16291. // `<>"'&`.
  16292. string = string
  16293. .replace(/&gt;\u20D2/g, '&nvgt;')
  16294. .replace(/&lt;\u20D2/g, '&nvlt;');
  16295. // Encode non-ASCII symbols that can be replaced with a named reference.
  16296. string = string.replace(regexEncodeNonAscii, function(string) {
  16297. // Note: there is no need to check `has(encodeMap, string)` here.
  16298. return '&' + encodeMap[string] + ';';
  16299. });
  16300. } else if (!allowUnsafeSymbols) {
  16301. // Encode `<>"'&` using hexadecimal escapes, now that they’re not handled
  16302. // using named character references.
  16303. string = string.replace(regexEscape, hexEscape);
  16304. }
  16305. return string
  16306. // Encode astral symbols.
  16307. .replace(regexAstralSymbols, function($0) {
  16308. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  16309. var high = $0.charCodeAt(0);
  16310. var low = $0.charCodeAt(1);
  16311. var codePoint = (high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000;
  16312. return '&#x' + codePoint.toString(16).toUpperCase() + ';';
  16313. })
  16314. // Encode any remaining BMP symbols that are not printable ASCII symbols
  16315. // using a hexadecimal escape.
  16316. .replace(regexBmpWhitelist, hexEscape);
  16317. };
  16318. // Expose default options (so they can be overridden globally).
  16319. encode.options = {
  16320. 'allowUnsafeSymbols': false,
  16321. 'encodeEverything': false,
  16322. 'strict': false,
  16323. 'useNamedReferences': false
  16324. };
  16325. var decode = function(html, options) {
  16326. options = merge(options, decode.options);
  16327. var strict = options.strict;
  16328. if (strict && regexInvalidEntity.test(html)) {
  16329. parseError('malformed character reference');
  16330. }
  16331. return html.replace(regexDecode, function($0, $1, $2, $3, $4, $5, $6, $7) {
  16332. var codePoint;
  16333. var semicolon;
  16334. var hexDigits;
  16335. var reference;
  16336. var next;
  16337. if ($1) {
  16338. // Decode decimal escapes, e.g. `&#119558;`.
  16339. codePoint = $1;
  16340. semicolon = $2;
  16341. if (strict && !semicolon) {
  16342. parseError('character reference was not terminated by a semicolon');
  16343. }
  16344. return codePointToSymbol(codePoint, strict);
  16345. }
  16346. if ($3) {
  16347. // Decode hexadecimal escapes, e.g. `&#x1D306;`.
  16348. hexDigits = $3;
  16349. semicolon = $4;
  16350. if (strict && !semicolon) {
  16351. parseError('character reference was not terminated by a semicolon');
  16352. }
  16353. codePoint = parseInt(hexDigits, 16);
  16354. return codePointToSymbol(codePoint, strict);
  16355. }
  16356. if ($5) {
  16357. // Decode named character references with trailing `;`, e.g. `&copy;`.
  16358. reference = $5;
  16359. if (has(decodeMap, reference)) {
  16360. return decodeMap[reference];
  16361. } else {
  16362. // Ambiguous ampersand; see http://mths.be/notes/ambiguous-ampersands.
  16363. if (strict) {
  16364. parseError(
  16365. 'named character reference was not terminated by a semicolon'
  16366. );
  16367. }
  16368. return $0;
  16369. }
  16370. }
  16371. // If we’re still here, it’s a legacy reference for sure. No need for an
  16372. // extra `if` check.
  16373. // Decode named character references without trailing `;`, e.g. `&amp`
  16374. // This is only a parse error if it gets converted to `&`, or if it is
  16375. // followed by `=` in an attribute context.
  16376. reference = $6;
  16377. next = $7;
  16378. if (next && options.isAttributeValue) {
  16379. if (strict && next == '=') {
  16380. parseError('`&` did not start a character reference');
  16381. }
  16382. return $0;
  16383. } else {
  16384. if (strict) {
  16385. parseError(
  16386. 'named character reference was not terminated by a semicolon'
  16387. );
  16388. }
  16389. // Note: there is no need to check `has(decodeMapLegacy, reference)`.
  16390. return decodeMapLegacy[reference] + (next || '');
  16391. }
  16392. });
  16393. };
  16394. // Expose default options (so they can be overridden globally).
  16395. decode.options = {
  16396. 'isAttributeValue': false,
  16397. 'strict': false
  16398. };
  16399. var escape = function(string) {
  16400. return string.replace(regexEscape, function($0) {
  16401. // Note: there is no need to check `has(escapeMap, $0)` here.
  16402. return escapeMap[$0];
  16403. });
  16404. };
  16405. /*--------------------------------------------------------------------------*/
  16406. var he = {
  16407. 'version': '0.5.0',
  16408. 'encode': encode,
  16409. 'decode': decode,
  16410. 'escape': escape,
  16411. 'unescape': decode
  16412. };
  16413. // Some AMD build optimizers, like r.js, check for specific condition patterns
  16414. // like the following:
  16415. if (
  16416. typeof define == 'function' &&
  16417. typeof define.amd == 'object' &&
  16418. define.amd
  16419. ) {
  16420. define(function() {
  16421. return he;
  16422. });
  16423. } else if (freeExports && !freeExports.nodeType) {
  16424. if (freeModule) { // in Node.js or RingoJS v0.8.0+
  16425. freeModule.exports = he;
  16426. } else { // in Narwhal or RingoJS v0.7.0-
  16427. for (var key in he) {
  16428. has(he, key) && (freeExports[key] = he[key]);
  16429. }
  16430. }
  16431. } else { // in Rhino or a web browser
  16432. root.he = he;
  16433. }
  16434. }(this));
  16435. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  16436. },{}],103:[function(require,module,exports){
  16437. (function (global){
  16438. /**
  16439. * @license
  16440. * lodash <https://lodash.com/>
  16441. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  16442. * Released under MIT license <https://lodash.com/license>
  16443. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  16444. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  16445. */
  16446. ;(function() {
  16447. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  16448. var undefined;
  16449. /** Used as the semantic version number. */
  16450. var VERSION = '4.13.1';
  16451. /** Used as the size to enable large array optimizations. */
  16452. var LARGE_ARRAY_SIZE = 200;
  16453. /** Used as the `TypeError` message for "Functions" methods. */
  16454. var FUNC_ERROR_TEXT = 'Expected a function';
  16455. /** Used to stand-in for `undefined` hash values. */
  16456. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  16457. /** Used as the internal argument placeholder. */
  16458. var PLACEHOLDER = '__lodash_placeholder__';
  16459. /** Used to compose bitmasks for wrapper metadata. */
  16460. var BIND_FLAG = 1,
  16461. BIND_KEY_FLAG = 2,
  16462. CURRY_BOUND_FLAG = 4,
  16463. CURRY_FLAG = 8,
  16464. CURRY_RIGHT_FLAG = 16,
  16465. PARTIAL_FLAG = 32,
  16466. PARTIAL_RIGHT_FLAG = 64,
  16467. ARY_FLAG = 128,
  16468. REARG_FLAG = 256,
  16469. FLIP_FLAG = 512;
  16470. /** Used to compose bitmasks for comparison styles. */
  16471. var UNORDERED_COMPARE_FLAG = 1,
  16472. PARTIAL_COMPARE_FLAG = 2;
  16473. /** Used as default options for `_.truncate`. */
  16474. var DEFAULT_TRUNC_LENGTH = 30,
  16475. DEFAULT_TRUNC_OMISSION = '...';
  16476. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  16477. var HOT_COUNT = 150,
  16478. HOT_SPAN = 16;
  16479. /** Used to indicate the type of lazy iteratees. */
  16480. var LAZY_FILTER_FLAG = 1,
  16481. LAZY_MAP_FLAG = 2,
  16482. LAZY_WHILE_FLAG = 3;
  16483. /** Used as references for various `Number` constants. */
  16484. var INFINITY = 1 / 0,
  16485. MAX_SAFE_INTEGER = 9007199254740991,
  16486. MAX_INTEGER = 1.7976931348623157e+308,
  16487. NAN = 0 / 0;
  16488. /** Used as references for the maximum length and index of an array. */
  16489. var MAX_ARRAY_LENGTH = 4294967295,
  16490. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  16491. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  16492. /** `Object#toString` result references. */
  16493. var argsTag = '[object Arguments]',
  16494. arrayTag = '[object Array]',
  16495. boolTag = '[object Boolean]',
  16496. dateTag = '[object Date]',
  16497. errorTag = '[object Error]',
  16498. funcTag = '[object Function]',
  16499. genTag = '[object GeneratorFunction]',
  16500. mapTag = '[object Map]',
  16501. numberTag = '[object Number]',
  16502. objectTag = '[object Object]',
  16503. promiseTag = '[object Promise]',
  16504. regexpTag = '[object RegExp]',
  16505. setTag = '[object Set]',
  16506. stringTag = '[object String]',
  16507. symbolTag = '[object Symbol]',
  16508. weakMapTag = '[object WeakMap]',
  16509. weakSetTag = '[object WeakSet]';
  16510. var arrayBufferTag = '[object ArrayBuffer]',
  16511. dataViewTag = '[object DataView]',
  16512. float32Tag = '[object Float32Array]',
  16513. float64Tag = '[object Float64Array]',
  16514. int8Tag = '[object Int8Array]',
  16515. int16Tag = '[object Int16Array]',
  16516. int32Tag = '[object Int32Array]',
  16517. uint8Tag = '[object Uint8Array]',
  16518. uint8ClampedTag = '[object Uint8ClampedArray]',
  16519. uint16Tag = '[object Uint16Array]',
  16520. uint32Tag = '[object Uint32Array]';
  16521. /** Used to match empty string literals in compiled template source. */
  16522. var reEmptyStringLeading = /\b__p \+= '';/g,
  16523. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  16524. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  16525. /** Used to match HTML entities and HTML characters. */
  16526. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
  16527. reUnescapedHtml = /[&<>"'`]/g,
  16528. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  16529. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  16530. /** Used to match template delimiters. */
  16531. var reEscape = /<%-([\s\S]+?)%>/g,
  16532. reEvaluate = /<%([\s\S]+?)%>/g,
  16533. reInterpolate = /<%=([\s\S]+?)%>/g;
  16534. /** Used to match property names within property paths. */
  16535. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  16536. reIsPlainProp = /^\w*$/,
  16537. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(\.|\[\])(?:\4|$))/g;
  16538. /**
  16539. * Used to match `RegExp`
  16540. * [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns).
  16541. */
  16542. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  16543. reHasRegExpChar = RegExp(reRegExpChar.source);
  16544. /** Used to match leading and trailing whitespace. */
  16545. var reTrim = /^\s+|\s+$/g,
  16546. reTrimStart = /^\s+/,
  16547. reTrimEnd = /\s+$/;
  16548. /** Used to match non-compound words composed of alphanumeric characters. */
  16549. var reBasicWord = /[a-zA-Z0-9]+/g;
  16550. /** Used to match backslashes in property paths. */
  16551. var reEscapeChar = /\\(\\)?/g;
  16552. /**
  16553. * Used to match
  16554. * [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components).
  16555. */
  16556. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  16557. /** Used to match `RegExp` flags from their coerced string values. */
  16558. var reFlags = /\w*$/;
  16559. /** Used to detect hexadecimal string values. */
  16560. var reHasHexPrefix = /^0x/i;
  16561. /** Used to detect bad signed hexadecimal string values. */
  16562. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  16563. /** Used to detect binary string values. */
  16564. var reIsBinary = /^0b[01]+$/i;
  16565. /** Used to detect host constructors (Safari). */
  16566. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  16567. /** Used to detect octal string values. */
  16568. var reIsOctal = /^0o[0-7]+$/i;
  16569. /** Used to detect unsigned integer values. */
  16570. var reIsUint = /^(?:0|[1-9]\d*)$/;
  16571. /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
  16572. var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
  16573. /** Used to ensure capturing order of template delimiters. */
  16574. var reNoMatch = /($^)/;
  16575. /** Used to match unescaped characters in compiled string literals. */
  16576. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  16577. /** Used to compose unicode character classes. */
  16578. var rsAstralRange = '\\ud800-\\udfff',
  16579. rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
  16580. rsComboSymbolsRange = '\\u20d0-\\u20f0',
  16581. rsDingbatRange = '\\u2700-\\u27bf',
  16582. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  16583. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  16584. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  16585. rsPunctuationRange = '\\u2000-\\u206f',
  16586. 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',
  16587. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  16588. rsVarRange = '\\ufe0e\\ufe0f',
  16589. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  16590. /** Used to compose unicode capture groups. */
  16591. var rsApos = "['\u2019]",
  16592. rsAstral = '[' + rsAstralRange + ']',
  16593. rsBreak = '[' + rsBreakRange + ']',
  16594. rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
  16595. rsDigits = '\\d+',
  16596. rsDingbat = '[' + rsDingbatRange + ']',
  16597. rsLower = '[' + rsLowerRange + ']',
  16598. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  16599. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  16600. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  16601. rsNonAstral = '[^' + rsAstralRange + ']',
  16602. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  16603. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  16604. rsUpper = '[' + rsUpperRange + ']',
  16605. rsZWJ = '\\u200d';
  16606. /** Used to compose unicode regexes. */
  16607. var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')',
  16608. rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')',
  16609. rsOptLowerContr = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  16610. rsOptUpperContr = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  16611. reOptMod = rsModifier + '?',
  16612. rsOptVar = '[' + rsVarRange + ']?',
  16613. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  16614. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  16615. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  16616. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  16617. /** Used to match apostrophes. */
  16618. var reApos = RegExp(rsApos, 'g');
  16619. /**
  16620. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  16621. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  16622. */
  16623. var reComboMark = RegExp(rsCombo, 'g');
  16624. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  16625. var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  16626. /** Used to match complex or compound words. */
  16627. var reComplexWord = RegExp([
  16628. rsUpper + '?' + rsLower + '+' + rsOptLowerContr + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  16629. rsUpperMisc + '+' + rsOptUpperContr + '(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')',
  16630. rsUpper + '?' + rsLowerMisc + '+' + rsOptLowerContr,
  16631. rsUpper + '+' + rsOptUpperContr,
  16632. rsDigits,
  16633. rsEmoji
  16634. ].join('|'), 'g');
  16635. /** 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/). */
  16636. var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
  16637. /** Used to detect strings that need a more robust regexp to match words. */
  16638. 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 ]/;
  16639. /** Used to assign default `context` object properties. */
  16640. var contextProps = [
  16641. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  16642. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  16643. 'Promise', 'Reflect', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError',
  16644. 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  16645. '_', 'isFinite', 'parseInt', 'setTimeout'
  16646. ];
  16647. /** Used to make template sourceURLs easier to identify. */
  16648. var templateCounter = -1;
  16649. /** Used to identify `toStringTag` values of typed arrays. */
  16650. var typedArrayTags = {};
  16651. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  16652. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  16653. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  16654. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  16655. typedArrayTags[uint32Tag] = true;
  16656. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  16657. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  16658. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  16659. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  16660. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  16661. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  16662. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  16663. typedArrayTags[weakMapTag] = false;
  16664. /** Used to identify `toStringTag` values supported by `_.clone`. */
  16665. var cloneableTags = {};
  16666. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  16667. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  16668. cloneableTags[boolTag] = cloneableTags[dateTag] =
  16669. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  16670. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  16671. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  16672. cloneableTags[numberTag] = cloneableTags[objectTag] =
  16673. cloneableTags[regexpTag] = cloneableTags[setTag] =
  16674. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  16675. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  16676. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  16677. cloneableTags[errorTag] = cloneableTags[funcTag] =
  16678. cloneableTags[weakMapTag] = false;
  16679. /** Used to map latin-1 supplementary letters to basic latin letters. */
  16680. var deburredLetters = {
  16681. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  16682. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  16683. '\xc7': 'C', '\xe7': 'c',
  16684. '\xd0': 'D', '\xf0': 'd',
  16685. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  16686. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  16687. '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  16688. '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  16689. '\xd1': 'N', '\xf1': 'n',
  16690. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  16691. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  16692. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  16693. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  16694. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  16695. '\xc6': 'Ae', '\xe6': 'ae',
  16696. '\xde': 'Th', '\xfe': 'th',
  16697. '\xdf': 'ss'
  16698. };
  16699. /** Used to map characters to HTML entities. */
  16700. var htmlEscapes = {
  16701. '&': '&amp;',
  16702. '<': '&lt;',
  16703. '>': '&gt;',
  16704. '"': '&quot;',
  16705. "'": '&#39;',
  16706. '`': '&#96;'
  16707. };
  16708. /** Used to map HTML entities to characters. */
  16709. var htmlUnescapes = {
  16710. '&amp;': '&',
  16711. '&lt;': '<',
  16712. '&gt;': '>',
  16713. '&quot;': '"',
  16714. '&#39;': "'",
  16715. '&#96;': '`'
  16716. };
  16717. /** Used to escape characters for inclusion in compiled string literals. */
  16718. var stringEscapes = {
  16719. '\\': '\\',
  16720. "'": "'",
  16721. '\n': 'n',
  16722. '\r': 'r',
  16723. '\u2028': 'u2028',
  16724. '\u2029': 'u2029'
  16725. };
  16726. /** Built-in method references without a dependency on `root`. */
  16727. var freeParseFloat = parseFloat,
  16728. freeParseInt = parseInt;
  16729. /** Detect free variable `exports`. */
  16730. var freeExports = typeof exports == 'object' && exports;
  16731. /** Detect free variable `module`. */
  16732. var freeModule = freeExports && typeof module == 'object' && module;
  16733. /** Detect the popular CommonJS extension `module.exports`. */
  16734. var moduleExports = freeModule && freeModule.exports === freeExports;
  16735. /** Detect free variable `global` from Node.js. */
  16736. var freeGlobal = checkGlobal(typeof global == 'object' && global);
  16737. /** Detect free variable `self`. */
  16738. var freeSelf = checkGlobal(typeof self == 'object' && self);
  16739. /** Detect `this` as the global object. */
  16740. var thisGlobal = checkGlobal(typeof this == 'object' && this);
  16741. /** Used as a reference to the global object. */
  16742. var root = freeGlobal || freeSelf || thisGlobal || Function('return this')();
  16743. /*--------------------------------------------------------------------------*/
  16744. /**
  16745. * Adds the key-value `pair` to `map`.
  16746. *
  16747. * @private
  16748. * @param {Object} map The map to modify.
  16749. * @param {Array} pair The key-value pair to add.
  16750. * @returns {Object} Returns `map`.
  16751. */
  16752. function addMapEntry(map, pair) {
  16753. // Don't return `Map#set` because it doesn't return the map instance in IE 11.
  16754. map.set(pair[0], pair[1]);
  16755. return map;
  16756. }
  16757. /**
  16758. * Adds `value` to `set`.
  16759. *
  16760. * @private
  16761. * @param {Object} set The set to modify.
  16762. * @param {*} value The value to add.
  16763. * @returns {Object} Returns `set`.
  16764. */
  16765. function addSetEntry(set, value) {
  16766. set.add(value);
  16767. return set;
  16768. }
  16769. /**
  16770. * A faster alternative to `Function#apply`, this function invokes `func`
  16771. * with the `this` binding of `thisArg` and the arguments of `args`.
  16772. *
  16773. * @private
  16774. * @param {Function} func The function to invoke.
  16775. * @param {*} thisArg The `this` binding of `func`.
  16776. * @param {Array} args The arguments to invoke `func` with.
  16777. * @returns {*} Returns the result of `func`.
  16778. */
  16779. function apply(func, thisArg, args) {
  16780. var length = args.length;
  16781. switch (length) {
  16782. case 0: return func.call(thisArg);
  16783. case 1: return func.call(thisArg, args[0]);
  16784. case 2: return func.call(thisArg, args[0], args[1]);
  16785. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  16786. }
  16787. return func.apply(thisArg, args);
  16788. }
  16789. /**
  16790. * A specialized version of `baseAggregator` for arrays.
  16791. *
  16792. * @private
  16793. * @param {Array} [array] The array to iterate over.
  16794. * @param {Function} setter The function to set `accumulator` values.
  16795. * @param {Function} iteratee The iteratee to transform keys.
  16796. * @param {Object} accumulator The initial aggregated object.
  16797. * @returns {Function} Returns `accumulator`.
  16798. */
  16799. function arrayAggregator(array, setter, iteratee, accumulator) {
  16800. var index = -1,
  16801. length = array ? array.length : 0;
  16802. while (++index < length) {
  16803. var value = array[index];
  16804. setter(accumulator, value, iteratee(value), array);
  16805. }
  16806. return accumulator;
  16807. }
  16808. /**
  16809. * A specialized version of `_.forEach` for arrays without support for
  16810. * iteratee shorthands.
  16811. *
  16812. * @private
  16813. * @param {Array} [array] The array to iterate over.
  16814. * @param {Function} iteratee The function invoked per iteration.
  16815. * @returns {Array} Returns `array`.
  16816. */
  16817. function arrayEach(array, iteratee) {
  16818. var index = -1,
  16819. length = array ? array.length : 0;
  16820. while (++index < length) {
  16821. if (iteratee(array[index], index, array) === false) {
  16822. break;
  16823. }
  16824. }
  16825. return array;
  16826. }
  16827. /**
  16828. * A specialized version of `_.forEachRight` for arrays without support for
  16829. * iteratee shorthands.
  16830. *
  16831. * @private
  16832. * @param {Array} [array] The array to iterate over.
  16833. * @param {Function} iteratee The function invoked per iteration.
  16834. * @returns {Array} Returns `array`.
  16835. */
  16836. function arrayEachRight(array, iteratee) {
  16837. var length = array ? array.length : 0;
  16838. while (length--) {
  16839. if (iteratee(array[length], length, array) === false) {
  16840. break;
  16841. }
  16842. }
  16843. return array;
  16844. }
  16845. /**
  16846. * A specialized version of `_.every` for arrays without support for
  16847. * iteratee shorthands.
  16848. *
  16849. * @private
  16850. * @param {Array} [array] The array to iterate over.
  16851. * @param {Function} predicate The function invoked per iteration.
  16852. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  16853. * else `false`.
  16854. */
  16855. function arrayEvery(array, predicate) {
  16856. var index = -1,
  16857. length = array ? array.length : 0;
  16858. while (++index < length) {
  16859. if (!predicate(array[index], index, array)) {
  16860. return false;
  16861. }
  16862. }
  16863. return true;
  16864. }
  16865. /**
  16866. * A specialized version of `_.filter` for arrays without support for
  16867. * iteratee shorthands.
  16868. *
  16869. * @private
  16870. * @param {Array} [array] The array to iterate over.
  16871. * @param {Function} predicate The function invoked per iteration.
  16872. * @returns {Array} Returns the new filtered array.
  16873. */
  16874. function arrayFilter(array, predicate) {
  16875. var index = -1,
  16876. length = array ? array.length : 0,
  16877. resIndex = 0,
  16878. result = [];
  16879. while (++index < length) {
  16880. var value = array[index];
  16881. if (predicate(value, index, array)) {
  16882. result[resIndex++] = value;
  16883. }
  16884. }
  16885. return result;
  16886. }
  16887. /**
  16888. * A specialized version of `_.includes` for arrays without support for
  16889. * specifying an index to search from.
  16890. *
  16891. * @private
  16892. * @param {Array} [array] The array to search.
  16893. * @param {*} target The value to search for.
  16894. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  16895. */
  16896. function arrayIncludes(array, value) {
  16897. var length = array ? array.length : 0;
  16898. return !!length && baseIndexOf(array, value, 0) > -1;
  16899. }
  16900. /**
  16901. * This function is like `arrayIncludes` except that it accepts a comparator.
  16902. *
  16903. * @private
  16904. * @param {Array} [array] The array to search.
  16905. * @param {*} target The value to search for.
  16906. * @param {Function} comparator The comparator invoked per element.
  16907. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  16908. */
  16909. function arrayIncludesWith(array, value, comparator) {
  16910. var index = -1,
  16911. length = array ? array.length : 0;
  16912. while (++index < length) {
  16913. if (comparator(value, array[index])) {
  16914. return true;
  16915. }
  16916. }
  16917. return false;
  16918. }
  16919. /**
  16920. * A specialized version of `_.map` for arrays without support for iteratee
  16921. * shorthands.
  16922. *
  16923. * @private
  16924. * @param {Array} [array] The array to iterate over.
  16925. * @param {Function} iteratee The function invoked per iteration.
  16926. * @returns {Array} Returns the new mapped array.
  16927. */
  16928. function arrayMap(array, iteratee) {
  16929. var index = -1,
  16930. length = array ? array.length : 0,
  16931. result = Array(length);
  16932. while (++index < length) {
  16933. result[index] = iteratee(array[index], index, array);
  16934. }
  16935. return result;
  16936. }
  16937. /**
  16938. * Appends the elements of `values` to `array`.
  16939. *
  16940. * @private
  16941. * @param {Array} array The array to modify.
  16942. * @param {Array} values The values to append.
  16943. * @returns {Array} Returns `array`.
  16944. */
  16945. function arrayPush(array, values) {
  16946. var index = -1,
  16947. length = values.length,
  16948. offset = array.length;
  16949. while (++index < length) {
  16950. array[offset + index] = values[index];
  16951. }
  16952. return array;
  16953. }
  16954. /**
  16955. * A specialized version of `_.reduce` for arrays without support for
  16956. * iteratee shorthands.
  16957. *
  16958. * @private
  16959. * @param {Array} [array] The array to iterate over.
  16960. * @param {Function} iteratee The function invoked per iteration.
  16961. * @param {*} [accumulator] The initial value.
  16962. * @param {boolean} [initAccum] Specify using the first element of `array` as
  16963. * the initial value.
  16964. * @returns {*} Returns the accumulated value.
  16965. */
  16966. function arrayReduce(array, iteratee, accumulator, initAccum) {
  16967. var index = -1,
  16968. length = array ? array.length : 0;
  16969. if (initAccum && length) {
  16970. accumulator = array[++index];
  16971. }
  16972. while (++index < length) {
  16973. accumulator = iteratee(accumulator, array[index], index, array);
  16974. }
  16975. return accumulator;
  16976. }
  16977. /**
  16978. * A specialized version of `_.reduceRight` for arrays without support for
  16979. * iteratee shorthands.
  16980. *
  16981. * @private
  16982. * @param {Array} [array] The array to iterate over.
  16983. * @param {Function} iteratee The function invoked per iteration.
  16984. * @param {*} [accumulator] The initial value.
  16985. * @param {boolean} [initAccum] Specify using the last element of `array` as
  16986. * the initial value.
  16987. * @returns {*} Returns the accumulated value.
  16988. */
  16989. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  16990. var length = array ? array.length : 0;
  16991. if (initAccum && length) {
  16992. accumulator = array[--length];
  16993. }
  16994. while (length--) {
  16995. accumulator = iteratee(accumulator, array[length], length, array);
  16996. }
  16997. return accumulator;
  16998. }
  16999. /**
  17000. * A specialized version of `_.some` for arrays without support for iteratee
  17001. * shorthands.
  17002. *
  17003. * @private
  17004. * @param {Array} [array] The array to iterate over.
  17005. * @param {Function} predicate The function invoked per iteration.
  17006. * @returns {boolean} Returns `true` if any element passes the predicate check,
  17007. * else `false`.
  17008. */
  17009. function arraySome(array, predicate) {
  17010. var index = -1,
  17011. length = array ? array.length : 0;
  17012. while (++index < length) {
  17013. if (predicate(array[index], index, array)) {
  17014. return true;
  17015. }
  17016. }
  17017. return false;
  17018. }
  17019. /**
  17020. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  17021. * without support for iteratee shorthands, which iterates over `collection`
  17022. * using `eachFunc`.
  17023. *
  17024. * @private
  17025. * @param {Array|Object} collection The collection to search.
  17026. * @param {Function} predicate The function invoked per iteration.
  17027. * @param {Function} eachFunc The function to iterate over `collection`.
  17028. * @returns {*} Returns the found element or its key, else `undefined`.
  17029. */
  17030. function baseFindKey(collection, predicate, eachFunc) {
  17031. var result;
  17032. eachFunc(collection, function(value, key, collection) {
  17033. if (predicate(value, key, collection)) {
  17034. result = key;
  17035. return false;
  17036. }
  17037. });
  17038. return result;
  17039. }
  17040. /**
  17041. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  17042. * support for iteratee shorthands.
  17043. *
  17044. * @private
  17045. * @param {Array} array The array to search.
  17046. * @param {Function} predicate The function invoked per iteration.
  17047. * @param {number} fromIndex The index to search from.
  17048. * @param {boolean} [fromRight] Specify iterating from right to left.
  17049. * @returns {number} Returns the index of the matched value, else `-1`.
  17050. */
  17051. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  17052. var length = array.length,
  17053. index = fromIndex + (fromRight ? 1 : -1);
  17054. while ((fromRight ? index-- : ++index < length)) {
  17055. if (predicate(array[index], index, array)) {
  17056. return index;
  17057. }
  17058. }
  17059. return -1;
  17060. }
  17061. /**
  17062. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  17063. *
  17064. * @private
  17065. * @param {Array} array The array to search.
  17066. * @param {*} value The value to search for.
  17067. * @param {number} fromIndex The index to search from.
  17068. * @returns {number} Returns the index of the matched value, else `-1`.
  17069. */
  17070. function baseIndexOf(array, value, fromIndex) {
  17071. if (value !== value) {
  17072. return indexOfNaN(array, fromIndex);
  17073. }
  17074. var index = fromIndex - 1,
  17075. length = array.length;
  17076. while (++index < length) {
  17077. if (array[index] === value) {
  17078. return index;
  17079. }
  17080. }
  17081. return -1;
  17082. }
  17083. /**
  17084. * This function is like `baseIndexOf` except that it accepts a comparator.
  17085. *
  17086. * @private
  17087. * @param {Array} array The array to search.
  17088. * @param {*} value The value to search for.
  17089. * @param {number} fromIndex The index to search from.
  17090. * @param {Function} comparator The comparator invoked per element.
  17091. * @returns {number} Returns the index of the matched value, else `-1`.
  17092. */
  17093. function baseIndexOfWith(array, value, fromIndex, comparator) {
  17094. var index = fromIndex - 1,
  17095. length = array.length;
  17096. while (++index < length) {
  17097. if (comparator(array[index], value)) {
  17098. return index;
  17099. }
  17100. }
  17101. return -1;
  17102. }
  17103. /**
  17104. * The base implementation of `_.mean` and `_.meanBy` without support for
  17105. * iteratee shorthands.
  17106. *
  17107. * @private
  17108. * @param {Array} array The array to iterate over.
  17109. * @param {Function} iteratee The function invoked per iteration.
  17110. * @returns {number} Returns the mean.
  17111. */
  17112. function baseMean(array, iteratee) {
  17113. var length = array ? array.length : 0;
  17114. return length ? (baseSum(array, iteratee) / length) : NAN;
  17115. }
  17116. /**
  17117. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  17118. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  17119. *
  17120. * @private
  17121. * @param {Array|Object} collection The collection to iterate over.
  17122. * @param {Function} iteratee The function invoked per iteration.
  17123. * @param {*} accumulator The initial value.
  17124. * @param {boolean} initAccum Specify using the first or last element of
  17125. * `collection` as the initial value.
  17126. * @param {Function} eachFunc The function to iterate over `collection`.
  17127. * @returns {*} Returns the accumulated value.
  17128. */
  17129. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  17130. eachFunc(collection, function(value, index, collection) {
  17131. accumulator = initAccum
  17132. ? (initAccum = false, value)
  17133. : iteratee(accumulator, value, index, collection);
  17134. });
  17135. return accumulator;
  17136. }
  17137. /**
  17138. * The base implementation of `_.sortBy` which uses `comparer` to define the
  17139. * sort order of `array` and replaces criteria objects with their corresponding
  17140. * values.
  17141. *
  17142. * @private
  17143. * @param {Array} array The array to sort.
  17144. * @param {Function} comparer The function to define sort order.
  17145. * @returns {Array} Returns `array`.
  17146. */
  17147. function baseSortBy(array, comparer) {
  17148. var length = array.length;
  17149. array.sort(comparer);
  17150. while (length--) {
  17151. array[length] = array[length].value;
  17152. }
  17153. return array;
  17154. }
  17155. /**
  17156. * The base implementation of `_.sum` and `_.sumBy` without support for
  17157. * iteratee shorthands.
  17158. *
  17159. * @private
  17160. * @param {Array} array The array to iterate over.
  17161. * @param {Function} iteratee The function invoked per iteration.
  17162. * @returns {number} Returns the sum.
  17163. */
  17164. function baseSum(array, iteratee) {
  17165. var result,
  17166. index = -1,
  17167. length = array.length;
  17168. while (++index < length) {
  17169. var current = iteratee(array[index]);
  17170. if (current !== undefined) {
  17171. result = result === undefined ? current : (result + current);
  17172. }
  17173. }
  17174. return result;
  17175. }
  17176. /**
  17177. * The base implementation of `_.times` without support for iteratee shorthands
  17178. * or max array length checks.
  17179. *
  17180. * @private
  17181. * @param {number} n The number of times to invoke `iteratee`.
  17182. * @param {Function} iteratee The function invoked per iteration.
  17183. * @returns {Array} Returns the array of results.
  17184. */
  17185. function baseTimes(n, iteratee) {
  17186. var index = -1,
  17187. result = Array(n);
  17188. while (++index < n) {
  17189. result[index] = iteratee(index);
  17190. }
  17191. return result;
  17192. }
  17193. /**
  17194. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  17195. * of key-value pairs for `object` corresponding to the property names of `props`.
  17196. *
  17197. * @private
  17198. * @param {Object} object The object to query.
  17199. * @param {Array} props The property names to get values for.
  17200. * @returns {Object} Returns the key-value pairs.
  17201. */
  17202. function baseToPairs(object, props) {
  17203. return arrayMap(props, function(key) {
  17204. return [key, object[key]];
  17205. });
  17206. }
  17207. /**
  17208. * The base implementation of `_.unary` without support for storing wrapper metadata.
  17209. *
  17210. * @private
  17211. * @param {Function} func The function to cap arguments for.
  17212. * @returns {Function} Returns the new capped function.
  17213. */
  17214. function baseUnary(func) {
  17215. return function(value) {
  17216. return func(value);
  17217. };
  17218. }
  17219. /**
  17220. * The base implementation of `_.values` and `_.valuesIn` which creates an
  17221. * array of `object` property values corresponding to the property names
  17222. * of `props`.
  17223. *
  17224. * @private
  17225. * @param {Object} object The object to query.
  17226. * @param {Array} props The property names to get values for.
  17227. * @returns {Object} Returns the array of property values.
  17228. */
  17229. function baseValues(object, props) {
  17230. return arrayMap(props, function(key) {
  17231. return object[key];
  17232. });
  17233. }
  17234. /**
  17235. * Checks if a cache value for `key` exists.
  17236. *
  17237. * @private
  17238. * @param {Object} cache The cache to query.
  17239. * @param {string} key The key of the entry to check.
  17240. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  17241. */
  17242. function cacheHas(cache, key) {
  17243. return cache.has(key);
  17244. }
  17245. /**
  17246. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  17247. * that is not found in the character symbols.
  17248. *
  17249. * @private
  17250. * @param {Array} strSymbols The string symbols to inspect.
  17251. * @param {Array} chrSymbols The character symbols to find.
  17252. * @returns {number} Returns the index of the first unmatched string symbol.
  17253. */
  17254. function charsStartIndex(strSymbols, chrSymbols) {
  17255. var index = -1,
  17256. length = strSymbols.length;
  17257. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  17258. return index;
  17259. }
  17260. /**
  17261. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  17262. * that is not found in the character symbols.
  17263. *
  17264. * @private
  17265. * @param {Array} strSymbols The string symbols to inspect.
  17266. * @param {Array} chrSymbols The character symbols to find.
  17267. * @returns {number} Returns the index of the last unmatched string symbol.
  17268. */
  17269. function charsEndIndex(strSymbols, chrSymbols) {
  17270. var index = strSymbols.length;
  17271. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  17272. return index;
  17273. }
  17274. /**
  17275. * Checks if `value` is a global object.
  17276. *
  17277. * @private
  17278. * @param {*} value The value to check.
  17279. * @returns {null|Object} Returns `value` if it's a global object, else `null`.
  17280. */
  17281. function checkGlobal(value) {
  17282. return (value && value.Object === Object) ? value : null;
  17283. }
  17284. /**
  17285. * Gets the number of `placeholder` occurrences in `array`.
  17286. *
  17287. * @private
  17288. * @param {Array} array The array to inspect.
  17289. * @param {*} placeholder The placeholder to search for.
  17290. * @returns {number} Returns the placeholder count.
  17291. */
  17292. function countHolders(array, placeholder) {
  17293. var length = array.length,
  17294. result = 0;
  17295. while (length--) {
  17296. if (array[length] === placeholder) {
  17297. result++;
  17298. }
  17299. }
  17300. return result;
  17301. }
  17302. /**
  17303. * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
  17304. *
  17305. * @private
  17306. * @param {string} letter The matched letter to deburr.
  17307. * @returns {string} Returns the deburred letter.
  17308. */
  17309. function deburrLetter(letter) {
  17310. return deburredLetters[letter];
  17311. }
  17312. /**
  17313. * Used by `_.escape` to convert characters to HTML entities.
  17314. *
  17315. * @private
  17316. * @param {string} chr The matched character to escape.
  17317. * @returns {string} Returns the escaped character.
  17318. */
  17319. function escapeHtmlChar(chr) {
  17320. return htmlEscapes[chr];
  17321. }
  17322. /**
  17323. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  17324. *
  17325. * @private
  17326. * @param {string} chr The matched character to escape.
  17327. * @returns {string} Returns the escaped character.
  17328. */
  17329. function escapeStringChar(chr) {
  17330. return '\\' + stringEscapes[chr];
  17331. }
  17332. /**
  17333. * Gets the value at `key` of `object`.
  17334. *
  17335. * @private
  17336. * @param {Object} [object] The object to query.
  17337. * @param {string} key The key of the property to get.
  17338. * @returns {*} Returns the property value.
  17339. */
  17340. function getValue(object, key) {
  17341. return object == null ? undefined : object[key];
  17342. }
  17343. /**
  17344. * Gets the index at which the first occurrence of `NaN` is found in `array`.
  17345. *
  17346. * @private
  17347. * @param {Array} array The array to search.
  17348. * @param {number} fromIndex The index to search from.
  17349. * @param {boolean} [fromRight] Specify iterating from right to left.
  17350. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
  17351. */
  17352. function indexOfNaN(array, fromIndex, fromRight) {
  17353. var length = array.length,
  17354. index = fromIndex + (fromRight ? 1 : -1);
  17355. while ((fromRight ? index-- : ++index < length)) {
  17356. var other = array[index];
  17357. if (other !== other) {
  17358. return index;
  17359. }
  17360. }
  17361. return -1;
  17362. }
  17363. /**
  17364. * Checks if `value` is a host object in IE < 9.
  17365. *
  17366. * @private
  17367. * @param {*} value The value to check.
  17368. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  17369. */
  17370. function isHostObject(value) {
  17371. // Many host objects are `Object` objects that can coerce to strings
  17372. // despite having improperly defined `toString` methods.
  17373. var result = false;
  17374. if (value != null && typeof value.toString != 'function') {
  17375. try {
  17376. result = !!(value + '');
  17377. } catch (e) {}
  17378. }
  17379. return result;
  17380. }
  17381. /**
  17382. * Converts `iterator` to an array.
  17383. *
  17384. * @private
  17385. * @param {Object} iterator The iterator to convert.
  17386. * @returns {Array} Returns the converted array.
  17387. */
  17388. function iteratorToArray(iterator) {
  17389. var data,
  17390. result = [];
  17391. while (!(data = iterator.next()).done) {
  17392. result.push(data.value);
  17393. }
  17394. return result;
  17395. }
  17396. /**
  17397. * Converts `map` to its key-value pairs.
  17398. *
  17399. * @private
  17400. * @param {Object} map The map to convert.
  17401. * @returns {Array} Returns the key-value pairs.
  17402. */
  17403. function mapToArray(map) {
  17404. var index = -1,
  17405. result = Array(map.size);
  17406. map.forEach(function(value, key) {
  17407. result[++index] = [key, value];
  17408. });
  17409. return result;
  17410. }
  17411. /**
  17412. * Replaces all `placeholder` elements in `array` with an internal placeholder
  17413. * and returns an array of their indexes.
  17414. *
  17415. * @private
  17416. * @param {Array} array The array to modify.
  17417. * @param {*} placeholder The placeholder to replace.
  17418. * @returns {Array} Returns the new array of placeholder indexes.
  17419. */
  17420. function replaceHolders(array, placeholder) {
  17421. var index = -1,
  17422. length = array.length,
  17423. resIndex = 0,
  17424. result = [];
  17425. while (++index < length) {
  17426. var value = array[index];
  17427. if (value === placeholder || value === PLACEHOLDER) {
  17428. array[index] = PLACEHOLDER;
  17429. result[resIndex++] = index;
  17430. }
  17431. }
  17432. return result;
  17433. }
  17434. /**
  17435. * Converts `set` to an array of its values.
  17436. *
  17437. * @private
  17438. * @param {Object} set The set to convert.
  17439. * @returns {Array} Returns the values.
  17440. */
  17441. function setToArray(set) {
  17442. var index = -1,
  17443. result = Array(set.size);
  17444. set.forEach(function(value) {
  17445. result[++index] = value;
  17446. });
  17447. return result;
  17448. }
  17449. /**
  17450. * Converts `set` to its value-value pairs.
  17451. *
  17452. * @private
  17453. * @param {Object} set The set to convert.
  17454. * @returns {Array} Returns the value-value pairs.
  17455. */
  17456. function setToPairs(set) {
  17457. var index = -1,
  17458. result = Array(set.size);
  17459. set.forEach(function(value) {
  17460. result[++index] = [value, value];
  17461. });
  17462. return result;
  17463. }
  17464. /**
  17465. * Gets the number of symbols in `string`.
  17466. *
  17467. * @private
  17468. * @param {string} string The string to inspect.
  17469. * @returns {number} Returns the string size.
  17470. */
  17471. function stringSize(string) {
  17472. if (!(string && reHasComplexSymbol.test(string))) {
  17473. return string.length;
  17474. }
  17475. var result = reComplexSymbol.lastIndex = 0;
  17476. while (reComplexSymbol.test(string)) {
  17477. result++;
  17478. }
  17479. return result;
  17480. }
  17481. /**
  17482. * Converts `string` to an array.
  17483. *
  17484. * @private
  17485. * @param {string} string The string to convert.
  17486. * @returns {Array} Returns the converted array.
  17487. */
  17488. function stringToArray(string) {
  17489. return string.match(reComplexSymbol);
  17490. }
  17491. /**
  17492. * Used by `_.unescape` to convert HTML entities to characters.
  17493. *
  17494. * @private
  17495. * @param {string} chr The matched character to unescape.
  17496. * @returns {string} Returns the unescaped character.
  17497. */
  17498. function unescapeHtmlChar(chr) {
  17499. return htmlUnescapes[chr];
  17500. }
  17501. /*--------------------------------------------------------------------------*/
  17502. /**
  17503. * Create a new pristine `lodash` function using the `context` object.
  17504. *
  17505. * @static
  17506. * @memberOf _
  17507. * @since 1.1.0
  17508. * @category Util
  17509. * @param {Object} [context=root] The context object.
  17510. * @returns {Function} Returns a new `lodash` function.
  17511. * @example
  17512. *
  17513. * _.mixin({ 'foo': _.constant('foo') });
  17514. *
  17515. * var lodash = _.runInContext();
  17516. * lodash.mixin({ 'bar': lodash.constant('bar') });
  17517. *
  17518. * _.isFunction(_.foo);
  17519. * // => true
  17520. * _.isFunction(_.bar);
  17521. * // => false
  17522. *
  17523. * lodash.isFunction(lodash.foo);
  17524. * // => false
  17525. * lodash.isFunction(lodash.bar);
  17526. * // => true
  17527. *
  17528. * // Use `context` to stub `Date#getTime` use in `_.now`.
  17529. * var stubbed = _.runInContext({
  17530. * 'Date': function() {
  17531. * return { 'getTime': stubGetTime };
  17532. * }
  17533. * });
  17534. *
  17535. * // Create a suped-up `defer` in Node.js.
  17536. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  17537. */
  17538. function runInContext(context) {
  17539. context = context ? _.defaults({}, context, _.pick(root, contextProps)) : root;
  17540. /** Built-in constructor references. */
  17541. var Date = context.Date,
  17542. Error = context.Error,
  17543. Math = context.Math,
  17544. RegExp = context.RegExp,
  17545. TypeError = context.TypeError;
  17546. /** Used for built-in method references. */
  17547. var arrayProto = context.Array.prototype,
  17548. objectProto = context.Object.prototype,
  17549. stringProto = context.String.prototype;
  17550. /** Used to detect overreaching core-js shims. */
  17551. var coreJsData = context['__core-js_shared__'];
  17552. /** Used to detect methods masquerading as native. */
  17553. var maskSrcKey = (function() {
  17554. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  17555. return uid ? ('Symbol(src)_1.' + uid) : '';
  17556. }());
  17557. /** Used to resolve the decompiled source of functions. */
  17558. var funcToString = context.Function.prototype.toString;
  17559. /** Used to check objects for own properties. */
  17560. var hasOwnProperty = objectProto.hasOwnProperty;
  17561. /** Used to generate unique IDs. */
  17562. var idCounter = 0;
  17563. /** Used to infer the `Object` constructor. */
  17564. var objectCtorString = funcToString.call(Object);
  17565. /**
  17566. * Used to resolve the
  17567. * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  17568. * of values.
  17569. */
  17570. var objectToString = objectProto.toString;
  17571. /** Used to restore the original `_` reference in `_.noConflict`. */
  17572. var oldDash = root._;
  17573. /** Used to detect if a method is native. */
  17574. var reIsNative = RegExp('^' +
  17575. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  17576. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  17577. );
  17578. /** Built-in value references. */
  17579. var Buffer = moduleExports ? context.Buffer : undefined,
  17580. Reflect = context.Reflect,
  17581. Symbol = context.Symbol,
  17582. Uint8Array = context.Uint8Array,
  17583. enumerate = Reflect ? Reflect.enumerate : undefined,
  17584. getOwnPropertySymbols = Object.getOwnPropertySymbols,
  17585. iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined,
  17586. objectCreate = Object.create,
  17587. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  17588. splice = arrayProto.splice;
  17589. /** Built-in method references that are mockable. */
  17590. var setTimeout = function(func, wait) { return context.setTimeout.call(root, func, wait); };
  17591. /* Built-in method references for those with the same name as other `lodash` methods. */
  17592. var nativeCeil = Math.ceil,
  17593. nativeFloor = Math.floor,
  17594. nativeGetPrototype = Object.getPrototypeOf,
  17595. nativeIsFinite = context.isFinite,
  17596. nativeJoin = arrayProto.join,
  17597. nativeKeys = Object.keys,
  17598. nativeMax = Math.max,
  17599. nativeMin = Math.min,
  17600. nativeParseInt = context.parseInt,
  17601. nativeRandom = Math.random,
  17602. nativeReplace = stringProto.replace,
  17603. nativeReverse = arrayProto.reverse,
  17604. nativeSplit = stringProto.split;
  17605. /* Built-in method references that are verified to be native. */
  17606. var DataView = getNative(context, 'DataView'),
  17607. Map = getNative(context, 'Map'),
  17608. Promise = getNative(context, 'Promise'),
  17609. Set = getNative(context, 'Set'),
  17610. WeakMap = getNative(context, 'WeakMap'),
  17611. nativeCreate = getNative(Object, 'create');
  17612. /** Used to store function metadata. */
  17613. var metaMap = WeakMap && new WeakMap;
  17614. /** Detect if properties shadowing those on `Object.prototype` are non-enumerable. */
  17615. var nonEnumShadows = !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf');
  17616. /** Used to lookup unminified function names. */
  17617. var realNames = {};
  17618. /** Used to detect maps, sets, and weakmaps. */
  17619. var dataViewCtorString = toSource(DataView),
  17620. mapCtorString = toSource(Map),
  17621. promiseCtorString = toSource(Promise),
  17622. setCtorString = toSource(Set),
  17623. weakMapCtorString = toSource(WeakMap);
  17624. /** Used to convert symbols to primitives and strings. */
  17625. var symbolProto = Symbol ? Symbol.prototype : undefined,
  17626. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  17627. symbolToString = symbolProto ? symbolProto.toString : undefined;
  17628. /*------------------------------------------------------------------------*/
  17629. /**
  17630. * Creates a `lodash` object which wraps `value` to enable implicit method
  17631. * chain sequences. Methods that operate on and return arrays, collections,
  17632. * and functions can be chained together. Methods that retrieve a single value
  17633. * or may return a primitive value will automatically end the chain sequence
  17634. * and return the unwrapped value. Otherwise, the value must be unwrapped
  17635. * with `_#value`.
  17636. *
  17637. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  17638. * enabled using `_.chain`.
  17639. *
  17640. * The execution of chained methods is lazy, that is, it's deferred until
  17641. * `_#value` is implicitly or explicitly called.
  17642. *
  17643. * Lazy evaluation allows several methods to support shortcut fusion.
  17644. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  17645. * the creation of intermediate arrays and can greatly reduce the number of
  17646. * iteratee executions. Sections of a chain sequence qualify for shortcut
  17647. * fusion if the section is applied to an array of at least `200` elements
  17648. * and any iteratees accept only one argument. The heuristic for whether a
  17649. * section qualifies for shortcut fusion is subject to change.
  17650. *
  17651. * Chaining is supported in custom builds as long as the `_#value` method is
  17652. * directly or indirectly included in the build.
  17653. *
  17654. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  17655. *
  17656. * The wrapper `Array` methods are:
  17657. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  17658. *
  17659. * The wrapper `String` methods are:
  17660. * `replace` and `split`
  17661. *
  17662. * The wrapper methods that support shortcut fusion are:
  17663. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  17664. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  17665. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  17666. *
  17667. * The chainable wrapper methods are:
  17668. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  17669. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  17670. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  17671. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  17672. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  17673. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  17674. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  17675. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  17676. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  17677. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  17678. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  17679. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  17680. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  17681. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  17682. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  17683. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  17684. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  17685. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  17686. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  17687. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  17688. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  17689. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  17690. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  17691. * `zipObject`, `zipObjectDeep`, and `zipWith`
  17692. *
  17693. * The wrapper methods that are **not** chainable by default are:
  17694. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  17695. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `divide`, `each`,
  17696. * `eachRight`, `endsWith`, `eq`, `escape`, `escapeRegExp`, `every`, `find`,
  17697. * `findIndex`, `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `first`,
  17698. * `floor`, `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`,
  17699. * `forOwnRight`, `get`, `gt`, `gte`, `has`, `hasIn`, `head`, `identity`,
  17700. * `includes`, `indexOf`, `inRange`, `invoke`, `isArguments`, `isArray`,
  17701. * `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`,
  17702. * `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`,
  17703. * `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMap`,
  17704. * `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  17705. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  17706. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  17707. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  17708. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  17709. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  17710. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  17711. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  17712. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  17713. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  17714. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  17715. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  17716. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  17717. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  17718. * `upperFirst`, `value`, and `words`
  17719. *
  17720. * @name _
  17721. * @constructor
  17722. * @category Seq
  17723. * @param {*} value The value to wrap in a `lodash` instance.
  17724. * @returns {Object} Returns the new `lodash` wrapper instance.
  17725. * @example
  17726. *
  17727. * function square(n) {
  17728. * return n * n;
  17729. * }
  17730. *
  17731. * var wrapped = _([1, 2, 3]);
  17732. *
  17733. * // Returns an unwrapped value.
  17734. * wrapped.reduce(_.add);
  17735. * // => 6
  17736. *
  17737. * // Returns a wrapped value.
  17738. * var squares = wrapped.map(square);
  17739. *
  17740. * _.isArray(squares);
  17741. * // => false
  17742. *
  17743. * _.isArray(squares.value());
  17744. * // => true
  17745. */
  17746. function lodash(value) {
  17747. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  17748. if (value instanceof LodashWrapper) {
  17749. return value;
  17750. }
  17751. if (hasOwnProperty.call(value, '__wrapped__')) {
  17752. return wrapperClone(value);
  17753. }
  17754. }
  17755. return new LodashWrapper(value);
  17756. }
  17757. /**
  17758. * The function whose prototype chain sequence wrappers inherit from.
  17759. *
  17760. * @private
  17761. */
  17762. function baseLodash() {
  17763. // No operation performed.
  17764. }
  17765. /**
  17766. * The base constructor for creating `lodash` wrapper objects.
  17767. *
  17768. * @private
  17769. * @param {*} value The value to wrap.
  17770. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  17771. */
  17772. function LodashWrapper(value, chainAll) {
  17773. this.__wrapped__ = value;
  17774. this.__actions__ = [];
  17775. this.__chain__ = !!chainAll;
  17776. this.__index__ = 0;
  17777. this.__values__ = undefined;
  17778. }
  17779. /**
  17780. * By default, the template delimiters used by lodash are like those in
  17781. * embedded Ruby (ERB). Change the following template settings to use
  17782. * alternative delimiters.
  17783. *
  17784. * @static
  17785. * @memberOf _
  17786. * @type {Object}
  17787. */
  17788. lodash.templateSettings = {
  17789. /**
  17790. * Used to detect `data` property values to be HTML-escaped.
  17791. *
  17792. * @memberOf _.templateSettings
  17793. * @type {RegExp}
  17794. */
  17795. 'escape': reEscape,
  17796. /**
  17797. * Used to detect code to be evaluated.
  17798. *
  17799. * @memberOf _.templateSettings
  17800. * @type {RegExp}
  17801. */
  17802. 'evaluate': reEvaluate,
  17803. /**
  17804. * Used to detect `data` property values to inject.
  17805. *
  17806. * @memberOf _.templateSettings
  17807. * @type {RegExp}
  17808. */
  17809. 'interpolate': reInterpolate,
  17810. /**
  17811. * Used to reference the data object in the template text.
  17812. *
  17813. * @memberOf _.templateSettings
  17814. * @type {string}
  17815. */
  17816. 'variable': '',
  17817. /**
  17818. * Used to import variables into the compiled template.
  17819. *
  17820. * @memberOf _.templateSettings
  17821. * @type {Object}
  17822. */
  17823. 'imports': {
  17824. /**
  17825. * A reference to the `lodash` function.
  17826. *
  17827. * @memberOf _.templateSettings.imports
  17828. * @type {Function}
  17829. */
  17830. '_': lodash
  17831. }
  17832. };
  17833. // Ensure wrappers are instances of `baseLodash`.
  17834. lodash.prototype = baseLodash.prototype;
  17835. lodash.prototype.constructor = lodash;
  17836. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  17837. LodashWrapper.prototype.constructor = LodashWrapper;
  17838. /*------------------------------------------------------------------------*/
  17839. /**
  17840. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  17841. *
  17842. * @private
  17843. * @constructor
  17844. * @param {*} value The value to wrap.
  17845. */
  17846. function LazyWrapper(value) {
  17847. this.__wrapped__ = value;
  17848. this.__actions__ = [];
  17849. this.__dir__ = 1;
  17850. this.__filtered__ = false;
  17851. this.__iteratees__ = [];
  17852. this.__takeCount__ = MAX_ARRAY_LENGTH;
  17853. this.__views__ = [];
  17854. }
  17855. /**
  17856. * Creates a clone of the lazy wrapper object.
  17857. *
  17858. * @private
  17859. * @name clone
  17860. * @memberOf LazyWrapper
  17861. * @returns {Object} Returns the cloned `LazyWrapper` object.
  17862. */
  17863. function lazyClone() {
  17864. var result = new LazyWrapper(this.__wrapped__);
  17865. result.__actions__ = copyArray(this.__actions__);
  17866. result.__dir__ = this.__dir__;
  17867. result.__filtered__ = this.__filtered__;
  17868. result.__iteratees__ = copyArray(this.__iteratees__);
  17869. result.__takeCount__ = this.__takeCount__;
  17870. result.__views__ = copyArray(this.__views__);
  17871. return result;
  17872. }
  17873. /**
  17874. * Reverses the direction of lazy iteration.
  17875. *
  17876. * @private
  17877. * @name reverse
  17878. * @memberOf LazyWrapper
  17879. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  17880. */
  17881. function lazyReverse() {
  17882. if (this.__filtered__) {
  17883. var result = new LazyWrapper(this);
  17884. result.__dir__ = -1;
  17885. result.__filtered__ = true;
  17886. } else {
  17887. result = this.clone();
  17888. result.__dir__ *= -1;
  17889. }
  17890. return result;
  17891. }
  17892. /**
  17893. * Extracts the unwrapped value from its lazy wrapper.
  17894. *
  17895. * @private
  17896. * @name value
  17897. * @memberOf LazyWrapper
  17898. * @returns {*} Returns the unwrapped value.
  17899. */
  17900. function lazyValue() {
  17901. var array = this.__wrapped__.value(),
  17902. dir = this.__dir__,
  17903. isArr = isArray(array),
  17904. isRight = dir < 0,
  17905. arrLength = isArr ? array.length : 0,
  17906. view = getView(0, arrLength, this.__views__),
  17907. start = view.start,
  17908. end = view.end,
  17909. length = end - start,
  17910. index = isRight ? end : (start - 1),
  17911. iteratees = this.__iteratees__,
  17912. iterLength = iteratees.length,
  17913. resIndex = 0,
  17914. takeCount = nativeMin(length, this.__takeCount__);
  17915. if (!isArr || arrLength < LARGE_ARRAY_SIZE ||
  17916. (arrLength == length && takeCount == length)) {
  17917. return baseWrapperValue(array, this.__actions__);
  17918. }
  17919. var result = [];
  17920. outer:
  17921. while (length-- && resIndex < takeCount) {
  17922. index += dir;
  17923. var iterIndex = -1,
  17924. value = array[index];
  17925. while (++iterIndex < iterLength) {
  17926. var data = iteratees[iterIndex],
  17927. iteratee = data.iteratee,
  17928. type = data.type,
  17929. computed = iteratee(value);
  17930. if (type == LAZY_MAP_FLAG) {
  17931. value = computed;
  17932. } else if (!computed) {
  17933. if (type == LAZY_FILTER_FLAG) {
  17934. continue outer;
  17935. } else {
  17936. break outer;
  17937. }
  17938. }
  17939. }
  17940. result[resIndex++] = value;
  17941. }
  17942. return result;
  17943. }
  17944. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  17945. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  17946. LazyWrapper.prototype.constructor = LazyWrapper;
  17947. /*------------------------------------------------------------------------*/
  17948. /**
  17949. * Creates a hash object.
  17950. *
  17951. * @private
  17952. * @constructor
  17953. * @param {Array} [entries] The key-value pairs to cache.
  17954. */
  17955. function Hash(entries) {
  17956. var index = -1,
  17957. length = entries ? entries.length : 0;
  17958. this.clear();
  17959. while (++index < length) {
  17960. var entry = entries[index];
  17961. this.set(entry[0], entry[1]);
  17962. }
  17963. }
  17964. /**
  17965. * Removes all key-value entries from the hash.
  17966. *
  17967. * @private
  17968. * @name clear
  17969. * @memberOf Hash
  17970. */
  17971. function hashClear() {
  17972. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  17973. }
  17974. /**
  17975. * Removes `key` and its value from the hash.
  17976. *
  17977. * @private
  17978. * @name delete
  17979. * @memberOf Hash
  17980. * @param {Object} hash The hash to modify.
  17981. * @param {string} key The key of the value to remove.
  17982. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  17983. */
  17984. function hashDelete(key) {
  17985. return this.has(key) && delete this.__data__[key];
  17986. }
  17987. /**
  17988. * Gets the hash value for `key`.
  17989. *
  17990. * @private
  17991. * @name get
  17992. * @memberOf Hash
  17993. * @param {string} key The key of the value to get.
  17994. * @returns {*} Returns the entry value.
  17995. */
  17996. function hashGet(key) {
  17997. var data = this.__data__;
  17998. if (nativeCreate) {
  17999. var result = data[key];
  18000. return result === HASH_UNDEFINED ? undefined : result;
  18001. }
  18002. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  18003. }
  18004. /**
  18005. * Checks if a hash value for `key` exists.
  18006. *
  18007. * @private
  18008. * @name has
  18009. * @memberOf Hash
  18010. * @param {string} key The key of the entry to check.
  18011. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  18012. */
  18013. function hashHas(key) {
  18014. var data = this.__data__;
  18015. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  18016. }
  18017. /**
  18018. * Sets the hash `key` to `value`.
  18019. *
  18020. * @private
  18021. * @name set
  18022. * @memberOf Hash
  18023. * @param {string} key The key of the value to set.
  18024. * @param {*} value The value to set.
  18025. * @returns {Object} Returns the hash instance.
  18026. */
  18027. function hashSet(key, value) {
  18028. var data = this.__data__;
  18029. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  18030. return this;
  18031. }
  18032. // Add methods to `Hash`.
  18033. Hash.prototype.clear = hashClear;
  18034. Hash.prototype['delete'] = hashDelete;
  18035. Hash.prototype.get = hashGet;
  18036. Hash.prototype.has = hashHas;
  18037. Hash.prototype.set = hashSet;
  18038. /*------------------------------------------------------------------------*/
  18039. /**
  18040. * Creates an list cache object.
  18041. *
  18042. * @private
  18043. * @constructor
  18044. * @param {Array} [entries] The key-value pairs to cache.
  18045. */
  18046. function ListCache(entries) {
  18047. var index = -1,
  18048. length = entries ? entries.length : 0;
  18049. this.clear();
  18050. while (++index < length) {
  18051. var entry = entries[index];
  18052. this.set(entry[0], entry[1]);
  18053. }
  18054. }
  18055. /**
  18056. * Removes all key-value entries from the list cache.
  18057. *
  18058. * @private
  18059. * @name clear
  18060. * @memberOf ListCache
  18061. */
  18062. function listCacheClear() {
  18063. this.__data__ = [];
  18064. }
  18065. /**
  18066. * Removes `key` and its value from the list cache.
  18067. *
  18068. * @private
  18069. * @name delete
  18070. * @memberOf ListCache
  18071. * @param {string} key The key of the value to remove.
  18072. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  18073. */
  18074. function listCacheDelete(key) {
  18075. var data = this.__data__,
  18076. index = assocIndexOf(data, key);
  18077. if (index < 0) {
  18078. return false;
  18079. }
  18080. var lastIndex = data.length - 1;
  18081. if (index == lastIndex) {
  18082. data.pop();
  18083. } else {
  18084. splice.call(data, index, 1);
  18085. }
  18086. return true;
  18087. }
  18088. /**
  18089. * Gets the list cache value for `key`.
  18090. *
  18091. * @private
  18092. * @name get
  18093. * @memberOf ListCache
  18094. * @param {string} key The key of the value to get.
  18095. * @returns {*} Returns the entry value.
  18096. */
  18097. function listCacheGet(key) {
  18098. var data = this.__data__,
  18099. index = assocIndexOf(data, key);
  18100. return index < 0 ? undefined : data[index][1];
  18101. }
  18102. /**
  18103. * Checks if a list cache value for `key` exists.
  18104. *
  18105. * @private
  18106. * @name has
  18107. * @memberOf ListCache
  18108. * @param {string} key The key of the entry to check.
  18109. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  18110. */
  18111. function listCacheHas(key) {
  18112. return assocIndexOf(this.__data__, key) > -1;
  18113. }
  18114. /**
  18115. * Sets the list cache `key` to `value`.
  18116. *
  18117. * @private
  18118. * @name set
  18119. * @memberOf ListCache
  18120. * @param {string} key The key of the value to set.
  18121. * @param {*} value The value to set.
  18122. * @returns {Object} Returns the list cache instance.
  18123. */
  18124. function listCacheSet(key, value) {
  18125. var data = this.__data__,
  18126. index = assocIndexOf(data, key);
  18127. if (index < 0) {
  18128. data.push([key, value]);
  18129. } else {
  18130. data[index][1] = value;
  18131. }
  18132. return this;
  18133. }
  18134. // Add methods to `ListCache`.
  18135. ListCache.prototype.clear = listCacheClear;
  18136. ListCache.prototype['delete'] = listCacheDelete;
  18137. ListCache.prototype.get = listCacheGet;
  18138. ListCache.prototype.has = listCacheHas;
  18139. ListCache.prototype.set = listCacheSet;
  18140. /*------------------------------------------------------------------------*/
  18141. /**
  18142. * Creates a map cache object to store key-value pairs.
  18143. *
  18144. * @private
  18145. * @constructor
  18146. * @param {Array} [entries] The key-value pairs to cache.
  18147. */
  18148. function MapCache(entries) {
  18149. var index = -1,
  18150. length = entries ? entries.length : 0;
  18151. this.clear();
  18152. while (++index < length) {
  18153. var entry = entries[index];
  18154. this.set(entry[0], entry[1]);
  18155. }
  18156. }
  18157. /**
  18158. * Removes all key-value entries from the map.
  18159. *
  18160. * @private
  18161. * @name clear
  18162. * @memberOf MapCache
  18163. */
  18164. function mapCacheClear() {
  18165. this.__data__ = {
  18166. 'hash': new Hash,
  18167. 'map': new (Map || ListCache),
  18168. 'string': new Hash
  18169. };
  18170. }
  18171. /**
  18172. * Removes `key` and its value from the map.
  18173. *
  18174. * @private
  18175. * @name delete
  18176. * @memberOf MapCache
  18177. * @param {string} key The key of the value to remove.
  18178. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  18179. */
  18180. function mapCacheDelete(key) {
  18181. return getMapData(this, key)['delete'](key);
  18182. }
  18183. /**
  18184. * Gets the map value for `key`.
  18185. *
  18186. * @private
  18187. * @name get
  18188. * @memberOf MapCache
  18189. * @param {string} key The key of the value to get.
  18190. * @returns {*} Returns the entry value.
  18191. */
  18192. function mapCacheGet(key) {
  18193. return getMapData(this, key).get(key);
  18194. }
  18195. /**
  18196. * Checks if a map value for `key` exists.
  18197. *
  18198. * @private
  18199. * @name has
  18200. * @memberOf MapCache
  18201. * @param {string} key The key of the entry to check.
  18202. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  18203. */
  18204. function mapCacheHas(key) {
  18205. return getMapData(this, key).has(key);
  18206. }
  18207. /**
  18208. * Sets the map `key` to `value`.
  18209. *
  18210. * @private
  18211. * @name set
  18212. * @memberOf MapCache
  18213. * @param {string} key The key of the value to set.
  18214. * @param {*} value The value to set.
  18215. * @returns {Object} Returns the map cache instance.
  18216. */
  18217. function mapCacheSet(key, value) {
  18218. getMapData(this, key).set(key, value);
  18219. return this;
  18220. }
  18221. // Add methods to `MapCache`.
  18222. MapCache.prototype.clear = mapCacheClear;
  18223. MapCache.prototype['delete'] = mapCacheDelete;
  18224. MapCache.prototype.get = mapCacheGet;
  18225. MapCache.prototype.has = mapCacheHas;
  18226. MapCache.prototype.set = mapCacheSet;
  18227. /*------------------------------------------------------------------------*/
  18228. /**
  18229. *
  18230. * Creates an array cache object to store unique values.
  18231. *
  18232. * @private
  18233. * @constructor
  18234. * @param {Array} [values] The values to cache.
  18235. */
  18236. function SetCache(values) {
  18237. var index = -1,
  18238. length = values ? values.length : 0;
  18239. this.__data__ = new MapCache;
  18240. while (++index < length) {
  18241. this.add(values[index]);
  18242. }
  18243. }
  18244. /**
  18245. * Adds `value` to the array cache.
  18246. *
  18247. * @private
  18248. * @name add
  18249. * @memberOf SetCache
  18250. * @alias push
  18251. * @param {*} value The value to cache.
  18252. * @returns {Object} Returns the cache instance.
  18253. */
  18254. function setCacheAdd(value) {
  18255. this.__data__.set(value, HASH_UNDEFINED);
  18256. return this;
  18257. }
  18258. /**
  18259. * Checks if `value` is in the array cache.
  18260. *
  18261. * @private
  18262. * @name has
  18263. * @memberOf SetCache
  18264. * @param {*} value The value to search for.
  18265. * @returns {number} Returns `true` if `value` is found, else `false`.
  18266. */
  18267. function setCacheHas(value) {
  18268. return this.__data__.has(value);
  18269. }
  18270. // Add methods to `SetCache`.
  18271. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  18272. SetCache.prototype.has = setCacheHas;
  18273. /*------------------------------------------------------------------------*/
  18274. /**
  18275. * Creates a stack cache object to store key-value pairs.
  18276. *
  18277. * @private
  18278. * @constructor
  18279. * @param {Array} [entries] The key-value pairs to cache.
  18280. */
  18281. function Stack(entries) {
  18282. this.__data__ = new ListCache(entries);
  18283. }
  18284. /**
  18285. * Removes all key-value entries from the stack.
  18286. *
  18287. * @private
  18288. * @name clear
  18289. * @memberOf Stack
  18290. */
  18291. function stackClear() {
  18292. this.__data__ = new ListCache;
  18293. }
  18294. /**
  18295. * Removes `key` and its value from the stack.
  18296. *
  18297. * @private
  18298. * @name delete
  18299. * @memberOf Stack
  18300. * @param {string} key The key of the value to remove.
  18301. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  18302. */
  18303. function stackDelete(key) {
  18304. return this.__data__['delete'](key);
  18305. }
  18306. /**
  18307. * Gets the stack value for `key`.
  18308. *
  18309. * @private
  18310. * @name get
  18311. * @memberOf Stack
  18312. * @param {string} key The key of the value to get.
  18313. * @returns {*} Returns the entry value.
  18314. */
  18315. function stackGet(key) {
  18316. return this.__data__.get(key);
  18317. }
  18318. /**
  18319. * Checks if a stack value for `key` exists.
  18320. *
  18321. * @private
  18322. * @name has
  18323. * @memberOf Stack
  18324. * @param {string} key The key of the entry to check.
  18325. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  18326. */
  18327. function stackHas(key) {
  18328. return this.__data__.has(key);
  18329. }
  18330. /**
  18331. * Sets the stack `key` to `value`.
  18332. *
  18333. * @private
  18334. * @name set
  18335. * @memberOf Stack
  18336. * @param {string} key The key of the value to set.
  18337. * @param {*} value The value to set.
  18338. * @returns {Object} Returns the stack cache instance.
  18339. */
  18340. function stackSet(key, value) {
  18341. var cache = this.__data__;
  18342. if (cache instanceof ListCache && cache.__data__.length == LARGE_ARRAY_SIZE) {
  18343. cache = this.__data__ = new MapCache(cache.__data__);
  18344. }
  18345. cache.set(key, value);
  18346. return this;
  18347. }
  18348. // Add methods to `Stack`.
  18349. Stack.prototype.clear = stackClear;
  18350. Stack.prototype['delete'] = stackDelete;
  18351. Stack.prototype.get = stackGet;
  18352. Stack.prototype.has = stackHas;
  18353. Stack.prototype.set = stackSet;
  18354. /*------------------------------------------------------------------------*/
  18355. /**
  18356. * Used by `_.defaults` to customize its `_.assignIn` use.
  18357. *
  18358. * @private
  18359. * @param {*} objValue The destination value.
  18360. * @param {*} srcValue The source value.
  18361. * @param {string} key The key of the property to assign.
  18362. * @param {Object} object The parent object of `objValue`.
  18363. * @returns {*} Returns the value to assign.
  18364. */
  18365. function assignInDefaults(objValue, srcValue, key, object) {
  18366. if (objValue === undefined ||
  18367. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  18368. return srcValue;
  18369. }
  18370. return objValue;
  18371. }
  18372. /**
  18373. * This function is like `assignValue` except that it doesn't assign
  18374. * `undefined` values.
  18375. *
  18376. * @private
  18377. * @param {Object} object The object to modify.
  18378. * @param {string} key The key of the property to assign.
  18379. * @param {*} value The value to assign.
  18380. */
  18381. function assignMergeValue(object, key, value) {
  18382. if ((value !== undefined && !eq(object[key], value)) ||
  18383. (typeof key == 'number' && value === undefined && !(key in object))) {
  18384. object[key] = value;
  18385. }
  18386. }
  18387. /**
  18388. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  18389. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  18390. * for equality comparisons.
  18391. *
  18392. * @private
  18393. * @param {Object} object The object to modify.
  18394. * @param {string} key The key of the property to assign.
  18395. * @param {*} value The value to assign.
  18396. */
  18397. function assignValue(object, key, value) {
  18398. var objValue = object[key];
  18399. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  18400. (value === undefined && !(key in object))) {
  18401. object[key] = value;
  18402. }
  18403. }
  18404. /**
  18405. * Gets the index at which the `key` is found in `array` of key-value pairs.
  18406. *
  18407. * @private
  18408. * @param {Array} array The array to search.
  18409. * @param {*} key The key to search for.
  18410. * @returns {number} Returns the index of the matched value, else `-1`.
  18411. */
  18412. function assocIndexOf(array, key) {
  18413. var length = array.length;
  18414. while (length--) {
  18415. if (eq(array[length][0], key)) {
  18416. return length;
  18417. }
  18418. }
  18419. return -1;
  18420. }
  18421. /**
  18422. * Aggregates elements of `collection` on `accumulator` with keys transformed
  18423. * by `iteratee` and values set by `setter`.
  18424. *
  18425. * @private
  18426. * @param {Array|Object} collection The collection to iterate over.
  18427. * @param {Function} setter The function to set `accumulator` values.
  18428. * @param {Function} iteratee The iteratee to transform keys.
  18429. * @param {Object} accumulator The initial aggregated object.
  18430. * @returns {Function} Returns `accumulator`.
  18431. */
  18432. function baseAggregator(collection, setter, iteratee, accumulator) {
  18433. baseEach(collection, function(value, key, collection) {
  18434. setter(accumulator, value, iteratee(value), collection);
  18435. });
  18436. return accumulator;
  18437. }
  18438. /**
  18439. * The base implementation of `_.assign` without support for multiple sources
  18440. * or `customizer` functions.
  18441. *
  18442. * @private
  18443. * @param {Object} object The destination object.
  18444. * @param {Object} source The source object.
  18445. * @returns {Object} Returns `object`.
  18446. */
  18447. function baseAssign(object, source) {
  18448. return object && copyObject(source, keys(source), object);
  18449. }
  18450. /**
  18451. * The base implementation of `_.at` without support for individual paths.
  18452. *
  18453. * @private
  18454. * @param {Object} object The object to iterate over.
  18455. * @param {string[]} paths The property paths of elements to pick.
  18456. * @returns {Array} Returns the picked elements.
  18457. */
  18458. function baseAt(object, paths) {
  18459. var index = -1,
  18460. isNil = object == null,
  18461. length = paths.length,
  18462. result = Array(length);
  18463. while (++index < length) {
  18464. result[index] = isNil ? undefined : get(object, paths[index]);
  18465. }
  18466. return result;
  18467. }
  18468. /**
  18469. * The base implementation of `_.clamp` which doesn't coerce arguments to numbers.
  18470. *
  18471. * @private
  18472. * @param {number} number The number to clamp.
  18473. * @param {number} [lower] The lower bound.
  18474. * @param {number} upper The upper bound.
  18475. * @returns {number} Returns the clamped number.
  18476. */
  18477. function baseClamp(number, lower, upper) {
  18478. if (number === number) {
  18479. if (upper !== undefined) {
  18480. number = number <= upper ? number : upper;
  18481. }
  18482. if (lower !== undefined) {
  18483. number = number >= lower ? number : lower;
  18484. }
  18485. }
  18486. return number;
  18487. }
  18488. /**
  18489. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  18490. * traversed objects.
  18491. *
  18492. * @private
  18493. * @param {*} value The value to clone.
  18494. * @param {boolean} [isDeep] Specify a deep clone.
  18495. * @param {boolean} [isFull] Specify a clone including symbols.
  18496. * @param {Function} [customizer] The function to customize cloning.
  18497. * @param {string} [key] The key of `value`.
  18498. * @param {Object} [object] The parent object of `value`.
  18499. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  18500. * @returns {*} Returns the cloned value.
  18501. */
  18502. function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
  18503. var result;
  18504. if (customizer) {
  18505. result = object ? customizer(value, key, object, stack) : customizer(value);
  18506. }
  18507. if (result !== undefined) {
  18508. return result;
  18509. }
  18510. if (!isObject(value)) {
  18511. return value;
  18512. }
  18513. var isArr = isArray(value);
  18514. if (isArr) {
  18515. result = initCloneArray(value);
  18516. if (!isDeep) {
  18517. return copyArray(value, result);
  18518. }
  18519. } else {
  18520. var tag = getTag(value),
  18521. isFunc = tag == funcTag || tag == genTag;
  18522. if (isBuffer(value)) {
  18523. return cloneBuffer(value, isDeep);
  18524. }
  18525. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  18526. if (isHostObject(value)) {
  18527. return object ? value : {};
  18528. }
  18529. result = initCloneObject(isFunc ? {} : value);
  18530. if (!isDeep) {
  18531. return copySymbols(value, baseAssign(result, value));
  18532. }
  18533. } else {
  18534. if (!cloneableTags[tag]) {
  18535. return object ? value : {};
  18536. }
  18537. result = initCloneByTag(value, tag, baseClone, isDeep);
  18538. }
  18539. }
  18540. // Check for circular references and return its corresponding clone.
  18541. stack || (stack = new Stack);
  18542. var stacked = stack.get(value);
  18543. if (stacked) {
  18544. return stacked;
  18545. }
  18546. stack.set(value, result);
  18547. if (!isArr) {
  18548. var props = isFull ? getAllKeys(value) : keys(value);
  18549. }
  18550. // Recursively populate clone (susceptible to call stack limits).
  18551. arrayEach(props || value, function(subValue, key) {
  18552. if (props) {
  18553. key = subValue;
  18554. subValue = value[key];
  18555. }
  18556. assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
  18557. });
  18558. return result;
  18559. }
  18560. /**
  18561. * The base implementation of `_.conforms` which doesn't clone `source`.
  18562. *
  18563. * @private
  18564. * @param {Object} source The object of property predicates to conform to.
  18565. * @returns {Function} Returns the new spec function.
  18566. */
  18567. function baseConforms(source) {
  18568. var props = keys(source),
  18569. length = props.length;
  18570. return function(object) {
  18571. if (object == null) {
  18572. return !length;
  18573. }
  18574. var index = length;
  18575. while (index--) {
  18576. var key = props[index],
  18577. predicate = source[key],
  18578. value = object[key];
  18579. if ((value === undefined &&
  18580. !(key in Object(object))) || !predicate(value)) {
  18581. return false;
  18582. }
  18583. }
  18584. return true;
  18585. };
  18586. }
  18587. /**
  18588. * The base implementation of `_.create` without support for assigning
  18589. * properties to the created object.
  18590. *
  18591. * @private
  18592. * @param {Object} prototype The object to inherit from.
  18593. * @returns {Object} Returns the new object.
  18594. */
  18595. function baseCreate(proto) {
  18596. return isObject(proto) ? objectCreate(proto) : {};
  18597. }
  18598. /**
  18599. * The base implementation of `_.delay` and `_.defer` which accepts an array
  18600. * of `func` arguments.
  18601. *
  18602. * @private
  18603. * @param {Function} func The function to delay.
  18604. * @param {number} wait The number of milliseconds to delay invocation.
  18605. * @param {Object} args The arguments to provide to `func`.
  18606. * @returns {number} Returns the timer id.
  18607. */
  18608. function baseDelay(func, wait, args) {
  18609. if (typeof func != 'function') {
  18610. throw new TypeError(FUNC_ERROR_TEXT);
  18611. }
  18612. return setTimeout(function() { func.apply(undefined, args); }, wait);
  18613. }
  18614. /**
  18615. * The base implementation of methods like `_.difference` without support
  18616. * for excluding multiple arrays or iteratee shorthands.
  18617. *
  18618. * @private
  18619. * @param {Array} array The array to inspect.
  18620. * @param {Array} values The values to exclude.
  18621. * @param {Function} [iteratee] The iteratee invoked per element.
  18622. * @param {Function} [comparator] The comparator invoked per element.
  18623. * @returns {Array} Returns the new array of filtered values.
  18624. */
  18625. function baseDifference(array, values, iteratee, comparator) {
  18626. var index = -1,
  18627. includes = arrayIncludes,
  18628. isCommon = true,
  18629. length = array.length,
  18630. result = [],
  18631. valuesLength = values.length;
  18632. if (!length) {
  18633. return result;
  18634. }
  18635. if (iteratee) {
  18636. values = arrayMap(values, baseUnary(iteratee));
  18637. }
  18638. if (comparator) {
  18639. includes = arrayIncludesWith;
  18640. isCommon = false;
  18641. }
  18642. else if (values.length >= LARGE_ARRAY_SIZE) {
  18643. includes = cacheHas;
  18644. isCommon = false;
  18645. values = new SetCache(values);
  18646. }
  18647. outer:
  18648. while (++index < length) {
  18649. var value = array[index],
  18650. computed = iteratee ? iteratee(value) : value;
  18651. value = (comparator || value !== 0) ? value : 0;
  18652. if (isCommon && computed === computed) {
  18653. var valuesIndex = valuesLength;
  18654. while (valuesIndex--) {
  18655. if (values[valuesIndex] === computed) {
  18656. continue outer;
  18657. }
  18658. }
  18659. result.push(value);
  18660. }
  18661. else if (!includes(values, computed, comparator)) {
  18662. result.push(value);
  18663. }
  18664. }
  18665. return result;
  18666. }
  18667. /**
  18668. * The base implementation of `_.forEach` without support for iteratee shorthands.
  18669. *
  18670. * @private
  18671. * @param {Array|Object} collection The collection to iterate over.
  18672. * @param {Function} iteratee The function invoked per iteration.
  18673. * @returns {Array|Object} Returns `collection`.
  18674. */
  18675. var baseEach = createBaseEach(baseForOwn);
  18676. /**
  18677. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  18678. *
  18679. * @private
  18680. * @param {Array|Object} collection The collection to iterate over.
  18681. * @param {Function} iteratee The function invoked per iteration.
  18682. * @returns {Array|Object} Returns `collection`.
  18683. */
  18684. var baseEachRight = createBaseEach(baseForOwnRight, true);
  18685. /**
  18686. * The base implementation of `_.every` without support for iteratee shorthands.
  18687. *
  18688. * @private
  18689. * @param {Array|Object} collection The collection to iterate over.
  18690. * @param {Function} predicate The function invoked per iteration.
  18691. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  18692. * else `false`
  18693. */
  18694. function baseEvery(collection, predicate) {
  18695. var result = true;
  18696. baseEach(collection, function(value, index, collection) {
  18697. result = !!predicate(value, index, collection);
  18698. return result;
  18699. });
  18700. return result;
  18701. }
  18702. /**
  18703. * The base implementation of methods like `_.max` and `_.min` which accepts a
  18704. * `comparator` to determine the extremum value.
  18705. *
  18706. * @private
  18707. * @param {Array} array The array to iterate over.
  18708. * @param {Function} iteratee The iteratee invoked per iteration.
  18709. * @param {Function} comparator The comparator used to compare values.
  18710. * @returns {*} Returns the extremum value.
  18711. */
  18712. function baseExtremum(array, iteratee, comparator) {
  18713. var index = -1,
  18714. length = array.length;
  18715. while (++index < length) {
  18716. var value = array[index],
  18717. current = iteratee(value);
  18718. if (current != null && (computed === undefined
  18719. ? (current === current && !isSymbol(current))
  18720. : comparator(current, computed)
  18721. )) {
  18722. var computed = current,
  18723. result = value;
  18724. }
  18725. }
  18726. return result;
  18727. }
  18728. /**
  18729. * The base implementation of `_.fill` without an iteratee call guard.
  18730. *
  18731. * @private
  18732. * @param {Array} array The array to fill.
  18733. * @param {*} value The value to fill `array` with.
  18734. * @param {number} [start=0] The start position.
  18735. * @param {number} [end=array.length] The end position.
  18736. * @returns {Array} Returns `array`.
  18737. */
  18738. function baseFill(array, value, start, end) {
  18739. var length = array.length;
  18740. start = toInteger(start);
  18741. if (start < 0) {
  18742. start = -start > length ? 0 : (length + start);
  18743. }
  18744. end = (end === undefined || end > length) ? length : toInteger(end);
  18745. if (end < 0) {
  18746. end += length;
  18747. }
  18748. end = start > end ? 0 : toLength(end);
  18749. while (start < end) {
  18750. array[start++] = value;
  18751. }
  18752. return array;
  18753. }
  18754. /**
  18755. * The base implementation of `_.filter` without support for iteratee shorthands.
  18756. *
  18757. * @private
  18758. * @param {Array|Object} collection The collection to iterate over.
  18759. * @param {Function} predicate The function invoked per iteration.
  18760. * @returns {Array} Returns the new filtered array.
  18761. */
  18762. function baseFilter(collection, predicate) {
  18763. var result = [];
  18764. baseEach(collection, function(value, index, collection) {
  18765. if (predicate(value, index, collection)) {
  18766. result.push(value);
  18767. }
  18768. });
  18769. return result;
  18770. }
  18771. /**
  18772. * The base implementation of `_.flatten` with support for restricting flattening.
  18773. *
  18774. * @private
  18775. * @param {Array} array The array to flatten.
  18776. * @param {number} depth The maximum recursion depth.
  18777. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  18778. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  18779. * @param {Array} [result=[]] The initial result value.
  18780. * @returns {Array} Returns the new flattened array.
  18781. */
  18782. function baseFlatten(array, depth, predicate, isStrict, result) {
  18783. var index = -1,
  18784. length = array.length;
  18785. predicate || (predicate = isFlattenable);
  18786. result || (result = []);
  18787. while (++index < length) {
  18788. var value = array[index];
  18789. if (depth > 0 && predicate(value)) {
  18790. if (depth > 1) {
  18791. // Recursively flatten arrays (susceptible to call stack limits).
  18792. baseFlatten(value, depth - 1, predicate, isStrict, result);
  18793. } else {
  18794. arrayPush(result, value);
  18795. }
  18796. } else if (!isStrict) {
  18797. result[result.length] = value;
  18798. }
  18799. }
  18800. return result;
  18801. }
  18802. /**
  18803. * The base implementation of `baseForOwn` which iterates over `object`
  18804. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  18805. * Iteratee functions may exit iteration early by explicitly returning `false`.
  18806. *
  18807. * @private
  18808. * @param {Object} object The object to iterate over.
  18809. * @param {Function} iteratee The function invoked per iteration.
  18810. * @param {Function} keysFunc The function to get the keys of `object`.
  18811. * @returns {Object} Returns `object`.
  18812. */
  18813. var baseFor = createBaseFor();
  18814. /**
  18815. * This function is like `baseFor` except that it iterates over properties
  18816. * in the opposite order.
  18817. *
  18818. * @private
  18819. * @param {Object} object The object to iterate over.
  18820. * @param {Function} iteratee The function invoked per iteration.
  18821. * @param {Function} keysFunc The function to get the keys of `object`.
  18822. * @returns {Object} Returns `object`.
  18823. */
  18824. var baseForRight = createBaseFor(true);
  18825. /**
  18826. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  18827. *
  18828. * @private
  18829. * @param {Object} object The object to iterate over.
  18830. * @param {Function} iteratee The function invoked per iteration.
  18831. * @returns {Object} Returns `object`.
  18832. */
  18833. function baseForOwn(object, iteratee) {
  18834. return object && baseFor(object, iteratee, keys);
  18835. }
  18836. /**
  18837. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  18838. *
  18839. * @private
  18840. * @param {Object} object The object to iterate over.
  18841. * @param {Function} iteratee The function invoked per iteration.
  18842. * @returns {Object} Returns `object`.
  18843. */
  18844. function baseForOwnRight(object, iteratee) {
  18845. return object && baseForRight(object, iteratee, keys);
  18846. }
  18847. /**
  18848. * The base implementation of `_.functions` which creates an array of
  18849. * `object` function property names filtered from `props`.
  18850. *
  18851. * @private
  18852. * @param {Object} object The object to inspect.
  18853. * @param {Array} props The property names to filter.
  18854. * @returns {Array} Returns the function names.
  18855. */
  18856. function baseFunctions(object, props) {
  18857. return arrayFilter(props, function(key) {
  18858. return isFunction(object[key]);
  18859. });
  18860. }
  18861. /**
  18862. * The base implementation of `_.get` without support for default values.
  18863. *
  18864. * @private
  18865. * @param {Object} object The object to query.
  18866. * @param {Array|string} path The path of the property to get.
  18867. * @returns {*} Returns the resolved value.
  18868. */
  18869. function baseGet(object, path) {
  18870. path = isKey(path, object) ? [path] : castPath(path);
  18871. var index = 0,
  18872. length = path.length;
  18873. while (object != null && index < length) {
  18874. object = object[toKey(path[index++])];
  18875. }
  18876. return (index && index == length) ? object : undefined;
  18877. }
  18878. /**
  18879. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  18880. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  18881. * symbols of `object`.
  18882. *
  18883. * @private
  18884. * @param {Object} object The object to query.
  18885. * @param {Function} keysFunc The function to get the keys of `object`.
  18886. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  18887. * @returns {Array} Returns the array of property names and symbols.
  18888. */
  18889. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  18890. var result = keysFunc(object);
  18891. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  18892. }
  18893. /**
  18894. * The base implementation of `_.gt` which doesn't coerce arguments to numbers.
  18895. *
  18896. * @private
  18897. * @param {*} value The value to compare.
  18898. * @param {*} other The other value to compare.
  18899. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  18900. * else `false`.
  18901. */
  18902. function baseGt(value, other) {
  18903. return value > other;
  18904. }
  18905. /**
  18906. * The base implementation of `_.has` without support for deep paths.
  18907. *
  18908. * @private
  18909. * @param {Object} [object] The object to query.
  18910. * @param {Array|string} key The key to check.
  18911. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  18912. */
  18913. function baseHas(object, key) {
  18914. // Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
  18915. // that are composed entirely of index properties, return `false` for
  18916. // `hasOwnProperty` checks of them.
  18917. return object != null &&
  18918. (hasOwnProperty.call(object, key) ||
  18919. (typeof object == 'object' && key in object && getPrototype(object) === null));
  18920. }
  18921. /**
  18922. * The base implementation of `_.hasIn` without support for deep paths.
  18923. *
  18924. * @private
  18925. * @param {Object} [object] The object to query.
  18926. * @param {Array|string} key The key to check.
  18927. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  18928. */
  18929. function baseHasIn(object, key) {
  18930. return object != null && key in Object(object);
  18931. }
  18932. /**
  18933. * The base implementation of `_.inRange` which doesn't coerce arguments to numbers.
  18934. *
  18935. * @private
  18936. * @param {number} number The number to check.
  18937. * @param {number} start The start of the range.
  18938. * @param {number} end The end of the range.
  18939. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  18940. */
  18941. function baseInRange(number, start, end) {
  18942. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  18943. }
  18944. /**
  18945. * The base implementation of methods like `_.intersection`, without support
  18946. * for iteratee shorthands, that accepts an array of arrays to inspect.
  18947. *
  18948. * @private
  18949. * @param {Array} arrays The arrays to inspect.
  18950. * @param {Function} [iteratee] The iteratee invoked per element.
  18951. * @param {Function} [comparator] The comparator invoked per element.
  18952. * @returns {Array} Returns the new array of shared values.
  18953. */
  18954. function baseIntersection(arrays, iteratee, comparator) {
  18955. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  18956. length = arrays[0].length,
  18957. othLength = arrays.length,
  18958. othIndex = othLength,
  18959. caches = Array(othLength),
  18960. maxLength = Infinity,
  18961. result = [];
  18962. while (othIndex--) {
  18963. var array = arrays[othIndex];
  18964. if (othIndex && iteratee) {
  18965. array = arrayMap(array, baseUnary(iteratee));
  18966. }
  18967. maxLength = nativeMin(array.length, maxLength);
  18968. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  18969. ? new SetCache(othIndex && array)
  18970. : undefined;
  18971. }
  18972. array = arrays[0];
  18973. var index = -1,
  18974. seen = caches[0];
  18975. outer:
  18976. while (++index < length && result.length < maxLength) {
  18977. var value = array[index],
  18978. computed = iteratee ? iteratee(value) : value;
  18979. value = (comparator || value !== 0) ? value : 0;
  18980. if (!(seen
  18981. ? cacheHas(seen, computed)
  18982. : includes(result, computed, comparator)
  18983. )) {
  18984. othIndex = othLength;
  18985. while (--othIndex) {
  18986. var cache = caches[othIndex];
  18987. if (!(cache
  18988. ? cacheHas(cache, computed)
  18989. : includes(arrays[othIndex], computed, comparator))
  18990. ) {
  18991. continue outer;
  18992. }
  18993. }
  18994. if (seen) {
  18995. seen.push(computed);
  18996. }
  18997. result.push(value);
  18998. }
  18999. }
  19000. return result;
  19001. }
  19002. /**
  19003. * The base implementation of `_.invert` and `_.invertBy` which inverts
  19004. * `object` with values transformed by `iteratee` and set by `setter`.
  19005. *
  19006. * @private
  19007. * @param {Object} object The object to iterate over.
  19008. * @param {Function} setter The function to set `accumulator` values.
  19009. * @param {Function} iteratee The iteratee to transform values.
  19010. * @param {Object} accumulator The initial inverted object.
  19011. * @returns {Function} Returns `accumulator`.
  19012. */
  19013. function baseInverter(object, setter, iteratee, accumulator) {
  19014. baseForOwn(object, function(value, key, object) {
  19015. setter(accumulator, iteratee(value), key, object);
  19016. });
  19017. return accumulator;
  19018. }
  19019. /**
  19020. * The base implementation of `_.invoke` without support for individual
  19021. * method arguments.
  19022. *
  19023. * @private
  19024. * @param {Object} object The object to query.
  19025. * @param {Array|string} path The path of the method to invoke.
  19026. * @param {Array} args The arguments to invoke the method with.
  19027. * @returns {*} Returns the result of the invoked method.
  19028. */
  19029. function baseInvoke(object, path, args) {
  19030. if (!isKey(path, object)) {
  19031. path = castPath(path);
  19032. object = parent(object, path);
  19033. path = last(path);
  19034. }
  19035. var func = object == null ? object : object[toKey(path)];
  19036. return func == null ? undefined : apply(func, object, args);
  19037. }
  19038. /**
  19039. * The base implementation of `_.isEqual` which supports partial comparisons
  19040. * and tracks traversed objects.
  19041. *
  19042. * @private
  19043. * @param {*} value The value to compare.
  19044. * @param {*} other The other value to compare.
  19045. * @param {Function} [customizer] The function to customize comparisons.
  19046. * @param {boolean} [bitmask] The bitmask of comparison flags.
  19047. * The bitmask may be composed of the following flags:
  19048. * 1 - Unordered comparison
  19049. * 2 - Partial comparison
  19050. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  19051. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  19052. */
  19053. function baseIsEqual(value, other, customizer, bitmask, stack) {
  19054. if (value === other) {
  19055. return true;
  19056. }
  19057. if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
  19058. return value !== value && other !== other;
  19059. }
  19060. return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
  19061. }
  19062. /**
  19063. * A specialized version of `baseIsEqual` for arrays and objects which performs
  19064. * deep comparisons and tracks traversed objects enabling objects with circular
  19065. * references to be compared.
  19066. *
  19067. * @private
  19068. * @param {Object} object The object to compare.
  19069. * @param {Object} other The other object to compare.
  19070. * @param {Function} equalFunc The function to determine equivalents of values.
  19071. * @param {Function} [customizer] The function to customize comparisons.
  19072. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
  19073. * for more details.
  19074. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  19075. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  19076. */
  19077. function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
  19078. var objIsArr = isArray(object),
  19079. othIsArr = isArray(other),
  19080. objTag = arrayTag,
  19081. othTag = arrayTag;
  19082. if (!objIsArr) {
  19083. objTag = getTag(object);
  19084. objTag = objTag == argsTag ? objectTag : objTag;
  19085. }
  19086. if (!othIsArr) {
  19087. othTag = getTag(other);
  19088. othTag = othTag == argsTag ? objectTag : othTag;
  19089. }
  19090. var objIsObj = objTag == objectTag && !isHostObject(object),
  19091. othIsObj = othTag == objectTag && !isHostObject(other),
  19092. isSameTag = objTag == othTag;
  19093. if (isSameTag && !objIsObj) {
  19094. stack || (stack = new Stack);
  19095. return (objIsArr || isTypedArray(object))
  19096. ? equalArrays(object, other, equalFunc, customizer, bitmask, stack)
  19097. : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
  19098. }
  19099. if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
  19100. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  19101. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  19102. if (objIsWrapped || othIsWrapped) {
  19103. var objUnwrapped = objIsWrapped ? object.value() : object,
  19104. othUnwrapped = othIsWrapped ? other.value() : other;
  19105. stack || (stack = new Stack);
  19106. return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
  19107. }
  19108. }
  19109. if (!isSameTag) {
  19110. return false;
  19111. }
  19112. stack || (stack = new Stack);
  19113. return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
  19114. }
  19115. /**
  19116. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  19117. *
  19118. * @private
  19119. * @param {Object} object The object to inspect.
  19120. * @param {Object} source The object of property values to match.
  19121. * @param {Array} matchData The property names, values, and compare flags to match.
  19122. * @param {Function} [customizer] The function to customize comparisons.
  19123. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  19124. */
  19125. function baseIsMatch(object, source, matchData, customizer) {
  19126. var index = matchData.length,
  19127. length = index,
  19128. noCustomizer = !customizer;
  19129. if (object == null) {
  19130. return !length;
  19131. }
  19132. object = Object(object);
  19133. while (index--) {
  19134. var data = matchData[index];
  19135. if ((noCustomizer && data[2])
  19136. ? data[1] !== object[data[0]]
  19137. : !(data[0] in object)
  19138. ) {
  19139. return false;
  19140. }
  19141. }
  19142. while (++index < length) {
  19143. data = matchData[index];
  19144. var key = data[0],
  19145. objValue = object[key],
  19146. srcValue = data[1];
  19147. if (noCustomizer && data[2]) {
  19148. if (objValue === undefined && !(key in object)) {
  19149. return false;
  19150. }
  19151. } else {
  19152. var stack = new Stack;
  19153. if (customizer) {
  19154. var result = customizer(objValue, srcValue, key, object, source, stack);
  19155. }
  19156. if (!(result === undefined
  19157. ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack)
  19158. : result
  19159. )) {
  19160. return false;
  19161. }
  19162. }
  19163. }
  19164. return true;
  19165. }
  19166. /**
  19167. * The base implementation of `_.isNative` without bad shim checks.
  19168. *
  19169. * @private
  19170. * @param {*} value The value to check.
  19171. * @returns {boolean} Returns `true` if `value` is a native function,
  19172. * else `false`.
  19173. */
  19174. function baseIsNative(value) {
  19175. if (!isObject(value) || isMasked(value)) {
  19176. return false;
  19177. }
  19178. var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
  19179. return pattern.test(toSource(value));
  19180. }
  19181. /**
  19182. * The base implementation of `_.iteratee`.
  19183. *
  19184. * @private
  19185. * @param {*} [value=_.identity] The value to convert to an iteratee.
  19186. * @returns {Function} Returns the iteratee.
  19187. */
  19188. function baseIteratee(value) {
  19189. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  19190. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  19191. if (typeof value == 'function') {
  19192. return value;
  19193. }
  19194. if (value == null) {
  19195. return identity;
  19196. }
  19197. if (typeof value == 'object') {
  19198. return isArray(value)
  19199. ? baseMatchesProperty(value[0], value[1])
  19200. : baseMatches(value);
  19201. }
  19202. return property(value);
  19203. }
  19204. /**
  19205. * The base implementation of `_.keys` which doesn't skip the constructor
  19206. * property of prototypes or treat sparse arrays as dense.
  19207. *
  19208. * @private
  19209. * @param {Object} object The object to query.
  19210. * @returns {Array} Returns the array of property names.
  19211. */
  19212. function baseKeys(object) {
  19213. return nativeKeys(Object(object));
  19214. }
  19215. /**
  19216. * The base implementation of `_.keysIn` which doesn't skip the constructor
  19217. * property of prototypes or treat sparse arrays as dense.
  19218. *
  19219. * @private
  19220. * @param {Object} object The object to query.
  19221. * @returns {Array} Returns the array of property names.
  19222. */
  19223. function baseKeysIn(object) {
  19224. object = object == null ? object : Object(object);
  19225. var result = [];
  19226. for (var key in object) {
  19227. result.push(key);
  19228. }
  19229. return result;
  19230. }
  19231. // Fallback for IE < 9 with es6-shim.
  19232. if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
  19233. baseKeysIn = function(object) {
  19234. return iteratorToArray(enumerate(object));
  19235. };
  19236. }
  19237. /**
  19238. * The base implementation of `_.lt` which doesn't coerce arguments to numbers.
  19239. *
  19240. * @private
  19241. * @param {*} value The value to compare.
  19242. * @param {*} other The other value to compare.
  19243. * @returns {boolean} Returns `true` if `value` is less than `other`,
  19244. * else `false`.
  19245. */
  19246. function baseLt(value, other) {
  19247. return value < other;
  19248. }
  19249. /**
  19250. * The base implementation of `_.map` without support for iteratee shorthands.
  19251. *
  19252. * @private
  19253. * @param {Array|Object} collection The collection to iterate over.
  19254. * @param {Function} iteratee The function invoked per iteration.
  19255. * @returns {Array} Returns the new mapped array.
  19256. */
  19257. function baseMap(collection, iteratee) {
  19258. var index = -1,
  19259. result = isArrayLike(collection) ? Array(collection.length) : [];
  19260. baseEach(collection, function(value, key, collection) {
  19261. result[++index] = iteratee(value, key, collection);
  19262. });
  19263. return result;
  19264. }
  19265. /**
  19266. * The base implementation of `_.matches` which doesn't clone `source`.
  19267. *
  19268. * @private
  19269. * @param {Object} source The object of property values to match.
  19270. * @returns {Function} Returns the new spec function.
  19271. */
  19272. function baseMatches(source) {
  19273. var matchData = getMatchData(source);
  19274. if (matchData.length == 1 && matchData[0][2]) {
  19275. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  19276. }
  19277. return function(object) {
  19278. return object === source || baseIsMatch(object, source, matchData);
  19279. };
  19280. }
  19281. /**
  19282. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  19283. *
  19284. * @private
  19285. * @param {string} path The path of the property to get.
  19286. * @param {*} srcValue The value to match.
  19287. * @returns {Function} Returns the new spec function.
  19288. */
  19289. function baseMatchesProperty(path, srcValue) {
  19290. if (isKey(path) && isStrictComparable(srcValue)) {
  19291. return matchesStrictComparable(toKey(path), srcValue);
  19292. }
  19293. return function(object) {
  19294. var objValue = get(object, path);
  19295. return (objValue === undefined && objValue === srcValue)
  19296. ? hasIn(object, path)
  19297. : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
  19298. };
  19299. }
  19300. /**
  19301. * The base implementation of `_.merge` without support for multiple sources.
  19302. *
  19303. * @private
  19304. * @param {Object} object The destination object.
  19305. * @param {Object} source The source object.
  19306. * @param {number} srcIndex The index of `source`.
  19307. * @param {Function} [customizer] The function to customize merged values.
  19308. * @param {Object} [stack] Tracks traversed source values and their merged
  19309. * counterparts.
  19310. */
  19311. function baseMerge(object, source, srcIndex, customizer, stack) {
  19312. if (object === source) {
  19313. return;
  19314. }
  19315. if (!(isArray(source) || isTypedArray(source))) {
  19316. var props = keysIn(source);
  19317. }
  19318. arrayEach(props || source, function(srcValue, key) {
  19319. if (props) {
  19320. key = srcValue;
  19321. srcValue = source[key];
  19322. }
  19323. if (isObject(srcValue)) {
  19324. stack || (stack = new Stack);
  19325. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  19326. }
  19327. else {
  19328. var newValue = customizer
  19329. ? customizer(object[key], srcValue, (key + ''), object, source, stack)
  19330. : undefined;
  19331. if (newValue === undefined) {
  19332. newValue = srcValue;
  19333. }
  19334. assignMergeValue(object, key, newValue);
  19335. }
  19336. });
  19337. }
  19338. /**
  19339. * A specialized version of `baseMerge` for arrays and objects which performs
  19340. * deep merges and tracks traversed objects enabling objects with circular
  19341. * references to be merged.
  19342. *
  19343. * @private
  19344. * @param {Object} object The destination object.
  19345. * @param {Object} source The source object.
  19346. * @param {string} key The key of the value to merge.
  19347. * @param {number} srcIndex The index of `source`.
  19348. * @param {Function} mergeFunc The function to merge values.
  19349. * @param {Function} [customizer] The function to customize assigned values.
  19350. * @param {Object} [stack] Tracks traversed source values and their merged
  19351. * counterparts.
  19352. */
  19353. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  19354. var objValue = object[key],
  19355. srcValue = source[key],
  19356. stacked = stack.get(srcValue);
  19357. if (stacked) {
  19358. assignMergeValue(object, key, stacked);
  19359. return;
  19360. }
  19361. var newValue = customizer
  19362. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  19363. : undefined;
  19364. var isCommon = newValue === undefined;
  19365. if (isCommon) {
  19366. newValue = srcValue;
  19367. if (isArray(srcValue) || isTypedArray(srcValue)) {
  19368. if (isArray(objValue)) {
  19369. newValue = objValue;
  19370. }
  19371. else if (isArrayLikeObject(objValue)) {
  19372. newValue = copyArray(objValue);
  19373. }
  19374. else {
  19375. isCommon = false;
  19376. newValue = baseClone(srcValue, true);
  19377. }
  19378. }
  19379. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  19380. if (isArguments(objValue)) {
  19381. newValue = toPlainObject(objValue);
  19382. }
  19383. else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
  19384. isCommon = false;
  19385. newValue = baseClone(srcValue, true);
  19386. }
  19387. else {
  19388. newValue = objValue;
  19389. }
  19390. }
  19391. else {
  19392. isCommon = false;
  19393. }
  19394. }
  19395. stack.set(srcValue, newValue);
  19396. if (isCommon) {
  19397. // Recursively merge objects and arrays (susceptible to call stack limits).
  19398. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  19399. }
  19400. stack['delete'](srcValue);
  19401. assignMergeValue(object, key, newValue);
  19402. }
  19403. /**
  19404. * The base implementation of `_.nth` which doesn't coerce `n` to an integer.
  19405. *
  19406. * @private
  19407. * @param {Array} array The array to query.
  19408. * @param {number} n The index of the element to return.
  19409. * @returns {*} Returns the nth element of `array`.
  19410. */
  19411. function baseNth(array, n) {
  19412. var length = array.length;
  19413. if (!length) {
  19414. return;
  19415. }
  19416. n += n < 0 ? length : 0;
  19417. return isIndex(n, length) ? array[n] : undefined;
  19418. }
  19419. /**
  19420. * The base implementation of `_.orderBy` without param guards.
  19421. *
  19422. * @private
  19423. * @param {Array|Object} collection The collection to iterate over.
  19424. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  19425. * @param {string[]} orders The sort orders of `iteratees`.
  19426. * @returns {Array} Returns the new sorted array.
  19427. */
  19428. function baseOrderBy(collection, iteratees, orders) {
  19429. var index = -1;
  19430. iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
  19431. var result = baseMap(collection, function(value, key, collection) {
  19432. var criteria = arrayMap(iteratees, function(iteratee) {
  19433. return iteratee(value);
  19434. });
  19435. return { 'criteria': criteria, 'index': ++index, 'value': value };
  19436. });
  19437. return baseSortBy(result, function(object, other) {
  19438. return compareMultiple(object, other, orders);
  19439. });
  19440. }
  19441. /**
  19442. * The base implementation of `_.pick` without support for individual
  19443. * property identifiers.
  19444. *
  19445. * @private
  19446. * @param {Object} object The source object.
  19447. * @param {string[]} props The property identifiers to pick.
  19448. * @returns {Object} Returns the new object.
  19449. */
  19450. function basePick(object, props) {
  19451. object = Object(object);
  19452. return arrayReduce(props, function(result, key) {
  19453. if (key in object) {
  19454. result[key] = object[key];
  19455. }
  19456. return result;
  19457. }, {});
  19458. }
  19459. /**
  19460. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  19461. *
  19462. * @private
  19463. * @param {Object} object The source object.
  19464. * @param {Function} predicate The function invoked per property.
  19465. * @returns {Object} Returns the new object.
  19466. */
  19467. function basePickBy(object, predicate) {
  19468. var index = -1,
  19469. props = getAllKeysIn(object),
  19470. length = props.length,
  19471. result = {};
  19472. while (++index < length) {
  19473. var key = props[index],
  19474. value = object[key];
  19475. if (predicate(value, key)) {
  19476. result[key] = value;
  19477. }
  19478. }
  19479. return result;
  19480. }
  19481. /**
  19482. * The base implementation of `_.property` without support for deep paths.
  19483. *
  19484. * @private
  19485. * @param {string} key The key of the property to get.
  19486. * @returns {Function} Returns the new accessor function.
  19487. */
  19488. function baseProperty(key) {
  19489. return function(object) {
  19490. return object == null ? undefined : object[key];
  19491. };
  19492. }
  19493. /**
  19494. * A specialized version of `baseProperty` which supports deep paths.
  19495. *
  19496. * @private
  19497. * @param {Array|string} path The path of the property to get.
  19498. * @returns {Function} Returns the new accessor function.
  19499. */
  19500. function basePropertyDeep(path) {
  19501. return function(object) {
  19502. return baseGet(object, path);
  19503. };
  19504. }
  19505. /**
  19506. * The base implementation of `_.pullAllBy` without support for iteratee
  19507. * shorthands.
  19508. *
  19509. * @private
  19510. * @param {Array} array The array to modify.
  19511. * @param {Array} values The values to remove.
  19512. * @param {Function} [iteratee] The iteratee invoked per element.
  19513. * @param {Function} [comparator] The comparator invoked per element.
  19514. * @returns {Array} Returns `array`.
  19515. */
  19516. function basePullAll(array, values, iteratee, comparator) {
  19517. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  19518. index = -1,
  19519. length = values.length,
  19520. seen = array;
  19521. if (array === values) {
  19522. values = copyArray(values);
  19523. }
  19524. if (iteratee) {
  19525. seen = arrayMap(array, baseUnary(iteratee));
  19526. }
  19527. while (++index < length) {
  19528. var fromIndex = 0,
  19529. value = values[index],
  19530. computed = iteratee ? iteratee(value) : value;
  19531. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  19532. if (seen !== array) {
  19533. splice.call(seen, fromIndex, 1);
  19534. }
  19535. splice.call(array, fromIndex, 1);
  19536. }
  19537. }
  19538. return array;
  19539. }
  19540. /**
  19541. * The base implementation of `_.pullAt` without support for individual
  19542. * indexes or capturing the removed elements.
  19543. *
  19544. * @private
  19545. * @param {Array} array The array to modify.
  19546. * @param {number[]} indexes The indexes of elements to remove.
  19547. * @returns {Array} Returns `array`.
  19548. */
  19549. function basePullAt(array, indexes) {
  19550. var length = array ? indexes.length : 0,
  19551. lastIndex = length - 1;
  19552. while (length--) {
  19553. var index = indexes[length];
  19554. if (length == lastIndex || index !== previous) {
  19555. var previous = index;
  19556. if (isIndex(index)) {
  19557. splice.call(array, index, 1);
  19558. }
  19559. else if (!isKey(index, array)) {
  19560. var path = castPath(index),
  19561. object = parent(array, path);
  19562. if (object != null) {
  19563. delete object[toKey(last(path))];
  19564. }
  19565. }
  19566. else {
  19567. delete array[toKey(index)];
  19568. }
  19569. }
  19570. }
  19571. return array;
  19572. }
  19573. /**
  19574. * The base implementation of `_.random` without support for returning
  19575. * floating-point numbers.
  19576. *
  19577. * @private
  19578. * @param {number} lower The lower bound.
  19579. * @param {number} upper The upper bound.
  19580. * @returns {number} Returns the random number.
  19581. */
  19582. function baseRandom(lower, upper) {
  19583. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  19584. }
  19585. /**
  19586. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  19587. * coerce arguments to numbers.
  19588. *
  19589. * @private
  19590. * @param {number} start The start of the range.
  19591. * @param {number} end The end of the range.
  19592. * @param {number} step The value to increment or decrement by.
  19593. * @param {boolean} [fromRight] Specify iterating from right to left.
  19594. * @returns {Array} Returns the range of numbers.
  19595. */
  19596. function baseRange(start, end, step, fromRight) {
  19597. var index = -1,
  19598. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  19599. result = Array(length);
  19600. while (length--) {
  19601. result[fromRight ? length : ++index] = start;
  19602. start += step;
  19603. }
  19604. return result;
  19605. }
  19606. /**
  19607. * The base implementation of `_.repeat` which doesn't coerce arguments.
  19608. *
  19609. * @private
  19610. * @param {string} string The string to repeat.
  19611. * @param {number} n The number of times to repeat the string.
  19612. * @returns {string} Returns the repeated string.
  19613. */
  19614. function baseRepeat(string, n) {
  19615. var result = '';
  19616. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  19617. return result;
  19618. }
  19619. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  19620. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  19621. do {
  19622. if (n % 2) {
  19623. result += string;
  19624. }
  19625. n = nativeFloor(n / 2);
  19626. if (n) {
  19627. string += string;
  19628. }
  19629. } while (n);
  19630. return result;
  19631. }
  19632. /**
  19633. * The base implementation of `_.set`.
  19634. *
  19635. * @private
  19636. * @param {Object} object The object to query.
  19637. * @param {Array|string} path The path of the property to set.
  19638. * @param {*} value The value to set.
  19639. * @param {Function} [customizer] The function to customize path creation.
  19640. * @returns {Object} Returns `object`.
  19641. */
  19642. function baseSet(object, path, value, customizer) {
  19643. path = isKey(path, object) ? [path] : castPath(path);
  19644. var index = -1,
  19645. length = path.length,
  19646. lastIndex = length - 1,
  19647. nested = object;
  19648. while (nested != null && ++index < length) {
  19649. var key = toKey(path[index]);
  19650. if (isObject(nested)) {
  19651. var newValue = value;
  19652. if (index != lastIndex) {
  19653. var objValue = nested[key];
  19654. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  19655. if (newValue === undefined) {
  19656. newValue = objValue == null
  19657. ? (isIndex(path[index + 1]) ? [] : {})
  19658. : objValue;
  19659. }
  19660. }
  19661. assignValue(nested, key, newValue);
  19662. }
  19663. nested = nested[key];
  19664. }
  19665. return object;
  19666. }
  19667. /**
  19668. * The base implementation of `setData` without support for hot loop detection.
  19669. *
  19670. * @private
  19671. * @param {Function} func The function to associate metadata with.
  19672. * @param {*} data The metadata.
  19673. * @returns {Function} Returns `func`.
  19674. */
  19675. var baseSetData = !metaMap ? identity : function(func, data) {
  19676. metaMap.set(func, data);
  19677. return func;
  19678. };
  19679. /**
  19680. * The base implementation of `_.slice` without an iteratee call guard.
  19681. *
  19682. * @private
  19683. * @param {Array} array The array to slice.
  19684. * @param {number} [start=0] The start position.
  19685. * @param {number} [end=array.length] The end position.
  19686. * @returns {Array} Returns the slice of `array`.
  19687. */
  19688. function baseSlice(array, start, end) {
  19689. var index = -1,
  19690. length = array.length;
  19691. if (start < 0) {
  19692. start = -start > length ? 0 : (length + start);
  19693. }
  19694. end = end > length ? length : end;
  19695. if (end < 0) {
  19696. end += length;
  19697. }
  19698. length = start > end ? 0 : ((end - start) >>> 0);
  19699. start >>>= 0;
  19700. var result = Array(length);
  19701. while (++index < length) {
  19702. result[index] = array[index + start];
  19703. }
  19704. return result;
  19705. }
  19706. /**
  19707. * The base implementation of `_.some` without support for iteratee shorthands.
  19708. *
  19709. * @private
  19710. * @param {Array|Object} collection The collection to iterate over.
  19711. * @param {Function} predicate The function invoked per iteration.
  19712. * @returns {boolean} Returns `true` if any element passes the predicate check,
  19713. * else `false`.
  19714. */
  19715. function baseSome(collection, predicate) {
  19716. var result;
  19717. baseEach(collection, function(value, index, collection) {
  19718. result = predicate(value, index, collection);
  19719. return !result;
  19720. });
  19721. return !!result;
  19722. }
  19723. /**
  19724. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  19725. * performs a binary search of `array` to determine the index at which `value`
  19726. * should be inserted into `array` in order to maintain its sort order.
  19727. *
  19728. * @private
  19729. * @param {Array} array The sorted array to inspect.
  19730. * @param {*} value The value to evaluate.
  19731. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  19732. * @returns {number} Returns the index at which `value` should be inserted
  19733. * into `array`.
  19734. */
  19735. function baseSortedIndex(array, value, retHighest) {
  19736. var low = 0,
  19737. high = array ? array.length : low;
  19738. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  19739. while (low < high) {
  19740. var mid = (low + high) >>> 1,
  19741. computed = array[mid];
  19742. if (computed !== null && !isSymbol(computed) &&
  19743. (retHighest ? (computed <= value) : (computed < value))) {
  19744. low = mid + 1;
  19745. } else {
  19746. high = mid;
  19747. }
  19748. }
  19749. return high;
  19750. }
  19751. return baseSortedIndexBy(array, value, identity, retHighest);
  19752. }
  19753. /**
  19754. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  19755. * which invokes `iteratee` for `value` and each element of `array` to compute
  19756. * their sort ranking. The iteratee is invoked with one argument; (value).
  19757. *
  19758. * @private
  19759. * @param {Array} array The sorted array to inspect.
  19760. * @param {*} value The value to evaluate.
  19761. * @param {Function} iteratee The iteratee invoked per element.
  19762. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  19763. * @returns {number} Returns the index at which `value` should be inserted
  19764. * into `array`.
  19765. */
  19766. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  19767. value = iteratee(value);
  19768. var low = 0,
  19769. high = array ? array.length : 0,
  19770. valIsNaN = value !== value,
  19771. valIsNull = value === null,
  19772. valIsSymbol = isSymbol(value),
  19773. valIsUndefined = value === undefined;
  19774. while (low < high) {
  19775. var mid = nativeFloor((low + high) / 2),
  19776. computed = iteratee(array[mid]),
  19777. othIsDefined = computed !== undefined,
  19778. othIsNull = computed === null,
  19779. othIsReflexive = computed === computed,
  19780. othIsSymbol = isSymbol(computed);
  19781. if (valIsNaN) {
  19782. var setLow = retHighest || othIsReflexive;
  19783. } else if (valIsUndefined) {
  19784. setLow = othIsReflexive && (retHighest || othIsDefined);
  19785. } else if (valIsNull) {
  19786. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  19787. } else if (valIsSymbol) {
  19788. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  19789. } else if (othIsNull || othIsSymbol) {
  19790. setLow = false;
  19791. } else {
  19792. setLow = retHighest ? (computed <= value) : (computed < value);
  19793. }
  19794. if (setLow) {
  19795. low = mid + 1;
  19796. } else {
  19797. high = mid;
  19798. }
  19799. }
  19800. return nativeMin(high, MAX_ARRAY_INDEX);
  19801. }
  19802. /**
  19803. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  19804. * support for iteratee shorthands.
  19805. *
  19806. * @private
  19807. * @param {Array} array The array to inspect.
  19808. * @param {Function} [iteratee] The iteratee invoked per element.
  19809. * @returns {Array} Returns the new duplicate free array.
  19810. */
  19811. function baseSortedUniq(array, iteratee) {
  19812. var index = -1,
  19813. length = array.length,
  19814. resIndex = 0,
  19815. result = [];
  19816. while (++index < length) {
  19817. var value = array[index],
  19818. computed = iteratee ? iteratee(value) : value;
  19819. if (!index || !eq(computed, seen)) {
  19820. var seen = computed;
  19821. result[resIndex++] = value === 0 ? 0 : value;
  19822. }
  19823. }
  19824. return result;
  19825. }
  19826. /**
  19827. * The base implementation of `_.toNumber` which doesn't ensure correct
  19828. * conversions of binary, hexadecimal, or octal string values.
  19829. *
  19830. * @private
  19831. * @param {*} value The value to process.
  19832. * @returns {number} Returns the number.
  19833. */
  19834. function baseToNumber(value) {
  19835. if (typeof value == 'number') {
  19836. return value;
  19837. }
  19838. if (isSymbol(value)) {
  19839. return NAN;
  19840. }
  19841. return +value;
  19842. }
  19843. /**
  19844. * The base implementation of `_.toString` which doesn't convert nullish
  19845. * values to empty strings.
  19846. *
  19847. * @private
  19848. * @param {*} value The value to process.
  19849. * @returns {string} Returns the string.
  19850. */
  19851. function baseToString(value) {
  19852. // Exit early for strings to avoid a performance hit in some environments.
  19853. if (typeof value == 'string') {
  19854. return value;
  19855. }
  19856. if (isSymbol(value)) {
  19857. return symbolToString ? symbolToString.call(value) : '';
  19858. }
  19859. var result = (value + '');
  19860. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  19861. }
  19862. /**
  19863. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  19864. *
  19865. * @private
  19866. * @param {Array} array The array to inspect.
  19867. * @param {Function} [iteratee] The iteratee invoked per element.
  19868. * @param {Function} [comparator] The comparator invoked per element.
  19869. * @returns {Array} Returns the new duplicate free array.
  19870. */
  19871. function baseUniq(array, iteratee, comparator) {
  19872. var index = -1,
  19873. includes = arrayIncludes,
  19874. length = array.length,
  19875. isCommon = true,
  19876. result = [],
  19877. seen = result;
  19878. if (comparator) {
  19879. isCommon = false;
  19880. includes = arrayIncludesWith;
  19881. }
  19882. else if (length >= LARGE_ARRAY_SIZE) {
  19883. var set = iteratee ? null : createSet(array);
  19884. if (set) {
  19885. return setToArray(set);
  19886. }
  19887. isCommon = false;
  19888. includes = cacheHas;
  19889. seen = new SetCache;
  19890. }
  19891. else {
  19892. seen = iteratee ? [] : result;
  19893. }
  19894. outer:
  19895. while (++index < length) {
  19896. var value = array[index],
  19897. computed = iteratee ? iteratee(value) : value;
  19898. value = (comparator || value !== 0) ? value : 0;
  19899. if (isCommon && computed === computed) {
  19900. var seenIndex = seen.length;
  19901. while (seenIndex--) {
  19902. if (seen[seenIndex] === computed) {
  19903. continue outer;
  19904. }
  19905. }
  19906. if (iteratee) {
  19907. seen.push(computed);
  19908. }
  19909. result.push(value);
  19910. }
  19911. else if (!includes(seen, computed, comparator)) {
  19912. if (seen !== result) {
  19913. seen.push(computed);
  19914. }
  19915. result.push(value);
  19916. }
  19917. }
  19918. return result;
  19919. }
  19920. /**
  19921. * The base implementation of `_.unset`.
  19922. *
  19923. * @private
  19924. * @param {Object} object The object to modify.
  19925. * @param {Array|string} path The path of the property to unset.
  19926. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  19927. */
  19928. function baseUnset(object, path) {
  19929. path = isKey(path, object) ? [path] : castPath(path);
  19930. object = parent(object, path);
  19931. var key = toKey(last(path));
  19932. return !(object != null && baseHas(object, key)) || delete object[key];
  19933. }
  19934. /**
  19935. * The base implementation of `_.update`.
  19936. *
  19937. * @private
  19938. * @param {Object} object The object to query.
  19939. * @param {Array|string} path The path of the property to update.
  19940. * @param {Function} updater The function to produce the updated value.
  19941. * @param {Function} [customizer] The function to customize path creation.
  19942. * @returns {Object} Returns `object`.
  19943. */
  19944. function baseUpdate(object, path, updater, customizer) {
  19945. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  19946. }
  19947. /**
  19948. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  19949. * without support for iteratee shorthands.
  19950. *
  19951. * @private
  19952. * @param {Array} array The array to query.
  19953. * @param {Function} predicate The function invoked per iteration.
  19954. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  19955. * @param {boolean} [fromRight] Specify iterating from right to left.
  19956. * @returns {Array} Returns the slice of `array`.
  19957. */
  19958. function baseWhile(array, predicate, isDrop, fromRight) {
  19959. var length = array.length,
  19960. index = fromRight ? length : -1;
  19961. while ((fromRight ? index-- : ++index < length) &&
  19962. predicate(array[index], index, array)) {}
  19963. return isDrop
  19964. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  19965. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  19966. }
  19967. /**
  19968. * The base implementation of `wrapperValue` which returns the result of
  19969. * performing a sequence of actions on the unwrapped `value`, where each
  19970. * successive action is supplied the return value of the previous.
  19971. *
  19972. * @private
  19973. * @param {*} value The unwrapped value.
  19974. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  19975. * @returns {*} Returns the resolved value.
  19976. */
  19977. function baseWrapperValue(value, actions) {
  19978. var result = value;
  19979. if (result instanceof LazyWrapper) {
  19980. result = result.value();
  19981. }
  19982. return arrayReduce(actions, function(result, action) {
  19983. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  19984. }, result);
  19985. }
  19986. /**
  19987. * The base implementation of methods like `_.xor`, without support for
  19988. * iteratee shorthands, that accepts an array of arrays to inspect.
  19989. *
  19990. * @private
  19991. * @param {Array} arrays The arrays to inspect.
  19992. * @param {Function} [iteratee] The iteratee invoked per element.
  19993. * @param {Function} [comparator] The comparator invoked per element.
  19994. * @returns {Array} Returns the new array of values.
  19995. */
  19996. function baseXor(arrays, iteratee, comparator) {
  19997. var index = -1,
  19998. length = arrays.length;
  19999. while (++index < length) {
  20000. var result = result
  20001. ? arrayPush(
  20002. baseDifference(result, arrays[index], iteratee, comparator),
  20003. baseDifference(arrays[index], result, iteratee, comparator)
  20004. )
  20005. : arrays[index];
  20006. }
  20007. return (result && result.length) ? baseUniq(result, iteratee, comparator) : [];
  20008. }
  20009. /**
  20010. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  20011. *
  20012. * @private
  20013. * @param {Array} props The property identifiers.
  20014. * @param {Array} values The property values.
  20015. * @param {Function} assignFunc The function to assign values.
  20016. * @returns {Object} Returns the new object.
  20017. */
  20018. function baseZipObject(props, values, assignFunc) {
  20019. var index = -1,
  20020. length = props.length,
  20021. valsLength = values.length,
  20022. result = {};
  20023. while (++index < length) {
  20024. var value = index < valsLength ? values[index] : undefined;
  20025. assignFunc(result, props[index], value);
  20026. }
  20027. return result;
  20028. }
  20029. /**
  20030. * Casts `value` to an empty array if it's not an array like object.
  20031. *
  20032. * @private
  20033. * @param {*} value The value to inspect.
  20034. * @returns {Array|Object} Returns the cast array-like object.
  20035. */
  20036. function castArrayLikeObject(value) {
  20037. return isArrayLikeObject(value) ? value : [];
  20038. }
  20039. /**
  20040. * Casts `value` to `identity` if it's not a function.
  20041. *
  20042. * @private
  20043. * @param {*} value The value to inspect.
  20044. * @returns {Function} Returns cast function.
  20045. */
  20046. function castFunction(value) {
  20047. return typeof value == 'function' ? value : identity;
  20048. }
  20049. /**
  20050. * Casts `value` to a path array if it's not one.
  20051. *
  20052. * @private
  20053. * @param {*} value The value to inspect.
  20054. * @returns {Array} Returns the cast property path array.
  20055. */
  20056. function castPath(value) {
  20057. return isArray(value) ? value : stringToPath(value);
  20058. }
  20059. /**
  20060. * Casts `array` to a slice if it's needed.
  20061. *
  20062. * @private
  20063. * @param {Array} array The array to inspect.
  20064. * @param {number} start The start position.
  20065. * @param {number} [end=array.length] The end position.
  20066. * @returns {Array} Returns the cast slice.
  20067. */
  20068. function castSlice(array, start, end) {
  20069. var length = array.length;
  20070. end = end === undefined ? length : end;
  20071. return (!start && end >= length) ? array : baseSlice(array, start, end);
  20072. }
  20073. /**
  20074. * Creates a clone of `buffer`.
  20075. *
  20076. * @private
  20077. * @param {Buffer} buffer The buffer to clone.
  20078. * @param {boolean} [isDeep] Specify a deep clone.
  20079. * @returns {Buffer} Returns the cloned buffer.
  20080. */
  20081. function cloneBuffer(buffer, isDeep) {
  20082. if (isDeep) {
  20083. return buffer.slice();
  20084. }
  20085. var result = new buffer.constructor(buffer.length);
  20086. buffer.copy(result);
  20087. return result;
  20088. }
  20089. /**
  20090. * Creates a clone of `arrayBuffer`.
  20091. *
  20092. * @private
  20093. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  20094. * @returns {ArrayBuffer} Returns the cloned array buffer.
  20095. */
  20096. function cloneArrayBuffer(arrayBuffer) {
  20097. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  20098. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  20099. return result;
  20100. }
  20101. /**
  20102. * Creates a clone of `dataView`.
  20103. *
  20104. * @private
  20105. * @param {Object} dataView The data view to clone.
  20106. * @param {boolean} [isDeep] Specify a deep clone.
  20107. * @returns {Object} Returns the cloned data view.
  20108. */
  20109. function cloneDataView(dataView, isDeep) {
  20110. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  20111. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  20112. }
  20113. /**
  20114. * Creates a clone of `map`.
  20115. *
  20116. * @private
  20117. * @param {Object} map The map to clone.
  20118. * @param {Function} cloneFunc The function to clone values.
  20119. * @param {boolean} [isDeep] Specify a deep clone.
  20120. * @returns {Object} Returns the cloned map.
  20121. */
  20122. function cloneMap(map, isDeep, cloneFunc) {
  20123. var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map);
  20124. return arrayReduce(array, addMapEntry, new map.constructor);
  20125. }
  20126. /**
  20127. * Creates a clone of `regexp`.
  20128. *
  20129. * @private
  20130. * @param {Object} regexp The regexp to clone.
  20131. * @returns {Object} Returns the cloned regexp.
  20132. */
  20133. function cloneRegExp(regexp) {
  20134. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  20135. result.lastIndex = regexp.lastIndex;
  20136. return result;
  20137. }
  20138. /**
  20139. * Creates a clone of `set`.
  20140. *
  20141. * @private
  20142. * @param {Object} set The set to clone.
  20143. * @param {Function} cloneFunc The function to clone values.
  20144. * @param {boolean} [isDeep] Specify a deep clone.
  20145. * @returns {Object} Returns the cloned set.
  20146. */
  20147. function cloneSet(set, isDeep, cloneFunc) {
  20148. var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set);
  20149. return arrayReduce(array, addSetEntry, new set.constructor);
  20150. }
  20151. /**
  20152. * Creates a clone of the `symbol` object.
  20153. *
  20154. * @private
  20155. * @param {Object} symbol The symbol object to clone.
  20156. * @returns {Object} Returns the cloned symbol object.
  20157. */
  20158. function cloneSymbol(symbol) {
  20159. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  20160. }
  20161. /**
  20162. * Creates a clone of `typedArray`.
  20163. *
  20164. * @private
  20165. * @param {Object} typedArray The typed array to clone.
  20166. * @param {boolean} [isDeep] Specify a deep clone.
  20167. * @returns {Object} Returns the cloned typed array.
  20168. */
  20169. function cloneTypedArray(typedArray, isDeep) {
  20170. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  20171. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  20172. }
  20173. /**
  20174. * Compares values to sort them in ascending order.
  20175. *
  20176. * @private
  20177. * @param {*} value The value to compare.
  20178. * @param {*} other The other value to compare.
  20179. * @returns {number} Returns the sort order indicator for `value`.
  20180. */
  20181. function compareAscending(value, other) {
  20182. if (value !== other) {
  20183. var valIsDefined = value !== undefined,
  20184. valIsNull = value === null,
  20185. valIsReflexive = value === value,
  20186. valIsSymbol = isSymbol(value);
  20187. var othIsDefined = other !== undefined,
  20188. othIsNull = other === null,
  20189. othIsReflexive = other === other,
  20190. othIsSymbol = isSymbol(other);
  20191. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  20192. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  20193. (valIsNull && othIsDefined && othIsReflexive) ||
  20194. (!valIsDefined && othIsReflexive) ||
  20195. !valIsReflexive) {
  20196. return 1;
  20197. }
  20198. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  20199. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  20200. (othIsNull && valIsDefined && valIsReflexive) ||
  20201. (!othIsDefined && valIsReflexive) ||
  20202. !othIsReflexive) {
  20203. return -1;
  20204. }
  20205. }
  20206. return 0;
  20207. }
  20208. /**
  20209. * Used by `_.orderBy` to compare multiple properties of a value to another
  20210. * and stable sort them.
  20211. *
  20212. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  20213. * specify an order of "desc" for descending or "asc" for ascending sort order
  20214. * of corresponding values.
  20215. *
  20216. * @private
  20217. * @param {Object} object The object to compare.
  20218. * @param {Object} other The other object to compare.
  20219. * @param {boolean[]|string[]} orders The order to sort by for each property.
  20220. * @returns {number} Returns the sort order indicator for `object`.
  20221. */
  20222. function compareMultiple(object, other, orders) {
  20223. var index = -1,
  20224. objCriteria = object.criteria,
  20225. othCriteria = other.criteria,
  20226. length = objCriteria.length,
  20227. ordersLength = orders.length;
  20228. while (++index < length) {
  20229. var result = compareAscending(objCriteria[index], othCriteria[index]);
  20230. if (result) {
  20231. if (index >= ordersLength) {
  20232. return result;
  20233. }
  20234. var order = orders[index];
  20235. return result * (order == 'desc' ? -1 : 1);
  20236. }
  20237. }
  20238. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  20239. // that causes it, under certain circumstances, to provide the same value for
  20240. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  20241. // for more details.
  20242. //
  20243. // This also ensures a stable sort in V8 and other engines.
  20244. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  20245. return object.index - other.index;
  20246. }
  20247. /**
  20248. * Creates an array that is the composition of partially applied arguments,
  20249. * placeholders, and provided arguments into a single array of arguments.
  20250. *
  20251. * @private
  20252. * @param {Array} args The provided arguments.
  20253. * @param {Array} partials The arguments to prepend to those provided.
  20254. * @param {Array} holders The `partials` placeholder indexes.
  20255. * @params {boolean} [isCurried] Specify composing for a curried function.
  20256. * @returns {Array} Returns the new array of composed arguments.
  20257. */
  20258. function composeArgs(args, partials, holders, isCurried) {
  20259. var argsIndex = -1,
  20260. argsLength = args.length,
  20261. holdersLength = holders.length,
  20262. leftIndex = -1,
  20263. leftLength = partials.length,
  20264. rangeLength = nativeMax(argsLength - holdersLength, 0),
  20265. result = Array(leftLength + rangeLength),
  20266. isUncurried = !isCurried;
  20267. while (++leftIndex < leftLength) {
  20268. result[leftIndex] = partials[leftIndex];
  20269. }
  20270. while (++argsIndex < holdersLength) {
  20271. if (isUncurried || argsIndex < argsLength) {
  20272. result[holders[argsIndex]] = args[argsIndex];
  20273. }
  20274. }
  20275. while (rangeLength--) {
  20276. result[leftIndex++] = args[argsIndex++];
  20277. }
  20278. return result;
  20279. }
  20280. /**
  20281. * This function is like `composeArgs` except that the arguments composition
  20282. * is tailored for `_.partialRight`.
  20283. *
  20284. * @private
  20285. * @param {Array} args The provided arguments.
  20286. * @param {Array} partials The arguments to append to those provided.
  20287. * @param {Array} holders The `partials` placeholder indexes.
  20288. * @params {boolean} [isCurried] Specify composing for a curried function.
  20289. * @returns {Array} Returns the new array of composed arguments.
  20290. */
  20291. function composeArgsRight(args, partials, holders, isCurried) {
  20292. var argsIndex = -1,
  20293. argsLength = args.length,
  20294. holdersIndex = -1,
  20295. holdersLength = holders.length,
  20296. rightIndex = -1,
  20297. rightLength = partials.length,
  20298. rangeLength = nativeMax(argsLength - holdersLength, 0),
  20299. result = Array(rangeLength + rightLength),
  20300. isUncurried = !isCurried;
  20301. while (++argsIndex < rangeLength) {
  20302. result[argsIndex] = args[argsIndex];
  20303. }
  20304. var offset = argsIndex;
  20305. while (++rightIndex < rightLength) {
  20306. result[offset + rightIndex] = partials[rightIndex];
  20307. }
  20308. while (++holdersIndex < holdersLength) {
  20309. if (isUncurried || argsIndex < argsLength) {
  20310. result[offset + holders[holdersIndex]] = args[argsIndex++];
  20311. }
  20312. }
  20313. return result;
  20314. }
  20315. /**
  20316. * Copies the values of `source` to `array`.
  20317. *
  20318. * @private
  20319. * @param {Array} source The array to copy values from.
  20320. * @param {Array} [array=[]] The array to copy values to.
  20321. * @returns {Array} Returns `array`.
  20322. */
  20323. function copyArray(source, array) {
  20324. var index = -1,
  20325. length = source.length;
  20326. array || (array = Array(length));
  20327. while (++index < length) {
  20328. array[index] = source[index];
  20329. }
  20330. return array;
  20331. }
  20332. /**
  20333. * Copies properties of `source` to `object`.
  20334. *
  20335. * @private
  20336. * @param {Object} source The object to copy properties from.
  20337. * @param {Array} props The property identifiers to copy.
  20338. * @param {Object} [object={}] The object to copy properties to.
  20339. * @param {Function} [customizer] The function to customize copied values.
  20340. * @returns {Object} Returns `object`.
  20341. */
  20342. function copyObject(source, props, object, customizer) {
  20343. object || (object = {});
  20344. var index = -1,
  20345. length = props.length;
  20346. while (++index < length) {
  20347. var key = props[index];
  20348. var newValue = customizer
  20349. ? customizer(object[key], source[key], key, object, source)
  20350. : source[key];
  20351. assignValue(object, key, newValue);
  20352. }
  20353. return object;
  20354. }
  20355. /**
  20356. * Copies own symbol properties of `source` to `object`.
  20357. *
  20358. * @private
  20359. * @param {Object} source The object to copy symbols from.
  20360. * @param {Object} [object={}] The object to copy symbols to.
  20361. * @returns {Object} Returns `object`.
  20362. */
  20363. function copySymbols(source, object) {
  20364. return copyObject(source, getSymbols(source), object);
  20365. }
  20366. /**
  20367. * Creates a function like `_.groupBy`.
  20368. *
  20369. * @private
  20370. * @param {Function} setter The function to set accumulator values.
  20371. * @param {Function} [initializer] The accumulator object initializer.
  20372. * @returns {Function} Returns the new aggregator function.
  20373. */
  20374. function createAggregator(setter, initializer) {
  20375. return function(collection, iteratee) {
  20376. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  20377. accumulator = initializer ? initializer() : {};
  20378. return func(collection, setter, getIteratee(iteratee), accumulator);
  20379. };
  20380. }
  20381. /**
  20382. * Creates a function like `_.assign`.
  20383. *
  20384. * @private
  20385. * @param {Function} assigner The function to assign values.
  20386. * @returns {Function} Returns the new assigner function.
  20387. */
  20388. function createAssigner(assigner) {
  20389. return rest(function(object, sources) {
  20390. var index = -1,
  20391. length = sources.length,
  20392. customizer = length > 1 ? sources[length - 1] : undefined,
  20393. guard = length > 2 ? sources[2] : undefined;
  20394. customizer = (assigner.length > 3 && typeof customizer == 'function')
  20395. ? (length--, customizer)
  20396. : undefined;
  20397. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  20398. customizer = length < 3 ? undefined : customizer;
  20399. length = 1;
  20400. }
  20401. object = Object(object);
  20402. while (++index < length) {
  20403. var source = sources[index];
  20404. if (source) {
  20405. assigner(object, source, index, customizer);
  20406. }
  20407. }
  20408. return object;
  20409. });
  20410. }
  20411. /**
  20412. * Creates a `baseEach` or `baseEachRight` function.
  20413. *
  20414. * @private
  20415. * @param {Function} eachFunc The function to iterate over a collection.
  20416. * @param {boolean} [fromRight] Specify iterating from right to left.
  20417. * @returns {Function} Returns the new base function.
  20418. */
  20419. function createBaseEach(eachFunc, fromRight) {
  20420. return function(collection, iteratee) {
  20421. if (collection == null) {
  20422. return collection;
  20423. }
  20424. if (!isArrayLike(collection)) {
  20425. return eachFunc(collection, iteratee);
  20426. }
  20427. var length = collection.length,
  20428. index = fromRight ? length : -1,
  20429. iterable = Object(collection);
  20430. while ((fromRight ? index-- : ++index < length)) {
  20431. if (iteratee(iterable[index], index, iterable) === false) {
  20432. break;
  20433. }
  20434. }
  20435. return collection;
  20436. };
  20437. }
  20438. /**
  20439. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  20440. *
  20441. * @private
  20442. * @param {boolean} [fromRight] Specify iterating from right to left.
  20443. * @returns {Function} Returns the new base function.
  20444. */
  20445. function createBaseFor(fromRight) {
  20446. return function(object, iteratee, keysFunc) {
  20447. var index = -1,
  20448. iterable = Object(object),
  20449. props = keysFunc(object),
  20450. length = props.length;
  20451. while (length--) {
  20452. var key = props[fromRight ? length : ++index];
  20453. if (iteratee(iterable[key], key, iterable) === false) {
  20454. break;
  20455. }
  20456. }
  20457. return object;
  20458. };
  20459. }
  20460. /**
  20461. * Creates a function that wraps `func` to invoke it with the optional `this`
  20462. * binding of `thisArg`.
  20463. *
  20464. * @private
  20465. * @param {Function} func The function to wrap.
  20466. * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
  20467. * for more details.
  20468. * @param {*} [thisArg] The `this` binding of `func`.
  20469. * @returns {Function} Returns the new wrapped function.
  20470. */
  20471. function createBaseWrapper(func, bitmask, thisArg) {
  20472. var isBind = bitmask & BIND_FLAG,
  20473. Ctor = createCtorWrapper(func);
  20474. function wrapper() {
  20475. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  20476. return fn.apply(isBind ? thisArg : this, arguments);
  20477. }
  20478. return wrapper;
  20479. }
  20480. /**
  20481. * Creates a function like `_.lowerFirst`.
  20482. *
  20483. * @private
  20484. * @param {string} methodName The name of the `String` case method to use.
  20485. * @returns {Function} Returns the new case function.
  20486. */
  20487. function createCaseFirst(methodName) {
  20488. return function(string) {
  20489. string = toString(string);
  20490. var strSymbols = reHasComplexSymbol.test(string)
  20491. ? stringToArray(string)
  20492. : undefined;
  20493. var chr = strSymbols
  20494. ? strSymbols[0]
  20495. : string.charAt(0);
  20496. var trailing = strSymbols
  20497. ? castSlice(strSymbols, 1).join('')
  20498. : string.slice(1);
  20499. return chr[methodName]() + trailing;
  20500. };
  20501. }
  20502. /**
  20503. * Creates a function like `_.camelCase`.
  20504. *
  20505. * @private
  20506. * @param {Function} callback The function to combine each word.
  20507. * @returns {Function} Returns the new compounder function.
  20508. */
  20509. function createCompounder(callback) {
  20510. return function(string) {
  20511. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  20512. };
  20513. }
  20514. /**
  20515. * Creates a function that produces an instance of `Ctor` regardless of
  20516. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  20517. *
  20518. * @private
  20519. * @param {Function} Ctor The constructor to wrap.
  20520. * @returns {Function} Returns the new wrapped function.
  20521. */
  20522. function createCtorWrapper(Ctor) {
  20523. return function() {
  20524. // Use a `switch` statement to work with class constructors. See
  20525. // http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  20526. // for more details.
  20527. var args = arguments;
  20528. switch (args.length) {
  20529. case 0: return new Ctor;
  20530. case 1: return new Ctor(args[0]);
  20531. case 2: return new Ctor(args[0], args[1]);
  20532. case 3: return new Ctor(args[0], args[1], args[2]);
  20533. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  20534. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  20535. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  20536. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  20537. }
  20538. var thisBinding = baseCreate(Ctor.prototype),
  20539. result = Ctor.apply(thisBinding, args);
  20540. // Mimic the constructor's `return` behavior.
  20541. // See https://es5.github.io/#x13.2.2 for more details.
  20542. return isObject(result) ? result : thisBinding;
  20543. };
  20544. }
  20545. /**
  20546. * Creates a function that wraps `func` to enable currying.
  20547. *
  20548. * @private
  20549. * @param {Function} func The function to wrap.
  20550. * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
  20551. * for more details.
  20552. * @param {number} arity The arity of `func`.
  20553. * @returns {Function} Returns the new wrapped function.
  20554. */
  20555. function createCurryWrapper(func, bitmask, arity) {
  20556. var Ctor = createCtorWrapper(func);
  20557. function wrapper() {
  20558. var length = arguments.length,
  20559. args = Array(length),
  20560. index = length,
  20561. placeholder = getHolder(wrapper);
  20562. while (index--) {
  20563. args[index] = arguments[index];
  20564. }
  20565. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  20566. ? []
  20567. : replaceHolders(args, placeholder);
  20568. length -= holders.length;
  20569. if (length < arity) {
  20570. return createRecurryWrapper(
  20571. func, bitmask, createHybridWrapper, wrapper.placeholder, undefined,
  20572. args, holders, undefined, undefined, arity - length);
  20573. }
  20574. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  20575. return apply(fn, this, args);
  20576. }
  20577. return wrapper;
  20578. }
  20579. /**
  20580. * Creates a `_.find` or `_.findLast` function.
  20581. *
  20582. * @private
  20583. * @param {Function} findIndexFunc The function to find the collection index.
  20584. * @returns {Function} Returns the new find function.
  20585. */
  20586. function createFind(findIndexFunc) {
  20587. return function(collection, predicate, fromIndex) {
  20588. var iterable = Object(collection);
  20589. predicate = getIteratee(predicate, 3);
  20590. if (!isArrayLike(collection)) {
  20591. var props = keys(collection);
  20592. }
  20593. var index = findIndexFunc(props || collection, function(value, key) {
  20594. if (props) {
  20595. key = value;
  20596. value = iterable[key];
  20597. }
  20598. return predicate(value, key, iterable);
  20599. }, fromIndex);
  20600. return index > -1 ? collection[props ? props[index] : index] : undefined;
  20601. };
  20602. }
  20603. /**
  20604. * Creates a `_.flow` or `_.flowRight` function.
  20605. *
  20606. * @private
  20607. * @param {boolean} [fromRight] Specify iterating from right to left.
  20608. * @returns {Function} Returns the new flow function.
  20609. */
  20610. function createFlow(fromRight) {
  20611. return rest(function(funcs) {
  20612. funcs = baseFlatten(funcs, 1);
  20613. var length = funcs.length,
  20614. index = length,
  20615. prereq = LodashWrapper.prototype.thru;
  20616. if (fromRight) {
  20617. funcs.reverse();
  20618. }
  20619. while (index--) {
  20620. var func = funcs[index];
  20621. if (typeof func != 'function') {
  20622. throw new TypeError(FUNC_ERROR_TEXT);
  20623. }
  20624. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  20625. var wrapper = new LodashWrapper([], true);
  20626. }
  20627. }
  20628. index = wrapper ? index : length;
  20629. while (++index < length) {
  20630. func = funcs[index];
  20631. var funcName = getFuncName(func),
  20632. data = funcName == 'wrapper' ? getData(func) : undefined;
  20633. if (data && isLaziable(data[0]) &&
  20634. data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) &&
  20635. !data[4].length && data[9] == 1
  20636. ) {
  20637. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  20638. } else {
  20639. wrapper = (func.length == 1 && isLaziable(func))
  20640. ? wrapper[funcName]()
  20641. : wrapper.thru(func);
  20642. }
  20643. }
  20644. return function() {
  20645. var args = arguments,
  20646. value = args[0];
  20647. if (wrapper && args.length == 1 &&
  20648. isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
  20649. return wrapper.plant(value).value();
  20650. }
  20651. var index = 0,
  20652. result = length ? funcs[index].apply(this, args) : value;
  20653. while (++index < length) {
  20654. result = funcs[index].call(this, result);
  20655. }
  20656. return result;
  20657. };
  20658. });
  20659. }
  20660. /**
  20661. * Creates a function that wraps `func` to invoke it with optional `this`
  20662. * binding of `thisArg`, partial application, and currying.
  20663. *
  20664. * @private
  20665. * @param {Function|string} func The function or method name to wrap.
  20666. * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
  20667. * for more details.
  20668. * @param {*} [thisArg] The `this` binding of `func`.
  20669. * @param {Array} [partials] The arguments to prepend to those provided to
  20670. * the new function.
  20671. * @param {Array} [holders] The `partials` placeholder indexes.
  20672. * @param {Array} [partialsRight] The arguments to append to those provided
  20673. * to the new function.
  20674. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  20675. * @param {Array} [argPos] The argument positions of the new function.
  20676. * @param {number} [ary] The arity cap of `func`.
  20677. * @param {number} [arity] The arity of `func`.
  20678. * @returns {Function} Returns the new wrapped function.
  20679. */
  20680. function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  20681. var isAry = bitmask & ARY_FLAG,
  20682. isBind = bitmask & BIND_FLAG,
  20683. isBindKey = bitmask & BIND_KEY_FLAG,
  20684. isCurried = bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG),
  20685. isFlip = bitmask & FLIP_FLAG,
  20686. Ctor = isBindKey ? undefined : createCtorWrapper(func);
  20687. function wrapper() {
  20688. var length = arguments.length,
  20689. args = Array(length),
  20690. index = length;
  20691. while (index--) {
  20692. args[index] = arguments[index];
  20693. }
  20694. if (isCurried) {
  20695. var placeholder = getHolder(wrapper),
  20696. holdersCount = countHolders(args, placeholder);
  20697. }
  20698. if (partials) {
  20699. args = composeArgs(args, partials, holders, isCurried);
  20700. }
  20701. if (partialsRight) {
  20702. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  20703. }
  20704. length -= holdersCount;
  20705. if (isCurried && length < arity) {
  20706. var newHolders = replaceHolders(args, placeholder);
  20707. return createRecurryWrapper(
  20708. func, bitmask, createHybridWrapper, wrapper.placeholder, thisArg,
  20709. args, newHolders, argPos, ary, arity - length
  20710. );
  20711. }
  20712. var thisBinding = isBind ? thisArg : this,
  20713. fn = isBindKey ? thisBinding[func] : func;
  20714. length = args.length;
  20715. if (argPos) {
  20716. args = reorder(args, argPos);
  20717. } else if (isFlip && length > 1) {
  20718. args.reverse();
  20719. }
  20720. if (isAry && ary < length) {
  20721. args.length = ary;
  20722. }
  20723. if (this && this !== root && this instanceof wrapper) {
  20724. fn = Ctor || createCtorWrapper(fn);
  20725. }
  20726. return fn.apply(thisBinding, args);
  20727. }
  20728. return wrapper;
  20729. }
  20730. /**
  20731. * Creates a function like `_.invertBy`.
  20732. *
  20733. * @private
  20734. * @param {Function} setter The function to set accumulator values.
  20735. * @param {Function} toIteratee The function to resolve iteratees.
  20736. * @returns {Function} Returns the new inverter function.
  20737. */
  20738. function createInverter(setter, toIteratee) {
  20739. return function(object, iteratee) {
  20740. return baseInverter(object, setter, toIteratee(iteratee), {});
  20741. };
  20742. }
  20743. /**
  20744. * Creates a function that performs a mathematical operation on two values.
  20745. *
  20746. * @private
  20747. * @param {Function} operator The function to perform the operation.
  20748. * @returns {Function} Returns the new mathematical operation function.
  20749. */
  20750. function createMathOperation(operator) {
  20751. return function(value, other) {
  20752. var result;
  20753. if (value === undefined && other === undefined) {
  20754. return 0;
  20755. }
  20756. if (value !== undefined) {
  20757. result = value;
  20758. }
  20759. if (other !== undefined) {
  20760. if (result === undefined) {
  20761. return other;
  20762. }
  20763. if (typeof value == 'string' || typeof other == 'string') {
  20764. value = baseToString(value);
  20765. other = baseToString(other);
  20766. } else {
  20767. value = baseToNumber(value);
  20768. other = baseToNumber(other);
  20769. }
  20770. result = operator(value, other);
  20771. }
  20772. return result;
  20773. };
  20774. }
  20775. /**
  20776. * Creates a function like `_.over`.
  20777. *
  20778. * @private
  20779. * @param {Function} arrayFunc The function to iterate over iteratees.
  20780. * @returns {Function} Returns the new over function.
  20781. */
  20782. function createOver(arrayFunc) {
  20783. return rest(function(iteratees) {
  20784. iteratees = (iteratees.length == 1 && isArray(iteratees[0]))
  20785. ? arrayMap(iteratees[0], baseUnary(getIteratee()))
  20786. : arrayMap(baseFlatten(iteratees, 1, isFlattenableIteratee), baseUnary(getIteratee()));
  20787. return rest(function(args) {
  20788. var thisArg = this;
  20789. return arrayFunc(iteratees, function(iteratee) {
  20790. return apply(iteratee, thisArg, args);
  20791. });
  20792. });
  20793. });
  20794. }
  20795. /**
  20796. * Creates the padding for `string` based on `length`. The `chars` string
  20797. * is truncated if the number of characters exceeds `length`.
  20798. *
  20799. * @private
  20800. * @param {number} length The padding length.
  20801. * @param {string} [chars=' '] The string used as padding.
  20802. * @returns {string} Returns the padding for `string`.
  20803. */
  20804. function createPadding(length, chars) {
  20805. chars = chars === undefined ? ' ' : baseToString(chars);
  20806. var charsLength = chars.length;
  20807. if (charsLength < 2) {
  20808. return charsLength ? baseRepeat(chars, length) : chars;
  20809. }
  20810. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  20811. return reHasComplexSymbol.test(chars)
  20812. ? castSlice(stringToArray(result), 0, length).join('')
  20813. : result.slice(0, length);
  20814. }
  20815. /**
  20816. * Creates a function that wraps `func` to invoke it with the `this` binding
  20817. * of `thisArg` and `partials` prepended to the arguments it receives.
  20818. *
  20819. * @private
  20820. * @param {Function} func The function to wrap.
  20821. * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
  20822. * for more details.
  20823. * @param {*} thisArg The `this` binding of `func`.
  20824. * @param {Array} partials The arguments to prepend to those provided to
  20825. * the new function.
  20826. * @returns {Function} Returns the new wrapped function.
  20827. */
  20828. function createPartialWrapper(func, bitmask, thisArg, partials) {
  20829. var isBind = bitmask & BIND_FLAG,
  20830. Ctor = createCtorWrapper(func);
  20831. function wrapper() {
  20832. var argsIndex = -1,
  20833. argsLength = arguments.length,
  20834. leftIndex = -1,
  20835. leftLength = partials.length,
  20836. args = Array(leftLength + argsLength),
  20837. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  20838. while (++leftIndex < leftLength) {
  20839. args[leftIndex] = partials[leftIndex];
  20840. }
  20841. while (argsLength--) {
  20842. args[leftIndex++] = arguments[++argsIndex];
  20843. }
  20844. return apply(fn, isBind ? thisArg : this, args);
  20845. }
  20846. return wrapper;
  20847. }
  20848. /**
  20849. * Creates a `_.range` or `_.rangeRight` function.
  20850. *
  20851. * @private
  20852. * @param {boolean} [fromRight] Specify iterating from right to left.
  20853. * @returns {Function} Returns the new range function.
  20854. */
  20855. function createRange(fromRight) {
  20856. return function(start, end, step) {
  20857. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  20858. end = step = undefined;
  20859. }
  20860. // Ensure the sign of `-0` is preserved.
  20861. start = toNumber(start);
  20862. start = start === start ? start : 0;
  20863. if (end === undefined) {
  20864. end = start;
  20865. start = 0;
  20866. } else {
  20867. end = toNumber(end) || 0;
  20868. }
  20869. step = step === undefined ? (start < end ? 1 : -1) : (toNumber(step) || 0);
  20870. return baseRange(start, end, step, fromRight);
  20871. };
  20872. }
  20873. /**
  20874. * Creates a function that performs a relational operation on two values.
  20875. *
  20876. * @private
  20877. * @param {Function} operator The function to perform the operation.
  20878. * @returns {Function} Returns the new relational operation function.
  20879. */
  20880. function createRelationalOperation(operator) {
  20881. return function(value, other) {
  20882. if (!(typeof value == 'string' && typeof other == 'string')) {
  20883. value = toNumber(value);
  20884. other = toNumber(other);
  20885. }
  20886. return operator(value, other);
  20887. };
  20888. }
  20889. /**
  20890. * Creates a function that wraps `func` to continue currying.
  20891. *
  20892. * @private
  20893. * @param {Function} func The function to wrap.
  20894. * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
  20895. * for more details.
  20896. * @param {Function} wrapFunc The function to create the `func` wrapper.
  20897. * @param {*} placeholder The placeholder value.
  20898. * @param {*} [thisArg] The `this` binding of `func`.
  20899. * @param {Array} [partials] The arguments to prepend to those provided to
  20900. * the new function.
  20901. * @param {Array} [holders] The `partials` placeholder indexes.
  20902. * @param {Array} [argPos] The argument positions of the new function.
  20903. * @param {number} [ary] The arity cap of `func`.
  20904. * @param {number} [arity] The arity of `func`.
  20905. * @returns {Function} Returns the new wrapped function.
  20906. */
  20907. function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  20908. var isCurry = bitmask & CURRY_FLAG,
  20909. newHolders = isCurry ? holders : undefined,
  20910. newHoldersRight = isCurry ? undefined : holders,
  20911. newPartials = isCurry ? partials : undefined,
  20912. newPartialsRight = isCurry ? undefined : partials;
  20913. bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
  20914. bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
  20915. if (!(bitmask & CURRY_BOUND_FLAG)) {
  20916. bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
  20917. }
  20918. var newData = [
  20919. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  20920. newHoldersRight, argPos, ary, arity
  20921. ];
  20922. var result = wrapFunc.apply(undefined, newData);
  20923. if (isLaziable(func)) {
  20924. setData(result, newData);
  20925. }
  20926. result.placeholder = placeholder;
  20927. return result;
  20928. }
  20929. /**
  20930. * Creates a function like `_.round`.
  20931. *
  20932. * @private
  20933. * @param {string} methodName The name of the `Math` method to use when rounding.
  20934. * @returns {Function} Returns the new round function.
  20935. */
  20936. function createRound(methodName) {
  20937. var func = Math[methodName];
  20938. return function(number, precision) {
  20939. number = toNumber(number);
  20940. precision = nativeMin(toInteger(precision), 292);
  20941. if (precision) {
  20942. // Shift with exponential notation to avoid floating-point issues.
  20943. // See [MDN](https://mdn.io/round#Examples) for more details.
  20944. var pair = (toString(number) + 'e').split('e'),
  20945. value = func(pair[0] + 'e' + (+pair[1] + precision));
  20946. pair = (toString(value) + 'e').split('e');
  20947. return +(pair[0] + 'e' + (+pair[1] - precision));
  20948. }
  20949. return func(number);
  20950. };
  20951. }
  20952. /**
  20953. * Creates a set of `values`.
  20954. *
  20955. * @private
  20956. * @param {Array} values The values to add to the set.
  20957. * @returns {Object} Returns the new set.
  20958. */
  20959. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  20960. return new Set(values);
  20961. };
  20962. /**
  20963. * Creates a `_.toPairs` or `_.toPairsIn` function.
  20964. *
  20965. * @private
  20966. * @param {Function} keysFunc The function to get the keys of a given object.
  20967. * @returns {Function} Returns the new pairs function.
  20968. */
  20969. function createToPairs(keysFunc) {
  20970. return function(object) {
  20971. var tag = getTag(object);
  20972. if (tag == mapTag) {
  20973. return mapToArray(object);
  20974. }
  20975. if (tag == setTag) {
  20976. return setToPairs(object);
  20977. }
  20978. return baseToPairs(object, keysFunc(object));
  20979. };
  20980. }
  20981. /**
  20982. * Creates a function that either curries or invokes `func` with optional
  20983. * `this` binding and partially applied arguments.
  20984. *
  20985. * @private
  20986. * @param {Function|string} func The function or method name to wrap.
  20987. * @param {number} bitmask The bitmask of wrapper flags.
  20988. * The bitmask may be composed of the following flags:
  20989. * 1 - `_.bind`
  20990. * 2 - `_.bindKey`
  20991. * 4 - `_.curry` or `_.curryRight` of a bound function
  20992. * 8 - `_.curry`
  20993. * 16 - `_.curryRight`
  20994. * 32 - `_.partial`
  20995. * 64 - `_.partialRight`
  20996. * 128 - `_.rearg`
  20997. * 256 - `_.ary`
  20998. * 512 - `_.flip`
  20999. * @param {*} [thisArg] The `this` binding of `func`.
  21000. * @param {Array} [partials] The arguments to be partially applied.
  21001. * @param {Array} [holders] The `partials` placeholder indexes.
  21002. * @param {Array} [argPos] The argument positions of the new function.
  21003. * @param {number} [ary] The arity cap of `func`.
  21004. * @param {number} [arity] The arity of `func`.
  21005. * @returns {Function} Returns the new wrapped function.
  21006. */
  21007. function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  21008. var isBindKey = bitmask & BIND_KEY_FLAG;
  21009. if (!isBindKey && typeof func != 'function') {
  21010. throw new TypeError(FUNC_ERROR_TEXT);
  21011. }
  21012. var length = partials ? partials.length : 0;
  21013. if (!length) {
  21014. bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
  21015. partials = holders = undefined;
  21016. }
  21017. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  21018. arity = arity === undefined ? arity : toInteger(arity);
  21019. length -= holders ? holders.length : 0;
  21020. if (bitmask & PARTIAL_RIGHT_FLAG) {
  21021. var partialsRight = partials,
  21022. holdersRight = holders;
  21023. partials = holders = undefined;
  21024. }
  21025. var data = isBindKey ? undefined : getData(func);
  21026. var newData = [
  21027. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  21028. argPos, ary, arity
  21029. ];
  21030. if (data) {
  21031. mergeData(newData, data);
  21032. }
  21033. func = newData[0];
  21034. bitmask = newData[1];
  21035. thisArg = newData[2];
  21036. partials = newData[3];
  21037. holders = newData[4];
  21038. arity = newData[9] = newData[9] == null
  21039. ? (isBindKey ? 0 : func.length)
  21040. : nativeMax(newData[9] - length, 0);
  21041. if (!arity && bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG)) {
  21042. bitmask &= ~(CURRY_FLAG | CURRY_RIGHT_FLAG);
  21043. }
  21044. if (!bitmask || bitmask == BIND_FLAG) {
  21045. var result = createBaseWrapper(func, bitmask, thisArg);
  21046. } else if (bitmask == CURRY_FLAG || bitmask == CURRY_RIGHT_FLAG) {
  21047. result = createCurryWrapper(func, bitmask, arity);
  21048. } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) {
  21049. result = createPartialWrapper(func, bitmask, thisArg, partials);
  21050. } else {
  21051. result = createHybridWrapper.apply(undefined, newData);
  21052. }
  21053. var setter = data ? baseSetData : setData;
  21054. return setter(result, newData);
  21055. }
  21056. /**
  21057. * A specialized version of `baseIsEqualDeep` for arrays with support for
  21058. * partial deep comparisons.
  21059. *
  21060. * @private
  21061. * @param {Array} array The array to compare.
  21062. * @param {Array} other The other array to compare.
  21063. * @param {Function} equalFunc The function to determine equivalents of values.
  21064. * @param {Function} customizer The function to customize comparisons.
  21065. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  21066. * for more details.
  21067. * @param {Object} stack Tracks traversed `array` and `other` objects.
  21068. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  21069. */
  21070. function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
  21071. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  21072. arrLength = array.length,
  21073. othLength = other.length;
  21074. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  21075. return false;
  21076. }
  21077. // Assume cyclic values are equal.
  21078. var stacked = stack.get(array);
  21079. if (stacked) {
  21080. return stacked == other;
  21081. }
  21082. var index = -1,
  21083. result = true,
  21084. seen = (bitmask & UNORDERED_COMPARE_FLAG) ? new SetCache : undefined;
  21085. stack.set(array, other);
  21086. // Ignore non-index properties.
  21087. while (++index < arrLength) {
  21088. var arrValue = array[index],
  21089. othValue = other[index];
  21090. if (customizer) {
  21091. var compared = isPartial
  21092. ? customizer(othValue, arrValue, index, other, array, stack)
  21093. : customizer(arrValue, othValue, index, array, other, stack);
  21094. }
  21095. if (compared !== undefined) {
  21096. if (compared) {
  21097. continue;
  21098. }
  21099. result = false;
  21100. break;
  21101. }
  21102. // Recursively compare arrays (susceptible to call stack limits).
  21103. if (seen) {
  21104. if (!arraySome(other, function(othValue, othIndex) {
  21105. if (!seen.has(othIndex) &&
  21106. (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  21107. return seen.add(othIndex);
  21108. }
  21109. })) {
  21110. result = false;
  21111. break;
  21112. }
  21113. } else if (!(
  21114. arrValue === othValue ||
  21115. equalFunc(arrValue, othValue, customizer, bitmask, stack)
  21116. )) {
  21117. result = false;
  21118. break;
  21119. }
  21120. }
  21121. stack['delete'](array);
  21122. return result;
  21123. }
  21124. /**
  21125. * A specialized version of `baseIsEqualDeep` for comparing objects of
  21126. * the same `toStringTag`.
  21127. *
  21128. * **Note:** This function only supports comparing values with tags of
  21129. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  21130. *
  21131. * @private
  21132. * @param {Object} object The object to compare.
  21133. * @param {Object} other The other object to compare.
  21134. * @param {string} tag The `toStringTag` of the objects to compare.
  21135. * @param {Function} equalFunc The function to determine equivalents of values.
  21136. * @param {Function} customizer The function to customize comparisons.
  21137. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  21138. * for more details.
  21139. * @param {Object} stack Tracks traversed `object` and `other` objects.
  21140. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  21141. */
  21142. function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
  21143. switch (tag) {
  21144. case dataViewTag:
  21145. if ((object.byteLength != other.byteLength) ||
  21146. (object.byteOffset != other.byteOffset)) {
  21147. return false;
  21148. }
  21149. object = object.buffer;
  21150. other = other.buffer;
  21151. case arrayBufferTag:
  21152. if ((object.byteLength != other.byteLength) ||
  21153. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  21154. return false;
  21155. }
  21156. return true;
  21157. case boolTag:
  21158. case dateTag:
  21159. // Coerce dates and booleans to numbers, dates to milliseconds and
  21160. // booleans to `1` or `0` treating invalid dates coerced to `NaN` as
  21161. // not equal.
  21162. return +object == +other;
  21163. case errorTag:
  21164. return object.name == other.name && object.message == other.message;
  21165. case numberTag:
  21166. // Treat `NaN` vs. `NaN` as equal.
  21167. return (object != +object) ? other != +other : object == +other;
  21168. case regexpTag:
  21169. case stringTag:
  21170. // Coerce regexes to strings and treat strings, primitives and objects,
  21171. // as equal. See http://www.ecma-international.org/ecma-262/6.0/#sec-regexp.prototype.tostring
  21172. // for more details.
  21173. return object == (other + '');
  21174. case mapTag:
  21175. var convert = mapToArray;
  21176. case setTag:
  21177. var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
  21178. convert || (convert = setToArray);
  21179. if (object.size != other.size && !isPartial) {
  21180. return false;
  21181. }
  21182. // Assume cyclic values are equal.
  21183. var stacked = stack.get(object);
  21184. if (stacked) {
  21185. return stacked == other;
  21186. }
  21187. bitmask |= UNORDERED_COMPARE_FLAG;
  21188. stack.set(object, other);
  21189. // Recursively compare objects (susceptible to call stack limits).
  21190. return equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
  21191. case symbolTag:
  21192. if (symbolValueOf) {
  21193. return symbolValueOf.call(object) == symbolValueOf.call(other);
  21194. }
  21195. }
  21196. return false;
  21197. }
  21198. /**
  21199. * A specialized version of `baseIsEqualDeep` for objects with support for
  21200. * partial deep comparisons.
  21201. *
  21202. * @private
  21203. * @param {Object} object The object to compare.
  21204. * @param {Object} other The other object to compare.
  21205. * @param {Function} equalFunc The function to determine equivalents of values.
  21206. * @param {Function} customizer The function to customize comparisons.
  21207. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  21208. * for more details.
  21209. * @param {Object} stack Tracks traversed `object` and `other` objects.
  21210. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  21211. */
  21212. function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
  21213. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  21214. objProps = keys(object),
  21215. objLength = objProps.length,
  21216. othProps = keys(other),
  21217. othLength = othProps.length;
  21218. if (objLength != othLength && !isPartial) {
  21219. return false;
  21220. }
  21221. var index = objLength;
  21222. while (index--) {
  21223. var key = objProps[index];
  21224. if (!(isPartial ? key in other : baseHas(other, key))) {
  21225. return false;
  21226. }
  21227. }
  21228. // Assume cyclic values are equal.
  21229. var stacked = stack.get(object);
  21230. if (stacked) {
  21231. return stacked == other;
  21232. }
  21233. var result = true;
  21234. stack.set(object, other);
  21235. var skipCtor = isPartial;
  21236. while (++index < objLength) {
  21237. key = objProps[index];
  21238. var objValue = object[key],
  21239. othValue = other[key];
  21240. if (customizer) {
  21241. var compared = isPartial
  21242. ? customizer(othValue, objValue, key, other, object, stack)
  21243. : customizer(objValue, othValue, key, object, other, stack);
  21244. }
  21245. // Recursively compare objects (susceptible to call stack limits).
  21246. if (!(compared === undefined
  21247. ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
  21248. : compared
  21249. )) {
  21250. result = false;
  21251. break;
  21252. }
  21253. skipCtor || (skipCtor = key == 'constructor');
  21254. }
  21255. if (result && !skipCtor) {
  21256. var objCtor = object.constructor,
  21257. othCtor = other.constructor;
  21258. // Non `Object` object instances with different constructors are not equal.
  21259. if (objCtor != othCtor &&
  21260. ('constructor' in object && 'constructor' in other) &&
  21261. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  21262. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  21263. result = false;
  21264. }
  21265. }
  21266. stack['delete'](object);
  21267. return result;
  21268. }
  21269. /**
  21270. * Creates an array of own enumerable property names and symbols of `object`.
  21271. *
  21272. * @private
  21273. * @param {Object} object The object to query.
  21274. * @returns {Array} Returns the array of property names and symbols.
  21275. */
  21276. function getAllKeys(object) {
  21277. return baseGetAllKeys(object, keys, getSymbols);
  21278. }
  21279. /**
  21280. * Creates an array of own and inherited enumerable property names and
  21281. * symbols of `object`.
  21282. *
  21283. * @private
  21284. * @param {Object} object The object to query.
  21285. * @returns {Array} Returns the array of property names and symbols.
  21286. */
  21287. function getAllKeysIn(object) {
  21288. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  21289. }
  21290. /**
  21291. * Gets metadata for `func`.
  21292. *
  21293. * @private
  21294. * @param {Function} func The function to query.
  21295. * @returns {*} Returns the metadata for `func`.
  21296. */
  21297. var getData = !metaMap ? noop : function(func) {
  21298. return metaMap.get(func);
  21299. };
  21300. /**
  21301. * Gets the name of `func`.
  21302. *
  21303. * @private
  21304. * @param {Function} func The function to query.
  21305. * @returns {string} Returns the function name.
  21306. */
  21307. function getFuncName(func) {
  21308. var result = (func.name + ''),
  21309. array = realNames[result],
  21310. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  21311. while (length--) {
  21312. var data = array[length],
  21313. otherFunc = data.func;
  21314. if (otherFunc == null || otherFunc == func) {
  21315. return data.name;
  21316. }
  21317. }
  21318. return result;
  21319. }
  21320. /**
  21321. * Gets the argument placeholder value for `func`.
  21322. *
  21323. * @private
  21324. * @param {Function} func The function to inspect.
  21325. * @returns {*} Returns the placeholder value.
  21326. */
  21327. function getHolder(func) {
  21328. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  21329. return object.placeholder;
  21330. }
  21331. /**
  21332. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  21333. * this function returns the custom method, otherwise it returns `baseIteratee`.
  21334. * If arguments are provided, the chosen function is invoked with them and
  21335. * its result is returned.
  21336. *
  21337. * @private
  21338. * @param {*} [value] The value to convert to an iteratee.
  21339. * @param {number} [arity] The arity of the created iteratee.
  21340. * @returns {Function} Returns the chosen function or its result.
  21341. */
  21342. function getIteratee() {
  21343. var result = lodash.iteratee || iteratee;
  21344. result = result === iteratee ? baseIteratee : result;
  21345. return arguments.length ? result(arguments[0], arguments[1]) : result;
  21346. }
  21347. /**
  21348. * Gets the "length" property value of `object`.
  21349. *
  21350. * **Note:** This function is used to avoid a
  21351. * [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects
  21352. * Safari on at least iOS 8.1-8.3 ARM64.
  21353. *
  21354. * @private
  21355. * @param {Object} object The object to query.
  21356. * @returns {*} Returns the "length" value.
  21357. */
  21358. var getLength = baseProperty('length');
  21359. /**
  21360. * Gets the data for `map`.
  21361. *
  21362. * @private
  21363. * @param {Object} map The map to query.
  21364. * @param {string} key The reference key.
  21365. * @returns {*} Returns the map data.
  21366. */
  21367. function getMapData(map, key) {
  21368. var data = map.__data__;
  21369. return isKeyable(key)
  21370. ? data[typeof key == 'string' ? 'string' : 'hash']
  21371. : data.map;
  21372. }
  21373. /**
  21374. * Gets the property names, values, and compare flags of `object`.
  21375. *
  21376. * @private
  21377. * @param {Object} object The object to query.
  21378. * @returns {Array} Returns the match data of `object`.
  21379. */
  21380. function getMatchData(object) {
  21381. var result = keys(object),
  21382. length = result.length;
  21383. while (length--) {
  21384. var key = result[length],
  21385. value = object[key];
  21386. result[length] = [key, value, isStrictComparable(value)];
  21387. }
  21388. return result;
  21389. }
  21390. /**
  21391. * Gets the native function at `key` of `object`.
  21392. *
  21393. * @private
  21394. * @param {Object} object The object to query.
  21395. * @param {string} key The key of the method to get.
  21396. * @returns {*} Returns the function if it's native, else `undefined`.
  21397. */
  21398. function getNative(object, key) {
  21399. var value = getValue(object, key);
  21400. return baseIsNative(value) ? value : undefined;
  21401. }
  21402. /**
  21403. * Gets the `[[Prototype]]` of `value`.
  21404. *
  21405. * @private
  21406. * @param {*} value The value to query.
  21407. * @returns {null|Object} Returns the `[[Prototype]]`.
  21408. */
  21409. function getPrototype(value) {
  21410. return nativeGetPrototype(Object(value));
  21411. }
  21412. /**
  21413. * Creates an array of the own enumerable symbol properties of `object`.
  21414. *
  21415. * @private
  21416. * @param {Object} object The object to query.
  21417. * @returns {Array} Returns the array of symbols.
  21418. */
  21419. function getSymbols(object) {
  21420. // Coerce `object` to an object to avoid non-object errors in V8.
  21421. // See https://bugs.chromium.org/p/v8/issues/detail?id=3443 for more details.
  21422. return getOwnPropertySymbols(Object(object));
  21423. }
  21424. // Fallback for IE < 11.
  21425. if (!getOwnPropertySymbols) {
  21426. getSymbols = stubArray;
  21427. }
  21428. /**
  21429. * Creates an array of the own and inherited enumerable symbol properties
  21430. * of `object`.
  21431. *
  21432. * @private
  21433. * @param {Object} object The object to query.
  21434. * @returns {Array} Returns the array of symbols.
  21435. */
  21436. var getSymbolsIn = !getOwnPropertySymbols ? getSymbols : function(object) {
  21437. var result = [];
  21438. while (object) {
  21439. arrayPush(result, getSymbols(object));
  21440. object = getPrototype(object);
  21441. }
  21442. return result;
  21443. };
  21444. /**
  21445. * Gets the `toStringTag` of `value`.
  21446. *
  21447. * @private
  21448. * @param {*} value The value to query.
  21449. * @returns {string} Returns the `toStringTag`.
  21450. */
  21451. function getTag(value) {
  21452. return objectToString.call(value);
  21453. }
  21454. // Fallback for data views, maps, sets, and weak maps in IE 11,
  21455. // for data views in Edge, and promises in Node.js.
  21456. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  21457. (Map && getTag(new Map) != mapTag) ||
  21458. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  21459. (Set && getTag(new Set) != setTag) ||
  21460. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  21461. getTag = function(value) {
  21462. var result = objectToString.call(value),
  21463. Ctor = result == objectTag ? value.constructor : undefined,
  21464. ctorString = Ctor ? toSource(Ctor) : undefined;
  21465. if (ctorString) {
  21466. switch (ctorString) {
  21467. case dataViewCtorString: return dataViewTag;
  21468. case mapCtorString: return mapTag;
  21469. case promiseCtorString: return promiseTag;
  21470. case setCtorString: return setTag;
  21471. case weakMapCtorString: return weakMapTag;
  21472. }
  21473. }
  21474. return result;
  21475. };
  21476. }
  21477. /**
  21478. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  21479. *
  21480. * @private
  21481. * @param {number} start The start of the view.
  21482. * @param {number} end The end of the view.
  21483. * @param {Array} transforms The transformations to apply to the view.
  21484. * @returns {Object} Returns an object containing the `start` and `end`
  21485. * positions of the view.
  21486. */
  21487. function getView(start, end, transforms) {
  21488. var index = -1,
  21489. length = transforms.length;
  21490. while (++index < length) {
  21491. var data = transforms[index],
  21492. size = data.size;
  21493. switch (data.type) {
  21494. case 'drop': start += size; break;
  21495. case 'dropRight': end -= size; break;
  21496. case 'take': end = nativeMin(end, start + size); break;
  21497. case 'takeRight': start = nativeMax(start, end - size); break;
  21498. }
  21499. }
  21500. return { 'start': start, 'end': end };
  21501. }
  21502. /**
  21503. * Checks if `path` exists on `object`.
  21504. *
  21505. * @private
  21506. * @param {Object} object The object to query.
  21507. * @param {Array|string} path The path to check.
  21508. * @param {Function} hasFunc The function to check properties.
  21509. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  21510. */
  21511. function hasPath(object, path, hasFunc) {
  21512. path = isKey(path, object) ? [path] : castPath(path);
  21513. var result,
  21514. index = -1,
  21515. length = path.length;
  21516. while (++index < length) {
  21517. var key = toKey(path[index]);
  21518. if (!(result = object != null && hasFunc(object, key))) {
  21519. break;
  21520. }
  21521. object = object[key];
  21522. }
  21523. if (result) {
  21524. return result;
  21525. }
  21526. var length = object ? object.length : 0;
  21527. return !!length && isLength(length) && isIndex(key, length) &&
  21528. (isArray(object) || isString(object) || isArguments(object));
  21529. }
  21530. /**
  21531. * Initializes an array clone.
  21532. *
  21533. * @private
  21534. * @param {Array} array The array to clone.
  21535. * @returns {Array} Returns the initialized clone.
  21536. */
  21537. function initCloneArray(array) {
  21538. var length = array.length,
  21539. result = array.constructor(length);
  21540. // Add properties assigned by `RegExp#exec`.
  21541. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  21542. result.index = array.index;
  21543. result.input = array.input;
  21544. }
  21545. return result;
  21546. }
  21547. /**
  21548. * Initializes an object clone.
  21549. *
  21550. * @private
  21551. * @param {Object} object The object to clone.
  21552. * @returns {Object} Returns the initialized clone.
  21553. */
  21554. function initCloneObject(object) {
  21555. return (typeof object.constructor == 'function' && !isPrototype(object))
  21556. ? baseCreate(getPrototype(object))
  21557. : {};
  21558. }
  21559. /**
  21560. * Initializes an object clone based on its `toStringTag`.
  21561. *
  21562. * **Note:** This function only supports cloning values with tags of
  21563. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  21564. *
  21565. * @private
  21566. * @param {Object} object The object to clone.
  21567. * @param {string} tag The `toStringTag` of the object to clone.
  21568. * @param {Function} cloneFunc The function to clone values.
  21569. * @param {boolean} [isDeep] Specify a deep clone.
  21570. * @returns {Object} Returns the initialized clone.
  21571. */
  21572. function initCloneByTag(object, tag, cloneFunc, isDeep) {
  21573. var Ctor = object.constructor;
  21574. switch (tag) {
  21575. case arrayBufferTag:
  21576. return cloneArrayBuffer(object);
  21577. case boolTag:
  21578. case dateTag:
  21579. return new Ctor(+object);
  21580. case dataViewTag:
  21581. return cloneDataView(object, isDeep);
  21582. case float32Tag: case float64Tag:
  21583. case int8Tag: case int16Tag: case int32Tag:
  21584. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  21585. return cloneTypedArray(object, isDeep);
  21586. case mapTag:
  21587. return cloneMap(object, isDeep, cloneFunc);
  21588. case numberTag:
  21589. case stringTag:
  21590. return new Ctor(object);
  21591. case regexpTag:
  21592. return cloneRegExp(object);
  21593. case setTag:
  21594. return cloneSet(object, isDeep, cloneFunc);
  21595. case symbolTag:
  21596. return cloneSymbol(object);
  21597. }
  21598. }
  21599. /**
  21600. * Creates an array of index keys for `object` values of arrays,
  21601. * `arguments` objects, and strings, otherwise `null` is returned.
  21602. *
  21603. * @private
  21604. * @param {Object} object The object to query.
  21605. * @returns {Array|null} Returns index keys, else `null`.
  21606. */
  21607. function indexKeys(object) {
  21608. var length = object ? object.length : undefined;
  21609. if (isLength(length) &&
  21610. (isArray(object) || isString(object) || isArguments(object))) {
  21611. return baseTimes(length, String);
  21612. }
  21613. return null;
  21614. }
  21615. /**
  21616. * Checks if `value` is a flattenable `arguments` object or array.
  21617. *
  21618. * @private
  21619. * @param {*} value The value to check.
  21620. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  21621. */
  21622. function isFlattenable(value) {
  21623. return isArray(value) || isArguments(value);
  21624. }
  21625. /**
  21626. * Checks if `value` is a flattenable array and not a `_.matchesProperty`
  21627. * iteratee shorthand.
  21628. *
  21629. * @private
  21630. * @param {*} value The value to check.
  21631. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  21632. */
  21633. function isFlattenableIteratee(value) {
  21634. return isArray(value) && !(value.length == 2 && !isFunction(value[0]));
  21635. }
  21636. /**
  21637. * Checks if `value` is a valid array-like index.
  21638. *
  21639. * @private
  21640. * @param {*} value The value to check.
  21641. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  21642. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  21643. */
  21644. function isIndex(value, length) {
  21645. length = length == null ? MAX_SAFE_INTEGER : length;
  21646. return !!length &&
  21647. (typeof value == 'number' || reIsUint.test(value)) &&
  21648. (value > -1 && value % 1 == 0 && value < length);
  21649. }
  21650. /**
  21651. * Checks if the given arguments are from an iteratee call.
  21652. *
  21653. * @private
  21654. * @param {*} value The potential iteratee value argument.
  21655. * @param {*} index The potential iteratee index or key argument.
  21656. * @param {*} object The potential iteratee object argument.
  21657. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  21658. * else `false`.
  21659. */
  21660. function isIterateeCall(value, index, object) {
  21661. if (!isObject(object)) {
  21662. return false;
  21663. }
  21664. var type = typeof index;
  21665. if (type == 'number'
  21666. ? (isArrayLike(object) && isIndex(index, object.length))
  21667. : (type == 'string' && index in object)
  21668. ) {
  21669. return eq(object[index], value);
  21670. }
  21671. return false;
  21672. }
  21673. /**
  21674. * Checks if `value` is a property name and not a property path.
  21675. *
  21676. * @private
  21677. * @param {*} value The value to check.
  21678. * @param {Object} [object] The object to query keys on.
  21679. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  21680. */
  21681. function isKey(value, object) {
  21682. if (isArray(value)) {
  21683. return false;
  21684. }
  21685. var type = typeof value;
  21686. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  21687. value == null || isSymbol(value)) {
  21688. return true;
  21689. }
  21690. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  21691. (object != null && value in Object(object));
  21692. }
  21693. /**
  21694. * Checks if `value` is suitable for use as unique object key.
  21695. *
  21696. * @private
  21697. * @param {*} value The value to check.
  21698. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  21699. */
  21700. function isKeyable(value) {
  21701. var type = typeof value;
  21702. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  21703. ? (value !== '__proto__')
  21704. : (value === null);
  21705. }
  21706. /**
  21707. * Checks if `func` has a lazy counterpart.
  21708. *
  21709. * @private
  21710. * @param {Function} func The function to check.
  21711. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  21712. * else `false`.
  21713. */
  21714. function isLaziable(func) {
  21715. var funcName = getFuncName(func),
  21716. other = lodash[funcName];
  21717. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  21718. return false;
  21719. }
  21720. if (func === other) {
  21721. return true;
  21722. }
  21723. var data = getData(other);
  21724. return !!data && func === data[0];
  21725. }
  21726. /**
  21727. * Checks if `func` has its source masked.
  21728. *
  21729. * @private
  21730. * @param {Function} func The function to check.
  21731. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  21732. */
  21733. function isMasked(func) {
  21734. return !!maskSrcKey && (maskSrcKey in func);
  21735. }
  21736. /**
  21737. * Checks if `func` is capable of being masked.
  21738. *
  21739. * @private
  21740. * @param {*} value The value to check.
  21741. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  21742. */
  21743. var isMaskable = coreJsData ? isFunction : stubFalse;
  21744. /**
  21745. * Checks if `value` is likely a prototype object.
  21746. *
  21747. * @private
  21748. * @param {*} value The value to check.
  21749. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  21750. */
  21751. function isPrototype(value) {
  21752. var Ctor = value && value.constructor,
  21753. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  21754. return value === proto;
  21755. }
  21756. /**
  21757. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  21758. *
  21759. * @private
  21760. * @param {*} value The value to check.
  21761. * @returns {boolean} Returns `true` if `value` if suitable for strict
  21762. * equality comparisons, else `false`.
  21763. */
  21764. function isStrictComparable(value) {
  21765. return value === value && !isObject(value);
  21766. }
  21767. /**
  21768. * A specialized version of `matchesProperty` for source values suitable
  21769. * for strict equality comparisons, i.e. `===`.
  21770. *
  21771. * @private
  21772. * @param {string} key The key of the property to get.
  21773. * @param {*} srcValue The value to match.
  21774. * @returns {Function} Returns the new spec function.
  21775. */
  21776. function matchesStrictComparable(key, srcValue) {
  21777. return function(object) {
  21778. if (object == null) {
  21779. return false;
  21780. }
  21781. return object[key] === srcValue &&
  21782. (srcValue !== undefined || (key in Object(object)));
  21783. };
  21784. }
  21785. /**
  21786. * Merges the function metadata of `source` into `data`.
  21787. *
  21788. * Merging metadata reduces the number of wrappers used to invoke a function.
  21789. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  21790. * may be applied regardless of execution order. Methods like `_.ary` and
  21791. * `_.rearg` modify function arguments, making the order in which they are
  21792. * executed important, preventing the merging of metadata. However, we make
  21793. * an exception for a safe combined case where curried functions have `_.ary`
  21794. * and or `_.rearg` applied.
  21795. *
  21796. * @private
  21797. * @param {Array} data The destination metadata.
  21798. * @param {Array} source The source metadata.
  21799. * @returns {Array} Returns `data`.
  21800. */
  21801. function mergeData(data, source) {
  21802. var bitmask = data[1],
  21803. srcBitmask = source[1],
  21804. newBitmask = bitmask | srcBitmask,
  21805. isCommon = newBitmask < (BIND_FLAG | BIND_KEY_FLAG | ARY_FLAG);
  21806. var isCombo =
  21807. ((srcBitmask == ARY_FLAG) && (bitmask == CURRY_FLAG)) ||
  21808. ((srcBitmask == ARY_FLAG) && (bitmask == REARG_FLAG) && (data[7].length <= source[8])) ||
  21809. ((srcBitmask == (ARY_FLAG | REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == CURRY_FLAG));
  21810. // Exit early if metadata can't be merged.
  21811. if (!(isCommon || isCombo)) {
  21812. return data;
  21813. }
  21814. // Use source `thisArg` if available.
  21815. if (srcBitmask & BIND_FLAG) {
  21816. data[2] = source[2];
  21817. // Set when currying a bound function.
  21818. newBitmask |= bitmask & BIND_FLAG ? 0 : CURRY_BOUND_FLAG;
  21819. }
  21820. // Compose partial arguments.
  21821. var value = source[3];
  21822. if (value) {
  21823. var partials = data[3];
  21824. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  21825. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  21826. }
  21827. // Compose partial right arguments.
  21828. value = source[5];
  21829. if (value) {
  21830. partials = data[5];
  21831. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  21832. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  21833. }
  21834. // Use source `argPos` if available.
  21835. value = source[7];
  21836. if (value) {
  21837. data[7] = value;
  21838. }
  21839. // Use source `ary` if it's smaller.
  21840. if (srcBitmask & ARY_FLAG) {
  21841. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  21842. }
  21843. // Use source `arity` if one is not provided.
  21844. if (data[9] == null) {
  21845. data[9] = source[9];
  21846. }
  21847. // Use source `func` and merge bitmasks.
  21848. data[0] = source[0];
  21849. data[1] = newBitmask;
  21850. return data;
  21851. }
  21852. /**
  21853. * Used by `_.defaultsDeep` to customize its `_.merge` use.
  21854. *
  21855. * @private
  21856. * @param {*} objValue The destination value.
  21857. * @param {*} srcValue The source value.
  21858. * @param {string} key The key of the property to merge.
  21859. * @param {Object} object The parent object of `objValue`.
  21860. * @param {Object} source The parent object of `srcValue`.
  21861. * @param {Object} [stack] Tracks traversed source values and their merged
  21862. * counterparts.
  21863. * @returns {*} Returns the value to assign.
  21864. */
  21865. function mergeDefaults(objValue, srcValue, key, object, source, stack) {
  21866. if (isObject(objValue) && isObject(srcValue)) {
  21867. baseMerge(objValue, srcValue, undefined, mergeDefaults, stack.set(srcValue, objValue));
  21868. }
  21869. return objValue;
  21870. }
  21871. /**
  21872. * Gets the parent value at `path` of `object`.
  21873. *
  21874. * @private
  21875. * @param {Object} object The object to query.
  21876. * @param {Array} path The path to get the parent value of.
  21877. * @returns {*} Returns the parent value.
  21878. */
  21879. function parent(object, path) {
  21880. return path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  21881. }
  21882. /**
  21883. * Reorder `array` according to the specified indexes where the element at
  21884. * the first index is assigned as the first element, the element at
  21885. * the second index is assigned as the second element, and so on.
  21886. *
  21887. * @private
  21888. * @param {Array} array The array to reorder.
  21889. * @param {Array} indexes The arranged array indexes.
  21890. * @returns {Array} Returns `array`.
  21891. */
  21892. function reorder(array, indexes) {
  21893. var arrLength = array.length,
  21894. length = nativeMin(indexes.length, arrLength),
  21895. oldArray = copyArray(array);
  21896. while (length--) {
  21897. var index = indexes[length];
  21898. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  21899. }
  21900. return array;
  21901. }
  21902. /**
  21903. * Sets metadata for `func`.
  21904. *
  21905. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  21906. * period of time, it will trip its breaker and transition to an identity
  21907. * function to avoid garbage collection pauses in V8. See
  21908. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  21909. * for more details.
  21910. *
  21911. * @private
  21912. * @param {Function} func The function to associate metadata with.
  21913. * @param {*} data The metadata.
  21914. * @returns {Function} Returns `func`.
  21915. */
  21916. var setData = (function() {
  21917. var count = 0,
  21918. lastCalled = 0;
  21919. return function(key, value) {
  21920. var stamp = now(),
  21921. remaining = HOT_SPAN - (stamp - lastCalled);
  21922. lastCalled = stamp;
  21923. if (remaining > 0) {
  21924. if (++count >= HOT_COUNT) {
  21925. return key;
  21926. }
  21927. } else {
  21928. count = 0;
  21929. }
  21930. return baseSetData(key, value);
  21931. };
  21932. }());
  21933. /**
  21934. * Converts `string` to a property path array.
  21935. *
  21936. * @private
  21937. * @param {string} string The string to convert.
  21938. * @returns {Array} Returns the property path array.
  21939. */
  21940. var stringToPath = memoize(function(string) {
  21941. var result = [];
  21942. toString(string).replace(rePropName, function(match, number, quote, string) {
  21943. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  21944. });
  21945. return result;
  21946. });
  21947. /**
  21948. * Converts `value` to a string key if it's not a string or symbol.
  21949. *
  21950. * @private
  21951. * @param {*} value The value to inspect.
  21952. * @returns {string|symbol} Returns the key.
  21953. */
  21954. function toKey(value) {
  21955. if (typeof value == 'string' || isSymbol(value)) {
  21956. return value;
  21957. }
  21958. var result = (value + '');
  21959. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  21960. }
  21961. /**
  21962. * Converts `func` to its source code.
  21963. *
  21964. * @private
  21965. * @param {Function} func The function to process.
  21966. * @returns {string} Returns the source code.
  21967. */
  21968. function toSource(func) {
  21969. if (func != null) {
  21970. try {
  21971. return funcToString.call(func);
  21972. } catch (e) {}
  21973. try {
  21974. return (func + '');
  21975. } catch (e) {}
  21976. }
  21977. return '';
  21978. }
  21979. /**
  21980. * Creates a clone of `wrapper`.
  21981. *
  21982. * @private
  21983. * @param {Object} wrapper The wrapper to clone.
  21984. * @returns {Object} Returns the cloned wrapper.
  21985. */
  21986. function wrapperClone(wrapper) {
  21987. if (wrapper instanceof LazyWrapper) {
  21988. return wrapper.clone();
  21989. }
  21990. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  21991. result.__actions__ = copyArray(wrapper.__actions__);
  21992. result.__index__ = wrapper.__index__;
  21993. result.__values__ = wrapper.__values__;
  21994. return result;
  21995. }
  21996. /*------------------------------------------------------------------------*/
  21997. /**
  21998. * Creates an array of elements split into groups the length of `size`.
  21999. * If `array` can't be split evenly, the final chunk will be the remaining
  22000. * elements.
  22001. *
  22002. * @static
  22003. * @memberOf _
  22004. * @since 3.0.0
  22005. * @category Array
  22006. * @param {Array} array The array to process.
  22007. * @param {number} [size=1] The length of each chunk
  22008. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  22009. * @returns {Array} Returns the new array of chunks.
  22010. * @example
  22011. *
  22012. * _.chunk(['a', 'b', 'c', 'd'], 2);
  22013. * // => [['a', 'b'], ['c', 'd']]
  22014. *
  22015. * _.chunk(['a', 'b', 'c', 'd'], 3);
  22016. * // => [['a', 'b', 'c'], ['d']]
  22017. */
  22018. function chunk(array, size, guard) {
  22019. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  22020. size = 1;
  22021. } else {
  22022. size = nativeMax(toInteger(size), 0);
  22023. }
  22024. var length = array ? array.length : 0;
  22025. if (!length || size < 1) {
  22026. return [];
  22027. }
  22028. var index = 0,
  22029. resIndex = 0,
  22030. result = Array(nativeCeil(length / size));
  22031. while (index < length) {
  22032. result[resIndex++] = baseSlice(array, index, (index += size));
  22033. }
  22034. return result;
  22035. }
  22036. /**
  22037. * Creates an array with all falsey values removed. The values `false`, `null`,
  22038. * `0`, `""`, `undefined`, and `NaN` are falsey.
  22039. *
  22040. * @static
  22041. * @memberOf _
  22042. * @since 0.1.0
  22043. * @category Array
  22044. * @param {Array} array The array to compact.
  22045. * @returns {Array} Returns the new array of filtered values.
  22046. * @example
  22047. *
  22048. * _.compact([0, 1, false, 2, '', 3]);
  22049. * // => [1, 2, 3]
  22050. */
  22051. function compact(array) {
  22052. var index = -1,
  22053. length = array ? array.length : 0,
  22054. resIndex = 0,
  22055. result = [];
  22056. while (++index < length) {
  22057. var value = array[index];
  22058. if (value) {
  22059. result[resIndex++] = value;
  22060. }
  22061. }
  22062. return result;
  22063. }
  22064. /**
  22065. * Creates a new array concatenating `array` with any additional arrays
  22066. * and/or values.
  22067. *
  22068. * @static
  22069. * @memberOf _
  22070. * @since 4.0.0
  22071. * @category Array
  22072. * @param {Array} array The array to concatenate.
  22073. * @param {...*} [values] The values to concatenate.
  22074. * @returns {Array} Returns the new concatenated array.
  22075. * @example
  22076. *
  22077. * var array = [1];
  22078. * var other = _.concat(array, 2, [3], [[4]]);
  22079. *
  22080. * console.log(other);
  22081. * // => [1, 2, 3, [4]]
  22082. *
  22083. * console.log(array);
  22084. * // => [1]
  22085. */
  22086. function concat() {
  22087. var length = arguments.length,
  22088. args = Array(length ? length - 1 : 0),
  22089. array = arguments[0],
  22090. index = length;
  22091. while (index--) {
  22092. args[index - 1] = arguments[index];
  22093. }
  22094. return length
  22095. ? arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1))
  22096. : [];
  22097. }
  22098. /**
  22099. * Creates an array of unique `array` values not included in the other given
  22100. * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  22101. * for equality comparisons. The order of result values is determined by the
  22102. * order they occur in the first array.
  22103. *
  22104. * @static
  22105. * @memberOf _
  22106. * @since 0.1.0
  22107. * @category Array
  22108. * @param {Array} array The array to inspect.
  22109. * @param {...Array} [values] The values to exclude.
  22110. * @returns {Array} Returns the new array of filtered values.
  22111. * @see _.without, _.xor
  22112. * @example
  22113. *
  22114. * _.difference([2, 1], [2, 3]);
  22115. * // => [1]
  22116. */
  22117. var difference = rest(function(array, values) {
  22118. return isArrayLikeObject(array)
  22119. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  22120. : [];
  22121. });
  22122. /**
  22123. * This method is like `_.difference` except that it accepts `iteratee` which
  22124. * is invoked for each element of `array` and `values` to generate the criterion
  22125. * by which they're compared. Result values are chosen from the first array.
  22126. * The iteratee is invoked with one argument: (value).
  22127. *
  22128. * @static
  22129. * @memberOf _
  22130. * @since 4.0.0
  22131. * @category Array
  22132. * @param {Array} array The array to inspect.
  22133. * @param {...Array} [values] The values to exclude.
  22134. * @param {Array|Function|Object|string} [iteratee=_.identity]
  22135. * The iteratee invoked per element.
  22136. * @returns {Array} Returns the new array of filtered values.
  22137. * @example
  22138. *
  22139. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  22140. * // => [1.2]
  22141. *
  22142. * // The `_.property` iteratee shorthand.
  22143. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  22144. * // => [{ 'x': 2 }]
  22145. */
  22146. var differenceBy = rest(function(array, values) {
  22147. var iteratee = last(values);
  22148. if (isArrayLikeObject(iteratee)) {
  22149. iteratee = undefined;
  22150. }
  22151. return isArrayLikeObject(array)
  22152. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee))
  22153. : [];
  22154. });
  22155. /**
  22156. * This method is like `_.difference` except that it accepts `comparator`
  22157. * which is invoked to compare elements of `array` to `values`. Result values
  22158. * are chosen from the first array. The comparator is invoked with two arguments:
  22159. * (arrVal, othVal).
  22160. *
  22161. * @static
  22162. * @memberOf _
  22163. * @since 4.0.0
  22164. * @category Array
  22165. * @param {Array} array The array to inspect.
  22166. * @param {...Array} [values] The values to exclude.
  22167. * @param {Function} [comparator] The comparator invoked per element.
  22168. * @returns {Array} Returns the new array of filtered values.
  22169. * @example
  22170. *
  22171. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  22172. *
  22173. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  22174. * // => [{ 'x': 2, 'y': 1 }]
  22175. */
  22176. var differenceWith = rest(function(array, values) {
  22177. var comparator = last(values);
  22178. if (isArrayLikeObject(comparator)) {
  22179. comparator = undefined;
  22180. }
  22181. return isArrayLikeObject(array)
  22182. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  22183. : [];
  22184. });
  22185. /**
  22186. * Creates a slice of `array` with `n` elements dropped from the beginning.
  22187. *
  22188. * @static
  22189. * @memberOf _
  22190. * @since 0.5.0
  22191. * @category Array
  22192. * @param {Array} array The array to query.
  22193. * @param {number} [n=1] The number of elements to drop.
  22194. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  22195. * @returns {Array} Returns the slice of `array`.
  22196. * @example
  22197. *
  22198. * _.drop([1, 2, 3]);
  22199. * // => [2, 3]
  22200. *
  22201. * _.drop([1, 2, 3], 2);
  22202. * // => [3]
  22203. *
  22204. * _.drop([1, 2, 3], 5);
  22205. * // => []
  22206. *
  22207. * _.drop([1, 2, 3], 0);
  22208. * // => [1, 2, 3]
  22209. */
  22210. function drop(array, n, guard) {
  22211. var length = array ? array.length : 0;
  22212. if (!length) {
  22213. return [];
  22214. }
  22215. n = (guard || n === undefined) ? 1 : toInteger(n);
  22216. return baseSlice(array, n < 0 ? 0 : n, length);
  22217. }
  22218. /**
  22219. * Creates a slice of `array` with `n` elements dropped from the end.
  22220. *
  22221. * @static
  22222. * @memberOf _
  22223. * @since 3.0.0
  22224. * @category Array
  22225. * @param {Array} array The array to query.
  22226. * @param {number} [n=1] The number of elements to drop.
  22227. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  22228. * @returns {Array} Returns the slice of `array`.
  22229. * @example
  22230. *
  22231. * _.dropRight([1, 2, 3]);
  22232. * // => [1, 2]
  22233. *
  22234. * _.dropRight([1, 2, 3], 2);
  22235. * // => [1]
  22236. *
  22237. * _.dropRight([1, 2, 3], 5);
  22238. * // => []
  22239. *
  22240. * _.dropRight([1, 2, 3], 0);
  22241. * // => [1, 2, 3]
  22242. */
  22243. function dropRight(array, n, guard) {
  22244. var length = array ? array.length : 0;
  22245. if (!length) {
  22246. return [];
  22247. }
  22248. n = (guard || n === undefined) ? 1 : toInteger(n);
  22249. n = length - n;
  22250. return baseSlice(array, 0, n < 0 ? 0 : n);
  22251. }
  22252. /**
  22253. * Creates a slice of `array` excluding elements dropped from the end.
  22254. * Elements are dropped until `predicate` returns falsey. The predicate is
  22255. * invoked with three arguments: (value, index, array).
  22256. *
  22257. * @static
  22258. * @memberOf _
  22259. * @since 3.0.0
  22260. * @category Array
  22261. * @param {Array} array The array to query.
  22262. * @param {Array|Function|Object|string} [predicate=_.identity]
  22263. * The function invoked per iteration.
  22264. * @returns {Array} Returns the slice of `array`.
  22265. * @example
  22266. *
  22267. * var users = [
  22268. * { 'user': 'barney', 'active': true },
  22269. * { 'user': 'fred', 'active': false },
  22270. * { 'user': 'pebbles', 'active': false }
  22271. * ];
  22272. *
  22273. * _.dropRightWhile(users, function(o) { return !o.active; });
  22274. * // => objects for ['barney']
  22275. *
  22276. * // The `_.matches` iteratee shorthand.
  22277. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  22278. * // => objects for ['barney', 'fred']
  22279. *
  22280. * // The `_.matchesProperty` iteratee shorthand.
  22281. * _.dropRightWhile(users, ['active', false]);
  22282. * // => objects for ['barney']
  22283. *
  22284. * // The `_.property` iteratee shorthand.
  22285. * _.dropRightWhile(users, 'active');
  22286. * // => objects for ['barney', 'fred', 'pebbles']
  22287. */
  22288. function dropRightWhile(array, predicate) {
  22289. return (array && array.length)
  22290. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  22291. : [];
  22292. }
  22293. /**
  22294. * Creates a slice of `array` excluding elements dropped from the beginning.
  22295. * Elements are dropped until `predicate` returns falsey. The predicate is
  22296. * invoked with three arguments: (value, index, array).
  22297. *
  22298. * @static
  22299. * @memberOf _
  22300. * @since 3.0.0
  22301. * @category Array
  22302. * @param {Array} array The array to query.
  22303. * @param {Array|Function|Object|string} [predicate=_.identity]
  22304. * The function invoked per iteration.
  22305. * @returns {Array} Returns the slice of `array`.
  22306. * @example
  22307. *
  22308. * var users = [
  22309. * { 'user': 'barney', 'active': false },
  22310. * { 'user': 'fred', 'active': false },
  22311. * { 'user': 'pebbles', 'active': true }
  22312. * ];
  22313. *
  22314. * _.dropWhile(users, function(o) { return !o.active; });
  22315. * // => objects for ['pebbles']
  22316. *
  22317. * // The `_.matches` iteratee shorthand.
  22318. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  22319. * // => objects for ['fred', 'pebbles']
  22320. *
  22321. * // The `_.matchesProperty` iteratee shorthand.
  22322. * _.dropWhile(users, ['active', false]);
  22323. * // => objects for ['pebbles']
  22324. *
  22325. * // The `_.property` iteratee shorthand.
  22326. * _.dropWhile(users, 'active');
  22327. * // => objects for ['barney', 'fred', 'pebbles']
  22328. */
  22329. function dropWhile(array, predicate) {
  22330. return (array && array.length)
  22331. ? baseWhile(array, getIteratee(predicate, 3), true)
  22332. : [];
  22333. }
  22334. /**
  22335. * Fills elements of `array` with `value` from `start` up to, but not
  22336. * including, `end`.
  22337. *
  22338. * **Note:** This method mutates `array`.
  22339. *
  22340. * @static
  22341. * @memberOf _
  22342. * @since 3.2.0
  22343. * @category Array
  22344. * @param {Array} array The array to fill.
  22345. * @param {*} value The value to fill `array` with.
  22346. * @param {number} [start=0] The start position.
  22347. * @param {number} [end=array.length] The end position.
  22348. * @returns {Array} Returns `array`.
  22349. * @example
  22350. *
  22351. * var array = [1, 2, 3];
  22352. *
  22353. * _.fill(array, 'a');
  22354. * console.log(array);
  22355. * // => ['a', 'a', 'a']
  22356. *
  22357. * _.fill(Array(3), 2);
  22358. * // => [2, 2, 2]
  22359. *
  22360. * _.fill([4, 6, 8, 10], '*', 1, 3);
  22361. * // => [4, '*', '*', 10]
  22362. */
  22363. function fill(array, value, start, end) {
  22364. var length = array ? array.length : 0;
  22365. if (!length) {
  22366. return [];
  22367. }
  22368. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  22369. start = 0;
  22370. end = length;
  22371. }
  22372. return baseFill(array, value, start, end);
  22373. }
  22374. /**
  22375. * This method is like `_.find` except that it returns the index of the first
  22376. * element `predicate` returns truthy for instead of the element itself.
  22377. *
  22378. * @static
  22379. * @memberOf _
  22380. * @since 1.1.0
  22381. * @category Array
  22382. * @param {Array} array The array to search.
  22383. * @param {Array|Function|Object|string} [predicate=_.identity]
  22384. * The function invoked per iteration.
  22385. * @param {number} [fromIndex=0] The index to search from.
  22386. * @returns {number} Returns the index of the found element, else `-1`.
  22387. * @example
  22388. *
  22389. * var users = [
  22390. * { 'user': 'barney', 'active': false },
  22391. * { 'user': 'fred', 'active': false },
  22392. * { 'user': 'pebbles', 'active': true }
  22393. * ];
  22394. *
  22395. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  22396. * // => 0
  22397. *
  22398. * // The `_.matches` iteratee shorthand.
  22399. * _.findIndex(users, { 'user': 'fred', 'active': false });
  22400. * // => 1
  22401. *
  22402. * // The `_.matchesProperty` iteratee shorthand.
  22403. * _.findIndex(users, ['active', false]);
  22404. * // => 0
  22405. *
  22406. * // The `_.property` iteratee shorthand.
  22407. * _.findIndex(users, 'active');
  22408. * // => 2
  22409. */
  22410. function findIndex(array, predicate, fromIndex) {
  22411. var length = array ? array.length : 0;
  22412. if (!length) {
  22413. return -1;
  22414. }
  22415. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  22416. if (index < 0) {
  22417. index = nativeMax(length + index, 0);
  22418. }
  22419. return baseFindIndex(array, getIteratee(predicate, 3), index);
  22420. }
  22421. /**
  22422. * This method is like `_.findIndex` except that it iterates over elements
  22423. * of `collection` from right to left.
  22424. *
  22425. * @static
  22426. * @memberOf _
  22427. * @since 2.0.0
  22428. * @category Array
  22429. * @param {Array} array The array to search.
  22430. * @param {Array|Function|Object|string} [predicate=_.identity]
  22431. * The function invoked per iteration.
  22432. * @param {number} [fromIndex=array.length-1] The index to search from.
  22433. * @returns {number} Returns the index of the found element, else `-1`.
  22434. * @example
  22435. *
  22436. * var users = [
  22437. * { 'user': 'barney', 'active': true },
  22438. * { 'user': 'fred', 'active': false },
  22439. * { 'user': 'pebbles', 'active': false }
  22440. * ];
  22441. *
  22442. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  22443. * // => 2
  22444. *
  22445. * // The `_.matches` iteratee shorthand.
  22446. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  22447. * // => 0
  22448. *
  22449. * // The `_.matchesProperty` iteratee shorthand.
  22450. * _.findLastIndex(users, ['active', false]);
  22451. * // => 2
  22452. *
  22453. * // The `_.property` iteratee shorthand.
  22454. * _.findLastIndex(users, 'active');
  22455. * // => 0
  22456. */
  22457. function findLastIndex(array, predicate, fromIndex) {
  22458. var length = array ? array.length : 0;
  22459. if (!length) {
  22460. return -1;
  22461. }
  22462. var index = length - 1;
  22463. if (fromIndex !== undefined) {
  22464. index = toInteger(fromIndex);
  22465. index = fromIndex < 0
  22466. ? nativeMax(length + index, 0)
  22467. : nativeMin(index, length - 1);
  22468. }
  22469. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  22470. }
  22471. /**
  22472. * Flattens `array` a single level deep.
  22473. *
  22474. * @static
  22475. * @memberOf _
  22476. * @since 0.1.0
  22477. * @category Array
  22478. * @param {Array} array The array to flatten.
  22479. * @returns {Array} Returns the new flattened array.
  22480. * @example
  22481. *
  22482. * _.flatten([1, [2, [3, [4]], 5]]);
  22483. * // => [1, 2, [3, [4]], 5]
  22484. */
  22485. function flatten(array) {
  22486. var length = array ? array.length : 0;
  22487. return length ? baseFlatten(array, 1) : [];
  22488. }
  22489. /**
  22490. * Recursively flattens `array`.
  22491. *
  22492. * @static
  22493. * @memberOf _
  22494. * @since 3.0.0
  22495. * @category Array
  22496. * @param {Array} array The array to flatten.
  22497. * @returns {Array} Returns the new flattened array.
  22498. * @example
  22499. *
  22500. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  22501. * // => [1, 2, 3, 4, 5]
  22502. */
  22503. function flattenDeep(array) {
  22504. var length = array ? array.length : 0;
  22505. return length ? baseFlatten(array, INFINITY) : [];
  22506. }
  22507. /**
  22508. * Recursively flatten `array` up to `depth` times.
  22509. *
  22510. * @static
  22511. * @memberOf _
  22512. * @since 4.4.0
  22513. * @category Array
  22514. * @param {Array} array The array to flatten.
  22515. * @param {number} [depth=1] The maximum recursion depth.
  22516. * @returns {Array} Returns the new flattened array.
  22517. * @example
  22518. *
  22519. * var array = [1, [2, [3, [4]], 5]];
  22520. *
  22521. * _.flattenDepth(array, 1);
  22522. * // => [1, 2, [3, [4]], 5]
  22523. *
  22524. * _.flattenDepth(array, 2);
  22525. * // => [1, 2, 3, [4], 5]
  22526. */
  22527. function flattenDepth(array, depth) {
  22528. var length = array ? array.length : 0;
  22529. if (!length) {
  22530. return [];
  22531. }
  22532. depth = depth === undefined ? 1 : toInteger(depth);
  22533. return baseFlatten(array, depth);
  22534. }
  22535. /**
  22536. * The inverse of `_.toPairs`; this method returns an object composed
  22537. * from key-value `pairs`.
  22538. *
  22539. * @static
  22540. * @memberOf _
  22541. * @since 4.0.0
  22542. * @category Array
  22543. * @param {Array} pairs The key-value pairs.
  22544. * @returns {Object} Returns the new object.
  22545. * @example
  22546. *
  22547. * _.fromPairs([['fred', 30], ['barney', 40]]);
  22548. * // => { 'fred': 30, 'barney': 40 }
  22549. */
  22550. function fromPairs(pairs) {
  22551. var index = -1,
  22552. length = pairs ? pairs.length : 0,
  22553. result = {};
  22554. while (++index < length) {
  22555. var pair = pairs[index];
  22556. result[pair[0]] = pair[1];
  22557. }
  22558. return result;
  22559. }
  22560. /**
  22561. * Gets the first element of `array`.
  22562. *
  22563. * @static
  22564. * @memberOf _
  22565. * @since 0.1.0
  22566. * @alias first
  22567. * @category Array
  22568. * @param {Array} array The array to query.
  22569. * @returns {*} Returns the first element of `array`.
  22570. * @example
  22571. *
  22572. * _.head([1, 2, 3]);
  22573. * // => 1
  22574. *
  22575. * _.head([]);
  22576. * // => undefined
  22577. */
  22578. function head(array) {
  22579. return (array && array.length) ? array[0] : undefined;
  22580. }
  22581. /**
  22582. * Gets the index at which the first occurrence of `value` is found in `array`
  22583. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  22584. * for equality comparisons. If `fromIndex` is negative, it's used as the
  22585. * offset from the end of `array`.
  22586. *
  22587. * @static
  22588. * @memberOf _
  22589. * @since 0.1.0
  22590. * @category Array
  22591. * @param {Array} array The array to search.
  22592. * @param {*} value The value to search for.
  22593. * @param {number} [fromIndex=0] The index to search from.
  22594. * @returns {number} Returns the index of the matched value, else `-1`.
  22595. * @example
  22596. *
  22597. * _.indexOf([1, 2, 1, 2], 2);
  22598. * // => 1
  22599. *
  22600. * // Search from the `fromIndex`.
  22601. * _.indexOf([1, 2, 1, 2], 2, 2);
  22602. * // => 3
  22603. */
  22604. function indexOf(array, value, fromIndex) {
  22605. var length = array ? array.length : 0;
  22606. if (!length) {
  22607. return -1;
  22608. }
  22609. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  22610. if (index < 0) {
  22611. index = nativeMax(length + index, 0);
  22612. }
  22613. return baseIndexOf(array, value, index);
  22614. }
  22615. /**
  22616. * Gets all but the last element of `array`.
  22617. *
  22618. * @static
  22619. * @memberOf _
  22620. * @since 0.1.0
  22621. * @category Array
  22622. * @param {Array} array The array to query.
  22623. * @returns {Array} Returns the slice of `array`.
  22624. * @example
  22625. *
  22626. * _.initial([1, 2, 3]);
  22627. * // => [1, 2]
  22628. */
  22629. function initial(array) {
  22630. return dropRight(array, 1);
  22631. }
  22632. /**
  22633. * Creates an array of unique values that are included in all given arrays
  22634. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  22635. * for equality comparisons. The order of result values is determined by the
  22636. * order they occur in the first array.
  22637. *
  22638. * @static
  22639. * @memberOf _
  22640. * @since 0.1.0
  22641. * @category Array
  22642. * @param {...Array} [arrays] The arrays to inspect.
  22643. * @returns {Array} Returns the new array of intersecting values.
  22644. * @example
  22645. *
  22646. * _.intersection([2, 1], [2, 3]);
  22647. * // => [2]
  22648. */
  22649. var intersection = rest(function(arrays) {
  22650. var mapped = arrayMap(arrays, castArrayLikeObject);
  22651. return (mapped.length && mapped[0] === arrays[0])
  22652. ? baseIntersection(mapped)
  22653. : [];
  22654. });
  22655. /**
  22656. * This method is like `_.intersection` except that it accepts `iteratee`
  22657. * which is invoked for each element of each `arrays` to generate the criterion
  22658. * by which they're compared. Result values are chosen from the first array.
  22659. * The iteratee is invoked with one argument: (value).
  22660. *
  22661. * @static
  22662. * @memberOf _
  22663. * @since 4.0.0
  22664. * @category Array
  22665. * @param {...Array} [arrays] The arrays to inspect.
  22666. * @param {Array|Function|Object|string} [iteratee=_.identity]
  22667. * The iteratee invoked per element.
  22668. * @returns {Array} Returns the new array of intersecting values.
  22669. * @example
  22670. *
  22671. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  22672. * // => [2.1]
  22673. *
  22674. * // The `_.property` iteratee shorthand.
  22675. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  22676. * // => [{ 'x': 1 }]
  22677. */
  22678. var intersectionBy = rest(function(arrays) {
  22679. var iteratee = last(arrays),
  22680. mapped = arrayMap(arrays, castArrayLikeObject);
  22681. if (iteratee === last(mapped)) {
  22682. iteratee = undefined;
  22683. } else {
  22684. mapped.pop();
  22685. }
  22686. return (mapped.length && mapped[0] === arrays[0])
  22687. ? baseIntersection(mapped, getIteratee(iteratee))
  22688. : [];
  22689. });
  22690. /**
  22691. * This method is like `_.intersection` except that it accepts `comparator`
  22692. * which is invoked to compare elements of `arrays`. Result values are chosen
  22693. * from the first array. The comparator is invoked with two arguments:
  22694. * (arrVal, othVal).
  22695. *
  22696. * @static
  22697. * @memberOf _
  22698. * @since 4.0.0
  22699. * @category Array
  22700. * @param {...Array} [arrays] The arrays to inspect.
  22701. * @param {Function} [comparator] The comparator invoked per element.
  22702. * @returns {Array} Returns the new array of intersecting values.
  22703. * @example
  22704. *
  22705. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  22706. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  22707. *
  22708. * _.intersectionWith(objects, others, _.isEqual);
  22709. * // => [{ 'x': 1, 'y': 2 }]
  22710. */
  22711. var intersectionWith = rest(function(arrays) {
  22712. var comparator = last(arrays),
  22713. mapped = arrayMap(arrays, castArrayLikeObject);
  22714. if (comparator === last(mapped)) {
  22715. comparator = undefined;
  22716. } else {
  22717. mapped.pop();
  22718. }
  22719. return (mapped.length && mapped[0] === arrays[0])
  22720. ? baseIntersection(mapped, undefined, comparator)
  22721. : [];
  22722. });
  22723. /**
  22724. * Converts all elements in `array` into a string separated by `separator`.
  22725. *
  22726. * @static
  22727. * @memberOf _
  22728. * @since 4.0.0
  22729. * @category Array
  22730. * @param {Array} array The array to convert.
  22731. * @param {string} [separator=','] The element separator.
  22732. * @returns {string} Returns the joined string.
  22733. * @example
  22734. *
  22735. * _.join(['a', 'b', 'c'], '~');
  22736. * // => 'a~b~c'
  22737. */
  22738. function join(array, separator) {
  22739. return array ? nativeJoin.call(array, separator) : '';
  22740. }
  22741. /**
  22742. * Gets the last element of `array`.
  22743. *
  22744. * @static
  22745. * @memberOf _
  22746. * @since 0.1.0
  22747. * @category Array
  22748. * @param {Array} array The array to query.
  22749. * @returns {*} Returns the last element of `array`.
  22750. * @example
  22751. *
  22752. * _.last([1, 2, 3]);
  22753. * // => 3
  22754. */
  22755. function last(array) {
  22756. var length = array ? array.length : 0;
  22757. return length ? array[length - 1] : undefined;
  22758. }
  22759. /**
  22760. * This method is like `_.indexOf` except that it iterates over elements of
  22761. * `array` from right to left.
  22762. *
  22763. * @static
  22764. * @memberOf _
  22765. * @since 0.1.0
  22766. * @category Array
  22767. * @param {Array} array The array to search.
  22768. * @param {*} value The value to search for.
  22769. * @param {number} [fromIndex=array.length-1] The index to search from.
  22770. * @returns {number} Returns the index of the matched value, else `-1`.
  22771. * @example
  22772. *
  22773. * _.lastIndexOf([1, 2, 1, 2], 2);
  22774. * // => 3
  22775. *
  22776. * // Search from the `fromIndex`.
  22777. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  22778. * // => 1
  22779. */
  22780. function lastIndexOf(array, value, fromIndex) {
  22781. var length = array ? array.length : 0;
  22782. if (!length) {
  22783. return -1;
  22784. }
  22785. var index = length;
  22786. if (fromIndex !== undefined) {
  22787. index = toInteger(fromIndex);
  22788. index = (
  22789. index < 0
  22790. ? nativeMax(length + index, 0)
  22791. : nativeMin(index, length - 1)
  22792. ) + 1;
  22793. }
  22794. if (value !== value) {
  22795. return indexOfNaN(array, index - 1, true);
  22796. }
  22797. while (index--) {
  22798. if (array[index] === value) {
  22799. return index;
  22800. }
  22801. }
  22802. return -1;
  22803. }
  22804. /**
  22805. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  22806. * element from the end is returned.
  22807. *
  22808. * @static
  22809. * @memberOf _
  22810. * @since 4.11.0
  22811. * @category Array
  22812. * @param {Array} array The array to query.
  22813. * @param {number} [n=0] The index of the element to return.
  22814. * @returns {*} Returns the nth element of `array`.
  22815. * @example
  22816. *
  22817. * var array = ['a', 'b', 'c', 'd'];
  22818. *
  22819. * _.nth(array, 1);
  22820. * // => 'b'
  22821. *
  22822. * _.nth(array, -2);
  22823. * // => 'c';
  22824. */
  22825. function nth(array, n) {
  22826. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  22827. }
  22828. /**
  22829. * Removes all given values from `array` using
  22830. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  22831. * for equality comparisons.
  22832. *
  22833. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  22834. * to remove elements from an array by predicate.
  22835. *
  22836. * @static
  22837. * @memberOf _
  22838. * @since 2.0.0
  22839. * @category Array
  22840. * @param {Array} array The array to modify.
  22841. * @param {...*} [values] The values to remove.
  22842. * @returns {Array} Returns `array`.
  22843. * @example
  22844. *
  22845. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  22846. *
  22847. * _.pull(array, 'a', 'c');
  22848. * console.log(array);
  22849. * // => ['b', 'b']
  22850. */
  22851. var pull = rest(pullAll);
  22852. /**
  22853. * This method is like `_.pull` except that it accepts an array of values to remove.
  22854. *
  22855. * **Note:** Unlike `_.difference`, this method mutates `array`.
  22856. *
  22857. * @static
  22858. * @memberOf _
  22859. * @since 4.0.0
  22860. * @category Array
  22861. * @param {Array} array The array to modify.
  22862. * @param {Array} values The values to remove.
  22863. * @returns {Array} Returns `array`.
  22864. * @example
  22865. *
  22866. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  22867. *
  22868. * _.pullAll(array, ['a', 'c']);
  22869. * console.log(array);
  22870. * // => ['b', 'b']
  22871. */
  22872. function pullAll(array, values) {
  22873. return (array && array.length && values && values.length)
  22874. ? basePullAll(array, values)
  22875. : array;
  22876. }
  22877. /**
  22878. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  22879. * invoked for each element of `array` and `values` to generate the criterion
  22880. * by which they're compared. The iteratee is invoked with one argument: (value).
  22881. *
  22882. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  22883. *
  22884. * @static
  22885. * @memberOf _
  22886. * @since 4.0.0
  22887. * @category Array
  22888. * @param {Array} array The array to modify.
  22889. * @param {Array} values The values to remove.
  22890. * @param {Array|Function|Object|string} [iteratee=_.identity]
  22891. * The iteratee invoked per element.
  22892. * @returns {Array} Returns `array`.
  22893. * @example
  22894. *
  22895. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  22896. *
  22897. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  22898. * console.log(array);
  22899. * // => [{ 'x': 2 }]
  22900. */
  22901. function pullAllBy(array, values, iteratee) {
  22902. return (array && array.length && values && values.length)
  22903. ? basePullAll(array, values, getIteratee(iteratee))
  22904. : array;
  22905. }
  22906. /**
  22907. * This method is like `_.pullAll` except that it accepts `comparator` which
  22908. * is invoked to compare elements of `array` to `values`. The comparator is
  22909. * invoked with two arguments: (arrVal, othVal).
  22910. *
  22911. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  22912. *
  22913. * @static
  22914. * @memberOf _
  22915. * @since 4.6.0
  22916. * @category Array
  22917. * @param {Array} array The array to modify.
  22918. * @param {Array} values The values to remove.
  22919. * @param {Function} [comparator] The comparator invoked per element.
  22920. * @returns {Array} Returns `array`.
  22921. * @example
  22922. *
  22923. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  22924. *
  22925. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  22926. * console.log(array);
  22927. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  22928. */
  22929. function pullAllWith(array, values, comparator) {
  22930. return (array && array.length && values && values.length)
  22931. ? basePullAll(array, values, undefined, comparator)
  22932. : array;
  22933. }
  22934. /**
  22935. * Removes elements from `array` corresponding to `indexes` and returns an
  22936. * array of removed elements.
  22937. *
  22938. * **Note:** Unlike `_.at`, this method mutates `array`.
  22939. *
  22940. * @static
  22941. * @memberOf _
  22942. * @since 3.0.0
  22943. * @category Array
  22944. * @param {Array} array The array to modify.
  22945. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  22946. * @returns {Array} Returns the new array of removed elements.
  22947. * @example
  22948. *
  22949. * var array = ['a', 'b', 'c', 'd'];
  22950. * var pulled = _.pullAt(array, [1, 3]);
  22951. *
  22952. * console.log(array);
  22953. * // => ['a', 'c']
  22954. *
  22955. * console.log(pulled);
  22956. * // => ['b', 'd']
  22957. */
  22958. var pullAt = rest(function(array, indexes) {
  22959. indexes = baseFlatten(indexes, 1);
  22960. var length = array ? array.length : 0,
  22961. result = baseAt(array, indexes);
  22962. basePullAt(array, arrayMap(indexes, function(index) {
  22963. return isIndex(index, length) ? +index : index;
  22964. }).sort(compareAscending));
  22965. return result;
  22966. });
  22967. /**
  22968. * Removes all elements from `array` that `predicate` returns truthy for
  22969. * and returns an array of the removed elements. The predicate is invoked
  22970. * with three arguments: (value, index, array).
  22971. *
  22972. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  22973. * to pull elements from an array by value.
  22974. *
  22975. * @static
  22976. * @memberOf _
  22977. * @since 2.0.0
  22978. * @category Array
  22979. * @param {Array} array The array to modify.
  22980. * @param {Array|Function|Object|string} [predicate=_.identity]
  22981. * The function invoked per iteration.
  22982. * @returns {Array} Returns the new array of removed elements.
  22983. * @example
  22984. *
  22985. * var array = [1, 2, 3, 4];
  22986. * var evens = _.remove(array, function(n) {
  22987. * return n % 2 == 0;
  22988. * });
  22989. *
  22990. * console.log(array);
  22991. * // => [1, 3]
  22992. *
  22993. * console.log(evens);
  22994. * // => [2, 4]
  22995. */
  22996. function remove(array, predicate) {
  22997. var result = [];
  22998. if (!(array && array.length)) {
  22999. return result;
  23000. }
  23001. var index = -1,
  23002. indexes = [],
  23003. length = array.length;
  23004. predicate = getIteratee(predicate, 3);
  23005. while (++index < length) {
  23006. var value = array[index];
  23007. if (predicate(value, index, array)) {
  23008. result.push(value);
  23009. indexes.push(index);
  23010. }
  23011. }
  23012. basePullAt(array, indexes);
  23013. return result;
  23014. }
  23015. /**
  23016. * Reverses `array` so that the first element becomes the last, the second
  23017. * element becomes the second to last, and so on.
  23018. *
  23019. * **Note:** This method mutates `array` and is based on
  23020. * [`Array#reverse`](https://mdn.io/Array/reverse).
  23021. *
  23022. * @static
  23023. * @memberOf _
  23024. * @since 4.0.0
  23025. * @category Array
  23026. * @param {Array} array The array to modify.
  23027. * @returns {Array} Returns `array`.
  23028. * @example
  23029. *
  23030. * var array = [1, 2, 3];
  23031. *
  23032. * _.reverse(array);
  23033. * // => [3, 2, 1]
  23034. *
  23035. * console.log(array);
  23036. * // => [3, 2, 1]
  23037. */
  23038. function reverse(array) {
  23039. return array ? nativeReverse.call(array) : array;
  23040. }
  23041. /**
  23042. * Creates a slice of `array` from `start` up to, but not including, `end`.
  23043. *
  23044. * **Note:** This method is used instead of
  23045. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  23046. * returned.
  23047. *
  23048. * @static
  23049. * @memberOf _
  23050. * @since 3.0.0
  23051. * @category Array
  23052. * @param {Array} array The array to slice.
  23053. * @param {number} [start=0] The start position.
  23054. * @param {number} [end=array.length] The end position.
  23055. * @returns {Array} Returns the slice of `array`.
  23056. */
  23057. function slice(array, start, end) {
  23058. var length = array ? array.length : 0;
  23059. if (!length) {
  23060. return [];
  23061. }
  23062. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  23063. start = 0;
  23064. end = length;
  23065. }
  23066. else {
  23067. start = start == null ? 0 : toInteger(start);
  23068. end = end === undefined ? length : toInteger(end);
  23069. }
  23070. return baseSlice(array, start, end);
  23071. }
  23072. /**
  23073. * Uses a binary search to determine the lowest index at which `value`
  23074. * should be inserted into `array` in order to maintain its sort order.
  23075. *
  23076. * @static
  23077. * @memberOf _
  23078. * @since 0.1.0
  23079. * @category Array
  23080. * @param {Array} array The sorted array to inspect.
  23081. * @param {*} value The value to evaluate.
  23082. * @returns {number} Returns the index at which `value` should be inserted
  23083. * into `array`.
  23084. * @example
  23085. *
  23086. * _.sortedIndex([30, 50], 40);
  23087. * // => 1
  23088. */
  23089. function sortedIndex(array, value) {
  23090. return baseSortedIndex(array, value);
  23091. }
  23092. /**
  23093. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  23094. * which is invoked for `value` and each element of `array` to compute their
  23095. * sort ranking. The iteratee is invoked with one argument: (value).
  23096. *
  23097. * @static
  23098. * @memberOf _
  23099. * @since 4.0.0
  23100. * @category Array
  23101. * @param {Array} array The sorted array to inspect.
  23102. * @param {*} value The value to evaluate.
  23103. * @param {Array|Function|Object|string} [iteratee=_.identity]
  23104. * The iteratee invoked per element.
  23105. * @returns {number} Returns the index at which `value` should be inserted
  23106. * into `array`.
  23107. * @example
  23108. *
  23109. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  23110. *
  23111. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  23112. * // => 0
  23113. *
  23114. * // The `_.property` iteratee shorthand.
  23115. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  23116. * // => 0
  23117. */
  23118. function sortedIndexBy(array, value, iteratee) {
  23119. return baseSortedIndexBy(array, value, getIteratee(iteratee));
  23120. }
  23121. /**
  23122. * This method is like `_.indexOf` except that it performs a binary
  23123. * search on a sorted `array`.
  23124. *
  23125. * @static
  23126. * @memberOf _
  23127. * @since 4.0.0
  23128. * @category Array
  23129. * @param {Array} array The array to search.
  23130. * @param {*} value The value to search for.
  23131. * @returns {number} Returns the index of the matched value, else `-1`.
  23132. * @example
  23133. *
  23134. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  23135. * // => 1
  23136. */
  23137. function sortedIndexOf(array, value) {
  23138. var length = array ? array.length : 0;
  23139. if (length) {
  23140. var index = baseSortedIndex(array, value);
  23141. if (index < length && eq(array[index], value)) {
  23142. return index;
  23143. }
  23144. }
  23145. return -1;
  23146. }
  23147. /**
  23148. * This method is like `_.sortedIndex` except that it returns the highest
  23149. * index at which `value` should be inserted into `array` in order to
  23150. * maintain its sort order.
  23151. *
  23152. * @static
  23153. * @memberOf _
  23154. * @since 3.0.0
  23155. * @category Array
  23156. * @param {Array} array The sorted array to inspect.
  23157. * @param {*} value The value to evaluate.
  23158. * @returns {number} Returns the index at which `value` should be inserted
  23159. * into `array`.
  23160. * @example
  23161. *
  23162. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  23163. * // => 4
  23164. */
  23165. function sortedLastIndex(array, value) {
  23166. return baseSortedIndex(array, value, true);
  23167. }
  23168. /**
  23169. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  23170. * which is invoked for `value` and each element of `array` to compute their
  23171. * sort ranking. The iteratee is invoked with one argument: (value).
  23172. *
  23173. * @static
  23174. * @memberOf _
  23175. * @since 4.0.0
  23176. * @category Array
  23177. * @param {Array} array The sorted array to inspect.
  23178. * @param {*} value The value to evaluate.
  23179. * @param {Array|Function|Object|string} [iteratee=_.identity]
  23180. * The iteratee invoked per element.
  23181. * @returns {number} Returns the index at which `value` should be inserted
  23182. * into `array`.
  23183. * @example
  23184. *
  23185. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  23186. *
  23187. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  23188. * // => 1
  23189. *
  23190. * // The `_.property` iteratee shorthand.
  23191. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  23192. * // => 1
  23193. */
  23194. function sortedLastIndexBy(array, value, iteratee) {
  23195. return baseSortedIndexBy(array, value, getIteratee(iteratee), true);
  23196. }
  23197. /**
  23198. * This method is like `_.lastIndexOf` except that it performs a binary
  23199. * search on a sorted `array`.
  23200. *
  23201. * @static
  23202. * @memberOf _
  23203. * @since 4.0.0
  23204. * @category Array
  23205. * @param {Array} array The array to search.
  23206. * @param {*} value The value to search for.
  23207. * @returns {number} Returns the index of the matched value, else `-1`.
  23208. * @example
  23209. *
  23210. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  23211. * // => 3
  23212. */
  23213. function sortedLastIndexOf(array, value) {
  23214. var length = array ? array.length : 0;
  23215. if (length) {
  23216. var index = baseSortedIndex(array, value, true) - 1;
  23217. if (eq(array[index], value)) {
  23218. return index;
  23219. }
  23220. }
  23221. return -1;
  23222. }
  23223. /**
  23224. * This method is like `_.uniq` except that it's designed and optimized
  23225. * for sorted arrays.
  23226. *
  23227. * @static
  23228. * @memberOf _
  23229. * @since 4.0.0
  23230. * @category Array
  23231. * @param {Array} array The array to inspect.
  23232. * @returns {Array} Returns the new duplicate free array.
  23233. * @example
  23234. *
  23235. * _.sortedUniq([1, 1, 2]);
  23236. * // => [1, 2]
  23237. */
  23238. function sortedUniq(array) {
  23239. return (array && array.length)
  23240. ? baseSortedUniq(array)
  23241. : [];
  23242. }
  23243. /**
  23244. * This method is like `_.uniqBy` except that it's designed and optimized
  23245. * for sorted arrays.
  23246. *
  23247. * @static
  23248. * @memberOf _
  23249. * @since 4.0.0
  23250. * @category Array
  23251. * @param {Array} array The array to inspect.
  23252. * @param {Function} [iteratee] The iteratee invoked per element.
  23253. * @returns {Array} Returns the new duplicate free array.
  23254. * @example
  23255. *
  23256. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  23257. * // => [1.1, 2.3]
  23258. */
  23259. function sortedUniqBy(array, iteratee) {
  23260. return (array && array.length)
  23261. ? baseSortedUniq(array, getIteratee(iteratee))
  23262. : [];
  23263. }
  23264. /**
  23265. * Gets all but the first element of `array`.
  23266. *
  23267. * @static
  23268. * @memberOf _
  23269. * @since 4.0.0
  23270. * @category Array
  23271. * @param {Array} array The array to query.
  23272. * @returns {Array} Returns the slice of `array`.
  23273. * @example
  23274. *
  23275. * _.tail([1, 2, 3]);
  23276. * // => [2, 3]
  23277. */
  23278. function tail(array) {
  23279. return drop(array, 1);
  23280. }
  23281. /**
  23282. * Creates a slice of `array` with `n` elements taken from the beginning.
  23283. *
  23284. * @static
  23285. * @memberOf _
  23286. * @since 0.1.0
  23287. * @category Array
  23288. * @param {Array} array The array to query.
  23289. * @param {number} [n=1] The number of elements to take.
  23290. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  23291. * @returns {Array} Returns the slice of `array`.
  23292. * @example
  23293. *
  23294. * _.take([1, 2, 3]);
  23295. * // => [1]
  23296. *
  23297. * _.take([1, 2, 3], 2);
  23298. * // => [1, 2]
  23299. *
  23300. * _.take([1, 2, 3], 5);
  23301. * // => [1, 2, 3]
  23302. *
  23303. * _.take([1, 2, 3], 0);
  23304. * // => []
  23305. */
  23306. function take(array, n, guard) {
  23307. if (!(array && array.length)) {
  23308. return [];
  23309. }
  23310. n = (guard || n === undefined) ? 1 : toInteger(n);
  23311. return baseSlice(array, 0, n < 0 ? 0 : n);
  23312. }
  23313. /**
  23314. * Creates a slice of `array` with `n` elements taken from the end.
  23315. *
  23316. * @static
  23317. * @memberOf _
  23318. * @since 3.0.0
  23319. * @category Array
  23320. * @param {Array} array The array to query.
  23321. * @param {number} [n=1] The number of elements to take.
  23322. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  23323. * @returns {Array} Returns the slice of `array`.
  23324. * @example
  23325. *
  23326. * _.takeRight([1, 2, 3]);
  23327. * // => [3]
  23328. *
  23329. * _.takeRight([1, 2, 3], 2);
  23330. * // => [2, 3]
  23331. *
  23332. * _.takeRight([1, 2, 3], 5);
  23333. * // => [1, 2, 3]
  23334. *
  23335. * _.takeRight([1, 2, 3], 0);
  23336. * // => []
  23337. */
  23338. function takeRight(array, n, guard) {
  23339. var length = array ? array.length : 0;
  23340. if (!length) {
  23341. return [];
  23342. }
  23343. n = (guard || n === undefined) ? 1 : toInteger(n);
  23344. n = length - n;
  23345. return baseSlice(array, n < 0 ? 0 : n, length);
  23346. }
  23347. /**
  23348. * Creates a slice of `array` with elements taken from the end. Elements are
  23349. * taken until `predicate` returns falsey. The predicate is invoked with
  23350. * three arguments: (value, index, array).
  23351. *
  23352. * @static
  23353. * @memberOf _
  23354. * @since 3.0.0
  23355. * @category Array
  23356. * @param {Array} array The array to query.
  23357. * @param {Array|Function|Object|string} [predicate=_.identity]
  23358. * The function invoked per iteration.
  23359. * @returns {Array} Returns the slice of `array`.
  23360. * @example
  23361. *
  23362. * var users = [
  23363. * { 'user': 'barney', 'active': true },
  23364. * { 'user': 'fred', 'active': false },
  23365. * { 'user': 'pebbles', 'active': false }
  23366. * ];
  23367. *
  23368. * _.takeRightWhile(users, function(o) { return !o.active; });
  23369. * // => objects for ['fred', 'pebbles']
  23370. *
  23371. * // The `_.matches` iteratee shorthand.
  23372. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  23373. * // => objects for ['pebbles']
  23374. *
  23375. * // The `_.matchesProperty` iteratee shorthand.
  23376. * _.takeRightWhile(users, ['active', false]);
  23377. * // => objects for ['fred', 'pebbles']
  23378. *
  23379. * // The `_.property` iteratee shorthand.
  23380. * _.takeRightWhile(users, 'active');
  23381. * // => []
  23382. */
  23383. function takeRightWhile(array, predicate) {
  23384. return (array && array.length)
  23385. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  23386. : [];
  23387. }
  23388. /**
  23389. * Creates a slice of `array` with elements taken from the beginning. Elements
  23390. * are taken until `predicate` returns falsey. The predicate is invoked with
  23391. * three arguments: (value, index, array).
  23392. *
  23393. * @static
  23394. * @memberOf _
  23395. * @since 3.0.0
  23396. * @category Array
  23397. * @param {Array} array The array to query.
  23398. * @param {Array|Function|Object|string} [predicate=_.identity]
  23399. * The function invoked per iteration.
  23400. * @returns {Array} Returns the slice of `array`.
  23401. * @example
  23402. *
  23403. * var users = [
  23404. * { 'user': 'barney', 'active': false },
  23405. * { 'user': 'fred', 'active': false},
  23406. * { 'user': 'pebbles', 'active': true }
  23407. * ];
  23408. *
  23409. * _.takeWhile(users, function(o) { return !o.active; });
  23410. * // => objects for ['barney', 'fred']
  23411. *
  23412. * // The `_.matches` iteratee shorthand.
  23413. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  23414. * // => objects for ['barney']
  23415. *
  23416. * // The `_.matchesProperty` iteratee shorthand.
  23417. * _.takeWhile(users, ['active', false]);
  23418. * // => objects for ['barney', 'fred']
  23419. *
  23420. * // The `_.property` iteratee shorthand.
  23421. * _.takeWhile(users, 'active');
  23422. * // => []
  23423. */
  23424. function takeWhile(array, predicate) {
  23425. return (array && array.length)
  23426. ? baseWhile(array, getIteratee(predicate, 3))
  23427. : [];
  23428. }
  23429. /**
  23430. * Creates an array of unique values, in order, from all given arrays using
  23431. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  23432. * for equality comparisons.
  23433. *
  23434. * @static
  23435. * @memberOf _
  23436. * @since 0.1.0
  23437. * @category Array
  23438. * @param {...Array} [arrays] The arrays to inspect.
  23439. * @returns {Array} Returns the new array of combined values.
  23440. * @example
  23441. *
  23442. * _.union([2], [1, 2]);
  23443. * // => [2, 1]
  23444. */
  23445. var union = rest(function(arrays) {
  23446. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  23447. });
  23448. /**
  23449. * This method is like `_.union` except that it accepts `iteratee` which is
  23450. * invoked for each element of each `arrays` to generate the criterion by
  23451. * which uniqueness is computed. The iteratee is invoked with one argument:
  23452. * (value).
  23453. *
  23454. * @static
  23455. * @memberOf _
  23456. * @since 4.0.0
  23457. * @category Array
  23458. * @param {...Array} [arrays] The arrays to inspect.
  23459. * @param {Array|Function|Object|string} [iteratee=_.identity]
  23460. * The iteratee invoked per element.
  23461. * @returns {Array} Returns the new array of combined values.
  23462. * @example
  23463. *
  23464. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  23465. * // => [2.1, 1.2]
  23466. *
  23467. * // The `_.property` iteratee shorthand.
  23468. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  23469. * // => [{ 'x': 1 }, { 'x': 2 }]
  23470. */
  23471. var unionBy = rest(function(arrays) {
  23472. var iteratee = last(arrays);
  23473. if (isArrayLikeObject(iteratee)) {
  23474. iteratee = undefined;
  23475. }
  23476. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee));
  23477. });
  23478. /**
  23479. * This method is like `_.union` except that it accepts `comparator` which
  23480. * is invoked to compare elements of `arrays`. The comparator is invoked
  23481. * with two arguments: (arrVal, othVal).
  23482. *
  23483. * @static
  23484. * @memberOf _
  23485. * @since 4.0.0
  23486. * @category Array
  23487. * @param {...Array} [arrays] The arrays to inspect.
  23488. * @param {Function} [comparator] The comparator invoked per element.
  23489. * @returns {Array} Returns the new array of combined values.
  23490. * @example
  23491. *
  23492. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  23493. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  23494. *
  23495. * _.unionWith(objects, others, _.isEqual);
  23496. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  23497. */
  23498. var unionWith = rest(function(arrays) {
  23499. var comparator = last(arrays);
  23500. if (isArrayLikeObject(comparator)) {
  23501. comparator = undefined;
  23502. }
  23503. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  23504. });
  23505. /**
  23506. * Creates a duplicate-free version of an array, using
  23507. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  23508. * for equality comparisons, in which only the first occurrence of each
  23509. * element is kept.
  23510. *
  23511. * @static
  23512. * @memberOf _
  23513. * @since 0.1.0
  23514. * @category Array
  23515. * @param {Array} array The array to inspect.
  23516. * @returns {Array} Returns the new duplicate free array.
  23517. * @example
  23518. *
  23519. * _.uniq([2, 1, 2]);
  23520. * // => [2, 1]
  23521. */
  23522. function uniq(array) {
  23523. return (array && array.length)
  23524. ? baseUniq(array)
  23525. : [];
  23526. }
  23527. /**
  23528. * This method is like `_.uniq` except that it accepts `iteratee` which is
  23529. * invoked for each element in `array` to generate the criterion by which
  23530. * uniqueness is computed. The iteratee is invoked with one argument: (value).
  23531. *
  23532. * @static
  23533. * @memberOf _
  23534. * @since 4.0.0
  23535. * @category Array
  23536. * @param {Array} array The array to inspect.
  23537. * @param {Array|Function|Object|string} [iteratee=_.identity]
  23538. * The iteratee invoked per element.
  23539. * @returns {Array} Returns the new duplicate free array.
  23540. * @example
  23541. *
  23542. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  23543. * // => [2.1, 1.2]
  23544. *
  23545. * // The `_.property` iteratee shorthand.
  23546. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  23547. * // => [{ 'x': 1 }, { 'x': 2 }]
  23548. */
  23549. function uniqBy(array, iteratee) {
  23550. return (array && array.length)
  23551. ? baseUniq(array, getIteratee(iteratee))
  23552. : [];
  23553. }
  23554. /**
  23555. * This method is like `_.uniq` except that it accepts `comparator` which
  23556. * is invoked to compare elements of `array`. The comparator is invoked with
  23557. * two arguments: (arrVal, othVal).
  23558. *
  23559. * @static
  23560. * @memberOf _
  23561. * @since 4.0.0
  23562. * @category Array
  23563. * @param {Array} array The array to inspect.
  23564. * @param {Function} [comparator] The comparator invoked per element.
  23565. * @returns {Array} Returns the new duplicate free array.
  23566. * @example
  23567. *
  23568. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  23569. *
  23570. * _.uniqWith(objects, _.isEqual);
  23571. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  23572. */
  23573. function uniqWith(array, comparator) {
  23574. return (array && array.length)
  23575. ? baseUniq(array, undefined, comparator)
  23576. : [];
  23577. }
  23578. /**
  23579. * This method is like `_.zip` except that it accepts an array of grouped
  23580. * elements and creates an array regrouping the elements to their pre-zip
  23581. * configuration.
  23582. *
  23583. * @static
  23584. * @memberOf _
  23585. * @since 1.2.0
  23586. * @category Array
  23587. * @param {Array} array The array of grouped elements to process.
  23588. * @returns {Array} Returns the new array of regrouped elements.
  23589. * @example
  23590. *
  23591. * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
  23592. * // => [['fred', 30, true], ['barney', 40, false]]
  23593. *
  23594. * _.unzip(zipped);
  23595. * // => [['fred', 'barney'], [30, 40], [true, false]]
  23596. */
  23597. function unzip(array) {
  23598. if (!(array && array.length)) {
  23599. return [];
  23600. }
  23601. var length = 0;
  23602. array = arrayFilter(array, function(group) {
  23603. if (isArrayLikeObject(group)) {
  23604. length = nativeMax(group.length, length);
  23605. return true;
  23606. }
  23607. });
  23608. return baseTimes(length, function(index) {
  23609. return arrayMap(array, baseProperty(index));
  23610. });
  23611. }
  23612. /**
  23613. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  23614. * how regrouped values should be combined. The iteratee is invoked with the
  23615. * elements of each group: (...group).
  23616. *
  23617. * @static
  23618. * @memberOf _
  23619. * @since 3.8.0
  23620. * @category Array
  23621. * @param {Array} array The array of grouped elements to process.
  23622. * @param {Function} [iteratee=_.identity] The function to combine
  23623. * regrouped values.
  23624. * @returns {Array} Returns the new array of regrouped elements.
  23625. * @example
  23626. *
  23627. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  23628. * // => [[1, 10, 100], [2, 20, 200]]
  23629. *
  23630. * _.unzipWith(zipped, _.add);
  23631. * // => [3, 30, 300]
  23632. */
  23633. function unzipWith(array, iteratee) {
  23634. if (!(array && array.length)) {
  23635. return [];
  23636. }
  23637. var result = unzip(array);
  23638. if (iteratee == null) {
  23639. return result;
  23640. }
  23641. return arrayMap(result, function(group) {
  23642. return apply(iteratee, undefined, group);
  23643. });
  23644. }
  23645. /**
  23646. * Creates an array excluding all given values using
  23647. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  23648. * for equality comparisons.
  23649. *
  23650. * @static
  23651. * @memberOf _
  23652. * @since 0.1.0
  23653. * @category Array
  23654. * @param {Array} array The array to inspect.
  23655. * @param {...*} [values] The values to exclude.
  23656. * @returns {Array} Returns the new array of filtered values.
  23657. * @see _.difference, _.xor
  23658. * @example
  23659. *
  23660. * _.without([2, 1, 2, 3], 1, 2);
  23661. * // => [3]
  23662. */
  23663. var without = rest(function(array, values) {
  23664. return isArrayLikeObject(array)
  23665. ? baseDifference(array, values)
  23666. : [];
  23667. });
  23668. /**
  23669. * Creates an array of unique values that is the
  23670. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  23671. * of the given arrays. The order of result values is determined by the order
  23672. * they occur in the arrays.
  23673. *
  23674. * @static
  23675. * @memberOf _
  23676. * @since 2.4.0
  23677. * @category Array
  23678. * @param {...Array} [arrays] The arrays to inspect.
  23679. * @returns {Array} Returns the new array of filtered values.
  23680. * @see _.difference, _.without
  23681. * @example
  23682. *
  23683. * _.xor([2, 1], [2, 3]);
  23684. * // => [1, 3]
  23685. */
  23686. var xor = rest(function(arrays) {
  23687. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  23688. });
  23689. /**
  23690. * This method is like `_.xor` except that it accepts `iteratee` which is
  23691. * invoked for each element of each `arrays` to generate the criterion by
  23692. * which by which they're compared. The iteratee is invoked with one argument:
  23693. * (value).
  23694. *
  23695. * @static
  23696. * @memberOf _
  23697. * @since 4.0.0
  23698. * @category Array
  23699. * @param {...Array} [arrays] The arrays to inspect.
  23700. * @param {Array|Function|Object|string} [iteratee=_.identity]
  23701. * The iteratee invoked per element.
  23702. * @returns {Array} Returns the new array of filtered values.
  23703. * @example
  23704. *
  23705. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  23706. * // => [1.2, 3.4]
  23707. *
  23708. * // The `_.property` iteratee shorthand.
  23709. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  23710. * // => [{ 'x': 2 }]
  23711. */
  23712. var xorBy = rest(function(arrays) {
  23713. var iteratee = last(arrays);
  23714. if (isArrayLikeObject(iteratee)) {
  23715. iteratee = undefined;
  23716. }
  23717. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee));
  23718. });
  23719. /**
  23720. * This method is like `_.xor` except that it accepts `comparator` which is
  23721. * invoked to compare elements of `arrays`. The comparator is invoked with
  23722. * two arguments: (arrVal, othVal).
  23723. *
  23724. * @static
  23725. * @memberOf _
  23726. * @since 4.0.0
  23727. * @category Array
  23728. * @param {...Array} [arrays] The arrays to inspect.
  23729. * @param {Function} [comparator] The comparator invoked per element.
  23730. * @returns {Array} Returns the new array of filtered values.
  23731. * @example
  23732. *
  23733. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  23734. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  23735. *
  23736. * _.xorWith(objects, others, _.isEqual);
  23737. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  23738. */
  23739. var xorWith = rest(function(arrays) {
  23740. var comparator = last(arrays);
  23741. if (isArrayLikeObject(comparator)) {
  23742. comparator = undefined;
  23743. }
  23744. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  23745. });
  23746. /**
  23747. * Creates an array of grouped elements, the first of which contains the
  23748. * first elements of the given arrays, the second of which contains the
  23749. * second elements of the given arrays, and so on.
  23750. *
  23751. * @static
  23752. * @memberOf _
  23753. * @since 0.1.0
  23754. * @category Array
  23755. * @param {...Array} [arrays] The arrays to process.
  23756. * @returns {Array} Returns the new array of grouped elements.
  23757. * @example
  23758. *
  23759. * _.zip(['fred', 'barney'], [30, 40], [true, false]);
  23760. * // => [['fred', 30, true], ['barney', 40, false]]
  23761. */
  23762. var zip = rest(unzip);
  23763. /**
  23764. * This method is like `_.fromPairs` except that it accepts two arrays,
  23765. * one of property identifiers and one of corresponding values.
  23766. *
  23767. * @static
  23768. * @memberOf _
  23769. * @since 0.4.0
  23770. * @category Array
  23771. * @param {Array} [props=[]] The property identifiers.
  23772. * @param {Array} [values=[]] The property values.
  23773. * @returns {Object} Returns the new object.
  23774. * @example
  23775. *
  23776. * _.zipObject(['a', 'b'], [1, 2]);
  23777. * // => { 'a': 1, 'b': 2 }
  23778. */
  23779. function zipObject(props, values) {
  23780. return baseZipObject(props || [], values || [], assignValue);
  23781. }
  23782. /**
  23783. * This method is like `_.zipObject` except that it supports property paths.
  23784. *
  23785. * @static
  23786. * @memberOf _
  23787. * @since 4.1.0
  23788. * @category Array
  23789. * @param {Array} [props=[]] The property identifiers.
  23790. * @param {Array} [values=[]] The property values.
  23791. * @returns {Object} Returns the new object.
  23792. * @example
  23793. *
  23794. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  23795. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  23796. */
  23797. function zipObjectDeep(props, values) {
  23798. return baseZipObject(props || [], values || [], baseSet);
  23799. }
  23800. /**
  23801. * This method is like `_.zip` except that it accepts `iteratee` to specify
  23802. * how grouped values should be combined. The iteratee is invoked with the
  23803. * elements of each group: (...group).
  23804. *
  23805. * @static
  23806. * @memberOf _
  23807. * @since 3.8.0
  23808. * @category Array
  23809. * @param {...Array} [arrays] The arrays to process.
  23810. * @param {Function} [iteratee=_.identity] The function to combine grouped values.
  23811. * @returns {Array} Returns the new array of grouped elements.
  23812. * @example
  23813. *
  23814. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  23815. * return a + b + c;
  23816. * });
  23817. * // => [111, 222]
  23818. */
  23819. var zipWith = rest(function(arrays) {
  23820. var length = arrays.length,
  23821. iteratee = length > 1 ? arrays[length - 1] : undefined;
  23822. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  23823. return unzipWith(arrays, iteratee);
  23824. });
  23825. /*------------------------------------------------------------------------*/
  23826. /**
  23827. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  23828. * chain sequences enabled. The result of such sequences must be unwrapped
  23829. * with `_#value`.
  23830. *
  23831. * @static
  23832. * @memberOf _
  23833. * @since 1.3.0
  23834. * @category Seq
  23835. * @param {*} value The value to wrap.
  23836. * @returns {Object} Returns the new `lodash` wrapper instance.
  23837. * @example
  23838. *
  23839. * var users = [
  23840. * { 'user': 'barney', 'age': 36 },
  23841. * { 'user': 'fred', 'age': 40 },
  23842. * { 'user': 'pebbles', 'age': 1 }
  23843. * ];
  23844. *
  23845. * var youngest = _
  23846. * .chain(users)
  23847. * .sortBy('age')
  23848. * .map(function(o) {
  23849. * return o.user + ' is ' + o.age;
  23850. * })
  23851. * .head()
  23852. * .value();
  23853. * // => 'pebbles is 1'
  23854. */
  23855. function chain(value) {
  23856. var result = lodash(value);
  23857. result.__chain__ = true;
  23858. return result;
  23859. }
  23860. /**
  23861. * This method invokes `interceptor` and returns `value`. The interceptor
  23862. * is invoked with one argument; (value). The purpose of this method is to
  23863. * "tap into" a method chain sequence in order to modify intermediate results.
  23864. *
  23865. * @static
  23866. * @memberOf _
  23867. * @since 0.1.0
  23868. * @category Seq
  23869. * @param {*} value The value to provide to `interceptor`.
  23870. * @param {Function} interceptor The function to invoke.
  23871. * @returns {*} Returns `value`.
  23872. * @example
  23873. *
  23874. * _([1, 2, 3])
  23875. * .tap(function(array) {
  23876. * // Mutate input array.
  23877. * array.pop();
  23878. * })
  23879. * .reverse()
  23880. * .value();
  23881. * // => [2, 1]
  23882. */
  23883. function tap(value, interceptor) {
  23884. interceptor(value);
  23885. return value;
  23886. }
  23887. /**
  23888. * This method is like `_.tap` except that it returns the result of `interceptor`.
  23889. * The purpose of this method is to "pass thru" values replacing intermediate
  23890. * results in a method chain sequence.
  23891. *
  23892. * @static
  23893. * @memberOf _
  23894. * @since 3.0.0
  23895. * @category Seq
  23896. * @param {*} value The value to provide to `interceptor`.
  23897. * @param {Function} interceptor The function to invoke.
  23898. * @returns {*} Returns the result of `interceptor`.
  23899. * @example
  23900. *
  23901. * _(' abc ')
  23902. * .chain()
  23903. * .trim()
  23904. * .thru(function(value) {
  23905. * return [value];
  23906. * })
  23907. * .value();
  23908. * // => ['abc']
  23909. */
  23910. function thru(value, interceptor) {
  23911. return interceptor(value);
  23912. }
  23913. /**
  23914. * This method is the wrapper version of `_.at`.
  23915. *
  23916. * @name at
  23917. * @memberOf _
  23918. * @since 1.0.0
  23919. * @category Seq
  23920. * @param {...(string|string[])} [paths] The property paths of elements to pick.
  23921. * @returns {Object} Returns the new `lodash` wrapper instance.
  23922. * @example
  23923. *
  23924. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  23925. *
  23926. * _(object).at(['a[0].b.c', 'a[1]']).value();
  23927. * // => [3, 4]
  23928. */
  23929. var wrapperAt = rest(function(paths) {
  23930. paths = baseFlatten(paths, 1);
  23931. var length = paths.length,
  23932. start = length ? paths[0] : 0,
  23933. value = this.__wrapped__,
  23934. interceptor = function(object) { return baseAt(object, paths); };
  23935. if (length > 1 || this.__actions__.length ||
  23936. !(value instanceof LazyWrapper) || !isIndex(start)) {
  23937. return this.thru(interceptor);
  23938. }
  23939. value = value.slice(start, +start + (length ? 1 : 0));
  23940. value.__actions__.push({
  23941. 'func': thru,
  23942. 'args': [interceptor],
  23943. 'thisArg': undefined
  23944. });
  23945. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  23946. if (length && !array.length) {
  23947. array.push(undefined);
  23948. }
  23949. return array;
  23950. });
  23951. });
  23952. /**
  23953. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  23954. *
  23955. * @name chain
  23956. * @memberOf _
  23957. * @since 0.1.0
  23958. * @category Seq
  23959. * @returns {Object} Returns the new `lodash` wrapper instance.
  23960. * @example
  23961. *
  23962. * var users = [
  23963. * { 'user': 'barney', 'age': 36 },
  23964. * { 'user': 'fred', 'age': 40 }
  23965. * ];
  23966. *
  23967. * // A sequence without explicit chaining.
  23968. * _(users).head();
  23969. * // => { 'user': 'barney', 'age': 36 }
  23970. *
  23971. * // A sequence with explicit chaining.
  23972. * _(users)
  23973. * .chain()
  23974. * .head()
  23975. * .pick('user')
  23976. * .value();
  23977. * // => { 'user': 'barney' }
  23978. */
  23979. function wrapperChain() {
  23980. return chain(this);
  23981. }
  23982. /**
  23983. * Executes the chain sequence and returns the wrapped result.
  23984. *
  23985. * @name commit
  23986. * @memberOf _
  23987. * @since 3.2.0
  23988. * @category Seq
  23989. * @returns {Object} Returns the new `lodash` wrapper instance.
  23990. * @example
  23991. *
  23992. * var array = [1, 2];
  23993. * var wrapped = _(array).push(3);
  23994. *
  23995. * console.log(array);
  23996. * // => [1, 2]
  23997. *
  23998. * wrapped = wrapped.commit();
  23999. * console.log(array);
  24000. * // => [1, 2, 3]
  24001. *
  24002. * wrapped.last();
  24003. * // => 3
  24004. *
  24005. * console.log(array);
  24006. * // => [1, 2, 3]
  24007. */
  24008. function wrapperCommit() {
  24009. return new LodashWrapper(this.value(), this.__chain__);
  24010. }
  24011. /**
  24012. * Gets the next value on a wrapped object following the
  24013. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  24014. *
  24015. * @name next
  24016. * @memberOf _
  24017. * @since 4.0.0
  24018. * @category Seq
  24019. * @returns {Object} Returns the next iterator value.
  24020. * @example
  24021. *
  24022. * var wrapped = _([1, 2]);
  24023. *
  24024. * wrapped.next();
  24025. * // => { 'done': false, 'value': 1 }
  24026. *
  24027. * wrapped.next();
  24028. * // => { 'done': false, 'value': 2 }
  24029. *
  24030. * wrapped.next();
  24031. * // => { 'done': true, 'value': undefined }
  24032. */
  24033. function wrapperNext() {
  24034. if (this.__values__ === undefined) {
  24035. this.__values__ = toArray(this.value());
  24036. }
  24037. var done = this.__index__ >= this.__values__.length,
  24038. value = done ? undefined : this.__values__[this.__index__++];
  24039. return { 'done': done, 'value': value };
  24040. }
  24041. /**
  24042. * Enables the wrapper to be iterable.
  24043. *
  24044. * @name Symbol.iterator
  24045. * @memberOf _
  24046. * @since 4.0.0
  24047. * @category Seq
  24048. * @returns {Object} Returns the wrapper object.
  24049. * @example
  24050. *
  24051. * var wrapped = _([1, 2]);
  24052. *
  24053. * wrapped[Symbol.iterator]() === wrapped;
  24054. * // => true
  24055. *
  24056. * Array.from(wrapped);
  24057. * // => [1, 2]
  24058. */
  24059. function wrapperToIterator() {
  24060. return this;
  24061. }
  24062. /**
  24063. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  24064. *
  24065. * @name plant
  24066. * @memberOf _
  24067. * @since 3.2.0
  24068. * @category Seq
  24069. * @param {*} value The value to plant.
  24070. * @returns {Object} Returns the new `lodash` wrapper instance.
  24071. * @example
  24072. *
  24073. * function square(n) {
  24074. * return n * n;
  24075. * }
  24076. *
  24077. * var wrapped = _([1, 2]).map(square);
  24078. * var other = wrapped.plant([3, 4]);
  24079. *
  24080. * other.value();
  24081. * // => [9, 16]
  24082. *
  24083. * wrapped.value();
  24084. * // => [1, 4]
  24085. */
  24086. function wrapperPlant(value) {
  24087. var result,
  24088. parent = this;
  24089. while (parent instanceof baseLodash) {
  24090. var clone = wrapperClone(parent);
  24091. clone.__index__ = 0;
  24092. clone.__values__ = undefined;
  24093. if (result) {
  24094. previous.__wrapped__ = clone;
  24095. } else {
  24096. result = clone;
  24097. }
  24098. var previous = clone;
  24099. parent = parent.__wrapped__;
  24100. }
  24101. previous.__wrapped__ = value;
  24102. return result;
  24103. }
  24104. /**
  24105. * This method is the wrapper version of `_.reverse`.
  24106. *
  24107. * **Note:** This method mutates the wrapped array.
  24108. *
  24109. * @name reverse
  24110. * @memberOf _
  24111. * @since 0.1.0
  24112. * @category Seq
  24113. * @returns {Object} Returns the new `lodash` wrapper instance.
  24114. * @example
  24115. *
  24116. * var array = [1, 2, 3];
  24117. *
  24118. * _(array).reverse().value()
  24119. * // => [3, 2, 1]
  24120. *
  24121. * console.log(array);
  24122. * // => [3, 2, 1]
  24123. */
  24124. function wrapperReverse() {
  24125. var value = this.__wrapped__;
  24126. if (value instanceof LazyWrapper) {
  24127. var wrapped = value;
  24128. if (this.__actions__.length) {
  24129. wrapped = new LazyWrapper(this);
  24130. }
  24131. wrapped = wrapped.reverse();
  24132. wrapped.__actions__.push({
  24133. 'func': thru,
  24134. 'args': [reverse],
  24135. 'thisArg': undefined
  24136. });
  24137. return new LodashWrapper(wrapped, this.__chain__);
  24138. }
  24139. return this.thru(reverse);
  24140. }
  24141. /**
  24142. * Executes the chain sequence to resolve the unwrapped value.
  24143. *
  24144. * @name value
  24145. * @memberOf _
  24146. * @since 0.1.0
  24147. * @alias toJSON, valueOf
  24148. * @category Seq
  24149. * @returns {*} Returns the resolved unwrapped value.
  24150. * @example
  24151. *
  24152. * _([1, 2, 3]).value();
  24153. * // => [1, 2, 3]
  24154. */
  24155. function wrapperValue() {
  24156. return baseWrapperValue(this.__wrapped__, this.__actions__);
  24157. }
  24158. /*------------------------------------------------------------------------*/
  24159. /**
  24160. * Creates an object composed of keys generated from the results of running
  24161. * each element of `collection` thru `iteratee`. The corresponding value of
  24162. * each key is the number of times the key was returned by `iteratee`. The
  24163. * iteratee is invoked with one argument: (value).
  24164. *
  24165. * @static
  24166. * @memberOf _
  24167. * @since 0.5.0
  24168. * @category Collection
  24169. * @param {Array|Object} collection The collection to iterate over.
  24170. * @param {Array|Function|Object|string} [iteratee=_.identity]
  24171. * The iteratee to transform keys.
  24172. * @returns {Object} Returns the composed aggregate object.
  24173. * @example
  24174. *
  24175. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  24176. * // => { '4': 1, '6': 2 }
  24177. *
  24178. * // The `_.property` iteratee shorthand.
  24179. * _.countBy(['one', 'two', 'three'], 'length');
  24180. * // => { '3': 2, '5': 1 }
  24181. */
  24182. var countBy = createAggregator(function(result, value, key) {
  24183. hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
  24184. });
  24185. /**
  24186. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  24187. * Iteration is stopped once `predicate` returns falsey. The predicate is
  24188. * invoked with three arguments: (value, index|key, collection).
  24189. *
  24190. * @static
  24191. * @memberOf _
  24192. * @since 0.1.0
  24193. * @category Collection
  24194. * @param {Array|Object} collection The collection to iterate over.
  24195. * @param {Array|Function|Object|string} [predicate=_.identity]
  24196. * The function invoked per iteration.
  24197. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  24198. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  24199. * else `false`.
  24200. * @example
  24201. *
  24202. * _.every([true, 1, null, 'yes'], Boolean);
  24203. * // => false
  24204. *
  24205. * var users = [
  24206. * { 'user': 'barney', 'age': 36, 'active': false },
  24207. * { 'user': 'fred', 'age': 40, 'active': false }
  24208. * ];
  24209. *
  24210. * // The `_.matches` iteratee shorthand.
  24211. * _.every(users, { 'user': 'barney', 'active': false });
  24212. * // => false
  24213. *
  24214. * // The `_.matchesProperty` iteratee shorthand.
  24215. * _.every(users, ['active', false]);
  24216. * // => true
  24217. *
  24218. * // The `_.property` iteratee shorthand.
  24219. * _.every(users, 'active');
  24220. * // => false
  24221. */
  24222. function every(collection, predicate, guard) {
  24223. var func = isArray(collection) ? arrayEvery : baseEvery;
  24224. if (guard && isIterateeCall(collection, predicate, guard)) {
  24225. predicate = undefined;
  24226. }
  24227. return func(collection, getIteratee(predicate, 3));
  24228. }
  24229. /**
  24230. * Iterates over elements of `collection`, returning an array of all elements
  24231. * `predicate` returns truthy for. The predicate is invoked with three
  24232. * arguments: (value, index|key, collection).
  24233. *
  24234. * @static
  24235. * @memberOf _
  24236. * @since 0.1.0
  24237. * @category Collection
  24238. * @param {Array|Object} collection The collection to iterate over.
  24239. * @param {Array|Function|Object|string} [predicate=_.identity]
  24240. * The function invoked per iteration.
  24241. * @returns {Array} Returns the new filtered array.
  24242. * @see _.reject
  24243. * @example
  24244. *
  24245. * var users = [
  24246. * { 'user': 'barney', 'age': 36, 'active': true },
  24247. * { 'user': 'fred', 'age': 40, 'active': false }
  24248. * ];
  24249. *
  24250. * _.filter(users, function(o) { return !o.active; });
  24251. * // => objects for ['fred']
  24252. *
  24253. * // The `_.matches` iteratee shorthand.
  24254. * _.filter(users, { 'age': 36, 'active': true });
  24255. * // => objects for ['barney']
  24256. *
  24257. * // The `_.matchesProperty` iteratee shorthand.
  24258. * _.filter(users, ['active', false]);
  24259. * // => objects for ['fred']
  24260. *
  24261. * // The `_.property` iteratee shorthand.
  24262. * _.filter(users, 'active');
  24263. * // => objects for ['barney']
  24264. */
  24265. function filter(collection, predicate) {
  24266. var func = isArray(collection) ? arrayFilter : baseFilter;
  24267. return func(collection, getIteratee(predicate, 3));
  24268. }
  24269. /**
  24270. * Iterates over elements of `collection`, returning the first element
  24271. * `predicate` returns truthy for. The predicate is invoked with three
  24272. * arguments: (value, index|key, collection).
  24273. *
  24274. * @static
  24275. * @memberOf _
  24276. * @since 0.1.0
  24277. * @category Collection
  24278. * @param {Array|Object} collection The collection to search.
  24279. * @param {Array|Function|Object|string} [predicate=_.identity]
  24280. * The function invoked per iteration.
  24281. * @param {number} [fromIndex=0] The index to search from.
  24282. * @returns {*} Returns the matched element, else `undefined`.
  24283. * @example
  24284. *
  24285. * var users = [
  24286. * { 'user': 'barney', 'age': 36, 'active': true },
  24287. * { 'user': 'fred', 'age': 40, 'active': false },
  24288. * { 'user': 'pebbles', 'age': 1, 'active': true }
  24289. * ];
  24290. *
  24291. * _.find(users, function(o) { return o.age < 40; });
  24292. * // => object for 'barney'
  24293. *
  24294. * // The `_.matches` iteratee shorthand.
  24295. * _.find(users, { 'age': 1, 'active': true });
  24296. * // => object for 'pebbles'
  24297. *
  24298. * // The `_.matchesProperty` iteratee shorthand.
  24299. * _.find(users, ['active', false]);
  24300. * // => object for 'fred'
  24301. *
  24302. * // The `_.property` iteratee shorthand.
  24303. * _.find(users, 'active');
  24304. * // => object for 'barney'
  24305. */
  24306. var find = createFind(findIndex);
  24307. /**
  24308. * This method is like `_.find` except that it iterates over elements of
  24309. * `collection` from right to left.
  24310. *
  24311. * @static
  24312. * @memberOf _
  24313. * @since 2.0.0
  24314. * @category Collection
  24315. * @param {Array|Object} collection The collection to search.
  24316. * @param {Array|Function|Object|string} [predicate=_.identity]
  24317. * The function invoked per iteration.
  24318. * @param {number} [fromIndex=collection.length-1] The index to search from.
  24319. * @returns {*} Returns the matched element, else `undefined`.
  24320. * @example
  24321. *
  24322. * _.findLast([1, 2, 3, 4], function(n) {
  24323. * return n % 2 == 1;
  24324. * });
  24325. * // => 3
  24326. */
  24327. var findLast = createFind(findLastIndex);
  24328. /**
  24329. * Creates a flattened array of values by running each element in `collection`
  24330. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  24331. * with three arguments: (value, index|key, collection).
  24332. *
  24333. * @static
  24334. * @memberOf _
  24335. * @since 4.0.0
  24336. * @category Collection
  24337. * @param {Array|Object} collection The collection to iterate over.
  24338. * @param {Array|Function|Object|string} [iteratee=_.identity]
  24339. * The function invoked per iteration.
  24340. * @returns {Array} Returns the new flattened array.
  24341. * @example
  24342. *
  24343. * function duplicate(n) {
  24344. * return [n, n];
  24345. * }
  24346. *
  24347. * _.flatMap([1, 2], duplicate);
  24348. * // => [1, 1, 2, 2]
  24349. */
  24350. function flatMap(collection, iteratee) {
  24351. return baseFlatten(map(collection, iteratee), 1);
  24352. }
  24353. /**
  24354. * This method is like `_.flatMap` except that it recursively flattens the
  24355. * mapped results.
  24356. *
  24357. * @static
  24358. * @memberOf _
  24359. * @since 4.7.0
  24360. * @category Collection
  24361. * @param {Array|Object} collection The collection to iterate over.
  24362. * @param {Array|Function|Object|string} [iteratee=_.identity]
  24363. * The function invoked per iteration.
  24364. * @returns {Array} Returns the new flattened array.
  24365. * @example
  24366. *
  24367. * function duplicate(n) {
  24368. * return [[[n, n]]];
  24369. * }
  24370. *
  24371. * _.flatMapDeep([1, 2], duplicate);
  24372. * // => [1, 1, 2, 2]
  24373. */
  24374. function flatMapDeep(collection, iteratee) {
  24375. return baseFlatten(map(collection, iteratee), INFINITY);
  24376. }
  24377. /**
  24378. * This method is like `_.flatMap` except that it recursively flattens the
  24379. * mapped results up to `depth` times.
  24380. *
  24381. * @static
  24382. * @memberOf _
  24383. * @since 4.7.0
  24384. * @category Collection
  24385. * @param {Array|Object} collection The collection to iterate over.
  24386. * @param {Array|Function|Object|string} [iteratee=_.identity]
  24387. * The function invoked per iteration.
  24388. * @param {number} [depth=1] The maximum recursion depth.
  24389. * @returns {Array} Returns the new flattened array.
  24390. * @example
  24391. *
  24392. * function duplicate(n) {
  24393. * return [[[n, n]]];
  24394. * }
  24395. *
  24396. * _.flatMapDepth([1, 2], duplicate, 2);
  24397. * // => [[1, 1], [2, 2]]
  24398. */
  24399. function flatMapDepth(collection, iteratee, depth) {
  24400. depth = depth === undefined ? 1 : toInteger(depth);
  24401. return baseFlatten(map(collection, iteratee), depth);
  24402. }
  24403. /**
  24404. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  24405. * The iteratee is invoked with three arguments: (value, index|key, collection).
  24406. * Iteratee functions may exit iteration early by explicitly returning `false`.
  24407. *
  24408. * **Note:** As with other "Collections" methods, objects with a "length"
  24409. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  24410. * or `_.forOwn` for object iteration.
  24411. *
  24412. * @static
  24413. * @memberOf _
  24414. * @since 0.1.0
  24415. * @alias each
  24416. * @category Collection
  24417. * @param {Array|Object} collection The collection to iterate over.
  24418. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  24419. * @returns {Array|Object} Returns `collection`.
  24420. * @see _.forEachRight
  24421. * @example
  24422. *
  24423. * _([1, 2]).forEach(function(value) {
  24424. * console.log(value);
  24425. * });
  24426. * // => Logs `1` then `2`.
  24427. *
  24428. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  24429. * console.log(key);
  24430. * });
  24431. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  24432. */
  24433. function forEach(collection, iteratee) {
  24434. var func = isArray(collection) ? arrayEach : baseEach;
  24435. return func(collection, getIteratee(iteratee, 3));
  24436. }
  24437. /**
  24438. * This method is like `_.forEach` except that it iterates over elements of
  24439. * `collection` from right to left.
  24440. *
  24441. * @static
  24442. * @memberOf _
  24443. * @since 2.0.0
  24444. * @alias eachRight
  24445. * @category Collection
  24446. * @param {Array|Object} collection The collection to iterate over.
  24447. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  24448. * @returns {Array|Object} Returns `collection`.
  24449. * @see _.forEach
  24450. * @example
  24451. *
  24452. * _.forEachRight([1, 2], function(value) {
  24453. * console.log(value);
  24454. * });
  24455. * // => Logs `2` then `1`.
  24456. */
  24457. function forEachRight(collection, iteratee) {
  24458. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  24459. return func(collection, getIteratee(iteratee, 3));
  24460. }
  24461. /**
  24462. * Creates an object composed of keys generated from the results of running
  24463. * each element of `collection` thru `iteratee`. The order of grouped values
  24464. * is determined by the order they occur in `collection`. The corresponding
  24465. * value of each key is an array of elements responsible for generating the
  24466. * key. The iteratee is invoked with one argument: (value).
  24467. *
  24468. * @static
  24469. * @memberOf _
  24470. * @since 0.1.0
  24471. * @category Collection
  24472. * @param {Array|Object} collection The collection to iterate over.
  24473. * @param {Array|Function|Object|string} [iteratee=_.identity]
  24474. * The iteratee to transform keys.
  24475. * @returns {Object} Returns the composed aggregate object.
  24476. * @example
  24477. *
  24478. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  24479. * // => { '4': [4.2], '6': [6.1, 6.3] }
  24480. *
  24481. * // The `_.property` iteratee shorthand.
  24482. * _.groupBy(['one', 'two', 'three'], 'length');
  24483. * // => { '3': ['one', 'two'], '5': ['three'] }
  24484. */
  24485. var groupBy = createAggregator(function(result, value, key) {
  24486. if (hasOwnProperty.call(result, key)) {
  24487. result[key].push(value);
  24488. } else {
  24489. result[key] = [value];
  24490. }
  24491. });
  24492. /**
  24493. * Checks if `value` is in `collection`. If `collection` is a string, it's
  24494. * checked for a substring of `value`, otherwise
  24495. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  24496. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  24497. * the offset from the end of `collection`.
  24498. *
  24499. * @static
  24500. * @memberOf _
  24501. * @since 0.1.0
  24502. * @category Collection
  24503. * @param {Array|Object|string} collection The collection to search.
  24504. * @param {*} value The value to search for.
  24505. * @param {number} [fromIndex=0] The index to search from.
  24506. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  24507. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  24508. * @example
  24509. *
  24510. * _.includes([1, 2, 3], 1);
  24511. * // => true
  24512. *
  24513. * _.includes([1, 2, 3], 1, 2);
  24514. * // => false
  24515. *
  24516. * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
  24517. * // => true
  24518. *
  24519. * _.includes('pebbles', 'eb');
  24520. * // => true
  24521. */
  24522. function includes(collection, value, fromIndex, guard) {
  24523. collection = isArrayLike(collection) ? collection : values(collection);
  24524. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  24525. var length = collection.length;
  24526. if (fromIndex < 0) {
  24527. fromIndex = nativeMax(length + fromIndex, 0);
  24528. }
  24529. return isString(collection)
  24530. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  24531. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  24532. }
  24533. /**
  24534. * Invokes the method at `path` of each element in `collection`, returning
  24535. * an array of the results of each invoked method. Any additional arguments
  24536. * are provided to each invoked method. If `methodName` is a function, it's
  24537. * invoked for and `this` bound to, each element in `collection`.
  24538. *
  24539. * @static
  24540. * @memberOf _
  24541. * @since 4.0.0
  24542. * @category Collection
  24543. * @param {Array|Object} collection The collection to iterate over.
  24544. * @param {Array|Function|string} path The path of the method to invoke or
  24545. * the function invoked per iteration.
  24546. * @param {...*} [args] The arguments to invoke each method with.
  24547. * @returns {Array} Returns the array of results.
  24548. * @example
  24549. *
  24550. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  24551. * // => [[1, 5, 7], [1, 2, 3]]
  24552. *
  24553. * _.invokeMap([123, 456], String.prototype.split, '');
  24554. * // => [['1', '2', '3'], ['4', '5', '6']]
  24555. */
  24556. var invokeMap = rest(function(collection, path, args) {
  24557. var index = -1,
  24558. isFunc = typeof path == 'function',
  24559. isProp = isKey(path),
  24560. result = isArrayLike(collection) ? Array(collection.length) : [];
  24561. baseEach(collection, function(value) {
  24562. var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
  24563. result[++index] = func ? apply(func, value, args) : baseInvoke(value, path, args);
  24564. });
  24565. return result;
  24566. });
  24567. /**
  24568. * Creates an object composed of keys generated from the results of running
  24569. * each element of `collection` thru `iteratee`. The corresponding value of
  24570. * each key is the last element responsible for generating the key. The
  24571. * iteratee is invoked with one argument: (value).
  24572. *
  24573. * @static
  24574. * @memberOf _
  24575. * @since 4.0.0
  24576. * @category Collection
  24577. * @param {Array|Object} collection The collection to iterate over.
  24578. * @param {Array|Function|Object|string} [iteratee=_.identity]
  24579. * The iteratee to transform keys.
  24580. * @returns {Object} Returns the composed aggregate object.
  24581. * @example
  24582. *
  24583. * var array = [
  24584. * { 'dir': 'left', 'code': 97 },
  24585. * { 'dir': 'right', 'code': 100 }
  24586. * ];
  24587. *
  24588. * _.keyBy(array, function(o) {
  24589. * return String.fromCharCode(o.code);
  24590. * });
  24591. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  24592. *
  24593. * _.keyBy(array, 'dir');
  24594. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  24595. */
  24596. var keyBy = createAggregator(function(result, value, key) {
  24597. result[key] = value;
  24598. });
  24599. /**
  24600. * Creates an array of values by running each element in `collection` thru
  24601. * `iteratee`. The iteratee is invoked with three arguments:
  24602. * (value, index|key, collection).
  24603. *
  24604. * Many lodash methods are guarded to work as iteratees for methods like
  24605. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  24606. *
  24607. * The guarded methods are:
  24608. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  24609. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  24610. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  24611. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  24612. *
  24613. * @static
  24614. * @memberOf _
  24615. * @since 0.1.0
  24616. * @category Collection
  24617. * @param {Array|Object} collection The collection to iterate over.
  24618. * @param {Array|Function|Object|string} [iteratee=_.identity]
  24619. * The function invoked per iteration.
  24620. * @returns {Array} Returns the new mapped array.
  24621. * @example
  24622. *
  24623. * function square(n) {
  24624. * return n * n;
  24625. * }
  24626. *
  24627. * _.map([4, 8], square);
  24628. * // => [16, 64]
  24629. *
  24630. * _.map({ 'a': 4, 'b': 8 }, square);
  24631. * // => [16, 64] (iteration order is not guaranteed)
  24632. *
  24633. * var users = [
  24634. * { 'user': 'barney' },
  24635. * { 'user': 'fred' }
  24636. * ];
  24637. *
  24638. * // The `_.property` iteratee shorthand.
  24639. * _.map(users, 'user');
  24640. * // => ['barney', 'fred']
  24641. */
  24642. function map(collection, iteratee) {
  24643. var func = isArray(collection) ? arrayMap : baseMap;
  24644. return func(collection, getIteratee(iteratee, 3));
  24645. }
  24646. /**
  24647. * This method is like `_.sortBy` except that it allows specifying the sort
  24648. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  24649. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  24650. * descending or "asc" for ascending sort order of corresponding values.
  24651. *
  24652. * @static
  24653. * @memberOf _
  24654. * @since 4.0.0
  24655. * @category Collection
  24656. * @param {Array|Object} collection The collection to iterate over.
  24657. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  24658. * The iteratees to sort by.
  24659. * @param {string[]} [orders] The sort orders of `iteratees`.
  24660. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  24661. * @returns {Array} Returns the new sorted array.
  24662. * @example
  24663. *
  24664. * var users = [
  24665. * { 'user': 'fred', 'age': 48 },
  24666. * { 'user': 'barney', 'age': 34 },
  24667. * { 'user': 'fred', 'age': 40 },
  24668. * { 'user': 'barney', 'age': 36 }
  24669. * ];
  24670. *
  24671. * // Sort by `user` in ascending order and by `age` in descending order.
  24672. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  24673. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  24674. */
  24675. function orderBy(collection, iteratees, orders, guard) {
  24676. if (collection == null) {
  24677. return [];
  24678. }
  24679. if (!isArray(iteratees)) {
  24680. iteratees = iteratees == null ? [] : [iteratees];
  24681. }
  24682. orders = guard ? undefined : orders;
  24683. if (!isArray(orders)) {
  24684. orders = orders == null ? [] : [orders];
  24685. }
  24686. return baseOrderBy(collection, iteratees, orders);
  24687. }
  24688. /**
  24689. * Creates an array of elements split into two groups, the first of which
  24690. * contains elements `predicate` returns truthy for, the second of which
  24691. * contains elements `predicate` returns falsey for. The predicate is
  24692. * invoked with one argument: (value).
  24693. *
  24694. * @static
  24695. * @memberOf _
  24696. * @since 3.0.0
  24697. * @category Collection
  24698. * @param {Array|Object} collection The collection to iterate over.
  24699. * @param {Array|Function|Object|string} [predicate=_.identity]
  24700. * The function invoked per iteration.
  24701. * @returns {Array} Returns the array of grouped elements.
  24702. * @example
  24703. *
  24704. * var users = [
  24705. * { 'user': 'barney', 'age': 36, 'active': false },
  24706. * { 'user': 'fred', 'age': 40, 'active': true },
  24707. * { 'user': 'pebbles', 'age': 1, 'active': false }
  24708. * ];
  24709. *
  24710. * _.partition(users, function(o) { return o.active; });
  24711. * // => objects for [['fred'], ['barney', 'pebbles']]
  24712. *
  24713. * // The `_.matches` iteratee shorthand.
  24714. * _.partition(users, { 'age': 1, 'active': false });
  24715. * // => objects for [['pebbles'], ['barney', 'fred']]
  24716. *
  24717. * // The `_.matchesProperty` iteratee shorthand.
  24718. * _.partition(users, ['active', false]);
  24719. * // => objects for [['barney', 'pebbles'], ['fred']]
  24720. *
  24721. * // The `_.property` iteratee shorthand.
  24722. * _.partition(users, 'active');
  24723. * // => objects for [['fred'], ['barney', 'pebbles']]
  24724. */
  24725. var partition = createAggregator(function(result, value, key) {
  24726. result[key ? 0 : 1].push(value);
  24727. }, function() { return [[], []]; });
  24728. /**
  24729. * Reduces `collection` to a value which is the accumulated result of running
  24730. * each element in `collection` thru `iteratee`, where each successive
  24731. * invocation is supplied the return value of the previous. If `accumulator`
  24732. * is not given, the first element of `collection` is used as the initial
  24733. * value. The iteratee is invoked with four arguments:
  24734. * (accumulator, value, index|key, collection).
  24735. *
  24736. * Many lodash methods are guarded to work as iteratees for methods like
  24737. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  24738. *
  24739. * The guarded methods are:
  24740. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  24741. * and `sortBy`
  24742. *
  24743. * @static
  24744. * @memberOf _
  24745. * @since 0.1.0
  24746. * @category Collection
  24747. * @param {Array|Object} collection The collection to iterate over.
  24748. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  24749. * @param {*} [accumulator] The initial value.
  24750. * @returns {*} Returns the accumulated value.
  24751. * @see _.reduceRight
  24752. * @example
  24753. *
  24754. * _.reduce([1, 2], function(sum, n) {
  24755. * return sum + n;
  24756. * }, 0);
  24757. * // => 3
  24758. *
  24759. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  24760. * (result[value] || (result[value] = [])).push(key);
  24761. * return result;
  24762. * }, {});
  24763. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  24764. */
  24765. function reduce(collection, iteratee, accumulator) {
  24766. var func = isArray(collection) ? arrayReduce : baseReduce,
  24767. initAccum = arguments.length < 3;
  24768. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  24769. }
  24770. /**
  24771. * This method is like `_.reduce` except that it iterates over elements of
  24772. * `collection` from right to left.
  24773. *
  24774. * @static
  24775. * @memberOf _
  24776. * @since 0.1.0
  24777. * @category Collection
  24778. * @param {Array|Object} collection The collection to iterate over.
  24779. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  24780. * @param {*} [accumulator] The initial value.
  24781. * @returns {*} Returns the accumulated value.
  24782. * @see _.reduce
  24783. * @example
  24784. *
  24785. * var array = [[0, 1], [2, 3], [4, 5]];
  24786. *
  24787. * _.reduceRight(array, function(flattened, other) {
  24788. * return flattened.concat(other);
  24789. * }, []);
  24790. * // => [4, 5, 2, 3, 0, 1]
  24791. */
  24792. function reduceRight(collection, iteratee, accumulator) {
  24793. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  24794. initAccum = arguments.length < 3;
  24795. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  24796. }
  24797. /**
  24798. * The opposite of `_.filter`; this method returns the elements of `collection`
  24799. * that `predicate` does **not** return truthy for.
  24800. *
  24801. * @static
  24802. * @memberOf _
  24803. * @since 0.1.0
  24804. * @category Collection
  24805. * @param {Array|Object} collection The collection to iterate over.
  24806. * @param {Array|Function|Object|string} [predicate=_.identity]
  24807. * The function invoked per iteration.
  24808. * @returns {Array} Returns the new filtered array.
  24809. * @see _.filter
  24810. * @example
  24811. *
  24812. * var users = [
  24813. * { 'user': 'barney', 'age': 36, 'active': false },
  24814. * { 'user': 'fred', 'age': 40, 'active': true }
  24815. * ];
  24816. *
  24817. * _.reject(users, function(o) { return !o.active; });
  24818. * // => objects for ['fred']
  24819. *
  24820. * // The `_.matches` iteratee shorthand.
  24821. * _.reject(users, { 'age': 40, 'active': true });
  24822. * // => objects for ['barney']
  24823. *
  24824. * // The `_.matchesProperty` iteratee shorthand.
  24825. * _.reject(users, ['active', false]);
  24826. * // => objects for ['fred']
  24827. *
  24828. * // The `_.property` iteratee shorthand.
  24829. * _.reject(users, 'active');
  24830. * // => objects for ['barney']
  24831. */
  24832. function reject(collection, predicate) {
  24833. var func = isArray(collection) ? arrayFilter : baseFilter;
  24834. predicate = getIteratee(predicate, 3);
  24835. return func(collection, function(value, index, collection) {
  24836. return !predicate(value, index, collection);
  24837. });
  24838. }
  24839. /**
  24840. * Gets a random element from `collection`.
  24841. *
  24842. * @static
  24843. * @memberOf _
  24844. * @since 2.0.0
  24845. * @category Collection
  24846. * @param {Array|Object} collection The collection to sample.
  24847. * @returns {*} Returns the random element.
  24848. * @example
  24849. *
  24850. * _.sample([1, 2, 3, 4]);
  24851. * // => 2
  24852. */
  24853. function sample(collection) {
  24854. var array = isArrayLike(collection) ? collection : values(collection),
  24855. length = array.length;
  24856. return length > 0 ? array[baseRandom(0, length - 1)] : undefined;
  24857. }
  24858. /**
  24859. * Gets `n` random elements at unique keys from `collection` up to the
  24860. * size of `collection`.
  24861. *
  24862. * @static
  24863. * @memberOf _
  24864. * @since 4.0.0
  24865. * @category Collection
  24866. * @param {Array|Object} collection The collection to sample.
  24867. * @param {number} [n=1] The number of elements to sample.
  24868. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  24869. * @returns {Array} Returns the random elements.
  24870. * @example
  24871. *
  24872. * _.sampleSize([1, 2, 3], 2);
  24873. * // => [3, 1]
  24874. *
  24875. * _.sampleSize([1, 2, 3], 4);
  24876. * // => [2, 3, 1]
  24877. */
  24878. function sampleSize(collection, n, guard) {
  24879. var index = -1,
  24880. result = toArray(collection),
  24881. length = result.length,
  24882. lastIndex = length - 1;
  24883. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  24884. n = 1;
  24885. } else {
  24886. n = baseClamp(toInteger(n), 0, length);
  24887. }
  24888. while (++index < n) {
  24889. var rand = baseRandom(index, lastIndex),
  24890. value = result[rand];
  24891. result[rand] = result[index];
  24892. result[index] = value;
  24893. }
  24894. result.length = n;
  24895. return result;
  24896. }
  24897. /**
  24898. * Creates an array of shuffled values, using a version of the
  24899. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  24900. *
  24901. * @static
  24902. * @memberOf _
  24903. * @since 0.1.0
  24904. * @category Collection
  24905. * @param {Array|Object} collection The collection to shuffle.
  24906. * @returns {Array} Returns the new shuffled array.
  24907. * @example
  24908. *
  24909. * _.shuffle([1, 2, 3, 4]);
  24910. * // => [4, 1, 3, 2]
  24911. */
  24912. function shuffle(collection) {
  24913. return sampleSize(collection, MAX_ARRAY_LENGTH);
  24914. }
  24915. /**
  24916. * Gets the size of `collection` by returning its length for array-like
  24917. * values or the number of own enumerable string keyed properties for objects.
  24918. *
  24919. * @static
  24920. * @memberOf _
  24921. * @since 0.1.0
  24922. * @category Collection
  24923. * @param {Array|Object} collection The collection to inspect.
  24924. * @returns {number} Returns the collection size.
  24925. * @example
  24926. *
  24927. * _.size([1, 2, 3]);
  24928. * // => 3
  24929. *
  24930. * _.size({ 'a': 1, 'b': 2 });
  24931. * // => 2
  24932. *
  24933. * _.size('pebbles');
  24934. * // => 7
  24935. */
  24936. function size(collection) {
  24937. if (collection == null) {
  24938. return 0;
  24939. }
  24940. if (isArrayLike(collection)) {
  24941. var result = collection.length;
  24942. return (result && isString(collection)) ? stringSize(collection) : result;
  24943. }
  24944. if (isObjectLike(collection)) {
  24945. var tag = getTag(collection);
  24946. if (tag == mapTag || tag == setTag) {
  24947. return collection.size;
  24948. }
  24949. }
  24950. return keys(collection).length;
  24951. }
  24952. /**
  24953. * Checks if `predicate` returns truthy for **any** element of `collection`.
  24954. * Iteration is stopped once `predicate` returns truthy. The predicate is
  24955. * invoked with three arguments: (value, index|key, collection).
  24956. *
  24957. * @static
  24958. * @memberOf _
  24959. * @since 0.1.0
  24960. * @category Collection
  24961. * @param {Array|Object} collection The collection to iterate over.
  24962. * @param {Array|Function|Object|string} [predicate=_.identity]
  24963. * The function invoked per iteration.
  24964. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  24965. * @returns {boolean} Returns `true` if any element passes the predicate check,
  24966. * else `false`.
  24967. * @example
  24968. *
  24969. * _.some([null, 0, 'yes', false], Boolean);
  24970. * // => true
  24971. *
  24972. * var users = [
  24973. * { 'user': 'barney', 'active': true },
  24974. * { 'user': 'fred', 'active': false }
  24975. * ];
  24976. *
  24977. * // The `_.matches` iteratee shorthand.
  24978. * _.some(users, { 'user': 'barney', 'active': false });
  24979. * // => false
  24980. *
  24981. * // The `_.matchesProperty` iteratee shorthand.
  24982. * _.some(users, ['active', false]);
  24983. * // => true
  24984. *
  24985. * // The `_.property` iteratee shorthand.
  24986. * _.some(users, 'active');
  24987. * // => true
  24988. */
  24989. function some(collection, predicate, guard) {
  24990. var func = isArray(collection) ? arraySome : baseSome;
  24991. if (guard && isIterateeCall(collection, predicate, guard)) {
  24992. predicate = undefined;
  24993. }
  24994. return func(collection, getIteratee(predicate, 3));
  24995. }
  24996. /**
  24997. * Creates an array of elements, sorted in ascending order by the results of
  24998. * running each element in a collection thru each iteratee. This method
  24999. * performs a stable sort, that is, it preserves the original sort order of
  25000. * equal elements. The iteratees are invoked with one argument: (value).
  25001. *
  25002. * @static
  25003. * @memberOf _
  25004. * @since 0.1.0
  25005. * @category Collection
  25006. * @param {Array|Object} collection The collection to iterate over.
  25007. * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
  25008. * [iteratees=[_.identity]] The iteratees to sort by.
  25009. * @returns {Array} Returns the new sorted array.
  25010. * @example
  25011. *
  25012. * var users = [
  25013. * { 'user': 'fred', 'age': 48 },
  25014. * { 'user': 'barney', 'age': 36 },
  25015. * { 'user': 'fred', 'age': 40 },
  25016. * { 'user': 'barney', 'age': 34 }
  25017. * ];
  25018. *
  25019. * _.sortBy(users, function(o) { return o.user; });
  25020. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  25021. *
  25022. * _.sortBy(users, ['user', 'age']);
  25023. * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
  25024. *
  25025. * _.sortBy(users, 'user', function(o) {
  25026. * return Math.floor(o.age / 10);
  25027. * });
  25028. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  25029. */
  25030. var sortBy = rest(function(collection, iteratees) {
  25031. if (collection == null) {
  25032. return [];
  25033. }
  25034. var length = iteratees.length;
  25035. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  25036. iteratees = [];
  25037. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  25038. iteratees = [iteratees[0]];
  25039. }
  25040. iteratees = (iteratees.length == 1 && isArray(iteratees[0]))
  25041. ? iteratees[0]
  25042. : baseFlatten(iteratees, 1, isFlattenableIteratee);
  25043. return baseOrderBy(collection, iteratees, []);
  25044. });
  25045. /*------------------------------------------------------------------------*/
  25046. /**
  25047. * Gets the timestamp of the number of milliseconds that have elapsed since
  25048. * the Unix epoch (1 January 1970 00:00:00 UTC).
  25049. *
  25050. * @static
  25051. * @memberOf _
  25052. * @since 2.4.0
  25053. * @category Date
  25054. * @returns {number} Returns the timestamp.
  25055. * @example
  25056. *
  25057. * _.defer(function(stamp) {
  25058. * console.log(_.now() - stamp);
  25059. * }, _.now());
  25060. * // => Logs the number of milliseconds it took for the deferred invocation.
  25061. */
  25062. function now() {
  25063. return Date.now();
  25064. }
  25065. /*------------------------------------------------------------------------*/
  25066. /**
  25067. * The opposite of `_.before`; this method creates a function that invokes
  25068. * `func` once it's called `n` or more times.
  25069. *
  25070. * @static
  25071. * @memberOf _
  25072. * @since 0.1.0
  25073. * @category Function
  25074. * @param {number} n The number of calls before `func` is invoked.
  25075. * @param {Function} func The function to restrict.
  25076. * @returns {Function} Returns the new restricted function.
  25077. * @example
  25078. *
  25079. * var saves = ['profile', 'settings'];
  25080. *
  25081. * var done = _.after(saves.length, function() {
  25082. * console.log('done saving!');
  25083. * });
  25084. *
  25085. * _.forEach(saves, function(type) {
  25086. * asyncSave({ 'type': type, 'complete': done });
  25087. * });
  25088. * // => Logs 'done saving!' after the two async saves have completed.
  25089. */
  25090. function after(n, func) {
  25091. if (typeof func != 'function') {
  25092. throw new TypeError(FUNC_ERROR_TEXT);
  25093. }
  25094. n = toInteger(n);
  25095. return function() {
  25096. if (--n < 1) {
  25097. return func.apply(this, arguments);
  25098. }
  25099. };
  25100. }
  25101. /**
  25102. * Creates a function that invokes `func`, with up to `n` arguments,
  25103. * ignoring any additional arguments.
  25104. *
  25105. * @static
  25106. * @memberOf _
  25107. * @since 3.0.0
  25108. * @category Function
  25109. * @param {Function} func The function to cap arguments for.
  25110. * @param {number} [n=func.length] The arity cap.
  25111. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  25112. * @returns {Function} Returns the new capped function.
  25113. * @example
  25114. *
  25115. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  25116. * // => [6, 8, 10]
  25117. */
  25118. function ary(func, n, guard) {
  25119. n = guard ? undefined : n;
  25120. n = (func && n == null) ? func.length : n;
  25121. return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
  25122. }
  25123. /**
  25124. * Creates a function that invokes `func`, with the `this` binding and arguments
  25125. * of the created function, while it's called less than `n` times. Subsequent
  25126. * calls to the created function return the result of the last `func` invocation.
  25127. *
  25128. * @static
  25129. * @memberOf _
  25130. * @since 3.0.0
  25131. * @category Function
  25132. * @param {number} n The number of calls at which `func` is no longer invoked.
  25133. * @param {Function} func The function to restrict.
  25134. * @returns {Function} Returns the new restricted function.
  25135. * @example
  25136. *
  25137. * jQuery(element).on('click', _.before(5, addContactToList));
  25138. * // => allows adding up to 4 contacts to the list
  25139. */
  25140. function before(n, func) {
  25141. var result;
  25142. if (typeof func != 'function') {
  25143. throw new TypeError(FUNC_ERROR_TEXT);
  25144. }
  25145. n = toInteger(n);
  25146. return function() {
  25147. if (--n > 0) {
  25148. result = func.apply(this, arguments);
  25149. }
  25150. if (n <= 1) {
  25151. func = undefined;
  25152. }
  25153. return result;
  25154. };
  25155. }
  25156. /**
  25157. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  25158. * and `partials` prepended to the arguments it receives.
  25159. *
  25160. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  25161. * may be used as a placeholder for partially applied arguments.
  25162. *
  25163. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  25164. * property of bound functions.
  25165. *
  25166. * @static
  25167. * @memberOf _
  25168. * @since 0.1.0
  25169. * @category Function
  25170. * @param {Function} func The function to bind.
  25171. * @param {*} thisArg The `this` binding of `func`.
  25172. * @param {...*} [partials] The arguments to be partially applied.
  25173. * @returns {Function} Returns the new bound function.
  25174. * @example
  25175. *
  25176. * var greet = function(greeting, punctuation) {
  25177. * return greeting + ' ' + this.user + punctuation;
  25178. * };
  25179. *
  25180. * var object = { 'user': 'fred' };
  25181. *
  25182. * var bound = _.bind(greet, object, 'hi');
  25183. * bound('!');
  25184. * // => 'hi fred!'
  25185. *
  25186. * // Bound with placeholders.
  25187. * var bound = _.bind(greet, object, _, '!');
  25188. * bound('hi');
  25189. * // => 'hi fred!'
  25190. */
  25191. var bind = rest(function(func, thisArg, partials) {
  25192. var bitmask = BIND_FLAG;
  25193. if (partials.length) {
  25194. var holders = replaceHolders(partials, getHolder(bind));
  25195. bitmask |= PARTIAL_FLAG;
  25196. }
  25197. return createWrapper(func, bitmask, thisArg, partials, holders);
  25198. });
  25199. /**
  25200. * Creates a function that invokes the method at `object[key]` with `partials`
  25201. * prepended to the arguments it receives.
  25202. *
  25203. * This method differs from `_.bind` by allowing bound functions to reference
  25204. * methods that may be redefined or don't yet exist. See
  25205. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  25206. * for more details.
  25207. *
  25208. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  25209. * builds, may be used as a placeholder for partially applied arguments.
  25210. *
  25211. * @static
  25212. * @memberOf _
  25213. * @since 0.10.0
  25214. * @category Function
  25215. * @param {Object} object The object to invoke the method on.
  25216. * @param {string} key The key of the method.
  25217. * @param {...*} [partials] The arguments to be partially applied.
  25218. * @returns {Function} Returns the new bound function.
  25219. * @example
  25220. *
  25221. * var object = {
  25222. * 'user': 'fred',
  25223. * 'greet': function(greeting, punctuation) {
  25224. * return greeting + ' ' + this.user + punctuation;
  25225. * }
  25226. * };
  25227. *
  25228. * var bound = _.bindKey(object, 'greet', 'hi');
  25229. * bound('!');
  25230. * // => 'hi fred!'
  25231. *
  25232. * object.greet = function(greeting, punctuation) {
  25233. * return greeting + 'ya ' + this.user + punctuation;
  25234. * };
  25235. *
  25236. * bound('!');
  25237. * // => 'hiya fred!'
  25238. *
  25239. * // Bound with placeholders.
  25240. * var bound = _.bindKey(object, 'greet', _, '!');
  25241. * bound('hi');
  25242. * // => 'hiya fred!'
  25243. */
  25244. var bindKey = rest(function(object, key, partials) {
  25245. var bitmask = BIND_FLAG | BIND_KEY_FLAG;
  25246. if (partials.length) {
  25247. var holders = replaceHolders(partials, getHolder(bindKey));
  25248. bitmask |= PARTIAL_FLAG;
  25249. }
  25250. return createWrapper(key, bitmask, object, partials, holders);
  25251. });
  25252. /**
  25253. * Creates a function that accepts arguments of `func` and either invokes
  25254. * `func` returning its result, if at least `arity` number of arguments have
  25255. * been provided, or returns a function that accepts the remaining `func`
  25256. * arguments, and so on. The arity of `func` may be specified if `func.length`
  25257. * is not sufficient.
  25258. *
  25259. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  25260. * may be used as a placeholder for provided arguments.
  25261. *
  25262. * **Note:** This method doesn't set the "length" property of curried functions.
  25263. *
  25264. * @static
  25265. * @memberOf _
  25266. * @since 2.0.0
  25267. * @category Function
  25268. * @param {Function} func The function to curry.
  25269. * @param {number} [arity=func.length] The arity of `func`.
  25270. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  25271. * @returns {Function} Returns the new curried function.
  25272. * @example
  25273. *
  25274. * var abc = function(a, b, c) {
  25275. * return [a, b, c];
  25276. * };
  25277. *
  25278. * var curried = _.curry(abc);
  25279. *
  25280. * curried(1)(2)(3);
  25281. * // => [1, 2, 3]
  25282. *
  25283. * curried(1, 2)(3);
  25284. * // => [1, 2, 3]
  25285. *
  25286. * curried(1, 2, 3);
  25287. * // => [1, 2, 3]
  25288. *
  25289. * // Curried with placeholders.
  25290. * curried(1)(_, 3)(2);
  25291. * // => [1, 2, 3]
  25292. */
  25293. function curry(func, arity, guard) {
  25294. arity = guard ? undefined : arity;
  25295. var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  25296. result.placeholder = curry.placeholder;
  25297. return result;
  25298. }
  25299. /**
  25300. * This method is like `_.curry` except that arguments are applied to `func`
  25301. * in the manner of `_.partialRight` instead of `_.partial`.
  25302. *
  25303. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  25304. * builds, may be used as a placeholder for provided arguments.
  25305. *
  25306. * **Note:** This method doesn't set the "length" property of curried functions.
  25307. *
  25308. * @static
  25309. * @memberOf _
  25310. * @since 3.0.0
  25311. * @category Function
  25312. * @param {Function} func The function to curry.
  25313. * @param {number} [arity=func.length] The arity of `func`.
  25314. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  25315. * @returns {Function} Returns the new curried function.
  25316. * @example
  25317. *
  25318. * var abc = function(a, b, c) {
  25319. * return [a, b, c];
  25320. * };
  25321. *
  25322. * var curried = _.curryRight(abc);
  25323. *
  25324. * curried(3)(2)(1);
  25325. * // => [1, 2, 3]
  25326. *
  25327. * curried(2, 3)(1);
  25328. * // => [1, 2, 3]
  25329. *
  25330. * curried(1, 2, 3);
  25331. * // => [1, 2, 3]
  25332. *
  25333. * // Curried with placeholders.
  25334. * curried(3)(1, _)(2);
  25335. * // => [1, 2, 3]
  25336. */
  25337. function curryRight(func, arity, guard) {
  25338. arity = guard ? undefined : arity;
  25339. var result = createWrapper(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  25340. result.placeholder = curryRight.placeholder;
  25341. return result;
  25342. }
  25343. /**
  25344. * Creates a debounced function that delays invoking `func` until after `wait`
  25345. * milliseconds have elapsed since the last time the debounced function was
  25346. * invoked. The debounced function comes with a `cancel` method to cancel
  25347. * delayed `func` invocations and a `flush` method to immediately invoke them.
  25348. * Provide an options object to indicate whether `func` should be invoked on
  25349. * the leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  25350. * with the last arguments provided to the debounced function. Subsequent calls
  25351. * to the debounced function return the result of the last `func` invocation.
  25352. *
  25353. * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
  25354. * on the trailing edge of the timeout only if the debounced function is
  25355. * invoked more than once during the `wait` timeout.
  25356. *
  25357. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  25358. * for details over the differences between `_.debounce` and `_.throttle`.
  25359. *
  25360. * @static
  25361. * @memberOf _
  25362. * @since 0.1.0
  25363. * @category Function
  25364. * @param {Function} func The function to debounce.
  25365. * @param {number} [wait=0] The number of milliseconds to delay.
  25366. * @param {Object} [options={}] The options object.
  25367. * @param {boolean} [options.leading=false]
  25368. * Specify invoking on the leading edge of the timeout.
  25369. * @param {number} [options.maxWait]
  25370. * The maximum time `func` is allowed to be delayed before it's invoked.
  25371. * @param {boolean} [options.trailing=true]
  25372. * Specify invoking on the trailing edge of the timeout.
  25373. * @returns {Function} Returns the new debounced function.
  25374. * @example
  25375. *
  25376. * // Avoid costly calculations while the window size is in flux.
  25377. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  25378. *
  25379. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  25380. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  25381. * 'leading': true,
  25382. * 'trailing': false
  25383. * }));
  25384. *
  25385. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  25386. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  25387. * var source = new EventSource('/stream');
  25388. * jQuery(source).on('message', debounced);
  25389. *
  25390. * // Cancel the trailing debounced invocation.
  25391. * jQuery(window).on('popstate', debounced.cancel);
  25392. */
  25393. function debounce(func, wait, options) {
  25394. var lastArgs,
  25395. lastThis,
  25396. maxWait,
  25397. result,
  25398. timerId,
  25399. lastCallTime,
  25400. lastInvokeTime = 0,
  25401. leading = false,
  25402. maxing = false,
  25403. trailing = true;
  25404. if (typeof func != 'function') {
  25405. throw new TypeError(FUNC_ERROR_TEXT);
  25406. }
  25407. wait = toNumber(wait) || 0;
  25408. if (isObject(options)) {
  25409. leading = !!options.leading;
  25410. maxing = 'maxWait' in options;
  25411. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  25412. trailing = 'trailing' in options ? !!options.trailing : trailing;
  25413. }
  25414. function invokeFunc(time) {
  25415. var args = lastArgs,
  25416. thisArg = lastThis;
  25417. lastArgs = lastThis = undefined;
  25418. lastInvokeTime = time;
  25419. result = func.apply(thisArg, args);
  25420. return result;
  25421. }
  25422. function leadingEdge(time) {
  25423. // Reset any `maxWait` timer.
  25424. lastInvokeTime = time;
  25425. // Start the timer for the trailing edge.
  25426. timerId = setTimeout(timerExpired, wait);
  25427. // Invoke the leading edge.
  25428. return leading ? invokeFunc(time) : result;
  25429. }
  25430. function remainingWait(time) {
  25431. var timeSinceLastCall = time - lastCallTime,
  25432. timeSinceLastInvoke = time - lastInvokeTime,
  25433. result = wait - timeSinceLastCall;
  25434. return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;
  25435. }
  25436. function shouldInvoke(time) {
  25437. var timeSinceLastCall = time - lastCallTime,
  25438. timeSinceLastInvoke = time - lastInvokeTime;
  25439. // Either this is the first call, activity has stopped and we're at the
  25440. // trailing edge, the system time has gone backwards and we're treating
  25441. // it as the trailing edge, or we've hit the `maxWait` limit.
  25442. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  25443. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  25444. }
  25445. function timerExpired() {
  25446. var time = now();
  25447. if (shouldInvoke(time)) {
  25448. return trailingEdge(time);
  25449. }
  25450. // Restart the timer.
  25451. timerId = setTimeout(timerExpired, remainingWait(time));
  25452. }
  25453. function trailingEdge(time) {
  25454. timerId = undefined;
  25455. // Only invoke if we have `lastArgs` which means `func` has been
  25456. // debounced at least once.
  25457. if (trailing && lastArgs) {
  25458. return invokeFunc(time);
  25459. }
  25460. lastArgs = lastThis = undefined;
  25461. return result;
  25462. }
  25463. function cancel() {
  25464. lastInvokeTime = 0;
  25465. lastArgs = lastCallTime = lastThis = timerId = undefined;
  25466. }
  25467. function flush() {
  25468. return timerId === undefined ? result : trailingEdge(now());
  25469. }
  25470. function debounced() {
  25471. var time = now(),
  25472. isInvoking = shouldInvoke(time);
  25473. lastArgs = arguments;
  25474. lastThis = this;
  25475. lastCallTime = time;
  25476. if (isInvoking) {
  25477. if (timerId === undefined) {
  25478. return leadingEdge(lastCallTime);
  25479. }
  25480. if (maxing) {
  25481. // Handle invocations in a tight loop.
  25482. timerId = setTimeout(timerExpired, wait);
  25483. return invokeFunc(lastCallTime);
  25484. }
  25485. }
  25486. if (timerId === undefined) {
  25487. timerId = setTimeout(timerExpired, wait);
  25488. }
  25489. return result;
  25490. }
  25491. debounced.cancel = cancel;
  25492. debounced.flush = flush;
  25493. return debounced;
  25494. }
  25495. /**
  25496. * Defers invoking the `func` until the current call stack has cleared. Any
  25497. * additional arguments are provided to `func` when it's invoked.
  25498. *
  25499. * @static
  25500. * @memberOf _
  25501. * @since 0.1.0
  25502. * @category Function
  25503. * @param {Function} func The function to defer.
  25504. * @param {...*} [args] The arguments to invoke `func` with.
  25505. * @returns {number} Returns the timer id.
  25506. * @example
  25507. *
  25508. * _.defer(function(text) {
  25509. * console.log(text);
  25510. * }, 'deferred');
  25511. * // => Logs 'deferred' after one or more milliseconds.
  25512. */
  25513. var defer = rest(function(func, args) {
  25514. return baseDelay(func, 1, args);
  25515. });
  25516. /**
  25517. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  25518. * provided to `func` when it's invoked.
  25519. *
  25520. * @static
  25521. * @memberOf _
  25522. * @since 0.1.0
  25523. * @category Function
  25524. * @param {Function} func The function to delay.
  25525. * @param {number} wait The number of milliseconds to delay invocation.
  25526. * @param {...*} [args] The arguments to invoke `func` with.
  25527. * @returns {number} Returns the timer id.
  25528. * @example
  25529. *
  25530. * _.delay(function(text) {
  25531. * console.log(text);
  25532. * }, 1000, 'later');
  25533. * // => Logs 'later' after one second.
  25534. */
  25535. var delay = rest(function(func, wait, args) {
  25536. return baseDelay(func, toNumber(wait) || 0, args);
  25537. });
  25538. /**
  25539. * Creates a function that invokes `func` with arguments reversed.
  25540. *
  25541. * @static
  25542. * @memberOf _
  25543. * @since 4.0.0
  25544. * @category Function
  25545. * @param {Function} func The function to flip arguments for.
  25546. * @returns {Function} Returns the new flipped function.
  25547. * @example
  25548. *
  25549. * var flipped = _.flip(function() {
  25550. * return _.toArray(arguments);
  25551. * });
  25552. *
  25553. * flipped('a', 'b', 'c', 'd');
  25554. * // => ['d', 'c', 'b', 'a']
  25555. */
  25556. function flip(func) {
  25557. return createWrapper(func, FLIP_FLAG);
  25558. }
  25559. /**
  25560. * Creates a function that memoizes the result of `func`. If `resolver` is
  25561. * provided, it determines the cache key for storing the result based on the
  25562. * arguments provided to the memoized function. By default, the first argument
  25563. * provided to the memoized function is used as the map cache key. The `func`
  25564. * is invoked with the `this` binding of the memoized function.
  25565. *
  25566. * **Note:** The cache is exposed as the `cache` property on the memoized
  25567. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  25568. * constructor with one whose instances implement the
  25569. * [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
  25570. * method interface of `delete`, `get`, `has`, and `set`.
  25571. *
  25572. * @static
  25573. * @memberOf _
  25574. * @since 0.1.0
  25575. * @category Function
  25576. * @param {Function} func The function to have its output memoized.
  25577. * @param {Function} [resolver] The function to resolve the cache key.
  25578. * @returns {Function} Returns the new memoized function.
  25579. * @example
  25580. *
  25581. * var object = { 'a': 1, 'b': 2 };
  25582. * var other = { 'c': 3, 'd': 4 };
  25583. *
  25584. * var values = _.memoize(_.values);
  25585. * values(object);
  25586. * // => [1, 2]
  25587. *
  25588. * values(other);
  25589. * // => [3, 4]
  25590. *
  25591. * object.a = 2;
  25592. * values(object);
  25593. * // => [1, 2]
  25594. *
  25595. * // Modify the result cache.
  25596. * values.cache.set(object, ['a', 'b']);
  25597. * values(object);
  25598. * // => ['a', 'b']
  25599. *
  25600. * // Replace `_.memoize.Cache`.
  25601. * _.memoize.Cache = WeakMap;
  25602. */
  25603. function memoize(func, resolver) {
  25604. if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
  25605. throw new TypeError(FUNC_ERROR_TEXT);
  25606. }
  25607. var memoized = function() {
  25608. var args = arguments,
  25609. key = resolver ? resolver.apply(this, args) : args[0],
  25610. cache = memoized.cache;
  25611. if (cache.has(key)) {
  25612. return cache.get(key);
  25613. }
  25614. var result = func.apply(this, args);
  25615. memoized.cache = cache.set(key, result);
  25616. return result;
  25617. };
  25618. memoized.cache = new (memoize.Cache || MapCache);
  25619. return memoized;
  25620. }
  25621. // Assign cache to `_.memoize`.
  25622. memoize.Cache = MapCache;
  25623. /**
  25624. * Creates a function that negates the result of the predicate `func`. The
  25625. * `func` predicate is invoked with the `this` binding and arguments of the
  25626. * created function.
  25627. *
  25628. * @static
  25629. * @memberOf _
  25630. * @since 3.0.0
  25631. * @category Function
  25632. * @param {Function} predicate The predicate to negate.
  25633. * @returns {Function} Returns the new negated function.
  25634. * @example
  25635. *
  25636. * function isEven(n) {
  25637. * return n % 2 == 0;
  25638. * }
  25639. *
  25640. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  25641. * // => [1, 3, 5]
  25642. */
  25643. function negate(predicate) {
  25644. if (typeof predicate != 'function') {
  25645. throw new TypeError(FUNC_ERROR_TEXT);
  25646. }
  25647. return function() {
  25648. return !predicate.apply(this, arguments);
  25649. };
  25650. }
  25651. /**
  25652. * Creates a function that is restricted to invoking `func` once. Repeat calls
  25653. * to the function return the value of the first invocation. The `func` is
  25654. * invoked with the `this` binding and arguments of the created function.
  25655. *
  25656. * @static
  25657. * @memberOf _
  25658. * @since 0.1.0
  25659. * @category Function
  25660. * @param {Function} func The function to restrict.
  25661. * @returns {Function} Returns the new restricted function.
  25662. * @example
  25663. *
  25664. * var initialize = _.once(createApplication);
  25665. * initialize();
  25666. * initialize();
  25667. * // `initialize` invokes `createApplication` once
  25668. */
  25669. function once(func) {
  25670. return before(2, func);
  25671. }
  25672. /**
  25673. * Creates a function that invokes `func` with arguments transformed by
  25674. * corresponding `transforms`.
  25675. *
  25676. * @static
  25677. * @since 4.0.0
  25678. * @memberOf _
  25679. * @category Function
  25680. * @param {Function} func The function to wrap.
  25681. * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
  25682. * [transforms[_.identity]] The functions to transform.
  25683. * @returns {Function} Returns the new function.
  25684. * @example
  25685. *
  25686. * function doubled(n) {
  25687. * return n * 2;
  25688. * }
  25689. *
  25690. * function square(n) {
  25691. * return n * n;
  25692. * }
  25693. *
  25694. * var func = _.overArgs(function(x, y) {
  25695. * return [x, y];
  25696. * }, [square, doubled]);
  25697. *
  25698. * func(9, 3);
  25699. * // => [81, 6]
  25700. *
  25701. * func(10, 5);
  25702. * // => [100, 10]
  25703. */
  25704. var overArgs = rest(function(func, transforms) {
  25705. transforms = (transforms.length == 1 && isArray(transforms[0]))
  25706. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  25707. : arrayMap(baseFlatten(transforms, 1, isFlattenableIteratee), baseUnary(getIteratee()));
  25708. var funcsLength = transforms.length;
  25709. return rest(function(args) {
  25710. var index = -1,
  25711. length = nativeMin(args.length, funcsLength);
  25712. while (++index < length) {
  25713. args[index] = transforms[index].call(this, args[index]);
  25714. }
  25715. return apply(func, this, args);
  25716. });
  25717. });
  25718. /**
  25719. * Creates a function that invokes `func` with `partials` prepended to the
  25720. * arguments it receives. This method is like `_.bind` except it does **not**
  25721. * alter the `this` binding.
  25722. *
  25723. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  25724. * builds, may be used as a placeholder for partially applied arguments.
  25725. *
  25726. * **Note:** This method doesn't set the "length" property of partially
  25727. * applied functions.
  25728. *
  25729. * @static
  25730. * @memberOf _
  25731. * @since 0.2.0
  25732. * @category Function
  25733. * @param {Function} func The function to partially apply arguments to.
  25734. * @param {...*} [partials] The arguments to be partially applied.
  25735. * @returns {Function} Returns the new partially applied function.
  25736. * @example
  25737. *
  25738. * var greet = function(greeting, name) {
  25739. * return greeting + ' ' + name;
  25740. * };
  25741. *
  25742. * var sayHelloTo = _.partial(greet, 'hello');
  25743. * sayHelloTo('fred');
  25744. * // => 'hello fred'
  25745. *
  25746. * // Partially applied with placeholders.
  25747. * var greetFred = _.partial(greet, _, 'fred');
  25748. * greetFred('hi');
  25749. * // => 'hi fred'
  25750. */
  25751. var partial = rest(function(func, partials) {
  25752. var holders = replaceHolders(partials, getHolder(partial));
  25753. return createWrapper(func, PARTIAL_FLAG, undefined, partials, holders);
  25754. });
  25755. /**
  25756. * This method is like `_.partial` except that partially applied arguments
  25757. * are appended to the arguments it receives.
  25758. *
  25759. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  25760. * builds, may be used as a placeholder for partially applied arguments.
  25761. *
  25762. * **Note:** This method doesn't set the "length" property of partially
  25763. * applied functions.
  25764. *
  25765. * @static
  25766. * @memberOf _
  25767. * @since 1.0.0
  25768. * @category Function
  25769. * @param {Function} func The function to partially apply arguments to.
  25770. * @param {...*} [partials] The arguments to be partially applied.
  25771. * @returns {Function} Returns the new partially applied function.
  25772. * @example
  25773. *
  25774. * var greet = function(greeting, name) {
  25775. * return greeting + ' ' + name;
  25776. * };
  25777. *
  25778. * var greetFred = _.partialRight(greet, 'fred');
  25779. * greetFred('hi');
  25780. * // => 'hi fred'
  25781. *
  25782. * // Partially applied with placeholders.
  25783. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  25784. * sayHelloTo('fred');
  25785. * // => 'hello fred'
  25786. */
  25787. var partialRight = rest(function(func, partials) {
  25788. var holders = replaceHolders(partials, getHolder(partialRight));
  25789. return createWrapper(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  25790. });
  25791. /**
  25792. * Creates a function that invokes `func` with arguments arranged according
  25793. * to the specified `indexes` where the argument value at the first index is
  25794. * provided as the first argument, the argument value at the second index is
  25795. * provided as the second argument, and so on.
  25796. *
  25797. * @static
  25798. * @memberOf _
  25799. * @since 3.0.0
  25800. * @category Function
  25801. * @param {Function} func The function to rearrange arguments for.
  25802. * @param {...(number|number[])} indexes The arranged argument indexes.
  25803. * @returns {Function} Returns the new function.
  25804. * @example
  25805. *
  25806. * var rearged = _.rearg(function(a, b, c) {
  25807. * return [a, b, c];
  25808. * }, [2, 0, 1]);
  25809. *
  25810. * rearged('b', 'c', 'a')
  25811. * // => ['a', 'b', 'c']
  25812. */
  25813. var rearg = rest(function(func, indexes) {
  25814. return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes, 1));
  25815. });
  25816. /**
  25817. * Creates a function that invokes `func` with the `this` binding of the
  25818. * created function and arguments from `start` and beyond provided as
  25819. * an array.
  25820. *
  25821. * **Note:** This method is based on the
  25822. * [rest parameter](https://mdn.io/rest_parameters).
  25823. *
  25824. * @static
  25825. * @memberOf _
  25826. * @since 4.0.0
  25827. * @category Function
  25828. * @param {Function} func The function to apply a rest parameter to.
  25829. * @param {number} [start=func.length-1] The start position of the rest parameter.
  25830. * @returns {Function} Returns the new function.
  25831. * @example
  25832. *
  25833. * var say = _.rest(function(what, names) {
  25834. * return what + ' ' + _.initial(names).join(', ') +
  25835. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  25836. * });
  25837. *
  25838. * say('hello', 'fred', 'barney', 'pebbles');
  25839. * // => 'hello fred, barney, & pebbles'
  25840. */
  25841. function rest(func, start) {
  25842. if (typeof func != 'function') {
  25843. throw new TypeError(FUNC_ERROR_TEXT);
  25844. }
  25845. start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
  25846. return function() {
  25847. var args = arguments,
  25848. index = -1,
  25849. length = nativeMax(args.length - start, 0),
  25850. array = Array(length);
  25851. while (++index < length) {
  25852. array[index] = args[start + index];
  25853. }
  25854. switch (start) {
  25855. case 0: return func.call(this, array);
  25856. case 1: return func.call(this, args[0], array);
  25857. case 2: return func.call(this, args[0], args[1], array);
  25858. }
  25859. var otherArgs = Array(start + 1);
  25860. index = -1;
  25861. while (++index < start) {
  25862. otherArgs[index] = args[index];
  25863. }
  25864. otherArgs[start] = array;
  25865. return apply(func, this, otherArgs);
  25866. };
  25867. }
  25868. /**
  25869. * Creates a function that invokes `func` with the `this` binding of the
  25870. * create function and an array of arguments much like
  25871. * [`Function#apply`](http://www.ecma-international.org/ecma-262/6.0/#sec-function.prototype.apply).
  25872. *
  25873. * **Note:** This method is based on the
  25874. * [spread operator](https://mdn.io/spread_operator).
  25875. *
  25876. * @static
  25877. * @memberOf _
  25878. * @since 3.2.0
  25879. * @category Function
  25880. * @param {Function} func The function to spread arguments over.
  25881. * @param {number} [start=0] The start position of the spread.
  25882. * @returns {Function} Returns the new function.
  25883. * @example
  25884. *
  25885. * var say = _.spread(function(who, what) {
  25886. * return who + ' says ' + what;
  25887. * });
  25888. *
  25889. * say(['fred', 'hello']);
  25890. * // => 'fred says hello'
  25891. *
  25892. * var numbers = Promise.all([
  25893. * Promise.resolve(40),
  25894. * Promise.resolve(36)
  25895. * ]);
  25896. *
  25897. * numbers.then(_.spread(function(x, y) {
  25898. * return x + y;
  25899. * }));
  25900. * // => a Promise of 76
  25901. */
  25902. function spread(func, start) {
  25903. if (typeof func != 'function') {
  25904. throw new TypeError(FUNC_ERROR_TEXT);
  25905. }
  25906. start = start === undefined ? 0 : nativeMax(toInteger(start), 0);
  25907. return rest(function(args) {
  25908. var array = args[start],
  25909. otherArgs = castSlice(args, 0, start);
  25910. if (array) {
  25911. arrayPush(otherArgs, array);
  25912. }
  25913. return apply(func, this, otherArgs);
  25914. });
  25915. }
  25916. /**
  25917. * Creates a throttled function that only invokes `func` at most once per
  25918. * every `wait` milliseconds. The throttled function comes with a `cancel`
  25919. * method to cancel delayed `func` invocations and a `flush` method to
  25920. * immediately invoke them. Provide an options object to indicate whether
  25921. * `func` should be invoked on the leading and/or trailing edge of the `wait`
  25922. * timeout. The `func` is invoked with the last arguments provided to the
  25923. * throttled function. Subsequent calls to the throttled function return the
  25924. * result of the last `func` invocation.
  25925. *
  25926. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  25927. * invoked on the trailing edge of the timeout only if the throttled function
  25928. * is invoked more than once during the `wait` timeout.
  25929. *
  25930. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  25931. * for details over the differences between `_.throttle` and `_.debounce`.
  25932. *
  25933. * @static
  25934. * @memberOf _
  25935. * @since 0.1.0
  25936. * @category Function
  25937. * @param {Function} func The function to throttle.
  25938. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  25939. * @param {Object} [options={}] The options object.
  25940. * @param {boolean} [options.leading=true]
  25941. * Specify invoking on the leading edge of the timeout.
  25942. * @param {boolean} [options.trailing=true]
  25943. * Specify invoking on the trailing edge of the timeout.
  25944. * @returns {Function} Returns the new throttled function.
  25945. * @example
  25946. *
  25947. * // Avoid excessively updating the position while scrolling.
  25948. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  25949. *
  25950. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  25951. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  25952. * jQuery(element).on('click', throttled);
  25953. *
  25954. * // Cancel the trailing throttled invocation.
  25955. * jQuery(window).on('popstate', throttled.cancel);
  25956. */
  25957. function throttle(func, wait, options) {
  25958. var leading = true,
  25959. trailing = true;
  25960. if (typeof func != 'function') {
  25961. throw new TypeError(FUNC_ERROR_TEXT);
  25962. }
  25963. if (isObject(options)) {
  25964. leading = 'leading' in options ? !!options.leading : leading;
  25965. trailing = 'trailing' in options ? !!options.trailing : trailing;
  25966. }
  25967. return debounce(func, wait, {
  25968. 'leading': leading,
  25969. 'maxWait': wait,
  25970. 'trailing': trailing
  25971. });
  25972. }
  25973. /**
  25974. * Creates a function that accepts up to one argument, ignoring any
  25975. * additional arguments.
  25976. *
  25977. * @static
  25978. * @memberOf _
  25979. * @since 4.0.0
  25980. * @category Function
  25981. * @param {Function} func The function to cap arguments for.
  25982. * @returns {Function} Returns the new capped function.
  25983. * @example
  25984. *
  25985. * _.map(['6', '8', '10'], _.unary(parseInt));
  25986. * // => [6, 8, 10]
  25987. */
  25988. function unary(func) {
  25989. return ary(func, 1);
  25990. }
  25991. /**
  25992. * Creates a function that provides `value` to the wrapper function as its
  25993. * first argument. Any additional arguments provided to the function are
  25994. * appended to those provided to the wrapper function. The wrapper is invoked
  25995. * with the `this` binding of the created function.
  25996. *
  25997. * @static
  25998. * @memberOf _
  25999. * @since 0.1.0
  26000. * @category Function
  26001. * @param {*} value The value to wrap.
  26002. * @param {Function} [wrapper=identity] The wrapper function.
  26003. * @returns {Function} Returns the new function.
  26004. * @example
  26005. *
  26006. * var p = _.wrap(_.escape, function(func, text) {
  26007. * return '<p>' + func(text) + '</p>';
  26008. * });
  26009. *
  26010. * p('fred, barney, & pebbles');
  26011. * // => '<p>fred, barney, &amp; pebbles</p>'
  26012. */
  26013. function wrap(value, wrapper) {
  26014. wrapper = wrapper == null ? identity : wrapper;
  26015. return partial(wrapper, value);
  26016. }
  26017. /*------------------------------------------------------------------------*/
  26018. /**
  26019. * Casts `value` as an array if it's not one.
  26020. *
  26021. * @static
  26022. * @memberOf _
  26023. * @since 4.4.0
  26024. * @category Lang
  26025. * @param {*} value The value to inspect.
  26026. * @returns {Array} Returns the cast array.
  26027. * @example
  26028. *
  26029. * _.castArray(1);
  26030. * // => [1]
  26031. *
  26032. * _.castArray({ 'a': 1 });
  26033. * // => [{ 'a': 1 }]
  26034. *
  26035. * _.castArray('abc');
  26036. * // => ['abc']
  26037. *
  26038. * _.castArray(null);
  26039. * // => [null]
  26040. *
  26041. * _.castArray(undefined);
  26042. * // => [undefined]
  26043. *
  26044. * _.castArray();
  26045. * // => []
  26046. *
  26047. * var array = [1, 2, 3];
  26048. * console.log(_.castArray(array) === array);
  26049. * // => true
  26050. */
  26051. function castArray() {
  26052. if (!arguments.length) {
  26053. return [];
  26054. }
  26055. var value = arguments[0];
  26056. return isArray(value) ? value : [value];
  26057. }
  26058. /**
  26059. * Creates a shallow clone of `value`.
  26060. *
  26061. * **Note:** This method is loosely based on the
  26062. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  26063. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  26064. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  26065. * arrays. The own enumerable properties of `arguments` objects are cloned
  26066. * as plain objects. An empty object is returned for uncloneable values such
  26067. * as error objects, functions, DOM nodes, and WeakMaps.
  26068. *
  26069. * @static
  26070. * @memberOf _
  26071. * @since 0.1.0
  26072. * @category Lang
  26073. * @param {*} value The value to clone.
  26074. * @returns {*} Returns the cloned value.
  26075. * @see _.cloneDeep
  26076. * @example
  26077. *
  26078. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  26079. *
  26080. * var shallow = _.clone(objects);
  26081. * console.log(shallow[0] === objects[0]);
  26082. * // => true
  26083. */
  26084. function clone(value) {
  26085. return baseClone(value, false, true);
  26086. }
  26087. /**
  26088. * This method is like `_.clone` except that it accepts `customizer` which
  26089. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  26090. * cloning is handled by the method instead. The `customizer` is invoked with
  26091. * up to four arguments; (value [, index|key, object, stack]).
  26092. *
  26093. * @static
  26094. * @memberOf _
  26095. * @since 4.0.0
  26096. * @category Lang
  26097. * @param {*} value The value to clone.
  26098. * @param {Function} [customizer] The function to customize cloning.
  26099. * @returns {*} Returns the cloned value.
  26100. * @see _.cloneDeepWith
  26101. * @example
  26102. *
  26103. * function customizer(value) {
  26104. * if (_.isElement(value)) {
  26105. * return value.cloneNode(false);
  26106. * }
  26107. * }
  26108. *
  26109. * var el = _.cloneWith(document.body, customizer);
  26110. *
  26111. * console.log(el === document.body);
  26112. * // => false
  26113. * console.log(el.nodeName);
  26114. * // => 'BODY'
  26115. * console.log(el.childNodes.length);
  26116. * // => 0
  26117. */
  26118. function cloneWith(value, customizer) {
  26119. return baseClone(value, false, true, customizer);
  26120. }
  26121. /**
  26122. * This method is like `_.clone` except that it recursively clones `value`.
  26123. *
  26124. * @static
  26125. * @memberOf _
  26126. * @since 1.0.0
  26127. * @category Lang
  26128. * @param {*} value The value to recursively clone.
  26129. * @returns {*} Returns the deep cloned value.
  26130. * @see _.clone
  26131. * @example
  26132. *
  26133. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  26134. *
  26135. * var deep = _.cloneDeep(objects);
  26136. * console.log(deep[0] === objects[0]);
  26137. * // => false
  26138. */
  26139. function cloneDeep(value) {
  26140. return baseClone(value, true, true);
  26141. }
  26142. /**
  26143. * This method is like `_.cloneWith` except that it recursively clones `value`.
  26144. *
  26145. * @static
  26146. * @memberOf _
  26147. * @since 4.0.0
  26148. * @category Lang
  26149. * @param {*} value The value to recursively clone.
  26150. * @param {Function} [customizer] The function to customize cloning.
  26151. * @returns {*} Returns the deep cloned value.
  26152. * @see _.cloneWith
  26153. * @example
  26154. *
  26155. * function customizer(value) {
  26156. * if (_.isElement(value)) {
  26157. * return value.cloneNode(true);
  26158. * }
  26159. * }
  26160. *
  26161. * var el = _.cloneDeepWith(document.body, customizer);
  26162. *
  26163. * console.log(el === document.body);
  26164. * // => false
  26165. * console.log(el.nodeName);
  26166. * // => 'BODY'
  26167. * console.log(el.childNodes.length);
  26168. * // => 20
  26169. */
  26170. function cloneDeepWith(value, customizer) {
  26171. return baseClone(value, true, true, customizer);
  26172. }
  26173. /**
  26174. * Performs a
  26175. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  26176. * comparison between two values to determine if they are equivalent.
  26177. *
  26178. * @static
  26179. * @memberOf _
  26180. * @since 4.0.0
  26181. * @category Lang
  26182. * @param {*} value The value to compare.
  26183. * @param {*} other The other value to compare.
  26184. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  26185. * @example
  26186. *
  26187. * var object = { 'user': 'fred' };
  26188. * var other = { 'user': 'fred' };
  26189. *
  26190. * _.eq(object, object);
  26191. * // => true
  26192. *
  26193. * _.eq(object, other);
  26194. * // => false
  26195. *
  26196. * _.eq('a', 'a');
  26197. * // => true
  26198. *
  26199. * _.eq('a', Object('a'));
  26200. * // => false
  26201. *
  26202. * _.eq(NaN, NaN);
  26203. * // => true
  26204. */
  26205. function eq(value, other) {
  26206. return value === other || (value !== value && other !== other);
  26207. }
  26208. /**
  26209. * Checks if `value` is greater than `other`.
  26210. *
  26211. * @static
  26212. * @memberOf _
  26213. * @since 3.9.0
  26214. * @category Lang
  26215. * @param {*} value The value to compare.
  26216. * @param {*} other The other value to compare.
  26217. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  26218. * else `false`.
  26219. * @see _.lt
  26220. * @example
  26221. *
  26222. * _.gt(3, 1);
  26223. * // => true
  26224. *
  26225. * _.gt(3, 3);
  26226. * // => false
  26227. *
  26228. * _.gt(1, 3);
  26229. * // => false
  26230. */
  26231. var gt = createRelationalOperation(baseGt);
  26232. /**
  26233. * Checks if `value` is greater than or equal to `other`.
  26234. *
  26235. * @static
  26236. * @memberOf _
  26237. * @since 3.9.0
  26238. * @category Lang
  26239. * @param {*} value The value to compare.
  26240. * @param {*} other The other value to compare.
  26241. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  26242. * `other`, else `false`.
  26243. * @see _.lte
  26244. * @example
  26245. *
  26246. * _.gte(3, 1);
  26247. * // => true
  26248. *
  26249. * _.gte(3, 3);
  26250. * // => true
  26251. *
  26252. * _.gte(1, 3);
  26253. * // => false
  26254. */
  26255. var gte = createRelationalOperation(function(value, other) {
  26256. return value >= other;
  26257. });
  26258. /**
  26259. * Checks if `value` is likely an `arguments` object.
  26260. *
  26261. * @static
  26262. * @memberOf _
  26263. * @since 0.1.0
  26264. * @category Lang
  26265. * @param {*} value The value to check.
  26266. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26267. * else `false`.
  26268. * @example
  26269. *
  26270. * _.isArguments(function() { return arguments; }());
  26271. * // => true
  26272. *
  26273. * _.isArguments([1, 2, 3]);
  26274. * // => false
  26275. */
  26276. function isArguments(value) {
  26277. // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
  26278. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  26279. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  26280. }
  26281. /**
  26282. * Checks if `value` is classified as an `Array` object.
  26283. *
  26284. * @static
  26285. * @memberOf _
  26286. * @since 0.1.0
  26287. * @type {Function}
  26288. * @category Lang
  26289. * @param {*} value The value to check.
  26290. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26291. * else `false`.
  26292. * @example
  26293. *
  26294. * _.isArray([1, 2, 3]);
  26295. * // => true
  26296. *
  26297. * _.isArray(document.body.children);
  26298. * // => false
  26299. *
  26300. * _.isArray('abc');
  26301. * // => false
  26302. *
  26303. * _.isArray(_.noop);
  26304. * // => false
  26305. */
  26306. var isArray = Array.isArray;
  26307. /**
  26308. * Checks if `value` is classified as an `ArrayBuffer` object.
  26309. *
  26310. * @static
  26311. * @memberOf _
  26312. * @since 4.3.0
  26313. * @category Lang
  26314. * @param {*} value The value to check.
  26315. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26316. * else `false`.
  26317. * @example
  26318. *
  26319. * _.isArrayBuffer(new ArrayBuffer(2));
  26320. * // => true
  26321. *
  26322. * _.isArrayBuffer(new Array(2));
  26323. * // => false
  26324. */
  26325. function isArrayBuffer(value) {
  26326. return isObjectLike(value) && objectToString.call(value) == arrayBufferTag;
  26327. }
  26328. /**
  26329. * Checks if `value` is array-like. A value is considered array-like if it's
  26330. * not a function and has a `value.length` that's an integer greater than or
  26331. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  26332. *
  26333. * @static
  26334. * @memberOf _
  26335. * @since 4.0.0
  26336. * @category Lang
  26337. * @param {*} value The value to check.
  26338. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  26339. * @example
  26340. *
  26341. * _.isArrayLike([1, 2, 3]);
  26342. * // => true
  26343. *
  26344. * _.isArrayLike(document.body.children);
  26345. * // => true
  26346. *
  26347. * _.isArrayLike('abc');
  26348. * // => true
  26349. *
  26350. * _.isArrayLike(_.noop);
  26351. * // => false
  26352. */
  26353. function isArrayLike(value) {
  26354. return value != null && isLength(getLength(value)) && !isFunction(value);
  26355. }
  26356. /**
  26357. * This method is like `_.isArrayLike` except that it also checks if `value`
  26358. * is an object.
  26359. *
  26360. * @static
  26361. * @memberOf _
  26362. * @since 4.0.0
  26363. * @category Lang
  26364. * @param {*} value The value to check.
  26365. * @returns {boolean} Returns `true` if `value` is an array-like object,
  26366. * else `false`.
  26367. * @example
  26368. *
  26369. * _.isArrayLikeObject([1, 2, 3]);
  26370. * // => true
  26371. *
  26372. * _.isArrayLikeObject(document.body.children);
  26373. * // => true
  26374. *
  26375. * _.isArrayLikeObject('abc');
  26376. * // => false
  26377. *
  26378. * _.isArrayLikeObject(_.noop);
  26379. * // => false
  26380. */
  26381. function isArrayLikeObject(value) {
  26382. return isObjectLike(value) && isArrayLike(value);
  26383. }
  26384. /**
  26385. * Checks if `value` is classified as a boolean primitive or object.
  26386. *
  26387. * @static
  26388. * @memberOf _
  26389. * @since 0.1.0
  26390. * @category Lang
  26391. * @param {*} value The value to check.
  26392. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26393. * else `false`.
  26394. * @example
  26395. *
  26396. * _.isBoolean(false);
  26397. * // => true
  26398. *
  26399. * _.isBoolean(null);
  26400. * // => false
  26401. */
  26402. function isBoolean(value) {
  26403. return value === true || value === false ||
  26404. (isObjectLike(value) && objectToString.call(value) == boolTag);
  26405. }
  26406. /**
  26407. * Checks if `value` is a buffer.
  26408. *
  26409. * @static
  26410. * @memberOf _
  26411. * @since 4.3.0
  26412. * @category Lang
  26413. * @param {*} value The value to check.
  26414. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  26415. * @example
  26416. *
  26417. * _.isBuffer(new Buffer(2));
  26418. * // => true
  26419. *
  26420. * _.isBuffer(new Uint8Array(2));
  26421. * // => false
  26422. */
  26423. var isBuffer = !Buffer ? stubFalse : function(value) {
  26424. return value instanceof Buffer;
  26425. };
  26426. /**
  26427. * Checks if `value` is classified as a `Date` object.
  26428. *
  26429. * @static
  26430. * @memberOf _
  26431. * @since 0.1.0
  26432. * @category Lang
  26433. * @param {*} value The value to check.
  26434. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26435. * else `false`.
  26436. * @example
  26437. *
  26438. * _.isDate(new Date);
  26439. * // => true
  26440. *
  26441. * _.isDate('Mon April 23 2012');
  26442. * // => false
  26443. */
  26444. function isDate(value) {
  26445. return isObjectLike(value) && objectToString.call(value) == dateTag;
  26446. }
  26447. /**
  26448. * Checks if `value` is likely a DOM element.
  26449. *
  26450. * @static
  26451. * @memberOf _
  26452. * @since 0.1.0
  26453. * @category Lang
  26454. * @param {*} value The value to check.
  26455. * @returns {boolean} Returns `true` if `value` is a DOM element,
  26456. * else `false`.
  26457. * @example
  26458. *
  26459. * _.isElement(document.body);
  26460. * // => true
  26461. *
  26462. * _.isElement('<body>');
  26463. * // => false
  26464. */
  26465. function isElement(value) {
  26466. return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
  26467. }
  26468. /**
  26469. * Checks if `value` is an empty object, collection, map, or set.
  26470. *
  26471. * Objects are considered empty if they have no own enumerable string keyed
  26472. * properties.
  26473. *
  26474. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  26475. * jQuery-like collections are considered empty if they have a `length` of `0`.
  26476. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  26477. *
  26478. * @static
  26479. * @memberOf _
  26480. * @since 0.1.0
  26481. * @category Lang
  26482. * @param {*} value The value to check.
  26483. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  26484. * @example
  26485. *
  26486. * _.isEmpty(null);
  26487. * // => true
  26488. *
  26489. * _.isEmpty(true);
  26490. * // => true
  26491. *
  26492. * _.isEmpty(1);
  26493. * // => true
  26494. *
  26495. * _.isEmpty([1, 2, 3]);
  26496. * // => false
  26497. *
  26498. * _.isEmpty({ 'a': 1 });
  26499. * // => false
  26500. */
  26501. function isEmpty(value) {
  26502. if (isArrayLike(value) &&
  26503. (isArray(value) || isString(value) || isFunction(value.splice) ||
  26504. isArguments(value) || isBuffer(value))) {
  26505. return !value.length;
  26506. }
  26507. if (isObjectLike(value)) {
  26508. var tag = getTag(value);
  26509. if (tag == mapTag || tag == setTag) {
  26510. return !value.size;
  26511. }
  26512. }
  26513. for (var key in value) {
  26514. if (hasOwnProperty.call(value, key)) {
  26515. return false;
  26516. }
  26517. }
  26518. return !(nonEnumShadows && keys(value).length);
  26519. }
  26520. /**
  26521. * Performs a deep comparison between two values to determine if they are
  26522. * equivalent.
  26523. *
  26524. * **Note:** This method supports comparing arrays, array buffers, booleans,
  26525. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  26526. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  26527. * by their own, not inherited, enumerable properties. Functions and DOM
  26528. * nodes are **not** supported.
  26529. *
  26530. * @static
  26531. * @memberOf _
  26532. * @since 0.1.0
  26533. * @category Lang
  26534. * @param {*} value The value to compare.
  26535. * @param {*} other The other value to compare.
  26536. * @returns {boolean} Returns `true` if the values are equivalent,
  26537. * else `false`.
  26538. * @example
  26539. *
  26540. * var object = { 'user': 'fred' };
  26541. * var other = { 'user': 'fred' };
  26542. *
  26543. * _.isEqual(object, other);
  26544. * // => true
  26545. *
  26546. * object === other;
  26547. * // => false
  26548. */
  26549. function isEqual(value, other) {
  26550. return baseIsEqual(value, other);
  26551. }
  26552. /**
  26553. * This method is like `_.isEqual` except that it accepts `customizer` which
  26554. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  26555. * are handled by the method instead. The `customizer` is invoked with up to
  26556. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  26557. *
  26558. * @static
  26559. * @memberOf _
  26560. * @since 4.0.0
  26561. * @category Lang
  26562. * @param {*} value The value to compare.
  26563. * @param {*} other The other value to compare.
  26564. * @param {Function} [customizer] The function to customize comparisons.
  26565. * @returns {boolean} Returns `true` if the values are equivalent,
  26566. * else `false`.
  26567. * @example
  26568. *
  26569. * function isGreeting(value) {
  26570. * return /^h(?:i|ello)$/.test(value);
  26571. * }
  26572. *
  26573. * function customizer(objValue, othValue) {
  26574. * if (isGreeting(objValue) && isGreeting(othValue)) {
  26575. * return true;
  26576. * }
  26577. * }
  26578. *
  26579. * var array = ['hello', 'goodbye'];
  26580. * var other = ['hi', 'goodbye'];
  26581. *
  26582. * _.isEqualWith(array, other, customizer);
  26583. * // => true
  26584. */
  26585. function isEqualWith(value, other, customizer) {
  26586. customizer = typeof customizer == 'function' ? customizer : undefined;
  26587. var result = customizer ? customizer(value, other) : undefined;
  26588. return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
  26589. }
  26590. /**
  26591. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  26592. * `SyntaxError`, `TypeError`, or `URIError` object.
  26593. *
  26594. * @static
  26595. * @memberOf _
  26596. * @since 3.0.0
  26597. * @category Lang
  26598. * @param {*} value The value to check.
  26599. * @returns {boolean} Returns `true` if `value` is an error object,
  26600. * else `false`.
  26601. * @example
  26602. *
  26603. * _.isError(new Error);
  26604. * // => true
  26605. *
  26606. * _.isError(Error);
  26607. * // => false
  26608. */
  26609. function isError(value) {
  26610. if (!isObjectLike(value)) {
  26611. return false;
  26612. }
  26613. return (objectToString.call(value) == errorTag) ||
  26614. (typeof value.message == 'string' && typeof value.name == 'string');
  26615. }
  26616. /**
  26617. * Checks if `value` is a finite primitive number.
  26618. *
  26619. * **Note:** This method is based on
  26620. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  26621. *
  26622. * @static
  26623. * @memberOf _
  26624. * @since 0.1.0
  26625. * @category Lang
  26626. * @param {*} value The value to check.
  26627. * @returns {boolean} Returns `true` if `value` is a finite number,
  26628. * else `false`.
  26629. * @example
  26630. *
  26631. * _.isFinite(3);
  26632. * // => true
  26633. *
  26634. * _.isFinite(Number.MIN_VALUE);
  26635. * // => true
  26636. *
  26637. * _.isFinite(Infinity);
  26638. * // => false
  26639. *
  26640. * _.isFinite('3');
  26641. * // => false
  26642. */
  26643. function isFinite(value) {
  26644. return typeof value == 'number' && nativeIsFinite(value);
  26645. }
  26646. /**
  26647. * Checks if `value` is classified as a `Function` object.
  26648. *
  26649. * @static
  26650. * @memberOf _
  26651. * @since 0.1.0
  26652. * @category Lang
  26653. * @param {*} value The value to check.
  26654. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26655. * else `false`.
  26656. * @example
  26657. *
  26658. * _.isFunction(_);
  26659. * // => true
  26660. *
  26661. * _.isFunction(/abc/);
  26662. * // => false
  26663. */
  26664. function isFunction(value) {
  26665. // The use of `Object#toString` avoids issues with the `typeof` operator
  26666. // in Safari 8 which returns 'object' for typed array and weak map constructors,
  26667. // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
  26668. var tag = isObject(value) ? objectToString.call(value) : '';
  26669. return tag == funcTag || tag == genTag;
  26670. }
  26671. /**
  26672. * Checks if `value` is an integer.
  26673. *
  26674. * **Note:** This method is based on
  26675. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  26676. *
  26677. * @static
  26678. * @memberOf _
  26679. * @since 4.0.0
  26680. * @category Lang
  26681. * @param {*} value The value to check.
  26682. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  26683. * @example
  26684. *
  26685. * _.isInteger(3);
  26686. * // => true
  26687. *
  26688. * _.isInteger(Number.MIN_VALUE);
  26689. * // => false
  26690. *
  26691. * _.isInteger(Infinity);
  26692. * // => false
  26693. *
  26694. * _.isInteger('3');
  26695. * // => false
  26696. */
  26697. function isInteger(value) {
  26698. return typeof value == 'number' && value == toInteger(value);
  26699. }
  26700. /**
  26701. * Checks if `value` is a valid array-like length.
  26702. *
  26703. * **Note:** This function is loosely based on
  26704. * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  26705. *
  26706. * @static
  26707. * @memberOf _
  26708. * @since 4.0.0
  26709. * @category Lang
  26710. * @param {*} value The value to check.
  26711. * @returns {boolean} Returns `true` if `value` is a valid length,
  26712. * else `false`.
  26713. * @example
  26714. *
  26715. * _.isLength(3);
  26716. * // => true
  26717. *
  26718. * _.isLength(Number.MIN_VALUE);
  26719. * // => false
  26720. *
  26721. * _.isLength(Infinity);
  26722. * // => false
  26723. *
  26724. * _.isLength('3');
  26725. * // => false
  26726. */
  26727. function isLength(value) {
  26728. return typeof value == 'number' &&
  26729. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  26730. }
  26731. /**
  26732. * Checks if `value` is the
  26733. * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types)
  26734. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  26735. *
  26736. * @static
  26737. * @memberOf _
  26738. * @since 0.1.0
  26739. * @category Lang
  26740. * @param {*} value The value to check.
  26741. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  26742. * @example
  26743. *
  26744. * _.isObject({});
  26745. * // => true
  26746. *
  26747. * _.isObject([1, 2, 3]);
  26748. * // => true
  26749. *
  26750. * _.isObject(_.noop);
  26751. * // => true
  26752. *
  26753. * _.isObject(null);
  26754. * // => false
  26755. */
  26756. function isObject(value) {
  26757. var type = typeof value;
  26758. return !!value && (type == 'object' || type == 'function');
  26759. }
  26760. /**
  26761. * Checks if `value` is object-like. A value is object-like if it's not `null`
  26762. * and has a `typeof` result of "object".
  26763. *
  26764. * @static
  26765. * @memberOf _
  26766. * @since 4.0.0
  26767. * @category Lang
  26768. * @param {*} value The value to check.
  26769. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  26770. * @example
  26771. *
  26772. * _.isObjectLike({});
  26773. * // => true
  26774. *
  26775. * _.isObjectLike([1, 2, 3]);
  26776. * // => true
  26777. *
  26778. * _.isObjectLike(_.noop);
  26779. * // => false
  26780. *
  26781. * _.isObjectLike(null);
  26782. * // => false
  26783. */
  26784. function isObjectLike(value) {
  26785. return !!value && typeof value == 'object';
  26786. }
  26787. /**
  26788. * Checks if `value` is classified as a `Map` object.
  26789. *
  26790. * @static
  26791. * @memberOf _
  26792. * @since 4.3.0
  26793. * @category Lang
  26794. * @param {*} value The value to check.
  26795. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26796. * else `false`.
  26797. * @example
  26798. *
  26799. * _.isMap(new Map);
  26800. * // => true
  26801. *
  26802. * _.isMap(new WeakMap);
  26803. * // => false
  26804. */
  26805. function isMap(value) {
  26806. return isObjectLike(value) && getTag(value) == mapTag;
  26807. }
  26808. /**
  26809. * Performs a partial deep comparison between `object` and `source` to
  26810. * determine if `object` contains equivalent property values. This method is
  26811. * equivalent to a `_.matches` function when `source` is partially applied.
  26812. *
  26813. * **Note:** This method supports comparing the same values as `_.isEqual`.
  26814. *
  26815. * @static
  26816. * @memberOf _
  26817. * @since 3.0.0
  26818. * @category Lang
  26819. * @param {Object} object The object to inspect.
  26820. * @param {Object} source The object of property values to match.
  26821. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  26822. * @example
  26823. *
  26824. * var object = { 'user': 'fred', 'age': 40 };
  26825. *
  26826. * _.isMatch(object, { 'age': 40 });
  26827. * // => true
  26828. *
  26829. * _.isMatch(object, { 'age': 36 });
  26830. * // => false
  26831. */
  26832. function isMatch(object, source) {
  26833. return object === source || baseIsMatch(object, source, getMatchData(source));
  26834. }
  26835. /**
  26836. * This method is like `_.isMatch` except that it accepts `customizer` which
  26837. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  26838. * are handled by the method instead. The `customizer` is invoked with five
  26839. * arguments: (objValue, srcValue, index|key, object, source).
  26840. *
  26841. * @static
  26842. * @memberOf _
  26843. * @since 4.0.0
  26844. * @category Lang
  26845. * @param {Object} object The object to inspect.
  26846. * @param {Object} source The object of property values to match.
  26847. * @param {Function} [customizer] The function to customize comparisons.
  26848. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  26849. * @example
  26850. *
  26851. * function isGreeting(value) {
  26852. * return /^h(?:i|ello)$/.test(value);
  26853. * }
  26854. *
  26855. * function customizer(objValue, srcValue) {
  26856. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  26857. * return true;
  26858. * }
  26859. * }
  26860. *
  26861. * var object = { 'greeting': 'hello' };
  26862. * var source = { 'greeting': 'hi' };
  26863. *
  26864. * _.isMatchWith(object, source, customizer);
  26865. * // => true
  26866. */
  26867. function isMatchWith(object, source, customizer) {
  26868. customizer = typeof customizer == 'function' ? customizer : undefined;
  26869. return baseIsMatch(object, source, getMatchData(source), customizer);
  26870. }
  26871. /**
  26872. * Checks if `value` is `NaN`.
  26873. *
  26874. * **Note:** This method is based on
  26875. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  26876. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  26877. * `undefined` and other non-number values.
  26878. *
  26879. * @static
  26880. * @memberOf _
  26881. * @since 0.1.0
  26882. * @category Lang
  26883. * @param {*} value The value to check.
  26884. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  26885. * @example
  26886. *
  26887. * _.isNaN(NaN);
  26888. * // => true
  26889. *
  26890. * _.isNaN(new Number(NaN));
  26891. * // => true
  26892. *
  26893. * isNaN(undefined);
  26894. * // => true
  26895. *
  26896. * _.isNaN(undefined);
  26897. * // => false
  26898. */
  26899. function isNaN(value) {
  26900. // An `NaN` primitive is the only value that is not equal to itself.
  26901. // Perform the `toStringTag` check first to avoid errors with some
  26902. // ActiveX objects in IE.
  26903. return isNumber(value) && value != +value;
  26904. }
  26905. /**
  26906. * Checks if `value` is a pristine native function.
  26907. *
  26908. * **Note:** This method can't reliably detect native functions in the
  26909. * presence of the `core-js` package because `core-js` circumvents this kind
  26910. * of detection. Despite multiple requests, the `core-js` maintainer has made
  26911. * it clear: any attempt to fix the detection will be obstructed. As a result,
  26912. * we're left with little choice but to throw an error. Unfortunately, this
  26913. * also affects packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  26914. * which rely on `core-js`.
  26915. *
  26916. * @static
  26917. * @memberOf _
  26918. * @since 3.0.0
  26919. * @category Lang
  26920. * @param {*} value The value to check.
  26921. * @returns {boolean} Returns `true` if `value` is a native function,
  26922. * else `false`.
  26923. * @example
  26924. *
  26925. * _.isNative(Array.prototype.push);
  26926. * // => true
  26927. *
  26928. * _.isNative(_);
  26929. * // => false
  26930. */
  26931. function isNative(value) {
  26932. if (isMaskable(value)) {
  26933. throw new Error('This method is not supported with `core-js`. Try https://github.com/es-shims.');
  26934. }
  26935. return baseIsNative(value);
  26936. }
  26937. /**
  26938. * Checks if `value` is `null`.
  26939. *
  26940. * @static
  26941. * @memberOf _
  26942. * @since 0.1.0
  26943. * @category Lang
  26944. * @param {*} value The value to check.
  26945. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  26946. * @example
  26947. *
  26948. * _.isNull(null);
  26949. * // => true
  26950. *
  26951. * _.isNull(void 0);
  26952. * // => false
  26953. */
  26954. function isNull(value) {
  26955. return value === null;
  26956. }
  26957. /**
  26958. * Checks if `value` is `null` or `undefined`.
  26959. *
  26960. * @static
  26961. * @memberOf _
  26962. * @since 4.0.0
  26963. * @category Lang
  26964. * @param {*} value The value to check.
  26965. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  26966. * @example
  26967. *
  26968. * _.isNil(null);
  26969. * // => true
  26970. *
  26971. * _.isNil(void 0);
  26972. * // => true
  26973. *
  26974. * _.isNil(NaN);
  26975. * // => false
  26976. */
  26977. function isNil(value) {
  26978. return value == null;
  26979. }
  26980. /**
  26981. * Checks if `value` is classified as a `Number` primitive or object.
  26982. *
  26983. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  26984. * classified as numbers, use the `_.isFinite` method.
  26985. *
  26986. * @static
  26987. * @memberOf _
  26988. * @since 0.1.0
  26989. * @category Lang
  26990. * @param {*} value The value to check.
  26991. * @returns {boolean} Returns `true` if `value` is correctly classified,
  26992. * else `false`.
  26993. * @example
  26994. *
  26995. * _.isNumber(3);
  26996. * // => true
  26997. *
  26998. * _.isNumber(Number.MIN_VALUE);
  26999. * // => true
  27000. *
  27001. * _.isNumber(Infinity);
  27002. * // => true
  27003. *
  27004. * _.isNumber('3');
  27005. * // => false
  27006. */
  27007. function isNumber(value) {
  27008. return typeof value == 'number' ||
  27009. (isObjectLike(value) && objectToString.call(value) == numberTag);
  27010. }
  27011. /**
  27012. * Checks if `value` is a plain object, that is, an object created by the
  27013. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  27014. *
  27015. * @static
  27016. * @memberOf _
  27017. * @since 0.8.0
  27018. * @category Lang
  27019. * @param {*} value The value to check.
  27020. * @returns {boolean} Returns `true` if `value` is a plain object,
  27021. * else `false`.
  27022. * @example
  27023. *
  27024. * function Foo() {
  27025. * this.a = 1;
  27026. * }
  27027. *
  27028. * _.isPlainObject(new Foo);
  27029. * // => false
  27030. *
  27031. * _.isPlainObject([1, 2, 3]);
  27032. * // => false
  27033. *
  27034. * _.isPlainObject({ 'x': 0, 'y': 0 });
  27035. * // => true
  27036. *
  27037. * _.isPlainObject(Object.create(null));
  27038. * // => true
  27039. */
  27040. function isPlainObject(value) {
  27041. if (!isObjectLike(value) ||
  27042. objectToString.call(value) != objectTag || isHostObject(value)) {
  27043. return false;
  27044. }
  27045. var proto = getPrototype(value);
  27046. if (proto === null) {
  27047. return true;
  27048. }
  27049. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  27050. return (typeof Ctor == 'function' &&
  27051. Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
  27052. }
  27053. /**
  27054. * Checks if `value` is classified as a `RegExp` object.
  27055. *
  27056. * @static
  27057. * @memberOf _
  27058. * @since 0.1.0
  27059. * @category Lang
  27060. * @param {*} value The value to check.
  27061. * @returns {boolean} Returns `true` if `value` is correctly classified,
  27062. * else `false`.
  27063. * @example
  27064. *
  27065. * _.isRegExp(/abc/);
  27066. * // => true
  27067. *
  27068. * _.isRegExp('/abc/');
  27069. * // => false
  27070. */
  27071. function isRegExp(value) {
  27072. return isObject(value) && objectToString.call(value) == regexpTag;
  27073. }
  27074. /**
  27075. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  27076. * double precision number which isn't the result of a rounded unsafe integer.
  27077. *
  27078. * **Note:** This method is based on
  27079. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  27080. *
  27081. * @static
  27082. * @memberOf _
  27083. * @since 4.0.0
  27084. * @category Lang
  27085. * @param {*} value The value to check.
  27086. * @returns {boolean} Returns `true` if `value` is a safe integer,
  27087. * else `false`.
  27088. * @example
  27089. *
  27090. * _.isSafeInteger(3);
  27091. * // => true
  27092. *
  27093. * _.isSafeInteger(Number.MIN_VALUE);
  27094. * // => false
  27095. *
  27096. * _.isSafeInteger(Infinity);
  27097. * // => false
  27098. *
  27099. * _.isSafeInteger('3');
  27100. * // => false
  27101. */
  27102. function isSafeInteger(value) {
  27103. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  27104. }
  27105. /**
  27106. * Checks if `value` is classified as a `Set` object.
  27107. *
  27108. * @static
  27109. * @memberOf _
  27110. * @since 4.3.0
  27111. * @category Lang
  27112. * @param {*} value The value to check.
  27113. * @returns {boolean} Returns `true` if `value` is correctly classified,
  27114. * else `false`.
  27115. * @example
  27116. *
  27117. * _.isSet(new Set);
  27118. * // => true
  27119. *
  27120. * _.isSet(new WeakSet);
  27121. * // => false
  27122. */
  27123. function isSet(value) {
  27124. return isObjectLike(value) && getTag(value) == setTag;
  27125. }
  27126. /**
  27127. * Checks if `value` is classified as a `String` primitive or object.
  27128. *
  27129. * @static
  27130. * @since 0.1.0
  27131. * @memberOf _
  27132. * @category Lang
  27133. * @param {*} value The value to check.
  27134. * @returns {boolean} Returns `true` if `value` is correctly classified,
  27135. * else `false`.
  27136. * @example
  27137. *
  27138. * _.isString('abc');
  27139. * // => true
  27140. *
  27141. * _.isString(1);
  27142. * // => false
  27143. */
  27144. function isString(value) {
  27145. return typeof value == 'string' ||
  27146. (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
  27147. }
  27148. /**
  27149. * Checks if `value` is classified as a `Symbol` primitive or object.
  27150. *
  27151. * @static
  27152. * @memberOf _
  27153. * @since 4.0.0
  27154. * @category Lang
  27155. * @param {*} value The value to check.
  27156. * @returns {boolean} Returns `true` if `value` is correctly classified,
  27157. * else `false`.
  27158. * @example
  27159. *
  27160. * _.isSymbol(Symbol.iterator);
  27161. * // => true
  27162. *
  27163. * _.isSymbol('abc');
  27164. * // => false
  27165. */
  27166. function isSymbol(value) {
  27167. return typeof value == 'symbol' ||
  27168. (isObjectLike(value) && objectToString.call(value) == symbolTag);
  27169. }
  27170. /**
  27171. * Checks if `value` is classified as a typed array.
  27172. *
  27173. * @static
  27174. * @memberOf _
  27175. * @since 3.0.0
  27176. * @category Lang
  27177. * @param {*} value The value to check.
  27178. * @returns {boolean} Returns `true` if `value` is correctly classified,
  27179. * else `false`.
  27180. * @example
  27181. *
  27182. * _.isTypedArray(new Uint8Array);
  27183. * // => true
  27184. *
  27185. * _.isTypedArray([]);
  27186. * // => false
  27187. */
  27188. function isTypedArray(value) {
  27189. return isObjectLike(value) &&
  27190. isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
  27191. }
  27192. /**
  27193. * Checks if `value` is `undefined`.
  27194. *
  27195. * @static
  27196. * @since 0.1.0
  27197. * @memberOf _
  27198. * @category Lang
  27199. * @param {*} value The value to check.
  27200. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  27201. * @example
  27202. *
  27203. * _.isUndefined(void 0);
  27204. * // => true
  27205. *
  27206. * _.isUndefined(null);
  27207. * // => false
  27208. */
  27209. function isUndefined(value) {
  27210. return value === undefined;
  27211. }
  27212. /**
  27213. * Checks if `value` is classified as a `WeakMap` object.
  27214. *
  27215. * @static
  27216. * @memberOf _
  27217. * @since 4.3.0
  27218. * @category Lang
  27219. * @param {*} value The value to check.
  27220. * @returns {boolean} Returns `true` if `value` is correctly classified,
  27221. * else `false`.
  27222. * @example
  27223. *
  27224. * _.isWeakMap(new WeakMap);
  27225. * // => true
  27226. *
  27227. * _.isWeakMap(new Map);
  27228. * // => false
  27229. */
  27230. function isWeakMap(value) {
  27231. return isObjectLike(value) && getTag(value) == weakMapTag;
  27232. }
  27233. /**
  27234. * Checks if `value` is classified as a `WeakSet` object.
  27235. *
  27236. * @static
  27237. * @memberOf _
  27238. * @since 4.3.0
  27239. * @category Lang
  27240. * @param {*} value The value to check.
  27241. * @returns {boolean} Returns `true` if `value` is correctly classified,
  27242. * else `false`.
  27243. * @example
  27244. *
  27245. * _.isWeakSet(new WeakSet);
  27246. * // => true
  27247. *
  27248. * _.isWeakSet(new Set);
  27249. * // => false
  27250. */
  27251. function isWeakSet(value) {
  27252. return isObjectLike(value) && objectToString.call(value) == weakSetTag;
  27253. }
  27254. /**
  27255. * Checks if `value` is less than `other`.
  27256. *
  27257. * @static
  27258. * @memberOf _
  27259. * @since 3.9.0
  27260. * @category Lang
  27261. * @param {*} value The value to compare.
  27262. * @param {*} other The other value to compare.
  27263. * @returns {boolean} Returns `true` if `value` is less than `other`,
  27264. * else `false`.
  27265. * @see _.gt
  27266. * @example
  27267. *
  27268. * _.lt(1, 3);
  27269. * // => true
  27270. *
  27271. * _.lt(3, 3);
  27272. * // => false
  27273. *
  27274. * _.lt(3, 1);
  27275. * // => false
  27276. */
  27277. var lt = createRelationalOperation(baseLt);
  27278. /**
  27279. * Checks if `value` is less than or equal to `other`.
  27280. *
  27281. * @static
  27282. * @memberOf _
  27283. * @since 3.9.0
  27284. * @category Lang
  27285. * @param {*} value The value to compare.
  27286. * @param {*} other The other value to compare.
  27287. * @returns {boolean} Returns `true` if `value` is less than or equal to
  27288. * `other`, else `false`.
  27289. * @see _.gte
  27290. * @example
  27291. *
  27292. * _.lte(1, 3);
  27293. * // => true
  27294. *
  27295. * _.lte(3, 3);
  27296. * // => true
  27297. *
  27298. * _.lte(3, 1);
  27299. * // => false
  27300. */
  27301. var lte = createRelationalOperation(function(value, other) {
  27302. return value <= other;
  27303. });
  27304. /**
  27305. * Converts `value` to an array.
  27306. *
  27307. * @static
  27308. * @since 0.1.0
  27309. * @memberOf _
  27310. * @category Lang
  27311. * @param {*} value The value to convert.
  27312. * @returns {Array} Returns the converted array.
  27313. * @example
  27314. *
  27315. * _.toArray({ 'a': 1, 'b': 2 });
  27316. * // => [1, 2]
  27317. *
  27318. * _.toArray('abc');
  27319. * // => ['a', 'b', 'c']
  27320. *
  27321. * _.toArray(1);
  27322. * // => []
  27323. *
  27324. * _.toArray(null);
  27325. * // => []
  27326. */
  27327. function toArray(value) {
  27328. if (!value) {
  27329. return [];
  27330. }
  27331. if (isArrayLike(value)) {
  27332. return isString(value) ? stringToArray(value) : copyArray(value);
  27333. }
  27334. if (iteratorSymbol && value[iteratorSymbol]) {
  27335. return iteratorToArray(value[iteratorSymbol]());
  27336. }
  27337. var tag = getTag(value),
  27338. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  27339. return func(value);
  27340. }
  27341. /**
  27342. * Converts `value` to a finite number.
  27343. *
  27344. * @static
  27345. * @memberOf _
  27346. * @since 4.12.0
  27347. * @category Lang
  27348. * @param {*} value The value to convert.
  27349. * @returns {number} Returns the converted number.
  27350. * @example
  27351. *
  27352. * _.toFinite(3.2);
  27353. * // => 3.2
  27354. *
  27355. * _.toFinite(Number.MIN_VALUE);
  27356. * // => 5e-324
  27357. *
  27358. * _.toFinite(Infinity);
  27359. * // => 1.7976931348623157e+308
  27360. *
  27361. * _.toFinite('3.2');
  27362. * // => 3.2
  27363. */
  27364. function toFinite(value) {
  27365. if (!value) {
  27366. return value === 0 ? value : 0;
  27367. }
  27368. value = toNumber(value);
  27369. if (value === INFINITY || value === -INFINITY) {
  27370. var sign = (value < 0 ? -1 : 1);
  27371. return sign * MAX_INTEGER;
  27372. }
  27373. return value === value ? value : 0;
  27374. }
  27375. /**
  27376. * Converts `value` to an integer.
  27377. *
  27378. * **Note:** This method is loosely based on
  27379. * [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
  27380. *
  27381. * @static
  27382. * @memberOf _
  27383. * @since 4.0.0
  27384. * @category Lang
  27385. * @param {*} value The value to convert.
  27386. * @returns {number} Returns the converted integer.
  27387. * @example
  27388. *
  27389. * _.toInteger(3.2);
  27390. * // => 3
  27391. *
  27392. * _.toInteger(Number.MIN_VALUE);
  27393. * // => 0
  27394. *
  27395. * _.toInteger(Infinity);
  27396. * // => 1.7976931348623157e+308
  27397. *
  27398. * _.toInteger('3.2');
  27399. * // => 3
  27400. */
  27401. function toInteger(value) {
  27402. var result = toFinite(value),
  27403. remainder = result % 1;
  27404. return result === result ? (remainder ? result - remainder : result) : 0;
  27405. }
  27406. /**
  27407. * Converts `value` to an integer suitable for use as the length of an
  27408. * array-like object.
  27409. *
  27410. * **Note:** This method is based on
  27411. * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  27412. *
  27413. * @static
  27414. * @memberOf _
  27415. * @since 4.0.0
  27416. * @category Lang
  27417. * @param {*} value The value to convert.
  27418. * @returns {number} Returns the converted integer.
  27419. * @example
  27420. *
  27421. * _.toLength(3.2);
  27422. * // => 3
  27423. *
  27424. * _.toLength(Number.MIN_VALUE);
  27425. * // => 0
  27426. *
  27427. * _.toLength(Infinity);
  27428. * // => 4294967295
  27429. *
  27430. * _.toLength('3.2');
  27431. * // => 3
  27432. */
  27433. function toLength(value) {
  27434. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  27435. }
  27436. /**
  27437. * Converts `value` to a number.
  27438. *
  27439. * @static
  27440. * @memberOf _
  27441. * @since 4.0.0
  27442. * @category Lang
  27443. * @param {*} value The value to process.
  27444. * @returns {number} Returns the number.
  27445. * @example
  27446. *
  27447. * _.toNumber(3.2);
  27448. * // => 3.2
  27449. *
  27450. * _.toNumber(Number.MIN_VALUE);
  27451. * // => 5e-324
  27452. *
  27453. * _.toNumber(Infinity);
  27454. * // => Infinity
  27455. *
  27456. * _.toNumber('3.2');
  27457. * // => 3.2
  27458. */
  27459. function toNumber(value) {
  27460. if (typeof value == 'number') {
  27461. return value;
  27462. }
  27463. if (isSymbol(value)) {
  27464. return NAN;
  27465. }
  27466. if (isObject(value)) {
  27467. var other = isFunction(value.valueOf) ? value.valueOf() : value;
  27468. value = isObject(other) ? (other + '') : other;
  27469. }
  27470. if (typeof value != 'string') {
  27471. return value === 0 ? value : +value;
  27472. }
  27473. value = value.replace(reTrim, '');
  27474. var isBinary = reIsBinary.test(value);
  27475. return (isBinary || reIsOctal.test(value))
  27476. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  27477. : (reIsBadHex.test(value) ? NAN : +value);
  27478. }
  27479. /**
  27480. * Converts `value` to a plain object flattening inherited enumerable string
  27481. * keyed properties of `value` to own properties of the plain object.
  27482. *
  27483. * @static
  27484. * @memberOf _
  27485. * @since 3.0.0
  27486. * @category Lang
  27487. * @param {*} value The value to convert.
  27488. * @returns {Object} Returns the converted plain object.
  27489. * @example
  27490. *
  27491. * function Foo() {
  27492. * this.b = 2;
  27493. * }
  27494. *
  27495. * Foo.prototype.c = 3;
  27496. *
  27497. * _.assign({ 'a': 1 }, new Foo);
  27498. * // => { 'a': 1, 'b': 2 }
  27499. *
  27500. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  27501. * // => { 'a': 1, 'b': 2, 'c': 3 }
  27502. */
  27503. function toPlainObject(value) {
  27504. return copyObject(value, keysIn(value));
  27505. }
  27506. /**
  27507. * Converts `value` to a safe integer. A safe integer can be compared and
  27508. * represented correctly.
  27509. *
  27510. * @static
  27511. * @memberOf _
  27512. * @since 4.0.0
  27513. * @category Lang
  27514. * @param {*} value The value to convert.
  27515. * @returns {number} Returns the converted integer.
  27516. * @example
  27517. *
  27518. * _.toSafeInteger(3.2);
  27519. * // => 3
  27520. *
  27521. * _.toSafeInteger(Number.MIN_VALUE);
  27522. * // => 0
  27523. *
  27524. * _.toSafeInteger(Infinity);
  27525. * // => 9007199254740991
  27526. *
  27527. * _.toSafeInteger('3.2');
  27528. * // => 3
  27529. */
  27530. function toSafeInteger(value) {
  27531. return baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
  27532. }
  27533. /**
  27534. * Converts `value` to a string. An empty string is returned for `null`
  27535. * and `undefined` values. The sign of `-0` is preserved.
  27536. *
  27537. * @static
  27538. * @memberOf _
  27539. * @since 4.0.0
  27540. * @category Lang
  27541. * @param {*} value The value to process.
  27542. * @returns {string} Returns the string.
  27543. * @example
  27544. *
  27545. * _.toString(null);
  27546. * // => ''
  27547. *
  27548. * _.toString(-0);
  27549. * // => '-0'
  27550. *
  27551. * _.toString([1, 2, 3]);
  27552. * // => '1,2,3'
  27553. */
  27554. function toString(value) {
  27555. return value == null ? '' : baseToString(value);
  27556. }
  27557. /*------------------------------------------------------------------------*/
  27558. /**
  27559. * Assigns own enumerable string keyed properties of source objects to the
  27560. * destination object. Source objects are applied from left to right.
  27561. * Subsequent sources overwrite property assignments of previous sources.
  27562. *
  27563. * **Note:** This method mutates `object` and is loosely based on
  27564. * [`Object.assign`](https://mdn.io/Object/assign).
  27565. *
  27566. * @static
  27567. * @memberOf _
  27568. * @since 0.10.0
  27569. * @category Object
  27570. * @param {Object} object The destination object.
  27571. * @param {...Object} [sources] The source objects.
  27572. * @returns {Object} Returns `object`.
  27573. * @see _.assignIn
  27574. * @example
  27575. *
  27576. * function Foo() {
  27577. * this.c = 3;
  27578. * }
  27579. *
  27580. * function Bar() {
  27581. * this.e = 5;
  27582. * }
  27583. *
  27584. * Foo.prototype.d = 4;
  27585. * Bar.prototype.f = 6;
  27586. *
  27587. * _.assign({ 'a': 1 }, new Foo, new Bar);
  27588. * // => { 'a': 1, 'c': 3, 'e': 5 }
  27589. */
  27590. var assign = createAssigner(function(object, source) {
  27591. if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) {
  27592. copyObject(source, keys(source), object);
  27593. return;
  27594. }
  27595. for (var key in source) {
  27596. if (hasOwnProperty.call(source, key)) {
  27597. assignValue(object, key, source[key]);
  27598. }
  27599. }
  27600. });
  27601. /**
  27602. * This method is like `_.assign` except that it iterates over own and
  27603. * inherited source properties.
  27604. *
  27605. * **Note:** This method mutates `object`.
  27606. *
  27607. * @static
  27608. * @memberOf _
  27609. * @since 4.0.0
  27610. * @alias extend
  27611. * @category Object
  27612. * @param {Object} object The destination object.
  27613. * @param {...Object} [sources] The source objects.
  27614. * @returns {Object} Returns `object`.
  27615. * @see _.assign
  27616. * @example
  27617. *
  27618. * function Foo() {
  27619. * this.b = 2;
  27620. * }
  27621. *
  27622. * function Bar() {
  27623. * this.d = 4;
  27624. * }
  27625. *
  27626. * Foo.prototype.c = 3;
  27627. * Bar.prototype.e = 5;
  27628. *
  27629. * _.assignIn({ 'a': 1 }, new Foo, new Bar);
  27630. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
  27631. */
  27632. var assignIn = createAssigner(function(object, source) {
  27633. if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) {
  27634. copyObject(source, keysIn(source), object);
  27635. return;
  27636. }
  27637. for (var key in source) {
  27638. assignValue(object, key, source[key]);
  27639. }
  27640. });
  27641. /**
  27642. * This method is like `_.assignIn` except that it accepts `customizer`
  27643. * which is invoked to produce the assigned values. If `customizer` returns
  27644. * `undefined`, assignment is handled by the method instead. The `customizer`
  27645. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  27646. *
  27647. * **Note:** This method mutates `object`.
  27648. *
  27649. * @static
  27650. * @memberOf _
  27651. * @since 4.0.0
  27652. * @alias extendWith
  27653. * @category Object
  27654. * @param {Object} object The destination object.
  27655. * @param {...Object} sources The source objects.
  27656. * @param {Function} [customizer] The function to customize assigned values.
  27657. * @returns {Object} Returns `object`.
  27658. * @see _.assignWith
  27659. * @example
  27660. *
  27661. * function customizer(objValue, srcValue) {
  27662. * return _.isUndefined(objValue) ? srcValue : objValue;
  27663. * }
  27664. *
  27665. * var defaults = _.partialRight(_.assignInWith, customizer);
  27666. *
  27667. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  27668. * // => { 'a': 1, 'b': 2 }
  27669. */
  27670. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  27671. copyObject(source, keysIn(source), object, customizer);
  27672. });
  27673. /**
  27674. * This method is like `_.assign` except that it accepts `customizer`
  27675. * which is invoked to produce the assigned values. If `customizer` returns
  27676. * `undefined`, assignment is handled by the method instead. The `customizer`
  27677. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  27678. *
  27679. * **Note:** This method mutates `object`.
  27680. *
  27681. * @static
  27682. * @memberOf _
  27683. * @since 4.0.0
  27684. * @category Object
  27685. * @param {Object} object The destination object.
  27686. * @param {...Object} sources The source objects.
  27687. * @param {Function} [customizer] The function to customize assigned values.
  27688. * @returns {Object} Returns `object`.
  27689. * @see _.assignInWith
  27690. * @example
  27691. *
  27692. * function customizer(objValue, srcValue) {
  27693. * return _.isUndefined(objValue) ? srcValue : objValue;
  27694. * }
  27695. *
  27696. * var defaults = _.partialRight(_.assignWith, customizer);
  27697. *
  27698. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  27699. * // => { 'a': 1, 'b': 2 }
  27700. */
  27701. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  27702. copyObject(source, keys(source), object, customizer);
  27703. });
  27704. /**
  27705. * Creates an array of values corresponding to `paths` of `object`.
  27706. *
  27707. * @static
  27708. * @memberOf _
  27709. * @since 1.0.0
  27710. * @category Object
  27711. * @param {Object} object The object to iterate over.
  27712. * @param {...(string|string[])} [paths] The property paths of elements to pick.
  27713. * @returns {Array} Returns the picked values.
  27714. * @example
  27715. *
  27716. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  27717. *
  27718. * _.at(object, ['a[0].b.c', 'a[1]']);
  27719. * // => [3, 4]
  27720. */
  27721. var at = rest(function(object, paths) {
  27722. return baseAt(object, baseFlatten(paths, 1));
  27723. });
  27724. /**
  27725. * Creates an object that inherits from the `prototype` object. If a
  27726. * `properties` object is given, its own enumerable string keyed properties
  27727. * are assigned to the created object.
  27728. *
  27729. * @static
  27730. * @memberOf _
  27731. * @since 2.3.0
  27732. * @category Object
  27733. * @param {Object} prototype The object to inherit from.
  27734. * @param {Object} [properties] The properties to assign to the object.
  27735. * @returns {Object} Returns the new object.
  27736. * @example
  27737. *
  27738. * function Shape() {
  27739. * this.x = 0;
  27740. * this.y = 0;
  27741. * }
  27742. *
  27743. * function Circle() {
  27744. * Shape.call(this);
  27745. * }
  27746. *
  27747. * Circle.prototype = _.create(Shape.prototype, {
  27748. * 'constructor': Circle
  27749. * });
  27750. *
  27751. * var circle = new Circle;
  27752. * circle instanceof Circle;
  27753. * // => true
  27754. *
  27755. * circle instanceof Shape;
  27756. * // => true
  27757. */
  27758. function create(prototype, properties) {
  27759. var result = baseCreate(prototype);
  27760. return properties ? baseAssign(result, properties) : result;
  27761. }
  27762. /**
  27763. * Assigns own and inherited enumerable string keyed properties of source
  27764. * objects to the destination object for all destination properties that
  27765. * resolve to `undefined`. Source objects are applied from left to right.
  27766. * Once a property is set, additional values of the same property are ignored.
  27767. *
  27768. * **Note:** This method mutates `object`.
  27769. *
  27770. * @static
  27771. * @since 0.1.0
  27772. * @memberOf _
  27773. * @category Object
  27774. * @param {Object} object The destination object.
  27775. * @param {...Object} [sources] The source objects.
  27776. * @returns {Object} Returns `object`.
  27777. * @see _.defaultsDeep
  27778. * @example
  27779. *
  27780. * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
  27781. * // => { 'user': 'barney', 'age': 36 }
  27782. */
  27783. var defaults = rest(function(args) {
  27784. args.push(undefined, assignInDefaults);
  27785. return apply(assignInWith, undefined, args);
  27786. });
  27787. /**
  27788. * This method is like `_.defaults` except that it recursively assigns
  27789. * default properties.
  27790. *
  27791. * **Note:** This method mutates `object`.
  27792. *
  27793. * @static
  27794. * @memberOf _
  27795. * @since 3.10.0
  27796. * @category Object
  27797. * @param {Object} object The destination object.
  27798. * @param {...Object} [sources] The source objects.
  27799. * @returns {Object} Returns `object`.
  27800. * @see _.defaults
  27801. * @example
  27802. *
  27803. * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
  27804. * // => { 'user': { 'name': 'barney', 'age': 36 } }
  27805. *
  27806. */
  27807. var defaultsDeep = rest(function(args) {
  27808. args.push(undefined, mergeDefaults);
  27809. return apply(mergeWith, undefined, args);
  27810. });
  27811. /**
  27812. * This method is like `_.find` except that it returns the key of the first
  27813. * element `predicate` returns truthy for instead of the element itself.
  27814. *
  27815. * @static
  27816. * @memberOf _
  27817. * @since 1.1.0
  27818. * @category Object
  27819. * @param {Object} object The object to search.
  27820. * @param {Array|Function|Object|string} [predicate=_.identity]
  27821. * The function invoked per iteration.
  27822. * @returns {string|undefined} Returns the key of the matched element,
  27823. * else `undefined`.
  27824. * @example
  27825. *
  27826. * var users = {
  27827. * 'barney': { 'age': 36, 'active': true },
  27828. * 'fred': { 'age': 40, 'active': false },
  27829. * 'pebbles': { 'age': 1, 'active': true }
  27830. * };
  27831. *
  27832. * _.findKey(users, function(o) { return o.age < 40; });
  27833. * // => 'barney' (iteration order is not guaranteed)
  27834. *
  27835. * // The `_.matches` iteratee shorthand.
  27836. * _.findKey(users, { 'age': 1, 'active': true });
  27837. * // => 'pebbles'
  27838. *
  27839. * // The `_.matchesProperty` iteratee shorthand.
  27840. * _.findKey(users, ['active', false]);
  27841. * // => 'fred'
  27842. *
  27843. * // The `_.property` iteratee shorthand.
  27844. * _.findKey(users, 'active');
  27845. * // => 'barney'
  27846. */
  27847. function findKey(object, predicate) {
  27848. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  27849. }
  27850. /**
  27851. * This method is like `_.findKey` except that it iterates over elements of
  27852. * a collection in the opposite order.
  27853. *
  27854. * @static
  27855. * @memberOf _
  27856. * @since 2.0.0
  27857. * @category Object
  27858. * @param {Object} object The object to search.
  27859. * @param {Array|Function|Object|string} [predicate=_.identity]
  27860. * The function invoked per iteration.
  27861. * @returns {string|undefined} Returns the key of the matched element,
  27862. * else `undefined`.
  27863. * @example
  27864. *
  27865. * var users = {
  27866. * 'barney': { 'age': 36, 'active': true },
  27867. * 'fred': { 'age': 40, 'active': false },
  27868. * 'pebbles': { 'age': 1, 'active': true }
  27869. * };
  27870. *
  27871. * _.findLastKey(users, function(o) { return o.age < 40; });
  27872. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  27873. *
  27874. * // The `_.matches` iteratee shorthand.
  27875. * _.findLastKey(users, { 'age': 36, 'active': true });
  27876. * // => 'barney'
  27877. *
  27878. * // The `_.matchesProperty` iteratee shorthand.
  27879. * _.findLastKey(users, ['active', false]);
  27880. * // => 'fred'
  27881. *
  27882. * // The `_.property` iteratee shorthand.
  27883. * _.findLastKey(users, 'active');
  27884. * // => 'pebbles'
  27885. */
  27886. function findLastKey(object, predicate) {
  27887. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  27888. }
  27889. /**
  27890. * Iterates over own and inherited enumerable string keyed properties of an
  27891. * object and invokes `iteratee` for each property. The iteratee is invoked
  27892. * with three arguments: (value, key, object). Iteratee functions may exit
  27893. * iteration early by explicitly returning `false`.
  27894. *
  27895. * @static
  27896. * @memberOf _
  27897. * @since 0.3.0
  27898. * @category Object
  27899. * @param {Object} object The object to iterate over.
  27900. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  27901. * @returns {Object} Returns `object`.
  27902. * @see _.forInRight
  27903. * @example
  27904. *
  27905. * function Foo() {
  27906. * this.a = 1;
  27907. * this.b = 2;
  27908. * }
  27909. *
  27910. * Foo.prototype.c = 3;
  27911. *
  27912. * _.forIn(new Foo, function(value, key) {
  27913. * console.log(key);
  27914. * });
  27915. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  27916. */
  27917. function forIn(object, iteratee) {
  27918. return object == null
  27919. ? object
  27920. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  27921. }
  27922. /**
  27923. * This method is like `_.forIn` except that it iterates over properties of
  27924. * `object` in the opposite order.
  27925. *
  27926. * @static
  27927. * @memberOf _
  27928. * @since 2.0.0
  27929. * @category Object
  27930. * @param {Object} object The object to iterate over.
  27931. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  27932. * @returns {Object} Returns `object`.
  27933. * @see _.forIn
  27934. * @example
  27935. *
  27936. * function Foo() {
  27937. * this.a = 1;
  27938. * this.b = 2;
  27939. * }
  27940. *
  27941. * Foo.prototype.c = 3;
  27942. *
  27943. * _.forInRight(new Foo, function(value, key) {
  27944. * console.log(key);
  27945. * });
  27946. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  27947. */
  27948. function forInRight(object, iteratee) {
  27949. return object == null
  27950. ? object
  27951. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  27952. }
  27953. /**
  27954. * Iterates over own enumerable string keyed properties of an object and
  27955. * invokes `iteratee` for each property. The iteratee is invoked with three
  27956. * arguments: (value, key, object). Iteratee functions may exit iteration
  27957. * early by explicitly returning `false`.
  27958. *
  27959. * @static
  27960. * @memberOf _
  27961. * @since 0.3.0
  27962. * @category Object
  27963. * @param {Object} object The object to iterate over.
  27964. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  27965. * @returns {Object} Returns `object`.
  27966. * @see _.forOwnRight
  27967. * @example
  27968. *
  27969. * function Foo() {
  27970. * this.a = 1;
  27971. * this.b = 2;
  27972. * }
  27973. *
  27974. * Foo.prototype.c = 3;
  27975. *
  27976. * _.forOwn(new Foo, function(value, key) {
  27977. * console.log(key);
  27978. * });
  27979. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  27980. */
  27981. function forOwn(object, iteratee) {
  27982. return object && baseForOwn(object, getIteratee(iteratee, 3));
  27983. }
  27984. /**
  27985. * This method is like `_.forOwn` except that it iterates over properties of
  27986. * `object` in the opposite order.
  27987. *
  27988. * @static
  27989. * @memberOf _
  27990. * @since 2.0.0
  27991. * @category Object
  27992. * @param {Object} object The object to iterate over.
  27993. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  27994. * @returns {Object} Returns `object`.
  27995. * @see _.forOwn
  27996. * @example
  27997. *
  27998. * function Foo() {
  27999. * this.a = 1;
  28000. * this.b = 2;
  28001. * }
  28002. *
  28003. * Foo.prototype.c = 3;
  28004. *
  28005. * _.forOwnRight(new Foo, function(value, key) {
  28006. * console.log(key);
  28007. * });
  28008. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  28009. */
  28010. function forOwnRight(object, iteratee) {
  28011. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  28012. }
  28013. /**
  28014. * Creates an array of function property names from own enumerable properties
  28015. * of `object`.
  28016. *
  28017. * @static
  28018. * @since 0.1.0
  28019. * @memberOf _
  28020. * @category Object
  28021. * @param {Object} object The object to inspect.
  28022. * @returns {Array} Returns the function names.
  28023. * @see _.functionsIn
  28024. * @example
  28025. *
  28026. * function Foo() {
  28027. * this.a = _.constant('a');
  28028. * this.b = _.constant('b');
  28029. * }
  28030. *
  28031. * Foo.prototype.c = _.constant('c');
  28032. *
  28033. * _.functions(new Foo);
  28034. * // => ['a', 'b']
  28035. */
  28036. function functions(object) {
  28037. return object == null ? [] : baseFunctions(object, keys(object));
  28038. }
  28039. /**
  28040. * Creates an array of function property names from own and inherited
  28041. * enumerable properties of `object`.
  28042. *
  28043. * @static
  28044. * @memberOf _
  28045. * @since 4.0.0
  28046. * @category Object
  28047. * @param {Object} object The object to inspect.
  28048. * @returns {Array} Returns the function names.
  28049. * @see _.functions
  28050. * @example
  28051. *
  28052. * function Foo() {
  28053. * this.a = _.constant('a');
  28054. * this.b = _.constant('b');
  28055. * }
  28056. *
  28057. * Foo.prototype.c = _.constant('c');
  28058. *
  28059. * _.functionsIn(new Foo);
  28060. * // => ['a', 'b', 'c']
  28061. */
  28062. function functionsIn(object) {
  28063. return object == null ? [] : baseFunctions(object, keysIn(object));
  28064. }
  28065. /**
  28066. * Gets the value at `path` of `object`. If the resolved value is
  28067. * `undefined`, the `defaultValue` is used in its place.
  28068. *
  28069. * @static
  28070. * @memberOf _
  28071. * @since 3.7.0
  28072. * @category Object
  28073. * @param {Object} object The object to query.
  28074. * @param {Array|string} path The path of the property to get.
  28075. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  28076. * @returns {*} Returns the resolved value.
  28077. * @example
  28078. *
  28079. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  28080. *
  28081. * _.get(object, 'a[0].b.c');
  28082. * // => 3
  28083. *
  28084. * _.get(object, ['a', '0', 'b', 'c']);
  28085. * // => 3
  28086. *
  28087. * _.get(object, 'a.b.c', 'default');
  28088. * // => 'default'
  28089. */
  28090. function get(object, path, defaultValue) {
  28091. var result = object == null ? undefined : baseGet(object, path);
  28092. return result === undefined ? defaultValue : result;
  28093. }
  28094. /**
  28095. * Checks if `path` is a direct property of `object`.
  28096. *
  28097. * @static
  28098. * @since 0.1.0
  28099. * @memberOf _
  28100. * @category Object
  28101. * @param {Object} object The object to query.
  28102. * @param {Array|string} path The path to check.
  28103. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  28104. * @example
  28105. *
  28106. * var object = { 'a': { 'b': 2 } };
  28107. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  28108. *
  28109. * _.has(object, 'a');
  28110. * // => true
  28111. *
  28112. * _.has(object, 'a.b');
  28113. * // => true
  28114. *
  28115. * _.has(object, ['a', 'b']);
  28116. * // => true
  28117. *
  28118. * _.has(other, 'a');
  28119. * // => false
  28120. */
  28121. function has(object, path) {
  28122. return object != null && hasPath(object, path, baseHas);
  28123. }
  28124. /**
  28125. * Checks if `path` is a direct or inherited property of `object`.
  28126. *
  28127. * @static
  28128. * @memberOf _
  28129. * @since 4.0.0
  28130. * @category Object
  28131. * @param {Object} object The object to query.
  28132. * @param {Array|string} path The path to check.
  28133. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  28134. * @example
  28135. *
  28136. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  28137. *
  28138. * _.hasIn(object, 'a');
  28139. * // => true
  28140. *
  28141. * _.hasIn(object, 'a.b');
  28142. * // => true
  28143. *
  28144. * _.hasIn(object, ['a', 'b']);
  28145. * // => true
  28146. *
  28147. * _.hasIn(object, 'b');
  28148. * // => false
  28149. */
  28150. function hasIn(object, path) {
  28151. return object != null && hasPath(object, path, baseHasIn);
  28152. }
  28153. /**
  28154. * Creates an object composed of the inverted keys and values of `object`.
  28155. * If `object` contains duplicate values, subsequent values overwrite
  28156. * property assignments of previous values.
  28157. *
  28158. * @static
  28159. * @memberOf _
  28160. * @since 0.7.0
  28161. * @category Object
  28162. * @param {Object} object The object to invert.
  28163. * @returns {Object} Returns the new inverted object.
  28164. * @example
  28165. *
  28166. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  28167. *
  28168. * _.invert(object);
  28169. * // => { '1': 'c', '2': 'b' }
  28170. */
  28171. var invert = createInverter(function(result, value, key) {
  28172. result[value] = key;
  28173. }, constant(identity));
  28174. /**
  28175. * This method is like `_.invert` except that the inverted object is generated
  28176. * from the results of running each element of `object` thru `iteratee`. The
  28177. * corresponding inverted value of each inverted key is an array of keys
  28178. * responsible for generating the inverted value. The iteratee is invoked
  28179. * with one argument: (value).
  28180. *
  28181. * @static
  28182. * @memberOf _
  28183. * @since 4.1.0
  28184. * @category Object
  28185. * @param {Object} object The object to invert.
  28186. * @param {Array|Function|Object|string} [iteratee=_.identity]
  28187. * The iteratee invoked per element.
  28188. * @returns {Object} Returns the new inverted object.
  28189. * @example
  28190. *
  28191. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  28192. *
  28193. * _.invertBy(object);
  28194. * // => { '1': ['a', 'c'], '2': ['b'] }
  28195. *
  28196. * _.invertBy(object, function(value) {
  28197. * return 'group' + value;
  28198. * });
  28199. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  28200. */
  28201. var invertBy = createInverter(function(result, value, key) {
  28202. if (hasOwnProperty.call(result, value)) {
  28203. result[value].push(key);
  28204. } else {
  28205. result[value] = [key];
  28206. }
  28207. }, getIteratee);
  28208. /**
  28209. * Invokes the method at `path` of `object`.
  28210. *
  28211. * @static
  28212. * @memberOf _
  28213. * @since 4.0.0
  28214. * @category Object
  28215. * @param {Object} object The object to query.
  28216. * @param {Array|string} path The path of the method to invoke.
  28217. * @param {...*} [args] The arguments to invoke the method with.
  28218. * @returns {*} Returns the result of the invoked method.
  28219. * @example
  28220. *
  28221. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  28222. *
  28223. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  28224. * // => [2, 3]
  28225. */
  28226. var invoke = rest(baseInvoke);
  28227. /**
  28228. * Creates an array of the own enumerable property names of `object`.
  28229. *
  28230. * **Note:** Non-object values are coerced to objects. See the
  28231. * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
  28232. * for more details.
  28233. *
  28234. * @static
  28235. * @since 0.1.0
  28236. * @memberOf _
  28237. * @category Object
  28238. * @param {Object} object The object to query.
  28239. * @returns {Array} Returns the array of property names.
  28240. * @example
  28241. *
  28242. * function Foo() {
  28243. * this.a = 1;
  28244. * this.b = 2;
  28245. * }
  28246. *
  28247. * Foo.prototype.c = 3;
  28248. *
  28249. * _.keys(new Foo);
  28250. * // => ['a', 'b'] (iteration order is not guaranteed)
  28251. *
  28252. * _.keys('hi');
  28253. * // => ['0', '1']
  28254. */
  28255. function keys(object) {
  28256. var isProto = isPrototype(object);
  28257. if (!(isProto || isArrayLike(object))) {
  28258. return baseKeys(object);
  28259. }
  28260. var indexes = indexKeys(object),
  28261. skipIndexes = !!indexes,
  28262. result = indexes || [],
  28263. length = result.length;
  28264. for (var key in object) {
  28265. if (baseHas(object, key) &&
  28266. !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
  28267. !(isProto && key == 'constructor')) {
  28268. result.push(key);
  28269. }
  28270. }
  28271. return result;
  28272. }
  28273. /**
  28274. * Creates an array of the own and inherited enumerable property names of `object`.
  28275. *
  28276. * **Note:** Non-object values are coerced to objects.
  28277. *
  28278. * @static
  28279. * @memberOf _
  28280. * @since 3.0.0
  28281. * @category Object
  28282. * @param {Object} object The object to query.
  28283. * @returns {Array} Returns the array of property names.
  28284. * @example
  28285. *
  28286. * function Foo() {
  28287. * this.a = 1;
  28288. * this.b = 2;
  28289. * }
  28290. *
  28291. * Foo.prototype.c = 3;
  28292. *
  28293. * _.keysIn(new Foo);
  28294. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  28295. */
  28296. function keysIn(object) {
  28297. var index = -1,
  28298. isProto = isPrototype(object),
  28299. props = baseKeysIn(object),
  28300. propsLength = props.length,
  28301. indexes = indexKeys(object),
  28302. skipIndexes = !!indexes,
  28303. result = indexes || [],
  28304. length = result.length;
  28305. while (++index < propsLength) {
  28306. var key = props[index];
  28307. if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
  28308. !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  28309. result.push(key);
  28310. }
  28311. }
  28312. return result;
  28313. }
  28314. /**
  28315. * The opposite of `_.mapValues`; this method creates an object with the
  28316. * same values as `object` and keys generated by running each own enumerable
  28317. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  28318. * with three arguments: (value, key, object).
  28319. *
  28320. * @static
  28321. * @memberOf _
  28322. * @since 3.8.0
  28323. * @category Object
  28324. * @param {Object} object The object to iterate over.
  28325. * @param {Array|Function|Object|string} [iteratee=_.identity]
  28326. * The function invoked per iteration.
  28327. * @returns {Object} Returns the new mapped object.
  28328. * @see _.mapValues
  28329. * @example
  28330. *
  28331. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  28332. * return key + value;
  28333. * });
  28334. * // => { 'a1': 1, 'b2': 2 }
  28335. */
  28336. function mapKeys(object, iteratee) {
  28337. var result = {};
  28338. iteratee = getIteratee(iteratee, 3);
  28339. baseForOwn(object, function(value, key, object) {
  28340. result[iteratee(value, key, object)] = value;
  28341. });
  28342. return result;
  28343. }
  28344. /**
  28345. * Creates an object with the same keys as `object` and values generated
  28346. * by running each own enumerable string keyed property of `object` thru
  28347. * `iteratee`. The iteratee is invoked with three arguments:
  28348. * (value, key, object).
  28349. *
  28350. * @static
  28351. * @memberOf _
  28352. * @since 2.4.0
  28353. * @category Object
  28354. * @param {Object} object The object to iterate over.
  28355. * @param {Array|Function|Object|string} [iteratee=_.identity]
  28356. * The function invoked per iteration.
  28357. * @returns {Object} Returns the new mapped object.
  28358. * @see _.mapKeys
  28359. * @example
  28360. *
  28361. * var users = {
  28362. * 'fred': { 'user': 'fred', 'age': 40 },
  28363. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  28364. * };
  28365. *
  28366. * _.mapValues(users, function(o) { return o.age; });
  28367. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  28368. *
  28369. * // The `_.property` iteratee shorthand.
  28370. * _.mapValues(users, 'age');
  28371. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  28372. */
  28373. function mapValues(object, iteratee) {
  28374. var result = {};
  28375. iteratee = getIteratee(iteratee, 3);
  28376. baseForOwn(object, function(value, key, object) {
  28377. result[key] = iteratee(value, key, object);
  28378. });
  28379. return result;
  28380. }
  28381. /**
  28382. * This method is like `_.assign` except that it recursively merges own and
  28383. * inherited enumerable string keyed properties of source objects into the
  28384. * destination object. Source properties that resolve to `undefined` are
  28385. * skipped if a destination value exists. Array and plain object properties
  28386. * are merged recursively. Other objects and value types are overridden by
  28387. * assignment. Source objects are applied from left to right. Subsequent
  28388. * sources overwrite property assignments of previous sources.
  28389. *
  28390. * **Note:** This method mutates `object`.
  28391. *
  28392. * @static
  28393. * @memberOf _
  28394. * @since 0.5.0
  28395. * @category Object
  28396. * @param {Object} object The destination object.
  28397. * @param {...Object} [sources] The source objects.
  28398. * @returns {Object} Returns `object`.
  28399. * @example
  28400. *
  28401. * var users = {
  28402. * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
  28403. * };
  28404. *
  28405. * var ages = {
  28406. * 'data': [{ 'age': 36 }, { 'age': 40 }]
  28407. * };
  28408. *
  28409. * _.merge(users, ages);
  28410. * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
  28411. */
  28412. var merge = createAssigner(function(object, source, srcIndex) {
  28413. baseMerge(object, source, srcIndex);
  28414. });
  28415. /**
  28416. * This method is like `_.merge` except that it accepts `customizer` which
  28417. * is invoked to produce the merged values of the destination and source
  28418. * properties. If `customizer` returns `undefined`, merging is handled by the
  28419. * method instead. The `customizer` is invoked with seven arguments:
  28420. * (objValue, srcValue, key, object, source, stack).
  28421. *
  28422. * **Note:** This method mutates `object`.
  28423. *
  28424. * @static
  28425. * @memberOf _
  28426. * @since 4.0.0
  28427. * @category Object
  28428. * @param {Object} object The destination object.
  28429. * @param {...Object} sources The source objects.
  28430. * @param {Function} customizer The function to customize assigned values.
  28431. * @returns {Object} Returns `object`.
  28432. * @example
  28433. *
  28434. * function customizer(objValue, srcValue) {
  28435. * if (_.isArray(objValue)) {
  28436. * return objValue.concat(srcValue);
  28437. * }
  28438. * }
  28439. *
  28440. * var object = {
  28441. * 'fruits': ['apple'],
  28442. * 'vegetables': ['beet']
  28443. * };
  28444. *
  28445. * var other = {
  28446. * 'fruits': ['banana'],
  28447. * 'vegetables': ['carrot']
  28448. * };
  28449. *
  28450. * _.mergeWith(object, other, customizer);
  28451. * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
  28452. */
  28453. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  28454. baseMerge(object, source, srcIndex, customizer);
  28455. });
  28456. /**
  28457. * The opposite of `_.pick`; this method creates an object composed of the
  28458. * own and inherited enumerable string keyed properties of `object` that are
  28459. * not omitted.
  28460. *
  28461. * @static
  28462. * @since 0.1.0
  28463. * @memberOf _
  28464. * @category Object
  28465. * @param {Object} object The source object.
  28466. * @param {...(string|string[])} [props] The property identifiers to omit.
  28467. * @returns {Object} Returns the new object.
  28468. * @example
  28469. *
  28470. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  28471. *
  28472. * _.omit(object, ['a', 'c']);
  28473. * // => { 'b': '2' }
  28474. */
  28475. var omit = rest(function(object, props) {
  28476. if (object == null) {
  28477. return {};
  28478. }
  28479. props = arrayMap(baseFlatten(props, 1), toKey);
  28480. return basePick(object, baseDifference(getAllKeysIn(object), props));
  28481. });
  28482. /**
  28483. * The opposite of `_.pickBy`; this method creates an object composed of
  28484. * the own and inherited enumerable string keyed properties of `object` that
  28485. * `predicate` doesn't return truthy for. The predicate is invoked with two
  28486. * arguments: (value, key).
  28487. *
  28488. * @static
  28489. * @memberOf _
  28490. * @since 4.0.0
  28491. * @category Object
  28492. * @param {Object} object The source object.
  28493. * @param {Array|Function|Object|string} [predicate=_.identity]
  28494. * The function invoked per property.
  28495. * @returns {Object} Returns the new object.
  28496. * @example
  28497. *
  28498. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  28499. *
  28500. * _.omitBy(object, _.isNumber);
  28501. * // => { 'b': '2' }
  28502. */
  28503. function omitBy(object, predicate) {
  28504. predicate = getIteratee(predicate);
  28505. return basePickBy(object, function(value, key) {
  28506. return !predicate(value, key);
  28507. });
  28508. }
  28509. /**
  28510. * Creates an object composed of the picked `object` properties.
  28511. *
  28512. * @static
  28513. * @since 0.1.0
  28514. * @memberOf _
  28515. * @category Object
  28516. * @param {Object} object The source object.
  28517. * @param {...(string|string[])} [props] The property identifiers to pick.
  28518. * @returns {Object} Returns the new object.
  28519. * @example
  28520. *
  28521. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  28522. *
  28523. * _.pick(object, ['a', 'c']);
  28524. * // => { 'a': 1, 'c': 3 }
  28525. */
  28526. var pick = rest(function(object, props) {
  28527. return object == null ? {} : basePick(object, arrayMap(baseFlatten(props, 1), toKey));
  28528. });
  28529. /**
  28530. * Creates an object composed of the `object` properties `predicate` returns
  28531. * truthy for. The predicate is invoked with two arguments: (value, key).
  28532. *
  28533. * @static
  28534. * @memberOf _
  28535. * @since 4.0.0
  28536. * @category Object
  28537. * @param {Object} object The source object.
  28538. * @param {Array|Function|Object|string} [predicate=_.identity]
  28539. * The function invoked per property.
  28540. * @returns {Object} Returns the new object.
  28541. * @example
  28542. *
  28543. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  28544. *
  28545. * _.pickBy(object, _.isNumber);
  28546. * // => { 'a': 1, 'c': 3 }
  28547. */
  28548. function pickBy(object, predicate) {
  28549. return object == null ? {} : basePickBy(object, getIteratee(predicate));
  28550. }
  28551. /**
  28552. * This method is like `_.get` except that if the resolved value is a
  28553. * function it's invoked with the `this` binding of its parent object and
  28554. * its result is returned.
  28555. *
  28556. * @static
  28557. * @since 0.1.0
  28558. * @memberOf _
  28559. * @category Object
  28560. * @param {Object} object The object to query.
  28561. * @param {Array|string} path The path of the property to resolve.
  28562. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  28563. * @returns {*} Returns the resolved value.
  28564. * @example
  28565. *
  28566. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  28567. *
  28568. * _.result(object, 'a[0].b.c1');
  28569. * // => 3
  28570. *
  28571. * _.result(object, 'a[0].b.c2');
  28572. * // => 4
  28573. *
  28574. * _.result(object, 'a[0].b.c3', 'default');
  28575. * // => 'default'
  28576. *
  28577. * _.result(object, 'a[0].b.c3', _.constant('default'));
  28578. * // => 'default'
  28579. */
  28580. function result(object, path, defaultValue) {
  28581. path = isKey(path, object) ? [path] : castPath(path);
  28582. var index = -1,
  28583. length = path.length;
  28584. // Ensure the loop is entered when path is empty.
  28585. if (!length) {
  28586. object = undefined;
  28587. length = 1;
  28588. }
  28589. while (++index < length) {
  28590. var value = object == null ? undefined : object[toKey(path[index])];
  28591. if (value === undefined) {
  28592. index = length;
  28593. value = defaultValue;
  28594. }
  28595. object = isFunction(value) ? value.call(object) : value;
  28596. }
  28597. return object;
  28598. }
  28599. /**
  28600. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  28601. * it's created. Arrays are created for missing index properties while objects
  28602. * are created for all other missing properties. Use `_.setWith` to customize
  28603. * `path` creation.
  28604. *
  28605. * **Note:** This method mutates `object`.
  28606. *
  28607. * @static
  28608. * @memberOf _
  28609. * @since 3.7.0
  28610. * @category Object
  28611. * @param {Object} object The object to modify.
  28612. * @param {Array|string} path The path of the property to set.
  28613. * @param {*} value The value to set.
  28614. * @returns {Object} Returns `object`.
  28615. * @example
  28616. *
  28617. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  28618. *
  28619. * _.set(object, 'a[0].b.c', 4);
  28620. * console.log(object.a[0].b.c);
  28621. * // => 4
  28622. *
  28623. * _.set(object, ['x', '0', 'y', 'z'], 5);
  28624. * console.log(object.x[0].y.z);
  28625. * // => 5
  28626. */
  28627. function set(object, path, value) {
  28628. return object == null ? object : baseSet(object, path, value);
  28629. }
  28630. /**
  28631. * This method is like `_.set` except that it accepts `customizer` which is
  28632. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  28633. * path creation is handled by the method instead. The `customizer` is invoked
  28634. * with three arguments: (nsValue, key, nsObject).
  28635. *
  28636. * **Note:** This method mutates `object`.
  28637. *
  28638. * @static
  28639. * @memberOf _
  28640. * @since 4.0.0
  28641. * @category Object
  28642. * @param {Object} object The object to modify.
  28643. * @param {Array|string} path The path of the property to set.
  28644. * @param {*} value The value to set.
  28645. * @param {Function} [customizer] The function to customize assigned values.
  28646. * @returns {Object} Returns `object`.
  28647. * @example
  28648. *
  28649. * var object = {};
  28650. *
  28651. * _.setWith(object, '[0][1]', 'a', Object);
  28652. * // => { '0': { '1': 'a' } }
  28653. */
  28654. function setWith(object, path, value, customizer) {
  28655. customizer = typeof customizer == 'function' ? customizer : undefined;
  28656. return object == null ? object : baseSet(object, path, value, customizer);
  28657. }
  28658. /**
  28659. * Creates an array of own enumerable string keyed-value pairs for `object`
  28660. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  28661. * entries are returned.
  28662. *
  28663. * @static
  28664. * @memberOf _
  28665. * @since 4.0.0
  28666. * @alias entries
  28667. * @category Object
  28668. * @param {Object} object The object to query.
  28669. * @returns {Array} Returns the key-value pairs.
  28670. * @example
  28671. *
  28672. * function Foo() {
  28673. * this.a = 1;
  28674. * this.b = 2;
  28675. * }
  28676. *
  28677. * Foo.prototype.c = 3;
  28678. *
  28679. * _.toPairs(new Foo);
  28680. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  28681. */
  28682. var toPairs = createToPairs(keys);
  28683. /**
  28684. * Creates an array of own and inherited enumerable string keyed-value pairs
  28685. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  28686. * or set, its entries are returned.
  28687. *
  28688. * @static
  28689. * @memberOf _
  28690. * @since 4.0.0
  28691. * @alias entriesIn
  28692. * @category Object
  28693. * @param {Object} object The object to query.
  28694. * @returns {Array} Returns the key-value pairs.
  28695. * @example
  28696. *
  28697. * function Foo() {
  28698. * this.a = 1;
  28699. * this.b = 2;
  28700. * }
  28701. *
  28702. * Foo.prototype.c = 3;
  28703. *
  28704. * _.toPairsIn(new Foo);
  28705. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  28706. */
  28707. var toPairsIn = createToPairs(keysIn);
  28708. /**
  28709. * An alternative to `_.reduce`; this method transforms `object` to a new
  28710. * `accumulator` object which is the result of running each of its own
  28711. * enumerable string keyed properties thru `iteratee`, with each invocation
  28712. * potentially mutating the `accumulator` object. If `accumulator` is not
  28713. * provided, a new object with the same `[[Prototype]]` will be used. The
  28714. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  28715. * Iteratee functions may exit iteration early by explicitly returning `false`.
  28716. *
  28717. * @static
  28718. * @memberOf _
  28719. * @since 1.3.0
  28720. * @category Object
  28721. * @param {Object} object The object to iterate over.
  28722. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  28723. * @param {*} [accumulator] The custom accumulator value.
  28724. * @returns {*} Returns the accumulated value.
  28725. * @example
  28726. *
  28727. * _.transform([2, 3, 4], function(result, n) {
  28728. * result.push(n *= n);
  28729. * return n % 2 == 0;
  28730. * }, []);
  28731. * // => [4, 9]
  28732. *
  28733. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  28734. * (result[value] || (result[value] = [])).push(key);
  28735. * }, {});
  28736. * // => { '1': ['a', 'c'], '2': ['b'] }
  28737. */
  28738. function transform(object, iteratee, accumulator) {
  28739. var isArr = isArray(object) || isTypedArray(object);
  28740. iteratee = getIteratee(iteratee, 4);
  28741. if (accumulator == null) {
  28742. if (isArr || isObject(object)) {
  28743. var Ctor = object.constructor;
  28744. if (isArr) {
  28745. accumulator = isArray(object) ? new Ctor : [];
  28746. } else {
  28747. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  28748. }
  28749. } else {
  28750. accumulator = {};
  28751. }
  28752. }
  28753. (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
  28754. return iteratee(accumulator, value, index, object);
  28755. });
  28756. return accumulator;
  28757. }
  28758. /**
  28759. * Removes the property at `path` of `object`.
  28760. *
  28761. * **Note:** This method mutates `object`.
  28762. *
  28763. * @static
  28764. * @memberOf _
  28765. * @since 4.0.0
  28766. * @category Object
  28767. * @param {Object} object The object to modify.
  28768. * @param {Array|string} path The path of the property to unset.
  28769. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  28770. * @example
  28771. *
  28772. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  28773. * _.unset(object, 'a[0].b.c');
  28774. * // => true
  28775. *
  28776. * console.log(object);
  28777. * // => { 'a': [{ 'b': {} }] };
  28778. *
  28779. * _.unset(object, ['a', '0', 'b', 'c']);
  28780. * // => true
  28781. *
  28782. * console.log(object);
  28783. * // => { 'a': [{ 'b': {} }] };
  28784. */
  28785. function unset(object, path) {
  28786. return object == null ? true : baseUnset(object, path);
  28787. }
  28788. /**
  28789. * This method is like `_.set` except that accepts `updater` to produce the
  28790. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  28791. * is invoked with one argument: (value).
  28792. *
  28793. * **Note:** This method mutates `object`.
  28794. *
  28795. * @static
  28796. * @memberOf _
  28797. * @since 4.6.0
  28798. * @category Object
  28799. * @param {Object} object The object to modify.
  28800. * @param {Array|string} path The path of the property to set.
  28801. * @param {Function} updater The function to produce the updated value.
  28802. * @returns {Object} Returns `object`.
  28803. * @example
  28804. *
  28805. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  28806. *
  28807. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  28808. * console.log(object.a[0].b.c);
  28809. * // => 9
  28810. *
  28811. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  28812. * console.log(object.x[0].y.z);
  28813. * // => 0
  28814. */
  28815. function update(object, path, updater) {
  28816. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  28817. }
  28818. /**
  28819. * This method is like `_.update` except that it accepts `customizer` which is
  28820. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  28821. * path creation is handled by the method instead. The `customizer` is invoked
  28822. * with three arguments: (nsValue, key, nsObject).
  28823. *
  28824. * **Note:** This method mutates `object`.
  28825. *
  28826. * @static
  28827. * @memberOf _
  28828. * @since 4.6.0
  28829. * @category Object
  28830. * @param {Object} object The object to modify.
  28831. * @param {Array|string} path The path of the property to set.
  28832. * @param {Function} updater The function to produce the updated value.
  28833. * @param {Function} [customizer] The function to customize assigned values.
  28834. * @returns {Object} Returns `object`.
  28835. * @example
  28836. *
  28837. * var object = {};
  28838. *
  28839. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  28840. * // => { '0': { '1': 'a' } }
  28841. */
  28842. function updateWith(object, path, updater, customizer) {
  28843. customizer = typeof customizer == 'function' ? customizer : undefined;
  28844. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  28845. }
  28846. /**
  28847. * Creates an array of the own enumerable string keyed property values of `object`.
  28848. *
  28849. * **Note:** Non-object values are coerced to objects.
  28850. *
  28851. * @static
  28852. * @since 0.1.0
  28853. * @memberOf _
  28854. * @category Object
  28855. * @param {Object} object The object to query.
  28856. * @returns {Array} Returns the array of property values.
  28857. * @example
  28858. *
  28859. * function Foo() {
  28860. * this.a = 1;
  28861. * this.b = 2;
  28862. * }
  28863. *
  28864. * Foo.prototype.c = 3;
  28865. *
  28866. * _.values(new Foo);
  28867. * // => [1, 2] (iteration order is not guaranteed)
  28868. *
  28869. * _.values('hi');
  28870. * // => ['h', 'i']
  28871. */
  28872. function values(object) {
  28873. return object ? baseValues(object, keys(object)) : [];
  28874. }
  28875. /**
  28876. * Creates an array of the own and inherited enumerable string keyed property
  28877. * values of `object`.
  28878. *
  28879. * **Note:** Non-object values are coerced to objects.
  28880. *
  28881. * @static
  28882. * @memberOf _
  28883. * @since 3.0.0
  28884. * @category Object
  28885. * @param {Object} object The object to query.
  28886. * @returns {Array} Returns the array of property values.
  28887. * @example
  28888. *
  28889. * function Foo() {
  28890. * this.a = 1;
  28891. * this.b = 2;
  28892. * }
  28893. *
  28894. * Foo.prototype.c = 3;
  28895. *
  28896. * _.valuesIn(new Foo);
  28897. * // => [1, 2, 3] (iteration order is not guaranteed)
  28898. */
  28899. function valuesIn(object) {
  28900. return object == null ? [] : baseValues(object, keysIn(object));
  28901. }
  28902. /*------------------------------------------------------------------------*/
  28903. /**
  28904. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  28905. *
  28906. * @static
  28907. * @memberOf _
  28908. * @since 4.0.0
  28909. * @category Number
  28910. * @param {number} number The number to clamp.
  28911. * @param {number} [lower] The lower bound.
  28912. * @param {number} upper The upper bound.
  28913. * @returns {number} Returns the clamped number.
  28914. * @example
  28915. *
  28916. * _.clamp(-10, -5, 5);
  28917. * // => -5
  28918. *
  28919. * _.clamp(10, -5, 5);
  28920. * // => 5
  28921. */
  28922. function clamp(number, lower, upper) {
  28923. if (upper === undefined) {
  28924. upper = lower;
  28925. lower = undefined;
  28926. }
  28927. if (upper !== undefined) {
  28928. upper = toNumber(upper);
  28929. upper = upper === upper ? upper : 0;
  28930. }
  28931. if (lower !== undefined) {
  28932. lower = toNumber(lower);
  28933. lower = lower === lower ? lower : 0;
  28934. }
  28935. return baseClamp(toNumber(number), lower, upper);
  28936. }
  28937. /**
  28938. * Checks if `n` is between `start` and up to, but not including, `end`. If
  28939. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  28940. * If `start` is greater than `end` the params are swapped to support
  28941. * negative ranges.
  28942. *
  28943. * @static
  28944. * @memberOf _
  28945. * @since 3.3.0
  28946. * @category Number
  28947. * @param {number} number The number to check.
  28948. * @param {number} [start=0] The start of the range.
  28949. * @param {number} end The end of the range.
  28950. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  28951. * @see _.range, _.rangeRight
  28952. * @example
  28953. *
  28954. * _.inRange(3, 2, 4);
  28955. * // => true
  28956. *
  28957. * _.inRange(4, 8);
  28958. * // => true
  28959. *
  28960. * _.inRange(4, 2);
  28961. * // => false
  28962. *
  28963. * _.inRange(2, 2);
  28964. * // => false
  28965. *
  28966. * _.inRange(1.2, 2);
  28967. * // => true
  28968. *
  28969. * _.inRange(5.2, 4);
  28970. * // => false
  28971. *
  28972. * _.inRange(-3, -2, -6);
  28973. * // => true
  28974. */
  28975. function inRange(number, start, end) {
  28976. start = toNumber(start) || 0;
  28977. if (end === undefined) {
  28978. end = start;
  28979. start = 0;
  28980. } else {
  28981. end = toNumber(end) || 0;
  28982. }
  28983. number = toNumber(number);
  28984. return baseInRange(number, start, end);
  28985. }
  28986. /**
  28987. * Produces a random number between the inclusive `lower` and `upper` bounds.
  28988. * If only one argument is provided a number between `0` and the given number
  28989. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  28990. * floats, a floating-point number is returned instead of an integer.
  28991. *
  28992. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  28993. * floating-point values which can produce unexpected results.
  28994. *
  28995. * @static
  28996. * @memberOf _
  28997. * @since 0.7.0
  28998. * @category Number
  28999. * @param {number} [lower=0] The lower bound.
  29000. * @param {number} [upper=1] The upper bound.
  29001. * @param {boolean} [floating] Specify returning a floating-point number.
  29002. * @returns {number} Returns the random number.
  29003. * @example
  29004. *
  29005. * _.random(0, 5);
  29006. * // => an integer between 0 and 5
  29007. *
  29008. * _.random(5);
  29009. * // => also an integer between 0 and 5
  29010. *
  29011. * _.random(5, true);
  29012. * // => a floating-point number between 0 and 5
  29013. *
  29014. * _.random(1.2, 5.2);
  29015. * // => a floating-point number between 1.2 and 5.2
  29016. */
  29017. function random(lower, upper, floating) {
  29018. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  29019. upper = floating = undefined;
  29020. }
  29021. if (floating === undefined) {
  29022. if (typeof upper == 'boolean') {
  29023. floating = upper;
  29024. upper = undefined;
  29025. }
  29026. else if (typeof lower == 'boolean') {
  29027. floating = lower;
  29028. lower = undefined;
  29029. }
  29030. }
  29031. if (lower === undefined && upper === undefined) {
  29032. lower = 0;
  29033. upper = 1;
  29034. }
  29035. else {
  29036. lower = toNumber(lower) || 0;
  29037. if (upper === undefined) {
  29038. upper = lower;
  29039. lower = 0;
  29040. } else {
  29041. upper = toNumber(upper) || 0;
  29042. }
  29043. }
  29044. if (lower > upper) {
  29045. var temp = lower;
  29046. lower = upper;
  29047. upper = temp;
  29048. }
  29049. if (floating || lower % 1 || upper % 1) {
  29050. var rand = nativeRandom();
  29051. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  29052. }
  29053. return baseRandom(lower, upper);
  29054. }
  29055. /*------------------------------------------------------------------------*/
  29056. /**
  29057. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  29058. *
  29059. * @static
  29060. * @memberOf _
  29061. * @since 3.0.0
  29062. * @category String
  29063. * @param {string} [string=''] The string to convert.
  29064. * @returns {string} Returns the camel cased string.
  29065. * @example
  29066. *
  29067. * _.camelCase('Foo Bar');
  29068. * // => 'fooBar'
  29069. *
  29070. * _.camelCase('--foo-bar--');
  29071. * // => 'fooBar'
  29072. *
  29073. * _.camelCase('__FOO_BAR__');
  29074. * // => 'fooBar'
  29075. */
  29076. var camelCase = createCompounder(function(result, word, index) {
  29077. word = word.toLowerCase();
  29078. return result + (index ? capitalize(word) : word);
  29079. });
  29080. /**
  29081. * Converts the first character of `string` to upper case and the remaining
  29082. * to lower case.
  29083. *
  29084. * @static
  29085. * @memberOf _
  29086. * @since 3.0.0
  29087. * @category String
  29088. * @param {string} [string=''] The string to capitalize.
  29089. * @returns {string} Returns the capitalized string.
  29090. * @example
  29091. *
  29092. * _.capitalize('FRED');
  29093. * // => 'Fred'
  29094. */
  29095. function capitalize(string) {
  29096. return upperFirst(toString(string).toLowerCase());
  29097. }
  29098. /**
  29099. * Deburrs `string` by converting
  29100. * [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  29101. * to basic latin letters and removing
  29102. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  29103. *
  29104. * @static
  29105. * @memberOf _
  29106. * @since 3.0.0
  29107. * @category String
  29108. * @param {string} [string=''] The string to deburr.
  29109. * @returns {string} Returns the deburred string.
  29110. * @example
  29111. *
  29112. * _.deburr('déjà vu');
  29113. * // => 'deja vu'
  29114. */
  29115. function deburr(string) {
  29116. string = toString(string);
  29117. return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
  29118. }
  29119. /**
  29120. * Checks if `string` ends with the given target string.
  29121. *
  29122. * @static
  29123. * @memberOf _
  29124. * @since 3.0.0
  29125. * @category String
  29126. * @param {string} [string=''] The string to search.
  29127. * @param {string} [target] The string to search for.
  29128. * @param {number} [position=string.length] The position to search up to.
  29129. * @returns {boolean} Returns `true` if `string` ends with `target`,
  29130. * else `false`.
  29131. * @example
  29132. *
  29133. * _.endsWith('abc', 'c');
  29134. * // => true
  29135. *
  29136. * _.endsWith('abc', 'b');
  29137. * // => false
  29138. *
  29139. * _.endsWith('abc', 'b', 2);
  29140. * // => true
  29141. */
  29142. function endsWith(string, target, position) {
  29143. string = toString(string);
  29144. target = baseToString(target);
  29145. var length = string.length;
  29146. position = position === undefined
  29147. ? length
  29148. : baseClamp(toInteger(position), 0, length);
  29149. position -= target.length;
  29150. return position >= 0 && string.indexOf(target, position) == position;
  29151. }
  29152. /**
  29153. * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
  29154. * their corresponding HTML entities.
  29155. *
  29156. * **Note:** No other characters are escaped. To escape additional
  29157. * characters use a third-party library like [_he_](https://mths.be/he).
  29158. *
  29159. * Though the ">" character is escaped for symmetry, characters like
  29160. * ">" and "/" don't need escaping in HTML and have no special meaning
  29161. * unless they're part of a tag or unquoted attribute value. See
  29162. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  29163. * (under "semi-related fun fact") for more details.
  29164. *
  29165. * Backticks are escaped because in IE < 9, they can break out of
  29166. * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
  29167. * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
  29168. * [#133](https://html5sec.org/#133) of the
  29169. * [HTML5 Security Cheatsheet](https://html5sec.org/) for more details.
  29170. *
  29171. * When working with HTML you should always
  29172. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  29173. * XSS vectors.
  29174. *
  29175. * @static
  29176. * @since 0.1.0
  29177. * @memberOf _
  29178. * @category String
  29179. * @param {string} [string=''] The string to escape.
  29180. * @returns {string} Returns the escaped string.
  29181. * @example
  29182. *
  29183. * _.escape('fred, barney, & pebbles');
  29184. * // => 'fred, barney, &amp; pebbles'
  29185. */
  29186. function escape(string) {
  29187. string = toString(string);
  29188. return (string && reHasUnescapedHtml.test(string))
  29189. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  29190. : string;
  29191. }
  29192. /**
  29193. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  29194. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  29195. *
  29196. * @static
  29197. * @memberOf _
  29198. * @since 3.0.0
  29199. * @category String
  29200. * @param {string} [string=''] The string to escape.
  29201. * @returns {string} Returns the escaped string.
  29202. * @example
  29203. *
  29204. * _.escapeRegExp('[lodash](https://lodash.com/)');
  29205. * // => '\[lodash\]\(https://lodash\.com/\)'
  29206. */
  29207. function escapeRegExp(string) {
  29208. string = toString(string);
  29209. return (string && reHasRegExpChar.test(string))
  29210. ? string.replace(reRegExpChar, '\\$&')
  29211. : string;
  29212. }
  29213. /**
  29214. * Converts `string` to
  29215. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  29216. *
  29217. * @static
  29218. * @memberOf _
  29219. * @since 3.0.0
  29220. * @category String
  29221. * @param {string} [string=''] The string to convert.
  29222. * @returns {string} Returns the kebab cased string.
  29223. * @example
  29224. *
  29225. * _.kebabCase('Foo Bar');
  29226. * // => 'foo-bar'
  29227. *
  29228. * _.kebabCase('fooBar');
  29229. * // => 'foo-bar'
  29230. *
  29231. * _.kebabCase('__FOO_BAR__');
  29232. * // => 'foo-bar'
  29233. */
  29234. var kebabCase = createCompounder(function(result, word, index) {
  29235. return result + (index ? '-' : '') + word.toLowerCase();
  29236. });
  29237. /**
  29238. * Converts `string`, as space separated words, to lower case.
  29239. *
  29240. * @static
  29241. * @memberOf _
  29242. * @since 4.0.0
  29243. * @category String
  29244. * @param {string} [string=''] The string to convert.
  29245. * @returns {string} Returns the lower cased string.
  29246. * @example
  29247. *
  29248. * _.lowerCase('--Foo-Bar--');
  29249. * // => 'foo bar'
  29250. *
  29251. * _.lowerCase('fooBar');
  29252. * // => 'foo bar'
  29253. *
  29254. * _.lowerCase('__FOO_BAR__');
  29255. * // => 'foo bar'
  29256. */
  29257. var lowerCase = createCompounder(function(result, word, index) {
  29258. return result + (index ? ' ' : '') + word.toLowerCase();
  29259. });
  29260. /**
  29261. * Converts the first character of `string` to lower case.
  29262. *
  29263. * @static
  29264. * @memberOf _
  29265. * @since 4.0.0
  29266. * @category String
  29267. * @param {string} [string=''] The string to convert.
  29268. * @returns {string} Returns the converted string.
  29269. * @example
  29270. *
  29271. * _.lowerFirst('Fred');
  29272. * // => 'fred'
  29273. *
  29274. * _.lowerFirst('FRED');
  29275. * // => 'fRED'
  29276. */
  29277. var lowerFirst = createCaseFirst('toLowerCase');
  29278. /**
  29279. * Pads `string` on the left and right sides if it's shorter than `length`.
  29280. * Padding characters are truncated if they can't be evenly divided by `length`.
  29281. *
  29282. * @static
  29283. * @memberOf _
  29284. * @since 3.0.0
  29285. * @category String
  29286. * @param {string} [string=''] The string to pad.
  29287. * @param {number} [length=0] The padding length.
  29288. * @param {string} [chars=' '] The string used as padding.
  29289. * @returns {string} Returns the padded string.
  29290. * @example
  29291. *
  29292. * _.pad('abc', 8);
  29293. * // => ' abc '
  29294. *
  29295. * _.pad('abc', 8, '_-');
  29296. * // => '_-abc_-_'
  29297. *
  29298. * _.pad('abc', 3);
  29299. * // => 'abc'
  29300. */
  29301. function pad(string, length, chars) {
  29302. string = toString(string);
  29303. length = toInteger(length);
  29304. var strLength = length ? stringSize(string) : 0;
  29305. if (!length || strLength >= length) {
  29306. return string;
  29307. }
  29308. var mid = (length - strLength) / 2;
  29309. return (
  29310. createPadding(nativeFloor(mid), chars) +
  29311. string +
  29312. createPadding(nativeCeil(mid), chars)
  29313. );
  29314. }
  29315. /**
  29316. * Pads `string` on the right side if it's shorter than `length`. Padding
  29317. * characters are truncated if they exceed `length`.
  29318. *
  29319. * @static
  29320. * @memberOf _
  29321. * @since 4.0.0
  29322. * @category String
  29323. * @param {string} [string=''] The string to pad.
  29324. * @param {number} [length=0] The padding length.
  29325. * @param {string} [chars=' '] The string used as padding.
  29326. * @returns {string} Returns the padded string.
  29327. * @example
  29328. *
  29329. * _.padEnd('abc', 6);
  29330. * // => 'abc '
  29331. *
  29332. * _.padEnd('abc', 6, '_-');
  29333. * // => 'abc_-_'
  29334. *
  29335. * _.padEnd('abc', 3);
  29336. * // => 'abc'
  29337. */
  29338. function padEnd(string, length, chars) {
  29339. string = toString(string);
  29340. length = toInteger(length);
  29341. var strLength = length ? stringSize(string) : 0;
  29342. return (length && strLength < length)
  29343. ? (string + createPadding(length - strLength, chars))
  29344. : string;
  29345. }
  29346. /**
  29347. * Pads `string` on the left side if it's shorter than `length`. Padding
  29348. * characters are truncated if they exceed `length`.
  29349. *
  29350. * @static
  29351. * @memberOf _
  29352. * @since 4.0.0
  29353. * @category String
  29354. * @param {string} [string=''] The string to pad.
  29355. * @param {number} [length=0] The padding length.
  29356. * @param {string} [chars=' '] The string used as padding.
  29357. * @returns {string} Returns the padded string.
  29358. * @example
  29359. *
  29360. * _.padStart('abc', 6);
  29361. * // => ' abc'
  29362. *
  29363. * _.padStart('abc', 6, '_-');
  29364. * // => '_-_abc'
  29365. *
  29366. * _.padStart('abc', 3);
  29367. * // => 'abc'
  29368. */
  29369. function padStart(string, length, chars) {
  29370. string = toString(string);
  29371. length = toInteger(length);
  29372. var strLength = length ? stringSize(string) : 0;
  29373. return (length && strLength < length)
  29374. ? (createPadding(length - strLength, chars) + string)
  29375. : string;
  29376. }
  29377. /**
  29378. * Converts `string` to an integer of the specified radix. If `radix` is
  29379. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  29380. * hexadecimal, in which case a `radix` of `16` is used.
  29381. *
  29382. * **Note:** This method aligns with the
  29383. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  29384. *
  29385. * @static
  29386. * @memberOf _
  29387. * @since 1.1.0
  29388. * @category String
  29389. * @param {string} string The string to convert.
  29390. * @param {number} [radix=10] The radix to interpret `value` by.
  29391. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  29392. * @returns {number} Returns the converted integer.
  29393. * @example
  29394. *
  29395. * _.parseInt('08');
  29396. * // => 8
  29397. *
  29398. * _.map(['6', '08', '10'], _.parseInt);
  29399. * // => [6, 8, 10]
  29400. */
  29401. function parseInt(string, radix, guard) {
  29402. // Chrome fails to trim leading <BOM> whitespace characters.
  29403. // See https://bugs.chromium.org/p/v8/issues/detail?id=3109 for more details.
  29404. if (guard || radix == null) {
  29405. radix = 0;
  29406. } else if (radix) {
  29407. radix = +radix;
  29408. }
  29409. string = toString(string).replace(reTrim, '');
  29410. return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
  29411. }
  29412. /**
  29413. * Repeats the given string `n` times.
  29414. *
  29415. * @static
  29416. * @memberOf _
  29417. * @since 3.0.0
  29418. * @category String
  29419. * @param {string} [string=''] The string to repeat.
  29420. * @param {number} [n=1] The number of times to repeat the string.
  29421. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  29422. * @returns {string} Returns the repeated string.
  29423. * @example
  29424. *
  29425. * _.repeat('*', 3);
  29426. * // => '***'
  29427. *
  29428. * _.repeat('abc', 2);
  29429. * // => 'abcabc'
  29430. *
  29431. * _.repeat('abc', 0);
  29432. * // => ''
  29433. */
  29434. function repeat(string, n, guard) {
  29435. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  29436. n = 1;
  29437. } else {
  29438. n = toInteger(n);
  29439. }
  29440. return baseRepeat(toString(string), n);
  29441. }
  29442. /**
  29443. * Replaces matches for `pattern` in `string` with `replacement`.
  29444. *
  29445. * **Note:** This method is based on
  29446. * [`String#replace`](https://mdn.io/String/replace).
  29447. *
  29448. * @static
  29449. * @memberOf _
  29450. * @since 4.0.0
  29451. * @category String
  29452. * @param {string} [string=''] The string to modify.
  29453. * @param {RegExp|string} pattern The pattern to replace.
  29454. * @param {Function|string} replacement The match replacement.
  29455. * @returns {string} Returns the modified string.
  29456. * @example
  29457. *
  29458. * _.replace('Hi Fred', 'Fred', 'Barney');
  29459. * // => 'Hi Barney'
  29460. */
  29461. function replace() {
  29462. var args = arguments,
  29463. string = toString(args[0]);
  29464. return args.length < 3 ? string : nativeReplace.call(string, args[1], args[2]);
  29465. }
  29466. /**
  29467. * Converts `string` to
  29468. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  29469. *
  29470. * @static
  29471. * @memberOf _
  29472. * @since 3.0.0
  29473. * @category String
  29474. * @param {string} [string=''] The string to convert.
  29475. * @returns {string} Returns the snake cased string.
  29476. * @example
  29477. *
  29478. * _.snakeCase('Foo Bar');
  29479. * // => 'foo_bar'
  29480. *
  29481. * _.snakeCase('fooBar');
  29482. * // => 'foo_bar'
  29483. *
  29484. * _.snakeCase('--FOO-BAR--');
  29485. * // => 'foo_bar'
  29486. */
  29487. var snakeCase = createCompounder(function(result, word, index) {
  29488. return result + (index ? '_' : '') + word.toLowerCase();
  29489. });
  29490. /**
  29491. * Splits `string` by `separator`.
  29492. *
  29493. * **Note:** This method is based on
  29494. * [`String#split`](https://mdn.io/String/split).
  29495. *
  29496. * @static
  29497. * @memberOf _
  29498. * @since 4.0.0
  29499. * @category String
  29500. * @param {string} [string=''] The string to split.
  29501. * @param {RegExp|string} separator The separator pattern to split by.
  29502. * @param {number} [limit] The length to truncate results to.
  29503. * @returns {Array} Returns the string segments.
  29504. * @example
  29505. *
  29506. * _.split('a-b-c', '-', 2);
  29507. * // => ['a', 'b']
  29508. */
  29509. function split(string, separator, limit) {
  29510. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  29511. separator = limit = undefined;
  29512. }
  29513. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  29514. if (!limit) {
  29515. return [];
  29516. }
  29517. string = toString(string);
  29518. if (string && (
  29519. typeof separator == 'string' ||
  29520. (separator != null && !isRegExp(separator))
  29521. )) {
  29522. separator = baseToString(separator);
  29523. if (separator == '' && reHasComplexSymbol.test(string)) {
  29524. return castSlice(stringToArray(string), 0, limit);
  29525. }
  29526. }
  29527. return nativeSplit.call(string, separator, limit);
  29528. }
  29529. /**
  29530. * Converts `string` to
  29531. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  29532. *
  29533. * @static
  29534. * @memberOf _
  29535. * @since 3.1.0
  29536. * @category String
  29537. * @param {string} [string=''] The string to convert.
  29538. * @returns {string} Returns the start cased string.
  29539. * @example
  29540. *
  29541. * _.startCase('--foo-bar--');
  29542. * // => 'Foo Bar'
  29543. *
  29544. * _.startCase('fooBar');
  29545. * // => 'Foo Bar'
  29546. *
  29547. * _.startCase('__FOO_BAR__');
  29548. * // => 'FOO BAR'
  29549. */
  29550. var startCase = createCompounder(function(result, word, index) {
  29551. return result + (index ? ' ' : '') + upperFirst(word);
  29552. });
  29553. /**
  29554. * Checks if `string` starts with the given target string.
  29555. *
  29556. * @static
  29557. * @memberOf _
  29558. * @since 3.0.0
  29559. * @category String
  29560. * @param {string} [string=''] The string to search.
  29561. * @param {string} [target] The string to search for.
  29562. * @param {number} [position=0] The position to search from.
  29563. * @returns {boolean} Returns `true` if `string` starts with `target`,
  29564. * else `false`.
  29565. * @example
  29566. *
  29567. * _.startsWith('abc', 'a');
  29568. * // => true
  29569. *
  29570. * _.startsWith('abc', 'b');
  29571. * // => false
  29572. *
  29573. * _.startsWith('abc', 'b', 1);
  29574. * // => true
  29575. */
  29576. function startsWith(string, target, position) {
  29577. string = toString(string);
  29578. position = baseClamp(toInteger(position), 0, string.length);
  29579. return string.lastIndexOf(baseToString(target), position) == position;
  29580. }
  29581. /**
  29582. * Creates a compiled template function that can interpolate data properties
  29583. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  29584. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  29585. * properties may be accessed as free variables in the template. If a setting
  29586. * object is given, it takes precedence over `_.templateSettings` values.
  29587. *
  29588. * **Note:** In the development build `_.template` utilizes
  29589. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  29590. * for easier debugging.
  29591. *
  29592. * For more information on precompiling templates see
  29593. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  29594. *
  29595. * For more information on Chrome extension sandboxes see
  29596. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  29597. *
  29598. * @static
  29599. * @since 0.1.0
  29600. * @memberOf _
  29601. * @category String
  29602. * @param {string} [string=''] The template string.
  29603. * @param {Object} [options={}] The options object.
  29604. * @param {RegExp} [options.escape=_.templateSettings.escape]
  29605. * The HTML "escape" delimiter.
  29606. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  29607. * The "evaluate" delimiter.
  29608. * @param {Object} [options.imports=_.templateSettings.imports]
  29609. * An object to import into the template as free variables.
  29610. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  29611. * The "interpolate" delimiter.
  29612. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  29613. * The sourceURL of the compiled template.
  29614. * @param {string} [options.variable='obj']
  29615. * The data object variable name.
  29616. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  29617. * @returns {Function} Returns the compiled template function.
  29618. * @example
  29619. *
  29620. * // Use the "interpolate" delimiter to create a compiled template.
  29621. * var compiled = _.template('hello <%= user %>!');
  29622. * compiled({ 'user': 'fred' });
  29623. * // => 'hello fred!'
  29624. *
  29625. * // Use the HTML "escape" delimiter to escape data property values.
  29626. * var compiled = _.template('<b><%- value %></b>');
  29627. * compiled({ 'value': '<script>' });
  29628. * // => '<b>&lt;script&gt;</b>'
  29629. *
  29630. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  29631. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  29632. * compiled({ 'users': ['fred', 'barney'] });
  29633. * // => '<li>fred</li><li>barney</li>'
  29634. *
  29635. * // Use the internal `print` function in "evaluate" delimiters.
  29636. * var compiled = _.template('<% print("hello " + user); %>!');
  29637. * compiled({ 'user': 'barney' });
  29638. * // => 'hello barney!'
  29639. *
  29640. * // Use the ES delimiter as an alternative to the default "interpolate" delimiter.
  29641. * var compiled = _.template('hello ${ user }!');
  29642. * compiled({ 'user': 'pebbles' });
  29643. * // => 'hello pebbles!'
  29644. *
  29645. * // Use backslashes to treat delimiters as plain text.
  29646. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  29647. * compiled({ 'value': 'ignored' });
  29648. * // => '<%- value %>'
  29649. *
  29650. * // Use the `imports` option to import `jQuery` as `jq`.
  29651. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  29652. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  29653. * compiled({ 'users': ['fred', 'barney'] });
  29654. * // => '<li>fred</li><li>barney</li>'
  29655. *
  29656. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  29657. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  29658. * compiled(data);
  29659. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  29660. *
  29661. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  29662. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  29663. * compiled.source;
  29664. * // => function(data) {
  29665. * // var __t, __p = '';
  29666. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  29667. * // return __p;
  29668. * // }
  29669. *
  29670. * // Use custom template delimiters.
  29671. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  29672. * var compiled = _.template('hello {{ user }}!');
  29673. * compiled({ 'user': 'mustache' });
  29674. * // => 'hello mustache!'
  29675. *
  29676. * // Use the `source` property to inline compiled templates for meaningful
  29677. * // line numbers in error messages and stack traces.
  29678. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  29679. * var JST = {\
  29680. * "main": ' + _.template(mainText).source + '\
  29681. * };\
  29682. * ');
  29683. */
  29684. function template(string, options, guard) {
  29685. // Based on John Resig's `tmpl` implementation
  29686. // (http://ejohn.org/blog/javascript-micro-templating/)
  29687. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  29688. var settings = lodash.templateSettings;
  29689. if (guard && isIterateeCall(string, options, guard)) {
  29690. options = undefined;
  29691. }
  29692. string = toString(string);
  29693. options = assignInWith({}, options, settings, assignInDefaults);
  29694. var imports = assignInWith({}, options.imports, settings.imports, assignInDefaults),
  29695. importsKeys = keys(imports),
  29696. importsValues = baseValues(imports, importsKeys);
  29697. var isEscaping,
  29698. isEvaluating,
  29699. index = 0,
  29700. interpolate = options.interpolate || reNoMatch,
  29701. source = "__p += '";
  29702. // Compile the regexp to match each delimiter.
  29703. var reDelimiters = RegExp(
  29704. (options.escape || reNoMatch).source + '|' +
  29705. interpolate.source + '|' +
  29706. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  29707. (options.evaluate || reNoMatch).source + '|$'
  29708. , 'g');
  29709. // Use a sourceURL for easier debugging.
  29710. var sourceURL = '//# sourceURL=' +
  29711. ('sourceURL' in options
  29712. ? options.sourceURL
  29713. : ('lodash.templateSources[' + (++templateCounter) + ']')
  29714. ) + '\n';
  29715. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  29716. interpolateValue || (interpolateValue = esTemplateValue);
  29717. // Escape characters that can't be included in string literals.
  29718. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  29719. // Replace delimiters with snippets.
  29720. if (escapeValue) {
  29721. isEscaping = true;
  29722. source += "' +\n__e(" + escapeValue + ") +\n'";
  29723. }
  29724. if (evaluateValue) {
  29725. isEvaluating = true;
  29726. source += "';\n" + evaluateValue + ";\n__p += '";
  29727. }
  29728. if (interpolateValue) {
  29729. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  29730. }
  29731. index = offset + match.length;
  29732. // The JS engine embedded in Adobe products needs `match` returned in
  29733. // order to produce the correct `offset` value.
  29734. return match;
  29735. });
  29736. source += "';\n";
  29737. // If `variable` is not specified wrap a with-statement around the generated
  29738. // code to add the data object to the top of the scope chain.
  29739. var variable = options.variable;
  29740. if (!variable) {
  29741. source = 'with (obj) {\n' + source + '\n}\n';
  29742. }
  29743. // Cleanup code by stripping empty strings.
  29744. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  29745. .replace(reEmptyStringMiddle, '$1')
  29746. .replace(reEmptyStringTrailing, '$1;');
  29747. // Frame code as the function body.
  29748. source = 'function(' + (variable || 'obj') + ') {\n' +
  29749. (variable
  29750. ? ''
  29751. : 'obj || (obj = {});\n'
  29752. ) +
  29753. "var __t, __p = ''" +
  29754. (isEscaping
  29755. ? ', __e = _.escape'
  29756. : ''
  29757. ) +
  29758. (isEvaluating
  29759. ? ', __j = Array.prototype.join;\n' +
  29760. "function print() { __p += __j.call(arguments, '') }\n"
  29761. : ';\n'
  29762. ) +
  29763. source +
  29764. 'return __p\n}';
  29765. var result = attempt(function() {
  29766. return Function(importsKeys, sourceURL + 'return ' + source)
  29767. .apply(undefined, importsValues);
  29768. });
  29769. // Provide the compiled function's source by its `toString` method or
  29770. // the `source` property as a convenience for inlining compiled templates.
  29771. result.source = source;
  29772. if (isError(result)) {
  29773. throw result;
  29774. }
  29775. return result;
  29776. }
  29777. /**
  29778. * Converts `string`, as a whole, to lower case just like
  29779. * [String#toLowerCase](https://mdn.io/toLowerCase).
  29780. *
  29781. * @static
  29782. * @memberOf _
  29783. * @since 4.0.0
  29784. * @category String
  29785. * @param {string} [string=''] The string to convert.
  29786. * @returns {string} Returns the lower cased string.
  29787. * @example
  29788. *
  29789. * _.toLower('--Foo-Bar--');
  29790. * // => '--foo-bar--'
  29791. *
  29792. * _.toLower('fooBar');
  29793. * // => 'foobar'
  29794. *
  29795. * _.toLower('__FOO_BAR__');
  29796. * // => '__foo_bar__'
  29797. */
  29798. function toLower(value) {
  29799. return toString(value).toLowerCase();
  29800. }
  29801. /**
  29802. * Converts `string`, as a whole, to upper case just like
  29803. * [String#toUpperCase](https://mdn.io/toUpperCase).
  29804. *
  29805. * @static
  29806. * @memberOf _
  29807. * @since 4.0.0
  29808. * @category String
  29809. * @param {string} [string=''] The string to convert.
  29810. * @returns {string} Returns the upper cased string.
  29811. * @example
  29812. *
  29813. * _.toUpper('--foo-bar--');
  29814. * // => '--FOO-BAR--'
  29815. *
  29816. * _.toUpper('fooBar');
  29817. * // => 'FOOBAR'
  29818. *
  29819. * _.toUpper('__foo_bar__');
  29820. * // => '__FOO_BAR__'
  29821. */
  29822. function toUpper(value) {
  29823. return toString(value).toUpperCase();
  29824. }
  29825. /**
  29826. * Removes leading and trailing whitespace or specified characters from `string`.
  29827. *
  29828. * @static
  29829. * @memberOf _
  29830. * @since 3.0.0
  29831. * @category String
  29832. * @param {string} [string=''] The string to trim.
  29833. * @param {string} [chars=whitespace] The characters to trim.
  29834. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  29835. * @returns {string} Returns the trimmed string.
  29836. * @example
  29837. *
  29838. * _.trim(' abc ');
  29839. * // => 'abc'
  29840. *
  29841. * _.trim('-_-abc-_-', '_-');
  29842. * // => 'abc'
  29843. *
  29844. * _.map([' foo ', ' bar '], _.trim);
  29845. * // => ['foo', 'bar']
  29846. */
  29847. function trim(string, chars, guard) {
  29848. string = toString(string);
  29849. if (string && (guard || chars === undefined)) {
  29850. return string.replace(reTrim, '');
  29851. }
  29852. if (!string || !(chars = baseToString(chars))) {
  29853. return string;
  29854. }
  29855. var strSymbols = stringToArray(string),
  29856. chrSymbols = stringToArray(chars),
  29857. start = charsStartIndex(strSymbols, chrSymbols),
  29858. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  29859. return castSlice(strSymbols, start, end).join('');
  29860. }
  29861. /**
  29862. * Removes trailing whitespace or specified characters from `string`.
  29863. *
  29864. * @static
  29865. * @memberOf _
  29866. * @since 4.0.0
  29867. * @category String
  29868. * @param {string} [string=''] The string to trim.
  29869. * @param {string} [chars=whitespace] The characters to trim.
  29870. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  29871. * @returns {string} Returns the trimmed string.
  29872. * @example
  29873. *
  29874. * _.trimEnd(' abc ');
  29875. * // => ' abc'
  29876. *
  29877. * _.trimEnd('-_-abc-_-', '_-');
  29878. * // => '-_-abc'
  29879. */
  29880. function trimEnd(string, chars, guard) {
  29881. string = toString(string);
  29882. if (string && (guard || chars === undefined)) {
  29883. return string.replace(reTrimEnd, '');
  29884. }
  29885. if (!string || !(chars = baseToString(chars))) {
  29886. return string;
  29887. }
  29888. var strSymbols = stringToArray(string),
  29889. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  29890. return castSlice(strSymbols, 0, end).join('');
  29891. }
  29892. /**
  29893. * Removes leading whitespace or specified characters from `string`.
  29894. *
  29895. * @static
  29896. * @memberOf _
  29897. * @since 4.0.0
  29898. * @category String
  29899. * @param {string} [string=''] The string to trim.
  29900. * @param {string} [chars=whitespace] The characters to trim.
  29901. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  29902. * @returns {string} Returns the trimmed string.
  29903. * @example
  29904. *
  29905. * _.trimStart(' abc ');
  29906. * // => 'abc '
  29907. *
  29908. * _.trimStart('-_-abc-_-', '_-');
  29909. * // => 'abc-_-'
  29910. */
  29911. function trimStart(string, chars, guard) {
  29912. string = toString(string);
  29913. if (string && (guard || chars === undefined)) {
  29914. return string.replace(reTrimStart, '');
  29915. }
  29916. if (!string || !(chars = baseToString(chars))) {
  29917. return string;
  29918. }
  29919. var strSymbols = stringToArray(string),
  29920. start = charsStartIndex(strSymbols, stringToArray(chars));
  29921. return castSlice(strSymbols, start).join('');
  29922. }
  29923. /**
  29924. * Truncates `string` if it's longer than the given maximum string length.
  29925. * The last characters of the truncated string are replaced with the omission
  29926. * string which defaults to "...".
  29927. *
  29928. * @static
  29929. * @memberOf _
  29930. * @since 4.0.0
  29931. * @category String
  29932. * @param {string} [string=''] The string to truncate.
  29933. * @param {Object} [options={}] The options object.
  29934. * @param {number} [options.length=30] The maximum string length.
  29935. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  29936. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  29937. * @returns {string} Returns the truncated string.
  29938. * @example
  29939. *
  29940. * _.truncate('hi-diddly-ho there, neighborino');
  29941. * // => 'hi-diddly-ho there, neighbo...'
  29942. *
  29943. * _.truncate('hi-diddly-ho there, neighborino', {
  29944. * 'length': 24,
  29945. * 'separator': ' '
  29946. * });
  29947. * // => 'hi-diddly-ho there,...'
  29948. *
  29949. * _.truncate('hi-diddly-ho there, neighborino', {
  29950. * 'length': 24,
  29951. * 'separator': /,? +/
  29952. * });
  29953. * // => 'hi-diddly-ho there...'
  29954. *
  29955. * _.truncate('hi-diddly-ho there, neighborino', {
  29956. * 'omission': ' [...]'
  29957. * });
  29958. * // => 'hi-diddly-ho there, neig [...]'
  29959. */
  29960. function truncate(string, options) {
  29961. var length = DEFAULT_TRUNC_LENGTH,
  29962. omission = DEFAULT_TRUNC_OMISSION;
  29963. if (isObject(options)) {
  29964. var separator = 'separator' in options ? options.separator : separator;
  29965. length = 'length' in options ? toInteger(options.length) : length;
  29966. omission = 'omission' in options ? baseToString(options.omission) : omission;
  29967. }
  29968. string = toString(string);
  29969. var strLength = string.length;
  29970. if (reHasComplexSymbol.test(string)) {
  29971. var strSymbols = stringToArray(string);
  29972. strLength = strSymbols.length;
  29973. }
  29974. if (length >= strLength) {
  29975. return string;
  29976. }
  29977. var end = length - stringSize(omission);
  29978. if (end < 1) {
  29979. return omission;
  29980. }
  29981. var result = strSymbols
  29982. ? castSlice(strSymbols, 0, end).join('')
  29983. : string.slice(0, end);
  29984. if (separator === undefined) {
  29985. return result + omission;
  29986. }
  29987. if (strSymbols) {
  29988. end += (result.length - end);
  29989. }
  29990. if (isRegExp(separator)) {
  29991. if (string.slice(end).search(separator)) {
  29992. var match,
  29993. substring = result;
  29994. if (!separator.global) {
  29995. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  29996. }
  29997. separator.lastIndex = 0;
  29998. while ((match = separator.exec(substring))) {
  29999. var newEnd = match.index;
  30000. }
  30001. result = result.slice(0, newEnd === undefined ? end : newEnd);
  30002. }
  30003. } else if (string.indexOf(baseToString(separator), end) != end) {
  30004. var index = result.lastIndexOf(separator);
  30005. if (index > -1) {
  30006. result = result.slice(0, index);
  30007. }
  30008. }
  30009. return result + omission;
  30010. }
  30011. /**
  30012. * The inverse of `_.escape`; this method converts the HTML entities
  30013. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&#39;`, and `&#96;` in `string` to
  30014. * their corresponding characters.
  30015. *
  30016. * **Note:** No other HTML entities are unescaped. To unescape additional
  30017. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  30018. *
  30019. * @static
  30020. * @memberOf _
  30021. * @since 0.6.0
  30022. * @category String
  30023. * @param {string} [string=''] The string to unescape.
  30024. * @returns {string} Returns the unescaped string.
  30025. * @example
  30026. *
  30027. * _.unescape('fred, barney, &amp; pebbles');
  30028. * // => 'fred, barney, & pebbles'
  30029. */
  30030. function unescape(string) {
  30031. string = toString(string);
  30032. return (string && reHasEscapedHtml.test(string))
  30033. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  30034. : string;
  30035. }
  30036. /**
  30037. * Converts `string`, as space separated words, to upper case.
  30038. *
  30039. * @static
  30040. * @memberOf _
  30041. * @since 4.0.0
  30042. * @category String
  30043. * @param {string} [string=''] The string to convert.
  30044. * @returns {string} Returns the upper cased string.
  30045. * @example
  30046. *
  30047. * _.upperCase('--foo-bar');
  30048. * // => 'FOO BAR'
  30049. *
  30050. * _.upperCase('fooBar');
  30051. * // => 'FOO BAR'
  30052. *
  30053. * _.upperCase('__foo_bar__');
  30054. * // => 'FOO BAR'
  30055. */
  30056. var upperCase = createCompounder(function(result, word, index) {
  30057. return result + (index ? ' ' : '') + word.toUpperCase();
  30058. });
  30059. /**
  30060. * Converts the first character of `string` to upper case.
  30061. *
  30062. * @static
  30063. * @memberOf _
  30064. * @since 4.0.0
  30065. * @category String
  30066. * @param {string} [string=''] The string to convert.
  30067. * @returns {string} Returns the converted string.
  30068. * @example
  30069. *
  30070. * _.upperFirst('fred');
  30071. * // => 'Fred'
  30072. *
  30073. * _.upperFirst('FRED');
  30074. * // => 'FRED'
  30075. */
  30076. var upperFirst = createCaseFirst('toUpperCase');
  30077. /**
  30078. * Splits `string` into an array of its words.
  30079. *
  30080. * @static
  30081. * @memberOf _
  30082. * @since 3.0.0
  30083. * @category String
  30084. * @param {string} [string=''] The string to inspect.
  30085. * @param {RegExp|string} [pattern] The pattern to match words.
  30086. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  30087. * @returns {Array} Returns the words of `string`.
  30088. * @example
  30089. *
  30090. * _.words('fred, barney, & pebbles');
  30091. * // => ['fred', 'barney', 'pebbles']
  30092. *
  30093. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  30094. * // => ['fred', 'barney', '&', 'pebbles']
  30095. */
  30096. function words(string, pattern, guard) {
  30097. string = toString(string);
  30098. pattern = guard ? undefined : pattern;
  30099. if (pattern === undefined) {
  30100. pattern = reHasComplexWord.test(string) ? reComplexWord : reBasicWord;
  30101. }
  30102. return string.match(pattern) || [];
  30103. }
  30104. /*------------------------------------------------------------------------*/
  30105. /**
  30106. * Attempts to invoke `func`, returning either the result or the caught error
  30107. * object. Any additional arguments are provided to `func` when it's invoked.
  30108. *
  30109. * @static
  30110. * @memberOf _
  30111. * @since 3.0.0
  30112. * @category Util
  30113. * @param {Function} func The function to attempt.
  30114. * @param {...*} [args] The arguments to invoke `func` with.
  30115. * @returns {*} Returns the `func` result or error object.
  30116. * @example
  30117. *
  30118. * // Avoid throwing errors for invalid selectors.
  30119. * var elements = _.attempt(function(selector) {
  30120. * return document.querySelectorAll(selector);
  30121. * }, '>_>');
  30122. *
  30123. * if (_.isError(elements)) {
  30124. * elements = [];
  30125. * }
  30126. */
  30127. var attempt = rest(function(func, args) {
  30128. try {
  30129. return apply(func, undefined, args);
  30130. } catch (e) {
  30131. return isError(e) ? e : new Error(e);
  30132. }
  30133. });
  30134. /**
  30135. * Binds methods of an object to the object itself, overwriting the existing
  30136. * method.
  30137. *
  30138. * **Note:** This method doesn't set the "length" property of bound functions.
  30139. *
  30140. * @static
  30141. * @since 0.1.0
  30142. * @memberOf _
  30143. * @category Util
  30144. * @param {Object} object The object to bind and assign the bound methods to.
  30145. * @param {...(string|string[])} methodNames The object method names to bind.
  30146. * @returns {Object} Returns `object`.
  30147. * @example
  30148. *
  30149. * var view = {
  30150. * 'label': 'docs',
  30151. * 'onClick': function() {
  30152. * console.log('clicked ' + this.label);
  30153. * }
  30154. * };
  30155. *
  30156. * _.bindAll(view, ['onClick']);
  30157. * jQuery(element).on('click', view.onClick);
  30158. * // => Logs 'clicked docs' when clicked.
  30159. */
  30160. var bindAll = rest(function(object, methodNames) {
  30161. arrayEach(baseFlatten(methodNames, 1), function(key) {
  30162. key = toKey(key);
  30163. object[key] = bind(object[key], object);
  30164. });
  30165. return object;
  30166. });
  30167. /**
  30168. * Creates a function that iterates over `pairs` and invokes the corresponding
  30169. * function of the first predicate to return truthy. The predicate-function
  30170. * pairs are invoked with the `this` binding and arguments of the created
  30171. * function.
  30172. *
  30173. * @static
  30174. * @memberOf _
  30175. * @since 4.0.0
  30176. * @category Util
  30177. * @param {Array} pairs The predicate-function pairs.
  30178. * @returns {Function} Returns the new composite function.
  30179. * @example
  30180. *
  30181. * var func = _.cond([
  30182. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  30183. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  30184. * [_.constant(true), _.constant('no match')]
  30185. * ]);
  30186. *
  30187. * func({ 'a': 1, 'b': 2 });
  30188. * // => 'matches A'
  30189. *
  30190. * func({ 'a': 0, 'b': 1 });
  30191. * // => 'matches B'
  30192. *
  30193. * func({ 'a': '1', 'b': '2' });
  30194. * // => 'no match'
  30195. */
  30196. function cond(pairs) {
  30197. var length = pairs ? pairs.length : 0,
  30198. toIteratee = getIteratee();
  30199. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  30200. if (typeof pair[1] != 'function') {
  30201. throw new TypeError(FUNC_ERROR_TEXT);
  30202. }
  30203. return [toIteratee(pair[0]), pair[1]];
  30204. });
  30205. return rest(function(args) {
  30206. var index = -1;
  30207. while (++index < length) {
  30208. var pair = pairs[index];
  30209. if (apply(pair[0], this, args)) {
  30210. return apply(pair[1], this, args);
  30211. }
  30212. }
  30213. });
  30214. }
  30215. /**
  30216. * Creates a function that invokes the predicate properties of `source` with
  30217. * the corresponding property values of a given object, returning `true` if
  30218. * all predicates return truthy, else `false`.
  30219. *
  30220. * @static
  30221. * @memberOf _
  30222. * @since 4.0.0
  30223. * @category Util
  30224. * @param {Object} source The object of property predicates to conform to.
  30225. * @returns {Function} Returns the new spec function.
  30226. * @example
  30227. *
  30228. * var users = [
  30229. * { 'user': 'barney', 'age': 36 },
  30230. * { 'user': 'fred', 'age': 40 }
  30231. * ];
  30232. *
  30233. * _.filter(users, _.conforms({ 'age': function(n) { return n > 38; } }));
  30234. * // => [{ 'user': 'fred', 'age': 40 }]
  30235. */
  30236. function conforms(source) {
  30237. return baseConforms(baseClone(source, true));
  30238. }
  30239. /**
  30240. * Creates a function that returns `value`.
  30241. *
  30242. * @static
  30243. * @memberOf _
  30244. * @since 2.4.0
  30245. * @category Util
  30246. * @param {*} value The value to return from the new function.
  30247. * @returns {Function} Returns the new constant function.
  30248. * @example
  30249. *
  30250. * var objects = _.times(2, _.constant({ 'a': 1 }));
  30251. *
  30252. * console.log(objects);
  30253. * // => [{ 'a': 1 }, { 'a': 1 }]
  30254. *
  30255. * console.log(objects[0] === objects[1]);
  30256. * // => true
  30257. */
  30258. function constant(value) {
  30259. return function() {
  30260. return value;
  30261. };
  30262. }
  30263. /**
  30264. * Creates a function that returns the result of invoking the given functions
  30265. * with the `this` binding of the created function, where each successive
  30266. * invocation is supplied the return value of the previous.
  30267. *
  30268. * @static
  30269. * @memberOf _
  30270. * @since 3.0.0
  30271. * @category Util
  30272. * @param {...(Function|Function[])} [funcs] Functions to invoke.
  30273. * @returns {Function} Returns the new composite function.
  30274. * @see _.flowRight
  30275. * @example
  30276. *
  30277. * function square(n) {
  30278. * return n * n;
  30279. * }
  30280. *
  30281. * var addSquare = _.flow([_.add, square]);
  30282. * addSquare(1, 2);
  30283. * // => 9
  30284. */
  30285. var flow = createFlow();
  30286. /**
  30287. * This method is like `_.flow` except that it creates a function that
  30288. * invokes the given functions from right to left.
  30289. *
  30290. * @static
  30291. * @since 3.0.0
  30292. * @memberOf _
  30293. * @category Util
  30294. * @param {...(Function|Function[])} [funcs] Functions to invoke.
  30295. * @returns {Function} Returns the new composite function.
  30296. * @see _.flow
  30297. * @example
  30298. *
  30299. * function square(n) {
  30300. * return n * n;
  30301. * }
  30302. *
  30303. * var addSquare = _.flowRight([square, _.add]);
  30304. * addSquare(1, 2);
  30305. * // => 9
  30306. */
  30307. var flowRight = createFlow(true);
  30308. /**
  30309. * This method returns the first argument given to it.
  30310. *
  30311. * @static
  30312. * @since 0.1.0
  30313. * @memberOf _
  30314. * @category Util
  30315. * @param {*} value Any value.
  30316. * @returns {*} Returns `value`.
  30317. * @example
  30318. *
  30319. * var object = { 'user': 'fred' };
  30320. *
  30321. * console.log(_.identity(object) === object);
  30322. * // => true
  30323. */
  30324. function identity(value) {
  30325. return value;
  30326. }
  30327. /**
  30328. * Creates a function that invokes `func` with the arguments of the created
  30329. * function. If `func` is a property name, the created function returns the
  30330. * property value for a given element. If `func` is an array or object, the
  30331. * created function returns `true` for elements that contain the equivalent
  30332. * source properties, otherwise it returns `false`.
  30333. *
  30334. * @static
  30335. * @since 4.0.0
  30336. * @memberOf _
  30337. * @category Util
  30338. * @param {*} [func=_.identity] The value to convert to a callback.
  30339. * @returns {Function} Returns the callback.
  30340. * @example
  30341. *
  30342. * var users = [
  30343. * { 'user': 'barney', 'age': 36, 'active': true },
  30344. * { 'user': 'fred', 'age': 40, 'active': false }
  30345. * ];
  30346. *
  30347. * // The `_.matches` iteratee shorthand.
  30348. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  30349. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  30350. *
  30351. * // The `_.matchesProperty` iteratee shorthand.
  30352. * _.filter(users, _.iteratee(['user', 'fred']));
  30353. * // => [{ 'user': 'fred', 'age': 40 }]
  30354. *
  30355. * // The `_.property` iteratee shorthand.
  30356. * _.map(users, _.iteratee('user'));
  30357. * // => ['barney', 'fred']
  30358. *
  30359. * // Create custom iteratee shorthands.
  30360. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  30361. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  30362. * return func.test(string);
  30363. * };
  30364. * });
  30365. *
  30366. * _.filter(['abc', 'def'], /ef/);
  30367. * // => ['def']
  30368. */
  30369. function iteratee(func) {
  30370. return baseIteratee(typeof func == 'function' ? func : baseClone(func, true));
  30371. }
  30372. /**
  30373. * Creates a function that performs a partial deep comparison between a given
  30374. * object and `source`, returning `true` if the given object has equivalent
  30375. * property values, else `false`. The created function is equivalent to
  30376. * `_.isMatch` with a `source` partially applied.
  30377. *
  30378. * **Note:** This method supports comparing the same values as `_.isEqual`.
  30379. *
  30380. * @static
  30381. * @memberOf _
  30382. * @since 3.0.0
  30383. * @category Util
  30384. * @param {Object} source The object of property values to match.
  30385. * @returns {Function} Returns the new spec function.
  30386. * @example
  30387. *
  30388. * var users = [
  30389. * { 'user': 'barney', 'age': 36, 'active': true },
  30390. * { 'user': 'fred', 'age': 40, 'active': false }
  30391. * ];
  30392. *
  30393. * _.filter(users, _.matches({ 'age': 40, 'active': false }));
  30394. * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
  30395. */
  30396. function matches(source) {
  30397. return baseMatches(baseClone(source, true));
  30398. }
  30399. /**
  30400. * Creates a function that performs a partial deep comparison between the
  30401. * value at `path` of a given object to `srcValue`, returning `true` if the
  30402. * object value is equivalent, else `false`.
  30403. *
  30404. * **Note:** This method supports comparing the same values as `_.isEqual`.
  30405. *
  30406. * @static
  30407. * @memberOf _
  30408. * @since 3.2.0
  30409. * @category Util
  30410. * @param {Array|string} path The path of the property to get.
  30411. * @param {*} srcValue The value to match.
  30412. * @returns {Function} Returns the new spec function.
  30413. * @example
  30414. *
  30415. * var users = [
  30416. * { 'user': 'barney' },
  30417. * { 'user': 'fred' }
  30418. * ];
  30419. *
  30420. * _.find(users, _.matchesProperty('user', 'fred'));
  30421. * // => { 'user': 'fred' }
  30422. */
  30423. function matchesProperty(path, srcValue) {
  30424. return baseMatchesProperty(path, baseClone(srcValue, true));
  30425. }
  30426. /**
  30427. * Creates a function that invokes the method at `path` of a given object.
  30428. * Any additional arguments are provided to the invoked method.
  30429. *
  30430. * @static
  30431. * @memberOf _
  30432. * @since 3.7.0
  30433. * @category Util
  30434. * @param {Array|string} path The path of the method to invoke.
  30435. * @param {...*} [args] The arguments to invoke the method with.
  30436. * @returns {Function} Returns the new invoker function.
  30437. * @example
  30438. *
  30439. * var objects = [
  30440. * { 'a': { 'b': _.constant(2) } },
  30441. * { 'a': { 'b': _.constant(1) } }
  30442. * ];
  30443. *
  30444. * _.map(objects, _.method('a.b'));
  30445. * // => [2, 1]
  30446. *
  30447. * _.map(objects, _.method(['a', 'b']));
  30448. * // => [2, 1]
  30449. */
  30450. var method = rest(function(path, args) {
  30451. return function(object) {
  30452. return baseInvoke(object, path, args);
  30453. };
  30454. });
  30455. /**
  30456. * The opposite of `_.method`; this method creates a function that invokes
  30457. * the method at a given path of `object`. Any additional arguments are
  30458. * provided to the invoked method.
  30459. *
  30460. * @static
  30461. * @memberOf _
  30462. * @since 3.7.0
  30463. * @category Util
  30464. * @param {Object} object The object to query.
  30465. * @param {...*} [args] The arguments to invoke the method with.
  30466. * @returns {Function} Returns the new invoker function.
  30467. * @example
  30468. *
  30469. * var array = _.times(3, _.constant),
  30470. * object = { 'a': array, 'b': array, 'c': array };
  30471. *
  30472. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  30473. * // => [2, 0]
  30474. *
  30475. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  30476. * // => [2, 0]
  30477. */
  30478. var methodOf = rest(function(object, args) {
  30479. return function(path) {
  30480. return baseInvoke(object, path, args);
  30481. };
  30482. });
  30483. /**
  30484. * Adds all own enumerable string keyed function properties of a source
  30485. * object to the destination object. If `object` is a function, then methods
  30486. * are added to its prototype as well.
  30487. *
  30488. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  30489. * avoid conflicts caused by modifying the original.
  30490. *
  30491. * @static
  30492. * @since 0.1.0
  30493. * @memberOf _
  30494. * @category Util
  30495. * @param {Function|Object} [object=lodash] The destination object.
  30496. * @param {Object} source The object of functions to add.
  30497. * @param {Object} [options={}] The options object.
  30498. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  30499. * @returns {Function|Object} Returns `object`.
  30500. * @example
  30501. *
  30502. * function vowels(string) {
  30503. * return _.filter(string, function(v) {
  30504. * return /[aeiou]/i.test(v);
  30505. * });
  30506. * }
  30507. *
  30508. * _.mixin({ 'vowels': vowels });
  30509. * _.vowels('fred');
  30510. * // => ['e']
  30511. *
  30512. * _('fred').vowels().value();
  30513. * // => ['e']
  30514. *
  30515. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  30516. * _('fred').vowels();
  30517. * // => ['e']
  30518. */
  30519. function mixin(object, source, options) {
  30520. var props = keys(source),
  30521. methodNames = baseFunctions(source, props);
  30522. if (options == null &&
  30523. !(isObject(source) && (methodNames.length || !props.length))) {
  30524. options = source;
  30525. source = object;
  30526. object = this;
  30527. methodNames = baseFunctions(source, keys(source));
  30528. }
  30529. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  30530. isFunc = isFunction(object);
  30531. arrayEach(methodNames, function(methodName) {
  30532. var func = source[methodName];
  30533. object[methodName] = func;
  30534. if (isFunc) {
  30535. object.prototype[methodName] = function() {
  30536. var chainAll = this.__chain__;
  30537. if (chain || chainAll) {
  30538. var result = object(this.__wrapped__),
  30539. actions = result.__actions__ = copyArray(this.__actions__);
  30540. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  30541. result.__chain__ = chainAll;
  30542. return result;
  30543. }
  30544. return func.apply(object, arrayPush([this.value()], arguments));
  30545. };
  30546. }
  30547. });
  30548. return object;
  30549. }
  30550. /**
  30551. * Reverts the `_` variable to its previous value and returns a reference to
  30552. * the `lodash` function.
  30553. *
  30554. * @static
  30555. * @since 0.1.0
  30556. * @memberOf _
  30557. * @category Util
  30558. * @returns {Function} Returns the `lodash` function.
  30559. * @example
  30560. *
  30561. * var lodash = _.noConflict();
  30562. */
  30563. function noConflict() {
  30564. if (root._ === this) {
  30565. root._ = oldDash;
  30566. }
  30567. return this;
  30568. }
  30569. /**
  30570. * A method that returns `undefined`.
  30571. *
  30572. * @static
  30573. * @memberOf _
  30574. * @since 2.3.0
  30575. * @category Util
  30576. * @example
  30577. *
  30578. * _.times(2, _.noop);
  30579. * // => [undefined, undefined]
  30580. */
  30581. function noop() {
  30582. // No operation performed.
  30583. }
  30584. /**
  30585. * Creates a function that gets the argument at index `n`. If `n` is negative,
  30586. * the nth argument from the end is returned.
  30587. *
  30588. * @static
  30589. * @memberOf _
  30590. * @since 4.0.0
  30591. * @category Util
  30592. * @param {number} [n=0] The index of the argument to return.
  30593. * @returns {Function} Returns the new pass-thru function.
  30594. * @example
  30595. *
  30596. * var func = _.nthArg(1);
  30597. * func('a', 'b', 'c', 'd');
  30598. * // => 'b'
  30599. *
  30600. * var func = _.nthArg(-2);
  30601. * func('a', 'b', 'c', 'd');
  30602. * // => 'c'
  30603. */
  30604. function nthArg(n) {
  30605. n = toInteger(n);
  30606. return rest(function(args) {
  30607. return baseNth(args, n);
  30608. });
  30609. }
  30610. /**
  30611. * Creates a function that invokes `iteratees` with the arguments it receives
  30612. * and returns their results.
  30613. *
  30614. * @static
  30615. * @memberOf _
  30616. * @since 4.0.0
  30617. * @category Util
  30618. * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
  30619. * [iteratees=[_.identity]] The iteratees to invoke.
  30620. * @returns {Function} Returns the new function.
  30621. * @example
  30622. *
  30623. * var func = _.over([Math.max, Math.min]);
  30624. *
  30625. * func(1, 2, 3, 4);
  30626. * // => [4, 1]
  30627. */
  30628. var over = createOver(arrayMap);
  30629. /**
  30630. * Creates a function that checks if **all** of the `predicates` return
  30631. * truthy when invoked with the arguments it receives.
  30632. *
  30633. * @static
  30634. * @memberOf _
  30635. * @since 4.0.0
  30636. * @category Util
  30637. * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
  30638. * [predicates=[_.identity]] The predicates to check.
  30639. * @returns {Function} Returns the new function.
  30640. * @example
  30641. *
  30642. * var func = _.overEvery([Boolean, isFinite]);
  30643. *
  30644. * func('1');
  30645. * // => true
  30646. *
  30647. * func(null);
  30648. * // => false
  30649. *
  30650. * func(NaN);
  30651. * // => false
  30652. */
  30653. var overEvery = createOver(arrayEvery);
  30654. /**
  30655. * Creates a function that checks if **any** of the `predicates` return
  30656. * truthy when invoked with the arguments it receives.
  30657. *
  30658. * @static
  30659. * @memberOf _
  30660. * @since 4.0.0
  30661. * @category Util
  30662. * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
  30663. * [predicates=[_.identity]] The predicates to check.
  30664. * @returns {Function} Returns the new function.
  30665. * @example
  30666. *
  30667. * var func = _.overSome([Boolean, isFinite]);
  30668. *
  30669. * func('1');
  30670. * // => true
  30671. *
  30672. * func(null);
  30673. * // => true
  30674. *
  30675. * func(NaN);
  30676. * // => false
  30677. */
  30678. var overSome = createOver(arraySome);
  30679. /**
  30680. * Creates a function that returns the value at `path` of a given object.
  30681. *
  30682. * @static
  30683. * @memberOf _
  30684. * @since 2.4.0
  30685. * @category Util
  30686. * @param {Array|string} path The path of the property to get.
  30687. * @returns {Function} Returns the new accessor function.
  30688. * @example
  30689. *
  30690. * var objects = [
  30691. * { 'a': { 'b': 2 } },
  30692. * { 'a': { 'b': 1 } }
  30693. * ];
  30694. *
  30695. * _.map(objects, _.property('a.b'));
  30696. * // => [2, 1]
  30697. *
  30698. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  30699. * // => [1, 2]
  30700. */
  30701. function property(path) {
  30702. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  30703. }
  30704. /**
  30705. * The opposite of `_.property`; this method creates a function that returns
  30706. * the value at a given path of `object`.
  30707. *
  30708. * @static
  30709. * @memberOf _
  30710. * @since 3.0.0
  30711. * @category Util
  30712. * @param {Object} object The object to query.
  30713. * @returns {Function} Returns the new accessor function.
  30714. * @example
  30715. *
  30716. * var array = [0, 1, 2],
  30717. * object = { 'a': array, 'b': array, 'c': array };
  30718. *
  30719. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  30720. * // => [2, 0]
  30721. *
  30722. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  30723. * // => [2, 0]
  30724. */
  30725. function propertyOf(object) {
  30726. return function(path) {
  30727. return object == null ? undefined : baseGet(object, path);
  30728. };
  30729. }
  30730. /**
  30731. * Creates an array of numbers (positive and/or negative) progressing from
  30732. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  30733. * `start` is specified without an `end` or `step`. If `end` is not specified,
  30734. * it's set to `start` with `start` then set to `0`.
  30735. *
  30736. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  30737. * floating-point values which can produce unexpected results.
  30738. *
  30739. * @static
  30740. * @since 0.1.0
  30741. * @memberOf _
  30742. * @category Util
  30743. * @param {number} [start=0] The start of the range.
  30744. * @param {number} end The end of the range.
  30745. * @param {number} [step=1] The value to increment or decrement by.
  30746. * @returns {Array} Returns the range of numbers.
  30747. * @see _.inRange, _.rangeRight
  30748. * @example
  30749. *
  30750. * _.range(4);
  30751. * // => [0, 1, 2, 3]
  30752. *
  30753. * _.range(-4);
  30754. * // => [0, -1, -2, -3]
  30755. *
  30756. * _.range(1, 5);
  30757. * // => [1, 2, 3, 4]
  30758. *
  30759. * _.range(0, 20, 5);
  30760. * // => [0, 5, 10, 15]
  30761. *
  30762. * _.range(0, -4, -1);
  30763. * // => [0, -1, -2, -3]
  30764. *
  30765. * _.range(1, 4, 0);
  30766. * // => [1, 1, 1]
  30767. *
  30768. * _.range(0);
  30769. * // => []
  30770. */
  30771. var range = createRange();
  30772. /**
  30773. * This method is like `_.range` except that it populates values in
  30774. * descending order.
  30775. *
  30776. * @static
  30777. * @memberOf _
  30778. * @since 4.0.0
  30779. * @category Util
  30780. * @param {number} [start=0] The start of the range.
  30781. * @param {number} end The end of the range.
  30782. * @param {number} [step=1] The value to increment or decrement by.
  30783. * @returns {Array} Returns the range of numbers.
  30784. * @see _.inRange, _.range
  30785. * @example
  30786. *
  30787. * _.rangeRight(4);
  30788. * // => [3, 2, 1, 0]
  30789. *
  30790. * _.rangeRight(-4);
  30791. * // => [-3, -2, -1, 0]
  30792. *
  30793. * _.rangeRight(1, 5);
  30794. * // => [4, 3, 2, 1]
  30795. *
  30796. * _.rangeRight(0, 20, 5);
  30797. * // => [15, 10, 5, 0]
  30798. *
  30799. * _.rangeRight(0, -4, -1);
  30800. * // => [-3, -2, -1, 0]
  30801. *
  30802. * _.rangeRight(1, 4, 0);
  30803. * // => [1, 1, 1]
  30804. *
  30805. * _.rangeRight(0);
  30806. * // => []
  30807. */
  30808. var rangeRight = createRange(true);
  30809. /**
  30810. * A method that returns a new empty array.
  30811. *
  30812. * @static
  30813. * @memberOf _
  30814. * @since 4.13.0
  30815. * @category Util
  30816. * @returns {Array} Returns the new empty array.
  30817. * @example
  30818. *
  30819. * var arrays = _.times(2, _.stubArray);
  30820. *
  30821. * console.log(arrays);
  30822. * // => [[], []]
  30823. *
  30824. * console.log(arrays[0] === arrays[1]);
  30825. * // => false
  30826. */
  30827. function stubArray() {
  30828. return [];
  30829. }
  30830. /**
  30831. * A method that returns `false`.
  30832. *
  30833. * @static
  30834. * @memberOf _
  30835. * @since 4.13.0
  30836. * @category Util
  30837. * @returns {boolean} Returns `false`.
  30838. * @example
  30839. *
  30840. * _.times(2, _.stubFalse);
  30841. * // => [false, false]
  30842. */
  30843. function stubFalse() {
  30844. return false;
  30845. }
  30846. /**
  30847. * A method that returns a new empty object.
  30848. *
  30849. * @static
  30850. * @memberOf _
  30851. * @since 4.13.0
  30852. * @category Util
  30853. * @returns {Object} Returns the new empty object.
  30854. * @example
  30855. *
  30856. * var objects = _.times(2, _.stubObject);
  30857. *
  30858. * console.log(objects);
  30859. * // => [{}, {}]
  30860. *
  30861. * console.log(objects[0] === objects[1]);
  30862. * // => false
  30863. */
  30864. function stubObject() {
  30865. return {};
  30866. }
  30867. /**
  30868. * A method that returns an empty string.
  30869. *
  30870. * @static
  30871. * @memberOf _
  30872. * @since 4.13.0
  30873. * @category Util
  30874. * @returns {string} Returns the empty string.
  30875. * @example
  30876. *
  30877. * _.times(2, _.stubString);
  30878. * // => ['', '']
  30879. */
  30880. function stubString() {
  30881. return '';
  30882. }
  30883. /**
  30884. * A method that returns `true`.
  30885. *
  30886. * @static
  30887. * @memberOf _
  30888. * @since 4.13.0
  30889. * @category Util
  30890. * @returns {boolean} Returns `true`.
  30891. * @example
  30892. *
  30893. * _.times(2, _.stubTrue);
  30894. * // => [true, true]
  30895. */
  30896. function stubTrue() {
  30897. return true;
  30898. }
  30899. /**
  30900. * Invokes the iteratee `n` times, returning an array of the results of
  30901. * each invocation. The iteratee is invoked with one argument; (index).
  30902. *
  30903. * @static
  30904. * @since 0.1.0
  30905. * @memberOf _
  30906. * @category Util
  30907. * @param {number} n The number of times to invoke `iteratee`.
  30908. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  30909. * @returns {Array} Returns the array of results.
  30910. * @example
  30911. *
  30912. * _.times(3, String);
  30913. * // => ['0', '1', '2']
  30914. *
  30915. * _.times(4, _.constant(0));
  30916. * // => [0, 0, 0, 0]
  30917. */
  30918. function times(n, iteratee) {
  30919. n = toInteger(n);
  30920. if (n < 1 || n > MAX_SAFE_INTEGER) {
  30921. return [];
  30922. }
  30923. var index = MAX_ARRAY_LENGTH,
  30924. length = nativeMin(n, MAX_ARRAY_LENGTH);
  30925. iteratee = getIteratee(iteratee);
  30926. n -= MAX_ARRAY_LENGTH;
  30927. var result = baseTimes(length, iteratee);
  30928. while (++index < n) {
  30929. iteratee(index);
  30930. }
  30931. return result;
  30932. }
  30933. /**
  30934. * Converts `value` to a property path array.
  30935. *
  30936. * @static
  30937. * @memberOf _
  30938. * @since 4.0.0
  30939. * @category Util
  30940. * @param {*} value The value to convert.
  30941. * @returns {Array} Returns the new property path array.
  30942. * @example
  30943. *
  30944. * _.toPath('a.b.c');
  30945. * // => ['a', 'b', 'c']
  30946. *
  30947. * _.toPath('a[0].b.c');
  30948. * // => ['a', '0', 'b', 'c']
  30949. */
  30950. function toPath(value) {
  30951. if (isArray(value)) {
  30952. return arrayMap(value, toKey);
  30953. }
  30954. return isSymbol(value) ? [value] : copyArray(stringToPath(value));
  30955. }
  30956. /**
  30957. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  30958. *
  30959. * @static
  30960. * @since 0.1.0
  30961. * @memberOf _
  30962. * @category Util
  30963. * @param {string} [prefix=''] The value to prefix the ID with.
  30964. * @returns {string} Returns the unique ID.
  30965. * @example
  30966. *
  30967. * _.uniqueId('contact_');
  30968. * // => 'contact_104'
  30969. *
  30970. * _.uniqueId();
  30971. * // => '105'
  30972. */
  30973. function uniqueId(prefix) {
  30974. var id = ++idCounter;
  30975. return toString(prefix) + id;
  30976. }
  30977. /*------------------------------------------------------------------------*/
  30978. /**
  30979. * Adds two numbers.
  30980. *
  30981. * @static
  30982. * @memberOf _
  30983. * @since 3.4.0
  30984. * @category Math
  30985. * @param {number} augend The first number in an addition.
  30986. * @param {number} addend The second number in an addition.
  30987. * @returns {number} Returns the total.
  30988. * @example
  30989. *
  30990. * _.add(6, 4);
  30991. * // => 10
  30992. */
  30993. var add = createMathOperation(function(augend, addend) {
  30994. return augend + addend;
  30995. });
  30996. /**
  30997. * Computes `number` rounded up to `precision`.
  30998. *
  30999. * @static
  31000. * @memberOf _
  31001. * @since 3.10.0
  31002. * @category Math
  31003. * @param {number} number The number to round up.
  31004. * @param {number} [precision=0] The precision to round up to.
  31005. * @returns {number} Returns the rounded up number.
  31006. * @example
  31007. *
  31008. * _.ceil(4.006);
  31009. * // => 5
  31010. *
  31011. * _.ceil(6.004, 2);
  31012. * // => 6.01
  31013. *
  31014. * _.ceil(6040, -2);
  31015. * // => 6100
  31016. */
  31017. var ceil = createRound('ceil');
  31018. /**
  31019. * Divide two numbers.
  31020. *
  31021. * @static
  31022. * @memberOf _
  31023. * @since 4.7.0
  31024. * @category Math
  31025. * @param {number} dividend The first number in a division.
  31026. * @param {number} divisor The second number in a division.
  31027. * @returns {number} Returns the quotient.
  31028. * @example
  31029. *
  31030. * _.divide(6, 4);
  31031. * // => 1.5
  31032. */
  31033. var divide = createMathOperation(function(dividend, divisor) {
  31034. return dividend / divisor;
  31035. });
  31036. /**
  31037. * Computes `number` rounded down to `precision`.
  31038. *
  31039. * @static
  31040. * @memberOf _
  31041. * @since 3.10.0
  31042. * @category Math
  31043. * @param {number} number The number to round down.
  31044. * @param {number} [precision=0] The precision to round down to.
  31045. * @returns {number} Returns the rounded down number.
  31046. * @example
  31047. *
  31048. * _.floor(4.006);
  31049. * // => 4
  31050. *
  31051. * _.floor(0.046, 2);
  31052. * // => 0.04
  31053. *
  31054. * _.floor(4060, -2);
  31055. * // => 4000
  31056. */
  31057. var floor = createRound('floor');
  31058. /**
  31059. * Computes the maximum value of `array`. If `array` is empty or falsey,
  31060. * `undefined` is returned.
  31061. *
  31062. * @static
  31063. * @since 0.1.0
  31064. * @memberOf _
  31065. * @category Math
  31066. * @param {Array} array The array to iterate over.
  31067. * @returns {*} Returns the maximum value.
  31068. * @example
  31069. *
  31070. * _.max([4, 2, 8, 6]);
  31071. * // => 8
  31072. *
  31073. * _.max([]);
  31074. * // => undefined
  31075. */
  31076. function max(array) {
  31077. return (array && array.length)
  31078. ? baseExtremum(array, identity, baseGt)
  31079. : undefined;
  31080. }
  31081. /**
  31082. * This method is like `_.max` except that it accepts `iteratee` which is
  31083. * invoked for each element in `array` to generate the criterion by which
  31084. * the value is ranked. The iteratee is invoked with one argument: (value).
  31085. *
  31086. * @static
  31087. * @memberOf _
  31088. * @since 4.0.0
  31089. * @category Math
  31090. * @param {Array} array The array to iterate over.
  31091. * @param {Array|Function|Object|string} [iteratee=_.identity]
  31092. * The iteratee invoked per element.
  31093. * @returns {*} Returns the maximum value.
  31094. * @example
  31095. *
  31096. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  31097. *
  31098. * _.maxBy(objects, function(o) { return o.n; });
  31099. * // => { 'n': 2 }
  31100. *
  31101. * // The `_.property` iteratee shorthand.
  31102. * _.maxBy(objects, 'n');
  31103. * // => { 'n': 2 }
  31104. */
  31105. function maxBy(array, iteratee) {
  31106. return (array && array.length)
  31107. ? baseExtremum(array, getIteratee(iteratee), baseGt)
  31108. : undefined;
  31109. }
  31110. /**
  31111. * Computes the mean of the values in `array`.
  31112. *
  31113. * @static
  31114. * @memberOf _
  31115. * @since 4.0.0
  31116. * @category Math
  31117. * @param {Array} array The array to iterate over.
  31118. * @returns {number} Returns the mean.
  31119. * @example
  31120. *
  31121. * _.mean([4, 2, 8, 6]);
  31122. * // => 5
  31123. */
  31124. function mean(array) {
  31125. return baseMean(array, identity);
  31126. }
  31127. /**
  31128. * This method is like `_.mean` except that it accepts `iteratee` which is
  31129. * invoked for each element in `array` to generate the value to be averaged.
  31130. * The iteratee is invoked with one argument: (value).
  31131. *
  31132. * @static
  31133. * @memberOf _
  31134. * @since 4.7.0
  31135. * @category Math
  31136. * @param {Array} array The array to iterate over.
  31137. * @param {Array|Function|Object|string} [iteratee=_.identity]
  31138. * The iteratee invoked per element.
  31139. * @returns {number} Returns the mean.
  31140. * @example
  31141. *
  31142. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  31143. *
  31144. * _.meanBy(objects, function(o) { return o.n; });
  31145. * // => 5
  31146. *
  31147. * // The `_.property` iteratee shorthand.
  31148. * _.meanBy(objects, 'n');
  31149. * // => 5
  31150. */
  31151. function meanBy(array, iteratee) {
  31152. return baseMean(array, getIteratee(iteratee));
  31153. }
  31154. /**
  31155. * Computes the minimum value of `array`. If `array` is empty or falsey,
  31156. * `undefined` is returned.
  31157. *
  31158. * @static
  31159. * @since 0.1.0
  31160. * @memberOf _
  31161. * @category Math
  31162. * @param {Array} array The array to iterate over.
  31163. * @returns {*} Returns the minimum value.
  31164. * @example
  31165. *
  31166. * _.min([4, 2, 8, 6]);
  31167. * // => 2
  31168. *
  31169. * _.min([]);
  31170. * // => undefined
  31171. */
  31172. function min(array) {
  31173. return (array && array.length)
  31174. ? baseExtremum(array, identity, baseLt)
  31175. : undefined;
  31176. }
  31177. /**
  31178. * This method is like `_.min` except that it accepts `iteratee` which is
  31179. * invoked for each element in `array` to generate the criterion by which
  31180. * the value is ranked. The iteratee is invoked with one argument: (value).
  31181. *
  31182. * @static
  31183. * @memberOf _
  31184. * @since 4.0.0
  31185. * @category Math
  31186. * @param {Array} array The array to iterate over.
  31187. * @param {Array|Function|Object|string} [iteratee=_.identity]
  31188. * The iteratee invoked per element.
  31189. * @returns {*} Returns the minimum value.
  31190. * @example
  31191. *
  31192. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  31193. *
  31194. * _.minBy(objects, function(o) { return o.n; });
  31195. * // => { 'n': 1 }
  31196. *
  31197. * // The `_.property` iteratee shorthand.
  31198. * _.minBy(objects, 'n');
  31199. * // => { 'n': 1 }
  31200. */
  31201. function minBy(array, iteratee) {
  31202. return (array && array.length)
  31203. ? baseExtremum(array, getIteratee(iteratee), baseLt)
  31204. : undefined;
  31205. }
  31206. /**
  31207. * Multiply two numbers.
  31208. *
  31209. * @static
  31210. * @memberOf _
  31211. * @since 4.7.0
  31212. * @category Math
  31213. * @param {number} multiplier The first number in a multiplication.
  31214. * @param {number} multiplicand The second number in a multiplication.
  31215. * @returns {number} Returns the product.
  31216. * @example
  31217. *
  31218. * _.multiply(6, 4);
  31219. * // => 24
  31220. */
  31221. var multiply = createMathOperation(function(multiplier, multiplicand) {
  31222. return multiplier * multiplicand;
  31223. });
  31224. /**
  31225. * Computes `number` rounded to `precision`.
  31226. *
  31227. * @static
  31228. * @memberOf _
  31229. * @since 3.10.0
  31230. * @category Math
  31231. * @param {number} number The number to round.
  31232. * @param {number} [precision=0] The precision to round to.
  31233. * @returns {number} Returns the rounded number.
  31234. * @example
  31235. *
  31236. * _.round(4.006);
  31237. * // => 4
  31238. *
  31239. * _.round(4.006, 2);
  31240. * // => 4.01
  31241. *
  31242. * _.round(4060, -2);
  31243. * // => 4100
  31244. */
  31245. var round = createRound('round');
  31246. /**
  31247. * Subtract two numbers.
  31248. *
  31249. * @static
  31250. * @memberOf _
  31251. * @since 4.0.0
  31252. * @category Math
  31253. * @param {number} minuend The first number in a subtraction.
  31254. * @param {number} subtrahend The second number in a subtraction.
  31255. * @returns {number} Returns the difference.
  31256. * @example
  31257. *
  31258. * _.subtract(6, 4);
  31259. * // => 2
  31260. */
  31261. var subtract = createMathOperation(function(minuend, subtrahend) {
  31262. return minuend - subtrahend;
  31263. });
  31264. /**
  31265. * Computes the sum of the values in `array`.
  31266. *
  31267. * @static
  31268. * @memberOf _
  31269. * @since 3.4.0
  31270. * @category Math
  31271. * @param {Array} array The array to iterate over.
  31272. * @returns {number} Returns the sum.
  31273. * @example
  31274. *
  31275. * _.sum([4, 2, 8, 6]);
  31276. * // => 20
  31277. */
  31278. function sum(array) {
  31279. return (array && array.length)
  31280. ? baseSum(array, identity)
  31281. : 0;
  31282. }
  31283. /**
  31284. * This method is like `_.sum` except that it accepts `iteratee` which is
  31285. * invoked for each element in `array` to generate the value to be summed.
  31286. * The iteratee is invoked with one argument: (value).
  31287. *
  31288. * @static
  31289. * @memberOf _
  31290. * @since 4.0.0
  31291. * @category Math
  31292. * @param {Array} array The array to iterate over.
  31293. * @param {Array|Function|Object|string} [iteratee=_.identity]
  31294. * The iteratee invoked per element.
  31295. * @returns {number} Returns the sum.
  31296. * @example
  31297. *
  31298. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  31299. *
  31300. * _.sumBy(objects, function(o) { return o.n; });
  31301. * // => 20
  31302. *
  31303. * // The `_.property` iteratee shorthand.
  31304. * _.sumBy(objects, 'n');
  31305. * // => 20
  31306. */
  31307. function sumBy(array, iteratee) {
  31308. return (array && array.length)
  31309. ? baseSum(array, getIteratee(iteratee))
  31310. : 0;
  31311. }
  31312. /*------------------------------------------------------------------------*/
  31313. // Add methods that return wrapped values in chain sequences.
  31314. lodash.after = after;
  31315. lodash.ary = ary;
  31316. lodash.assign = assign;
  31317. lodash.assignIn = assignIn;
  31318. lodash.assignInWith = assignInWith;
  31319. lodash.assignWith = assignWith;
  31320. lodash.at = at;
  31321. lodash.before = before;
  31322. lodash.bind = bind;
  31323. lodash.bindAll = bindAll;
  31324. lodash.bindKey = bindKey;
  31325. lodash.castArray = castArray;
  31326. lodash.chain = chain;
  31327. lodash.chunk = chunk;
  31328. lodash.compact = compact;
  31329. lodash.concat = concat;
  31330. lodash.cond = cond;
  31331. lodash.conforms = conforms;
  31332. lodash.constant = constant;
  31333. lodash.countBy = countBy;
  31334. lodash.create = create;
  31335. lodash.curry = curry;
  31336. lodash.curryRight = curryRight;
  31337. lodash.debounce = debounce;
  31338. lodash.defaults = defaults;
  31339. lodash.defaultsDeep = defaultsDeep;
  31340. lodash.defer = defer;
  31341. lodash.delay = delay;
  31342. lodash.difference = difference;
  31343. lodash.differenceBy = differenceBy;
  31344. lodash.differenceWith = differenceWith;
  31345. lodash.drop = drop;
  31346. lodash.dropRight = dropRight;
  31347. lodash.dropRightWhile = dropRightWhile;
  31348. lodash.dropWhile = dropWhile;
  31349. lodash.fill = fill;
  31350. lodash.filter = filter;
  31351. lodash.flatMap = flatMap;
  31352. lodash.flatMapDeep = flatMapDeep;
  31353. lodash.flatMapDepth = flatMapDepth;
  31354. lodash.flatten = flatten;
  31355. lodash.flattenDeep = flattenDeep;
  31356. lodash.flattenDepth = flattenDepth;
  31357. lodash.flip = flip;
  31358. lodash.flow = flow;
  31359. lodash.flowRight = flowRight;
  31360. lodash.fromPairs = fromPairs;
  31361. lodash.functions = functions;
  31362. lodash.functionsIn = functionsIn;
  31363. lodash.groupBy = groupBy;
  31364. lodash.initial = initial;
  31365. lodash.intersection = intersection;
  31366. lodash.intersectionBy = intersectionBy;
  31367. lodash.intersectionWith = intersectionWith;
  31368. lodash.invert = invert;
  31369. lodash.invertBy = invertBy;
  31370. lodash.invokeMap = invokeMap;
  31371. lodash.iteratee = iteratee;
  31372. lodash.keyBy = keyBy;
  31373. lodash.keys = keys;
  31374. lodash.keysIn = keysIn;
  31375. lodash.map = map;
  31376. lodash.mapKeys = mapKeys;
  31377. lodash.mapValues = mapValues;
  31378. lodash.matches = matches;
  31379. lodash.matchesProperty = matchesProperty;
  31380. lodash.memoize = memoize;
  31381. lodash.merge = merge;
  31382. lodash.mergeWith = mergeWith;
  31383. lodash.method = method;
  31384. lodash.methodOf = methodOf;
  31385. lodash.mixin = mixin;
  31386. lodash.negate = negate;
  31387. lodash.nthArg = nthArg;
  31388. lodash.omit = omit;
  31389. lodash.omitBy = omitBy;
  31390. lodash.once = once;
  31391. lodash.orderBy = orderBy;
  31392. lodash.over = over;
  31393. lodash.overArgs = overArgs;
  31394. lodash.overEvery = overEvery;
  31395. lodash.overSome = overSome;
  31396. lodash.partial = partial;
  31397. lodash.partialRight = partialRight;
  31398. lodash.partition = partition;
  31399. lodash.pick = pick;
  31400. lodash.pickBy = pickBy;
  31401. lodash.property = property;
  31402. lodash.propertyOf = propertyOf;
  31403. lodash.pull = pull;
  31404. lodash.pullAll = pullAll;
  31405. lodash.pullAllBy = pullAllBy;
  31406. lodash.pullAllWith = pullAllWith;
  31407. lodash.pullAt = pullAt;
  31408. lodash.range = range;
  31409. lodash.rangeRight = rangeRight;
  31410. lodash.rearg = rearg;
  31411. lodash.reject = reject;
  31412. lodash.remove = remove;
  31413. lodash.rest = rest;
  31414. lodash.reverse = reverse;
  31415. lodash.sampleSize = sampleSize;
  31416. lodash.set = set;
  31417. lodash.setWith = setWith;
  31418. lodash.shuffle = shuffle;
  31419. lodash.slice = slice;
  31420. lodash.sortBy = sortBy;
  31421. lodash.sortedUniq = sortedUniq;
  31422. lodash.sortedUniqBy = sortedUniqBy;
  31423. lodash.split = split;
  31424. lodash.spread = spread;
  31425. lodash.tail = tail;
  31426. lodash.take = take;
  31427. lodash.takeRight = takeRight;
  31428. lodash.takeRightWhile = takeRightWhile;
  31429. lodash.takeWhile = takeWhile;
  31430. lodash.tap = tap;
  31431. lodash.throttle = throttle;
  31432. lodash.thru = thru;
  31433. lodash.toArray = toArray;
  31434. lodash.toPairs = toPairs;
  31435. lodash.toPairsIn = toPairsIn;
  31436. lodash.toPath = toPath;
  31437. lodash.toPlainObject = toPlainObject;
  31438. lodash.transform = transform;
  31439. lodash.unary = unary;
  31440. lodash.union = union;
  31441. lodash.unionBy = unionBy;
  31442. lodash.unionWith = unionWith;
  31443. lodash.uniq = uniq;
  31444. lodash.uniqBy = uniqBy;
  31445. lodash.uniqWith = uniqWith;
  31446. lodash.unset = unset;
  31447. lodash.unzip = unzip;
  31448. lodash.unzipWith = unzipWith;
  31449. lodash.update = update;
  31450. lodash.updateWith = updateWith;
  31451. lodash.values = values;
  31452. lodash.valuesIn = valuesIn;
  31453. lodash.without = without;
  31454. lodash.words = words;
  31455. lodash.wrap = wrap;
  31456. lodash.xor = xor;
  31457. lodash.xorBy = xorBy;
  31458. lodash.xorWith = xorWith;
  31459. lodash.zip = zip;
  31460. lodash.zipObject = zipObject;
  31461. lodash.zipObjectDeep = zipObjectDeep;
  31462. lodash.zipWith = zipWith;
  31463. // Add aliases.
  31464. lodash.entries = toPairs;
  31465. lodash.entriesIn = toPairsIn;
  31466. lodash.extend = assignIn;
  31467. lodash.extendWith = assignInWith;
  31468. // Add methods to `lodash.prototype`.
  31469. mixin(lodash, lodash);
  31470. /*------------------------------------------------------------------------*/
  31471. // Add methods that return unwrapped values in chain sequences.
  31472. lodash.add = add;
  31473. lodash.attempt = attempt;
  31474. lodash.camelCase = camelCase;
  31475. lodash.capitalize = capitalize;
  31476. lodash.ceil = ceil;
  31477. lodash.clamp = clamp;
  31478. lodash.clone = clone;
  31479. lodash.cloneDeep = cloneDeep;
  31480. lodash.cloneDeepWith = cloneDeepWith;
  31481. lodash.cloneWith = cloneWith;
  31482. lodash.deburr = deburr;
  31483. lodash.divide = divide;
  31484. lodash.endsWith = endsWith;
  31485. lodash.eq = eq;
  31486. lodash.escape = escape;
  31487. lodash.escapeRegExp = escapeRegExp;
  31488. lodash.every = every;
  31489. lodash.find = find;
  31490. lodash.findIndex = findIndex;
  31491. lodash.findKey = findKey;
  31492. lodash.findLast = findLast;
  31493. lodash.findLastIndex = findLastIndex;
  31494. lodash.findLastKey = findLastKey;
  31495. lodash.floor = floor;
  31496. lodash.forEach = forEach;
  31497. lodash.forEachRight = forEachRight;
  31498. lodash.forIn = forIn;
  31499. lodash.forInRight = forInRight;
  31500. lodash.forOwn = forOwn;
  31501. lodash.forOwnRight = forOwnRight;
  31502. lodash.get = get;
  31503. lodash.gt = gt;
  31504. lodash.gte = gte;
  31505. lodash.has = has;
  31506. lodash.hasIn = hasIn;
  31507. lodash.head = head;
  31508. lodash.identity = identity;
  31509. lodash.includes = includes;
  31510. lodash.indexOf = indexOf;
  31511. lodash.inRange = inRange;
  31512. lodash.invoke = invoke;
  31513. lodash.isArguments = isArguments;
  31514. lodash.isArray = isArray;
  31515. lodash.isArrayBuffer = isArrayBuffer;
  31516. lodash.isArrayLike = isArrayLike;
  31517. lodash.isArrayLikeObject = isArrayLikeObject;
  31518. lodash.isBoolean = isBoolean;
  31519. lodash.isBuffer = isBuffer;
  31520. lodash.isDate = isDate;
  31521. lodash.isElement = isElement;
  31522. lodash.isEmpty = isEmpty;
  31523. lodash.isEqual = isEqual;
  31524. lodash.isEqualWith = isEqualWith;
  31525. lodash.isError = isError;
  31526. lodash.isFinite = isFinite;
  31527. lodash.isFunction = isFunction;
  31528. lodash.isInteger = isInteger;
  31529. lodash.isLength = isLength;
  31530. lodash.isMap = isMap;
  31531. lodash.isMatch = isMatch;
  31532. lodash.isMatchWith = isMatchWith;
  31533. lodash.isNaN = isNaN;
  31534. lodash.isNative = isNative;
  31535. lodash.isNil = isNil;
  31536. lodash.isNull = isNull;
  31537. lodash.isNumber = isNumber;
  31538. lodash.isObject = isObject;
  31539. lodash.isObjectLike = isObjectLike;
  31540. lodash.isPlainObject = isPlainObject;
  31541. lodash.isRegExp = isRegExp;
  31542. lodash.isSafeInteger = isSafeInteger;
  31543. lodash.isSet = isSet;
  31544. lodash.isString = isString;
  31545. lodash.isSymbol = isSymbol;
  31546. lodash.isTypedArray = isTypedArray;
  31547. lodash.isUndefined = isUndefined;
  31548. lodash.isWeakMap = isWeakMap;
  31549. lodash.isWeakSet = isWeakSet;
  31550. lodash.join = join;
  31551. lodash.kebabCase = kebabCase;
  31552. lodash.last = last;
  31553. lodash.lastIndexOf = lastIndexOf;
  31554. lodash.lowerCase = lowerCase;
  31555. lodash.lowerFirst = lowerFirst;
  31556. lodash.lt = lt;
  31557. lodash.lte = lte;
  31558. lodash.max = max;
  31559. lodash.maxBy = maxBy;
  31560. lodash.mean = mean;
  31561. lodash.meanBy = meanBy;
  31562. lodash.min = min;
  31563. lodash.minBy = minBy;
  31564. lodash.stubArray = stubArray;
  31565. lodash.stubFalse = stubFalse;
  31566. lodash.stubObject = stubObject;
  31567. lodash.stubString = stubString;
  31568. lodash.stubTrue = stubTrue;
  31569. lodash.multiply = multiply;
  31570. lodash.nth = nth;
  31571. lodash.noConflict = noConflict;
  31572. lodash.noop = noop;
  31573. lodash.now = now;
  31574. lodash.pad = pad;
  31575. lodash.padEnd = padEnd;
  31576. lodash.padStart = padStart;
  31577. lodash.parseInt = parseInt;
  31578. lodash.random = random;
  31579. lodash.reduce = reduce;
  31580. lodash.reduceRight = reduceRight;
  31581. lodash.repeat = repeat;
  31582. lodash.replace = replace;
  31583. lodash.result = result;
  31584. lodash.round = round;
  31585. lodash.runInContext = runInContext;
  31586. lodash.sample = sample;
  31587. lodash.size = size;
  31588. lodash.snakeCase = snakeCase;
  31589. lodash.some = some;
  31590. lodash.sortedIndex = sortedIndex;
  31591. lodash.sortedIndexBy = sortedIndexBy;
  31592. lodash.sortedIndexOf = sortedIndexOf;
  31593. lodash.sortedLastIndex = sortedLastIndex;
  31594. lodash.sortedLastIndexBy = sortedLastIndexBy;
  31595. lodash.sortedLastIndexOf = sortedLastIndexOf;
  31596. lodash.startCase = startCase;
  31597. lodash.startsWith = startsWith;
  31598. lodash.subtract = subtract;
  31599. lodash.sum = sum;
  31600. lodash.sumBy = sumBy;
  31601. lodash.template = template;
  31602. lodash.times = times;
  31603. lodash.toFinite = toFinite;
  31604. lodash.toInteger = toInteger;
  31605. lodash.toLength = toLength;
  31606. lodash.toLower = toLower;
  31607. lodash.toNumber = toNumber;
  31608. lodash.toSafeInteger = toSafeInteger;
  31609. lodash.toString = toString;
  31610. lodash.toUpper = toUpper;
  31611. lodash.trim = trim;
  31612. lodash.trimEnd = trimEnd;
  31613. lodash.trimStart = trimStart;
  31614. lodash.truncate = truncate;
  31615. lodash.unescape = unescape;
  31616. lodash.uniqueId = uniqueId;
  31617. lodash.upperCase = upperCase;
  31618. lodash.upperFirst = upperFirst;
  31619. // Add aliases.
  31620. lodash.each = forEach;
  31621. lodash.eachRight = forEachRight;
  31622. lodash.first = head;
  31623. mixin(lodash, (function() {
  31624. var source = {};
  31625. baseForOwn(lodash, function(func, methodName) {
  31626. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  31627. source[methodName] = func;
  31628. }
  31629. });
  31630. return source;
  31631. }()), { 'chain': false });
  31632. /*------------------------------------------------------------------------*/
  31633. /**
  31634. * The semantic version number.
  31635. *
  31636. * @static
  31637. * @memberOf _
  31638. * @type {string}
  31639. */
  31640. lodash.VERSION = VERSION;
  31641. // Assign default placeholders.
  31642. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  31643. lodash[methodName].placeholder = lodash;
  31644. });
  31645. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  31646. arrayEach(['drop', 'take'], function(methodName, index) {
  31647. LazyWrapper.prototype[methodName] = function(n) {
  31648. var filtered = this.__filtered__;
  31649. if (filtered && !index) {
  31650. return new LazyWrapper(this);
  31651. }
  31652. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  31653. var result = this.clone();
  31654. if (filtered) {
  31655. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  31656. } else {
  31657. result.__views__.push({
  31658. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  31659. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  31660. });
  31661. }
  31662. return result;
  31663. };
  31664. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  31665. return this.reverse()[methodName](n).reverse();
  31666. };
  31667. });
  31668. // Add `LazyWrapper` methods that accept an `iteratee` value.
  31669. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  31670. var type = index + 1,
  31671. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  31672. LazyWrapper.prototype[methodName] = function(iteratee) {
  31673. var result = this.clone();
  31674. result.__iteratees__.push({
  31675. 'iteratee': getIteratee(iteratee, 3),
  31676. 'type': type
  31677. });
  31678. result.__filtered__ = result.__filtered__ || isFilter;
  31679. return result;
  31680. };
  31681. });
  31682. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  31683. arrayEach(['head', 'last'], function(methodName, index) {
  31684. var takeName = 'take' + (index ? 'Right' : '');
  31685. LazyWrapper.prototype[methodName] = function() {
  31686. return this[takeName](1).value()[0];
  31687. };
  31688. });
  31689. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  31690. arrayEach(['initial', 'tail'], function(methodName, index) {
  31691. var dropName = 'drop' + (index ? '' : 'Right');
  31692. LazyWrapper.prototype[methodName] = function() {
  31693. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  31694. };
  31695. });
  31696. LazyWrapper.prototype.compact = function() {
  31697. return this.filter(identity);
  31698. };
  31699. LazyWrapper.prototype.find = function(predicate) {
  31700. return this.filter(predicate).head();
  31701. };
  31702. LazyWrapper.prototype.findLast = function(predicate) {
  31703. return this.reverse().find(predicate);
  31704. };
  31705. LazyWrapper.prototype.invokeMap = rest(function(path, args) {
  31706. if (typeof path == 'function') {
  31707. return new LazyWrapper(this);
  31708. }
  31709. return this.map(function(value) {
  31710. return baseInvoke(value, path, args);
  31711. });
  31712. });
  31713. LazyWrapper.prototype.reject = function(predicate) {
  31714. predicate = getIteratee(predicate, 3);
  31715. return this.filter(function(value) {
  31716. return !predicate(value);
  31717. });
  31718. };
  31719. LazyWrapper.prototype.slice = function(start, end) {
  31720. start = toInteger(start);
  31721. var result = this;
  31722. if (result.__filtered__ && (start > 0 || end < 0)) {
  31723. return new LazyWrapper(result);
  31724. }
  31725. if (start < 0) {
  31726. result = result.takeRight(-start);
  31727. } else if (start) {
  31728. result = result.drop(start);
  31729. }
  31730. if (end !== undefined) {
  31731. end = toInteger(end);
  31732. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  31733. }
  31734. return result;
  31735. };
  31736. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  31737. return this.reverse().takeWhile(predicate).reverse();
  31738. };
  31739. LazyWrapper.prototype.toArray = function() {
  31740. return this.take(MAX_ARRAY_LENGTH);
  31741. };
  31742. // Add `LazyWrapper` methods to `lodash.prototype`.
  31743. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  31744. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  31745. isTaker = /^(?:head|last)$/.test(methodName),
  31746. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  31747. retUnwrapped = isTaker || /^find/.test(methodName);
  31748. if (!lodashFunc) {
  31749. return;
  31750. }
  31751. lodash.prototype[methodName] = function() {
  31752. var value = this.__wrapped__,
  31753. args = isTaker ? [1] : arguments,
  31754. isLazy = value instanceof LazyWrapper,
  31755. iteratee = args[0],
  31756. useLazy = isLazy || isArray(value);
  31757. var interceptor = function(value) {
  31758. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  31759. return (isTaker && chainAll) ? result[0] : result;
  31760. };
  31761. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  31762. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  31763. isLazy = useLazy = false;
  31764. }
  31765. var chainAll = this.__chain__,
  31766. isHybrid = !!this.__actions__.length,
  31767. isUnwrapped = retUnwrapped && !chainAll,
  31768. onlyLazy = isLazy && !isHybrid;
  31769. if (!retUnwrapped && useLazy) {
  31770. value = onlyLazy ? value : new LazyWrapper(this);
  31771. var result = func.apply(value, args);
  31772. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  31773. return new LodashWrapper(result, chainAll);
  31774. }
  31775. if (isUnwrapped && onlyLazy) {
  31776. return func.apply(this, args);
  31777. }
  31778. result = this.thru(interceptor);
  31779. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  31780. };
  31781. });
  31782. // Add `Array` methods to `lodash.prototype`.
  31783. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  31784. var func = arrayProto[methodName],
  31785. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  31786. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  31787. lodash.prototype[methodName] = function() {
  31788. var args = arguments;
  31789. if (retUnwrapped && !this.__chain__) {
  31790. var value = this.value();
  31791. return func.apply(isArray(value) ? value : [], args);
  31792. }
  31793. return this[chainName](function(value) {
  31794. return func.apply(isArray(value) ? value : [], args);
  31795. });
  31796. };
  31797. });
  31798. // Map minified method names to their real names.
  31799. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  31800. var lodashFunc = lodash[methodName];
  31801. if (lodashFunc) {
  31802. var key = (lodashFunc.name + ''),
  31803. names = realNames[key] || (realNames[key] = []);
  31804. names.push({ 'name': methodName, 'func': lodashFunc });
  31805. }
  31806. });
  31807. realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{
  31808. 'name': 'wrapper',
  31809. 'func': undefined
  31810. }];
  31811. // Add methods to `LazyWrapper`.
  31812. LazyWrapper.prototype.clone = lazyClone;
  31813. LazyWrapper.prototype.reverse = lazyReverse;
  31814. LazyWrapper.prototype.value = lazyValue;
  31815. // Add chain sequence methods to the `lodash` wrapper.
  31816. lodash.prototype.at = wrapperAt;
  31817. lodash.prototype.chain = wrapperChain;
  31818. lodash.prototype.commit = wrapperCommit;
  31819. lodash.prototype.next = wrapperNext;
  31820. lodash.prototype.plant = wrapperPlant;
  31821. lodash.prototype.reverse = wrapperReverse;
  31822. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  31823. if (iteratorSymbol) {
  31824. lodash.prototype[iteratorSymbol] = wrapperToIterator;
  31825. }
  31826. return lodash;
  31827. }
  31828. /*--------------------------------------------------------------------------*/
  31829. // Export lodash.
  31830. var _ = runInContext();
  31831. // Expose Lodash on the free variable `window` or `self` when available so it's
  31832. // globally accessible, even when bundled with Browserify, Webpack, etc. This
  31833. // also prevents errors in cases where Lodash is loaded by a script tag in the
  31834. // presence of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch
  31835. // for more details. Use `_.noConflict` to remove Lodash from the global object.
  31836. (freeSelf || {})._ = _;
  31837. // Some AMD build optimizers like r.js check for condition patterns like the following:
  31838. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  31839. // Define as an anonymous module so, through path mapping, it can be
  31840. // referenced as the "underscore" module.
  31841. define(function() {
  31842. return _;
  31843. });
  31844. }
  31845. // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
  31846. else if (freeModule) {
  31847. // Export for Node.js.
  31848. (freeModule.exports = _)._ = _;
  31849. // Export for CommonJS support.
  31850. freeExports._ = _;
  31851. }
  31852. else {
  31853. // Export to the global object.
  31854. root._ = _;
  31855. }
  31856. }.call(this));
  31857. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  31858. },{}],104:[function(require,module,exports){
  31859. //! moment.js
  31860. //! version : 2.13.0
  31861. //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
  31862. //! license : MIT
  31863. //! momentjs.com
  31864. ;(function (global, factory) {
  31865. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  31866. typeof define === 'function' && define.amd ? define(factory) :
  31867. global.moment = factory()
  31868. }(this, function () { 'use strict';
  31869. var hookCallback;
  31870. function utils_hooks__hooks () {
  31871. return hookCallback.apply(null, arguments);
  31872. }
  31873. // This is done to register the method called with moment()
  31874. // without creating circular dependencies.
  31875. function setHookCallback (callback) {
  31876. hookCallback = callback;
  31877. }
  31878. function isArray(input) {
  31879. return input instanceof Array || Object.prototype.toString.call(input) === '[object Array]';
  31880. }
  31881. function isDate(input) {
  31882. return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';
  31883. }
  31884. function map(arr, fn) {
  31885. var res = [], i;
  31886. for (i = 0; i < arr.length; ++i) {
  31887. res.push(fn(arr[i], i));
  31888. }
  31889. return res;
  31890. }
  31891. function hasOwnProp(a, b) {
  31892. return Object.prototype.hasOwnProperty.call(a, b);
  31893. }
  31894. function extend(a, b) {
  31895. for (var i in b) {
  31896. if (hasOwnProp(b, i)) {
  31897. a[i] = b[i];
  31898. }
  31899. }
  31900. if (hasOwnProp(b, 'toString')) {
  31901. a.toString = b.toString;
  31902. }
  31903. if (hasOwnProp(b, 'valueOf')) {
  31904. a.valueOf = b.valueOf;
  31905. }
  31906. return a;
  31907. }
  31908. function create_utc__createUTC (input, format, locale, strict) {
  31909. return createLocalOrUTC(input, format, locale, strict, true).utc();
  31910. }
  31911. function defaultParsingFlags() {
  31912. // We need to deep clone this object.
  31913. return {
  31914. empty : false,
  31915. unusedTokens : [],
  31916. unusedInput : [],
  31917. overflow : -2,
  31918. charsLeftOver : 0,
  31919. nullInput : false,
  31920. invalidMonth : null,
  31921. invalidFormat : false,
  31922. userInvalidated : false,
  31923. iso : false,
  31924. parsedDateParts : [],
  31925. meridiem : null
  31926. };
  31927. }
  31928. function getParsingFlags(m) {
  31929. if (m._pf == null) {
  31930. m._pf = defaultParsingFlags();
  31931. }
  31932. return m._pf;
  31933. }
  31934. var some;
  31935. if (Array.prototype.some) {
  31936. some = Array.prototype.some;
  31937. } else {
  31938. some = function (fun) {
  31939. var t = Object(this);
  31940. var len = t.length >>> 0;
  31941. for (var i = 0; i < len; i++) {
  31942. if (i in t && fun.call(this, t[i], i, t)) {
  31943. return true;
  31944. }
  31945. }
  31946. return false;
  31947. };
  31948. }
  31949. function valid__isValid(m) {
  31950. if (m._isValid == null) {
  31951. var flags = getParsingFlags(m);
  31952. var parsedParts = some.call(flags.parsedDateParts, function (i) {
  31953. return i != null;
  31954. });
  31955. m._isValid = !isNaN(m._d.getTime()) &&
  31956. flags.overflow < 0 &&
  31957. !flags.empty &&
  31958. !flags.invalidMonth &&
  31959. !flags.invalidWeekday &&
  31960. !flags.nullInput &&
  31961. !flags.invalidFormat &&
  31962. !flags.userInvalidated &&
  31963. (!flags.meridiem || (flags.meridiem && parsedParts));
  31964. if (m._strict) {
  31965. m._isValid = m._isValid &&
  31966. flags.charsLeftOver === 0 &&
  31967. flags.unusedTokens.length === 0 &&
  31968. flags.bigHour === undefined;
  31969. }
  31970. }
  31971. return m._isValid;
  31972. }
  31973. function valid__createInvalid (flags) {
  31974. var m = create_utc__createUTC(NaN);
  31975. if (flags != null) {
  31976. extend(getParsingFlags(m), flags);
  31977. }
  31978. else {
  31979. getParsingFlags(m).userInvalidated = true;
  31980. }
  31981. return m;
  31982. }
  31983. function isUndefined(input) {
  31984. return input === void 0;
  31985. }
  31986. // Plugins that add properties should also add the key here (null value),
  31987. // so we can properly clone ourselves.
  31988. var momentProperties = utils_hooks__hooks.momentProperties = [];
  31989. function copyConfig(to, from) {
  31990. var i, prop, val;
  31991. if (!isUndefined(from._isAMomentObject)) {
  31992. to._isAMomentObject = from._isAMomentObject;
  31993. }
  31994. if (!isUndefined(from._i)) {
  31995. to._i = from._i;
  31996. }
  31997. if (!isUndefined(from._f)) {
  31998. to._f = from._f;
  31999. }
  32000. if (!isUndefined(from._l)) {
  32001. to._l = from._l;
  32002. }
  32003. if (!isUndefined(from._strict)) {
  32004. to._strict = from._strict;
  32005. }
  32006. if (!isUndefined(from._tzm)) {
  32007. to._tzm = from._tzm;
  32008. }
  32009. if (!isUndefined(from._isUTC)) {
  32010. to._isUTC = from._isUTC;
  32011. }
  32012. if (!isUndefined(from._offset)) {
  32013. to._offset = from._offset;
  32014. }
  32015. if (!isUndefined(from._pf)) {
  32016. to._pf = getParsingFlags(from);
  32017. }
  32018. if (!isUndefined(from._locale)) {
  32019. to._locale = from._locale;
  32020. }
  32021. if (momentProperties.length > 0) {
  32022. for (i in momentProperties) {
  32023. prop = momentProperties[i];
  32024. val = from[prop];
  32025. if (!isUndefined(val)) {
  32026. to[prop] = val;
  32027. }
  32028. }
  32029. }
  32030. return to;
  32031. }
  32032. var updateInProgress = false;
  32033. // Moment prototype object
  32034. function Moment(config) {
  32035. copyConfig(this, config);
  32036. this._d = new Date(config._d != null ? config._d.getTime() : NaN);
  32037. // Prevent infinite loop in case updateOffset creates new moment
  32038. // objects.
  32039. if (updateInProgress === false) {
  32040. updateInProgress = true;
  32041. utils_hooks__hooks.updateOffset(this);
  32042. updateInProgress = false;
  32043. }
  32044. }
  32045. function isMoment (obj) {
  32046. return obj instanceof Moment || (obj != null && obj._isAMomentObject != null);
  32047. }
  32048. function absFloor (number) {
  32049. if (number < 0) {
  32050. return Math.ceil(number);
  32051. } else {
  32052. return Math.floor(number);
  32053. }
  32054. }
  32055. function toInt(argumentForCoercion) {
  32056. var coercedNumber = +argumentForCoercion,
  32057. value = 0;
  32058. if (coercedNumber !== 0 && isFinite(coercedNumber)) {
  32059. value = absFloor(coercedNumber);
  32060. }
  32061. return value;
  32062. }
  32063. // compare two arrays, return the number of differences
  32064. function compareArrays(array1, array2, dontConvert) {
  32065. var len = Math.min(array1.length, array2.length),
  32066. lengthDiff = Math.abs(array1.length - array2.length),
  32067. diffs = 0,
  32068. i;
  32069. for (i = 0; i < len; i++) {
  32070. if ((dontConvert && array1[i] !== array2[i]) ||
  32071. (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
  32072. diffs++;
  32073. }
  32074. }
  32075. return diffs + lengthDiff;
  32076. }
  32077. function warn(msg) {
  32078. if (utils_hooks__hooks.suppressDeprecationWarnings === false &&
  32079. (typeof console !== 'undefined') && console.warn) {
  32080. console.warn('Deprecation warning: ' + msg);
  32081. }
  32082. }
  32083. function deprecate(msg, fn) {
  32084. var firstTime = true;
  32085. return extend(function () {
  32086. if (utils_hooks__hooks.deprecationHandler != null) {
  32087. utils_hooks__hooks.deprecationHandler(null, msg);
  32088. }
  32089. if (firstTime) {
  32090. warn(msg + '\nArguments: ' + Array.prototype.slice.call(arguments).join(', ') + '\n' + (new Error()).stack);
  32091. firstTime = false;
  32092. }
  32093. return fn.apply(this, arguments);
  32094. }, fn);
  32095. }
  32096. var deprecations = {};
  32097. function deprecateSimple(name, msg) {
  32098. if (utils_hooks__hooks.deprecationHandler != null) {
  32099. utils_hooks__hooks.deprecationHandler(name, msg);
  32100. }
  32101. if (!deprecations[name]) {
  32102. warn(msg);
  32103. deprecations[name] = true;
  32104. }
  32105. }
  32106. utils_hooks__hooks.suppressDeprecationWarnings = false;
  32107. utils_hooks__hooks.deprecationHandler = null;
  32108. function isFunction(input) {
  32109. return input instanceof Function || Object.prototype.toString.call(input) === '[object Function]';
  32110. }
  32111. function isObject(input) {
  32112. return Object.prototype.toString.call(input) === '[object Object]';
  32113. }
  32114. function locale_set__set (config) {
  32115. var prop, i;
  32116. for (i in config) {
  32117. prop = config[i];
  32118. if (isFunction(prop)) {
  32119. this[i] = prop;
  32120. } else {
  32121. this['_' + i] = prop;
  32122. }
  32123. }
  32124. this._config = config;
  32125. // Lenient ordinal parsing accepts just a number in addition to
  32126. // number + (possibly) stuff coming from _ordinalParseLenient.
  32127. this._ordinalParseLenient = new RegExp(this._ordinalParse.source + '|' + (/\d{1,2}/).source);
  32128. }
  32129. function mergeConfigs(parentConfig, childConfig) {
  32130. var res = extend({}, parentConfig), prop;
  32131. for (prop in childConfig) {
  32132. if (hasOwnProp(childConfig, prop)) {
  32133. if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) {
  32134. res[prop] = {};
  32135. extend(res[prop], parentConfig[prop]);
  32136. extend(res[prop], childConfig[prop]);
  32137. } else if (childConfig[prop] != null) {
  32138. res[prop] = childConfig[prop];
  32139. } else {
  32140. delete res[prop];
  32141. }
  32142. }
  32143. }
  32144. return res;
  32145. }
  32146. function Locale(config) {
  32147. if (config != null) {
  32148. this.set(config);
  32149. }
  32150. }
  32151. var keys;
  32152. if (Object.keys) {
  32153. keys = Object.keys;
  32154. } else {
  32155. keys = function (obj) {
  32156. var i, res = [];
  32157. for (i in obj) {
  32158. if (hasOwnProp(obj, i)) {
  32159. res.push(i);
  32160. }
  32161. }
  32162. return res;
  32163. };
  32164. }
  32165. // internal storage for locale config files
  32166. var locales = {};
  32167. var globalLocale;
  32168. function normalizeLocale(key) {
  32169. return key ? key.toLowerCase().replace('_', '-') : key;
  32170. }
  32171. // pick the locale from the array
  32172. // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
  32173. // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
  32174. function chooseLocale(names) {
  32175. var i = 0, j, next, locale, split;
  32176. while (i < names.length) {
  32177. split = normalizeLocale(names[i]).split('-');
  32178. j = split.length;
  32179. next = normalizeLocale(names[i + 1]);
  32180. next = next ? next.split('-') : null;
  32181. while (j > 0) {
  32182. locale = loadLocale(split.slice(0, j).join('-'));
  32183. if (locale) {
  32184. return locale;
  32185. }
  32186. if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
  32187. //the next array item is better than a shallower substring of this one
  32188. break;
  32189. }
  32190. j--;
  32191. }
  32192. i++;
  32193. }
  32194. return null;
  32195. }
  32196. function loadLocale(name) {
  32197. var oldLocale = null;
  32198. // TODO: Find a better way to register and load all the locales in Node
  32199. if (!locales[name] && (typeof module !== 'undefined') &&
  32200. module && module.exports) {
  32201. try {
  32202. oldLocale = globalLocale._abbr;
  32203. require('./locale/' + name);
  32204. // because defineLocale currently also sets the global locale, we
  32205. // want to undo that for lazy loaded locales
  32206. locale_locales__getSetGlobalLocale(oldLocale);
  32207. } catch (e) { }
  32208. }
  32209. return locales[name];
  32210. }
  32211. // This function will load locale and then set the global locale. If
  32212. // no arguments are passed in, it will simply return the current global
  32213. // locale key.
  32214. function locale_locales__getSetGlobalLocale (key, values) {
  32215. var data;
  32216. if (key) {
  32217. if (isUndefined(values)) {
  32218. data = locale_locales__getLocale(key);
  32219. }
  32220. else {
  32221. data = defineLocale(key, values);
  32222. }
  32223. if (data) {
  32224. // moment.duration._locale = moment._locale = data;
  32225. globalLocale = data;
  32226. }
  32227. }
  32228. return globalLocale._abbr;
  32229. }
  32230. function defineLocale (name, config) {
  32231. if (config !== null) {
  32232. config.abbr = name;
  32233. if (locales[name] != null) {
  32234. deprecateSimple('defineLocaleOverride',
  32235. 'use moment.updateLocale(localeName, config) to change ' +
  32236. 'an existing locale. moment.defineLocale(localeName, ' +
  32237. 'config) should only be used for creating a new locale');
  32238. config = mergeConfigs(locales[name]._config, config);
  32239. } else if (config.parentLocale != null) {
  32240. if (locales[config.parentLocale] != null) {
  32241. config = mergeConfigs(locales[config.parentLocale]._config, config);
  32242. } else {
  32243. // treat as if there is no base config
  32244. deprecateSimple('parentLocaleUndefined',
  32245. 'specified parentLocale is not defined yet');
  32246. }
  32247. }
  32248. locales[name] = new Locale(config);
  32249. // backwards compat for now: also set the locale
  32250. locale_locales__getSetGlobalLocale(name);
  32251. return locales[name];
  32252. } else {
  32253. // useful for testing
  32254. delete locales[name];
  32255. return null;
  32256. }
  32257. }
  32258. function updateLocale(name, config) {
  32259. if (config != null) {
  32260. var locale;
  32261. if (locales[name] != null) {
  32262. config = mergeConfigs(locales[name]._config, config);
  32263. }
  32264. locale = new Locale(config);
  32265. locale.parentLocale = locales[name];
  32266. locales[name] = locale;
  32267. // backwards compat for now: also set the locale
  32268. locale_locales__getSetGlobalLocale(name);
  32269. } else {
  32270. // pass null for config to unupdate, useful for tests
  32271. if (locales[name] != null) {
  32272. if (locales[name].parentLocale != null) {
  32273. locales[name] = locales[name].parentLocale;
  32274. } else if (locales[name] != null) {
  32275. delete locales[name];
  32276. }
  32277. }
  32278. }
  32279. return locales[name];
  32280. }
  32281. // returns locale data
  32282. function locale_locales__getLocale (key) {
  32283. var locale;
  32284. if (key && key._locale && key._locale._abbr) {
  32285. key = key._locale._abbr;
  32286. }
  32287. if (!key) {
  32288. return globalLocale;
  32289. }
  32290. if (!isArray(key)) {
  32291. //short-circuit everything else
  32292. locale = loadLocale(key);
  32293. if (locale) {
  32294. return locale;
  32295. }
  32296. key = [key];
  32297. }
  32298. return chooseLocale(key);
  32299. }
  32300. function locale_locales__listLocales() {
  32301. return keys(locales);
  32302. }
  32303. var aliases = {};
  32304. function addUnitAlias (unit, shorthand) {
  32305. var lowerCase = unit.toLowerCase();
  32306. aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
  32307. }
  32308. function normalizeUnits(units) {
  32309. return typeof units === 'string' ? aliases[units] || aliases[units.toLowerCase()] : undefined;
  32310. }
  32311. function normalizeObjectUnits(inputObject) {
  32312. var normalizedInput = {},
  32313. normalizedProp,
  32314. prop;
  32315. for (prop in inputObject) {
  32316. if (hasOwnProp(inputObject, prop)) {
  32317. normalizedProp = normalizeUnits(prop);
  32318. if (normalizedProp) {
  32319. normalizedInput[normalizedProp] = inputObject[prop];
  32320. }
  32321. }
  32322. }
  32323. return normalizedInput;
  32324. }
  32325. function makeGetSet (unit, keepTime) {
  32326. return function (value) {
  32327. if (value != null) {
  32328. get_set__set(this, unit, value);
  32329. utils_hooks__hooks.updateOffset(this, keepTime);
  32330. return this;
  32331. } else {
  32332. return get_set__get(this, unit);
  32333. }
  32334. };
  32335. }
  32336. function get_set__get (mom, unit) {
  32337. return mom.isValid() ?
  32338. mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]() : NaN;
  32339. }
  32340. function get_set__set (mom, unit, value) {
  32341. if (mom.isValid()) {
  32342. mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
  32343. }
  32344. }
  32345. // MOMENTS
  32346. function getSet (units, value) {
  32347. var unit;
  32348. if (typeof units === 'object') {
  32349. for (unit in units) {
  32350. this.set(unit, units[unit]);
  32351. }
  32352. } else {
  32353. units = normalizeUnits(units);
  32354. if (isFunction(this[units])) {
  32355. return this[units](value);
  32356. }
  32357. }
  32358. return this;
  32359. }
  32360. function zeroFill(number, targetLength, forceSign) {
  32361. var absNumber = '' + Math.abs(number),
  32362. zerosToFill = targetLength - absNumber.length,
  32363. sign = number >= 0;
  32364. return (sign ? (forceSign ? '+' : '') : '-') +
  32365. Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber;
  32366. }
  32367. 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;
  32368. var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;
  32369. var formatFunctions = {};
  32370. var formatTokenFunctions = {};
  32371. // token: 'M'
  32372. // padded: ['MM', 2]
  32373. // ordinal: 'Mo'
  32374. // callback: function () { this.month() + 1 }
  32375. function addFormatToken (token, padded, ordinal, callback) {
  32376. var func = callback;
  32377. if (typeof callback === 'string') {
  32378. func = function () {
  32379. return this[callback]();
  32380. };
  32381. }
  32382. if (token) {
  32383. formatTokenFunctions[token] = func;
  32384. }
  32385. if (padded) {
  32386. formatTokenFunctions[padded[0]] = function () {
  32387. return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
  32388. };
  32389. }
  32390. if (ordinal) {
  32391. formatTokenFunctions[ordinal] = function () {
  32392. return this.localeData().ordinal(func.apply(this, arguments), token);
  32393. };
  32394. }
  32395. }
  32396. function removeFormattingTokens(input) {
  32397. if (input.match(/\[[\s\S]/)) {
  32398. return input.replace(/^\[|\]$/g, '');
  32399. }
  32400. return input.replace(/\\/g, '');
  32401. }
  32402. function makeFormatFunction(format) {
  32403. var array = format.match(formattingTokens), i, length;
  32404. for (i = 0, length = array.length; i < length; i++) {
  32405. if (formatTokenFunctions[array[i]]) {
  32406. array[i] = formatTokenFunctions[array[i]];
  32407. } else {
  32408. array[i] = removeFormattingTokens(array[i]);
  32409. }
  32410. }
  32411. return function (mom) {
  32412. var output = '', i;
  32413. for (i = 0; i < length; i++) {
  32414. output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];
  32415. }
  32416. return output;
  32417. };
  32418. }
  32419. // format date using native date object
  32420. function formatMoment(m, format) {
  32421. if (!m.isValid()) {
  32422. return m.localeData().invalidDate();
  32423. }
  32424. format = expandFormat(format, m.localeData());
  32425. formatFunctions[format] = formatFunctions[format] || makeFormatFunction(format);
  32426. return formatFunctions[format](m);
  32427. }
  32428. function expandFormat(format, locale) {
  32429. var i = 5;
  32430. function replaceLongDateFormatTokens(input) {
  32431. return locale.longDateFormat(input) || input;
  32432. }
  32433. localFormattingTokens.lastIndex = 0;
  32434. while (i >= 0 && localFormattingTokens.test(format)) {
  32435. format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
  32436. localFormattingTokens.lastIndex = 0;
  32437. i -= 1;
  32438. }
  32439. return format;
  32440. }
  32441. var match1 = /\d/; // 0 - 9
  32442. var match2 = /\d\d/; // 00 - 99
  32443. var match3 = /\d{3}/; // 000 - 999
  32444. var match4 = /\d{4}/; // 0000 - 9999
  32445. var match6 = /[+-]?\d{6}/; // -999999 - 999999
  32446. var match1to2 = /\d\d?/; // 0 - 99
  32447. var match3to4 = /\d\d\d\d?/; // 999 - 9999
  32448. var match5to6 = /\d\d\d\d\d\d?/; // 99999 - 999999
  32449. var match1to3 = /\d{1,3}/; // 0 - 999
  32450. var match1to4 = /\d{1,4}/; // 0 - 9999
  32451. var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999
  32452. var matchUnsigned = /\d+/; // 0 - inf
  32453. var matchSigned = /[+-]?\d+/; // -inf - inf
  32454. var matchOffset = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
  32455. var matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z
  32456. var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
  32457. // any word (or two) characters or numbers including two/three word month in arabic.
  32458. // includes scottish gaelic two word and hyphenated months
  32459. var matchWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i;
  32460. var regexes = {};
  32461. function addRegexToken (token, regex, strictRegex) {
  32462. regexes[token] = isFunction(regex) ? regex : function (isStrict, localeData) {
  32463. return (isStrict && strictRegex) ? strictRegex : regex;
  32464. };
  32465. }
  32466. function getParseRegexForToken (token, config) {
  32467. if (!hasOwnProp(regexes, token)) {
  32468. return new RegExp(unescapeFormat(token));
  32469. }
  32470. return regexes[token](config._strict, config._locale);
  32471. }
  32472. // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
  32473. function unescapeFormat(s) {
  32474. return regexEscape(s.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
  32475. return p1 || p2 || p3 || p4;
  32476. }));
  32477. }
  32478. function regexEscape(s) {
  32479. return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  32480. }
  32481. var tokens = {};
  32482. function addParseToken (token, callback) {
  32483. var i, func = callback;
  32484. if (typeof token === 'string') {
  32485. token = [token];
  32486. }
  32487. if (typeof callback === 'number') {
  32488. func = function (input, array) {
  32489. array[callback] = toInt(input);
  32490. };
  32491. }
  32492. for (i = 0; i < token.length; i++) {
  32493. tokens[token[i]] = func;
  32494. }
  32495. }
  32496. function addWeekParseToken (token, callback) {
  32497. addParseToken(token, function (input, array, config, token) {
  32498. config._w = config._w || {};
  32499. callback(input, config._w, config, token);
  32500. });
  32501. }
  32502. function addTimeToArrayFromToken(token, input, config) {
  32503. if (input != null && hasOwnProp(tokens, token)) {
  32504. tokens[token](input, config._a, config, token);
  32505. }
  32506. }
  32507. var YEAR = 0;
  32508. var MONTH = 1;
  32509. var DATE = 2;
  32510. var HOUR = 3;
  32511. var MINUTE = 4;
  32512. var SECOND = 5;
  32513. var MILLISECOND = 6;
  32514. var WEEK = 7;
  32515. var WEEKDAY = 8;
  32516. var indexOf;
  32517. if (Array.prototype.indexOf) {
  32518. indexOf = Array.prototype.indexOf;
  32519. } else {
  32520. indexOf = function (o) {
  32521. // I know
  32522. var i;
  32523. for (i = 0; i < this.length; ++i) {
  32524. if (this[i] === o) {
  32525. return i;
  32526. }
  32527. }
  32528. return -1;
  32529. };
  32530. }
  32531. function daysInMonth(year, month) {
  32532. return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
  32533. }
  32534. // FORMATTING
  32535. addFormatToken('M', ['MM', 2], 'Mo', function () {
  32536. return this.month() + 1;
  32537. });
  32538. addFormatToken('MMM', 0, 0, function (format) {
  32539. return this.localeData().monthsShort(this, format);
  32540. });
  32541. addFormatToken('MMMM', 0, 0, function (format) {
  32542. return this.localeData().months(this, format);
  32543. });
  32544. // ALIASES
  32545. addUnitAlias('month', 'M');
  32546. // PARSING
  32547. addRegexToken('M', match1to2);
  32548. addRegexToken('MM', match1to2, match2);
  32549. addRegexToken('MMM', function (isStrict, locale) {
  32550. return locale.monthsShortRegex(isStrict);
  32551. });
  32552. addRegexToken('MMMM', function (isStrict, locale) {
  32553. return locale.monthsRegex(isStrict);
  32554. });
  32555. addParseToken(['M', 'MM'], function (input, array) {
  32556. array[MONTH] = toInt(input) - 1;
  32557. });
  32558. addParseToken(['MMM', 'MMMM'], function (input, array, config, token) {
  32559. var month = config._locale.monthsParse(input, token, config._strict);
  32560. // if we didn't find a month name, mark the date as invalid.
  32561. if (month != null) {
  32562. array[MONTH] = month;
  32563. } else {
  32564. getParsingFlags(config).invalidMonth = input;
  32565. }
  32566. });
  32567. // LOCALES
  32568. var MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/;
  32569. var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');
  32570. function localeMonths (m, format) {
  32571. return isArray(this._months) ? this._months[m.month()] :
  32572. this._months[MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'][m.month()];
  32573. }
  32574. var defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
  32575. function localeMonthsShort (m, format) {
  32576. return isArray(this._monthsShort) ? this._monthsShort[m.month()] :
  32577. this._monthsShort[MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'][m.month()];
  32578. }
  32579. function units_month__handleStrictParse(monthName, format, strict) {
  32580. var i, ii, mom, llc = monthName.toLocaleLowerCase();
  32581. if (!this._monthsParse) {
  32582. // this is not used
  32583. this._monthsParse = [];
  32584. this._longMonthsParse = [];
  32585. this._shortMonthsParse = [];
  32586. for (i = 0; i < 12; ++i) {
  32587. mom = create_utc__createUTC([2000, i]);
  32588. this._shortMonthsParse[i] = this.monthsShort(mom, '').toLocaleLowerCase();
  32589. this._longMonthsParse[i] = this.months(mom, '').toLocaleLowerCase();
  32590. }
  32591. }
  32592. if (strict) {
  32593. if (format === 'MMM') {
  32594. ii = indexOf.call(this._shortMonthsParse, llc);
  32595. return ii !== -1 ? ii : null;
  32596. } else {
  32597. ii = indexOf.call(this._longMonthsParse, llc);
  32598. return ii !== -1 ? ii : null;
  32599. }
  32600. } else {
  32601. if (format === 'MMM') {
  32602. ii = indexOf.call(this._shortMonthsParse, llc);
  32603. if (ii !== -1) {
  32604. return ii;
  32605. }
  32606. ii = indexOf.call(this._longMonthsParse, llc);
  32607. return ii !== -1 ? ii : null;
  32608. } else {
  32609. ii = indexOf.call(this._longMonthsParse, llc);
  32610. if (ii !== -1) {
  32611. return ii;
  32612. }
  32613. ii = indexOf.call(this._shortMonthsParse, llc);
  32614. return ii !== -1 ? ii : null;
  32615. }
  32616. }
  32617. }
  32618. function localeMonthsParse (monthName, format, strict) {
  32619. var i, mom, regex;
  32620. if (this._monthsParseExact) {
  32621. return units_month__handleStrictParse.call(this, monthName, format, strict);
  32622. }
  32623. if (!this._monthsParse) {
  32624. this._monthsParse = [];
  32625. this._longMonthsParse = [];
  32626. this._shortMonthsParse = [];
  32627. }
  32628. // TODO: add sorting
  32629. // Sorting makes sure if one month (or abbr) is a prefix of another
  32630. // see sorting in computeMonthsParse
  32631. for (i = 0; i < 12; i++) {
  32632. // make the regex if we don't have it already
  32633. mom = create_utc__createUTC([2000, i]);
  32634. if (strict && !this._longMonthsParse[i]) {
  32635. this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i');
  32636. this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i');
  32637. }
  32638. if (!strict && !this._monthsParse[i]) {
  32639. regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
  32640. this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
  32641. }
  32642. // test the regex
  32643. if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) {
  32644. return i;
  32645. } else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) {
  32646. return i;
  32647. } else if (!strict && this._monthsParse[i].test(monthName)) {
  32648. return i;
  32649. }
  32650. }
  32651. }
  32652. // MOMENTS
  32653. function setMonth (mom, value) {
  32654. var dayOfMonth;
  32655. if (!mom.isValid()) {
  32656. // No op
  32657. return mom;
  32658. }
  32659. if (typeof value === 'string') {
  32660. if (/^\d+$/.test(value)) {
  32661. value = toInt(value);
  32662. } else {
  32663. value = mom.localeData().monthsParse(value);
  32664. // TODO: Another silent failure?
  32665. if (typeof value !== 'number') {
  32666. return mom;
  32667. }
  32668. }
  32669. }
  32670. dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
  32671. mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
  32672. return mom;
  32673. }
  32674. function getSetMonth (value) {
  32675. if (value != null) {
  32676. setMonth(this, value);
  32677. utils_hooks__hooks.updateOffset(this, true);
  32678. return this;
  32679. } else {
  32680. return get_set__get(this, 'Month');
  32681. }
  32682. }
  32683. function getDaysInMonth () {
  32684. return daysInMonth(this.year(), this.month());
  32685. }
  32686. var defaultMonthsShortRegex = matchWord;
  32687. function monthsShortRegex (isStrict) {
  32688. if (this._monthsParseExact) {
  32689. if (!hasOwnProp(this, '_monthsRegex')) {
  32690. computeMonthsParse.call(this);
  32691. }
  32692. if (isStrict) {
  32693. return this._monthsShortStrictRegex;
  32694. } else {
  32695. return this._monthsShortRegex;
  32696. }
  32697. } else {
  32698. return this._monthsShortStrictRegex && isStrict ?
  32699. this._monthsShortStrictRegex : this._monthsShortRegex;
  32700. }
  32701. }
  32702. var defaultMonthsRegex = matchWord;
  32703. function monthsRegex (isStrict) {
  32704. if (this._monthsParseExact) {
  32705. if (!hasOwnProp(this, '_monthsRegex')) {
  32706. computeMonthsParse.call(this);
  32707. }
  32708. if (isStrict) {
  32709. return this._monthsStrictRegex;
  32710. } else {
  32711. return this._monthsRegex;
  32712. }
  32713. } else {
  32714. return this._monthsStrictRegex && isStrict ?
  32715. this._monthsStrictRegex : this._monthsRegex;
  32716. }
  32717. }
  32718. function computeMonthsParse () {
  32719. function cmpLenRev(a, b) {
  32720. return b.length - a.length;
  32721. }
  32722. var shortPieces = [], longPieces = [], mixedPieces = [],
  32723. i, mom;
  32724. for (i = 0; i < 12; i++) {
  32725. // make the regex if we don't have it already
  32726. mom = create_utc__createUTC([2000, i]);
  32727. shortPieces.push(this.monthsShort(mom, ''));
  32728. longPieces.push(this.months(mom, ''));
  32729. mixedPieces.push(this.months(mom, ''));
  32730. mixedPieces.push(this.monthsShort(mom, ''));
  32731. }
  32732. // Sorting makes sure if one month (or abbr) is a prefix of another it
  32733. // will match the longer piece.
  32734. shortPieces.sort(cmpLenRev);
  32735. longPieces.sort(cmpLenRev);
  32736. mixedPieces.sort(cmpLenRev);
  32737. for (i = 0; i < 12; i++) {
  32738. shortPieces[i] = regexEscape(shortPieces[i]);
  32739. longPieces[i] = regexEscape(longPieces[i]);
  32740. mixedPieces[i] = regexEscape(mixedPieces[i]);
  32741. }
  32742. this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
  32743. this._monthsShortRegex = this._monthsRegex;
  32744. this._monthsStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
  32745. this._monthsShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
  32746. }
  32747. function checkOverflow (m) {
  32748. var overflow;
  32749. var a = m._a;
  32750. if (a && getParsingFlags(m).overflow === -2) {
  32751. overflow =
  32752. a[MONTH] < 0 || a[MONTH] > 11 ? MONTH :
  32753. a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH]) ? DATE :
  32754. a[HOUR] < 0 || a[HOUR] > 24 || (a[HOUR] === 24 && (a[MINUTE] !== 0 || a[SECOND] !== 0 || a[MILLISECOND] !== 0)) ? HOUR :
  32755. a[MINUTE] < 0 || a[MINUTE] > 59 ? MINUTE :
  32756. a[SECOND] < 0 || a[SECOND] > 59 ? SECOND :
  32757. a[MILLISECOND] < 0 || a[MILLISECOND] > 999 ? MILLISECOND :
  32758. -1;
  32759. if (getParsingFlags(m)._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
  32760. overflow = DATE;
  32761. }
  32762. if (getParsingFlags(m)._overflowWeeks && overflow === -1) {
  32763. overflow = WEEK;
  32764. }
  32765. if (getParsingFlags(m)._overflowWeekday && overflow === -1) {
  32766. overflow = WEEKDAY;
  32767. }
  32768. getParsingFlags(m).overflow = overflow;
  32769. }
  32770. return m;
  32771. }
  32772. // iso 8601 regex
  32773. // 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)
  32774. 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)?)?/;
  32775. 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)?)?/;
  32776. var tzRegex = /Z|[+-]\d\d(?::?\d\d)?/;
  32777. var isoDates = [
  32778. ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
  32779. ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
  32780. ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
  32781. ['GGGG-[W]WW', /\d{4}-W\d\d/, false],
  32782. ['YYYY-DDD', /\d{4}-\d{3}/],
  32783. ['YYYY-MM', /\d{4}-\d\d/, false],
  32784. ['YYYYYYMMDD', /[+-]\d{10}/],
  32785. ['YYYYMMDD', /\d{8}/],
  32786. // YYYYMM is NOT allowed by the standard
  32787. ['GGGG[W]WWE', /\d{4}W\d{3}/],
  32788. ['GGGG[W]WW', /\d{4}W\d{2}/, false],
  32789. ['YYYYDDD', /\d{7}/]
  32790. ];
  32791. // iso time formats and regexes
  32792. var isoTimes = [
  32793. ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
  32794. ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
  32795. ['HH:mm:ss', /\d\d:\d\d:\d\d/],
  32796. ['HH:mm', /\d\d:\d\d/],
  32797. ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
  32798. ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
  32799. ['HHmmss', /\d\d\d\d\d\d/],
  32800. ['HHmm', /\d\d\d\d/],
  32801. ['HH', /\d\d/]
  32802. ];
  32803. var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i;
  32804. // date from iso format
  32805. function configFromISO(config) {
  32806. var i, l,
  32807. string = config._i,
  32808. match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string),
  32809. allowTime, dateFormat, timeFormat, tzFormat;
  32810. if (match) {
  32811. getParsingFlags(config).iso = true;
  32812. for (i = 0, l = isoDates.length; i < l; i++) {
  32813. if (isoDates[i][1].exec(match[1])) {
  32814. dateFormat = isoDates[i][0];
  32815. allowTime = isoDates[i][2] !== false;
  32816. break;
  32817. }
  32818. }
  32819. if (dateFormat == null) {
  32820. config._isValid = false;
  32821. return;
  32822. }
  32823. if (match[3]) {
  32824. for (i = 0, l = isoTimes.length; i < l; i++) {
  32825. if (isoTimes[i][1].exec(match[3])) {
  32826. // match[2] should be 'T' or space
  32827. timeFormat = (match[2] || ' ') + isoTimes[i][0];
  32828. break;
  32829. }
  32830. }
  32831. if (timeFormat == null) {
  32832. config._isValid = false;
  32833. return;
  32834. }
  32835. }
  32836. if (!allowTime && timeFormat != null) {
  32837. config._isValid = false;
  32838. return;
  32839. }
  32840. if (match[4]) {
  32841. if (tzRegex.exec(match[4])) {
  32842. tzFormat = 'Z';
  32843. } else {
  32844. config._isValid = false;
  32845. return;
  32846. }
  32847. }
  32848. config._f = dateFormat + (timeFormat || '') + (tzFormat || '');
  32849. configFromStringAndFormat(config);
  32850. } else {
  32851. config._isValid = false;
  32852. }
  32853. }
  32854. // date from iso format or fallback
  32855. function configFromString(config) {
  32856. var matched = aspNetJsonRegex.exec(config._i);
  32857. if (matched !== null) {
  32858. config._d = new Date(+matched[1]);
  32859. return;
  32860. }
  32861. configFromISO(config);
  32862. if (config._isValid === false) {
  32863. delete config._isValid;
  32864. utils_hooks__hooks.createFromInputFallback(config);
  32865. }
  32866. }
  32867. utils_hooks__hooks.createFromInputFallback = deprecate(
  32868. 'moment construction falls back to js Date. This is ' +
  32869. 'discouraged and will be removed in upcoming major ' +
  32870. 'release. Please refer to ' +
  32871. 'https://github.com/moment/moment/issues/1407 for more info.',
  32872. function (config) {
  32873. config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
  32874. }
  32875. );
  32876. function createDate (y, m, d, h, M, s, ms) {
  32877. //can't just apply() to create a date:
  32878. //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply
  32879. var date = new Date(y, m, d, h, M, s, ms);
  32880. //the date constructor remaps years 0-99 to 1900-1999
  32881. if (y < 100 && y >= 0 && isFinite(date.getFullYear())) {
  32882. date.setFullYear(y);
  32883. }
  32884. return date;
  32885. }
  32886. function createUTCDate (y) {
  32887. var date = new Date(Date.UTC.apply(null, arguments));
  32888. //the Date.UTC function remaps years 0-99 to 1900-1999
  32889. if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) {
  32890. date.setUTCFullYear(y);
  32891. }
  32892. return date;
  32893. }
  32894. // FORMATTING
  32895. addFormatToken('Y', 0, 0, function () {
  32896. var y = this.year();
  32897. return y <= 9999 ? '' + y : '+' + y;
  32898. });
  32899. addFormatToken(0, ['YY', 2], 0, function () {
  32900. return this.year() % 100;
  32901. });
  32902. addFormatToken(0, ['YYYY', 4], 0, 'year');
  32903. addFormatToken(0, ['YYYYY', 5], 0, 'year');
  32904. addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
  32905. // ALIASES
  32906. addUnitAlias('year', 'y');
  32907. // PARSING
  32908. addRegexToken('Y', matchSigned);
  32909. addRegexToken('YY', match1to2, match2);
  32910. addRegexToken('YYYY', match1to4, match4);
  32911. addRegexToken('YYYYY', match1to6, match6);
  32912. addRegexToken('YYYYYY', match1to6, match6);
  32913. addParseToken(['YYYYY', 'YYYYYY'], YEAR);
  32914. addParseToken('YYYY', function (input, array) {
  32915. array[YEAR] = input.length === 2 ? utils_hooks__hooks.parseTwoDigitYear(input) : toInt(input);
  32916. });
  32917. addParseToken('YY', function (input, array) {
  32918. array[YEAR] = utils_hooks__hooks.parseTwoDigitYear(input);
  32919. });
  32920. addParseToken('Y', function (input, array) {
  32921. array[YEAR] = parseInt(input, 10);
  32922. });
  32923. // HELPERS
  32924. function daysInYear(year) {
  32925. return isLeapYear(year) ? 366 : 365;
  32926. }
  32927. function isLeapYear(year) {
  32928. return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
  32929. }
  32930. // HOOKS
  32931. utils_hooks__hooks.parseTwoDigitYear = function (input) {
  32932. return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
  32933. };
  32934. // MOMENTS
  32935. var getSetYear = makeGetSet('FullYear', true);
  32936. function getIsLeapYear () {
  32937. return isLeapYear(this.year());
  32938. }
  32939. // start-of-first-week - start-of-year
  32940. function firstWeekOffset(year, dow, doy) {
  32941. var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
  32942. fwd = 7 + dow - doy,
  32943. // first-week day local weekday -- which local weekday is fwd
  32944. fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7;
  32945. return -fwdlw + fwd - 1;
  32946. }
  32947. //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
  32948. function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
  32949. var localWeekday = (7 + weekday - dow) % 7,
  32950. weekOffset = firstWeekOffset(year, dow, doy),
  32951. dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset,
  32952. resYear, resDayOfYear;
  32953. if (dayOfYear <= 0) {
  32954. resYear = year - 1;
  32955. resDayOfYear = daysInYear(resYear) + dayOfYear;
  32956. } else if (dayOfYear > daysInYear(year)) {
  32957. resYear = year + 1;
  32958. resDayOfYear = dayOfYear - daysInYear(year);
  32959. } else {
  32960. resYear = year;
  32961. resDayOfYear = dayOfYear;
  32962. }
  32963. return {
  32964. year: resYear,
  32965. dayOfYear: resDayOfYear
  32966. };
  32967. }
  32968. function weekOfYear(mom, dow, doy) {
  32969. var weekOffset = firstWeekOffset(mom.year(), dow, doy),
  32970. week = Math.floor((mom.dayOfYear() - weekOffset - 1) / 7) + 1,
  32971. resWeek, resYear;
  32972. if (week < 1) {
  32973. resYear = mom.year() - 1;
  32974. resWeek = week + weeksInYear(resYear, dow, doy);
  32975. } else if (week > weeksInYear(mom.year(), dow, doy)) {
  32976. resWeek = week - weeksInYear(mom.year(), dow, doy);
  32977. resYear = mom.year() + 1;
  32978. } else {
  32979. resYear = mom.year();
  32980. resWeek = week;
  32981. }
  32982. return {
  32983. week: resWeek,
  32984. year: resYear
  32985. };
  32986. }
  32987. function weeksInYear(year, dow, doy) {
  32988. var weekOffset = firstWeekOffset(year, dow, doy),
  32989. weekOffsetNext = firstWeekOffset(year + 1, dow, doy);
  32990. return (daysInYear(year) - weekOffset + weekOffsetNext) / 7;
  32991. }
  32992. // Pick the first defined of two or three arguments.
  32993. function defaults(a, b, c) {
  32994. if (a != null) {
  32995. return a;
  32996. }
  32997. if (b != null) {
  32998. return b;
  32999. }
  33000. return c;
  33001. }
  33002. function currentDateArray(config) {
  33003. // hooks is actually the exported moment object
  33004. var nowValue = new Date(utils_hooks__hooks.now());
  33005. if (config._useUTC) {
  33006. return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()];
  33007. }
  33008. return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
  33009. }
  33010. // convert an array to a date.
  33011. // the array should mirror the parameters below
  33012. // note: all values past the year are optional and will default to the lowest possible value.
  33013. // [year, month, day , hour, minute, second, millisecond]
  33014. function configFromArray (config) {
  33015. var i, date, input = [], currentDate, yearToUse;
  33016. if (config._d) {
  33017. return;
  33018. }
  33019. currentDate = currentDateArray(config);
  33020. //compute day of the year from weeks and weekdays
  33021. if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
  33022. dayOfYearFromWeekInfo(config);
  33023. }
  33024. //if the day of the year is set, figure out what it is
  33025. if (config._dayOfYear) {
  33026. yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
  33027. if (config._dayOfYear > daysInYear(yearToUse)) {
  33028. getParsingFlags(config)._overflowDayOfYear = true;
  33029. }
  33030. date = createUTCDate(yearToUse, 0, config._dayOfYear);
  33031. config._a[MONTH] = date.getUTCMonth();
  33032. config._a[DATE] = date.getUTCDate();
  33033. }
  33034. // Default to current date.
  33035. // * if no year, month, day of month are given, default to today
  33036. // * if day of month is given, default month and year
  33037. // * if month is given, default only year
  33038. // * if year is given, don't default anything
  33039. for (i = 0; i < 3 && config._a[i] == null; ++i) {
  33040. config._a[i] = input[i] = currentDate[i];
  33041. }
  33042. // Zero out whatever was not defaulted, including time
  33043. for (; i < 7; i++) {
  33044. config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
  33045. }
  33046. // Check for 24:00:00.000
  33047. if (config._a[HOUR] === 24 &&
  33048. config._a[MINUTE] === 0 &&
  33049. config._a[SECOND] === 0 &&
  33050. config._a[MILLISECOND] === 0) {
  33051. config._nextDay = true;
  33052. config._a[HOUR] = 0;
  33053. }
  33054. config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input);
  33055. // Apply timezone offset from input. The actual utcOffset can be changed
  33056. // with parseZone.
  33057. if (config._tzm != null) {
  33058. config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
  33059. }
  33060. if (config._nextDay) {
  33061. config._a[HOUR] = 24;
  33062. }
  33063. }
  33064. function dayOfYearFromWeekInfo(config) {
  33065. var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow;
  33066. w = config._w;
  33067. if (w.GG != null || w.W != null || w.E != null) {
  33068. dow = 1;
  33069. doy = 4;
  33070. // TODO: We need to take the current isoWeekYear, but that depends on
  33071. // how we interpret now (local, utc, fixed offset). So create
  33072. // a now version of current config (take local/utc/offset flags, and
  33073. // create now).
  33074. weekYear = defaults(w.GG, config._a[YEAR], weekOfYear(local__createLocal(), 1, 4).year);
  33075. week = defaults(w.W, 1);
  33076. weekday = defaults(w.E, 1);
  33077. if (weekday < 1 || weekday > 7) {
  33078. weekdayOverflow = true;
  33079. }
  33080. } else {
  33081. dow = config._locale._week.dow;
  33082. doy = config._locale._week.doy;
  33083. weekYear = defaults(w.gg, config._a[YEAR], weekOfYear(local__createLocal(), dow, doy).year);
  33084. week = defaults(w.w, 1);
  33085. if (w.d != null) {
  33086. // weekday -- low day numbers are considered next week
  33087. weekday = w.d;
  33088. if (weekday < 0 || weekday > 6) {
  33089. weekdayOverflow = true;
  33090. }
  33091. } else if (w.e != null) {
  33092. // local weekday -- counting starts from begining of week
  33093. weekday = w.e + dow;
  33094. if (w.e < 0 || w.e > 6) {
  33095. weekdayOverflow = true;
  33096. }
  33097. } else {
  33098. // default to begining of week
  33099. weekday = dow;
  33100. }
  33101. }
  33102. if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
  33103. getParsingFlags(config)._overflowWeeks = true;
  33104. } else if (weekdayOverflow != null) {
  33105. getParsingFlags(config)._overflowWeekday = true;
  33106. } else {
  33107. temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
  33108. config._a[YEAR] = temp.year;
  33109. config._dayOfYear = temp.dayOfYear;
  33110. }
  33111. }
  33112. // constant that refers to the ISO standard
  33113. utils_hooks__hooks.ISO_8601 = function () {};
  33114. // date from string and format string
  33115. function configFromStringAndFormat(config) {
  33116. // TODO: Move this to another part of the creation flow to prevent circular deps
  33117. if (config._f === utils_hooks__hooks.ISO_8601) {
  33118. configFromISO(config);
  33119. return;
  33120. }
  33121. config._a = [];
  33122. getParsingFlags(config).empty = true;
  33123. // This array is used to make a Date, either with `new Date` or `Date.UTC`
  33124. var string = '' + config._i,
  33125. i, parsedInput, tokens, token, skipped,
  33126. stringLength = string.length,
  33127. totalParsedInputLength = 0;
  33128. tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];
  33129. for (i = 0; i < tokens.length; i++) {
  33130. token = tokens[i];
  33131. parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
  33132. // console.log('token', token, 'parsedInput', parsedInput,
  33133. // 'regex', getParseRegexForToken(token, config));
  33134. if (parsedInput) {
  33135. skipped = string.substr(0, string.indexOf(parsedInput));
  33136. if (skipped.length > 0) {
  33137. getParsingFlags(config).unusedInput.push(skipped);
  33138. }
  33139. string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
  33140. totalParsedInputLength += parsedInput.length;
  33141. }
  33142. // don't parse if it's not a known token
  33143. if (formatTokenFunctions[token]) {
  33144. if (parsedInput) {
  33145. getParsingFlags(config).empty = false;
  33146. }
  33147. else {
  33148. getParsingFlags(config).unusedTokens.push(token);
  33149. }
  33150. addTimeToArrayFromToken(token, parsedInput, config);
  33151. }
  33152. else if (config._strict && !parsedInput) {
  33153. getParsingFlags(config).unusedTokens.push(token);
  33154. }
  33155. }
  33156. // add remaining unparsed input length to the string
  33157. getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength;
  33158. if (string.length > 0) {
  33159. getParsingFlags(config).unusedInput.push(string);
  33160. }
  33161. // clear _12h flag if hour is <= 12
  33162. if (getParsingFlags(config).bigHour === true &&
  33163. config._a[HOUR] <= 12 &&
  33164. config._a[HOUR] > 0) {
  33165. getParsingFlags(config).bigHour = undefined;
  33166. }
  33167. getParsingFlags(config).parsedDateParts = config._a.slice(0);
  33168. getParsingFlags(config).meridiem = config._meridiem;
  33169. // handle meridiem
  33170. config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR], config._meridiem);
  33171. configFromArray(config);
  33172. checkOverflow(config);
  33173. }
  33174. function meridiemFixWrap (locale, hour, meridiem) {
  33175. var isPm;
  33176. if (meridiem == null) {
  33177. // nothing to do
  33178. return hour;
  33179. }
  33180. if (locale.meridiemHour != null) {
  33181. return locale.meridiemHour(hour, meridiem);
  33182. } else if (locale.isPM != null) {
  33183. // Fallback
  33184. isPm = locale.isPM(meridiem);
  33185. if (isPm && hour < 12) {
  33186. hour += 12;
  33187. }
  33188. if (!isPm && hour === 12) {
  33189. hour = 0;
  33190. }
  33191. return hour;
  33192. } else {
  33193. // this is not supposed to happen
  33194. return hour;
  33195. }
  33196. }
  33197. // date from string and array of format strings
  33198. function configFromStringAndArray(config) {
  33199. var tempConfig,
  33200. bestMoment,
  33201. scoreToBeat,
  33202. i,
  33203. currentScore;
  33204. if (config._f.length === 0) {
  33205. getParsingFlags(config).invalidFormat = true;
  33206. config._d = new Date(NaN);
  33207. return;
  33208. }
  33209. for (i = 0; i < config._f.length; i++) {
  33210. currentScore = 0;
  33211. tempConfig = copyConfig({}, config);
  33212. if (config._useUTC != null) {
  33213. tempConfig._useUTC = config._useUTC;
  33214. }
  33215. tempConfig._f = config._f[i];
  33216. configFromStringAndFormat(tempConfig);
  33217. if (!valid__isValid(tempConfig)) {
  33218. continue;
  33219. }
  33220. // if there is any input that was not parsed add a penalty for that format
  33221. currentScore += getParsingFlags(tempConfig).charsLeftOver;
  33222. //or tokens
  33223. currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
  33224. getParsingFlags(tempConfig).score = currentScore;
  33225. if (scoreToBeat == null || currentScore < scoreToBeat) {
  33226. scoreToBeat = currentScore;
  33227. bestMoment = tempConfig;
  33228. }
  33229. }
  33230. extend(config, bestMoment || tempConfig);
  33231. }
  33232. function configFromObject(config) {
  33233. if (config._d) {
  33234. return;
  33235. }
  33236. var i = normalizeObjectUnits(config._i);
  33237. config._a = map([i.year, i.month, i.day || i.date, i.hour, i.minute, i.second, i.millisecond], function (obj) {
  33238. return obj && parseInt(obj, 10);
  33239. });
  33240. configFromArray(config);
  33241. }
  33242. function createFromConfig (config) {
  33243. var res = new Moment(checkOverflow(prepareConfig(config)));
  33244. if (res._nextDay) {
  33245. // Adding is smart enough around DST
  33246. res.add(1, 'd');
  33247. res._nextDay = undefined;
  33248. }
  33249. return res;
  33250. }
  33251. function prepareConfig (config) {
  33252. var input = config._i,
  33253. format = config._f;
  33254. config._locale = config._locale || locale_locales__getLocale(config._l);
  33255. if (input === null || (format === undefined && input === '')) {
  33256. return valid__createInvalid({nullInput: true});
  33257. }
  33258. if (typeof input === 'string') {
  33259. config._i = input = config._locale.preparse(input);
  33260. }
  33261. if (isMoment(input)) {
  33262. return new Moment(checkOverflow(input));
  33263. } else if (isArray(format)) {
  33264. configFromStringAndArray(config);
  33265. } else if (format) {
  33266. configFromStringAndFormat(config);
  33267. } else if (isDate(input)) {
  33268. config._d = input;
  33269. } else {
  33270. configFromInput(config);
  33271. }
  33272. if (!valid__isValid(config)) {
  33273. config._d = null;
  33274. }
  33275. return config;
  33276. }
  33277. function configFromInput(config) {
  33278. var input = config._i;
  33279. if (input === undefined) {
  33280. config._d = new Date(utils_hooks__hooks.now());
  33281. } else if (isDate(input)) {
  33282. config._d = new Date(input.valueOf());
  33283. } else if (typeof input === 'string') {
  33284. configFromString(config);
  33285. } else if (isArray(input)) {
  33286. config._a = map(input.slice(0), function (obj) {
  33287. return parseInt(obj, 10);
  33288. });
  33289. configFromArray(config);
  33290. } else if (typeof(input) === 'object') {
  33291. configFromObject(config);
  33292. } else if (typeof(input) === 'number') {
  33293. // from milliseconds
  33294. config._d = new Date(input);
  33295. } else {
  33296. utils_hooks__hooks.createFromInputFallback(config);
  33297. }
  33298. }
  33299. function createLocalOrUTC (input, format, locale, strict, isUTC) {
  33300. var c = {};
  33301. if (typeof(locale) === 'boolean') {
  33302. strict = locale;
  33303. locale = undefined;
  33304. }
  33305. // object construction must be done this way.
  33306. // https://github.com/moment/moment/issues/1423
  33307. c._isAMomentObject = true;
  33308. c._useUTC = c._isUTC = isUTC;
  33309. c._l = locale;
  33310. c._i = input;
  33311. c._f = format;
  33312. c._strict = strict;
  33313. return createFromConfig(c);
  33314. }
  33315. function local__createLocal (input, format, locale, strict) {
  33316. return createLocalOrUTC(input, format, locale, strict, false);
  33317. }
  33318. var prototypeMin = deprecate(
  33319. 'moment().min is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548',
  33320. function () {
  33321. var other = local__createLocal.apply(null, arguments);
  33322. if (this.isValid() && other.isValid()) {
  33323. return other < this ? this : other;
  33324. } else {
  33325. return valid__createInvalid();
  33326. }
  33327. }
  33328. );
  33329. var prototypeMax = deprecate(
  33330. 'moment().max is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548',
  33331. function () {
  33332. var other = local__createLocal.apply(null, arguments);
  33333. if (this.isValid() && other.isValid()) {
  33334. return other > this ? this : other;
  33335. } else {
  33336. return valid__createInvalid();
  33337. }
  33338. }
  33339. );
  33340. // Pick a moment m from moments so that m[fn](other) is true for all
  33341. // other. This relies on the function fn to be transitive.
  33342. //
  33343. // moments should either be an array of moment objects or an array, whose
  33344. // first element is an array of moment objects.
  33345. function pickBy(fn, moments) {
  33346. var res, i;
  33347. if (moments.length === 1 && isArray(moments[0])) {
  33348. moments = moments[0];
  33349. }
  33350. if (!moments.length) {
  33351. return local__createLocal();
  33352. }
  33353. res = moments[0];
  33354. for (i = 1; i < moments.length; ++i) {
  33355. if (!moments[i].isValid() || moments[i][fn](res)) {
  33356. res = moments[i];
  33357. }
  33358. }
  33359. return res;
  33360. }
  33361. // TODO: Use [].sort instead?
  33362. function min () {
  33363. var args = [].slice.call(arguments, 0);
  33364. return pickBy('isBefore', args);
  33365. }
  33366. function max () {
  33367. var args = [].slice.call(arguments, 0);
  33368. return pickBy('isAfter', args);
  33369. }
  33370. var now = function () {
  33371. return Date.now ? Date.now() : +(new Date());
  33372. };
  33373. function Duration (duration) {
  33374. var normalizedInput = normalizeObjectUnits(duration),
  33375. years = normalizedInput.year || 0,
  33376. quarters = normalizedInput.quarter || 0,
  33377. months = normalizedInput.month || 0,
  33378. weeks = normalizedInput.week || 0,
  33379. days = normalizedInput.day || 0,
  33380. hours = normalizedInput.hour || 0,
  33381. minutes = normalizedInput.minute || 0,
  33382. seconds = normalizedInput.second || 0,
  33383. milliseconds = normalizedInput.millisecond || 0;
  33384. // representation for dateAddRemove
  33385. this._milliseconds = +milliseconds +
  33386. seconds * 1e3 + // 1000
  33387. minutes * 6e4 + // 1000 * 60
  33388. hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
  33389. // Because of dateAddRemove treats 24 hours as different from a
  33390. // day when working around DST, we need to store them separately
  33391. this._days = +days +
  33392. weeks * 7;
  33393. // It is impossible translate months into days without knowing
  33394. // which months you are are talking about, so we have to store
  33395. // it separately.
  33396. this._months = +months +
  33397. quarters * 3 +
  33398. years * 12;
  33399. this._data = {};
  33400. this._locale = locale_locales__getLocale();
  33401. this._bubble();
  33402. }
  33403. function isDuration (obj) {
  33404. return obj instanceof Duration;
  33405. }
  33406. // FORMATTING
  33407. function offset (token, separator) {
  33408. addFormatToken(token, 0, 0, function () {
  33409. var offset = this.utcOffset();
  33410. var sign = '+';
  33411. if (offset < 0) {
  33412. offset = -offset;
  33413. sign = '-';
  33414. }
  33415. return sign + zeroFill(~~(offset / 60), 2) + separator + zeroFill(~~(offset) % 60, 2);
  33416. });
  33417. }
  33418. offset('Z', ':');
  33419. offset('ZZ', '');
  33420. // PARSING
  33421. addRegexToken('Z', matchShortOffset);
  33422. addRegexToken('ZZ', matchShortOffset);
  33423. addParseToken(['Z', 'ZZ'], function (input, array, config) {
  33424. config._useUTC = true;
  33425. config._tzm = offsetFromString(matchShortOffset, input);
  33426. });
  33427. // HELPERS
  33428. // timezone chunker
  33429. // '+10:00' > ['10', '00']
  33430. // '-1530' > ['-15', '30']
  33431. var chunkOffset = /([\+\-]|\d\d)/gi;
  33432. function offsetFromString(matcher, string) {
  33433. var matches = ((string || '').match(matcher) || []);
  33434. var chunk = matches[matches.length - 1] || [];
  33435. var parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];
  33436. var minutes = +(parts[1] * 60) + toInt(parts[2]);
  33437. return parts[0] === '+' ? minutes : -minutes;
  33438. }
  33439. // Return a moment from input, that is local/utc/zone equivalent to model.
  33440. function cloneWithOffset(input, model) {
  33441. var res, diff;
  33442. if (model._isUTC) {
  33443. res = model.clone();
  33444. diff = (isMoment(input) || isDate(input) ? input.valueOf() : local__createLocal(input).valueOf()) - res.valueOf();
  33445. // Use low-level api, because this fn is low-level api.
  33446. res._d.setTime(res._d.valueOf() + diff);
  33447. utils_hooks__hooks.updateOffset(res, false);
  33448. return res;
  33449. } else {
  33450. return local__createLocal(input).local();
  33451. }
  33452. }
  33453. function getDateOffset (m) {
  33454. // On Firefox.24 Date#getTimezoneOffset returns a floating point.
  33455. // https://github.com/moment/moment/pull/1871
  33456. return -Math.round(m._d.getTimezoneOffset() / 15) * 15;
  33457. }
  33458. // HOOKS
  33459. // This function will be called whenever a moment is mutated.
  33460. // It is intended to keep the offset in sync with the timezone.
  33461. utils_hooks__hooks.updateOffset = function () {};
  33462. // MOMENTS
  33463. // keepLocalTime = true means only change the timezone, without
  33464. // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
  33465. // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
  33466. // +0200, so we adjust the time as needed, to be valid.
  33467. //
  33468. // Keeping the time actually adds/subtracts (one hour)
  33469. // from the actual represented time. That is why we call updateOffset
  33470. // a second time. In case it wants us to change the offset again
  33471. // _changeInProgress == true case, then we have to adjust, because
  33472. // there is no such time in the given timezone.
  33473. function getSetOffset (input, keepLocalTime) {
  33474. var offset = this._offset || 0,
  33475. localAdjust;
  33476. if (!this.isValid()) {
  33477. return input != null ? this : NaN;
  33478. }
  33479. if (input != null) {
  33480. if (typeof input === 'string') {
  33481. input = offsetFromString(matchShortOffset, input);
  33482. } else if (Math.abs(input) < 16) {
  33483. input = input * 60;
  33484. }
  33485. if (!this._isUTC && keepLocalTime) {
  33486. localAdjust = getDateOffset(this);
  33487. }
  33488. this._offset = input;
  33489. this._isUTC = true;
  33490. if (localAdjust != null) {
  33491. this.add(localAdjust, 'm');
  33492. }
  33493. if (offset !== input) {
  33494. if (!keepLocalTime || this._changeInProgress) {
  33495. add_subtract__addSubtract(this, create__createDuration(input - offset, 'm'), 1, false);
  33496. } else if (!this._changeInProgress) {
  33497. this._changeInProgress = true;
  33498. utils_hooks__hooks.updateOffset(this, true);
  33499. this._changeInProgress = null;
  33500. }
  33501. }
  33502. return this;
  33503. } else {
  33504. return this._isUTC ? offset : getDateOffset(this);
  33505. }
  33506. }
  33507. function getSetZone (input, keepLocalTime) {
  33508. if (input != null) {
  33509. if (typeof input !== 'string') {
  33510. input = -input;
  33511. }
  33512. this.utcOffset(input, keepLocalTime);
  33513. return this;
  33514. } else {
  33515. return -this.utcOffset();
  33516. }
  33517. }
  33518. function setOffsetToUTC (keepLocalTime) {
  33519. return this.utcOffset(0, keepLocalTime);
  33520. }
  33521. function setOffsetToLocal (keepLocalTime) {
  33522. if (this._isUTC) {
  33523. this.utcOffset(0, keepLocalTime);
  33524. this._isUTC = false;
  33525. if (keepLocalTime) {
  33526. this.subtract(getDateOffset(this), 'm');
  33527. }
  33528. }
  33529. return this;
  33530. }
  33531. function setOffsetToParsedOffset () {
  33532. if (this._tzm) {
  33533. this.utcOffset(this._tzm);
  33534. } else if (typeof this._i === 'string') {
  33535. this.utcOffset(offsetFromString(matchOffset, this._i));
  33536. }
  33537. return this;
  33538. }
  33539. function hasAlignedHourOffset (input) {
  33540. if (!this.isValid()) {
  33541. return false;
  33542. }
  33543. input = input ? local__createLocal(input).utcOffset() : 0;
  33544. return (this.utcOffset() - input) % 60 === 0;
  33545. }
  33546. function isDaylightSavingTime () {
  33547. return (
  33548. this.utcOffset() > this.clone().month(0).utcOffset() ||
  33549. this.utcOffset() > this.clone().month(5).utcOffset()
  33550. );
  33551. }
  33552. function isDaylightSavingTimeShifted () {
  33553. if (!isUndefined(this._isDSTShifted)) {
  33554. return this._isDSTShifted;
  33555. }
  33556. var c = {};
  33557. copyConfig(c, this);
  33558. c = prepareConfig(c);
  33559. if (c._a) {
  33560. var other = c._isUTC ? create_utc__createUTC(c._a) : local__createLocal(c._a);
  33561. this._isDSTShifted = this.isValid() &&
  33562. compareArrays(c._a, other.toArray()) > 0;
  33563. } else {
  33564. this._isDSTShifted = false;
  33565. }
  33566. return this._isDSTShifted;
  33567. }
  33568. function isLocal () {
  33569. return this.isValid() ? !this._isUTC : false;
  33570. }
  33571. function isUtcOffset () {
  33572. return this.isValid() ? this._isUTC : false;
  33573. }
  33574. function isUtc () {
  33575. return this.isValid() ? this._isUTC && this._offset === 0 : false;
  33576. }
  33577. // ASP.NET json date format regex
  33578. var aspNetRegex = /^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?\d*)?$/;
  33579. // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
  33580. // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
  33581. // and further modified to allow for strings containing both week and day
  33582. 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)?)?$/;
  33583. function create__createDuration (input, key) {
  33584. var duration = input,
  33585. // matching against regexp is expensive, do it on demand
  33586. match = null,
  33587. sign,
  33588. ret,
  33589. diffRes;
  33590. if (isDuration(input)) {
  33591. duration = {
  33592. ms : input._milliseconds,
  33593. d : input._days,
  33594. M : input._months
  33595. };
  33596. } else if (typeof input === 'number') {
  33597. duration = {};
  33598. if (key) {
  33599. duration[key] = input;
  33600. } else {
  33601. duration.milliseconds = input;
  33602. }
  33603. } else if (!!(match = aspNetRegex.exec(input))) {
  33604. sign = (match[1] === '-') ? -1 : 1;
  33605. duration = {
  33606. y : 0,
  33607. d : toInt(match[DATE]) * sign,
  33608. h : toInt(match[HOUR]) * sign,
  33609. m : toInt(match[MINUTE]) * sign,
  33610. s : toInt(match[SECOND]) * sign,
  33611. ms : toInt(match[MILLISECOND]) * sign
  33612. };
  33613. } else if (!!(match = isoRegex.exec(input))) {
  33614. sign = (match[1] === '-') ? -1 : 1;
  33615. duration = {
  33616. y : parseIso(match[2], sign),
  33617. M : parseIso(match[3], sign),
  33618. w : parseIso(match[4], sign),
  33619. d : parseIso(match[5], sign),
  33620. h : parseIso(match[6], sign),
  33621. m : parseIso(match[7], sign),
  33622. s : parseIso(match[8], sign)
  33623. };
  33624. } else if (duration == null) {// checks for null or undefined
  33625. duration = {};
  33626. } else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) {
  33627. diffRes = momentsDifference(local__createLocal(duration.from), local__createLocal(duration.to));
  33628. duration = {};
  33629. duration.ms = diffRes.milliseconds;
  33630. duration.M = diffRes.months;
  33631. }
  33632. ret = new Duration(duration);
  33633. if (isDuration(input) && hasOwnProp(input, '_locale')) {
  33634. ret._locale = input._locale;
  33635. }
  33636. return ret;
  33637. }
  33638. create__createDuration.fn = Duration.prototype;
  33639. function parseIso (inp, sign) {
  33640. // We'd normally use ~~inp for this, but unfortunately it also
  33641. // converts floats to ints.
  33642. // inp may be undefined, so careful calling replace on it.
  33643. var res = inp && parseFloat(inp.replace(',', '.'));
  33644. // apply sign while we're at it
  33645. return (isNaN(res) ? 0 : res) * sign;
  33646. }
  33647. function positiveMomentsDifference(base, other) {
  33648. var res = {milliseconds: 0, months: 0};
  33649. res.months = other.month() - base.month() +
  33650. (other.year() - base.year()) * 12;
  33651. if (base.clone().add(res.months, 'M').isAfter(other)) {
  33652. --res.months;
  33653. }
  33654. res.milliseconds = +other - +(base.clone().add(res.months, 'M'));
  33655. return res;
  33656. }
  33657. function momentsDifference(base, other) {
  33658. var res;
  33659. if (!(base.isValid() && other.isValid())) {
  33660. return {milliseconds: 0, months: 0};
  33661. }
  33662. other = cloneWithOffset(other, base);
  33663. if (base.isBefore(other)) {
  33664. res = positiveMomentsDifference(base, other);
  33665. } else {
  33666. res = positiveMomentsDifference(other, base);
  33667. res.milliseconds = -res.milliseconds;
  33668. res.months = -res.months;
  33669. }
  33670. return res;
  33671. }
  33672. function absRound (number) {
  33673. if (number < 0) {
  33674. return Math.round(-1 * number) * -1;
  33675. } else {
  33676. return Math.round(number);
  33677. }
  33678. }
  33679. // TODO: remove 'name' arg after deprecation is removed
  33680. function createAdder(direction, name) {
  33681. return function (val, period) {
  33682. var dur, tmp;
  33683. //invert the arguments, but complain about it
  33684. if (period !== null && !isNaN(+period)) {
  33685. deprecateSimple(name, 'moment().' + name + '(period, number) is deprecated. Please use moment().' + name + '(number, period).');
  33686. tmp = val; val = period; period = tmp;
  33687. }
  33688. val = typeof val === 'string' ? +val : val;
  33689. dur = create__createDuration(val, period);
  33690. add_subtract__addSubtract(this, dur, direction);
  33691. return this;
  33692. };
  33693. }
  33694. function add_subtract__addSubtract (mom, duration, isAdding, updateOffset) {
  33695. var milliseconds = duration._milliseconds,
  33696. days = absRound(duration._days),
  33697. months = absRound(duration._months);
  33698. if (!mom.isValid()) {
  33699. // No op
  33700. return;
  33701. }
  33702. updateOffset = updateOffset == null ? true : updateOffset;
  33703. if (milliseconds) {
  33704. mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding);
  33705. }
  33706. if (days) {
  33707. get_set__set(mom, 'Date', get_set__get(mom, 'Date') + days * isAdding);
  33708. }
  33709. if (months) {
  33710. setMonth(mom, get_set__get(mom, 'Month') + months * isAdding);
  33711. }
  33712. if (updateOffset) {
  33713. utils_hooks__hooks.updateOffset(mom, days || months);
  33714. }
  33715. }
  33716. var add_subtract__add = createAdder(1, 'add');
  33717. var add_subtract__subtract = createAdder(-1, 'subtract');
  33718. function moment_calendar__calendar (time, formats) {
  33719. // We want to compare the start of today, vs this.
  33720. // Getting start-of-today depends on whether we're local/utc/offset or not.
  33721. var now = time || local__createLocal(),
  33722. sod = cloneWithOffset(now, this).startOf('day'),
  33723. diff = this.diff(sod, 'days', true),
  33724. format = diff < -6 ? 'sameElse' :
  33725. diff < -1 ? 'lastWeek' :
  33726. diff < 0 ? 'lastDay' :
  33727. diff < 1 ? 'sameDay' :
  33728. diff < 2 ? 'nextDay' :
  33729. diff < 7 ? 'nextWeek' : 'sameElse';
  33730. var output = formats && (isFunction(formats[format]) ? formats[format]() : formats[format]);
  33731. return this.format(output || this.localeData().calendar(format, this, local__createLocal(now)));
  33732. }
  33733. function clone () {
  33734. return new Moment(this);
  33735. }
  33736. function isAfter (input, units) {
  33737. var localInput = isMoment(input) ? input : local__createLocal(input);
  33738. if (!(this.isValid() && localInput.isValid())) {
  33739. return false;
  33740. }
  33741. units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
  33742. if (units === 'millisecond') {
  33743. return this.valueOf() > localInput.valueOf();
  33744. } else {
  33745. return localInput.valueOf() < this.clone().startOf(units).valueOf();
  33746. }
  33747. }
  33748. function isBefore (input, units) {
  33749. var localInput = isMoment(input) ? input : local__createLocal(input);
  33750. if (!(this.isValid() && localInput.isValid())) {
  33751. return false;
  33752. }
  33753. units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
  33754. if (units === 'millisecond') {
  33755. return this.valueOf() < localInput.valueOf();
  33756. } else {
  33757. return this.clone().endOf(units).valueOf() < localInput.valueOf();
  33758. }
  33759. }
  33760. function isBetween (from, to, units, inclusivity) {
  33761. inclusivity = inclusivity || '()';
  33762. return (inclusivity[0] === '(' ? this.isAfter(from, units) : !this.isBefore(from, units)) &&
  33763. (inclusivity[1] === ')' ? this.isBefore(to, units) : !this.isAfter(to, units));
  33764. }
  33765. function isSame (input, units) {
  33766. var localInput = isMoment(input) ? input : local__createLocal(input),
  33767. inputMs;
  33768. if (!(this.isValid() && localInput.isValid())) {
  33769. return false;
  33770. }
  33771. units = normalizeUnits(units || 'millisecond');
  33772. if (units === 'millisecond') {
  33773. return this.valueOf() === localInput.valueOf();
  33774. } else {
  33775. inputMs = localInput.valueOf();
  33776. return this.clone().startOf(units).valueOf() <= inputMs && inputMs <= this.clone().endOf(units).valueOf();
  33777. }
  33778. }
  33779. function isSameOrAfter (input, units) {
  33780. return this.isSame(input, units) || this.isAfter(input,units);
  33781. }
  33782. function isSameOrBefore (input, units) {
  33783. return this.isSame(input, units) || this.isBefore(input,units);
  33784. }
  33785. function diff (input, units, asFloat) {
  33786. var that,
  33787. zoneDelta,
  33788. delta, output;
  33789. if (!this.isValid()) {
  33790. return NaN;
  33791. }
  33792. that = cloneWithOffset(input, this);
  33793. if (!that.isValid()) {
  33794. return NaN;
  33795. }
  33796. zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
  33797. units = normalizeUnits(units);
  33798. if (units === 'year' || units === 'month' || units === 'quarter') {
  33799. output = monthDiff(this, that);
  33800. if (units === 'quarter') {
  33801. output = output / 3;
  33802. } else if (units === 'year') {
  33803. output = output / 12;
  33804. }
  33805. } else {
  33806. delta = this - that;
  33807. output = units === 'second' ? delta / 1e3 : // 1000
  33808. units === 'minute' ? delta / 6e4 : // 1000 * 60
  33809. units === 'hour' ? delta / 36e5 : // 1000 * 60 * 60
  33810. units === 'day' ? (delta - zoneDelta) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
  33811. units === 'week' ? (delta - zoneDelta) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
  33812. delta;
  33813. }
  33814. return asFloat ? output : absFloor(output);
  33815. }
  33816. function monthDiff (a, b) {
  33817. // difference in months
  33818. var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()),
  33819. // b is in (anchor - 1 month, anchor + 1 month)
  33820. anchor = a.clone().add(wholeMonthDiff, 'months'),
  33821. anchor2, adjust;
  33822. if (b - anchor < 0) {
  33823. anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
  33824. // linear across the month
  33825. adjust = (b - anchor) / (anchor - anchor2);
  33826. } else {
  33827. anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
  33828. // linear across the month
  33829. adjust = (b - anchor) / (anchor2 - anchor);
  33830. }
  33831. //check for negative zero, return zero if negative zero
  33832. return -(wholeMonthDiff + adjust) || 0;
  33833. }
  33834. utils_hooks__hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
  33835. utils_hooks__hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]';
  33836. function toString () {
  33837. return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
  33838. }
  33839. function moment_format__toISOString () {
  33840. var m = this.clone().utc();
  33841. if (0 < m.year() && m.year() <= 9999) {
  33842. if (isFunction(Date.prototype.toISOString)) {
  33843. // native implementation is ~50x faster, use it when we can
  33844. return this.toDate().toISOString();
  33845. } else {
  33846. return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
  33847. }
  33848. } else {
  33849. return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
  33850. }
  33851. }
  33852. function format (inputString) {
  33853. if (!inputString) {
  33854. inputString = this.isUtc() ? utils_hooks__hooks.defaultFormatUtc : utils_hooks__hooks.defaultFormat;
  33855. }
  33856. var output = formatMoment(this, inputString);
  33857. return this.localeData().postformat(output);
  33858. }
  33859. function from (time, withoutSuffix) {
  33860. if (this.isValid() &&
  33861. ((isMoment(time) && time.isValid()) ||
  33862. local__createLocal(time).isValid())) {
  33863. return create__createDuration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);
  33864. } else {
  33865. return this.localeData().invalidDate();
  33866. }
  33867. }
  33868. function fromNow (withoutSuffix) {
  33869. return this.from(local__createLocal(), withoutSuffix);
  33870. }
  33871. function to (time, withoutSuffix) {
  33872. if (this.isValid() &&
  33873. ((isMoment(time) && time.isValid()) ||
  33874. local__createLocal(time).isValid())) {
  33875. return create__createDuration({from: this, to: time}).locale(this.locale()).humanize(!withoutSuffix);
  33876. } else {
  33877. return this.localeData().invalidDate();
  33878. }
  33879. }
  33880. function toNow (withoutSuffix) {
  33881. return this.to(local__createLocal(), withoutSuffix);
  33882. }
  33883. // If passed a locale key, it will set the locale for this
  33884. // instance. Otherwise, it will return the locale configuration
  33885. // variables for this instance.
  33886. function locale (key) {
  33887. var newLocaleData;
  33888. if (key === undefined) {
  33889. return this._locale._abbr;
  33890. } else {
  33891. newLocaleData = locale_locales__getLocale(key);
  33892. if (newLocaleData != null) {
  33893. this._locale = newLocaleData;
  33894. }
  33895. return this;
  33896. }
  33897. }
  33898. var lang = deprecate(
  33899. 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
  33900. function (key) {
  33901. if (key === undefined) {
  33902. return this.localeData();
  33903. } else {
  33904. return this.locale(key);
  33905. }
  33906. }
  33907. );
  33908. function localeData () {
  33909. return this._locale;
  33910. }
  33911. function startOf (units) {
  33912. units = normalizeUnits(units);
  33913. // the following switch intentionally omits break keywords
  33914. // to utilize falling through the cases.
  33915. switch (units) {
  33916. case 'year':
  33917. this.month(0);
  33918. /* falls through */
  33919. case 'quarter':
  33920. case 'month':
  33921. this.date(1);
  33922. /* falls through */
  33923. case 'week':
  33924. case 'isoWeek':
  33925. case 'day':
  33926. case 'date':
  33927. this.hours(0);
  33928. /* falls through */
  33929. case 'hour':
  33930. this.minutes(0);
  33931. /* falls through */
  33932. case 'minute':
  33933. this.seconds(0);
  33934. /* falls through */
  33935. case 'second':
  33936. this.milliseconds(0);
  33937. }
  33938. // weeks are a special case
  33939. if (units === 'week') {
  33940. this.weekday(0);
  33941. }
  33942. if (units === 'isoWeek') {
  33943. this.isoWeekday(1);
  33944. }
  33945. // quarters are also special
  33946. if (units === 'quarter') {
  33947. this.month(Math.floor(this.month() / 3) * 3);
  33948. }
  33949. return this;
  33950. }
  33951. function endOf (units) {
  33952. units = normalizeUnits(units);
  33953. if (units === undefined || units === 'millisecond') {
  33954. return this;
  33955. }
  33956. // 'date' is an alias for 'day', so it should be considered as such.
  33957. if (units === 'date') {
  33958. units = 'day';
  33959. }
  33960. return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
  33961. }
  33962. function to_type__valueOf () {
  33963. return this._d.valueOf() - ((this._offset || 0) * 60000);
  33964. }
  33965. function unix () {
  33966. return Math.floor(this.valueOf() / 1000);
  33967. }
  33968. function toDate () {
  33969. return this._offset ? new Date(this.valueOf()) : this._d;
  33970. }
  33971. function toArray () {
  33972. var m = this;
  33973. return [m.year(), m.month(), m.date(), m.hour(), m.minute(), m.second(), m.millisecond()];
  33974. }
  33975. function toObject () {
  33976. var m = this;
  33977. return {
  33978. years: m.year(),
  33979. months: m.month(),
  33980. date: m.date(),
  33981. hours: m.hours(),
  33982. minutes: m.minutes(),
  33983. seconds: m.seconds(),
  33984. milliseconds: m.milliseconds()
  33985. };
  33986. }
  33987. function toJSON () {
  33988. // new Date(NaN).toJSON() === null
  33989. return this.isValid() ? this.toISOString() : null;
  33990. }
  33991. function moment_valid__isValid () {
  33992. return valid__isValid(this);
  33993. }
  33994. function parsingFlags () {
  33995. return extend({}, getParsingFlags(this));
  33996. }
  33997. function invalidAt () {
  33998. return getParsingFlags(this).overflow;
  33999. }
  34000. function creationData() {
  34001. return {
  34002. input: this._i,
  34003. format: this._f,
  34004. locale: this._locale,
  34005. isUTC: this._isUTC,
  34006. strict: this._strict
  34007. };
  34008. }
  34009. // FORMATTING
  34010. addFormatToken(0, ['gg', 2], 0, function () {
  34011. return this.weekYear() % 100;
  34012. });
  34013. addFormatToken(0, ['GG', 2], 0, function () {
  34014. return this.isoWeekYear() % 100;
  34015. });
  34016. function addWeekYearFormatToken (token, getter) {
  34017. addFormatToken(0, [token, token.length], 0, getter);
  34018. }
  34019. addWeekYearFormatToken('gggg', 'weekYear');
  34020. addWeekYearFormatToken('ggggg', 'weekYear');
  34021. addWeekYearFormatToken('GGGG', 'isoWeekYear');
  34022. addWeekYearFormatToken('GGGGG', 'isoWeekYear');
  34023. // ALIASES
  34024. addUnitAlias('weekYear', 'gg');
  34025. addUnitAlias('isoWeekYear', 'GG');
  34026. // PARSING
  34027. addRegexToken('G', matchSigned);
  34028. addRegexToken('g', matchSigned);
  34029. addRegexToken('GG', match1to2, match2);
  34030. addRegexToken('gg', match1to2, match2);
  34031. addRegexToken('GGGG', match1to4, match4);
  34032. addRegexToken('gggg', match1to4, match4);
  34033. addRegexToken('GGGGG', match1to6, match6);
  34034. addRegexToken('ggggg', match1to6, match6);
  34035. addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input, week, config, token) {
  34036. week[token.substr(0, 2)] = toInt(input);
  34037. });
  34038. addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
  34039. week[token] = utils_hooks__hooks.parseTwoDigitYear(input);
  34040. });
  34041. // MOMENTS
  34042. function getSetWeekYear (input) {
  34043. return getSetWeekYearHelper.call(this,
  34044. input,
  34045. this.week(),
  34046. this.weekday(),
  34047. this.localeData()._week.dow,
  34048. this.localeData()._week.doy);
  34049. }
  34050. function getSetISOWeekYear (input) {
  34051. return getSetWeekYearHelper.call(this,
  34052. input, this.isoWeek(), this.isoWeekday(), 1, 4);
  34053. }
  34054. function getISOWeeksInYear () {
  34055. return weeksInYear(this.year(), 1, 4);
  34056. }
  34057. function getWeeksInYear () {
  34058. var weekInfo = this.localeData()._week;
  34059. return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
  34060. }
  34061. function getSetWeekYearHelper(input, week, weekday, dow, doy) {
  34062. var weeksTarget;
  34063. if (input == null) {
  34064. return weekOfYear(this, dow, doy).year;
  34065. } else {
  34066. weeksTarget = weeksInYear(input, dow, doy);
  34067. if (week > weeksTarget) {
  34068. week = weeksTarget;
  34069. }
  34070. return setWeekAll.call(this, input, week, weekday, dow, doy);
  34071. }
  34072. }
  34073. function setWeekAll(weekYear, week, weekday, dow, doy) {
  34074. var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy),
  34075. date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear);
  34076. this.year(date.getUTCFullYear());
  34077. this.month(date.getUTCMonth());
  34078. this.date(date.getUTCDate());
  34079. return this;
  34080. }
  34081. // FORMATTING
  34082. addFormatToken('Q', 0, 'Qo', 'quarter');
  34083. // ALIASES
  34084. addUnitAlias('quarter', 'Q');
  34085. // PARSING
  34086. addRegexToken('Q', match1);
  34087. addParseToken('Q', function (input, array) {
  34088. array[MONTH] = (toInt(input) - 1) * 3;
  34089. });
  34090. // MOMENTS
  34091. function getSetQuarter (input) {
  34092. return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);
  34093. }
  34094. // FORMATTING
  34095. addFormatToken('w', ['ww', 2], 'wo', 'week');
  34096. addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
  34097. // ALIASES
  34098. addUnitAlias('week', 'w');
  34099. addUnitAlias('isoWeek', 'W');
  34100. // PARSING
  34101. addRegexToken('w', match1to2);
  34102. addRegexToken('ww', match1to2, match2);
  34103. addRegexToken('W', match1to2);
  34104. addRegexToken('WW', match1to2, match2);
  34105. addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) {
  34106. week[token.substr(0, 1)] = toInt(input);
  34107. });
  34108. // HELPERS
  34109. // LOCALES
  34110. function localeWeek (mom) {
  34111. return weekOfYear(mom, this._week.dow, this._week.doy).week;
  34112. }
  34113. var defaultLocaleWeek = {
  34114. dow : 0, // Sunday is the first day of the week.
  34115. doy : 6 // The week that contains Jan 1st is the first week of the year.
  34116. };
  34117. function localeFirstDayOfWeek () {
  34118. return this._week.dow;
  34119. }
  34120. function localeFirstDayOfYear () {
  34121. return this._week.doy;
  34122. }
  34123. // MOMENTS
  34124. function getSetWeek (input) {
  34125. var week = this.localeData().week(this);
  34126. return input == null ? week : this.add((input - week) * 7, 'd');
  34127. }
  34128. function getSetISOWeek (input) {
  34129. var week = weekOfYear(this, 1, 4).week;
  34130. return input == null ? week : this.add((input - week) * 7, 'd');
  34131. }
  34132. // FORMATTING
  34133. addFormatToken('D', ['DD', 2], 'Do', 'date');
  34134. // ALIASES
  34135. addUnitAlias('date', 'D');
  34136. // PARSING
  34137. addRegexToken('D', match1to2);
  34138. addRegexToken('DD', match1to2, match2);
  34139. addRegexToken('Do', function (isStrict, locale) {
  34140. return isStrict ? locale._ordinalParse : locale._ordinalParseLenient;
  34141. });
  34142. addParseToken(['D', 'DD'], DATE);
  34143. addParseToken('Do', function (input, array) {
  34144. array[DATE] = toInt(input.match(match1to2)[0], 10);
  34145. });
  34146. // MOMENTS
  34147. var getSetDayOfMonth = makeGetSet('Date', true);
  34148. // FORMATTING
  34149. addFormatToken('d', 0, 'do', 'day');
  34150. addFormatToken('dd', 0, 0, function (format) {
  34151. return this.localeData().weekdaysMin(this, format);
  34152. });
  34153. addFormatToken('ddd', 0, 0, function (format) {
  34154. return this.localeData().weekdaysShort(this, format);
  34155. });
  34156. addFormatToken('dddd', 0, 0, function (format) {
  34157. return this.localeData().weekdays(this, format);
  34158. });
  34159. addFormatToken('e', 0, 0, 'weekday');
  34160. addFormatToken('E', 0, 0, 'isoWeekday');
  34161. // ALIASES
  34162. addUnitAlias('day', 'd');
  34163. addUnitAlias('weekday', 'e');
  34164. addUnitAlias('isoWeekday', 'E');
  34165. // PARSING
  34166. addRegexToken('d', match1to2);
  34167. addRegexToken('e', match1to2);
  34168. addRegexToken('E', match1to2);
  34169. addRegexToken('dd', function (isStrict, locale) {
  34170. return locale.weekdaysMinRegex(isStrict);
  34171. });
  34172. addRegexToken('ddd', function (isStrict, locale) {
  34173. return locale.weekdaysShortRegex(isStrict);
  34174. });
  34175. addRegexToken('dddd', function (isStrict, locale) {
  34176. return locale.weekdaysRegex(isStrict);
  34177. });
  34178. addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) {
  34179. var weekday = config._locale.weekdaysParse(input, token, config._strict);
  34180. // if we didn't get a weekday name, mark the date as invalid
  34181. if (weekday != null) {
  34182. week.d = weekday;
  34183. } else {
  34184. getParsingFlags(config).invalidWeekday = input;
  34185. }
  34186. });
  34187. addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) {
  34188. week[token] = toInt(input);
  34189. });
  34190. // HELPERS
  34191. function parseWeekday(input, locale) {
  34192. if (typeof input !== 'string') {
  34193. return input;
  34194. }
  34195. if (!isNaN(input)) {
  34196. return parseInt(input, 10);
  34197. }
  34198. input = locale.weekdaysParse(input);
  34199. if (typeof input === 'number') {
  34200. return input;
  34201. }
  34202. return null;
  34203. }
  34204. // LOCALES
  34205. var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
  34206. function localeWeekdays (m, format) {
  34207. return isArray(this._weekdays) ? this._weekdays[m.day()] :
  34208. this._weekdays[this._weekdays.isFormat.test(format) ? 'format' : 'standalone'][m.day()];
  34209. }
  34210. var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
  34211. function localeWeekdaysShort (m) {
  34212. return this._weekdaysShort[m.day()];
  34213. }
  34214. var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
  34215. function localeWeekdaysMin (m) {
  34216. return this._weekdaysMin[m.day()];
  34217. }
  34218. function day_of_week__handleStrictParse(weekdayName, format, strict) {
  34219. var i, ii, mom, llc = weekdayName.toLocaleLowerCase();
  34220. if (!this._weekdaysParse) {
  34221. this._weekdaysParse = [];
  34222. this._shortWeekdaysParse = [];
  34223. this._minWeekdaysParse = [];
  34224. for (i = 0; i < 7; ++i) {
  34225. mom = create_utc__createUTC([2000, 1]).day(i);
  34226. this._minWeekdaysParse[i] = this.weekdaysMin(mom, '').toLocaleLowerCase();
  34227. this._shortWeekdaysParse[i] = this.weekdaysShort(mom, '').toLocaleLowerCase();
  34228. this._weekdaysParse[i] = this.weekdays(mom, '').toLocaleLowerCase();
  34229. }
  34230. }
  34231. if (strict) {
  34232. if (format === 'dddd') {
  34233. ii = indexOf.call(this._weekdaysParse, llc);
  34234. return ii !== -1 ? ii : null;
  34235. } else if (format === 'ddd') {
  34236. ii = indexOf.call(this._shortWeekdaysParse, llc);
  34237. return ii !== -1 ? ii : null;
  34238. } else {
  34239. ii = indexOf.call(this._minWeekdaysParse, llc);
  34240. return ii !== -1 ? ii : null;
  34241. }
  34242. } else {
  34243. if (format === 'dddd') {
  34244. ii = indexOf.call(this._weekdaysParse, llc);
  34245. if (ii !== -1) {
  34246. return ii;
  34247. }
  34248. ii = indexOf.call(this._shortWeekdaysParse, llc);
  34249. if (ii !== -1) {
  34250. return ii;
  34251. }
  34252. ii = indexOf.call(this._minWeekdaysParse, llc);
  34253. return ii !== -1 ? ii : null;
  34254. } else if (format === 'ddd') {
  34255. ii = indexOf.call(this._shortWeekdaysParse, llc);
  34256. if (ii !== -1) {
  34257. return ii;
  34258. }
  34259. ii = indexOf.call(this._weekdaysParse, llc);
  34260. if (ii !== -1) {
  34261. return ii;
  34262. }
  34263. ii = indexOf.call(this._minWeekdaysParse, llc);
  34264. return ii !== -1 ? ii : null;
  34265. } else {
  34266. ii = indexOf.call(this._minWeekdaysParse, llc);
  34267. if (ii !== -1) {
  34268. return ii;
  34269. }
  34270. ii = indexOf.call(this._weekdaysParse, llc);
  34271. if (ii !== -1) {
  34272. return ii;
  34273. }
  34274. ii = indexOf.call(this._shortWeekdaysParse, llc);
  34275. return ii !== -1 ? ii : null;
  34276. }
  34277. }
  34278. }
  34279. function localeWeekdaysParse (weekdayName, format, strict) {
  34280. var i, mom, regex;
  34281. if (this._weekdaysParseExact) {
  34282. return day_of_week__handleStrictParse.call(this, weekdayName, format, strict);
  34283. }
  34284. if (!this._weekdaysParse) {
  34285. this._weekdaysParse = [];
  34286. this._minWeekdaysParse = [];
  34287. this._shortWeekdaysParse = [];
  34288. this._fullWeekdaysParse = [];
  34289. }
  34290. for (i = 0; i < 7; i++) {
  34291. // make the regex if we don't have it already
  34292. mom = create_utc__createUTC([2000, 1]).day(i);
  34293. if (strict && !this._fullWeekdaysParse[i]) {
  34294. this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\.?') + '$', 'i');
  34295. this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\.?') + '$', 'i');
  34296. this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\.?') + '$', 'i');
  34297. }
  34298. if (!this._weekdaysParse[i]) {
  34299. regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
  34300. this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
  34301. }
  34302. // test the regex
  34303. if (strict && format === 'dddd' && this._fullWeekdaysParse[i].test(weekdayName)) {
  34304. return i;
  34305. } else if (strict && format === 'ddd' && this._shortWeekdaysParse[i].test(weekdayName)) {
  34306. return i;
  34307. } else if (strict && format === 'dd' && this._minWeekdaysParse[i].test(weekdayName)) {
  34308. return i;
  34309. } else if (!strict && this._weekdaysParse[i].test(weekdayName)) {
  34310. return i;
  34311. }
  34312. }
  34313. }
  34314. // MOMENTS
  34315. function getSetDayOfWeek (input) {
  34316. if (!this.isValid()) {
  34317. return input != null ? this : NaN;
  34318. }
  34319. var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
  34320. if (input != null) {
  34321. input = parseWeekday(input, this.localeData());
  34322. return this.add(input - day, 'd');
  34323. } else {
  34324. return day;
  34325. }
  34326. }
  34327. function getSetLocaleDayOfWeek (input) {
  34328. if (!this.isValid()) {
  34329. return input != null ? this : NaN;
  34330. }
  34331. var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
  34332. return input == null ? weekday : this.add(input - weekday, 'd');
  34333. }
  34334. function getSetISODayOfWeek (input) {
  34335. if (!this.isValid()) {
  34336. return input != null ? this : NaN;
  34337. }
  34338. // behaves the same as moment#day except
  34339. // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
  34340. // as a setter, sunday should belong to the previous week.
  34341. return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7);
  34342. }
  34343. var defaultWeekdaysRegex = matchWord;
  34344. function weekdaysRegex (isStrict) {
  34345. if (this._weekdaysParseExact) {
  34346. if (!hasOwnProp(this, '_weekdaysRegex')) {
  34347. computeWeekdaysParse.call(this);
  34348. }
  34349. if (isStrict) {
  34350. return this._weekdaysStrictRegex;
  34351. } else {
  34352. return this._weekdaysRegex;
  34353. }
  34354. } else {
  34355. return this._weekdaysStrictRegex && isStrict ?
  34356. this._weekdaysStrictRegex : this._weekdaysRegex;
  34357. }
  34358. }
  34359. var defaultWeekdaysShortRegex = matchWord;
  34360. function weekdaysShortRegex (isStrict) {
  34361. if (this._weekdaysParseExact) {
  34362. if (!hasOwnProp(this, '_weekdaysRegex')) {
  34363. computeWeekdaysParse.call(this);
  34364. }
  34365. if (isStrict) {
  34366. return this._weekdaysShortStrictRegex;
  34367. } else {
  34368. return this._weekdaysShortRegex;
  34369. }
  34370. } else {
  34371. return this._weekdaysShortStrictRegex && isStrict ?
  34372. this._weekdaysShortStrictRegex : this._weekdaysShortRegex;
  34373. }
  34374. }
  34375. var defaultWeekdaysMinRegex = matchWord;
  34376. function weekdaysMinRegex (isStrict) {
  34377. if (this._weekdaysParseExact) {
  34378. if (!hasOwnProp(this, '_weekdaysRegex')) {
  34379. computeWeekdaysParse.call(this);
  34380. }
  34381. if (isStrict) {
  34382. return this._weekdaysMinStrictRegex;
  34383. } else {
  34384. return this._weekdaysMinRegex;
  34385. }
  34386. } else {
  34387. return this._weekdaysMinStrictRegex && isStrict ?
  34388. this._weekdaysMinStrictRegex : this._weekdaysMinRegex;
  34389. }
  34390. }
  34391. function computeWeekdaysParse () {
  34392. function cmpLenRev(a, b) {
  34393. return b.length - a.length;
  34394. }
  34395. var minPieces = [], shortPieces = [], longPieces = [], mixedPieces = [],
  34396. i, mom, minp, shortp, longp;
  34397. for (i = 0; i < 7; i++) {
  34398. // make the regex if we don't have it already
  34399. mom = create_utc__createUTC([2000, 1]).day(i);
  34400. minp = this.weekdaysMin(mom, '');
  34401. shortp = this.weekdaysShort(mom, '');
  34402. longp = this.weekdays(mom, '');
  34403. minPieces.push(minp);
  34404. shortPieces.push(shortp);
  34405. longPieces.push(longp);
  34406. mixedPieces.push(minp);
  34407. mixedPieces.push(shortp);
  34408. mixedPieces.push(longp);
  34409. }
  34410. // Sorting makes sure if one weekday (or abbr) is a prefix of another it
  34411. // will match the longer piece.
  34412. minPieces.sort(cmpLenRev);
  34413. shortPieces.sort(cmpLenRev);
  34414. longPieces.sort(cmpLenRev);
  34415. mixedPieces.sort(cmpLenRev);
  34416. for (i = 0; i < 7; i++) {
  34417. shortPieces[i] = regexEscape(shortPieces[i]);
  34418. longPieces[i] = regexEscape(longPieces[i]);
  34419. mixedPieces[i] = regexEscape(mixedPieces[i]);
  34420. }
  34421. this._weekdaysRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
  34422. this._weekdaysShortRegex = this._weekdaysRegex;
  34423. this._weekdaysMinRegex = this._weekdaysRegex;
  34424. this._weekdaysStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
  34425. this._weekdaysShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
  34426. this._weekdaysMinStrictRegex = new RegExp('^(' + minPieces.join('|') + ')', 'i');
  34427. }
  34428. // FORMATTING
  34429. addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
  34430. // ALIASES
  34431. addUnitAlias('dayOfYear', 'DDD');
  34432. // PARSING
  34433. addRegexToken('DDD', match1to3);
  34434. addRegexToken('DDDD', match3);
  34435. addParseToken(['DDD', 'DDDD'], function (input, array, config) {
  34436. config._dayOfYear = toInt(input);
  34437. });
  34438. // HELPERS
  34439. // MOMENTS
  34440. function getSetDayOfYear (input) {
  34441. var dayOfYear = Math.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5) + 1;
  34442. return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
  34443. }
  34444. // FORMATTING
  34445. function hFormat() {
  34446. return this.hours() % 12 || 12;
  34447. }
  34448. function kFormat() {
  34449. return this.hours() || 24;
  34450. }
  34451. addFormatToken('H', ['HH', 2], 0, 'hour');
  34452. addFormatToken('h', ['hh', 2], 0, hFormat);
  34453. addFormatToken('k', ['kk', 2], 0, kFormat);
  34454. addFormatToken('hmm', 0, 0, function () {
  34455. return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2);
  34456. });
  34457. addFormatToken('hmmss', 0, 0, function () {
  34458. return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2) +
  34459. zeroFill(this.seconds(), 2);
  34460. });
  34461. addFormatToken('Hmm', 0, 0, function () {
  34462. return '' + this.hours() + zeroFill(this.minutes(), 2);
  34463. });
  34464. addFormatToken('Hmmss', 0, 0, function () {
  34465. return '' + this.hours() + zeroFill(this.minutes(), 2) +
  34466. zeroFill(this.seconds(), 2);
  34467. });
  34468. function meridiem (token, lowercase) {
  34469. addFormatToken(token, 0, 0, function () {
  34470. return this.localeData().meridiem(this.hours(), this.minutes(), lowercase);
  34471. });
  34472. }
  34473. meridiem('a', true);
  34474. meridiem('A', false);
  34475. // ALIASES
  34476. addUnitAlias('hour', 'h');
  34477. // PARSING
  34478. function matchMeridiem (isStrict, locale) {
  34479. return locale._meridiemParse;
  34480. }
  34481. addRegexToken('a', matchMeridiem);
  34482. addRegexToken('A', matchMeridiem);
  34483. addRegexToken('H', match1to2);
  34484. addRegexToken('h', match1to2);
  34485. addRegexToken('HH', match1to2, match2);
  34486. addRegexToken('hh', match1to2, match2);
  34487. addRegexToken('hmm', match3to4);
  34488. addRegexToken('hmmss', match5to6);
  34489. addRegexToken('Hmm', match3to4);
  34490. addRegexToken('Hmmss', match5to6);
  34491. addParseToken(['H', 'HH'], HOUR);
  34492. addParseToken(['a', 'A'], function (input, array, config) {
  34493. config._isPm = config._locale.isPM(input);
  34494. config._meridiem = input;
  34495. });
  34496. addParseToken(['h', 'hh'], function (input, array, config) {
  34497. array[HOUR] = toInt(input);
  34498. getParsingFlags(config).bigHour = true;
  34499. });
  34500. addParseToken('hmm', function (input, array, config) {
  34501. var pos = input.length - 2;
  34502. array[HOUR] = toInt(input.substr(0, pos));
  34503. array[MINUTE] = toInt(input.substr(pos));
  34504. getParsingFlags(config).bigHour = true;
  34505. });
  34506. addParseToken('hmmss', function (input, array, config) {
  34507. var pos1 = input.length - 4;
  34508. var pos2 = input.length - 2;
  34509. array[HOUR] = toInt(input.substr(0, pos1));
  34510. array[MINUTE] = toInt(input.substr(pos1, 2));
  34511. array[SECOND] = toInt(input.substr(pos2));
  34512. getParsingFlags(config).bigHour = true;
  34513. });
  34514. addParseToken('Hmm', function (input, array, config) {
  34515. var pos = input.length - 2;
  34516. array[HOUR] = toInt(input.substr(0, pos));
  34517. array[MINUTE] = toInt(input.substr(pos));
  34518. });
  34519. addParseToken('Hmmss', function (input, array, config) {
  34520. var pos1 = input.length - 4;
  34521. var pos2 = input.length - 2;
  34522. array[HOUR] = toInt(input.substr(0, pos1));
  34523. array[MINUTE] = toInt(input.substr(pos1, 2));
  34524. array[SECOND] = toInt(input.substr(pos2));
  34525. });
  34526. // LOCALES
  34527. function localeIsPM (input) {
  34528. // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
  34529. // Using charAt should be more compatible.
  34530. return ((input + '').toLowerCase().charAt(0) === 'p');
  34531. }
  34532. var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i;
  34533. function localeMeridiem (hours, minutes, isLower) {
  34534. if (hours > 11) {
  34535. return isLower ? 'pm' : 'PM';
  34536. } else {
  34537. return isLower ? 'am' : 'AM';
  34538. }
  34539. }
  34540. // MOMENTS
  34541. // Setting the hour should keep the time, because the user explicitly
  34542. // specified which hour he wants. So trying to maintain the same hour (in
  34543. // a new timezone) makes sense. Adding/subtracting hours does not follow
  34544. // this rule.
  34545. var getSetHour = makeGetSet('Hours', true);
  34546. // FORMATTING
  34547. addFormatToken('m', ['mm', 2], 0, 'minute');
  34548. // ALIASES
  34549. addUnitAlias('minute', 'm');
  34550. // PARSING
  34551. addRegexToken('m', match1to2);
  34552. addRegexToken('mm', match1to2, match2);
  34553. addParseToken(['m', 'mm'], MINUTE);
  34554. // MOMENTS
  34555. var getSetMinute = makeGetSet('Minutes', false);
  34556. // FORMATTING
  34557. addFormatToken('s', ['ss', 2], 0, 'second');
  34558. // ALIASES
  34559. addUnitAlias('second', 's');
  34560. // PARSING
  34561. addRegexToken('s', match1to2);
  34562. addRegexToken('ss', match1to2, match2);
  34563. addParseToken(['s', 'ss'], SECOND);
  34564. // MOMENTS
  34565. var getSetSecond = makeGetSet('Seconds', false);
  34566. // FORMATTING
  34567. addFormatToken('S', 0, 0, function () {
  34568. return ~~(this.millisecond() / 100);
  34569. });
  34570. addFormatToken(0, ['SS', 2], 0, function () {
  34571. return ~~(this.millisecond() / 10);
  34572. });
  34573. addFormatToken(0, ['SSS', 3], 0, 'millisecond');
  34574. addFormatToken(0, ['SSSS', 4], 0, function () {
  34575. return this.millisecond() * 10;
  34576. });
  34577. addFormatToken(0, ['SSSSS', 5], 0, function () {
  34578. return this.millisecond() * 100;
  34579. });
  34580. addFormatToken(0, ['SSSSSS', 6], 0, function () {
  34581. return this.millisecond() * 1000;
  34582. });
  34583. addFormatToken(0, ['SSSSSSS', 7], 0, function () {
  34584. return this.millisecond() * 10000;
  34585. });
  34586. addFormatToken(0, ['SSSSSSSS', 8], 0, function () {
  34587. return this.millisecond() * 100000;
  34588. });
  34589. addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
  34590. return this.millisecond() * 1000000;
  34591. });
  34592. // ALIASES
  34593. addUnitAlias('millisecond', 'ms');
  34594. // PARSING
  34595. addRegexToken('S', match1to3, match1);
  34596. addRegexToken('SS', match1to3, match2);
  34597. addRegexToken('SSS', match1to3, match3);
  34598. var token;
  34599. for (token = 'SSSS'; token.length <= 9; token += 'S') {
  34600. addRegexToken(token, matchUnsigned);
  34601. }
  34602. function parseMs(input, array) {
  34603. array[MILLISECOND] = toInt(('0.' + input) * 1000);
  34604. }
  34605. for (token = 'S'; token.length <= 9; token += 'S') {
  34606. addParseToken(token, parseMs);
  34607. }
  34608. // MOMENTS
  34609. var getSetMillisecond = makeGetSet('Milliseconds', false);
  34610. // FORMATTING
  34611. addFormatToken('z', 0, 0, 'zoneAbbr');
  34612. addFormatToken('zz', 0, 0, 'zoneName');
  34613. // MOMENTS
  34614. function getZoneAbbr () {
  34615. return this._isUTC ? 'UTC' : '';
  34616. }
  34617. function getZoneName () {
  34618. return this._isUTC ? 'Coordinated Universal Time' : '';
  34619. }
  34620. var momentPrototype__proto = Moment.prototype;
  34621. momentPrototype__proto.add = add_subtract__add;
  34622. momentPrototype__proto.calendar = moment_calendar__calendar;
  34623. momentPrototype__proto.clone = clone;
  34624. momentPrototype__proto.diff = diff;
  34625. momentPrototype__proto.endOf = endOf;
  34626. momentPrototype__proto.format = format;
  34627. momentPrototype__proto.from = from;
  34628. momentPrototype__proto.fromNow = fromNow;
  34629. momentPrototype__proto.to = to;
  34630. momentPrototype__proto.toNow = toNow;
  34631. momentPrototype__proto.get = getSet;
  34632. momentPrototype__proto.invalidAt = invalidAt;
  34633. momentPrototype__proto.isAfter = isAfter;
  34634. momentPrototype__proto.isBefore = isBefore;
  34635. momentPrototype__proto.isBetween = isBetween;
  34636. momentPrototype__proto.isSame = isSame;
  34637. momentPrototype__proto.isSameOrAfter = isSameOrAfter;
  34638. momentPrototype__proto.isSameOrBefore = isSameOrBefore;
  34639. momentPrototype__proto.isValid = moment_valid__isValid;
  34640. momentPrototype__proto.lang = lang;
  34641. momentPrototype__proto.locale = locale;
  34642. momentPrototype__proto.localeData = localeData;
  34643. momentPrototype__proto.max = prototypeMax;
  34644. momentPrototype__proto.min = prototypeMin;
  34645. momentPrototype__proto.parsingFlags = parsingFlags;
  34646. momentPrototype__proto.set = getSet;
  34647. momentPrototype__proto.startOf = startOf;
  34648. momentPrototype__proto.subtract = add_subtract__subtract;
  34649. momentPrototype__proto.toArray = toArray;
  34650. momentPrototype__proto.toObject = toObject;
  34651. momentPrototype__proto.toDate = toDate;
  34652. momentPrototype__proto.toISOString = moment_format__toISOString;
  34653. momentPrototype__proto.toJSON = toJSON;
  34654. momentPrototype__proto.toString = toString;
  34655. momentPrototype__proto.unix = unix;
  34656. momentPrototype__proto.valueOf = to_type__valueOf;
  34657. momentPrototype__proto.creationData = creationData;
  34658. // Year
  34659. momentPrototype__proto.year = getSetYear;
  34660. momentPrototype__proto.isLeapYear = getIsLeapYear;
  34661. // Week Year
  34662. momentPrototype__proto.weekYear = getSetWeekYear;
  34663. momentPrototype__proto.isoWeekYear = getSetISOWeekYear;
  34664. // Quarter
  34665. momentPrototype__proto.quarter = momentPrototype__proto.quarters = getSetQuarter;
  34666. // Month
  34667. momentPrototype__proto.month = getSetMonth;
  34668. momentPrototype__proto.daysInMonth = getDaysInMonth;
  34669. // Week
  34670. momentPrototype__proto.week = momentPrototype__proto.weeks = getSetWeek;
  34671. momentPrototype__proto.isoWeek = momentPrototype__proto.isoWeeks = getSetISOWeek;
  34672. momentPrototype__proto.weeksInYear = getWeeksInYear;
  34673. momentPrototype__proto.isoWeeksInYear = getISOWeeksInYear;
  34674. // Day
  34675. momentPrototype__proto.date = getSetDayOfMonth;
  34676. momentPrototype__proto.day = momentPrototype__proto.days = getSetDayOfWeek;
  34677. momentPrototype__proto.weekday = getSetLocaleDayOfWeek;
  34678. momentPrototype__proto.isoWeekday = getSetISODayOfWeek;
  34679. momentPrototype__proto.dayOfYear = getSetDayOfYear;
  34680. // Hour
  34681. momentPrototype__proto.hour = momentPrototype__proto.hours = getSetHour;
  34682. // Minute
  34683. momentPrototype__proto.minute = momentPrototype__proto.minutes = getSetMinute;
  34684. // Second
  34685. momentPrototype__proto.second = momentPrototype__proto.seconds = getSetSecond;
  34686. // Millisecond
  34687. momentPrototype__proto.millisecond = momentPrototype__proto.milliseconds = getSetMillisecond;
  34688. // Offset
  34689. momentPrototype__proto.utcOffset = getSetOffset;
  34690. momentPrototype__proto.utc = setOffsetToUTC;
  34691. momentPrototype__proto.local = setOffsetToLocal;
  34692. momentPrototype__proto.parseZone = setOffsetToParsedOffset;
  34693. momentPrototype__proto.hasAlignedHourOffset = hasAlignedHourOffset;
  34694. momentPrototype__proto.isDST = isDaylightSavingTime;
  34695. momentPrototype__proto.isDSTShifted = isDaylightSavingTimeShifted;
  34696. momentPrototype__proto.isLocal = isLocal;
  34697. momentPrototype__proto.isUtcOffset = isUtcOffset;
  34698. momentPrototype__proto.isUtc = isUtc;
  34699. momentPrototype__proto.isUTC = isUtc;
  34700. // Timezone
  34701. momentPrototype__proto.zoneAbbr = getZoneAbbr;
  34702. momentPrototype__proto.zoneName = getZoneName;
  34703. // Deprecations
  34704. momentPrototype__proto.dates = deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth);
  34705. momentPrototype__proto.months = deprecate('months accessor is deprecated. Use month instead', getSetMonth);
  34706. momentPrototype__proto.years = deprecate('years accessor is deprecated. Use year instead', getSetYear);
  34707. momentPrototype__proto.zone = deprecate('moment().zone is deprecated, use moment().utcOffset instead. https://github.com/moment/moment/issues/1779', getSetZone);
  34708. var momentPrototype = momentPrototype__proto;
  34709. function moment__createUnix (input) {
  34710. return local__createLocal(input * 1000);
  34711. }
  34712. function moment__createInZone () {
  34713. return local__createLocal.apply(null, arguments).parseZone();
  34714. }
  34715. var defaultCalendar = {
  34716. sameDay : '[Today at] LT',
  34717. nextDay : '[Tomorrow at] LT',
  34718. nextWeek : 'dddd [at] LT',
  34719. lastDay : '[Yesterday at] LT',
  34720. lastWeek : '[Last] dddd [at] LT',
  34721. sameElse : 'L'
  34722. };
  34723. function locale_calendar__calendar (key, mom, now) {
  34724. var output = this._calendar[key];
  34725. return isFunction(output) ? output.call(mom, now) : output;
  34726. }
  34727. var defaultLongDateFormat = {
  34728. LTS : 'h:mm:ss A',
  34729. LT : 'h:mm A',
  34730. L : 'MM/DD/YYYY',
  34731. LL : 'MMMM D, YYYY',
  34732. LLL : 'MMMM D, YYYY h:mm A',
  34733. LLLL : 'dddd, MMMM D, YYYY h:mm A'
  34734. };
  34735. function longDateFormat (key) {
  34736. var format = this._longDateFormat[key],
  34737. formatUpper = this._longDateFormat[key.toUpperCase()];
  34738. if (format || !formatUpper) {
  34739. return format;
  34740. }
  34741. this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) {
  34742. return val.slice(1);
  34743. });
  34744. return this._longDateFormat[key];
  34745. }
  34746. var defaultInvalidDate = 'Invalid date';
  34747. function invalidDate () {
  34748. return this._invalidDate;
  34749. }
  34750. var defaultOrdinal = '%d';
  34751. var defaultOrdinalParse = /\d{1,2}/;
  34752. function ordinal (number) {
  34753. return this._ordinal.replace('%d', number);
  34754. }
  34755. function preParsePostFormat (string) {
  34756. return string;
  34757. }
  34758. var defaultRelativeTime = {
  34759. future : 'in %s',
  34760. past : '%s ago',
  34761. s : 'a few seconds',
  34762. m : 'a minute',
  34763. mm : '%d minutes',
  34764. h : 'an hour',
  34765. hh : '%d hours',
  34766. d : 'a day',
  34767. dd : '%d days',
  34768. M : 'a month',
  34769. MM : '%d months',
  34770. y : 'a year',
  34771. yy : '%d years'
  34772. };
  34773. function relative__relativeTime (number, withoutSuffix, string, isFuture) {
  34774. var output = this._relativeTime[string];
  34775. return (isFunction(output)) ?
  34776. output(number, withoutSuffix, string, isFuture) :
  34777. output.replace(/%d/i, number);
  34778. }
  34779. function pastFuture (diff, output) {
  34780. var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
  34781. return isFunction(format) ? format(output) : format.replace(/%s/i, output);
  34782. }
  34783. var prototype__proto = Locale.prototype;
  34784. prototype__proto._calendar = defaultCalendar;
  34785. prototype__proto.calendar = locale_calendar__calendar;
  34786. prototype__proto._longDateFormat = defaultLongDateFormat;
  34787. prototype__proto.longDateFormat = longDateFormat;
  34788. prototype__proto._invalidDate = defaultInvalidDate;
  34789. prototype__proto.invalidDate = invalidDate;
  34790. prototype__proto._ordinal = defaultOrdinal;
  34791. prototype__proto.ordinal = ordinal;
  34792. prototype__proto._ordinalParse = defaultOrdinalParse;
  34793. prototype__proto.preparse = preParsePostFormat;
  34794. prototype__proto.postformat = preParsePostFormat;
  34795. prototype__proto._relativeTime = defaultRelativeTime;
  34796. prototype__proto.relativeTime = relative__relativeTime;
  34797. prototype__proto.pastFuture = pastFuture;
  34798. prototype__proto.set = locale_set__set;
  34799. // Month
  34800. prototype__proto.months = localeMonths;
  34801. prototype__proto._months = defaultLocaleMonths;
  34802. prototype__proto.monthsShort = localeMonthsShort;
  34803. prototype__proto._monthsShort = defaultLocaleMonthsShort;
  34804. prototype__proto.monthsParse = localeMonthsParse;
  34805. prototype__proto._monthsRegex = defaultMonthsRegex;
  34806. prototype__proto.monthsRegex = monthsRegex;
  34807. prototype__proto._monthsShortRegex = defaultMonthsShortRegex;
  34808. prototype__proto.monthsShortRegex = monthsShortRegex;
  34809. // Week
  34810. prototype__proto.week = localeWeek;
  34811. prototype__proto._week = defaultLocaleWeek;
  34812. prototype__proto.firstDayOfYear = localeFirstDayOfYear;
  34813. prototype__proto.firstDayOfWeek = localeFirstDayOfWeek;
  34814. // Day of Week
  34815. prototype__proto.weekdays = localeWeekdays;
  34816. prototype__proto._weekdays = defaultLocaleWeekdays;
  34817. prototype__proto.weekdaysMin = localeWeekdaysMin;
  34818. prototype__proto._weekdaysMin = defaultLocaleWeekdaysMin;
  34819. prototype__proto.weekdaysShort = localeWeekdaysShort;
  34820. prototype__proto._weekdaysShort = defaultLocaleWeekdaysShort;
  34821. prototype__proto.weekdaysParse = localeWeekdaysParse;
  34822. prototype__proto._weekdaysRegex = defaultWeekdaysRegex;
  34823. prototype__proto.weekdaysRegex = weekdaysRegex;
  34824. prototype__proto._weekdaysShortRegex = defaultWeekdaysShortRegex;
  34825. prototype__proto.weekdaysShortRegex = weekdaysShortRegex;
  34826. prototype__proto._weekdaysMinRegex = defaultWeekdaysMinRegex;
  34827. prototype__proto.weekdaysMinRegex = weekdaysMinRegex;
  34828. // Hours
  34829. prototype__proto.isPM = localeIsPM;
  34830. prototype__proto._meridiemParse = defaultLocaleMeridiemParse;
  34831. prototype__proto.meridiem = localeMeridiem;
  34832. function lists__get (format, index, field, setter) {
  34833. var locale = locale_locales__getLocale();
  34834. var utc = create_utc__createUTC().set(setter, index);
  34835. return locale[field](utc, format);
  34836. }
  34837. function listMonthsImpl (format, index, field) {
  34838. if (typeof format === 'number') {
  34839. index = format;
  34840. format = undefined;
  34841. }
  34842. format = format || '';
  34843. if (index != null) {
  34844. return lists__get(format, index, field, 'month');
  34845. }
  34846. var i;
  34847. var out = [];
  34848. for (i = 0; i < 12; i++) {
  34849. out[i] = lists__get(format, i, field, 'month');
  34850. }
  34851. return out;
  34852. }
  34853. // ()
  34854. // (5)
  34855. // (fmt, 5)
  34856. // (fmt)
  34857. // (true)
  34858. // (true, 5)
  34859. // (true, fmt, 5)
  34860. // (true, fmt)
  34861. function listWeekdaysImpl (localeSorted, format, index, field) {
  34862. if (typeof localeSorted === 'boolean') {
  34863. if (typeof format === 'number') {
  34864. index = format;
  34865. format = undefined;
  34866. }
  34867. format = format || '';
  34868. } else {
  34869. format = localeSorted;
  34870. index = format;
  34871. localeSorted = false;
  34872. if (typeof format === 'number') {
  34873. index = format;
  34874. format = undefined;
  34875. }
  34876. format = format || '';
  34877. }
  34878. var locale = locale_locales__getLocale(),
  34879. shift = localeSorted ? locale._week.dow : 0;
  34880. if (index != null) {
  34881. return lists__get(format, (index + shift) % 7, field, 'day');
  34882. }
  34883. var i;
  34884. var out = [];
  34885. for (i = 0; i < 7; i++) {
  34886. out[i] = lists__get(format, (i + shift) % 7, field, 'day');
  34887. }
  34888. return out;
  34889. }
  34890. function lists__listMonths (format, index) {
  34891. return listMonthsImpl(format, index, 'months');
  34892. }
  34893. function lists__listMonthsShort (format, index) {
  34894. return listMonthsImpl(format, index, 'monthsShort');
  34895. }
  34896. function lists__listWeekdays (localeSorted, format, index) {
  34897. return listWeekdaysImpl(localeSorted, format, index, 'weekdays');
  34898. }
  34899. function lists__listWeekdaysShort (localeSorted, format, index) {
  34900. return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort');
  34901. }
  34902. function lists__listWeekdaysMin (localeSorted, format, index) {
  34903. return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin');
  34904. }
  34905. locale_locales__getSetGlobalLocale('en', {
  34906. ordinalParse: /\d{1,2}(th|st|nd|rd)/,
  34907. ordinal : function (number) {
  34908. var b = number % 10,
  34909. output = (toInt(number % 100 / 10) === 1) ? 'th' :
  34910. (b === 1) ? 'st' :
  34911. (b === 2) ? 'nd' :
  34912. (b === 3) ? 'rd' : 'th';
  34913. return number + output;
  34914. }
  34915. });
  34916. // Side effect imports
  34917. utils_hooks__hooks.lang = deprecate('moment.lang is deprecated. Use moment.locale instead.', locale_locales__getSetGlobalLocale);
  34918. utils_hooks__hooks.langData = deprecate('moment.langData is deprecated. Use moment.localeData instead.', locale_locales__getLocale);
  34919. var mathAbs = Math.abs;
  34920. function duration_abs__abs () {
  34921. var data = this._data;
  34922. this._milliseconds = mathAbs(this._milliseconds);
  34923. this._days = mathAbs(this._days);
  34924. this._months = mathAbs(this._months);
  34925. data.milliseconds = mathAbs(data.milliseconds);
  34926. data.seconds = mathAbs(data.seconds);
  34927. data.minutes = mathAbs(data.minutes);
  34928. data.hours = mathAbs(data.hours);
  34929. data.months = mathAbs(data.months);
  34930. data.years = mathAbs(data.years);
  34931. return this;
  34932. }
  34933. function duration_add_subtract__addSubtract (duration, input, value, direction) {
  34934. var other = create__createDuration(input, value);
  34935. duration._milliseconds += direction * other._milliseconds;
  34936. duration._days += direction * other._days;
  34937. duration._months += direction * other._months;
  34938. return duration._bubble();
  34939. }
  34940. // supports only 2.0-style add(1, 's') or add(duration)
  34941. function duration_add_subtract__add (input, value) {
  34942. return duration_add_subtract__addSubtract(this, input, value, 1);
  34943. }
  34944. // supports only 2.0-style subtract(1, 's') or subtract(duration)
  34945. function duration_add_subtract__subtract (input, value) {
  34946. return duration_add_subtract__addSubtract(this, input, value, -1);
  34947. }
  34948. function absCeil (number) {
  34949. if (number < 0) {
  34950. return Math.floor(number);
  34951. } else {
  34952. return Math.ceil(number);
  34953. }
  34954. }
  34955. function bubble () {
  34956. var milliseconds = this._milliseconds;
  34957. var days = this._days;
  34958. var months = this._months;
  34959. var data = this._data;
  34960. var seconds, minutes, hours, years, monthsFromDays;
  34961. // if we have a mix of positive and negative values, bubble down first
  34962. // check: https://github.com/moment/moment/issues/2166
  34963. if (!((milliseconds >= 0 && days >= 0 && months >= 0) ||
  34964. (milliseconds <= 0 && days <= 0 && months <= 0))) {
  34965. milliseconds += absCeil(monthsToDays(months) + days) * 864e5;
  34966. days = 0;
  34967. months = 0;
  34968. }
  34969. // The following code bubbles up values, see the tests for
  34970. // examples of what that means.
  34971. data.milliseconds = milliseconds % 1000;
  34972. seconds = absFloor(milliseconds / 1000);
  34973. data.seconds = seconds % 60;
  34974. minutes = absFloor(seconds / 60);
  34975. data.minutes = minutes % 60;
  34976. hours = absFloor(minutes / 60);
  34977. data.hours = hours % 24;
  34978. days += absFloor(hours / 24);
  34979. // convert days to months
  34980. monthsFromDays = absFloor(daysToMonths(days));
  34981. months += monthsFromDays;
  34982. days -= absCeil(monthsToDays(monthsFromDays));
  34983. // 12 months -> 1 year
  34984. years = absFloor(months / 12);
  34985. months %= 12;
  34986. data.days = days;
  34987. data.months = months;
  34988. data.years = years;
  34989. return this;
  34990. }
  34991. function daysToMonths (days) {
  34992. // 400 years have 146097 days (taking into account leap year rules)
  34993. // 400 years have 12 months === 4800
  34994. return days * 4800 / 146097;
  34995. }
  34996. function monthsToDays (months) {
  34997. // the reverse of daysToMonths
  34998. return months * 146097 / 4800;
  34999. }
  35000. function as (units) {
  35001. var days;
  35002. var months;
  35003. var milliseconds = this._milliseconds;
  35004. units = normalizeUnits(units);
  35005. if (units === 'month' || units === 'year') {
  35006. days = this._days + milliseconds / 864e5;
  35007. months = this._months + daysToMonths(days);
  35008. return units === 'month' ? months : months / 12;
  35009. } else {
  35010. // handle milliseconds separately because of floating point math errors (issue #1867)
  35011. days = this._days + Math.round(monthsToDays(this._months));
  35012. switch (units) {
  35013. case 'week' : return days / 7 + milliseconds / 6048e5;
  35014. case 'day' : return days + milliseconds / 864e5;
  35015. case 'hour' : return days * 24 + milliseconds / 36e5;
  35016. case 'minute' : return days * 1440 + milliseconds / 6e4;
  35017. case 'second' : return days * 86400 + milliseconds / 1000;
  35018. // Math.floor prevents floating point math errors here
  35019. case 'millisecond': return Math.floor(days * 864e5) + milliseconds;
  35020. default: throw new Error('Unknown unit ' + units);
  35021. }
  35022. }
  35023. }
  35024. // TODO: Use this.as('ms')?
  35025. function duration_as__valueOf () {
  35026. return (
  35027. this._milliseconds +
  35028. this._days * 864e5 +
  35029. (this._months % 12) * 2592e6 +
  35030. toInt(this._months / 12) * 31536e6
  35031. );
  35032. }
  35033. function makeAs (alias) {
  35034. return function () {
  35035. return this.as(alias);
  35036. };
  35037. }
  35038. var asMilliseconds = makeAs('ms');
  35039. var asSeconds = makeAs('s');
  35040. var asMinutes = makeAs('m');
  35041. var asHours = makeAs('h');
  35042. var asDays = makeAs('d');
  35043. var asWeeks = makeAs('w');
  35044. var asMonths = makeAs('M');
  35045. var asYears = makeAs('y');
  35046. function duration_get__get (units) {
  35047. units = normalizeUnits(units);
  35048. return this[units + 's']();
  35049. }
  35050. function makeGetter(name) {
  35051. return function () {
  35052. return this._data[name];
  35053. };
  35054. }
  35055. var milliseconds = makeGetter('milliseconds');
  35056. var seconds = makeGetter('seconds');
  35057. var minutes = makeGetter('minutes');
  35058. var hours = makeGetter('hours');
  35059. var days = makeGetter('days');
  35060. var months = makeGetter('months');
  35061. var years = makeGetter('years');
  35062. function weeks () {
  35063. return absFloor(this.days() / 7);
  35064. }
  35065. var round = Math.round;
  35066. var thresholds = {
  35067. s: 45, // seconds to minute
  35068. m: 45, // minutes to hour
  35069. h: 22, // hours to day
  35070. d: 26, // days to month
  35071. M: 11 // months to year
  35072. };
  35073. // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
  35074. function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
  35075. return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
  35076. }
  35077. function duration_humanize__relativeTime (posNegDuration, withoutSuffix, locale) {
  35078. var duration = create__createDuration(posNegDuration).abs();
  35079. var seconds = round(duration.as('s'));
  35080. var minutes = round(duration.as('m'));
  35081. var hours = round(duration.as('h'));
  35082. var days = round(duration.as('d'));
  35083. var months = round(duration.as('M'));
  35084. var years = round(duration.as('y'));
  35085. var a = seconds < thresholds.s && ['s', seconds] ||
  35086. minutes <= 1 && ['m'] ||
  35087. minutes < thresholds.m && ['mm', minutes] ||
  35088. hours <= 1 && ['h'] ||
  35089. hours < thresholds.h && ['hh', hours] ||
  35090. days <= 1 && ['d'] ||
  35091. days < thresholds.d && ['dd', days] ||
  35092. months <= 1 && ['M'] ||
  35093. months < thresholds.M && ['MM', months] ||
  35094. years <= 1 && ['y'] || ['yy', years];
  35095. a[2] = withoutSuffix;
  35096. a[3] = +posNegDuration > 0;
  35097. a[4] = locale;
  35098. return substituteTimeAgo.apply(null, a);
  35099. }
  35100. // This function allows you to set a threshold for relative time strings
  35101. function duration_humanize__getSetRelativeTimeThreshold (threshold, limit) {
  35102. if (thresholds[threshold] === undefined) {
  35103. return false;
  35104. }
  35105. if (limit === undefined) {
  35106. return thresholds[threshold];
  35107. }
  35108. thresholds[threshold] = limit;
  35109. return true;
  35110. }
  35111. function humanize (withSuffix) {
  35112. var locale = this.localeData();
  35113. var output = duration_humanize__relativeTime(this, !withSuffix, locale);
  35114. if (withSuffix) {
  35115. output = locale.pastFuture(+this, output);
  35116. }
  35117. return locale.postformat(output);
  35118. }
  35119. var iso_string__abs = Math.abs;
  35120. function iso_string__toISOString() {
  35121. // for ISO strings we do not use the normal bubbling rules:
  35122. // * milliseconds bubble up until they become hours
  35123. // * days do not bubble at all
  35124. // * months bubble up until they become years
  35125. // This is because there is no context-free conversion between hours and days
  35126. // (think of clock changes)
  35127. // and also not between days and months (28-31 days per month)
  35128. var seconds = iso_string__abs(this._milliseconds) / 1000;
  35129. var days = iso_string__abs(this._days);
  35130. var months = iso_string__abs(this._months);
  35131. var minutes, hours, years;
  35132. // 3600 seconds -> 60 minutes -> 1 hour
  35133. minutes = absFloor(seconds / 60);
  35134. hours = absFloor(minutes / 60);
  35135. seconds %= 60;
  35136. minutes %= 60;
  35137. // 12 months -> 1 year
  35138. years = absFloor(months / 12);
  35139. months %= 12;
  35140. // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
  35141. var Y = years;
  35142. var M = months;
  35143. var D = days;
  35144. var h = hours;
  35145. var m = minutes;
  35146. var s = seconds;
  35147. var total = this.asSeconds();
  35148. if (!total) {
  35149. // this is the same as C#'s (Noda) and python (isodate)...
  35150. // but not other JS (goog.date)
  35151. return 'P0D';
  35152. }
  35153. return (total < 0 ? '-' : '') +
  35154. 'P' +
  35155. (Y ? Y + 'Y' : '') +
  35156. (M ? M + 'M' : '') +
  35157. (D ? D + 'D' : '') +
  35158. ((h || m || s) ? 'T' : '') +
  35159. (h ? h + 'H' : '') +
  35160. (m ? m + 'M' : '') +
  35161. (s ? s + 'S' : '');
  35162. }
  35163. var duration_prototype__proto = Duration.prototype;
  35164. duration_prototype__proto.abs = duration_abs__abs;
  35165. duration_prototype__proto.add = duration_add_subtract__add;
  35166. duration_prototype__proto.subtract = duration_add_subtract__subtract;
  35167. duration_prototype__proto.as = as;
  35168. duration_prototype__proto.asMilliseconds = asMilliseconds;
  35169. duration_prototype__proto.asSeconds = asSeconds;
  35170. duration_prototype__proto.asMinutes = asMinutes;
  35171. duration_prototype__proto.asHours = asHours;
  35172. duration_prototype__proto.asDays = asDays;
  35173. duration_prototype__proto.asWeeks = asWeeks;
  35174. duration_prototype__proto.asMonths = asMonths;
  35175. duration_prototype__proto.asYears = asYears;
  35176. duration_prototype__proto.valueOf = duration_as__valueOf;
  35177. duration_prototype__proto._bubble = bubble;
  35178. duration_prototype__proto.get = duration_get__get;
  35179. duration_prototype__proto.milliseconds = milliseconds;
  35180. duration_prototype__proto.seconds = seconds;
  35181. duration_prototype__proto.minutes = minutes;
  35182. duration_prototype__proto.hours = hours;
  35183. duration_prototype__proto.days = days;
  35184. duration_prototype__proto.weeks = weeks;
  35185. duration_prototype__proto.months = months;
  35186. duration_prototype__proto.years = years;
  35187. duration_prototype__proto.humanize = humanize;
  35188. duration_prototype__proto.toISOString = iso_string__toISOString;
  35189. duration_prototype__proto.toString = iso_string__toISOString;
  35190. duration_prototype__proto.toJSON = iso_string__toISOString;
  35191. duration_prototype__proto.locale = locale;
  35192. duration_prototype__proto.localeData = localeData;
  35193. // Deprecations
  35194. duration_prototype__proto.toIsoString = deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', iso_string__toISOString);
  35195. duration_prototype__proto.lang = lang;
  35196. // Side effect imports
  35197. // FORMATTING
  35198. addFormatToken('X', 0, 0, 'unix');
  35199. addFormatToken('x', 0, 0, 'valueOf');
  35200. // PARSING
  35201. addRegexToken('x', matchSigned);
  35202. addRegexToken('X', matchTimestamp);
  35203. addParseToken('X', function (input, array, config) {
  35204. config._d = new Date(parseFloat(input, 10) * 1000);
  35205. });
  35206. addParseToken('x', function (input, array, config) {
  35207. config._d = new Date(toInt(input));
  35208. });
  35209. // Side effect imports
  35210. utils_hooks__hooks.version = '2.13.0';
  35211. setHookCallback(local__createLocal);
  35212. utils_hooks__hooks.fn = momentPrototype;
  35213. utils_hooks__hooks.min = min;
  35214. utils_hooks__hooks.max = max;
  35215. utils_hooks__hooks.now = now;
  35216. utils_hooks__hooks.utc = create_utc__createUTC;
  35217. utils_hooks__hooks.unix = moment__createUnix;
  35218. utils_hooks__hooks.months = lists__listMonths;
  35219. utils_hooks__hooks.isDate = isDate;
  35220. utils_hooks__hooks.locale = locale_locales__getSetGlobalLocale;
  35221. utils_hooks__hooks.invalid = valid__createInvalid;
  35222. utils_hooks__hooks.duration = create__createDuration;
  35223. utils_hooks__hooks.isMoment = isMoment;
  35224. utils_hooks__hooks.weekdays = lists__listWeekdays;
  35225. utils_hooks__hooks.parseZone = moment__createInZone;
  35226. utils_hooks__hooks.localeData = locale_locales__getLocale;
  35227. utils_hooks__hooks.isDuration = isDuration;
  35228. utils_hooks__hooks.monthsShort = lists__listMonthsShort;
  35229. utils_hooks__hooks.weekdaysMin = lists__listWeekdaysMin;
  35230. utils_hooks__hooks.defineLocale = defineLocale;
  35231. utils_hooks__hooks.updateLocale = updateLocale;
  35232. utils_hooks__hooks.locales = locale_locales__listLocales;
  35233. utils_hooks__hooks.weekdaysShort = lists__listWeekdaysShort;
  35234. utils_hooks__hooks.normalizeUnits = normalizeUnits;
  35235. utils_hooks__hooks.relativeTimeThreshold = duration_humanize__getSetRelativeTimeThreshold;
  35236. utils_hooks__hooks.prototype = momentPrototype;
  35237. var _moment = utils_hooks__hooks;
  35238. return _moment;
  35239. }));
  35240. },{}],105:[function(require,module,exports){
  35241. (function (process){
  35242. // Copyright Joyent, Inc. and other Node contributors.
  35243. //
  35244. // Permission is hereby granted, free of charge, to any person obtaining a
  35245. // copy of this software and associated documentation files (the
  35246. // "Software"), to deal in the Software without restriction, including
  35247. // without limitation the rights to use, copy, modify, merge, publish,
  35248. // distribute, sublicense, and/or sell copies of the Software, and to permit
  35249. // persons to whom the Software is furnished to do so, subject to the
  35250. // following conditions:
  35251. //
  35252. // The above copyright notice and this permission notice shall be included
  35253. // in all copies or substantial portions of the Software.
  35254. //
  35255. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  35256. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  35257. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  35258. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  35259. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  35260. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  35261. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  35262. // resolves . and .. elements in a path array with directory names there
  35263. // must be no slashes, empty elements, or device names (c:\) in the array
  35264. // (so also no leading and trailing slashes - it does not distinguish
  35265. // relative and absolute paths)
  35266. function normalizeArray(parts, allowAboveRoot) {
  35267. // if the path tries to go above the root, `up` ends up > 0
  35268. var up = 0;
  35269. for (var i = parts.length - 1; i >= 0; i--) {
  35270. var last = parts[i];
  35271. if (last === '.') {
  35272. parts.splice(i, 1);
  35273. } else if (last === '..') {
  35274. parts.splice(i, 1);
  35275. up++;
  35276. } else if (up) {
  35277. parts.splice(i, 1);
  35278. up--;
  35279. }
  35280. }
  35281. // if the path is allowed to go above the root, restore leading ..s
  35282. if (allowAboveRoot) {
  35283. for (; up--; up) {
  35284. parts.unshift('..');
  35285. }
  35286. }
  35287. return parts;
  35288. }
  35289. // Split a filename into [root, dir, basename, ext], unix version
  35290. // 'root' is just a slash, or nothing.
  35291. var splitPathRe =
  35292. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  35293. var splitPath = function(filename) {
  35294. return splitPathRe.exec(filename).slice(1);
  35295. };
  35296. // path.resolve([from ...], to)
  35297. // posix version
  35298. exports.resolve = function() {
  35299. var resolvedPath = '',
  35300. resolvedAbsolute = false;
  35301. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  35302. var path = (i >= 0) ? arguments[i] : process.cwd();
  35303. // Skip empty and invalid entries
  35304. if (typeof path !== 'string') {
  35305. throw new TypeError('Arguments to path.resolve must be strings');
  35306. } else if (!path) {
  35307. continue;
  35308. }
  35309. resolvedPath = path + '/' + resolvedPath;
  35310. resolvedAbsolute = path.charAt(0) === '/';
  35311. }
  35312. // At this point the path should be resolved to a full absolute path, but
  35313. // handle relative paths to be safe (might happen when process.cwd() fails)
  35314. // Normalize the path
  35315. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  35316. return !!p;
  35317. }), !resolvedAbsolute).join('/');
  35318. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  35319. };
  35320. // path.normalize(path)
  35321. // posix version
  35322. exports.normalize = function(path) {
  35323. var isAbsolute = exports.isAbsolute(path),
  35324. trailingSlash = substr(path, -1) === '/';
  35325. // Normalize the path
  35326. path = normalizeArray(filter(path.split('/'), function(p) {
  35327. return !!p;
  35328. }), !isAbsolute).join('/');
  35329. if (!path && !isAbsolute) {
  35330. path = '.';
  35331. }
  35332. if (path && trailingSlash) {
  35333. path += '/';
  35334. }
  35335. return (isAbsolute ? '/' : '') + path;
  35336. };
  35337. // posix version
  35338. exports.isAbsolute = function(path) {
  35339. return path.charAt(0) === '/';
  35340. };
  35341. // posix version
  35342. exports.join = function() {
  35343. var paths = Array.prototype.slice.call(arguments, 0);
  35344. return exports.normalize(filter(paths, function(p, index) {
  35345. if (typeof p !== 'string') {
  35346. throw new TypeError('Arguments to path.join must be strings');
  35347. }
  35348. return p;
  35349. }).join('/'));
  35350. };
  35351. // path.relative(from, to)
  35352. // posix version
  35353. exports.relative = function(from, to) {
  35354. from = exports.resolve(from).substr(1);
  35355. to = exports.resolve(to).substr(1);
  35356. function trim(arr) {
  35357. var start = 0;
  35358. for (; start < arr.length; start++) {
  35359. if (arr[start] !== '') break;
  35360. }
  35361. var end = arr.length - 1;
  35362. for (; end >= 0; end--) {
  35363. if (arr[end] !== '') break;
  35364. }
  35365. if (start > end) return [];
  35366. return arr.slice(start, end - start + 1);
  35367. }
  35368. var fromParts = trim(from.split('/'));
  35369. var toParts = trim(to.split('/'));
  35370. var length = Math.min(fromParts.length, toParts.length);
  35371. var samePartsLength = length;
  35372. for (var i = 0; i < length; i++) {
  35373. if (fromParts[i] !== toParts[i]) {
  35374. samePartsLength = i;
  35375. break;
  35376. }
  35377. }
  35378. var outputParts = [];
  35379. for (var i = samePartsLength; i < fromParts.length; i++) {
  35380. outputParts.push('..');
  35381. }
  35382. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  35383. return outputParts.join('/');
  35384. };
  35385. exports.sep = '/';
  35386. exports.delimiter = ':';
  35387. exports.dirname = function(path) {
  35388. var result = splitPath(path),
  35389. root = result[0],
  35390. dir = result[1];
  35391. if (!root && !dir) {
  35392. // No dirname whatsoever
  35393. return '.';
  35394. }
  35395. if (dir) {
  35396. // It has a dirname, strip trailing slash
  35397. dir = dir.substr(0, dir.length - 1);
  35398. }
  35399. return root + dir;
  35400. };
  35401. exports.basename = function(path, ext) {
  35402. var f = splitPath(path)[2];
  35403. // TODO: make this comparison case-insensitive on windows?
  35404. if (ext && f.substr(-1 * ext.length) === ext) {
  35405. f = f.substr(0, f.length - ext.length);
  35406. }
  35407. return f;
  35408. };
  35409. exports.extname = function(path) {
  35410. return splitPath(path)[3];
  35411. };
  35412. function filter (xs, f) {
  35413. if (xs.filter) return xs.filter(f);
  35414. var res = [];
  35415. for (var i = 0; i < xs.length; i++) {
  35416. if (f(xs[i], i, xs)) res.push(xs[i]);
  35417. }
  35418. return res;
  35419. }
  35420. // String.prototype.substr - negative index don't work in IE8
  35421. var substr = 'ab'.substr(-1) === 'b'
  35422. ? function (str, start, len) { return str.substr(start, len) }
  35423. : function (str, start, len) {
  35424. if (start < 0) start = str.length + start;
  35425. return str.substr(start, len);
  35426. }
  35427. ;
  35428. }).call(this,require('_process'))
  35429. },{"_process":106}],106:[function(require,module,exports){
  35430. // shim for using process in browser
  35431. var process = module.exports = {};
  35432. process.nextTick = (function () {
  35433. var canSetImmediate = typeof window !== 'undefined'
  35434. && window.setImmediate;
  35435. var canMutationObserver = typeof window !== 'undefined'
  35436. && window.MutationObserver;
  35437. var canPost = typeof window !== 'undefined'
  35438. && window.postMessage && window.addEventListener
  35439. ;
  35440. if (canSetImmediate) {
  35441. return function (f) { return window.setImmediate(f) };
  35442. }
  35443. var queue = [];
  35444. if (canMutationObserver) {
  35445. var hiddenDiv = document.createElement("div");
  35446. var observer = new MutationObserver(function () {
  35447. var queueList = queue.slice();
  35448. queue.length = 0;
  35449. queueList.forEach(function (fn) {
  35450. fn();
  35451. });
  35452. });
  35453. observer.observe(hiddenDiv, { attributes: true });
  35454. return function nextTick(fn) {
  35455. if (!queue.length) {
  35456. hiddenDiv.setAttribute('yes', 'no');
  35457. }
  35458. queue.push(fn);
  35459. };
  35460. }
  35461. if (canPost) {
  35462. window.addEventListener('message', function (ev) {
  35463. var source = ev.source;
  35464. if ((source === window || source === null) && ev.data === 'process-tick') {
  35465. ev.stopPropagation();
  35466. if (queue.length > 0) {
  35467. var fn = queue.shift();
  35468. fn();
  35469. }
  35470. }
  35471. }, true);
  35472. return function nextTick(fn) {
  35473. queue.push(fn);
  35474. window.postMessage('process-tick', '*');
  35475. };
  35476. }
  35477. return function nextTick(fn) {
  35478. setTimeout(fn, 0);
  35479. };
  35480. })();
  35481. process.title = 'browser';
  35482. process.browser = true;
  35483. process.env = {};
  35484. process.argv = [];
  35485. function noop() {}
  35486. process.on = noop;
  35487. process.addListener = noop;
  35488. process.once = noop;
  35489. process.off = noop;
  35490. process.removeListener = noop;
  35491. process.removeAllListeners = noop;
  35492. process.emit = noop;
  35493. process.binding = function (name) {
  35494. throw new Error('process.binding is not supported');
  35495. };
  35496. // TODO(shtylman)
  35497. process.cwd = function () { return '/' };
  35498. process.chdir = function (dir) {
  35499. throw new Error('process.chdir is not supported');
  35500. };
  35501. },{}],107:[function(require,module,exports){
  35502. module.exports= {
  35503. "name": "mermaid",
  35504. "version": "7.0.0",
  35505. "description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams and gantt charts.",
  35506. "main": "src/mermaid.js",
  35507. "keywords": [
  35508. "diagram",
  35509. "markdown",
  35510. "flowchart",
  35511. "sequence diagram",
  35512. "gantt"
  35513. ],
  35514. "bin": {
  35515. "mermaid": "./bin/mermaid.js"
  35516. },
  35517. "scripts": {
  35518. "live": "live-server ./test/examples",
  35519. "lint": "node node_modules/eslint/bin/eslint.js src",
  35520. "jison": "gulp jison_legacy",
  35521. "karma": "node node_modules/karma/bin/karma start karma.conf.js --single-run",
  35522. "watch": "source ./scripts/watch.sh",
  35523. "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",
  35524. "tape": "node node_modules/tape/bin/tape test/cli_test-*.js",
  35525. "jasmine": "npm run jison &&node node_modules/jasmine-es6/bin/jasmine.js",
  35526. "pretest": "npm run jison",
  35527. "test": "npm run dist && npm run karma && npm run tape",
  35528. "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",
  35529. "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",
  35530. "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",
  35531. "dist-mermaid-nomin": "node node_modules/browserify/bin/cmd.js src/mermaid.js -t babelify -s mermaid -o dist/mermaid.js",
  35532. "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",
  35533. "dist": "npm run dist-slim-mermaid && npm run dist-slim-mermaidAPI && npm run dist-mermaid && npm run dist-mermaidAPI"
  35534. },
  35535. "repository": {
  35536. "type": "git",
  35537. "url": "https://github.com/knsv/mermaid"
  35538. },
  35539. "author": "Knut Sveidqvist",
  35540. "license": "MIT",
  35541. "dependencies": {
  35542. "chalk": "^0.5.1",
  35543. "d3": "3.5.6",
  35544. "dagre": "^0.7.4",
  35545. "dagre-d3": "0.4.10",
  35546. "he": "^0.5.0",
  35547. "lodash": "^4.6.1",
  35548. "minimist": "^1.1.0",
  35549. "mkdirp": "^0.5.0",
  35550. "moment": "^2.9.0",
  35551. "semver": "^4.1.1",
  35552. "which": "^1.0.8"
  35553. },
  35554. "devDependencies": {
  35555. "async": "^0.9.0",
  35556. "babel-eslint": "^4.1.3",
  35557. "babelify": "^6.4.0",
  35558. "browserify": "~6.2.0",
  35559. "clone": "^0.2.0",
  35560. "codeclimate-test-reporter": "0.0.4",
  35561. "dateformat": "^1.0.11",
  35562. "dox": "^0.8.0",
  35563. "eslint": "^1.6.0",
  35564. "eslint-watch": "^2.1.2",
  35565. "event-stream": "^3.2.0",
  35566. "foundation": "^4.2.1-1",
  35567. "front-matter": "^0.2.0",
  35568. "gulp": "~3.9.0",
  35569. "gulp-bower": "0.0.10",
  35570. "gulp-browserify": "^0.5.0",
  35571. "gulp-bump": "^0.1.11",
  35572. "gulp-concat": "~2.4.1",
  35573. "gulp-data": "^1.1.1",
  35574. "gulp-dox": "^0.1.6",
  35575. "gulp-ext-replace": "^0.2.0",
  35576. "gulp-filelog": "^0.4.1",
  35577. "gulp-front-matter": "^1.2.3",
  35578. "gulp-hogan": "^1.1.0",
  35579. "gulp-if": "^1.2.5",
  35580. "gulp-insert": "^0.4.0",
  35581. "gulp-istanbul": "^0.4.0",
  35582. "gulp-jasmine": "~2.1.0",
  35583. "gulp-jasmine-browser": "^0.2.3",
  35584. "gulp-jison": "~1.2.0",
  35585. "gulp-jshint": "^1.9.0",
  35586. "gulp-less": "^3.0.1",
  35587. "gulp-livereload": "^3.8.0",
  35588. "gulp-marked": "^1.0.0",
  35589. "gulp-mdvars": "^2.0.0",
  35590. "gulp-qunit": "~1.2.1",
  35591. "gulp-rename": "~1.2.0",
  35592. "gulp-shell": "^0.2.10",
  35593. "gulp-tag-version": "^1.2.1",
  35594. "gulp-uglify": "~1.0.1",
  35595. "gulp-util": "^3.0.7",
  35596. "gulp-vartree": "^2.0.1",
  35597. "hogan.js": "^3.0.2",
  35598. "jasmine": "2.3.2",
  35599. "jasmine-es6": "0.0.18",
  35600. "jison": "zaach/jison",
  35601. "jsdom": "^7.0.2",
  35602. "jshint-stylish": "^2.0.1",
  35603. "karma": "^0.13.15",
  35604. "karma-babel-preprocessor": "^6.0.1",
  35605. "karma-browserify": "^4.4.0",
  35606. "karma-jasmine": "^0.3.6",
  35607. "karma-phantomjs-launcher": "^0.2.1",
  35608. "live-server": "^0.9.0",
  35609. "map-stream": "0.0.6",
  35610. "marked": "^0.3.2",
  35611. "mock-browser": "^0.91.34",
  35612. "path": "^0.4.9",
  35613. "phantomjs": "^2.1.3",
  35614. "proxyquire": "^1.7.3",
  35615. "proxyquire-universal": "^1.0.8",
  35616. "proxyquireify": "^3.0.0",
  35617. "require-dir": "^0.3.0",
  35618. "rewire": "^2.1.3",
  35619. "rimraf": "^2.2.8",
  35620. "tape": "^3.0.3",
  35621. "testdom": "^2.0.0",
  35622. "uglifyjs": "^2.4.10",
  35623. "vinyl-source-stream": "^1.1.0",
  35624. "watchify": "^3.6.1"
  35625. }
  35626. }
  35627. },{}],108:[function(require,module,exports){
  35628. /* global window */
  35629. //log.debug('Setting up d3');
  35630. 'use strict';
  35631. var d3;
  35632. if (typeof require !== 'undefined') {
  35633. try {
  35634. d3 = require('d3');
  35635. } catch (e) {
  35636. //log.debug('Exception ... but ok');
  35637. //log.debug(e);
  35638. }
  35639. }
  35640. //log.debug(d3);
  35641. if (!d3) {
  35642. //if(typeof window !== 'undefined')
  35643. d3 = window.d3;
  35644. }
  35645. //if(typeof window === 'undefined'){
  35646. // window = {};
  35647. // window.d3 = d3;
  35648. //}
  35649. //log.debug('window');
  35650. //log.debug(window);
  35651. module.exports = d3;
  35652. /* jshint ignore:start */
  35653. /*
  35654. D3 Text Wrap
  35655. By Vijith Assar
  35656. http://www.vijithassar.com
  35657. http://www.github.com/vijithassar
  35658. @vijithassar
  35659. Detailed instructions at http://www.github.com/vijithassar/d3textwrap
  35660. */
  35661. (function () {
  35662. // set this variable to a string value to always force a particular
  35663. // wrap method for development purposes, for example to check tspan
  35664. // rendering using a foreignobject-enabled browser. set to 'tspan' to
  35665. // use tspans and 'foreignobject' to use foreignobject
  35666. var force_wrap_method = false; // by default no wrap method is forced
  35667. force_wrap_method = 'tspans'; // uncomment this statement to force tspans
  35668. // force_wrap_method = 'foreignobjects'; // uncomment this statement to force foreignobjects
  35669. // exit immediately if something in this location
  35670. // has already been defined; the plugin will defer to whatever
  35671. // else you're doing in your code
  35672. if (d3.selection.prototype.textwrap) {
  35673. return false;
  35674. }
  35675. // double check the force_wrap_method flag
  35676. // and reset if someone screwed up the above
  35677. // settings
  35678. if (typeof force_wrap_method == 'undefined') {
  35679. var force_wrap_method = false;
  35680. }
  35681. // create the plugin method twice, both for regular use
  35682. // and again for use inside the enter() selection
  35683. d3.selection.prototype.textwrap = d3.selection.enter.prototype.textwrap = function (bounds, padding) {
  35684. // default value of padding is zero if it's undefined
  35685. var padding = parseInt(padding) || 0;
  35686. // save callee into a variable so we can continue to refer to it
  35687. // as the function scope changes
  35688. var selection = this;
  35689. // create a variable to store desired return values in
  35690. var return_value;
  35691. // extract wrap boundaries from any d3-selected rect and return them
  35692. // in a format that matches the simpler object argument option
  35693. var extract_bounds = function extract_bounds(bounds) {
  35694. // discard the nested array wrappers added by d3
  35695. var bounding_rect = bounds[0][0];
  35696. // sanitize the svg element name so we can test against it
  35697. var element_type = bounding_rect.tagName.toString();
  35698. // if it's not a rect, exit
  35699. if (element_type !== 'rect') {
  35700. return false;
  35701. // if it's a rect, proceed to extracting the position attributes
  35702. } else {
  35703. var bounds_extracted = {};
  35704. bounds_extracted.x = d3.select(bounding_rect).attr('x') || 0;
  35705. bounds_extracted.y = d3.select(bounding_rect).attr('y') || 0;
  35706. bounds_extracted.width = d3.select(bounding_rect).attr('width') || 0;
  35707. bounds_extracted.height = d3.select(bounding_rect).attr('height') || 0;
  35708. // also pass along the getter function
  35709. bounds_extracted.attr = bounds.attr;
  35710. }
  35711. return bounds_extracted;
  35712. };
  35713. // double check the input argument for the wrapping
  35714. // boundaries to make sure it actually contains all
  35715. // the information we'll need in order to wrap successfully
  35716. var verify_bounds = function verify_bounds(bounds) {
  35717. // quickly add a simple getter method so you can use either
  35718. // bounds.x or bounds.attr('x') as your notation,
  35719. // the latter being a common convention among D3
  35720. // developers
  35721. if (!bounds.attr) {
  35722. bounds.attr = function (property) {
  35723. if (this[property]) {
  35724. return this[property];
  35725. }
  35726. };
  35727. }
  35728. // if it's an associative array, make sure it has all the
  35729. // necessary properties represented directly
  35730. if (typeof bounds == 'object' && typeof bounds.x !== 'undefined' && typeof bounds.y !== 'undefined' && typeof bounds.width !== 'undefined' && typeof bounds.height !== 'undefined'
  35731. // if that's the case, then the bounds are fine
  35732. ) {
  35733. // return the lightly modified bounds
  35734. return bounds;
  35735. // if it's a numerically indexed array, assume it's a
  35736. // d3-selected rect and try to extract the positions
  35737. } else if (
  35738. // first try to make sure it's an array using Array.isArray
  35739. typeof Array.isArray == 'function' && Array.isArray(bounds) ||
  35740. // but since Array.isArray isn't always supported, fall
  35741. // back to casting to the object to string when it's not
  35742. Object.prototype.toString.call(bounds) === '[object Array]') {
  35743. // once you're sure it's an array, extract the boundaries
  35744. // from the rect
  35745. var extracted_bounds = extract_bounds(bounds);
  35746. return extracted_bounds;
  35747. } else {
  35748. // but if the bounds are neither an object nor a numerical
  35749. // array, then the bounds argument is invalid and you'll
  35750. // need to fix it
  35751. return false;
  35752. }
  35753. };
  35754. var apply_padding = function apply_padding(bounds, padding) {
  35755. var padded_bounds = bounds;
  35756. if (padding !== 0) {
  35757. padded_bounds.x = parseInt(padded_bounds.x) + padding;
  35758. padded_bounds.y = parseInt(padded_bounds.y) + padding;
  35759. padded_bounds.width -= padding * 2;
  35760. padded_bounds.height -= padding * 2;
  35761. }
  35762. return padded_bounds;
  35763. };
  35764. // verify bounds
  35765. var verified_bounds = verify_bounds(bounds);
  35766. // modify bounds if a padding value is provided
  35767. if (padding) {
  35768. verified_bounds = apply_padding(verified_bounds, padding);
  35769. }
  35770. // check that we have the necessary conditions for this function to operate properly
  35771. if (
  35772. // selection it's operating on cannot be not empty
  35773. selection.length == 0 ||
  35774. // d3 must be available
  35775. !d3 ||
  35776. // desired wrapping bounds must be provided as an input argument
  35777. !bounds ||
  35778. // input bounds must validate
  35779. !verified_bounds) {
  35780. // try to return the calling selection if possible
  35781. // so as not to interfere with methods downstream in the
  35782. // chain
  35783. if (selection) {
  35784. return selection;
  35785. // if all else fails, just return false. if you hit this point then you're
  35786. // almost certainly trying to call the textwrap() method on something that
  35787. // doesn't make sense!
  35788. } else {
  35789. return false;
  35790. }
  35791. // if we've validated everything then we can finally proceed
  35792. // to the meat of this operation
  35793. } else {
  35794. // reassign the verified bounds as the set we want
  35795. // to work with from here on; this ensures that we're
  35796. // using the same data structure for our bounds regardless
  35797. // of whether the input argument was a simple object or
  35798. // a d3 selection
  35799. bounds = verified_bounds;
  35800. // wrap using html and foreignObjects if they are supported
  35801. var wrap_with_foreignobjects = function wrap_with_foreignobjects(item) {
  35802. // establish variables to quickly reference target nodes later
  35803. var parent = d3.select(item[0].parentNode);
  35804. var text_node = parent.select('text');
  35805. var styled_line_height = text_node.style('line-height');
  35806. // extract our desired content from the single text element
  35807. var text_to_wrap = text_node.text();
  35808. // remove the text node and replace with a foreign object
  35809. text_node.remove();
  35810. var foreign_object = parent.append('foreignObject');
  35811. // add foreign object and set dimensions, position, etc
  35812. 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);
  35813. // insert an HTML div
  35814. var wrap_div = foreign_object.append('xhtml:div')
  35815. // this class is currently hardcoded
  35816. // probably not necessary but easy to
  35817. // override using .classed() and for now
  35818. // it's nice to avoid a litany of input
  35819. // arguments
  35820. .attr('class', 'wrapped');
  35821. // set div to same dimensions as foreign object
  35822. wrap_div.style('height', bounds.height).style('width', bounds.width)
  35823. // insert text content
  35824. .html(text_to_wrap);
  35825. if (styled_line_height) {
  35826. wrap_div.style('line-height', styled_line_height);
  35827. }
  35828. return_value = parent.select('foreignObject');
  35829. };
  35830. // wrap with tspans if foreignObject is undefined
  35831. var wrap_with_tspans = function wrap_with_tspans(item) {
  35832. // operate on the first text item in the selection
  35833. var text_node = item[0];
  35834. var parent = text_node.parentNode;
  35835. var text_node_selected = d3.select(text_node);
  35836. // measure initial size of the text node as rendered
  35837. var text_node_height = text_node.getBBox().height;
  35838. var text_node_width = text_node.getBBox().width;
  35839. // figure out the line height, either from rendered height
  35840. // of the font or attached styling
  35841. var line_height;
  35842. var rendered_line_height = text_node_height;
  35843. var styled_line_height = text_node_selected.style('line-height');
  35844. if (styled_line_height && parseInt(styled_line_height)) {
  35845. line_height = parseInt(styled_line_height.replace('px', ''));
  35846. } else {
  35847. line_height = rendered_line_height;
  35848. }
  35849. // only fire the rest of this if the text content
  35850. // overflows the desired dimensions
  35851. if (text_node_width > bounds.width) {
  35852. // store whatever is inside the text node
  35853. // in a variable and then zero out the
  35854. // initial content; we'll reinsert in a moment
  35855. // using tspan elements.
  35856. var text_to_wrap = text_node_selected.text();
  35857. text_node_selected.text('');
  35858. if (text_to_wrap) {
  35859. // keep track of whether we are splitting by spaces
  35860. // so we know whether to reinsert those spaces later
  35861. var break_delimiter;
  35862. // split at spaces to create an array of individual words
  35863. var text_to_wrap_array;
  35864. if (text_to_wrap.indexOf(' ') !== -1) {
  35865. var break_delimiter = ' ';
  35866. text_to_wrap_array = text_to_wrap.split(' ');
  35867. } else {
  35868. // if there are no spaces, figure out the split
  35869. // points by comparing rendered text width against
  35870. // bounds and translating that into character position
  35871. // cuts
  35872. break_delimiter = '';
  35873. var string_length = text_to_wrap.length;
  35874. var number_of_substrings = Math.ceil(text_node_width / bounds.width);
  35875. var splice_interval = Math.floor(string_length / number_of_substrings);
  35876. if (!(splice_interval * number_of_substrings >= string_length)) {
  35877. number_of_substrings++;
  35878. }
  35879. var text_to_wrap_array = [];
  35880. var substring;
  35881. var start_position;
  35882. for (var i = 0; i < number_of_substrings; i++) {
  35883. start_position = i * splice_interval;
  35884. substring = text_to_wrap.substr(start_position, splice_interval);
  35885. text_to_wrap_array.push(substring);
  35886. }
  35887. }
  35888. // new array where we'll store the words re-assembled into
  35889. // substrings that have been tested against the desired
  35890. // maximum wrapping width
  35891. var substrings = [];
  35892. // computed text length is arguably incorrectly reported for
  35893. // all tspans after the first one, in that they will include
  35894. // the width of previous separate tspans. to compensate we need
  35895. // to manually track the computed text length of all those
  35896. // previous tspans and substrings, and then use that to offset
  35897. // the miscalculation. this then gives us the actual correct
  35898. // position we want to use in rendering the text in the SVG.
  35899. var total_offset = 0;
  35900. // object for storing the results of text length computations later
  35901. var temp = {};
  35902. // loop through the words and test the computed text length
  35903. // of the string against the maximum desired wrapping width
  35904. for (var i = 0; i < text_to_wrap_array.length; i++) {
  35905. var word = text_to_wrap_array[i];
  35906. var previous_string = text_node_selected.text();
  35907. var previous_width = text_node.getComputedTextLength();
  35908. // initialize the current word as the first word
  35909. // or append to the previous string if one exists
  35910. var new_string;
  35911. if (previous_string) {
  35912. new_string = previous_string + break_delimiter + word;
  35913. } else {
  35914. new_string = word;
  35915. }
  35916. // add the newest substring back to the text node and
  35917. // measure the length
  35918. text_node_selected.text(new_string);
  35919. var new_width = text_node.getComputedTextLength();
  35920. // adjust the length by the offset we've tracked
  35921. // due to the misreported length discussed above
  35922. var test_width = new_width - total_offset;
  35923. // if our latest version of the string is too
  35924. // big for the bounds, use the previous
  35925. // version of the string (without the newest word
  35926. // added) and use the latest word to restart the
  35927. // process with a new tspan
  35928. if (new_width > bounds.width) {
  35929. if (previous_string && previous_string !== '') {
  35930. total_offset = total_offset + previous_width;
  35931. temp = { string: previous_string, width: previous_width, offset: total_offset };
  35932. substrings.push(temp);
  35933. text_node_selected.text('');
  35934. text_node_selected.text(word);
  35935. // Handle case where there is just one more word to be wrapped
  35936. if (i == text_to_wrap_array.length - 1) {
  35937. new_string = word;
  35938. text_node_selected.text(new_string);
  35939. new_width = text_node.getComputedTextLength();
  35940. }
  35941. }
  35942. }
  35943. // if we're up to the last word in the array,
  35944. // get the computed length as is without
  35945. // appending anything further to it
  35946. if (i == text_to_wrap_array.length - 1) {
  35947. text_node_selected.text('');
  35948. var final_string = new_string;
  35949. if (final_string && final_string !== '') {
  35950. if (new_width - total_offset > 0) {
  35951. new_width = new_width - total_offset;
  35952. }
  35953. temp = { string: final_string, width: new_width, offset: total_offset };
  35954. substrings.push(temp);
  35955. }
  35956. }
  35957. }
  35958. // append each substring as a tspan
  35959. var current_tspan;
  35960. var tspan_count;
  35961. // double check that the text content has been removed
  35962. // before we start appending tspans
  35963. text_node_selected.text('');
  35964. for (var i = 0; i < substrings.length; i++) {
  35965. var substring = substrings[i].string;
  35966. if (i > 0) {
  35967. var previous_substring = substrings[i - 1];
  35968. }
  35969. // only append if we're sure it won't make the tspans
  35970. // overflow the bounds.
  35971. if (i * line_height < bounds.height - line_height * 1.5) {
  35972. current_tspan = text_node_selected.append('tspan').text(substring);
  35973. // vertical shift to all tspans after the first one
  35974. current_tspan.attr('dy', function (d) {
  35975. if (i > 0) {
  35976. return line_height;
  35977. }
  35978. });
  35979. // shift left from default position, which
  35980. // is probably based on the full length of the
  35981. // text string until we make this adjustment
  35982. current_tspan.attr('x', function () {
  35983. var x_offset = bounds.x;
  35984. if (padding) {
  35985. x_offset += padding;
  35986. }
  35987. return x_offset;
  35988. });
  35989. // .attr('dx', function() {
  35990. // if(i == 0) {
  35991. // var render_offset = 0;
  35992. // } else if(i > 0) {
  35993. // render_offset = substrings[i - 1].width;
  35994. // render_offset = render_offset * -1;
  35995. // }
  35996. // return render_offset;
  35997. // });
  35998. }
  35999. }
  36000. }
  36001. }
  36002. // position the overall text node, whether wrapped or not
  36003. text_node_selected.attr('y', function () {
  36004. var y_offset = bounds.y;
  36005. // shift by line-height to move the baseline into
  36006. // the bounds – otherwise the text baseline would be
  36007. // at the top of the bounds
  36008. if (line_height) {
  36009. y_offset += line_height;
  36010. }
  36011. // shift by padding, if it's there
  36012. if (padding) {
  36013. y_offset += padding;
  36014. }
  36015. return y_offset;
  36016. });
  36017. // shift to the right by the padding value
  36018. text_node_selected.attr('x', function () {
  36019. var x_offset = bounds.x;
  36020. if (padding) {
  36021. x_offset += padding;
  36022. }
  36023. return x_offset;
  36024. });
  36025. // assign our modified text node with tspans
  36026. // to the return value
  36027. return_value = d3.select(parent).selectAll('text');
  36028. };
  36029. // variable used to hold the functions that let us
  36030. // switch between the wrap methods
  36031. var wrap_method;
  36032. // if a wrap method if being forced, assign that
  36033. // function
  36034. if (force_wrap_method) {
  36035. if (force_wrap_method == 'foreignobjects') {
  36036. wrap_method = wrap_with_foreignobjects;
  36037. } else if (force_wrap_method == 'tspans') {
  36038. wrap_method = wrap_with_tspans;
  36039. }
  36040. }
  36041. // if no wrap method is being forced, then instead
  36042. // test for browser support of foreignobject and
  36043. // use whichever wrap method makes sense accordingly
  36044. if (!force_wrap_method) {
  36045. if (typeof SVGForeignObjectElement !== 'undefined') {
  36046. wrap_method = wrap_with_foreignobjects;
  36047. } else {
  36048. wrap_method = wrap_with_tspans;
  36049. }
  36050. }
  36051. // run the desired wrap function for each item
  36052. // in the d3 selection that called .textwrap()
  36053. for (var i = 0; i < selection.length; i++) {
  36054. var item = selection[i];
  36055. wrap_method(item);
  36056. }
  36057. // return the modified nodes so we can chain other
  36058. // methods to them.
  36059. return return_value;
  36060. }
  36061. };
  36062. })();
  36063. /* jshint ignore:end */
  36064. },{"d3":"d3"}],109:[function(require,module,exports){
  36065. 'use strict';
  36066. var Logger = require('../../logger');
  36067. var log = new Logger.Log();
  36068. var relations = [];
  36069. var classes;
  36070. var idCache;
  36071. classes = {};
  36072. // Functions to be run after graph rendering
  36073. var funs = [];
  36074. /**
  36075. * Function called by parser when a node definition has been found.
  36076. * @param id
  36077. * @param text
  36078. * @param type
  36079. * @param style
  36080. */
  36081. exports.addClass = function (id) {
  36082. if (typeof classes[id] === 'undefined') {
  36083. classes[id] = {
  36084. id: id,
  36085. methods: [],
  36086. members: []
  36087. };
  36088. }
  36089. };
  36090. exports.clear = function () {
  36091. relations = [];
  36092. classes = {};
  36093. };
  36094. module.exports.getClass = function (id) {
  36095. return classes[id];
  36096. };
  36097. module.exports.getClasses = function () {
  36098. return classes;
  36099. };
  36100. module.exports.getRelations = function () {
  36101. return relations;
  36102. };
  36103. exports.addRelation = function (relation) {
  36104. log.warn('Adding relation: ' + JSON.stringify(relation));
  36105. exports.addClass(relation.id1);
  36106. exports.addClass(relation.id2);
  36107. relations.push(relation);
  36108. };
  36109. exports.addMembers = function (className, MembersArr) {
  36110. var theClass = classes[className];
  36111. if (typeof MembersArr === 'string') {
  36112. if (MembersArr.substr(-1) === ')') {
  36113. theClass.methods.push(MembersArr);
  36114. } else {
  36115. theClass.members.push(MembersArr);
  36116. }
  36117. }
  36118. };
  36119. exports.cleanupLabel = function (label) {
  36120. if (label.substring(0, 1) === ':') {
  36121. return label.substr(2).trim();
  36122. } else {
  36123. return label.trim();
  36124. }
  36125. };
  36126. exports.lineType = {
  36127. LINE: 0,
  36128. DOTTED_LINE: 1
  36129. };
  36130. exports.relationType = {
  36131. AGGREGATION: 0,
  36132. EXTENSION: 1,
  36133. COMPOSITION: 2,
  36134. DEPENDENCY: 3
  36135. };
  36136. },{"../../logger":130}],110:[function(require,module,exports){
  36137. /**
  36138. * Created by knut on 14-11-23.
  36139. */
  36140. 'use strict';
  36141. var cd = require('./parser/classDiagram').parser;
  36142. var cDDb = require('./classDb');
  36143. cd.yy = cDDb;
  36144. var d3 = require('../../d3');
  36145. var Logger = require('../../logger');
  36146. var dagre = require('dagre');
  36147. var log = new Logger.Log();
  36148. var idCache;
  36149. idCache = {};
  36150. var classCnt = 0;
  36151. var conf = {
  36152. dividerMargin: 10,
  36153. padding: 5,
  36154. textHeight: 14
  36155. };
  36156. // Todo optimize
  36157. var getGraphId = function getGraphId(label) {
  36158. var keys = Object.keys(idCache);
  36159. var i;
  36160. for (i = 0; i < keys.length; i++) {
  36161. if (idCache[keys[i]].label === label) {
  36162. return keys[i];
  36163. }
  36164. }
  36165. return undefined;
  36166. };
  36167. /**
  36168. * Setup arrow head and define the marker. The result is appended to the svg.
  36169. */
  36170. var insertMarkers = function insertMarkers(elem) {
  36171. 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');
  36172. 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
  36173. 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');
  36174. 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');
  36175. 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');
  36176. 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');
  36177. 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');
  36178. 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');
  36179. };
  36180. var edgeCount = 0;
  36181. var drawEdge = function drawEdge(elem, path, relation) {
  36182. var getRelationType = function getRelationType(type) {
  36183. switch (type) {
  36184. case cDDb.relationType.AGGREGATION:
  36185. return 'aggregation';
  36186. case cDDb.relationType.EXTENSION:
  36187. return 'extension';
  36188. case cDDb.relationType.COMPOSITION:
  36189. return 'composition';
  36190. case cDDb.relationType.DEPENDENCY:
  36191. return 'dependency';
  36192. }
  36193. };
  36194. //The data for our line
  36195. var lineData = path.points;
  36196. //This is the accessor function we talked about above
  36197. var lineFunction = d3.svg.line().x(function (d) {
  36198. return d.x;
  36199. }).y(function (d) {
  36200. return d.y;
  36201. })
  36202. //.interpolate('cardinal');
  36203. .interpolate('basis');
  36204. var svgPath = elem.append('path').attr('d', lineFunction(lineData)).attr('id', 'edge' + edgeCount).attr('class', 'relation');
  36205. var url = '';
  36206. if (conf.arrowMarkerAbsolute) {
  36207. url = window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search;
  36208. url = url.replace(/\(/g, '\\(');
  36209. url = url.replace(/\)/g, '\\)');
  36210. }
  36211. //console.log(relation.relation.type1);
  36212. if (relation.relation.type1 !== 'none') {
  36213. svgPath.attr('marker-start', 'url(' + url + '#' + getRelationType(relation.relation.type1) + 'Start' + ')');
  36214. }
  36215. if (relation.relation.type2 !== 'none') {
  36216. svgPath.attr('marker-end', 'url(' + url + '#' + getRelationType(relation.relation.type2) + 'End' + ')');
  36217. }
  36218. //var bbox = svgPath[0][0].getBBox();
  36219. //var x = Math.floor(bbox.x + bbox.width/2.0);
  36220. //var y = Math.floor(bbox.y + bbox.height/2.0);
  36221. var x, y;
  36222. var l = path.points.length;
  36223. if (l % 2 !== 0) {
  36224. var p1 = path.points[Math.floor(l / 2)];
  36225. var p2 = path.points[Math.ceil(l / 2)];
  36226. x = (p1.x + p2.x) / 2;
  36227. y = (p1.y + p2.y) / 2;
  36228. } else {
  36229. var p = path.points[Math.floor(l / 2)];
  36230. x = p.x;
  36231. y = p.y;
  36232. }
  36233. if (typeof relation.title !== 'undefined') {
  36234. var g = elem.append('g').attr('class', 'classLabel');
  36235. var label = g.append('text').attr('class', 'label').attr('x', x).attr('y', y).attr('fill', 'red').attr('text-anchor', 'middle').text(relation.title);
  36236. window.label = label;
  36237. var bounds = label.node().getBBox();
  36238. 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);
  36239. //.append('textpath')
  36240. //.attr('xlink:href','#edge'+edgeCount)
  36241. //.attr('text-anchor','middle')
  36242. //.attr('startOffset','50%')
  36243. }
  36244. edgeCount++;
  36245. };
  36246. var drawClass = function drawClass(elem, classDef) {
  36247. log.info('Rendering class ' + classDef);
  36248. var addTspan = function addTspan(textEl, txt, isFirst) {
  36249. var tSpan = textEl.append('tspan').attr('x', conf.padding).text(txt);
  36250. if (!isFirst) {
  36251. tSpan.attr('dy', conf.textHeight);
  36252. }
  36253. };
  36254. var id = 'classId' + classCnt;
  36255. var classInfo = {
  36256. id: id,
  36257. label: classDef.id,
  36258. width: 0,
  36259. height: 0
  36260. };
  36261. var g = elem.append('g').attr('id', id).attr('class', 'classGroup');
  36262. var title = g.append('text').attr('x', conf.padding).attr('y', conf.textHeight + conf.padding).text(classDef.id);
  36263. var titleHeight = title.node().getBBox().height;
  36264. var membersLine = g.append('line') // text label for the x axis
  36265. .attr('x1', 0).attr('y1', conf.padding + titleHeight + conf.dividerMargin / 2).attr('y2', conf.padding + titleHeight + conf.dividerMargin / 2);
  36266. var members = g.append('text') // text label for the x axis
  36267. .attr('x', conf.padding).attr('y', titleHeight + conf.dividerMargin + conf.textHeight).attr('fill', 'white').attr('class', 'classText');
  36268. var isFirst = true;
  36269. classDef.members.forEach(function (member) {
  36270. addTspan(members, member, isFirst);
  36271. isFirst = false;
  36272. });
  36273. //for (var member of classDef.members) {
  36274. // addTspan(members, member, isFirst);
  36275. // isFirst = false;
  36276. //}
  36277. var membersBox = members.node().getBBox();
  36278. var methodsLine = g.append('line') // text label for the x axis
  36279. .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);
  36280. var methods = g.append('text') // text label for the x axis
  36281. .attr('x', conf.padding).attr('y', titleHeight + 2 * conf.dividerMargin + membersBox.height + conf.textHeight).attr('fill', 'white').attr('class', 'classText');
  36282. isFirst = true;
  36283. classDef.methods.forEach(function (method) {
  36284. addTspan(methods, method, isFirst);
  36285. isFirst = false;
  36286. });
  36287. //for (var method of classDef.methods) {
  36288. // addTspan(methods, method, isFirst);
  36289. // isFirst = false;
  36290. //}
  36291. var classBox = g.node().getBBox();
  36292. 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);
  36293. membersLine.attr('x2', classBox.width + 2 * conf.padding);
  36294. methodsLine.attr('x2', classBox.width + 2 * conf.padding);
  36295. classInfo.width = classBox.width + 2 * conf.padding;
  36296. classInfo.height = classBox.height + conf.padding + 0.5 * conf.dividerMargin;
  36297. idCache[id] = classInfo;
  36298. classCnt++;
  36299. return classInfo;
  36300. };
  36301. module.exports.setConf = function (cnf) {
  36302. var keys = Object.keys(cnf);
  36303. keys.forEach(function (key) {
  36304. conf[key] = cnf[key];
  36305. });
  36306. };
  36307. /**
  36308. * Draws a flowchart in the tag with id: id based on the graph definition in text.
  36309. * @param text
  36310. * @param id
  36311. */
  36312. module.exports.draw = function (text, id) {
  36313. cd.yy.clear();
  36314. cd.parse(text);
  36315. log.info('Rendering diagram ' + text);
  36316. //// Fetch the default direction, use TD if none was found
  36317. var diagram = d3.select('#' + id);
  36318. insertMarkers(diagram);
  36319. //var svg = diagram.append('svg');
  36320. // Layout graph, Create a new directed graph
  36321. var g = new dagre.graphlib.Graph({
  36322. multigraph: true
  36323. });
  36324. // Set an object for the graph label
  36325. g.setGraph({
  36326. isMultiGraph: true
  36327. });
  36328. // Default to assigning a new object as a label for each new edge.
  36329. g.setDefaultEdgeLabel(function () {
  36330. return {};
  36331. });
  36332. var classes = cDDb.getClasses();
  36333. var keys = Object.keys(classes);
  36334. var i;
  36335. for (i = 0; i < keys.length; i++) {
  36336. var classDef = classes[keys[i]];
  36337. var node = drawClass(diagram, classDef);
  36338. // Add nodes to the graph. The first argument is the node id. The second is
  36339. // metadata about the node. In this case we're going to add labels to each of
  36340. // our nodes.
  36341. g.setNode(node.id, node);
  36342. log.info('Org height: ' + node.height);
  36343. //g.setNode("swilliams", { label: "Saul Williams", width: 160, height: 100 });
  36344. //g.setNode("bpitt", { label: "Brad Pitt", width: 108, height: 100 });
  36345. //g.setNode("hford", { label: "Harrison Ford", width: 168, height: 100 });
  36346. //g.setNode("lwilson", { label: "Luke Wilson", width: 144, height: 100 });
  36347. //g.setNode("kbacon", { label: "Kevin Bacon", width: 121, height: 100 });
  36348. }
  36349. var relations = cDDb.getRelations();
  36350. var i = 0;
  36351. relations.forEach(function (relation) {
  36352. i = i + 1;
  36353. log.info('tjoho' + getGraphId(relation.id1) + getGraphId(relation.id2) + JSON.stringify(relation));
  36354. g.setEdge(getGraphId(relation.id1), getGraphId(relation.id2), { relation: relation });
  36355. });
  36356. //for (var relation of relations) {
  36357. // i = i + 1;
  36358. // log.info('tjoho' + getGraphId(relation.id1) + getGraphId(relation.id2) + JSON.stringify(relation));
  36359. // g.setEdge(getGraphId(relation.id1), getGraphId(relation.id2), {relation: relation});
  36360. //}
  36361. dagre.layout(g);
  36362. g.nodes().forEach(function (v) {
  36363. if (typeof v !== 'undefined') {
  36364. log.debug('Node ' + v + ': ' + JSON.stringify(g.node(v)));
  36365. d3.select('#' + v).attr('transform', 'translate(' + (g.node(v).x - g.node(v).width / 2) + ',' + (g.node(v).y - g.node(v).height / 2) + ' )');
  36366. //d3.select('#' +v +' rect').attr('x',(g.node(v).x-(g.node(v).width/2)))
  36367. //.attr('y',(g.node(v).y-(g.node(v).height/2)));
  36368. }
  36369. });
  36370. g.edges().forEach(function (e) {
  36371. log.debug('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(g.edge(e)));
  36372. drawEdge(diagram, g.edge(e), g.edge(e).relation);
  36373. });
  36374. //
  36375. diagram.attr('height', '100%');
  36376. diagram.attr('width', '100%');
  36377. //
  36378. //
  36379. //
  36380. //
  36381. //if(conf.useMaxWidth) {
  36382. // diagram.attr('height', '100%');
  36383. // diagram.attr('width', '100%');
  36384. // diagram.attr('style', 'max-width:' + (width) + 'px;');
  36385. //}else{
  36386. // diagram.attr('height',height);
  36387. // diagram.attr('width', width );
  36388. //}
  36389. //diagram.attr('viewBox', (box.startx-conf.diagramMarginX) + ' -' +conf.diagramMarginY + ' ' + width + ' ' + height);
  36390. };
  36391. },{"../../d3":108,"../../logger":130,"./classDb":109,"./parser/classDiagram":111,"dagre":51}],111:[function(require,module,exports){
  36392. (function (process){
  36393. /* parser generated by jison 0.4.17 */
  36394. /*
  36395. Returns a Parser object of the following structure:
  36396. Parser: {
  36397. yy: {}
  36398. }
  36399. Parser.prototype: {
  36400. yy: {},
  36401. trace: function(),
  36402. symbols_: {associative list: name ==> number},
  36403. terminals_: {associative list: number ==> name},
  36404. productions_: [...],
  36405. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  36406. table: [...],
  36407. defaultActions: {...},
  36408. parseError: function(str, hash),
  36409. parse: function(input),
  36410. lexer: {
  36411. EOF: 1,
  36412. parseError: function(str, hash),
  36413. setInput: function(input),
  36414. input: function(),
  36415. unput: function(str),
  36416. more: function(),
  36417. less: function(n),
  36418. pastInput: function(),
  36419. upcomingInput: function(),
  36420. showPosition: function(),
  36421. test_match: function(regex_match_array, rule_index),
  36422. next: function(),
  36423. lex: function(),
  36424. begin: function(condition),
  36425. popState: function(),
  36426. _currentRules: function(),
  36427. topState: function(),
  36428. pushState: function(condition),
  36429. options: {
  36430. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  36431. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  36432. 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)
  36433. },
  36434. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  36435. rules: [...],
  36436. conditions: {associative list: name ==> set},
  36437. }
  36438. }
  36439. token location info (@$, _$, etc.): {
  36440. first_line: n,
  36441. last_line: n,
  36442. first_column: n,
  36443. last_column: n,
  36444. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  36445. }
  36446. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  36447. text: (matched text)
  36448. token: (the produced terminal token, if any)
  36449. line: (yylineno)
  36450. }
  36451. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  36452. loc: (yylloc)
  36453. expected: (string describing the set of expected tokens)
  36454. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  36455. }
  36456. */
  36457. "use strict";
  36458. var parser = (function () {
  36459. var o = function o(k, v, _o, l) {
  36460. for (_o = _o || {}, l = k.length; l--; _o[k[l]] = v);return _o;
  36461. },
  36462. $V0 = [1, 11],
  36463. $V1 = [1, 12],
  36464. $V2 = [1, 13],
  36465. $V3 = [1, 15],
  36466. $V4 = [1, 16],
  36467. $V5 = [1, 17],
  36468. $V6 = [6, 8],
  36469. $V7 = [1, 26],
  36470. $V8 = [1, 27],
  36471. $V9 = [1, 28],
  36472. $Va = [1, 29],
  36473. $Vb = [1, 30],
  36474. $Vc = [1, 31],
  36475. $Vd = [6, 8, 13, 17, 23, 26, 27, 28, 29, 30, 31],
  36476. $Ve = [6, 8, 13, 17, 23, 26, 27, 28, 29, 30, 31, 45, 46, 47],
  36477. $Vf = [23, 45, 46, 47],
  36478. $Vg = [23, 30, 31, 45, 46, 47],
  36479. $Vh = [23, 26, 27, 28, 29, 45, 46, 47],
  36480. $Vi = [6, 8, 13],
  36481. $Vj = [1, 46];
  36482. var parser = { trace: function trace() {},
  36483. yy: {},
  36484. 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 },
  36485. 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" },
  36486. 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]],
  36487. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, /* action[1] */$$, /* vstack */_$ /* lstack */) {
  36488. /* this == yyval */
  36489. var $0 = $$.length - 1;
  36490. switch (yystate) {
  36491. case 5:
  36492. this.$ = $$[$0 - 1] + $$[$0];
  36493. break;
  36494. case 6:
  36495. this.$ = $$[$0];
  36496. break;
  36497. case 7:
  36498. yy.addRelation($$[$0]);
  36499. break;
  36500. case 8:
  36501. $$[$0 - 1].title = yy.cleanupLabel($$[$0]);yy.addRelation($$[$0 - 1]);
  36502. break;
  36503. case 12:
  36504. /*console.log($$[$0-3],JSON.stringify($$[$0-1]));*/yy.addMembers($$[$0 - 3], $$[$0 - 1]);
  36505. break;
  36506. case 13:
  36507. this.$ = [$$[$0]];
  36508. break;
  36509. case 14:
  36510. $$[$0].push($$[$0 - 1]);this.$ = $$[$0];
  36511. break;
  36512. case 15:
  36513. /*console.log('Rel found',$$[$0]);*/
  36514. break;
  36515. case 16:
  36516. yy.addMembers($$[$0 - 1], yy.cleanupLabel($$[$0]));
  36517. break;
  36518. case 17:
  36519. console.warn('Member', $$[$0]);
  36520. break;
  36521. case 18:
  36522. /*console.log('sep found',$$[$0]);*/
  36523. break;
  36524. case 19:
  36525. this.$ = { 'id1': $$[$0 - 2], 'id2': $$[$0], relation: $$[$0 - 1], relationTitle1: 'none', relationTitle2: 'none' };
  36526. break;
  36527. case 20:
  36528. this.$ = { id1: $$[$0 - 3], id2: $$[$0], relation: $$[$0 - 1], relationTitle1: $$[$0 - 2], relationTitle2: 'none' };
  36529. break;
  36530. case 21:
  36531. this.$ = { id1: $$[$0 - 3], id2: $$[$0], relation: $$[$0 - 2], relationTitle1: 'none', relationTitle2: $$[$0 - 1] };
  36532. break;
  36533. case 22:
  36534. this.$ = { id1: $$[$0 - 4], id2: $$[$0], relation: $$[$0 - 2], relationTitle1: $$[$0 - 3], relationTitle2: $$[$0 - 1] };
  36535. break;
  36536. case 23:
  36537. this.$ = { type1: $$[$0 - 2], type2: $$[$0], lineType: $$[$0 - 1] };
  36538. break;
  36539. case 24:
  36540. this.$ = { type1: 'none', type2: $$[$0], lineType: $$[$0 - 1] };
  36541. break;
  36542. case 25:
  36543. this.$ = { type1: $$[$0 - 1], type2: 'none', lineType: $$[$0] };
  36544. break;
  36545. case 26:
  36546. this.$ = { type1: 'none', type2: 'none', lineType: $$[$0] };
  36547. break;
  36548. case 27:
  36549. this.$ = yy.relationType.AGGREGATION;
  36550. break;
  36551. case 28:
  36552. this.$ = yy.relationType.EXTENSION;
  36553. break;
  36554. case 29:
  36555. this.$ = yy.relationType.COMPOSITION;
  36556. break;
  36557. case 30:
  36558. this.$ = yy.relationType.DEPENDENCY;
  36559. break;
  36560. case 31:
  36561. this.$ = yy.lineType.LINE;
  36562. break;
  36563. case 32:
  36564. this.$ = yy.lineType.DOTTED_LINE;
  36565. break;
  36566. }
  36567. },
  36568. 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] }],
  36569. defaultActions: { 2: [2, 1], 18: [2, 2], 34: [2, 4], 49: [2, 14] },
  36570. parseError: function parseError(str, hash) {
  36571. if (hash.recoverable) {
  36572. this.trace(str);
  36573. } else {
  36574. var _parseError = function _parseError(msg, hash) {
  36575. this.message = msg;
  36576. this.hash = hash;
  36577. };
  36578. _parseError.prototype = Error;
  36579. throw new _parseError(str, hash);
  36580. }
  36581. },
  36582. parse: function parse(input) {
  36583. var self = this,
  36584. stack = [0],
  36585. tstack = [],
  36586. vstack = [null],
  36587. lstack = [],
  36588. table = this.table,
  36589. yytext = '',
  36590. yylineno = 0,
  36591. yyleng = 0,
  36592. recovering = 0,
  36593. TERROR = 2,
  36594. EOF = 1;
  36595. var args = lstack.slice.call(arguments, 1);
  36596. var lexer = Object.create(this.lexer);
  36597. var sharedState = { yy: {} };
  36598. for (var k in this.yy) {
  36599. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  36600. sharedState.yy[k] = this.yy[k];
  36601. }
  36602. }
  36603. lexer.setInput(input, sharedState.yy);
  36604. sharedState.yy.lexer = lexer;
  36605. sharedState.yy.parser = this;
  36606. if (typeof lexer.yylloc == 'undefined') {
  36607. lexer.yylloc = {};
  36608. }
  36609. var yyloc = lexer.yylloc;
  36610. lstack.push(yyloc);
  36611. var ranges = lexer.options && lexer.options.ranges;
  36612. if (typeof sharedState.yy.parseError === 'function') {
  36613. this.parseError = sharedState.yy.parseError;
  36614. } else {
  36615. this.parseError = Object.getPrototypeOf(this).parseError;
  36616. }
  36617. function popStack(n) {
  36618. stack.length = stack.length - 2 * n;
  36619. vstack.length = vstack.length - n;
  36620. lstack.length = lstack.length - n;
  36621. }
  36622. _token_stack: var lex = function lex() {
  36623. var token;
  36624. token = lexer.lex() || EOF;
  36625. if (typeof token !== 'number') {
  36626. token = self.symbols_[token] || token;
  36627. }
  36628. return token;
  36629. };
  36630. var symbol,
  36631. preErrorSymbol,
  36632. state,
  36633. action,
  36634. a,
  36635. r,
  36636. yyval = {},
  36637. p,
  36638. len,
  36639. newState,
  36640. expected;
  36641. while (true) {
  36642. state = stack[stack.length - 1];
  36643. if (this.defaultActions[state]) {
  36644. action = this.defaultActions[state];
  36645. } else {
  36646. if (symbol === null || typeof symbol == 'undefined') {
  36647. symbol = lex();
  36648. }
  36649. action = table[state] && table[state][symbol];
  36650. }
  36651. if (typeof action === 'undefined' || !action.length || !action[0]) {
  36652. var errStr = '';
  36653. expected = [];
  36654. for (p in table[state]) {
  36655. if (this.terminals_[p] && p > TERROR) {
  36656. expected.push('\'' + this.terminals_[p] + '\'');
  36657. }
  36658. }
  36659. if (lexer.showPosition) {
  36660. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  36661. } else {
  36662. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  36663. }
  36664. this.parseError(errStr, {
  36665. text: lexer.match,
  36666. token: this.terminals_[symbol] || symbol,
  36667. line: lexer.yylineno,
  36668. loc: yyloc,
  36669. expected: expected
  36670. });
  36671. }
  36672. if (action[0] instanceof Array && action.length > 1) {
  36673. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  36674. }
  36675. switch (action[0]) {
  36676. case 1:
  36677. stack.push(symbol);
  36678. vstack.push(lexer.yytext);
  36679. lstack.push(lexer.yylloc);
  36680. stack.push(action[1]);
  36681. symbol = null;
  36682. if (!preErrorSymbol) {
  36683. yyleng = lexer.yyleng;
  36684. yytext = lexer.yytext;
  36685. yylineno = lexer.yylineno;
  36686. yyloc = lexer.yylloc;
  36687. if (recovering > 0) {
  36688. recovering--;
  36689. }
  36690. } else {
  36691. symbol = preErrorSymbol;
  36692. preErrorSymbol = null;
  36693. }
  36694. break;
  36695. case 2:
  36696. len = this.productions_[action[1]][1];
  36697. yyval.$ = vstack[vstack.length - len];
  36698. yyval._$ = {
  36699. first_line: lstack[lstack.length - (len || 1)].first_line,
  36700. last_line: lstack[lstack.length - 1].last_line,
  36701. first_column: lstack[lstack.length - (len || 1)].first_column,
  36702. last_column: lstack[lstack.length - 1].last_column
  36703. };
  36704. if (ranges) {
  36705. yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
  36706. }
  36707. r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
  36708. if (typeof r !== 'undefined') {
  36709. return r;
  36710. }
  36711. if (len) {
  36712. stack = stack.slice(0, -1 * len * 2);
  36713. vstack = vstack.slice(0, -1 * len);
  36714. lstack = lstack.slice(0, -1 * len);
  36715. }
  36716. stack.push(this.productions_[action[1]][0]);
  36717. vstack.push(yyval.$);
  36718. lstack.push(yyval._$);
  36719. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  36720. stack.push(newState);
  36721. break;
  36722. case 3:
  36723. return true;
  36724. }
  36725. }
  36726. return true;
  36727. } };
  36728. /* generated by jison-lex 0.3.4 */
  36729. var lexer = (function () {
  36730. var lexer = {
  36731. EOF: 1,
  36732. parseError: function parseError(str, hash) {
  36733. if (this.yy.parser) {
  36734. this.yy.parser.parseError(str, hash);
  36735. } else {
  36736. throw new Error(str);
  36737. }
  36738. },
  36739. // resets the lexer, sets new input
  36740. setInput: function setInput(input, yy) {
  36741. this.yy = yy || this.yy || {};
  36742. this._input = input;
  36743. this._more = this._backtrack = this.done = false;
  36744. this.yylineno = this.yyleng = 0;
  36745. this.yytext = this.matched = this.match = '';
  36746. this.conditionStack = ['INITIAL'];
  36747. this.yylloc = {
  36748. first_line: 1,
  36749. first_column: 0,
  36750. last_line: 1,
  36751. last_column: 0
  36752. };
  36753. if (this.options.ranges) {
  36754. this.yylloc.range = [0, 0];
  36755. }
  36756. this.offset = 0;
  36757. return this;
  36758. },
  36759. // consumes and returns one char from the input
  36760. input: function input() {
  36761. var ch = this._input[0];
  36762. this.yytext += ch;
  36763. this.yyleng++;
  36764. this.offset++;
  36765. this.match += ch;
  36766. this.matched += ch;
  36767. var lines = ch.match(/(?:\r\n?|\n).*/g);
  36768. if (lines) {
  36769. this.yylineno++;
  36770. this.yylloc.last_line++;
  36771. } else {
  36772. this.yylloc.last_column++;
  36773. }
  36774. if (this.options.ranges) {
  36775. this.yylloc.range[1]++;
  36776. }
  36777. this._input = this._input.slice(1);
  36778. return ch;
  36779. },
  36780. // unshifts one char (or a string) into the input
  36781. unput: function unput(ch) {
  36782. var len = ch.length;
  36783. var lines = ch.split(/(?:\r\n?|\n)/g);
  36784. this._input = ch + this._input;
  36785. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  36786. //this.yyleng -= len;
  36787. this.offset -= len;
  36788. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  36789. this.match = this.match.substr(0, this.match.length - 1);
  36790. this.matched = this.matched.substr(0, this.matched.length - 1);
  36791. if (lines.length - 1) {
  36792. this.yylineno -= lines.length - 1;
  36793. }
  36794. var r = this.yylloc.range;
  36795. this.yylloc = {
  36796. first_line: this.yylloc.first_line,
  36797. last_line: this.yylineno + 1,
  36798. first_column: this.yylloc.first_column,
  36799. 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
  36800. };
  36801. if (this.options.ranges) {
  36802. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  36803. }
  36804. this.yyleng = this.yytext.length;
  36805. return this;
  36806. },
  36807. // When called from action, caches matched text and appends it on next action
  36808. more: function more() {
  36809. this._more = true;
  36810. return this;
  36811. },
  36812. // 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.
  36813. reject: function reject() {
  36814. if (this.options.backtrack_lexer) {
  36815. this._backtrack = true;
  36816. } else {
  36817. 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(), {
  36818. text: "",
  36819. token: null,
  36820. line: this.yylineno
  36821. });
  36822. }
  36823. return this;
  36824. },
  36825. // retain first n characters of the match
  36826. less: function less(n) {
  36827. this.unput(this.match.slice(n));
  36828. },
  36829. // displays already matched input, i.e. for error messages
  36830. pastInput: function pastInput() {
  36831. var past = this.matched.substr(0, this.matched.length - this.match.length);
  36832. return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
  36833. },
  36834. // displays upcoming input, i.e. for error messages
  36835. upcomingInput: function upcomingInput() {
  36836. var next = this.match;
  36837. if (next.length < 20) {
  36838. next += this._input.substr(0, 20 - next.length);
  36839. }
  36840. return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  36841. },
  36842. // displays the character position where the lexing error occurred, i.e. for error messages
  36843. showPosition: function showPosition() {
  36844. var pre = this.pastInput();
  36845. var c = new Array(pre.length + 1).join("-");
  36846. return pre + this.upcomingInput() + "\n" + c + "^";
  36847. },
  36848. // test the lexed token: return FALSE when not a match, otherwise return token
  36849. test_match: function test_match(match, indexed_rule) {
  36850. var token, lines, backup;
  36851. if (this.options.backtrack_lexer) {
  36852. // save context
  36853. backup = {
  36854. yylineno: this.yylineno,
  36855. yylloc: {
  36856. first_line: this.yylloc.first_line,
  36857. last_line: this.last_line,
  36858. first_column: this.yylloc.first_column,
  36859. last_column: this.yylloc.last_column
  36860. },
  36861. yytext: this.yytext,
  36862. match: this.match,
  36863. matches: this.matches,
  36864. matched: this.matched,
  36865. yyleng: this.yyleng,
  36866. offset: this.offset,
  36867. _more: this._more,
  36868. _input: this._input,
  36869. yy: this.yy,
  36870. conditionStack: this.conditionStack.slice(0),
  36871. done: this.done
  36872. };
  36873. if (this.options.ranges) {
  36874. backup.yylloc.range = this.yylloc.range.slice(0);
  36875. }
  36876. }
  36877. lines = match[0].match(/(?:\r\n?|\n).*/g);
  36878. if (lines) {
  36879. this.yylineno += lines.length;
  36880. }
  36881. this.yylloc = {
  36882. first_line: this.yylloc.last_line,
  36883. last_line: this.yylineno + 1,
  36884. first_column: this.yylloc.last_column,
  36885. last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
  36886. };
  36887. this.yytext += match[0];
  36888. this.match += match[0];
  36889. this.matches = match;
  36890. this.yyleng = this.yytext.length;
  36891. if (this.options.ranges) {
  36892. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  36893. }
  36894. this._more = false;
  36895. this._backtrack = false;
  36896. this._input = this._input.slice(match[0].length);
  36897. this.matched += match[0];
  36898. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  36899. if (this.done && this._input) {
  36900. this.done = false;
  36901. }
  36902. if (token) {
  36903. return token;
  36904. } else if (this._backtrack) {
  36905. // recover context
  36906. for (var k in backup) {
  36907. this[k] = backup[k];
  36908. }
  36909. return false; // rule action called reject() implying the next rule should be tested instead.
  36910. }
  36911. return false;
  36912. },
  36913. // return next match in input
  36914. next: function next() {
  36915. if (this.done) {
  36916. return this.EOF;
  36917. }
  36918. if (!this._input) {
  36919. this.done = true;
  36920. }
  36921. var token, match, tempMatch, index;
  36922. if (!this._more) {
  36923. this.yytext = '';
  36924. this.match = '';
  36925. }
  36926. var rules = this._currentRules();
  36927. for (var i = 0; i < rules.length; i++) {
  36928. tempMatch = this._input.match(this.rules[rules[i]]);
  36929. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  36930. match = tempMatch;
  36931. index = i;
  36932. if (this.options.backtrack_lexer) {
  36933. token = this.test_match(tempMatch, rules[i]);
  36934. if (token !== false) {
  36935. return token;
  36936. } else if (this._backtrack) {
  36937. match = false;
  36938. continue; // rule action called reject() implying a rule MISmatch.
  36939. } else {
  36940. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  36941. return false;
  36942. }
  36943. } else if (!this.options.flex) {
  36944. break;
  36945. }
  36946. }
  36947. }
  36948. if (match) {
  36949. token = this.test_match(match, rules[index]);
  36950. if (token !== false) {
  36951. return token;
  36952. }
  36953. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  36954. return false;
  36955. }
  36956. if (this._input === "") {
  36957. return this.EOF;
  36958. } else {
  36959. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  36960. text: "",
  36961. token: null,
  36962. line: this.yylineno
  36963. });
  36964. }
  36965. },
  36966. // return next match that has a token
  36967. lex: function lex() {
  36968. var r = this.next();
  36969. if (r) {
  36970. return r;
  36971. } else {
  36972. return this.lex();
  36973. }
  36974. },
  36975. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  36976. begin: function begin(condition) {
  36977. this.conditionStack.push(condition);
  36978. },
  36979. // pop the previously active lexer condition state off the condition stack
  36980. popState: function popState() {
  36981. var n = this.conditionStack.length - 1;
  36982. if (n > 0) {
  36983. return this.conditionStack.pop();
  36984. } else {
  36985. return this.conditionStack[0];
  36986. }
  36987. },
  36988. // produce the lexer rule set which is active for the currently active lexer condition state
  36989. _currentRules: function _currentRules() {
  36990. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  36991. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  36992. } else {
  36993. return this.conditions["INITIAL"].rules;
  36994. }
  36995. },
  36996. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  36997. topState: function topState(n) {
  36998. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  36999. if (n >= 0) {
  37000. return this.conditionStack[n];
  37001. } else {
  37002. return "INITIAL";
  37003. }
  37004. },
  37005. // alias for begin(condition)
  37006. pushState: function pushState(condition) {
  37007. this.begin(condition);
  37008. },
  37009. // return the number of states currently on the stack
  37010. stateStackSize: function stateStackSize() {
  37011. return this.conditionStack.length;
  37012. },
  37013. options: {},
  37014. performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
  37015. var YYSTATE = YY_START;
  37016. switch ($avoiding_name_collisions) {
  37017. case 0:
  37018. /* do nothing */
  37019. break;
  37020. case 1:
  37021. return 6;
  37022. break;
  37023. case 2:
  37024. /* skip whitespace */
  37025. break;
  37026. case 3:
  37027. return 5;
  37028. break;
  37029. case 4:
  37030. this.begin("struct"); /*console.log('Starting struct');*/return 17;
  37031. break;
  37032. case 5:
  37033. /*console.log('Ending struct');*/this.popState();return 19;
  37034. break;
  37035. case 6:
  37036. /* nothing */
  37037. break;
  37038. case 7:
  37039. /*console.log('lex-member: ' + yy_.yytext);*/return "MEMBER";
  37040. break;
  37041. case 8:
  37042. return 16;
  37043. break;
  37044. case 9:
  37045. this.begin("string");
  37046. break;
  37047. case 10:
  37048. this.popState();
  37049. break;
  37050. case 11:
  37051. return "STR";
  37052. break;
  37053. case 12:
  37054. return 27;
  37055. break;
  37056. case 13:
  37057. return 27;
  37058. break;
  37059. case 14:
  37060. return 29;
  37061. break;
  37062. case 15:
  37063. return 29;
  37064. break;
  37065. case 16:
  37066. return 28;
  37067. break;
  37068. case 17:
  37069. return 26;
  37070. break;
  37071. case 18:
  37072. return 30;
  37073. break;
  37074. case 19:
  37075. return 31;
  37076. break;
  37077. case 20:
  37078. return 13;
  37079. break;
  37080. case 21:
  37081. return 43;
  37082. break;
  37083. case 22:
  37084. return 'DOT';
  37085. break;
  37086. case 23:
  37087. return 'PLUS';
  37088. break;
  37089. case 24:
  37090. return 40;
  37091. break;
  37092. case 25:
  37093. return 'EQUALS';
  37094. break;
  37095. case 26:
  37096. return 'EQUALS';
  37097. break;
  37098. case 27:
  37099. return 47;
  37100. break;
  37101. case 28:
  37102. return 'PUNCTUATION';
  37103. break;
  37104. case 29:
  37105. return 46;
  37106. break;
  37107. case 30:
  37108. return 45;
  37109. break;
  37110. case 31:
  37111. return 42;
  37112. break;
  37113. case 32:
  37114. return 8;
  37115. break;
  37116. }
  37117. },
  37118. 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)/, /^(?:$)/],
  37119. 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 } }
  37120. };
  37121. return lexer;
  37122. })();
  37123. parser.lexer = lexer;
  37124. function Parser() {
  37125. this.yy = {};
  37126. }
  37127. Parser.prototype = parser;parser.Parser = Parser;
  37128. return new Parser();
  37129. })();
  37130. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  37131. exports.parser = parser;
  37132. exports.Parser = parser.Parser;
  37133. exports.parse = function () {
  37134. return parser.parse.apply(parser, arguments);
  37135. };
  37136. exports.main = function commonjsMain(args) {
  37137. if (!args[1]) {
  37138. console.log('Usage: ' + args[0] + ' FILE');
  37139. process.exit(1);
  37140. }
  37141. var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
  37142. return exports.parser.parse(source);
  37143. };
  37144. if (typeof module !== 'undefined' && require.main === module) {
  37145. exports.main(process.argv.slice(1));
  37146. }
  37147. }
  37148. }).call(this,require('_process'))
  37149. },{"_process":106,"fs":1,"path":105}],112:[function(require,module,exports){
  37150. (function (global){
  37151. /**
  37152. * Created by knut on 15-01-14.
  37153. */
  37154. 'use strict';
  37155. var Logger = require('../../logger');
  37156. var log = new Logger.Log();
  37157. var message = '';
  37158. var info = false;
  37159. exports.setMessage = function (txt) {
  37160. log.debug('Setting message to: ' + txt);
  37161. message = txt;
  37162. };
  37163. exports.getMessage = function () {
  37164. return message;
  37165. };
  37166. exports.setInfo = function (inf) {
  37167. info = inf;
  37168. };
  37169. exports.getInfo = function () {
  37170. return info;
  37171. };
  37172. exports.parseError = function (err, hash) {
  37173. global.mermaidAPI.parseError(err, hash);
  37174. };
  37175. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  37176. },{"../../logger":130}],113:[function(require,module,exports){
  37177. /**
  37178. * Created by knut on 14-12-11.
  37179. */
  37180. 'use strict';
  37181. var db = require('./exampleDb');
  37182. var exampleParser = require('./parser/example.js');
  37183. var d3 = require('../../d3');
  37184. var Logger = require('../../logger');
  37185. var log = new Logger.Log();
  37186. /**
  37187. * Draws a an info picture in the tag with id: id based on the graph definition in text.
  37188. * @param text
  37189. * @param id
  37190. */
  37191. exports.draw = function (txt, id, ver) {
  37192. var parser;
  37193. parser = exampleParser.parser;
  37194. parser.yy = db;
  37195. log.debug('Renering example diagram');
  37196. // Parse the graph definition
  37197. parser.parse(txt);
  37198. // Fetch the default direction, use TD if none was found
  37199. var svg = d3.select('#' + id);
  37200. var g = svg.append('g');
  37201. g.append('text') // text label for the x axis
  37202. .attr('x', 100).attr('y', 40).attr('class', 'version').attr('font-size', '32px').style('text-anchor', 'middle').text('mermaid ' + ver);
  37203. /*
  37204. var box = exports.bounds.getBounds();
  37205. var height = box.stopy-box.starty+2*conf.diagramMarginY;
  37206. var width = box.stopx-box.startx+2*conf.diagramMarginX;*/
  37207. svg.attr('height', 100);
  37208. svg.attr('width', 400);
  37209. //svg.attr('viewBox', '0 0 300 150');
  37210. };
  37211. },{"../../d3":108,"../../logger":130,"./exampleDb":112,"./parser/example.js":114}],114:[function(require,module,exports){
  37212. (function (process){
  37213. /* parser generated by jison 0.4.17 */
  37214. /*
  37215. Returns a Parser object of the following structure:
  37216. Parser: {
  37217. yy: {}
  37218. }
  37219. Parser.prototype: {
  37220. yy: {},
  37221. trace: function(),
  37222. symbols_: {associative list: name ==> number},
  37223. terminals_: {associative list: number ==> name},
  37224. productions_: [...],
  37225. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  37226. table: [...],
  37227. defaultActions: {...},
  37228. parseError: function(str, hash),
  37229. parse: function(input),
  37230. lexer: {
  37231. EOF: 1,
  37232. parseError: function(str, hash),
  37233. setInput: function(input),
  37234. input: function(),
  37235. unput: function(str),
  37236. more: function(),
  37237. less: function(n),
  37238. pastInput: function(),
  37239. upcomingInput: function(),
  37240. showPosition: function(),
  37241. test_match: function(regex_match_array, rule_index),
  37242. next: function(),
  37243. lex: function(),
  37244. begin: function(condition),
  37245. popState: function(),
  37246. _currentRules: function(),
  37247. topState: function(),
  37248. pushState: function(condition),
  37249. options: {
  37250. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  37251. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  37252. 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)
  37253. },
  37254. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  37255. rules: [...],
  37256. conditions: {associative list: name ==> set},
  37257. }
  37258. }
  37259. token location info (@$, _$, etc.): {
  37260. first_line: n,
  37261. last_line: n,
  37262. first_column: n,
  37263. last_column: n,
  37264. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  37265. }
  37266. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  37267. text: (matched text)
  37268. token: (the produced terminal token, if any)
  37269. line: (yylineno)
  37270. }
  37271. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  37272. loc: (yylloc)
  37273. expected: (string describing the set of expected tokens)
  37274. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  37275. }
  37276. */
  37277. "use strict";
  37278. var parser = (function () {
  37279. var o = function o(k, v, _o, l) {
  37280. for (_o = _o || {}, l = k.length; l--; _o[k[l]] = v);return _o;
  37281. },
  37282. $V0 = [6, 9, 10, 12];
  37283. var parser = { trace: function trace() {},
  37284. yy: {},
  37285. 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 },
  37286. terminals_: { 2: "error", 4: "info", 6: "EOF", 9: "NL", 10: "showInfo", 12: "say", 13: "TXT" },
  37287. productions_: [0, [3, 3], [5, 0], [5, 2], [7, 1], [7, 1], [8, 1], [8, 1], [11, 2]],
  37288. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, /* action[1] */$$, /* vstack */_$ /* lstack */) {
  37289. /* this == yyval */
  37290. var $0 = $$.length - 1;
  37291. switch (yystate) {
  37292. case 1:
  37293. return yy;
  37294. break;
  37295. case 4:
  37296. break;
  37297. case 6:
  37298. yy.setInfo(true);
  37299. break;
  37300. case 7:
  37301. yy.setMessage($$[$0]);
  37302. break;
  37303. case 8:
  37304. this.$ = $$[$0 - 1].substring(1).trim().replace(/\\n/gm, "\n");
  37305. break;
  37306. }
  37307. },
  37308. 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])],
  37309. defaultActions: { 4: [2, 1] },
  37310. parseError: function parseError(str, hash) {
  37311. if (hash.recoverable) {
  37312. this.trace(str);
  37313. } else {
  37314. var _parseError = function _parseError(msg, hash) {
  37315. this.message = msg;
  37316. this.hash = hash;
  37317. };
  37318. _parseError.prototype = Error;
  37319. throw new _parseError(str, hash);
  37320. }
  37321. },
  37322. parse: function parse(input) {
  37323. var self = this,
  37324. stack = [0],
  37325. tstack = [],
  37326. vstack = [null],
  37327. lstack = [],
  37328. table = this.table,
  37329. yytext = '',
  37330. yylineno = 0,
  37331. yyleng = 0,
  37332. recovering = 0,
  37333. TERROR = 2,
  37334. EOF = 1;
  37335. var args = lstack.slice.call(arguments, 1);
  37336. var lexer = Object.create(this.lexer);
  37337. var sharedState = { yy: {} };
  37338. for (var k in this.yy) {
  37339. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  37340. sharedState.yy[k] = this.yy[k];
  37341. }
  37342. }
  37343. lexer.setInput(input, sharedState.yy);
  37344. sharedState.yy.lexer = lexer;
  37345. sharedState.yy.parser = this;
  37346. if (typeof lexer.yylloc == 'undefined') {
  37347. lexer.yylloc = {};
  37348. }
  37349. var yyloc = lexer.yylloc;
  37350. lstack.push(yyloc);
  37351. var ranges = lexer.options && lexer.options.ranges;
  37352. if (typeof sharedState.yy.parseError === 'function') {
  37353. this.parseError = sharedState.yy.parseError;
  37354. } else {
  37355. this.parseError = Object.getPrototypeOf(this).parseError;
  37356. }
  37357. function popStack(n) {
  37358. stack.length = stack.length - 2 * n;
  37359. vstack.length = vstack.length - n;
  37360. lstack.length = lstack.length - n;
  37361. }
  37362. _token_stack: var lex = function lex() {
  37363. var token;
  37364. token = lexer.lex() || EOF;
  37365. if (typeof token !== 'number') {
  37366. token = self.symbols_[token] || token;
  37367. }
  37368. return token;
  37369. };
  37370. var symbol,
  37371. preErrorSymbol,
  37372. state,
  37373. action,
  37374. a,
  37375. r,
  37376. yyval = {},
  37377. p,
  37378. len,
  37379. newState,
  37380. expected;
  37381. while (true) {
  37382. state = stack[stack.length - 1];
  37383. if (this.defaultActions[state]) {
  37384. action = this.defaultActions[state];
  37385. } else {
  37386. if (symbol === null || typeof symbol == 'undefined') {
  37387. symbol = lex();
  37388. }
  37389. action = table[state] && table[state][symbol];
  37390. }
  37391. if (typeof action === 'undefined' || !action.length || !action[0]) {
  37392. var errStr = '';
  37393. expected = [];
  37394. for (p in table[state]) {
  37395. if (this.terminals_[p] && p > TERROR) {
  37396. expected.push('\'' + this.terminals_[p] + '\'');
  37397. }
  37398. }
  37399. if (lexer.showPosition) {
  37400. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  37401. } else {
  37402. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  37403. }
  37404. this.parseError(errStr, {
  37405. text: lexer.match,
  37406. token: this.terminals_[symbol] || symbol,
  37407. line: lexer.yylineno,
  37408. loc: yyloc,
  37409. expected: expected
  37410. });
  37411. }
  37412. if (action[0] instanceof Array && action.length > 1) {
  37413. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  37414. }
  37415. switch (action[0]) {
  37416. case 1:
  37417. stack.push(symbol);
  37418. vstack.push(lexer.yytext);
  37419. lstack.push(lexer.yylloc);
  37420. stack.push(action[1]);
  37421. symbol = null;
  37422. if (!preErrorSymbol) {
  37423. yyleng = lexer.yyleng;
  37424. yytext = lexer.yytext;
  37425. yylineno = lexer.yylineno;
  37426. yyloc = lexer.yylloc;
  37427. if (recovering > 0) {
  37428. recovering--;
  37429. }
  37430. } else {
  37431. symbol = preErrorSymbol;
  37432. preErrorSymbol = null;
  37433. }
  37434. break;
  37435. case 2:
  37436. len = this.productions_[action[1]][1];
  37437. yyval.$ = vstack[vstack.length - len];
  37438. yyval._$ = {
  37439. first_line: lstack[lstack.length - (len || 1)].first_line,
  37440. last_line: lstack[lstack.length - 1].last_line,
  37441. first_column: lstack[lstack.length - (len || 1)].first_column,
  37442. last_column: lstack[lstack.length - 1].last_column
  37443. };
  37444. if (ranges) {
  37445. yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
  37446. }
  37447. r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
  37448. if (typeof r !== 'undefined') {
  37449. return r;
  37450. }
  37451. if (len) {
  37452. stack = stack.slice(0, -1 * len * 2);
  37453. vstack = vstack.slice(0, -1 * len);
  37454. lstack = lstack.slice(0, -1 * len);
  37455. }
  37456. stack.push(this.productions_[action[1]][0]);
  37457. vstack.push(yyval.$);
  37458. lstack.push(yyval._$);
  37459. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  37460. stack.push(newState);
  37461. break;
  37462. case 3:
  37463. return true;
  37464. }
  37465. }
  37466. return true;
  37467. } };
  37468. /* generated by jison-lex 0.3.4 */
  37469. var lexer = (function () {
  37470. var lexer = {
  37471. EOF: 1,
  37472. parseError: function parseError(str, hash) {
  37473. if (this.yy.parser) {
  37474. this.yy.parser.parseError(str, hash);
  37475. } else {
  37476. throw new Error(str);
  37477. }
  37478. },
  37479. // resets the lexer, sets new input
  37480. setInput: function setInput(input, yy) {
  37481. this.yy = yy || this.yy || {};
  37482. this._input = input;
  37483. this._more = this._backtrack = this.done = false;
  37484. this.yylineno = this.yyleng = 0;
  37485. this.yytext = this.matched = this.match = '';
  37486. this.conditionStack = ['INITIAL'];
  37487. this.yylloc = {
  37488. first_line: 1,
  37489. first_column: 0,
  37490. last_line: 1,
  37491. last_column: 0
  37492. };
  37493. if (this.options.ranges) {
  37494. this.yylloc.range = [0, 0];
  37495. }
  37496. this.offset = 0;
  37497. return this;
  37498. },
  37499. // consumes and returns one char from the input
  37500. input: function input() {
  37501. var ch = this._input[0];
  37502. this.yytext += ch;
  37503. this.yyleng++;
  37504. this.offset++;
  37505. this.match += ch;
  37506. this.matched += ch;
  37507. var lines = ch.match(/(?:\r\n?|\n).*/g);
  37508. if (lines) {
  37509. this.yylineno++;
  37510. this.yylloc.last_line++;
  37511. } else {
  37512. this.yylloc.last_column++;
  37513. }
  37514. if (this.options.ranges) {
  37515. this.yylloc.range[1]++;
  37516. }
  37517. this._input = this._input.slice(1);
  37518. return ch;
  37519. },
  37520. // unshifts one char (or a string) into the input
  37521. unput: function unput(ch) {
  37522. var len = ch.length;
  37523. var lines = ch.split(/(?:\r\n?|\n)/g);
  37524. this._input = ch + this._input;
  37525. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  37526. //this.yyleng -= len;
  37527. this.offset -= len;
  37528. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  37529. this.match = this.match.substr(0, this.match.length - 1);
  37530. this.matched = this.matched.substr(0, this.matched.length - 1);
  37531. if (lines.length - 1) {
  37532. this.yylineno -= lines.length - 1;
  37533. }
  37534. var r = this.yylloc.range;
  37535. this.yylloc = {
  37536. first_line: this.yylloc.first_line,
  37537. last_line: this.yylineno + 1,
  37538. first_column: this.yylloc.first_column,
  37539. 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
  37540. };
  37541. if (this.options.ranges) {
  37542. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  37543. }
  37544. this.yyleng = this.yytext.length;
  37545. return this;
  37546. },
  37547. // When called from action, caches matched text and appends it on next action
  37548. more: function more() {
  37549. this._more = true;
  37550. return this;
  37551. },
  37552. // 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.
  37553. reject: function reject() {
  37554. if (this.options.backtrack_lexer) {
  37555. this._backtrack = true;
  37556. } else {
  37557. 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(), {
  37558. text: "",
  37559. token: null,
  37560. line: this.yylineno
  37561. });
  37562. }
  37563. return this;
  37564. },
  37565. // retain first n characters of the match
  37566. less: function less(n) {
  37567. this.unput(this.match.slice(n));
  37568. },
  37569. // displays already matched input, i.e. for error messages
  37570. pastInput: function pastInput() {
  37571. var past = this.matched.substr(0, this.matched.length - this.match.length);
  37572. return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
  37573. },
  37574. // displays upcoming input, i.e. for error messages
  37575. upcomingInput: function upcomingInput() {
  37576. var next = this.match;
  37577. if (next.length < 20) {
  37578. next += this._input.substr(0, 20 - next.length);
  37579. }
  37580. return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  37581. },
  37582. // displays the character position where the lexing error occurred, i.e. for error messages
  37583. showPosition: function showPosition() {
  37584. var pre = this.pastInput();
  37585. var c = new Array(pre.length + 1).join("-");
  37586. return pre + this.upcomingInput() + "\n" + c + "^";
  37587. },
  37588. // test the lexed token: return FALSE when not a match, otherwise return token
  37589. test_match: function test_match(match, indexed_rule) {
  37590. var token, lines, backup;
  37591. if (this.options.backtrack_lexer) {
  37592. // save context
  37593. backup = {
  37594. yylineno: this.yylineno,
  37595. yylloc: {
  37596. first_line: this.yylloc.first_line,
  37597. last_line: this.last_line,
  37598. first_column: this.yylloc.first_column,
  37599. last_column: this.yylloc.last_column
  37600. },
  37601. yytext: this.yytext,
  37602. match: this.match,
  37603. matches: this.matches,
  37604. matched: this.matched,
  37605. yyleng: this.yyleng,
  37606. offset: this.offset,
  37607. _more: this._more,
  37608. _input: this._input,
  37609. yy: this.yy,
  37610. conditionStack: this.conditionStack.slice(0),
  37611. done: this.done
  37612. };
  37613. if (this.options.ranges) {
  37614. backup.yylloc.range = this.yylloc.range.slice(0);
  37615. }
  37616. }
  37617. lines = match[0].match(/(?:\r\n?|\n).*/g);
  37618. if (lines) {
  37619. this.yylineno += lines.length;
  37620. }
  37621. this.yylloc = {
  37622. first_line: this.yylloc.last_line,
  37623. last_line: this.yylineno + 1,
  37624. first_column: this.yylloc.last_column,
  37625. last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
  37626. };
  37627. this.yytext += match[0];
  37628. this.match += match[0];
  37629. this.matches = match;
  37630. this.yyleng = this.yytext.length;
  37631. if (this.options.ranges) {
  37632. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  37633. }
  37634. this._more = false;
  37635. this._backtrack = false;
  37636. this._input = this._input.slice(match[0].length);
  37637. this.matched += match[0];
  37638. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  37639. if (this.done && this._input) {
  37640. this.done = false;
  37641. }
  37642. if (token) {
  37643. return token;
  37644. } else if (this._backtrack) {
  37645. // recover context
  37646. for (var k in backup) {
  37647. this[k] = backup[k];
  37648. }
  37649. return false; // rule action called reject() implying the next rule should be tested instead.
  37650. }
  37651. return false;
  37652. },
  37653. // return next match in input
  37654. next: function next() {
  37655. if (this.done) {
  37656. return this.EOF;
  37657. }
  37658. if (!this._input) {
  37659. this.done = true;
  37660. }
  37661. var token, match, tempMatch, index;
  37662. if (!this._more) {
  37663. this.yytext = '';
  37664. this.match = '';
  37665. }
  37666. var rules = this._currentRules();
  37667. for (var i = 0; i < rules.length; i++) {
  37668. tempMatch = this._input.match(this.rules[rules[i]]);
  37669. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  37670. match = tempMatch;
  37671. index = i;
  37672. if (this.options.backtrack_lexer) {
  37673. token = this.test_match(tempMatch, rules[i]);
  37674. if (token !== false) {
  37675. return token;
  37676. } else if (this._backtrack) {
  37677. match = false;
  37678. continue; // rule action called reject() implying a rule MISmatch.
  37679. } else {
  37680. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  37681. return false;
  37682. }
  37683. } else if (!this.options.flex) {
  37684. break;
  37685. }
  37686. }
  37687. }
  37688. if (match) {
  37689. token = this.test_match(match, rules[index]);
  37690. if (token !== false) {
  37691. return token;
  37692. }
  37693. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  37694. return false;
  37695. }
  37696. if (this._input === "") {
  37697. return this.EOF;
  37698. } else {
  37699. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  37700. text: "",
  37701. token: null,
  37702. line: this.yylineno
  37703. });
  37704. }
  37705. },
  37706. // return next match that has a token
  37707. lex: function lex() {
  37708. var r = this.next();
  37709. if (r) {
  37710. return r;
  37711. } else {
  37712. return this.lex();
  37713. }
  37714. },
  37715. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  37716. begin: function begin(condition) {
  37717. this.conditionStack.push(condition);
  37718. },
  37719. // pop the previously active lexer condition state off the condition stack
  37720. popState: function popState() {
  37721. var n = this.conditionStack.length - 1;
  37722. if (n > 0) {
  37723. return this.conditionStack.pop();
  37724. } else {
  37725. return this.conditionStack[0];
  37726. }
  37727. },
  37728. // produce the lexer rule set which is active for the currently active lexer condition state
  37729. _currentRules: function _currentRules() {
  37730. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  37731. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  37732. } else {
  37733. return this.conditions["INITIAL"].rules;
  37734. }
  37735. },
  37736. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  37737. topState: function topState(n) {
  37738. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  37739. if (n >= 0) {
  37740. return this.conditionStack[n];
  37741. } else {
  37742. return "INITIAL";
  37743. }
  37744. },
  37745. // alias for begin(condition)
  37746. pushState: function pushState(condition) {
  37747. this.begin(condition);
  37748. },
  37749. // return the number of states currently on the stack
  37750. stateStackSize: function stateStackSize() {
  37751. return this.conditionStack.length;
  37752. },
  37753. options: { "case-insensitive": true },
  37754. performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
  37755. // Pre-lexer code can go here
  37756. var YYSTATE = YY_START;
  37757. switch ($avoiding_name_collisions) {
  37758. case 0:
  37759. return 9;
  37760. break;
  37761. case 1:
  37762. return 10;
  37763. break;
  37764. case 2:
  37765. return 4;
  37766. break;
  37767. case 3:
  37768. return 12;
  37769. break;
  37770. case 4:
  37771. return 13;
  37772. break;
  37773. case 5:
  37774. return 6;
  37775. break;
  37776. case 6:
  37777. return 'INVALID';
  37778. break;
  37779. }
  37780. },
  37781. rules: [/^(?:[\n]+)/i, /^(?:showInfo\b)/i, /^(?:info\b)/i, /^(?:say\b)/i, /^(?::[^#\n;]+)/i, /^(?:$)/i, /^(?:.)/i],
  37782. conditions: { "INITIAL": { "rules": [0, 1, 2, 3, 4, 5, 6], "inclusive": true } }
  37783. };
  37784. return lexer;
  37785. })();
  37786. parser.lexer = lexer;
  37787. function Parser() {
  37788. this.yy = {};
  37789. }
  37790. Parser.prototype = parser;parser.Parser = Parser;
  37791. return new Parser();
  37792. })();
  37793. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  37794. exports.parser = parser;
  37795. exports.Parser = parser.Parser;
  37796. exports.parse = function () {
  37797. return parser.parse.apply(parser, arguments);
  37798. };
  37799. exports.main = function commonjsMain(args) {
  37800. if (!args[1]) {
  37801. console.log('Usage: ' + args[0] + ' FILE');
  37802. process.exit(1);
  37803. }
  37804. var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
  37805. return exports.parser.parse(source);
  37806. };
  37807. if (typeof module !== 'undefined' && require.main === module) {
  37808. exports.main(process.argv.slice(1));
  37809. }
  37810. }
  37811. }).call(this,require('_process'))
  37812. },{"_process":106,"fs":1,"path":105}],115:[function(require,module,exports){
  37813. /* global window */
  37814. 'use strict';
  37815. var Logger = require('../../logger');
  37816. var log = new Logger.Log();
  37817. var dagreD3;
  37818. //log.debug('setting up dagre-d3');
  37819. if (require) {
  37820. try {
  37821. dagreD3 = require('dagre-d3');
  37822. //log.debug('Got it (dagre-d3)');
  37823. } catch (e) {
  37824. log.debug('Could not load dagre-d3');
  37825. }
  37826. }
  37827. if (!dagreD3) {
  37828. dagreD3 = window.dagreD3;
  37829. }
  37830. module.exports = dagreD3;
  37831. },{"../../logger":130,"dagre-d3":2}],116:[function(require,module,exports){
  37832. /**
  37833. * Created by knut on 14-12-11.
  37834. */
  37835. 'use strict';
  37836. var graph = require('./graphDb');
  37837. var flow = require('./parser/flow');
  37838. var dot = require('./parser/dot');
  37839. var d3 = require('../../d3');
  37840. var dagreD3 = require('./dagre-d3');
  37841. var Logger = require('../../logger');
  37842. var log = new Logger.Log();
  37843. var conf = {};
  37844. module.exports.setConf = function (cnf) {
  37845. var keys = Object.keys(cnf);
  37846. var i;
  37847. for (i = 0; i < keys.length; i++) {
  37848. conf[keys[i]] = cnf[keys[i]];
  37849. }
  37850. };
  37851. /**
  37852. * Function that adds the vertices found in the graph definition to the graph to be rendered.
  37853. * @param vert Object containing the vertices.
  37854. * @param g The graph that is to be drawn.
  37855. */
  37856. exports.addVertices = function (vert, g) {
  37857. var keys = Object.keys(vert);
  37858. var styleFromStyleArr = function styleFromStyleArr(styleStr, arr) {
  37859. var i;
  37860. // Create a compound style definition from the style definitions found for the node in the graph definition
  37861. for (i = 0; i < arr.length; i++) {
  37862. if (typeof arr[i] !== 'undefined') {
  37863. styleStr = styleStr + arr[i] + ';';
  37864. }
  37865. }
  37866. return styleStr;
  37867. };
  37868. // Iterate through each item in the vertice object (containing all the vertices found) in the graph definition
  37869. keys.forEach(function (id) {
  37870. var vertice = vert[id];
  37871. var verticeText;
  37872. /**
  37873. * Variable for storing the classes for the vertice
  37874. * @type {string}
  37875. */
  37876. var classStr = '';
  37877. //log.debug(vertice.classes);
  37878. if (vertice.classes.length > 0) {
  37879. classStr = vertice.classes.join(' ');
  37880. }
  37881. /**
  37882. * Variable for storing the extracted style for the vertice
  37883. * @type {string}
  37884. */
  37885. var style = '';
  37886. // Create a compound style definition from the style definitions found for the node in the graph definition
  37887. style = styleFromStyleArr(style, vertice.styles);
  37888. // Use vertice id as text in the box if no text is provided by the graph definition
  37889. if (typeof vertice.text === 'undefined') {
  37890. verticeText = vertice.id;
  37891. } else {
  37892. verticeText = vertice.text;
  37893. }
  37894. var labelTypeStr = '';
  37895. if (conf.htmlLabels) {
  37896. labelTypeStr = 'html';
  37897. verticeText = verticeText.replace(/fa:fa[\w\-]+/g, function (s) {
  37898. return '<i class="fa ' + s.substring(3) + '"></i>';
  37899. });
  37900. } else {
  37901. var svg_label = document.createElementNS('http://www.w3.org/2000/svg', 'text');
  37902. var rows = verticeText.split(/<br>/);
  37903. var j = 0;
  37904. for (j = 0; j < rows.length; j++) {
  37905. var tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan');
  37906. tspan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
  37907. tspan.setAttribute('dy', '1em');
  37908. tspan.setAttribute('x', '1');
  37909. tspan.textContent = rows[j];
  37910. svg_label.appendChild(tspan);
  37911. }
  37912. labelTypeStr = 'svg';
  37913. verticeText = svg_label;
  37914. //verticeText = verticeText.replace(/<br\/>/g, '\n');
  37915. //labelTypeStr = 'text';
  37916. }
  37917. var radious = 0;
  37918. var _shape = '';
  37919. // Set the shape based parameters
  37920. switch (vertice.type) {
  37921. case 'round':
  37922. radious = 5;
  37923. _shape = 'rect';
  37924. break;
  37925. case 'square':
  37926. _shape = 'rect';
  37927. break;
  37928. case 'diamond':
  37929. _shape = 'question';
  37930. break;
  37931. case 'odd':
  37932. _shape = 'rect_left_inv_arrow';
  37933. break;
  37934. case 'odd_right':
  37935. _shape = 'rect_left_inv_arrow';
  37936. break;
  37937. case 'circle':
  37938. _shape = 'circle';
  37939. break;
  37940. case 'ellipse':
  37941. _shape = 'ellipse';
  37942. break;
  37943. case 'group':
  37944. _shape = 'rect';
  37945. // Need to create a text node if using svg labels, see #367
  37946. verticeText = conf.htmlLabels ? '' : document.createElementNS('http://www.w3.org/2000/svg', 'text');
  37947. break;
  37948. default:
  37949. _shape = 'rect';
  37950. }
  37951. // Add the node
  37952. g.setNode(vertice.id, { labelType: labelTypeStr, shape: _shape, label: verticeText, rx: radious, ry: radious, 'class': classStr, style: style, id: vertice.id });
  37953. });
  37954. };
  37955. /**
  37956. * Add edges to graph based on parsed graph defninition
  37957. * @param {Object} edges The edges to add to the graph
  37958. * @param {Object} g The graph object
  37959. */
  37960. exports.addEdges = function (edges, g) {
  37961. var cnt = 0;
  37962. var defaultStyle;
  37963. if (typeof edges.defaultStyle !== 'undefined') {
  37964. defaultStyle = edges.defaultStyle.toString().replace(/,/g, ';');
  37965. }
  37966. edges.forEach(function (edge) {
  37967. cnt++;
  37968. var edgeData = {};
  37969. // Set link type for rendering
  37970. if (edge.type === 'arrow_open') {
  37971. edgeData.arrowhead = 'none';
  37972. } else {
  37973. edgeData.arrowhead = 'normal';
  37974. }
  37975. var style = '';
  37976. if (typeof edge.style !== 'undefined') {
  37977. edge.style.forEach(function (s) {
  37978. style = style + s + ';';
  37979. });
  37980. } else {
  37981. switch (edge.stroke) {
  37982. case 'normal':
  37983. style = 'fill:none';
  37984. if (typeof defaultStyle !== 'undefined') {
  37985. style = defaultStyle;
  37986. }
  37987. break;
  37988. case 'dotted':
  37989. style = 'stroke: #333; fill:none;stroke-width:2px;stroke-dasharray:3;';
  37990. break;
  37991. case 'thick':
  37992. style = 'stroke: #333; stroke-width: 3.5px;fill:none';
  37993. break;
  37994. }
  37995. }
  37996. edgeData.style = style;
  37997. if (typeof edge.interpolate !== 'undefined') {
  37998. edgeData.lineInterpolate = edge.interpolate;
  37999. } else {
  38000. if (typeof edges.defaultInterpolate !== 'undefined') {
  38001. edgeData.lineInterpolate = edges.defaultInterpolate;
  38002. }
  38003. }
  38004. if (typeof edge.text === 'undefined') {
  38005. if (typeof edge.style !== 'undefined') {
  38006. edgeData.arrowheadStyle = 'fill: #333';
  38007. }
  38008. } else {
  38009. edgeData.arrowheadStyle = 'fill: #333';
  38010. if (typeof edge.style === 'undefined') {
  38011. edgeData.labelpos = 'c';
  38012. if (conf.htmlLabels) {
  38013. edgeData.labelType = 'html';
  38014. edgeData.label = '<span class="edgeLabel">' + edge.text + '</span>';
  38015. } else {
  38016. edgeData.labelType = 'text';
  38017. edgeData.style = 'stroke: #333; stroke-width: 1.5px;fill:none';
  38018. edgeData.label = edge.text.replace(/<br>/g, '\n');
  38019. }
  38020. } else {
  38021. edgeData.label = edge.text.replace(/<br>/g, '\n');
  38022. }
  38023. }
  38024. // Add the edge to the graph
  38025. g.setEdge(edge.start, edge.end, edgeData, cnt);
  38026. });
  38027. };
  38028. /**
  38029. * Returns the all the styles from classDef statements in the graph definition.
  38030. * @returns {object} classDef styles
  38031. */
  38032. exports.getClasses = function (text, isDot) {
  38033. var parser;
  38034. graph.clear();
  38035. if (isDot) {
  38036. parser = dot.parser;
  38037. } else {
  38038. parser = flow.parser;
  38039. }
  38040. parser.yy = graph;
  38041. // Parse the graph definition
  38042. parser.parse(text);
  38043. var classes = graph.getClasses();
  38044. // Add default class if undefined
  38045. if (typeof classes['default'] === 'undefined') {
  38046. classes['default'] = { id: 'default' };
  38047. //classes.default.styles = ['fill:#ffa','stroke:#666','stroke-width:3px'];
  38048. classes['default'].styles = [];
  38049. classes['default'].clusterStyles = ['rx:4px', 'fill: rgb(255, 255, 222)', 'rx: 4px', 'stroke: rgb(170, 170, 51)', 'stroke-width: 1px'];
  38050. classes['default'].nodeLabelStyles = ['fill:#000', 'stroke:none', 'font-weight:300', 'font-family:"Helvetica Neue",Helvetica,Arial,sans-serf', 'font-size:14px'];
  38051. classes['default'].edgeLabelStyles = ['fill:#000', 'stroke:none', 'font-weight:300', 'font-family:"Helvetica Neue",Helvetica,Arial,sans-serf', 'font-size:14px'];
  38052. }
  38053. return classes;
  38054. };
  38055. /**
  38056. * Draws a flowchart in the tag with id: id based on the graph definition in text.
  38057. * @param text
  38058. * @param id
  38059. */
  38060. exports.draw = function (text, id, isDot) {
  38061. log.debug('Drawing flowchart');
  38062. var parser;
  38063. graph.clear();
  38064. if (isDot) {
  38065. parser = dot.parser;
  38066. } else {
  38067. parser = flow.parser;
  38068. }
  38069. parser.yy = graph;
  38070. // Parse the graph definition
  38071. try {
  38072. parser.parse(text);
  38073. } catch (err) {
  38074. log.debug('Parsing failed');
  38075. }
  38076. // Fetch the default direction, use TD if none was found
  38077. var dir;
  38078. dir = graph.getDirection();
  38079. if (typeof dir === 'undefined') {
  38080. dir = 'TD';
  38081. }
  38082. // Create the input mermaid.graph
  38083. var g = new dagreD3.graphlib.Graph({
  38084. multigraph: true,
  38085. compound: true
  38086. }).setGraph({
  38087. rankdir: dir,
  38088. marginx: 20,
  38089. marginy: 20
  38090. }).setDefaultEdgeLabel(function () {
  38091. return {};
  38092. });
  38093. var subG;
  38094. var subGraphs = graph.getSubGraphs();
  38095. var i = 0;
  38096. for (i = subGraphs.length - 1; i >= 0; i--) {
  38097. subG = subGraphs[i];
  38098. graph.addVertex(subG.id, subG.title, 'group', undefined);
  38099. }
  38100. // Fetch the verices/nodes and edges/links from the parsed graph definition
  38101. var vert = graph.getVertices();
  38102. //log.debug(vert);
  38103. var edges = graph.getEdges();
  38104. i = 0;
  38105. var j;
  38106. for (i = subGraphs.length - 1; i >= 0; i--) {
  38107. subG = subGraphs[i];
  38108. d3.selectAll('cluster').append('text');
  38109. for (j = 0; j < subG.nodes.length; j++) {
  38110. //log.debug('Setting node',subG.nodes[j],' to subgraph '+id);
  38111. g.setParent(subG.nodes[j], subG.id);
  38112. }
  38113. }
  38114. exports.addVertices(vert, g);
  38115. exports.addEdges(edges, g);
  38116. // Create the renderer
  38117. var render = new dagreD3.render();
  38118. // Add custom shape for rhombus type of boc (decision)
  38119. render.shapes().question = function (parent, bbox, node) {
  38120. var w = bbox.width,
  38121. h = bbox.height,
  38122. s = (w + h) * 0.8,
  38123. points = [{ x: s / 2, y: 0 }, { x: s, y: -s / 2 }, { x: s / 2, y: -s }, { x: 0, y: -s / 2 }];
  38124. var shapeSvg = parent.insert('polygon', ':first-child').attr('points', points.map(function (d) {
  38125. return d.x + ',' + d.y;
  38126. }).join(' ')).attr('rx', 5).attr('ry', 5).attr('transform', 'translate(' + -s / 2 + ',' + s * 2 / 4 + ')');
  38127. node.intersect = function (point) {
  38128. return dagreD3.intersect.polygon(node, points, point);
  38129. };
  38130. return shapeSvg;
  38131. };
  38132. // Add custom shape for box with inverted arrow on left side
  38133. render.shapes().rect_left_inv_arrow = function (parent, bbox, node) {
  38134. var w = bbox.width,
  38135. h = bbox.height,
  38136. points = [{ x: -h / 2, y: 0 }, { x: w, y: 0 }, { x: w, y: -h }, { x: -h / 2, y: -h }, { x: 0, y: -h / 2 }];
  38137. var shapeSvg = parent.insert('polygon', ':first-child').attr('points', points.map(function (d) {
  38138. return d.x + ',' + d.y;
  38139. }).join(' ')).attr('transform', 'translate(' + -w / 2 + ',' + h * 2 / 4 + ')');
  38140. node.intersect = function (point) {
  38141. return dagreD3.intersect.polygon(node, points, point);
  38142. };
  38143. return shapeSvg;
  38144. };
  38145. // Add custom shape for box with inverted arrow on right side
  38146. render.shapes().rect_right_inv_arrow = function (parent, bbox, node) {
  38147. var w = bbox.width,
  38148. h = bbox.height,
  38149. 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 }];
  38150. var shapeSvg = parent.insert('polygon', ':first-child').attr('points', points.map(function (d) {
  38151. return d.x + ',' + d.y;
  38152. }).join(' ')).attr('transform', 'translate(' + -w / 2 + ',' + h * 2 / 4 + ')');
  38153. node.intersect = function (point) {
  38154. return dagreD3.intersect.polygon(node, points, point);
  38155. };
  38156. return shapeSvg;
  38157. };
  38158. // Add our custom arrow - an empty arrowhead
  38159. render.arrows().none = function normal(parent, id, edge, type) {
  38160. 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');
  38161. var path = marker.append('path').attr('d', 'M 0 0 L 0 0 L 0 0 z');
  38162. dagreD3.util.applyStyle(path, edge[type + 'Style']);
  38163. };
  38164. // Override normal arrowhead defined in d3. Remove style & add class to allow css styling.
  38165. render.arrows().normal = function normal(parent, id, edge, type) {
  38166. 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");
  38167. 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");
  38168. };
  38169. // Set up an SVG group so that we can translate the final graph.
  38170. var svg = d3.select('#' + id);
  38171. //svgGroup = d3.select('#' + id + ' g');
  38172. // Run the renderer. This is what draws the final graph.
  38173. var element = d3.select('#' + id + ' g');
  38174. render(element, g);
  38175. //var tip = d3.tip().html(function(d) { return d; });
  38176. element.selectAll('g.node').attr('title', function () {
  38177. return graph.getTooltip(this.id);
  38178. });
  38179. /*
  38180. var xPos = document.querySelectorAll('.clusters rect')[0].x.baseVal.value;
  38181. var width = document.querySelectorAll('.clusters rect')[0].width.baseVal.value;
  38182. var cluster = d3.selectAll('.cluster');
  38183. var te = cluster.append('text');
  38184. te.attr('x', xPos+width/2);
  38185. te.attr('y', 12);
  38186. //te.stroke('black');
  38187. te.attr('id', 'apa12');
  38188. te.style('text-anchor', 'middle');
  38189. te.text('Title for cluster');
  38190. */
  38191. if (conf.useMaxWidth) {
  38192. // Center the graph
  38193. svg.attr('height', '100%');
  38194. svg.attr('width', conf.width);
  38195. //svg.attr('viewBox', svgb.getBBox().x + ' 0 '+ g.graph().width+' '+ g.graph().height);
  38196. svg.attr('viewBox', '0 0 ' + (g.graph().width + 20) + ' ' + (g.graph().height + 20));
  38197. svg.attr('style', 'max-width:' + (g.graph().width + 20) + 'px;');
  38198. } else {
  38199. // Center the graph
  38200. svg.attr('height', g.graph().height);
  38201. if (typeof conf.width === 'undefined') {
  38202. svg.attr('width', g.graph().width);
  38203. } else {
  38204. svg.attr('width', conf.width);
  38205. }
  38206. //svg.attr('viewBox', svgb.getBBox().x + ' 0 '+ g.graph().width+' '+ g.graph().height);
  38207. svg.attr('viewBox', '0 0 ' + (g.graph().width + 20) + ' ' + (g.graph().height + 20));
  38208. }
  38209. // Index nodes
  38210. graph.indexNodes('subGraph' + i);
  38211. for (i = 0; i < subGraphs.length; i++) {
  38212. subG = subGraphs[i];
  38213. if (subG.title !== 'undefined') {
  38214. var clusterRects = document.querySelectorAll('#' + id + ' #' + subG.id + ' rect');
  38215. //log.debug('looking up: #' + id + ' #' + subG.id)
  38216. var clusterEl = document.querySelectorAll('#' + id + ' #' + subG.id);
  38217. var xPos = clusterRects[0].x.baseVal.value;
  38218. var yPos = clusterRects[0].y.baseVal.value;
  38219. var width = clusterRects[0].width.baseVal.value;
  38220. var cluster = d3.select(clusterEl[0]);
  38221. var te = cluster.append('text');
  38222. te.attr('x', xPos + width / 2);
  38223. te.attr('y', yPos + 14);
  38224. te.attr('fill', 'black');
  38225. te.attr('stroke', 'none');
  38226. te.attr('id', id + 'Text');
  38227. te.style('text-anchor', 'middle');
  38228. if (typeof subG.title === 'undefined') {
  38229. te.text('Undef');
  38230. } else {
  38231. //te.text(subGraphs[subGraphs.length-i-1].title);
  38232. te.text(subG.title);
  38233. }
  38234. }
  38235. }
  38236. // Add label rects for non html labels
  38237. if (!conf.htmlLabels) {
  38238. var labels = document.querySelectorAll('#' + id + ' .edgeLabel .label');
  38239. var i;
  38240. for (i = 0; i < labels.length; i++) {
  38241. var label = labels[i];
  38242. // Get dimensions of label
  38243. var dim = label.getBBox();
  38244. var rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
  38245. rect.setAttribute('rx', 0);
  38246. rect.setAttribute('ry', 0);
  38247. rect.setAttribute('width', dim.width);
  38248. rect.setAttribute('height', dim.height);
  38249. rect.setAttribute('style', 'fill:#e8e8e8;');
  38250. label.insertBefore(rect, label.firstChild);
  38251. }
  38252. }
  38253. };
  38254. },{"../../d3":108,"../../logger":130,"./dagre-d3":115,"./graphDb":117,"./parser/dot":118,"./parser/flow":119}],117:[function(require,module,exports){
  38255. (function (global){
  38256. /**
  38257. * Created by knut on 14-11-03.
  38258. */
  38259. 'use strict';
  38260. var Logger = require('../../logger');
  38261. var log = new Logger.Log();
  38262. var utils = require('../../utils');
  38263. var d3 = require('../../d3');
  38264. var vertices = {};
  38265. var edges = [];
  38266. var classes = [];
  38267. var subGraphs = [];
  38268. var tooltips = {};
  38269. var subCount = 0;
  38270. var direction;
  38271. // Functions to be run after graph rendering
  38272. var funs = [];
  38273. /**
  38274. * Function called by parser when a node definition has been found
  38275. * @param id
  38276. * @param text
  38277. * @param type
  38278. * @param style
  38279. */
  38280. exports.addVertex = function (id, text, type, style) {
  38281. var txt;
  38282. if (typeof id === 'undefined') {
  38283. return;
  38284. }
  38285. if (id.trim().length === 0) {
  38286. return;
  38287. }
  38288. if (typeof vertices[id] === 'undefined') {
  38289. vertices[id] = { id: id, styles: [], classes: [] };
  38290. }
  38291. if (typeof text !== 'undefined') {
  38292. txt = text.trim();
  38293. // strip quotes if string starts and exnds with a quote
  38294. if (txt[0] === '"' && txt[txt.length - 1] === '"') {
  38295. txt = txt.substring(1, txt.length - 1);
  38296. }
  38297. vertices[id].text = txt;
  38298. }
  38299. if (typeof type !== 'undefined') {
  38300. vertices[id].type = type;
  38301. }
  38302. if (typeof type !== 'undefined') {
  38303. vertices[id].type = type;
  38304. }
  38305. if (typeof style !== 'undefined') {
  38306. if (style !== null) {
  38307. style.forEach(function (s) {
  38308. vertices[id].styles.push(s);
  38309. });
  38310. }
  38311. }
  38312. };
  38313. /**
  38314. * Function called by parser when a link/edge definition has been found
  38315. * @param start
  38316. * @param end
  38317. * @param type
  38318. * @param linktext
  38319. */
  38320. exports.addLink = function (start, end, type, linktext) {
  38321. log.info('Got edge...', start, end);
  38322. var edge = { start: start, end: end, type: undefined, text: '' };
  38323. linktext = type.text;
  38324. if (typeof linktext !== 'undefined') {
  38325. edge.text = linktext.trim();
  38326. // strip quotes if string starts and exnds with a quote
  38327. if (edge.text[0] === '"' && edge.text[edge.text.length - 1] === '"') {
  38328. edge.text = edge.text.substring(1, edge.text.length - 1);
  38329. }
  38330. }
  38331. if (typeof type !== 'undefined') {
  38332. edge.type = type.type;
  38333. edge.stroke = type.stroke;
  38334. }
  38335. edges.push(edge);
  38336. };
  38337. /**
  38338. * Updates a link's line interpolation algorithm
  38339. * @param pos
  38340. * @param interpolate
  38341. */
  38342. exports.updateLinkInterpolate = function (pos, interp) {
  38343. if (pos === 'default') {
  38344. edges.defaultInterpolate = interp;
  38345. } else {
  38346. edges[pos].interpolate = interp;
  38347. }
  38348. };
  38349. /**
  38350. * Updates a link with a style
  38351. * @param pos
  38352. * @param style
  38353. */
  38354. exports.updateLink = function (pos, style) {
  38355. if (pos === 'default') {
  38356. edges.defaultStyle = style;
  38357. } else {
  38358. if (utils.isSubstringInArray('fill', style) === -1) {
  38359. style.push('fill:none');
  38360. }
  38361. edges[pos].style = style;
  38362. }
  38363. };
  38364. exports.addClass = function (id, style) {
  38365. if (typeof classes[id] === 'undefined') {
  38366. classes[id] = { id: id, styles: [] };
  38367. }
  38368. if (typeof style !== 'undefined') {
  38369. if (style !== null) {
  38370. style.forEach(function (s) {
  38371. classes[id].styles.push(s);
  38372. });
  38373. }
  38374. }
  38375. };
  38376. /**
  38377. * Called by parser when a graph definition is found, stores the direction of the chart.
  38378. * @param dir
  38379. */
  38380. exports.setDirection = function (dir) {
  38381. direction = dir;
  38382. };
  38383. /**
  38384. * Called by parser when a graph definition is found, stores the direction of the chart.
  38385. * @param dir
  38386. */
  38387. exports.setClass = function (id, className) {
  38388. if (id.indexOf(',') > 0) {
  38389. id.split(',').forEach(function (id2) {
  38390. if (typeof vertices[id2] !== 'undefined') {
  38391. vertices[id2].classes.push(className);
  38392. }
  38393. });
  38394. } else {
  38395. if (typeof vertices[id] !== 'undefined') {
  38396. vertices[id].classes.push(className);
  38397. }
  38398. }
  38399. };
  38400. var setTooltip = function setTooltip(id, tooltip) {
  38401. if (typeof tooltip !== 'undefined') {
  38402. tooltips[id] = tooltip;
  38403. }
  38404. };
  38405. var setClickFun = function setClickFun(id, functionName) {
  38406. if (typeof functionName === 'undefined') {
  38407. return;
  38408. }
  38409. if (typeof vertices[id] !== 'undefined') {
  38410. funs.push(function (element) {
  38411. var elem = d3.select(element).select('#' + id);
  38412. if (elem !== null) {
  38413. elem.on('click', function () {
  38414. eval(functionName + '(\'' + id + '\')'); // jshint ignore:line
  38415. });
  38416. }
  38417. });
  38418. }
  38419. };
  38420. var setLink = function setLink(id, linkStr) {
  38421. if (typeof linkStr === 'undefined') {
  38422. return;
  38423. }
  38424. if (typeof vertices[id] !== 'undefined') {
  38425. funs.push(function (element) {
  38426. var elem = d3.select(element).select('#' + id);
  38427. if (elem !== null) {
  38428. elem.on('click', function () {
  38429. window.open(linkStr, 'newTab'); // jshint ignore:line
  38430. });
  38431. }
  38432. });
  38433. }
  38434. };
  38435. exports.getTooltip = function (id) {
  38436. return tooltips[id];
  38437. };
  38438. /**
  38439. * Called by parser when a graph definition is found, stores the direction of the chart.
  38440. * @param dir
  38441. */
  38442. exports.setClickEvent = function (id, functionName, link, tooltip) {
  38443. if (id.indexOf(',') > 0) {
  38444. id.split(',').forEach(function (id2) {
  38445. setTooltip(id2, tooltip);
  38446. setClickFun(id2, functionName);
  38447. setLink(id2, link);
  38448. });
  38449. } else {
  38450. setTooltip(id, tooltip);
  38451. setClickFun(id, functionName);
  38452. setLink(id, link);
  38453. }
  38454. };
  38455. exports.bindFunctions = function (element) {
  38456. funs.forEach(function (fun) {
  38457. fun(element);
  38458. });
  38459. };
  38460. exports.getDirection = function () {
  38461. return direction;
  38462. };
  38463. /**
  38464. * Retrieval function for fetching the found nodes after parsing has completed.
  38465. * @returns {{}|*|vertices}
  38466. */
  38467. exports.getVertices = function () {
  38468. return vertices;
  38469. };
  38470. /**
  38471. * Retrieval function for fetching the found links after parsing has completed.
  38472. * @returns {{}|*|edges}
  38473. */
  38474. exports.getEdges = function () {
  38475. return edges;
  38476. };
  38477. /**
  38478. * Retrieval function for fetching the found class definitions after parsing has completed.
  38479. * @returns {{}|*|classes}
  38480. */
  38481. exports.getClasses = function () {
  38482. return classes;
  38483. };
  38484. var setupToolTips = function setupToolTips(element) {
  38485. var tooltipElem = d3.select('.mermaidTooltip');
  38486. if (tooltipElem[0][0] === null) {
  38487. tooltipElem = d3.select('body').append('div').attr('class', 'mermaidTooltip').style('opacity', 0);
  38488. }
  38489. var svg = d3.select(element).select('svg');
  38490. var nodes = svg.selectAll('g.node');
  38491. nodes.on('mouseover', function () {
  38492. var el = d3.select(this);
  38493. var title = el.attr('title');
  38494. // Dont try to draw a tooltip if no data is provided
  38495. if (title === null) {
  38496. return;
  38497. }
  38498. var rect = this.getBoundingClientRect();
  38499. tooltipElem.transition().duration(200).style('opacity', '.9');
  38500. tooltipElem.html(el.attr('title')).style('left', rect.left + (rect.right - rect.left) / 2 + 'px').style('top', rect.top - 14 + document.body.scrollTop + 'px');
  38501. el.classed('hover', true);
  38502. }).on('mouseout', function () {
  38503. tooltipElem.transition().duration(500).style('opacity', 0);
  38504. var el = d3.select(this);
  38505. el.classed('hover', false);
  38506. });
  38507. };
  38508. funs.push(setupToolTips);
  38509. /**
  38510. * Clears the internal graph db so that a new graph can be parsed.
  38511. */
  38512. exports.clear = function () {
  38513. vertices = {};
  38514. classes = {};
  38515. edges = [];
  38516. funs = [];
  38517. funs.push(setupToolTips);
  38518. subGraphs = [];
  38519. subCount = 0;
  38520. tooltips = [];
  38521. };
  38522. /**
  38523. *
  38524. * @returns {string}
  38525. */
  38526. exports.defaultStyle = function () {
  38527. return 'fill:#ffa;stroke: #f66; stroke-width: 3px; stroke-dasharray: 5, 5;fill:#ffa;stroke: #666;';
  38528. };
  38529. /**
  38530. * Clears the internal graph db so that a new graph can be parsed.
  38531. */
  38532. exports.addSubGraph = function (list, title) {
  38533. function uniq(a) {
  38534. var prims = { 'boolean': {}, 'number': {}, 'string': {} },
  38535. objs = [];
  38536. return a.filter(function (item) {
  38537. var type = typeof item;
  38538. if (item === ' ') {
  38539. return false;
  38540. }
  38541. if (type in prims) return prims[type].hasOwnProperty(item) ? false : prims[type][item] = true;else return objs.indexOf(item) >= 0 ? false : objs.push(item);
  38542. });
  38543. }
  38544. var nodeList = [];
  38545. nodeList = uniq(nodeList.concat.apply(nodeList, list));
  38546. var subGraph = { id: 'subGraph' + subCount, nodes: nodeList, title: title };
  38547. //log.debug('subGraph:' + subGraph.title + subGraph.id);
  38548. //log.debug(subGraph.nodes);
  38549. subGraphs.push(subGraph);
  38550. subCount = subCount + 1;
  38551. return subGraph.id;
  38552. };
  38553. var getPosForId = function getPosForId(id) {
  38554. var i;
  38555. for (i = 0; i < subGraphs.length; i++) {
  38556. if (subGraphs[i].id === id) {
  38557. //log.debug('Found pos for ',id,' ',i);
  38558. return i;
  38559. }
  38560. }
  38561. //log.debug('No pos found for ',id,' ',i);
  38562. return -1;
  38563. };
  38564. var secCount = -1;
  38565. var posCrossRef = [];
  38566. var indexNodes = function indexNodes(id, pos) {
  38567. var nodes = subGraphs[pos].nodes;
  38568. secCount = secCount + 1;
  38569. if (secCount > 2000) {
  38570. return;
  38571. }
  38572. //var nPos = getPosForId(subGraphs[pos].id);
  38573. posCrossRef[secCount] = pos;
  38574. // Check if match
  38575. if (subGraphs[pos].id === id) {
  38576. return {
  38577. result: true,
  38578. count: 0
  38579. };
  38580. }
  38581. var count = 0;
  38582. var posCount = 1;
  38583. while (count < nodes.length) {
  38584. var childPos = getPosForId(nodes[count]);
  38585. // Ignore regular nodes (pos will be -1)
  38586. if (childPos >= 0) {
  38587. var res = indexNodes(id, childPos);
  38588. if (res.result) {
  38589. return {
  38590. result: true,
  38591. count: posCount + res.count
  38592. };
  38593. } else {
  38594. posCount = posCount + res.count;
  38595. }
  38596. }
  38597. count = count + 1;
  38598. }
  38599. return {
  38600. result: false,
  38601. count: posCount
  38602. };
  38603. };
  38604. exports.getDepthFirstPos = function (pos) {
  38605. return posCrossRef[pos];
  38606. };
  38607. exports.indexNodes = function () {
  38608. secCount = -1;
  38609. if (subGraphs.length > 0) {
  38610. indexNodes('none', subGraphs.length - 1, 0);
  38611. }
  38612. };
  38613. exports.getSubGraphs = function () {
  38614. return subGraphs;
  38615. };
  38616. exports.parseError = function (err, hash) {
  38617. global.mermaidAPI.parseError(err, hash);
  38618. };
  38619. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  38620. },{"../../d3":108,"../../logger":130,"../../utils":133}],118:[function(require,module,exports){
  38621. (function (process){
  38622. /* parser generated by jison 0.4.17 */
  38623. /*
  38624. Returns a Parser object of the following structure:
  38625. Parser: {
  38626. yy: {}
  38627. }
  38628. Parser.prototype: {
  38629. yy: {},
  38630. trace: function(),
  38631. symbols_: {associative list: name ==> number},
  38632. terminals_: {associative list: number ==> name},
  38633. productions_: [...],
  38634. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  38635. table: [...],
  38636. defaultActions: {...},
  38637. parseError: function(str, hash),
  38638. parse: function(input),
  38639. lexer: {
  38640. EOF: 1,
  38641. parseError: function(str, hash),
  38642. setInput: function(input),
  38643. input: function(),
  38644. unput: function(str),
  38645. more: function(),
  38646. less: function(n),
  38647. pastInput: function(),
  38648. upcomingInput: function(),
  38649. showPosition: function(),
  38650. test_match: function(regex_match_array, rule_index),
  38651. next: function(),
  38652. lex: function(),
  38653. begin: function(condition),
  38654. popState: function(),
  38655. _currentRules: function(),
  38656. topState: function(),
  38657. pushState: function(condition),
  38658. options: {
  38659. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  38660. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  38661. 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)
  38662. },
  38663. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  38664. rules: [...],
  38665. conditions: {associative list: name ==> set},
  38666. }
  38667. }
  38668. token location info (@$, _$, etc.): {
  38669. first_line: n,
  38670. last_line: n,
  38671. first_column: n,
  38672. last_column: n,
  38673. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  38674. }
  38675. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  38676. text: (matched text)
  38677. token: (the produced terminal token, if any)
  38678. line: (yylineno)
  38679. }
  38680. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  38681. loc: (yylloc)
  38682. expected: (string describing the set of expected tokens)
  38683. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  38684. }
  38685. */
  38686. "use strict";
  38687. var parser = (function () {
  38688. var o = function o(k, v, _o, l) {
  38689. for (_o = _o || {}, l = k.length; l--; _o[k[l]] = v);return _o;
  38690. },
  38691. $V0 = [1, 5],
  38692. $V1 = [1, 6],
  38693. $V2 = [1, 12],
  38694. $V3 = [1, 13],
  38695. $V4 = [1, 14],
  38696. $V5 = [1, 15],
  38697. $V6 = [1, 16],
  38698. $V7 = [1, 17],
  38699. $V8 = [1, 18],
  38700. $V9 = [1, 19],
  38701. $Va = [1, 20],
  38702. $Vb = [1, 21],
  38703. $Vc = [1, 22],
  38704. $Vd = [8, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26],
  38705. $Ve = [1, 37],
  38706. $Vf = [1, 33],
  38707. $Vg = [1, 34],
  38708. $Vh = [1, 35],
  38709. $Vi = [1, 36],
  38710. $Vj = [8, 10, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 32, 37, 39, 40, 45, 57, 58],
  38711. $Vk = [10, 28],
  38712. $Vl = [10, 28, 37, 57, 58],
  38713. $Vm = [2, 49],
  38714. $Vn = [1, 45],
  38715. $Vo = [1, 48],
  38716. $Vp = [1, 49],
  38717. $Vq = [1, 52],
  38718. $Vr = [2, 65],
  38719. $Vs = [1, 65],
  38720. $Vt = [1, 66],
  38721. $Vu = [1, 67],
  38722. $Vv = [1, 68],
  38723. $Vw = [1, 69],
  38724. $Vx = [1, 70],
  38725. $Vy = [1, 71],
  38726. $Vz = [1, 72],
  38727. $VA = [1, 73],
  38728. $VB = [8, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 47],
  38729. $VC = [10, 28, 37];
  38730. var parser = { trace: function trace() {},
  38731. yy: {},
  38732. 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 },
  38733. 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" },
  38734. 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]],
  38735. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, /* action[1] */$$, /* vstack */_$ /* lstack */) {
  38736. /* this == yyval */
  38737. var $0 = $$.length - 1;
  38738. switch (yystate) {
  38739. case 1:
  38740. this.$ = $$[$0 - 1];
  38741. break;
  38742. case 2:
  38743. this.$ = $$[$0 - 4];
  38744. break;
  38745. case 3:
  38746. this.$ = $$[$0 - 5];
  38747. break;
  38748. case 4:
  38749. this.$ = $$[$0 - 3];
  38750. break;
  38751. case 8:case 10:case 11:
  38752. this.$ = $$[$0];
  38753. break;
  38754. case 9:
  38755. this.$ = $$[$0 - 1] + '' + $$[$0];
  38756. break;
  38757. case 12:case 13:case 14:case 15:case 16:case 18:case 19:case 20:
  38758. this.$ = $$[$0];
  38759. break;
  38760. case 17:
  38761. this.$ = '<br>';
  38762. break;
  38763. case 39:
  38764. this.$ = 'oy';
  38765. break;
  38766. case 40:
  38767. yy.addLink($$[$0 - 1], $$[$0].id, $$[$0].op);
  38768. this.$ = 'oy';
  38769. break;
  38770. case 42:
  38771. yy.addLink($$[$0 - 1], $$[$0].id, $$[$0].op);
  38772. this.$ = { op: $$[$0 - 2], id: $$[$0 - 1] };
  38773. break;
  38774. case 44:
  38775. this.$ = { op: $$[$0 - 1], id: $$[$0] };
  38776. break;
  38777. case 48:
  38778. yy.addVertex($$[$0 - 1]);this.$ = $$[$0 - 1];
  38779. break;
  38780. case 49:
  38781. yy.addVertex($$[$0]);this.$ = $$[$0];
  38782. break;
  38783. case 66:
  38784. this.$ = 'arrow';
  38785. break;
  38786. case 67:
  38787. this.$ = 'arrow_open';
  38788. break;
  38789. }
  38790. },
  38791. 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] }],
  38792. defaultActions: { 7: [2, 1], 41: [2, 4], 60: [2, 2], 61: [2, 22], 94: [2, 3], 101: [2, 35], 102: [2, 36] },
  38793. parseError: function parseError(str, hash) {
  38794. if (hash.recoverable) {
  38795. this.trace(str);
  38796. } else {
  38797. var _parseError = function _parseError(msg, hash) {
  38798. this.message = msg;
  38799. this.hash = hash;
  38800. };
  38801. _parseError.prototype = Error;
  38802. throw new _parseError(str, hash);
  38803. }
  38804. },
  38805. parse: function parse(input) {
  38806. var self = this,
  38807. stack = [0],
  38808. tstack = [],
  38809. vstack = [null],
  38810. lstack = [],
  38811. table = this.table,
  38812. yytext = '',
  38813. yylineno = 0,
  38814. yyleng = 0,
  38815. recovering = 0,
  38816. TERROR = 2,
  38817. EOF = 1;
  38818. var args = lstack.slice.call(arguments, 1);
  38819. var lexer = Object.create(this.lexer);
  38820. var sharedState = { yy: {} };
  38821. for (var k in this.yy) {
  38822. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  38823. sharedState.yy[k] = this.yy[k];
  38824. }
  38825. }
  38826. lexer.setInput(input, sharedState.yy);
  38827. sharedState.yy.lexer = lexer;
  38828. sharedState.yy.parser = this;
  38829. if (typeof lexer.yylloc == 'undefined') {
  38830. lexer.yylloc = {};
  38831. }
  38832. var yyloc = lexer.yylloc;
  38833. lstack.push(yyloc);
  38834. var ranges = lexer.options && lexer.options.ranges;
  38835. if (typeof sharedState.yy.parseError === 'function') {
  38836. this.parseError = sharedState.yy.parseError;
  38837. } else {
  38838. this.parseError = Object.getPrototypeOf(this).parseError;
  38839. }
  38840. function popStack(n) {
  38841. stack.length = stack.length - 2 * n;
  38842. vstack.length = vstack.length - n;
  38843. lstack.length = lstack.length - n;
  38844. }
  38845. _token_stack: var lex = function lex() {
  38846. var token;
  38847. token = lexer.lex() || EOF;
  38848. if (typeof token !== 'number') {
  38849. token = self.symbols_[token] || token;
  38850. }
  38851. return token;
  38852. };
  38853. var symbol,
  38854. preErrorSymbol,
  38855. state,
  38856. action,
  38857. a,
  38858. r,
  38859. yyval = {},
  38860. p,
  38861. len,
  38862. newState,
  38863. expected;
  38864. while (true) {
  38865. state = stack[stack.length - 1];
  38866. if (this.defaultActions[state]) {
  38867. action = this.defaultActions[state];
  38868. } else {
  38869. if (symbol === null || typeof symbol == 'undefined') {
  38870. symbol = lex();
  38871. }
  38872. action = table[state] && table[state][symbol];
  38873. }
  38874. if (typeof action === 'undefined' || !action.length || !action[0]) {
  38875. var errStr = '';
  38876. expected = [];
  38877. for (p in table[state]) {
  38878. if (this.terminals_[p] && p > TERROR) {
  38879. expected.push('\'' + this.terminals_[p] + '\'');
  38880. }
  38881. }
  38882. if (lexer.showPosition) {
  38883. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  38884. } else {
  38885. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  38886. }
  38887. this.parseError(errStr, {
  38888. text: lexer.match,
  38889. token: this.terminals_[symbol] || symbol,
  38890. line: lexer.yylineno,
  38891. loc: yyloc,
  38892. expected: expected
  38893. });
  38894. }
  38895. if (action[0] instanceof Array && action.length > 1) {
  38896. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  38897. }
  38898. switch (action[0]) {
  38899. case 1:
  38900. stack.push(symbol);
  38901. vstack.push(lexer.yytext);
  38902. lstack.push(lexer.yylloc);
  38903. stack.push(action[1]);
  38904. symbol = null;
  38905. if (!preErrorSymbol) {
  38906. yyleng = lexer.yyleng;
  38907. yytext = lexer.yytext;
  38908. yylineno = lexer.yylineno;
  38909. yyloc = lexer.yylloc;
  38910. if (recovering > 0) {
  38911. recovering--;
  38912. }
  38913. } else {
  38914. symbol = preErrorSymbol;
  38915. preErrorSymbol = null;
  38916. }
  38917. break;
  38918. case 2:
  38919. len = this.productions_[action[1]][1];
  38920. yyval.$ = vstack[vstack.length - len];
  38921. yyval._$ = {
  38922. first_line: lstack[lstack.length - (len || 1)].first_line,
  38923. last_line: lstack[lstack.length - 1].last_line,
  38924. first_column: lstack[lstack.length - (len || 1)].first_column,
  38925. last_column: lstack[lstack.length - 1].last_column
  38926. };
  38927. if (ranges) {
  38928. yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
  38929. }
  38930. r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
  38931. if (typeof r !== 'undefined') {
  38932. return r;
  38933. }
  38934. if (len) {
  38935. stack = stack.slice(0, -1 * len * 2);
  38936. vstack = vstack.slice(0, -1 * len);
  38937. lstack = lstack.slice(0, -1 * len);
  38938. }
  38939. stack.push(this.productions_[action[1]][0]);
  38940. vstack.push(yyval.$);
  38941. lstack.push(yyval._$);
  38942. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  38943. stack.push(newState);
  38944. break;
  38945. case 3:
  38946. return true;
  38947. }
  38948. }
  38949. return true;
  38950. } };
  38951. /* generated by jison-lex 0.3.4 */
  38952. var lexer = (function () {
  38953. var lexer = {
  38954. EOF: 1,
  38955. parseError: function parseError(str, hash) {
  38956. if (this.yy.parser) {
  38957. this.yy.parser.parseError(str, hash);
  38958. } else {
  38959. throw new Error(str);
  38960. }
  38961. },
  38962. // resets the lexer, sets new input
  38963. setInput: function setInput(input, yy) {
  38964. this.yy = yy || this.yy || {};
  38965. this._input = input;
  38966. this._more = this._backtrack = this.done = false;
  38967. this.yylineno = this.yyleng = 0;
  38968. this.yytext = this.matched = this.match = '';
  38969. this.conditionStack = ['INITIAL'];
  38970. this.yylloc = {
  38971. first_line: 1,
  38972. first_column: 0,
  38973. last_line: 1,
  38974. last_column: 0
  38975. };
  38976. if (this.options.ranges) {
  38977. this.yylloc.range = [0, 0];
  38978. }
  38979. this.offset = 0;
  38980. return this;
  38981. },
  38982. // consumes and returns one char from the input
  38983. input: function input() {
  38984. var ch = this._input[0];
  38985. this.yytext += ch;
  38986. this.yyleng++;
  38987. this.offset++;
  38988. this.match += ch;
  38989. this.matched += ch;
  38990. var lines = ch.match(/(?:\r\n?|\n).*/g);
  38991. if (lines) {
  38992. this.yylineno++;
  38993. this.yylloc.last_line++;
  38994. } else {
  38995. this.yylloc.last_column++;
  38996. }
  38997. if (this.options.ranges) {
  38998. this.yylloc.range[1]++;
  38999. }
  39000. this._input = this._input.slice(1);
  39001. return ch;
  39002. },
  39003. // unshifts one char (or a string) into the input
  39004. unput: function unput(ch) {
  39005. var len = ch.length;
  39006. var lines = ch.split(/(?:\r\n?|\n)/g);
  39007. this._input = ch + this._input;
  39008. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  39009. //this.yyleng -= len;
  39010. this.offset -= len;
  39011. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  39012. this.match = this.match.substr(0, this.match.length - 1);
  39013. this.matched = this.matched.substr(0, this.matched.length - 1);
  39014. if (lines.length - 1) {
  39015. this.yylineno -= lines.length - 1;
  39016. }
  39017. var r = this.yylloc.range;
  39018. this.yylloc = {
  39019. first_line: this.yylloc.first_line,
  39020. last_line: this.yylineno + 1,
  39021. first_column: this.yylloc.first_column,
  39022. 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
  39023. };
  39024. if (this.options.ranges) {
  39025. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  39026. }
  39027. this.yyleng = this.yytext.length;
  39028. return this;
  39029. },
  39030. // When called from action, caches matched text and appends it on next action
  39031. more: function more() {
  39032. this._more = true;
  39033. return this;
  39034. },
  39035. // 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.
  39036. reject: function reject() {
  39037. if (this.options.backtrack_lexer) {
  39038. this._backtrack = true;
  39039. } else {
  39040. 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(), {
  39041. text: "",
  39042. token: null,
  39043. line: this.yylineno
  39044. });
  39045. }
  39046. return this;
  39047. },
  39048. // retain first n characters of the match
  39049. less: function less(n) {
  39050. this.unput(this.match.slice(n));
  39051. },
  39052. // displays already matched input, i.e. for error messages
  39053. pastInput: function pastInput() {
  39054. var past = this.matched.substr(0, this.matched.length - this.match.length);
  39055. return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
  39056. },
  39057. // displays upcoming input, i.e. for error messages
  39058. upcomingInput: function upcomingInput() {
  39059. var next = this.match;
  39060. if (next.length < 20) {
  39061. next += this._input.substr(0, 20 - next.length);
  39062. }
  39063. return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  39064. },
  39065. // displays the character position where the lexing error occurred, i.e. for error messages
  39066. showPosition: function showPosition() {
  39067. var pre = this.pastInput();
  39068. var c = new Array(pre.length + 1).join("-");
  39069. return pre + this.upcomingInput() + "\n" + c + "^";
  39070. },
  39071. // test the lexed token: return FALSE when not a match, otherwise return token
  39072. test_match: function test_match(match, indexed_rule) {
  39073. var token, lines, backup;
  39074. if (this.options.backtrack_lexer) {
  39075. // save context
  39076. backup = {
  39077. yylineno: this.yylineno,
  39078. yylloc: {
  39079. first_line: this.yylloc.first_line,
  39080. last_line: this.last_line,
  39081. first_column: this.yylloc.first_column,
  39082. last_column: this.yylloc.last_column
  39083. },
  39084. yytext: this.yytext,
  39085. match: this.match,
  39086. matches: this.matches,
  39087. matched: this.matched,
  39088. yyleng: this.yyleng,
  39089. offset: this.offset,
  39090. _more: this._more,
  39091. _input: this._input,
  39092. yy: this.yy,
  39093. conditionStack: this.conditionStack.slice(0),
  39094. done: this.done
  39095. };
  39096. if (this.options.ranges) {
  39097. backup.yylloc.range = this.yylloc.range.slice(0);
  39098. }
  39099. }
  39100. lines = match[0].match(/(?:\r\n?|\n).*/g);
  39101. if (lines) {
  39102. this.yylineno += lines.length;
  39103. }
  39104. this.yylloc = {
  39105. first_line: this.yylloc.last_line,
  39106. last_line: this.yylineno + 1,
  39107. first_column: this.yylloc.last_column,
  39108. last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
  39109. };
  39110. this.yytext += match[0];
  39111. this.match += match[0];
  39112. this.matches = match;
  39113. this.yyleng = this.yytext.length;
  39114. if (this.options.ranges) {
  39115. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  39116. }
  39117. this._more = false;
  39118. this._backtrack = false;
  39119. this._input = this._input.slice(match[0].length);
  39120. this.matched += match[0];
  39121. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  39122. if (this.done && this._input) {
  39123. this.done = false;
  39124. }
  39125. if (token) {
  39126. return token;
  39127. } else if (this._backtrack) {
  39128. // recover context
  39129. for (var k in backup) {
  39130. this[k] = backup[k];
  39131. }
  39132. return false; // rule action called reject() implying the next rule should be tested instead.
  39133. }
  39134. return false;
  39135. },
  39136. // return next match in input
  39137. next: function next() {
  39138. if (this.done) {
  39139. return this.EOF;
  39140. }
  39141. if (!this._input) {
  39142. this.done = true;
  39143. }
  39144. var token, match, tempMatch, index;
  39145. if (!this._more) {
  39146. this.yytext = '';
  39147. this.match = '';
  39148. }
  39149. var rules = this._currentRules();
  39150. for (var i = 0; i < rules.length; i++) {
  39151. tempMatch = this._input.match(this.rules[rules[i]]);
  39152. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  39153. match = tempMatch;
  39154. index = i;
  39155. if (this.options.backtrack_lexer) {
  39156. token = this.test_match(tempMatch, rules[i]);
  39157. if (token !== false) {
  39158. return token;
  39159. } else if (this._backtrack) {
  39160. match = false;
  39161. continue; // rule action called reject() implying a rule MISmatch.
  39162. } else {
  39163. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  39164. return false;
  39165. }
  39166. } else if (!this.options.flex) {
  39167. break;
  39168. }
  39169. }
  39170. }
  39171. if (match) {
  39172. token = this.test_match(match, rules[index]);
  39173. if (token !== false) {
  39174. return token;
  39175. }
  39176. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  39177. return false;
  39178. }
  39179. if (this._input === "") {
  39180. return this.EOF;
  39181. } else {
  39182. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  39183. text: "",
  39184. token: null,
  39185. line: this.yylineno
  39186. });
  39187. }
  39188. },
  39189. // return next match that has a token
  39190. lex: function lex() {
  39191. var r = this.next();
  39192. if (r) {
  39193. return r;
  39194. } else {
  39195. return this.lex();
  39196. }
  39197. },
  39198. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  39199. begin: function begin(condition) {
  39200. this.conditionStack.push(condition);
  39201. },
  39202. // pop the previously active lexer condition state off the condition stack
  39203. popState: function popState() {
  39204. var n = this.conditionStack.length - 1;
  39205. if (n > 0) {
  39206. return this.conditionStack.pop();
  39207. } else {
  39208. return this.conditionStack[0];
  39209. }
  39210. },
  39211. // produce the lexer rule set which is active for the currently active lexer condition state
  39212. _currentRules: function _currentRules() {
  39213. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  39214. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  39215. } else {
  39216. return this.conditions["INITIAL"].rules;
  39217. }
  39218. },
  39219. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  39220. topState: function topState(n) {
  39221. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  39222. if (n >= 0) {
  39223. return this.conditionStack[n];
  39224. } else {
  39225. return "INITIAL";
  39226. }
  39227. },
  39228. // alias for begin(condition)
  39229. pushState: function pushState(condition) {
  39230. this.begin(condition);
  39231. },
  39232. // return the number of states currently on the stack
  39233. stateStackSize: function stateStackSize() {
  39234. return this.conditionStack.length;
  39235. },
  39236. options: {},
  39237. performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
  39238. var YYSTATE = YY_START;
  39239. switch ($avoiding_name_collisions) {
  39240. case 0:
  39241. return 'STYLE';
  39242. break;
  39243. case 1:
  39244. return 'LINKSTYLE';
  39245. break;
  39246. case 2:
  39247. return 'CLASSDEF';
  39248. break;
  39249. case 3:
  39250. return 'CLASS';
  39251. break;
  39252. case 4:
  39253. return 'CLICK';
  39254. break;
  39255. case 5:
  39256. return 12;
  39257. break;
  39258. case 6:
  39259. return 13;
  39260. break;
  39261. case 7:
  39262. return 47;
  39263. break;
  39264. case 8:
  39265. return 35;
  39266. break;
  39267. case 9:
  39268. return 36;
  39269. break;
  39270. case 10:
  39271. return 'DIR';
  39272. break;
  39273. case 11:
  39274. return 'DIR';
  39275. break;
  39276. case 12:
  39277. return 'DIR';
  39278. break;
  39279. case 13:
  39280. return 'DIR';
  39281. break;
  39282. case 14:
  39283. return 'DIR';
  39284. break;
  39285. case 15:
  39286. return 'DIR';
  39287. break;
  39288. case 16:
  39289. return 17;
  39290. break;
  39291. case 17:
  39292. return 23;
  39293. break;
  39294. case 18:
  39295. return 18;
  39296. break;
  39297. case 19:
  39298. return 28;
  39299. break;
  39300. case 20:
  39301. return 40;
  39302. break;
  39303. case 21:
  39304. return 32;
  39305. break;
  39306. case 22:
  39307. return 21;
  39308. break;
  39309. case 23:
  39310. return 22;
  39311. break;
  39312. case 24:
  39313. return 'ARROW_CROSS';
  39314. break;
  39315. case 25:
  39316. return 57;
  39317. break;
  39318. case 26:
  39319. return 'ARROW_CIRCLE';
  39320. break;
  39321. case 27:
  39322. return 58;
  39323. break;
  39324. case 28:
  39325. return 25;
  39326. break;
  39327. case 29:
  39328. return 19;
  39329. break;
  39330. case 30:
  39331. return 20;
  39332. break;
  39333. case 31:
  39334. return 16;
  39335. break;
  39336. case 32:
  39337. return 'PIPE';
  39338. break;
  39339. case 33:
  39340. return 'PS';
  39341. break;
  39342. case 34:
  39343. return 'PE';
  39344. break;
  39345. case 35:
  39346. return 37;
  39347. break;
  39348. case 36:
  39349. return 39;
  39350. break;
  39351. case 37:
  39352. return 8;
  39353. break;
  39354. case 38:
  39355. return 10;
  39356. break;
  39357. case 39:
  39358. return 'QUOTE';
  39359. break;
  39360. case 40:
  39361. return 24;
  39362. break;
  39363. case 41:
  39364. return 'NEWLINE';
  39365. break;
  39366. case 42:
  39367. return 5;
  39368. break;
  39369. }
  39370. },
  39371. 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)/, /^(?:$)/],
  39372. 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 } }
  39373. };
  39374. return lexer;
  39375. })();
  39376. parser.lexer = lexer;
  39377. function Parser() {
  39378. this.yy = {};
  39379. }
  39380. Parser.prototype = parser;parser.Parser = Parser;
  39381. return new Parser();
  39382. })();
  39383. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  39384. exports.parser = parser;
  39385. exports.Parser = parser.Parser;
  39386. exports.parse = function () {
  39387. return parser.parse.apply(parser, arguments);
  39388. };
  39389. exports.main = function commonjsMain(args) {
  39390. if (!args[1]) {
  39391. console.log('Usage: ' + args[0] + ' FILE');
  39392. process.exit(1);
  39393. }
  39394. var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
  39395. return exports.parser.parse(source);
  39396. };
  39397. if (typeof module !== 'undefined' && require.main === module) {
  39398. exports.main(process.argv.slice(1));
  39399. }
  39400. }
  39401. }).call(this,require('_process'))
  39402. },{"_process":106,"fs":1,"path":105}],119:[function(require,module,exports){
  39403. (function (process){
  39404. /* parser generated by jison 0.4.17 */
  39405. /*
  39406. Returns a Parser object of the following structure:
  39407. Parser: {
  39408. yy: {}
  39409. }
  39410. Parser.prototype: {
  39411. yy: {},
  39412. trace: function(),
  39413. symbols_: {associative list: name ==> number},
  39414. terminals_: {associative list: number ==> name},
  39415. productions_: [...],
  39416. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  39417. table: [...],
  39418. defaultActions: {...},
  39419. parseError: function(str, hash),
  39420. parse: function(input),
  39421. lexer: {
  39422. EOF: 1,
  39423. parseError: function(str, hash),
  39424. setInput: function(input),
  39425. input: function(),
  39426. unput: function(str),
  39427. more: function(),
  39428. less: function(n),
  39429. pastInput: function(),
  39430. upcomingInput: function(),
  39431. showPosition: function(),
  39432. test_match: function(regex_match_array, rule_index),
  39433. next: function(),
  39434. lex: function(),
  39435. begin: function(condition),
  39436. popState: function(),
  39437. _currentRules: function(),
  39438. topState: function(),
  39439. pushState: function(condition),
  39440. options: {
  39441. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  39442. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  39443. 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)
  39444. },
  39445. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  39446. rules: [...],
  39447. conditions: {associative list: name ==> set},
  39448. }
  39449. }
  39450. token location info (@$, _$, etc.): {
  39451. first_line: n,
  39452. last_line: n,
  39453. first_column: n,
  39454. last_column: n,
  39455. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  39456. }
  39457. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  39458. text: (matched text)
  39459. token: (the produced terminal token, if any)
  39460. line: (yylineno)
  39461. }
  39462. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  39463. loc: (yylloc)
  39464. expected: (string describing the set of expected tokens)
  39465. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  39466. }
  39467. */
  39468. "use strict";
  39469. var parser = (function () {
  39470. var o = function o(k, v, _o, l) {
  39471. for (_o = _o || {}, l = k.length; l--; _o[k[l]] = v);return _o;
  39472. },
  39473. $V0 = [1, 4],
  39474. $V1 = [1, 3],
  39475. $V2 = [1, 5],
  39476. $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],
  39477. $V4 = [2, 2],
  39478. $V5 = [1, 12],
  39479. $V6 = [1, 13],
  39480. $V7 = [1, 14],
  39481. $V8 = [1, 15],
  39482. $V9 = [1, 31],
  39483. $Va = [1, 33],
  39484. $Vb = [1, 22],
  39485. $Vc = [1, 34],
  39486. $Vd = [1, 24],
  39487. $Ve = [1, 25],
  39488. $Vf = [1, 26],
  39489. $Vg = [1, 27],
  39490. $Vh = [1, 28],
  39491. $Vi = [1, 38],
  39492. $Vj = [1, 40],
  39493. $Vk = [1, 35],
  39494. $Vl = [1, 39],
  39495. $Vm = [1, 45],
  39496. $Vn = [1, 44],
  39497. $Vo = [1, 36],
  39498. $Vp = [1, 37],
  39499. $Vq = [1, 41],
  39500. $Vr = [1, 42],
  39501. $Vs = [1, 43],
  39502. $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],
  39503. $Vu = [1, 53],
  39504. $Vv = [1, 52],
  39505. $Vw = [1, 54],
  39506. $Vx = [1, 72],
  39507. $Vy = [1, 80],
  39508. $Vz = [1, 81],
  39509. $VA = [1, 66],
  39510. $VB = [1, 65],
  39511. $VC = [1, 85],
  39512. $VD = [1, 84],
  39513. $VE = [1, 82],
  39514. $VF = [1, 83],
  39515. $VG = [1, 73],
  39516. $VH = [1, 68],
  39517. $VI = [1, 67],
  39518. $VJ = [1, 63],
  39519. $VK = [1, 75],
  39520. $VL = [1, 76],
  39521. $VM = [1, 77],
  39522. $VN = [1, 78],
  39523. $VO = [1, 79],
  39524. $VP = [1, 70],
  39525. $VQ = [1, 69],
  39526. $VR = [8, 9, 11],
  39527. $VS = [8, 9, 11, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64],
  39528. $VT = [1, 115],
  39529. $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],
  39530. $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],
  39531. $VW = [1, 117],
  39532. $VX = [1, 118],
  39533. $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],
  39534. $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],
  39535. $V_ = [13, 18, 46, 81, 86, 88, 89, 91, 92, 94, 95, 96, 97, 98],
  39536. $V$ = [13, 18, 46, 49, 65, 81, 86, 88, 89, 91, 92, 94, 95, 96, 97, 98],
  39537. $V01 = [1, 191],
  39538. $V11 = [1, 188],
  39539. $V21 = [1, 195],
  39540. $V31 = [1, 192],
  39541. $V41 = [1, 189],
  39542. $V51 = [1, 196],
  39543. $V61 = [1, 186],
  39544. $V71 = [1, 187],
  39545. $V81 = [1, 190],
  39546. $V91 = [1, 193],
  39547. $Va1 = [1, 194],
  39548. $Vb1 = [1, 213],
  39549. $Vc1 = [8, 9, 11, 86],
  39550. $Vd1 = [8, 9, 10, 11, 46, 71, 80, 81, 84, 86, 88, 89, 90, 91, 92];
  39551. var parser = { trace: function trace() {},
  39552. yy: {},
  39553. 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 },
  39554. 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" },
  39555. 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]],
  39556. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, /* action[1] */$$, /* vstack */_$ /* lstack */) {
  39557. /* this == yyval */
  39558. var $0 = $$.length - 1;
  39559. switch (yystate) {
  39560. case 2:
  39561. this.$ = [];
  39562. break;
  39563. case 3:
  39564. if ($$[$0] !== []) {
  39565. $$[$0 - 1].push($$[$0]);
  39566. }
  39567. this.$ = $$[$0 - 1];
  39568. break;
  39569. case 4:case 57:case 59:case 60:case 92:case 94:case 95:case 108:
  39570. this.$ = $$[$0];
  39571. break;
  39572. case 11:
  39573. yy.setDirection($$[$0 - 1]);this.$ = $$[$0 - 1];
  39574. break;
  39575. case 12:
  39576. yy.setDirection("LR");this.$ = $$[$0 - 1];
  39577. break;
  39578. case 13:
  39579. yy.setDirection("RL");this.$ = $$[$0 - 1];
  39580. break;
  39581. case 14:
  39582. yy.setDirection("BT");this.$ = $$[$0 - 1];
  39583. break;
  39584. case 15:
  39585. yy.setDirection("TB");this.$ = $$[$0 - 1];
  39586. break;
  39587. case 30:
  39588. this.$ = $$[$0 - 1];
  39589. break;
  39590. case 31:case 32:case 33:case 34:case 35:
  39591. this.$ = [];
  39592. break;
  39593. case 36:
  39594. this.$ = yy.addSubGraph($$[$0 - 1], $$[$0 - 3]);
  39595. break;
  39596. case 37:
  39597. this.$ = yy.addSubGraph($$[$0 - 1], undefined);
  39598. break;
  39599. case 41:
  39600. yy.addLink($$[$0 - 2], $$[$0], $$[$0 - 1]);this.$ = [$$[$0 - 2], $$[$0]];
  39601. break;
  39602. case 42:
  39603. this.$ = [$$[$0]];
  39604. break;
  39605. case 43:
  39606. this.$ = $$[$0 - 3];yy.addVertex($$[$0 - 3], $$[$0 - 1], 'square');
  39607. break;
  39608. case 44:
  39609. this.$ = $$[$0 - 4];yy.addVertex($$[$0 - 4], $$[$0 - 2], 'square');
  39610. break;
  39611. case 45:
  39612. this.$ = $$[$0 - 5];yy.addVertex($$[$0 - 5], $$[$0 - 2], 'circle');
  39613. break;
  39614. case 46:
  39615. this.$ = $$[$0 - 6];yy.addVertex($$[$0 - 6], $$[$0 - 3], 'circle');
  39616. break;
  39617. case 47:
  39618. this.$ = $$[$0 - 3];yy.addVertex($$[$0 - 3], $$[$0 - 1], 'ellipse');
  39619. break;
  39620. case 48:
  39621. this.$ = $$[$0 - 4];yy.addVertex($$[$0 - 4], $$[$0 - 2], 'ellipse');
  39622. break;
  39623. case 49:
  39624. this.$ = $$[$0 - 3];yy.addVertex($$[$0 - 3], $$[$0 - 1], 'round');
  39625. break;
  39626. case 50:
  39627. this.$ = $$[$0 - 4];yy.addVertex($$[$0 - 4], $$[$0 - 2], 'round');
  39628. break;
  39629. case 51:
  39630. this.$ = $$[$0 - 3];yy.addVertex($$[$0 - 3], $$[$0 - 1], 'diamond');
  39631. break;
  39632. case 52:
  39633. this.$ = $$[$0 - 4];yy.addVertex($$[$0 - 4], $$[$0 - 2], 'diamond');
  39634. break;
  39635. case 53:
  39636. this.$ = $$[$0 - 3];yy.addVertex($$[$0 - 3], $$[$0 - 1], 'odd');
  39637. break;
  39638. case 54:
  39639. this.$ = $$[$0 - 4];yy.addVertex($$[$0 - 4], $$[$0 - 2], 'odd');
  39640. break;
  39641. case 55:
  39642. this.$ = $$[$0];yy.addVertex($$[$0]);
  39643. break;
  39644. case 56:
  39645. this.$ = $$[$0 - 1];yy.addVertex($$[$0 - 1]);
  39646. break;
  39647. case 58:case 93:case 96:case 109:
  39648. this.$ = $$[$0 - 1] + '' + $$[$0];
  39649. break;
  39650. case 61:
  39651. this.$ = 'v';
  39652. break;
  39653. case 62:
  39654. this.$ = '-';
  39655. break;
  39656. case 63:
  39657. $$[$0 - 1].text = $$[$0];this.$ = $$[$0 - 1];
  39658. break;
  39659. case 64:case 65:
  39660. $$[$0 - 2].text = $$[$0 - 1];this.$ = $$[$0 - 2];
  39661. break;
  39662. case 66:
  39663. this.$ = $$[$0];
  39664. break;
  39665. case 67:
  39666. this.$ = { "type": "arrow", "stroke": "normal", "text": $$[$0 - 1] };
  39667. break;
  39668. case 68:
  39669. this.$ = { "type": "arrow_circle", "stroke": "normal", "text": $$[$0 - 1] };
  39670. break;
  39671. case 69:
  39672. this.$ = { "type": "arrow_cross", "stroke": "normal", "text": $$[$0 - 1] };
  39673. break;
  39674. case 70:
  39675. this.$ = { "type": "arrow_open", "stroke": "normal", "text": $$[$0 - 1] };
  39676. break;
  39677. case 71:
  39678. this.$ = { "type": "arrow", "stroke": "dotted", "text": $$[$0 - 1] };
  39679. break;
  39680. case 72:
  39681. this.$ = { "type": "arrow_circle", "stroke": "dotted", "text": $$[$0 - 1] };
  39682. break;
  39683. case 73:
  39684. this.$ = { "type": "arrow_cross", "stroke": "dotted", "text": $$[$0 - 1] };
  39685. break;
  39686. case 74:
  39687. this.$ = { "type": "arrow_open", "stroke": "dotted", "text": $$[$0 - 1] };
  39688. break;
  39689. case 75:
  39690. this.$ = { "type": "arrow", "stroke": "thick", "text": $$[$0 - 1] };
  39691. break;
  39692. case 76:
  39693. this.$ = { "type": "arrow_circle", "stroke": "thick", "text": $$[$0 - 1] };
  39694. break;
  39695. case 77:
  39696. this.$ = { "type": "arrow_cross", "stroke": "thick", "text": $$[$0 - 1] };
  39697. break;
  39698. case 78:
  39699. this.$ = { "type": "arrow_open", "stroke": "thick", "text": $$[$0 - 1] };
  39700. break;
  39701. case 79:
  39702. this.$ = { "type": "arrow", "stroke": "normal" };
  39703. break;
  39704. case 80:
  39705. this.$ = { "type": "arrow_circle", "stroke": "normal" };
  39706. break;
  39707. case 81:
  39708. this.$ = { "type": "arrow_cross", "stroke": "normal" };
  39709. break;
  39710. case 82:
  39711. this.$ = { "type": "arrow_open", "stroke": "normal" };
  39712. break;
  39713. case 83:
  39714. this.$ = { "type": "arrow", "stroke": "dotted" };
  39715. break;
  39716. case 84:
  39717. this.$ = { "type": "arrow_circle", "stroke": "dotted" };
  39718. break;
  39719. case 85:
  39720. this.$ = { "type": "arrow_cross", "stroke": "dotted" };
  39721. break;
  39722. case 86:
  39723. this.$ = { "type": "arrow_open", "stroke": "dotted" };
  39724. break;
  39725. case 87:
  39726. this.$ = { "type": "arrow", "stroke": "thick" };
  39727. break;
  39728. case 88:
  39729. this.$ = { "type": "arrow_circle", "stroke": "thick" };
  39730. break;
  39731. case 89:
  39732. this.$ = { "type": "arrow_cross", "stroke": "thick" };
  39733. break;
  39734. case 90:
  39735. this.$ = { "type": "arrow_open", "stroke": "thick" };
  39736. break;
  39737. case 91:
  39738. this.$ = $$[$0 - 1];
  39739. break;
  39740. case 110:case 111:
  39741. this.$ = $$[$0 - 4];yy.addClass($$[$0 - 2], $$[$0]);
  39742. break;
  39743. case 112:
  39744. this.$ = $$[$0 - 4];yy.setClass($$[$0 - 2], $$[$0]);
  39745. break;
  39746. case 113:
  39747. this.$ = $$[$0 - 4];yy.setClickEvent($$[$0 - 2], $$[$0], undefined, undefined);
  39748. break;
  39749. case 114:
  39750. this.$ = $$[$0 - 6];yy.setClickEvent($$[$0 - 4], $$[$0 - 2], undefined, $$[$0]);
  39751. break;
  39752. case 115:
  39753. this.$ = $$[$0 - 4];yy.setClickEvent($$[$0 - 2], undefined, $$[$0], undefined);
  39754. break;
  39755. case 116:
  39756. this.$ = $$[$0 - 6];yy.setClickEvent($$[$0 - 4], undefined, $$[$0 - 2], $$[$0]);
  39757. break;
  39758. case 117:
  39759. this.$ = $$[$0 - 4];yy.addVertex($$[$0 - 2], undefined, undefined, $$[$0]);
  39760. break;
  39761. case 118:case 119:case 120:
  39762. this.$ = $$[$0 - 4];yy.updateLink($$[$0 - 2], $$[$0]);
  39763. break;
  39764. case 121:case 122:
  39765. this.$ = $$[$0 - 8];yy.updateLinkInterpolate($$[$0 - 6], $$[$0 - 2]);yy.updateLink($$[$0 - 6], $$[$0]);
  39766. break;
  39767. case 123:case 124:
  39768. this.$ = $$[$0 - 6];yy.updateLinkInterpolate($$[$0 - 4], $$[$0]);
  39769. break;
  39770. case 126:
  39771. this.$ = [$$[$0]];
  39772. break;
  39773. case 127:
  39774. $$[$0 - 2].push($$[$0]);this.$ = $$[$0 - 2];
  39775. break;
  39776. case 129:
  39777. this.$ = $$[$0 - 1] + $$[$0];
  39778. break;
  39779. }
  39780. },
  39781. 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 })],
  39782. defaultActions: {},
  39783. parseError: function parseError(str, hash) {
  39784. if (hash.recoverable) {
  39785. this.trace(str);
  39786. } else {
  39787. var _parseError = function _parseError(msg, hash) {
  39788. this.message = msg;
  39789. this.hash = hash;
  39790. };
  39791. _parseError.prototype = Error;
  39792. throw new _parseError(str, hash);
  39793. }
  39794. },
  39795. parse: function parse(input) {
  39796. var self = this,
  39797. stack = [0],
  39798. tstack = [],
  39799. vstack = [null],
  39800. lstack = [],
  39801. table = this.table,
  39802. yytext = '',
  39803. yylineno = 0,
  39804. yyleng = 0,
  39805. recovering = 0,
  39806. TERROR = 2,
  39807. EOF = 1;
  39808. var args = lstack.slice.call(arguments, 1);
  39809. var lexer = Object.create(this.lexer);
  39810. var sharedState = { yy: {} };
  39811. for (var k in this.yy) {
  39812. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  39813. sharedState.yy[k] = this.yy[k];
  39814. }
  39815. }
  39816. lexer.setInput(input, sharedState.yy);
  39817. sharedState.yy.lexer = lexer;
  39818. sharedState.yy.parser = this;
  39819. if (typeof lexer.yylloc == 'undefined') {
  39820. lexer.yylloc = {};
  39821. }
  39822. var yyloc = lexer.yylloc;
  39823. lstack.push(yyloc);
  39824. var ranges = lexer.options && lexer.options.ranges;
  39825. if (typeof sharedState.yy.parseError === 'function') {
  39826. this.parseError = sharedState.yy.parseError;
  39827. } else {
  39828. this.parseError = Object.getPrototypeOf(this).parseError;
  39829. }
  39830. function popStack(n) {
  39831. stack.length = stack.length - 2 * n;
  39832. vstack.length = vstack.length - n;
  39833. lstack.length = lstack.length - n;
  39834. }
  39835. _token_stack: var lex = function lex() {
  39836. var token;
  39837. token = lexer.lex() || EOF;
  39838. if (typeof token !== 'number') {
  39839. token = self.symbols_[token] || token;
  39840. }
  39841. return token;
  39842. };
  39843. var symbol,
  39844. preErrorSymbol,
  39845. state,
  39846. action,
  39847. a,
  39848. r,
  39849. yyval = {},
  39850. p,
  39851. len,
  39852. newState,
  39853. expected;
  39854. while (true) {
  39855. state = stack[stack.length - 1];
  39856. if (this.defaultActions[state]) {
  39857. action = this.defaultActions[state];
  39858. } else {
  39859. if (symbol === null || typeof symbol == 'undefined') {
  39860. symbol = lex();
  39861. }
  39862. action = table[state] && table[state][symbol];
  39863. }
  39864. if (typeof action === 'undefined' || !action.length || !action[0]) {
  39865. var errStr = '';
  39866. expected = [];
  39867. for (p in table[state]) {
  39868. if (this.terminals_[p] && p > TERROR) {
  39869. expected.push('\'' + this.terminals_[p] + '\'');
  39870. }
  39871. }
  39872. if (lexer.showPosition) {
  39873. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  39874. } else {
  39875. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  39876. }
  39877. this.parseError(errStr, {
  39878. text: lexer.match,
  39879. token: this.terminals_[symbol] || symbol,
  39880. line: lexer.yylineno,
  39881. loc: yyloc,
  39882. expected: expected
  39883. });
  39884. }
  39885. if (action[0] instanceof Array && action.length > 1) {
  39886. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  39887. }
  39888. switch (action[0]) {
  39889. case 1:
  39890. stack.push(symbol);
  39891. vstack.push(lexer.yytext);
  39892. lstack.push(lexer.yylloc);
  39893. stack.push(action[1]);
  39894. symbol = null;
  39895. if (!preErrorSymbol) {
  39896. yyleng = lexer.yyleng;
  39897. yytext = lexer.yytext;
  39898. yylineno = lexer.yylineno;
  39899. yyloc = lexer.yylloc;
  39900. if (recovering > 0) {
  39901. recovering--;
  39902. }
  39903. } else {
  39904. symbol = preErrorSymbol;
  39905. preErrorSymbol = null;
  39906. }
  39907. break;
  39908. case 2:
  39909. len = this.productions_[action[1]][1];
  39910. yyval.$ = vstack[vstack.length - len];
  39911. yyval._$ = {
  39912. first_line: lstack[lstack.length - (len || 1)].first_line,
  39913. last_line: lstack[lstack.length - 1].last_line,
  39914. first_column: lstack[lstack.length - (len || 1)].first_column,
  39915. last_column: lstack[lstack.length - 1].last_column
  39916. };
  39917. if (ranges) {
  39918. yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
  39919. }
  39920. r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
  39921. if (typeof r !== 'undefined') {
  39922. return r;
  39923. }
  39924. if (len) {
  39925. stack = stack.slice(0, -1 * len * 2);
  39926. vstack = vstack.slice(0, -1 * len);
  39927. lstack = lstack.slice(0, -1 * len);
  39928. }
  39929. stack.push(this.productions_[action[1]][0]);
  39930. vstack.push(yyval.$);
  39931. lstack.push(yyval._$);
  39932. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  39933. stack.push(newState);
  39934. break;
  39935. case 3:
  39936. return true;
  39937. }
  39938. }
  39939. return true;
  39940. } };
  39941. /* generated by jison-lex 0.3.4 */
  39942. var lexer = (function () {
  39943. var lexer = {
  39944. EOF: 1,
  39945. parseError: function parseError(str, hash) {
  39946. if (this.yy.parser) {
  39947. this.yy.parser.parseError(str, hash);
  39948. } else {
  39949. throw new Error(str);
  39950. }
  39951. },
  39952. // resets the lexer, sets new input
  39953. setInput: function setInput(input, yy) {
  39954. this.yy = yy || this.yy || {};
  39955. this._input = input;
  39956. this._more = this._backtrack = this.done = false;
  39957. this.yylineno = this.yyleng = 0;
  39958. this.yytext = this.matched = this.match = '';
  39959. this.conditionStack = ['INITIAL'];
  39960. this.yylloc = {
  39961. first_line: 1,
  39962. first_column: 0,
  39963. last_line: 1,
  39964. last_column: 0
  39965. };
  39966. if (this.options.ranges) {
  39967. this.yylloc.range = [0, 0];
  39968. }
  39969. this.offset = 0;
  39970. return this;
  39971. },
  39972. // consumes and returns one char from the input
  39973. input: function input() {
  39974. var ch = this._input[0];
  39975. this.yytext += ch;
  39976. this.yyleng++;
  39977. this.offset++;
  39978. this.match += ch;
  39979. this.matched += ch;
  39980. var lines = ch.match(/(?:\r\n?|\n).*/g);
  39981. if (lines) {
  39982. this.yylineno++;
  39983. this.yylloc.last_line++;
  39984. } else {
  39985. this.yylloc.last_column++;
  39986. }
  39987. if (this.options.ranges) {
  39988. this.yylloc.range[1]++;
  39989. }
  39990. this._input = this._input.slice(1);
  39991. return ch;
  39992. },
  39993. // unshifts one char (or a string) into the input
  39994. unput: function unput(ch) {
  39995. var len = ch.length;
  39996. var lines = ch.split(/(?:\r\n?|\n)/g);
  39997. this._input = ch + this._input;
  39998. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  39999. //this.yyleng -= len;
  40000. this.offset -= len;
  40001. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  40002. this.match = this.match.substr(0, this.match.length - 1);
  40003. this.matched = this.matched.substr(0, this.matched.length - 1);
  40004. if (lines.length - 1) {
  40005. this.yylineno -= lines.length - 1;
  40006. }
  40007. var r = this.yylloc.range;
  40008. this.yylloc = {
  40009. first_line: this.yylloc.first_line,
  40010. last_line: this.yylineno + 1,
  40011. first_column: this.yylloc.first_column,
  40012. 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
  40013. };
  40014. if (this.options.ranges) {
  40015. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  40016. }
  40017. this.yyleng = this.yytext.length;
  40018. return this;
  40019. },
  40020. // When called from action, caches matched text and appends it on next action
  40021. more: function more() {
  40022. this._more = true;
  40023. return this;
  40024. },
  40025. // 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.
  40026. reject: function reject() {
  40027. if (this.options.backtrack_lexer) {
  40028. this._backtrack = true;
  40029. } else {
  40030. 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(), {
  40031. text: "",
  40032. token: null,
  40033. line: this.yylineno
  40034. });
  40035. }
  40036. return this;
  40037. },
  40038. // retain first n characters of the match
  40039. less: function less(n) {
  40040. this.unput(this.match.slice(n));
  40041. },
  40042. // displays already matched input, i.e. for error messages
  40043. pastInput: function pastInput() {
  40044. var past = this.matched.substr(0, this.matched.length - this.match.length);
  40045. return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
  40046. },
  40047. // displays upcoming input, i.e. for error messages
  40048. upcomingInput: function upcomingInput() {
  40049. var next = this.match;
  40050. if (next.length < 20) {
  40051. next += this._input.substr(0, 20 - next.length);
  40052. }
  40053. return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  40054. },
  40055. // displays the character position where the lexing error occurred, i.e. for error messages
  40056. showPosition: function showPosition() {
  40057. var pre = this.pastInput();
  40058. var c = new Array(pre.length + 1).join("-");
  40059. return pre + this.upcomingInput() + "\n" + c + "^";
  40060. },
  40061. // test the lexed token: return FALSE when not a match, otherwise return token
  40062. test_match: function test_match(match, indexed_rule) {
  40063. var token, lines, backup;
  40064. if (this.options.backtrack_lexer) {
  40065. // save context
  40066. backup = {
  40067. yylineno: this.yylineno,
  40068. yylloc: {
  40069. first_line: this.yylloc.first_line,
  40070. last_line: this.last_line,
  40071. first_column: this.yylloc.first_column,
  40072. last_column: this.yylloc.last_column
  40073. },
  40074. yytext: this.yytext,
  40075. match: this.match,
  40076. matches: this.matches,
  40077. matched: this.matched,
  40078. yyleng: this.yyleng,
  40079. offset: this.offset,
  40080. _more: this._more,
  40081. _input: this._input,
  40082. yy: this.yy,
  40083. conditionStack: this.conditionStack.slice(0),
  40084. done: this.done
  40085. };
  40086. if (this.options.ranges) {
  40087. backup.yylloc.range = this.yylloc.range.slice(0);
  40088. }
  40089. }
  40090. lines = match[0].match(/(?:\r\n?|\n).*/g);
  40091. if (lines) {
  40092. this.yylineno += lines.length;
  40093. }
  40094. this.yylloc = {
  40095. first_line: this.yylloc.last_line,
  40096. last_line: this.yylineno + 1,
  40097. first_column: this.yylloc.last_column,
  40098. last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
  40099. };
  40100. this.yytext += match[0];
  40101. this.match += match[0];
  40102. this.matches = match;
  40103. this.yyleng = this.yytext.length;
  40104. if (this.options.ranges) {
  40105. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  40106. }
  40107. this._more = false;
  40108. this._backtrack = false;
  40109. this._input = this._input.slice(match[0].length);
  40110. this.matched += match[0];
  40111. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  40112. if (this.done && this._input) {
  40113. this.done = false;
  40114. }
  40115. if (token) {
  40116. return token;
  40117. } else if (this._backtrack) {
  40118. // recover context
  40119. for (var k in backup) {
  40120. this[k] = backup[k];
  40121. }
  40122. return false; // rule action called reject() implying the next rule should be tested instead.
  40123. }
  40124. return false;
  40125. },
  40126. // return next match in input
  40127. next: function next() {
  40128. if (this.done) {
  40129. return this.EOF;
  40130. }
  40131. if (!this._input) {
  40132. this.done = true;
  40133. }
  40134. var token, match, tempMatch, index;
  40135. if (!this._more) {
  40136. this.yytext = '';
  40137. this.match = '';
  40138. }
  40139. var rules = this._currentRules();
  40140. for (var i = 0; i < rules.length; i++) {
  40141. tempMatch = this._input.match(this.rules[rules[i]]);
  40142. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  40143. match = tempMatch;
  40144. index = i;
  40145. if (this.options.backtrack_lexer) {
  40146. token = this.test_match(tempMatch, rules[i]);
  40147. if (token !== false) {
  40148. return token;
  40149. } else if (this._backtrack) {
  40150. match = false;
  40151. continue; // rule action called reject() implying a rule MISmatch.
  40152. } else {
  40153. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  40154. return false;
  40155. }
  40156. } else if (!this.options.flex) {
  40157. break;
  40158. }
  40159. }
  40160. }
  40161. if (match) {
  40162. token = this.test_match(match, rules[index]);
  40163. if (token !== false) {
  40164. return token;
  40165. }
  40166. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  40167. return false;
  40168. }
  40169. if (this._input === "") {
  40170. return this.EOF;
  40171. } else {
  40172. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  40173. text: "",
  40174. token: null,
  40175. line: this.yylineno
  40176. });
  40177. }
  40178. },
  40179. // return next match that has a token
  40180. lex: function lex() {
  40181. var r = this.next();
  40182. if (r) {
  40183. return r;
  40184. } else {
  40185. return this.lex();
  40186. }
  40187. },
  40188. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  40189. begin: function begin(condition) {
  40190. this.conditionStack.push(condition);
  40191. },
  40192. // pop the previously active lexer condition state off the condition stack
  40193. popState: function popState() {
  40194. var n = this.conditionStack.length - 1;
  40195. if (n > 0) {
  40196. return this.conditionStack.pop();
  40197. } else {
  40198. return this.conditionStack[0];
  40199. }
  40200. },
  40201. // produce the lexer rule set which is active for the currently active lexer condition state
  40202. _currentRules: function _currentRules() {
  40203. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  40204. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  40205. } else {
  40206. return this.conditions["INITIAL"].rules;
  40207. }
  40208. },
  40209. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  40210. topState: function topState(n) {
  40211. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  40212. if (n >= 0) {
  40213. return this.conditionStack[n];
  40214. } else {
  40215. return "INITIAL";
  40216. }
  40217. },
  40218. // alias for begin(condition)
  40219. pushState: function pushState(condition) {
  40220. this.begin(condition);
  40221. },
  40222. // return the number of states currently on the stack
  40223. stateStackSize: function stateStackSize() {
  40224. return this.conditionStack.length;
  40225. },
  40226. options: {},
  40227. performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
  40228. var YYSTATE = YY_START;
  40229. switch ($avoiding_name_collisions) {
  40230. case 0:
  40231. /* do nothing */
  40232. break;
  40233. case 1:
  40234. this.begin("string");
  40235. break;
  40236. case 2:
  40237. this.popState();
  40238. break;
  40239. case 3:
  40240. return "STR";
  40241. break;
  40242. case 4:
  40243. return 71;
  40244. break;
  40245. case 5:
  40246. return 78;
  40247. break;
  40248. case 6:
  40249. return 72;
  40250. break;
  40251. case 7:
  40252. return 82;
  40253. break;
  40254. case 8:
  40255. return 73;
  40256. break;
  40257. case 9:
  40258. return 74;
  40259. break;
  40260. case 10:
  40261. return 75;
  40262. break;
  40263. case 11:
  40264. return 12;
  40265. break;
  40266. case 12:
  40267. return 30;
  40268. break;
  40269. case 13:
  40270. return 32;
  40271. break;
  40272. case 14:
  40273. return 13;
  40274. break;
  40275. case 15:
  40276. return 13;
  40277. break;
  40278. case 16:
  40279. return 13;
  40280. break;
  40281. case 17:
  40282. return 13;
  40283. break;
  40284. case 18:
  40285. return 13;
  40286. break;
  40287. case 19:
  40288. return 13;
  40289. break;
  40290. case 20:
  40291. return 81;
  40292. break;
  40293. case 21:
  40294. return 91;
  40295. break;
  40296. case 22:
  40297. return 89;
  40298. break;
  40299. case 23:
  40300. return 8;
  40301. break;
  40302. case 24:
  40303. return 86;
  40304. break;
  40305. case 25:
  40306. return 98;
  40307. break;
  40308. case 26:
  40309. return 16;
  40310. break;
  40311. case 27:
  40312. return 15;
  40313. break;
  40314. case 28:
  40315. return 17;
  40316. break;
  40317. case 29:
  40318. return 18;
  40319. break;
  40320. case 30:
  40321. return 53;
  40322. break;
  40323. case 31:
  40324. return 51;
  40325. break;
  40326. case 32:
  40327. return 52;
  40328. break;
  40329. case 33:
  40330. return 54;
  40331. break;
  40332. case 34:
  40333. return 58;
  40334. break;
  40335. case 35:
  40336. return 56;
  40337. break;
  40338. case 36:
  40339. return 57;
  40340. break;
  40341. case 37:
  40342. return 59;
  40343. break;
  40344. case 38:
  40345. return 58;
  40346. break;
  40347. case 39:
  40348. return 56;
  40349. break;
  40350. case 40:
  40351. return 57;
  40352. break;
  40353. case 41:
  40354. return 59;
  40355. break;
  40356. case 42:
  40357. return 63;
  40358. break;
  40359. case 43:
  40360. return 61;
  40361. break;
  40362. case 44:
  40363. return 62;
  40364. break;
  40365. case 45:
  40366. return 64;
  40367. break;
  40368. case 46:
  40369. return 50;
  40370. break;
  40371. case 47:
  40372. return 55;
  40373. break;
  40374. case 48:
  40375. return 60;
  40376. break;
  40377. case 49:
  40378. return 40;
  40379. break;
  40380. case 50:
  40381. return 41;
  40382. break;
  40383. case 51:
  40384. return 46;
  40385. break;
  40386. case 52:
  40387. return 92;
  40388. break;
  40389. case 53:
  40390. return 96;
  40391. break;
  40392. case 54:
  40393. return 84;
  40394. break;
  40395. case 55:
  40396. return 97;
  40397. break;
  40398. case 56:
  40399. return 97;
  40400. break;
  40401. case 57:
  40402. return 88;
  40403. break;
  40404. case 58:
  40405. return 94;
  40406. break;
  40407. case 59:
  40408. return 95;
  40409. break;
  40410. case 60:
  40411. return 65;
  40412. break;
  40413. case 61:
  40414. return 38;
  40415. break;
  40416. case 62:
  40417. return 39;
  40418. break;
  40419. case 63:
  40420. return 36;
  40421. break;
  40422. case 64:
  40423. return 37;
  40424. break;
  40425. case 65:
  40426. return 42;
  40427. break;
  40428. case 66:
  40429. return 43;
  40430. break;
  40431. case 67:
  40432. return 101;
  40433. break;
  40434. case 68:
  40435. return 9;
  40436. break;
  40437. case 69:
  40438. return 10;
  40439. break;
  40440. case 70:
  40441. return 11;
  40442. break;
  40443. }
  40444. },
  40445. 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)/, /^(?:$)/],
  40446. 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 } }
  40447. };
  40448. return lexer;
  40449. })();
  40450. parser.lexer = lexer;
  40451. function Parser() {
  40452. this.yy = {};
  40453. }
  40454. Parser.prototype = parser;parser.Parser = Parser;
  40455. return new Parser();
  40456. })();
  40457. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  40458. exports.parser = parser;
  40459. exports.Parser = parser.Parser;
  40460. exports.parse = function () {
  40461. return parser.parse.apply(parser, arguments);
  40462. };
  40463. exports.main = function commonjsMain(args) {
  40464. if (!args[1]) {
  40465. console.log('Usage: ' + args[0] + ' FILE');
  40466. process.exit(1);
  40467. }
  40468. var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
  40469. return exports.parser.parse(source);
  40470. };
  40471. if (typeof module !== 'undefined' && require.main === module) {
  40472. exports.main(process.argv.slice(1));
  40473. }
  40474. }
  40475. }).call(this,require('_process'))
  40476. },{"_process":106,"fs":1,"path":105}],120:[function(require,module,exports){
  40477. (function (global){
  40478. /**
  40479. * Created by knut on 15-01-14.
  40480. */
  40481. 'use strict';
  40482. var moment = require('moment');
  40483. var Logger = require('../../logger');
  40484. var log = new Logger.Log();
  40485. var dateFormat = '';
  40486. var title = '';
  40487. var sections = [];
  40488. var tasks = [];
  40489. var currentSection = '';
  40490. exports.clear = function () {
  40491. sections = [];
  40492. tasks = [];
  40493. currentSection = '';
  40494. title = '';
  40495. taskCnt = 0;
  40496. lastTask = undefined;
  40497. lastTaskID = undefined;
  40498. rawTasks = [];
  40499. };
  40500. exports.setDateFormat = function (txt) {
  40501. dateFormat = txt;
  40502. };
  40503. exports.getDateFormat = function () {
  40504. return dateFormat;
  40505. };
  40506. exports.setTitle = function (txt) {
  40507. title = txt;
  40508. };
  40509. exports.getTitle = function () {
  40510. return title;
  40511. };
  40512. exports.addSection = function (txt) {
  40513. currentSection = txt;
  40514. sections.push(txt);
  40515. };
  40516. exports.getTasks = function () {
  40517. var allItemsPricessed = compileTasks();
  40518. var maxDepth = 10;
  40519. var iterationCount = 0;
  40520. while (!allItemsPricessed && iterationCount < maxDepth) {
  40521. allItemsPricessed = compileTasks();
  40522. iterationCount++;
  40523. }
  40524. tasks = rawTasks;
  40525. //var i;
  40526. //for(i=10000;i<tasks.length;i++){
  40527. // tasks[i].startTime = moment(tasks[i].startTime).format(dateFormat);
  40528. // tasks[i].endTime = moment(tasks[i].endTime).format(dateFormat);
  40529. //}
  40530. return tasks;
  40531. };
  40532. var getStartDate = function getStartDate(prevTime, dateFormat, str) {
  40533. //console.log('Deciding start date:'+JSON.stringify(str));
  40534. //log.debug('Deciding start date:'+str);
  40535. //log.debug('with dateformat:'+dateFormat);
  40536. str = str.trim();
  40537. // Test for after
  40538. var re = /^after\s+([\d\w\-]+)/;
  40539. var afterStatement = re.exec(str.trim());
  40540. if (afterStatement !== null) {
  40541. var task = exports.findTaskById(afterStatement[1]);
  40542. if (typeof task === 'undefined') {
  40543. var dt = new Date();
  40544. dt.setHours(0, 0, 0, 0);
  40545. return dt;
  40546. //return undefined;
  40547. }
  40548. return task.endTime;
  40549. }
  40550. // Check for actual date set
  40551. if (moment(str, dateFormat.trim(), true).isValid()) {
  40552. return moment(str, dateFormat.trim(), true).toDate();
  40553. } else {
  40554. log.debug('Invalid date:' + str);
  40555. log.debug('With date format:' + dateFormat.trim());
  40556. //log.debug('----');
  40557. }
  40558. // Default date - now
  40559. return new Date();
  40560. };
  40561. var getEndDate = function getEndDate(prevTime, dateFormat, str) {
  40562. str = str.trim();
  40563. // Check for actual date
  40564. if (moment(str, dateFormat.trim(), true).isValid()) {
  40565. return moment(str, dateFormat.trim()).toDate();
  40566. }
  40567. var d = moment(prevTime);
  40568. // Check for length
  40569. var re = /^([\d]+)([wdhms])/;
  40570. var durationStatement = re.exec(str.trim());
  40571. if (durationStatement !== null) {
  40572. switch (durationStatement[2]) {
  40573. case 's':
  40574. d.add(durationStatement[1], 'seconds');
  40575. break;
  40576. case 'm':
  40577. d.add(durationStatement[1], 'minutes');
  40578. break;
  40579. case 'h':
  40580. d.add(durationStatement[1], 'hours');
  40581. break;
  40582. case 'd':
  40583. d.add(durationStatement[1], 'days');
  40584. break;
  40585. case 'w':
  40586. d.add(durationStatement[1], 'weeks');
  40587. break;
  40588. }
  40589. return d.toDate();
  40590. }
  40591. // Default date - now
  40592. return d.toDate();
  40593. };
  40594. var taskCnt = 0;
  40595. var parseId = function parseId(idStr) {
  40596. if (typeof idStr === 'undefined') {
  40597. taskCnt = taskCnt + 1;
  40598. return 'task' + taskCnt;
  40599. }
  40600. return idStr;
  40601. };
  40602. // id, startDate, endDate
  40603. // id, startDate, length
  40604. // id, after x, endDate
  40605. // id, after x, length
  40606. // startDate, endDate
  40607. // startDate, length
  40608. // after x, endDate
  40609. // after x, length
  40610. // endDate
  40611. // length
  40612. var compileData = function compileData(prevTask, dataStr) {
  40613. var ds;
  40614. if (dataStr.substr(0, 1) === ':') {
  40615. ds = dataStr.substr(1, dataStr.length);
  40616. } else {
  40617. ds = dataStr;
  40618. }
  40619. var data = ds.split(',');
  40620. var task = {};
  40621. var df = exports.getDateFormat();
  40622. // Get tags like active, done cand crit
  40623. var matchFound = true;
  40624. while (matchFound) {
  40625. matchFound = false;
  40626. if (data[0].match(/^\s*active\s*$/)) {
  40627. task.active = true;
  40628. data.shift(1);
  40629. matchFound = true;
  40630. }
  40631. if (data[0].match(/^\s*done\s*$/)) {
  40632. task.done = true;
  40633. data.shift(1);
  40634. matchFound = true;
  40635. }
  40636. if (data[0].match(/^\s*crit\s*$/)) {
  40637. task.crit = true;
  40638. data.shift(1);
  40639. matchFound = true;
  40640. }
  40641. }
  40642. var i;
  40643. for (i = 0; i < data.length; i++) {
  40644. data[i] = data[i].trim();
  40645. }
  40646. switch (data.length) {
  40647. case 1:
  40648. task.id = parseId();
  40649. task.startTime = prevTask.endTime;
  40650. task.endTime = getEndDate(task.startTime, df, data[0]);
  40651. break;
  40652. case 2:
  40653. task.id = parseId();
  40654. task.startTime = getStartDate(undefined, df, data[0]);
  40655. task.endTime = getEndDate(task.startTime, df, data[1]);
  40656. break;
  40657. case 3:
  40658. task.id = parseId(data[0]);
  40659. task.startTime = getStartDate(undefined, df, data[1]);
  40660. task.endTime = getEndDate(task.startTime, df, data[2]);
  40661. break;
  40662. default:
  40663. }
  40664. return task;
  40665. };
  40666. var parseData = function parseData(prevTaskId, dataStr) {
  40667. var ds;
  40668. if (dataStr.substr(0, 1) === ':') {
  40669. ds = dataStr.substr(1, dataStr.length);
  40670. } else {
  40671. ds = dataStr;
  40672. }
  40673. var data = ds.split(',');
  40674. var task = {};
  40675. // Get tags like active, done cand crit
  40676. var matchFound = true;
  40677. while (matchFound) {
  40678. matchFound = false;
  40679. if (data[0].match(/^\s*active\s*$/)) {
  40680. task.active = true;
  40681. data.shift(1);
  40682. matchFound = true;
  40683. }
  40684. if (data[0].match(/^\s*done\s*$/)) {
  40685. task.done = true;
  40686. data.shift(1);
  40687. matchFound = true;
  40688. }
  40689. if (data[0].match(/^\s*crit\s*$/)) {
  40690. task.crit = true;
  40691. data.shift(1);
  40692. matchFound = true;
  40693. }
  40694. }
  40695. var i;
  40696. for (i = 0; i < data.length; i++) {
  40697. data[i] = data[i].trim();
  40698. }
  40699. switch (data.length) {
  40700. case 1:
  40701. task.id = parseId();
  40702. task.startTime = { type: 'prevTaskEnd', id: prevTaskId };
  40703. task.endTime = { data: data[0] };
  40704. break;
  40705. case 2:
  40706. task.id = parseId();
  40707. task.startTime = { type: 'getStartDate', startData: data[0] };
  40708. task.endTime = { data: data[1] };
  40709. break;
  40710. case 3:
  40711. task.id = parseId(data[0]);
  40712. task.startTime = { type: 'getStartDate', startData: data[1] };
  40713. task.endTime = { data: data[2] };
  40714. break;
  40715. default:
  40716. }
  40717. return task;
  40718. };
  40719. var lastTask;
  40720. var lastTaskID;
  40721. var rawTasks = [];
  40722. var taskDb = {};
  40723. exports.addTask = function (descr, data) {
  40724. var rawTask = {
  40725. section: currentSection,
  40726. type: currentSection,
  40727. processed: false,
  40728. raw: { data: data },
  40729. task: descr
  40730. };
  40731. var taskInfo = parseData(lastTaskID, data);
  40732. rawTask.raw.startTime = taskInfo.startTime;
  40733. rawTask.raw.endTime = taskInfo.endTime;
  40734. rawTask.id = taskInfo.id;
  40735. rawTask.prevTaskId = lastTaskID;
  40736. rawTask.active = taskInfo.active;
  40737. rawTask.done = taskInfo.done;
  40738. rawTask.crit = taskInfo.crit;
  40739. var pos = rawTasks.push(rawTask);
  40740. lastTaskID = rawTask.id;
  40741. // Store cross ref
  40742. taskDb[rawTask.id] = pos - 1;
  40743. };
  40744. exports.findTaskById = function (id) {
  40745. //var i;
  40746. //for(i=0;i<tasks.length;i++){
  40747. // if(tasks[i].id === id){
  40748. // return tasks[i];
  40749. // }
  40750. //}
  40751. var pos = taskDb[id];
  40752. return rawTasks[pos];
  40753. };
  40754. exports.addTaskOrg = function (descr, data) {
  40755. var newTask = {
  40756. section: currentSection,
  40757. type: currentSection,
  40758. description: descr,
  40759. task: descr
  40760. };
  40761. var taskInfo = compileData(lastTask, data);
  40762. newTask.startTime = taskInfo.startTime;
  40763. newTask.endTime = taskInfo.endTime;
  40764. newTask.id = taskInfo.id;
  40765. newTask.active = taskInfo.active;
  40766. newTask.done = taskInfo.done;
  40767. newTask.crit = taskInfo.crit;
  40768. lastTask = newTask;
  40769. tasks.push(newTask);
  40770. };
  40771. var compileTasks = function compileTasks() {
  40772. var df = exports.getDateFormat();
  40773. var compileTask = function compileTask(pos) {
  40774. var task = rawTasks[pos];
  40775. var startTime = '';
  40776. switch (rawTasks[pos].raw.startTime.type) {
  40777. case 'prevTaskEnd':
  40778. var prevTask = exports.findTaskById(task.prevTaskId);
  40779. task.startTime = prevTask.endTime;
  40780. break;
  40781. case 'getStartDate':
  40782. startTime = getStartDate(undefined, df, rawTasks[pos].raw.startTime.startData);
  40783. if (startTime) {
  40784. rawTasks[pos].startTime = startTime;
  40785. }
  40786. break;
  40787. }
  40788. if (rawTasks[pos].startTime) {
  40789. rawTasks[pos].endTime = getEndDate(rawTasks[pos].startTime, df, rawTasks[pos].raw.endTime.data);
  40790. if (rawTasks[pos].endTime) {
  40791. rawTasks[pos].processed = true;
  40792. }
  40793. }
  40794. return rawTasks[pos].processed;
  40795. };
  40796. var i;
  40797. var allProcessed = true;
  40798. for (i = 0; i < rawTasks.length; i++) {
  40799. compileTask(i);
  40800. allProcessed = allProcessed && rawTasks[i].processed;
  40801. }
  40802. return allProcessed;
  40803. };
  40804. exports.parseError = function (err, hash) {
  40805. global.mermaidAPI.parseError(err, hash);
  40806. };
  40807. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  40808. },{"../../logger":130,"moment":104}],121:[function(require,module,exports){
  40809. 'use strict';
  40810. var gantt = require('./parser/gantt').parser;
  40811. gantt.yy = require('./ganttDb');
  40812. var d3 = require('../../d3');
  40813. var moment = require('moment');
  40814. //var log = require('../../logger').create();
  40815. var daysInChart;
  40816. var conf = {
  40817. titleTopMargin: 25,
  40818. barHeight: 20,
  40819. barGap: 4,
  40820. topPadding: 50,
  40821. rightPadding: 75,
  40822. leftPadding: 75,
  40823. gridLineStartPadding: 35,
  40824. fontSize: 11,
  40825. fontFamily: '"Open-Sans", "sans-serif"'
  40826. };
  40827. module.exports.setConf = function (cnf) {
  40828. var keys = Object.keys(cnf);
  40829. keys.forEach(function (key) {
  40830. conf[key] = cnf[key];
  40831. });
  40832. };
  40833. var w;
  40834. module.exports.draw = function (text, id) {
  40835. gantt.yy.clear();
  40836. gantt.parse(text);
  40837. var elem = document.getElementById(id);
  40838. w = elem.parentElement.offsetWidth;
  40839. if (typeof w === 'undefined') {
  40840. w = 1200;
  40841. }
  40842. if (typeof conf.useWidth !== 'undefined') {
  40843. w = conf.useWidth;
  40844. }
  40845. var taskArray = gantt.yy.getTasks();
  40846. // Set height based on number of tasks
  40847. var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding;
  40848. elem.setAttribute('height', '100%');
  40849. // Set viewBox
  40850. elem.setAttribute('viewBox', '0 0 ' + w + ' ' + h);
  40851. var svg = d3.select('#' + id);
  40852. //var dateFormat = d3.time.format('%Y-%m-%d');
  40853. var startDate = d3.min(taskArray, function (d) {
  40854. return d.startTime;
  40855. });
  40856. var endDate = d3.max(taskArray, function (d) {
  40857. return d.endTime;
  40858. });
  40859. // Set timescale
  40860. var timeScale = d3.time.scale().domain([d3.min(taskArray, function (d) {
  40861. return d.startTime;
  40862. }), d3.max(taskArray, function (d) {
  40863. return d.endTime;
  40864. })]).rangeRound([0, w - conf.leftPadding - conf.rightPadding]);
  40865. //.nice(d3.time.monday);
  40866. var categories = [];
  40867. daysInChart = moment.duration(endDate - startDate).asDays();
  40868. for (var i = 0; i < taskArray.length; i++) {
  40869. categories.push(taskArray[i].type);
  40870. }
  40871. var catsUnfiltered = categories; //for vert labels
  40872. categories = checkUnique(categories);
  40873. makeGant(taskArray, w, h);
  40874. if (typeof conf.useWidth !== 'undefined') {
  40875. elem.setAttribute('width', w);
  40876. }
  40877. svg.append('text').text(gantt.yy.getTitle()).attr('x', w / 2).attr('y', conf.titleTopMargin).attr('class', 'titleText');
  40878. function makeGant(tasks, pageWidth, pageHeight) {
  40879. var barHeight = conf.barHeight;
  40880. var gap = barHeight + conf.barGap;
  40881. var topPadding = conf.topPadding;
  40882. var leftPadding = conf.leftPadding;
  40883. var colorScale = d3.scale.linear().domain([0, categories.length]).range(['#00B9FA', '#F95002']).interpolate(d3.interpolateHcl);
  40884. makeGrid(leftPadding, topPadding, pageWidth, pageHeight);
  40885. drawRects(tasks, gap, topPadding, leftPadding, barHeight, colorScale, pageWidth, pageHeight);
  40886. vertLabels(gap, topPadding, leftPadding, barHeight, colorScale);
  40887. drawToday(leftPadding, topPadding, pageWidth, pageHeight);
  40888. }
  40889. function drawRects(theArray, theGap, theTopPad, theSidePad, theBarHeight, theColorScale, w, h) {
  40890. //eslint-disable-line no-unused-vars
  40891. svg.append('g').selectAll('rect').data(theArray).enter().append('rect').attr('x', 0).attr('y', function (d, i) {
  40892. return i * theGap + theTopPad - 2;
  40893. }).attr('width', function () {
  40894. return w - conf.rightPadding / 2;
  40895. }).attr('height', theGap).attr('class', function (d) {
  40896. //eslint-disable-line no-unused-vars
  40897. for (var i = 0; i < categories.length; i++) {
  40898. if (d.type === categories[i]) {
  40899. return 'section section' + i % conf.numberSectionStyles;
  40900. }
  40901. }
  40902. return 'section section0';
  40903. });
  40904. var rectangles = svg.append('g').selectAll('rect').data(theArray).enter();
  40905. rectangles.append('rect').attr('rx', 3).attr('ry', 3).attr('x', function (d) {
  40906. return timeScale(d.startTime) + theSidePad;
  40907. }).attr('y', function (d, i) {
  40908. return i * theGap + theTopPad;
  40909. }).attr('width', function (d) {
  40910. return timeScale(d.endTime) - timeScale(d.startTime);
  40911. }).attr('height', theBarHeight).attr('class', function (d) {
  40912. var res = 'task ';
  40913. var secNum = 0;
  40914. for (var i = 0; i < categories.length; i++) {
  40915. if (d.type === categories[i]) {
  40916. secNum = i % conf.numberSectionStyles;
  40917. }
  40918. }
  40919. if (d.active) {
  40920. if (d.crit) {
  40921. return res + ' activeCrit' + secNum;
  40922. } else {
  40923. return res + ' active' + secNum;
  40924. }
  40925. }
  40926. if (d.done) {
  40927. if (d.crit) {
  40928. return res + ' doneCrit' + secNum;
  40929. } else {
  40930. return res + ' done' + secNum;
  40931. }
  40932. }
  40933. if (d.crit) {
  40934. return res + ' crit' + secNum;
  40935. }
  40936. return res + ' task' + secNum;
  40937. });
  40938. rectangles.append('text').text(function (d) {
  40939. return d.task;
  40940. }).attr('font-size', conf.fontSize)
  40941. //.attr('font-family',conf.fontFamily)
  40942. .attr('x', function (d) {
  40943. var startX = timeScale(d.startTime),
  40944. endX = timeScale(d.endTime),
  40945. textWidth = this.getBBox().width;
  40946. // Check id text width > width of rectangle
  40947. if (textWidth > endX - startX) {
  40948. if (endX + textWidth + 1.5 * conf.leftPadding > w) {
  40949. return startX + theSidePad - 5;
  40950. } else {
  40951. return endX + theSidePad + 5;
  40952. }
  40953. } else {
  40954. return (endX - startX) / 2 + startX + theSidePad;
  40955. }
  40956. }).attr('y', function (d, i) {
  40957. return i * theGap + conf.barHeight / 2 + (conf.fontSize / 2 - 2) + theTopPad;
  40958. })
  40959. //.attr('text-anchor', 'middle')
  40960. .attr('text-height', theBarHeight).attr('class', function (d) {
  40961. var startX = timeScale(d.startTime),
  40962. endX = timeScale(d.endTime),
  40963. textWidth = this.getBBox().width;
  40964. var secNum = 0;
  40965. for (var i = 0; i < categories.length; i++) {
  40966. if (d.type === categories[i]) {
  40967. secNum = i % conf.numberSectionStyles;
  40968. }
  40969. }
  40970. var taskType = '';
  40971. if (d.active) {
  40972. if (d.crit) {
  40973. taskType = 'activeCritText' + secNum;
  40974. } else {
  40975. taskType = 'activeText' + secNum;
  40976. }
  40977. }
  40978. if (d.done) {
  40979. if (d.crit) {
  40980. taskType = taskType + ' doneCritText' + secNum;
  40981. } else {
  40982. taskType = taskType + ' doneText' + secNum;
  40983. }
  40984. } else {
  40985. if (d.crit) {
  40986. taskType = taskType + ' critText' + secNum;
  40987. }
  40988. }
  40989. // Check id text width > width of rectangle
  40990. if (textWidth > endX - startX) {
  40991. if (endX + textWidth + 1.5 * conf.leftPadding > w) {
  40992. return 'taskTextOutsideLeft taskTextOutside' + secNum + ' ' + taskType;
  40993. } else {
  40994. return 'taskTextOutsideRight taskTextOutside' + secNum + ' ' + taskType;
  40995. }
  40996. } else {
  40997. return 'taskText taskText' + secNum + ' ' + taskType;
  40998. }
  40999. });
  41000. }
  41001. function makeGrid(theSidePad, theTopPad, w, h) {
  41002. var pre = [['.%L', function (d) {
  41003. return d.getMilliseconds();
  41004. }], [':%S', function (d) {
  41005. return d.getSeconds();
  41006. }],
  41007. // Within a hour
  41008. ['h1 %I:%M', function (d) {
  41009. return d.getMinutes();
  41010. }]];
  41011. var post = [['%Y', function () {
  41012. return true;
  41013. }]];
  41014. var mid = [
  41015. // Within a day
  41016. ['%I:%M', function (d) {
  41017. return d.getHours();
  41018. }],
  41019. // Day within a week (not monday)
  41020. ['%a %d', function (d) {
  41021. //return d.getDay() ==1;
  41022. return d.getDay() && d.getDate() != 1;
  41023. }],
  41024. // within a month
  41025. ['%b %d', function (d) {
  41026. return d.getDate() != 1;
  41027. }],
  41028. // Month
  41029. ['%B', function (d) {
  41030. return d.getMonth();
  41031. }]];
  41032. var formatter;
  41033. if (typeof conf.axisFormatter !== 'undefined') {
  41034. mid = [];
  41035. conf.axisFormatter.forEach(function (item) {
  41036. var n = [];
  41037. n[0] = item[0];
  41038. n[1] = item[1];
  41039. mid.push(n);
  41040. });
  41041. }
  41042. formatter = pre.concat(mid).concat(post);
  41043. var xAxis = d3.svg.axis().scale(timeScale).orient('bottom').tickSize(-h + theTopPad + conf.gridLineStartPadding, 0, 0).tickFormat(d3.time.format.multi(formatter));
  41044. if (daysInChart > 7 && daysInChart < 230) {
  41045. xAxis = xAxis.ticks(d3.time.monday.range);
  41046. }
  41047. 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');
  41048. }
  41049. function vertLabels(theGap, theTopPad) {
  41050. var numOccurances = [];
  41051. var prevGap = 0;
  41052. for (var i = 0; i < categories.length; i++) {
  41053. numOccurances[i] = [categories[i], getCount(categories[i], catsUnfiltered)];
  41054. }
  41055. svg.append('g') //without doing this, impossible to put grid lines behind text
  41056. .selectAll('text').data(numOccurances).enter().append('text').text(function (d) {
  41057. return d[0];
  41058. }).attr('x', 10).attr('y', function (d, i) {
  41059. if (i > 0) {
  41060. for (var j = 0; j < i; j++) {
  41061. prevGap += numOccurances[i - 1][1];
  41062. // log.debug(prevGap);
  41063. return d[1] * theGap / 2 + prevGap * theGap + theTopPad;
  41064. }
  41065. } else {
  41066. return d[1] * theGap / 2 + theTopPad;
  41067. }
  41068. }).attr('class', function (d) {
  41069. for (var i = 0; i < categories.length; i++) {
  41070. if (d[0] === categories[i]) {
  41071. return 'sectionTitle sectionTitle' + i % conf.numberSectionStyles;
  41072. }
  41073. }
  41074. return 'sectionTitle';
  41075. });
  41076. }
  41077. function drawToday(theSidePad, theTopPad, w, h) {
  41078. var todayG = svg.append('g').attr('class', 'today');
  41079. var today = new Date();
  41080. 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');
  41081. }
  41082. //from this stackexchange question: http://stackoverflow.com/questions/1890203/unique-for-arrays-in-javascript
  41083. function checkUnique(arr) {
  41084. var hash = {},
  41085. result = [];
  41086. for (var i = 0, l = arr.length; i < l; ++i) {
  41087. if (!hash.hasOwnProperty(arr[i])) {
  41088. //it works with objects! in FF, at least
  41089. hash[arr[i]] = true;
  41090. result.push(arr[i]);
  41091. }
  41092. }
  41093. return result;
  41094. }
  41095. //from this stackexchange question: http://stackoverflow.com/questions/14227981/count-how-many-strings-in-an-array-have-duplicates-in-the-same-array
  41096. function getCounts(arr) {
  41097. var i = arr.length,
  41098. // var to loop over
  41099. obj = {}; // obj to store results
  41100. while (i) {
  41101. obj[arr[--i]] = (obj[arr[i]] || 0) + 1; // count occurrences
  41102. }
  41103. return obj;
  41104. }
  41105. // get specific from everything
  41106. function getCount(word, arr) {
  41107. return getCounts(arr)[word] || 0;
  41108. }
  41109. };
  41110. },{"../../d3":108,"./ganttDb":120,"./parser/gantt":122,"moment":104}],122:[function(require,module,exports){
  41111. (function (process){
  41112. /* parser generated by jison 0.4.17 */
  41113. /*
  41114. Returns a Parser object of the following structure:
  41115. Parser: {
  41116. yy: {}
  41117. }
  41118. Parser.prototype: {
  41119. yy: {},
  41120. trace: function(),
  41121. symbols_: {associative list: name ==> number},
  41122. terminals_: {associative list: number ==> name},
  41123. productions_: [...],
  41124. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  41125. table: [...],
  41126. defaultActions: {...},
  41127. parseError: function(str, hash),
  41128. parse: function(input),
  41129. lexer: {
  41130. EOF: 1,
  41131. parseError: function(str, hash),
  41132. setInput: function(input),
  41133. input: function(),
  41134. unput: function(str),
  41135. more: function(),
  41136. less: function(n),
  41137. pastInput: function(),
  41138. upcomingInput: function(),
  41139. showPosition: function(),
  41140. test_match: function(regex_match_array, rule_index),
  41141. next: function(),
  41142. lex: function(),
  41143. begin: function(condition),
  41144. popState: function(),
  41145. _currentRules: function(),
  41146. topState: function(),
  41147. pushState: function(condition),
  41148. options: {
  41149. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  41150. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  41151. 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)
  41152. },
  41153. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  41154. rules: [...],
  41155. conditions: {associative list: name ==> set},
  41156. }
  41157. }
  41158. token location info (@$, _$, etc.): {
  41159. first_line: n,
  41160. last_line: n,
  41161. first_column: n,
  41162. last_column: n,
  41163. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  41164. }
  41165. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  41166. text: (matched text)
  41167. token: (the produced terminal token, if any)
  41168. line: (yylineno)
  41169. }
  41170. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  41171. loc: (yylloc)
  41172. expected: (string describing the set of expected tokens)
  41173. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  41174. }
  41175. */
  41176. "use strict";
  41177. var parser = (function () {
  41178. var o = function o(k, v, _o, l) {
  41179. for (_o = _o || {}, l = k.length; l--; _o[k[l]] = v);return _o;
  41180. },
  41181. $V0 = [6, 8, 10, 11, 12, 13, 14],
  41182. $V1 = [1, 9],
  41183. $V2 = [1, 10],
  41184. $V3 = [1, 11],
  41185. $V4 = [1, 12];
  41186. var parser = { trace: function trace() {},
  41187. yy: {},
  41188. 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 },
  41189. terminals_: { 2: "error", 4: "gantt", 6: "EOF", 8: "SPACE", 10: "NL", 11: "dateFormat", 12: "title", 13: "section", 14: "taskTxt", 15: "taskData" },
  41190. productions_: [0, [3, 3], [5, 0], [5, 2], [7, 2], [7, 1], [7, 1], [7, 1], [9, 1], [9, 1], [9, 1], [9, 2]],
  41191. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, /* action[1] */$$, /* vstack */_$ /* lstack */) {
  41192. /* this == yyval */
  41193. var $0 = $$.length - 1;
  41194. switch (yystate) {
  41195. case 1:
  41196. return $$[$0 - 1];
  41197. break;
  41198. case 2:
  41199. this.$ = [];
  41200. break;
  41201. case 3:
  41202. $$[$0 - 1].push($$[$0]);this.$ = $$[$0 - 1];
  41203. break;
  41204. case 4:case 5:
  41205. this.$ = $$[$0];
  41206. break;
  41207. case 6:case 7:
  41208. this.$ = [];
  41209. break;
  41210. case 8:
  41211. yy.setDateFormat($$[$0].substr(11));this.$ = $$[$0].substr(11);
  41212. break;
  41213. case 9:
  41214. yy.setTitle($$[$0].substr(6));this.$ = $$[$0].substr(6);
  41215. break;
  41216. case 10:
  41217. yy.addSection($$[$0].substr(8));this.$ = $$[$0].substr(8);
  41218. break;
  41219. case 11:
  41220. yy.addTask($$[$0 - 1], $$[$0]);this.$ = 'task';
  41221. break;
  41222. }
  41223. },
  41224. 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])],
  41225. defaultActions: {},
  41226. parseError: function parseError(str, hash) {
  41227. if (hash.recoverable) {
  41228. this.trace(str);
  41229. } else {
  41230. var _parseError = function _parseError(msg, hash) {
  41231. this.message = msg;
  41232. this.hash = hash;
  41233. };
  41234. _parseError.prototype = Error;
  41235. throw new _parseError(str, hash);
  41236. }
  41237. },
  41238. parse: function parse(input) {
  41239. var self = this,
  41240. stack = [0],
  41241. tstack = [],
  41242. vstack = [null],
  41243. lstack = [],
  41244. table = this.table,
  41245. yytext = '',
  41246. yylineno = 0,
  41247. yyleng = 0,
  41248. recovering = 0,
  41249. TERROR = 2,
  41250. EOF = 1;
  41251. var args = lstack.slice.call(arguments, 1);
  41252. var lexer = Object.create(this.lexer);
  41253. var sharedState = { yy: {} };
  41254. for (var k in this.yy) {
  41255. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  41256. sharedState.yy[k] = this.yy[k];
  41257. }
  41258. }
  41259. lexer.setInput(input, sharedState.yy);
  41260. sharedState.yy.lexer = lexer;
  41261. sharedState.yy.parser = this;
  41262. if (typeof lexer.yylloc == 'undefined') {
  41263. lexer.yylloc = {};
  41264. }
  41265. var yyloc = lexer.yylloc;
  41266. lstack.push(yyloc);
  41267. var ranges = lexer.options && lexer.options.ranges;
  41268. if (typeof sharedState.yy.parseError === 'function') {
  41269. this.parseError = sharedState.yy.parseError;
  41270. } else {
  41271. this.parseError = Object.getPrototypeOf(this).parseError;
  41272. }
  41273. function popStack(n) {
  41274. stack.length = stack.length - 2 * n;
  41275. vstack.length = vstack.length - n;
  41276. lstack.length = lstack.length - n;
  41277. }
  41278. _token_stack: var lex = function lex() {
  41279. var token;
  41280. token = lexer.lex() || EOF;
  41281. if (typeof token !== 'number') {
  41282. token = self.symbols_[token] || token;
  41283. }
  41284. return token;
  41285. };
  41286. var symbol,
  41287. preErrorSymbol,
  41288. state,
  41289. action,
  41290. a,
  41291. r,
  41292. yyval = {},
  41293. p,
  41294. len,
  41295. newState,
  41296. expected;
  41297. while (true) {
  41298. state = stack[stack.length - 1];
  41299. if (this.defaultActions[state]) {
  41300. action = this.defaultActions[state];
  41301. } else {
  41302. if (symbol === null || typeof symbol == 'undefined') {
  41303. symbol = lex();
  41304. }
  41305. action = table[state] && table[state][symbol];
  41306. }
  41307. if (typeof action === 'undefined' || !action.length || !action[0]) {
  41308. var errStr = '';
  41309. expected = [];
  41310. for (p in table[state]) {
  41311. if (this.terminals_[p] && p > TERROR) {
  41312. expected.push('\'' + this.terminals_[p] + '\'');
  41313. }
  41314. }
  41315. if (lexer.showPosition) {
  41316. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  41317. } else {
  41318. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  41319. }
  41320. this.parseError(errStr, {
  41321. text: lexer.match,
  41322. token: this.terminals_[symbol] || symbol,
  41323. line: lexer.yylineno,
  41324. loc: yyloc,
  41325. expected: expected
  41326. });
  41327. }
  41328. if (action[0] instanceof Array && action.length > 1) {
  41329. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  41330. }
  41331. switch (action[0]) {
  41332. case 1:
  41333. stack.push(symbol);
  41334. vstack.push(lexer.yytext);
  41335. lstack.push(lexer.yylloc);
  41336. stack.push(action[1]);
  41337. symbol = null;
  41338. if (!preErrorSymbol) {
  41339. yyleng = lexer.yyleng;
  41340. yytext = lexer.yytext;
  41341. yylineno = lexer.yylineno;
  41342. yyloc = lexer.yylloc;
  41343. if (recovering > 0) {
  41344. recovering--;
  41345. }
  41346. } else {
  41347. symbol = preErrorSymbol;
  41348. preErrorSymbol = null;
  41349. }
  41350. break;
  41351. case 2:
  41352. len = this.productions_[action[1]][1];
  41353. yyval.$ = vstack[vstack.length - len];
  41354. yyval._$ = {
  41355. first_line: lstack[lstack.length - (len || 1)].first_line,
  41356. last_line: lstack[lstack.length - 1].last_line,
  41357. first_column: lstack[lstack.length - (len || 1)].first_column,
  41358. last_column: lstack[lstack.length - 1].last_column
  41359. };
  41360. if (ranges) {
  41361. yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
  41362. }
  41363. r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
  41364. if (typeof r !== 'undefined') {
  41365. return r;
  41366. }
  41367. if (len) {
  41368. stack = stack.slice(0, -1 * len * 2);
  41369. vstack = vstack.slice(0, -1 * len);
  41370. lstack = lstack.slice(0, -1 * len);
  41371. }
  41372. stack.push(this.productions_[action[1]][0]);
  41373. vstack.push(yyval.$);
  41374. lstack.push(yyval._$);
  41375. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  41376. stack.push(newState);
  41377. break;
  41378. case 3:
  41379. return true;
  41380. }
  41381. }
  41382. return true;
  41383. } };
  41384. /* generated by jison-lex 0.3.4 */
  41385. var lexer = (function () {
  41386. var lexer = {
  41387. EOF: 1,
  41388. parseError: function parseError(str, hash) {
  41389. if (this.yy.parser) {
  41390. this.yy.parser.parseError(str, hash);
  41391. } else {
  41392. throw new Error(str);
  41393. }
  41394. },
  41395. // resets the lexer, sets new input
  41396. setInput: function setInput(input, yy) {
  41397. this.yy = yy || this.yy || {};
  41398. this._input = input;
  41399. this._more = this._backtrack = this.done = false;
  41400. this.yylineno = this.yyleng = 0;
  41401. this.yytext = this.matched = this.match = '';
  41402. this.conditionStack = ['INITIAL'];
  41403. this.yylloc = {
  41404. first_line: 1,
  41405. first_column: 0,
  41406. last_line: 1,
  41407. last_column: 0
  41408. };
  41409. if (this.options.ranges) {
  41410. this.yylloc.range = [0, 0];
  41411. }
  41412. this.offset = 0;
  41413. return this;
  41414. },
  41415. // consumes and returns one char from the input
  41416. input: function input() {
  41417. var ch = this._input[0];
  41418. this.yytext += ch;
  41419. this.yyleng++;
  41420. this.offset++;
  41421. this.match += ch;
  41422. this.matched += ch;
  41423. var lines = ch.match(/(?:\r\n?|\n).*/g);
  41424. if (lines) {
  41425. this.yylineno++;
  41426. this.yylloc.last_line++;
  41427. } else {
  41428. this.yylloc.last_column++;
  41429. }
  41430. if (this.options.ranges) {
  41431. this.yylloc.range[1]++;
  41432. }
  41433. this._input = this._input.slice(1);
  41434. return ch;
  41435. },
  41436. // unshifts one char (or a string) into the input
  41437. unput: function unput(ch) {
  41438. var len = ch.length;
  41439. var lines = ch.split(/(?:\r\n?|\n)/g);
  41440. this._input = ch + this._input;
  41441. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  41442. //this.yyleng -= len;
  41443. this.offset -= len;
  41444. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  41445. this.match = this.match.substr(0, this.match.length - 1);
  41446. this.matched = this.matched.substr(0, this.matched.length - 1);
  41447. if (lines.length - 1) {
  41448. this.yylineno -= lines.length - 1;
  41449. }
  41450. var r = this.yylloc.range;
  41451. this.yylloc = {
  41452. first_line: this.yylloc.first_line,
  41453. last_line: this.yylineno + 1,
  41454. first_column: this.yylloc.first_column,
  41455. 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
  41456. };
  41457. if (this.options.ranges) {
  41458. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  41459. }
  41460. this.yyleng = this.yytext.length;
  41461. return this;
  41462. },
  41463. // When called from action, caches matched text and appends it on next action
  41464. more: function more() {
  41465. this._more = true;
  41466. return this;
  41467. },
  41468. // 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.
  41469. reject: function reject() {
  41470. if (this.options.backtrack_lexer) {
  41471. this._backtrack = true;
  41472. } else {
  41473. 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(), {
  41474. text: "",
  41475. token: null,
  41476. line: this.yylineno
  41477. });
  41478. }
  41479. return this;
  41480. },
  41481. // retain first n characters of the match
  41482. less: function less(n) {
  41483. this.unput(this.match.slice(n));
  41484. },
  41485. // displays already matched input, i.e. for error messages
  41486. pastInput: function pastInput() {
  41487. var past = this.matched.substr(0, this.matched.length - this.match.length);
  41488. return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
  41489. },
  41490. // displays upcoming input, i.e. for error messages
  41491. upcomingInput: function upcomingInput() {
  41492. var next = this.match;
  41493. if (next.length < 20) {
  41494. next += this._input.substr(0, 20 - next.length);
  41495. }
  41496. return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  41497. },
  41498. // displays the character position where the lexing error occurred, i.e. for error messages
  41499. showPosition: function showPosition() {
  41500. var pre = this.pastInput();
  41501. var c = new Array(pre.length + 1).join("-");
  41502. return pre + this.upcomingInput() + "\n" + c + "^";
  41503. },
  41504. // test the lexed token: return FALSE when not a match, otherwise return token
  41505. test_match: function test_match(match, indexed_rule) {
  41506. var token, lines, backup;
  41507. if (this.options.backtrack_lexer) {
  41508. // save context
  41509. backup = {
  41510. yylineno: this.yylineno,
  41511. yylloc: {
  41512. first_line: this.yylloc.first_line,
  41513. last_line: this.last_line,
  41514. first_column: this.yylloc.first_column,
  41515. last_column: this.yylloc.last_column
  41516. },
  41517. yytext: this.yytext,
  41518. match: this.match,
  41519. matches: this.matches,
  41520. matched: this.matched,
  41521. yyleng: this.yyleng,
  41522. offset: this.offset,
  41523. _more: this._more,
  41524. _input: this._input,
  41525. yy: this.yy,
  41526. conditionStack: this.conditionStack.slice(0),
  41527. done: this.done
  41528. };
  41529. if (this.options.ranges) {
  41530. backup.yylloc.range = this.yylloc.range.slice(0);
  41531. }
  41532. }
  41533. lines = match[0].match(/(?:\r\n?|\n).*/g);
  41534. if (lines) {
  41535. this.yylineno += lines.length;
  41536. }
  41537. this.yylloc = {
  41538. first_line: this.yylloc.last_line,
  41539. last_line: this.yylineno + 1,
  41540. first_column: this.yylloc.last_column,
  41541. last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
  41542. };
  41543. this.yytext += match[0];
  41544. this.match += match[0];
  41545. this.matches = match;
  41546. this.yyleng = this.yytext.length;
  41547. if (this.options.ranges) {
  41548. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  41549. }
  41550. this._more = false;
  41551. this._backtrack = false;
  41552. this._input = this._input.slice(match[0].length);
  41553. this.matched += match[0];
  41554. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  41555. if (this.done && this._input) {
  41556. this.done = false;
  41557. }
  41558. if (token) {
  41559. return token;
  41560. } else if (this._backtrack) {
  41561. // recover context
  41562. for (var k in backup) {
  41563. this[k] = backup[k];
  41564. }
  41565. return false; // rule action called reject() implying the next rule should be tested instead.
  41566. }
  41567. return false;
  41568. },
  41569. // return next match in input
  41570. next: function next() {
  41571. if (this.done) {
  41572. return this.EOF;
  41573. }
  41574. if (!this._input) {
  41575. this.done = true;
  41576. }
  41577. var token, match, tempMatch, index;
  41578. if (!this._more) {
  41579. this.yytext = '';
  41580. this.match = '';
  41581. }
  41582. var rules = this._currentRules();
  41583. for (var i = 0; i < rules.length; i++) {
  41584. tempMatch = this._input.match(this.rules[rules[i]]);
  41585. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  41586. match = tempMatch;
  41587. index = i;
  41588. if (this.options.backtrack_lexer) {
  41589. token = this.test_match(tempMatch, rules[i]);
  41590. if (token !== false) {
  41591. return token;
  41592. } else if (this._backtrack) {
  41593. match = false;
  41594. continue; // rule action called reject() implying a rule MISmatch.
  41595. } else {
  41596. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  41597. return false;
  41598. }
  41599. } else if (!this.options.flex) {
  41600. break;
  41601. }
  41602. }
  41603. }
  41604. if (match) {
  41605. token = this.test_match(match, rules[index]);
  41606. if (token !== false) {
  41607. return token;
  41608. }
  41609. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  41610. return false;
  41611. }
  41612. if (this._input === "") {
  41613. return this.EOF;
  41614. } else {
  41615. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  41616. text: "",
  41617. token: null,
  41618. line: this.yylineno
  41619. });
  41620. }
  41621. },
  41622. // return next match that has a token
  41623. lex: function lex() {
  41624. var r = this.next();
  41625. if (r) {
  41626. return r;
  41627. } else {
  41628. return this.lex();
  41629. }
  41630. },
  41631. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  41632. begin: function begin(condition) {
  41633. this.conditionStack.push(condition);
  41634. },
  41635. // pop the previously active lexer condition state off the condition stack
  41636. popState: function popState() {
  41637. var n = this.conditionStack.length - 1;
  41638. if (n > 0) {
  41639. return this.conditionStack.pop();
  41640. } else {
  41641. return this.conditionStack[0];
  41642. }
  41643. },
  41644. // produce the lexer rule set which is active for the currently active lexer condition state
  41645. _currentRules: function _currentRules() {
  41646. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  41647. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  41648. } else {
  41649. return this.conditions["INITIAL"].rules;
  41650. }
  41651. },
  41652. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  41653. topState: function topState(n) {
  41654. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  41655. if (n >= 0) {
  41656. return this.conditionStack[n];
  41657. } else {
  41658. return "INITIAL";
  41659. }
  41660. },
  41661. // alias for begin(condition)
  41662. pushState: function pushState(condition) {
  41663. this.begin(condition);
  41664. },
  41665. // return the number of states currently on the stack
  41666. stateStackSize: function stateStackSize() {
  41667. return this.conditionStack.length;
  41668. },
  41669. options: { "case-insensitive": true },
  41670. performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
  41671. // Pre-lexer code can go here
  41672. var YYSTATE = YY_START;
  41673. switch ($avoiding_name_collisions) {
  41674. case 0:
  41675. return 10;
  41676. break;
  41677. case 1:
  41678. /* skip whitespace */
  41679. break;
  41680. case 2:
  41681. /* skip comments */
  41682. break;
  41683. case 3:
  41684. /* skip comments */
  41685. break;
  41686. case 4:
  41687. return 4;
  41688. break;
  41689. case 5:
  41690. return 11;
  41691. break;
  41692. case 6:
  41693. return 'date';
  41694. break;
  41695. case 7:
  41696. return 12;
  41697. break;
  41698. case 8:
  41699. return 13;
  41700. break;
  41701. case 9:
  41702. return 14;
  41703. break;
  41704. case 10:
  41705. return 15;
  41706. break;
  41707. case 11:
  41708. return ':';
  41709. break;
  41710. case 12:
  41711. return 6;
  41712. break;
  41713. case 13:
  41714. return 'INVALID';
  41715. break;
  41716. }
  41717. },
  41718. 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],
  41719. conditions: { "INITIAL": { "rules": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], "inclusive": true } }
  41720. };
  41721. return lexer;
  41722. })();
  41723. parser.lexer = lexer;
  41724. function Parser() {
  41725. this.yy = {};
  41726. }
  41727. Parser.prototype = parser;parser.Parser = Parser;
  41728. return new Parser();
  41729. })();
  41730. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  41731. exports.parser = parser;
  41732. exports.Parser = parser.Parser;
  41733. exports.parse = function () {
  41734. return parser.parse.apply(parser, arguments);
  41735. };
  41736. exports.main = function commonjsMain(args) {
  41737. if (!args[1]) {
  41738. console.log('Usage: ' + args[0] + ' FILE');
  41739. process.exit(1);
  41740. }
  41741. var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
  41742. return exports.parser.parse(source);
  41743. };
  41744. if (typeof module !== 'undefined' && require.main === module) {
  41745. exports.main(process.argv.slice(1));
  41746. }
  41747. }
  41748. }).call(this,require('_process'))
  41749. },{"_process":106,"fs":1,"path":105}],123:[function(require,module,exports){
  41750. 'use strict';
  41751. var Logger = require('../../logger');
  41752. var _ = require('lodash');
  41753. //var log = new Logger.Log();
  41754. var log = new Logger.Log(1);
  41755. var commits = {};
  41756. var head = null;
  41757. var branches = { 'master': head };
  41758. var curBranch = 'master';
  41759. var direction = 'LR';
  41760. var seq = 0;
  41761. function getRandomInt(min, max) {
  41762. return Math.floor(Math.random() * (max - min)) + min;
  41763. }
  41764. function getId() {
  41765. var pool = '0123456789abcdef';
  41766. var id = '';
  41767. for (var i = 0; i < 7; i++) {
  41768. id += pool[getRandomInt(0, 16)];
  41769. }
  41770. return id;
  41771. }
  41772. function isfastforwardable(_x, _x2) {
  41773. var _left;
  41774. var _again = true;
  41775. _function: while (_again) {
  41776. var currentCommit = _x,
  41777. otherCommit = _x2;
  41778. _again = false;
  41779. log.debug('Entering isfastforwardable:', currentCommit.id, otherCommit.id);
  41780. while (currentCommit.seq <= otherCommit.seq && currentCommit != otherCommit) {
  41781. // only if other branch has more commits
  41782. if (otherCommit.parent == null) break;
  41783. if (Array.isArray(otherCommit.parent)) {
  41784. log.debug('In merge commit:', otherCommit.parent);
  41785. if (_left = isfastforwardable(currentCommit, commits[otherCommit.parent[0]])) {
  41786. return _left;
  41787. }
  41788. _x = currentCommit;
  41789. _x2 = commits[otherCommit.parent[1]];
  41790. _again = true;
  41791. continue _function;
  41792. } else {
  41793. otherCommit = commits[otherCommit.parent];
  41794. }
  41795. }
  41796. log.debug(currentCommit.id, otherCommit.id);
  41797. return currentCommit.id == otherCommit.id;
  41798. }
  41799. }
  41800. function isReachableFrom(currentCommit, otherCommit) {
  41801. var currentSeq = currentCommit.seq;
  41802. var otherSeq = otherCommit.seq;
  41803. if (currentSeq > otherSeq) return isfastforwardable(otherCommit, currentCommit);
  41804. return false;
  41805. }
  41806. exports.setDirection = function (dir) {
  41807. direction = dir;
  41808. };
  41809. var options = {};
  41810. exports.setOptions = function (rawOptString) {
  41811. log.debug('options str', rawOptString);
  41812. rawOptString = rawOptString && rawOptString.trim();
  41813. rawOptString = rawOptString || '{}';
  41814. try {
  41815. options = JSON.parse(rawOptString);
  41816. } catch (e) {
  41817. log.error('error while parsing gitGraph options', e.message);
  41818. }
  41819. };
  41820. exports.getOptions = function () {
  41821. return options;
  41822. };
  41823. exports.commit = function (msg) {
  41824. var commit = { id: getId(),
  41825. message: msg,
  41826. seq: seq++,
  41827. parent: head == null ? null : head.id };
  41828. head = commit;
  41829. commits[commit.id] = commit;
  41830. branches[curBranch] = commit.id;
  41831. log.debug('in pushCommit ' + commit.id);
  41832. };
  41833. exports.branch = function (name) {
  41834. branches[name] = head != null ? head.id : null;
  41835. log.debug('in createBranch');
  41836. };
  41837. exports.merge = function (otherBranch) {
  41838. var currentCommit = commits[branches[curBranch]];
  41839. var otherCommit = commits[branches[otherBranch]];
  41840. if (isReachableFrom(currentCommit, otherCommit)) {
  41841. log.debug('Already merged');
  41842. return;
  41843. }
  41844. if (isfastforwardable(currentCommit, otherCommit)) {
  41845. branches[curBranch] = branches[otherBranch];
  41846. head = commits[branches[curBranch]];
  41847. } else {
  41848. // create merge commit
  41849. var commit = {
  41850. id: getId(),
  41851. message: 'merged branch ' + otherBranch + ' into ' + curBranch,
  41852. seq: seq++,
  41853. parent: [head == null ? null : head.id, branches[otherBranch]]
  41854. };
  41855. head = commit;
  41856. commits[commit.id] = commit;
  41857. branches[curBranch] = commit.id;
  41858. }
  41859. log.debug(branches);
  41860. log.debug('in mergeBranch');
  41861. };
  41862. exports.checkout = function (branch) {
  41863. log.debug('in checkout');
  41864. curBranch = branch;
  41865. var id = branches[curBranch];
  41866. head = commits[id];
  41867. };
  41868. exports.reset = function (commitRef) {
  41869. log.debug('in reset', commitRef);
  41870. var ref = commitRef.split(':')[0];
  41871. var parentCount = parseInt(commitRef.split(':')[1]);
  41872. var commit = ref == 'HEAD' ? head : commits[branches[ref]];
  41873. log.debug(commit, parentCount);
  41874. while (parentCount > 0) {
  41875. commit = commits[commit.parent];
  41876. parentCount--;
  41877. if (!commit) {
  41878. var err = 'Critical error - unique parent commit not found during reset';
  41879. log.error(err);
  41880. throw err;
  41881. }
  41882. }
  41883. head = commit;
  41884. branches[curBranch] = commit.id;
  41885. };
  41886. function upsert(arr, key, newval) {
  41887. var match = _.find(arr, key);
  41888. if (match) {
  41889. var index = _.indexOf(arr, _.find(arr, key));
  41890. arr.splice(index, 1, newval);
  41891. } else {
  41892. arr.push(newval);
  41893. }
  41894. //console.log(arr);
  41895. }
  41896. function prettyPrintCommitHistory(commitArr) {
  41897. var commit = _.maxBy(commitArr, 'seq');
  41898. var line = '';
  41899. _.each(commitArr, function (c) {
  41900. if (c == commit) {
  41901. line += '\t*';
  41902. } else {
  41903. line += '\t|';
  41904. }
  41905. });
  41906. var label = [line, commit.id, commit.seq];
  41907. _.each(branches, function (v, k) {
  41908. if (v == commit.id) label.push(k);
  41909. });
  41910. log.debug(label.join(' '));
  41911. if (Array.isArray(commit.parent)) {
  41912. //console.log("here", commit.parent);
  41913. var newCommit = commits[commit.parent[0]];
  41914. upsert(commitArr, commit, newCommit);
  41915. commitArr.push(commits[commit.parent[1]]);
  41916. //console.log("shoudl have 2", commitArr);
  41917. } else if (commit.parent == null) {
  41918. return;
  41919. } else {
  41920. var nextCommit = commits[commit.parent];
  41921. upsert(commitArr, commit, nextCommit);
  41922. }
  41923. commitArr = _.uniqBy(commitArr, 'id');
  41924. prettyPrintCommitHistory(commitArr);
  41925. }
  41926. exports.prettyPrint = function () {
  41927. log.debug(commits);
  41928. var node = exports.getCommitsArray()[0];
  41929. prettyPrintCommitHistory([node]);
  41930. };
  41931. exports.clear = function () {
  41932. commits = {};
  41933. head = null;
  41934. branches = { 'master': head };
  41935. curBranch = 'master';
  41936. seq = 0;
  41937. };
  41938. exports.getBranchesAsObjArray = function () {
  41939. var branchArr = _.map(branches, function (v, k) {
  41940. return { 'name': k, 'commit': commits[v] };
  41941. });
  41942. //return _.orderBy(branchArr, [function(b) { return b.commit.seq}], ['desc']);
  41943. return branchArr;
  41944. };
  41945. exports.getBranches = function () {
  41946. return branches;
  41947. };
  41948. exports.getCommits = function () {
  41949. return commits;
  41950. };
  41951. exports.getCommitsArray = function () {
  41952. var commitArr = Object.keys(commits).map(function (key) {
  41953. return commits[key];
  41954. });
  41955. _.each(commitArr, function (o) {
  41956. log.debug(o.id);
  41957. });
  41958. return _.orderBy(commitArr, ['seq'], ['desc']);
  41959. };
  41960. exports.getCurrentBranch = function () {
  41961. return curBranch;
  41962. };
  41963. exports.getDirection = function () {
  41964. return direction;
  41965. };
  41966. exports.getHead = function () {
  41967. return head;
  41968. };
  41969. },{"../../logger":130,"lodash":103}],124:[function(require,module,exports){
  41970. 'use strict';
  41971. var db = require('./gitGraphAst');
  41972. var _ = require('lodash');
  41973. var gitGraphParser = require('./parser/gitGraph');
  41974. var d3 = require('../../d3');
  41975. var Logger = require('../../logger');
  41976. var log = new Logger.Log();
  41977. var allCommitsDict = {};
  41978. var branchNum;
  41979. var config = {
  41980. nodeSpacing: 75,
  41981. nodeFillColor: 'yellow',
  41982. nodeStrokeWidth: 2,
  41983. nodeStrokeColor: 'grey',
  41984. lineStrokeWidth: 4,
  41985. branchOffset: 50,
  41986. lineColor: 'grey',
  41987. leftMargin: 50,
  41988. branchColors: ['#442f74', '#983351', '#609732', '#AA9A39'],
  41989. nodeRadius: 15,
  41990. nodeLabel: {
  41991. width: 75,
  41992. height: 100,
  41993. x: -25,
  41994. y: 15
  41995. }
  41996. };
  41997. var apiConfig = {};
  41998. exports.setConf = function (c) {
  41999. apiConfig = c;
  42000. };
  42001. function svgCreateDefs(svg) {
  42002. svg.append('defs').append('g').attr('id', 'def-commit').append('circle').attr('r', config.nodeRadius).attr('cx', 0).attr('cy', 0);
  42003. 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('');
  42004. }
  42005. function svgDrawLine(svg, points, colorIdx, interpolate) {
  42006. interpolate = interpolate || 'basis';
  42007. var color = config.branchColors[colorIdx % config.branchColors.length];
  42008. var lineGen = d3.svg.line().x(function (d) {
  42009. return Math.round(d.x);
  42010. }).y(function (d) {
  42011. return Math.round(d.y);
  42012. }).interpolate(interpolate);
  42013. svg.append('svg:path').attr('d', lineGen(points)).style('stroke', color).style('stroke-width', config.lineStrokeWidth).style('fill', 'none');
  42014. }
  42015. // Pass in the element and its pre-transform coords
  42016. function getElementCoords(element, coords) {
  42017. coords = coords || element.node().getBBox();
  42018. var ctm = element.node().getCTM(),
  42019. xn = ctm.e + coords.x * ctm.a,
  42020. yn = ctm.f + coords.y * ctm.d;
  42021. //log.debug(ctm, coords);
  42022. return {
  42023. left: xn,
  42024. top: yn,
  42025. width: coords.width,
  42026. height: coords.height
  42027. };
  42028. }
  42029. function svgDrawLineForCommits(svg, fromId, toId, direction, color) {
  42030. log.debug('svgDrawLineForCommits: ', fromId, toId);
  42031. var fromBbox = getElementCoords(svg.select('#node-' + fromId + ' circle'));
  42032. var toBbox = getElementCoords(svg.select('#node-' + toId + ' circle'));
  42033. //log.debug('svgDrawLineForCommits: ', fromBbox, toBbox);
  42034. switch (direction) {
  42035. case 'LR':
  42036. // (toBbox)
  42037. // +--------
  42038. // + (fromBbox)
  42039. if (fromBbox.left - toBbox.left > config.nodeSpacing) {
  42040. var lineStart = { x: fromBbox.left - config.nodeSpacing, y: toBbox.top + toBbox.height / 2 };
  42041. var lineEnd = { x: toBbox.left + toBbox.width, y: toBbox.top + toBbox.height / 2 };
  42042. svgDrawLine(svg, [lineStart, lineEnd], color, 'linear');
  42043. 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);
  42044. } else {
  42045. svgDrawLine(svg, [{
  42046. 'x': fromBbox.left,
  42047. 'y': fromBbox.top + fromBbox.height / 2
  42048. }, {
  42049. 'x': fromBbox.left - config.nodeSpacing / 2,
  42050. 'y': fromBbox.top + fromBbox.height / 2
  42051. }, {
  42052. 'x': fromBbox.left - config.nodeSpacing / 2,
  42053. 'y': toBbox.top + toBbox.height / 2
  42054. }, {
  42055. 'x': toBbox.left + toBbox.width,
  42056. 'y': toBbox.top + toBbox.height / 2
  42057. }], color);
  42058. }
  42059. break;
  42060. case 'BT':
  42061. // + (fromBbox)
  42062. // |
  42063. // |
  42064. // + (toBbox)
  42065. if (toBbox.top - fromBbox.top > config.nodeSpacing) {
  42066. lineStart = { x: toBbox.left + toBbox.width / 2, y: fromBbox.top + fromBbox.height + config.nodeSpacing };
  42067. lineEnd = { x: toBbox.left + toBbox.width / 2, y: toBbox.top };
  42068. svgDrawLine(svg, [lineStart, lineEnd], color, 'linear');
  42069. 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);
  42070. } else {
  42071. svgDrawLine(svg, [{
  42072. 'x': fromBbox.left + fromBbox.width / 2,
  42073. 'y': fromBbox.top + fromBbox.height
  42074. }, {
  42075. 'x': fromBbox.left + fromBbox.width / 2,
  42076. 'y': fromBbox.top + config.nodeSpacing / 2
  42077. }, {
  42078. 'x': toBbox.left + toBbox.width / 2,
  42079. 'y': toBbox.top - config.nodeSpacing / 2
  42080. }, {
  42081. 'x': toBbox.left + toBbox.width / 2,
  42082. 'y': toBbox.top
  42083. }], color);
  42084. }
  42085. break;
  42086. }
  42087. }
  42088. function cloneNode(svg, selector) {
  42089. return svg.select(selector).node().cloneNode(true);
  42090. }
  42091. function renderCommitHistory(svg, commitid, branches, direction) {
  42092. var commit;
  42093. var numCommits = Object.keys(allCommitsDict).length;
  42094. if (_.isString(commitid)) {
  42095. do {
  42096. commit = allCommitsDict[commitid];
  42097. log.debug('in renderCommitHistory', commit.id, commit.seq);
  42098. if (svg.select('#node-' + commitid).size() > 0) {
  42099. return;
  42100. }
  42101. svg.append(function () {
  42102. return cloneNode(svg, '#def-commit');
  42103. }).attr('class', 'commit').attr('id', function () {
  42104. return 'node-' + commit.id;
  42105. }).attr('transform', function () {
  42106. switch (direction) {
  42107. case 'LR':
  42108. return 'translate(' + (commit.seq * config.nodeSpacing + config.leftMargin) + ', ' + branchNum * config.branchOffset + ')';
  42109. case 'BT':
  42110. return 'translate(' + (branchNum * config.branchOffset + config.leftMargin) + ', ' + (numCommits - commit.seq) * config.nodeSpacing + ')';
  42111. }
  42112. }).attr('fill', config.nodeFillColor).attr('stroke', config.nodeStrokeColor).attr('stroke-width', config.nodeStrokeWidth);
  42113. var branch = _.find(branches, ['commit', commit]);
  42114. if (branch) {
  42115. log.debug('found branch ', branch.name);
  42116. svg.select('#node-' + commit.id + ' p').append('xhtml:span').attr('class', 'branch-label').text(branch.name + ', ');
  42117. }
  42118. svg.select('#node-' + commit.id + ' p').append('xhtml:span').attr('class', 'commit-id').text(commit.id);
  42119. if (commit.message !== '' && direction === 'BT') {
  42120. svg.select('#node-' + commit.id + ' p').append('xhtml:span').attr('class', 'commit-msg').text(', ' + commit.message);
  42121. }
  42122. commitid = commit.parent;
  42123. } while (commitid && allCommitsDict[commitid]);
  42124. }
  42125. if (_.isArray(commitid)) {
  42126. log.debug('found merge commmit', commitid);
  42127. renderCommitHistory(svg, commitid[0], branches, direction);
  42128. branchNum++;
  42129. renderCommitHistory(svg, commitid[1], branches, direction);
  42130. branchNum--;
  42131. }
  42132. }
  42133. function renderLines(svg, commit, direction, branchColor) {
  42134. branchColor = branchColor || 0;
  42135. while (commit.seq > 0 && !commit.lineDrawn) {
  42136. if (_.isString(commit.parent)) {
  42137. svgDrawLineForCommits(svg, commit.id, commit.parent, direction, branchColor);
  42138. commit.lineDrawn = true;
  42139. commit = allCommitsDict[commit.parent];
  42140. } else if (_.isArray(commit.parent)) {
  42141. svgDrawLineForCommits(svg, commit.id, commit.parent[0], direction, branchColor);
  42142. svgDrawLineForCommits(svg, commit.id, commit.parent[1], direction, branchColor + 1);
  42143. renderLines(svg, allCommitsDict[commit.parent[1]], direction, branchColor + 1);
  42144. commit.lineDrawn = true;
  42145. commit = allCommitsDict[commit.parent[0]];
  42146. }
  42147. }
  42148. }
  42149. exports.draw = function (txt, id, ver) {
  42150. try {
  42151. var parser;
  42152. parser = gitGraphParser.parser;
  42153. parser.yy = db;
  42154. log.debug('in gitgraph renderer', txt, id, ver);
  42155. // Parse the graph definition
  42156. parser.parse(txt + '\n');
  42157. config = _.extend(config, apiConfig, db.getOptions());
  42158. log.debug('effective options', config);
  42159. var direction = db.getDirection();
  42160. allCommitsDict = db.getCommits();
  42161. var branches = db.getBranchesAsObjArray();
  42162. if (direction === 'BT') {
  42163. config.nodeLabel.x = branches.length * config.branchOffset;
  42164. config.nodeLabel.width = '100%';
  42165. config.nodeLabel.y = -1 * 2 * config.nodeRadius;
  42166. }
  42167. var svg = d3.select('#' + id);
  42168. svgCreateDefs(svg);
  42169. branchNum = 1;
  42170. _.each(branches, function (v) {
  42171. renderCommitHistory(svg, v.commit.id, branches, direction);
  42172. renderLines(svg, v.commit, direction);
  42173. branchNum++;
  42174. });
  42175. svg.attr('height', function () {
  42176. if (direction === 'BT') return Object.keys(allCommitsDict).length * config.nodeSpacing;
  42177. return (branches.length + 1) * config.branchOffset;
  42178. });
  42179. //svg.attr('width', function() {
  42180. //if (direction === 'LR') return Object.keys(allCommitsDict).length * config.nodeSpacing + config.leftMargin;
  42181. //return (branches.length + 1) * config.branchOffset;
  42182. //});
  42183. } catch (e) {
  42184. log.error('Error while rendering gitgraph');
  42185. log.error(e.message);
  42186. }
  42187. };
  42188. },{"../../d3":108,"../../logger":130,"./gitGraphAst":123,"./parser/gitGraph":125,"lodash":103}],125:[function(require,module,exports){
  42189. (function (process){
  42190. /* parser generated by jison 0.4.17 */
  42191. /*
  42192. Returns a Parser object of the following structure:
  42193. Parser: {
  42194. yy: {}
  42195. }
  42196. Parser.prototype: {
  42197. yy: {},
  42198. trace: function(),
  42199. symbols_: {associative list: name ==> number},
  42200. terminals_: {associative list: number ==> name},
  42201. productions_: [...],
  42202. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  42203. table: [...],
  42204. defaultActions: {...},
  42205. parseError: function(str, hash),
  42206. parse: function(input),
  42207. lexer: {
  42208. EOF: 1,
  42209. parseError: function(str, hash),
  42210. setInput: function(input),
  42211. input: function(),
  42212. unput: function(str),
  42213. more: function(),
  42214. less: function(n),
  42215. pastInput: function(),
  42216. upcomingInput: function(),
  42217. showPosition: function(),
  42218. test_match: function(regex_match_array, rule_index),
  42219. next: function(),
  42220. lex: function(),
  42221. begin: function(condition),
  42222. popState: function(),
  42223. _currentRules: function(),
  42224. topState: function(),
  42225. pushState: function(condition),
  42226. options: {
  42227. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  42228. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  42229. 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)
  42230. },
  42231. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  42232. rules: [...],
  42233. conditions: {associative list: name ==> set},
  42234. }
  42235. }
  42236. token location info (@$, _$, etc.): {
  42237. first_line: n,
  42238. last_line: n,
  42239. first_column: n,
  42240. last_column: n,
  42241. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  42242. }
  42243. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  42244. text: (matched text)
  42245. token: (the produced terminal token, if any)
  42246. line: (yylineno)
  42247. }
  42248. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  42249. loc: (yylloc)
  42250. expected: (string describing the set of expected tokens)
  42251. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  42252. }
  42253. */
  42254. "use strict";
  42255. var parser = (function () {
  42256. var o = function o(k, v, _o, l) {
  42257. for (_o = _o || {}, l = k.length; l--; _o[k[l]] = v);return _o;
  42258. },
  42259. $V0 = [2, 3],
  42260. $V1 = [1, 7],
  42261. $V2 = [7, 12, 15, 17, 19, 20, 21],
  42262. $V3 = [7, 11, 12, 15, 17, 19, 20, 21],
  42263. $V4 = [2, 20],
  42264. $V5 = [1, 32];
  42265. var parser = { trace: function trace() {},
  42266. yy: {},
  42267. 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 },
  42268. 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" },
  42269. 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]],
  42270. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, /* action[1] */$$, /* vstack */_$ /* lstack */) {
  42271. /* this == yyval */
  42272. var $0 = $$.length - 1;
  42273. switch (yystate) {
  42274. case 1:
  42275. return $$[$0 - 1];
  42276. break;
  42277. case 2:
  42278. yy.setDirection($$[$0 - 3]);return $$[$0 - 1];
  42279. break;
  42280. case 4:
  42281. yy.setOptions($$[$0 - 1]);this.$ = $$[$0];
  42282. break;
  42283. case 5:
  42284. $$[$0 - 1] += $$[$0];this.$ = $$[$0 - 1];
  42285. break;
  42286. case 7:
  42287. this.$ = [];
  42288. break;
  42289. case 8:
  42290. $$[$0 - 1].push($$[$0]);this.$ = $$[$0 - 1];
  42291. break;
  42292. case 9:
  42293. this.$ = $$[$0 - 1];
  42294. break;
  42295. case 11:
  42296. yy.commit($$[$0]);
  42297. break;
  42298. case 12:
  42299. yy.branch($$[$0]);
  42300. break;
  42301. case 13:
  42302. yy.checkout($$[$0]);
  42303. break;
  42304. case 14:
  42305. yy.merge($$[$0]);
  42306. break;
  42307. case 15:
  42308. yy.reset($$[$0]);
  42309. break;
  42310. case 16:
  42311. this.$ = "";
  42312. break;
  42313. case 17:
  42314. this.$ = $$[$0];
  42315. break;
  42316. case 18:
  42317. this.$ = $$[$0 - 1] + ":" + $$[$0];
  42318. break;
  42319. case 19:
  42320. this.$ = $$[$0 - 1] + ":" + yy.count;yy.count = 0;
  42321. break;
  42322. case 20:
  42323. yy.count = 0;
  42324. break;
  42325. case 21:
  42326. yy.count += 1;
  42327. break;
  42328. }
  42329. },
  42330. 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] }],
  42331. 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] },
  42332. parseError: function parseError(str, hash) {
  42333. if (hash.recoverable) {
  42334. this.trace(str);
  42335. } else {
  42336. var _parseError = function _parseError(msg, hash) {
  42337. this.message = msg;
  42338. this.hash = hash;
  42339. };
  42340. _parseError.prototype = Error;
  42341. throw new _parseError(str, hash);
  42342. }
  42343. },
  42344. parse: function parse(input) {
  42345. var self = this,
  42346. stack = [0],
  42347. tstack = [],
  42348. vstack = [null],
  42349. lstack = [],
  42350. table = this.table,
  42351. yytext = '',
  42352. yylineno = 0,
  42353. yyleng = 0,
  42354. recovering = 0,
  42355. TERROR = 2,
  42356. EOF = 1;
  42357. var args = lstack.slice.call(arguments, 1);
  42358. var lexer = Object.create(this.lexer);
  42359. var sharedState = { yy: {} };
  42360. for (var k in this.yy) {
  42361. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  42362. sharedState.yy[k] = this.yy[k];
  42363. }
  42364. }
  42365. lexer.setInput(input, sharedState.yy);
  42366. sharedState.yy.lexer = lexer;
  42367. sharedState.yy.parser = this;
  42368. if (typeof lexer.yylloc == 'undefined') {
  42369. lexer.yylloc = {};
  42370. }
  42371. var yyloc = lexer.yylloc;
  42372. lstack.push(yyloc);
  42373. var ranges = lexer.options && lexer.options.ranges;
  42374. if (typeof sharedState.yy.parseError === 'function') {
  42375. this.parseError = sharedState.yy.parseError;
  42376. } else {
  42377. this.parseError = Object.getPrototypeOf(this).parseError;
  42378. }
  42379. function popStack(n) {
  42380. stack.length = stack.length - 2 * n;
  42381. vstack.length = vstack.length - n;
  42382. lstack.length = lstack.length - n;
  42383. }
  42384. _token_stack: var lex = function lex() {
  42385. var token;
  42386. token = lexer.lex() || EOF;
  42387. if (typeof token !== 'number') {
  42388. token = self.symbols_[token] || token;
  42389. }
  42390. return token;
  42391. };
  42392. var symbol,
  42393. preErrorSymbol,
  42394. state,
  42395. action,
  42396. a,
  42397. r,
  42398. yyval = {},
  42399. p,
  42400. len,
  42401. newState,
  42402. expected;
  42403. while (true) {
  42404. state = stack[stack.length - 1];
  42405. if (this.defaultActions[state]) {
  42406. action = this.defaultActions[state];
  42407. } else {
  42408. if (symbol === null || typeof symbol == 'undefined') {
  42409. symbol = lex();
  42410. }
  42411. action = table[state] && table[state][symbol];
  42412. }
  42413. if (typeof action === 'undefined' || !action.length || !action[0]) {
  42414. var errStr = '';
  42415. expected = [];
  42416. for (p in table[state]) {
  42417. if (this.terminals_[p] && p > TERROR) {
  42418. expected.push('\'' + this.terminals_[p] + '\'');
  42419. }
  42420. }
  42421. if (lexer.showPosition) {
  42422. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  42423. } else {
  42424. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  42425. }
  42426. this.parseError(errStr, {
  42427. text: lexer.match,
  42428. token: this.terminals_[symbol] || symbol,
  42429. line: lexer.yylineno,
  42430. loc: yyloc,
  42431. expected: expected
  42432. });
  42433. }
  42434. if (action[0] instanceof Array && action.length > 1) {
  42435. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  42436. }
  42437. switch (action[0]) {
  42438. case 1:
  42439. stack.push(symbol);
  42440. vstack.push(lexer.yytext);
  42441. lstack.push(lexer.yylloc);
  42442. stack.push(action[1]);
  42443. symbol = null;
  42444. if (!preErrorSymbol) {
  42445. yyleng = lexer.yyleng;
  42446. yytext = lexer.yytext;
  42447. yylineno = lexer.yylineno;
  42448. yyloc = lexer.yylloc;
  42449. if (recovering > 0) {
  42450. recovering--;
  42451. }
  42452. } else {
  42453. symbol = preErrorSymbol;
  42454. preErrorSymbol = null;
  42455. }
  42456. break;
  42457. case 2:
  42458. len = this.productions_[action[1]][1];
  42459. yyval.$ = vstack[vstack.length - len];
  42460. yyval._$ = {
  42461. first_line: lstack[lstack.length - (len || 1)].first_line,
  42462. last_line: lstack[lstack.length - 1].last_line,
  42463. first_column: lstack[lstack.length - (len || 1)].first_column,
  42464. last_column: lstack[lstack.length - 1].last_column
  42465. };
  42466. if (ranges) {
  42467. yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
  42468. }
  42469. r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
  42470. if (typeof r !== 'undefined') {
  42471. return r;
  42472. }
  42473. if (len) {
  42474. stack = stack.slice(0, -1 * len * 2);
  42475. vstack = vstack.slice(0, -1 * len);
  42476. lstack = lstack.slice(0, -1 * len);
  42477. }
  42478. stack.push(this.productions_[action[1]][0]);
  42479. vstack.push(yyval.$);
  42480. lstack.push(yyval._$);
  42481. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  42482. stack.push(newState);
  42483. break;
  42484. case 3:
  42485. return true;
  42486. }
  42487. }
  42488. return true;
  42489. } };
  42490. /* generated by jison-lex 0.3.4 */
  42491. var lexer = (function () {
  42492. var lexer = {
  42493. EOF: 1,
  42494. parseError: function parseError(str, hash) {
  42495. if (this.yy.parser) {
  42496. this.yy.parser.parseError(str, hash);
  42497. } else {
  42498. throw new Error(str);
  42499. }
  42500. },
  42501. // resets the lexer, sets new input
  42502. setInput: function setInput(input, yy) {
  42503. this.yy = yy || this.yy || {};
  42504. this._input = input;
  42505. this._more = this._backtrack = this.done = false;
  42506. this.yylineno = this.yyleng = 0;
  42507. this.yytext = this.matched = this.match = '';
  42508. this.conditionStack = ['INITIAL'];
  42509. this.yylloc = {
  42510. first_line: 1,
  42511. first_column: 0,
  42512. last_line: 1,
  42513. last_column: 0
  42514. };
  42515. if (this.options.ranges) {
  42516. this.yylloc.range = [0, 0];
  42517. }
  42518. this.offset = 0;
  42519. return this;
  42520. },
  42521. // consumes and returns one char from the input
  42522. input: function input() {
  42523. var ch = this._input[0];
  42524. this.yytext += ch;
  42525. this.yyleng++;
  42526. this.offset++;
  42527. this.match += ch;
  42528. this.matched += ch;
  42529. var lines = ch.match(/(?:\r\n?|\n).*/g);
  42530. if (lines) {
  42531. this.yylineno++;
  42532. this.yylloc.last_line++;
  42533. } else {
  42534. this.yylloc.last_column++;
  42535. }
  42536. if (this.options.ranges) {
  42537. this.yylloc.range[1]++;
  42538. }
  42539. this._input = this._input.slice(1);
  42540. return ch;
  42541. },
  42542. // unshifts one char (or a string) into the input
  42543. unput: function unput(ch) {
  42544. var len = ch.length;
  42545. var lines = ch.split(/(?:\r\n?|\n)/g);
  42546. this._input = ch + this._input;
  42547. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  42548. //this.yyleng -= len;
  42549. this.offset -= len;
  42550. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  42551. this.match = this.match.substr(0, this.match.length - 1);
  42552. this.matched = this.matched.substr(0, this.matched.length - 1);
  42553. if (lines.length - 1) {
  42554. this.yylineno -= lines.length - 1;
  42555. }
  42556. var r = this.yylloc.range;
  42557. this.yylloc = {
  42558. first_line: this.yylloc.first_line,
  42559. last_line: this.yylineno + 1,
  42560. first_column: this.yylloc.first_column,
  42561. 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
  42562. };
  42563. if (this.options.ranges) {
  42564. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  42565. }
  42566. this.yyleng = this.yytext.length;
  42567. return this;
  42568. },
  42569. // When called from action, caches matched text and appends it on next action
  42570. more: function more() {
  42571. this._more = true;
  42572. return this;
  42573. },
  42574. // 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.
  42575. reject: function reject() {
  42576. if (this.options.backtrack_lexer) {
  42577. this._backtrack = true;
  42578. } else {
  42579. 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(), {
  42580. text: "",
  42581. token: null,
  42582. line: this.yylineno
  42583. });
  42584. }
  42585. return this;
  42586. },
  42587. // retain first n characters of the match
  42588. less: function less(n) {
  42589. this.unput(this.match.slice(n));
  42590. },
  42591. // displays already matched input, i.e. for error messages
  42592. pastInput: function pastInput() {
  42593. var past = this.matched.substr(0, this.matched.length - this.match.length);
  42594. return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
  42595. },
  42596. // displays upcoming input, i.e. for error messages
  42597. upcomingInput: function upcomingInput() {
  42598. var next = this.match;
  42599. if (next.length < 20) {
  42600. next += this._input.substr(0, 20 - next.length);
  42601. }
  42602. return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  42603. },
  42604. // displays the character position where the lexing error occurred, i.e. for error messages
  42605. showPosition: function showPosition() {
  42606. var pre = this.pastInput();
  42607. var c = new Array(pre.length + 1).join("-");
  42608. return pre + this.upcomingInput() + "\n" + c + "^";
  42609. },
  42610. // test the lexed token: return FALSE when not a match, otherwise return token
  42611. test_match: function test_match(match, indexed_rule) {
  42612. var token, lines, backup;
  42613. if (this.options.backtrack_lexer) {
  42614. // save context
  42615. backup = {
  42616. yylineno: this.yylineno,
  42617. yylloc: {
  42618. first_line: this.yylloc.first_line,
  42619. last_line: this.last_line,
  42620. first_column: this.yylloc.first_column,
  42621. last_column: this.yylloc.last_column
  42622. },
  42623. yytext: this.yytext,
  42624. match: this.match,
  42625. matches: this.matches,
  42626. matched: this.matched,
  42627. yyleng: this.yyleng,
  42628. offset: this.offset,
  42629. _more: this._more,
  42630. _input: this._input,
  42631. yy: this.yy,
  42632. conditionStack: this.conditionStack.slice(0),
  42633. done: this.done
  42634. };
  42635. if (this.options.ranges) {
  42636. backup.yylloc.range = this.yylloc.range.slice(0);
  42637. }
  42638. }
  42639. lines = match[0].match(/(?:\r\n?|\n).*/g);
  42640. if (lines) {
  42641. this.yylineno += lines.length;
  42642. }
  42643. this.yylloc = {
  42644. first_line: this.yylloc.last_line,
  42645. last_line: this.yylineno + 1,
  42646. first_column: this.yylloc.last_column,
  42647. last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
  42648. };
  42649. this.yytext += match[0];
  42650. this.match += match[0];
  42651. this.matches = match;
  42652. this.yyleng = this.yytext.length;
  42653. if (this.options.ranges) {
  42654. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  42655. }
  42656. this._more = false;
  42657. this._backtrack = false;
  42658. this._input = this._input.slice(match[0].length);
  42659. this.matched += match[0];
  42660. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  42661. if (this.done && this._input) {
  42662. this.done = false;
  42663. }
  42664. if (token) {
  42665. return token;
  42666. } else if (this._backtrack) {
  42667. // recover context
  42668. for (var k in backup) {
  42669. this[k] = backup[k];
  42670. }
  42671. return false; // rule action called reject() implying the next rule should be tested instead.
  42672. }
  42673. return false;
  42674. },
  42675. // return next match in input
  42676. next: function next() {
  42677. if (this.done) {
  42678. return this.EOF;
  42679. }
  42680. if (!this._input) {
  42681. this.done = true;
  42682. }
  42683. var token, match, tempMatch, index;
  42684. if (!this._more) {
  42685. this.yytext = '';
  42686. this.match = '';
  42687. }
  42688. var rules = this._currentRules();
  42689. for (var i = 0; i < rules.length; i++) {
  42690. tempMatch = this._input.match(this.rules[rules[i]]);
  42691. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  42692. match = tempMatch;
  42693. index = i;
  42694. if (this.options.backtrack_lexer) {
  42695. token = this.test_match(tempMatch, rules[i]);
  42696. if (token !== false) {
  42697. return token;
  42698. } else if (this._backtrack) {
  42699. match = false;
  42700. continue; // rule action called reject() implying a rule MISmatch.
  42701. } else {
  42702. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  42703. return false;
  42704. }
  42705. } else if (!this.options.flex) {
  42706. break;
  42707. }
  42708. }
  42709. }
  42710. if (match) {
  42711. token = this.test_match(match, rules[index]);
  42712. if (token !== false) {
  42713. return token;
  42714. }
  42715. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  42716. return false;
  42717. }
  42718. if (this._input === "") {
  42719. return this.EOF;
  42720. } else {
  42721. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  42722. text: "",
  42723. token: null,
  42724. line: this.yylineno
  42725. });
  42726. }
  42727. },
  42728. // return next match that has a token
  42729. lex: function lex() {
  42730. var r = this.next();
  42731. if (r) {
  42732. return r;
  42733. } else {
  42734. return this.lex();
  42735. }
  42736. },
  42737. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  42738. begin: function begin(condition) {
  42739. this.conditionStack.push(condition);
  42740. },
  42741. // pop the previously active lexer condition state off the condition stack
  42742. popState: function popState() {
  42743. var n = this.conditionStack.length - 1;
  42744. if (n > 0) {
  42745. return this.conditionStack.pop();
  42746. } else {
  42747. return this.conditionStack[0];
  42748. }
  42749. },
  42750. // produce the lexer rule set which is active for the currently active lexer condition state
  42751. _currentRules: function _currentRules() {
  42752. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  42753. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  42754. } else {
  42755. return this.conditions["INITIAL"].rules;
  42756. }
  42757. },
  42758. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  42759. topState: function topState(n) {
  42760. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  42761. if (n >= 0) {
  42762. return this.conditionStack[n];
  42763. } else {
  42764. return "INITIAL";
  42765. }
  42766. },
  42767. // alias for begin(condition)
  42768. pushState: function pushState(condition) {
  42769. this.begin(condition);
  42770. },
  42771. // return the number of states currently on the stack
  42772. stateStackSize: function stateStackSize() {
  42773. return this.conditionStack.length;
  42774. },
  42775. options: { "case-insensitive": true },
  42776. performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
  42777. var YYSTATE = YY_START;
  42778. switch ($avoiding_name_collisions) {
  42779. case 0:
  42780. return 12;
  42781. break;
  42782. case 1:
  42783. /* skip all whitespace */
  42784. break;
  42785. case 2:
  42786. /* skip comments */
  42787. break;
  42788. case 3:
  42789. /* skip comments */
  42790. break;
  42791. case 4:
  42792. return 4;
  42793. break;
  42794. case 5:
  42795. return 15;
  42796. break;
  42797. case 6:
  42798. return 17;
  42799. break;
  42800. case 7:
  42801. return 20;
  42802. break;
  42803. case 8:
  42804. return 21;
  42805. break;
  42806. case 9:
  42807. return 19;
  42808. break;
  42809. case 10:
  42810. return 8;
  42811. break;
  42812. case 11:
  42813. return 8;
  42814. break;
  42815. case 12:
  42816. return 5;
  42817. break;
  42818. case 13:
  42819. return 26;
  42820. break;
  42821. case 14:
  42822. this.begin("options");
  42823. break;
  42824. case 15:
  42825. this.popState();
  42826. break;
  42827. case 16:
  42828. return 11;
  42829. break;
  42830. case 17:
  42831. this.begin("string");
  42832. break;
  42833. case 18:
  42834. this.popState();
  42835. break;
  42836. case 19:
  42837. return 23;
  42838. break;
  42839. case 20:
  42840. return 18;
  42841. break;
  42842. case 21:
  42843. return 7;
  42844. break;
  42845. }
  42846. },
  42847. 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],
  42848. 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 } }
  42849. };
  42850. return lexer;
  42851. })();
  42852. parser.lexer = lexer;
  42853. function Parser() {
  42854. this.yy = {};
  42855. }
  42856. Parser.prototype = parser;parser.Parser = Parser;
  42857. return new Parser();
  42858. })();
  42859. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  42860. exports.parser = parser;
  42861. exports.Parser = parser.Parser;
  42862. exports.parse = function () {
  42863. return parser.parse.apply(parser, arguments);
  42864. };
  42865. exports.main = function commonjsMain(args) {
  42866. if (!args[1]) {
  42867. console.log('Usage: ' + args[0] + ' FILE');
  42868. process.exit(1);
  42869. }
  42870. var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
  42871. return exports.parser.parse(source);
  42872. };
  42873. if (typeof module !== 'undefined' && require.main === module) {
  42874. exports.main(process.argv.slice(1));
  42875. }
  42876. }
  42877. }).call(this,require('_process'))
  42878. },{"_process":106,"fs":1,"path":105}],126:[function(require,module,exports){
  42879. (function (process){
  42880. /* parser generated by jison 0.4.17 */
  42881. /*
  42882. Returns a Parser object of the following structure:
  42883. Parser: {
  42884. yy: {}
  42885. }
  42886. Parser.prototype: {
  42887. yy: {},
  42888. trace: function(),
  42889. symbols_: {associative list: name ==> number},
  42890. terminals_: {associative list: number ==> name},
  42891. productions_: [...],
  42892. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  42893. table: [...],
  42894. defaultActions: {...},
  42895. parseError: function(str, hash),
  42896. parse: function(input),
  42897. lexer: {
  42898. EOF: 1,
  42899. parseError: function(str, hash),
  42900. setInput: function(input),
  42901. input: function(),
  42902. unput: function(str),
  42903. more: function(),
  42904. less: function(n),
  42905. pastInput: function(),
  42906. upcomingInput: function(),
  42907. showPosition: function(),
  42908. test_match: function(regex_match_array, rule_index),
  42909. next: function(),
  42910. lex: function(),
  42911. begin: function(condition),
  42912. popState: function(),
  42913. _currentRules: function(),
  42914. topState: function(),
  42915. pushState: function(condition),
  42916. options: {
  42917. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  42918. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  42919. 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)
  42920. },
  42921. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  42922. rules: [...],
  42923. conditions: {associative list: name ==> set},
  42924. }
  42925. }
  42926. token location info (@$, _$, etc.): {
  42927. first_line: n,
  42928. last_line: n,
  42929. first_column: n,
  42930. last_column: n,
  42931. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  42932. }
  42933. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  42934. text: (matched text)
  42935. token: (the produced terminal token, if any)
  42936. line: (yylineno)
  42937. }
  42938. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  42939. loc: (yylloc)
  42940. expected: (string describing the set of expected tokens)
  42941. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  42942. }
  42943. */
  42944. "use strict";
  42945. var parser = (function () {
  42946. var o = function o(k, v, _o, l) {
  42947. for (_o = _o || {}, l = k.length; l--; _o[k[l]] = v);return _o;
  42948. },
  42949. $V0 = [1, 2],
  42950. $V1 = [1, 3],
  42951. $V2 = [1, 4],
  42952. $V3 = [2, 4],
  42953. $V4 = [1, 9],
  42954. $V5 = [1, 11],
  42955. $V6 = [1, 12],
  42956. $V7 = [1, 14],
  42957. $V8 = [1, 15],
  42958. $V9 = [1, 17],
  42959. $Va = [1, 18],
  42960. $Vb = [1, 19],
  42961. $Vc = [1, 20],
  42962. $Vd = [1, 22],
  42963. $Ve = [1, 23],
  42964. $Vf = [1, 4, 5, 10, 15, 16, 18, 20, 21, 22, 23, 24, 25, 36],
  42965. $Vg = [1, 31],
  42966. $Vh = [4, 5, 10, 15, 16, 18, 20, 21, 22, 23, 25, 36],
  42967. $Vi = [34, 35, 36];
  42968. var parser = { trace: function trace() {},
  42969. yy: {},
  42970. 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 },
  42971. 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" },
  42972. 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]],
  42973. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, /* action[1] */$$, /* vstack */_$ /* lstack */) {
  42974. /* this == yyval */
  42975. var $0 = $$.length - 1;
  42976. switch (yystate) {
  42977. case 3:
  42978. yy.apply($$[$0]);return $$[$0];
  42979. break;
  42980. case 4:
  42981. this.$ = [];
  42982. break;
  42983. case 5:
  42984. $$[$0 - 1].push($$[$0]);this.$ = $$[$0 - 1];
  42985. break;
  42986. case 6:case 7:
  42987. this.$ = $$[$0];
  42988. break;
  42989. case 8:
  42990. this.$ = [];
  42991. break;
  42992. case 9:
  42993. $$[$0 - 3].description = $$[$0 - 1];this.$ = $$[$0 - 3];
  42994. break;
  42995. case 10:
  42996. this.$ = $$[$0 - 1];
  42997. break;
  42998. case 12:
  42999. this.$ = { type: 'activeStart', signalType: yy.LINETYPE.ACTIVE_START, actor: $$[$0 - 1] };
  43000. break;
  43001. case 13:
  43002. this.$ = { type: 'activeEnd', signalType: yy.LINETYPE.ACTIVE_END, actor: $$[$0 - 1] };
  43003. break;
  43004. case 15:
  43005. this.$ = [{ type: 'setTitle', text: $$[$0 - 1] }];
  43006. break;
  43007. case 16:
  43008. $$[$0 - 1].unshift({ type: 'loopStart', loopText: $$[$0 - 2], signalType: yy.LINETYPE.LOOP_START });
  43009. $$[$0 - 1].push({ type: 'loopEnd', loopText: $$[$0 - 2], signalType: yy.LINETYPE.LOOP_END });
  43010. this.$ = $$[$0 - 1];
  43011. break;
  43012. case 17:
  43013. $$[$0 - 1].unshift({ type: 'optStart', optText: $$[$0 - 2], signalType: yy.LINETYPE.OPT_START });
  43014. $$[$0 - 1].push({ type: 'optEnd', optText: $$[$0 - 2], signalType: yy.LINETYPE.OPT_END });
  43015. this.$ = $$[$0 - 1];
  43016. break;
  43017. case 18:
  43018. // Alt start
  43019. $$[$0 - 4].unshift({ type: 'altStart', altText: $$[$0 - 5], signalType: yy.LINETYPE.ALT_START });
  43020. // Content in alt is already in $$[$0-4]
  43021. // Else
  43022. $$[$0 - 4].push({ type: 'else', altText: $$[$0 - 2], signalType: yy.LINETYPE.ALT_ELSE });
  43023. // Content in other alt
  43024. $$[$0 - 4] = $$[$0 - 4].concat($$[$0 - 1]);
  43025. // End
  43026. $$[$0 - 4].push({ type: 'altEnd', signalType: yy.LINETYPE.ALT_END });
  43027. this.$ = $$[$0 - 4];
  43028. break;
  43029. case 19:
  43030. this.$ = [$$[$0 - 1], { type: 'addNote', placement: $$[$0 - 2], actor: $$[$0 - 1].actor, text: $$[$0] }];
  43031. break;
  43032. case 20:
  43033. // Coerce actor_pair into a [to, from, ...] array
  43034. $$[$0 - 2] = [].concat($$[$0 - 1], $$[$0 - 1]).slice(0, 2);
  43035. $$[$0 - 2][0] = $$[$0 - 2][0].actor;
  43036. $$[$0 - 2][1] = $$[$0 - 2][1].actor;
  43037. this.$ = [$$[$0 - 1], { type: 'addNote', placement: yy.PLACEMENT.OVER, actor: $$[$0 - 2].slice(0, 2), text: $$[$0] }];
  43038. break;
  43039. case 23:
  43040. this.$ = [$$[$0 - 2], $$[$0]];
  43041. break;
  43042. case 24:
  43043. this.$ = $$[$0];
  43044. break;
  43045. case 25:
  43046. this.$ = yy.PLACEMENT.LEFTOF;
  43047. break;
  43048. case 26:
  43049. this.$ = yy.PLACEMENT.RIGHTOF;
  43050. break;
  43051. case 27:
  43052. 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] }];
  43053. break;
  43054. case 28:
  43055. 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] }];
  43056. break;
  43057. case 29:
  43058. this.$ = [$$[$0 - 3], $$[$0 - 1], { type: 'addMessage', from: $$[$0 - 3].actor, to: $$[$0 - 1].actor, signalType: $$[$0 - 2], msg: $$[$0] }];
  43059. break;
  43060. case 30:
  43061. this.$ = { type: 'addActor', actor: $$[$0] };
  43062. break;
  43063. case 31:
  43064. this.$ = yy.LINETYPE.SOLID_OPEN;
  43065. break;
  43066. case 32:
  43067. this.$ = yy.LINETYPE.DOTTED_OPEN;
  43068. break;
  43069. case 33:
  43070. this.$ = yy.LINETYPE.SOLID;
  43071. break;
  43072. case 34:
  43073. this.$ = yy.LINETYPE.DOTTED;
  43074. break;
  43075. case 35:
  43076. this.$ = yy.LINETYPE.SOLID_CROSS;
  43077. break;
  43078. case 36:
  43079. this.$ = yy.LINETYPE.DOTTED_CROSS;
  43080. break;
  43081. case 37:
  43082. this.$ = $$[$0].substring(1).trim().replace(/\\n/gm, "\n");
  43083. break;
  43084. }
  43085. },
  43086. 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])],
  43087. 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] },
  43088. parseError: function parseError(str, hash) {
  43089. if (hash.recoverable) {
  43090. this.trace(str);
  43091. } else {
  43092. var _parseError = function _parseError(msg, hash) {
  43093. this.message = msg;
  43094. this.hash = hash;
  43095. };
  43096. _parseError.prototype = Error;
  43097. throw new _parseError(str, hash);
  43098. }
  43099. },
  43100. parse: function parse(input) {
  43101. var self = this,
  43102. stack = [0],
  43103. tstack = [],
  43104. vstack = [null],
  43105. lstack = [],
  43106. table = this.table,
  43107. yytext = '',
  43108. yylineno = 0,
  43109. yyleng = 0,
  43110. recovering = 0,
  43111. TERROR = 2,
  43112. EOF = 1;
  43113. var args = lstack.slice.call(arguments, 1);
  43114. var lexer = Object.create(this.lexer);
  43115. var sharedState = { yy: {} };
  43116. for (var k in this.yy) {
  43117. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  43118. sharedState.yy[k] = this.yy[k];
  43119. }
  43120. }
  43121. lexer.setInput(input, sharedState.yy);
  43122. sharedState.yy.lexer = lexer;
  43123. sharedState.yy.parser = this;
  43124. if (typeof lexer.yylloc == 'undefined') {
  43125. lexer.yylloc = {};
  43126. }
  43127. var yyloc = lexer.yylloc;
  43128. lstack.push(yyloc);
  43129. var ranges = lexer.options && lexer.options.ranges;
  43130. if (typeof sharedState.yy.parseError === 'function') {
  43131. this.parseError = sharedState.yy.parseError;
  43132. } else {
  43133. this.parseError = Object.getPrototypeOf(this).parseError;
  43134. }
  43135. function popStack(n) {
  43136. stack.length = stack.length - 2 * n;
  43137. vstack.length = vstack.length - n;
  43138. lstack.length = lstack.length - n;
  43139. }
  43140. _token_stack: var lex = function lex() {
  43141. var token;
  43142. token = lexer.lex() || EOF;
  43143. if (typeof token !== 'number') {
  43144. token = self.symbols_[token] || token;
  43145. }
  43146. return token;
  43147. };
  43148. var symbol,
  43149. preErrorSymbol,
  43150. state,
  43151. action,
  43152. a,
  43153. r,
  43154. yyval = {},
  43155. p,
  43156. len,
  43157. newState,
  43158. expected;
  43159. while (true) {
  43160. state = stack[stack.length - 1];
  43161. if (this.defaultActions[state]) {
  43162. action = this.defaultActions[state];
  43163. } else {
  43164. if (symbol === null || typeof symbol == 'undefined') {
  43165. symbol = lex();
  43166. }
  43167. action = table[state] && table[state][symbol];
  43168. }
  43169. if (typeof action === 'undefined' || !action.length || !action[0]) {
  43170. var errStr = '';
  43171. expected = [];
  43172. for (p in table[state]) {
  43173. if (this.terminals_[p] && p > TERROR) {
  43174. expected.push('\'' + this.terminals_[p] + '\'');
  43175. }
  43176. }
  43177. if (lexer.showPosition) {
  43178. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  43179. } else {
  43180. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  43181. }
  43182. this.parseError(errStr, {
  43183. text: lexer.match,
  43184. token: this.terminals_[symbol] || symbol,
  43185. line: lexer.yylineno,
  43186. loc: yyloc,
  43187. expected: expected
  43188. });
  43189. }
  43190. if (action[0] instanceof Array && action.length > 1) {
  43191. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  43192. }
  43193. switch (action[0]) {
  43194. case 1:
  43195. stack.push(symbol);
  43196. vstack.push(lexer.yytext);
  43197. lstack.push(lexer.yylloc);
  43198. stack.push(action[1]);
  43199. symbol = null;
  43200. if (!preErrorSymbol) {
  43201. yyleng = lexer.yyleng;
  43202. yytext = lexer.yytext;
  43203. yylineno = lexer.yylineno;
  43204. yyloc = lexer.yylloc;
  43205. if (recovering > 0) {
  43206. recovering--;
  43207. }
  43208. } else {
  43209. symbol = preErrorSymbol;
  43210. preErrorSymbol = null;
  43211. }
  43212. break;
  43213. case 2:
  43214. len = this.productions_[action[1]][1];
  43215. yyval.$ = vstack[vstack.length - len];
  43216. yyval._$ = {
  43217. first_line: lstack[lstack.length - (len || 1)].first_line,
  43218. last_line: lstack[lstack.length - 1].last_line,
  43219. first_column: lstack[lstack.length - (len || 1)].first_column,
  43220. last_column: lstack[lstack.length - 1].last_column
  43221. };
  43222. if (ranges) {
  43223. yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
  43224. }
  43225. r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
  43226. if (typeof r !== 'undefined') {
  43227. return r;
  43228. }
  43229. if (len) {
  43230. stack = stack.slice(0, -1 * len * 2);
  43231. vstack = vstack.slice(0, -1 * len);
  43232. lstack = lstack.slice(0, -1 * len);
  43233. }
  43234. stack.push(this.productions_[action[1]][0]);
  43235. vstack.push(yyval.$);
  43236. lstack.push(yyval._$);
  43237. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  43238. stack.push(newState);
  43239. break;
  43240. case 3:
  43241. return true;
  43242. }
  43243. }
  43244. return true;
  43245. } };
  43246. /* generated by jison-lex 0.3.4 */
  43247. var lexer = (function () {
  43248. var lexer = {
  43249. EOF: 1,
  43250. parseError: function parseError(str, hash) {
  43251. if (this.yy.parser) {
  43252. this.yy.parser.parseError(str, hash);
  43253. } else {
  43254. throw new Error(str);
  43255. }
  43256. },
  43257. // resets the lexer, sets new input
  43258. setInput: function setInput(input, yy) {
  43259. this.yy = yy || this.yy || {};
  43260. this._input = input;
  43261. this._more = this._backtrack = this.done = false;
  43262. this.yylineno = this.yyleng = 0;
  43263. this.yytext = this.matched = this.match = '';
  43264. this.conditionStack = ['INITIAL'];
  43265. this.yylloc = {
  43266. first_line: 1,
  43267. first_column: 0,
  43268. last_line: 1,
  43269. last_column: 0
  43270. };
  43271. if (this.options.ranges) {
  43272. this.yylloc.range = [0, 0];
  43273. }
  43274. this.offset = 0;
  43275. return this;
  43276. },
  43277. // consumes and returns one char from the input
  43278. input: function input() {
  43279. var ch = this._input[0];
  43280. this.yytext += ch;
  43281. this.yyleng++;
  43282. this.offset++;
  43283. this.match += ch;
  43284. this.matched += ch;
  43285. var lines = ch.match(/(?:\r\n?|\n).*/g);
  43286. if (lines) {
  43287. this.yylineno++;
  43288. this.yylloc.last_line++;
  43289. } else {
  43290. this.yylloc.last_column++;
  43291. }
  43292. if (this.options.ranges) {
  43293. this.yylloc.range[1]++;
  43294. }
  43295. this._input = this._input.slice(1);
  43296. return ch;
  43297. },
  43298. // unshifts one char (or a string) into the input
  43299. unput: function unput(ch) {
  43300. var len = ch.length;
  43301. var lines = ch.split(/(?:\r\n?|\n)/g);
  43302. this._input = ch + this._input;
  43303. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  43304. //this.yyleng -= len;
  43305. this.offset -= len;
  43306. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  43307. this.match = this.match.substr(0, this.match.length - 1);
  43308. this.matched = this.matched.substr(0, this.matched.length - 1);
  43309. if (lines.length - 1) {
  43310. this.yylineno -= lines.length - 1;
  43311. }
  43312. var r = this.yylloc.range;
  43313. this.yylloc = {
  43314. first_line: this.yylloc.first_line,
  43315. last_line: this.yylineno + 1,
  43316. first_column: this.yylloc.first_column,
  43317. 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
  43318. };
  43319. if (this.options.ranges) {
  43320. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  43321. }
  43322. this.yyleng = this.yytext.length;
  43323. return this;
  43324. },
  43325. // When called from action, caches matched text and appends it on next action
  43326. more: function more() {
  43327. this._more = true;
  43328. return this;
  43329. },
  43330. // 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.
  43331. reject: function reject() {
  43332. if (this.options.backtrack_lexer) {
  43333. this._backtrack = true;
  43334. } else {
  43335. 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(), {
  43336. text: "",
  43337. token: null,
  43338. line: this.yylineno
  43339. });
  43340. }
  43341. return this;
  43342. },
  43343. // retain first n characters of the match
  43344. less: function less(n) {
  43345. this.unput(this.match.slice(n));
  43346. },
  43347. // displays already matched input, i.e. for error messages
  43348. pastInput: function pastInput() {
  43349. var past = this.matched.substr(0, this.matched.length - this.match.length);
  43350. return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
  43351. },
  43352. // displays upcoming input, i.e. for error messages
  43353. upcomingInput: function upcomingInput() {
  43354. var next = this.match;
  43355. if (next.length < 20) {
  43356. next += this._input.substr(0, 20 - next.length);
  43357. }
  43358. return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  43359. },
  43360. // displays the character position where the lexing error occurred, i.e. for error messages
  43361. showPosition: function showPosition() {
  43362. var pre = this.pastInput();
  43363. var c = new Array(pre.length + 1).join("-");
  43364. return pre + this.upcomingInput() + "\n" + c + "^";
  43365. },
  43366. // test the lexed token: return FALSE when not a match, otherwise return token
  43367. test_match: function test_match(match, indexed_rule) {
  43368. var token, lines, backup;
  43369. if (this.options.backtrack_lexer) {
  43370. // save context
  43371. backup = {
  43372. yylineno: this.yylineno,
  43373. yylloc: {
  43374. first_line: this.yylloc.first_line,
  43375. last_line: this.last_line,
  43376. first_column: this.yylloc.first_column,
  43377. last_column: this.yylloc.last_column
  43378. },
  43379. yytext: this.yytext,
  43380. match: this.match,
  43381. matches: this.matches,
  43382. matched: this.matched,
  43383. yyleng: this.yyleng,
  43384. offset: this.offset,
  43385. _more: this._more,
  43386. _input: this._input,
  43387. yy: this.yy,
  43388. conditionStack: this.conditionStack.slice(0),
  43389. done: this.done
  43390. };
  43391. if (this.options.ranges) {
  43392. backup.yylloc.range = this.yylloc.range.slice(0);
  43393. }
  43394. }
  43395. lines = match[0].match(/(?:\r\n?|\n).*/g);
  43396. if (lines) {
  43397. this.yylineno += lines.length;
  43398. }
  43399. this.yylloc = {
  43400. first_line: this.yylloc.last_line,
  43401. last_line: this.yylineno + 1,
  43402. first_column: this.yylloc.last_column,
  43403. last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
  43404. };
  43405. this.yytext += match[0];
  43406. this.match += match[0];
  43407. this.matches = match;
  43408. this.yyleng = this.yytext.length;
  43409. if (this.options.ranges) {
  43410. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  43411. }
  43412. this._more = false;
  43413. this._backtrack = false;
  43414. this._input = this._input.slice(match[0].length);
  43415. this.matched += match[0];
  43416. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  43417. if (this.done && this._input) {
  43418. this.done = false;
  43419. }
  43420. if (token) {
  43421. return token;
  43422. } else if (this._backtrack) {
  43423. // recover context
  43424. for (var k in backup) {
  43425. this[k] = backup[k];
  43426. }
  43427. return false; // rule action called reject() implying the next rule should be tested instead.
  43428. }
  43429. return false;
  43430. },
  43431. // return next match in input
  43432. next: function next() {
  43433. if (this.done) {
  43434. return this.EOF;
  43435. }
  43436. if (!this._input) {
  43437. this.done = true;
  43438. }
  43439. var token, match, tempMatch, index;
  43440. if (!this._more) {
  43441. this.yytext = '';
  43442. this.match = '';
  43443. }
  43444. var rules = this._currentRules();
  43445. for (var i = 0; i < rules.length; i++) {
  43446. tempMatch = this._input.match(this.rules[rules[i]]);
  43447. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  43448. match = tempMatch;
  43449. index = i;
  43450. if (this.options.backtrack_lexer) {
  43451. token = this.test_match(tempMatch, rules[i]);
  43452. if (token !== false) {
  43453. return token;
  43454. } else if (this._backtrack) {
  43455. match = false;
  43456. continue; // rule action called reject() implying a rule MISmatch.
  43457. } else {
  43458. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  43459. return false;
  43460. }
  43461. } else if (!this.options.flex) {
  43462. break;
  43463. }
  43464. }
  43465. }
  43466. if (match) {
  43467. token = this.test_match(match, rules[index]);
  43468. if (token !== false) {
  43469. return token;
  43470. }
  43471. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  43472. return false;
  43473. }
  43474. if (this._input === "") {
  43475. return this.EOF;
  43476. } else {
  43477. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  43478. text: "",
  43479. token: null,
  43480. line: this.yylineno
  43481. });
  43482. }
  43483. },
  43484. // return next match that has a token
  43485. lex: function lex() {
  43486. var r = this.next();
  43487. if (r) {
  43488. return r;
  43489. } else {
  43490. return this.lex();
  43491. }
  43492. },
  43493. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  43494. begin: function begin(condition) {
  43495. this.conditionStack.push(condition);
  43496. },
  43497. // pop the previously active lexer condition state off the condition stack
  43498. popState: function popState() {
  43499. var n = this.conditionStack.length - 1;
  43500. if (n > 0) {
  43501. return this.conditionStack.pop();
  43502. } else {
  43503. return this.conditionStack[0];
  43504. }
  43505. },
  43506. // produce the lexer rule set which is active for the currently active lexer condition state
  43507. _currentRules: function _currentRules() {
  43508. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  43509. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  43510. } else {
  43511. return this.conditions["INITIAL"].rules;
  43512. }
  43513. },
  43514. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  43515. topState: function topState(n) {
  43516. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  43517. if (n >= 0) {
  43518. return this.conditionStack[n];
  43519. } else {
  43520. return "INITIAL";
  43521. }
  43522. },
  43523. // alias for begin(condition)
  43524. pushState: function pushState(condition) {
  43525. this.begin(condition);
  43526. },
  43527. // return the number of states currently on the stack
  43528. stateStackSize: function stateStackSize() {
  43529. return this.conditionStack.length;
  43530. },
  43531. options: { "case-insensitive": true },
  43532. performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
  43533. var YYSTATE = YY_START;
  43534. switch ($avoiding_name_collisions) {
  43535. case 0:
  43536. return 5;
  43537. break;
  43538. case 1:
  43539. /* skip all whitespace */
  43540. break;
  43541. case 2:
  43542. /* skip same-line whitespace */
  43543. break;
  43544. case 3:
  43545. /* skip comments */
  43546. break;
  43547. case 4:
  43548. /* skip comments */
  43549. break;
  43550. case 5:
  43551. this.begin('ID');return 10;
  43552. break;
  43553. case 6:
  43554. this.begin('ALIAS');return 36;
  43555. break;
  43556. case 7:
  43557. this.popState();this.popState();this.begin('LINE');return 12;
  43558. break;
  43559. case 8:
  43560. this.popState();this.popState();return 5;
  43561. break;
  43562. case 9:
  43563. this.begin('LINE');return 20;
  43564. break;
  43565. case 10:
  43566. this.begin('LINE');return 22;
  43567. break;
  43568. case 11:
  43569. this.begin('LINE');return 23;
  43570. break;
  43571. case 12:
  43572. this.begin('LINE');return 24;
  43573. break;
  43574. case 13:
  43575. this.popState();return 13;
  43576. break;
  43577. case 14:
  43578. return 21;
  43579. break;
  43580. case 15:
  43581. return 31;
  43582. break;
  43583. case 16:
  43584. return 32;
  43585. break;
  43586. case 17:
  43587. return 27;
  43588. break;
  43589. case 18:
  43590. return 25;
  43591. break;
  43592. case 19:
  43593. this.begin('ID');return 15;
  43594. break;
  43595. case 20:
  43596. this.begin('ID');return 16;
  43597. break;
  43598. case 21:
  43599. return 18;
  43600. break;
  43601. case 22:
  43602. return 6;
  43603. break;
  43604. case 23:
  43605. return 30;
  43606. break;
  43607. case 24:
  43608. return 5;
  43609. break;
  43610. case 25:
  43611. yy_.yytext = yy_.yytext.trim();return 36;
  43612. break;
  43613. case 26:
  43614. return 39;
  43615. break;
  43616. case 27:
  43617. return 40;
  43618. break;
  43619. case 28:
  43620. return 37;
  43621. break;
  43622. case 29:
  43623. return 38;
  43624. break;
  43625. case 30:
  43626. return 41;
  43627. break;
  43628. case 31:
  43629. return 42;
  43630. break;
  43631. case 32:
  43632. return 43;
  43633. break;
  43634. case 33:
  43635. return 34;
  43636. break;
  43637. case 34:
  43638. return 35;
  43639. break;
  43640. case 35:
  43641. return 5;
  43642. break;
  43643. case 36:
  43644. return 'INVALID';
  43645. break;
  43646. }
  43647. },
  43648. 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],
  43649. 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 } }
  43650. };
  43651. return lexer;
  43652. })();
  43653. parser.lexer = lexer;
  43654. function Parser() {
  43655. this.yy = {};
  43656. }
  43657. Parser.prototype = parser;parser.Parser = Parser;
  43658. return new Parser();
  43659. })();
  43660. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  43661. exports.parser = parser;
  43662. exports.Parser = parser.Parser;
  43663. exports.parse = function () {
  43664. return parser.parse.apply(parser, arguments);
  43665. };
  43666. exports.main = function commonjsMain(args) {
  43667. if (!args[1]) {
  43668. console.log('Usage: ' + args[0] + ' FILE');
  43669. process.exit(1);
  43670. }
  43671. var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
  43672. return exports.parser.parse(source);
  43673. };
  43674. if (typeof module !== 'undefined' && require.main === module) {
  43675. exports.main(process.argv.slice(1));
  43676. }
  43677. }
  43678. }).call(this,require('_process'))
  43679. },{"_process":106,"fs":1,"path":105}],127:[function(require,module,exports){
  43680. (function (global){
  43681. /**
  43682. * Created by knut on 14-11-19.
  43683. */
  43684. 'use strict';
  43685. var actors = {};
  43686. var messages = [];
  43687. var notes = [];
  43688. var title = '';
  43689. var Logger = require('../../logger');
  43690. var log = new Logger.Log();
  43691. exports.addActor = function (id, name, description) {
  43692. // Don't allow description nulling
  43693. var old = actors[id];
  43694. if (old && name === old.name && description == null) return;
  43695. // Don't allow null descriptions, either
  43696. if (description == null) description = name;
  43697. actors[id] = { name: name, description: description };
  43698. };
  43699. exports.addMessage = function (idFrom, idTo, message, answer) {
  43700. messages.push({ from: idFrom, to: idTo, message: message, answer: answer });
  43701. };
  43702. /**
  43703. *
  43704. */
  43705. exports.addSignal = function (idFrom, idTo, message, messageType) {
  43706. log.debug('Adding message from=' + idFrom + ' to=' + idTo + ' message=' + message + ' type=' + messageType);
  43707. messages.push({ from: idFrom, to: idTo, message: message, type: messageType });
  43708. };
  43709. exports.getMessages = function () {
  43710. return messages;
  43711. };
  43712. exports.getActors = function () {
  43713. return actors;
  43714. };
  43715. exports.getActor = function (id) {
  43716. return actors[id];
  43717. };
  43718. exports.getActorKeys = function () {
  43719. return Object.keys(actors);
  43720. };
  43721. exports.getTitle = function () {
  43722. return title;
  43723. };
  43724. exports.clear = function () {
  43725. actors = {};
  43726. messages = [];
  43727. };
  43728. exports.LINETYPE = {
  43729. SOLID: 0,
  43730. DOTTED: 1,
  43731. NOTE: 2,
  43732. SOLID_CROSS: 3,
  43733. DOTTED_CROSS: 4,
  43734. SOLID_OPEN: 5,
  43735. DOTTED_OPEN: 6,
  43736. LOOP_START: 10,
  43737. LOOP_END: 11,
  43738. ALT_START: 12,
  43739. ALT_ELSE: 13,
  43740. ALT_END: 14,
  43741. OPT_START: 15,
  43742. OPT_END: 16,
  43743. ACTIVE_START: 17,
  43744. ACTIVE_END: 18
  43745. };
  43746. exports.ARROWTYPE = {
  43747. FILLED: 0,
  43748. OPEN: 1
  43749. };
  43750. exports.PLACEMENT = {
  43751. LEFTOF: 0,
  43752. RIGHTOF: 1,
  43753. OVER: 2
  43754. };
  43755. exports.addNote = function (actor, placement, message) {
  43756. var note = { actor: actor, placement: placement, message: message };
  43757. // Coerce actor into a [to, from, ...] array
  43758. var actors = [].concat(actor, actor);
  43759. notes.push(note);
  43760. messages.push({ from: actors[0], to: actors[1], message: message, type: exports.LINETYPE.NOTE, placement: placement });
  43761. };
  43762. exports.setTitle = function (titleText) {
  43763. title = titleText;
  43764. };
  43765. exports.parseError = function (err, hash) {
  43766. global.mermaidAPI.parseError(err, hash);
  43767. };
  43768. exports.apply = function (param) {
  43769. if (param instanceof Array) {
  43770. param.forEach(function (item) {
  43771. exports.apply(item);
  43772. });
  43773. } else {
  43774. // console.info(param);
  43775. switch (param.type) {
  43776. case 'addActor':
  43777. exports.addActor(param.actor, param.actor, param.description);
  43778. break;
  43779. case 'activeStart':
  43780. exports.addSignal(param.actor, undefined, undefined, param.signalType);
  43781. break;
  43782. case 'activeEnd':
  43783. exports.addSignal(param.actor, undefined, undefined, param.signalType);
  43784. break;
  43785. case 'addNote':
  43786. exports.addNote(param.actor, param.placement, param.text);
  43787. break;
  43788. case 'addMessage':
  43789. exports.addSignal(param.from, param.to, param.msg, param.signalType);
  43790. break;
  43791. case 'loopStart':
  43792. //log.debug('Loop text: ',param.loopText);
  43793. exports.addSignal(undefined, undefined, param.loopText, param.signalType);
  43794. //yy.addSignal(undefined, undefined, $2, yy.LINETYPE.LOOP_START);
  43795. break;
  43796. case 'loopEnd':
  43797. exports.addSignal(undefined, undefined, undefined, param.signalType);
  43798. break;
  43799. case 'optStart':
  43800. //log.debug('Loop text: ',param.loopText);
  43801. exports.addSignal(undefined, undefined, param.optText, param.signalType);
  43802. //yy.addSignal(undefined, undefined, $2, yy.LINETYPE.LOOP_START);
  43803. break;
  43804. case 'optEnd':
  43805. exports.addSignal(undefined, undefined, undefined, param.signalType);
  43806. break;
  43807. case 'altStart':
  43808. //log.debug('Loop text: ',param.loopText);
  43809. exports.addSignal(undefined, undefined, param.altText, param.signalType);
  43810. //yy.addSignal(undefined, undefined, $2, yy.LINETYPE.LOOP_START);
  43811. break;
  43812. case 'else':
  43813. exports.addSignal(undefined, undefined, param.altText, param.signalType);
  43814. break;
  43815. case 'altEnd':
  43816. exports.addSignal(undefined, undefined, undefined, param.signalType);
  43817. break;
  43818. case 'setTitle':
  43819. exports.setTitle(param.text);
  43820. }
  43821. }
  43822. };
  43823. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  43824. },{"../../logger":130}],128:[function(require,module,exports){
  43825. /**
  43826. * Created by knut on 14-11-23.
  43827. */
  43828. 'use strict';
  43829. var sq = require('./parser/sequenceDiagram').parser;
  43830. sq.yy = require('./sequenceDb');
  43831. var svgDraw = require('./svgDraw');
  43832. var d3 = require('../../d3');
  43833. var Logger = require('../../logger');
  43834. var log = new Logger.Log();
  43835. var conf = {
  43836. diagramMarginX: 50,
  43837. diagramMarginY: 30,
  43838. // Margin between actors
  43839. actorMargin: 50,
  43840. // Width of actor boxes
  43841. width: 150,
  43842. // Height of actor boxes
  43843. height: 65,
  43844. // Margin around loop boxes
  43845. boxMargin: 10,
  43846. boxTextMargin: 5,
  43847. noteMargin: 10,
  43848. // Space between messages
  43849. messageMargin: 35,
  43850. //mirror actors under diagram
  43851. mirrorActors: false,
  43852. // Depending on css styling this might need adjustment
  43853. // Prolongs the edge of the diagram downwards
  43854. bottomMarginAdj: 1,
  43855. // width of activation box
  43856. activationWidth: 10,
  43857. //text placement as: tspan | fo | old only text as before
  43858. textPlacement: 'tspan'
  43859. };
  43860. exports.bounds = {
  43861. data: {
  43862. startx: undefined,
  43863. stopx: undefined,
  43864. starty: undefined,
  43865. stopy: undefined
  43866. },
  43867. verticalPos: 0,
  43868. sequenceItems: [],
  43869. activations: [],
  43870. init: function init() {
  43871. this.sequenceItems = [];
  43872. this.activations = [];
  43873. this.data = {
  43874. startx: undefined,
  43875. stopx: undefined,
  43876. starty: undefined,
  43877. stopy: undefined
  43878. };
  43879. this.verticalPos = 0;
  43880. },
  43881. updateVal: function updateVal(obj, key, val, fun) {
  43882. if (typeof obj[key] === 'undefined') {
  43883. obj[key] = val;
  43884. } else {
  43885. obj[key] = fun(val, obj[key]);
  43886. }
  43887. },
  43888. updateBounds: function updateBounds(startx, starty, stopx, stopy) {
  43889. var _self = this;
  43890. var cnt = 0;
  43891. function updateFn(type) {
  43892. return function updateItemBounds(item) {
  43893. cnt++;
  43894. // The loop sequenceItems is a stack so the biggest margins in the beginning of the sequenceItems
  43895. var n = _self.sequenceItems.length - cnt + 1;
  43896. _self.updateVal(item, 'starty', starty - n * conf.boxMargin, Math.min);
  43897. _self.updateVal(item, 'stopy', stopy + n * conf.boxMargin, Math.max);
  43898. _self.updateVal(exports.bounds.data, 'startx', startx - n * conf.boxMargin, Math.min);
  43899. _self.updateVal(exports.bounds.data, 'stopx', stopx + n * conf.boxMargin, Math.max);
  43900. if (!(type == 'activation')) {
  43901. _self.updateVal(item, 'startx', startx - n * conf.boxMargin, Math.min);
  43902. _self.updateVal(item, 'stopx', stopx + n * conf.boxMargin, Math.max);
  43903. _self.updateVal(exports.bounds.data, 'starty', starty - n * conf.boxMargin, Math.min);
  43904. _self.updateVal(exports.bounds.data, 'stopy', stopy + n * conf.boxMargin, Math.max);
  43905. }
  43906. };
  43907. }
  43908. this.sequenceItems.forEach(updateFn());
  43909. this.activations.forEach(updateFn('activation'));
  43910. },
  43911. insert: function insert(startx, starty, stopx, stopy) {
  43912. var _startx, _starty, _stopx, _stopy;
  43913. _startx = Math.min(startx, stopx);
  43914. _stopx = Math.max(startx, stopx);
  43915. _starty = Math.min(starty, stopy);
  43916. _stopy = Math.max(starty, stopy);
  43917. this.updateVal(exports.bounds.data, 'startx', _startx, Math.min);
  43918. this.updateVal(exports.bounds.data, 'starty', _starty, Math.min);
  43919. this.updateVal(exports.bounds.data, 'stopx', _stopx, Math.max);
  43920. this.updateVal(exports.bounds.data, 'stopy', _stopy, Math.max);
  43921. this.updateBounds(_startx, _starty, _stopx, _stopy);
  43922. },
  43923. newActivation: function newActivation(message, diagram) {
  43924. var actorRect = sq.yy.getActors()[message.from.actor];
  43925. var stackedSize = actorActivations(message.from.actor).length;
  43926. var x = actorRect.x + conf.width / 2 + (stackedSize - 1) * conf.activationWidth / 2;
  43927. this.activations.push({ startx: x, starty: this.verticalPos + 2, stopx: x + conf.activationWidth, stopy: undefined,
  43928. actor: message.from.actor,
  43929. anchored: svgDraw.anchorElement(diagram)
  43930. });
  43931. },
  43932. endActivation: function endActivation(message) {
  43933. // find most recent activation for given actor
  43934. var lastActorActivationIdx = this.activations.map(function (activation) {
  43935. return activation.actor;
  43936. }).lastIndexOf(message.from.actor);
  43937. var activation = this.activations.splice(lastActorActivationIdx, 1)[0];
  43938. return activation;
  43939. },
  43940. newLoop: function newLoop(title) {
  43941. this.sequenceItems.push({ startx: undefined, starty: this.verticalPos, stopx: undefined, stopy: undefined, title: title });
  43942. },
  43943. endLoop: function endLoop() {
  43944. var loop = this.sequenceItems.pop();
  43945. return loop;
  43946. },
  43947. addElseToLoop: function addElseToLoop(message) {
  43948. var loop = this.sequenceItems.pop();
  43949. loop.elsey = exports.bounds.getVerticalPos();
  43950. loop.elseText = message;
  43951. this.sequenceItems.push(loop);
  43952. },
  43953. bumpVerticalPos: function bumpVerticalPos(bump) {
  43954. this.verticalPos = this.verticalPos + bump;
  43955. this.data.stopy = this.verticalPos;
  43956. },
  43957. getVerticalPos: function getVerticalPos() {
  43958. return this.verticalPos;
  43959. },
  43960. getBounds: function getBounds() {
  43961. return this.data;
  43962. }
  43963. };
  43964. /**
  43965. * Draws an actor in the diagram with the attaced line
  43966. * @param center - The center of the the actor
  43967. * @param pos The position if the actor in the liost of actors
  43968. * @param description The text in the box
  43969. */
  43970. var drawNote = function drawNote(elem, startx, verticalPos, msg, forceWidth) {
  43971. var rect = svgDraw.getNoteRect();
  43972. rect.x = startx;
  43973. rect.y = verticalPos;
  43974. rect.width = forceWidth || conf.width;
  43975. rect['class'] = 'note';
  43976. var g = elem.append('g');
  43977. var rectElem = svgDraw.drawRect(g, rect);
  43978. var textObj = svgDraw.getTextObj();
  43979. textObj.x = startx - 4;
  43980. textObj.y = verticalPos - 13;
  43981. textObj.textMargin = conf.noteMargin;
  43982. textObj.dy = '1em';
  43983. textObj.text = msg.message;
  43984. textObj['class'] = 'noteText';
  43985. var textElem = svgDraw.drawText(g, textObj, rect.width - conf.noteMargin);
  43986. var textHeight = textElem[0][0].getBBox().height;
  43987. if (!forceWidth && textHeight > conf.width) {
  43988. textElem.remove();
  43989. g = elem.append('g');
  43990. textElem = svgDraw.drawText(g, textObj, 2 * rect.width - conf.noteMargin);
  43991. textHeight = textElem[0][0].getBBox().height;
  43992. rectElem.attr('width', 2 * rect.width);
  43993. exports.bounds.insert(startx, verticalPos, startx + 2 * rect.width, verticalPos + 2 * conf.noteMargin + textHeight);
  43994. } else {
  43995. exports.bounds.insert(startx, verticalPos, startx + rect.width, verticalPos + 2 * conf.noteMargin + textHeight);
  43996. }
  43997. rectElem.attr('height', textHeight + 2 * conf.noteMargin);
  43998. exports.bounds.bumpVerticalPos(textHeight + 2 * conf.noteMargin);
  43999. };
  44000. /**
  44001. * Draws a message
  44002. * @param elem
  44003. * @param startx
  44004. * @param stopx
  44005. * @param verticalPos
  44006. * @param txtCenter
  44007. * @param msg
  44008. */
  44009. var drawMessage = function drawMessage(elem, startx, stopx, verticalPos, msg) {
  44010. var g = elem.append('g');
  44011. var txtCenter = startx + (stopx - startx) / 2;
  44012. var textElem = g.append('text') // text label for the x axis
  44013. .attr('x', txtCenter).attr('y', verticalPos - 7).style('text-anchor', 'middle').attr('class', 'messageText').text(msg.message);
  44014. var textWidth;
  44015. if (typeof textElem[0][0].getBBox !== 'undefined') {
  44016. textWidth = textElem[0][0].getBBox().width;
  44017. } else {
  44018. //textWidth = getBBox(textElem).width; //.getComputedTextLength()
  44019. textWidth = textElem[0][0].getBoundingClientRect();
  44020. //textWidth = textElem[0][0].getComputedTextLength();
  44021. }
  44022. var line;
  44023. if (startx === stopx) {
  44024. line = g.append('path').attr('d', 'M ' + startx + ',' + verticalPos + ' C ' + (startx + 60) + ',' + (verticalPos - 10) + ' ' + (startx + 60) + ',' + (verticalPos + 30) + ' ' + startx + ',' + (verticalPos + 20));
  44025. exports.bounds.bumpVerticalPos(30);
  44026. var dx = Math.max(textWidth / 2, 100);
  44027. exports.bounds.insert(startx - dx, exports.bounds.getVerticalPos() - 10, stopx + dx, exports.bounds.getVerticalPos());
  44028. } else {
  44029. line = g.append('line');
  44030. line.attr('x1', startx);
  44031. line.attr('y1', verticalPos);
  44032. line.attr('x2', stopx);
  44033. line.attr('y2', verticalPos);
  44034. exports.bounds.insert(startx, exports.bounds.getVerticalPos() - 10, stopx, exports.bounds.getVerticalPos());
  44035. }
  44036. //Make an SVG Container
  44037. //Draw the line
  44038. if (msg.type === sq.yy.LINETYPE.DOTTED || msg.type === sq.yy.LINETYPE.DOTTED_CROSS || msg.type === sq.yy.LINETYPE.DOTTED_OPEN) {
  44039. line.style('stroke-dasharray', '3, 3');
  44040. line.attr('class', 'messageLine1');
  44041. } else {
  44042. line.attr('class', 'messageLine0');
  44043. }
  44044. var url = '';
  44045. if (conf.arrowMarkerAbsolute) {
  44046. url = window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search;
  44047. url = url.replace(/\(/g, '\\(');
  44048. url = url.replace(/\)/g, '\\)');
  44049. }
  44050. line.attr('stroke-width', 2);
  44051. line.attr('stroke', 'black');
  44052. line.style('fill', 'none'); // remove any fill colour
  44053. if (msg.type === sq.yy.LINETYPE.SOLID || msg.type === sq.yy.LINETYPE.DOTTED) {
  44054. line.attr('marker-end', 'url(' + url + '#arrowhead)');
  44055. }
  44056. if (msg.type === sq.yy.LINETYPE.SOLID_CROSS || msg.type === sq.yy.LINETYPE.DOTTED_CROSS) {
  44057. line.attr('marker-end', 'url(' + url + '#crosshead)');
  44058. }
  44059. };
  44060. module.exports.drawActors = function (diagram, actors, actorKeys, verticalPos) {
  44061. var i;
  44062. // Draw the actors
  44063. for (i = 0; i < actorKeys.length; i++) {
  44064. var key = actorKeys[i];
  44065. // Add some rendering data to the object
  44066. actors[key].x = i * conf.actorMargin + i * conf.width;
  44067. actors[key].y = verticalPos;
  44068. actors[key].width = conf.diagramMarginX;
  44069. actors[key].height = conf.diagramMarginY;
  44070. // Draw the box with the attached line
  44071. svgDraw.drawActor(diagram, actors[key].x, verticalPos, actors[key].description, conf);
  44072. exports.bounds.insert(actors[key].x, verticalPos, actors[key].x + conf.width, conf.height);
  44073. }
  44074. // Add a margin between the actor boxes and the first arrow
  44075. //exports.bounds.bumpVerticalPos(conf.height+conf.messageMargin);
  44076. exports.bounds.bumpVerticalPos(conf.height);
  44077. };
  44078. module.exports.setConf = function (cnf) {
  44079. var keys = Object.keys(cnf);
  44080. keys.forEach(function (key) {
  44081. conf[key] = cnf[key];
  44082. });
  44083. };
  44084. var actorActivations = function actorActivations(actor) {
  44085. return module.exports.bounds.activations.filter(function (activation) {
  44086. return activation.actor == actor;
  44087. });
  44088. };
  44089. var actorFlowVerticaBounds = function actorFlowVerticaBounds(actor) {
  44090. // handle multiple stacked activations for same actor
  44091. var actors = sq.yy.getActors();
  44092. var activations = actorActivations(actor);
  44093. var left = activations.reduce(function (acc, activation) {
  44094. return Math.min(acc, activation.startx);
  44095. }, actors[actor].x + conf.width / 2);
  44096. var right = activations.reduce(function (acc, activation) {
  44097. return Math.max(acc, activation.stopx);
  44098. }, actors[actor].x + conf.width / 2);
  44099. return [left, right];
  44100. };
  44101. /**
  44102. * Draws a flowchart in the tag with id: id based on the graph definition in text.
  44103. * @param text
  44104. * @param id
  44105. */
  44106. module.exports.draw = function (text, id) {
  44107. sq.yy.clear();
  44108. sq.parse(text + '\n');
  44109. exports.bounds.init();
  44110. var diagram = d3.select('#' + id);
  44111. var startx;
  44112. var stopx;
  44113. var forceWidth;
  44114. // Fetch data from the parsing
  44115. var actors = sq.yy.getActors();
  44116. var actorKeys = sq.yy.getActorKeys();
  44117. var messages = sq.yy.getMessages();
  44118. var title = sq.yy.getTitle();
  44119. module.exports.drawActors(diagram, actors, actorKeys, 0);
  44120. // The arrow head definition is attached to the svg once
  44121. svgDraw.insertArrowHead(diagram);
  44122. svgDraw.insertArrowCrossHead(diagram);
  44123. function activeEnd(msg, verticalPos) {
  44124. var activationData = exports.bounds.endActivation(msg);
  44125. if (activationData.starty + 18 > verticalPos) {
  44126. activationData.starty = verticalPos - 6;
  44127. verticalPos += 12;
  44128. }
  44129. svgDraw.drawActivation(diagram, activationData, verticalPos, conf);
  44130. exports.bounds.insert(activationData.startx, verticalPos - 10, activationData.stopx, verticalPos);
  44131. }
  44132. var lastMsg;
  44133. // Draw the messages/signals
  44134. messages.forEach(function (msg) {
  44135. var loopData;
  44136. switch (msg.type) {
  44137. case sq.yy.LINETYPE.NOTE:
  44138. exports.bounds.bumpVerticalPos(conf.boxMargin);
  44139. startx = actors[msg.from].x;
  44140. stopx = actors[msg.to].x;
  44141. if (msg.placement === sq.yy.PLACEMENT.RIGHTOF) {
  44142. drawNote(diagram, startx + (conf.width + conf.actorMargin) / 2, exports.bounds.getVerticalPos(), msg);
  44143. } else if (msg.placement === sq.yy.PLACEMENT.LEFTOF) {
  44144. drawNote(diagram, startx - (conf.width + conf.actorMargin) / 2, exports.bounds.getVerticalPos(), msg);
  44145. } else if (msg.to === msg.from) {
  44146. // Single-actor over
  44147. drawNote(diagram, startx, exports.bounds.getVerticalPos(), msg);
  44148. } else {
  44149. // Multi-actor over
  44150. forceWidth = Math.abs(startx - stopx) + conf.actorMargin;
  44151. drawNote(diagram, (startx + stopx + conf.width - forceWidth) / 2, exports.bounds.getVerticalPos(), msg, forceWidth);
  44152. }
  44153. break;
  44154. case sq.yy.LINETYPE.ACTIVE_START:
  44155. exports.bounds.newActivation(msg, diagram);
  44156. break;
  44157. case sq.yy.LINETYPE.ACTIVE_END:
  44158. activeEnd(msg, exports.bounds.getVerticalPos());
  44159. break;
  44160. case sq.yy.LINETYPE.LOOP_START:
  44161. exports.bounds.bumpVerticalPos(conf.boxMargin);
  44162. exports.bounds.newLoop(msg.message);
  44163. exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin);
  44164. break;
  44165. case sq.yy.LINETYPE.LOOP_END:
  44166. loopData = exports.bounds.endLoop();
  44167. svgDraw.drawLoop(diagram, loopData, 'loop', conf);
  44168. exports.bounds.bumpVerticalPos(conf.boxMargin);
  44169. break;
  44170. case sq.yy.LINETYPE.OPT_START:
  44171. exports.bounds.bumpVerticalPos(conf.boxMargin);
  44172. exports.bounds.newLoop(msg.message);
  44173. exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin);
  44174. break;
  44175. case sq.yy.LINETYPE.OPT_END:
  44176. loopData = exports.bounds.endLoop();
  44177. svgDraw.drawLoop(diagram, loopData, 'opt', conf);
  44178. exports.bounds.bumpVerticalPos(conf.boxMargin);
  44179. break;
  44180. case sq.yy.LINETYPE.ALT_START:
  44181. exports.bounds.bumpVerticalPos(conf.boxMargin);
  44182. exports.bounds.newLoop(msg.message);
  44183. exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin);
  44184. break;
  44185. case sq.yy.LINETYPE.ALT_ELSE:
  44186. //exports.drawLoop(diagram, loopData);
  44187. exports.bounds.bumpVerticalPos(conf.boxMargin);
  44188. loopData = exports.bounds.addElseToLoop(msg.message);
  44189. exports.bounds.bumpVerticalPos(conf.boxMargin);
  44190. break;
  44191. case sq.yy.LINETYPE.ALT_END:
  44192. loopData = exports.bounds.endLoop();
  44193. svgDraw.drawLoop(diagram, loopData, 'alt', conf);
  44194. exports.bounds.bumpVerticalPos(conf.boxMargin);
  44195. break;
  44196. default:
  44197. try {
  44198. lastMsg = msg;
  44199. exports.bounds.bumpVerticalPos(conf.messageMargin);
  44200. var fromBounds = actorFlowVerticaBounds(msg.from);
  44201. var toBounds = actorFlowVerticaBounds(msg.to);
  44202. var fromIdx = fromBounds[0] <= toBounds[0] ? 1 : 0;
  44203. var toIdx = fromBounds[0] < toBounds[0] ? 0 : 1;
  44204. startx = fromBounds[fromIdx];
  44205. stopx = toBounds[toIdx];
  44206. var verticalPos = exports.bounds.getVerticalPos();
  44207. drawMessage(diagram, startx, stopx, verticalPos, msg);
  44208. var allBounds = fromBounds.concat(toBounds);
  44209. exports.bounds.insert(Math.min.apply(null, allBounds), verticalPos, Math.max.apply(null, allBounds), verticalPos);
  44210. } catch (e) {
  44211. console.error('error while drawing message', e);
  44212. }
  44213. }
  44214. });
  44215. if (conf.mirrorActors) {
  44216. // Draw actors below diagram
  44217. exports.bounds.bumpVerticalPos(conf.boxMargin * 2);
  44218. module.exports.drawActors(diagram, actors, actorKeys, exports.bounds.getVerticalPos());
  44219. }
  44220. var box = exports.bounds.getBounds();
  44221. // Adjust line height of actor lines now that the height of the diagram is known
  44222. log.debug('For line height fix Querying: #' + id + ' .actor-line');
  44223. var actorLines = d3.selectAll('#' + id + ' .actor-line');
  44224. actorLines.attr('y2', box.stopy);
  44225. var height = box.stopy - box.starty + 2 * conf.diagramMarginY;
  44226. if (conf.mirrorActors) {
  44227. height = height - conf.boxMargin + conf.bottomMarginAdj;
  44228. }
  44229. var width = box.stopx - box.startx + 2 * conf.diagramMarginX;
  44230. if (title) {
  44231. diagram.append('text').text(title).attr('x', (box.stopx - box.startx) / 2 - 2 * conf.diagramMarginX).attr('y', -25);
  44232. }
  44233. if (conf.useMaxWidth) {
  44234. diagram.attr('height', '100%');
  44235. diagram.attr('width', '100%');
  44236. diagram.attr('style', 'max-width:' + width + 'px;');
  44237. } else {
  44238. diagram.attr('height', height);
  44239. diagram.attr('width', width);
  44240. }
  44241. var extraVertForTitle = title ? 40 : 0;
  44242. diagram.attr('viewBox', box.startx - conf.diagramMarginX + ' -' + (conf.diagramMarginY + extraVertForTitle) + ' ' + width + ' ' + (height + extraVertForTitle));
  44243. };
  44244. },{"../../d3":108,"../../logger":130,"./parser/sequenceDiagram":126,"./sequenceDb":127,"./svgDraw":129}],129:[function(require,module,exports){
  44245. /**
  44246. * Created by knut on 14-12-20.
  44247. */
  44248. //var log = require('../../logger').create();
  44249. 'use strict';
  44250. exports.drawRect = function (elem, rectData) {
  44251. var rectElem = elem.append('rect');
  44252. rectElem.attr('x', rectData.x);
  44253. rectElem.attr('y', rectData.y);
  44254. rectElem.attr('fill', rectData.fill);
  44255. rectElem.attr('stroke', rectData.stroke);
  44256. rectElem.attr('width', rectData.width);
  44257. rectElem.attr('height', rectData.height);
  44258. rectElem.attr('rx', rectData.rx);
  44259. rectElem.attr('ry', rectData.ry);
  44260. if (typeof rectData['class'] !== 'undefined') {
  44261. rectElem.attr('class', rectData['class']);
  44262. }
  44263. return rectElem;
  44264. };
  44265. exports.drawText = function (elem, textData, width) {
  44266. // Remove and ignore br:s
  44267. var nText = textData.text.replace(/<br\/?>/ig, ' ');
  44268. var textElem = elem.append('text');
  44269. textElem.attr('x', textData.x);
  44270. textElem.attr('y', textData.y);
  44271. textElem.style('text-anchor', textData.anchor);
  44272. textElem.attr('fill', textData.fill);
  44273. if (typeof textData['class'] !== 'undefined') {
  44274. textElem.attr('class', textData['class']);
  44275. }
  44276. /* textData.text.split(/<br\/?>/ig).forEach(function(rowText){
  44277. var span = textElem.append('tspan');
  44278. span.attr('x', textData.x +textData.textMargin);
  44279. span.attr('dy', textData.dy);
  44280. span.text(rowText);
  44281. });*/
  44282. var span = textElem.append('tspan');
  44283. //span.attr('x', textData.x);
  44284. span.attr('x', textData.x + textData.textMargin * 2);
  44285. //span.attr('dy', textData.dy);
  44286. span.text(nText);
  44287. if (typeof textElem.textwrap !== 'undefined') {
  44288. textElem.textwrap({
  44289. x: textData.x, // bounding box is 300 pixels from the left
  44290. y: textData.y, // bounding box is 400 pixels from the top
  44291. width: width, // bounding box is 500 pixels across
  44292. height: 1800 // bounding box is 600 pixels tall
  44293. }, textData.textMargin);
  44294. }
  44295. return textElem;
  44296. };
  44297. exports.drawLabel = function (elem, txtObject) {
  44298. var rectData = exports.getNoteRect();
  44299. rectData.x = txtObject.x;
  44300. rectData.y = txtObject.y;
  44301. rectData.width = 50;
  44302. rectData.height = 20;
  44303. rectData.fill = '#526e52';
  44304. rectData.stroke = 'none';
  44305. rectData['class'] = 'labelBox';
  44306. //rectData.color = 'white';
  44307. exports.drawRect(elem, rectData);
  44308. txtObject.y = txtObject.y + txtObject.labelMargin;
  44309. txtObject.x = txtObject.x + 0.5 * txtObject.labelMargin;
  44310. txtObject.fill = 'white';
  44311. exports.drawText(elem, txtObject);
  44312. //return textElem;
  44313. };
  44314. var actorCnt = -1;
  44315. /**
  44316. * Draws an actor in the diagram with the attaced line
  44317. * @param center - The center of the the actor
  44318. * @param pos The position if the actor in the liost of actors
  44319. * @param description The text in the box
  44320. */
  44321. exports.drawActor = function (elem, left, verticalPos, description, conf) {
  44322. var center = left + conf.width / 2;
  44323. var g = elem.append('g');
  44324. if (verticalPos === 0) {
  44325. actorCnt++;
  44326. 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');
  44327. }
  44328. var rect = exports.getNoteRect();
  44329. rect.x = left;
  44330. rect.y = verticalPos;
  44331. rect.fill = '#eaeaea';
  44332. rect.width = conf.width;
  44333. rect.height = conf.height;
  44334. rect['class'] = 'actor';
  44335. rect.rx = 3;
  44336. rect.ry = 3;
  44337. exports.drawRect(g, rect);
  44338. _drawTextCandidateFunc(conf)(description, g, rect.x, rect.y, rect.width, rect.height, { 'class': 'actor' });
  44339. };
  44340. exports.anchorElement = function (elem) {
  44341. return elem.append('g');
  44342. };
  44343. /**
  44344. * Draws an actor in the diagram with the attaced line
  44345. * @param elem - element to append activation rect
  44346. * @param bounds - activation box bounds
  44347. * @param verticalPos - precise y cooridnate of bottom activation box edge
  44348. */
  44349. exports.drawActivation = function (elem, bounds, verticalPos) {
  44350. var rect = exports.getNoteRect();
  44351. var g = bounds.anchored;
  44352. rect.x = bounds.startx;
  44353. rect.y = bounds.starty;
  44354. rect.fill = '#f4f4f4';
  44355. rect.width = bounds.stopx - bounds.startx;
  44356. rect.height = verticalPos - bounds.starty;
  44357. exports.drawRect(g, rect);
  44358. };
  44359. /**
  44360. * Draws an actor in the diagram with the attaced line
  44361. * @param center - The center of the the actor
  44362. * @param pos The position if the actor in the list of actors
  44363. * @param description The text in the box
  44364. */
  44365. exports.drawLoop = function (elem, bounds, labelText, conf) {
  44366. var g = elem.append('g');
  44367. var drawLoopLine = function drawLoopLine(startx, starty, stopx, stopy) {
  44368. 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');
  44369. };
  44370. drawLoopLine(bounds.startx, bounds.starty, bounds.stopx, bounds.starty);
  44371. drawLoopLine(bounds.stopx, bounds.starty, bounds.stopx, bounds.stopy);
  44372. drawLoopLine(bounds.startx, bounds.stopy, bounds.stopx, bounds.stopy);
  44373. drawLoopLine(bounds.startx, bounds.starty, bounds.startx, bounds.stopy);
  44374. if (typeof bounds.elsey !== 'undefined') {
  44375. drawLoopLine(bounds.startx, bounds.elsey, bounds.stopx, bounds.elsey);
  44376. }
  44377. var txt = exports.getTextObj();
  44378. txt.text = labelText;
  44379. txt.x = bounds.startx;
  44380. txt.y = bounds.starty;
  44381. txt.labelMargin = 1.5 * 10; // This is the small box that says "loop"
  44382. txt['class'] = 'labelText'; // Its size & position are fixed.
  44383. txt.fill = 'white';
  44384. exports.drawLabel(g, txt);
  44385. txt = exports.getTextObj();
  44386. txt.text = '[ ' + bounds.title + ' ]';
  44387. txt.x = bounds.startx + (bounds.stopx - bounds.startx) / 2;
  44388. txt.y = bounds.starty + 1.5 * conf.boxMargin;
  44389. txt.anchor = 'middle';
  44390. txt['class'] = 'loopText';
  44391. exports.drawText(g, txt);
  44392. if (typeof bounds.elseText !== 'undefined') {
  44393. txt.text = '[ ' + bounds.elseText + ' ]';
  44394. txt.y = bounds.elsey + 1.5 * conf.boxMargin;
  44395. exports.drawText(g, txt);
  44396. }
  44397. };
  44398. /**
  44399. * Setup arrow head and define the marker. The result is appended to the svg.
  44400. */
  44401. exports.insertArrowHead = function (elem) {
  44402. 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
  44403. };
  44404. /**
  44405. * Setup arrow head and define the marker. The result is appended to the svg.
  44406. */
  44407. exports.insertArrowCrossHead = function (elem) {
  44408. var defs = elem.append('defs');
  44409. var marker = defs.append('marker').attr('id', 'crosshead').attr('markerWidth', 15).attr('markerHeight', 8).attr('orient', 'auto').attr('refX', 16).attr('refY', 4);
  44410. // The arrow
  44411. 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');
  44412. // The cross
  44413. 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
  44414. };
  44415. exports.getTextObj = function () {
  44416. var txt = {
  44417. x: 0,
  44418. y: 0,
  44419. 'fill': 'black',
  44420. 'text-anchor': 'start',
  44421. style: '#666',
  44422. width: 100,
  44423. height: 100,
  44424. textMargin: 0,
  44425. rx: 0,
  44426. ry: 0
  44427. };
  44428. return txt;
  44429. };
  44430. exports.getNoteRect = function () {
  44431. var rect = {
  44432. x: 0,
  44433. y: 0,
  44434. fill: '#EDF2AE',
  44435. stroke: '#666',
  44436. width: 100,
  44437. anchor: 'start',
  44438. height: 100,
  44439. rx: 0,
  44440. ry: 0
  44441. };
  44442. return rect;
  44443. };
  44444. var _drawTextCandidateFunc = (function () {
  44445. function byText(content, g, x, y, width, height, textAttrs) {
  44446. var text = g.append('text').attr('x', x + width / 2).attr('y', y + height / 2 + 5).style('text-anchor', 'middle').text(content);
  44447. _setTextAttrs(text, textAttrs);
  44448. }
  44449. function byTspan(content, g, x, y, width, height, textAttrs) {
  44450. var text = g.append('text').attr('x', x + width / 2).attr('y', y).style('text-anchor', 'middle');
  44451. text.append('tspan').attr('x', x + width / 2).attr('dy', '0').text(content);
  44452. if (typeof text.textwrap !== 'undefined') {
  44453. text.textwrap({ //d3textwrap
  44454. x: x + width / 2, y: y, width: width, height: height
  44455. }, 0);
  44456. //vertical aligment after d3textwrap expans tspan to multiple tspans
  44457. var tspans = text.selectAll('tspan');
  44458. if (tspans.length > 0 && tspans[0].length > 0) {
  44459. tspans = tspans[0];
  44460. //set y of <text> to the mid y of the first line
  44461. 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");
  44462. }
  44463. }
  44464. _setTextAttrs(text, textAttrs);
  44465. }
  44466. function byFo(content, g, x, y, width, height, textAttrs) {
  44467. var s = g.append('switch');
  44468. var f = s.append("foreignObject").attr('x', x).attr('y', y).attr('width', width).attr('height', height);
  44469. var text = f.append('div').style('display', 'table').style('height', '100%').style('width', '100%');
  44470. text.append('div').style('display', 'table-cell').style('text-align', 'center').style('vertical-align', 'middle').text(content);
  44471. byTspan(content, s, x, y, width, height, textAttrs);
  44472. _setTextAttrs(text, textAttrs);
  44473. }
  44474. function _setTextAttrs(toText, fromTextAttrsDict) {
  44475. for (var key in fromTextAttrsDict) {
  44476. if (fromTextAttrsDict.hasOwnProperty(key)) {
  44477. toText.attr(key, fromTextAttrsDict[key]);
  44478. }
  44479. }
  44480. }
  44481. return function (conf) {
  44482. return conf.textPlacement === 'fo' ? byFo : conf.textPlacement === 'old' ? byText : byTspan;
  44483. };
  44484. })();
  44485. },{}],130:[function(require,module,exports){
  44486. /**
  44487. * #logger
  44488. * logger = require('logger').create()
  44489. * logger.info("blah")
  44490. * => [2011-3-3T20:24:4.810 info (5021)] blah
  44491. * logger.debug("boom")
  44492. * =>
  44493. * logger.level = Logger.levels.debug
  44494. * logger.debug(function() { return "booom" })
  44495. * => [2011-3-3T20:24:4.810 error (5021)] booom
  44496. */
  44497. 'use strict';
  44498. var LEVELS = {
  44499. debug: 1,
  44500. info: 2,
  44501. warn: 3,
  44502. error: 4,
  44503. fatal: 5,
  44504. 'default': 5
  44505. };
  44506. var defaultLevel = LEVELS.error;
  44507. exports.setLogLevel = function (level) {
  44508. defaultLevel = level;
  44509. };
  44510. function formatTime(timestamp) {
  44511. var hh = timestamp.getUTCHours();
  44512. var mm = timestamp.getUTCMinutes();
  44513. var ss = timestamp.getSeconds();
  44514. var ms = timestamp.getMilliseconds();
  44515. // If you were building a timestamp instead of a duration, you would uncomment the following line to get 12-hour (not 24) time
  44516. // if (hh > 12) {hh = hh % 12;}
  44517. // These lines ensure you have two-digits
  44518. if (hh < 10) {
  44519. hh = '0' + hh;
  44520. }
  44521. if (mm < 10) {
  44522. mm = '0' + mm;
  44523. }
  44524. if (ss < 10) {
  44525. ss = '0' + ss;
  44526. }
  44527. if (ms < 100) {
  44528. ms = '0' + ms;
  44529. }
  44530. if (ms < 10) {
  44531. ms = '00' + ms;
  44532. }
  44533. // This formats your string to HH:MM:SS
  44534. var t = hh + ':' + mm + ':' + ss + ' (' + ms + ')';
  44535. return t;
  44536. }
  44537. function format(level) {
  44538. var time = formatTime(new Date());
  44539. return '%c ' + time + ' :%c' + level + ': ';
  44540. }
  44541. function Log(level) {
  44542. this.level = level;
  44543. this.log = function () {
  44544. var args = Array.prototype.slice.call(arguments);
  44545. var level = args.shift();
  44546. var logLevel = this.level;
  44547. if (typeof logLevel === 'undefined') {
  44548. logLevel = defaultLevel;
  44549. }
  44550. if (logLevel <= level) {
  44551. if (typeof console !== 'undefined') {
  44552. //eslint-disable-line no-console
  44553. if (typeof console.log !== 'undefined') {
  44554. //eslint-disable-line no-console
  44555. //return console.log('[' + formatTime(new Date()) + '] ' , str); //eslint-disable-line no-console
  44556. args.unshift('[' + formatTime(new Date()) + '] ');
  44557. console.log.apply(console, args.map(function (a) {
  44558. if (typeof a === "object") {
  44559. return a.toString() + JSON.stringify(a, null, 2);
  44560. }
  44561. return a;
  44562. }));
  44563. }
  44564. }
  44565. }
  44566. };
  44567. this.trace = window.console.debug.bind(window.console, format('TRACE', name), 'color:grey;', 'color: grey;');
  44568. this.debug = window.console.debug.bind(window.console, format('DEBUG', name), 'color:grey;', 'color: green;');
  44569. this.info = window.console.debug.bind(window.console, format('INFO', name), 'color:grey;', 'color: blue;');
  44570. this.warn = window.console.debug.bind(window.console, format('WARN', name), 'color:grey;', 'color: orange;');
  44571. this.error = window.console.debug.bind(window.console, format('ERROR', name), 'color:grey;', 'color: red;');
  44572. }
  44573. exports.Log = Log;
  44574. },{}],131:[function(require,module,exports){
  44575. (function (global){
  44576. /**
  44577. * Web page integration module for the mermaid framework. It uses the mermaidAPI for mermaid functionality and to render
  44578. * the diagrams to svg code.
  44579. */
  44580. 'use strict';
  44581. var Logger = require('./logger');
  44582. var log = new Logger.Log();
  44583. var mermaidAPI = require('./mermaidAPI');
  44584. var nextId = 0;
  44585. var he = require('he');
  44586. module.exports.mermaidAPI = mermaidAPI;
  44587. /**
  44588. * ## init
  44589. * Function that goes through the document to find the chart definitions in there and render them.
  44590. *
  44591. * The function tags the processed attributes with the attribute data-processed and ignores found elements with the
  44592. * attribute already set. This way the init function can be triggered several times.
  44593. *
  44594. * Optionally, `init` can accept in the second argument one of the following:
  44595. * - a DOM Node
  44596. * - an array of DOM nodes (as would come from a jQuery selector)
  44597. * - a W3C selector, a la `.mermaid`
  44598. *
  44599. * ```mermaid
  44600. * graph LR;
  44601. * a(Find elements)-->b{Processed}
  44602. * b-->|Yes|c(Leave element)
  44603. * b-->|No |d(Transform)
  44604. * ```
  44605. * Renders the mermaid diagrams
  44606. * @param nodes a css selector or an array of nodes
  44607. */
  44608. var _init = function _init() {
  44609. var conf = mermaidAPI.getConfig();
  44610. log.debug('Starting rendering diagrams');
  44611. var nodes;
  44612. if (arguments.length >= 2) {
  44613. /*! sequence config was passed as #1 */
  44614. if (typeof arguments[0] !== 'undefined') {
  44615. global.mermaid.sequenceConfig = arguments[0];
  44616. }
  44617. nodes = arguments[1];
  44618. } else {
  44619. nodes = arguments[0];
  44620. }
  44621. // if last argument is a function this is the callback function
  44622. var callback;
  44623. if (typeof arguments[arguments.length - 1] === 'function') {
  44624. callback = arguments[arguments.length - 1];
  44625. log.debug('Callback function found');
  44626. } else {
  44627. if (typeof conf.mermaid !== 'undefined') {
  44628. if (typeof conf.mermaid.callback === 'function') {
  44629. callback = conf.mermaid.callback;
  44630. log.debug('Callback function found');
  44631. } else {
  44632. log.debug('No Callback function found');
  44633. }
  44634. }
  44635. }
  44636. nodes = nodes === undefined ? document.querySelectorAll('.mermaid') : typeof nodes === 'string' ? document.querySelectorAll(nodes) : nodes instanceof Node ? [nodes] : nodes; // Last case - sequence config was passed pick next
  44637. var i;
  44638. if (typeof mermaid_config !== 'undefined') {
  44639. mermaidAPI.initialize(global.mermaid_config);
  44640. }
  44641. log.debug('Start On Load before: ' + global.mermaid.startOnLoad);
  44642. if (typeof global.mermaid.startOnLoad !== 'undefined') {
  44643. log.debug('Start On Load inner: ' + global.mermaid.startOnLoad);
  44644. mermaidAPI.initialize({ startOnLoad: global.mermaid.startOnLoad });
  44645. }
  44646. if (typeof global.mermaid.ganttConfig !== 'undefined') {
  44647. mermaidAPI.initialize({ gantt: global.mermaid.ganttConfig });
  44648. }
  44649. var txt;
  44650. var insertSvg = function insertSvg(svgCode, bindFunctions) {
  44651. element.innerHTML = svgCode;
  44652. if (typeof callback !== 'undefined') {
  44653. callback(id);
  44654. }
  44655. bindFunctions(element);
  44656. };
  44657. for (i = 0; i < nodes.length; i++) {
  44658. var element = nodes[i];
  44659. /*! Check if previously processed */
  44660. if (!element.getAttribute('data-processed')) {
  44661. element.setAttribute('data-processed', true);
  44662. } else {
  44663. continue;
  44664. }
  44665. var id = 'mermaidChart' + nextId++;
  44666. // Fetch the graph definition including tags
  44667. txt = element.innerHTML;
  44668. //console.warn('delivererd from the browser: ');
  44669. //console.warn(txt);
  44670. // transforms the html to pure text
  44671. txt = he.decode(txt).trim();
  44672. //console.warn('he decode: ');
  44673. //console.warn(txt);
  44674. mermaidAPI.render(id, txt, insertSvg, element);
  44675. }
  44676. };
  44677. exports.init = _init;
  44678. exports.parse = mermaidAPI.parse;
  44679. /**
  44680. * ## version
  44681. * Function returning version information
  44682. * @returns {string} A string containing the version info
  44683. */
  44684. exports.version = function () {
  44685. return 'v' + require('../package.json').version;
  44686. };
  44687. /**
  44688. * ## initialize
  44689. * This function overrides the default configuration.
  44690. * @param config
  44691. */
  44692. exports.initialize = function (config) {
  44693. log.debug('Initializing mermaid');
  44694. if (typeof config.mermaid !== 'undefined') {
  44695. if (typeof config.mermaid.startOnLoad !== 'undefined') {
  44696. global.mermaid.startOnLoad = config.mermaid.startOnLoad;
  44697. }
  44698. if (typeof config.mermaid.htmlLabels !== 'undefined') {
  44699. global.mermaid.htmlLabels = config.mermaid.htmlLabels;
  44700. }
  44701. }
  44702. mermaidAPI.initialize(config);
  44703. };
  44704. var equals = function equals(val, variable) {
  44705. if (typeof variable === 'undefined') {
  44706. return false;
  44707. } else {
  44708. return val === variable;
  44709. }
  44710. };
  44711. /**
  44712. * Global mermaid object. Contains the functions:
  44713. * * init
  44714. * * initialize
  44715. * * version
  44716. * * parse
  44717. * * parseError
  44718. * * render
  44719. */
  44720. global.mermaid = {
  44721. startOnLoad: true,
  44722. htmlLabels: true,
  44723. init: function init() {
  44724. _init.apply(null, arguments);
  44725. },
  44726. initialize: function initialize(config) {
  44727. exports.initialize(config);
  44728. },
  44729. version: function version() {
  44730. return mermaidAPI.version();
  44731. },
  44732. parse: function parse(text) {
  44733. return mermaidAPI.parse(text);
  44734. },
  44735. parseError: function parseError(err) {
  44736. log.debug('Mermaid Syntax error:');
  44737. log.debug(err);
  44738. },
  44739. render: function render(id, text, callback, element) {
  44740. return mermaidAPI.render(id, text, callback, element);
  44741. }
  44742. };
  44743. /**
  44744. * ## parseError
  44745. * This function overrides the default configuration.
  44746. * @param config
  44747. */
  44748. exports.parseError = global.mermaid.parseError;
  44749. /**
  44750. * ##contentLoaded
  44751. * Callback function that is called when page is loaded. This functions fetches configuration for mermaid rendering and
  44752. * calls init for rendering the mermaid diagrams on the page.
  44753. */
  44754. exports.contentLoaded = function () {
  44755. var config;
  44756. // Check state of start config mermaid namespace
  44757. if (typeof mermaid_config !== 'undefined') {
  44758. if (equals(false, global.mermaid_config.htmlLabels)) {
  44759. global.mermaid.htmlLabels = false;
  44760. }
  44761. }
  44762. if (global.mermaid.startOnLoad) {
  44763. // For backwards compatability reasons also check mermaid_config variable
  44764. if (typeof global.mermaid_config !== 'undefined') {
  44765. // Check if property startOnLoad is set
  44766. if (equals(true, global.mermaid_config.startOnLoad)) {
  44767. global.mermaid.init();
  44768. }
  44769. } else {
  44770. // No config found, do check API config
  44771. config = mermaidAPI.getConfig();
  44772. if (config.startOnLoad) {
  44773. global.mermaid.init();
  44774. }
  44775. }
  44776. } else {
  44777. //if(typeof global.mermaid === 'undefined' ){
  44778. if (typeof global.mermaid.startOnLoad === 'undefined') {
  44779. log.debug('In start, no config');
  44780. config = mermaidAPI.getConfig();
  44781. if (config.startOnLoad) {
  44782. global.mermaid.init();
  44783. }
  44784. //}else{
  44785. //
  44786. //}
  44787. }
  44788. }
  44789. };
  44790. if (typeof document !== 'undefined') {
  44791. /*!
  44792. * Wait for document loaded before starting the execution
  44793. */
  44794. window.addEventListener('load', function () {
  44795. exports.contentLoaded();
  44796. }, false);
  44797. }
  44798. // // Your actual module
  44799. // return module.exports;
  44800. //}));
  44801. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  44802. },{"../package.json":107,"./logger":130,"./mermaidAPI":132,"he":102}],132:[function(require,module,exports){
  44803. (function (global){
  44804. /**
  44805. * ---
  44806. * title: mermaidAPI
  44807. * order: 5
  44808. * ---
  44809. * # mermaidAPI
  44810. * This is the api to be used when handling the integration with the web page instead of using the default integration
  44811. * (mermaid.js).
  44812. *
  44813. * The core of this api is the **render** function that given a graph definitionas text renders the graph/diagram and
  44814. * 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
  44815. * somewhere in the page or something completely different.
  44816. */
  44817. 'use strict';
  44818. var Logger = require('./logger');
  44819. var log = new Logger.Log();
  44820. var graph = require('./diagrams/flowchart/graphDb');
  44821. var utils = require('./utils');
  44822. var flowRenderer = require('./diagrams/flowchart/flowRenderer');
  44823. var seq = require('./diagrams/sequenceDiagram/sequenceRenderer');
  44824. var info = require('./diagrams/example/exampleRenderer');
  44825. var infoParser = require('./diagrams/example/parser/example');
  44826. var flowParser = require('./diagrams/flowchart/parser/flow');
  44827. var dotParser = require('./diagrams/flowchart/parser/dot');
  44828. var sequenceParser = require('./diagrams/sequenceDiagram/parser/sequenceDiagram');
  44829. var sequenceDb = require('./diagrams/sequenceDiagram/sequenceDb');
  44830. var infoDb = require('./diagrams/example/exampleDb');
  44831. var gantt = require('./diagrams/gantt/ganttRenderer');
  44832. var ganttParser = require('./diagrams/gantt/parser/gantt');
  44833. var ganttDb = require('./diagrams/gantt/ganttDb');
  44834. var classParser = require('./diagrams/classDiagram/parser/classDiagram');
  44835. var classRenderer = require('./diagrams/classDiagram/classRenderer');
  44836. var classDb = require('./diagrams/classDiagram/classDb');
  44837. var gitGraphParser = require('./diagrams/gitGraph/parser/gitGraph');
  44838. var gitGraphRenderer = require('./diagrams/gitGraph/gitGraphRenderer');
  44839. var gitGraphAst = require('./diagrams/gitGraph/gitGraphAst');
  44840. var d3 = require('./d3');
  44841. SVGElement.prototype.getTransformToElement = SVGElement.prototype.getTransformToElement || function (toElement) {
  44842. return toElement.getScreenCTM().inverse().multiply(this.getScreenCTM());
  44843. };
  44844. /**
  44845. * ## Configuration
  44846. * These are the default options which can be overridden with the initialization call as in the example below:
  44847. * ```
  44848. * mermaid.initialize({
  44849. * flowchart:{
  44850. * htmlLabels: false
  44851. * }
  44852. * });
  44853. * ```
  44854. */
  44855. var config = {
  44856. /**
  44857. * logLevel , decides the amount of logging to be used.
  44858. * * debug: 1
  44859. * * info: 2
  44860. * * warn: 3
  44861. * * error: 4
  44862. * * fatal: 5
  44863. */
  44864. logLevel: 5,
  44865. /**
  44866. * **cloneCssStyles** - This options controls whether or not the css rules should be copied into the generated svg
  44867. */
  44868. cloneCssStyles: true,
  44869. /**
  44870. * **startOnLoad** - This options controls whether or mermaid starts when the page loads
  44871. */
  44872. startOnLoad: true,
  44873. /**
  44874. * **arrowMarkerAbsolute** - This options controls whether or arrow markers in html code will be absolute paths or
  44875. * an anchor, #. This matters if you are using base tag settings.
  44876. */
  44877. arrowMarkerAbsolute: false,
  44878. /**
  44879. * ### flowchart
  44880. * *The object containing configurations specific for flowcharts*
  44881. */
  44882. flowchart: {
  44883. /**
  44884. * **htmlLabels** - Flag for setting whether or not a html tag should be used for rendering labels
  44885. * on the edges
  44886. */
  44887. htmlLabels: true,
  44888. /**
  44889. * **useMaxWidth** - Flag for setting whether or not a all available width should be used for
  44890. * the diagram.
  44891. */
  44892. useMaxWidth: true
  44893. },
  44894. /**
  44895. * ### sequenceDiagram
  44896. * The object containing configurations specific for sequence diagrams
  44897. */
  44898. sequenceDiagram: {
  44899. /**
  44900. * **diagramMarginX** - margin to the right and left of the sequence diagram
  44901. */
  44902. diagramMarginX: 50,
  44903. /**
  44904. * **diagramMarginY** - margin to the over and under the sequence diagram
  44905. */
  44906. diagramMarginY: 10,
  44907. /**
  44908. * **actorMargin** - Margin between actors
  44909. */
  44910. actorMargin: 50,
  44911. /**
  44912. * **width** - Width of actor boxes
  44913. */
  44914. width: 150,
  44915. /**
  44916. * **height** - Height of actor boxes
  44917. */
  44918. height: 65,
  44919. /**
  44920. * **boxMargin** - Margin around loop boxes
  44921. */
  44922. boxMargin: 10,
  44923. /**
  44924. * **boxTextMargin** - margin around the text in loop/alt/opt boxes
  44925. */
  44926. boxTextMargin: 5,
  44927. /**
  44928. * **noteMargin** - margin around notes
  44929. */
  44930. noteMargin: 10,
  44931. /**
  44932. * **messageMargin** - Space between messages
  44933. */
  44934. messageMargin: 35,
  44935. /**
  44936. * **mirrorActors** - mirror actors under diagram
  44937. */
  44938. mirrorActors: true,
  44939. /**
  44940. * **bottomMarginAdj** - Depending on css styling this might need adjustment.
  44941. * Prolongs the edge of the diagram downwards
  44942. */
  44943. bottomMarginAdj: 1,
  44944. /**
  44945. * **useMaxWidth** - when this flag is set the height and width is set to 100% and is then scaling with the
  44946. * available space if not the absolute space required is used
  44947. */
  44948. useMaxWidth: true
  44949. },
  44950. /** ### gantt
  44951. * The object containing configurations specific for gantt diagrams*
  44952. */
  44953. gantt: {
  44954. /**
  44955. * **titleTopMargin** - margin top for the text over the gantt diagram
  44956. */
  44957. titleTopMargin: 25,
  44958. /**
  44959. * **barHeight** - the height of the bars in the graph
  44960. */
  44961. barHeight: 20,
  44962. /**
  44963. * **barGap** - the margin between the different activities in the gantt diagram
  44964. */
  44965. barGap: 4,
  44966. /**
  44967. * **topPadding** - margin between title and gantt diagram and between axis and gantt diagram.
  44968. */
  44969. topPadding: 50,
  44970. /**
  44971. * **leftPadding** - the space allocated for the section name to the left of the activities.
  44972. */
  44973. leftPadding: 75,
  44974. /**
  44975. * **gridLineStartPadding** - Vertical starting position of the grid lines
  44976. */
  44977. gridLineStartPadding: 35,
  44978. /**
  44979. * **fontSize** - font size ...
  44980. */
  44981. fontSize: 11,
  44982. /**
  44983. * **fontFamily** - font family ...
  44984. */
  44985. fontFamily: '"Open-Sans", "sans-serif"',
  44986. /**
  44987. * **numberSectionStyles** - the number of alternating section styles
  44988. */
  44989. numberSectionStyles: 3,
  44990. /**
  44991. * **axisFormatter** - formatting of the axis, this might need adjustment to match your locale and preferences
  44992. */
  44993. axisFormatter: [
  44994. // Within a day
  44995. ['%I:%M', function (d) {
  44996. return d.getHours();
  44997. }],
  44998. // Monday a week
  44999. ['w. %U', function (d) {
  45000. return d.getDay() == 1;
  45001. }],
  45002. // Day within a week (not monday)
  45003. ['%a %d', function (d) {
  45004. return d.getDay() && d.getDate() != 1;
  45005. }],
  45006. // within a month
  45007. ['%b %d', function (d) {
  45008. return d.getDate() != 1;
  45009. }],
  45010. // Month
  45011. ['%m-%y', function (d) {
  45012. return d.getMonth();
  45013. }]]
  45014. },
  45015. classDiagram: {},
  45016. gitGraph: {},
  45017. info: {}
  45018. };
  45019. Logger.setLogLevel(config.logLevel);
  45020. /**
  45021. * ## parse
  45022. * Function that parses a mermaid diagram definition. If parsing fails the parseError callback is called and an error is
  45023. * thrown and
  45024. * @param text
  45025. */
  45026. var parse = function parse(text) {
  45027. var graphType = utils.detectType(text);
  45028. var parser;
  45029. switch (graphType) {
  45030. case 'gitGraph':
  45031. parser = gitGraphParser;
  45032. parser.parser.yy = gitGraphAst;
  45033. break;
  45034. case 'graph':
  45035. parser = flowParser;
  45036. parser.parser.yy = graph;
  45037. break;
  45038. case 'dotGraph':
  45039. parser = dotParser;
  45040. parser.parser.yy = graph;
  45041. break;
  45042. case 'sequenceDiagram':
  45043. parser = sequenceParser;
  45044. parser.parser.yy = sequenceDb;
  45045. break;
  45046. case 'info':
  45047. parser = infoParser;
  45048. parser.parser.yy = infoDb;
  45049. break;
  45050. case 'gantt':
  45051. parser = ganttParser;
  45052. parser.parser.yy = ganttDb;
  45053. break;
  45054. case 'classDiagram':
  45055. parser = classParser;
  45056. parser.parser.yy = classDb;
  45057. break;
  45058. }
  45059. try {
  45060. parser.parse(text);
  45061. return true;
  45062. } catch (err) {
  45063. return false;
  45064. }
  45065. };
  45066. exports.parse = parse;
  45067. /**
  45068. * ## version
  45069. * Function returning version information
  45070. * @returns {string} A string containing the version info
  45071. */
  45072. exports.version = function () {
  45073. return require('../package.json').version;
  45074. };
  45075. exports.encodeEntities = function (text) {
  45076. var txt = text;
  45077. txt = txt.replace(/style.*:\S*#.*;/g, function (s) {
  45078. var innerTxt = s.substring(0, s.length - 1);
  45079. return innerTxt;
  45080. });
  45081. txt = txt.replace(/classDef.*:\S*#.*;/g, function (s) {
  45082. var innerTxt = s.substring(0, s.length - 1);
  45083. return innerTxt;
  45084. });
  45085. txt = txt.replace(/#\w+\;/g, function (s) {
  45086. var innerTxt = s.substring(1, s.length - 1);
  45087. var isInt = /^\+?\d+$/.test(innerTxt);
  45088. if (isInt) {
  45089. return 'fl°°' + innerTxt + '¶ß';
  45090. } else {
  45091. return 'fl°' + innerTxt + '¶ß';
  45092. }
  45093. });
  45094. return txt;
  45095. };
  45096. exports.decodeEntities = function (text) {
  45097. var txt = text;
  45098. txt = txt.replace(/\fl\°\°/g, function () {
  45099. return '&#';
  45100. });
  45101. txt = txt.replace(/\fl\°/g, function () {
  45102. return '&';
  45103. });
  45104. txt = txt.replace(/¶ß/g, function () {
  45105. return ';';
  45106. });
  45107. return txt;
  45108. };
  45109. /**
  45110. * ##render
  45111. * Function that renders an svg with a graph from a chart definition. Usage example below.
  45112. *
  45113. * ```
  45114. * mermaidAPI.initialize({
  45115. * startOnLoad:true
  45116. * });
  45117. * $(function(){
  45118. * var graphDefinition = 'graph TB\na-->b';
  45119. * var cb = function(svgGraph){
  45120. * console.log(svgGraph);
  45121. * };
  45122. * mermaidAPI.render('id1',graphDefinition,cb);
  45123. * });
  45124. *```
  45125. * @param id the id of the element to be rendered
  45126. * @param txt the graph definition
  45127. * @param cb callback which is called after rendering is finished with the svg code as inparam.
  45128. * @param container selector to element in which a div with the graph temporarily will be inserted. In one is
  45129. * provided a hidden div will be inserted in the body of the page instead. The element will be removed when rendering is
  45130. * completed.
  45131. */
  45132. var render = function render(id, txt, cb, container) {
  45133. if (typeof container !== 'undefined') {
  45134. container.innerHTML = '';
  45135. 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');
  45136. } else {
  45137. var element = document.querySelector('#' + 'd' + id);
  45138. if (element) {
  45139. element.innerHTML = '';
  45140. }
  45141. 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');
  45142. }
  45143. window.txt = txt;
  45144. txt = exports.encodeEntities(txt);
  45145. //console.warn('mermaid encode: ');
  45146. //console.warn(txt);
  45147. var element = d3.select('#d' + id).node();
  45148. var graphType = utils.detectType(txt);
  45149. var classes = {};
  45150. switch (graphType) {
  45151. case 'gitGraph':
  45152. config.flowchart.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
  45153. gitGraphRenderer.setConf(config.gitGraph);
  45154. gitGraphRenderer.draw(txt, id, false);
  45155. //if(config.cloneCssStyles){
  45156. //classes = gitGraphRenderer.getClasses(txt, false);
  45157. //utils.cloneCssStyles(element.firstChild, classes);
  45158. //}
  45159. break;
  45160. case 'graph':
  45161. config.flowchart.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
  45162. flowRenderer.setConf(config.flowchart);
  45163. flowRenderer.draw(txt, id, false);
  45164. if (config.cloneCssStyles) {
  45165. classes = flowRenderer.getClasses(txt, false);
  45166. utils.cloneCssStyles(element.firstChild, classes);
  45167. }
  45168. break;
  45169. case 'dotGraph':
  45170. config.flowchart.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
  45171. flowRenderer.setConf(config.flowchart);
  45172. flowRenderer.draw(txt, id, true);
  45173. if (config.cloneCssStyles) {
  45174. classes = flowRenderer.getClasses(txt, true);
  45175. utils.cloneCssStyles(element.firstChild, classes);
  45176. }
  45177. break;
  45178. case 'sequenceDiagram':
  45179. config.sequenceDiagram.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
  45180. seq.setConf(config.sequenceDiagram);
  45181. seq.draw(txt, id);
  45182. if (config.cloneCssStyles) {
  45183. utils.cloneCssStyles(element.firstChild, []);
  45184. }
  45185. break;
  45186. case 'gantt':
  45187. config.gantt.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
  45188. gantt.setConf(config.gantt);
  45189. gantt.draw(txt, id);
  45190. if (config.cloneCssStyles) {
  45191. utils.cloneCssStyles(element.firstChild, []);
  45192. }
  45193. break;
  45194. case 'classDiagram':
  45195. config.classDiagram.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
  45196. classRenderer.setConf(config.classDiagram);
  45197. classRenderer.draw(txt, id);
  45198. if (config.cloneCssStyles) {
  45199. utils.cloneCssStyles(element.firstChild, []);
  45200. }
  45201. break;
  45202. case 'info':
  45203. config.info.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
  45204. info.draw(txt, id, exports.version());
  45205. if (config.cloneCssStyles) {
  45206. utils.cloneCssStyles(element.firstChild, []);
  45207. }
  45208. break;
  45209. }
  45210. d3.select('#d' + id).selectAll('foreignobject div').attr('xmlns', 'http://www.w3.org/1999/xhtml');
  45211. var url = '';
  45212. if (config.arrowMarkerAbsolute) {
  45213. url = window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search;
  45214. url = url.replace(/\(/g, '\\(');
  45215. url = url.replace(/\)/g, '\\)');
  45216. }
  45217. // Fix for when the base tag is used
  45218. var svgCode = d3.select('#d' + id).node().innerHTML.replace(/url\(#arrowhead/g, 'url(' + url + '#arrowhead', 'g');
  45219. svgCode = exports.decodeEntities(svgCode);
  45220. //console.warn('mermaid decode: ');
  45221. //console.warn(svgCode);
  45222. //var he = require('he');
  45223. //svgCode = he.decode(svgCode);
  45224. if (typeof cb !== 'undefined') {
  45225. cb(svgCode, graph.bindFunctions);
  45226. } else {
  45227. log.warn('CB = undefined!');
  45228. }
  45229. var node = d3.select('#d' + id).node();
  45230. if (node !== null && typeof node.remove === 'function') {
  45231. d3.select('#d' + id).node().remove();
  45232. }
  45233. return svgCode;
  45234. };
  45235. exports.render = function (id, text, cb, containerElement) {
  45236. try {
  45237. if (arguments.length === 1) {
  45238. text = id;
  45239. id = 'mermaidId0';
  45240. }
  45241. if (typeof document === 'undefined') {
  45242. // Todo handle rendering serverside using phantomjs
  45243. } else {
  45244. // In browser
  45245. return render(id, text, cb, containerElement);
  45246. }
  45247. } catch (e) {
  45248. log.warn(e);
  45249. }
  45250. };
  45251. var setConf = function setConf(cnf) {
  45252. // Top level initially mermaid, gflow, sequenceDiagram and gantt
  45253. var lvl1Keys = Object.keys(cnf);
  45254. var i;
  45255. for (i = 0; i < lvl1Keys.length; i++) {
  45256. if (typeof cnf[lvl1Keys[i]] === 'object') {
  45257. var lvl2Keys = Object.keys(cnf[lvl1Keys[i]]);
  45258. var j;
  45259. for (j = 0; j < lvl2Keys.length; j++) {
  45260. log.debug('Setting conf ', lvl1Keys[i], '-', lvl2Keys[j]);
  45261. if (typeof config[lvl1Keys[i]] === 'undefined') {
  45262. config[lvl1Keys[i]] = {};
  45263. }
  45264. log.debug('Setting config: ' + lvl1Keys[i] + ' ' + lvl2Keys[j] + ' to ' + cnf[lvl1Keys[i]][lvl2Keys[j]]);
  45265. config[lvl1Keys[i]][lvl2Keys[j]] = cnf[lvl1Keys[i]][lvl2Keys[j]];
  45266. }
  45267. } else {
  45268. config[lvl1Keys[i]] = cnf[lvl1Keys[i]];
  45269. }
  45270. }
  45271. };
  45272. exports.initialize = function (options) {
  45273. log.debug('Initializing mermaidAPI');
  45274. // Update default config with options supplied at initialization
  45275. if (typeof options === 'object') {
  45276. setConf(options);
  45277. }
  45278. Logger.setLogLevel(config.logLevel);
  45279. };
  45280. exports.getConfig = function () {
  45281. return config;
  45282. };
  45283. exports.parseError = function (err, hash) {
  45284. if (typeof mermaid !== 'undefined') {
  45285. global.mermaid.parseError(err, hash);
  45286. } else {
  45287. log.debug('Mermaid Syntax error:');
  45288. log.debug(err);
  45289. }
  45290. };
  45291. global.mermaidAPI = {
  45292. render: exports.render,
  45293. parse: exports.parse,
  45294. initialize: exports.initialize,
  45295. detectType: utils.detectType,
  45296. parseError: exports.parseError,
  45297. getConfig: exports.getConfig
  45298. };
  45299. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  45300. },{"../package.json":107,"./d3":108,"./diagrams/classDiagram/classDb":109,"./diagrams/classDiagram/classRenderer":110,"./diagrams/classDiagram/parser/classDiagram":111,"./diagrams/example/exampleDb":112,"./diagrams/example/exampleRenderer":113,"./diagrams/example/parser/example":114,"./diagrams/flowchart/flowRenderer":116,"./diagrams/flowchart/graphDb":117,"./diagrams/flowchart/parser/dot":118,"./diagrams/flowchart/parser/flow":119,"./diagrams/gantt/ganttDb":120,"./diagrams/gantt/ganttRenderer":121,"./diagrams/gantt/parser/gantt":122,"./diagrams/gitGraph/gitGraphAst":123,"./diagrams/gitGraph/gitGraphRenderer":124,"./diagrams/gitGraph/parser/gitGraph":125,"./diagrams/sequenceDiagram/parser/sequenceDiagram":126,"./diagrams/sequenceDiagram/sequenceDb":127,"./diagrams/sequenceDiagram/sequenceRenderer":128,"./logger":130,"./utils":133}],133:[function(require,module,exports){
  45301. /**
  45302. * Created by knut on 14-11-23.
  45303. */
  45304. 'use strict';
  45305. var Logger = require('./logger');
  45306. var log = new Logger.Log();
  45307. /**
  45308. * @function detectType
  45309. * Detects the type of the graph text.
  45310. * ```mermaid
  45311. * graph LR
  45312. * a-->b
  45313. * b-->c
  45314. * c-->d
  45315. * d-->e
  45316. * e-->f
  45317. * f-->g
  45318. * g-->h
  45319. * ```
  45320. *
  45321. * @param {string} text The text defining the graph
  45322. * @returns {string} A graph definition key
  45323. */
  45324. var detectType = function detectType(text) {
  45325. text = text.replace(/^\s*%%.*\n/g, '\n');
  45326. if (text.match(/^\s*sequenceDiagram/)) {
  45327. return 'sequenceDiagram';
  45328. }
  45329. if (text.match(/^\s*digraph/)) {
  45330. //log.debug('Detected dot syntax');
  45331. return 'dotGraph';
  45332. }
  45333. if (text.match(/^\s*info/)) {
  45334. //log.debug('Detected info syntax');
  45335. return 'info';
  45336. }
  45337. if (text.match(/^\s*gantt/)) {
  45338. //log.debug('Detected info syntax');
  45339. return 'gantt';
  45340. }
  45341. if (text.match(/^\s*classDiagram/)) {
  45342. log.debug('Detected classDiagram syntax');
  45343. return 'classDiagram';
  45344. }
  45345. if (text.match(/^\s*gitGraph/)) {
  45346. log.debug('Detected gitGraph syntax');
  45347. return 'gitGraph';
  45348. }
  45349. return 'graph';
  45350. };
  45351. exports.detectType = detectType;
  45352. /**
  45353. * Copies all relevant CSS content into the graph SVG.
  45354. * This allows the SVG to be copied as is while keeping class based styling
  45355. * @param {element} svg The root element of the SVG
  45356. * @param {object} Hash table of class definitions from the graph definition
  45357. */
  45358. var cloneCssStyles = function cloneCssStyles(svg, classes) {
  45359. var usedStyles = '';
  45360. var sheets = document.styleSheets;
  45361. var rule;
  45362. for (var i = 0; i < sheets.length; i++) {
  45363. // Avoid multiple inclusion on pages with multiple graphs
  45364. if (sheets[i].title !== 'mermaid-svg-internal-css') {
  45365. try {
  45366. var rules = sheets[i].cssRules;
  45367. if (rules !== null) {
  45368. for (var j = 0; j < rules.length; j++) {
  45369. rule = rules[j];
  45370. if (typeof rule.style !== 'undefined') {
  45371. var elems;
  45372. elems = svg.querySelectorAll(rule.selectorText);
  45373. if (elems.length > 0) {
  45374. usedStyles += rule.selectorText + ' { ' + rule.style.cssText + '}\n';
  45375. }
  45376. }
  45377. }
  45378. }
  45379. } catch (err) {
  45380. if (typeof rule !== 'undefined') {
  45381. log.warn('Invalid CSS selector "' + rule.selectorText + '"', err);
  45382. }
  45383. }
  45384. }
  45385. }
  45386. var defaultStyles = '';
  45387. var embeddedStyles = '';
  45388. for (var className in classes) {
  45389. if (classes.hasOwnProperty(className) && typeof className != 'undefined') {
  45390. if (className === 'default') {
  45391. if (classes['default'].styles instanceof Array) {
  45392. defaultStyles += '#' + svg.id.trim() + ' .node' + '>rect { ' + classes[className].styles.join('; ') + '; }\n';
  45393. }
  45394. if (classes['default'].nodeLabelStyles instanceof Array) {
  45395. defaultStyles += '#' + svg.id.trim() + ' .node text ' + ' { ' + classes[className].nodeLabelStyles.join('; ') + '; }\n';
  45396. }
  45397. if (classes['default'].edgeLabelStyles instanceof Array) {
  45398. defaultStyles += '#' + svg.id.trim() + ' .edgeLabel text ' + ' { ' + classes[className].edgeLabelStyles.join('; ') + '; }\n';
  45399. }
  45400. if (classes['default'].clusterStyles instanceof Array) {
  45401. defaultStyles += '#' + svg.id.trim() + ' .cluster rect ' + ' { ' + classes[className].clusterStyles.join('; ') + '; }\n';
  45402. }
  45403. } else {
  45404. if (classes[className].styles instanceof Array) {
  45405. embeddedStyles += '#' + svg.id.trim() + ' .' + className + '>rect, .' + className + '>polygon, .' + className + '>circle, .' + className + '>ellipse { ' + classes[className].styles.join('; ') + '; }\n';
  45406. }
  45407. }
  45408. }
  45409. }
  45410. if (usedStyles !== '' || defaultStyles !== '' || embeddedStyles !== '') {
  45411. var s = document.createElement('style');
  45412. s.setAttribute('type', 'text/css');
  45413. s.setAttribute('title', 'mermaid-svg-internal-css');
  45414. s.innerHTML = '/* <![CDATA[ */\n';
  45415. // Make this CSS local to this SVG
  45416. if (defaultStyles !== '') {
  45417. s.innerHTML += defaultStyles;
  45418. }
  45419. if (usedStyles !== '') {
  45420. s.innerHTML += usedStyles;
  45421. }
  45422. if (embeddedStyles !== '') {
  45423. s.innerHTML += embeddedStyles;
  45424. }
  45425. s.innerHTML += '/* ]]> */\n';
  45426. svg.insertBefore(s, svg.firstChild);
  45427. }
  45428. };
  45429. exports.cloneCssStyles = cloneCssStyles;
  45430. /**
  45431. * @function isSubstringInArray
  45432. * Detects whether a substring in present in a given array
  45433. * @param {string} str The substring to detect
  45434. * @param {array} arr The array to search
  45435. * @returns {number} the array index containing the substring or -1 if not present
  45436. **/
  45437. var isSubstringInArray = function isSubstringInArray(str, arr) {
  45438. for (var i = 0; i < arr.length; i++) {
  45439. if (arr[i].match(str)) return i;
  45440. }
  45441. return -1;
  45442. };
  45443. exports.isSubstringInArray = isSubstringInArray;
  45444. },{"./logger":130}]},{},[131])(131)
  45445. });