lodash3.3.0.js 374 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421
  1. /**
  2. * @license
  3. * lodash 3.3.0 (Custom Build) <https://lodash.com/>
  4. * Build: `lodash modern -o ./lodash.js`
  5. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  6. * Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
  7. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  8. * Available under MIT license <https://lodash.com/license>
  9. */
  10. ;(function() {
  11. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  12. var undefined;
  13. /** Used as the semantic version number. */
  14. var VERSION = '3.3.0';
  15. /** Used to compose bitmasks for wrapper metadata. */
  16. var BIND_FLAG = 1,
  17. BIND_KEY_FLAG = 2,
  18. CURRY_BOUND_FLAG = 4,
  19. CURRY_FLAG = 8,
  20. CURRY_RIGHT_FLAG = 16,
  21. PARTIAL_FLAG = 32,
  22. PARTIAL_RIGHT_FLAG = 64,
  23. REARG_FLAG = 128,
  24. ARY_FLAG = 256;
  25. /** Used as default options for `_.trunc`. */
  26. var DEFAULT_TRUNC_LENGTH = 30,
  27. DEFAULT_TRUNC_OMISSION = '...';
  28. /** Used to detect when a function becomes hot. */
  29. var HOT_COUNT = 150,
  30. HOT_SPAN = 16;
  31. /** Used to indicate the type of lazy iteratees. */
  32. var LAZY_FILTER_FLAG = 0,
  33. LAZY_MAP_FLAG = 1,
  34. LAZY_WHILE_FLAG = 2;
  35. /** Used as the `TypeError` message for "Functions" methods. */
  36. var FUNC_ERROR_TEXT = 'Expected a function';
  37. /** Used as the internal argument placeholder. */
  38. var PLACEHOLDER = '__lodash_placeholder__';
  39. /** `Object#toString` result references. */
  40. var argsTag = '[object Arguments]',
  41. arrayTag = '[object Array]',
  42. boolTag = '[object Boolean]',
  43. dateTag = '[object Date]',
  44. errorTag = '[object Error]',
  45. funcTag = '[object Function]',
  46. mapTag = '[object Map]',
  47. numberTag = '[object Number]',
  48. objectTag = '[object Object]',
  49. regexpTag = '[object RegExp]',
  50. setTag = '[object Set]',
  51. stringTag = '[object String]',
  52. weakMapTag = '[object WeakMap]';
  53. var arrayBufferTag = '[object ArrayBuffer]',
  54. float32Tag = '[object Float32Array]',
  55. float64Tag = '[object Float64Array]',
  56. int8Tag = '[object Int8Array]',
  57. int16Tag = '[object Int16Array]',
  58. int32Tag = '[object Int32Array]',
  59. uint8Tag = '[object Uint8Array]',
  60. uint8ClampedTag = '[object Uint8ClampedArray]',
  61. uint16Tag = '[object Uint16Array]',
  62. uint32Tag = '[object Uint32Array]';
  63. /** Used to match empty string literals in compiled template source. */
  64. var reEmptyStringLeading = /\b__p \+= '';/g,
  65. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  66. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  67. /** Used to match HTML entities and HTML characters. */
  68. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
  69. reUnescapedHtml = /[&<>"'`]/g,
  70. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  71. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  72. /** Used to match template delimiters. */
  73. var reEscape = /<%-([\s\S]+?)%>/g,
  74. reEvaluate = /<%([\s\S]+?)%>/g,
  75. reInterpolate = /<%=([\s\S]+?)%>/g;
  76. /**
  77. * Used to match ES template delimiters.
  78. * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components)
  79. * for more details.
  80. */
  81. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  82. /** Used to match `RegExp` flags from their coerced string values. */
  83. var reFlags = /\w*$/;
  84. /** Used to detect named functions. */
  85. var reFuncName = /^\s*function[ \n\r\t]+\w/;
  86. /** Used to detect hexadecimal string values. */
  87. var reHexPrefix = /^0[xX]/;
  88. /** Used to detect host constructors (Safari > 5). */
  89. var reHostCtor = /^\[object .+?Constructor\]$/;
  90. /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
  91. var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
  92. /** Used to ensure capturing order of template delimiters. */
  93. var reNoMatch = /($^)/;
  94. /**
  95. * Used to match `RegExp` special characters.
  96. * See this [article on `RegExp` characters](http://www.regular-expressions.info/characters.html#special)
  97. * for more details.
  98. */
  99. var reRegExpChars = /[.*+?^${}()|[\]\/\\]/g,
  100. reHasRegExpChars = RegExp(reRegExpChars.source);
  101. /** Used to detect functions containing a `this` reference. */
  102. var reThis = /\bthis\b/;
  103. /** Used to match unescaped characters in compiled string literals. */
  104. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  105. /** Used to match words to create compound words. */
  106. var reWords = (function() {
  107. var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]',
  108. lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
  109. return RegExp(upper + '{2,}(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
  110. }());
  111. /** Used to detect and test for whitespace. */
  112. var whitespace = (
  113. // Basic whitespace characters.
  114. ' \t\x0b\f\xa0\ufeff' +
  115. // Line terminators.
  116. '\n\r\u2028\u2029' +
  117. // Unicode category "Zs" space separators.
  118. '\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000'
  119. );
  120. /** Used to assign default `context` object properties. */
  121. var contextProps = [
  122. 'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
  123. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number',
  124. 'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'document',
  125. 'isFinite', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array',
  126. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  127. 'window', 'WinRTError'
  128. ];
  129. /** Used to make template sourceURLs easier to identify. */
  130. var templateCounter = -1;
  131. /** Used to identify `toStringTag` values of typed arrays. */
  132. var typedArrayTags = {};
  133. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  134. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  135. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  136. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  137. typedArrayTags[uint32Tag] = true;
  138. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  139. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  140. typedArrayTags[dateTag] = typedArrayTags[errorTag] =
  141. typedArrayTags[funcTag] = typedArrayTags[mapTag] =
  142. typedArrayTags[numberTag] = typedArrayTags[objectTag] =
  143. typedArrayTags[regexpTag] = typedArrayTags[setTag] =
  144. typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
  145. /** Used to identify `toStringTag` values supported by `_.clone`. */
  146. var cloneableTags = {};
  147. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  148. cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
  149. cloneableTags[dateTag] = cloneableTags[float32Tag] =
  150. cloneableTags[float64Tag] = cloneableTags[int8Tag] =
  151. cloneableTags[int16Tag] = cloneableTags[int32Tag] =
  152. cloneableTags[numberTag] = cloneableTags[objectTag] =
  153. cloneableTags[regexpTag] = cloneableTags[stringTag] =
  154. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  155. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  156. cloneableTags[errorTag] = cloneableTags[funcTag] =
  157. cloneableTags[mapTag] = cloneableTags[setTag] =
  158. cloneableTags[weakMapTag] = false;
  159. /** Used as an internal `_.debounce` options object by `_.throttle`. */
  160. var debounceOptions = {
  161. 'leading': false,
  162. 'maxWait': 0,
  163. 'trailing': false
  164. };
  165. /** Used to map latin-1 supplementary letters to basic latin letters. */
  166. var deburredLetters = {
  167. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  168. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  169. '\xc7': 'C', '\xe7': 'c',
  170. '\xd0': 'D', '\xf0': 'd',
  171. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  172. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  173. '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  174. '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  175. '\xd1': 'N', '\xf1': 'n',
  176. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  177. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  178. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  179. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  180. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  181. '\xc6': 'Ae', '\xe6': 'ae',
  182. '\xde': 'Th', '\xfe': 'th',
  183. '\xdf': 'ss'
  184. };
  185. /** Used to map characters to HTML entities. */
  186. var htmlEscapes = {
  187. '&': '&amp;',
  188. '<': '&lt;',
  189. '>': '&gt;',
  190. '"': '&quot;',
  191. "'": '&#39;',
  192. '`': '&#96;'
  193. };
  194. /** Used to map HTML entities to characters. */
  195. var htmlUnescapes = {
  196. '&amp;': '&',
  197. '&lt;': '<',
  198. '&gt;': '>',
  199. '&quot;': '"',
  200. '&#39;': "'",
  201. '&#96;': '`'
  202. };
  203. /** Used to determine if values are of the language type `Object`. */
  204. var objectTypes = {
  205. 'function': true,
  206. 'object': true
  207. };
  208. /** Used to escape characters for inclusion in compiled string literals. */
  209. var stringEscapes = {
  210. '\\': '\\',
  211. "'": "'",
  212. '\n': 'n',
  213. '\r': 'r',
  214. '\u2028': 'u2028',
  215. '\u2029': 'u2029'
  216. };
  217. /**
  218. * Used as a reference to the global object.
  219. *
  220. * The `this` value is used if it is the global object to avoid Greasemonkey's
  221. * restricted `window` object, otherwise the `window` object is used.
  222. */
  223. var root = (objectTypes[typeof window] && window !== (this && this.window)) ? window : this;
  224. /** Detect free variable `exports`. */
  225. var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
  226. /** Detect free variable `module`. */
  227. var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
  228. /** Detect free variable `global` from Node.js or Browserified code and use it as `root`. */
  229. var freeGlobal = freeExports && freeModule && typeof global == 'object' && global;
  230. if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
  231. root = freeGlobal;
  232. }
  233. /** Detect the popular CommonJS extension `module.exports`. */
  234. var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
  235. /*--------------------------------------------------------------------------*/
  236. /**
  237. * The base implementation of `compareAscending` which compares values and
  238. * sorts them in ascending order without guaranteeing a stable sort.
  239. *
  240. * @private
  241. * @param {*} value The value to compare to `other`.
  242. * @param {*} other The value to compare to `value`.
  243. * @returns {number} Returns the sort order indicator for `value`.
  244. */
  245. function baseCompareAscending(value, other) {
  246. if (value !== other) {
  247. var valIsReflexive = value === value,
  248. othIsReflexive = other === other;
  249. if (value > other || !valIsReflexive || (typeof value == 'undefined' && othIsReflexive)) {
  250. return 1;
  251. }
  252. if (value < other || !othIsReflexive || (typeof other == 'undefined' && valIsReflexive)) {
  253. return -1;
  254. }
  255. }
  256. return 0;
  257. }
  258. /**
  259. * The base implementation of `_.indexOf` without support for binary searches.
  260. *
  261. * @private
  262. * @param {Array} array The array to search.
  263. * @param {*} value The value to search for.
  264. * @param {number} [fromIndex=0] The index to search from.
  265. * @returns {number} Returns the index of the matched value, else `-1`.
  266. */
  267. function baseIndexOf(array, value, fromIndex) {
  268. if (value !== value) {
  269. return indexOfNaN(array, fromIndex);
  270. }
  271. var index = (fromIndex || 0) - 1,
  272. length = array.length;
  273. while (++index < length) {
  274. if (array[index] === value) {
  275. return index;
  276. }
  277. }
  278. return -1;
  279. }
  280. /**
  281. * The base implementation of `_.isFunction` without support for environments
  282. * with incorrect `typeof` results.
  283. *
  284. * @private
  285. * @param {*} value The value to check.
  286. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  287. */
  288. function baseIsFunction(value) {
  289. // Avoid a Chakra JIT bug in compatibility modes of IE 11.
  290. // See https://github.com/jashkenas/underscore/issues/1621 for more details.
  291. return typeof value == 'function' || false;
  292. }
  293. /**
  294. * The base implementation of `_.sortBy` and `_.sortByAll` which uses `comparer`
  295. * to define the sort order of `array` and replaces criteria objects with their
  296. * corresponding values.
  297. *
  298. * @private
  299. * @param {Array} array The array to sort.
  300. * @param {Function} comparer The function to define sort order.
  301. * @returns {Array} Returns `array`.
  302. */
  303. function baseSortBy(array, comparer) {
  304. var length = array.length;
  305. array.sort(comparer);
  306. while (length--) {
  307. array[length] = array[length].value;
  308. }
  309. return array;
  310. }
  311. /**
  312. * Converts `value` to a string if it is not one. An empty string is returned
  313. * for `null` or `undefined` values.
  314. *
  315. * @private
  316. * @param {*} value The value to process.
  317. * @returns {string} Returns the string.
  318. */
  319. function baseToString(value) {
  320. if (typeof value == 'string') {
  321. return value;
  322. }
  323. return value == null ? '' : (value + '');
  324. }
  325. /**
  326. * Used by `_.max` and `_.min` as the default callback for string values.
  327. *
  328. * @private
  329. * @param {string} string The string to inspect.
  330. * @returns {number} Returns the code unit of the first character of the string.
  331. */
  332. function charAtCallback(string) {
  333. return string.charCodeAt(0);
  334. }
  335. /**
  336. * Used by `_.trim` and `_.trimLeft` to get the index of the first character
  337. * of `string` that is not found in `chars`.
  338. *
  339. * @private
  340. * @param {string} string The string to inspect.
  341. * @param {string} chars The characters to find.
  342. * @returns {number} Returns the index of the first character not found in `chars`.
  343. */
  344. function charsLeftIndex(string, chars) {
  345. var index = -1,
  346. length = string.length;
  347. while (++index < length && chars.indexOf(string.charAt(index)) > -1) {}
  348. return index;
  349. }
  350. /**
  351. * Used by `_.trim` and `_.trimRight` to get the index of the last character
  352. * of `string` that is not found in `chars`.
  353. *
  354. * @private
  355. * @param {string} string The string to inspect.
  356. * @param {string} chars The characters to find.
  357. * @returns {number} Returns the index of the last character not found in `chars`.
  358. */
  359. function charsRightIndex(string, chars) {
  360. var index = string.length;
  361. while (index-- && chars.indexOf(string.charAt(index)) > -1) {}
  362. return index;
  363. }
  364. /**
  365. * Used by `_.sortBy` to compare transformed elements of a collection and stable
  366. * sort them in ascending order.
  367. *
  368. * @private
  369. * @param {Object} object The object to compare to `other`.
  370. * @param {Object} other The object to compare to `object`.
  371. * @returns {number} Returns the sort order indicator for `object`.
  372. */
  373. function compareAscending(object, other) {
  374. return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index);
  375. }
  376. /**
  377. * Used by `_.sortByAll` to compare multiple properties of each element
  378. * in a collection and stable sort them in ascending order.
  379. *
  380. * @private
  381. * @param {Object} object The object to compare to `other`.
  382. * @param {Object} other The object to compare to `object`.
  383. * @returns {number} Returns the sort order indicator for `object`.
  384. */
  385. function compareMultipleAscending(object, other) {
  386. var index = -1,
  387. objCriteria = object.criteria,
  388. othCriteria = other.criteria,
  389. length = objCriteria.length;
  390. while (++index < length) {
  391. var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
  392. if (result) {
  393. return result;
  394. }
  395. }
  396. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  397. // that causes it, under certain circumstances, to provide the same value for
  398. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  399. // for more details.
  400. //
  401. // This also ensures a stable sort in V8 and other engines.
  402. // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
  403. return object.index - other.index;
  404. }
  405. /**
  406. * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
  407. *
  408. * @private
  409. * @param {string} letter The matched letter to deburr.
  410. * @returns {string} Returns the deburred letter.
  411. */
  412. function deburrLetter(letter) {
  413. return deburredLetters[letter];
  414. }
  415. /**
  416. * Used by `_.escape` to convert characters to HTML entities.
  417. *
  418. * @private
  419. * @param {string} chr The matched character to escape.
  420. * @returns {string} Returns the escaped character.
  421. */
  422. function escapeHtmlChar(chr) {
  423. return htmlEscapes[chr];
  424. }
  425. /**
  426. * Used by `_.template` to escape characters for inclusion in compiled
  427. * string literals.
  428. *
  429. * @private
  430. * @param {string} chr The matched character to escape.
  431. * @returns {string} Returns the escaped character.
  432. */
  433. function escapeStringChar(chr) {
  434. return '\\' + stringEscapes[chr];
  435. }
  436. /**
  437. * Gets the index at which the first occurrence of `NaN` is found in `array`.
  438. * If `fromRight` is provided elements of `array` are iterated from right to left.
  439. *
  440. * @private
  441. * @param {Array} array The array to search.
  442. * @param {number} [fromIndex] The index to search from.
  443. * @param {boolean} [fromRight] Specify iterating from right to left.
  444. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
  445. */
  446. function indexOfNaN(array, fromIndex, fromRight) {
  447. var length = array.length,
  448. index = fromRight ? (fromIndex || length) : ((fromIndex || 0) - 1);
  449. while ((fromRight ? index-- : ++index < length)) {
  450. var other = array[index];
  451. if (other !== other) {
  452. return index;
  453. }
  454. }
  455. return -1;
  456. }
  457. /**
  458. * Checks if `value` is object-like.
  459. *
  460. * @private
  461. * @param {*} value The value to check.
  462. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  463. */
  464. function isObjectLike(value) {
  465. return (value && typeof value == 'object') || false;
  466. }
  467. /**
  468. * Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
  469. * character code is whitespace.
  470. *
  471. * @private
  472. * @param {number} charCode The character code to inspect.
  473. * @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
  474. */
  475. function isSpace(charCode) {
  476. return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 ||
  477. (charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279)));
  478. }
  479. /**
  480. * Replaces all `placeholder` elements in `array` with an internal placeholder
  481. * and returns an array of their indexes.
  482. *
  483. * @private
  484. * @param {Array} array The array to modify.
  485. * @param {*} placeholder The placeholder to replace.
  486. * @returns {Array} Returns the new array of placeholder indexes.
  487. */
  488. function replaceHolders(array, placeholder) {
  489. var index = -1,
  490. length = array.length,
  491. resIndex = -1,
  492. result = [];
  493. while (++index < length) {
  494. if (array[index] === placeholder) {
  495. array[index] = PLACEHOLDER;
  496. result[++resIndex] = index;
  497. }
  498. }
  499. return result;
  500. }
  501. /**
  502. * An implementation of `_.uniq` optimized for sorted arrays without support
  503. * for callback shorthands and `this` binding.
  504. *
  505. * @private
  506. * @param {Array} array The array to inspect.
  507. * @param {Function} [iteratee] The function invoked per iteration.
  508. * @returns {Array} Returns the new duplicate-value-free array.
  509. */
  510. function sortedUniq(array, iteratee) {
  511. var seen,
  512. index = -1,
  513. length = array.length,
  514. resIndex = -1,
  515. result = [];
  516. while (++index < length) {
  517. var value = array[index],
  518. computed = iteratee ? iteratee(value, index, array) : value;
  519. if (!index || seen !== computed) {
  520. seen = computed;
  521. result[++resIndex] = value;
  522. }
  523. }
  524. return result;
  525. }
  526. /**
  527. * Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
  528. * character of `string`.
  529. *
  530. * @private
  531. * @param {string} string The string to inspect.
  532. * @returns {number} Returns the index of the first non-whitespace character.
  533. */
  534. function trimmedLeftIndex(string) {
  535. var index = -1,
  536. length = string.length;
  537. while (++index < length && isSpace(string.charCodeAt(index))) {}
  538. return index;
  539. }
  540. /**
  541. * Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
  542. * character of `string`.
  543. *
  544. * @private
  545. * @param {string} string The string to inspect.
  546. * @returns {number} Returns the index of the last non-whitespace character.
  547. */
  548. function trimmedRightIndex(string) {
  549. var index = string.length;
  550. while (index-- && isSpace(string.charCodeAt(index))) {}
  551. return index;
  552. }
  553. /**
  554. * Used by `_.unescape` to convert HTML entities to characters.
  555. *
  556. * @private
  557. * @param {string} chr The matched character to unescape.
  558. * @returns {string} Returns the unescaped character.
  559. */
  560. function unescapeHtmlChar(chr) {
  561. return htmlUnescapes[chr];
  562. }
  563. /*--------------------------------------------------------------------------*/
  564. /**
  565. * Create a new pristine `lodash` function using the given `context` object.
  566. *
  567. * @static
  568. * @memberOf _
  569. * @category Utility
  570. * @param {Object} [context=root] The context object.
  571. * @returns {Function} Returns a new `lodash` function.
  572. * @example
  573. *
  574. * _.mixin({ 'add': function(a, b) { return a + b; } });
  575. *
  576. * var lodash = _.runInContext();
  577. * lodash.mixin({ 'sub': function(a, b) { return a - b; } });
  578. *
  579. * _.isFunction(_.add);
  580. * // => true
  581. * _.isFunction(_.sub);
  582. * // => false
  583. *
  584. * lodash.isFunction(lodash.add);
  585. * // => false
  586. * lodash.isFunction(lodash.sub);
  587. * // => true
  588. *
  589. * // using `context` to mock `Date#getTime` use in `_.now`
  590. * var mock = _.runInContext({
  591. * 'Date': function() {
  592. * return { 'getTime': getTimeMock };
  593. * }
  594. * });
  595. *
  596. * // or creating a suped-up `defer` in Node.js
  597. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  598. */
  599. function runInContext(context) {
  600. // Avoid issues with some ES3 environments that attempt to use values, named
  601. // after built-in constructors like `Object`, for the creation of literals.
  602. // ES5 clears this up by stating that literals must use built-in constructors.
  603. // See https://es5.github.io/#x11.1.5 for more details.
  604. context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
  605. /** Native constructor references. */
  606. var Array = context.Array,
  607. Date = context.Date,
  608. Error = context.Error,
  609. Function = context.Function,
  610. Math = context.Math,
  611. Number = context.Number,
  612. Object = context.Object,
  613. RegExp = context.RegExp,
  614. String = context.String,
  615. TypeError = context.TypeError;
  616. /** Used for native method references. */
  617. var arrayProto = Array.prototype,
  618. objectProto = Object.prototype;
  619. /** Used to detect DOM support. */
  620. var document = (document = context.window) && document.document;
  621. /** Used to resolve the decompiled source of functions. */
  622. var fnToString = Function.prototype.toString;
  623. /** Used to the length of n-tuples for `_.unzip`. */
  624. var getLength = baseProperty('length');
  625. /** Used to check objects for own properties. */
  626. var hasOwnProperty = objectProto.hasOwnProperty;
  627. /** Used to generate unique IDs. */
  628. var idCounter = 0;
  629. /**
  630. * Used to resolve the `toStringTag` of values.
  631. * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
  632. * for more details.
  633. */
  634. var objToString = objectProto.toString;
  635. /** Used to restore the original `_` reference in `_.noConflict`. */
  636. var oldDash = context._;
  637. /** Used to detect if a method is native. */
  638. var reNative = RegExp('^' +
  639. escapeRegExp(objToString)
  640. .replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  641. );
  642. /** Native method references. */
  643. var ArrayBuffer = isNative(ArrayBuffer = context.ArrayBuffer) && ArrayBuffer,
  644. bufferSlice = isNative(bufferSlice = ArrayBuffer && new ArrayBuffer(0).slice) && bufferSlice,
  645. ceil = Math.ceil,
  646. clearTimeout = context.clearTimeout,
  647. floor = Math.floor,
  648. getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
  649. push = arrayProto.push,
  650. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  651. Set = isNative(Set = context.Set) && Set,
  652. setTimeout = context.setTimeout,
  653. splice = arrayProto.splice,
  654. Uint8Array = isNative(Uint8Array = context.Uint8Array) && Uint8Array,
  655. WeakMap = isNative(WeakMap = context.WeakMap) && WeakMap;
  656. /** Used to clone array buffers. */
  657. var Float64Array = (function() {
  658. // Safari 5 errors when using an array buffer to initialize a typed array
  659. // where the array buffer's `byteLength` is not a multiple of the typed
  660. // array's `BYTES_PER_ELEMENT`.
  661. try {
  662. var func = isNative(func = context.Float64Array) && func,
  663. result = new func(new ArrayBuffer(10), 0, 1) && func;
  664. } catch(e) {}
  665. return result;
  666. }());
  667. /* Native method references for those with the same name as other `lodash` methods. */
  668. var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray,
  669. nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate,
  670. nativeIsFinite = context.isFinite,
  671. nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys,
  672. nativeMax = Math.max,
  673. nativeMin = Math.min,
  674. nativeNow = isNative(nativeNow = Date.now) && nativeNow,
  675. nativeNumIsFinite = isNative(nativeNumIsFinite = Number.isFinite) && nativeNumIsFinite,
  676. nativeParseInt = context.parseInt,
  677. nativeRandom = Math.random;
  678. /** Used as references for `-Infinity` and `Infinity`. */
  679. var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
  680. POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
  681. /** Used as references for the maximum length and index of an array. */
  682. var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
  683. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  684. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  685. /** Used as the size, in bytes, of each `Float64Array` element. */
  686. var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT : 0;
  687. /**
  688. * Used as the maximum length of an array-like value.
  689. * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
  690. * for more details.
  691. */
  692. var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
  693. /** Used to store function metadata. */
  694. var metaMap = WeakMap && new WeakMap;
  695. /*------------------------------------------------------------------------*/
  696. /**
  697. * Creates a `lodash` object which wraps `value` to enable implicit chaining.
  698. * Methods that operate on and return arrays, collections, and functions can
  699. * be chained together. Methods that return a boolean or single value will
  700. * automatically end the chain returning the unwrapped value. Explicit chaining
  701. * may be enabled using `_.chain`. The execution of chained methods is lazy,
  702. * that is, execution is deferred until `_#value` is implicitly or explicitly
  703. * called.
  704. *
  705. * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
  706. * fusion is an optimization that merges iteratees to avoid creating intermediate
  707. * arrays and reduce the number of iteratee executions.
  708. *
  709. * Chaining is supported in custom builds as long as the `_#value` method is
  710. * directly or indirectly included in the build.
  711. *
  712. * In addition to lodash methods, wrappers also have the following `Array` methods:
  713. * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
  714. * and `unshift`
  715. *
  716. * The wrapper methods that support shortcut fusion are:
  717. * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
  718. * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
  719. * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
  720. * and `where`
  721. *
  722. * The chainable wrapper methods are:
  723. * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
  724. * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
  725. * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`,
  726. * `difference`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `fill`,
  727. * `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`,
  728. * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`,
  729. * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`,
  730. * `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`,
  731. * `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
  732. * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
  733. * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
  734. * `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `splice`, `spread`,
  735. * `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`,
  736. * `thru`, `times`, `toArray`, `toPlainObject`, `transform`, `union`, `uniq`,
  737. * `unshift`, `unzip`, `values`, `valuesIn`, `where`, `without`, `wrap`, `xor`,
  738. * `zip`, and `zipObject`
  739. *
  740. * The wrapper methods that are **not** chainable by default are:
  741. * `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
  742. * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
  743. * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
  744. * `identity`, `includes`, `indexOf`, `isArguments`, `isArray`, `isBoolean`,
  745. * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`,
  746. * `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
  747. * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
  748. * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
  749. * `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
  750. * `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
  751. * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
  752. * `startCase`, `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`,
  753. * `trunc`, `unescape`, `uniqueId`, `value`, and `words`
  754. *
  755. * The wrapper method `sample` will return a wrapped value when `n` is provided,
  756. * otherwise an unwrapped value is returned.
  757. *
  758. * @name _
  759. * @constructor
  760. * @category Chain
  761. * @param {*} value The value to wrap in a `lodash` instance.
  762. * @returns {Object} Returns the new `lodash` wrapper instance.
  763. * @example
  764. *
  765. * var wrapped = _([1, 2, 3]);
  766. *
  767. * // returns an unwrapped value
  768. * wrapped.reduce(function(sum, n) {
  769. * return sum + n;
  770. * });
  771. * // => 6
  772. *
  773. * // returns a wrapped value
  774. * var squares = wrapped.map(function(n) {
  775. * return n * n;
  776. * });
  777. *
  778. * _.isArray(squares);
  779. * // => false
  780. *
  781. * _.isArray(squares.value());
  782. * // => true
  783. */
  784. function lodash(value) {
  785. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  786. if (value instanceof LodashWrapper) {
  787. return value;
  788. }
  789. if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
  790. return wrapperClone(value);
  791. }
  792. }
  793. return new LodashWrapper(value);
  794. }
  795. /**
  796. * The function whose prototype all chaining wrappers inherit from.
  797. *
  798. * @private
  799. */
  800. function baseLodash() {
  801. // No operation performed.
  802. }
  803. /**
  804. * The base constructor for creating `lodash` wrapper objects.
  805. *
  806. * @private
  807. * @param {*} value The value to wrap.
  808. * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
  809. * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
  810. */
  811. function LodashWrapper(value, chainAll, actions) {
  812. this.__wrapped__ = value;
  813. this.__actions__ = actions || [];
  814. this.__chain__ = !!chainAll;
  815. }
  816. /**
  817. * An object environment feature flags.
  818. *
  819. * @static
  820. * @memberOf _
  821. * @type Object
  822. */
  823. var support = lodash.support = {};
  824. (function(x) {
  825. /**
  826. * Detect if functions can be decompiled by `Function#toString`
  827. * (all but Firefox OS certified apps, older Opera mobile browsers, and
  828. * the PlayStation 3; forced `false` for Windows 8 apps).
  829. *
  830. * @memberOf _.support
  831. * @type boolean
  832. */
  833. support.funcDecomp = !isNative(context.WinRTError) && reThis.test(runInContext);
  834. /**
  835. * Detect if `Function#name` is supported (all but IE).
  836. *
  837. * @memberOf _.support
  838. * @type boolean
  839. */
  840. support.funcNames = typeof Function.name == 'string';
  841. /**
  842. * Detect if the DOM is supported.
  843. *
  844. * @memberOf _.support
  845. * @type boolean
  846. */
  847. try {
  848. support.dom = document.createDocumentFragment().nodeType === 11;
  849. } catch(e) {
  850. support.dom = false;
  851. }
  852. /**
  853. * Detect if `arguments` object indexes are non-enumerable.
  854. *
  855. * In Firefox < 4, IE < 9, PhantomJS, and Safari < 5.1 `arguments` object
  856. * indexes are non-enumerable. Chrome < 25 and Node.js < 0.11.0 treat
  857. * `arguments` object indexes as non-enumerable and fail `hasOwnProperty`
  858. * checks for indexes that exceed their function's formal parameters with
  859. * associated values of `0`.
  860. *
  861. * @memberOf _.support
  862. * @type boolean
  863. */
  864. try {
  865. support.nonEnumArgs = !propertyIsEnumerable.call(arguments, 1);
  866. } catch(e) {
  867. support.nonEnumArgs = true;
  868. }
  869. }(0, 0));
  870. /**
  871. * By default, the template delimiters used by lodash are like those in
  872. * embedded Ruby (ERB). Change the following template settings to use
  873. * alternative delimiters.
  874. *
  875. * @static
  876. * @memberOf _
  877. * @type Object
  878. */
  879. lodash.templateSettings = {
  880. /**
  881. * Used to detect `data` property values to be HTML-escaped.
  882. *
  883. * @memberOf _.templateSettings
  884. * @type RegExp
  885. */
  886. 'escape': reEscape,
  887. /**
  888. * Used to detect code to be evaluated.
  889. *
  890. * @memberOf _.templateSettings
  891. * @type RegExp
  892. */
  893. 'evaluate': reEvaluate,
  894. /**
  895. * Used to detect `data` property values to inject.
  896. *
  897. * @memberOf _.templateSettings
  898. * @type RegExp
  899. */
  900. 'interpolate': reInterpolate,
  901. /**
  902. * Used to reference the data object in the template text.
  903. *
  904. * @memberOf _.templateSettings
  905. * @type string
  906. */
  907. 'variable': '',
  908. /**
  909. * Used to import variables into the compiled template.
  910. *
  911. * @memberOf _.templateSettings
  912. * @type Object
  913. */
  914. 'imports': {
  915. /**
  916. * A reference to the `lodash` function.
  917. *
  918. * @memberOf _.templateSettings.imports
  919. * @type Function
  920. */
  921. '_': lodash
  922. }
  923. };
  924. /*------------------------------------------------------------------------*/
  925. /**
  926. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  927. *
  928. * @private
  929. * @param {*} value The value to wrap.
  930. */
  931. function LazyWrapper(value) {
  932. this.__wrapped__ = value;
  933. this.__actions__ = null;
  934. this.__dir__ = 1;
  935. this.__dropCount__ = 0;
  936. this.__filtered__ = false;
  937. this.__iteratees__ = null;
  938. this.__takeCount__ = POSITIVE_INFINITY;
  939. this.__views__ = null;
  940. }
  941. /**
  942. * Creates a clone of the lazy wrapper object.
  943. *
  944. * @private
  945. * @name clone
  946. * @memberOf LazyWrapper
  947. * @returns {Object} Returns the cloned `LazyWrapper` object.
  948. */
  949. function lazyClone() {
  950. var actions = this.__actions__,
  951. iteratees = this.__iteratees__,
  952. views = this.__views__,
  953. result = new LazyWrapper(this.__wrapped__);
  954. result.__actions__ = actions ? arrayCopy(actions) : null;
  955. result.__dir__ = this.__dir__;
  956. result.__dropCount__ = this.__dropCount__;
  957. result.__filtered__ = this.__filtered__;
  958. result.__iteratees__ = iteratees ? arrayCopy(iteratees) : null;
  959. result.__takeCount__ = this.__takeCount__;
  960. result.__views__ = views ? arrayCopy(views) : null;
  961. return result;
  962. }
  963. /**
  964. * Reverses the direction of lazy iteration.
  965. *
  966. * @private
  967. * @name reverse
  968. * @memberOf LazyWrapper
  969. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  970. */
  971. function lazyReverse() {
  972. if (this.__filtered__) {
  973. var result = new LazyWrapper(this);
  974. result.__dir__ = -1;
  975. result.__filtered__ = true;
  976. } else {
  977. result = this.clone();
  978. result.__dir__ *= -1;
  979. }
  980. return result;
  981. }
  982. /**
  983. * Extracts the unwrapped value from its lazy wrapper.
  984. *
  985. * @private
  986. * @name value
  987. * @memberOf LazyWrapper
  988. * @returns {*} Returns the unwrapped value.
  989. */
  990. function lazyValue() {
  991. var array = this.__wrapped__.value();
  992. if (!isArray(array)) {
  993. return baseWrapperValue(array, this.__actions__);
  994. }
  995. var dir = this.__dir__,
  996. isRight = dir < 0,
  997. view = getView(0, array.length, this.__views__),
  998. start = view.start,
  999. end = view.end,
  1000. length = end - start,
  1001. dropCount = this.__dropCount__,
  1002. takeCount = nativeMin(length, this.__takeCount__),
  1003. index = isRight ? end : start - 1,
  1004. iteratees = this.__iteratees__,
  1005. iterLength = iteratees ? iteratees.length : 0,
  1006. resIndex = 0,
  1007. result = [];
  1008. outer:
  1009. while (length-- && resIndex < takeCount) {
  1010. index += dir;
  1011. var iterIndex = -1,
  1012. value = array[index];
  1013. while (++iterIndex < iterLength) {
  1014. var data = iteratees[iterIndex],
  1015. iteratee = data.iteratee,
  1016. computed = iteratee(value, index, array),
  1017. type = data.type;
  1018. if (type == LAZY_MAP_FLAG) {
  1019. value = computed;
  1020. } else if (!computed) {
  1021. if (type == LAZY_FILTER_FLAG) {
  1022. continue outer;
  1023. } else {
  1024. break outer;
  1025. }
  1026. }
  1027. }
  1028. if (dropCount) {
  1029. dropCount--;
  1030. } else {
  1031. result[resIndex++] = value;
  1032. }
  1033. }
  1034. return result;
  1035. }
  1036. /*------------------------------------------------------------------------*/
  1037. /**
  1038. * Creates a cache object to store key/value pairs.
  1039. *
  1040. * @private
  1041. * @static
  1042. * @name Cache
  1043. * @memberOf _.memoize
  1044. */
  1045. function MapCache() {
  1046. this.__data__ = {};
  1047. }
  1048. /**
  1049. * Removes `key` and its value from the cache.
  1050. *
  1051. * @private
  1052. * @name delete
  1053. * @memberOf _.memoize.Cache
  1054. * @param {string} key The key of the value to remove.
  1055. * @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
  1056. */
  1057. function mapDelete(key) {
  1058. return this.has(key) && delete this.__data__[key];
  1059. }
  1060. /**
  1061. * Gets the cached value for `key`.
  1062. *
  1063. * @private
  1064. * @name get
  1065. * @memberOf _.memoize.Cache
  1066. * @param {string} key The key of the value to get.
  1067. * @returns {*} Returns the cached value.
  1068. */
  1069. function mapGet(key) {
  1070. return key == '__proto__' ? undefined : this.__data__[key];
  1071. }
  1072. /**
  1073. * Checks if a cached value for `key` exists.
  1074. *
  1075. * @private
  1076. * @name has
  1077. * @memberOf _.memoize.Cache
  1078. * @param {string} key The key of the entry to check.
  1079. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1080. */
  1081. function mapHas(key) {
  1082. return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
  1083. }
  1084. /**
  1085. * Adds `value` to `key` of the cache.
  1086. *
  1087. * @private
  1088. * @name set
  1089. * @memberOf _.memoize.Cache
  1090. * @param {string} key The key of the value to cache.
  1091. * @param {*} value The value to cache.
  1092. * @returns {Object} Returns the cache object.
  1093. */
  1094. function mapSet(key, value) {
  1095. if (key != '__proto__') {
  1096. this.__data__[key] = value;
  1097. }
  1098. return this;
  1099. }
  1100. /*------------------------------------------------------------------------*/
  1101. /**
  1102. *
  1103. * Creates a cache object to store unique values.
  1104. *
  1105. * @private
  1106. * @param {Array} [values] The values to cache.
  1107. */
  1108. function SetCache(values) {
  1109. var length = values ? values.length : 0;
  1110. this.data = { 'hash': nativeCreate(null), 'set': new Set };
  1111. while (length--) {
  1112. this.push(values[length]);
  1113. }
  1114. }
  1115. /**
  1116. * Checks if `value` is in `cache` mimicking the return signature of
  1117. * `_.indexOf` by returning `0` if the value is found, else `-1`.
  1118. *
  1119. * @private
  1120. * @param {Object} cache The cache to search.
  1121. * @param {*} value The value to search for.
  1122. * @returns {number} Returns `0` if `value` is found, else `-1`.
  1123. */
  1124. function cacheIndexOf(cache, value) {
  1125. var data = cache.data,
  1126. result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
  1127. return result ? 0 : -1;
  1128. }
  1129. /**
  1130. * Adds `value` to the cache.
  1131. *
  1132. * @private
  1133. * @name push
  1134. * @memberOf SetCache
  1135. * @param {*} value The value to cache.
  1136. */
  1137. function cachePush(value) {
  1138. var data = this.data;
  1139. if (typeof value == 'string' || isObject(value)) {
  1140. data.set.add(value);
  1141. } else {
  1142. data.hash[value] = true;
  1143. }
  1144. }
  1145. /*------------------------------------------------------------------------*/
  1146. /**
  1147. * Copies the values of `source` to `array`.
  1148. *
  1149. * @private
  1150. * @param {Array} source The array to copy values from.
  1151. * @param {Array} [array=[]] The array to copy values to.
  1152. * @returns {Array} Returns `array`.
  1153. */
  1154. function arrayCopy(source, array) {
  1155. var index = -1,
  1156. length = source.length;
  1157. array || (array = Array(length));
  1158. while (++index < length) {
  1159. array[index] = source[index];
  1160. }
  1161. return array;
  1162. }
  1163. /**
  1164. * A specialized version of `_.forEach` for arrays without support for callback
  1165. * shorthands or `this` binding.
  1166. *
  1167. * @private
  1168. * @param {Array} array The array to iterate over.
  1169. * @param {Function} iteratee The function invoked per iteration.
  1170. * @returns {Array} Returns `array`.
  1171. */
  1172. function arrayEach(array, iteratee) {
  1173. var index = -1,
  1174. length = array.length;
  1175. while (++index < length) {
  1176. if (iteratee(array[index], index, array) === false) {
  1177. break;
  1178. }
  1179. }
  1180. return array;
  1181. }
  1182. /**
  1183. * A specialized version of `_.forEachRight` for arrays without support for
  1184. * callback shorthands or `this` binding.
  1185. *
  1186. * @private
  1187. * @param {Array} array The array to iterate over.
  1188. * @param {Function} iteratee The function invoked per iteration.
  1189. * @returns {Array} Returns `array`.
  1190. */
  1191. function arrayEachRight(array, iteratee) {
  1192. var length = array.length;
  1193. while (length--) {
  1194. if (iteratee(array[length], length, array) === false) {
  1195. break;
  1196. }
  1197. }
  1198. return array;
  1199. }
  1200. /**
  1201. * A specialized version of `_.every` for arrays without support for callback
  1202. * shorthands or `this` binding.
  1203. *
  1204. * @private
  1205. * @param {Array} array The array to iterate over.
  1206. * @param {Function} predicate The function invoked per iteration.
  1207. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  1208. * else `false`.
  1209. */
  1210. function arrayEvery(array, predicate) {
  1211. var index = -1,
  1212. length = array.length;
  1213. while (++index < length) {
  1214. if (!predicate(array[index], index, array)) {
  1215. return false;
  1216. }
  1217. }
  1218. return true;
  1219. }
  1220. /**
  1221. * A specialized version of `_.filter` for arrays without support for callback
  1222. * shorthands or `this` binding.
  1223. *
  1224. * @private
  1225. * @param {Array} array The array to iterate over.
  1226. * @param {Function} predicate The function invoked per iteration.
  1227. * @returns {Array} Returns the new filtered array.
  1228. */
  1229. function arrayFilter(array, predicate) {
  1230. var index = -1,
  1231. length = array.length,
  1232. resIndex = -1,
  1233. result = [];
  1234. while (++index < length) {
  1235. var value = array[index];
  1236. if (predicate(value, index, array)) {
  1237. result[++resIndex] = value;
  1238. }
  1239. }
  1240. return result;
  1241. }
  1242. /**
  1243. * A specialized version of `_.map` for arrays without support for callback
  1244. * shorthands or `this` binding.
  1245. *
  1246. * @private
  1247. * @param {Array} array The array to iterate over.
  1248. * @param {Function} iteratee The function invoked per iteration.
  1249. * @returns {Array} Returns the new mapped array.
  1250. */
  1251. function arrayMap(array, iteratee) {
  1252. var index = -1,
  1253. length = array.length,
  1254. result = Array(length);
  1255. while (++index < length) {
  1256. result[index] = iteratee(array[index], index, array);
  1257. }
  1258. return result;
  1259. }
  1260. /**
  1261. * A specialized version of `_.max` for arrays without support for iteratees.
  1262. *
  1263. * @private
  1264. * @param {Array} array The array to iterate over.
  1265. * @returns {*} Returns the maximum value.
  1266. */
  1267. function arrayMax(array) {
  1268. var index = -1,
  1269. length = array.length,
  1270. result = NEGATIVE_INFINITY;
  1271. while (++index < length) {
  1272. var value = array[index];
  1273. if (value > result) {
  1274. result = value;
  1275. }
  1276. }
  1277. return result;
  1278. }
  1279. /**
  1280. * A specialized version of `_.min` for arrays without support for iteratees.
  1281. *
  1282. * @private
  1283. * @param {Array} array The array to iterate over.
  1284. * @returns {*} Returns the minimum value.
  1285. */
  1286. function arrayMin(array) {
  1287. var index = -1,
  1288. length = array.length,
  1289. result = POSITIVE_INFINITY;
  1290. while (++index < length) {
  1291. var value = array[index];
  1292. if (value < result) {
  1293. result = value;
  1294. }
  1295. }
  1296. return result;
  1297. }
  1298. /**
  1299. * A specialized version of `_.reduce` for arrays without support for callback
  1300. * shorthands or `this` binding.
  1301. *
  1302. * @private
  1303. * @param {Array} array The array to iterate over.
  1304. * @param {Function} iteratee The function invoked per iteration.
  1305. * @param {*} [accumulator] The initial value.
  1306. * @param {boolean} [initFromArray] Specify using the first element of `array`
  1307. * as the initial value.
  1308. * @returns {*} Returns the accumulated value.
  1309. */
  1310. function arrayReduce(array, iteratee, accumulator, initFromArray) {
  1311. var index = -1,
  1312. length = array.length;
  1313. if (initFromArray && length) {
  1314. accumulator = array[++index];
  1315. }
  1316. while (++index < length) {
  1317. accumulator = iteratee(accumulator, array[index], index, array);
  1318. }
  1319. return accumulator;
  1320. }
  1321. /**
  1322. * A specialized version of `_.reduceRight` for arrays without support for
  1323. * callback shorthands or `this` binding.
  1324. *
  1325. * @private
  1326. * @param {Array} array The array to iterate over.
  1327. * @param {Function} iteratee The function invoked per iteration.
  1328. * @param {*} [accumulator] The initial value.
  1329. * @param {boolean} [initFromArray] Specify using the last element of `array`
  1330. * as the initial value.
  1331. * @returns {*} Returns the accumulated value.
  1332. */
  1333. function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
  1334. var length = array.length;
  1335. if (initFromArray && length) {
  1336. accumulator = array[--length];
  1337. }
  1338. while (length--) {
  1339. accumulator = iteratee(accumulator, array[length], length, array);
  1340. }
  1341. return accumulator;
  1342. }
  1343. /**
  1344. * A specialized version of `_.some` for arrays without support for callback
  1345. * shorthands or `this` binding.
  1346. *
  1347. * @private
  1348. * @param {Array} array The array to iterate over.
  1349. * @param {Function} predicate The function invoked per iteration.
  1350. * @returns {boolean} Returns `true` if any element passes the predicate check,
  1351. * else `false`.
  1352. */
  1353. function arraySome(array, predicate) {
  1354. var index = -1,
  1355. length = array.length;
  1356. while (++index < length) {
  1357. if (predicate(array[index], index, array)) {
  1358. return true;
  1359. }
  1360. }
  1361. return false;
  1362. }
  1363. /**
  1364. * Used by `_.defaults` to customize its `_.assign` use.
  1365. *
  1366. * @private
  1367. * @param {*} objectValue The destination object property value.
  1368. * @param {*} sourceValue The source object property value.
  1369. * @returns {*} Returns the value to assign to the destination object.
  1370. */
  1371. function assignDefaults(objectValue, sourceValue) {
  1372. return typeof objectValue == 'undefined' ? sourceValue : objectValue;
  1373. }
  1374. /**
  1375. * Used by `_.template` to customize its `_.assign` use.
  1376. *
  1377. * **Note:** This method is like `assignDefaults` except that it ignores
  1378. * inherited property values when checking if a property is `undefined`.
  1379. *
  1380. * @private
  1381. * @param {*} objectValue The destination object property value.
  1382. * @param {*} sourceValue The source object property value.
  1383. * @param {string} key The key associated with the object and source values.
  1384. * @param {Object} object The destination object.
  1385. * @returns {*} Returns the value to assign to the destination object.
  1386. */
  1387. function assignOwnDefaults(objectValue, sourceValue, key, object) {
  1388. return (typeof objectValue == 'undefined' || !hasOwnProperty.call(object, key))
  1389. ? sourceValue
  1390. : objectValue;
  1391. }
  1392. /**
  1393. * The base implementation of `_.assign` without support for argument juggling,
  1394. * multiple sources, and `this` binding `customizer` functions.
  1395. *
  1396. * @private
  1397. * @param {Object} object The destination object.
  1398. * @param {Object} source The source object.
  1399. * @param {Function} [customizer] The function to customize assigning values.
  1400. * @returns {Object} Returns the destination object.
  1401. */
  1402. function baseAssign(object, source, customizer) {
  1403. var props = keys(source);
  1404. if (!customizer) {
  1405. return baseCopy(source, object, props);
  1406. }
  1407. var index = -1,
  1408. length = props.length;
  1409. while (++index < length) {
  1410. var key = props[index],
  1411. value = object[key],
  1412. result = customizer(value, source[key], key, object, source);
  1413. if ((result === result ? result !== value : value === value) ||
  1414. (typeof value == 'undefined' && !(key in object))) {
  1415. object[key] = result;
  1416. }
  1417. }
  1418. return object;
  1419. }
  1420. /**
  1421. * The base implementation of `_.at` without support for strings and individual
  1422. * key arguments.
  1423. *
  1424. * @private
  1425. * @param {Array|Object} collection The collection to iterate over.
  1426. * @param {number[]|string[]} [props] The property names or indexes of elements to pick.
  1427. * @returns {Array} Returns the new array of picked elements.
  1428. */
  1429. function baseAt(collection, props) {
  1430. var index = -1,
  1431. length = collection.length,
  1432. isArr = isLength(length),
  1433. propsLength = props.length,
  1434. result = Array(propsLength);
  1435. while(++index < propsLength) {
  1436. var key = props[index];
  1437. if (isArr) {
  1438. key = parseFloat(key);
  1439. result[index] = isIndex(key, length) ? collection[key] : undefined;
  1440. } else {
  1441. result[index] = collection[key];
  1442. }
  1443. }
  1444. return result;
  1445. }
  1446. /**
  1447. * Copies the properties of `source` to `object`.
  1448. *
  1449. * @private
  1450. * @param {Object} source The object to copy properties from.
  1451. * @param {Object} [object={}] The object to copy properties to.
  1452. * @param {Array} props The property names to copy.
  1453. * @returns {Object} Returns `object`.
  1454. */
  1455. function baseCopy(source, object, props) {
  1456. if (!props) {
  1457. props = object;
  1458. object = {};
  1459. }
  1460. var index = -1,
  1461. length = props.length;
  1462. while (++index < length) {
  1463. var key = props[index];
  1464. object[key] = source[key];
  1465. }
  1466. return object;
  1467. }
  1468. /**
  1469. * The base implementation of `_.bindAll` without support for individual
  1470. * method name arguments.
  1471. *
  1472. * @private
  1473. * @param {Object} object The object to bind and assign the bound methods to.
  1474. * @param {string[]} methodNames The object method names to bind.
  1475. * @returns {Object} Returns `object`.
  1476. */
  1477. function baseBindAll(object, methodNames) {
  1478. var index = -1,
  1479. length = methodNames.length;
  1480. while (++index < length) {
  1481. var key = methodNames[index];
  1482. object[key] = createWrapper(object[key], BIND_FLAG, object);
  1483. }
  1484. return object;
  1485. }
  1486. /**
  1487. * The base implementation of `_.callback` which supports specifying the
  1488. * number of arguments to provide to `func`.
  1489. *
  1490. * @private
  1491. * @param {*} [func=_.identity] The value to convert to a callback.
  1492. * @param {*} [thisArg] The `this` binding of `func`.
  1493. * @param {number} [argCount] The number of arguments to provide to `func`.
  1494. * @returns {Function} Returns the callback.
  1495. */
  1496. function baseCallback(func, thisArg, argCount) {
  1497. var type = typeof func;
  1498. if (type == 'function') {
  1499. return (typeof thisArg != 'undefined' && isBindable(func))
  1500. ? bindCallback(func, thisArg, argCount)
  1501. : func;
  1502. }
  1503. if (func == null) {
  1504. return identity;
  1505. }
  1506. if (type == 'object') {
  1507. return baseMatches(func);
  1508. }
  1509. return typeof thisArg == 'undefined'
  1510. ? baseProperty(func + '')
  1511. : baseMatchesProperty(func + '', thisArg);
  1512. }
  1513. /**
  1514. * The base implementation of `_.clone` without support for argument juggling
  1515. * and `this` binding `customizer` functions.
  1516. *
  1517. * @private
  1518. * @param {*} value The value to clone.
  1519. * @param {boolean} [isDeep] Specify a deep clone.
  1520. * @param {Function} [customizer] The function to customize cloning values.
  1521. * @param {string} [key] The key of `value`.
  1522. * @param {Object} [object] The object `value` belongs to.
  1523. * @param {Array} [stackA=[]] Tracks traversed source objects.
  1524. * @param {Array} [stackB=[]] Associates clones with source counterparts.
  1525. * @returns {*} Returns the cloned value.
  1526. */
  1527. function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
  1528. var result;
  1529. if (customizer) {
  1530. result = object ? customizer(value, key, object) : customizer(value);
  1531. }
  1532. if (typeof result != 'undefined') {
  1533. return result;
  1534. }
  1535. if (!isObject(value)) {
  1536. return value;
  1537. }
  1538. var isArr = isArray(value);
  1539. if (isArr) {
  1540. result = initCloneArray(value);
  1541. if (!isDeep) {
  1542. return arrayCopy(value, result);
  1543. }
  1544. } else {
  1545. var tag = objToString.call(value),
  1546. isFunc = tag == funcTag;
  1547. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  1548. result = initCloneObject(isFunc ? {} : value);
  1549. if (!isDeep) {
  1550. return baseCopy(value, result, keys(value));
  1551. }
  1552. } else {
  1553. return cloneableTags[tag]
  1554. ? initCloneByTag(value, tag, isDeep)
  1555. : (object ? value : {});
  1556. }
  1557. }
  1558. // Check for circular references and return corresponding clone.
  1559. stackA || (stackA = []);
  1560. stackB || (stackB = []);
  1561. var length = stackA.length;
  1562. while (length--) {
  1563. if (stackA[length] == value) {
  1564. return stackB[length];
  1565. }
  1566. }
  1567. // Add the source value to the stack of traversed objects and associate it with its clone.
  1568. stackA.push(value);
  1569. stackB.push(result);
  1570. // Recursively populate clone (susceptible to call stack limits).
  1571. (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
  1572. result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB);
  1573. });
  1574. return result;
  1575. }
  1576. /**
  1577. * The base implementation of `_.create` without support for assigning
  1578. * properties to the created object.
  1579. *
  1580. * @private
  1581. * @param {Object} prototype The object to inherit from.
  1582. * @returns {Object} Returns the new object.
  1583. */
  1584. var baseCreate = (function() {
  1585. function Object() {}
  1586. return function(prototype) {
  1587. if (isObject(prototype)) {
  1588. Object.prototype = prototype;
  1589. var result = new Object;
  1590. Object.prototype = null;
  1591. }
  1592. return result || context.Object();
  1593. };
  1594. }());
  1595. /**
  1596. * The base implementation of `_.delay` and `_.defer` which accepts an index
  1597. * of where to slice the arguments to provide to `func`.
  1598. *
  1599. * @private
  1600. * @param {Function} func The function to delay.
  1601. * @param {number} wait The number of milliseconds to delay invocation.
  1602. * @param {Object} args The `arguments` object to slice and provide to `func`.
  1603. * @returns {number} Returns the timer id.
  1604. */
  1605. function baseDelay(func, wait, args, fromIndex) {
  1606. if (typeof func != 'function') {
  1607. throw new TypeError(FUNC_ERROR_TEXT);
  1608. }
  1609. return setTimeout(function() { func.apply(undefined, baseSlice(args, fromIndex)); }, wait);
  1610. }
  1611. /**
  1612. * The base implementation of `_.difference` which accepts a single array
  1613. * of values to exclude.
  1614. *
  1615. * @private
  1616. * @param {Array} array The array to inspect.
  1617. * @param {Array} values The values to exclude.
  1618. * @returns {Array} Returns the new array of filtered values.
  1619. */
  1620. function baseDifference(array, values) {
  1621. var length = array ? array.length : 0,
  1622. result = [];
  1623. if (!length) {
  1624. return result;
  1625. }
  1626. var index = -1,
  1627. indexOf = getIndexOf(),
  1628. isCommon = indexOf == baseIndexOf,
  1629. cache = isCommon && values.length >= 200 && createCache(values),
  1630. valuesLength = values.length;
  1631. if (cache) {
  1632. indexOf = cacheIndexOf;
  1633. isCommon = false;
  1634. values = cache;
  1635. }
  1636. outer:
  1637. while (++index < length) {
  1638. var value = array[index];
  1639. if (isCommon && value === value) {
  1640. var valuesIndex = valuesLength;
  1641. while (valuesIndex--) {
  1642. if (values[valuesIndex] === value) {
  1643. continue outer;
  1644. }
  1645. }
  1646. result.push(value);
  1647. }
  1648. else if (indexOf(values, value) < 0) {
  1649. result.push(value);
  1650. }
  1651. }
  1652. return result;
  1653. }
  1654. /**
  1655. * The base implementation of `_.forEach` without support for callback
  1656. * shorthands and `this` binding.
  1657. *
  1658. * @private
  1659. * @param {Array|Object|string} collection The collection to iterate over.
  1660. * @param {Function} iteratee The function invoked per iteration.
  1661. * @returns {Array|Object|string} Returns `collection`.
  1662. */
  1663. function baseEach(collection, iteratee) {
  1664. var length = collection ? collection.length : 0;
  1665. if (!isLength(length)) {
  1666. return baseForOwn(collection, iteratee);
  1667. }
  1668. var index = -1,
  1669. iterable = toObject(collection);
  1670. while (++index < length) {
  1671. if (iteratee(iterable[index], index, iterable) === false) {
  1672. break;
  1673. }
  1674. }
  1675. return collection;
  1676. }
  1677. /**
  1678. * The base implementation of `_.forEachRight` without support for callback
  1679. * shorthands and `this` binding.
  1680. *
  1681. * @private
  1682. * @param {Array|Object|string} collection The collection to iterate over.
  1683. * @param {Function} iteratee The function invoked per iteration.
  1684. * @returns {Array|Object|string} Returns `collection`.
  1685. */
  1686. function baseEachRight(collection, iteratee) {
  1687. var length = collection ? collection.length : 0;
  1688. if (!isLength(length)) {
  1689. return baseForOwnRight(collection, iteratee);
  1690. }
  1691. var iterable = toObject(collection);
  1692. while (length--) {
  1693. if (iteratee(iterable[length], length, iterable) === false) {
  1694. break;
  1695. }
  1696. }
  1697. return collection;
  1698. }
  1699. /**
  1700. * The base implementation of `_.every` without support for callback
  1701. * shorthands or `this` binding.
  1702. *
  1703. * @private
  1704. * @param {Array|Object|string} collection The collection to iterate over.
  1705. * @param {Function} predicate The function invoked per iteration.
  1706. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  1707. * else `false`
  1708. */
  1709. function baseEvery(collection, predicate) {
  1710. var result = true;
  1711. baseEach(collection, function(value, index, collection) {
  1712. result = !!predicate(value, index, collection);
  1713. return result;
  1714. });
  1715. return result;
  1716. }
  1717. /**
  1718. * The base implementation of `_.fill` without an iteratee call guard.
  1719. *
  1720. * @private
  1721. * @param {Array} array The array to fill.
  1722. * @param {*} value The value to fill `array` with.
  1723. * @param {number} [start=0] The start position.
  1724. * @param {number} [end=array.length] The end position.
  1725. * @returns {Array} Returns `array`.
  1726. */
  1727. function baseFill(array, value, start, end) {
  1728. var length = array.length;
  1729. start = start == null ? 0 : (+start || 0);
  1730. if (start < 0) {
  1731. start = -start > length ? 0 : (length + start);
  1732. }
  1733. end = (typeof end == 'undefined' || end > length) ? length : (+end || 0);
  1734. if (end < 0) {
  1735. end += length;
  1736. }
  1737. length = start > end ? 0 : end >>> 0;
  1738. start >>>= 0;
  1739. while (start < length) {
  1740. array[start++] = value;
  1741. }
  1742. return array;
  1743. }
  1744. /**
  1745. * The base implementation of `_.filter` without support for callback
  1746. * shorthands or `this` binding.
  1747. *
  1748. * @private
  1749. * @param {Array|Object|string} collection The collection to iterate over.
  1750. * @param {Function} predicate The function invoked per iteration.
  1751. * @returns {Array} Returns the new filtered array.
  1752. */
  1753. function baseFilter(collection, predicate) {
  1754. var result = [];
  1755. baseEach(collection, function(value, index, collection) {
  1756. if (predicate(value, index, collection)) {
  1757. result.push(value);
  1758. }
  1759. });
  1760. return result;
  1761. }
  1762. /**
  1763. * The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.findLastKey`,
  1764. * without support for callback shorthands and `this` binding, which iterates
  1765. * over `collection` using the provided `eachFunc`.
  1766. *
  1767. * @private
  1768. * @param {Array|Object|string} collection The collection to search.
  1769. * @param {Function} predicate The function invoked per iteration.
  1770. * @param {Function} eachFunc The function to iterate over `collection`.
  1771. * @param {boolean} [retKey] Specify returning the key of the found element
  1772. * instead of the element itself.
  1773. * @returns {*} Returns the found element or its key, else `undefined`.
  1774. */
  1775. function baseFind(collection, predicate, eachFunc, retKey) {
  1776. var result;
  1777. eachFunc(collection, function(value, key, collection) {
  1778. if (predicate(value, key, collection)) {
  1779. result = retKey ? key : value;
  1780. return false;
  1781. }
  1782. });
  1783. return result;
  1784. }
  1785. /**
  1786. * The base implementation of `_.flatten` with added support for restricting
  1787. * flattening and specifying the start index.
  1788. *
  1789. * @private
  1790. * @param {Array} array The array to flatten.
  1791. * @param {boolean} [isDeep] Specify a deep flatten.
  1792. * @param {boolean} [isStrict] Restrict flattening to arrays and `arguments` objects.
  1793. * @param {number} [fromIndex=0] The index to start from.
  1794. * @returns {Array} Returns the new flattened array.
  1795. */
  1796. function baseFlatten(array, isDeep, isStrict, fromIndex) {
  1797. var index = (fromIndex || 0) - 1,
  1798. length = array.length,
  1799. resIndex = -1,
  1800. result = [];
  1801. while (++index < length) {
  1802. var value = array[index];
  1803. if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) {
  1804. if (isDeep) {
  1805. // Recursively flatten arrays (susceptible to call stack limits).
  1806. value = baseFlatten(value, isDeep, isStrict);
  1807. }
  1808. var valIndex = -1,
  1809. valLength = value.length;
  1810. result.length += valLength;
  1811. while (++valIndex < valLength) {
  1812. result[++resIndex] = value[valIndex];
  1813. }
  1814. } else if (!isStrict) {
  1815. result[++resIndex] = value;
  1816. }
  1817. }
  1818. return result;
  1819. }
  1820. /**
  1821. * The base implementation of `baseForIn` and `baseForOwn` which iterates
  1822. * over `object` properties returned by `keysFunc` invoking `iteratee` for
  1823. * each property. Iterator functions may exit iteration early by explicitly
  1824. * returning `false`.
  1825. *
  1826. * @private
  1827. * @param {Object} object The object to iterate over.
  1828. * @param {Function} iteratee The function invoked per iteration.
  1829. * @param {Function} keysFunc The function to get the keys of `object`.
  1830. * @returns {Object} Returns `object`.
  1831. */
  1832. function baseFor(object, iteratee, keysFunc) {
  1833. var index = -1,
  1834. iterable = toObject(object),
  1835. props = keysFunc(object),
  1836. length = props.length;
  1837. while (++index < length) {
  1838. var key = props[index];
  1839. if (iteratee(iterable[key], key, iterable) === false) {
  1840. break;
  1841. }
  1842. }
  1843. return object;
  1844. }
  1845. /**
  1846. * This function is like `baseFor` except that it iterates over properties
  1847. * in the opposite order.
  1848. *
  1849. * @private
  1850. * @param {Object} object The object to iterate over.
  1851. * @param {Function} iteratee The function invoked per iteration.
  1852. * @param {Function} keysFunc The function to get the keys of `object`.
  1853. * @returns {Object} Returns `object`.
  1854. */
  1855. function baseForRight(object, iteratee, keysFunc) {
  1856. var iterable = toObject(object),
  1857. props = keysFunc(object),
  1858. length = props.length;
  1859. while (length--) {
  1860. var key = props[length];
  1861. if (iteratee(iterable[key], key, iterable) === false) {
  1862. break;
  1863. }
  1864. }
  1865. return object;
  1866. }
  1867. /**
  1868. * The base implementation of `_.forIn` without support for callback
  1869. * shorthands and `this` binding.
  1870. *
  1871. * @private
  1872. * @param {Object} object The object to iterate over.
  1873. * @param {Function} iteratee The function invoked per iteration.
  1874. * @returns {Object} Returns `object`.
  1875. */
  1876. function baseForIn(object, iteratee) {
  1877. return baseFor(object, iteratee, keysIn);
  1878. }
  1879. /**
  1880. * The base implementation of `_.forOwn` without support for callback
  1881. * shorthands and `this` binding.
  1882. *
  1883. * @private
  1884. * @param {Object} object The object to iterate over.
  1885. * @param {Function} iteratee The function invoked per iteration.
  1886. * @returns {Object} Returns `object`.
  1887. */
  1888. function baseForOwn(object, iteratee) {
  1889. return baseFor(object, iteratee, keys);
  1890. }
  1891. /**
  1892. * The base implementation of `_.forOwnRight` without support for callback
  1893. * shorthands and `this` binding.
  1894. *
  1895. * @private
  1896. * @param {Object} object The object to iterate over.
  1897. * @param {Function} iteratee The function invoked per iteration.
  1898. * @returns {Object} Returns `object`.
  1899. */
  1900. function baseForOwnRight(object, iteratee) {
  1901. return baseForRight(object, iteratee, keys);
  1902. }
  1903. /**
  1904. * The base implementation of `_.functions` which creates an array of
  1905. * `object` function property names filtered from those provided.
  1906. *
  1907. * @private
  1908. * @param {Object} object The object to inspect.
  1909. * @param {Array} props The property names to filter.
  1910. * @returns {Array} Returns the new array of filtered property names.
  1911. */
  1912. function baseFunctions(object, props) {
  1913. var index = -1,
  1914. length = props.length,
  1915. resIndex = -1,
  1916. result = [];
  1917. while (++index < length) {
  1918. var key = props[index];
  1919. if (isFunction(object[key])) {
  1920. result[++resIndex] = key;
  1921. }
  1922. }
  1923. return result;
  1924. }
  1925. /**
  1926. * The base implementation of `_.invoke` which requires additional arguments
  1927. * to be provided as an array of arguments rather than individually.
  1928. *
  1929. * @private
  1930. * @param {Array|Object|string} collection The collection to iterate over.
  1931. * @param {Function|string} methodName The name of the method to invoke or
  1932. * the function invoked per iteration.
  1933. * @param {Array} [args] The arguments to invoke the method with.
  1934. * @returns {Array} Returns the array of results.
  1935. */
  1936. function baseInvoke(collection, methodName, args) {
  1937. var index = -1,
  1938. isFunc = typeof methodName == 'function',
  1939. length = collection ? collection.length : 0,
  1940. result = isLength(length) ? Array(length) : [];
  1941. baseEach(collection, function(value) {
  1942. var func = isFunc ? methodName : (value != null && value[methodName]);
  1943. result[++index] = func ? func.apply(value, args) : undefined;
  1944. });
  1945. return result;
  1946. }
  1947. /**
  1948. * The base implementation of `_.isEqual` without support for `this` binding
  1949. * `customizer` functions.
  1950. *
  1951. * @private
  1952. * @param {*} value The value to compare.
  1953. * @param {*} other The other value to compare.
  1954. * @param {Function} [customizer] The function to customize comparing values.
  1955. * @param {boolean} [isWhere] Specify performing partial comparisons.
  1956. * @param {Array} [stackA] Tracks traversed `value` objects.
  1957. * @param {Array} [stackB] Tracks traversed `other` objects.
  1958. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  1959. */
  1960. function baseIsEqual(value, other, customizer, isWhere, stackA, stackB) {
  1961. // Exit early for identical values.
  1962. if (value === other) {
  1963. // Treat `+0` vs. `-0` as not equal.
  1964. return value !== 0 || (1 / value == 1 / other);
  1965. }
  1966. var valType = typeof value,
  1967. othType = typeof other;
  1968. // Exit early for unlike primitive values.
  1969. if ((valType != 'function' && valType != 'object' && othType != 'function' && othType != 'object') ||
  1970. value == null || other == null) {
  1971. // Return `false` unless both values are `NaN`.
  1972. return value !== value && other !== other;
  1973. }
  1974. return baseIsEqualDeep(value, other, baseIsEqual, customizer, isWhere, stackA, stackB);
  1975. }
  1976. /**
  1977. * A specialized version of `baseIsEqual` for arrays and objects which performs
  1978. * deep comparisons and tracks traversed objects enabling objects with circular
  1979. * references to be compared.
  1980. *
  1981. * @private
  1982. * @param {Object} object The object to compare.
  1983. * @param {Object} other The other object to compare.
  1984. * @param {Function} equalFunc The function to determine equivalents of values.
  1985. * @param {Function} [customizer] The function to customize comparing objects.
  1986. * @param {boolean} [isWhere] Specify performing partial comparisons.
  1987. * @param {Array} [stackA=[]] Tracks traversed `value` objects.
  1988. * @param {Array} [stackB=[]] Tracks traversed `other` objects.
  1989. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  1990. */
  1991. function baseIsEqualDeep(object, other, equalFunc, customizer, isWhere, stackA, stackB) {
  1992. var objIsArr = isArray(object),
  1993. othIsArr = isArray(other),
  1994. objTag = arrayTag,
  1995. othTag = arrayTag;
  1996. if (!objIsArr) {
  1997. objTag = objToString.call(object);
  1998. if (objTag == argsTag) {
  1999. objTag = objectTag;
  2000. } else if (objTag != objectTag) {
  2001. objIsArr = isTypedArray(object);
  2002. }
  2003. }
  2004. if (!othIsArr) {
  2005. othTag = objToString.call(other);
  2006. if (othTag == argsTag) {
  2007. othTag = objectTag;
  2008. } else if (othTag != objectTag) {
  2009. othIsArr = isTypedArray(other);
  2010. }
  2011. }
  2012. var objIsObj = objTag == objectTag,
  2013. othIsObj = othTag == objectTag,
  2014. isSameTag = objTag == othTag;
  2015. if (isSameTag && !(objIsArr || objIsObj)) {
  2016. return equalByTag(object, other, objTag);
  2017. }
  2018. var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  2019. othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  2020. if (valWrapped || othWrapped) {
  2021. return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isWhere, stackA, stackB);
  2022. }
  2023. if (!isSameTag) {
  2024. return false;
  2025. }
  2026. // Assume cyclic values are equal.
  2027. // For more information on detecting circular references see https://es5.github.io/#JO.
  2028. stackA || (stackA = []);
  2029. stackB || (stackB = []);
  2030. var length = stackA.length;
  2031. while (length--) {
  2032. if (stackA[length] == object) {
  2033. return stackB[length] == other;
  2034. }
  2035. }
  2036. // Add `object` and `other` to the stack of traversed objects.
  2037. stackA.push(object);
  2038. stackB.push(other);
  2039. var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isWhere, stackA, stackB);
  2040. stackA.pop();
  2041. stackB.pop();
  2042. return result;
  2043. }
  2044. /**
  2045. * The base implementation of `_.isMatch` without support for callback
  2046. * shorthands or `this` binding.
  2047. *
  2048. * @private
  2049. * @param {Object} object The object to inspect.
  2050. * @param {Array} props The source property names to match.
  2051. * @param {Array} values The source values to match.
  2052. * @param {Array} strictCompareFlags Strict comparison flags for source values.
  2053. * @param {Function} [customizer] The function to customize comparing objects.
  2054. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  2055. */
  2056. function baseIsMatch(object, props, values, strictCompareFlags, customizer) {
  2057. var length = props.length;
  2058. if (object == null) {
  2059. return !length;
  2060. }
  2061. var index = -1,
  2062. noCustomizer = !customizer;
  2063. while (++index < length) {
  2064. if ((noCustomizer && strictCompareFlags[index])
  2065. ? values[index] !== object[props[index]]
  2066. : !hasOwnProperty.call(object, props[index])
  2067. ) {
  2068. return false;
  2069. }
  2070. }
  2071. index = -1;
  2072. while (++index < length) {
  2073. var key = props[index];
  2074. if (noCustomizer && strictCompareFlags[index]) {
  2075. var result = hasOwnProperty.call(object, key);
  2076. } else {
  2077. var objValue = object[key],
  2078. srcValue = values[index];
  2079. result = customizer ? customizer(objValue, srcValue, key) : undefined;
  2080. if (typeof result == 'undefined') {
  2081. result = baseIsEqual(srcValue, objValue, customizer, true);
  2082. }
  2083. }
  2084. if (!result) {
  2085. return false;
  2086. }
  2087. }
  2088. return true;
  2089. }
  2090. /**
  2091. * The base implementation of `_.map` without support for callback shorthands
  2092. * or `this` binding.
  2093. *
  2094. * @private
  2095. * @param {Array|Object|string} collection The collection to iterate over.
  2096. * @param {Function} iteratee The function invoked per iteration.
  2097. * @returns {Array} Returns the new mapped array.
  2098. */
  2099. function baseMap(collection, iteratee) {
  2100. var result = [];
  2101. baseEach(collection, function(value, key, collection) {
  2102. result.push(iteratee(value, key, collection));
  2103. });
  2104. return result;
  2105. }
  2106. /**
  2107. * The base implementation of `_.matches` which does not clone `source`.
  2108. *
  2109. * @private
  2110. * @param {Object} source The object of property values to match.
  2111. * @returns {Function} Returns the new function.
  2112. */
  2113. function baseMatches(source) {
  2114. var props = keys(source),
  2115. length = props.length;
  2116. if (length == 1) {
  2117. var key = props[0],
  2118. value = source[key];
  2119. if (isStrictComparable(value)) {
  2120. return function(object) {
  2121. return object != null && object[key] === value && hasOwnProperty.call(object, key);
  2122. };
  2123. }
  2124. }
  2125. var values = Array(length),
  2126. strictCompareFlags = Array(length);
  2127. while (length--) {
  2128. value = source[props[length]];
  2129. values[length] = value;
  2130. strictCompareFlags[length] = isStrictComparable(value);
  2131. }
  2132. return function(object) {
  2133. return baseIsMatch(object, props, values, strictCompareFlags);
  2134. };
  2135. }
  2136. /**
  2137. * The base implementation of `_.matchesProperty` which does not coerce `key`
  2138. * to a string.
  2139. *
  2140. * @private
  2141. * @param {string} key The key of the property to get.
  2142. * @param {*} value The value to compare.
  2143. * @returns {Function} Returns the new function.
  2144. */
  2145. function baseMatchesProperty(key, value) {
  2146. if (isStrictComparable(value)) {
  2147. return function(object) {
  2148. return object != null && object[key] === value;
  2149. };
  2150. }
  2151. return function(object) {
  2152. return object != null && baseIsEqual(value, object[key], null, true);
  2153. };
  2154. }
  2155. /**
  2156. * The base implementation of `_.merge` without support for argument juggling,
  2157. * multiple sources, and `this` binding `customizer` functions.
  2158. *
  2159. * @private
  2160. * @param {Object} object The destination object.
  2161. * @param {Object} source The source object.
  2162. * @param {Function} [customizer] The function to customize merging properties.
  2163. * @param {Array} [stackA=[]] Tracks traversed source objects.
  2164. * @param {Array} [stackB=[]] Associates values with source counterparts.
  2165. * @returns {Object} Returns the destination object.
  2166. */
  2167. function baseMerge(object, source, customizer, stackA, stackB) {
  2168. if (!isObject(object)) {
  2169. return object;
  2170. }
  2171. var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
  2172. (isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
  2173. if (isObjectLike(srcValue)) {
  2174. stackA || (stackA = []);
  2175. stackB || (stackB = []);
  2176. return baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
  2177. }
  2178. var value = object[key],
  2179. result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
  2180. isCommon = typeof result == 'undefined';
  2181. if (isCommon) {
  2182. result = srcValue;
  2183. }
  2184. if ((isSrcArr || typeof result != 'undefined') &&
  2185. (isCommon || (result === result ? result !== value : value === value))) {
  2186. object[key] = result;
  2187. }
  2188. });
  2189. return object;
  2190. }
  2191. /**
  2192. * A specialized version of `baseMerge` for arrays and objects which performs
  2193. * deep merges and tracks traversed objects enabling objects with circular
  2194. * references to be merged.
  2195. *
  2196. * @private
  2197. * @param {Object} object The destination object.
  2198. * @param {Object} source The source object.
  2199. * @param {string} key The key of the value to merge.
  2200. * @param {Function} mergeFunc The function to merge values.
  2201. * @param {Function} [customizer] The function to customize merging properties.
  2202. * @param {Array} [stackA=[]] Tracks traversed source objects.
  2203. * @param {Array} [stackB=[]] Associates values with source counterparts.
  2204. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2205. */
  2206. function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
  2207. var length = stackA.length,
  2208. srcValue = source[key];
  2209. while (length--) {
  2210. if (stackA[length] == srcValue) {
  2211. object[key] = stackB[length];
  2212. return;
  2213. }
  2214. }
  2215. var value = object[key],
  2216. result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
  2217. isCommon = typeof result == 'undefined';
  2218. if (isCommon) {
  2219. result = srcValue;
  2220. if (isLength(srcValue.length) && (isArray(srcValue) || isTypedArray(srcValue))) {
  2221. result = isArray(value)
  2222. ? value
  2223. : (value ? arrayCopy(value) : []);
  2224. }
  2225. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  2226. result = isArguments(value)
  2227. ? toPlainObject(value)
  2228. : (isPlainObject(value) ? value : {});
  2229. }
  2230. else {
  2231. isCommon = false;
  2232. }
  2233. }
  2234. // Add the source value to the stack of traversed objects and associate
  2235. // it with its merged value.
  2236. stackA.push(srcValue);
  2237. stackB.push(result);
  2238. if (isCommon) {
  2239. // Recursively merge objects and arrays (susceptible to call stack limits).
  2240. object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
  2241. } else if (result === result ? result !== value : value === value) {
  2242. object[key] = result;
  2243. }
  2244. }
  2245. /**
  2246. * The base implementation of `_.property` which does not coerce `key` to a string.
  2247. *
  2248. * @private
  2249. * @param {string} key The key of the property to get.
  2250. * @returns {Function} Returns the new function.
  2251. */
  2252. function baseProperty(key) {
  2253. return function(object) {
  2254. return object == null ? undefined : object[key];
  2255. };
  2256. }
  2257. /**
  2258. * The base implementation of `_.pullAt` without support for individual
  2259. * index arguments.
  2260. *
  2261. * @private
  2262. * @param {Array} array The array to modify.
  2263. * @param {number[]} indexes The indexes of elements to remove.
  2264. * @returns {Array} Returns the new array of removed elements.
  2265. */
  2266. function basePullAt(array, indexes) {
  2267. var length = indexes.length,
  2268. result = baseAt(array, indexes);
  2269. indexes.sort(baseCompareAscending);
  2270. while (length--) {
  2271. var index = parseFloat(indexes[length]);
  2272. if (index != previous && isIndex(index)) {
  2273. var previous = index;
  2274. splice.call(array, index, 1);
  2275. }
  2276. }
  2277. return result;
  2278. }
  2279. /**
  2280. * The base implementation of `_.random` without support for argument juggling
  2281. * and returning floating-point numbers.
  2282. *
  2283. * @private
  2284. * @param {number} min The minimum possible value.
  2285. * @param {number} max The maximum possible value.
  2286. * @returns {number} Returns the random number.
  2287. */
  2288. function baseRandom(min, max) {
  2289. return min + floor(nativeRandom() * (max - min + 1));
  2290. }
  2291. /**
  2292. * The base implementation of `_.reduce` and `_.reduceRight` without support
  2293. * for callback shorthands or `this` binding, which iterates over `collection`
  2294. * using the provided `eachFunc`.
  2295. *
  2296. * @private
  2297. * @param {Array|Object|string} collection The collection to iterate over.
  2298. * @param {Function} iteratee The function invoked per iteration.
  2299. * @param {*} accumulator The initial value.
  2300. * @param {boolean} initFromCollection Specify using the first or last element
  2301. * of `collection` as the initial value.
  2302. * @param {Function} eachFunc The function to iterate over `collection`.
  2303. * @returns {*} Returns the accumulated value.
  2304. */
  2305. function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
  2306. eachFunc(collection, function(value, index, collection) {
  2307. accumulator = initFromCollection
  2308. ? (initFromCollection = false, value)
  2309. : iteratee(accumulator, value, index, collection);
  2310. });
  2311. return accumulator;
  2312. }
  2313. /**
  2314. * The base implementation of `setData` without support for hot loop detection.
  2315. *
  2316. * @private
  2317. * @param {Function} func The function to associate metadata with.
  2318. * @param {*} data The metadata.
  2319. * @returns {Function} Returns `func`.
  2320. */
  2321. var baseSetData = !metaMap ? identity : function(func, data) {
  2322. metaMap.set(func, data);
  2323. return func;
  2324. };
  2325. /**
  2326. * The base implementation of `_.slice` without an iteratee call guard.
  2327. *
  2328. * @private
  2329. * @param {Array} array The array to slice.
  2330. * @param {number} [start=0] The start position.
  2331. * @param {number} [end=array.length] The end position.
  2332. * @returns {Array} Returns the slice of `array`.
  2333. */
  2334. function baseSlice(array, start, end) {
  2335. var index = -1,
  2336. length = array.length;
  2337. start = start == null ? 0 : (+start || 0);
  2338. if (start < 0) {
  2339. start = -start > length ? 0 : (length + start);
  2340. }
  2341. end = (typeof end == 'undefined' || end > length) ? length : (+end || 0);
  2342. if (end < 0) {
  2343. end += length;
  2344. }
  2345. length = start > end ? 0 : (end - start) >>> 0;
  2346. start >>>= 0;
  2347. var result = Array(length);
  2348. while (++index < length) {
  2349. result[index] = array[index + start];
  2350. }
  2351. return result;
  2352. }
  2353. /**
  2354. * The base implementation of `_.some` without support for callback shorthands
  2355. * or `this` binding.
  2356. *
  2357. * @private
  2358. * @param {Array|Object|string} collection The collection to iterate over.
  2359. * @param {Function} predicate The function invoked per iteration.
  2360. * @returns {boolean} Returns `true` if any element passes the predicate check,
  2361. * else `false`.
  2362. */
  2363. function baseSome(collection, predicate) {
  2364. var result;
  2365. baseEach(collection, function(value, index, collection) {
  2366. result = predicate(value, index, collection);
  2367. return !result;
  2368. });
  2369. return !!result;
  2370. }
  2371. /**
  2372. * The base implementation of `_.uniq` without support for callback shorthands
  2373. * and `this` binding.
  2374. *
  2375. * @private
  2376. * @param {Array} array The array to inspect.
  2377. * @param {Function} [iteratee] The function invoked per iteration.
  2378. * @returns {Array} Returns the new duplicate-value-free array.
  2379. */
  2380. function baseUniq(array, iteratee) {
  2381. var index = -1,
  2382. indexOf = getIndexOf(),
  2383. length = array.length,
  2384. isCommon = indexOf == baseIndexOf,
  2385. isLarge = isCommon && length >= 200,
  2386. seen = isLarge && createCache(),
  2387. result = [];
  2388. if (seen) {
  2389. indexOf = cacheIndexOf;
  2390. isCommon = false;
  2391. } else {
  2392. isLarge = false;
  2393. seen = iteratee ? [] : result;
  2394. }
  2395. outer:
  2396. while (++index < length) {
  2397. var value = array[index],
  2398. computed = iteratee ? iteratee(value, index, array) : value;
  2399. if (isCommon && value === value) {
  2400. var seenIndex = seen.length;
  2401. while (seenIndex--) {
  2402. if (seen[seenIndex] === computed) {
  2403. continue outer;
  2404. }
  2405. }
  2406. if (iteratee) {
  2407. seen.push(computed);
  2408. }
  2409. result.push(value);
  2410. }
  2411. else if (indexOf(seen, computed) < 0) {
  2412. if (iteratee || isLarge) {
  2413. seen.push(computed);
  2414. }
  2415. result.push(value);
  2416. }
  2417. }
  2418. return result;
  2419. }
  2420. /**
  2421. * The base implementation of `_.values` and `_.valuesIn` which creates an
  2422. * array of `object` property values corresponding to the property names
  2423. * returned by `keysFunc`.
  2424. *
  2425. * @private
  2426. * @param {Object} object The object to query.
  2427. * @param {Array} props The property names to get values for.
  2428. * @returns {Object} Returns the array of property values.
  2429. */
  2430. function baseValues(object, props) {
  2431. var index = -1,
  2432. length = props.length,
  2433. result = Array(length);
  2434. while (++index < length) {
  2435. result[index] = object[props[index]];
  2436. }
  2437. return result;
  2438. }
  2439. /**
  2440. * The base implementation of `wrapperValue` which returns the result of
  2441. * performing a sequence of actions on the unwrapped `value`, where each
  2442. * successive action is supplied the return value of the previous.
  2443. *
  2444. * @private
  2445. * @param {*} value The unwrapped value.
  2446. * @param {Array} actions Actions to peform to resolve the unwrapped value.
  2447. * @returns {*} Returns the resolved unwrapped value.
  2448. */
  2449. function baseWrapperValue(value, actions) {
  2450. var result = value;
  2451. if (result instanceof LazyWrapper) {
  2452. result = result.value();
  2453. }
  2454. var index = -1,
  2455. length = actions.length;
  2456. while (++index < length) {
  2457. var args = [result],
  2458. action = actions[index];
  2459. push.apply(args, action.args);
  2460. result = action.func.apply(action.thisArg, args);
  2461. }
  2462. return result;
  2463. }
  2464. /**
  2465. * Performs a binary search of `array` to determine the index at which `value`
  2466. * should be inserted into `array` in order to maintain its sort order.
  2467. *
  2468. * @private
  2469. * @param {Array} array The sorted array to inspect.
  2470. * @param {*} value The value to evaluate.
  2471. * @param {boolean} [retHighest] Specify returning the highest, instead
  2472. * of the lowest, index at which a value should be inserted into `array`.
  2473. * @returns {number} Returns the index at which `value` should be inserted
  2474. * into `array`.
  2475. */
  2476. function binaryIndex(array, value, retHighest) {
  2477. var low = 0,
  2478. high = array ? array.length : low;
  2479. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  2480. while (low < high) {
  2481. var mid = (low + high) >>> 1,
  2482. computed = array[mid];
  2483. if (retHighest ? (computed <= value) : (computed < value)) {
  2484. low = mid + 1;
  2485. } else {
  2486. high = mid;
  2487. }
  2488. }
  2489. return high;
  2490. }
  2491. return binaryIndexBy(array, value, identity, retHighest);
  2492. }
  2493. /**
  2494. * This function is like `binaryIndex` except that it invokes `iteratee` for
  2495. * `value` and each element of `array` to compute their sort ranking. The
  2496. * iteratee is invoked with one argument; (value).
  2497. *
  2498. * @private
  2499. * @param {Array} array The sorted array to inspect.
  2500. * @param {*} value The value to evaluate.
  2501. * @param {Function} iteratee The function invoked per iteration.
  2502. * @param {boolean} [retHighest] Specify returning the highest, instead
  2503. * of the lowest, index at which a value should be inserted into `array`.
  2504. * @returns {number} Returns the index at which `value` should be inserted
  2505. * into `array`.
  2506. */
  2507. function binaryIndexBy(array, value, iteratee, retHighest) {
  2508. value = iteratee(value);
  2509. var low = 0,
  2510. high = array ? array.length : 0,
  2511. valIsNaN = value !== value,
  2512. valIsUndef = typeof value == 'undefined';
  2513. while (low < high) {
  2514. var mid = floor((low + high) / 2),
  2515. computed = iteratee(array[mid]),
  2516. isReflexive = computed === computed;
  2517. if (valIsNaN) {
  2518. var setLow = isReflexive || retHighest;
  2519. } else if (valIsUndef) {
  2520. setLow = isReflexive && (retHighest || typeof computed != 'undefined');
  2521. } else {
  2522. setLow = retHighest ? (computed <= value) : (computed < value);
  2523. }
  2524. if (setLow) {
  2525. low = mid + 1;
  2526. } else {
  2527. high = mid;
  2528. }
  2529. }
  2530. return nativeMin(high, MAX_ARRAY_INDEX);
  2531. }
  2532. /**
  2533. * A specialized version of `baseCallback` which only supports `this` binding
  2534. * and specifying the number of arguments to provide to `func`.
  2535. *
  2536. * @private
  2537. * @param {Function} func The function to bind.
  2538. * @param {*} thisArg The `this` binding of `func`.
  2539. * @param {number} [argCount] The number of arguments to provide to `func`.
  2540. * @returns {Function} Returns the callback.
  2541. */
  2542. function bindCallback(func, thisArg, argCount) {
  2543. if (typeof func != 'function') {
  2544. return identity;
  2545. }
  2546. if (typeof thisArg == 'undefined') {
  2547. return func;
  2548. }
  2549. switch (argCount) {
  2550. case 1: return function(value) {
  2551. return func.call(thisArg, value);
  2552. };
  2553. case 3: return function(value, index, collection) {
  2554. return func.call(thisArg, value, index, collection);
  2555. };
  2556. case 4: return function(accumulator, value, index, collection) {
  2557. return func.call(thisArg, accumulator, value, index, collection);
  2558. };
  2559. case 5: return function(value, other, key, object, source) {
  2560. return func.call(thisArg, value, other, key, object, source);
  2561. };
  2562. }
  2563. return function() {
  2564. return func.apply(thisArg, arguments);
  2565. };
  2566. }
  2567. /**
  2568. * Creates a clone of the given array buffer.
  2569. *
  2570. * @private
  2571. * @param {ArrayBuffer} buffer The array buffer to clone.
  2572. * @returns {ArrayBuffer} Returns the cloned array buffer.
  2573. */
  2574. function bufferClone(buffer) {
  2575. return bufferSlice.call(buffer, 0);
  2576. }
  2577. if (!bufferSlice) {
  2578. // PhantomJS has `ArrayBuffer` and `Uint8Array` but not `Float64Array`.
  2579. bufferClone = !(ArrayBuffer && Uint8Array) ? constant(null) : function(buffer) {
  2580. var byteLength = buffer.byteLength,
  2581. floatLength = Float64Array ? floor(byteLength / FLOAT64_BYTES_PER_ELEMENT) : 0,
  2582. offset = floatLength * FLOAT64_BYTES_PER_ELEMENT,
  2583. result = new ArrayBuffer(byteLength);
  2584. if (floatLength) {
  2585. var view = new Float64Array(result, 0, floatLength);
  2586. view.set(new Float64Array(buffer, 0, floatLength));
  2587. }
  2588. if (byteLength != offset) {
  2589. view = new Uint8Array(result, offset);
  2590. view.set(new Uint8Array(buffer, offset));
  2591. }
  2592. return result;
  2593. };
  2594. }
  2595. /**
  2596. * Creates an array that is the composition of partially applied arguments,
  2597. * placeholders, and provided arguments into a single array of arguments.
  2598. *
  2599. * @private
  2600. * @param {Array|Object} args The provided arguments.
  2601. * @param {Array} partials The arguments to prepend to those provided.
  2602. * @param {Array} holders The `partials` placeholder indexes.
  2603. * @returns {Array} Returns the new array of composed arguments.
  2604. */
  2605. function composeArgs(args, partials, holders) {
  2606. var holdersLength = holders.length,
  2607. argsIndex = -1,
  2608. argsLength = nativeMax(args.length - holdersLength, 0),
  2609. leftIndex = -1,
  2610. leftLength = partials.length,
  2611. result = Array(argsLength + leftLength);
  2612. while (++leftIndex < leftLength) {
  2613. result[leftIndex] = partials[leftIndex];
  2614. }
  2615. while (++argsIndex < holdersLength) {
  2616. result[holders[argsIndex]] = args[argsIndex];
  2617. }
  2618. while (argsLength--) {
  2619. result[leftIndex++] = args[argsIndex++];
  2620. }
  2621. return result;
  2622. }
  2623. /**
  2624. * This function is like `composeArgs` except that the arguments composition
  2625. * is tailored for `_.partialRight`.
  2626. *
  2627. * @private
  2628. * @param {Array|Object} args The provided arguments.
  2629. * @param {Array} partials The arguments to append to those provided.
  2630. * @param {Array} holders The `partials` placeholder indexes.
  2631. * @returns {Array} Returns the new array of composed arguments.
  2632. */
  2633. function composeArgsRight(args, partials, holders) {
  2634. var holdersIndex = -1,
  2635. holdersLength = holders.length,
  2636. argsIndex = -1,
  2637. argsLength = nativeMax(args.length - holdersLength, 0),
  2638. rightIndex = -1,
  2639. rightLength = partials.length,
  2640. result = Array(argsLength + rightLength);
  2641. while (++argsIndex < argsLength) {
  2642. result[argsIndex] = args[argsIndex];
  2643. }
  2644. var pad = argsIndex;
  2645. while (++rightIndex < rightLength) {
  2646. result[pad + rightIndex] = partials[rightIndex];
  2647. }
  2648. while (++holdersIndex < holdersLength) {
  2649. result[pad + holders[holdersIndex]] = args[argsIndex++];
  2650. }
  2651. return result;
  2652. }
  2653. /**
  2654. * Creates a function that aggregates a collection, creating an accumulator
  2655. * object composed from the results of running each element in the collection
  2656. * through an iteratee.
  2657. *
  2658. * @private
  2659. * @param {Function} setter The function to set keys and values of the accumulator object.
  2660. * @param {Function} [initializer] The function to initialize the accumulator object.
  2661. * @returns {Function} Returns the new aggregator function.
  2662. */
  2663. function createAggregator(setter, initializer) {
  2664. return function(collection, iteratee, thisArg) {
  2665. var result = initializer ? initializer() : {};
  2666. iteratee = getCallback(iteratee, thisArg, 3);
  2667. if (isArray(collection)) {
  2668. var index = -1,
  2669. length = collection.length;
  2670. while (++index < length) {
  2671. var value = collection[index];
  2672. setter(result, value, iteratee(value, index, collection), collection);
  2673. }
  2674. } else {
  2675. baseEach(collection, function(value, key, collection) {
  2676. setter(result, value, iteratee(value, key, collection), collection);
  2677. });
  2678. }
  2679. return result;
  2680. };
  2681. }
  2682. /**
  2683. * Creates a function that assigns properties of source object(s) to a given
  2684. * destination object.
  2685. *
  2686. * @private
  2687. * @param {Function} assigner The function to assign values.
  2688. * @returns {Function} Returns the new assigner function.
  2689. */
  2690. function createAssigner(assigner) {
  2691. return function() {
  2692. var length = arguments.length,
  2693. object = arguments[0];
  2694. if (length < 2 || object == null) {
  2695. return object;
  2696. }
  2697. if (length > 3 && isIterateeCall(arguments[1], arguments[2], arguments[3])) {
  2698. length = 2;
  2699. }
  2700. // Juggle arguments.
  2701. if (length > 3 && typeof arguments[length - 2] == 'function') {
  2702. var customizer = bindCallback(arguments[--length - 1], arguments[length--], 5);
  2703. } else if (length > 2 && typeof arguments[length - 1] == 'function') {
  2704. customizer = arguments[--length];
  2705. }
  2706. var index = 0;
  2707. while (++index < length) {
  2708. var source = arguments[index];
  2709. if (source) {
  2710. assigner(object, source, customizer);
  2711. }
  2712. }
  2713. return object;
  2714. };
  2715. }
  2716. /**
  2717. * Creates a function that wraps `func` and invokes it with the `this`
  2718. * binding of `thisArg`.
  2719. *
  2720. * @private
  2721. * @param {Function} func The function to bind.
  2722. * @param {*} [thisArg] The `this` binding of `func`.
  2723. * @returns {Function} Returns the new bound function.
  2724. */
  2725. function createBindWrapper(func, thisArg) {
  2726. var Ctor = createCtorWrapper(func);
  2727. function wrapper() {
  2728. return (this instanceof wrapper ? Ctor : func).apply(thisArg, arguments);
  2729. }
  2730. return wrapper;
  2731. }
  2732. /**
  2733. * Creates a `Set` cache object to optimize linear searches of large arrays.
  2734. *
  2735. * @private
  2736. * @param {Array} [values] The values to cache.
  2737. * @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
  2738. */
  2739. var createCache = !(nativeCreate && Set) ? constant(null) : function(values) {
  2740. return new SetCache(values);
  2741. };
  2742. /**
  2743. * Creates a function that produces compound words out of the words in a
  2744. * given string.
  2745. *
  2746. * @private
  2747. * @param {Function} callback The function to combine each word.
  2748. * @returns {Function} Returns the new compounder function.
  2749. */
  2750. function createCompounder(callback) {
  2751. return function(string) {
  2752. var index = -1,
  2753. array = words(deburr(string)),
  2754. length = array.length,
  2755. result = '';
  2756. while (++index < length) {
  2757. result = callback(result, array[index], index);
  2758. }
  2759. return result;
  2760. };
  2761. }
  2762. /**
  2763. * Creates a function that produces an instance of `Ctor` regardless of
  2764. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  2765. *
  2766. * @private
  2767. * @param {Function} Ctor The constructor to wrap.
  2768. * @returns {Function} Returns the new wrapped function.
  2769. */
  2770. function createCtorWrapper(Ctor) {
  2771. return function() {
  2772. var thisBinding = baseCreate(Ctor.prototype),
  2773. result = Ctor.apply(thisBinding, arguments);
  2774. // Mimic the constructor's `return` behavior.
  2775. // See https://es5.github.io/#x13.2.2 for more details.
  2776. return isObject(result) ? result : thisBinding;
  2777. };
  2778. }
  2779. /**
  2780. * Creates a function that gets the extremum value of a collection.
  2781. *
  2782. * @private
  2783. * @param {Function} arrayFunc The function to get the extremum value from an array.
  2784. * @param {boolean} [isMin] Specify returning the minimum, instead of the maximum,
  2785. * extremum value.
  2786. * @returns {Function} Returns the new extremum function.
  2787. */
  2788. function createExtremum(arrayFunc, isMin) {
  2789. return function(collection, iteratee, thisArg) {
  2790. if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
  2791. iteratee = null;
  2792. }
  2793. var func = getCallback(),
  2794. noIteratee = iteratee == null;
  2795. if (!(func === baseCallback && noIteratee)) {
  2796. noIteratee = false;
  2797. iteratee = func(iteratee, thisArg, 3);
  2798. }
  2799. if (noIteratee) {
  2800. var isArr = isArray(collection);
  2801. if (!isArr && isString(collection)) {
  2802. iteratee = charAtCallback;
  2803. } else {
  2804. return arrayFunc(isArr ? collection : toIterable(collection));
  2805. }
  2806. }
  2807. return extremumBy(collection, iteratee, isMin);
  2808. };
  2809. }
  2810. /**
  2811. * Creates a function that wraps `func` and invokes it with optional `this`
  2812. * binding of, partial application, and currying.
  2813. *
  2814. * @private
  2815. * @param {Function|string} func The function or method name to reference.
  2816. * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
  2817. * @param {*} [thisArg] The `this` binding of `func`.
  2818. * @param {Array} [partials] The arguments to prepend to those provided to the new function.
  2819. * @param {Array} [holders] The `partials` placeholder indexes.
  2820. * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
  2821. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  2822. * @param {Array} [argPos] The argument positions of the new function.
  2823. * @param {number} [ary] The arity cap of `func`.
  2824. * @param {number} [arity] The arity of `func`.
  2825. * @returns {Function} Returns the new wrapped function.
  2826. */
  2827. function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  2828. var isAry = bitmask & ARY_FLAG,
  2829. isBind = bitmask & BIND_FLAG,
  2830. isBindKey = bitmask & BIND_KEY_FLAG,
  2831. isCurry = bitmask & CURRY_FLAG,
  2832. isCurryBound = bitmask & CURRY_BOUND_FLAG,
  2833. isCurryRight = bitmask & CURRY_RIGHT_FLAG;
  2834. var Ctor = !isBindKey && createCtorWrapper(func),
  2835. key = func;
  2836. function wrapper() {
  2837. // Avoid `arguments` object use disqualifying optimizations by
  2838. // converting it to an array before providing it to other functions.
  2839. var length = arguments.length,
  2840. index = length,
  2841. args = Array(length);
  2842. while (index--) {
  2843. args[index] = arguments[index];
  2844. }
  2845. if (partials) {
  2846. args = composeArgs(args, partials, holders);
  2847. }
  2848. if (partialsRight) {
  2849. args = composeArgsRight(args, partialsRight, holdersRight);
  2850. }
  2851. if (isCurry || isCurryRight) {
  2852. var placeholder = wrapper.placeholder,
  2853. argsHolders = replaceHolders(args, placeholder);
  2854. length -= argsHolders.length;
  2855. if (length < arity) {
  2856. var newArgPos = argPos ? arrayCopy(argPos) : null,
  2857. newArity = nativeMax(arity - length, 0),
  2858. newsHolders = isCurry ? argsHolders : null,
  2859. newHoldersRight = isCurry ? null : argsHolders,
  2860. newPartials = isCurry ? args : null,
  2861. newPartialsRight = isCurry ? null : args;
  2862. bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
  2863. bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
  2864. if (!isCurryBound) {
  2865. bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
  2866. }
  2867. var result = createHybridWrapper(func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity);
  2868. result.placeholder = placeholder;
  2869. return result;
  2870. }
  2871. }
  2872. var thisBinding = isBind ? thisArg : this;
  2873. if (isBindKey) {
  2874. func = thisBinding[key];
  2875. }
  2876. if (argPos) {
  2877. args = reorder(args, argPos);
  2878. }
  2879. if (isAry && ary < args.length) {
  2880. args.length = ary;
  2881. }
  2882. return (this instanceof wrapper ? (Ctor || createCtorWrapper(func)) : func).apply(thisBinding, args);
  2883. }
  2884. return wrapper;
  2885. }
  2886. /**
  2887. * Creates the pad required for `string` based on the given padding length.
  2888. * The `chars` string may be truncated if the number of padding characters
  2889. * exceeds the padding length.
  2890. *
  2891. * @private
  2892. * @param {string} string The string to create padding for.
  2893. * @param {number} [length=0] The padding length.
  2894. * @param {string} [chars=' '] The string used as padding.
  2895. * @returns {string} Returns the pad for `string`.
  2896. */
  2897. function createPad(string, length, chars) {
  2898. var strLength = string.length;
  2899. length = +length;
  2900. if (strLength >= length || !nativeIsFinite(length)) {
  2901. return '';
  2902. }
  2903. var padLength = length - strLength;
  2904. chars = chars == null ? ' ' : (chars + '');
  2905. return repeat(chars, ceil(padLength / chars.length)).slice(0, padLength);
  2906. }
  2907. /**
  2908. * Creates a function that wraps `func` and invokes it with the optional `this`
  2909. * binding of `thisArg` and the `partials` prepended to those provided to
  2910. * the wrapper.
  2911. *
  2912. * @private
  2913. * @param {Function} func The function to partially apply arguments to.
  2914. * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
  2915. * @param {*} thisArg The `this` binding of `func`.
  2916. * @param {Array} partials The arguments to prepend to those provided to the new function.
  2917. * @returns {Function} Returns the new bound function.
  2918. */
  2919. function createPartialWrapper(func, bitmask, thisArg, partials) {
  2920. var isBind = bitmask & BIND_FLAG,
  2921. Ctor = createCtorWrapper(func);
  2922. function wrapper() {
  2923. // Avoid `arguments` object use disqualifying optimizations by
  2924. // converting it to an array before providing it `func`.
  2925. var argsIndex = -1,
  2926. argsLength = arguments.length,
  2927. leftIndex = -1,
  2928. leftLength = partials.length,
  2929. args = Array(argsLength + leftLength);
  2930. while (++leftIndex < leftLength) {
  2931. args[leftIndex] = partials[leftIndex];
  2932. }
  2933. while (argsLength--) {
  2934. args[leftIndex++] = arguments[++argsIndex];
  2935. }
  2936. return (this instanceof wrapper ? Ctor : func).apply(isBind ? thisArg : this, args);
  2937. }
  2938. return wrapper;
  2939. }
  2940. /**
  2941. * Creates a function that either curries or invokes `func` with optional
  2942. * `this` binding and partially applied arguments.
  2943. *
  2944. * @private
  2945. * @param {Function|string} func The function or method name to reference.
  2946. * @param {number} bitmask The bitmask of flags.
  2947. * The bitmask may be composed of the following flags:
  2948. * 1 - `_.bind`
  2949. * 2 - `_.bindKey`
  2950. * 4 - `_.curry` or `_.curryRight` of a bound function
  2951. * 8 - `_.curry`
  2952. * 16 - `_.curryRight`
  2953. * 32 - `_.partial`
  2954. * 64 - `_.partialRight`
  2955. * 128 - `_.rearg`
  2956. * 256 - `_.ary`
  2957. * @param {*} [thisArg] The `this` binding of `func`.
  2958. * @param {Array} [partials] The arguments to be partially applied.
  2959. * @param {Array} [holders] The `partials` placeholder indexes.
  2960. * @param {Array} [argPos] The argument positions of the new function.
  2961. * @param {number} [ary] The arity cap of `func`.
  2962. * @param {number} [arity] The arity of `func`.
  2963. * @returns {Function} Returns the new wrapped function.
  2964. */
  2965. function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  2966. var isBindKey = bitmask & BIND_KEY_FLAG;
  2967. if (!isBindKey && typeof func != 'function') {
  2968. throw new TypeError(FUNC_ERROR_TEXT);
  2969. }
  2970. var length = partials ? partials.length : 0;
  2971. if (!length) {
  2972. bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
  2973. partials = holders = null;
  2974. }
  2975. length -= (holders ? holders.length : 0);
  2976. if (bitmask & PARTIAL_RIGHT_FLAG) {
  2977. var partialsRight = partials,
  2978. holdersRight = holders;
  2979. partials = holders = null;
  2980. }
  2981. var data = !isBindKey && getData(func),
  2982. newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
  2983. if (data && data !== true) {
  2984. mergeData(newData, data);
  2985. bitmask = newData[1];
  2986. arity = newData[9];
  2987. }
  2988. newData[9] = arity == null
  2989. ? (isBindKey ? 0 : func.length)
  2990. : (nativeMax(arity - length, 0) || 0);
  2991. if (bitmask == BIND_FLAG) {
  2992. var result = createBindWrapper(newData[0], newData[2]);
  2993. } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
  2994. result = createPartialWrapper.apply(undefined, newData);
  2995. } else {
  2996. result = createHybridWrapper.apply(undefined, newData);
  2997. }
  2998. var setter = data ? baseSetData : setData;
  2999. return setter(result, newData);
  3000. }
  3001. /**
  3002. * A specialized version of `baseIsEqualDeep` for arrays with support for
  3003. * partial deep comparisons.
  3004. *
  3005. * @private
  3006. * @param {Array} array The array to compare.
  3007. * @param {Array} other The other array to compare.
  3008. * @param {Function} equalFunc The function to determine equivalents of values.
  3009. * @param {Function} [customizer] The function to customize comparing arrays.
  3010. * @param {boolean} [isWhere] Specify performing partial comparisons.
  3011. * @param {Array} [stackA] Tracks traversed `value` objects.
  3012. * @param {Array} [stackB] Tracks traversed `other` objects.
  3013. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  3014. */
  3015. function equalArrays(array, other, equalFunc, customizer, isWhere, stackA, stackB) {
  3016. var index = -1,
  3017. arrLength = array.length,
  3018. othLength = other.length,
  3019. result = true;
  3020. if (arrLength != othLength && !(isWhere && othLength > arrLength)) {
  3021. return false;
  3022. }
  3023. // Deep compare the contents, ignoring non-numeric properties.
  3024. while (result && ++index < arrLength) {
  3025. var arrValue = array[index],
  3026. othValue = other[index];
  3027. result = undefined;
  3028. if (customizer) {
  3029. result = isWhere
  3030. ? customizer(othValue, arrValue, index)
  3031. : customizer(arrValue, othValue, index);
  3032. }
  3033. if (typeof result == 'undefined') {
  3034. // Recursively compare arrays (susceptible to call stack limits).
  3035. if (isWhere) {
  3036. var othIndex = othLength;
  3037. while (othIndex--) {
  3038. othValue = other[othIndex];
  3039. result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isWhere, stackA, stackB);
  3040. if (result) {
  3041. break;
  3042. }
  3043. }
  3044. } else {
  3045. result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isWhere, stackA, stackB);
  3046. }
  3047. }
  3048. }
  3049. return !!result;
  3050. }
  3051. /**
  3052. * A specialized version of `baseIsEqualDeep` for comparing objects of
  3053. * the same `toStringTag`.
  3054. *
  3055. * **Note:** This function only supports comparing values with tags of
  3056. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  3057. *
  3058. * @private
  3059. * @param {Object} value The object to compare.
  3060. * @param {Object} other The other object to compare.
  3061. * @param {string} tag The `toStringTag` of the objects to compare.
  3062. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3063. */
  3064. function equalByTag(object, other, tag) {
  3065. switch (tag) {
  3066. case boolTag:
  3067. case dateTag:
  3068. // Coerce dates and booleans to numbers, dates to milliseconds and booleans
  3069. // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
  3070. return +object == +other;
  3071. case errorTag:
  3072. return object.name == other.name && object.message == other.message;
  3073. case numberTag:
  3074. // Treat `NaN` vs. `NaN` as equal.
  3075. return (object != +object)
  3076. ? other != +other
  3077. // But, treat `-0` vs. `+0` as not equal.
  3078. : (object == 0 ? ((1 / object) == (1 / other)) : object == +other);
  3079. case regexpTag:
  3080. case stringTag:
  3081. // Coerce regexes to strings and treat strings primitives and string
  3082. // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
  3083. return object == (other + '');
  3084. }
  3085. return false;
  3086. }
  3087. /**
  3088. * A specialized version of `baseIsEqualDeep` for objects with support for
  3089. * partial deep comparisons.
  3090. *
  3091. * @private
  3092. * @param {Object} object The object to compare.
  3093. * @param {Object} other The other object to compare.
  3094. * @param {Function} equalFunc The function to determine equivalents of values.
  3095. * @param {Function} [customizer] The function to customize comparing values.
  3096. * @param {boolean} [isWhere] Specify performing partial comparisons.
  3097. * @param {Array} [stackA] Tracks traversed `value` objects.
  3098. * @param {Array} [stackB] Tracks traversed `other` objects.
  3099. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3100. */
  3101. function equalObjects(object, other, equalFunc, customizer, isWhere, stackA, stackB) {
  3102. var objProps = keys(object),
  3103. objLength = objProps.length,
  3104. othProps = keys(other),
  3105. othLength = othProps.length;
  3106. if (objLength != othLength && !isWhere) {
  3107. return false;
  3108. }
  3109. var hasCtor,
  3110. index = -1;
  3111. while (++index < objLength) {
  3112. var key = objProps[index],
  3113. result = hasOwnProperty.call(other, key);
  3114. if (result) {
  3115. var objValue = object[key],
  3116. othValue = other[key];
  3117. result = undefined;
  3118. if (customizer) {
  3119. result = isWhere
  3120. ? customizer(othValue, objValue, key)
  3121. : customizer(objValue, othValue, key);
  3122. }
  3123. if (typeof result == 'undefined') {
  3124. // Recursively compare objects (susceptible to call stack limits).
  3125. result = (objValue && objValue === othValue) || equalFunc(objValue, othValue, customizer, isWhere, stackA, stackB);
  3126. }
  3127. }
  3128. if (!result) {
  3129. return false;
  3130. }
  3131. hasCtor || (hasCtor = key == 'constructor');
  3132. }
  3133. if (!hasCtor) {
  3134. var objCtor = object.constructor,
  3135. othCtor = other.constructor;
  3136. // Non `Object` object instances with different constructors are not equal.
  3137. if (objCtor != othCtor && ('constructor' in object && 'constructor' in other) &&
  3138. !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  3139. return false;
  3140. }
  3141. }
  3142. return true;
  3143. }
  3144. /**
  3145. * Gets the extremum value of `collection` invoking `iteratee` for each value
  3146. * in `collection` to generate the criterion by which the value is ranked.
  3147. * The `iteratee` is invoked with three arguments; (value, index, collection).
  3148. *
  3149. * @private
  3150. * @param {Array|Object|string} collection The collection to iterate over.
  3151. * @param {Function} iteratee The function invoked per iteration.
  3152. * @param {boolean} [isMin] Specify returning the minimum, instead of the
  3153. * maximum, extremum value.
  3154. * @returns {*} Returns the extremum value.
  3155. */
  3156. function extremumBy(collection, iteratee, isMin) {
  3157. var exValue = isMin ? POSITIVE_INFINITY : NEGATIVE_INFINITY,
  3158. computed = exValue,
  3159. result = computed;
  3160. baseEach(collection, function(value, index, collection) {
  3161. var current = iteratee(value, index, collection);
  3162. if ((isMin ? current < computed : current > computed) || (current === exValue && current === result)) {
  3163. computed = current;
  3164. result = value;
  3165. }
  3166. });
  3167. return result;
  3168. }
  3169. /**
  3170. * Gets the appropriate "callback" function. If the `_.callback` method is
  3171. * customized this function returns the custom method, otherwise it returns
  3172. * the `baseCallback` function. If arguments are provided the chosen function
  3173. * is invoked with them and its result is returned.
  3174. *
  3175. * @private
  3176. * @returns {Function} Returns the chosen function or its result.
  3177. */
  3178. function getCallback(func, thisArg, argCount) {
  3179. var result = lodash.callback || callback;
  3180. result = result === callback ? baseCallback : result;
  3181. return argCount ? result(func, thisArg, argCount) : result;
  3182. }
  3183. /**
  3184. * Gets metadata for `func`.
  3185. *
  3186. * @private
  3187. * @param {Function} func The function to query.
  3188. * @returns {*} Returns the metadata for `func`.
  3189. */
  3190. var getData = !metaMap ? noop : function(func) {
  3191. return metaMap.get(func);
  3192. };
  3193. /**
  3194. * Gets the appropriate "indexOf" function. If the `_.indexOf` method is
  3195. * customized this function returns the custom method, otherwise it returns
  3196. * the `baseIndexOf` function. If arguments are provided the chosen function
  3197. * is invoked with them and its result is returned.
  3198. *
  3199. * @private
  3200. * @returns {Function|number} Returns the chosen function or its result.
  3201. */
  3202. function getIndexOf(collection, target, fromIndex) {
  3203. var result = lodash.indexOf || indexOf;
  3204. result = result === indexOf ? baseIndexOf : result;
  3205. return collection ? result(collection, target, fromIndex) : result;
  3206. }
  3207. /**
  3208. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  3209. *
  3210. * @private
  3211. * @param {number} start The start of the view.
  3212. * @param {number} end The end of the view.
  3213. * @param {Array} [transforms] The transformations to apply to the view.
  3214. * @returns {Object} Returns an object containing the `start` and `end`
  3215. * positions of the view.
  3216. */
  3217. function getView(start, end, transforms) {
  3218. var index = -1,
  3219. length = transforms ? transforms.length : 0;
  3220. while (++index < length) {
  3221. var data = transforms[index],
  3222. size = data.size;
  3223. switch (data.type) {
  3224. case 'drop': start += size; break;
  3225. case 'dropRight': end -= size; break;
  3226. case 'take': end = nativeMin(end, start + size); break;
  3227. case 'takeRight': start = nativeMax(start, end - size); break;
  3228. }
  3229. }
  3230. return { 'start': start, 'end': end };
  3231. }
  3232. /**
  3233. * Initializes an array clone.
  3234. *
  3235. * @private
  3236. * @param {Array} array The array to clone.
  3237. * @returns {Array} Returns the initialized clone.
  3238. */
  3239. function initCloneArray(array) {
  3240. var length = array.length,
  3241. result = new array.constructor(length);
  3242. // Add array properties assigned by `RegExp#exec`.
  3243. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  3244. result.index = array.index;
  3245. result.input = array.input;
  3246. }
  3247. return result;
  3248. }
  3249. /**
  3250. * Initializes an object clone.
  3251. *
  3252. * @private
  3253. * @param {Object} object The object to clone.
  3254. * @returns {Object} Returns the initialized clone.
  3255. */
  3256. function initCloneObject(object) {
  3257. var Ctor = object.constructor;
  3258. if (!(typeof Ctor == 'function' && Ctor instanceof Ctor)) {
  3259. Ctor = Object;
  3260. }
  3261. return new Ctor;
  3262. }
  3263. /**
  3264. * Initializes an object clone based on its `toStringTag`.
  3265. *
  3266. * **Note:** This function only supports cloning values with tags of
  3267. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  3268. *
  3269. *
  3270. * @private
  3271. * @param {Object} object The object to clone.
  3272. * @param {string} tag The `toStringTag` of the object to clone.
  3273. * @param {boolean} [isDeep] Specify a deep clone.
  3274. * @returns {Object} Returns the initialized clone.
  3275. */
  3276. function initCloneByTag(object, tag, isDeep) {
  3277. var Ctor = object.constructor;
  3278. switch (tag) {
  3279. case arrayBufferTag:
  3280. return bufferClone(object);
  3281. case boolTag:
  3282. case dateTag:
  3283. return new Ctor(+object);
  3284. case float32Tag: case float64Tag:
  3285. case int8Tag: case int16Tag: case int32Tag:
  3286. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  3287. var buffer = object.buffer;
  3288. return new Ctor(isDeep ? bufferClone(buffer) : buffer, object.byteOffset, object.length);
  3289. case numberTag:
  3290. case stringTag:
  3291. return new Ctor(object);
  3292. case regexpTag:
  3293. var result = new Ctor(object.source, reFlags.exec(object));
  3294. result.lastIndex = object.lastIndex;
  3295. }
  3296. return result;
  3297. }
  3298. /**
  3299. * Checks if `func` is eligible for `this` binding.
  3300. *
  3301. * @private
  3302. * @param {Function} func The function to check.
  3303. * @returns {boolean} Returns `true` if `func` is eligible, else `false`.
  3304. */
  3305. function isBindable(func) {
  3306. var support = lodash.support,
  3307. result = !(support.funcNames ? func.name : support.funcDecomp);
  3308. if (!result) {
  3309. var source = fnToString.call(func);
  3310. if (!support.funcNames) {
  3311. result = !reFuncName.test(source);
  3312. }
  3313. if (!result) {
  3314. // Check if `func` references the `this` keyword and store the result.
  3315. result = reThis.test(source) || isNative(func);
  3316. baseSetData(func, result);
  3317. }
  3318. }
  3319. return result;
  3320. }
  3321. /**
  3322. * Checks if `value` is a valid array-like index.
  3323. *
  3324. * @private
  3325. * @param {*} value The value to check.
  3326. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  3327. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  3328. */
  3329. function isIndex(value, length) {
  3330. value = +value;
  3331. length = length == null ? MAX_SAFE_INTEGER : length;
  3332. return value > -1 && value % 1 == 0 && value < length;
  3333. }
  3334. /**
  3335. * Checks if the provided arguments are from an iteratee call.
  3336. *
  3337. * @private
  3338. * @param {*} value The potential iteratee value argument.
  3339. * @param {*} index The potential iteratee index or key argument.
  3340. * @param {*} object The potential iteratee object argument.
  3341. * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
  3342. */
  3343. function isIterateeCall(value, index, object) {
  3344. if (!isObject(object)) {
  3345. return false;
  3346. }
  3347. var type = typeof index;
  3348. if (type == 'number') {
  3349. var length = object.length,
  3350. prereq = isLength(length) && isIndex(index, length);
  3351. } else {
  3352. prereq = type == 'string' && index in object;
  3353. }
  3354. var other = object[index];
  3355. return prereq && (value === value ? value === other : other !== other);
  3356. }
  3357. /**
  3358. * Checks if `value` is a valid array-like length.
  3359. *
  3360. * **Note:** This function is based on ES `ToLength`. See the
  3361. * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength)
  3362. * for more details.
  3363. *
  3364. * @private
  3365. * @param {*} value The value to check.
  3366. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  3367. */
  3368. function isLength(value) {
  3369. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  3370. }
  3371. /**
  3372. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  3373. *
  3374. * @private
  3375. * @param {*} value The value to check.
  3376. * @returns {boolean} Returns `true` if `value` if suitable for strict
  3377. * equality comparisons, else `false`.
  3378. */
  3379. function isStrictComparable(value) {
  3380. return value === value && (value === 0 ? ((1 / value) > 0) : !isObject(value));
  3381. }
  3382. /**
  3383. * Merges the function metadata of `source` into `data`.
  3384. *
  3385. * Merging metadata reduces the number of wrappers required to invoke a function.
  3386. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  3387. * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
  3388. * augment function arguments, making the order in which they are executed important,
  3389. * preventing the merging of metadata. However, we make an exception for a safe
  3390. * common case where curried functions have `_.ary` and or `_.rearg` applied.
  3391. *
  3392. * @private
  3393. * @param {Array} data The destination metadata.
  3394. * @param {Array} source The source metadata.
  3395. * @returns {Array} Returns `data`.
  3396. */
  3397. function mergeData(data, source) {
  3398. var bitmask = data[1],
  3399. srcBitmask = source[1],
  3400. newBitmask = bitmask | srcBitmask;
  3401. var arityFlags = ARY_FLAG | REARG_FLAG,
  3402. bindFlags = BIND_FLAG | BIND_KEY_FLAG,
  3403. comboFlags = arityFlags | bindFlags | CURRY_BOUND_FLAG | CURRY_RIGHT_FLAG;
  3404. var isAry = bitmask & ARY_FLAG && !(srcBitmask & ARY_FLAG),
  3405. isRearg = bitmask & REARG_FLAG && !(srcBitmask & REARG_FLAG),
  3406. argPos = (isRearg ? data : source)[7],
  3407. ary = (isAry ? data : source)[8];
  3408. var isCommon = !(bitmask >= REARG_FLAG && srcBitmask > bindFlags) &&
  3409. !(bitmask > bindFlags && srcBitmask >= REARG_FLAG);
  3410. var isCombo = (newBitmask >= arityFlags && newBitmask <= comboFlags) &&
  3411. (bitmask < REARG_FLAG || ((isRearg || isAry) && argPos.length <= ary));
  3412. // Exit early if metadata can't be merged.
  3413. if (!(isCommon || isCombo)) {
  3414. return data;
  3415. }
  3416. // Use source `thisArg` if available.
  3417. if (srcBitmask & BIND_FLAG) {
  3418. data[2] = source[2];
  3419. // Set when currying a bound function.
  3420. newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
  3421. }
  3422. // Compose partial arguments.
  3423. var value = source[3];
  3424. if (value) {
  3425. var partials = data[3];
  3426. data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
  3427. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
  3428. }
  3429. // Compose partial right arguments.
  3430. value = source[5];
  3431. if (value) {
  3432. partials = data[5];
  3433. data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
  3434. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
  3435. }
  3436. // Use source `argPos` if available.
  3437. value = source[7];
  3438. if (value) {
  3439. data[7] = arrayCopy(value);
  3440. }
  3441. // Use source `ary` if it's smaller.
  3442. if (srcBitmask & ARY_FLAG) {
  3443. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  3444. }
  3445. // Use source `arity` if one is not provided.
  3446. if (data[9] == null) {
  3447. data[9] = source[9];
  3448. }
  3449. // Use source `func` and merge bitmasks.
  3450. data[0] = source[0];
  3451. data[1] = newBitmask;
  3452. return data;
  3453. }
  3454. /**
  3455. * A specialized version of `_.pick` that picks `object` properties specified
  3456. * by the `props` array.
  3457. *
  3458. * @private
  3459. * @param {Object} object The source object.
  3460. * @param {string[]} props The property names to pick.
  3461. * @returns {Object} Returns the new object.
  3462. */
  3463. function pickByArray(object, props) {
  3464. object = toObject(object);
  3465. var index = -1,
  3466. length = props.length,
  3467. result = {};
  3468. while (++index < length) {
  3469. var key = props[index];
  3470. if (key in object) {
  3471. result[key] = object[key];
  3472. }
  3473. }
  3474. return result;
  3475. }
  3476. /**
  3477. * A specialized version of `_.pick` that picks `object` properties `predicate`
  3478. * returns truthy for.
  3479. *
  3480. * @private
  3481. * @param {Object} object The source object.
  3482. * @param {Function} predicate The function invoked per iteration.
  3483. * @returns {Object} Returns the new object.
  3484. */
  3485. function pickByCallback(object, predicate) {
  3486. var result = {};
  3487. baseForIn(object, function(value, key, object) {
  3488. if (predicate(value, key, object)) {
  3489. result[key] = value;
  3490. }
  3491. });
  3492. return result;
  3493. }
  3494. /**
  3495. * Reorder `array` according to the specified indexes where the element at
  3496. * the first index is assigned as the first element, the element at
  3497. * the second index is assigned as the second element, and so on.
  3498. *
  3499. * @private
  3500. * @param {Array} array The array to reorder.
  3501. * @param {Array} indexes The arranged array indexes.
  3502. * @returns {Array} Returns `array`.
  3503. */
  3504. function reorder(array, indexes) {
  3505. var arrLength = array.length,
  3506. length = nativeMin(indexes.length, arrLength),
  3507. oldArray = arrayCopy(array);
  3508. while (length--) {
  3509. var index = indexes[length];
  3510. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  3511. }
  3512. return array;
  3513. }
  3514. /**
  3515. * Sets metadata for `func`.
  3516. *
  3517. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  3518. * period of time, it will trip its breaker and transition to an identity function
  3519. * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
  3520. * for more details.
  3521. *
  3522. * @private
  3523. * @param {Function} func The function to associate metadata with.
  3524. * @param {*} data The metadata.
  3525. * @returns {Function} Returns `func`.
  3526. */
  3527. var setData = (function() {
  3528. var count = 0,
  3529. lastCalled = 0;
  3530. return function(key, value) {
  3531. var stamp = now(),
  3532. remaining = HOT_SPAN - (stamp - lastCalled);
  3533. lastCalled = stamp;
  3534. if (remaining > 0) {
  3535. if (++count >= HOT_COUNT) {
  3536. return key;
  3537. }
  3538. } else {
  3539. count = 0;
  3540. }
  3541. return baseSetData(key, value);
  3542. };
  3543. }());
  3544. /**
  3545. * A fallback implementation of `_.isPlainObject` which checks if `value`
  3546. * is an object created by the `Object` constructor or has a `[[Prototype]]`
  3547. * of `null`.
  3548. *
  3549. * @private
  3550. * @param {*} value The value to check.
  3551. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  3552. */
  3553. function shimIsPlainObject(value) {
  3554. var Ctor,
  3555. support = lodash.support;
  3556. // Exit early for non `Object` objects.
  3557. if (!(isObjectLike(value) && objToString.call(value) == objectTag) ||
  3558. (!hasOwnProperty.call(value, 'constructor') &&
  3559. (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
  3560. return false;
  3561. }
  3562. // IE < 9 iterates inherited properties before own properties. If the first
  3563. // iterated property is an object's own property then there are no inherited
  3564. // enumerable properties.
  3565. var result;
  3566. // In most environments an object's own properties are iterated before
  3567. // its inherited properties. If the last iterated property is an object's
  3568. // own property then there are no inherited enumerable properties.
  3569. baseForIn(value, function(subValue, key) {
  3570. result = key;
  3571. });
  3572. return typeof result == 'undefined' || hasOwnProperty.call(value, result);
  3573. }
  3574. /**
  3575. * A fallback implementation of `Object.keys` which creates an array of the
  3576. * own enumerable property names of `object`.
  3577. *
  3578. * @private
  3579. * @param {Object} object The object to inspect.
  3580. * @returns {Array} Returns the array of property names.
  3581. */
  3582. function shimKeys(object) {
  3583. var props = keysIn(object),
  3584. propsLength = props.length,
  3585. length = propsLength && object.length,
  3586. support = lodash.support;
  3587. var allowIndexes = length && isLength(length) &&
  3588. (isArray(object) || (support.nonEnumArgs && isArguments(object)));
  3589. var index = -1,
  3590. result = [];
  3591. while (++index < propsLength) {
  3592. var key = props[index];
  3593. if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
  3594. result.push(key);
  3595. }
  3596. }
  3597. return result;
  3598. }
  3599. /**
  3600. * Converts `value` to an array-like object if it is not one.
  3601. *
  3602. * @private
  3603. * @param {*} value The value to process.
  3604. * @returns {Array|Object} Returns the array-like object.
  3605. */
  3606. function toIterable(value) {
  3607. if (value == null) {
  3608. return [];
  3609. }
  3610. if (!isLength(value.length)) {
  3611. return values(value);
  3612. }
  3613. return isObject(value) ? value : Object(value);
  3614. }
  3615. /**
  3616. * Converts `value` to an object if it is not one.
  3617. *
  3618. * @private
  3619. * @param {*} value The value to process.
  3620. * @returns {Object} Returns the object.
  3621. */
  3622. function toObject(value) {
  3623. return isObject(value) ? value : Object(value);
  3624. }
  3625. /**
  3626. * Creates a clone of `wrapper`.
  3627. *
  3628. * @private
  3629. * @param {Object} wrapper The wrapper to clone.
  3630. * @returns {Object} Returns the cloned wrapper.
  3631. */
  3632. function wrapperClone(wrapper) {
  3633. return wrapper instanceof LazyWrapper
  3634. ? wrapper.clone()
  3635. : new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
  3636. }
  3637. /*------------------------------------------------------------------------*/
  3638. /**
  3639. * Creates an array of elements split into groups the length of `size`.
  3640. * If `collection` can't be split evenly, the final chunk will be the remaining
  3641. * elements.
  3642. *
  3643. * @static
  3644. * @memberOf _
  3645. * @category Array
  3646. * @param {Array} array The array to process.
  3647. * @param {number} [size=1] The length of each chunk.
  3648. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  3649. * @returns {Array} Returns the new array containing chunks.
  3650. * @example
  3651. *
  3652. * _.chunk(['a', 'b', 'c', 'd'], 2);
  3653. * // => [['a', 'b'], ['c', 'd']]
  3654. *
  3655. * _.chunk(['a', 'b', 'c', 'd'], 3);
  3656. * // => [['a', 'b', 'c'], ['d']]
  3657. */
  3658. function chunk(array, size, guard) {
  3659. if (guard ? isIterateeCall(array, size, guard) : size == null) {
  3660. size = 1;
  3661. } else {
  3662. size = nativeMax(+size || 1, 1);
  3663. }
  3664. var index = 0,
  3665. length = array ? array.length : 0,
  3666. resIndex = -1,
  3667. result = Array(ceil(length / size));
  3668. while (index < length) {
  3669. result[++resIndex] = baseSlice(array, index, (index += size));
  3670. }
  3671. return result;
  3672. }
  3673. /**
  3674. * Creates an array with all falsey values removed. The values `false`, `null`,
  3675. * `0`, `""`, `undefined`, and `NaN` are falsey.
  3676. *
  3677. * @static
  3678. * @memberOf _
  3679. * @category Array
  3680. * @param {Array} array The array to compact.
  3681. * @returns {Array} Returns the new array of filtered values.
  3682. * @example
  3683. *
  3684. * _.compact([0, 1, false, 2, '', 3]);
  3685. * // => [1, 2, 3]
  3686. */
  3687. function compact(array) {
  3688. var index = -1,
  3689. length = array ? array.length : 0,
  3690. resIndex = -1,
  3691. result = [];
  3692. while (++index < length) {
  3693. var value = array[index];
  3694. if (value) {
  3695. result[++resIndex] = value;
  3696. }
  3697. }
  3698. return result;
  3699. }
  3700. /**
  3701. * Creates an array excluding all values of the provided arrays using
  3702. * `SameValueZero` for equality comparisons.
  3703. *
  3704. * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
  3705. * e.g. `===`, except that `NaN` matches `NaN`. See the
  3706. * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
  3707. * for more details.
  3708. *
  3709. * @static
  3710. * @memberOf _
  3711. * @category Array
  3712. * @param {Array} array The array to inspect.
  3713. * @param {...Array} [values] The arrays of values to exclude.
  3714. * @returns {Array} Returns the new array of filtered values.
  3715. * @example
  3716. *
  3717. * _.difference([1, 2, 3], [4, 2]);
  3718. * // => [1, 3]
  3719. */
  3720. function difference() {
  3721. var index = -1,
  3722. length = arguments.length;
  3723. while (++index < length) {
  3724. var value = arguments[index];
  3725. if (isArray(value) || isArguments(value)) {
  3726. break;
  3727. }
  3728. }
  3729. return baseDifference(value, baseFlatten(arguments, false, true, ++index));
  3730. }
  3731. /**
  3732. * Creates a slice of `array` with `n` elements dropped from the beginning.
  3733. *
  3734. * @static
  3735. * @memberOf _
  3736. * @category Array
  3737. * @param {Array} array The array to query.
  3738. * @param {number} [n=1] The number of elements to drop.
  3739. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  3740. * @returns {Array} Returns the slice of `array`.
  3741. * @example
  3742. *
  3743. * _.drop([1, 2, 3]);
  3744. * // => [2, 3]
  3745. *
  3746. * _.drop([1, 2, 3], 2);
  3747. * // => [3]
  3748. *
  3749. * _.drop([1, 2, 3], 5);
  3750. * // => []
  3751. *
  3752. * _.drop([1, 2, 3], 0);
  3753. * // => [1, 2, 3]
  3754. */
  3755. function drop(array, n, guard) {
  3756. var length = array ? array.length : 0;
  3757. if (!length) {
  3758. return [];
  3759. }
  3760. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  3761. n = 1;
  3762. }
  3763. return baseSlice(array, n < 0 ? 0 : n);
  3764. }
  3765. /**
  3766. * Creates a slice of `array` with `n` elements dropped from the end.
  3767. *
  3768. * @static
  3769. * @memberOf _
  3770. * @category Array
  3771. * @param {Array} array The array to query.
  3772. * @param {number} [n=1] The number of elements to drop.
  3773. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  3774. * @returns {Array} Returns the slice of `array`.
  3775. * @example
  3776. *
  3777. * _.dropRight([1, 2, 3]);
  3778. * // => [1, 2]
  3779. *
  3780. * _.dropRight([1, 2, 3], 2);
  3781. * // => [1]
  3782. *
  3783. * _.dropRight([1, 2, 3], 5);
  3784. * // => []
  3785. *
  3786. * _.dropRight([1, 2, 3], 0);
  3787. * // => [1, 2, 3]
  3788. */
  3789. function dropRight(array, n, guard) {
  3790. var length = array ? array.length : 0;
  3791. if (!length) {
  3792. return [];
  3793. }
  3794. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  3795. n = 1;
  3796. }
  3797. n = length - (+n || 0);
  3798. return baseSlice(array, 0, n < 0 ? 0 : n);
  3799. }
  3800. /**
  3801. * Creates a slice of `array` excluding elements dropped from the end.
  3802. * Elements are dropped until `predicate` returns falsey. The predicate is
  3803. * bound to `thisArg` and invoked with three arguments; (value, index, array).
  3804. *
  3805. * If a property name is provided for `predicate` the created `_.property`
  3806. * style callback returns the property value of the given element.
  3807. *
  3808. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  3809. * style callback returns `true` for elements that have a matching property
  3810. * value, else `false`.
  3811. *
  3812. * If an object is provided for `predicate` the created `_.matches` style
  3813. * callback returns `true` for elements that match the properties of the given
  3814. * object, else `false`.
  3815. *
  3816. * @static
  3817. * @memberOf _
  3818. * @category Array
  3819. * @param {Array} array The array to query.
  3820. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  3821. * per iteration.
  3822. * @param {*} [thisArg] The `this` binding of `predicate`.
  3823. * @returns {Array} Returns the slice of `array`.
  3824. * @example
  3825. *
  3826. * _.dropRightWhile([1, 2, 3], function(n) {
  3827. * return n > 1;
  3828. * });
  3829. * // => [1]
  3830. *
  3831. * var users = [
  3832. * { 'user': 'barney', 'active': true },
  3833. * { 'user': 'fred', 'active': false },
  3834. * { 'user': 'pebbles', 'active': false }
  3835. * ];
  3836. *
  3837. * // using the `_.matches` callback shorthand
  3838. * _.pluck(_.dropRightWhile(users, { 'user': pebbles, 'active': false }), 'user');
  3839. * // => ['barney', 'fred']
  3840. *
  3841. * // using the `_.matchesProperty` callback shorthand
  3842. * _.pluck(_.dropRightWhile(users, 'active', false), 'user');
  3843. * // => ['barney']
  3844. *
  3845. * // using the `_.property` callback shorthand
  3846. * _.pluck(_.dropRightWhile(users, 'active'), 'user');
  3847. * // => ['barney', 'fred', 'pebbles']
  3848. */
  3849. function dropRightWhile(array, predicate, thisArg) {
  3850. var length = array ? array.length : 0;
  3851. if (!length) {
  3852. return [];
  3853. }
  3854. predicate = getCallback(predicate, thisArg, 3);
  3855. while (length-- && predicate(array[length], length, array)) {}
  3856. return baseSlice(array, 0, length + 1);
  3857. }
  3858. /**
  3859. * Creates a slice of `array` excluding elements dropped from the beginning.
  3860. * Elements are dropped until `predicate` returns falsey. The predicate is
  3861. * bound to `thisArg` and invoked with three arguments; (value, index, array).
  3862. *
  3863. * If a property name is provided for `predicate` the created `_.property`
  3864. * style callback returns the property value of the given element.
  3865. *
  3866. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  3867. * style callback returns `true` for elements that have a matching property
  3868. * value, else `false`.
  3869. *
  3870. * If an object is provided for `predicate` the created `_.matches` style
  3871. * callback returns `true` for elements that have the properties of the given
  3872. * object, else `false`.
  3873. *
  3874. * @static
  3875. * @memberOf _
  3876. * @category Array
  3877. * @param {Array} array The array to query.
  3878. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  3879. * per iteration.
  3880. * @param {*} [thisArg] The `this` binding of `predicate`.
  3881. * @returns {Array} Returns the slice of `array`.
  3882. * @example
  3883. *
  3884. * _.dropWhile([1, 2, 3], function(n) {
  3885. * return n < 3;
  3886. * });
  3887. * // => [3]
  3888. *
  3889. * var users = [
  3890. * { 'user': 'barney', 'active': false },
  3891. * { 'user': 'fred', 'active': false },
  3892. * { 'user': 'pebbles', 'active': true }
  3893. * ];
  3894. *
  3895. * // using the `_.matches` callback shorthand
  3896. * _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
  3897. * // => ['fred', 'pebbles']
  3898. *
  3899. * // using the `_.matchesProperty` callback shorthand
  3900. * _.pluck(_.dropWhile(users, 'active', false), 'user');
  3901. * // => ['pebbles']
  3902. *
  3903. * // using the `_.property` callback shorthand
  3904. * _.pluck(_.dropWhile(users, 'active'), 'user');
  3905. * // => ['barney', 'fred', 'pebbles']
  3906. */
  3907. function dropWhile(array, predicate, thisArg) {
  3908. var length = array ? array.length : 0;
  3909. if (!length) {
  3910. return [];
  3911. }
  3912. var index = -1;
  3913. predicate = getCallback(predicate, thisArg, 3);
  3914. while (++index < length && predicate(array[index], index, array)) {}
  3915. return baseSlice(array, index);
  3916. }
  3917. /**
  3918. * Fills elements of `array` with `value` from `start` up to, but not
  3919. * including, `end`.
  3920. *
  3921. * **Note:** This method mutates `array`.
  3922. *
  3923. * @static
  3924. * @memberOf _
  3925. * @category Array
  3926. * @param {Array} array The array to fill.
  3927. * @param {*} value The value to fill `array` with.
  3928. * @param {number} [start=0] The start position.
  3929. * @param {number} [end=array.length] The end position.
  3930. * @returns {Array} Returns `array`.
  3931. */
  3932. function fill(array, value, start, end) {
  3933. var length = array ? array.length : 0;
  3934. if (!length) {
  3935. return [];
  3936. }
  3937. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  3938. start = 0;
  3939. end = length;
  3940. }
  3941. return baseFill(array, value, start, end);
  3942. }
  3943. /**
  3944. * This method is like `_.find` except that it returns the index of the first
  3945. * element `predicate` returns truthy for, instead of the element itself.
  3946. *
  3947. * If a property name is provided for `predicate` the created `_.property`
  3948. * style callback returns the property value of the given element.
  3949. *
  3950. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  3951. * style callback returns `true` for elements that have a matching property
  3952. * value, else `false`.
  3953. *
  3954. * If an object is provided for `predicate` the created `_.matches` style
  3955. * callback returns `true` for elements that have the properties of the given
  3956. * object, else `false`.
  3957. *
  3958. * @static
  3959. * @memberOf _
  3960. * @category Array
  3961. * @param {Array} array The array to search.
  3962. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  3963. * per iteration.
  3964. * @param {*} [thisArg] The `this` binding of `predicate`.
  3965. * @returns {number} Returns the index of the found element, else `-1`.
  3966. * @example
  3967. *
  3968. * var users = [
  3969. * { 'user': 'barney', 'active': false },
  3970. * { 'user': 'fred', 'active': false },
  3971. * { 'user': 'pebbles', 'active': true }
  3972. * ];
  3973. *
  3974. * _.findIndex(users, function(chr) {
  3975. * return chr.user == 'barney';
  3976. * });
  3977. * // => 0
  3978. *
  3979. * // using the `_.matches` callback shorthand
  3980. * _.findIndex(users, { 'user': 'fred', 'active': false });
  3981. * // => 1
  3982. *
  3983. * // using the `_.matchesProperty` callback shorthand
  3984. * _.findIndex(users, 'active', false);
  3985. * // => 0
  3986. *
  3987. * // using the `_.property` callback shorthand
  3988. * _.findIndex(users, 'active');
  3989. * // => 2
  3990. */
  3991. function findIndex(array, predicate, thisArg) {
  3992. var index = -1,
  3993. length = array ? array.length : 0;
  3994. predicate = getCallback(predicate, thisArg, 3);
  3995. while (++index < length) {
  3996. if (predicate(array[index], index, array)) {
  3997. return index;
  3998. }
  3999. }
  4000. return -1;
  4001. }
  4002. /**
  4003. * This method is like `_.findIndex` except that it iterates over elements
  4004. * of `collection` from right to left.
  4005. *
  4006. * If a property name is provided for `predicate` the created `_.property`
  4007. * style callback returns the property value of the given element.
  4008. *
  4009. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4010. * style callback returns `true` for elements that have a matching property
  4011. * value, else `false`.
  4012. *
  4013. * If an object is provided for `predicate` the created `_.matches` style
  4014. * callback returns `true` for elements that have the properties of the given
  4015. * object, else `false`.
  4016. *
  4017. * @static
  4018. * @memberOf _
  4019. * @category Array
  4020. * @param {Array} array The array to search.
  4021. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4022. * per iteration.
  4023. * @param {*} [thisArg] The `this` binding of `predicate`.
  4024. * @returns {number} Returns the index of the found element, else `-1`.
  4025. * @example
  4026. *
  4027. * var users = [
  4028. * { 'user': 'barney', 'active': true },
  4029. * { 'user': 'fred', 'active': false },
  4030. * { 'user': 'pebbles', 'active': false }
  4031. * ];
  4032. *
  4033. * _.findLastIndex(users, function(chr) {
  4034. * return chr.user == 'pebbles';
  4035. * });
  4036. * // => 2
  4037. *
  4038. * // using the `_.matches` callback shorthand
  4039. * _.findLastIndex(users, { user': 'barney', 'active': true });
  4040. * // => 0
  4041. *
  4042. * // using the `_.matchesProperty` callback shorthand
  4043. * _.findLastIndex(users, 'active', false);
  4044. * // => 1
  4045. *
  4046. * // using the `_.property` callback shorthand
  4047. * _.findLastIndex(users, 'active');
  4048. * // => 0
  4049. */
  4050. function findLastIndex(array, predicate, thisArg) {
  4051. var length = array ? array.length : 0;
  4052. predicate = getCallback(predicate, thisArg, 3);
  4053. while (length--) {
  4054. if (predicate(array[length], length, array)) {
  4055. return length;
  4056. }
  4057. }
  4058. return -1;
  4059. }
  4060. /**
  4061. * Gets the first element of `array`.
  4062. *
  4063. * @static
  4064. * @memberOf _
  4065. * @alias head
  4066. * @category Array
  4067. * @param {Array} array The array to query.
  4068. * @returns {*} Returns the first element of `array`.
  4069. * @example
  4070. *
  4071. * _.first([1, 2, 3]);
  4072. * // => 1
  4073. *
  4074. * _.first([]);
  4075. * // => undefined
  4076. */
  4077. function first(array) {
  4078. return array ? array[0] : undefined;
  4079. }
  4080. /**
  4081. * Flattens a nested array. If `isDeep` is `true` the array is recursively
  4082. * flattened, otherwise it is only flattened a single level.
  4083. *
  4084. * @static
  4085. * @memberOf _
  4086. * @category Array
  4087. * @param {Array} array The array to flatten.
  4088. * @param {boolean} [isDeep] Specify a deep flatten.
  4089. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  4090. * @returns {Array} Returns the new flattened array.
  4091. * @example
  4092. *
  4093. * _.flatten([1, [2, 3, [4]]]);
  4094. * // => [1, 2, 3, [4]];
  4095. *
  4096. * // using `isDeep`
  4097. * _.flatten([1, [2, 3, [4]]], true);
  4098. * // => [1, 2, 3, 4];
  4099. */
  4100. function flatten(array, isDeep, guard) {
  4101. var length = array ? array.length : 0;
  4102. if (guard && isIterateeCall(array, isDeep, guard)) {
  4103. isDeep = false;
  4104. }
  4105. return length ? baseFlatten(array, isDeep) : [];
  4106. }
  4107. /**
  4108. * Recursively flattens a nested array.
  4109. *
  4110. * @static
  4111. * @memberOf _
  4112. * @category Array
  4113. * @param {Array} array The array to recursively flatten.
  4114. * @returns {Array} Returns the new flattened array.
  4115. * @example
  4116. *
  4117. * _.flattenDeep([1, [2, 3, [4]]]);
  4118. * // => [1, 2, 3, 4];
  4119. */
  4120. function flattenDeep(array) {
  4121. var length = array ? array.length : 0;
  4122. return length ? baseFlatten(array, true) : [];
  4123. }
  4124. /**
  4125. * Gets the index at which the first occurrence of `value` is found in `array`
  4126. * using `SameValueZero` for equality comparisons. If `fromIndex` is negative,
  4127. * it is used as the offset from the end of `array`. If `array` is sorted
  4128. * providing `true` for `fromIndex` performs a faster binary search.
  4129. *
  4130. * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
  4131. * e.g. `===`, except that `NaN` matches `NaN`. See the
  4132. * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
  4133. * for more details.
  4134. *
  4135. * @static
  4136. * @memberOf _
  4137. * @category Array
  4138. * @param {Array} array The array to search.
  4139. * @param {*} value The value to search for.
  4140. * @param {boolean|number} [fromIndex=0] The index to search from or `true`
  4141. * to perform a binary search on a sorted array.
  4142. * @returns {number} Returns the index of the matched value, else `-1`.
  4143. * @example
  4144. *
  4145. * _.indexOf([1, 2, 1, 2], 2);
  4146. * // => 2
  4147. *
  4148. * // using `fromIndex`
  4149. * _.indexOf([1, 2, 1, 2], 2, 2);
  4150. * // => 3
  4151. *
  4152. * // performing a binary search
  4153. * _.indexOf([1, 1, 2, 2], 2, true);
  4154. * // => 2
  4155. */
  4156. function indexOf(array, value, fromIndex) {
  4157. var length = array ? array.length : 0;
  4158. if (!length) {
  4159. return -1;
  4160. }
  4161. if (typeof fromIndex == 'number') {
  4162. fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
  4163. } else if (fromIndex) {
  4164. var index = binaryIndex(array, value),
  4165. other = array[index];
  4166. return (value === value ? value === other : other !== other) ? index : -1;
  4167. }
  4168. return baseIndexOf(array, value, fromIndex);
  4169. }
  4170. /**
  4171. * Gets all but the last element of `array`.
  4172. *
  4173. * @static
  4174. * @memberOf _
  4175. * @category Array
  4176. * @param {Array} array The array to query.
  4177. * @returns {Array} Returns the slice of `array`.
  4178. * @example
  4179. *
  4180. * _.initial([1, 2, 3]);
  4181. * // => [1, 2]
  4182. */
  4183. function initial(array) {
  4184. return dropRight(array, 1);
  4185. }
  4186. /**
  4187. * Creates an array of unique values in all provided arrays using `SameValueZero`
  4188. * for equality comparisons.
  4189. *
  4190. * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
  4191. * e.g. `===`, except that `NaN` matches `NaN`. See the
  4192. * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
  4193. * for more details.
  4194. *
  4195. * @static
  4196. * @memberOf _
  4197. * @category Array
  4198. * @param {...Array} [arrays] The arrays to inspect.
  4199. * @returns {Array} Returns the new array of shared values.
  4200. * @example
  4201. * _.intersection([1, 2], [4, 2], [2, 1]);
  4202. * // => [2]
  4203. */
  4204. function intersection() {
  4205. var args = [],
  4206. argsIndex = -1,
  4207. argsLength = arguments.length,
  4208. caches = [],
  4209. indexOf = getIndexOf(),
  4210. isCommon = indexOf == baseIndexOf;
  4211. while (++argsIndex < argsLength) {
  4212. var value = arguments[argsIndex];
  4213. if (isArray(value) || isArguments(value)) {
  4214. args.push(value);
  4215. caches.push(isCommon && value.length >= 120 && createCache(argsIndex && value));
  4216. }
  4217. }
  4218. argsLength = args.length;
  4219. var array = args[0],
  4220. index = -1,
  4221. length = array ? array.length : 0,
  4222. result = [],
  4223. seen = caches[0];
  4224. outer:
  4225. while (++index < length) {
  4226. value = array[index];
  4227. if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value)) < 0) {
  4228. argsIndex = argsLength;
  4229. while (--argsIndex) {
  4230. var cache = caches[argsIndex];
  4231. if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value)) < 0) {
  4232. continue outer;
  4233. }
  4234. }
  4235. if (seen) {
  4236. seen.push(value);
  4237. }
  4238. result.push(value);
  4239. }
  4240. }
  4241. return result;
  4242. }
  4243. /**
  4244. * Gets the last element of `array`.
  4245. *
  4246. * @static
  4247. * @memberOf _
  4248. * @category Array
  4249. * @param {Array} array The array to query.
  4250. * @returns {*} Returns the last element of `array`.
  4251. * @example
  4252. *
  4253. * _.last([1, 2, 3]);
  4254. * // => 3
  4255. */
  4256. function last(array) {
  4257. var length = array ? array.length : 0;
  4258. return length ? array[length - 1] : undefined;
  4259. }
  4260. /**
  4261. * This method is like `_.indexOf` except that it iterates over elements of
  4262. * `array` from right to left.
  4263. *
  4264. * @static
  4265. * @memberOf _
  4266. * @category Array
  4267. * @param {Array} array The array to search.
  4268. * @param {*} value The value to search for.
  4269. * @param {boolean|number} [fromIndex=array.length-1] The index to search from
  4270. * or `true` to perform a binary search on a sorted array.
  4271. * @returns {number} Returns the index of the matched value, else `-1`.
  4272. * @example
  4273. *
  4274. * _.lastIndexOf([1, 2, 1, 2], 2);
  4275. * // => 3
  4276. *
  4277. * // using `fromIndex`
  4278. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  4279. * // => 1
  4280. *
  4281. * // performing a binary search
  4282. * _.lastIndexOf([1, 1, 2, 2], 2, true);
  4283. * // => 3
  4284. */
  4285. function lastIndexOf(array, value, fromIndex) {
  4286. var length = array ? array.length : 0;
  4287. if (!length) {
  4288. return -1;
  4289. }
  4290. var index = length;
  4291. if (typeof fromIndex == 'number') {
  4292. index = (fromIndex < 0 ? nativeMax(length + fromIndex, 0) : nativeMin(fromIndex || 0, length - 1)) + 1;
  4293. } else if (fromIndex) {
  4294. index = binaryIndex(array, value, true) - 1;
  4295. var other = array[index];
  4296. return (value === value ? value === other : other !== other) ? index : -1;
  4297. }
  4298. if (value !== value) {
  4299. return indexOfNaN(array, index, true);
  4300. }
  4301. while (index--) {
  4302. if (array[index] === value) {
  4303. return index;
  4304. }
  4305. }
  4306. return -1;
  4307. }
  4308. /**
  4309. * Removes all provided values from `array` using `SameValueZero` for equality
  4310. * comparisons.
  4311. *
  4312. * **Notes:**
  4313. * - Unlike `_.without`, this method mutates `array`.
  4314. * - `SameValueZero` comparisons are like strict equality comparisons, e.g. `===`,
  4315. * except that `NaN` matches `NaN`. See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
  4316. * for more details.
  4317. *
  4318. * @static
  4319. * @memberOf _
  4320. * @category Array
  4321. * @param {Array} array The array to modify.
  4322. * @param {...*} [values] The values to remove.
  4323. * @returns {Array} Returns `array`.
  4324. * @example
  4325. *
  4326. * var array = [1, 2, 3, 1, 2, 3];
  4327. *
  4328. * _.pull(array, 2, 3);
  4329. * console.log(array);
  4330. * // => [1, 1]
  4331. */
  4332. function pull() {
  4333. var array = arguments[0];
  4334. if (!(array && array.length)) {
  4335. return array;
  4336. }
  4337. var index = 0,
  4338. indexOf = getIndexOf(),
  4339. length = arguments.length;
  4340. while (++index < length) {
  4341. var fromIndex = 0,
  4342. value = arguments[index];
  4343. while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
  4344. splice.call(array, fromIndex, 1);
  4345. }
  4346. }
  4347. return array;
  4348. }
  4349. /**
  4350. * Removes elements from `array` corresponding to the given indexes and returns
  4351. * an array of the removed elements. Indexes may be specified as an array of
  4352. * indexes or as individual arguments.
  4353. *
  4354. * **Note:** Unlike `_.at`, this method mutates `array`.
  4355. *
  4356. * @static
  4357. * @memberOf _
  4358. * @category Array
  4359. * @param {Array} array The array to modify.
  4360. * @param {...(number|number[])} [indexes] The indexes of elements to remove,
  4361. * specified as individual indexes or arrays of indexes.
  4362. * @returns {Array} Returns the new array of removed elements.
  4363. * @example
  4364. *
  4365. * var array = [5, 10, 15, 20];
  4366. * var evens = _.pullAt(array, 1, 3);
  4367. *
  4368. * console.log(array);
  4369. * // => [5, 15]
  4370. *
  4371. * console.log(evens);
  4372. * // => [10, 20]
  4373. */
  4374. function pullAt(array) {
  4375. return basePullAt(array || [], baseFlatten(arguments, false, false, 1));
  4376. }
  4377. /**
  4378. * Removes all elements from `array` that `predicate` returns truthy for
  4379. * and returns an array of the removed elements. The predicate is bound to
  4380. * `thisArg` and invoked with three arguments; (value, index, array).
  4381. *
  4382. * If a property name is provided for `predicate` the created `_.property`
  4383. * style callback returns the property value of the given element.
  4384. *
  4385. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4386. * style callback returns `true` for elements that have a matching property
  4387. * value, else `false`.
  4388. *
  4389. * If an object is provided for `predicate` the created `_.matches` style
  4390. * callback returns `true` for elements that have the properties of the given
  4391. * object, else `false`.
  4392. *
  4393. * **Note:** Unlike `_.filter`, this method mutates `array`.
  4394. *
  4395. * @static
  4396. * @memberOf _
  4397. * @category Array
  4398. * @param {Array} array The array to modify.
  4399. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4400. * per iteration.
  4401. * @param {*} [thisArg] The `this` binding of `predicate`.
  4402. * @returns {Array} Returns the new array of removed elements.
  4403. * @example
  4404. *
  4405. * var array = [1, 2, 3, 4];
  4406. * var evens = _.remove(array, function(n) {
  4407. * return n % 2 == 0;
  4408. * });
  4409. *
  4410. * console.log(array);
  4411. * // => [1, 3]
  4412. *
  4413. * console.log(evens);
  4414. * // => [2, 4]
  4415. */
  4416. function remove(array, predicate, thisArg) {
  4417. var index = -1,
  4418. length = array ? array.length : 0,
  4419. result = [];
  4420. predicate = getCallback(predicate, thisArg, 3);
  4421. while (++index < length) {
  4422. var value = array[index];
  4423. if (predicate(value, index, array)) {
  4424. result.push(value);
  4425. splice.call(array, index--, 1);
  4426. length--;
  4427. }
  4428. }
  4429. return result;
  4430. }
  4431. /**
  4432. * Gets all but the first element of `array`.
  4433. *
  4434. * @static
  4435. * @memberOf _
  4436. * @alias tail
  4437. * @category Array
  4438. * @param {Array} array The array to query.
  4439. * @returns {Array} Returns the slice of `array`.
  4440. * @example
  4441. *
  4442. * _.rest([1, 2, 3]);
  4443. * // => [2, 3]
  4444. */
  4445. function rest(array) {
  4446. return drop(array, 1);
  4447. }
  4448. /**
  4449. * Creates a slice of `array` from `start` up to, but not including, `end`.
  4450. *
  4451. * **Note:** This function is used instead of `Array#slice` to support node
  4452. * lists in IE < 9 and to ensure dense arrays are returned.
  4453. *
  4454. * @static
  4455. * @memberOf _
  4456. * @category Array
  4457. * @param {Array} array The array to slice.
  4458. * @param {number} [start=0] The start position.
  4459. * @param {number} [end=array.length] The end position.
  4460. * @returns {Array} Returns the slice of `array`.
  4461. */
  4462. function slice(array, start, end) {
  4463. var length = array ? array.length : 0;
  4464. if (!length) {
  4465. return [];
  4466. }
  4467. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  4468. start = 0;
  4469. end = length;
  4470. }
  4471. return baseSlice(array, start, end);
  4472. }
  4473. /**
  4474. * Uses a binary search to determine the lowest index at which `value` should
  4475. * be inserted into `array` in order to maintain its sort order. If an iteratee
  4476. * function is provided it is invoked for `value` and each element of `array`
  4477. * to compute their sort ranking. The iteratee is bound to `thisArg` and
  4478. * invoked with one argument; (value).
  4479. *
  4480. * If a property name is provided for `predicate` the created `_.property`
  4481. * style callback returns the property value of the given element.
  4482. *
  4483. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4484. * style callback returns `true` for elements that have a matching property
  4485. * value, else `false`.
  4486. *
  4487. * If an object is provided for `predicate` the created `_.matches` style
  4488. * callback returns `true` for elements that have the properties of the given
  4489. * object, else `false`.
  4490. *
  4491. * @static
  4492. * @memberOf _
  4493. * @category Array
  4494. * @param {Array} array The sorted array to inspect.
  4495. * @param {*} value The value to evaluate.
  4496. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  4497. * per iteration.
  4498. * @param {*} [thisArg] The `this` binding of `iteratee`.
  4499. * @returns {number} Returns the index at which `value` should be inserted
  4500. * into `array`.
  4501. * @example
  4502. *
  4503. * _.sortedIndex([30, 50], 40);
  4504. * // => 1
  4505. *
  4506. * _.sortedIndex([4, 4, 5, 5], 5);
  4507. * // => 2
  4508. *
  4509. * var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
  4510. *
  4511. * // using an iteratee function
  4512. * _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
  4513. * return this.data[word];
  4514. * }, dict);
  4515. * // => 1
  4516. *
  4517. * // using the `_.property` callback shorthand
  4518. * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
  4519. * // => 1
  4520. */
  4521. function sortedIndex(array, value, iteratee, thisArg) {
  4522. var func = getCallback(iteratee);
  4523. return (func === baseCallback && iteratee == null)
  4524. ? binaryIndex(array, value)
  4525. : binaryIndexBy(array, value, func(iteratee, thisArg, 1));
  4526. }
  4527. /**
  4528. * This method is like `_.sortedIndex` except that it returns the highest
  4529. * index at which `value` should be inserted into `array` in order to
  4530. * maintain its sort order.
  4531. *
  4532. * @static
  4533. * @memberOf _
  4534. * @category Array
  4535. * @param {Array} array The sorted array to inspect.
  4536. * @param {*} value The value to evaluate.
  4537. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  4538. * per iteration.
  4539. * @param {*} [thisArg] The `this` binding of `iteratee`.
  4540. * @returns {number} Returns the index at which `value` should be inserted
  4541. * into `array`.
  4542. * @example
  4543. *
  4544. * _.sortedLastIndex([4, 4, 5, 5], 5);
  4545. * // => 4
  4546. */
  4547. function sortedLastIndex(array, value, iteratee, thisArg) {
  4548. var func = getCallback(iteratee);
  4549. return (func === baseCallback && iteratee == null)
  4550. ? binaryIndex(array, value, true)
  4551. : binaryIndexBy(array, value, func(iteratee, thisArg, 1), true);
  4552. }
  4553. /**
  4554. * Creates a slice of `array` with `n` elements taken from the beginning.
  4555. *
  4556. * @static
  4557. * @memberOf _
  4558. * @category Array
  4559. * @param {Array} array The array to query.
  4560. * @param {number} [n=1] The number of elements to take.
  4561. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  4562. * @returns {Array} Returns the slice of `array`.
  4563. * @example
  4564. *
  4565. * _.take([1, 2, 3]);
  4566. * // => [1]
  4567. *
  4568. * _.take([1, 2, 3], 2);
  4569. * // => [1, 2]
  4570. *
  4571. * _.take([1, 2, 3], 5);
  4572. * // => [1, 2, 3]
  4573. *
  4574. * _.take([1, 2, 3], 0);
  4575. * // => []
  4576. */
  4577. function take(array, n, guard) {
  4578. var length = array ? array.length : 0;
  4579. if (!length) {
  4580. return [];
  4581. }
  4582. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  4583. n = 1;
  4584. }
  4585. return baseSlice(array, 0, n < 0 ? 0 : n);
  4586. }
  4587. /**
  4588. * Creates a slice of `array` with `n` elements taken from the end.
  4589. *
  4590. * @static
  4591. * @memberOf _
  4592. * @category Array
  4593. * @param {Array} array The array to query.
  4594. * @param {number} [n=1] The number of elements to take.
  4595. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  4596. * @returns {Array} Returns the slice of `array`.
  4597. * @example
  4598. *
  4599. * _.takeRight([1, 2, 3]);
  4600. * // => [3]
  4601. *
  4602. * _.takeRight([1, 2, 3], 2);
  4603. * // => [2, 3]
  4604. *
  4605. * _.takeRight([1, 2, 3], 5);
  4606. * // => [1, 2, 3]
  4607. *
  4608. * _.takeRight([1, 2, 3], 0);
  4609. * // => []
  4610. */
  4611. function takeRight(array, n, guard) {
  4612. var length = array ? array.length : 0;
  4613. if (!length) {
  4614. return [];
  4615. }
  4616. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  4617. n = 1;
  4618. }
  4619. n = length - (+n || 0);
  4620. return baseSlice(array, n < 0 ? 0 : n);
  4621. }
  4622. /**
  4623. * Creates a slice of `array` with elements taken from the end. Elements are
  4624. * taken until `predicate` returns falsey. The predicate is bound to `thisArg`
  4625. * and invoked with three arguments; (value, index, array).
  4626. *
  4627. * If a property name is provided for `predicate` the created `_.property`
  4628. * style callback returns the property value of the given element.
  4629. *
  4630. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4631. * style callback returns `true` for elements that have a matching property
  4632. * value, else `false`.
  4633. *
  4634. * If an object is provided for `predicate` the created `_.matches` style
  4635. * callback returns `true` for elements that have the properties of the given
  4636. * object, else `false`.
  4637. *
  4638. * @static
  4639. * @memberOf _
  4640. * @category Array
  4641. * @param {Array} array The array to query.
  4642. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4643. * per iteration.
  4644. * @param {*} [thisArg] The `this` binding of `predicate`.
  4645. * @returns {Array} Returns the slice of `array`.
  4646. * @example
  4647. *
  4648. * _.takeRightWhile([1, 2, 3], function(n) {
  4649. * return n > 1;
  4650. * });
  4651. * // => [2, 3]
  4652. *
  4653. * var users = [
  4654. * { 'user': 'barney', 'active': true },
  4655. * { 'user': 'fred', 'active': false },
  4656. * { 'user': 'pebbles', 'active': false }
  4657. * ];
  4658. *
  4659. * // using the `_.matches` callback shorthand
  4660. * _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
  4661. * // => ['pebbles']
  4662. *
  4663. * // using the `_.matchesProperty` callback shorthand
  4664. * _.pluck(_.takeRightWhile(users, 'active', false), 'user');
  4665. * // => ['fred', 'pebbles']
  4666. *
  4667. * // using the `_.property` callback shorthand
  4668. * _.pluck(_.takeRightWhile(users, 'active'), 'user');
  4669. * // => []
  4670. */
  4671. function takeRightWhile(array, predicate, thisArg) {
  4672. var length = array ? array.length : 0;
  4673. if (!length) {
  4674. return [];
  4675. }
  4676. predicate = getCallback(predicate, thisArg, 3);
  4677. while (length-- && predicate(array[length], length, array)) {}
  4678. return baseSlice(array, length + 1);
  4679. }
  4680. /**
  4681. * Creates a slice of `array` with elements taken from the beginning. Elements
  4682. * are taken until `predicate` returns falsey. The predicate is bound to
  4683. * `thisArg` and invoked with three arguments; (value, index, array).
  4684. *
  4685. * If a property name is provided for `predicate` the created `_.property`
  4686. * style callback returns the property value of the given element.
  4687. *
  4688. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4689. * style callback returns `true` for elements that have a matching property
  4690. * value, else `false`.
  4691. *
  4692. * If an object is provided for `predicate` the created `_.matches` style
  4693. * callback returns `true` for elements that have the properties of the given
  4694. * object, else `false`.
  4695. *
  4696. * @static
  4697. * @memberOf _
  4698. * @category Array
  4699. * @param {Array} array The array to query.
  4700. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4701. * per iteration.
  4702. * @param {*} [thisArg] The `this` binding of `predicate`.
  4703. * @returns {Array} Returns the slice of `array`.
  4704. * @example
  4705. *
  4706. * _.takeWhile([1, 2, 3], function(n) {
  4707. * return n < 3;
  4708. * });
  4709. * // => [1, 2]
  4710. *
  4711. * var users = [
  4712. * { 'user': 'barney', 'active': false },
  4713. * { 'user': 'fred', 'active': false},
  4714. * { 'user': 'pebbles', 'active': true }
  4715. * ];
  4716. *
  4717. * // using the `_.matches` callback shorthand
  4718. * _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
  4719. * // => ['barney']
  4720. *
  4721. * // using the `_.matchesProperty` callback shorthand
  4722. * _.pluck(_.takeWhile(users, 'active', false), 'user');
  4723. * // => ['barney', 'fred']
  4724. *
  4725. * // using the `_.property` callback shorthand
  4726. * _.pluck(_.takeWhile(users, 'active'), 'user');
  4727. * // => []
  4728. */
  4729. function takeWhile(array, predicate, thisArg) {
  4730. var length = array ? array.length : 0;
  4731. if (!length) {
  4732. return [];
  4733. }
  4734. var index = -1;
  4735. predicate = getCallback(predicate, thisArg, 3);
  4736. while (++index < length && predicate(array[index], index, array)) {}
  4737. return baseSlice(array, 0, index);
  4738. }
  4739. /**
  4740. * Creates an array of unique values, in order, of the provided arrays using
  4741. * `SameValueZero` for equality comparisons.
  4742. *
  4743. * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
  4744. * e.g. `===`, except that `NaN` matches `NaN`. See the
  4745. * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
  4746. * for more details.
  4747. *
  4748. * @static
  4749. * @memberOf _
  4750. * @category Array
  4751. * @param {...Array} [arrays] The arrays to inspect.
  4752. * @returns {Array} Returns the new array of combined values.
  4753. * @example
  4754. *
  4755. * _.union([1, 2], [4, 2], [2, 1]);
  4756. * // => [1, 2, 4]
  4757. */
  4758. function union() {
  4759. return baseUniq(baseFlatten(arguments, false, true));
  4760. }
  4761. /**
  4762. * Creates a duplicate-value-free version of an array using `SameValueZero`
  4763. * for equality comparisons. Providing `true` for `isSorted` performs a faster
  4764. * search algorithm for sorted arrays. If an iteratee function is provided it
  4765. * is invoked for each value in the array to generate the criterion by which
  4766. * uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked
  4767. * with three arguments; (value, index, array).
  4768. *
  4769. * If a property name is provided for `predicate` the created `_.property`
  4770. * style callback returns the property value of the given element.
  4771. *
  4772. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4773. * style callback returns `true` for elements that have a matching property
  4774. * value, else `false`.
  4775. *
  4776. * If an object is provided for `predicate` the created `_.matches` style
  4777. * callback returns `true` for elements that have the properties of the given
  4778. * object, else `false`.
  4779. *
  4780. * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
  4781. * e.g. `===`, except that `NaN` matches `NaN`. See the
  4782. * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
  4783. * for more details.
  4784. *
  4785. * @static
  4786. * @memberOf _
  4787. * @alias unique
  4788. * @category Array
  4789. * @param {Array} array The array to inspect.
  4790. * @param {boolean} [isSorted] Specify the array is sorted.
  4791. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  4792. * @param {*} [thisArg] The `this` binding of `iteratee`.
  4793. * @returns {Array} Returns the new duplicate-value-free array.
  4794. * @example
  4795. *
  4796. * _.uniq([1, 2, 1]);
  4797. * // => [1, 2]
  4798. *
  4799. * // using `isSorted`
  4800. * _.uniq([1, 1, 2], true);
  4801. * // => [1, 2]
  4802. *
  4803. * // using an iteratee function
  4804. * _.uniq([1, 2.5, 1.5, 2], function(n) {
  4805. * return this.floor(n);
  4806. * }, Math);
  4807. * // => [1, 2.5]
  4808. *
  4809. * // using the `_.property` callback shorthand
  4810. * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  4811. * // => [{ 'x': 1 }, { 'x': 2 }]
  4812. */
  4813. function uniq(array, isSorted, iteratee, thisArg) {
  4814. var length = array ? array.length : 0;
  4815. if (!length) {
  4816. return [];
  4817. }
  4818. if (isSorted != null && typeof isSorted != 'boolean') {
  4819. thisArg = iteratee;
  4820. iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted;
  4821. isSorted = false;
  4822. }
  4823. var func = getCallback();
  4824. if (!(func === baseCallback && iteratee == null)) {
  4825. iteratee = func(iteratee, thisArg, 3);
  4826. }
  4827. return (isSorted && getIndexOf() == baseIndexOf)
  4828. ? sortedUniq(array, iteratee)
  4829. : baseUniq(array, iteratee);
  4830. }
  4831. /**
  4832. * This method is like `_.zip` except that it accepts an array of grouped
  4833. * elements and creates an array regrouping the elements to their pre-`_.zip`
  4834. * configuration.
  4835. *
  4836. * @static
  4837. * @memberOf _
  4838. * @category Array
  4839. * @param {Array} array The array of grouped elements to process.
  4840. * @returns {Array} Returns the new array of regrouped elements.
  4841. * @example
  4842. *
  4843. * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
  4844. * // => [['fred', 30, true], ['barney', 40, false]]
  4845. *
  4846. * _.unzip(zipped);
  4847. * // => [['fred', 'barney'], [30, 40], [true, false]]
  4848. */
  4849. function unzip(array) {
  4850. var index = -1,
  4851. length = (array && array.length && arrayMax(arrayMap(array, getLength))) >>> 0,
  4852. result = Array(length);
  4853. while (++index < length) {
  4854. result[index] = arrayMap(array, baseProperty(index));
  4855. }
  4856. return result;
  4857. }
  4858. /**
  4859. * Creates an array excluding all provided values using `SameValueZero` for
  4860. * equality comparisons.
  4861. *
  4862. * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
  4863. * e.g. `===`, except that `NaN` matches `NaN`. See the
  4864. * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
  4865. * for more details.
  4866. *
  4867. * @static
  4868. * @memberOf _
  4869. * @category Array
  4870. * @param {Array} array The array to filter.
  4871. * @param {...*} [values] The values to exclude.
  4872. * @returns {Array} Returns the new array of filtered values.
  4873. * @example
  4874. *
  4875. * _.without([1, 2, 1, 3], 1, 2);
  4876. * // => [3]
  4877. */
  4878. function without(array) {
  4879. return baseDifference(array, baseSlice(arguments, 1));
  4880. }
  4881. /**
  4882. * Creates an array that is the symmetric difference of the provided arrays.
  4883. * See [Wikipedia](https://en.wikipedia.org/wiki/Symmetric_difference) for
  4884. * more details.
  4885. *
  4886. * @static
  4887. * @memberOf _
  4888. * @category Array
  4889. * @param {...Array} [arrays] The arrays to inspect.
  4890. * @returns {Array} Returns the new array of values.
  4891. * @example
  4892. *
  4893. * _.xor([1, 2], [4, 2]);
  4894. * // => [1, 4]
  4895. */
  4896. function xor() {
  4897. var index = -1,
  4898. length = arguments.length;
  4899. while (++index < length) {
  4900. var array = arguments[index];
  4901. if (isArray(array) || isArguments(array)) {
  4902. var result = result
  4903. ? baseDifference(result, array).concat(baseDifference(array, result))
  4904. : array;
  4905. }
  4906. }
  4907. return result ? baseUniq(result) : [];
  4908. }
  4909. /**
  4910. * Creates an array of grouped elements, the first of which contains the first
  4911. * elements of the given arrays, the second of which contains the second elements
  4912. * of the given arrays, and so on.
  4913. *
  4914. * @static
  4915. * @memberOf _
  4916. * @category Array
  4917. * @param {...Array} [arrays] The arrays to process.
  4918. * @returns {Array} Returns the new array of grouped elements.
  4919. * @example
  4920. *
  4921. * _.zip(['fred', 'barney'], [30, 40], [true, false]);
  4922. * // => [['fred', 30, true], ['barney', 40, false]]
  4923. */
  4924. function zip() {
  4925. var length = arguments.length,
  4926. array = Array(length);
  4927. while (length--) {
  4928. array[length] = arguments[length];
  4929. }
  4930. return unzip(array);
  4931. }
  4932. /**
  4933. * Creates an object composed from arrays of property names and values. Provide
  4934. * either a single two dimensional array, e.g. `[[key1, value1], [key2, value2]]`
  4935. * or two arrays, one of property names and one of corresponding values.
  4936. *
  4937. * @static
  4938. * @memberOf _
  4939. * @alias object
  4940. * @category Array
  4941. * @param {Array} props The property names.
  4942. * @param {Array} [values=[]] The property values.
  4943. * @returns {Object} Returns the new object.
  4944. * @example
  4945. *
  4946. * _.zipObject(['fred', 'barney'], [30, 40]);
  4947. * // => { 'fred': 30, 'barney': 40 }
  4948. */
  4949. function zipObject(props, values) {
  4950. var index = -1,
  4951. length = props ? props.length : 0,
  4952. result = {};
  4953. if (length && !values && !isArray(props[0])) {
  4954. values = [];
  4955. }
  4956. while (++index < length) {
  4957. var key = props[index];
  4958. if (values) {
  4959. result[key] = values[index];
  4960. } else if (key) {
  4961. result[key[0]] = key[1];
  4962. }
  4963. }
  4964. return result;
  4965. }
  4966. /*------------------------------------------------------------------------*/
  4967. /**
  4968. * Creates a `lodash` object that wraps `value` with explicit method
  4969. * chaining enabled.
  4970. *
  4971. * @static
  4972. * @memberOf _
  4973. * @category Chain
  4974. * @param {*} value The value to wrap.
  4975. * @returns {Object} Returns the new `lodash` wrapper instance.
  4976. * @example
  4977. *
  4978. * var users = [
  4979. * { 'user': 'barney', 'age': 36 },
  4980. * { 'user': 'fred', 'age': 40 },
  4981. * { 'user': 'pebbles', 'age': 1 }
  4982. * ];
  4983. *
  4984. * var youngest = _.chain(users)
  4985. * .sortBy('age')
  4986. * .map(function(chr) {
  4987. * return chr.user + ' is ' + chr.age;
  4988. * })
  4989. * .first()
  4990. * .value();
  4991. * // => 'pebbles is 1'
  4992. */
  4993. function chain(value) {
  4994. var result = lodash(value);
  4995. result.__chain__ = true;
  4996. return result;
  4997. }
  4998. /**
  4999. * This method invokes `interceptor` and returns `value`. The interceptor is
  5000. * bound to `thisArg` and invoked with one argument; (value). The purpose of
  5001. * this method is to "tap into" a method chain in order to perform operations
  5002. * on intermediate results within the chain.
  5003. *
  5004. * @static
  5005. * @memberOf _
  5006. * @category Chain
  5007. * @param {*} value The value to provide to `interceptor`.
  5008. * @param {Function} interceptor The function to invoke.
  5009. * @param {*} [thisArg] The `this` binding of `interceptor`.
  5010. * @returns {*} Returns `value`.
  5011. * @example
  5012. *
  5013. * _([1, 2, 3])
  5014. * .tap(function(array) {
  5015. * array.pop();
  5016. * })
  5017. * .reverse()
  5018. * .value();
  5019. * // => [2, 1]
  5020. */
  5021. function tap(value, interceptor, thisArg) {
  5022. interceptor.call(thisArg, value);
  5023. return value;
  5024. }
  5025. /**
  5026. * This method is like `_.tap` except that it returns the result of `interceptor`.
  5027. *
  5028. * @static
  5029. * @memberOf _
  5030. * @category Chain
  5031. * @param {*} value The value to provide to `interceptor`.
  5032. * @param {Function} interceptor The function to invoke.
  5033. * @param {*} [thisArg] The `this` binding of `interceptor`.
  5034. * @returns {*} Returns the result of `interceptor`.
  5035. * @example
  5036. *
  5037. * _([1, 2, 3])
  5038. * .last()
  5039. * .thru(function(value) {
  5040. * return [value];
  5041. * })
  5042. * .value();
  5043. * // => [3]
  5044. */
  5045. function thru(value, interceptor, thisArg) {
  5046. return interceptor.call(thisArg, value);
  5047. }
  5048. /**
  5049. * Enables explicit method chaining on the wrapper object.
  5050. *
  5051. * @name chain
  5052. * @memberOf _
  5053. * @category Chain
  5054. * @returns {Object} Returns the new `lodash` wrapper instance.
  5055. * @example
  5056. *
  5057. * var users = [
  5058. * { 'user': 'barney', 'age': 36 },
  5059. * { 'user': 'fred', 'age': 40 }
  5060. * ];
  5061. *
  5062. * // without explicit chaining
  5063. * _(users).first();
  5064. * // => { 'user': 'barney', 'age': 36 }
  5065. *
  5066. * // with explicit chaining
  5067. * _(users).chain()
  5068. * .first()
  5069. * .pick('user')
  5070. * .value();
  5071. * // => { 'user': 'barney' }
  5072. */
  5073. function wrapperChain() {
  5074. return chain(this);
  5075. }
  5076. /**
  5077. * Executes the chained sequence and returns the wrapped result.
  5078. *
  5079. * @name commit
  5080. * @memberOf _
  5081. * @category Chain
  5082. * @returns {Object} Returns the new `lodash` wrapper instance.
  5083. * @example
  5084. *
  5085. * var array = [1, 2];
  5086. * var wrapper = _(array).push(3);
  5087. *
  5088. * console.log(array);
  5089. * // => [1, 2]
  5090. *
  5091. * wrapper = wrapper.commit();
  5092. * console.log(array);
  5093. * // => [1, 2, 3]
  5094. *
  5095. * wrapper.last();
  5096. * // => 3
  5097. *
  5098. * console.log(array);
  5099. * // => [1, 2, 3]
  5100. */
  5101. function wrapperCommit() {
  5102. return new LodashWrapper(this.value(), this.__chain__);
  5103. }
  5104. /**
  5105. * Creates a clone of the chained sequence planting `value` as the wrapped value.
  5106. *
  5107. * @name plant
  5108. * @memberOf _
  5109. * @category Chain
  5110. * @returns {Object} Returns the new `lodash` wrapper instance.
  5111. * @example
  5112. *
  5113. * var array = [1, 2];
  5114. * var wrapper = _(array).map(function(value) {
  5115. * return Math.pow(value, 2);
  5116. * });
  5117. *
  5118. * var other = [3, 4];
  5119. * var otherWrapper = wrapper.plant(other);
  5120. *
  5121. * otherWrapper.value();
  5122. * // => [9, 16]
  5123. *
  5124. * wrapper.value();
  5125. * // => [1, 4]
  5126. */
  5127. function wrapperPlant(value) {
  5128. var result,
  5129. parent = this;
  5130. while (parent instanceof baseLodash) {
  5131. var clone = wrapperClone(parent);
  5132. if (result) {
  5133. previous.__wrapped__ = clone;
  5134. } else {
  5135. result = clone;
  5136. }
  5137. var previous = clone;
  5138. parent = parent.__wrapped__;
  5139. }
  5140. previous.__wrapped__ = value;
  5141. return result;
  5142. }
  5143. /**
  5144. * Reverses the wrapped array so the first element becomes the last, the
  5145. * second element becomes the second to last, and so on.
  5146. *
  5147. * **Note:** This method mutates the wrapped array.
  5148. *
  5149. * @name reverse
  5150. * @memberOf _
  5151. * @category Chain
  5152. * @returns {Object} Returns the new reversed `lodash` wrapper instance.
  5153. * @example
  5154. *
  5155. * var array = [1, 2, 3];
  5156. *
  5157. * _(array).reverse().value()
  5158. * // => [3, 2, 1]
  5159. *
  5160. * console.log(array);
  5161. * // => [3, 2, 1]
  5162. */
  5163. function wrapperReverse() {
  5164. var value = this.__wrapped__;
  5165. if (value instanceof LazyWrapper) {
  5166. if (this.__actions__.length) {
  5167. value = new LazyWrapper(this);
  5168. }
  5169. return new LodashWrapper(value.reverse(), this.__chain__);
  5170. }
  5171. return this.thru(function(value) {
  5172. return value.reverse();
  5173. });
  5174. }
  5175. /**
  5176. * Produces the result of coercing the unwrapped value to a string.
  5177. *
  5178. * @name toString
  5179. * @memberOf _
  5180. * @category Chain
  5181. * @returns {string} Returns the coerced string value.
  5182. * @example
  5183. *
  5184. * _([1, 2, 3]).toString();
  5185. * // => '1,2,3'
  5186. */
  5187. function wrapperToString() {
  5188. return (this.value() + '');
  5189. }
  5190. /**
  5191. * Executes the chained sequence to extract the unwrapped value.
  5192. *
  5193. * @name value
  5194. * @memberOf _
  5195. * @alias run, toJSON, valueOf
  5196. * @category Chain
  5197. * @returns {*} Returns the resolved unwrapped value.
  5198. * @example
  5199. *
  5200. * _([1, 2, 3]).value();
  5201. * // => [1, 2, 3]
  5202. */
  5203. function wrapperValue() {
  5204. return baseWrapperValue(this.__wrapped__, this.__actions__);
  5205. }
  5206. /*------------------------------------------------------------------------*/
  5207. /**
  5208. * Creates an array of elements corresponding to the given keys, or indexes,
  5209. * of `collection`. Keys may be specified as individual arguments or as arrays
  5210. * of keys.
  5211. *
  5212. * @static
  5213. * @memberOf _
  5214. * @category Collection
  5215. * @param {Array|Object|string} collection The collection to iterate over.
  5216. * @param {...(number|number[]|string|string[])} [props] The property names
  5217. * or indexes of elements to pick, specified individually or in arrays.
  5218. * @returns {Array} Returns the new array of picked elements.
  5219. * @example
  5220. *
  5221. * _.at(['a', 'b', 'c'], [0, 2]);
  5222. * // => ['a', 'c']
  5223. *
  5224. * _.at(['fred', 'barney', 'pebbles'], 0, 2);
  5225. * // => ['fred', 'pebbles']
  5226. */
  5227. function at(collection) {
  5228. var length = collection ? collection.length : 0;
  5229. if (isLength(length)) {
  5230. collection = toIterable(collection);
  5231. }
  5232. return baseAt(collection, baseFlatten(arguments, false, false, 1));
  5233. }
  5234. /**
  5235. * Creates an object composed of keys generated from the results of running
  5236. * each element of `collection` through `iteratee`. The corresponding value
  5237. * of each key is the number of times the key was returned by `iteratee`.
  5238. * The `iteratee` is bound to `thisArg` and invoked with three arguments;
  5239. * (value, index|key, collection).
  5240. *
  5241. * If a property name is provided for `predicate` the created `_.property`
  5242. * style callback returns the property value of the given element.
  5243. *
  5244. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5245. * style callback returns `true` for elements that have a matching property
  5246. * value, else `false`.
  5247. *
  5248. * If an object is provided for `predicate` the created `_.matches` style
  5249. * callback returns `true` for elements that have the properties of the given
  5250. * object, else `false`.
  5251. *
  5252. * @static
  5253. * @memberOf _
  5254. * @category Collection
  5255. * @param {Array|Object|string} collection The collection to iterate over.
  5256. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  5257. * per iteration.
  5258. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5259. * @returns {Object} Returns the composed aggregate object.
  5260. * @example
  5261. *
  5262. * _.countBy([4.3, 6.1, 6.4], function(n) {
  5263. * return Math.floor(n);
  5264. * });
  5265. * // => { '4': 1, '6': 2 }
  5266. *
  5267. * _.countBy([4.3, 6.1, 6.4], function(n) {
  5268. * return this.floor(n);
  5269. * }, Math);
  5270. * // => { '4': 1, '6': 2 }
  5271. *
  5272. * _.countBy(['one', 'two', 'three'], 'length');
  5273. * // => { '3': 2, '5': 1 }
  5274. */
  5275. var countBy = createAggregator(function(result, value, key) {
  5276. hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
  5277. });
  5278. /**
  5279. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  5280. * The predicate is bound to `thisArg` and invoked with three arguments;
  5281. * (value, index|key, collection).
  5282. *
  5283. * If a property name is provided for `predicate` the created `_.property`
  5284. * style callback returns the property value of the given element.
  5285. *
  5286. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5287. * style callback returns `true` for elements that have a matching property
  5288. * value, else `false`.
  5289. *
  5290. * If an object is provided for `predicate` the created `_.matches` style
  5291. * callback returns `true` for elements that have the properties of the given
  5292. * object, else `false`.
  5293. *
  5294. * @static
  5295. * @memberOf _
  5296. * @alias all
  5297. * @category Collection
  5298. * @param {Array|Object|string} collection The collection to iterate over.
  5299. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  5300. * per iteration.
  5301. * @param {*} [thisArg] The `this` binding of `predicate`.
  5302. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  5303. * else `false`.
  5304. * @example
  5305. *
  5306. * _.every([true, 1, null, 'yes'], Boolean);
  5307. * // => false
  5308. *
  5309. * var users = [
  5310. * { 'user': 'barney', 'active': false },
  5311. * { 'user': 'fred', 'active': false }
  5312. * ];
  5313. *
  5314. * // using the `_.matches` callback shorthand
  5315. * _.every(users, { 'user': 'barney', 'active': false });
  5316. * // => false
  5317. *
  5318. * // using the `_.matchesProperty` callback shorthand
  5319. * _.every(users, 'active', false);
  5320. * // => true
  5321. *
  5322. * // using the `_.property` callback shorthand
  5323. * _.every(users, 'active');
  5324. * // => false
  5325. */
  5326. function every(collection, predicate, thisArg) {
  5327. var func = isArray(collection) ? arrayEvery : baseEvery;
  5328. if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
  5329. predicate = getCallback(predicate, thisArg, 3);
  5330. }
  5331. return func(collection, predicate);
  5332. }
  5333. /**
  5334. * Iterates over elements of `collection`, returning an array of all elements
  5335. * `predicate` returns truthy for. The predicate is bound to `thisArg` and
  5336. * invoked with three arguments; (value, index|key, collection).
  5337. *
  5338. * If a property name is provided for `predicate` the created `_.property`
  5339. * style callback returns the property value of the given element.
  5340. *
  5341. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5342. * style callback returns `true` for elements that have a matching property
  5343. * value, else `false`.
  5344. *
  5345. * If an object is provided for `predicate` the created `_.matches` style
  5346. * callback returns `true` for elements that have the properties of the given
  5347. * object, else `false`.
  5348. *
  5349. * @static
  5350. * @memberOf _
  5351. * @alias select
  5352. * @category Collection
  5353. * @param {Array|Object|string} collection The collection to iterate over.
  5354. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  5355. * per iteration.
  5356. * @param {*} [thisArg] The `this` binding of `predicate`.
  5357. * @returns {Array} Returns the new filtered array.
  5358. * @example
  5359. *
  5360. * _.filter([4, 5, 6], function(n) {
  5361. * return n % 2 == 0;
  5362. * });
  5363. * // => [4, 6]
  5364. *
  5365. * var users = [
  5366. * { 'user': 'barney', 'age': 36, 'active': true },
  5367. * { 'user': 'fred', 'age': 40, 'active': false }
  5368. * ];
  5369. *
  5370. * // using the `_.matches` callback shorthand
  5371. * _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
  5372. * // => ['barney']
  5373. *
  5374. * // using the `_.matchesProperty` callback shorthand
  5375. * _.pluck(_.filter(users, 'active', false), 'user');
  5376. * // => ['fred']
  5377. *
  5378. * // using the `_.property` callback shorthand
  5379. * _.pluck(_.filter(users, 'active'), 'user');
  5380. * // => ['barney']
  5381. */
  5382. function filter(collection, predicate, thisArg) {
  5383. var func = isArray(collection) ? arrayFilter : baseFilter;
  5384. predicate = getCallback(predicate, thisArg, 3);
  5385. return func(collection, predicate);
  5386. }
  5387. /**
  5388. * Iterates over elements of `collection`, returning the first element
  5389. * `predicate` returns truthy for. The predicate is bound to `thisArg` and
  5390. * invoked with three arguments; (value, index|key, collection).
  5391. *
  5392. * If a property name is provided for `predicate` the created `_.property`
  5393. * style callback returns the property value of the given element.
  5394. *
  5395. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5396. * style callback returns `true` for elements that have a matching property
  5397. * value, else `false`.
  5398. *
  5399. * If an object is provided for `predicate` the created `_.matches` style
  5400. * callback returns `true` for elements that have the properties of the given
  5401. * object, else `false`.
  5402. *
  5403. * @static
  5404. * @memberOf _
  5405. * @alias detect
  5406. * @category Collection
  5407. * @param {Array|Object|string} collection The collection to search.
  5408. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  5409. * per iteration.
  5410. * @param {*} [thisArg] The `this` binding of `predicate`.
  5411. * @returns {*} Returns the matched element, else `undefined`.
  5412. * @example
  5413. *
  5414. * var users = [
  5415. * { 'user': 'barney', 'age': 36, 'active': true },
  5416. * { 'user': 'fred', 'age': 40, 'active': false },
  5417. * { 'user': 'pebbles', 'age': 1, 'active': true }
  5418. * ];
  5419. *
  5420. * _.result(_.find(users, function(chr) {
  5421. * return chr.age < 40;
  5422. * }), 'user');
  5423. * // => 'barney'
  5424. *
  5425. * // using the `_.matches` callback shorthand
  5426. * _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
  5427. * // => 'pebbles'
  5428. *
  5429. * // using the `_.matchesProperty` callback shorthand
  5430. * _.result(_.find(users, 'active', false), 'user');
  5431. * // => 'fred'
  5432. *
  5433. * // using the `_.property` callback shorthand
  5434. * _.result(_.find(users, 'active'), 'user');
  5435. * // => 'barney'
  5436. */
  5437. function find(collection, predicate, thisArg) {
  5438. if (isArray(collection)) {
  5439. var index = findIndex(collection, predicate, thisArg);
  5440. return index > -1 ? collection[index] : undefined;
  5441. }
  5442. predicate = getCallback(predicate, thisArg, 3);
  5443. return baseFind(collection, predicate, baseEach);
  5444. }
  5445. /**
  5446. * This method is like `_.find` except that it iterates over elements of
  5447. * `collection` from right to left.
  5448. *
  5449. * @static
  5450. * @memberOf _
  5451. * @category Collection
  5452. * @param {Array|Object|string} collection The collection to search.
  5453. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  5454. * per iteration.
  5455. * @param {*} [thisArg] The `this` binding of `predicate`.
  5456. * @returns {*} Returns the matched element, else `undefined`.
  5457. * @example
  5458. *
  5459. * _.findLast([1, 2, 3, 4], function(n) {
  5460. * return n % 2 == 1;
  5461. * });
  5462. * // => 3
  5463. */
  5464. function findLast(collection, predicate, thisArg) {
  5465. predicate = getCallback(predicate, thisArg, 3);
  5466. return baseFind(collection, predicate, baseEachRight);
  5467. }
  5468. /**
  5469. * Performs a deep comparison between each element in `collection` and the
  5470. * source object, returning the first element that has equivalent property
  5471. * values.
  5472. *
  5473. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  5474. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  5475. * their own, not inherited, enumerable properties. For comparing a single
  5476. * own or inherited property value see `_.matchesProperty`.
  5477. *
  5478. * @static
  5479. * @memberOf _
  5480. * @category Collection
  5481. * @param {Array|Object|string} collection The collection to search.
  5482. * @param {Object} source The object of property values to match.
  5483. * @returns {*} Returns the matched element, else `undefined`.
  5484. * @example
  5485. *
  5486. * var users = [
  5487. * { 'user': 'barney', 'age': 36, 'active': true },
  5488. * { 'user': 'fred', 'age': 40, 'active': false }
  5489. * ];
  5490. *
  5491. * _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user');
  5492. * // => 'barney'
  5493. *
  5494. * _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user');
  5495. * // => 'fred'
  5496. */
  5497. function findWhere(collection, source) {
  5498. return find(collection, baseMatches(source));
  5499. }
  5500. /**
  5501. * Iterates over elements of `collection` invoking `iteratee` for each element.
  5502. * The `iteratee` is bound to `thisArg` and invoked with three arguments;
  5503. * (value, index|key, collection). Iterator functions may exit iteration early
  5504. * by explicitly returning `false`.
  5505. *
  5506. * **Note:** As with other "Collections" methods, objects with a `length` property
  5507. * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
  5508. * may be used for object iteration.
  5509. *
  5510. * @static
  5511. * @memberOf _
  5512. * @alias each
  5513. * @category Collection
  5514. * @param {Array|Object|string} collection The collection to iterate over.
  5515. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  5516. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5517. * @returns {Array|Object|string} Returns `collection`.
  5518. * @example
  5519. *
  5520. * _([1, 2]).forEach(function(n) {
  5521. * console.log(n);
  5522. * }).value();
  5523. * // => logs each value from left to right and returns the array
  5524. *
  5525. * _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
  5526. * console.log(n, key);
  5527. * });
  5528. * // => logs each value-key pair and returns the object (iteration order is not guaranteed)
  5529. */
  5530. function forEach(collection, iteratee, thisArg) {
  5531. return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
  5532. ? arrayEach(collection, iteratee)
  5533. : baseEach(collection, bindCallback(iteratee, thisArg, 3));
  5534. }
  5535. /**
  5536. * This method is like `_.forEach` except that it iterates over elements of
  5537. * `collection` from right to left.
  5538. *
  5539. * @static
  5540. * @memberOf _
  5541. * @alias eachRight
  5542. * @category Collection
  5543. * @param {Array|Object|string} collection The collection to iterate over.
  5544. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  5545. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5546. * @returns {Array|Object|string} Returns `collection`.
  5547. * @example
  5548. *
  5549. * _([1, 2]).forEachRight(function(n) {
  5550. * console.log(n);
  5551. * }).join(',');
  5552. * // => logs each value from right to left and returns the array
  5553. */
  5554. function forEachRight(collection, iteratee, thisArg) {
  5555. return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
  5556. ? arrayEachRight(collection, iteratee)
  5557. : baseEachRight(collection, bindCallback(iteratee, thisArg, 3));
  5558. }
  5559. /**
  5560. * Creates an object composed of keys generated from the results of running
  5561. * each element of `collection` through `iteratee`. The corresponding value
  5562. * of each key is an array of the elements responsible for generating the key.
  5563. * The `iteratee` is bound to `thisArg` and invoked with three arguments;
  5564. * (value, index|key, collection).
  5565. *
  5566. * If a property name is provided for `predicate` the created `_.property`
  5567. * style callback returns the property value of the given element.
  5568. *
  5569. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5570. * style callback returns `true` for elements that have a matching property
  5571. * value, else `false`.
  5572. *
  5573. * If an object is provided for `predicate` the created `_.matches` style
  5574. * callback returns `true` for elements that have the properties of the given
  5575. * object, else `false`.
  5576. *
  5577. * @static
  5578. * @memberOf _
  5579. * @category Collection
  5580. * @param {Array|Object|string} collection The collection to iterate over.
  5581. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  5582. * per iteration.
  5583. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5584. * @returns {Object} Returns the composed aggregate object.
  5585. * @example
  5586. *
  5587. * _.groupBy([4.2, 6.1, 6.4], function(n) {
  5588. * return Math.floor(n);
  5589. * });
  5590. * // => { '4': [4.2], '6': [6.1, 6.4] }
  5591. *
  5592. * _.groupBy([4.2, 6.1, 6.4], function(n) {
  5593. * return this.floor(n);
  5594. * }, Math);
  5595. * // => { '4': [4.2], '6': [6.1, 6.4] }
  5596. *
  5597. * // using the `_.property` callback shorthand
  5598. * _.groupBy(['one', 'two', 'three'], 'length');
  5599. * // => { '3': ['one', 'two'], '5': ['three'] }
  5600. */
  5601. var groupBy = createAggregator(function(result, value, key) {
  5602. if (hasOwnProperty.call(result, key)) {
  5603. result[key].push(value);
  5604. } else {
  5605. result[key] = [value];
  5606. }
  5607. });
  5608. /**
  5609. * Checks if `value` is in `collection` using `SameValueZero` for equality
  5610. * comparisons. If `fromIndex` is negative, it is used as the offset from
  5611. * the end of `collection`.
  5612. *
  5613. * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
  5614. * e.g. `===`, except that `NaN` matches `NaN`. See the
  5615. * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
  5616. * for more details.
  5617. *
  5618. * @static
  5619. * @memberOf _
  5620. * @alias contains, include
  5621. * @category Collection
  5622. * @param {Array|Object|string} collection The collection to search.
  5623. * @param {*} target The value to search for.
  5624. * @param {number} [fromIndex=0] The index to search from.
  5625. * @returns {boolean} Returns `true` if a matching element is found, else `false`.
  5626. * @example
  5627. *
  5628. * _.includes([1, 2, 3], 1);
  5629. * // => true
  5630. *
  5631. * _.includes([1, 2, 3], 1, 2);
  5632. * // => false
  5633. *
  5634. * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
  5635. * // => true
  5636. *
  5637. * _.includes('pebbles', 'eb');
  5638. * // => true
  5639. */
  5640. function includes(collection, target, fromIndex) {
  5641. var length = collection ? collection.length : 0;
  5642. if (!isLength(length)) {
  5643. collection = values(collection);
  5644. length = collection.length;
  5645. }
  5646. if (!length) {
  5647. return false;
  5648. }
  5649. if (typeof fromIndex == 'number') {
  5650. fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
  5651. } else {
  5652. fromIndex = 0;
  5653. }
  5654. return (typeof collection == 'string' || !isArray(collection) && isString(collection))
  5655. ? (fromIndex < length && collection.indexOf(target, fromIndex) > -1)
  5656. : (getIndexOf(collection, target, fromIndex) > -1);
  5657. }
  5658. /**
  5659. * Creates an object composed of keys generated from the results of running
  5660. * each element of `collection` through `iteratee`. The corresponding value
  5661. * of each key is the last element responsible for generating the key. The
  5662. * iteratee function is bound to `thisArg` and invoked with three arguments;
  5663. * (value, index|key, collection).
  5664. *
  5665. * If a property name is provided for `predicate` the created `_.property`
  5666. * style callback returns the property value of the given element.
  5667. *
  5668. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5669. * style callback returns `true` for elements that have a matching property
  5670. * value, else `false`.
  5671. *
  5672. * If an object is provided for `predicate` the created `_.matches` style
  5673. * callback returns `true` for elements that have the properties of the given
  5674. * object, else `false`.
  5675. *
  5676. * @static
  5677. * @memberOf _
  5678. * @category Collection
  5679. * @param {Array|Object|string} collection The collection to iterate over.
  5680. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  5681. * per iteration.
  5682. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5683. * @returns {Object} Returns the composed aggregate object.
  5684. * @example
  5685. *
  5686. * var keyData = [
  5687. * { 'dir': 'left', 'code': 97 },
  5688. * { 'dir': 'right', 'code': 100 }
  5689. * ];
  5690. *
  5691. * _.indexBy(keyData, 'dir');
  5692. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  5693. *
  5694. * _.indexBy(keyData, function(object) {
  5695. * return String.fromCharCode(object.code);
  5696. * });
  5697. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  5698. *
  5699. * _.indexBy(keyData, function(object) {
  5700. * return this.fromCharCode(object.code);
  5701. * }, String);
  5702. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  5703. */
  5704. var indexBy = createAggregator(function(result, value, key) {
  5705. result[key] = value;
  5706. });
  5707. /**
  5708. * Invokes the method named by `methodName` on each element in `collection`,
  5709. * returning an array of the results of each invoked method. Any additional
  5710. * arguments are provided to each invoked method. If `methodName` is a function
  5711. * it is invoked for, and `this` bound to, each element in `collection`.
  5712. *
  5713. * @static
  5714. * @memberOf _
  5715. * @category Collection
  5716. * @param {Array|Object|string} collection The collection to iterate over.
  5717. * @param {Function|string} methodName The name of the method to invoke or
  5718. * the function invoked per iteration.
  5719. * @param {...*} [args] The arguments to invoke the method with.
  5720. * @returns {Array} Returns the array of results.
  5721. * @example
  5722. *
  5723. * _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
  5724. * // => [[1, 5, 7], [1, 2, 3]]
  5725. *
  5726. * _.invoke([123, 456], String.prototype.split, '');
  5727. * // => [['1', '2', '3'], ['4', '5', '6']]
  5728. */
  5729. function invoke(collection, methodName) {
  5730. return baseInvoke(collection, methodName, baseSlice(arguments, 2));
  5731. }
  5732. /**
  5733. * Creates an array of values by running each element in `collection` through
  5734. * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
  5735. * arguments; (value, index|key, collection).
  5736. *
  5737. * If a property name is provided for `predicate` the created `_.property`
  5738. * style callback returns the property value of the given element.
  5739. *
  5740. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5741. * style callback returns `true` for elements that have a matching property
  5742. * value, else `false`.
  5743. *
  5744. * If an object is provided for `predicate` the created `_.matches` style
  5745. * callback returns `true` for elements that have the properties of the given
  5746. * object, else `false`.
  5747. *
  5748. * Many lodash methods are guarded to work as interatees for methods like
  5749. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  5750. *
  5751. * The guarded methods are:
  5752. * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, `drop`,
  5753. * `dropRight`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`, `slice`,
  5754. * `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`, `trimRight`,
  5755. * `trunc`, `random`, `range`, `sample`, `uniq`, and `words`
  5756. *
  5757. * @static
  5758. * @memberOf _
  5759. * @alias collect
  5760. * @category Collection
  5761. * @param {Array|Object|string} collection The collection to iterate over.
  5762. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  5763. * per iteration.
  5764. * create a `_.property` or `_.matches` style callback respectively.
  5765. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5766. * @returns {Array} Returns the new mapped array.
  5767. * @example
  5768. *
  5769. * function timesThree(n) {
  5770. * return n * 3;
  5771. * }
  5772. *
  5773. * _.map([1, 2], timesThree);
  5774. * // => [3, 6]
  5775. *
  5776. * _.map({ 'a': 1, 'b': 2 }, timesThree);
  5777. * // => [3, 6] (iteration order is not guaranteed)
  5778. *
  5779. * var users = [
  5780. * { 'user': 'barney' },
  5781. * { 'user': 'fred' }
  5782. * ];
  5783. *
  5784. * // using the `_.property` callback shorthand
  5785. * _.map(users, 'user');
  5786. * // => ['barney', 'fred']
  5787. */
  5788. function map(collection, iteratee, thisArg) {
  5789. var func = isArray(collection) ? arrayMap : baseMap;
  5790. iteratee = getCallback(iteratee, thisArg, 3);
  5791. return func(collection, iteratee);
  5792. }
  5793. /**
  5794. * Gets the maximum value of `collection`. If `collection` is empty or falsey
  5795. * `-Infinity` is returned. If an iteratee function is provided it is invoked
  5796. * for each value in `collection` to generate the criterion by which the value
  5797. * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
  5798. * arguments; (value, index, collection).
  5799. *
  5800. * If a property name is provided for `predicate` the created `_.property`
  5801. * style callback returns the property value of the given element.
  5802. *
  5803. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5804. * style callback returns `true` for elements that have a matching property
  5805. * value, else `false`.
  5806. *
  5807. * If an object is provided for `predicate` the created `_.matches` style
  5808. * callback returns `true` for elements that have the properties of the given
  5809. * object, else `false`.
  5810. *
  5811. * @static
  5812. * @memberOf _
  5813. * @category Collection
  5814. * @param {Array|Object|string} collection The collection to iterate over.
  5815. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  5816. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5817. * @returns {*} Returns the maximum value.
  5818. * @example
  5819. *
  5820. * _.max([4, 2, 8, 6]);
  5821. * // => 8
  5822. *
  5823. * _.max([]);
  5824. * // => -Infinity
  5825. *
  5826. * var users = [
  5827. * { 'user': 'barney', 'age': 36 },
  5828. * { 'user': 'fred', 'age': 40 }
  5829. * ];
  5830. *
  5831. * _.max(users, function(chr) {
  5832. * return chr.age;
  5833. * });
  5834. * // => { 'user': 'fred', 'age': 40 };
  5835. *
  5836. * // using the `_.property` callback shorthand
  5837. * _.max(users, 'age');
  5838. * // => { 'user': 'fred', 'age': 40 };
  5839. */
  5840. var max = createExtremum(arrayMax);
  5841. /**
  5842. * Gets the minimum value of `collection`. If `collection` is empty or falsey
  5843. * `Infinity` is returned. If an iteratee function is provided it is invoked
  5844. * for each value in `collection` to generate the criterion by which the value
  5845. * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
  5846. * arguments; (value, index, collection).
  5847. *
  5848. * If a property name is provided for `predicate` the created `_.property`
  5849. * style callback returns the property value of the given element.
  5850. *
  5851. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5852. * style callback returns `true` for elements that have a matching property
  5853. * value, else `false`.
  5854. *
  5855. * If an object is provided for `predicate` the created `_.matches` style
  5856. * callback returns `true` for elements that have the properties of the given
  5857. * object, else `false`.
  5858. *
  5859. * @static
  5860. * @memberOf _
  5861. * @category Collection
  5862. * @param {Array|Object|string} collection The collection to iterate over.
  5863. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  5864. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5865. * @returns {*} Returns the minimum value.
  5866. * @example
  5867. *
  5868. * _.min([4, 2, 8, 6]);
  5869. * // => 2
  5870. *
  5871. * _.min([]);
  5872. * // => Infinity
  5873. *
  5874. * var users = [
  5875. * { 'user': 'barney', 'age': 36 },
  5876. * { 'user': 'fred', 'age': 40 }
  5877. * ];
  5878. *
  5879. * _.min(users, function(chr) {
  5880. * return chr.age;
  5881. * });
  5882. * // => { 'user': 'barney', 'age': 36 };
  5883. *
  5884. * // using the `_.property` callback shorthand
  5885. * _.min(users, 'age');
  5886. * // => { 'user': 'barney', 'age': 36 };
  5887. */
  5888. var min = createExtremum(arrayMin, true);
  5889. /**
  5890. * Creates an array of elements split into two groups, the first of which
  5891. * contains elements `predicate` returns truthy for, while the second of which
  5892. * contains elements `predicate` returns falsey for. The predicate is bound
  5893. * to `thisArg` and invoked with three arguments; (value, index|key, collection).
  5894. *
  5895. * If a property name is provided for `predicate` the created `_.property`
  5896. * style callback returns the property value of the given element.
  5897. *
  5898. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5899. * style callback returns `true` for elements that have a matching property
  5900. * value, else `false`.
  5901. *
  5902. * If an object is provided for `predicate` the created `_.matches` style
  5903. * callback returns `true` for elements that have the properties of the given
  5904. * object, else `false`.
  5905. *
  5906. * @static
  5907. * @memberOf _
  5908. * @category Collection
  5909. * @param {Array|Object|string} collection The collection to iterate over.
  5910. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  5911. * per iteration.
  5912. * @param {*} [thisArg] The `this` binding of `predicate`.
  5913. * @returns {Array} Returns the array of grouped elements.
  5914. * @example
  5915. *
  5916. * _.partition([1, 2, 3], function(n) {
  5917. * return n % 2;
  5918. * });
  5919. * // => [[1, 3], [2]]
  5920. *
  5921. * _.partition([1.2, 2.3, 3.4], function(n) {
  5922. * return this.floor(n) % 2;
  5923. * }, Math);
  5924. * // => [[1, 3], [2]]
  5925. *
  5926. * var users = [
  5927. * { 'user': 'barney', 'age': 36, 'active': false },
  5928. * { 'user': 'fred', 'age': 40, 'active': true },
  5929. * { 'user': 'pebbles', 'age': 1, 'active': false }
  5930. * ];
  5931. *
  5932. * var mapper = function(array) {
  5933. * return _.pluck(array, 'user');
  5934. * };
  5935. *
  5936. * // using the `_.matches` callback shorthand
  5937. * _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
  5938. * // => [['pebbles'], ['barney', 'fred']]
  5939. *
  5940. * // using the `_.matchesProperty` callback shorthand
  5941. * _.map(_.partition(users, 'active', false), mapper);
  5942. * // => [['barney', 'pebbles'], ['fred']]
  5943. *
  5944. * // using the `_.property` callback shorthand
  5945. * _.map(_.partition(users, 'active'), mapper);
  5946. * // => [['fred'], ['barney', 'pebbles']]
  5947. */
  5948. var partition = createAggregator(function(result, value, key) {
  5949. result[key ? 0 : 1].push(value);
  5950. }, function() { return [[], []]; });
  5951. /**
  5952. * Gets the value of `key` from all elements in `collection`.
  5953. *
  5954. * @static
  5955. * @memberOf _
  5956. * @category Collection
  5957. * @param {Array|Object|string} collection The collection to iterate over.
  5958. * @param {string} key The key of the property to pluck.
  5959. * @returns {Array} Returns the property values.
  5960. * @example
  5961. *
  5962. * var users = [
  5963. * { 'user': 'barney', 'age': 36 },
  5964. * { 'user': 'fred', 'age': 40 }
  5965. * ];
  5966. *
  5967. * _.pluck(users, 'user');
  5968. * // => ['barney', 'fred']
  5969. *
  5970. * var userIndex = _.indexBy(users, 'user');
  5971. * _.pluck(userIndex, 'age');
  5972. * // => [36, 40] (iteration order is not guaranteed)
  5973. */
  5974. function pluck(collection, key) {
  5975. return map(collection, baseProperty(key));
  5976. }
  5977. /**
  5978. * Reduces `collection` to a value which is the accumulated result of running
  5979. * each element in `collection` through `iteratee`, where each successive
  5980. * invocation is supplied the return value of the previous. If `accumulator`
  5981. * is not provided the first element of `collection` is used as the initial
  5982. * value. The `iteratee` is bound to `thisArg`and invoked with four arguments;
  5983. * (accumulator, value, index|key, collection).
  5984. *
  5985. * Many lodash methods are guarded to work as interatees for methods like
  5986. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  5987. *
  5988. * The guarded methods are:
  5989. * `assign`, `defaults`, `merge`, and `sortAllBy`
  5990. *
  5991. * @static
  5992. * @memberOf _
  5993. * @alias foldl, inject
  5994. * @category Collection
  5995. * @param {Array|Object|string} collection The collection to iterate over.
  5996. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  5997. * @param {*} [accumulator] The initial value.
  5998. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5999. * @returns {*} Returns the accumulated value.
  6000. * @example
  6001. *
  6002. * _.reduce([1, 2], function(sum, n) {
  6003. * return sum + n;
  6004. * });
  6005. * // => 3
  6006. *
  6007. * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
  6008. * result[key] = n * 3;
  6009. * return result;
  6010. * }, {});
  6011. * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
  6012. */
  6013. function reduce(collection, iteratee, accumulator, thisArg) {
  6014. var func = isArray(collection) ? arrayReduce : baseReduce;
  6015. return func(collection, getCallback(iteratee, thisArg, 4), accumulator, arguments.length < 3, baseEach);
  6016. }
  6017. /**
  6018. * This method is like `_.reduce` except that it iterates over elements of
  6019. * `collection` from right to left.
  6020. *
  6021. * @static
  6022. * @memberOf _
  6023. * @alias foldr
  6024. * @category Collection
  6025. * @param {Array|Object|string} collection The collection to iterate over.
  6026. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  6027. * @param {*} [accumulator] The initial value.
  6028. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6029. * @returns {*} Returns the accumulated value.
  6030. * @example
  6031. *
  6032. * var array = [[0, 1], [2, 3], [4, 5]];
  6033. *
  6034. * _.reduceRight(array, function(flattened, other) {
  6035. * return flattened.concat(other);
  6036. * }, []);
  6037. * // => [4, 5, 2, 3, 0, 1]
  6038. */
  6039. function reduceRight(collection, iteratee, accumulator, thisArg) {
  6040. var func = isArray(collection) ? arrayReduceRight : baseReduce;
  6041. return func(collection, getCallback(iteratee, thisArg, 4), accumulator, arguments.length < 3, baseEachRight);
  6042. }
  6043. /**
  6044. * The opposite of `_.filter`; this method returns the elements of `collection`
  6045. * that `predicate` does **not** return truthy for.
  6046. *
  6047. * If a property name is provided for `predicate` the created `_.property`
  6048. * style callback returns the property value of the given element.
  6049. *
  6050. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6051. * style callback returns `true` for elements that have a matching property
  6052. * value, else `false`.
  6053. *
  6054. * If an object is provided for `predicate` the created `_.matches` style
  6055. * callback returns `true` for elements that have the properties of the given
  6056. * object, else `false`.
  6057. *
  6058. * @static
  6059. * @memberOf _
  6060. * @category Collection
  6061. * @param {Array|Object|string} collection The collection to iterate over.
  6062. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6063. * per iteration.
  6064. * @param {*} [thisArg] The `this` binding of `predicate`.
  6065. * @returns {Array} Returns the new filtered array.
  6066. * @example
  6067. *
  6068. * _.reject([1, 2, 3, 4], function(n) {
  6069. * return n % 2 == 0;
  6070. * });
  6071. * // => [1, 3]
  6072. *
  6073. * var users = [
  6074. * { 'user': 'barney', 'age': 36, 'active': false },
  6075. * { 'user': 'fred', 'age': 40, 'active': true }
  6076. * ];
  6077. *
  6078. * // using the `_.matches` callback shorthand
  6079. * _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
  6080. * // => ['barney']
  6081. *
  6082. * // using the `_.matchesProperty` callback shorthand
  6083. * _.pluck(_.reject(users, 'active', false), 'user');
  6084. * // => ['fred']
  6085. *
  6086. * // using the `_.property` callback shorthand
  6087. * _.pluck(_.reject(users, 'active'), 'user');
  6088. * // => ['barney']
  6089. */
  6090. function reject(collection, predicate, thisArg) {
  6091. var func = isArray(collection) ? arrayFilter : baseFilter;
  6092. predicate = getCallback(predicate, thisArg, 3);
  6093. return func(collection, function(value, index, collection) {
  6094. return !predicate(value, index, collection);
  6095. });
  6096. }
  6097. /**
  6098. * Gets a random element or `n` random elements from a collection.
  6099. *
  6100. * @static
  6101. * @memberOf _
  6102. * @category Collection
  6103. * @param {Array|Object|string} collection The collection to sample.
  6104. * @param {number} [n] The number of elements to sample.
  6105. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  6106. * @returns {*} Returns the random sample(s).
  6107. * @example
  6108. *
  6109. * _.sample([1, 2, 3, 4]);
  6110. * // => 2
  6111. *
  6112. * _.sample([1, 2, 3, 4], 2);
  6113. * // => [3, 1]
  6114. */
  6115. function sample(collection, n, guard) {
  6116. if (guard ? isIterateeCall(collection, n, guard) : n == null) {
  6117. collection = toIterable(collection);
  6118. var length = collection.length;
  6119. return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
  6120. }
  6121. var result = shuffle(collection);
  6122. result.length = nativeMin(n < 0 ? 0 : (+n || 0), result.length);
  6123. return result;
  6124. }
  6125. /**
  6126. * Creates an array of shuffled values, using a version of the Fisher-Yates
  6127. * shuffle. See [Wikipedia](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle)
  6128. * for more details.
  6129. *
  6130. * @static
  6131. * @memberOf _
  6132. * @category Collection
  6133. * @param {Array|Object|string} collection The collection to shuffle.
  6134. * @returns {Array} Returns the new shuffled array.
  6135. * @example
  6136. *
  6137. * _.shuffle([1, 2, 3, 4]);
  6138. * // => [4, 1, 3, 2]
  6139. */
  6140. function shuffle(collection) {
  6141. collection = toIterable(collection);
  6142. var index = -1,
  6143. length = collection.length,
  6144. result = Array(length);
  6145. while (++index < length) {
  6146. var rand = baseRandom(0, index);
  6147. if (index != rand) {
  6148. result[index] = result[rand];
  6149. }
  6150. result[rand] = collection[index];
  6151. }
  6152. return result;
  6153. }
  6154. /**
  6155. * Gets the size of `collection` by returning `collection.length` for
  6156. * array-like values or the number of own enumerable properties for objects.
  6157. *
  6158. * @static
  6159. * @memberOf _
  6160. * @category Collection
  6161. * @param {Array|Object|string} collection The collection to inspect.
  6162. * @returns {number} Returns the size of `collection`.
  6163. * @example
  6164. *
  6165. * _.size([1, 2, 3]);
  6166. * // => 3
  6167. *
  6168. * _.size({ 'a': 1, 'b': 2 });
  6169. * // => 2
  6170. *
  6171. * _.size('pebbles');
  6172. * // => 7
  6173. */
  6174. function size(collection) {
  6175. var length = collection ? collection.length : 0;
  6176. return isLength(length) ? length : keys(collection).length;
  6177. }
  6178. /**
  6179. * Checks if `predicate` returns truthy for **any** element of `collection`.
  6180. * The function returns as soon as it finds a passing value and does not iterate
  6181. * over the entire collection. The predicate is bound to `thisArg` and invoked
  6182. * with three arguments; (value, index|key, collection).
  6183. *
  6184. * If a property name is provided for `predicate` the created `_.property`
  6185. * style callback returns the property value of the given element.
  6186. *
  6187. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6188. * style callback returns `true` for elements that have a matching property
  6189. * value, else `false`.
  6190. *
  6191. * If an object is provided for `predicate` the created `_.matches` style
  6192. * callback returns `true` for elements that have the properties of the given
  6193. * object, else `false`.
  6194. *
  6195. * @static
  6196. * @memberOf _
  6197. * @alias any
  6198. * @category Collection
  6199. * @param {Array|Object|string} collection The collection to iterate over.
  6200. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6201. * per iteration.
  6202. * @param {*} [thisArg] The `this` binding of `predicate`.
  6203. * @returns {boolean} Returns `true` if any element passes the predicate check,
  6204. * else `false`.
  6205. * @example
  6206. *
  6207. * _.some([null, 0, 'yes', false], Boolean);
  6208. * // => true
  6209. *
  6210. * var users = [
  6211. * { 'user': 'barney', 'active': true },
  6212. * { 'user': 'fred', 'active': false }
  6213. * ];
  6214. *
  6215. * // using the `_.matches` callback shorthand
  6216. * _.some(users, { user': 'barney', 'active': false });
  6217. * // => false
  6218. *
  6219. * // using the `_.matchesProperty` callback shorthand
  6220. * _.some(users, 'active', false);
  6221. * // => true
  6222. *
  6223. * // using the `_.property` callback shorthand
  6224. * _.some(users, 'active');
  6225. * // => true
  6226. */
  6227. function some(collection, predicate, thisArg) {
  6228. var func = isArray(collection) ? arraySome : baseSome;
  6229. if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
  6230. predicate = getCallback(predicate, thisArg, 3);
  6231. }
  6232. return func(collection, predicate);
  6233. }
  6234. /**
  6235. * Creates an array of elements, sorted in ascending order by the results of
  6236. * running each element in a collection through `iteratee`. This method performs
  6237. * a stable sort, that is, it preserves the original sort order of equal elements.
  6238. * The `iteratee` is bound to `thisArg` and invoked with three arguments;
  6239. * (value, index|key, collection).
  6240. *
  6241. * If a property name is provided for `predicate` the created `_.property`
  6242. * style callback returns the property value of the given element.
  6243. *
  6244. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6245. * style callback returns `true` for elements that have a matching property
  6246. * value, else `false`.
  6247. *
  6248. * If an object is provided for `predicate` the created `_.matches` style
  6249. * callback returns `true` for elements that have the properties of the given
  6250. * object, else `false`.
  6251. *
  6252. * @static
  6253. * @memberOf _
  6254. * @category Collection
  6255. * @param {Array|Object|string} collection The collection to iterate over.
  6256. * @param {Array|Function|Object|string} [iteratee=_.identity] The function
  6257. * invoked per iteration. If a property name or an object is provided it is
  6258. * used to create a `_.property` or `_.matches` style callback respectively.
  6259. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6260. * @returns {Array} Returns the new sorted array.
  6261. * @example
  6262. *
  6263. * _.sortBy([1, 2, 3], function(n) {
  6264. * return Math.sin(n);
  6265. * });
  6266. * // => [3, 1, 2]
  6267. *
  6268. * _.sortBy([1, 2, 3], function(n) {
  6269. * return this.sin(n);
  6270. * }, Math);
  6271. * // => [3, 1, 2]
  6272. *
  6273. * var users = [
  6274. * { 'user': 'fred' },
  6275. * { 'user': 'pebbles' },
  6276. * { 'user': 'barney' }
  6277. * ];
  6278. *
  6279. * // using the `_.property` callback shorthand
  6280. * _.pluck(_.sortBy(users, 'user'), 'user');
  6281. * // => ['barney', 'fred', 'pebbles']
  6282. */
  6283. function sortBy(collection, iteratee, thisArg) {
  6284. var index = -1,
  6285. length = collection ? collection.length : 0,
  6286. result = isLength(length) ? Array(length) : [];
  6287. if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
  6288. iteratee = null;
  6289. }
  6290. iteratee = getCallback(iteratee, thisArg, 3);
  6291. baseEach(collection, function(value, key, collection) {
  6292. result[++index] = { 'criteria': iteratee(value, key, collection), 'index': index, 'value': value };
  6293. });
  6294. return baseSortBy(result, compareAscending);
  6295. }
  6296. /**
  6297. * This method is like `_.sortBy` except that it sorts by property names
  6298. * instead of an iteratee function.
  6299. *
  6300. * @static
  6301. * @memberOf _
  6302. * @category Collection
  6303. * @param {Array|Object|string} collection The collection to iterate over.
  6304. * @param {...(string|string[])} props The property names to sort by,
  6305. * specified as individual property names or arrays of property names.
  6306. * @returns {Array} Returns the new sorted array.
  6307. * @example
  6308. *
  6309. * var users = [
  6310. * { 'user': 'barney', 'age': 36 },
  6311. * { 'user': 'fred', 'age': 40 },
  6312. * { 'user': 'barney', 'age': 26 },
  6313. * { 'user': 'fred', 'age': 30 }
  6314. * ];
  6315. *
  6316. * _.map(_.sortByAll(users, ['user', 'age']), _.values);
  6317. * // => [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]]
  6318. */
  6319. function sortByAll(collection) {
  6320. var args = arguments;
  6321. if (args.length > 3 && isIterateeCall(args[1], args[2], args[3])) {
  6322. args = [collection, args[1]];
  6323. }
  6324. var index = -1,
  6325. length = collection ? collection.length : 0,
  6326. props = baseFlatten(args, false, false, 1),
  6327. result = isLength(length) ? Array(length) : [];
  6328. baseEach(collection, function(value) {
  6329. var length = props.length,
  6330. criteria = Array(length);
  6331. while (length--) {
  6332. criteria[length] = value == null ? undefined : value[props[length]];
  6333. }
  6334. result[++index] = { 'criteria': criteria, 'index': index, 'value': value };
  6335. });
  6336. return baseSortBy(result, compareMultipleAscending);
  6337. }
  6338. /**
  6339. * Performs a deep comparison between each element in `collection` and the
  6340. * source object, returning an array of all elements that have equivalent
  6341. * property values.
  6342. *
  6343. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  6344. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  6345. * their own, not inherited, enumerable properties. For comparing a single
  6346. * own or inherited property value see `_.matchesProperty`.
  6347. *
  6348. * @static
  6349. * @memberOf _
  6350. * @category Collection
  6351. * @param {Array|Object|string} collection The collection to search.
  6352. * @param {Object} source The object of property values to match.
  6353. * @returns {Array} Returns the new filtered array.
  6354. * @example
  6355. *
  6356. * var users = [
  6357. * { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] },
  6358. * { 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] }
  6359. * ];
  6360. *
  6361. * _.pluck(_.where(users, { 'age': 36, 'active': false }), 'user');
  6362. * // => ['barney']
  6363. *
  6364. * _.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
  6365. * // => ['fred']
  6366. */
  6367. function where(collection, source) {
  6368. return filter(collection, baseMatches(source));
  6369. }
  6370. /*------------------------------------------------------------------------*/
  6371. /**
  6372. * Gets the number of milliseconds that have elapsed since the Unix epoch
  6373. * (1 January 1970 00:00:00 UTC).
  6374. *
  6375. * @static
  6376. * @memberOf _
  6377. * @category Date
  6378. * @example
  6379. *
  6380. * _.defer(function(stamp) {
  6381. * console.log(_.now() - stamp);
  6382. * }, _.now());
  6383. * // => logs the number of milliseconds it took for the deferred function to be invoked
  6384. */
  6385. var now = nativeNow || function() {
  6386. return new Date().getTime();
  6387. };
  6388. /*------------------------------------------------------------------------*/
  6389. /**
  6390. * The opposite of `_.before`; this method creates a function that invokes
  6391. * `func` once it is called `n` or more times.
  6392. *
  6393. * @static
  6394. * @memberOf _
  6395. * @category Function
  6396. * @param {number} n The number of calls before `func` is invoked.
  6397. * @param {Function} func The function to restrict.
  6398. * @returns {Function} Returns the new restricted function.
  6399. * @example
  6400. *
  6401. * var saves = ['profile', 'settings'];
  6402. *
  6403. * var done = _.after(saves.length, function() {
  6404. * console.log('done saving!');
  6405. * });
  6406. *
  6407. * _.forEach(saves, function(type) {
  6408. * asyncSave({ 'type': type, 'complete': done });
  6409. * });
  6410. * // => logs 'done saving!' after the two async saves have completed
  6411. */
  6412. function after(n, func) {
  6413. if (typeof func != 'function') {
  6414. if (typeof n == 'function') {
  6415. var temp = n;
  6416. n = func;
  6417. func = temp;
  6418. } else {
  6419. throw new TypeError(FUNC_ERROR_TEXT);
  6420. }
  6421. }
  6422. n = nativeIsFinite(n = +n) ? n : 0;
  6423. return function() {
  6424. if (--n < 1) {
  6425. return func.apply(this, arguments);
  6426. }
  6427. };
  6428. }
  6429. /**
  6430. * Creates a function that accepts up to `n` arguments ignoring any
  6431. * additional arguments.
  6432. *
  6433. * @static
  6434. * @memberOf _
  6435. * @category Function
  6436. * @param {Function} func The function to cap arguments for.
  6437. * @param {number} [n=func.length] The arity cap.
  6438. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  6439. * @returns {Function} Returns the new function.
  6440. * @example
  6441. *
  6442. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  6443. * // => [6, 8, 10]
  6444. */
  6445. function ary(func, n, guard) {
  6446. if (guard && isIterateeCall(func, n, guard)) {
  6447. n = null;
  6448. }
  6449. n = (func && n == null) ? func.length : nativeMax(+n || 0, 0);
  6450. return createWrapper(func, ARY_FLAG, null, null, null, null, n);
  6451. }
  6452. /**
  6453. * Creates a function that invokes `func`, with the `this` binding and arguments
  6454. * of the created function, while it is called less than `n` times. Subsequent
  6455. * calls to the created function return the result of the last `func` invocation.
  6456. *
  6457. * @static
  6458. * @memberOf _
  6459. * @category Function
  6460. * @param {number} n The number of calls at which `func` is no longer invoked.
  6461. * @param {Function} func The function to restrict.
  6462. * @returns {Function} Returns the new restricted function.
  6463. * @example
  6464. *
  6465. * jQuery('#add').on('click', _.before(5, addContactToList));
  6466. * // => allows adding up to 4 contacts to the list
  6467. */
  6468. function before(n, func) {
  6469. var result;
  6470. if (typeof func != 'function') {
  6471. if (typeof n == 'function') {
  6472. var temp = n;
  6473. n = func;
  6474. func = temp;
  6475. } else {
  6476. throw new TypeError(FUNC_ERROR_TEXT);
  6477. }
  6478. }
  6479. return function() {
  6480. if (--n > 0) {
  6481. result = func.apply(this, arguments);
  6482. } else {
  6483. func = null;
  6484. }
  6485. return result;
  6486. };
  6487. }
  6488. /**
  6489. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  6490. * and prepends any additional `_.bind` arguments to those provided to the
  6491. * bound function.
  6492. *
  6493. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  6494. * may be used as a placeholder for partially applied arguments.
  6495. *
  6496. * **Note:** Unlike native `Function#bind` this method does not set the `length`
  6497. * property of bound functions.
  6498. *
  6499. * @static
  6500. * @memberOf _
  6501. * @category Function
  6502. * @param {Function} func The function to bind.
  6503. * @param {*} thisArg The `this` binding of `func`.
  6504. * @param {...*} [args] The arguments to be partially applied.
  6505. * @returns {Function} Returns the new bound function.
  6506. * @example
  6507. *
  6508. * var greet = function(greeting, punctuation) {
  6509. * return greeting + ' ' + this.user + punctuation;
  6510. * };
  6511. *
  6512. * var object = { 'user': 'fred' };
  6513. *
  6514. * var bound = _.bind(greet, object, 'hi');
  6515. * bound('!');
  6516. * // => 'hi fred!'
  6517. *
  6518. * // using placeholders
  6519. * var bound = _.bind(greet, object, _, '!');
  6520. * bound('hi');
  6521. * // => 'hi fred!'
  6522. */
  6523. function bind(func, thisArg) {
  6524. var bitmask = BIND_FLAG;
  6525. if (arguments.length > 2) {
  6526. var partials = baseSlice(arguments, 2),
  6527. holders = replaceHolders(partials, bind.placeholder);
  6528. bitmask |= PARTIAL_FLAG;
  6529. }
  6530. return createWrapper(func, bitmask, thisArg, partials, holders);
  6531. }
  6532. /**
  6533. * Binds methods of an object to the object itself, overwriting the existing
  6534. * method. Method names may be specified as individual arguments or as arrays
  6535. * of method names. If no method names are provided all enumerable function
  6536. * properties, own and inherited, of `object` are bound.
  6537. *
  6538. * **Note:** This method does not set the `length` property of bound functions.
  6539. *
  6540. * @static
  6541. * @memberOf _
  6542. * @category Function
  6543. * @param {Object} object The object to bind and assign the bound methods to.
  6544. * @param {...(string|string[])} [methodNames] The object method names to bind,
  6545. * specified as individual method names or arrays of method names.
  6546. * @returns {Object} Returns `object`.
  6547. * @example
  6548. *
  6549. * var view = {
  6550. * 'label': 'docs',
  6551. * 'onClick': function() {
  6552. * console.log('clicked ' + this.label);
  6553. * }
  6554. * };
  6555. *
  6556. * _.bindAll(view);
  6557. * jQuery('#docs').on('click', view.onClick);
  6558. * // => logs 'clicked docs' when the element is clicked
  6559. */
  6560. function bindAll(object) {
  6561. return baseBindAll(object,
  6562. arguments.length > 1
  6563. ? baseFlatten(arguments, false, false, 1)
  6564. : functions(object)
  6565. );
  6566. }
  6567. /**
  6568. * Creates a function that invokes the method at `object[key]` and prepends
  6569. * any additional `_.bindKey` arguments to those provided to the bound function.
  6570. *
  6571. * This method differs from `_.bind` by allowing bound functions to reference
  6572. * methods that may be redefined or don't yet exist.
  6573. * See [Peter Michaux's article](http://michaux.ca/articles/lazy-function-definition-pattern)
  6574. * for more details.
  6575. *
  6576. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  6577. * builds, may be used as a placeholder for partially applied arguments.
  6578. *
  6579. * @static
  6580. * @memberOf _
  6581. * @category Function
  6582. * @param {Object} object The object the method belongs to.
  6583. * @param {string} key The key of the method.
  6584. * @param {...*} [args] The arguments to be partially applied.
  6585. * @returns {Function} Returns the new bound function.
  6586. * @example
  6587. *
  6588. * var object = {
  6589. * 'user': 'fred',
  6590. * 'greet': function(greeting, punctuation) {
  6591. * return greeting + ' ' + this.user + punctuation;
  6592. * }
  6593. * };
  6594. *
  6595. * var bound = _.bindKey(object, 'greet', 'hi');
  6596. * bound('!');
  6597. * // => 'hi fred!'
  6598. *
  6599. * object.greet = function(greeting, punctuation) {
  6600. * return greeting + 'ya ' + this.user + punctuation;
  6601. * };
  6602. *
  6603. * bound('!');
  6604. * // => 'hiya fred!'
  6605. *
  6606. * // using placeholders
  6607. * var bound = _.bindKey(object, 'greet', _, '!');
  6608. * bound('hi');
  6609. * // => 'hiya fred!'
  6610. */
  6611. function bindKey(object, key) {
  6612. var bitmask = BIND_FLAG | BIND_KEY_FLAG;
  6613. if (arguments.length > 2) {
  6614. var partials = baseSlice(arguments, 2),
  6615. holders = replaceHolders(partials, bindKey.placeholder);
  6616. bitmask |= PARTIAL_FLAG;
  6617. }
  6618. return createWrapper(key, bitmask, object, partials, holders);
  6619. }
  6620. /**
  6621. * Creates a function that accepts one or more arguments of `func` that when
  6622. * called either invokes `func` returning its result, if all `func` arguments
  6623. * have been provided, or returns a function that accepts one or more of the
  6624. * remaining `func` arguments, and so on. The arity of `func` may be specified
  6625. * if `func.length` is not sufficient.
  6626. *
  6627. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  6628. * may be used as a placeholder for provided arguments.
  6629. *
  6630. * **Note:** This method does not set the `length` property of curried functions.
  6631. *
  6632. * @static
  6633. * @memberOf _
  6634. * @category Function
  6635. * @param {Function} func The function to curry.
  6636. * @param {number} [arity=func.length] The arity of `func`.
  6637. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  6638. * @returns {Function} Returns the new curried function.
  6639. * @example
  6640. *
  6641. * var abc = function(a, b, c) {
  6642. * return [a, b, c];
  6643. * };
  6644. *
  6645. * var curried = _.curry(abc);
  6646. *
  6647. * curried(1)(2)(3);
  6648. * // => [1, 2, 3]
  6649. *
  6650. * curried(1, 2)(3);
  6651. * // => [1, 2, 3]
  6652. *
  6653. * curried(1, 2, 3);
  6654. * // => [1, 2, 3]
  6655. *
  6656. * // using placeholders
  6657. * curried(1)(_, 3)(2);
  6658. * // => [1, 2, 3]
  6659. */
  6660. function curry(func, arity, guard) {
  6661. if (guard && isIterateeCall(func, arity, guard)) {
  6662. arity = null;
  6663. }
  6664. var result = createWrapper(func, CURRY_FLAG, null, null, null, null, null, arity);
  6665. result.placeholder = curry.placeholder;
  6666. return result;
  6667. }
  6668. /**
  6669. * This method is like `_.curry` except that arguments are applied to `func`
  6670. * in the manner of `_.partialRight` instead of `_.partial`.
  6671. *
  6672. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  6673. * builds, may be used as a placeholder for provided arguments.
  6674. *
  6675. * **Note:** This method does not set the `length` property of curried functions.
  6676. *
  6677. * @static
  6678. * @memberOf _
  6679. * @category Function
  6680. * @param {Function} func The function to curry.
  6681. * @param {number} [arity=func.length] The arity of `func`.
  6682. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  6683. * @returns {Function} Returns the new curried function.
  6684. * @example
  6685. *
  6686. * var abc = function(a, b, c) {
  6687. * return [a, b, c];
  6688. * };
  6689. *
  6690. * var curried = _.curryRight(abc);
  6691. *
  6692. * curried(3)(2)(1);
  6693. * // => [1, 2, 3]
  6694. *
  6695. * curried(2, 3)(1);
  6696. * // => [1, 2, 3]
  6697. *
  6698. * curried(1, 2, 3);
  6699. * // => [1, 2, 3]
  6700. *
  6701. * // using placeholders
  6702. * curried(3)(1, _)(2);
  6703. * // => [1, 2, 3]
  6704. */
  6705. function curryRight(func, arity, guard) {
  6706. if (guard && isIterateeCall(func, arity, guard)) {
  6707. arity = null;
  6708. }
  6709. var result = createWrapper(func, CURRY_RIGHT_FLAG, null, null, null, null, null, arity);
  6710. result.placeholder = curryRight.placeholder;
  6711. return result;
  6712. }
  6713. /**
  6714. * Creates a function that delays invoking `func` until after `wait` milliseconds
  6715. * have elapsed since the last time it was invoked. The created function comes
  6716. * with a `cancel` method to cancel delayed invocations. Provide an options
  6717. * object to indicate that `func` should be invoked on the leading and/or
  6718. * trailing edge of the `wait` timeout. Subsequent calls to the debounced
  6719. * function return the result of the last `func` invocation.
  6720. *
  6721. * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
  6722. * on the trailing edge of the timeout only if the the debounced function is
  6723. * invoked more than once during the `wait` timeout.
  6724. *
  6725. * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
  6726. * for details over the differences between `_.debounce` and `_.throttle`.
  6727. *
  6728. * @static
  6729. * @memberOf _
  6730. * @category Function
  6731. * @param {Function} func The function to debounce.
  6732. * @param {number} wait The number of milliseconds to delay.
  6733. * @param {Object} [options] The options object.
  6734. * @param {boolean} [options.leading=false] Specify invoking on the leading
  6735. * edge of the timeout.
  6736. * @param {number} [options.maxWait] The maximum time `func` is allowed to be
  6737. * delayed before it is invoked.
  6738. * @param {boolean} [options.trailing=true] Specify invoking on the trailing
  6739. * edge of the timeout.
  6740. * @returns {Function} Returns the new debounced function.
  6741. * @example
  6742. *
  6743. * // avoid costly calculations while the window size is in flux
  6744. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  6745. *
  6746. * // invoke `sendMail` when the click event is fired, debouncing subsequent calls
  6747. * jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
  6748. * 'leading': true,
  6749. * 'trailing': false
  6750. * }));
  6751. *
  6752. * // ensure `batchLog` is invoked once after 1 second of debounced calls
  6753. * var source = new EventSource('/stream');
  6754. * jQuery(source).on('message', _.debounce(batchLog, 250, {
  6755. * 'maxWait': 1000
  6756. * }));
  6757. *
  6758. * // cancel a debounced call
  6759. * var todoChanges = _.debounce(batchLog, 1000);
  6760. * Object.observe(models.todo, todoChanges);
  6761. *
  6762. * Object.observe(models, function(changes) {
  6763. * if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
  6764. * todoChanges.cancel();
  6765. * }
  6766. * }, ['delete']);
  6767. *
  6768. * // ...at some point `models.todo` is changed
  6769. * models.todo.completed = true;
  6770. *
  6771. * // ...before 1 second has passed `models.todo` is deleted
  6772. * // which cancels the debounced `todoChanges` call
  6773. * delete models.todo;
  6774. */
  6775. function debounce(func, wait, options) {
  6776. var args,
  6777. maxTimeoutId,
  6778. result,
  6779. stamp,
  6780. thisArg,
  6781. timeoutId,
  6782. trailingCall,
  6783. lastCalled = 0,
  6784. maxWait = false,
  6785. trailing = true;
  6786. if (typeof func != 'function') {
  6787. throw new TypeError(FUNC_ERROR_TEXT);
  6788. }
  6789. wait = wait < 0 ? 0 : wait;
  6790. if (options === true) {
  6791. var leading = true;
  6792. trailing = false;
  6793. } else if (isObject(options)) {
  6794. leading = options.leading;
  6795. maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
  6796. trailing = 'trailing' in options ? options.trailing : trailing;
  6797. }
  6798. function cancel() {
  6799. if (timeoutId) {
  6800. clearTimeout(timeoutId);
  6801. }
  6802. if (maxTimeoutId) {
  6803. clearTimeout(maxTimeoutId);
  6804. }
  6805. maxTimeoutId = timeoutId = trailingCall = undefined;
  6806. }
  6807. function delayed() {
  6808. var remaining = wait - (now() - stamp);
  6809. if (remaining <= 0 || remaining > wait) {
  6810. if (maxTimeoutId) {
  6811. clearTimeout(maxTimeoutId);
  6812. }
  6813. var isCalled = trailingCall;
  6814. maxTimeoutId = timeoutId = trailingCall = undefined;
  6815. if (isCalled) {
  6816. lastCalled = now();
  6817. result = func.apply(thisArg, args);
  6818. if (!timeoutId && !maxTimeoutId) {
  6819. args = thisArg = null;
  6820. }
  6821. }
  6822. } else {
  6823. timeoutId = setTimeout(delayed, remaining);
  6824. }
  6825. }
  6826. function maxDelayed() {
  6827. if (timeoutId) {
  6828. clearTimeout(timeoutId);
  6829. }
  6830. maxTimeoutId = timeoutId = trailingCall = undefined;
  6831. if (trailing || (maxWait !== wait)) {
  6832. lastCalled = now();
  6833. result = func.apply(thisArg, args);
  6834. if (!timeoutId && !maxTimeoutId) {
  6835. args = thisArg = null;
  6836. }
  6837. }
  6838. }
  6839. function debounced() {
  6840. args = arguments;
  6841. stamp = now();
  6842. thisArg = this;
  6843. trailingCall = trailing && (timeoutId || !leading);
  6844. if (maxWait === false) {
  6845. var leadingCall = leading && !timeoutId;
  6846. } else {
  6847. if (!maxTimeoutId && !leading) {
  6848. lastCalled = stamp;
  6849. }
  6850. var remaining = maxWait - (stamp - lastCalled),
  6851. isCalled = remaining <= 0 || remaining > maxWait;
  6852. if (isCalled) {
  6853. if (maxTimeoutId) {
  6854. maxTimeoutId = clearTimeout(maxTimeoutId);
  6855. }
  6856. lastCalled = stamp;
  6857. result = func.apply(thisArg, args);
  6858. }
  6859. else if (!maxTimeoutId) {
  6860. maxTimeoutId = setTimeout(maxDelayed, remaining);
  6861. }
  6862. }
  6863. if (isCalled && timeoutId) {
  6864. timeoutId = clearTimeout(timeoutId);
  6865. }
  6866. else if (!timeoutId && wait !== maxWait) {
  6867. timeoutId = setTimeout(delayed, wait);
  6868. }
  6869. if (leadingCall) {
  6870. isCalled = true;
  6871. result = func.apply(thisArg, args);
  6872. }
  6873. if (isCalled && !timeoutId && !maxTimeoutId) {
  6874. args = thisArg = null;
  6875. }
  6876. return result;
  6877. }
  6878. debounced.cancel = cancel;
  6879. return debounced;
  6880. }
  6881. /**
  6882. * Defers invoking the `func` until the current call stack has cleared. Any
  6883. * additional arguments are provided to `func` when it is invoked.
  6884. *
  6885. * @static
  6886. * @memberOf _
  6887. * @category Function
  6888. * @param {Function} func The function to defer.
  6889. * @param {...*} [args] The arguments to invoke the function with.
  6890. * @returns {number} Returns the timer id.
  6891. * @example
  6892. *
  6893. * _.defer(function(text) {
  6894. * console.log(text);
  6895. * }, 'deferred');
  6896. * // logs 'deferred' after one or more milliseconds
  6897. */
  6898. function defer(func) {
  6899. return baseDelay(func, 1, arguments, 1);
  6900. }
  6901. /**
  6902. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  6903. * provided to `func` when it is invoked.
  6904. *
  6905. * @static
  6906. * @memberOf _
  6907. * @category Function
  6908. * @param {Function} func The function to delay.
  6909. * @param {number} wait The number of milliseconds to delay invocation.
  6910. * @param {...*} [args] The arguments to invoke the function with.
  6911. * @returns {number} Returns the timer id.
  6912. * @example
  6913. *
  6914. * _.delay(function(text) {
  6915. * console.log(text);
  6916. * }, 1000, 'later');
  6917. * // => logs 'later' after one second
  6918. */
  6919. function delay(func, wait) {
  6920. return baseDelay(func, wait, arguments, 2);
  6921. }
  6922. /**
  6923. * Creates a function that returns the result of invoking the provided
  6924. * functions with the `this` binding of the created function, where each
  6925. * successive invocation is supplied the return value of the previous.
  6926. *
  6927. * @static
  6928. * @memberOf _
  6929. * @category Function
  6930. * @param {...Function} [funcs] Functions to invoke.
  6931. * @returns {Function} Returns the new function.
  6932. * @example
  6933. *
  6934. * function add(x, y) {
  6935. * return x + y;
  6936. * }
  6937. *
  6938. * function square(n) {
  6939. * return n * n;
  6940. * }
  6941. *
  6942. * var addSquare = _.flow(add, square);
  6943. * addSquare(1, 2);
  6944. * // => 9
  6945. */
  6946. function flow() {
  6947. var funcs = arguments,
  6948. length = funcs.length;
  6949. if (!length) {
  6950. return function() { return arguments[0]; };
  6951. }
  6952. if (!arrayEvery(funcs, baseIsFunction)) {
  6953. throw new TypeError(FUNC_ERROR_TEXT);
  6954. }
  6955. return function() {
  6956. var index = 0,
  6957. result = funcs[index].apply(this, arguments);
  6958. while (++index < length) {
  6959. result = funcs[index].call(this, result);
  6960. }
  6961. return result;
  6962. };
  6963. }
  6964. /**
  6965. * This method is like `_.flow` except that it creates a function that
  6966. * invokes the provided functions from right to left.
  6967. *
  6968. * @static
  6969. * @memberOf _
  6970. * @alias backflow, compose
  6971. * @category Function
  6972. * @param {...Function} [funcs] Functions to invoke.
  6973. * @returns {Function} Returns the new function.
  6974. * @example
  6975. *
  6976. * function add(x, y) {
  6977. * return x + y;
  6978. * }
  6979. *
  6980. * function square(n) {
  6981. * return n * n;
  6982. * }
  6983. *
  6984. * var addSquare = _.flowRight(square, add);
  6985. * addSquare(1, 2);
  6986. * // => 9
  6987. */
  6988. function flowRight() {
  6989. var funcs = arguments,
  6990. fromIndex = funcs.length - 1;
  6991. if (fromIndex < 0) {
  6992. return function() { return arguments[0]; };
  6993. }
  6994. if (!arrayEvery(funcs, baseIsFunction)) {
  6995. throw new TypeError(FUNC_ERROR_TEXT);
  6996. }
  6997. return function() {
  6998. var index = fromIndex,
  6999. result = funcs[index].apply(this, arguments);
  7000. while (index--) {
  7001. result = funcs[index].call(this, result);
  7002. }
  7003. return result;
  7004. };
  7005. }
  7006. /**
  7007. * Creates a function that memoizes the result of `func`. If `resolver` is
  7008. * provided it determines the cache key for storing the result based on the
  7009. * arguments provided to the memoized function. By default, the first argument
  7010. * provided to the memoized function is coerced to a string and used as the
  7011. * cache key. The `func` is invoked with the `this` binding of the memoized
  7012. * function.
  7013. *
  7014. * **Note:** The cache is exposed as the `cache` property on the memoized
  7015. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  7016. * constructor with one whose instances implement the ES `Map` method interface
  7017. * of `get`, `has`, and `set`. See the
  7018. * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-properties-of-the-map-prototype-object)
  7019. * for more details.
  7020. *
  7021. * @static
  7022. * @memberOf _
  7023. * @category Function
  7024. * @param {Function} func The function to have its output memoized.
  7025. * @param {Function} [resolver] The function to resolve the cache key.
  7026. * @returns {Function} Returns the new memoizing function.
  7027. * @example
  7028. *
  7029. * var upperCase = _.memoize(function(string) {
  7030. * return string.toUpperCase();
  7031. * });
  7032. *
  7033. * upperCase('fred');
  7034. * // => 'FRED'
  7035. *
  7036. * // modifying the result cache
  7037. * upperCase.cache.set('fred', 'BARNEY');
  7038. * upperCase('fred');
  7039. * // => 'BARNEY'
  7040. *
  7041. * // replacing `_.memoize.Cache`
  7042. * var object = { 'user': 'fred' };
  7043. * var other = { 'user': 'barney' };
  7044. * var identity = _.memoize(_.identity);
  7045. *
  7046. * identity(object);
  7047. * // => { 'user': 'fred' }
  7048. * identity(other);
  7049. * // => { 'user': 'fred' }
  7050. *
  7051. * _.memoize.Cache = WeakMap;
  7052. * var identity = _.memoize(_.identity);
  7053. *
  7054. * identity(object);
  7055. * // => { 'user': 'fred' }
  7056. * identity(other);
  7057. * // => { 'user': 'barney' }
  7058. */
  7059. function memoize(func, resolver) {
  7060. if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
  7061. throw new TypeError(FUNC_ERROR_TEXT);
  7062. }
  7063. var memoized = function() {
  7064. var cache = memoized.cache,
  7065. key = resolver ? resolver.apply(this, arguments) : arguments[0];
  7066. if (cache.has(key)) {
  7067. return cache.get(key);
  7068. }
  7069. var result = func.apply(this, arguments);
  7070. cache.set(key, result);
  7071. return result;
  7072. };
  7073. memoized.cache = new memoize.Cache;
  7074. return memoized;
  7075. }
  7076. /**
  7077. * Creates a function that negates the result of the predicate `func`. The
  7078. * `func` predicate is invoked with the `this` binding and arguments of the
  7079. * created function.
  7080. *
  7081. * @static
  7082. * @memberOf _
  7083. * @category Function
  7084. * @param {Function} predicate The predicate to negate.
  7085. * @returns {Function} Returns the new function.
  7086. * @example
  7087. *
  7088. * function isEven(n) {
  7089. * return n % 2 == 0;
  7090. * }
  7091. *
  7092. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  7093. * // => [1, 3, 5]
  7094. */
  7095. function negate(predicate) {
  7096. if (typeof predicate != 'function') {
  7097. throw new TypeError(FUNC_ERROR_TEXT);
  7098. }
  7099. return function() {
  7100. return !predicate.apply(this, arguments);
  7101. };
  7102. }
  7103. /**
  7104. * Creates a function that is restricted to invoking `func` once. Repeat calls
  7105. * to the function return the value of the first call. The `func` is invoked
  7106. * with the `this` binding of the created function.
  7107. *
  7108. * @static
  7109. * @memberOf _
  7110. * @category Function
  7111. * @param {Function} func The function to restrict.
  7112. * @returns {Function} Returns the new restricted function.
  7113. * @example
  7114. *
  7115. * var initialize = _.once(createApplication);
  7116. * initialize();
  7117. * initialize();
  7118. * // `initialize` invokes `createApplication` once
  7119. */
  7120. function once(func) {
  7121. return before(func, 2);
  7122. }
  7123. /**
  7124. * Creates a function that invokes `func` with `partial` arguments prepended
  7125. * to those provided to the new function. This method is like `_.bind` except
  7126. * it does **not** alter the `this` binding.
  7127. *
  7128. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  7129. * builds, may be used as a placeholder for partially applied arguments.
  7130. *
  7131. * **Note:** This method does not set the `length` property of partially
  7132. * applied functions.
  7133. *
  7134. * @static
  7135. * @memberOf _
  7136. * @category Function
  7137. * @param {Function} func The function to partially apply arguments to.
  7138. * @param {...*} [args] The arguments to be partially applied.
  7139. * @returns {Function} Returns the new partially applied function.
  7140. * @example
  7141. *
  7142. * var greet = function(greeting, name) {
  7143. * return greeting + ' ' + name;
  7144. * };
  7145. *
  7146. * var sayHelloTo = _.partial(greet, 'hello');
  7147. * sayHelloTo('fred');
  7148. * // => 'hello fred'
  7149. *
  7150. * // using placeholders
  7151. * var greetFred = _.partial(greet, _, 'fred');
  7152. * greetFred('hi');
  7153. * // => 'hi fred'
  7154. */
  7155. function partial(func) {
  7156. var partials = baseSlice(arguments, 1),
  7157. holders = replaceHolders(partials, partial.placeholder);
  7158. return createWrapper(func, PARTIAL_FLAG, null, partials, holders);
  7159. }
  7160. /**
  7161. * This method is like `_.partial` except that partially applied arguments
  7162. * are appended to those provided to the new function.
  7163. *
  7164. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  7165. * builds, may be used as a placeholder for partially applied arguments.
  7166. *
  7167. * **Note:** This method does not set the `length` property of partially
  7168. * applied functions.
  7169. *
  7170. * @static
  7171. * @memberOf _
  7172. * @category Function
  7173. * @param {Function} func The function to partially apply arguments to.
  7174. * @param {...*} [args] The arguments to be partially applied.
  7175. * @returns {Function} Returns the new partially applied function.
  7176. * @example
  7177. *
  7178. * var greet = function(greeting, name) {
  7179. * return greeting + ' ' + name;
  7180. * };
  7181. *
  7182. * var greetFred = _.partialRight(greet, 'fred');
  7183. * greetFred('hi');
  7184. * // => 'hi fred'
  7185. *
  7186. * // using placeholders
  7187. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  7188. * sayHelloTo('fred');
  7189. * // => 'hello fred'
  7190. */
  7191. function partialRight(func) {
  7192. var partials = baseSlice(arguments, 1),
  7193. holders = replaceHolders(partials, partialRight.placeholder);
  7194. return createWrapper(func, PARTIAL_RIGHT_FLAG, null, partials, holders);
  7195. }
  7196. /**
  7197. * Creates a function that invokes `func` with arguments arranged according
  7198. * to the specified indexes where the argument value at the first index is
  7199. * provided as the first argument, the argument value at the second index is
  7200. * provided as the second argument, and so on.
  7201. *
  7202. * @static
  7203. * @memberOf _
  7204. * @category Function
  7205. * @param {Function} func The function to rearrange arguments for.
  7206. * @param {...(number|number[])} indexes The arranged argument indexes,
  7207. * specified as individual indexes or arrays of indexes.
  7208. * @returns {Function} Returns the new function.
  7209. * @example
  7210. *
  7211. * var rearged = _.rearg(function(a, b, c) {
  7212. * return [a, b, c];
  7213. * }, 2, 0, 1);
  7214. *
  7215. * rearged('b', 'c', 'a')
  7216. * // => ['a', 'b', 'c']
  7217. *
  7218. * var map = _.rearg(_.map, [1, 0]);
  7219. * map(function(n) {
  7220. * return n * 3;
  7221. * }, [1, 2, 3]);
  7222. * // => [3, 6, 9]
  7223. */
  7224. function rearg(func) {
  7225. var indexes = baseFlatten(arguments, false, false, 1);
  7226. return createWrapper(func, REARG_FLAG, null, null, null, indexes);
  7227. }
  7228. /**
  7229. * Creates a function that invokes `func` with the `this` binding of the
  7230. * created function and the array of arguments provided to the created
  7231. * function much like [Function#apply](http://es5.github.io/#x15.3.4.3).
  7232. *
  7233. * @static
  7234. * @memberOf _
  7235. * @category Function
  7236. * @param {Function} func The function to spread arguments over.
  7237. * @returns {*} Returns the new function.
  7238. * @example
  7239. *
  7240. * var spread = _.spread(function(who, what) {
  7241. * return who + ' says ' + what;
  7242. * });
  7243. *
  7244. * spread(['Fred', 'hello']);
  7245. * // => 'Fred says hello'
  7246. *
  7247. * // with a Promise
  7248. * var numbers = Promise.all([
  7249. * Promise.resolve(40),
  7250. * Promise.resolve(36)
  7251. * ]);
  7252. *
  7253. * numbers.then(_.spread(function(x, y) {
  7254. * return x + y;
  7255. * }));
  7256. * // => a Promise of 76
  7257. */
  7258. function spread(func) {
  7259. if (typeof func != 'function') {
  7260. throw new TypeError(FUNC_ERROR_TEXT);
  7261. }
  7262. return function(array) {
  7263. return func.apply(this, array);
  7264. };
  7265. }
  7266. /**
  7267. * Creates a function that only invokes `func` at most once per every `wait`
  7268. * milliseconds. The created function comes with a `cancel` method to cancel
  7269. * delayed invocations. Provide an options object to indicate that `func`
  7270. * should be invoked on the leading and/or trailing edge of the `wait` timeout.
  7271. * Subsequent calls to the throttled function return the result of the last
  7272. * `func` call.
  7273. *
  7274. * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
  7275. * on the trailing edge of the timeout only if the the throttled function is
  7276. * invoked more than once during the `wait` timeout.
  7277. *
  7278. * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
  7279. * for details over the differences between `_.throttle` and `_.debounce`.
  7280. *
  7281. * @static
  7282. * @memberOf _
  7283. * @category Function
  7284. * @param {Function} func The function to throttle.
  7285. * @param {number} wait The number of milliseconds to throttle invocations to.
  7286. * @param {Object} [options] The options object.
  7287. * @param {boolean} [options.leading=true] Specify invoking on the leading
  7288. * edge of the timeout.
  7289. * @param {boolean} [options.trailing=true] Specify invoking on the trailing
  7290. * edge of the timeout.
  7291. * @returns {Function} Returns the new throttled function.
  7292. * @example
  7293. *
  7294. * // avoid excessively updating the position while scrolling
  7295. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  7296. *
  7297. * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
  7298. * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
  7299. * 'trailing': false
  7300. * }));
  7301. *
  7302. * // cancel a trailing throttled call
  7303. * jQuery(window).on('popstate', throttled.cancel);
  7304. */
  7305. function throttle(func, wait, options) {
  7306. var leading = true,
  7307. trailing = true;
  7308. if (typeof func != 'function') {
  7309. throw new TypeError(FUNC_ERROR_TEXT);
  7310. }
  7311. if (options === false) {
  7312. leading = false;
  7313. } else if (isObject(options)) {
  7314. leading = 'leading' in options ? !!options.leading : leading;
  7315. trailing = 'trailing' in options ? !!options.trailing : trailing;
  7316. }
  7317. debounceOptions.leading = leading;
  7318. debounceOptions.maxWait = +wait;
  7319. debounceOptions.trailing = trailing;
  7320. return debounce(func, wait, debounceOptions);
  7321. }
  7322. /**
  7323. * Creates a function that provides `value` to the wrapper function as its
  7324. * first argument. Any additional arguments provided to the function are
  7325. * appended to those provided to the wrapper function. The wrapper is invoked
  7326. * with the `this` binding of the created function.
  7327. *
  7328. * @static
  7329. * @memberOf _
  7330. * @category Function
  7331. * @param {*} value The value to wrap.
  7332. * @param {Function} wrapper The wrapper function.
  7333. * @returns {Function} Returns the new function.
  7334. * @example
  7335. *
  7336. * var p = _.wrap(_.escape, function(func, text) {
  7337. * return '<p>' + func(text) + '</p>';
  7338. * });
  7339. *
  7340. * p('fred, barney, & pebbles');
  7341. * // => '<p>fred, barney, &amp; pebbles</p>'
  7342. */
  7343. function wrap(value, wrapper) {
  7344. wrapper = wrapper == null ? identity : wrapper;
  7345. return createWrapper(wrapper, PARTIAL_FLAG, null, [value], []);
  7346. }
  7347. /*------------------------------------------------------------------------*/
  7348. /**
  7349. * Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,
  7350. * otherwise they are assigned by reference. If `customizer` is provided it is
  7351. * invoked to produce the cloned values. If `customizer` returns `undefined`
  7352. * cloning is handled by the method instead. The `customizer` is bound to
  7353. * `thisArg` and invoked with two argument; (value [, index|key, object]).
  7354. *
  7355. * **Note:** This method is loosely based on the structured clone algorithm.
  7356. * The enumerable properties of `arguments` objects and objects created by
  7357. * constructors other than `Object` are cloned to plain `Object` objects. An
  7358. * empty object is returned for uncloneable values such as functions, DOM nodes,
  7359. * Maps, Sets, and WeakMaps. See the [HTML5 specification](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm)
  7360. * for more details.
  7361. *
  7362. * @static
  7363. * @memberOf _
  7364. * @category Lang
  7365. * @param {*} value The value to clone.
  7366. * @param {boolean} [isDeep] Specify a deep clone.
  7367. * @param {Function} [customizer] The function to customize cloning values.
  7368. * @param {*} [thisArg] The `this` binding of `customizer`.
  7369. * @returns {*} Returns the cloned value.
  7370. * @example
  7371. *
  7372. * var users = [
  7373. * { 'user': 'barney' },
  7374. * { 'user': 'fred' }
  7375. * ];
  7376. *
  7377. * var shallow = _.clone(users);
  7378. * shallow[0] === users[0];
  7379. * // => true
  7380. *
  7381. * var deep = _.clone(users, true);
  7382. * deep[0] === users[0];
  7383. * // => false
  7384. *
  7385. * // using a customizer callback
  7386. * var el = _.clone(document.body, function(value) {
  7387. * if (_.isElement(value)) {
  7388. * return value.cloneNode(false);
  7389. * }
  7390. * });
  7391. *
  7392. * el === document.body
  7393. * // => false
  7394. * el.nodeName
  7395. * // => BODY
  7396. * el.childNodes.length;
  7397. * // => 0
  7398. */
  7399. function clone(value, isDeep, customizer, thisArg) {
  7400. if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
  7401. isDeep = false;
  7402. }
  7403. else if (typeof isDeep == 'function') {
  7404. thisArg = customizer;
  7405. customizer = isDeep;
  7406. isDeep = false;
  7407. }
  7408. customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
  7409. return baseClone(value, isDeep, customizer);
  7410. }
  7411. /**
  7412. * Creates a deep clone of `value`. If `customizer` is provided it is invoked
  7413. * to produce the cloned values. If `customizer` returns `undefined` cloning
  7414. * is handled by the method instead. The `customizer` is bound to `thisArg`
  7415. * and invoked with two argument; (value [, index|key, object]).
  7416. *
  7417. * **Note:** This method is loosely based on the structured clone algorithm.
  7418. * The enumerable properties of `arguments` objects and objects created by
  7419. * constructors other than `Object` are cloned to plain `Object` objects. An
  7420. * empty object is returned for uncloneable values such as functions, DOM nodes,
  7421. * Maps, Sets, and WeakMaps. See the [HTML5 specification](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm)
  7422. * for more details.
  7423. *
  7424. * @static
  7425. * @memberOf _
  7426. * @category Lang
  7427. * @param {*} value The value to deep clone.
  7428. * @param {Function} [customizer] The function to customize cloning values.
  7429. * @param {*} [thisArg] The `this` binding of `customizer`.
  7430. * @returns {*} Returns the deep cloned value.
  7431. * @example
  7432. *
  7433. * var users = [
  7434. * { 'user': 'barney' },
  7435. * { 'user': 'fred' }
  7436. * ];
  7437. *
  7438. * var deep = _.cloneDeep(users);
  7439. * deep[0] === users[0];
  7440. * // => false
  7441. *
  7442. * // using a customizer callback
  7443. * var el = _.cloneDeep(document.body, function(value) {
  7444. * if (_.isElement(value)) {
  7445. * return value.cloneNode(true);
  7446. * }
  7447. * });
  7448. *
  7449. * el === document.body
  7450. * // => false
  7451. * el.nodeName
  7452. * // => BODY
  7453. * el.childNodes.length;
  7454. * // => 20
  7455. */
  7456. function cloneDeep(value, customizer, thisArg) {
  7457. customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
  7458. return baseClone(value, true, customizer);
  7459. }
  7460. /**
  7461. * Checks if `value` is classified as an `arguments` object.
  7462. *
  7463. * @static
  7464. * @memberOf _
  7465. * @category Lang
  7466. * @param {*} value The value to check.
  7467. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  7468. * @example
  7469. *
  7470. * _.isArguments(function() { return arguments; }());
  7471. * // => true
  7472. *
  7473. * _.isArguments([1, 2, 3]);
  7474. * // => false
  7475. */
  7476. function isArguments(value) {
  7477. var length = isObjectLike(value) ? value.length : undefined;
  7478. return (isLength(length) && objToString.call(value) == argsTag) || false;
  7479. }
  7480. /**
  7481. * Checks if `value` is classified as an `Array` object.
  7482. *
  7483. * @static
  7484. * @memberOf _
  7485. * @category Lang
  7486. * @param {*} value The value to check.
  7487. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  7488. * @example
  7489. *
  7490. * _.isArray([1, 2, 3]);
  7491. * // => true
  7492. *
  7493. * _.isArray(function() { return arguments; }());
  7494. * // => false
  7495. */
  7496. var isArray = nativeIsArray || function(value) {
  7497. return (isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag) || false;
  7498. };
  7499. /**
  7500. * Checks if `value` is classified as a boolean primitive or object.
  7501. *
  7502. * @static
  7503. * @memberOf _
  7504. * @category Lang
  7505. * @param {*} value The value to check.
  7506. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  7507. * @example
  7508. *
  7509. * _.isBoolean(false);
  7510. * // => true
  7511. *
  7512. * _.isBoolean(null);
  7513. * // => false
  7514. */
  7515. function isBoolean(value) {
  7516. return (value === true || value === false || isObjectLike(value) && objToString.call(value) == boolTag) || false;
  7517. }
  7518. /**
  7519. * Checks if `value` is classified as a `Date` object.
  7520. *
  7521. * @static
  7522. * @memberOf _
  7523. * @category Lang
  7524. * @param {*} value The value to check.
  7525. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  7526. * @example
  7527. *
  7528. * _.isDate(new Date);
  7529. * // => true
  7530. *
  7531. * _.isDate('Mon April 23 2012');
  7532. * // => false
  7533. */
  7534. function isDate(value) {
  7535. return (isObjectLike(value) && objToString.call(value) == dateTag) || false;
  7536. }
  7537. /**
  7538. * Checks if `value` is a DOM element.
  7539. *
  7540. * @static
  7541. * @memberOf _
  7542. * @category Lang
  7543. * @param {*} value The value to check.
  7544. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  7545. * @example
  7546. *
  7547. * _.isElement(document.body);
  7548. * // => true
  7549. *
  7550. * _.isElement('<body>');
  7551. * // => false
  7552. */
  7553. function isElement(value) {
  7554. return (value && value.nodeType === 1 && isObjectLike(value) &&
  7555. objToString.call(value).indexOf('Element') > -1) || false;
  7556. }
  7557. // Fallback for environments without DOM support.
  7558. if (!support.dom) {
  7559. isElement = function(value) {
  7560. return (value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value)) || false;
  7561. };
  7562. }
  7563. /**
  7564. * Checks if a value is empty. A value is considered empty unless it is an
  7565. * `arguments` object, array, string, or jQuery-like collection with a length
  7566. * greater than `0` or an object with own enumerable properties.
  7567. *
  7568. * @static
  7569. * @memberOf _
  7570. * @category Lang
  7571. * @param {Array|Object|string} value The value to inspect.
  7572. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  7573. * @example
  7574. *
  7575. * _.isEmpty(null);
  7576. * // => true
  7577. *
  7578. * _.isEmpty(true);
  7579. * // => true
  7580. *
  7581. * _.isEmpty(1);
  7582. * // => true
  7583. *
  7584. * _.isEmpty([1, 2, 3]);
  7585. * // => false
  7586. *
  7587. * _.isEmpty({ 'a': 1 });
  7588. * // => false
  7589. */
  7590. function isEmpty(value) {
  7591. if (value == null) {
  7592. return true;
  7593. }
  7594. var length = value.length;
  7595. if (isLength(length) && (isArray(value) || isString(value) || isArguments(value) ||
  7596. (isObjectLike(value) && isFunction(value.splice)))) {
  7597. return !length;
  7598. }
  7599. return !keys(value).length;
  7600. }
  7601. /**
  7602. * Performs a deep comparison between two values to determine if they are
  7603. * equivalent. If `customizer` is provided it is invoked to compare values.
  7604. * If `customizer` returns `undefined` comparisons are handled by the method
  7605. * instead. The `customizer` is bound to `thisArg` and invoked with three
  7606. * arguments; (value, other [, index|key]).
  7607. *
  7608. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  7609. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  7610. * their own, not inherited, enumerable properties. Functions and DOM nodes
  7611. * are **not** supported. Provide a customizer function to extend support
  7612. * for comparing other values.
  7613. *
  7614. * @static
  7615. * @memberOf _
  7616. * @category Lang
  7617. * @param {*} value The value to compare.
  7618. * @param {*} other The other value to compare.
  7619. * @param {Function} [customizer] The function to customize comparing values.
  7620. * @param {*} [thisArg] The `this` binding of `customizer`.
  7621. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  7622. * @example
  7623. *
  7624. * var object = { 'user': 'fred' };
  7625. * var other = { 'user': 'fred' };
  7626. *
  7627. * object == other;
  7628. * // => false
  7629. *
  7630. * _.isEqual(object, other);
  7631. * // => true
  7632. *
  7633. * // using a customizer callback
  7634. * var array = ['hello', 'goodbye'];
  7635. * var other = ['hi', 'goodbye'];
  7636. *
  7637. * _.isEqual(array, other, function(value, other) {
  7638. * if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
  7639. * return true;
  7640. * }
  7641. * });
  7642. * // => true
  7643. */
  7644. function isEqual(value, other, customizer, thisArg) {
  7645. customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
  7646. if (!customizer && isStrictComparable(value) && isStrictComparable(other)) {
  7647. return value === other;
  7648. }
  7649. var result = customizer ? customizer(value, other) : undefined;
  7650. return typeof result == 'undefined' ? baseIsEqual(value, other, customizer) : !!result;
  7651. }
  7652. /**
  7653. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  7654. * `SyntaxError`, `TypeError`, or `URIError` object.
  7655. *
  7656. * @static
  7657. * @memberOf _
  7658. * @category Lang
  7659. * @param {*} value The value to check.
  7660. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  7661. * @example
  7662. *
  7663. * _.isError(new Error);
  7664. * // => true
  7665. *
  7666. * _.isError(Error);
  7667. * // => false
  7668. */
  7669. function isError(value) {
  7670. return (isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag) || false;
  7671. }
  7672. /**
  7673. * Checks if `value` is a finite primitive number.
  7674. *
  7675. * **Note:** This method is based on ES `Number.isFinite`. See the
  7676. * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isfinite)
  7677. * for more details.
  7678. *
  7679. * @static
  7680. * @memberOf _
  7681. * @category Lang
  7682. * @param {*} value The value to check.
  7683. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  7684. * @example
  7685. *
  7686. * _.isFinite(10);
  7687. * // => true
  7688. *
  7689. * _.isFinite('10');
  7690. * // => false
  7691. *
  7692. * _.isFinite(true);
  7693. * // => false
  7694. *
  7695. * _.isFinite(Object(10));
  7696. * // => false
  7697. *
  7698. * _.isFinite(Infinity);
  7699. * // => false
  7700. */
  7701. var isFinite = nativeNumIsFinite || function(value) {
  7702. return typeof value == 'number' && nativeIsFinite(value);
  7703. };
  7704. /**
  7705. * Checks if `value` is classified as a `Function` object.
  7706. *
  7707. * @static
  7708. * @memberOf _
  7709. * @category Lang
  7710. * @param {*} value The value to check.
  7711. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  7712. * @example
  7713. *
  7714. * _.isFunction(_);
  7715. * // => true
  7716. *
  7717. * _.isFunction(/abc/);
  7718. * // => false
  7719. */
  7720. var isFunction = !(baseIsFunction(/x/) || (Uint8Array && !baseIsFunction(Uint8Array))) ? baseIsFunction : function(value) {
  7721. // The use of `Object#toString` avoids issues with the `typeof` operator
  7722. // in older versions of Chrome and Safari which return 'function' for regexes
  7723. // and Safari 8 equivalents which return 'object' for typed array constructors.
  7724. return objToString.call(value) == funcTag;
  7725. };
  7726. /**
  7727. * Checks if `value` is the language type of `Object`.
  7728. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  7729. *
  7730. * **Note:** See the [ES5 spec](https://es5.github.io/#x8) for more details.
  7731. *
  7732. * @static
  7733. * @memberOf _
  7734. * @category Lang
  7735. * @param {*} value The value to check.
  7736. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  7737. * @example
  7738. *
  7739. * _.isObject({});
  7740. * // => true
  7741. *
  7742. * _.isObject([1, 2, 3]);
  7743. * // => true
  7744. *
  7745. * _.isObject(1);
  7746. * // => false
  7747. */
  7748. function isObject(value) {
  7749. // Avoid a V8 JIT bug in Chrome 19-20.
  7750. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  7751. var type = typeof value;
  7752. return type == 'function' || (value && type == 'object') || false;
  7753. }
  7754. /**
  7755. * Performs a deep comparison between `object` and `source` to determine if
  7756. * `object` contains equivalent property values. If `customizer` is provided
  7757. * it is invoked to compare values. If `customizer` returns `undefined`
  7758. * comparisons are handled by the method instead. The `customizer` is bound
  7759. * to `thisArg` and invoked with three arguments; (value, other, index|key).
  7760. *
  7761. * **Note:** This method supports comparing properties of arrays, booleans,
  7762. * `Date` objects, numbers, `Object` objects, regexes, and strings. Functions
  7763. * and DOM nodes are **not** supported. Provide a customizer function to extend
  7764. * support for comparing other values.
  7765. *
  7766. * @static
  7767. * @memberOf _
  7768. * @category Lang
  7769. * @param {Object} object The object to inspect.
  7770. * @param {Object} source The object of property values to match.
  7771. * @param {Function} [customizer] The function to customize comparing values.
  7772. * @param {*} [thisArg] The `this` binding of `customizer`.
  7773. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  7774. * @example
  7775. *
  7776. * var object = { 'user': 'fred', 'age': 40 };
  7777. *
  7778. * _.isMatch(object, { 'age': 40 });
  7779. * // => true
  7780. *
  7781. * _.isMatch(object, { 'age': 36 });
  7782. * // => false
  7783. *
  7784. * // using a customizer callback
  7785. * var object = { 'greeting': 'hello' };
  7786. * var source = { 'greeting': 'hi' };
  7787. *
  7788. * _.isMatch(object, source, function(value, other) {
  7789. * return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
  7790. * });
  7791. * // => true
  7792. */
  7793. function isMatch(object, source, customizer, thisArg) {
  7794. var props = keys(source),
  7795. length = props.length;
  7796. customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
  7797. if (!customizer && length == 1) {
  7798. var key = props[0],
  7799. value = source[key];
  7800. if (isStrictComparable(value)) {
  7801. return object != null && value === object[key] && hasOwnProperty.call(object, key);
  7802. }
  7803. }
  7804. var values = Array(length),
  7805. strictCompareFlags = Array(length);
  7806. while (length--) {
  7807. value = values[length] = source[props[length]];
  7808. strictCompareFlags[length] = isStrictComparable(value);
  7809. }
  7810. return baseIsMatch(object, props, values, strictCompareFlags, customizer);
  7811. }
  7812. /**
  7813. * Checks if `value` is `NaN`.
  7814. *
  7815. * **Note:** This method is not the same as native `isNaN` which returns `true`
  7816. * for `undefined` and other non-numeric values. See the [ES5 spec](https://es5.github.io/#x15.1.2.4)
  7817. * for more details.
  7818. *
  7819. * @static
  7820. * @memberOf _
  7821. * @category Lang
  7822. * @param {*} value The value to check.
  7823. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  7824. * @example
  7825. *
  7826. * _.isNaN(NaN);
  7827. * // => true
  7828. *
  7829. * _.isNaN(new Number(NaN));
  7830. * // => true
  7831. *
  7832. * isNaN(undefined);
  7833. * // => true
  7834. *
  7835. * _.isNaN(undefined);
  7836. * // => false
  7837. */
  7838. function isNaN(value) {
  7839. // An `NaN` primitive is the only value that is not equal to itself.
  7840. // Perform the `toStringTag` check first to avoid errors with some host objects in IE.
  7841. return isNumber(value) && value != +value;
  7842. }
  7843. /**
  7844. * Checks if `value` is a native function.
  7845. *
  7846. * @static
  7847. * @memberOf _
  7848. * @category Lang
  7849. * @param {*} value The value to check.
  7850. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  7851. * @example
  7852. *
  7853. * _.isNative(Array.prototype.push);
  7854. * // => true
  7855. *
  7856. * _.isNative(_);
  7857. * // => false
  7858. */
  7859. function isNative(value) {
  7860. if (value == null) {
  7861. return false;
  7862. }
  7863. if (objToString.call(value) == funcTag) {
  7864. return reNative.test(fnToString.call(value));
  7865. }
  7866. return (isObjectLike(value) && reHostCtor.test(value)) || false;
  7867. }
  7868. /**
  7869. * Checks if `value` is `null`.
  7870. *
  7871. * @static
  7872. * @memberOf _
  7873. * @category Lang
  7874. * @param {*} value The value to check.
  7875. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  7876. * @example
  7877. *
  7878. * _.isNull(null);
  7879. * // => true
  7880. *
  7881. * _.isNull(void 0);
  7882. * // => false
  7883. */
  7884. function isNull(value) {
  7885. return value === null;
  7886. }
  7887. /**
  7888. * Checks if `value` is classified as a `Number` primitive or object.
  7889. *
  7890. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
  7891. * as numbers, use the `_.isFinite` method.
  7892. *
  7893. * @static
  7894. * @memberOf _
  7895. * @category Lang
  7896. * @param {*} value The value to check.
  7897. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  7898. * @example
  7899. *
  7900. * _.isNumber(8.4);
  7901. * // => true
  7902. *
  7903. * _.isNumber(NaN);
  7904. * // => true
  7905. *
  7906. * _.isNumber('8.4');
  7907. * // => false
  7908. */
  7909. function isNumber(value) {
  7910. return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag) || false;
  7911. }
  7912. /**
  7913. * Checks if `value` is a plain object, that is, an object created by the
  7914. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  7915. *
  7916. * **Note:** This method assumes objects created by the `Object` constructor
  7917. * have no inherited enumerable properties.
  7918. *
  7919. * @static
  7920. * @memberOf _
  7921. * @category Lang
  7922. * @param {*} value The value to check.
  7923. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  7924. * @example
  7925. *
  7926. * function Foo() {
  7927. * this.a = 1;
  7928. * }
  7929. *
  7930. * _.isPlainObject(new Foo);
  7931. * // => false
  7932. *
  7933. * _.isPlainObject([1, 2, 3]);
  7934. * // => false
  7935. *
  7936. * _.isPlainObject({ 'x': 0, 'y': 0 });
  7937. * // => true
  7938. *
  7939. * _.isPlainObject(Object.create(null));
  7940. * // => true
  7941. */
  7942. var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) {
  7943. if (!(value && objToString.call(value) == objectTag)) {
  7944. return false;
  7945. }
  7946. var valueOf = value.valueOf,
  7947. objProto = isNative(valueOf) && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
  7948. return objProto
  7949. ? (value == objProto || getPrototypeOf(value) == objProto)
  7950. : shimIsPlainObject(value);
  7951. };
  7952. /**
  7953. * Checks if `value` is classified as a `RegExp` object.
  7954. *
  7955. * @static
  7956. * @memberOf _
  7957. * @category Lang
  7958. * @param {*} value The value to check.
  7959. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  7960. * @example
  7961. *
  7962. * _.isRegExp(/abc/);
  7963. * // => true
  7964. *
  7965. * _.isRegExp('/abc/');
  7966. * // => false
  7967. */
  7968. function isRegExp(value) {
  7969. return (isObjectLike(value) && objToString.call(value) == regexpTag) || false;
  7970. }
  7971. /**
  7972. * Checks if `value` is classified as a `String` primitive or object.
  7973. *
  7974. * @static
  7975. * @memberOf _
  7976. * @category Lang
  7977. * @param {*} value The value to check.
  7978. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  7979. * @example
  7980. *
  7981. * _.isString('abc');
  7982. * // => true
  7983. *
  7984. * _.isString(1);
  7985. * // => false
  7986. */
  7987. function isString(value) {
  7988. return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag) || false;
  7989. }
  7990. /**
  7991. * Checks if `value` is classified as a typed array.
  7992. *
  7993. * @static
  7994. * @memberOf _
  7995. * @category Lang
  7996. * @param {*} value The value to check.
  7997. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  7998. * @example
  7999. *
  8000. * _.isTypedArray(new Uint8Array);
  8001. * // => true
  8002. *
  8003. * _.isTypedArray([]);
  8004. * // => false
  8005. */
  8006. function isTypedArray(value) {
  8007. return (isObjectLike(value) && isLength(value.length) && typedArrayTags[objToString.call(value)]) || false;
  8008. }
  8009. /**
  8010. * Checks if `value` is `undefined`.
  8011. *
  8012. * @static
  8013. * @memberOf _
  8014. * @category Lang
  8015. * @param {*} value The value to check.
  8016. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  8017. * @example
  8018. *
  8019. * _.isUndefined(void 0);
  8020. * // => true
  8021. *
  8022. * _.isUndefined(null);
  8023. * // => false
  8024. */
  8025. function isUndefined(value) {
  8026. return typeof value == 'undefined';
  8027. }
  8028. /**
  8029. * Converts `value` to an array.
  8030. *
  8031. * @static
  8032. * @memberOf _
  8033. * @category Lang
  8034. * @param {*} value The value to convert.
  8035. * @returns {Array} Returns the converted array.
  8036. * @example
  8037. *
  8038. * (function() {
  8039. * return _.toArray(arguments).slice(1);
  8040. * }(1, 2, 3));
  8041. * // => [2, 3]
  8042. */
  8043. function toArray(value) {
  8044. var length = value ? value.length : 0;
  8045. if (!isLength(length)) {
  8046. return values(value);
  8047. }
  8048. if (!length) {
  8049. return [];
  8050. }
  8051. return arrayCopy(value);
  8052. }
  8053. /**
  8054. * Converts `value` to a plain object flattening inherited enumerable
  8055. * properties of `value` to own properties of the plain object.
  8056. *
  8057. * @static
  8058. * @memberOf _
  8059. * @category Lang
  8060. * @param {*} value The value to convert.
  8061. * @returns {Object} Returns the converted plain object.
  8062. * @example
  8063. *
  8064. * function Foo() {
  8065. * this.b = 2;
  8066. * }
  8067. *
  8068. * Foo.prototype.c = 3;
  8069. *
  8070. * _.assign({ 'a': 1 }, new Foo);
  8071. * // => { 'a': 1, 'b': 2 }
  8072. *
  8073. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  8074. * // => { 'a': 1, 'b': 2, 'c': 3 }
  8075. */
  8076. function toPlainObject(value) {
  8077. return baseCopy(value, keysIn(value));
  8078. }
  8079. /*------------------------------------------------------------------------*/
  8080. /**
  8081. * Assigns own enumerable properties of source object(s) to the destination
  8082. * object. Subsequent sources overwrite property assignments of previous sources.
  8083. * If `customizer` is provided it is invoked to produce the assigned values.
  8084. * The `customizer` is bound to `thisArg` and invoked with five arguments;
  8085. * (objectValue, sourceValue, key, object, source).
  8086. *
  8087. * @static
  8088. * @memberOf _
  8089. * @alias extend
  8090. * @category Object
  8091. * @param {Object} object The destination object.
  8092. * @param {...Object} [sources] The source objects.
  8093. * @param {Function} [customizer] The function to customize assigning values.
  8094. * @param {*} [thisArg] The `this` binding of `customizer`.
  8095. * @returns {Object} Returns `object`.
  8096. * @example
  8097. *
  8098. * _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
  8099. * // => { 'user': 'fred', 'age': 40 }
  8100. *
  8101. * // using a customizer callback
  8102. * var defaults = _.partialRight(_.assign, function(value, other) {
  8103. * return typeof value == 'undefined' ? other : value;
  8104. * });
  8105. *
  8106. * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
  8107. * // => { 'user': 'barney', 'age': 36 }
  8108. */
  8109. var assign = createAssigner(baseAssign);
  8110. /**
  8111. * Creates an object that inherits from the given `prototype` object. If a
  8112. * `properties` object is provided its own enumerable properties are assigned
  8113. * to the created object.
  8114. *
  8115. * @static
  8116. * @memberOf _
  8117. * @category Object
  8118. * @param {Object} prototype The object to inherit from.
  8119. * @param {Object} [properties] The properties to assign to the object.
  8120. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  8121. * @returns {Object} Returns the new object.
  8122. * @example
  8123. *
  8124. * function Shape() {
  8125. * this.x = 0;
  8126. * this.y = 0;
  8127. * }
  8128. *
  8129. * function Circle() {
  8130. * Shape.call(this);
  8131. * }
  8132. *
  8133. * Circle.prototype = _.create(Shape.prototype, {
  8134. * 'constructor': Circle
  8135. * });
  8136. *
  8137. * var circle = new Circle;
  8138. * circle instanceof Circle;
  8139. * // => true
  8140. *
  8141. * circle instanceof Shape;
  8142. * // => true
  8143. */
  8144. function create(prototype, properties, guard) {
  8145. var result = baseCreate(prototype);
  8146. if (guard && isIterateeCall(prototype, properties, guard)) {
  8147. properties = null;
  8148. }
  8149. return properties ? baseCopy(properties, result, keys(properties)) : result;
  8150. }
  8151. /**
  8152. * Assigns own enumerable properties of source object(s) to the destination
  8153. * object for all destination properties that resolve to `undefined`. Once a
  8154. * property is set, additional defaults of the same property are ignored.
  8155. *
  8156. * @static
  8157. * @memberOf _
  8158. * @category Object
  8159. * @param {Object} object The destination object.
  8160. * @param {...Object} [sources] The source objects.
  8161. * @returns {Object} Returns `object`.
  8162. * @example
  8163. *
  8164. * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
  8165. * // => { 'user': 'barney', 'age': 36 }
  8166. */
  8167. function defaults(object) {
  8168. if (object == null) {
  8169. return object;
  8170. }
  8171. var args = arrayCopy(arguments);
  8172. args.push(assignDefaults);
  8173. return assign.apply(undefined, args);
  8174. }
  8175. /**
  8176. * This method is like `_.findIndex` except that it returns the key of the
  8177. * first element `predicate` returns truthy for, instead of the element itself.
  8178. *
  8179. * If a property name is provided for `predicate` the created `_.property`
  8180. * style callback returns the property value of the given element.
  8181. *
  8182. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  8183. * style callback returns `true` for elements that have a matching property
  8184. * value, else `false`.
  8185. *
  8186. * If an object is provided for `predicate` the created `_.matches` style
  8187. * callback returns `true` for elements that have the properties of the given
  8188. * object, else `false`.
  8189. *
  8190. * @static
  8191. * @memberOf _
  8192. * @category Object
  8193. * @param {Object} object The object to search.
  8194. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  8195. * per iteration.
  8196. * @param {*} [thisArg] The `this` binding of `predicate`.
  8197. * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
  8198. * @example
  8199. *
  8200. * var users = {
  8201. * 'barney': { 'age': 36, 'active': true },
  8202. * 'fred': { 'age': 40, 'active': false },
  8203. * 'pebbles': { 'age': 1, 'active': true }
  8204. * };
  8205. *
  8206. * _.findKey(users, function(chr) {
  8207. * return chr.age < 40;
  8208. * });
  8209. * // => 'barney' (iteration order is not guaranteed)
  8210. *
  8211. * // using the `_.matches` callback shorthand
  8212. * _.findKey(users, { 'age': 1, 'active': true });
  8213. * // => 'pebbles'
  8214. *
  8215. * // using the `_.matchesProperty` callback shorthand
  8216. * _.findKey(users, 'active', false);
  8217. * // => 'fred'
  8218. *
  8219. * // using the `_.property` callback shorthand
  8220. * _.findKey(users, 'active');
  8221. * // => 'barney'
  8222. */
  8223. function findKey(object, predicate, thisArg) {
  8224. predicate = getCallback(predicate, thisArg, 3);
  8225. return baseFind(object, predicate, baseForOwn, true);
  8226. }
  8227. /**
  8228. * This method is like `_.findKey` except that it iterates over elements of
  8229. * a collection in the opposite order.
  8230. *
  8231. * If a property name is provided for `predicate` the created `_.property`
  8232. * style callback returns the property value of the given element.
  8233. *
  8234. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  8235. * style callback returns `true` for elements that have a matching property
  8236. * value, else `false`.
  8237. *
  8238. * If an object is provided for `predicate` the created `_.matches` style
  8239. * callback returns `true` for elements that have the properties of the given
  8240. * object, else `false`.
  8241. *
  8242. * @static
  8243. * @memberOf _
  8244. * @category Object
  8245. * @param {Object} object The object to search.
  8246. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  8247. * per iteration.
  8248. * @param {*} [thisArg] The `this` binding of `predicate`.
  8249. * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
  8250. * @example
  8251. *
  8252. * var users = {
  8253. * 'barney': { 'age': 36, 'active': true },
  8254. * 'fred': { 'age': 40, 'active': false },
  8255. * 'pebbles': { 'age': 1, 'active': true }
  8256. * };
  8257. *
  8258. * _.findLastKey(users, function(chr) {
  8259. * return chr.age < 40;
  8260. * });
  8261. * // => returns `pebbles` assuming `_.findKey` returns `barney`
  8262. *
  8263. * // using the `_.matches` callback shorthand
  8264. * _.findLastKey(users, { 'age': 36, 'active': true });
  8265. * // => 'barney'
  8266. *
  8267. * // using the `_.matchesProperty` callback shorthand
  8268. * _.findLastKey(users, 'active', false);
  8269. * // => 'fred'
  8270. *
  8271. * // using the `_.property` callback shorthand
  8272. * _.findLastKey(users, 'active');
  8273. * // => 'pebbles'
  8274. */
  8275. function findLastKey(object, predicate, thisArg) {
  8276. predicate = getCallback(predicate, thisArg, 3);
  8277. return baseFind(object, predicate, baseForOwnRight, true);
  8278. }
  8279. /**
  8280. * Iterates over own and inherited enumerable properties of an object invoking
  8281. * `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
  8282. * with three arguments; (value, key, object). Iterator functions may exit
  8283. * iteration early by explicitly returning `false`.
  8284. *
  8285. * @static
  8286. * @memberOf _
  8287. * @category Object
  8288. * @param {Object} object The object to iterate over.
  8289. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8290. * @param {*} [thisArg] The `this` binding of `iteratee`.
  8291. * @returns {Object} Returns `object`.
  8292. * @example
  8293. *
  8294. * function Foo() {
  8295. * this.a = 1;
  8296. * this.b = 2;
  8297. * }
  8298. *
  8299. * Foo.prototype.c = 3;
  8300. *
  8301. * _.forIn(new Foo, function(value, key) {
  8302. * console.log(key);
  8303. * });
  8304. * // => logs 'a', 'b', and 'c' (iteration order is not guaranteed)
  8305. */
  8306. function forIn(object, iteratee, thisArg) {
  8307. if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
  8308. iteratee = bindCallback(iteratee, thisArg, 3);
  8309. }
  8310. return baseFor(object, iteratee, keysIn);
  8311. }
  8312. /**
  8313. * This method is like `_.forIn` except that it iterates over properties of
  8314. * `object` in the opposite order.
  8315. *
  8316. * @static
  8317. * @memberOf _
  8318. * @category Object
  8319. * @param {Object} object The object to iterate over.
  8320. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8321. * @param {*} [thisArg] The `this` binding of `iteratee`.
  8322. * @returns {Object} Returns `object`.
  8323. * @example
  8324. *
  8325. * function Foo() {
  8326. * this.a = 1;
  8327. * this.b = 2;
  8328. * }
  8329. *
  8330. * Foo.prototype.c = 3;
  8331. *
  8332. * _.forInRight(new Foo, function(value, key) {
  8333. * console.log(key);
  8334. * });
  8335. * // => logs 'c', 'b', and 'a' assuming `_.forIn ` logs 'a', 'b', and 'c'
  8336. */
  8337. function forInRight(object, iteratee, thisArg) {
  8338. iteratee = bindCallback(iteratee, thisArg, 3);
  8339. return baseForRight(object, iteratee, keysIn);
  8340. }
  8341. /**
  8342. * Iterates over own enumerable properties of an object invoking `iteratee`
  8343. * for each property. The `iteratee` is bound to `thisArg` and invoked with
  8344. * three arguments; (value, key, object). Iterator functions may exit iteration
  8345. * early by explicitly returning `false`.
  8346. *
  8347. * @static
  8348. * @memberOf _
  8349. * @category Object
  8350. * @param {Object} object The object to iterate over.
  8351. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8352. * @param {*} [thisArg] The `this` binding of `iteratee`.
  8353. * @returns {Object} Returns `object`.
  8354. * @example
  8355. *
  8356. * function Foo() {
  8357. * this.a = 1;
  8358. * this.b = 2;
  8359. * }
  8360. *
  8361. * Foo.prototype.c = 3;
  8362. *
  8363. * _.forOwn(new Foo, function(value, key) {
  8364. * console.log(key);
  8365. * });
  8366. * // => logs 'a' and 'b' (iteration order is not guaranteed)
  8367. */
  8368. function forOwn(object, iteratee, thisArg) {
  8369. if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
  8370. iteratee = bindCallback(iteratee, thisArg, 3);
  8371. }
  8372. return baseForOwn(object, iteratee);
  8373. }
  8374. /**
  8375. * This method is like `_.forOwn` except that it iterates over properties of
  8376. * `object` in the opposite order.
  8377. *
  8378. * @static
  8379. * @memberOf _
  8380. * @category Object
  8381. * @param {Object} object The object to iterate over.
  8382. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8383. * @param {*} [thisArg] The `this` binding of `iteratee`.
  8384. * @returns {Object} Returns `object`.
  8385. * @example
  8386. *
  8387. * function Foo() {
  8388. * this.a = 1;
  8389. * this.b = 2;
  8390. * }
  8391. *
  8392. * Foo.prototype.c = 3;
  8393. *
  8394. * _.forOwnRight(new Foo, function(value, key) {
  8395. * console.log(key);
  8396. * });
  8397. * // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
  8398. */
  8399. function forOwnRight(object, iteratee, thisArg) {
  8400. iteratee = bindCallback(iteratee, thisArg, 3);
  8401. return baseForRight(object, iteratee, keys);
  8402. }
  8403. /**
  8404. * Creates an array of function property names from all enumerable properties,
  8405. * own and inherited, of `object`.
  8406. *
  8407. * @static
  8408. * @memberOf _
  8409. * @alias methods
  8410. * @category Object
  8411. * @param {Object} object The object to inspect.
  8412. * @returns {Array} Returns the new array of property names.
  8413. * @example
  8414. *
  8415. * _.functions(_);
  8416. * // => ['after', 'ary', 'assign', ...]
  8417. */
  8418. function functions(object) {
  8419. return baseFunctions(object, keysIn(object));
  8420. }
  8421. /**
  8422. * Checks if `key` exists as a direct property of `object` instead of an
  8423. * inherited property.
  8424. *
  8425. * @static
  8426. * @memberOf _
  8427. * @category Object
  8428. * @param {Object} object The object to inspect.
  8429. * @param {string} key The key to check.
  8430. * @returns {boolean} Returns `true` if `key` is a direct property, else `false`.
  8431. * @example
  8432. *
  8433. * var object = { 'a': 1, 'b': 2, 'c': 3 };
  8434. *
  8435. * _.has(object, 'b');
  8436. * // => true
  8437. */
  8438. function has(object, key) {
  8439. return object ? hasOwnProperty.call(object, key) : false;
  8440. }
  8441. /**
  8442. * Creates an object composed of the inverted keys and values of `object`.
  8443. * If `object` contains duplicate values, subsequent values overwrite property
  8444. * assignments of previous values unless `multiValue` is `true`.
  8445. *
  8446. * @static
  8447. * @memberOf _
  8448. * @category Object
  8449. * @param {Object} object The object to invert.
  8450. * @param {boolean} [multiValue] Allow multiple values per key.
  8451. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  8452. * @returns {Object} Returns the new inverted object.
  8453. * @example
  8454. *
  8455. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  8456. *
  8457. * _.invert(object);
  8458. * // => { '1': 'c', '2': 'b' }
  8459. *
  8460. * // with `multiValue`
  8461. * _.invert(object, true);
  8462. * // => { '1': ['a', 'c'], '2': ['b'] }
  8463. */
  8464. function invert(object, multiValue, guard) {
  8465. if (guard && isIterateeCall(object, multiValue, guard)) {
  8466. multiValue = null;
  8467. }
  8468. var index = -1,
  8469. props = keys(object),
  8470. length = props.length,
  8471. result = {};
  8472. while (++index < length) {
  8473. var key = props[index],
  8474. value = object[key];
  8475. if (multiValue) {
  8476. if (hasOwnProperty.call(result, value)) {
  8477. result[value].push(key);
  8478. } else {
  8479. result[value] = [key];
  8480. }
  8481. }
  8482. else {
  8483. result[value] = key;
  8484. }
  8485. }
  8486. return result;
  8487. }
  8488. /**
  8489. * Creates an array of the own enumerable property names of `object`.
  8490. *
  8491. * **Note:** Non-object values are coerced to objects. See the
  8492. * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.keys)
  8493. * for more details.
  8494. *
  8495. * @static
  8496. * @memberOf _
  8497. * @category Object
  8498. * @param {Object} object The object to inspect.
  8499. * @returns {Array} Returns the array of property names.
  8500. * @example
  8501. *
  8502. * function Foo() {
  8503. * this.a = 1;
  8504. * this.b = 2;
  8505. * }
  8506. *
  8507. * Foo.prototype.c = 3;
  8508. *
  8509. * _.keys(new Foo);
  8510. * // => ['a', 'b'] (iteration order is not guaranteed)
  8511. *
  8512. * _.keys('hi');
  8513. * // => ['0', '1']
  8514. */
  8515. var keys = !nativeKeys ? shimKeys : function(object) {
  8516. if (object) {
  8517. var Ctor = object.constructor,
  8518. length = object.length;
  8519. }
  8520. if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
  8521. (typeof object != 'function' && (length && isLength(length)))) {
  8522. return shimKeys(object);
  8523. }
  8524. return isObject(object) ? nativeKeys(object) : [];
  8525. };
  8526. /**
  8527. * Creates an array of the own and inherited enumerable property names of `object`.
  8528. *
  8529. * **Note:** Non-object values are coerced to objects.
  8530. *
  8531. * @static
  8532. * @memberOf _
  8533. * @category Object
  8534. * @param {Object} object The object to inspect.
  8535. * @returns {Array} Returns the array of property names.
  8536. * @example
  8537. *
  8538. * function Foo() {
  8539. * this.a = 1;
  8540. * this.b = 2;
  8541. * }
  8542. *
  8543. * Foo.prototype.c = 3;
  8544. *
  8545. * _.keysIn(new Foo);
  8546. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  8547. */
  8548. function keysIn(object) {
  8549. if (object == null) {
  8550. return [];
  8551. }
  8552. if (!isObject(object)) {
  8553. object = Object(object);
  8554. }
  8555. var length = object.length;
  8556. length = (length && isLength(length) &&
  8557. (isArray(object) || (support.nonEnumArgs && isArguments(object))) && length) || 0;
  8558. var Ctor = object.constructor,
  8559. index = -1,
  8560. isProto = typeof Ctor == 'function' && Ctor.prototype === object,
  8561. result = Array(length),
  8562. skipIndexes = length > 0;
  8563. while (++index < length) {
  8564. result[index] = (index + '');
  8565. }
  8566. for (var key in object) {
  8567. if (!(skipIndexes && isIndex(key, length)) &&
  8568. !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  8569. result.push(key);
  8570. }
  8571. }
  8572. return result;
  8573. }
  8574. /**
  8575. * Creates an object with the same keys as `object` and values generated by
  8576. * running each own enumerable property of `object` through `iteratee`. The
  8577. * iteratee function is bound to `thisArg` and invoked with three arguments;
  8578. * (value, key, object).
  8579. *
  8580. * If a property name is provided for `iteratee` the created `_.property`
  8581. * style callback returns the property value of the given element.
  8582. *
  8583. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  8584. * style callback returns `true` for elements that have a matching property
  8585. * value, else `false`.
  8586. *
  8587. * If an object is provided for `iteratee` the created `_.matches` style
  8588. * callback returns `true` for elements that have the properties of the given
  8589. * object, else `false`.
  8590. *
  8591. * @static
  8592. * @memberOf _
  8593. * @category Object
  8594. * @param {Object} object The object to iterate over.
  8595. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  8596. * per iteration.
  8597. * @param {*} [thisArg] The `this` binding of `iteratee`.
  8598. * @returns {Object} Returns the new mapped object.
  8599. * @example
  8600. *
  8601. * _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
  8602. * return n * 3;
  8603. * });
  8604. * // => { 'a': 3, 'b': 6 }
  8605. *
  8606. * var users = {
  8607. * 'fred': { 'user': 'fred', 'age': 40 },
  8608. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  8609. * };
  8610. *
  8611. * // using the `_.property` callback shorthand
  8612. * _.mapValues(users, 'age');
  8613. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  8614. */
  8615. function mapValues(object, iteratee, thisArg) {
  8616. var result = {};
  8617. iteratee = getCallback(iteratee, thisArg, 3);
  8618. baseForOwn(object, function(value, key, object) {
  8619. result[key] = iteratee(value, key, object);
  8620. });
  8621. return result;
  8622. }
  8623. /**
  8624. * Recursively merges own enumerable properties of the source object(s), that
  8625. * don't resolve to `undefined` into the destination object. Subsequent sources
  8626. * overwrite property assignments of previous sources. If `customizer` is
  8627. * provided it is invoked to produce the merged values of the destination and
  8628. * source properties. If `customizer` returns `undefined` merging is handled
  8629. * by the method instead. The `customizer` is bound to `thisArg` and invoked
  8630. * with five arguments; (objectValue, sourceValue, key, object, source).
  8631. *
  8632. * @static
  8633. * @memberOf _
  8634. * @category Object
  8635. * @param {Object} object The destination object.
  8636. * @param {...Object} [sources] The source objects.
  8637. * @param {Function} [customizer] The function to customize merging properties.
  8638. * @param {*} [thisArg] The `this` binding of `customizer`.
  8639. * @returns {Object} Returns `object`.
  8640. * @example
  8641. *
  8642. * var users = {
  8643. * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
  8644. * };
  8645. *
  8646. * var ages = {
  8647. * 'data': [{ 'age': 36 }, { 'age': 40 }]
  8648. * };
  8649. *
  8650. * _.merge(users, ages);
  8651. * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
  8652. *
  8653. * // using a customizer callback
  8654. * var object = {
  8655. * 'fruits': ['apple'],
  8656. * 'vegetables': ['beet']
  8657. * };
  8658. *
  8659. * var other = {
  8660. * 'fruits': ['banana'],
  8661. * 'vegetables': ['carrot']
  8662. * };
  8663. *
  8664. * _.merge(object, other, function(a, b) {
  8665. * if (_.isArray(a)) {
  8666. * return a.concat(b);
  8667. * }
  8668. * });
  8669. * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
  8670. */
  8671. var merge = createAssigner(baseMerge);
  8672. /**
  8673. * The opposite of `_.pick`; this method creates an object composed of the
  8674. * own and inherited enumerable properties of `object` that are not omitted.
  8675. * Property names may be specified as individual arguments or as arrays of
  8676. * property names. If `predicate` is provided it is invoked for each property
  8677. * of `object` omitting the properties `predicate` returns truthy for. The
  8678. * predicate is bound to `thisArg` and invoked with three arguments;
  8679. * (value, key, object).
  8680. *
  8681. * @static
  8682. * @memberOf _
  8683. * @category Object
  8684. * @param {Object} object The source object.
  8685. * @param {Function|...(string|string[])} [predicate] The function invoked per
  8686. * iteration or property names to omit, specified as individual property
  8687. * names or arrays of property names.
  8688. * @param {*} [thisArg] The `this` binding of `predicate`.
  8689. * @returns {Object} Returns the new object.
  8690. * @example
  8691. *
  8692. * var object = { 'user': 'fred', 'age': 40 };
  8693. *
  8694. * _.omit(object, 'age');
  8695. * // => { 'user': 'fred' }
  8696. *
  8697. * _.omit(object, _.isNumber);
  8698. * // => { 'user': 'fred' }
  8699. */
  8700. function omit(object, predicate, thisArg) {
  8701. if (object == null) {
  8702. return {};
  8703. }
  8704. if (typeof predicate != 'function') {
  8705. var props = arrayMap(baseFlatten(arguments, false, false, 1), String);
  8706. return pickByArray(object, baseDifference(keysIn(object), props));
  8707. }
  8708. predicate = bindCallback(predicate, thisArg, 3);
  8709. return pickByCallback(object, function(value, key, object) {
  8710. return !predicate(value, key, object);
  8711. });
  8712. }
  8713. /**
  8714. * Creates a two dimensional array of the key-value pairs for `object`,
  8715. * e.g. `[[key1, value1], [key2, value2]]`.
  8716. *
  8717. * @static
  8718. * @memberOf _
  8719. * @category Object
  8720. * @param {Object} object The object to inspect.
  8721. * @returns {Array} Returns the new array of key-value pairs.
  8722. * @example
  8723. *
  8724. * _.pairs({ 'barney': 36, 'fred': 40 });
  8725. * // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
  8726. */
  8727. function pairs(object) {
  8728. var index = -1,
  8729. props = keys(object),
  8730. length = props.length,
  8731. result = Array(length);
  8732. while (++index < length) {
  8733. var key = props[index];
  8734. result[index] = [key, object[key]];
  8735. }
  8736. return result;
  8737. }
  8738. /**
  8739. * Creates an object composed of the picked `object` properties. Property
  8740. * names may be specified as individual arguments or as arrays of property
  8741. * names. If `predicate` is provided it is invoked for each property of `object`
  8742. * picking the properties `predicate` returns truthy for. The predicate is
  8743. * bound to `thisArg` and invoked with three arguments; (value, key, object).
  8744. *
  8745. * @static
  8746. * @memberOf _
  8747. * @category Object
  8748. * @param {Object} object The source object.
  8749. * @param {Function|...(string|string[])} [predicate] The function invoked per
  8750. * iteration or property names to pick, specified as individual property
  8751. * names or arrays of property names.
  8752. * @param {*} [thisArg] The `this` binding of `predicate`.
  8753. * @returns {Object} Returns the new object.
  8754. * @example
  8755. *
  8756. * var object = { 'user': 'fred', 'age': 40 };
  8757. *
  8758. * _.pick(object, 'user');
  8759. * // => { 'user': 'fred' }
  8760. *
  8761. * _.pick(object, _.isString);
  8762. * // => { 'user': 'fred' }
  8763. */
  8764. function pick(object, predicate, thisArg) {
  8765. if (object == null) {
  8766. return {};
  8767. }
  8768. return typeof predicate == 'function'
  8769. ? pickByCallback(object, bindCallback(predicate, thisArg, 3))
  8770. : pickByArray(object, baseFlatten(arguments, false, false, 1));
  8771. }
  8772. /**
  8773. * Resolves the value of property `key` on `object`. If the value of `key` is
  8774. * a function it is invoked with the `this` binding of `object` and its result
  8775. * is returned, else the property value is returned. If the property value is
  8776. * `undefined` the `defaultValue` is used in its place.
  8777. *
  8778. * @static
  8779. * @memberOf _
  8780. * @category Object
  8781. * @param {Object} object The object to query.
  8782. * @param {string} key The key of the property to resolve.
  8783. * @param {*} [defaultValue] The value returned if the property value
  8784. * resolves to `undefined`.
  8785. * @returns {*} Returns the resolved value.
  8786. * @example
  8787. *
  8788. * var object = { 'user': 'fred', 'age': _.constant(40) };
  8789. *
  8790. * _.result(object, 'user');
  8791. * // => 'fred'
  8792. *
  8793. * _.result(object, 'age');
  8794. * // => 40
  8795. *
  8796. * _.result(object, 'status', 'busy');
  8797. * // => 'busy'
  8798. *
  8799. * _.result(object, 'status', _.constant('busy'));
  8800. * // => 'busy'
  8801. */
  8802. function result(object, key, defaultValue) {
  8803. var value = object == null ? undefined : object[key];
  8804. if (typeof value == 'undefined') {
  8805. value = defaultValue;
  8806. }
  8807. return isFunction(value) ? value.call(object) : value;
  8808. }
  8809. /**
  8810. * An alternative to `_.reduce`; this method transforms `object` to a new
  8811. * `accumulator` object which is the result of running each of its own enumerable
  8812. * properties through `iteratee`, with each invocation potentially mutating
  8813. * the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
  8814. * with four arguments; (accumulator, value, key, object). Iterator functions
  8815. * may exit iteration early by explicitly returning `false`.
  8816. *
  8817. * @static
  8818. * @memberOf _
  8819. * @category Object
  8820. * @param {Array|Object} object The object to iterate over.
  8821. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8822. * @param {*} [accumulator] The custom accumulator value.
  8823. * @param {*} [thisArg] The `this` binding of `iteratee`.
  8824. * @returns {*} Returns the accumulated value.
  8825. * @example
  8826. *
  8827. * _.transform([2, 3, 4], function(result, n) {
  8828. * result.push(n *= n);
  8829. * return n % 2 == 0;
  8830. * });
  8831. * // => [4, 9]
  8832. *
  8833. * _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
  8834. * result[key] = n * 3;
  8835. * });
  8836. * // => { 'a': 3, 'b': 6 }
  8837. */
  8838. function transform(object, iteratee, accumulator, thisArg) {
  8839. var isArr = isArray(object) || isTypedArray(object);
  8840. iteratee = getCallback(iteratee, thisArg, 4);
  8841. if (accumulator == null) {
  8842. if (isArr || isObject(object)) {
  8843. var Ctor = object.constructor;
  8844. if (isArr) {
  8845. accumulator = isArray(object) ? new Ctor : [];
  8846. } else {
  8847. accumulator = baseCreate(isFunction(Ctor) && Ctor.prototype);
  8848. }
  8849. } else {
  8850. accumulator = {};
  8851. }
  8852. }
  8853. (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
  8854. return iteratee(accumulator, value, index, object);
  8855. });
  8856. return accumulator;
  8857. }
  8858. /**
  8859. * Creates an array of the own enumerable property values of `object`.
  8860. *
  8861. * **Note:** Non-object values are coerced to objects.
  8862. *
  8863. * @static
  8864. * @memberOf _
  8865. * @category Object
  8866. * @param {Object} object The object to query.
  8867. * @returns {Array} Returns the array of property values.
  8868. * @example
  8869. *
  8870. * function Foo() {
  8871. * this.a = 1;
  8872. * this.b = 2;
  8873. * }
  8874. *
  8875. * Foo.prototype.c = 3;
  8876. *
  8877. * _.values(new Foo);
  8878. * // => [1, 2] (iteration order is not guaranteed)
  8879. *
  8880. * _.values('hi');
  8881. * // => ['h', 'i']
  8882. */
  8883. function values(object) {
  8884. return baseValues(object, keys(object));
  8885. }
  8886. /**
  8887. * Creates an array of the own and inherited enumerable property values
  8888. * of `object`.
  8889. *
  8890. * **Note:** Non-object values are coerced to objects.
  8891. *
  8892. * @static
  8893. * @memberOf _
  8894. * @category Object
  8895. * @param {Object} object The object to query.
  8896. * @returns {Array} Returns the array of property values.
  8897. * @example
  8898. *
  8899. * function Foo() {
  8900. * this.a = 1;
  8901. * this.b = 2;
  8902. * }
  8903. *
  8904. * Foo.prototype.c = 3;
  8905. *
  8906. * _.valuesIn(new Foo);
  8907. * // => [1, 2, 3] (iteration order is not guaranteed)
  8908. */
  8909. function valuesIn(object) {
  8910. return baseValues(object, keysIn(object));
  8911. }
  8912. /*------------------------------------------------------------------------*/
  8913. /**
  8914. * Checks if `n` is between `start` and up to but not including, `end`. If
  8915. * `end` is not specified it defaults to `start` with `start` becoming `0`.
  8916. *
  8917. * @static
  8918. * @memberOf _
  8919. * @category Number
  8920. * @param {number} n The number to check.
  8921. * @param {number} [start=0] The start of the range.
  8922. * @param {number} end The end of the range.
  8923. * @returns {boolean} Returns `true` if `n` is in the range, else `false`.
  8924. * @example
  8925. *
  8926. * _.inRange(3, 2, 4);
  8927. * // => true
  8928. *
  8929. * _.inRange(4, 8);
  8930. * // => true
  8931. *
  8932. * _.inRange(4, 2);
  8933. * // => false
  8934. *
  8935. * _.inRange(2, 2);
  8936. * // => false
  8937. *
  8938. * _.inRange(1.2, 2);
  8939. * // => true
  8940. *
  8941. * _.inRange(5.2, 4);
  8942. * // => false
  8943. */
  8944. function inRange(value, start, end) {
  8945. start = +start || 0;
  8946. if (typeof end === 'undefined') {
  8947. end = start;
  8948. start = 0;
  8949. } else {
  8950. end = +end || 0;
  8951. }
  8952. return value >= start && value < end;
  8953. }
  8954. /**
  8955. * Produces a random number between `min` and `max` (inclusive). If only one
  8956. * argument is provided a number between `0` and the given number is returned.
  8957. * If `floating` is `true`, or either `min` or `max` are floats, a floating-point
  8958. * number is returned instead of an integer.
  8959. *
  8960. * @static
  8961. * @memberOf _
  8962. * @category Number
  8963. * @param {number} [min=0] The minimum possible value.
  8964. * @param {number} [max=1] The maximum possible value.
  8965. * @param {boolean} [floating] Specify returning a floating-point number.
  8966. * @returns {number} Returns the random number.
  8967. * @example
  8968. *
  8969. * _.random(0, 5);
  8970. * // => an integer between 0 and 5
  8971. *
  8972. * _.random(5);
  8973. * // => also an integer between 0 and 5
  8974. *
  8975. * _.random(5, true);
  8976. * // => a floating-point number between 0 and 5
  8977. *
  8978. * _.random(1.2, 5.2);
  8979. * // => a floating-point number between 1.2 and 5.2
  8980. */
  8981. function random(min, max, floating) {
  8982. if (floating && isIterateeCall(min, max, floating)) {
  8983. max = floating = null;
  8984. }
  8985. var noMin = min == null,
  8986. noMax = max == null;
  8987. if (floating == null) {
  8988. if (noMax && typeof min == 'boolean') {
  8989. floating = min;
  8990. min = 1;
  8991. }
  8992. else if (typeof max == 'boolean') {
  8993. floating = max;
  8994. noMax = true;
  8995. }
  8996. }
  8997. if (noMin && noMax) {
  8998. max = 1;
  8999. noMax = false;
  9000. }
  9001. min = +min || 0;
  9002. if (noMax) {
  9003. max = min;
  9004. min = 0;
  9005. } else {
  9006. max = +max || 0;
  9007. }
  9008. if (floating || min % 1 || max % 1) {
  9009. var rand = nativeRandom();
  9010. return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1)))), max);
  9011. }
  9012. return baseRandom(min, max);
  9013. }
  9014. /*------------------------------------------------------------------------*/
  9015. /**
  9016. * Converts `string` to camel case.
  9017. * See [Wikipedia](https://en.wikipedia.org/wiki/CamelCase) for more details.
  9018. *
  9019. * @static
  9020. * @memberOf _
  9021. * @category String
  9022. * @param {string} [string=''] The string to convert.
  9023. * @returns {string} Returns the camel cased string.
  9024. * @example
  9025. *
  9026. * _.camelCase('Foo Bar');
  9027. * // => 'fooBar'
  9028. *
  9029. * _.camelCase('--foo-bar');
  9030. * // => 'fooBar'
  9031. *
  9032. * _.camelCase('__foo_bar__');
  9033. * // => 'fooBar'
  9034. */
  9035. var camelCase = createCompounder(function(result, word, index) {
  9036. word = word.toLowerCase();
  9037. return result + (index ? (word.charAt(0).toUpperCase() + word.slice(1)) : word);
  9038. });
  9039. /**
  9040. * Capitalizes the first character of `string`.
  9041. *
  9042. * @static
  9043. * @memberOf _
  9044. * @category String
  9045. * @param {string} [string=''] The string to capitalize.
  9046. * @returns {string} Returns the capitalized string.
  9047. * @example
  9048. *
  9049. * _.capitalize('fred');
  9050. * // => 'Fred'
  9051. */
  9052. function capitalize(string) {
  9053. string = baseToString(string);
  9054. return string && (string.charAt(0).toUpperCase() + string.slice(1));
  9055. }
  9056. /**
  9057. * Deburrs `string` by converting latin-1 supplementary letters to basic latin letters.
  9058. * See [Wikipedia](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  9059. * for more details.
  9060. *
  9061. * @static
  9062. * @memberOf _
  9063. * @category String
  9064. * @param {string} [string=''] The string to deburr.
  9065. * @returns {string} Returns the deburred string.
  9066. * @example
  9067. *
  9068. * _.deburr('déjà vu');
  9069. * // => 'deja vu'
  9070. */
  9071. function deburr(string) {
  9072. string = baseToString(string);
  9073. return string && string.replace(reLatin1, deburrLetter);
  9074. }
  9075. /**
  9076. * Checks if `string` ends with the given target string.
  9077. *
  9078. * @static
  9079. * @memberOf _
  9080. * @category String
  9081. * @param {string} [string=''] The string to search.
  9082. * @param {string} [target] The string to search for.
  9083. * @param {number} [position=string.length] The position to search from.
  9084. * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
  9085. * @example
  9086. *
  9087. * _.endsWith('abc', 'c');
  9088. * // => true
  9089. *
  9090. * _.endsWith('abc', 'b');
  9091. * // => false
  9092. *
  9093. * _.endsWith('abc', 'b', 2);
  9094. * // => true
  9095. */
  9096. function endsWith(string, target, position) {
  9097. string = baseToString(string);
  9098. target = (target + '');
  9099. var length = string.length;
  9100. position = (typeof position == 'undefined' ? length : nativeMin(position < 0 ? 0 : (+position || 0), length)) - target.length;
  9101. return position >= 0 && string.indexOf(target, position) == position;
  9102. }
  9103. /**
  9104. * Converts the characters "&", "<", ">", '"', "'", and '`', in `string` to
  9105. * their corresponding HTML entities.
  9106. *
  9107. * **Note:** No other characters are escaped. To escape additional characters
  9108. * use a third-party library like [_he_](https://mths.be/he).
  9109. *
  9110. * Though the ">" character is escaped for symmetry, characters like
  9111. * ">" and "/" don't require escaping in HTML and have no special meaning
  9112. * unless they're part of a tag or unquoted attribute value.
  9113. * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  9114. * (under "semi-related fun fact") for more details.
  9115. *
  9116. * Backticks are escaped because in Internet Explorer < 9, they can break out
  9117. * of attribute values or HTML comments. See [#102](https://html5sec.org/#102),
  9118. * [#108](https://html5sec.org/#108), and [#133](https://html5sec.org/#133) of
  9119. * the [HTML5 Security Cheatsheet](https://html5sec.org/) for more details.
  9120. *
  9121. * When working with HTML you should always quote attribute values to reduce
  9122. * XSS vectors. See [Ryan Grove's article](http://wonko.com/post/html-escaping)
  9123. * for more details.
  9124. *
  9125. * @static
  9126. * @memberOf _
  9127. * @category String
  9128. * @param {string} [string=''] The string to escape.
  9129. * @returns {string} Returns the escaped string.
  9130. * @example
  9131. *
  9132. * _.escape('fred, barney, & pebbles');
  9133. * // => 'fred, barney, &amp; pebbles'
  9134. */
  9135. function escape(string) {
  9136. // Reset `lastIndex` because in IE < 9 `String#replace` does not.
  9137. string = baseToString(string);
  9138. return (string && reHasUnescapedHtml.test(string))
  9139. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  9140. : string;
  9141. }
  9142. /**
  9143. * Escapes the `RegExp` special characters "\", "^", "$", ".", "|", "?", "*",
  9144. * "+", "(", ")", "[", "]", "{" and "}" in `string`.
  9145. *
  9146. * @static
  9147. * @memberOf _
  9148. * @category String
  9149. * @param {string} [string=''] The string to escape.
  9150. * @returns {string} Returns the escaped string.
  9151. * @example
  9152. *
  9153. * _.escapeRegExp('[lodash](https://lodash.com/)');
  9154. * // => '\[lodash\]\(https://lodash\.com/\)'
  9155. */
  9156. function escapeRegExp(string) {
  9157. string = baseToString(string);
  9158. return (string && reHasRegExpChars.test(string))
  9159. ? string.replace(reRegExpChars, '\\$&')
  9160. : string;
  9161. }
  9162. /**
  9163. * Converts `string` to kebab case.
  9164. * See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles) for
  9165. * more details.
  9166. *
  9167. * @static
  9168. * @memberOf _
  9169. * @category String
  9170. * @param {string} [string=''] The string to convert.
  9171. * @returns {string} Returns the kebab cased string.
  9172. * @example
  9173. *
  9174. * _.kebabCase('Foo Bar');
  9175. * // => 'foo-bar'
  9176. *
  9177. * _.kebabCase('fooBar');
  9178. * // => 'foo-bar'
  9179. *
  9180. * _.kebabCase('__foo_bar__');
  9181. * // => 'foo-bar'
  9182. */
  9183. var kebabCase = createCompounder(function(result, word, index) {
  9184. return result + (index ? '-' : '') + word.toLowerCase();
  9185. });
  9186. /**
  9187. * Pads `string` on the left and right sides if it is shorter then the given
  9188. * padding length. The `chars` string may be truncated if the number of padding
  9189. * characters can't be evenly divided by the padding length.
  9190. *
  9191. * @static
  9192. * @memberOf _
  9193. * @category String
  9194. * @param {string} [string=''] The string to pad.
  9195. * @param {number} [length=0] The padding length.
  9196. * @param {string} [chars=' '] The string used as padding.
  9197. * @returns {string} Returns the padded string.
  9198. * @example
  9199. *
  9200. * _.pad('abc', 8);
  9201. * // => ' abc '
  9202. *
  9203. * _.pad('abc', 8, '_-');
  9204. * // => '_-abc_-_'
  9205. *
  9206. * _.pad('abc', 3);
  9207. * // => 'abc'
  9208. */
  9209. function pad(string, length, chars) {
  9210. string = baseToString(string);
  9211. length = +length;
  9212. var strLength = string.length;
  9213. if (strLength >= length || !nativeIsFinite(length)) {
  9214. return string;
  9215. }
  9216. var mid = (length - strLength) / 2,
  9217. leftLength = floor(mid),
  9218. rightLength = ceil(mid);
  9219. chars = createPad('', rightLength, chars);
  9220. return chars.slice(0, leftLength) + string + chars;
  9221. }
  9222. /**
  9223. * Pads `string` on the left side if it is shorter then the given padding
  9224. * length. The `chars` string may be truncated if the number of padding
  9225. * characters exceeds the padding length.
  9226. *
  9227. * @static
  9228. * @memberOf _
  9229. * @category String
  9230. * @param {string} [string=''] The string to pad.
  9231. * @param {number} [length=0] The padding length.
  9232. * @param {string} [chars=' '] The string used as padding.
  9233. * @returns {string} Returns the padded string.
  9234. * @example
  9235. *
  9236. * _.padLeft('abc', 6);
  9237. * // => ' abc'
  9238. *
  9239. * _.padLeft('abc', 6, '_-');
  9240. * // => '_-_abc'
  9241. *
  9242. * _.padLeft('abc', 3);
  9243. * // => 'abc'
  9244. */
  9245. function padLeft(string, length, chars) {
  9246. string = baseToString(string);
  9247. return string && (createPad(string, length, chars) + string);
  9248. }
  9249. /**
  9250. * Pads `string` on the right side if it is shorter then the given padding
  9251. * length. The `chars` string may be truncated if the number of padding
  9252. * characters exceeds the padding length.
  9253. *
  9254. * @static
  9255. * @memberOf _
  9256. * @category String
  9257. * @param {string} [string=''] The string to pad.
  9258. * @param {number} [length=0] The padding length.
  9259. * @param {string} [chars=' '] The string used as padding.
  9260. * @returns {string} Returns the padded string.
  9261. * @example
  9262. *
  9263. * _.padRight('abc', 6);
  9264. * // => 'abc '
  9265. *
  9266. * _.padRight('abc', 6, '_-');
  9267. * // => 'abc_-_'
  9268. *
  9269. * _.padRight('abc', 3);
  9270. * // => 'abc'
  9271. */
  9272. function padRight(string, length, chars) {
  9273. string = baseToString(string);
  9274. return string && (string + createPad(string, length, chars));
  9275. }
  9276. /**
  9277. * Converts `string` to an integer of the specified radix. If `radix` is
  9278. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
  9279. * in which case a `radix` of `16` is used.
  9280. *
  9281. * **Note:** This method aligns with the ES5 implementation of `parseInt`.
  9282. * See the [ES5 spec](https://es5.github.io/#E) for more details.
  9283. *
  9284. * @static
  9285. * @memberOf _
  9286. * @category String
  9287. * @param {string} string The string to convert.
  9288. * @param {number} [radix] The radix to interpret `value` by.
  9289. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  9290. * @returns {number} Returns the converted integer.
  9291. * @example
  9292. *
  9293. * _.parseInt('08');
  9294. * // => 8
  9295. *
  9296. * _.map(['6', '08', '10'], _.parseInt);
  9297. * // => [6, 8, 10]
  9298. */
  9299. function parseInt(string, radix, guard) {
  9300. if (guard && isIterateeCall(string, radix, guard)) {
  9301. radix = 0;
  9302. }
  9303. return nativeParseInt(string, radix);
  9304. }
  9305. // Fallback for environments with pre-ES5 implementations.
  9306. if (nativeParseInt(whitespace + '08') != 8) {
  9307. parseInt = function(string, radix, guard) {
  9308. // Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
  9309. // Chrome fails to trim leading <BOM> whitespace characters.
  9310. // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
  9311. if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
  9312. radix = 0;
  9313. } else if (radix) {
  9314. radix = +radix;
  9315. }
  9316. string = trim(string);
  9317. return nativeParseInt(string, radix || (reHexPrefix.test(string) ? 16 : 10));
  9318. };
  9319. }
  9320. /**
  9321. * Repeats the given string `n` times.
  9322. *
  9323. * @static
  9324. * @memberOf _
  9325. * @category String
  9326. * @param {string} [string=''] The string to repeat.
  9327. * @param {number} [n=0] The number of times to repeat the string.
  9328. * @returns {string} Returns the repeated string.
  9329. * @example
  9330. *
  9331. * _.repeat('*', 3);
  9332. * // => '***'
  9333. *
  9334. * _.repeat('abc', 2);
  9335. * // => 'abcabc'
  9336. *
  9337. * _.repeat('abc', 0);
  9338. * // => ''
  9339. */
  9340. function repeat(string, n) {
  9341. var result = '';
  9342. string = baseToString(string);
  9343. n = +n;
  9344. if (n < 1 || !string || !nativeIsFinite(n)) {
  9345. return result;
  9346. }
  9347. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  9348. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  9349. do {
  9350. if (n % 2) {
  9351. result += string;
  9352. }
  9353. n = floor(n / 2);
  9354. string += string;
  9355. } while (n);
  9356. return result;
  9357. }
  9358. /**
  9359. * Converts `string` to snake case.
  9360. * See [Wikipedia](https://en.wikipedia.org/wiki/Snake_case) for more details.
  9361. *
  9362. * @static
  9363. * @memberOf _
  9364. * @category String
  9365. * @param {string} [string=''] The string to convert.
  9366. * @returns {string} Returns the snake cased string.
  9367. * @example
  9368. *
  9369. * _.snakeCase('Foo Bar');
  9370. * // => 'foo_bar'
  9371. *
  9372. * _.snakeCase('fooBar');
  9373. * // => 'foo_bar'
  9374. *
  9375. * _.snakeCase('--foo-bar');
  9376. * // => 'foo_bar'
  9377. */
  9378. var snakeCase = createCompounder(function(result, word, index) {
  9379. return result + (index ? '_' : '') + word.toLowerCase();
  9380. });
  9381. /**
  9382. * Converts `string` to start case.
  9383. * See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage)
  9384. * for more details.
  9385. *
  9386. * @static
  9387. * @memberOf _
  9388. * @category String
  9389. * @param {string} [string=''] The string to convert.
  9390. * @returns {string} Returns the start cased string.
  9391. * @example
  9392. *
  9393. * _.startCase('--foo-bar');
  9394. * // => 'Foo Bar'
  9395. *
  9396. * _.startCase('fooBar');
  9397. * // => 'Foo Bar'
  9398. *
  9399. * _.startCase('__foo_bar__');
  9400. * // => 'Foo Bar'
  9401. */
  9402. var startCase = createCompounder(function(result, word, index) {
  9403. return result + (index ? ' ' : '') + (word.charAt(0).toUpperCase() + word.slice(1));
  9404. });
  9405. /**
  9406. * Checks if `string` starts with the given target string.
  9407. *
  9408. * @static
  9409. * @memberOf _
  9410. * @category String
  9411. * @param {string} [string=''] The string to search.
  9412. * @param {string} [target] The string to search for.
  9413. * @param {number} [position=0] The position to search from.
  9414. * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
  9415. * @example
  9416. *
  9417. * _.startsWith('abc', 'a');
  9418. * // => true
  9419. *
  9420. * _.startsWith('abc', 'b');
  9421. * // => false
  9422. *
  9423. * _.startsWith('abc', 'b', 1);
  9424. * // => true
  9425. */
  9426. function startsWith(string, target, position) {
  9427. string = baseToString(string);
  9428. position = position == null ? 0 : nativeMin(position < 0 ? 0 : (+position || 0), string.length);
  9429. return string.lastIndexOf(target, position) == position;
  9430. }
  9431. /**
  9432. * Creates a compiled template function that can interpolate data properties
  9433. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  9434. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  9435. * properties may be accessed as free variables in the template. If a setting
  9436. * object is provided it takes precedence over `_.templateSettings` values.
  9437. *
  9438. * **Note:** In the development build `_.template` utilizes sourceURLs for easier debugging.
  9439. * See the [HTML5 Rocks article on sourcemaps](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  9440. * for more details.
  9441. *
  9442. * For more information on precompiling templates see
  9443. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  9444. *
  9445. * For more information on Chrome extension sandboxes see
  9446. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  9447. *
  9448. * @static
  9449. * @memberOf _
  9450. * @category String
  9451. * @param {string} [string=''] The template string.
  9452. * @param {Object} [options] The options object.
  9453. * @param {RegExp} [options.escape] The HTML "escape" delimiter.
  9454. * @param {RegExp} [options.evaluate] The "evaluate" delimiter.
  9455. * @param {Object} [options.imports] An object to import into the template as free variables.
  9456. * @param {RegExp} [options.interpolate] The "interpolate" delimiter.
  9457. * @param {string} [options.sourceURL] The sourceURL of the template's compiled source.
  9458. * @param {string} [options.variable] The data object variable name.
  9459. * @param- {Object} [otherOptions] Enables the legacy `options` param signature.
  9460. * @returns {Function} Returns the compiled template function.
  9461. * @example
  9462. *
  9463. * // using the "interpolate" delimiter to create a compiled template
  9464. * var compiled = _.template('hello <%= user %>!');
  9465. * compiled({ 'user': 'fred' });
  9466. * // => 'hello fred!'
  9467. *
  9468. * // using the HTML "escape" delimiter to escape data property values
  9469. * var compiled = _.template('<b><%- value %></b>');
  9470. * compiled({ 'value': '<script>' });
  9471. * // => '<b>&lt;script&gt;</b>'
  9472. *
  9473. * // using the "evaluate" delimiter to execute JavaScript and generate HTML
  9474. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  9475. * compiled({ 'users': ['fred', 'barney'] });
  9476. * // => '<li>fred</li><li>barney</li>'
  9477. *
  9478. * // using the internal `print` function in "evaluate" delimiters
  9479. * var compiled = _.template('<% print("hello " + user); %>!');
  9480. * compiled({ 'user': 'barney' });
  9481. * // => 'hello barney!'
  9482. *
  9483. * // using the ES delimiter as an alternative to the default "interpolate" delimiter
  9484. * var compiled = _.template('hello ${ user }!');
  9485. * compiled({ 'user': 'pebbles' });
  9486. * // => 'hello pebbles!'
  9487. *
  9488. * // using custom template delimiters
  9489. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  9490. * var compiled = _.template('hello {{ user }}!');
  9491. * compiled({ 'user': 'mustache' });
  9492. * // => 'hello mustache!'
  9493. *
  9494. * // using backslashes to treat delimiters as plain text
  9495. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  9496. * compiled({ 'value': 'ignored' });
  9497. * // => '<%- value %>'
  9498. *
  9499. * // using the `imports` option to import `jQuery` as `jq`
  9500. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  9501. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  9502. * compiled({ 'users': ['fred', 'barney'] });
  9503. * // => '<li>fred</li><li>barney</li>'
  9504. *
  9505. * // using the `sourceURL` option to specify a custom sourceURL for the template
  9506. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  9507. * compiled(data);
  9508. * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
  9509. *
  9510. * // using the `variable` option to ensure a with-statement isn't used in the compiled template
  9511. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  9512. * compiled.source;
  9513. * // => function(data) {
  9514. * var __t, __p = '';
  9515. * __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  9516. * return __p;
  9517. * }
  9518. *
  9519. * // using the `source` property to inline compiled templates for meaningful
  9520. * // line numbers in error messages and a stack trace
  9521. * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
  9522. * var JST = {\
  9523. * "main": ' + _.template(mainText).source + '\
  9524. * };\
  9525. * ');
  9526. */
  9527. function template(string, options, otherOptions) {
  9528. // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
  9529. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  9530. var settings = lodash.templateSettings;
  9531. if (otherOptions && isIterateeCall(string, options, otherOptions)) {
  9532. options = otherOptions = null;
  9533. }
  9534. string = baseToString(string);
  9535. options = baseAssign(baseAssign({}, otherOptions || options), settings, assignOwnDefaults);
  9536. var imports = baseAssign(baseAssign({}, options.imports), settings.imports, assignOwnDefaults),
  9537. importsKeys = keys(imports),
  9538. importsValues = baseValues(imports, importsKeys);
  9539. var isEscaping,
  9540. isEvaluating,
  9541. index = 0,
  9542. interpolate = options.interpolate || reNoMatch,
  9543. source = "__p += '";
  9544. // Compile the regexp to match each delimiter.
  9545. var reDelimiters = RegExp(
  9546. (options.escape || reNoMatch).source + '|' +
  9547. interpolate.source + '|' +
  9548. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  9549. (options.evaluate || reNoMatch).source + '|$'
  9550. , 'g');
  9551. // Use a sourceURL for easier debugging.
  9552. var sourceURL = '//# sourceURL=' +
  9553. ('sourceURL' in options
  9554. ? options.sourceURL
  9555. : ('lodash.templateSources[' + (++templateCounter) + ']')
  9556. ) + '\n';
  9557. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  9558. interpolateValue || (interpolateValue = esTemplateValue);
  9559. // Escape characters that can't be included in string literals.
  9560. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  9561. // Replace delimiters with snippets.
  9562. if (escapeValue) {
  9563. isEscaping = true;
  9564. source += "' +\n__e(" + escapeValue + ") +\n'";
  9565. }
  9566. if (evaluateValue) {
  9567. isEvaluating = true;
  9568. source += "';\n" + evaluateValue + ";\n__p += '";
  9569. }
  9570. if (interpolateValue) {
  9571. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  9572. }
  9573. index = offset + match.length;
  9574. // The JS engine embedded in Adobe products requires returning the `match`
  9575. // string in order to produce the correct `offset` value.
  9576. return match;
  9577. });
  9578. source += "';\n";
  9579. // If `variable` is not specified wrap a with-statement around the generated
  9580. // code to add the data object to the top of the scope chain.
  9581. var variable = options.variable;
  9582. if (!variable) {
  9583. source = 'with (obj) {\n' + source + '\n}\n';
  9584. }
  9585. // Cleanup code by stripping empty strings.
  9586. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  9587. .replace(reEmptyStringMiddle, '$1')
  9588. .replace(reEmptyStringTrailing, '$1;');
  9589. // Frame code as the function body.
  9590. source = 'function(' + (variable || 'obj') + ') {\n' +
  9591. (variable
  9592. ? ''
  9593. : 'obj || (obj = {});\n'
  9594. ) +
  9595. "var __t, __p = ''" +
  9596. (isEscaping
  9597. ? ', __e = _.escape'
  9598. : ''
  9599. ) +
  9600. (isEvaluating
  9601. ? ', __j = Array.prototype.join;\n' +
  9602. "function print() { __p += __j.call(arguments, '') }\n"
  9603. : ';\n'
  9604. ) +
  9605. source +
  9606. 'return __p\n}';
  9607. var result = attempt(function() {
  9608. return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues);
  9609. });
  9610. // Provide the compiled function's source by its `toString` method or
  9611. // the `source` property as a convenience for inlining compiled templates.
  9612. result.source = source;
  9613. if (isError(result)) {
  9614. throw result;
  9615. }
  9616. return result;
  9617. }
  9618. /**
  9619. * Removes leading and trailing whitespace or specified characters from `string`.
  9620. *
  9621. * @static
  9622. * @memberOf _
  9623. * @category String
  9624. * @param {string} [string=''] The string to trim.
  9625. * @param {string} [chars=whitespace] The characters to trim.
  9626. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  9627. * @returns {string} Returns the trimmed string.
  9628. * @example
  9629. *
  9630. * _.trim(' abc ');
  9631. * // => 'abc'
  9632. *
  9633. * _.trim('-_-abc-_-', '_-');
  9634. * // => 'abc'
  9635. *
  9636. * _.map([' foo ', ' bar '], _.trim);
  9637. * // => ['foo', 'bar]
  9638. */
  9639. function trim(string, chars, guard) {
  9640. var value = string;
  9641. string = baseToString(string);
  9642. if (!string) {
  9643. return string;
  9644. }
  9645. if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
  9646. return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
  9647. }
  9648. chars = (chars + '');
  9649. return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
  9650. }
  9651. /**
  9652. * Removes leading whitespace or specified characters from `string`.
  9653. *
  9654. * @static
  9655. * @memberOf _
  9656. * @category String
  9657. * @param {string} [string=''] The string to trim.
  9658. * @param {string} [chars=whitespace] The characters to trim.
  9659. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  9660. * @returns {string} Returns the trimmed string.
  9661. * @example
  9662. *
  9663. * _.trimLeft(' abc ');
  9664. * // => 'abc '
  9665. *
  9666. * _.trimLeft('-_-abc-_-', '_-');
  9667. * // => 'abc-_-'
  9668. */
  9669. function trimLeft(string, chars, guard) {
  9670. var value = string;
  9671. string = baseToString(string);
  9672. if (!string) {
  9673. return string;
  9674. }
  9675. if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
  9676. return string.slice(trimmedLeftIndex(string));
  9677. }
  9678. return string.slice(charsLeftIndex(string, (chars + '')));
  9679. }
  9680. /**
  9681. * Removes trailing whitespace or specified characters from `string`.
  9682. *
  9683. * @static
  9684. * @memberOf _
  9685. * @category String
  9686. * @param {string} [string=''] The string to trim.
  9687. * @param {string} [chars=whitespace] The characters to trim.
  9688. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  9689. * @returns {string} Returns the trimmed string.
  9690. * @example
  9691. *
  9692. * _.trimRight(' abc ');
  9693. * // => ' abc'
  9694. *
  9695. * _.trimRight('-_-abc-_-', '_-');
  9696. * // => '-_-abc'
  9697. */
  9698. function trimRight(string, chars, guard) {
  9699. var value = string;
  9700. string = baseToString(string);
  9701. if (!string) {
  9702. return string;
  9703. }
  9704. if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
  9705. return string.slice(0, trimmedRightIndex(string) + 1);
  9706. }
  9707. return string.slice(0, charsRightIndex(string, (chars + '')) + 1);
  9708. }
  9709. /**
  9710. * Truncates `string` if it is longer than the given maximum string length.
  9711. * The last characters of the truncated string are replaced with the omission
  9712. * string which defaults to "...".
  9713. *
  9714. * @static
  9715. * @memberOf _
  9716. * @category String
  9717. * @param {string} [string=''] The string to truncate.
  9718. * @param {Object|number} [options] The options object or maximum string length.
  9719. * @param {number} [options.length=30] The maximum string length.
  9720. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  9721. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  9722. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  9723. * @returns {string} Returns the truncated string.
  9724. * @example
  9725. *
  9726. * _.trunc('hi-diddly-ho there, neighborino');
  9727. * // => 'hi-diddly-ho there, neighbo...'
  9728. *
  9729. * _.trunc('hi-diddly-ho there, neighborino', 24);
  9730. * // => 'hi-diddly-ho there, n...'
  9731. *
  9732. * _.trunc('hi-diddly-ho there, neighborino', {
  9733. * 'length': 24,
  9734. * 'separator': ' '
  9735. * });
  9736. * // => 'hi-diddly-ho there,...'
  9737. *
  9738. * _.trunc('hi-diddly-ho there, neighborino', {
  9739. * 'length': 24,
  9740. * 'separator': /,? +/
  9741. * });
  9742. * //=> 'hi-diddly-ho there...'
  9743. *
  9744. * _.trunc('hi-diddly-ho there, neighborino', {
  9745. * 'omission': ' [...]'
  9746. * });
  9747. * // => 'hi-diddly-ho there, neig [...]'
  9748. */
  9749. function trunc(string, options, guard) {
  9750. if (guard && isIterateeCall(string, options, guard)) {
  9751. options = null;
  9752. }
  9753. var length = DEFAULT_TRUNC_LENGTH,
  9754. omission = DEFAULT_TRUNC_OMISSION;
  9755. if (options != null) {
  9756. if (isObject(options)) {
  9757. var separator = 'separator' in options ? options.separator : separator;
  9758. length = 'length' in options ? +options.length || 0 : length;
  9759. omission = 'omission' in options ? baseToString(options.omission) : omission;
  9760. } else {
  9761. length = +options || 0;
  9762. }
  9763. }
  9764. string = baseToString(string);
  9765. if (length >= string.length) {
  9766. return string;
  9767. }
  9768. var end = length - omission.length;
  9769. if (end < 1) {
  9770. return omission;
  9771. }
  9772. var result = string.slice(0, end);
  9773. if (separator == null) {
  9774. return result + omission;
  9775. }
  9776. if (isRegExp(separator)) {
  9777. if (string.slice(end).search(separator)) {
  9778. var match,
  9779. newEnd,
  9780. substring = string.slice(0, end);
  9781. if (!separator.global) {
  9782. separator = RegExp(separator.source, (reFlags.exec(separator) || '') + 'g');
  9783. }
  9784. separator.lastIndex = 0;
  9785. while ((match = separator.exec(substring))) {
  9786. newEnd = match.index;
  9787. }
  9788. result = result.slice(0, newEnd == null ? end : newEnd);
  9789. }
  9790. } else if (string.indexOf(separator, end) != end) {
  9791. var index = result.lastIndexOf(separator);
  9792. if (index > -1) {
  9793. result = result.slice(0, index);
  9794. }
  9795. }
  9796. return result + omission;
  9797. }
  9798. /**
  9799. * The inverse of `_.escape`; this method converts the HTML entities
  9800. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&#39;`, and `&#96;` in `string` to their
  9801. * corresponding characters.
  9802. *
  9803. * **Note:** No other HTML entities are unescaped. To unescape additional HTML
  9804. * entities use a third-party library like [_he_](https://mths.be/he).
  9805. *
  9806. * @static
  9807. * @memberOf _
  9808. * @category String
  9809. * @param {string} [string=''] The string to unescape.
  9810. * @returns {string} Returns the unescaped string.
  9811. * @example
  9812. *
  9813. * _.unescape('fred, barney, &amp; pebbles');
  9814. * // => 'fred, barney, & pebbles'
  9815. */
  9816. function unescape(string) {
  9817. string = baseToString(string);
  9818. return (string && reHasEscapedHtml.test(string))
  9819. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  9820. : string;
  9821. }
  9822. /**
  9823. * Splits `string` into an array of its words.
  9824. *
  9825. * @static
  9826. * @memberOf _
  9827. * @category String
  9828. * @param {string} [string=''] The string to inspect.
  9829. * @param {RegExp|string} [pattern] The pattern to match words.
  9830. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  9831. * @returns {Array} Returns the words of `string`.
  9832. * @example
  9833. *
  9834. * _.words('fred, barney, & pebbles');
  9835. * // => ['fred', 'barney', 'pebbles']
  9836. *
  9837. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  9838. * // => ['fred', 'barney', '&', 'pebbles']
  9839. */
  9840. function words(string, pattern, guard) {
  9841. if (guard && isIterateeCall(string, pattern, guard)) {
  9842. pattern = null;
  9843. }
  9844. string = baseToString(string);
  9845. return string.match(pattern || reWords) || [];
  9846. }
  9847. /*------------------------------------------------------------------------*/
  9848. /**
  9849. * Attempts to invoke `func`, returning either the result or the caught error
  9850. * object. Any additional arguments are provided to `func` when it is invoked.
  9851. *
  9852. * @static
  9853. * @memberOf _
  9854. * @category Utility
  9855. * @param {*} func The function to attempt.
  9856. * @returns {*} Returns the `func` result or error object.
  9857. * @example
  9858. *
  9859. * // avoid throwing errors for invalid selectors
  9860. * var elements = _.attempt(function(selector) {
  9861. * return document.querySelectorAll(selector);
  9862. * }, '>_>');
  9863. *
  9864. * if (_.isError(elements)) {
  9865. * elements = [];
  9866. * }
  9867. */
  9868. function attempt() {
  9869. var length = arguments.length,
  9870. func = arguments[0];
  9871. try {
  9872. var args = Array(length ? length - 1 : 0);
  9873. while (--length > 0) {
  9874. args[length - 1] = arguments[length];
  9875. }
  9876. return func.apply(undefined, args);
  9877. } catch(e) {
  9878. return isError(e) ? e : new Error(e);
  9879. }
  9880. }
  9881. /**
  9882. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  9883. * and arguments of the created function. If `func` is a property name the
  9884. * created callback returns the property value for a given element. If `func`
  9885. * is an object the created callback returns `true` for elements that contain
  9886. * the equivalent object properties, otherwise it returns `false`.
  9887. *
  9888. * @static
  9889. * @memberOf _
  9890. * @alias iteratee
  9891. * @category Utility
  9892. * @param {*} [func=_.identity] The value to convert to a callback.
  9893. * @param {*} [thisArg] The `this` binding of `func`.
  9894. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  9895. * @returns {Function} Returns the callback.
  9896. * @example
  9897. *
  9898. * var users = [
  9899. * { 'user': 'barney', 'age': 36 },
  9900. * { 'user': 'fred', 'age': 40 }
  9901. * ];
  9902. *
  9903. * // wrap to create custom callback shorthands
  9904. * _.callback = _.wrap(_.callback, function(callback, func, thisArg) {
  9905. * var match = /^(.+?)__([gl]t)(.+)$/.exec(func);
  9906. * if (!match) {
  9907. * return callback(func, thisArg);
  9908. * }
  9909. * return function(object) {
  9910. * return match[2] == 'gt'
  9911. * ? object[match[1]] > match[3]
  9912. * : object[match[1]] < match[3];
  9913. * };
  9914. * });
  9915. *
  9916. * _.filter(users, 'age__gt36');
  9917. * // => [{ 'user': 'fred', 'age': 40 }]
  9918. */
  9919. function callback(func, thisArg, guard) {
  9920. if (guard && isIterateeCall(func, thisArg, guard)) {
  9921. thisArg = null;
  9922. }
  9923. return isObjectLike(func)
  9924. ? matches(func)
  9925. : baseCallback(func, thisArg);
  9926. }
  9927. /**
  9928. * Creates a function that returns `value`.
  9929. *
  9930. * @static
  9931. * @memberOf _
  9932. * @category Utility
  9933. * @param {*} value The value to return from the new function.
  9934. * @returns {Function} Returns the new function.
  9935. * @example
  9936. *
  9937. * var object = { 'user': 'fred' };
  9938. * var getter = _.constant(object);
  9939. *
  9940. * getter() === object;
  9941. * // => true
  9942. */
  9943. function constant(value) {
  9944. return function() {
  9945. return value;
  9946. };
  9947. }
  9948. /**
  9949. * This method returns the first argument provided to it.
  9950. *
  9951. * @static
  9952. * @memberOf _
  9953. * @category Utility
  9954. * @param {*} value Any value.
  9955. * @returns {*} Returns `value`.
  9956. * @example
  9957. *
  9958. * var object = { 'user': 'fred' };
  9959. *
  9960. * _.identity(object) === object;
  9961. * // => true
  9962. */
  9963. function identity(value) {
  9964. return value;
  9965. }
  9966. /**
  9967. * Creates a function which performs a deep comparison between a given object
  9968. * and `source`, returning `true` if the given object has equivalent property
  9969. * values, else `false`.
  9970. *
  9971. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  9972. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  9973. * their own, not inherited, enumerable properties. For comparing a single
  9974. * own or inherited property value see `_.matchesProperty`.
  9975. *
  9976. * @static
  9977. * @memberOf _
  9978. * @category Utility
  9979. * @param {Object} source The object of property values to match.
  9980. * @returns {Function} Returns the new function.
  9981. * @example
  9982. *
  9983. * var users = [
  9984. * { 'user': 'barney', 'age': 36, 'active': true },
  9985. * { 'user': 'fred', 'age': 40, 'active': false }
  9986. * ];
  9987. *
  9988. * _.filter(users, _.matches({ 'age': 40, 'active': false }));
  9989. * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
  9990. */
  9991. function matches(source) {
  9992. return baseMatches(baseClone(source, true));
  9993. }
  9994. /**
  9995. * Creates a function which compares the property value of `key` on a given
  9996. * object to `value`.
  9997. *
  9998. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  9999. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  10000. * their own, not inherited, enumerable properties.
  10001. *
  10002. * @static
  10003. * @memberOf _
  10004. * @category Utility
  10005. * @param {string} key The key of the property to get.
  10006. * @param {*} value The value to compare.
  10007. * @returns {Function} Returns the new function.
  10008. * @example
  10009. *
  10010. * var users = [
  10011. * { 'user': 'barney' },
  10012. * { 'user': 'fred' },
  10013. * { 'user': 'pebbles' }
  10014. * ];
  10015. *
  10016. * _.find(users, _.matchesProperty('user', 'fred'));
  10017. * // => { 'user': 'fred', 'age': 40 }
  10018. */
  10019. function matchesProperty(key, value) {
  10020. return baseMatchesProperty(key + '', baseClone(value, true));
  10021. }
  10022. /**
  10023. * Adds all own enumerable function properties of a source object to the
  10024. * destination object. If `object` is a function then methods are added to
  10025. * its prototype as well.
  10026. *
  10027. * @static
  10028. * @memberOf _
  10029. * @category Utility
  10030. * @param {Function|Object} [object=this] object The destination object.
  10031. * @param {Object} source The object of functions to add.
  10032. * @param {Object} [options] The options object.
  10033. * @param {boolean} [options.chain=true] Specify whether the functions added
  10034. * are chainable.
  10035. * @returns {Function|Object} Returns `object`.
  10036. * @example
  10037. *
  10038. * function vowels(string) {
  10039. * return _.filter(string, function(v) {
  10040. * return /[aeiou]/i.test(v);
  10041. * });
  10042. * }
  10043. *
  10044. * // use `_.runInContext` to avoid potential conflicts (esp. in Node.js)
  10045. * var _ = require('lodash').runInContext();
  10046. *
  10047. * _.mixin({ 'vowels': vowels });
  10048. * _.vowels('fred');
  10049. * // => ['e']
  10050. *
  10051. * _('fred').vowels().value();
  10052. * // => ['e']
  10053. *
  10054. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  10055. * _('fred').vowels();
  10056. * // => ['e']
  10057. */
  10058. function mixin(object, source, options) {
  10059. if (options == null) {
  10060. var isObj = isObject(source),
  10061. props = isObj && keys(source),
  10062. methodNames = props && props.length && baseFunctions(source, props);
  10063. if (!(methodNames ? methodNames.length : isObj)) {
  10064. methodNames = false;
  10065. options = source;
  10066. source = object;
  10067. object = this;
  10068. }
  10069. }
  10070. if (!methodNames) {
  10071. methodNames = baseFunctions(source, keys(source));
  10072. }
  10073. var chain = true,
  10074. index = -1,
  10075. isFunc = isFunction(object),
  10076. length = methodNames.length;
  10077. if (options === false) {
  10078. chain = false;
  10079. } else if (isObject(options) && 'chain' in options) {
  10080. chain = options.chain;
  10081. }
  10082. while (++index < length) {
  10083. var methodName = methodNames[index],
  10084. func = source[methodName];
  10085. object[methodName] = func;
  10086. if (isFunc) {
  10087. object.prototype[methodName] = (function(func) {
  10088. return function() {
  10089. var chainAll = this.__chain__;
  10090. if (chain || chainAll) {
  10091. var result = object(this.__wrapped__);
  10092. (result.__actions__ = arrayCopy(this.__actions__)).push({ 'func': func, 'args': arguments, 'thisArg': object });
  10093. result.__chain__ = chainAll;
  10094. return result;
  10095. }
  10096. var args = [this.value()];
  10097. push.apply(args, arguments);
  10098. return func.apply(object, args);
  10099. };
  10100. }(func));
  10101. }
  10102. }
  10103. return object;
  10104. }
  10105. /**
  10106. * Reverts the `_` variable to its previous value and returns a reference to
  10107. * the `lodash` function.
  10108. *
  10109. * @static
  10110. * @memberOf _
  10111. * @category Utility
  10112. * @returns {Function} Returns the `lodash` function.
  10113. * @example
  10114. *
  10115. * var lodash = _.noConflict();
  10116. */
  10117. function noConflict() {
  10118. context._ = oldDash;
  10119. return this;
  10120. }
  10121. /**
  10122. * A no-operation function which returns `undefined` regardless of the
  10123. * arguments it receives.
  10124. *
  10125. * @static
  10126. * @memberOf _
  10127. * @category Utility
  10128. * @example
  10129. *
  10130. * var object = { 'user': 'fred' };
  10131. *
  10132. * _.noop(object) === undefined;
  10133. * // => true
  10134. */
  10135. function noop() {
  10136. // No operation performed.
  10137. }
  10138. /**
  10139. * Creates a function which returns the property value of `key` on a given object.
  10140. *
  10141. * @static
  10142. * @memberOf _
  10143. * @category Utility
  10144. * @param {string} key The key of the property to get.
  10145. * @returns {Function} Returns the new function.
  10146. * @example
  10147. *
  10148. * var users = [
  10149. * { 'user': 'fred' },
  10150. * { 'user': 'barney' }
  10151. * ];
  10152. *
  10153. * var getName = _.property('user');
  10154. *
  10155. * _.map(users, getName);
  10156. * // => ['fred', barney']
  10157. *
  10158. * _.pluck(_.sortBy(users, getName), 'user');
  10159. * // => ['barney', 'fred']
  10160. */
  10161. function property(key) {
  10162. return baseProperty(key + '');
  10163. }
  10164. /**
  10165. * The inverse of `_.property`; this method creates a function which returns
  10166. * the property value of a given key on `object`.
  10167. *
  10168. * @static
  10169. * @memberOf _
  10170. * @category Utility
  10171. * @param {Object} object The object to inspect.
  10172. * @returns {Function} Returns the new function.
  10173. * @example
  10174. *
  10175. * var object = { 'a': 3, 'b': 1, 'c': 2 };
  10176. *
  10177. * _.map(['a', 'c'], _.propertyOf(object));
  10178. * // => [3, 2]
  10179. *
  10180. * _.sortBy(['a', 'b', 'c'], _.propertyOf(object));
  10181. * // => ['b', 'c', 'a']
  10182. */
  10183. function propertyOf(object) {
  10184. return function(key) {
  10185. return object == null ? undefined : object[key];
  10186. };
  10187. }
  10188. /**
  10189. * Creates an array of numbers (positive and/or negative) progressing from
  10190. * `start` up to, but not including, `end`. If `end` is not specified it
  10191. * defaults to `start` with `start` becoming `0`. If `start` is less than
  10192. * `end` a zero-length range is created unless a negative `step` is specified.
  10193. *
  10194. * @static
  10195. * @memberOf _
  10196. * @category Utility
  10197. * @param {number} [start=0] The start of the range.
  10198. * @param {number} end The end of the range.
  10199. * @param {number} [step=1] The value to increment or decrement by.
  10200. * @returns {Array} Returns the new array of numbers.
  10201. * @example
  10202. *
  10203. * _.range(4);
  10204. * // => [0, 1, 2, 3]
  10205. *
  10206. * _.range(1, 5);
  10207. * // => [1, 2, 3, 4]
  10208. *
  10209. * _.range(0, 20, 5);
  10210. * // => [0, 5, 10, 15]
  10211. *
  10212. * _.range(0, -4, -1);
  10213. * // => [0, -1, -2, -3]
  10214. *
  10215. * _.range(1, 4, 0);
  10216. * // => [1, 1, 1]
  10217. *
  10218. * _.range(0);
  10219. * // => []
  10220. */
  10221. function range(start, end, step) {
  10222. if (step && isIterateeCall(start, end, step)) {
  10223. end = step = null;
  10224. }
  10225. start = +start || 0;
  10226. step = step == null ? 1 : (+step || 0);
  10227. if (end == null) {
  10228. end = start;
  10229. start = 0;
  10230. } else {
  10231. end = +end || 0;
  10232. }
  10233. // Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
  10234. // See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
  10235. var index = -1,
  10236. length = nativeMax(ceil((end - start) / (step || 1)), 0),
  10237. result = Array(length);
  10238. while (++index < length) {
  10239. result[index] = start;
  10240. start += step;
  10241. }
  10242. return result;
  10243. }
  10244. /**
  10245. * Invokes the iteratee function `n` times, returning an array of the results
  10246. * of each invocation. The `iteratee` is bound to `thisArg` and invoked with
  10247. * one argument; (index).
  10248. *
  10249. * @static
  10250. * @memberOf _
  10251. * @category Utility
  10252. * @param {number} n The number of times to invoke `iteratee`.
  10253. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  10254. * @param {*} [thisArg] The `this` binding of `iteratee`.
  10255. * @returns {Array} Returns the array of results.
  10256. * @example
  10257. *
  10258. * var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
  10259. * // => [3, 6, 4]
  10260. *
  10261. * _.times(3, function(n) {
  10262. * mage.castSpell(n);
  10263. * });
  10264. * // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2` respectively
  10265. *
  10266. * _.times(3, function(n) {
  10267. * this.cast(n);
  10268. * }, mage);
  10269. * // => also invokes `mage.castSpell(n)` three times
  10270. */
  10271. function times(n, iteratee, thisArg) {
  10272. n = +n;
  10273. // Exit early to avoid a JSC JIT bug in Safari 8
  10274. // where `Array(0)` is treated as `Array(1)`.
  10275. if (n < 1 || !nativeIsFinite(n)) {
  10276. return [];
  10277. }
  10278. var index = -1,
  10279. result = Array(nativeMin(n, MAX_ARRAY_LENGTH));
  10280. iteratee = bindCallback(iteratee, thisArg, 1);
  10281. while (++index < n) {
  10282. if (index < MAX_ARRAY_LENGTH) {
  10283. result[index] = iteratee(index);
  10284. } else {
  10285. iteratee(index);
  10286. }
  10287. }
  10288. return result;
  10289. }
  10290. /**
  10291. * Generates a unique ID. If `prefix` is provided the ID is appended to it.
  10292. *
  10293. * @static
  10294. * @memberOf _
  10295. * @category Utility
  10296. * @param {string} [prefix] The value to prefix the ID with.
  10297. * @returns {string} Returns the unique ID.
  10298. * @example
  10299. *
  10300. * _.uniqueId('contact_');
  10301. * // => 'contact_104'
  10302. *
  10303. * _.uniqueId();
  10304. * // => '105'
  10305. */
  10306. function uniqueId(prefix) {
  10307. var id = ++idCounter;
  10308. return baseToString(prefix) + id;
  10309. }
  10310. /*------------------------------------------------------------------------*/
  10311. // Ensure wrappers are instances of `baseLodash`.
  10312. lodash.prototype = baseLodash.prototype;
  10313. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  10314. LodashWrapper.prototype.constructor = LodashWrapper;
  10315. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  10316. LazyWrapper.prototype.constructor = LazyWrapper;
  10317. // Add functions to the `Map` cache.
  10318. MapCache.prototype['delete'] = mapDelete;
  10319. MapCache.prototype.get = mapGet;
  10320. MapCache.prototype.has = mapHas;
  10321. MapCache.prototype.set = mapSet;
  10322. // Add functions to the `Set` cache.
  10323. SetCache.prototype.push = cachePush;
  10324. // Assign cache to `_.memoize`.
  10325. memoize.Cache = MapCache;
  10326. // Add functions that return wrapped values when chaining.
  10327. lodash.after = after;
  10328. lodash.ary = ary;
  10329. lodash.assign = assign;
  10330. lodash.at = at;
  10331. lodash.before = before;
  10332. lodash.bind = bind;
  10333. lodash.bindAll = bindAll;
  10334. lodash.bindKey = bindKey;
  10335. lodash.callback = callback;
  10336. lodash.chain = chain;
  10337. lodash.chunk = chunk;
  10338. lodash.compact = compact;
  10339. lodash.constant = constant;
  10340. lodash.countBy = countBy;
  10341. lodash.create = create;
  10342. lodash.curry = curry;
  10343. lodash.curryRight = curryRight;
  10344. lodash.debounce = debounce;
  10345. lodash.defaults = defaults;
  10346. lodash.defer = defer;
  10347. lodash.delay = delay;
  10348. lodash.difference = difference;
  10349. lodash.drop = drop;
  10350. lodash.dropRight = dropRight;
  10351. lodash.dropRightWhile = dropRightWhile;
  10352. lodash.dropWhile = dropWhile;
  10353. lodash.fill = fill;
  10354. lodash.filter = filter;
  10355. lodash.flatten = flatten;
  10356. lodash.flattenDeep = flattenDeep;
  10357. lodash.flow = flow;
  10358. lodash.flowRight = flowRight;
  10359. lodash.forEach = forEach;
  10360. lodash.forEachRight = forEachRight;
  10361. lodash.forIn = forIn;
  10362. lodash.forInRight = forInRight;
  10363. lodash.forOwn = forOwn;
  10364. lodash.forOwnRight = forOwnRight;
  10365. lodash.functions = functions;
  10366. lodash.groupBy = groupBy;
  10367. lodash.indexBy = indexBy;
  10368. lodash.initial = initial;
  10369. lodash.intersection = intersection;
  10370. lodash.invert = invert;
  10371. lodash.invoke = invoke;
  10372. lodash.keys = keys;
  10373. lodash.keysIn = keysIn;
  10374. lodash.map = map;
  10375. lodash.mapValues = mapValues;
  10376. lodash.matches = matches;
  10377. lodash.matchesProperty = matchesProperty;
  10378. lodash.memoize = memoize;
  10379. lodash.merge = merge;
  10380. lodash.mixin = mixin;
  10381. lodash.negate = negate;
  10382. lodash.omit = omit;
  10383. lodash.once = once;
  10384. lodash.pairs = pairs;
  10385. lodash.partial = partial;
  10386. lodash.partialRight = partialRight;
  10387. lodash.partition = partition;
  10388. lodash.pick = pick;
  10389. lodash.pluck = pluck;
  10390. lodash.property = property;
  10391. lodash.propertyOf = propertyOf;
  10392. lodash.pull = pull;
  10393. lodash.pullAt = pullAt;
  10394. lodash.range = range;
  10395. lodash.rearg = rearg;
  10396. lodash.reject = reject;
  10397. lodash.remove = remove;
  10398. lodash.rest = rest;
  10399. lodash.shuffle = shuffle;
  10400. lodash.slice = slice;
  10401. lodash.sortBy = sortBy;
  10402. lodash.sortByAll = sortByAll;
  10403. lodash.spread = spread;
  10404. lodash.take = take;
  10405. lodash.takeRight = takeRight;
  10406. lodash.takeRightWhile = takeRightWhile;
  10407. lodash.takeWhile = takeWhile;
  10408. lodash.tap = tap;
  10409. lodash.throttle = throttle;
  10410. lodash.thru = thru;
  10411. lodash.times = times;
  10412. lodash.toArray = toArray;
  10413. lodash.toPlainObject = toPlainObject;
  10414. lodash.transform = transform;
  10415. lodash.union = union;
  10416. lodash.uniq = uniq;
  10417. lodash.unzip = unzip;
  10418. lodash.values = values;
  10419. lodash.valuesIn = valuesIn;
  10420. lodash.where = where;
  10421. lodash.without = without;
  10422. lodash.wrap = wrap;
  10423. lodash.xor = xor;
  10424. lodash.zip = zip;
  10425. lodash.zipObject = zipObject;
  10426. // Add aliases.
  10427. lodash.backflow = flowRight;
  10428. lodash.collect = map;
  10429. lodash.compose = flowRight;
  10430. lodash.each = forEach;
  10431. lodash.eachRight = forEachRight;
  10432. lodash.extend = assign;
  10433. lodash.iteratee = callback;
  10434. lodash.methods = functions;
  10435. lodash.object = zipObject;
  10436. lodash.select = filter;
  10437. lodash.tail = rest;
  10438. lodash.unique = uniq;
  10439. // Add functions to `lodash.prototype`.
  10440. mixin(lodash, lodash);
  10441. /*------------------------------------------------------------------------*/
  10442. // Add functions that return unwrapped values when chaining.
  10443. lodash.attempt = attempt;
  10444. lodash.camelCase = camelCase;
  10445. lodash.capitalize = capitalize;
  10446. lodash.clone = clone;
  10447. lodash.cloneDeep = cloneDeep;
  10448. lodash.deburr = deburr;
  10449. lodash.endsWith = endsWith;
  10450. lodash.escape = escape;
  10451. lodash.escapeRegExp = escapeRegExp;
  10452. lodash.every = every;
  10453. lodash.find = find;
  10454. lodash.findIndex = findIndex;
  10455. lodash.findKey = findKey;
  10456. lodash.findLast = findLast;
  10457. lodash.findLastIndex = findLastIndex;
  10458. lodash.findLastKey = findLastKey;
  10459. lodash.findWhere = findWhere;
  10460. lodash.first = first;
  10461. lodash.has = has;
  10462. lodash.identity = identity;
  10463. lodash.includes = includes;
  10464. lodash.indexOf = indexOf;
  10465. lodash.inRange = inRange;
  10466. lodash.isArguments = isArguments;
  10467. lodash.isArray = isArray;
  10468. lodash.isBoolean = isBoolean;
  10469. lodash.isDate = isDate;
  10470. lodash.isElement = isElement;
  10471. lodash.isEmpty = isEmpty;
  10472. lodash.isEqual = isEqual;
  10473. lodash.isError = isError;
  10474. lodash.isFinite = isFinite;
  10475. lodash.isFunction = isFunction;
  10476. lodash.isMatch = isMatch;
  10477. lodash.isNaN = isNaN;
  10478. lodash.isNative = isNative;
  10479. lodash.isNull = isNull;
  10480. lodash.isNumber = isNumber;
  10481. lodash.isObject = isObject;
  10482. lodash.isPlainObject = isPlainObject;
  10483. lodash.isRegExp = isRegExp;
  10484. lodash.isString = isString;
  10485. lodash.isTypedArray = isTypedArray;
  10486. lodash.isUndefined = isUndefined;
  10487. lodash.kebabCase = kebabCase;
  10488. lodash.last = last;
  10489. lodash.lastIndexOf = lastIndexOf;
  10490. lodash.max = max;
  10491. lodash.min = min;
  10492. lodash.noConflict = noConflict;
  10493. lodash.noop = noop;
  10494. lodash.now = now;
  10495. lodash.pad = pad;
  10496. lodash.padLeft = padLeft;
  10497. lodash.padRight = padRight;
  10498. lodash.parseInt = parseInt;
  10499. lodash.random = random;
  10500. lodash.reduce = reduce;
  10501. lodash.reduceRight = reduceRight;
  10502. lodash.repeat = repeat;
  10503. lodash.result = result;
  10504. lodash.runInContext = runInContext;
  10505. lodash.size = size;
  10506. lodash.snakeCase = snakeCase;
  10507. lodash.some = some;
  10508. lodash.sortedIndex = sortedIndex;
  10509. lodash.sortedLastIndex = sortedLastIndex;
  10510. lodash.startCase = startCase;
  10511. lodash.startsWith = startsWith;
  10512. lodash.template = template;
  10513. lodash.trim = trim;
  10514. lodash.trimLeft = trimLeft;
  10515. lodash.trimRight = trimRight;
  10516. lodash.trunc = trunc;
  10517. lodash.unescape = unescape;
  10518. lodash.uniqueId = uniqueId;
  10519. lodash.words = words;
  10520. // Add aliases.
  10521. lodash.all = every;
  10522. lodash.any = some;
  10523. lodash.contains = includes;
  10524. lodash.detect = find;
  10525. lodash.foldl = reduce;
  10526. lodash.foldr = reduceRight;
  10527. lodash.head = first;
  10528. lodash.include = includes;
  10529. lodash.inject = reduce;
  10530. mixin(lodash, (function() {
  10531. var source = {};
  10532. baseForOwn(lodash, function(func, methodName) {
  10533. if (!lodash.prototype[methodName]) {
  10534. source[methodName] = func;
  10535. }
  10536. });
  10537. return source;
  10538. }()), false);
  10539. /*------------------------------------------------------------------------*/
  10540. // Add functions capable of returning wrapped and unwrapped values when chaining.
  10541. lodash.sample = sample;
  10542. lodash.prototype.sample = function(n) {
  10543. if (!this.__chain__ && n == null) {
  10544. return sample(this.value());
  10545. }
  10546. return this.thru(function(value) {
  10547. return sample(value, n);
  10548. });
  10549. };
  10550. /*------------------------------------------------------------------------*/
  10551. /**
  10552. * The semantic version number.
  10553. *
  10554. * @static
  10555. * @memberOf _
  10556. * @type string
  10557. */
  10558. lodash.VERSION = VERSION;
  10559. // Assign default placeholders.
  10560. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  10561. lodash[methodName].placeholder = lodash;
  10562. });
  10563. // Add `LazyWrapper` methods that accept an `iteratee` value.
  10564. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  10565. var isFilter = index == LAZY_FILTER_FLAG,
  10566. isWhile = index == LAZY_WHILE_FLAG;
  10567. LazyWrapper.prototype[methodName] = function(iteratee, thisArg) {
  10568. var result = this.clone(),
  10569. filtered = result.__filtered__,
  10570. iteratees = result.__iteratees__ || (result.__iteratees__ = []);
  10571. result.__filtered__ = filtered || isFilter || (isWhile && result.__dir__ < 0);
  10572. iteratees.push({ 'iteratee': getCallback(iteratee, thisArg, 3), 'type': index });
  10573. return result;
  10574. };
  10575. });
  10576. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  10577. arrayEach(['drop', 'take'], function(methodName, index) {
  10578. var countName = '__' + methodName + 'Count__',
  10579. whileName = methodName + 'While';
  10580. LazyWrapper.prototype[methodName] = function(n) {
  10581. n = n == null ? 1 : nativeMax(floor(n) || 0, 0);
  10582. var result = this.clone();
  10583. if (result.__filtered__) {
  10584. var value = result[countName];
  10585. result[countName] = index ? nativeMin(value, n) : (value + n);
  10586. } else {
  10587. var views = result.__views__ || (result.__views__ = []);
  10588. views.push({ 'size': n, 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') });
  10589. }
  10590. return result;
  10591. };
  10592. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  10593. return this.reverse()[methodName](n).reverse();
  10594. };
  10595. LazyWrapper.prototype[methodName + 'RightWhile'] = function(predicate, thisArg) {
  10596. return this.reverse()[whileName](predicate, thisArg).reverse();
  10597. };
  10598. });
  10599. // Add `LazyWrapper` methods for `_.first` and `_.last`.
  10600. arrayEach(['first', 'last'], function(methodName, index) {
  10601. var takeName = 'take' + (index ? 'Right' : '');
  10602. LazyWrapper.prototype[methodName] = function() {
  10603. return this[takeName](1).value()[0];
  10604. };
  10605. });
  10606. // Add `LazyWrapper` methods for `_.initial` and `_.rest`.
  10607. arrayEach(['initial', 'rest'], function(methodName, index) {
  10608. var dropName = 'drop' + (index ? '' : 'Right');
  10609. LazyWrapper.prototype[methodName] = function() {
  10610. return this[dropName](1);
  10611. };
  10612. });
  10613. // Add `LazyWrapper` methods for `_.pluck` and `_.where`.
  10614. arrayEach(['pluck', 'where'], function(methodName, index) {
  10615. var operationName = index ? 'filter' : 'map',
  10616. createCallback = index ? baseMatches : baseProperty;
  10617. LazyWrapper.prototype[methodName] = function(value) {
  10618. return this[operationName](createCallback(value));
  10619. };
  10620. });
  10621. LazyWrapper.prototype.compact = function() {
  10622. return this.filter(identity);
  10623. };
  10624. LazyWrapper.prototype.dropWhile = function(predicate, thisArg) {
  10625. var done;
  10626. predicate = getCallback(predicate, thisArg, 3);
  10627. return this.filter(function(value, index, array) {
  10628. return done || (done = !predicate(value, index, array));
  10629. });
  10630. };
  10631. LazyWrapper.prototype.reject = function(predicate, thisArg) {
  10632. predicate = getCallback(predicate, thisArg, 3);
  10633. return this.filter(function(value, index, array) {
  10634. return !predicate(value, index, array);
  10635. });
  10636. };
  10637. LazyWrapper.prototype.slice = function(start, end) {
  10638. start = start == null ? 0 : (+start || 0);
  10639. var result = start < 0 ? this.takeRight(-start) : this.drop(start);
  10640. if (typeof end != 'undefined') {
  10641. end = (+end || 0);
  10642. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  10643. }
  10644. return result;
  10645. };
  10646. LazyWrapper.prototype.toArray = function() {
  10647. return this.drop(0);
  10648. };
  10649. // Add `LazyWrapper` methods to `lodash.prototype`.
  10650. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  10651. var lodashFunc = lodash[methodName],
  10652. retUnwrapped = /^(?:first|last)$/.test(methodName);
  10653. lodash.prototype[methodName] = function() {
  10654. var value = this.__wrapped__,
  10655. args = arguments,
  10656. chainAll = this.__chain__,
  10657. isHybrid = !!this.__actions__.length,
  10658. isLazy = value instanceof LazyWrapper,
  10659. onlyLazy = isLazy && !isHybrid;
  10660. if (retUnwrapped && !chainAll) {
  10661. return onlyLazy
  10662. ? func.call(value)
  10663. : lodashFunc.call(lodash, this.value());
  10664. }
  10665. var interceptor = function(value) {
  10666. var otherArgs = [value];
  10667. push.apply(otherArgs, args);
  10668. return lodashFunc.apply(lodash, otherArgs);
  10669. };
  10670. if (isLazy || isArray(value)) {
  10671. var wrapper = onlyLazy ? value : new LazyWrapper(this),
  10672. result = func.apply(wrapper, args);
  10673. if (!retUnwrapped && (isHybrid || result.__actions__)) {
  10674. var actions = result.__actions__ || (result.__actions__ = []);
  10675. actions.push({ 'func': thru, 'args': [interceptor], 'thisArg': lodash });
  10676. }
  10677. return new LodashWrapper(result, chainAll);
  10678. }
  10679. return this.thru(interceptor);
  10680. };
  10681. });
  10682. // Add `Array.prototype` functions to `lodash.prototype`.
  10683. arrayEach(['concat', 'join', 'pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  10684. var func = arrayProto[methodName],
  10685. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  10686. retUnwrapped = /^(?:join|pop|shift)$/.test(methodName);
  10687. lodash.prototype[methodName] = function() {
  10688. var args = arguments;
  10689. if (retUnwrapped && !this.__chain__) {
  10690. return func.apply(this.value(), args);
  10691. }
  10692. return this[chainName](function(value) {
  10693. return func.apply(value, args);
  10694. });
  10695. };
  10696. });
  10697. // Add functions to the lazy wrapper.
  10698. LazyWrapper.prototype.clone = lazyClone;
  10699. LazyWrapper.prototype.reverse = lazyReverse;
  10700. LazyWrapper.prototype.value = lazyValue;
  10701. // Add chaining functions to the `lodash` wrapper.
  10702. lodash.prototype.chain = wrapperChain;
  10703. lodash.prototype.commit = wrapperCommit;
  10704. lodash.prototype.plant = wrapperPlant;
  10705. lodash.prototype.reverse = wrapperReverse;
  10706. lodash.prototype.toString = wrapperToString;
  10707. lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  10708. // Add function aliases to the `lodash` wrapper.
  10709. lodash.prototype.collect = lodash.prototype.map;
  10710. lodash.prototype.head = lodash.prototype.first;
  10711. lodash.prototype.select = lodash.prototype.filter;
  10712. lodash.prototype.tail = lodash.prototype.rest;
  10713. return lodash;
  10714. }
  10715. /*--------------------------------------------------------------------------*/
  10716. // Export lodash.
  10717. var _ = runInContext();
  10718. // Some AMD build optimizers like r.js check for condition patterns like the following:
  10719. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  10720. // Expose lodash to the global object when an AMD loader is present to avoid
  10721. // errors in cases where lodash is loaded by a script tag and not intended
  10722. // as an AMD module. See http://requirejs.org/docs/errors.html#mismatch for
  10723. // more details.
  10724. root._ = _;
  10725. // Define as an anonymous module so, through path mapping, it can be
  10726. // referenced as the "underscore" module.
  10727. define(function() {
  10728. return _;
  10729. });
  10730. }
  10731. // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
  10732. else if (freeExports && freeModule) {
  10733. // Export for Node.js or RingoJS.
  10734. if (moduleExports) {
  10735. (freeModule.exports = _)._ = _;
  10736. }
  10737. // Export for Narwhal or Rhino -require.
  10738. else {
  10739. freeExports._ = _;
  10740. }
  10741. }
  10742. else {
  10743. // Export for a browser or Rhino.
  10744. root._ = _;
  10745. }
  10746. }.call(this));