a zip code crypto-currency system good for red ONLY

lodash.js 527KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106
  1. /**
  2. * @license
  3. * Lodash <https://lodash.com/>
  4. * Copyright JS Foundation and other contributors <https://js.foundation/>
  5. * Released under MIT license <https://lodash.com/license>
  6. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  7. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  8. */
  9. ;(function() {
  10. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  11. var undefined;
  12. /** Used as the semantic version number. */
  13. var VERSION = '4.17.10';
  14. /** Used as the size to enable large array optimizations. */
  15. var LARGE_ARRAY_SIZE = 200;
  16. /** Error message constants. */
  17. var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
  18. FUNC_ERROR_TEXT = 'Expected a function';
  19. /** Used to stand-in for `undefined` hash values. */
  20. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  21. /** Used as the maximum memoize cache size. */
  22. var MAX_MEMOIZE_SIZE = 500;
  23. /** Used as the internal argument placeholder. */
  24. var PLACEHOLDER = '__lodash_placeholder__';
  25. /** Used to compose bitmasks for cloning. */
  26. var CLONE_DEEP_FLAG = 1,
  27. CLONE_FLAT_FLAG = 2,
  28. CLONE_SYMBOLS_FLAG = 4;
  29. /** Used to compose bitmasks for value comparisons. */
  30. var COMPARE_PARTIAL_FLAG = 1,
  31. COMPARE_UNORDERED_FLAG = 2;
  32. /** Used to compose bitmasks for function metadata. */
  33. var WRAP_BIND_FLAG = 1,
  34. WRAP_BIND_KEY_FLAG = 2,
  35. WRAP_CURRY_BOUND_FLAG = 4,
  36. WRAP_CURRY_FLAG = 8,
  37. WRAP_CURRY_RIGHT_FLAG = 16,
  38. WRAP_PARTIAL_FLAG = 32,
  39. WRAP_PARTIAL_RIGHT_FLAG = 64,
  40. WRAP_ARY_FLAG = 128,
  41. WRAP_REARG_FLAG = 256,
  42. WRAP_FLIP_FLAG = 512;
  43. /** Used as default options for `_.truncate`. */
  44. var DEFAULT_TRUNC_LENGTH = 30,
  45. DEFAULT_TRUNC_OMISSION = '...';
  46. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  47. var HOT_COUNT = 800,
  48. HOT_SPAN = 16;
  49. /** Used to indicate the type of lazy iteratees. */
  50. var LAZY_FILTER_FLAG = 1,
  51. LAZY_MAP_FLAG = 2,
  52. LAZY_WHILE_FLAG = 3;
  53. /** Used as references for various `Number` constants. */
  54. var INFINITY = 1 / 0,
  55. MAX_SAFE_INTEGER = 9007199254740991,
  56. MAX_INTEGER = 1.7976931348623157e+308,
  57. NAN = 0 / 0;
  58. /** Used as references for the maximum length and index of an array. */
  59. var MAX_ARRAY_LENGTH = 4294967295,
  60. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  61. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  62. /** Used to associate wrap methods with their bit flags. */
  63. var wrapFlags = [
  64. ['ary', WRAP_ARY_FLAG],
  65. ['bind', WRAP_BIND_FLAG],
  66. ['bindKey', WRAP_BIND_KEY_FLAG],
  67. ['curry', WRAP_CURRY_FLAG],
  68. ['curryRight', WRAP_CURRY_RIGHT_FLAG],
  69. ['flip', WRAP_FLIP_FLAG],
  70. ['partial', WRAP_PARTIAL_FLAG],
  71. ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
  72. ['rearg', WRAP_REARG_FLAG]
  73. ];
  74. /** `Object#toString` result references. */
  75. var argsTag = '[object Arguments]',
  76. arrayTag = '[object Array]',
  77. asyncTag = '[object AsyncFunction]',
  78. boolTag = '[object Boolean]',
  79. dateTag = '[object Date]',
  80. domExcTag = '[object DOMException]',
  81. errorTag = '[object Error]',
  82. funcTag = '[object Function]',
  83. genTag = '[object GeneratorFunction]',
  84. mapTag = '[object Map]',
  85. numberTag = '[object Number]',
  86. nullTag = '[object Null]',
  87. objectTag = '[object Object]',
  88. promiseTag = '[object Promise]',
  89. proxyTag = '[object Proxy]',
  90. regexpTag = '[object RegExp]',
  91. setTag = '[object Set]',
  92. stringTag = '[object String]',
  93. symbolTag = '[object Symbol]',
  94. undefinedTag = '[object Undefined]',
  95. weakMapTag = '[object WeakMap]',
  96. weakSetTag = '[object WeakSet]';
  97. var arrayBufferTag = '[object ArrayBuffer]',
  98. dataViewTag = '[object DataView]',
  99. float32Tag = '[object Float32Array]',
  100. float64Tag = '[object Float64Array]',
  101. int8Tag = '[object Int8Array]',
  102. int16Tag = '[object Int16Array]',
  103. int32Tag = '[object Int32Array]',
  104. uint8Tag = '[object Uint8Array]',
  105. uint8ClampedTag = '[object Uint8ClampedArray]',
  106. uint16Tag = '[object Uint16Array]',
  107. uint32Tag = '[object Uint32Array]';
  108. /** Used to match empty string literals in compiled template source. */
  109. var reEmptyStringLeading = /\b__p \+= '';/g,
  110. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  111. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  112. /** Used to match HTML entities and HTML characters. */
  113. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
  114. reUnescapedHtml = /[&<>"']/g,
  115. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  116. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  117. /** Used to match template delimiters. */
  118. var reEscape = /<%-([\s\S]+?)%>/g,
  119. reEvaluate = /<%([\s\S]+?)%>/g,
  120. reInterpolate = /<%=([\s\S]+?)%>/g;
  121. /** Used to match property names within property paths. */
  122. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  123. reIsPlainProp = /^\w*$/,
  124. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  125. /**
  126. * Used to match `RegExp`
  127. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  128. */
  129. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  130. reHasRegExpChar = RegExp(reRegExpChar.source);
  131. /** Used to match leading and trailing whitespace. */
  132. var reTrim = /^\s+|\s+$/g,
  133. reTrimStart = /^\s+/,
  134. reTrimEnd = /\s+$/;
  135. /** Used to match wrap detail comments. */
  136. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  137. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  138. reSplitDetails = /,? & /;
  139. /** Used to match words composed of alphanumeric characters. */
  140. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  141. /** Used to match backslashes in property paths. */
  142. var reEscapeChar = /\\(\\)?/g;
  143. /**
  144. * Used to match
  145. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  146. */
  147. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  148. /** Used to match `RegExp` flags from their coerced string values. */
  149. var reFlags = /\w*$/;
  150. /** Used to detect bad signed hexadecimal string values. */
  151. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  152. /** Used to detect binary string values. */
  153. var reIsBinary = /^0b[01]+$/i;
  154. /** Used to detect host constructors (Safari). */
  155. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  156. /** Used to detect octal string values. */
  157. var reIsOctal = /^0o[0-7]+$/i;
  158. /** Used to detect unsigned integer values. */
  159. var reIsUint = /^(?:0|[1-9]\d*)$/;
  160. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  161. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  162. /** Used to ensure capturing order of template delimiters. */
  163. var reNoMatch = /($^)/;
  164. /** Used to match unescaped characters in compiled string literals. */
  165. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  166. /** Used to compose unicode character classes. */
  167. var rsAstralRange = '\\ud800-\\udfff',
  168. rsComboMarksRange = '\\u0300-\\u036f',
  169. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  170. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  171. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  172. rsDingbatRange = '\\u2700-\\u27bf',
  173. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  174. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  175. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  176. rsPunctuationRange = '\\u2000-\\u206f',
  177. rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
  178. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  179. rsVarRange = '\\ufe0e\\ufe0f',
  180. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  181. /** Used to compose unicode capture groups. */
  182. var rsApos = "['\u2019]",
  183. rsAstral = '[' + rsAstralRange + ']',
  184. rsBreak = '[' + rsBreakRange + ']',
  185. rsCombo = '[' + rsComboRange + ']',
  186. rsDigits = '\\d+',
  187. rsDingbat = '[' + rsDingbatRange + ']',
  188. rsLower = '[' + rsLowerRange + ']',
  189. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  190. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  191. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  192. rsNonAstral = '[^' + rsAstralRange + ']',
  193. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  194. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  195. rsUpper = '[' + rsUpperRange + ']',
  196. rsZWJ = '\\u200d';
  197. /** Used to compose unicode regexes. */
  198. var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
  199. rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
  200. rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  201. rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  202. reOptMod = rsModifier + '?',
  203. rsOptVar = '[' + rsVarRange + ']?',
  204. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  205. rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
  206. rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
  207. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  208. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  209. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  210. /** Used to match apostrophes. */
  211. var reApos = RegExp(rsApos, 'g');
  212. /**
  213. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  214. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  215. */
  216. var reComboMark = RegExp(rsCombo, 'g');
  217. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  218. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  219. /** Used to match complex or compound words. */
  220. var reUnicodeWord = RegExp([
  221. rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  222. rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
  223. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  224. rsUpper + '+' + rsOptContrUpper,
  225. rsOrdUpper,
  226. rsOrdLower,
  227. rsDigits,
  228. rsEmoji
  229. ].join('|'), 'g');
  230. /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
  231. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  232. /** Used to detect strings that need a more robust regexp to match words. */
  233. var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
  234. /** Used to assign default `context` object properties. */
  235. var contextProps = [
  236. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  237. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  238. 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  239. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  240. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  241. ];
  242. /** Used to make template sourceURLs easier to identify. */
  243. var templateCounter = -1;
  244. /** Used to identify `toStringTag` values of typed arrays. */
  245. var typedArrayTags = {};
  246. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  247. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  248. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  249. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  250. typedArrayTags[uint32Tag] = true;
  251. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  252. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  253. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  254. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  255. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  256. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  257. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  258. typedArrayTags[weakMapTag] = false;
  259. /** Used to identify `toStringTag` values supported by `_.clone`. */
  260. var cloneableTags = {};
  261. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  262. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  263. cloneableTags[boolTag] = cloneableTags[dateTag] =
  264. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  265. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  266. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  267. cloneableTags[numberTag] = cloneableTags[objectTag] =
  268. cloneableTags[regexpTag] = cloneableTags[setTag] =
  269. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  270. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  271. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  272. cloneableTags[errorTag] = cloneableTags[funcTag] =
  273. cloneableTags[weakMapTag] = false;
  274. /** Used to map Latin Unicode letters to basic Latin letters. */
  275. var deburredLetters = {
  276. // Latin-1 Supplement block.
  277. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  278. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  279. '\xc7': 'C', '\xe7': 'c',
  280. '\xd0': 'D', '\xf0': 'd',
  281. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  282. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  283. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  284. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  285. '\xd1': 'N', '\xf1': 'n',
  286. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  287. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  288. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  289. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  290. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  291. '\xc6': 'Ae', '\xe6': 'ae',
  292. '\xde': 'Th', '\xfe': 'th',
  293. '\xdf': 'ss',
  294. // Latin Extended-A block.
  295. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  296. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  297. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  298. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  299. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  300. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  301. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  302. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  303. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  304. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  305. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  306. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  307. '\u0134': 'J', '\u0135': 'j',
  308. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  309. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  310. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  311. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  312. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  313. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  314. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  315. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  316. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  317. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  318. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  319. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  320. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  321. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  322. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  323. '\u0174': 'W', '\u0175': 'w',
  324. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  325. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  326. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  327. '\u0132': 'IJ', '\u0133': 'ij',
  328. '\u0152': 'Oe', '\u0153': 'oe',
  329. '\u0149': "'n", '\u017f': 's'
  330. };
  331. /** Used to map characters to HTML entities. */
  332. var htmlEscapes = {
  333. '&': '&amp;',
  334. '<': '&lt;',
  335. '>': '&gt;',
  336. '"': '&quot;',
  337. "'": '&#39;'
  338. };
  339. /** Used to map HTML entities to characters. */
  340. var htmlUnescapes = {
  341. '&amp;': '&',
  342. '&lt;': '<',
  343. '&gt;': '>',
  344. '&quot;': '"',
  345. '&#39;': "'"
  346. };
  347. /** Used to escape characters for inclusion in compiled string literals. */
  348. var stringEscapes = {
  349. '\\': '\\',
  350. "'": "'",
  351. '\n': 'n',
  352. '\r': 'r',
  353. '\u2028': 'u2028',
  354. '\u2029': 'u2029'
  355. };
  356. /** Built-in method references without a dependency on `root`. */
  357. var freeParseFloat = parseFloat,
  358. freeParseInt = parseInt;
  359. /** Detect free variable `global` from Node.js. */
  360. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  361. /** Detect free variable `self`. */
  362. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  363. /** Used as a reference to the global object. */
  364. var root = freeGlobal || freeSelf || Function('return this')();
  365. /** Detect free variable `exports`. */
  366. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  367. /** Detect free variable `module`. */
  368. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  369. /** Detect the popular CommonJS extension `module.exports`. */
  370. var moduleExports = freeModule && freeModule.exports === freeExports;
  371. /** Detect free variable `process` from Node.js. */
  372. var freeProcess = moduleExports && freeGlobal.process;
  373. /** Used to access faster Node.js helpers. */
  374. var nodeUtil = (function() {
  375. try {
  376. // Use `util.types` for Node.js 10+.
  377. var types = freeModule && freeModule.require && freeModule.require('util').types;
  378. if (types) {
  379. return types;
  380. }
  381. // Legacy `process.binding('util')` for Node.js < 10.
  382. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  383. } catch (e) {}
  384. }());
  385. /* Node.js helper references. */
  386. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  387. nodeIsDate = nodeUtil && nodeUtil.isDate,
  388. nodeIsMap = nodeUtil && nodeUtil.isMap,
  389. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  390. nodeIsSet = nodeUtil && nodeUtil.isSet,
  391. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  392. /*--------------------------------------------------------------------------*/
  393. /**
  394. * A faster alternative to `Function#apply`, this function invokes `func`
  395. * with the `this` binding of `thisArg` and the arguments of `args`.
  396. *
  397. * @private
  398. * @param {Function} func The function to invoke.
  399. * @param {*} thisArg The `this` binding of `func`.
  400. * @param {Array} args The arguments to invoke `func` with.
  401. * @returns {*} Returns the result of `func`.
  402. */
  403. function apply(func, thisArg, args) {
  404. switch (args.length) {
  405. case 0: return func.call(thisArg);
  406. case 1: return func.call(thisArg, args[0]);
  407. case 2: return func.call(thisArg, args[0], args[1]);
  408. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  409. }
  410. return func.apply(thisArg, args);
  411. }
  412. /**
  413. * A specialized version of `baseAggregator` for arrays.
  414. *
  415. * @private
  416. * @param {Array} [array] The array to iterate over.
  417. * @param {Function} setter The function to set `accumulator` values.
  418. * @param {Function} iteratee The iteratee to transform keys.
  419. * @param {Object} accumulator The initial aggregated object.
  420. * @returns {Function} Returns `accumulator`.
  421. */
  422. function arrayAggregator(array, setter, iteratee, accumulator) {
  423. var index = -1,
  424. length = array == null ? 0 : array.length;
  425. while (++index < length) {
  426. var value = array[index];
  427. setter(accumulator, value, iteratee(value), array);
  428. }
  429. return accumulator;
  430. }
  431. /**
  432. * A specialized version of `_.forEach` for arrays without support for
  433. * iteratee shorthands.
  434. *
  435. * @private
  436. * @param {Array} [array] The array to iterate over.
  437. * @param {Function} iteratee The function invoked per iteration.
  438. * @returns {Array} Returns `array`.
  439. */
  440. function arrayEach(array, iteratee) {
  441. var index = -1,
  442. length = array == null ? 0 : array.length;
  443. while (++index < length) {
  444. if (iteratee(array[index], index, array) === false) {
  445. break;
  446. }
  447. }
  448. return array;
  449. }
  450. /**
  451. * A specialized version of `_.forEachRight` for arrays without support for
  452. * iteratee shorthands.
  453. *
  454. * @private
  455. * @param {Array} [array] The array to iterate over.
  456. * @param {Function} iteratee The function invoked per iteration.
  457. * @returns {Array} Returns `array`.
  458. */
  459. function arrayEachRight(array, iteratee) {
  460. var length = array == null ? 0 : array.length;
  461. while (length--) {
  462. if (iteratee(array[length], length, array) === false) {
  463. break;
  464. }
  465. }
  466. return array;
  467. }
  468. /**
  469. * A specialized version of `_.every` for arrays without support for
  470. * iteratee shorthands.
  471. *
  472. * @private
  473. * @param {Array} [array] The array to iterate over.
  474. * @param {Function} predicate The function invoked per iteration.
  475. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  476. * else `false`.
  477. */
  478. function arrayEvery(array, predicate) {
  479. var index = -1,
  480. length = array == null ? 0 : array.length;
  481. while (++index < length) {
  482. if (!predicate(array[index], index, array)) {
  483. return false;
  484. }
  485. }
  486. return true;
  487. }
  488. /**
  489. * A specialized version of `_.filter` for arrays without support for
  490. * iteratee shorthands.
  491. *
  492. * @private
  493. * @param {Array} [array] The array to iterate over.
  494. * @param {Function} predicate The function invoked per iteration.
  495. * @returns {Array} Returns the new filtered array.
  496. */
  497. function arrayFilter(array, predicate) {
  498. var index = -1,
  499. length = array == null ? 0 : array.length,
  500. resIndex = 0,
  501. result = [];
  502. while (++index < length) {
  503. var value = array[index];
  504. if (predicate(value, index, array)) {
  505. result[resIndex++] = value;
  506. }
  507. }
  508. return result;
  509. }
  510. /**
  511. * A specialized version of `_.includes` for arrays without support for
  512. * specifying an index to search from.
  513. *
  514. * @private
  515. * @param {Array} [array] The array to inspect.
  516. * @param {*} target The value to search for.
  517. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  518. */
  519. function arrayIncludes(array, value) {
  520. var length = array == null ? 0 : array.length;
  521. return !!length && baseIndexOf(array, value, 0) > -1;
  522. }
  523. /**
  524. * This function is like `arrayIncludes` except that it accepts a comparator.
  525. *
  526. * @private
  527. * @param {Array} [array] The array to inspect.
  528. * @param {*} target The value to search for.
  529. * @param {Function} comparator The comparator invoked per element.
  530. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  531. */
  532. function arrayIncludesWith(array, value, comparator) {
  533. var index = -1,
  534. length = array == null ? 0 : array.length;
  535. while (++index < length) {
  536. if (comparator(value, array[index])) {
  537. return true;
  538. }
  539. }
  540. return false;
  541. }
  542. /**
  543. * A specialized version of `_.map` for arrays without support for iteratee
  544. * shorthands.
  545. *
  546. * @private
  547. * @param {Array} [array] The array to iterate over.
  548. * @param {Function} iteratee The function invoked per iteration.
  549. * @returns {Array} Returns the new mapped array.
  550. */
  551. function arrayMap(array, iteratee) {
  552. var index = -1,
  553. length = array == null ? 0 : array.length,
  554. result = Array(length);
  555. while (++index < length) {
  556. result[index] = iteratee(array[index], index, array);
  557. }
  558. return result;
  559. }
  560. /**
  561. * Appends the elements of `values` to `array`.
  562. *
  563. * @private
  564. * @param {Array} array The array to modify.
  565. * @param {Array} values The values to append.
  566. * @returns {Array} Returns `array`.
  567. */
  568. function arrayPush(array, values) {
  569. var index = -1,
  570. length = values.length,
  571. offset = array.length;
  572. while (++index < length) {
  573. array[offset + index] = values[index];
  574. }
  575. return array;
  576. }
  577. /**
  578. * A specialized version of `_.reduce` for arrays without support for
  579. * iteratee shorthands.
  580. *
  581. * @private
  582. * @param {Array} [array] The array to iterate over.
  583. * @param {Function} iteratee The function invoked per iteration.
  584. * @param {*} [accumulator] The initial value.
  585. * @param {boolean} [initAccum] Specify using the first element of `array` as
  586. * the initial value.
  587. * @returns {*} Returns the accumulated value.
  588. */
  589. function arrayReduce(array, iteratee, accumulator, initAccum) {
  590. var index = -1,
  591. length = array == null ? 0 : array.length;
  592. if (initAccum && length) {
  593. accumulator = array[++index];
  594. }
  595. while (++index < length) {
  596. accumulator = iteratee(accumulator, array[index], index, array);
  597. }
  598. return accumulator;
  599. }
  600. /**
  601. * A specialized version of `_.reduceRight` for arrays without support for
  602. * iteratee shorthands.
  603. *
  604. * @private
  605. * @param {Array} [array] The array to iterate over.
  606. * @param {Function} iteratee The function invoked per iteration.
  607. * @param {*} [accumulator] The initial value.
  608. * @param {boolean} [initAccum] Specify using the last element of `array` as
  609. * the initial value.
  610. * @returns {*} Returns the accumulated value.
  611. */
  612. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  613. var length = array == null ? 0 : array.length;
  614. if (initAccum && length) {
  615. accumulator = array[--length];
  616. }
  617. while (length--) {
  618. accumulator = iteratee(accumulator, array[length], length, array);
  619. }
  620. return accumulator;
  621. }
  622. /**
  623. * A specialized version of `_.some` for arrays without support for iteratee
  624. * shorthands.
  625. *
  626. * @private
  627. * @param {Array} [array] The array to iterate over.
  628. * @param {Function} predicate The function invoked per iteration.
  629. * @returns {boolean} Returns `true` if any element passes the predicate check,
  630. * else `false`.
  631. */
  632. function arraySome(array, predicate) {
  633. var index = -1,
  634. length = array == null ? 0 : array.length;
  635. while (++index < length) {
  636. if (predicate(array[index], index, array)) {
  637. return true;
  638. }
  639. }
  640. return false;
  641. }
  642. /**
  643. * Gets the size of an ASCII `string`.
  644. *
  645. * @private
  646. * @param {string} string The string inspect.
  647. * @returns {number} Returns the string size.
  648. */
  649. var asciiSize = baseProperty('length');
  650. /**
  651. * Converts an ASCII `string` to an array.
  652. *
  653. * @private
  654. * @param {string} string The string to convert.
  655. * @returns {Array} Returns the converted array.
  656. */
  657. function asciiToArray(string) {
  658. return string.split('');
  659. }
  660. /**
  661. * Splits an ASCII `string` into an array of its words.
  662. *
  663. * @private
  664. * @param {string} The string to inspect.
  665. * @returns {Array} Returns the words of `string`.
  666. */
  667. function asciiWords(string) {
  668. return string.match(reAsciiWord) || [];
  669. }
  670. /**
  671. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  672. * without support for iteratee shorthands, which iterates over `collection`
  673. * using `eachFunc`.
  674. *
  675. * @private
  676. * @param {Array|Object} collection The collection to inspect.
  677. * @param {Function} predicate The function invoked per iteration.
  678. * @param {Function} eachFunc The function to iterate over `collection`.
  679. * @returns {*} Returns the found element or its key, else `undefined`.
  680. */
  681. function baseFindKey(collection, predicate, eachFunc) {
  682. var result;
  683. eachFunc(collection, function(value, key, collection) {
  684. if (predicate(value, key, collection)) {
  685. result = key;
  686. return false;
  687. }
  688. });
  689. return result;
  690. }
  691. /**
  692. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  693. * support for iteratee shorthands.
  694. *
  695. * @private
  696. * @param {Array} array The array to inspect.
  697. * @param {Function} predicate The function invoked per iteration.
  698. * @param {number} fromIndex The index to search from.
  699. * @param {boolean} [fromRight] Specify iterating from right to left.
  700. * @returns {number} Returns the index of the matched value, else `-1`.
  701. */
  702. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  703. var length = array.length,
  704. index = fromIndex + (fromRight ? 1 : -1);
  705. while ((fromRight ? index-- : ++index < length)) {
  706. if (predicate(array[index], index, array)) {
  707. return index;
  708. }
  709. }
  710. return -1;
  711. }
  712. /**
  713. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  714. *
  715. * @private
  716. * @param {Array} array The array to inspect.
  717. * @param {*} value The value to search for.
  718. * @param {number} fromIndex The index to search from.
  719. * @returns {number} Returns the index of the matched value, else `-1`.
  720. */
  721. function baseIndexOf(array, value, fromIndex) {
  722. return value === value
  723. ? strictIndexOf(array, value, fromIndex)
  724. : baseFindIndex(array, baseIsNaN, fromIndex);
  725. }
  726. /**
  727. * This function is like `baseIndexOf` except that it accepts a comparator.
  728. *
  729. * @private
  730. * @param {Array} array The array to inspect.
  731. * @param {*} value The value to search for.
  732. * @param {number} fromIndex The index to search from.
  733. * @param {Function} comparator The comparator invoked per element.
  734. * @returns {number} Returns the index of the matched value, else `-1`.
  735. */
  736. function baseIndexOfWith(array, value, fromIndex, comparator) {
  737. var index = fromIndex - 1,
  738. length = array.length;
  739. while (++index < length) {
  740. if (comparator(array[index], value)) {
  741. return index;
  742. }
  743. }
  744. return -1;
  745. }
  746. /**
  747. * The base implementation of `_.isNaN` without support for number objects.
  748. *
  749. * @private
  750. * @param {*} value The value to check.
  751. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  752. */
  753. function baseIsNaN(value) {
  754. return value !== value;
  755. }
  756. /**
  757. * The base implementation of `_.mean` and `_.meanBy` without support for
  758. * iteratee shorthands.
  759. *
  760. * @private
  761. * @param {Array} array The array to iterate over.
  762. * @param {Function} iteratee The function invoked per iteration.
  763. * @returns {number} Returns the mean.
  764. */
  765. function baseMean(array, iteratee) {
  766. var length = array == null ? 0 : array.length;
  767. return length ? (baseSum(array, iteratee) / length) : NAN;
  768. }
  769. /**
  770. * The base implementation of `_.property` without support for deep paths.
  771. *
  772. * @private
  773. * @param {string} key The key of the property to get.
  774. * @returns {Function} Returns the new accessor function.
  775. */
  776. function baseProperty(key) {
  777. return function(object) {
  778. return object == null ? undefined : object[key];
  779. };
  780. }
  781. /**
  782. * The base implementation of `_.propertyOf` without support for deep paths.
  783. *
  784. * @private
  785. * @param {Object} object The object to query.
  786. * @returns {Function} Returns the new accessor function.
  787. */
  788. function basePropertyOf(object) {
  789. return function(key) {
  790. return object == null ? undefined : object[key];
  791. };
  792. }
  793. /**
  794. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  795. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  796. *
  797. * @private
  798. * @param {Array|Object} collection The collection to iterate over.
  799. * @param {Function} iteratee The function invoked per iteration.
  800. * @param {*} accumulator The initial value.
  801. * @param {boolean} initAccum Specify using the first or last element of
  802. * `collection` as the initial value.
  803. * @param {Function} eachFunc The function to iterate over `collection`.
  804. * @returns {*} Returns the accumulated value.
  805. */
  806. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  807. eachFunc(collection, function(value, index, collection) {
  808. accumulator = initAccum
  809. ? (initAccum = false, value)
  810. : iteratee(accumulator, value, index, collection);
  811. });
  812. return accumulator;
  813. }
  814. /**
  815. * The base implementation of `_.sortBy` which uses `comparer` to define the
  816. * sort order of `array` and replaces criteria objects with their corresponding
  817. * values.
  818. *
  819. * @private
  820. * @param {Array} array The array to sort.
  821. * @param {Function} comparer The function to define sort order.
  822. * @returns {Array} Returns `array`.
  823. */
  824. function baseSortBy(array, comparer) {
  825. var length = array.length;
  826. array.sort(comparer);
  827. while (length--) {
  828. array[length] = array[length].value;
  829. }
  830. return array;
  831. }
  832. /**
  833. * The base implementation of `_.sum` and `_.sumBy` without support for
  834. * iteratee shorthands.
  835. *
  836. * @private
  837. * @param {Array} array The array to iterate over.
  838. * @param {Function} iteratee The function invoked per iteration.
  839. * @returns {number} Returns the sum.
  840. */
  841. function baseSum(array, iteratee) {
  842. var result,
  843. index = -1,
  844. length = array.length;
  845. while (++index < length) {
  846. var current = iteratee(array[index]);
  847. if (current !== undefined) {
  848. result = result === undefined ? current : (result + current);
  849. }
  850. }
  851. return result;
  852. }
  853. /**
  854. * The base implementation of `_.times` without support for iteratee shorthands
  855. * or max array length checks.
  856. *
  857. * @private
  858. * @param {number} n The number of times to invoke `iteratee`.
  859. * @param {Function} iteratee The function invoked per iteration.
  860. * @returns {Array} Returns the array of results.
  861. */
  862. function baseTimes(n, iteratee) {
  863. var index = -1,
  864. result = Array(n);
  865. while (++index < n) {
  866. result[index] = iteratee(index);
  867. }
  868. return result;
  869. }
  870. /**
  871. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  872. * of key-value pairs for `object` corresponding to the property names of `props`.
  873. *
  874. * @private
  875. * @param {Object} object The object to query.
  876. * @param {Array} props The property names to get values for.
  877. * @returns {Object} Returns the key-value pairs.
  878. */
  879. function baseToPairs(object, props) {
  880. return arrayMap(props, function(key) {
  881. return [key, object[key]];
  882. });
  883. }
  884. /**
  885. * The base implementation of `_.unary` without support for storing metadata.
  886. *
  887. * @private
  888. * @param {Function} func The function to cap arguments for.
  889. * @returns {Function} Returns the new capped function.
  890. */
  891. function baseUnary(func) {
  892. return function(value) {
  893. return func(value);
  894. };
  895. }
  896. /**
  897. * The base implementation of `_.values` and `_.valuesIn` which creates an
  898. * array of `object` property values corresponding to the property names
  899. * of `props`.
  900. *
  901. * @private
  902. * @param {Object} object The object to query.
  903. * @param {Array} props The property names to get values for.
  904. * @returns {Object} Returns the array of property values.
  905. */
  906. function baseValues(object, props) {
  907. return arrayMap(props, function(key) {
  908. return object[key];
  909. });
  910. }
  911. /**
  912. * Checks if a `cache` value for `key` exists.
  913. *
  914. * @private
  915. * @param {Object} cache The cache to query.
  916. * @param {string} key The key of the entry to check.
  917. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  918. */
  919. function cacheHas(cache, key) {
  920. return cache.has(key);
  921. }
  922. /**
  923. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  924. * that is not found in the character symbols.
  925. *
  926. * @private
  927. * @param {Array} strSymbols The string symbols to inspect.
  928. * @param {Array} chrSymbols The character symbols to find.
  929. * @returns {number} Returns the index of the first unmatched string symbol.
  930. */
  931. function charsStartIndex(strSymbols, chrSymbols) {
  932. var index = -1,
  933. length = strSymbols.length;
  934. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  935. return index;
  936. }
  937. /**
  938. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  939. * that is not found in the character symbols.
  940. *
  941. * @private
  942. * @param {Array} strSymbols The string symbols to inspect.
  943. * @param {Array} chrSymbols The character symbols to find.
  944. * @returns {number} Returns the index of the last unmatched string symbol.
  945. */
  946. function charsEndIndex(strSymbols, chrSymbols) {
  947. var index = strSymbols.length;
  948. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  949. return index;
  950. }
  951. /**
  952. * Gets the number of `placeholder` occurrences in `array`.
  953. *
  954. * @private
  955. * @param {Array} array The array to inspect.
  956. * @param {*} placeholder The placeholder to search for.
  957. * @returns {number} Returns the placeholder count.
  958. */
  959. function countHolders(array, placeholder) {
  960. var length = array.length,
  961. result = 0;
  962. while (length--) {
  963. if (array[length] === placeholder) {
  964. ++result;
  965. }
  966. }
  967. return result;
  968. }
  969. /**
  970. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  971. * letters to basic Latin letters.
  972. *
  973. * @private
  974. * @param {string} letter The matched letter to deburr.
  975. * @returns {string} Returns the deburred letter.
  976. */
  977. var deburrLetter = basePropertyOf(deburredLetters);
  978. /**
  979. * Used by `_.escape` to convert characters to HTML entities.
  980. *
  981. * @private
  982. * @param {string} chr The matched character to escape.
  983. * @returns {string} Returns the escaped character.
  984. */
  985. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  986. /**
  987. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  988. *
  989. * @private
  990. * @param {string} chr The matched character to escape.
  991. * @returns {string} Returns the escaped character.
  992. */
  993. function escapeStringChar(chr) {
  994. return '\\' + stringEscapes[chr];
  995. }
  996. /**
  997. * Gets the value at `key` of `object`.
  998. *
  999. * @private
  1000. * @param {Object} [object] The object to query.
  1001. * @param {string} key The key of the property to get.
  1002. * @returns {*} Returns the property value.
  1003. */
  1004. function getValue(object, key) {
  1005. return object == null ? undefined : object[key];
  1006. }
  1007. /**
  1008. * Checks if `string` contains Unicode symbols.
  1009. *
  1010. * @private
  1011. * @param {string} string The string to inspect.
  1012. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  1013. */
  1014. function hasUnicode(string) {
  1015. return reHasUnicode.test(string);
  1016. }
  1017. /**
  1018. * Checks if `string` contains a word composed of Unicode symbols.
  1019. *
  1020. * @private
  1021. * @param {string} string The string to inspect.
  1022. * @returns {boolean} Returns `true` if a word is found, else `false`.
  1023. */
  1024. function hasUnicodeWord(string) {
  1025. return reHasUnicodeWord.test(string);
  1026. }
  1027. /**
  1028. * Converts `iterator` to an array.
  1029. *
  1030. * @private
  1031. * @param {Object} iterator The iterator to convert.
  1032. * @returns {Array} Returns the converted array.
  1033. */
  1034. function iteratorToArray(iterator) {
  1035. var data,
  1036. result = [];
  1037. while (!(data = iterator.next()).done) {
  1038. result.push(data.value);
  1039. }
  1040. return result;
  1041. }
  1042. /**
  1043. * Converts `map` to its key-value pairs.
  1044. *
  1045. * @private
  1046. * @param {Object} map The map to convert.
  1047. * @returns {Array} Returns the key-value pairs.
  1048. */
  1049. function mapToArray(map) {
  1050. var index = -1,
  1051. result = Array(map.size);
  1052. map.forEach(function(value, key) {
  1053. result[++index] = [key, value];
  1054. });
  1055. return result;
  1056. }
  1057. /**
  1058. * Creates a unary function that invokes `func` with its argument transformed.
  1059. *
  1060. * @private
  1061. * @param {Function} func The function to wrap.
  1062. * @param {Function} transform The argument transform.
  1063. * @returns {Function} Returns the new function.
  1064. */
  1065. function overArg(func, transform) {
  1066. return function(arg) {
  1067. return func(transform(arg));
  1068. };
  1069. }
  1070. /**
  1071. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1072. * and returns an array of their indexes.
  1073. *
  1074. * @private
  1075. * @param {Array} array The array to modify.
  1076. * @param {*} placeholder The placeholder to replace.
  1077. * @returns {Array} Returns the new array of placeholder indexes.
  1078. */
  1079. function replaceHolders(array, placeholder) {
  1080. var index = -1,
  1081. length = array.length,
  1082. resIndex = 0,
  1083. result = [];
  1084. while (++index < length) {
  1085. var value = array[index];
  1086. if (value === placeholder || value === PLACEHOLDER) {
  1087. array[index] = PLACEHOLDER;
  1088. result[resIndex++] = index;
  1089. }
  1090. }
  1091. return result;
  1092. }
  1093. /**
  1094. * Gets the value at `key`, unless `key` is "__proto__".
  1095. *
  1096. * @private
  1097. * @param {Object} object The object to query.
  1098. * @param {string} key The key of the property to get.
  1099. * @returns {*} Returns the property value.
  1100. */
  1101. function safeGet(object, key) {
  1102. return key == '__proto__'
  1103. ? undefined
  1104. : object[key];
  1105. }
  1106. /**
  1107. * Converts `set` to an array of its values.
  1108. *
  1109. * @private
  1110. * @param {Object} set The set to convert.
  1111. * @returns {Array} Returns the values.
  1112. */
  1113. function setToArray(set) {
  1114. var index = -1,
  1115. result = Array(set.size);
  1116. set.forEach(function(value) {
  1117. result[++index] = value;
  1118. });
  1119. return result;
  1120. }
  1121. /**
  1122. * Converts `set` to its value-value pairs.
  1123. *
  1124. * @private
  1125. * @param {Object} set The set to convert.
  1126. * @returns {Array} Returns the value-value pairs.
  1127. */
  1128. function setToPairs(set) {
  1129. var index = -1,
  1130. result = Array(set.size);
  1131. set.forEach(function(value) {
  1132. result[++index] = [value, value];
  1133. });
  1134. return result;
  1135. }
  1136. /**
  1137. * A specialized version of `_.indexOf` which performs strict equality
  1138. * comparisons of values, i.e. `===`.
  1139. *
  1140. * @private
  1141. * @param {Array} array The array to inspect.
  1142. * @param {*} value The value to search for.
  1143. * @param {number} fromIndex The index to search from.
  1144. * @returns {number} Returns the index of the matched value, else `-1`.
  1145. */
  1146. function strictIndexOf(array, value, fromIndex) {
  1147. var index = fromIndex - 1,
  1148. length = array.length;
  1149. while (++index < length) {
  1150. if (array[index] === value) {
  1151. return index;
  1152. }
  1153. }
  1154. return -1;
  1155. }
  1156. /**
  1157. * A specialized version of `_.lastIndexOf` which performs strict equality
  1158. * comparisons of values, i.e. `===`.
  1159. *
  1160. * @private
  1161. * @param {Array} array The array to inspect.
  1162. * @param {*} value The value to search for.
  1163. * @param {number} fromIndex The index to search from.
  1164. * @returns {number} Returns the index of the matched value, else `-1`.
  1165. */
  1166. function strictLastIndexOf(array, value, fromIndex) {
  1167. var index = fromIndex + 1;
  1168. while (index--) {
  1169. if (array[index] === value) {
  1170. return index;
  1171. }
  1172. }
  1173. return index;
  1174. }
  1175. /**
  1176. * Gets the number of symbols in `string`.
  1177. *
  1178. * @private
  1179. * @param {string} string The string to inspect.
  1180. * @returns {number} Returns the string size.
  1181. */
  1182. function stringSize(string) {
  1183. return hasUnicode(string)
  1184. ? unicodeSize(string)
  1185. : asciiSize(string);
  1186. }
  1187. /**
  1188. * Converts `string` to an array.
  1189. *
  1190. * @private
  1191. * @param {string} string The string to convert.
  1192. * @returns {Array} Returns the converted array.
  1193. */
  1194. function stringToArray(string) {
  1195. return hasUnicode(string)
  1196. ? unicodeToArray(string)
  1197. : asciiToArray(string);
  1198. }
  1199. /**
  1200. * Used by `_.unescape` to convert HTML entities to characters.
  1201. *
  1202. * @private
  1203. * @param {string} chr The matched character to unescape.
  1204. * @returns {string} Returns the unescaped character.
  1205. */
  1206. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  1207. /**
  1208. * Gets the size of a Unicode `string`.
  1209. *
  1210. * @private
  1211. * @param {string} string The string inspect.
  1212. * @returns {number} Returns the string size.
  1213. */
  1214. function unicodeSize(string) {
  1215. var result = reUnicode.lastIndex = 0;
  1216. while (reUnicode.test(string)) {
  1217. ++result;
  1218. }
  1219. return result;
  1220. }
  1221. /**
  1222. * Converts a Unicode `string` to an array.
  1223. *
  1224. * @private
  1225. * @param {string} string The string to convert.
  1226. * @returns {Array} Returns the converted array.
  1227. */
  1228. function unicodeToArray(string) {
  1229. return string.match(reUnicode) || [];
  1230. }
  1231. /**
  1232. * Splits a Unicode `string` into an array of its words.
  1233. *
  1234. * @private
  1235. * @param {string} The string to inspect.
  1236. * @returns {Array} Returns the words of `string`.
  1237. */
  1238. function unicodeWords(string) {
  1239. return string.match(reUnicodeWord) || [];
  1240. }
  1241. /*--------------------------------------------------------------------------*/
  1242. /**
  1243. * Create a new pristine `lodash` function using the `context` object.
  1244. *
  1245. * @static
  1246. * @memberOf _
  1247. * @since 1.1.0
  1248. * @category Util
  1249. * @param {Object} [context=root] The context object.
  1250. * @returns {Function} Returns a new `lodash` function.
  1251. * @example
  1252. *
  1253. * _.mixin({ 'foo': _.constant('foo') });
  1254. *
  1255. * var lodash = _.runInContext();
  1256. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1257. *
  1258. * _.isFunction(_.foo);
  1259. * // => true
  1260. * _.isFunction(_.bar);
  1261. * // => false
  1262. *
  1263. * lodash.isFunction(lodash.foo);
  1264. * // => false
  1265. * lodash.isFunction(lodash.bar);
  1266. * // => true
  1267. *
  1268. * // Create a suped-up `defer` in Node.js.
  1269. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1270. */
  1271. var runInContext = (function runInContext(context) {
  1272. context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
  1273. /** Built-in constructor references. */
  1274. var Array = context.Array,
  1275. Date = context.Date,
  1276. Error = context.Error,
  1277. Function = context.Function,
  1278. Math = context.Math,
  1279. Object = context.Object,
  1280. RegExp = context.RegExp,
  1281. String = context.String,
  1282. TypeError = context.TypeError;
  1283. /** Used for built-in method references. */
  1284. var arrayProto = Array.prototype,
  1285. funcProto = Function.prototype,
  1286. objectProto = Object.prototype;
  1287. /** Used to detect overreaching core-js shims. */
  1288. var coreJsData = context['__core-js_shared__'];
  1289. /** Used to resolve the decompiled source of functions. */
  1290. var funcToString = funcProto.toString;
  1291. /** Used to check objects for own properties. */
  1292. var hasOwnProperty = objectProto.hasOwnProperty;
  1293. /** Used to generate unique IDs. */
  1294. var idCounter = 0;
  1295. /** Used to detect methods masquerading as native. */
  1296. var maskSrcKey = (function() {
  1297. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1298. return uid ? ('Symbol(src)_1.' + uid) : '';
  1299. }());
  1300. /**
  1301. * Used to resolve the
  1302. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1303. * of values.
  1304. */
  1305. var nativeObjectToString = objectProto.toString;
  1306. /** Used to infer the `Object` constructor. */
  1307. var objectCtorString = funcToString.call(Object);
  1308. /** Used to restore the original `_` reference in `_.noConflict`. */
  1309. var oldDash = root._;
  1310. /** Used to detect if a method is native. */
  1311. var reIsNative = RegExp('^' +
  1312. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1313. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1314. );
  1315. /** Built-in value references. */
  1316. var Buffer = moduleExports ? context.Buffer : undefined,
  1317. Symbol = context.Symbol,
  1318. Uint8Array = context.Uint8Array,
  1319. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  1320. getPrototype = overArg(Object.getPrototypeOf, Object),
  1321. objectCreate = Object.create,
  1322. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1323. splice = arrayProto.splice,
  1324. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  1325. symIterator = Symbol ? Symbol.iterator : undefined,
  1326. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  1327. var defineProperty = (function() {
  1328. try {
  1329. var func = getNative(Object, 'defineProperty');
  1330. func({}, '', {});
  1331. return func;
  1332. } catch (e) {}
  1333. }());
  1334. /** Mocked built-ins. */
  1335. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  1336. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  1337. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  1338. /* Built-in method references for those with the same name as other `lodash` methods. */
  1339. var nativeCeil = Math.ceil,
  1340. nativeFloor = Math.floor,
  1341. nativeGetSymbols = Object.getOwnPropertySymbols,
  1342. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1343. nativeIsFinite = context.isFinite,
  1344. nativeJoin = arrayProto.join,
  1345. nativeKeys = overArg(Object.keys, Object),
  1346. nativeMax = Math.max,
  1347. nativeMin = Math.min,
  1348. nativeNow = Date.now,
  1349. nativeParseInt = context.parseInt,
  1350. nativeRandom = Math.random,
  1351. nativeReverse = arrayProto.reverse;
  1352. /* Built-in method references that are verified to be native. */
  1353. var DataView = getNative(context, 'DataView'),
  1354. Map = getNative(context, 'Map'),
  1355. Promise = getNative(context, 'Promise'),
  1356. Set = getNative(context, 'Set'),
  1357. WeakMap = getNative(context, 'WeakMap'),
  1358. nativeCreate = getNative(Object, 'create');
  1359. /** Used to store function metadata. */
  1360. var metaMap = WeakMap && new WeakMap;
  1361. /** Used to lookup unminified function names. */
  1362. var realNames = {};
  1363. /** Used to detect maps, sets, and weakmaps. */
  1364. var dataViewCtorString = toSource(DataView),
  1365. mapCtorString = toSource(Map),
  1366. promiseCtorString = toSource(Promise),
  1367. setCtorString = toSource(Set),
  1368. weakMapCtorString = toSource(WeakMap);
  1369. /** Used to convert symbols to primitives and strings. */
  1370. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1371. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1372. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1373. /*------------------------------------------------------------------------*/
  1374. /**
  1375. * Creates a `lodash` object which wraps `value` to enable implicit method
  1376. * chain sequences. Methods that operate on and return arrays, collections,
  1377. * and functions can be chained together. Methods that retrieve a single value
  1378. * or may return a primitive value will automatically end the chain sequence
  1379. * and return the unwrapped value. Otherwise, the value must be unwrapped
  1380. * with `_#value`.
  1381. *
  1382. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  1383. * enabled using `_.chain`.
  1384. *
  1385. * The execution of chained methods is lazy, that is, it's deferred until
  1386. * `_#value` is implicitly or explicitly called.
  1387. *
  1388. * Lazy evaluation allows several methods to support shortcut fusion.
  1389. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  1390. * the creation of intermediate arrays and can greatly reduce the number of
  1391. * iteratee executions. Sections of a chain sequence qualify for shortcut
  1392. * fusion if the section is applied to an array and iteratees accept only
  1393. * one argument. The heuristic for whether a section qualifies for shortcut
  1394. * fusion is subject to change.
  1395. *
  1396. * Chaining is supported in custom builds as long as the `_#value` method is
  1397. * directly or indirectly included in the build.
  1398. *
  1399. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1400. *
  1401. * The wrapper `Array` methods are:
  1402. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1403. *
  1404. * The wrapper `String` methods are:
  1405. * `replace` and `split`
  1406. *
  1407. * The wrapper methods that support shortcut fusion are:
  1408. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1409. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1410. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1411. *
  1412. * The chainable wrapper methods are:
  1413. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1414. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1415. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1416. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1417. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1418. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1419. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  1420. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  1421. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  1422. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  1423. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  1424. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  1425. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  1426. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  1427. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  1428. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  1429. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  1430. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  1431. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  1432. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  1433. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  1434. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  1435. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  1436. * `zipObject`, `zipObjectDeep`, and `zipWith`
  1437. *
  1438. * The wrapper methods that are **not** chainable by default are:
  1439. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1440. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  1441. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  1442. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  1443. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  1444. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1445. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1446. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  1447. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  1448. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  1449. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  1450. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  1451. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  1452. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  1453. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  1454. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  1455. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  1456. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  1457. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  1458. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  1459. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  1460. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  1461. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  1462. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  1463. * `upperFirst`, `value`, and `words`
  1464. *
  1465. * @name _
  1466. * @constructor
  1467. * @category Seq
  1468. * @param {*} value The value to wrap in a `lodash` instance.
  1469. * @returns {Object} Returns the new `lodash` wrapper instance.
  1470. * @example
  1471. *
  1472. * function square(n) {
  1473. * return n * n;
  1474. * }
  1475. *
  1476. * var wrapped = _([1, 2, 3]);
  1477. *
  1478. * // Returns an unwrapped value.
  1479. * wrapped.reduce(_.add);
  1480. * // => 6
  1481. *
  1482. * // Returns a wrapped value.
  1483. * var squares = wrapped.map(square);
  1484. *
  1485. * _.isArray(squares);
  1486. * // => false
  1487. *
  1488. * _.isArray(squares.value());
  1489. * // => true
  1490. */
  1491. function lodash(value) {
  1492. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  1493. if (value instanceof LodashWrapper) {
  1494. return value;
  1495. }
  1496. if (hasOwnProperty.call(value, '__wrapped__')) {
  1497. return wrapperClone(value);
  1498. }
  1499. }
  1500. return new LodashWrapper(value);
  1501. }
  1502. /**
  1503. * The base implementation of `_.create` without support for assigning
  1504. * properties to the created object.
  1505. *
  1506. * @private
  1507. * @param {Object} proto The object to inherit from.
  1508. * @returns {Object} Returns the new object.
  1509. */
  1510. var baseCreate = (function() {
  1511. function object() {}
  1512. return function(proto) {
  1513. if (!isObject(proto)) {
  1514. return {};
  1515. }
  1516. if (objectCreate) {
  1517. return objectCreate(proto);
  1518. }
  1519. object.prototype = proto;
  1520. var result = new object;
  1521. object.prototype = undefined;
  1522. return result;
  1523. };
  1524. }());
  1525. /**
  1526. * The function whose prototype chain sequence wrappers inherit from.
  1527. *
  1528. * @private
  1529. */
  1530. function baseLodash() {
  1531. // No operation performed.
  1532. }
  1533. /**
  1534. * The base constructor for creating `lodash` wrapper objects.
  1535. *
  1536. * @private
  1537. * @param {*} value The value to wrap.
  1538. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  1539. */
  1540. function LodashWrapper(value, chainAll) {
  1541. this.__wrapped__ = value;
  1542. this.__actions__ = [];
  1543. this.__chain__ = !!chainAll;
  1544. this.__index__ = 0;
  1545. this.__values__ = undefined;
  1546. }
  1547. /**
  1548. * By default, the template delimiters used by lodash are like those in
  1549. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  1550. * following template settings to use alternative delimiters.
  1551. *
  1552. * @static
  1553. * @memberOf _
  1554. * @type {Object}
  1555. */
  1556. lodash.templateSettings = {
  1557. /**
  1558. * Used to detect `data` property values to be HTML-escaped.
  1559. *
  1560. * @memberOf _.templateSettings
  1561. * @type {RegExp}
  1562. */
  1563. 'escape': reEscape,
  1564. /**
  1565. * Used to detect code to be evaluated.
  1566. *
  1567. * @memberOf _.templateSettings
  1568. * @type {RegExp}
  1569. */
  1570. 'evaluate': reEvaluate,
  1571. /**
  1572. * Used to detect `data` property values to inject.
  1573. *
  1574. * @memberOf _.templateSettings
  1575. * @type {RegExp}
  1576. */
  1577. 'interpolate': reInterpolate,
  1578. /**
  1579. * Used to reference the data object in the template text.
  1580. *
  1581. * @memberOf _.templateSettings
  1582. * @type {string}
  1583. */
  1584. 'variable': '',
  1585. /**
  1586. * Used to import variables into the compiled template.
  1587. *
  1588. * @memberOf _.templateSettings
  1589. * @type {Object}
  1590. */
  1591. 'imports': {
  1592. /**
  1593. * A reference to the `lodash` function.
  1594. *
  1595. * @memberOf _.templateSettings.imports
  1596. * @type {Function}
  1597. */
  1598. '_': lodash
  1599. }
  1600. };
  1601. // Ensure wrappers are instances of `baseLodash`.
  1602. lodash.prototype = baseLodash.prototype;
  1603. lodash.prototype.constructor = lodash;
  1604. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  1605. LodashWrapper.prototype.constructor = LodashWrapper;
  1606. /*------------------------------------------------------------------------*/
  1607. /**
  1608. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1609. *
  1610. * @private
  1611. * @constructor
  1612. * @param {*} value The value to wrap.
  1613. */
  1614. function LazyWrapper(value) {
  1615. this.__wrapped__ = value;
  1616. this.__actions__ = [];
  1617. this.__dir__ = 1;
  1618. this.__filtered__ = false;
  1619. this.__iteratees__ = [];
  1620. this.__takeCount__ = MAX_ARRAY_LENGTH;
  1621. this.__views__ = [];
  1622. }
  1623. /**
  1624. * Creates a clone of the lazy wrapper object.
  1625. *
  1626. * @private
  1627. * @name clone
  1628. * @memberOf LazyWrapper
  1629. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1630. */
  1631. function lazyClone() {
  1632. var result = new LazyWrapper(this.__wrapped__);
  1633. result.__actions__ = copyArray(this.__actions__);
  1634. result.__dir__ = this.__dir__;
  1635. result.__filtered__ = this.__filtered__;
  1636. result.__iteratees__ = copyArray(this.__iteratees__);
  1637. result.__takeCount__ = this.__takeCount__;
  1638. result.__views__ = copyArray(this.__views__);
  1639. return result;
  1640. }
  1641. /**
  1642. * Reverses the direction of lazy iteration.
  1643. *
  1644. * @private
  1645. * @name reverse
  1646. * @memberOf LazyWrapper
  1647. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1648. */
  1649. function lazyReverse() {
  1650. if (this.__filtered__) {
  1651. var result = new LazyWrapper(this);
  1652. result.__dir__ = -1;
  1653. result.__filtered__ = true;
  1654. } else {
  1655. result = this.clone();
  1656. result.__dir__ *= -1;
  1657. }
  1658. return result;
  1659. }
  1660. /**
  1661. * Extracts the unwrapped value from its lazy wrapper.
  1662. *
  1663. * @private
  1664. * @name value
  1665. * @memberOf LazyWrapper
  1666. * @returns {*} Returns the unwrapped value.
  1667. */
  1668. function lazyValue() {
  1669. var array = this.__wrapped__.value(),
  1670. dir = this.__dir__,
  1671. isArr = isArray(array),
  1672. isRight = dir < 0,
  1673. arrLength = isArr ? array.length : 0,
  1674. view = getView(0, arrLength, this.__views__),
  1675. start = view.start,
  1676. end = view.end,
  1677. length = end - start,
  1678. index = isRight ? end : (start - 1),
  1679. iteratees = this.__iteratees__,
  1680. iterLength = iteratees.length,
  1681. resIndex = 0,
  1682. takeCount = nativeMin(length, this.__takeCount__);
  1683. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  1684. return baseWrapperValue(array, this.__actions__);
  1685. }
  1686. var result = [];
  1687. outer:
  1688. while (length-- && resIndex < takeCount) {
  1689. index += dir;
  1690. var iterIndex = -1,
  1691. value = array[index];
  1692. while (++iterIndex < iterLength) {
  1693. var data = iteratees[iterIndex],
  1694. iteratee = data.iteratee,
  1695. type = data.type,
  1696. computed = iteratee(value);
  1697. if (type == LAZY_MAP_FLAG) {
  1698. value = computed;
  1699. } else if (!computed) {
  1700. if (type == LAZY_FILTER_FLAG) {
  1701. continue outer;
  1702. } else {
  1703. break outer;
  1704. }
  1705. }
  1706. }
  1707. result[resIndex++] = value;
  1708. }
  1709. return result;
  1710. }
  1711. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  1712. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  1713. LazyWrapper.prototype.constructor = LazyWrapper;
  1714. /*------------------------------------------------------------------------*/
  1715. /**
  1716. * Creates a hash object.
  1717. *
  1718. * @private
  1719. * @constructor
  1720. * @param {Array} [entries] The key-value pairs to cache.
  1721. */
  1722. function Hash(entries) {
  1723. var index = -1,
  1724. length = entries == null ? 0 : entries.length;
  1725. this.clear();
  1726. while (++index < length) {
  1727. var entry = entries[index];
  1728. this.set(entry[0], entry[1]);
  1729. }
  1730. }
  1731. /**
  1732. * Removes all key-value entries from the hash.
  1733. *
  1734. * @private
  1735. * @name clear
  1736. * @memberOf Hash
  1737. */
  1738. function hashClear() {
  1739. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1740. this.size = 0;
  1741. }
  1742. /**
  1743. * Removes `key` and its value from the hash.
  1744. *
  1745. * @private
  1746. * @name delete
  1747. * @memberOf Hash
  1748. * @param {Object} hash The hash to modify.
  1749. * @param {string} key The key of the value to remove.
  1750. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1751. */
  1752. function hashDelete(key) {
  1753. var result = this.has(key) && delete this.__data__[key];
  1754. this.size -= result ? 1 : 0;
  1755. return result;
  1756. }
  1757. /**
  1758. * Gets the hash value for `key`.
  1759. *
  1760. * @private
  1761. * @name get
  1762. * @memberOf Hash
  1763. * @param {string} key The key of the value to get.
  1764. * @returns {*} Returns the entry value.
  1765. */
  1766. function hashGet(key) {
  1767. var data = this.__data__;
  1768. if (nativeCreate) {
  1769. var result = data[key];
  1770. return result === HASH_UNDEFINED ? undefined : result;
  1771. }
  1772. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  1773. }
  1774. /**
  1775. * Checks if a hash value for `key` exists.
  1776. *
  1777. * @private
  1778. * @name has
  1779. * @memberOf Hash
  1780. * @param {string} key The key of the entry to check.
  1781. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1782. */
  1783. function hashHas(key) {
  1784. var data = this.__data__;
  1785. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  1786. }
  1787. /**
  1788. * Sets the hash `key` to `value`.
  1789. *
  1790. * @private
  1791. * @name set
  1792. * @memberOf Hash
  1793. * @param {string} key The key of the value to set.
  1794. * @param {*} value The value to set.
  1795. * @returns {Object} Returns the hash instance.
  1796. */
  1797. function hashSet(key, value) {
  1798. var data = this.__data__;
  1799. this.size += this.has(key) ? 0 : 1;
  1800. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1801. return this;
  1802. }
  1803. // Add methods to `Hash`.
  1804. Hash.prototype.clear = hashClear;
  1805. Hash.prototype['delete'] = hashDelete;
  1806. Hash.prototype.get = hashGet;
  1807. Hash.prototype.has = hashHas;
  1808. Hash.prototype.set = hashSet;
  1809. /*------------------------------------------------------------------------*/
  1810. /**
  1811. * Creates an list cache object.
  1812. *
  1813. * @private
  1814. * @constructor
  1815. * @param {Array} [entries] The key-value pairs to cache.
  1816. */
  1817. function ListCache(entries) {
  1818. var index = -1,
  1819. length = entries == null ? 0 : entries.length;
  1820. this.clear();
  1821. while (++index < length) {
  1822. var entry = entries[index];
  1823. this.set(entry[0], entry[1]);
  1824. }
  1825. }
  1826. /**
  1827. * Removes all key-value entries from the list cache.
  1828. *
  1829. * @private
  1830. * @name clear
  1831. * @memberOf ListCache
  1832. */
  1833. function listCacheClear() {
  1834. this.__data__ = [];
  1835. this.size = 0;
  1836. }
  1837. /**
  1838. * Removes `key` and its value from the list cache.
  1839. *
  1840. * @private
  1841. * @name delete
  1842. * @memberOf ListCache
  1843. * @param {string} key The key of the value to remove.
  1844. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1845. */
  1846. function listCacheDelete(key) {
  1847. var data = this.__data__,
  1848. index = assocIndexOf(data, key);
  1849. if (index < 0) {
  1850. return false;
  1851. }
  1852. var lastIndex = data.length - 1;
  1853. if (index == lastIndex) {
  1854. data.pop();
  1855. } else {
  1856. splice.call(data, index, 1);
  1857. }
  1858. --this.size;
  1859. return true;
  1860. }
  1861. /**
  1862. * Gets the list cache value for `key`.
  1863. *
  1864. * @private
  1865. * @name get
  1866. * @memberOf ListCache
  1867. * @param {string} key The key of the value to get.
  1868. * @returns {*} Returns the entry value.
  1869. */
  1870. function listCacheGet(key) {
  1871. var data = this.__data__,
  1872. index = assocIndexOf(data, key);
  1873. return index < 0 ? undefined : data[index][1];
  1874. }
  1875. /**
  1876. * Checks if a list cache value for `key` exists.
  1877. *
  1878. * @private
  1879. * @name has
  1880. * @memberOf ListCache
  1881. * @param {string} key The key of the entry to check.
  1882. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1883. */
  1884. function listCacheHas(key) {
  1885. return assocIndexOf(this.__data__, key) > -1;
  1886. }
  1887. /**
  1888. * Sets the list cache `key` to `value`.
  1889. *
  1890. * @private
  1891. * @name set
  1892. * @memberOf ListCache
  1893. * @param {string} key The key of the value to set.
  1894. * @param {*} value The value to set.
  1895. * @returns {Object} Returns the list cache instance.
  1896. */
  1897. function listCacheSet(key, value) {
  1898. var data = this.__data__,
  1899. index = assocIndexOf(data, key);
  1900. if (index < 0) {
  1901. ++this.size;
  1902. data.push([key, value]);
  1903. } else {
  1904. data[index][1] = value;
  1905. }
  1906. return this;
  1907. }
  1908. // Add methods to `ListCache`.
  1909. ListCache.prototype.clear = listCacheClear;
  1910. ListCache.prototype['delete'] = listCacheDelete;
  1911. ListCache.prototype.get = listCacheGet;
  1912. ListCache.prototype.has = listCacheHas;
  1913. ListCache.prototype.set = listCacheSet;
  1914. /*------------------------------------------------------------------------*/
  1915. /**
  1916. * Creates a map cache object to store key-value pairs.
  1917. *
  1918. * @private
  1919. * @constructor
  1920. * @param {Array} [entries] The key-value pairs to cache.
  1921. */
  1922. function MapCache(entries) {
  1923. var index = -1,
  1924. length = entries == null ? 0 : entries.length;
  1925. this.clear();
  1926. while (++index < length) {
  1927. var entry = entries[index];
  1928. this.set(entry[0], entry[1]);
  1929. }
  1930. }
  1931. /**
  1932. * Removes all key-value entries from the map.
  1933. *
  1934. * @private
  1935. * @name clear
  1936. * @memberOf MapCache
  1937. */
  1938. function mapCacheClear() {
  1939. this.size = 0;
  1940. this.__data__ = {
  1941. 'hash': new Hash,
  1942. 'map': new (Map || ListCache),
  1943. 'string': new Hash
  1944. };
  1945. }
  1946. /**
  1947. * Removes `key` and its value from the map.
  1948. *
  1949. * @private
  1950. * @name delete
  1951. * @memberOf MapCache
  1952. * @param {string} key The key of the value to remove.
  1953. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1954. */
  1955. function mapCacheDelete(key) {
  1956. var result = getMapData(this, key)['delete'](key);
  1957. this.size -= result ? 1 : 0;
  1958. return result;
  1959. }
  1960. /**
  1961. * Gets the map value for `key`.
  1962. *
  1963. * @private
  1964. * @name get
  1965. * @memberOf MapCache
  1966. * @param {string} key The key of the value to get.
  1967. * @returns {*} Returns the entry value.
  1968. */
  1969. function mapCacheGet(key) {
  1970. return getMapData(this, key).get(key);
  1971. }
  1972. /**
  1973. * Checks if a map value for `key` exists.
  1974. *
  1975. * @private
  1976. * @name has
  1977. * @memberOf MapCache
  1978. * @param {string} key The key of the entry to check.
  1979. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1980. */
  1981. function mapCacheHas(key) {
  1982. return getMapData(this, key).has(key);
  1983. }
  1984. /**
  1985. * Sets the map `key` to `value`.
  1986. *
  1987. * @private
  1988. * @name set
  1989. * @memberOf MapCache
  1990. * @param {string} key The key of the value to set.
  1991. * @param {*} value The value to set.
  1992. * @returns {Object} Returns the map cache instance.
  1993. */
  1994. function mapCacheSet(key, value) {
  1995. var data = getMapData(this, key),
  1996. size = data.size;
  1997. data.set(key, value);
  1998. this.size += data.size == size ? 0 : 1;
  1999. return this;
  2000. }
  2001. // Add methods to `MapCache`.
  2002. MapCache.prototype.clear = mapCacheClear;
  2003. MapCache.prototype['delete'] = mapCacheDelete;
  2004. MapCache.prototype.get = mapCacheGet;
  2005. MapCache.prototype.has = mapCacheHas;
  2006. MapCache.prototype.set = mapCacheSet;
  2007. /*------------------------------------------------------------------------*/
  2008. /**
  2009. *
  2010. * Creates an array cache object to store unique values.
  2011. *
  2012. * @private
  2013. * @constructor
  2014. * @param {Array} [values] The values to cache.
  2015. */
  2016. function SetCache(values) {
  2017. var index = -1,
  2018. length = values == null ? 0 : values.length;
  2019. this.__data__ = new MapCache;
  2020. while (++index < length) {
  2021. this.add(values[index]);
  2022. }
  2023. }
  2024. /**
  2025. * Adds `value` to the array cache.
  2026. *
  2027. * @private
  2028. * @name add
  2029. * @memberOf SetCache
  2030. * @alias push
  2031. * @param {*} value The value to cache.
  2032. * @returns {Object} Returns the cache instance.
  2033. */
  2034. function setCacheAdd(value) {
  2035. this.__data__.set(value, HASH_UNDEFINED);
  2036. return this;
  2037. }
  2038. /**
  2039. * Checks if `value` is in the array cache.
  2040. *
  2041. * @private
  2042. * @name has
  2043. * @memberOf SetCache
  2044. * @param {*} value The value to search for.
  2045. * @returns {number} Returns `true` if `value` is found, else `false`.
  2046. */
  2047. function setCacheHas(value) {
  2048. return this.__data__.has(value);
  2049. }
  2050. // Add methods to `SetCache`.
  2051. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  2052. SetCache.prototype.has = setCacheHas;
  2053. /*------------------------------------------------------------------------*/
  2054. /**
  2055. * Creates a stack cache object to store key-value pairs.
  2056. *
  2057. * @private
  2058. * @constructor
  2059. * @param {Array} [entries] The key-value pairs to cache.
  2060. */
  2061. function Stack(entries) {
  2062. var data = this.__data__ = new ListCache(entries);
  2063. this.size = data.size;
  2064. }
  2065. /**
  2066. * Removes all key-value entries from the stack.
  2067. *
  2068. * @private
  2069. * @name clear
  2070. * @memberOf Stack
  2071. */
  2072. function stackClear() {
  2073. this.__data__ = new ListCache;
  2074. this.size = 0;
  2075. }
  2076. /**
  2077. * Removes `key` and its value from the stack.
  2078. *
  2079. * @private
  2080. * @name delete
  2081. * @memberOf Stack
  2082. * @param {string} key The key of the value to remove.
  2083. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2084. */
  2085. function stackDelete(key) {
  2086. var data = this.__data__,
  2087. result = data['delete'](key);
  2088. this.size = data.size;
  2089. return result;
  2090. }
  2091. /**
  2092. * Gets the stack value for `key`.
  2093. *
  2094. * @private
  2095. * @name get
  2096. * @memberOf Stack
  2097. * @param {string} key The key of the value to get.
  2098. * @returns {*} Returns the entry value.
  2099. */
  2100. function stackGet(key) {
  2101. return this.__data__.get(key);
  2102. }
  2103. /**
  2104. * Checks if a stack value for `key` exists.
  2105. *
  2106. * @private
  2107. * @name has
  2108. * @memberOf Stack
  2109. * @param {string} key The key of the entry to check.
  2110. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2111. */
  2112. function stackHas(key) {
  2113. return this.__data__.has(key);
  2114. }
  2115. /**
  2116. * Sets the stack `key` to `value`.
  2117. *
  2118. * @private
  2119. * @name set
  2120. * @memberOf Stack
  2121. * @param {string} key The key of the value to set.
  2122. * @param {*} value The value to set.
  2123. * @returns {Object} Returns the stack cache instance.
  2124. */
  2125. function stackSet(key, value) {
  2126. var data = this.__data__;
  2127. if (data instanceof ListCache) {
  2128. var pairs = data.__data__;
  2129. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  2130. pairs.push([key, value]);
  2131. this.size = ++data.size;
  2132. return this;
  2133. }
  2134. data = this.__data__ = new MapCache(pairs);
  2135. }
  2136. data.set(key, value);
  2137. this.size = data.size;
  2138. return this;
  2139. }
  2140. // Add methods to `Stack`.
  2141. Stack.prototype.clear = stackClear;
  2142. Stack.prototype['delete'] = stackDelete;
  2143. Stack.prototype.get = stackGet;
  2144. Stack.prototype.has = stackHas;
  2145. Stack.prototype.set = stackSet;
  2146. /*------------------------------------------------------------------------*/
  2147. /**
  2148. * Creates an array of the enumerable property names of the array-like `value`.
  2149. *
  2150. * @private
  2151. * @param {*} value The value to query.
  2152. * @param {boolean} inherited Specify returning inherited property names.
  2153. * @returns {Array} Returns the array of property names.
  2154. */
  2155. function arrayLikeKeys(value, inherited) {
  2156. var isArr = isArray(value),
  2157. isArg = !isArr && isArguments(value),
  2158. isBuff = !isArr && !isArg && isBuffer(value),
  2159. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  2160. skipIndexes = isArr || isArg || isBuff || isType,
  2161. result = skipIndexes ? baseTimes(value.length, String) : [],
  2162. length = result.length;
  2163. for (var key in value) {
  2164. if ((inherited || hasOwnProperty.call(value, key)) &&
  2165. !(skipIndexes && (
  2166. // Safari 9 has enumerable `arguments.length` in strict mode.
  2167. key == 'length' ||
  2168. // Node.js 0.10 has enumerable non-index properties on buffers.
  2169. (isBuff && (key == 'offset' || key == 'parent')) ||
  2170. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  2171. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  2172. // Skip index properties.
  2173. isIndex(key, length)
  2174. ))) {
  2175. result.push(key);
  2176. }
  2177. }
  2178. return result;
  2179. }
  2180. /**
  2181. * A specialized version of `_.sample` for arrays.
  2182. *
  2183. * @private
  2184. * @param {Array} array The array to sample.
  2185. * @returns {*} Returns the random element.
  2186. */
  2187. function arraySample(array) {
  2188. var length = array.length;
  2189. return length ? array[baseRandom(0, length - 1)] : undefined;
  2190. }
  2191. /**
  2192. * A specialized version of `_.sampleSize` for arrays.
  2193. *
  2194. * @private
  2195. * @param {Array} array The array to sample.
  2196. * @param {number} n The number of elements to sample.
  2197. * @returns {Array} Returns the random elements.
  2198. */
  2199. function arraySampleSize(array, n) {
  2200. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  2201. }
  2202. /**
  2203. * A specialized version of `_.shuffle` for arrays.
  2204. *
  2205. * @private
  2206. * @param {Array} array The array to shuffle.
  2207. * @returns {Array} Returns the new shuffled array.
  2208. */
  2209. function arrayShuffle(array) {
  2210. return shuffleSelf(copyArray(array));
  2211. }
  2212. /**
  2213. * This function is like `assignValue` except that it doesn't assign
  2214. * `undefined` values.
  2215. *
  2216. * @private
  2217. * @param {Object} object The object to modify.
  2218. * @param {string} key The key of the property to assign.
  2219. * @param {*} value The value to assign.
  2220. */
  2221. function assignMergeValue(object, key, value) {
  2222. if ((value !== undefined && !eq(object[key], value)) ||
  2223. (value === undefined && !(key in object))) {
  2224. baseAssignValue(object, key, value);
  2225. }
  2226. }
  2227. /**
  2228. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  2229. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2230. * for equality comparisons.
  2231. *
  2232. * @private
  2233. * @param {Object} object The object to modify.
  2234. * @param {string} key The key of the property to assign.
  2235. * @param {*} value The value to assign.
  2236. */
  2237. function assignValue(object, key, value) {
  2238. var objValue = object[key];
  2239. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  2240. (value === undefined && !(key in object))) {
  2241. baseAssignValue(object, key, value);
  2242. }
  2243. }
  2244. /**
  2245. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2246. *
  2247. * @private
  2248. * @param {Array} array The array to inspect.
  2249. * @param {*} key The key to search for.
  2250. * @returns {number} Returns the index of the matched value, else `-1`.
  2251. */
  2252. function assocIndexOf(array, key) {
  2253. var length = array.length;
  2254. while (length--) {
  2255. if (eq(array[length][0], key)) {
  2256. return length;
  2257. }
  2258. }
  2259. return -1;
  2260. }
  2261. /**
  2262. * Aggregates elements of `collection` on `accumulator` with keys transformed
  2263. * by `iteratee` and values set by `setter`.
  2264. *
  2265. * @private
  2266. * @param {Array|Object} collection The collection to iterate over.
  2267. * @param {Function} setter The function to set `accumulator` values.
  2268. * @param {Function} iteratee The iteratee to transform keys.
  2269. * @param {Object} accumulator The initial aggregated object.
  2270. * @returns {Function} Returns `accumulator`.
  2271. */
  2272. function baseAggregator(collection, setter, iteratee, accumulator) {
  2273. baseEach(collection, function(value, key, collection) {
  2274. setter(accumulator, value, iteratee(value), collection);
  2275. });
  2276. return accumulator;
  2277. }
  2278. /**
  2279. * The base implementation of `_.assign` without support for multiple sources
  2280. * or `customizer` functions.
  2281. *
  2282. * @private
  2283. * @param {Object} object The destination object.
  2284. * @param {Object} source The source object.
  2285. * @returns {Object} Returns `object`.
  2286. */
  2287. function baseAssign(object, source) {
  2288. return object && copyObject(source, keys(source), object);
  2289. }
  2290. /**
  2291. * The base implementation of `_.assignIn` without support for multiple sources
  2292. * or `customizer` functions.
  2293. *
  2294. * @private
  2295. * @param {Object} object The destination object.
  2296. * @param {Object} source The source object.
  2297. * @returns {Object} Returns `object`.
  2298. */
  2299. function baseAssignIn(object, source) {
  2300. return object && copyObject(source, keysIn(source), object);
  2301. }
  2302. /**
  2303. * The base implementation of `assignValue` and `assignMergeValue` without
  2304. * value checks.
  2305. *
  2306. * @private
  2307. * @param {Object} object The object to modify.
  2308. * @param {string} key The key of the property to assign.
  2309. * @param {*} value The value to assign.
  2310. */
  2311. function baseAssignValue(object, key, value) {
  2312. if (key == '__proto__' && defineProperty) {
  2313. defineProperty(object, key, {
  2314. 'configurable': true,
  2315. 'enumerable': true,
  2316. 'value': value,
  2317. 'writable': true
  2318. });
  2319. } else {
  2320. object[key] = value;
  2321. }
  2322. }
  2323. /**
  2324. * The base implementation of `_.at` without support for individual paths.
  2325. *
  2326. * @private
  2327. * @param {Object} object The object to iterate over.
  2328. * @param {string[]} paths The property paths to pick.
  2329. * @returns {Array} Returns the picked elements.
  2330. */
  2331. function baseAt(object, paths) {
  2332. var index = -1,
  2333. length = paths.length,
  2334. result = Array(length),
  2335. skip = object == null;
  2336. while (++index < length) {
  2337. result[index] = skip ? undefined : get(object, paths[index]);
  2338. }
  2339. return result;
  2340. }
  2341. /**
  2342. * The base implementation of `_.clamp` which doesn't coerce arguments.
  2343. *
  2344. * @private
  2345. * @param {number} number The number to clamp.
  2346. * @param {number} [lower] The lower bound.
  2347. * @param {number} upper The upper bound.
  2348. * @returns {number} Returns the clamped number.
  2349. */
  2350. function baseClamp(number, lower, upper) {
  2351. if (number === number) {
  2352. if (upper !== undefined) {
  2353. number = number <= upper ? number : upper;
  2354. }
  2355. if (lower !== undefined) {
  2356. number = number >= lower ? number : lower;
  2357. }
  2358. }
  2359. return number;
  2360. }
  2361. /**
  2362. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  2363. * traversed objects.
  2364. *
  2365. * @private
  2366. * @param {*} value The value to clone.
  2367. * @param {boolean} bitmask The bitmask flags.
  2368. * 1 - Deep clone
  2369. * 2 - Flatten inherited properties
  2370. * 4 - Clone symbols
  2371. * @param {Function} [customizer] The function to customize cloning.
  2372. * @param {string} [key] The key of `value`.
  2373. * @param {Object} [object] The parent object of `value`.
  2374. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  2375. * @returns {*} Returns the cloned value.
  2376. */
  2377. function baseClone(value, bitmask, customizer, key, object, stack) {
  2378. var result,
  2379. isDeep = bitmask & CLONE_DEEP_FLAG,
  2380. isFlat = bitmask & CLONE_FLAT_FLAG,
  2381. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  2382. if (customizer) {
  2383. result = object ? customizer(value, key, object, stack) : customizer(value);
  2384. }
  2385. if (result !== undefined) {
  2386. return result;
  2387. }
  2388. if (!isObject(value)) {
  2389. return value;
  2390. }
  2391. var isArr = isArray(value);
  2392. if (isArr) {
  2393. result = initCloneArray(value);
  2394. if (!isDeep) {
  2395. return copyArray(value, result);
  2396. }
  2397. } else {
  2398. var tag = getTag(value),
  2399. isFunc = tag == funcTag || tag == genTag;
  2400. if (isBuffer(value)) {
  2401. return cloneBuffer(value, isDeep);
  2402. }
  2403. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  2404. result = (isFlat || isFunc) ? {} : initCloneObject(value);
  2405. if (!isDeep) {
  2406. return isFlat
  2407. ? copySymbolsIn(value, baseAssignIn(result, value))
  2408. : copySymbols(value, baseAssign(result, value));
  2409. }
  2410. } else {
  2411. if (!cloneableTags[tag]) {
  2412. return object ? value : {};
  2413. }
  2414. result = initCloneByTag(value, tag, isDeep);
  2415. }
  2416. }
  2417. // Check for circular references and return its corresponding clone.
  2418. stack || (stack = new Stack);
  2419. var stacked = stack.get(value);
  2420. if (stacked) {
  2421. return stacked;
  2422. }
  2423. stack.set(value, result);
  2424. if (isSet(value)) {
  2425. value.forEach(function(subValue) {
  2426. result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
  2427. });
  2428. return result;
  2429. }
  2430. if (isMap(value)) {
  2431. value.forEach(function(subValue, key) {
  2432. result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2433. });
  2434. return result;
  2435. }
  2436. var keysFunc = isFull
  2437. ? (isFlat ? getAllKeysIn : getAllKeys)
  2438. : (isFlat ? keysIn : keys);
  2439. var props = isArr ? undefined : keysFunc(value);
  2440. arrayEach(props || value, function(subValue, key) {
  2441. if (props) {
  2442. key = subValue;
  2443. subValue = value[key];
  2444. }
  2445. // Recursively populate clone (susceptible to call stack limits).
  2446. assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2447. });
  2448. return result;
  2449. }
  2450. /**
  2451. * The base implementation of `_.conforms` which doesn't clone `source`.
  2452. *
  2453. * @private
  2454. * @param {Object} source The object of property predicates to conform to.
  2455. * @returns {Function} Returns the new spec function.
  2456. */
  2457. function baseConforms(source) {
  2458. var props = keys(source);
  2459. return function(object) {
  2460. return baseConformsTo(object, source, props);
  2461. };
  2462. }
  2463. /**
  2464. * The base implementation of `_.conformsTo` which accepts `props` to check.
  2465. *
  2466. * @private
  2467. * @param {Object} object The object to inspect.
  2468. * @param {Object} source The object of property predicates to conform to.
  2469. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  2470. */
  2471. function baseConformsTo(object, source, props) {
  2472. var length = props.length;
  2473. if (object == null) {
  2474. return !length;
  2475. }
  2476. object = Object(object);
  2477. while (length--) {
  2478. var key = props[length],
  2479. predicate = source[key],
  2480. value = object[key];
  2481. if ((value === undefined && !(key in object)) || !predicate(value)) {
  2482. return false;
  2483. }
  2484. }
  2485. return true;
  2486. }
  2487. /**
  2488. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  2489. * to provide to `func`.
  2490. *
  2491. * @private
  2492. * @param {Function} func The function to delay.
  2493. * @param {number} wait The number of milliseconds to delay invocation.
  2494. * @param {Array} args The arguments to provide to `func`.
  2495. * @returns {number|Object} Returns the timer id or timeout object.
  2496. */
  2497. function baseDelay(func, wait, args) {
  2498. if (typeof func != 'function') {
  2499. throw new TypeError(FUNC_ERROR_TEXT);
  2500. }
  2501. return setTimeout(function() { func.apply(undefined, args); }, wait);
  2502. }
  2503. /**
  2504. * The base implementation of methods like `_.difference` without support
  2505. * for excluding multiple arrays or iteratee shorthands.
  2506. *
  2507. * @private
  2508. * @param {Array} array The array to inspect.
  2509. * @param {Array} values The values to exclude.
  2510. * @param {Function} [iteratee] The iteratee invoked per element.
  2511. * @param {Function} [comparator] The comparator invoked per element.
  2512. * @returns {Array} Returns the new array of filtered values.
  2513. */
  2514. function baseDifference(array, values, iteratee, comparator) {
  2515. var index = -1,
  2516. includes = arrayIncludes,
  2517. isCommon = true,
  2518. length = array.length,
  2519. result = [],
  2520. valuesLength = values.length;
  2521. if (!length) {
  2522. return result;
  2523. }
  2524. if (iteratee) {
  2525. values = arrayMap(values, baseUnary(iteratee));
  2526. }
  2527. if (comparator) {
  2528. includes = arrayIncludesWith;
  2529. isCommon = false;
  2530. }
  2531. else if (values.length >= LARGE_ARRAY_SIZE) {
  2532. includes = cacheHas;
  2533. isCommon = false;
  2534. values = new SetCache(values);
  2535. }
  2536. outer:
  2537. while (++index < length) {
  2538. var value = array[index],
  2539. computed = iteratee == null ? value : iteratee(value);
  2540. value = (comparator || value !== 0) ? value : 0;
  2541. if (isCommon && computed === computed) {
  2542. var valuesIndex = valuesLength;
  2543. while (valuesIndex--) {
  2544. if (values[valuesIndex] === computed) {
  2545. continue outer;
  2546. }
  2547. }
  2548. result.push(value);
  2549. }
  2550. else if (!includes(values, computed, comparator)) {
  2551. result.push(value);
  2552. }
  2553. }
  2554. return result;
  2555. }
  2556. /**
  2557. * The base implementation of `_.forEach` without support for iteratee shorthands.
  2558. *
  2559. * @private
  2560. * @param {Array|Object} collection The collection to iterate over.
  2561. * @param {Function} iteratee The function invoked per iteration.
  2562. * @returns {Array|Object} Returns `collection`.
  2563. */
  2564. var baseEach = createBaseEach(baseForOwn);
  2565. /**
  2566. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  2567. *
  2568. * @private
  2569. * @param {Array|Object} collection The collection to iterate over.
  2570. * @param {Function} iteratee The function invoked per iteration.
  2571. * @returns {Array|Object} Returns `collection`.
  2572. */
  2573. var baseEachRight = createBaseEach(baseForOwnRight, true);
  2574. /**
  2575. * The base implementation of `_.every` without support for iteratee shorthands.
  2576. *
  2577. * @private
  2578. * @param {Array|Object} collection The collection to iterate over.
  2579. * @param {Function} predicate The function invoked per iteration.
  2580. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2581. * else `false`
  2582. */
  2583. function baseEvery(collection, predicate) {
  2584. var result = true;
  2585. baseEach(collection, function(value, index, collection) {
  2586. result = !!predicate(value, index, collection);
  2587. return result;
  2588. });
  2589. return result;
  2590. }
  2591. /**
  2592. * The base implementation of methods like `_.max` and `_.min` which accepts a
  2593. * `comparator` to determine the extremum value.
  2594. *
  2595. * @private
  2596. * @param {Array} array The array to iterate over.
  2597. * @param {Function} iteratee The iteratee invoked per iteration.
  2598. * @param {Function} comparator The comparator used to compare values.
  2599. * @returns {*} Returns the extremum value.
  2600. */
  2601. function baseExtremum(array, iteratee, comparator) {
  2602. var index = -1,
  2603. length = array.length;
  2604. while (++index < length) {
  2605. var value = array[index],
  2606. current = iteratee(value);
  2607. if (current != null && (computed === undefined
  2608. ? (current === current && !isSymbol(current))
  2609. : comparator(current, computed)
  2610. )) {
  2611. var computed = current,
  2612. result = value;
  2613. }
  2614. }
  2615. return result;
  2616. }
  2617. /**
  2618. * The base implementation of `_.fill` without an iteratee call guard.
  2619. *
  2620. * @private
  2621. * @param {Array} array The array to fill.
  2622. * @param {*} value The value to fill `array` with.
  2623. * @param {number} [start=0] The start position.
  2624. * @param {number} [end=array.length] The end position.
  2625. * @returns {Array} Returns `array`.
  2626. */
  2627. function baseFill(array, value, start, end) {
  2628. var length = array.length;
  2629. start = toInteger(start);
  2630. if (start < 0) {
  2631. start = -start > length ? 0 : (length + start);
  2632. }
  2633. end = (end === undefined || end > length) ? length : toInteger(end);
  2634. if (end < 0) {
  2635. end += length;
  2636. }
  2637. end = start > end ? 0 : toLength(end);
  2638. while (start < end) {
  2639. array[start++] = value;
  2640. }
  2641. return array;
  2642. }
  2643. /**
  2644. * The base implementation of `_.filter` without support for iteratee shorthands.
  2645. *
  2646. * @private
  2647. * @param {Array|Object} collection The collection to iterate over.
  2648. * @param {Function} predicate The function invoked per iteration.
  2649. * @returns {Array} Returns the new filtered array.
  2650. */
  2651. function baseFilter(collection, predicate) {
  2652. var result = [];
  2653. baseEach(collection, function(value, index, collection) {
  2654. if (predicate(value, index, collection)) {
  2655. result.push(value);
  2656. }
  2657. });
  2658. return result;
  2659. }
  2660. /**
  2661. * The base implementation of `_.flatten` with support for restricting flattening.
  2662. *
  2663. * @private
  2664. * @param {Array} array The array to flatten.
  2665. * @param {number} depth The maximum recursion depth.
  2666. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  2667. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  2668. * @param {Array} [result=[]] The initial result value.
  2669. * @returns {Array} Returns the new flattened array.
  2670. */
  2671. function baseFlatten(array, depth, predicate, isStrict, result) {
  2672. var index = -1,
  2673. length = array.length;
  2674. predicate || (predicate = isFlattenable);
  2675. result || (result = []);
  2676. while (++index < length) {
  2677. var value = array[index];
  2678. if (depth > 0 && predicate(value)) {
  2679. if (depth > 1) {
  2680. // Recursively flatten arrays (susceptible to call stack limits).
  2681. baseFlatten(value, depth - 1, predicate, isStrict, result);
  2682. } else {
  2683. arrayPush(result, value);
  2684. }
  2685. } else if (!isStrict) {
  2686. result[result.length] = value;
  2687. }
  2688. }
  2689. return result;
  2690. }
  2691. /**
  2692. * The base implementation of `baseForOwn` which iterates over `object`
  2693. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  2694. * Iteratee functions may exit iteration early by explicitly returning `false`.
  2695. *
  2696. * @private
  2697. * @param {Object} object The object to iterate over.
  2698. * @param {Function} iteratee The function invoked per iteration.
  2699. * @param {Function} keysFunc The function to get the keys of `object`.
  2700. * @returns {Object} Returns `object`.
  2701. */
  2702. var baseFor = createBaseFor();
  2703. /**
  2704. * This function is like `baseFor` except that it iterates over properties
  2705. * in the opposite order.
  2706. *
  2707. * @private
  2708. * @param {Object} object The object to iterate over.
  2709. * @param {Function} iteratee The function invoked per iteration.
  2710. * @param {Function} keysFunc The function to get the keys of `object`.
  2711. * @returns {Object} Returns `object`.
  2712. */
  2713. var baseForRight = createBaseFor(true);
  2714. /**
  2715. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  2716. *
  2717. * @private
  2718. * @param {Object} object The object to iterate over.
  2719. * @param {Function} iteratee The function invoked per iteration.
  2720. * @returns {Object} Returns `object`.
  2721. */
  2722. function baseForOwn(object, iteratee) {
  2723. return object && baseFor(object, iteratee, keys);
  2724. }
  2725. /**
  2726. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  2727. *
  2728. * @private
  2729. * @param {Object} object The object to iterate over.
  2730. * @param {Function} iteratee The function invoked per iteration.
  2731. * @returns {Object} Returns `object`.
  2732. */
  2733. function baseForOwnRight(object, iteratee) {
  2734. return object && baseForRight(object, iteratee, keys);
  2735. }
  2736. /**
  2737. * The base implementation of `_.functions` which creates an array of
  2738. * `object` function property names filtered from `props`.
  2739. *
  2740. * @private
  2741. * @param {Object} object The object to inspect.
  2742. * @param {Array} props The property names to filter.
  2743. * @returns {Array} Returns the function names.
  2744. */
  2745. function baseFunctions(object, props) {
  2746. return arrayFilter(props, function(key) {
  2747. return isFunction(object[key]);
  2748. });
  2749. }
  2750. /**
  2751. * The base implementation of `_.get` without support for default values.
  2752. *
  2753. * @private
  2754. * @param {Object} object The object to query.
  2755. * @param {Array|string} path The path of the property to get.
  2756. * @returns {*} Returns the resolved value.
  2757. */
  2758. function baseGet(object, path) {
  2759. path = castPath(path, object);
  2760. var index = 0,
  2761. length = path.length;
  2762. while (object != null && index < length) {
  2763. object = object[toKey(path[index++])];
  2764. }
  2765. return (index && index == length) ? object : undefined;
  2766. }
  2767. /**
  2768. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  2769. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  2770. * symbols of `object`.
  2771. *
  2772. * @private
  2773. * @param {Object} object The object to query.
  2774. * @param {Function} keysFunc The function to get the keys of `object`.
  2775. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  2776. * @returns {Array} Returns the array of property names and symbols.
  2777. */
  2778. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  2779. var result = keysFunc(object);
  2780. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  2781. }
  2782. /**
  2783. * The base implementation of `getTag` without fallbacks for buggy environments.
  2784. *
  2785. * @private
  2786. * @param {*} value The value to query.
  2787. * @returns {string} Returns the `toStringTag`.
  2788. */
  2789. function baseGetTag(value) {
  2790. if (value == null) {
  2791. return value === undefined ? undefinedTag : nullTag;
  2792. }
  2793. return (symToStringTag && symToStringTag in Object(value))
  2794. ? getRawTag(value)
  2795. : objectToString(value);
  2796. }
  2797. /**
  2798. * The base implementation of `_.gt` which doesn't coerce arguments.
  2799. *
  2800. * @private
  2801. * @param {*} value The value to compare.
  2802. * @param {*} other The other value to compare.
  2803. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  2804. * else `false`.
  2805. */
  2806. function baseGt(value, other) {
  2807. return value > other;
  2808. }
  2809. /**
  2810. * The base implementation of `_.has` without support for deep paths.
  2811. *
  2812. * @private
  2813. * @param {Object} [object] The object to query.
  2814. * @param {Array|string} key The key to check.
  2815. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2816. */
  2817. function baseHas(object, key) {
  2818. return object != null && hasOwnProperty.call(object, key);
  2819. }
  2820. /**
  2821. * The base implementation of `_.hasIn` without support for deep paths.
  2822. *
  2823. * @private
  2824. * @param {Object} [object] The object to query.
  2825. * @param {Array|string} key The key to check.
  2826. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2827. */
  2828. function baseHasIn(object, key) {
  2829. return object != null && key in Object(object);
  2830. }
  2831. /**
  2832. * The base implementation of `_.inRange` which doesn't coerce arguments.
  2833. *
  2834. * @private
  2835. * @param {number} number The number to check.
  2836. * @param {number} start The start of the range.
  2837. * @param {number} end The end of the range.
  2838. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  2839. */
  2840. function baseInRange(number, start, end) {
  2841. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  2842. }
  2843. /**
  2844. * The base implementation of methods like `_.intersection`, without support
  2845. * for iteratee shorthands, that accepts an array of arrays to inspect.
  2846. *
  2847. * @private
  2848. * @param {Array} arrays The arrays to inspect.
  2849. * @param {Function} [iteratee] The iteratee invoked per element.
  2850. * @param {Function} [comparator] The comparator invoked per element.
  2851. * @returns {Array} Returns the new array of shared values.
  2852. */
  2853. function baseIntersection(arrays, iteratee, comparator) {
  2854. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  2855. length = arrays[0].length,
  2856. othLength = arrays.length,
  2857. othIndex = othLength,
  2858. caches = Array(othLength),
  2859. maxLength = Infinity,
  2860. result = [];
  2861. while (othIndex--) {
  2862. var array = arrays[othIndex];
  2863. if (othIndex && iteratee) {
  2864. array = arrayMap(array, baseUnary(iteratee));
  2865. }
  2866. maxLength = nativeMin(array.length, maxLength);
  2867. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  2868. ? new SetCache(othIndex && array)
  2869. : undefined;
  2870. }
  2871. array = arrays[0];
  2872. var index = -1,
  2873. seen = caches[0];
  2874. outer:
  2875. while (++index < length && result.length < maxLength) {
  2876. var value = array[index],
  2877. computed = iteratee ? iteratee(value) : value;
  2878. value = (comparator || value !== 0) ? value : 0;
  2879. if (!(seen
  2880. ? cacheHas(seen, computed)
  2881. : includes(result, computed, comparator)
  2882. )) {
  2883. othIndex = othLength;
  2884. while (--othIndex) {
  2885. var cache = caches[othIndex];
  2886. if (!(cache
  2887. ? cacheHas(cache, computed)
  2888. : includes(arrays[othIndex], computed, comparator))
  2889. ) {
  2890. continue outer;
  2891. }
  2892. }
  2893. if (seen) {
  2894. seen.push(computed);
  2895. }
  2896. result.push(value);
  2897. }
  2898. }
  2899. return result;
  2900. }
  2901. /**
  2902. * The base implementation of `_.invert` and `_.invertBy` which inverts
  2903. * `object` with values transformed by `iteratee` and set by `setter`.
  2904. *
  2905. * @private
  2906. * @param {Object} object The object to iterate over.
  2907. * @param {Function} setter The function to set `accumulator` values.
  2908. * @param {Function} iteratee The iteratee to transform values.
  2909. * @param {Object} accumulator The initial inverted object.
  2910. * @returns {Function} Returns `accumulator`.
  2911. */
  2912. function baseInverter(object, setter, iteratee, accumulator) {
  2913. baseForOwn(object, function(value, key, object) {
  2914. setter(accumulator, iteratee(value), key, object);
  2915. });
  2916. return accumulator;
  2917. }
  2918. /**
  2919. * The base implementation of `_.invoke` without support for individual
  2920. * method arguments.
  2921. *
  2922. * @private
  2923. * @param {Object} object The object to query.
  2924. * @param {Array|string} path The path of the method to invoke.
  2925. * @param {Array} args The arguments to invoke the method with.
  2926. * @returns {*} Returns the result of the invoked method.
  2927. */
  2928. function baseInvoke(object, path, args) {
  2929. path = castPath(path, object);
  2930. object = parent(object, path);
  2931. var func = object == null ? object : object[toKey(last(path))];
  2932. return func == null ? undefined : apply(func, object, args);
  2933. }
  2934. /**
  2935. * The base implementation of `_.isArguments`.
  2936. *
  2937. * @private
  2938. * @param {*} value The value to check.
  2939. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2940. */
  2941. function baseIsArguments(value) {
  2942. return isObjectLike(value) && baseGetTag(value) == argsTag;
  2943. }
  2944. /**
  2945. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  2946. *
  2947. * @private
  2948. * @param {*} value The value to check.
  2949. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  2950. */
  2951. function baseIsArrayBuffer(value) {
  2952. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  2953. }
  2954. /**
  2955. * The base implementation of `_.isDate` without Node.js optimizations.
  2956. *
  2957. * @private
  2958. * @param {*} value The value to check.
  2959. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  2960. */
  2961. function baseIsDate(value) {
  2962. return isObjectLike(value) && baseGetTag(value) == dateTag;
  2963. }
  2964. /**
  2965. * The base implementation of `_.isEqual` which supports partial comparisons
  2966. * and tracks traversed objects.
  2967. *
  2968. * @private
  2969. * @param {*} value The value to compare.
  2970. * @param {*} other The other value to compare.
  2971. * @param {boolean} bitmask The bitmask flags.
  2972. * 1 - Unordered comparison
  2973. * 2 - Partial comparison
  2974. * @param {Function} [customizer] The function to customize comparisons.
  2975. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  2976. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2977. */
  2978. function baseIsEqual(value, other, bitmask, customizer, stack) {
  2979. if (value === other) {
  2980. return true;
  2981. }
  2982. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  2983. return value !== value && other !== other;
  2984. }
  2985. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  2986. }
  2987. /**
  2988. * A specialized version of `baseIsEqual` for arrays and objects which performs
  2989. * deep comparisons and tracks traversed objects enabling objects with circular
  2990. * references to be compared.
  2991. *
  2992. * @private
  2993. * @param {Object} object The object to compare.
  2994. * @param {Object} other The other object to compare.
  2995. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  2996. * @param {Function} customizer The function to customize comparisons.
  2997. * @param {Function} equalFunc The function to determine equivalents of values.
  2998. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  2999. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3000. */
  3001. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  3002. var objIsArr = isArray(object),
  3003. othIsArr = isArray(other),
  3004. objTag = objIsArr ? arrayTag : getTag(object),
  3005. othTag = othIsArr ? arrayTag : getTag(other);
  3006. objTag = objTag == argsTag ? objectTag : objTag;
  3007. othTag = othTag == argsTag ? objectTag : othTag;
  3008. var objIsObj = objTag == objectTag,
  3009. othIsObj = othTag == objectTag,
  3010. isSameTag = objTag == othTag;
  3011. if (isSameTag && isBuffer(object)) {
  3012. if (!isBuffer(other)) {
  3013. return false;
  3014. }
  3015. objIsArr = true;
  3016. objIsObj = false;
  3017. }
  3018. if (isSameTag && !objIsObj) {
  3019. stack || (stack = new Stack);
  3020. return (objIsArr || isTypedArray(object))
  3021. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  3022. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  3023. }
  3024. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  3025. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  3026. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  3027. if (objIsWrapped || othIsWrapped) {
  3028. var objUnwrapped = objIsWrapped ? object.value() : object,
  3029. othUnwrapped = othIsWrapped ? other.value() : other;
  3030. stack || (stack = new Stack);
  3031. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  3032. }
  3033. }
  3034. if (!isSameTag) {
  3035. return false;
  3036. }
  3037. stack || (stack = new Stack);
  3038. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  3039. }
  3040. /**
  3041. * The base implementation of `_.isMap` without Node.js optimizations.
  3042. *
  3043. * @private
  3044. * @param {*} value The value to check.
  3045. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  3046. */
  3047. function baseIsMap(value) {
  3048. return isObjectLike(value) && getTag(value) == mapTag;
  3049. }
  3050. /**
  3051. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  3052. *
  3053. * @private
  3054. * @param {Object} object The object to inspect.
  3055. * @param {Object} source The object of property values to match.
  3056. * @param {Array} matchData The property names, values, and compare flags to match.
  3057. * @param {Function} [customizer] The function to customize comparisons.
  3058. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  3059. */
  3060. function baseIsMatch(object, source, matchData, customizer) {
  3061. var index = matchData.length,
  3062. length = index,
  3063. noCustomizer = !customizer;
  3064. if (object == null) {
  3065. return !length;
  3066. }
  3067. object = Object(object);
  3068. while (index--) {
  3069. var data = matchData[index];
  3070. if ((noCustomizer && data[2])
  3071. ? data[1] !== object[data[0]]
  3072. : !(data[0] in object)
  3073. ) {
  3074. return false;
  3075. }
  3076. }
  3077. while (++index < length) {
  3078. data = matchData[index];
  3079. var key = data[0],
  3080. objValue = object[key],
  3081. srcValue = data[1];
  3082. if (noCustomizer && data[2]) {
  3083. if (objValue === undefined && !(key in object)) {
  3084. return false;
  3085. }
  3086. } else {
  3087. var stack = new Stack;
  3088. if (customizer) {
  3089. var result = customizer(objValue, srcValue, key, object, source, stack);
  3090. }
  3091. if (!(result === undefined
  3092. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  3093. : result
  3094. )) {
  3095. return false;
  3096. }
  3097. }
  3098. }
  3099. return true;
  3100. }
  3101. /**
  3102. * The base implementation of `_.isNative` without bad shim checks.
  3103. *
  3104. * @private
  3105. * @param {*} value The value to check.
  3106. * @returns {boolean} Returns `true` if `value` is a native function,
  3107. * else `false`.
  3108. */
  3109. function baseIsNative(value) {
  3110. if (!isObject(value) || isMasked(value)) {
  3111. return false;
  3112. }
  3113. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  3114. return pattern.test(toSource(value));
  3115. }
  3116. /**
  3117. * The base implementation of `_.isRegExp` without Node.js optimizations.
  3118. *
  3119. * @private
  3120. * @param {*} value The value to check.
  3121. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  3122. */
  3123. function baseIsRegExp(value) {
  3124. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  3125. }
  3126. /**
  3127. * The base implementation of `_.isSet` without Node.js optimizations.
  3128. *
  3129. * @private
  3130. * @param {*} value The value to check.
  3131. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  3132. */
  3133. function baseIsSet(value) {
  3134. return isObjectLike(value) && getTag(value) == setTag;
  3135. }
  3136. /**
  3137. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3138. *
  3139. * @private
  3140. * @param {*} value The value to check.
  3141. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3142. */
  3143. function baseIsTypedArray(value) {
  3144. return isObjectLike(value) &&
  3145. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  3146. }
  3147. /**
  3148. * The base implementation of `_.iteratee`.
  3149. *
  3150. * @private
  3151. * @param {*} [value=_.identity] The value to convert to an iteratee.
  3152. * @returns {Function} Returns the iteratee.
  3153. */
  3154. function baseIteratee(value) {
  3155. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  3156. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  3157. if (typeof value == 'function') {
  3158. return value;
  3159. }
  3160. if (value == null) {
  3161. return identity;
  3162. }
  3163. if (typeof value == 'object') {
  3164. return isArray(value)
  3165. ? baseMatchesProperty(value[0], value[1])
  3166. : baseMatches(value);
  3167. }
  3168. return property(value);
  3169. }
  3170. /**
  3171. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3172. *
  3173. * @private
  3174. * @param {Object} object The object to query.
  3175. * @returns {Array} Returns the array of property names.
  3176. */
  3177. function baseKeys(object) {
  3178. if (!isPrototype(object)) {
  3179. return nativeKeys(object);
  3180. }
  3181. var result = [];
  3182. for (var key in Object(object)) {
  3183. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  3184. result.push(key);
  3185. }
  3186. }
  3187. return result;
  3188. }
  3189. /**
  3190. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  3191. *
  3192. * @private
  3193. * @param {Object} object The object to query.
  3194. * @returns {Array} Returns the array of property names.
  3195. */
  3196. function baseKeysIn(object) {
  3197. if (!isObject(object)) {
  3198. return nativeKeysIn(object);
  3199. }
  3200. var isProto = isPrototype(object),
  3201. result = [];
  3202. for (var key in object) {
  3203. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  3204. result.push(key);
  3205. }
  3206. }
  3207. return result;
  3208. }
  3209. /**
  3210. * The base implementation of `_.lt` which doesn't coerce arguments.
  3211. *
  3212. * @private
  3213. * @param {*} value The value to compare.
  3214. * @param {*} other The other value to compare.
  3215. * @returns {boolean} Returns `true` if `value` is less than `other`,
  3216. * else `false`.
  3217. */
  3218. function baseLt(value, other) {
  3219. return value < other;
  3220. }
  3221. /**
  3222. * The base implementation of `_.map` without support for iteratee shorthands.
  3223. *
  3224. * @private
  3225. * @param {Array|Object} collection The collection to iterate over.
  3226. * @param {Function} iteratee The function invoked per iteration.
  3227. * @returns {Array} Returns the new mapped array.
  3228. */
  3229. function baseMap(collection, iteratee) {
  3230. var index = -1,
  3231. result = isArrayLike(collection) ? Array(collection.length) : [];
  3232. baseEach(collection, function(value, key, collection) {
  3233. result[++index] = iteratee(value, key, collection);
  3234. });
  3235. return result;
  3236. }
  3237. /**
  3238. * The base implementation of `_.matches` which doesn't clone `source`.
  3239. *
  3240. * @private
  3241. * @param {Object} source The object of property values to match.
  3242. * @returns {Function} Returns the new spec function.
  3243. */
  3244. function baseMatches(source) {
  3245. var matchData = getMatchData(source);
  3246. if (matchData.length == 1 && matchData[0][2]) {
  3247. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  3248. }
  3249. return function(object) {
  3250. return object === source || baseIsMatch(object, source, matchData);
  3251. };
  3252. }
  3253. /**
  3254. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  3255. *
  3256. * @private
  3257. * @param {string} path The path of the property to get.
  3258. * @param {*} srcValue The value to match.
  3259. * @returns {Function} Returns the new spec function.
  3260. */
  3261. function baseMatchesProperty(path, srcValue) {
  3262. if (isKey(path) && isStrictComparable(srcValue)) {
  3263. return matchesStrictComparable(toKey(path), srcValue);
  3264. }
  3265. return function(object) {
  3266. var objValue = get(object, path);
  3267. return (objValue === undefined && objValue === srcValue)
  3268. ? hasIn(object, path)
  3269. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  3270. };
  3271. }
  3272. /**
  3273. * The base implementation of `_.merge` without support for multiple sources.
  3274. *
  3275. * @private
  3276. * @param {Object} object The destination object.
  3277. * @param {Object} source The source object.
  3278. * @param {number} srcIndex The index of `source`.
  3279. * @param {Function} [customizer] The function to customize merged values.
  3280. * @param {Object} [stack] Tracks traversed source values and their merged
  3281. * counterparts.
  3282. */
  3283. function baseMerge(object, source, srcIndex, customizer, stack) {
  3284. if (object === source) {
  3285. return;
  3286. }
  3287. baseFor(source, function(srcValue, key) {
  3288. if (isObject(srcValue)) {
  3289. stack || (stack = new Stack);
  3290. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  3291. }
  3292. else {
  3293. var newValue = customizer
  3294. ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
  3295. : undefined;
  3296. if (newValue === undefined) {
  3297. newValue = srcValue;
  3298. }
  3299. assignMergeValue(object, key, newValue);
  3300. }
  3301. }, keysIn);
  3302. }
  3303. /**
  3304. * A specialized version of `baseMerge` for arrays and objects which performs
  3305. * deep merges and tracks traversed objects enabling objects with circular
  3306. * references to be merged.
  3307. *
  3308. * @private
  3309. * @param {Object} object The destination object.
  3310. * @param {Object} source The source object.
  3311. * @param {string} key The key of the value to merge.
  3312. * @param {number} srcIndex The index of `source`.
  3313. * @param {Function} mergeFunc The function to merge values.
  3314. * @param {Function} [customizer] The function to customize assigned values.
  3315. * @param {Object} [stack] Tracks traversed source values and their merged
  3316. * counterparts.
  3317. */
  3318. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  3319. var objValue = safeGet(object, key),
  3320. srcValue = safeGet(source, key),
  3321. stacked = stack.get(srcValue);
  3322. if (stacked) {
  3323. assignMergeValue(object, key, stacked);
  3324. return;
  3325. }
  3326. var newValue = customizer
  3327. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  3328. : undefined;
  3329. var isCommon = newValue === undefined;
  3330. if (isCommon) {
  3331. var isArr = isArray(srcValue),
  3332. isBuff = !isArr && isBuffer(srcValue),
  3333. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  3334. newValue = srcValue;
  3335. if (isArr || isBuff || isTyped) {
  3336. if (isArray(objValue)) {
  3337. newValue = objValue;
  3338. }
  3339. else if (isArrayLikeObject(objValue)) {
  3340. newValue = copyArray(objValue);
  3341. }
  3342. else if (isBuff) {
  3343. isCommon = false;
  3344. newValue = cloneBuffer(srcValue, true);
  3345. }
  3346. else if (isTyped) {
  3347. isCommon = false;
  3348. newValue = cloneTypedArray(srcValue, true);
  3349. }
  3350. else {
  3351. newValue = [];
  3352. }
  3353. }
  3354. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  3355. newValue = objValue;
  3356. if (isArguments(objValue)) {
  3357. newValue = toPlainObject(objValue);
  3358. }
  3359. else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
  3360. newValue = initCloneObject(srcValue);
  3361. }
  3362. }
  3363. else {
  3364. isCommon = false;
  3365. }
  3366. }
  3367. if (isCommon) {
  3368. // Recursively merge objects and arrays (susceptible to call stack limits).
  3369. stack.set(srcValue, newValue);
  3370. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  3371. stack['delete'](srcValue);
  3372. }
  3373. assignMergeValue(object, key, newValue);
  3374. }
  3375. /**
  3376. * The base implementation of `_.nth` which doesn't coerce arguments.
  3377. *
  3378. * @private
  3379. * @param {Array} array The array to query.
  3380. * @param {number} n The index of the element to return.
  3381. * @returns {*} Returns the nth element of `array`.
  3382. */
  3383. function baseNth(array, n) {
  3384. var length = array.length;
  3385. if (!length) {
  3386. return;
  3387. }
  3388. n += n < 0 ? length : 0;
  3389. return isIndex(n, length) ? array[n] : undefined;
  3390. }
  3391. /**
  3392. * The base implementation of `_.orderBy` without param guards.
  3393. *
  3394. * @private
  3395. * @param {Array|Object} collection The collection to iterate over.
  3396. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  3397. * @param {string[]} orders The sort orders of `iteratees`.
  3398. * @returns {Array} Returns the new sorted array.
  3399. */
  3400. function baseOrderBy(collection, iteratees, orders) {
  3401. var index = -1;
  3402. iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
  3403. var result = baseMap(collection, function(value, key, collection) {
  3404. var criteria = arrayMap(iteratees, function(iteratee) {
  3405. return iteratee(value);
  3406. });
  3407. return { 'criteria': criteria, 'index': ++index, 'value': value };
  3408. });
  3409. return baseSortBy(result, function(object, other) {
  3410. return compareMultiple(object, other, orders);
  3411. });
  3412. }
  3413. /**
  3414. * The base implementation of `_.pick` without support for individual
  3415. * property identifiers.
  3416. *
  3417. * @private
  3418. * @param {Object} object The source object.
  3419. * @param {string[]} paths The property paths to pick.
  3420. * @returns {Object} Returns the new object.
  3421. */
  3422. function basePick(object, paths) {
  3423. return basePickBy(object, paths, function(value, path) {
  3424. return hasIn(object, path);
  3425. });
  3426. }
  3427. /**
  3428. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3429. *
  3430. * @private
  3431. * @param {Object} object The source object.
  3432. * @param {string[]} paths The property paths to pick.
  3433. * @param {Function} predicate The function invoked per property.
  3434. * @returns {Object} Returns the new object.
  3435. */
  3436. function basePickBy(object, paths, predicate) {
  3437. var index = -1,
  3438. length = paths.length,
  3439. result = {};
  3440. while (++index < length) {
  3441. var path = paths[index],
  3442. value = baseGet(object, path);
  3443. if (predicate(value, path)) {
  3444. baseSet(result, castPath(path, object), value);
  3445. }
  3446. }
  3447. return result;
  3448. }
  3449. /**
  3450. * A specialized version of `baseProperty` which supports deep paths.
  3451. *
  3452. * @private
  3453. * @param {Array|string} path The path of the property to get.
  3454. * @returns {Function} Returns the new accessor function.
  3455. */
  3456. function basePropertyDeep(path) {
  3457. return function(object) {
  3458. return baseGet(object, path);
  3459. };
  3460. }
  3461. /**
  3462. * The base implementation of `_.pullAllBy` without support for iteratee
  3463. * shorthands.
  3464. *
  3465. * @private
  3466. * @param {Array} array The array to modify.
  3467. * @param {Array} values The values to remove.
  3468. * @param {Function} [iteratee] The iteratee invoked per element.
  3469. * @param {Function} [comparator] The comparator invoked per element.
  3470. * @returns {Array} Returns `array`.
  3471. */
  3472. function basePullAll(array, values, iteratee, comparator) {
  3473. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3474. index = -1,
  3475. length = values.length,
  3476. seen = array;
  3477. if (array === values) {
  3478. values = copyArray(values);
  3479. }
  3480. if (iteratee) {
  3481. seen = arrayMap(array, baseUnary(iteratee));
  3482. }
  3483. while (++index < length) {
  3484. var fromIndex = 0,
  3485. value = values[index],
  3486. computed = iteratee ? iteratee(value) : value;
  3487. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  3488. if (seen !== array) {
  3489. splice.call(seen, fromIndex, 1);
  3490. }
  3491. splice.call(array, fromIndex, 1);
  3492. }
  3493. }
  3494. return array;
  3495. }
  3496. /**
  3497. * The base implementation of `_.pullAt` without support for individual
  3498. * indexes or capturing the removed elements.
  3499. *
  3500. * @private
  3501. * @param {Array} array The array to modify.
  3502. * @param {number[]} indexes The indexes of elements to remove.
  3503. * @returns {Array} Returns `array`.
  3504. */
  3505. function basePullAt(array, indexes) {
  3506. var length = array ? indexes.length : 0,
  3507. lastIndex = length - 1;
  3508. while (length--) {
  3509. var index = indexes[length];
  3510. if (length == lastIndex || index !== previous) {
  3511. var previous = index;
  3512. if (isIndex(index)) {
  3513. splice.call(array, index, 1);
  3514. } else {
  3515. baseUnset(array, index);
  3516. }
  3517. }
  3518. }
  3519. return array;
  3520. }
  3521. /**
  3522. * The base implementation of `_.random` without support for returning
  3523. * floating-point numbers.
  3524. *
  3525. * @private
  3526. * @param {number} lower The lower bound.
  3527. * @param {number} upper The upper bound.
  3528. * @returns {number} Returns the random number.
  3529. */
  3530. function baseRandom(lower, upper) {
  3531. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3532. }
  3533. /**
  3534. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3535. * coerce arguments.
  3536. *
  3537. * @private
  3538. * @param {number} start The start of the range.
  3539. * @param {number} end The end of the range.
  3540. * @param {number} step The value to increment or decrement by.
  3541. * @param {boolean} [fromRight] Specify iterating from right to left.
  3542. * @returns {Array} Returns the range of numbers.
  3543. */
  3544. function baseRange(start, end, step, fromRight) {
  3545. var index = -1,
  3546. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3547. result = Array(length);
  3548. while (length--) {
  3549. result[fromRight ? length : ++index] = start;
  3550. start += step;
  3551. }
  3552. return result;
  3553. }
  3554. /**
  3555. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3556. *
  3557. * @private
  3558. * @param {string} string The string to repeat.
  3559. * @param {number} n The number of times to repeat the string.
  3560. * @returns {string} Returns the repeated string.
  3561. */
  3562. function baseRepeat(string, n) {
  3563. var result = '';
  3564. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3565. return result;
  3566. }
  3567. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3568. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3569. do {
  3570. if (n % 2) {
  3571. result += string;
  3572. }
  3573. n = nativeFloor(n / 2);
  3574. if (n) {
  3575. string += string;
  3576. }
  3577. } while (n);
  3578. return result;
  3579. }
  3580. /**
  3581. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3582. *
  3583. * @private
  3584. * @param {Function} func The function to apply a rest parameter to.
  3585. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3586. * @returns {Function} Returns the new function.
  3587. */
  3588. function baseRest(func, start) {
  3589. return setToString(overRest(func, start, identity), func + '');
  3590. }
  3591. /**
  3592. * The base implementation of `_.sample`.
  3593. *
  3594. * @private
  3595. * @param {Array|Object} collection The collection to sample.
  3596. * @returns {*} Returns the random element.
  3597. */
  3598. function baseSample(collection) {
  3599. return arraySample(values(collection));
  3600. }
  3601. /**
  3602. * The base implementation of `_.sampleSize` without param guards.
  3603. *
  3604. * @private
  3605. * @param {Array|Object} collection The collection to sample.
  3606. * @param {number} n The number of elements to sample.
  3607. * @returns {Array} Returns the random elements.
  3608. */
  3609. function baseSampleSize(collection, n) {
  3610. var array = values(collection);
  3611. return shuffleSelf(array, baseClamp(n, 0, array.length));
  3612. }
  3613. /**
  3614. * The base implementation of `_.set`.
  3615. *
  3616. * @private
  3617. * @param {Object} object The object to modify.
  3618. * @param {Array|string} path The path of the property to set.
  3619. * @param {*} value The value to set.
  3620. * @param {Function} [customizer] The function to customize path creation.
  3621. * @returns {Object} Returns `object`.
  3622. */
  3623. function baseSet(object, path, value, customizer) {
  3624. if (!isObject(object)) {
  3625. return object;
  3626. }
  3627. path = castPath(path, object);
  3628. var index = -1,
  3629. length = path.length,
  3630. lastIndex = length - 1,
  3631. nested = object;
  3632. while (nested != null && ++index < length) {
  3633. var key = toKey(path[index]),
  3634. newValue = value;
  3635. if (index != lastIndex) {
  3636. var objValue = nested[key];
  3637. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  3638. if (newValue === undefined) {
  3639. newValue = isObject(objValue)
  3640. ? objValue
  3641. : (isIndex(path[index + 1]) ? [] : {});
  3642. }
  3643. }
  3644. assignValue(nested, key, newValue);
  3645. nested = nested[key];
  3646. }
  3647. return object;
  3648. }
  3649. /**
  3650. * The base implementation of `setData` without support for hot loop shorting.
  3651. *
  3652. * @private
  3653. * @param {Function} func The function to associate metadata with.
  3654. * @param {*} data The metadata.
  3655. * @returns {Function} Returns `func`.
  3656. */
  3657. var baseSetData = !metaMap ? identity : function(func, data) {
  3658. metaMap.set(func, data);
  3659. return func;
  3660. };
  3661. /**
  3662. * The base implementation of `setToString` without support for hot loop shorting.
  3663. *
  3664. * @private
  3665. * @param {Function} func The function to modify.
  3666. * @param {Function} string The `toString` result.
  3667. * @returns {Function} Returns `func`.
  3668. */
  3669. var baseSetToString = !defineProperty ? identity : function(func, string) {
  3670. return defineProperty(func, 'toString', {
  3671. 'configurable': true,
  3672. 'enumerable': false,
  3673. 'value': constant(string),
  3674. 'writable': true
  3675. });
  3676. };
  3677. /**
  3678. * The base implementation of `_.shuffle`.
  3679. *
  3680. * @private
  3681. * @param {Array|Object} collection The collection to shuffle.
  3682. * @returns {Array} Returns the new shuffled array.
  3683. */
  3684. function baseShuffle(collection) {
  3685. return shuffleSelf(values(collection));
  3686. }
  3687. /**
  3688. * The base implementation of `_.slice` without an iteratee call guard.
  3689. *
  3690. * @private
  3691. * @param {Array} array The array to slice.
  3692. * @param {number} [start=0] The start position.
  3693. * @param {number} [end=array.length] The end position.
  3694. * @returns {Array} Returns the slice of `array`.
  3695. */
  3696. function baseSlice(array, start, end) {
  3697. var index = -1,
  3698. length = array.length;
  3699. if (start < 0) {
  3700. start = -start > length ? 0 : (length + start);
  3701. }
  3702. end = end > length ? length : end;
  3703. if (end < 0) {
  3704. end += length;
  3705. }
  3706. length = start > end ? 0 : ((end - start) >>> 0);
  3707. start >>>= 0;
  3708. var result = Array(length);
  3709. while (++index < length) {
  3710. result[index] = array[index + start];
  3711. }
  3712. return result;
  3713. }
  3714. /**
  3715. * The base implementation of `_.some` without support for iteratee shorthands.
  3716. *
  3717. * @private
  3718. * @param {Array|Object} collection The collection to iterate over.
  3719. * @param {Function} predicate The function invoked per iteration.
  3720. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3721. * else `false`.
  3722. */
  3723. function baseSome(collection, predicate) {
  3724. var result;
  3725. baseEach(collection, function(value, index, collection) {
  3726. result = predicate(value, index, collection);
  3727. return !result;
  3728. });
  3729. return !!result;
  3730. }
  3731. /**
  3732. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  3733. * performs a binary search of `array` to determine the index at which `value`
  3734. * should be inserted into `array` in order to maintain its sort order.
  3735. *
  3736. * @private
  3737. * @param {Array} array The sorted array to inspect.
  3738. * @param {*} value The value to evaluate.
  3739. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3740. * @returns {number} Returns the index at which `value` should be inserted
  3741. * into `array`.
  3742. */
  3743. function baseSortedIndex(array, value, retHighest) {
  3744. var low = 0,
  3745. high = array == null ? low : array.length;
  3746. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  3747. while (low < high) {
  3748. var mid = (low + high) >>> 1,
  3749. computed = array[mid];
  3750. if (computed !== null && !isSymbol(computed) &&
  3751. (retHighest ? (computed <= value) : (computed < value))) {
  3752. low = mid + 1;
  3753. } else {
  3754. high = mid;
  3755. }
  3756. }
  3757. return high;
  3758. }
  3759. return baseSortedIndexBy(array, value, identity, retHighest);
  3760. }
  3761. /**
  3762. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  3763. * which invokes `iteratee` for `value` and each element of `array` to compute
  3764. * their sort ranking. The iteratee is invoked with one argument; (value).
  3765. *
  3766. * @private
  3767. * @param {Array} array The sorted array to inspect.
  3768. * @param {*} value The value to evaluate.
  3769. * @param {Function} iteratee The iteratee invoked per element.
  3770. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3771. * @returns {number} Returns the index at which `value` should be inserted
  3772. * into `array`.
  3773. */
  3774. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  3775. value = iteratee(value);
  3776. var low = 0,
  3777. high = array == null ? 0 : array.length,
  3778. valIsNaN = value !== value,
  3779. valIsNull = value === null,
  3780. valIsSymbol = isSymbol(value),
  3781. valIsUndefined = value === undefined;
  3782. while (low < high) {
  3783. var mid = nativeFloor((low + high) / 2),
  3784. computed = iteratee(array[mid]),
  3785. othIsDefined = computed !== undefined,
  3786. othIsNull = computed === null,
  3787. othIsReflexive = computed === computed,
  3788. othIsSymbol = isSymbol(computed);
  3789. if (valIsNaN) {
  3790. var setLow = retHighest || othIsReflexive;
  3791. } else if (valIsUndefined) {
  3792. setLow = othIsReflexive && (retHighest || othIsDefined);
  3793. } else if (valIsNull) {
  3794. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  3795. } else if (valIsSymbol) {
  3796. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  3797. } else if (othIsNull || othIsSymbol) {
  3798. setLow = false;
  3799. } else {
  3800. setLow = retHighest ? (computed <= value) : (computed < value);
  3801. }
  3802. if (setLow) {
  3803. low = mid + 1;
  3804. } else {
  3805. high = mid;
  3806. }
  3807. }
  3808. return nativeMin(high, MAX_ARRAY_INDEX);
  3809. }
  3810. /**
  3811. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  3812. * support for iteratee shorthands.
  3813. *
  3814. * @private
  3815. * @param {Array} array The array to inspect.
  3816. * @param {Function} [iteratee] The iteratee invoked per element.
  3817. * @returns {Array} Returns the new duplicate free array.
  3818. */
  3819. function baseSortedUniq(array, iteratee) {
  3820. var index = -1,
  3821. length = array.length,
  3822. resIndex = 0,
  3823. result = [];
  3824. while (++index < length) {
  3825. var value = array[index],
  3826. computed = iteratee ? iteratee(value) : value;
  3827. if (!index || !eq(computed, seen)) {
  3828. var seen = computed;
  3829. result[resIndex++] = value === 0 ? 0 : value;
  3830. }
  3831. }
  3832. return result;
  3833. }
  3834. /**
  3835. * The base implementation of `_.toNumber` which doesn't ensure correct
  3836. * conversions of binary, hexadecimal, or octal string values.
  3837. *
  3838. * @private
  3839. * @param {*} value The value to process.
  3840. * @returns {number} Returns the number.
  3841. */
  3842. function baseToNumber(value) {
  3843. if (typeof value == 'number') {
  3844. return value;
  3845. }
  3846. if (isSymbol(value)) {
  3847. return NAN;
  3848. }
  3849. return +value;
  3850. }
  3851. /**
  3852. * The base implementation of `_.toString` which doesn't convert nullish
  3853. * values to empty strings.
  3854. *
  3855. * @private
  3856. * @param {*} value The value to process.
  3857. * @returns {string} Returns the string.
  3858. */
  3859. function baseToString(value) {
  3860. // Exit early for strings to avoid a performance hit in some environments.
  3861. if (typeof value == 'string') {
  3862. return value;
  3863. }
  3864. if (isArray(value)) {
  3865. // Recursively convert values (susceptible to call stack limits).
  3866. return arrayMap(value, baseToString) + '';
  3867. }
  3868. if (isSymbol(value)) {
  3869. return symbolToString ? symbolToString.call(value) : '';
  3870. }
  3871. var result = (value + '');
  3872. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3873. }
  3874. /**
  3875. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  3876. *
  3877. * @private
  3878. * @param {Array} array The array to inspect.
  3879. * @param {Function} [iteratee] The iteratee invoked per element.
  3880. * @param {Function} [comparator] The comparator invoked per element.
  3881. * @returns {Array} Returns the new duplicate free array.
  3882. */
  3883. function baseUniq(array, iteratee, comparator) {
  3884. var index = -1,
  3885. includes = arrayIncludes,
  3886. length = array.length,
  3887. isCommon = true,
  3888. result = [],
  3889. seen = result;
  3890. if (comparator) {
  3891. isCommon = false;
  3892. includes = arrayIncludesWith;
  3893. }
  3894. else if (length >= LARGE_ARRAY_SIZE) {
  3895. var set = iteratee ? null : createSet(array);
  3896. if (set) {
  3897. return setToArray(set);
  3898. }
  3899. isCommon = false;
  3900. includes = cacheHas;
  3901. seen = new SetCache;
  3902. }
  3903. else {
  3904. seen = iteratee ? [] : result;
  3905. }
  3906. outer:
  3907. while (++index < length) {
  3908. var value = array[index],
  3909. computed = iteratee ? iteratee(value) : value;
  3910. value = (comparator || value !== 0) ? value : 0;
  3911. if (isCommon && computed === computed) {
  3912. var seenIndex = seen.length;
  3913. while (seenIndex--) {
  3914. if (seen[seenIndex] === computed) {
  3915. continue outer;
  3916. }
  3917. }
  3918. if (iteratee) {
  3919. seen.push(computed);
  3920. }
  3921. result.push(value);
  3922. }
  3923. else if (!includes(seen, computed, comparator)) {
  3924. if (seen !== result) {
  3925. seen.push(computed);
  3926. }
  3927. result.push(value);
  3928. }
  3929. }
  3930. return result;
  3931. }
  3932. /**
  3933. * The base implementation of `_.unset`.
  3934. *
  3935. * @private
  3936. * @param {Object} object The object to modify.
  3937. * @param {Array|string} path The property path to unset.
  3938. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  3939. */
  3940. function baseUnset(object, path) {
  3941. path = castPath(path, object);
  3942. object = parent(object, path);
  3943. return object == null || delete object[toKey(last(path))];
  3944. }
  3945. /**
  3946. * The base implementation of `_.update`.
  3947. *
  3948. * @private
  3949. * @param {Object} object The object to modify.
  3950. * @param {Array|string} path The path of the property to update.
  3951. * @param {Function} updater The function to produce the updated value.
  3952. * @param {Function} [customizer] The function to customize path creation.
  3953. * @returns {Object} Returns `object`.
  3954. */
  3955. function baseUpdate(object, path, updater, customizer) {
  3956. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  3957. }
  3958. /**
  3959. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  3960. * without support for iteratee shorthands.
  3961. *
  3962. * @private
  3963. * @param {Array} array The array to query.
  3964. * @param {Function} predicate The function invoked per iteration.
  3965. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  3966. * @param {boolean} [fromRight] Specify iterating from right to left.
  3967. * @returns {Array} Returns the slice of `array`.
  3968. */
  3969. function baseWhile(array, predicate, isDrop, fromRight) {
  3970. var length = array.length,
  3971. index = fromRight ? length : -1;
  3972. while ((fromRight ? index-- : ++index < length) &&
  3973. predicate(array[index], index, array)) {}
  3974. return isDrop
  3975. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  3976. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  3977. }
  3978. /**
  3979. * The base implementation of `wrapperValue` which returns the result of
  3980. * performing a sequence of actions on the unwrapped `value`, where each
  3981. * successive action is supplied the return value of the previous.
  3982. *
  3983. * @private
  3984. * @param {*} value The unwrapped value.
  3985. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  3986. * @returns {*} Returns the resolved value.
  3987. */
  3988. function baseWrapperValue(value, actions) {
  3989. var result = value;
  3990. if (result instanceof LazyWrapper) {
  3991. result = result.value();
  3992. }
  3993. return arrayReduce(actions, function(result, action) {
  3994. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  3995. }, result);
  3996. }
  3997. /**
  3998. * The base implementation of methods like `_.xor`, without support for
  3999. * iteratee shorthands, that accepts an array of arrays to inspect.
  4000. *
  4001. * @private
  4002. * @param {Array} arrays The arrays to inspect.
  4003. * @param {Function} [iteratee] The iteratee invoked per element.
  4004. * @param {Function} [comparator] The comparator invoked per element.
  4005. * @returns {Array} Returns the new array of values.
  4006. */
  4007. function baseXor(arrays, iteratee, comparator) {
  4008. var length = arrays.length;
  4009. if (length < 2) {
  4010. return length ? baseUniq(arrays[0]) : [];
  4011. }
  4012. var index = -1,
  4013. result = Array(length);
  4014. while (++index < length) {
  4015. var array = arrays[index],
  4016. othIndex = -1;
  4017. while (++othIndex < length) {
  4018. if (othIndex != index) {
  4019. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  4020. }
  4021. }
  4022. }
  4023. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  4024. }
  4025. /**
  4026. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  4027. *
  4028. * @private
  4029. * @param {Array} props The property identifiers.
  4030. * @param {Array} values The property values.
  4031. * @param {Function} assignFunc The function to assign values.
  4032. * @returns {Object} Returns the new object.
  4033. */
  4034. function baseZipObject(props, values, assignFunc) {
  4035. var index = -1,
  4036. length = props.length,
  4037. valsLength = values.length,
  4038. result = {};
  4039. while (++index < length) {
  4040. var value = index < valsLength ? values[index] : undefined;
  4041. assignFunc(result, props[index], value);
  4042. }
  4043. return result;
  4044. }
  4045. /**
  4046. * Casts `value` to an empty array if it's not an array like object.
  4047. *
  4048. * @private
  4049. * @param {*} value The value to inspect.
  4050. * @returns {Array|Object} Returns the cast array-like object.
  4051. */
  4052. function castArrayLikeObject(value) {
  4053. return isArrayLikeObject(value) ? value : [];
  4054. }
  4055. /**
  4056. * Casts `value` to `identity` if it's not a function.
  4057. *
  4058. * @private
  4059. * @param {*} value The value to inspect.
  4060. * @returns {Function} Returns cast function.
  4061. */
  4062. function castFunction(value) {
  4063. return typeof value == 'function' ? value : identity;
  4064. }
  4065. /**
  4066. * Casts `value` to a path array if it's not one.
  4067. *
  4068. * @private
  4069. * @param {*} value The value to inspect.
  4070. * @param {Object} [object] The object to query keys on.
  4071. * @returns {Array} Returns the cast property path array.
  4072. */
  4073. function castPath(value, object) {
  4074. if (isArray(value)) {
  4075. return value;
  4076. }
  4077. return isKey(value, object) ? [value] : stringToPath(toString(value));
  4078. }
  4079. /**
  4080. * A `baseRest` alias which can be replaced with `identity` by module
  4081. * replacement plugins.
  4082. *
  4083. * @private
  4084. * @type {Function}
  4085. * @param {Function} func The function to apply a rest parameter to.
  4086. * @returns {Function} Returns the new function.
  4087. */
  4088. var castRest = baseRest;
  4089. /**
  4090. * Casts `array` to a slice if it's needed.
  4091. *
  4092. * @private
  4093. * @param {Array} array The array to inspect.
  4094. * @param {number} start The start position.
  4095. * @param {number} [end=array.length] The end position.
  4096. * @returns {Array} Returns the cast slice.
  4097. */
  4098. function castSlice(array, start, end) {
  4099. var length = array.length;
  4100. end = end === undefined ? length : end;
  4101. return (!start && end >= length) ? array : baseSlice(array, start, end);
  4102. }
  4103. /**
  4104. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  4105. *
  4106. * @private
  4107. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  4108. */
  4109. var clearTimeout = ctxClearTimeout || function(id) {
  4110. return root.clearTimeout(id);
  4111. };
  4112. /**
  4113. * Creates a clone of `buffer`.
  4114. *
  4115. * @private
  4116. * @param {Buffer} buffer The buffer to clone.
  4117. * @param {boolean} [isDeep] Specify a deep clone.
  4118. * @returns {Buffer} Returns the cloned buffer.
  4119. */
  4120. function cloneBuffer(buffer, isDeep) {
  4121. if (isDeep) {
  4122. return buffer.slice();
  4123. }
  4124. var length = buffer.length,
  4125. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  4126. buffer.copy(result);
  4127. return result;
  4128. }
  4129. /**
  4130. * Creates a clone of `arrayBuffer`.
  4131. *
  4132. * @private
  4133. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  4134. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4135. */
  4136. function cloneArrayBuffer(arrayBuffer) {
  4137. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  4138. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  4139. return result;
  4140. }
  4141. /**
  4142. * Creates a clone of `dataView`.
  4143. *
  4144. * @private
  4145. * @param {Object} dataView The data view to clone.
  4146. * @param {boolean} [isDeep] Specify a deep clone.
  4147. * @returns {Object} Returns the cloned data view.
  4148. */
  4149. function cloneDataView(dataView, isDeep) {
  4150. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  4151. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  4152. }
  4153. /**
  4154. * Creates a clone of `regexp`.
  4155. *
  4156. * @private
  4157. * @param {Object} regexp The regexp to clone.
  4158. * @returns {Object} Returns the cloned regexp.
  4159. */
  4160. function cloneRegExp(regexp) {
  4161. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  4162. result.lastIndex = regexp.lastIndex;
  4163. return result;
  4164. }
  4165. /**
  4166. * Creates a clone of the `symbol` object.
  4167. *
  4168. * @private
  4169. * @param {Object} symbol The symbol object to clone.
  4170. * @returns {Object} Returns the cloned symbol object.
  4171. */
  4172. function cloneSymbol(symbol) {
  4173. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  4174. }
  4175. /**
  4176. * Creates a clone of `typedArray`.
  4177. *
  4178. * @private
  4179. * @param {Object} typedArray The typed array to clone.
  4180. * @param {boolean} [isDeep] Specify a deep clone.
  4181. * @returns {Object} Returns the cloned typed array.
  4182. */
  4183. function cloneTypedArray(typedArray, isDeep) {
  4184. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  4185. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  4186. }
  4187. /**
  4188. * Compares values to sort them in ascending order.
  4189. *
  4190. * @private
  4191. * @param {*} value The value to compare.
  4192. * @param {*} other The other value to compare.
  4193. * @returns {number} Returns the sort order indicator for `value`.
  4194. */
  4195. function compareAscending(value, other) {
  4196. if (value !== other) {
  4197. var valIsDefined = value !== undefined,
  4198. valIsNull = value === null,
  4199. valIsReflexive = value === value,
  4200. valIsSymbol = isSymbol(value);
  4201. var othIsDefined = other !== undefined,
  4202. othIsNull = other === null,
  4203. othIsReflexive = other === other,
  4204. othIsSymbol = isSymbol(other);
  4205. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  4206. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  4207. (valIsNull && othIsDefined && othIsReflexive) ||
  4208. (!valIsDefined && othIsReflexive) ||
  4209. !valIsReflexive) {
  4210. return 1;
  4211. }
  4212. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  4213. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  4214. (othIsNull && valIsDefined && valIsReflexive) ||
  4215. (!othIsDefined && valIsReflexive) ||
  4216. !othIsReflexive) {
  4217. return -1;
  4218. }
  4219. }
  4220. return 0;
  4221. }
  4222. /**
  4223. * Used by `_.orderBy` to compare multiple properties of a value to another
  4224. * and stable sort them.
  4225. *
  4226. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  4227. * specify an order of "desc" for descending or "asc" for ascending sort order
  4228. * of corresponding values.
  4229. *
  4230. * @private
  4231. * @param {Object} object The object to compare.
  4232. * @param {Object} other The other object to compare.
  4233. * @param {boolean[]|string[]} orders The order to sort by for each property.
  4234. * @returns {number} Returns the sort order indicator for `object`.
  4235. */
  4236. function compareMultiple(object, other, orders) {
  4237. var index = -1,
  4238. objCriteria = object.criteria,
  4239. othCriteria = other.criteria,
  4240. length = objCriteria.length,
  4241. ordersLength = orders.length;
  4242. while (++index < length) {
  4243. var result = compareAscending(objCriteria[index], othCriteria[index]);
  4244. if (result) {
  4245. if (index >= ordersLength) {
  4246. return result;
  4247. }
  4248. var order = orders[index];
  4249. return result * (order == 'desc' ? -1 : 1);
  4250. }
  4251. }
  4252. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  4253. // that causes it, under certain circumstances, to provide the same value for
  4254. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  4255. // for more details.
  4256. //
  4257. // This also ensures a stable sort in V8 and other engines.
  4258. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  4259. return object.index - other.index;
  4260. }
  4261. /**
  4262. * Creates an array that is the composition of partially applied arguments,
  4263. * placeholders, and provided arguments into a single array of arguments.
  4264. *
  4265. * @private
  4266. * @param {Array} args The provided arguments.
  4267. * @param {Array} partials The arguments to prepend to those provided.
  4268. * @param {Array} holders The `partials` placeholder indexes.
  4269. * @params {boolean} [isCurried] Specify composing for a curried function.
  4270. * @returns {Array} Returns the new array of composed arguments.
  4271. */
  4272. function composeArgs(args, partials, holders, isCurried) {
  4273. var argsIndex = -1,
  4274. argsLength = args.length,
  4275. holdersLength = holders.length,
  4276. leftIndex = -1,
  4277. leftLength = partials.length,
  4278. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4279. result = Array(leftLength + rangeLength),
  4280. isUncurried = !isCurried;
  4281. while (++leftIndex < leftLength) {
  4282. result[leftIndex] = partials[leftIndex];
  4283. }
  4284. while (++argsIndex < holdersLength) {
  4285. if (isUncurried || argsIndex < argsLength) {
  4286. result[holders[argsIndex]] = args[argsIndex];
  4287. }
  4288. }
  4289. while (rangeLength--) {
  4290. result[leftIndex++] = args[argsIndex++];
  4291. }
  4292. return result;
  4293. }
  4294. /**
  4295. * This function is like `composeArgs` except that the arguments composition
  4296. * is tailored for `_.partialRight`.
  4297. *
  4298. * @private
  4299. * @param {Array} args The provided arguments.
  4300. * @param {Array} partials The arguments to append to those provided.
  4301. * @param {Array} holders The `partials` placeholder indexes.
  4302. * @params {boolean} [isCurried] Specify composing for a curried function.
  4303. * @returns {Array} Returns the new array of composed arguments.
  4304. */
  4305. function composeArgsRight(args, partials, holders, isCurried) {
  4306. var argsIndex = -1,
  4307. argsLength = args.length,
  4308. holdersIndex = -1,
  4309. holdersLength = holders.length,
  4310. rightIndex = -1,
  4311. rightLength = partials.length,
  4312. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4313. result = Array(rangeLength + rightLength),
  4314. isUncurried = !isCurried;
  4315. while (++argsIndex < rangeLength) {
  4316. result[argsIndex] = args[argsIndex];
  4317. }
  4318. var offset = argsIndex;
  4319. while (++rightIndex < rightLength) {
  4320. result[offset + rightIndex] = partials[rightIndex];
  4321. }
  4322. while (++holdersIndex < holdersLength) {
  4323. if (isUncurried || argsIndex < argsLength) {
  4324. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4325. }
  4326. }
  4327. return result;
  4328. }
  4329. /**
  4330. * Copies the values of `source` to `array`.
  4331. *
  4332. * @private
  4333. * @param {Array} source The array to copy values from.
  4334. * @param {Array} [array=[]] The array to copy values to.
  4335. * @returns {Array} Returns `array`.
  4336. */
  4337. function copyArray(source, array) {
  4338. var index = -1,
  4339. length = source.length;
  4340. array || (array = Array(length));
  4341. while (++index < length) {
  4342. array[index] = source[index];
  4343. }
  4344. return array;
  4345. }
  4346. /**
  4347. * Copies properties of `source` to `object`.
  4348. *
  4349. * @private
  4350. * @param {Object} source The object to copy properties from.
  4351. * @param {Array} props The property identifiers to copy.
  4352. * @param {Object} [object={}] The object to copy properties to.
  4353. * @param {Function} [customizer] The function to customize copied values.
  4354. * @returns {Object} Returns `object`.
  4355. */
  4356. function copyObject(source, props, object, customizer) {
  4357. var isNew = !object;
  4358. object || (object = {});
  4359. var index = -1,
  4360. length = props.length;
  4361. while (++index < length) {
  4362. var key = props[index];
  4363. var newValue = customizer
  4364. ? customizer(object[key], source[key], key, object, source)
  4365. : undefined;
  4366. if (newValue === undefined) {
  4367. newValue = source[key];
  4368. }
  4369. if (isNew) {
  4370. baseAssignValue(object, key, newValue);
  4371. } else {
  4372. assignValue(object, key, newValue);
  4373. }
  4374. }
  4375. return object;
  4376. }
  4377. /**
  4378. * Copies own symbols of `source` to `object`.
  4379. *
  4380. * @private
  4381. * @param {Object} source The object to copy symbols from.
  4382. * @param {Object} [object={}] The object to copy symbols to.
  4383. * @returns {Object} Returns `object`.
  4384. */
  4385. function copySymbols(source, object) {
  4386. return copyObject(source, getSymbols(source), object);
  4387. }
  4388. /**
  4389. * Copies own and inherited symbols of `source` to `object`.
  4390. *
  4391. * @private
  4392. * @param {Object} source The object to copy symbols from.
  4393. * @param {Object} [object={}] The object to copy symbols to.
  4394. * @returns {Object} Returns `object`.
  4395. */
  4396. function copySymbolsIn(source, object) {
  4397. return copyObject(source, getSymbolsIn(source), object);
  4398. }
  4399. /**
  4400. * Creates a function like `_.groupBy`.
  4401. *
  4402. * @private
  4403. * @param {Function} setter The function to set accumulator values.
  4404. * @param {Function} [initializer] The accumulator object initializer.
  4405. * @returns {Function} Returns the new aggregator function.
  4406. */
  4407. function createAggregator(setter, initializer) {
  4408. return function(collection, iteratee) {
  4409. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4410. accumulator = initializer ? initializer() : {};
  4411. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4412. };
  4413. }
  4414. /**
  4415. * Creates a function like `_.assign`.
  4416. *
  4417. * @private
  4418. * @param {Function} assigner The function to assign values.
  4419. * @returns {Function} Returns the new assigner function.
  4420. */
  4421. function createAssigner(assigner) {
  4422. return baseRest(function(object, sources) {
  4423. var index = -1,
  4424. length = sources.length,
  4425. customizer = length > 1 ? sources[length - 1] : undefined,
  4426. guard = length > 2 ? sources[2] : undefined;
  4427. customizer = (assigner.length > 3 && typeof customizer == 'function')
  4428. ? (length--, customizer)
  4429. : undefined;
  4430. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4431. customizer = length < 3 ? undefined : customizer;
  4432. length = 1;
  4433. }
  4434. object = Object(object);
  4435. while (++index < length) {
  4436. var source = sources[index];
  4437. if (source) {
  4438. assigner(object, source, index, customizer);
  4439. }
  4440. }
  4441. return object;
  4442. });
  4443. }
  4444. /**
  4445. * Creates a `baseEach` or `baseEachRight` function.
  4446. *
  4447. * @private
  4448. * @param {Function} eachFunc The function to iterate over a collection.
  4449. * @param {boolean} [fromRight] Specify iterating from right to left.
  4450. * @returns {Function} Returns the new base function.
  4451. */
  4452. function createBaseEach(eachFunc, fromRight) {
  4453. return function(collection, iteratee) {
  4454. if (collection == null) {
  4455. return collection;
  4456. }
  4457. if (!isArrayLike(collection)) {
  4458. return eachFunc(collection, iteratee);
  4459. }
  4460. var length = collection.length,
  4461. index = fromRight ? length : -1,
  4462. iterable = Object(collection);
  4463. while ((fromRight ? index-- : ++index < length)) {
  4464. if (iteratee(iterable[index], index, iterable) === false) {
  4465. break;
  4466. }
  4467. }
  4468. return collection;
  4469. };
  4470. }
  4471. /**
  4472. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4473. *
  4474. * @private
  4475. * @param {boolean} [fromRight] Specify iterating from right to left.
  4476. * @returns {Function} Returns the new base function.
  4477. */
  4478. function createBaseFor(fromRight) {
  4479. return function(object, iteratee, keysFunc) {
  4480. var index = -1,
  4481. iterable = Object(object),
  4482. props = keysFunc(object),
  4483. length = props.length;
  4484. while (length--) {
  4485. var key = props[fromRight ? length : ++index];
  4486. if (iteratee(iterable[key], key, iterable) === false) {
  4487. break;
  4488. }
  4489. }
  4490. return object;
  4491. };
  4492. }
  4493. /**
  4494. * Creates a function that wraps `func` to invoke it with the optional `this`
  4495. * binding of `thisArg`.
  4496. *
  4497. * @private
  4498. * @param {Function} func The function to wrap.
  4499. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4500. * @param {*} [thisArg] The `this` binding of `func`.
  4501. * @returns {Function} Returns the new wrapped function.
  4502. */
  4503. function createBind(func, bitmask, thisArg) {
  4504. var isBind = bitmask & WRAP_BIND_FLAG,
  4505. Ctor = createCtor(func);
  4506. function wrapper() {
  4507. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4508. return fn.apply(isBind ? thisArg : this, arguments);
  4509. }
  4510. return wrapper;
  4511. }
  4512. /**
  4513. * Creates a function like `_.lowerFirst`.
  4514. *
  4515. * @private
  4516. * @param {string} methodName The name of the `String` case method to use.
  4517. * @returns {Function} Returns the new case function.
  4518. */
  4519. function createCaseFirst(methodName) {
  4520. return function(string) {
  4521. string = toString(string);
  4522. var strSymbols = hasUnicode(string)
  4523. ? stringToArray(string)
  4524. : undefined;
  4525. var chr = strSymbols
  4526. ? strSymbols[0]
  4527. : string.charAt(0);
  4528. var trailing = strSymbols
  4529. ? castSlice(strSymbols, 1).join('')
  4530. : string.slice(1);
  4531. return chr[methodName]() + trailing;
  4532. };
  4533. }
  4534. /**
  4535. * Creates a function like `_.camelCase`.
  4536. *
  4537. * @private
  4538. * @param {Function} callback The function to combine each word.
  4539. * @returns {Function} Returns the new compounder function.
  4540. */
  4541. function createCompounder(callback) {
  4542. return function(string) {
  4543. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  4544. };
  4545. }
  4546. /**
  4547. * Creates a function that produces an instance of `Ctor` regardless of
  4548. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4549. *
  4550. * @private
  4551. * @param {Function} Ctor The constructor to wrap.
  4552. * @returns {Function} Returns the new wrapped function.
  4553. */
  4554. function createCtor(Ctor) {
  4555. return function() {
  4556. // Use a `switch` statement to work with class constructors. See
  4557. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4558. // for more details.
  4559. var args = arguments;
  4560. switch (args.length) {
  4561. case 0: return new Ctor;
  4562. case 1: return new Ctor(args[0]);
  4563. case 2: return new Ctor(args[0], args[1]);
  4564. case 3: return new Ctor(args[0], args[1], args[2]);
  4565. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4566. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4567. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4568. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4569. }
  4570. var thisBinding = baseCreate(Ctor.prototype),
  4571. result = Ctor.apply(thisBinding, args);
  4572. // Mimic the constructor's `return` behavior.
  4573. // See https://es5.github.io/#x13.2.2 for more details.
  4574. return isObject(result) ? result : thisBinding;
  4575. };
  4576. }
  4577. /**
  4578. * Creates a function that wraps `func` to enable currying.
  4579. *
  4580. * @private
  4581. * @param {Function} func The function to wrap.
  4582. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4583. * @param {number} arity The arity of `func`.
  4584. * @returns {Function} Returns the new wrapped function.
  4585. */
  4586. function createCurry(func, bitmask, arity) {
  4587. var Ctor = createCtor(func);
  4588. function wrapper() {
  4589. var length = arguments.length,
  4590. args = Array(length),
  4591. index = length,
  4592. placeholder = getHolder(wrapper);
  4593. while (index--) {
  4594. args[index] = arguments[index];
  4595. }
  4596. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  4597. ? []
  4598. : replaceHolders(args, placeholder);
  4599. length -= holders.length;
  4600. if (length < arity) {
  4601. return createRecurry(
  4602. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  4603. args, holders, undefined, undefined, arity - length);
  4604. }
  4605. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4606. return apply(fn, this, args);
  4607. }
  4608. return wrapper;
  4609. }
  4610. /**
  4611. * Creates a `_.find` or `_.findLast` function.
  4612. *
  4613. * @private
  4614. * @param {Function} findIndexFunc The function to find the collection index.
  4615. * @returns {Function} Returns the new find function.
  4616. */
  4617. function createFind(findIndexFunc) {
  4618. return function(collection, predicate, fromIndex) {
  4619. var iterable = Object(collection);
  4620. if (!isArrayLike(collection)) {
  4621. var iteratee = getIteratee(predicate, 3);
  4622. collection = keys(collection);
  4623. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  4624. }
  4625. var index = findIndexFunc(collection, predicate, fromIndex);
  4626. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  4627. };
  4628. }
  4629. /**
  4630. * Creates a `_.flow` or `_.flowRight` function.
  4631. *
  4632. * @private
  4633. * @param {boolean} [fromRight] Specify iterating from right to left.
  4634. * @returns {Function} Returns the new flow function.
  4635. */
  4636. function createFlow(fromRight) {
  4637. return flatRest(function(funcs) {
  4638. var length = funcs.length,
  4639. index = length,
  4640. prereq = LodashWrapper.prototype.thru;
  4641. if (fromRight) {
  4642. funcs.reverse();
  4643. }
  4644. while (index--) {
  4645. var func = funcs[index];
  4646. if (typeof func != 'function') {
  4647. throw new TypeError(FUNC_ERROR_TEXT);
  4648. }
  4649. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  4650. var wrapper = new LodashWrapper([], true);
  4651. }
  4652. }
  4653. index = wrapper ? index : length;
  4654. while (++index < length) {
  4655. func = funcs[index];
  4656. var funcName = getFuncName(func),
  4657. data = funcName == 'wrapper' ? getData(func) : undefined;
  4658. if (data && isLaziable(data[0]) &&
  4659. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  4660. !data[4].length && data[9] == 1
  4661. ) {
  4662. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4663. } else {
  4664. wrapper = (func.length == 1 && isLaziable(func))
  4665. ? wrapper[funcName]()
  4666. : wrapper.thru(func);
  4667. }
  4668. }
  4669. return function() {
  4670. var args = arguments,
  4671. value = args[0];
  4672. if (wrapper && args.length == 1 && isArray(value)) {
  4673. return wrapper.plant(value).value();
  4674. }
  4675. var index = 0,
  4676. result = length ? funcs[index].apply(this, args) : value;
  4677. while (++index < length) {
  4678. result = funcs[index].call(this, result);
  4679. }
  4680. return result;
  4681. };
  4682. });
  4683. }
  4684. /**
  4685. * Creates a function that wraps `func` to invoke it with optional `this`
  4686. * binding of `thisArg`, partial application, and currying.
  4687. *
  4688. * @private
  4689. * @param {Function|string} func The function or method name to wrap.
  4690. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4691. * @param {*} [thisArg] The `this` binding of `func`.
  4692. * @param {Array} [partials] The arguments to prepend to those provided to
  4693. * the new function.
  4694. * @param {Array} [holders] The `partials` placeholder indexes.
  4695. * @param {Array} [partialsRight] The arguments to append to those provided
  4696. * to the new function.
  4697. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  4698. * @param {Array} [argPos] The argument positions of the new function.
  4699. * @param {number} [ary] The arity cap of `func`.
  4700. * @param {number} [arity] The arity of `func`.
  4701. * @returns {Function} Returns the new wrapped function.
  4702. */
  4703. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  4704. var isAry = bitmask & WRAP_ARY_FLAG,
  4705. isBind = bitmask & WRAP_BIND_FLAG,
  4706. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  4707. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  4708. isFlip = bitmask & WRAP_FLIP_FLAG,
  4709. Ctor = isBindKey ? undefined : createCtor(func);
  4710. function wrapper() {
  4711. var length = arguments.length,
  4712. args = Array(length),
  4713. index = length;
  4714. while (index--) {
  4715. args[index] = arguments[index];
  4716. }
  4717. if (isCurried) {
  4718. var placeholder = getHolder(wrapper),
  4719. holdersCount = countHolders(args, placeholder);
  4720. }
  4721. if (partials) {
  4722. args = composeArgs(args, partials, holders, isCurried);
  4723. }
  4724. if (partialsRight) {
  4725. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  4726. }
  4727. length -= holdersCount;
  4728. if (isCurried && length < arity) {
  4729. var newHolders = replaceHolders(args, placeholder);
  4730. return createRecurry(
  4731. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  4732. args, newHolders, argPos, ary, arity - length
  4733. );
  4734. }
  4735. var thisBinding = isBind ? thisArg : this,
  4736. fn = isBindKey ? thisBinding[func] : func;
  4737. length = args.length;
  4738. if (argPos) {
  4739. args = reorder(args, argPos);
  4740. } else if (isFlip && length > 1) {
  4741. args.reverse();
  4742. }
  4743. if (isAry && ary < length) {
  4744. args.length = ary;
  4745. }
  4746. if (this && this !== root && this instanceof wrapper) {
  4747. fn = Ctor || createCtor(fn);
  4748. }
  4749. return fn.apply(thisBinding, args);
  4750. }
  4751. return wrapper;
  4752. }
  4753. /**
  4754. * Creates a function like `_.invertBy`.
  4755. *
  4756. * @private
  4757. * @param {Function} setter The function to set accumulator values.
  4758. * @param {Function} toIteratee The function to resolve iteratees.
  4759. * @returns {Function} Returns the new inverter function.
  4760. */
  4761. function createInverter(setter, toIteratee) {
  4762. return function(object, iteratee) {
  4763. return baseInverter(object, setter, toIteratee(iteratee), {});
  4764. };
  4765. }
  4766. /**
  4767. * Creates a function that performs a mathematical operation on two values.
  4768. *
  4769. * @private
  4770. * @param {Function} operator The function to perform the operation.
  4771. * @param {number} [defaultValue] The value used for `undefined` arguments.
  4772. * @returns {Function} Returns the new mathematical operation function.
  4773. */
  4774. function createMathOperation(operator, defaultValue) {
  4775. return function(value, other) {
  4776. var result;
  4777. if (value === undefined && other === undefined) {
  4778. return defaultValue;
  4779. }
  4780. if (value !== undefined) {
  4781. result = value;
  4782. }
  4783. if (other !== undefined) {
  4784. if (result === undefined) {
  4785. return other;
  4786. }
  4787. if (typeof value == 'string' || typeof other == 'string') {
  4788. value = baseToString(value);
  4789. other = baseToString(other);
  4790. } else {
  4791. value = baseToNumber(value);
  4792. other = baseToNumber(other);
  4793. }
  4794. result = operator(value, other);
  4795. }
  4796. return result;
  4797. };
  4798. }
  4799. /**
  4800. * Creates a function like `_.over`.
  4801. *
  4802. * @private
  4803. * @param {Function} arrayFunc The function to iterate over iteratees.
  4804. * @returns {Function} Returns the new over function.
  4805. */
  4806. function createOver(arrayFunc) {
  4807. return flatRest(function(iteratees) {
  4808. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  4809. return baseRest(function(args) {
  4810. var thisArg = this;
  4811. return arrayFunc(iteratees, function(iteratee) {
  4812. return apply(iteratee, thisArg, args);
  4813. });
  4814. });
  4815. });
  4816. }
  4817. /**
  4818. * Creates the padding for `string` based on `length`. The `chars` string
  4819. * is truncated if the number of characters exceeds `length`.
  4820. *
  4821. * @private
  4822. * @param {number} length The padding length.
  4823. * @param {string} [chars=' '] The string used as padding.
  4824. * @returns {string} Returns the padding for `string`.
  4825. */
  4826. function createPadding(length, chars) {
  4827. chars = chars === undefined ? ' ' : baseToString(chars);
  4828. var charsLength = chars.length;
  4829. if (charsLength < 2) {
  4830. return charsLength ? baseRepeat(chars, length) : chars;
  4831. }
  4832. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  4833. return hasUnicode(chars)
  4834. ? castSlice(stringToArray(result), 0, length).join('')
  4835. : result.slice(0, length);
  4836. }
  4837. /**
  4838. * Creates a function that wraps `func` to invoke it with the `this` binding
  4839. * of `thisArg` and `partials` prepended to the arguments it receives.
  4840. *
  4841. * @private
  4842. * @param {Function} func The function to wrap.
  4843. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4844. * @param {*} thisArg The `this` binding of `func`.
  4845. * @param {Array} partials The arguments to prepend to those provided to
  4846. * the new function.
  4847. * @returns {Function} Returns the new wrapped function.
  4848. */
  4849. function createPartial(func, bitmask, thisArg, partials) {
  4850. var isBind = bitmask & WRAP_BIND_FLAG,
  4851. Ctor = createCtor(func);
  4852. function wrapper() {
  4853. var argsIndex = -1,
  4854. argsLength = arguments.length,
  4855. leftIndex = -1,
  4856. leftLength = partials.length,
  4857. args = Array(leftLength + argsLength),
  4858. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4859. while (++leftIndex < leftLength) {
  4860. args[leftIndex] = partials[leftIndex];
  4861. }
  4862. while (argsLength--) {
  4863. args[leftIndex++] = arguments[++argsIndex];
  4864. }
  4865. return apply(fn, isBind ? thisArg : this, args);
  4866. }
  4867. return wrapper;
  4868. }
  4869. /**
  4870. * Creates a `_.range` or `_.rangeRight` function.
  4871. *
  4872. * @private
  4873. * @param {boolean} [fromRight] Specify iterating from right to left.
  4874. * @returns {Function} Returns the new range function.
  4875. */
  4876. function createRange(fromRight) {
  4877. return function(start, end, step) {
  4878. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  4879. end = step = undefined;
  4880. }
  4881. // Ensure the sign of `-0` is preserved.
  4882. start = toFinite(start);
  4883. if (end === undefined) {
  4884. end = start;
  4885. start = 0;
  4886. } else {
  4887. end = toFinite(end);
  4888. }
  4889. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  4890. return baseRange(start, end, step, fromRight);
  4891. };
  4892. }
  4893. /**
  4894. * Creates a function that performs a relational operation on two values.
  4895. *
  4896. * @private
  4897. * @param {Function} operator The function to perform the operation.
  4898. * @returns {Function} Returns the new relational operation function.
  4899. */
  4900. function createRelationalOperation(operator) {
  4901. return function(value, other) {
  4902. if (!(typeof value == 'string' && typeof other == 'string')) {
  4903. value = toNumber(value);
  4904. other = toNumber(other);
  4905. }
  4906. return operator(value, other);
  4907. };
  4908. }
  4909. /**
  4910. * Creates a function that wraps `func` to continue currying.
  4911. *
  4912. * @private
  4913. * @param {Function} func The function to wrap.
  4914. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4915. * @param {Function} wrapFunc The function to create the `func` wrapper.
  4916. * @param {*} placeholder The placeholder value.
  4917. * @param {*} [thisArg] The `this` binding of `func`.
  4918. * @param {Array} [partials] The arguments to prepend to those provided to
  4919. * the new function.
  4920. * @param {Array} [holders] The `partials` placeholder indexes.
  4921. * @param {Array} [argPos] The argument positions of the new function.
  4922. * @param {number} [ary] The arity cap of `func`.
  4923. * @param {number} [arity] The arity of `func`.
  4924. * @returns {Function} Returns the new wrapped function.
  4925. */
  4926. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  4927. var isCurry = bitmask & WRAP_CURRY_FLAG,
  4928. newHolders = isCurry ? holders : undefined,
  4929. newHoldersRight = isCurry ? undefined : holders,
  4930. newPartials = isCurry ? partials : undefined,
  4931. newPartialsRight = isCurry ? undefined : partials;
  4932. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  4933. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  4934. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  4935. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  4936. }
  4937. var newData = [
  4938. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  4939. newHoldersRight, argPos, ary, arity
  4940. ];
  4941. var result = wrapFunc.apply(undefined, newData);
  4942. if (isLaziable(func)) {
  4943. setData(result, newData);
  4944. }
  4945. result.placeholder = placeholder;
  4946. return setWrapToString(result, func, bitmask);
  4947. }
  4948. /**
  4949. * Creates a function like `_.round`.
  4950. *
  4951. * @private
  4952. * @param {string} methodName The name of the `Math` method to use when rounding.
  4953. * @returns {Function} Returns the new round function.
  4954. */
  4955. function createRound(methodName) {
  4956. var func = Math[methodName];
  4957. return function(number, precision) {
  4958. number = toNumber(number);
  4959. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  4960. if (precision) {
  4961. // Shift with exponential notation to avoid floating-point issues.
  4962. // See [MDN](https://mdn.io/round#Examples) for more details.
  4963. var pair = (toString(number) + 'e').split('e'),
  4964. value = func(pair[0] + 'e' + (+pair[1] + precision));
  4965. pair = (toString(value) + 'e').split('e');
  4966. return +(pair[0] + 'e' + (+pair[1] - precision));
  4967. }
  4968. return func(number);
  4969. };
  4970. }
  4971. /**
  4972. * Creates a set object of `values`.
  4973. *
  4974. * @private
  4975. * @param {Array} values The values to add to the set.
  4976. * @returns {Object} Returns the new set.
  4977. */
  4978. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  4979. return new Set(values);
  4980. };
  4981. /**
  4982. * Creates a `_.toPairs` or `_.toPairsIn` function.
  4983. *
  4984. * @private
  4985. * @param {Function} keysFunc The function to get the keys of a given object.
  4986. * @returns {Function} Returns the new pairs function.
  4987. */
  4988. function createToPairs(keysFunc) {
  4989. return function(object) {
  4990. var tag = getTag(object);
  4991. if (tag == mapTag) {
  4992. return mapToArray(object);
  4993. }
  4994. if (tag == setTag) {
  4995. return setToPairs(object);
  4996. }
  4997. return baseToPairs(object, keysFunc(object));
  4998. };
  4999. }
  5000. /**
  5001. * Creates a function that either curries or invokes `func` with optional
  5002. * `this` binding and partially applied arguments.
  5003. *
  5004. * @private
  5005. * @param {Function|string} func The function or method name to wrap.
  5006. * @param {number} bitmask The bitmask flags.
  5007. * 1 - `_.bind`
  5008. * 2 - `_.bindKey`
  5009. * 4 - `_.curry` or `_.curryRight` of a bound function
  5010. * 8 - `_.curry`
  5011. * 16 - `_.curryRight`
  5012. * 32 - `_.partial`
  5013. * 64 - `_.partialRight`
  5014. * 128 - `_.rearg`
  5015. * 256 - `_.ary`
  5016. * 512 - `_.flip`
  5017. * @param {*} [thisArg] The `this` binding of `func`.
  5018. * @param {Array} [partials] The arguments to be partially applied.
  5019. * @param {Array} [holders] The `partials` placeholder indexes.
  5020. * @param {Array} [argPos] The argument positions of the new function.
  5021. * @param {number} [ary] The arity cap of `func`.
  5022. * @param {number} [arity] The arity of `func`.
  5023. * @returns {Function} Returns the new wrapped function.
  5024. */
  5025. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  5026. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  5027. if (!isBindKey && typeof func != 'function') {
  5028. throw new TypeError(FUNC_ERROR_TEXT);
  5029. }
  5030. var length = partials ? partials.length : 0;
  5031. if (!length) {
  5032. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  5033. partials = holders = undefined;
  5034. }
  5035. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  5036. arity = arity === undefined ? arity : toInteger(arity);
  5037. length -= holders ? holders.length : 0;
  5038. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  5039. var partialsRight = partials,
  5040. holdersRight = holders;
  5041. partials = holders = undefined;
  5042. }
  5043. var data = isBindKey ? undefined : getData(func);
  5044. var newData = [
  5045. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  5046. argPos, ary, arity
  5047. ];
  5048. if (data) {
  5049. mergeData(newData, data);
  5050. }
  5051. func = newData[0];
  5052. bitmask = newData[1];
  5053. thisArg = newData[2];
  5054. partials = newData[3];
  5055. holders = newData[4];
  5056. arity = newData[9] = newData[9] === undefined
  5057. ? (isBindKey ? 0 : func.length)
  5058. : nativeMax(newData[9] - length, 0);
  5059. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  5060. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  5061. }
  5062. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  5063. var result = createBind(func, bitmask, thisArg);
  5064. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  5065. result = createCurry(func, bitmask, arity);
  5066. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  5067. result = createPartial(func, bitmask, thisArg, partials);
  5068. } else {
  5069. result = createHybrid.apply(undefined, newData);
  5070. }
  5071. var setter = data ? baseSetData : setData;
  5072. return setWrapToString(setter(result, newData), func, bitmask);
  5073. }
  5074. /**
  5075. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  5076. * of source objects to the destination object for all destination properties
  5077. * that resolve to `undefined`.
  5078. *
  5079. * @private
  5080. * @param {*} objValue The destination value.
  5081. * @param {*} srcValue The source value.
  5082. * @param {string} key The key of the property to assign.
  5083. * @param {Object} object The parent object of `objValue`.
  5084. * @returns {*} Returns the value to assign.
  5085. */
  5086. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  5087. if (objValue === undefined ||
  5088. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  5089. return srcValue;
  5090. }
  5091. return objValue;
  5092. }
  5093. /**
  5094. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  5095. * objects into destination objects that are passed thru.
  5096. *
  5097. * @private
  5098. * @param {*} objValue The destination value.
  5099. * @param {*} srcValue The source value.
  5100. * @param {string} key The key of the property to merge.
  5101. * @param {Object} object The parent object of `objValue`.
  5102. * @param {Object} source The parent object of `srcValue`.
  5103. * @param {Object} [stack] Tracks traversed source values and their merged
  5104. * counterparts.
  5105. * @returns {*} Returns the value to assign.
  5106. */
  5107. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  5108. if (isObject(objValue) && isObject(srcValue)) {
  5109. // Recursively merge objects and arrays (susceptible to call stack limits).
  5110. stack.set(srcValue, objValue);
  5111. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  5112. stack['delete'](srcValue);
  5113. }
  5114. return objValue;
  5115. }
  5116. /**
  5117. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  5118. * objects.
  5119. *
  5120. * @private
  5121. * @param {*} value The value to inspect.
  5122. * @param {string} key The key of the property to inspect.
  5123. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  5124. */
  5125. function customOmitClone(value) {
  5126. return isPlainObject(value) ? undefined : value;
  5127. }
  5128. /**
  5129. * A specialized version of `baseIsEqualDeep` for arrays with support for
  5130. * partial deep comparisons.
  5131. *
  5132. * @private
  5133. * @param {Array} array The array to compare.
  5134. * @param {Array} other The other array to compare.
  5135. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5136. * @param {Function} customizer The function to customize comparisons.
  5137. * @param {Function} equalFunc The function to determine equivalents of values.
  5138. * @param {Object} stack Tracks traversed `array` and `other` objects.
  5139. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  5140. */
  5141. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  5142. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5143. arrLength = array.length,
  5144. othLength = other.length;
  5145. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  5146. return false;
  5147. }
  5148. // Assume cyclic values are equal.
  5149. var stacked = stack.get(array);
  5150. if (stacked && stack.get(other)) {
  5151. return stacked == other;
  5152. }
  5153. var index = -1,
  5154. result = true,
  5155. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  5156. stack.set(array, other);
  5157. stack.set(other, array);
  5158. // Ignore non-index properties.
  5159. while (++index < arrLength) {
  5160. var arrValue = array[index],
  5161. othValue = other[index];
  5162. if (customizer) {
  5163. var compared = isPartial
  5164. ? customizer(othValue, arrValue, index, other, array, stack)
  5165. : customizer(arrValue, othValue, index, array, other, stack);
  5166. }
  5167. if (compared !== undefined) {
  5168. if (compared) {
  5169. continue;
  5170. }
  5171. result = false;
  5172. break;
  5173. }
  5174. // Recursively compare arrays (susceptible to call stack limits).
  5175. if (seen) {
  5176. if (!arraySome(other, function(othValue, othIndex) {
  5177. if (!cacheHas(seen, othIndex) &&
  5178. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  5179. return seen.push(othIndex);
  5180. }
  5181. })) {
  5182. result = false;
  5183. break;
  5184. }
  5185. } else if (!(
  5186. arrValue === othValue ||
  5187. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  5188. )) {
  5189. result = false;
  5190. break;
  5191. }
  5192. }
  5193. stack['delete'](array);
  5194. stack['delete'](other);
  5195. return result;
  5196. }
  5197. /**
  5198. * A specialized version of `baseIsEqualDeep` for comparing objects of
  5199. * the same `toStringTag`.
  5200. *
  5201. * **Note:** This function only supports comparing values with tags of
  5202. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5203. *
  5204. * @private
  5205. * @param {Object} object The object to compare.
  5206. * @param {Object} other The other object to compare.
  5207. * @param {string} tag The `toStringTag` of the objects to compare.
  5208. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5209. * @param {Function} customizer The function to customize comparisons.
  5210. * @param {Function} equalFunc The function to determine equivalents of values.
  5211. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5212. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5213. */
  5214. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  5215. switch (tag) {
  5216. case dataViewTag:
  5217. if ((object.byteLength != other.byteLength) ||
  5218. (object.byteOffset != other.byteOffset)) {
  5219. return false;
  5220. }
  5221. object = object.buffer;
  5222. other = other.buffer;
  5223. case arrayBufferTag:
  5224. if ((object.byteLength != other.byteLength) ||
  5225. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  5226. return false;
  5227. }
  5228. return true;
  5229. case boolTag:
  5230. case dateTag:
  5231. case numberTag:
  5232. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5233. // Invalid dates are coerced to `NaN`.
  5234. return eq(+object, +other);
  5235. case errorTag:
  5236. return object.name == other.name && object.message == other.message;
  5237. case regexpTag:
  5238. case stringTag:
  5239. // Coerce regexes to strings and treat strings, primitives and objects,
  5240. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5241. // for more details.
  5242. return object == (other + '');
  5243. case mapTag:
  5244. var convert = mapToArray;
  5245. case setTag:
  5246. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  5247. convert || (convert = setToArray);
  5248. if (object.size != other.size && !isPartial) {
  5249. return false;
  5250. }
  5251. // Assume cyclic values are equal.
  5252. var stacked = stack.get(object);
  5253. if (stacked) {
  5254. return stacked == other;
  5255. }
  5256. bitmask |= COMPARE_UNORDERED_FLAG;
  5257. // Recursively compare objects (susceptible to call stack limits).
  5258. stack.set(object, other);
  5259. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  5260. stack['delete'](object);
  5261. return result;
  5262. case symbolTag:
  5263. if (symbolValueOf) {
  5264. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5265. }
  5266. }
  5267. return false;
  5268. }
  5269. /**
  5270. * A specialized version of `baseIsEqualDeep` for objects with support for
  5271. * partial deep comparisons.
  5272. *
  5273. * @private
  5274. * @param {Object} object The object to compare.
  5275. * @param {Object} other The other object to compare.
  5276. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5277. * @param {Function} customizer The function to customize comparisons.
  5278. * @param {Function} equalFunc The function to determine equivalents of values.
  5279. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5280. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5281. */
  5282. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  5283. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5284. objProps = getAllKeys(object),
  5285. objLength = objProps.length,
  5286. othProps = getAllKeys(other),
  5287. othLength = othProps.length;
  5288. if (objLength != othLength && !isPartial) {
  5289. return false;
  5290. }
  5291. var index = objLength;
  5292. while (index--) {
  5293. var key = objProps[index];
  5294. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  5295. return false;
  5296. }
  5297. }
  5298. // Assume cyclic values are equal.
  5299. var stacked = stack.get(object);
  5300. if (stacked && stack.get(other)) {
  5301. return stacked == other;
  5302. }
  5303. var result = true;
  5304. stack.set(object, other);
  5305. stack.set(other, object);
  5306. var skipCtor = isPartial;
  5307. while (++index < objLength) {
  5308. key = objProps[index];
  5309. var objValue = object[key],
  5310. othValue = other[key];
  5311. if (customizer) {
  5312. var compared = isPartial
  5313. ? customizer(othValue, objValue, key, other, object, stack)
  5314. : customizer(objValue, othValue, key, object, other, stack);
  5315. }
  5316. // Recursively compare objects (susceptible to call stack limits).
  5317. if (!(compared === undefined
  5318. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  5319. : compared
  5320. )) {
  5321. result = false;
  5322. break;
  5323. }
  5324. skipCtor || (skipCtor = key == 'constructor');
  5325. }
  5326. if (result && !skipCtor) {
  5327. var objCtor = object.constructor,
  5328. othCtor = other.constructor;
  5329. // Non `Object` object instances with different constructors are not equal.
  5330. if (objCtor != othCtor &&
  5331. ('constructor' in object && 'constructor' in other) &&
  5332. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5333. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5334. result = false;
  5335. }
  5336. }
  5337. stack['delete'](object);
  5338. stack['delete'](other);
  5339. return result;
  5340. }
  5341. /**
  5342. * A specialized version of `baseRest` which flattens the rest array.
  5343. *
  5344. * @private
  5345. * @param {Function} func The function to apply a rest parameter to.
  5346. * @returns {Function} Returns the new function.
  5347. */
  5348. function flatRest(func) {
  5349. return setToString(overRest(func, undefined, flatten), func + '');
  5350. }
  5351. /**
  5352. * Creates an array of own enumerable property names and symbols of `object`.
  5353. *
  5354. * @private
  5355. * @param {Object} object The object to query.
  5356. * @returns {Array} Returns the array of property names and symbols.
  5357. */
  5358. function getAllKeys(object) {
  5359. return baseGetAllKeys(object, keys, getSymbols);
  5360. }
  5361. /**
  5362. * Creates an array of own and inherited enumerable property names and
  5363. * symbols of `object`.
  5364. *
  5365. * @private
  5366. * @param {Object} object The object to query.
  5367. * @returns {Array} Returns the array of property names and symbols.
  5368. */
  5369. function getAllKeysIn(object) {
  5370. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  5371. }
  5372. /**
  5373. * Gets metadata for `func`.
  5374. *
  5375. * @private
  5376. * @param {Function} func The function to query.
  5377. * @returns {*} Returns the metadata for `func`.
  5378. */
  5379. var getData = !metaMap ? noop : function(func) {
  5380. return metaMap.get(func);
  5381. };
  5382. /**
  5383. * Gets the name of `func`.
  5384. *
  5385. * @private
  5386. * @param {Function} func The function to query.
  5387. * @returns {string} Returns the function name.
  5388. */
  5389. function getFuncName(func) {
  5390. var result = (func.name + ''),
  5391. array = realNames[result],
  5392. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5393. while (length--) {
  5394. var data = array[length],
  5395. otherFunc = data.func;
  5396. if (otherFunc == null || otherFunc == func) {
  5397. return data.name;
  5398. }
  5399. }
  5400. return result;
  5401. }
  5402. /**
  5403. * Gets the argument placeholder value for `func`.
  5404. *
  5405. * @private
  5406. * @param {Function} func The function to inspect.
  5407. * @returns {*} Returns the placeholder value.
  5408. */
  5409. function getHolder(func) {
  5410. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  5411. return object.placeholder;
  5412. }
  5413. /**
  5414. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  5415. * this function returns the custom method, otherwise it returns `baseIteratee`.
  5416. * If arguments are provided, the chosen function is invoked with them and
  5417. * its result is returned.
  5418. *
  5419. * @private
  5420. * @param {*} [value] The value to convert to an iteratee.
  5421. * @param {number} [arity] The arity of the created iteratee.
  5422. * @returns {Function} Returns the chosen function or its result.
  5423. */
  5424. function getIteratee() {
  5425. var result = lodash.iteratee || iteratee;
  5426. result = result === iteratee ? baseIteratee : result;
  5427. return arguments.length ? result(arguments[0], arguments[1]) : result;
  5428. }
  5429. /**
  5430. * Gets the data for `map`.
  5431. *
  5432. * @private
  5433. * @param {Object} map The map to query.
  5434. * @param {string} key The reference key.
  5435. * @returns {*} Returns the map data.
  5436. */
  5437. function getMapData(map, key) {
  5438. var data = map.__data__;
  5439. return isKeyable(key)
  5440. ? data[typeof key == 'string' ? 'string' : 'hash']
  5441. : data.map;
  5442. }
  5443. /**
  5444. * Gets the property names, values, and compare flags of `object`.
  5445. *
  5446. * @private
  5447. * @param {Object} object The object to query.
  5448. * @returns {Array} Returns the match data of `object`.
  5449. */
  5450. function getMatchData(object) {
  5451. var result = keys(object),
  5452. length = result.length;
  5453. while (length--) {
  5454. var key = result[length],
  5455. value = object[key];
  5456. result[length] = [key, value, isStrictComparable(value)];
  5457. }
  5458. return result;
  5459. }
  5460. /**
  5461. * Gets the native function at `key` of `object`.
  5462. *
  5463. * @private
  5464. * @param {Object} object The object to query.
  5465. * @param {string} key The key of the method to get.
  5466. * @returns {*} Returns the function if it's native, else `undefined`.
  5467. */
  5468. function getNative(object, key) {
  5469. var value = getValue(object, key);
  5470. return baseIsNative(value) ? value : undefined;
  5471. }
  5472. /**
  5473. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  5474. *
  5475. * @private
  5476. * @param {*} value The value to query.
  5477. * @returns {string} Returns the raw `toStringTag`.
  5478. */
  5479. function getRawTag(value) {
  5480. var isOwn = hasOwnProperty.call(value, symToStringTag),
  5481. tag = value[symToStringTag];
  5482. try {
  5483. value[symToStringTag] = undefined;
  5484. var unmasked = true;
  5485. } catch (e) {}
  5486. var result = nativeObjectToString.call(value);
  5487. if (unmasked) {
  5488. if (isOwn) {
  5489. value[symToStringTag] = tag;
  5490. } else {
  5491. delete value[symToStringTag];
  5492. }
  5493. }
  5494. return result;
  5495. }
  5496. /**
  5497. * Creates an array of the own enumerable symbols of `object`.
  5498. *
  5499. * @private
  5500. * @param {Object} object The object to query.
  5501. * @returns {Array} Returns the array of symbols.
  5502. */
  5503. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  5504. if (object == null) {
  5505. return [];
  5506. }
  5507. object = Object(object);
  5508. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  5509. return propertyIsEnumerable.call(object, symbol);
  5510. });
  5511. };
  5512. /**
  5513. * Creates an array of the own and inherited enumerable symbols of `object`.
  5514. *
  5515. * @private
  5516. * @param {Object} object The object to query.
  5517. * @returns {Array} Returns the array of symbols.
  5518. */
  5519. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  5520. var result = [];
  5521. while (object) {
  5522. arrayPush(result, getSymbols(object));
  5523. object = getPrototype(object);
  5524. }
  5525. return result;
  5526. };
  5527. /**
  5528. * Gets the `toStringTag` of `value`.
  5529. *
  5530. * @private
  5531. * @param {*} value The value to query.
  5532. * @returns {string} Returns the `toStringTag`.
  5533. */
  5534. var getTag = baseGetTag;
  5535. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  5536. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  5537. (Map && getTag(new Map) != mapTag) ||
  5538. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  5539. (Set && getTag(new Set) != setTag) ||
  5540. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  5541. getTag = function(value) {
  5542. var result = baseGetTag(value),
  5543. Ctor = result == objectTag ? value.constructor : undefined,
  5544. ctorString = Ctor ? toSource(Ctor) : '';
  5545. if (ctorString) {
  5546. switch (ctorString) {
  5547. case dataViewCtorString: return dataViewTag;
  5548. case mapCtorString: return mapTag;
  5549. case promiseCtorString: return promiseTag;
  5550. case setCtorString: return setTag;
  5551. case weakMapCtorString: return weakMapTag;
  5552. }
  5553. }
  5554. return result;
  5555. };
  5556. }
  5557. /**
  5558. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5559. *
  5560. * @private
  5561. * @param {number} start The start of the view.
  5562. * @param {number} end The end of the view.
  5563. * @param {Array} transforms The transformations to apply to the view.
  5564. * @returns {Object} Returns an object containing the `start` and `end`
  5565. * positions of the view.
  5566. */
  5567. function getView(start, end, transforms) {
  5568. var index = -1,
  5569. length = transforms.length;
  5570. while (++index < length) {
  5571. var data = transforms[index],
  5572. size = data.size;
  5573. switch (data.type) {
  5574. case 'drop': start += size; break;
  5575. case 'dropRight': end -= size; break;
  5576. case 'take': end = nativeMin(end, start + size); break;
  5577. case 'takeRight': start = nativeMax(start, end - size); break;
  5578. }
  5579. }
  5580. return { 'start': start, 'end': end };
  5581. }
  5582. /**
  5583. * Extracts wrapper details from the `source` body comment.
  5584. *
  5585. * @private
  5586. * @param {string} source The source to inspect.
  5587. * @returns {Array} Returns the wrapper details.
  5588. */
  5589. function getWrapDetails(source) {
  5590. var match = source.match(reWrapDetails);
  5591. return match ? match[1].split(reSplitDetails) : [];
  5592. }
  5593. /**
  5594. * Checks if `path` exists on `object`.
  5595. *
  5596. * @private
  5597. * @param {Object} object The object to query.
  5598. * @param {Array|string} path The path to check.
  5599. * @param {Function} hasFunc The function to check properties.
  5600. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5601. */
  5602. function hasPath(object, path, hasFunc) {
  5603. path = castPath(path, object);
  5604. var index = -1,
  5605. length = path.length,
  5606. result = false;
  5607. while (++index < length) {
  5608. var key = toKey(path[index]);
  5609. if (!(result = object != null && hasFunc(object, key))) {
  5610. break;
  5611. }
  5612. object = object[key];
  5613. }
  5614. if (result || ++index != length) {
  5615. return result;
  5616. }
  5617. length = object == null ? 0 : object.length;
  5618. return !!length && isLength(length) && isIndex(key, length) &&
  5619. (isArray(object) || isArguments(object));
  5620. }
  5621. /**
  5622. * Initializes an array clone.
  5623. *
  5624. * @private
  5625. * @param {Array} array The array to clone.
  5626. * @returns {Array} Returns the initialized clone.
  5627. */
  5628. function initCloneArray(array) {
  5629. var length = array.length,
  5630. result = new array.constructor(length);
  5631. // Add properties assigned by `RegExp#exec`.
  5632. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5633. result.index = array.index;
  5634. result.input = array.input;
  5635. }
  5636. return result;
  5637. }
  5638. /**
  5639. * Initializes an object clone.
  5640. *
  5641. * @private
  5642. * @param {Object} object The object to clone.
  5643. * @returns {Object} Returns the initialized clone.
  5644. */
  5645. function initCloneObject(object) {
  5646. return (typeof object.constructor == 'function' && !isPrototype(object))
  5647. ? baseCreate(getPrototype(object))
  5648. : {};
  5649. }
  5650. /**
  5651. * Initializes an object clone based on its `toStringTag`.
  5652. *
  5653. * **Note:** This function only supports cloning values with tags of
  5654. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  5655. *
  5656. * @private
  5657. * @param {Object} object The object to clone.
  5658. * @param {string} tag The `toStringTag` of the object to clone.
  5659. * @param {boolean} [isDeep] Specify a deep clone.
  5660. * @returns {Object} Returns the initialized clone.
  5661. */
  5662. function initCloneByTag(object, tag, isDeep) {
  5663. var Ctor = object.constructor;
  5664. switch (tag) {
  5665. case arrayBufferTag:
  5666. return cloneArrayBuffer(object);
  5667. case boolTag:
  5668. case dateTag:
  5669. return new Ctor(+object);
  5670. case dataViewTag:
  5671. return cloneDataView(object, isDeep);
  5672. case float32Tag: case float64Tag:
  5673. case int8Tag: case int16Tag: case int32Tag:
  5674. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5675. return cloneTypedArray(object, isDeep);
  5676. case mapTag:
  5677. return new Ctor;
  5678. case numberTag:
  5679. case stringTag:
  5680. return new Ctor(object);
  5681. case regexpTag:
  5682. return cloneRegExp(object);
  5683. case setTag:
  5684. return new Ctor;
  5685. case symbolTag:
  5686. return cloneSymbol(object);
  5687. }
  5688. }
  5689. /**
  5690. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5691. *
  5692. * @private
  5693. * @param {string} source The source to modify.
  5694. * @returns {Array} details The details to insert.
  5695. * @returns {string} Returns the modified source.
  5696. */
  5697. function insertWrapDetails(source, details) {
  5698. var length = details.length;
  5699. if (!length) {
  5700. return source;
  5701. }
  5702. var lastIndex = length - 1;
  5703. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  5704. details = details.join(length > 2 ? ', ' : ' ');
  5705. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  5706. }
  5707. /**
  5708. * Checks if `value` is a flattenable `arguments` object or array.
  5709. *
  5710. * @private
  5711. * @param {*} value The value to check.
  5712. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5713. */
  5714. function isFlattenable(value) {
  5715. return isArray(value) || isArguments(value) ||
  5716. !!(spreadableSymbol && value && value[spreadableSymbol]);
  5717. }
  5718. /**
  5719. * Checks if `value` is a valid array-like index.
  5720. *
  5721. * @private
  5722. * @param {*} value The value to check.
  5723. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5724. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5725. */
  5726. function isIndex(value, length) {
  5727. var type = typeof value;
  5728. length = length == null ? MAX_SAFE_INTEGER : length;
  5729. return !!length &&
  5730. (type == 'number' ||
  5731. (type != 'symbol' && reIsUint.test(value))) &&
  5732. (value > -1 && value % 1 == 0 && value < length);
  5733. }
  5734. /**
  5735. * Checks if the given arguments are from an iteratee call.
  5736. *
  5737. * @private
  5738. * @param {*} value The potential iteratee value argument.
  5739. * @param {*} index The potential iteratee index or key argument.
  5740. * @param {*} object The potential iteratee object argument.
  5741. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  5742. * else `false`.
  5743. */
  5744. function isIterateeCall(value, index, object) {
  5745. if (!isObject(object)) {
  5746. return false;
  5747. }
  5748. var type = typeof index;
  5749. if (type == 'number'
  5750. ? (isArrayLike(object) && isIndex(index, object.length))
  5751. : (type == 'string' && index in object)
  5752. ) {
  5753. return eq(object[index], value);
  5754. }
  5755. return false;
  5756. }
  5757. /**
  5758. * Checks if `value` is a property name and not a property path.
  5759. *
  5760. * @private
  5761. * @param {*} value The value to check.
  5762. * @param {Object} [object] The object to query keys on.
  5763. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5764. */
  5765. function isKey(value, object) {
  5766. if (isArray(value)) {
  5767. return false;
  5768. }
  5769. var type = typeof value;
  5770. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5771. value == null || isSymbol(value)) {
  5772. return true;
  5773. }
  5774. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5775. (object != null && value in Object(object));
  5776. }
  5777. /**
  5778. * Checks if `value` is suitable for use as unique object key.
  5779. *
  5780. * @private
  5781. * @param {*} value The value to check.
  5782. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  5783. */
  5784. function isKeyable(value) {
  5785. var type = typeof value;
  5786. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  5787. ? (value !== '__proto__')
  5788. : (value === null);
  5789. }
  5790. /**
  5791. * Checks if `func` has a lazy counterpart.
  5792. *
  5793. * @private
  5794. * @param {Function} func The function to check.
  5795. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  5796. * else `false`.
  5797. */
  5798. function isLaziable(func) {
  5799. var funcName = getFuncName(func),
  5800. other = lodash[funcName];
  5801. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  5802. return false;
  5803. }
  5804. if (func === other) {
  5805. return true;
  5806. }
  5807. var data = getData(other);
  5808. return !!data && func === data[0];
  5809. }
  5810. /**
  5811. * Checks if `func` has its source masked.
  5812. *
  5813. * @private
  5814. * @param {Function} func The function to check.
  5815. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  5816. */
  5817. function isMasked(func) {
  5818. return !!maskSrcKey && (maskSrcKey in func);
  5819. }
  5820. /**
  5821. * Checks if `func` is capable of being masked.
  5822. *
  5823. * @private
  5824. * @param {*} value The value to check.
  5825. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  5826. */
  5827. var isMaskable = coreJsData ? isFunction : stubFalse;
  5828. /**
  5829. * Checks if `value` is likely a prototype object.
  5830. *
  5831. * @private
  5832. * @param {*} value The value to check.
  5833. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  5834. */
  5835. function isPrototype(value) {
  5836. var Ctor = value && value.constructor,
  5837. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  5838. return value === proto;
  5839. }
  5840. /**
  5841. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5842. *
  5843. * @private
  5844. * @param {*} value The value to check.
  5845. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5846. * equality comparisons, else `false`.
  5847. */
  5848. function isStrictComparable(value) {
  5849. return value === value && !isObject(value);
  5850. }
  5851. /**
  5852. * A specialized version of `matchesProperty` for source values suitable
  5853. * for strict equality comparisons, i.e. `===`.
  5854. *
  5855. * @private
  5856. * @param {string} key The key of the property to get.
  5857. * @param {*} srcValue The value to match.
  5858. * @returns {Function} Returns the new spec function.
  5859. */
  5860. function matchesStrictComparable(key, srcValue) {
  5861. return function(object) {
  5862. if (object == null) {
  5863. return false;
  5864. }
  5865. return object[key] === srcValue &&
  5866. (srcValue !== undefined || (key in Object(object)));
  5867. };
  5868. }
  5869. /**
  5870. * A specialized version of `_.memoize` which clears the memoized function's
  5871. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  5872. *
  5873. * @private
  5874. * @param {Function} func The function to have its output memoized.
  5875. * @returns {Function} Returns the new memoized function.
  5876. */
  5877. function memoizeCapped(func) {
  5878. var result = memoize(func, function(key) {
  5879. if (cache.size === MAX_MEMOIZE_SIZE) {
  5880. cache.clear();
  5881. }
  5882. return key;
  5883. });
  5884. var cache = result.cache;
  5885. return result;
  5886. }
  5887. /**
  5888. * Merges the function metadata of `source` into `data`.
  5889. *
  5890. * Merging metadata reduces the number of wrappers used to invoke a function.
  5891. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  5892. * may be applied regardless of execution order. Methods like `_.ary` and
  5893. * `_.rearg` modify function arguments, making the order in which they are
  5894. * executed important, preventing the merging of metadata. However, we make
  5895. * an exception for a safe combined case where curried functions have `_.ary`
  5896. * and or `_.rearg` applied.
  5897. *
  5898. * @private
  5899. * @param {Array} data The destination metadata.
  5900. * @param {Array} source The source metadata.
  5901. * @returns {Array} Returns `data`.
  5902. */
  5903. function mergeData(data, source) {
  5904. var bitmask = data[1],
  5905. srcBitmask = source[1],
  5906. newBitmask = bitmask | srcBitmask,
  5907. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  5908. var isCombo =
  5909. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  5910. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  5911. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  5912. // Exit early if metadata can't be merged.
  5913. if (!(isCommon || isCombo)) {
  5914. return data;
  5915. }
  5916. // Use source `thisArg` if available.
  5917. if (srcBitmask & WRAP_BIND_FLAG) {
  5918. data[2] = source[2];
  5919. // Set when currying a bound function.
  5920. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  5921. }
  5922. // Compose partial arguments.
  5923. var value = source[3];
  5924. if (value) {
  5925. var partials = data[3];
  5926. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  5927. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  5928. }
  5929. // Compose partial right arguments.
  5930. value = source[5];
  5931. if (value) {
  5932. partials = data[5];
  5933. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  5934. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  5935. }
  5936. // Use source `argPos` if available.
  5937. value = source[7];
  5938. if (value) {
  5939. data[7] = value;
  5940. }
  5941. // Use source `ary` if it's smaller.
  5942. if (srcBitmask & WRAP_ARY_FLAG) {
  5943. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  5944. }
  5945. // Use source `arity` if one is not provided.
  5946. if (data[9] == null) {
  5947. data[9] = source[9];
  5948. }
  5949. // Use source `func` and merge bitmasks.
  5950. data[0] = source[0];
  5951. data[1] = newBitmask;
  5952. return data;
  5953. }
  5954. /**
  5955. * This function is like
  5956. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  5957. * except that it includes inherited enumerable properties.
  5958. *
  5959. * @private
  5960. * @param {Object} object The object to query.
  5961. * @returns {Array} Returns the array of property names.
  5962. */
  5963. function nativeKeysIn(object) {
  5964. var result = [];
  5965. if (object != null) {
  5966. for (var key in Object(object)) {
  5967. result.push(key);
  5968. }
  5969. }
  5970. return result;
  5971. }
  5972. /**
  5973. * Converts `value` to a string using `Object.prototype.toString`.
  5974. *
  5975. * @private
  5976. * @param {*} value The value to convert.
  5977. * @returns {string} Returns the converted string.
  5978. */
  5979. function objectToString(value) {
  5980. return nativeObjectToString.call(value);
  5981. }
  5982. /**
  5983. * A specialized version of `baseRest` which transforms the rest array.
  5984. *
  5985. * @private
  5986. * @param {Function} func The function to apply a rest parameter to.
  5987. * @param {number} [start=func.length-1] The start position of the rest parameter.
  5988. * @param {Function} transform The rest array transform.
  5989. * @returns {Function} Returns the new function.
  5990. */
  5991. function overRest(func, start, transform) {
  5992. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  5993. return function() {
  5994. var args = arguments,
  5995. index = -1,
  5996. length = nativeMax(args.length - start, 0),
  5997. array = Array(length);
  5998. while (++index < length) {
  5999. array[index] = args[start + index];
  6000. }
  6001. index = -1;
  6002. var otherArgs = Array(start + 1);
  6003. while (++index < start) {
  6004. otherArgs[index] = args[index];
  6005. }
  6006. otherArgs[start] = transform(array);
  6007. return apply(func, this, otherArgs);
  6008. };
  6009. }
  6010. /**
  6011. * Gets the parent value at `path` of `object`.
  6012. *
  6013. * @private
  6014. * @param {Object} object The object to query.
  6015. * @param {Array} path The path to get the parent value of.
  6016. * @returns {*} Returns the parent value.
  6017. */
  6018. function parent(object, path) {
  6019. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  6020. }
  6021. /**
  6022. * Reorder `array` according to the specified indexes where the element at
  6023. * the first index is assigned as the first element, the element at
  6024. * the second index is assigned as the second element, and so on.
  6025. *
  6026. * @private
  6027. * @param {Array} array The array to reorder.
  6028. * @param {Array} indexes The arranged array indexes.
  6029. * @returns {Array} Returns `array`.
  6030. */
  6031. function reorder(array, indexes) {
  6032. var arrLength = array.length,
  6033. length = nativeMin(indexes.length, arrLength),
  6034. oldArray = copyArray(array);
  6035. while (length--) {
  6036. var index = indexes[length];
  6037. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  6038. }
  6039. return array;
  6040. }
  6041. /**
  6042. * Sets metadata for `func`.
  6043. *
  6044. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  6045. * period of time, it will trip its breaker and transition to an identity
  6046. * function to avoid garbage collection pauses in V8. See
  6047. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  6048. * for more details.
  6049. *
  6050. * @private
  6051. * @param {Function} func The function to associate metadata with.
  6052. * @param {*} data The metadata.
  6053. * @returns {Function} Returns `func`.
  6054. */
  6055. var setData = shortOut(baseSetData);
  6056. /**
  6057. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  6058. *
  6059. * @private
  6060. * @param {Function} func The function to delay.
  6061. * @param {number} wait The number of milliseconds to delay invocation.
  6062. * @returns {number|Object} Returns the timer id or timeout object.
  6063. */
  6064. var setTimeout = ctxSetTimeout || function(func, wait) {
  6065. return root.setTimeout(func, wait);
  6066. };
  6067. /**
  6068. * Sets the `toString` method of `func` to return `string`.
  6069. *
  6070. * @private
  6071. * @param {Function} func The function to modify.
  6072. * @param {Function} string The `toString` result.
  6073. * @returns {Function} Returns `func`.
  6074. */
  6075. var setToString = shortOut(baseSetToString);
  6076. /**
  6077. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  6078. * with wrapper details in a comment at the top of the source body.
  6079. *
  6080. * @private
  6081. * @param {Function} wrapper The function to modify.
  6082. * @param {Function} reference The reference function.
  6083. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6084. * @returns {Function} Returns `wrapper`.
  6085. */
  6086. function setWrapToString(wrapper, reference, bitmask) {
  6087. var source = (reference + '');
  6088. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  6089. }
  6090. /**
  6091. * Creates a function that'll short out and invoke `identity` instead
  6092. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  6093. * milliseconds.
  6094. *
  6095. * @private
  6096. * @param {Function} func The function to restrict.
  6097. * @returns {Function} Returns the new shortable function.
  6098. */
  6099. function shortOut(func) {
  6100. var count = 0,
  6101. lastCalled = 0;
  6102. return function() {
  6103. var stamp = nativeNow(),
  6104. remaining = HOT_SPAN - (stamp - lastCalled);
  6105. lastCalled = stamp;
  6106. if (remaining > 0) {
  6107. if (++count >= HOT_COUNT) {
  6108. return arguments[0];
  6109. }
  6110. } else {
  6111. count = 0;
  6112. }
  6113. return func.apply(undefined, arguments);
  6114. };
  6115. }
  6116. /**
  6117. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  6118. *
  6119. * @private
  6120. * @param {Array} array The array to shuffle.
  6121. * @param {number} [size=array.length] The size of `array`.
  6122. * @returns {Array} Returns `array`.
  6123. */
  6124. function shuffleSelf(array, size) {
  6125. var index = -1,
  6126. length = array.length,
  6127. lastIndex = length - 1;
  6128. size = size === undefined ? length : size;
  6129. while (++index < size) {
  6130. var rand = baseRandom(index, lastIndex),
  6131. value = array[rand];
  6132. array[rand] = array[index];
  6133. array[index] = value;
  6134. }
  6135. array.length = size;
  6136. return array;
  6137. }
  6138. /**
  6139. * Converts `string` to a property path array.
  6140. *
  6141. * @private
  6142. * @param {string} string The string to convert.
  6143. * @returns {Array} Returns the property path array.
  6144. */
  6145. var stringToPath = memoizeCapped(function(string) {
  6146. var result = [];
  6147. if (string.charCodeAt(0) === 46 /* . */) {
  6148. result.push('');
  6149. }
  6150. string.replace(rePropName, function(match, number, quote, subString) {
  6151. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  6152. });
  6153. return result;
  6154. });
  6155. /**
  6156. * Converts `value` to a string key if it's not a string or symbol.
  6157. *
  6158. * @private
  6159. * @param {*} value The value to inspect.
  6160. * @returns {string|symbol} Returns the key.
  6161. */
  6162. function toKey(value) {
  6163. if (typeof value == 'string' || isSymbol(value)) {
  6164. return value;
  6165. }
  6166. var result = (value + '');
  6167. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  6168. }
  6169. /**
  6170. * Converts `func` to its source code.
  6171. *
  6172. * @private
  6173. * @param {Function} func The function to convert.
  6174. * @returns {string} Returns the source code.
  6175. */
  6176. function toSource(func) {
  6177. if (func != null) {
  6178. try {
  6179. return funcToString.call(func);
  6180. } catch (e) {}
  6181. try {
  6182. return (func + '');
  6183. } catch (e) {}
  6184. }
  6185. return '';
  6186. }
  6187. /**
  6188. * Updates wrapper `details` based on `bitmask` flags.
  6189. *
  6190. * @private
  6191. * @returns {Array} details The details to modify.
  6192. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6193. * @returns {Array} Returns `details`.
  6194. */
  6195. function updateWrapDetails(details, bitmask) {
  6196. arrayEach(wrapFlags, function(pair) {
  6197. var value = '_.' + pair[0];
  6198. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  6199. details.push(value);
  6200. }
  6201. });
  6202. return details.sort();
  6203. }
  6204. /**
  6205. * Creates a clone of `wrapper`.
  6206. *
  6207. * @private
  6208. * @param {Object} wrapper The wrapper to clone.
  6209. * @returns {Object} Returns the cloned wrapper.
  6210. */
  6211. function wrapperClone(wrapper) {
  6212. if (wrapper instanceof LazyWrapper) {
  6213. return wrapper.clone();
  6214. }
  6215. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  6216. result.__actions__ = copyArray(wrapper.__actions__);
  6217. result.__index__ = wrapper.__index__;
  6218. result.__values__ = wrapper.__values__;
  6219. return result;
  6220. }
  6221. /*------------------------------------------------------------------------*/
  6222. /**
  6223. * Creates an array of elements split into groups the length of `size`.
  6224. * If `array` can't be split evenly, the final chunk will be the remaining
  6225. * elements.
  6226. *
  6227. * @static
  6228. * @memberOf _
  6229. * @since 3.0.0
  6230. * @category Array
  6231. * @param {Array} array The array to process.
  6232. * @param {number} [size=1] The length of each chunk
  6233. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6234. * @returns {Array} Returns the new array of chunks.
  6235. * @example
  6236. *
  6237. * _.chunk(['a', 'b', 'c', 'd'], 2);
  6238. * // => [['a', 'b'], ['c', 'd']]
  6239. *
  6240. * _.chunk(['a', 'b', 'c', 'd'], 3);
  6241. * // => [['a', 'b', 'c'], ['d']]
  6242. */
  6243. function chunk(array, size, guard) {
  6244. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  6245. size = 1;
  6246. } else {
  6247. size = nativeMax(toInteger(size), 0);
  6248. }
  6249. var length = array == null ? 0 : array.length;
  6250. if (!length || size < 1) {
  6251. return [];
  6252. }
  6253. var index = 0,
  6254. resIndex = 0,
  6255. result = Array(nativeCeil(length / size));
  6256. while (index < length) {
  6257. result[resIndex++] = baseSlice(array, index, (index += size));
  6258. }
  6259. return result;
  6260. }
  6261. /**
  6262. * Creates an array with all falsey values removed. The values `false`, `null`,
  6263. * `0`, `""`, `undefined`, and `NaN` are falsey.
  6264. *
  6265. * @static
  6266. * @memberOf _
  6267. * @since 0.1.0
  6268. * @category Array
  6269. * @param {Array} array The array to compact.
  6270. * @returns {Array} Returns the new array of filtered values.
  6271. * @example
  6272. *
  6273. * _.compact([0, 1, false, 2, '', 3]);
  6274. * // => [1, 2, 3]
  6275. */
  6276. function compact(array) {
  6277. var index = -1,
  6278. length = array == null ? 0 : array.length,
  6279. resIndex = 0,
  6280. result = [];
  6281. while (++index < length) {
  6282. var value = array[index];
  6283. if (value) {
  6284. result[resIndex++] = value;
  6285. }
  6286. }
  6287. return result;
  6288. }
  6289. /**
  6290. * Creates a new array concatenating `array` with any additional arrays
  6291. * and/or values.
  6292. *
  6293. * @static
  6294. * @memberOf _
  6295. * @since 4.0.0
  6296. * @category Array
  6297. * @param {Array} array The array to concatenate.
  6298. * @param {...*} [values] The values to concatenate.
  6299. * @returns {Array} Returns the new concatenated array.
  6300. * @example
  6301. *
  6302. * var array = [1];
  6303. * var other = _.concat(array, 2, [3], [[4]]);
  6304. *
  6305. * console.log(other);
  6306. * // => [1, 2, 3, [4]]
  6307. *
  6308. * console.log(array);
  6309. * // => [1]
  6310. */
  6311. function concat() {
  6312. var length = arguments.length;
  6313. if (!length) {
  6314. return [];
  6315. }
  6316. var args = Array(length - 1),
  6317. array = arguments[0],
  6318. index = length;
  6319. while (index--) {
  6320. args[index - 1] = arguments[index];
  6321. }
  6322. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  6323. }
  6324. /**
  6325. * Creates an array of `array` values not included in the other given arrays
  6326. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6327. * for equality comparisons. The order and references of result values are
  6328. * determined by the first array.
  6329. *
  6330. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  6331. *
  6332. * @static
  6333. * @memberOf _
  6334. * @since 0.1.0
  6335. * @category Array
  6336. * @param {Array} array The array to inspect.
  6337. * @param {...Array} [values] The values to exclude.
  6338. * @returns {Array} Returns the new array of filtered values.
  6339. * @see _.without, _.xor
  6340. * @example
  6341. *
  6342. * _.difference([2, 1], [2, 3]);
  6343. * // => [1]
  6344. */
  6345. var difference = baseRest(function(array, values) {
  6346. return isArrayLikeObject(array)
  6347. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  6348. : [];
  6349. });
  6350. /**
  6351. * This method is like `_.difference` except that it accepts `iteratee` which
  6352. * is invoked for each element of `array` and `values` to generate the criterion
  6353. * by which they're compared. The order and references of result values are
  6354. * determined by the first array. The iteratee is invoked with one argument:
  6355. * (value).
  6356. *
  6357. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  6358. *
  6359. * @static
  6360. * @memberOf _
  6361. * @since 4.0.0
  6362. * @category Array
  6363. * @param {Array} array The array to inspect.
  6364. * @param {...Array} [values] The values to exclude.
  6365. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6366. * @returns {Array} Returns the new array of filtered values.
  6367. * @example
  6368. *
  6369. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6370. * // => [1.2]
  6371. *
  6372. * // The `_.property` iteratee shorthand.
  6373. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  6374. * // => [{ 'x': 2 }]
  6375. */
  6376. var differenceBy = baseRest(function(array, values) {
  6377. var iteratee = last(values);
  6378. if (isArrayLikeObject(iteratee)) {
  6379. iteratee = undefined;
  6380. }
  6381. return isArrayLikeObject(array)
  6382. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  6383. : [];
  6384. });
  6385. /**
  6386. * This method is like `_.difference` except that it accepts `comparator`
  6387. * which is invoked to compare elements of `array` to `values`. The order and
  6388. * references of result values are determined by the first array. The comparator
  6389. * is invoked with two arguments: (arrVal, othVal).
  6390. *
  6391. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  6392. *
  6393. * @static
  6394. * @memberOf _
  6395. * @since 4.0.0
  6396. * @category Array
  6397. * @param {Array} array The array to inspect.
  6398. * @param {...Array} [values] The values to exclude.
  6399. * @param {Function} [comparator] The comparator invoked per element.
  6400. * @returns {Array} Returns the new array of filtered values.
  6401. * @example
  6402. *
  6403. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6404. *
  6405. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  6406. * // => [{ 'x': 2, 'y': 1 }]
  6407. */
  6408. var differenceWith = baseRest(function(array, values) {
  6409. var comparator = last(values);
  6410. if (isArrayLikeObject(comparator)) {
  6411. comparator = undefined;
  6412. }
  6413. return isArrayLikeObject(array)
  6414. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  6415. : [];
  6416. });
  6417. /**
  6418. * Creates a slice of `array` with `n` elements dropped from the beginning.
  6419. *
  6420. * @static
  6421. * @memberOf _
  6422. * @since 0.5.0
  6423. * @category Array
  6424. * @param {Array} array The array to query.
  6425. * @param {number} [n=1] The number of elements to drop.
  6426. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6427. * @returns {Array} Returns the slice of `array`.
  6428. * @example
  6429. *
  6430. * _.drop([1, 2, 3]);
  6431. * // => [2, 3]
  6432. *
  6433. * _.drop([1, 2, 3], 2);
  6434. * // => [3]
  6435. *
  6436. * _.drop([1, 2, 3], 5);
  6437. * // => []
  6438. *
  6439. * _.drop([1, 2, 3], 0);
  6440. * // => [1, 2, 3]
  6441. */
  6442. function drop(array, n, guard) {
  6443. var length = array == null ? 0 : array.length;
  6444. if (!length) {
  6445. return [];
  6446. }
  6447. n = (guard || n === undefined) ? 1 : toInteger(n);
  6448. return baseSlice(array, n < 0 ? 0 : n, length);
  6449. }
  6450. /**
  6451. * Creates a slice of `array` with `n` elements dropped from the end.
  6452. *
  6453. * @static
  6454. * @memberOf _
  6455. * @since 3.0.0
  6456. * @category Array
  6457. * @param {Array} array The array to query.
  6458. * @param {number} [n=1] The number of elements to drop.
  6459. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6460. * @returns {Array} Returns the slice of `array`.
  6461. * @example
  6462. *
  6463. * _.dropRight([1, 2, 3]);
  6464. * // => [1, 2]
  6465. *
  6466. * _.dropRight([1, 2, 3], 2);
  6467. * // => [1]
  6468. *
  6469. * _.dropRight([1, 2, 3], 5);
  6470. * // => []
  6471. *
  6472. * _.dropRight([1, 2, 3], 0);
  6473. * // => [1, 2, 3]
  6474. */
  6475. function dropRight(array, n, guard) {
  6476. var length = array == null ? 0 : array.length;
  6477. if (!length) {
  6478. return [];
  6479. }
  6480. n = (guard || n === undefined) ? 1 : toInteger(n);
  6481. n = length - n;
  6482. return baseSlice(array, 0, n < 0 ? 0 : n);
  6483. }
  6484. /**
  6485. * Creates a slice of `array` excluding elements dropped from the end.
  6486. * Elements are dropped until `predicate` returns falsey. The predicate is
  6487. * invoked with three arguments: (value, index, array).
  6488. *
  6489. * @static
  6490. * @memberOf _
  6491. * @since 3.0.0
  6492. * @category Array
  6493. * @param {Array} array The array to query.
  6494. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6495. * @returns {Array} Returns the slice of `array`.
  6496. * @example
  6497. *
  6498. * var users = [
  6499. * { 'user': 'barney', 'active': true },
  6500. * { 'user': 'fred', 'active': false },
  6501. * { 'user': 'pebbles', 'active': false }
  6502. * ];
  6503. *
  6504. * _.dropRightWhile(users, function(o) { return !o.active; });
  6505. * // => objects for ['barney']
  6506. *
  6507. * // The `_.matches` iteratee shorthand.
  6508. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  6509. * // => objects for ['barney', 'fred']
  6510. *
  6511. * // The `_.matchesProperty` iteratee shorthand.
  6512. * _.dropRightWhile(users, ['active', false]);
  6513. * // => objects for ['barney']
  6514. *
  6515. * // The `_.property` iteratee shorthand.
  6516. * _.dropRightWhile(users, 'active');
  6517. * // => objects for ['barney', 'fred', 'pebbles']
  6518. */
  6519. function dropRightWhile(array, predicate) {
  6520. return (array && array.length)
  6521. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  6522. : [];
  6523. }
  6524. /**
  6525. * Creates a slice of `array` excluding elements dropped from the beginning.
  6526. * Elements are dropped until `predicate` returns falsey. The predicate is
  6527. * invoked with three arguments: (value, index, array).
  6528. *
  6529. * @static
  6530. * @memberOf _
  6531. * @since 3.0.0
  6532. * @category Array
  6533. * @param {Array} array The array to query.
  6534. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6535. * @returns {Array} Returns the slice of `array`.
  6536. * @example
  6537. *
  6538. * var users = [
  6539. * { 'user': 'barney', 'active': false },
  6540. * { 'user': 'fred', 'active': false },
  6541. * { 'user': 'pebbles', 'active': true }
  6542. * ];
  6543. *
  6544. * _.dropWhile(users, function(o) { return !o.active; });
  6545. * // => objects for ['pebbles']
  6546. *
  6547. * // The `_.matches` iteratee shorthand.
  6548. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  6549. * // => objects for ['fred', 'pebbles']
  6550. *
  6551. * // The `_.matchesProperty` iteratee shorthand.
  6552. * _.dropWhile(users, ['active', false]);
  6553. * // => objects for ['pebbles']
  6554. *
  6555. * // The `_.property` iteratee shorthand.
  6556. * _.dropWhile(users, 'active');
  6557. * // => objects for ['barney', 'fred', 'pebbles']
  6558. */
  6559. function dropWhile(array, predicate) {
  6560. return (array && array.length)
  6561. ? baseWhile(array, getIteratee(predicate, 3), true)
  6562. : [];
  6563. }
  6564. /**
  6565. * Fills elements of `array` with `value` from `start` up to, but not
  6566. * including, `end`.
  6567. *
  6568. * **Note:** This method mutates `array`.
  6569. *
  6570. * @static
  6571. * @memberOf _
  6572. * @since 3.2.0
  6573. * @category Array
  6574. * @param {Array} array The array to fill.
  6575. * @param {*} value The value to fill `array` with.
  6576. * @param {number} [start=0] The start position.
  6577. * @param {number} [end=array.length] The end position.
  6578. * @returns {Array} Returns `array`.
  6579. * @example
  6580. *
  6581. * var array = [1, 2, 3];
  6582. *
  6583. * _.fill(array, 'a');
  6584. * console.log(array);
  6585. * // => ['a', 'a', 'a']
  6586. *
  6587. * _.fill(Array(3), 2);
  6588. * // => [2, 2, 2]
  6589. *
  6590. * _.fill([4, 6, 8, 10], '*', 1, 3);
  6591. * // => [4, '*', '*', 10]
  6592. */
  6593. function fill(array, value, start, end) {
  6594. var length = array == null ? 0 : array.length;
  6595. if (!length) {
  6596. return [];
  6597. }
  6598. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6599. start = 0;
  6600. end = length;
  6601. }
  6602. return baseFill(array, value, start, end);
  6603. }
  6604. /**
  6605. * This method is like `_.find` except that it returns the index of the first
  6606. * element `predicate` returns truthy for instead of the element itself.
  6607. *
  6608. * @static
  6609. * @memberOf _
  6610. * @since 1.1.0
  6611. * @category Array
  6612. * @param {Array} array The array to inspect.
  6613. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6614. * @param {number} [fromIndex=0] The index to search from.
  6615. * @returns {number} Returns the index of the found element, else `-1`.
  6616. * @example
  6617. *
  6618. * var users = [
  6619. * { 'user': 'barney', 'active': false },
  6620. * { 'user': 'fred', 'active': false },
  6621. * { 'user': 'pebbles', 'active': true }
  6622. * ];
  6623. *
  6624. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  6625. * // => 0
  6626. *
  6627. * // The `_.matches` iteratee shorthand.
  6628. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6629. * // => 1
  6630. *
  6631. * // The `_.matchesProperty` iteratee shorthand.
  6632. * _.findIndex(users, ['active', false]);
  6633. * // => 0
  6634. *
  6635. * // The `_.property` iteratee shorthand.
  6636. * _.findIndex(users, 'active');
  6637. * // => 2
  6638. */
  6639. function findIndex(array, predicate, fromIndex) {
  6640. var length = array == null ? 0 : array.length;
  6641. if (!length) {
  6642. return -1;
  6643. }
  6644. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6645. if (index < 0) {
  6646. index = nativeMax(length + index, 0);
  6647. }
  6648. return baseFindIndex(array, getIteratee(predicate, 3), index);
  6649. }
  6650. /**
  6651. * This method is like `_.findIndex` except that it iterates over elements
  6652. * of `collection` from right to left.
  6653. *
  6654. * @static
  6655. * @memberOf _
  6656. * @since 2.0.0
  6657. * @category Array
  6658. * @param {Array} array The array to inspect.
  6659. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6660. * @param {number} [fromIndex=array.length-1] The index to search from.
  6661. * @returns {number} Returns the index of the found element, else `-1`.
  6662. * @example
  6663. *
  6664. * var users = [
  6665. * { 'user': 'barney', 'active': true },
  6666. * { 'user': 'fred', 'active': false },
  6667. * { 'user': 'pebbles', 'active': false }
  6668. * ];
  6669. *
  6670. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  6671. * // => 2
  6672. *
  6673. * // The `_.matches` iteratee shorthand.
  6674. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6675. * // => 0
  6676. *
  6677. * // The `_.matchesProperty` iteratee shorthand.
  6678. * _.findLastIndex(users, ['active', false]);
  6679. * // => 2
  6680. *
  6681. * // The `_.property` iteratee shorthand.
  6682. * _.findLastIndex(users, 'active');
  6683. * // => 0
  6684. */
  6685. function findLastIndex(array, predicate, fromIndex) {
  6686. var length = array == null ? 0 : array.length;
  6687. if (!length) {
  6688. return -1;
  6689. }
  6690. var index = length - 1;
  6691. if (fromIndex !== undefined) {
  6692. index = toInteger(fromIndex);
  6693. index = fromIndex < 0
  6694. ? nativeMax(length + index, 0)
  6695. : nativeMin(index, length - 1);
  6696. }
  6697. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  6698. }
  6699. /**
  6700. * Flattens `array` a single level deep.
  6701. *
  6702. * @static
  6703. * @memberOf _
  6704. * @since 0.1.0
  6705. * @category Array
  6706. * @param {Array} array The array to flatten.
  6707. * @returns {Array} Returns the new flattened array.
  6708. * @example
  6709. *
  6710. * _.flatten([1, [2, [3, [4]], 5]]);
  6711. * // => [1, 2, [3, [4]], 5]
  6712. */
  6713. function flatten(array) {
  6714. var length = array == null ? 0 : array.length;
  6715. return length ? baseFlatten(array, 1) : [];
  6716. }
  6717. /**
  6718. * Recursively flattens `array`.
  6719. *
  6720. * @static
  6721. * @memberOf _
  6722. * @since 3.0.0
  6723. * @category Array
  6724. * @param {Array} array The array to flatten.
  6725. * @returns {Array} Returns the new flattened array.
  6726. * @example
  6727. *
  6728. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  6729. * // => [1, 2, 3, 4, 5]
  6730. */
  6731. function flattenDeep(array) {
  6732. var length = array == null ? 0 : array.length;
  6733. return length ? baseFlatten(array, INFINITY) : [];
  6734. }
  6735. /**
  6736. * Recursively flatten `array` up to `depth` times.
  6737. *
  6738. * @static
  6739. * @memberOf _
  6740. * @since 4.4.0
  6741. * @category Array
  6742. * @param {Array} array The array to flatten.
  6743. * @param {number} [depth=1] The maximum recursion depth.
  6744. * @returns {Array} Returns the new flattened array.
  6745. * @example
  6746. *
  6747. * var array = [1, [2, [3, [4]], 5]];
  6748. *
  6749. * _.flattenDepth(array, 1);
  6750. * // => [1, 2, [3, [4]], 5]
  6751. *
  6752. * _.flattenDepth(array, 2);
  6753. * // => [1, 2, 3, [4], 5]
  6754. */
  6755. function flattenDepth(array, depth) {
  6756. var length = array == null ? 0 : array.length;
  6757. if (!length) {
  6758. return [];
  6759. }
  6760. depth = depth === undefined ? 1 : toInteger(depth);
  6761. return baseFlatten(array, depth);
  6762. }
  6763. /**
  6764. * The inverse of `_.toPairs`; this method returns an object composed
  6765. * from key-value `pairs`.
  6766. *
  6767. * @static
  6768. * @memberOf _
  6769. * @since 4.0.0
  6770. * @category Array
  6771. * @param {Array} pairs The key-value pairs.
  6772. * @returns {Object} Returns the new object.
  6773. * @example
  6774. *
  6775. * _.fromPairs([['a', 1], ['b', 2]]);
  6776. * // => { 'a': 1, 'b': 2 }
  6777. */
  6778. function fromPairs(pairs) {
  6779. var index = -1,
  6780. length = pairs == null ? 0 : pairs.length,
  6781. result = {};
  6782. while (++index < length) {
  6783. var pair = pairs[index];
  6784. result[pair[0]] = pair[1];
  6785. }
  6786. return result;
  6787. }
  6788. /**
  6789. * Gets the first element of `array`.
  6790. *
  6791. * @static
  6792. * @memberOf _
  6793. * @since 0.1.0
  6794. * @alias first
  6795. * @category Array
  6796. * @param {Array} array The array to query.
  6797. * @returns {*} Returns the first element of `array`.
  6798. * @example
  6799. *
  6800. * _.head([1, 2, 3]);
  6801. * // => 1
  6802. *
  6803. * _.head([]);
  6804. * // => undefined
  6805. */
  6806. function head(array) {
  6807. return (array && array.length) ? array[0] : undefined;
  6808. }
  6809. /**
  6810. * Gets the index at which the first occurrence of `value` is found in `array`
  6811. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6812. * for equality comparisons. If `fromIndex` is negative, it's used as the
  6813. * offset from the end of `array`.
  6814. *
  6815. * @static
  6816. * @memberOf _
  6817. * @since 0.1.0
  6818. * @category Array
  6819. * @param {Array} array The array to inspect.
  6820. * @param {*} value The value to search for.
  6821. * @param {number} [fromIndex=0] The index to search from.
  6822. * @returns {number} Returns the index of the matched value, else `-1`.
  6823. * @example
  6824. *
  6825. * _.indexOf([1, 2, 1, 2], 2);
  6826. * // => 1
  6827. *
  6828. * // Search from the `fromIndex`.
  6829. * _.indexOf([1, 2, 1, 2], 2, 2);
  6830. * // => 3
  6831. */
  6832. function indexOf(array, value, fromIndex) {
  6833. var length = array == null ? 0 : array.length;
  6834. if (!length) {
  6835. return -1;
  6836. }
  6837. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6838. if (index < 0) {
  6839. index = nativeMax(length + index, 0);
  6840. }
  6841. return baseIndexOf(array, value, index);
  6842. }
  6843. /**
  6844. * Gets all but the last element of `array`.
  6845. *
  6846. * @static
  6847. * @memberOf _
  6848. * @since 0.1.0
  6849. * @category Array
  6850. * @param {Array} array The array to query.
  6851. * @returns {Array} Returns the slice of `array`.
  6852. * @example
  6853. *
  6854. * _.initial([1, 2, 3]);
  6855. * // => [1, 2]
  6856. */
  6857. function initial(array) {
  6858. var length = array == null ? 0 : array.length;
  6859. return length ? baseSlice(array, 0, -1) : [];
  6860. }
  6861. /**
  6862. * Creates an array of unique values that are included in all given arrays
  6863. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6864. * for equality comparisons. The order and references of result values are
  6865. * determined by the first array.
  6866. *
  6867. * @static
  6868. * @memberOf _
  6869. * @since 0.1.0
  6870. * @category Array
  6871. * @param {...Array} [arrays] The arrays to inspect.
  6872. * @returns {Array} Returns the new array of intersecting values.
  6873. * @example
  6874. *
  6875. * _.intersection([2, 1], [2, 3]);
  6876. * // => [2]
  6877. */
  6878. var intersection = baseRest(function(arrays) {
  6879. var mapped = arrayMap(arrays, castArrayLikeObject);
  6880. return (mapped.length && mapped[0] === arrays[0])
  6881. ? baseIntersection(mapped)
  6882. : [];
  6883. });
  6884. /**
  6885. * This method is like `_.intersection` except that it accepts `iteratee`
  6886. * which is invoked for each element of each `arrays` to generate the criterion
  6887. * by which they're compared. The order and references of result values are
  6888. * determined by the first array. The iteratee is invoked with one argument:
  6889. * (value).
  6890. *
  6891. * @static
  6892. * @memberOf _
  6893. * @since 4.0.0
  6894. * @category Array
  6895. * @param {...Array} [arrays] The arrays to inspect.
  6896. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6897. * @returns {Array} Returns the new array of intersecting values.
  6898. * @example
  6899. *
  6900. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6901. * // => [2.1]
  6902. *
  6903. * // The `_.property` iteratee shorthand.
  6904. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  6905. * // => [{ 'x': 1 }]
  6906. */
  6907. var intersectionBy = baseRest(function(arrays) {
  6908. var iteratee = last(arrays),
  6909. mapped = arrayMap(arrays, castArrayLikeObject);
  6910. if (iteratee === last(mapped)) {
  6911. iteratee = undefined;
  6912. } else {
  6913. mapped.pop();
  6914. }
  6915. return (mapped.length && mapped[0] === arrays[0])
  6916. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  6917. : [];
  6918. });
  6919. /**
  6920. * This method is like `_.intersection` except that it accepts `comparator`
  6921. * which is invoked to compare elements of `arrays`. The order and references
  6922. * of result values are determined by the first array. The comparator is
  6923. * invoked with two arguments: (arrVal, othVal).
  6924. *
  6925. * @static
  6926. * @memberOf _
  6927. * @since 4.0.0
  6928. * @category Array
  6929. * @param {...Array} [arrays] The arrays to inspect.
  6930. * @param {Function} [comparator] The comparator invoked per element.
  6931. * @returns {Array} Returns the new array of intersecting values.
  6932. * @example
  6933. *
  6934. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6935. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  6936. *
  6937. * _.intersectionWith(objects, others, _.isEqual);
  6938. * // => [{ 'x': 1, 'y': 2 }]
  6939. */
  6940. var intersectionWith = baseRest(function(arrays) {
  6941. var comparator = last(arrays),
  6942. mapped = arrayMap(arrays, castArrayLikeObject);
  6943. comparator = typeof comparator == 'function' ? comparator : undefined;
  6944. if (comparator) {
  6945. mapped.pop();
  6946. }
  6947. return (mapped.length && mapped[0] === arrays[0])
  6948. ? baseIntersection(mapped, undefined, comparator)
  6949. : [];
  6950. });
  6951. /**
  6952. * Converts all elements in `array` into a string separated by `separator`.
  6953. *
  6954. * @static
  6955. * @memberOf _
  6956. * @since 4.0.0
  6957. * @category Array
  6958. * @param {Array} array The array to convert.
  6959. * @param {string} [separator=','] The element separator.
  6960. * @returns {string} Returns the joined string.
  6961. * @example
  6962. *
  6963. * _.join(['a', 'b', 'c'], '~');
  6964. * // => 'a~b~c'
  6965. */
  6966. function join(array, separator) {
  6967. return array == null ? '' : nativeJoin.call(array, separator);
  6968. }
  6969. /**
  6970. * Gets the last element of `array`.
  6971. *
  6972. * @static
  6973. * @memberOf _
  6974. * @since 0.1.0
  6975. * @category Array
  6976. * @param {Array} array The array to query.
  6977. * @returns {*} Returns the last element of `array`.
  6978. * @example
  6979. *
  6980. * _.last([1, 2, 3]);
  6981. * // => 3
  6982. */
  6983. function last(array) {
  6984. var length = array == null ? 0 : array.length;
  6985. return length ? array[length - 1] : undefined;
  6986. }
  6987. /**
  6988. * This method is like `_.indexOf` except that it iterates over elements of
  6989. * `array` from right to left.
  6990. *
  6991. * @static
  6992. * @memberOf _
  6993. * @since 0.1.0
  6994. * @category Array
  6995. * @param {Array} array The array to inspect.
  6996. * @param {*} value The value to search for.
  6997. * @param {number} [fromIndex=array.length-1] The index to search from.
  6998. * @returns {number} Returns the index of the matched value, else `-1`.
  6999. * @example
  7000. *
  7001. * _.lastIndexOf([1, 2, 1, 2], 2);
  7002. * // => 3
  7003. *
  7004. * // Search from the `fromIndex`.
  7005. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  7006. * // => 1
  7007. */
  7008. function lastIndexOf(array, value, fromIndex) {
  7009. var length = array == null ? 0 : array.length;
  7010. if (!length) {
  7011. return -1;
  7012. }
  7013. var index = length;
  7014. if (fromIndex !== undefined) {
  7015. index = toInteger(fromIndex);
  7016. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  7017. }
  7018. return value === value
  7019. ? strictLastIndexOf(array, value, index)
  7020. : baseFindIndex(array, baseIsNaN, index, true);
  7021. }
  7022. /**
  7023. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  7024. * element from the end is returned.
  7025. *
  7026. * @static
  7027. * @memberOf _
  7028. * @since 4.11.0
  7029. * @category Array
  7030. * @param {Array} array The array to query.
  7031. * @param {number} [n=0] The index of the element to return.
  7032. * @returns {*} Returns the nth element of `array`.
  7033. * @example
  7034. *
  7035. * var array = ['a', 'b', 'c', 'd'];
  7036. *
  7037. * _.nth(array, 1);
  7038. * // => 'b'
  7039. *
  7040. * _.nth(array, -2);
  7041. * // => 'c';
  7042. */
  7043. function nth(array, n) {
  7044. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  7045. }
  7046. /**
  7047. * Removes all given values from `array` using
  7048. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7049. * for equality comparisons.
  7050. *
  7051. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  7052. * to remove elements from an array by predicate.
  7053. *
  7054. * @static
  7055. * @memberOf _
  7056. * @since 2.0.0
  7057. * @category Array
  7058. * @param {Array} array The array to modify.
  7059. * @param {...*} [values] The values to remove.
  7060. * @returns {Array} Returns `array`.
  7061. * @example
  7062. *
  7063. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7064. *
  7065. * _.pull(array, 'a', 'c');
  7066. * console.log(array);
  7067. * // => ['b', 'b']
  7068. */
  7069. var pull = baseRest(pullAll);
  7070. /**
  7071. * This method is like `_.pull` except that it accepts an array of values to remove.
  7072. *
  7073. * **Note:** Unlike `_.difference`, this method mutates `array`.
  7074. *
  7075. * @static
  7076. * @memberOf _
  7077. * @since 4.0.0
  7078. * @category Array
  7079. * @param {Array} array The array to modify.
  7080. * @param {Array} values The values to remove.
  7081. * @returns {Array} Returns `array`.
  7082. * @example
  7083. *
  7084. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7085. *
  7086. * _.pullAll(array, ['a', 'c']);
  7087. * console.log(array);
  7088. * // => ['b', 'b']
  7089. */
  7090. function pullAll(array, values) {
  7091. return (array && array.length && values && values.length)
  7092. ? basePullAll(array, values)
  7093. : array;
  7094. }
  7095. /**
  7096. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  7097. * invoked for each element of `array` and `values` to generate the criterion
  7098. * by which they're compared. The iteratee is invoked with one argument: (value).
  7099. *
  7100. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  7101. *
  7102. * @static
  7103. * @memberOf _
  7104. * @since 4.0.0
  7105. * @category Array
  7106. * @param {Array} array The array to modify.
  7107. * @param {Array} values The values to remove.
  7108. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7109. * @returns {Array} Returns `array`.
  7110. * @example
  7111. *
  7112. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  7113. *
  7114. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  7115. * console.log(array);
  7116. * // => [{ 'x': 2 }]
  7117. */
  7118. function pullAllBy(array, values, iteratee) {
  7119. return (array && array.length && values && values.length)
  7120. ? basePullAll(array, values, getIteratee(iteratee, 2))
  7121. : array;
  7122. }
  7123. /**
  7124. * This method is like `_.pullAll` except that it accepts `comparator` which
  7125. * is invoked to compare elements of `array` to `values`. The comparator is
  7126. * invoked with two arguments: (arrVal, othVal).
  7127. *
  7128. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  7129. *
  7130. * @static
  7131. * @memberOf _
  7132. * @since 4.6.0
  7133. * @category Array
  7134. * @param {Array} array The array to modify.
  7135. * @param {Array} values The values to remove.
  7136. * @param {Function} [comparator] The comparator invoked per element.
  7137. * @returns {Array} Returns `array`.
  7138. * @example
  7139. *
  7140. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  7141. *
  7142. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  7143. * console.log(array);
  7144. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  7145. */
  7146. function pullAllWith(array, values, comparator) {
  7147. return (array && array.length && values && values.length)
  7148. ? basePullAll(array, values, undefined, comparator)
  7149. : array;
  7150. }
  7151. /**
  7152. * Removes elements from `array` corresponding to `indexes` and returns an
  7153. * array of removed elements.
  7154. *
  7155. * **Note:** Unlike `_.at`, this method mutates `array`.
  7156. *
  7157. * @static
  7158. * @memberOf _
  7159. * @since 3.0.0
  7160. * @category Array
  7161. * @param {Array} array The array to modify.
  7162. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  7163. * @returns {Array} Returns the new array of removed elements.
  7164. * @example
  7165. *
  7166. * var array = ['a', 'b', 'c', 'd'];
  7167. * var pulled = _.pullAt(array, [1, 3]);
  7168. *
  7169. * console.log(array);
  7170. * // => ['a', 'c']
  7171. *
  7172. * console.log(pulled);
  7173. * // => ['b', 'd']
  7174. */
  7175. var pullAt = flatRest(function(array, indexes) {
  7176. var length = array == null ? 0 : array.length,
  7177. result = baseAt(array, indexes);
  7178. basePullAt(array, arrayMap(indexes, function(index) {
  7179. return isIndex(index, length) ? +index : index;
  7180. }).sort(compareAscending));
  7181. return result;
  7182. });
  7183. /**
  7184. * Removes all elements from `array` that `predicate` returns truthy for
  7185. * and returns an array of the removed elements. The predicate is invoked
  7186. * with three arguments: (value, index, array).
  7187. *
  7188. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  7189. * to pull elements from an array by value.
  7190. *
  7191. * @static
  7192. * @memberOf _
  7193. * @since 2.0.0
  7194. * @category Array
  7195. * @param {Array} array The array to modify.
  7196. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7197. * @returns {Array} Returns the new array of removed elements.
  7198. * @example
  7199. *
  7200. * var array = [1, 2, 3, 4];
  7201. * var evens = _.remove(array, function(n) {
  7202. * return n % 2 == 0;
  7203. * });
  7204. *
  7205. * console.log(array);
  7206. * // => [1, 3]
  7207. *
  7208. * console.log(evens);
  7209. * // => [2, 4]
  7210. */
  7211. function remove(array, predicate) {
  7212. var result = [];
  7213. if (!(array && array.length)) {
  7214. return result;
  7215. }
  7216. var index = -1,
  7217. indexes = [],
  7218. length = array.length;
  7219. predicate = getIteratee(predicate, 3);
  7220. while (++index < length) {
  7221. var value = array[index];
  7222. if (predicate(value, index, array)) {
  7223. result.push(value);
  7224. indexes.push(index);
  7225. }
  7226. }
  7227. basePullAt(array, indexes);
  7228. return result;
  7229. }
  7230. /**
  7231. * Reverses `array` so that the first element becomes the last, the second
  7232. * element becomes the second to last, and so on.
  7233. *
  7234. * **Note:** This method mutates `array` and is based on
  7235. * [`Array#reverse`](https://mdn.io/Array/reverse).
  7236. *
  7237. * @static
  7238. * @memberOf _
  7239. * @since 4.0.0
  7240. * @category Array
  7241. * @param {Array} array The array to modify.
  7242. * @returns {Array} Returns `array`.
  7243. * @example
  7244. *
  7245. * var array = [1, 2, 3];
  7246. *
  7247. * _.reverse(array);
  7248. * // => [3, 2, 1]
  7249. *
  7250. * console.log(array);
  7251. * // => [3, 2, 1]
  7252. */
  7253. function reverse(array) {
  7254. return array == null ? array : nativeReverse.call(array);
  7255. }
  7256. /**
  7257. * Creates a slice of `array` from `start` up to, but not including, `end`.
  7258. *
  7259. * **Note:** This method is used instead of
  7260. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  7261. * returned.
  7262. *
  7263. * @static
  7264. * @memberOf _
  7265. * @since 3.0.0
  7266. * @category Array
  7267. * @param {Array} array The array to slice.
  7268. * @param {number} [start=0] The start position.
  7269. * @param {number} [end=array.length] The end position.
  7270. * @returns {Array} Returns the slice of `array`.
  7271. */
  7272. function slice(array, start, end) {
  7273. var length = array == null ? 0 : array.length;
  7274. if (!length) {
  7275. return [];
  7276. }
  7277. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  7278. start = 0;
  7279. end = length;
  7280. }
  7281. else {
  7282. start = start == null ? 0 : toInteger(start);
  7283. end = end === undefined ? length : toInteger(end);
  7284. }
  7285. return baseSlice(array, start, end);
  7286. }
  7287. /**
  7288. * Uses a binary search to determine the lowest index at which `value`
  7289. * should be inserted into `array` in order to maintain its sort order.
  7290. *
  7291. * @static
  7292. * @memberOf _
  7293. * @since 0.1.0
  7294. * @category Array
  7295. * @param {Array} array The sorted array to inspect.
  7296. * @param {*} value The value to evaluate.
  7297. * @returns {number} Returns the index at which `value` should be inserted
  7298. * into `array`.
  7299. * @example
  7300. *
  7301. * _.sortedIndex([30, 50], 40);
  7302. * // => 1
  7303. */
  7304. function sortedIndex(array, value) {
  7305. return baseSortedIndex(array, value);
  7306. }
  7307. /**
  7308. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  7309. * which is invoked for `value` and each element of `array` to compute their
  7310. * sort ranking. The iteratee is invoked with one argument: (value).
  7311. *
  7312. * @static
  7313. * @memberOf _
  7314. * @since 4.0.0
  7315. * @category Array
  7316. * @param {Array} array The sorted array to inspect.
  7317. * @param {*} value The value to evaluate.
  7318. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7319. * @returns {number} Returns the index at which `value` should be inserted
  7320. * into `array`.
  7321. * @example
  7322. *
  7323. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7324. *
  7325. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7326. * // => 0
  7327. *
  7328. * // The `_.property` iteratee shorthand.
  7329. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  7330. * // => 0
  7331. */
  7332. function sortedIndexBy(array, value, iteratee) {
  7333. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  7334. }
  7335. /**
  7336. * This method is like `_.indexOf` except that it performs a binary
  7337. * search on a sorted `array`.
  7338. *
  7339. * @static
  7340. * @memberOf _
  7341. * @since 4.0.0
  7342. * @category Array
  7343. * @param {Array} array The array to inspect.
  7344. * @param {*} value The value to search for.
  7345. * @returns {number} Returns the index of the matched value, else `-1`.
  7346. * @example
  7347. *
  7348. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  7349. * // => 1
  7350. */
  7351. function sortedIndexOf(array, value) {
  7352. var length = array == null ? 0 : array.length;
  7353. if (length) {
  7354. var index = baseSortedIndex(array, value);
  7355. if (index < length && eq(array[index], value)) {
  7356. return index;
  7357. }
  7358. }
  7359. return -1;
  7360. }
  7361. /**
  7362. * This method is like `_.sortedIndex` except that it returns the highest
  7363. * index at which `value` should be inserted into `array` in order to
  7364. * maintain its sort order.
  7365. *
  7366. * @static
  7367. * @memberOf _
  7368. * @since 3.0.0
  7369. * @category Array
  7370. * @param {Array} array The sorted array to inspect.
  7371. * @param {*} value The value to evaluate.
  7372. * @returns {number} Returns the index at which `value` should be inserted
  7373. * into `array`.
  7374. * @example
  7375. *
  7376. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  7377. * // => 4
  7378. */
  7379. function sortedLastIndex(array, value) {
  7380. return baseSortedIndex(array, value, true);
  7381. }
  7382. /**
  7383. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  7384. * which is invoked for `value` and each element of `array` to compute their
  7385. * sort ranking. The iteratee is invoked with one argument: (value).
  7386. *
  7387. * @static
  7388. * @memberOf _
  7389. * @since 4.0.0
  7390. * @category Array
  7391. * @param {Array} array The sorted array to inspect.
  7392. * @param {*} value The value to evaluate.
  7393. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7394. * @returns {number} Returns the index at which `value` should be inserted
  7395. * into `array`.
  7396. * @example
  7397. *
  7398. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7399. *
  7400. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7401. * // => 1
  7402. *
  7403. * // The `_.property` iteratee shorthand.
  7404. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  7405. * // => 1
  7406. */
  7407. function sortedLastIndexBy(array, value, iteratee) {
  7408. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  7409. }
  7410. /**
  7411. * This method is like `_.lastIndexOf` except that it performs a binary
  7412. * search on a sorted `array`.
  7413. *
  7414. * @static
  7415. * @memberOf _
  7416. * @since 4.0.0
  7417. * @category Array
  7418. * @param {Array} array The array to inspect.
  7419. * @param {*} value The value to search for.
  7420. * @returns {number} Returns the index of the matched value, else `-1`.
  7421. * @example
  7422. *
  7423. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  7424. * // => 3
  7425. */
  7426. function sortedLastIndexOf(array, value) {
  7427. var length = array == null ? 0 : array.length;
  7428. if (length) {
  7429. var index = baseSortedIndex(array, value, true) - 1;
  7430. if (eq(array[index], value)) {
  7431. return index;
  7432. }
  7433. }
  7434. return -1;
  7435. }
  7436. /**
  7437. * This method is like `_.uniq` except that it's designed and optimized
  7438. * for sorted arrays.
  7439. *
  7440. * @static
  7441. * @memberOf _
  7442. * @since 4.0.0
  7443. * @category Array
  7444. * @param {Array} array The array to inspect.
  7445. * @returns {Array} Returns the new duplicate free array.
  7446. * @example
  7447. *
  7448. * _.sortedUniq([1, 1, 2]);
  7449. * // => [1, 2]
  7450. */
  7451. function sortedUniq(array) {
  7452. return (array && array.length)
  7453. ? baseSortedUniq(array)
  7454. : [];
  7455. }
  7456. /**
  7457. * This method is like `_.uniqBy` except that it's designed and optimized
  7458. * for sorted arrays.
  7459. *
  7460. * @static
  7461. * @memberOf _
  7462. * @since 4.0.0
  7463. * @category Array
  7464. * @param {Array} array The array to inspect.
  7465. * @param {Function} [iteratee] The iteratee invoked per element.
  7466. * @returns {Array} Returns the new duplicate free array.
  7467. * @example
  7468. *
  7469. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  7470. * // => [1.1, 2.3]
  7471. */
  7472. function sortedUniqBy(array, iteratee) {
  7473. return (array && array.length)
  7474. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  7475. : [];
  7476. }
  7477. /**
  7478. * Gets all but the first element of `array`.
  7479. *
  7480. * @static
  7481. * @memberOf _
  7482. * @since 4.0.0
  7483. * @category Array
  7484. * @param {Array} array The array to query.
  7485. * @returns {Array} Returns the slice of `array`.
  7486. * @example
  7487. *
  7488. * _.tail([1, 2, 3]);
  7489. * // => [2, 3]
  7490. */
  7491. function tail(array) {
  7492. var length = array == null ? 0 : array.length;
  7493. return length ? baseSlice(array, 1, length) : [];
  7494. }
  7495. /**
  7496. * Creates a slice of `array` with `n` elements taken from the beginning.
  7497. *
  7498. * @static
  7499. * @memberOf _
  7500. * @since 0.1.0
  7501. * @category Array
  7502. * @param {Array} array The array to query.
  7503. * @param {number} [n=1] The number of elements to take.
  7504. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7505. * @returns {Array} Returns the slice of `array`.
  7506. * @example
  7507. *
  7508. * _.take([1, 2, 3]);
  7509. * // => [1]
  7510. *
  7511. * _.take([1, 2, 3], 2);
  7512. * // => [1, 2]
  7513. *
  7514. * _.take([1, 2, 3], 5);
  7515. * // => [1, 2, 3]
  7516. *
  7517. * _.take([1, 2, 3], 0);
  7518. * // => []
  7519. */
  7520. function take(array, n, guard) {
  7521. if (!(array && array.length)) {
  7522. return [];
  7523. }
  7524. n = (guard || n === undefined) ? 1 : toInteger(n);
  7525. return baseSlice(array, 0, n < 0 ? 0 : n);
  7526. }
  7527. /**
  7528. * Creates a slice of `array` with `n` elements taken from the end.
  7529. *
  7530. * @static
  7531. * @memberOf _
  7532. * @since 3.0.0
  7533. * @category Array
  7534. * @param {Array} array The array to query.
  7535. * @param {number} [n=1] The number of elements to take.
  7536. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7537. * @returns {Array} Returns the slice of `array`.
  7538. * @example
  7539. *
  7540. * _.takeRight([1, 2, 3]);
  7541. * // => [3]
  7542. *
  7543. * _.takeRight([1, 2, 3], 2);
  7544. * // => [2, 3]
  7545. *
  7546. * _.takeRight([1, 2, 3], 5);
  7547. * // => [1, 2, 3]
  7548. *
  7549. * _.takeRight([1, 2, 3], 0);
  7550. * // => []
  7551. */
  7552. function takeRight(array, n, guard) {
  7553. var length = array == null ? 0 : array.length;
  7554. if (!length) {
  7555. return [];
  7556. }
  7557. n = (guard || n === undefined) ? 1 : toInteger(n);
  7558. n = length - n;
  7559. return baseSlice(array, n < 0 ? 0 : n, length);
  7560. }
  7561. /**
  7562. * Creates a slice of `array` with elements taken from the end. Elements are
  7563. * taken until `predicate` returns falsey. The predicate is invoked with
  7564. * three arguments: (value, index, array).
  7565. *
  7566. * @static
  7567. * @memberOf _
  7568. * @since 3.0.0
  7569. * @category Array
  7570. * @param {Array} array The array to query.
  7571. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7572. * @returns {Array} Returns the slice of `array`.
  7573. * @example
  7574. *
  7575. * var users = [
  7576. * { 'user': 'barney', 'active': true },
  7577. * { 'user': 'fred', 'active': false },
  7578. * { 'user': 'pebbles', 'active': false }
  7579. * ];
  7580. *
  7581. * _.takeRightWhile(users, function(o) { return !o.active; });
  7582. * // => objects for ['fred', 'pebbles']
  7583. *
  7584. * // The `_.matches` iteratee shorthand.
  7585. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  7586. * // => objects for ['pebbles']
  7587. *
  7588. * // The `_.matchesProperty` iteratee shorthand.
  7589. * _.takeRightWhile(users, ['active', false]);
  7590. * // => objects for ['fred', 'pebbles']
  7591. *
  7592. * // The `_.property` iteratee shorthand.
  7593. * _.takeRightWhile(users, 'active');
  7594. * // => []
  7595. */
  7596. function takeRightWhile(array, predicate) {
  7597. return (array && array.length)
  7598. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  7599. : [];
  7600. }
  7601. /**
  7602. * Creates a slice of `array` with elements taken from the beginning. Elements
  7603. * are taken until `predicate` returns falsey. The predicate is invoked with
  7604. * three arguments: (value, index, array).
  7605. *
  7606. * @static
  7607. * @memberOf _
  7608. * @since 3.0.0
  7609. * @category Array
  7610. * @param {Array} array The array to query.
  7611. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7612. * @returns {Array} Returns the slice of `array`.
  7613. * @example
  7614. *
  7615. * var users = [
  7616. * { 'user': 'barney', 'active': false },
  7617. * { 'user': 'fred', 'active': false },
  7618. * { 'user': 'pebbles', 'active': true }
  7619. * ];
  7620. *
  7621. * _.takeWhile(users, function(o) { return !o.active; });
  7622. * // => objects for ['barney', 'fred']
  7623. *
  7624. * // The `_.matches` iteratee shorthand.
  7625. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  7626. * // => objects for ['barney']
  7627. *
  7628. * // The `_.matchesProperty` iteratee shorthand.
  7629. * _.takeWhile(users, ['active', false]);
  7630. * // => objects for ['barney', 'fred']
  7631. *
  7632. * // The `_.property` iteratee shorthand.
  7633. * _.takeWhile(users, 'active');
  7634. * // => []
  7635. */
  7636. function takeWhile(array, predicate) {
  7637. return (array && array.length)
  7638. ? baseWhile(array, getIteratee(predicate, 3))
  7639. : [];
  7640. }
  7641. /**
  7642. * Creates an array of unique values, in order, from all given arrays using
  7643. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7644. * for equality comparisons.
  7645. *
  7646. * @static
  7647. * @memberOf _
  7648. * @since 0.1.0
  7649. * @category Array
  7650. * @param {...Array} [arrays] The arrays to inspect.
  7651. * @returns {Array} Returns the new array of combined values.
  7652. * @example
  7653. *
  7654. * _.union([2], [1, 2]);
  7655. * // => [2, 1]
  7656. */
  7657. var union = baseRest(function(arrays) {
  7658. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  7659. });
  7660. /**
  7661. * This method is like `_.union` except that it accepts `iteratee` which is
  7662. * invoked for each element of each `arrays` to generate the criterion by
  7663. * which uniqueness is computed. Result values are chosen from the first
  7664. * array in which the value occurs. The iteratee is invoked with one argument:
  7665. * (value).
  7666. *
  7667. * @static
  7668. * @memberOf _
  7669. * @since 4.0.0
  7670. * @category Array
  7671. * @param {...Array} [arrays] The arrays to inspect.
  7672. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7673. * @returns {Array} Returns the new array of combined values.
  7674. * @example
  7675. *
  7676. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  7677. * // => [2.1, 1.2]
  7678. *
  7679. * // The `_.property` iteratee shorthand.
  7680. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7681. * // => [{ 'x': 1 }, { 'x': 2 }]
  7682. */
  7683. var unionBy = baseRest(function(arrays) {
  7684. var iteratee = last(arrays);
  7685. if (isArrayLikeObject(iteratee)) {
  7686. iteratee = undefined;
  7687. }
  7688. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  7689. });
  7690. /**
  7691. * This method is like `_.union` except that it accepts `comparator` which
  7692. * is invoked to compare elements of `arrays`. Result values are chosen from
  7693. * the first array in which the value occurs. The comparator is invoked
  7694. * with two arguments: (arrVal, othVal).
  7695. *
  7696. * @static
  7697. * @memberOf _
  7698. * @since 4.0.0
  7699. * @category Array
  7700. * @param {...Array} [arrays] The arrays to inspect.
  7701. * @param {Function} [comparator] The comparator invoked per element.
  7702. * @returns {Array} Returns the new array of combined values.
  7703. * @example
  7704. *
  7705. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7706. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7707. *
  7708. * _.unionWith(objects, others, _.isEqual);
  7709. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7710. */
  7711. var unionWith = baseRest(function(arrays) {
  7712. var comparator = last(arrays);
  7713. comparator = typeof comparator == 'function' ? comparator : undefined;
  7714. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  7715. });
  7716. /**
  7717. * Creates a duplicate-free version of an array, using
  7718. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7719. * for equality comparisons, in which only the first occurrence of each element
  7720. * is kept. The order of result values is determined by the order they occur
  7721. * in the array.
  7722. *
  7723. * @static
  7724. * @memberOf _
  7725. * @since 0.1.0
  7726. * @category Array
  7727. * @param {Array} array The array to inspect.
  7728. * @returns {Array} Returns the new duplicate free array.
  7729. * @example
  7730. *
  7731. * _.uniq([2, 1, 2]);
  7732. * // => [2, 1]
  7733. */
  7734. function uniq(array) {
  7735. return (array && array.length) ? baseUniq(array) : [];
  7736. }
  7737. /**
  7738. * This method is like `_.uniq` except that it accepts `iteratee` which is
  7739. * invoked for each element in `array` to generate the criterion by which
  7740. * uniqueness is computed. The order of result values is determined by the
  7741. * order they occur in the array. The iteratee is invoked with one argument:
  7742. * (value).
  7743. *
  7744. * @static
  7745. * @memberOf _
  7746. * @since 4.0.0
  7747. * @category Array
  7748. * @param {Array} array The array to inspect.
  7749. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7750. * @returns {Array} Returns the new duplicate free array.
  7751. * @example
  7752. *
  7753. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  7754. * // => [2.1, 1.2]
  7755. *
  7756. * // The `_.property` iteratee shorthand.
  7757. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7758. * // => [{ 'x': 1 }, { 'x': 2 }]
  7759. */
  7760. function uniqBy(array, iteratee) {
  7761. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  7762. }
  7763. /**
  7764. * This method is like `_.uniq` except that it accepts `comparator` which
  7765. * is invoked to compare elements of `array`. The order of result values is
  7766. * determined by the order they occur in the array.The comparator is invoked
  7767. * with two arguments: (arrVal, othVal).
  7768. *
  7769. * @static
  7770. * @memberOf _
  7771. * @since 4.0.0
  7772. * @category Array
  7773. * @param {Array} array The array to inspect.
  7774. * @param {Function} [comparator] The comparator invoked per element.
  7775. * @returns {Array} Returns the new duplicate free array.
  7776. * @example
  7777. *
  7778. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7779. *
  7780. * _.uniqWith(objects, _.isEqual);
  7781. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  7782. */
  7783. function uniqWith(array, comparator) {
  7784. comparator = typeof comparator == 'function' ? comparator : undefined;
  7785. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  7786. }
  7787. /**
  7788. * This method is like `_.zip` except that it accepts an array of grouped
  7789. * elements and creates an array regrouping the elements to their pre-zip
  7790. * configuration.
  7791. *
  7792. * @static
  7793. * @memberOf _
  7794. * @since 1.2.0
  7795. * @category Array
  7796. * @param {Array} array The array of grouped elements to process.
  7797. * @returns {Array} Returns the new array of regrouped elements.
  7798. * @example
  7799. *
  7800. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  7801. * // => [['a', 1, true], ['b', 2, false]]
  7802. *
  7803. * _.unzip(zipped);
  7804. * // => [['a', 'b'], [1, 2], [true, false]]
  7805. */
  7806. function unzip(array) {
  7807. if (!(array && array.length)) {
  7808. return [];
  7809. }
  7810. var length = 0;
  7811. array = arrayFilter(array, function(group) {
  7812. if (isArrayLikeObject(group)) {
  7813. length = nativeMax(group.length, length);
  7814. return true;
  7815. }
  7816. });
  7817. return baseTimes(length, function(index) {
  7818. return arrayMap(array, baseProperty(index));
  7819. });
  7820. }
  7821. /**
  7822. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  7823. * how regrouped values should be combined. The iteratee is invoked with the
  7824. * elements of each group: (...group).
  7825. *
  7826. * @static
  7827. * @memberOf _
  7828. * @since 3.8.0
  7829. * @category Array
  7830. * @param {Array} array The array of grouped elements to process.
  7831. * @param {Function} [iteratee=_.identity] The function to combine
  7832. * regrouped values.
  7833. * @returns {Array} Returns the new array of regrouped elements.
  7834. * @example
  7835. *
  7836. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7837. * // => [[1, 10, 100], [2, 20, 200]]
  7838. *
  7839. * _.unzipWith(zipped, _.add);
  7840. * // => [3, 30, 300]
  7841. */
  7842. function unzipWith(array, iteratee) {
  7843. if (!(array && array.length)) {
  7844. return [];
  7845. }
  7846. var result = unzip(array);
  7847. if (iteratee == null) {
  7848. return result;
  7849. }
  7850. return arrayMap(result, function(group) {
  7851. return apply(iteratee, undefined, group);
  7852. });
  7853. }
  7854. /**
  7855. * Creates an array excluding all given values using
  7856. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7857. * for equality comparisons.
  7858. *
  7859. * **Note:** Unlike `_.pull`, this method returns a new array.
  7860. *
  7861. * @static
  7862. * @memberOf _
  7863. * @since 0.1.0
  7864. * @category Array
  7865. * @param {Array} array The array to inspect.
  7866. * @param {...*} [values] The values to exclude.
  7867. * @returns {Array} Returns the new array of filtered values.
  7868. * @see _.difference, _.xor
  7869. * @example
  7870. *
  7871. * _.without([2, 1, 2, 3], 1, 2);
  7872. * // => [3]
  7873. */
  7874. var without = baseRest(function(array, values) {
  7875. return isArrayLikeObject(array)
  7876. ? baseDifference(array, values)
  7877. : [];
  7878. });
  7879. /**
  7880. * Creates an array of unique values that is the
  7881. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7882. * of the given arrays. The order of result values is determined by the order
  7883. * they occur in the arrays.
  7884. *
  7885. * @static
  7886. * @memberOf _
  7887. * @since 2.4.0
  7888. * @category Array
  7889. * @param {...Array} [arrays] The arrays to inspect.
  7890. * @returns {Array} Returns the new array of filtered values.
  7891. * @see _.difference, _.without
  7892. * @example
  7893. *
  7894. * _.xor([2, 1], [2, 3]);
  7895. * // => [1, 3]
  7896. */
  7897. var xor = baseRest(function(arrays) {
  7898. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  7899. });
  7900. /**
  7901. * This method is like `_.xor` except that it accepts `iteratee` which is
  7902. * invoked for each element of each `arrays` to generate the criterion by
  7903. * which by which they're compared. The order of result values is determined
  7904. * by the order they occur in the arrays. The iteratee is invoked with one
  7905. * argument: (value).
  7906. *
  7907. * @static
  7908. * @memberOf _
  7909. * @since 4.0.0
  7910. * @category Array
  7911. * @param {...Array} [arrays] The arrays to inspect.
  7912. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7913. * @returns {Array} Returns the new array of filtered values.
  7914. * @example
  7915. *
  7916. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7917. * // => [1.2, 3.4]
  7918. *
  7919. * // The `_.property` iteratee shorthand.
  7920. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7921. * // => [{ 'x': 2 }]
  7922. */
  7923. var xorBy = baseRest(function(arrays) {
  7924. var iteratee = last(arrays);
  7925. if (isArrayLikeObject(iteratee)) {
  7926. iteratee = undefined;
  7927. }
  7928. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  7929. });
  7930. /**
  7931. * This method is like `_.xor` except that it accepts `comparator` which is
  7932. * invoked to compare elements of `arrays`. The order of result values is
  7933. * determined by the order they occur in the arrays. The comparator is invoked
  7934. * with two arguments: (arrVal, othVal).
  7935. *
  7936. * @static
  7937. * @memberOf _
  7938. * @since 4.0.0
  7939. * @category Array
  7940. * @param {...Array} [arrays] The arrays to inspect.
  7941. * @param {Function} [comparator] The comparator invoked per element.
  7942. * @returns {Array} Returns the new array of filtered values.
  7943. * @example
  7944. *
  7945. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7946. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7947. *
  7948. * _.xorWith(objects, others, _.isEqual);
  7949. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7950. */
  7951. var xorWith = baseRest(function(arrays) {
  7952. var comparator = last(arrays);
  7953. comparator = typeof comparator == 'function' ? comparator : undefined;
  7954. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  7955. });
  7956. /**
  7957. * Creates an array of grouped elements, the first of which contains the
  7958. * first elements of the given arrays, the second of which contains the
  7959. * second elements of the given arrays, and so on.
  7960. *
  7961. * @static
  7962. * @memberOf _
  7963. * @since 0.1.0
  7964. * @category Array
  7965. * @param {...Array} [arrays] The arrays to process.
  7966. * @returns {Array} Returns the new array of grouped elements.
  7967. * @example
  7968. *
  7969. * _.zip(['a', 'b'], [1, 2], [true, false]);
  7970. * // => [['a', 1, true], ['b', 2, false]]
  7971. */
  7972. var zip = baseRest(unzip);
  7973. /**
  7974. * This method is like `_.fromPairs` except that it accepts two arrays,
  7975. * one of property identifiers and one of corresponding values.
  7976. *
  7977. * @static
  7978. * @memberOf _
  7979. * @since 0.4.0
  7980. * @category Array
  7981. * @param {Array} [props=[]] The property identifiers.
  7982. * @param {Array} [values=[]] The property values.
  7983. * @returns {Object} Returns the new object.
  7984. * @example
  7985. *
  7986. * _.zipObject(['a', 'b'], [1, 2]);
  7987. * // => { 'a': 1, 'b': 2 }
  7988. */
  7989. function zipObject(props, values) {
  7990. return baseZipObject(props || [], values || [], assignValue);
  7991. }
  7992. /**
  7993. * This method is like `_.zipObject` except that it supports property paths.
  7994. *
  7995. * @static
  7996. * @memberOf _
  7997. * @since 4.1.0
  7998. * @category Array
  7999. * @param {Array} [props=[]] The property identifiers.
  8000. * @param {Array} [values=[]] The property values.
  8001. * @returns {Object} Returns the new object.
  8002. * @example
  8003. *
  8004. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  8005. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  8006. */
  8007. function zipObjectDeep(props, values) {
  8008. return baseZipObject(props || [], values || [], baseSet);
  8009. }
  8010. /**
  8011. * This method is like `_.zip` except that it accepts `iteratee` to specify
  8012. * how grouped values should be combined. The iteratee is invoked with the
  8013. * elements of each group: (...group).
  8014. *
  8015. * @static
  8016. * @memberOf _
  8017. * @since 3.8.0
  8018. * @category Array
  8019. * @param {...Array} [arrays] The arrays to process.
  8020. * @param {Function} [iteratee=_.identity] The function to combine
  8021. * grouped values.
  8022. * @returns {Array} Returns the new array of grouped elements.
  8023. * @example
  8024. *
  8025. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  8026. * return a + b + c;
  8027. * });
  8028. * // => [111, 222]
  8029. */
  8030. var zipWith = baseRest(function(arrays) {
  8031. var length = arrays.length,
  8032. iteratee = length > 1 ? arrays[length - 1] : undefined;
  8033. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  8034. return unzipWith(arrays, iteratee);
  8035. });
  8036. /*------------------------------------------------------------------------*/
  8037. /**
  8038. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  8039. * chain sequences enabled. The result of such sequences must be unwrapped
  8040. * with `_#value`.
  8041. *
  8042. * @static
  8043. * @memberOf _
  8044. * @since 1.3.0
  8045. * @category Seq
  8046. * @param {*} value The value to wrap.
  8047. * @returns {Object} Returns the new `lodash` wrapper instance.
  8048. * @example
  8049. *
  8050. * var users = [
  8051. * { 'user': 'barney', 'age': 36 },
  8052. * { 'user': 'fred', 'age': 40 },
  8053. * { 'user': 'pebbles', 'age': 1 }
  8054. * ];
  8055. *
  8056. * var youngest = _
  8057. * .chain(users)
  8058. * .sortBy('age')
  8059. * .map(function(o) {
  8060. * return o.user + ' is ' + o.age;
  8061. * })
  8062. * .head()
  8063. * .value();
  8064. * // => 'pebbles is 1'
  8065. */
  8066. function chain(value) {
  8067. var result = lodash(value);
  8068. result.__chain__ = true;
  8069. return result;
  8070. }
  8071. /**
  8072. * This method invokes `interceptor` and returns `value`. The interceptor
  8073. * is invoked with one argument; (value). The purpose of this method is to
  8074. * "tap into" a method chain sequence in order to modify intermediate results.
  8075. *
  8076. * @static
  8077. * @memberOf _
  8078. * @since 0.1.0
  8079. * @category Seq
  8080. * @param {*} value The value to provide to `interceptor`.
  8081. * @param {Function} interceptor The function to invoke.
  8082. * @returns {*} Returns `value`.
  8083. * @example
  8084. *
  8085. * _([1, 2, 3])
  8086. * .tap(function(array) {
  8087. * // Mutate input array.
  8088. * array.pop();
  8089. * })
  8090. * .reverse()
  8091. * .value();
  8092. * // => [2, 1]
  8093. */
  8094. function tap(value, interceptor) {
  8095. interceptor(value);
  8096. return value;
  8097. }
  8098. /**
  8099. * This method is like `_.tap` except that it returns the result of `interceptor`.
  8100. * The purpose of this method is to "pass thru" values replacing intermediate
  8101. * results in a method chain sequence.
  8102. *
  8103. * @static
  8104. * @memberOf _
  8105. * @since 3.0.0
  8106. * @category Seq
  8107. * @param {*} value The value to provide to `interceptor`.
  8108. * @param {Function} interceptor The function to invoke.
  8109. * @returns {*} Returns the result of `interceptor`.
  8110. * @example
  8111. *
  8112. * _(' abc ')
  8113. * .chain()
  8114. * .trim()
  8115. * .thru(function(value) {
  8116. * return [value];
  8117. * })
  8118. * .value();
  8119. * // => ['abc']
  8120. */
  8121. function thru(value, interceptor) {
  8122. return interceptor(value);
  8123. }
  8124. /**
  8125. * This method is the wrapper version of `_.at`.
  8126. *
  8127. * @name at
  8128. * @memberOf _
  8129. * @since 1.0.0
  8130. * @category Seq
  8131. * @param {...(string|string[])} [paths] The property paths to pick.
  8132. * @returns {Object} Returns the new `lodash` wrapper instance.
  8133. * @example
  8134. *
  8135. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  8136. *
  8137. * _(object).at(['a[0].b.c', 'a[1]']).value();
  8138. * // => [3, 4]
  8139. */
  8140. var wrapperAt = flatRest(function(paths) {
  8141. var length = paths.length,
  8142. start = length ? paths[0] : 0,
  8143. value = this.__wrapped__,
  8144. interceptor = function(object) { return baseAt(object, paths); };
  8145. if (length > 1 || this.__actions__.length ||
  8146. !(value instanceof LazyWrapper) || !isIndex(start)) {
  8147. return this.thru(interceptor);
  8148. }
  8149. value = value.slice(start, +start + (length ? 1 : 0));
  8150. value.__actions__.push({
  8151. 'func': thru,
  8152. 'args': [interceptor],
  8153. 'thisArg': undefined
  8154. });
  8155. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  8156. if (length && !array.length) {
  8157. array.push(undefined);
  8158. }
  8159. return array;
  8160. });
  8161. });
  8162. /**
  8163. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  8164. *
  8165. * @name chain
  8166. * @memberOf _
  8167. * @since 0.1.0
  8168. * @category Seq
  8169. * @returns {Object} Returns the new `lodash` wrapper instance.
  8170. * @example
  8171. *
  8172. * var users = [
  8173. * { 'user': 'barney', 'age': 36 },
  8174. * { 'user': 'fred', 'age': 40 }
  8175. * ];
  8176. *
  8177. * // A sequence without explicit chaining.
  8178. * _(users).head();
  8179. * // => { 'user': 'barney', 'age': 36 }
  8180. *
  8181. * // A sequence with explicit chaining.
  8182. * _(users)
  8183. * .chain()
  8184. * .head()
  8185. * .pick('user')
  8186. * .value();
  8187. * // => { 'user': 'barney' }
  8188. */
  8189. function wrapperChain() {
  8190. return chain(this);
  8191. }
  8192. /**
  8193. * Executes the chain sequence and returns the wrapped result.
  8194. *
  8195. * @name commit
  8196. * @memberOf _
  8197. * @since 3.2.0
  8198. * @category Seq
  8199. * @returns {Object} Returns the new `lodash` wrapper instance.
  8200. * @example
  8201. *
  8202. * var array = [1, 2];
  8203. * var wrapped = _(array).push(3);
  8204. *
  8205. * console.log(array);
  8206. * // => [1, 2]
  8207. *
  8208. * wrapped = wrapped.commit();
  8209. * console.log(array);
  8210. * // => [1, 2, 3]
  8211. *
  8212. * wrapped.last();
  8213. * // => 3
  8214. *
  8215. * console.log(array);
  8216. * // => [1, 2, 3]
  8217. */
  8218. function wrapperCommit() {
  8219. return new LodashWrapper(this.value(), this.__chain__);
  8220. }
  8221. /**
  8222. * Gets the next value on a wrapped object following the
  8223. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  8224. *
  8225. * @name next
  8226. * @memberOf _
  8227. * @since 4.0.0
  8228. * @category Seq
  8229. * @returns {Object} Returns the next iterator value.
  8230. * @example
  8231. *
  8232. * var wrapped = _([1, 2]);
  8233. *
  8234. * wrapped.next();
  8235. * // => { 'done': false, 'value': 1 }
  8236. *
  8237. * wrapped.next();
  8238. * // => { 'done': false, 'value': 2 }
  8239. *
  8240. * wrapped.next();
  8241. * // => { 'done': true, 'value': undefined }
  8242. */
  8243. function wrapperNext() {
  8244. if (this.__values__ === undefined) {
  8245. this.__values__ = toArray(this.value());
  8246. }
  8247. var done = this.__index__ >= this.__values__.length,
  8248. value = done ? undefined : this.__values__[this.__index__++];
  8249. return { 'done': done, 'value': value };
  8250. }
  8251. /**
  8252. * Enables the wrapper to be iterable.
  8253. *
  8254. * @name Symbol.iterator
  8255. * @memberOf _
  8256. * @since 4.0.0
  8257. * @category Seq
  8258. * @returns {Object} Returns the wrapper object.
  8259. * @example
  8260. *
  8261. * var wrapped = _([1, 2]);
  8262. *
  8263. * wrapped[Symbol.iterator]() === wrapped;
  8264. * // => true
  8265. *
  8266. * Array.from(wrapped);
  8267. * // => [1, 2]
  8268. */
  8269. function wrapperToIterator() {
  8270. return this;
  8271. }
  8272. /**
  8273. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  8274. *
  8275. * @name plant
  8276. * @memberOf _
  8277. * @since 3.2.0
  8278. * @category Seq
  8279. * @param {*} value The value to plant.
  8280. * @returns {Object} Returns the new `lodash` wrapper instance.
  8281. * @example
  8282. *
  8283. * function square(n) {
  8284. * return n * n;
  8285. * }
  8286. *
  8287. * var wrapped = _([1, 2]).map(square);
  8288. * var other = wrapped.plant([3, 4]);
  8289. *
  8290. * other.value();
  8291. * // => [9, 16]
  8292. *
  8293. * wrapped.value();
  8294. * // => [1, 4]
  8295. */
  8296. function wrapperPlant(value) {
  8297. var result,
  8298. parent = this;
  8299. while (parent instanceof baseLodash) {
  8300. var clone = wrapperClone(parent);
  8301. clone.__index__ = 0;
  8302. clone.__values__ = undefined;
  8303. if (result) {
  8304. previous.__wrapped__ = clone;
  8305. } else {
  8306. result = clone;
  8307. }
  8308. var previous = clone;
  8309. parent = parent.__wrapped__;
  8310. }
  8311. previous.__wrapped__ = value;
  8312. return result;
  8313. }
  8314. /**
  8315. * This method is the wrapper version of `_.reverse`.
  8316. *
  8317. * **Note:** This method mutates the wrapped array.
  8318. *
  8319. * @name reverse
  8320. * @memberOf _
  8321. * @since 0.1.0
  8322. * @category Seq
  8323. * @returns {Object} Returns the new `lodash` wrapper instance.
  8324. * @example
  8325. *
  8326. * var array = [1, 2, 3];
  8327. *
  8328. * _(array).reverse().value()
  8329. * // => [3, 2, 1]
  8330. *
  8331. * console.log(array);
  8332. * // => [3, 2, 1]
  8333. */
  8334. function wrapperReverse() {
  8335. var value = this.__wrapped__;
  8336. if (value instanceof LazyWrapper) {
  8337. var wrapped = value;
  8338. if (this.__actions__.length) {
  8339. wrapped = new LazyWrapper(this);
  8340. }
  8341. wrapped = wrapped.reverse();
  8342. wrapped.__actions__.push({
  8343. 'func': thru,
  8344. 'args': [reverse],
  8345. 'thisArg': undefined
  8346. });
  8347. return new LodashWrapper(wrapped, this.__chain__);
  8348. }
  8349. return this.thru(reverse);
  8350. }
  8351. /**
  8352. * Executes the chain sequence to resolve the unwrapped value.
  8353. *
  8354. * @name value
  8355. * @memberOf _
  8356. * @since 0.1.0
  8357. * @alias toJSON, valueOf
  8358. * @category Seq
  8359. * @returns {*} Returns the resolved unwrapped value.
  8360. * @example
  8361. *
  8362. * _([1, 2, 3]).value();
  8363. * // => [1, 2, 3]
  8364. */
  8365. function wrapperValue() {
  8366. return baseWrapperValue(this.__wrapped__, this.__actions__);
  8367. }
  8368. /*------------------------------------------------------------------------*/
  8369. /**
  8370. * Creates an object composed of keys generated from the results of running
  8371. * each element of `collection` thru `iteratee`. The corresponding value of
  8372. * each key is the number of times the key was returned by `iteratee`. The
  8373. * iteratee is invoked with one argument: (value).
  8374. *
  8375. * @static
  8376. * @memberOf _
  8377. * @since 0.5.0
  8378. * @category Collection
  8379. * @param {Array|Object} collection The collection to iterate over.
  8380. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8381. * @returns {Object} Returns the composed aggregate object.
  8382. * @example
  8383. *
  8384. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  8385. * // => { '4': 1, '6': 2 }
  8386. *
  8387. * // The `_.property` iteratee shorthand.
  8388. * _.countBy(['one', 'two', 'three'], 'length');
  8389. * // => { '3': 2, '5': 1 }
  8390. */
  8391. var countBy = createAggregator(function(result, value, key) {
  8392. if (hasOwnProperty.call(result, key)) {
  8393. ++result[key];
  8394. } else {
  8395. baseAssignValue(result, key, 1);
  8396. }
  8397. });
  8398. /**
  8399. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  8400. * Iteration is stopped once `predicate` returns falsey. The predicate is
  8401. * invoked with three arguments: (value, index|key, collection).
  8402. *
  8403. * **Note:** This method returns `true` for
  8404. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  8405. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  8406. * elements of empty collections.
  8407. *
  8408. * @static
  8409. * @memberOf _
  8410. * @since 0.1.0
  8411. * @category Collection
  8412. * @param {Array|Object} collection The collection to iterate over.
  8413. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8414. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8415. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  8416. * else `false`.
  8417. * @example
  8418. *
  8419. * _.every([true, 1, null, 'yes'], Boolean);
  8420. * // => false
  8421. *
  8422. * var users = [
  8423. * { 'user': 'barney', 'age': 36, 'active': false },
  8424. * { 'user': 'fred', 'age': 40, 'active': false }
  8425. * ];
  8426. *
  8427. * // The `_.matches` iteratee shorthand.
  8428. * _.every(users, { 'user': 'barney', 'active': false });
  8429. * // => false
  8430. *
  8431. * // The `_.matchesProperty` iteratee shorthand.
  8432. * _.every(users, ['active', false]);
  8433. * // => true
  8434. *
  8435. * // The `_.property` iteratee shorthand.
  8436. * _.every(users, 'active');
  8437. * // => false
  8438. */
  8439. function every(collection, predicate, guard) {
  8440. var func = isArray(collection) ? arrayEvery : baseEvery;
  8441. if (guard && isIterateeCall(collection, predicate, guard)) {
  8442. predicate = undefined;
  8443. }
  8444. return func(collection, getIteratee(predicate, 3));
  8445. }
  8446. /**
  8447. * Iterates over elements of `collection`, returning an array of all elements
  8448. * `predicate` returns truthy for. The predicate is invoked with three
  8449. * arguments: (value, index|key, collection).
  8450. *
  8451. * **Note:** Unlike `_.remove`, this method returns a new array.
  8452. *
  8453. * @static
  8454. * @memberOf _
  8455. * @since 0.1.0
  8456. * @category Collection
  8457. * @param {Array|Object} collection The collection to iterate over.
  8458. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8459. * @returns {Array} Returns the new filtered array.
  8460. * @see _.reject
  8461. * @example
  8462. *
  8463. * var users = [
  8464. * { 'user': 'barney', 'age': 36, 'active': true },
  8465. * { 'user': 'fred', 'age': 40, 'active': false }
  8466. * ];
  8467. *
  8468. * _.filter(users, function(o) { return !o.active; });
  8469. * // => objects for ['fred']
  8470. *
  8471. * // The `_.matches` iteratee shorthand.
  8472. * _.filter(users, { 'age': 36, 'active': true });
  8473. * // => objects for ['barney']
  8474. *
  8475. * // The `_.matchesProperty` iteratee shorthand.
  8476. * _.filter(users, ['active', false]);
  8477. * // => objects for ['fred']
  8478. *
  8479. * // The `_.property` iteratee shorthand.
  8480. * _.filter(users, 'active');
  8481. * // => objects for ['barney']
  8482. */
  8483. function filter(collection, predicate) {
  8484. var func = isArray(collection) ? arrayFilter : baseFilter;
  8485. return func(collection, getIteratee(predicate, 3));
  8486. }
  8487. /**
  8488. * Iterates over elements of `collection`, returning the first element
  8489. * `predicate` returns truthy for. The predicate is invoked with three
  8490. * arguments: (value, index|key, collection).
  8491. *
  8492. * @static
  8493. * @memberOf _
  8494. * @since 0.1.0
  8495. * @category Collection
  8496. * @param {Array|Object} collection The collection to inspect.
  8497. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8498. * @param {number} [fromIndex=0] The index to search from.
  8499. * @returns {*} Returns the matched element, else `undefined`.
  8500. * @example
  8501. *
  8502. * var users = [
  8503. * { 'user': 'barney', 'age': 36, 'active': true },
  8504. * { 'user': 'fred', 'age': 40, 'active': false },
  8505. * { 'user': 'pebbles', 'age': 1, 'active': true }
  8506. * ];
  8507. *
  8508. * _.find(users, function(o) { return o.age < 40; });
  8509. * // => object for 'barney'
  8510. *
  8511. * // The `_.matches` iteratee shorthand.
  8512. * _.find(users, { 'age': 1, 'active': true });
  8513. * // => object for 'pebbles'
  8514. *
  8515. * // The `_.matchesProperty` iteratee shorthand.
  8516. * _.find(users, ['active', false]);
  8517. * // => object for 'fred'
  8518. *
  8519. * // The `_.property` iteratee shorthand.
  8520. * _.find(users, 'active');
  8521. * // => object for 'barney'
  8522. */
  8523. var find = createFind(findIndex);
  8524. /**
  8525. * This method is like `_.find` except that it iterates over elements of
  8526. * `collection` from right to left.
  8527. *
  8528. * @static
  8529. * @memberOf _
  8530. * @since 2.0.0
  8531. * @category Collection
  8532. * @param {Array|Object} collection The collection to inspect.
  8533. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8534. * @param {number} [fromIndex=collection.length-1] The index to search from.
  8535. * @returns {*} Returns the matched element, else `undefined`.
  8536. * @example
  8537. *
  8538. * _.findLast([1, 2, 3, 4], function(n) {
  8539. * return n % 2 == 1;
  8540. * });
  8541. * // => 3
  8542. */
  8543. var findLast = createFind(findLastIndex);
  8544. /**
  8545. * Creates a flattened array of values by running each element in `collection`
  8546. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  8547. * with three arguments: (value, index|key, collection).
  8548. *
  8549. * @static
  8550. * @memberOf _
  8551. * @since 4.0.0
  8552. * @category Collection
  8553. * @param {Array|Object} collection The collection to iterate over.
  8554. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8555. * @returns {Array} Returns the new flattened array.
  8556. * @example
  8557. *
  8558. * function duplicate(n) {
  8559. * return [n, n];
  8560. * }
  8561. *
  8562. * _.flatMap([1, 2], duplicate);
  8563. * // => [1, 1, 2, 2]
  8564. */
  8565. function flatMap(collection, iteratee) {
  8566. return baseFlatten(map(collection, iteratee), 1);
  8567. }
  8568. /**
  8569. * This method is like `_.flatMap` except that it recursively flattens the
  8570. * mapped results.
  8571. *
  8572. * @static
  8573. * @memberOf _
  8574. * @since 4.7.0
  8575. * @category Collection
  8576. * @param {Array|Object} collection The collection to iterate over.
  8577. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8578. * @returns {Array} Returns the new flattened array.
  8579. * @example
  8580. *
  8581. * function duplicate(n) {
  8582. * return [[[n, n]]];
  8583. * }
  8584. *
  8585. * _.flatMapDeep([1, 2], duplicate);
  8586. * // => [1, 1, 2, 2]
  8587. */
  8588. function flatMapDeep(collection, iteratee) {
  8589. return baseFlatten(map(collection, iteratee), INFINITY);
  8590. }
  8591. /**
  8592. * This method is like `_.flatMap` except that it recursively flattens the
  8593. * mapped results up to `depth` times.
  8594. *
  8595. * @static
  8596. * @memberOf _
  8597. * @since 4.7.0
  8598. * @category Collection
  8599. * @param {Array|Object} collection The collection to iterate over.
  8600. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8601. * @param {number} [depth=1] The maximum recursion depth.
  8602. * @returns {Array} Returns the new flattened array.
  8603. * @example
  8604. *
  8605. * function duplicate(n) {
  8606. * return [[[n, n]]];
  8607. * }
  8608. *
  8609. * _.flatMapDepth([1, 2], duplicate, 2);
  8610. * // => [[1, 1], [2, 2]]
  8611. */
  8612. function flatMapDepth(collection, iteratee, depth) {
  8613. depth = depth === undefined ? 1 : toInteger(depth);
  8614. return baseFlatten(map(collection, iteratee), depth);
  8615. }
  8616. /**
  8617. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  8618. * The iteratee is invoked with three arguments: (value, index|key, collection).
  8619. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8620. *
  8621. * **Note:** As with other "Collections" methods, objects with a "length"
  8622. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  8623. * or `_.forOwn` for object iteration.
  8624. *
  8625. * @static
  8626. * @memberOf _
  8627. * @since 0.1.0
  8628. * @alias each
  8629. * @category Collection
  8630. * @param {Array|Object} collection The collection to iterate over.
  8631. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8632. * @returns {Array|Object} Returns `collection`.
  8633. * @see _.forEachRight
  8634. * @example
  8635. *
  8636. * _.forEach([1, 2], function(value) {
  8637. * console.log(value);
  8638. * });
  8639. * // => Logs `1` then `2`.
  8640. *
  8641. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  8642. * console.log(key);
  8643. * });
  8644. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  8645. */
  8646. function forEach(collection, iteratee) {
  8647. var func = isArray(collection) ? arrayEach : baseEach;
  8648. return func(collection, getIteratee(iteratee, 3));
  8649. }
  8650. /**
  8651. * This method is like `_.forEach` except that it iterates over elements of
  8652. * `collection` from right to left.
  8653. *
  8654. * @static
  8655. * @memberOf _
  8656. * @since 2.0.0
  8657. * @alias eachRight
  8658. * @category Collection
  8659. * @param {Array|Object} collection The collection to iterate over.
  8660. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8661. * @returns {Array|Object} Returns `collection`.
  8662. * @see _.forEach
  8663. * @example
  8664. *
  8665. * _.forEachRight([1, 2], function(value) {
  8666. * console.log(value);
  8667. * });
  8668. * // => Logs `2` then `1`.
  8669. */
  8670. function forEachRight(collection, iteratee) {
  8671. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  8672. return func(collection, getIteratee(iteratee, 3));
  8673. }
  8674. /**
  8675. * Creates an object composed of keys generated from the results of running
  8676. * each element of `collection` thru `iteratee`. The order of grouped values
  8677. * is determined by the order they occur in `collection`. The corresponding
  8678. * value of each key is an array of elements responsible for generating the
  8679. * key. The iteratee is invoked with one argument: (value).
  8680. *
  8681. * @static
  8682. * @memberOf _
  8683. * @since 0.1.0
  8684. * @category Collection
  8685. * @param {Array|Object} collection The collection to iterate over.
  8686. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8687. * @returns {Object} Returns the composed aggregate object.
  8688. * @example
  8689. *
  8690. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  8691. * // => { '4': [4.2], '6': [6.1, 6.3] }
  8692. *
  8693. * // The `_.property` iteratee shorthand.
  8694. * _.groupBy(['one', 'two', 'three'], 'length');
  8695. * // => { '3': ['one', 'two'], '5': ['three'] }
  8696. */
  8697. var groupBy = createAggregator(function(result, value, key) {
  8698. if (hasOwnProperty.call(result, key)) {
  8699. result[key].push(value);
  8700. } else {
  8701. baseAssignValue(result, key, [value]);
  8702. }
  8703. });
  8704. /**
  8705. * Checks if `value` is in `collection`. If `collection` is a string, it's
  8706. * checked for a substring of `value`, otherwise
  8707. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8708. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  8709. * the offset from the end of `collection`.
  8710. *
  8711. * @static
  8712. * @memberOf _
  8713. * @since 0.1.0
  8714. * @category Collection
  8715. * @param {Array|Object|string} collection The collection to inspect.
  8716. * @param {*} value The value to search for.
  8717. * @param {number} [fromIndex=0] The index to search from.
  8718. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8719. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  8720. * @example
  8721. *
  8722. * _.includes([1, 2, 3], 1);
  8723. * // => true
  8724. *
  8725. * _.includes([1, 2, 3], 1, 2);
  8726. * // => false
  8727. *
  8728. * _.includes({ 'a': 1, 'b': 2 }, 1);
  8729. * // => true
  8730. *
  8731. * _.includes('abcd', 'bc');
  8732. * // => true
  8733. */
  8734. function includes(collection, value, fromIndex, guard) {
  8735. collection = isArrayLike(collection) ? collection : values(collection);
  8736. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  8737. var length = collection.length;
  8738. if (fromIndex < 0) {
  8739. fromIndex = nativeMax(length + fromIndex, 0);
  8740. }
  8741. return isString(collection)
  8742. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  8743. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  8744. }
  8745. /**
  8746. * Invokes the method at `path` of each element in `collection`, returning
  8747. * an array of the results of each invoked method. Any additional arguments
  8748. * are provided to each invoked method. If `path` is a function, it's invoked
  8749. * for, and `this` bound to, each element in `collection`.
  8750. *
  8751. * @static
  8752. * @memberOf _
  8753. * @since 4.0.0
  8754. * @category Collection
  8755. * @param {Array|Object} collection The collection to iterate over.
  8756. * @param {Array|Function|string} path The path of the method to invoke or
  8757. * the function invoked per iteration.
  8758. * @param {...*} [args] The arguments to invoke each method with.
  8759. * @returns {Array} Returns the array of results.
  8760. * @example
  8761. *
  8762. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  8763. * // => [[1, 5, 7], [1, 2, 3]]
  8764. *
  8765. * _.invokeMap([123, 456], String.prototype.split, '');
  8766. * // => [['1', '2', '3'], ['4', '5', '6']]
  8767. */
  8768. var invokeMap = baseRest(function(collection, path, args) {
  8769. var index = -1,
  8770. isFunc = typeof path == 'function',
  8771. result = isArrayLike(collection) ? Array(collection.length) : [];
  8772. baseEach(collection, function(value) {
  8773. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  8774. });
  8775. return result;
  8776. });
  8777. /**
  8778. * Creates an object composed of keys generated from the results of running
  8779. * each element of `collection` thru `iteratee`. The corresponding value of
  8780. * each key is the last element responsible for generating the key. The
  8781. * iteratee is invoked with one argument: (value).
  8782. *
  8783. * @static
  8784. * @memberOf _
  8785. * @since 4.0.0
  8786. * @category Collection
  8787. * @param {Array|Object} collection The collection to iterate over.
  8788. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8789. * @returns {Object} Returns the composed aggregate object.
  8790. * @example
  8791. *
  8792. * var array = [
  8793. * { 'dir': 'left', 'code': 97 },
  8794. * { 'dir': 'right', 'code': 100 }
  8795. * ];
  8796. *
  8797. * _.keyBy(array, function(o) {
  8798. * return String.fromCharCode(o.code);
  8799. * });
  8800. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8801. *
  8802. * _.keyBy(array, 'dir');
  8803. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8804. */
  8805. var keyBy = createAggregator(function(result, value, key) {
  8806. baseAssignValue(result, key, value);
  8807. });
  8808. /**
  8809. * Creates an array of values by running each element in `collection` thru
  8810. * `iteratee`. The iteratee is invoked with three arguments:
  8811. * (value, index|key, collection).
  8812. *
  8813. * Many lodash methods are guarded to work as iteratees for methods like
  8814. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8815. *
  8816. * The guarded methods are:
  8817. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  8818. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  8819. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  8820. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  8821. *
  8822. * @static
  8823. * @memberOf _
  8824. * @since 0.1.0
  8825. * @category Collection
  8826. * @param {Array|Object} collection The collection to iterate over.
  8827. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8828. * @returns {Array} Returns the new mapped array.
  8829. * @example
  8830. *
  8831. * function square(n) {
  8832. * return n * n;
  8833. * }
  8834. *
  8835. * _.map([4, 8], square);
  8836. * // => [16, 64]
  8837. *
  8838. * _.map({ 'a': 4, 'b': 8 }, square);
  8839. * // => [16, 64] (iteration order is not guaranteed)
  8840. *
  8841. * var users = [
  8842. * { 'user': 'barney' },
  8843. * { 'user': 'fred' }
  8844. * ];
  8845. *
  8846. * // The `_.property` iteratee shorthand.
  8847. * _.map(users, 'user');
  8848. * // => ['barney', 'fred']
  8849. */
  8850. function map(collection, iteratee) {
  8851. var func = isArray(collection) ? arrayMap : baseMap;
  8852. return func(collection, getIteratee(iteratee, 3));
  8853. }
  8854. /**
  8855. * This method is like `_.sortBy` except that it allows specifying the sort
  8856. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  8857. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  8858. * descending or "asc" for ascending sort order of corresponding values.
  8859. *
  8860. * @static
  8861. * @memberOf _
  8862. * @since 4.0.0
  8863. * @category Collection
  8864. * @param {Array|Object} collection The collection to iterate over.
  8865. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  8866. * The iteratees to sort by.
  8867. * @param {string[]} [orders] The sort orders of `iteratees`.
  8868. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8869. * @returns {Array} Returns the new sorted array.
  8870. * @example
  8871. *
  8872. * var users = [
  8873. * { 'user': 'fred', 'age': 48 },
  8874. * { 'user': 'barney', 'age': 34 },
  8875. * { 'user': 'fred', 'age': 40 },
  8876. * { 'user': 'barney', 'age': 36 }
  8877. * ];
  8878. *
  8879. * // Sort by `user` in ascending order and by `age` in descending order.
  8880. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  8881. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8882. */
  8883. function orderBy(collection, iteratees, orders, guard) {
  8884. if (collection == null) {
  8885. return [];
  8886. }
  8887. if (!isArray(iteratees)) {
  8888. iteratees = iteratees == null ? [] : [iteratees];
  8889. }
  8890. orders = guard ? undefined : orders;
  8891. if (!isArray(orders)) {
  8892. orders = orders == null ? [] : [orders];
  8893. }
  8894. return baseOrderBy(collection, iteratees, orders);
  8895. }
  8896. /**
  8897. * Creates an array of elements split into two groups, the first of which
  8898. * contains elements `predicate` returns truthy for, the second of which
  8899. * contains elements `predicate` returns falsey for. The predicate is
  8900. * invoked with one argument: (value).
  8901. *
  8902. * @static
  8903. * @memberOf _
  8904. * @since 3.0.0
  8905. * @category Collection
  8906. * @param {Array|Object} collection The collection to iterate over.
  8907. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8908. * @returns {Array} Returns the array of grouped elements.
  8909. * @example
  8910. *
  8911. * var users = [
  8912. * { 'user': 'barney', 'age': 36, 'active': false },
  8913. * { 'user': 'fred', 'age': 40, 'active': true },
  8914. * { 'user': 'pebbles', 'age': 1, 'active': false }
  8915. * ];
  8916. *
  8917. * _.partition(users, function(o) { return o.active; });
  8918. * // => objects for [['fred'], ['barney', 'pebbles']]
  8919. *
  8920. * // The `_.matches` iteratee shorthand.
  8921. * _.partition(users, { 'age': 1, 'active': false });
  8922. * // => objects for [['pebbles'], ['barney', 'fred']]
  8923. *
  8924. * // The `_.matchesProperty` iteratee shorthand.
  8925. * _.partition(users, ['active', false]);
  8926. * // => objects for [['barney', 'pebbles'], ['fred']]
  8927. *
  8928. * // The `_.property` iteratee shorthand.
  8929. * _.partition(users, 'active');
  8930. * // => objects for [['fred'], ['barney', 'pebbles']]
  8931. */
  8932. var partition = createAggregator(function(result, value, key) {
  8933. result[key ? 0 : 1].push(value);
  8934. }, function() { return [[], []]; });
  8935. /**
  8936. * Reduces `collection` to a value which is the accumulated result of running
  8937. * each element in `collection` thru `iteratee`, where each successive
  8938. * invocation is supplied the return value of the previous. If `accumulator`
  8939. * is not given, the first element of `collection` is used as the initial
  8940. * value. The iteratee is invoked with four arguments:
  8941. * (accumulator, value, index|key, collection).
  8942. *
  8943. * Many lodash methods are guarded to work as iteratees for methods like
  8944. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  8945. *
  8946. * The guarded methods are:
  8947. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  8948. * and `sortBy`
  8949. *
  8950. * @static
  8951. * @memberOf _
  8952. * @since 0.1.0
  8953. * @category Collection
  8954. * @param {Array|Object} collection The collection to iterate over.
  8955. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8956. * @param {*} [accumulator] The initial value.
  8957. * @returns {*} Returns the accumulated value.
  8958. * @see _.reduceRight
  8959. * @example
  8960. *
  8961. * _.reduce([1, 2], function(sum, n) {
  8962. * return sum + n;
  8963. * }, 0);
  8964. * // => 3
  8965. *
  8966. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  8967. * (result[value] || (result[value] = [])).push(key);
  8968. * return result;
  8969. * }, {});
  8970. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  8971. */
  8972. function reduce(collection, iteratee, accumulator) {
  8973. var func = isArray(collection) ? arrayReduce : baseReduce,
  8974. initAccum = arguments.length < 3;
  8975. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  8976. }
  8977. /**
  8978. * This method is like `_.reduce` except that it iterates over elements of
  8979. * `collection` from right to left.
  8980. *
  8981. * @static
  8982. * @memberOf _
  8983. * @since 0.1.0
  8984. * @category Collection
  8985. * @param {Array|Object} collection The collection to iterate over.
  8986. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8987. * @param {*} [accumulator] The initial value.
  8988. * @returns {*} Returns the accumulated value.
  8989. * @see _.reduce
  8990. * @example
  8991. *
  8992. * var array = [[0, 1], [2, 3], [4, 5]];
  8993. *
  8994. * _.reduceRight(array, function(flattened, other) {
  8995. * return flattened.concat(other);
  8996. * }, []);
  8997. * // => [4, 5, 2, 3, 0, 1]
  8998. */
  8999. function reduceRight(collection, iteratee, accumulator) {
  9000. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  9001. initAccum = arguments.length < 3;
  9002. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  9003. }
  9004. /**
  9005. * The opposite of `_.filter`; this method returns the elements of `collection`
  9006. * that `predicate` does **not** return truthy for.
  9007. *
  9008. * @static
  9009. * @memberOf _
  9010. * @since 0.1.0
  9011. * @category Collection
  9012. * @param {Array|Object} collection The collection to iterate over.
  9013. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9014. * @returns {Array} Returns the new filtered array.
  9015. * @see _.filter
  9016. * @example
  9017. *
  9018. * var users = [
  9019. * { 'user': 'barney', 'age': 36, 'active': false },
  9020. * { 'user': 'fred', 'age': 40, 'active': true }
  9021. * ];
  9022. *
  9023. * _.reject(users, function(o) { return !o.active; });
  9024. * // => objects for ['fred']
  9025. *
  9026. * // The `_.matches` iteratee shorthand.
  9027. * _.reject(users, { 'age': 40, 'active': true });
  9028. * // => objects for ['barney']
  9029. *
  9030. * // The `_.matchesProperty` iteratee shorthand.
  9031. * _.reject(users, ['active', false]);
  9032. * // => objects for ['fred']
  9033. *
  9034. * // The `_.property` iteratee shorthand.
  9035. * _.reject(users, 'active');
  9036. * // => objects for ['barney']
  9037. */
  9038. function reject(collection, predicate) {
  9039. var func = isArray(collection) ? arrayFilter : baseFilter;
  9040. return func(collection, negate(getIteratee(predicate, 3)));
  9041. }
  9042. /**
  9043. * Gets a random element from `collection`.
  9044. *
  9045. * @static
  9046. * @memberOf _
  9047. * @since 2.0.0
  9048. * @category Collection
  9049. * @param {Array|Object} collection The collection to sample.
  9050. * @returns {*} Returns the random element.
  9051. * @example
  9052. *
  9053. * _.sample([1, 2, 3, 4]);
  9054. * // => 2
  9055. */
  9056. function sample(collection) {
  9057. var func = isArray(collection) ? arraySample : baseSample;
  9058. return func(collection);
  9059. }
  9060. /**
  9061. * Gets `n` random elements at unique keys from `collection` up to the
  9062. * size of `collection`.
  9063. *
  9064. * @static
  9065. * @memberOf _
  9066. * @since 4.0.0
  9067. * @category Collection
  9068. * @param {Array|Object} collection The collection to sample.
  9069. * @param {number} [n=1] The number of elements to sample.
  9070. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9071. * @returns {Array} Returns the random elements.
  9072. * @example
  9073. *
  9074. * _.sampleSize([1, 2, 3], 2);
  9075. * // => [3, 1]
  9076. *
  9077. * _.sampleSize([1, 2, 3], 4);
  9078. * // => [2, 3, 1]
  9079. */
  9080. function sampleSize(collection, n, guard) {
  9081. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  9082. n = 1;
  9083. } else {
  9084. n = toInteger(n);
  9085. }
  9086. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  9087. return func(collection, n);
  9088. }
  9089. /**
  9090. * Creates an array of shuffled values, using a version of the
  9091. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  9092. *
  9093. * @static
  9094. * @memberOf _
  9095. * @since 0.1.0
  9096. * @category Collection
  9097. * @param {Array|Object} collection The collection to shuffle.
  9098. * @returns {Array} Returns the new shuffled array.
  9099. * @example
  9100. *
  9101. * _.shuffle([1, 2, 3, 4]);
  9102. * // => [4, 1, 3, 2]
  9103. */
  9104. function shuffle(collection) {
  9105. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  9106. return func(collection);
  9107. }
  9108. /**
  9109. * Gets the size of `collection` by returning its length for array-like
  9110. * values or the number of own enumerable string keyed properties for objects.
  9111. *
  9112. * @static
  9113. * @memberOf _
  9114. * @since 0.1.0
  9115. * @category Collection
  9116. * @param {Array|Object|string} collection The collection to inspect.
  9117. * @returns {number} Returns the collection size.
  9118. * @example
  9119. *
  9120. * _.size([1, 2, 3]);
  9121. * // => 3
  9122. *
  9123. * _.size({ 'a': 1, 'b': 2 });
  9124. * // => 2
  9125. *
  9126. * _.size('pebbles');
  9127. * // => 7
  9128. */
  9129. function size(collection) {
  9130. if (collection == null) {
  9131. return 0;
  9132. }
  9133. if (isArrayLike(collection)) {
  9134. return isString(collection) ? stringSize(collection) : collection.length;
  9135. }
  9136. var tag = getTag(collection);
  9137. if (tag == mapTag || tag == setTag) {
  9138. return collection.size;
  9139. }
  9140. return baseKeys(collection).length;
  9141. }
  9142. /**
  9143. * Checks if `predicate` returns truthy for **any** element of `collection`.
  9144. * Iteration is stopped once `predicate` returns truthy. The predicate is
  9145. * invoked with three arguments: (value, index|key, collection).
  9146. *
  9147. * @static
  9148. * @memberOf _
  9149. * @since 0.1.0
  9150. * @category Collection
  9151. * @param {Array|Object} collection The collection to iterate over.
  9152. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9153. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9154. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9155. * else `false`.
  9156. * @example
  9157. *
  9158. * _.some([null, 0, 'yes', false], Boolean);
  9159. * // => true
  9160. *
  9161. * var users = [
  9162. * { 'user': 'barney', 'active': true },
  9163. * { 'user': 'fred', 'active': false }
  9164. * ];
  9165. *
  9166. * // The `_.matches` iteratee shorthand.
  9167. * _.some(users, { 'user': 'barney', 'active': false });
  9168. * // => false
  9169. *
  9170. * // The `_.matchesProperty` iteratee shorthand.
  9171. * _.some(users, ['active', false]);
  9172. * // => true
  9173. *
  9174. * // The `_.property` iteratee shorthand.
  9175. * _.some(users, 'active');
  9176. * // => true
  9177. */
  9178. function some(collection, predicate, guard) {
  9179. var func = isArray(collection) ? arraySome : baseSome;
  9180. if (guard && isIterateeCall(collection, predicate, guard)) {
  9181. predicate = undefined;
  9182. }
  9183. return func(collection, getIteratee(predicate, 3));
  9184. }
  9185. /**
  9186. * Creates an array of elements, sorted in ascending order by the results of
  9187. * running each element in a collection thru each iteratee. This method
  9188. * performs a stable sort, that is, it preserves the original sort order of
  9189. * equal elements. The iteratees are invoked with one argument: (value).
  9190. *
  9191. * @static
  9192. * @memberOf _
  9193. * @since 0.1.0
  9194. * @category Collection
  9195. * @param {Array|Object} collection The collection to iterate over.
  9196. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  9197. * The iteratees to sort by.
  9198. * @returns {Array} Returns the new sorted array.
  9199. * @example
  9200. *
  9201. * var users = [
  9202. * { 'user': 'fred', 'age': 48 },
  9203. * { 'user': 'barney', 'age': 36 },
  9204. * { 'user': 'fred', 'age': 40 },
  9205. * { 'user': 'barney', 'age': 34 }
  9206. * ];
  9207. *
  9208. * _.sortBy(users, [function(o) { return o.user; }]);
  9209. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  9210. *
  9211. * _.sortBy(users, ['user', 'age']);
  9212. * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
  9213. */
  9214. var sortBy = baseRest(function(collection, iteratees) {
  9215. if (collection == null) {
  9216. return [];
  9217. }
  9218. var length = iteratees.length;
  9219. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  9220. iteratees = [];
  9221. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  9222. iteratees = [iteratees[0]];
  9223. }
  9224. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  9225. });
  9226. /*------------------------------------------------------------------------*/
  9227. /**
  9228. * Gets the timestamp of the number of milliseconds that have elapsed since
  9229. * the Unix epoch (1 January 1970 00:00:00 UTC).
  9230. *
  9231. * @static
  9232. * @memberOf _
  9233. * @since 2.4.0
  9234. * @category Date
  9235. * @returns {number} Returns the timestamp.
  9236. * @example
  9237. *
  9238. * _.defer(function(stamp) {
  9239. * console.log(_.now() - stamp);
  9240. * }, _.now());
  9241. * // => Logs the number of milliseconds it took for the deferred invocation.
  9242. */
  9243. var now = ctxNow || function() {
  9244. return root.Date.now();
  9245. };
  9246. /*------------------------------------------------------------------------*/
  9247. /**
  9248. * The opposite of `_.before`; this method creates a function that invokes
  9249. * `func` once it's called `n` or more times.
  9250. *
  9251. * @static
  9252. * @memberOf _
  9253. * @since 0.1.0
  9254. * @category Function
  9255. * @param {number} n The number of calls before `func` is invoked.
  9256. * @param {Function} func The function to restrict.
  9257. * @returns {Function} Returns the new restricted function.
  9258. * @example
  9259. *
  9260. * var saves = ['profile', 'settings'];
  9261. *
  9262. * var done = _.after(saves.length, function() {
  9263. * console.log('done saving!');
  9264. * });
  9265. *
  9266. * _.forEach(saves, function(type) {
  9267. * asyncSave({ 'type': type, 'complete': done });
  9268. * });
  9269. * // => Logs 'done saving!' after the two async saves have completed.
  9270. */
  9271. function after(n, func) {
  9272. if (typeof func != 'function') {
  9273. throw new TypeError(FUNC_ERROR_TEXT);
  9274. }
  9275. n = toInteger(n);
  9276. return function() {
  9277. if (--n < 1) {
  9278. return func.apply(this, arguments);
  9279. }
  9280. };
  9281. }
  9282. /**
  9283. * Creates a function that invokes `func`, with up to `n` arguments,
  9284. * ignoring any additional arguments.
  9285. *
  9286. * @static
  9287. * @memberOf _
  9288. * @since 3.0.0
  9289. * @category Function
  9290. * @param {Function} func The function to cap arguments for.
  9291. * @param {number} [n=func.length] The arity cap.
  9292. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9293. * @returns {Function} Returns the new capped function.
  9294. * @example
  9295. *
  9296. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  9297. * // => [6, 8, 10]
  9298. */
  9299. function ary(func, n, guard) {
  9300. n = guard ? undefined : n;
  9301. n = (func && n == null) ? func.length : n;
  9302. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  9303. }
  9304. /**
  9305. * Creates a function that invokes `func`, with the `this` binding and arguments
  9306. * of the created function, while it's called less than `n` times. Subsequent
  9307. * calls to the created function return the result of the last `func` invocation.
  9308. *
  9309. * @static
  9310. * @memberOf _
  9311. * @since 3.0.0
  9312. * @category Function
  9313. * @param {number} n The number of calls at which `func` is no longer invoked.
  9314. * @param {Function} func The function to restrict.
  9315. * @returns {Function} Returns the new restricted function.
  9316. * @example
  9317. *
  9318. * jQuery(element).on('click', _.before(5, addContactToList));
  9319. * // => Allows adding up to 4 contacts to the list.
  9320. */
  9321. function before(n, func) {
  9322. var result;
  9323. if (typeof func != 'function') {
  9324. throw new TypeError(FUNC_ERROR_TEXT);
  9325. }
  9326. n = toInteger(n);
  9327. return function() {
  9328. if (--n > 0) {
  9329. result = func.apply(this, arguments);
  9330. }
  9331. if (n <= 1) {
  9332. func = undefined;
  9333. }
  9334. return result;
  9335. };
  9336. }
  9337. /**
  9338. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  9339. * and `partials` prepended to the arguments it receives.
  9340. *
  9341. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  9342. * may be used as a placeholder for partially applied arguments.
  9343. *
  9344. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  9345. * property of bound functions.
  9346. *
  9347. * @static
  9348. * @memberOf _
  9349. * @since 0.1.0
  9350. * @category Function
  9351. * @param {Function} func The function to bind.
  9352. * @param {*} thisArg The `this` binding of `func`.
  9353. * @param {...*} [partials] The arguments to be partially applied.
  9354. * @returns {Function} Returns the new bound function.
  9355. * @example
  9356. *
  9357. * function greet(greeting, punctuation) {
  9358. * return greeting + ' ' + this.user + punctuation;
  9359. * }
  9360. *
  9361. * var object = { 'user': 'fred' };
  9362. *
  9363. * var bound = _.bind(greet, object, 'hi');
  9364. * bound('!');
  9365. * // => 'hi fred!'
  9366. *
  9367. * // Bound with placeholders.
  9368. * var bound = _.bind(greet, object, _, '!');
  9369. * bound('hi');
  9370. * // => 'hi fred!'
  9371. */
  9372. var bind = baseRest(function(func, thisArg, partials) {
  9373. var bitmask = WRAP_BIND_FLAG;
  9374. if (partials.length) {
  9375. var holders = replaceHolders(partials, getHolder(bind));
  9376. bitmask |= WRAP_PARTIAL_FLAG;
  9377. }
  9378. return createWrap(func, bitmask, thisArg, partials, holders);
  9379. });
  9380. /**
  9381. * Creates a function that invokes the method at `object[key]` with `partials`
  9382. * prepended to the arguments it receives.
  9383. *
  9384. * This method differs from `_.bind` by allowing bound functions to reference
  9385. * methods that may be redefined or don't yet exist. See
  9386. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  9387. * for more details.
  9388. *
  9389. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  9390. * builds, may be used as a placeholder for partially applied arguments.
  9391. *
  9392. * @static
  9393. * @memberOf _
  9394. * @since 0.10.0
  9395. * @category Function
  9396. * @param {Object} object The object to invoke the method on.
  9397. * @param {string} key The key of the method.
  9398. * @param {...*} [partials] The arguments to be partially applied.
  9399. * @returns {Function} Returns the new bound function.
  9400. * @example
  9401. *
  9402. * var object = {
  9403. * 'user': 'fred',
  9404. * 'greet': function(greeting, punctuation) {
  9405. * return greeting + ' ' + this.user + punctuation;
  9406. * }
  9407. * };
  9408. *
  9409. * var bound = _.bindKey(object, 'greet', 'hi');
  9410. * bound('!');
  9411. * // => 'hi fred!'
  9412. *
  9413. * object.greet = function(greeting, punctuation) {
  9414. * return greeting + 'ya ' + this.user + punctuation;
  9415. * };
  9416. *
  9417. * bound('!');
  9418. * // => 'hiya fred!'
  9419. *
  9420. * // Bound with placeholders.
  9421. * var bound = _.bindKey(object, 'greet', _, '!');
  9422. * bound('hi');
  9423. * // => 'hiya fred!'
  9424. */
  9425. var bindKey = baseRest(function(object, key, partials) {
  9426. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  9427. if (partials.length) {
  9428. var holders = replaceHolders(partials, getHolder(bindKey));
  9429. bitmask |= WRAP_PARTIAL_FLAG;
  9430. }
  9431. return createWrap(key, bitmask, object, partials, holders);
  9432. });
  9433. /**
  9434. * Creates a function that accepts arguments of `func` and either invokes
  9435. * `func` returning its result, if at least `arity` number of arguments have
  9436. * been provided, or returns a function that accepts the remaining `func`
  9437. * arguments, and so on. The arity of `func` may be specified if `func.length`
  9438. * is not sufficient.
  9439. *
  9440. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  9441. * may be used as a placeholder for provided arguments.
  9442. *
  9443. * **Note:** This method doesn't set the "length" property of curried functions.
  9444. *
  9445. * @static
  9446. * @memberOf _
  9447. * @since 2.0.0
  9448. * @category Function
  9449. * @param {Function} func The function to curry.
  9450. * @param {number} [arity=func.length] The arity of `func`.
  9451. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9452. * @returns {Function} Returns the new curried function.
  9453. * @example
  9454. *
  9455. * var abc = function(a, b, c) {
  9456. * return [a, b, c];
  9457. * };
  9458. *
  9459. * var curried = _.curry(abc);
  9460. *
  9461. * curried(1)(2)(3);
  9462. * // => [1, 2, 3]
  9463. *
  9464. * curried(1, 2)(3);
  9465. * // => [1, 2, 3]
  9466. *
  9467. * curried(1, 2, 3);
  9468. * // => [1, 2, 3]
  9469. *
  9470. * // Curried with placeholders.
  9471. * curried(1)(_, 3)(2);
  9472. * // => [1, 2, 3]
  9473. */
  9474. function curry(func, arity, guard) {
  9475. arity = guard ? undefined : arity;
  9476. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9477. result.placeholder = curry.placeholder;
  9478. return result;
  9479. }
  9480. /**
  9481. * This method is like `_.curry` except that arguments are applied to `func`
  9482. * in the manner of `_.partialRight` instead of `_.partial`.
  9483. *
  9484. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9485. * builds, may be used as a placeholder for provided arguments.
  9486. *
  9487. * **Note:** This method doesn't set the "length" property of curried functions.
  9488. *
  9489. * @static
  9490. * @memberOf _
  9491. * @since 3.0.0
  9492. * @category Function
  9493. * @param {Function} func The function to curry.
  9494. * @param {number} [arity=func.length] The arity of `func`.
  9495. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9496. * @returns {Function} Returns the new curried function.
  9497. * @example
  9498. *
  9499. * var abc = function(a, b, c) {
  9500. * return [a, b, c];
  9501. * };
  9502. *
  9503. * var curried = _.curryRight(abc);
  9504. *
  9505. * curried(3)(2)(1);
  9506. * // => [1, 2, 3]
  9507. *
  9508. * curried(2, 3)(1);
  9509. * // => [1, 2, 3]
  9510. *
  9511. * curried(1, 2, 3);
  9512. * // => [1, 2, 3]
  9513. *
  9514. * // Curried with placeholders.
  9515. * curried(3)(1, _)(2);
  9516. * // => [1, 2, 3]
  9517. */
  9518. function curryRight(func, arity, guard) {
  9519. arity = guard ? undefined : arity;
  9520. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9521. result.placeholder = curryRight.placeholder;
  9522. return result;
  9523. }
  9524. /**
  9525. * Creates a debounced function that delays invoking `func` until after `wait`
  9526. * milliseconds have elapsed since the last time the debounced function was
  9527. * invoked. The debounced function comes with a `cancel` method to cancel
  9528. * delayed `func` invocations and a `flush` method to immediately invoke them.
  9529. * Provide `options` to indicate whether `func` should be invoked on the
  9530. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  9531. * with the last arguments provided to the debounced function. Subsequent
  9532. * calls to the debounced function return the result of the last `func`
  9533. * invocation.
  9534. *
  9535. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9536. * invoked on the trailing edge of the timeout only if the debounced function
  9537. * is invoked more than once during the `wait` timeout.
  9538. *
  9539. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  9540. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  9541. *
  9542. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9543. * for details over the differences between `_.debounce` and `_.throttle`.
  9544. *
  9545. * @static
  9546. * @memberOf _
  9547. * @since 0.1.0
  9548. * @category Function
  9549. * @param {Function} func The function to debounce.
  9550. * @param {number} [wait=0] The number of milliseconds to delay.
  9551. * @param {Object} [options={}] The options object.
  9552. * @param {boolean} [options.leading=false]
  9553. * Specify invoking on the leading edge of the timeout.
  9554. * @param {number} [options.maxWait]
  9555. * The maximum time `func` is allowed to be delayed before it's invoked.
  9556. * @param {boolean} [options.trailing=true]
  9557. * Specify invoking on the trailing edge of the timeout.
  9558. * @returns {Function} Returns the new debounced function.
  9559. * @example
  9560. *
  9561. * // Avoid costly calculations while the window size is in flux.
  9562. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9563. *
  9564. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  9565. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  9566. * 'leading': true,
  9567. * 'trailing': false
  9568. * }));
  9569. *
  9570. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  9571. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  9572. * var source = new EventSource('/stream');
  9573. * jQuery(source).on('message', debounced);
  9574. *
  9575. * // Cancel the trailing debounced invocation.
  9576. * jQuery(window).on('popstate', debounced.cancel);
  9577. */
  9578. function debounce(func, wait, options) {
  9579. var lastArgs,
  9580. lastThis,
  9581. maxWait,
  9582. result,
  9583. timerId,
  9584. lastCallTime,
  9585. lastInvokeTime = 0,
  9586. leading = false,
  9587. maxing = false,
  9588. trailing = true;
  9589. if (typeof func != 'function') {
  9590. throw new TypeError(FUNC_ERROR_TEXT);
  9591. }
  9592. wait = toNumber(wait) || 0;
  9593. if (isObject(options)) {
  9594. leading = !!options.leading;
  9595. maxing = 'maxWait' in options;
  9596. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  9597. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9598. }
  9599. function invokeFunc(time) {
  9600. var args = lastArgs,
  9601. thisArg = lastThis;
  9602. lastArgs = lastThis = undefined;
  9603. lastInvokeTime = time;
  9604. result = func.apply(thisArg, args);
  9605. return result;
  9606. }
  9607. function leadingEdge(time) {
  9608. // Reset any `maxWait` timer.
  9609. lastInvokeTime = time;
  9610. // Start the timer for the trailing edge.
  9611. timerId = setTimeout(timerExpired, wait);
  9612. // Invoke the leading edge.
  9613. return leading ? invokeFunc(time) : result;
  9614. }
  9615. function remainingWait(time) {
  9616. var timeSinceLastCall = time - lastCallTime,
  9617. timeSinceLastInvoke = time - lastInvokeTime,
  9618. timeWaiting = wait - timeSinceLastCall;
  9619. return maxing
  9620. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  9621. : timeWaiting;
  9622. }
  9623. function shouldInvoke(time) {
  9624. var timeSinceLastCall = time - lastCallTime,
  9625. timeSinceLastInvoke = time - lastInvokeTime;
  9626. // Either this is the first call, activity has stopped and we're at the
  9627. // trailing edge, the system time has gone backwards and we're treating
  9628. // it as the trailing edge, or we've hit the `maxWait` limit.
  9629. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  9630. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  9631. }
  9632. function timerExpired() {
  9633. var time = now();
  9634. if (shouldInvoke(time)) {
  9635. return trailingEdge(time);
  9636. }
  9637. // Restart the timer.
  9638. timerId = setTimeout(timerExpired, remainingWait(time));
  9639. }
  9640. function trailingEdge(time) {
  9641. timerId = undefined;
  9642. // Only invoke if we have `lastArgs` which means `func` has been
  9643. // debounced at least once.
  9644. if (trailing && lastArgs) {
  9645. return invokeFunc(time);
  9646. }
  9647. lastArgs = lastThis = undefined;
  9648. return result;
  9649. }
  9650. function cancel() {
  9651. if (timerId !== undefined) {
  9652. clearTimeout(timerId);
  9653. }
  9654. lastInvokeTime = 0;
  9655. lastArgs = lastCallTime = lastThis = timerId = undefined;
  9656. }
  9657. function flush() {
  9658. return timerId === undefined ? result : trailingEdge(now());
  9659. }
  9660. function debounced() {
  9661. var time = now(),
  9662. isInvoking = shouldInvoke(time);
  9663. lastArgs = arguments;
  9664. lastThis = this;
  9665. lastCallTime = time;
  9666. if (isInvoking) {
  9667. if (timerId === undefined) {
  9668. return leadingEdge(lastCallTime);
  9669. }
  9670. if (maxing) {
  9671. // Handle invocations in a tight loop.
  9672. timerId = setTimeout(timerExpired, wait);
  9673. return invokeFunc(lastCallTime);
  9674. }
  9675. }
  9676. if (timerId === undefined) {
  9677. timerId = setTimeout(timerExpired, wait);
  9678. }
  9679. return result;
  9680. }
  9681. debounced.cancel = cancel;
  9682. debounced.flush = flush;
  9683. return debounced;
  9684. }
  9685. /**
  9686. * Defers invoking the `func` until the current call stack has cleared. Any
  9687. * additional arguments are provided to `func` when it's invoked.
  9688. *
  9689. * @static
  9690. * @memberOf _
  9691. * @since 0.1.0
  9692. * @category Function
  9693. * @param {Function} func The function to defer.
  9694. * @param {...*} [args] The arguments to invoke `func` with.
  9695. * @returns {number} Returns the timer id.
  9696. * @example
  9697. *
  9698. * _.defer(function(text) {
  9699. * console.log(text);
  9700. * }, 'deferred');
  9701. * // => Logs 'deferred' after one millisecond.
  9702. */
  9703. var defer = baseRest(function(func, args) {
  9704. return baseDelay(func, 1, args);
  9705. });
  9706. /**
  9707. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9708. * provided to `func` when it's invoked.
  9709. *
  9710. * @static
  9711. * @memberOf _
  9712. * @since 0.1.0
  9713. * @category Function
  9714. * @param {Function} func The function to delay.
  9715. * @param {number} wait The number of milliseconds to delay invocation.
  9716. * @param {...*} [args] The arguments to invoke `func` with.
  9717. * @returns {number} Returns the timer id.
  9718. * @example
  9719. *
  9720. * _.delay(function(text) {
  9721. * console.log(text);
  9722. * }, 1000, 'later');
  9723. * // => Logs 'later' after one second.
  9724. */
  9725. var delay = baseRest(function(func, wait, args) {
  9726. return baseDelay(func, toNumber(wait) || 0, args);
  9727. });
  9728. /**
  9729. * Creates a function that invokes `func` with arguments reversed.
  9730. *
  9731. * @static
  9732. * @memberOf _
  9733. * @since 4.0.0
  9734. * @category Function
  9735. * @param {Function} func The function to flip arguments for.
  9736. * @returns {Function} Returns the new flipped function.
  9737. * @example
  9738. *
  9739. * var flipped = _.flip(function() {
  9740. * return _.toArray(arguments);
  9741. * });
  9742. *
  9743. * flipped('a', 'b', 'c', 'd');
  9744. * // => ['d', 'c', 'b', 'a']
  9745. */
  9746. function flip(func) {
  9747. return createWrap(func, WRAP_FLIP_FLAG);
  9748. }
  9749. /**
  9750. * Creates a function that memoizes the result of `func`. If `resolver` is
  9751. * provided, it determines the cache key for storing the result based on the
  9752. * arguments provided to the memoized function. By default, the first argument
  9753. * provided to the memoized function is used as the map cache key. The `func`
  9754. * is invoked with the `this` binding of the memoized function.
  9755. *
  9756. * **Note:** The cache is exposed as the `cache` property on the memoized
  9757. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9758. * constructor with one whose instances implement the
  9759. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  9760. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  9761. *
  9762. * @static
  9763. * @memberOf _
  9764. * @since 0.1.0
  9765. * @category Function
  9766. * @param {Function} func The function to have its output memoized.
  9767. * @param {Function} [resolver] The function to resolve the cache key.
  9768. * @returns {Function} Returns the new memoized function.
  9769. * @example
  9770. *
  9771. * var object = { 'a': 1, 'b': 2 };
  9772. * var other = { 'c': 3, 'd': 4 };
  9773. *
  9774. * var values = _.memoize(_.values);
  9775. * values(object);
  9776. * // => [1, 2]
  9777. *
  9778. * values(other);
  9779. * // => [3, 4]
  9780. *
  9781. * object.a = 2;
  9782. * values(object);
  9783. * // => [1, 2]
  9784. *
  9785. * // Modify the result cache.
  9786. * values.cache.set(object, ['a', 'b']);
  9787. * values(object);
  9788. * // => ['a', 'b']
  9789. *
  9790. * // Replace `_.memoize.Cache`.
  9791. * _.memoize.Cache = WeakMap;
  9792. */
  9793. function memoize(func, resolver) {
  9794. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  9795. throw new TypeError(FUNC_ERROR_TEXT);
  9796. }
  9797. var memoized = function() {
  9798. var args = arguments,
  9799. key = resolver ? resolver.apply(this, args) : args[0],
  9800. cache = memoized.cache;
  9801. if (cache.has(key)) {
  9802. return cache.get(key);
  9803. }
  9804. var result = func.apply(this, args);
  9805. memoized.cache = cache.set(key, result) || cache;
  9806. return result;
  9807. };
  9808. memoized.cache = new (memoize.Cache || MapCache);
  9809. return memoized;
  9810. }
  9811. // Expose `MapCache`.
  9812. memoize.Cache = MapCache;
  9813. /**
  9814. * Creates a function that negates the result of the predicate `func`. The
  9815. * `func` predicate is invoked with the `this` binding and arguments of the
  9816. * created function.
  9817. *
  9818. * @static
  9819. * @memberOf _
  9820. * @since 3.0.0
  9821. * @category Function
  9822. * @param {Function} predicate The predicate to negate.
  9823. * @returns {Function} Returns the new negated function.
  9824. * @example
  9825. *
  9826. * function isEven(n) {
  9827. * return n % 2 == 0;
  9828. * }
  9829. *
  9830. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9831. * // => [1, 3, 5]
  9832. */
  9833. function negate(predicate) {
  9834. if (typeof predicate != 'function') {
  9835. throw new TypeError(FUNC_ERROR_TEXT);
  9836. }
  9837. return function() {
  9838. var args = arguments;
  9839. switch (args.length) {
  9840. case 0: return !predicate.call(this);
  9841. case 1: return !predicate.call(this, args[0]);
  9842. case 2: return !predicate.call(this, args[0], args[1]);
  9843. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  9844. }
  9845. return !predicate.apply(this, args);
  9846. };
  9847. }
  9848. /**
  9849. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9850. * to the function return the value of the first invocation. The `func` is
  9851. * invoked with the `this` binding and arguments of the created function.
  9852. *
  9853. * @static
  9854. * @memberOf _
  9855. * @since 0.1.0
  9856. * @category Function
  9857. * @param {Function} func The function to restrict.
  9858. * @returns {Function} Returns the new restricted function.
  9859. * @example
  9860. *
  9861. * var initialize = _.once(createApplication);
  9862. * initialize();
  9863. * initialize();
  9864. * // => `createApplication` is invoked once
  9865. */
  9866. function once(func) {
  9867. return before(2, func);
  9868. }
  9869. /**
  9870. * Creates a function that invokes `func` with its arguments transformed.
  9871. *
  9872. * @static
  9873. * @since 4.0.0
  9874. * @memberOf _
  9875. * @category Function
  9876. * @param {Function} func The function to wrap.
  9877. * @param {...(Function|Function[])} [transforms=[_.identity]]
  9878. * The argument transforms.
  9879. * @returns {Function} Returns the new function.
  9880. * @example
  9881. *
  9882. * function doubled(n) {
  9883. * return n * 2;
  9884. * }
  9885. *
  9886. * function square(n) {
  9887. * return n * n;
  9888. * }
  9889. *
  9890. * var func = _.overArgs(function(x, y) {
  9891. * return [x, y];
  9892. * }, [square, doubled]);
  9893. *
  9894. * func(9, 3);
  9895. * // => [81, 6]
  9896. *
  9897. * func(10, 5);
  9898. * // => [100, 10]
  9899. */
  9900. var overArgs = castRest(function(func, transforms) {
  9901. transforms = (transforms.length == 1 && isArray(transforms[0]))
  9902. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  9903. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  9904. var funcsLength = transforms.length;
  9905. return baseRest(function(args) {
  9906. var index = -1,
  9907. length = nativeMin(args.length, funcsLength);
  9908. while (++index < length) {
  9909. args[index] = transforms[index].call(this, args[index]);
  9910. }
  9911. return apply(func, this, args);
  9912. });
  9913. });
  9914. /**
  9915. * Creates a function that invokes `func` with `partials` prepended to the
  9916. * arguments it receives. This method is like `_.bind` except it does **not**
  9917. * alter the `this` binding.
  9918. *
  9919. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  9920. * builds, may be used as a placeholder for partially applied arguments.
  9921. *
  9922. * **Note:** This method doesn't set the "length" property of partially
  9923. * applied functions.
  9924. *
  9925. * @static
  9926. * @memberOf _
  9927. * @since 0.2.0
  9928. * @category Function
  9929. * @param {Function} func The function to partially apply arguments to.
  9930. * @param {...*} [partials] The arguments to be partially applied.
  9931. * @returns {Function} Returns the new partially applied function.
  9932. * @example
  9933. *
  9934. * function greet(greeting, name) {
  9935. * return greeting + ' ' + name;
  9936. * }
  9937. *
  9938. * var sayHelloTo = _.partial(greet, 'hello');
  9939. * sayHelloTo('fred');
  9940. * // => 'hello fred'
  9941. *
  9942. * // Partially applied with placeholders.
  9943. * var greetFred = _.partial(greet, _, 'fred');
  9944. * greetFred('hi');
  9945. * // => 'hi fred'
  9946. */
  9947. var partial = baseRest(function(func, partials) {
  9948. var holders = replaceHolders(partials, getHolder(partial));
  9949. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  9950. });
  9951. /**
  9952. * This method is like `_.partial` except that partially applied arguments
  9953. * are appended to the arguments it receives.
  9954. *
  9955. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  9956. * builds, may be used as a placeholder for partially applied arguments.
  9957. *
  9958. * **Note:** This method doesn't set the "length" property of partially
  9959. * applied functions.
  9960. *
  9961. * @static
  9962. * @memberOf _
  9963. * @since 1.0.0
  9964. * @category Function
  9965. * @param {Function} func The function to partially apply arguments to.
  9966. * @param {...*} [partials] The arguments to be partially applied.
  9967. * @returns {Function} Returns the new partially applied function.
  9968. * @example
  9969. *
  9970. * function greet(greeting, name) {
  9971. * return greeting + ' ' + name;
  9972. * }
  9973. *
  9974. * var greetFred = _.partialRight(greet, 'fred');
  9975. * greetFred('hi');
  9976. * // => 'hi fred'
  9977. *
  9978. * // Partially applied with placeholders.
  9979. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  9980. * sayHelloTo('fred');
  9981. * // => 'hello fred'
  9982. */
  9983. var partialRight = baseRest(function(func, partials) {
  9984. var holders = replaceHolders(partials, getHolder(partialRight));
  9985. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  9986. });
  9987. /**
  9988. * Creates a function that invokes `func` with arguments arranged according
  9989. * to the specified `indexes` where the argument value at the first index is
  9990. * provided as the first argument, the argument value at the second index is
  9991. * provided as the second argument, and so on.
  9992. *
  9993. * @static
  9994. * @memberOf _
  9995. * @since 3.0.0
  9996. * @category Function
  9997. * @param {Function} func The function to rearrange arguments for.
  9998. * @param {...(number|number[])} indexes The arranged argument indexes.
  9999. * @returns {Function} Returns the new function.
  10000. * @example
  10001. *
  10002. * var rearged = _.rearg(function(a, b, c) {
  10003. * return [a, b, c];
  10004. * }, [2, 0, 1]);
  10005. *
  10006. * rearged('b', 'c', 'a')
  10007. * // => ['a', 'b', 'c']
  10008. */
  10009. var rearg = flatRest(function(func, indexes) {
  10010. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  10011. });
  10012. /**
  10013. * Creates a function that invokes `func` with the `this` binding of the
  10014. * created function and arguments from `start` and beyond provided as
  10015. * an array.
  10016. *
  10017. * **Note:** This method is based on the
  10018. * [rest parameter](https://mdn.io/rest_parameters).
  10019. *
  10020. * @static
  10021. * @memberOf _
  10022. * @since 4.0.0
  10023. * @category Function
  10024. * @param {Function} func The function to apply a rest parameter to.
  10025. * @param {number} [start=func.length-1] The start position of the rest parameter.
  10026. * @returns {Function} Returns the new function.
  10027. * @example
  10028. *
  10029. * var say = _.rest(function(what, names) {
  10030. * return what + ' ' + _.initial(names).join(', ') +
  10031. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  10032. * });
  10033. *
  10034. * say('hello', 'fred', 'barney', 'pebbles');
  10035. * // => 'hello fred, barney, & pebbles'
  10036. */
  10037. function rest(func, start) {
  10038. if (typeof func != 'function') {
  10039. throw new TypeError(FUNC_ERROR_TEXT);
  10040. }
  10041. start = start === undefined ? start : toInteger(start);
  10042. return baseRest(func, start);
  10043. }
  10044. /**
  10045. * Creates a function that invokes `func` with the `this` binding of the
  10046. * create function and an array of arguments much like
  10047. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  10048. *
  10049. * **Note:** This method is based on the
  10050. * [spread operator](https://mdn.io/spread_operator).
  10051. *
  10052. * @static
  10053. * @memberOf _
  10054. * @since 3.2.0
  10055. * @category Function
  10056. * @param {Function} func The function to spread arguments over.
  10057. * @param {number} [start=0] The start position of the spread.
  10058. * @returns {Function} Returns the new function.
  10059. * @example
  10060. *
  10061. * var say = _.spread(function(who, what) {
  10062. * return who + ' says ' + what;
  10063. * });
  10064. *
  10065. * say(['fred', 'hello']);
  10066. * // => 'fred says hello'
  10067. *
  10068. * var numbers = Promise.all([
  10069. * Promise.resolve(40),
  10070. * Promise.resolve(36)
  10071. * ]);
  10072. *
  10073. * numbers.then(_.spread(function(x, y) {
  10074. * return x + y;
  10075. * }));
  10076. * // => a Promise of 76
  10077. */
  10078. function spread(func, start) {
  10079. if (typeof func != 'function') {
  10080. throw new TypeError(FUNC_ERROR_TEXT);
  10081. }
  10082. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  10083. return baseRest(function(args) {
  10084. var array = args[start],
  10085. otherArgs = castSlice(args, 0, start);
  10086. if (array) {
  10087. arrayPush(otherArgs, array);
  10088. }
  10089. return apply(func, this, otherArgs);
  10090. });
  10091. }
  10092. /**
  10093. * Creates a throttled function that only invokes `func` at most once per
  10094. * every `wait` milliseconds. The throttled function comes with a `cancel`
  10095. * method to cancel delayed `func` invocations and a `flush` method to
  10096. * immediately invoke them. Provide `options` to indicate whether `func`
  10097. * should be invoked on the leading and/or trailing edge of the `wait`
  10098. * timeout. The `func` is invoked with the last arguments provided to the
  10099. * throttled function. Subsequent calls to the throttled function return the
  10100. * result of the last `func` invocation.
  10101. *
  10102. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  10103. * invoked on the trailing edge of the timeout only if the throttled function
  10104. * is invoked more than once during the `wait` timeout.
  10105. *
  10106. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  10107. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  10108. *
  10109. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  10110. * for details over the differences between `_.throttle` and `_.debounce`.
  10111. *
  10112. * @static
  10113. * @memberOf _
  10114. * @since 0.1.0
  10115. * @category Function
  10116. * @param {Function} func The function to throttle.
  10117. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  10118. * @param {Object} [options={}] The options object.
  10119. * @param {boolean} [options.leading=true]
  10120. * Specify invoking on the leading edge of the timeout.
  10121. * @param {boolean} [options.trailing=true]
  10122. * Specify invoking on the trailing edge of the timeout.
  10123. * @returns {Function} Returns the new throttled function.
  10124. * @example
  10125. *
  10126. * // Avoid excessively updating the position while scrolling.
  10127. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  10128. *
  10129. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  10130. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  10131. * jQuery(element).on('click', throttled);
  10132. *
  10133. * // Cancel the trailing throttled invocation.
  10134. * jQuery(window).on('popstate', throttled.cancel);
  10135. */
  10136. function throttle(func, wait, options) {
  10137. var leading = true,
  10138. trailing = true;
  10139. if (typeof func != 'function') {
  10140. throw new TypeError(FUNC_ERROR_TEXT);
  10141. }
  10142. if (isObject(options)) {
  10143. leading = 'leading' in options ? !!options.leading : leading;
  10144. trailing = 'trailing' in options ? !!options.trailing : trailing;
  10145. }
  10146. return debounce(func, wait, {
  10147. 'leading': leading,
  10148. 'maxWait': wait,
  10149. 'trailing': trailing
  10150. });
  10151. }
  10152. /**
  10153. * Creates a function that accepts up to one argument, ignoring any
  10154. * additional arguments.
  10155. *
  10156. * @static
  10157. * @memberOf _
  10158. * @since 4.0.0
  10159. * @category Function
  10160. * @param {Function} func The function to cap arguments for.
  10161. * @returns {Function} Returns the new capped function.
  10162. * @example
  10163. *
  10164. * _.map(['6', '8', '10'], _.unary(parseInt));
  10165. * // => [6, 8, 10]
  10166. */
  10167. function unary(func) {
  10168. return ary(func, 1);
  10169. }
  10170. /**
  10171. * Creates a function that provides `value` to `wrapper` as its first
  10172. * argument. Any additional arguments provided to the function are appended
  10173. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  10174. * binding of the created function.
  10175. *
  10176. * @static
  10177. * @memberOf _
  10178. * @since 0.1.0
  10179. * @category Function
  10180. * @param {*} value The value to wrap.
  10181. * @param {Function} [wrapper=identity] The wrapper function.
  10182. * @returns {Function} Returns the new function.
  10183. * @example
  10184. *
  10185. * var p = _.wrap(_.escape, function(func, text) {
  10186. * return '<p>' + func(text) + '</p>';
  10187. * });
  10188. *
  10189. * p('fred, barney, & pebbles');
  10190. * // => '<p>fred, barney, &amp; pebbles</p>'
  10191. */
  10192. function wrap(value, wrapper) {
  10193. return partial(castFunction(wrapper), value);
  10194. }
  10195. /*------------------------------------------------------------------------*/
  10196. /**
  10197. * Casts `value` as an array if it's not one.
  10198. *
  10199. * @static
  10200. * @memberOf _
  10201. * @since 4.4.0
  10202. * @category Lang
  10203. * @param {*} value The value to inspect.
  10204. * @returns {Array} Returns the cast array.
  10205. * @example
  10206. *
  10207. * _.castArray(1);
  10208. * // => [1]
  10209. *
  10210. * _.castArray({ 'a': 1 });
  10211. * // => [{ 'a': 1 }]
  10212. *
  10213. * _.castArray('abc');
  10214. * // => ['abc']
  10215. *
  10216. * _.castArray(null);
  10217. * // => [null]
  10218. *
  10219. * _.castArray(undefined);
  10220. * // => [undefined]
  10221. *
  10222. * _.castArray();
  10223. * // => []
  10224. *
  10225. * var array = [1, 2, 3];
  10226. * console.log(_.castArray(array) === array);
  10227. * // => true
  10228. */
  10229. function castArray() {
  10230. if (!arguments.length) {
  10231. return [];
  10232. }
  10233. var value = arguments[0];
  10234. return isArray(value) ? value : [value];
  10235. }
  10236. /**
  10237. * Creates a shallow clone of `value`.
  10238. *
  10239. * **Note:** This method is loosely based on the
  10240. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  10241. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  10242. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  10243. * arrays. The own enumerable properties of `arguments` objects are cloned
  10244. * as plain objects. An empty object is returned for uncloneable values such
  10245. * as error objects, functions, DOM nodes, and WeakMaps.
  10246. *
  10247. * @static
  10248. * @memberOf _
  10249. * @since 0.1.0
  10250. * @category Lang
  10251. * @param {*} value The value to clone.
  10252. * @returns {*} Returns the cloned value.
  10253. * @see _.cloneDeep
  10254. * @example
  10255. *
  10256. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10257. *
  10258. * var shallow = _.clone(objects);
  10259. * console.log(shallow[0] === objects[0]);
  10260. * // => true
  10261. */
  10262. function clone(value) {
  10263. return baseClone(value, CLONE_SYMBOLS_FLAG);
  10264. }
  10265. /**
  10266. * This method is like `_.clone` except that it accepts `customizer` which
  10267. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  10268. * cloning is handled by the method instead. The `customizer` is invoked with
  10269. * up to four arguments; (value [, index|key, object, stack]).
  10270. *
  10271. * @static
  10272. * @memberOf _
  10273. * @since 4.0.0
  10274. * @category Lang
  10275. * @param {*} value The value to clone.
  10276. * @param {Function} [customizer] The function to customize cloning.
  10277. * @returns {*} Returns the cloned value.
  10278. * @see _.cloneDeepWith
  10279. * @example
  10280. *
  10281. * function customizer(value) {
  10282. * if (_.isElement(value)) {
  10283. * return value.cloneNode(false);
  10284. * }
  10285. * }
  10286. *
  10287. * var el = _.cloneWith(document.body, customizer);
  10288. *
  10289. * console.log(el === document.body);
  10290. * // => false
  10291. * console.log(el.nodeName);
  10292. * // => 'BODY'
  10293. * console.log(el.childNodes.length);
  10294. * // => 0
  10295. */
  10296. function cloneWith(value, customizer) {
  10297. customizer = typeof customizer == 'function' ? customizer : undefined;
  10298. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  10299. }
  10300. /**
  10301. * This method is like `_.clone` except that it recursively clones `value`.
  10302. *
  10303. * @static
  10304. * @memberOf _
  10305. * @since 1.0.0
  10306. * @category Lang
  10307. * @param {*} value The value to recursively clone.
  10308. * @returns {*} Returns the deep cloned value.
  10309. * @see _.clone
  10310. * @example
  10311. *
  10312. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10313. *
  10314. * var deep = _.cloneDeep(objects);
  10315. * console.log(deep[0] === objects[0]);
  10316. * // => false
  10317. */
  10318. function cloneDeep(value) {
  10319. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  10320. }
  10321. /**
  10322. * This method is like `_.cloneWith` except that it recursively clones `value`.
  10323. *
  10324. * @static
  10325. * @memberOf _
  10326. * @since 4.0.0
  10327. * @category Lang
  10328. * @param {*} value The value to recursively clone.
  10329. * @param {Function} [customizer] The function to customize cloning.
  10330. * @returns {*} Returns the deep cloned value.
  10331. * @see _.cloneWith
  10332. * @example
  10333. *
  10334. * function customizer(value) {
  10335. * if (_.isElement(value)) {
  10336. * return value.cloneNode(true);
  10337. * }
  10338. * }
  10339. *
  10340. * var el = _.cloneDeepWith(document.body, customizer);
  10341. *
  10342. * console.log(el === document.body);
  10343. * // => false
  10344. * console.log(el.nodeName);
  10345. * // => 'BODY'
  10346. * console.log(el.childNodes.length);
  10347. * // => 20
  10348. */
  10349. function cloneDeepWith(value, customizer) {
  10350. customizer = typeof customizer == 'function' ? customizer : undefined;
  10351. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  10352. }
  10353. /**
  10354. * Checks if `object` conforms to `source` by invoking the predicate
  10355. * properties of `source` with the corresponding property values of `object`.
  10356. *
  10357. * **Note:** This method is equivalent to `_.conforms` when `source` is
  10358. * partially applied.
  10359. *
  10360. * @static
  10361. * @memberOf _
  10362. * @since 4.14.0
  10363. * @category Lang
  10364. * @param {Object} object The object to inspect.
  10365. * @param {Object} source The object of property predicates to conform to.
  10366. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  10367. * @example
  10368. *
  10369. * var object = { 'a': 1, 'b': 2 };
  10370. *
  10371. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  10372. * // => true
  10373. *
  10374. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  10375. * // => false
  10376. */
  10377. function conformsTo(object, source) {
  10378. return source == null || baseConformsTo(object, source, keys(source));
  10379. }
  10380. /**
  10381. * Performs a
  10382. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10383. * comparison between two values to determine if they are equivalent.
  10384. *
  10385. * @static
  10386. * @memberOf _
  10387. * @since 4.0.0
  10388. * @category Lang
  10389. * @param {*} value The value to compare.
  10390. * @param {*} other The other value to compare.
  10391. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10392. * @example
  10393. *
  10394. * var object = { 'a': 1 };
  10395. * var other = { 'a': 1 };
  10396. *
  10397. * _.eq(object, object);
  10398. * // => true
  10399. *
  10400. * _.eq(object, other);
  10401. * // => false
  10402. *
  10403. * _.eq('a', 'a');
  10404. * // => true
  10405. *
  10406. * _.eq('a', Object('a'));
  10407. * // => false
  10408. *
  10409. * _.eq(NaN, NaN);
  10410. * // => true
  10411. */
  10412. function eq(value, other) {
  10413. return value === other || (value !== value && other !== other);
  10414. }
  10415. /**
  10416. * Checks if `value` is greater than `other`.
  10417. *
  10418. * @static
  10419. * @memberOf _
  10420. * @since 3.9.0
  10421. * @category Lang
  10422. * @param {*} value The value to compare.
  10423. * @param {*} other The other value to compare.
  10424. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  10425. * else `false`.
  10426. * @see _.lt
  10427. * @example
  10428. *
  10429. * _.gt(3, 1);
  10430. * // => true
  10431. *
  10432. * _.gt(3, 3);
  10433. * // => false
  10434. *
  10435. * _.gt(1, 3);
  10436. * // => false
  10437. */
  10438. var gt = createRelationalOperation(baseGt);
  10439. /**
  10440. * Checks if `value` is greater than or equal to `other`.
  10441. *
  10442. * @static
  10443. * @memberOf _
  10444. * @since 3.9.0
  10445. * @category Lang
  10446. * @param {*} value The value to compare.
  10447. * @param {*} other The other value to compare.
  10448. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  10449. * `other`, else `false`.
  10450. * @see _.lte
  10451. * @example
  10452. *
  10453. * _.gte(3, 1);
  10454. * // => true
  10455. *
  10456. * _.gte(3, 3);
  10457. * // => true
  10458. *
  10459. * _.gte(1, 3);
  10460. * // => false
  10461. */
  10462. var gte = createRelationalOperation(function(value, other) {
  10463. return value >= other;
  10464. });
  10465. /**
  10466. * Checks if `value` is likely an `arguments` object.
  10467. *
  10468. * @static
  10469. * @memberOf _
  10470. * @since 0.1.0
  10471. * @category Lang
  10472. * @param {*} value The value to check.
  10473. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10474. * else `false`.
  10475. * @example
  10476. *
  10477. * _.isArguments(function() { return arguments; }());
  10478. * // => true
  10479. *
  10480. * _.isArguments([1, 2, 3]);
  10481. * // => false
  10482. */
  10483. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  10484. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  10485. !propertyIsEnumerable.call(value, 'callee');
  10486. };
  10487. /**
  10488. * Checks if `value` is classified as an `Array` object.
  10489. *
  10490. * @static
  10491. * @memberOf _
  10492. * @since 0.1.0
  10493. * @category Lang
  10494. * @param {*} value The value to check.
  10495. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10496. * @example
  10497. *
  10498. * _.isArray([1, 2, 3]);
  10499. * // => true
  10500. *
  10501. * _.isArray(document.body.children);
  10502. * // => false
  10503. *
  10504. * _.isArray('abc');
  10505. * // => false
  10506. *
  10507. * _.isArray(_.noop);
  10508. * // => false
  10509. */
  10510. var isArray = Array.isArray;
  10511. /**
  10512. * Checks if `value` is classified as an `ArrayBuffer` object.
  10513. *
  10514. * @static
  10515. * @memberOf _
  10516. * @since 4.3.0
  10517. * @category Lang
  10518. * @param {*} value The value to check.
  10519. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  10520. * @example
  10521. *
  10522. * _.isArrayBuffer(new ArrayBuffer(2));
  10523. * // => true
  10524. *
  10525. * _.isArrayBuffer(new Array(2));
  10526. * // => false
  10527. */
  10528. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  10529. /**
  10530. * Checks if `value` is array-like. A value is considered array-like if it's
  10531. * not a function and has a `value.length` that's an integer greater than or
  10532. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10533. *
  10534. * @static
  10535. * @memberOf _
  10536. * @since 4.0.0
  10537. * @category Lang
  10538. * @param {*} value The value to check.
  10539. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10540. * @example
  10541. *
  10542. * _.isArrayLike([1, 2, 3]);
  10543. * // => true
  10544. *
  10545. * _.isArrayLike(document.body.children);
  10546. * // => true
  10547. *
  10548. * _.isArrayLike('abc');
  10549. * // => true
  10550. *
  10551. * _.isArrayLike(_.noop);
  10552. * // => false
  10553. */
  10554. function isArrayLike(value) {
  10555. return value != null && isLength(value.length) && !isFunction(value);
  10556. }
  10557. /**
  10558. * This method is like `_.isArrayLike` except that it also checks if `value`
  10559. * is an object.
  10560. *
  10561. * @static
  10562. * @memberOf _
  10563. * @since 4.0.0
  10564. * @category Lang
  10565. * @param {*} value The value to check.
  10566. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10567. * else `false`.
  10568. * @example
  10569. *
  10570. * _.isArrayLikeObject([1, 2, 3]);
  10571. * // => true
  10572. *
  10573. * _.isArrayLikeObject(document.body.children);
  10574. * // => true
  10575. *
  10576. * _.isArrayLikeObject('abc');
  10577. * // => false
  10578. *
  10579. * _.isArrayLikeObject(_.noop);
  10580. * // => false
  10581. */
  10582. function isArrayLikeObject(value) {
  10583. return isObjectLike(value) && isArrayLike(value);
  10584. }
  10585. /**
  10586. * Checks if `value` is classified as a boolean primitive or object.
  10587. *
  10588. * @static
  10589. * @memberOf _
  10590. * @since 0.1.0
  10591. * @category Lang
  10592. * @param {*} value The value to check.
  10593. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  10594. * @example
  10595. *
  10596. * _.isBoolean(false);
  10597. * // => true
  10598. *
  10599. * _.isBoolean(null);
  10600. * // => false
  10601. */
  10602. function isBoolean(value) {
  10603. return value === true || value === false ||
  10604. (isObjectLike(value) && baseGetTag(value) == boolTag);
  10605. }
  10606. /**
  10607. * Checks if `value` is a buffer.
  10608. *
  10609. * @static
  10610. * @memberOf _
  10611. * @since 4.3.0
  10612. * @category Lang
  10613. * @param {*} value The value to check.
  10614. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  10615. * @example
  10616. *
  10617. * _.isBuffer(new Buffer(2));
  10618. * // => true
  10619. *
  10620. * _.isBuffer(new Uint8Array(2));
  10621. * // => false
  10622. */
  10623. var isBuffer = nativeIsBuffer || stubFalse;
  10624. /**
  10625. * Checks if `value` is classified as a `Date` object.
  10626. *
  10627. * @static
  10628. * @memberOf _
  10629. * @since 0.1.0
  10630. * @category Lang
  10631. * @param {*} value The value to check.
  10632. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  10633. * @example
  10634. *
  10635. * _.isDate(new Date);
  10636. * // => true
  10637. *
  10638. * _.isDate('Mon April 23 2012');
  10639. * // => false
  10640. */
  10641. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  10642. /**
  10643. * Checks if `value` is likely a DOM element.
  10644. *
  10645. * @static
  10646. * @memberOf _
  10647. * @since 0.1.0
  10648. * @category Lang
  10649. * @param {*} value The value to check.
  10650. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  10651. * @example
  10652. *
  10653. * _.isElement(document.body);
  10654. * // => true
  10655. *
  10656. * _.isElement('<body>');
  10657. * // => false
  10658. */
  10659. function isElement(value) {
  10660. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  10661. }
  10662. /**
  10663. * Checks if `value` is an empty object, collection, map, or set.
  10664. *
  10665. * Objects are considered empty if they have no own enumerable string keyed
  10666. * properties.
  10667. *
  10668. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  10669. * jQuery-like collections are considered empty if they have a `length` of `0`.
  10670. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  10671. *
  10672. * @static
  10673. * @memberOf _
  10674. * @since 0.1.0
  10675. * @category Lang
  10676. * @param {*} value The value to check.
  10677. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  10678. * @example
  10679. *
  10680. * _.isEmpty(null);
  10681. * // => true
  10682. *
  10683. * _.isEmpty(true);
  10684. * // => true
  10685. *
  10686. * _.isEmpty(1);
  10687. * // => true
  10688. *
  10689. * _.isEmpty([1, 2, 3]);
  10690. * // => false
  10691. *
  10692. * _.isEmpty({ 'a': 1 });
  10693. * // => false
  10694. */
  10695. function isEmpty(value) {
  10696. if (value == null) {
  10697. return true;
  10698. }
  10699. if (isArrayLike(value) &&
  10700. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  10701. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  10702. return !value.length;
  10703. }
  10704. var tag = getTag(value);
  10705. if (tag == mapTag || tag == setTag) {
  10706. return !value.size;
  10707. }
  10708. if (isPrototype(value)) {
  10709. return !baseKeys(value).length;
  10710. }
  10711. for (var key in value) {
  10712. if (hasOwnProperty.call(value, key)) {
  10713. return false;
  10714. }
  10715. }
  10716. return true;
  10717. }
  10718. /**
  10719. * Performs a deep comparison between two values to determine if they are
  10720. * equivalent.
  10721. *
  10722. * **Note:** This method supports comparing arrays, array buffers, booleans,
  10723. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  10724. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  10725. * by their own, not inherited, enumerable properties. Functions and DOM
  10726. * nodes are compared by strict equality, i.e. `===`.
  10727. *
  10728. * @static
  10729. * @memberOf _
  10730. * @since 0.1.0
  10731. * @category Lang
  10732. * @param {*} value The value to compare.
  10733. * @param {*} other The other value to compare.
  10734. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10735. * @example
  10736. *
  10737. * var object = { 'a': 1 };
  10738. * var other = { 'a': 1 };
  10739. *
  10740. * _.isEqual(object, other);
  10741. * // => true
  10742. *
  10743. * object === other;
  10744. * // => false
  10745. */
  10746. function isEqual(value, other) {
  10747. return baseIsEqual(value, other);
  10748. }
  10749. /**
  10750. * This method is like `_.isEqual` except that it accepts `customizer` which
  10751. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10752. * are handled by the method instead. The `customizer` is invoked with up to
  10753. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  10754. *
  10755. * @static
  10756. * @memberOf _
  10757. * @since 4.0.0
  10758. * @category Lang
  10759. * @param {*} value The value to compare.
  10760. * @param {*} other The other value to compare.
  10761. * @param {Function} [customizer] The function to customize comparisons.
  10762. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10763. * @example
  10764. *
  10765. * function isGreeting(value) {
  10766. * return /^h(?:i|ello)$/.test(value);
  10767. * }
  10768. *
  10769. * function customizer(objValue, othValue) {
  10770. * if (isGreeting(objValue) && isGreeting(othValue)) {
  10771. * return true;
  10772. * }
  10773. * }
  10774. *
  10775. * var array = ['hello', 'goodbye'];
  10776. * var other = ['hi', 'goodbye'];
  10777. *
  10778. * _.isEqualWith(array, other, customizer);
  10779. * // => true
  10780. */
  10781. function isEqualWith(value, other, customizer) {
  10782. customizer = typeof customizer == 'function' ? customizer : undefined;
  10783. var result = customizer ? customizer(value, other) : undefined;
  10784. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  10785. }
  10786. /**
  10787. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10788. * `SyntaxError`, `TypeError`, or `URIError` object.
  10789. *
  10790. * @static
  10791. * @memberOf _
  10792. * @since 3.0.0
  10793. * @category Lang
  10794. * @param {*} value The value to check.
  10795. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  10796. * @example
  10797. *
  10798. * _.isError(new Error);
  10799. * // => true
  10800. *
  10801. * _.isError(Error);
  10802. * // => false
  10803. */
  10804. function isError(value) {
  10805. if (!isObjectLike(value)) {
  10806. return false;
  10807. }
  10808. var tag = baseGetTag(value);
  10809. return tag == errorTag || tag == domExcTag ||
  10810. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  10811. }
  10812. /**
  10813. * Checks if `value` is a finite primitive number.
  10814. *
  10815. * **Note:** This method is based on
  10816. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  10817. *
  10818. * @static
  10819. * @memberOf _
  10820. * @since 0.1.0
  10821. * @category Lang
  10822. * @param {*} value The value to check.
  10823. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  10824. * @example
  10825. *
  10826. * _.isFinite(3);
  10827. * // => true
  10828. *
  10829. * _.isFinite(Number.MIN_VALUE);
  10830. * // => true
  10831. *
  10832. * _.isFinite(Infinity);
  10833. * // => false
  10834. *
  10835. * _.isFinite('3');
  10836. * // => false
  10837. */
  10838. function isFinite(value) {
  10839. return typeof value == 'number' && nativeIsFinite(value);
  10840. }
  10841. /**
  10842. * Checks if `value` is classified as a `Function` object.
  10843. *
  10844. * @static
  10845. * @memberOf _
  10846. * @since 0.1.0
  10847. * @category Lang
  10848. * @param {*} value The value to check.
  10849. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10850. * @example
  10851. *
  10852. * _.isFunction(_);
  10853. * // => true
  10854. *
  10855. * _.isFunction(/abc/);
  10856. * // => false
  10857. */
  10858. function isFunction(value) {
  10859. if (!isObject(value)) {
  10860. return false;
  10861. }
  10862. // The use of `Object#toString` avoids issues with the `typeof` operator
  10863. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  10864. var tag = baseGetTag(value);
  10865. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  10866. }
  10867. /**
  10868. * Checks if `value` is an integer.
  10869. *
  10870. * **Note:** This method is based on
  10871. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  10872. *
  10873. * @static
  10874. * @memberOf _
  10875. * @since 4.0.0
  10876. * @category Lang
  10877. * @param {*} value The value to check.
  10878. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  10879. * @example
  10880. *
  10881. * _.isInteger(3);
  10882. * // => true
  10883. *
  10884. * _.isInteger(Number.MIN_VALUE);
  10885. * // => false
  10886. *
  10887. * _.isInteger(Infinity);
  10888. * // => false
  10889. *
  10890. * _.isInteger('3');
  10891. * // => false
  10892. */
  10893. function isInteger(value) {
  10894. return typeof value == 'number' && value == toInteger(value);
  10895. }
  10896. /**
  10897. * Checks if `value` is a valid array-like length.
  10898. *
  10899. * **Note:** This method is loosely based on
  10900. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10901. *
  10902. * @static
  10903. * @memberOf _
  10904. * @since 4.0.0
  10905. * @category Lang
  10906. * @param {*} value The value to check.
  10907. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10908. * @example
  10909. *
  10910. * _.isLength(3);
  10911. * // => true
  10912. *
  10913. * _.isLength(Number.MIN_VALUE);
  10914. * // => false
  10915. *
  10916. * _.isLength(Infinity);
  10917. * // => false
  10918. *
  10919. * _.isLength('3');
  10920. * // => false
  10921. */
  10922. function isLength(value) {
  10923. return typeof value == 'number' &&
  10924. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10925. }
  10926. /**
  10927. * Checks if `value` is the
  10928. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10929. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10930. *
  10931. * @static
  10932. * @memberOf _
  10933. * @since 0.1.0
  10934. * @category Lang
  10935. * @param {*} value The value to check.
  10936. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10937. * @example
  10938. *
  10939. * _.isObject({});
  10940. * // => true
  10941. *
  10942. * _.isObject([1, 2, 3]);
  10943. * // => true
  10944. *
  10945. * _.isObject(_.noop);
  10946. * // => true
  10947. *
  10948. * _.isObject(null);
  10949. * // => false
  10950. */
  10951. function isObject(value) {
  10952. var type = typeof value;
  10953. return value != null && (type == 'object' || type == 'function');
  10954. }
  10955. /**
  10956. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10957. * and has a `typeof` result of "object".
  10958. *
  10959. * @static
  10960. * @memberOf _
  10961. * @since 4.0.0
  10962. * @category Lang
  10963. * @param {*} value The value to check.
  10964. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10965. * @example
  10966. *
  10967. * _.isObjectLike({});
  10968. * // => true
  10969. *
  10970. * _.isObjectLike([1, 2, 3]);
  10971. * // => true
  10972. *
  10973. * _.isObjectLike(_.noop);
  10974. * // => false
  10975. *
  10976. * _.isObjectLike(null);
  10977. * // => false
  10978. */
  10979. function isObjectLike(value) {
  10980. return value != null && typeof value == 'object';
  10981. }
  10982. /**
  10983. * Checks if `value` is classified as a `Map` object.
  10984. *
  10985. * @static
  10986. * @memberOf _
  10987. * @since 4.3.0
  10988. * @category Lang
  10989. * @param {*} value The value to check.
  10990. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  10991. * @example
  10992. *
  10993. * _.isMap(new Map);
  10994. * // => true
  10995. *
  10996. * _.isMap(new WeakMap);
  10997. * // => false
  10998. */
  10999. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  11000. /**
  11001. * Performs a partial deep comparison between `object` and `source` to
  11002. * determine if `object` contains equivalent property values.
  11003. *
  11004. * **Note:** This method is equivalent to `_.matches` when `source` is
  11005. * partially applied.
  11006. *
  11007. * Partial comparisons will match empty array and empty object `source`
  11008. * values against any array or object value, respectively. See `_.isEqual`
  11009. * for a list of supported value comparisons.
  11010. *
  11011. * @static
  11012. * @memberOf _
  11013. * @since 3.0.0
  11014. * @category Lang
  11015. * @param {Object} object The object to inspect.
  11016. * @param {Object} source The object of property values to match.
  11017. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11018. * @example
  11019. *
  11020. * var object = { 'a': 1, 'b': 2 };
  11021. *
  11022. * _.isMatch(object, { 'b': 2 });
  11023. * // => true
  11024. *
  11025. * _.isMatch(object, { 'b': 1 });
  11026. * // => false
  11027. */
  11028. function isMatch(object, source) {
  11029. return object === source || baseIsMatch(object, source, getMatchData(source));
  11030. }
  11031. /**
  11032. * This method is like `_.isMatch` except that it accepts `customizer` which
  11033. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  11034. * are handled by the method instead. The `customizer` is invoked with five
  11035. * arguments: (objValue, srcValue, index|key, object, source).
  11036. *
  11037. * @static
  11038. * @memberOf _
  11039. * @since 4.0.0
  11040. * @category Lang
  11041. * @param {Object} object The object to inspect.
  11042. * @param {Object} source The object of property values to match.
  11043. * @param {Function} [customizer] The function to customize comparisons.
  11044. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11045. * @example
  11046. *
  11047. * function isGreeting(value) {
  11048. * return /^h(?:i|ello)$/.test(value);
  11049. * }
  11050. *
  11051. * function customizer(objValue, srcValue) {
  11052. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  11053. * return true;
  11054. * }
  11055. * }
  11056. *
  11057. * var object = { 'greeting': 'hello' };
  11058. * var source = { 'greeting': 'hi' };
  11059. *
  11060. * _.isMatchWith(object, source, customizer);
  11061. * // => true
  11062. */
  11063. function isMatchWith(object, source, customizer) {
  11064. customizer = typeof customizer == 'function' ? customizer : undefined;
  11065. return baseIsMatch(object, source, getMatchData(source), customizer);
  11066. }
  11067. /**
  11068. * Checks if `value` is `NaN`.
  11069. *
  11070. * **Note:** This method is based on
  11071. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  11072. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  11073. * `undefined` and other non-number values.
  11074. *
  11075. * @static
  11076. * @memberOf _
  11077. * @since 0.1.0
  11078. * @category Lang
  11079. * @param {*} value The value to check.
  11080. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  11081. * @example
  11082. *
  11083. * _.isNaN(NaN);
  11084. * // => true
  11085. *
  11086. * _.isNaN(new Number(NaN));
  11087. * // => true
  11088. *
  11089. * isNaN(undefined);
  11090. * // => true
  11091. *
  11092. * _.isNaN(undefined);
  11093. * // => false
  11094. */
  11095. function isNaN(value) {
  11096. // An `NaN` primitive is the only value that is not equal to itself.
  11097. // Perform the `toStringTag` check first to avoid errors with some
  11098. // ActiveX objects in IE.
  11099. return isNumber(value) && value != +value;
  11100. }
  11101. /**
  11102. * Checks if `value` is a pristine native function.
  11103. *
  11104. * **Note:** This method can't reliably detect native functions in the presence
  11105. * of the core-js package because core-js circumvents this kind of detection.
  11106. * Despite multiple requests, the core-js maintainer has made it clear: any
  11107. * attempt to fix the detection will be obstructed. As a result, we're left
  11108. * with little choice but to throw an error. Unfortunately, this also affects
  11109. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  11110. * which rely on core-js.
  11111. *
  11112. * @static
  11113. * @memberOf _
  11114. * @since 3.0.0
  11115. * @category Lang
  11116. * @param {*} value The value to check.
  11117. * @returns {boolean} Returns `true` if `value` is a native function,
  11118. * else `false`.
  11119. * @example
  11120. *
  11121. * _.isNative(Array.prototype.push);
  11122. * // => true
  11123. *
  11124. * _.isNative(_);
  11125. * // => false
  11126. */
  11127. function isNative(value) {
  11128. if (isMaskable(value)) {
  11129. throw new Error(CORE_ERROR_TEXT);
  11130. }
  11131. return baseIsNative(value);
  11132. }
  11133. /**
  11134. * Checks if `value` is `null`.
  11135. *
  11136. * @static
  11137. * @memberOf _
  11138. * @since 0.1.0
  11139. * @category Lang
  11140. * @param {*} value The value to check.
  11141. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  11142. * @example
  11143. *
  11144. * _.isNull(null);
  11145. * // => true
  11146. *
  11147. * _.isNull(void 0);
  11148. * // => false
  11149. */
  11150. function isNull(value) {
  11151. return value === null;
  11152. }
  11153. /**
  11154. * Checks if `value` is `null` or `undefined`.
  11155. *
  11156. * @static
  11157. * @memberOf _
  11158. * @since 4.0.0
  11159. * @category Lang
  11160. * @param {*} value The value to check.
  11161. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  11162. * @example
  11163. *
  11164. * _.isNil(null);
  11165. * // => true
  11166. *
  11167. * _.isNil(void 0);
  11168. * // => true
  11169. *
  11170. * _.isNil(NaN);
  11171. * // => false
  11172. */
  11173. function isNil(value) {
  11174. return value == null;
  11175. }
  11176. /**
  11177. * Checks if `value` is classified as a `Number` primitive or object.
  11178. *
  11179. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  11180. * classified as numbers, use the `_.isFinite` method.
  11181. *
  11182. * @static
  11183. * @memberOf _
  11184. * @since 0.1.0
  11185. * @category Lang
  11186. * @param {*} value The value to check.
  11187. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  11188. * @example
  11189. *
  11190. * _.isNumber(3);
  11191. * // => true
  11192. *
  11193. * _.isNumber(Number.MIN_VALUE);
  11194. * // => true
  11195. *
  11196. * _.isNumber(Infinity);
  11197. * // => true
  11198. *
  11199. * _.isNumber('3');
  11200. * // => false
  11201. */
  11202. function isNumber(value) {
  11203. return typeof value == 'number' ||
  11204. (isObjectLike(value) && baseGetTag(value) == numberTag);
  11205. }
  11206. /**
  11207. * Checks if `value` is a plain object, that is, an object created by the
  11208. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  11209. *
  11210. * @static
  11211. * @memberOf _
  11212. * @since 0.8.0
  11213. * @category Lang
  11214. * @param {*} value The value to check.
  11215. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  11216. * @example
  11217. *
  11218. * function Foo() {
  11219. * this.a = 1;
  11220. * }
  11221. *
  11222. * _.isPlainObject(new Foo);
  11223. * // => false
  11224. *
  11225. * _.isPlainObject([1, 2, 3]);
  11226. * // => false
  11227. *
  11228. * _.isPlainObject({ 'x': 0, 'y': 0 });
  11229. * // => true
  11230. *
  11231. * _.isPlainObject(Object.create(null));
  11232. * // => true
  11233. */
  11234. function isPlainObject(value) {
  11235. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  11236. return false;
  11237. }
  11238. var proto = getPrototype(value);
  11239. if (proto === null) {
  11240. return true;
  11241. }
  11242. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  11243. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  11244. funcToString.call(Ctor) == objectCtorString;
  11245. }
  11246. /**
  11247. * Checks if `value` is classified as a `RegExp` object.
  11248. *
  11249. * @static
  11250. * @memberOf _
  11251. * @since 0.1.0
  11252. * @category Lang
  11253. * @param {*} value The value to check.
  11254. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  11255. * @example
  11256. *
  11257. * _.isRegExp(/abc/);
  11258. * // => true
  11259. *
  11260. * _.isRegExp('/abc/');
  11261. * // => false
  11262. */
  11263. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  11264. /**
  11265. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  11266. * double precision number which isn't the result of a rounded unsafe integer.
  11267. *
  11268. * **Note:** This method is based on
  11269. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  11270. *
  11271. * @static
  11272. * @memberOf _
  11273. * @since 4.0.0
  11274. * @category Lang
  11275. * @param {*} value The value to check.
  11276. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  11277. * @example
  11278. *
  11279. * _.isSafeInteger(3);
  11280. * // => true
  11281. *
  11282. * _.isSafeInteger(Number.MIN_VALUE);
  11283. * // => false
  11284. *
  11285. * _.isSafeInteger(Infinity);
  11286. * // => false
  11287. *
  11288. * _.isSafeInteger('3');
  11289. * // => false
  11290. */
  11291. function isSafeInteger(value) {
  11292. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  11293. }
  11294. /**
  11295. * Checks if `value` is classified as a `Set` object.
  11296. *
  11297. * @static
  11298. * @memberOf _
  11299. * @since 4.3.0
  11300. * @category Lang
  11301. * @param {*} value The value to check.
  11302. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  11303. * @example
  11304. *
  11305. * _.isSet(new Set);
  11306. * // => true
  11307. *
  11308. * _.isSet(new WeakSet);
  11309. * // => false
  11310. */
  11311. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  11312. /**
  11313. * Checks if `value` is classified as a `String` primitive or object.
  11314. *
  11315. * @static
  11316. * @since 0.1.0
  11317. * @memberOf _
  11318. * @category Lang
  11319. * @param {*} value The value to check.
  11320. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  11321. * @example
  11322. *
  11323. * _.isString('abc');
  11324. * // => true
  11325. *
  11326. * _.isString(1);
  11327. * // => false
  11328. */
  11329. function isString(value) {
  11330. return typeof value == 'string' ||
  11331. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  11332. }
  11333. /**
  11334. * Checks if `value` is classified as a `Symbol` primitive or object.
  11335. *
  11336. * @static
  11337. * @memberOf _
  11338. * @since 4.0.0
  11339. * @category Lang
  11340. * @param {*} value The value to check.
  11341. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  11342. * @example
  11343. *
  11344. * _.isSymbol(Symbol.iterator);
  11345. * // => true
  11346. *
  11347. * _.isSymbol('abc');
  11348. * // => false
  11349. */
  11350. function isSymbol(value) {
  11351. return typeof value == 'symbol' ||
  11352. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  11353. }
  11354. /**
  11355. * Checks if `value` is classified as a typed array.
  11356. *
  11357. * @static
  11358. * @memberOf _
  11359. * @since 3.0.0
  11360. * @category Lang
  11361. * @param {*} value The value to check.
  11362. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  11363. * @example
  11364. *
  11365. * _.isTypedArray(new Uint8Array);
  11366. * // => true
  11367. *
  11368. * _.isTypedArray([]);
  11369. * // => false
  11370. */
  11371. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  11372. /**
  11373. * Checks if `value` is `undefined`.
  11374. *
  11375. * @static
  11376. * @since 0.1.0
  11377. * @memberOf _
  11378. * @category Lang
  11379. * @param {*} value The value to check.
  11380. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  11381. * @example
  11382. *
  11383. * _.isUndefined(void 0);
  11384. * // => true
  11385. *
  11386. * _.isUndefined(null);
  11387. * // => false
  11388. */
  11389. function isUndefined(value) {
  11390. return value === undefined;
  11391. }
  11392. /**
  11393. * Checks if `value` is classified as a `WeakMap` object.
  11394. *
  11395. * @static
  11396. * @memberOf _
  11397. * @since 4.3.0
  11398. * @category Lang
  11399. * @param {*} value The value to check.
  11400. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  11401. * @example
  11402. *
  11403. * _.isWeakMap(new WeakMap);
  11404. * // => true
  11405. *
  11406. * _.isWeakMap(new Map);
  11407. * // => false
  11408. */
  11409. function isWeakMap(value) {
  11410. return isObjectLike(value) && getTag(value) == weakMapTag;
  11411. }
  11412. /**
  11413. * Checks if `value` is classified as a `WeakSet` object.
  11414. *
  11415. * @static
  11416. * @memberOf _
  11417. * @since 4.3.0
  11418. * @category Lang
  11419. * @param {*} value The value to check.
  11420. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  11421. * @example
  11422. *
  11423. * _.isWeakSet(new WeakSet);
  11424. * // => true
  11425. *
  11426. * _.isWeakSet(new Set);
  11427. * // => false
  11428. */
  11429. function isWeakSet(value) {
  11430. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  11431. }
  11432. /**
  11433. * Checks if `value` is less than `other`.
  11434. *
  11435. * @static
  11436. * @memberOf _
  11437. * @since 3.9.0
  11438. * @category Lang
  11439. * @param {*} value The value to compare.
  11440. * @param {*} other The other value to compare.
  11441. * @returns {boolean} Returns `true` if `value` is less than `other`,
  11442. * else `false`.
  11443. * @see _.gt
  11444. * @example
  11445. *
  11446. * _.lt(1, 3);
  11447. * // => true
  11448. *
  11449. * _.lt(3, 3);
  11450. * // => false
  11451. *
  11452. * _.lt(3, 1);
  11453. * // => false
  11454. */
  11455. var lt = createRelationalOperation(baseLt);
  11456. /**
  11457. * Checks if `value` is less than or equal to `other`.
  11458. *
  11459. * @static
  11460. * @memberOf _
  11461. * @since 3.9.0
  11462. * @category Lang
  11463. * @param {*} value The value to compare.
  11464. * @param {*} other The other value to compare.
  11465. * @returns {boolean} Returns `true` if `value` is less than or equal to
  11466. * `other`, else `false`.
  11467. * @see _.gte
  11468. * @example
  11469. *
  11470. * _.lte(1, 3);
  11471. * // => true
  11472. *
  11473. * _.lte(3, 3);
  11474. * // => true
  11475. *
  11476. * _.lte(3, 1);
  11477. * // => false
  11478. */
  11479. var lte = createRelationalOperation(function(value, other) {
  11480. return value <= other;
  11481. });
  11482. /**
  11483. * Converts `value` to an array.
  11484. *
  11485. * @static
  11486. * @since 0.1.0
  11487. * @memberOf _
  11488. * @category Lang
  11489. * @param {*} value The value to convert.
  11490. * @returns {Array} Returns the converted array.
  11491. * @example
  11492. *
  11493. * _.toArray({ 'a': 1, 'b': 2 });
  11494. * // => [1, 2]
  11495. *
  11496. * _.toArray('abc');
  11497. * // => ['a', 'b', 'c']
  11498. *
  11499. * _.toArray(1);
  11500. * // => []
  11501. *
  11502. * _.toArray(null);
  11503. * // => []
  11504. */
  11505. function toArray(value) {
  11506. if (!value) {
  11507. return [];
  11508. }
  11509. if (isArrayLike(value)) {
  11510. return isString(value) ? stringToArray(value) : copyArray(value);
  11511. }
  11512. if (symIterator && value[symIterator]) {
  11513. return iteratorToArray(value[symIterator]());
  11514. }
  11515. var tag = getTag(value),
  11516. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  11517. return func(value);
  11518. }
  11519. /**
  11520. * Converts `value` to a finite number.
  11521. *
  11522. * @static
  11523. * @memberOf _
  11524. * @since 4.12.0
  11525. * @category Lang
  11526. * @param {*} value The value to convert.
  11527. * @returns {number} Returns the converted number.
  11528. * @example
  11529. *
  11530. * _.toFinite(3.2);
  11531. * // => 3.2
  11532. *
  11533. * _.toFinite(Number.MIN_VALUE);
  11534. * // => 5e-324
  11535. *
  11536. * _.toFinite(Infinity);
  11537. * // => 1.7976931348623157e+308
  11538. *
  11539. * _.toFinite('3.2');
  11540. * // => 3.2
  11541. */
  11542. function toFinite(value) {
  11543. if (!value) {
  11544. return value === 0 ? value : 0;
  11545. }
  11546. value = toNumber(value);
  11547. if (value === INFINITY || value === -INFINITY) {
  11548. var sign = (value < 0 ? -1 : 1);
  11549. return sign * MAX_INTEGER;
  11550. }
  11551. return value === value ? value : 0;
  11552. }
  11553. /**
  11554. * Converts `value` to an integer.
  11555. *
  11556. * **Note:** This method is loosely based on
  11557. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  11558. *
  11559. * @static
  11560. * @memberOf _
  11561. * @since 4.0.0
  11562. * @category Lang
  11563. * @param {*} value The value to convert.
  11564. * @returns {number} Returns the converted integer.
  11565. * @example
  11566. *
  11567. * _.toInteger(3.2);
  11568. * // => 3
  11569. *
  11570. * _.toInteger(Number.MIN_VALUE);
  11571. * // => 0
  11572. *
  11573. * _.toInteger(Infinity);
  11574. * // => 1.7976931348623157e+308
  11575. *
  11576. * _.toInteger('3.2');
  11577. * // => 3
  11578. */
  11579. function toInteger(value) {
  11580. var result = toFinite(value),
  11581. remainder = result % 1;
  11582. return result === result ? (remainder ? result - remainder : result) : 0;
  11583. }
  11584. /**
  11585. * Converts `value` to an integer suitable for use as the length of an
  11586. * array-like object.
  11587. *
  11588. * **Note:** This method is based on
  11589. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  11590. *
  11591. * @static
  11592. * @memberOf _
  11593. * @since 4.0.0
  11594. * @category Lang
  11595. * @param {*} value The value to convert.
  11596. * @returns {number} Returns the converted integer.
  11597. * @example
  11598. *
  11599. * _.toLength(3.2);
  11600. * // => 3
  11601. *
  11602. * _.toLength(Number.MIN_VALUE);
  11603. * // => 0
  11604. *
  11605. * _.toLength(Infinity);
  11606. * // => 4294967295
  11607. *
  11608. * _.toLength('3.2');
  11609. * // => 3
  11610. */
  11611. function toLength(value) {
  11612. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  11613. }
  11614. /**
  11615. * Converts `value` to a number.
  11616. *
  11617. * @static
  11618. * @memberOf _
  11619. * @since 4.0.0
  11620. * @category Lang
  11621. * @param {*} value The value to process.
  11622. * @returns {number} Returns the number.
  11623. * @example
  11624. *
  11625. * _.toNumber(3.2);
  11626. * // => 3.2
  11627. *
  11628. * _.toNumber(Number.MIN_VALUE);
  11629. * // => 5e-324
  11630. *
  11631. * _.toNumber(Infinity);
  11632. * // => Infinity
  11633. *
  11634. * _.toNumber('3.2');
  11635. * // => 3.2
  11636. */
  11637. function toNumber(value) {
  11638. if (typeof value == 'number') {
  11639. return value;
  11640. }
  11641. if (isSymbol(value)) {
  11642. return NAN;
  11643. }
  11644. if (isObject(value)) {
  11645. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  11646. value = isObject(other) ? (other + '') : other;
  11647. }
  11648. if (typeof value != 'string') {
  11649. return value === 0 ? value : +value;
  11650. }
  11651. value = value.replace(reTrim, '');
  11652. var isBinary = reIsBinary.test(value);
  11653. return (isBinary || reIsOctal.test(value))
  11654. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  11655. : (reIsBadHex.test(value) ? NAN : +value);
  11656. }
  11657. /**
  11658. * Converts `value` to a plain object flattening inherited enumerable string
  11659. * keyed properties of `value` to own properties of the plain object.
  11660. *
  11661. * @static
  11662. * @memberOf _
  11663. * @since 3.0.0
  11664. * @category Lang
  11665. * @param {*} value The value to convert.
  11666. * @returns {Object} Returns the converted plain object.
  11667. * @example
  11668. *
  11669. * function Foo() {
  11670. * this.b = 2;
  11671. * }
  11672. *
  11673. * Foo.prototype.c = 3;
  11674. *
  11675. * _.assign({ 'a': 1 }, new Foo);
  11676. * // => { 'a': 1, 'b': 2 }
  11677. *
  11678. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11679. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11680. */
  11681. function toPlainObject(value) {
  11682. return copyObject(value, keysIn(value));
  11683. }
  11684. /**
  11685. * Converts `value` to a safe integer. A safe integer can be compared and
  11686. * represented correctly.
  11687. *
  11688. * @static
  11689. * @memberOf _
  11690. * @since 4.0.0
  11691. * @category Lang
  11692. * @param {*} value The value to convert.
  11693. * @returns {number} Returns the converted integer.
  11694. * @example
  11695. *
  11696. * _.toSafeInteger(3.2);
  11697. * // => 3
  11698. *
  11699. * _.toSafeInteger(Number.MIN_VALUE);
  11700. * // => 0
  11701. *
  11702. * _.toSafeInteger(Infinity);
  11703. * // => 9007199254740991
  11704. *
  11705. * _.toSafeInteger('3.2');
  11706. * // => 3
  11707. */
  11708. function toSafeInteger(value) {
  11709. return value
  11710. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  11711. : (value === 0 ? value : 0);
  11712. }
  11713. /**
  11714. * Converts `value` to a string. An empty string is returned for `null`
  11715. * and `undefined` values. The sign of `-0` is preserved.
  11716. *
  11717. * @static
  11718. * @memberOf _
  11719. * @since 4.0.0
  11720. * @category Lang
  11721. * @param {*} value The value to convert.
  11722. * @returns {string} Returns the converted string.
  11723. * @example
  11724. *
  11725. * _.toString(null);
  11726. * // => ''
  11727. *
  11728. * _.toString(-0);
  11729. * // => '-0'
  11730. *
  11731. * _.toString([1, 2, 3]);
  11732. * // => '1,2,3'
  11733. */
  11734. function toString(value) {
  11735. return value == null ? '' : baseToString(value);
  11736. }
  11737. /*------------------------------------------------------------------------*/
  11738. /**
  11739. * Assigns own enumerable string keyed properties of source objects to the
  11740. * destination object. Source objects are applied from left to right.
  11741. * Subsequent sources overwrite property assignments of previous sources.
  11742. *
  11743. * **Note:** This method mutates `object` and is loosely based on
  11744. * [`Object.assign`](https://mdn.io/Object/assign).
  11745. *
  11746. * @static
  11747. * @memberOf _
  11748. * @since 0.10.0
  11749. * @category Object
  11750. * @param {Object} object The destination object.
  11751. * @param {...Object} [sources] The source objects.
  11752. * @returns {Object} Returns `object`.
  11753. * @see _.assignIn
  11754. * @example
  11755. *
  11756. * function Foo() {
  11757. * this.a = 1;
  11758. * }
  11759. *
  11760. * function Bar() {
  11761. * this.c = 3;
  11762. * }
  11763. *
  11764. * Foo.prototype.b = 2;
  11765. * Bar.prototype.d = 4;
  11766. *
  11767. * _.assign({ 'a': 0 }, new Foo, new Bar);
  11768. * // => { 'a': 1, 'c': 3 }
  11769. */
  11770. var assign = createAssigner(function(object, source) {
  11771. if (isPrototype(source) || isArrayLike(source)) {
  11772. copyObject(source, keys(source), object);
  11773. return;
  11774. }
  11775. for (var key in source) {
  11776. if (hasOwnProperty.call(source, key)) {
  11777. assignValue(object, key, source[key]);
  11778. }
  11779. }
  11780. });
  11781. /**
  11782. * This method is like `_.assign` except that it iterates over own and
  11783. * inherited source properties.
  11784. *
  11785. * **Note:** This method mutates `object`.
  11786. *
  11787. * @static
  11788. * @memberOf _
  11789. * @since 4.0.0
  11790. * @alias extend
  11791. * @category Object
  11792. * @param {Object} object The destination object.
  11793. * @param {...Object} [sources] The source objects.
  11794. * @returns {Object} Returns `object`.
  11795. * @see _.assign
  11796. * @example
  11797. *
  11798. * function Foo() {
  11799. * this.a = 1;
  11800. * }
  11801. *
  11802. * function Bar() {
  11803. * this.c = 3;
  11804. * }
  11805. *
  11806. * Foo.prototype.b = 2;
  11807. * Bar.prototype.d = 4;
  11808. *
  11809. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  11810. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  11811. */
  11812. var assignIn = createAssigner(function(object, source) {
  11813. copyObject(source, keysIn(source), object);
  11814. });
  11815. /**
  11816. * This method is like `_.assignIn` except that it accepts `customizer`
  11817. * which is invoked to produce the assigned values. If `customizer` returns
  11818. * `undefined`, assignment is handled by the method instead. The `customizer`
  11819. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11820. *
  11821. * **Note:** This method mutates `object`.
  11822. *
  11823. * @static
  11824. * @memberOf _
  11825. * @since 4.0.0
  11826. * @alias extendWith
  11827. * @category Object
  11828. * @param {Object} object The destination object.
  11829. * @param {...Object} sources The source objects.
  11830. * @param {Function} [customizer] The function to customize assigned values.
  11831. * @returns {Object} Returns `object`.
  11832. * @see _.assignWith
  11833. * @example
  11834. *
  11835. * function customizer(objValue, srcValue) {
  11836. * return _.isUndefined(objValue) ? srcValue : objValue;
  11837. * }
  11838. *
  11839. * var defaults = _.partialRight(_.assignInWith, customizer);
  11840. *
  11841. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11842. * // => { 'a': 1, 'b': 2 }
  11843. */
  11844. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  11845. copyObject(source, keysIn(source), object, customizer);
  11846. });
  11847. /**
  11848. * This method is like `_.assign` except that it accepts `customizer`
  11849. * which is invoked to produce the assigned values. If `customizer` returns
  11850. * `undefined`, assignment is handled by the method instead. The `customizer`
  11851. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11852. *
  11853. * **Note:** This method mutates `object`.
  11854. *
  11855. * @static
  11856. * @memberOf _
  11857. * @since 4.0.0
  11858. * @category Object
  11859. * @param {Object} object The destination object.
  11860. * @param {...Object} sources The source objects.
  11861. * @param {Function} [customizer] The function to customize assigned values.
  11862. * @returns {Object} Returns `object`.
  11863. * @see _.assignInWith
  11864. * @example
  11865. *
  11866. * function customizer(objValue, srcValue) {
  11867. * return _.isUndefined(objValue) ? srcValue : objValue;
  11868. * }
  11869. *
  11870. * var defaults = _.partialRight(_.assignWith, customizer);
  11871. *
  11872. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11873. * // => { 'a': 1, 'b': 2 }
  11874. */
  11875. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  11876. copyObject(source, keys(source), object, customizer);
  11877. });
  11878. /**
  11879. * Creates an array of values corresponding to `paths` of `object`.
  11880. *
  11881. * @static
  11882. * @memberOf _
  11883. * @since 1.0.0
  11884. * @category Object
  11885. * @param {Object} object The object to iterate over.
  11886. * @param {...(string|string[])} [paths] The property paths to pick.
  11887. * @returns {Array} Returns the picked values.
  11888. * @example
  11889. *
  11890. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11891. *
  11892. * _.at(object, ['a[0].b.c', 'a[1]']);
  11893. * // => [3, 4]
  11894. */
  11895. var at = flatRest(baseAt);
  11896. /**
  11897. * Creates an object that inherits from the `prototype` object. If a
  11898. * `properties` object is given, its own enumerable string keyed properties
  11899. * are assigned to the created object.
  11900. *
  11901. * @static
  11902. * @memberOf _
  11903. * @since 2.3.0
  11904. * @category Object
  11905. * @param {Object} prototype The object to inherit from.
  11906. * @param {Object} [properties] The properties to assign to the object.
  11907. * @returns {Object} Returns the new object.
  11908. * @example
  11909. *
  11910. * function Shape() {
  11911. * this.x = 0;
  11912. * this.y = 0;
  11913. * }
  11914. *
  11915. * function Circle() {
  11916. * Shape.call(this);
  11917. * }
  11918. *
  11919. * Circle.prototype = _.create(Shape.prototype, {
  11920. * 'constructor': Circle
  11921. * });
  11922. *
  11923. * var circle = new Circle;
  11924. * circle instanceof Circle;
  11925. * // => true
  11926. *
  11927. * circle instanceof Shape;
  11928. * // => true
  11929. */
  11930. function create(prototype, properties) {
  11931. var result = baseCreate(prototype);
  11932. return properties == null ? result : baseAssign(result, properties);
  11933. }
  11934. /**
  11935. * Assigns own and inherited enumerable string keyed properties of source
  11936. * objects to the destination object for all destination properties that
  11937. * resolve to `undefined`. Source objects are applied from left to right.
  11938. * Once a property is set, additional values of the same property are ignored.
  11939. *
  11940. * **Note:** This method mutates `object`.
  11941. *
  11942. * @static
  11943. * @since 0.1.0
  11944. * @memberOf _
  11945. * @category Object
  11946. * @param {Object} object The destination object.
  11947. * @param {...Object} [sources] The source objects.
  11948. * @returns {Object} Returns `object`.
  11949. * @see _.defaultsDeep
  11950. * @example
  11951. *
  11952. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11953. * // => { 'a': 1, 'b': 2 }
  11954. */
  11955. var defaults = baseRest(function(object, sources) {
  11956. object = Object(object);
  11957. var index = -1;
  11958. var length = sources.length;
  11959. var guard = length > 2 ? sources[2] : undefined;
  11960. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  11961. length = 1;
  11962. }
  11963. while (++index < length) {
  11964. var source = sources[index];
  11965. var props = keysIn(source);
  11966. var propsIndex = -1;
  11967. var propsLength = props.length;
  11968. while (++propsIndex < propsLength) {
  11969. var key = props[propsIndex];
  11970. var value = object[key];
  11971. if (value === undefined ||
  11972. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  11973. object[key] = source[key];
  11974. }
  11975. }
  11976. }
  11977. return object;
  11978. });
  11979. /**
  11980. * This method is like `_.defaults` except that it recursively assigns
  11981. * default properties.
  11982. *
  11983. * **Note:** This method mutates `object`.
  11984. *
  11985. * @static
  11986. * @memberOf _
  11987. * @since 3.10.0
  11988. * @category Object
  11989. * @param {Object} object The destination object.
  11990. * @param {...Object} [sources] The source objects.
  11991. * @returns {Object} Returns `object`.
  11992. * @see _.defaults
  11993. * @example
  11994. *
  11995. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  11996. * // => { 'a': { 'b': 2, 'c': 3 } }
  11997. */
  11998. var defaultsDeep = baseRest(function(args) {
  11999. args.push(undefined, customDefaultsMerge);
  12000. return apply(mergeWith, undefined, args);
  12001. });
  12002. /**
  12003. * This method is like `_.find` except that it returns the key of the first
  12004. * element `predicate` returns truthy for instead of the element itself.
  12005. *
  12006. * @static
  12007. * @memberOf _
  12008. * @since 1.1.0
  12009. * @category Object
  12010. * @param {Object} object The object to inspect.
  12011. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12012. * @returns {string|undefined} Returns the key of the matched element,
  12013. * else `undefined`.
  12014. * @example
  12015. *
  12016. * var users = {
  12017. * 'barney': { 'age': 36, 'active': true },
  12018. * 'fred': { 'age': 40, 'active': false },
  12019. * 'pebbles': { 'age': 1, 'active': true }
  12020. * };
  12021. *
  12022. * _.findKey(users, function(o) { return o.age < 40; });
  12023. * // => 'barney' (iteration order is not guaranteed)
  12024. *
  12025. * // The `_.matches` iteratee shorthand.
  12026. * _.findKey(users, { 'age': 1, 'active': true });
  12027. * // => 'pebbles'
  12028. *
  12029. * // The `_.matchesProperty` iteratee shorthand.
  12030. * _.findKey(users, ['active', false]);
  12031. * // => 'fred'
  12032. *
  12033. * // The `_.property` iteratee shorthand.
  12034. * _.findKey(users, 'active');
  12035. * // => 'barney'
  12036. */
  12037. function findKey(object, predicate) {
  12038. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  12039. }
  12040. /**
  12041. * This method is like `_.findKey` except that it iterates over elements of
  12042. * a collection in the opposite order.
  12043. *
  12044. * @static
  12045. * @memberOf _
  12046. * @since 2.0.0
  12047. * @category Object
  12048. * @param {Object} object The object to inspect.
  12049. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12050. * @returns {string|undefined} Returns the key of the matched element,
  12051. * else `undefined`.
  12052. * @example
  12053. *
  12054. * var users = {
  12055. * 'barney': { 'age': 36, 'active': true },
  12056. * 'fred': { 'age': 40, 'active': false },
  12057. * 'pebbles': { 'age': 1, 'active': true }
  12058. * };
  12059. *
  12060. * _.findLastKey(users, function(o) { return o.age < 40; });
  12061. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  12062. *
  12063. * // The `_.matches` iteratee shorthand.
  12064. * _.findLastKey(users, { 'age': 36, 'active': true });
  12065. * // => 'barney'
  12066. *
  12067. * // The `_.matchesProperty` iteratee shorthand.
  12068. * _.findLastKey(users, ['active', false]);
  12069. * // => 'fred'
  12070. *
  12071. * // The `_.property` iteratee shorthand.
  12072. * _.findLastKey(users, 'active');
  12073. * // => 'pebbles'
  12074. */
  12075. function findLastKey(object, predicate) {
  12076. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  12077. }
  12078. /**
  12079. * Iterates over own and inherited enumerable string keyed properties of an
  12080. * object and invokes `iteratee` for each property. The iteratee is invoked
  12081. * with three arguments: (value, key, object). Iteratee functions may exit
  12082. * iteration early by explicitly returning `false`.
  12083. *
  12084. * @static
  12085. * @memberOf _
  12086. * @since 0.3.0
  12087. * @category Object
  12088. * @param {Object} object The object to iterate over.
  12089. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12090. * @returns {Object} Returns `object`.
  12091. * @see _.forInRight
  12092. * @example
  12093. *
  12094. * function Foo() {
  12095. * this.a = 1;
  12096. * this.b = 2;
  12097. * }
  12098. *
  12099. * Foo.prototype.c = 3;
  12100. *
  12101. * _.forIn(new Foo, function(value, key) {
  12102. * console.log(key);
  12103. * });
  12104. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  12105. */
  12106. function forIn(object, iteratee) {
  12107. return object == null
  12108. ? object
  12109. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  12110. }
  12111. /**
  12112. * This method is like `_.forIn` except that it iterates over properties of
  12113. * `object` in the opposite order.
  12114. *
  12115. * @static
  12116. * @memberOf _
  12117. * @since 2.0.0
  12118. * @category Object
  12119. * @param {Object} object The object to iterate over.
  12120. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12121. * @returns {Object} Returns `object`.
  12122. * @see _.forIn
  12123. * @example
  12124. *
  12125. * function Foo() {
  12126. * this.a = 1;
  12127. * this.b = 2;
  12128. * }
  12129. *
  12130. * Foo.prototype.c = 3;
  12131. *
  12132. * _.forInRight(new Foo, function(value, key) {
  12133. * console.log(key);
  12134. * });
  12135. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  12136. */
  12137. function forInRight(object, iteratee) {
  12138. return object == null
  12139. ? object
  12140. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  12141. }
  12142. /**
  12143. * Iterates over own enumerable string keyed properties of an object and
  12144. * invokes `iteratee` for each property. The iteratee is invoked with three
  12145. * arguments: (value, key, object). Iteratee functions may exit iteration
  12146. * early by explicitly returning `false`.
  12147. *
  12148. * @static
  12149. * @memberOf _
  12150. * @since 0.3.0
  12151. * @category Object
  12152. * @param {Object} object The object to iterate over.
  12153. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12154. * @returns {Object} Returns `object`.
  12155. * @see _.forOwnRight
  12156. * @example
  12157. *
  12158. * function Foo() {
  12159. * this.a = 1;
  12160. * this.b = 2;
  12161. * }
  12162. *
  12163. * Foo.prototype.c = 3;
  12164. *
  12165. * _.forOwn(new Foo, function(value, key) {
  12166. * console.log(key);
  12167. * });
  12168. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  12169. */
  12170. function forOwn(object, iteratee) {
  12171. return object && baseForOwn(object, getIteratee(iteratee, 3));
  12172. }
  12173. /**
  12174. * This method is like `_.forOwn` except that it iterates over properties of
  12175. * `object` in the opposite order.
  12176. *
  12177. * @static
  12178. * @memberOf _
  12179. * @since 2.0.0
  12180. * @category Object
  12181. * @param {Object} object The object to iterate over.
  12182. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12183. * @returns {Object} Returns `object`.
  12184. * @see _.forOwn
  12185. * @example
  12186. *
  12187. * function Foo() {
  12188. * this.a = 1;
  12189. * this.b = 2;
  12190. * }
  12191. *
  12192. * Foo.prototype.c = 3;
  12193. *
  12194. * _.forOwnRight(new Foo, function(value, key) {
  12195. * console.log(key);
  12196. * });
  12197. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  12198. */
  12199. function forOwnRight(object, iteratee) {
  12200. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  12201. }
  12202. /**
  12203. * Creates an array of function property names from own enumerable properties
  12204. * of `object`.
  12205. *
  12206. * @static
  12207. * @since 0.1.0
  12208. * @memberOf _
  12209. * @category Object
  12210. * @param {Object} object The object to inspect.
  12211. * @returns {Array} Returns the function names.
  12212. * @see _.functionsIn
  12213. * @example
  12214. *
  12215. * function Foo() {
  12216. * this.a = _.constant('a');
  12217. * this.b = _.constant('b');
  12218. * }
  12219. *
  12220. * Foo.prototype.c = _.constant('c');
  12221. *
  12222. * _.functions(new Foo);
  12223. * // => ['a', 'b']
  12224. */
  12225. function functions(object) {
  12226. return object == null ? [] : baseFunctions(object, keys(object));
  12227. }
  12228. /**
  12229. * Creates an array of function property names from own and inherited
  12230. * enumerable properties of `object`.
  12231. *
  12232. * @static
  12233. * @memberOf _
  12234. * @since 4.0.0
  12235. * @category Object
  12236. * @param {Object} object The object to inspect.
  12237. * @returns {Array} Returns the function names.
  12238. * @see _.functions
  12239. * @example
  12240. *
  12241. * function Foo() {
  12242. * this.a = _.constant('a');
  12243. * this.b = _.constant('b');
  12244. * }
  12245. *
  12246. * Foo.prototype.c = _.constant('c');
  12247. *
  12248. * _.functionsIn(new Foo);
  12249. * // => ['a', 'b', 'c']
  12250. */
  12251. function functionsIn(object) {
  12252. return object == null ? [] : baseFunctions(object, keysIn(object));
  12253. }
  12254. /**
  12255. * Gets the value at `path` of `object`. If the resolved value is
  12256. * `undefined`, the `defaultValue` is returned in its place.
  12257. *
  12258. * @static
  12259. * @memberOf _
  12260. * @since 3.7.0
  12261. * @category Object
  12262. * @param {Object} object The object to query.
  12263. * @param {Array|string} path The path of the property to get.
  12264. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12265. * @returns {*} Returns the resolved value.
  12266. * @example
  12267. *
  12268. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12269. *
  12270. * _.get(object, 'a[0].b.c');
  12271. * // => 3
  12272. *
  12273. * _.get(object, ['a', '0', 'b', 'c']);
  12274. * // => 3
  12275. *
  12276. * _.get(object, 'a.b.c', 'default');
  12277. * // => 'default'
  12278. */
  12279. function get(object, path, defaultValue) {
  12280. var result = object == null ? undefined : baseGet(object, path);
  12281. return result === undefined ? defaultValue : result;
  12282. }
  12283. /**
  12284. * Checks if `path` is a direct property of `object`.
  12285. *
  12286. * @static
  12287. * @since 0.1.0
  12288. * @memberOf _
  12289. * @category Object
  12290. * @param {Object} object The object to query.
  12291. * @param {Array|string} path The path to check.
  12292. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12293. * @example
  12294. *
  12295. * var object = { 'a': { 'b': 2 } };
  12296. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  12297. *
  12298. * _.has(object, 'a');
  12299. * // => true
  12300. *
  12301. * _.has(object, 'a.b');
  12302. * // => true
  12303. *
  12304. * _.has(object, ['a', 'b']);
  12305. * // => true
  12306. *
  12307. * _.has(other, 'a');
  12308. * // => false
  12309. */
  12310. function has(object, path) {
  12311. return object != null && hasPath(object, path, baseHas);
  12312. }
  12313. /**
  12314. * Checks if `path` is a direct or inherited property of `object`.
  12315. *
  12316. * @static
  12317. * @memberOf _
  12318. * @since 4.0.0
  12319. * @category Object
  12320. * @param {Object} object The object to query.
  12321. * @param {Array|string} path The path to check.
  12322. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12323. * @example
  12324. *
  12325. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  12326. *
  12327. * _.hasIn(object, 'a');
  12328. * // => true
  12329. *
  12330. * _.hasIn(object, 'a.b');
  12331. * // => true
  12332. *
  12333. * _.hasIn(object, ['a', 'b']);
  12334. * // => true
  12335. *
  12336. * _.hasIn(object, 'b');
  12337. * // => false
  12338. */
  12339. function hasIn(object, path) {
  12340. return object != null && hasPath(object, path, baseHasIn);
  12341. }
  12342. /**
  12343. * Creates an object composed of the inverted keys and values of `object`.
  12344. * If `object` contains duplicate values, subsequent values overwrite
  12345. * property assignments of previous values.
  12346. *
  12347. * @static
  12348. * @memberOf _
  12349. * @since 0.7.0
  12350. * @category Object
  12351. * @param {Object} object The object to invert.
  12352. * @returns {Object} Returns the new inverted object.
  12353. * @example
  12354. *
  12355. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12356. *
  12357. * _.invert(object);
  12358. * // => { '1': 'c', '2': 'b' }
  12359. */
  12360. var invert = createInverter(function(result, value, key) {
  12361. if (value != null &&
  12362. typeof value.toString != 'function') {
  12363. value = nativeObjectToString.call(value);
  12364. }
  12365. result[value] = key;
  12366. }, constant(identity));
  12367. /**
  12368. * This method is like `_.invert` except that the inverted object is generated
  12369. * from the results of running each element of `object` thru `iteratee`. The
  12370. * corresponding inverted value of each inverted key is an array of keys
  12371. * responsible for generating the inverted value. The iteratee is invoked
  12372. * with one argument: (value).
  12373. *
  12374. * @static
  12375. * @memberOf _
  12376. * @since 4.1.0
  12377. * @category Object
  12378. * @param {Object} object The object to invert.
  12379. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  12380. * @returns {Object} Returns the new inverted object.
  12381. * @example
  12382. *
  12383. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12384. *
  12385. * _.invertBy(object);
  12386. * // => { '1': ['a', 'c'], '2': ['b'] }
  12387. *
  12388. * _.invertBy(object, function(value) {
  12389. * return 'group' + value;
  12390. * });
  12391. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  12392. */
  12393. var invertBy = createInverter(function(result, value, key) {
  12394. if (value != null &&
  12395. typeof value.toString != 'function') {
  12396. value = nativeObjectToString.call(value);
  12397. }
  12398. if (hasOwnProperty.call(result, value)) {
  12399. result[value].push(key);
  12400. } else {
  12401. result[value] = [key];
  12402. }
  12403. }, getIteratee);
  12404. /**
  12405. * Invokes the method at `path` of `object`.
  12406. *
  12407. * @static
  12408. * @memberOf _
  12409. * @since 4.0.0
  12410. * @category Object
  12411. * @param {Object} object The object to query.
  12412. * @param {Array|string} path The path of the method to invoke.
  12413. * @param {...*} [args] The arguments to invoke the method with.
  12414. * @returns {*} Returns the result of the invoked method.
  12415. * @example
  12416. *
  12417. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  12418. *
  12419. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  12420. * // => [2, 3]
  12421. */
  12422. var invoke = baseRest(baseInvoke);
  12423. /**
  12424. * Creates an array of the own enumerable property names of `object`.
  12425. *
  12426. * **Note:** Non-object values are coerced to objects. See the
  12427. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  12428. * for more details.
  12429. *
  12430. * @static
  12431. * @since 0.1.0
  12432. * @memberOf _
  12433. * @category Object
  12434. * @param {Object} object The object to query.
  12435. * @returns {Array} Returns the array of property names.
  12436. * @example
  12437. *
  12438. * function Foo() {
  12439. * this.a = 1;
  12440. * this.b = 2;
  12441. * }
  12442. *
  12443. * Foo.prototype.c = 3;
  12444. *
  12445. * _.keys(new Foo);
  12446. * // => ['a', 'b'] (iteration order is not guaranteed)
  12447. *
  12448. * _.keys('hi');
  12449. * // => ['0', '1']
  12450. */
  12451. function keys(object) {
  12452. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  12453. }
  12454. /**
  12455. * Creates an array of the own and inherited enumerable property names of `object`.
  12456. *
  12457. * **Note:** Non-object values are coerced to objects.
  12458. *
  12459. * @static
  12460. * @memberOf _
  12461. * @since 3.0.0
  12462. * @category Object
  12463. * @param {Object} object The object to query.
  12464. * @returns {Array} Returns the array of property names.
  12465. * @example
  12466. *
  12467. * function Foo() {
  12468. * this.a = 1;
  12469. * this.b = 2;
  12470. * }
  12471. *
  12472. * Foo.prototype.c = 3;
  12473. *
  12474. * _.keysIn(new Foo);
  12475. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  12476. */
  12477. function keysIn(object) {
  12478. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  12479. }
  12480. /**
  12481. * The opposite of `_.mapValues`; this method creates an object with the
  12482. * same values as `object` and keys generated by running each own enumerable
  12483. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  12484. * with three arguments: (value, key, object).
  12485. *
  12486. * @static
  12487. * @memberOf _
  12488. * @since 3.8.0
  12489. * @category Object
  12490. * @param {Object} object The object to iterate over.
  12491. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12492. * @returns {Object} Returns the new mapped object.
  12493. * @see _.mapValues
  12494. * @example
  12495. *
  12496. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  12497. * return key + value;
  12498. * });
  12499. * // => { 'a1': 1, 'b2': 2 }
  12500. */
  12501. function mapKeys(object, iteratee) {
  12502. var result = {};
  12503. iteratee = getIteratee(iteratee, 3);
  12504. baseForOwn(object, function(value, key, object) {
  12505. baseAssignValue(result, iteratee(value, key, object), value);
  12506. });
  12507. return result;
  12508. }
  12509. /**
  12510. * Creates an object with the same keys as `object` and values generated
  12511. * by running each own enumerable string keyed property of `object` thru
  12512. * `iteratee`. The iteratee is invoked with three arguments:
  12513. * (value, key, object).
  12514. *
  12515. * @static
  12516. * @memberOf _
  12517. * @since 2.4.0
  12518. * @category Object
  12519. * @param {Object} object The object to iterate over.
  12520. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12521. * @returns {Object} Returns the new mapped object.
  12522. * @see _.mapKeys
  12523. * @example
  12524. *
  12525. * var users = {
  12526. * 'fred': { 'user': 'fred', 'age': 40 },
  12527. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  12528. * };
  12529. *
  12530. * _.mapValues(users, function(o) { return o.age; });
  12531. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12532. *
  12533. * // The `_.property` iteratee shorthand.
  12534. * _.mapValues(users, 'age');
  12535. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12536. */
  12537. function mapValues(object, iteratee) {
  12538. var result = {};
  12539. iteratee = getIteratee(iteratee, 3);
  12540. baseForOwn(object, function(value, key, object) {
  12541. baseAssignValue(result, key, iteratee(value, key, object));
  12542. });
  12543. return result;
  12544. }
  12545. /**
  12546. * This method is like `_.assign` except that it recursively merges own and
  12547. * inherited enumerable string keyed properties of source objects into the
  12548. * destination object. Source properties that resolve to `undefined` are
  12549. * skipped if a destination value exists. Array and plain object properties
  12550. * are merged recursively. Other objects and value types are overridden by
  12551. * assignment. Source objects are applied from left to right. Subsequent
  12552. * sources overwrite property assignments of previous sources.
  12553. *
  12554. * **Note:** This method mutates `object`.
  12555. *
  12556. * @static
  12557. * @memberOf _
  12558. * @since 0.5.0
  12559. * @category Object
  12560. * @param {Object} object The destination object.
  12561. * @param {...Object} [sources] The source objects.
  12562. * @returns {Object} Returns `object`.
  12563. * @example
  12564. *
  12565. * var object = {
  12566. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  12567. * };
  12568. *
  12569. * var other = {
  12570. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  12571. * };
  12572. *
  12573. * _.merge(object, other);
  12574. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  12575. */
  12576. var merge = createAssigner(function(object, source, srcIndex) {
  12577. baseMerge(object, source, srcIndex);
  12578. });
  12579. /**
  12580. * This method is like `_.merge` except that it accepts `customizer` which
  12581. * is invoked to produce the merged values of the destination and source
  12582. * properties. If `customizer` returns `undefined`, merging is handled by the
  12583. * method instead. The `customizer` is invoked with six arguments:
  12584. * (objValue, srcValue, key, object, source, stack).
  12585. *
  12586. * **Note:** This method mutates `object`.
  12587. *
  12588. * @static
  12589. * @memberOf _
  12590. * @since 4.0.0
  12591. * @category Object
  12592. * @param {Object} object The destination object.
  12593. * @param {...Object} sources The source objects.
  12594. * @param {Function} customizer The function to customize assigned values.
  12595. * @returns {Object} Returns `object`.
  12596. * @example
  12597. *
  12598. * function customizer(objValue, srcValue) {
  12599. * if (_.isArray(objValue)) {
  12600. * return objValue.concat(srcValue);
  12601. * }
  12602. * }
  12603. *
  12604. * var object = { 'a': [1], 'b': [2] };
  12605. * var other = { 'a': [3], 'b': [4] };
  12606. *
  12607. * _.mergeWith(object, other, customizer);
  12608. * // => { 'a': [1, 3], 'b': [2, 4] }
  12609. */
  12610. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  12611. baseMerge(object, source, srcIndex, customizer);
  12612. });
  12613. /**
  12614. * The opposite of `_.pick`; this method creates an object composed of the
  12615. * own and inherited enumerable property paths of `object` that are not omitted.
  12616. *
  12617. * **Note:** This method is considerably slower than `_.pick`.
  12618. *
  12619. * @static
  12620. * @since 0.1.0
  12621. * @memberOf _
  12622. * @category Object
  12623. * @param {Object} object The source object.
  12624. * @param {...(string|string[])} [paths] The property paths to omit.
  12625. * @returns {Object} Returns the new object.
  12626. * @example
  12627. *
  12628. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12629. *
  12630. * _.omit(object, ['a', 'c']);
  12631. * // => { 'b': '2' }
  12632. */
  12633. var omit = flatRest(function(object, paths) {
  12634. var result = {};
  12635. if (object == null) {
  12636. return result;
  12637. }
  12638. var isDeep = false;
  12639. paths = arrayMap(paths, function(path) {
  12640. path = castPath(path, object);
  12641. isDeep || (isDeep = path.length > 1);
  12642. return path;
  12643. });
  12644. copyObject(object, getAllKeysIn(object), result);
  12645. if (isDeep) {
  12646. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  12647. }
  12648. var length = paths.length;
  12649. while (length--) {
  12650. baseUnset(result, paths[length]);
  12651. }
  12652. return result;
  12653. });
  12654. /**
  12655. * The opposite of `_.pickBy`; this method creates an object composed of
  12656. * the own and inherited enumerable string keyed properties of `object` that
  12657. * `predicate` doesn't return truthy for. The predicate is invoked with two
  12658. * arguments: (value, key).
  12659. *
  12660. * @static
  12661. * @memberOf _
  12662. * @since 4.0.0
  12663. * @category Object
  12664. * @param {Object} object The source object.
  12665. * @param {Function} [predicate=_.identity] The function invoked per property.
  12666. * @returns {Object} Returns the new object.
  12667. * @example
  12668. *
  12669. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12670. *
  12671. * _.omitBy(object, _.isNumber);
  12672. * // => { 'b': '2' }
  12673. */
  12674. function omitBy(object, predicate) {
  12675. return pickBy(object, negate(getIteratee(predicate)));
  12676. }
  12677. /**
  12678. * Creates an object composed of the picked `object` properties.
  12679. *
  12680. * @static
  12681. * @since 0.1.0
  12682. * @memberOf _
  12683. * @category Object
  12684. * @param {Object} object The source object.
  12685. * @param {...(string|string[])} [paths] The property paths to pick.
  12686. * @returns {Object} Returns the new object.
  12687. * @example
  12688. *
  12689. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12690. *
  12691. * _.pick(object, ['a', 'c']);
  12692. * // => { 'a': 1, 'c': 3 }
  12693. */
  12694. var pick = flatRest(function(object, paths) {
  12695. return object == null ? {} : basePick(object, paths);
  12696. });
  12697. /**
  12698. * Creates an object composed of the `object` properties `predicate` returns
  12699. * truthy for. The predicate is invoked with two arguments: (value, key).
  12700. *
  12701. * @static
  12702. * @memberOf _
  12703. * @since 4.0.0
  12704. * @category Object
  12705. * @param {Object} object The source object.
  12706. * @param {Function} [predicate=_.identity] The function invoked per property.
  12707. * @returns {Object} Returns the new object.
  12708. * @example
  12709. *
  12710. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12711. *
  12712. * _.pickBy(object, _.isNumber);
  12713. * // => { 'a': 1, 'c': 3 }
  12714. */
  12715. function pickBy(object, predicate) {
  12716. if (object == null) {
  12717. return {};
  12718. }
  12719. var props = arrayMap(getAllKeysIn(object), function(prop) {
  12720. return [prop];
  12721. });
  12722. predicate = getIteratee(predicate);
  12723. return basePickBy(object, props, function(value, path) {
  12724. return predicate(value, path[0]);
  12725. });
  12726. }
  12727. /**
  12728. * This method is like `_.get` except that if the resolved value is a
  12729. * function it's invoked with the `this` binding of its parent object and
  12730. * its result is returned.
  12731. *
  12732. * @static
  12733. * @since 0.1.0
  12734. * @memberOf _
  12735. * @category Object
  12736. * @param {Object} object The object to query.
  12737. * @param {Array|string} path The path of the property to resolve.
  12738. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12739. * @returns {*} Returns the resolved value.
  12740. * @example
  12741. *
  12742. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  12743. *
  12744. * _.result(object, 'a[0].b.c1');
  12745. * // => 3
  12746. *
  12747. * _.result(object, 'a[0].b.c2');
  12748. * // => 4
  12749. *
  12750. * _.result(object, 'a[0].b.c3', 'default');
  12751. * // => 'default'
  12752. *
  12753. * _.result(object, 'a[0].b.c3', _.constant('default'));
  12754. * // => 'default'
  12755. */
  12756. function result(object, path, defaultValue) {
  12757. path = castPath(path, object);
  12758. var index = -1,
  12759. length = path.length;
  12760. // Ensure the loop is entered when path is empty.
  12761. if (!length) {
  12762. length = 1;
  12763. object = undefined;
  12764. }
  12765. while (++index < length) {
  12766. var value = object == null ? undefined : object[toKey(path[index])];
  12767. if (value === undefined) {
  12768. index = length;
  12769. value = defaultValue;
  12770. }
  12771. object = isFunction(value) ? value.call(object) : value;
  12772. }
  12773. return object;
  12774. }
  12775. /**
  12776. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  12777. * it's created. Arrays are created for missing index properties while objects
  12778. * are created for all other missing properties. Use `_.setWith` to customize
  12779. * `path` creation.
  12780. *
  12781. * **Note:** This method mutates `object`.
  12782. *
  12783. * @static
  12784. * @memberOf _
  12785. * @since 3.7.0
  12786. * @category Object
  12787. * @param {Object} object The object to modify.
  12788. * @param {Array|string} path The path of the property to set.
  12789. * @param {*} value The value to set.
  12790. * @returns {Object} Returns `object`.
  12791. * @example
  12792. *
  12793. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12794. *
  12795. * _.set(object, 'a[0].b.c', 4);
  12796. * console.log(object.a[0].b.c);
  12797. * // => 4
  12798. *
  12799. * _.set(object, ['x', '0', 'y', 'z'], 5);
  12800. * console.log(object.x[0].y.z);
  12801. * // => 5
  12802. */
  12803. function set(object, path, value) {
  12804. return object == null ? object : baseSet(object, path, value);
  12805. }
  12806. /**
  12807. * This method is like `_.set` except that it accepts `customizer` which is
  12808. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12809. * path creation is handled by the method instead. The `customizer` is invoked
  12810. * with three arguments: (nsValue, key, nsObject).
  12811. *
  12812. * **Note:** This method mutates `object`.
  12813. *
  12814. * @static
  12815. * @memberOf _
  12816. * @since 4.0.0
  12817. * @category Object
  12818. * @param {Object} object The object to modify.
  12819. * @param {Array|string} path The path of the property to set.
  12820. * @param {*} value The value to set.
  12821. * @param {Function} [customizer] The function to customize assigned values.
  12822. * @returns {Object} Returns `object`.
  12823. * @example
  12824. *
  12825. * var object = {};
  12826. *
  12827. * _.setWith(object, '[0][1]', 'a', Object);
  12828. * // => { '0': { '1': 'a' } }
  12829. */
  12830. function setWith(object, path, value, customizer) {
  12831. customizer = typeof customizer == 'function' ? customizer : undefined;
  12832. return object == null ? object : baseSet(object, path, value, customizer);
  12833. }
  12834. /**
  12835. * Creates an array of own enumerable string keyed-value pairs for `object`
  12836. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  12837. * entries are returned.
  12838. *
  12839. * @static
  12840. * @memberOf _
  12841. * @since 4.0.0
  12842. * @alias entries
  12843. * @category Object
  12844. * @param {Object} object The object to query.
  12845. * @returns {Array} Returns the key-value pairs.
  12846. * @example
  12847. *
  12848. * function Foo() {
  12849. * this.a = 1;
  12850. * this.b = 2;
  12851. * }
  12852. *
  12853. * Foo.prototype.c = 3;
  12854. *
  12855. * _.toPairs(new Foo);
  12856. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  12857. */
  12858. var toPairs = createToPairs(keys);
  12859. /**
  12860. * Creates an array of own and inherited enumerable string keyed-value pairs
  12861. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  12862. * or set, its entries are returned.
  12863. *
  12864. * @static
  12865. * @memberOf _
  12866. * @since 4.0.0
  12867. * @alias entriesIn
  12868. * @category Object
  12869. * @param {Object} object The object to query.
  12870. * @returns {Array} Returns the key-value pairs.
  12871. * @example
  12872. *
  12873. * function Foo() {
  12874. * this.a = 1;
  12875. * this.b = 2;
  12876. * }
  12877. *
  12878. * Foo.prototype.c = 3;
  12879. *
  12880. * _.toPairsIn(new Foo);
  12881. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  12882. */
  12883. var toPairsIn = createToPairs(keysIn);
  12884. /**
  12885. * An alternative to `_.reduce`; this method transforms `object` to a new
  12886. * `accumulator` object which is the result of running each of its own
  12887. * enumerable string keyed properties thru `iteratee`, with each invocation
  12888. * potentially mutating the `accumulator` object. If `accumulator` is not
  12889. * provided, a new object with the same `[[Prototype]]` will be used. The
  12890. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  12891. * Iteratee functions may exit iteration early by explicitly returning `false`.
  12892. *
  12893. * @static
  12894. * @memberOf _
  12895. * @since 1.3.0
  12896. * @category Object
  12897. * @param {Object} object The object to iterate over.
  12898. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12899. * @param {*} [accumulator] The custom accumulator value.
  12900. * @returns {*} Returns the accumulated value.
  12901. * @example
  12902. *
  12903. * _.transform([2, 3, 4], function(result, n) {
  12904. * result.push(n *= n);
  12905. * return n % 2 == 0;
  12906. * }, []);
  12907. * // => [4, 9]
  12908. *
  12909. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12910. * (result[value] || (result[value] = [])).push(key);
  12911. * }, {});
  12912. * // => { '1': ['a', 'c'], '2': ['b'] }
  12913. */
  12914. function transform(object, iteratee, accumulator) {
  12915. var isArr = isArray(object),
  12916. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  12917. iteratee = getIteratee(iteratee, 4);
  12918. if (accumulator == null) {
  12919. var Ctor = object && object.constructor;
  12920. if (isArrLike) {
  12921. accumulator = isArr ? new Ctor : [];
  12922. }
  12923. else if (isObject(object)) {
  12924. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  12925. }
  12926. else {
  12927. accumulator = {};
  12928. }
  12929. }
  12930. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  12931. return iteratee(accumulator, value, index, object);
  12932. });
  12933. return accumulator;
  12934. }
  12935. /**
  12936. * Removes the property at `path` of `object`.
  12937. *
  12938. * **Note:** This method mutates `object`.
  12939. *
  12940. * @static
  12941. * @memberOf _
  12942. * @since 4.0.0
  12943. * @category Object
  12944. * @param {Object} object The object to modify.
  12945. * @param {Array|string} path The path of the property to unset.
  12946. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  12947. * @example
  12948. *
  12949. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  12950. * _.unset(object, 'a[0].b.c');
  12951. * // => true
  12952. *
  12953. * console.log(object);
  12954. * // => { 'a': [{ 'b': {} }] };
  12955. *
  12956. * _.unset(object, ['a', '0', 'b', 'c']);
  12957. * // => true
  12958. *
  12959. * console.log(object);
  12960. * // => { 'a': [{ 'b': {} }] };
  12961. */
  12962. function unset(object, path) {
  12963. return object == null ? true : baseUnset(object, path);
  12964. }
  12965. /**
  12966. * This method is like `_.set` except that accepts `updater` to produce the
  12967. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  12968. * is invoked with one argument: (value).
  12969. *
  12970. * **Note:** This method mutates `object`.
  12971. *
  12972. * @static
  12973. * @memberOf _
  12974. * @since 4.6.0
  12975. * @category Object
  12976. * @param {Object} object The object to modify.
  12977. * @param {Array|string} path The path of the property to set.
  12978. * @param {Function} updater The function to produce the updated value.
  12979. * @returns {Object} Returns `object`.
  12980. * @example
  12981. *
  12982. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12983. *
  12984. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  12985. * console.log(object.a[0].b.c);
  12986. * // => 9
  12987. *
  12988. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  12989. * console.log(object.x[0].y.z);
  12990. * // => 0
  12991. */
  12992. function update(object, path, updater) {
  12993. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  12994. }
  12995. /**
  12996. * This method is like `_.update` except that it accepts `customizer` which is
  12997. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12998. * path creation is handled by the method instead. The `customizer` is invoked
  12999. * with three arguments: (nsValue, key, nsObject).
  13000. *
  13001. * **Note:** This method mutates `object`.
  13002. *
  13003. * @static
  13004. * @memberOf _
  13005. * @since 4.6.0
  13006. * @category Object
  13007. * @param {Object} object The object to modify.
  13008. * @param {Array|string} path The path of the property to set.
  13009. * @param {Function} updater The function to produce the updated value.
  13010. * @param {Function} [customizer] The function to customize assigned values.
  13011. * @returns {Object} Returns `object`.
  13012. * @example
  13013. *
  13014. * var object = {};
  13015. *
  13016. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  13017. * // => { '0': { '1': 'a' } }
  13018. */
  13019. function updateWith(object, path, updater, customizer) {
  13020. customizer = typeof customizer == 'function' ? customizer : undefined;
  13021. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  13022. }
  13023. /**
  13024. * Creates an array of the own enumerable string keyed property values of `object`.
  13025. *
  13026. * **Note:** Non-object values are coerced to objects.
  13027. *
  13028. * @static
  13029. * @since 0.1.0
  13030. * @memberOf _
  13031. * @category Object
  13032. * @param {Object} object The object to query.
  13033. * @returns {Array} Returns the array of property values.
  13034. * @example
  13035. *
  13036. * function Foo() {
  13037. * this.a = 1;
  13038. * this.b = 2;
  13039. * }
  13040. *
  13041. * Foo.prototype.c = 3;
  13042. *
  13043. * _.values(new Foo);
  13044. * // => [1, 2] (iteration order is not guaranteed)
  13045. *
  13046. * _.values('hi');
  13047. * // => ['h', 'i']
  13048. */
  13049. function values(object) {
  13050. return object == null ? [] : baseValues(object, keys(object));
  13051. }
  13052. /**
  13053. * Creates an array of the own and inherited enumerable string keyed property
  13054. * values of `object`.
  13055. *
  13056. * **Note:** Non-object values are coerced to objects.
  13057. *
  13058. * @static
  13059. * @memberOf _
  13060. * @since 3.0.0
  13061. * @category Object
  13062. * @param {Object} object The object to query.
  13063. * @returns {Array} Returns the array of property values.
  13064. * @example
  13065. *
  13066. * function Foo() {
  13067. * this.a = 1;
  13068. * this.b = 2;
  13069. * }
  13070. *
  13071. * Foo.prototype.c = 3;
  13072. *
  13073. * _.valuesIn(new Foo);
  13074. * // => [1, 2, 3] (iteration order is not guaranteed)
  13075. */
  13076. function valuesIn(object) {
  13077. return object == null ? [] : baseValues(object, keysIn(object));
  13078. }
  13079. /*------------------------------------------------------------------------*/
  13080. /**
  13081. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  13082. *
  13083. * @static
  13084. * @memberOf _
  13085. * @since 4.0.0
  13086. * @category Number
  13087. * @param {number} number The number to clamp.
  13088. * @param {number} [lower] The lower bound.
  13089. * @param {number} upper The upper bound.
  13090. * @returns {number} Returns the clamped number.
  13091. * @example
  13092. *
  13093. * _.clamp(-10, -5, 5);
  13094. * // => -5
  13095. *
  13096. * _.clamp(10, -5, 5);
  13097. * // => 5
  13098. */
  13099. function clamp(number, lower, upper) {
  13100. if (upper === undefined) {
  13101. upper = lower;
  13102. lower = undefined;
  13103. }
  13104. if (upper !== undefined) {
  13105. upper = toNumber(upper);
  13106. upper = upper === upper ? upper : 0;
  13107. }
  13108. if (lower !== undefined) {
  13109. lower = toNumber(lower);
  13110. lower = lower === lower ? lower : 0;
  13111. }
  13112. return baseClamp(toNumber(number), lower, upper);
  13113. }
  13114. /**
  13115. * Checks if `n` is between `start` and up to, but not including, `end`. If
  13116. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  13117. * If `start` is greater than `end` the params are swapped to support
  13118. * negative ranges.
  13119. *
  13120. * @static
  13121. * @memberOf _
  13122. * @since 3.3.0
  13123. * @category Number
  13124. * @param {number} number The number to check.
  13125. * @param {number} [start=0] The start of the range.
  13126. * @param {number} end The end of the range.
  13127. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  13128. * @see _.range, _.rangeRight
  13129. * @example
  13130. *
  13131. * _.inRange(3, 2, 4);
  13132. * // => true
  13133. *
  13134. * _.inRange(4, 8);
  13135. * // => true
  13136. *
  13137. * _.inRange(4, 2);
  13138. * // => false
  13139. *
  13140. * _.inRange(2, 2);
  13141. * // => false
  13142. *
  13143. * _.inRange(1.2, 2);
  13144. * // => true
  13145. *
  13146. * _.inRange(5.2, 4);
  13147. * // => false
  13148. *
  13149. * _.inRange(-3, -2, -6);
  13150. * // => true
  13151. */
  13152. function inRange(number, start, end) {
  13153. start = toFinite(start);
  13154. if (end === undefined) {
  13155. end = start;
  13156. start = 0;
  13157. } else {
  13158. end = toFinite(end);
  13159. }
  13160. number = toNumber(number);
  13161. return baseInRange(number, start, end);
  13162. }
  13163. /**
  13164. * Produces a random number between the inclusive `lower` and `upper` bounds.
  13165. * If only one argument is provided a number between `0` and the given number
  13166. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  13167. * floats, a floating-point number is returned instead of an integer.
  13168. *
  13169. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  13170. * floating-point values which can produce unexpected results.
  13171. *
  13172. * @static
  13173. * @memberOf _
  13174. * @since 0.7.0
  13175. * @category Number
  13176. * @param {number} [lower=0] The lower bound.
  13177. * @param {number} [upper=1] The upper bound.
  13178. * @param {boolean} [floating] Specify returning a floating-point number.
  13179. * @returns {number} Returns the random number.
  13180. * @example
  13181. *
  13182. * _.random(0, 5);
  13183. * // => an integer between 0 and 5
  13184. *
  13185. * _.random(5);
  13186. * // => also an integer between 0 and 5
  13187. *
  13188. * _.random(5, true);
  13189. * // => a floating-point number between 0 and 5
  13190. *
  13191. * _.random(1.2, 5.2);
  13192. * // => a floating-point number between 1.2 and 5.2
  13193. */
  13194. function random(lower, upper, floating) {
  13195. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  13196. upper = floating = undefined;
  13197. }
  13198. if (floating === undefined) {
  13199. if (typeof upper == 'boolean') {
  13200. floating = upper;
  13201. upper = undefined;
  13202. }
  13203. else if (typeof lower == 'boolean') {
  13204. floating = lower;
  13205. lower = undefined;
  13206. }
  13207. }
  13208. if (lower === undefined && upper === undefined) {
  13209. lower = 0;
  13210. upper = 1;
  13211. }
  13212. else {
  13213. lower = toFinite(lower);
  13214. if (upper === undefined) {
  13215. upper = lower;
  13216. lower = 0;
  13217. } else {
  13218. upper = toFinite(upper);
  13219. }
  13220. }
  13221. if (lower > upper) {
  13222. var temp = lower;
  13223. lower = upper;
  13224. upper = temp;
  13225. }
  13226. if (floating || lower % 1 || upper % 1) {
  13227. var rand = nativeRandom();
  13228. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  13229. }
  13230. return baseRandom(lower, upper);
  13231. }
  13232. /*------------------------------------------------------------------------*/
  13233. /**
  13234. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  13235. *
  13236. * @static
  13237. * @memberOf _
  13238. * @since 3.0.0
  13239. * @category String
  13240. * @param {string} [string=''] The string to convert.
  13241. * @returns {string} Returns the camel cased string.
  13242. * @example
  13243. *
  13244. * _.camelCase('Foo Bar');
  13245. * // => 'fooBar'
  13246. *
  13247. * _.camelCase('--foo-bar--');
  13248. * // => 'fooBar'
  13249. *
  13250. * _.camelCase('__FOO_BAR__');
  13251. * // => 'fooBar'
  13252. */
  13253. var camelCase = createCompounder(function(result, word, index) {
  13254. word = word.toLowerCase();
  13255. return result + (index ? capitalize(word) : word);
  13256. });
  13257. /**
  13258. * Converts the first character of `string` to upper case and the remaining
  13259. * to lower case.
  13260. *
  13261. * @static
  13262. * @memberOf _
  13263. * @since 3.0.0
  13264. * @category String
  13265. * @param {string} [string=''] The string to capitalize.
  13266. * @returns {string} Returns the capitalized string.
  13267. * @example
  13268. *
  13269. * _.capitalize('FRED');
  13270. * // => 'Fred'
  13271. */
  13272. function capitalize(string) {
  13273. return upperFirst(toString(string).toLowerCase());
  13274. }
  13275. /**
  13276. * Deburrs `string` by converting
  13277. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  13278. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  13279. * letters to basic Latin letters and removing
  13280. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  13281. *
  13282. * @static
  13283. * @memberOf _
  13284. * @since 3.0.0
  13285. * @category String
  13286. * @param {string} [string=''] The string to deburr.
  13287. * @returns {string} Returns the deburred string.
  13288. * @example
  13289. *
  13290. * _.deburr('déjà vu');
  13291. * // => 'deja vu'
  13292. */
  13293. function deburr(string) {
  13294. string = toString(string);
  13295. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  13296. }
  13297. /**
  13298. * Checks if `string` ends with the given target string.
  13299. *
  13300. * @static
  13301. * @memberOf _
  13302. * @since 3.0.0
  13303. * @category String
  13304. * @param {string} [string=''] The string to inspect.
  13305. * @param {string} [target] The string to search for.
  13306. * @param {number} [position=string.length] The position to search up to.
  13307. * @returns {boolean} Returns `true` if `string` ends with `target`,
  13308. * else `false`.
  13309. * @example
  13310. *
  13311. * _.endsWith('abc', 'c');
  13312. * // => true
  13313. *
  13314. * _.endsWith('abc', 'b');
  13315. * // => false
  13316. *
  13317. * _.endsWith('abc', 'b', 2);
  13318. * // => true
  13319. */
  13320. function endsWith(string, target, position) {
  13321. string = toString(string);
  13322. target = baseToString(target);
  13323. var length = string.length;
  13324. position = position === undefined
  13325. ? length
  13326. : baseClamp(toInteger(position), 0, length);
  13327. var end = position;
  13328. position -= target.length;
  13329. return position >= 0 && string.slice(position, end) == target;
  13330. }
  13331. /**
  13332. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  13333. * corresponding HTML entities.
  13334. *
  13335. * **Note:** No other characters are escaped. To escape additional
  13336. * characters use a third-party library like [_he_](https://mths.be/he).
  13337. *
  13338. * Though the ">" character is escaped for symmetry, characters like
  13339. * ">" and "/" don't need escaping in HTML and have no special meaning
  13340. * unless they're part of a tag or unquoted attribute value. See
  13341. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  13342. * (under "semi-related fun fact") for more details.
  13343. *
  13344. * When working with HTML you should always
  13345. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  13346. * XSS vectors.
  13347. *
  13348. * @static
  13349. * @since 0.1.0
  13350. * @memberOf _
  13351. * @category String
  13352. * @param {string} [string=''] The string to escape.
  13353. * @returns {string} Returns the escaped string.
  13354. * @example
  13355. *
  13356. * _.escape('fred, barney, & pebbles');
  13357. * // => 'fred, barney, &amp; pebbles'
  13358. */
  13359. function escape(string) {
  13360. string = toString(string);
  13361. return (string && reHasUnescapedHtml.test(string))
  13362. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  13363. : string;
  13364. }
  13365. /**
  13366. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  13367. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  13368. *
  13369. * @static
  13370. * @memberOf _
  13371. * @since 3.0.0
  13372. * @category String
  13373. * @param {string} [string=''] The string to escape.
  13374. * @returns {string} Returns the escaped string.
  13375. * @example
  13376. *
  13377. * _.escapeRegExp('[lodash](https://lodash.com/)');
  13378. * // => '\[lodash\]\(https://lodash\.com/\)'
  13379. */
  13380. function escapeRegExp(string) {
  13381. string = toString(string);
  13382. return (string && reHasRegExpChar.test(string))
  13383. ? string.replace(reRegExpChar, '\\$&')
  13384. : string;
  13385. }
  13386. /**
  13387. * Converts `string` to
  13388. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  13389. *
  13390. * @static
  13391. * @memberOf _
  13392. * @since 3.0.0
  13393. * @category String
  13394. * @param {string} [string=''] The string to convert.
  13395. * @returns {string} Returns the kebab cased string.
  13396. * @example
  13397. *
  13398. * _.kebabCase('Foo Bar');
  13399. * // => 'foo-bar'
  13400. *
  13401. * _.kebabCase('fooBar');
  13402. * // => 'foo-bar'
  13403. *
  13404. * _.kebabCase('__FOO_BAR__');
  13405. * // => 'foo-bar'
  13406. */
  13407. var kebabCase = createCompounder(function(result, word, index) {
  13408. return result + (index ? '-' : '') + word.toLowerCase();
  13409. });
  13410. /**
  13411. * Converts `string`, as space separated words, to lower case.
  13412. *
  13413. * @static
  13414. * @memberOf _
  13415. * @since 4.0.0
  13416. * @category String
  13417. * @param {string} [string=''] The string to convert.
  13418. * @returns {string} Returns the lower cased string.
  13419. * @example
  13420. *
  13421. * _.lowerCase('--Foo-Bar--');
  13422. * // => 'foo bar'
  13423. *
  13424. * _.lowerCase('fooBar');
  13425. * // => 'foo bar'
  13426. *
  13427. * _.lowerCase('__FOO_BAR__');
  13428. * // => 'foo bar'
  13429. */
  13430. var lowerCase = createCompounder(function(result, word, index) {
  13431. return result + (index ? ' ' : '') + word.toLowerCase();
  13432. });
  13433. /**
  13434. * Converts the first character of `string` to lower case.
  13435. *
  13436. * @static
  13437. * @memberOf _
  13438. * @since 4.0.0
  13439. * @category String
  13440. * @param {string} [string=''] The string to convert.
  13441. * @returns {string} Returns the converted string.
  13442. * @example
  13443. *
  13444. * _.lowerFirst('Fred');
  13445. * // => 'fred'
  13446. *
  13447. * _.lowerFirst('FRED');
  13448. * // => 'fRED'
  13449. */
  13450. var lowerFirst = createCaseFirst('toLowerCase');
  13451. /**
  13452. * Pads `string` on the left and right sides if it's shorter than `length`.
  13453. * Padding characters are truncated if they can't be evenly divided by `length`.
  13454. *
  13455. * @static
  13456. * @memberOf _
  13457. * @since 3.0.0
  13458. * @category String
  13459. * @param {string} [string=''] The string to pad.
  13460. * @param {number} [length=0] The padding length.
  13461. * @param {string} [chars=' '] The string used as padding.
  13462. * @returns {string} Returns the padded string.
  13463. * @example
  13464. *
  13465. * _.pad('abc', 8);
  13466. * // => ' abc '
  13467. *
  13468. * _.pad('abc', 8, '_-');
  13469. * // => '_-abc_-_'
  13470. *
  13471. * _.pad('abc', 3);
  13472. * // => 'abc'
  13473. */
  13474. function pad(string, length, chars) {
  13475. string = toString(string);
  13476. length = toInteger(length);
  13477. var strLength = length ? stringSize(string) : 0;
  13478. if (!length || strLength >= length) {
  13479. return string;
  13480. }
  13481. var mid = (length - strLength) / 2;
  13482. return (
  13483. createPadding(nativeFloor(mid), chars) +
  13484. string +
  13485. createPadding(nativeCeil(mid), chars)
  13486. );
  13487. }
  13488. /**
  13489. * Pads `string` on the right side if it's shorter than `length`. Padding
  13490. * characters are truncated if they exceed `length`.
  13491. *
  13492. * @static
  13493. * @memberOf _
  13494. * @since 4.0.0
  13495. * @category String
  13496. * @param {string} [string=''] The string to pad.
  13497. * @param {number} [length=0] The padding length.
  13498. * @param {string} [chars=' '] The string used as padding.
  13499. * @returns {string} Returns the padded string.
  13500. * @example
  13501. *
  13502. * _.padEnd('abc', 6);
  13503. * // => 'abc '
  13504. *
  13505. * _.padEnd('abc', 6, '_-');
  13506. * // => 'abc_-_'
  13507. *
  13508. * _.padEnd('abc', 3);
  13509. * // => 'abc'
  13510. */
  13511. function padEnd(string, length, chars) {
  13512. string = toString(string);
  13513. length = toInteger(length);
  13514. var strLength = length ? stringSize(string) : 0;
  13515. return (length && strLength < length)
  13516. ? (string + createPadding(length - strLength, chars))
  13517. : string;
  13518. }
  13519. /**
  13520. * Pads `string` on the left side if it's shorter than `length`. Padding
  13521. * characters are truncated if they exceed `length`.
  13522. *
  13523. * @static
  13524. * @memberOf _
  13525. * @since 4.0.0
  13526. * @category String
  13527. * @param {string} [string=''] The string to pad.
  13528. * @param {number} [length=0] The padding length.
  13529. * @param {string} [chars=' '] The string used as padding.
  13530. * @returns {string} Returns the padded string.
  13531. * @example
  13532. *
  13533. * _.padStart('abc', 6);
  13534. * // => ' abc'
  13535. *
  13536. * _.padStart('abc', 6, '_-');
  13537. * // => '_-_abc'
  13538. *
  13539. * _.padStart('abc', 3);
  13540. * // => 'abc'
  13541. */
  13542. function padStart(string, length, chars) {
  13543. string = toString(string);
  13544. length = toInteger(length);
  13545. var strLength = length ? stringSize(string) : 0;
  13546. return (length && strLength < length)
  13547. ? (createPadding(length - strLength, chars) + string)
  13548. : string;
  13549. }
  13550. /**
  13551. * Converts `string` to an integer of the specified radix. If `radix` is
  13552. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  13553. * hexadecimal, in which case a `radix` of `16` is used.
  13554. *
  13555. * **Note:** This method aligns with the
  13556. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  13557. *
  13558. * @static
  13559. * @memberOf _
  13560. * @since 1.1.0
  13561. * @category String
  13562. * @param {string} string The string to convert.
  13563. * @param {number} [radix=10] The radix to interpret `value` by.
  13564. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13565. * @returns {number} Returns the converted integer.
  13566. * @example
  13567. *
  13568. * _.parseInt('08');
  13569. * // => 8
  13570. *
  13571. * _.map(['6', '08', '10'], _.parseInt);
  13572. * // => [6, 8, 10]
  13573. */
  13574. function parseInt(string, radix, guard) {
  13575. if (guard || radix == null) {
  13576. radix = 0;
  13577. } else if (radix) {
  13578. radix = +radix;
  13579. }
  13580. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  13581. }
  13582. /**
  13583. * Repeats the given string `n` times.
  13584. *
  13585. * @static
  13586. * @memberOf _
  13587. * @since 3.0.0
  13588. * @category String
  13589. * @param {string} [string=''] The string to repeat.
  13590. * @param {number} [n=1] The number of times to repeat the string.
  13591. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13592. * @returns {string} Returns the repeated string.
  13593. * @example
  13594. *
  13595. * _.repeat('*', 3);
  13596. * // => '***'
  13597. *
  13598. * _.repeat('abc', 2);
  13599. * // => 'abcabc'
  13600. *
  13601. * _.repeat('abc', 0);
  13602. * // => ''
  13603. */
  13604. function repeat(string, n, guard) {
  13605. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  13606. n = 1;
  13607. } else {
  13608. n = toInteger(n);
  13609. }
  13610. return baseRepeat(toString(string), n);
  13611. }
  13612. /**
  13613. * Replaces matches for `pattern` in `string` with `replacement`.
  13614. *
  13615. * **Note:** This method is based on
  13616. * [`String#replace`](https://mdn.io/String/replace).
  13617. *
  13618. * @static
  13619. * @memberOf _
  13620. * @since 4.0.0
  13621. * @category String
  13622. * @param {string} [string=''] The string to modify.
  13623. * @param {RegExp|string} pattern The pattern to replace.
  13624. * @param {Function|string} replacement The match replacement.
  13625. * @returns {string} Returns the modified string.
  13626. * @example
  13627. *
  13628. * _.replace('Hi Fred', 'Fred', 'Barney');
  13629. * // => 'Hi Barney'
  13630. */
  13631. function replace() {
  13632. var args = arguments,
  13633. string = toString(args[0]);
  13634. return args.length < 3 ? string : string.replace(args[1], args[2]);
  13635. }
  13636. /**
  13637. * Converts `string` to
  13638. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  13639. *
  13640. * @static
  13641. * @memberOf _
  13642. * @since 3.0.0
  13643. * @category String
  13644. * @param {string} [string=''] The string to convert.
  13645. * @returns {string} Returns the snake cased string.
  13646. * @example
  13647. *
  13648. * _.snakeCase('Foo Bar');
  13649. * // => 'foo_bar'
  13650. *
  13651. * _.snakeCase('fooBar');
  13652. * // => 'foo_bar'
  13653. *
  13654. * _.snakeCase('--FOO-BAR--');
  13655. * // => 'foo_bar'
  13656. */
  13657. var snakeCase = createCompounder(function(result, word, index) {
  13658. return result + (index ? '_' : '') + word.toLowerCase();
  13659. });
  13660. /**
  13661. * Splits `string` by `separator`.
  13662. *
  13663. * **Note:** This method is based on
  13664. * [`String#split`](https://mdn.io/String/split).
  13665. *
  13666. * @static
  13667. * @memberOf _
  13668. * @since 4.0.0
  13669. * @category String
  13670. * @param {string} [string=''] The string to split.
  13671. * @param {RegExp|string} separator The separator pattern to split by.
  13672. * @param {number} [limit] The length to truncate results to.
  13673. * @returns {Array} Returns the string segments.
  13674. * @example
  13675. *
  13676. * _.split('a-b-c', '-', 2);
  13677. * // => ['a', 'b']
  13678. */
  13679. function split(string, separator, limit) {
  13680. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  13681. separator = limit = undefined;
  13682. }
  13683. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  13684. if (!limit) {
  13685. return [];
  13686. }
  13687. string = toString(string);
  13688. if (string && (
  13689. typeof separator == 'string' ||
  13690. (separator != null && !isRegExp(separator))
  13691. )) {
  13692. separator = baseToString(separator);
  13693. if (!separator && hasUnicode(string)) {
  13694. return castSlice(stringToArray(string), 0, limit);
  13695. }
  13696. }
  13697. return string.split(separator, limit);
  13698. }
  13699. /**
  13700. * Converts `string` to
  13701. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  13702. *
  13703. * @static
  13704. * @memberOf _
  13705. * @since 3.1.0
  13706. * @category String
  13707. * @param {string} [string=''] The string to convert.
  13708. * @returns {string} Returns the start cased string.
  13709. * @example
  13710. *
  13711. * _.startCase('--foo-bar--');
  13712. * // => 'Foo Bar'
  13713. *
  13714. * _.startCase('fooBar');
  13715. * // => 'Foo Bar'
  13716. *
  13717. * _.startCase('__FOO_BAR__');
  13718. * // => 'FOO BAR'
  13719. */
  13720. var startCase = createCompounder(function(result, word, index) {
  13721. return result + (index ? ' ' : '') + upperFirst(word);
  13722. });
  13723. /**
  13724. * Checks if `string` starts with the given target string.
  13725. *
  13726. * @static
  13727. * @memberOf _
  13728. * @since 3.0.0
  13729. * @category String
  13730. * @param {string} [string=''] The string to inspect.
  13731. * @param {string} [target] The string to search for.
  13732. * @param {number} [position=0] The position to search from.
  13733. * @returns {boolean} Returns `true` if `string` starts with `target`,
  13734. * else `false`.
  13735. * @example
  13736. *
  13737. * _.startsWith('abc', 'a');
  13738. * // => true
  13739. *
  13740. * _.startsWith('abc', 'b');
  13741. * // => false
  13742. *
  13743. * _.startsWith('abc', 'b', 1);
  13744. * // => true
  13745. */
  13746. function startsWith(string, target, position) {
  13747. string = toString(string);
  13748. position = position == null
  13749. ? 0
  13750. : baseClamp(toInteger(position), 0, string.length);
  13751. target = baseToString(target);
  13752. return string.slice(position, position + target.length) == target;
  13753. }
  13754. /**
  13755. * Creates a compiled template function that can interpolate data properties
  13756. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  13757. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  13758. * properties may be accessed as free variables in the template. If a setting
  13759. * object is given, it takes precedence over `_.templateSettings` values.
  13760. *
  13761. * **Note:** In the development build `_.template` utilizes
  13762. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  13763. * for easier debugging.
  13764. *
  13765. * For more information on precompiling templates see
  13766. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  13767. *
  13768. * For more information on Chrome extension sandboxes see
  13769. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  13770. *
  13771. * @static
  13772. * @since 0.1.0
  13773. * @memberOf _
  13774. * @category String
  13775. * @param {string} [string=''] The template string.
  13776. * @param {Object} [options={}] The options object.
  13777. * @param {RegExp} [options.escape=_.templateSettings.escape]
  13778. * The HTML "escape" delimiter.
  13779. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  13780. * The "evaluate" delimiter.
  13781. * @param {Object} [options.imports=_.templateSettings.imports]
  13782. * An object to import into the template as free variables.
  13783. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  13784. * The "interpolate" delimiter.
  13785. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  13786. * The sourceURL of the compiled template.
  13787. * @param {string} [options.variable='obj']
  13788. * The data object variable name.
  13789. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13790. * @returns {Function} Returns the compiled template function.
  13791. * @example
  13792. *
  13793. * // Use the "interpolate" delimiter to create a compiled template.
  13794. * var compiled = _.template('hello <%= user %>!');
  13795. * compiled({ 'user': 'fred' });
  13796. * // => 'hello fred!'
  13797. *
  13798. * // Use the HTML "escape" delimiter to escape data property values.
  13799. * var compiled = _.template('<b><%- value %></b>');
  13800. * compiled({ 'value': '<script>' });
  13801. * // => '<b>&lt;script&gt;</b>'
  13802. *
  13803. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  13804. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  13805. * compiled({ 'users': ['fred', 'barney'] });
  13806. * // => '<li>fred</li><li>barney</li>'
  13807. *
  13808. * // Use the internal `print` function in "evaluate" delimiters.
  13809. * var compiled = _.template('<% print("hello " + user); %>!');
  13810. * compiled({ 'user': 'barney' });
  13811. * // => 'hello barney!'
  13812. *
  13813. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  13814. * // Disable support by replacing the "interpolate" delimiter.
  13815. * var compiled = _.template('hello ${ user }!');
  13816. * compiled({ 'user': 'pebbles' });
  13817. * // => 'hello pebbles!'
  13818. *
  13819. * // Use backslashes to treat delimiters as plain text.
  13820. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  13821. * compiled({ 'value': 'ignored' });
  13822. * // => '<%- value %>'
  13823. *
  13824. * // Use the `imports` option to import `jQuery` as `jq`.
  13825. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  13826. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  13827. * compiled({ 'users': ['fred', 'barney'] });
  13828. * // => '<li>fred</li><li>barney</li>'
  13829. *
  13830. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  13831. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  13832. * compiled(data);
  13833. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  13834. *
  13835. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  13836. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  13837. * compiled.source;
  13838. * // => function(data) {
  13839. * // var __t, __p = '';
  13840. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  13841. * // return __p;
  13842. * // }
  13843. *
  13844. * // Use custom template delimiters.
  13845. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  13846. * var compiled = _.template('hello {{ user }}!');
  13847. * compiled({ 'user': 'mustache' });
  13848. * // => 'hello mustache!'
  13849. *
  13850. * // Use the `source` property to inline compiled templates for meaningful
  13851. * // line numbers in error messages and stack traces.
  13852. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  13853. * var JST = {\
  13854. * "main": ' + _.template(mainText).source + '\
  13855. * };\
  13856. * ');
  13857. */
  13858. function template(string, options, guard) {
  13859. // Based on John Resig's `tmpl` implementation
  13860. // (http://ejohn.org/blog/javascript-micro-templating/)
  13861. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  13862. var settings = lodash.templateSettings;
  13863. if (guard && isIterateeCall(string, options, guard)) {
  13864. options = undefined;
  13865. }
  13866. string = toString(string);
  13867. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  13868. var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  13869. importsKeys = keys(imports),
  13870. importsValues = baseValues(imports, importsKeys);
  13871. var isEscaping,
  13872. isEvaluating,
  13873. index = 0,
  13874. interpolate = options.interpolate || reNoMatch,
  13875. source = "__p += '";
  13876. // Compile the regexp to match each delimiter.
  13877. var reDelimiters = RegExp(
  13878. (options.escape || reNoMatch).source + '|' +
  13879. interpolate.source + '|' +
  13880. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  13881. (options.evaluate || reNoMatch).source + '|$'
  13882. , 'g');
  13883. // Use a sourceURL for easier debugging.
  13884. var sourceURL = '//# sourceURL=' +
  13885. ('sourceURL' in options
  13886. ? options.sourceURL
  13887. : ('lodash.templateSources[' + (++templateCounter) + ']')
  13888. ) + '\n';
  13889. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  13890. interpolateValue || (interpolateValue = esTemplateValue);
  13891. // Escape characters that can't be included in string literals.
  13892. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  13893. // Replace delimiters with snippets.
  13894. if (escapeValue) {
  13895. isEscaping = true;
  13896. source += "' +\n__e(" + escapeValue + ") +\n'";
  13897. }
  13898. if (evaluateValue) {
  13899. isEvaluating = true;
  13900. source += "';\n" + evaluateValue + ";\n__p += '";
  13901. }
  13902. if (interpolateValue) {
  13903. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  13904. }
  13905. index = offset + match.length;
  13906. // The JS engine embedded in Adobe products needs `match` returned in
  13907. // order to produce the correct `offset` value.
  13908. return match;
  13909. });
  13910. source += "';\n";
  13911. // If `variable` is not specified wrap a with-statement around the generated
  13912. // code to add the data object to the top of the scope chain.
  13913. var variable = options.variable;
  13914. if (!variable) {
  13915. source = 'with (obj) {\n' + source + '\n}\n';
  13916. }
  13917. // Cleanup code by stripping empty strings.
  13918. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  13919. .replace(reEmptyStringMiddle, '$1')
  13920. .replace(reEmptyStringTrailing, '$1;');
  13921. // Frame code as the function body.
  13922. source = 'function(' + (variable || 'obj') + ') {\n' +
  13923. (variable
  13924. ? ''
  13925. : 'obj || (obj = {});\n'
  13926. ) +
  13927. "var __t, __p = ''" +
  13928. (isEscaping
  13929. ? ', __e = _.escape'
  13930. : ''
  13931. ) +
  13932. (isEvaluating
  13933. ? ', __j = Array.prototype.join;\n' +
  13934. "function print() { __p += __j.call(arguments, '') }\n"
  13935. : ';\n'
  13936. ) +
  13937. source +
  13938. 'return __p\n}';
  13939. var result = attempt(function() {
  13940. return Function(importsKeys, sourceURL + 'return ' + source)
  13941. .apply(undefined, importsValues);
  13942. });
  13943. // Provide the compiled function's source by its `toString` method or
  13944. // the `source` property as a convenience for inlining compiled templates.
  13945. result.source = source;
  13946. if (isError(result)) {
  13947. throw result;
  13948. }
  13949. return result;
  13950. }
  13951. /**
  13952. * Converts `string`, as a whole, to lower case just like
  13953. * [String#toLowerCase](https://mdn.io/toLowerCase).
  13954. *
  13955. * @static
  13956. * @memberOf _
  13957. * @since 4.0.0
  13958. * @category String
  13959. * @param {string} [string=''] The string to convert.
  13960. * @returns {string} Returns the lower cased string.
  13961. * @example
  13962. *
  13963. * _.toLower('--Foo-Bar--');
  13964. * // => '--foo-bar--'
  13965. *
  13966. * _.toLower('fooBar');
  13967. * // => 'foobar'
  13968. *
  13969. * _.toLower('__FOO_BAR__');
  13970. * // => '__foo_bar__'
  13971. */
  13972. function toLower(value) {
  13973. return toString(value).toLowerCase();
  13974. }
  13975. /**
  13976. * Converts `string`, as a whole, to upper case just like
  13977. * [String#toUpperCase](https://mdn.io/toUpperCase).
  13978. *
  13979. * @static
  13980. * @memberOf _
  13981. * @since 4.0.0
  13982. * @category String
  13983. * @param {string} [string=''] The string to convert.
  13984. * @returns {string} Returns the upper cased string.
  13985. * @example
  13986. *
  13987. * _.toUpper('--foo-bar--');
  13988. * // => '--FOO-BAR--'
  13989. *
  13990. * _.toUpper('fooBar');
  13991. * // => 'FOOBAR'
  13992. *
  13993. * _.toUpper('__foo_bar__');
  13994. * // => '__FOO_BAR__'
  13995. */
  13996. function toUpper(value) {
  13997. return toString(value).toUpperCase();
  13998. }
  13999. /**
  14000. * Removes leading and trailing whitespace or specified characters from `string`.
  14001. *
  14002. * @static
  14003. * @memberOf _
  14004. * @since 3.0.0
  14005. * @category String
  14006. * @param {string} [string=''] The string to trim.
  14007. * @param {string} [chars=whitespace] The characters to trim.
  14008. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14009. * @returns {string} Returns the trimmed string.
  14010. * @example
  14011. *
  14012. * _.trim(' abc ');
  14013. * // => 'abc'
  14014. *
  14015. * _.trim('-_-abc-_-', '_-');
  14016. * // => 'abc'
  14017. *
  14018. * _.map([' foo ', ' bar '], _.trim);
  14019. * // => ['foo', 'bar']
  14020. */
  14021. function trim(string, chars, guard) {
  14022. string = toString(string);
  14023. if (string && (guard || chars === undefined)) {
  14024. return string.replace(reTrim, '');
  14025. }
  14026. if (!string || !(chars = baseToString(chars))) {
  14027. return string;
  14028. }
  14029. var strSymbols = stringToArray(string),
  14030. chrSymbols = stringToArray(chars),
  14031. start = charsStartIndex(strSymbols, chrSymbols),
  14032. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  14033. return castSlice(strSymbols, start, end).join('');
  14034. }
  14035. /**
  14036. * Removes trailing whitespace or specified characters from `string`.
  14037. *
  14038. * @static
  14039. * @memberOf _
  14040. * @since 4.0.0
  14041. * @category String
  14042. * @param {string} [string=''] The string to trim.
  14043. * @param {string} [chars=whitespace] The characters to trim.
  14044. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14045. * @returns {string} Returns the trimmed string.
  14046. * @example
  14047. *
  14048. * _.trimEnd(' abc ');
  14049. * // => ' abc'
  14050. *
  14051. * _.trimEnd('-_-abc-_-', '_-');
  14052. * // => '-_-abc'
  14053. */
  14054. function trimEnd(string, chars, guard) {
  14055. string = toString(string);
  14056. if (string && (guard || chars === undefined)) {
  14057. return string.replace(reTrimEnd, '');
  14058. }
  14059. if (!string || !(chars = baseToString(chars))) {
  14060. return string;
  14061. }
  14062. var strSymbols = stringToArray(string),
  14063. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  14064. return castSlice(strSymbols, 0, end).join('');
  14065. }
  14066. /**
  14067. * Removes leading whitespace or specified characters from `string`.
  14068. *
  14069. * @static
  14070. * @memberOf _
  14071. * @since 4.0.0
  14072. * @category String
  14073. * @param {string} [string=''] The string to trim.
  14074. * @param {string} [chars=whitespace] The characters to trim.
  14075. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14076. * @returns {string} Returns the trimmed string.
  14077. * @example
  14078. *
  14079. * _.trimStart(' abc ');
  14080. * // => 'abc '
  14081. *
  14082. * _.trimStart('-_-abc-_-', '_-');
  14083. * // => 'abc-_-'
  14084. */
  14085. function trimStart(string, chars, guard) {
  14086. string = toString(string);
  14087. if (string && (guard || chars === undefined)) {
  14088. return string.replace(reTrimStart, '');
  14089. }
  14090. if (!string || !(chars = baseToString(chars))) {
  14091. return string;
  14092. }
  14093. var strSymbols = stringToArray(string),
  14094. start = charsStartIndex(strSymbols, stringToArray(chars));
  14095. return castSlice(strSymbols, start).join('');
  14096. }
  14097. /**
  14098. * Truncates `string` if it's longer than the given maximum string length.
  14099. * The last characters of the truncated string are replaced with the omission
  14100. * string which defaults to "...".
  14101. *
  14102. * @static
  14103. * @memberOf _
  14104. * @since 4.0.0
  14105. * @category String
  14106. * @param {string} [string=''] The string to truncate.
  14107. * @param {Object} [options={}] The options object.
  14108. * @param {number} [options.length=30] The maximum string length.
  14109. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  14110. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  14111. * @returns {string} Returns the truncated string.
  14112. * @example
  14113. *
  14114. * _.truncate('hi-diddly-ho there, neighborino');
  14115. * // => 'hi-diddly-ho there, neighbo...'
  14116. *
  14117. * _.truncate('hi-diddly-ho there, neighborino', {
  14118. * 'length': 24,
  14119. * 'separator': ' '
  14120. * });
  14121. * // => 'hi-diddly-ho there,...'
  14122. *
  14123. * _.truncate('hi-diddly-ho there, neighborino', {
  14124. * 'length': 24,
  14125. * 'separator': /,? +/
  14126. * });
  14127. * // => 'hi-diddly-ho there...'
  14128. *
  14129. * _.truncate('hi-diddly-ho there, neighborino', {
  14130. * 'omission': ' [...]'
  14131. * });
  14132. * // => 'hi-diddly-ho there, neig [...]'
  14133. */
  14134. function truncate(string, options) {
  14135. var length = DEFAULT_TRUNC_LENGTH,
  14136. omission = DEFAULT_TRUNC_OMISSION;
  14137. if (isObject(options)) {
  14138. var separator = 'separator' in options ? options.separator : separator;
  14139. length = 'length' in options ? toInteger(options.length) : length;
  14140. omission = 'omission' in options ? baseToString(options.omission) : omission;
  14141. }
  14142. string = toString(string);
  14143. var strLength = string.length;
  14144. if (hasUnicode(string)) {
  14145. var strSymbols = stringToArray(string);
  14146. strLength = strSymbols.length;
  14147. }
  14148. if (length >= strLength) {
  14149. return string;
  14150. }
  14151. var end = length - stringSize(omission);
  14152. if (end < 1) {
  14153. return omission;
  14154. }
  14155. var result = strSymbols
  14156. ? castSlice(strSymbols, 0, end).join('')
  14157. : string.slice(0, end);
  14158. if (separator === undefined) {
  14159. return result + omission;
  14160. }
  14161. if (strSymbols) {
  14162. end += (result.length - end);
  14163. }
  14164. if (isRegExp(separator)) {
  14165. if (string.slice(end).search(separator)) {
  14166. var match,
  14167. substring = result;
  14168. if (!separator.global) {
  14169. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  14170. }
  14171. separator.lastIndex = 0;
  14172. while ((match = separator.exec(substring))) {
  14173. var newEnd = match.index;
  14174. }
  14175. result = result.slice(0, newEnd === undefined ? end : newEnd);
  14176. }
  14177. } else if (string.indexOf(baseToString(separator), end) != end) {
  14178. var index = result.lastIndexOf(separator);
  14179. if (index > -1) {
  14180. result = result.slice(0, index);
  14181. }
  14182. }
  14183. return result + omission;
  14184. }
  14185. /**
  14186. * The inverse of `_.escape`; this method converts the HTML entities
  14187. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  14188. * their corresponding characters.
  14189. *
  14190. * **Note:** No other HTML entities are unescaped. To unescape additional
  14191. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  14192. *
  14193. * @static
  14194. * @memberOf _
  14195. * @since 0.6.0
  14196. * @category String
  14197. * @param {string} [string=''] The string to unescape.
  14198. * @returns {string} Returns the unescaped string.
  14199. * @example
  14200. *
  14201. * _.unescape('fred, barney, &amp; pebbles');
  14202. * // => 'fred, barney, & pebbles'
  14203. */
  14204. function unescape(string) {
  14205. string = toString(string);
  14206. return (string && reHasEscapedHtml.test(string))
  14207. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  14208. : string;
  14209. }
  14210. /**
  14211. * Converts `string`, as space separated words, to upper case.
  14212. *
  14213. * @static
  14214. * @memberOf _
  14215. * @since 4.0.0
  14216. * @category String
  14217. * @param {string} [string=''] The string to convert.
  14218. * @returns {string} Returns the upper cased string.
  14219. * @example
  14220. *
  14221. * _.upperCase('--foo-bar');
  14222. * // => 'FOO BAR'
  14223. *
  14224. * _.upperCase('fooBar');
  14225. * // => 'FOO BAR'
  14226. *
  14227. * _.upperCase('__foo_bar__');
  14228. * // => 'FOO BAR'
  14229. */
  14230. var upperCase = createCompounder(function(result, word, index) {
  14231. return result + (index ? ' ' : '') + word.toUpperCase();
  14232. });
  14233. /**
  14234. * Converts the first character of `string` to upper case.
  14235. *
  14236. * @static
  14237. * @memberOf _
  14238. * @since 4.0.0
  14239. * @category String
  14240. * @param {string} [string=''] The string to convert.
  14241. * @returns {string} Returns the converted string.
  14242. * @example
  14243. *
  14244. * _.upperFirst('fred');
  14245. * // => 'Fred'
  14246. *
  14247. * _.upperFirst('FRED');
  14248. * // => 'FRED'
  14249. */
  14250. var upperFirst = createCaseFirst('toUpperCase');
  14251. /**
  14252. * Splits `string` into an array of its words.
  14253. *
  14254. * @static
  14255. * @memberOf _
  14256. * @since 3.0.0
  14257. * @category String
  14258. * @param {string} [string=''] The string to inspect.
  14259. * @param {RegExp|string} [pattern] The pattern to match words.
  14260. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14261. * @returns {Array} Returns the words of `string`.
  14262. * @example
  14263. *
  14264. * _.words('fred, barney, & pebbles');
  14265. * // => ['fred', 'barney', 'pebbles']
  14266. *
  14267. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  14268. * // => ['fred', 'barney', '&', 'pebbles']
  14269. */
  14270. function words(string, pattern, guard) {
  14271. string = toString(string);
  14272. pattern = guard ? undefined : pattern;
  14273. if (pattern === undefined) {
  14274. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  14275. }
  14276. return string.match(pattern) || [];
  14277. }
  14278. /*------------------------------------------------------------------------*/
  14279. /**
  14280. * Attempts to invoke `func`, returning either the result or the caught error
  14281. * object. Any additional arguments are provided to `func` when it's invoked.
  14282. *
  14283. * @static
  14284. * @memberOf _
  14285. * @since 3.0.0
  14286. * @category Util
  14287. * @param {Function} func The function to attempt.
  14288. * @param {...*} [args] The arguments to invoke `func` with.
  14289. * @returns {*} Returns the `func` result or error object.
  14290. * @example
  14291. *
  14292. * // Avoid throwing errors for invalid selectors.
  14293. * var elements = _.attempt(function(selector) {
  14294. * return document.querySelectorAll(selector);
  14295. * }, '>_>');
  14296. *
  14297. * if (_.isError(elements)) {
  14298. * elements = [];
  14299. * }
  14300. */
  14301. var attempt = baseRest(function(func, args) {
  14302. try {
  14303. return apply(func, undefined, args);
  14304. } catch (e) {
  14305. return isError(e) ? e : new Error(e);
  14306. }
  14307. });
  14308. /**
  14309. * Binds methods of an object to the object itself, overwriting the existing
  14310. * method.
  14311. *
  14312. * **Note:** This method doesn't set the "length" property of bound functions.
  14313. *
  14314. * @static
  14315. * @since 0.1.0
  14316. * @memberOf _
  14317. * @category Util
  14318. * @param {Object} object The object to bind and assign the bound methods to.
  14319. * @param {...(string|string[])} methodNames The object method names to bind.
  14320. * @returns {Object} Returns `object`.
  14321. * @example
  14322. *
  14323. * var view = {
  14324. * 'label': 'docs',
  14325. * 'click': function() {
  14326. * console.log('clicked ' + this.label);
  14327. * }
  14328. * };
  14329. *
  14330. * _.bindAll(view, ['click']);
  14331. * jQuery(element).on('click', view.click);
  14332. * // => Logs 'clicked docs' when clicked.
  14333. */
  14334. var bindAll = flatRest(function(object, methodNames) {
  14335. arrayEach(methodNames, function(key) {
  14336. key = toKey(key);
  14337. baseAssignValue(object, key, bind(object[key], object));
  14338. });
  14339. return object;
  14340. });
  14341. /**
  14342. * Creates a function that iterates over `pairs` and invokes the corresponding
  14343. * function of the first predicate to return truthy. The predicate-function
  14344. * pairs are invoked with the `this` binding and arguments of the created
  14345. * function.
  14346. *
  14347. * @static
  14348. * @memberOf _
  14349. * @since 4.0.0
  14350. * @category Util
  14351. * @param {Array} pairs The predicate-function pairs.
  14352. * @returns {Function} Returns the new composite function.
  14353. * @example
  14354. *
  14355. * var func = _.cond([
  14356. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  14357. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  14358. * [_.stubTrue, _.constant('no match')]
  14359. * ]);
  14360. *
  14361. * func({ 'a': 1, 'b': 2 });
  14362. * // => 'matches A'
  14363. *
  14364. * func({ 'a': 0, 'b': 1 });
  14365. * // => 'matches B'
  14366. *
  14367. * func({ 'a': '1', 'b': '2' });
  14368. * // => 'no match'
  14369. */
  14370. function cond(pairs) {
  14371. var length = pairs == null ? 0 : pairs.length,
  14372. toIteratee = getIteratee();
  14373. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  14374. if (typeof pair[1] != 'function') {
  14375. throw new TypeError(FUNC_ERROR_TEXT);
  14376. }
  14377. return [toIteratee(pair[0]), pair[1]];
  14378. });
  14379. return baseRest(function(args) {
  14380. var index = -1;
  14381. while (++index < length) {
  14382. var pair = pairs[index];
  14383. if (apply(pair[0], this, args)) {
  14384. return apply(pair[1], this, args);
  14385. }
  14386. }
  14387. });
  14388. }
  14389. /**
  14390. * Creates a function that invokes the predicate properties of `source` with
  14391. * the corresponding property values of a given object, returning `true` if
  14392. * all predicates return truthy, else `false`.
  14393. *
  14394. * **Note:** The created function is equivalent to `_.conformsTo` with
  14395. * `source` partially applied.
  14396. *
  14397. * @static
  14398. * @memberOf _
  14399. * @since 4.0.0
  14400. * @category Util
  14401. * @param {Object} source The object of property predicates to conform to.
  14402. * @returns {Function} Returns the new spec function.
  14403. * @example
  14404. *
  14405. * var objects = [
  14406. * { 'a': 2, 'b': 1 },
  14407. * { 'a': 1, 'b': 2 }
  14408. * ];
  14409. *
  14410. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  14411. * // => [{ 'a': 1, 'b': 2 }]
  14412. */
  14413. function conforms(source) {
  14414. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  14415. }
  14416. /**
  14417. * Creates a function that returns `value`.
  14418. *
  14419. * @static
  14420. * @memberOf _
  14421. * @since 2.4.0
  14422. * @category Util
  14423. * @param {*} value The value to return from the new function.
  14424. * @returns {Function} Returns the new constant function.
  14425. * @example
  14426. *
  14427. * var objects = _.times(2, _.constant({ 'a': 1 }));
  14428. *
  14429. * console.log(objects);
  14430. * // => [{ 'a': 1 }, { 'a': 1 }]
  14431. *
  14432. * console.log(objects[0] === objects[1]);
  14433. * // => true
  14434. */
  14435. function constant(value) {
  14436. return function() {
  14437. return value;
  14438. };
  14439. }
  14440. /**
  14441. * Checks `value` to determine whether a default value should be returned in
  14442. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  14443. * or `undefined`.
  14444. *
  14445. * @static
  14446. * @memberOf _
  14447. * @since 4.14.0
  14448. * @category Util
  14449. * @param {*} value The value to check.
  14450. * @param {*} defaultValue The default value.
  14451. * @returns {*} Returns the resolved value.
  14452. * @example
  14453. *
  14454. * _.defaultTo(1, 10);
  14455. * // => 1
  14456. *
  14457. * _.defaultTo(undefined, 10);
  14458. * // => 10
  14459. */
  14460. function defaultTo(value, defaultValue) {
  14461. return (value == null || value !== value) ? defaultValue : value;
  14462. }
  14463. /**
  14464. * Creates a function that returns the result of invoking the given functions
  14465. * with the `this` binding of the created function, where each successive
  14466. * invocation is supplied the return value of the previous.
  14467. *
  14468. * @static
  14469. * @memberOf _
  14470. * @since 3.0.0
  14471. * @category Util
  14472. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14473. * @returns {Function} Returns the new composite function.
  14474. * @see _.flowRight
  14475. * @example
  14476. *
  14477. * function square(n) {
  14478. * return n * n;
  14479. * }
  14480. *
  14481. * var addSquare = _.flow([_.add, square]);
  14482. * addSquare(1, 2);
  14483. * // => 9
  14484. */
  14485. var flow = createFlow();
  14486. /**
  14487. * This method is like `_.flow` except that it creates a function that
  14488. * invokes the given functions from right to left.
  14489. *
  14490. * @static
  14491. * @since 3.0.0
  14492. * @memberOf _
  14493. * @category Util
  14494. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14495. * @returns {Function} Returns the new composite function.
  14496. * @see _.flow
  14497. * @example
  14498. *
  14499. * function square(n) {
  14500. * return n * n;
  14501. * }
  14502. *
  14503. * var addSquare = _.flowRight([square, _.add]);
  14504. * addSquare(1, 2);
  14505. * // => 9
  14506. */
  14507. var flowRight = createFlow(true);
  14508. /**
  14509. * This method returns the first argument it receives.
  14510. *
  14511. * @static
  14512. * @since 0.1.0
  14513. * @memberOf _
  14514. * @category Util
  14515. * @param {*} value Any value.
  14516. * @returns {*} Returns `value`.
  14517. * @example
  14518. *
  14519. * var object = { 'a': 1 };
  14520. *
  14521. * console.log(_.identity(object) === object);
  14522. * // => true
  14523. */
  14524. function identity(value) {
  14525. return value;
  14526. }
  14527. /**
  14528. * Creates a function that invokes `func` with the arguments of the created
  14529. * function. If `func` is a property name, the created function returns the
  14530. * property value for a given element. If `func` is an array or object, the
  14531. * created function returns `true` for elements that contain the equivalent
  14532. * source properties, otherwise it returns `false`.
  14533. *
  14534. * @static
  14535. * @since 4.0.0
  14536. * @memberOf _
  14537. * @category Util
  14538. * @param {*} [func=_.identity] The value to convert to a callback.
  14539. * @returns {Function} Returns the callback.
  14540. * @example
  14541. *
  14542. * var users = [
  14543. * { 'user': 'barney', 'age': 36, 'active': true },
  14544. * { 'user': 'fred', 'age': 40, 'active': false }
  14545. * ];
  14546. *
  14547. * // The `_.matches` iteratee shorthand.
  14548. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  14549. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  14550. *
  14551. * // The `_.matchesProperty` iteratee shorthand.
  14552. * _.filter(users, _.iteratee(['user', 'fred']));
  14553. * // => [{ 'user': 'fred', 'age': 40 }]
  14554. *
  14555. * // The `_.property` iteratee shorthand.
  14556. * _.map(users, _.iteratee('user'));
  14557. * // => ['barney', 'fred']
  14558. *
  14559. * // Create custom iteratee shorthands.
  14560. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  14561. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  14562. * return func.test(string);
  14563. * };
  14564. * });
  14565. *
  14566. * _.filter(['abc', 'def'], /ef/);
  14567. * // => ['def']
  14568. */
  14569. function iteratee(func) {
  14570. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  14571. }
  14572. /**
  14573. * Creates a function that performs a partial deep comparison between a given
  14574. * object and `source`, returning `true` if the given object has equivalent
  14575. * property values, else `false`.
  14576. *
  14577. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  14578. * partially applied.
  14579. *
  14580. * Partial comparisons will match empty array and empty object `source`
  14581. * values against any array or object value, respectively. See `_.isEqual`
  14582. * for a list of supported value comparisons.
  14583. *
  14584. * @static
  14585. * @memberOf _
  14586. * @since 3.0.0
  14587. * @category Util
  14588. * @param {Object} source The object of property values to match.
  14589. * @returns {Function} Returns the new spec function.
  14590. * @example
  14591. *
  14592. * var objects = [
  14593. * { 'a': 1, 'b': 2, 'c': 3 },
  14594. * { 'a': 4, 'b': 5, 'c': 6 }
  14595. * ];
  14596. *
  14597. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  14598. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  14599. */
  14600. function matches(source) {
  14601. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  14602. }
  14603. /**
  14604. * Creates a function that performs a partial deep comparison between the
  14605. * value at `path` of a given object to `srcValue`, returning `true` if the
  14606. * object value is equivalent, else `false`.
  14607. *
  14608. * **Note:** Partial comparisons will match empty array and empty object
  14609. * `srcValue` values against any array or object value, respectively. See
  14610. * `_.isEqual` for a list of supported value comparisons.
  14611. *
  14612. * @static
  14613. * @memberOf _
  14614. * @since 3.2.0
  14615. * @category Util
  14616. * @param {Array|string} path The path of the property to get.
  14617. * @param {*} srcValue The value to match.
  14618. * @returns {Function} Returns the new spec function.
  14619. * @example
  14620. *
  14621. * var objects = [
  14622. * { 'a': 1, 'b': 2, 'c': 3 },
  14623. * { 'a': 4, 'b': 5, 'c': 6 }
  14624. * ];
  14625. *
  14626. * _.find(objects, _.matchesProperty('a', 4));
  14627. * // => { 'a': 4, 'b': 5, 'c': 6 }
  14628. */
  14629. function matchesProperty(path, srcValue) {
  14630. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  14631. }
  14632. /**
  14633. * Creates a function that invokes the method at `path` of a given object.
  14634. * Any additional arguments are provided to the invoked method.
  14635. *
  14636. * @static
  14637. * @memberOf _
  14638. * @since 3.7.0
  14639. * @category Util
  14640. * @param {Array|string} path The path of the method to invoke.
  14641. * @param {...*} [args] The arguments to invoke the method with.
  14642. * @returns {Function} Returns the new invoker function.
  14643. * @example
  14644. *
  14645. * var objects = [
  14646. * { 'a': { 'b': _.constant(2) } },
  14647. * { 'a': { 'b': _.constant(1) } }
  14648. * ];
  14649. *
  14650. * _.map(objects, _.method('a.b'));
  14651. * // => [2, 1]
  14652. *
  14653. * _.map(objects, _.method(['a', 'b']));
  14654. * // => [2, 1]
  14655. */
  14656. var method = baseRest(function(path, args) {
  14657. return function(object) {
  14658. return baseInvoke(object, path, args);
  14659. };
  14660. });
  14661. /**
  14662. * The opposite of `_.method`; this method creates a function that invokes
  14663. * the method at a given path of `object`. Any additional arguments are
  14664. * provided to the invoked method.
  14665. *
  14666. * @static
  14667. * @memberOf _
  14668. * @since 3.7.0
  14669. * @category Util
  14670. * @param {Object} object The object to query.
  14671. * @param {...*} [args] The arguments to invoke the method with.
  14672. * @returns {Function} Returns the new invoker function.
  14673. * @example
  14674. *
  14675. * var array = _.times(3, _.constant),
  14676. * object = { 'a': array, 'b': array, 'c': array };
  14677. *
  14678. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  14679. * // => [2, 0]
  14680. *
  14681. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  14682. * // => [2, 0]
  14683. */
  14684. var methodOf = baseRest(function(object, args) {
  14685. return function(path) {
  14686. return baseInvoke(object, path, args);
  14687. };
  14688. });
  14689. /**
  14690. * Adds all own enumerable string keyed function properties of a source
  14691. * object to the destination object. If `object` is a function, then methods
  14692. * are added to its prototype as well.
  14693. *
  14694. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  14695. * avoid conflicts caused by modifying the original.
  14696. *
  14697. * @static
  14698. * @since 0.1.0
  14699. * @memberOf _
  14700. * @category Util
  14701. * @param {Function|Object} [object=lodash] The destination object.
  14702. * @param {Object} source The object of functions to add.
  14703. * @param {Object} [options={}] The options object.
  14704. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  14705. * @returns {Function|Object} Returns `object`.
  14706. * @example
  14707. *
  14708. * function vowels(string) {
  14709. * return _.filter(string, function(v) {
  14710. * return /[aeiou]/i.test(v);
  14711. * });
  14712. * }
  14713. *
  14714. * _.mixin({ 'vowels': vowels });
  14715. * _.vowels('fred');
  14716. * // => ['e']
  14717. *
  14718. * _('fred').vowels().value();
  14719. * // => ['e']
  14720. *
  14721. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  14722. * _('fred').vowels();
  14723. * // => ['e']
  14724. */
  14725. function mixin(object, source, options) {
  14726. var props = keys(source),
  14727. methodNames = baseFunctions(source, props);
  14728. if (options == null &&
  14729. !(isObject(source) && (methodNames.length || !props.length))) {
  14730. options = source;
  14731. source = object;
  14732. object = this;
  14733. methodNames = baseFunctions(source, keys(source));
  14734. }
  14735. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  14736. isFunc = isFunction(object);
  14737. arrayEach(methodNames, function(methodName) {
  14738. var func = source[methodName];
  14739. object[methodName] = func;
  14740. if (isFunc) {
  14741. object.prototype[methodName] = function() {
  14742. var chainAll = this.__chain__;
  14743. if (chain || chainAll) {
  14744. var result = object(this.__wrapped__),
  14745. actions = result.__actions__ = copyArray(this.__actions__);
  14746. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  14747. result.__chain__ = chainAll;
  14748. return result;
  14749. }
  14750. return func.apply(object, arrayPush([this.value()], arguments));
  14751. };
  14752. }
  14753. });
  14754. return object;
  14755. }
  14756. /**
  14757. * Reverts the `_` variable to its previous value and returns a reference to
  14758. * the `lodash` function.
  14759. *
  14760. * @static
  14761. * @since 0.1.0
  14762. * @memberOf _
  14763. * @category Util
  14764. * @returns {Function} Returns the `lodash` function.
  14765. * @example
  14766. *
  14767. * var lodash = _.noConflict();
  14768. */
  14769. function noConflict() {
  14770. if (root._ === this) {
  14771. root._ = oldDash;
  14772. }
  14773. return this;
  14774. }
  14775. /**
  14776. * This method returns `undefined`.
  14777. *
  14778. * @static
  14779. * @memberOf _
  14780. * @since 2.3.0
  14781. * @category Util
  14782. * @example
  14783. *
  14784. * _.times(2, _.noop);
  14785. * // => [undefined, undefined]
  14786. */
  14787. function noop() {
  14788. // No operation performed.
  14789. }
  14790. /**
  14791. * Creates a function that gets the argument at index `n`. If `n` is negative,
  14792. * the nth argument from the end is returned.
  14793. *
  14794. * @static
  14795. * @memberOf _
  14796. * @since 4.0.0
  14797. * @category Util
  14798. * @param {number} [n=0] The index of the argument to return.
  14799. * @returns {Function} Returns the new pass-thru function.
  14800. * @example
  14801. *
  14802. * var func = _.nthArg(1);
  14803. * func('a', 'b', 'c', 'd');
  14804. * // => 'b'
  14805. *
  14806. * var func = _.nthArg(-2);
  14807. * func('a', 'b', 'c', 'd');
  14808. * // => 'c'
  14809. */
  14810. function nthArg(n) {
  14811. n = toInteger(n);
  14812. return baseRest(function(args) {
  14813. return baseNth(args, n);
  14814. });
  14815. }
  14816. /**
  14817. * Creates a function that invokes `iteratees` with the arguments it receives
  14818. * and returns their results.
  14819. *
  14820. * @static
  14821. * @memberOf _
  14822. * @since 4.0.0
  14823. * @category Util
  14824. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  14825. * The iteratees to invoke.
  14826. * @returns {Function} Returns the new function.
  14827. * @example
  14828. *
  14829. * var func = _.over([Math.max, Math.min]);
  14830. *
  14831. * func(1, 2, 3, 4);
  14832. * // => [4, 1]
  14833. */
  14834. var over = createOver(arrayMap);
  14835. /**
  14836. * Creates a function that checks if **all** of the `predicates` return
  14837. * truthy when invoked with the arguments it receives.
  14838. *
  14839. * @static
  14840. * @memberOf _
  14841. * @since 4.0.0
  14842. * @category Util
  14843. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14844. * The predicates to check.
  14845. * @returns {Function} Returns the new function.
  14846. * @example
  14847. *
  14848. * var func = _.overEvery([Boolean, isFinite]);
  14849. *
  14850. * func('1');
  14851. * // => true
  14852. *
  14853. * func(null);
  14854. * // => false
  14855. *
  14856. * func(NaN);
  14857. * // => false
  14858. */
  14859. var overEvery = createOver(arrayEvery);
  14860. /**
  14861. * Creates a function that checks if **any** of the `predicates` return
  14862. * truthy when invoked with the arguments it receives.
  14863. *
  14864. * @static
  14865. * @memberOf _
  14866. * @since 4.0.0
  14867. * @category Util
  14868. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14869. * The predicates to check.
  14870. * @returns {Function} Returns the new function.
  14871. * @example
  14872. *
  14873. * var func = _.overSome([Boolean, isFinite]);
  14874. *
  14875. * func('1');
  14876. * // => true
  14877. *
  14878. * func(null);
  14879. * // => true
  14880. *
  14881. * func(NaN);
  14882. * // => false
  14883. */
  14884. var overSome = createOver(arraySome);
  14885. /**
  14886. * Creates a function that returns the value at `path` of a given object.
  14887. *
  14888. * @static
  14889. * @memberOf _
  14890. * @since 2.4.0
  14891. * @category Util
  14892. * @param {Array|string} path The path of the property to get.
  14893. * @returns {Function} Returns the new accessor function.
  14894. * @example
  14895. *
  14896. * var objects = [
  14897. * { 'a': { 'b': 2 } },
  14898. * { 'a': { 'b': 1 } }
  14899. * ];
  14900. *
  14901. * _.map(objects, _.property('a.b'));
  14902. * // => [2, 1]
  14903. *
  14904. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  14905. * // => [1, 2]
  14906. */
  14907. function property(path) {
  14908. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  14909. }
  14910. /**
  14911. * The opposite of `_.property`; this method creates a function that returns
  14912. * the value at a given path of `object`.
  14913. *
  14914. * @static
  14915. * @memberOf _
  14916. * @since 3.0.0
  14917. * @category Util
  14918. * @param {Object} object The object to query.
  14919. * @returns {Function} Returns the new accessor function.
  14920. * @example
  14921. *
  14922. * var array = [0, 1, 2],
  14923. * object = { 'a': array, 'b': array, 'c': array };
  14924. *
  14925. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  14926. * // => [2, 0]
  14927. *
  14928. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  14929. * // => [2, 0]
  14930. */
  14931. function propertyOf(object) {
  14932. return function(path) {
  14933. return object == null ? undefined : baseGet(object, path);
  14934. };
  14935. }
  14936. /**
  14937. * Creates an array of numbers (positive and/or negative) progressing from
  14938. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  14939. * `start` is specified without an `end` or `step`. If `end` is not specified,
  14940. * it's set to `start` with `start` then set to `0`.
  14941. *
  14942. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  14943. * floating-point values which can produce unexpected results.
  14944. *
  14945. * @static
  14946. * @since 0.1.0
  14947. * @memberOf _
  14948. * @category Util
  14949. * @param {number} [start=0] The start of the range.
  14950. * @param {number} end The end of the range.
  14951. * @param {number} [step=1] The value to increment or decrement by.
  14952. * @returns {Array} Returns the range of numbers.
  14953. * @see _.inRange, _.rangeRight
  14954. * @example
  14955. *
  14956. * _.range(4);
  14957. * // => [0, 1, 2, 3]
  14958. *
  14959. * _.range(-4);
  14960. * // => [0, -1, -2, -3]
  14961. *
  14962. * _.range(1, 5);
  14963. * // => [1, 2, 3, 4]
  14964. *
  14965. * _.range(0, 20, 5);
  14966. * // => [0, 5, 10, 15]
  14967. *
  14968. * _.range(0, -4, -1);
  14969. * // => [0, -1, -2, -3]
  14970. *
  14971. * _.range(1, 4, 0);
  14972. * // => [1, 1, 1]
  14973. *
  14974. * _.range(0);
  14975. * // => []
  14976. */
  14977. var range = createRange();
  14978. /**
  14979. * This method is like `_.range` except that it populates values in
  14980. * descending order.
  14981. *
  14982. * @static
  14983. * @memberOf _
  14984. * @since 4.0.0
  14985. * @category Util
  14986. * @param {number} [start=0] The start of the range.
  14987. * @param {number} end The end of the range.
  14988. * @param {number} [step=1] The value to increment or decrement by.
  14989. * @returns {Array} Returns the range of numbers.
  14990. * @see _.inRange, _.range
  14991. * @example
  14992. *
  14993. * _.rangeRight(4);
  14994. * // => [3, 2, 1, 0]
  14995. *
  14996. * _.rangeRight(-4);
  14997. * // => [-3, -2, -1, 0]
  14998. *
  14999. * _.rangeRight(1, 5);
  15000. * // => [4, 3, 2, 1]
  15001. *
  15002. * _.rangeRight(0, 20, 5);
  15003. * // => [15, 10, 5, 0]
  15004. *
  15005. * _.rangeRight(0, -4, -1);
  15006. * // => [-3, -2, -1, 0]
  15007. *
  15008. * _.rangeRight(1, 4, 0);
  15009. * // => [1, 1, 1]
  15010. *
  15011. * _.rangeRight(0);
  15012. * // => []
  15013. */
  15014. var rangeRight = createRange(true);
  15015. /**
  15016. * This method returns a new empty array.
  15017. *
  15018. * @static
  15019. * @memberOf _
  15020. * @since 4.13.0
  15021. * @category Util
  15022. * @returns {Array} Returns the new empty array.
  15023. * @example
  15024. *
  15025. * var arrays = _.times(2, _.stubArray);
  15026. *
  15027. * console.log(arrays);
  15028. * // => [[], []]
  15029. *
  15030. * console.log(arrays[0] === arrays[1]);
  15031. * // => false
  15032. */
  15033. function stubArray() {
  15034. return [];
  15035. }
  15036. /**
  15037. * This method returns `false`.
  15038. *
  15039. * @static
  15040. * @memberOf _
  15041. * @since 4.13.0
  15042. * @category Util
  15043. * @returns {boolean} Returns `false`.
  15044. * @example
  15045. *
  15046. * _.times(2, _.stubFalse);
  15047. * // => [false, false]
  15048. */
  15049. function stubFalse() {
  15050. return false;
  15051. }
  15052. /**
  15053. * This method returns a new empty object.
  15054. *
  15055. * @static
  15056. * @memberOf _
  15057. * @since 4.13.0
  15058. * @category Util
  15059. * @returns {Object} Returns the new empty object.
  15060. * @example
  15061. *
  15062. * var objects = _.times(2, _.stubObject);
  15063. *
  15064. * console.log(objects);
  15065. * // => [{}, {}]
  15066. *
  15067. * console.log(objects[0] === objects[1]);
  15068. * // => false
  15069. */
  15070. function stubObject() {
  15071. return {};
  15072. }
  15073. /**
  15074. * This method returns an empty string.
  15075. *
  15076. * @static
  15077. * @memberOf _
  15078. * @since 4.13.0
  15079. * @category Util
  15080. * @returns {string} Returns the empty string.
  15081. * @example
  15082. *
  15083. * _.times(2, _.stubString);
  15084. * // => ['', '']
  15085. */
  15086. function stubString() {
  15087. return '';
  15088. }
  15089. /**
  15090. * This method returns `true`.
  15091. *
  15092. * @static
  15093. * @memberOf _
  15094. * @since 4.13.0
  15095. * @category Util
  15096. * @returns {boolean} Returns `true`.
  15097. * @example
  15098. *
  15099. * _.times(2, _.stubTrue);
  15100. * // => [true, true]
  15101. */
  15102. function stubTrue() {
  15103. return true;
  15104. }
  15105. /**
  15106. * Invokes the iteratee `n` times, returning an array of the results of
  15107. * each invocation. The iteratee is invoked with one argument; (index).
  15108. *
  15109. * @static
  15110. * @since 0.1.0
  15111. * @memberOf _
  15112. * @category Util
  15113. * @param {number} n The number of times to invoke `iteratee`.
  15114. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15115. * @returns {Array} Returns the array of results.
  15116. * @example
  15117. *
  15118. * _.times(3, String);
  15119. * // => ['0', '1', '2']
  15120. *
  15121. * _.times(4, _.constant(0));
  15122. * // => [0, 0, 0, 0]
  15123. */
  15124. function times(n, iteratee) {
  15125. n = toInteger(n);
  15126. if (n < 1 || n > MAX_SAFE_INTEGER) {
  15127. return [];
  15128. }
  15129. var index = MAX_ARRAY_LENGTH,
  15130. length = nativeMin(n, MAX_ARRAY_LENGTH);
  15131. iteratee = getIteratee(iteratee);
  15132. n -= MAX_ARRAY_LENGTH;
  15133. var result = baseTimes(length, iteratee);
  15134. while (++index < n) {
  15135. iteratee(index);
  15136. }
  15137. return result;
  15138. }
  15139. /**
  15140. * Converts `value` to a property path array.
  15141. *
  15142. * @static
  15143. * @memberOf _
  15144. * @since 4.0.0
  15145. * @category Util
  15146. * @param {*} value The value to convert.
  15147. * @returns {Array} Returns the new property path array.
  15148. * @example
  15149. *
  15150. * _.toPath('a.b.c');
  15151. * // => ['a', 'b', 'c']
  15152. *
  15153. * _.toPath('a[0].b.c');
  15154. * // => ['a', '0', 'b', 'c']
  15155. */
  15156. function toPath(value) {
  15157. if (isArray(value)) {
  15158. return arrayMap(value, toKey);
  15159. }
  15160. return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
  15161. }
  15162. /**
  15163. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  15164. *
  15165. * @static
  15166. * @since 0.1.0
  15167. * @memberOf _
  15168. * @category Util
  15169. * @param {string} [prefix=''] The value to prefix the ID with.
  15170. * @returns {string} Returns the unique ID.
  15171. * @example
  15172. *
  15173. * _.uniqueId('contact_');
  15174. * // => 'contact_104'
  15175. *
  15176. * _.uniqueId();
  15177. * // => '105'
  15178. */
  15179. function uniqueId(prefix) {
  15180. var id = ++idCounter;
  15181. return toString(prefix) + id;
  15182. }
  15183. /*------------------------------------------------------------------------*/
  15184. /**
  15185. * Adds two numbers.
  15186. *
  15187. * @static
  15188. * @memberOf _
  15189. * @since 3.4.0
  15190. * @category Math
  15191. * @param {number} augend The first number in an addition.
  15192. * @param {number} addend The second number in an addition.
  15193. * @returns {number} Returns the total.
  15194. * @example
  15195. *
  15196. * _.add(6, 4);
  15197. * // => 10
  15198. */
  15199. var add = createMathOperation(function(augend, addend) {
  15200. return augend + addend;
  15201. }, 0);
  15202. /**
  15203. * Computes `number` rounded up to `precision`.
  15204. *
  15205. * @static
  15206. * @memberOf _
  15207. * @since 3.10.0
  15208. * @category Math
  15209. * @param {number} number The number to round up.
  15210. * @param {number} [precision=0] The precision to round up to.
  15211. * @returns {number} Returns the rounded up number.
  15212. * @example
  15213. *
  15214. * _.ceil(4.006);
  15215. * // => 5
  15216. *
  15217. * _.ceil(6.004, 2);
  15218. * // => 6.01
  15219. *
  15220. * _.ceil(6040, -2);
  15221. * // => 6100
  15222. */
  15223. var ceil = createRound('ceil');
  15224. /**
  15225. * Divide two numbers.
  15226. *
  15227. * @static
  15228. * @memberOf _
  15229. * @since 4.7.0
  15230. * @category Math
  15231. * @param {number} dividend The first number in a division.
  15232. * @param {number} divisor The second number in a division.
  15233. * @returns {number} Returns the quotient.
  15234. * @example
  15235. *
  15236. * _.divide(6, 4);
  15237. * // => 1.5
  15238. */
  15239. var divide = createMathOperation(function(dividend, divisor) {
  15240. return dividend / divisor;
  15241. }, 1);
  15242. /**
  15243. * Computes `number` rounded down to `precision`.
  15244. *
  15245. * @static
  15246. * @memberOf _
  15247. * @since 3.10.0
  15248. * @category Math
  15249. * @param {number} number The number to round down.
  15250. * @param {number} [precision=0] The precision to round down to.
  15251. * @returns {number} Returns the rounded down number.
  15252. * @example
  15253. *
  15254. * _.floor(4.006);
  15255. * // => 4
  15256. *
  15257. * _.floor(0.046, 2);
  15258. * // => 0.04
  15259. *
  15260. * _.floor(4060, -2);
  15261. * // => 4000
  15262. */
  15263. var floor = createRound('floor');
  15264. /**
  15265. * Computes the maximum value of `array`. If `array` is empty or falsey,
  15266. * `undefined` is returned.
  15267. *
  15268. * @static
  15269. * @since 0.1.0
  15270. * @memberOf _
  15271. * @category Math
  15272. * @param {Array} array The array to iterate over.
  15273. * @returns {*} Returns the maximum value.
  15274. * @example
  15275. *
  15276. * _.max([4, 2, 8, 6]);
  15277. * // => 8
  15278. *
  15279. * _.max([]);
  15280. * // => undefined
  15281. */
  15282. function max(array) {
  15283. return (array && array.length)
  15284. ? baseExtremum(array, identity, baseGt)
  15285. : undefined;
  15286. }
  15287. /**
  15288. * This method is like `_.max` except that it accepts `iteratee` which is
  15289. * invoked for each element in `array` to generate the criterion by which
  15290. * the value is ranked. The iteratee is invoked with one argument: (value).
  15291. *
  15292. * @static
  15293. * @memberOf _
  15294. * @since 4.0.0
  15295. * @category Math
  15296. * @param {Array} array The array to iterate over.
  15297. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15298. * @returns {*} Returns the maximum value.
  15299. * @example
  15300. *
  15301. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15302. *
  15303. * _.maxBy(objects, function(o) { return o.n; });
  15304. * // => { 'n': 2 }
  15305. *
  15306. * // The `_.property` iteratee shorthand.
  15307. * _.maxBy(objects, 'n');
  15308. * // => { 'n': 2 }
  15309. */
  15310. function maxBy(array, iteratee) {
  15311. return (array && array.length)
  15312. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  15313. : undefined;
  15314. }
  15315. /**
  15316. * Computes the mean of the values in `array`.
  15317. *
  15318. * @static
  15319. * @memberOf _
  15320. * @since 4.0.0
  15321. * @category Math
  15322. * @param {Array} array The array to iterate over.
  15323. * @returns {number} Returns the mean.
  15324. * @example
  15325. *
  15326. * _.mean([4, 2, 8, 6]);
  15327. * // => 5
  15328. */
  15329. function mean(array) {
  15330. return baseMean(array, identity);
  15331. }
  15332. /**
  15333. * This method is like `_.mean` except that it accepts `iteratee` which is
  15334. * invoked for each element in `array` to generate the value to be averaged.
  15335. * The iteratee is invoked with one argument: (value).
  15336. *
  15337. * @static
  15338. * @memberOf _
  15339. * @since 4.7.0
  15340. * @category Math
  15341. * @param {Array} array The array to iterate over.
  15342. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15343. * @returns {number} Returns the mean.
  15344. * @example
  15345. *
  15346. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15347. *
  15348. * _.meanBy(objects, function(o) { return o.n; });
  15349. * // => 5
  15350. *
  15351. * // The `_.property` iteratee shorthand.
  15352. * _.meanBy(objects, 'n');
  15353. * // => 5
  15354. */
  15355. function meanBy(array, iteratee) {
  15356. return baseMean(array, getIteratee(iteratee, 2));
  15357. }
  15358. /**
  15359. * Computes the minimum value of `array`. If `array` is empty or falsey,
  15360. * `undefined` is returned.
  15361. *
  15362. * @static
  15363. * @since 0.1.0
  15364. * @memberOf _
  15365. * @category Math
  15366. * @param {Array} array The array to iterate over.
  15367. * @returns {*} Returns the minimum value.
  15368. * @example
  15369. *
  15370. * _.min([4, 2, 8, 6]);
  15371. * // => 2
  15372. *
  15373. * _.min([]);
  15374. * // => undefined
  15375. */
  15376. function min(array) {
  15377. return (array && array.length)
  15378. ? baseExtremum(array, identity, baseLt)
  15379. : undefined;
  15380. }
  15381. /**
  15382. * This method is like `_.min` except that it accepts `iteratee` which is
  15383. * invoked for each element in `array` to generate the criterion by which
  15384. * the value is ranked. The iteratee is invoked with one argument: (value).
  15385. *
  15386. * @static
  15387. * @memberOf _
  15388. * @since 4.0.0
  15389. * @category Math
  15390. * @param {Array} array The array to iterate over.
  15391. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15392. * @returns {*} Returns the minimum value.
  15393. * @example
  15394. *
  15395. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15396. *
  15397. * _.minBy(objects, function(o) { return o.n; });
  15398. * // => { 'n': 1 }
  15399. *
  15400. * // The `_.property` iteratee shorthand.
  15401. * _.minBy(objects, 'n');
  15402. * // => { 'n': 1 }
  15403. */
  15404. function minBy(array, iteratee) {
  15405. return (array && array.length)
  15406. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  15407. : undefined;
  15408. }
  15409. /**
  15410. * Multiply two numbers.
  15411. *
  15412. * @static
  15413. * @memberOf _
  15414. * @since 4.7.0
  15415. * @category Math
  15416. * @param {number} multiplier The first number in a multiplication.
  15417. * @param {number} multiplicand The second number in a multiplication.
  15418. * @returns {number} Returns the product.
  15419. * @example
  15420. *
  15421. * _.multiply(6, 4);
  15422. * // => 24
  15423. */
  15424. var multiply = createMathOperation(function(multiplier, multiplicand) {
  15425. return multiplier * multiplicand;
  15426. }, 1);
  15427. /**
  15428. * Computes `number` rounded to `precision`.
  15429. *
  15430. * @static
  15431. * @memberOf _
  15432. * @since 3.10.0
  15433. * @category Math
  15434. * @param {number} number The number to round.
  15435. * @param {number} [precision=0] The precision to round to.
  15436. * @returns {number} Returns the rounded number.
  15437. * @example
  15438. *
  15439. * _.round(4.006);
  15440. * // => 4
  15441. *
  15442. * _.round(4.006, 2);
  15443. * // => 4.01
  15444. *
  15445. * _.round(4060, -2);
  15446. * // => 4100
  15447. */
  15448. var round = createRound('round');
  15449. /**
  15450. * Subtract two numbers.
  15451. *
  15452. * @static
  15453. * @memberOf _
  15454. * @since 4.0.0
  15455. * @category Math
  15456. * @param {number} minuend The first number in a subtraction.
  15457. * @param {number} subtrahend The second number in a subtraction.
  15458. * @returns {number} Returns the difference.
  15459. * @example
  15460. *
  15461. * _.subtract(6, 4);
  15462. * // => 2
  15463. */
  15464. var subtract = createMathOperation(function(minuend, subtrahend) {
  15465. return minuend - subtrahend;
  15466. }, 0);
  15467. /**
  15468. * Computes the sum of the values in `array`.
  15469. *
  15470. * @static
  15471. * @memberOf _
  15472. * @since 3.4.0
  15473. * @category Math
  15474. * @param {Array} array The array to iterate over.
  15475. * @returns {number} Returns the sum.
  15476. * @example
  15477. *
  15478. * _.sum([4, 2, 8, 6]);
  15479. * // => 20
  15480. */
  15481. function sum(array) {
  15482. return (array && array.length)
  15483. ? baseSum(array, identity)
  15484. : 0;
  15485. }
  15486. /**
  15487. * This method is like `_.sum` except that it accepts `iteratee` which is
  15488. * invoked for each element in `array` to generate the value to be summed.
  15489. * The iteratee is invoked with one argument: (value).
  15490. *
  15491. * @static
  15492. * @memberOf _
  15493. * @since 4.0.0
  15494. * @category Math
  15495. * @param {Array} array The array to iterate over.
  15496. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15497. * @returns {number} Returns the sum.
  15498. * @example
  15499. *
  15500. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15501. *
  15502. * _.sumBy(objects, function(o) { return o.n; });
  15503. * // => 20
  15504. *
  15505. * // The `_.property` iteratee shorthand.
  15506. * _.sumBy(objects, 'n');
  15507. * // => 20
  15508. */
  15509. function sumBy(array, iteratee) {
  15510. return (array && array.length)
  15511. ? baseSum(array, getIteratee(iteratee, 2))
  15512. : 0;
  15513. }
  15514. /*------------------------------------------------------------------------*/
  15515. // Add methods that return wrapped values in chain sequences.
  15516. lodash.after = after;
  15517. lodash.ary = ary;
  15518. lodash.assign = assign;
  15519. lodash.assignIn = assignIn;
  15520. lodash.assignInWith = assignInWith;
  15521. lodash.assignWith = assignWith;
  15522. lodash.at = at;
  15523. lodash.before = before;
  15524. lodash.bind = bind;
  15525. lodash.bindAll = bindAll;
  15526. lodash.bindKey = bindKey;
  15527. lodash.castArray = castArray;
  15528. lodash.chain = chain;
  15529. lodash.chunk = chunk;
  15530. lodash.compact = compact;
  15531. lodash.concat = concat;
  15532. lodash.cond = cond;
  15533. lodash.conforms = conforms;
  15534. lodash.constant = constant;
  15535. lodash.countBy = countBy;
  15536. lodash.create = create;
  15537. lodash.curry = curry;
  15538. lodash.curryRight = curryRight;
  15539. lodash.debounce = debounce;
  15540. lodash.defaults = defaults;
  15541. lodash.defaultsDeep = defaultsDeep;
  15542. lodash.defer = defer;
  15543. lodash.delay = delay;
  15544. lodash.difference = difference;
  15545. lodash.differenceBy = differenceBy;
  15546. lodash.differenceWith = differenceWith;
  15547. lodash.drop = drop;
  15548. lodash.dropRight = dropRight;
  15549. lodash.dropRightWhile = dropRightWhile;
  15550. lodash.dropWhile = dropWhile;
  15551. lodash.fill = fill;
  15552. lodash.filter = filter;
  15553. lodash.flatMap = flatMap;
  15554. lodash.flatMapDeep = flatMapDeep;
  15555. lodash.flatMapDepth = flatMapDepth;
  15556. lodash.flatten = flatten;
  15557. lodash.flattenDeep = flattenDeep;
  15558. lodash.flattenDepth = flattenDepth;
  15559. lodash.flip = flip;
  15560. lodash.flow = flow;
  15561. lodash.flowRight = flowRight;
  15562. lodash.fromPairs = fromPairs;
  15563. lodash.functions = functions;
  15564. lodash.functionsIn = functionsIn;
  15565. lodash.groupBy = groupBy;
  15566. lodash.initial = initial;
  15567. lodash.intersection = intersection;
  15568. lodash.intersectionBy = intersectionBy;
  15569. lodash.intersectionWith = intersectionWith;
  15570. lodash.invert = invert;
  15571. lodash.invertBy = invertBy;
  15572. lodash.invokeMap = invokeMap;
  15573. lodash.iteratee = iteratee;
  15574. lodash.keyBy = keyBy;
  15575. lodash.keys = keys;
  15576. lodash.keysIn = keysIn;
  15577. lodash.map = map;
  15578. lodash.mapKeys = mapKeys;
  15579. lodash.mapValues = mapValues;
  15580. lodash.matches = matches;
  15581. lodash.matchesProperty = matchesProperty;
  15582. lodash.memoize = memoize;
  15583. lodash.merge = merge;
  15584. lodash.mergeWith = mergeWith;
  15585. lodash.method = method;
  15586. lodash.methodOf = methodOf;
  15587. lodash.mixin = mixin;
  15588. lodash.negate = negate;
  15589. lodash.nthArg = nthArg;
  15590. lodash.omit = omit;
  15591. lodash.omitBy = omitBy;
  15592. lodash.once = once;
  15593. lodash.orderBy = orderBy;
  15594. lodash.over = over;
  15595. lodash.overArgs = overArgs;
  15596. lodash.overEvery = overEvery;
  15597. lodash.overSome = overSome;
  15598. lodash.partial = partial;
  15599. lodash.partialRight = partialRight;
  15600. lodash.partition = partition;
  15601. lodash.pick = pick;
  15602. lodash.pickBy = pickBy;
  15603. lodash.property = property;
  15604. lodash.propertyOf = propertyOf;
  15605. lodash.pull = pull;
  15606. lodash.pullAll = pullAll;
  15607. lodash.pullAllBy = pullAllBy;
  15608. lodash.pullAllWith = pullAllWith;
  15609. lodash.pullAt = pullAt;
  15610. lodash.range = range;
  15611. lodash.rangeRight = rangeRight;
  15612. lodash.rearg = rearg;
  15613. lodash.reject = reject;
  15614. lodash.remove = remove;
  15615. lodash.rest = rest;
  15616. lodash.reverse = reverse;
  15617. lodash.sampleSize = sampleSize;
  15618. lodash.set = set;
  15619. lodash.setWith = setWith;
  15620. lodash.shuffle = shuffle;
  15621. lodash.slice = slice;
  15622. lodash.sortBy = sortBy;
  15623. lodash.sortedUniq = sortedUniq;
  15624. lodash.sortedUniqBy = sortedUniqBy;
  15625. lodash.split = split;
  15626. lodash.spread = spread;
  15627. lodash.tail = tail;
  15628. lodash.take = take;
  15629. lodash.takeRight = takeRight;
  15630. lodash.takeRightWhile = takeRightWhile;
  15631. lodash.takeWhile = takeWhile;
  15632. lodash.tap = tap;
  15633. lodash.throttle = throttle;
  15634. lodash.thru = thru;
  15635. lodash.toArray = toArray;
  15636. lodash.toPairs = toPairs;
  15637. lodash.toPairsIn = toPairsIn;
  15638. lodash.toPath = toPath;
  15639. lodash.toPlainObject = toPlainObject;
  15640. lodash.transform = transform;
  15641. lodash.unary = unary;
  15642. lodash.union = union;
  15643. lodash.unionBy = unionBy;
  15644. lodash.unionWith = unionWith;
  15645. lodash.uniq = uniq;
  15646. lodash.uniqBy = uniqBy;
  15647. lodash.uniqWith = uniqWith;
  15648. lodash.unset = unset;
  15649. lodash.unzip = unzip;
  15650. lodash.unzipWith = unzipWith;
  15651. lodash.update = update;
  15652. lodash.updateWith = updateWith;
  15653. lodash.values = values;
  15654. lodash.valuesIn = valuesIn;
  15655. lodash.without = without;
  15656. lodash.words = words;
  15657. lodash.wrap = wrap;
  15658. lodash.xor = xor;
  15659. lodash.xorBy = xorBy;
  15660. lodash.xorWith = xorWith;
  15661. lodash.zip = zip;
  15662. lodash.zipObject = zipObject;
  15663. lodash.zipObjectDeep = zipObjectDeep;
  15664. lodash.zipWith = zipWith;
  15665. // Add aliases.
  15666. lodash.entries = toPairs;
  15667. lodash.entriesIn = toPairsIn;
  15668. lodash.extend = assignIn;
  15669. lodash.extendWith = assignInWith;
  15670. // Add methods to `lodash.prototype`.
  15671. mixin(lodash, lodash);
  15672. /*------------------------------------------------------------------------*/
  15673. // Add methods that return unwrapped values in chain sequences.
  15674. lodash.add = add;
  15675. lodash.attempt = attempt;
  15676. lodash.camelCase = camelCase;
  15677. lodash.capitalize = capitalize;
  15678. lodash.ceil = ceil;
  15679. lodash.clamp = clamp;
  15680. lodash.clone = clone;
  15681. lodash.cloneDeep = cloneDeep;
  15682. lodash.cloneDeepWith = cloneDeepWith;
  15683. lodash.cloneWith = cloneWith;
  15684. lodash.conformsTo = conformsTo;
  15685. lodash.deburr = deburr;
  15686. lodash.defaultTo = defaultTo;
  15687. lodash.divide = divide;
  15688. lodash.endsWith = endsWith;
  15689. lodash.eq = eq;
  15690. lodash.escape = escape;
  15691. lodash.escapeRegExp = escapeRegExp;
  15692. lodash.every = every;
  15693. lodash.find = find;
  15694. lodash.findIndex = findIndex;
  15695. lodash.findKey = findKey;
  15696. lodash.findLast = findLast;
  15697. lodash.findLastIndex = findLastIndex;
  15698. lodash.findLastKey = findLastKey;
  15699. lodash.floor = floor;
  15700. lodash.forEach = forEach;
  15701. lodash.forEachRight = forEachRight;
  15702. lodash.forIn = forIn;
  15703. lodash.forInRight = forInRight;
  15704. lodash.forOwn = forOwn;
  15705. lodash.forOwnRight = forOwnRight;
  15706. lodash.get = get;
  15707. lodash.gt = gt;
  15708. lodash.gte = gte;
  15709. lodash.has = has;
  15710. lodash.hasIn = hasIn;
  15711. lodash.head = head;
  15712. lodash.identity = identity;
  15713. lodash.includes = includes;
  15714. lodash.indexOf = indexOf;
  15715. lodash.inRange = inRange;
  15716. lodash.invoke = invoke;
  15717. lodash.isArguments = isArguments;
  15718. lodash.isArray = isArray;
  15719. lodash.isArrayBuffer = isArrayBuffer;
  15720. lodash.isArrayLike = isArrayLike;
  15721. lodash.isArrayLikeObject = isArrayLikeObject;
  15722. lodash.isBoolean = isBoolean;
  15723. lodash.isBuffer = isBuffer;
  15724. lodash.isDate = isDate;
  15725. lodash.isElement = isElement;
  15726. lodash.isEmpty = isEmpty;
  15727. lodash.isEqual = isEqual;
  15728. lodash.isEqualWith = isEqualWith;
  15729. lodash.isError = isError;
  15730. lodash.isFinite = isFinite;
  15731. lodash.isFunction = isFunction;
  15732. lodash.isInteger = isInteger;
  15733. lodash.isLength = isLength;
  15734. lodash.isMap = isMap;
  15735. lodash.isMatch = isMatch;
  15736. lodash.isMatchWith = isMatchWith;
  15737. lodash.isNaN = isNaN;
  15738. lodash.isNative = isNative;
  15739. lodash.isNil = isNil;
  15740. lodash.isNull = isNull;
  15741. lodash.isNumber = isNumber;
  15742. lodash.isObject = isObject;
  15743. lodash.isObjectLike = isObjectLike;
  15744. lodash.isPlainObject = isPlainObject;
  15745. lodash.isRegExp = isRegExp;
  15746. lodash.isSafeInteger = isSafeInteger;
  15747. lodash.isSet = isSet;
  15748. lodash.isString = isString;
  15749. lodash.isSymbol = isSymbol;
  15750. lodash.isTypedArray = isTypedArray;
  15751. lodash.isUndefined = isUndefined;
  15752. lodash.isWeakMap = isWeakMap;
  15753. lodash.isWeakSet = isWeakSet;
  15754. lodash.join = join;
  15755. lodash.kebabCase = kebabCase;
  15756. lodash.last = last;
  15757. lodash.lastIndexOf = lastIndexOf;
  15758. lodash.lowerCase = lowerCase;
  15759. lodash.lowerFirst = lowerFirst;
  15760. lodash.lt = lt;
  15761. lodash.lte = lte;
  15762. lodash.max = max;
  15763. lodash.maxBy = maxBy;
  15764. lodash.mean = mean;
  15765. lodash.meanBy = meanBy;
  15766. lodash.min = min;
  15767. lodash.minBy = minBy;
  15768. lodash.stubArray = stubArray;
  15769. lodash.stubFalse = stubFalse;
  15770. lodash.stubObject = stubObject;
  15771. lodash.stubString = stubString;
  15772. lodash.stubTrue = stubTrue;
  15773. lodash.multiply = multiply;
  15774. lodash.nth = nth;
  15775. lodash.noConflict = noConflict;
  15776. lodash.noop = noop;
  15777. lodash.now = now;
  15778. lodash.pad = pad;
  15779. lodash.padEnd = padEnd;
  15780. lodash.padStart = padStart;
  15781. lodash.parseInt = parseInt;
  15782. lodash.random = random;
  15783. lodash.reduce = reduce;
  15784. lodash.reduceRight = reduceRight;
  15785. lodash.repeat = repeat;
  15786. lodash.replace = replace;
  15787. lodash.result = result;
  15788. lodash.round = round;
  15789. lodash.runInContext = runInContext;
  15790. lodash.sample = sample;
  15791. lodash.size = size;
  15792. lodash.snakeCase = snakeCase;
  15793. lodash.some = some;
  15794. lodash.sortedIndex = sortedIndex;
  15795. lodash.sortedIndexBy = sortedIndexBy;
  15796. lodash.sortedIndexOf = sortedIndexOf;
  15797. lodash.sortedLastIndex = sortedLastIndex;
  15798. lodash.sortedLastIndexBy = sortedLastIndexBy;
  15799. lodash.sortedLastIndexOf = sortedLastIndexOf;
  15800. lodash.startCase = startCase;
  15801. lodash.startsWith = startsWith;
  15802. lodash.subtract = subtract;
  15803. lodash.sum = sum;
  15804. lodash.sumBy = sumBy;
  15805. lodash.template = template;
  15806. lodash.times = times;
  15807. lodash.toFinite = toFinite;
  15808. lodash.toInteger = toInteger;
  15809. lodash.toLength = toLength;
  15810. lodash.toLower = toLower;
  15811. lodash.toNumber = toNumber;
  15812. lodash.toSafeInteger = toSafeInteger;
  15813. lodash.toString = toString;
  15814. lodash.toUpper = toUpper;
  15815. lodash.trim = trim;
  15816. lodash.trimEnd = trimEnd;
  15817. lodash.trimStart = trimStart;
  15818. lodash.truncate = truncate;
  15819. lodash.unescape = unescape;
  15820. lodash.uniqueId = uniqueId;
  15821. lodash.upperCase = upperCase;
  15822. lodash.upperFirst = upperFirst;
  15823. // Add aliases.
  15824. lodash.each = forEach;
  15825. lodash.eachRight = forEachRight;
  15826. lodash.first = head;
  15827. mixin(lodash, (function() {
  15828. var source = {};
  15829. baseForOwn(lodash, function(func, methodName) {
  15830. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  15831. source[methodName] = func;
  15832. }
  15833. });
  15834. return source;
  15835. }()), { 'chain': false });
  15836. /*------------------------------------------------------------------------*/
  15837. /**
  15838. * The semantic version number.
  15839. *
  15840. * @static
  15841. * @memberOf _
  15842. * @type {string}
  15843. */
  15844. lodash.VERSION = VERSION;
  15845. // Assign default placeholders.
  15846. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  15847. lodash[methodName].placeholder = lodash;
  15848. });
  15849. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  15850. arrayEach(['drop', 'take'], function(methodName, index) {
  15851. LazyWrapper.prototype[methodName] = function(n) {
  15852. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  15853. var result = (this.__filtered__ && !index)
  15854. ? new LazyWrapper(this)
  15855. : this.clone();
  15856. if (result.__filtered__) {
  15857. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  15858. } else {
  15859. result.__views__.push({
  15860. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  15861. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  15862. });
  15863. }
  15864. return result;
  15865. };
  15866. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  15867. return this.reverse()[methodName](n).reverse();
  15868. };
  15869. });
  15870. // Add `LazyWrapper` methods that accept an `iteratee` value.
  15871. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  15872. var type = index + 1,
  15873. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  15874. LazyWrapper.prototype[methodName] = function(iteratee) {
  15875. var result = this.clone();
  15876. result.__iteratees__.push({
  15877. 'iteratee': getIteratee(iteratee, 3),
  15878. 'type': type
  15879. });
  15880. result.__filtered__ = result.__filtered__ || isFilter;
  15881. return result;
  15882. };
  15883. });
  15884. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  15885. arrayEach(['head', 'last'], function(methodName, index) {
  15886. var takeName = 'take' + (index ? 'Right' : '');
  15887. LazyWrapper.prototype[methodName] = function() {
  15888. return this[takeName](1).value()[0];
  15889. };
  15890. });
  15891. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  15892. arrayEach(['initial', 'tail'], function(methodName, index) {
  15893. var dropName = 'drop' + (index ? '' : 'Right');
  15894. LazyWrapper.prototype[methodName] = function() {
  15895. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  15896. };
  15897. });
  15898. LazyWrapper.prototype.compact = function() {
  15899. return this.filter(identity);
  15900. };
  15901. LazyWrapper.prototype.find = function(predicate) {
  15902. return this.filter(predicate).head();
  15903. };
  15904. LazyWrapper.prototype.findLast = function(predicate) {
  15905. return this.reverse().find(predicate);
  15906. };
  15907. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  15908. if (typeof path == 'function') {
  15909. return new LazyWrapper(this);
  15910. }
  15911. return this.map(function(value) {
  15912. return baseInvoke(value, path, args);
  15913. });
  15914. });
  15915. LazyWrapper.prototype.reject = function(predicate) {
  15916. return this.filter(negate(getIteratee(predicate)));
  15917. };
  15918. LazyWrapper.prototype.slice = function(start, end) {
  15919. start = toInteger(start);
  15920. var result = this;
  15921. if (result.__filtered__ && (start > 0 || end < 0)) {
  15922. return new LazyWrapper(result);
  15923. }
  15924. if (start < 0) {
  15925. result = result.takeRight(-start);
  15926. } else if (start) {
  15927. result = result.drop(start);
  15928. }
  15929. if (end !== undefined) {
  15930. end = toInteger(end);
  15931. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  15932. }
  15933. return result;
  15934. };
  15935. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  15936. return this.reverse().takeWhile(predicate).reverse();
  15937. };
  15938. LazyWrapper.prototype.toArray = function() {
  15939. return this.take(MAX_ARRAY_LENGTH);
  15940. };
  15941. // Add `LazyWrapper` methods to `lodash.prototype`.
  15942. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  15943. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  15944. isTaker = /^(?:head|last)$/.test(methodName),
  15945. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  15946. retUnwrapped = isTaker || /^find/.test(methodName);
  15947. if (!lodashFunc) {
  15948. return;
  15949. }
  15950. lodash.prototype[methodName] = function() {
  15951. var value = this.__wrapped__,
  15952. args = isTaker ? [1] : arguments,
  15953. isLazy = value instanceof LazyWrapper,
  15954. iteratee = args[0],
  15955. useLazy = isLazy || isArray(value);
  15956. var interceptor = function(value) {
  15957. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  15958. return (isTaker && chainAll) ? result[0] : result;
  15959. };
  15960. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  15961. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  15962. isLazy = useLazy = false;
  15963. }
  15964. var chainAll = this.__chain__,
  15965. isHybrid = !!this.__actions__.length,
  15966. isUnwrapped = retUnwrapped && !chainAll,
  15967. onlyLazy = isLazy && !isHybrid;
  15968. if (!retUnwrapped && useLazy) {
  15969. value = onlyLazy ? value : new LazyWrapper(this);
  15970. var result = func.apply(value, args);
  15971. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  15972. return new LodashWrapper(result, chainAll);
  15973. }
  15974. if (isUnwrapped && onlyLazy) {
  15975. return func.apply(this, args);
  15976. }
  15977. result = this.thru(interceptor);
  15978. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  15979. };
  15980. });
  15981. // Add `Array` methods to `lodash.prototype`.
  15982. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  15983. var func = arrayProto[methodName],
  15984. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  15985. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  15986. lodash.prototype[methodName] = function() {
  15987. var args = arguments;
  15988. if (retUnwrapped && !this.__chain__) {
  15989. var value = this.value();
  15990. return func.apply(isArray(value) ? value : [], args);
  15991. }
  15992. return this[chainName](function(value) {
  15993. return func.apply(isArray(value) ? value : [], args);
  15994. });
  15995. };
  15996. });
  15997. // Map minified method names to their real names.
  15998. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  15999. var lodashFunc = lodash[methodName];
  16000. if (lodashFunc) {
  16001. var key = (lodashFunc.name + ''),
  16002. names = realNames[key] || (realNames[key] = []);
  16003. names.push({ 'name': methodName, 'func': lodashFunc });
  16004. }
  16005. });
  16006. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  16007. 'name': 'wrapper',
  16008. 'func': undefined
  16009. }];
  16010. // Add methods to `LazyWrapper`.
  16011. LazyWrapper.prototype.clone = lazyClone;
  16012. LazyWrapper.prototype.reverse = lazyReverse;
  16013. LazyWrapper.prototype.value = lazyValue;
  16014. // Add chain sequence methods to the `lodash` wrapper.
  16015. lodash.prototype.at = wrapperAt;
  16016. lodash.prototype.chain = wrapperChain;
  16017. lodash.prototype.commit = wrapperCommit;
  16018. lodash.prototype.next = wrapperNext;
  16019. lodash.prototype.plant = wrapperPlant;
  16020. lodash.prototype.reverse = wrapperReverse;
  16021. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  16022. // Add lazy aliases.
  16023. lodash.prototype.first = lodash.prototype.head;
  16024. if (symIterator) {
  16025. lodash.prototype[symIterator] = wrapperToIterator;
  16026. }
  16027. return lodash;
  16028. });
  16029. /*--------------------------------------------------------------------------*/
  16030. // Export lodash.
  16031. var _ = runInContext();
  16032. // Some AMD build optimizers, like r.js, check for condition patterns like:
  16033. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  16034. // Expose Lodash on the global object to prevent errors when Lodash is
  16035. // loaded by a script tag in the presence of an AMD loader.
  16036. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  16037. // Use `_.noConflict` to remove Lodash from the global object.
  16038. root._ = _;
  16039. // Define as an anonymous module so, through path mapping, it can be
  16040. // referenced as the "underscore" module.
  16041. define(function() {
  16042. return _;
  16043. });
  16044. }
  16045. // Check for `exports` after `define` in case a build optimizer adds it.
  16046. else if (freeModule) {
  16047. // Export for Node.js.
  16048. (freeModule.exports = _)._ = _;
  16049. // Export for CommonJS support.
  16050. freeExports._ = _;
  16051. }
  16052. else {
  16053. // Export to the global object.
  16054. root._ = _;
  16055. }
  16056. }.call(this));