lodash.js 412 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597
  1. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. // For info about this version of lodash, see https://npmjs.com/package/@sailshq/lodash
  3. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  5. // Originally from https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js
  6. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  7. //
  8. // Patches:
  9. //
  10. // ### Wed Nov 2, 2016
  11. // I added a hotfix based on https://github.com/lodash/lodash/commit/95bc54a3ddc7a25f5e134f5b376a0d1d96118f49
  12. // in order to solve https://github.com/lodash/lodash/issues/2768.
  13. // -@mikermcneil
  14. //
  15. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  16. /**
  17. * @license
  18. * lodash 3.10.2 <https://github.com/sailshq/lodash>
  19. * A fork of Lodash 3.10.1 <https://lodash.com/> with minor patches made by Mike McNeil.
  20. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  21. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  22. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  23. * Available under MIT license <https://lodash.com/license>
  24. */
  25. ;(function() {
  26. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  27. var undefined;
  28. /** Used as the semantic version number. */
  29. var VERSION = '3.10.2';
  30. /** Used to compose bitmasks for wrapper metadata. */
  31. var BIND_FLAG = 1,
  32. BIND_KEY_FLAG = 2,
  33. CURRY_BOUND_FLAG = 4,
  34. CURRY_FLAG = 8,
  35. CURRY_RIGHT_FLAG = 16,
  36. PARTIAL_FLAG = 32,
  37. PARTIAL_RIGHT_FLAG = 64,
  38. ARY_FLAG = 128,
  39. REARG_FLAG = 256;
  40. /** Used as default options for `_.trunc`. */
  41. var DEFAULT_TRUNC_LENGTH = 30,
  42. DEFAULT_TRUNC_OMISSION = '...';
  43. /** Used to detect when a function becomes hot. */
  44. var HOT_COUNT = 150,
  45. HOT_SPAN = 16;
  46. /** Used as the size to enable large array optimizations. */
  47. var LARGE_ARRAY_SIZE = 200;
  48. /** Used to indicate the type of lazy iteratees. */
  49. var LAZY_FILTER_FLAG = 1,
  50. LAZY_MAP_FLAG = 2;
  51. /** Used as the `TypeError` message for "Functions" methods. */
  52. var FUNC_ERROR_TEXT = 'Expected a function';
  53. /** Used as the internal argument placeholder. */
  54. var PLACEHOLDER = '__lodash_placeholder__';
  55. /** `Object#toString` result references. */
  56. var argsTag = '[object Arguments]',
  57. arrayTag = '[object Array]',
  58. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  59. // Patched from https://github.com/lodash/lodash/blob/95bc54a3ddc7a25f5e134f5b376a0d1d96118f49/lodash.js#L86-L108
  60. asyncTag = '[object AsyncFunction]',
  61. genTag = '[object GeneratorFunction]',
  62. proxyTag = '[object Proxy]',
  63. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  64. boolTag = '[object Boolean]',
  65. dateTag = '[object Date]',
  66. errorTag = '[object Error]',
  67. funcTag = '[object Function]',
  68. mapTag = '[object Map]',
  69. numberTag = '[object Number]',
  70. objectTag = '[object Object]',
  71. regexpTag = '[object RegExp]',
  72. setTag = '[object Set]',
  73. stringTag = '[object String]',
  74. weakMapTag = '[object WeakMap]';
  75. var arrayBufferTag = '[object ArrayBuffer]',
  76. float32Tag = '[object Float32Array]',
  77. float64Tag = '[object Float64Array]',
  78. int8Tag = '[object Int8Array]',
  79. int16Tag = '[object Int16Array]',
  80. int32Tag = '[object Int32Array]',
  81. uint8Tag = '[object Uint8Array]',
  82. uint8ClampedTag = '[object Uint8ClampedArray]',
  83. uint16Tag = '[object Uint16Array]',
  84. uint32Tag = '[object Uint32Array]';
  85. /** Used to match empty string literals in compiled template source. */
  86. var reEmptyStringLeading = /\b__p \+= '';/g,
  87. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  88. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  89. /** Used to match HTML entities and HTML characters. */
  90. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
  91. reUnescapedHtml = /[&<>"'`]/g,
  92. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  93. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  94. /** Used to match template delimiters. */
  95. var reEscape = /<%-([\s\S]+?)%>/g,
  96. reEvaluate = /<%([\s\S]+?)%>/g,
  97. reInterpolate = /<%=([\s\S]+?)%>/g;
  98. /** Used to match property names within property paths. */
  99. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,
  100. reIsPlainProp = /^\w*$/,
  101. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
  102. /**
  103. * Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns)
  104. * and those outlined by [`EscapeRegExpPattern`](http://ecma-international.org/ecma-262/6.0/#sec-escaperegexppattern).
  105. */
  106. var reRegExpChars = /^[:!,]|[\\^$.*+?()[\]{}|\/]|(^[0-9a-fA-Fnrtuvx])|([\n\r\u2028\u2029])/g,
  107. reHasRegExpChars = RegExp(reRegExpChars.source);
  108. /** Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). */
  109. var reComboMark = /[\u0300-\u036f\ufe20-\ufe23]/g;
  110. /** Used to match backslashes in property paths. */
  111. var reEscapeChar = /\\(\\)?/g;
  112. /** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */
  113. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  114. /** Used to match `RegExp` flags from their coerced string values. */
  115. var reFlags = /\w*$/;
  116. /** Used to detect hexadecimal string values. */
  117. var reHasHexPrefix = /^0[xX]/;
  118. /** Used to detect host constructors (Safari > 5). */
  119. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  120. /** Used to detect unsigned integer values. */
  121. var reIsUint = /^\d+$/;
  122. /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
  123. var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
  124. /** Used to ensure capturing order of template delimiters. */
  125. var reNoMatch = /($^)/;
  126. /** Used to match unescaped characters in compiled string literals. */
  127. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  128. /** Used to match words to create compound words. */
  129. var reWords = (function() {
  130. var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]',
  131. lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
  132. return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
  133. }());
  134. /** Used to assign default `context` object properties. */
  135. var contextProps = [
  136. 'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
  137. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number',
  138. 'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'isFinite',
  139. 'parseFloat', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array',
  140. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap'
  141. ];
  142. /** Used to fix the JScript `[[DontEnum]]` bug. */
  143. var shadowProps = [
  144. 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
  145. 'toLocaleString', 'toString', 'valueOf'
  146. ];
  147. /** Used to make template sourceURLs easier to identify. */
  148. var templateCounter = -1;
  149. /** Used to identify `toStringTag` values of typed arrays. */
  150. var typedArrayTags = {};
  151. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  152. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  153. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  154. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  155. typedArrayTags[uint32Tag] = true;
  156. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  157. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  158. typedArrayTags[dateTag] = typedArrayTags[errorTag] =
  159. typedArrayTags[funcTag] = typedArrayTags[mapTag] =
  160. typedArrayTags[numberTag] = typedArrayTags[objectTag] =
  161. typedArrayTags[regexpTag] = typedArrayTags[setTag] =
  162. typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
  163. /** Used to identify `toStringTag` values supported by `_.clone`. */
  164. var cloneableTags = {};
  165. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  166. cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
  167. cloneableTags[dateTag] = cloneableTags[float32Tag] =
  168. cloneableTags[float64Tag] = cloneableTags[int8Tag] =
  169. cloneableTags[int16Tag] = cloneableTags[int32Tag] =
  170. cloneableTags[numberTag] = cloneableTags[objectTag] =
  171. cloneableTags[regexpTag] = cloneableTags[stringTag] =
  172. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  173. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  174. cloneableTags[errorTag] = cloneableTags[funcTag] =
  175. cloneableTags[mapTag] = cloneableTags[setTag] =
  176. cloneableTags[weakMapTag] = false;
  177. /** Used to map latin-1 supplementary letters to basic latin letters. */
  178. var deburredLetters = {
  179. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  180. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  181. '\xc7': 'C', '\xe7': 'c',
  182. '\xd0': 'D', '\xf0': 'd',
  183. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  184. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  185. '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  186. '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  187. '\xd1': 'N', '\xf1': 'n',
  188. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  189. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  190. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  191. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  192. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  193. '\xc6': 'Ae', '\xe6': 'ae',
  194. '\xde': 'Th', '\xfe': 'th',
  195. '\xdf': 'ss'
  196. };
  197. /** Used to map characters to HTML entities. */
  198. var htmlEscapes = {
  199. '&': '&amp;',
  200. '<': '&lt;',
  201. '>': '&gt;',
  202. '"': '&quot;',
  203. "'": '&#39;',
  204. '`': '&#96;'
  205. };
  206. /** Used to map HTML entities to characters. */
  207. var htmlUnescapes = {
  208. '&amp;': '&',
  209. '&lt;': '<',
  210. '&gt;': '>',
  211. '&quot;': '"',
  212. '&#39;': "'",
  213. '&#96;': '`'
  214. };
  215. /** Used to determine if values are of the language type `Object`. */
  216. var objectTypes = {
  217. 'function': true,
  218. 'object': true
  219. };
  220. /** Used to escape characters for inclusion in compiled regexes. */
  221. var regexpEscapes = {
  222. '0': 'x30', '1': 'x31', '2': 'x32', '3': 'x33', '4': 'x34',
  223. '5': 'x35', '6': 'x36', '7': 'x37', '8': 'x38', '9': 'x39',
  224. 'A': 'x41', 'B': 'x42', 'C': 'x43', 'D': 'x44', 'E': 'x45', 'F': 'x46',
  225. 'a': 'x61', 'b': 'x62', 'c': 'x63', 'd': 'x64', 'e': 'x65', 'f': 'x66',
  226. 'n': 'x6e', 'r': 'x72', 't': 'x74', 'u': 'x75', 'v': 'x76', 'x': 'x78'
  227. };
  228. /** Used to escape characters for inclusion in compiled string literals. */
  229. var stringEscapes = {
  230. '\\': '\\',
  231. "'": "'",
  232. '\n': 'n',
  233. '\r': 'r',
  234. '\u2028': 'u2028',
  235. '\u2029': 'u2029'
  236. };
  237. /** Detect free variable `exports`. */
  238. var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
  239. /** Detect free variable `module`. */
  240. var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
  241. /** Detect free variable `global` from Node.js. */
  242. var freeGlobal = freeExports && freeModule && typeof global == 'object' && global && global.Object && global;
  243. /** Detect free variable `self`. */
  244. var freeSelf = objectTypes[typeof self] && self && self.Object && self;
  245. /** Detect free variable `window`. */
  246. var freeWindow = objectTypes[typeof window] && window && window.Object && window;
  247. /** Detect the popular CommonJS extension `module.exports`. */
  248. var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
  249. /**
  250. * Used as a reference to the global object.
  251. *
  252. * The `this` value is used if it's the global object to avoid Greasemonkey's
  253. * restricted `window` object, otherwise the `window` object is used.
  254. */
  255. var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this;
  256. /*--------------------------------------------------------------------------*/
  257. /**
  258. * The base implementation of `compareAscending` which compares values and
  259. * sorts them in ascending order without guaranteeing a stable sort.
  260. *
  261. * @private
  262. * @param {*} value The value to compare.
  263. * @param {*} other The other value to compare.
  264. * @returns {number} Returns the sort order indicator for `value`.
  265. */
  266. function baseCompareAscending(value, other) {
  267. if (value !== other) {
  268. var valIsNull = value === null,
  269. valIsUndef = value === undefined,
  270. valIsReflexive = value === value;
  271. var othIsNull = other === null,
  272. othIsUndef = other === undefined,
  273. othIsReflexive = other === other;
  274. if ((value > other && !othIsNull) || !valIsReflexive ||
  275. (valIsNull && !othIsUndef && othIsReflexive) ||
  276. (valIsUndef && othIsReflexive)) {
  277. return 1;
  278. }
  279. if ((value < other && !valIsNull) || !othIsReflexive ||
  280. (othIsNull && !valIsUndef && valIsReflexive) ||
  281. (othIsUndef && valIsReflexive)) {
  282. return -1;
  283. }
  284. }
  285. return 0;
  286. }
  287. /**
  288. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  289. * support for callback shorthands and `this` binding.
  290. *
  291. * @private
  292. * @param {Array} array The array to search.
  293. * @param {Function} predicate The function invoked per iteration.
  294. * @param {boolean} [fromRight] Specify iterating from right to left.
  295. * @returns {number} Returns the index of the matched value, else `-1`.
  296. */
  297. function baseFindIndex(array, predicate, fromRight) {
  298. var length = array.length,
  299. index = fromRight ? length : -1;
  300. while ((fromRight ? index-- : ++index < length)) {
  301. if (predicate(array[index], index, array)) {
  302. return index;
  303. }
  304. }
  305. return -1;
  306. }
  307. /**
  308. * The base implementation of `_.indexOf` without support for binary searches.
  309. *
  310. * @private
  311. * @param {Array} array The array to search.
  312. * @param {*} value The value to search for.
  313. * @param {number} fromIndex The index to search from.
  314. * @returns {number} Returns the index of the matched value, else `-1`.
  315. */
  316. function baseIndexOf(array, value, fromIndex) {
  317. if (value !== value) {
  318. return indexOfNaN(array, fromIndex);
  319. }
  320. var index = fromIndex - 1,
  321. length = array.length;
  322. while (++index < length) {
  323. if (array[index] === value) {
  324. return index;
  325. }
  326. }
  327. return -1;
  328. }
  329. /**
  330. * The base implementation of `_.isFunction` without support for environments
  331. * with incorrect `typeof` results.
  332. *
  333. * @private
  334. * @param {*} value The value to check.
  335. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  336. */
  337. function baseIsFunction(value) {
  338. // Avoid a Chakra JIT bug in compatibility modes of IE 11.
  339. // See https://github.com/jashkenas/underscore/issues/1621 for more details.
  340. return typeof value == 'function' || false;
  341. }
  342. /**
  343. * Converts `value` to a string if it's not one. An empty string is returned
  344. * for `null` or `undefined` values.
  345. *
  346. * @private
  347. * @param {*} value The value to process.
  348. * @returns {string} Returns the string.
  349. */
  350. function baseToString(value) {
  351. return value == null ? '' : (value + '');
  352. }
  353. /**
  354. * Used by `_.trim` and `_.trimLeft` to get the index of the first character
  355. * of `string` that is not found in `chars`.
  356. *
  357. * @private
  358. * @param {string} string The string to inspect.
  359. * @param {string} chars The characters to find.
  360. * @returns {number} Returns the index of the first character not found in `chars`.
  361. */
  362. function charsLeftIndex(string, chars) {
  363. var index = -1,
  364. length = string.length;
  365. while (++index < length && chars.indexOf(string.charAt(index)) > -1) {}
  366. return index;
  367. }
  368. /**
  369. * Used by `_.trim` and `_.trimRight` to get the index of the last character
  370. * of `string` that is not found in `chars`.
  371. *
  372. * @private
  373. * @param {string} string The string to inspect.
  374. * @param {string} chars The characters to find.
  375. * @returns {number} Returns the index of the last character not found in `chars`.
  376. */
  377. function charsRightIndex(string, chars) {
  378. var index = string.length;
  379. while (index-- && chars.indexOf(string.charAt(index)) > -1) {}
  380. return index;
  381. }
  382. /**
  383. * Used by `_.sortBy` to compare transformed elements of a collection and stable
  384. * sort them in ascending order.
  385. *
  386. * @private
  387. * @param {Object} object The object to compare.
  388. * @param {Object} other The other object to compare.
  389. * @returns {number} Returns the sort order indicator for `object`.
  390. */
  391. function compareAscending(object, other) {
  392. return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index);
  393. }
  394. /**
  395. * Used by `_.sortByOrder` to compare multiple properties of a value to another
  396. * and stable sort them.
  397. *
  398. * If `orders` is unspecified, all valuess are sorted in ascending order. Otherwise,
  399. * a value is sorted in ascending order if its corresponding order is "asc", and
  400. * descending if "desc".
  401. *
  402. * @private
  403. * @param {Object} object The object to compare.
  404. * @param {Object} other The other object to compare.
  405. * @param {boolean[]} orders The order to sort by for each property.
  406. * @returns {number} Returns the sort order indicator for `object`.
  407. */
  408. function compareMultiple(object, other, orders) {
  409. var index = -1,
  410. objCriteria = object.criteria,
  411. othCriteria = other.criteria,
  412. length = objCriteria.length,
  413. ordersLength = orders.length;
  414. while (++index < length) {
  415. var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
  416. if (result) {
  417. if (index >= ordersLength) {
  418. return result;
  419. }
  420. var order = orders[index];
  421. return result * ((order === 'asc' || order === true) ? 1 : -1);
  422. }
  423. }
  424. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  425. // that causes it, under certain circumstances, to provide the same value for
  426. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  427. // for more details.
  428. //
  429. // This also ensures a stable sort in V8 and other engines.
  430. // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
  431. return object.index - other.index;
  432. }
  433. /**
  434. * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
  435. *
  436. * @private
  437. * @param {string} letter The matched letter to deburr.
  438. * @returns {string} Returns the deburred letter.
  439. */
  440. function deburrLetter(letter) {
  441. return deburredLetters[letter];
  442. }
  443. /**
  444. * Used by `_.escape` to convert characters to HTML entities.
  445. *
  446. * @private
  447. * @param {string} chr The matched character to escape.
  448. * @returns {string} Returns the escaped character.
  449. */
  450. function escapeHtmlChar(chr) {
  451. return htmlEscapes[chr];
  452. }
  453. /**
  454. * Used by `_.escapeRegExp` to escape characters for inclusion in compiled regexes.
  455. *
  456. * @private
  457. * @param {string} chr The matched character to escape.
  458. * @param {string} leadingChar The capture group for a leading character.
  459. * @param {string} whitespaceChar The capture group for a whitespace character.
  460. * @returns {string} Returns the escaped character.
  461. */
  462. function escapeRegExpChar(chr, leadingChar, whitespaceChar) {
  463. if (leadingChar) {
  464. chr = regexpEscapes[chr];
  465. } else if (whitespaceChar) {
  466. chr = stringEscapes[chr];
  467. }
  468. return '\\' + chr;
  469. }
  470. /**
  471. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  472. *
  473. * @private
  474. * @param {string} chr The matched character to escape.
  475. * @returns {string} Returns the escaped character.
  476. */
  477. function escapeStringChar(chr) {
  478. return '\\' + stringEscapes[chr];
  479. }
  480. /**
  481. * Gets the index at which the first occurrence of `NaN` is found in `array`.
  482. *
  483. * @private
  484. * @param {Array} array The array to search.
  485. * @param {number} fromIndex The index to search from.
  486. * @param {boolean} [fromRight] Specify iterating from right to left.
  487. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
  488. */
  489. function indexOfNaN(array, fromIndex, fromRight) {
  490. var length = array.length,
  491. index = fromIndex + (fromRight ? 0 : -1);
  492. while ((fromRight ? index-- : ++index < length)) {
  493. var other = array[index];
  494. if (other !== other) {
  495. return index;
  496. }
  497. }
  498. return -1;
  499. }
  500. /**
  501. * Checks if `value` is a host object in IE < 9.
  502. *
  503. * @private
  504. * @param {*} value The value to check.
  505. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  506. */
  507. var isHostObject = (function() {
  508. try {
  509. Object({ 'toString': 0 } + '');
  510. } catch(e) {
  511. return function() { return false; };
  512. }
  513. return function(value) {
  514. // IE < 9 presents many host objects as `Object` objects that can coerce
  515. // to strings despite having improperly defined `toString` methods.
  516. return typeof value.toString != 'function' && typeof (value + '') == 'string';
  517. };
  518. }());
  519. /**
  520. * Checks if `value` is object-like.
  521. *
  522. * @private
  523. * @param {*} value The value to check.
  524. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  525. */
  526. function isObjectLike(value) {
  527. return !!value && typeof value == 'object';
  528. }
  529. /**
  530. * Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
  531. * character code is whitespace.
  532. *
  533. * @private
  534. * @param {number} charCode The character code to inspect.
  535. * @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
  536. */
  537. function isSpace(charCode) {
  538. return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 ||
  539. (charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279)));
  540. }
  541. /**
  542. * Replaces all `placeholder` elements in `array` with an internal placeholder
  543. * and returns an array of their indexes.
  544. *
  545. * @private
  546. * @param {Array} array The array to modify.
  547. * @param {*} placeholder The placeholder to replace.
  548. * @returns {Array} Returns the new array of placeholder indexes.
  549. */
  550. function replaceHolders(array, placeholder) {
  551. var index = -1,
  552. length = array.length,
  553. resIndex = -1,
  554. result = [];
  555. while (++index < length) {
  556. if (array[index] === placeholder) {
  557. array[index] = PLACEHOLDER;
  558. result[++resIndex] = index;
  559. }
  560. }
  561. return result;
  562. }
  563. /**
  564. * An implementation of `_.uniq` optimized for sorted arrays without support
  565. * for callback shorthands and `this` binding.
  566. *
  567. * @private
  568. * @param {Array} array The array to inspect.
  569. * @param {Function} [iteratee] The function invoked per iteration.
  570. * @returns {Array} Returns the new duplicate free array.
  571. */
  572. function sortedUniq(array, iteratee) {
  573. var seen,
  574. index = -1,
  575. length = array.length,
  576. resIndex = -1,
  577. result = [];
  578. while (++index < length) {
  579. var value = array[index],
  580. computed = iteratee ? iteratee(value, index, array) : value;
  581. if (!index || seen !== computed) {
  582. seen = computed;
  583. result[++resIndex] = value;
  584. }
  585. }
  586. return result;
  587. }
  588. /**
  589. * Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
  590. * character of `string`.
  591. *
  592. * @private
  593. * @param {string} string The string to inspect.
  594. * @returns {number} Returns the index of the first non-whitespace character.
  595. */
  596. function trimmedLeftIndex(string) {
  597. var index = -1,
  598. length = string.length;
  599. while (++index < length && isSpace(string.charCodeAt(index))) {}
  600. return index;
  601. }
  602. /**
  603. * Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
  604. * character of `string`.
  605. *
  606. * @private
  607. * @param {string} string The string to inspect.
  608. * @returns {number} Returns the index of the last non-whitespace character.
  609. */
  610. function trimmedRightIndex(string) {
  611. var index = string.length;
  612. while (index-- && isSpace(string.charCodeAt(index))) {}
  613. return index;
  614. }
  615. /**
  616. * Used by `_.unescape` to convert HTML entities to characters.
  617. *
  618. * @private
  619. * @param {string} chr The matched character to unescape.
  620. * @returns {string} Returns the unescaped character.
  621. */
  622. function unescapeHtmlChar(chr) {
  623. return htmlUnescapes[chr];
  624. }
  625. /*--------------------------------------------------------------------------*/
  626. /**
  627. * Create a new pristine `lodash` function using the given `context` object.
  628. *
  629. * @static
  630. * @memberOf _
  631. * @category Utility
  632. * @param {Object} [context=root] The context object.
  633. * @returns {Function} Returns a new `lodash` function.
  634. * @example
  635. *
  636. * _.mixin({ 'foo': _.constant('foo') });
  637. *
  638. * var lodash = _.runInContext();
  639. * lodash.mixin({ 'bar': lodash.constant('bar') });
  640. *
  641. * _.isFunction(_.foo);
  642. * // => true
  643. * _.isFunction(_.bar);
  644. * // => false
  645. *
  646. * lodash.isFunction(lodash.foo);
  647. * // => false
  648. * lodash.isFunction(lodash.bar);
  649. * // => true
  650. *
  651. * // using `context` to mock `Date#getTime` use in `_.now`
  652. * var mock = _.runInContext({
  653. * 'Date': function() {
  654. * return { 'getTime': getTimeMock };
  655. * }
  656. * });
  657. *
  658. * // or creating a suped-up `defer` in Node.js
  659. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  660. */
  661. function runInContext(context) {
  662. // Avoid issues with some ES3 environments that attempt to use values, named
  663. // after built-in constructors like `Object`, for the creation of literals.
  664. // ES5 clears this up by stating that literals must use built-in constructors.
  665. // See https://es5.github.io/#x11.1.5 for more details.
  666. context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
  667. /** Native constructor references. */
  668. var Array = context.Array,
  669. Date = context.Date,
  670. Error = context.Error,
  671. Function = context.Function,
  672. Math = context.Math,
  673. Number = context.Number,
  674. Object = context.Object,
  675. RegExp = context.RegExp,
  676. String = context.String,
  677. TypeError = context.TypeError;
  678. /** Used for native method references. */
  679. var arrayProto = Array.prototype,
  680. errorProto = Error.prototype,
  681. objectProto = Object.prototype,
  682. stringProto = String.prototype;
  683. /** Used to resolve the decompiled source of functions. */
  684. var fnToString = Function.prototype.toString;
  685. /** Used to check objects for own properties. */
  686. var hasOwnProperty = objectProto.hasOwnProperty;
  687. /** Used to generate unique IDs. */
  688. var idCounter = 0;
  689. /**
  690. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  691. * of values.
  692. */
  693. var objToString = objectProto.toString;
  694. /** Used to restore the original `_` reference in `_.noConflict`. */
  695. var oldDash = root._;
  696. /** Used to detect if a method is native. */
  697. var reIsNative = RegExp('^' +
  698. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  699. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  700. );
  701. /** Native method references. */
  702. var ArrayBuffer = context.ArrayBuffer,
  703. clearTimeout = context.clearTimeout,
  704. parseFloat = context.parseFloat,
  705. pow = Math.pow,
  706. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  707. Set = getNative(context, 'Set'),
  708. setTimeout = context.setTimeout,
  709. splice = arrayProto.splice,
  710. Uint8Array = context.Uint8Array,
  711. WeakMap = getNative(context, 'WeakMap');
  712. /* Native method references for those with the same name as other `lodash` methods. */
  713. var nativeCeil = Math.ceil,
  714. nativeCreate = getNative(Object, 'create'),
  715. nativeFloor = Math.floor,
  716. nativeIsArray = getNative(Array, 'isArray'),
  717. nativeIsFinite = context.isFinite,
  718. nativeKeys = getNative(Object, 'keys'),
  719. nativeMax = Math.max,
  720. nativeMin = Math.min,
  721. nativeNow = getNative(Date, 'now'),
  722. nativeParseInt = context.parseInt,
  723. nativeRandom = Math.random;
  724. /** Used as references for `-Infinity` and `Infinity`. */
  725. var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
  726. POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
  727. /** Used as references for the maximum length and index of an array. */
  728. var MAX_ARRAY_LENGTH = 4294967295,
  729. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  730. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  731. /**
  732. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  733. * of an array-like value.
  734. */
  735. var MAX_SAFE_INTEGER = 9007199254740991;
  736. /** Used to store function metadata. */
  737. var metaMap = WeakMap && new WeakMap;
  738. /** Used to lookup unminified function names. */
  739. var realNames = {};
  740. /** Used to lookup a type array constructors by `toStringTag`. */
  741. var ctorByTag = {};
  742. ctorByTag[float32Tag] = context.Float32Array;
  743. ctorByTag[float64Tag] = context.Float64Array;
  744. ctorByTag[int8Tag] = context.Int8Array;
  745. ctorByTag[int16Tag] = context.Int16Array;
  746. ctorByTag[int32Tag] = context.Int32Array;
  747. ctorByTag[uint8Tag] = Uint8Array;
  748. ctorByTag[uint8ClampedTag] = context.Uint8ClampedArray;
  749. ctorByTag[uint16Tag] = context.Uint16Array;
  750. ctorByTag[uint32Tag] = context.Uint32Array;
  751. /** Used to avoid iterating over non-enumerable properties in IE < 9. */
  752. var nonEnumProps = {};
  753. nonEnumProps[arrayTag] = nonEnumProps[dateTag] = nonEnumProps[numberTag] = { 'constructor': true, 'toLocaleString': true, 'toString': true, 'valueOf': true };
  754. nonEnumProps[boolTag] = nonEnumProps[stringTag] = { 'constructor': true, 'toString': true, 'valueOf': true };
  755. nonEnumProps[errorTag] = nonEnumProps[funcTag] = nonEnumProps[regexpTag] = { 'constructor': true, 'toString': true };
  756. nonEnumProps[objectTag] = { 'constructor': true };
  757. arrayEach(shadowProps, function(key) {
  758. for (var tag in nonEnumProps) {
  759. if (hasOwnProperty.call(nonEnumProps, tag)) {
  760. var props = nonEnumProps[tag];
  761. props[key] = hasOwnProperty.call(props, key);
  762. }
  763. }
  764. });
  765. /*------------------------------------------------------------------------*/
  766. /**
  767. * Creates a `lodash` object which wraps `value` to enable implicit chaining.
  768. * Methods that operate on and return arrays, collections, and functions can
  769. * be chained together. Methods that retrieve a single value or may return a
  770. * primitive value will automatically end the chain returning the unwrapped
  771. * value. Explicit chaining may be enabled using `_.chain`. The execution of
  772. * chained methods is lazy, that is, execution is deferred until `_#value`
  773. * is implicitly or explicitly called.
  774. *
  775. * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
  776. * fusion is an optimization strategy which merge iteratee calls; this can help
  777. * to avoid the creation of intermediate data structures and greatly reduce the
  778. * number of iteratee executions.
  779. *
  780. * Chaining is supported in custom builds as long as the `_#value` method is
  781. * directly or indirectly included in the build.
  782. *
  783. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  784. *
  785. * The wrapper `Array` methods are:
  786. * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
  787. * `splice`, and `unshift`
  788. *
  789. * The wrapper `String` methods are:
  790. * `replace` and `split`
  791. *
  792. * The wrapper methods that support shortcut fusion are:
  793. * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
  794. * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
  795. * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
  796. * and `where`
  797. *
  798. * The chainable wrapper methods are:
  799. * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
  800. * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
  801. * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defaultsDeep`,
  802. * `defer`, `delay`, `difference`, `drop`, `dropRight`, `dropRightWhile`,
  803. * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`,
  804. * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
  805. * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
  806. * `invoke`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`,
  807. * `matchesProperty`, `memoize`, `merge`, `method`, `methodOf`, `mixin`,
  808. * `modArgs`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
  809. * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
  810. * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `restParam`,
  811. * `reverse`, `set`, `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`,
  812. * `sortByOrder`, `splice`, `spread`, `take`, `takeRight`, `takeRightWhile`,
  813. * `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
  814. * `transform`, `union`, `uniq`, `unshift`, `unzip`, `unzipWith`, `values`,
  815. * `valuesIn`, `where`, `without`, `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
  816. *
  817. * The wrapper methods that are **not** chainable by default are:
  818. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
  819. * `deburr`, `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`,
  820. * `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`,
  821. * `floor`, `get`, `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`,
  822. * `inRange`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
  823. * `isEmpty`, `isEqual`, `isError`, `isFinite` `isFunction`, `isMatch`,
  824. * `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`,
  825. * `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
  826. * `last`, `lastIndexOf`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
  827. * `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
  828. * `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
  829. * `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`,
  830. * `startsWith`, `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`,
  831. * `unescape`, `uniqueId`, `value`, and `words`
  832. *
  833. * The wrapper method `sample` will return a wrapped value when `n` is provided,
  834. * otherwise an unwrapped value is returned.
  835. *
  836. * @name _
  837. * @constructor
  838. * @category Chain
  839. * @param {*} value The value to wrap in a `lodash` instance.
  840. * @returns {Object} Returns the new `lodash` wrapper instance.
  841. * @example
  842. *
  843. * var wrapped = _([1, 2, 3]);
  844. *
  845. * // returns an unwrapped value
  846. * wrapped.reduce(function(total, n) {
  847. * return total + n;
  848. * });
  849. * // => 6
  850. *
  851. * // returns a wrapped value
  852. * var squares = wrapped.map(function(n) {
  853. * return n * n;
  854. * });
  855. *
  856. * _.isArray(squares);
  857. * // => false
  858. *
  859. * _.isArray(squares.value());
  860. * // => true
  861. */
  862. function lodash(value) {
  863. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  864. if (value instanceof LodashWrapper) {
  865. return value;
  866. }
  867. if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
  868. return wrapperClone(value);
  869. }
  870. }
  871. return new LodashWrapper(value);
  872. }
  873. /**
  874. * The function whose prototype all chaining wrappers inherit from.
  875. *
  876. * @private
  877. */
  878. function baseLodash() {
  879. // No operation performed.
  880. }
  881. /**
  882. * The base constructor for creating `lodash` wrapper objects.
  883. *
  884. * @private
  885. * @param {*} value The value to wrap.
  886. * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
  887. * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
  888. */
  889. function LodashWrapper(value, chainAll, actions) {
  890. this.__wrapped__ = value;
  891. this.__actions__ = actions || [];
  892. this.__chain__ = !!chainAll;
  893. }
  894. /**
  895. * An object environment feature flags.
  896. *
  897. * @static
  898. * @memberOf _
  899. * @type Object
  900. */
  901. var support = lodash.support = {};
  902. (function(x) {
  903. var Ctor = function() { this.x = x; },
  904. object = { '0': x, 'length': x },
  905. props = [];
  906. Ctor.prototype = { 'valueOf': x, 'y': x };
  907. for (var key in new Ctor) { props.push(key); }
  908. /**
  909. * Detect if `name` or `message` properties of `Error.prototype` are
  910. * enumerable by default (IE < 9, Safari < 5.1).
  911. *
  912. * @memberOf _.support
  913. * @type boolean
  914. */
  915. support.enumErrorProps = propertyIsEnumerable.call(errorProto, 'message') ||
  916. propertyIsEnumerable.call(errorProto, 'name');
  917. /**
  918. * Detect if `prototype` properties are enumerable by default.
  919. *
  920. * Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
  921. * (if the prototype or a property on the prototype has been set)
  922. * incorrectly set the `[[Enumerable]]` value of a function's `prototype`
  923. * property to `true`.
  924. *
  925. * @memberOf _.support
  926. * @type boolean
  927. */
  928. support.enumPrototypes = propertyIsEnumerable.call(Ctor, 'prototype');
  929. /**
  930. * Detect if properties shadowing those on `Object.prototype` are non-enumerable.
  931. *
  932. * In IE < 9 an object's own properties, shadowing non-enumerable ones,
  933. * are made non-enumerable as well (a.k.a the JScript `[[DontEnum]]` bug).
  934. *
  935. * @memberOf _.support
  936. * @type boolean
  937. */
  938. support.nonEnumShadows = !/valueOf/.test(props);
  939. /**
  940. * Detect if own properties are iterated after inherited properties (IE < 9).
  941. *
  942. * @memberOf _.support
  943. * @type boolean
  944. */
  945. support.ownLast = props[0] != 'x';
  946. /**
  947. * Detect if `Array#shift` and `Array#splice` augment array-like objects
  948. * correctly.
  949. *
  950. * Firefox < 10, compatibility modes of IE 8, and IE < 9 have buggy Array
  951. * `shift()` and `splice()` functions that fail to remove the last element,
  952. * `value[0]`, of array-like objects even though the "length" property is
  953. * set to `0`. The `shift()` method is buggy in compatibility modes of IE 8,
  954. * while `splice()` is buggy regardless of mode in IE < 9.
  955. *
  956. * @memberOf _.support
  957. * @type boolean
  958. */
  959. support.spliceObjects = (splice.call(object, 0, 1), !object[0]);
  960. /**
  961. * Detect lack of support for accessing string characters by index.
  962. *
  963. * IE < 8 can't access characters by index. IE 8 can only access characters
  964. * by index on string literals, not string objects.
  965. *
  966. * @memberOf _.support
  967. * @type boolean
  968. */
  969. support.unindexedChars = ('x'[0] + Object('x')[0]) != 'xx';
  970. }(1, 0));
  971. /**
  972. * By default, the template delimiters used by lodash are like those in
  973. * embedded Ruby (ERB). Change the following template settings to use
  974. * alternative delimiters.
  975. *
  976. * @static
  977. * @memberOf _
  978. * @type Object
  979. */
  980. lodash.templateSettings = {
  981. /**
  982. * Used to detect `data` property values to be HTML-escaped.
  983. *
  984. * @memberOf _.templateSettings
  985. * @type RegExp
  986. */
  987. 'escape': reEscape,
  988. /**
  989. * Used to detect code to be evaluated.
  990. *
  991. * @memberOf _.templateSettings
  992. * @type RegExp
  993. */
  994. 'evaluate': reEvaluate,
  995. /**
  996. * Used to detect `data` property values to inject.
  997. *
  998. * @memberOf _.templateSettings
  999. * @type RegExp
  1000. */
  1001. 'interpolate': reInterpolate,
  1002. /**
  1003. * Used to reference the data object in the template text.
  1004. *
  1005. * @memberOf _.templateSettings
  1006. * @type string
  1007. */
  1008. 'variable': '',
  1009. /**
  1010. * Used to import variables into the compiled template.
  1011. *
  1012. * @memberOf _.templateSettings
  1013. * @type Object
  1014. */
  1015. 'imports': {
  1016. /**
  1017. * A reference to the `lodash` function.
  1018. *
  1019. * @memberOf _.templateSettings.imports
  1020. * @type Function
  1021. */
  1022. '_': lodash
  1023. }
  1024. };
  1025. /*------------------------------------------------------------------------*/
  1026. /**
  1027. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1028. *
  1029. * @private
  1030. * @param {*} value The value to wrap.
  1031. */
  1032. function LazyWrapper(value) {
  1033. this.__wrapped__ = value;
  1034. this.__actions__ = [];
  1035. this.__dir__ = 1;
  1036. this.__filtered__ = false;
  1037. this.__iteratees__ = [];
  1038. this.__takeCount__ = POSITIVE_INFINITY;
  1039. this.__views__ = [];
  1040. }
  1041. /**
  1042. * Creates a clone of the lazy wrapper object.
  1043. *
  1044. * @private
  1045. * @name clone
  1046. * @memberOf LazyWrapper
  1047. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1048. */
  1049. function lazyClone() {
  1050. var result = new LazyWrapper(this.__wrapped__);
  1051. result.__actions__ = arrayCopy(this.__actions__);
  1052. result.__dir__ = this.__dir__;
  1053. result.__filtered__ = this.__filtered__;
  1054. result.__iteratees__ = arrayCopy(this.__iteratees__);
  1055. result.__takeCount__ = this.__takeCount__;
  1056. result.__views__ = arrayCopy(this.__views__);
  1057. return result;
  1058. }
  1059. /**
  1060. * Reverses the direction of lazy iteration.
  1061. *
  1062. * @private
  1063. * @name reverse
  1064. * @memberOf LazyWrapper
  1065. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1066. */
  1067. function lazyReverse() {
  1068. if (this.__filtered__) {
  1069. var result = new LazyWrapper(this);
  1070. result.__dir__ = -1;
  1071. result.__filtered__ = true;
  1072. } else {
  1073. result = this.clone();
  1074. result.__dir__ *= -1;
  1075. }
  1076. return result;
  1077. }
  1078. /**
  1079. * Extracts the unwrapped value from its lazy wrapper.
  1080. *
  1081. * @private
  1082. * @name value
  1083. * @memberOf LazyWrapper
  1084. * @returns {*} Returns the unwrapped value.
  1085. */
  1086. function lazyValue() {
  1087. var array = this.__wrapped__.value(),
  1088. dir = this.__dir__,
  1089. isArr = isArray(array),
  1090. isRight = dir < 0,
  1091. arrLength = isArr ? array.length : 0,
  1092. view = getView(0, arrLength, this.__views__),
  1093. start = view.start,
  1094. end = view.end,
  1095. length = end - start,
  1096. index = isRight ? end : (start - 1),
  1097. iteratees = this.__iteratees__,
  1098. iterLength = iteratees.length,
  1099. resIndex = 0,
  1100. takeCount = nativeMin(length, this.__takeCount__);
  1101. if (!isArr || arrLength < LARGE_ARRAY_SIZE || (arrLength == length && takeCount == length)) {
  1102. return baseWrapperValue(array, this.__actions__);
  1103. }
  1104. var result = [];
  1105. outer:
  1106. while (length-- && resIndex < takeCount) {
  1107. index += dir;
  1108. var iterIndex = -1,
  1109. value = array[index];
  1110. while (++iterIndex < iterLength) {
  1111. var data = iteratees[iterIndex],
  1112. iteratee = data.iteratee,
  1113. type = data.type,
  1114. computed = iteratee(value);
  1115. if (type == LAZY_MAP_FLAG) {
  1116. value = computed;
  1117. } else if (!computed) {
  1118. if (type == LAZY_FILTER_FLAG) {
  1119. continue outer;
  1120. } else {
  1121. break outer;
  1122. }
  1123. }
  1124. }
  1125. result[resIndex++] = value;
  1126. }
  1127. return result;
  1128. }
  1129. /*------------------------------------------------------------------------*/
  1130. /**
  1131. * Creates a cache object to store key/value pairs.
  1132. *
  1133. * @private
  1134. * @static
  1135. * @name Cache
  1136. * @memberOf _.memoize
  1137. */
  1138. function MapCache() {
  1139. this.__data__ = {};
  1140. }
  1141. /**
  1142. * Removes `key` and its value from the cache.
  1143. *
  1144. * @private
  1145. * @name delete
  1146. * @memberOf _.memoize.Cache
  1147. * @param {string} key The key of the value to remove.
  1148. * @returns {boolean} Returns `true` if the thing was removed successfully, else `false`.
  1149. */
  1150. function mapDelete(key) {
  1151. return this.has(key) && delete this.__data__[key];
  1152. }
  1153. /**
  1154. * Gets the cached value for `key`.
  1155. *
  1156. * @private
  1157. * @name get
  1158. * @memberOf _.memoize.Cache
  1159. * @param {string} key The key of the value to get.
  1160. * @returns {*} Returns the cached value.
  1161. */
  1162. function mapGet(key) {
  1163. return key == '__proto__' ? undefined : this.__data__[key];
  1164. }
  1165. /**
  1166. * Checks if a cached value for `key` exists.
  1167. *
  1168. * @private
  1169. * @name has
  1170. * @memberOf _.memoize.Cache
  1171. * @param {string} key The key of the thing to check.
  1172. * @returns {boolean} Returns `true` if an thing for `key` exists, else `false`.
  1173. */
  1174. function mapHas(key) {
  1175. return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
  1176. }
  1177. /**
  1178. * Sets `value` to `key` of the cache.
  1179. *
  1180. * @private
  1181. * @name set
  1182. * @memberOf _.memoize.Cache
  1183. * @param {string} key The key of the value to cache.
  1184. * @param {*} value The value to cache.
  1185. * @returns {Object} Returns the cache object.
  1186. */
  1187. function mapSet(key, value) {
  1188. if (key != '__proto__') {
  1189. this.__data__[key] = value;
  1190. }
  1191. return this;
  1192. }
  1193. /*------------------------------------------------------------------------*/
  1194. /**
  1195. *
  1196. * Creates a cache object to store unique values.
  1197. *
  1198. * @private
  1199. * @param {Array} [values] The values to cache.
  1200. */
  1201. function SetCache(values) {
  1202. var length = values ? values.length : 0;
  1203. this.data = { 'hash': nativeCreate(null), 'set': new Set };
  1204. while (length--) {
  1205. this.push(values[length]);
  1206. }
  1207. }
  1208. /**
  1209. * Checks if `value` is in `cache` mimicking the return signature of
  1210. * `_.indexOf` by returning `0` if the value is found, else `-1`.
  1211. *
  1212. * @private
  1213. * @param {Object} cache The cache to search.
  1214. * @param {*} value The value to search for.
  1215. * @returns {number} Returns `0` if `value` is found, else `-1`.
  1216. */
  1217. function cacheIndexOf(cache, value) {
  1218. var data = cache.data,
  1219. result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
  1220. return result ? 0 : -1;
  1221. }
  1222. /**
  1223. * Adds `value` to the cache.
  1224. *
  1225. * @private
  1226. * @name push
  1227. * @memberOf SetCache
  1228. * @param {*} value The value to cache.
  1229. */
  1230. function cachePush(value) {
  1231. var data = this.data;
  1232. if (typeof value == 'string' || isObject(value)) {
  1233. data.set.add(value);
  1234. } else {
  1235. data.hash[value] = true;
  1236. }
  1237. }
  1238. /*------------------------------------------------------------------------*/
  1239. /**
  1240. * Creates a new array joining `array` with `other`.
  1241. *
  1242. * @private
  1243. * @param {Array} array The array to join.
  1244. * @param {Array} other The other array to join.
  1245. * @returns {Array} Returns the new concatenated array.
  1246. */
  1247. function arrayConcat(array, other) {
  1248. var index = -1,
  1249. length = array.length,
  1250. othIndex = -1,
  1251. othLength = other.length,
  1252. result = Array(length + othLength);
  1253. while (++index < length) {
  1254. result[index] = array[index];
  1255. }
  1256. while (++othIndex < othLength) {
  1257. result[index++] = other[othIndex];
  1258. }
  1259. return result;
  1260. }
  1261. /**
  1262. * Copies the values of `source` to `array`.
  1263. *
  1264. * @private
  1265. * @param {Array} source The array to copy values from.
  1266. * @param {Array} [array=[]] The array to copy values to.
  1267. * @returns {Array} Returns `array`.
  1268. */
  1269. function arrayCopy(source, array) {
  1270. var index = -1,
  1271. length = source.length;
  1272. array || (array = Array(length));
  1273. while (++index < length) {
  1274. array[index] = source[index];
  1275. }
  1276. return array;
  1277. }
  1278. /**
  1279. * A specialized version of `_.forEach` for arrays without support for callback
  1280. * shorthands and `this` binding.
  1281. *
  1282. * @private
  1283. * @param {Array} array The array to iterate over.
  1284. * @param {Function} iteratee The function invoked per iteration.
  1285. * @returns {Array} Returns `array`.
  1286. */
  1287. function arrayEach(array, iteratee) {
  1288. var index = -1,
  1289. length = array.length;
  1290. while (++index < length) {
  1291. if (iteratee(array[index], index, array) === false) {
  1292. break;
  1293. }
  1294. }
  1295. return array;
  1296. }
  1297. /**
  1298. * A specialized version of `_.forEachRight` for arrays without support for
  1299. * callback shorthands and `this` binding.
  1300. *
  1301. * @private
  1302. * @param {Array} array The array to iterate over.
  1303. * @param {Function} iteratee The function invoked per iteration.
  1304. * @returns {Array} Returns `array`.
  1305. */
  1306. function arrayEachRight(array, iteratee) {
  1307. var length = array.length;
  1308. while (length--) {
  1309. if (iteratee(array[length], length, array) === false) {
  1310. break;
  1311. }
  1312. }
  1313. return array;
  1314. }
  1315. /**
  1316. * A specialized version of `_.every` for arrays without support for callback
  1317. * shorthands and `this` binding.
  1318. *
  1319. * @private
  1320. * @param {Array} array The array to iterate over.
  1321. * @param {Function} predicate The function invoked per iteration.
  1322. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  1323. * else `false`.
  1324. */
  1325. function arrayEvery(array, predicate) {
  1326. var index = -1,
  1327. length = array.length;
  1328. while (++index < length) {
  1329. if (!predicate(array[index], index, array)) {
  1330. return false;
  1331. }
  1332. }
  1333. return true;
  1334. }
  1335. /**
  1336. * A specialized version of `baseExtremum` for arrays which invokes `iteratee`
  1337. * with one argument: (value).
  1338. *
  1339. * @private
  1340. * @param {Array} array The array to iterate over.
  1341. * @param {Function} iteratee The function invoked per iteration.
  1342. * @param {Function} comparator The function used to compare values.
  1343. * @param {*} exValue The initial extremum value.
  1344. * @returns {*} Returns the extremum value.
  1345. */
  1346. function arrayExtremum(array, iteratee, comparator, exValue) {
  1347. var index = -1,
  1348. length = array.length,
  1349. computed = exValue,
  1350. result = computed;
  1351. while (++index < length) {
  1352. var value = array[index],
  1353. current = +iteratee(value);
  1354. if (comparator(current, computed)) {
  1355. computed = current;
  1356. result = value;
  1357. }
  1358. }
  1359. return result;
  1360. }
  1361. /**
  1362. * A specialized version of `_.filter` for arrays without support for callback
  1363. * shorthands and `this` binding.
  1364. *
  1365. * @private
  1366. * @param {Array} array The array to iterate over.
  1367. * @param {Function} predicate The function invoked per iteration.
  1368. * @returns {Array} Returns the new filtered array.
  1369. */
  1370. function arrayFilter(array, predicate) {
  1371. var index = -1,
  1372. length = array.length,
  1373. resIndex = -1,
  1374. result = [];
  1375. while (++index < length) {
  1376. var value = array[index];
  1377. if (predicate(value, index, array)) {
  1378. result[++resIndex] = value;
  1379. }
  1380. }
  1381. return result;
  1382. }
  1383. /**
  1384. * A specialized version of `_.map` for arrays without support for callback
  1385. * shorthands and `this` binding.
  1386. *
  1387. * @private
  1388. * @param {Array} array The array to iterate over.
  1389. * @param {Function} iteratee The function invoked per iteration.
  1390. * @returns {Array} Returns the new mapped array.
  1391. */
  1392. function arrayMap(array, iteratee) {
  1393. var index = -1,
  1394. length = array.length,
  1395. result = Array(length);
  1396. while (++index < length) {
  1397. result[index] = iteratee(array[index], index, array);
  1398. }
  1399. return result;
  1400. }
  1401. /**
  1402. * Appends the elements of `values` to `array`.
  1403. *
  1404. * @private
  1405. * @param {Array} array The array to modify.
  1406. * @param {Array} values The values to append.
  1407. * @returns {Array} Returns `array`.
  1408. */
  1409. function arrayPush(array, values) {
  1410. var index = -1,
  1411. length = values.length,
  1412. offset = array.length;
  1413. while (++index < length) {
  1414. array[offset + index] = values[index];
  1415. }
  1416. return array;
  1417. }
  1418. /**
  1419. * A specialized version of `_.reduce` for arrays without support for callback
  1420. * shorthands and `this` binding.
  1421. *
  1422. * @private
  1423. * @param {Array} array The array to iterate over.
  1424. * @param {Function} iteratee The function invoked per iteration.
  1425. * @param {*} [accumulator] The initial value.
  1426. * @param {boolean} [initFromArray] Specify using the first element of `array`
  1427. * as the initial value.
  1428. * @returns {*} Returns the accumulated value.
  1429. */
  1430. function arrayReduce(array, iteratee, accumulator, initFromArray) {
  1431. var index = -1,
  1432. length = array.length;
  1433. if (initFromArray && length) {
  1434. accumulator = array[++index];
  1435. }
  1436. while (++index < length) {
  1437. accumulator = iteratee(accumulator, array[index], index, array);
  1438. }
  1439. return accumulator;
  1440. }
  1441. /**
  1442. * A specialized version of `_.reduceRight` for arrays without support for
  1443. * callback shorthands and `this` binding.
  1444. *
  1445. * @private
  1446. * @param {Array} array The array to iterate over.
  1447. * @param {Function} iteratee The function invoked per iteration.
  1448. * @param {*} [accumulator] The initial value.
  1449. * @param {boolean} [initFromArray] Specify using the last element of `array`
  1450. * as the initial value.
  1451. * @returns {*} Returns the accumulated value.
  1452. */
  1453. function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
  1454. var length = array.length;
  1455. if (initFromArray && length) {
  1456. accumulator = array[--length];
  1457. }
  1458. while (length--) {
  1459. accumulator = iteratee(accumulator, array[length], length, array);
  1460. }
  1461. return accumulator;
  1462. }
  1463. /**
  1464. * A specialized version of `_.some` for arrays without support for callback
  1465. * shorthands and `this` binding.
  1466. *
  1467. * @private
  1468. * @param {Array} array The array to iterate over.
  1469. * @param {Function} predicate The function invoked per iteration.
  1470. * @returns {boolean} Returns `true` if any element passes the predicate check,
  1471. * else `false`.
  1472. */
  1473. function arraySome(array, predicate) {
  1474. var index = -1,
  1475. length = array.length;
  1476. while (++index < length) {
  1477. if (predicate(array[index], index, array)) {
  1478. return true;
  1479. }
  1480. }
  1481. return false;
  1482. }
  1483. /**
  1484. * A specialized version of `_.sum` for arrays without support for callback
  1485. * shorthands and `this` binding..
  1486. *
  1487. * @private
  1488. * @param {Array} array The array to iterate over.
  1489. * @param {Function} iteratee The function invoked per iteration.
  1490. * @returns {number} Returns the sum.
  1491. */
  1492. function arraySum(array, iteratee) {
  1493. var length = array.length,
  1494. result = 0;
  1495. while (length--) {
  1496. result += +iteratee(array[length]) || 0;
  1497. }
  1498. return result;
  1499. }
  1500. /**
  1501. * Used by `_.defaults` to customize its `_.assign` use.
  1502. *
  1503. * @private
  1504. * @param {*} objectValue The destination object property value.
  1505. * @param {*} sourceValue The source object property value.
  1506. * @returns {*} Returns the value to assign to the destination object.
  1507. */
  1508. function assignDefaults(objectValue, sourceValue) {
  1509. return objectValue === undefined ? sourceValue : objectValue;
  1510. }
  1511. /**
  1512. * Used by `_.template` to customize its `_.assign` use.
  1513. *
  1514. * **Note:** This function is like `assignDefaults` except that it ignores
  1515. * inherited property values when checking if a property is `undefined`.
  1516. *
  1517. * @private
  1518. * @param {*} objectValue The destination object property value.
  1519. * @param {*} sourceValue The source object property value.
  1520. * @param {string} key The key associated with the object and source values.
  1521. * @param {Object} object The destination object.
  1522. * @returns {*} Returns the value to assign to the destination object.
  1523. */
  1524. function assignOwnDefaults(objectValue, sourceValue, key, object) {
  1525. return (objectValue === undefined || !hasOwnProperty.call(object, key))
  1526. ? sourceValue
  1527. : objectValue;
  1528. }
  1529. /**
  1530. * A specialized version of `_.assign` for customizing assigned values without
  1531. * support for argument juggling, multiple sources, and `this` binding `customizer`
  1532. * functions.
  1533. *
  1534. * @private
  1535. * @param {Object} object The destination object.
  1536. * @param {Object} source The source object.
  1537. * @param {Function} customizer The function to customize assigned values.
  1538. * @returns {Object} Returns `object`.
  1539. */
  1540. function assignWith(object, source, customizer) {
  1541. var index = -1,
  1542. props = keys(source),
  1543. length = props.length;
  1544. while (++index < length) {
  1545. var key = props[index],
  1546. value = object[key],
  1547. result = customizer(value, source[key], key, object, source);
  1548. if ((result === result ? (result !== value) : (value === value)) ||
  1549. (value === undefined && !(key in object))) {
  1550. object[key] = result;
  1551. }
  1552. }
  1553. return object;
  1554. }
  1555. /**
  1556. * The base implementation of `_.assign` without support for argument juggling,
  1557. * multiple sources, and `customizer` functions.
  1558. *
  1559. * @private
  1560. * @param {Object} object The destination object.
  1561. * @param {Object} source The source object.
  1562. * @returns {Object} Returns `object`.
  1563. */
  1564. function baseAssign(object, source) {
  1565. return source == null
  1566. ? object
  1567. : baseCopy(source, keys(source), object);
  1568. }
  1569. /**
  1570. * The base implementation of `_.at` without support for string collections
  1571. * and individual key arguments.
  1572. *
  1573. * @private
  1574. * @param {Array|Object} collection The collection to iterate over.
  1575. * @param {number[]|string[]} props The property names or indexes of elements to pick.
  1576. * @returns {Array} Returns the new array of picked elements.
  1577. */
  1578. function baseAt(collection, props) {
  1579. var index = -1,
  1580. isNil = collection == null,
  1581. isArr = !isNil && isArrayLike(collection),
  1582. length = isArr ? collection.length : 0,
  1583. propsLength = props.length,
  1584. result = Array(propsLength);
  1585. while(++index < propsLength) {
  1586. var key = props[index];
  1587. if (isArr) {
  1588. result[index] = isIndex(key, length) ? collection[key] : undefined;
  1589. } else {
  1590. result[index] = isNil ? undefined : collection[key];
  1591. }
  1592. }
  1593. return result;
  1594. }
  1595. /**
  1596. * Copies properties of `source` to `object`.
  1597. *
  1598. * @private
  1599. * @param {Object} source The object to copy properties from.
  1600. * @param {Array} props The property names to copy.
  1601. * @param {Object} [object={}] The object to copy properties to.
  1602. * @returns {Object} Returns `object`.
  1603. */
  1604. function baseCopy(source, props, object) {
  1605. object || (object = {});
  1606. var index = -1,
  1607. length = props.length;
  1608. while (++index < length) {
  1609. var key = props[index];
  1610. object[key] = source[key];
  1611. }
  1612. return object;
  1613. }
  1614. /**
  1615. * The base implementation of `_.callback` which supports specifying the
  1616. * number of arguments to provide to `func`.
  1617. *
  1618. * @private
  1619. * @param {*} [func=_.identity] The value to convert to a callback.
  1620. * @param {*} [thisArg] The `this` binding of `func`.
  1621. * @param {number} [argCount] The number of arguments to provide to `func`.
  1622. * @returns {Function} Returns the callback.
  1623. */
  1624. function baseCallback(func, thisArg, argCount) {
  1625. var type = typeof func;
  1626. if (type == 'function') {
  1627. return thisArg === undefined
  1628. ? func
  1629. : bindCallback(func, thisArg, argCount);
  1630. }
  1631. if (func == null) {
  1632. return identity;
  1633. }
  1634. if (type == 'object') {
  1635. return baseMatches(func);
  1636. }
  1637. return thisArg === undefined
  1638. ? property(func)
  1639. : baseMatchesProperty(func, thisArg);
  1640. }
  1641. /**
  1642. * The base implementation of `_.clone` without support for argument juggling
  1643. * and `this` binding `customizer` functions.
  1644. *
  1645. * @private
  1646. * @param {*} value The value to clone.
  1647. * @param {boolean} [isDeep] Specify a deep clone.
  1648. * @param {Function} [customizer] The function to customize cloning values.
  1649. * @param {string} [key] The key of `value`.
  1650. * @param {Object} [object] The object `value` belongs to.
  1651. * @param {Array} [stackA=[]] Tracks traversed source objects.
  1652. * @param {Array} [stackB=[]] Associates clones with source counterparts.
  1653. * @returns {*} Returns the cloned value.
  1654. */
  1655. function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
  1656. var result;
  1657. if (customizer) {
  1658. result = object ? customizer(value, key, object) : customizer(value);
  1659. }
  1660. if (result !== undefined) {
  1661. return result;
  1662. }
  1663. if (!isObject(value)) {
  1664. return value;
  1665. }
  1666. var isArr = isArray(value);
  1667. if (isArr) {
  1668. result = initCloneArray(value);
  1669. if (!isDeep) {
  1670. return arrayCopy(value, result);
  1671. }
  1672. } else {
  1673. var tag = objToString.call(value),
  1674. isFunc = tag == funcTag;
  1675. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  1676. if (isHostObject(value)) {
  1677. return object ? value : {};
  1678. }
  1679. result = initCloneObject(isFunc ? {} : value);
  1680. if (!isDeep) {
  1681. return baseAssign(result, value);
  1682. }
  1683. } else {
  1684. return cloneableTags[tag]
  1685. ? initCloneByTag(value, tag, isDeep)
  1686. : (object ? value : {});
  1687. }
  1688. }
  1689. // Check for circular references and return its corresponding clone.
  1690. stackA || (stackA = []);
  1691. stackB || (stackB = []);
  1692. var length = stackA.length;
  1693. while (length--) {
  1694. if (stackA[length] == value) {
  1695. return stackB[length];
  1696. }
  1697. }
  1698. // Add the source value to the stack of traversed objects and associate it with its clone.
  1699. stackA.push(value);
  1700. stackB.push(result);
  1701. // Recursively populate clone (susceptible to call stack limits).
  1702. (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
  1703. result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB);
  1704. });
  1705. return result;
  1706. }
  1707. /**
  1708. * The base implementation of `_.create` without support for assigning
  1709. * properties to the created object.
  1710. *
  1711. * @private
  1712. * @param {Object} prototype The object to inherit from.
  1713. * @returns {Object} Returns the new object.
  1714. */
  1715. var baseCreate = (function() {
  1716. function object() {}
  1717. return function(prototype) {
  1718. if (isObject(prototype)) {
  1719. object.prototype = prototype;
  1720. var result = new object;
  1721. object.prototype = undefined;
  1722. }
  1723. return result || {};
  1724. };
  1725. }());
  1726. /**
  1727. * The base implementation of `_.delay` and `_.defer` which accepts an index
  1728. * of where to slice the arguments to provide to `func`.
  1729. *
  1730. * @private
  1731. * @param {Function} func The function to delay.
  1732. * @param {number} wait The number of milliseconds to delay invocation.
  1733. * @param {Object} args The arguments provide to `func`.
  1734. * @returns {number} Returns the timer id.
  1735. */
  1736. function baseDelay(func, wait, args) {
  1737. if (typeof func != 'function') {
  1738. throw new TypeError(FUNC_ERROR_TEXT);
  1739. }
  1740. return setTimeout(function() { func.apply(undefined, args); }, wait);
  1741. }
  1742. /**
  1743. * The base implementation of `_.difference` which accepts a single array
  1744. * of values to exclude.
  1745. *
  1746. * @private
  1747. * @param {Array} array The array to inspect.
  1748. * @param {Array} values The values to exclude.
  1749. * @returns {Array} Returns the new array of filtered values.
  1750. */
  1751. function baseDifference(array, values) {
  1752. var length = array ? array.length : 0,
  1753. result = [];
  1754. if (!length) {
  1755. return result;
  1756. }
  1757. var index = -1,
  1758. indexOf = getIndexOf(),
  1759. isCommon = indexOf === baseIndexOf,
  1760. cache = (isCommon && values.length >= LARGE_ARRAY_SIZE) ? createCache(values) : null,
  1761. valuesLength = values.length;
  1762. if (cache) {
  1763. indexOf = cacheIndexOf;
  1764. isCommon = false;
  1765. values = cache;
  1766. }
  1767. outer:
  1768. while (++index < length) {
  1769. var value = array[index];
  1770. if (isCommon && value === value) {
  1771. var valuesIndex = valuesLength;
  1772. while (valuesIndex--) {
  1773. if (values[valuesIndex] === value) {
  1774. continue outer;
  1775. }
  1776. }
  1777. result.push(value);
  1778. }
  1779. else if (indexOf(values, value, 0) < 0) {
  1780. result.push(value);
  1781. }
  1782. }
  1783. return result;
  1784. }
  1785. /**
  1786. * The base implementation of `_.forEach` without support for callback
  1787. * shorthands and `this` binding.
  1788. *
  1789. * @private
  1790. * @param {Array|Object|string} collection The collection to iterate over.
  1791. * @param {Function} iteratee The function invoked per iteration.
  1792. * @returns {Array|Object|string} Returns `collection`.
  1793. */
  1794. var baseEach = createBaseEach(baseForOwn);
  1795. /**
  1796. * The base implementation of `_.forEachRight` without support for callback
  1797. * shorthands and `this` binding.
  1798. *
  1799. * @private
  1800. * @param {Array|Object|string} collection The collection to iterate over.
  1801. * @param {Function} iteratee The function invoked per iteration.
  1802. * @returns {Array|Object|string} Returns `collection`.
  1803. */
  1804. var baseEachRight = createBaseEach(baseForOwnRight, true);
  1805. /**
  1806. * The base implementation of `_.every` without support for callback
  1807. * shorthands and `this` binding.
  1808. *
  1809. * @private
  1810. * @param {Array|Object|string} collection The collection to iterate over.
  1811. * @param {Function} predicate The function invoked per iteration.
  1812. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  1813. * else `false`
  1814. */
  1815. function baseEvery(collection, predicate) {
  1816. var result = true;
  1817. baseEach(collection, function(value, index, collection) {
  1818. result = !!predicate(value, index, collection);
  1819. return result;
  1820. });
  1821. return result;
  1822. }
  1823. /**
  1824. * Gets the extremum value of `collection` invoking `iteratee` for each value
  1825. * in `collection` to generate the criterion by which the value is ranked.
  1826. * The `iteratee` is invoked with three arguments: (value, index|key, collection).
  1827. *
  1828. * @private
  1829. * @param {Array|Object|string} collection The collection to iterate over.
  1830. * @param {Function} iteratee The function invoked per iteration.
  1831. * @param {Function} comparator The function used to compare values.
  1832. * @param {*} exValue The initial extremum value.
  1833. * @returns {*} Returns the extremum value.
  1834. */
  1835. function baseExtremum(collection, iteratee, comparator, exValue) {
  1836. var computed = exValue,
  1837. result = computed;
  1838. baseEach(collection, function(value, index, collection) {
  1839. var current = +iteratee(value, index, collection);
  1840. if (comparator(current, computed) || (current === exValue && current === result)) {
  1841. computed = current;
  1842. result = value;
  1843. }
  1844. });
  1845. return result;
  1846. }
  1847. /**
  1848. * The base implementation of `_.fill` without an iteratee call guard.
  1849. *
  1850. * @private
  1851. * @param {Array} array The array to fill.
  1852. * @param {*} value The value to fill `array` with.
  1853. * @param {number} [start=0] The start position.
  1854. * @param {number} [end=array.length] The end position.
  1855. * @returns {Array} Returns `array`.
  1856. */
  1857. function baseFill(array, value, start, end) {
  1858. var length = array.length;
  1859. start = start == null ? 0 : (+start || 0);
  1860. if (start < 0) {
  1861. start = -start > length ? 0 : (length + start);
  1862. }
  1863. end = (end === undefined || end > length) ? length : (+end || 0);
  1864. if (end < 0) {
  1865. end += length;
  1866. }
  1867. length = start > end ? 0 : (end >>> 0);
  1868. start >>>= 0;
  1869. while (start < length) {
  1870. array[start++] = value;
  1871. }
  1872. return array;
  1873. }
  1874. /**
  1875. * The base implementation of `_.filter` without support for callback
  1876. * shorthands and `this` binding.
  1877. *
  1878. * @private
  1879. * @param {Array|Object|string} collection The collection to iterate over.
  1880. * @param {Function} predicate The function invoked per iteration.
  1881. * @returns {Array} Returns the new filtered array.
  1882. */
  1883. function baseFilter(collection, predicate) {
  1884. var result = [];
  1885. baseEach(collection, function(value, index, collection) {
  1886. if (predicate(value, index, collection)) {
  1887. result.push(value);
  1888. }
  1889. });
  1890. return result;
  1891. }
  1892. /**
  1893. * The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.findLastKey`,
  1894. * without support for callback shorthands and `this` binding, which iterates
  1895. * over `collection` using the provided `eachFunc`.
  1896. *
  1897. * @private
  1898. * @param {Array|Object|string} collection The collection to search.
  1899. * @param {Function} predicate The function invoked per iteration.
  1900. * @param {Function} eachFunc The function to iterate over `collection`.
  1901. * @param {boolean} [retKey] Specify returning the key of the found element
  1902. * instead of the element itself.
  1903. * @returns {*} Returns the found element or its key, else `undefined`.
  1904. */
  1905. function baseFind(collection, predicate, eachFunc, retKey) {
  1906. var result;
  1907. eachFunc(collection, function(value, key, collection) {
  1908. if (predicate(value, key, collection)) {
  1909. result = retKey ? key : value;
  1910. return false;
  1911. }
  1912. });
  1913. return result;
  1914. }
  1915. /**
  1916. * The base implementation of `_.flatten` with added support for restricting
  1917. * flattening and specifying the start index.
  1918. *
  1919. * @private
  1920. * @param {Array} array The array to flatten.
  1921. * @param {boolean} [isDeep] Specify a deep flatten.
  1922. * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
  1923. * @param {Array} [result=[]] The initial result value.
  1924. * @returns {Array} Returns the new flattened array.
  1925. */
  1926. function baseFlatten(array, isDeep, isStrict, result) {
  1927. result || (result = []);
  1928. var index = -1,
  1929. length = array.length;
  1930. while (++index < length) {
  1931. var value = array[index];
  1932. if (isObjectLike(value) && isArrayLike(value) &&
  1933. (isStrict || isArray(value) || isArguments(value))) {
  1934. if (isDeep) {
  1935. // Recursively flatten arrays (susceptible to call stack limits).
  1936. baseFlatten(value, isDeep, isStrict, result);
  1937. } else {
  1938. arrayPush(result, value);
  1939. }
  1940. } else if (!isStrict) {
  1941. result[result.length] = value;
  1942. }
  1943. }
  1944. return result;
  1945. }
  1946. /**
  1947. * The base implementation of `baseForIn` and `baseForOwn` which iterates
  1948. * over `object` properties returned by `keysFunc` invoking `iteratee` for
  1949. * each property. Iteratee functions may exit iteration early by explicitly
  1950. * returning `false`.
  1951. *
  1952. * @private
  1953. * @param {Object} object The object to iterate over.
  1954. * @param {Function} iteratee The function invoked per iteration.
  1955. * @param {Function} keysFunc The function to get the keys of `object`.
  1956. * @returns {Object} Returns `object`.
  1957. */
  1958. var baseFor = createBaseFor();
  1959. /**
  1960. * This function is like `baseFor` except that it iterates over properties
  1961. * in the opposite order.
  1962. *
  1963. * @private
  1964. * @param {Object} object The object to iterate over.
  1965. * @param {Function} iteratee The function invoked per iteration.
  1966. * @param {Function} keysFunc The function to get the keys of `object`.
  1967. * @returns {Object} Returns `object`.
  1968. */
  1969. var baseForRight = createBaseFor(true);
  1970. /**
  1971. * The base implementation of `_.forIn` without support for callback
  1972. * shorthands and `this` binding.
  1973. *
  1974. * @private
  1975. * @param {Object} object The object to iterate over.
  1976. * @param {Function} iteratee The function invoked per iteration.
  1977. * @returns {Object} Returns `object`.
  1978. */
  1979. function baseForIn(object, iteratee) {
  1980. return baseFor(object, iteratee, keysIn);
  1981. }
  1982. /**
  1983. * The base implementation of `_.forOwn` without support for callback
  1984. * shorthands and `this` binding.
  1985. *
  1986. * @private
  1987. * @param {Object} object The object to iterate over.
  1988. * @param {Function} iteratee The function invoked per iteration.
  1989. * @returns {Object} Returns `object`.
  1990. */
  1991. function baseForOwn(object, iteratee) {
  1992. return baseFor(object, iteratee, keys);
  1993. }
  1994. /**
  1995. * The base implementation of `_.forOwnRight` without support for callback
  1996. * shorthands and `this` binding.
  1997. *
  1998. * @private
  1999. * @param {Object} object The object to iterate over.
  2000. * @param {Function} iteratee The function invoked per iteration.
  2001. * @returns {Object} Returns `object`.
  2002. */
  2003. function baseForOwnRight(object, iteratee) {
  2004. return baseForRight(object, iteratee, keys);
  2005. }
  2006. /**
  2007. * The base implementation of `_.functions` which creates an array of
  2008. * `object` function property names filtered from those provided.
  2009. *
  2010. * @private
  2011. * @param {Object} object The object to inspect.
  2012. * @param {Array} props The property names to filter.
  2013. * @returns {Array} Returns the new array of filtered property names.
  2014. */
  2015. function baseFunctions(object, props) {
  2016. var index = -1,
  2017. length = props.length,
  2018. resIndex = -1,
  2019. result = [];
  2020. while (++index < length) {
  2021. var key = props[index];
  2022. if (isFunction(object[key])) {
  2023. result[++resIndex] = key;
  2024. }
  2025. }
  2026. return result;
  2027. }
  2028. /**
  2029. * The base implementation of `get` without support for string paths
  2030. * and default values.
  2031. *
  2032. * @private
  2033. * @param {Object} object The object to query.
  2034. * @param {Array} path The path of the property to get.
  2035. * @param {string} [pathKey] The key representation of path.
  2036. * @returns {*} Returns the resolved value.
  2037. */
  2038. function baseGet(object, path, pathKey) {
  2039. if (object == null) {
  2040. return;
  2041. }
  2042. object = toObject(object);
  2043. if (pathKey !== undefined && pathKey in object) {
  2044. path = [pathKey];
  2045. }
  2046. var index = 0,
  2047. length = path.length;
  2048. while (object != null && index < length) {
  2049. object = toObject(object)[path[index++]];
  2050. }
  2051. return (index && index == length) ? object : undefined;
  2052. }
  2053. /**
  2054. * The base implementation of `_.isEqual` without support for `this` binding
  2055. * `customizer` functions.
  2056. *
  2057. * @private
  2058. * @param {*} value The value to compare.
  2059. * @param {*} other The other value to compare.
  2060. * @param {Function} [customizer] The function to customize comparing values.
  2061. * @param {boolean} [isLoose] Specify performing partial comparisons.
  2062. * @param {Array} [stackA] Tracks traversed `value` objects.
  2063. * @param {Array} [stackB] Tracks traversed `other` objects.
  2064. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2065. */
  2066. function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
  2067. if (value === other) {
  2068. return true;
  2069. }
  2070. if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
  2071. return value !== value && other !== other;
  2072. }
  2073. return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
  2074. }
  2075. /**
  2076. * A specialized version of `baseIsEqual` for arrays and objects which performs
  2077. * deep comparisons and tracks traversed objects enabling objects with circular
  2078. * references to be compared.
  2079. *
  2080. * @private
  2081. * @param {Object} object The object to compare.
  2082. * @param {Object} other The other object to compare.
  2083. * @param {Function} equalFunc The function to determine equivalents of values.
  2084. * @param {Function} [customizer] The function to customize comparing objects.
  2085. * @param {boolean} [isLoose] Specify performing partial comparisons.
  2086. * @param {Array} [stackA=[]] Tracks traversed `value` objects.
  2087. * @param {Array} [stackB=[]] Tracks traversed `other` objects.
  2088. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2089. */
  2090. function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
  2091. var objIsArr = isArray(object),
  2092. othIsArr = isArray(other),
  2093. objTag = arrayTag,
  2094. othTag = arrayTag;
  2095. if (!objIsArr) {
  2096. objTag = objToString.call(object);
  2097. if (objTag == argsTag) {
  2098. objTag = objectTag;
  2099. } else if (objTag != objectTag) {
  2100. objIsArr = isTypedArray(object);
  2101. }
  2102. }
  2103. if (!othIsArr) {
  2104. othTag = objToString.call(other);
  2105. if (othTag == argsTag) {
  2106. othTag = objectTag;
  2107. } else if (othTag != objectTag) {
  2108. othIsArr = isTypedArray(other);
  2109. }
  2110. }
  2111. var objIsObj = objTag == objectTag && !isHostObject(object),
  2112. othIsObj = othTag == objectTag && !isHostObject(other),
  2113. isSameTag = objTag == othTag;
  2114. if (isSameTag && !(objIsArr || objIsObj)) {
  2115. return equalByTag(object, other, objTag);
  2116. }
  2117. if (!isLoose) {
  2118. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  2119. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  2120. if (objIsWrapped || othIsWrapped) {
  2121. return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
  2122. }
  2123. }
  2124. if (!isSameTag) {
  2125. return false;
  2126. }
  2127. // Assume cyclic values are equal.
  2128. // For more information on detecting circular references see https://es5.github.io/#JO.
  2129. stackA || (stackA = []);
  2130. stackB || (stackB = []);
  2131. var length = stackA.length;
  2132. while (length--) {
  2133. if (stackA[length] == object) {
  2134. return stackB[length] == other;
  2135. }
  2136. }
  2137. // Add `object` and `other` to the stack of traversed objects.
  2138. stackA.push(object);
  2139. stackB.push(other);
  2140. var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB);
  2141. stackA.pop();
  2142. stackB.pop();
  2143. return result;
  2144. }
  2145. /**
  2146. * The base implementation of `_.isMatch` without support for callback
  2147. * shorthands and `this` binding.
  2148. *
  2149. * @private
  2150. * @param {Object} object The object to inspect.
  2151. * @param {Array} matchData The propery names, values, and compare flags to match.
  2152. * @param {Function} [customizer] The function to customize comparing objects.
  2153. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  2154. */
  2155. function baseIsMatch(object, matchData, customizer) {
  2156. var index = matchData.length,
  2157. length = index,
  2158. noCustomizer = !customizer;
  2159. if (object == null) {
  2160. return !length;
  2161. }
  2162. object = toObject(object);
  2163. while (index--) {
  2164. var data = matchData[index];
  2165. if ((noCustomizer && data[2])
  2166. ? data[1] !== object[data[0]]
  2167. : !(data[0] in object)
  2168. ) {
  2169. return false;
  2170. }
  2171. }
  2172. while (++index < length) {
  2173. data = matchData[index];
  2174. var key = data[0],
  2175. objValue = object[key],
  2176. srcValue = data[1];
  2177. if (noCustomizer && data[2]) {
  2178. if (objValue === undefined && !(key in object)) {
  2179. return false;
  2180. }
  2181. } else {
  2182. var result = customizer ? customizer(objValue, srcValue, key) : undefined;
  2183. if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) {
  2184. return false;
  2185. }
  2186. }
  2187. }
  2188. return true;
  2189. }
  2190. /**
  2191. * The base implementation of `_.map` without support for callback shorthands
  2192. * and `this` binding.
  2193. *
  2194. * @private
  2195. * @param {Array|Object|string} collection The collection to iterate over.
  2196. * @param {Function} iteratee The function invoked per iteration.
  2197. * @returns {Array} Returns the new mapped array.
  2198. */
  2199. function baseMap(collection, iteratee) {
  2200. var index = -1,
  2201. result = isArrayLike(collection) ? Array(collection.length) : [];
  2202. baseEach(collection, function(value, key, collection) {
  2203. result[++index] = iteratee(value, key, collection);
  2204. });
  2205. return result;
  2206. }
  2207. /**
  2208. * The base implementation of `_.matches` which does not clone `source`.
  2209. *
  2210. * @private
  2211. * @param {Object} source The object of property values to match.
  2212. * @returns {Function} Returns the new function.
  2213. */
  2214. function baseMatches(source) {
  2215. var matchData = getMatchData(source);
  2216. if (matchData.length == 1 && matchData[0][2]) {
  2217. var key = matchData[0][0],
  2218. value = matchData[0][1];
  2219. return function(object) {
  2220. if (object == null) {
  2221. return false;
  2222. }
  2223. object = toObject(object);
  2224. return object[key] === value && (value !== undefined || (key in object));
  2225. };
  2226. }
  2227. return function(object) {
  2228. return baseIsMatch(object, matchData);
  2229. };
  2230. }
  2231. /**
  2232. * The base implementation of `_.matchesProperty` which does not clone `srcValue`.
  2233. *
  2234. * @private
  2235. * @param {string} path The path of the property to get.
  2236. * @param {*} srcValue The value to compare.
  2237. * @returns {Function} Returns the new function.
  2238. */
  2239. function baseMatchesProperty(path, srcValue) {
  2240. var isArr = isArray(path),
  2241. isCommon = isKey(path) && isStrictComparable(srcValue),
  2242. pathKey = (path + '');
  2243. path = toPath(path);
  2244. return function(object) {
  2245. if (object == null) {
  2246. return false;
  2247. }
  2248. var key = pathKey;
  2249. object = toObject(object);
  2250. if ((isArr || !isCommon) && !(key in object)) {
  2251. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  2252. if (object == null) {
  2253. return false;
  2254. }
  2255. key = last(path);
  2256. object = toObject(object);
  2257. }
  2258. return object[key] === srcValue
  2259. ? (srcValue !== undefined || (key in object))
  2260. : baseIsEqual(srcValue, object[key], undefined, true);
  2261. };
  2262. }
  2263. /**
  2264. * The base implementation of `_.merge` without support for argument juggling,
  2265. * multiple sources, and `this` binding `customizer` functions.
  2266. *
  2267. * @private
  2268. * @param {Object} object The destination object.
  2269. * @param {Object} source The source object.
  2270. * @param {Function} [customizer] The function to customize merged values.
  2271. * @param {Array} [stackA=[]] Tracks traversed source objects.
  2272. * @param {Array} [stackB=[]] Associates values with source counterparts.
  2273. * @returns {Object} Returns `object`.
  2274. */
  2275. function baseMerge(object, source, customizer, stackA, stackB) {
  2276. if (!isObject(object)) {
  2277. return object;
  2278. }
  2279. var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
  2280. props = isSrcArr ? undefined : keys(source);
  2281. arrayEach(props || source, function(srcValue, key) {
  2282. if (props) {
  2283. key = srcValue;
  2284. srcValue = source[key];
  2285. }
  2286. if (isObjectLike(srcValue)) {
  2287. stackA || (stackA = []);
  2288. stackB || (stackB = []);
  2289. baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
  2290. }
  2291. else {
  2292. var value = object[key],
  2293. result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
  2294. isCommon = result === undefined;
  2295. if (isCommon) {
  2296. result = srcValue;
  2297. }
  2298. if ((result !== undefined || (isSrcArr && !(key in object))) &&
  2299. (isCommon || (result === result ? (result !== value) : (value === value)))) {
  2300. object[key] = result;
  2301. }
  2302. }
  2303. });
  2304. return object;
  2305. }
  2306. /**
  2307. * A specialized version of `baseMerge` for arrays and objects which performs
  2308. * deep merges and tracks traversed objects enabling objects with circular
  2309. * references to be merged.
  2310. *
  2311. * @private
  2312. * @param {Object} object The destination object.
  2313. * @param {Object} source The source object.
  2314. * @param {string} key The key of the value to merge.
  2315. * @param {Function} mergeFunc The function to merge values.
  2316. * @param {Function} [customizer] The function to customize merged values.
  2317. * @param {Array} [stackA=[]] Tracks traversed source objects.
  2318. * @param {Array} [stackB=[]] Associates values with source counterparts.
  2319. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2320. */
  2321. function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
  2322. var length = stackA.length,
  2323. srcValue = source[key];
  2324. while (length--) {
  2325. if (stackA[length] == srcValue) {
  2326. object[key] = stackB[length];
  2327. return;
  2328. }
  2329. }
  2330. var value = object[key],
  2331. result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
  2332. isCommon = result === undefined;
  2333. if (isCommon) {
  2334. result = srcValue;
  2335. if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
  2336. result = isArray(value)
  2337. ? value
  2338. : (isArrayLike(value) ? arrayCopy(value) : []);
  2339. }
  2340. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  2341. result = isArguments(value)
  2342. ? toPlainObject(value)
  2343. : (isPlainObject(value) ? value : {});
  2344. }
  2345. else {
  2346. isCommon = false;
  2347. }
  2348. }
  2349. // Add the source value to the stack of traversed objects and associate
  2350. // it with its merged value.
  2351. stackA.push(srcValue);
  2352. stackB.push(result);
  2353. if (isCommon) {
  2354. // Recursively merge objects and arrays (susceptible to call stack limits).
  2355. object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
  2356. } else if (result === result ? (result !== value) : (value === value)) {
  2357. object[key] = result;
  2358. }
  2359. }
  2360. /**
  2361. * The base implementation of `_.property` without support for deep paths.
  2362. *
  2363. * @private
  2364. * @param {string} key The key of the property to get.
  2365. * @returns {Function} Returns the new function.
  2366. */
  2367. function baseProperty(key) {
  2368. return function(object) {
  2369. return object == null ? undefined : toObject(object)[key];
  2370. };
  2371. }
  2372. /**
  2373. * A specialized version of `baseProperty` which supports deep paths.
  2374. *
  2375. * @private
  2376. * @param {Array|string} path The path of the property to get.
  2377. * @returns {Function} Returns the new function.
  2378. */
  2379. function basePropertyDeep(path) {
  2380. var pathKey = (path + '');
  2381. path = toPath(path);
  2382. return function(object) {
  2383. return baseGet(object, path, pathKey);
  2384. };
  2385. }
  2386. /**
  2387. * The base implementation of `_.pullAt` without support for individual
  2388. * index arguments and capturing the removed elements.
  2389. *
  2390. * @private
  2391. * @param {Array} array The array to modify.
  2392. * @param {number[]} indexes The indexes of elements to remove.
  2393. * @returns {Array} Returns `array`.
  2394. */
  2395. function basePullAt(array, indexes) {
  2396. var length = array ? indexes.length : 0;
  2397. while (length--) {
  2398. var index = indexes[length];
  2399. if (index != previous && isIndex(index)) {
  2400. var previous = index;
  2401. splice.call(array, index, 1);
  2402. }
  2403. }
  2404. return array;
  2405. }
  2406. /**
  2407. * The base implementation of `_.random` without support for argument juggling
  2408. * and returning floating-point numbers.
  2409. *
  2410. * @private
  2411. * @param {number} min The minimum possible value.
  2412. * @param {number} max The maximum possible value.
  2413. * @returns {number} Returns the random number.
  2414. */
  2415. function baseRandom(min, max) {
  2416. return min + nativeFloor(nativeRandom() * (max - min + 1));
  2417. }
  2418. /**
  2419. * The base implementation of `_.reduce` and `_.reduceRight` without support
  2420. * for callback shorthands and `this` binding, which iterates over `collection`
  2421. * using the provided `eachFunc`.
  2422. *
  2423. * @private
  2424. * @param {Array|Object|string} collection The collection to iterate over.
  2425. * @param {Function} iteratee The function invoked per iteration.
  2426. * @param {*} accumulator The initial value.
  2427. * @param {boolean} initFromCollection Specify using the first or last element
  2428. * of `collection` as the initial value.
  2429. * @param {Function} eachFunc The function to iterate over `collection`.
  2430. * @returns {*} Returns the accumulated value.
  2431. */
  2432. function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
  2433. eachFunc(collection, function(value, index, collection) {
  2434. accumulator = initFromCollection
  2435. ? (initFromCollection = false, value)
  2436. : iteratee(accumulator, value, index, collection);
  2437. });
  2438. return accumulator;
  2439. }
  2440. /**
  2441. * The base implementation of `setData` without support for hot loop detection.
  2442. *
  2443. * @private
  2444. * @param {Function} func The function to associate metadata with.
  2445. * @param {*} data The metadata.
  2446. * @returns {Function} Returns `func`.
  2447. */
  2448. var baseSetData = !metaMap ? identity : function(func, data) {
  2449. metaMap.set(func, data);
  2450. return func;
  2451. };
  2452. /**
  2453. * The base implementation of `_.slice` without an iteratee call guard.
  2454. *
  2455. * @private
  2456. * @param {Array} array The array to slice.
  2457. * @param {number} [start=0] The start position.
  2458. * @param {number} [end=array.length] The end position.
  2459. * @returns {Array} Returns the slice of `array`.
  2460. */
  2461. function baseSlice(array, start, end) {
  2462. var index = -1,
  2463. length = array.length;
  2464. start = start == null ? 0 : (+start || 0);
  2465. if (start < 0) {
  2466. start = -start > length ? 0 : (length + start);
  2467. }
  2468. end = (end === undefined || end > length) ? length : (+end || 0);
  2469. if (end < 0) {
  2470. end += length;
  2471. }
  2472. length = start > end ? 0 : ((end - start) >>> 0);
  2473. start >>>= 0;
  2474. var result = Array(length);
  2475. while (++index < length) {
  2476. result[index] = array[index + start];
  2477. }
  2478. return result;
  2479. }
  2480. /**
  2481. * The base implementation of `_.some` without support for callback shorthands
  2482. * and `this` binding.
  2483. *
  2484. * @private
  2485. * @param {Array|Object|string} collection The collection to iterate over.
  2486. * @param {Function} predicate The function invoked per iteration.
  2487. * @returns {boolean} Returns `true` if any element passes the predicate check,
  2488. * else `false`.
  2489. */
  2490. function baseSome(collection, predicate) {
  2491. var result;
  2492. baseEach(collection, function(value, index, collection) {
  2493. result = predicate(value, index, collection);
  2494. return !result;
  2495. });
  2496. return !!result;
  2497. }
  2498. /**
  2499. * The base implementation of `_.sortBy` which uses `comparer` to define
  2500. * the sort order of `array` and replaces criteria objects with their
  2501. * corresponding values.
  2502. *
  2503. * @private
  2504. * @param {Array} array The array to sort.
  2505. * @param {Function} comparer The function to define sort order.
  2506. * @returns {Array} Returns `array`.
  2507. */
  2508. function baseSortBy(array, comparer) {
  2509. var length = array.length;
  2510. array.sort(comparer);
  2511. while (length--) {
  2512. array[length] = array[length].value;
  2513. }
  2514. return array;
  2515. }
  2516. /**
  2517. * The base implementation of `_.sortByOrder` without param guards.
  2518. *
  2519. * @private
  2520. * @param {Array|Object|string} collection The collection to iterate over.
  2521. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  2522. * @param {boolean[]} orders The sort orders of `iteratees`.
  2523. * @returns {Array} Returns the new sorted array.
  2524. */
  2525. function baseSortByOrder(collection, iteratees, orders) {
  2526. var callback = getCallback(),
  2527. index = -1;
  2528. iteratees = arrayMap(iteratees, function(iteratee) { return callback(iteratee); });
  2529. var result = baseMap(collection, function(value) {
  2530. var criteria = arrayMap(iteratees, function(iteratee) { return iteratee(value); });
  2531. return { 'criteria': criteria, 'index': ++index, 'value': value };
  2532. });
  2533. return baseSortBy(result, function(object, other) {
  2534. return compareMultiple(object, other, orders);
  2535. });
  2536. }
  2537. /**
  2538. * The base implementation of `_.sum` without support for callback shorthands
  2539. * and `this` binding.
  2540. *
  2541. * @private
  2542. * @param {Array|Object|string} collection The collection to iterate over.
  2543. * @param {Function} iteratee The function invoked per iteration.
  2544. * @returns {number} Returns the sum.
  2545. */
  2546. function baseSum(collection, iteratee) {
  2547. var result = 0;
  2548. baseEach(collection, function(value, index, collection) {
  2549. result += +iteratee(value, index, collection) || 0;
  2550. });
  2551. return result;
  2552. }
  2553. /**
  2554. * The base implementation of `_.uniq` without support for callback shorthands
  2555. * and `this` binding.
  2556. *
  2557. * @private
  2558. * @param {Array} array The array to inspect.
  2559. * @param {Function} [iteratee] The function invoked per iteration.
  2560. * @returns {Array} Returns the new duplicate free array.
  2561. */
  2562. function baseUniq(array, iteratee) {
  2563. var index = -1,
  2564. indexOf = getIndexOf(),
  2565. length = array.length,
  2566. isCommon = indexOf === baseIndexOf,
  2567. isLarge = isCommon && length >= LARGE_ARRAY_SIZE,
  2568. seen = isLarge ? createCache() : null,
  2569. result = [];
  2570. if (seen) {
  2571. indexOf = cacheIndexOf;
  2572. isCommon = false;
  2573. } else {
  2574. isLarge = false;
  2575. seen = iteratee ? [] : result;
  2576. }
  2577. outer:
  2578. while (++index < length) {
  2579. var value = array[index],
  2580. computed = iteratee ? iteratee(value, index, array) : value;
  2581. if (isCommon && value === value) {
  2582. var seenIndex = seen.length;
  2583. while (seenIndex--) {
  2584. if (seen[seenIndex] === computed) {
  2585. continue outer;
  2586. }
  2587. }
  2588. if (iteratee) {
  2589. seen.push(computed);
  2590. }
  2591. result.push(value);
  2592. }
  2593. else if (indexOf(seen, computed, 0) < 0) {
  2594. if (iteratee || isLarge) {
  2595. seen.push(computed);
  2596. }
  2597. result.push(value);
  2598. }
  2599. }
  2600. return result;
  2601. }
  2602. /**
  2603. * The base implementation of `_.values` and `_.valuesIn` which creates an
  2604. * array of `object` property values corresponding to the property names
  2605. * of `props`.
  2606. *
  2607. * @private
  2608. * @param {Object} object The object to query.
  2609. * @param {Array} props The property names to get values for.
  2610. * @returns {Object} Returns the array of property values.
  2611. */
  2612. function baseValues(object, props) {
  2613. var index = -1,
  2614. length = props.length,
  2615. result = Array(length);
  2616. while (++index < length) {
  2617. result[index] = object[props[index]];
  2618. }
  2619. return result;
  2620. }
  2621. /**
  2622. * The base implementation of `_.dropRightWhile`, `_.dropWhile`, `_.takeRightWhile`,
  2623. * and `_.takeWhile` without support for callback shorthands and `this` binding.
  2624. *
  2625. * @private
  2626. * @param {Array} array The array to query.
  2627. * @param {Function} predicate The function invoked per iteration.
  2628. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  2629. * @param {boolean} [fromRight] Specify iterating from right to left.
  2630. * @returns {Array} Returns the slice of `array`.
  2631. */
  2632. function baseWhile(array, predicate, isDrop, fromRight) {
  2633. var length = array.length,
  2634. index = fromRight ? length : -1;
  2635. while ((fromRight ? index-- : ++index < length) && predicate(array[index], index, array)) {}
  2636. return isDrop
  2637. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  2638. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  2639. }
  2640. /**
  2641. * The base implementation of `wrapperValue` which returns the result of
  2642. * performing a sequence of actions on the unwrapped `value`, where each
  2643. * successive action is supplied the return value of the previous.
  2644. *
  2645. * @private
  2646. * @param {*} value The unwrapped value.
  2647. * @param {Array} actions Actions to peform to resolve the unwrapped value.
  2648. * @returns {*} Returns the resolved value.
  2649. */
  2650. function baseWrapperValue(value, actions) {
  2651. var result = value;
  2652. if (result instanceof LazyWrapper) {
  2653. result = result.value();
  2654. }
  2655. var index = -1,
  2656. length = actions.length;
  2657. while (++index < length) {
  2658. var action = actions[index];
  2659. result = action.func.apply(action.thisArg, arrayPush([result], action.args));
  2660. }
  2661. return result;
  2662. }
  2663. /**
  2664. * Performs a binary search of `array` to determine the index at which `value`
  2665. * should be inserted into `array` in order to maintain its sort order.
  2666. *
  2667. * @private
  2668. * @param {Array} array The sorted array to inspect.
  2669. * @param {*} value The value to evaluate.
  2670. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  2671. * @returns {number} Returns the index at which `value` should be inserted
  2672. * into `array`.
  2673. */
  2674. function binaryIndex(array, value, retHighest) {
  2675. var low = 0,
  2676. high = array ? array.length : low;
  2677. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  2678. while (low < high) {
  2679. var mid = (low + high) >>> 1,
  2680. computed = array[mid];
  2681. if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) {
  2682. low = mid + 1;
  2683. } else {
  2684. high = mid;
  2685. }
  2686. }
  2687. return high;
  2688. }
  2689. return binaryIndexBy(array, value, identity, retHighest);
  2690. }
  2691. /**
  2692. * This function is like `binaryIndex` except that it invokes `iteratee` for
  2693. * `value` and each element of `array` to compute their sort ranking. The
  2694. * iteratee is invoked with one argument; (value).
  2695. *
  2696. * @private
  2697. * @param {Array} array The sorted array to inspect.
  2698. * @param {*} value The value to evaluate.
  2699. * @param {Function} iteratee The function invoked per iteration.
  2700. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  2701. * @returns {number} Returns the index at which `value` should be inserted
  2702. * into `array`.
  2703. */
  2704. function binaryIndexBy(array, value, iteratee, retHighest) {
  2705. value = iteratee(value);
  2706. var low = 0,
  2707. high = array ? array.length : 0,
  2708. valIsNaN = value !== value,
  2709. valIsNull = value === null,
  2710. valIsUndef = value === undefined;
  2711. while (low < high) {
  2712. var mid = nativeFloor((low + high) / 2),
  2713. computed = iteratee(array[mid]),
  2714. isDef = computed !== undefined,
  2715. isReflexive = computed === computed;
  2716. if (valIsNaN) {
  2717. var setLow = isReflexive || retHighest;
  2718. } else if (valIsNull) {
  2719. setLow = isReflexive && isDef && (retHighest || computed != null);
  2720. } else if (valIsUndef) {
  2721. setLow = isReflexive && (retHighest || isDef);
  2722. } else if (computed == null) {
  2723. setLow = false;
  2724. } else {
  2725. setLow = retHighest ? (computed <= value) : (computed < value);
  2726. }
  2727. if (setLow) {
  2728. low = mid + 1;
  2729. } else {
  2730. high = mid;
  2731. }
  2732. }
  2733. return nativeMin(high, MAX_ARRAY_INDEX);
  2734. }
  2735. /**
  2736. * A specialized version of `baseCallback` which only supports `this` binding
  2737. * and specifying the number of arguments to provide to `func`.
  2738. *
  2739. * @private
  2740. * @param {Function} func The function to bind.
  2741. * @param {*} thisArg The `this` binding of `func`.
  2742. * @param {number} [argCount] The number of arguments to provide to `func`.
  2743. * @returns {Function} Returns the callback.
  2744. */
  2745. function bindCallback(func, thisArg, argCount) {
  2746. if (typeof func != 'function') {
  2747. return identity;
  2748. }
  2749. if (thisArg === undefined) {
  2750. return func;
  2751. }
  2752. switch (argCount) {
  2753. case 1: return function(value) {
  2754. return func.call(thisArg, value);
  2755. };
  2756. case 3: return function(value, index, collection) {
  2757. return func.call(thisArg, value, index, collection);
  2758. };
  2759. case 4: return function(accumulator, value, index, collection) {
  2760. return func.call(thisArg, accumulator, value, index, collection);
  2761. };
  2762. case 5: return function(value, other, key, object, source) {
  2763. return func.call(thisArg, value, other, key, object, source);
  2764. };
  2765. }
  2766. return function() {
  2767. return func.apply(thisArg, arguments);
  2768. };
  2769. }
  2770. /**
  2771. * Creates a clone of the given array buffer.
  2772. *
  2773. * @private
  2774. * @param {ArrayBuffer} buffer The array buffer to clone.
  2775. * @returns {ArrayBuffer} Returns the cloned array buffer.
  2776. */
  2777. function bufferClone(buffer) {
  2778. var result = new ArrayBuffer(buffer.byteLength),
  2779. view = new Uint8Array(result);
  2780. view.set(new Uint8Array(buffer));
  2781. return result;
  2782. }
  2783. /**
  2784. * Creates an array that is the composition of partially applied arguments,
  2785. * placeholders, and provided arguments into a single array of arguments.
  2786. *
  2787. * @private
  2788. * @param {Array|Object} args The provided arguments.
  2789. * @param {Array} partials The arguments to prepend to those provided.
  2790. * @param {Array} holders The `partials` placeholder indexes.
  2791. * @returns {Array} Returns the new array of composed arguments.
  2792. */
  2793. function composeArgs(args, partials, holders) {
  2794. var holdersLength = holders.length,
  2795. argsIndex = -1,
  2796. argsLength = nativeMax(args.length - holdersLength, 0),
  2797. leftIndex = -1,
  2798. leftLength = partials.length,
  2799. result = Array(leftLength + argsLength);
  2800. while (++leftIndex < leftLength) {
  2801. result[leftIndex] = partials[leftIndex];
  2802. }
  2803. while (++argsIndex < holdersLength) {
  2804. result[holders[argsIndex]] = args[argsIndex];
  2805. }
  2806. while (argsLength--) {
  2807. result[leftIndex++] = args[argsIndex++];
  2808. }
  2809. return result;
  2810. }
  2811. /**
  2812. * This function is like `composeArgs` except that the arguments composition
  2813. * is tailored for `_.partialRight`.
  2814. *
  2815. * @private
  2816. * @param {Array|Object} args The provided arguments.
  2817. * @param {Array} partials The arguments to append to those provided.
  2818. * @param {Array} holders The `partials` placeholder indexes.
  2819. * @returns {Array} Returns the new array of composed arguments.
  2820. */
  2821. function composeArgsRight(args, partials, holders) {
  2822. var holdersIndex = -1,
  2823. holdersLength = holders.length,
  2824. argsIndex = -1,
  2825. argsLength = nativeMax(args.length - holdersLength, 0),
  2826. rightIndex = -1,
  2827. rightLength = partials.length,
  2828. result = Array(argsLength + rightLength);
  2829. while (++argsIndex < argsLength) {
  2830. result[argsIndex] = args[argsIndex];
  2831. }
  2832. var offset = argsIndex;
  2833. while (++rightIndex < rightLength) {
  2834. result[offset + rightIndex] = partials[rightIndex];
  2835. }
  2836. while (++holdersIndex < holdersLength) {
  2837. result[offset + holders[holdersIndex]] = args[argsIndex++];
  2838. }
  2839. return result;
  2840. }
  2841. /**
  2842. * Creates a `_.countBy`, `_.groupBy`, `_.indexBy`, or `_.partition` function.
  2843. *
  2844. * @private
  2845. * @param {Function} setter The function to set keys and values of the accumulator object.
  2846. * @param {Function} [initializer] The function to initialize the accumulator object.
  2847. * @returns {Function} Returns the new aggregator function.
  2848. */
  2849. function createAggregator(setter, initializer) {
  2850. return function(collection, iteratee, thisArg) {
  2851. var result = initializer ? initializer() : {};
  2852. iteratee = getCallback(iteratee, thisArg, 3);
  2853. if (isArray(collection)) {
  2854. var index = -1,
  2855. length = collection.length;
  2856. while (++index < length) {
  2857. var value = collection[index];
  2858. setter(result, value, iteratee(value, index, collection), collection);
  2859. }
  2860. } else {
  2861. baseEach(collection, function(value, key, collection) {
  2862. setter(result, value, iteratee(value, key, collection), collection);
  2863. });
  2864. }
  2865. return result;
  2866. };
  2867. }
  2868. /**
  2869. * Creates a `_.assign`, `_.defaults`, or `_.merge` function.
  2870. *
  2871. * @private
  2872. * @param {Function} assigner The function to assign values.
  2873. * @returns {Function} Returns the new assigner function.
  2874. */
  2875. function createAssigner(assigner) {
  2876. return restParam(function(object, sources) {
  2877. var index = -1,
  2878. length = object == null ? 0 : sources.length,
  2879. customizer = length > 2 ? sources[length - 2] : undefined,
  2880. guard = length > 2 ? sources[2] : undefined,
  2881. thisArg = length > 1 ? sources[length - 1] : undefined;
  2882. if (typeof customizer == 'function') {
  2883. customizer = bindCallback(customizer, thisArg, 5);
  2884. length -= 2;
  2885. } else {
  2886. customizer = typeof thisArg == 'function' ? thisArg : undefined;
  2887. length -= (customizer ? 1 : 0);
  2888. }
  2889. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  2890. customizer = length < 3 ? undefined : customizer;
  2891. length = 1;
  2892. }
  2893. while (++index < length) {
  2894. var source = sources[index];
  2895. if (source) {
  2896. assigner(object, source, customizer);
  2897. }
  2898. }
  2899. return object;
  2900. });
  2901. }
  2902. /**
  2903. * Creates a `baseEach` or `baseEachRight` function.
  2904. *
  2905. * @private
  2906. * @param {Function} eachFunc The function to iterate over a collection.
  2907. * @param {boolean} [fromRight] Specify iterating from right to left.
  2908. * @returns {Function} Returns the new base function.
  2909. */
  2910. function createBaseEach(eachFunc, fromRight) {
  2911. return function(collection, iteratee) {
  2912. var length = collection ? getLength(collection) : 0;
  2913. if (!isLength(length)) {
  2914. return eachFunc(collection, iteratee);
  2915. }
  2916. var index = fromRight ? length : -1,
  2917. iterable = toObject(collection);
  2918. while ((fromRight ? index-- : ++index < length)) {
  2919. if (iteratee(iterable[index], index, iterable) === false) {
  2920. break;
  2921. }
  2922. }
  2923. return collection;
  2924. };
  2925. }
  2926. /**
  2927. * Creates a base function for `_.forIn` or `_.forInRight`.
  2928. *
  2929. * @private
  2930. * @param {boolean} [fromRight] Specify iterating from right to left.
  2931. * @returns {Function} Returns the new base function.
  2932. */
  2933. function createBaseFor(fromRight) {
  2934. return function(object, iteratee, keysFunc) {
  2935. var iterable = toObject(object),
  2936. props = keysFunc(object),
  2937. length = props.length,
  2938. index = fromRight ? length : -1;
  2939. while ((fromRight ? index-- : ++index < length)) {
  2940. var key = props[index];
  2941. if (iteratee(iterable[key], key, iterable) === false) {
  2942. break;
  2943. }
  2944. }
  2945. return object;
  2946. };
  2947. }
  2948. /**
  2949. * Creates a function that wraps `func` and invokes it with the `this`
  2950. * binding of `thisArg`.
  2951. *
  2952. * @private
  2953. * @param {Function} func The function to bind.
  2954. * @param {*} [thisArg] The `this` binding of `func`.
  2955. * @returns {Function} Returns the new bound function.
  2956. */
  2957. function createBindWrapper(func, thisArg) {
  2958. var Ctor = createCtorWrapper(func);
  2959. function wrapper() {
  2960. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  2961. return fn.apply(thisArg, arguments);
  2962. }
  2963. return wrapper;
  2964. }
  2965. /**
  2966. * Creates a `Set` cache object to optimize linear searches of large arrays.
  2967. *
  2968. * @private
  2969. * @param {Array} [values] The values to cache.
  2970. * @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
  2971. */
  2972. function createCache(values) {
  2973. return (nativeCreate && Set) ? new SetCache(values) : null;
  2974. }
  2975. /**
  2976. * Creates a function that produces compound words out of the words in a
  2977. * given string.
  2978. *
  2979. * @private
  2980. * @param {Function} callback The function to combine each word.
  2981. * @returns {Function} Returns the new compounder function.
  2982. */
  2983. function createCompounder(callback) {
  2984. return function(string) {
  2985. var index = -1,
  2986. array = words(deburr(string)),
  2987. length = array.length,
  2988. result = '';
  2989. while (++index < length) {
  2990. result = callback(result, array[index], index);
  2991. }
  2992. return result;
  2993. };
  2994. }
  2995. /**
  2996. * Creates a function that produces an instance of `Ctor` regardless of
  2997. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  2998. *
  2999. * @private
  3000. * @param {Function} Ctor The constructor to wrap.
  3001. * @returns {Function} Returns the new wrapped function.
  3002. */
  3003. function createCtorWrapper(Ctor) {
  3004. return function() {
  3005. // Use a `switch` statement to work with class constructors.
  3006. // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  3007. // for more details.
  3008. var args = arguments;
  3009. switch (args.length) {
  3010. case 0: return new Ctor;
  3011. case 1: return new Ctor(args[0]);
  3012. case 2: return new Ctor(args[0], args[1]);
  3013. case 3: return new Ctor(args[0], args[1], args[2]);
  3014. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  3015. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  3016. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  3017. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  3018. }
  3019. var thisBinding = baseCreate(Ctor.prototype),
  3020. result = Ctor.apply(thisBinding, args);
  3021. // Mimic the constructor's `return` behavior.
  3022. // See https://es5.github.io/#x13.2.2 for more details.
  3023. return isObject(result) ? result : thisBinding;
  3024. };
  3025. }
  3026. /**
  3027. * Creates a `_.curry` or `_.curryRight` function.
  3028. *
  3029. * @private
  3030. * @param {boolean} flag The curry bit flag.
  3031. * @returns {Function} Returns the new curry function.
  3032. */
  3033. function createCurry(flag) {
  3034. function curryFunc(func, arity, guard) {
  3035. if (guard && isIterateeCall(func, arity, guard)) {
  3036. arity = undefined;
  3037. }
  3038. var result = createWrapper(func, flag, undefined, undefined, undefined, undefined, undefined, arity);
  3039. result.placeholder = curryFunc.placeholder;
  3040. return result;
  3041. }
  3042. return curryFunc;
  3043. }
  3044. /**
  3045. * Creates a `_.defaults` or `_.defaultsDeep` function.
  3046. *
  3047. * @private
  3048. * @param {Function} assigner The function to assign values.
  3049. * @param {Function} customizer The function to customize assigned values.
  3050. * @returns {Function} Returns the new defaults function.
  3051. */
  3052. function createDefaults(assigner, customizer) {
  3053. return restParam(function(args) {
  3054. var object = args[0];
  3055. if (object == null) {
  3056. return object;
  3057. }
  3058. args.push(customizer);
  3059. return assigner.apply(undefined, args);
  3060. });
  3061. }
  3062. /**
  3063. * Creates a `_.max` or `_.min` function.
  3064. *
  3065. * @private
  3066. * @param {Function} comparator The function used to compare values.
  3067. * @param {*} exValue The initial extremum value.
  3068. * @returns {Function} Returns the new extremum function.
  3069. */
  3070. function createExtremum(comparator, exValue) {
  3071. return function(collection, iteratee, thisArg) {
  3072. if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
  3073. iteratee = undefined;
  3074. }
  3075. iteratee = getCallback(iteratee, thisArg, 3);
  3076. if (iteratee.length == 1) {
  3077. collection = isArray(collection) ? collection : toIterable(collection);
  3078. var result = arrayExtremum(collection, iteratee, comparator, exValue);
  3079. if (!(collection.length && result === exValue)) {
  3080. return result;
  3081. }
  3082. }
  3083. return baseExtremum(collection, iteratee, comparator, exValue);
  3084. };
  3085. }
  3086. /**
  3087. * Creates a `_.find` or `_.findLast` function.
  3088. *
  3089. * @private
  3090. * @param {Function} eachFunc The function to iterate over a collection.
  3091. * @param {boolean} [fromRight] Specify iterating from right to left.
  3092. * @returns {Function} Returns the new find function.
  3093. */
  3094. function createFind(eachFunc, fromRight) {
  3095. return function(collection, predicate, thisArg) {
  3096. predicate = getCallback(predicate, thisArg, 3);
  3097. if (isArray(collection)) {
  3098. var index = baseFindIndex(collection, predicate, fromRight);
  3099. return index > -1 ? collection[index] : undefined;
  3100. }
  3101. return baseFind(collection, predicate, eachFunc);
  3102. };
  3103. }
  3104. /**
  3105. * Creates a `_.findIndex` or `_.findLastIndex` function.
  3106. *
  3107. * @private
  3108. * @param {boolean} [fromRight] Specify iterating from right to left.
  3109. * @returns {Function} Returns the new find function.
  3110. */
  3111. function createFindIndex(fromRight) {
  3112. return function(array, predicate, thisArg) {
  3113. if (!(array && array.length)) {
  3114. return -1;
  3115. }
  3116. predicate = getCallback(predicate, thisArg, 3);
  3117. return baseFindIndex(array, predicate, fromRight);
  3118. };
  3119. }
  3120. /**
  3121. * Creates a `_.findKey` or `_.findLastKey` function.
  3122. *
  3123. * @private
  3124. * @param {Function} objectFunc The function to iterate over an object.
  3125. * @returns {Function} Returns the new find function.
  3126. */
  3127. function createFindKey(objectFunc) {
  3128. return function(object, predicate, thisArg) {
  3129. predicate = getCallback(predicate, thisArg, 3);
  3130. return baseFind(object, predicate, objectFunc, true);
  3131. };
  3132. }
  3133. /**
  3134. * Creates a `_.flow` or `_.flowRight` function.
  3135. *
  3136. * @private
  3137. * @param {boolean} [fromRight] Specify iterating from right to left.
  3138. * @returns {Function} Returns the new flow function.
  3139. */
  3140. function createFlow(fromRight) {
  3141. return function() {
  3142. var wrapper,
  3143. length = arguments.length,
  3144. index = fromRight ? length : -1,
  3145. leftIndex = 0,
  3146. funcs = Array(length);
  3147. while ((fromRight ? index-- : ++index < length)) {
  3148. var func = funcs[leftIndex++] = arguments[index];
  3149. if (typeof func != 'function') {
  3150. throw new TypeError(FUNC_ERROR_TEXT);
  3151. }
  3152. if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') {
  3153. wrapper = new LodashWrapper([], true);
  3154. }
  3155. }
  3156. index = wrapper ? -1 : length;
  3157. while (++index < length) {
  3158. func = funcs[index];
  3159. var funcName = getFuncName(func),
  3160. data = funcName == 'wrapper' ? getData(func) : undefined;
  3161. if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
  3162. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  3163. } else {
  3164. wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func);
  3165. }
  3166. }
  3167. return function() {
  3168. var args = arguments,
  3169. value = args[0];
  3170. if (wrapper && args.length == 1 && isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
  3171. return wrapper.plant(value).value();
  3172. }
  3173. var index = 0,
  3174. result = length ? funcs[index].apply(this, args) : value;
  3175. while (++index < length) {
  3176. result = funcs[index].call(this, result);
  3177. }
  3178. return result;
  3179. };
  3180. };
  3181. }
  3182. /**
  3183. * Creates a function for `_.forEach` or `_.forEachRight`.
  3184. *
  3185. * @private
  3186. * @param {Function} arrayFunc The function to iterate over an array.
  3187. * @param {Function} eachFunc The function to iterate over a collection.
  3188. * @returns {Function} Returns the new each function.
  3189. */
  3190. function createForEach(arrayFunc, eachFunc) {
  3191. return function(collection, iteratee, thisArg) {
  3192. return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
  3193. ? arrayFunc(collection, iteratee)
  3194. : eachFunc(collection, bindCallback(iteratee, thisArg, 3));
  3195. };
  3196. }
  3197. /**
  3198. * Creates a function for `_.forIn` or `_.forInRight`.
  3199. *
  3200. * @private
  3201. * @param {Function} objectFunc The function to iterate over an object.
  3202. * @returns {Function} Returns the new each function.
  3203. */
  3204. function createForIn(objectFunc) {
  3205. return function(object, iteratee, thisArg) {
  3206. if (typeof iteratee != 'function' || thisArg !== undefined) {
  3207. iteratee = bindCallback(iteratee, thisArg, 3);
  3208. }
  3209. return objectFunc(object, iteratee, keysIn);
  3210. };
  3211. }
  3212. /**
  3213. * Creates a function for `_.forOwn` or `_.forOwnRight`.
  3214. *
  3215. * @private
  3216. * @param {Function} objectFunc The function to iterate over an object.
  3217. * @returns {Function} Returns the new each function.
  3218. */
  3219. function createForOwn(objectFunc) {
  3220. return function(object, iteratee, thisArg) {
  3221. if (typeof iteratee != 'function' || thisArg !== undefined) {
  3222. iteratee = bindCallback(iteratee, thisArg, 3);
  3223. }
  3224. return objectFunc(object, iteratee);
  3225. };
  3226. }
  3227. /**
  3228. * Creates a function for `_.mapKeys` or `_.mapValues`.
  3229. *
  3230. * @private
  3231. * @param {boolean} [isMapKeys] Specify mapping keys instead of values.
  3232. * @returns {Function} Returns the new map function.
  3233. */
  3234. function createObjectMapper(isMapKeys) {
  3235. return function(object, iteratee, thisArg) {
  3236. var result = {};
  3237. iteratee = getCallback(iteratee, thisArg, 3);
  3238. baseForOwn(object, function(value, key, object) {
  3239. var mapped = iteratee(value, key, object);
  3240. key = isMapKeys ? mapped : key;
  3241. value = isMapKeys ? value : mapped;
  3242. result[key] = value;
  3243. });
  3244. return result;
  3245. };
  3246. }
  3247. /**
  3248. * Creates a function for `_.padLeft` or `_.padRight`.
  3249. *
  3250. * @private
  3251. * @param {boolean} [fromRight] Specify padding from the right.
  3252. * @returns {Function} Returns the new pad function.
  3253. */
  3254. function createPadDir(fromRight) {
  3255. return function(string, length, chars) {
  3256. string = baseToString(string);
  3257. return (fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string);
  3258. };
  3259. }
  3260. /**
  3261. * Creates a `_.partial` or `_.partialRight` function.
  3262. *
  3263. * @private
  3264. * @param {boolean} flag The partial bit flag.
  3265. * @returns {Function} Returns the new partial function.
  3266. */
  3267. function createPartial(flag) {
  3268. var partialFunc = restParam(function(func, partials) {
  3269. var holders = replaceHolders(partials, partialFunc.placeholder);
  3270. return createWrapper(func, flag, undefined, partials, holders);
  3271. });
  3272. return partialFunc;
  3273. }
  3274. /**
  3275. * Creates a function for `_.reduce` or `_.reduceRight`.
  3276. *
  3277. * @private
  3278. * @param {Function} arrayFunc The function to iterate over an array.
  3279. * @param {Function} eachFunc The function to iterate over a collection.
  3280. * @returns {Function} Returns the new each function.
  3281. */
  3282. function createReduce(arrayFunc, eachFunc) {
  3283. return function(collection, iteratee, accumulator, thisArg) {
  3284. var initFromArray = arguments.length < 3;
  3285. return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
  3286. ? arrayFunc(collection, iteratee, accumulator, initFromArray)
  3287. : baseReduce(collection, getCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
  3288. };
  3289. }
  3290. /**
  3291. * Creates a function that wraps `func` and invokes it with optional `this`
  3292. * binding of, partial application, and currying.
  3293. *
  3294. * @private
  3295. * @param {Function|string} func The function or method name to reference.
  3296. * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
  3297. * @param {*} [thisArg] The `this` binding of `func`.
  3298. * @param {Array} [partials] The arguments to prepend to those provided to the new function.
  3299. * @param {Array} [holders] The `partials` placeholder indexes.
  3300. * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
  3301. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  3302. * @param {Array} [argPos] The argument positions of the new function.
  3303. * @param {number} [ary] The arity cap of `func`.
  3304. * @param {number} [arity] The arity of `func`.
  3305. * @returns {Function} Returns the new wrapped function.
  3306. */
  3307. function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  3308. var isAry = bitmask & ARY_FLAG,
  3309. isBind = bitmask & BIND_FLAG,
  3310. isBindKey = bitmask & BIND_KEY_FLAG,
  3311. isCurry = bitmask & CURRY_FLAG,
  3312. isCurryBound = bitmask & CURRY_BOUND_FLAG,
  3313. isCurryRight = bitmask & CURRY_RIGHT_FLAG,
  3314. Ctor = isBindKey ? undefined : createCtorWrapper(func);
  3315. function wrapper() {
  3316. // Avoid `arguments` object use disqualifying optimizations by
  3317. // converting it to an array before providing it to other functions.
  3318. var length = arguments.length,
  3319. index = length,
  3320. args = Array(length);
  3321. while (index--) {
  3322. args[index] = arguments[index];
  3323. }
  3324. if (partials) {
  3325. args = composeArgs(args, partials, holders);
  3326. }
  3327. if (partialsRight) {
  3328. args = composeArgsRight(args, partialsRight, holdersRight);
  3329. }
  3330. if (isCurry || isCurryRight) {
  3331. var placeholder = wrapper.placeholder,
  3332. argsHolders = replaceHolders(args, placeholder);
  3333. length -= argsHolders.length;
  3334. if (length < arity) {
  3335. var newArgPos = argPos ? arrayCopy(argPos) : undefined,
  3336. newArity = nativeMax(arity - length, 0),
  3337. newsHolders = isCurry ? argsHolders : undefined,
  3338. newHoldersRight = isCurry ? undefined : argsHolders,
  3339. newPartials = isCurry ? args : undefined,
  3340. newPartialsRight = isCurry ? undefined : args;
  3341. bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
  3342. bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
  3343. if (!isCurryBound) {
  3344. bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
  3345. }
  3346. var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity],
  3347. result = createHybridWrapper.apply(undefined, newData);
  3348. if (isLaziable(func)) {
  3349. setData(result, newData);
  3350. }
  3351. result.placeholder = placeholder;
  3352. return result;
  3353. }
  3354. }
  3355. var thisBinding = isBind ? thisArg : this,
  3356. fn = isBindKey ? thisBinding[func] : func;
  3357. if (argPos) {
  3358. args = reorder(args, argPos);
  3359. }
  3360. if (isAry && ary < args.length) {
  3361. args.length = ary;
  3362. }
  3363. if (this && this !== root && this instanceof wrapper) {
  3364. fn = Ctor || createCtorWrapper(func);
  3365. }
  3366. return fn.apply(thisBinding, args);
  3367. }
  3368. return wrapper;
  3369. }
  3370. /**
  3371. * Creates the padding required for `string` based on the given `length`.
  3372. * The `chars` string is truncated if the number of characters exceeds `length`.
  3373. *
  3374. * @private
  3375. * @param {string} string The string to create padding for.
  3376. * @param {number} [length=0] The padding length.
  3377. * @param {string} [chars=' '] The string used as padding.
  3378. * @returns {string} Returns the pad for `string`.
  3379. */
  3380. function createPadding(string, length, chars) {
  3381. var strLength = string.length;
  3382. length = +length;
  3383. if (strLength >= length || !nativeIsFinite(length)) {
  3384. return '';
  3385. }
  3386. var padLength = length - strLength;
  3387. chars = chars == null ? ' ' : (chars + '');
  3388. return repeat(chars, nativeCeil(padLength / chars.length)).slice(0, padLength);
  3389. }
  3390. /**
  3391. * Creates a function that wraps `func` and invokes it with the optional `this`
  3392. * binding of `thisArg` and the `partials` prepended to those provided to
  3393. * the wrapper.
  3394. *
  3395. * @private
  3396. * @param {Function} func The function to partially apply arguments to.
  3397. * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
  3398. * @param {*} thisArg The `this` binding of `func`.
  3399. * @param {Array} partials The arguments to prepend to those provided to the new function.
  3400. * @returns {Function} Returns the new bound function.
  3401. */
  3402. function createPartialWrapper(func, bitmask, thisArg, partials) {
  3403. var isBind = bitmask & BIND_FLAG,
  3404. Ctor = createCtorWrapper(func);
  3405. function wrapper() {
  3406. // Avoid `arguments` object use disqualifying optimizations by
  3407. // converting it to an array before providing it `func`.
  3408. var argsIndex = -1,
  3409. argsLength = arguments.length,
  3410. leftIndex = -1,
  3411. leftLength = partials.length,
  3412. args = Array(leftLength + argsLength);
  3413. while (++leftIndex < leftLength) {
  3414. args[leftIndex] = partials[leftIndex];
  3415. }
  3416. while (argsLength--) {
  3417. args[leftIndex++] = arguments[++argsIndex];
  3418. }
  3419. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  3420. return fn.apply(isBind ? thisArg : this, args);
  3421. }
  3422. return wrapper;
  3423. }
  3424. /**
  3425. * Creates a `_.ceil`, `_.floor`, or `_.round` function.
  3426. *
  3427. * @private
  3428. * @param {string} methodName The name of the `Math` method to use when rounding.
  3429. * @returns {Function} Returns the new round function.
  3430. */
  3431. function createRound(methodName) {
  3432. var func = Math[methodName];
  3433. return function(number, precision) {
  3434. precision = precision === undefined ? 0 : (+precision || 0);
  3435. if (precision) {
  3436. precision = pow(10, precision);
  3437. return func(number * precision) / precision;
  3438. }
  3439. return func(number);
  3440. };
  3441. }
  3442. /**
  3443. * Creates a `_.sortedIndex` or `_.sortedLastIndex` function.
  3444. *
  3445. * @private
  3446. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3447. * @returns {Function} Returns the new index function.
  3448. */
  3449. function createSortedIndex(retHighest) {
  3450. return function(array, value, iteratee, thisArg) {
  3451. var callback = getCallback(iteratee);
  3452. return (iteratee == null && callback === baseCallback)
  3453. ? binaryIndex(array, value, retHighest)
  3454. : binaryIndexBy(array, value, callback(iteratee, thisArg, 1), retHighest);
  3455. };
  3456. }
  3457. /**
  3458. * Creates a function that either curries or invokes `func` with optional
  3459. * `this` binding and partially applied arguments.
  3460. *
  3461. * @private
  3462. * @param {Function|string} func The function or method name to reference.
  3463. * @param {number} bitmask The bitmask of flags.
  3464. * The bitmask may be composed of the following flags:
  3465. * 1 - `_.bind`
  3466. * 2 - `_.bindKey`
  3467. * 4 - `_.curry` or `_.curryRight` of a bound function
  3468. * 8 - `_.curry`
  3469. * 16 - `_.curryRight`
  3470. * 32 - `_.partial`
  3471. * 64 - `_.partialRight`
  3472. * 128 - `_.rearg`
  3473. * 256 - `_.ary`
  3474. * @param {*} [thisArg] The `this` binding of `func`.
  3475. * @param {Array} [partials] The arguments to be partially applied.
  3476. * @param {Array} [holders] The `partials` placeholder indexes.
  3477. * @param {Array} [argPos] The argument positions of the new function.
  3478. * @param {number} [ary] The arity cap of `func`.
  3479. * @param {number} [arity] The arity of `func`.
  3480. * @returns {Function} Returns the new wrapped function.
  3481. */
  3482. function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  3483. var isBindKey = bitmask & BIND_KEY_FLAG;
  3484. if (!isBindKey && typeof func != 'function') {
  3485. throw new TypeError(FUNC_ERROR_TEXT);
  3486. }
  3487. var length = partials ? partials.length : 0;
  3488. if (!length) {
  3489. bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
  3490. partials = holders = undefined;
  3491. }
  3492. length -= (holders ? holders.length : 0);
  3493. if (bitmask & PARTIAL_RIGHT_FLAG) {
  3494. var partialsRight = partials,
  3495. holdersRight = holders;
  3496. partials = holders = undefined;
  3497. }
  3498. var data = isBindKey ? undefined : getData(func),
  3499. newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
  3500. if (data) {
  3501. mergeData(newData, data);
  3502. bitmask = newData[1];
  3503. arity = newData[9];
  3504. }
  3505. newData[9] = arity == null
  3506. ? (isBindKey ? 0 : func.length)
  3507. : (nativeMax(arity - length, 0) || 0);
  3508. if (bitmask == BIND_FLAG) {
  3509. var result = createBindWrapper(newData[0], newData[2]);
  3510. } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
  3511. result = createPartialWrapper.apply(undefined, newData);
  3512. } else {
  3513. result = createHybridWrapper.apply(undefined, newData);
  3514. }
  3515. var setter = data ? baseSetData : setData;
  3516. return setter(result, newData);
  3517. }
  3518. /**
  3519. * A specialized version of `baseIsEqualDeep` for arrays with support for
  3520. * partial deep comparisons.
  3521. *
  3522. * @private
  3523. * @param {Array} array The array to compare.
  3524. * @param {Array} other The other array to compare.
  3525. * @param {Function} equalFunc The function to determine equivalents of values.
  3526. * @param {Function} [customizer] The function to customize comparing arrays.
  3527. * @param {boolean} [isLoose] Specify performing partial comparisons.
  3528. * @param {Array} [stackA] Tracks traversed `value` objects.
  3529. * @param {Array} [stackB] Tracks traversed `other` objects.
  3530. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  3531. */
  3532. function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
  3533. var index = -1,
  3534. arrLength = array.length,
  3535. othLength = other.length;
  3536. if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
  3537. return false;
  3538. }
  3539. // Ignore non-index properties.
  3540. while (++index < arrLength) {
  3541. var arrValue = array[index],
  3542. othValue = other[index],
  3543. result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined;
  3544. if (result !== undefined) {
  3545. if (result) {
  3546. continue;
  3547. }
  3548. return false;
  3549. }
  3550. // Recursively compare arrays (susceptible to call stack limits).
  3551. if (isLoose) {
  3552. if (!arraySome(other, function(othValue) {
  3553. return arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
  3554. })) {
  3555. return false;
  3556. }
  3557. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB))) {
  3558. return false;
  3559. }
  3560. }
  3561. return true;
  3562. }
  3563. /**
  3564. * A specialized version of `baseIsEqualDeep` for comparing objects of
  3565. * the same `toStringTag`.
  3566. *
  3567. * **Note:** This function only supports comparing values with tags of
  3568. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  3569. *
  3570. * @private
  3571. * @param {Object} object The object to compare.
  3572. * @param {Object} other The other object to compare.
  3573. * @param {string} tag The `toStringTag` of the objects to compare.
  3574. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3575. */
  3576. function equalByTag(object, other, tag) {
  3577. switch (tag) {
  3578. case boolTag:
  3579. case dateTag:
  3580. // Coerce dates and booleans to numbers, dates to milliseconds and booleans
  3581. // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
  3582. return +object == +other;
  3583. case errorTag:
  3584. return object.name == other.name && object.message == other.message;
  3585. case numberTag:
  3586. // Treat `NaN` vs. `NaN` as equal.
  3587. return (object != +object)
  3588. ? other != +other
  3589. : object == +other;
  3590. case regexpTag:
  3591. case stringTag:
  3592. // Coerce regexes to strings and treat strings primitives and string
  3593. // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
  3594. return object == (other + '');
  3595. }
  3596. return false;
  3597. }
  3598. /**
  3599. * A specialized version of `baseIsEqualDeep` for objects with support for
  3600. * partial deep comparisons.
  3601. *
  3602. * @private
  3603. * @param {Object} object The object to compare.
  3604. * @param {Object} other The other object to compare.
  3605. * @param {Function} equalFunc The function to determine equivalents of values.
  3606. * @param {Function} [customizer] The function to customize comparing values.
  3607. * @param {boolean} [isLoose] Specify performing partial comparisons.
  3608. * @param {Array} [stackA] Tracks traversed `value` objects.
  3609. * @param {Array} [stackB] Tracks traversed `other` objects.
  3610. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3611. */
  3612. function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
  3613. var objProps = keys(object),
  3614. objLength = objProps.length,
  3615. othProps = keys(other),
  3616. othLength = othProps.length;
  3617. if (objLength != othLength && !isLoose) {
  3618. return false;
  3619. }
  3620. var index = objLength;
  3621. while (index--) {
  3622. var key = objProps[index];
  3623. if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) {
  3624. return false;
  3625. }
  3626. }
  3627. var skipCtor = isLoose;
  3628. while (++index < objLength) {
  3629. key = objProps[index];
  3630. var objValue = object[key],
  3631. othValue = other[key],
  3632. result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined;
  3633. // Recursively compare objects (susceptible to call stack limits).
  3634. if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) {
  3635. return false;
  3636. }
  3637. skipCtor || (skipCtor = key == 'constructor');
  3638. }
  3639. if (!skipCtor) {
  3640. var objCtor = object.constructor,
  3641. othCtor = other.constructor;
  3642. // Non `Object` object instances with different constructors are not equal.
  3643. if (objCtor != othCtor &&
  3644. ('constructor' in object && 'constructor' in other) &&
  3645. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  3646. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  3647. return false;
  3648. }
  3649. }
  3650. return true;
  3651. }
  3652. /**
  3653. * Gets the appropriate "callback" function. If the `_.callback` method is
  3654. * customized this function returns the custom method, otherwise it returns
  3655. * the `baseCallback` function. If arguments are provided the chosen function
  3656. * is invoked with them and its result is returned.
  3657. *
  3658. * @private
  3659. * @returns {Function} Returns the chosen function or its result.
  3660. */
  3661. function getCallback(func, thisArg, argCount) {
  3662. var result = lodash.callback || callback;
  3663. result = result === callback ? baseCallback : result;
  3664. return argCount ? result(func, thisArg, argCount) : result;
  3665. }
  3666. /**
  3667. * Gets metadata for `func`.
  3668. *
  3669. * @private
  3670. * @param {Function} func The function to query.
  3671. * @returns {*} Returns the metadata for `func`.
  3672. */
  3673. var getData = !metaMap ? noop : function(func) {
  3674. return metaMap.get(func);
  3675. };
  3676. /**
  3677. * Gets the name of `func`.
  3678. *
  3679. * @private
  3680. * @param {Function} func The function to query.
  3681. * @returns {string} Returns the function name.
  3682. */
  3683. function getFuncName(func) {
  3684. var result = (func.name + ''),
  3685. array = realNames[result],
  3686. length = array ? array.length : 0;
  3687. while (length--) {
  3688. var data = array[length],
  3689. otherFunc = data.func;
  3690. if (otherFunc == null || otherFunc == func) {
  3691. return data.name;
  3692. }
  3693. }
  3694. return result;
  3695. }
  3696. /**
  3697. * Gets the appropriate "indexOf" function. If the `_.indexOf` method is
  3698. * customized this function returns the custom method, otherwise it returns
  3699. * the `baseIndexOf` function. If arguments are provided the chosen function
  3700. * is invoked with them and its result is returned.
  3701. *
  3702. * @private
  3703. * @returns {Function|number} Returns the chosen function or its result.
  3704. */
  3705. function getIndexOf(collection, target, fromIndex) {
  3706. var result = lodash.indexOf || indexOf;
  3707. result = result === indexOf ? baseIndexOf : result;
  3708. return collection ? result(collection, target, fromIndex) : result;
  3709. }
  3710. /**
  3711. * Gets the "length" property value of `object`.
  3712. *
  3713. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  3714. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  3715. *
  3716. * @private
  3717. * @param {Object} object The object to query.
  3718. * @returns {*} Returns the "length" value.
  3719. */
  3720. var getLength = baseProperty('length');
  3721. /**
  3722. * Gets the propery names, values, and compare flags of `object`.
  3723. *
  3724. * @private
  3725. * @param {Object} object The object to query.
  3726. * @returns {Array} Returns the match data of `object`.
  3727. */
  3728. function getMatchData(object) {
  3729. var result = pairs(object),
  3730. length = result.length;
  3731. while (length--) {
  3732. result[length][2] = isStrictComparable(result[length][1]);
  3733. }
  3734. return result;
  3735. }
  3736. /**
  3737. * Gets the native function at `key` of `object`.
  3738. *
  3739. * @private
  3740. * @param {Object} object The object to query.
  3741. * @param {string} key The key of the method to get.
  3742. * @returns {*} Returns the function if it's native, else `undefined`.
  3743. */
  3744. function getNative(object, key) {
  3745. var value = object == null ? undefined : object[key];
  3746. return isNative(value) ? value : undefined;
  3747. }
  3748. /**
  3749. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  3750. *
  3751. * @private
  3752. * @param {number} start The start of the view.
  3753. * @param {number} end The end of the view.
  3754. * @param {Array} transforms The transformations to apply to the view.
  3755. * @returns {Object} Returns an object containing the `start` and `end`
  3756. * positions of the view.
  3757. */
  3758. function getView(start, end, transforms) {
  3759. var index = -1,
  3760. length = transforms.length;
  3761. while (++index < length) {
  3762. var data = transforms[index],
  3763. size = data.size;
  3764. switch (data.type) {
  3765. case 'drop': start += size; break;
  3766. case 'dropRight': end -= size; break;
  3767. case 'take': end = nativeMin(end, start + size); break;
  3768. case 'takeRight': start = nativeMax(start, end - size); break;
  3769. }
  3770. }
  3771. return { 'start': start, 'end': end };
  3772. }
  3773. /**
  3774. * Initializes an array clone.
  3775. *
  3776. * @private
  3777. * @param {Array} array The array to clone.
  3778. * @returns {Array} Returns the initialized clone.
  3779. */
  3780. function initCloneArray(array) {
  3781. var length = array.length,
  3782. result = new array.constructor(length);
  3783. // Add array properties assigned by `RegExp#exec`.
  3784. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  3785. result.index = array.index;
  3786. result.input = array.input;
  3787. }
  3788. return result;
  3789. }
  3790. /**
  3791. * Initializes an object clone.
  3792. *
  3793. * @private
  3794. * @param {Object} object The object to clone.
  3795. * @returns {Object} Returns the initialized clone.
  3796. */
  3797. function initCloneObject(object) {
  3798. var Ctor = object.constructor;
  3799. if (!(typeof Ctor == 'function' && Ctor instanceof Ctor)) {
  3800. Ctor = Object;
  3801. }
  3802. return new Ctor;
  3803. }
  3804. /**
  3805. * Initializes an object clone based on its `toStringTag`.
  3806. *
  3807. * **Note:** This function only supports cloning values with tags of
  3808. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  3809. *
  3810. * @private
  3811. * @param {Object} object The object to clone.
  3812. * @param {string} tag The `toStringTag` of the object to clone.
  3813. * @param {boolean} [isDeep] Specify a deep clone.
  3814. * @returns {Object} Returns the initialized clone.
  3815. */
  3816. function initCloneByTag(object, tag, isDeep) {
  3817. var Ctor = object.constructor;
  3818. switch (tag) {
  3819. case arrayBufferTag:
  3820. return bufferClone(object);
  3821. case boolTag:
  3822. case dateTag:
  3823. return new Ctor(+object);
  3824. case float32Tag: case float64Tag:
  3825. case int8Tag: case int16Tag: case int32Tag:
  3826. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  3827. // Safari 5 mobile incorrectly has `Object` as the constructor of typed arrays.
  3828. if (Ctor instanceof Ctor) {
  3829. Ctor = ctorByTag[tag];
  3830. }
  3831. var buffer = object.buffer;
  3832. return new Ctor(isDeep ? bufferClone(buffer) : buffer, object.byteOffset, object.length);
  3833. case numberTag:
  3834. case stringTag:
  3835. return new Ctor(object);
  3836. case regexpTag:
  3837. var result = new Ctor(object.source, reFlags.exec(object));
  3838. result.lastIndex = object.lastIndex;
  3839. }
  3840. return result;
  3841. }
  3842. /**
  3843. * Invokes the method at `path` on `object`.
  3844. *
  3845. * @private
  3846. * @param {Object} object The object to query.
  3847. * @param {Array|string} path The path of the method to invoke.
  3848. * @param {Array} args The arguments to invoke the method with.
  3849. * @returns {*} Returns the result of the invoked method.
  3850. */
  3851. function invokePath(object, path, args) {
  3852. if (object != null && !isKey(path, object)) {
  3853. path = toPath(path);
  3854. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  3855. path = last(path);
  3856. }
  3857. var func = object == null ? object : object[path];
  3858. return func == null ? undefined : func.apply(object, args);
  3859. }
  3860. /**
  3861. * Checks if `value` is array-like.
  3862. *
  3863. * @private
  3864. * @param {*} value The value to check.
  3865. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  3866. */
  3867. function isArrayLike(value) {
  3868. return value != null && isLength(getLength(value));
  3869. }
  3870. /**
  3871. * Checks if `value` is a valid array-like index.
  3872. *
  3873. * @private
  3874. * @param {*} value The value to check.
  3875. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  3876. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  3877. */
  3878. function isIndex(value, length) {
  3879. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  3880. length = length == null ? MAX_SAFE_INTEGER : length;
  3881. return value > -1 && value % 1 == 0 && value < length;
  3882. }
  3883. /**
  3884. * Checks if the provided arguments are from an iteratee call.
  3885. *
  3886. * @private
  3887. * @param {*} value The potential iteratee value argument.
  3888. * @param {*} index The potential iteratee index or key argument.
  3889. * @param {*} object The potential iteratee object argument.
  3890. * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
  3891. */
  3892. function isIterateeCall(value, index, object) {
  3893. if (!isObject(object)) {
  3894. return false;
  3895. }
  3896. var type = typeof index;
  3897. if (type == 'number'
  3898. ? (isArrayLike(object) && isIndex(index, object.length))
  3899. : (type == 'string' && index in object)) {
  3900. var other = object[index];
  3901. return value === value ? (value === other) : (other !== other);
  3902. }
  3903. return false;
  3904. }
  3905. /**
  3906. * Checks if `value` is a property name and not a property path.
  3907. *
  3908. * @private
  3909. * @param {*} value The value to check.
  3910. * @param {Object} [object] The object to query keys on.
  3911. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  3912. */
  3913. function isKey(value, object) {
  3914. var type = typeof value;
  3915. if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') {
  3916. return true;
  3917. }
  3918. if (isArray(value)) {
  3919. return false;
  3920. }
  3921. var result = !reIsDeepProp.test(value);
  3922. return result || (object != null && value in toObject(object));
  3923. }
  3924. /**
  3925. * Checks if `func` has a lazy counterpart.
  3926. *
  3927. * @private
  3928. * @param {Function} func The function to check.
  3929. * @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
  3930. */
  3931. function isLaziable(func) {
  3932. var funcName = getFuncName(func),
  3933. other = lodash[funcName];
  3934. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  3935. return false;
  3936. }
  3937. if (func === other) {
  3938. return true;
  3939. }
  3940. var data = getData(other);
  3941. return !!data && func === data[0];
  3942. }
  3943. /**
  3944. * Checks if `value` is a valid array-like length.
  3945. *
  3946. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  3947. *
  3948. * @private
  3949. * @param {*} value The value to check.
  3950. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  3951. */
  3952. function isLength(value) {
  3953. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  3954. }
  3955. /**
  3956. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  3957. *
  3958. * @private
  3959. * @param {*} value The value to check.
  3960. * @returns {boolean} Returns `true` if `value` if suitable for strict
  3961. * equality comparisons, else `false`.
  3962. */
  3963. function isStrictComparable(value) {
  3964. return value === value && !isObject(value);
  3965. }
  3966. /**
  3967. * Merges the function metadata of `source` into `data`.
  3968. *
  3969. * Merging metadata reduces the number of wrappers required to invoke a function.
  3970. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  3971. * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
  3972. * augment function arguments, making the order in which they are executed important,
  3973. * preventing the merging of metadata. However, we make an exception for a safe
  3974. * common case where curried functions have `_.ary` and or `_.rearg` applied.
  3975. *
  3976. * @private
  3977. * @param {Array} data The destination metadata.
  3978. * @param {Array} source The source metadata.
  3979. * @returns {Array} Returns `data`.
  3980. */
  3981. function mergeData(data, source) {
  3982. var bitmask = data[1],
  3983. srcBitmask = source[1],
  3984. newBitmask = bitmask | srcBitmask,
  3985. isCommon = newBitmask < ARY_FLAG;
  3986. var isCombo =
  3987. (srcBitmask == ARY_FLAG && bitmask == CURRY_FLAG) ||
  3988. (srcBitmask == ARY_FLAG && bitmask == REARG_FLAG && data[7].length <= source[8]) ||
  3989. (srcBitmask == (ARY_FLAG | REARG_FLAG) && bitmask == CURRY_FLAG);
  3990. // Exit early if metadata can't be merged.
  3991. if (!(isCommon || isCombo)) {
  3992. return data;
  3993. }
  3994. // Use source `thisArg` if available.
  3995. if (srcBitmask & BIND_FLAG) {
  3996. data[2] = source[2];
  3997. // Set when currying a bound function.
  3998. newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
  3999. }
  4000. // Compose partial arguments.
  4001. var value = source[3];
  4002. if (value) {
  4003. var partials = data[3];
  4004. data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
  4005. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
  4006. }
  4007. // Compose partial right arguments.
  4008. value = source[5];
  4009. if (value) {
  4010. partials = data[5];
  4011. data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
  4012. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
  4013. }
  4014. // Use source `argPos` if available.
  4015. value = source[7];
  4016. if (value) {
  4017. data[7] = arrayCopy(value);
  4018. }
  4019. // Use source `ary` if it's smaller.
  4020. if (srcBitmask & ARY_FLAG) {
  4021. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  4022. }
  4023. // Use source `arity` if one is not provided.
  4024. if (data[9] == null) {
  4025. data[9] = source[9];
  4026. }
  4027. // Use source `func` and merge bitmasks.
  4028. data[0] = source[0];
  4029. data[1] = newBitmask;
  4030. return data;
  4031. }
  4032. /**
  4033. * Used by `_.defaultsDeep` to customize its `_.merge` use.
  4034. *
  4035. * @private
  4036. * @param {*} objectValue The destination object property value.
  4037. * @param {*} sourceValue The source object property value.
  4038. * @returns {*} Returns the value to assign to the destination object.
  4039. */
  4040. function mergeDefaults(objectValue, sourceValue) {
  4041. return objectValue === undefined ? sourceValue : merge(objectValue, sourceValue, mergeDefaults);
  4042. }
  4043. /**
  4044. * A specialized version of `_.pick` which picks `object` properties specified
  4045. * by `props`.
  4046. *
  4047. * @private
  4048. * @param {Object} object The source object.
  4049. * @param {string[]} props The property names to pick.
  4050. * @returns {Object} Returns the new object.
  4051. */
  4052. function pickByArray(object, props) {
  4053. object = toObject(object);
  4054. var index = -1,
  4055. length = props.length,
  4056. result = {};
  4057. while (++index < length) {
  4058. var key = props[index];
  4059. if (key in object) {
  4060. result[key] = object[key];
  4061. }
  4062. }
  4063. return result;
  4064. }
  4065. /**
  4066. * A specialized version of `_.pick` which picks `object` properties `predicate`
  4067. * returns truthy for.
  4068. *
  4069. * @private
  4070. * @param {Object} object The source object.
  4071. * @param {Function} predicate The function invoked per iteration.
  4072. * @returns {Object} Returns the new object.
  4073. */
  4074. function pickByCallback(object, predicate) {
  4075. var result = {};
  4076. baseForIn(object, function(value, key, object) {
  4077. if (predicate(value, key, object)) {
  4078. result[key] = value;
  4079. }
  4080. });
  4081. return result;
  4082. }
  4083. /**
  4084. * Reorder `array` according to the specified indexes where the element at
  4085. * the first index is assigned as the first element, the element at
  4086. * the second index is assigned as the second element, and so on.
  4087. *
  4088. * @private
  4089. * @param {Array} array The array to reorder.
  4090. * @param {Array} indexes The arranged array indexes.
  4091. * @returns {Array} Returns `array`.
  4092. */
  4093. function reorder(array, indexes) {
  4094. var arrLength = array.length,
  4095. length = nativeMin(indexes.length, arrLength),
  4096. oldArray = arrayCopy(array);
  4097. while (length--) {
  4098. var index = indexes[length];
  4099. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  4100. }
  4101. return array;
  4102. }
  4103. /**
  4104. * Sets metadata for `func`.
  4105. *
  4106. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  4107. * period of time, it will trip its breaker and transition to an identity function
  4108. * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
  4109. * for more details.
  4110. *
  4111. * @private
  4112. * @param {Function} func The function to associate metadata with.
  4113. * @param {*} data The metadata.
  4114. * @returns {Function} Returns `func`.
  4115. */
  4116. var setData = (function() {
  4117. var count = 0,
  4118. lastCalled = 0;
  4119. return function(key, value) {
  4120. var stamp = now(),
  4121. remaining = HOT_SPAN - (stamp - lastCalled);
  4122. lastCalled = stamp;
  4123. if (remaining > 0) {
  4124. if (++count >= HOT_COUNT) {
  4125. return key;
  4126. }
  4127. } else {
  4128. count = 0;
  4129. }
  4130. return baseSetData(key, value);
  4131. };
  4132. }());
  4133. /**
  4134. * A fallback implementation of `Object.keys` which creates an array of the
  4135. * own enumerable property names of `object`.
  4136. *
  4137. * @private
  4138. * @param {Object} object The object to query.
  4139. * @returns {Array} Returns the array of property names.
  4140. */
  4141. function shimKeys(object) {
  4142. var props = keysIn(object),
  4143. propsLength = props.length,
  4144. length = propsLength && object.length;
  4145. var allowIndexes = !!length && isLength(length) &&
  4146. (isArray(object) || isArguments(object) || isString(object));
  4147. var index = -1,
  4148. result = [];
  4149. while (++index < propsLength) {
  4150. var key = props[index];
  4151. if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
  4152. result.push(key);
  4153. }
  4154. }
  4155. return result;
  4156. }
  4157. /**
  4158. * Converts `value` to an array-like object if it's not one.
  4159. *
  4160. * @private
  4161. * @param {*} value The value to process.
  4162. * @returns {Array|Object} Returns the array-like object.
  4163. */
  4164. function toIterable(value) {
  4165. if (value == null) {
  4166. return [];
  4167. }
  4168. if (!isArrayLike(value)) {
  4169. return values(value);
  4170. }
  4171. if (lodash.support.unindexedChars && isString(value)) {
  4172. return value.split('');
  4173. }
  4174. return isObject(value) ? value : Object(value);
  4175. }
  4176. /**
  4177. * Converts `value` to an object if it's not one.
  4178. *
  4179. * @private
  4180. * @param {*} value The value to process.
  4181. * @returns {Object} Returns the object.
  4182. */
  4183. function toObject(value) {
  4184. if (lodash.support.unindexedChars && isString(value)) {
  4185. var index = -1,
  4186. length = value.length,
  4187. result = Object(value);
  4188. while (++index < length) {
  4189. result[index] = value.charAt(index);
  4190. }
  4191. return result;
  4192. }
  4193. return isObject(value) ? value : Object(value);
  4194. }
  4195. /**
  4196. * Converts `value` to property path array if it's not one.
  4197. *
  4198. * @private
  4199. * @param {*} value The value to process.
  4200. * @returns {Array} Returns the property path array.
  4201. */
  4202. function toPath(value) {
  4203. if (isArray(value)) {
  4204. return value;
  4205. }
  4206. var result = [];
  4207. baseToString(value).replace(rePropName, function(match, number, quote, string) {
  4208. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  4209. });
  4210. return result;
  4211. }
  4212. /**
  4213. * Creates a clone of `wrapper`.
  4214. *
  4215. * @private
  4216. * @param {Object} wrapper The wrapper to clone.
  4217. * @returns {Object} Returns the cloned wrapper.
  4218. */
  4219. function wrapperClone(wrapper) {
  4220. return wrapper instanceof LazyWrapper
  4221. ? wrapper.clone()
  4222. : new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
  4223. }
  4224. /*------------------------------------------------------------------------*/
  4225. /**
  4226. * Creates an array of elements split into groups the length of `size`.
  4227. * If `collection` can't be split evenly, the final chunk will be the remaining
  4228. * elements.
  4229. *
  4230. * @static
  4231. * @memberOf _
  4232. * @category Array
  4233. * @param {Array} array The array to process.
  4234. * @param {number} [size=1] The length of each chunk.
  4235. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  4236. * @returns {Array} Returns the new array containing chunks.
  4237. * @example
  4238. *
  4239. * _.chunk(['a', 'b', 'c', 'd'], 2);
  4240. * // => [['a', 'b'], ['c', 'd']]
  4241. *
  4242. * _.chunk(['a', 'b', 'c', 'd'], 3);
  4243. * // => [['a', 'b', 'c'], ['d']]
  4244. */
  4245. function chunk(array, size, guard) {
  4246. if (guard ? isIterateeCall(array, size, guard) : size == null) {
  4247. size = 1;
  4248. } else {
  4249. size = nativeMax(nativeFloor(size) || 1, 1);
  4250. }
  4251. var index = 0,
  4252. length = array ? array.length : 0,
  4253. resIndex = -1,
  4254. result = Array(nativeCeil(length / size));
  4255. while (index < length) {
  4256. result[++resIndex] = baseSlice(array, index, (index += size));
  4257. }
  4258. return result;
  4259. }
  4260. /**
  4261. * Creates an array with all falsey values removed. The values `false`, `null`,
  4262. * `0`, `""`, `undefined`, and `NaN` are falsey.
  4263. *
  4264. * @static
  4265. * @memberOf _
  4266. * @category Array
  4267. * @param {Array} array The array to compact.
  4268. * @returns {Array} Returns the new array of filtered values.
  4269. * @example
  4270. *
  4271. * _.compact([0, 1, false, 2, '', 3]);
  4272. * // => [1, 2, 3]
  4273. */
  4274. function compact(array) {
  4275. var index = -1,
  4276. length = array ? array.length : 0,
  4277. resIndex = -1,
  4278. result = [];
  4279. while (++index < length) {
  4280. var value = array[index];
  4281. if (value) {
  4282. result[++resIndex] = value;
  4283. }
  4284. }
  4285. return result;
  4286. }
  4287. /**
  4288. * Creates an array of unique `array` values not included in the other
  4289. * provided arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  4290. * for equality comparisons.
  4291. *
  4292. * @static
  4293. * @memberOf _
  4294. * @category Array
  4295. * @param {Array} array The array to inspect.
  4296. * @param {...Array} [values] The arrays of values to exclude.
  4297. * @returns {Array} Returns the new array of filtered values.
  4298. * @example
  4299. *
  4300. * _.difference([1, 2, 3], [4, 2]);
  4301. * // => [1, 3]
  4302. */
  4303. var difference = restParam(function(array, values) {
  4304. return (isObjectLike(array) && isArrayLike(array))
  4305. ? baseDifference(array, baseFlatten(values, false, true))
  4306. : [];
  4307. });
  4308. /**
  4309. * Creates a slice of `array` with `n` elements dropped from the beginning.
  4310. *
  4311. * @static
  4312. * @memberOf _
  4313. * @category Array
  4314. * @param {Array} array The array to query.
  4315. * @param {number} [n=1] The number of elements to drop.
  4316. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  4317. * @returns {Array} Returns the slice of `array`.
  4318. * @example
  4319. *
  4320. * _.drop([1, 2, 3]);
  4321. * // => [2, 3]
  4322. *
  4323. * _.drop([1, 2, 3], 2);
  4324. * // => [3]
  4325. *
  4326. * _.drop([1, 2, 3], 5);
  4327. * // => []
  4328. *
  4329. * _.drop([1, 2, 3], 0);
  4330. * // => [1, 2, 3]
  4331. */
  4332. function drop(array, n, guard) {
  4333. var length = array ? array.length : 0;
  4334. if (!length) {
  4335. return [];
  4336. }
  4337. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  4338. n = 1;
  4339. }
  4340. return baseSlice(array, n < 0 ? 0 : n);
  4341. }
  4342. /**
  4343. * Creates a slice of `array` with `n` elements dropped from the end.
  4344. *
  4345. * @static
  4346. * @memberOf _
  4347. * @category Array
  4348. * @param {Array} array The array to query.
  4349. * @param {number} [n=1] The number of elements to drop.
  4350. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  4351. * @returns {Array} Returns the slice of `array`.
  4352. * @example
  4353. *
  4354. * _.dropRight([1, 2, 3]);
  4355. * // => [1, 2]
  4356. *
  4357. * _.dropRight([1, 2, 3], 2);
  4358. * // => [1]
  4359. *
  4360. * _.dropRight([1, 2, 3], 5);
  4361. * // => []
  4362. *
  4363. * _.dropRight([1, 2, 3], 0);
  4364. * // => [1, 2, 3]
  4365. */
  4366. function dropRight(array, n, guard) {
  4367. var length = array ? array.length : 0;
  4368. if (!length) {
  4369. return [];
  4370. }
  4371. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  4372. n = 1;
  4373. }
  4374. n = length - (+n || 0);
  4375. return baseSlice(array, 0, n < 0 ? 0 : n);
  4376. }
  4377. /**
  4378. * Creates a slice of `array` excluding elements dropped from the end.
  4379. * Elements are dropped until `predicate` returns falsey. The predicate is
  4380. * bound to `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 match the properties of the given
  4391. * object, else `false`.
  4392. *
  4393. * @static
  4394. * @memberOf _
  4395. * @category Array
  4396. * @param {Array} array The array to query.
  4397. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4398. * per iteration.
  4399. * @param {*} [thisArg] The `this` binding of `predicate`.
  4400. * @returns {Array} Returns the slice of `array`.
  4401. * @example
  4402. *
  4403. * _.dropRightWhile([1, 2, 3], function(n) {
  4404. * return n > 1;
  4405. * });
  4406. * // => [1]
  4407. *
  4408. * var users = [
  4409. * { 'user': 'barney', 'active': true },
  4410. * { 'user': 'fred', 'active': false },
  4411. * { 'user': 'pebbles', 'active': false }
  4412. * ];
  4413. *
  4414. * // using the `_.matches` callback shorthand
  4415. * _.pluck(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
  4416. * // => ['barney', 'fred']
  4417. *
  4418. * // using the `_.matchesProperty` callback shorthand
  4419. * _.pluck(_.dropRightWhile(users, 'active', false), 'user');
  4420. * // => ['barney']
  4421. *
  4422. * // using the `_.property` callback shorthand
  4423. * _.pluck(_.dropRightWhile(users, 'active'), 'user');
  4424. * // => ['barney', 'fred', 'pebbles']
  4425. */
  4426. function dropRightWhile(array, predicate, thisArg) {
  4427. return (array && array.length)
  4428. ? baseWhile(array, getCallback(predicate, thisArg, 3), true, true)
  4429. : [];
  4430. }
  4431. /**
  4432. * Creates a slice of `array` excluding elements dropped from the beginning.
  4433. * Elements are dropped until `predicate` returns falsey. The predicate is
  4434. * bound to `thisArg` and invoked with three arguments: (value, index, array).
  4435. *
  4436. * If a property name is provided for `predicate` the created `_.property`
  4437. * style callback returns the property value of the given element.
  4438. *
  4439. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4440. * style callback returns `true` for elements that have a matching property
  4441. * value, else `false`.
  4442. *
  4443. * If an object is provided for `predicate` the created `_.matches` style
  4444. * callback returns `true` for elements that have the properties of the given
  4445. * object, else `false`.
  4446. *
  4447. * @static
  4448. * @memberOf _
  4449. * @category Array
  4450. * @param {Array} array The array to query.
  4451. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4452. * per iteration.
  4453. * @param {*} [thisArg] The `this` binding of `predicate`.
  4454. * @returns {Array} Returns the slice of `array`.
  4455. * @example
  4456. *
  4457. * _.dropWhile([1, 2, 3], function(n) {
  4458. * return n < 3;
  4459. * });
  4460. * // => [3]
  4461. *
  4462. * var users = [
  4463. * { 'user': 'barney', 'active': false },
  4464. * { 'user': 'fred', 'active': false },
  4465. * { 'user': 'pebbles', 'active': true }
  4466. * ];
  4467. *
  4468. * // using the `_.matches` callback shorthand
  4469. * _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
  4470. * // => ['fred', 'pebbles']
  4471. *
  4472. * // using the `_.matchesProperty` callback shorthand
  4473. * _.pluck(_.dropWhile(users, 'active', false), 'user');
  4474. * // => ['pebbles']
  4475. *
  4476. * // using the `_.property` callback shorthand
  4477. * _.pluck(_.dropWhile(users, 'active'), 'user');
  4478. * // => ['barney', 'fred', 'pebbles']
  4479. */
  4480. function dropWhile(array, predicate, thisArg) {
  4481. return (array && array.length)
  4482. ? baseWhile(array, getCallback(predicate, thisArg, 3), true)
  4483. : [];
  4484. }
  4485. /**
  4486. * Fills elements of `array` with `value` from `start` up to, but not
  4487. * including, `end`.
  4488. *
  4489. * **Note:** This method mutates `array`.
  4490. *
  4491. * @static
  4492. * @memberOf _
  4493. * @category Array
  4494. * @param {Array} array The array to fill.
  4495. * @param {*} value The value to fill `array` with.
  4496. * @param {number} [start=0] The start position.
  4497. * @param {number} [end=array.length] The end position.
  4498. * @returns {Array} Returns `array`.
  4499. * @example
  4500. *
  4501. * var array = [1, 2, 3];
  4502. *
  4503. * _.fill(array, 'a');
  4504. * console.log(array);
  4505. * // => ['a', 'a', 'a']
  4506. *
  4507. * _.fill(Array(3), 2);
  4508. * // => [2, 2, 2]
  4509. *
  4510. * _.fill([4, 6, 8], '*', 1, 2);
  4511. * // => [4, '*', 8]
  4512. */
  4513. function fill(array, value, start, end) {
  4514. var length = array ? array.length : 0;
  4515. if (!length) {
  4516. return [];
  4517. }
  4518. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  4519. start = 0;
  4520. end = length;
  4521. }
  4522. return baseFill(array, value, start, end);
  4523. }
  4524. /**
  4525. * This method is like `_.find` except that it returns the index of the first
  4526. * element `predicate` returns truthy for instead of the element itself.
  4527. *
  4528. * If a property name is provided for `predicate` the created `_.property`
  4529. * style callback returns the property value of the given element.
  4530. *
  4531. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4532. * style callback returns `true` for elements that have a matching property
  4533. * value, else `false`.
  4534. *
  4535. * If an object is provided for `predicate` the created `_.matches` style
  4536. * callback returns `true` for elements that have the properties of the given
  4537. * object, else `false`.
  4538. *
  4539. * @static
  4540. * @memberOf _
  4541. * @category Array
  4542. * @param {Array} array The array to search.
  4543. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4544. * per iteration.
  4545. * @param {*} [thisArg] The `this` binding of `predicate`.
  4546. * @returns {number} Returns the index of the found element, else `-1`.
  4547. * @example
  4548. *
  4549. * var users = [
  4550. * { 'user': 'barney', 'active': false },
  4551. * { 'user': 'fred', 'active': false },
  4552. * { 'user': 'pebbles', 'active': true }
  4553. * ];
  4554. *
  4555. * _.findIndex(users, function(chr) {
  4556. * return chr.user == 'barney';
  4557. * });
  4558. * // => 0
  4559. *
  4560. * // using the `_.matches` callback shorthand
  4561. * _.findIndex(users, { 'user': 'fred', 'active': false });
  4562. * // => 1
  4563. *
  4564. * // using the `_.matchesProperty` callback shorthand
  4565. * _.findIndex(users, 'active', false);
  4566. * // => 0
  4567. *
  4568. * // using the `_.property` callback shorthand
  4569. * _.findIndex(users, 'active');
  4570. * // => 2
  4571. */
  4572. var findIndex = createFindIndex();
  4573. /**
  4574. * This method is like `_.findIndex` except that it iterates over elements
  4575. * of `collection` from right to left.
  4576. *
  4577. * If a property name is provided for `predicate` the created `_.property`
  4578. * style callback returns the property value of the given element.
  4579. *
  4580. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4581. * style callback returns `true` for elements that have a matching property
  4582. * value, else `false`.
  4583. *
  4584. * If an object is provided for `predicate` the created `_.matches` style
  4585. * callback returns `true` for elements that have the properties of the given
  4586. * object, else `false`.
  4587. *
  4588. * @static
  4589. * @memberOf _
  4590. * @category Array
  4591. * @param {Array} array The array to search.
  4592. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4593. * per iteration.
  4594. * @param {*} [thisArg] The `this` binding of `predicate`.
  4595. * @returns {number} Returns the index of the found element, else `-1`.
  4596. * @example
  4597. *
  4598. * var users = [
  4599. * { 'user': 'barney', 'active': true },
  4600. * { 'user': 'fred', 'active': false },
  4601. * { 'user': 'pebbles', 'active': false }
  4602. * ];
  4603. *
  4604. * _.findLastIndex(users, function(chr) {
  4605. * return chr.user == 'pebbles';
  4606. * });
  4607. * // => 2
  4608. *
  4609. * // using the `_.matches` callback shorthand
  4610. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  4611. * // => 0
  4612. *
  4613. * // using the `_.matchesProperty` callback shorthand
  4614. * _.findLastIndex(users, 'active', false);
  4615. * // => 2
  4616. *
  4617. * // using the `_.property` callback shorthand
  4618. * _.findLastIndex(users, 'active');
  4619. * // => 0
  4620. */
  4621. var findLastIndex = createFindIndex(true);
  4622. /**
  4623. * Gets the first element of `array`.
  4624. *
  4625. * @static
  4626. * @memberOf _
  4627. * @alias head
  4628. * @category Array
  4629. * @param {Array} array The array to query.
  4630. * @returns {*} Returns the first element of `array`.
  4631. * @example
  4632. *
  4633. * _.first([1, 2, 3]);
  4634. * // => 1
  4635. *
  4636. * _.first([]);
  4637. * // => undefined
  4638. */
  4639. function first(array) {
  4640. return array ? array[0] : undefined;
  4641. }
  4642. /**
  4643. * Flattens a nested array. If `isDeep` is `true` the array is recursively
  4644. * flattened, otherwise it's only flattened a single level.
  4645. *
  4646. * @static
  4647. * @memberOf _
  4648. * @category Array
  4649. * @param {Array} array The array to flatten.
  4650. * @param {boolean} [isDeep] Specify a deep flatten.
  4651. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  4652. * @returns {Array} Returns the new flattened array.
  4653. * @example
  4654. *
  4655. * _.flatten([1, [2, 3, [4]]]);
  4656. * // => [1, 2, 3, [4]]
  4657. *
  4658. * // using `isDeep`
  4659. * _.flatten([1, [2, 3, [4]]], true);
  4660. * // => [1, 2, 3, 4]
  4661. */
  4662. function flatten(array, isDeep, guard) {
  4663. var length = array ? array.length : 0;
  4664. if (guard && isIterateeCall(array, isDeep, guard)) {
  4665. isDeep = false;
  4666. }
  4667. return length ? baseFlatten(array, isDeep) : [];
  4668. }
  4669. /**
  4670. * Recursively flattens a nested array.
  4671. *
  4672. * @static
  4673. * @memberOf _
  4674. * @category Array
  4675. * @param {Array} array The array to recursively flatten.
  4676. * @returns {Array} Returns the new flattened array.
  4677. * @example
  4678. *
  4679. * _.flattenDeep([1, [2, 3, [4]]]);
  4680. * // => [1, 2, 3, 4]
  4681. */
  4682. function flattenDeep(array) {
  4683. var length = array ? array.length : 0;
  4684. return length ? baseFlatten(array, true) : [];
  4685. }
  4686. /**
  4687. * Gets the index at which the first occurrence of `value` is found in `array`
  4688. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  4689. * for equality comparisons. If `fromIndex` is negative, it's used as the offset
  4690. * from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
  4691. * performs a faster binary search.
  4692. *
  4693. * @static
  4694. * @memberOf _
  4695. * @category Array
  4696. * @param {Array} array The array to search.
  4697. * @param {*} value The value to search for.
  4698. * @param {boolean|number} [fromIndex=0] The index to search from or `true`
  4699. * to perform a binary search on a sorted array.
  4700. * @returns {number} Returns the index of the matched value, else `-1`.
  4701. * @example
  4702. *
  4703. * _.indexOf([1, 2, 1, 2], 2);
  4704. * // => 1
  4705. *
  4706. * // using `fromIndex`
  4707. * _.indexOf([1, 2, 1, 2], 2, 2);
  4708. * // => 3
  4709. *
  4710. * // performing a binary search
  4711. * _.indexOf([1, 1, 2, 2], 2, true);
  4712. * // => 2
  4713. */
  4714. function indexOf(array, value, fromIndex) {
  4715. var length = array ? array.length : 0;
  4716. if (!length) {
  4717. return -1;
  4718. }
  4719. if (typeof fromIndex == 'number') {
  4720. fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
  4721. } else if (fromIndex) {
  4722. var index = binaryIndex(array, value);
  4723. if (index < length &&
  4724. (value === value ? (value === array[index]) : (array[index] !== array[index]))) {
  4725. return index;
  4726. }
  4727. return -1;
  4728. }
  4729. return baseIndexOf(array, value, fromIndex || 0);
  4730. }
  4731. /**
  4732. * Gets all but the last element of `array`.
  4733. *
  4734. * @static
  4735. * @memberOf _
  4736. * @category Array
  4737. * @param {Array} array The array to query.
  4738. * @returns {Array} Returns the slice of `array`.
  4739. * @example
  4740. *
  4741. * _.initial([1, 2, 3]);
  4742. * // => [1, 2]
  4743. */
  4744. function initial(array) {
  4745. return dropRight(array, 1);
  4746. }
  4747. /**
  4748. * Creates an array of unique values that are included in all of the provided
  4749. * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  4750. * for equality comparisons.
  4751. *
  4752. * @static
  4753. * @memberOf _
  4754. * @category Array
  4755. * @param {...Array} [arrays] The arrays to inspect.
  4756. * @returns {Array} Returns the new array of shared values.
  4757. * @example
  4758. * _.intersection([1, 2], [4, 2], [2, 1]);
  4759. * // => [2]
  4760. */
  4761. var intersection = restParam(function(arrays) {
  4762. var othLength = arrays.length,
  4763. othIndex = othLength,
  4764. caches = Array(length),
  4765. indexOf = getIndexOf(),
  4766. isCommon = indexOf === baseIndexOf,
  4767. result = [];
  4768. while (othIndex--) {
  4769. var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : [];
  4770. caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null;
  4771. }
  4772. var array = arrays[0],
  4773. index = -1,
  4774. length = array ? array.length : 0,
  4775. seen = caches[0];
  4776. outer:
  4777. while (++index < length) {
  4778. value = array[index];
  4779. if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
  4780. var othIndex = othLength;
  4781. while (--othIndex) {
  4782. var cache = caches[othIndex];
  4783. if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) {
  4784. continue outer;
  4785. }
  4786. }
  4787. if (seen) {
  4788. seen.push(value);
  4789. }
  4790. result.push(value);
  4791. }
  4792. }
  4793. return result;
  4794. });
  4795. /**
  4796. * Gets the last element of `array`.
  4797. *
  4798. * @static
  4799. * @memberOf _
  4800. * @category Array
  4801. * @param {Array} array The array to query.
  4802. * @returns {*} Returns the last element of `array`.
  4803. * @example
  4804. *
  4805. * _.last([1, 2, 3]);
  4806. * // => 3
  4807. */
  4808. function last(array) {
  4809. var length = array ? array.length : 0;
  4810. return length ? array[length - 1] : undefined;
  4811. }
  4812. /**
  4813. * This method is like `_.indexOf` except that it iterates over elements of
  4814. * `array` from right to left.
  4815. *
  4816. * @static
  4817. * @memberOf _
  4818. * @category Array
  4819. * @param {Array} array The array to search.
  4820. * @param {*} value The value to search for.
  4821. * @param {boolean|number} [fromIndex=array.length-1] The index to search from
  4822. * or `true` to perform a binary search on a sorted array.
  4823. * @returns {number} Returns the index of the matched value, else `-1`.
  4824. * @example
  4825. *
  4826. * _.lastIndexOf([1, 2, 1, 2], 2);
  4827. * // => 3
  4828. *
  4829. * // using `fromIndex`
  4830. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  4831. * // => 1
  4832. *
  4833. * // performing a binary search
  4834. * _.lastIndexOf([1, 1, 2, 2], 2, true);
  4835. * // => 3
  4836. */
  4837. function lastIndexOf(array, value, fromIndex) {
  4838. var length = array ? array.length : 0;
  4839. if (!length) {
  4840. return -1;
  4841. }
  4842. var index = length;
  4843. if (typeof fromIndex == 'number') {
  4844. index = (fromIndex < 0 ? nativeMax(length + fromIndex, 0) : nativeMin(fromIndex || 0, length - 1)) + 1;
  4845. } else if (fromIndex) {
  4846. index = binaryIndex(array, value, true) - 1;
  4847. var other = array[index];
  4848. if (value === value ? (value === other) : (other !== other)) {
  4849. return index;
  4850. }
  4851. return -1;
  4852. }
  4853. if (value !== value) {
  4854. return indexOfNaN(array, index, true);
  4855. }
  4856. while (index--) {
  4857. if (array[index] === value) {
  4858. return index;
  4859. }
  4860. }
  4861. return -1;
  4862. }
  4863. /**
  4864. * Removes all provided values from `array` using
  4865. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  4866. * for equality comparisons.
  4867. *
  4868. * **Note:** Unlike `_.without`, this method mutates `array`.
  4869. *
  4870. * @static
  4871. * @memberOf _
  4872. * @category Array
  4873. * @param {Array} array The array to modify.
  4874. * @param {...*} [values] The values to remove.
  4875. * @returns {Array} Returns `array`.
  4876. * @example
  4877. *
  4878. * var array = [1, 2, 3, 1, 2, 3];
  4879. *
  4880. * _.pull(array, 2, 3);
  4881. * console.log(array);
  4882. * // => [1, 1]
  4883. */
  4884. function pull() {
  4885. var args = arguments,
  4886. array = args[0];
  4887. if (!(array && array.length)) {
  4888. return array;
  4889. }
  4890. var index = 0,
  4891. indexOf = getIndexOf(),
  4892. length = args.length;
  4893. while (++index < length) {
  4894. var fromIndex = 0,
  4895. value = args[index];
  4896. while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
  4897. splice.call(array, fromIndex, 1);
  4898. }
  4899. }
  4900. return array;
  4901. }
  4902. /**
  4903. * Removes elements from `array` corresponding to the given indexes and returns
  4904. * an array of the removed elements. Indexes may be specified as an array of
  4905. * indexes or as individual arguments.
  4906. *
  4907. * **Note:** Unlike `_.at`, this method mutates `array`.
  4908. *
  4909. * @static
  4910. * @memberOf _
  4911. * @category Array
  4912. * @param {Array} array The array to modify.
  4913. * @param {...(number|number[])} [indexes] The indexes of elements to remove,
  4914. * specified as individual indexes or arrays of indexes.
  4915. * @returns {Array} Returns the new array of removed elements.
  4916. * @example
  4917. *
  4918. * var array = [5, 10, 15, 20];
  4919. * var evens = _.pullAt(array, 1, 3);
  4920. *
  4921. * console.log(array);
  4922. * // => [5, 15]
  4923. *
  4924. * console.log(evens);
  4925. * // => [10, 20]
  4926. */
  4927. var pullAt = restParam(function(array, indexes) {
  4928. indexes = baseFlatten(indexes);
  4929. var result = baseAt(array, indexes);
  4930. basePullAt(array, indexes.sort(baseCompareAscending));
  4931. return result;
  4932. });
  4933. /**
  4934. * Removes all elements from `array` that `predicate` returns truthy for
  4935. * and returns an array of the removed elements. The predicate is bound to
  4936. * `thisArg` and invoked with three arguments: (value, index, array).
  4937. *
  4938. * If a property name is provided for `predicate` the created `_.property`
  4939. * style callback returns the property value of the given element.
  4940. *
  4941. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4942. * style callback returns `true` for elements that have a matching property
  4943. * value, else `false`.
  4944. *
  4945. * If an object is provided for `predicate` the created `_.matches` style
  4946. * callback returns `true` for elements that have the properties of the given
  4947. * object, else `false`.
  4948. *
  4949. * **Note:** Unlike `_.filter`, this method mutates `array`.
  4950. *
  4951. * @static
  4952. * @memberOf _
  4953. * @category Array
  4954. * @param {Array} array The array to modify.
  4955. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4956. * per iteration.
  4957. * @param {*} [thisArg] The `this` binding of `predicate`.
  4958. * @returns {Array} Returns the new array of removed elements.
  4959. * @example
  4960. *
  4961. * var array = [1, 2, 3, 4];
  4962. * var evens = _.remove(array, function(n) {
  4963. * return n % 2 == 0;
  4964. * });
  4965. *
  4966. * console.log(array);
  4967. * // => [1, 3]
  4968. *
  4969. * console.log(evens);
  4970. * // => [2, 4]
  4971. */
  4972. function remove(array, predicate, thisArg) {
  4973. var result = [];
  4974. if (!(array && array.length)) {
  4975. return result;
  4976. }
  4977. var index = -1,
  4978. indexes = [],
  4979. length = array.length;
  4980. predicate = getCallback(predicate, thisArg, 3);
  4981. while (++index < length) {
  4982. var value = array[index];
  4983. if (predicate(value, index, array)) {
  4984. result.push(value);
  4985. indexes.push(index);
  4986. }
  4987. }
  4988. basePullAt(array, indexes);
  4989. return result;
  4990. }
  4991. /**
  4992. * Gets all but the first element of `array`.
  4993. *
  4994. * @static
  4995. * @memberOf _
  4996. * @alias tail
  4997. * @category Array
  4998. * @param {Array} array The array to query.
  4999. * @returns {Array} Returns the slice of `array`.
  5000. * @example
  5001. *
  5002. * _.rest([1, 2, 3]);
  5003. * // => [2, 3]
  5004. */
  5005. function rest(array) {
  5006. return drop(array, 1);
  5007. }
  5008. /**
  5009. * Creates a slice of `array` from `start` up to, but not including, `end`.
  5010. *
  5011. * **Note:** This method is used instead of `Array#slice` to support node
  5012. * lists in IE < 9 and to ensure dense arrays are returned.
  5013. *
  5014. * @static
  5015. * @memberOf _
  5016. * @category Array
  5017. * @param {Array} array The array to slice.
  5018. * @param {number} [start=0] The start position.
  5019. * @param {number} [end=array.length] The end position.
  5020. * @returns {Array} Returns the slice of `array`.
  5021. */
  5022. function slice(array, start, end) {
  5023. var length = array ? array.length : 0;
  5024. if (!length) {
  5025. return [];
  5026. }
  5027. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  5028. start = 0;
  5029. end = length;
  5030. }
  5031. return baseSlice(array, start, end);
  5032. }
  5033. /**
  5034. * Uses a binary search to determine the lowest index at which `value` should
  5035. * be inserted into `array` in order to maintain its sort order. If an iteratee
  5036. * function is provided it's invoked for `value` and each element of `array`
  5037. * to compute their sort ranking. The iteratee is bound to `thisArg` and
  5038. * invoked with one argument; (value).
  5039. *
  5040. * If a property name is provided for `iteratee` the created `_.property`
  5041. * style callback returns the property value of the given element.
  5042. *
  5043. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5044. * style callback returns `true` for elements that have a matching property
  5045. * value, else `false`.
  5046. *
  5047. * If an object is provided for `iteratee` the created `_.matches` style
  5048. * callback returns `true` for elements that have the properties of the given
  5049. * object, else `false`.
  5050. *
  5051. * @static
  5052. * @memberOf _
  5053. * @category Array
  5054. * @param {Array} array The sorted array to inspect.
  5055. * @param {*} value The value to evaluate.
  5056. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  5057. * per iteration.
  5058. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5059. * @returns {number} Returns the index at which `value` should be inserted
  5060. * into `array`.
  5061. * @example
  5062. *
  5063. * _.sortedIndex([30, 50], 40);
  5064. * // => 1
  5065. *
  5066. * _.sortedIndex([4, 4, 5, 5], 5);
  5067. * // => 2
  5068. *
  5069. * var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
  5070. *
  5071. * // using an iteratee function
  5072. * _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
  5073. * return this.data[word];
  5074. * }, dict);
  5075. * // => 1
  5076. *
  5077. * // using the `_.property` callback shorthand
  5078. * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
  5079. * // => 1
  5080. */
  5081. var sortedIndex = createSortedIndex();
  5082. /**
  5083. * This method is like `_.sortedIndex` except that it returns the highest
  5084. * index at which `value` should be inserted into `array` in order to
  5085. * maintain its sort order.
  5086. *
  5087. * @static
  5088. * @memberOf _
  5089. * @category Array
  5090. * @param {Array} array The sorted array to inspect.
  5091. * @param {*} value The value to evaluate.
  5092. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  5093. * per iteration.
  5094. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5095. * @returns {number} Returns the index at which `value` should be inserted
  5096. * into `array`.
  5097. * @example
  5098. *
  5099. * _.sortedLastIndex([4, 4, 5, 5], 5);
  5100. * // => 4
  5101. */
  5102. var sortedLastIndex = createSortedIndex(true);
  5103. /**
  5104. * Creates a slice of `array` with `n` elements taken from the beginning.
  5105. *
  5106. * @static
  5107. * @memberOf _
  5108. * @category Array
  5109. * @param {Array} array The array to query.
  5110. * @param {number} [n=1] The number of elements to take.
  5111. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  5112. * @returns {Array} Returns the slice of `array`.
  5113. * @example
  5114. *
  5115. * _.take([1, 2, 3]);
  5116. * // => [1]
  5117. *
  5118. * _.take([1, 2, 3], 2);
  5119. * // => [1, 2]
  5120. *
  5121. * _.take([1, 2, 3], 5);
  5122. * // => [1, 2, 3]
  5123. *
  5124. * _.take([1, 2, 3], 0);
  5125. * // => []
  5126. */
  5127. function take(array, n, guard) {
  5128. var length = array ? array.length : 0;
  5129. if (!length) {
  5130. return [];
  5131. }
  5132. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  5133. n = 1;
  5134. }
  5135. return baseSlice(array, 0, n < 0 ? 0 : n);
  5136. }
  5137. /**
  5138. * Creates a slice of `array` with `n` elements taken from the end.
  5139. *
  5140. * @static
  5141. * @memberOf _
  5142. * @category Array
  5143. * @param {Array} array The array to query.
  5144. * @param {number} [n=1] The number of elements to take.
  5145. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  5146. * @returns {Array} Returns the slice of `array`.
  5147. * @example
  5148. *
  5149. * _.takeRight([1, 2, 3]);
  5150. * // => [3]
  5151. *
  5152. * _.takeRight([1, 2, 3], 2);
  5153. * // => [2, 3]
  5154. *
  5155. * _.takeRight([1, 2, 3], 5);
  5156. * // => [1, 2, 3]
  5157. *
  5158. * _.takeRight([1, 2, 3], 0);
  5159. * // => []
  5160. */
  5161. function takeRight(array, n, guard) {
  5162. var length = array ? array.length : 0;
  5163. if (!length) {
  5164. return [];
  5165. }
  5166. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  5167. n = 1;
  5168. }
  5169. n = length - (+n || 0);
  5170. return baseSlice(array, n < 0 ? 0 : n);
  5171. }
  5172. /**
  5173. * Creates a slice of `array` with elements taken from the end. Elements are
  5174. * taken until `predicate` returns falsey. The predicate is bound to `thisArg`
  5175. * and invoked with three arguments: (value, index, array).
  5176. *
  5177. * If a property name is provided for `predicate` the created `_.property`
  5178. * style callback returns the property value of the given element.
  5179. *
  5180. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5181. * style callback returns `true` for elements that have a matching property
  5182. * value, else `false`.
  5183. *
  5184. * If an object is provided for `predicate` the created `_.matches` style
  5185. * callback returns `true` for elements that have the properties of the given
  5186. * object, else `false`.
  5187. *
  5188. * @static
  5189. * @memberOf _
  5190. * @category Array
  5191. * @param {Array} array The array to query.
  5192. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  5193. * per iteration.
  5194. * @param {*} [thisArg] The `this` binding of `predicate`.
  5195. * @returns {Array} Returns the slice of `array`.
  5196. * @example
  5197. *
  5198. * _.takeRightWhile([1, 2, 3], function(n) {
  5199. * return n > 1;
  5200. * });
  5201. * // => [2, 3]
  5202. *
  5203. * var users = [
  5204. * { 'user': 'barney', 'active': true },
  5205. * { 'user': 'fred', 'active': false },
  5206. * { 'user': 'pebbles', 'active': false }
  5207. * ];
  5208. *
  5209. * // using the `_.matches` callback shorthand
  5210. * _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
  5211. * // => ['pebbles']
  5212. *
  5213. * // using the `_.matchesProperty` callback shorthand
  5214. * _.pluck(_.takeRightWhile(users, 'active', false), 'user');
  5215. * // => ['fred', 'pebbles']
  5216. *
  5217. * // using the `_.property` callback shorthand
  5218. * _.pluck(_.takeRightWhile(users, 'active'), 'user');
  5219. * // => []
  5220. */
  5221. function takeRightWhile(array, predicate, thisArg) {
  5222. return (array && array.length)
  5223. ? baseWhile(array, getCallback(predicate, thisArg, 3), false, true)
  5224. : [];
  5225. }
  5226. /**
  5227. * Creates a slice of `array` with elements taken from the beginning. Elements
  5228. * are taken until `predicate` returns falsey. The predicate is bound to
  5229. * `thisArg` and invoked with three arguments: (value, index, array).
  5230. *
  5231. * If a property name is provided for `predicate` the created `_.property`
  5232. * style callback returns the property value of the given element.
  5233. *
  5234. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5235. * style callback returns `true` for elements that have a matching property
  5236. * value, else `false`.
  5237. *
  5238. * If an object is provided for `predicate` the created `_.matches` style
  5239. * callback returns `true` for elements that have the properties of the given
  5240. * object, else `false`.
  5241. *
  5242. * @static
  5243. * @memberOf _
  5244. * @category Array
  5245. * @param {Array} array The array to query.
  5246. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  5247. * per iteration.
  5248. * @param {*} [thisArg] The `this` binding of `predicate`.
  5249. * @returns {Array} Returns the slice of `array`.
  5250. * @example
  5251. *
  5252. * _.takeWhile([1, 2, 3], function(n) {
  5253. * return n < 3;
  5254. * });
  5255. * // => [1, 2]
  5256. *
  5257. * var users = [
  5258. * { 'user': 'barney', 'active': false },
  5259. * { 'user': 'fred', 'active': false},
  5260. * { 'user': 'pebbles', 'active': true }
  5261. * ];
  5262. *
  5263. * // using the `_.matches` callback shorthand
  5264. * _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
  5265. * // => ['barney']
  5266. *
  5267. * // using the `_.matchesProperty` callback shorthand
  5268. * _.pluck(_.takeWhile(users, 'active', false), 'user');
  5269. * // => ['barney', 'fred']
  5270. *
  5271. * // using the `_.property` callback shorthand
  5272. * _.pluck(_.takeWhile(users, 'active'), 'user');
  5273. * // => []
  5274. */
  5275. function takeWhile(array, predicate, thisArg) {
  5276. return (array && array.length)
  5277. ? baseWhile(array, getCallback(predicate, thisArg, 3))
  5278. : [];
  5279. }
  5280. /**
  5281. * Creates an array of unique values, in order, from all of the provided arrays
  5282. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  5283. * for equality comparisons.
  5284. *
  5285. * @static
  5286. * @memberOf _
  5287. * @category Array
  5288. * @param {...Array} [arrays] The arrays to inspect.
  5289. * @returns {Array} Returns the new array of combined values.
  5290. * @example
  5291. *
  5292. * _.union([1, 2], [4, 2], [2, 1]);
  5293. * // => [1, 2, 4]
  5294. */
  5295. var union = restParam(function(arrays) {
  5296. return baseUniq(baseFlatten(arrays, false, true));
  5297. });
  5298. /**
  5299. * Creates a duplicate-free version of an array, using
  5300. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  5301. * for equality comparisons, in which only the first occurence of each element
  5302. * is kept. Providing `true` for `isSorted` performs a faster search algorithm
  5303. * for sorted arrays. If an iteratee function is provided it's invoked for
  5304. * each element in the array to generate the criterion by which uniqueness
  5305. * is computed. The `iteratee` is bound to `thisArg` and invoked with three
  5306. * arguments: (value, index, array).
  5307. *
  5308. * If a property name is provided for `iteratee` the created `_.property`
  5309. * style callback returns the property value of the given element.
  5310. *
  5311. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5312. * style callback returns `true` for elements that have a matching property
  5313. * value, else `false`.
  5314. *
  5315. * If an object is provided for `iteratee` the created `_.matches` style
  5316. * callback returns `true` for elements that have the properties of the given
  5317. * object, else `false`.
  5318. *
  5319. * @static
  5320. * @memberOf _
  5321. * @alias unique
  5322. * @category Array
  5323. * @param {Array} array The array to inspect.
  5324. * @param {boolean} [isSorted] Specify the array is sorted.
  5325. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  5326. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5327. * @returns {Array} Returns the new duplicate-value-free array.
  5328. * @example
  5329. *
  5330. * _.uniq([2, 1, 2]);
  5331. * // => [2, 1]
  5332. *
  5333. * // using `isSorted`
  5334. * _.uniq([1, 1, 2], true);
  5335. * // => [1, 2]
  5336. *
  5337. * // using an iteratee function
  5338. * _.uniq([1, 2.5, 1.5, 2], function(n) {
  5339. * return this.floor(n);
  5340. * }, Math);
  5341. * // => [1, 2.5]
  5342. *
  5343. * // using the `_.property` callback shorthand
  5344. * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  5345. * // => [{ 'x': 1 }, { 'x': 2 }]
  5346. */
  5347. function uniq(array, isSorted, iteratee, thisArg) {
  5348. var length = array ? array.length : 0;
  5349. if (!length) {
  5350. return [];
  5351. }
  5352. if (isSorted != null && typeof isSorted != 'boolean') {
  5353. thisArg = iteratee;
  5354. iteratee = isIterateeCall(array, isSorted, thisArg) ? undefined : isSorted;
  5355. isSorted = false;
  5356. }
  5357. var callback = getCallback();
  5358. if (!(iteratee == null && callback === baseCallback)) {
  5359. iteratee = callback(iteratee, thisArg, 3);
  5360. }
  5361. return (isSorted && getIndexOf() === baseIndexOf)
  5362. ? sortedUniq(array, iteratee)
  5363. : baseUniq(array, iteratee);
  5364. }
  5365. /**
  5366. * This method is like `_.zip` except that it accepts an array of grouped
  5367. * elements and creates an array regrouping the elements to their pre-zip
  5368. * configuration.
  5369. *
  5370. * @static
  5371. * @memberOf _
  5372. * @category Array
  5373. * @param {Array} array The array of grouped elements to process.
  5374. * @returns {Array} Returns the new array of regrouped elements.
  5375. * @example
  5376. *
  5377. * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
  5378. * // => [['fred', 30, true], ['barney', 40, false]]
  5379. *
  5380. * _.unzip(zipped);
  5381. * // => [['fred', 'barney'], [30, 40], [true, false]]
  5382. */
  5383. function unzip(array) {
  5384. if (!(array && array.length)) {
  5385. return [];
  5386. }
  5387. var index = -1,
  5388. length = 0;
  5389. array = arrayFilter(array, function(group) {
  5390. if (isArrayLike(group)) {
  5391. length = nativeMax(group.length, length);
  5392. return true;
  5393. }
  5394. });
  5395. var result = Array(length);
  5396. while (++index < length) {
  5397. result[index] = arrayMap(array, baseProperty(index));
  5398. }
  5399. return result;
  5400. }
  5401. /**
  5402. * This method is like `_.unzip` except that it accepts an iteratee to specify
  5403. * how regrouped values should be combined. The `iteratee` is bound to `thisArg`
  5404. * and invoked with four arguments: (accumulator, value, index, group).
  5405. *
  5406. * @static
  5407. * @memberOf _
  5408. * @category Array
  5409. * @param {Array} array The array of grouped elements to process.
  5410. * @param {Function} [iteratee] The function to combine regrouped values.
  5411. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5412. * @returns {Array} Returns the new array of regrouped elements.
  5413. * @example
  5414. *
  5415. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  5416. * // => [[1, 10, 100], [2, 20, 200]]
  5417. *
  5418. * _.unzipWith(zipped, _.add);
  5419. * // => [3, 30, 300]
  5420. */
  5421. function unzipWith(array, iteratee, thisArg) {
  5422. var length = array ? array.length : 0;
  5423. if (!length) {
  5424. return [];
  5425. }
  5426. var result = unzip(array);
  5427. if (iteratee == null) {
  5428. return result;
  5429. }
  5430. iteratee = bindCallback(iteratee, thisArg, 4);
  5431. return arrayMap(result, function(group) {
  5432. return arrayReduce(group, iteratee, undefined, true);
  5433. });
  5434. }
  5435. /**
  5436. * Creates an array excluding all provided values using
  5437. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  5438. * for equality comparisons.
  5439. *
  5440. * @static
  5441. * @memberOf _
  5442. * @category Array
  5443. * @param {Array} array The array to filter.
  5444. * @param {...*} [values] The values to exclude.
  5445. * @returns {Array} Returns the new array of filtered values.
  5446. * @example
  5447. *
  5448. * _.without([1, 2, 1, 3], 1, 2);
  5449. * // => [3]
  5450. */
  5451. var without = restParam(function(array, values) {
  5452. return isArrayLike(array)
  5453. ? baseDifference(array, values)
  5454. : [];
  5455. });
  5456. /**
  5457. * Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  5458. * of the provided arrays.
  5459. *
  5460. * @static
  5461. * @memberOf _
  5462. * @category Array
  5463. * @param {...Array} [arrays] The arrays to inspect.
  5464. * @returns {Array} Returns the new array of values.
  5465. * @example
  5466. *
  5467. * _.xor([1, 2], [4, 2]);
  5468. * // => [1, 4]
  5469. */
  5470. function xor() {
  5471. var index = -1,
  5472. length = arguments.length;
  5473. while (++index < length) {
  5474. var array = arguments[index];
  5475. if (isArrayLike(array)) {
  5476. var result = result
  5477. ? arrayPush(baseDifference(result, array), baseDifference(array, result))
  5478. : array;
  5479. }
  5480. }
  5481. return result ? baseUniq(result) : [];
  5482. }
  5483. /**
  5484. * Creates an array of grouped elements, the first of which contains the first
  5485. * elements of the given arrays, the second of which contains the second elements
  5486. * of the given arrays, and so on.
  5487. *
  5488. * @static
  5489. * @memberOf _
  5490. * @category Array
  5491. * @param {...Array} [arrays] The arrays to process.
  5492. * @returns {Array} Returns the new array of grouped elements.
  5493. * @example
  5494. *
  5495. * _.zip(['fred', 'barney'], [30, 40], [true, false]);
  5496. * // => [['fred', 30, true], ['barney', 40, false]]
  5497. */
  5498. var zip = restParam(unzip);
  5499. /**
  5500. * The inverse of `_.pairs`; this method returns an object composed from arrays
  5501. * of property names and values. Provide either a single two dimensional array,
  5502. * e.g. `[[key1, value1], [key2, value2]]` or two arrays, one of property names
  5503. * and one of corresponding values.
  5504. *
  5505. * @static
  5506. * @memberOf _
  5507. * @alias object
  5508. * @category Array
  5509. * @param {Array} props The property names.
  5510. * @param {Array} [values=[]] The property values.
  5511. * @returns {Object} Returns the new object.
  5512. * @example
  5513. *
  5514. * _.zipObject([['fred', 30], ['barney', 40]]);
  5515. * // => { 'fred': 30, 'barney': 40 }
  5516. *
  5517. * _.zipObject(['fred', 'barney'], [30, 40]);
  5518. * // => { 'fred': 30, 'barney': 40 }
  5519. */
  5520. function zipObject(props, values) {
  5521. var index = -1,
  5522. length = props ? props.length : 0,
  5523. result = {};
  5524. if (length && !values && !isArray(props[0])) {
  5525. values = [];
  5526. }
  5527. while (++index < length) {
  5528. var key = props[index];
  5529. if (values) {
  5530. result[key] = values[index];
  5531. } else if (key) {
  5532. result[key[0]] = key[1];
  5533. }
  5534. }
  5535. return result;
  5536. }
  5537. /**
  5538. * This method is like `_.zip` except that it accepts an iteratee to specify
  5539. * how grouped values should be combined. The `iteratee` is bound to `thisArg`
  5540. * and invoked with four arguments: (accumulator, value, index, group).
  5541. *
  5542. * @static
  5543. * @memberOf _
  5544. * @category Array
  5545. * @param {...Array} [arrays] The arrays to process.
  5546. * @param {Function} [iteratee] The function to combine grouped values.
  5547. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5548. * @returns {Array} Returns the new array of grouped elements.
  5549. * @example
  5550. *
  5551. * _.zipWith([1, 2], [10, 20], [100, 200], _.add);
  5552. * // => [111, 222]
  5553. */
  5554. var zipWith = restParam(function(arrays) {
  5555. var length = arrays.length,
  5556. iteratee = length > 2 ? arrays[length - 2] : undefined,
  5557. thisArg = length > 1 ? arrays[length - 1] : undefined;
  5558. if (length > 2 && typeof iteratee == 'function') {
  5559. length -= 2;
  5560. } else {
  5561. iteratee = (length > 1 && typeof thisArg == 'function') ? (--length, thisArg) : undefined;
  5562. thisArg = undefined;
  5563. }
  5564. arrays.length = length;
  5565. return unzipWith(arrays, iteratee, thisArg);
  5566. });
  5567. /*------------------------------------------------------------------------*/
  5568. /**
  5569. * Creates a `lodash` object that wraps `value` with explicit method
  5570. * chaining enabled.
  5571. *
  5572. * @static
  5573. * @memberOf _
  5574. * @category Chain
  5575. * @param {*} value The value to wrap.
  5576. * @returns {Object} Returns the new `lodash` wrapper instance.
  5577. * @example
  5578. *
  5579. * var users = [
  5580. * { 'user': 'barney', 'age': 36 },
  5581. * { 'user': 'fred', 'age': 40 },
  5582. * { 'user': 'pebbles', 'age': 1 }
  5583. * ];
  5584. *
  5585. * var youngest = _.chain(users)
  5586. * .sortBy('age')
  5587. * .map(function(chr) {
  5588. * return chr.user + ' is ' + chr.age;
  5589. * })
  5590. * .first()
  5591. * .value();
  5592. * // => 'pebbles is 1'
  5593. */
  5594. function chain(value) {
  5595. var result = lodash(value);
  5596. result.__chain__ = true;
  5597. return result;
  5598. }
  5599. /**
  5600. * This method invokes `interceptor` and returns `value`. The interceptor is
  5601. * bound to `thisArg` and invoked with one argument; (value). The purpose of
  5602. * this method is to "tap into" a method chain in order to perform operations
  5603. * on intermediate results within the chain.
  5604. *
  5605. * @static
  5606. * @memberOf _
  5607. * @category Chain
  5608. * @param {*} value The value to provide to `interceptor`.
  5609. * @param {Function} interceptor The function to invoke.
  5610. * @param {*} [thisArg] The `this` binding of `interceptor`.
  5611. * @returns {*} Returns `value`.
  5612. * @example
  5613. *
  5614. * _([1, 2, 3])
  5615. * .tap(function(array) {
  5616. * array.pop();
  5617. * })
  5618. * .reverse()
  5619. * .value();
  5620. * // => [2, 1]
  5621. */
  5622. function tap(value, interceptor, thisArg) {
  5623. interceptor.call(thisArg, value);
  5624. return value;
  5625. }
  5626. /**
  5627. * This method is like `_.tap` except that it returns the result of `interceptor`.
  5628. *
  5629. * @static
  5630. * @memberOf _
  5631. * @category Chain
  5632. * @param {*} value The value to provide to `interceptor`.
  5633. * @param {Function} interceptor The function to invoke.
  5634. * @param {*} [thisArg] The `this` binding of `interceptor`.
  5635. * @returns {*} Returns the result of `interceptor`.
  5636. * @example
  5637. *
  5638. * _(' abc ')
  5639. * .chain()
  5640. * .trim()
  5641. * .thru(function(value) {
  5642. * return [value];
  5643. * })
  5644. * .value();
  5645. * // => ['abc']
  5646. */
  5647. function thru(value, interceptor, thisArg) {
  5648. return interceptor.call(thisArg, value);
  5649. }
  5650. /**
  5651. * Enables explicit method chaining on the wrapper object.
  5652. *
  5653. * @name chain
  5654. * @memberOf _
  5655. * @category Chain
  5656. * @returns {Object} Returns the new `lodash` wrapper instance.
  5657. * @example
  5658. *
  5659. * var users = [
  5660. * { 'user': 'barney', 'age': 36 },
  5661. * { 'user': 'fred', 'age': 40 }
  5662. * ];
  5663. *
  5664. * // without explicit chaining
  5665. * _(users).first();
  5666. * // => { 'user': 'barney', 'age': 36 }
  5667. *
  5668. * // with explicit chaining
  5669. * _(users).chain()
  5670. * .first()
  5671. * .pick('user')
  5672. * .value();
  5673. * // => { 'user': 'barney' }
  5674. */
  5675. function wrapperChain() {
  5676. return chain(this);
  5677. }
  5678. /**
  5679. * Executes the chained sequence and returns the wrapped result.
  5680. *
  5681. * @name commit
  5682. * @memberOf _
  5683. * @category Chain
  5684. * @returns {Object} Returns the new `lodash` wrapper instance.
  5685. * @example
  5686. *
  5687. * var array = [1, 2];
  5688. * var wrapped = _(array).push(3);
  5689. *
  5690. * console.log(array);
  5691. * // => [1, 2]
  5692. *
  5693. * wrapped = wrapped.commit();
  5694. * console.log(array);
  5695. * // => [1, 2, 3]
  5696. *
  5697. * wrapped.last();
  5698. * // => 3
  5699. *
  5700. * console.log(array);
  5701. * // => [1, 2, 3]
  5702. */
  5703. function wrapperCommit() {
  5704. return new LodashWrapper(this.value(), this.__chain__);
  5705. }
  5706. /**
  5707. * Creates a new array joining a wrapped array with any additional arrays
  5708. * and/or values.
  5709. *
  5710. * @name concat
  5711. * @memberOf _
  5712. * @category Chain
  5713. * @param {...*} [values] The values to concatenate.
  5714. * @returns {Array} Returns the new concatenated array.
  5715. * @example
  5716. *
  5717. * var array = [1];
  5718. * var wrapped = _(array).concat(2, [3], [[4]]);
  5719. *
  5720. * console.log(wrapped.value());
  5721. * // => [1, 2, 3, [4]]
  5722. *
  5723. * console.log(array);
  5724. * // => [1]
  5725. */
  5726. var wrapperConcat = restParam(function(values) {
  5727. values = baseFlatten(values);
  5728. return this.thru(function(array) {
  5729. return arrayConcat(isArray(array) ? array : [toObject(array)], values);
  5730. });
  5731. });
  5732. /**
  5733. * Creates a clone of the chained sequence planting `value` as the wrapped value.
  5734. *
  5735. * @name plant
  5736. * @memberOf _
  5737. * @category Chain
  5738. * @returns {Object} Returns the new `lodash` wrapper instance.
  5739. * @example
  5740. *
  5741. * var array = [1, 2];
  5742. * var wrapped = _(array).map(function(value) {
  5743. * return Math.pow(value, 2);
  5744. * });
  5745. *
  5746. * var other = [3, 4];
  5747. * var otherWrapped = wrapped.plant(other);
  5748. *
  5749. * otherWrapped.value();
  5750. * // => [9, 16]
  5751. *
  5752. * wrapped.value();
  5753. * // => [1, 4]
  5754. */
  5755. function wrapperPlant(value) {
  5756. var result,
  5757. parent = this;
  5758. while (parent instanceof baseLodash) {
  5759. var clone = wrapperClone(parent);
  5760. if (result) {
  5761. previous.__wrapped__ = clone;
  5762. } else {
  5763. result = clone;
  5764. }
  5765. var previous = clone;
  5766. parent = parent.__wrapped__;
  5767. }
  5768. previous.__wrapped__ = value;
  5769. return result;
  5770. }
  5771. /**
  5772. * Reverses the wrapped array so the first element becomes the last, the
  5773. * second element becomes the second to last, and so on.
  5774. *
  5775. * **Note:** This method mutates the wrapped array.
  5776. *
  5777. * @name reverse
  5778. * @memberOf _
  5779. * @category Chain
  5780. * @returns {Object} Returns the new reversed `lodash` wrapper instance.
  5781. * @example
  5782. *
  5783. * var array = [1, 2, 3];
  5784. *
  5785. * _(array).reverse().value()
  5786. * // => [3, 2, 1]
  5787. *
  5788. * console.log(array);
  5789. * // => [3, 2, 1]
  5790. */
  5791. function wrapperReverse() {
  5792. var value = this.__wrapped__;
  5793. var interceptor = function(value) {
  5794. return value.reverse();
  5795. };
  5796. if (value instanceof LazyWrapper) {
  5797. var wrapped = value;
  5798. if (this.__actions__.length) {
  5799. wrapped = new LazyWrapper(this);
  5800. }
  5801. wrapped = wrapped.reverse();
  5802. wrapped.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  5803. return new LodashWrapper(wrapped, this.__chain__);
  5804. }
  5805. return this.thru(interceptor);
  5806. }
  5807. /**
  5808. * Produces the result of coercing the unwrapped value to a string.
  5809. *
  5810. * @name toString
  5811. * @memberOf _
  5812. * @category Chain
  5813. * @returns {string} Returns the coerced string value.
  5814. * @example
  5815. *
  5816. * _([1, 2, 3]).toString();
  5817. * // => '1,2,3'
  5818. */
  5819. function wrapperToString() {
  5820. return (this.value() + '');
  5821. }
  5822. /**
  5823. * Executes the chained sequence to extract the unwrapped value.
  5824. *
  5825. * @name value
  5826. * @memberOf _
  5827. * @alias run, toJSON, valueOf
  5828. * @category Chain
  5829. * @returns {*} Returns the resolved unwrapped value.
  5830. * @example
  5831. *
  5832. * _([1, 2, 3]).value();
  5833. * // => [1, 2, 3]
  5834. */
  5835. function wrapperValue() {
  5836. return baseWrapperValue(this.__wrapped__, this.__actions__);
  5837. }
  5838. /*------------------------------------------------------------------------*/
  5839. /**
  5840. * Creates an array of elements corresponding to the given keys, or indexes,
  5841. * of `collection`. Keys may be specified as individual arguments or as arrays
  5842. * of keys.
  5843. *
  5844. * @static
  5845. * @memberOf _
  5846. * @category Collection
  5847. * @param {Array|Object|string} collection The collection to iterate over.
  5848. * @param {...(number|number[]|string|string[])} [props] The property names
  5849. * or indexes of elements to pick, specified individually or in arrays.
  5850. * @returns {Array} Returns the new array of picked elements.
  5851. * @example
  5852. *
  5853. * _.at(['a', 'b', 'c'], [0, 2]);
  5854. * // => ['a', 'c']
  5855. *
  5856. * _.at(['barney', 'fred', 'pebbles'], 0, 2);
  5857. * // => ['barney', 'pebbles']
  5858. */
  5859. var at = restParam(function(collection, props) {
  5860. if (isArrayLike(collection)) {
  5861. collection = toIterable(collection);
  5862. }
  5863. return baseAt(collection, baseFlatten(props));
  5864. });
  5865. /**
  5866. * Creates an object composed of keys generated from the results of running
  5867. * each element of `collection` through `iteratee`. The corresponding value
  5868. * of each key is the number of times the key was returned by `iteratee`.
  5869. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  5870. * (value, index|key, collection).
  5871. *
  5872. * If a property name is provided for `iteratee` the created `_.property`
  5873. * style callback returns the property value of the given element.
  5874. *
  5875. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5876. * style callback returns `true` for elements that have a matching property
  5877. * value, else `false`.
  5878. *
  5879. * If an object is provided for `iteratee` the created `_.matches` style
  5880. * callback returns `true` for elements that have the properties of the given
  5881. * object, else `false`.
  5882. *
  5883. * @static
  5884. * @memberOf _
  5885. * @category Collection
  5886. * @param {Array|Object|string} collection The collection to iterate over.
  5887. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  5888. * per iteration.
  5889. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5890. * @returns {Object} Returns the composed aggregate object.
  5891. * @example
  5892. *
  5893. * _.countBy([4.3, 6.1, 6.4], function(n) {
  5894. * return Math.floor(n);
  5895. * });
  5896. * // => { '4': 1, '6': 2 }
  5897. *
  5898. * _.countBy([4.3, 6.1, 6.4], function(n) {
  5899. * return this.floor(n);
  5900. * }, Math);
  5901. * // => { '4': 1, '6': 2 }
  5902. *
  5903. * _.countBy(['one', 'two', 'three'], 'length');
  5904. * // => { '3': 2, '5': 1 }
  5905. */
  5906. var countBy = createAggregator(function(result, value, key) {
  5907. hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
  5908. });
  5909. /**
  5910. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  5911. * The predicate is bound to `thisArg` and invoked with three arguments:
  5912. * (value, index|key, collection).
  5913. *
  5914. * If a property name is provided for `predicate` the created `_.property`
  5915. * style callback returns the property value of the given element.
  5916. *
  5917. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5918. * style callback returns `true` for elements that have a matching property
  5919. * value, else `false`.
  5920. *
  5921. * If an object is provided for `predicate` the created `_.matches` style
  5922. * callback returns `true` for elements that have the properties of the given
  5923. * object, else `false`.
  5924. *
  5925. * @static
  5926. * @memberOf _
  5927. * @alias all
  5928. * @category Collection
  5929. * @param {Array|Object|string} collection The collection to iterate over.
  5930. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  5931. * per iteration.
  5932. * @param {*} [thisArg] The `this` binding of `predicate`.
  5933. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  5934. * else `false`.
  5935. * @example
  5936. *
  5937. * _.every([true, 1, null, 'yes'], Boolean);
  5938. * // => false
  5939. *
  5940. * var users = [
  5941. * { 'user': 'barney', 'active': false },
  5942. * { 'user': 'fred', 'active': false }
  5943. * ];
  5944. *
  5945. * // using the `_.matches` callback shorthand
  5946. * _.every(users, { 'user': 'barney', 'active': false });
  5947. * // => false
  5948. *
  5949. * // using the `_.matchesProperty` callback shorthand
  5950. * _.every(users, 'active', false);
  5951. * // => true
  5952. *
  5953. * // using the `_.property` callback shorthand
  5954. * _.every(users, 'active');
  5955. * // => false
  5956. */
  5957. function every(collection, predicate, thisArg) {
  5958. var func = isArray(collection) ? arrayEvery : baseEvery;
  5959. if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
  5960. predicate = undefined;
  5961. }
  5962. if (typeof predicate != 'function' || thisArg !== undefined) {
  5963. predicate = getCallback(predicate, thisArg, 3);
  5964. }
  5965. return func(collection, predicate);
  5966. }
  5967. /**
  5968. * Iterates over elements of `collection`, returning an array of all elements
  5969. * `predicate` returns truthy for. The predicate is bound to `thisArg` and
  5970. * invoked with three arguments: (value, index|key, collection).
  5971. *
  5972. * If a property name is provided for `predicate` the created `_.property`
  5973. * style callback returns the property value of the given element.
  5974. *
  5975. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5976. * style callback returns `true` for elements that have a matching property
  5977. * value, else `false`.
  5978. *
  5979. * If an object is provided for `predicate` the created `_.matches` style
  5980. * callback returns `true` for elements that have the properties of the given
  5981. * object, else `false`.
  5982. *
  5983. * @static
  5984. * @memberOf _
  5985. * @alias select
  5986. * @category Collection
  5987. * @param {Array|Object|string} collection The collection to iterate over.
  5988. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  5989. * per iteration.
  5990. * @param {*} [thisArg] The `this` binding of `predicate`.
  5991. * @returns {Array} Returns the new filtered array.
  5992. * @example
  5993. *
  5994. * _.filter([4, 5, 6], function(n) {
  5995. * return n % 2 == 0;
  5996. * });
  5997. * // => [4, 6]
  5998. *
  5999. * var users = [
  6000. * { 'user': 'barney', 'age': 36, 'active': true },
  6001. * { 'user': 'fred', 'age': 40, 'active': false }
  6002. * ];
  6003. *
  6004. * // using the `_.matches` callback shorthand
  6005. * _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
  6006. * // => ['barney']
  6007. *
  6008. * // using the `_.matchesProperty` callback shorthand
  6009. * _.pluck(_.filter(users, 'active', false), 'user');
  6010. * // => ['fred']
  6011. *
  6012. * // using the `_.property` callback shorthand
  6013. * _.pluck(_.filter(users, 'active'), 'user');
  6014. * // => ['barney']
  6015. */
  6016. function filter(collection, predicate, thisArg) {
  6017. var func = isArray(collection) ? arrayFilter : baseFilter;
  6018. predicate = getCallback(predicate, thisArg, 3);
  6019. return func(collection, predicate);
  6020. }
  6021. /**
  6022. * Iterates over elements of `collection`, returning the first element
  6023. * `predicate` returns truthy for. The predicate is bound to `thisArg` and
  6024. * invoked with three arguments: (value, index|key, collection).
  6025. *
  6026. * If a property name is provided for `predicate` the created `_.property`
  6027. * style callback returns the property value of the given element.
  6028. *
  6029. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6030. * style callback returns `true` for elements that have a matching property
  6031. * value, else `false`.
  6032. *
  6033. * If an object is provided for `predicate` the created `_.matches` style
  6034. * callback returns `true` for elements that have the properties of the given
  6035. * object, else `false`.
  6036. *
  6037. * @static
  6038. * @memberOf _
  6039. * @alias detect
  6040. * @category Collection
  6041. * @param {Array|Object|string} collection The collection to search.
  6042. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6043. * per iteration.
  6044. * @param {*} [thisArg] The `this` binding of `predicate`.
  6045. * @returns {*} Returns the matched element, else `undefined`.
  6046. * @example
  6047. *
  6048. * var users = [
  6049. * { 'user': 'barney', 'age': 36, 'active': true },
  6050. * { 'user': 'fred', 'age': 40, 'active': false },
  6051. * { 'user': 'pebbles', 'age': 1, 'active': true }
  6052. * ];
  6053. *
  6054. * _.result(_.find(users, function(chr) {
  6055. * return chr.age < 40;
  6056. * }), 'user');
  6057. * // => 'barney'
  6058. *
  6059. * // using the `_.matches` callback shorthand
  6060. * _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
  6061. * // => 'pebbles'
  6062. *
  6063. * // using the `_.matchesProperty` callback shorthand
  6064. * _.result(_.find(users, 'active', false), 'user');
  6065. * // => 'fred'
  6066. *
  6067. * // using the `_.property` callback shorthand
  6068. * _.result(_.find(users, 'active'), 'user');
  6069. * // => 'barney'
  6070. */
  6071. var find = createFind(baseEach);
  6072. /**
  6073. * This method is like `_.find` except that it iterates over elements of
  6074. * `collection` from right to left.
  6075. *
  6076. * @static
  6077. * @memberOf _
  6078. * @category Collection
  6079. * @param {Array|Object|string} collection The collection to search.
  6080. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6081. * per iteration.
  6082. * @param {*} [thisArg] The `this` binding of `predicate`.
  6083. * @returns {*} Returns the matched element, else `undefined`.
  6084. * @example
  6085. *
  6086. * _.findLast([1, 2, 3, 4], function(n) {
  6087. * return n % 2 == 1;
  6088. * });
  6089. * // => 3
  6090. */
  6091. var findLast = createFind(baseEachRight, true);
  6092. /**
  6093. * Performs a deep comparison between each element in `collection` and the
  6094. * source object, returning the first element that has equivalent property
  6095. * values.
  6096. *
  6097. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  6098. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  6099. * their own, not inherited, enumerable properties. For comparing a single
  6100. * own or inherited property value see `_.matchesProperty`.
  6101. *
  6102. * @static
  6103. * @memberOf _
  6104. * @category Collection
  6105. * @param {Array|Object|string} collection The collection to search.
  6106. * @param {Object} source The object of property values to match.
  6107. * @returns {*} Returns the matched element, else `undefined`.
  6108. * @example
  6109. *
  6110. * var users = [
  6111. * { 'user': 'barney', 'age': 36, 'active': true },
  6112. * { 'user': 'fred', 'age': 40, 'active': false }
  6113. * ];
  6114. *
  6115. * _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user');
  6116. * // => 'barney'
  6117. *
  6118. * _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user');
  6119. * // => 'fred'
  6120. */
  6121. function findWhere(collection, source) {
  6122. return find(collection, baseMatches(source));
  6123. }
  6124. /**
  6125. * Iterates over elements of `collection` invoking `iteratee` for each element.
  6126. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  6127. * (value, index|key, collection). Iteratee functions may exit iteration early
  6128. * by explicitly returning `false`.
  6129. *
  6130. * **Note:** As with other "Collections" methods, objects with a "length" property
  6131. * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
  6132. * may be used for object iteration.
  6133. *
  6134. * @static
  6135. * @memberOf _
  6136. * @alias each
  6137. * @category Collection
  6138. * @param {Array|Object|string} collection The collection to iterate over.
  6139. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  6140. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6141. * @returns {Array|Object|string} Returns `collection`.
  6142. * @example
  6143. *
  6144. * _([1, 2]).forEach(function(n) {
  6145. * console.log(n);
  6146. * }).value();
  6147. * // => logs each value from left to right and returns the array
  6148. *
  6149. * _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
  6150. * console.log(n, key);
  6151. * });
  6152. * // => logs each value-key pair and returns the object (iteration order is not guaranteed)
  6153. */
  6154. var forEach = createForEach(arrayEach, baseEach);
  6155. /**
  6156. * This method is like `_.forEach` except that it iterates over elements of
  6157. * `collection` from right to left.
  6158. *
  6159. * @static
  6160. * @memberOf _
  6161. * @alias eachRight
  6162. * @category Collection
  6163. * @param {Array|Object|string} collection The collection to iterate over.
  6164. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  6165. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6166. * @returns {Array|Object|string} Returns `collection`.
  6167. * @example
  6168. *
  6169. * _([1, 2]).forEachRight(function(n) {
  6170. * console.log(n);
  6171. * }).value();
  6172. * // => logs each value from right to left and returns the array
  6173. */
  6174. var forEachRight = createForEach(arrayEachRight, baseEachRight);
  6175. /**
  6176. * Creates an object composed of keys generated from the results of running
  6177. * each element of `collection` through `iteratee`. The corresponding value
  6178. * of each key is an array of the elements responsible for generating the key.
  6179. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  6180. * (value, index|key, collection).
  6181. *
  6182. * If a property name is provided for `iteratee` the created `_.property`
  6183. * style callback returns the property value of the given element.
  6184. *
  6185. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6186. * style callback returns `true` for elements that have a matching property
  6187. * value, else `false`.
  6188. *
  6189. * If an object is provided for `iteratee` the created `_.matches` style
  6190. * callback returns `true` for elements that have the properties of the given
  6191. * object, else `false`.
  6192. *
  6193. * @static
  6194. * @memberOf _
  6195. * @category Collection
  6196. * @param {Array|Object|string} collection The collection to iterate over.
  6197. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  6198. * per iteration.
  6199. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6200. * @returns {Object} Returns the composed aggregate object.
  6201. * @example
  6202. *
  6203. * _.groupBy([4.2, 6.1, 6.4], function(n) {
  6204. * return Math.floor(n);
  6205. * });
  6206. * // => { '4': [4.2], '6': [6.1, 6.4] }
  6207. *
  6208. * _.groupBy([4.2, 6.1, 6.4], function(n) {
  6209. * return this.floor(n);
  6210. * }, Math);
  6211. * // => { '4': [4.2], '6': [6.1, 6.4] }
  6212. *
  6213. * // using the `_.property` callback shorthand
  6214. * _.groupBy(['one', 'two', 'three'], 'length');
  6215. * // => { '3': ['one', 'two'], '5': ['three'] }
  6216. */
  6217. var groupBy = createAggregator(function(result, value, key) {
  6218. if (hasOwnProperty.call(result, key)) {
  6219. result[key].push(value);
  6220. } else {
  6221. result[key] = [value];
  6222. }
  6223. });
  6224. /**
  6225. * Checks if `target` is in `collection` using
  6226. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  6227. * for equality comparisons. If `fromIndex` is negative, it's used as the offset
  6228. * from the end of `collection`.
  6229. *
  6230. * @static
  6231. * @memberOf _
  6232. * @alias contains, include
  6233. * @category Collection
  6234. * @param {Array|Object|string} collection The collection to search.
  6235. * @param {*} target The value to search for.
  6236. * @param {number} [fromIndex=0] The index to search from.
  6237. * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
  6238. * @returns {boolean} Returns `true` if a matching element is found, else `false`.
  6239. * @example
  6240. *
  6241. * _.includes([1, 2, 3], 1);
  6242. * // => true
  6243. *
  6244. * _.includes([1, 2, 3], 1, 2);
  6245. * // => false
  6246. *
  6247. * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
  6248. * // => true
  6249. *
  6250. * _.includes('pebbles', 'eb');
  6251. * // => true
  6252. */
  6253. function includes(collection, target, fromIndex, guard) {
  6254. var length = collection ? getLength(collection) : 0;
  6255. if (!isLength(length)) {
  6256. collection = values(collection);
  6257. length = collection.length;
  6258. }
  6259. if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
  6260. fromIndex = 0;
  6261. } else {
  6262. fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
  6263. }
  6264. return (typeof collection == 'string' || !isArray(collection) && isString(collection))
  6265. ? (fromIndex <= length && collection.indexOf(target, fromIndex) > -1)
  6266. : (!!length && getIndexOf(collection, target, fromIndex) > -1);
  6267. }
  6268. /**
  6269. * Creates an object composed of keys generated from the results of running
  6270. * each element of `collection` through `iteratee`. The corresponding value
  6271. * of each key is the last element responsible for generating the key. The
  6272. * iteratee function is bound to `thisArg` and invoked with three arguments:
  6273. * (value, index|key, collection).
  6274. *
  6275. * If a property name is provided for `iteratee` the created `_.property`
  6276. * style callback returns the property value of the given element.
  6277. *
  6278. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6279. * style callback returns `true` for elements that have a matching property
  6280. * value, else `false`.
  6281. *
  6282. * If an object is provided for `iteratee` the created `_.matches` style
  6283. * callback returns `true` for elements that have the properties of the given
  6284. * object, else `false`.
  6285. *
  6286. * @static
  6287. * @memberOf _
  6288. * @category Collection
  6289. * @param {Array|Object|string} collection The collection to iterate over.
  6290. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  6291. * per iteration.
  6292. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6293. * @returns {Object} Returns the composed aggregate object.
  6294. * @example
  6295. *
  6296. * var keyData = [
  6297. * { 'dir': 'left', 'code': 97 },
  6298. * { 'dir': 'right', 'code': 100 }
  6299. * ];
  6300. *
  6301. * _.indexBy(keyData, 'dir');
  6302. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  6303. *
  6304. * _.indexBy(keyData, function(object) {
  6305. * return String.fromCharCode(object.code);
  6306. * });
  6307. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  6308. *
  6309. * _.indexBy(keyData, function(object) {
  6310. * return this.fromCharCode(object.code);
  6311. * }, String);
  6312. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  6313. */
  6314. var indexBy = createAggregator(function(result, value, key) {
  6315. result[key] = value;
  6316. });
  6317. /**
  6318. * Invokes the method at `path` of each element in `collection`, returning
  6319. * an array of the results of each invoked method. Any additional arguments
  6320. * are provided to each invoked method. If `methodName` is a function it's
  6321. * invoked for, and `this` bound to, each element in `collection`.
  6322. *
  6323. * @static
  6324. * @memberOf _
  6325. * @category Collection
  6326. * @param {Array|Object|string} collection The collection to iterate over.
  6327. * @param {Array|Function|string} path The path of the method to invoke or
  6328. * the function invoked per iteration.
  6329. * @param {...*} [args] The arguments to invoke the method with.
  6330. * @returns {Array} Returns the array of results.
  6331. * @example
  6332. *
  6333. * _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
  6334. * // => [[1, 5, 7], [1, 2, 3]]
  6335. *
  6336. * _.invoke([123, 456], String.prototype.split, '');
  6337. * // => [['1', '2', '3'], ['4', '5', '6']]
  6338. */
  6339. var invoke = restParam(function(collection, path, args) {
  6340. var index = -1,
  6341. isFunc = typeof path == 'function',
  6342. isProp = isKey(path),
  6343. result = isArrayLike(collection) ? Array(collection.length) : [];
  6344. baseEach(collection, function(value) {
  6345. var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
  6346. result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
  6347. });
  6348. return result;
  6349. });
  6350. /**
  6351. * Creates an array of values by running each element in `collection` through
  6352. * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
  6353. * arguments: (value, index|key, collection).
  6354. *
  6355. * If a property name is provided for `iteratee` the created `_.property`
  6356. * style callback returns the property value of the given element.
  6357. *
  6358. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6359. * style callback returns `true` for elements that have a matching property
  6360. * value, else `false`.
  6361. *
  6362. * If an object is provided for `iteratee` the created `_.matches` style
  6363. * callback returns `true` for elements that have the properties of the given
  6364. * object, else `false`.
  6365. *
  6366. * Many lodash methods are guarded to work as iteratees for methods like
  6367. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  6368. *
  6369. * The guarded methods are:
  6370. * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
  6371. * `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
  6372. * `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
  6373. * `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
  6374. * `sum`, `uniq`, and `words`
  6375. *
  6376. * @static
  6377. * @memberOf _
  6378. * @alias collect
  6379. * @category Collection
  6380. * @param {Array|Object|string} collection The collection to iterate over.
  6381. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  6382. * per iteration.
  6383. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6384. * @returns {Array} Returns the new mapped array.
  6385. * @example
  6386. *
  6387. * function timesThree(n) {
  6388. * return n * 3;
  6389. * }
  6390. *
  6391. * _.map([1, 2], timesThree);
  6392. * // => [3, 6]
  6393. *
  6394. * _.map({ 'a': 1, 'b': 2 }, timesThree);
  6395. * // => [3, 6] (iteration order is not guaranteed)
  6396. *
  6397. * var users = [
  6398. * { 'user': 'barney' },
  6399. * { 'user': 'fred' }
  6400. * ];
  6401. *
  6402. * // using the `_.property` callback shorthand
  6403. * _.map(users, 'user');
  6404. * // => ['barney', 'fred']
  6405. */
  6406. function map(collection, iteratee, thisArg) {
  6407. var func = isArray(collection) ? arrayMap : baseMap;
  6408. iteratee = getCallback(iteratee, thisArg, 3);
  6409. return func(collection, iteratee);
  6410. }
  6411. /**
  6412. * Creates an array of elements split into two groups, the first of which
  6413. * contains elements `predicate` returns truthy for, while the second of which
  6414. * contains elements `predicate` returns falsey for. The predicate is bound
  6415. * to `thisArg` and invoked with three arguments: (value, index|key, collection).
  6416. *
  6417. * If a property name is provided for `predicate` the created `_.property`
  6418. * style callback returns the property value of the given element.
  6419. *
  6420. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6421. * style callback returns `true` for elements that have a matching property
  6422. * value, else `false`.
  6423. *
  6424. * If an object is provided for `predicate` the created `_.matches` style
  6425. * callback returns `true` for elements that have the properties of the given
  6426. * object, else `false`.
  6427. *
  6428. * @static
  6429. * @memberOf _
  6430. * @category Collection
  6431. * @param {Array|Object|string} collection The collection to iterate over.
  6432. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6433. * per iteration.
  6434. * @param {*} [thisArg] The `this` binding of `predicate`.
  6435. * @returns {Array} Returns the array of grouped elements.
  6436. * @example
  6437. *
  6438. * _.partition([1, 2, 3], function(n) {
  6439. * return n % 2;
  6440. * });
  6441. * // => [[1, 3], [2]]
  6442. *
  6443. * _.partition([1.2, 2.3, 3.4], function(n) {
  6444. * return this.floor(n) % 2;
  6445. * }, Math);
  6446. * // => [[1.2, 3.4], [2.3]]
  6447. *
  6448. * var users = [
  6449. * { 'user': 'barney', 'age': 36, 'active': false },
  6450. * { 'user': 'fred', 'age': 40, 'active': true },
  6451. * { 'user': 'pebbles', 'age': 1, 'active': false }
  6452. * ];
  6453. *
  6454. * var mapper = function(array) {
  6455. * return _.pluck(array, 'user');
  6456. * };
  6457. *
  6458. * // using the `_.matches` callback shorthand
  6459. * _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
  6460. * // => [['pebbles'], ['barney', 'fred']]
  6461. *
  6462. * // using the `_.matchesProperty` callback shorthand
  6463. * _.map(_.partition(users, 'active', false), mapper);
  6464. * // => [['barney', 'pebbles'], ['fred']]
  6465. *
  6466. * // using the `_.property` callback shorthand
  6467. * _.map(_.partition(users, 'active'), mapper);
  6468. * // => [['fred'], ['barney', 'pebbles']]
  6469. */
  6470. var partition = createAggregator(function(result, value, key) {
  6471. result[key ? 0 : 1].push(value);
  6472. }, function() { return [[], []]; });
  6473. /**
  6474. * Gets the property value of `path` from all elements in `collection`.
  6475. *
  6476. * @static
  6477. * @memberOf _
  6478. * @category Collection
  6479. * @param {Array|Object|string} collection The collection to iterate over.
  6480. * @param {Array|string} path The path of the property to pluck.
  6481. * @returns {Array} Returns the property values.
  6482. * @example
  6483. *
  6484. * var users = [
  6485. * { 'user': 'barney', 'age': 36 },
  6486. * { 'user': 'fred', 'age': 40 }
  6487. * ];
  6488. *
  6489. * _.pluck(users, 'user');
  6490. * // => ['barney', 'fred']
  6491. *
  6492. * var userIndex = _.indexBy(users, 'user');
  6493. * _.pluck(userIndex, 'age');
  6494. * // => [36, 40] (iteration order is not guaranteed)
  6495. */
  6496. function pluck(collection, path) {
  6497. return map(collection, property(path));
  6498. }
  6499. /**
  6500. * Reduces `collection` to a value which is the accumulated result of running
  6501. * each element in `collection` through `iteratee`, where each successive
  6502. * invocation is supplied the return value of the previous. If `accumulator`
  6503. * is not provided the first element of `collection` is used as the initial
  6504. * value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
  6505. * (accumulator, value, index|key, collection).
  6506. *
  6507. * Many lodash methods are guarded to work as iteratees for methods like
  6508. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  6509. *
  6510. * The guarded methods are:
  6511. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `sortByAll`,
  6512. * and `sortByOrder`
  6513. *
  6514. * @static
  6515. * @memberOf _
  6516. * @alias foldl, inject
  6517. * @category Collection
  6518. * @param {Array|Object|string} collection The collection to iterate over.
  6519. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  6520. * @param {*} [accumulator] The initial value.
  6521. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6522. * @returns {*} Returns the accumulated value.
  6523. * @example
  6524. *
  6525. * _.reduce([1, 2], function(total, n) {
  6526. * return total + n;
  6527. * });
  6528. * // => 3
  6529. *
  6530. * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
  6531. * result[key] = n * 3;
  6532. * return result;
  6533. * }, {});
  6534. * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
  6535. */
  6536. var reduce = createReduce(arrayReduce, baseEach);
  6537. /**
  6538. * This method is like `_.reduce` except that it iterates over elements of
  6539. * `collection` from right to left.
  6540. *
  6541. * @static
  6542. * @memberOf _
  6543. * @alias foldr
  6544. * @category Collection
  6545. * @param {Array|Object|string} collection The collection to iterate over.
  6546. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  6547. * @param {*} [accumulator] The initial value.
  6548. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6549. * @returns {*} Returns the accumulated value.
  6550. * @example
  6551. *
  6552. * var array = [[0, 1], [2, 3], [4, 5]];
  6553. *
  6554. * _.reduceRight(array, function(flattened, other) {
  6555. * return flattened.concat(other);
  6556. * }, []);
  6557. * // => [4, 5, 2, 3, 0, 1]
  6558. */
  6559. var reduceRight = createReduce(arrayReduceRight, baseEachRight);
  6560. /**
  6561. * The opposite of `_.filter`; this method returns the elements of `collection`
  6562. * that `predicate` does **not** return truthy for.
  6563. *
  6564. * @static
  6565. * @memberOf _
  6566. * @category Collection
  6567. * @param {Array|Object|string} collection The collection to iterate over.
  6568. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6569. * per iteration.
  6570. * @param {*} [thisArg] The `this` binding of `predicate`.
  6571. * @returns {Array} Returns the new filtered array.
  6572. * @example
  6573. *
  6574. * _.reject([1, 2, 3, 4], function(n) {
  6575. * return n % 2 == 0;
  6576. * });
  6577. * // => [1, 3]
  6578. *
  6579. * var users = [
  6580. * { 'user': 'barney', 'age': 36, 'active': false },
  6581. * { 'user': 'fred', 'age': 40, 'active': true }
  6582. * ];
  6583. *
  6584. * // using the `_.matches` callback shorthand
  6585. * _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
  6586. * // => ['barney']
  6587. *
  6588. * // using the `_.matchesProperty` callback shorthand
  6589. * _.pluck(_.reject(users, 'active', false), 'user');
  6590. * // => ['fred']
  6591. *
  6592. * // using the `_.property` callback shorthand
  6593. * _.pluck(_.reject(users, 'active'), 'user');
  6594. * // => ['barney']
  6595. */
  6596. function reject(collection, predicate, thisArg) {
  6597. var func = isArray(collection) ? arrayFilter : baseFilter;
  6598. predicate = getCallback(predicate, thisArg, 3);
  6599. return func(collection, function(value, index, collection) {
  6600. return !predicate(value, index, collection);
  6601. });
  6602. }
  6603. /**
  6604. * Gets a random element or `n` random elements from a collection.
  6605. *
  6606. * @static
  6607. * @memberOf _
  6608. * @category Collection
  6609. * @param {Array|Object|string} collection The collection to sample.
  6610. * @param {number} [n] The number of elements to sample.
  6611. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  6612. * @returns {*} Returns the random sample(s).
  6613. * @example
  6614. *
  6615. * _.sample([1, 2, 3, 4]);
  6616. * // => 2
  6617. *
  6618. * _.sample([1, 2, 3, 4], 2);
  6619. * // => [3, 1]
  6620. */
  6621. function sample(collection, n, guard) {
  6622. if (guard ? isIterateeCall(collection, n, guard) : n == null) {
  6623. collection = toIterable(collection);
  6624. var length = collection.length;
  6625. return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
  6626. }
  6627. var index = -1,
  6628. result = toArray(collection),
  6629. length = result.length,
  6630. lastIndex = length - 1;
  6631. n = nativeMin(n < 0 ? 0 : (+n || 0), length);
  6632. while (++index < n) {
  6633. var rand = baseRandom(index, lastIndex),
  6634. value = result[rand];
  6635. result[rand] = result[index];
  6636. result[index] = value;
  6637. }
  6638. result.length = n;
  6639. return result;
  6640. }
  6641. /**
  6642. * Creates an array of shuffled values, using a version of the
  6643. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  6644. *
  6645. * @static
  6646. * @memberOf _
  6647. * @category Collection
  6648. * @param {Array|Object|string} collection The collection to shuffle.
  6649. * @returns {Array} Returns the new shuffled array.
  6650. * @example
  6651. *
  6652. * _.shuffle([1, 2, 3, 4]);
  6653. * // => [4, 1, 3, 2]
  6654. */
  6655. function shuffle(collection) {
  6656. return sample(collection, POSITIVE_INFINITY);
  6657. }
  6658. /**
  6659. * Gets the size of `collection` by returning its length for array-like
  6660. * values or the number of own enumerable properties for objects.
  6661. *
  6662. * @static
  6663. * @memberOf _
  6664. * @category Collection
  6665. * @param {Array|Object|string} collection The collection to inspect.
  6666. * @returns {number} Returns the size of `collection`.
  6667. * @example
  6668. *
  6669. * _.size([1, 2, 3]);
  6670. * // => 3
  6671. *
  6672. * _.size({ 'a': 1, 'b': 2 });
  6673. * // => 2
  6674. *
  6675. * _.size('pebbles');
  6676. * // => 7
  6677. */
  6678. function size(collection) {
  6679. var length = collection ? getLength(collection) : 0;
  6680. return isLength(length) ? length : keys(collection).length;
  6681. }
  6682. /**
  6683. * Checks if `predicate` returns truthy for **any** element of `collection`.
  6684. * The function returns as soon as it finds a passing value and does not iterate
  6685. * over the entire collection. The predicate is bound to `thisArg` and invoked
  6686. * with three arguments: (value, index|key, collection).
  6687. *
  6688. * If a property name is provided for `predicate` the created `_.property`
  6689. * style callback returns the property value of the given element.
  6690. *
  6691. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6692. * style callback returns `true` for elements that have a matching property
  6693. * value, else `false`.
  6694. *
  6695. * If an object is provided for `predicate` the created `_.matches` style
  6696. * callback returns `true` for elements that have the properties of the given
  6697. * object, else `false`.
  6698. *
  6699. * @static
  6700. * @memberOf _
  6701. * @alias any
  6702. * @category Collection
  6703. * @param {Array|Object|string} collection The collection to iterate over.
  6704. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6705. * per iteration.
  6706. * @param {*} [thisArg] The `this` binding of `predicate`.
  6707. * @returns {boolean} Returns `true` if any element passes the predicate check,
  6708. * else `false`.
  6709. * @example
  6710. *
  6711. * _.some([null, 0, 'yes', false], Boolean);
  6712. * // => true
  6713. *
  6714. * var users = [
  6715. * { 'user': 'barney', 'active': true },
  6716. * { 'user': 'fred', 'active': false }
  6717. * ];
  6718. *
  6719. * // using the `_.matches` callback shorthand
  6720. * _.some(users, { 'user': 'barney', 'active': false });
  6721. * // => false
  6722. *
  6723. * // using the `_.matchesProperty` callback shorthand
  6724. * _.some(users, 'active', false);
  6725. * // => true
  6726. *
  6727. * // using the `_.property` callback shorthand
  6728. * _.some(users, 'active');
  6729. * // => true
  6730. */
  6731. function some(collection, predicate, thisArg) {
  6732. var func = isArray(collection) ? arraySome : baseSome;
  6733. if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
  6734. predicate = undefined;
  6735. }
  6736. if (typeof predicate != 'function' || thisArg !== undefined) {
  6737. predicate = getCallback(predicate, thisArg, 3);
  6738. }
  6739. return func(collection, predicate);
  6740. }
  6741. /**
  6742. * Creates an array of elements, sorted in ascending order by the results of
  6743. * running each element in a collection through `iteratee`. This method performs
  6744. * a stable sort, that is, it preserves the original sort order of equal elements.
  6745. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  6746. * (value, index|key, collection).
  6747. *
  6748. * If a property name is provided for `iteratee` the created `_.property`
  6749. * style callback returns the property value of the given element.
  6750. *
  6751. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6752. * style callback returns `true` for elements that have a matching property
  6753. * value, else `false`.
  6754. *
  6755. * If an object is provided for `iteratee` the created `_.matches` style
  6756. * callback returns `true` for elements that have the properties of the given
  6757. * object, else `false`.
  6758. *
  6759. * @static
  6760. * @memberOf _
  6761. * @category Collection
  6762. * @param {Array|Object|string} collection The collection to iterate over.
  6763. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  6764. * per iteration.
  6765. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6766. * @returns {Array} Returns the new sorted array.
  6767. * @example
  6768. *
  6769. * _.sortBy([1, 2, 3], function(n) {
  6770. * return Math.sin(n);
  6771. * });
  6772. * // => [3, 1, 2]
  6773. *
  6774. * _.sortBy([1, 2, 3], function(n) {
  6775. * return this.sin(n);
  6776. * }, Math);
  6777. * // => [3, 1, 2]
  6778. *
  6779. * var users = [
  6780. * { 'user': 'fred' },
  6781. * { 'user': 'pebbles' },
  6782. * { 'user': 'barney' }
  6783. * ];
  6784. *
  6785. * // using the `_.property` callback shorthand
  6786. * _.pluck(_.sortBy(users, 'user'), 'user');
  6787. * // => ['barney', 'fred', 'pebbles']
  6788. */
  6789. function sortBy(collection, iteratee, thisArg) {
  6790. if (collection == null) {
  6791. return [];
  6792. }
  6793. if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
  6794. iteratee = undefined;
  6795. }
  6796. var index = -1;
  6797. iteratee = getCallback(iteratee, thisArg, 3);
  6798. var result = baseMap(collection, function(value, key, collection) {
  6799. return { 'criteria': iteratee(value, key, collection), 'index': ++index, 'value': value };
  6800. });
  6801. return baseSortBy(result, compareAscending);
  6802. }
  6803. /**
  6804. * This method is like `_.sortBy` except that it can sort by multiple iteratees
  6805. * or property names.
  6806. *
  6807. * If a property name is provided for an iteratee the created `_.property`
  6808. * style callback returns the property value of the given element.
  6809. *
  6810. * If an object is provided for an iteratee the created `_.matches` style
  6811. * callback returns `true` for elements that have the properties of the given
  6812. * object, else `false`.
  6813. *
  6814. * @static
  6815. * @memberOf _
  6816. * @category Collection
  6817. * @param {Array|Object|string} collection The collection to iterate over.
  6818. * @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees
  6819. * The iteratees to sort by, specified as individual values or arrays of values.
  6820. * @returns {Array} Returns the new sorted array.
  6821. * @example
  6822. *
  6823. * var users = [
  6824. * { 'user': 'fred', 'age': 48 },
  6825. * { 'user': 'barney', 'age': 36 },
  6826. * { 'user': 'fred', 'age': 42 },
  6827. * { 'user': 'barney', 'age': 34 }
  6828. * ];
  6829. *
  6830. * _.map(_.sortByAll(users, ['user', 'age']), _.values);
  6831. * // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
  6832. *
  6833. * _.map(_.sortByAll(users, 'user', function(chr) {
  6834. * return Math.floor(chr.age / 10);
  6835. * }), _.values);
  6836. * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
  6837. */
  6838. var sortByAll = restParam(function(collection, iteratees) {
  6839. if (collection == null) {
  6840. return [];
  6841. }
  6842. var guard = iteratees[2];
  6843. if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {
  6844. iteratees.length = 1;
  6845. }
  6846. return baseSortByOrder(collection, baseFlatten(iteratees), []);
  6847. });
  6848. /**
  6849. * This method is like `_.sortByAll` except that it allows specifying the
  6850. * sort orders of the iteratees to sort by. If `orders` is unspecified, all
  6851. * values are sorted in ascending order. Otherwise, a value is sorted in
  6852. * ascending order if its corresponding order is "asc", and descending if "desc".
  6853. *
  6854. * If a property name is provided for an iteratee the created `_.property`
  6855. * style callback returns the property value of the given element.
  6856. *
  6857. * If an object is provided for an iteratee the created `_.matches` style
  6858. * callback returns `true` for elements that have the properties of the given
  6859. * object, else `false`.
  6860. *
  6861. * @static
  6862. * @memberOf _
  6863. * @category Collection
  6864. * @param {Array|Object|string} collection The collection to iterate over.
  6865. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  6866. * @param {boolean[]} [orders] The sort orders of `iteratees`.
  6867. * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
  6868. * @returns {Array} Returns the new sorted array.
  6869. * @example
  6870. *
  6871. * var users = [
  6872. * { 'user': 'fred', 'age': 48 },
  6873. * { 'user': 'barney', 'age': 34 },
  6874. * { 'user': 'fred', 'age': 42 },
  6875. * { 'user': 'barney', 'age': 36 }
  6876. * ];
  6877. *
  6878. * // sort by `user` in ascending order and by `age` in descending order
  6879. * _.map(_.sortByOrder(users, ['user', 'age'], ['asc', 'desc']), _.values);
  6880. * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
  6881. */
  6882. function sortByOrder(collection, iteratees, orders, guard) {
  6883. if (collection == null) {
  6884. return [];
  6885. }
  6886. if (guard && isIterateeCall(iteratees, orders, guard)) {
  6887. orders = undefined;
  6888. }
  6889. if (!isArray(iteratees)) {
  6890. iteratees = iteratees == null ? [] : [iteratees];
  6891. }
  6892. if (!isArray(orders)) {
  6893. orders = orders == null ? [] : [orders];
  6894. }
  6895. return baseSortByOrder(collection, iteratees, orders);
  6896. }
  6897. /**
  6898. * Performs a deep comparison between each element in `collection` and the
  6899. * source object, returning an array of all elements that have equivalent
  6900. * property values.
  6901. *
  6902. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  6903. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  6904. * their own, not inherited, enumerable properties. For comparing a single
  6905. * own or inherited property value see `_.matchesProperty`.
  6906. *
  6907. * @static
  6908. * @memberOf _
  6909. * @category Collection
  6910. * @param {Array|Object|string} collection The collection to search.
  6911. * @param {Object} source The object of property values to match.
  6912. * @returns {Array} Returns the new filtered array.
  6913. * @example
  6914. *
  6915. * var users = [
  6916. * { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] },
  6917. * { 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] }
  6918. * ];
  6919. *
  6920. * _.pluck(_.where(users, { 'age': 36, 'active': false }), 'user');
  6921. * // => ['barney']
  6922. *
  6923. * _.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
  6924. * // => ['fred']
  6925. */
  6926. function where(collection, source) {
  6927. return filter(collection, baseMatches(source));
  6928. }
  6929. /*------------------------------------------------------------------------*/
  6930. /**
  6931. * Gets the number of milliseconds that have elapsed since the Unix epoch
  6932. * (1 January 1970 00:00:00 UTC).
  6933. *
  6934. * @static
  6935. * @memberOf _
  6936. * @category Date
  6937. * @example
  6938. *
  6939. * _.defer(function(stamp) {
  6940. * console.log(_.now() - stamp);
  6941. * }, _.now());
  6942. * // => logs the number of milliseconds it took for the deferred function to be invoked
  6943. */
  6944. var now = nativeNow || function() {
  6945. return new Date().getTime();
  6946. };
  6947. /*------------------------------------------------------------------------*/
  6948. /**
  6949. * The opposite of `_.before`; this method creates a function that invokes
  6950. * `func` once it's called `n` or more times.
  6951. *
  6952. * @static
  6953. * @memberOf _
  6954. * @category Function
  6955. * @param {number} n The number of calls before `func` is invoked.
  6956. * @param {Function} func The function to restrict.
  6957. * @returns {Function} Returns the new restricted function.
  6958. * @example
  6959. *
  6960. * var saves = ['profile', 'settings'];
  6961. *
  6962. * var done = _.after(saves.length, function() {
  6963. * console.log('done saving!');
  6964. * });
  6965. *
  6966. * _.forEach(saves, function(type) {
  6967. * asyncSave({ 'type': type, 'complete': done });
  6968. * });
  6969. * // => logs 'done saving!' after the two async saves have completed
  6970. */
  6971. function after(n, func) {
  6972. if (typeof func != 'function') {
  6973. if (typeof n == 'function') {
  6974. var temp = n;
  6975. n = func;
  6976. func = temp;
  6977. } else {
  6978. throw new TypeError(FUNC_ERROR_TEXT);
  6979. }
  6980. }
  6981. n = nativeIsFinite(n = +n) ? n : 0;
  6982. return function() {
  6983. if (--n < 1) {
  6984. return func.apply(this, arguments);
  6985. }
  6986. };
  6987. }
  6988. /**
  6989. * Creates a function that accepts up to `n` arguments ignoring any
  6990. * additional arguments.
  6991. *
  6992. * @static
  6993. * @memberOf _
  6994. * @category Function
  6995. * @param {Function} func The function to cap arguments for.
  6996. * @param {number} [n=func.length] The arity cap.
  6997. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  6998. * @returns {Function} Returns the new function.
  6999. * @example
  7000. *
  7001. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  7002. * // => [6, 8, 10]
  7003. */
  7004. function ary(func, n, guard) {
  7005. if (guard && isIterateeCall(func, n, guard)) {
  7006. n = undefined;
  7007. }
  7008. n = (func && n == null) ? func.length : nativeMax(+n || 0, 0);
  7009. return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
  7010. }
  7011. /**
  7012. * Creates a function that invokes `func`, with the `this` binding and arguments
  7013. * of the created function, while it's called less than `n` times. Subsequent
  7014. * calls to the created function return the result of the last `func` invocation.
  7015. *
  7016. * @static
  7017. * @memberOf _
  7018. * @category Function
  7019. * @param {number} n The number of calls at which `func` is no longer invoked.
  7020. * @param {Function} func The function to restrict.
  7021. * @returns {Function} Returns the new restricted function.
  7022. * @example
  7023. *
  7024. * jQuery('#add').on('click', _.before(5, addContactToList));
  7025. * // => allows adding up to 4 contacts to the list
  7026. */
  7027. function before(n, func) {
  7028. var result;
  7029. if (typeof func != 'function') {
  7030. if (typeof n == 'function') {
  7031. var temp = n;
  7032. n = func;
  7033. func = temp;
  7034. } else {
  7035. throw new TypeError(FUNC_ERROR_TEXT);
  7036. }
  7037. }
  7038. return function() {
  7039. if (--n > 0) {
  7040. result = func.apply(this, arguments);
  7041. }
  7042. if (n <= 1) {
  7043. func = undefined;
  7044. }
  7045. return result;
  7046. };
  7047. }
  7048. /**
  7049. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  7050. * and prepends any additional `_.bind` arguments to those provided to the
  7051. * bound function.
  7052. *
  7053. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  7054. * may be used as a placeholder for partially applied arguments.
  7055. *
  7056. * **Note:** Unlike native `Function#bind` this method does not set the "length"
  7057. * property of bound functions.
  7058. *
  7059. * @static
  7060. * @memberOf _
  7061. * @category Function
  7062. * @param {Function} func The function to bind.
  7063. * @param {*} thisArg The `this` binding of `func`.
  7064. * @param {...*} [partials] The arguments to be partially applied.
  7065. * @returns {Function} Returns the new bound function.
  7066. * @example
  7067. *
  7068. * var greet = function(greeting, punctuation) {
  7069. * return greeting + ' ' + this.user + punctuation;
  7070. * };
  7071. *
  7072. * var object = { 'user': 'fred' };
  7073. *
  7074. * var bound = _.bind(greet, object, 'hi');
  7075. * bound('!');
  7076. * // => 'hi fred!'
  7077. *
  7078. * // using placeholders
  7079. * var bound = _.bind(greet, object, _, '!');
  7080. * bound('hi');
  7081. * // => 'hi fred!'
  7082. */
  7083. var bind = restParam(function(func, thisArg, partials) {
  7084. var bitmask = BIND_FLAG;
  7085. if (partials.length) {
  7086. var holders = replaceHolders(partials, bind.placeholder);
  7087. bitmask |= PARTIAL_FLAG;
  7088. }
  7089. return createWrapper(func, bitmask, thisArg, partials, holders);
  7090. });
  7091. /**
  7092. * Binds methods of an object to the object itself, overwriting the existing
  7093. * method. Method names may be specified as individual arguments or as arrays
  7094. * of method names. If no method names are provided all enumerable function
  7095. * properties, own and inherited, of `object` are bound.
  7096. *
  7097. * **Note:** This method does not set the "length" property of bound functions.
  7098. *
  7099. * @static
  7100. * @memberOf _
  7101. * @category Function
  7102. * @param {Object} object The object to bind and assign the bound methods to.
  7103. * @param {...(string|string[])} [methodNames] The object method names to bind,
  7104. * specified as individual method names or arrays of method names.
  7105. * @returns {Object} Returns `object`.
  7106. * @example
  7107. *
  7108. * var view = {
  7109. * 'label': 'docs',
  7110. * 'onClick': function() {
  7111. * console.log('clicked ' + this.label);
  7112. * }
  7113. * };
  7114. *
  7115. * _.bindAll(view);
  7116. * jQuery('#docs').on('click', view.onClick);
  7117. * // => logs 'clicked docs' when the element is clicked
  7118. */
  7119. var bindAll = restParam(function(object, methodNames) {
  7120. methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object);
  7121. var index = -1,
  7122. length = methodNames.length;
  7123. while (++index < length) {
  7124. var key = methodNames[index];
  7125. object[key] = createWrapper(object[key], BIND_FLAG, object);
  7126. }
  7127. return object;
  7128. });
  7129. /**
  7130. * Creates a function that invokes the method at `object[key]` and prepends
  7131. * any additional `_.bindKey` arguments to those provided to the bound function.
  7132. *
  7133. * This method differs from `_.bind` by allowing bound functions to reference
  7134. * methods that may be redefined or don't yet exist.
  7135. * See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  7136. * for more details.
  7137. *
  7138. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  7139. * builds, may be used as a placeholder for partially applied arguments.
  7140. *
  7141. * @static
  7142. * @memberOf _
  7143. * @category Function
  7144. * @param {Object} object The object the method belongs to.
  7145. * @param {string} key The key of the method.
  7146. * @param {...*} [partials] The arguments to be partially applied.
  7147. * @returns {Function} Returns the new bound function.
  7148. * @example
  7149. *
  7150. * var object = {
  7151. * 'user': 'fred',
  7152. * 'greet': function(greeting, punctuation) {
  7153. * return greeting + ' ' + this.user + punctuation;
  7154. * }
  7155. * };
  7156. *
  7157. * var bound = _.bindKey(object, 'greet', 'hi');
  7158. * bound('!');
  7159. * // => 'hi fred!'
  7160. *
  7161. * object.greet = function(greeting, punctuation) {
  7162. * return greeting + 'ya ' + this.user + punctuation;
  7163. * };
  7164. *
  7165. * bound('!');
  7166. * // => 'hiya fred!'
  7167. *
  7168. * // using placeholders
  7169. * var bound = _.bindKey(object, 'greet', _, '!');
  7170. * bound('hi');
  7171. * // => 'hiya fred!'
  7172. */
  7173. var bindKey = restParam(function(object, key, partials) {
  7174. var bitmask = BIND_FLAG | BIND_KEY_FLAG;
  7175. if (partials.length) {
  7176. var holders = replaceHolders(partials, bindKey.placeholder);
  7177. bitmask |= PARTIAL_FLAG;
  7178. }
  7179. return createWrapper(key, bitmask, object, partials, holders);
  7180. });
  7181. /**
  7182. * Creates a function that accepts one or more arguments of `func` that when
  7183. * called either invokes `func` returning its result, if all `func` arguments
  7184. * have been provided, or returns a function that accepts one or more of the
  7185. * remaining `func` arguments, and so on. The arity of `func` may be specified
  7186. * if `func.length` is not sufficient.
  7187. *
  7188. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  7189. * may be used as a placeholder for provided arguments.
  7190. *
  7191. * **Note:** This method does not set the "length" property of curried functions.
  7192. *
  7193. * @static
  7194. * @memberOf _
  7195. * @category Function
  7196. * @param {Function} func The function to curry.
  7197. * @param {number} [arity=func.length] The arity of `func`.
  7198. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  7199. * @returns {Function} Returns the new curried function.
  7200. * @example
  7201. *
  7202. * var abc = function(a, b, c) {
  7203. * return [a, b, c];
  7204. * };
  7205. *
  7206. * var curried = _.curry(abc);
  7207. *
  7208. * curried(1)(2)(3);
  7209. * // => [1, 2, 3]
  7210. *
  7211. * curried(1, 2)(3);
  7212. * // => [1, 2, 3]
  7213. *
  7214. * curried(1, 2, 3);
  7215. * // => [1, 2, 3]
  7216. *
  7217. * // using placeholders
  7218. * curried(1)(_, 3)(2);
  7219. * // => [1, 2, 3]
  7220. */
  7221. var curry = createCurry(CURRY_FLAG);
  7222. /**
  7223. * This method is like `_.curry` except that arguments are applied to `func`
  7224. * in the manner of `_.partialRight` instead of `_.partial`.
  7225. *
  7226. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  7227. * builds, may be used as a placeholder for provided arguments.
  7228. *
  7229. * **Note:** This method does not set the "length" property of curried functions.
  7230. *
  7231. * @static
  7232. * @memberOf _
  7233. * @category Function
  7234. * @param {Function} func The function to curry.
  7235. * @param {number} [arity=func.length] The arity of `func`.
  7236. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  7237. * @returns {Function} Returns the new curried function.
  7238. * @example
  7239. *
  7240. * var abc = function(a, b, c) {
  7241. * return [a, b, c];
  7242. * };
  7243. *
  7244. * var curried = _.curryRight(abc);
  7245. *
  7246. * curried(3)(2)(1);
  7247. * // => [1, 2, 3]
  7248. *
  7249. * curried(2, 3)(1);
  7250. * // => [1, 2, 3]
  7251. *
  7252. * curried(1, 2, 3);
  7253. * // => [1, 2, 3]
  7254. *
  7255. * // using placeholders
  7256. * curried(3)(1, _)(2);
  7257. * // => [1, 2, 3]
  7258. */
  7259. var curryRight = createCurry(CURRY_RIGHT_FLAG);
  7260. /**
  7261. * Creates a debounced function that delays invoking `func` until after `wait`
  7262. * milliseconds have elapsed since the last time the debounced function was
  7263. * invoked. The debounced function comes with a `cancel` method to cancel
  7264. * delayed invocations. Provide an options object to indicate that `func`
  7265. * should be invoked on the leading and/or trailing edge of the `wait` timeout.
  7266. * Subsequent calls to the debounced function return the result of the last
  7267. * `func` invocation.
  7268. *
  7269. * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
  7270. * on the trailing edge of the timeout only if the the debounced function is
  7271. * invoked more than once during the `wait` timeout.
  7272. *
  7273. * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
  7274. * for details over the differences between `_.debounce` and `_.throttle`.
  7275. *
  7276. * @static
  7277. * @memberOf _
  7278. * @category Function
  7279. * @param {Function} func The function to debounce.
  7280. * @param {number} [wait=0] The number of milliseconds to delay.
  7281. * @param {Object} [options] The options object.
  7282. * @param {boolean} [options.leading=false] Specify invoking on the leading
  7283. * edge of the timeout.
  7284. * @param {number} [options.maxWait] The maximum time `func` is allowed to be
  7285. * delayed before it's invoked.
  7286. * @param {boolean} [options.trailing=true] Specify invoking on the trailing
  7287. * edge of the timeout.
  7288. * @returns {Function} Returns the new debounced function.
  7289. * @example
  7290. *
  7291. * // avoid costly calculations while the window size is in flux
  7292. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  7293. *
  7294. * // invoke `sendMail` when the click event is fired, debouncing subsequent calls
  7295. * jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
  7296. * 'leading': true,
  7297. * 'trailing': false
  7298. * }));
  7299. *
  7300. * // ensure `batchLog` is invoked once after 1 second of debounced calls
  7301. * var source = new EventSource('/stream');
  7302. * jQuery(source).on('message', _.debounce(batchLog, 250, {
  7303. * 'maxWait': 1000
  7304. * }));
  7305. *
  7306. * // cancel a debounced call
  7307. * var upcomingChanges = _.debounce(batchLog, 1000);
  7308. * Object.observe(models.todo, upcomingChanges);
  7309. *
  7310. * Object.observe(models, function(changes) {
  7311. * if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
  7312. * upcomingChanges.cancel();
  7313. * }
  7314. * }, ['delete']);
  7315. *
  7316. * // ...at some point `models.todo` is changed
  7317. * models.todo.completed = true;
  7318. *
  7319. * // ...before 1 second has passed `models.todo` is deleted
  7320. * // which cancels the debounced `upcomingChanges` call
  7321. * delete models.todo;
  7322. */
  7323. function debounce(func, wait, options) {
  7324. var args,
  7325. maxTimeoutId,
  7326. result,
  7327. stamp,
  7328. thisArg,
  7329. timeoutId,
  7330. trailingCall,
  7331. lastCalled = 0,
  7332. maxWait = false,
  7333. trailing = true;
  7334. if (typeof func != 'function') {
  7335. throw new TypeError(FUNC_ERROR_TEXT);
  7336. }
  7337. wait = wait < 0 ? 0 : (+wait || 0);
  7338. if (options === true) {
  7339. var leading = true;
  7340. trailing = false;
  7341. } else if (isObject(options)) {
  7342. leading = !!options.leading;
  7343. maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
  7344. trailing = 'trailing' in options ? !!options.trailing : trailing;
  7345. }
  7346. function cancel() {
  7347. if (timeoutId) {
  7348. clearTimeout(timeoutId);
  7349. }
  7350. if (maxTimeoutId) {
  7351. clearTimeout(maxTimeoutId);
  7352. }
  7353. lastCalled = 0;
  7354. maxTimeoutId = timeoutId = trailingCall = undefined;
  7355. }
  7356. function complete(isCalled, id) {
  7357. if (id) {
  7358. clearTimeout(id);
  7359. }
  7360. maxTimeoutId = timeoutId = trailingCall = undefined;
  7361. if (isCalled) {
  7362. lastCalled = now();
  7363. result = func.apply(thisArg, args);
  7364. if (!timeoutId && !maxTimeoutId) {
  7365. args = thisArg = undefined;
  7366. }
  7367. }
  7368. }
  7369. function delayed() {
  7370. var remaining = wait - (now() - stamp);
  7371. if (remaining <= 0 || remaining > wait) {
  7372. complete(trailingCall, maxTimeoutId);
  7373. } else {
  7374. timeoutId = setTimeout(delayed, remaining);
  7375. }
  7376. }
  7377. function maxDelayed() {
  7378. complete(trailing, timeoutId);
  7379. }
  7380. function debounced() {
  7381. args = arguments;
  7382. stamp = now();
  7383. thisArg = this;
  7384. trailingCall = trailing && (timeoutId || !leading);
  7385. if (maxWait === false) {
  7386. var leadingCall = leading && !timeoutId;
  7387. } else {
  7388. if (!maxTimeoutId && !leading) {
  7389. lastCalled = stamp;
  7390. }
  7391. var remaining = maxWait - (stamp - lastCalled),
  7392. isCalled = remaining <= 0 || remaining > maxWait;
  7393. if (isCalled) {
  7394. if (maxTimeoutId) {
  7395. maxTimeoutId = clearTimeout(maxTimeoutId);
  7396. }
  7397. lastCalled = stamp;
  7398. result = func.apply(thisArg, args);
  7399. }
  7400. else if (!maxTimeoutId) {
  7401. maxTimeoutId = setTimeout(maxDelayed, remaining);
  7402. }
  7403. }
  7404. if (isCalled && timeoutId) {
  7405. timeoutId = clearTimeout(timeoutId);
  7406. }
  7407. else if (!timeoutId && wait !== maxWait) {
  7408. timeoutId = setTimeout(delayed, wait);
  7409. }
  7410. if (leadingCall) {
  7411. isCalled = true;
  7412. result = func.apply(thisArg, args);
  7413. }
  7414. if (isCalled && !timeoutId && !maxTimeoutId) {
  7415. args = thisArg = undefined;
  7416. }
  7417. return result;
  7418. }
  7419. debounced.cancel = cancel;
  7420. return debounced;
  7421. }
  7422. /**
  7423. * Defers invoking the `func` until the current call stack has cleared. Any
  7424. * additional arguments are provided to `func` when it's invoked.
  7425. *
  7426. * @static
  7427. * @memberOf _
  7428. * @category Function
  7429. * @param {Function} func The function to defer.
  7430. * @param {...*} [args] The arguments to invoke the function with.
  7431. * @returns {number} Returns the timer id.
  7432. * @example
  7433. *
  7434. * _.defer(function(text) {
  7435. * console.log(text);
  7436. * }, 'deferred');
  7437. * // logs 'deferred' after one or more milliseconds
  7438. */
  7439. var defer = restParam(function(func, args) {
  7440. return baseDelay(func, 1, args);
  7441. });
  7442. /**
  7443. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  7444. * provided to `func` when it's invoked.
  7445. *
  7446. * @static
  7447. * @memberOf _
  7448. * @category Function
  7449. * @param {Function} func The function to delay.
  7450. * @param {number} wait The number of milliseconds to delay invocation.
  7451. * @param {...*} [args] The arguments to invoke the function with.
  7452. * @returns {number} Returns the timer id.
  7453. * @example
  7454. *
  7455. * _.delay(function(text) {
  7456. * console.log(text);
  7457. * }, 1000, 'later');
  7458. * // => logs 'later' after one second
  7459. */
  7460. var delay = restParam(function(func, wait, args) {
  7461. return baseDelay(func, wait, args);
  7462. });
  7463. /**
  7464. * Creates a function that returns the result of invoking the provided
  7465. * functions with the `this` binding of the created function, where each
  7466. * successive invocation is supplied the return value of the previous.
  7467. *
  7468. * @static
  7469. * @memberOf _
  7470. * @category Function
  7471. * @param {...Function} [funcs] Functions to invoke.
  7472. * @returns {Function} Returns the new function.
  7473. * @example
  7474. *
  7475. * function square(n) {
  7476. * return n * n;
  7477. * }
  7478. *
  7479. * var addSquare = _.flow(_.add, square);
  7480. * addSquare(1, 2);
  7481. * // => 9
  7482. */
  7483. var flow = createFlow();
  7484. /**
  7485. * This method is like `_.flow` except that it creates a function that
  7486. * invokes the provided functions from right to left.
  7487. *
  7488. * @static
  7489. * @memberOf _
  7490. * @alias backflow, compose
  7491. * @category Function
  7492. * @param {...Function} [funcs] Functions to invoke.
  7493. * @returns {Function} Returns the new function.
  7494. * @example
  7495. *
  7496. * function square(n) {
  7497. * return n * n;
  7498. * }
  7499. *
  7500. * var addSquare = _.flowRight(square, _.add);
  7501. * addSquare(1, 2);
  7502. * // => 9
  7503. */
  7504. var flowRight = createFlow(true);
  7505. /**
  7506. * Creates a function that memoizes the result of `func`. If `resolver` is
  7507. * provided it determines the cache key for storing the result based on the
  7508. * arguments provided to the memoized function. By default, the first argument
  7509. * provided to the memoized function is coerced to a string and used as the
  7510. * cache key. The `func` is invoked with the `this` binding of the memoized
  7511. * function.
  7512. *
  7513. * **Note:** The cache is exposed as the `cache` property on the memoized
  7514. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  7515. * constructor with one whose instances implement the [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
  7516. * method interface of `get`, `has`, and `set`.
  7517. *
  7518. * @static
  7519. * @memberOf _
  7520. * @category Function
  7521. * @param {Function} func The function to have its output memoized.
  7522. * @param {Function} [resolver] The function to resolve the cache key.
  7523. * @returns {Function} Returns the new memoizing function.
  7524. * @example
  7525. *
  7526. * var upperCase = _.memoize(function(string) {
  7527. * return string.toUpperCase();
  7528. * });
  7529. *
  7530. * upperCase('fred');
  7531. * // => 'FRED'
  7532. *
  7533. * // modifying the result cache
  7534. * upperCase.cache.set('fred', 'BARNEY');
  7535. * upperCase('fred');
  7536. * // => 'BARNEY'
  7537. *
  7538. * // replacing `_.memoize.Cache`
  7539. * var object = { 'user': 'fred' };
  7540. * var other = { 'user': 'barney' };
  7541. * var identity = _.memoize(_.identity);
  7542. *
  7543. * identity(object);
  7544. * // => { 'user': 'fred' }
  7545. * identity(other);
  7546. * // => { 'user': 'fred' }
  7547. *
  7548. * _.memoize.Cache = WeakMap;
  7549. * var identity = _.memoize(_.identity);
  7550. *
  7551. * identity(object);
  7552. * // => { 'user': 'fred' }
  7553. * identity(other);
  7554. * // => { 'user': 'barney' }
  7555. */
  7556. function memoize(func, resolver) {
  7557. if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
  7558. throw new TypeError(FUNC_ERROR_TEXT);
  7559. }
  7560. var memoized = function() {
  7561. var args = arguments,
  7562. key = resolver ? resolver.apply(this, args) : args[0],
  7563. cache = memoized.cache;
  7564. if (cache.has(key)) {
  7565. return cache.get(key);
  7566. }
  7567. var result = func.apply(this, args);
  7568. memoized.cache = cache.set(key, result);
  7569. return result;
  7570. };
  7571. memoized.cache = new memoize.Cache;
  7572. return memoized;
  7573. }
  7574. /**
  7575. * Creates a function that runs each argument through a corresponding
  7576. * transform function.
  7577. *
  7578. * @static
  7579. * @memberOf _
  7580. * @category Function
  7581. * @param {Function} func The function to wrap.
  7582. * @param {...(Function|Function[])} [transforms] The functions to transform
  7583. * arguments, specified as individual functions or arrays of functions.
  7584. * @returns {Function} Returns the new function.
  7585. * @example
  7586. *
  7587. * function doubled(n) {
  7588. * return n * 2;
  7589. * }
  7590. *
  7591. * function square(n) {
  7592. * return n * n;
  7593. * }
  7594. *
  7595. * var modded = _.modArgs(function(x, y) {
  7596. * return [x, y];
  7597. * }, square, doubled);
  7598. *
  7599. * modded(1, 2);
  7600. * // => [1, 4]
  7601. *
  7602. * modded(5, 10);
  7603. * // => [25, 20]
  7604. */
  7605. var modArgs = restParam(function(func, transforms) {
  7606. transforms = baseFlatten(transforms);
  7607. if (typeof func != 'function' || !arrayEvery(transforms, baseIsFunction)) {
  7608. throw new TypeError(FUNC_ERROR_TEXT);
  7609. }
  7610. var length = transforms.length;
  7611. return restParam(function(args) {
  7612. var index = nativeMin(args.length, length);
  7613. while (index--) {
  7614. args[index] = transforms[index](args[index]);
  7615. }
  7616. return func.apply(this, args);
  7617. });
  7618. });
  7619. /**
  7620. * Creates a function that negates the result of the predicate `func`. The
  7621. * `func` predicate is invoked with the `this` binding and arguments of the
  7622. * created function.
  7623. *
  7624. * @static
  7625. * @memberOf _
  7626. * @category Function
  7627. * @param {Function} predicate The predicate to negate.
  7628. * @returns {Function} Returns the new function.
  7629. * @example
  7630. *
  7631. * function isEven(n) {
  7632. * return n % 2 == 0;
  7633. * }
  7634. *
  7635. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  7636. * // => [1, 3, 5]
  7637. */
  7638. function negate(predicate) {
  7639. if (typeof predicate != 'function') {
  7640. throw new TypeError(FUNC_ERROR_TEXT);
  7641. }
  7642. return function() {
  7643. return !predicate.apply(this, arguments);
  7644. };
  7645. }
  7646. /**
  7647. * Creates a function that is restricted to invoking `func` once. Repeat calls
  7648. * to the function return the value of the first call. The `func` is invoked
  7649. * with the `this` binding and arguments of the created function.
  7650. *
  7651. * @static
  7652. * @memberOf _
  7653. * @category Function
  7654. * @param {Function} func The function to restrict.
  7655. * @returns {Function} Returns the new restricted function.
  7656. * @example
  7657. *
  7658. * var initialize = _.once(createApplication);
  7659. * initialize();
  7660. * initialize();
  7661. * // `initialize` invokes `createApplication` once
  7662. */
  7663. function once(func) {
  7664. return before(2, func);
  7665. }
  7666. /**
  7667. * Creates a function that invokes `func` with `partial` arguments prepended
  7668. * to those provided to the new function. This method is like `_.bind` except
  7669. * it does **not** alter the `this` binding.
  7670. *
  7671. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  7672. * builds, may be used as a placeholder for partially applied arguments.
  7673. *
  7674. * **Note:** This method does not set the "length" property of partially
  7675. * applied functions.
  7676. *
  7677. * @static
  7678. * @memberOf _
  7679. * @category Function
  7680. * @param {Function} func The function to partially apply arguments to.
  7681. * @param {...*} [partials] The arguments to be partially applied.
  7682. * @returns {Function} Returns the new partially applied function.
  7683. * @example
  7684. *
  7685. * var greet = function(greeting, name) {
  7686. * return greeting + ' ' + name;
  7687. * };
  7688. *
  7689. * var sayHelloTo = _.partial(greet, 'hello');
  7690. * sayHelloTo('fred');
  7691. * // => 'hello fred'
  7692. *
  7693. * // using placeholders
  7694. * var greetFred = _.partial(greet, _, 'fred');
  7695. * greetFred('hi');
  7696. * // => 'hi fred'
  7697. */
  7698. var partial = createPartial(PARTIAL_FLAG);
  7699. /**
  7700. * This method is like `_.partial` except that partially applied arguments
  7701. * are appended to those provided to the new function.
  7702. *
  7703. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  7704. * builds, may be used as a placeholder for partially applied arguments.
  7705. *
  7706. * **Note:** This method does not set the "length" property of partially
  7707. * applied functions.
  7708. *
  7709. * @static
  7710. * @memberOf _
  7711. * @category Function
  7712. * @param {Function} func The function to partially apply arguments to.
  7713. * @param {...*} [partials] The arguments to be partially applied.
  7714. * @returns {Function} Returns the new partially applied function.
  7715. * @example
  7716. *
  7717. * var greet = function(greeting, name) {
  7718. * return greeting + ' ' + name;
  7719. * };
  7720. *
  7721. * var greetFred = _.partialRight(greet, 'fred');
  7722. * greetFred('hi');
  7723. * // => 'hi fred'
  7724. *
  7725. * // using placeholders
  7726. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  7727. * sayHelloTo('fred');
  7728. * // => 'hello fred'
  7729. */
  7730. var partialRight = createPartial(PARTIAL_RIGHT_FLAG);
  7731. /**
  7732. * Creates a function that invokes `func` with arguments arranged according
  7733. * to the specified indexes where the argument value at the first index is
  7734. * provided as the first argument, the argument value at the second index is
  7735. * provided as the second argument, and so on.
  7736. *
  7737. * @static
  7738. * @memberOf _
  7739. * @category Function
  7740. * @param {Function} func The function to rearrange arguments for.
  7741. * @param {...(number|number[])} indexes The arranged argument indexes,
  7742. * specified as individual indexes or arrays of indexes.
  7743. * @returns {Function} Returns the new function.
  7744. * @example
  7745. *
  7746. * var rearged = _.rearg(function(a, b, c) {
  7747. * return [a, b, c];
  7748. * }, 2, 0, 1);
  7749. *
  7750. * rearged('b', 'c', 'a')
  7751. * // => ['a', 'b', 'c']
  7752. *
  7753. * var map = _.rearg(_.map, [1, 0]);
  7754. * map(function(n) {
  7755. * return n * 3;
  7756. * }, [1, 2, 3]);
  7757. * // => [3, 6, 9]
  7758. */
  7759. var rearg = restParam(function(func, indexes) {
  7760. return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes));
  7761. });
  7762. /**
  7763. * Creates a function that invokes `func` with the `this` binding of the
  7764. * created function and arguments from `start` and beyond provided as an array.
  7765. *
  7766. * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/Web/JavaScript/Reference/Functions/rest_parameters).
  7767. *
  7768. * @static
  7769. * @memberOf _
  7770. * @category Function
  7771. * @param {Function} func The function to apply a rest parameter to.
  7772. * @param {number} [start=func.length-1] The start position of the rest parameter.
  7773. * @returns {Function} Returns the new function.
  7774. * @example
  7775. *
  7776. * var say = _.restParam(function(what, names) {
  7777. * return what + ' ' + _.initial(names).join(', ') +
  7778. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  7779. * });
  7780. *
  7781. * say('hello', 'fred', 'barney', 'pebbles');
  7782. * // => 'hello fred, barney, & pebbles'
  7783. */
  7784. function restParam(func, start) {
  7785. if (typeof func != 'function') {
  7786. throw new TypeError(FUNC_ERROR_TEXT);
  7787. }
  7788. start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
  7789. return function() {
  7790. var args = arguments,
  7791. index = -1,
  7792. length = nativeMax(args.length - start, 0),
  7793. rest = Array(length);
  7794. while (++index < length) {
  7795. rest[index] = args[start + index];
  7796. }
  7797. switch (start) {
  7798. case 0: return func.call(this, rest);
  7799. case 1: return func.call(this, args[0], rest);
  7800. case 2: return func.call(this, args[0], args[1], rest);
  7801. }
  7802. var otherArgs = Array(start + 1);
  7803. index = -1;
  7804. while (++index < start) {
  7805. otherArgs[index] = args[index];
  7806. }
  7807. otherArgs[start] = rest;
  7808. return func.apply(this, otherArgs);
  7809. };
  7810. }
  7811. /**
  7812. * Creates a function that invokes `func` with the `this` binding of the created
  7813. * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
  7814. *
  7815. * **Note:** This method is based on the [spread operator](https://developer.mozilla.org/Web/JavaScript/Reference/Operators/Spread_operator).
  7816. *
  7817. * @static
  7818. * @memberOf _
  7819. * @category Function
  7820. * @param {Function} func The function to spread arguments over.
  7821. * @returns {Function} Returns the new function.
  7822. * @example
  7823. *
  7824. * var say = _.spread(function(who, what) {
  7825. * return who + ' says ' + what;
  7826. * });
  7827. *
  7828. * say(['fred', 'hello']);
  7829. * // => 'fred says hello'
  7830. *
  7831. * // with a Promise
  7832. * var numbers = Promise.all([
  7833. * Promise.resolve(40),
  7834. * Promise.resolve(36)
  7835. * ]);
  7836. *
  7837. * numbers.then(_.spread(function(x, y) {
  7838. * return x + y;
  7839. * }));
  7840. * // => a Promise of 76
  7841. */
  7842. function spread(func) {
  7843. if (typeof func != 'function') {
  7844. throw new TypeError(FUNC_ERROR_TEXT);
  7845. }
  7846. return function(array) {
  7847. return func.apply(this, array);
  7848. };
  7849. }
  7850. /**
  7851. * Creates a throttled function that only invokes `func` at most once per
  7852. * every `wait` milliseconds. The throttled function comes with a `cancel`
  7853. * method to cancel delayed invocations. Provide an options object to indicate
  7854. * that `func` should be invoked on the leading and/or trailing edge of the
  7855. * `wait` timeout. Subsequent calls to the throttled function return the
  7856. * result of the last `func` call.
  7857. *
  7858. * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
  7859. * on the trailing edge of the timeout only if the the throttled function is
  7860. * invoked more than once during the `wait` timeout.
  7861. *
  7862. * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
  7863. * for details over the differences between `_.throttle` and `_.debounce`.
  7864. *
  7865. * @static
  7866. * @memberOf _
  7867. * @category Function
  7868. * @param {Function} func The function to throttle.
  7869. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  7870. * @param {Object} [options] The options object.
  7871. * @param {boolean} [options.leading=true] Specify invoking on the leading
  7872. * edge of the timeout.
  7873. * @param {boolean} [options.trailing=true] Specify invoking on the trailing
  7874. * edge of the timeout.
  7875. * @returns {Function} Returns the new throttled function.
  7876. * @example
  7877. *
  7878. * // avoid excessively updating the position while scrolling
  7879. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  7880. *
  7881. * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
  7882. * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
  7883. * 'trailing': false
  7884. * }));
  7885. *
  7886. * // cancel a trailing throttled call
  7887. * jQuery(window).on('popstate', throttled.cancel);
  7888. */
  7889. function throttle(func, wait, options) {
  7890. var leading = true,
  7891. trailing = true;
  7892. if (typeof func != 'function') {
  7893. throw new TypeError(FUNC_ERROR_TEXT);
  7894. }
  7895. if (options === false) {
  7896. leading = false;
  7897. } else if (isObject(options)) {
  7898. leading = 'leading' in options ? !!options.leading : leading;
  7899. trailing = 'trailing' in options ? !!options.trailing : trailing;
  7900. }
  7901. return debounce(func, wait, { 'leading': leading, 'maxWait': +wait, 'trailing': trailing });
  7902. }
  7903. /**
  7904. * Creates a function that provides `value` to the wrapper function as its
  7905. * first argument. Any additional arguments provided to the function are
  7906. * appended to those provided to the wrapper function. The wrapper is invoked
  7907. * with the `this` binding of the created function.
  7908. *
  7909. * @static
  7910. * @memberOf _
  7911. * @category Function
  7912. * @param {*} value The value to wrap.
  7913. * @param {Function} wrapper The wrapper function.
  7914. * @returns {Function} Returns the new function.
  7915. * @example
  7916. *
  7917. * var p = _.wrap(_.escape, function(func, text) {
  7918. * return '<p>' + func(text) + '</p>';
  7919. * });
  7920. *
  7921. * p('fred, barney, & pebbles');
  7922. * // => '<p>fred, barney, &amp; pebbles</p>'
  7923. */
  7924. function wrap(value, wrapper) {
  7925. wrapper = wrapper == null ? identity : wrapper;
  7926. return createWrapper(wrapper, PARTIAL_FLAG, undefined, [value], []);
  7927. }
  7928. /*------------------------------------------------------------------------*/
  7929. /**
  7930. * Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,
  7931. * otherwise they are assigned by reference. If `customizer` is provided it's
  7932. * invoked to produce the cloned values. If `customizer` returns `undefined`
  7933. * cloning is handled by the method instead. The `customizer` is bound to
  7934. * `thisArg` and invoked with up to three argument; (value [, index|key, object]).
  7935. *
  7936. * **Note:** This method is loosely based on the
  7937. * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
  7938. * The enumerable properties of `arguments` objects and objects created by
  7939. * constructors other than `Object` are cloned to plain `Object` objects. An
  7940. * empty object is returned for uncloneable values such as functions, DOM nodes,
  7941. * Maps, Sets, and WeakMaps.
  7942. *
  7943. * @static
  7944. * @memberOf _
  7945. * @category Lang
  7946. * @param {*} value The value to clone.
  7947. * @param {boolean} [isDeep] Specify a deep clone.
  7948. * @param {Function} [customizer] The function to customize cloning values.
  7949. * @param {*} [thisArg] The `this` binding of `customizer`.
  7950. * @returns {*} Returns the cloned value.
  7951. * @example
  7952. *
  7953. * var users = [
  7954. * { 'user': 'barney' },
  7955. * { 'user': 'fred' }
  7956. * ];
  7957. *
  7958. * var shallow = _.clone(users);
  7959. * shallow[0] === users[0];
  7960. * // => true
  7961. *
  7962. * var deep = _.clone(users, true);
  7963. * deep[0] === users[0];
  7964. * // => false
  7965. *
  7966. * // using a customizer callback
  7967. * var el = _.clone(document.body, function(value) {
  7968. * if (_.isElement(value)) {
  7969. * return value.cloneNode(false);
  7970. * }
  7971. * });
  7972. *
  7973. * el === document.body
  7974. * // => false
  7975. * el.nodeName
  7976. * // => BODY
  7977. * el.childNodes.length;
  7978. * // => 0
  7979. */
  7980. function clone(value, isDeep, customizer, thisArg) {
  7981. if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
  7982. isDeep = false;
  7983. }
  7984. else if (typeof isDeep == 'function') {
  7985. thisArg = customizer;
  7986. customizer = isDeep;
  7987. isDeep = false;
  7988. }
  7989. return typeof customizer == 'function'
  7990. ? baseClone(value, isDeep, bindCallback(customizer, thisArg, 3))
  7991. : baseClone(value, isDeep);
  7992. }
  7993. /**
  7994. * Creates a deep clone of `value`. If `customizer` is provided it's invoked
  7995. * to produce the cloned values. If `customizer` returns `undefined` cloning
  7996. * is handled by the method instead. The `customizer` is bound to `thisArg`
  7997. * and invoked with up to three argument; (value [, index|key, object]).
  7998. *
  7999. * **Note:** This method is loosely based on the
  8000. * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
  8001. * The enumerable properties of `arguments` objects and objects created by
  8002. * constructors other than `Object` are cloned to plain `Object` objects. An
  8003. * empty object is returned for uncloneable values such as functions, DOM nodes,
  8004. * Maps, Sets, and WeakMaps.
  8005. *
  8006. * @static
  8007. * @memberOf _
  8008. * @category Lang
  8009. * @param {*} value The value to deep clone.
  8010. * @param {Function} [customizer] The function to customize cloning values.
  8011. * @param {*} [thisArg] The `this` binding of `customizer`.
  8012. * @returns {*} Returns the deep cloned value.
  8013. * @example
  8014. *
  8015. * var users = [
  8016. * { 'user': 'barney' },
  8017. * { 'user': 'fred' }
  8018. * ];
  8019. *
  8020. * var deep = _.cloneDeep(users);
  8021. * deep[0] === users[0];
  8022. * // => false
  8023. *
  8024. * // using a customizer callback
  8025. * var el = _.cloneDeep(document.body, function(value) {
  8026. * if (_.isElement(value)) {
  8027. * return value.cloneNode(true);
  8028. * }
  8029. * });
  8030. *
  8031. * el === document.body
  8032. * // => false
  8033. * el.nodeName
  8034. * // => BODY
  8035. * el.childNodes.length;
  8036. * // => 20
  8037. */
  8038. function cloneDeep(value, customizer, thisArg) {
  8039. return typeof customizer == 'function'
  8040. ? baseClone(value, true, bindCallback(customizer, thisArg, 3))
  8041. : baseClone(value, true);
  8042. }
  8043. /**
  8044. * Checks if `value` is greater than `other`.
  8045. *
  8046. * @static
  8047. * @memberOf _
  8048. * @category Lang
  8049. * @param {*} value The value to compare.
  8050. * @param {*} other The other value to compare.
  8051. * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
  8052. * @example
  8053. *
  8054. * _.gt(3, 1);
  8055. * // => true
  8056. *
  8057. * _.gt(3, 3);
  8058. * // => false
  8059. *
  8060. * _.gt(1, 3);
  8061. * // => false
  8062. */
  8063. function gt(value, other) {
  8064. return value > other;
  8065. }
  8066. /**
  8067. * Checks if `value` is greater than or equal to `other`.
  8068. *
  8069. * @static
  8070. * @memberOf _
  8071. * @category Lang
  8072. * @param {*} value The value to compare.
  8073. * @param {*} other The other value to compare.
  8074. * @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`.
  8075. * @example
  8076. *
  8077. * _.gte(3, 1);
  8078. * // => true
  8079. *
  8080. * _.gte(3, 3);
  8081. * // => true
  8082. *
  8083. * _.gte(1, 3);
  8084. * // => false
  8085. */
  8086. function gte(value, other) {
  8087. return value >= other;
  8088. }
  8089. /**
  8090. * Checks if `value` is classified as an `arguments` object.
  8091. *
  8092. * @static
  8093. * @memberOf _
  8094. * @category Lang
  8095. * @param {*} value The value to check.
  8096. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8097. * @example
  8098. *
  8099. * _.isArguments(function() { return arguments; }());
  8100. * // => true
  8101. *
  8102. * _.isArguments([1, 2, 3]);
  8103. * // => false
  8104. */
  8105. function isArguments(value) {
  8106. return isObjectLike(value) && isArrayLike(value) &&
  8107. hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
  8108. }
  8109. /**
  8110. * Checks if `value` is classified as an `Array` object.
  8111. *
  8112. * @static
  8113. * @memberOf _
  8114. * @category Lang
  8115. * @param {*} value The value to check.
  8116. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8117. * @example
  8118. *
  8119. * _.isArray([1, 2, 3]);
  8120. * // => true
  8121. *
  8122. * _.isArray(function() { return arguments; }());
  8123. * // => false
  8124. */
  8125. var isArray = nativeIsArray || function(value) {
  8126. return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
  8127. };
  8128. /**
  8129. * Checks if `value` is classified as a boolean primitive or object.
  8130. *
  8131. * @static
  8132. * @memberOf _
  8133. * @category Lang
  8134. * @param {*} value The value to check.
  8135. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8136. * @example
  8137. *
  8138. * _.isBoolean(false);
  8139. * // => true
  8140. *
  8141. * _.isBoolean(null);
  8142. * // => false
  8143. */
  8144. function isBoolean(value) {
  8145. return value === true || value === false || (isObjectLike(value) && objToString.call(value) == boolTag);
  8146. }
  8147. /**
  8148. * Checks if `value` is classified as a `Date` object.
  8149. *
  8150. * @static
  8151. * @memberOf _
  8152. * @category Lang
  8153. * @param {*} value The value to check.
  8154. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8155. * @example
  8156. *
  8157. * _.isDate(new Date);
  8158. * // => true
  8159. *
  8160. * _.isDate('Mon April 23 2012');
  8161. * // => false
  8162. */
  8163. function isDate(value) {
  8164. return isObjectLike(value) && objToString.call(value) == dateTag;
  8165. }
  8166. /**
  8167. * Checks if `value` is a DOM element.
  8168. *
  8169. * @static
  8170. * @memberOf _
  8171. * @category Lang
  8172. * @param {*} value The value to check.
  8173. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  8174. * @example
  8175. *
  8176. * _.isElement(document.body);
  8177. * // => true
  8178. *
  8179. * _.isElement('<body>');
  8180. * // => false
  8181. */
  8182. function isElement(value) {
  8183. return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
  8184. }
  8185. /**
  8186. * Checks if `value` is empty. A value is considered empty unless it's an
  8187. * `arguments` object, array, string, or jQuery-like collection with a length
  8188. * greater than `0` or an object with own enumerable properties.
  8189. *
  8190. * @static
  8191. * @memberOf _
  8192. * @category Lang
  8193. * @param {Array|Object|string} value The value to inspect.
  8194. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  8195. * @example
  8196. *
  8197. * _.isEmpty(null);
  8198. * // => true
  8199. *
  8200. * _.isEmpty(true);
  8201. * // => true
  8202. *
  8203. * _.isEmpty(1);
  8204. * // => true
  8205. *
  8206. * _.isEmpty([1, 2, 3]);
  8207. * // => false
  8208. *
  8209. * _.isEmpty({ 'a': 1 });
  8210. * // => false
  8211. */
  8212. function isEmpty(value) {
  8213. if (value == null) {
  8214. return true;
  8215. }
  8216. if (isArrayLike(value) && (isArray(value) || isString(value) || isArguments(value) ||
  8217. (isObjectLike(value) && isFunction(value.splice)))) {
  8218. return !value.length;
  8219. }
  8220. return !keys(value).length;
  8221. }
  8222. /**
  8223. * Performs a deep comparison between two values to determine if they are
  8224. * equivalent. If `customizer` is provided it's invoked to compare values.
  8225. * If `customizer` returns `undefined` comparisons are handled by the method
  8226. * instead. The `customizer` is bound to `thisArg` and invoked with up to
  8227. * three arguments: (value, other [, index|key]).
  8228. *
  8229. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  8230. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  8231. * their own, not inherited, enumerable properties. Functions and DOM nodes
  8232. * are **not** supported. Provide a customizer function to extend support
  8233. * for comparing other values.
  8234. *
  8235. * @static
  8236. * @memberOf _
  8237. * @alias eq
  8238. * @category Lang
  8239. * @param {*} value The value to compare.
  8240. * @param {*} other The other value to compare.
  8241. * @param {Function} [customizer] The function to customize value comparisons.
  8242. * @param {*} [thisArg] The `this` binding of `customizer`.
  8243. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  8244. * @example
  8245. *
  8246. * var object = { 'user': 'fred' };
  8247. * var other = { 'user': 'fred' };
  8248. *
  8249. * object == other;
  8250. * // => false
  8251. *
  8252. * _.isEqual(object, other);
  8253. * // => true
  8254. *
  8255. * // using a customizer callback
  8256. * var array = ['hello', 'goodbye'];
  8257. * var other = ['hi', 'goodbye'];
  8258. *
  8259. * _.isEqual(array, other, function(value, other) {
  8260. * if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
  8261. * return true;
  8262. * }
  8263. * });
  8264. * // => true
  8265. */
  8266. function isEqual(value, other, customizer, thisArg) {
  8267. customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
  8268. var result = customizer ? customizer(value, other) : undefined;
  8269. return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
  8270. }
  8271. /**
  8272. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  8273. * `SyntaxError`, `TypeError`, or `URIError` object.
  8274. *
  8275. * @static
  8276. * @memberOf _
  8277. * @category Lang
  8278. * @param {*} value The value to check.
  8279. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  8280. * @example
  8281. *
  8282. * _.isError(new Error);
  8283. * // => true
  8284. *
  8285. * _.isError(Error);
  8286. * // => false
  8287. */
  8288. function isError(value) {
  8289. return isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag;
  8290. }
  8291. /**
  8292. * Checks if `value` is a finite primitive number.
  8293. *
  8294. * **Note:** This method is based on [`Number.isFinite`](http://ecma-international.org/ecma-262/6.0/#sec-number.isfinite).
  8295. *
  8296. * @static
  8297. * @memberOf _
  8298. * @category Lang
  8299. * @param {*} value The value to check.
  8300. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  8301. * @example
  8302. *
  8303. * _.isFinite(10);
  8304. * // => true
  8305. *
  8306. * _.isFinite('10');
  8307. * // => false
  8308. *
  8309. * _.isFinite(true);
  8310. * // => false
  8311. *
  8312. * _.isFinite(Object(10));
  8313. * // => false
  8314. *
  8315. * _.isFinite(Infinity);
  8316. * // => false
  8317. */
  8318. function isFinite(value) {
  8319. return typeof value == 'number' && nativeIsFinite(value);
  8320. }
  8321. /**
  8322. * Checks if `value` is classified as a `Function` object.
  8323. *
  8324. * @static
  8325. * @memberOf _
  8326. * @category Lang
  8327. * @param {*} value The value to check.
  8328. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8329. * @example
  8330. *
  8331. * _.isFunction(_);
  8332. * // => true
  8333. *
  8334. * _.isFunction(/abc/);
  8335. * // => false
  8336. */
  8337. function isFunction(value) {
  8338. if (!isObject(value)) {
  8339. return false;
  8340. }//--•
  8341. // The use of `Object#toString` avoids issues with the `typeof` operator
  8342. // in older versions of Chrome and Safari which return 'function' for regexes
  8343. // and Safari 8 which returns 'object' for typed array constructors.
  8344. var tag = objToString.call(value);
  8345. // Return true if this looks like a function, an "async function", a "generator", or a "proxy".
  8346. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  8347. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8348. // ^^^^
  8349. // PATCHED FROM https://github.com/lodash/lodash/commit/95bc54a3ddc7a25f5e134f5b376a0d1d96118f49
  8350. // Note that, in Lodash 4, this looks like:
  8351. // ```
  8352. // return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  8353. // ```
  8354. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8355. }
  8356. /**
  8357. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  8358. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  8359. *
  8360. * @static
  8361. * @memberOf _
  8362. * @category Lang
  8363. * @param {*} value The value to check.
  8364. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  8365. * @example
  8366. *
  8367. * _.isObject({});
  8368. * // => true
  8369. *
  8370. * _.isObject([1, 2, 3]);
  8371. * // => true
  8372. *
  8373. * _.isObject(1);
  8374. * // => false
  8375. */
  8376. function isObject(value) {
  8377. // Avoid a V8 JIT bug in Chrome 19-20.
  8378. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  8379. var type = typeof value;
  8380. return !!value && (type == 'object' || type == 'function');
  8381. }
  8382. /**
  8383. * Performs a deep comparison between `object` and `source` to determine if
  8384. * `object` contains equivalent property values. If `customizer` is provided
  8385. * it's invoked to compare values. If `customizer` returns `undefined`
  8386. * comparisons are handled by the method instead. The `customizer` is bound
  8387. * to `thisArg` and invoked with three arguments: (value, other, index|key).
  8388. *
  8389. * **Note:** This method supports comparing properties of arrays, booleans,
  8390. * `Date` objects, numbers, `Object` objects, regexes, and strings. Functions
  8391. * and DOM nodes are **not** supported. Provide a customizer function to extend
  8392. * support for comparing other values.
  8393. *
  8394. * @static
  8395. * @memberOf _
  8396. * @category Lang
  8397. * @param {Object} object The object to inspect.
  8398. * @param {Object} source The object of property values to match.
  8399. * @param {Function} [customizer] The function to customize value comparisons.
  8400. * @param {*} [thisArg] The `this` binding of `customizer`.
  8401. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  8402. * @example
  8403. *
  8404. * var object = { 'user': 'fred', 'age': 40 };
  8405. *
  8406. * _.isMatch(object, { 'age': 40 });
  8407. * // => true
  8408. *
  8409. * _.isMatch(object, { 'age': 36 });
  8410. * // => false
  8411. *
  8412. * // using a customizer callback
  8413. * var object = { 'greeting': 'hello' };
  8414. * var source = { 'greeting': 'hi' };
  8415. *
  8416. * _.isMatch(object, source, function(value, other) {
  8417. * return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
  8418. * });
  8419. * // => true
  8420. */
  8421. function isMatch(object, source, customizer, thisArg) {
  8422. customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
  8423. return baseIsMatch(object, getMatchData(source), customizer);
  8424. }
  8425. /**
  8426. * Checks if `value` is `NaN`.
  8427. *
  8428. * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
  8429. * which returns `true` for `undefined` and other non-numeric values.
  8430. *
  8431. * @static
  8432. * @memberOf _
  8433. * @category Lang
  8434. * @param {*} value The value to check.
  8435. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  8436. * @example
  8437. *
  8438. * _.isNaN(NaN);
  8439. * // => true
  8440. *
  8441. * _.isNaN(new Number(NaN));
  8442. * // => true
  8443. *
  8444. * isNaN(undefined);
  8445. * // => true
  8446. *
  8447. * _.isNaN(undefined);
  8448. * // => false
  8449. */
  8450. function isNaN(value) {
  8451. // An `NaN` primitive is the only value that is not equal to itself.
  8452. // Perform the `toStringTag` check first to avoid errors with some host objects in IE.
  8453. return isNumber(value) && value != +value;
  8454. }
  8455. /**
  8456. * Checks if `value` is a native function.
  8457. *
  8458. * @static
  8459. * @memberOf _
  8460. * @category Lang
  8461. * @param {*} value The value to check.
  8462. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  8463. * @example
  8464. *
  8465. * _.isNative(Array.prototype.push);
  8466. * // => true
  8467. *
  8468. * _.isNative(_);
  8469. * // => false
  8470. */
  8471. function isNative(value) {
  8472. if (value == null) {
  8473. return false;
  8474. }
  8475. if (isFunction(value)) {
  8476. return reIsNative.test(fnToString.call(value));
  8477. }
  8478. return isObjectLike(value) && (isHostObject(value) ? reIsNative : reIsHostCtor).test(value);
  8479. }
  8480. /**
  8481. * Checks if `value` is `null`.
  8482. *
  8483. * @static
  8484. * @memberOf _
  8485. * @category Lang
  8486. * @param {*} value The value to check.
  8487. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  8488. * @example
  8489. *
  8490. * _.isNull(null);
  8491. * // => true
  8492. *
  8493. * _.isNull(void 0);
  8494. * // => false
  8495. */
  8496. function isNull(value) {
  8497. return value === null;
  8498. }
  8499. /**
  8500. * Checks if `value` is classified as a `Number` primitive or object.
  8501. *
  8502. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
  8503. * as numbers, use the `_.isFinite` method.
  8504. *
  8505. * @static
  8506. * @memberOf _
  8507. * @category Lang
  8508. * @param {*} value The value to check.
  8509. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8510. * @example
  8511. *
  8512. * _.isNumber(8.4);
  8513. * // => true
  8514. *
  8515. * _.isNumber(NaN);
  8516. * // => true
  8517. *
  8518. * _.isNumber('8.4');
  8519. * // => false
  8520. */
  8521. function isNumber(value) {
  8522. return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag);
  8523. }
  8524. /**
  8525. * Checks if `value` is a plain object, that is, an object created by the
  8526. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  8527. *
  8528. * **Note:** This method assumes objects created by the `Object` constructor
  8529. * have no inherited enumerable properties.
  8530. *
  8531. * @static
  8532. * @memberOf _
  8533. * @category Lang
  8534. * @param {*} value The value to check.
  8535. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  8536. * @example
  8537. *
  8538. * function Foo() {
  8539. * this.a = 1;
  8540. * }
  8541. *
  8542. * _.isPlainObject(new Foo);
  8543. * // => false
  8544. *
  8545. * _.isPlainObject([1, 2, 3]);
  8546. * // => false
  8547. *
  8548. * _.isPlainObject({ 'x': 0, 'y': 0 });
  8549. * // => true
  8550. *
  8551. * _.isPlainObject(Object.create(null));
  8552. * // => true
  8553. */
  8554. function isPlainObject(value) {
  8555. var Ctor;
  8556. // Exit early for non `Object` objects.
  8557. if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isHostObject(value) && !isArguments(value)) ||
  8558. (!hasOwnProperty.call(value, 'constructor') && (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
  8559. return false;
  8560. }
  8561. // IE < 9 iterates inherited properties before own properties. If the first
  8562. // iterated property is an object's own property then there are no inherited
  8563. // enumerable properties.
  8564. var result;
  8565. if (lodash.support.ownLast) {
  8566. baseForIn(value, function(subValue, key, object) {
  8567. result = hasOwnProperty.call(object, key);
  8568. return false;
  8569. });
  8570. return result !== false;
  8571. }
  8572. // In most environments an object's own properties are iterated before
  8573. // its inherited properties. If the last iterated property is an object's
  8574. // own property then there are no inherited enumerable properties.
  8575. baseForIn(value, function(subValue, key) {
  8576. result = key;
  8577. });
  8578. return result === undefined || hasOwnProperty.call(value, result);
  8579. }
  8580. /**
  8581. * Checks if `value` is classified as a `RegExp` object.
  8582. *
  8583. * @static
  8584. * @memberOf _
  8585. * @category Lang
  8586. * @param {*} value The value to check.
  8587. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8588. * @example
  8589. *
  8590. * _.isRegExp(/abc/);
  8591. * // => true
  8592. *
  8593. * _.isRegExp('/abc/');
  8594. * // => false
  8595. */
  8596. function isRegExp(value) {
  8597. return isObject(value) && objToString.call(value) == regexpTag;
  8598. }
  8599. /**
  8600. * Checks if `value` is classified as a `String` primitive or object.
  8601. *
  8602. * @static
  8603. * @memberOf _
  8604. * @category Lang
  8605. * @param {*} value The value to check.
  8606. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8607. * @example
  8608. *
  8609. * _.isString('abc');
  8610. * // => true
  8611. *
  8612. * _.isString(1);
  8613. * // => false
  8614. */
  8615. function isString(value) {
  8616. return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag);
  8617. }
  8618. /**
  8619. * Checks if `value` is classified as a typed array.
  8620. *
  8621. * @static
  8622. * @memberOf _
  8623. * @category Lang
  8624. * @param {*} value The value to check.
  8625. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8626. * @example
  8627. *
  8628. * _.isTypedArray(new Uint8Array);
  8629. * // => true
  8630. *
  8631. * _.isTypedArray([]);
  8632. * // => false
  8633. */
  8634. function isTypedArray(value) {
  8635. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
  8636. }
  8637. /**
  8638. * Checks if `value` is `undefined`.
  8639. *
  8640. * @static
  8641. * @memberOf _
  8642. * @category Lang
  8643. * @param {*} value The value to check.
  8644. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  8645. * @example
  8646. *
  8647. * _.isUndefined(void 0);
  8648. * // => true
  8649. *
  8650. * _.isUndefined(null);
  8651. * // => false
  8652. */
  8653. function isUndefined(value) {
  8654. return value === undefined;
  8655. }
  8656. /**
  8657. * Checks if `value` is less than `other`.
  8658. *
  8659. * @static
  8660. * @memberOf _
  8661. * @category Lang
  8662. * @param {*} value The value to compare.
  8663. * @param {*} other The other value to compare.
  8664. * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
  8665. * @example
  8666. *
  8667. * _.lt(1, 3);
  8668. * // => true
  8669. *
  8670. * _.lt(3, 3);
  8671. * // => false
  8672. *
  8673. * _.lt(3, 1);
  8674. * // => false
  8675. */
  8676. function lt(value, other) {
  8677. return value < other;
  8678. }
  8679. /**
  8680. * Checks if `value` is less than or equal to `other`.
  8681. *
  8682. * @static
  8683. * @memberOf _
  8684. * @category Lang
  8685. * @param {*} value The value to compare.
  8686. * @param {*} other The other value to compare.
  8687. * @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`.
  8688. * @example
  8689. *
  8690. * _.lte(1, 3);
  8691. * // => true
  8692. *
  8693. * _.lte(3, 3);
  8694. * // => true
  8695. *
  8696. * _.lte(3, 1);
  8697. * // => false
  8698. */
  8699. function lte(value, other) {
  8700. return value <= other;
  8701. }
  8702. /**
  8703. * Converts `value` to an array.
  8704. *
  8705. * @static
  8706. * @memberOf _
  8707. * @category Lang
  8708. * @param {*} value The value to convert.
  8709. * @returns {Array} Returns the converted array.
  8710. * @example
  8711. *
  8712. * (function() {
  8713. * return _.toArray(arguments).slice(1);
  8714. * }(1, 2, 3));
  8715. * // => [2, 3]
  8716. */
  8717. function toArray(value) {
  8718. var length = value ? getLength(value) : 0;
  8719. if (!isLength(length)) {
  8720. return values(value);
  8721. }
  8722. if (!length) {
  8723. return [];
  8724. }
  8725. return (lodash.support.unindexedChars && isString(value))
  8726. ? value.split('')
  8727. : arrayCopy(value);
  8728. }
  8729. /**
  8730. * Converts `value` to a plain object flattening inherited enumerable
  8731. * properties of `value` to own properties of the plain object.
  8732. *
  8733. * @static
  8734. * @memberOf _
  8735. * @category Lang
  8736. * @param {*} value The value to convert.
  8737. * @returns {Object} Returns the converted plain object.
  8738. * @example
  8739. *
  8740. * function Foo() {
  8741. * this.b = 2;
  8742. * }
  8743. *
  8744. * Foo.prototype.c = 3;
  8745. *
  8746. * _.assign({ 'a': 1 }, new Foo);
  8747. * // => { 'a': 1, 'b': 2 }
  8748. *
  8749. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  8750. * // => { 'a': 1, 'b': 2, 'c': 3 }
  8751. */
  8752. function toPlainObject(value) {
  8753. return baseCopy(value, keysIn(value));
  8754. }
  8755. /*------------------------------------------------------------------------*/
  8756. /**
  8757. * Recursively merges own enumerable properties of the source object(s), that
  8758. * don't resolve to `undefined` into the destination object. Subsequent sources
  8759. * overwrite property assignments of previous sources. If `customizer` is
  8760. * provided it's invoked to produce the merged values of the destination and
  8761. * source properties. If `customizer` returns `undefined` merging is handled
  8762. * by the method instead. The `customizer` is bound to `thisArg` and invoked
  8763. * with five arguments: (objectValue, sourceValue, key, object, source).
  8764. *
  8765. * @static
  8766. * @memberOf _
  8767. * @category Object
  8768. * @param {Object} object The destination object.
  8769. * @param {...Object} [sources] The source objects.
  8770. * @param {Function} [customizer] The function to customize assigned values.
  8771. * @param {*} [thisArg] The `this` binding of `customizer`.
  8772. * @returns {Object} Returns `object`.
  8773. * @example
  8774. *
  8775. * var users = {
  8776. * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
  8777. * };
  8778. *
  8779. * var ages = {
  8780. * 'data': [{ 'age': 36 }, { 'age': 40 }]
  8781. * };
  8782. *
  8783. * _.merge(users, ages);
  8784. * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
  8785. *
  8786. * // using a customizer callback
  8787. * var object = {
  8788. * 'fruits': ['apple'],
  8789. * 'vegetables': ['beet']
  8790. * };
  8791. *
  8792. * var other = {
  8793. * 'fruits': ['banana'],
  8794. * 'vegetables': ['carrot']
  8795. * };
  8796. *
  8797. * _.merge(object, other, function(a, b) {
  8798. * if (_.isArray(a)) {
  8799. * return a.concat(b);
  8800. * }
  8801. * });
  8802. * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
  8803. */
  8804. var merge = createAssigner(baseMerge);
  8805. /**
  8806. * Assigns own enumerable properties of source object(s) to the destination
  8807. * object. Subsequent sources overwrite property assignments of previous sources.
  8808. * If `customizer` is provided it's invoked to produce the assigned values.
  8809. * The `customizer` is bound to `thisArg` and invoked with five arguments:
  8810. * (objectValue, sourceValue, key, object, source).
  8811. *
  8812. * **Note:** This method mutates `object` and is based on
  8813. * [`Object.assign`](http://ecma-international.org/ecma-262/6.0/#sec-object.assign).
  8814. *
  8815. * @static
  8816. * @memberOf _
  8817. * @alias extend
  8818. * @category Object
  8819. * @param {Object} object The destination object.
  8820. * @param {...Object} [sources] The source objects.
  8821. * @param {Function} [customizer] The function to customize assigned values.
  8822. * @param {*} [thisArg] The `this` binding of `customizer`.
  8823. * @returns {Object} Returns `object`.
  8824. * @example
  8825. *
  8826. * _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
  8827. * // => { 'user': 'fred', 'age': 40 }
  8828. *
  8829. * // using a customizer callback
  8830. * var defaults = _.partialRight(_.assign, function(value, other) {
  8831. * return _.isUndefined(value) ? other : value;
  8832. * });
  8833. *
  8834. * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
  8835. * // => { 'user': 'barney', 'age': 36 }
  8836. */
  8837. var assign = createAssigner(function(object, source, customizer) {
  8838. return customizer
  8839. ? assignWith(object, source, customizer)
  8840. : baseAssign(object, source);
  8841. });
  8842. /**
  8843. * Creates an object that inherits from the given `prototype` object. If a
  8844. * `properties` object is provided its own enumerable properties are assigned
  8845. * to the created object.
  8846. *
  8847. * @static
  8848. * @memberOf _
  8849. * @category Object
  8850. * @param {Object} prototype The object to inherit from.
  8851. * @param {Object} [properties] The properties to assign to the object.
  8852. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  8853. * @returns {Object} Returns the new object.
  8854. * @example
  8855. *
  8856. * function Shape() {
  8857. * this.x = 0;
  8858. * this.y = 0;
  8859. * }
  8860. *
  8861. * function Circle() {
  8862. * Shape.call(this);
  8863. * }
  8864. *
  8865. * Circle.prototype = _.create(Shape.prototype, {
  8866. * 'constructor': Circle
  8867. * });
  8868. *
  8869. * var circle = new Circle;
  8870. * circle instanceof Circle;
  8871. * // => true
  8872. *
  8873. * circle instanceof Shape;
  8874. * // => true
  8875. */
  8876. function create(prototype, properties, guard) {
  8877. var result = baseCreate(prototype);
  8878. if (guard && isIterateeCall(prototype, properties, guard)) {
  8879. properties = undefined;
  8880. }
  8881. return properties ? baseAssign(result, properties) : result;
  8882. }
  8883. /**
  8884. * Assigns own enumerable properties of source object(s) to the destination
  8885. * object for all destination properties that resolve to `undefined`. Once a
  8886. * property is set, additional values of the same property are ignored.
  8887. *
  8888. * **Note:** This method mutates `object`.
  8889. *
  8890. * @static
  8891. * @memberOf _
  8892. * @category Object
  8893. * @param {Object} object The destination object.
  8894. * @param {...Object} [sources] The source objects.
  8895. * @returns {Object} Returns `object`.
  8896. * @example
  8897. *
  8898. * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
  8899. * // => { 'user': 'barney', 'age': 36 }
  8900. */
  8901. var defaults = createDefaults(assign, assignDefaults);
  8902. /**
  8903. * This method is like `_.defaults` except that it recursively assigns
  8904. * default properties.
  8905. *
  8906. * **Note:** This method mutates `object`.
  8907. *
  8908. * @static
  8909. * @memberOf _
  8910. * @category Object
  8911. * @param {Object} object The destination object.
  8912. * @param {...Object} [sources] The source objects.
  8913. * @returns {Object} Returns `object`.
  8914. * @example
  8915. *
  8916. * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
  8917. * // => { 'user': { 'name': 'barney', 'age': 36 } }
  8918. *
  8919. */
  8920. var defaultsDeep = createDefaults(merge, mergeDefaults);
  8921. /**
  8922. * This method is like `_.find` except that it returns the key of the first
  8923. * element `predicate` returns truthy for instead of the element itself.
  8924. *
  8925. * If a property name is provided for `predicate` the created `_.property`
  8926. * style callback returns the property value of the given element.
  8927. *
  8928. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  8929. * style callback returns `true` for elements that have a matching property
  8930. * value, else `false`.
  8931. *
  8932. * If an object is provided for `predicate` the created `_.matches` style
  8933. * callback returns `true` for elements that have the properties of the given
  8934. * object, else `false`.
  8935. *
  8936. * @static
  8937. * @memberOf _
  8938. * @category Object
  8939. * @param {Object} object The object to search.
  8940. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  8941. * per iteration.
  8942. * @param {*} [thisArg] The `this` binding of `predicate`.
  8943. * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
  8944. * @example
  8945. *
  8946. * var users = {
  8947. * 'barney': { 'age': 36, 'active': true },
  8948. * 'fred': { 'age': 40, 'active': false },
  8949. * 'pebbles': { 'age': 1, 'active': true }
  8950. * };
  8951. *
  8952. * _.findKey(users, function(chr) {
  8953. * return chr.age < 40;
  8954. * });
  8955. * // => 'barney' (iteration order is not guaranteed)
  8956. *
  8957. * // using the `_.matches` callback shorthand
  8958. * _.findKey(users, { 'age': 1, 'active': true });
  8959. * // => 'pebbles'
  8960. *
  8961. * // using the `_.matchesProperty` callback shorthand
  8962. * _.findKey(users, 'active', false);
  8963. * // => 'fred'
  8964. *
  8965. * // using the `_.property` callback shorthand
  8966. * _.findKey(users, 'active');
  8967. * // => 'barney'
  8968. */
  8969. var findKey = createFindKey(baseForOwn);
  8970. /**
  8971. * This method is like `_.findKey` except that it iterates over elements of
  8972. * a collection in the opposite order.
  8973. *
  8974. * If a property name is provided for `predicate` the created `_.property`
  8975. * style callback returns the property value of the given element.
  8976. *
  8977. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  8978. * style callback returns `true` for elements that have a matching property
  8979. * value, else `false`.
  8980. *
  8981. * If an object is provided for `predicate` the created `_.matches` style
  8982. * callback returns `true` for elements that have the properties of the given
  8983. * object, else `false`.
  8984. *
  8985. * @static
  8986. * @memberOf _
  8987. * @category Object
  8988. * @param {Object} object The object to search.
  8989. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  8990. * per iteration.
  8991. * @param {*} [thisArg] The `this` binding of `predicate`.
  8992. * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
  8993. * @example
  8994. *
  8995. * var users = {
  8996. * 'barney': { 'age': 36, 'active': true },
  8997. * 'fred': { 'age': 40, 'active': false },
  8998. * 'pebbles': { 'age': 1, 'active': true }
  8999. * };
  9000. *
  9001. * _.findLastKey(users, function(chr) {
  9002. * return chr.age < 40;
  9003. * });
  9004. * // => returns `pebbles` assuming `_.findKey` returns `barney`
  9005. *
  9006. * // using the `_.matches` callback shorthand
  9007. * _.findLastKey(users, { 'age': 36, 'active': true });
  9008. * // => 'barney'
  9009. *
  9010. * // using the `_.matchesProperty` callback shorthand
  9011. * _.findLastKey(users, 'active', false);
  9012. * // => 'fred'
  9013. *
  9014. * // using the `_.property` callback shorthand
  9015. * _.findLastKey(users, 'active');
  9016. * // => 'pebbles'
  9017. */
  9018. var findLastKey = createFindKey(baseForOwnRight);
  9019. /**
  9020. * Iterates over own and inherited enumerable properties of an object invoking
  9021. * `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
  9022. * with three arguments: (value, key, object). Iteratee functions may exit
  9023. * iteration early by explicitly returning `false`.
  9024. *
  9025. * @static
  9026. * @memberOf _
  9027. * @category Object
  9028. * @param {Object} object The object to iterate over.
  9029. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9030. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9031. * @returns {Object} Returns `object`.
  9032. * @example
  9033. *
  9034. * function Foo() {
  9035. * this.a = 1;
  9036. * this.b = 2;
  9037. * }
  9038. *
  9039. * Foo.prototype.c = 3;
  9040. *
  9041. * _.forIn(new Foo, function(value, key) {
  9042. * console.log(key);
  9043. * });
  9044. * // => logs 'a', 'b', and 'c' (iteration order is not guaranteed)
  9045. */
  9046. var forIn = createForIn(baseFor);
  9047. /**
  9048. * This method is like `_.forIn` except that it iterates over properties of
  9049. * `object` in the opposite order.
  9050. *
  9051. * @static
  9052. * @memberOf _
  9053. * @category Object
  9054. * @param {Object} object The object to iterate over.
  9055. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9056. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9057. * @returns {Object} Returns `object`.
  9058. * @example
  9059. *
  9060. * function Foo() {
  9061. * this.a = 1;
  9062. * this.b = 2;
  9063. * }
  9064. *
  9065. * Foo.prototype.c = 3;
  9066. *
  9067. * _.forInRight(new Foo, function(value, key) {
  9068. * console.log(key);
  9069. * });
  9070. * // => logs 'c', 'b', and 'a' assuming `_.forIn ` logs 'a', 'b', and 'c'
  9071. */
  9072. var forInRight = createForIn(baseForRight);
  9073. /**
  9074. * Iterates over own enumerable properties of an object invoking `iteratee`
  9075. * for each property. The `iteratee` is bound to `thisArg` and invoked with
  9076. * three arguments: (value, key, object). Iteratee functions may exit iteration
  9077. * early by explicitly returning `false`.
  9078. *
  9079. * @static
  9080. * @memberOf _
  9081. * @category Object
  9082. * @param {Object} object The object to iterate over.
  9083. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9084. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9085. * @returns {Object} Returns `object`.
  9086. * @example
  9087. *
  9088. * function Foo() {
  9089. * this.a = 1;
  9090. * this.b = 2;
  9091. * }
  9092. *
  9093. * Foo.prototype.c = 3;
  9094. *
  9095. * _.forOwn(new Foo, function(value, key) {
  9096. * console.log(key);
  9097. * });
  9098. * // => logs 'a' and 'b' (iteration order is not guaranteed)
  9099. */
  9100. var forOwn = createForOwn(baseForOwn);
  9101. /**
  9102. * This method is like `_.forOwn` except that it iterates over properties of
  9103. * `object` in the opposite order.
  9104. *
  9105. * @static
  9106. * @memberOf _
  9107. * @category Object
  9108. * @param {Object} object The object to iterate over.
  9109. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9110. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9111. * @returns {Object} Returns `object`.
  9112. * @example
  9113. *
  9114. * function Foo() {
  9115. * this.a = 1;
  9116. * this.b = 2;
  9117. * }
  9118. *
  9119. * Foo.prototype.c = 3;
  9120. *
  9121. * _.forOwnRight(new Foo, function(value, key) {
  9122. * console.log(key);
  9123. * });
  9124. * // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
  9125. */
  9126. var forOwnRight = createForOwn(baseForOwnRight);
  9127. /**
  9128. * Creates an array of function property names from all enumerable properties,
  9129. * own and inherited, of `object`.
  9130. *
  9131. * @static
  9132. * @memberOf _
  9133. * @alias methods
  9134. * @category Object
  9135. * @param {Object} object The object to inspect.
  9136. * @returns {Array} Returns the new array of property names.
  9137. * @example
  9138. *
  9139. * _.functions(_);
  9140. * // => ['after', 'ary', 'assign', ...]
  9141. */
  9142. function functions(object) {
  9143. return baseFunctions(object, keysIn(object));
  9144. }
  9145. /**
  9146. * Gets the property value at `path` of `object`. If the resolved value is
  9147. * `undefined` the `defaultValue` is used in its place.
  9148. *
  9149. * @static
  9150. * @memberOf _
  9151. * @category Object
  9152. * @param {Object} object The object to query.
  9153. * @param {Array|string} path The path of the property to get.
  9154. * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
  9155. * @returns {*} Returns the resolved value.
  9156. * @example
  9157. *
  9158. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  9159. *
  9160. * _.get(object, 'a[0].b.c');
  9161. * // => 3
  9162. *
  9163. * _.get(object, ['a', '0', 'b', 'c']);
  9164. * // => 3
  9165. *
  9166. * _.get(object, 'a.b.c', 'default');
  9167. * // => 'default'
  9168. */
  9169. function get(object, path, defaultValue) {
  9170. var result = object == null ? undefined : baseGet(object, toPath(path), (path + ''));
  9171. return result === undefined ? defaultValue : result;
  9172. }
  9173. /**
  9174. * Checks if `path` is a direct property.
  9175. *
  9176. * @static
  9177. * @memberOf _
  9178. * @category Object
  9179. * @param {Object} object The object to query.
  9180. * @param {Array|string} path The path to check.
  9181. * @returns {boolean} Returns `true` if `path` is a direct property, else `false`.
  9182. * @example
  9183. *
  9184. * var object = { 'a': { 'b': { 'c': 3 } } };
  9185. *
  9186. * _.has(object, 'a');
  9187. * // => true
  9188. *
  9189. * _.has(object, 'a.b.c');
  9190. * // => true
  9191. *
  9192. * _.has(object, ['a', 'b', 'c']);
  9193. * // => true
  9194. */
  9195. function has(object, path) {
  9196. if (object == null) {
  9197. return false;
  9198. }
  9199. var result = hasOwnProperty.call(object, path);
  9200. if (!result && !isKey(path)) {
  9201. path = toPath(path);
  9202. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  9203. if (object == null) {
  9204. return false;
  9205. }
  9206. path = last(path);
  9207. result = hasOwnProperty.call(object, path);
  9208. }
  9209. return result || (isLength(object.length) && isIndex(path, object.length) &&
  9210. (isArray(object) || isArguments(object) || isString(object)));
  9211. }
  9212. /**
  9213. * Creates an object composed of the inverted keys and values of `object`.
  9214. * If `object` contains duplicate values, subsequent values overwrite property
  9215. * assignments of previous values unless `multiValue` is `true`.
  9216. *
  9217. * @static
  9218. * @memberOf _
  9219. * @category Object
  9220. * @param {Object} object The object to invert.
  9221. * @param {boolean} [multiValue] Allow multiple values per key.
  9222. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  9223. * @returns {Object} Returns the new inverted object.
  9224. * @example
  9225. *
  9226. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  9227. *
  9228. * _.invert(object);
  9229. * // => { '1': 'c', '2': 'b' }
  9230. *
  9231. * // with `multiValue`
  9232. * _.invert(object, true);
  9233. * // => { '1': ['a', 'c'], '2': ['b'] }
  9234. */
  9235. function invert(object, multiValue, guard) {
  9236. if (guard && isIterateeCall(object, multiValue, guard)) {
  9237. multiValue = undefined;
  9238. }
  9239. var index = -1,
  9240. props = keys(object),
  9241. length = props.length,
  9242. result = {};
  9243. while (++index < length) {
  9244. var key = props[index],
  9245. value = object[key];
  9246. if (multiValue) {
  9247. if (hasOwnProperty.call(result, value)) {
  9248. result[value].push(key);
  9249. } else {
  9250. result[value] = [key];
  9251. }
  9252. }
  9253. else {
  9254. result[value] = key;
  9255. }
  9256. }
  9257. return result;
  9258. }
  9259. /**
  9260. * Creates an array of the own enumerable property names of `object`.
  9261. *
  9262. * **Note:** Non-object values are coerced to objects. See the
  9263. * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
  9264. * for more details.
  9265. *
  9266. * @static
  9267. * @memberOf _
  9268. * @category Object
  9269. * @param {Object} object The object to query.
  9270. * @returns {Array} Returns the array of property names.
  9271. * @example
  9272. *
  9273. * function Foo() {
  9274. * this.a = 1;
  9275. * this.b = 2;
  9276. * }
  9277. *
  9278. * Foo.prototype.c = 3;
  9279. *
  9280. * _.keys(new Foo);
  9281. * // => ['a', 'b'] (iteration order is not guaranteed)
  9282. *
  9283. * _.keys('hi');
  9284. * // => ['0', '1']
  9285. */
  9286. var keys = !nativeKeys ? shimKeys : function(object) {
  9287. var Ctor = object == null ? undefined : object.constructor;
  9288. if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
  9289. (typeof object == 'function' ? lodash.support.enumPrototypes : isArrayLike(object))) {
  9290. return shimKeys(object);
  9291. }
  9292. return isObject(object) ? nativeKeys(object) : [];
  9293. };
  9294. /**
  9295. * Creates an array of the own and inherited enumerable property names of `object`.
  9296. *
  9297. * **Note:** Non-object values are coerced to objects.
  9298. *
  9299. * @static
  9300. * @memberOf _
  9301. * @category Object
  9302. * @param {Object} object The object to query.
  9303. * @returns {Array} Returns the array of property names.
  9304. * @example
  9305. *
  9306. * function Foo() {
  9307. * this.a = 1;
  9308. * this.b = 2;
  9309. * }
  9310. *
  9311. * Foo.prototype.c = 3;
  9312. *
  9313. * _.keysIn(new Foo);
  9314. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  9315. */
  9316. function keysIn(object) {
  9317. if (object == null) {
  9318. return [];
  9319. }
  9320. if (!isObject(object)) {
  9321. object = Object(object);
  9322. }
  9323. var length = object.length,
  9324. support = lodash.support;
  9325. length = (length && isLength(length) &&
  9326. (isArray(object) || isArguments(object) || isString(object)) && length) || 0;
  9327. var Ctor = object.constructor,
  9328. index = -1,
  9329. proto = (isFunction(Ctor) && Ctor.prototype) || objectProto,
  9330. isProto = proto === object,
  9331. result = Array(length),
  9332. skipIndexes = length > 0,
  9333. skipErrorProps = support.enumErrorProps && (object === errorProto || object instanceof Error),
  9334. skipProto = support.enumPrototypes && isFunction(object);
  9335. while (++index < length) {
  9336. result[index] = (index + '');
  9337. }
  9338. // lodash skips the `constructor` property when it infers it's iterating
  9339. // over a `prototype` object because IE < 9 can't set the `[[Enumerable]]`
  9340. // attribute of an existing property and the `constructor` property of a
  9341. // prototype defaults to non-enumerable.
  9342. for (var key in object) {
  9343. if (!(skipProto && key == 'prototype') &&
  9344. !(skipErrorProps && (key == 'message' || key == 'name')) &&
  9345. !(skipIndexes && isIndex(key, length)) &&
  9346. !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  9347. result.push(key);
  9348. }
  9349. }
  9350. if (support.nonEnumShadows && object !== objectProto) {
  9351. var tag = object === stringProto ? stringTag : (object === errorProto ? errorTag : objToString.call(object)),
  9352. nonEnums = nonEnumProps[tag] || nonEnumProps[objectTag];
  9353. if (tag == objectTag) {
  9354. proto = objectProto;
  9355. }
  9356. length = shadowProps.length;
  9357. while (length--) {
  9358. key = shadowProps[length];
  9359. var nonEnum = nonEnums[key];
  9360. if (!(isProto && nonEnum) &&
  9361. (nonEnum ? hasOwnProperty.call(object, key) : object[key] !== proto[key])) {
  9362. result.push(key);
  9363. }
  9364. }
  9365. }
  9366. return result;
  9367. }
  9368. /**
  9369. * The opposite of `_.mapValues`; this method creates an object with the
  9370. * same values as `object` and keys generated by running each own enumerable
  9371. * property of `object` through `iteratee`.
  9372. *
  9373. * @static
  9374. * @memberOf _
  9375. * @category Object
  9376. * @param {Object} object The object to iterate over.
  9377. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  9378. * per iteration.
  9379. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9380. * @returns {Object} Returns the new mapped object.
  9381. * @example
  9382. *
  9383. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  9384. * return key + value;
  9385. * });
  9386. * // => { 'a1': 1, 'b2': 2 }
  9387. */
  9388. var mapKeys = createObjectMapper(true);
  9389. /**
  9390. * Creates an object with the same keys as `object` and values generated by
  9391. * running each own enumerable property of `object` through `iteratee`. The
  9392. * iteratee function is bound to `thisArg` and invoked with three arguments:
  9393. * (value, key, object).
  9394. *
  9395. * If a property name is provided for `iteratee` the created `_.property`
  9396. * style callback returns the property value of the given element.
  9397. *
  9398. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  9399. * style callback returns `true` for elements that have a matching property
  9400. * value, else `false`.
  9401. *
  9402. * If an object is provided for `iteratee` the created `_.matches` style
  9403. * callback returns `true` for elements that have the properties of the given
  9404. * object, else `false`.
  9405. *
  9406. * @static
  9407. * @memberOf _
  9408. * @category Object
  9409. * @param {Object} object The object to iterate over.
  9410. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  9411. * per iteration.
  9412. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9413. * @returns {Object} Returns the new mapped object.
  9414. * @example
  9415. *
  9416. * _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
  9417. * return n * 3;
  9418. * });
  9419. * // => { 'a': 3, 'b': 6 }
  9420. *
  9421. * var users = {
  9422. * 'fred': { 'user': 'fred', 'age': 40 },
  9423. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  9424. * };
  9425. *
  9426. * // using the `_.property` callback shorthand
  9427. * _.mapValues(users, 'age');
  9428. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  9429. */
  9430. var mapValues = createObjectMapper();
  9431. /**
  9432. * The opposite of `_.pick`; this method creates an object composed of the
  9433. * own and inherited enumerable properties of `object` that are not omitted.
  9434. *
  9435. * @static
  9436. * @memberOf _
  9437. * @category Object
  9438. * @param {Object} object The source object.
  9439. * @param {Function|...(string|string[])} [predicate] The function invoked per
  9440. * iteration or property names to omit, specified as individual property
  9441. * names or arrays of property names.
  9442. * @param {*} [thisArg] The `this` binding of `predicate`.
  9443. * @returns {Object} Returns the new object.
  9444. * @example
  9445. *
  9446. * var object = { 'user': 'fred', 'age': 40 };
  9447. *
  9448. * _.omit(object, 'age');
  9449. * // => { 'user': 'fred' }
  9450. *
  9451. * _.omit(object, _.isNumber);
  9452. * // => { 'user': 'fred' }
  9453. */
  9454. var omit = restParam(function(object, props) {
  9455. if (object == null) {
  9456. return {};
  9457. }
  9458. if (typeof props[0] != 'function') {
  9459. var props = arrayMap(baseFlatten(props), String);
  9460. return pickByArray(object, baseDifference(keysIn(object), props));
  9461. }
  9462. var predicate = bindCallback(props[0], props[1], 3);
  9463. return pickByCallback(object, function(value, key, object) {
  9464. return !predicate(value, key, object);
  9465. });
  9466. });
  9467. /**
  9468. * Creates a two dimensional array of the key-value pairs for `object`,
  9469. * e.g. `[[key1, value1], [key2, value2]]`.
  9470. *
  9471. * @static
  9472. * @memberOf _
  9473. * @category Object
  9474. * @param {Object} object The object to query.
  9475. * @returns {Array} Returns the new array of key-value pairs.
  9476. * @example
  9477. *
  9478. * _.pairs({ 'barney': 36, 'fred': 40 });
  9479. * // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
  9480. */
  9481. function pairs(object) {
  9482. object = toObject(object);
  9483. var index = -1,
  9484. props = keys(object),
  9485. length = props.length,
  9486. result = Array(length);
  9487. while (++index < length) {
  9488. var key = props[index];
  9489. result[index] = [key, object[key]];
  9490. }
  9491. return result;
  9492. }
  9493. /**
  9494. * Creates an object composed of the picked `object` properties. Property
  9495. * names may be specified as individual arguments or as arrays of property
  9496. * names. If `predicate` is provided it's invoked for each property of `object`
  9497. * picking the properties `predicate` returns truthy for. The predicate is
  9498. * bound to `thisArg` and invoked with three arguments: (value, key, object).
  9499. *
  9500. * @static
  9501. * @memberOf _
  9502. * @category Object
  9503. * @param {Object} object The source object.
  9504. * @param {Function|...(string|string[])} [predicate] The function invoked per
  9505. * iteration or property names to pick, specified as individual property
  9506. * names or arrays of property names.
  9507. * @param {*} [thisArg] The `this` binding of `predicate`.
  9508. * @returns {Object} Returns the new object.
  9509. * @example
  9510. *
  9511. * var object = { 'user': 'fred', 'age': 40 };
  9512. *
  9513. * _.pick(object, 'user');
  9514. * // => { 'user': 'fred' }
  9515. *
  9516. * _.pick(object, _.isString);
  9517. * // => { 'user': 'fred' }
  9518. */
  9519. var pick = restParam(function(object, props) {
  9520. if (object == null) {
  9521. return {};
  9522. }
  9523. return typeof props[0] == 'function'
  9524. ? pickByCallback(object, bindCallback(props[0], props[1], 3))
  9525. : pickByArray(object, baseFlatten(props));
  9526. });
  9527. /**
  9528. * This method is like `_.get` except that if the resolved value is a function
  9529. * it's invoked with the `this` binding of its parent object and its result
  9530. * is returned.
  9531. *
  9532. * @static
  9533. * @memberOf _
  9534. * @category Object
  9535. * @param {Object} object The object to query.
  9536. * @param {Array|string} path The path of the property to resolve.
  9537. * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
  9538. * @returns {*} Returns the resolved value.
  9539. * @example
  9540. *
  9541. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  9542. *
  9543. * _.result(object, 'a[0].b.c1');
  9544. * // => 3
  9545. *
  9546. * _.result(object, 'a[0].b.c2');
  9547. * // => 4
  9548. *
  9549. * _.result(object, 'a.b.c', 'default');
  9550. * // => 'default'
  9551. *
  9552. * _.result(object, 'a.b.c', _.constant('default'));
  9553. * // => 'default'
  9554. */
  9555. function result(object, path, defaultValue) {
  9556. var result = object == null ? undefined : toObject(object)[path];
  9557. if (result === undefined) {
  9558. if (object != null && !isKey(path, object)) {
  9559. path = toPath(path);
  9560. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  9561. result = object == null ? undefined : toObject(object)[last(path)];
  9562. }
  9563. result = result === undefined ? defaultValue : result;
  9564. }
  9565. return isFunction(result) ? result.call(object) : result;
  9566. }
  9567. /**
  9568. * Sets the property value of `path` on `object`. If a portion of `path`
  9569. * does not exist it's created.
  9570. *
  9571. * @static
  9572. * @memberOf _
  9573. * @category Object
  9574. * @param {Object} object The object to augment.
  9575. * @param {Array|string} path The path of the property to set.
  9576. * @param {*} value The value to set.
  9577. * @returns {Object} Returns `object`.
  9578. * @example
  9579. *
  9580. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  9581. *
  9582. * _.set(object, 'a[0].b.c', 4);
  9583. * console.log(object.a[0].b.c);
  9584. * // => 4
  9585. *
  9586. * _.set(object, 'x[0].y.z', 5);
  9587. * console.log(object.x[0].y.z);
  9588. * // => 5
  9589. */
  9590. function set(object, path, value) {
  9591. if (object == null) {
  9592. return object;
  9593. }
  9594. var pathKey = (path + '');
  9595. path = (object[pathKey] != null || isKey(path, object)) ? [pathKey] : toPath(path);
  9596. var index = -1,
  9597. length = path.length,
  9598. lastIndex = length - 1,
  9599. nested = object;
  9600. while (nested != null && ++index < length) {
  9601. var key = path[index];
  9602. if (isObject(nested)) {
  9603. if (index == lastIndex) {
  9604. nested[key] = value;
  9605. } else if (nested[key] == null) {
  9606. nested[key] = isIndex(path[index + 1]) ? [] : {};
  9607. }
  9608. }
  9609. nested = nested[key];
  9610. }
  9611. return object;
  9612. }
  9613. /**
  9614. * An alternative to `_.reduce`; this method transforms `object` to a new
  9615. * `accumulator` object which is the result of running each of its own enumerable
  9616. * properties through `iteratee`, with each invocation potentially mutating
  9617. * the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
  9618. * with four arguments: (accumulator, value, key, object). Iteratee functions
  9619. * may exit iteration early by explicitly returning `false`.
  9620. *
  9621. * @static
  9622. * @memberOf _
  9623. * @category Object
  9624. * @param {Array|Object} object The object to iterate over.
  9625. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9626. * @param {*} [accumulator] The custom accumulator value.
  9627. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9628. * @returns {*} Returns the accumulated value.
  9629. * @example
  9630. *
  9631. * _.transform([2, 3, 4], function(result, n) {
  9632. * result.push(n *= n);
  9633. * return n % 2 == 0;
  9634. * });
  9635. * // => [4, 9]
  9636. *
  9637. * _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
  9638. * result[key] = n * 3;
  9639. * });
  9640. * // => { 'a': 3, 'b': 6 }
  9641. */
  9642. function transform(object, iteratee, accumulator, thisArg) {
  9643. var isArr = isArray(object) || isTypedArray(object);
  9644. iteratee = getCallback(iteratee, thisArg, 4);
  9645. if (accumulator == null) {
  9646. if (isArr || isObject(object)) {
  9647. var Ctor = object.constructor;
  9648. if (isArr) {
  9649. accumulator = isArray(object) ? new Ctor : [];
  9650. } else {
  9651. accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
  9652. }
  9653. } else {
  9654. accumulator = {};
  9655. }
  9656. }
  9657. (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
  9658. return iteratee(accumulator, value, index, object);
  9659. });
  9660. return accumulator;
  9661. }
  9662. /**
  9663. * Creates an array of the own enumerable property values of `object`.
  9664. *
  9665. * **Note:** Non-object values are coerced to objects.
  9666. *
  9667. * @static
  9668. * @memberOf _
  9669. * @category Object
  9670. * @param {Object} object The object to query.
  9671. * @returns {Array} Returns the array of property values.
  9672. * @example
  9673. *
  9674. * function Foo() {
  9675. * this.a = 1;
  9676. * this.b = 2;
  9677. * }
  9678. *
  9679. * Foo.prototype.c = 3;
  9680. *
  9681. * _.values(new Foo);
  9682. * // => [1, 2] (iteration order is not guaranteed)
  9683. *
  9684. * _.values('hi');
  9685. * // => ['h', 'i']
  9686. */
  9687. function values(object) {
  9688. return baseValues(object, keys(object));
  9689. }
  9690. /**
  9691. * Creates an array of the own and inherited enumerable property values
  9692. * of `object`.
  9693. *
  9694. * **Note:** Non-object values are coerced to objects.
  9695. *
  9696. * @static
  9697. * @memberOf _
  9698. * @category Object
  9699. * @param {Object} object The object to query.
  9700. * @returns {Array} Returns the array of property values.
  9701. * @example
  9702. *
  9703. * function Foo() {
  9704. * this.a = 1;
  9705. * this.b = 2;
  9706. * }
  9707. *
  9708. * Foo.prototype.c = 3;
  9709. *
  9710. * _.valuesIn(new Foo);
  9711. * // => [1, 2, 3] (iteration order is not guaranteed)
  9712. */
  9713. function valuesIn(object) {
  9714. return baseValues(object, keysIn(object));
  9715. }
  9716. /*------------------------------------------------------------------------*/
  9717. /**
  9718. * Checks if `n` is between `start` and up to but not including, `end`. If
  9719. * `end` is not specified it's set to `start` with `start` then set to `0`.
  9720. *
  9721. * @static
  9722. * @memberOf _
  9723. * @category Number
  9724. * @param {number} n The number to check.
  9725. * @param {number} [start=0] The start of the range.
  9726. * @param {number} end The end of the range.
  9727. * @returns {boolean} Returns `true` if `n` is in the range, else `false`.
  9728. * @example
  9729. *
  9730. * _.inRange(3, 2, 4);
  9731. * // => true
  9732. *
  9733. * _.inRange(4, 8);
  9734. * // => true
  9735. *
  9736. * _.inRange(4, 2);
  9737. * // => false
  9738. *
  9739. * _.inRange(2, 2);
  9740. * // => false
  9741. *
  9742. * _.inRange(1.2, 2);
  9743. * // => true
  9744. *
  9745. * _.inRange(5.2, 4);
  9746. * // => false
  9747. */
  9748. function inRange(value, start, end) {
  9749. start = +start || 0;
  9750. if (end === undefined) {
  9751. end = start;
  9752. start = 0;
  9753. } else {
  9754. end = +end || 0;
  9755. }
  9756. return value >= nativeMin(start, end) && value < nativeMax(start, end);
  9757. }
  9758. /**
  9759. * Produces a random number between `min` and `max` (inclusive). If only one
  9760. * argument is provided a number between `0` and the given number is returned.
  9761. * If `floating` is `true`, or either `min` or `max` are floats, a floating-point
  9762. * number is returned instead of an integer.
  9763. *
  9764. * @static
  9765. * @memberOf _
  9766. * @category Number
  9767. * @param {number} [min=0] The minimum possible value.
  9768. * @param {number} [max=1] The maximum possible value.
  9769. * @param {boolean} [floating] Specify returning a floating-point number.
  9770. * @returns {number} Returns the random number.
  9771. * @example
  9772. *
  9773. * _.random(0, 5);
  9774. * // => an integer between 0 and 5
  9775. *
  9776. * _.random(5);
  9777. * // => also an integer between 0 and 5
  9778. *
  9779. * _.random(5, true);
  9780. * // => a floating-point number between 0 and 5
  9781. *
  9782. * _.random(1.2, 5.2);
  9783. * // => a floating-point number between 1.2 and 5.2
  9784. */
  9785. function random(min, max, floating) {
  9786. if (floating && isIterateeCall(min, max, floating)) {
  9787. max = floating = undefined;
  9788. }
  9789. var noMin = min == null,
  9790. noMax = max == null;
  9791. if (floating == null) {
  9792. if (noMax && typeof min == 'boolean') {
  9793. floating = min;
  9794. min = 1;
  9795. }
  9796. else if (typeof max == 'boolean') {
  9797. floating = max;
  9798. noMax = true;
  9799. }
  9800. }
  9801. if (noMin && noMax) {
  9802. max = 1;
  9803. noMax = false;
  9804. }
  9805. min = +min || 0;
  9806. if (noMax) {
  9807. max = min;
  9808. min = 0;
  9809. } else {
  9810. max = +max || 0;
  9811. }
  9812. if (floating || min % 1 || max % 1) {
  9813. var rand = nativeRandom();
  9814. return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1)))), max);
  9815. }
  9816. return baseRandom(min, max);
  9817. }
  9818. /*------------------------------------------------------------------------*/
  9819. /**
  9820. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  9821. *
  9822. * @static
  9823. * @memberOf _
  9824. * @category String
  9825. * @param {string} [string=''] The string to convert.
  9826. * @returns {string} Returns the camel cased string.
  9827. * @example
  9828. *
  9829. * _.camelCase('Foo Bar');
  9830. * // => 'fooBar'
  9831. *
  9832. * _.camelCase('--foo-bar');
  9833. * // => 'fooBar'
  9834. *
  9835. * _.camelCase('__foo_bar__');
  9836. * // => 'fooBar'
  9837. */
  9838. var camelCase = createCompounder(function(result, word, index) {
  9839. word = word.toLowerCase();
  9840. return result + (index ? (word.charAt(0).toUpperCase() + word.slice(1)) : word);
  9841. });
  9842. /**
  9843. * Capitalizes the first character of `string`.
  9844. *
  9845. * @static
  9846. * @memberOf _
  9847. * @category String
  9848. * @param {string} [string=''] The string to capitalize.
  9849. * @returns {string} Returns the capitalized string.
  9850. * @example
  9851. *
  9852. * _.capitalize('fred');
  9853. * // => 'Fred'
  9854. */
  9855. function capitalize(string) {
  9856. string = baseToString(string);
  9857. return string && (string.charAt(0).toUpperCase() + string.slice(1));
  9858. }
  9859. /**
  9860. * Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  9861. * to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  9862. *
  9863. * @static
  9864. * @memberOf _
  9865. * @category String
  9866. * @param {string} [string=''] The string to deburr.
  9867. * @returns {string} Returns the deburred string.
  9868. * @example
  9869. *
  9870. * _.deburr('déjà vu');
  9871. * // => 'deja vu'
  9872. */
  9873. function deburr(string) {
  9874. string = baseToString(string);
  9875. return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
  9876. }
  9877. /**
  9878. * Checks if `string` ends with the given target string.
  9879. *
  9880. * @static
  9881. * @memberOf _
  9882. * @category String
  9883. * @param {string} [string=''] The string to search.
  9884. * @param {string} [target] The string to search for.
  9885. * @param {number} [position=string.length] The position to search from.
  9886. * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
  9887. * @example
  9888. *
  9889. * _.endsWith('abc', 'c');
  9890. * // => true
  9891. *
  9892. * _.endsWith('abc', 'b');
  9893. * // => false
  9894. *
  9895. * _.endsWith('abc', 'b', 2);
  9896. * // => true
  9897. */
  9898. function endsWith(string, target, position) {
  9899. string = baseToString(string);
  9900. target = (target + '');
  9901. var length = string.length;
  9902. position = position === undefined
  9903. ? length
  9904. : nativeMin(position < 0 ? 0 : (+position || 0), length);
  9905. position -= target.length;
  9906. return position >= 0 && string.indexOf(target, position) == position;
  9907. }
  9908. /**
  9909. * Converts the characters "&", "<", ">", '"', "'", and "\`", in `string` to
  9910. * their corresponding HTML entities.
  9911. *
  9912. * **Note:** No other characters are escaped. To escape additional characters
  9913. * use a third-party library like [_he_](https://mths.be/he).
  9914. *
  9915. * Though the ">" character is escaped for symmetry, characters like
  9916. * ">" and "/" don't need escaping in HTML and have no special meaning
  9917. * unless they're part of a tag or unquoted attribute value.
  9918. * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  9919. * (under "semi-related fun fact") for more details.
  9920. *
  9921. * Backticks are escaped because in Internet Explorer < 9, they can break out
  9922. * of attribute values or HTML comments. See [#59](https://html5sec.org/#59),
  9923. * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
  9924. * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
  9925. * for more details.
  9926. *
  9927. * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
  9928. * to reduce XSS vectors.
  9929. *
  9930. * @static
  9931. * @memberOf _
  9932. * @category String
  9933. * @param {string} [string=''] The string to escape.
  9934. * @returns {string} Returns the escaped string.
  9935. * @example
  9936. *
  9937. * _.escape('fred, barney, & pebbles');
  9938. * // => 'fred, barney, &amp; pebbles'
  9939. */
  9940. function escape(string) {
  9941. // Reset `lastIndex` because in IE < 9 `String#replace` does not.
  9942. string = baseToString(string);
  9943. return (string && reHasUnescapedHtml.test(string))
  9944. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  9945. : string;
  9946. }
  9947. /**
  9948. * Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
  9949. * "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
  9950. *
  9951. * @static
  9952. * @memberOf _
  9953. * @category String
  9954. * @param {string} [string=''] The string to escape.
  9955. * @returns {string} Returns the escaped string.
  9956. * @example
  9957. *
  9958. * _.escapeRegExp('[lodash](https://lodash.com/)');
  9959. * // => '\[lodash\]\(https:\/\/lodash\.com\/\)'
  9960. */
  9961. function escapeRegExp(string) {
  9962. string = baseToString(string);
  9963. return (string && reHasRegExpChars.test(string))
  9964. ? string.replace(reRegExpChars, escapeRegExpChar)
  9965. : (string || '(?:)');
  9966. }
  9967. /**
  9968. * Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  9969. *
  9970. * @static
  9971. * @memberOf _
  9972. * @category String
  9973. * @param {string} [string=''] The string to convert.
  9974. * @returns {string} Returns the kebab cased string.
  9975. * @example
  9976. *
  9977. * _.kebabCase('Foo Bar');
  9978. * // => 'foo-bar'
  9979. *
  9980. * _.kebabCase('fooBar');
  9981. * // => 'foo-bar'
  9982. *
  9983. * _.kebabCase('__foo_bar__');
  9984. * // => 'foo-bar'
  9985. */
  9986. var kebabCase = createCompounder(function(result, word, index) {
  9987. return result + (index ? '-' : '') + word.toLowerCase();
  9988. });
  9989. /**
  9990. * Pads `string` on the left and right sides if it's shorter than `length`.
  9991. * Padding characters are truncated if they can't be evenly divided by `length`.
  9992. *
  9993. * @static
  9994. * @memberOf _
  9995. * @category String
  9996. * @param {string} [string=''] The string to pad.
  9997. * @param {number} [length=0] The padding length.
  9998. * @param {string} [chars=' '] The string used as padding.
  9999. * @returns {string} Returns the padded string.
  10000. * @example
  10001. *
  10002. * _.pad('abc', 8);
  10003. * // => ' abc '
  10004. *
  10005. * _.pad('abc', 8, '_-');
  10006. * // => '_-abc_-_'
  10007. *
  10008. * _.pad('abc', 3);
  10009. * // => 'abc'
  10010. */
  10011. function pad(string, length, chars) {
  10012. string = baseToString(string);
  10013. length = +length;
  10014. var strLength = string.length;
  10015. if (strLength >= length || !nativeIsFinite(length)) {
  10016. return string;
  10017. }
  10018. var mid = (length - strLength) / 2,
  10019. leftLength = nativeFloor(mid),
  10020. rightLength = nativeCeil(mid);
  10021. chars = createPadding('', rightLength, chars);
  10022. return chars.slice(0, leftLength) + string + chars;
  10023. }
  10024. /**
  10025. * Pads `string` on the left side if it's shorter than `length`. Padding
  10026. * characters are truncated if they exceed `length`.
  10027. *
  10028. * @static
  10029. * @memberOf _
  10030. * @category String
  10031. * @param {string} [string=''] The string to pad.
  10032. * @param {number} [length=0] The padding length.
  10033. * @param {string} [chars=' '] The string used as padding.
  10034. * @returns {string} Returns the padded string.
  10035. * @example
  10036. *
  10037. * _.padLeft('abc', 6);
  10038. * // => ' abc'
  10039. *
  10040. * _.padLeft('abc', 6, '_-');
  10041. * // => '_-_abc'
  10042. *
  10043. * _.padLeft('abc', 3);
  10044. * // => 'abc'
  10045. */
  10046. var padLeft = createPadDir();
  10047. /**
  10048. * Pads `string` on the right side if it's shorter than `length`. Padding
  10049. * characters are truncated if they exceed `length`.
  10050. *
  10051. * @static
  10052. * @memberOf _
  10053. * @category String
  10054. * @param {string} [string=''] The string to pad.
  10055. * @param {number} [length=0] The padding length.
  10056. * @param {string} [chars=' '] The string used as padding.
  10057. * @returns {string} Returns the padded string.
  10058. * @example
  10059. *
  10060. * _.padRight('abc', 6);
  10061. * // => 'abc '
  10062. *
  10063. * _.padRight('abc', 6, '_-');
  10064. * // => 'abc_-_'
  10065. *
  10066. * _.padRight('abc', 3);
  10067. * // => 'abc'
  10068. */
  10069. var padRight = createPadDir(true);
  10070. /**
  10071. * Converts `string` to an integer of the specified radix. If `radix` is
  10072. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
  10073. * in which case a `radix` of `16` is used.
  10074. *
  10075. * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)
  10076. * of `parseInt`.
  10077. *
  10078. * @static
  10079. * @memberOf _
  10080. * @category String
  10081. * @param {string} string The string to convert.
  10082. * @param {number} [radix] The radix to interpret `value` by.
  10083. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10084. * @returns {number} Returns the converted integer.
  10085. * @example
  10086. *
  10087. * _.parseInt('08');
  10088. * // => 8
  10089. *
  10090. * _.map(['6', '08', '10'], _.parseInt);
  10091. * // => [6, 8, 10]
  10092. */
  10093. function parseInt(string, radix, guard) {
  10094. // Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
  10095. // Chrome fails to trim leading <BOM> whitespace characters.
  10096. // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
  10097. if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
  10098. radix = 0;
  10099. } else if (radix) {
  10100. radix = +radix;
  10101. }
  10102. string = trim(string);
  10103. return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
  10104. }
  10105. /**
  10106. * Repeats the given string `n` times.
  10107. *
  10108. * @static
  10109. * @memberOf _
  10110. * @category String
  10111. * @param {string} [string=''] The string to repeat.
  10112. * @param {number} [n=0] The number of times to repeat the string.
  10113. * @returns {string} Returns the repeated string.
  10114. * @example
  10115. *
  10116. * _.repeat('*', 3);
  10117. * // => '***'
  10118. *
  10119. * _.repeat('abc', 2);
  10120. * // => 'abcabc'
  10121. *
  10122. * _.repeat('abc', 0);
  10123. * // => ''
  10124. */
  10125. function repeat(string, n) {
  10126. var result = '';
  10127. string = baseToString(string);
  10128. n = +n;
  10129. if (n < 1 || !string || !nativeIsFinite(n)) {
  10130. return result;
  10131. }
  10132. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  10133. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  10134. do {
  10135. if (n % 2) {
  10136. result += string;
  10137. }
  10138. n = nativeFloor(n / 2);
  10139. string += string;
  10140. } while (n);
  10141. return result;
  10142. }
  10143. /**
  10144. * Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
  10145. *
  10146. * @static
  10147. * @memberOf _
  10148. * @category String
  10149. * @param {string} [string=''] The string to convert.
  10150. * @returns {string} Returns the snake cased string.
  10151. * @example
  10152. *
  10153. * _.snakeCase('Foo Bar');
  10154. * // => 'foo_bar'
  10155. *
  10156. * _.snakeCase('fooBar');
  10157. * // => 'foo_bar'
  10158. *
  10159. * _.snakeCase('--foo-bar');
  10160. * // => 'foo_bar'
  10161. */
  10162. var snakeCase = createCompounder(function(result, word, index) {
  10163. return result + (index ? '_' : '') + word.toLowerCase();
  10164. });
  10165. /**
  10166. * Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  10167. *
  10168. * @static
  10169. * @memberOf _
  10170. * @category String
  10171. * @param {string} [string=''] The string to convert.
  10172. * @returns {string} Returns the start cased string.
  10173. * @example
  10174. *
  10175. * _.startCase('--foo-bar');
  10176. * // => 'Foo Bar'
  10177. *
  10178. * _.startCase('fooBar');
  10179. * // => 'Foo Bar'
  10180. *
  10181. * _.startCase('__foo_bar__');
  10182. * // => 'Foo Bar'
  10183. */
  10184. var startCase = createCompounder(function(result, word, index) {
  10185. return result + (index ? ' ' : '') + (word.charAt(0).toUpperCase() + word.slice(1));
  10186. });
  10187. /**
  10188. * Checks if `string` starts with the given target string.
  10189. *
  10190. * @static
  10191. * @memberOf _
  10192. * @category String
  10193. * @param {string} [string=''] The string to search.
  10194. * @param {string} [target] The string to search for.
  10195. * @param {number} [position=0] The position to search from.
  10196. * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
  10197. * @example
  10198. *
  10199. * _.startsWith('abc', 'a');
  10200. * // => true
  10201. *
  10202. * _.startsWith('abc', 'b');
  10203. * // => false
  10204. *
  10205. * _.startsWith('abc', 'b', 1);
  10206. * // => true
  10207. */
  10208. function startsWith(string, target, position) {
  10209. string = baseToString(string);
  10210. position = position == null
  10211. ? 0
  10212. : nativeMin(position < 0 ? 0 : (+position || 0), string.length);
  10213. return string.lastIndexOf(target, position) == position;
  10214. }
  10215. /**
  10216. * Creates a compiled template function that can interpolate data properties
  10217. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  10218. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  10219. * properties may be accessed as free variables in the template. If a setting
  10220. * object is provided it takes precedence over `_.templateSettings` values.
  10221. *
  10222. * **Note:** In the development build `_.template` utilizes
  10223. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  10224. * for easier debugging.
  10225. *
  10226. * For more information on precompiling templates see
  10227. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  10228. *
  10229. * For more information on Chrome extension sandboxes see
  10230. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  10231. *
  10232. * @static
  10233. * @memberOf _
  10234. * @category String
  10235. * @param {string} [string=''] The template string.
  10236. * @param {Object} [options] The options object.
  10237. * @param {RegExp} [options.escape] The HTML "escape" delimiter.
  10238. * @param {RegExp} [options.evaluate] The "evaluate" delimiter.
  10239. * @param {Object} [options.imports] An object to import into the template as free variables.
  10240. * @param {RegExp} [options.interpolate] The "interpolate" delimiter.
  10241. * @param {string} [options.sourceURL] The sourceURL of the template's compiled source.
  10242. * @param {string} [options.variable] The data object variable name.
  10243. * @param- {Object} [otherOptions] Enables the legacy `options` param signature.
  10244. * @returns {Function} Returns the compiled template function.
  10245. * @example
  10246. *
  10247. * // using the "interpolate" delimiter to create a compiled template
  10248. * var compiled = _.template('hello <%= user %>!');
  10249. * compiled({ 'user': 'fred' });
  10250. * // => 'hello fred!'
  10251. *
  10252. * // using the HTML "escape" delimiter to escape data property values
  10253. * var compiled = _.template('<b><%- value %></b>');
  10254. * compiled({ 'value': '<script>' });
  10255. * // => '<b>&lt;script&gt;</b>'
  10256. *
  10257. * // using the "evaluate" delimiter to execute JavaScript and generate HTML
  10258. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  10259. * compiled({ 'users': ['fred', 'barney'] });
  10260. * // => '<li>fred</li><li>barney</li>'
  10261. *
  10262. * // using the internal `print` function in "evaluate" delimiters
  10263. * var compiled = _.template('<% print("hello " + user); %>!');
  10264. * compiled({ 'user': 'barney' });
  10265. * // => 'hello barney!'
  10266. *
  10267. * // using the ES delimiter as an alternative to the default "interpolate" delimiter
  10268. * var compiled = _.template('hello ${ user }!');
  10269. * compiled({ 'user': 'pebbles' });
  10270. * // => 'hello pebbles!'
  10271. *
  10272. * // using custom template delimiters
  10273. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  10274. * var compiled = _.template('hello {{ user }}!');
  10275. * compiled({ 'user': 'mustache' });
  10276. * // => 'hello mustache!'
  10277. *
  10278. * // using backslashes to treat delimiters as plain text
  10279. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  10280. * compiled({ 'value': 'ignored' });
  10281. * // => '<%- value %>'
  10282. *
  10283. * // using the `imports` option to import `jQuery` as `jq`
  10284. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  10285. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  10286. * compiled({ 'users': ['fred', 'barney'] });
  10287. * // => '<li>fred</li><li>barney</li>'
  10288. *
  10289. * // using the `sourceURL` option to specify a custom sourceURL for the template
  10290. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  10291. * compiled(data);
  10292. * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
  10293. *
  10294. * // using the `variable` option to ensure a with-statement isn't used in the compiled template
  10295. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  10296. * compiled.source;
  10297. * // => function(data) {
  10298. * // var __t, __p = '';
  10299. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  10300. * // return __p;
  10301. * // }
  10302. *
  10303. * // using the `source` property to inline compiled templates for meaningful
  10304. * // line numbers in error messages and a stack trace
  10305. * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
  10306. * var JST = {\
  10307. * "main": ' + _.template(mainText).source + '\
  10308. * };\
  10309. * ');
  10310. */
  10311. function template(string, options, otherOptions) {
  10312. // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
  10313. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  10314. var settings = lodash.templateSettings;
  10315. if (otherOptions && isIterateeCall(string, options, otherOptions)) {
  10316. options = otherOptions = undefined;
  10317. }
  10318. string = baseToString(string);
  10319. options = assignWith(baseAssign({}, otherOptions || options), settings, assignOwnDefaults);
  10320. var imports = assignWith(baseAssign({}, options.imports), settings.imports, assignOwnDefaults),
  10321. importsKeys = keys(imports),
  10322. importsValues = baseValues(imports, importsKeys);
  10323. var isEscaping,
  10324. isEvaluating,
  10325. index = 0,
  10326. interpolate = options.interpolate || reNoMatch,
  10327. source = "__p += '";
  10328. // Compile the regexp to match each delimiter.
  10329. var reDelimiters = RegExp(
  10330. (options.escape || reNoMatch).source + '|' +
  10331. interpolate.source + '|' +
  10332. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  10333. (options.evaluate || reNoMatch).source + '|$'
  10334. , 'g');
  10335. // Use a sourceURL for easier debugging.
  10336. var sourceURL = '//# sourceURL=' +
  10337. ('sourceURL' in options
  10338. ? options.sourceURL
  10339. : ('lodash.templateSources[' + (++templateCounter) + ']')
  10340. ) + '\n';
  10341. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  10342. interpolateValue || (interpolateValue = esTemplateValue);
  10343. // Escape characters that can't be included in string literals.
  10344. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  10345. // Replace delimiters with snippets.
  10346. if (escapeValue) {
  10347. isEscaping = true;
  10348. source += "' +\n__e(" + escapeValue + ") +\n'";
  10349. }
  10350. if (evaluateValue) {
  10351. isEvaluating = true;
  10352. source += "';\n" + evaluateValue + ";\n__p += '";
  10353. }
  10354. if (interpolateValue) {
  10355. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  10356. }
  10357. index = offset + match.length;
  10358. // The JS engine embedded in Adobe products requires returning the `match`
  10359. // string in order to produce the correct `offset` value.
  10360. return match;
  10361. });
  10362. source += "';\n";
  10363. // If `variable` is not specified wrap a with-statement around the generated
  10364. // code to add the data object to the top of the scope chain.
  10365. var variable = options.variable;
  10366. if (!variable) {
  10367. source = 'with (obj) {\n' + source + '\n}\n';
  10368. }
  10369. // Cleanup code by stripping empty strings.
  10370. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  10371. .replace(reEmptyStringMiddle, '$1')
  10372. .replace(reEmptyStringTrailing, '$1;');
  10373. // Frame code as the function body.
  10374. source = 'function(' + (variable || 'obj') + ') {\n' +
  10375. (variable
  10376. ? ''
  10377. : 'obj || (obj = {});\n'
  10378. ) +
  10379. "var __t, __p = ''" +
  10380. (isEscaping
  10381. ? ', __e = _.escape'
  10382. : ''
  10383. ) +
  10384. (isEvaluating
  10385. ? ', __j = Array.prototype.join;\n' +
  10386. "function print() { __p += __j.call(arguments, '') }\n"
  10387. : ';\n'
  10388. ) +
  10389. source +
  10390. 'return __p\n}';
  10391. var result = attempt(function() {
  10392. return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues);
  10393. });
  10394. // Provide the compiled function's source by its `toString` method or
  10395. // the `source` property as a convenience for inlining compiled templates.
  10396. result.source = source;
  10397. if (isError(result)) {
  10398. throw result;
  10399. }
  10400. return result;
  10401. }
  10402. /**
  10403. * Removes leading and trailing whitespace or specified characters from `string`.
  10404. *
  10405. * @static
  10406. * @memberOf _
  10407. * @category String
  10408. * @param {string} [string=''] The string to trim.
  10409. * @param {string} [chars=whitespace] The characters to trim.
  10410. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10411. * @returns {string} Returns the trimmed string.
  10412. * @example
  10413. *
  10414. * _.trim(' abc ');
  10415. * // => 'abc'
  10416. *
  10417. * _.trim('-_-abc-_-', '_-');
  10418. * // => 'abc'
  10419. *
  10420. * _.map([' foo ', ' bar '], _.trim);
  10421. * // => ['foo', 'bar']
  10422. */
  10423. function trim(string, chars, guard) {
  10424. var value = string;
  10425. string = baseToString(string);
  10426. if (!string) {
  10427. return string;
  10428. }
  10429. if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
  10430. return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
  10431. }
  10432. chars = (chars + '');
  10433. return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
  10434. }
  10435. /**
  10436. * Removes leading whitespace or specified characters from `string`.
  10437. *
  10438. * @static
  10439. * @memberOf _
  10440. * @category String
  10441. * @param {string} [string=''] The string to trim.
  10442. * @param {string} [chars=whitespace] The characters to trim.
  10443. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10444. * @returns {string} Returns the trimmed string.
  10445. * @example
  10446. *
  10447. * _.trimLeft(' abc ');
  10448. * // => 'abc '
  10449. *
  10450. * _.trimLeft('-_-abc-_-', '_-');
  10451. * // => 'abc-_-'
  10452. */
  10453. function trimLeft(string, chars, guard) {
  10454. var value = string;
  10455. string = baseToString(string);
  10456. if (!string) {
  10457. return string;
  10458. }
  10459. if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
  10460. return string.slice(trimmedLeftIndex(string));
  10461. }
  10462. return string.slice(charsLeftIndex(string, (chars + '')));
  10463. }
  10464. /**
  10465. * Removes trailing whitespace or specified characters from `string`.
  10466. *
  10467. * @static
  10468. * @memberOf _
  10469. * @category String
  10470. * @param {string} [string=''] The string to trim.
  10471. * @param {string} [chars=whitespace] The characters to trim.
  10472. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10473. * @returns {string} Returns the trimmed string.
  10474. * @example
  10475. *
  10476. * _.trimRight(' abc ');
  10477. * // => ' abc'
  10478. *
  10479. * _.trimRight('-_-abc-_-', '_-');
  10480. * // => '-_-abc'
  10481. */
  10482. function trimRight(string, chars, guard) {
  10483. var value = string;
  10484. string = baseToString(string);
  10485. if (!string) {
  10486. return string;
  10487. }
  10488. if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
  10489. return string.slice(0, trimmedRightIndex(string) + 1);
  10490. }
  10491. return string.slice(0, charsRightIndex(string, (chars + '')) + 1);
  10492. }
  10493. /**
  10494. * Truncates `string` if it's longer than the given maximum string length.
  10495. * The last characters of the truncated string are replaced with the omission
  10496. * string which defaults to "...".
  10497. *
  10498. * @static
  10499. * @memberOf _
  10500. * @category String
  10501. * @param {string} [string=''] The string to truncate.
  10502. * @param {Object|number} [options] The options object or maximum string length.
  10503. * @param {number} [options.length=30] The maximum string length.
  10504. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  10505. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  10506. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10507. * @returns {string} Returns the truncated string.
  10508. * @example
  10509. *
  10510. * _.trunc('hi-diddly-ho there, neighborino');
  10511. * // => 'hi-diddly-ho there, neighbo...'
  10512. *
  10513. * _.trunc('hi-diddly-ho there, neighborino', 24);
  10514. * // => 'hi-diddly-ho there, n...'
  10515. *
  10516. * _.trunc('hi-diddly-ho there, neighborino', {
  10517. * 'length': 24,
  10518. * 'separator': ' '
  10519. * });
  10520. * // => 'hi-diddly-ho there,...'
  10521. *
  10522. * _.trunc('hi-diddly-ho there, neighborino', {
  10523. * 'length': 24,
  10524. * 'separator': /,? +/
  10525. * });
  10526. * // => 'hi-diddly-ho there...'
  10527. *
  10528. * _.trunc('hi-diddly-ho there, neighborino', {
  10529. * 'omission': ' [...]'
  10530. * });
  10531. * // => 'hi-diddly-ho there, neig [...]'
  10532. */
  10533. function trunc(string, options, guard) {
  10534. if (guard && isIterateeCall(string, options, guard)) {
  10535. options = undefined;
  10536. }
  10537. var length = DEFAULT_TRUNC_LENGTH,
  10538. omission = DEFAULT_TRUNC_OMISSION;
  10539. if (options != null) {
  10540. if (isObject(options)) {
  10541. var separator = 'separator' in options ? options.separator : separator;
  10542. length = 'length' in options ? (+options.length || 0) : length;
  10543. omission = 'omission' in options ? baseToString(options.omission) : omission;
  10544. } else {
  10545. length = +options || 0;
  10546. }
  10547. }
  10548. string = baseToString(string);
  10549. if (length >= string.length) {
  10550. return string;
  10551. }
  10552. var end = length - omission.length;
  10553. if (end < 1) {
  10554. return omission;
  10555. }
  10556. var result = string.slice(0, end);
  10557. if (separator == null) {
  10558. return result + omission;
  10559. }
  10560. if (isRegExp(separator)) {
  10561. if (string.slice(end).search(separator)) {
  10562. var match,
  10563. newEnd,
  10564. substring = string.slice(0, end);
  10565. if (!separator.global) {
  10566. separator = RegExp(separator.source, (reFlags.exec(separator) || '') + 'g');
  10567. }
  10568. separator.lastIndex = 0;
  10569. while ((match = separator.exec(substring))) {
  10570. newEnd = match.index;
  10571. }
  10572. result = result.slice(0, newEnd == null ? end : newEnd);
  10573. }
  10574. } else if (string.indexOf(separator, end) != end) {
  10575. var index = result.lastIndexOf(separator);
  10576. if (index > -1) {
  10577. result = result.slice(0, index);
  10578. }
  10579. }
  10580. return result + omission;
  10581. }
  10582. /**
  10583. * The inverse of `_.escape`; this method converts the HTML entities
  10584. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&#39;`, and `&#96;` in `string` to their
  10585. * corresponding characters.
  10586. *
  10587. * **Note:** No other HTML entities are unescaped. To unescape additional HTML
  10588. * entities use a third-party library like [_he_](https://mths.be/he).
  10589. *
  10590. * @static
  10591. * @memberOf _
  10592. * @category String
  10593. * @param {string} [string=''] The string to unescape.
  10594. * @returns {string} Returns the unescaped string.
  10595. * @example
  10596. *
  10597. * _.unescape('fred, barney, &amp; pebbles');
  10598. * // => 'fred, barney, & pebbles'
  10599. */
  10600. function unescape(string) {
  10601. string = baseToString(string);
  10602. return (string && reHasEscapedHtml.test(string))
  10603. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  10604. : string;
  10605. }
  10606. /**
  10607. * Splits `string` into an array of its words.
  10608. *
  10609. * @static
  10610. * @memberOf _
  10611. * @category String
  10612. * @param {string} [string=''] The string to inspect.
  10613. * @param {RegExp|string} [pattern] The pattern to match words.
  10614. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10615. * @returns {Array} Returns the words of `string`.
  10616. * @example
  10617. *
  10618. * _.words('fred, barney, & pebbles');
  10619. * // => ['fred', 'barney', 'pebbles']
  10620. *
  10621. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  10622. * // => ['fred', 'barney', '&', 'pebbles']
  10623. */
  10624. function words(string, pattern, guard) {
  10625. if (guard && isIterateeCall(string, pattern, guard)) {
  10626. pattern = undefined;
  10627. }
  10628. string = baseToString(string);
  10629. return string.match(pattern || reWords) || [];
  10630. }
  10631. /*------------------------------------------------------------------------*/
  10632. /**
  10633. * Attempts to invoke `func`, returning either the result or the caught error
  10634. * object. Any additional arguments are provided to `func` when it's invoked.
  10635. *
  10636. * @static
  10637. * @memberOf _
  10638. * @category Utility
  10639. * @param {Function} func The function to attempt.
  10640. * @returns {*} Returns the `func` result or error object.
  10641. * @example
  10642. *
  10643. * // avoid throwing errors for invalid selectors
  10644. * var elements = _.attempt(function(selector) {
  10645. * return document.querySelectorAll(selector);
  10646. * }, '>_>');
  10647. *
  10648. * if (_.isError(elements)) {
  10649. * elements = [];
  10650. * }
  10651. */
  10652. var attempt = restParam(function(func, args) {
  10653. try {
  10654. return func.apply(undefined, args);
  10655. } catch(e) {
  10656. return isError(e) ? e : new Error(e);
  10657. }
  10658. });
  10659. /**
  10660. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  10661. * and arguments of the created function. If `func` is a property name the
  10662. * created callback returns the property value for a given element. If `func`
  10663. * is an object the created callback returns `true` for elements that contain
  10664. * the equivalent object properties, otherwise it returns `false`.
  10665. *
  10666. * @static
  10667. * @memberOf _
  10668. * @alias iteratee
  10669. * @category Utility
  10670. * @param {*} [func=_.identity] The value to convert to a callback.
  10671. * @param {*} [thisArg] The `this` binding of `func`.
  10672. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10673. * @returns {Function} Returns the callback.
  10674. * @example
  10675. *
  10676. * var users = [
  10677. * { 'user': 'barney', 'age': 36 },
  10678. * { 'user': 'fred', 'age': 40 }
  10679. * ];
  10680. *
  10681. * // wrap to create custom callback shorthands
  10682. * _.callback = _.wrap(_.callback, function(callback, func, thisArg) {
  10683. * var match = /^(.+?)__([gl]t)(.+)$/.exec(func);
  10684. * if (!match) {
  10685. * return callback(func, thisArg);
  10686. * }
  10687. * return function(object) {
  10688. * return match[2] == 'gt'
  10689. * ? object[match[1]] > match[3]
  10690. * : object[match[1]] < match[3];
  10691. * };
  10692. * });
  10693. *
  10694. * _.filter(users, 'age__gt36');
  10695. * // => [{ 'user': 'fred', 'age': 40 }]
  10696. */
  10697. function callback(func, thisArg, guard) {
  10698. if (guard && isIterateeCall(func, thisArg, guard)) {
  10699. thisArg = undefined;
  10700. }
  10701. return isObjectLike(func)
  10702. ? matches(func)
  10703. : baseCallback(func, thisArg);
  10704. }
  10705. /**
  10706. * Creates a function that returns `value`.
  10707. *
  10708. * @static
  10709. * @memberOf _
  10710. * @category Utility
  10711. * @param {*} value The value to return from the new function.
  10712. * @returns {Function} Returns the new function.
  10713. * @example
  10714. *
  10715. * var object = { 'user': 'fred' };
  10716. * var getter = _.constant(object);
  10717. *
  10718. * getter() === object;
  10719. * // => true
  10720. */
  10721. function constant(value) {
  10722. return function() {
  10723. return value;
  10724. };
  10725. }
  10726. /**
  10727. * This method returns the first argument provided to it.
  10728. *
  10729. * @static
  10730. * @memberOf _
  10731. * @category Utility
  10732. * @param {*} value Any value.
  10733. * @returns {*} Returns `value`.
  10734. * @example
  10735. *
  10736. * var object = { 'user': 'fred' };
  10737. *
  10738. * _.identity(object) === object;
  10739. * // => true
  10740. */
  10741. function identity(value) {
  10742. return value;
  10743. }
  10744. /**
  10745. * Creates a function that performs a deep comparison between a given object
  10746. * and `source`, returning `true` if the given object has equivalent property
  10747. * values, else `false`.
  10748. *
  10749. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  10750. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  10751. * their own, not inherited, enumerable properties. For comparing a single
  10752. * own or inherited property value see `_.matchesProperty`.
  10753. *
  10754. * @static
  10755. * @memberOf _
  10756. * @category Utility
  10757. * @param {Object} source The object of property values to match.
  10758. * @returns {Function} Returns the new function.
  10759. * @example
  10760. *
  10761. * var users = [
  10762. * { 'user': 'barney', 'age': 36, 'active': true },
  10763. * { 'user': 'fred', 'age': 40, 'active': false }
  10764. * ];
  10765. *
  10766. * _.filter(users, _.matches({ 'age': 40, 'active': false }));
  10767. * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
  10768. */
  10769. function matches(source) {
  10770. return baseMatches(baseClone(source, true));
  10771. }
  10772. /**
  10773. * Creates a function that compares the property value of `path` on a given
  10774. * object to `value`.
  10775. *
  10776. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  10777. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  10778. * their own, not inherited, enumerable properties.
  10779. *
  10780. * @static
  10781. * @memberOf _
  10782. * @category Utility
  10783. * @param {Array|string} path The path of the property to get.
  10784. * @param {*} srcValue The value to match.
  10785. * @returns {Function} Returns the new function.
  10786. * @example
  10787. *
  10788. * var users = [
  10789. * { 'user': 'barney' },
  10790. * { 'user': 'fred' }
  10791. * ];
  10792. *
  10793. * _.find(users, _.matchesProperty('user', 'fred'));
  10794. * // => { 'user': 'fred' }
  10795. */
  10796. function matchesProperty(path, srcValue) {
  10797. return baseMatchesProperty(path, baseClone(srcValue, true));
  10798. }
  10799. /**
  10800. * Creates a function that invokes the method at `path` on a given object.
  10801. * Any additional arguments are provided to the invoked method.
  10802. *
  10803. * @static
  10804. * @memberOf _
  10805. * @category Utility
  10806. * @param {Array|string} path The path of the method to invoke.
  10807. * @param {...*} [args] The arguments to invoke the method with.
  10808. * @returns {Function} Returns the new function.
  10809. * @example
  10810. *
  10811. * var objects = [
  10812. * { 'a': { 'b': { 'c': _.constant(2) } } },
  10813. * { 'a': { 'b': { 'c': _.constant(1) } } }
  10814. * ];
  10815. *
  10816. * _.map(objects, _.method('a.b.c'));
  10817. * // => [2, 1]
  10818. *
  10819. * _.invoke(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c');
  10820. * // => [1, 2]
  10821. */
  10822. var method = restParam(function(path, args) {
  10823. return function(object) {
  10824. return invokePath(object, path, args);
  10825. };
  10826. });
  10827. /**
  10828. * The opposite of `_.method`; this method creates a function that invokes
  10829. * the method at a given path on `object`. Any additional arguments are
  10830. * provided to the invoked method.
  10831. *
  10832. * @static
  10833. * @memberOf _
  10834. * @category Utility
  10835. * @param {Object} object The object to query.
  10836. * @param {...*} [args] The arguments to invoke the method with.
  10837. * @returns {Function} Returns the new function.
  10838. * @example
  10839. *
  10840. * var array = _.times(3, _.constant),
  10841. * object = { 'a': array, 'b': array, 'c': array };
  10842. *
  10843. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  10844. * // => [2, 0]
  10845. *
  10846. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  10847. * // => [2, 0]
  10848. */
  10849. var methodOf = restParam(function(object, args) {
  10850. return function(path) {
  10851. return invokePath(object, path, args);
  10852. };
  10853. });
  10854. /**
  10855. * Adds all own enumerable function properties of a source object to the
  10856. * destination object. If `object` is a function then methods are added to
  10857. * its prototype as well.
  10858. *
  10859. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  10860. * avoid conflicts caused by modifying the original.
  10861. *
  10862. * @static
  10863. * @memberOf _
  10864. * @category Utility
  10865. * @param {Function|Object} [object=lodash] The destination object.
  10866. * @param {Object} source The object of functions to add.
  10867. * @param {Object} [options] The options object.
  10868. * @param {boolean} [options.chain=true] Specify whether the functions added
  10869. * are chainable.
  10870. * @returns {Function|Object} Returns `object`.
  10871. * @example
  10872. *
  10873. * function vowels(string) {
  10874. * return _.filter(string, function(v) {
  10875. * return /[aeiou]/i.test(v);
  10876. * });
  10877. * }
  10878. *
  10879. * _.mixin({ 'vowels': vowels });
  10880. * _.vowels('fred');
  10881. * // => ['e']
  10882. *
  10883. * _('fred').vowels().value();
  10884. * // => ['e']
  10885. *
  10886. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  10887. * _('fred').vowels();
  10888. * // => ['e']
  10889. */
  10890. function mixin(object, source, options) {
  10891. if (options == null) {
  10892. var isObj = isObject(source),
  10893. props = isObj ? keys(source) : undefined,
  10894. methodNames = (props && props.length) ? baseFunctions(source, props) : undefined;
  10895. if (!(methodNames ? methodNames.length : isObj)) {
  10896. methodNames = false;
  10897. options = source;
  10898. source = object;
  10899. object = this;
  10900. }
  10901. }
  10902. if (!methodNames) {
  10903. methodNames = baseFunctions(source, keys(source));
  10904. }
  10905. var chain = true,
  10906. index = -1,
  10907. isFunc = isFunction(object),
  10908. length = methodNames.length;
  10909. if (options === false) {
  10910. chain = false;
  10911. } else if (isObject(options) && 'chain' in options) {
  10912. chain = options.chain;
  10913. }
  10914. while (++index < length) {
  10915. var methodName = methodNames[index],
  10916. func = source[methodName];
  10917. object[methodName] = func;
  10918. if (isFunc) {
  10919. object.prototype[methodName] = (function(func) {
  10920. return function() {
  10921. var chainAll = this.__chain__;
  10922. if (chain || chainAll) {
  10923. var result = object(this.__wrapped__),
  10924. actions = result.__actions__ = arrayCopy(this.__actions__);
  10925. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  10926. result.__chain__ = chainAll;
  10927. return result;
  10928. }
  10929. return func.apply(object, arrayPush([this.value()], arguments));
  10930. };
  10931. }(func));
  10932. }
  10933. }
  10934. return object;
  10935. }
  10936. /**
  10937. * Reverts the `_` variable to its previous value and returns a reference to
  10938. * the `lodash` function.
  10939. *
  10940. * @static
  10941. * @memberOf _
  10942. * @category Utility
  10943. * @returns {Function} Returns the `lodash` function.
  10944. * @example
  10945. *
  10946. * var lodash = _.noConflict();
  10947. */
  10948. function noConflict() {
  10949. root._ = oldDash;
  10950. return this;
  10951. }
  10952. /**
  10953. * A no-operation function that returns `undefined` regardless of the
  10954. * arguments it receives.
  10955. *
  10956. * @static
  10957. * @memberOf _
  10958. * @category Utility
  10959. * @example
  10960. *
  10961. * var object = { 'user': 'fred' };
  10962. *
  10963. * _.noop(object) === undefined;
  10964. * // => true
  10965. */
  10966. function noop() {
  10967. // No operation performed.
  10968. }
  10969. /**
  10970. * Creates a function that returns the property value at `path` on a
  10971. * given object.
  10972. *
  10973. * @static
  10974. * @memberOf _
  10975. * @category Utility
  10976. * @param {Array|string} path The path of the property to get.
  10977. * @returns {Function} Returns the new function.
  10978. * @example
  10979. *
  10980. * var objects = [
  10981. * { 'a': { 'b': { 'c': 2 } } },
  10982. * { 'a': { 'b': { 'c': 1 } } }
  10983. * ];
  10984. *
  10985. * _.map(objects, _.property('a.b.c'));
  10986. * // => [2, 1]
  10987. *
  10988. * _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
  10989. * // => [1, 2]
  10990. */
  10991. function property(path) {
  10992. return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
  10993. }
  10994. /**
  10995. * The opposite of `_.property`; this method creates a function that returns
  10996. * the property value at a given path on `object`.
  10997. *
  10998. * @static
  10999. * @memberOf _
  11000. * @category Utility
  11001. * @param {Object} object The object to query.
  11002. * @returns {Function} Returns the new function.
  11003. * @example
  11004. *
  11005. * var array = [0, 1, 2],
  11006. * object = { 'a': array, 'b': array, 'c': array };
  11007. *
  11008. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  11009. * // => [2, 0]
  11010. *
  11011. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  11012. * // => [2, 0]
  11013. */
  11014. function propertyOf(object) {
  11015. return function(path) {
  11016. return baseGet(object, toPath(path), (path + ''));
  11017. };
  11018. }
  11019. /**
  11020. * Creates an array of numbers (positive and/or negative) progressing from
  11021. * `start` up to, but not including, `end`. If `end` is not specified it's
  11022. * set to `start` with `start` then set to `0`. If `end` is less than `start`
  11023. * a zero-length range is created unless a negative `step` is specified.
  11024. *
  11025. * @static
  11026. * @memberOf _
  11027. * @category Utility
  11028. * @param {number} [start=0] The start of the range.
  11029. * @param {number} end The end of the range.
  11030. * @param {number} [step=1] The value to increment or decrement by.
  11031. * @returns {Array} Returns the new array of numbers.
  11032. * @example
  11033. *
  11034. * _.range(4);
  11035. * // => [0, 1, 2, 3]
  11036. *
  11037. * _.range(1, 5);
  11038. * // => [1, 2, 3, 4]
  11039. *
  11040. * _.range(0, 20, 5);
  11041. * // => [0, 5, 10, 15]
  11042. *
  11043. * _.range(0, -4, -1);
  11044. * // => [0, -1, -2, -3]
  11045. *
  11046. * _.range(1, 4, 0);
  11047. * // => [1, 1, 1]
  11048. *
  11049. * _.range(0);
  11050. * // => []
  11051. */
  11052. function range(start, end, step) {
  11053. if (step && isIterateeCall(start, end, step)) {
  11054. end = step = undefined;
  11055. }
  11056. start = +start || 0;
  11057. step = step == null ? 1 : (+step || 0);
  11058. if (end == null) {
  11059. end = start;
  11060. start = 0;
  11061. } else {
  11062. end = +end || 0;
  11063. }
  11064. // Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
  11065. // See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
  11066. var index = -1,
  11067. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  11068. result = Array(length);
  11069. while (++index < length) {
  11070. result[index] = start;
  11071. start += step;
  11072. }
  11073. return result;
  11074. }
  11075. /**
  11076. * Invokes the iteratee function `n` times, returning an array of the results
  11077. * of each invocation. The `iteratee` is bound to `thisArg` and invoked with
  11078. * one argument; (index).
  11079. *
  11080. * @static
  11081. * @memberOf _
  11082. * @category Utility
  11083. * @param {number} n The number of times to invoke `iteratee`.
  11084. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11085. * @param {*} [thisArg] The `this` binding of `iteratee`.
  11086. * @returns {Array} Returns the array of results.
  11087. * @example
  11088. *
  11089. * var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
  11090. * // => [3, 6, 4]
  11091. *
  11092. * _.times(3, function(n) {
  11093. * mage.castSpell(n);
  11094. * });
  11095. * // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2`
  11096. *
  11097. * _.times(3, function(n) {
  11098. * this.cast(n);
  11099. * }, mage);
  11100. * // => also invokes `mage.castSpell(n)` three times
  11101. */
  11102. function times(n, iteratee, thisArg) {
  11103. n = nativeFloor(n);
  11104. // Exit early to avoid a JSC JIT bug in Safari 8
  11105. // where `Array(0)` is treated as `Array(1)`.
  11106. if (n < 1 || !nativeIsFinite(n)) {
  11107. return [];
  11108. }
  11109. var index = -1,
  11110. result = Array(nativeMin(n, MAX_ARRAY_LENGTH));
  11111. iteratee = bindCallback(iteratee, thisArg, 1);
  11112. while (++index < n) {
  11113. if (index < MAX_ARRAY_LENGTH) {
  11114. result[index] = iteratee(index);
  11115. } else {
  11116. iteratee(index);
  11117. }
  11118. }
  11119. return result;
  11120. }
  11121. /**
  11122. * Generates a unique ID. If `prefix` is provided the ID is appended to it.
  11123. *
  11124. * @static
  11125. * @memberOf _
  11126. * @category Utility
  11127. * @param {string} [prefix] The value to prefix the ID with.
  11128. * @returns {string} Returns the unique ID.
  11129. * @example
  11130. *
  11131. * _.uniqueId('contact_');
  11132. * // => 'contact_104'
  11133. *
  11134. * _.uniqueId();
  11135. * // => '105'
  11136. */
  11137. function uniqueId(prefix) {
  11138. var id = ++idCounter;
  11139. return baseToString(prefix) + id;
  11140. }
  11141. /*------------------------------------------------------------------------*/
  11142. /**
  11143. * Adds two numbers.
  11144. *
  11145. * @static
  11146. * @memberOf _
  11147. * @category Math
  11148. * @param {number} augend The first number to add.
  11149. * @param {number} addend The second number to add.
  11150. * @returns {number} Returns the sum.
  11151. * @example
  11152. *
  11153. * _.add(6, 4);
  11154. * // => 10
  11155. */
  11156. function add(augend, addend) {
  11157. return (+augend || 0) + (+addend || 0);
  11158. }
  11159. /**
  11160. * Calculates `n` rounded up to `precision`.
  11161. *
  11162. * @static
  11163. * @memberOf _
  11164. * @category Math
  11165. * @param {number} n The number to round up.
  11166. * @param {number} [precision=0] The precision to round up to.
  11167. * @returns {number} Returns the rounded up number.
  11168. * @example
  11169. *
  11170. * _.ceil(4.006);
  11171. * // => 5
  11172. *
  11173. * _.ceil(6.004, 2);
  11174. * // => 6.01
  11175. *
  11176. * _.ceil(6040, -2);
  11177. * // => 6100
  11178. */
  11179. var ceil = createRound('ceil');
  11180. /**
  11181. * Calculates `n` rounded down to `precision`.
  11182. *
  11183. * @static
  11184. * @memberOf _
  11185. * @category Math
  11186. * @param {number} n The number to round down.
  11187. * @param {number} [precision=0] The precision to round down to.
  11188. * @returns {number} Returns the rounded down number.
  11189. * @example
  11190. *
  11191. * _.floor(4.006);
  11192. * // => 4
  11193. *
  11194. * _.floor(0.046, 2);
  11195. * // => 0.04
  11196. *
  11197. * _.floor(4060, -2);
  11198. * // => 4000
  11199. */
  11200. var floor = createRound('floor');
  11201. /**
  11202. * Gets the maximum value of `collection`. If `collection` is empty or falsey
  11203. * `-Infinity` is returned. If an iteratee function is provided it's invoked
  11204. * for each value in `collection` to generate the criterion by which the value
  11205. * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
  11206. * arguments: (value, index, collection).
  11207. *
  11208. * If a property name is provided for `iteratee` the created `_.property`
  11209. * style callback returns the property value of the given element.
  11210. *
  11211. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  11212. * style callback returns `true` for elements that have a matching property
  11213. * value, else `false`.
  11214. *
  11215. * If an object is provided for `iteratee` the created `_.matches` style
  11216. * callback returns `true` for elements that have the properties of the given
  11217. * object, else `false`.
  11218. *
  11219. * @static
  11220. * @memberOf _
  11221. * @category Math
  11222. * @param {Array|Object|string} collection The collection to iterate over.
  11223. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  11224. * @param {*} [thisArg] The `this` binding of `iteratee`.
  11225. * @returns {*} Returns the maximum value.
  11226. * @example
  11227. *
  11228. * _.max([4, 2, 8, 6]);
  11229. * // => 8
  11230. *
  11231. * _.max([]);
  11232. * // => -Infinity
  11233. *
  11234. * var users = [
  11235. * { 'user': 'barney', 'age': 36 },
  11236. * { 'user': 'fred', 'age': 40 }
  11237. * ];
  11238. *
  11239. * _.max(users, function(chr) {
  11240. * return chr.age;
  11241. * });
  11242. * // => { 'user': 'fred', 'age': 40 }
  11243. *
  11244. * // using the `_.property` callback shorthand
  11245. * _.max(users, 'age');
  11246. * // => { 'user': 'fred', 'age': 40 }
  11247. */
  11248. var max = createExtremum(gt, NEGATIVE_INFINITY);
  11249. /**
  11250. * Gets the minimum value of `collection`. If `collection` is empty or falsey
  11251. * `Infinity` is returned. If an iteratee function is provided it's invoked
  11252. * for each value in `collection` to generate the criterion by which the value
  11253. * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
  11254. * arguments: (value, index, collection).
  11255. *
  11256. * If a property name is provided for `iteratee` the created `_.property`
  11257. * style callback returns the property value of the given element.
  11258. *
  11259. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  11260. * style callback returns `true` for elements that have a matching property
  11261. * value, else `false`.
  11262. *
  11263. * If an object is provided for `iteratee` the created `_.matches` style
  11264. * callback returns `true` for elements that have the properties of the given
  11265. * object, else `false`.
  11266. *
  11267. * @static
  11268. * @memberOf _
  11269. * @category Math
  11270. * @param {Array|Object|string} collection The collection to iterate over.
  11271. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  11272. * @param {*} [thisArg] The `this` binding of `iteratee`.
  11273. * @returns {*} Returns the minimum value.
  11274. * @example
  11275. *
  11276. * _.min([4, 2, 8, 6]);
  11277. * // => 2
  11278. *
  11279. * _.min([]);
  11280. * // => Infinity
  11281. *
  11282. * var users = [
  11283. * { 'user': 'barney', 'age': 36 },
  11284. * { 'user': 'fred', 'age': 40 }
  11285. * ];
  11286. *
  11287. * _.min(users, function(chr) {
  11288. * return chr.age;
  11289. * });
  11290. * // => { 'user': 'barney', 'age': 36 }
  11291. *
  11292. * // using the `_.property` callback shorthand
  11293. * _.min(users, 'age');
  11294. * // => { 'user': 'barney', 'age': 36 }
  11295. */
  11296. var min = createExtremum(lt, POSITIVE_INFINITY);
  11297. /**
  11298. * Calculates `n` rounded to `precision`.
  11299. *
  11300. * @static
  11301. * @memberOf _
  11302. * @category Math
  11303. * @param {number} n The number to round.
  11304. * @param {number} [precision=0] The precision to round to.
  11305. * @returns {number} Returns the rounded number.
  11306. * @example
  11307. *
  11308. * _.round(4.006);
  11309. * // => 4
  11310. *
  11311. * _.round(4.006, 2);
  11312. * // => 4.01
  11313. *
  11314. * _.round(4060, -2);
  11315. * // => 4100
  11316. */
  11317. var round = createRound('round');
  11318. /**
  11319. * Gets the sum of the values in `collection`.
  11320. *
  11321. * @static
  11322. * @memberOf _
  11323. * @category Math
  11324. * @param {Array|Object|string} collection The collection to iterate over.
  11325. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  11326. * @param {*} [thisArg] The `this` binding of `iteratee`.
  11327. * @returns {number} Returns the sum.
  11328. * @example
  11329. *
  11330. * _.sum([4, 6]);
  11331. * // => 10
  11332. *
  11333. * _.sum({ 'a': 4, 'b': 6 });
  11334. * // => 10
  11335. *
  11336. * var objects = [
  11337. * { 'n': 4 },
  11338. * { 'n': 6 }
  11339. * ];
  11340. *
  11341. * _.sum(objects, function(object) {
  11342. * return object.n;
  11343. * });
  11344. * // => 10
  11345. *
  11346. * // using the `_.property` callback shorthand
  11347. * _.sum(objects, 'n');
  11348. * // => 10
  11349. */
  11350. function sum(collection, iteratee, thisArg) {
  11351. if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
  11352. iteratee = undefined;
  11353. }
  11354. iteratee = getCallback(iteratee, thisArg, 3);
  11355. return iteratee.length == 1
  11356. ? arraySum(isArray(collection) ? collection : toIterable(collection), iteratee)
  11357. : baseSum(collection, iteratee);
  11358. }
  11359. /*------------------------------------------------------------------------*/
  11360. // Ensure wrappers are instances of `baseLodash`.
  11361. lodash.prototype = baseLodash.prototype;
  11362. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  11363. LodashWrapper.prototype.constructor = LodashWrapper;
  11364. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  11365. LazyWrapper.prototype.constructor = LazyWrapper;
  11366. // Add functions to the `Map` cache.
  11367. MapCache.prototype['delete'] = mapDelete;
  11368. MapCache.prototype.get = mapGet;
  11369. MapCache.prototype.has = mapHas;
  11370. MapCache.prototype.set = mapSet;
  11371. // Add functions to the `Set` cache.
  11372. SetCache.prototype.push = cachePush;
  11373. // Assign cache to `_.memoize`.
  11374. memoize.Cache = MapCache;
  11375. // Add functions that return wrapped values when chaining.
  11376. lodash.after = after;
  11377. lodash.ary = ary;
  11378. lodash.assign = assign;
  11379. lodash.at = at;
  11380. lodash.before = before;
  11381. lodash.bind = bind;
  11382. lodash.bindAll = bindAll;
  11383. lodash.bindKey = bindKey;
  11384. lodash.callback = callback;
  11385. lodash.chain = chain;
  11386. lodash.chunk = chunk;
  11387. lodash.compact = compact;
  11388. lodash.constant = constant;
  11389. lodash.countBy = countBy;
  11390. lodash.create = create;
  11391. lodash.curry = curry;
  11392. lodash.curryRight = curryRight;
  11393. lodash.debounce = debounce;
  11394. lodash.defaults = defaults;
  11395. lodash.defaultsDeep = defaultsDeep;
  11396. lodash.defer = defer;
  11397. lodash.delay = delay;
  11398. lodash.difference = difference;
  11399. lodash.drop = drop;
  11400. lodash.dropRight = dropRight;
  11401. lodash.dropRightWhile = dropRightWhile;
  11402. lodash.dropWhile = dropWhile;
  11403. lodash.fill = fill;
  11404. lodash.filter = filter;
  11405. lodash.flatten = flatten;
  11406. lodash.flattenDeep = flattenDeep;
  11407. lodash.flow = flow;
  11408. lodash.flowRight = flowRight;
  11409. lodash.forEach = forEach;
  11410. lodash.forEachRight = forEachRight;
  11411. lodash.forIn = forIn;
  11412. lodash.forInRight = forInRight;
  11413. lodash.forOwn = forOwn;
  11414. lodash.forOwnRight = forOwnRight;
  11415. lodash.functions = functions;
  11416. lodash.groupBy = groupBy;
  11417. lodash.indexBy = indexBy;
  11418. lodash.initial = initial;
  11419. lodash.intersection = intersection;
  11420. lodash.invert = invert;
  11421. lodash.invoke = invoke;
  11422. lodash.keys = keys;
  11423. lodash.keysIn = keysIn;
  11424. lodash.map = map;
  11425. lodash.mapKeys = mapKeys;
  11426. lodash.mapValues = mapValues;
  11427. lodash.matches = matches;
  11428. lodash.matchesProperty = matchesProperty;
  11429. lodash.memoize = memoize;
  11430. lodash.merge = merge;
  11431. lodash.method = method;
  11432. lodash.methodOf = methodOf;
  11433. lodash.mixin = mixin;
  11434. lodash.modArgs = modArgs;
  11435. lodash.negate = negate;
  11436. lodash.omit = omit;
  11437. lodash.once = once;
  11438. lodash.pairs = pairs;
  11439. lodash.partial = partial;
  11440. lodash.partialRight = partialRight;
  11441. lodash.partition = partition;
  11442. lodash.pick = pick;
  11443. lodash.pluck = pluck;
  11444. lodash.property = property;
  11445. lodash.propertyOf = propertyOf;
  11446. lodash.pull = pull;
  11447. lodash.pullAt = pullAt;
  11448. lodash.range = range;
  11449. lodash.rearg = rearg;
  11450. lodash.reject = reject;
  11451. lodash.remove = remove;
  11452. lodash.rest = rest;
  11453. lodash.restParam = restParam;
  11454. lodash.set = set;
  11455. lodash.shuffle = shuffle;
  11456. lodash.slice = slice;
  11457. lodash.sortBy = sortBy;
  11458. lodash.sortByAll = sortByAll;
  11459. lodash.sortByOrder = sortByOrder;
  11460. lodash.spread = spread;
  11461. lodash.take = take;
  11462. lodash.takeRight = takeRight;
  11463. lodash.takeRightWhile = takeRightWhile;
  11464. lodash.takeWhile = takeWhile;
  11465. lodash.tap = tap;
  11466. lodash.throttle = throttle;
  11467. lodash.thru = thru;
  11468. lodash.times = times;
  11469. lodash.toArray = toArray;
  11470. lodash.toPlainObject = toPlainObject;
  11471. lodash.transform = transform;
  11472. lodash.union = union;
  11473. lodash.uniq = uniq;
  11474. lodash.unzip = unzip;
  11475. lodash.unzipWith = unzipWith;
  11476. lodash.values = values;
  11477. lodash.valuesIn = valuesIn;
  11478. lodash.where = where;
  11479. lodash.without = without;
  11480. lodash.wrap = wrap;
  11481. lodash.xor = xor;
  11482. lodash.zip = zip;
  11483. lodash.zipObject = zipObject;
  11484. lodash.zipWith = zipWith;
  11485. // Add aliases.
  11486. lodash.backflow = flowRight;
  11487. lodash.collect = map;
  11488. lodash.compose = flowRight;
  11489. lodash.each = forEach;
  11490. lodash.eachRight = forEachRight;
  11491. lodash.extend = assign;
  11492. lodash.iteratee = callback;
  11493. lodash.methods = functions;
  11494. lodash.object = zipObject;
  11495. lodash.select = filter;
  11496. lodash.tail = rest;
  11497. lodash.unique = uniq;
  11498. // Add functions to `lodash.prototype`.
  11499. mixin(lodash, lodash);
  11500. /*------------------------------------------------------------------------*/
  11501. // Add functions that return unwrapped values when chaining.
  11502. lodash.add = add;
  11503. lodash.attempt = attempt;
  11504. lodash.camelCase = camelCase;
  11505. lodash.capitalize = capitalize;
  11506. lodash.ceil = ceil;
  11507. lodash.clone = clone;
  11508. lodash.cloneDeep = cloneDeep;
  11509. lodash.deburr = deburr;
  11510. lodash.endsWith = endsWith;
  11511. lodash.escape = escape;
  11512. lodash.escapeRegExp = escapeRegExp;
  11513. lodash.every = every;
  11514. lodash.find = find;
  11515. lodash.findIndex = findIndex;
  11516. lodash.findKey = findKey;
  11517. lodash.findLast = findLast;
  11518. lodash.findLastIndex = findLastIndex;
  11519. lodash.findLastKey = findLastKey;
  11520. lodash.findWhere = findWhere;
  11521. lodash.first = first;
  11522. lodash.floor = floor;
  11523. lodash.get = get;
  11524. lodash.gt = gt;
  11525. lodash.gte = gte;
  11526. lodash.has = has;
  11527. lodash.identity = identity;
  11528. lodash.includes = includes;
  11529. lodash.indexOf = indexOf;
  11530. lodash.inRange = inRange;
  11531. lodash.isArguments = isArguments;
  11532. lodash.isArray = isArray;
  11533. lodash.isBoolean = isBoolean;
  11534. lodash.isDate = isDate;
  11535. lodash.isElement = isElement;
  11536. lodash.isEmpty = isEmpty;
  11537. lodash.isEqual = isEqual;
  11538. lodash.isError = isError;
  11539. lodash.isFinite = isFinite;
  11540. lodash.isFunction = isFunction;
  11541. lodash.isMatch = isMatch;
  11542. lodash.isNaN = isNaN;
  11543. lodash.isNative = isNative;
  11544. lodash.isNull = isNull;
  11545. lodash.isNumber = isNumber;
  11546. lodash.isObject = isObject;
  11547. lodash.isPlainObject = isPlainObject;
  11548. lodash.isRegExp = isRegExp;
  11549. lodash.isString = isString;
  11550. lodash.isTypedArray = isTypedArray;
  11551. lodash.isUndefined = isUndefined;
  11552. lodash.kebabCase = kebabCase;
  11553. lodash.last = last;
  11554. lodash.lastIndexOf = lastIndexOf;
  11555. lodash.lt = lt;
  11556. lodash.lte = lte;
  11557. lodash.max = max;
  11558. lodash.min = min;
  11559. lodash.noConflict = noConflict;
  11560. lodash.noop = noop;
  11561. lodash.now = now;
  11562. lodash.pad = pad;
  11563. lodash.padLeft = padLeft;
  11564. lodash.padRight = padRight;
  11565. lodash.parseInt = parseInt;
  11566. lodash.random = random;
  11567. lodash.reduce = reduce;
  11568. lodash.reduceRight = reduceRight;
  11569. lodash.repeat = repeat;
  11570. lodash.result = result;
  11571. lodash.round = round;
  11572. lodash.runInContext = runInContext;
  11573. lodash.size = size;
  11574. lodash.snakeCase = snakeCase;
  11575. lodash.some = some;
  11576. lodash.sortedIndex = sortedIndex;
  11577. lodash.sortedLastIndex = sortedLastIndex;
  11578. lodash.startCase = startCase;
  11579. lodash.startsWith = startsWith;
  11580. lodash.sum = sum;
  11581. lodash.template = template;
  11582. lodash.trim = trim;
  11583. lodash.trimLeft = trimLeft;
  11584. lodash.trimRight = trimRight;
  11585. lodash.trunc = trunc;
  11586. lodash.unescape = unescape;
  11587. lodash.uniqueId = uniqueId;
  11588. lodash.words = words;
  11589. // Add aliases.
  11590. lodash.all = every;
  11591. lodash.any = some;
  11592. lodash.contains = includes;
  11593. lodash.eq = isEqual;
  11594. lodash.detect = find;
  11595. lodash.foldl = reduce;
  11596. lodash.foldr = reduceRight;
  11597. lodash.head = first;
  11598. lodash.include = includes;
  11599. lodash.inject = reduce;
  11600. mixin(lodash, (function() {
  11601. var source = {};
  11602. baseForOwn(lodash, function(func, methodName) {
  11603. if (!lodash.prototype[methodName]) {
  11604. source[methodName] = func;
  11605. }
  11606. });
  11607. return source;
  11608. }()), false);
  11609. /*------------------------------------------------------------------------*/
  11610. // Add functions capable of returning wrapped and unwrapped values when chaining.
  11611. lodash.sample = sample;
  11612. lodash.prototype.sample = function(n) {
  11613. if (!this.__chain__ && n == null) {
  11614. return sample(this.value());
  11615. }
  11616. return this.thru(function(value) {
  11617. return sample(value, n);
  11618. });
  11619. };
  11620. /*------------------------------------------------------------------------*/
  11621. /**
  11622. * The semantic version number.
  11623. *
  11624. * @static
  11625. * @memberOf _
  11626. * @type string
  11627. */
  11628. lodash.VERSION = VERSION;
  11629. // Assign default placeholders.
  11630. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  11631. lodash[methodName].placeholder = lodash;
  11632. });
  11633. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  11634. arrayEach(['drop', 'take'], function(methodName, index) {
  11635. LazyWrapper.prototype[methodName] = function(n) {
  11636. var filtered = this.__filtered__;
  11637. if (filtered && !index) {
  11638. return new LazyWrapper(this);
  11639. }
  11640. n = n == null ? 1 : nativeMax(nativeFloor(n) || 0, 0);
  11641. var result = this.clone();
  11642. if (filtered) {
  11643. result.__takeCount__ = nativeMin(result.__takeCount__, n);
  11644. } else {
  11645. result.__views__.push({ 'size': n, 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') });
  11646. }
  11647. return result;
  11648. };
  11649. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  11650. return this.reverse()[methodName](n).reverse();
  11651. };
  11652. });
  11653. // Add `LazyWrapper` methods that accept an `iteratee` value.
  11654. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  11655. var type = index + 1,
  11656. isFilter = type != LAZY_MAP_FLAG;
  11657. LazyWrapper.prototype[methodName] = function(iteratee, thisArg) {
  11658. var result = this.clone();
  11659. result.__iteratees__.push({ 'iteratee': getCallback(iteratee, thisArg, 1), 'type': type });
  11660. result.__filtered__ = result.__filtered__ || isFilter;
  11661. return result;
  11662. };
  11663. });
  11664. // Add `LazyWrapper` methods for `_.first` and `_.last`.
  11665. arrayEach(['first', 'last'], function(methodName, index) {
  11666. var takeName = 'take' + (index ? 'Right' : '');
  11667. LazyWrapper.prototype[methodName] = function() {
  11668. return this[takeName](1).value()[0];
  11669. };
  11670. });
  11671. // Add `LazyWrapper` methods for `_.initial` and `_.rest`.
  11672. arrayEach(['initial', 'rest'], function(methodName, index) {
  11673. var dropName = 'drop' + (index ? '' : 'Right');
  11674. LazyWrapper.prototype[methodName] = function() {
  11675. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  11676. };
  11677. });
  11678. // Add `LazyWrapper` methods for `_.pluck` and `_.where`.
  11679. arrayEach(['pluck', 'where'], function(methodName, index) {
  11680. var operationName = index ? 'filter' : 'map',
  11681. createCallback = index ? baseMatches : property;
  11682. LazyWrapper.prototype[methodName] = function(value) {
  11683. return this[operationName](createCallback(value));
  11684. };
  11685. });
  11686. LazyWrapper.prototype.compact = function() {
  11687. return this.filter(identity);
  11688. };
  11689. LazyWrapper.prototype.reject = function(predicate, thisArg) {
  11690. predicate = getCallback(predicate, thisArg, 1);
  11691. return this.filter(function(value) {
  11692. return !predicate(value);
  11693. });
  11694. };
  11695. LazyWrapper.prototype.slice = function(start, end) {
  11696. start = start == null ? 0 : (+start || 0);
  11697. var result = this;
  11698. if (result.__filtered__ && (start > 0 || end < 0)) {
  11699. return new LazyWrapper(result);
  11700. }
  11701. if (start < 0) {
  11702. result = result.takeRight(-start);
  11703. } else if (start) {
  11704. result = result.drop(start);
  11705. }
  11706. if (end !== undefined) {
  11707. end = (+end || 0);
  11708. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  11709. }
  11710. return result;
  11711. };
  11712. LazyWrapper.prototype.takeRightWhile = function(predicate, thisArg) {
  11713. return this.reverse().takeWhile(predicate, thisArg).reverse();
  11714. };
  11715. LazyWrapper.prototype.toArray = function() {
  11716. return this.take(POSITIVE_INFINITY);
  11717. };
  11718. // Add `LazyWrapper` methods to `lodash.prototype`.
  11719. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  11720. var checkIteratee = /^(?:filter|map|reject)|While$/.test(methodName),
  11721. retUnwrapped = /^(?:first|last)$/.test(methodName),
  11722. lodashFunc = lodash[retUnwrapped ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName];
  11723. if (!lodashFunc) {
  11724. return;
  11725. }
  11726. lodash.prototype[methodName] = function() {
  11727. var args = retUnwrapped ? [1] : arguments,
  11728. chainAll = this.__chain__,
  11729. value = this.__wrapped__,
  11730. isHybrid = !!this.__actions__.length,
  11731. isLazy = value instanceof LazyWrapper,
  11732. iteratee = args[0],
  11733. useLazy = isLazy || isArray(value);
  11734. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  11735. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  11736. isLazy = useLazy = false;
  11737. }
  11738. var interceptor = function(value) {
  11739. return (retUnwrapped && chainAll)
  11740. ? lodashFunc(value, 1)[0]
  11741. : lodashFunc.apply(undefined, arrayPush([value], args));
  11742. };
  11743. var action = { 'func': thru, 'args': [interceptor], 'thisArg': undefined },
  11744. onlyLazy = isLazy && !isHybrid;
  11745. if (retUnwrapped && !chainAll) {
  11746. if (onlyLazy) {
  11747. value = value.clone();
  11748. value.__actions__.push(action);
  11749. return func.call(value);
  11750. }
  11751. return lodashFunc.call(undefined, this.value())[0];
  11752. }
  11753. if (!retUnwrapped && useLazy) {
  11754. value = onlyLazy ? value : new LazyWrapper(this);
  11755. var result = func.apply(value, args);
  11756. result.__actions__.push(action);
  11757. return new LodashWrapper(result, chainAll);
  11758. }
  11759. return this.thru(interceptor);
  11760. };
  11761. });
  11762. // Add `Array` and `String` methods to `lodash.prototype`.
  11763. arrayEach(['join', 'pop', 'push', 'replace', 'shift', 'sort', 'splice', 'split', 'unshift'], function(methodName) {
  11764. var protoFunc = (/^(?:replace|split)$/.test(methodName) ? stringProto : arrayProto)[methodName],
  11765. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  11766. fixObjects = !support.spliceObjects && /^(?:pop|shift|splice)$/.test(methodName),
  11767. retUnwrapped = /^(?:join|pop|replace|shift)$/.test(methodName);
  11768. // Avoid array-like object bugs with `Array#shift` and `Array#splice` in
  11769. // IE < 9, Firefox < 10, and RingoJS.
  11770. var func = !fixObjects ? protoFunc : function() {
  11771. var result = protoFunc.apply(this, arguments);
  11772. if (this.length === 0) {
  11773. delete this[0];
  11774. }
  11775. return result;
  11776. };
  11777. lodash.prototype[methodName] = function() {
  11778. var args = arguments;
  11779. if (retUnwrapped && !this.__chain__) {
  11780. return func.apply(this.value(), args);
  11781. }
  11782. return this[chainName](function(value) {
  11783. return func.apply(value, args);
  11784. });
  11785. };
  11786. });
  11787. // Map minified function names to their real names.
  11788. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  11789. var lodashFunc = lodash[methodName];
  11790. if (lodashFunc) {
  11791. var key = (lodashFunc.name + ''),
  11792. names = realNames[key] || (realNames[key] = []);
  11793. names.push({ 'name': methodName, 'func': lodashFunc });
  11794. }
  11795. });
  11796. realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': undefined }];
  11797. // Add functions to the lazy wrapper.
  11798. LazyWrapper.prototype.clone = lazyClone;
  11799. LazyWrapper.prototype.reverse = lazyReverse;
  11800. LazyWrapper.prototype.value = lazyValue;
  11801. // Add chaining functions to the `lodash` wrapper.
  11802. lodash.prototype.chain = wrapperChain;
  11803. lodash.prototype.commit = wrapperCommit;
  11804. lodash.prototype.concat = wrapperConcat;
  11805. lodash.prototype.plant = wrapperPlant;
  11806. lodash.prototype.reverse = wrapperReverse;
  11807. lodash.prototype.toString = wrapperToString;
  11808. lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  11809. // Add function aliases to the `lodash` wrapper.
  11810. lodash.prototype.collect = lodash.prototype.map;
  11811. lodash.prototype.head = lodash.prototype.first;
  11812. lodash.prototype.select = lodash.prototype.filter;
  11813. lodash.prototype.tail = lodash.prototype.rest;
  11814. return lodash;
  11815. }
  11816. /*--------------------------------------------------------------------------*/
  11817. // Export lodash.
  11818. var _ = runInContext();
  11819. // Some AMD build optimizers like r.js check for condition patterns like the following:
  11820. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  11821. // Expose lodash to the global object when an AMD loader is present to avoid
  11822. // errors in cases where lodash is loaded by a script tag and not intended
  11823. // as an AMD module. See http://requirejs.org/docs/errors.html#mismatch for
  11824. // more details.
  11825. root._ = _;
  11826. // Define as an anonymous module so, through path mapping, it can be
  11827. // referenced as the "underscore" module.
  11828. define(function() {
  11829. return _;
  11830. });
  11831. }
  11832. // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
  11833. else if (freeExports && freeModule) {
  11834. // Export for Node.js or RingoJS.
  11835. if (moduleExports) {
  11836. (freeModule.exports = _)._ = _;
  11837. }
  11838. // Export for Rhino with CommonJS support.
  11839. else {
  11840. freeExports._ = _;
  11841. }
  11842. }
  11843. else {
  11844. // Export for a browser or Rhino.
  11845. root._ = _;
  11846. }
  11847. }.call(this));